Skip to content

Commit

Permalink
chore: [IAI-189] Upgrade TypeScript to version 4.7 (pagopa#3963)
Browse files Browse the repository at this point in the history
* Update TS to `4.6.3`

* Solved `handleSearchUserSatispay` ts error

* Fix `validCreditCard` ts type

* Fix nested type error

* Refactor the `Transaction` type to avoid refinements

* Update typescript to `4.6.4`

* Moved `IOTransaction` changes to `spec.json`

* Restore useless change in `pagopa.ts`

* Upgrade TypeScript to `4.7`

* Add spec changelog

Co-authored-by: fabriziofff <[email protected]>
  • Loading branch information
dgopsq and fabriziofff authored May 27, 2022
1 parent 54cff66 commit d5ef1c9
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 52 deletions.
13 changes: 13 additions & 0 deletions assets/paymentManager/README.MD
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
### 2022-05-27
- Created a new structure `TransactionAmount` used to replace the generic `Amount` definition inside `Transaction`. This new structure differs from the normal `Amount` just on the `amount` property which is now **required**.
- Marked fields as **required** in the `Transaction` structure in order to replace the changes made manually in the code (take a look at https://github.com/pagopa/io-app/pull/3963):
- `created`
- `description`
- `id`
- `idPayment`
- `idWallet`
- `merchant`
- `statusMessage`
- `grandTotal`
- `amount`

### 2021-12-03
- ignored `payPals` field in `Wallet` since the relative model is different from the one returned by the API and the app doesn't use it

Expand Down
39 changes: 35 additions & 4 deletions assets/paymentManager/spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -2086,6 +2086,26 @@
},
"title": "Amount"
},
"TransactionAmount": {
"type": "object",
"properties": {
"amount": {
"type": "integer"
},
"currency": {
"type": "string"
},
"currencyNumber": {
"type": "string"
},
"decimalDigits": {
"type": "integer",
"format": "int32"
}
},
"title": "Amount",
"required": ["amount"]
},
"BPay": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -3017,7 +3037,7 @@
"format": "int64"
},
"amount": {
"$ref": "#/definitions/Amount"
"$ref": "#/definitions/TransactionAmount"
},
"authorizationCode": {
"type": "string"
Expand All @@ -3042,10 +3062,10 @@
"type": "boolean"
},
"fee": {
"$ref": "#/definitions/Amount"
"$ref": "#/definitions/TransactionAmount"
},
"grandTotal": {
"$ref": "#/definitions/Amount"
"$ref": "#/definitions/TransactionAmount"
},
"id": {
"type": "integer",
Expand Down Expand Up @@ -3117,7 +3137,18 @@
"type": "string"
}
},
"title": "Transaction"
"title": "Transaction",
"required": [
"created",
"description",
"id",
"idPayment",
"idWallet",
"merchant",
"statusMessage",
"grandTotal",
"amount"
]
},
"TransactionListResponse": {
"type": "object",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@
"rn-nodeify": "^10.0.1",
"standard-version": "^8.0.2",
"ts-node": "^7.0.1",
"typescript": "^4.1.0"
"typescript": "^4.7.2"
},
"resolutions": {
"@codler/react-native-keyboard-aware-scroll-view": "2.0.1",
Expand Down
11 changes: 7 additions & 4 deletions ts/features/wallet/onboarding/satispay/saga/networking/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ export function* handleSearchUserSatispay(
// even if the user doesn't own satispay the response is 200 but the payload is empty
// FIXME 200 must always contain a non-empty payload
return yield* put(
searchUserSatispay.success(_.isEmpty(value.data) ? null : value.data)
searchUserSatispay.success(
!value.data || _.isEmpty(value.data) ? null : value.data
)
);
} else if (statusCode === 404) {
// the user doesn't own any satispay
Expand Down Expand Up @@ -88,10 +90,11 @@ export function* handleAddUserSatispayToWallet(
> = yield* call(addSatispayToWalletWithRefresh);
if (addSatispayToWalletWithRefreshResult.isRight()) {
const statusCode = addSatispayToWalletWithRefreshResult.value.status;
const wallet = addSatispayToWalletWithRefreshResult.value.value.data;
if (statusCode === 200) {
const newSatispay = fromPatchedWalletV2ToRawSatispay(
addSatispayToWalletWithRefreshResult.value.value.data
);
const newSatispay = wallet
? fromPatchedWalletV2ToRawSatispay(wallet)
: undefined;
if (newSatispay) {
// satispay has been added to the user wallet
return yield* put(addSatispayToWallet.success(newSatispay));
Expand Down
6 changes: 3 additions & 3 deletions ts/store/reducers/entities/__tests__/readTransactions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ProfileState } from "../../profile";
import { GlobalState } from "../../types";
import { getSafeUnreadTransactionsNumSelector } from "../readTransactions";

const transactionsState: DeepPartial<GlobalState> = {
const transactionsState = {
wallet: {
transactions: {
transactions: pot.some({
Expand All @@ -25,7 +25,7 @@ const transactionsState: DeepPartial<GlobalState> = {
describe("readTransaction", () => {
describe("getSafeUnreadTransactionsNumSelector", () => {
it("should return the correct unread transaction number", () => {
const state: DeepPartial<GlobalState> = {
const state = {
profile: pot.some({
is_email_validated: true,
email: "[email protected]"
Expand All @@ -41,7 +41,7 @@ describe("readTransaction", () => {
});

it("should return the 0 because the email is not validated", () => {
const state: DeepPartial<GlobalState> = {
const state = {
profile: pot.some({
is_email_validated: false,
email: "[email protected]"
Expand Down
38 changes: 6 additions & 32 deletions ts/types/pagopa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { PspListResponseCD as PspListResponsePagoPA } from "../../definitions/pa
import { PspResponse as PspResponsePagoPA } from "../../definitions/pagopa/PspResponse";
import { Session as SessionPagoPA } from "../../definitions/pagopa/Session";
import { SessionResponse as SessionResponsePagoPA } from "../../definitions/pagopa/SessionResponse";
import { Transaction as TransactionPagoPA } from "../../definitions/pagopa/Transaction";
import { TransactionListResponse as TransactionListResponsePagoPA } from "../../definitions/pagopa/TransactionListResponse";
import { TransactionResponse as TransactionResponsePagoPA } from "../../definitions/pagopa/TransactionResponse";
import { Wallet as WalletPagoPA } from "../../definitions/pagopa/Wallet";
Expand All @@ -39,6 +38,10 @@ import {
} from "../../definitions/pagopa/walletv2/CardInfo";
import { EnableableFunctions } from "../../definitions/pagopa/EnableableFunctions";
import { PayPalInfo } from "../../definitions/pagopa/PayPalInfo";
import {
Transaction as TransactionPagoPA,
Transaction as TTransactionPagoPA
} from "../../definitions/pagopa/Transaction";

/**
* Union of all possible credit card types
Expand Down Expand Up @@ -313,37 +316,8 @@ export type NullableWallet = ReplaceProp1<Wallet, "idWallet", undefined>;
/**
* A refined Transaction
*/
export const Transaction = repP(
repP(
repP(
reqP(
reqP(
reqP(
reqP(
reqP(
reqP(reqP(TransactionPagoPA, "created"), "description"),
"id"
),
"idPayment"
),
"idWallet"
),
"merchant"
),
"statusMessage"
),
"amount",
Amount
),
"fee",
t.union([Amount, t.undefined])
),
"grandTotal",
Amount,
"Transaction"
);

export type Transaction = t.TypeOf<typeof Transaction>;
export type Transaction = TTransactionPagoPA;
export const Transaction = TransactionPagoPA;

export const isCompletedTransaction = (tx: Transaction) => tx.idStatus === 3;

Expand Down
18 changes: 16 additions & 2 deletions ts/utils/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ import {
import { Millisecond } from "italia-ts-commons/lib/units";
import { fetchMaxRetries, fetchTimeout } from "../config";

// FIXME: This is a temporary type created to avoid
// a compilation error caused by the `toFetch` function
// not returning a function with the `input` parameter
// typed as `RequestInfo | URL`, which is the correct
// type for the `fetch` method.
type FixedFetch = (
input: RequestInfo | URL,
init?: RequestInit | undefined
) => Promise<Response>;

/**
* Wrapper for the Fetch API configured by default with a short timeout and
* an exponential backoff retrying strategy.
Expand All @@ -35,7 +45,9 @@ export function defaultRetryingFetch(
): typeof fetch {
const fetchApi = (global as any).fetch;
const abortableFetch = AbortableFetch(fetchApi);
const timeoutFetch = toFetch(setFetchTimeout(timeout, abortableFetch));
const timeoutFetch = toFetch(
setFetchTimeout(timeout, abortableFetch)
) as FixedFetch;
// configure retry logic with default exponential backoff
// @see https://github.com/pagopa/io-ts-commons/blob/master/src/backoff.ts
const exponentialBackoff = calculateExponentialBackoffInterval();
Expand Down Expand Up @@ -87,7 +99,9 @@ export const constantPollingFetch = (
timeout: Millisecond = fetchTimeout
): typeof fetch => {
const abortableFetch = AbortableFetch((global as any).fetch);
const timeoutFetch = toFetch(setFetchTimeout(timeout, abortableFetch));
const timeoutFetch = toFetch(
setFetchTimeout(timeout, abortableFetch)
) as FixedFetch;
const constantBackoff = () => delay as Millisecond;
const retryLogic = withRetries<Error, Response>(retries, constantBackoff);
// makes the retry logic map 404s to transient errors (by default only
Expand Down
2 changes: 1 addition & 1 deletion ts/utils/testFaker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { CreditCardExpirationMonth, CreditCardExpirationYear } from "./input";
const validCreditCard: CreditCard = {
id: 1464,
holder: "Mario Rossi",
pan: "************0111" as string & IPatternStringTag<string>,
pan: "************0111" as string & IPatternStringTag<"^[0-9\\*]{12,19}$">,
securityCode: "345" as string & IPatternStringTag<"^[0-9]{3,4}$">,
expireMonth: "05" as string & CreditCardExpirationMonth,
expireYear: "22" as string & CreditCardExpirationYear,
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"noUnusedLocals": true,
"strictFunctionTypes": true,
"skipLibCheck": true,
"isolatedModules": true
"isolatedModules": true,
"useUnknownInCatchVariables": false
},
"exclude": [
"android",
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -15878,10 +15878,10 @@ typescript-tuple@^2.2.1:
dependencies:
typescript-compare "^0.0.2"

typescript@^4.1.0:
version "4.1.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.1.3.tgz#519d582bd94cba0cf8934c7d8e8467e473f53bb7"
integrity sha512-B3ZIOf1IKeH2ixgHhj6la6xdwR9QrLC5d1VKeCSY4tvkqhF2eqd9O7txNlS0PO3GrBAFIdr3L1ndNwteUbZLYg==
typescript@^4.7.2:
version "4.7.2"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.7.2.tgz#1f9aa2ceb9af87cca227813b4310fff0b51593c4"
integrity sha512-Mamb1iX2FDUpcTRzltPxgWMKy3fhg0TN378ylbktPGPK/99KbDtMQ4W1hwgsbPAsG3a0xKa1vmw4VKZQbkvz5A==

typical@^2.4.2, typical@^2.6.0, typical@^2.6.1:
version "2.6.1"
Expand Down

0 comments on commit d5ef1c9

Please sign in to comment.