@metamask/subscription-controller 10.0.1 → 12.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +57 -1
- package/dist/SubscriptionController-method-action-types.d.ts +17 -1
- package/dist/SubscriptionController-method-action-types.d.ts.map +1 -1
- package/dist/SubscriptionController-method-action-types.js.map +1 -1
- package/dist/SubscriptionController.d.ts +15 -1
- package/dist/SubscriptionController.d.ts.map +1 -1
- package/dist/SubscriptionController.js +41 -5
- package/dist/SubscriptionController.js.map +1 -1
- package/dist/SubscriptionService-method-action-types.d.ts +2 -1
- package/dist/SubscriptionService-method-action-types.d.ts.map +1 -1
- package/dist/SubscriptionService-method-action-types.js.map +1 -1
- package/dist/SubscriptionService-structs.d.ts +33 -47
- package/dist/SubscriptionService-structs.d.ts.map +1 -1
- package/dist/SubscriptionService-structs.js +2 -6
- package/dist/SubscriptionService-structs.js.map +1 -1
- package/dist/SubscriptionService.d.ts +2 -1
- package/dist/SubscriptionService.d.ts.map +1 -1
- package/dist/SubscriptionService.js +4 -3
- package/dist/SubscriptionService.js.map +1 -1
- package/dist/constants.d.ts +8 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +7 -0
- package/dist/constants.js.map +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/subscription-delegation/SubscriptionDelegationService-method-action-types.d.ts +29 -5
- package/dist/subscription-delegation/SubscriptionDelegationService-method-action-types.d.ts.map +1 -1
- package/dist/subscription-delegation/SubscriptionDelegationService-method-action-types.js.map +1 -1
- package/dist/subscription-delegation/SubscriptionDelegationService.d.ts +33 -11
- package/dist/subscription-delegation/SubscriptionDelegationService.d.ts.map +1 -1
- package/dist/subscription-delegation/SubscriptionDelegationService.js +305 -22
- package/dist/subscription-delegation/SubscriptionDelegationService.js.map +1 -1
- package/dist/subscription-delegation/caveats.d.ts +31 -2
- package/dist/subscription-delegation/caveats.d.ts.map +1 -1
- package/dist/subscription-delegation/caveats.js +49 -9
- package/dist/subscription-delegation/caveats.js.map +1 -1
- package/dist/subscription-delegation/fingerprint.d.ts +1 -0
- package/dist/subscription-delegation/fingerprint.d.ts.map +1 -1
- package/dist/subscription-delegation/fingerprint.js +10 -6
- package/dist/subscription-delegation/fingerprint.js.map +1 -1
- package/dist/subscription-delegation/typed-data.d.ts +23 -0
- package/dist/subscription-delegation/typed-data.d.ts.map +1 -0
- package/dist/subscription-delegation/typed-data.js +75 -0
- package/dist/subscription-delegation/typed-data.js.map +1 -0
- package/dist/subscription-delegation/types.d.ts +105 -12
- package/dist/subscription-delegation/types.d.ts.map +1 -1
- package/dist/subscription-delegation/types.js +3 -4
- package/dist/subscription-delegation/types.js.map +1 -1
- package/dist/types.d.ts +15 -6
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -1
- package/package.json +19 -16
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,60 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [12.0.0]
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- **BREAKING:** Add `SubscriptionController:isUserEligibleForTrial` to report whether a user can start a trial for a product ([#10622](https://github.com/MetaMask/core/pull/10622))
|
|
15
|
+
- Clients must grant `SubscriptionControllerMessenger` access to `SeedlessOnboardingController:getIsUserAuthenticated` in order to call `SubscriptionController:isUserEligibleForTrial`.
|
|
16
|
+
|
|
17
|
+
### Changed
|
|
18
|
+
|
|
19
|
+
- Bump `@metamask/money-account-balance-service` from `^3.1.1` to `^3.1.2` ([#10624](https://github.com/MetaMask/core/pull/10624))
|
|
20
|
+
- Bump `@metamask/chomp-api-service` from `^6.0.0` to `^6.0.1` ([#10626](https://github.com/MetaMask/core/pull/10626))
|
|
21
|
+
- Bump `@metamask/transaction-controller` from `^72.0.1` to `^72.1.0` ([#10652](https://github.com/MetaMask/core/pull/10652))
|
|
22
|
+
|
|
23
|
+
## [11.0.0]
|
|
24
|
+
|
|
25
|
+
### Added
|
|
26
|
+
|
|
27
|
+
- Add `SubscriptionDelegationService:startSubscriptionWithDelegation` to orchestrate one immutable approval for MM Pay funding, recurring-payment delegation signing, CHOMP registration, and subscription creation ([#10339](https://github.com/MetaMask/core/pull/10339))
|
|
28
|
+
- Before the approval, call `MoneyAccountUpgradeController:forceUpgradeAccount` with the payer address so the Money Account vault delegations and CHOMP intents exist; the Subscription API validates them server-side.
|
|
29
|
+
- Add exported approval, funding, and prepared-bundle contracts.
|
|
30
|
+
- Bind recurring permissions to the token, amount, period, start, and zero native value, and verify reusable delegation hashes with CHOMP.
|
|
31
|
+
- Derive trial timing from authoritative subscription state.
|
|
32
|
+
- Add optional `skipApproval` to `StartSubscriptionWithDelegationRequest` to bypass the `ApprovalController:addRequest` consent and funding step; the caller is then responsible for consent and funding.
|
|
33
|
+
- Add `SUBSCRIPTION_STATUSES.awaitingFunds` (`awaiting_funds`) for crypto subscriptions that are waiting for the payer to fund the first invoice ([#10566](https://github.com/MetaMask/core/pull/10566))
|
|
34
|
+
- `SubscriptionController:submitSubscriptionCryptoApproval` treats it like `past_due` / `unpaid`: a new approval updates the existing subscription's payment method.
|
|
35
|
+
|
|
36
|
+
### Changed
|
|
37
|
+
|
|
38
|
+
- **BREAKING:** `StartCryptoSubscriptionResponse` (returned by `SubscriptionService:startSubscriptionWithCrypto`, `SubscriptionController:startSubscriptionWithCrypto`, and `SubscriptionDelegationService:startSubscriptionWithDelegation`) is now the created `Subscription` instead of `{ subscriptionId, status }`, matching what `POST /subscriptions/crypto` actually returns ([#10566](https://github.com/MetaMask/core/pull/10566))
|
|
39
|
+
- Read `response.id` instead of `response.subscriptionId`. `response.status` is unchanged.
|
|
40
|
+
- Previously the response failed validation on every successful call, so the crypto start flow always threw.
|
|
41
|
+
- **BREAKING:** Widen `SubscriptionDelegationServiceMessenger` so `SubscriptionDelegationService:startSubscriptionWithDelegation` can call the actions it needs ([#10339](https://github.com/MetaMask/core/pull/10339))
|
|
42
|
+
- The messenger must now allow `ApprovalController:addRequest`, `MoneyAccountUpgradeController:forceUpgradeAccount`, `SubscriptionController:getState`, `SubscriptionController:getSubscriptions`, and `SubscriptionController:startSubscriptionWithCrypto`.
|
|
43
|
+
- Clients that construct this messenger must delegate those actions before calling `startSubscriptionWithDelegation`. A messenger typed against the previous `SubscriptionDelegationServiceMessenger` is no longer assignable.
|
|
44
|
+
- Restrict cash-subscription delegations created by `SubscriptionDelegationService:prepareDelegation` so the ERC-20 `transfer` recipient must be the pricing chain `paymentAddress` (subscription treasury), via an `AllowedCalldataEnforcer` caveat. ([#10427](https://github.com/MetaMask/core/pull/10427))
|
|
45
|
+
- The caveat pins calldata from offset 0 to the `transfer(address,uint256)` selector followed by the ABI-encoded treasury address, matching the terms CHOMP expects.
|
|
46
|
+
- `prepareDelegation` throws when the pricing `paymentAddress` is not a valid address.
|
|
47
|
+
- Stored delegations without a matching recipient caveat are no longer reused; a new delegation is created and signed instead.
|
|
48
|
+
- Stop adding the `ValueLteEnforcer` caveat to cash-subscription delegations created by `SubscriptionDelegationService:prepareDelegation`, because CHOMP only accepts `ERC20PeriodTransferEnforcer` and `AllowedCalldataEnforcer` for this intent type. ([#10427](https://github.com/MetaMask/core/pull/10427))
|
|
49
|
+
- Stored delegations that still include a `ValueLteEnforcer` caveat are no longer reused; a new delegation is created and signed instead.
|
|
50
|
+
- Add `@ethersproject/abi` `^5.7.0` as a dependency ([#10427](https://github.com/MetaMask/core/pull/10427))
|
|
51
|
+
- Add `@metamask/money-account-upgrade-controller` `^5.1.0` as a dependency ([#10339](https://github.com/MetaMask/core/pull/10339))
|
|
52
|
+
- Bump `@metamask/transaction-controller` from `^72.0.0` to `^72.0.1` ([#10462](https://github.com/MetaMask/core/pull/10462))
|
|
53
|
+
- Bump `@metamask/base-data-service` from `^2.0.0` to `^2.1.0` ([#10502](https://github.com/MetaMask/core/pull/10502))
|
|
54
|
+
- Bump `@metamask/money-account-balance-service` from `^3.0.0` to `^3.1.1` ([#10502](https://github.com/MetaMask/core/pull/10502), [#10544](https://github.com/MetaMask/core/pull/10544))
|
|
55
|
+
- Bump `@metamask/chomp-api-service` from `^5.0.0` to `^6.0.0` ([#10505](https://github.com/MetaMask/core/pull/10505))
|
|
56
|
+
- Bump `@metamask/money-account-utils` from `^2.0.1` to `^2.1.0` ([#10505](https://github.com/MetaMask/core/pull/10505))
|
|
57
|
+
- Bump `@tanstack/query-core` from `^5.89.0` to `^5.103.2` ([#10511](https://github.com/MetaMask/core/pull/10511))
|
|
58
|
+
|
|
59
|
+
### Fixed
|
|
60
|
+
|
|
61
|
+
- Stop rejecting Subscription API responses whose `lastInvoice` omits `updatedAt` or whose card payment method omits `displayBrand`; both fields are optional in the API and are now optional on `SubscriptionInvoice` and `SubscriptionCardPaymentMethod` ([#10566](https://github.com/MetaMask/core/pull/10566))
|
|
62
|
+
- Previously a subscription with a `lastInvoice` failed validation and `getSubscriptions` threw.
|
|
63
|
+
|
|
10
64
|
## [10.0.1]
|
|
11
65
|
|
|
12
66
|
### Changed
|
|
@@ -544,7 +598,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
544
598
|
- 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))
|
|
545
599
|
- Bump `@metamask/utils` from `^11.4.2` to `^11.8.0` ([#6588](https://github.com/MetaMask/core/pull/6588))
|
|
546
600
|
|
|
547
|
-
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/subscription-controller@
|
|
601
|
+
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/subscription-controller@12.0.0...HEAD
|
|
602
|
+
[12.0.0]: https://github.com/MetaMask/core/compare/@metamask/subscription-controller@11.0.0...@metamask/subscription-controller@12.0.0
|
|
603
|
+
[11.0.0]: https://github.com/MetaMask/core/compare/@metamask/subscription-controller@10.0.1...@metamask/subscription-controller@11.0.0
|
|
548
604
|
[10.0.1]: https://github.com/MetaMask/core/compare/@metamask/subscription-controller@10.0.0...@metamask/subscription-controller@10.0.1
|
|
549
605
|
[10.0.0]: https://github.com/MetaMask/core/compare/@metamask/subscription-controller@9.1.0...@metamask/subscription-controller@10.0.0
|
|
550
606
|
[9.1.0]: https://github.com/MetaMask/core/compare/@metamask/subscription-controller@9.0.1...@metamask/subscription-controller@9.1.0
|
|
@@ -37,6 +37,22 @@ export type SubscriptionControllerGetSubscriptionByProductAction = {
|
|
|
37
37
|
type: `SubscriptionController:getSubscriptionByProduct`;
|
|
38
38
|
handler: SubscriptionController['getSubscriptionByProduct'];
|
|
39
39
|
};
|
|
40
|
+
/**
|
|
41
|
+
* Whether the user is eligible to start a trial for the given product.
|
|
42
|
+
*
|
|
43
|
+
* Shield is eligible when the user has not trialed Shield before.
|
|
44
|
+
* Money Account Plus is eligible when the user has not trialed it before
|
|
45
|
+
* and is authenticated with social login. Only an unlocked wallet can
|
|
46
|
+
* subscribe, so `SeedlessOnboardingController:getIsUserAuthenticated` is a
|
|
47
|
+
* sufficient social-login check.
|
|
48
|
+
*
|
|
49
|
+
* @param productType - The product to check.
|
|
50
|
+
* @returns Whether the user is eligible for a trial.
|
|
51
|
+
*/
|
|
52
|
+
export type SubscriptionControllerIsUserEligibleForTrialAction = {
|
|
53
|
+
type: `SubscriptionController:isUserEligibleForTrial`;
|
|
54
|
+
handler: SubscriptionController['isUserEligibleForTrial'];
|
|
55
|
+
};
|
|
40
56
|
/**
|
|
41
57
|
* Get the subscriptions eligibilities.
|
|
42
58
|
*
|
|
@@ -257,5 +273,5 @@ export type SubscriptionControllerStopAllPollingAction = {
|
|
|
257
273
|
/**
|
|
258
274
|
* Union of all SubscriptionController action types.
|
|
259
275
|
*/
|
|
260
|
-
export type SubscriptionControllerMethodActions = SubscriptionControllerGetPricingAction | SubscriptionControllerGetSubscriptionsAction | SubscriptionControllerGetBenefitsAction | SubscriptionControllerGetSubscriptionByProductAction | SubscriptionControllerGetSubscriptionsEligibilitiesAction | SubscriptionControllerCancelSubscriptionAction | SubscriptionControllerUnCancelSubscriptionAction | SubscriptionControllerStartSubscriptionWithCardAction | SubscriptionControllerStartSubscriptionWithCryptoAction | SubscriptionControllerSubmitSubscriptionCryptoApprovalAction | SubscriptionControllerGetCryptoApproveTransactionParamsAction | SubscriptionControllerUpdatePaymentMethodAction | SubscriptionControllerGetBillingPortalUrlAction | SubscriptionControllerCacheLastSelectedPaymentMethodAction | SubscriptionControllerClearLastSelectedPaymentMethodAction | SubscriptionControllerSubmitSponsorshipIntentsAction | SubscriptionControllerSubmitUserEventAction | SubscriptionControllerAssignUserToCohortAction | SubscriptionControllerLinkRewardsAction | SubscriptionControllerGetTokenApproveAmountAction | SubscriptionControllerGetTokenMinimumBalanceAmountAction | SubscriptionControllerClearStateAction | SubscriptionControllerTriggerAccessTokenRefreshAction | SubscriptionControllerStopAllPollingAction;
|
|
276
|
+
export type SubscriptionControllerMethodActions = SubscriptionControllerGetPricingAction | SubscriptionControllerGetSubscriptionsAction | SubscriptionControllerGetBenefitsAction | SubscriptionControllerGetSubscriptionByProductAction | SubscriptionControllerIsUserEligibleForTrialAction | SubscriptionControllerGetSubscriptionsEligibilitiesAction | SubscriptionControllerCancelSubscriptionAction | SubscriptionControllerUnCancelSubscriptionAction | SubscriptionControllerStartSubscriptionWithCardAction | SubscriptionControllerStartSubscriptionWithCryptoAction | SubscriptionControllerSubmitSubscriptionCryptoApprovalAction | SubscriptionControllerGetCryptoApproveTransactionParamsAction | SubscriptionControllerUpdatePaymentMethodAction | SubscriptionControllerGetBillingPortalUrlAction | SubscriptionControllerCacheLastSelectedPaymentMethodAction | SubscriptionControllerClearLastSelectedPaymentMethodAction | SubscriptionControllerSubmitSponsorshipIntentsAction | SubscriptionControllerSubmitUserEventAction | SubscriptionControllerAssignUserToCohortAction | SubscriptionControllerLinkRewardsAction | SubscriptionControllerGetTokenApproveAmountAction | SubscriptionControllerGetTokenMinimumBalanceAmountAction | SubscriptionControllerClearStateAction | SubscriptionControllerTriggerAccessTokenRefreshAction | SubscriptionControllerStopAllPollingAction;
|
|
261
277
|
//# sourceMappingURL=SubscriptionController-method-action-types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SubscriptionController-method-action-types.d.ts","sourceRoot":"","sources":["../src/SubscriptionController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAE1E;;;;GAIG;AACH,MAAM,MAAM,sCAAsC,GAAG;IACnD,IAAI,EAAE,mCAAmC,CAAC;IAC1C,OAAO,EAAE,sBAAsB,CAAC,YAAY,CAAC,CAAC;CAC/C,CAAC;AAEF,MAAM,MAAM,4CAA4C,GAAG;IACzD,IAAI,EAAE,yCAAyC,CAAC;IAChD,OAAO,EAAE,sBAAsB,CAAC,kBAAkB,CAAC,CAAC;CACrD,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,uCAAuC,GAAG;IACpD,IAAI,EAAE,oCAAoC,CAAC;IAC3C,OAAO,EAAE,sBAAsB,CAAC,aAAa,CAAC,CAAC;CAChD,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,oDAAoD,GAAG;IACjE,IAAI,EAAE,iDAAiD,CAAC;IACxD,OAAO,EAAE,sBAAsB,CAAC,0BAA0B,CAAC,CAAC;CAC7D,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,yDAAyD,GAAG;IACtE,IAAI,EAAE,sDAAsD,CAAC;IAC7D,OAAO,EAAE,sBAAsB,CAAC,+BAA+B,CAAC,CAAC;CAClE,CAAC;AAEF,MAAM,MAAM,8CAA8C,GAAG;IAC3D,IAAI,EAAE,2CAA2C,CAAC;IAClD,OAAO,EAAE,sBAAsB,CAA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AAkD,CAAC;IACzD,OAAO,EAAE,sBAAsB,CAAC,2BAA2B,CAAC,CAAC;CAC9D,CAAC;AAEF,MAAM,MAAM,0CAA0C,GAAG;IACvD,IAAI,EAAE,uCAAuC,CAAC;IAC9C,OAAO,EAAE,sBAAsB,CAAC,gBAAgB,CAAC,CAAC;CACnD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,mCAAmC,GAC3C,sCAAsC,GACtC,4CAA4C,GAC5C,uCAAuC,GACvC,oDAAoD,GACpD,yDAAyD,GACzD,8CAA8C,GAC9C,gDAAgD,GAChD,qDAAqD,GACrD,uDAAuD,GACvD,4DAA4D,GAC5D,6DAA6D,GAC7D,+CAA+C,GAC/C,+CAA+C,GAC/C,0DAA0D,GAC1D,0DAA0D,GAC1D,oDAAoD,GACpD,2CAA2C,GAC3C,8CAA8C,GAC9C,uCAAuC,GACvC,iDAAiD,GACjD,wDAAwD,GACxD,sCAAsC,GACtC,qDAAqD,GACrD,0CAA0C,CAAC"}
|
|
1
|
+
{"version":3,"file":"SubscriptionController-method-action-types.d.ts","sourceRoot":"","sources":["../src/SubscriptionController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAE1E;;;;GAIG;AACH,MAAM,MAAM,sCAAsC,GAAG;IACnD,IAAI,EAAE,mCAAmC,CAAC;IAC1C,OAAO,EAAE,sBAAsB,CAAC,YAAY,CAAC,CAAC;CAC/C,CAAC;AAEF,MAAM,MAAM,4CAA4C,GAAG;IACzD,IAAI,EAAE,yCAAyC,CAAC;IAChD,OAAO,EAAE,sBAAsB,CAAC,kBAAkB,CAAC,CAAC;CACrD,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,uCAAuC,GAAG;IACpD,IAAI,EAAE,oCAAoC,CAAC;IAC3C,OAAO,EAAE,sBAAsB,CAAC,aAAa,CAAC,CAAC;CAChD,CAAC;AAEF;;;;;GAKG;AACH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ources":["../src/SubscriptionController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { SubscriptionController } from './SubscriptionController.js';\n\n/**\n * Gets the pricing information from the subscription service.\n *\n * @returns The pricing information.\n */\nexport type SubscriptionControllerGetPricingAction = {\n type: `SubscriptionController:getPricing`;\n handler: SubscriptionController['getPricing'];\n};\n\nexport type SubscriptionControllerGetSubscriptionsAction = {\n type: `SubscriptionController:getSubscriptions`;\n handler: SubscriptionController['getSubscriptions'];\n};\n\n/**\n * Gets and stores the user's subscription benefits.\n *\n * @returns The benefits response.\n * @throws If the user is not an active Money Account Plus subscriber or is\n * not eligible for benefits.\n */\nexport type SubscriptionControllerGetBenefitsAction = {\n type: `SubscriptionController:getBenefits`;\n handler: SubscriptionController['getBenefits'];\n};\n\n/**\n * Get the subscription by product.\n *\n * @param productType - The product type.\n * @returns The subscription.\n */\nexport type SubscriptionControllerGetSubscriptionByProductAction = {\n type: `SubscriptionController:getSubscriptionByProduct`;\n handler: SubscriptionController['getSubscriptionByProduct'];\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 */\nexport type SubscriptionControllerGetSubscriptionsEligibilitiesAction = {\n type: `SubscriptionController:getSubscriptionsEligibilities`;\n handler: SubscriptionController['getSubscriptionsEligibilities'];\n};\n\nexport type SubscriptionControllerCancelSubscriptionAction = {\n type: `SubscriptionController:cancelSubscription`;\n handler: SubscriptionController['cancelSubscription'];\n};\n\nexport type SubscriptionControllerUnCancelSubscriptionAction = {\n type: `SubscriptionController:unCancelSubscription`;\n handler: SubscriptionController['unCancelSubscription'];\n};\n\n/**\n * Starts a card-paid subscription checkout session for the requested products\n * (e.g. Shield or Money Account Plus).\n *\n * `isTrialRequested` on the request is ignored and overwritten from pricing\n * (`trialPeriodDays > 0`) and `trialedProducts`.\n *\n * @param request - The start subscription request.\n * @returns The checkout session response.\n */\nexport type SubscriptionControllerStartSubscriptionWithCardAction = {\n type: `SubscriptionController:startSubscriptionWithCard`;\n handler: SubscriptionController['startSubscriptionWithCard'];\n};\n\n/**\n * Starts a crypto-paid subscription for the requested products\n * (e.g. Shield or Money Account Plus). Unlike card checkout, this\n * creates the subscription immediately, so local state is refreshed\n * afterwards.\n *\n * `isTrialRequested` on the request is ignored and overwritten from pricing\n * (`trialPeriodDays > 0`) and `trialedProducts`.\n *\n * @param request - The start crypto subscription request.\n * @returns The start crypto subscription response.\n * @throws If `products` is empty.\n */\nexport type SubscriptionControllerStartSubscriptionWithCryptoAction = {\n type: `SubscriptionController:startSubscriptionWithCrypto`;\n handler: SubscriptionController['startSubscriptionWithCrypto'];\n};\n\n/**\n * Submits a Shield ERC-20 crypto approval transaction to start or update a\n * crypto subscription.\n *\n * This handler is Shield / `TransactionType.shieldSubscriptionApprove` only.\n * Delegation-based products (e.g. Money Account) must call\n * `startSubscriptionWithCrypto` instead.\n *\n * @param request - The crypto approval request.\n * @param request.productType - The subscription product. Typed as\n * `typeof PRODUCT_TYPES.SHIELD` only at the moment (future might support more\n * product).\n * @param request.txMeta - The transaction metadata. Must have type\n * `TransactionType.shieldSubscriptionApprove`.\n * @param request.isSponsored - Whether the transaction is sponsored.\n * @param request.rewardAccountId - The account ID of the reward subscription\n * to link.\n * @throws If `productType` is not Shield or `txMeta.type` is not\n * `shieldSubscriptionApprove`.\n * @returns void\n */\nexport type SubscriptionControllerSubmitSubscriptionCryptoApprovalAction = {\n type: `SubscriptionController:submitSubscriptionCryptoApproval`;\n handler: SubscriptionController['submitSubscriptionCryptoApproval'];\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 */\nexport type SubscriptionControllerGetCryptoApproveTransactionParamsAction = {\n type: `SubscriptionController:getCryptoApproveTransactionParams`;\n handler: SubscriptionController['getCryptoApproveTransactionParams'];\n};\n\nexport type SubscriptionControllerUpdatePaymentMethodAction = {\n type: `SubscriptionController:updatePaymentMethod`;\n handler: SubscriptionController['updatePaymentMethod'];\n};\n\n/**\n * Gets the billing portal URL.\n *\n * @returns The billing portal URL\n */\nexport type SubscriptionControllerGetBillingPortalUrlAction = {\n type: `SubscriptionController:getBillingPortalUrl`;\n handler: SubscriptionController['getBillingPortalUrl'];\n};\n\n/**\n * Cache the last selected payment method for a specific product.\n *\n * @param request - The request object.\n * @param request.product - The product to cache the payment method for.\n * @param request.paymentMethod - The payment method to cache.\n * @param request.paymentMethod.type - The type of the payment method.\n * @param request.paymentMethod.paymentTokenAddress - The payment token address.\n * @param request.paymentMethod.plan - The plan of the payment method.\n */\nexport type SubscriptionControllerCacheLastSelectedPaymentMethodAction = {\n type: `SubscriptionController:cacheLastSelectedPaymentMethod`;\n handler: SubscriptionController['cacheLastSelectedPaymentMethod'];\n};\n\n/**\n * Clear the last selected payment method for a specific product.\n *\n * @param product - The product to clear the payment method for.\n */\nexport type SubscriptionControllerClearLastSelectedPaymentMethodAction = {\n type: `SubscriptionController:clearLastSelectedPaymentMethod`;\n handler: SubscriptionController['clearLastSelectedPaymentMethod'];\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 if the chain does not support sponsorship or the user has already trialed\n * @throws If the crypto payment method or chain is missing from pricing\n */\nexport type SubscriptionControllerSubmitSponsorshipIntentsAction = {\n type: `SubscriptionController:submitSponsorshipIntents`;\n handler: SubscriptionController['submitSponsorshipIntents'];\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 */\nexport type SubscriptionControllerSubmitUserEventAction = {\n type: `SubscriptionController:submitUserEvent`;\n handler: SubscriptionController['submitUserEvent'];\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 */\nexport type SubscriptionControllerAssignUserToCohortAction = {\n type: `SubscriptionController:assignUserToCohort`;\n handler: SubscriptionController['assignUserToCohort'];\n};\n\n/**\n * Link rewards to a subscription.\n *\n * @param request - Request object containing the reward subscription ID.\n * @param request.subscriptionId - The ID of the subscription to link rewards to.\n * @param request.rewardAccountId - The account ID of the reward subscription to link to the subscription.\n * @example { subscriptionId: '1234567890', rewardAccountId: 'eip155:1:0x1234567890123456789012345678901234567890' }\n * @returns Resolves when the rewards are linked successfully.\n */\nexport type SubscriptionControllerLinkRewardsAction = {\n type: `SubscriptionController:linkRewards`;\n handler: SubscriptionController['linkRewards'];\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 */\nexport type SubscriptionControllerGetTokenApproveAmountAction = {\n type: `SubscriptionController:getTokenApproveAmount`;\n handler: SubscriptionController['getTokenApproveAmount'];\n};\n\n/**\n * Calculate token minimum balance amount from price info\n *\n * @param price - The price info\n * @param tokenPaymentInfo - The token price info\n * @returns The token balance amount\n */\nexport type SubscriptionControllerGetTokenMinimumBalanceAmountAction = {\n type: `SubscriptionController:getTokenMinimumBalanceAmount`;\n handler: SubscriptionController['getTokenMinimumBalanceAmount'];\n};\n\n/**\n * Clears the subscription state and resets to default values.\n */\nexport type SubscriptionControllerClearStateAction = {\n type: `SubscriptionController:clearState`;\n handler: SubscriptionController['clearState'];\n};\n\n/**\n * Triggers an access token refresh.\n */\nexport type SubscriptionControllerTriggerAccessTokenRefreshAction = {\n type: `SubscriptionController:triggerAccessTokenRefresh`;\n handler: SubscriptionController['triggerAccessTokenRefresh'];\n};\n\nexport type SubscriptionControllerStopAllPollingAction = {\n type: `SubscriptionController:stopAllPolling`;\n handler: SubscriptionController['stopAllPolling'];\n};\n\n/**\n * Union of all SubscriptionController action types.\n */\nexport type SubscriptionControllerMethodActions =\n | SubscriptionControllerGetPricingAction\n | SubscriptionControllerGetSubscriptionsAction\n | SubscriptionControllerGetBenefitsAction\n | SubscriptionControllerGetSubscriptionByProductAction\n | SubscriptionControllerGetSubscriptionsEligibilitiesAction\n | SubscriptionControllerCancelSubscriptionAction\n | SubscriptionControllerUnCancelSubscriptionAction\n | SubscriptionControllerStartSubscriptionWithCardAction\n | SubscriptionControllerStartSubscriptionWithCryptoAction\n | SubscriptionControllerSubmitSubscriptionCryptoApprovalAction\n | SubscriptionControllerGetCryptoApproveTransactionParamsAction\n | SubscriptionControllerUpdatePaymentMethodAction\n | SubscriptionControllerGetBillingPortalUrlAction\n | SubscriptionControllerCacheLastSelectedPaymentMethodAction\n | SubscriptionControllerClearLastSelectedPaymentMethodAction\n | SubscriptionControllerSubmitSponsorshipIntentsAction\n | SubscriptionControllerSubmitUserEventAction\n | SubscriptionControllerAssignUserToCohortAction\n | SubscriptionControllerLinkRewardsAction\n | SubscriptionControllerGetTokenApproveAmountAction\n | SubscriptionControllerGetTokenMinimumBalanceAmountAction\n | SubscriptionControllerClearStateAction\n | SubscriptionControllerTriggerAccessTokenRefreshAction\n | SubscriptionControllerStopAllPollingAction;\n"]}
|
|
1
|
+
{"version":3,"file":"SubscriptionController-method-action-types.js","sourceRoot":"","sources":["../src/SubscriptionController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { SubscriptionController } from './SubscriptionController.js';\n\n/**\n * Gets the pricing information from the subscription service.\n *\n * @returns The pricing information.\n */\nexport type SubscriptionControllerGetPricingAction = {\n type: `SubscriptionController:getPricing`;\n handler: SubscriptionController['getPricing'];\n};\n\nexport type SubscriptionControllerGetSubscriptionsAction = {\n type: `SubscriptionController:getSubscriptions`;\n handler: SubscriptionController['getSubscriptions'];\n};\n\n/**\n * Gets and stores the user's subscription benefits.\n *\n * @returns The benefits response.\n * @throws If the user is not an active Money Account Plus subscriber or is\n * not eligible for benefits.\n */\nexport type SubscriptionControllerGetBenefitsAction = {\n type: `SubscriptionController:getBenefits`;\n handler: SubscriptionController['getBenefits'];\n};\n\n/**\n * Get the subscription by product.\n *\n * @param productType - The product type.\n * @returns The subscription.\n */\nexport type SubscriptionControllerGetSubscriptionByProductAction = {\n type: `SubscriptionController:getSubscriptionByProduct`;\n handler: SubscriptionController['getSubscriptionByProduct'];\n};\n\n/**\n * Whether the user is eligible to start a trial for the given product.\n *\n * Shield is eligible when the user has not trialed Shield before.\n * Money Account Plus is eligible when the user has not trialed it before\n * and is authenticated with social login. Only an unlocked wallet can\n * subscribe, so `SeedlessOnboardingController:getIsUserAuthenticated` is a\n * sufficient social-login check.\n *\n * @param productType - The product to check.\n * @returns Whether the user is eligible for a trial.\n */\nexport type SubscriptionControllerIsUserEligibleForTrialAction = {\n type: `SubscriptionController:isUserEligibleForTrial`;\n handler: SubscriptionController['isUserEligibleForTrial'];\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 */\nexport type SubscriptionControllerGetSubscriptionsEligibilitiesAction = {\n type: `SubscriptionController:getSubscriptionsEligibilities`;\n handler: SubscriptionController['getSubscriptionsEligibilities'];\n};\n\nexport type SubscriptionControllerCancelSubscriptionAction = {\n type: `SubscriptionController:cancelSubscription`;\n handler: SubscriptionController['cancelSubscription'];\n};\n\nexport type SubscriptionControllerUnCancelSubscriptionAction = {\n type: `SubscriptionController:unCancelSubscription`;\n handler: SubscriptionController['unCancelSubscription'];\n};\n\n/**\n * Starts a card-paid subscription checkout session for the requested products\n * (e.g. Shield or Money Account Plus).\n *\n * `isTrialRequested` on the request is ignored and overwritten from pricing\n * (`trialPeriodDays > 0`) and `trialedProducts`.\n *\n * @param request - The start subscription request.\n * @returns The checkout session response.\n */\nexport type SubscriptionControllerStartSubscriptionWithCardAction = {\n type: `SubscriptionController:startSubscriptionWithCard`;\n handler: SubscriptionController['startSubscriptionWithCard'];\n};\n\n/**\n * Starts a crypto-paid subscription for the requested products\n * (e.g. Shield or Money Account Plus). Unlike card checkout, this\n * creates the subscription immediately, so local state is refreshed\n * afterwards.\n *\n * `isTrialRequested` on the request is ignored and overwritten from pricing\n * (`trialPeriodDays > 0`) and `trialedProducts`.\n *\n * @param request - The start crypto subscription request.\n * @returns The start crypto subscription response.\n * @throws If `products` is empty.\n */\nexport type SubscriptionControllerStartSubscriptionWithCryptoAction = {\n type: `SubscriptionController:startSubscriptionWithCrypto`;\n handler: SubscriptionController['startSubscriptionWithCrypto'];\n};\n\n/**\n * Submits a Shield ERC-20 crypto approval transaction to start or update a\n * crypto subscription.\n *\n * This handler is Shield / `TransactionType.shieldSubscriptionApprove` only.\n * Delegation-based products (e.g. Money Account) must call\n * `startSubscriptionWithCrypto` instead.\n *\n * @param request - The crypto approval request.\n * @param request.productType - The subscription product. Typed as\n * `typeof PRODUCT_TYPES.SHIELD` only at the moment (future might support more\n * product).\n * @param request.txMeta - The transaction metadata. Must have type\n * `TransactionType.shieldSubscriptionApprove`.\n * @param request.isSponsored - Whether the transaction is sponsored.\n * @param request.rewardAccountId - The account ID of the reward subscription\n * to link.\n * @throws If `productType` is not Shield or `txMeta.type` is not\n * `shieldSubscriptionApprove`.\n * @returns void\n */\nexport type SubscriptionControllerSubmitSubscriptionCryptoApprovalAction = {\n type: `SubscriptionController:submitSubscriptionCryptoApproval`;\n handler: SubscriptionController['submitSubscriptionCryptoApproval'];\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 */\nexport type SubscriptionControllerGetCryptoApproveTransactionParamsAction = {\n type: `SubscriptionController:getCryptoApproveTransactionParams`;\n handler: SubscriptionController['getCryptoApproveTransactionParams'];\n};\n\nexport type SubscriptionControllerUpdatePaymentMethodAction = {\n type: `SubscriptionController:updatePaymentMethod`;\n handler: SubscriptionController['updatePaymentMethod'];\n};\n\n/**\n * Gets the billing portal URL.\n *\n * @returns The billing portal URL\n */\nexport type SubscriptionControllerGetBillingPortalUrlAction = {\n type: `SubscriptionController:getBillingPortalUrl`;\n handler: SubscriptionController['getBillingPortalUrl'];\n};\n\n/**\n * Cache the last selected payment method for a specific product.\n *\n * @param request - The request object.\n * @param request.product - The product to cache the payment method for.\n * @param request.paymentMethod - The payment method to cache.\n * @param request.paymentMethod.type - The type of the payment method.\n * @param request.paymentMethod.paymentTokenAddress - The payment token address.\n * @param request.paymentMethod.plan - The plan of the payment method.\n */\nexport type SubscriptionControllerCacheLastSelectedPaymentMethodAction = {\n type: `SubscriptionController:cacheLastSelectedPaymentMethod`;\n handler: SubscriptionController['cacheLastSelectedPaymentMethod'];\n};\n\n/**\n * Clear the last selected payment method for a specific product.\n *\n * @param product - The product to clear the payment method for.\n */\nexport type SubscriptionControllerClearLastSelectedPaymentMethodAction = {\n type: `SubscriptionController:clearLastSelectedPaymentMethod`;\n handler: SubscriptionController['clearLastSelectedPaymentMethod'];\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 if the chain does not support sponsorship or the user has already trialed\n * @throws If the crypto payment method or chain is missing from pricing\n */\nexport type SubscriptionControllerSubmitSponsorshipIntentsAction = {\n type: `SubscriptionController:submitSponsorshipIntents`;\n handler: SubscriptionController['submitSponsorshipIntents'];\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 */\nexport type SubscriptionControllerSubmitUserEventAction = {\n type: `SubscriptionController:submitUserEvent`;\n handler: SubscriptionController['submitUserEvent'];\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 */\nexport type SubscriptionControllerAssignUserToCohortAction = {\n type: `SubscriptionController:assignUserToCohort`;\n handler: SubscriptionController['assignUserToCohort'];\n};\n\n/**\n * Link rewards to a subscription.\n *\n * @param request - Request object containing the reward subscription ID.\n * @param request.subscriptionId - The ID of the subscription to link rewards to.\n * @param request.rewardAccountId - The account ID of the reward subscription to link to the subscription.\n * @example { subscriptionId: '1234567890', rewardAccountId: 'eip155:1:0x1234567890123456789012345678901234567890' }\n * @returns Resolves when the rewards are linked successfully.\n */\nexport type SubscriptionControllerLinkRewardsAction = {\n type: `SubscriptionController:linkRewards`;\n handler: SubscriptionController['linkRewards'];\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 */\nexport type SubscriptionControllerGetTokenApproveAmountAction = {\n type: `SubscriptionController:getTokenApproveAmount`;\n handler: SubscriptionController['getTokenApproveAmount'];\n};\n\n/**\n * Calculate token minimum balance amount from price info\n *\n * @param price - The price info\n * @param tokenPaymentInfo - The token price info\n * @returns The token balance amount\n */\nexport type SubscriptionControllerGetTokenMinimumBalanceAmountAction = {\n type: `SubscriptionController:getTokenMinimumBalanceAmount`;\n handler: SubscriptionController['getTokenMinimumBalanceAmount'];\n};\n\n/**\n * Clears the subscription state and resets to default values.\n */\nexport type SubscriptionControllerClearStateAction = {\n type: `SubscriptionController:clearState`;\n handler: SubscriptionController['clearState'];\n};\n\n/**\n * Triggers an access token refresh.\n */\nexport type SubscriptionControllerTriggerAccessTokenRefreshAction = {\n type: `SubscriptionController:triggerAccessTokenRefresh`;\n handler: SubscriptionController['triggerAccessTokenRefresh'];\n};\n\nexport type SubscriptionControllerStopAllPollingAction = {\n type: `SubscriptionController:stopAllPolling`;\n handler: SubscriptionController['stopAllPolling'];\n};\n\n/**\n * Union of all SubscriptionController action types.\n */\nexport type SubscriptionControllerMethodActions =\n | SubscriptionControllerGetPricingAction\n | SubscriptionControllerGetSubscriptionsAction\n | SubscriptionControllerGetBenefitsAction\n | SubscriptionControllerGetSubscriptionByProductAction\n | SubscriptionControllerIsUserEligibleForTrialAction\n | SubscriptionControllerGetSubscriptionsEligibilitiesAction\n | SubscriptionControllerCancelSubscriptionAction\n | SubscriptionControllerUnCancelSubscriptionAction\n | SubscriptionControllerStartSubscriptionWithCardAction\n | SubscriptionControllerStartSubscriptionWithCryptoAction\n | SubscriptionControllerSubmitSubscriptionCryptoApprovalAction\n | SubscriptionControllerGetCryptoApproveTransactionParamsAction\n | SubscriptionControllerUpdatePaymentMethodAction\n | SubscriptionControllerGetBillingPortalUrlAction\n | SubscriptionControllerCacheLastSelectedPaymentMethodAction\n | SubscriptionControllerClearLastSelectedPaymentMethodAction\n | SubscriptionControllerSubmitSponsorshipIntentsAction\n | SubscriptionControllerSubmitUserEventAction\n | SubscriptionControllerAssignUserToCohortAction\n | SubscriptionControllerLinkRewardsAction\n | SubscriptionControllerGetTokenApproveAmountAction\n | SubscriptionControllerGetTokenMinimumBalanceAmountAction\n | SubscriptionControllerClearStateAction\n | SubscriptionControllerTriggerAccessTokenRefreshAction\n | SubscriptionControllerStopAllPollingAction;\n"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ControllerStateChangeEvent, ControllerGetStateAction } from '@metamask/base-controller';
|
|
2
2
|
import type { Messenger } from '@metamask/messenger';
|
|
3
3
|
import type { AuthenticationController } from '@metamask/profile-sync-controller';
|
|
4
|
+
import type { SeedlessOnboardingControllerGetIsUserAuthenticatedAction } from '@metamask/seedless-onboarding-controller';
|
|
4
5
|
import type { CaipAccountId } from '@metamask/utils';
|
|
5
6
|
import { controllerName } from './constants.js';
|
|
6
7
|
import type { SubscriptionControllerMethodActions } from './SubscriptionController-method-action-types.js';
|
|
@@ -27,7 +28,7 @@ export type SubscriptionControllerState = {
|
|
|
27
28
|
};
|
|
28
29
|
export type SubscriptionControllerGetStateAction = ControllerGetStateAction<typeof controllerName, SubscriptionControllerState>;
|
|
29
30
|
export type SubscriptionControllerActions = SubscriptionControllerGetStateAction | SubscriptionControllerMethodActions;
|
|
30
|
-
type AllowedActions = SubscriptionServiceGetPricingAction | SubscriptionServiceGetSubscriptionsAction | SubscriptionServiceGetBenefitsAction | SubscriptionServiceGetSubscriptionsEligibilitiesAction | SubscriptionServiceCancelSubscriptionAction | SubscriptionServiceUnCancelSubscriptionAction | SubscriptionServiceStartSubscriptionWithCardAction | SubscriptionServiceStartSubscriptionWithCryptoAction | SubscriptionServiceUpdatePaymentMethodCardAction | SubscriptionServiceUpdatePaymentMethodCryptoAction | SubscriptionServiceGetBillingPortalUrlAction | SubscriptionServiceSubmitSponsorshipIntentsAction | SubscriptionServiceSubmitUserEventAction | SubscriptionServiceAssignUserToCohortAction | SubscriptionServiceLinkRewardsAction | AuthenticationController.AuthenticationControllerPerformSignOutAction;
|
|
31
|
+
type AllowedActions = SubscriptionServiceGetPricingAction | SubscriptionServiceGetSubscriptionsAction | SubscriptionServiceGetBenefitsAction | SubscriptionServiceGetSubscriptionsEligibilitiesAction | SubscriptionServiceCancelSubscriptionAction | SubscriptionServiceUnCancelSubscriptionAction | SubscriptionServiceStartSubscriptionWithCardAction | SubscriptionServiceStartSubscriptionWithCryptoAction | SubscriptionServiceUpdatePaymentMethodCardAction | SubscriptionServiceUpdatePaymentMethodCryptoAction | SubscriptionServiceGetBillingPortalUrlAction | SubscriptionServiceSubmitSponsorshipIntentsAction | SubscriptionServiceSubmitUserEventAction | SubscriptionServiceAssignUserToCohortAction | SubscriptionServiceLinkRewardsAction | AuthenticationController.AuthenticationControllerPerformSignOutAction | SeedlessOnboardingControllerGetIsUserAuthenticatedAction;
|
|
31
32
|
export type SubscriptionControllerStateChangeEvent = ControllerStateChangeEvent<typeof controllerName, SubscriptionControllerState>;
|
|
32
33
|
export type SubscriptionControllerEvents = SubscriptionControllerStateChangeEvent;
|
|
33
34
|
type AllowedEvents = never;
|
|
@@ -102,6 +103,19 @@ export declare class SubscriptionController extends SubscriptionController_base<
|
|
|
102
103
|
* @returns The subscription.
|
|
103
104
|
*/
|
|
104
105
|
getSubscriptionByProduct(productType: ProductType): Subscription | undefined;
|
|
106
|
+
/**
|
|
107
|
+
* Whether the user is eligible to start a trial for the given product.
|
|
108
|
+
*
|
|
109
|
+
* Shield is eligible when the user has not trialed Shield before.
|
|
110
|
+
* Money Account Plus is eligible when the user has not trialed it before
|
|
111
|
+
* and is authenticated with social login. Only an unlocked wallet can
|
|
112
|
+
* subscribe, so `SeedlessOnboardingController:getIsUserAuthenticated` is a
|
|
113
|
+
* sufficient social-login check.
|
|
114
|
+
*
|
|
115
|
+
* @param productType - The product to check.
|
|
116
|
+
* @returns Whether the user is eligible for a trial.
|
|
117
|
+
*/
|
|
118
|
+
isUserEligibleForTrial(productType: ProductType): Promise<boolean>;
|
|
105
119
|
/**
|
|
106
120
|
* Get the subscriptions eligibilities.
|
|
107
121
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SubscriptionController.d.ts","sourceRoot":"","sources":["../src/SubscriptionController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,0BAA0B,EAC1B,wBAAwB,EACzB,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAErD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,mCAAmC,CAAC;
|
|
1
|
+
{"version":3,"file":"SubscriptionController.d.ts","sourceRoot":"","sources":["../src/SubscriptionController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,0BAA0B,EAC1B,wBAAwB,EACzB,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAErD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,mCAAmC,CAAC;AAClF,OAAO,KAAK,EAAE,wDAAwD,EAAE,MAAM,0CAA0C,CAAC;AAEzH,OAAO,KAAK,EAAE,aAAa,EAAO,MAAM,iBAAiB,CAAC;AAI1D,OAAO,EAEL,cAAc,EAIf,MAAM,gBAAgB,CAAC;AAExB,OAAO,KAAK,EAAE,mCAAmC,EAAE,MAAM,iDAAiD,CAAC;AAC3G,OAAO,KAAK,EACV,2CAA2C,EAC3C,2CAA2C,EAC3C,4CAA4C,EAC5C,oCAAoC,EACpC,mCAAmC,EACnC,yCAAyC,EACzC,sDAAsD,EACtD,oCAAoC,EACpC,kDAAkD,EAClD,oDAAoD,EACpD,iDAAiD,EACjD,wCAAwC,EACxC,6CAA6C,EAC7C,gDAAgD,EAChD,kDAAkD,EACnD,MAAM,8CAA8C,CAAC;AAOtD,OAAO,KAAK,EACV,mBAAmB,EACnB,qBAAqB,EAErB,kCAAkC,EAClC,mCAAmC,EACnC,oCAAoC,EAEpC,YAAY,EACZ,uBAAuB,EACvB,8BAA8B,EAC9B,uCAAuC,EACvC,sBAAsB,EACtB,gBAAgB,EAChB,+BAA+B,EAC/B,uBAAuB,EACvB,+BAA+B,EAC/B,qCAAqC,EACrC,oCAAoC,EAGpC,kBAAkB,EAClB,+BAA+B,EAC/B,yBAAyB,EACzB,yBAAyB,EAEzB,4BAA4B,EAC5B,yBAAyB,EAC1B,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EACV,eAAe,EACf,WAAW,EACX,mBAAmB,EACnB,wBAAwB,EACxB,YAAY,EACb,MAAM,YAAY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,EAAE,gBAAgB,GACjC,MAAM,CAiBR;IAED;;OAEG;IACH,UAAU,IAAI,IAAI,CAKjB;IAED;;OAEG;IACH,yBAAyB,IAAI,IAAI,CAKhC;CA2XF"}
|
|
@@ -2,7 +2,7 @@ import { StaticIntervalPollingController } from '@metamask/polling-controller';
|
|
|
2
2
|
import { TransactionType } from '@metamask/transaction-controller';
|
|
3
3
|
import { BigNumber } from 'bignumber.js';
|
|
4
4
|
import deepEqual from 'fast-deep-equal';
|
|
5
|
-
import { ACTIVE_SUBSCRIPTION_STATUSES, controllerName, DEFAULT_POLLING_INTERVAL, SubscriptionControllerErrorMessage, } from './constants.js';
|
|
5
|
+
import { ACTIVE_SUBSCRIPTION_STATUSES, controllerName, DEFAULT_POLLING_INTERVAL, SubscriptionControllerErrorMessage, SubscriptionDelegationServiceErrorMessage, } from './constants.js';
|
|
6
6
|
import { createModuleLogger, projectLogger } from './logger.js';
|
|
7
7
|
import { CRYPTO_AUTH_METHODS, PAYMENT_TYPES, PRODUCT_TYPES, SUBSCRIPTION_STATUSES, } from './types.js';
|
|
8
8
|
const log = createModuleLogger(projectLogger, controllerName);
|
|
@@ -85,6 +85,7 @@ const MESSENGER_EXPOSED_METHODS = [
|
|
|
85
85
|
'getSubscriptions',
|
|
86
86
|
'getBenefits',
|
|
87
87
|
'getSubscriptionByProduct',
|
|
88
|
+
'isUserEligibleForTrial',
|
|
88
89
|
'getSubscriptionsEligibilities',
|
|
89
90
|
'cancelSubscription',
|
|
90
91
|
'unCancelSubscription',
|
|
@@ -241,6 +242,35 @@ export class SubscriptionController extends StaticIntervalPollingController() {
|
|
|
241
242
|
getSubscriptionByProduct(productType) {
|
|
242
243
|
return this.state.subscriptions.find((subscription) => subscription.products.some((product) => product.name === productType));
|
|
243
244
|
}
|
|
245
|
+
/**
|
|
246
|
+
* Whether the user is eligible to start a trial for the given product.
|
|
247
|
+
*
|
|
248
|
+
* Shield is eligible when the user has not trialed Shield before.
|
|
249
|
+
* Money Account Plus is eligible when the user has not trialed it before
|
|
250
|
+
* and is authenticated with social login. Only an unlocked wallet can
|
|
251
|
+
* subscribe, so `SeedlessOnboardingController:getIsUserAuthenticated` is a
|
|
252
|
+
* sufficient social-login check.
|
|
253
|
+
*
|
|
254
|
+
* @param productType - The product to check.
|
|
255
|
+
* @returns Whether the user is eligible for a trial.
|
|
256
|
+
*/
|
|
257
|
+
async isUserEligibleForTrial(productType) {
|
|
258
|
+
if (this.state.trialedProducts.includes(productType)) {
|
|
259
|
+
return false;
|
|
260
|
+
}
|
|
261
|
+
switch (productType) {
|
|
262
|
+
case PRODUCT_TYPES.SHIELD:
|
|
263
|
+
return true;
|
|
264
|
+
case PRODUCT_TYPES.MONEY_ACCOUNT_PLUS:
|
|
265
|
+
return await this.messenger.call('SeedlessOnboardingController:getIsUserAuthenticated');
|
|
266
|
+
default: {
|
|
267
|
+
// `productType` is `never` here. A new `PRODUCT_TYPES` member fails
|
|
268
|
+
// compilation until this switch handles it.
|
|
269
|
+
const unexpectedProduct = productType;
|
|
270
|
+
throw new Error(`Unexpected product type: ${String(unexpectedProduct)}`);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
244
274
|
/**
|
|
245
275
|
* Get the subscriptions eligibilities.
|
|
246
276
|
*
|
|
@@ -323,9 +353,15 @@ export class SubscriptionController extends StaticIntervalPollingController() {
|
|
|
323
353
|
// get the latest subscriptions state before computing trial eligibility
|
|
324
354
|
await this.#getSubscriptions({ refreshBenefits: false });
|
|
325
355
|
this.#assertIsUserNotSubscribed({ products: request.products });
|
|
356
|
+
const isTrialRequested = this.#getIsTrialRequested(request.products, request.recurringInterval);
|
|
357
|
+
if (request.assertTrialEligibility &&
|
|
358
|
+
request.isTrialRequested !== isTrialRequested) {
|
|
359
|
+
throw new Error(SubscriptionDelegationServiceErrorMessage.TrialEligibilityChanged);
|
|
360
|
+
}
|
|
361
|
+
const { assertTrialEligibility: _assertTrialEligibility, ...subscriptionRequest } = request;
|
|
326
362
|
const response = await this.messenger.call('SubscriptionService:startSubscriptionWithCrypto', {
|
|
327
|
-
...
|
|
328
|
-
isTrialRequested
|
|
363
|
+
...subscriptionRequest,
|
|
364
|
+
isTrialRequested,
|
|
329
365
|
});
|
|
330
366
|
// Crypto start creates the subscription immediately (unlike card checkout).
|
|
331
367
|
await this.getSubscriptions();
|
|
@@ -512,8 +548,7 @@ export class SubscriptionController extends StaticIntervalPollingController() {
|
|
|
512
548
|
this.update((state) => {
|
|
513
549
|
if (state.lastSelectedPaymentMethod) {
|
|
514
550
|
const { [product]: _, ...rest } = state.lastSelectedPaymentMethod;
|
|
515
|
-
state.lastSelectedPaymentMethod =
|
|
516
|
-
rest;
|
|
551
|
+
state.lastSelectedPaymentMethod = rest;
|
|
517
552
|
}
|
|
518
553
|
});
|
|
519
554
|
}
|
|
@@ -718,6 +753,7 @@ export class SubscriptionController extends StaticIntervalPollingController() {
|
|
|
718
753
|
const subscription = this.state.subscriptions.find((sub) => sub.products.some((product) => product.name === productType));
|
|
719
754
|
const isValid = !subscription ||
|
|
720
755
|
[
|
|
756
|
+
SUBSCRIPTION_STATUSES.awaitingFunds,
|
|
721
757
|
SUBSCRIPTION_STATUSES.pastDue,
|
|
722
758
|
SUBSCRIPTION_STATUSES.unpaid,
|
|
723
759
|
SUBSCRIPTION_STATUSES.paused,
|