@metamask-previews/subscription-controller 5.0.0-preview-66e0169 → 5.1.0-preview-8d461ad5

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 CHANGED
@@ -7,8 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [5.1.0]
11
+
10
12
  ### Changed
11
13
 
14
+ - Removed `minBalanceUSD` field from the `SubscriptionEligibility` type. ([#7248](https://github.com/MetaMask/core/pull/7248))
15
+ - Updated `submitShieldSubscriptionCryptoApproval` to handle change payment method transaction if subscription already existed ([#7231](https://github.com/MetaMask/core/pull/7231))
12
16
  - Bump `@metamask/transaction-controller` from `^62.0.0` to `^62.3.0` ([#7215](https://github.com/MetaMask/core/pull/7215), [#7220](https://github.com/MetaMask/core/pull/7220), [#7236](https://github.com/MetaMask/core/pull/7236))
13
17
  - Move peer dependencies for controller and service packages to direct dependencies ([#7209](https://github.com/MetaMask/core/pull/7209))
14
18
  - The dependencies moved are:
@@ -213,7 +217,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
213
217
  - Bump `@metamask/controller-utils` from `^11.12.0` to `^11.14.0` ([#6620](https://github.com/MetaMask/core/pull/6620), [#6629](https://github.com/MetaMask/core/pull/6629))
214
218
  - Bump `@metamask/utils` from `^11.4.2` to `^11.8.0` ([#6588](https://github.com/MetaMask/core/pull/6588))
215
219
 
216
- [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/subscription-controller@5.0.0...HEAD
220
+ [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/subscription-controller@5.1.0...HEAD
221
+ [5.1.0]: https://github.com/MetaMask/core/compare/@metamask/subscription-controller@5.0.0...@metamask/subscription-controller@5.1.0
217
222
  [5.0.0]: https://github.com/MetaMask/core/compare/@metamask/subscription-controller@4.2.2...@metamask/subscription-controller@5.0.0
218
223
  [4.2.2]: https://github.com/MetaMask/core/compare/@metamask/subscription-controller@4.2.1...@metamask/subscription-controller@4.2.2
219
224
  [4.2.1]: https://github.com/MetaMask/core/compare/@metamask/subscription-controller@4.2.0...@metamask/subscription-controller@4.2.1
@@ -10,7 +10,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
10
10
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
11
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
12
  };
13
- var _SubscriptionController_instances, _SubscriptionController_subscriptionService, _SubscriptionController_registerMessageHandlers, _SubscriptionController_getSubscriptionPriceAmount, _SubscriptionController_getProductPriceByProductAndPlan, _SubscriptionController_assertIsUserNotSubscribed, _SubscriptionController_assertIsUserSubscribed, _SubscriptionController_assertIsPaymentMethodCrypto, _SubscriptionController_getIsEligibleForTrialedSponsorship, _SubscriptionController_getChainSupportsSponsorship, _SubscriptionController_areTrialedProductsEqual, _SubscriptionController_areSubscriptionsEqual, _SubscriptionController_isSubscriptionEqual, _SubscriptionController_stringifySubscription;
13
+ var _SubscriptionController_instances, _SubscriptionController_subscriptionService, _SubscriptionController_registerMessageHandlers, _SubscriptionController_getSubscriptionPriceAmount, _SubscriptionController_getProductPriceByProductAndPlan, _SubscriptionController_assertValidSubscriptionStateForCryptoApproval, _SubscriptionController_assertIsUserNotSubscribed, _SubscriptionController_assertIsUserSubscribed, _SubscriptionController_assertIsPaymentMethodCrypto, _SubscriptionController_getIsEligibleForTrialedSponsorship, _SubscriptionController_getChainSupportsSponsorship, _SubscriptionController_areTrialedProductsEqual, _SubscriptionController_areSubscriptionsEqual, _SubscriptionController_isSubscriptionEqual, _SubscriptionController_stringifySubscription;
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.SubscriptionController = exports.getDefaultSubscriptionControllerState = void 0;
16
16
  const polling_controller_1 = require("@metamask/polling-controller");
@@ -220,21 +220,43 @@ class SubscriptionController extends (0, polling_controller_1.StaticIntervalPoll
220
220
  }
221
221
  const lastSelectedPaymentMethodShield = lastSelectedPaymentMethod[types_1.PRODUCT_TYPES.SHIELD];
222
222
  __classPrivateFieldGet(this, _SubscriptionController_instances, "m", _SubscriptionController_assertIsPaymentMethodCrypto).call(this, lastSelectedPaymentMethodShield);
223
- const isTrialed = trialedProducts?.includes(types_1.PRODUCT_TYPES.SHIELD);
224
223
  const productPrice = __classPrivateFieldGet(this, _SubscriptionController_instances, "m", _SubscriptionController_getProductPriceByProductAndPlan).call(this, types_1.PRODUCT_TYPES.SHIELD, lastSelectedPaymentMethodShield.plan);
225
- const params = {
226
- products: [types_1.PRODUCT_TYPES.SHIELD],
227
- isTrialRequested: !isTrialed,
228
- recurringInterval: productPrice.interval,
229
- billingCycles: productPrice.minBillingCycles,
230
- chainId,
231
- payerAddress: txMeta.txParams.from,
232
- tokenSymbol: lastSelectedPaymentMethodShield.paymentTokenSymbol,
233
- rawTransaction: rawTx,
234
- isSponsored,
235
- useTestClock: lastSelectedPaymentMethodShield.useTestClock,
236
- };
237
- await this.startSubscriptionWithCrypto(params);
224
+ const isTrialed = trialedProducts?.includes(types_1.PRODUCT_TYPES.SHIELD);
225
+ // get the latest subscriptions state to check if the user has an active shield subscription
226
+ await this.getSubscriptions();
227
+ const currentSubscription = this.state.subscriptions.find((subscription) => subscription.products.some((p) => p.name === types_1.PRODUCT_TYPES.SHIELD));
228
+ __classPrivateFieldGet(this, _SubscriptionController_instances, "m", _SubscriptionController_assertValidSubscriptionStateForCryptoApproval).call(this, {
229
+ product: types_1.PRODUCT_TYPES.SHIELD,
230
+ });
231
+ // if shield subscription exists, this transaction is for changing payment method
232
+ const isChangePaymentMethod = Boolean(currentSubscription);
233
+ if (isChangePaymentMethod) {
234
+ await this.updatePaymentMethod({
235
+ paymentType: types_1.PAYMENT_TYPES.byCrypto,
236
+ subscriptionId: currentSubscription.id,
237
+ chainId,
238
+ payerAddress: txMeta.txParams.from,
239
+ tokenSymbol: lastSelectedPaymentMethodShield.paymentTokenSymbol,
240
+ rawTransaction: rawTx,
241
+ recurringInterval: productPrice.interval,
242
+ billingCycles: productPrice.minBillingCycles,
243
+ });
244
+ }
245
+ else {
246
+ const params = {
247
+ products: [types_1.PRODUCT_TYPES.SHIELD],
248
+ isTrialRequested: !isTrialed,
249
+ recurringInterval: productPrice.interval,
250
+ billingCycles: productPrice.minBillingCycles,
251
+ chainId,
252
+ payerAddress: txMeta.txParams.from,
253
+ tokenSymbol: lastSelectedPaymentMethodShield.paymentTokenSymbol,
254
+ rawTransaction: rawTx,
255
+ isSponsored,
256
+ useTestClock: lastSelectedPaymentMethodShield.useTestClock,
257
+ };
258
+ await this.startSubscriptionWithCrypto(params);
259
+ }
238
260
  // update the subscriptions state after subscription created in server
239
261
  await this.getSubscriptions();
240
262
  }
@@ -441,6 +463,20 @@ _SubscriptionController_subscriptionService = new WeakMap(), _SubscriptionContro
441
463
  throw new Error(constants_1.SubscriptionControllerErrorMessage.ProductPriceNotFound);
442
464
  }
443
465
  return productPrice;
466
+ }, _SubscriptionController_assertValidSubscriptionStateForCryptoApproval = function _SubscriptionController_assertValidSubscriptionStateForCryptoApproval({ product, }) {
467
+ const subscription = this.state.subscriptions.find((sub) => sub.products.some((p) => p.name === product));
468
+ const isValid = !subscription ||
469
+ [
470
+ types_1.SUBSCRIPTION_STATUSES.pastDue,
471
+ types_1.SUBSCRIPTION_STATUSES.unpaid,
472
+ types_1.SUBSCRIPTION_STATUSES.paused,
473
+ types_1.SUBSCRIPTION_STATUSES.provisional,
474
+ types_1.SUBSCRIPTION_STATUSES.active,
475
+ types_1.SUBSCRIPTION_STATUSES.trialing,
476
+ ].includes(subscription.status);
477
+ if (!isValid) {
478
+ throw new Error(constants_1.SubscriptionControllerErrorMessage.SubscriptionNotValidForCryptoApproval);
479
+ }
444
480
  }, _SubscriptionController_assertIsUserNotSubscribed = function _SubscriptionController_assertIsUserNotSubscribed({ products }) {
445
481
  const subscription = this.state.subscriptions.find((sub) => sub.products.some((p) => products.includes(p.name)));
446
482
  if (subscription &&
@@ -1 +1 @@
1
- {"version":3,"file":"SubscriptionController.cjs","sourceRoot":"","sources":["../src/SubscriptionController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAMA,qEAA+E;AAG/E,6EAAmE;AAEnE,+CAAyC;AAEzC,+CAKqB;AAkBrB,uCAQiB;AAqIjB;;;;GAIG;AACH,SAAgB,qCAAqC;IACnD,OAAO;QACL,aAAa,EAAE,EAAE;QACjB,eAAe,EAAE,EAAE;KACpB,CAAC;AACJ,CAAC;AALD,sFAKC;AAED;;;;;;GAMG;AACH,MAAM,8BAA8B,GAClC;IACE,aAAa,EAAE;QACb,kBAAkB,EAAE,KAAK;QACzB,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,KAAK;QAC7B,QAAQ,EAAE,IAAI;KACf;IACD,gBAAgB,EAAE;QAChB,kBAAkB,EAAE,KAAK;QACzB,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,KAAK;QAC7B,QAAQ,EAAE,IAAI;KACf;IACD,UAAU,EAAE;QACV,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,KAAK;QAC7B,QAAQ,EAAE,IAAI;KACf;IACD,eAAe,EAAE;QACf,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,IAAI;QAC5B,QAAQ,EAAE,IAAI;KACf;IACD,OAAO,EAAE;QACP,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,IAAI;QAC5B,QAAQ,EAAE,IAAI;KACf;IACD,yBAAyB,EAAE;QACzB,kBAAkB,EAAE,KAAK;QACzB,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,KAAK;QAC7B,QAAQ,EAAE,IAAI;KACf;CACF,CAAC;AAEJ,MAAa,sBAAuB,SAAQ,IAAA,oDAA+B,GAI1E;IAGC;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AE,CAAC;YACvB,OAAO,IAAI,CAAC;QACd,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,CACL,uBAAA,IAAI,wFAAuB,MAA3B,IAAI,EAAwB,MAAM,CAAC;QACnC,uBAAA,IAAI,wFAAuB,MAA3B,IAAI,EAAwB,MAAM,CAAC,CACpC,CAAC;AACJ,CAAC,yGAEsB,YAA0B;IAC/C,MAAM,sBAAsB,GAAG;QAC7B,GAAG,YAAY;QACf,6BAA6B;QAC7B,QAAQ,EAAE,CAAC,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CACjD,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,CAC7B;KACF,CAAC;IAEF,OAAO,IAAI,CAAC,SAAS,CAAC,sBAAsB,CAAC,CAAC;AAChD,CAAC","sourcesContent":["import {\n type StateMetadata,\n type ControllerStateChangeEvent,\n type 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 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 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} from './types';\nimport {\n PAYMENT_TYPES,\n PRODUCT_TYPES,\n type ISubscriptionService,\n type PricingResponse,\n type ProductType,\n type StartSubscriptionRequest,\n type 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 /**\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 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\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 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\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() {\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 {\n customerId: newCustomerId,\n subscriptions: newSubscriptions,\n trialedProducts: newTrialedProducts,\n lastSubscription: newLastSubscription,\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\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 ) {\n this.update((state) => {\n state.subscriptions = newSubscriptions;\n state.customerId = newCustomerId;\n state.trialedProducts = newTrialedProducts;\n state.lastSubscription = newLastSubscription;\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 product - The product type.\n * @returns The subscription.\n */\n getSubscriptionByProduct(product: ProductType): Subscription | undefined {\n return this.state.subscriptions.find((subscription) =>\n subscription.products.some((p) => p.name === product),\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 }) {\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: { subscriptionId: string }) {\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(request: StartSubscriptionRequest) {\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(request: StartCryptoSubscriptionRequest) {\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 * @returns void\n */\n async submitShieldSubscriptionCryptoApproval(\n txMeta: TransactionMeta,\n isSponsored?: boolean,\n ) {\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 isTrialed = trialedProducts?.includes(PRODUCT_TYPES.SHIELD);\n\n const productPrice = this.#getProductPriceByProductAndPlan(\n PRODUCT_TYPES.SHIELD,\n lastSelectedPaymentMethodShield.plan,\n );\n\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 };\n await this.startSubscriptionWithCrypto(params);\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 (p) => p.name === request.productType,\n );\n if (!product) {\n throw new Error('Product price not found');\n }\n\n const price = product.prices.find((p) => p.interval === request.interval);\n if (!price) {\n throw new Error('Price not found');\n }\n\n const chainsPaymentInfo = pricing.paymentMethods.find(\n (t) => t.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 (t) => t.chainId === request.chainId,\n );\n if (!chainPaymentInfo) {\n throw new Error('Invalid chain id');\n }\n const tokenPaymentInfo = chainPaymentInfo.tokens.find(\n (t) => t.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 ) {\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) {\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 async _executePoll(): Promise<void> {\n await this.getSubscriptions();\n }\n\n /**\n * Calculate total subscription price 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) {\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 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 * Triggers an access token refresh.\n */\n triggerAccessTokenRefresh() {\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 product: ProductType,\n plan: RecurringInterval,\n ): ProductPrice {\n const { pricing } = this.state;\n const productPricing = pricing?.products.find((p) => p.name === product);\n const productPrice = productPricing?.prices.find(\n (p) => p.interval === plan,\n );\n if (!productPrice) {\n throw new Error(SubscriptionControllerErrorMessage.ProductPriceNotFound);\n }\n return productPrice;\n }\n\n #assertIsUserNotSubscribed({ products }: { products: ProductType[] }) {\n const subscription = this.state.subscriptions.find((sub) =>\n sub.products.some((p) => products.includes(p.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 }) {\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 (t) => t.type === PAYMENT_TYPES.byCrypto,\n );\n\n const isSponsorshipSupported = cryptoPaymentInfo?.chains?.find(\n (t) => t.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.cjs","sourceRoot":"","sources":["../src/SubscriptionController.ts"],"names":[],"mappings":";;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AEoB,MAAqB,EAAE,MAAqB;IAC/D,yDAAyD;IACzD,IAAI,CAAC,MAAM,IAAI,CAAC,MAAM,EAAE,CAAC;QACvB,IAAI,CAAC,MAAM,IAAI,CAAC,MAAM,EAAE,CAAC;YACvB,OAAO,IAAI,CAAC;QACd,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,CACL,uBAAA,IAAI,wFAAuB,MAA3B,IAAI,EAAwB,MAAM,CAAC;QACnC,uBAAA,IAAI,wFAAuB,MAA3B,IAAI,EAAwB,MAAM,CAAC,CACpC,CAAC;AACJ,CAAC,yGAEsB,YAA0B;IAC/C,MAAM,sBAAsB,GAAG;QAC7B,GAAG,YAAY;QACf,6BAA6B;QAC7B,QAAQ,EAAE,CAAC,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CACjD,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,CAC7B;KACF,CAAC;IAEF,OAAO,IAAI,CAAC,SAAS,CAAC,sBAAsB,CAAC,CAAC;AAChD,CAAC","sourcesContent":["import {\n type StateMetadata,\n type ControllerStateChangeEvent,\n type 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 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 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} from './types';\nimport {\n PAYMENT_TYPES,\n PRODUCT_TYPES,\n SUBSCRIPTION_STATUSES,\n type ISubscriptionService,\n type PricingResponse,\n type ProductType,\n type StartSubscriptionRequest,\n type 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 /**\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 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\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 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\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() {\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 {\n customerId: newCustomerId,\n subscriptions: newSubscriptions,\n trialedProducts: newTrialedProducts,\n lastSubscription: newLastSubscription,\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\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 ) {\n this.update((state) => {\n state.subscriptions = newSubscriptions;\n state.customerId = newCustomerId;\n state.trialedProducts = newTrialedProducts;\n state.lastSubscription = newLastSubscription;\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 product - The product type.\n * @returns The subscription.\n */\n getSubscriptionByProduct(product: ProductType): Subscription | undefined {\n return this.state.subscriptions.find((subscription) =>\n subscription.products.some((p) => p.name === product),\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 }) {\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: { subscriptionId: string }) {\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(request: StartSubscriptionRequest) {\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(request: StartCryptoSubscriptionRequest) {\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 * @returns void\n */\n async submitShieldSubscriptionCryptoApproval(\n txMeta: TransactionMeta,\n isSponsored?: boolean,\n ) {\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((p) => p.name === PRODUCT_TYPES.SHIELD),\n );\n\n this.#assertValidSubscriptionStateForCryptoApproval({\n product: 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 };\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 (p) => p.name === request.productType,\n );\n if (!product) {\n throw new Error('Product price not found');\n }\n\n const price = product.prices.find((p) => p.interval === request.interval);\n if (!price) {\n throw new Error('Price not found');\n }\n\n const chainsPaymentInfo = pricing.paymentMethods.find(\n (t) => t.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 (t) => t.chainId === request.chainId,\n );\n if (!chainPaymentInfo) {\n throw new Error('Invalid chain id');\n }\n const tokenPaymentInfo = chainPaymentInfo.tokens.find(\n (t) => t.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 ) {\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) {\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 async _executePoll(): Promise<void> {\n await this.getSubscriptions();\n }\n\n /**\n * Calculate total subscription price 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) {\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 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 * Triggers an access token refresh.\n */\n triggerAccessTokenRefresh() {\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 product: ProductType,\n plan: RecurringInterval,\n ): ProductPrice {\n const { pricing } = this.state;\n const productPricing = pricing?.products.find((p) => p.name === product);\n const productPrice = productPricing?.prices.find(\n (p) => p.interval === plan,\n );\n if (!productPrice) {\n throw new Error(SubscriptionControllerErrorMessage.ProductPriceNotFound);\n }\n return productPrice;\n }\n\n #assertValidSubscriptionStateForCryptoApproval({\n product,\n }: {\n product: ProductType;\n }) {\n const subscription = this.state.subscriptions.find((sub) =>\n sub.products.some((p) => p.name === product),\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[] }) {\n const subscription = this.state.subscriptions.find((sub) =>\n sub.products.some((p) => products.includes(p.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 }) {\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 (t) => t.type === PAYMENT_TYPES.byCrypto,\n );\n\n const isSponsorshipSupported = cryptoPaymentInfo?.chains?.find(\n (t) => t.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 +1 @@
1
- {"version":3,"file":"SubscriptionController.d.cts","sourceRoot":"","sources":["../src/SubscriptionController.ts"],"names":[],"mappings":";AAAA,OAAO,EAEL,KAAK,0BAA0B,EAC/B,KAAK,wBAAwB,EAC9B,kCAAkC;AACnC,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AAEr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AgB,EAAE,gBAAgB,GACjC,MAAM;IAkBT;;OAEG;IACH,yBAAyB;CA4K1B"}
1
+ {"version":3,"file":"SubscriptionController.d.cts","sourceRoot":"","sources":["../src/SubscriptionController.ts"],"names":[],"mappings":";AAAA,OAAO,EAEL,KAAK,0BAA0B,EAC/B,KAAK,wBAAwB,EAC9B,kCAAkC;AACnC,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AAErD,OAAO,KAAK,EAAE,wBAAwB,EAAE,0CAA0C;AAClF,OAAO,KAAK,EAAE,eAAe,EAAE,yCAAyC;AAKxE,OAAO,EAEL,cAAc,EAGf,wBAAoB;AACrB,OAAO,KAAK,EACV,mBAAmB,EACnB,qBAAqB,EACrB,kCAAkC,EAClC,mCAAmC,EACnC,oCAAoC,EACpC,YAAY,EACZ,uBAAuB,EACvB,8BAA8B,EAC9B,sBAAsB,EACtB,gBAAgB,EAChB,+BAA+B,EAC/B,uBAAuB,EACvB,+BAA+B,EAC/B,oCAAoC,EAGrC,oBAAgB;AACjB,OAAO,EAIL,KAAK,oBAAoB,EACzB,KAAK,eAAe,EACpB,KAAK,WAAW,EAChB,KAAK,wBAAwB,EAC7B,KAAK,YAAY,EAClB,oBAAgB;AAEjB,MAAM,MAAM,2BAA2B,GAAG;IACxC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,eAAe,EAAE,WAAW,EAAE,CAAC;IAC/B,aAAa,EAAE,YAAY,EAAE,CAAC;IAC9B,OAAO,CAAC,EAAE,eAAe,CAAC;IAC1B,gEAAgE;IAChE,gBAAgB,CAAC,EAAE,YAAY,CAAC;IAChC;;;;OAIG;IACH,yBAAyB,CAAC,EAAE,MAAM,CAChC,WAAW,EACX,+BAA+B,CAChC,CAAC;CACH,CAAC;AAGF,MAAM,MAAM,4CAA4C,GAAG;IACzD,IAAI,EAAE,GAAG,OAAO,cAAc,mBAAmB,CAAC;IAClD,OAAO,EAAE,sBAAsB,CAAC,kBAAkB,CAAC,CAAC;CACrD,CAAC;A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,OAAO,CAAC;IAuCnB;;;;;OAKG;IACG,eAAe,CAAC,OAAO,EAAE,sBAAsB;IAIrD;;;;;OAKG;IACG,kBAAkB,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;IAI/D,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;IAoBnC;;;;;;OAMG;IACH,qBAAqB,CACnB,KAAK,EAAE,YAAY,EACnB,gBAAgB,EAAE,gBAAgB,GACjC,MAAM;IAkBT;;OAEG;IACH,yBAAyB;CAwM1B"}
@@ -1 +1 @@
1
- {"version":3,"file":"SubscriptionController.d.mts","sourceRoot":"","sources":["../src/SubscriptionController.ts"],"names":[],"mappings":";AAAA,OAAO,EAEL,KAAK,0BAA0B,EAC/B,KAAK,wBAAwB,EAC9B,kCAAkC;AACnC,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AAErD,OAAO,KAAK,EAAE,wBAAwB,EAAE,0CAA0C;AAClF,OAAO,KAAK,EAAE,eAAe,EAAE,yCAAyC;AAKxE,OAAO,EAEL,cAAc,EAGf,wBAAoB;AACrB,OAAO,KAAK,EACV,mBAAmB,EACnB,qBAAqB,EACrB,kCAAkC,EAClC,mCAAmC,EACnC,oCAAoC,EACpC,YAAY,EACZ,uBAAuB,EACvB,8BAA8B,EAC9B,sBAAsB,EACtB,gBAAgB,EAChB,+BAA+B,EAC/B,uBAAuB,EACvB,+BAA+B,EAC/B,oCAAoC,EAErC,oBAAgB;AACjB,OAAO,EAGL,KAAK,oBAAoB,EACzB,KAAK,eAAe,EACpB,KAAK,WAAW,EAChB,KAAK,wBAAwB,EAC7B,KAAK,YAAY,EAClB,oBAAgB;AAEjB,MAAM,MAAM,2BAA2B,GAAG;IACxC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,eAAe,EAAE,WAAW,EAAE,CAAC;IAC/B,aAAa,EAAE,YAAY,EAAE,CAAC;IAC9B,OAAO,CAAC,EAAE,eAAe,CAAC;IAC1B,gEAAgE;IA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AO,CAAC,+BAA+B,GAAG,YAAY,EAAE,CAAC;IAc5D;;;;OAIG;IACG,mBAAmB,IAAI,OAAO,CAAC,qBAAqB,CAAC;IAI3D;;;;;;;;;OASG;IACH,8BAA8B,CAC5B,OAAO,EAAE,WAAW,EACpB,aAAa,EAAE,+BAA+B;IAmBhD;;;;;;;;;;;;;;OAcG;IACG,wBAAwB,CAC5B,OAAO,EAAE,oCAAoC,GAC5C,OAAO,CAAC,OAAO,CAAC;IAuCnB;;;;;OAKG;IACG,eAAe,CAAC,OAAO,EAAE,sBAAsB;IAIrD;;;;;OAKG;IACG,kBAAkB,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;IAI/D,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;IAoBnC;;;;;;OAMG;IACH,qBAAqB,CACnB,KAAK,EAAE,YAAY,EACnB,gBAAgB,EAAE,gBAAgB,GACjC,MAAM;IAkBT;;OAEG;IACH,yBAAyB;CA4K1B"}
1
+ {"version":3,"file":"SubscriptionController.d.mts","sourceRoot":"","sources":["../src/SubscriptionController.ts"],"names":[],"mappings":";AAAA,OAAO,EAEL,KAAK,0BAA0B,EAC/B,KAAK,wBAAwB,EAC9B,kCAAkC;AACnC,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AAErD,OAAO,KAAK,EAAE,wBAAwB,EAAE,0CAA0C;AAClF,OAAO,KAAK,EAAE,eAAe,EAAE,yCAAyC;AAKxE,OAAO,EAEL,cAAc,EAGf,wBAAoB;AACrB,OAAO,KAAK,EACV,mBAAmB,EACnB,qBAAqB,EACrB,kCAAkC,EAClC,mCAAmC,EACnC,oCAAoC,EACpC,YAAY,EACZ,uBAAuB,EACvB,8BAA8B,EAC9B,sBAAsB,EACtB,gBAAgB,EAChB,+BAA+B,EAC/B,uBAAuB,EACvB,+BAA+B,EAC/B,oCAAoC,EAGrC,oBAAgB;AACjB,OAAO,EAIL,KAAK,oBAAoB,EACzB,KAAK,eAAe,EAC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AAwB;IAUjE,2BAA2B,CAAC,OAAO,EAAE,8BAA8B;IAQzE;;;;;;OAMG;IACG,sCAAsC,CAC1C,MAAM,EAAE,eAAe,EACvB,WAAW,CAAC,EAAE,OAAO;IAsEvB;;;;;;;;;OASG;IACH,iCAAiC,CAC/B,OAAO,EAAE,kCAAkC,GAC1C,mCAAmC;IAiDhC,mBAAmB,CACvB,IAAI,EAAE,uBAAuB,GAC5B,OAAO,CAAC,+BAA+B,GAAG,YAAY,EAAE,CAAC;IAc5D;;;;OAIG;IACG,mBAAmB,IAAI,OAAO,CAAC,qBAAqB,CAAC;IAI3D;;;;;;;;;OASG;IACH,8BAA8B,CAC5B,OAAO,EAAE,WAAW,EACpB,aAAa,EAAE,+BAA+B;IAmBhD;;;;;;;;;;;;;;OAcG;IACG,wBAAwB,CAC5B,OAAO,EAAE,oCAAoC,GAC5C,OAAO,CAAC,OAAO,CAAC;IAuCnB;;;;;OAKG;IACG,eAAe,CAAC,OAAO,EAAE,sBAAsB;IAIrD;;;;;OAKG;IACG,kBAAkB,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;IAI/D,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;IAoBnC;;;;;;OAMG;IACH,qBAAqB,CACnB,KAAK,EAAE,YAAY,EACnB,gBAAgB,EAAE,gBAAgB,GACjC,MAAM;IAkBT;;OAEG;IACH,yBAAyB;CAwM1B"}
@@ -9,12 +9,12 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
9
9
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
10
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
11
  };
12
- var _SubscriptionController_instances, _SubscriptionController_subscriptionService, _SubscriptionController_registerMessageHandlers, _SubscriptionController_getSubscriptionPriceAmount, _SubscriptionController_getProductPriceByProductAndPlan, _SubscriptionController_assertIsUserNotSubscribed, _SubscriptionController_assertIsUserSubscribed, _SubscriptionController_assertIsPaymentMethodCrypto, _SubscriptionController_getIsEligibleForTrialedSponsorship, _SubscriptionController_getChainSupportsSponsorship, _SubscriptionController_areTrialedProductsEqual, _SubscriptionController_areSubscriptionsEqual, _SubscriptionController_isSubscriptionEqual, _SubscriptionController_stringifySubscription;
12
+ var _SubscriptionController_instances, _SubscriptionController_subscriptionService, _SubscriptionController_registerMessageHandlers, _SubscriptionController_getSubscriptionPriceAmount, _SubscriptionController_getProductPriceByProductAndPlan, _SubscriptionController_assertValidSubscriptionStateForCryptoApproval, _SubscriptionController_assertIsUserNotSubscribed, _SubscriptionController_assertIsUserSubscribed, _SubscriptionController_assertIsPaymentMethodCrypto, _SubscriptionController_getIsEligibleForTrialedSponsorship, _SubscriptionController_getChainSupportsSponsorship, _SubscriptionController_areTrialedProductsEqual, _SubscriptionController_areSubscriptionsEqual, _SubscriptionController_isSubscriptionEqual, _SubscriptionController_stringifySubscription;
13
13
  import { StaticIntervalPollingController } from "@metamask/polling-controller";
14
14
  import { TransactionType } from "@metamask/transaction-controller";
15
15
  import { BigNumber } from "bignumber.js";
16
16
  import { ACTIVE_SUBSCRIPTION_STATUSES, controllerName, DEFAULT_POLLING_INTERVAL, SubscriptionControllerErrorMessage } from "./constants.mjs";
17
- import { PAYMENT_TYPES, PRODUCT_TYPES } from "./types.mjs";
17
+ import { PAYMENT_TYPES, PRODUCT_TYPES, SUBSCRIPTION_STATUSES } from "./types.mjs";
18
18
  /**
19
19
  * Get the default state for the Subscription Controller.
20
20
  *
@@ -216,21 +216,43 @@ export class SubscriptionController extends StaticIntervalPollingController() {
216
216
  }
217
217
  const lastSelectedPaymentMethodShield = lastSelectedPaymentMethod[PRODUCT_TYPES.SHIELD];
218
218
  __classPrivateFieldGet(this, _SubscriptionController_instances, "m", _SubscriptionController_assertIsPaymentMethodCrypto).call(this, lastSelectedPaymentMethodShield);
219
- const isTrialed = trialedProducts?.includes(PRODUCT_TYPES.SHIELD);
220
219
  const productPrice = __classPrivateFieldGet(this, _SubscriptionController_instances, "m", _SubscriptionController_getProductPriceByProductAndPlan).call(this, PRODUCT_TYPES.SHIELD, lastSelectedPaymentMethodShield.plan);
221
- const params = {
222
- products: [PRODUCT_TYPES.SHIELD],
223
- isTrialRequested: !isTrialed,
224
- recurringInterval: productPrice.interval,
225
- billingCycles: productPrice.minBillingCycles,
226
- chainId,
227
- payerAddress: txMeta.txParams.from,
228
- tokenSymbol: lastSelectedPaymentMethodShield.paymentTokenSymbol,
229
- rawTransaction: rawTx,
230
- isSponsored,
231
- useTestClock: lastSelectedPaymentMethodShield.useTestClock,
232
- };
233
- await this.startSubscriptionWithCrypto(params);
220
+ const isTrialed = trialedProducts?.includes(PRODUCT_TYPES.SHIELD);
221
+ // get the latest subscriptions state to check if the user has an active shield subscription
222
+ await this.getSubscriptions();
223
+ const currentSubscription = this.state.subscriptions.find((subscription) => subscription.products.some((p) => p.name === PRODUCT_TYPES.SHIELD));
224
+ __classPrivateFieldGet(this, _SubscriptionController_instances, "m", _SubscriptionController_assertValidSubscriptionStateForCryptoApproval).call(this, {
225
+ product: PRODUCT_TYPES.SHIELD,
226
+ });
227
+ // if shield subscription exists, this transaction is for changing payment method
228
+ const isChangePaymentMethod = Boolean(currentSubscription);
229
+ if (isChangePaymentMethod) {
230
+ await this.updatePaymentMethod({
231
+ paymentType: PAYMENT_TYPES.byCrypto,
232
+ subscriptionId: currentSubscription.id,
233
+ chainId,
234
+ payerAddress: txMeta.txParams.from,
235
+ tokenSymbol: lastSelectedPaymentMethodShield.paymentTokenSymbol,
236
+ rawTransaction: rawTx,
237
+ recurringInterval: productPrice.interval,
238
+ billingCycles: productPrice.minBillingCycles,
239
+ });
240
+ }
241
+ else {
242
+ const params = {
243
+ products: [PRODUCT_TYPES.SHIELD],
244
+ isTrialRequested: !isTrialed,
245
+ recurringInterval: productPrice.interval,
246
+ billingCycles: productPrice.minBillingCycles,
247
+ chainId,
248
+ payerAddress: txMeta.txParams.from,
249
+ tokenSymbol: lastSelectedPaymentMethodShield.paymentTokenSymbol,
250
+ rawTransaction: rawTx,
251
+ isSponsored,
252
+ useTestClock: lastSelectedPaymentMethodShield.useTestClock,
253
+ };
254
+ await this.startSubscriptionWithCrypto(params);
255
+ }
234
256
  // update the subscriptions state after subscription created in server
235
257
  await this.getSubscriptions();
236
258
  }
@@ -436,6 +458,20 @@ _SubscriptionController_subscriptionService = new WeakMap(), _SubscriptionContro
436
458
  throw new Error(SubscriptionControllerErrorMessage.ProductPriceNotFound);
437
459
  }
438
460
  return productPrice;
461
+ }, _SubscriptionController_assertValidSubscriptionStateForCryptoApproval = function _SubscriptionController_assertValidSubscriptionStateForCryptoApproval({ product, }) {
462
+ const subscription = this.state.subscriptions.find((sub) => sub.products.some((p) => p.name === product));
463
+ const isValid = !subscription ||
464
+ [
465
+ SUBSCRIPTION_STATUSES.pastDue,
466
+ SUBSCRIPTION_STATUSES.unpaid,
467
+ SUBSCRIPTION_STATUSES.paused,
468
+ SUBSCRIPTION_STATUSES.provisional,
469
+ SUBSCRIPTION_STATUSES.active,
470
+ SUBSCRIPTION_STATUSES.trialing,
471
+ ].includes(subscription.status);
472
+ if (!isValid) {
473
+ throw new Error(SubscriptionControllerErrorMessage.SubscriptionNotValidForCryptoApproval);
474
+ }
439
475
  }, _SubscriptionController_assertIsUserNotSubscribed = function _SubscriptionController_assertIsUserNotSubscribed({ products }) {
440
476
  const subscription = this.state.subscriptions.find((sub) => sub.products.some((p) => products.includes(p.name)));
441
477
  if (subscription &&
@@ -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,EAAE,qBAAqB;AAEzC,OAAO,EACL,4BAA4B,EAC5B,cAAc,EACd,wBAAwB,EAC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CAAC;AACJ,CAAC,yGAEsB,YAA0B;IAC/C,MAAM,sBAAsB,GAAG;QAC7B,GAAG,YAAY;QACf,6BAA6B;QAC7B,QAAQ,EAAE,CAAC,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CACjD,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,CAC7B;KACF,CAAC;IAEF,OAAO,IAAI,CAAC,SAAS,CAAC,sBAAsB,CAAC,CAAC;AAChD,CAAC","sourcesContent":["import {\n type StateMetadata,\n type ControllerStateChangeEvent,\n type 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 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 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} from './types';\nimport {\n PAYMENT_TYPES,\n PRODUCT_TYPES,\n type ISubscriptionService,\n type PricingResponse,\n type ProductType,\n type StartSubscriptionRequest,\n type 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 /**\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 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\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 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\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() {\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 {\n customerId: newCustomerId,\n subscriptions: newSubscriptions,\n trialedProducts: newTrialedProducts,\n lastSubscription: newLastSubscription,\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\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 ) {\n this.update((state) => {\n state.subscriptions = newSubscriptions;\n state.customerId = newCustomerId;\n state.trialedProducts = newTrialedProducts;\n state.lastSubscription = newLastSubscription;\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 product - The product type.\n * @returns The subscription.\n */\n getSubscriptionByProduct(product: ProductType): Subscription | undefined {\n return this.state.subscriptions.find((subscription) =>\n subscription.products.some((p) => p.name === product),\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 }) {\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: { subscriptionId: string }) {\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(request: StartSubscriptionRequest) {\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(request: StartCryptoSubscriptionRequest) {\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 * @returns void\n */\n async submitShieldSubscriptionCryptoApproval(\n txMeta: TransactionMeta,\n isSponsored?: boolean,\n ) {\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 isTrialed = trialedProducts?.includes(PRODUCT_TYPES.SHIELD);\n\n const productPrice = this.#getProductPriceByProductAndPlan(\n PRODUCT_TYPES.SHIELD,\n lastSelectedPaymentMethodShield.plan,\n );\n\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 };\n await this.startSubscriptionWithCrypto(params);\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 (p) => p.name === request.productType,\n );\n if (!product) {\n throw new Error('Product price not found');\n }\n\n const price = product.prices.find((p) => p.interval === request.interval);\n if (!price) {\n throw new Error('Price not found');\n }\n\n const chainsPaymentInfo = pricing.paymentMethods.find(\n (t) => t.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 (t) => t.chainId === request.chainId,\n );\n if (!chainPaymentInfo) {\n throw new Error('Invalid chain id');\n }\n const tokenPaymentInfo = chainPaymentInfo.tokens.find(\n (t) => t.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 ) {\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) {\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 async _executePoll(): Promise<void> {\n await this.getSubscriptions();\n }\n\n /**\n * Calculate total subscription price 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) {\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 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 * Triggers an access token refresh.\n */\n triggerAccessTokenRefresh() {\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 product: ProductType,\n plan: RecurringInterval,\n ): ProductPrice {\n const { pricing } = this.state;\n const productPricing = pricing?.products.find((p) => p.name === product);\n const productPrice = productPricing?.prices.find(\n (p) => p.interval === plan,\n );\n if (!productPrice) {\n throw new Error(SubscriptionControllerErrorMessage.ProductPriceNotFound);\n }\n return productPrice;\n }\n\n #assertIsUserNotSubscribed({ products }: { products: ProductType[] }) {\n const subscription = this.state.subscriptions.find((sub) =>\n sub.products.some((p) => products.includes(p.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 }) {\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 (t) => t.type === PAYMENT_TYPES.byCrypto,\n );\n\n const isSponsorshipSupported = cryptoPaymentInfo?.chains?.find(\n (t) => t.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,qCAAqC;AAG/E,OAAO,EAAE,eAAe,EAAE,yCAAyC;AAEnE,OAAO,EAAE,SAAS,EAAE,qBAAqB;AAEzC,OAAO,EACL,4BAA4B,EAC5B,cAAc,EACd,wBAAwB,EACxB,kCAAkC,EACnC,wBAAoB;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,MAAM,EAAE,CAAC;QACvB,IAAI,CAAC,MAAM,IAAI,CAAC,MAAM,EAAE,CAAC;YACvB,OAAO,IAAI,CAAC;QACd,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,CACL,uBAAA,IAAI,wFAAuB,MAA3B,IAAI,EAAwB,MAAM,CAAC;QACnC,uBAAA,IAAI,wFAAuB,MAA3B,IAAI,EAAwB,MAAM,CAAC,CACpC,CAAC;AACJ,CAAC,yGAEsB,YAA0B;IAC/C,MAAM,sBAAsB,GAAG;QAC7B,GAAG,YAAY;QACf,6BAA6B;QAC7B,QAAQ,EAAE,CAAC,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CACjD,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,CAC7B;KACF,CAAC;IAEF,OAAO,IAAI,CAAC,SAAS,CAAC,sBAAsB,CAAC,CAAC;AAChD,CAAC","sourcesContent":["import {\n type StateMetadata,\n type ControllerStateChangeEvent,\n type 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 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 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} from './types';\nimport {\n PAYMENT_TYPES,\n PRODUCT_TYPES,\n SUBSCRIPTION_STATUSES,\n type ISubscriptionService,\n type PricingResponse,\n type ProductType,\n type StartSubscriptionRequest,\n type 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 /**\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 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\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 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\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() {\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 {\n customerId: newCustomerId,\n subscriptions: newSubscriptions,\n trialedProducts: newTrialedProducts,\n lastSubscription: newLastSubscription,\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\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 ) {\n this.update((state) => {\n state.subscriptions = newSubscriptions;\n state.customerId = newCustomerId;\n state.trialedProducts = newTrialedProducts;\n state.lastSubscription = newLastSubscription;\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 product - The product type.\n * @returns The subscription.\n */\n getSubscriptionByProduct(product: ProductType): Subscription | undefined {\n return this.state.subscriptions.find((subscription) =>\n subscription.products.some((p) => p.name === product),\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 }) {\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: { subscriptionId: string }) {\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(request: StartSubscriptionRequest) {\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(request: StartCryptoSubscriptionRequest) {\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 * @returns void\n */\n async submitShieldSubscriptionCryptoApproval(\n txMeta: TransactionMeta,\n isSponsored?: boolean,\n ) {\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((p) => p.name === PRODUCT_TYPES.SHIELD),\n );\n\n this.#assertValidSubscriptionStateForCryptoApproval({\n product: 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 };\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 (p) => p.name === request.productType,\n );\n if (!product) {\n throw new Error('Product price not found');\n }\n\n const price = product.prices.find((p) => p.interval === request.interval);\n if (!price) {\n throw new Error('Price not found');\n }\n\n const chainsPaymentInfo = pricing.paymentMethods.find(\n (t) => t.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 (t) => t.chainId === request.chainId,\n );\n if (!chainPaymentInfo) {\n throw new Error('Invalid chain id');\n }\n const tokenPaymentInfo = chainPaymentInfo.tokens.find(\n (t) => t.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 ) {\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) {\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 async _executePoll(): Promise<void> {\n await this.getSubscriptions();\n }\n\n /**\n * Calculate total subscription price 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) {\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 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 * Triggers an access token refresh.\n */\n triggerAccessTokenRefresh() {\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 product: ProductType,\n plan: RecurringInterval,\n ): ProductPrice {\n const { pricing } = this.state;\n const productPricing = pricing?.products.find((p) => p.name === product);\n const productPrice = productPricing?.prices.find(\n (p) => p.interval === plan,\n );\n if (!productPrice) {\n throw new Error(SubscriptionControllerErrorMessage.ProductPriceNotFound);\n }\n return productPrice;\n }\n\n #assertValidSubscriptionStateForCryptoApproval({\n product,\n }: {\n product: ProductType;\n }) {\n const subscription = this.state.subscriptions.find((sub) =>\n sub.products.some((p) => p.name === product),\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[] }) {\n const subscription = this.state.subscriptions.find((sub) =>\n sub.products.some((p) => products.includes(p.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 }) {\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 (t) => t.type === PAYMENT_TYPES.byCrypto,\n );\n\n const isSponsorshipSupported = cryptoPaymentInfo?.chains?.find(\n (t) => t.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"]}
@@ -42,6 +42,7 @@ var SubscriptionControllerErrorMessage;
42
42
  SubscriptionControllerErrorMessage["PaymentTokenAddressAndSymbolRequiredForCrypto"] = "SubscriptionController - Payment token address and symbol are required for crypto payment";
43
43
  SubscriptionControllerErrorMessage["PaymentMethodNotCrypto"] = "SubscriptionController - Payment method is not crypto";
44
44
  SubscriptionControllerErrorMessage["ProductPriceNotFound"] = "SubscriptionController - Product price not found";
45
+ SubscriptionControllerErrorMessage["SubscriptionNotValidForCryptoApproval"] = "SubscriptionController - Subscription is not valid for crypto approval";
45
46
  })(SubscriptionControllerErrorMessage || (exports.SubscriptionControllerErrorMessage = SubscriptionControllerErrorMessage = {}));
46
47
  exports.DEFAULT_POLLING_INTERVAL = 5 * 60 * 1000; // 5 minutes
47
48
  exports.ACTIVE_SUBSCRIPTION_STATUSES = [
@@ -1 +1 @@
1
- {"version":3,"file":"constants.cjs","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;;AAAA,uCAAgD;AAEnC,QAAA,cAAc,GAAG,wBAAwB,CAAC;AAEvD,IAAY,GAIX;AAJD,WAAY,GAAG;IACb,kBAAW,CAAA;IACX,kBAAW,CAAA;IACX,kBAAW,CAAA;AACb,CAAC,EAJW,GAAG,mBAAH,GAAG,QAId;AAMD,MAAM,QAAQ,GAA8B;IAC1C,GAAG,EAAE;QACH,kBAAkB,EAAE,6CAA6C;KAClE;IACD,GAAG,EAAE;QACH,kBAAkB,EAAE,6CAA6C;KAClE;IACD,GAAG,EAAE;QACH,kBAAkB,EAAE,yCAAyC;KAC9D;CACF,CAAC;AAEF;;;;;;GAMG;AACH,SAAgB,UAAU,CAAC,GAAQ;IACjC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QACnB,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;IACvD,CAAC;IACD,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC;AACvB,CAAC;AALD,gCAKC;AAED,IAAY,kCAOX;AAPD,WAAY,kCAAkC;IAC5C,mHAAwE,CAAA;IACxE,2GAAgE,CAAA;IAChE,wIAA6F,CAAA;IAC7F,iLAAsI,CAAA;IACtI,sHAA2E,CAAA;IAC3E,+GAAoE,CAAA;AACtE,CAAC,EAPW,kCAAkC,kDAAlC,kCAAkC,QAO7C;AAEY,QAAA,wBAAwB,GAAG,CAAC,GAAG,EAAE,GAAG,IAAK,CAAC,CAAC,YAAY;AAEvD,QAAA,4BAA4B,GAAG;IAC1C,6BAAqB,CAAC,MAAM;IAC5B,6BAAqB,CAAC,QAAQ;IAC9B,6BAAqB,CAAC,WAAW;CACtB,CAAC","sourcesContent":["import { SUBSCRIPTION_STATUSES } from './types';\n\nexport const controllerName = 'SubscriptionController';\n\nexport enum Env {\n DEV = 'dev',\n UAT = 'uat',\n PRD = 'prd',\n}\n\ntype EnvUrlsEntry = {\n subscriptionApiUrl: string;\n};\n\nconst ENV_URLS: Record<Env, EnvUrlsEntry> = {\n dev: {\n subscriptionApiUrl: 'https://subscription.dev-api.cx.metamask.io',\n },\n uat: {\n subscriptionApiUrl: 'https://subscription.uat-api.cx.metamask.io',\n },\n prd: {\n subscriptionApiUrl: 'https://subscription.api.cx.metamask.io',\n },\n};\n\n/**\n * Validates and returns correct environment endpoints\n *\n * @param env - environment field\n * @returns the correct environment url\n * @throws on invalid environment passed\n */\nexport function getEnvUrls(env: Env): EnvUrlsEntry {\n if (!ENV_URLS[env]) {\n throw new Error('invalid environment configuration');\n }\n return ENV_URLS[env];\n}\n\nexport enum SubscriptionControllerErrorMessage {\n UserAlreadySubscribed = `${controllerName} - User is already subscribed`,\n UserNotSubscribed = `${controllerName} - User is not subscribed`,\n SubscriptionProductsEmpty = `${controllerName} - Subscription products array cannot be empty`,\n PaymentTokenAddressAndSymbolRequiredForCrypto = `${controllerName} - Payment token address and symbol are required for crypto payment`,\n PaymentMethodNotCrypto = `${controllerName} - Payment method is not crypto`,\n ProductPriceNotFound = `${controllerName} - Product price not found`,\n}\n\nexport const DEFAULT_POLLING_INTERVAL = 5 * 60 * 1_000; // 5 minutes\n\nexport const ACTIVE_SUBSCRIPTION_STATUSES = [\n SUBSCRIPTION_STATUSES.active,\n SUBSCRIPTION_STATUSES.trialing,\n SUBSCRIPTION_STATUSES.provisional,\n] as string[];\n"]}
1
+ {"version":3,"file":"constants.cjs","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;;AAAA,uCAAgD;AAEnC,QAAA,cAAc,GAAG,wBAAwB,CAAC;AAEvD,IAAY,GAIX;AAJD,WAAY,GAAG;IACb,kBAAW,CAAA;IACX,kBAAW,CAAA;IACX,kBAAW,CAAA;AACb,CAAC,EAJW,GAAG,mBAAH,GAAG,QAId;AAMD,MAAM,QAAQ,GAA8B;IAC1C,GAAG,EAAE;QACH,kBAAkB,EAAE,6CAA6C;KAClE;IACD,GAAG,EAAE;QACH,kBAAkB,EAAE,6CAA6C;KAClE;IACD,GAAG,EAAE;QACH,kBAAkB,EAAE,yCAAyC;KAC9D;CACF,CAAC;AAEF;;;;;;GAMG;AACH,SAAgB,UAAU,CAAC,GAAQ;IACjC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QACnB,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;IACvD,CAAC;IACD,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC;AACvB,CAAC;AALD,gCAKC;AAED,IAAY,kCAQX;AARD,WAAY,kCAAkC;IAC5C,mHAAwE,CAAA;IACxE,2GAAgE,CAAA;IAChE,wIAA6F,CAAA;IAC7F,iLAAsI,CAAA;IACtI,sHAA2E,CAAA;IAC3E,+GAAoE,CAAA;IACpE,sJAA2G,CAAA;AAC7G,CAAC,EARW,kCAAkC,kDAAlC,kCAAkC,QAQ7C;AAEY,QAAA,wBAAwB,GAAG,CAAC,GAAG,EAAE,GAAG,IAAK,CAAC,CAAC,YAAY;AAEvD,QAAA,4BAA4B,GAAG;IAC1C,6BAAqB,CAAC,MAAM;IAC5B,6BAAqB,CAAC,QAAQ;IAC9B,6BAAqB,CAAC,WAAW;CACtB,CAAC","sourcesContent":["import { SUBSCRIPTION_STATUSES } from './types';\n\nexport const controllerName = 'SubscriptionController';\n\nexport enum Env {\n DEV = 'dev',\n UAT = 'uat',\n PRD = 'prd',\n}\n\ntype EnvUrlsEntry = {\n subscriptionApiUrl: string;\n};\n\nconst ENV_URLS: Record<Env, EnvUrlsEntry> = {\n dev: {\n subscriptionApiUrl: 'https://subscription.dev-api.cx.metamask.io',\n },\n uat: {\n subscriptionApiUrl: 'https://subscription.uat-api.cx.metamask.io',\n },\n prd: {\n subscriptionApiUrl: 'https://subscription.api.cx.metamask.io',\n },\n};\n\n/**\n * Validates and returns correct environment endpoints\n *\n * @param env - environment field\n * @returns the correct environment url\n * @throws on invalid environment passed\n */\nexport function getEnvUrls(env: Env): EnvUrlsEntry {\n if (!ENV_URLS[env]) {\n throw new Error('invalid environment configuration');\n }\n return ENV_URLS[env];\n}\n\nexport enum SubscriptionControllerErrorMessage {\n UserAlreadySubscribed = `${controllerName} - User is already subscribed`,\n UserNotSubscribed = `${controllerName} - User is not subscribed`,\n SubscriptionProductsEmpty = `${controllerName} - Subscription products array cannot be empty`,\n PaymentTokenAddressAndSymbolRequiredForCrypto = `${controllerName} - Payment token address and symbol are required for crypto payment`,\n PaymentMethodNotCrypto = `${controllerName} - Payment method is not crypto`,\n ProductPriceNotFound = `${controllerName} - Product price not found`,\n SubscriptionNotValidForCryptoApproval = `${controllerName} - Subscription is not valid for crypto approval`,\n}\n\nexport const DEFAULT_POLLING_INTERVAL = 5 * 60 * 1_000; // 5 minutes\n\nexport const ACTIVE_SUBSCRIPTION_STATUSES = [\n SUBSCRIPTION_STATUSES.active,\n SUBSCRIPTION_STATUSES.trialing,\n SUBSCRIPTION_STATUSES.provisional,\n] as string[];\n"]}
@@ -21,7 +21,8 @@ export declare enum SubscriptionControllerErrorMessage {
21
21
  SubscriptionProductsEmpty = "SubscriptionController - Subscription products array cannot be empty",
22
22
  PaymentTokenAddressAndSymbolRequiredForCrypto = "SubscriptionController - Payment token address and symbol are required for crypto payment",
23
23
  PaymentMethodNotCrypto = "SubscriptionController - Payment method is not crypto",
24
- ProductPriceNotFound = "SubscriptionController - Product price not found"
24
+ ProductPriceNotFound = "SubscriptionController - Product price not found",
25
+ SubscriptionNotValidForCryptoApproval = "SubscriptionController - Subscription is not valid for crypto approval"
25
26
  }
26
27
  export declare const DEFAULT_POLLING_INTERVAL: number;
27
28
  export declare const ACTIVE_SUBSCRIPTION_STATUSES: string[];
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.cts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,cAAc,2BAA2B,CAAC;AAEvD,oBAAY,GAAG;IACb,GAAG,QAAQ;IACX,GAAG,QAAQ;IACX,GAAG,QAAQ;CACZ;AAED,KAAK,YAAY,GAAG;IAClB,kBAAkB,EAAE,MAAM,CAAC;CAC5B,CAAC;AAcF;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,GAAG,GAAG,YAAY,CAKjD;AAED,oBAAY,kCAAkC;IAC5C,qBAAqB,wDAAmD;IACxE,iBAAiB,oDAA+C;IAChE,yBAAyB,yEAAoE;IAC7F,6CAA6C,8FAAyF;IACtI,sBAAsB,0DAAqD;IAC3E,oBAAoB,qDAAgD;CACrE;AAED,eAAO,MAAM,wBAAwB,QAAiB,CAAC;AAEvD,eAAO,MAAM,4BAA4B,UAI5B,CAAC"}
1
+ {"version":3,"file":"constants.d.cts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,cAAc,2BAA2B,CAAC;AAEvD,oBAAY,GAAG;IACb,GAAG,QAAQ;IACX,GAAG,QAAQ;IACX,GAAG,QAAQ;CACZ;AAED,KAAK,YAAY,GAAG;IAClB,kBAAkB,EAAE,MAAM,CAAC;CAC5B,CAAC;AAcF;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,GAAG,GAAG,YAAY,CAKjD;AAED,oBAAY,kCAAkC;IAC5C,qBAAqB,wDAAmD;IACxE,iBAAiB,oDAA+C;IAChE,yBAAyB,yEAAoE;IAC7F,6CAA6C,8FAAyF;IACtI,sBAAsB,0DAAqD;IAC3E,oBAAoB,qDAAgD;IACpE,qCAAqC,2EAAsE;CAC5G;AAED,eAAO,MAAM,wBAAwB,QAAiB,CAAC;AAEvD,eAAO,MAAM,4BAA4B,UAI5B,CAAC"}
@@ -21,7 +21,8 @@ export declare enum SubscriptionControllerErrorMessage {
21
21
  SubscriptionProductsEmpty = "SubscriptionController - Subscription products array cannot be empty",
22
22
  PaymentTokenAddressAndSymbolRequiredForCrypto = "SubscriptionController - Payment token address and symbol are required for crypto payment",
23
23
  PaymentMethodNotCrypto = "SubscriptionController - Payment method is not crypto",
24
- ProductPriceNotFound = "SubscriptionController - Product price not found"
24
+ ProductPriceNotFound = "SubscriptionController - Product price not found",
25
+ SubscriptionNotValidForCryptoApproval = "SubscriptionController - Subscription is not valid for crypto approval"
25
26
  }
26
27
  export declare const DEFAULT_POLLING_INTERVAL: number;
27
28
  export declare const ACTIVE_SUBSCRIPTION_STATUSES: string[];
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.mts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,cAAc,2BAA2B,CAAC;AAEvD,oBAAY,GAAG;IACb,GAAG,QAAQ;IACX,GAAG,QAAQ;IACX,GAAG,QAAQ;CACZ;AAED,KAAK,YAAY,GAAG;IAClB,kBAAkB,EAAE,MAAM,CAAC;CAC5B,CAAC;AAcF;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,GAAG,GAAG,YAAY,CAKjD;AAED,oBAAY,kCAAkC;IAC5C,qBAAqB,wDAAmD;IACxE,iBAAiB,oDAA+C;IAChE,yBAAyB,yEAAoE;IAC7F,6CAA6C,8FAAyF;IACtI,sBAAsB,0DAAqD;IAC3E,oBAAoB,qDAAgD;CACrE;AAED,eAAO,MAAM,wBAAwB,QAAiB,CAAC;AAEvD,eAAO,MAAM,4BAA4B,UAI5B,CAAC"}
1
+ {"version":3,"file":"constants.d.mts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,cAAc,2BAA2B,CAAC;AAEvD,oBAAY,GAAG;IACb,GAAG,QAAQ;IACX,GAAG,QAAQ;IACX,GAAG,QAAQ;CACZ;AAED,KAAK,YAAY,GAAG;IAClB,kBAAkB,EAAE,MAAM,CAAC;CAC5B,CAAC;AAcF;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,GAAG,GAAG,YAAY,CAKjD;AAED,oBAAY,kCAAkC;IAC5C,qBAAqB,wDAAmD;IACxE,iBAAiB,oDAA+C;IAChE,yBAAyB,yEAAoE;IAC7F,6CAA6C,8FAAyF;IACtI,sBAAsB,0DAAqD;IAC3E,oBAAoB,qDAAgD;IACpE,qCAAqC,2EAAsE;CAC5G;AAED,eAAO,MAAM,wBAAwB,QAAiB,CAAC;AAEvD,eAAO,MAAM,4BAA4B,UAI5B,CAAC"}
@@ -38,6 +38,7 @@ export var SubscriptionControllerErrorMessage;
38
38
  SubscriptionControllerErrorMessage["PaymentTokenAddressAndSymbolRequiredForCrypto"] = "SubscriptionController - Payment token address and symbol are required for crypto payment";
39
39
  SubscriptionControllerErrorMessage["PaymentMethodNotCrypto"] = "SubscriptionController - Payment method is not crypto";
40
40
  SubscriptionControllerErrorMessage["ProductPriceNotFound"] = "SubscriptionController - Product price not found";
41
+ SubscriptionControllerErrorMessage["SubscriptionNotValidForCryptoApproval"] = "SubscriptionController - Subscription is not valid for crypto approval";
41
42
  })(SubscriptionControllerErrorMessage || (SubscriptionControllerErrorMessage = {}));
42
43
  export const DEFAULT_POLLING_INTERVAL = 5 * 60 * 1000; // 5 minutes
43
44
  export const ACTIVE_SUBSCRIPTION_STATUSES = [
@@ -1 +1 @@
1
- {"version":3,"file":"constants.mjs","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,oBAAgB;AAEhD,MAAM,CAAC,MAAM,cAAc,GAAG,wBAAwB,CAAC;AAEvD,MAAM,CAAN,IAAY,GAIX;AAJD,WAAY,GAAG;IACb,kBAAW,CAAA;IACX,kBAAW,CAAA;IACX,kBAAW,CAAA;AACb,CAAC,EAJW,GAAG,KAAH,GAAG,QAId;AAMD,MAAM,QAAQ,GAA8B;IAC1C,GAAG,EAAE;QACH,kBAAkB,EAAE,6CAA6C;KAClE;IACD,GAAG,EAAE;QACH,kBAAkB,EAAE,6CAA6C;KAClE;IACD,GAAG,EAAE;QACH,kBAAkB,EAAE,yCAAyC;KAC9D;CACF,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CAAC,GAAQ;IACjC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QACnB,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;IACvD,CAAC;IACD,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC;AACvB,CAAC;AAED,MAAM,CAAN,IAAY,kCAOX;AAPD,WAAY,kCAAkC;IAC5C,mHAAwE,CAAA;IACxE,2GAAgE,CAAA;IAChE,wIAA6F,CAAA;IAC7F,iLAAsI,CAAA;IACtI,sHAA2E,CAAA;IAC3E,+GAAoE,CAAA;AACtE,CAAC,EAPW,kCAAkC,KAAlC,kCAAkC,QAO7C;AAED,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,GAAG,EAAE,GAAG,IAAK,CAAC,CAAC,YAAY;AAEpE,MAAM,CAAC,MAAM,4BAA4B,GAAG;IAC1C,qBAAqB,CAAC,MAAM;IAC5B,qBAAqB,CAAC,QAAQ;IAC9B,qBAAqB,CAAC,WAAW;CACtB,CAAC","sourcesContent":["import { SUBSCRIPTION_STATUSES } from './types';\n\nexport const controllerName = 'SubscriptionController';\n\nexport enum Env {\n DEV = 'dev',\n UAT = 'uat',\n PRD = 'prd',\n}\n\ntype EnvUrlsEntry = {\n subscriptionApiUrl: string;\n};\n\nconst ENV_URLS: Record<Env, EnvUrlsEntry> = {\n dev: {\n subscriptionApiUrl: 'https://subscription.dev-api.cx.metamask.io',\n },\n uat: {\n subscriptionApiUrl: 'https://subscription.uat-api.cx.metamask.io',\n },\n prd: {\n subscriptionApiUrl: 'https://subscription.api.cx.metamask.io',\n },\n};\n\n/**\n * Validates and returns correct environment endpoints\n *\n * @param env - environment field\n * @returns the correct environment url\n * @throws on invalid environment passed\n */\nexport function getEnvUrls(env: Env): EnvUrlsEntry {\n if (!ENV_URLS[env]) {\n throw new Error('invalid environment configuration');\n }\n return ENV_URLS[env];\n}\n\nexport enum SubscriptionControllerErrorMessage {\n UserAlreadySubscribed = `${controllerName} - User is already subscribed`,\n UserNotSubscribed = `${controllerName} - User is not subscribed`,\n SubscriptionProductsEmpty = `${controllerName} - Subscription products array cannot be empty`,\n PaymentTokenAddressAndSymbolRequiredForCrypto = `${controllerName} - Payment token address and symbol are required for crypto payment`,\n PaymentMethodNotCrypto = `${controllerName} - Payment method is not crypto`,\n ProductPriceNotFound = `${controllerName} - Product price not found`,\n}\n\nexport const DEFAULT_POLLING_INTERVAL = 5 * 60 * 1_000; // 5 minutes\n\nexport const ACTIVE_SUBSCRIPTION_STATUSES = [\n SUBSCRIPTION_STATUSES.active,\n SUBSCRIPTION_STATUSES.trialing,\n SUBSCRIPTION_STATUSES.provisional,\n] as string[];\n"]}
1
+ {"version":3,"file":"constants.mjs","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,oBAAgB;AAEhD,MAAM,CAAC,MAAM,cAAc,GAAG,wBAAwB,CAAC;AAEvD,MAAM,CAAN,IAAY,GAIX;AAJD,WAAY,GAAG;IACb,kBAAW,CAAA;IACX,kBAAW,CAAA;IACX,kBAAW,CAAA;AACb,CAAC,EAJW,GAAG,KAAH,GAAG,QAId;AAMD,MAAM,QAAQ,GAA8B;IAC1C,GAAG,EAAE;QACH,kBAAkB,EAAE,6CAA6C;KAClE;IACD,GAAG,EAAE;QACH,kBAAkB,EAAE,6CAA6C;KAClE;IACD,GAAG,EAAE;QACH,kBAAkB,EAAE,yCAAyC;KAC9D;CACF,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CAAC,GAAQ;IACjC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QACnB,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;IACvD,CAAC;IACD,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC;AACvB,CAAC;AAED,MAAM,CAAN,IAAY,kCAQX;AARD,WAAY,kCAAkC;IAC5C,mHAAwE,CAAA;IACxE,2GAAgE,CAAA;IAChE,wIAA6F,CAAA;IAC7F,iLAAsI,CAAA;IACtI,sHAA2E,CAAA;IAC3E,+GAAoE,CAAA;IACpE,sJAA2G,CAAA;AAC7G,CAAC,EARW,kCAAkC,KAAlC,kCAAkC,QAQ7C;AAED,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,GAAG,EAAE,GAAG,IAAK,CAAC,CAAC,YAAY;AAEpE,MAAM,CAAC,MAAM,4BAA4B,GAAG;IAC1C,qBAAqB,CAAC,MAAM;IAC5B,qBAAqB,CAAC,QAAQ;IAC9B,qBAAqB,CAAC,WAAW;CACtB,CAAC","sourcesContent":["import { SUBSCRIPTION_STATUSES } from './types';\n\nexport const controllerName = 'SubscriptionController';\n\nexport enum Env {\n DEV = 'dev',\n UAT = 'uat',\n PRD = 'prd',\n}\n\ntype EnvUrlsEntry = {\n subscriptionApiUrl: string;\n};\n\nconst ENV_URLS: Record<Env, EnvUrlsEntry> = {\n dev: {\n subscriptionApiUrl: 'https://subscription.dev-api.cx.metamask.io',\n },\n uat: {\n subscriptionApiUrl: 'https://subscription.uat-api.cx.metamask.io',\n },\n prd: {\n subscriptionApiUrl: 'https://subscription.api.cx.metamask.io',\n },\n};\n\n/**\n * Validates and returns correct environment endpoints\n *\n * @param env - environment field\n * @returns the correct environment url\n * @throws on invalid environment passed\n */\nexport function getEnvUrls(env: Env): EnvUrlsEntry {\n if (!ENV_URLS[env]) {\n throw new Error('invalid environment configuration');\n }\n return ENV_URLS[env];\n}\n\nexport enum SubscriptionControllerErrorMessage {\n UserAlreadySubscribed = `${controllerName} - User is already subscribed`,\n UserNotSubscribed = `${controllerName} - User is not subscribed`,\n SubscriptionProductsEmpty = `${controllerName} - Subscription products array cannot be empty`,\n PaymentTokenAddressAndSymbolRequiredForCrypto = `${controllerName} - Payment token address and symbol are required for crypto payment`,\n PaymentMethodNotCrypto = `${controllerName} - Payment method is not crypto`,\n ProductPriceNotFound = `${controllerName} - Product price not found`,\n SubscriptionNotValidForCryptoApproval = `${controllerName} - Subscription is not valid for crypto approval`,\n}\n\nexport const DEFAULT_POLLING_INTERVAL = 5 * 60 * 1_000; // 5 minutes\n\nexport const ACTIVE_SUBSCRIPTION_STATUSES = [\n SUBSCRIPTION_STATUSES.active,\n SUBSCRIPTION_STATUSES.trialing,\n SUBSCRIPTION_STATUSES.provisional,\n] as string[];\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAEa,QAAA,aAAa,GAAG;IAC3B,MAAM,EAAE,QAAQ;CACR,CAAC;AAIE,QAAA,aAAa,GAAG;IAC3B,MAAM,EAAE,MAAM;IACd,QAAQ,EAAE,QAAQ;CACV,CAAC;AAIE,QAAA,mBAAmB,GAAG;IACjC,KAAK,EAAE,OAAO;IACd,IAAI,EAAE,MAAM;CACJ,CAAC;AAKE,QAAA,qBAAqB,GAAG;IACnC,iBAAiB;IACjB,UAAU,EAAE,YAAY;IACxB,iBAAiB,EAAE,oBAAoB;IACvC,gBAAgB;IAChB,WAAW,EAAE,aAAa;IAC1B,QAAQ,EAAE,UAAU;IACpB,MAAM,EAAE,QAAQ;IAChB,iBAAiB;IACjB,OAAO,EAAE,UAAU;IACnB,MAAM,EAAE,QAAQ;IAChB,mBAAmB;IACnB,QAAQ,EAAE,UAAU;IACpB,gBAAgB;IAChB,MAAM,EAAE,QAAQ;CACR,CAAC;AAKE,QAAA,4BAA4B,GAAG;IAC1C,4BAA4B,EAAE,8BAA8B;IAC5D,6BAA6B,EAAE,+BAA+B;IAC9D,sDAAsD,EACpD,wDAAwD;IAC1D,oBAAoB,EAAE,sBAAsB;IAC5C,sBAAsB,EAAE,wBAAwB;CACxC,CAAC;AAKE,QAAA,UAAU,GAAG;IACxB,CAAC,EAAE,GAAG;IACN,CAAC,EAAE,GAAG;CACE,CAAC;AA4LE,QAAA,YAAY,GAAG;IAC1B,OAAO,EAAE,SAAS;IAClB,WAAW,EAAE,aAAa;CAClB,CAAC;AAIE,QAAA,kBAAkB,GAAG;IAChC,UAAU,EAAE,MAAM;IAClB,aAAa,EAAE,SAAS;IACxB,aAAa,EAAE,SAAS;IACxB,eAAe,EAAE,WAAW;IAC5B,iBAAiB,EAAE,aAAa;IAChC,aAAa,EAAE,KAAK;CACZ,CAAC;AAuBE,QAAA,qBAAqB,GAAG;IACnC,sBAAsB,EAAE,2BAA2B;IACnD,oBAAoB,EAAE,wBAAwB;CACtC,CAAC","sourcesContent":["import type { Hex } from '@metamask/utils';\n\nexport const PRODUCT_TYPES = {\n SHIELD: 'shield',\n} as const;\n\nexport type ProductType = (typeof PRODUCT_TYPES)[keyof typeof PRODUCT_TYPES];\n\nexport const PAYMENT_TYPES = {\n byCard: 'card',\n byCrypto: 'crypto',\n} as const;\n\nexport type PaymentType = (typeof PAYMENT_TYPES)[keyof typeof PAYMENT_TYPES];\n\nexport const RECURRING_INTERVALS = {\n month: 'month',\n year: 'year',\n} as const;\n\nexport type RecurringInterval =\n (typeof RECURRING_INTERVALS)[keyof typeof RECURRING_INTERVALS];\n\nexport const SUBSCRIPTION_STATUSES = {\n // Initial states\n incomplete: 'incomplete',\n incompleteExpired: 'incomplete_expired',\n // Active states\n provisional: 'provisional',\n trialing: 'trialing',\n active: 'active',\n // Payment issues\n pastDue: 'past_due',\n unpaid: 'unpaid',\n // Cancelled states\n canceled: 'canceled',\n // Paused states\n paused: 'paused',\n} as const;\n\nexport type SubscriptionStatus =\n (typeof SUBSCRIPTION_STATUSES)[keyof typeof SUBSCRIPTION_STATUSES];\n\nexport const CRYPTO_PAYMENT_METHOD_ERRORS = {\n APPROVAL_TRANSACTION_TOO_OLD: 'approval_transaction_too_old',\n APPROVAL_TRANSACTION_REVERTED: 'approval_transaction_reverted',\n APPROVAL_TRANSACTION_MAX_VERIFICATION_ATTEMPTS_REACHED:\n 'approval_transaction_max_verification_attempts_reached',\n INSUFFICIENT_BALANCE: 'insufficient_balance',\n INSUFFICIENT_ALLOWANCE: 'insufficient_allowance',\n} as const;\n\nexport type CryptoPaymentMethodError =\n (typeof CRYPTO_PAYMENT_METHOD_ERRORS)[keyof typeof CRYPTO_PAYMENT_METHOD_ERRORS];\n\nexport const MODAL_TYPE = {\n A: 'A',\n B: 'B',\n} as const;\n\nexport type ModalType = (typeof MODAL_TYPE)[keyof typeof MODAL_TYPE];\n\n/** only usd for now */\nexport type Currency = 'usd';\n\nexport type Product = {\n name: ProductType;\n currency: Currency;\n unitAmount: number;\n unitDecimals: number;\n};\n\n// state\nexport type Subscription = {\n id: string;\n products: Product[];\n currentPeriodStart: string; // ISO 8601\n currentPeriodEnd: string; // ISO 8601\n /** is subscription scheduled for cancellation */\n cancelAtPeriodEnd?: boolean;\n status: SubscriptionStatus;\n interval: RecurringInterval;\n paymentMethod: SubscriptionPaymentMethod;\n trialPeriodDays?: number;\n trialStart?: string; // ISO 8601\n trialEnd?: string; // ISO 8601\n /** Crypto payment only: next billing cycle date (e.g after 12 months) */\n endDate?: string; // ISO 8601\n /** The date the subscription was canceled. */\n canceledAt?: string; // ISO 8601\n /** The date the subscription was marked as inactive (paused/past_due/canceled). */\n inactiveAt?: string; // ISO 8601\n /** Whether the user is eligible for support features (priority support and filing claims). True for active subscriptions and inactive subscriptions within grace period. */\n isEligibleForSupport: boolean;\n billingCycles?: number;\n};\n\nexport type SubscriptionCardPaymentMethod = {\n type: Extract<PaymentType, 'card'>;\n card: {\n brand: string;\n /** display brand account for dual brand card */\n displayBrand: string;\n last4: string;\n };\n};\n\nexport type SubscriptionCryptoPaymentMethod = {\n type: Extract<PaymentType, 'crypto'>;\n crypto: {\n payerAddress: Hex;\n chainId: Hex;\n tokenSymbol: string;\n error?: CryptoPaymentMethodError;\n };\n};\n\nexport type SubscriptionPaymentMethod =\n | SubscriptionCardPaymentMethod\n | SubscriptionCryptoPaymentMethod;\n\nexport type GetSubscriptionsResponse = {\n customerId?: string;\n subscriptions: Subscription[];\n trialedProducts: ProductType[];\n /** The last subscription that user has subscribed to if any. */\n lastSubscription?: Subscription;\n};\n\nexport type StartSubscriptionRequest = {\n products: ProductType[];\n isTrialRequested: boolean;\n recurringInterval: RecurringInterval;\n successUrl?: string;\n useTestClock?: boolean;\n};\n\nexport type StartSubscriptionResponse = {\n checkoutSessionUrl: string;\n};\n\nexport type StartCryptoSubscriptionRequest = {\n products: ProductType[];\n isTrialRequested: boolean;\n recurringInterval: RecurringInterval;\n billingCycles: number;\n chainId: Hex;\n payerAddress: Hex;\n /**\n * e.g. \"USDC\"\n */\n tokenSymbol: string;\n rawTransaction: Hex;\n isSponsored?: boolean;\n useTestClock?: boolean;\n};\n\nexport type StartCryptoSubscriptionResponse = {\n subscriptionId: string;\n status: SubscriptionStatus;\n};\n\nexport type AuthUtils = {\n getAccessToken: () => Promise<string>;\n};\n\nexport type ProductPrice = {\n interval: RecurringInterval;\n unitAmount: number; // amount in the smallest unit of the currency, e.g., cents\n unitDecimals: number; // number of decimals for the smallest unit of the currency\n /** only usd for now */\n currency: Currency;\n trialPeriodDays: number;\n minBillingCycles: number;\n};\n\nexport type ProductPricing = {\n name: ProductType;\n prices: ProductPrice[];\n};\n\nexport type TokenPaymentInfo = {\n symbol: string;\n address: Hex;\n decimals: number;\n /**\n * example: {\n usd: '1.0',\n },\n */\n conversionRate: {\n usd: string;\n };\n};\n\nexport type ChainPaymentInfo = {\n chainId: Hex;\n paymentAddress: Hex;\n tokens: TokenPaymentInfo[];\n /**\n * Whether the chain supports sponsorship for the trialed subscription approval transaction.\n * This is used to determine if the user can be sponsored for the gas fees for the trialed subscription approval transaction.\n */\n isSponsorshipSupported?: boolean;\n};\n\nexport type PricingPaymentMethod = {\n type: PaymentType;\n chains?: ChainPaymentInfo[];\n};\n\nexport type PricingResponse = {\n products: ProductPricing[];\n paymentMethods: PricingPaymentMethod[];\n};\n\nexport type GetCryptoApproveTransactionRequest = {\n /**\n * payment chain ID\n */\n chainId: Hex;\n /**\n * Payment token address\n */\n paymentTokenAddress: Hex;\n productType: ProductType;\n interval: RecurringInterval;\n};\n\nexport type GetCryptoApproveTransactionResponse = {\n /**\n * The amount to approve\n * e.g: \"100000000\"\n */\n approveAmount: string;\n /**\n * The contract address (spender)\n */\n paymentAddress: Hex;\n /**\n * The payment token address\n */\n paymentTokenAddress: Hex;\n chainId: Hex;\n};\n\nexport const COHORT_NAMES = {\n POST_TX: 'post_tx',\n WALLET_HOME: 'wallet_home',\n} as const;\n\nexport type CohortName = (typeof COHORT_NAMES)[keyof typeof COHORT_NAMES];\n\nexport const BALANCE_CATEGORIES = {\n RANGE_0_99: '0-99',\n RANGE_100_999: '100-999',\n RANGE_1K_9_9K: '1k-9.9k',\n RANGE_10K_99_9K: '10k-99.9k',\n RANGE_100K_999_9K: '100k-999.9k',\n RANGE_1M_PLUS: '1M+',\n} as const;\n\nexport type BalanceCategory =\n (typeof BALANCE_CATEGORIES)[keyof typeof BALANCE_CATEGORIES];\n\nexport type Cohort = {\n cohort: string;\n eligibilityRate: number; // 0-1 probability of being assigned to this cohort\n priority: number; // lower number = higher priority\n eligible: boolean;\n};\n\nexport type SubscriptionEligibility = {\n product: ProductType;\n canSubscribe: boolean;\n minBalanceUSD: number;\n canViewEntryModal: boolean;\n modalType?: ModalType;\n cohorts: Cohort[];\n assignedCohort: string | null;\n hasAssignedCohortExpired: boolean;\n};\n\nexport const SubscriptionUserEvent = {\n ShieldEntryModalViewed: 'shield_entry_modal_viewed',\n ShieldCohortAssigned: 'shield_cohort_assigned',\n} as const;\n\nexport type SubscriptionUserEventType =\n (typeof SubscriptionUserEvent)[keyof typeof SubscriptionUserEvent];\n\nexport type SubmitUserEventRequest = {\n event: SubscriptionUserEventType;\n cohort?: string;\n};\n\nexport type AssignCohortRequest = {\n cohort: string;\n};\n\nexport type GetSubscriptionsEligibilitiesRequest = {\n balanceCategory?: BalanceCategory;\n};\n\n/**\n * Request object for submitting sponsorship intents.\n */\nexport type SubmitSponsorshipIntentsRequest = {\n chainId: Hex;\n address: Hex;\n products: ProductType[];\n paymentTokenSymbol: string;\n recurringInterval: RecurringInterval;\n billingCycles: number;\n};\n\nexport type SubmitSponsorshipIntentsMethodParams = Pick<\n SubmitSponsorshipIntentsRequest,\n 'chainId' | 'address' | 'products'\n>;\n\nexport type ISubscriptionService = {\n getSubscriptions(): Promise<GetSubscriptionsResponse>;\n cancelSubscription(request: {\n subscriptionId: string;\n }): Promise<Subscription>;\n unCancelSubscription(request: {\n subscriptionId: string;\n }): Promise<Subscription>;\n startSubscriptionWithCard(\n request: StartSubscriptionRequest,\n ): Promise<StartSubscriptionResponse>;\n getBillingPortalUrl(): Promise<BillingPortalResponse>;\n getPricing(): Promise<PricingResponse>;\n startSubscriptionWithCrypto(\n request: StartCryptoSubscriptionRequest,\n ): Promise<StartCryptoSubscriptionResponse>;\n updatePaymentMethodCard(\n request: UpdatePaymentMethodCardRequest,\n ): Promise<UpdatePaymentMethodCardResponse>;\n updatePaymentMethodCrypto(\n request: UpdatePaymentMethodCryptoRequest,\n ): Promise<void>;\n getSubscriptionsEligibilities(\n request?: GetSubscriptionsEligibilitiesRequest,\n ): Promise<SubscriptionEligibility[]>;\n submitUserEvent(request: SubmitUserEventRequest): Promise<void>;\n assignUserToCohort(request: AssignCohortRequest): Promise<void>;\n\n /**\n * Submit sponsorship intents to the Subscription Service backend.\n *\n * This is intended to be used together with the crypto subscription flow.\n * When the user has enabled the smart transaction feature, we will sponsor the gas fees for the subscription approval transaction.\n *\n * @param request - Request object containing the address and products.\n * @example {\n * address: '0x1234567890123456789012345678901234567890',\n * products: [ProductType.Shield],\n * recurringInterval: RecurringInterval.Month,\n * billingCycles: 1,\n * }\n */\n submitSponsorshipIntents(\n request: SubmitSponsorshipIntentsRequest,\n ): Promise<void>;\n};\n\nexport type UpdatePaymentMethodOpts =\n | ({\n paymentType: Extract<PaymentType, 'card'>;\n } & UpdatePaymentMethodCardRequest)\n | ({\n paymentType: Extract<PaymentType, 'crypto'>;\n } & UpdatePaymentMethodCryptoRequest);\n\nexport type UpdatePaymentMethodCardRequest = {\n /**\n * Subscription ID\n */\n subscriptionId: string;\n\n /**\n * Recurring interval\n */\n recurringInterval: RecurringInterval;\n successUrl?: string;\n};\n\nexport type UpdatePaymentMethodCardResponse = {\n redirectUrl: string;\n};\n\nexport type UpdatePaymentMethodCryptoRequest = {\n subscriptionId: string;\n chainId: Hex;\n payerAddress: Hex;\n tokenSymbol: string;\n /**\n * The raw transaction to pay for the subscription\n * Can be empty if retry after topping up balance\n */\n rawTransaction?: Hex;\n recurringInterval: RecurringInterval;\n billingCycles: number;\n};\n\nexport type BillingPortalResponse = {\n url: string;\n};\n\n/**\n * The cached result of last selected payment methods for the user.\n * These details are being cached to be used internally to track the last selected payment method for the user. (e.g. for crypto subscriptions)\n */\nexport type CachedLastSelectedPaymentMethod = {\n type: PaymentType;\n paymentTokenAddress?: Hex;\n paymentTokenSymbol?: string;\n plan: RecurringInterval;\n useTestClock?: boolean;\n};\n"]}
1
+ {"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAEa,QAAA,aAAa,GAAG;IAC3B,MAAM,EAAE,QAAQ;CACR,CAAC;AAIE,QAAA,aAAa,GAAG;IAC3B,MAAM,EAAE,MAAM;IACd,QAAQ,EAAE,QAAQ;CACV,CAAC;AAIE,QAAA,mBAAmB,GAAG;IACjC,KAAK,EAAE,OAAO;IACd,IAAI,EAAE,MAAM;CACJ,CAAC;AAKE,QAAA,qBAAqB,GAAG;IACnC,iBAAiB;IACjB,UAAU,EAAE,YAAY;IACxB,iBAAiB,EAAE,oBAAoB;IACvC,gBAAgB;IAChB,WAAW,EAAE,aAAa;IAC1B,QAAQ,EAAE,UAAU;IACpB,MAAM,EAAE,QAAQ;IAChB,iBAAiB;IACjB,OAAO,EAAE,UAAU;IACnB,MAAM,EAAE,QAAQ;IAChB,mBAAmB;IACnB,QAAQ,EAAE,UAAU;IACpB,gBAAgB;IAChB,MAAM,EAAE,QAAQ;CACR,CAAC;AAKE,QAAA,4BAA4B,GAAG;IAC1C,4BAA4B,EAAE,8BAA8B;IAC5D,6BAA6B,EAAE,+BAA+B;IAC9D,sDAAsD,EACpD,wDAAwD;IAC1D,oBAAoB,EAAE,sBAAsB;IAC5C,sBAAsB,EAAE,wBAAwB;CACxC,CAAC;AAKE,QAAA,UAAU,GAAG;IACxB,CAAC,EAAE,GAAG;IACN,CAAC,EAAE,GAAG;CACE,CAAC;AA4LE,QAAA,YAAY,GAAG;IAC1B,OAAO,EAAE,SAAS;IAClB,WAAW,EAAE,aAAa;CAClB,CAAC;AAIE,QAAA,kBAAkB,GAAG;IAChC,UAAU,EAAE,MAAM;IAClB,aAAa,EAAE,SAAS;IACxB,aAAa,EAAE,SAAS;IACxB,eAAe,EAAE,WAAW;IAC5B,iBAAiB,EAAE,aAAa;IAChC,aAAa,EAAE,KAAK;CACZ,CAAC;AAsBE,QAAA,qBAAqB,GAAG;IACnC,sBAAsB,EAAE,2BAA2B;IACnD,oBAAoB,EAAE,wBAAwB;CACtC,CAAC","sourcesContent":["import type { Hex } from '@metamask/utils';\n\nexport const PRODUCT_TYPES = {\n SHIELD: 'shield',\n} as const;\n\nexport type ProductType = (typeof PRODUCT_TYPES)[keyof typeof PRODUCT_TYPES];\n\nexport const PAYMENT_TYPES = {\n byCard: 'card',\n byCrypto: 'crypto',\n} as const;\n\nexport type PaymentType = (typeof PAYMENT_TYPES)[keyof typeof PAYMENT_TYPES];\n\nexport const RECURRING_INTERVALS = {\n month: 'month',\n year: 'year',\n} as const;\n\nexport type RecurringInterval =\n (typeof RECURRING_INTERVALS)[keyof typeof RECURRING_INTERVALS];\n\nexport const SUBSCRIPTION_STATUSES = {\n // Initial states\n incomplete: 'incomplete',\n incompleteExpired: 'incomplete_expired',\n // Active states\n provisional: 'provisional',\n trialing: 'trialing',\n active: 'active',\n // Payment issues\n pastDue: 'past_due',\n unpaid: 'unpaid',\n // Cancelled states\n canceled: 'canceled',\n // Paused states\n paused: 'paused',\n} as const;\n\nexport type SubscriptionStatus =\n (typeof SUBSCRIPTION_STATUSES)[keyof typeof SUBSCRIPTION_STATUSES];\n\nexport const CRYPTO_PAYMENT_METHOD_ERRORS = {\n APPROVAL_TRANSACTION_TOO_OLD: 'approval_transaction_too_old',\n APPROVAL_TRANSACTION_REVERTED: 'approval_transaction_reverted',\n APPROVAL_TRANSACTION_MAX_VERIFICATION_ATTEMPTS_REACHED:\n 'approval_transaction_max_verification_attempts_reached',\n INSUFFICIENT_BALANCE: 'insufficient_balance',\n INSUFFICIENT_ALLOWANCE: 'insufficient_allowance',\n} as const;\n\nexport type CryptoPaymentMethodError =\n (typeof CRYPTO_PAYMENT_METHOD_ERRORS)[keyof typeof CRYPTO_PAYMENT_METHOD_ERRORS];\n\nexport const MODAL_TYPE = {\n A: 'A',\n B: 'B',\n} as const;\n\nexport type ModalType = (typeof MODAL_TYPE)[keyof typeof MODAL_TYPE];\n\n/** only usd for now */\nexport type Currency = 'usd';\n\nexport type Product = {\n name: ProductType;\n currency: Currency;\n unitAmount: number;\n unitDecimals: number;\n};\n\n// state\nexport type Subscription = {\n id: string;\n products: Product[];\n currentPeriodStart: string; // ISO 8601\n currentPeriodEnd: string; // ISO 8601\n /** is subscription scheduled for cancellation */\n cancelAtPeriodEnd?: boolean;\n status: SubscriptionStatus;\n interval: RecurringInterval;\n paymentMethod: SubscriptionPaymentMethod;\n trialPeriodDays?: number;\n trialStart?: string; // ISO 8601\n trialEnd?: string; // ISO 8601\n /** Crypto payment only: next billing cycle date (e.g after 12 months) */\n endDate?: string; // ISO 8601\n /** The date the subscription was canceled. */\n canceledAt?: string; // ISO 8601\n /** The date the subscription was marked as inactive (paused/past_due/canceled). */\n inactiveAt?: string; // ISO 8601\n /** Whether the user is eligible for support features (priority support and filing claims). True for active subscriptions and inactive subscriptions within grace period. */\n isEligibleForSupport: boolean;\n billingCycles?: number;\n};\n\nexport type SubscriptionCardPaymentMethod = {\n type: Extract<PaymentType, 'card'>;\n card: {\n brand: string;\n /** display brand account for dual brand card */\n displayBrand: string;\n last4: string;\n };\n};\n\nexport type SubscriptionCryptoPaymentMethod = {\n type: Extract<PaymentType, 'crypto'>;\n crypto: {\n payerAddress: Hex;\n chainId: Hex;\n tokenSymbol: string;\n error?: CryptoPaymentMethodError;\n };\n};\n\nexport type SubscriptionPaymentMethod =\n | SubscriptionCardPaymentMethod\n | SubscriptionCryptoPaymentMethod;\n\nexport type GetSubscriptionsResponse = {\n customerId?: string;\n subscriptions: Subscription[];\n trialedProducts: ProductType[];\n /** The last subscription that user has subscribed to if any. */\n lastSubscription?: Subscription;\n};\n\nexport type StartSubscriptionRequest = {\n products: ProductType[];\n isTrialRequested: boolean;\n recurringInterval: RecurringInterval;\n successUrl?: string;\n useTestClock?: boolean;\n};\n\nexport type StartSubscriptionResponse = {\n checkoutSessionUrl: string;\n};\n\nexport type StartCryptoSubscriptionRequest = {\n products: ProductType[];\n isTrialRequested: boolean;\n recurringInterval: RecurringInterval;\n billingCycles: number;\n chainId: Hex;\n payerAddress: Hex;\n /**\n * e.g. \"USDC\"\n */\n tokenSymbol: string;\n rawTransaction: Hex;\n isSponsored?: boolean;\n useTestClock?: boolean;\n};\n\nexport type StartCryptoSubscriptionResponse = {\n subscriptionId: string;\n status: SubscriptionStatus;\n};\n\nexport type AuthUtils = {\n getAccessToken: () => Promise<string>;\n};\n\nexport type ProductPrice = {\n interval: RecurringInterval;\n unitAmount: number; // amount in the smallest unit of the currency, e.g., cents\n unitDecimals: number; // number of decimals for the smallest unit of the currency\n /** only usd for now */\n currency: Currency;\n trialPeriodDays: number;\n minBillingCycles: number;\n};\n\nexport type ProductPricing = {\n name: ProductType;\n prices: ProductPrice[];\n};\n\nexport type TokenPaymentInfo = {\n symbol: string;\n address: Hex;\n decimals: number;\n /**\n * example: {\n usd: '1.0',\n },\n */\n conversionRate: {\n usd: string;\n };\n};\n\nexport type ChainPaymentInfo = {\n chainId: Hex;\n paymentAddress: Hex;\n tokens: TokenPaymentInfo[];\n /**\n * Whether the chain supports sponsorship for the trialed subscription approval transaction.\n * This is used to determine if the user can be sponsored for the gas fees for the trialed subscription approval transaction.\n */\n isSponsorshipSupported?: boolean;\n};\n\nexport type PricingPaymentMethod = {\n type: PaymentType;\n chains?: ChainPaymentInfo[];\n};\n\nexport type PricingResponse = {\n products: ProductPricing[];\n paymentMethods: PricingPaymentMethod[];\n};\n\nexport type GetCryptoApproveTransactionRequest = {\n /**\n * payment chain ID\n */\n chainId: Hex;\n /**\n * Payment token address\n */\n paymentTokenAddress: Hex;\n productType: ProductType;\n interval: RecurringInterval;\n};\n\nexport type GetCryptoApproveTransactionResponse = {\n /**\n * The amount to approve\n * e.g: \"100000000\"\n */\n approveAmount: string;\n /**\n * The contract address (spender)\n */\n paymentAddress: Hex;\n /**\n * The payment token address\n */\n paymentTokenAddress: Hex;\n chainId: Hex;\n};\n\nexport const COHORT_NAMES = {\n POST_TX: 'post_tx',\n WALLET_HOME: 'wallet_home',\n} as const;\n\nexport type CohortName = (typeof COHORT_NAMES)[keyof typeof COHORT_NAMES];\n\nexport const BALANCE_CATEGORIES = {\n RANGE_0_99: '0-99',\n RANGE_100_999: '100-999',\n RANGE_1K_9_9K: '1k-9.9k',\n RANGE_10K_99_9K: '10k-99.9k',\n RANGE_100K_999_9K: '100k-999.9k',\n RANGE_1M_PLUS: '1M+',\n} as const;\n\nexport type BalanceCategory =\n (typeof BALANCE_CATEGORIES)[keyof typeof BALANCE_CATEGORIES];\n\nexport type Cohort = {\n cohort: string;\n eligibilityRate: number; // 0-1 probability of being assigned to this cohort\n priority: number; // lower number = higher priority\n eligible: boolean;\n};\n\nexport type SubscriptionEligibility = {\n product: ProductType;\n canSubscribe: boolean;\n canViewEntryModal: boolean;\n modalType?: ModalType;\n cohorts: Cohort[];\n assignedCohort: string | null;\n hasAssignedCohortExpired: boolean;\n};\n\nexport const SubscriptionUserEvent = {\n ShieldEntryModalViewed: 'shield_entry_modal_viewed',\n ShieldCohortAssigned: 'shield_cohort_assigned',\n} as const;\n\nexport type SubscriptionUserEventType =\n (typeof SubscriptionUserEvent)[keyof typeof SubscriptionUserEvent];\n\nexport type SubmitUserEventRequest = {\n event: SubscriptionUserEventType;\n cohort?: string;\n};\n\nexport type AssignCohortRequest = {\n cohort: string;\n};\n\nexport type GetSubscriptionsEligibilitiesRequest = {\n balanceCategory?: BalanceCategory;\n};\n\n/**\n * Request object for submitting sponsorship intents.\n */\nexport type SubmitSponsorshipIntentsRequest = {\n chainId: Hex;\n address: Hex;\n products: ProductType[];\n paymentTokenSymbol: string;\n recurringInterval: RecurringInterval;\n billingCycles: number;\n};\n\nexport type SubmitSponsorshipIntentsMethodParams = Pick<\n SubmitSponsorshipIntentsRequest,\n 'chainId' | 'address' | 'products'\n>;\n\nexport type ISubscriptionService = {\n getSubscriptions(): Promise<GetSubscriptionsResponse>;\n cancelSubscription(request: {\n subscriptionId: string;\n }): Promise<Subscription>;\n unCancelSubscription(request: {\n subscriptionId: string;\n }): Promise<Subscription>;\n startSubscriptionWithCard(\n request: StartSubscriptionRequest,\n ): Promise<StartSubscriptionResponse>;\n getBillingPortalUrl(): Promise<BillingPortalResponse>;\n getPricing(): Promise<PricingResponse>;\n startSubscriptionWithCrypto(\n request: StartCryptoSubscriptionRequest,\n ): Promise<StartCryptoSubscriptionResponse>;\n updatePaymentMethodCard(\n request: UpdatePaymentMethodCardRequest,\n ): Promise<UpdatePaymentMethodCardResponse>;\n updatePaymentMethodCrypto(\n request: UpdatePaymentMethodCryptoRequest,\n ): Promise<void>;\n getSubscriptionsEligibilities(\n request?: GetSubscriptionsEligibilitiesRequest,\n ): Promise<SubscriptionEligibility[]>;\n submitUserEvent(request: SubmitUserEventRequest): Promise<void>;\n assignUserToCohort(request: AssignCohortRequest): Promise<void>;\n\n /**\n * Submit sponsorship intents to the Subscription Service backend.\n *\n * This is intended to be used together with the crypto subscription flow.\n * When the user has enabled the smart transaction feature, we will sponsor the gas fees for the subscription approval transaction.\n *\n * @param request - Request object containing the address and products.\n * @example {\n * address: '0x1234567890123456789012345678901234567890',\n * products: [ProductType.Shield],\n * recurringInterval: RecurringInterval.Month,\n * billingCycles: 1,\n * }\n */\n submitSponsorshipIntents(\n request: SubmitSponsorshipIntentsRequest,\n ): Promise<void>;\n};\n\nexport type UpdatePaymentMethodOpts =\n | ({\n paymentType: Extract<PaymentType, 'card'>;\n } & UpdatePaymentMethodCardRequest)\n | ({\n paymentType: Extract<PaymentType, 'crypto'>;\n } & UpdatePaymentMethodCryptoRequest);\n\nexport type UpdatePaymentMethodCardRequest = {\n /**\n * Subscription ID\n */\n subscriptionId: string;\n\n /**\n * Recurring interval\n */\n recurringInterval: RecurringInterval;\n successUrl?: string;\n};\n\nexport type UpdatePaymentMethodCardResponse = {\n redirectUrl: string;\n};\n\nexport type UpdatePaymentMethodCryptoRequest = {\n subscriptionId: string;\n chainId: Hex;\n payerAddress: Hex;\n tokenSymbol: string;\n /**\n * The raw transaction to pay for the subscription\n * Can be empty if retry after topping up balance\n */\n rawTransaction?: Hex;\n recurringInterval: RecurringInterval;\n billingCycles: number;\n};\n\nexport type BillingPortalResponse = {\n url: string;\n};\n\n/**\n * The cached result of last selected payment methods for the user.\n * These details are being cached to be used internally to track the last selected payment method for the user. (e.g. for crypto subscriptions)\n */\nexport type CachedLastSelectedPaymentMethod = {\n type: PaymentType;\n paymentTokenAddress?: Hex;\n paymentTokenSymbol?: string;\n plan: RecurringInterval;\n useTestClock?: boolean;\n};\n"]}
package/dist/types.d.cts CHANGED
@@ -222,7 +222,6 @@ export type Cohort = {
222
222
  export type SubscriptionEligibility = {
223
223
  product: ProductType;
224
224
  canSubscribe: boolean;
225
- minBalanceUSD: number;
226
225
  canViewEnt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ProductType;
224
224
  canSubscribe: boolean;
225
- minBalanceUSD: number;
226
225
  canViewEntryModal: boolean;
227
226
  modalType?: ModalType;
228
227
  cohorts: Cohort[];
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAE3C,eAAO,MAAM,aAAa;;CAEhB,CAAC;AAEX,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,OAAO,aAAa,CAAC,CAAC;AAE7E,eAAO,MAAM,aAAa;;;CAGhB,CAAC;AAEX,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,OAAO,aAAa,CAAC,CAAC;AAE7E,eAAO,MAAM,mBAAmB;;;CAGtB,CAAC;AAEX,MAAM,MAAM,iBAAiB,GAC3B,CAAC,OAAO,mBAAmB,CAAC,CAAC,MAAM,OAAO,mBAAmB,CAAC,CAAC;AAEjE,eAAO,MAAM,qBAAqB;;;;;;;;;;CAexB,CAAC;AAEX,MAAM,MAAM,kBAAkB,GAC5B,CAAC,OAAO,qBAAqB,CAAC,CAAC,MAAM,OAAO,qBAAqB,CAAC,CAAC;AAErE,eAAO,MAAM,4BAA4B;;;;;;CAO/B,CAAC;AAEX,MAAM,MAAM,wBAAwB,GAClC,CAAC,OAAO,4BAA4B,CAAC,CAAC,MAAM,OAAO,4BAA4B,CAAC,CAAC;AAEnF,eAAO,MAAM,UAAU;;;CAGb,CAAC;AAEX,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,UAAU,CAAC,CAAC,MAAM,OAAO,UAAU,CAAC,CAAC;AAErE,uBAAuB;AACvB,MAAM,MAAM,QAAQ,GAAG,KAAK,CAAC;AAE7B,MAAM,MAAM,OAAO,GAAG;IACpB,IAAI,EAAE,WAAW,CAAC;IAClB,QAAQ,EAAE,QAAQ,CAAC;IACnB,UAAU,EAAE,MAAM,C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Aa,EAAE,KAAK;CACZ,CAAC;AAuBX,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,sBAAsB,EAAE,2BAA2B;IACnD,oBAAoB,EAAE,wBAAwB;CACtC,CAAC","sourcesContent":["import type { Hex } from '@metamask/utils';\n\nexport const PRODUCT_TYPES = {\n SHIELD: 'shield',\n} as const;\n\nexport type ProductType = (typeof PRODUCT_TYPES)[keyof typeof PRODUCT_TYPES];\n\nexport const PAYMENT_TYPES = {\n byCard: 'card',\n byCrypto: 'crypto',\n} as const;\n\nexport type PaymentType = (typeof PAYMENT_TYPES)[keyof typeof PAYMENT_TYPES];\n\nexport const RECURRING_INTERVALS = {\n month: 'month',\n year: 'year',\n} as const;\n\nexport type RecurringInterval =\n (typeof RECURRING_INTERVALS)[keyof typeof RECURRING_INTERVALS];\n\nexport const SUBSCRIPTION_STATUSES = {\n // Initial states\n incomplete: 'incomplete',\n incompleteExpired: 'incomplete_expired',\n // Active states\n provisional: 'provisional',\n trialing: 'trialing',\n active: 'active',\n // Payment issues\n pastDue: 'past_due',\n unpaid: 'unpaid',\n // Cancelled states\n canceled: 'canceled',\n // Paused states\n paused: 'paused',\n} as const;\n\nexport type SubscriptionStatus =\n (typeof SUBSCRIPTION_STATUSES)[keyof typeof SUBSCRIPTION_STATUSES];\n\nexport const CRYPTO_PAYMENT_METHOD_ERRORS = {\n APPROVAL_TRANSACTION_TOO_OLD: 'approval_transaction_too_old',\n APPROVAL_TRANSACTION_REVERTED: 'approval_transaction_reverted',\n APPROVAL_TRANSACTION_MAX_VERIFICATION_ATTEMPTS_REACHED:\n 'approval_transaction_max_verification_attempts_reached',\n INSUFFICIENT_BALANCE: 'insufficient_balance',\n INSUFFICIENT_ALLOWANCE: 'insufficient_allowance',\n} as const;\n\nexport type CryptoPaymentMethodError =\n (typeof CRYPTO_PAYMENT_METHOD_ERRORS)[keyof typeof CRYPTO_PAYMENT_METHOD_ERRORS];\n\nexport const MODAL_TYPE = {\n A: 'A',\n B: 'B',\n} as const;\n\nexport type ModalType = (typeof MODAL_TYPE)[keyof typeof MODAL_TYPE];\n\n/** only usd for now */\nexport type Currency = 'usd';\n\nexport type Product = {\n name: ProductType;\n currency: Currency;\n unitAmount: number;\n unitDecimals: number;\n};\n\n// state\nexport type Subscription = {\n id: string;\n products: Product[];\n currentPeriodStart: string; // ISO 8601\n currentPeriodEnd: string; // ISO 8601\n /** is subscription scheduled for cancellation */\n cancelAtPeriodEnd?: boolean;\n status: SubscriptionStatus;\n interval: RecurringInterval;\n paymentMethod: SubscriptionPaymentMethod;\n trialPeriodDays?: number;\n trialStart?: string; // ISO 8601\n trialEnd?: string; // ISO 8601\n /** Crypto payment only: next billing cycle date (e.g after 12 months) */\n endDate?: string; // ISO 8601\n /** The date the subscription was canceled. */\n canceledAt?: string; // ISO 8601\n /** The date the subscription was marked as inactive (paused/past_due/canceled). */\n inactiveAt?: string; // ISO 8601\n /** Whether the user is eligible for support features (priority support and filing claims). True for active subscriptions and inactive subscriptions within grace period. */\n isEligibleForSupport: boolean;\n billingCycles?: number;\n};\n\nexport type SubscriptionCardPaymentMethod = {\n type: Extract<PaymentType, 'card'>;\n card: {\n brand: string;\n /** display brand account for dual brand card */\n displayBrand: string;\n last4: string;\n };\n};\n\nexport type SubscriptionCryptoPaymentMethod = {\n type: Extract<PaymentType, 'crypto'>;\n crypto: {\n payerAddress: Hex;\n chainId: Hex;\n tokenSymbol: string;\n error?: CryptoPaymentMethodError;\n };\n};\n\nexport type SubscriptionPaymentMethod =\n | SubscriptionCardPaymentMethod\n | SubscriptionCryptoPaymentMethod;\n\nexport type GetSubscriptionsResponse = {\n customerId?: string;\n subscriptions: Subscription[];\n trialedProducts: ProductType[];\n /** The last subscription that user has subscribed to if any. */\n lastSubscription?: Subscription;\n};\n\nexport type StartSubscriptionRequest = {\n products: ProductType[];\n isTrialRequested: boolean;\n recurringInterval: RecurringInterval;\n successUrl?: string;\n useTestClock?: boolean;\n};\n\nexport type StartSubscriptionResponse = {\n checkoutSessionUrl: string;\n};\n\nexport type StartCryptoSubscriptionRequest = {\n products: ProductType[];\n isTrialRequested: boolean;\n recurringInterval: RecurringInterval;\n billingCycles: number;\n chainId: Hex;\n payerAddress: Hex;\n /**\n * e.g. \"USDC\"\n */\n tokenSymbol: string;\n rawTransaction: Hex;\n isSponsored?: boolean;\n useTestClock?: boolean;\n};\n\nexport type StartCryptoSubscriptionResponse = {\n subscriptionId: string;\n status: SubscriptionStatus;\n};\n\nexport type AuthUtils = {\n getAccessToken: () => Promise<string>;\n};\n\nexport type ProductPrice = {\n interval: RecurringInterval;\n unitAmount: number; // amount in the smallest unit of the currency, e.g., cents\n unitDecimals: number; // number of decimals for the smallest unit of the currency\n /** only usd for now */\n currency: Currency;\n trialPeriodDays: number;\n minBillingCycles: number;\n};\n\nexport type ProductPricing = {\n name: ProductType;\n prices: ProductPrice[];\n};\n\nexport type TokenPaymentInfo = {\n symbol: string;\n address: Hex;\n decimals: number;\n /**\n * example: {\n usd: '1.0',\n },\n */\n conversionRate: {\n usd: string;\n };\n};\n\nexport type ChainPaymentInfo = {\n chainId: Hex;\n paymentAddress: Hex;\n tokens: TokenPaymentInfo[];\n /**\n * Whether the chain supports sponsorship for the trialed subscription approval transaction.\n * This is used to determine if the user can be sponsored for the gas fees for the trialed subscription approval transaction.\n */\n isSponsorshipSupported?: boolean;\n};\n\nexport type PricingPaymentMethod = {\n type: PaymentType;\n chains?: ChainPaymentInfo[];\n};\n\nexport type PricingResponse = {\n products: ProductPricing[];\n paymentMethods: PricingPaymentMethod[];\n};\n\nexport type GetCryptoApproveTransactionRequest = {\n /**\n * payment chain ID\n */\n chainId: Hex;\n /**\n * Payment token address\n */\n paymentTokenAddress: Hex;\n productType: ProductType;\n interval: RecurringInterval;\n};\n\nexport type GetCryptoApproveTransactionResponse = {\n /**\n * The amount to approve\n * e.g: \"100000000\"\n */\n approveAmount: string;\n /**\n * The contract address (spender)\n */\n paymentAddress: Hex;\n /**\n * The payment token address\n */\n paymentTokenAddress: Hex;\n chainId: Hex;\n};\n\nexport const COHORT_NAMES = {\n POST_TX: 'post_tx',\n WALLET_HOME: 'wallet_home',\n} as const;\n\nexport type CohortName = (typeof COHORT_NAMES)[keyof typeof COHORT_NAMES];\n\nexport const BALANCE_CATEGORIES = {\n RANGE_0_99: '0-99',\n RANGE_100_999: '100-999',\n RANGE_1K_9_9K: '1k-9.9k',\n RANGE_10K_99_9K: '10k-99.9k',\n RANGE_100K_999_9K: '100k-999.9k',\n RANGE_1M_PLUS: '1M+',\n} as const;\n\nexport type BalanceCategory =\n (typeof BALANCE_CATEGORIES)[keyof typeof BALANCE_CATEGORIES];\n\nexport type Cohort = {\n cohort: string;\n eligibilityRate: number; // 0-1 probability of being assigned to this cohort\n priority: number; // lower number = higher priority\n eligible: boolean;\n};\n\nexport type SubscriptionEligibility = {\n product: ProductType;\n canSubscribe: boolean;\n minBalanceUSD: number;\n canViewEntryModal: boolean;\n modalType?: ModalType;\n cohorts: Cohort[];\n assignedCohort: string | null;\n hasAssignedCohortExpired: boolean;\n};\n\nexport const SubscriptionUserEvent = {\n ShieldEntryModalViewed: 'shield_entry_modal_viewed',\n ShieldCohortAssigned: 'shield_cohort_assigned',\n} as const;\n\nexport type SubscriptionUserEventType =\n (typeof SubscriptionUserEvent)[keyof typeof SubscriptionUserEvent];\n\nexport type SubmitUserEventRequest = {\n event: SubscriptionUserEventType;\n cohort?: string;\n};\n\nexport type AssignCohortRequest = {\n cohort: string;\n};\n\nexport type GetSubscriptionsEligibilitiesRequest = {\n balanceCategory?: BalanceCategory;\n};\n\n/**\n * Request object for submitting sponsorship intents.\n */\nexport type SubmitSponsorshipIntentsRequest = {\n chainId: Hex;\n address: Hex;\n products: ProductType[];\n paymentTokenSymbol: string;\n recurringInterval: RecurringInterval;\n billingCycles: number;\n};\n\nexport type SubmitSponsorshipIntentsMethodParams = Pick<\n SubmitSponsorshipIntentsRequest,\n 'chainId' | 'address' | 'products'\n>;\n\nexport type ISubscriptionService = {\n getSubscriptions(): Promise<GetSubscriptionsResponse>;\n cancelSubscription(request: {\n subscriptionId: string;\n }): Promise<Subscription>;\n unCancelSubscription(request: {\n subscriptionId: string;\n }): Promise<Subscription>;\n startSubscriptionWithCard(\n request: StartSubscriptionRequest,\n ): Promise<StartSubscriptionResponse>;\n getBillingPortalUrl(): Promise<BillingPortalResponse>;\n getPricing(): Promise<PricingResponse>;\n startSubscriptionWithCrypto(\n request: StartCryptoSubscriptionRequest,\n ): Promise<StartCryptoSubscriptionResponse>;\n updatePaymentMethodCard(\n request: UpdatePaymentMethodCardRequest,\n ): Promise<UpdatePaymentMethodCardResponse>;\n updatePaymentMethodCrypto(\n request: UpdatePaymentMethodCryptoRequest,\n ): Promise<void>;\n getSubscriptionsEligibilities(\n request?: GetSubscriptionsEligibilitiesRequest,\n ): Promise<SubscriptionEligibility[]>;\n submitUserEvent(request: SubmitUserEventRequest): Promise<void>;\n assignUserToCohort(request: AssignCohortRequest): Promise<void>;\n\n /**\n * Submit sponsorship intents to the Subscription Service backend.\n *\n * This is intended to be used together with the crypto subscription flow.\n * When the user has enabled the smart transaction feature, we will sponsor the gas fees for the subscription approval transaction.\n *\n * @param request - Request object containing the address and products.\n * @example {\n * address: '0x1234567890123456789012345678901234567890',\n * products: [ProductType.Shield],\n * recurringInterval: RecurringInterval.Month,\n * billingCycles: 1,\n * }\n */\n submitSponsorshipIntents(\n request: SubmitSponsorshipIntentsRequest,\n ): Promise<void>;\n};\n\nexport type UpdatePaymentMethodOpts =\n | ({\n paymentType: Extract<PaymentType, 'card'>;\n } & UpdatePaymentMethodCardRequest)\n | ({\n paymentType: Extract<PaymentType, 'crypto'>;\n } & UpdatePaymentMethodCryptoRequest);\n\nexport type UpdatePaymentMethodCardRequest = {\n /**\n * Subscription ID\n */\n subscriptionId: string;\n\n /**\n * Recurring interval\n */\n recurringInterval: RecurringInterval;\n successUrl?: string;\n};\n\nexport type UpdatePaymentMethodCardResponse = {\n redirectUrl: string;\n};\n\nexport type UpdatePaymentMethodCryptoRequest = {\n subscriptionId: string;\n chainId: Hex;\n payerAddress: Hex;\n tokenSymbol: string;\n /**\n * The raw transaction to pay for the subscription\n * Can be empty if retry after topping up balance\n */\n rawTransaction?: Hex;\n recurringInterval: RecurringInterval;\n billingCycles: number;\n};\n\nexport type BillingPortalResponse = {\n url: string;\n};\n\n/**\n * The cached result of last selected payment methods for the user.\n * These details are being cached to be used internally to track the last selected payment method for the user. (e.g. for crypto subscriptions)\n */\nexport type CachedLastSelectedPaymentMethod = {\n type: PaymentType;\n paymentTokenAddress?: Hex;\n paymentTokenSymbol?: string;\n plan: RecurringInterval;\n useTestClock?: boolean;\n};\n"]}
1
+ {"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,MAAM,EAAE,QAAQ;CACR,CAAC;AAIX,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,MAAM,EAAE,MAAM;IACd,QAAQ,EAAE,QAAQ;CACV,CAAC;AAIX,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,KAAK,EAAE,OAAO;IACd,IAAI,EAAE,MAAM;CACJ,CAAC;AAKX,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,iBAAiB;IACjB,UAAU,EAAE,YAAY;IACxB,iBAAiB,EAAE,oBAAoB;IACvC,gBAAgB;IAChB,WAAW,EAAE,aAAa;IAC1B,QAAQ,EAAE,UAAU;IACpB,MAAM,EAAE,QAAQ;IAChB,iBAAiB;IACjB,OAAO,EAAE,UAAU;IACnB,MAAM,EAAE,QAAQ;IAChB,mBAAmB;IACnB,QAAQ,EAAE,UAAU;IACpB,gBAAgB;IAChB,MAAM,EAAE,QAAQ;CACR,CAAC;AAKX,MAAM,CAAC,MAAM,4BAA4B,GAAG;IAC1C,4BAA4B,EAAE,8BAA8B;IAC5D,6BAA6B,EAAE,+BAA+B;IAC9D,sDAAsD,EACpD,wDAAwD;IAC1D,oBAAoB,EAAE,sBAAsB;IAC5C,sBAAsB,EAAE,wBAAwB;CACxC,CAAC;AAKX,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,CAAC,EAAE,GAAG;IACN,CAAC,EAAE,GAAG;CACE,CAAC;AA4LX,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,OAAO,EAAE,SAAS;IAClB,WAAW,EAAE,aAAa;CAClB,CAAC;AAIX,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,UAAU,EAAE,MAAM;IAClB,aAAa,EAAE,SAAS;IACxB,aAAa,EAAE,SAAS;IACxB,eAAe,EAAE,WAAW;IAC5B,iBAAiB,EAAE,aAAa;IAChC,aAAa,EAAE,KAAK;CACZ,CAAC;AAsBX,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,sBAAsB,EAAE,2BAA2B;IACnD,oBAAoB,EAAE,wBAAwB;CACtC,CAAC","sourcesContent":["import type { Hex } from '@metamask/utils';\n\nexport const PRODUCT_TYPES = {\n SHIELD: 'shield',\n} as const;\n\nexport type ProductType = (typeof PRODUCT_TYPES)[keyof typeof PRODUCT_TYPES];\n\nexport const PAYMENT_TYPES = {\n byCard: 'card',\n byCrypto: 'crypto',\n} as const;\n\nexport type PaymentType = (typeof PAYMENT_TYPES)[keyof typeof PAYMENT_TYPES];\n\nexport const RECURRING_INTERVALS = {\n month: 'month',\n year: 'year',\n} as const;\n\nexport type RecurringInterval =\n (typeof RECURRING_INTERVALS)[keyof typeof RECURRING_INTERVALS];\n\nexport const SUBSCRIPTION_STATUSES = {\n // Initial states\n incomplete: 'incomplete',\n incompleteExpired: 'incomplete_expired',\n // Active states\n provisional: 'provisional',\n trialing: 'trialing',\n active: 'active',\n // Payment issues\n pastDue: 'past_due',\n unpaid: 'unpaid',\n // Cancelled states\n canceled: 'canceled',\n // Paused states\n paused: 'paused',\n} as const;\n\nexport type SubscriptionStatus =\n (typeof SUBSCRIPTION_STATUSES)[keyof typeof SUBSCRIPTION_STATUSES];\n\nexport const CRYPTO_PAYMENT_METHOD_ERRORS = {\n APPROVAL_TRANSACTION_TOO_OLD: 'approval_transaction_too_old',\n APPROVAL_TRANSACTION_REVERTED: 'approval_transaction_reverted',\n APPROVAL_TRANSACTION_MAX_VERIFICATION_ATTEMPTS_REACHED:\n 'approval_transaction_max_verification_attempts_reached',\n INSUFFICIENT_BALANCE: 'insufficient_balance',\n INSUFFICIENT_ALLOWANCE: 'insufficient_allowance',\n} as const;\n\nexport type CryptoPaymentMethodError =\n (typeof CRYPTO_PAYMENT_METHOD_ERRORS)[keyof typeof CRYPTO_PAYMENT_METHOD_ERRORS];\n\nexport const MODAL_TYPE = {\n A: 'A',\n B: 'B',\n} as const;\n\nexport type ModalType = (typeof MODAL_TYPE)[keyof typeof MODAL_TYPE];\n\n/** only usd for now */\nexport type Currency = 'usd';\n\nexport type Product = {\n name: ProductType;\n currency: Currency;\n unitAmount: number;\n unitDecimals: number;\n};\n\n// state\nexport type Subscription = {\n id: string;\n products: Product[];\n currentPeriodStart: string; // ISO 8601\n currentPeriodEnd: string; // ISO 8601\n /** is subscription scheduled for cancellation */\n cancelAtPeriodEnd?: boolean;\n status: SubscriptionStatus;\n interval: RecurringInterval;\n paymentMethod: SubscriptionPaymentMethod;\n trialPeriodDays?: number;\n trialStart?: string; // ISO 8601\n trialEnd?: string; // ISO 8601\n /** Crypto payment only: next billing cycle date (e.g after 12 months) */\n endDate?: string; // ISO 8601\n /** The date the subscription was canceled. */\n canceledAt?: string; // ISO 8601\n /** The date the subscription was marked as inactive (paused/past_due/canceled). */\n inactiveAt?: string; // ISO 8601\n /** Whether the user is eligible for support features (priority support and filing claims). True for active subscriptions and inactive subscriptions within grace period. */\n isEligibleForSupport: boolean;\n billingCycles?: number;\n};\n\nexport type SubscriptionCardPaymentMethod = {\n type: Extract<PaymentType, 'card'>;\n card: {\n brand: string;\n /** display brand account for dual brand card */\n displayBrand: string;\n last4: string;\n };\n};\n\nexport type SubscriptionCryptoPaymentMethod = {\n type: Extract<PaymentType, 'crypto'>;\n crypto: {\n payerAddress: Hex;\n chainId: Hex;\n tokenSymbol: string;\n error?: CryptoPaymentMethodError;\n };\n};\n\nexport type SubscriptionPaymentMethod =\n | SubscriptionCardPaymentMethod\n | SubscriptionCryptoPaymentMethod;\n\nexport type GetSubscriptionsResponse = {\n customerId?: string;\n subscriptions: Subscription[];\n trialedProducts: ProductType[];\n /** The last subscription that user has subscribed to if any. */\n lastSubscription?: Subscription;\n};\n\nexport type StartSubscriptionRequest = {\n products: ProductType[];\n isTrialRequested: boolean;\n recurringInterval: RecurringInterval;\n successUrl?: string;\n useTestClock?: boolean;\n};\n\nexport type StartSubscriptionResponse = {\n checkoutSessionUrl: string;\n};\n\nexport type StartCryptoSubscriptionRequest = {\n products: ProductType[];\n isTrialRequested: boolean;\n recurringInterval: RecurringInterval;\n billingCycles: number;\n chainId: Hex;\n payerAddress: Hex;\n /**\n * e.g. \"USDC\"\n */\n tokenSymbol: string;\n rawTransaction: Hex;\n isSponsored?: boolean;\n useTestClock?: boolean;\n};\n\nexport type StartCryptoSubscriptionResponse = {\n subscriptionId: string;\n status: SubscriptionStatus;\n};\n\nexport type AuthUtils = {\n getAccessToken: () => Promise<string>;\n};\n\nexport type ProductPrice = {\n interval: RecurringInterval;\n unitAmount: number; // amount in the smallest unit of the currency, e.g., cents\n unitDecimals: number; // number of decimals for the smallest unit of the currency\n /** only usd for now */\n currency: Currency;\n trialPeriodDays: number;\n minBillingCycles: number;\n};\n\nexport type ProductPricing = {\n name: ProductType;\n prices: ProductPrice[];\n};\n\nexport type TokenPaymentInfo = {\n symbol: string;\n address: Hex;\n decimals: number;\n /**\n * example: {\n usd: '1.0',\n },\n */\n conversionRate: {\n usd: string;\n };\n};\n\nexport type ChainPaymentInfo = {\n chainId: Hex;\n paymentAddress: Hex;\n tokens: TokenPaymentInfo[];\n /**\n * Whether the chain supports sponsorship for the trialed subscription approval transaction.\n * This is used to determine if the user can be sponsored for the gas fees for the trialed subscription approval transaction.\n */\n isSponsorshipSupported?: boolean;\n};\n\nexport type PricingPaymentMethod = {\n type: PaymentType;\n chains?: ChainPaymentInfo[];\n};\n\nexport type PricingResponse = {\n products: ProductPricing[];\n paymentMethods: PricingPaymentMethod[];\n};\n\nexport type GetCryptoApproveTransactionRequest = {\n /**\n * payment chain ID\n */\n chainId: Hex;\n /**\n * Payment token address\n */\n paymentTokenAddress: Hex;\n productType: ProductType;\n interval: RecurringInterval;\n};\n\nexport type GetCryptoApproveTransactionResponse = {\n /**\n * The amount to approve\n * e.g: \"100000000\"\n */\n approveAmount: string;\n /**\n * The contract address (spender)\n */\n paymentAddress: Hex;\n /**\n * The payment token address\n */\n paymentTokenAddress: Hex;\n chainId: Hex;\n};\n\nexport const COHORT_NAMES = {\n POST_TX: 'post_tx',\n WALLET_HOME: 'wallet_home',\n} as const;\n\nexport type CohortName = (typeof COHORT_NAMES)[keyof typeof COHORT_NAMES];\n\nexport const BALANCE_CATEGORIES = {\n RANGE_0_99: '0-99',\n RANGE_100_999: '100-999',\n RANGE_1K_9_9K: '1k-9.9k',\n RANGE_10K_99_9K: '10k-99.9k',\n RANGE_100K_999_9K: '100k-999.9k',\n RANGE_1M_PLUS: '1M+',\n} as const;\n\nexport type BalanceCategory =\n (typeof BALANCE_CATEGORIES)[keyof typeof BALANCE_CATEGORIES];\n\nexport type Cohort = {\n cohort: string;\n eligibilityRate: number; // 0-1 probability of being assigned to this cohort\n priority: number; // lower number = higher priority\n eligible: boolean;\n};\n\nexport type SubscriptionEligibility = {\n product: ProductType;\n canSubscribe: boolean;\n canViewEntryModal: boolean;\n modalType?: ModalType;\n cohorts: Cohort[];\n assignedCohort: string | null;\n hasAssignedCohortExpired: boolean;\n};\n\nexport const SubscriptionUserEvent = {\n ShieldEntryModalViewed: 'shield_entry_modal_viewed',\n ShieldCohortAssigned: 'shield_cohort_assigned',\n} as const;\n\nexport type SubscriptionUserEventType =\n (typeof SubscriptionUserEvent)[keyof typeof SubscriptionUserEvent];\n\nexport type SubmitUserEventRequest = {\n event: SubscriptionUserEventType;\n cohort?: string;\n};\n\nexport type AssignCohortRequest = {\n cohort: string;\n};\n\nexport type GetSubscriptionsEligibilitiesRequest = {\n balanceCategory?: BalanceCategory;\n};\n\n/**\n * Request object for submitting sponsorship intents.\n */\nexport type SubmitSponsorshipIntentsRequest = {\n chainId: Hex;\n address: Hex;\n products: ProductType[];\n paymentTokenSymbol: string;\n recurringInterval: RecurringInterval;\n billingCycles: number;\n};\n\nexport type SubmitSponsorshipIntentsMethodParams = Pick<\n SubmitSponsorshipIntentsRequest,\n 'chainId' | 'address' | 'products'\n>;\n\nexport type ISubscriptionService = {\n getSubscriptions(): Promise<GetSubscriptionsResponse>;\n cancelSubscription(request: {\n subscriptionId: string;\n }): Promise<Subscription>;\n unCancelSubscription(request: {\n subscriptionId: string;\n }): Promise<Subscription>;\n startSubscriptionWithCard(\n request: StartSubscriptionRequest,\n ): Promise<StartSubscriptionResponse>;\n getBillingPortalUrl(): Promise<BillingPortalResponse>;\n getPricing(): Promise<PricingResponse>;\n startSubscriptionWithCrypto(\n request: StartCryptoSubscriptionRequest,\n ): Promise<StartCryptoSubscriptionResponse>;\n updatePaymentMethodCard(\n request: UpdatePaymentMethodCardRequest,\n ): Promise<UpdatePaymentMethodCardResponse>;\n updatePaymentMethodCrypto(\n request: UpdatePaymentMethodCryptoRequest,\n ): Promise<void>;\n getSubscriptionsEligibilities(\n request?: GetSubscriptionsEligibilitiesRequest,\n ): Promise<SubscriptionEligibility[]>;\n submitUserEvent(request: SubmitUserEventRequest): Promise<void>;\n assignUserToCohort(request: AssignCohortRequest): Promise<void>;\n\n /**\n * Submit sponsorship intents to the Subscription Service backend.\n *\n * This is intended to be used together with the crypto subscription flow.\n * When the user has enabled the smart transaction feature, we will sponsor the gas fees for the subscription approval transaction.\n *\n * @param request - Request object containing the address and products.\n * @example {\n * address: '0x1234567890123456789012345678901234567890',\n * products: [ProductType.Shield],\n * recurringInterval: RecurringInterval.Month,\n * billingCycles: 1,\n * }\n */\n submitSponsorshipIntents(\n request: SubmitSponsorshipIntentsRequest,\n ): Promise<void>;\n};\n\nexport type UpdatePaymentMethodOpts =\n | ({\n paymentType: Extract<PaymentType, 'card'>;\n } & UpdatePaymentMethodCardRequest)\n | ({\n paymentType: Extract<PaymentType, 'crypto'>;\n } & UpdatePaymentMethodCryptoRequest);\n\nexport type UpdatePaymentMethodCardRequest = {\n /**\n * Subscription ID\n */\n subscriptionId: string;\n\n /**\n * Recurring interval\n */\n recurringInterval: RecurringInterval;\n successUrl?: string;\n};\n\nexport type UpdatePaymentMethodCardResponse = {\n redirectUrl: string;\n};\n\nexport type UpdatePaymentMethodCryptoRequest = {\n subscriptionId: string;\n chainId: Hex;\n payerAddress: Hex;\n tokenSymbol: string;\n /**\n * The raw transaction to pay for the subscription\n * Can be empty if retry after topping up balance\n */\n rawTransaction?: Hex;\n recurringInterval: RecurringInterval;\n billingCycles: number;\n};\n\nexport type BillingPortalResponse = {\n url: string;\n};\n\n/**\n * The cached result of last selected payment methods for the user.\n * These details are being cached to be used internally to track the last selected payment method for the user. (e.g. for crypto subscriptions)\n */\nexport type CachedLastSelectedPaymentMethod = {\n type: PaymentType;\n paymentTokenAddress?: Hex;\n paymentTokenSymbol?: string;\n plan: RecurringInterval;\n useTestClock?: boolean;\n};\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/subscription-controller",
3
- "version": "5.0.0-preview-66e0169",
3
+ "version": "5.1.0-preview-8d461ad5",
4
4
  "description": "Handle user subscription",
5
5
  "keywords": [
6
6
  "MetaMask",