@metamask/subscription-controller 13.0.0 → 14.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"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","sourcesContent":["import type { TransactionMeta } from '@metamask/transaction-controller';\nimport type { CaipAccountId, Hex } from '@metamask/utils';\n\nimport type { CANCELLATION_REASONS } from './constants.js';\n\n/**\n * Error response from the Subscription API.\n */\nexport type SubscriptionApiError = {\n errorCode?: string;\n message?: string;\n statusCode?: number;\n};\n\n/**\n * Supported subscription products.\n */\nexport const PRODUCT_TYPES = {\n /**\n * MetaMask Shield.\n */\n SHIELD: 'shield',\n /**\n * Money Account Plus (delegation-based crypto billing).\n */\n MONEY_ACCOUNT_PLUS: 'money_account_plus',\n} as const;\n\nexport type ProductType = (typeof PRODUCT_TYPES)[keyof typeof PRODUCT_TYPES];\n\nexport const MoneyAccountFeature = {\n SwapFeeWaiver: 'swapFeeWaiver',\n PerpsFeeWaiver: 'perpsFeeWaiver',\n PredictFreeTx: 'predictFreeTx',\n PremiumApy: 'premiumApy',\n} as const;\n\nexport type MoneyAccountFeature =\n (typeof MoneyAccountFeature)[keyof typeof MoneyAccountFeature];\n\nexport type MoneyAccountEntitlements = Record<MoneyAccountFeature, boolean>;\n\nexport const ShieldFeature = {\n ShieldClaim: 'shieldClaim',\n PrioritySupport: 'prioritySupport',\n} as const;\n\nexport type ShieldFeature = (typeof ShieldFeature)[keyof typeof ShieldFeature];\n\nexport type ShieldEntitlements = Record<ShieldFeature, boolean>;\n\nexport type MoneyAccountPlusClaim = {\n plan: string;\n entitlements: MoneyAccountEntitlements;\n};\n\nexport type ProductEntitlements = {\n [PRODUCT_TYPES.SHIELD]?: {\n entitlements: ShieldEntitlements;\n };\n [PRODUCT_TYPES.MONEY_ACCOUNT_PLUS]?: MoneyAccountPlusClaim;\n};\n\nexport type ProductEntitlementFeatureMap = {\n [PRODUCT_TYPES.SHIELD]: ShieldFeature;\n [PRODUCT_TYPES.MONEY_ACCOUNT_PLUS]: MoneyAccountFeature;\n};\n\n/**\n * How a crypto subscription is authorized.\n *\n * Use `erc20_approval` with `rawTransaction` (e.g. Shield). Use `delegation`\n * with `delegationHash` (e.g. Money Account Plus).\n */\nexport const CRYPTO_AUTH_METHODS = {\n /**\n * User signs an ERC-20 approve transaction.\n */\n ERC20_APPROVAL: 'erc20_approval',\n /**\n * User authorizes via a stored delegation hash.\n */\n DELEGATION: 'delegation',\n} as const;\n\nexport type CryptoAuthMethod =\n (typeof CRYPTO_AUTH_METHODS)[keyof typeof CRYPTO_AUTH_METHODS];\n\nexport const PAYMENT_TYPES = {\n byCard: 'card',\n byCrypto: 'crypto',\n} as const;\n\nexport type PaymentType = (typeof PAYMENT_TYPES)[keyof typeof PAYMENT_TYPES];\n\nexport const RECURRING_INTERVALS = {\n month: 'month',\n year: 'year',\n} as const;\n\nexport type RecurringInterval =\n (typeof RECURRING_INTERVALS)[keyof typeof RECURRING_INTERVALS];\n\nexport const SUBSCRIPTION_STATUSES = {\n // Initial states\n incomplete: 'incomplete',\n incompleteExpired: 'incomplete_expired',\n /** Crypto subscription created, waiting for the payer to fund the first invoice. */\n awaitingFunds: 'awaiting_funds',\n // Active states\n provisional: 'provisional',\n trialing: 'trialing',\n active: 'active',\n // Payment issues\n pastDue: 'past_due',\n unpaid: 'unpaid',\n // Cancelled states\n canceled: 'canceled',\n // Paused states\n paused: 'paused',\n} as const;\n\nexport type SubscriptionStatus =\n (typeof SUBSCRIPTION_STATUSES)[keyof typeof SUBSCRIPTION_STATUSES];\n\nexport const INVOICE_PAYMENT_STATUSES = {\n PROCESSING: 'PROCESSING',\n SUCCEEDED: 'SUCCEEDED',\n FAILED: 'FAILED',\n UNKNOWN: 'UNKNOWN',\n} as const;\n\nexport type InvoicePaymentStatus =\n (typeof INVOICE_PAYMENT_STATUSES)[keyof typeof INVOICE_PAYMENT_STATUSES];\n\nexport const CANCEL_TYPES = {\n ALLOWED_IMMEDIATE: 'allowed_immediate',\n ALLOWED_AT_PERIOD_END: 'allowed_at_period_end',\n NOT_ALLOWED: 'not_allowed',\n NOT_ALLOWED_PENDING_VERIFICATION: 'not_allowed_pending_verification',\n} as const;\n\nexport type CancelType = (typeof CANCEL_TYPES)[keyof typeof CANCEL_TYPES];\n\nexport type CancellationReasonCode =\n (typeof CANCELLATION_REASONS)[keyof typeof CANCELLATION_REASONS];\n\nexport const CRYPTO_PAYMENT_METHOD_ERRORS = {\n APPROVAL_TRANSACTION_TOO_OLD: 'approval_transaction_too_old',\n APPROVAL_TRANSACTION_REVERTED: 'approval_transaction_reverted',\n APPROVAL_TRANSACTION_MAX_VERIFICATION_ATTEMPTS_REACHED:\n 'approval_transaction_max_verification_attempts_reached',\n INSUFFICIENT_BALANCE: 'insufficient_balance',\n INSUFFICIENT_ALLOWANCE: 'insufficient_allowance',\n} as const;\n\nexport type CryptoPaymentMethodError =\n (typeof CRYPTO_PAYMENT_METHOD_ERRORS)[keyof typeof CRYPTO_PAYMENT_METHOD_ERRORS];\n\n/**\n * Errors returned by the Subscription API after crypto payment execution.\n *\n * These are distinct from {@link CRYPTO_PAYMENT_METHOD_ERRORS}, which describe\n * approval/payment-method failures.\n */\nexport const CRYPTO_PAYMENT_ERRORS = {\n INSUFFICIENT_BALANCE: 'insufficient_balance',\n INSUFFICIENT_ALLOWANCE: 'insufficient_allowance',\n EXCEEDS_DELEGATION_ALLOWANCE: 'exceeds_delegation_allowance',\n DELEGATION_NOT_FOUND: 'delegation_not_found',\n DELEGATION_REVOKED: 'delegation_revoked',\n RECIPIENT_NOT_ALLOWLISTED: 'recipient_not_allowlisted',\n INTERNAL_SERVER_ERROR: 'internal_server_error',\n} as const;\n\nexport type CryptoPaymentError =\n (typeof CRYPTO_PAYMENT_ERRORS)[keyof typeof CRYPTO_PAYMENT_ERRORS];\n\nexport const MODAL_TYPE = {\n A: 'A',\n B: 'B',\n} as const;\n\nexport type ModalType = (typeof MODAL_TYPE)[keyof typeof MODAL_TYPE];\n\n/** only usd for now */\nexport type Currency = 'usd';\n\nexport type Product = {\n name: ProductType;\n currency: Currency;\n unitAmount: number;\n unitDecimals: number;\n};\n\n// state\nexport type Subscription = {\n id: string;\n products: Product[];\n currentPeriodStart?: string; // ISO 8601\n currentPeriodEnd?: string; // ISO 8601\n /** is subscription scheduled for cancellation */\n cancelAtPeriodEnd?: boolean;\n status: SubscriptionStatus;\n interval: RecurringInterval;\n paymentMethod: SubscriptionPaymentMethod;\n trialPeriodDays?: number;\n trialStart?: string; // ISO 8601\n trialEnd?: string; // ISO 8601\n /** Crypto payment only: next billing cycle date (e.g after 12 months) */\n endDate?: string; // ISO 8601\n /** The date the subscription was canceled. */\n canceledAt?: string; // ISO 8601\n /** The cancellation type indicating what cancellation options are available for this subscription. */\n cancelType?: CancelType;\n /** The date the subscription was marked as inactive (paused/past_due/canceled). */\n inactiveAt?: string; // ISO 8601\n /** Whether the user is eligible for support features (priority support and filing claims). True for active subscriptions and inactive subscriptions within grace period. */\n isEligibleForSupport?: boolean;\n billingCycles?: number;\n /** The most recent invoice associated with the subscription. */\n lastInvoice?: SubscriptionInvoice;\n};\n\nexport type SubscriptionInvoice = {\n id: string;\n status: InvoicePaymentStatus;\n errorCode?: CryptoPaymentError;\n updatedAt?: string; // ISO 8601\n};\n\nexport type SubscriptionCardPaymentMethod = {\n type: Extract<PaymentType, 'card'>;\n card: {\n brand: string;\n /** display brand account for dual brand card */\n displayBrand?: string;\n last4: string;\n };\n};\n\nexport type SubscriptionCryptoPaymentMethod = {\n type: Extract<PaymentType, 'crypto'>;\n crypto: {\n payerAddress: Hex;\n chainId: Hex;\n tokenSymbol: string;\n error?: CryptoPaymentMethodError;\n };\n};\n\nexport type SubscriptionPaymentMethod =\n | SubscriptionCardPaymentMethod\n | SubscriptionCryptoPaymentMethod;\n\nexport type GetSubscriptionsResponse = {\n customerId?: string;\n subscriptions: Subscription[];\n trialedProducts: ProductType[];\n productEntitlements?: ProductEntitlements;\n /** The last subscription that user has subscribed to if any. */\n lastSubscription?: Subscription;\n /** The reward account ID if user has linked rewards to the subscription. */\n rewardAccountId?: CaipAccountId;\n};\n\n/**\n * Benefits available to a subscription user.\n */\nexport type SwapsBenefitUsage = {\n feeBips: string | null;\n capMicroUsd?: number;\n consumedMicroUsd?: number;\n remainingMicroUsd: number | null;\n exhausted: boolean;\n};\n\nexport type PerpsBenefitUsage = {\n builderFeeBips: string | null;\n builderCode: string | null;\n capMicroUsd?: number;\n consumedMicroUsd?: number;\n remainingMicroUsd: number | null;\n exhausted: boolean;\n};\n\nexport type PredictBenefitUsage = {\n builderCode: string | null;\n capTxCount?: number;\n consumedTxCount?: number;\n remainingTxCount: number | null;\n exhausted: boolean;\n};\n\ntype SubscriptionBenefitsProducts = {\n swaps: SwapsBenefitUsage;\n perps: PerpsBenefitUsage;\n predict: PredictBenefitUsage;\n};\n\nexport type SubscriptionBenefitsResponse = {\n eligible: boolean;\n billingPeriodId: string | null;\n products: SubscriptionBenefitsProducts;\n};\n\n/**\n * Benefits state exposed to the UI.\n */\nexport type SubscriptionBenefitsState = SubscriptionBenefitsProducts & {\n billingPeriodId: string | null;\n};\n\nexport type StartSubscriptionRequest = {\n products: ProductType[];\n isTrialRequested: boolean;\n recurringInterval: RecurringInterval;\n successUrl?: string;\n cancelUrl?: string;\n useTestClock?: boolean;\n\n /**\n * Whether the user is eligible for a refund (e.g. EU/EEA withdrawal rights).\n *\n * When provided, this value is sent as-is and the geolocation check is\n * skipped. When omitted, the controller resolves it from geolocation.\n */\n isEligibleForRefund?: boolean;\n\n /**\n * Optional CAIP account ID of the rewards account to opt in alongside this\n * subscription. Required when the user wants to link rewards during\n * subscription creation.\n *\n * @example {\n * rewardAccountId: 'eip155:1:0x1234567890123456789012345678901234567890',\n * }\n */\n rewardAccountId?: CaipAccountId;\n};\n\nexport type StartSubscriptionResponse = {\n checkoutSessionUrl: string;\n};\n\ntype StartCryptoSubscriptionRequestBase = {\n products: ProductType[];\n isTrialRequested: boolean;\n recurringInterval: RecurringInterval;\n billingCycles: number;\n chainId: Hex;\n payerAddress: Hex;\n /**\n * e.g. \"USDC\"\n */\n tokenSymbol: string;\n /**\n * Reject if authoritative trial eligibility changed since authorization.\n */\n assertTrialEligibility?: boolean;\n isSponsored?: boolean;\n useTestClock?: boolean;\n\n /**\n * Whether the user is eligible for a refund (e.g. EU/EEA withdrawal rights).\n *\n * When provided, this value is sent as-is and the geolocation check is\n * skipped. When omitted, the controller resolves it from geolocation.\n */\n isEligibleForRefund?: boolean;\n\n /**\n * Optional CAIP account ID of the rewards account to opt in alongside this\n * subscription. Required when the user wants to link rewards during\n * subscription creation.\n *\n * @example {\n * rewardAccountId: 'eip155:1:0x1234567890123456789012345678901234567890',\n * }\n */\n rewardAccountId?: CaipAccountId;\n};\n\n/**\n * ERC-20 approval crypto subscription request (e.g. Shield).\n *\n * `cryptoAuthMethod` defaults to `CRYPTO_AUTH_METHODS.ERC20_APPROVAL` when\n * omitted.\n */\nexport type StartErc20CryptoSubscriptionRequest =\n StartCryptoSubscriptionRequestBase & {\n cryptoAuthMethod?: typeof CRYPTO_AUTH_METHODS.ERC20_APPROVAL;\n rawTransaction: Hex;\n delegationHash?: never;\n };\n\n/**\n * Delegation-based crypto subscription request (e.g. Money Account Plus).\n */\nexport type StartDelegationCryptoSubscriptionRequest =\n StartCryptoSubscriptionRequestBase & {\n cryptoAuthMethod: typeof CRYPTO_AUTH_METHODS.DELEGATION;\n delegationHash: Hex;\n rawTransaction?: never;\n };\n\n/**\n * Request to start a crypto subscription.\n *\n * Discriminated union of ERC-20 approval vs delegation. Provide\n * `rawTransaction` for ERC-20 approval (the default when `cryptoAuthMethod` is\n * omitted), or `delegationHash` with `cryptoAuthMethod: 'delegation'`.\n * Combining or omitting both is a type error, and is also rejected at runtime\n * by `startSubscriptionWithCrypto`.\n */\nexport type StartCryptoSubscriptionRequest =\n | StartErc20CryptoSubscriptionRequest\n | StartDelegationCryptoSubscriptionRequest;\n\n/**\n * Response of `POST /subscriptions/crypto`.\n *\n * Unlike card checkout, a crypto start creates the subscription immediately,\n * so the Subscription API returns the created {@link Subscription} itself.\n */\nexport type StartCryptoSubscriptionResponse = Subscription;\n\n/**\n * General response type for the subscription API requests\n * which doesn't require any specific response data.\n */\nexport type SubscriptionApiGeneralResponse = {\n /**\n * Whether the request was successful.\n */\n success: boolean;\n /**\n * The message of the response.\n */\n message?: string;\n};\n\nexport type CancelSubscriptionRequest = {\n subscriptionId: string;\n /** Whether to cancel at the end of the current period */\n cancelAtPeriodEnd?: boolean;\n /** Stable reason code for the cancellation. */\n cancellationReason?: CancellationReasonCode;\n /** Optional free-text feedback for the cancellation. */\n cancellationFeedback?: string;\n};\n\nexport type AuthUtils = {\n getAccessToken: () => Promise<string>;\n};\n\nexport type ProductPrice = {\n interval: RecurringInterval;\n unitAmount: number; // amount in the smallest unit of the currency, e.g., cents\n unitDecimals: number; // number of decimals for the smallest unit of the currency\n /** only usd for now */\n currency: Currency;\n trialPeriodDays: number;\n /** min billing cycles for approval */\n minBillingCycles: number;\n /** min billing cycles for account balance check */\n minBillingCyclesForBalance: number;\n};\n\nexport type ProductPricing = {\n name: ProductType;\n prices: ProductPrice[];\n};\n\ntype TokenPaymentInfoBase = {\n symbol: string;\n address: Hex;\n decimals: number;\n /**\n * example: {\n usd: '1.0',\n },\n */\n conversionRate?: {\n usd: string;\n };\n /**\n * Source tokens that can be converted into this settlement token.\n */\n sources?: TokenPaymentInfo[];\n};\n\n/**\n * Named vault a vault-share settlement token belongs to, e.g. `base` or\n * `premium`. Distinguishes which vault to withdraw from.\n *\n * Deliberately a plain `string` rather than a union: the set of vaults is\n * server-driven and grows without a client release, so narrowing it here would\n * make the pricing response fail validation the first time the API adds a\n * vault. Compare against `VAULT_NAMES` instead of raw literals, and always\n * handle the unknown case.\n */\nexport type VaultName = string;\n\n/**\n * The vault names known at the time of writing. Not exhaustive — see\n * {@link VaultName}.\n */\nexport const VAULT_NAMES = {\n base: 'base',\n premium: 'premium',\n} as const;\n\n/**\n * Spot (non-vault) settlement token. Priced via `conversionRate` when provided.\n * Neither `accountantAddress` nor `vault` is present on this variant.\n */\nexport type SpotTokenPaymentInfo = TokenPaymentInfoBase;\n\n/**\n * Yield-bearing vault share priced via an accountant rate.\n */\nexport type VaultTokenPaymentInfo = TokenPaymentInfoBase & {\n /**\n * Veda accountant address used to value this vault share. Every vault has\n * its own accountant, so this is present on every vault-share token — which\n * is what makes it the discriminant for this variant.\n */\n accountantAddress: Hex;\n /**\n * Named vault this token is a share of. Sent only for vault-share tokens.\n */\n vault?: VaultName;\n};\n\n/**\n * A settlement token in a pricing chain. Discriminated by the presence of\n * `accountantAddress`: vault shares carry it (and may carry `vault`), spot\n * tokens carry neither.\n *\n * The API previously sent an explicit `isVaultShare` boolean. It no longer\n * does, so do not reintroduce a dependency on it — use\n * {@link isVaultShareToken}.\n */\nexport type TokenPaymentInfo = SpotTokenPaymentInfo | VaultTokenPaymentInfo;\n\n/**\n * Whether a settlement token is a yield-bearing vault share, which must be\n * valued through its accountant rate rather than at face value.\n *\n * @param token - The settlement token to check.\n * @returns True if the token is a vault share.\n */\nexport function isVaultShareToken(\n token: TokenPaymentInfo,\n): token is VaultTokenPaymentInfo {\n return (token as VaultTokenPaymentInfo).accountantAddress !== undefined;\n}\n\nexport type ChainPaymentInfo = {\n chainId: Hex;\n paymentAddress: Hex;\n /**\n * Delegate address clients authorize when using the delegation auth method.\n */\n delegateAddress?: Hex;\n tokens: TokenPaymentInfo[];\n /**\n * Whether the chain supports sponsorship for the trialed subscription approval transaction.\n * This is used to determine if the user can be sponsored for the gas fees for the trialed subscription approval transaction.\n */\n isSponsorshipSupported?: boolean;\n};\n\nexport type PricingCardPaymentMethod = {\n type: Extract<PaymentType, 'card'>;\n /**\n * Products that support this payment method.\n */\n products?: ProductType[];\n};\n\nexport type PricingCryptoPaymentMethod = {\n type: Extract<PaymentType, 'crypto'>;\n /**\n * Crypto authorization method. Omitted together with `products` on persisted\n * pre-multi-product pricing rows; those rows are treated as Shield + `erc20_approval`.\n * If `products` is set, this field must be explicit.\n */\n cryptoAuthMethod?: CryptoAuthMethod;\n /**\n * Products that support this payment method. Omitted together with\n * `cryptoAuthMethod` on persisted pre-multi-product pricing rows (treated as Shield).\n * If present, must be non-empty and paired with an explicit `cryptoAuthMethod`.\n */\n products?: ProductType[];\n chains?: ChainPaymentInfo[];\n};\n\n/**\n * A pricing payment-method row. Discriminated by `type`: card rows have no\n * crypto fields; crypto rows may include `cryptoAuthMethod` and `chains`.\n */\nexport type PricingPaymentMethod =\n | PricingCardPaymentMethod\n | PricingCryptoPaymentMethod;\n\nexport type PricingResponse = {\n products: ProductPricing[];\n paymentMethods: PricingPaymentMethod[];\n};\n\nexport type GetCryptoApproveTransactionRequest = {\n /**\n * payment chain ID\n */\n chainId: Hex;\n /**\n * Payment token address\n */\n paymentTokenAddress: Hex;\n productType: ProductType;\n interval: RecurringInterval;\n};\n\nexport type GetCryptoApproveTransactionResponse = {\n /**\n * The amount to approve\n * e.g: \"100000000\"\n */\n approveAmount: string;\n /**\n * The contract address (spender)\n */\n paymentAddress: Hex;\n /**\n * The payment token address\n */\n paymentTokenAddress: Hex;\n chainId: Hex;\n};\n\n/**\n * Request to submit a Shield ERC-20 crypto approval transaction.\n */\nexport type SubmitSubscriptionCryptoApprovalRequest = {\n /**\n * The subscription product. Typed as `typeof PRODUCT_TYPES.SHIELD` only at\n * the moment (future might support more product).\n */\n productType: typeof PRODUCT_TYPES.SHIELD;\n /**\n * The transaction metadata. Must have type\n * `TransactionType.shieldSubscriptionApprove`.\n */\n txMeta: TransactionMeta;\n /**\n * Whether the transaction is sponsored.\n */\n isSponsored?: boolean;\n /**\n * The account ID of the reward subscription to link.\n */\n rewardAccountId?: CaipAccountId;\n};\n\nexport const COHORT_NAMES = {\n POST_TX: 'post_tx',\n WALLET_HOME: 'wallet_home',\n} as const;\n\nexport type CohortName = (typeof COHORT_NAMES)[keyof typeof COHORT_NAMES];\n\nexport const BALANCE_CATEGORIES = {\n RANGE_0_99: '0-99',\n RANGE_100_999: '100-999',\n RANGE_1K_9_9K: '1k-9.9k',\n RANGE_10K_99_9K: '10k-99.9k',\n RANGE_100K_999_9K: '100k-999.9k',\n RANGE_1M_PLUS: '1M+',\n} as const;\n\nexport type BalanceCategory =\n (typeof BALANCE_CATEGORIES)[keyof typeof BALANCE_CATEGORIES];\n\nexport type Cohort = {\n cohort: string;\n eligibilityRate: number; // 0-1 probability of being assigned to this cohort\n priority: number; // lower number = higher priority\n eligible: boolean;\n};\n\nexport type SubscriptionEligibility = {\n product: ProductType;\n canSubscribe: boolean;\n canViewEntryModal: boolean;\n modalType?: ModalType;\n cohorts: Cohort[];\n assignedCohort: string | null;\n hasAssignedCohortExpired: boolean;\n};\n\nexport const SubscriptionUserEvent = {\n ShieldEntryModalViewed: 'shield_entry_modal_viewed',\n ShieldCohortAssigned: 'shield_cohort_assigned',\n} as const;\n\nexport type SubscriptionUserEventType =\n (typeof SubscriptionUserEvent)[keyof typeof SubscriptionUserEvent];\n\nexport type SubmitUserEventRequest = {\n event: SubscriptionUserEventType;\n cohort?: string;\n};\n\nexport type AssignCohortRequest = {\n cohort: string;\n};\n\nexport type GetSubscriptionsEligibilitiesRequest = {\n balanceCategory?: BalanceCategory;\n};\n\n/**\n * Request object for submitting sponsorship intents.\n */\nexport type SubmitSponsorshipIntentsRequest = {\n chainId: Hex;\n address: Hex;\n products: ProductType[];\n paymentTokenSymbol: string;\n recurringInterval: RecurringInterval;\n billingCycles: number;\n};\n\nexport type SubmitSponsorshipIntentsMethodParams = Pick<\n SubmitSponsorshipIntentsRequest,\n 'chainId' | 'address' | 'products'\n>;\n\nexport type ISubscriptionService = {\n getSubscriptions(): Promise<GetSubscriptionsResponse>;\n getBenefits(): Promise<SubscriptionBenefitsResponse>;\n cancelSubscription(request: CancelSubscriptionRequest): Promise<Subscription>;\n unCancelSubscription(request: {\n subscriptionId: string;\n }): Promise<Subscription>;\n /**\n * Starts a card-paid subscription checkout session for the requested products\n * (e.g. Shield or Money Account Plus).\n *\n * @param request - The start subscription request.\n * @returns The checkout session response.\n */\n startSubscriptionWithCard(\n request: StartSubscriptionRequest,\n ): Promise<StartSubscriptionResponse>;\n getBillingPortalUrl(): Promise<BillingPortalResponse>;\n getPricing(): Promise<PricingResponse>;\n startSubscriptionWithCrypto(\n request: StartCryptoSubscriptionRequest,\n ): Promise<StartCryptoSubscriptionResponse>;\n updatePaymentMethodCard(\n request: UpdatePaymentMethodCardRequest,\n ): Promise<UpdatePaymentMethodCardResponse>;\n updatePaymentMethodCrypto(\n request: UpdatePaymentMethodCryptoRequest,\n ): Promise<void>;\n getSubscriptionsEligibilities(\n request?: GetSubscriptionsEligibilitiesRequest,\n ): Promise<SubscriptionEligibility[]>;\n submitUserEvent(request: SubmitUserEventRequest): Promise<void>;\n assignUserToCohort(request: AssignCohortRequest): Promise<void>;\n\n /**\n * Link rewards to a subscription.\n */\n linkRewards(\n request: LinkRewardsRequest,\n ): Promise<SubscriptionApiGeneralResponse>;\n\n /**\n * Submit sponsorship intents to the Subscription Service backend.\n *\n * This is intended to be used together with the crypto subscription flow.\n * When the user has enabled the smart transaction feature, we will sponsor the gas fees for the subscription approval transaction.\n *\n * @param request - Request object containing the address and products.\n * @example {\n * address: '0x1234567890123456789012345678901234567890',\n * products: [ProductType.Shield],\n * recurringInterval: RecurringInterval.Month,\n * billingCycles: 1,\n * }\n */\n submitSponsorshipIntents(\n request: SubmitSponsorshipIntentsRequest,\n ): Promise<void>;\n};\n\nexport type UpdatePaymentMethodOpts =\n | ({\n paymentType: Extract<PaymentType, 'card'>;\n } & UpdatePaymentMethodCardRequest)\n | ({\n paymentType: Extract<PaymentType, 'crypto'>;\n } & UpdatePaymentMethodCryptoRequest);\n\nexport type UpdatePaymentMethodCardRequest = {\n /**\n * Subscription ID\n */\n subscriptionId: string;\n\n /**\n * Recurring interval\n */\n recurringInterval: RecurringInterval;\n successUrl?: string;\n cancelUrl?: string;\n};\n\nexport type UpdatePaymentMethodCardResponse = {\n redirectUrl: string;\n};\n\ntype UpdatePaymentMethodCryptoRequestBase = {\n subscriptionId: string;\n chainId: Hex;\n payerAddress: Hex;\n tokenSymbol: string;\n recurringInterval: RecurringInterval;\n billingCycles: number;\n};\n\n/**\n * ERC-20 approval crypto payment-method update request.\n *\n * `rawTransaction` may be omitted when retrying after a balance top-up.\n */\nexport type UpdateErc20PaymentMethodCryptoRequest =\n UpdatePaymentMethodCryptoRequestBase & {\n cryptoAuthMethod?: typeof CRYPTO_AUTH_METHODS.ERC20_APPROVAL;\n /**\n * The raw transaction to pay for the subscription.\n */\n rawTransaction?: Hex;\n delegationHash?: never;\n };\n\n/**\n * Delegation crypto payment-method update request used to rotate an active\n * subscription to a replacement delegation.\n */\nexport type UpdateDelegationPaymentMethodCryptoRequest =\n UpdatePaymentMethodCryptoRequestBase & {\n cryptoAuthMethod: typeof CRYPTO_AUTH_METHODS.DELEGATION;\n delegationHash: Hex;\n rawTransaction?: never;\n };\n\n/**\n * Request to update a subscription's crypto payment method.\n *\n * Provide `rawTransaction` for the existing ERC-20 approval path, or provide\n * `cryptoAuthMethod: 'delegation'` and `delegationHash` to rotate a delegation.\n */\nexport type UpdatePaymentMethodCryptoRequest =\n | UpdateErc20PaymentMethodCryptoRequest\n | UpdateDelegationPaymentMethodCryptoRequest;\n\nexport type BillingPortalResponse = {\n url: string;\n};\n\n/**\n * The cached result of last selected payment methods for the user.\n * These details are being cached to be used internally to track the last selected payment method for the user. (e.g. for crypto subscriptions)\n */\nexport type CachedLastSelectedPaymentMethod = {\n type: PaymentType;\n paymentTokenAddress?: Hex;\n paymentTokenSymbol?: string;\n plan: RecurringInterval;\n useTestClock?: boolean;\n /**\n * Crypto authorization method. Omitted on persisted cache entries written\n * before this field existed; treat as `erc20_approval` when missing.\n */\n cryptoAuthMethod?: CryptoAuthMethod;\n};\n\n/**\n * Request to cache the last selected payment method for a product.\n */\nexport type CacheLastSelectedPaymentMethodRequest = {\n /**\n * The product to cache the payment method for.\n */\n product: ProductType;\n /**\n * The payment method to cache.\n */\n paymentMethod: CachedLastSelectedPaymentMethod;\n};\n\n/**\n * Request object for linking rewards to a subscription.\n */\nexport type LinkRewardsRequest = {\n /**\n * The ID of the reward subscription to be linked to the subscription.\n *\n * @example {\n * rewardAccountId: 'eip155:1:0x1234567890123456789012345678901234567890',\n * }\n */\n rewardAccountId: CaipAccountId;\n};\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"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","sourcesContent":["import type { TransactionMeta } from '@metamask/transaction-controller';\nimport type { CaipAccountId, Hex } from '@metamask/utils';\n\nimport type { CANCELLATION_REASONS } from './constants.js';\n\n/**\n * Error response from the Subscription API.\n */\nexport type SubscriptionApiError = {\n errorCode?: string;\n message?: string;\n statusCode?: number;\n};\n\n/**\n * Supported subscription products.\n */\nexport const PRODUCT_TYPES = {\n /**\n * MetaMask Shield.\n */\n SHIELD: 'shield',\n /**\n * Money Account Plus (delegation-based crypto billing).\n */\n MONEY_ACCOUNT_PLUS: 'money_account_plus',\n} as const;\n\nexport type ProductType = (typeof PRODUCT_TYPES)[keyof typeof PRODUCT_TYPES];\n\nexport const MoneyAccountFeature = {\n SwapFeeWaiver: 'swapFeeWaiver',\n PerpsFeeWaiver: 'perpsFeeWaiver',\n PredictFreeTx: 'predictFreeTx',\n PremiumApy: 'premiumApy',\n} as const;\n\nexport type MoneyAccountFeature =\n (typeof MoneyAccountFeature)[keyof typeof MoneyAccountFeature];\n\nexport type MoneyAccountEntitlements = Record<MoneyAccountFeature, boolean>;\n\nexport const ShieldFeature = {\n ShieldClaim: 'shieldClaim',\n PrioritySupport: 'prioritySupport',\n} as const;\n\nexport type ShieldFeature = (typeof ShieldFeature)[keyof typeof ShieldFeature];\n\nexport type ShieldEntitlements = Record<ShieldFeature, boolean>;\n\nexport type MoneyAccountPlusClaim = {\n plan: string;\n entitlements: MoneyAccountEntitlements;\n};\n\nexport type ProductEntitlements = {\n [PRODUCT_TYPES.SHIELD]?: {\n entitlements: ShieldEntitlements;\n };\n [PRODUCT_TYPES.MONEY_ACCOUNT_PLUS]?: MoneyAccountPlusClaim;\n};\n\nexport type ProductEntitlementFeatureMap = {\n [PRODUCT_TYPES.SHIELD]: ShieldFeature;\n [PRODUCT_TYPES.MONEY_ACCOUNT_PLUS]: MoneyAccountFeature;\n};\n\n/**\n * How a crypto subscription is authorized.\n *\n * Use `erc20_approval` with `rawTransaction` (e.g. Shield). Use `delegation`\n * with `delegationHash` (e.g. Money Account Plus).\n */\nexport const CRYPTO_AUTH_METHODS = {\n /**\n * User signs an ERC-20 approve transaction.\n */\n ERC20_APPROVAL: 'erc20_approval',\n /**\n * User authorizes via a stored delegation hash.\n */\n DELEGATION: 'delegation',\n} as const;\n\nexport type CryptoAuthMethod =\n (typeof CRYPTO_AUTH_METHODS)[keyof typeof CRYPTO_AUTH_METHODS];\n\nexport const PAYMENT_TYPES = {\n byCard: 'card',\n byCrypto: 'crypto',\n} as const;\n\nexport type PaymentType = (typeof PAYMENT_TYPES)[keyof typeof PAYMENT_TYPES];\n\nexport const RECURRING_INTERVALS = {\n month: 'month',\n year: 'year',\n} as const;\n\nexport type RecurringInterval =\n (typeof RECURRING_INTERVALS)[keyof typeof RECURRING_INTERVALS];\n\nexport const SUBSCRIPTION_STATUSES = {\n // Initial states\n incomplete: 'incomplete',\n incompleteExpired: 'incomplete_expired',\n /** Crypto subscription created, waiting for the payer to fund the first invoice. */\n awaitingFunds: 'awaiting_funds',\n // Active states\n provisional: 'provisional',\n trialing: 'trialing',\n active: 'active',\n // Payment issues\n pastDue: 'past_due',\n unpaid: 'unpaid',\n // Cancelled states\n canceled: 'canceled',\n // Paused states\n paused: 'paused',\n} as const;\n\nexport type SubscriptionStatus =\n (typeof SUBSCRIPTION_STATUSES)[keyof typeof SUBSCRIPTION_STATUSES];\n\nexport const INVOICE_PAYMENT_STATUSES = {\n PROCESSING: 'PROCESSING',\n SUCCEEDED: 'SUCCEEDED',\n FAILED: 'FAILED',\n UNKNOWN: 'UNKNOWN',\n} as const;\n\nexport type InvoicePaymentStatus =\n (typeof INVOICE_PAYMENT_STATUSES)[keyof typeof INVOICE_PAYMENT_STATUSES];\n\nexport const CANCEL_TYPES = {\n ALLOWED_IMMEDIATE: 'allowed_immediate',\n ALLOWED_AT_PERIOD_END: 'allowed_at_period_end',\n NOT_ALLOWED: 'not_allowed',\n NOT_ALLOWED_PENDING_VERIFICATION: 'not_allowed_pending_verification',\n} as const;\n\nexport type CancelType = (typeof CANCEL_TYPES)[keyof typeof CANCEL_TYPES];\n\nexport type CancellationReasonCode =\n (typeof CANCELLATION_REASONS)[keyof typeof CANCELLATION_REASONS];\n\nexport const CRYPTO_PAYMENT_METHOD_ERRORS = {\n APPROVAL_TRANSACTION_TOO_OLD: 'approval_transaction_too_old',\n APPROVAL_TRANSACTION_REVERTED: 'approval_transaction_reverted',\n APPROVAL_TRANSACTION_MAX_VERIFICATION_ATTEMPTS_REACHED:\n 'approval_transaction_max_verification_attempts_reached',\n INSUFFICIENT_BALANCE: 'insufficient_balance',\n INSUFFICIENT_ALLOWANCE: 'insufficient_allowance',\n} as const;\n\nexport type CryptoPaymentMethodError =\n (typeof CRYPTO_PAYMENT_METHOD_ERRORS)[keyof typeof CRYPTO_PAYMENT_METHOD_ERRORS];\n\n/**\n * Errors returned by the Subscription API after crypto payment execution.\n *\n * These are distinct from {@link CRYPTO_PAYMENT_METHOD_ERRORS}, which describe\n * approval/payment-method failures.\n */\nexport const CRYPTO_PAYMENT_ERRORS = {\n INSUFFICIENT_BALANCE: 'insufficient_balance',\n INSUFFICIENT_ALLOWANCE: 'insufficient_allowance',\n EXCEEDS_DELEGATION_ALLOWANCE: 'exceeds_delegation_allowance',\n DELEGATION_NOT_FOUND: 'delegation_not_found',\n DELEGATION_REVOKED: 'delegation_revoked',\n RECIPIENT_NOT_ALLOWLISTED: 'recipient_not_allowlisted',\n INTERNAL_SERVER_ERROR: 'internal_server_error',\n} as const;\n\nexport type CryptoPaymentError =\n (typeof CRYPTO_PAYMENT_ERRORS)[keyof typeof CRYPTO_PAYMENT_ERRORS];\n\nexport const MODAL_TYPE = {\n A: 'A',\n B: 'B',\n} as const;\n\nexport type ModalType = (typeof MODAL_TYPE)[keyof typeof MODAL_TYPE];\n\n/** only usd for now */\nexport type Currency = 'usd';\n\nexport type Product = {\n name: ProductType;\n currency: Currency;\n unitAmount: number;\n unitDecimals: number;\n};\n\n// state\nexport type Subscription = {\n id: string;\n products: Product[];\n currentPeriodStart: string; // ISO 8601\n currentPeriodEnd: string; // ISO 8601\n /** is subscription scheduled for cancellation */\n cancelAtPeriodEnd?: boolean;\n status: SubscriptionStatus;\n interval: RecurringInterval;\n paymentMethod: SubscriptionPaymentMethod;\n trialPeriodDays?: number;\n trialStart?: string; // ISO 8601\n trialEnd?: string; // ISO 8601\n /** Crypto payment only: next billing cycle date (e.g after 12 months) */\n endDate?: string; // ISO 8601\n /** The date the subscription was canceled. */\n canceledAt?: string; // ISO 8601\n /** The cancellation type indicating what cancellation options are available for this subscription. */\n cancelType: CancelType;\n /** The date the subscription was marked as inactive (paused/past_due/canceled). */\n inactiveAt?: string; // ISO 8601\n /** Whether the user is eligible for support features (priority support and filing claims). True for active subscriptions and inactive subscriptions within grace period. */\n isEligibleForSupport: boolean;\n billingCycles?: number;\n /** The most recent invoice associated with the subscription. */\n lastInvoice?: SubscriptionInvoice;\n};\n\nexport type SubscriptionInvoice = {\n id: string;\n status: InvoicePaymentStatus;\n errorCode?: CryptoPaymentError;\n updatedAt?: string; // ISO 8601\n};\n\nexport type SubscriptionCardPaymentMethod = {\n type: Extract<PaymentType, 'card'>;\n card: {\n brand: string;\n /** display brand account for dual brand card */\n displayBrand?: string;\n last4: string;\n };\n};\n\nexport type SubscriptionCryptoPaymentMethod = {\n type: Extract<PaymentType, 'crypto'>;\n crypto: {\n payerAddress: Hex;\n chainId: Hex;\n tokenSymbol: string;\n error?: CryptoPaymentMethodError;\n };\n};\n\nexport type SubscriptionPaymentMethod =\n | SubscriptionCardPaymentMethod\n | SubscriptionCryptoPaymentMethod;\n\nexport type GetSubscriptionsResponse = {\n customerId?: string;\n subscriptions: Subscription[];\n trialedProducts: ProductType[];\n productEntitlements?: ProductEntitlements;\n /** The last subscription that user has subscribed to if any. */\n lastSubscription?: Subscription;\n /** The reward account ID if user has linked rewards to the subscription. */\n rewardAccountId?: CaipAccountId;\n};\n\n/**\n * Benefits available to a subscription user.\n */\nexport type SwapsBenefitUsage = {\n feeBips: string | null;\n capMicroUsd?: number;\n consumedMicroUsd?: number;\n remainingMicroUsd: number | null;\n exhausted: boolean;\n};\n\nexport type PerpsBenefitUsage = {\n builderFeeBips: string | null;\n builderCode: string | null;\n capMicroUsd?: number;\n consumedMicroUsd?: number;\n remainingMicroUsd: number | null;\n exhausted: boolean;\n};\n\nexport type PredictBenefitUsage = {\n builderCode: string | null;\n capTxCount?: number;\n consumedTxCount?: number;\n remainingTxCount: number | null;\n exhausted: boolean;\n};\n\ntype SubscriptionBenefitsProducts = {\n swaps: SwapsBenefitUsage;\n perps: PerpsBenefitUsage;\n predict: PredictBenefitUsage;\n};\n\nexport type SubscriptionBenefitsResponse = {\n eligible: boolean;\n billingPeriodId: string | null;\n products: SubscriptionBenefitsProducts;\n};\n\n/**\n * Benefits state exposed to the UI.\n */\nexport type SubscriptionBenefitsState = SubscriptionBenefitsProducts & {\n billingPeriodId: string | null;\n};\n\nexport type StartSubscriptionRequest = {\n products: ProductType[];\n isTrialRequested: boolean;\n recurringInterval: RecurringInterval;\n successUrl?: string;\n cancelUrl?: string;\n useTestClock?: boolean;\n\n /**\n * Whether the user is eligible for a refund (e.g. EU/EEA withdrawal rights).\n *\n * When provided, this value is sent as-is and the geolocation check is\n * skipped. When omitted, the controller resolves it from geolocation.\n */\n isEligibleForRefund?: boolean;\n\n /**\n * Optional CAIP account ID of the rewards account to opt in alongside this\n * subscription. Required when the user wants to link rewards during\n * subscription creation.\n *\n * @example {\n * rewardAccountId: 'eip155:1:0x1234567890123456789012345678901234567890',\n * }\n */\n rewardAccountId?: CaipAccountId;\n};\n\nexport type StartSubscriptionResponse = {\n checkoutSessionUrl: string;\n};\n\ntype StartCryptoSubscriptionRequestBase = {\n products: ProductType[];\n isTrialRequested: boolean;\n recurringInterval: RecurringInterval;\n billingCycles: number;\n chainId: Hex;\n payerAddress: Hex;\n /**\n * e.g. \"USDC\"\n */\n tokenSymbol: string;\n /**\n * Reject if authoritative trial eligibility changed since authorization.\n */\n assertTrialEligibility?: boolean;\n isSponsored?: boolean;\n useTestClock?: boolean;\n\n /**\n * Whether the user is eligible for a refund (e.g. EU/EEA withdrawal rights).\n *\n * When provided, this value is sent as-is and the geolocation check is\n * skipped. When omitted, the controller resolves it from geolocation.\n */\n isEligibleForRefund?: boolean;\n\n /**\n * Optional CAIP account ID of the rewards account to opt in alongside this\n * subscription. Required when the user wants to link rewards during\n * subscription creation.\n *\n * @example {\n * rewardAccountId: 'eip155:1:0x1234567890123456789012345678901234567890',\n * }\n */\n rewardAccountId?: CaipAccountId;\n};\n\n/**\n * ERC-20 approval crypto subscription request (e.g. Shield).\n *\n * `cryptoAuthMethod` defaults to `CRYPTO_AUTH_METHODS.ERC20_APPROVAL` when\n * omitted.\n */\nexport type StartErc20CryptoSubscriptionRequest =\n StartCryptoSubscriptionRequestBase & {\n cryptoAuthMethod?: typeof CRYPTO_AUTH_METHODS.ERC20_APPROVAL;\n rawTransaction: Hex;\n delegationHash?: never;\n };\n\n/**\n * Delegation-based crypto subscription request (e.g. Money Account Plus).\n */\nexport type StartDelegationCryptoSubscriptionRequest =\n StartCryptoSubscriptionRequestBase & {\n cryptoAuthMethod: typeof CRYPTO_AUTH_METHODS.DELEGATION;\n delegationHash: Hex;\n rawTransaction?: never;\n };\n\n/**\n * Request to start a crypto subscription.\n *\n * Discriminated union of ERC-20 approval vs delegation. Provide\n * `rawTransaction` for ERC-20 approval (the default when `cryptoAuthMethod` is\n * omitted), or `delegationHash` with `cryptoAuthMethod: 'delegation'`.\n * Combining or omitting both is a type error, and is also rejected at runtime\n * by `startSubscriptionWithCrypto`.\n */\nexport type StartCryptoSubscriptionRequest =\n | StartErc20CryptoSubscriptionRequest\n | StartDelegationCryptoSubscriptionRequest;\n\n/**\n * Response of `POST /subscriptions/crypto`.\n *\n * Unlike card checkout, a crypto start creates the subscription immediately,\n * so the Subscription API returns the created {@link Subscription} itself.\n */\nexport type StartCryptoSubscriptionResponse = Subscription;\n\n/**\n * General response type for the subscription API requests\n * which doesn't require any specific response data.\n */\nexport type SubscriptionApiGeneralResponse = {\n /**\n * Whether the request was successful.\n */\n success: boolean;\n /**\n * The message of the response.\n */\n message?: string;\n};\n\nexport type CancelSubscriptionRequest = {\n subscriptionId: string;\n /** Whether to cancel at the end of the current period */\n cancelAtPeriodEnd?: boolean;\n /** Stable reason code for the cancellation. */\n cancellationReason?: CancellationReasonCode;\n /** Optional free-text feedback for the cancellation. */\n cancellationFeedback?: string;\n};\n\nexport type AuthUtils = {\n getAccessToken: () => Promise<string>;\n};\n\nexport type ProductPrice = {\n interval: RecurringInterval;\n unitAmount: number; // amount in the smallest unit of the currency, e.g., cents\n unitDecimals: number; // number of decimals for the smallest unit of the currency\n /** only usd for now */\n currency: Currency;\n trialPeriodDays: number;\n /** min billing cycles for approval */\n minBillingCycles: number;\n /** min billing cycles for account balance check */\n minBillingCyclesForBalance: number;\n};\n\nexport type ProductPricing = {\n name: ProductType;\n prices: ProductPrice[];\n};\n\ntype TokenPaymentInfoBase = {\n symbol: string;\n address: Hex;\n decimals: number;\n /**\n * example: {\n usd: '1.0',\n },\n */\n conversionRate?: {\n usd: string;\n };\n /**\n * Source tokens that can be converted into this settlement token.\n */\n sources?: TokenPaymentInfo[];\n};\n\n/**\n * Named vault a vault-share settlement token belongs to, e.g. `base` or\n * `premium`. Distinguishes which vault to withdraw from.\n *\n * Deliberately a plain `string` rather than a union: the set of vaults is\n * server-driven and grows without a client release, so narrowing it here would\n * make the pricing response fail validation the first time the API adds a\n * vault. Compare against `VAULT_NAMES` instead of raw literals, and always\n * handle the unknown case.\n */\nexport type VaultName = string;\n\n/**\n * The vault names known at the time of writing. Not exhaustive — see\n * {@link VaultName}.\n */\nexport const VAULT_NAMES = {\n base: 'base',\n premium: 'premium',\n} as const;\n\n/**\n * Spot (non-vault) settlement token. Priced via `conversionRate` when provided.\n * Neither `accountantAddress` nor `vault` is present on this variant.\n */\nexport type SpotTokenPaymentInfo = TokenPaymentInfoBase;\n\n/**\n * Yield-bearing vault share priced via an accountant rate.\n */\nexport type VaultTokenPaymentInfo = TokenPaymentInfoBase & {\n /**\n * Veda accountant address used to value this vault share. Every vault has\n * its own accountant, so this is present on every vault-share token — which\n * is what makes it the discriminant for this variant.\n */\n accountantAddress: Hex;\n /**\n * Named vault this token is a share of. Sent only for vault-share tokens.\n */\n vault?: VaultName;\n};\n\n/**\n * A settlement token in a pricing chain. Discriminated by the presence of\n * `accountantAddress`: vault shares carry it (and may carry `vault`), spot\n * tokens carry neither.\n *\n * The API previously sent an explicit `isVaultShare` boolean. It no longer\n * does, so do not reintroduce a dependency on it — use\n * {@link isVaultShareToken}.\n */\nexport type TokenPaymentInfo = SpotTokenPaymentInfo | VaultTokenPaymentInfo;\n\n/**\n * Whether a settlement token is a yield-bearing vault share, which must be\n * valued through its accountant rate rather than at face value.\n *\n * @param token - The settlement token to check.\n * @returns True if the token is a vault share.\n */\nexport function isVaultShareToken(\n token: TokenPaymentInfo,\n): token is VaultTokenPaymentInfo {\n return (token as VaultTokenPaymentInfo).accountantAddress !== undefined;\n}\n\nexport type ChainPaymentInfo = {\n chainId: Hex;\n paymentAddress: Hex;\n /**\n * Delegate address clients authorize when using the delegation auth method.\n */\n delegateAddress?: Hex;\n tokens: TokenPaymentInfo[];\n /**\n * Whether the chain supports sponsorship for the trialed subscription approval transaction.\n * This is used to determine if the user can be sponsored for the gas fees for the trialed subscription approval transaction.\n */\n isSponsorshipSupported?: boolean;\n};\n\nexport type PricingCardPaymentMethod = {\n type: Extract<PaymentType, 'card'>;\n /**\n * Products that support this payment method.\n */\n products?: ProductType[];\n};\n\nexport type PricingCryptoPaymentMethod = {\n type: Extract<PaymentType, 'crypto'>;\n /**\n * Crypto authorization method. Omitted together with `products` on persisted\n * pre-multi-product pricing rows; those rows are treated as Shield + `erc20_approval`.\n * If `products` is set, this field must be explicit.\n */\n cryptoAuthMethod?: CryptoAuthMethod;\n /**\n * Products that support this payment method. Omitted together with\n * `cryptoAuthMethod` on persisted pre-multi-product pricing rows (treated as Shield).\n * If present, must be non-empty and paired with an explicit `cryptoAuthMethod`.\n */\n products?: ProductType[];\n chains?: ChainPaymentInfo[];\n};\n\n/**\n * A pricing payment-method row. Discriminated by `type`: card rows have no\n * crypto fields; crypto rows may include `cryptoAuthMethod` and `chains`.\n */\nexport type PricingPaymentMethod =\n | PricingCardPaymentMethod\n | PricingCryptoPaymentMethod;\n\nexport type PricingResponse = {\n products: ProductPricing[];\n paymentMethods: PricingPaymentMethod[];\n};\n\nexport type GetCryptoApproveTransactionRequest = {\n /**\n * payment chain ID\n */\n chainId: Hex;\n /**\n * Payment token address\n */\n paymentTokenAddress: Hex;\n productType: ProductType;\n interval: RecurringInterval;\n};\n\nexport type GetCryptoApproveTransactionResponse = {\n /**\n * The amount to approve\n * e.g: \"100000000\"\n */\n approveAmount: string;\n /**\n * The contract address (spender)\n */\n paymentAddress: Hex;\n /**\n * The payment token address\n */\n paymentTokenAddress: Hex;\n chainId: Hex;\n};\n\n/**\n * Request to submit a Shield ERC-20 crypto approval transaction.\n */\nexport type SubmitSubscriptionCryptoApprovalRequest = {\n /**\n * The subscription product. Typed as `typeof PRODUCT_TYPES.SHIELD` only at\n * the moment (future might support more product).\n */\n productType: typeof PRODUCT_TYPES.SHIELD;\n /**\n * The transaction metadata. Must have type\n * `TransactionType.shieldSubscriptionApprove`.\n */\n txMeta: TransactionMeta;\n /**\n * Whether the transaction is sponsored.\n */\n isSponsored?: boolean;\n /**\n * The account ID of the reward subscription to link.\n */\n rewardAccountId?: CaipAccountId;\n};\n\nexport const COHORT_NAMES = {\n POST_TX: 'post_tx',\n WALLET_HOME: 'wallet_home',\n} as const;\n\nexport type CohortName = (typeof COHORT_NAMES)[keyof typeof COHORT_NAMES];\n\nexport const BALANCE_CATEGORIES = {\n RANGE_0_99: '0-99',\n RANGE_100_999: '100-999',\n RANGE_1K_9_9K: '1k-9.9k',\n RANGE_10K_99_9K: '10k-99.9k',\n RANGE_100K_999_9K: '100k-999.9k',\n RANGE_1M_PLUS: '1M+',\n} as const;\n\nexport type BalanceCategory =\n (typeof BALANCE_CATEGORIES)[keyof typeof BALANCE_CATEGORIES];\n\nexport type Cohort = {\n cohort: string;\n eligibilityRate: number; // 0-1 probability of being assigned to this cohort\n priority: number; // lower number = higher priority\n eligible: boolean;\n};\n\nexport type SubscriptionEligibility = {\n product: ProductType;\n canSubscribe: boolean;\n canViewEntryModal: boolean;\n modalType?: ModalType;\n cohorts: Cohort[];\n assignedCohort: string | null;\n hasAssignedCohortExpired: boolean;\n};\n\nexport const SubscriptionUserEvent = {\n ShieldEntryModalViewed: 'shield_entry_modal_viewed',\n ShieldCohortAssigned: 'shield_cohort_assigned',\n} as const;\n\nexport type SubscriptionUserEventType =\n (typeof SubscriptionUserEvent)[keyof typeof SubscriptionUserEvent];\n\nexport type SubmitUserEventRequest = {\n event: SubscriptionUserEventType;\n cohort?: string;\n};\n\nexport type AssignCohortRequest = {\n cohort: string;\n};\n\nexport type GetSubscriptionsEligibilitiesRequest = {\n balanceCategory?: BalanceCategory;\n};\n\n/**\n * Request object for submitting sponsorship intents.\n */\nexport type SubmitSponsorshipIntentsRequest = {\n chainId: Hex;\n address: Hex;\n products: ProductType[];\n paymentTokenSymbol: string;\n recurringInterval: RecurringInterval;\n billingCycles: number;\n};\n\nexport type SubmitSponsorshipIntentsMethodParams = Pick<\n SubmitSponsorshipIntentsRequest,\n 'chainId' | 'address' | 'products'\n>;\n\nexport type ISubscriptionService = {\n getSubscriptions(): Promise<GetSubscriptionsResponse>;\n getBenefits(): Promise<SubscriptionBenefitsResponse>;\n cancelSubscription(request: CancelSubscriptionRequest): Promise<Subscription>;\n unCancelSubscription(request: {\n subscriptionId: string;\n }): Promise<Subscription>;\n /**\n * Starts a card-paid subscription checkout session for the requested products\n * (e.g. Shield or Money Account Plus).\n *\n * @param request - The start subscription request.\n * @returns The checkout session response.\n */\n startSubscriptionWithCard(\n request: StartSubscriptionRequest,\n ): Promise<StartSubscriptionResponse>;\n getBillingPortalUrl(): Promise<BillingPortalResponse>;\n getPricing(): Promise<PricingResponse>;\n startSubscriptionWithCrypto(\n request: StartCryptoSubscriptionRequest,\n ): Promise<StartCryptoSubscriptionResponse>;\n updatePaymentMethodCard(\n request: UpdatePaymentMethodCardRequest,\n ): Promise<UpdatePaymentMethodCardResponse>;\n updatePaymentMethodCrypto(\n request: UpdatePaymentMethodCryptoRequest,\n ): Promise<void>;\n getSubscriptionsEligibilities(\n request?: GetSubscriptionsEligibilitiesRequest,\n ): Promise<SubscriptionEligibility[]>;\n submitUserEvent(request: SubmitUserEventRequest): Promise<void>;\n assignUserToCohort(request: AssignCohortRequest): Promise<void>;\n\n /**\n * Link rewards to a subscription.\n */\n linkRewards(\n request: LinkRewardsRequest,\n ): Promise<SubscriptionApiGeneralResponse>;\n\n /**\n * Submit sponsorship intents to the Subscription Service backend.\n *\n * This is intended to be used together with the crypto subscription flow.\n * When the user has enabled the smart transaction feature, we will sponsor the gas fees for the subscription approval transaction.\n *\n * @param request - Request object containing the address and products.\n * @example {\n * address: '0x1234567890123456789012345678901234567890',\n * products: [ProductType.Shield],\n * recurringInterval: RecurringInterval.Month,\n * billingCycles: 1,\n * }\n */\n submitSponsorshipIntents(\n request: SubmitSponsorshipIntentsRequest,\n ): Promise<void>;\n};\n\nexport type UpdatePaymentMethodOpts =\n | ({\n paymentType: Extract<PaymentType, 'card'>;\n } & UpdatePaymentMethodCardRequest)\n | ({\n paymentType: Extract<PaymentType, 'crypto'>;\n } & UpdatePaymentMethodCryptoRequest);\n\nexport type UpdatePaymentMethodCardRequest = {\n /**\n * Subscription ID\n */\n subscriptionId: string;\n\n /**\n * Recurring interval\n */\n recurringInterval: RecurringInterval;\n successUrl?: string;\n cancelUrl?: string;\n};\n\nexport type UpdatePaymentMethodCardResponse = {\n redirectUrl: string;\n};\n\ntype UpdatePaymentMethodCryptoRequestBase = {\n subscriptionId: string;\n chainId: Hex;\n payerAddress: Hex;\n tokenSymbol: string;\n recurringInterval: RecurringInterval;\n billingCycles: number;\n};\n\n/**\n * ERC-20 approval crypto payment-method update request.\n *\n * `rawTransaction` may be omitted when retrying after a balance top-up.\n */\nexport type UpdateErc20PaymentMethodCryptoRequest =\n UpdatePaymentMethodCryptoRequestBase & {\n cryptoAuthMethod?: typeof CRYPTO_AUTH_METHODS.ERC20_APPROVAL;\n /**\n * The raw transaction to pay for the subscription.\n */\n rawTransaction?: Hex;\n delegationHash?: never;\n };\n\n/**\n * Delegation crypto payment-method update request used to rotate an active\n * subscription to a replacement delegation.\n */\nexport type UpdateDelegationPaymentMethodCryptoRequest =\n UpdatePaymentMethodCryptoRequestBase & {\n cryptoAuthMethod: typeof CRYPTO_AUTH_METHODS.DELEGATION;\n delegationHash: Hex;\n rawTransaction?: never;\n };\n\n/**\n * Request to update a subscription's crypto payment method.\n *\n * Provide `rawTransaction` for the existing ERC-20 approval path, or provide\n * `cryptoAuthMethod: 'delegation'` and `delegationHash` to rotate a delegation.\n */\nexport type UpdatePaymentMethodCryptoRequest =\n | UpdateErc20PaymentMethodCryptoRequest\n | UpdateDelegationPaymentMethodCryptoRequest;\n\nexport type BillingPortalResponse = {\n url: string;\n};\n\n/**\n * The cached result of last selected payment methods for the user.\n * These details are being cached to be used internally to track the last selected payment method for the user. (e.g. for crypto subscriptions)\n */\nexport type CachedLastSelectedPaymentMethod = {\n type: PaymentType;\n paymentTokenAddress?: Hex;\n paymentTokenSymbol?: string;\n plan: RecurringInterval;\n useTestClock?: boolean;\n /**\n * Crypto authorization method. Omitted on persisted cache entries written\n * before this field existed; treat as `erc20_approval` when missing.\n */\n cryptoAuthMethod?: CryptoAuthMethod;\n};\n\n/**\n * Request to cache the last selected payment method for a product.\n */\nexport type CacheLastSelectedPaymentMethodRequest = {\n /**\n * The product to cache the payment method for.\n */\n product: ProductType;\n /**\n * The payment method to cache.\n */\n paymentMethod: CachedLastSelectedPaymentMethod;\n};\n\n/**\n * Request object for linking rewards to a subscription.\n */\nexport type LinkRewardsRequest = {\n /**\n * The ID of the reward subscription to be linked to the subscription.\n *\n * @example {\n * rewardAccountId: 'eip155:1:0x1234567890123456789012345678901234567890',\n * }\n */\n rewardAccountId: CaipAccountId;\n};\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask/subscription-controller",
3
- "version": "13.0.0",
3
+ "version": "14.0.0",
4
4
  "description": "Handle user subscription",
5
5
  "keywords": [
6
6
  "Ethereum",
@@ -65,11 +65,11 @@
65
65
  "@metamask/money-account-upgrade-controller": "^5.1.0",
66
66
  "@metamask/money-account-utils": "^2.1.0",
67
67
  "@metamask/polling-controller": "^17.0.0",
68
- "@metamask/profile-sync-controller": "^34.0.2",
68
+ "@metamask/profile-sync-controller": "^34.0.3",
69
69
  "@metamask/remote-feature-flag-controller": "^7.0.0",
70
70
  "@metamask/seedless-onboarding-controller": "^12.0.0",
71
71
  "@metamask/superstruct": "^3.4.1",
72
- "@metamask/transaction-controller": "^72.1.0",
72
+ "@metamask/transaction-controller": "^72.2.0",
73
73
  "@metamask/utils": "^12.0.0",
74
74
  "@tanstack/query-core": "^5.103.2",
75
75
  "bignumber.js": "^9.1.2",
@@ -85,7 +85,7 @@
85
85
  "rimraf": "^6.1.3",
86
86
  "ts-jest": "^29.4.14",
87
87
  "typedoc": "^0.28.20",
88
- "typedoc-plugin-missing-exports": "^2.0.0",
88
+ "typedoc-plugin-missing-exports": "^4.1.4",
89
89
  "typescript": "npm:@typescript/typescript6@^6.0.2"
90
90
  },
91
91
  "engines": {