diff --git a/ts/types/pagopa.ts b/ts/types/pagopa.ts index 58e241c2a38..13ad9c413a2 100644 --- a/ts/types/pagopa.ts +++ b/ts/types/pagopa.ts @@ -94,6 +94,38 @@ export const Psp = repP( ); export type Psp = t.TypeOf; +/** A refined WalletV2 + * reasons: + * - createDate and updateDate are generated from spec as UTCISODateFromString instead of DateFromString + * - info is required + * - info is CardInfo and not PaymentMethodInfo (empty interface) + */ + +// required attributes + +const WalletV2O = t.partial({ + updateDate: t.string, + createDate: DateFromString, + onboardingChannel: t.string, + favourite: t.boolean +}); + +// optional attributes +const WalletV2R = t.interface({ + enableableFunctions: t.readonlyArray(t.string, "array of string"), + info: CardInfo, + idWallet: t.Integer, + pagoPA: t.boolean, + walletType: enumType(WalletTypeEnum, "walletType") +}); + +export const PatchedWalletV2 = t.intersection( + [WalletV2R, WalletV2O], + "WalletV2" +); + +export type PatchedWalletV2 = t.TypeOf; + /** * A refined Wallet */ @@ -107,7 +139,9 @@ export const Wallet = repP( t.union([Psp, t.undefined]), "Wallet" ); -export type Wallet = t.TypeOf; +// add v2 optional field. It may contain a PatchedWalletV2 object +const WalletV1V2 = t.intersection([Wallet, t.partial({ v2: PatchedWalletV2 })]); +export type Wallet = t.TypeOf; /** * A Wallet that has not being saved yet @@ -292,38 +326,6 @@ export const PagoPAErrorResponse = t.type({ export type PagoPAErrorResponse = t.TypeOf; -/** - * reasons: - * - createDate and updateDate are generated from spec as UTCISODateFromString instead of DateFromString - * - info is required - * - info is CardInfo and not PaymentMethodInfo (empty interface) - */ - -// required attributes - -const WalletV2O = t.partial({ - updateDate: t.string, - createDate: DateFromString, - onboardingChannel: t.string, - favourite: t.boolean -}); - -// optional attributes -const WalletV2R = t.interface({ - enableableFunctions: t.readonlyArray(t.string, "array of string"), - info: CardInfo, - idWallet: t.Integer, - pagoPA: t.boolean, - walletType: enumType(WalletTypeEnum, "walletType") -}); - -export const PatchedWalletV2 = t.intersection( - [WalletV2R, WalletV2O], - "WalletV2" -); - -export type PatchedWalletV2 = t.TypeOf; - const WalletV2ListResponseR = t.interface({}); // optional attributes diff --git a/ts/utils/wallet.ts b/ts/utils/wallet.ts index f30c474b229..b6651e4f67c 100644 --- a/ts/utils/wallet.ts +++ b/ts/utils/wallet.ts @@ -104,6 +104,7 @@ export const convertWalletV2toWalletV1 = ( lastUsage: walletV2.updateDate ? new Date(walletV2.updateDate) : undefined, isPspToIgnore: false, registeredNexi: false, - saved: true + saved: true, + v2: walletV2 }; };