@metamask-previews/subscription-controller 5.4.0-preview-839e62c2 → 5.4.1-preview-cd0d0950
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/CHANGELOG.md +13 -1
- package/dist/SubscriptionController.cjs +1 -3
- package/dist/SubscriptionController.cjs.map +1 -1
- package/dist/SubscriptionController.d.cts +4 -6
- package/dist/SubscriptionController.d.cts.map +1 -1
- package/dist/SubscriptionController.d.mts +4 -6
- package/dist/SubscriptionController.d.mts.map +1 -1
- package/dist/SubscriptionController.mjs +1 -3
- package/dist/SubscriptionController.mjs.map +1 -1
- package/dist/SubscriptionService.cjs +3 -1
- package/dist/SubscriptionService.cjs.map +1 -1
- package/dist/SubscriptionService.d.cts +2 -4
- package/dist/SubscriptionService.d.cts.map +1 -1
- package/dist/SubscriptionService.d.mts +2 -4
- package/dist/SubscriptionService.d.mts.map +1 -1
- package/dist/SubscriptionService.mjs +3 -1
- package/dist/SubscriptionService.mjs.map +1 -1
- package/dist/index.cjs +2 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/types.cjs +7 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +17 -3
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +17 -3
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs +6 -0
- package/dist/types.mjs.map +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SubscriptionController.mjs","sourceRoot":"","sources":["../src/SubscriptionController.ts"],"names":[],"mappings":";;;;;;;;;;;;AAMA,OAAO,EAAE,+BAA+B,EAAE,qCAAqC;AAG/E,OAAO,EAAE,eAAe,EAAE,yCAAyC;AAEnE,OAAO,EAAE,SAAS,EAA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,CAAC,CAC7B;KACF,CAAC;IAEF,OAAO,IAAI,CAAC,SAAS,CAAC,sBAAsB,CAAC,CAAC;AAChD,CAAC","sourcesContent":["import type {\n StateMetadata,\n ControllerStateChangeEvent,\n ControllerGetStateAction,\n} from '@metamask/base-controller';\nimport type { Messenger } from '@metamask/messenger';\nimport { StaticIntervalPollingController } from '@metamask/polling-controller';\nimport type { AuthenticationController } from '@metamask/profile-sync-controller';\nimport type { TransactionMeta } from '@metamask/transaction-controller';\nimport { TransactionType } from '@metamask/transaction-controller';\nimport type { CaipAccountId, Hex } from '@metamask/utils';\nimport { BigNumber } from 'bignumber.js';\n\nimport {\n ACTIVE_SUBSCRIPTION_STATUSES,\n controllerName,\n DEFAULT_POLLING_INTERVAL,\n SubscriptionControllerErrorMessage,\n} from './constants';\nimport { PAYMENT_TYPES, PRODUCT_TYPES, SUBSCRIPTION_STATUSES } from './types';\nimport type {\n AssignCohortRequest,\n BillingPortalResponse,\n GetCryptoApproveTransactionRequest,\n GetCryptoApproveTransactionResponse,\n GetSubscriptionsEligibilitiesRequest,\n ProductPrice,\n SubscriptionEligibility,\n StartCryptoSubscriptionRequest,\n SubmitUserEventRequest,\n TokenPaymentInfo,\n UpdatePaymentMethodCardResponse,\n UpdatePaymentMethodOpts,\n CachedLastSelectedPaymentMethod,\n SubmitSponsorshipIntentsMethodParams,\n RecurringInterval,\n SubscriptionStatus,\n LinkRewardsRequest,\n StartCryptoSubscriptionResponse,\n StartSubscriptionResponse,\n} from './types';\nimport type {\n ISubscriptionService,\n PricingResponse,\n ProductType,\n StartSubscriptionRequest,\n Subscription,\n} from './types';\n\nexport type SubscriptionControllerState = {\n customerId?: string;\n trialedProducts: ProductType[];\n subscriptions: Subscription[];\n pricing?: PricingResponse;\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 * The last selected payment method for the user.\n * This is used to display the last selected payment method in the UI.\n * This state is also meant to be used internally to track the last selected payment method for the user. (e.g. for crypto subscriptions)\n */\n lastSelectedPaymentMethod?: Record<\n ProductType,\n CachedLastSelectedPaymentMethod\n >;\n};\n\n// Messenger Actions\nexport type SubscriptionControllerGetSubscriptionsAction = {\n type: `${typeof controllerName}:getSubscriptions`;\n handler: SubscriptionController['getSubscriptions'];\n};\nexport type SubscriptionControllerGetSubscriptionByProductAction = {\n type: `${typeof controllerName}:getSubscriptionByProduct`;\n handler: SubscriptionController['getSubscriptionByProduct'];\n};\nexport type SubscriptionControllerCancelSubscriptionAction = {\n type: `${typeof controllerName}:cancelSubscription`;\n handler: SubscriptionController['cancelSubscription'];\n};\nexport type SubscriptionControllerStartShieldSubscriptionWithCardAction = {\n type: `${typeof controllerName}:startShieldSubscriptionWithCard`;\n handler: SubscriptionController['startShieldSubscriptionWithCard'];\n};\nexport type SubscriptionControllerGetPricingAction = {\n type: `${typeof controllerName}:getPricing`;\n handler: SubscriptionController['getPricing'];\n};\nexport type SubscriptionControllerGetCryptoApproveTransactionParamsAction = {\n type: `${typeof controllerName}:getCryptoApproveTransactionParams`;\n handler: SubscriptionController['getCryptoApproveTransactionParams'];\n};\nexport type SubscriptionControllerStartSubscriptionWithCryptoAction = {\n type: `${typeof controllerName}:startSubscriptionWithCrypto`;\n handler: SubscriptionController['startSubscriptionWithCrypto'];\n};\nexport type SubscriptionControllerUpdatePaymentMethodAction = {\n type: `${typeof controllerName}:updatePaymentMethod`;\n handler: SubscriptionController['updatePaymentMethod'];\n};\nexport type SubscriptionControllerGetBillingPortalUrlAction = {\n type: `${typeof controllerName}:getBillingPortalUrl`;\n handler: SubscriptionController['getBillingPortalUrl'];\n};\n\nexport type SubscriptionControllerSubmitSponsorshipIntentsAction = {\n type: `${typeof controllerName}:submitSponsorshipIntents`;\n handler: SubscriptionController['submitSponsorshipIntents'];\n};\n\nexport type SubscriptionControllerLinkRewardsAction = {\n type: `${typeof controllerName}:linkRewards`;\n handler: SubscriptionController['linkRewards'];\n};\n\nexport type SubscriptionControllerSubmitShieldSubscriptionCryptoApprovalAction =\n {\n type: `${typeof controllerName}:submitShieldSubscriptionCryptoApproval`;\n handler: SubscriptionController['submitShieldSubscriptionCryptoApproval'];\n };\n\nexport type SubscriptionControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n SubscriptionControllerState\n>;\nexport type SubscriptionControllerActions =\n | SubscriptionControllerGetSubscriptionsAction\n | SubscriptionControllerGetSubscriptionByProductAction\n | SubscriptionControllerCancelSubscriptionAction\n | SubscriptionControllerStartShieldSubscriptionWithCardAction\n | SubscriptionControllerGetPricingAction\n | SubscriptionControllerGetStateAction\n | SubscriptionControllerGetCryptoApproveTransactionParamsAction\n | SubscriptionControllerStartSubscriptionWithCryptoAction\n | SubscriptionControllerUpdatePaymentMethodAction\n | SubscriptionControllerGetBillingPortalUrlAction\n | SubscriptionControllerSubmitSponsorshipIntentsAction\n | SubscriptionControllerSubmitShieldSubscriptionCryptoApprovalAction\n | SubscriptionControllerLinkRewardsAction;\n\nexport type AllowedActions =\n | AuthenticationController.AuthenticationControllerGetBearerToken\n | AuthenticationController.AuthenticationControllerPerformSignOut;\n\n// Events\nexport type SubscriptionControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof controllerName,\n SubscriptionControllerState\n>;\nexport type SubscriptionControllerEvents =\n SubscriptionControllerStateChangeEvent;\n\nexport type AllowedEvents =\n AuthenticationController.AuthenticationControllerStateChangeEvent;\n\n// Messenger\nexport type SubscriptionControllerMessenger = Messenger<\n typeof controllerName,\n SubscriptionControllerActions | AllowedActions,\n SubscriptionControllerEvents | AllowedEvents\n>;\n\n/**\n * Subscription Controller Options.\n */\nexport type SubscriptionControllerOptions = {\n messenger: SubscriptionControllerMessenger;\n\n /**\n * Initial state to set on this controller.\n */\n state?: Partial<SubscriptionControllerState>;\n\n /**\n * Subscription service to use for the subscription controller.\n */\n subscriptionService: ISubscriptionService;\n\n /**\n * Polling interval to use for the subscription controller.\n *\n * @default 5 minutes.\n */\n pollingInterval?: number;\n};\n\n/**\n * Get the default state for the Subscription Controller.\n *\n * @returns The default state for the Subscription Controller.\n */\nexport function getDefaultSubscriptionControllerState(): SubscriptionControllerState {\n return {\n subscriptions: [],\n trialedProducts: [],\n };\n}\n\n/**\n * Seedless Onboarding Controller State Metadata.\n *\n * This allows us to choose if fields of the state should be persisted or not\n * using the `persist` flag; and if they can be sent to Sentry or not, using\n * the `anonymous` flag.\n */\nconst subscriptionControllerMetadata: StateMetadata<SubscriptionControllerState> =\n {\n subscriptions: {\n includeInStateLogs: false,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n lastSubscription: {\n includeInStateLogs: false,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n customerId: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n rewardAccountId: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n trialedProducts: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: true,\n usedInUi: true,\n },\n pricing: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: true,\n usedInUi: true,\n },\n lastSelectedPaymentMethod: {\n includeInStateLogs: false,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n };\n\nexport class SubscriptionController extends StaticIntervalPollingController()<\n typeof controllerName,\n SubscriptionControllerState,\n SubscriptionControllerMessenger\n> {\n readonly #subscriptionService: ISubscriptionService;\n\n /**\n * Creates a new SubscriptionController instance.\n *\n * @param options - The options for the SubscriptionController.\n * @param options.messenger - A restricted messenger.\n * @param options.state - Initial state to set on this controller.\n * @param options.subscriptionService - The subscription service for communicating with subscription server.\n * @param options.pollingInterval - The polling interval to use for the subscription controller.\n */\n constructor({\n messenger,\n state,\n subscriptionService,\n pollingInterval = DEFAULT_POLLING_INTERVAL,\n }: SubscriptionControllerOptions) {\n super({\n name: controllerName,\n metadata: subscriptionControllerMetadata,\n state: {\n ...getDefaultSubscriptionControllerState(),\n ...state,\n },\n messenger,\n });\n\n this.setIntervalLength(pollingInterval);\n this.#subscriptionService = subscriptionService;\n this.#registerMessageHandlers();\n }\n\n /**\n * Constructor helper for registering this controller's messaging system\n * actions.\n */\n #registerMessageHandlers(): void {\n this.messenger.registerActionHandler(\n 'SubscriptionController:getSubscriptions',\n this.getSubscriptions.bind(this),\n );\n\n this.messenger.registerActionHandler(\n 'SubscriptionController:getSubscriptionByProduct',\n this.getSubscriptionByProduct.bind(this),\n );\n\n this.messenger.registerActionHandler(\n 'SubscriptionController:cancelSubscription',\n this.cancelSubscription.bind(this),\n );\n\n this.messenger.registerActionHandler(\n 'SubscriptionController:startShieldSubscriptionWithCard',\n this.startShieldSubscriptionWithCard.bind(this),\n );\n\n this.messenger.registerActionHandler(\n 'SubscriptionController:getPricing',\n this.getPricing.bind(this),\n );\n\n this.messenger.registerActionHandler(\n 'SubscriptionController:getCryptoApproveTransactionParams',\n this.getCryptoApproveTransactionParams.bind(this),\n );\n\n this.messenger.registerActionHandler(\n 'SubscriptionController:startSubscriptionWithCrypto',\n this.startSubscriptionWithCrypto.bind(this),\n );\n\n this.messenger.registerActionHandler(\n 'SubscriptionController:updatePaymentMethod',\n this.updatePaymentMethod.bind(this),\n );\n\n this.messenger.registerActionHandler(\n 'SubscriptionController:getBillingPortalUrl',\n this.getBillingPortalUrl.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:submitSponsorshipIntents`,\n this.submitSponsorshipIntents.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:submitShieldSubscriptionCryptoApproval`,\n this.submitShieldSubscriptionCryptoApproval.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:linkRewards`,\n this.linkRewards.bind(this),\n );\n }\n\n /**\n * Gets the pricing information from the subscription service.\n *\n * @returns The pricing information.\n */\n async getPricing(): Promise<PricingResponse> {\n const pricing = await this.#subscriptionService.getPricing();\n this.update((state) => {\n state.pricing = pricing;\n });\n return pricing;\n }\n\n async getSubscriptions(): Promise<Subscription[]> {\n const currentSubscriptions = this.state.subscriptions;\n const currentTrialedProducts = this.state.trialedProducts;\n const currentCustomerId = this.state.customerId;\n const currentLastSubscription = this.state.lastSubscription;\n const currentRewardAccountId = this.state.rewardAccountId;\n\n const {\n customerId: newCustomerId,\n subscriptions: newSubscriptions,\n trialedProducts: newTrialedProducts,\n lastSubscription: newLastSubscription,\n rewardAccountId: newRewardAccountId,\n } = await this.#subscriptionService.getSubscriptions();\n\n // check if the new subscriptions are different from the current subscriptions\n const areSubscriptionsEqual = this.#areSubscriptionsEqual(\n currentSubscriptions,\n newSubscriptions,\n );\n // check if the new trialed products are different from the current trialed products\n const areTrialedProductsEqual = this.#areTrialedProductsEqual(\n currentTrialedProducts,\n newTrialedProducts,\n );\n // check if the new last subscription is different from the current last subscription\n const isLastSubscriptionEqual = this.#isSubscriptionEqual(\n currentLastSubscription,\n newLastSubscription,\n );\n\n const areCustomerIdsEqual = currentCustomerId === newCustomerId;\n const areRewardAccountIdsEqual =\n currentRewardAccountId === newRewardAccountId;\n // only update the state if the subscriptions or trialed products are different\n // this prevents unnecessary state updates events, easier for the clients to handle\n if (\n !areSubscriptionsEqual ||\n !isLastSubscriptionEqual ||\n !areTrialedProductsEqual ||\n !areCustomerIdsEqual ||\n !areRewardAccountIdsEqual\n ) {\n this.update((state) => {\n state.subscriptions = newSubscriptions;\n state.customerId = newCustomerId;\n state.trialedProducts = newTrialedProducts;\n state.lastSubscription = newLastSubscription;\n state.rewardAccountId = newRewardAccountId;\n });\n // trigger access token refresh to ensure the user has the latest access token if subscription state change\n this.triggerAccessTokenRefresh();\n }\n\n return newSubscriptions;\n }\n\n /**\n * Get the subscription by product.\n *\n * @param productType - The product type.\n * @returns The subscription.\n */\n getSubscriptionByProduct(productType: ProductType): Subscription | undefined {\n return this.state.subscriptions.find((subscription) =>\n subscription.products.some((product) => product.name === productType),\n );\n }\n\n /**\n * Get the subscriptions eligibilities.\n *\n * @param request - Optional request object containing user balance to check cohort eligibility.\n * @returns The subscriptions eligibilities.\n */\n async getSubscriptionsEligibilities(\n request?: GetSubscriptionsEligibilitiesRequest,\n ): Promise<SubscriptionEligibility[]> {\n return await this.#subscriptionService.getSubscriptionsEligibilities(\n request,\n );\n }\n\n async cancelSubscription(request: { subscriptionId: string }): Promise<void> {\n this.#assertIsUserSubscribed({ subscriptionId: request.subscriptionId });\n\n const cancelledSubscription =\n await this.#subscriptionService.cancelSubscription({\n subscriptionId: request.subscriptionId,\n });\n\n this.update((state) => {\n state.subscriptions = state.subscriptions.map((subscription) =>\n subscription.id === request.subscriptionId\n ? { ...subscription, ...cancelledSubscription }\n : subscription,\n );\n });\n\n this.triggerAccessTokenRefresh();\n }\n\n async unCancelSubscription(request: {\n subscriptionId: string;\n }): Promise<void> {\n this.#assertIsUserSubscribed({ subscriptionId: request.subscriptionId });\n\n const uncancelledSubscription =\n await this.#subscriptionService.unCancelSubscription({\n subscriptionId: request.subscriptionId,\n });\n\n this.update((state) => {\n state.subscriptions = state.subscriptions.map((subscription) =>\n subscription.id === request.subscriptionId\n ? { ...subscription, ...uncancelledSubscription }\n : subscription,\n );\n });\n\n this.triggerAccessTokenRefresh();\n }\n\n async startShieldSubscriptionWithCard(\n request: StartSubscriptionRequest,\n ): Promise<StartSubscriptionResponse> {\n this.#assertIsUserNotSubscribed({ products: request.products });\n\n const response =\n await this.#subscriptionService.startSubscriptionWithCard(request);\n // note: no need to trigger access token refresh after startSubscriptionWithCard request because this only return stripe checkout session url, subscription not created yet\n\n return response;\n }\n\n async startSubscriptionWithCrypto(\n request: StartCryptoSubscriptionRequest,\n ): Promise<StartCryptoSubscriptionResponse> {\n this.#assertIsUserNotSubscribed({ products: request.products });\n const response =\n await this.#subscriptionService.startSubscriptionWithCrypto(request);\n\n return response;\n }\n\n /**\n * Handles shield subscription crypto approval transactions.\n *\n * @param txMeta - The transaction metadata.\n * @param isSponsored - Whether the transaction is sponsored.\n * @param rewardAccountId - The account ID of the reward subscription to link to the shield subscription.\n * @returns void\n */\n async submitShieldSubscriptionCryptoApproval(\n txMeta: TransactionMeta,\n isSponsored?: boolean,\n rewardAccountId?: CaipAccountId,\n ): Promise<void> {\n if (txMeta.type !== TransactionType.shieldSubscriptionApprove) {\n return;\n }\n\n const { chainId, rawTx } = txMeta;\n if (!chainId || !rawTx) {\n throw new Error('Chain ID or raw transaction not found');\n }\n\n const { pricing, trialedProducts, lastSelectedPaymentMethod } = this.state;\n if (!pricing) {\n throw new Error('Subscription pricing not found');\n }\n if (!lastSelectedPaymentMethod) {\n throw new Error('Last selected payment method not found');\n }\n const lastSelectedPaymentMethodShield =\n lastSelectedPaymentMethod[PRODUCT_TYPES.SHIELD];\n this.#assertIsPaymentMethodCrypto(lastSelectedPaymentMethodShield);\n\n const productPrice = this.#getProductPriceByProductAndPlan(\n PRODUCT_TYPES.SHIELD,\n lastSelectedPaymentMethodShield.plan,\n );\n const isTrialed = trialedProducts?.includes(PRODUCT_TYPES.SHIELD);\n // get the latest subscriptions state to check if the user has an active shield subscription\n await this.getSubscriptions();\n const currentSubscription = this.state.subscriptions.find((subscription) =>\n subscription.products.some(\n (product) => product.name === PRODUCT_TYPES.SHIELD,\n ),\n );\n\n this.#assertValidSubscriptionStateForCryptoApproval({\n productType: PRODUCT_TYPES.SHIELD,\n });\n // if shield subscription exists, this transaction is for changing payment method\n const isChangePaymentMethod = Boolean(currentSubscription);\n\n if (isChangePaymentMethod) {\n await this.updatePaymentMethod({\n paymentType: PAYMENT_TYPES.byCrypto,\n subscriptionId: (currentSubscription as Subscription).id,\n chainId,\n payerAddress: txMeta.txParams.from as Hex,\n tokenSymbol: lastSelectedPaymentMethodShield.paymentTokenSymbol,\n rawTransaction: rawTx as Hex,\n recurringInterval: productPrice.interval,\n billingCycles: productPrice.minBillingCycles,\n });\n } else {\n const params = {\n products: [PRODUCT_TYPES.SHIELD],\n isTrialRequested: !isTrialed,\n recurringInterval: productPrice.interval,\n billingCycles: productPrice.minBillingCycles,\n chainId,\n payerAddress: txMeta.txParams.from as Hex,\n tokenSymbol: lastSelectedPaymentMethodShield.paymentTokenSymbol,\n rawTransaction: rawTx as Hex,\n isSponsored,\n useTestClock: lastSelectedPaymentMethodShield.useTestClock,\n rewardAccountId,\n };\n await this.startSubscriptionWithCrypto(params);\n }\n\n // update the subscriptions state after subscription created in server\n await this.getSubscriptions();\n }\n\n /**\n * Get transaction params to create crypto approve transaction for subscription payment\n *\n * @param request - The request object\n * @param request.chainId - The chain ID\n * @param request.tokenAddress - The address of the token\n * @param request.productType - The product type\n * @param request.interval - The interval\n * @returns The crypto approve transaction params\n */\n getCryptoApproveTransactionParams(\n request: GetCryptoApproveTransactionRequest,\n ): GetCryptoApproveTransactionResponse {\n const { pricing } = this.state;\n if (!pricing) {\n throw new Error('Subscription pricing not found');\n }\n const product = pricing.products.find(\n (productInfo) => productInfo.name === request.productType,\n );\n if (!product) {\n throw new Error('Product price not found');\n }\n\n const price = product.prices.find(\n (productPrice) => productPrice.interval === request.interval,\n );\n if (!price) {\n throw new Error('Price not found');\n }\n\n const chainsPaymentInfo = pricing.paymentMethods.find(\n (paymentMethod) => paymentMethod.type === PAYMENT_TYPES.byCrypto,\n );\n if (!chainsPaymentInfo) {\n throw new Error('Chains payment info not found');\n }\n const chainPaymentInfo = chainsPaymentInfo.chains?.find(\n (chain) => chain.chainId === request.chainId,\n );\n if (!chainPaymentInfo) {\n throw new Error('Invalid chain id');\n }\n const tokenPaymentInfo = chainPaymentInfo.tokens.find(\n (token) => token.address === request.paymentTokenAddress,\n );\n if (!tokenPaymentInfo) {\n throw new Error('Invalid token address');\n }\n\n const tokenApproveAmount = this.getTokenApproveAmount(\n price,\n tokenPaymentInfo,\n );\n\n return {\n approveAmount: tokenApproveAmount,\n paymentAddress: chainPaymentInfo.paymentAddress,\n paymentTokenAddress: request.paymentTokenAddress,\n chainId: request.chainId,\n };\n }\n\n async updatePaymentMethod(\n opts: UpdatePaymentMethodOpts,\n ): Promise<UpdatePaymentMethodCardResponse | Subscription[]> {\n if (opts.paymentType === PAYMENT_TYPES.byCard) {\n const { paymentType, ...cardRequest } = opts;\n return await this.#subscriptionService.updatePaymentMethodCard(\n cardRequest,\n );\n } else if (opts.paymentType === PAYMENT_TYPES.byCrypto) {\n const { paymentType, ...cryptoRequest } = opts;\n await this.#subscriptionService.updatePaymentMethodCrypto(cryptoRequest);\n return await this.getSubscriptions();\n }\n throw new Error('Invalid payment type');\n }\n\n /**\n * Gets the billing portal URL.\n *\n * @returns The billing portal URL\n */\n async getBillingPortalUrl(): Promise<BillingPortalResponse> {\n return await this.#subscriptionService.getBillingPortalUrl();\n }\n\n /**\n * Cache the last selected payment method for a specific product.\n *\n * @param product - The product to cache the payment method for.\n * @param paymentMethod - The payment method to cache.\n * @param paymentMethod.type - The type of the payment method.\n * @param paymentMethod.paymentTokenAddress - The payment token address.\n * @param paymentMethod.plan - The plan of the payment method.\n * @param paymentMethod.product - The product of the payment method.\n */\n cacheLastSelectedPaymentMethod(\n product: ProductType,\n paymentMethod: CachedLastSelectedPaymentMethod,\n ): void {\n if (\n paymentMethod.type === PAYMENT_TYPES.byCrypto &&\n (!paymentMethod.paymentTokenAddress || !paymentMethod.paymentTokenSymbol)\n ) {\n throw new Error(\n SubscriptionControllerErrorMessage.PaymentTokenAddressAndSymbolRequiredForCrypto,\n );\n }\n\n this.update((state) => {\n state.lastSelectedPaymentMethod = {\n ...state.lastSelectedPaymentMethod,\n [product]: paymentMethod,\n };\n });\n }\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 * @returns resolves to true if the sponsorship is supported and intents were submitted successfully, false otherwise\n */\n async submitSponsorshipIntents(\n request: SubmitSponsorshipIntentsMethodParams,\n ): Promise<boolean> {\n if (request.products.length === 0) {\n throw new Error(\n SubscriptionControllerErrorMessage.SubscriptionProductsEmpty,\n );\n }\n\n this.#assertIsUserNotSubscribed({ products: request.products });\n\n const selectedPaymentMethod =\n this.state.lastSelectedPaymentMethod?.[request.products[0]];\n this.#assertIsPaymentMethodCrypto(selectedPaymentMethod);\n\n const isEligibleForTrialedSponsorship =\n this.#getIsEligibleForTrialedSponsorship(\n request.chainId,\n request.products,\n );\n if (!isEligibleForTrialedSponsorship) {\n return false;\n }\n\n const { paymentTokenSymbol, plan } = selectedPaymentMethod;\n const productPrice = this.#getProductPriceByProductAndPlan(\n // we only support one product at a time for now\n request.products[0],\n plan,\n );\n const billingCycles = productPrice.minBillingCycles;\n\n await this.#subscriptionService.submitSponsorshipIntents({\n ...request,\n paymentTokenSymbol,\n billingCycles,\n recurringInterval: plan,\n });\n return true;\n }\n\n /**\n * Submit a user event from the UI. (e.g. shield modal viewed)\n *\n * @param request - Request object containing the event to submit.\n * @example { event: SubscriptionUserEvent.ShieldEntryModalViewed, cohort: 'post_tx' }\n */\n async submitUserEvent(request: SubmitUserEventRequest): Promise<void> {\n await this.#subscriptionService.submitUserEvent(request);\n }\n\n /**\n * Assign user to a cohort.\n *\n * @param request - Request object containing the cohort to assign the user to.\n * @example { cohort: 'post_tx' }\n */\n async assignUserToCohort(request: AssignCohortRequest): Promise<void> {\n await this.#subscriptionService.assignUserToCohort(request);\n }\n\n /**\n * Link rewards to a subscription.\n *\n * @param request - Request object containing the reward subscription ID.\n * @param request.subscriptionId - The ID of the subscription to link rewards to.\n * @param request.rewardAccountId - The account ID of the reward subscription to link to the subscription.\n * @example { subscriptionId: '1234567890', rewardAccountId: 'eip155:1:0x1234567890123456789012345678901234567890' }\n * @returns Resolves when the rewards are linked successfully.\n */\n async linkRewards(\n request: LinkRewardsRequest & { subscriptionId: string },\n ): Promise<void> {\n // assert that the user is subscribed to the subscription\n this.#assertIsUserSubscribed({ subscriptionId: request.subscriptionId });\n\n // link rewards to the subscription\n const response = await this.#subscriptionService.linkRewards({\n rewardAccountId: request.rewardAccountId,\n });\n if (!response.success) {\n throw new Error(SubscriptionControllerErrorMessage.LinkRewardsFailed);\n }\n }\n\n async _executePoll(): Promise<void> {\n await this.getSubscriptions();\n }\n\n /**\n * Calculate total subscription price amount (approval amount) from price info\n * e.g: $8 per month * 12 months min billing cycles = $96\n *\n * @param price - The price info\n * @returns The price amount\n */\n #getSubscriptionPriceAmount(price: ProductPrice): string {\n // no need to use BigInt since max unitDecimals are always 2 for price\n const amount = new BigNumber(price.unitAmount)\n .div(10 ** price.unitDecimals)\n .multipliedBy(price.minBillingCycles)\n .toString();\n return amount;\n }\n\n /**\n * Calculate minimum subscription balance amount from price info\n *\n * @param price - The price info\n * @returns The balance amount\n */\n #getSubscriptionBalanceAmount(price: ProductPrice): string {\n // no need to use BigInt since max unitDecimals are always 2 for price\n const amount = new BigNumber(price.unitAmount)\n .div(10 ** price.unitDecimals)\n .multipliedBy(price.minBillingCyclesForBalance)\n .toString();\n return amount;\n }\n\n /**\n * Calculate token approve amount from price info\n *\n * @param price - The price info\n * @param tokenPaymentInfo - The token price info\n * @returns The token approve amount\n */\n getTokenApproveAmount(\n price: ProductPrice,\n tokenPaymentInfo: TokenPaymentInfo,\n ): string {\n const conversionRate =\n tokenPaymentInfo.conversionRate[\n price.currency as keyof typeof tokenPaymentInfo.conversionRate\n ];\n if (!conversionRate) {\n throw new Error('Conversion rate not found');\n }\n // price of the product\n const priceAmount = new BigNumber(this.#getSubscriptionPriceAmount(price));\n\n const tokenDecimal = new BigNumber(10).pow(tokenPaymentInfo.decimals);\n const tokenAmount = priceAmount\n .multipliedBy(tokenDecimal)\n .div(conversionRate);\n return tokenAmount.toFixed(0);\n }\n\n /**\n * Calculate token minimum balance amount from price info\n *\n * @param price - The price info\n * @param tokenPaymentInfo - The token price info\n * @returns The token balance amount\n */\n getTokenMinimumBalanceAmount(\n price: ProductPrice,\n tokenPaymentInfo: TokenPaymentInfo,\n ): string {\n const conversionRate =\n tokenPaymentInfo.conversionRate[\n price.currency as keyof typeof tokenPaymentInfo.conversionRate\n ];\n if (!conversionRate) {\n throw new Error('Conversion rate not found');\n }\n const balanceAmount = new BigNumber(\n this.#getSubscriptionBalanceAmount(price),\n );\n\n const tokenDecimal = new BigNumber(10).pow(tokenPaymentInfo.decimals);\n const tokenAmount = balanceAmount\n .multipliedBy(tokenDecimal)\n .div(conversionRate);\n return tokenAmount.toFixed(0);\n }\n\n /**\n * Triggers an access token refresh.\n */\n triggerAccessTokenRefresh(): void {\n // We perform a sign out to clear the access token from the authentication\n // controller. Next time the access token is requested, a new access token\n // will be fetched.\n this.messenger.call('AuthenticationController:performSignOut');\n }\n\n #getProductPriceByProductAndPlan(\n productType: ProductType,\n plan: RecurringInterval,\n ): ProductPrice {\n const { pricing } = this.state;\n const productPricing = pricing?.products.find(\n (product) => product.name === productType,\n );\n const productPrice = productPricing?.prices.find(\n (price) => price.interval === plan,\n );\n if (!productPrice) {\n throw new Error(SubscriptionControllerErrorMessage.ProductPriceNotFound);\n }\n return productPrice;\n }\n\n #assertValidSubscriptionStateForCryptoApproval({\n productType,\n }: {\n productType: ProductType;\n }): void {\n const subscription = this.state.subscriptions.find((sub) =>\n sub.products.some((product) => product.name === productType),\n );\n\n const isValid =\n !subscription ||\n (\n [\n SUBSCRIPTION_STATUSES.pastDue,\n SUBSCRIPTION_STATUSES.unpaid,\n SUBSCRIPTION_STATUSES.paused,\n SUBSCRIPTION_STATUSES.provisional,\n SUBSCRIPTION_STATUSES.active,\n SUBSCRIPTION_STATUSES.trialing,\n ] as SubscriptionStatus[]\n ).includes(subscription.status);\n if (!isValid) {\n throw new Error(\n SubscriptionControllerErrorMessage.SubscriptionNotValidForCryptoApproval,\n );\n }\n }\n\n #assertIsUserNotSubscribed({ products }: { products: ProductType[] }): void {\n const subscription = this.state.subscriptions.find((sub) =>\n sub.products.some((product) => products.includes(product.name)),\n );\n\n if (\n subscription &&\n ACTIVE_SUBSCRIPTION_STATUSES.includes(subscription.status)\n ) {\n throw new Error(SubscriptionControllerErrorMessage.UserAlreadySubscribed);\n }\n }\n\n #assertIsUserSubscribed(request: { subscriptionId: string }): void {\n if (\n !this.state.subscriptions.find(\n (subscription) => subscription.id === request.subscriptionId,\n )\n ) {\n throw new Error(SubscriptionControllerErrorMessage.UserNotSubscribed);\n }\n }\n\n /**\n * Asserts that the value is a valid crypto payment method.\n *\n * @param value - The value to assert.\n * @throws an error if the value is not a valid crypto payment method.\n */\n #assertIsPaymentMethodCrypto(\n value: CachedLastSelectedPaymentMethod | undefined,\n ): asserts value is Required<CachedLastSelectedPaymentMethod> {\n if (\n !value ||\n value.type !== PAYMENT_TYPES.byCrypto ||\n !value.paymentTokenAddress ||\n !value.paymentTokenSymbol\n ) {\n throw new Error(\n SubscriptionControllerErrorMessage.PaymentMethodNotCrypto,\n );\n }\n }\n\n /**\n * Determines if the user is eligible for trialed sponsorship for the given chain and products.\n * The user is eligible if the chain supports sponsorship and the user has not trialed the provided products before.\n *\n * @param chainId - The chain ID\n * @param products - The products to check eligibility for\n * @returns True if the user is eligible for trialed sponsorship, false otherwise\n */\n #getIsEligibleForTrialedSponsorship(\n chainId: Hex,\n products: ProductType[],\n ): boolean {\n const isSponsorshipSupported = this.#getChainSupportsSponsorship(chainId);\n\n // verify if the user has trialed the provided products before\n const hasTrialedBefore = this.state.trialedProducts.some((product) =>\n products.includes(product),\n );\n\n return isSponsorshipSupported && !hasTrialedBefore;\n }\n\n #getChainSupportsSponsorship(chainId: Hex): boolean {\n const cryptoPaymentInfo = this.state.pricing?.paymentMethods.find(\n (paymentMethod) => paymentMethod.type === PAYMENT_TYPES.byCrypto,\n );\n\n const isSponsorshipSupported = cryptoPaymentInfo?.chains?.find(\n (chain) => chain.chainId === chainId,\n )?.isSponsorshipSupported;\n return Boolean(isSponsorshipSupported);\n }\n\n /**\n * Determines whether two trialed products arrays are equal by comparing all products in the arrays.\n *\n * @param oldTrialedProducts - The first trialed products array to compare.\n * @param newTrialedProducts - The second trialed products array to compare.\n * @returns True if the trialed products arrays are equal, false otherwise.\n */\n #areTrialedProductsEqual(\n oldTrialedProducts: ProductType[],\n newTrialedProducts: ProductType[],\n ): boolean {\n return (\n oldTrialedProducts.length === newTrialedProducts?.length &&\n oldTrialedProducts.every((product) =>\n newTrialedProducts?.includes(product),\n )\n );\n }\n\n /**\n * Determines whether two subscription arrays are equal by comparing all properties\n * of each subscription in the arrays.\n *\n * @param oldSubs - The first subscription array to compare.\n * @param newSubs - The second subscription array to compare.\n * @returns True if the subscription arrays are equal, false otherwise.\n */\n #areSubscriptionsEqual(\n oldSubs: Subscription[],\n newSubs: Subscription[],\n ): boolean {\n // Check if arrays have different lengths\n if (oldSubs.length !== newSubs.length) {\n return false;\n }\n\n // Sort both arrays by id to ensure consistent comparison\n const sortedOldSubs = [...oldSubs].sort((a, b) => a.id.localeCompare(b.id));\n const sortedNewSubs = [...newSubs].sort((a, b) => a.id.localeCompare(b.id));\n\n // Check if all subscriptions are equal\n return sortedOldSubs.every((oldSub, index) => {\n const newSub = sortedNewSubs[index];\n return this.#isSubscriptionEqual(oldSub, newSub);\n });\n }\n\n #isSubscriptionEqual(oldSub?: Subscription, newSub?: Subscription): boolean {\n // not equal if one is undefined and the other is defined\n if (!oldSub || !newSub) {\n if (!oldSub && !newSub) {\n return true;\n }\n return false;\n }\n\n return (\n this.#stringifySubscription(oldSub) ===\n this.#stringifySubscription(newSub)\n );\n }\n\n #stringifySubscription(subscription: Subscription): string {\n const subsWithSortedProducts = {\n ...subscription,\n // order the products by name\n products: [...subscription.products].sort((a, b) =>\n a.name.localeCompare(b.name),\n ),\n };\n\n return JSON.stringify(subsWithSortedProducts);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"SubscriptionController.mjs","sourceRoot":"","sources":["../src/SubscriptionController.ts"],"names":[],"mappings":";;;;;;;;;;;;AAMA,OAAO,EAAE,+BAA+B,EAAE,qCAAq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CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,CAC7B;KACF,CAAC;IAEF,OAAO,IAAI,CAAC,SAAS,CAAC,sBAAsB,CAAC,CAAC;AAChD,CAAC","sourcesContent":["import type {\n StateMetadata,\n ControllerStateChangeEvent,\n ControllerGetStateAction,\n} from '@metamask/base-controller';\nimport type { Messenger } from '@metamask/messenger';\nimport { StaticIntervalPollingController } from '@metamask/polling-controller';\nimport type { AuthenticationController } from '@metamask/profile-sync-controller';\nimport type { TransactionMeta } from '@metamask/transaction-controller';\nimport { TransactionType } from '@metamask/transaction-controller';\nimport type { CaipAccountId, Hex } from '@metamask/utils';\nimport { BigNumber } from 'bignumber.js';\n\nimport {\n ACTIVE_SUBSCRIPTION_STATUSES,\n controllerName,\n DEFAULT_POLLING_INTERVAL,\n SubscriptionControllerErrorMessage,\n} from './constants';\nimport { PAYMENT_TYPES, PRODUCT_TYPES, SUBSCRIPTION_STATUSES } from './types';\nimport type {\n AssignCohortRequest,\n BillingPortalResponse,\n GetCryptoApproveTransactionRequest,\n GetCryptoApproveTransactionResponse,\n GetSubscriptionsEligibilitiesRequest,\n ProductPrice,\n SubscriptionEligibility,\n StartCryptoSubscriptionRequest,\n SubmitUserEventRequest,\n TokenPaymentInfo,\n UpdatePaymentMethodCardResponse,\n UpdatePaymentMethodOpts,\n CachedLastSelectedPaymentMethod,\n SubmitSponsorshipIntentsMethodParams,\n RecurringInterval,\n SubscriptionStatus,\n LinkRewardsRequest,\n StartCryptoSubscriptionResponse,\n StartSubscriptionResponse,\n CancelSubscriptionRequest,\n} from './types';\nimport type {\n ISubscriptionService,\n PricingResponse,\n ProductType,\n StartSubscriptionRequest,\n Subscription,\n} from './types';\n\nexport type SubscriptionControllerState = {\n customerId?: string;\n trialedProducts: ProductType[];\n subscriptions: Subscription[];\n pricing?: PricingResponse;\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 * The last selected payment method for the user.\n * This is used to display the last selected payment method in the UI.\n * This state is also meant to be used internally to track the last selected payment method for the user. (e.g. for crypto subscriptions)\n */\n lastSelectedPaymentMethod?: Record<\n ProductType,\n CachedLastSelectedPaymentMethod\n >;\n};\n\n// Messenger Actions\nexport type SubscriptionControllerGetSubscriptionsAction = {\n type: `${typeof controllerName}:getSubscriptions`;\n handler: SubscriptionController['getSubscriptions'];\n};\nexport type SubscriptionControllerGetSubscriptionByProductAction = {\n type: `${typeof controllerName}:getSubscriptionByProduct`;\n handler: SubscriptionController['getSubscriptionByProduct'];\n};\nexport type SubscriptionControllerCancelSubscriptionAction = {\n type: `${typeof controllerName}:cancelSubscription`;\n handler: SubscriptionController['cancelSubscription'];\n};\nexport type SubscriptionControllerStartShieldSubscriptionWithCardAction = {\n type: `${typeof controllerName}:startShieldSubscriptionWithCard`;\n handler: SubscriptionController['startShieldSubscriptionWithCard'];\n};\nexport type SubscriptionControllerGetPricingAction = {\n type: `${typeof controllerName}:getPricing`;\n handler: SubscriptionController['getPricing'];\n};\nexport type SubscriptionControllerGetCryptoApproveTransactionParamsAction = {\n type: `${typeof controllerName}:getCryptoApproveTransactionParams`;\n handler: SubscriptionController['getCryptoApproveTransactionParams'];\n};\nexport type SubscriptionControllerStartSubscriptionWithCryptoAction = {\n type: `${typeof controllerName}:startSubscriptionWithCrypto`;\n handler: SubscriptionController['startSubscriptionWithCrypto'];\n};\nexport type SubscriptionControllerUpdatePaymentMethodAction = {\n type: `${typeof controllerName}:updatePaymentMethod`;\n handler: SubscriptionController['updatePaymentMethod'];\n};\nexport type SubscriptionControllerGetBillingPortalUrlAction = {\n type: `${typeof controllerName}:getBillingPortalUrl`;\n handler: SubscriptionController['getBillingPortalUrl'];\n};\n\nexport type SubscriptionControllerSubmitSponsorshipIntentsAction = {\n type: `${typeof controllerName}:submitSponsorshipIntents`;\n handler: SubscriptionController['submitSponsorshipIntents'];\n};\n\nexport type SubscriptionControllerLinkRewardsAction = {\n type: `${typeof controllerName}:linkRewards`;\n handler: SubscriptionController['linkRewards'];\n};\n\nexport type SubscriptionControllerSubmitShieldSubscriptionCryptoApprovalAction =\n {\n type: `${typeof controllerName}:submitShieldSubscriptionCryptoApproval`;\n handler: SubscriptionController['submitShieldSubscriptionCryptoApproval'];\n };\n\nexport type SubscriptionControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n SubscriptionControllerState\n>;\nexport type SubscriptionControllerActions =\n | SubscriptionControllerGetSubscriptionsAction\n | SubscriptionControllerGetSubscriptionByProductAction\n | SubscriptionControllerCancelSubscriptionAction\n | SubscriptionControllerStartShieldSubscriptionWithCardAction\n | SubscriptionControllerGetPricingAction\n | SubscriptionControllerGetStateAction\n | SubscriptionControllerGetCryptoApproveTransactionParamsAction\n | SubscriptionControllerStartSubscriptionWithCryptoAction\n | SubscriptionControllerUpdatePaymentMethodAction\n | SubscriptionControllerGetBillingPortalUrlAction\n | SubscriptionControllerSubmitSponsorshipIntentsAction\n | SubscriptionControllerSubmitShieldSubscriptionCryptoApprovalAction\n | SubscriptionControllerLinkRewardsAction;\n\nexport type AllowedActions =\n | AuthenticationController.AuthenticationControllerGetBearerToken\n | AuthenticationController.AuthenticationControllerPerformSignOut;\n\n// Events\nexport type SubscriptionControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof controllerName,\n SubscriptionControllerState\n>;\nexport type SubscriptionControllerEvents =\n SubscriptionControllerStateChangeEvent;\n\nexport type AllowedEvents =\n AuthenticationController.AuthenticationControllerStateChangeEvent;\n\n// Messenger\nexport type SubscriptionControllerMessenger = Messenger<\n typeof controllerName,\n SubscriptionControllerActions | AllowedActions,\n SubscriptionControllerEvents | AllowedEvents\n>;\n\n/**\n * Subscription Controller Options.\n */\nexport type SubscriptionControllerOptions = {\n messenger: SubscriptionControllerMessenger;\n\n /**\n * Initial state to set on this controller.\n */\n state?: Partial<SubscriptionControllerState>;\n\n /**\n * Subscription service to use for the subscription controller.\n */\n subscriptionService: ISubscriptionService;\n\n /**\n * Polling interval to use for the subscription controller.\n *\n * @default 5 minutes.\n */\n pollingInterval?: number;\n};\n\n/**\n * Get the default state for the Subscription Controller.\n *\n * @returns The default state for the Subscription Controller.\n */\nexport function getDefaultSubscriptionControllerState(): SubscriptionControllerState {\n return {\n subscriptions: [],\n trialedProducts: [],\n };\n}\n\n/**\n * Seedless Onboarding Controller State Metadata.\n *\n * This allows us to choose if fields of the state should be persisted or not\n * using the `persist` flag; and if they can be sent to Sentry or not, using\n * the `anonymous` flag.\n */\nconst subscriptionControllerMetadata: StateMetadata<SubscriptionControllerState> =\n {\n subscriptions: {\n includeInStateLogs: false,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n lastSubscription: {\n includeInStateLogs: false,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n customerId: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n rewardAccountId: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n trialedProducts: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: true,\n usedInUi: true,\n },\n pricing: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: true,\n usedInUi: true,\n },\n lastSelectedPaymentMethod: {\n includeInStateLogs: false,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n };\n\nexport class SubscriptionController extends StaticIntervalPollingController()<\n typeof controllerName,\n SubscriptionControllerState,\n SubscriptionControllerMessenger\n> {\n readonly #subscriptionService: ISubscriptionService;\n\n /**\n * Creates a new SubscriptionController instance.\n *\n * @param options - The options for the SubscriptionController.\n * @param options.messenger - A restricted messenger.\n * @param options.state - Initial state to set on this controller.\n * @param options.subscriptionService - The subscription service for communicating with subscription server.\n * @param options.pollingInterval - The polling interval to use for the subscription controller.\n */\n constructor({\n messenger,\n state,\n subscriptionService,\n pollingInterval = DEFAULT_POLLING_INTERVAL,\n }: SubscriptionControllerOptions) {\n super({\n name: controllerName,\n metadata: subscriptionControllerMetadata,\n state: {\n ...getDefaultSubscriptionControllerState(),\n ...state,\n },\n messenger,\n });\n\n this.setIntervalLength(pollingInterval);\n this.#subscriptionService = subscriptionService;\n this.#registerMessageHandlers();\n }\n\n /**\n * Constructor helper for registering this controller's messaging system\n * actions.\n */\n #registerMessageHandlers(): void {\n this.messenger.registerActionHandler(\n 'SubscriptionController:getSubscriptions',\n this.getSubscriptions.bind(this),\n );\n\n this.messenger.registerActionHandler(\n 'SubscriptionController:getSubscriptionByProduct',\n this.getSubscriptionByProduct.bind(this),\n );\n\n this.messenger.registerActionHandler(\n 'SubscriptionController:cancelSubscription',\n this.cancelSubscription.bind(this),\n );\n\n this.messenger.registerActionHandler(\n 'SubscriptionController:startShieldSubscriptionWithCard',\n this.startShieldSubscriptionWithCard.bind(this),\n );\n\n this.messenger.registerActionHandler(\n 'SubscriptionController:getPricing',\n this.getPricing.bind(this),\n );\n\n this.messenger.registerActionHandler(\n 'SubscriptionController:getCryptoApproveTransactionParams',\n this.getCryptoApproveTransactionParams.bind(this),\n );\n\n this.messenger.registerActionHandler(\n 'SubscriptionController:startSubscriptionWithCrypto',\n this.startSubscriptionWithCrypto.bind(this),\n );\n\n this.messenger.registerActionHandler(\n 'SubscriptionController:updatePaymentMethod',\n this.updatePaymentMethod.bind(this),\n );\n\n this.messenger.registerActionHandler(\n 'SubscriptionController:getBillingPortalUrl',\n this.getBillingPortalUrl.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:submitSponsorshipIntents`,\n this.submitSponsorshipIntents.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:submitShieldSubscriptionCryptoApproval`,\n this.submitShieldSubscriptionCryptoApproval.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:linkRewards`,\n this.linkRewards.bind(this),\n );\n }\n\n /**\n * Gets the pricing information from the subscription service.\n *\n * @returns The pricing information.\n */\n async getPricing(): Promise<PricingResponse> {\n const pricing = await this.#subscriptionService.getPricing();\n this.update((state) => {\n state.pricing = pricing;\n });\n return pricing;\n }\n\n async getSubscriptions(): Promise<Subscription[]> {\n const currentSubscriptions = this.state.subscriptions;\n const currentTrialedProducts = this.state.trialedProducts;\n const currentCustomerId = this.state.customerId;\n const currentLastSubscription = this.state.lastSubscription;\n const currentRewardAccountId = this.state.rewardAccountId;\n\n const {\n customerId: newCustomerId,\n subscriptions: newSubscriptions,\n trialedProducts: newTrialedProducts,\n lastSubscription: newLastSubscription,\n rewardAccountId: newRewardAccountId,\n } = await this.#subscriptionService.getSubscriptions();\n\n // check if the new subscriptions are different from the current subscriptions\n const areSubscriptionsEqual = this.#areSubscriptionsEqual(\n currentSubscriptions,\n newSubscriptions,\n );\n // check if the new trialed products are different from the current trialed products\n const areTrialedProductsEqual = this.#areTrialedProductsEqual(\n currentTrialedProducts,\n newTrialedProducts,\n );\n // check if the new last subscription is different from the current last subscription\n const isLastSubscriptionEqual = this.#isSubscriptionEqual(\n currentLastSubscription,\n newLastSubscription,\n );\n\n const areCustomerIdsEqual = currentCustomerId === newCustomerId;\n const areRewardAccountIdsEqual =\n currentRewardAccountId === newRewardAccountId;\n // only update the state if the subscriptions or trialed products are different\n // this prevents unnecessary state updates events, easier for the clients to handle\n if (\n !areSubscriptionsEqual ||\n !isLastSubscriptionEqual ||\n !areTrialedProductsEqual ||\n !areCustomerIdsEqual ||\n !areRewardAccountIdsEqual\n ) {\n this.update((state) => {\n state.subscriptions = newSubscriptions;\n state.customerId = newCustomerId;\n state.trialedProducts = newTrialedProducts;\n state.lastSubscription = newLastSubscription;\n state.rewardAccountId = newRewardAccountId;\n });\n // trigger access token refresh to ensure the user has the latest access token if subscription state change\n this.triggerAccessTokenRefresh();\n }\n\n return newSubscriptions;\n }\n\n /**\n * Get the subscription by product.\n *\n * @param productType - The product type.\n * @returns The subscription.\n */\n getSubscriptionByProduct(productType: ProductType): Subscription | undefined {\n return this.state.subscriptions.find((subscription) =>\n subscription.products.some((product) => product.name === productType),\n );\n }\n\n /**\n * Get the subscriptions eligibilities.\n *\n * @param request - Optional request object containing user balance to check cohort eligibility.\n * @returns The subscriptions eligibilities.\n */\n async getSubscriptionsEligibilities(\n request?: GetSubscriptionsEligibilitiesRequest,\n ): Promise<SubscriptionEligibility[]> {\n return await this.#subscriptionService.getSubscriptionsEligibilities(\n request,\n );\n }\n\n async cancelSubscription(request: CancelSubscriptionRequest): Promise<void> {\n this.#assertIsUserSubscribed({ subscriptionId: request.subscriptionId });\n\n const cancelledSubscription =\n await this.#subscriptionService.cancelSubscription(request);\n\n this.update((state) => {\n state.subscriptions = state.subscriptions.map((subscription) =>\n subscription.id === request.subscriptionId\n ? { ...subscription, ...cancelledSubscription }\n : subscription,\n );\n });\n\n this.triggerAccessTokenRefresh();\n }\n\n async unCancelSubscription(request: {\n subscriptionId: string;\n }): Promise<void> {\n this.#assertIsUserSubscribed({ subscriptionId: request.subscriptionId });\n\n const uncancelledSubscription =\n await this.#subscriptionService.unCancelSubscription({\n subscriptionId: request.subscriptionId,\n });\n\n this.update((state) => {\n state.subscriptions = state.subscriptions.map((subscription) =>\n subscription.id === request.subscriptionId\n ? { ...subscription, ...uncancelledSubscription }\n : subscription,\n );\n });\n\n this.triggerAccessTokenRefresh();\n }\n\n async startShieldSubscriptionWithCard(\n request: StartSubscriptionRequest,\n ): Promise<StartSubscriptionResponse> {\n this.#assertIsUserNotSubscribed({ products: request.products });\n\n const response =\n await this.#subscriptionService.startSubscriptionWithCard(request);\n // note: no need to trigger access token refresh after startSubscriptionWithCard request because this only return stripe checkout session url, subscription not created yet\n\n return response;\n }\n\n async startSubscriptionWithCrypto(\n request: StartCryptoSubscriptionRequest,\n ): Promise<StartCryptoSubscriptionResponse> {\n this.#assertIsUserNotSubscribed({ products: request.products });\n const response =\n await this.#subscriptionService.startSubscriptionWithCrypto(request);\n\n return response;\n }\n\n /**\n * Handles shield subscription crypto approval transactions.\n *\n * @param txMeta - The transaction metadata.\n * @param isSponsored - Whether the transaction is sponsored.\n * @param rewardAccountId - The account ID of the reward subscription to link to the shield subscription.\n * @returns void\n */\n async submitShieldSubscriptionCryptoApproval(\n txMeta: TransactionMeta,\n isSponsored?: boolean,\n rewardAccountId?: CaipAccountId,\n ): Promise<void> {\n if (txMeta.type !== TransactionType.shieldSubscriptionApprove) {\n return;\n }\n\n const { chainId, rawTx } = txMeta;\n if (!chainId || !rawTx) {\n throw new Error('Chain ID or raw transaction not found');\n }\n\n const { pricing, trialedProducts, lastSelectedPaymentMethod } = this.state;\n if (!pricing) {\n throw new Error('Subscription pricing not found');\n }\n if (!lastSelectedPaymentMethod) {\n throw new Error('Last selected payment method not found');\n }\n const lastSelectedPaymentMethodShield =\n lastSelectedPaymentMethod[PRODUCT_TYPES.SHIELD];\n this.#assertIsPaymentMethodCrypto(lastSelectedPaymentMethodShield);\n\n const productPrice = this.#getProductPriceByProductAndPlan(\n PRODUCT_TYPES.SHIELD,\n lastSelectedPaymentMethodShield.plan,\n );\n const isTrialed = trialedProducts?.includes(PRODUCT_TYPES.SHIELD);\n // get the latest subscriptions state to check if the user has an active shield subscription\n await this.getSubscriptions();\n const currentSubscription = this.state.subscriptions.find((subscription) =>\n subscription.products.some(\n (product) => product.name === PRODUCT_TYPES.SHIELD,\n ),\n );\n\n this.#assertValidSubscriptionStateForCryptoApproval({\n productType: PRODUCT_TYPES.SHIELD,\n });\n // if shield subscription exists, this transaction is for changing payment method\n const isChangePaymentMethod = Boolean(currentSubscription);\n\n if (isChangePaymentMethod) {\n await this.updatePaymentMethod({\n paymentType: PAYMENT_TYPES.byCrypto,\n subscriptionId: (currentSubscription as Subscription).id,\n chainId,\n payerAddress: txMeta.txParams.from as Hex,\n tokenSymbol: lastSelectedPaymentMethodShield.paymentTokenSymbol,\n rawTransaction: rawTx as Hex,\n recurringInterval: productPrice.interval,\n billingCycles: productPrice.minBillingCycles,\n });\n } else {\n const params = {\n products: [PRODUCT_TYPES.SHIELD],\n isTrialRequested: !isTrialed,\n recurringInterval: productPrice.interval,\n billingCycles: productPrice.minBillingCycles,\n chainId,\n payerAddress: txMeta.txParams.from as Hex,\n tokenSymbol: lastSelectedPaymentMethodShield.paymentTokenSymbol,\n rawTransaction: rawTx as Hex,\n isSponsored,\n useTestClock: lastSelectedPaymentMethodShield.useTestClock,\n rewardAccountId,\n };\n await this.startSubscriptionWithCrypto(params);\n }\n\n // update the subscriptions state after subscription created in server\n await this.getSubscriptions();\n }\n\n /**\n * Get transaction params to create crypto approve transaction for subscription payment\n *\n * @param request - The request object\n * @param request.chainId - The chain ID\n * @param request.tokenAddress - The address of the token\n * @param request.productType - The product type\n * @param request.interval - The interval\n * @returns The crypto approve transaction params\n */\n getCryptoApproveTransactionParams(\n request: GetCryptoApproveTransactionRequest,\n ): GetCryptoApproveTransactionResponse {\n const { pricing } = this.state;\n if (!pricing) {\n throw new Error('Subscription pricing not found');\n }\n const product = pricing.products.find(\n (productInfo) => productInfo.name === request.productType,\n );\n if (!product) {\n throw new Error('Product price not found');\n }\n\n const price = product.prices.find(\n (productPrice) => productPrice.interval === request.interval,\n );\n if (!price) {\n throw new Error('Price not found');\n }\n\n const chainsPaymentInfo = pricing.paymentMethods.find(\n (paymentMethod) => paymentMethod.type === PAYMENT_TYPES.byCrypto,\n );\n if (!chainsPaymentInfo) {\n throw new Error('Chains payment info not found');\n }\n const chainPaymentInfo = chainsPaymentInfo.chains?.find(\n (chain) => chain.chainId === request.chainId,\n );\n if (!chainPaymentInfo) {\n throw new Error('Invalid chain id');\n }\n const tokenPaymentInfo = chainPaymentInfo.tokens.find(\n (token) => token.address === request.paymentTokenAddress,\n );\n if (!tokenPaymentInfo) {\n throw new Error('Invalid token address');\n }\n\n const tokenApproveAmount = this.getTokenApproveAmount(\n price,\n tokenPaymentInfo,\n );\n\n return {\n approveAmount: tokenApproveAmount,\n paymentAddress: chainPaymentInfo.paymentAddress,\n paymentTokenAddress: request.paymentTokenAddress,\n chainId: request.chainId,\n };\n }\n\n async updatePaymentMethod(\n opts: UpdatePaymentMethodOpts,\n ): Promise<UpdatePaymentMethodCardResponse | Subscription[]> {\n if (opts.paymentType === PAYMENT_TYPES.byCard) {\n const { paymentType, ...cardRequest } = opts;\n return await this.#subscriptionService.updatePaymentMethodCard(\n cardRequest,\n );\n } else if (opts.paymentType === PAYMENT_TYPES.byCrypto) {\n const { paymentType, ...cryptoRequest } = opts;\n await this.#subscriptionService.updatePaymentMethodCrypto(cryptoRequest);\n return await this.getSubscriptions();\n }\n throw new Error('Invalid payment type');\n }\n\n /**\n * Gets the billing portal URL.\n *\n * @returns The billing portal URL\n */\n async getBillingPortalUrl(): Promise<BillingPortalResponse> {\n return await this.#subscriptionService.getBillingPortalUrl();\n }\n\n /**\n * Cache the last selected payment method for a specific product.\n *\n * @param product - The product to cache the payment method for.\n * @param paymentMethod - The payment method to cache.\n * @param paymentMethod.type - The type of the payment method.\n * @param paymentMethod.paymentTokenAddress - The payment token address.\n * @param paymentMethod.plan - The plan of the payment method.\n * @param paymentMethod.product - The product of the payment method.\n */\n cacheLastSelectedPaymentMethod(\n product: ProductType,\n paymentMethod: CachedLastSelectedPaymentMethod,\n ): void {\n if (\n paymentMethod.type === PAYMENT_TYPES.byCrypto &&\n (!paymentMethod.paymentTokenAddress || !paymentMethod.paymentTokenSymbol)\n ) {\n throw new Error(\n SubscriptionControllerErrorMessage.PaymentTokenAddressAndSymbolRequiredForCrypto,\n );\n }\n\n this.update((state) => {\n state.lastSelectedPaymentMethod = {\n ...state.lastSelectedPaymentMethod,\n [product]: paymentMethod,\n };\n });\n }\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 * @returns resolves to true if the sponsorship is supported and intents were submitted successfully, false otherwise\n */\n async submitSponsorshipIntents(\n request: SubmitSponsorshipIntentsMethodParams,\n ): Promise<boolean> {\n if (request.products.length === 0) {\n throw new Error(\n SubscriptionControllerErrorMessage.SubscriptionProductsEmpty,\n );\n }\n\n this.#assertIsUserNotSubscribed({ products: request.products });\n\n const selectedPaymentMethod =\n this.state.lastSelectedPaymentMethod?.[request.products[0]];\n this.#assertIsPaymentMethodCrypto(selectedPaymentMethod);\n\n const isEligibleForTrialedSponsorship =\n this.#getIsEligibleForTrialedSponsorship(\n request.chainId,\n request.products,\n );\n if (!isEligibleForTrialedSponsorship) {\n return false;\n }\n\n const { paymentTokenSymbol, plan } = selectedPaymentMethod;\n const productPrice = this.#getProductPriceByProductAndPlan(\n // we only support one product at a time for now\n request.products[0],\n plan,\n );\n const billingCycles = productPrice.minBillingCycles;\n\n await this.#subscriptionService.submitSponsorshipIntents({\n ...request,\n paymentTokenSymbol,\n billingCycles,\n recurringInterval: plan,\n });\n return true;\n }\n\n /**\n * Submit a user event from the UI. (e.g. shield modal viewed)\n *\n * @param request - Request object containing the event to submit.\n * @example { event: SubscriptionUserEvent.ShieldEntryModalViewed, cohort: 'post_tx' }\n */\n async submitUserEvent(request: SubmitUserEventRequest): Promise<void> {\n await this.#subscriptionService.submitUserEvent(request);\n }\n\n /**\n * Assign user to a cohort.\n *\n * @param request - Request object containing the cohort to assign the user to.\n * @example { cohort: 'post_tx' }\n */\n async assignUserToCohort(request: AssignCohortRequest): Promise<void> {\n await this.#subscriptionService.assignUserToCohort(request);\n }\n\n /**\n * Link rewards to a subscription.\n *\n * @param request - Request object containing the reward subscription ID.\n * @param request.subscriptionId - The ID of the subscription to link rewards to.\n * @param request.rewardAccountId - The account ID of the reward subscription to link to the subscription.\n * @example { subscriptionId: '1234567890', rewardAccountId: 'eip155:1:0x1234567890123456789012345678901234567890' }\n * @returns Resolves when the rewards are linked successfully.\n */\n async linkRewards(\n request: LinkRewardsRequest & { subscriptionId: string },\n ): Promise<void> {\n // assert that the user is subscribed to the subscription\n this.#assertIsUserSubscribed({ subscriptionId: request.subscriptionId });\n\n // link rewards to the subscription\n const response = await this.#subscriptionService.linkRewards({\n rewardAccountId: request.rewardAccountId,\n });\n if (!response.success) {\n throw new Error(SubscriptionControllerErrorMessage.LinkRewardsFailed);\n }\n }\n\n async _executePoll(): Promise<void> {\n await this.getSubscriptions();\n }\n\n /**\n * Calculate total subscription price amount (approval amount) from price info\n * e.g: $8 per month * 12 months min billing cycles = $96\n *\n * @param price - The price info\n * @returns The price amount\n */\n #getSubscriptionPriceAmount(price: ProductPrice): string {\n // no need to use BigInt since max unitDecimals are always 2 for price\n const amount = new BigNumber(price.unitAmount)\n .div(10 ** price.unitDecimals)\n .multipliedBy(price.minBillingCycles)\n .toString();\n return amount;\n }\n\n /**\n * Calculate minimum subscription balance amount from price info\n *\n * @param price - The price info\n * @returns The balance amount\n */\n #getSubscriptionBalanceAmount(price: ProductPrice): string {\n // no need to use BigInt since max unitDecimals are always 2 for price\n const amount = new BigNumber(price.unitAmount)\n .div(10 ** price.unitDecimals)\n .multipliedBy(price.minBillingCyclesForBalance)\n .toString();\n return amount;\n }\n\n /**\n * Calculate token approve amount from price info\n *\n * @param price - The price info\n * @param tokenPaymentInfo - The token price info\n * @returns The token approve amount\n */\n getTokenApproveAmount(\n price: ProductPrice,\n tokenPaymentInfo: TokenPaymentInfo,\n ): string {\n const conversionRate =\n tokenPaymentInfo.conversionRate[\n price.currency as keyof typeof tokenPaymentInfo.conversionRate\n ];\n if (!conversionRate) {\n throw new Error('Conversion rate not found');\n }\n // price of the product\n const priceAmount = new BigNumber(this.#getSubscriptionPriceAmount(price));\n\n const tokenDecimal = new BigNumber(10).pow(tokenPaymentInfo.decimals);\n const tokenAmount = priceAmount\n .multipliedBy(tokenDecimal)\n .div(conversionRate);\n return tokenAmount.toFixed(0);\n }\n\n /**\n * Calculate token minimum balance amount from price info\n *\n * @param price - The price info\n * @param tokenPaymentInfo - The token price info\n * @returns The token balance amount\n */\n getTokenMinimumBalanceAmount(\n price: ProductPrice,\n tokenPaymentInfo: TokenPaymentInfo,\n ): string {\n const conversionRate =\n tokenPaymentInfo.conversionRate[\n price.currency as keyof typeof tokenPaymentInfo.conversionRate\n ];\n if (!conversionRate) {\n throw new Error('Conversion rate not found');\n }\n const balanceAmount = new BigNumber(\n this.#getSubscriptionBalanceAmount(price),\n );\n\n const tokenDecimal = new BigNumber(10).pow(tokenPaymentInfo.decimals);\n const tokenAmount = balanceAmount\n .multipliedBy(tokenDecimal)\n .div(conversionRate);\n return tokenAmount.toFixed(0);\n }\n\n /**\n * Triggers an access token refresh.\n */\n triggerAccessTokenRefresh(): void {\n // We perform a sign out to clear the access token from the authentication\n // controller. Next time the access token is requested, a new access token\n // will be fetched.\n this.messenger.call('AuthenticationController:performSignOut');\n }\n\n #getProductPriceByProductAndPlan(\n productType: ProductType,\n plan: RecurringInterval,\n ): ProductPrice {\n const { pricing } = this.state;\n const productPricing = pricing?.products.find(\n (product) => product.name === productType,\n );\n const productPrice = productPricing?.prices.find(\n (price) => price.interval === plan,\n );\n if (!productPrice) {\n throw new Error(SubscriptionControllerErrorMessage.ProductPriceNotFound);\n }\n return productPrice;\n }\n\n #assertValidSubscriptionStateForCryptoApproval({\n productType,\n }: {\n productType: ProductType;\n }): void {\n const subscription = this.state.subscriptions.find((sub) =>\n sub.products.some((product) => product.name === productType),\n );\n\n const isValid =\n !subscription ||\n (\n [\n SUBSCRIPTION_STATUSES.pastDue,\n SUBSCRIPTION_STATUSES.unpaid,\n SUBSCRIPTION_STATUSES.paused,\n SUBSCRIPTION_STATUSES.provisional,\n SUBSCRIPTION_STATUSES.active,\n SUBSCRIPTION_STATUSES.trialing,\n ] as SubscriptionStatus[]\n ).includes(subscription.status);\n if (!isValid) {\n throw new Error(\n SubscriptionControllerErrorMessage.SubscriptionNotValidForCryptoApproval,\n );\n }\n }\n\n #assertIsUserNotSubscribed({ products }: { products: ProductType[] }): void {\n const subscription = this.state.subscriptions.find((sub) =>\n sub.products.some((product) => products.includes(product.name)),\n );\n\n if (\n subscription &&\n ACTIVE_SUBSCRIPTION_STATUSES.includes(subscription.status)\n ) {\n throw new Error(SubscriptionControllerErrorMessage.UserAlreadySubscribed);\n }\n }\n\n #assertIsUserSubscribed(request: { subscriptionId: string }): void {\n if (\n !this.state.subscriptions.find(\n (subscription) => subscription.id === request.subscriptionId,\n )\n ) {\n throw new Error(SubscriptionControllerErrorMessage.UserNotSubscribed);\n }\n }\n\n /**\n * Asserts that the value is a valid crypto payment method.\n *\n * @param value - The value to assert.\n * @throws an error if the value is not a valid crypto payment method.\n */\n #assertIsPaymentMethodCrypto(\n value: CachedLastSelectedPaymentMethod | undefined,\n ): asserts value is Required<CachedLastSelectedPaymentMethod> {\n if (\n !value ||\n value.type !== PAYMENT_TYPES.byCrypto ||\n !value.paymentTokenAddress ||\n !value.paymentTokenSymbol\n ) {\n throw new Error(\n SubscriptionControllerErrorMessage.PaymentMethodNotCrypto,\n );\n }\n }\n\n /**\n * Determines if the user is eligible for trialed sponsorship for the given chain and products.\n * The user is eligible if the chain supports sponsorship and the user has not trialed the provided products before.\n *\n * @param chainId - The chain ID\n * @param products - The products to check eligibility for\n * @returns True if the user is eligible for trialed sponsorship, false otherwise\n */\n #getIsEligibleForTrialedSponsorship(\n chainId: Hex,\n products: ProductType[],\n ): boolean {\n const isSponsorshipSupported = this.#getChainSupportsSponsorship(chainId);\n\n // verify if the user has trialed the provided products before\n const hasTrialedBefore = this.state.trialedProducts.some((product) =>\n products.includes(product),\n );\n\n return isSponsorshipSupported && !hasTrialedBefore;\n }\n\n #getChainSupportsSponsorship(chainId: Hex): boolean {\n const cryptoPaymentInfo = this.state.pricing?.paymentMethods.find(\n (paymentMethod) => paymentMethod.type === PAYMENT_TYPES.byCrypto,\n );\n\n const isSponsorshipSupported = cryptoPaymentInfo?.chains?.find(\n (chain) => chain.chainId === chainId,\n )?.isSponsorshipSupported;\n return Boolean(isSponsorshipSupported);\n }\n\n /**\n * Determines whether two trialed products arrays are equal by comparing all products in the arrays.\n *\n * @param oldTrialedProducts - The first trialed products array to compare.\n * @param newTrialedProducts - The second trialed products array to compare.\n * @returns True if the trialed products arrays are equal, false otherwise.\n */\n #areTrialedProductsEqual(\n oldTrialedProducts: ProductType[],\n newTrialedProducts: ProductType[],\n ): boolean {\n return (\n oldTrialedProducts.length === newTrialedProducts?.length &&\n oldTrialedProducts.every((product) =>\n newTrialedProducts?.includes(product),\n )\n );\n }\n\n /**\n * Determines whether two subscription arrays are equal by comparing all properties\n * of each subscription in the arrays.\n *\n * @param oldSubs - The first subscription array to compare.\n * @param newSubs - The second subscription array to compare.\n * @returns True if the subscription arrays are equal, false otherwise.\n */\n #areSubscriptionsEqual(\n oldSubs: Subscription[],\n newSubs: Subscription[],\n ): boolean {\n // Check if arrays have different lengths\n if (oldSubs.length !== newSubs.length) {\n return false;\n }\n\n // Sort both arrays by id to ensure consistent comparison\n const sortedOldSubs = [...oldSubs].sort((a, b) => a.id.localeCompare(b.id));\n const sortedNewSubs = [...newSubs].sort((a, b) => a.id.localeCompare(b.id));\n\n // Check if all subscriptions are equal\n return sortedOldSubs.every((oldSub, index) => {\n const newSub = sortedNewSubs[index];\n return this.#isSubscriptionEqual(oldSub, newSub);\n });\n }\n\n #isSubscriptionEqual(oldSub?: Subscription, newSub?: Subscription): boolean {\n // not equal if one is undefined and the other is defined\n if (!oldSub || !newSub) {\n if (!oldSub && !newSub) {\n return true;\n }\n return false;\n }\n\n return (\n this.#stringifySubscription(oldSub) ===\n this.#stringifySubscription(newSub)\n );\n }\n\n #stringifySubscription(subscription: Subscription): string {\n const subsWithSortedProducts = {\n ...subscription,\n // order the products by name\n products: [...subscription.products].sort((a, b) =>\n a.name.localeCompare(b.name),\n ),\n };\n\n return JSON.stringify(subsWithSortedProducts);\n }\n}\n"]}
|
|
@@ -31,7 +31,9 @@ class SubscriptionService {
|
|
|
31
31
|
}
|
|
32
32
|
async cancelSubscription(params) {
|
|
33
33
|
const path = `subscriptions/${params.subscriptionId}/cancel`;
|
|
34
|
-
return await __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_makeRequest).call(this, path, 'POST', {
|
|
34
|
+
return await __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_makeRequest).call(this, path, 'POST', {
|
|
35
|
+
cancelAtPeriodEnd: params.cancelAtPeriodEnd,
|
|
36
|
+
});
|
|
35
37
|
}
|
|
36
38
|
async unCancelSubscription(params) {
|
|
37
39
|
const path = `subscriptions/${params.subscriptionId}/uncancel`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SubscriptionService.cjs","sourceRoot":"","sources":["../src/SubscriptionService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,iEAAyD;AAEzD,+CAA6E;AAE7E,yCAAoD;AA6B7C,MAAM,gBAAgB,GAAG,CAAC,GAAQ,EAAE,IAAY,EAAU,EAAE,CACjE,GAAG,IAAA,sBAAU,EAAC,GAAG,CAAC,CAAC,kBAAkB,OAAO,IAAI,EAAE,CAAC;AADxC,QAAA,gBAAgB,oBACwB;AAErD,MAAa,mBAAmB;IAK9B,YAAY,MAAiC;;QAJpC,2CAAU;QAKjB,uBAAA,IAAI,4BAAQ,MAAM,CAAC,GAAG,MAAA,CAAC;QACvB,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC;IAC/B,CAAC;IAED,KAAK,CAAC,gBAAgB;QACpB,MAAM,IAAI,GAAG,eAAe,CAAC;QAC7B,OAAO,MAAM,uBAAA,IAAI,wEAAa,MAAjB,IAAI,EAAc,IAAI,CAAC,CAAC;IACvC,CAAC;IAED,KAAK,CAAC,kBAAkB,CAAC,MAExB;QACC,MAAM,IAAI,GAAG,iBAAiB,MAAM,CAAC,cAAc,SAAS,CAAC;QAC7D,OAAO,MAAM,uBAAA,IAAI,wEAAa,MAAjB,IAAI,EAAc,IAAI,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC;IACnD,CAAC;IAED,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EAAC,GAAG,CAAC,QAAQ,EAAE,EAAE;YACjD,MAAM;YACN,OAAO,EAAE;gBACP,cAAc,EAAE,kBAAkB;gBAClC,GAAG,OAAO;aACX;YACD,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS;SAC9C,CAAC,CAAC;QAEH,OAAO,QAAQ,CAAC;IAClB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,YAAY,GAChB,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QAEjE,MAAM,IAAI,iCAAwB,CAChC,2BAA2B,YAAY,EAAE,CAC1C,CAAC;IACJ,CAAC;AACH,CAAC;AAED,gEAAgE;AAChE,KAAK;IACH,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,cAAc,EAAE,CAAC;IAC1D,OAAO,EAAE,aAAa,EAAE,UAAU,WAAW,EAAE,EAAE,CAAC;AACpD,CAAC","sourcesContent":["import { handleFetch } from '@metamask/controller-utils';\n\nimport { getEnvUrls, SubscriptionControllerErrorMessage } from './constants';\nimport type { Env } from './constants';\nimport { SubscriptionServiceError } from './errors';\nimport type {\n AssignCohortRequest,\n AuthUtils,\n BillingPortalResponse,\n GetSubscriptionsEligibilitiesRequest,\n GetSubscriptionsResponse,\n ISubscriptionService,\n PricingResponse,\n SubscriptionEligibility,\n StartCryptoSubscriptionRequest,\n StartCryptoSubscriptionResponse,\n StartSubscriptionRequest,\n StartSubscriptionResponse,\n SubmitUserEventRequest,\n Subscription,\n UpdatePaymentMethodCardRequest,\n UpdatePaymentMethodCardResponse,\n UpdatePaymentMethodCryptoRequest,\n SubmitSponsorshipIntentsRequest,\n LinkRewardsRequest,\n SubscriptionApiGeneralResponse,\n} from './types';\n\nexport type SubscriptionServiceConfig = {\n env: Env;\n auth: AuthUtils;\n};\n\nexport const SUBSCRIPTION_URL = (env: Env, path: string): string =>\n `${getEnvUrls(env).subscriptionApiUrl}/v1/${path}`;\n\nexport class SubscriptionService implements ISubscriptionService {\n readonly #env: Env;\n\n public authUtils: AuthUtils;\n\n constructor(config: SubscriptionServiceConfig) {\n this.#env = config.env;\n this.authUtils = config.auth;\n }\n\n async getSubscriptions(): Promise<GetSubscriptionsResponse> {\n const path = 'subscriptions';\n return await this.#makeRequest(path);\n }\n\n async cancelSubscription(params: {\n subscriptionId: string;\n }): Promise<Subscription> {\n const path = `subscriptions/${params.subscriptionId}/cancel`;\n return await this.#makeRequest(path, 'POST', {});\n }\n\n async unCancelSubscription(params: {\n subscriptionId: string;\n }): Promise<Subscription> {\n const path = `subscriptions/${params.subscriptionId}/uncancel`;\n return await this.#makeRequest(path, 'POST', {});\n }\n\n async startSubscriptionWithCard(\n request: StartSubscriptionRequest,\n ): Promise<StartSubscriptionResponse> {\n if (request.products.length === 0) {\n throw new SubscriptionServiceError(\n SubscriptionControllerErrorMessage.SubscriptionProductsEmpty,\n );\n }\n const path = 'subscriptions/card';\n\n return await this.#makeRequest(path, 'POST', request);\n }\n\n async startSubscriptionWithCrypto(\n request: StartCryptoSubscriptionRequest,\n ): Promise<StartCryptoSubscriptionResponse> {\n const path = 'subscriptions/crypto';\n return await this.#makeRequest(path, 'POST', request);\n }\n\n async updatePaymentMethodCard(\n request: UpdatePaymentMethodCardRequest,\n ): Promise<UpdatePaymentMethodCardResponse> {\n const path = `subscriptions/${request.subscriptionId}/payment-method/card`;\n return await this.#makeRequest<UpdatePaymentMethodCardResponse>(\n path,\n 'PATCH',\n {\n ...request,\n subscriptionId: undefined,\n },\n );\n }\n\n async updatePaymentMethodCrypto(\n request: UpdatePaymentMethodCryptoRequest,\n ): Promise<void> {\n const path = `subscriptions/${request.subscriptionId}/payment-method/crypto`;\n await this.#makeRequest(path, 'PATCH', {\n ...request,\n subscriptionId: undefined,\n });\n }\n\n /**\n * Get the eligibility for a shield subscription.\n *\n * @param request - Optional request object containing user balance category to check cohort eligibility\n * @returns The eligibility for a shield subscription\n */\n async getSubscriptionsEligibilities(\n request?: GetSubscriptionsEligibilitiesRequest,\n ): Promise<SubscriptionEligibility[]> {\n const path = 'subscriptions/eligibility';\n let query: Record<string, string> | undefined;\n if (request?.balanceCategory !== undefined) {\n query = { balanceCategory: request.balanceCategory };\n }\n const results = await this.#makeRequest<SubscriptionEligibility[]>(\n path,\n 'GET',\n undefined,\n query,\n );\n\n return results.map((result) => ({\n ...result,\n canSubscribe: result.canSubscribe || false,\n canViewEntryModal: result.canViewEntryModal || false,\n cohorts: result.cohorts || [],\n assignedCohort: result.assignedCohort ?? null,\n hasAssignedCohortExpired: result.hasAssignedCohortExpired || false,\n }));\n }\n\n /**\n * Submit a user event. (e.g. shield modal viewed)\n *\n * @param request - Request object containing the event to submit.\n * @example { event: SubscriptionUserEvent.ShieldEntryModalViewed, cohort: 'post_tx' }\n */\n async submitUserEvent(request: SubmitUserEventRequest): Promise<void> {\n const path = 'user-events';\n await this.#makeRequest(path, 'POST', request);\n }\n\n /**\n * Assign user to a cohort.\n *\n * @param request - Request object containing the cohort to assign the user to.\n * @example { cohort: 'post_tx' }\n */\n async assignUserToCohort(request: AssignCohortRequest): Promise<void> {\n const path = 'cohorts/assign';\n await this.#makeRequest(path, 'POST', request);\n }\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 { address: '0x1234567890123456789012345678901234567890', products: [ProductType.Shield] }\n */\n async submitSponsorshipIntents(\n request: SubmitSponsorshipIntentsRequest,\n ): Promise<void> {\n const path = 'transaction-sponsorship/intents';\n await this.#makeRequest(path, 'POST', request);\n }\n\n /**\n * Link rewards to a subscription.\n *\n * @param request - Request object containing the reward account ID.\n * @example { rewardAccountId: 'eip155:1:0x1234567890123456789012345678901234567890' }\n * @returns The response from the API.\n */\n async linkRewards(\n request: LinkRewardsRequest,\n ): Promise<SubscriptionApiGeneralResponse> {\n const path = 'rewards/link';\n return await this.#makeRequest<SubscriptionApiGeneralResponse>(\n path,\n 'POST',\n request,\n );\n }\n\n async #makeRequest<Result>(\n path: string,\n method: 'GET' | 'POST' | 'DELETE' | 'PUT' | 'PATCH' = 'GET',\n body?: Record<string, unknown>,\n queryParams?: Record<string, string>,\n ): Promise<Result> {\n try {\n const headers = await this.#getAuthorizationHeader();\n const url = new URL(SUBSCRIPTION_URL(this.#env, path));\n\n if (queryParams) {\n Object.entries(queryParams).forEach(([key, value]) => {\n url.searchParams.append(key, value);\n });\n }\n\n const response = await handleFetch(url.toString(), {\n method,\n headers: {\n 'Content-Type': 'application/json',\n ...headers,\n },\n body: body ? JSON.stringify(body) : undefined,\n });\n\n return response;\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : JSON.stringify(error);\n\n throw new SubscriptionServiceError(\n `failed to make request. ${errorMessage}`,\n );\n }\n }\n\n // eslint-disable-next-line @typescript-eslint/naming-convention\n async #getAuthorizationHeader(): Promise<{ Authorization: string }> {\n const accessToken = await this.authUtils.getAccessToken();\n return { Authorization: `Bearer ${accessToken}` };\n }\n\n async getPricing(): Promise<PricingResponse> {\n const path = 'pricing';\n return await this.#makeRequest<PricingResponse>(path);\n }\n\n async getBillingPortalUrl(): Promise<BillingPortalResponse> {\n const path = 'billing-portal';\n return await this.#makeRequest<BillingPortalResponse>(path);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"SubscriptionService.cjs","sourceRoot":"","sources":["../src/SubscriptionService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,iEAAyD;AAEzD,+CAA6E;AAE7E,yCAAoD;AA8B7C,MAAM,gBAAgB,GAAG,CAAC,GAAQ,EAAE,IAAY,EAAU,EAAE,CACjE,GAAG,IAAA,sBAAU,EAAC,GAAG,CAAC,CAAC,kBAAkB,OAAO,IAAI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,SAAS,CAAC,cAAc,EAAE,CAAC;IAC1D,OAAO,EAAE,aAAa,EAAE,UAAU,WAAW,EAAE,EAAE,CAAC;AACpD,CAAC","sourcesContent":["import { handleFetch } from '@metamask/controller-utils';\n\nimport { getEnvUrls, SubscriptionControllerErrorMessage } from './constants';\nimport type { Env } from './constants';\nimport { SubscriptionServiceError } from './errors';\nimport type {\n AssignCohortRequest,\n AuthUtils,\n BillingPortalResponse,\n GetSubscriptionsEligibilitiesRequest,\n GetSubscriptionsResponse,\n ISubscriptionService,\n PricingResponse,\n SubscriptionEligibility,\n StartCryptoSubscriptionRequest,\n StartCryptoSubscriptionResponse,\n StartSubscriptionRequest,\n StartSubscriptionResponse,\n SubmitUserEventRequest,\n Subscription,\n UpdatePaymentMethodCardRequest,\n UpdatePaymentMethodCardResponse,\n UpdatePaymentMethodCryptoRequest,\n SubmitSponsorshipIntentsRequest,\n LinkRewardsRequest,\n SubscriptionApiGeneralResponse,\n CancelSubscriptionRequest,\n} from './types';\n\nexport type SubscriptionServiceConfig = {\n env: Env;\n auth: AuthUtils;\n};\n\nexport const SUBSCRIPTION_URL = (env: Env, path: string): string =>\n `${getEnvUrls(env).subscriptionApiUrl}/v1/${path}`;\n\nexport class SubscriptionService implements ISubscriptionService {\n readonly #env: Env;\n\n public authUtils: AuthUtils;\n\n constructor(config: SubscriptionServiceConfig) {\n this.#env = config.env;\n this.authUtils = config.auth;\n }\n\n async getSubscriptions(): Promise<GetSubscriptionsResponse> {\n const path = 'subscriptions';\n return await this.#makeRequest(path);\n }\n\n async cancelSubscription(\n params: CancelSubscriptionRequest,\n ): Promise<Subscription> {\n const path = `subscriptions/${params.subscriptionId}/cancel`;\n return await this.#makeRequest(path, 'POST', {\n cancelAtPeriodEnd: params.cancelAtPeriodEnd,\n });\n }\n\n async unCancelSubscription(params: {\n subscriptionId: string;\n }): Promise<Subscription> {\n const path = `subscriptions/${params.subscriptionId}/uncancel`;\n return await this.#makeRequest(path, 'POST', {});\n }\n\n async startSubscriptionWithCard(\n request: StartSubscriptionRequest,\n ): Promise<StartSubscriptionResponse> {\n if (request.products.length === 0) {\n throw new SubscriptionServiceError(\n SubscriptionControllerErrorMessage.SubscriptionProductsEmpty,\n );\n }\n const path = 'subscriptions/card';\n\n return await this.#makeRequest(path, 'POST', request);\n }\n\n async startSubscriptionWithCrypto(\n request: StartCryptoSubscriptionRequest,\n ): Promise<StartCryptoSubscriptionResponse> {\n const path = 'subscriptions/crypto';\n return await this.#makeRequest(path, 'POST', request);\n }\n\n async updatePaymentMethodCard(\n request: UpdatePaymentMethodCardRequest,\n ): Promise<UpdatePaymentMethodCardResponse> {\n const path = `subscriptions/${request.subscriptionId}/payment-method/card`;\n return await this.#makeRequest<UpdatePaymentMethodCardResponse>(\n path,\n 'PATCH',\n {\n ...request,\n subscriptionId: undefined,\n },\n );\n }\n\n async updatePaymentMethodCrypto(\n request: UpdatePaymentMethodCryptoRequest,\n ): Promise<void> {\n const path = `subscriptions/${request.subscriptionId}/payment-method/crypto`;\n await this.#makeRequest(path, 'PATCH', {\n ...request,\n subscriptionId: undefined,\n });\n }\n\n /**\n * Get the eligibility for a shield subscription.\n *\n * @param request - Optional request object containing user balance category to check cohort eligibility\n * @returns The eligibility for a shield subscription\n */\n async getSubscriptionsEligibilities(\n request?: GetSubscriptionsEligibilitiesRequest,\n ): Promise<SubscriptionEligibility[]> {\n const path = 'subscriptions/eligibility';\n let query: Record<string, string> | undefined;\n if (request?.balanceCategory !== undefined) {\n query = { balanceCategory: request.balanceCategory };\n }\n const results = await this.#makeRequest<SubscriptionEligibility[]>(\n path,\n 'GET',\n undefined,\n query,\n );\n\n return results.map((result) => ({\n ...result,\n canSubscribe: result.canSubscribe || false,\n canViewEntryModal: result.canViewEntryModal || false,\n cohorts: result.cohorts || [],\n assignedCohort: result.assignedCohort ?? null,\n hasAssignedCohortExpired: result.hasAssignedCohortExpired || false,\n }));\n }\n\n /**\n * Submit a user event. (e.g. shield modal viewed)\n *\n * @param request - Request object containing the event to submit.\n * @example { event: SubscriptionUserEvent.ShieldEntryModalViewed, cohort: 'post_tx' }\n */\n async submitUserEvent(request: SubmitUserEventRequest): Promise<void> {\n const path = 'user-events';\n await this.#makeRequest(path, 'POST', request);\n }\n\n /**\n * Assign user to a cohort.\n *\n * @param request - Request object containing the cohort to assign the user to.\n * @example { cohort: 'post_tx' }\n */\n async assignUserToCohort(request: AssignCohortRequest): Promise<void> {\n const path = 'cohorts/assign';\n await this.#makeRequest(path, 'POST', request);\n }\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 { address: '0x1234567890123456789012345678901234567890', products: [ProductType.Shield] }\n */\n async submitSponsorshipIntents(\n request: SubmitSponsorshipIntentsRequest,\n ): Promise<void> {\n const path = 'transaction-sponsorship/intents';\n await this.#makeRequest(path, 'POST', request);\n }\n\n /**\n * Link rewards to a subscription.\n *\n * @param request - Request object containing the reward account ID.\n * @example { rewardAccountId: 'eip155:1:0x1234567890123456789012345678901234567890' }\n * @returns The response from the API.\n */\n async linkRewards(\n request: LinkRewardsRequest,\n ): Promise<SubscriptionApiGeneralResponse> {\n const path = 'rewards/link';\n return await this.#makeRequest<SubscriptionApiGeneralResponse>(\n path,\n 'POST',\n request,\n );\n }\n\n async #makeRequest<Result>(\n path: string,\n method: 'GET' | 'POST' | 'DELETE' | 'PUT' | 'PATCH' = 'GET',\n body?: Record<string, unknown>,\n queryParams?: Record<string, string>,\n ): Promise<Result> {\n try {\n const headers = await this.#getAuthorizationHeader();\n const url = new URL(SUBSCRIPTION_URL(this.#env, path));\n\n if (queryParams) {\n Object.entries(queryParams).forEach(([key, value]) => {\n url.searchParams.append(key, value);\n });\n }\n\n const response = await handleFetch(url.toString(), {\n method,\n headers: {\n 'Content-Type': 'application/json',\n ...headers,\n },\n body: body ? JSON.stringify(body) : undefined,\n });\n\n return response;\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : JSON.stringify(error);\n\n throw new SubscriptionServiceError(\n `failed to make request. ${errorMessage}`,\n );\n }\n }\n\n // eslint-disable-next-line @typescript-eslint/naming-convention\n async #getAuthorizationHeader(): Promise<{ Authorization: string }> {\n const accessToken = await this.authUtils.getAccessToken();\n return { Authorization: `Bearer ${accessToken}` };\n }\n\n async getPricing(): Promise<PricingResponse> {\n const path = 'pricing';\n return await this.#makeRequest<PricingResponse>(path);\n }\n\n async getBillingPortalUrl(): Promise<BillingPortalResponse> {\n const path = 'billing-portal';\n return await this.#makeRequest<BillingPortalResponse>(path);\n }\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Env } from "./constants.cjs";
|
|
2
|
-
import type { AssignCohortRequest, AuthUtils, BillingPortalResponse, GetSubscriptionsEligibilitiesRequest, GetSubscriptionsResponse, ISubscriptionService, PricingResponse, SubscriptionEligibility, StartCryptoSubscriptionRequest, StartCryptoSubscriptionResponse, StartSubscriptionRequest, StartSubscriptionResponse, SubmitUserEventRequest, Subscription, UpdatePaymentMethodCardRequest, UpdatePaymentMethodCardResponse, UpdatePaymentMethodCryptoRequest, SubmitSponsorshipIntentsRequest, LinkRewardsRequest, SubscriptionApiGeneralResponse } from "./types.cjs";
|
|
2
|
+
import type { AssignCohortRequest, AuthUtils, BillingPortalResponse, GetSubscriptionsEligibilitiesRequest, GetSubscriptionsResponse, ISubscriptionService, PricingResponse, SubscriptionEligibility, StartCryptoSubscriptionRequest, StartCryptoSubscriptionResponse, StartSubscriptionRequest, StartSubscriptionResponse, SubmitUserEventRequest, Subscription, UpdatePaymentMethodCardRequest, UpdatePaymentMethodCardResponse, UpdatePaymentMethodCryptoRequest, SubmitSponsorshipIntentsRequest, LinkRewardsRequest, SubscriptionApiGeneralResponse, CancelSubscriptionRequest } from "./types.cjs";
|
|
3
3
|
export type SubscriptionServiceConfig = {
|
|
4
4
|
env: Env;
|
|
5
5
|
auth: AuthUtils;
|
|
@@ -10,9 +10,7 @@ export declare class SubscriptionService implements ISubscriptionService {
|
|
|
10
10
|
authUtils: AuthUtils;
|
|
11
11
|
constructor(config: SubscriptionServiceConfig);
|
|
12
12
|
getSubscriptions(): Promise<GetSubscriptionsResponse>;
|
|
13
|
-
cancelSubscription(params:
|
|
14
|
-
subscriptionId: string;
|
|
15
|
-
}): Promise<Subscription>;
|
|
13
|
+
cancelSubscription(params: CancelSubscriptionRequest): Promise<Subscription>;
|
|
16
14
|
unCancelSubscription(params: {
|
|
17
15
|
subscriptionId: string;
|
|
18
16
|
}): Promise<Subscription>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SubscriptionService.d.cts","sourceRoot":"","sources":["../src/SubscriptionService.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAoB;AAEvC,OAAO,KAAK,EACV,mBAAmB,EACnB,SAAS,EACT,qBAAqB,EACrB,oCAAoC,EACpC,wBAAwB,EACxB,oBAAoB,EACpB,eAAe,EACf,uBAAuB,EACvB,8BAA8B,EAC9B,+BAA+B,EAC/B,wBAAwB,EACxB,yBAAyB,EACzB,sBAAsB,EACtB,YAAY,EACZ,8BAA8B,EAC9B,+BAA+B,EAC/B,gCAAgC,EAChC,+BAA+B,EAC/B,kBAAkB,EAClB,8BAA8B,
|
|
1
|
+
{"version":3,"file":"SubscriptionService.d.cts","sourceRoot":"","sources":["../src/SubscriptionService.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAoB;AAEvC,OAAO,KAAK,EACV,mBAAmB,EACnB,SAAS,EACT,qBAAqB,EACrB,oCAAoC,EACpC,wBAAwB,EACxB,oBAAoB,EACpB,eAAe,EACf,uBAAuB,EACvB,8BAA8B,EAC9B,+BAA+B,EAC/B,wBAAwB,EACxB,yBAAyB,EACzB,sBAAsB,EACtB,YAAY,EACZ,8BAA8B,EAC9B,+BAA+B,EAC/B,gCAAgC,EACh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C;IAKhB;;;;;;OAMG;IACG,WAAW,CACf,OAAO,EAAE,kBAAkB,GAC1B,OAAO,CAAC,8BAA8B,CAAC;IAmDpC,UAAU,IAAI,OAAO,CAAC,eAAe,CAAC;IAKtC,mBAAmB,IAAI,OAAO,CAAC,qBAAqB,CAAC;CAI5D"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Env } from "./constants.mjs";
|
|
2
|
-
import type { AssignCohortRequest, AuthUtils, BillingPortalResponse, GetSubscriptionsEligibilitiesRequest, GetSubscriptionsResponse, ISubscriptionService, PricingResponse, SubscriptionEligibility, StartCryptoSubscriptionRequest, StartCryptoSubscriptionResponse, StartSubscriptionRequest, StartSubscriptionResponse, SubmitUserEventRequest, Subscription, UpdatePaymentMethodCardRequest, UpdatePaymentMethodCardResponse, UpdatePaymentMethodCryptoRequest, SubmitSponsorshipIntentsRequest, LinkRewardsRequest, SubscriptionApiGeneralResponse } from "./types.mjs";
|
|
2
|
+
import type { AssignCohortRequest, AuthUtils, BillingPortalResponse, GetSubscriptionsEligibilitiesRequest, GetSubscriptionsResponse, ISubscriptionService, PricingResponse, SubscriptionEligibility, StartCryptoSubscriptionRequest, StartCryptoSubscriptionResponse, StartSubscriptionRequest, StartSubscriptionResponse, SubmitUserEventRequest, Subscription, UpdatePaymentMethodCardRequest, UpdatePaymentMethodCardResponse, UpdatePaymentMethodCryptoRequest, SubmitSponsorshipIntentsRequest, LinkRewardsRequest, SubscriptionApiGeneralResponse, CancelSubscriptionRequest } from "./types.mjs";
|
|
3
3
|
export type SubscriptionServiceConfig = {
|
|
4
4
|
env: Env;
|
|
5
5
|
auth: AuthUtils;
|
|
@@ -10,9 +10,7 @@ export declare class SubscriptionService implements ISubscriptionService {
|
|
|
10
10
|
authUtils: AuthUtils;
|
|
11
11
|
constructor(config: SubscriptionServiceConfig);
|
|
12
12
|
getSubscriptions(): Promise<GetSubscriptionsResponse>;
|
|
13
|
-
cancelSubscription(params:
|
|
14
|
-
subscriptionId: string;
|
|
15
|
-
}): Promise<Subscription>;
|
|
13
|
+
cancelSubscription(params: CancelSubscriptionRequest): Promise<Subscription>;
|
|
16
14
|
unCancelSubscription(params: {
|
|
17
15
|
subscriptionId: string;
|
|
18
16
|
}): Promise<Subscription>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SubscriptionService.d.mts","sourceRoot":"","sources":["../src/SubscriptionService.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAoB;AAEvC,OAAO,KAAK,EACV,mBAAmB,EACnB,SAAS,EACT,qBAAqB,EACrB,oCAAoC,EACpC,wBAAwB,EACxB,oBAAoB,EACpB,eAAe,EACf,uBAAuB,EACvB,8BAA8B,EAC9B,+BAA+B,EAC/B,wBAAwB,EACxB,yBAAyB,EACzB,sBAAsB,EACtB,YAAY,EACZ,8BAA8B,EAC9B,+BAA+B,EAC/B,gCAAgC,EAChC,+BAA+B,EAC/B,kBAAkB,EAClB,8BAA8B,
|
|
1
|
+
{"version":3,"file":"SubscriptionService.d.mts","sourceRoot":"","sources":["../src/SubscriptionService.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAoB;AAEvC,OAAO,KAAK,EACV,mBAAmB,EACnB,SAAS,EACT,qBAAqB,EACrB,oCAAoC,EACpC,wBAAwB,EACxB,oBAAoB,EACpB,eAAe,EACf,uBAAuB,EACvB,8BAA8B,EAC9B,+BAA+B,EAC/B,wBAAwB,EACxB,yBAAyB,EACzB,sBAAsB,EACtB,YAAY,EACZ,8BAA8B,EAC9B,+BAA+B,EAC/B,gCAAgC,EAChC,+BAA+B,EAC/B,kBAAkB,EAClB,8BAA8B,EAC9B,yBAAyB,EAC1B,oBAAgB;AAEjB,MAAM,MAAM,yBAAyB,GAAG;IACtC,GAAG,EAAE,GAAG,CAAC;IACT,IAAI,EAAE,SAAS,CAAC;CACjB,CAAC;AAEF,eAAO,MAAM,gBAAgB,QAAS,GAAG,QAA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class SubscriptionService {
|
|
|
27
27
|
}
|
|
28
28
|
async cancelSubscription(params) {
|
|
29
29
|
const path = `subscriptions/${params.subscriptionId}/cancel`;
|
|
30
|
-
return await __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_makeRequest).call(this, path, 'POST', {
|
|
30
|
+
return await __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_makeRequest).call(this, path, 'POST', {
|
|
31
|
+
cancelAtPeriodEnd: params.cancelAtPeriodEnd,
|
|
32
|
+
});
|
|
31
33
|
}
|
|
32
34
|
async unCancelSubscription(params) {
|
|
33
35
|
const path = `subscriptions/${params.subscriptionId}/uncancel`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SubscriptionService.mjs","sourceRoot":"","sources":["../src/SubscriptionService.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,WAAW,EAAE,mCAAmC;AAEzD,OAAO,EAAE,UAAU,EAAE,kCAAkC,EAAE,wBAAoB;AAE7E,OAAO,EAAE,wBAAwB,EAAE,qBAAiB;AA6BpD,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,GAAQ,EAAE,IAAY,EAAU,EAAE,CACjE,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,kBAAkB,OAAO,IAAI,EAAE,CAAC;AAErD,MAAM,OAAO,mBAAmB;IAK9B,YAAY,MAAiC;;QAJpC,2CAAU;QAKjB,uBAAA,IAAI,4BAAQ,MAAM,CAAC,GAAG,MAAA,CAAC;QACvB,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC;IAC/B,CAAC;IAED,KAAK,CAAC,gBAAgB;QACpB,MAAM,IAAI,GAAG,eAAe,CAAC;QAC7B,OAAO,MAAM,uBAAA,IAAI,wEAAa,MAAjB,IAAI,EAAc,IAAI,CAAC,CAAC;IACvC,CAAC;IAED,KAAK,CAAC,kBAAkB,CAAC,MAExB;QACC,MAAM,IAAI,GAAG,iBAAiB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Y,CAAC,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;YACtC,CAAC,CAAC,CAAC;QACL,CAAC;QAED,MAAM,QAAQ,GAAG,MAAM,WAAW,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE;YACjD,MAAM;YACN,OAAO,EAAE;gBACP,cAAc,EAAE,kBAAkB;gBAClC,GAAG,OAAO;aACX;YACD,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS;SAC9C,CAAC,CAAC;QAEH,OAAO,QAAQ,CAAC;IAClB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,YAAY,GAChB,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QAEjE,MAAM,IAAI,wBAAwB,CAChC,2BAA2B,YAAY,EAAE,CAC1C,CAAC;IACJ,CAAC;AACH,CAAC;AAED,gEAAgE;AAChE,KAAK;IACH,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,cAAc,EAAE,CAAC;IAC1D,OAAO,EAAE,aAAa,EAAE,UAAU,WAAW,EAAE,EAAE,CAAC;AACpD,CAAC","sourcesContent":["import { handleFetch } from '@metamask/controller-utils';\n\nimport { getEnvUrls, SubscriptionControllerErrorMessage } from './constants';\nimport type { Env } from './constants';\nimport { SubscriptionServiceError } from './errors';\nimport type {\n AssignCohortRequest,\n AuthUtils,\n BillingPortalResponse,\n GetSubscriptionsEligibilitiesRequest,\n GetSubscriptionsResponse,\n ISubscriptionService,\n PricingResponse,\n SubscriptionEligibility,\n StartCryptoSubscriptionRequest,\n StartCryptoSubscriptionResponse,\n StartSubscriptionRequest,\n StartSubscriptionResponse,\n SubmitUserEventRequest,\n Subscription,\n UpdatePaymentMethodCardRequest,\n UpdatePaymentMethodCardResponse,\n UpdatePaymentMethodCryptoRequest,\n SubmitSponsorshipIntentsRequest,\n LinkRewardsRequest,\n SubscriptionApiGeneralResponse,\n} from './types';\n\nexport type SubscriptionServiceConfig = {\n env: Env;\n auth: AuthUtils;\n};\n\nexport const SUBSCRIPTION_URL = (env: Env, path: string): string =>\n `${getEnvUrls(env).subscriptionApiUrl}/v1/${path}`;\n\nexport class SubscriptionService implements ISubscriptionService {\n readonly #env: Env;\n\n public authUtils: AuthUtils;\n\n constructor(config: SubscriptionServiceConfig) {\n this.#env = config.env;\n this.authUtils = config.auth;\n }\n\n async getSubscriptions(): Promise<GetSubscriptionsResponse> {\n const path = 'subscriptions';\n return await this.#makeRequest(path);\n }\n\n async cancelSubscription(params: {\n subscriptionId: string;\n }): Promise<Subscription> {\n const path = `subscriptions/${params.subscriptionId}/cancel`;\n return await this.#makeRequest(path, 'POST', {});\n }\n\n async unCancelSubscription(params: {\n subscriptionId: string;\n }): Promise<Subscription> {\n const path = `subscriptions/${params.subscriptionId}/uncancel`;\n return await this.#makeRequest(path, 'POST', {});\n }\n\n async startSubscriptionWithCard(\n request: StartSubscriptionRequest,\n ): Promise<StartSubscriptionResponse> {\n if (request.products.length === 0) {\n throw new SubscriptionServiceError(\n SubscriptionControllerErrorMessage.SubscriptionProductsEmpty,\n );\n }\n const path = 'subscriptions/card';\n\n return await this.#makeRequest(path, 'POST', request);\n }\n\n async startSubscriptionWithCrypto(\n request: StartCryptoSubscriptionRequest,\n ): Promise<StartCryptoSubscriptionResponse> {\n const path = 'subscriptions/crypto';\n return await this.#makeRequest(path, 'POST', request);\n }\n\n async updatePaymentMethodCard(\n request: UpdatePaymentMethodCardRequest,\n ): Promise<UpdatePaymentMethodCardResponse> {\n const path = `subscriptions/${request.subscriptionId}/payment-method/card`;\n return await this.#makeRequest<UpdatePaymentMethodCardResponse>(\n path,\n 'PATCH',\n {\n ...request,\n subscriptionId: undefined,\n },\n );\n }\n\n async updatePaymentMethodCrypto(\n request: UpdatePaymentMethodCryptoRequest,\n ): Promise<void> {\n const path = `subscriptions/${request.subscriptionId}/payment-method/crypto`;\n await this.#makeRequest(path, 'PATCH', {\n ...request,\n subscriptionId: undefined,\n });\n }\n\n /**\n * Get the eligibility for a shield subscription.\n *\n * @param request - Optional request object containing user balance category to check cohort eligibility\n * @returns The eligibility for a shield subscription\n */\n async getSubscriptionsEligibilities(\n request?: GetSubscriptionsEligibilitiesRequest,\n ): Promise<SubscriptionEligibility[]> {\n const path = 'subscriptions/eligibility';\n let query: Record<string, string> | undefined;\n if (request?.balanceCategory !== undefined) {\n query = { balanceCategory: request.balanceCategory };\n }\n const results = await this.#makeRequest<SubscriptionEligibility[]>(\n path,\n 'GET',\n undefined,\n query,\n );\n\n return results.map((result) => ({\n ...result,\n canSubscribe: result.canSubscribe || false,\n canViewEntryModal: result.canViewEntryModal || false,\n cohorts: result.cohorts || [],\n assignedCohort: result.assignedCohort ?? null,\n hasAssignedCohortExpired: result.hasAssignedCohortExpired || false,\n }));\n }\n\n /**\n * Submit a user event. (e.g. shield modal viewed)\n *\n * @param request - Request object containing the event to submit.\n * @example { event: SubscriptionUserEvent.ShieldEntryModalViewed, cohort: 'post_tx' }\n */\n async submitUserEvent(request: SubmitUserEventRequest): Promise<void> {\n const path = 'user-events';\n await this.#makeRequest(path, 'POST', request);\n }\n\n /**\n * Assign user to a cohort.\n *\n * @param request - Request object containing the cohort to assign the user to.\n * @example { cohort: 'post_tx' }\n */\n async assignUserToCohort(request: AssignCohortRequest): Promise<void> {\n const path = 'cohorts/assign';\n await this.#makeRequest(path, 'POST', request);\n }\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 { address: '0x1234567890123456789012345678901234567890', products: [ProductType.Shield] }\n */\n async submitSponsorshipIntents(\n request: SubmitSponsorshipIntentsRequest,\n ): Promise<void> {\n const path = 'transaction-sponsorship/intents';\n await this.#makeRequest(path, 'POST', request);\n }\n\n /**\n * Link rewards to a subscription.\n *\n * @param request - Request object containing the reward account ID.\n * @example { rewardAccountId: 'eip155:1:0x1234567890123456789012345678901234567890' }\n * @returns The response from the API.\n */\n async linkRewards(\n request: LinkRewardsRequest,\n ): Promise<SubscriptionApiGeneralResponse> {\n const path = 'rewards/link';\n return await this.#makeRequest<SubscriptionApiGeneralResponse>(\n path,\n 'POST',\n request,\n );\n }\n\n async #makeRequest<Result>(\n path: string,\n method: 'GET' | 'POST' | 'DELETE' | 'PUT' | 'PATCH' = 'GET',\n body?: Record<string, unknown>,\n queryParams?: Record<string, string>,\n ): Promise<Result> {\n try {\n const headers = await this.#getAuthorizationHeader();\n const url = new URL(SUBSCRIPTION_URL(this.#env, path));\n\n if (queryParams) {\n Object.entries(queryParams).forEach(([key, value]) => {\n url.searchParams.append(key, value);\n });\n }\n\n const response = await handleFetch(url.toString(), {\n method,\n headers: {\n 'Content-Type': 'application/json',\n ...headers,\n },\n body: body ? JSON.stringify(body) : undefined,\n });\n\n return response;\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : JSON.stringify(error);\n\n throw new SubscriptionServiceError(\n `failed to make request. ${errorMessage}`,\n );\n }\n }\n\n // eslint-disable-next-line @typescript-eslint/naming-convention\n async #getAuthorizationHeader(): Promise<{ Authorization: string }> {\n const accessToken = await this.authUtils.getAccessToken();\n return { Authorization: `Bearer ${accessToken}` };\n }\n\n async getPricing(): Promise<PricingResponse> {\n const path = 'pricing';\n return await this.#makeRequest<PricingResponse>(path);\n }\n\n async getBillingPortalUrl(): Promise<BillingPortalResponse> {\n const path = 'billing-portal';\n return await this.#makeRequest<BillingPortalResponse>(path);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"SubscriptionService.mjs","sourceRoot":"","sources":["../src/SubscriptionService.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,WAAW,EAAE,mCAAmC;AAEzD,OAAO,EAAE,UAAU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C,CAAC;QAEjE,MAAM,IAAI,wBAAwB,CAChC,2BAA2B,YAAY,EAAE,CAC1C,CAAC;IACJ,CAAC;AACH,CAAC;AAED,gEAAgE;AAChE,KAAK;IACH,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,cAAc,EAAE,CAAC;IAC1D,OAAO,EAAE,aAAa,EAAE,UAAU,WAAW,EAAE,EAAE,CAAC;AACpD,CAAC","sourcesContent":["import { handleFetch } from '@metamask/controller-utils';\n\nimport { getEnvUrls, SubscriptionControllerErrorMessage } from './constants';\nimport type { Env } from './constants';\nimport { SubscriptionServiceError } from './errors';\nimport type {\n AssignCohortRequest,\n AuthUtils,\n BillingPortalResponse,\n GetSubscriptionsEligibilitiesRequest,\n GetSubscriptionsResponse,\n ISubscriptionService,\n PricingResponse,\n SubscriptionEligibility,\n StartCryptoSubscriptionRequest,\n StartCryptoSubscriptionResponse,\n StartSubscriptionRequest,\n StartSubscriptionResponse,\n SubmitUserEventRequest,\n Subscription,\n UpdatePaymentMethodCardRequest,\n UpdatePaymentMethodCardResponse,\n UpdatePaymentMethodCryptoRequest,\n SubmitSponsorshipIntentsRequest,\n LinkRewardsRequest,\n SubscriptionApiGeneralResponse,\n CancelSubscriptionRequest,\n} from './types';\n\nexport type SubscriptionServiceConfig = {\n env: Env;\n auth: AuthUtils;\n};\n\nexport const SUBSCRIPTION_URL = (env: Env, path: string): string =>\n `${getEnvUrls(env).subscriptionApiUrl}/v1/${path}`;\n\nexport class SubscriptionService implements ISubscriptionService {\n readonly #env: Env;\n\n public authUtils: AuthUtils;\n\n constructor(config: SubscriptionServiceConfig) {\n this.#env = config.env;\n this.authUtils = config.auth;\n }\n\n async getSubscriptions(): Promise<GetSubscriptionsResponse> {\n const path = 'subscriptions';\n return await this.#makeRequest(path);\n }\n\n async cancelSubscription(\n params: CancelSubscriptionRequest,\n ): Promise<Subscription> {\n const path = `subscriptions/${params.subscriptionId}/cancel`;\n return await this.#makeRequest(path, 'POST', {\n cancelAtPeriodEnd: params.cancelAtPeriodEnd,\n });\n }\n\n async unCancelSubscription(params: {\n subscriptionId: string;\n }): Promise<Subscription> {\n const path = `subscriptions/${params.subscriptionId}/uncancel`;\n return await this.#makeRequest(path, 'POST', {});\n }\n\n async startSubscriptionWithCard(\n request: StartSubscriptionRequest,\n ): Promise<StartSubscriptionResponse> {\n if (request.products.length === 0) {\n throw new SubscriptionServiceError(\n SubscriptionControllerErrorMessage.SubscriptionProductsEmpty,\n );\n }\n const path = 'subscriptions/card';\n\n return await this.#makeRequest(path, 'POST', request);\n }\n\n async startSubscriptionWithCrypto(\n request: StartCryptoSubscriptionRequest,\n ): Promise<StartCryptoSubscriptionResponse> {\n const path = 'subscriptions/crypto';\n return await this.#makeRequest(path, 'POST', request);\n }\n\n async updatePaymentMethodCard(\n request: UpdatePaymentMethodCardRequest,\n ): Promise<UpdatePaymentMethodCardResponse> {\n const path = `subscriptions/${request.subscriptionId}/payment-method/card`;\n return await this.#makeRequest<UpdatePaymentMethodCardResponse>(\n path,\n 'PATCH',\n {\n ...request,\n subscriptionId: undefined,\n },\n );\n }\n\n async updatePaymentMethodCrypto(\n request: UpdatePaymentMethodCryptoRequest,\n ): Promise<void> {\n const path = `subscriptions/${request.subscriptionId}/payment-method/crypto`;\n await this.#makeRequest(path, 'PATCH', {\n ...request,\n subscriptionId: undefined,\n });\n }\n\n /**\n * Get the eligibility for a shield subscription.\n *\n * @param request - Optional request object containing user balance category to check cohort eligibility\n * @returns The eligibility for a shield subscription\n */\n async getSubscriptionsEligibilities(\n request?: GetSubscriptionsEligibilitiesRequest,\n ): Promise<SubscriptionEligibility[]> {\n const path = 'subscriptions/eligibility';\n let query: Record<string, string> | undefined;\n if (request?.balanceCategory !== undefined) {\n query = { balanceCategory: request.balanceCategory };\n }\n const results = await this.#makeRequest<SubscriptionEligibility[]>(\n path,\n 'GET',\n undefined,\n query,\n );\n\n return results.map((result) => ({\n ...result,\n canSubscribe: result.canSubscribe || false,\n canViewEntryModal: result.canViewEntryModal || false,\n cohorts: result.cohorts || [],\n assignedCohort: result.assignedCohort ?? null,\n hasAssignedCohortExpired: result.hasAssignedCohortExpired || false,\n }));\n }\n\n /**\n * Submit a user event. (e.g. shield modal viewed)\n *\n * @param request - Request object containing the event to submit.\n * @example { event: SubscriptionUserEvent.ShieldEntryModalViewed, cohort: 'post_tx' }\n */\n async submitUserEvent(request: SubmitUserEventRequest): Promise<void> {\n const path = 'user-events';\n await this.#makeRequest(path, 'POST', request);\n }\n\n /**\n * Assign user to a cohort.\n *\n * @param request - Request object containing the cohort to assign the user to.\n * @example { cohort: 'post_tx' }\n */\n async assignUserToCohort(request: AssignCohortRequest): Promise<void> {\n const path = 'cohorts/assign';\n await this.#makeRequest(path, 'POST', request);\n }\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 { address: '0x1234567890123456789012345678901234567890', products: [ProductType.Shield] }\n */\n async submitSponsorshipIntents(\n request: SubmitSponsorshipIntentsRequest,\n ): Promise<void> {\n const path = 'transaction-sponsorship/intents';\n await this.#makeRequest(path, 'POST', request);\n }\n\n /**\n * Link rewards to a subscription.\n *\n * @param request - Request object containing the reward account ID.\n * @example { rewardAccountId: 'eip155:1:0x1234567890123456789012345678901234567890' }\n * @returns The response from the API.\n */\n async linkRewards(\n request: LinkRewardsRequest,\n ): Promise<SubscriptionApiGeneralResponse> {\n const path = 'rewards/link';\n return await this.#makeRequest<SubscriptionApiGeneralResponse>(\n path,\n 'POST',\n request,\n );\n }\n\n async #makeRequest<Result>(\n path: string,\n method: 'GET' | 'POST' | 'DELETE' | 'PUT' | 'PATCH' = 'GET',\n body?: Record<string, unknown>,\n queryParams?: Record<string, string>,\n ): Promise<Result> {\n try {\n const headers = await this.#getAuthorizationHeader();\n const url = new URL(SUBSCRIPTION_URL(this.#env, path));\n\n if (queryParams) {\n Object.entries(queryParams).forEach(([key, value]) => {\n url.searchParams.append(key, value);\n });\n }\n\n const response = await handleFetch(url.toString(), {\n method,\n headers: {\n 'Content-Type': 'application/json',\n ...headers,\n },\n body: body ? JSON.stringify(body) : undefined,\n });\n\n return response;\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : JSON.stringify(error);\n\n throw new SubscriptionServiceError(\n `failed to make request. ${errorMessage}`,\n );\n }\n }\n\n // eslint-disable-next-line @typescript-eslint/naming-convention\n async #getAuthorizationHeader(): Promise<{ Authorization: string }> {\n const accessToken = await this.authUtils.getAccessToken();\n return { Authorization: `Bearer ${accessToken}` };\n }\n\n async getPricing(): Promise<PricingResponse> {\n const path = 'pricing';\n return await this.#makeRequest<PricingResponse>(path);\n }\n\n async getBillingPortalUrl(): Promise<BillingPortalResponse> {\n const path = 'billing-portal';\n return await this.#makeRequest<BillingPortalResponse>(path);\n }\n}\n"]}
|
package/dist/index.cjs
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SubscriptionService = exports.SubscriptionControllerErrorMessage = exports.Env = exports.SubscriptionServiceError = exports.MODAL_TYPE = exports.BALANCE_CATEGORIES = exports.COHORT_NAMES = exports.SubscriptionUserEvent = exports.PAYMENT_TYPES = exports.RECURRING_INTERVALS = exports.PRODUCT_TYPES = exports.SUBSCRIPTION_STATUSES = exports.CRYPTO_PAYMENT_METHOD_ERRORS = exports.getDefaultSubscriptionControllerState = exports.SubscriptionController = void 0;
|
|
3
|
+
exports.SubscriptionService = exports.SubscriptionControllerErrorMessage = exports.Env = exports.SubscriptionServiceError = exports.MODAL_TYPE = exports.BALANCE_CATEGORIES = exports.COHORT_NAMES = exports.SubscriptionUserEvent = exports.PAYMENT_TYPES = exports.RECURRING_INTERVALS = exports.PRODUCT_TYPES = exports.SUBSCRIPTION_STATUSES = exports.CRYPTO_PAYMENT_METHOD_ERRORS = exports.CANCEL_TYPES = exports.getDefaultSubscriptionControllerState = exports.SubscriptionController = void 0;
|
|
4
4
|
var SubscriptionController_1 = require("./SubscriptionController.cjs");
|
|
5
5
|
Object.defineProperty(exports, "SubscriptionController", { enumerable: true, get: function () { return SubscriptionController_1.SubscriptionController; } });
|
|
6
6
|
Object.defineProperty(exports, "getDefaultSubscriptionControllerState", { enumerable: true, get: function () { return SubscriptionController_1.getDefaultSubscriptionControllerState; } });
|
|
7
7
|
var types_1 = require("./types.cjs");
|
|
8
|
+
Object.defineProperty(exports, "CANCEL_TYPES", { enumerable: true, get: function () { return types_1.CANCEL_TYPES; } });
|
|
8
9
|
Object.defineProperty(exports, "CRYPTO_PAYMENT_METHOD_ERRORS", { enumerable: true, get: function () { return types_1.CRYPTO_PAYMENT_METHOD_ERRORS; } });
|
|
9
10
|
Object.defineProperty(exports, "SUBSCRIPTION_STATUSES", { enumerable: true, get: function () { return types_1.SUBSCRIPTION_STATUSES; } });
|
|
10
11
|
Object.defineProperty(exports, "PRODUCT_TYPES", { enumerable: true, get: function () { return types_1.PRODUCT_TYPES; } });
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAuBA,uEAGkC;AAFhC,gIAAA,sBAAsB,OAAA;AACtB,+IAAA,qCAAqC,OAAA;
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAuBA,uEAGkC;AAFhC,gIAAA,sBAAsB,OAAA;AACtB,+IAAA,qCAAqC,OAAA;AAgDvC,qCAWiB;AAVf,qGAAA,YAAY,OAAA;AACZ,qHAAA,4BAA4B,OAAA;AAC5B,8GAAA,qBAAqB,OAAA;AACrB,sGAAA,aAAa,OAAA;AACb,4GAAA,mBAAmB,OAAA;AACnB,sGAAA,aAAa,OAAA;AACb,8GAAA,qBAAqB,OAAA;AACrB,qGAAA,YAAY,OAAA;AACZ,2GAAA,kBAAkB,OAAA;AAClB,mGAAA,UAAU,OAAA;AAEZ,uCAAoD;AAA3C,kHAAA,wBAAwB,OAAA;AACjC,6CAAsE;AAA7D,gGAAA,GAAG,OAAA;AAAE,+HAAA,kCAAkC,OAAA;AAEhD,iEAA4D;AAAnD,0HAAA,mBAAmB,OAAA","sourcesContent":["export type {\n SubscriptionControllerActions,\n SubscriptionControllerState,\n SubscriptionControllerEvents,\n SubscriptionControllerGetSubscriptionsAction,\n SubscriptionControllerGetSubscriptionByProductAction,\n SubscriptionControllerCancelSubscriptionAction,\n SubscriptionControllerStartShieldSubscriptionWithCardAction,\n SubscriptionControllerGetPricingAction,\n SubscriptionControllerGetCryptoApproveTransactionParamsAction,\n SubscriptionControllerStartSubscriptionWithCryptoAction,\n SubscriptionControllerGetBillingPortalUrlAction,\n SubscriptionControllerUpdatePaymentMethodAction,\n SubscriptionControllerGetStateAction,\n SubscriptionControllerMessenger,\n SubscriptionControllerOptions,\n SubscriptionControllerStateChangeEvent,\n SubscriptionControllerSubmitSponsorshipIntentsAction,\n SubscriptionControllerLinkRewardsAction,\n SubscriptionControllerSubmitShieldSubscriptionCryptoApprovalAction,\n AllowedActions,\n AllowedEvents,\n} from './SubscriptionController';\nexport {\n SubscriptionController,\n getDefaultSubscriptionControllerState,\n} from './SubscriptionController';\nexport type {\n Subscription,\n AuthUtils,\n CancelSubscriptionRequest,\n CancelType,\n ISubscriptionService,\n StartCryptoSubscriptionRequest,\n StartCryptoSubscriptionResponse,\n StartSubscriptionRequest,\n StartSubscriptionResponse,\n GetCryptoApproveTransactionRequest,\n GetCryptoApproveTransactionResponse,\n SubscriptionCardPaymentMethod,\n SubscriptionCryptoPaymentMethod,\n SubscriptionPaymentMethod,\n SubmitUserEventRequest,\n SubmitSponsorshipIntentsRequest,\n SubscriptionEligibility,\n SubscriptionUserEventType,\n RecurringInterval,\n SubscriptionStatus,\n PaymentType,\n Product,\n ProductType,\n ProductPrice,\n ProductPricing,\n TokenPaymentInfo,\n ChainPaymentInfo,\n Currency,\n PricingPaymentMethod,\n PricingResponse,\n UpdatePaymentMethodOpts,\n BillingPortalResponse,\n CryptoPaymentMethodError,\n UpdatePaymentMethodCryptoRequest,\n UpdatePaymentMethodCardRequest,\n UpdatePaymentMethodCardResponse,\n CachedLastSelectedPaymentMethod,\n SubmitSponsorshipIntentsMethodParams,\n Cohort,\n CohortName,\n BalanceCategory,\n AssignCohortRequest,\n GetSubscriptionsEligibilitiesRequest,\n ModalType,\n} from './types';\nexport {\n CANCEL_TYPES,\n CRYPTO_PAYMENT_METHOD_ERRORS,\n SUBSCRIPTION_STATUSES,\n PRODUCT_TYPES,\n RECURRING_INTERVALS,\n PAYMENT_TYPES,\n SubscriptionUserEvent,\n COHORT_NAMES,\n BALANCE_CATEGORIES,\n MODAL_TYPE,\n} from './types';\nexport { SubscriptionServiceError } from './errors';\nexport { Env, SubscriptionControllerErrorMessage } from './constants';\nexport type { SubscriptionServiceConfig } from './SubscriptionService';\nexport { SubscriptionService } from './SubscriptionService';\n"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export type { SubscriptionControllerActions, SubscriptionControllerState, SubscriptionControllerEvents, SubscriptionControllerGetSubscriptionsAction, SubscriptionControllerGetSubscriptionByProductAction, SubscriptionControllerCancelSubscriptionAction, SubscriptionControllerStartShieldSubscriptionWithCardAction, SubscriptionControllerGetPricingAction, SubscriptionControllerGetCryptoApproveTransactionParamsAction, SubscriptionControllerStartSubscriptionWithCryptoAction, SubscriptionControllerGetBillingPortalUrlAction, SubscriptionControllerUpdatePaymentMethodAction, SubscriptionControllerGetStateAction, SubscriptionControllerMessenger, SubscriptionControllerOptions, SubscriptionControllerStateChangeEvent, SubscriptionControllerSubmitSponsorshipIntentsAction, SubscriptionControllerLinkRewardsAction, SubscriptionControllerSubmitShieldSubscriptionCryptoApprovalAction, AllowedActions, AllowedEvents, } from "./SubscriptionController.cjs";
|
|
2
2
|
export { SubscriptionController, getDefaultSubscriptionControllerState, } from "./SubscriptionController.cjs";
|
|
3
|
-
export type { Subscription, AuthUtils, ISubscriptionService, StartCryptoSubscriptionRequest, StartCryptoSubscriptionResponse, StartSubscriptionRequest, StartSubscriptionResponse, GetCryptoApproveTransactionRequest, GetCryptoApproveTransactionResponse, SubscriptionCardPaymentMethod, SubscriptionCryptoPaymentMethod, SubscriptionPaymentMethod, SubmitUserEventRequest, SubmitSponsorshipIntentsRequest, SubscriptionEligibility, SubscriptionUserEventType, RecurringInterval, SubscriptionStatus, PaymentType, Product, ProductType, ProductPrice, ProductPricing, TokenPaymentInfo, ChainPaymentInfo, Currency, PricingPaymentMethod, PricingResponse, UpdatePaymentMethodOpts, BillingPortalResponse, CryptoPaymentMethodError, UpdatePaymentMethodCryptoRequest, UpdatePaymentMethodCardRequest, UpdatePaymentMethodCardResponse, CachedLastSelectedPaymentMethod, SubmitSponsorshipIntentsMethodParams, Cohort, CohortName, BalanceCategory, AssignCohortRequest, GetSubscriptionsEligibilitiesRequest, ModalType, } from "./types.cjs";
|
|
4
|
-
export { CRYPTO_PAYMENT_METHOD_ERRORS, SUBSCRIPTION_STATUSES, PRODUCT_TYPES, RECURRING_INTERVALS, PAYMENT_TYPES, SubscriptionUserEvent, COHORT_NAMES, BALANCE_CATEGORIES, MODAL_TYPE, } from "./types.cjs";
|
|
3
|
+
export type { Subscription, AuthUtils, CancelSubscriptionRequest, CancelType, ISubscriptionService, StartCryptoSubscriptionRequest, StartCryptoSubscriptionResponse, StartSubscriptionRequest, StartSubscriptionResponse, GetCryptoApproveTransactionRequest, GetCryptoApproveTransactionResponse, SubscriptionCardPaymentMethod, SubscriptionCryptoPaymentMethod, SubscriptionPaymentMethod, SubmitUserEventRequest, SubmitSponsorshipIntentsRequest, SubscriptionEligibility, SubscriptionUserEventType, RecurringInterval, SubscriptionStatus, PaymentType, Product, ProductType, ProductPrice, ProductPricing, TokenPaymentInfo, ChainPaymentInfo, Currency, PricingPaymentMethod, PricingResponse, UpdatePaymentMethodOpts, BillingPortalResponse, CryptoPaymentMethodError, UpdatePaymentMethodCryptoRequest, UpdatePaymentMethodCardRequest, UpdatePaymentMethodCardResponse, CachedLastSelectedPaymentMethod, SubmitSponsorshipIntentsMethodParams, Cohort, CohortName, BalanceCategory, AssignCohortRequest, GetSubscriptionsEligibilitiesRequest, ModalType, } from "./types.cjs";
|
|
4
|
+
export { CANCEL_TYPES, CRYPTO_PAYMENT_METHOD_ERRORS, SUBSCRIPTION_STATUSES, PRODUCT_TYPES, RECURRING_INTERVALS, PAYMENT_TYPES, SubscriptionUserEvent, COHORT_NAMES, BALANCE_CATEGORIES, MODAL_TYPE, } from "./types.cjs";
|
|
5
5
|
export { SubscriptionServiceError } from "./errors.cjs";
|
|
6
6
|
export { Env, SubscriptionControllerErrorMessage } from "./constants.cjs";
|
|
7
7
|
export type { SubscriptionServiceConfig } from "./SubscriptionService.cjs";
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,6BAA6B,EAC7B,2BAA2B,EAC3B,4BAA4B,EAC5B,4CAA4C,EAC5C,oDAAoD,EACpD,8CAA8C,EAC9C,2DAA2D,EAC3D,sCAAsC,EACtC,6DAA6D,EAC7D,uDAAuD,EACvD,+CAA+C,EAC/C,+CAA+C,EAC/C,oCAAoC,EACpC,+BAA+B,EAC/B,6BAA6B,EAC7B,sCAAsC,EACtC,oDAAoD,EACpD,uCAAuC,EACvC,kEAAkE,EAClE,cAAc,EACd,aAAa,GACd,qCAAiC;AAClC,OAAO,EACL,sBAAsB,EACtB,qCAAqC,GACtC,qCAAiC;AAClC,YAAY,EACV,YAAY,EACZ,SAAS,EACT,oBAAoB,EACpB,8BAA8B,EAC9B,+BAA+B,EAC/B,wBAAwB,EACxB,yBAAyB,EACzB,kCAAkC,EAClC,mCAAmC,EACnC,6BAA6B,EAC7B,+BAA+B,EAC/B,yBAAyB,EACzB,sBAAsB,EACtB,+BAA+B,EAC/B,uBAAuB,EACvB,yBAAyB,EACzB,iBAAiB,EACjB,kBAAkB,EAClB,WAAW,EACX,OAAO,EACP,WAAW,EACX,YAAY,EACZ,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAChB,QAAQ,EACR,oBAAoB,EACpB,eAAe,EACf,uBAAuB,EACvB,qBAAqB,EACrB,wBAAwB,EACxB,gCAAgC,EAChC,8BAA8B,EAC9B,+BAA+B,EAC/B,+BAA+B,EAC/B,oCAAoC,EACpC,MAAM,EACN,UAAU,EACV,eAAe,EACf,mBAAmB,EACnB,oCAAoC,EACpC,SAAS,GACV,oBAAgB;AACjB,OAAO,EACL,4BAA4B,EAC5B,qBAAqB,EACrB,aAAa,EACb,mBAAmB,EACnB,aAAa,EACb,qBAAqB,EACrB,YAAY,EACZ,kBAAkB,EAClB,UAAU,GACX,oBAAgB;AACjB,OAAO,EAAE,wBAAwB,EAAE,qBAAiB;AACpD,OAAO,EAAE,GAAG,EAAE,kCAAkC,EAAE,wBAAoB;AACtE,YAAY,EAAE,yBAAyB,EAAE,kCAA8B;AACvE,OAAO,EAAE,mBAAmB,EAAE,kCAA8B"}
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,6BAA6B,EAC7B,2BAA2B,EAC3B,4BAA4B,EAC5B,4CAA4C,EAC5C,oDAAoD,EACpD,8CAA8C,EAC9C,2DAA2D,EAC3D,sCAAsC,EACtC,6DAA6D,EAC7D,uDAAuD,EACvD,+CAA+C,EAC/C,+CAA+C,EAC/C,oCAAoC,EACpC,+BAA+B,EAC/B,6BAA6B,EAC7B,sCAAsC,EACtC,oDAAoD,EACpD,uCAAuC,EACvC,kEAAkE,EAClE,cAAc,EACd,aAAa,GACd,qCAAiC;AAClC,OAAO,EACL,sBAAsB,EACtB,qCAAqC,GACtC,qCAAiC;AAClC,YAAY,EACV,YAAY,EACZ,SAAS,EACT,yBAAyB,EACzB,UAAU,EACV,oBAAoB,EACpB,8BAA8B,EAC9B,+BAA+B,EAC/B,wBAAwB,EACxB,yBAAyB,EACzB,kCAAkC,EAClC,mCAAmC,EACnC,6BAA6B,EAC7B,+BAA+B,EAC/B,yBAAyB,EACzB,sBAAsB,EACtB,+BAA+B,EAC/B,uBAAuB,EACvB,yBAAyB,EACzB,iBAAiB,EACjB,kBAAkB,EAClB,WAAW,EACX,OAAO,EACP,WAAW,EACX,YAAY,EACZ,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAChB,QAAQ,EACR,oBAAoB,EACpB,eAAe,EACf,uBAAuB,EACvB,qBAAqB,EACrB,wBAAwB,EACxB,gCAAgC,EAChC,8BAA8B,EAC9B,+BAA+B,EAC/B,+BAA+B,EAC/B,oCAAoC,EACpC,MAAM,EACN,UAAU,EACV,eAAe,EACf,mBAAmB,EACnB,oCAAoC,EACpC,SAAS,GACV,oBAAgB;AACjB,OAAO,EACL,YAAY,EACZ,4BAA4B,EAC5B,qBAAqB,EACrB,aAAa,EACb,mBAAmB,EACnB,aAAa,EACb,qBAAqB,EACrB,YAAY,EACZ,kBAAkB,EAClB,UAAU,GACX,oBAAgB;AACjB,OAAO,EAAE,wBAAwB,EAAE,qBAAiB;AACpD,OAAO,EAAE,GAAG,EAAE,kCAAkC,EAAE,wBAAoB;AACtE,YAAY,EAAE,yBAAyB,EAAE,kCAA8B;AACvE,OAAO,EAAE,mBAAmB,EAAE,kCAA8B"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export type { SubscriptionControllerActions, SubscriptionControllerState, SubscriptionControllerEvents, SubscriptionControllerGetSubscriptionsAction, SubscriptionControllerGetSubscriptionByProductAction, SubscriptionControllerCancelSubscriptionAction, SubscriptionControllerStartShieldSubscriptionWithCardAction, SubscriptionControllerGetPricingAction, SubscriptionControllerGetCryptoApproveTransactionParamsAction, SubscriptionControllerStartSubscriptionWithCryptoAction, SubscriptionControllerGetBillingPortalUrlAction, SubscriptionControllerUpdatePaymentMethodAction, SubscriptionControllerGetStateAction, SubscriptionControllerMessenger, SubscriptionControllerOptions, SubscriptionControllerStateChangeEvent, SubscriptionControllerSubmitSponsorshipIntentsAction, SubscriptionControllerLinkRewardsAction, SubscriptionControllerSubmitShieldSubscriptionCryptoApprovalAction, AllowedActions, AllowedEvents, } from "./SubscriptionController.mjs";
|
|
2
2
|
export { SubscriptionController, getDefaultSubscriptionControllerState, } from "./SubscriptionController.mjs";
|
|
3
|
-
export type { Subscription, AuthUtils, ISubscriptionService, StartCryptoSubscriptionRequest, StartCryptoSubscriptionResponse, StartSubscriptionRequest, StartSubscriptionResponse, GetCryptoApproveTransactionRequest, GetCryptoApproveTransactionResponse, SubscriptionCardPaymentMethod, SubscriptionCryptoPaymentMethod, SubscriptionPaymentMethod, SubmitUserEventRequest, SubmitSponsorshipIntentsRequest, SubscriptionEligibility, SubscriptionUserEventType, RecurringInterval, SubscriptionStatus, PaymentType, Product, ProductType, ProductPrice, ProductPricing, TokenPaymentInfo, ChainPaymentInfo, Currency, PricingPaymentMethod, PricingResponse, UpdatePaymentMethodOpts, BillingPortalResponse, CryptoPaymentMethodError, UpdatePaymentMethodCryptoRequest, UpdatePaymentMethodCardRequest, UpdatePaymentMethodCardResponse, CachedLastSelectedPaymentMethod, SubmitSponsorshipIntentsMethodParams, Cohort, CohortName, BalanceCategory, AssignCohortRequest, GetSubscriptionsEligibilitiesRequest, ModalType, } from "./types.mjs";
|
|
4
|
-
export { CRYPTO_PAYMENT_METHOD_ERRORS, SUBSCRIPTION_STATUSES, PRODUCT_TYPES, RECURRING_INTERVALS, PAYMENT_TYPES, SubscriptionUserEvent, COHORT_NAMES, BALANCE_CATEGORIES, MODAL_TYPE, } from "./types.mjs";
|
|
3
|
+
export type { Subscription, AuthUtils, CancelSubscriptionRequest, CancelType, ISubscriptionService, StartCryptoSubscriptionRequest, StartCryptoSubscriptionResponse, StartSubscriptionRequest, StartSubscriptionResponse, GetCryptoApproveTransactionRequest, GetCryptoApproveTransactionResponse, SubscriptionCardPaymentMethod, SubscriptionCryptoPaymentMethod, SubscriptionPaymentMethod, SubmitUserEventRequest, SubmitSponsorshipIntentsRequest, SubscriptionEligibility, SubscriptionUserEventType, RecurringInterval, SubscriptionStatus, PaymentType, Product, ProductType, ProductPrice, ProductPricing, TokenPaymentInfo, ChainPaymentInfo, Currency, PricingPaymentMethod, PricingResponse, UpdatePaymentMethodOpts, BillingPortalResponse, CryptoPaymentMethodError, UpdatePaymentMethodCryptoRequest, UpdatePaymentMethodCardRequest, UpdatePaymentMethodCardResponse, CachedLastSelectedPaymentMethod, SubmitSponsorshipIntentsMethodParams, Cohort, CohortName, BalanceCategory, AssignCohortRequest, GetSubscriptionsEligibilitiesRequest, ModalType, } from "./types.mjs";
|
|
4
|
+
export { CANCEL_TYPES, CRYPTO_PAYMENT_METHOD_ERRORS, SUBSCRIPTION_STATUSES, PRODUCT_TYPES, RECURRING_INTERVALS, PAYMENT_TYPES, SubscriptionUserEvent, COHORT_NAMES, BALANCE_CATEGORIES, MODAL_TYPE, } from "./types.mjs";
|
|
5
5
|
export { SubscriptionServiceError } from "./errors.mjs";
|
|
6
6
|
export { Env, SubscriptionControllerErrorMessage } from "./constants.mjs";
|
|
7
7
|
export type { SubscriptionServiceConfig } from "./SubscriptionService.mjs";
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,6BAA6B,EAC7B,2BAA2B,EAC3B,4BAA4B,EAC5B,4CAA4C,EAC5C,oDAAoD,EACpD,8CAA8C,EAC9C,2DAA2D,EAC3D,sCAAsC,EACtC,6DAA6D,EAC7D,uDAAuD,EACvD,+CAA+C,EAC/C,+CAA+C,EAC/C,oCAAoC,EACpC,+BAA+B,EAC/B,6BAA6B,EAC7B,sCAAsC,EACtC,oDAAoD,EACpD,uCAAuC,EACvC,kEAAkE,EAClE,cAAc,EACd,aAAa,GACd,qCAAiC;AAClC,OAAO,EACL,sBAAsB,EACtB,qCAAqC,GACtC,qCAAiC;AAClC,YAAY,EACV,YAAY,EACZ,SAAS,EACT,oBAAoB,EACpB,8BAA8B,EAC9B,+BAA+B,EAC/B,wBAAwB,EACxB,yBAAyB,EACzB,kCAAkC,EAClC,mCAAmC,EACnC,6BAA6B,EAC7B,+BAA+B,EAC/B,yBAAyB,EACzB,sBAAsB,EACtB,+BAA+B,EAC/B,uBAAuB,EACvB,yBAAyB,EACzB,iBAAiB,EACjB,kBAAkB,EAClB,WAAW,EACX,OAAO,EACP,WAAW,EACX,YAAY,EACZ,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAChB,QAAQ,EACR,oBAAoB,EACpB,eAAe,EACf,uBAAuB,EACvB,qBAAqB,EACrB,wBAAwB,EACxB,gCAAgC,EAChC,8BAA8B,EAC9B,+BAA+B,EAC/B,+BAA+B,EAC/B,oCAAoC,EACpC,MAAM,EACN,UAAU,EACV,eAAe,EACf,mBAAmB,EACnB,oCAAoC,EACpC,SAAS,GACV,oBAAgB;AACjB,OAAO,EACL,4BAA4B,EAC5B,qBAAqB,EACrB,aAAa,EACb,mBAAmB,EACnB,aAAa,EACb,qBAAqB,EACrB,YAAY,EACZ,kBAAkB,EAClB,UAAU,GACX,oBAAgB;AACjB,OAAO,EAAE,wBAAwB,EAAE,qBAAiB;AACpD,OAAO,EAAE,GAAG,EAAE,kCAAkC,EAAE,wBAAoB;AACtE,YAAY,EAAE,yBAAyB,EAAE,kCAA8B;AACvE,OAAO,EAAE,mBAAmB,EAAE,kCAA8B"}
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,6BAA6B,EAC7B,2BAA2B,EAC3B,4BAA4B,EAC5B,4CAA4C,EAC5C,oDAAo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E,mBAAmB,EAAE,kCAA8B"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { SubscriptionController, getDefaultSubscriptionControllerState } from "./SubscriptionController.mjs";
|
|
2
|
-
export { CRYPTO_PAYMENT_METHOD_ERRORS, SUBSCRIPTION_STATUSES, PRODUCT_TYPES, RECURRING_INTERVALS, PAYMENT_TYPES, SubscriptionUserEvent, COHORT_NAMES, BALANCE_CATEGORIES, MODAL_TYPE } from "./types.mjs";
|
|
2
|
+
export { CANCEL_TYPES, CRYPTO_PAYMENT_METHOD_ERRORS, SUBSCRIPTION_STATUSES, PRODUCT_TYPES, RECURRING_INTERVALS, PAYMENT_TYPES, SubscriptionUserEvent, COHORT_NAMES, BALANCE_CATEGORIES, MODAL_TYPE } from "./types.mjs";
|
|
3
3
|
export { SubscriptionServiceError } from "./errors.mjs";
|
|
4
4
|
export { Env, SubscriptionControllerErrorMessage } from "./constants.mjs";
|
|
5
5
|
export { SubscriptionService } from "./SubscriptionService.mjs";
|