@metamask-previews/subscription-controller 0.0.0-preview-236bab4a → 0.0.0-preview-2a00636
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 +1 -0
- package/dist/SubscriptionController.cjs +9 -0
- package/dist/SubscriptionController.cjs.map +1 -1
- package/dist/SubscriptionController.d.cts +12 -2
- package/dist/SubscriptionController.d.cts.map +1 -1
- package/dist/SubscriptionController.d.mts +12 -2
- package/dist/SubscriptionController.d.mts.map +1 -1
- package/dist/SubscriptionController.mjs +9 -0
- package/dist/SubscriptionController.mjs.map +1 -1
- package/dist/SubscriptionService.cjs +4 -0
- package/dist/SubscriptionService.cjs.map +1 -1
- package/dist/SubscriptionService.d.cts +2 -1
- package/dist/SubscriptionService.d.cts.map +1 -1
- package/dist/SubscriptionService.d.mts +2 -1
- package/dist/SubscriptionService.d.mts.map +1 -1
- package/dist/SubscriptionService.mjs +4 -0
- package/dist/SubscriptionService.mjs.map +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +34 -0
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +34 -0
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
@@ -13,5 +13,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
13
13
|
- `getSubscription`: Retrieve current user subscription info if exist.
|
14
14
|
- `cancelSubscription`: Cancel user active subscription.
|
15
15
|
- `startShieldSubscriptionWithCard`: start shield subscription via card (with trial option) ([#6300](https://github.com/MetaMask/core/pull/6300))
|
16
|
+
- Add `getPricing` method ([#6356](https://github.com/MetaMask/core/pull/6356))
|
16
17
|
|
17
18
|
[Unreleased]: https://github.com/MetaMask/core/
|
@@ -64,6 +64,14 @@ class SubscriptionController extends base_controller_1.BaseController {
|
|
64
64
|
__classPrivateFieldSet(this, _SubscriptionController_subscriptionService, subscriptionService, "f");
|
65
65
|
__classPrivateFieldGet(this, _SubscriptionController_instances, "m", _SubscriptionController_registerMessageHandlers).call(this);
|
66
66
|
}
|
67
|
+
/**
|
68
|
+
* Gets the pricing information from the subscription service.
|
69
|
+
*
|
70
|
+
* @returns The pricing information.
|
71
|
+
*/
|
72
|
+
async getPricing() {
|
73
|
+
return await __classPrivateFieldGet(this, _SubscriptionController_subscriptionService, "f").getPricing();
|
74
|
+
}
|
67
75
|
async getSubscriptions() {
|
68
76
|
const { subscriptions } = await __classPrivateFieldGet(this, _SubscriptionController_subscriptionService, "f").getSubscriptions();
|
69
77
|
this.update((state) => {
|
@@ -92,6 +100,7 @@ _SubscriptionController_subscriptionService = new WeakMap(), _SubscriptionContro
|
|
92
100
|
this.messagingSystem.registerActionHandler('SubscriptionController:getSubscriptions', this.getSubscriptions.bind(this));
|
93
101
|
this.messagingSystem.registerActionHandler('SubscriptionController:cancelSubscription', this.cancelSubscription.bind(this));
|
94
102
|
this.messagingSystem.registerActionHandler('SubscriptionController:startShieldSubscriptionWithCard', this.startShieldSubscriptionWithCard.bind(this));
|
103
|
+
this.messagingSystem.registerActionHandler('SubscriptionController:getPricing', this.getPricing.bind(this));
|
95
104
|
}, _SubscriptionController_assertIsUserNotSubscribed = function _SubscriptionController_assertIsUserNotSubscribed({ products }) {
|
96
105
|
if (this.state.subscriptions.find((subscription) => subscription.products.some((p) => products.includes(p.name)))) {
|
97
106
|
throw new Error(constants_1.SubscriptionControllerErrorMessage.UserAlreadySubscribed);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"SubscriptionController.cjs","sourceRoot":"","sources":["../src/SubscriptionController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,+DAMmC;AAGnC,+CAGqB;AACrB,uCAMiB;AA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AAC,CAAC;KAC3E;AACH,CAAC,2GAEuB,OAAmC;IACzD,IACE,CAAC,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,IAAI,CAC5B,CAAC,YAAY,EAAE,EAAE,CAAC,YAAY,CAAC,EAAE,KAAK,OAAO,CAAC,cAAc,CAC7D,EACD;QACA,MAAM,IAAI,KAAK,CAAC,8CAAkC,CAAC,iBAAiB,CAAC,CAAC;KACvE;AACH,CAAC","sourcesContent":["import {\n BaseController,\n type StateMetadata,\n type ControllerStateChangeEvent,\n type ControllerGetStateAction,\n type RestrictedMessenger,\n} from '@metamask/base-controller';\nimport type { AuthenticationController } from '@metamask/profile-sync-controller';\n\nimport {\n controllerName,\n SubscriptionControllerErrorMessage,\n} from './constants';\nimport {\n SubscriptionStatus,\n type ISubscriptionService,\n type ProductType,\n type StartSubscriptionRequest,\n type Subscription,\n} from './types';\n\nexport type SubscriptionControllerState = {\n subscriptions: Subscription[];\n};\n\n// Messenger Actions\nexport type SubscriptionControllerGetSubscriptionsAction = {\n type: `${typeof controllerName}:getSubscriptions`;\n handler: SubscriptionController['getSubscriptions'];\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};\n\nexport type SubscriptionControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n SubscriptionControllerState\n>;\nexport type SubscriptionControllerActions =\n | SubscriptionControllerGetSubscriptionsAction\n | SubscriptionControllerCancelSubscriptionAction\n | SubscriptionControllerStartShieldSubscriptionWithCardAction\n | SubscriptionControllerGetStateAction;\n\nexport type AllowedActions =\n AuthenticationController.AuthenticationControllerGetBearerToken;\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 = RestrictedMessenger<\n typeof controllerName,\n SubscriptionControllerActions | AllowedActions,\n SubscriptionControllerEvents | AllowedEvents,\n AllowedActions['type'],\n AllowedEvents['type']\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/**\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 };\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 persist: true,\n anonymous: false,\n },\n };\n\nexport class SubscriptionController extends BaseController<\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 */\n constructor({\n messenger,\n state,\n subscriptionService,\n }: SubscriptionControllerOptions) {\n super({\n name: controllerName,\n metadata: subscriptionControllerMetadata,\n state: {\n ...getDefaultSubscriptionControllerState(),\n ...state,\n },\n messenger,\n });\n\n this.#subscriptionService = subscriptionService;\n\n this.#registerMessageHandlers();\n }\n\n /**\n * Constructor helper for registering this controller's messaging system\n * actions.\n */\n #registerMessageHandlers(): void {\n this.messagingSystem.registerActionHandler(\n 'SubscriptionController:getSubscriptions',\n this.getSubscriptions.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n 'SubscriptionController:cancelSubscription',\n this.cancelSubscription.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n 'SubscriptionController:startShieldSubscriptionWithCard',\n this.startShieldSubscriptionWithCard.bind(this),\n );\n }\n\n async getSubscriptions() {\n const { subscriptions } =\n await this.#subscriptionService.getSubscriptions();\n\n this.update((state) => {\n state.subscriptions = subscriptions;\n });\n\n return subscriptions;\n }\n\n async cancelSubscription(request: { subscriptionId: string }) {\n this.#assertIsUserSubscribed({ subscriptionId: request.subscriptionId });\n\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, status: SubscriptionStatus.canceled }\n : subscription,\n );\n });\n }\n\n async startShieldSubscriptionWithCard(request: StartSubscriptionRequest) {\n this.#assertIsUserNotSubscribed({ products: request.products });\n\n return await this.#subscriptionService.startSubscriptionWithCard(request);\n }\n\n #assertIsUserNotSubscribed({ products }: { products: ProductType[] }) {\n if (\n this.state.subscriptions.find((subscription) =>\n subscription.products.some((p) => products.includes(p.name)),\n )\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"]}
|
1
|
+
{"version":3,"file":"SubscriptionController.cjs","sourceRoot":"","sources":["../src/SubscriptionController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,+DAMmC;AAGnC,+CAGqB;AACrB,uCAOiB;AA2EjB;;;;GAIG;AACH,SAAgB,qCAAqC;IACnD,OAAO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AY,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAC7D,EACD;QACA,MAAM,IAAI,KAAK,CAAC,8CAAkC,CAAC,qBAAqB,CAAC,CAAC;KAC3E;AACH,CAAC,2GAEuB,OAAmC;IACzD,IACE,CAAC,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,IAAI,CAC5B,CAAC,YAAY,EAAE,EAAE,CAAC,YAAY,CAAC,EAAE,KAAK,OAAO,CAAC,cAAc,CAC7D,EACD;QACA,MAAM,IAAI,KAAK,CAAC,8CAAkC,CAAC,iBAAiB,CAAC,CAAC;KACvE;AACH,CAAC","sourcesContent":["import {\n BaseController,\n type StateMetadata,\n type ControllerStateChangeEvent,\n type ControllerGetStateAction,\n type RestrictedMessenger,\n} from '@metamask/base-controller';\nimport type { AuthenticationController } from '@metamask/profile-sync-controller';\n\nimport {\n controllerName,\n SubscriptionControllerErrorMessage,\n} from './constants';\nimport {\n SubscriptionStatus,\n type ISubscriptionService,\n type PricingResponse,\n type ProductType,\n type StartSubscriptionRequest,\n type Subscription,\n} from './types';\n\nexport type SubscriptionControllerState = {\n subscriptions: Subscription[];\n};\n\n// Messenger Actions\nexport type SubscriptionControllerGetSubscriptionsAction = {\n type: `${typeof controllerName}:getSubscriptions`;\n handler: SubscriptionController['getSubscriptions'];\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};\n\nexport type SubscriptionControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n SubscriptionControllerState\n>;\nexport type SubscriptionControllerActions =\n | SubscriptionControllerGetSubscriptionsAction\n | SubscriptionControllerCancelSubscriptionAction\n | SubscriptionControllerStartShieldSubscriptionWithCardAction\n | SubscriptionControllerGetPricingAction\n | SubscriptionControllerGetStateAction;\n\nexport type AllowedActions =\n AuthenticationController.AuthenticationControllerGetBearerToken;\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 = RestrictedMessenger<\n typeof controllerName,\n SubscriptionControllerActions | AllowedActions,\n SubscriptionControllerEvents | AllowedEvents,\n AllowedActions['type'],\n AllowedEvents['type']\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/**\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 };\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 persist: true,\n anonymous: false,\n },\n };\n\nexport class SubscriptionController extends BaseController<\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 */\n constructor({\n messenger,\n state,\n subscriptionService,\n }: SubscriptionControllerOptions) {\n super({\n name: controllerName,\n metadata: subscriptionControllerMetadata,\n state: {\n ...getDefaultSubscriptionControllerState(),\n ...state,\n },\n messenger,\n });\n\n this.#subscriptionService = subscriptionService;\n\n this.#registerMessageHandlers();\n }\n\n /**\n * Constructor helper for registering this controller's messaging system\n * actions.\n */\n #registerMessageHandlers(): void {\n this.messagingSystem.registerActionHandler(\n 'SubscriptionController:getSubscriptions',\n this.getSubscriptions.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n 'SubscriptionController:cancelSubscription',\n this.cancelSubscription.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n 'SubscriptionController:startShieldSubscriptionWithCard',\n this.startShieldSubscriptionWithCard.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n 'SubscriptionController:getPricing',\n this.getPricing.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 return await this.#subscriptionService.getPricing();\n }\n\n async getSubscriptions() {\n const { subscriptions } =\n await this.#subscriptionService.getSubscriptions();\n\n this.update((state) => {\n state.subscriptions = subscriptions;\n });\n\n return subscriptions;\n }\n\n async cancelSubscription(request: { subscriptionId: string }) {\n this.#assertIsUserSubscribed({ subscriptionId: request.subscriptionId });\n\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, status: SubscriptionStatus.canceled }\n : subscription,\n );\n });\n }\n\n async startShieldSubscriptionWithCard(request: StartSubscriptionRequest) {\n this.#assertIsUserNotSubscribed({ products: request.products });\n\n return await this.#subscriptionService.startSubscriptionWithCard(request);\n }\n\n #assertIsUserNotSubscribed({ products }: { products: ProductType[] }) {\n if (\n this.state.subscriptions.find((subscription) =>\n subscription.products.some((p) => products.includes(p.name)),\n )\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"]}
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { BaseController, type ControllerStateChangeEvent, type ControllerGetStateAction, type RestrictedMessenger } from "@metamask/base-controller";
|
2
2
|
import type { AuthenticationController } from "@metamask/profile-sync-controller";
|
3
3
|
import { controllerName } from "./constants.cjs";
|
4
|
-
import { type ISubscriptionService, type StartSubscriptionRequest, type Subscription } from "./types.cjs";
|
4
|
+
import { type ISubscriptionService, type PricingResponse, type StartSubscriptionRequest, type Subscription } from "./types.cjs";
|
5
5
|
export type SubscriptionControllerState = {
|
6
6
|
subscriptions: Subscription[];
|
7
7
|
};
|
@@ -17,8 +17,12 @@ export type SubscriptionControllerStartShieldSubscriptionWithCardAction = {
|
|
17
17
|
type: `${typeof controllerName}:startShieldSubscriptionWithCard`;
|
18
18
|
handler: SubscriptionController['startShieldSubscriptionWithCard'];
|
19
19
|
};
|
20
|
+
export type SubscriptionControllerGetPricingAction = {
|
21
|
+
type: `${typeof controllerName}:getPricing`;
|
22
|
+
handler: SubscriptionController['getPricing'];
|
23
|
+
};
|
20
24
|
export type SubscriptionControllerGetStateAction = ControllerGetStateAction<typeof controllerName, SubscriptionControllerState>;
|
21
|
-
export type SubscriptionControllerActions = SubscriptionControllerGetSubscriptionsAction | SubscriptionControllerCancelSubscriptionAction | SubscriptionControllerStartShieldSubscriptionWithCardAction | SubscriptionControllerGetStateAction;
|
25
|
+
export type SubscriptionControllerActions = SubscriptionControllerGetSubscriptionsAction | SubscriptionControllerCancelSubscriptionAction | SubscriptionControllerStartShieldSubscriptionWithCardAction | SubscriptionControllerGetPricingAction | SubscriptionControllerGetStateAction;
|
22
26
|
export type AllowedActions = AuthenticationController.AuthenticationControllerGetBearerToken;
|
23
27
|
export type SubscriptionControllerStateChangeEvent = ControllerStateChangeEvent<typeof controllerName, SubscriptionControllerState>;
|
24
28
|
export type SubscriptionControllerEvents = SubscriptionControllerStateChangeEvent;
|
@@ -55,6 +59,12 @@ export declare class SubscriptionController extends BaseController<typeof contro
|
|
55
59
|
* @param options.subscriptionService - The subscription service for communicating with subscription server.
|
56
60
|
*/
|
57
61
|
constructor({ messenger, state, subscriptionService, }: SubscriptionControllerOptions);
|
62
|
+
/**
|
63
|
+
* Gets the pricing information from the subscription service.
|
64
|
+
*
|
65
|
+
* @returns The pricing information.
|
66
|
+
*/
|
67
|
+
getPricing(): Promise<PricingResponse>;
|
58
68
|
getSubscriptions(): Promise<Subscription[]>;
|
59
69
|
cancelSubscription(request: {
|
60
70
|
subscriptionId: string;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"SubscriptionController.d.cts","sourceRoot":"","sources":["../src/SubscriptionController.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EAEd,KAAK,0BAA0B,EAC/B,KAAK,wBAAwB,EAC7B,KAAK,mBAAmB,EACzB,kCAAkC;AACnC,OAAO,KAAK,EAAE,wBAAwB,EAAE,0CAA0C;AAElF,OAAO,EACL,cAAc,EAEf,wBAAoB;AACrB,OAAO,EAEL,KAAK,oBAAoB,
|
1
|
+
{"version":3,"file":"SubscriptionController.d.cts","sourceRoot":"","sources":["../src/SubscriptionController.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EAEd,KAAK,0BAA0B,EAC/B,KAAK,wBAAwB,EAC7B,KAAK,mBAAmB,EACzB,kCAAkC;AACnC,OAAO,KAAK,EAAE,wBAAwB,EAAE,0CAA0C;AAElF,OAAO,EACL,cAAc,EAEf,wBAAoB;AACrB,OAAO,EAEL,KAAK,oBAAoB,EACzB,KAAK,eAAe,EAEpB,KA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6BAA6B,GAAG,cAAc,EAC9C,4BAA4B,GAAG,aAAa,EAC5C,cAAc,CAAC,MAAM,CAAC,EACtB,aAAa,CAAC,MAAM,CAAC,CACtB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,6BAA6B,GAAG;IAC1C,SAAS,EAAE,+BAA+B,CAAC;IAE3C;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC,2BAA2B,CAAC,CAAC;IAE7C;;OAEG;IACH,mBAAmB,EAAE,oBAAoB,CAAC;CAC3C,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,qCAAqC,IAAI,2BAA2B,CAInF;AAiBD,qBAAa,sBAAuB,SAAQ,cAAc,CACxD,OAAO,cAAc,EACrB,2BAA2B,EAC3B,+BAA+B,CAChC;;IAGC;;;;;;;OAOG;gBACS,EACV,SAAS,EACT,KAAK,EACL,mBAAmB,GACpB,EAAE,6BAA6B;IA0ChC;;;;OAIG;IACG,UAAU,IAAI,OAAO,CAAC,eAAe,CAAC;IAItC,gBAAgB;IAWhB,kBAAkB,CAAC,OAAO,EAAE;QAAE,cAAc,EAAE,MAAM,CAAA;KAAE;IAgBtD,+BAA+B,CAAC,OAAO,EAAE,wBAAwB;CAyBxE"}
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { BaseController, type ControllerStateChangeEvent, type ControllerGetStateAction, type RestrictedMessenger } from "@metamask/base-controller";
|
2
2
|
import type { AuthenticationController } from "@metamask/profile-sync-controller";
|
3
3
|
import { controllerName } from "./constants.mjs";
|
4
|
-
import { type ISubscriptionService, type StartSubscriptionRequest, type Subscription } from "./types.mjs";
|
4
|
+
import { type ISubscriptionService, type PricingResponse, type StartSubscriptionRequest, type Subscription } from "./types.mjs";
|
5
5
|
export type SubscriptionControllerState = {
|
6
6
|
subscriptions: Subscription[];
|
7
7
|
};
|
@@ -17,8 +17,12 @@ export type SubscriptionControllerStartShieldSubscriptionWithCardAction = {
|
|
17
17
|
type: `${typeof controllerName}:startShieldSubscriptionWithCard`;
|
18
18
|
handler: SubscriptionController['startShieldSubscriptionWithCard'];
|
19
19
|
};
|
20
|
+
export type SubscriptionControllerGetPricingAction = {
|
21
|
+
type: `${typeof controllerName}:getPricing`;
|
22
|
+
handler: SubscriptionController['getPricing'];
|
23
|
+
};
|
20
24
|
export type SubscriptionControllerGetStateAction = ControllerGetStateAction<typeof controllerName, SubscriptionControllerState>;
|
21
|
-
export type SubscriptionControllerActions = SubscriptionControllerGetSubscriptionsAction | SubscriptionControllerCancelSubscriptionAction | SubscriptionControllerStartShieldSubscriptionWithCardAction | SubscriptionControllerGetStateAction;
|
25
|
+
export type SubscriptionControllerActions = SubscriptionControllerGetSubscriptionsAction | SubscriptionControllerCancelSubscriptionAction | SubscriptionControllerStartShieldSubscriptionWithCardAction | SubscriptionControllerGetPricingAction | SubscriptionControllerGetStateAction;
|
22
26
|
export type AllowedActions = AuthenticationController.AuthenticationControllerGetBearerToken;
|
23
27
|
export type SubscriptionControllerStateChangeEvent = ControllerStateChangeEvent<typeof controllerName, SubscriptionControllerState>;
|
24
28
|
export type SubscriptionControllerEvents = SubscriptionControllerStateChangeEvent;
|
@@ -55,6 +59,12 @@ export declare class SubscriptionController extends BaseController<typeof contro
|
|
55
59
|
* @param options.subscriptionService - The subscription service for communicating with subscription server.
|
56
60
|
*/
|
57
61
|
constructor({ messenger, state, subscriptionService, }: SubscriptionControllerOptions);
|
62
|
+
/**
|
63
|
+
* Gets the pricing information from the subscription service.
|
64
|
+
*
|
65
|
+
* @returns The pricing information.
|
66
|
+
*/
|
67
|
+
getPricing(): Promise<PricingResponse>;
|
58
68
|
getSubscriptions(): Promise<Subscription[]>;
|
59
69
|
cancelSubscription(request: {
|
60
70
|
subscriptionId: string;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"SubscriptionController.d.mts","sourceRoot":"","sources":["../src/SubscriptionController.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EAEd,KAAK,0BAA0B,EAC/B,KAAK,wBAAwB,E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yBxE"}
|
@@ -60,6 +60,14 @@ export class SubscriptionController extends BaseController {
|
|
60
60
|
__classPrivateFieldSet(this, _SubscriptionController_subscriptionService, subscriptionService, "f");
|
61
61
|
__classPrivateFieldGet(this, _SubscriptionController_instances, "m", _SubscriptionController_registerMessageHandlers).call(this);
|
62
62
|
}
|
63
|
+
/**
|
64
|
+
* Gets the pricing information from the subscription service.
|
65
|
+
*
|
66
|
+
* @returns The pricing information.
|
67
|
+
*/
|
68
|
+
async getPricing() {
|
69
|
+
return await __classPrivateFieldGet(this, _SubscriptionController_subscriptionService, "f").getPricing();
|
70
|
+
}
|
63
71
|
async getSubscriptions() {
|
64
72
|
const { subscriptions } = await __classPrivateFieldGet(this, _SubscriptionController_subscriptionService, "f").getSubscriptions();
|
65
73
|
this.update((state) => {
|
@@ -87,6 +95,7 @@ _SubscriptionController_subscriptionService = new WeakMap(), _SubscriptionContro
|
|
87
95
|
this.messagingSystem.registerActionHandler('SubscriptionController:getSubscriptions', this.getSubscriptions.bind(this));
|
88
96
|
this.messagingSystem.registerActionHandler('SubscriptionController:cancelSubscription', this.cancelSubscription.bind(this));
|
89
97
|
this.messagingSystem.registerActionHandler('SubscriptionController:startShieldSubscriptionWithCard', this.startShieldSubscriptionWithCard.bind(this));
|
98
|
+
this.messagingSystem.registerActionHandler('SubscriptionController:getPricing', this.getPricing.bind(this));
|
90
99
|
}, _SubscriptionController_assertIsUserNotSubscribed = function _SubscriptionController_assertIsUserNotSubscribed({ products }) {
|
91
100
|
if (this.state.subscriptions.find((subscription) => subscription.products.some((p) => products.includes(p.name)))) {
|
92
101
|
throw new Error(SubscriptionControllerErrorMessage.UserAlreadySubscribed);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"SubscriptionController.mjs","sourceRoot":"","sources":["../src/SubscriptionController.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EACL,cAAc,EAKf,kCAAkC;AAGnC,OAAO,EACL,cAAc,EACd,kCAAkC,EACnC,wBA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AC,kCAAkC,CAAC,qBAAqB,CAAC,CAAC;KAC3E;AACH,CAAC,2GAEuB,OAAmC;IACzD,IACE,CAAC,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,IAAI,CAC5B,CAAC,YAAY,EAAE,EAAE,CAAC,YAAY,CAAC,EAAE,KAAK,OAAO,CAAC,cAAc,CAC7D,EACD;QACA,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,iBAAiB,CAAC,CAAC;KACvE;AACH,CAAC","sourcesContent":["import {\n BaseController,\n type StateMetadata,\n type ControllerStateChangeEvent,\n type ControllerGetStateAction,\n type RestrictedMessenger,\n} from '@metamask/base-controller';\nimport type { AuthenticationController } from '@metamask/profile-sync-controller';\n\nimport {\n controllerName,\n SubscriptionControllerErrorMessage,\n} from './constants';\nimport {\n SubscriptionStatus,\n type ISubscriptionService,\n type ProductType,\n type StartSubscriptionRequest,\n type Subscription,\n} from './types';\n\nexport type SubscriptionControllerState = {\n subscriptions: Subscription[];\n};\n\n// Messenger Actions\nexport type SubscriptionControllerGetSubscriptionsAction = {\n type: `${typeof controllerName}:getSubscriptions`;\n handler: SubscriptionController['getSubscriptions'];\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};\n\nexport type SubscriptionControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n SubscriptionControllerState\n>;\nexport type SubscriptionControllerActions =\n | SubscriptionControllerGetSubscriptionsAction\n | SubscriptionControllerCancelSubscriptionAction\n | SubscriptionControllerStartShieldSubscriptionWithCardAction\n | SubscriptionControllerGetStateAction;\n\nexport type AllowedActions =\n AuthenticationController.AuthenticationControllerGetBearerToken;\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 = RestrictedMessenger<\n typeof controllerName,\n SubscriptionControllerActions | AllowedActions,\n SubscriptionControllerEvents | AllowedEvents,\n AllowedActions['type'],\n AllowedEvents['type']\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/**\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 };\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 persist: true,\n anonymous: false,\n },\n };\n\nexport class SubscriptionController extends BaseController<\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 */\n constructor({\n messenger,\n state,\n subscriptionService,\n }: SubscriptionControllerOptions) {\n super({\n name: controllerName,\n metadata: subscriptionControllerMetadata,\n state: {\n ...getDefaultSubscriptionControllerState(),\n ...state,\n },\n messenger,\n });\n\n this.#subscriptionService = subscriptionService;\n\n this.#registerMessageHandlers();\n }\n\n /**\n * Constructor helper for registering this controller's messaging system\n * actions.\n */\n #registerMessageHandlers(): void {\n this.messagingSystem.registerActionHandler(\n 'SubscriptionController:getSubscriptions',\n this.getSubscriptions.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n 'SubscriptionController:cancelSubscription',\n this.cancelSubscription.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n 'SubscriptionController:startShieldSubscriptionWithCard',\n this.startShieldSubscriptionWithCard.bind(this),\n );\n }\n\n async getSubscriptions() {\n const { subscriptions } =\n await this.#subscriptionService.getSubscriptions();\n\n this.update((state) => {\n state.subscriptions = subscriptions;\n });\n\n return subscriptions;\n }\n\n async cancelSubscription(request: { subscriptionId: string }) {\n this.#assertIsUserSubscribed({ subscriptionId: request.subscriptionId });\n\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, status: SubscriptionStatus.canceled }\n : subscription,\n );\n });\n }\n\n async startShieldSubscriptionWithCard(request: StartSubscriptionRequest) {\n this.#assertIsUserNotSubscribed({ products: request.products });\n\n return await this.#subscriptionService.startSubscriptionWithCard(request);\n }\n\n #assertIsUserNotSubscribed({ products }: { products: ProductType[] }) {\n if (\n this.state.subscriptions.find((subscription) =>\n subscription.products.some((p) => products.includes(p.name)),\n )\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"]}
|
1
|
+
{"version":3,"file":"SubscriptionController.mjs","sourceRoot":"","sources":["../src/SubscriptionController.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EACL,cAAc,EAKf,kCAAkC;AAGnC,OAAO,EACL,cAAc,EACd,kCA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E,IACE,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,YAAY,EAAE,EAAE,CAC7C,YAAY,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAC7D,EACD;QACA,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,qBAAqB,CAAC,CAAC;KAC3E;AACH,CAAC,2GAEuB,OAAmC;IACzD,IACE,CAAC,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,IAAI,CAC5B,CAAC,YAAY,EAAE,EAAE,CAAC,YAAY,CAAC,EAAE,KAAK,OAAO,CAAC,cAAc,CAC7D,EACD;QACA,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,iBAAiB,CAAC,CAAC;KACvE;AACH,CAAC","sourcesContent":["import {\n BaseController,\n type StateMetadata,\n type ControllerStateChangeEvent,\n type ControllerGetStateAction,\n type RestrictedMessenger,\n} from '@metamask/base-controller';\nimport type { AuthenticationController } from '@metamask/profile-sync-controller';\n\nimport {\n controllerName,\n SubscriptionControllerErrorMessage,\n} from './constants';\nimport {\n SubscriptionStatus,\n type ISubscriptionService,\n type PricingResponse,\n type ProductType,\n type StartSubscriptionRequest,\n type Subscription,\n} from './types';\n\nexport type SubscriptionControllerState = {\n subscriptions: Subscription[];\n};\n\n// Messenger Actions\nexport type SubscriptionControllerGetSubscriptionsAction = {\n type: `${typeof controllerName}:getSubscriptions`;\n handler: SubscriptionController['getSubscriptions'];\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};\n\nexport type SubscriptionControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n SubscriptionControllerState\n>;\nexport type SubscriptionControllerActions =\n | SubscriptionControllerGetSubscriptionsAction\n | SubscriptionControllerCancelSubscriptionAction\n | SubscriptionControllerStartShieldSubscriptionWithCardAction\n | SubscriptionControllerGetPricingAction\n | SubscriptionControllerGetStateAction;\n\nexport type AllowedActions =\n AuthenticationController.AuthenticationControllerGetBearerToken;\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 = RestrictedMessenger<\n typeof controllerName,\n SubscriptionControllerActions | AllowedActions,\n SubscriptionControllerEvents | AllowedEvents,\n AllowedActions['type'],\n AllowedEvents['type']\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/**\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 };\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 persist: true,\n anonymous: false,\n },\n };\n\nexport class SubscriptionController extends BaseController<\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 */\n constructor({\n messenger,\n state,\n subscriptionService,\n }: SubscriptionControllerOptions) {\n super({\n name: controllerName,\n metadata: subscriptionControllerMetadata,\n state: {\n ...getDefaultSubscriptionControllerState(),\n ...state,\n },\n messenger,\n });\n\n this.#subscriptionService = subscriptionService;\n\n this.#registerMessageHandlers();\n }\n\n /**\n * Constructor helper for registering this controller's messaging system\n * actions.\n */\n #registerMessageHandlers(): void {\n this.messagingSystem.registerActionHandler(\n 'SubscriptionController:getSubscriptions',\n this.getSubscriptions.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n 'SubscriptionController:cancelSubscription',\n this.cancelSubscription.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n 'SubscriptionController:startShieldSubscriptionWithCard',\n this.startShieldSubscriptionWithCard.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n 'SubscriptionController:getPricing',\n this.getPricing.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 return await this.#subscriptionService.getPricing();\n }\n\n async getSubscriptions() {\n const { subscriptions } =\n await this.#subscriptionService.getSubscriptions();\n\n this.update((state) => {\n state.subscriptions = subscriptions;\n });\n\n return subscriptions;\n }\n\n async cancelSubscription(request: { subscriptionId: string }) {\n this.#assertIsUserSubscribed({ subscriptionId: request.subscriptionId });\n\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, status: SubscriptionStatus.canceled }\n : subscription,\n );\n });\n }\n\n async startShieldSubscriptionWithCard(request: StartSubscriptionRequest) {\n this.#assertIsUserNotSubscribed({ products: request.products });\n\n return await this.#subscriptionService.startSubscriptionWithCard(request);\n }\n\n #assertIsUserNotSubscribed({ products }: { products: ProductType[] }) {\n if (\n this.state.subscriptions.find((subscription) =>\n subscription.products.some((p) => products.includes(p.name)),\n )\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"]}
|
@@ -41,6 +41,10 @@ class SubscriptionService {
|
|
41
41
|
const path = 'subscriptions/card';
|
42
42
|
return await __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_makeRequest).call(this, path, 'POST', request);
|
43
43
|
}
|
44
|
+
async getPricing() {
|
45
|
+
const path = 'pricing';
|
46
|
+
return await __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_makeRequest).call(this, path);
|
47
|
+
}
|
44
48
|
}
|
45
49
|
exports.SubscriptionService = SubscriptionService;
|
46
50
|
_SubscriptionService_env = new WeakMap(), _SubscriptionService_fetch = new WeakMap(), _SubscriptionService_instances = new WeakSet(), _SubscriptionService_makeRequest = async function _SubscriptionService_makeRequest(path, method = 'GET', body) {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"SubscriptionService.cjs","sourceRoot":"","sources":["../src/SubscriptionService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,+CAIqB;AACrB,yCAAoD;
|
1
|
+
{"version":3,"file":"SubscriptionService.cjs","sourceRoot":"","sources":["../src/SubscriptionService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,+CAIqB;AACrB,yCAAoD;AAqB7C,MAAM,gBAAgB,GAAG,CAAC,GAAQ,EAAE,IAAY,EAAE,EAAE,CACzD,GAAG,IAAA,sBAAU,EAAC,GAAG,CAAC,CAAC,kBAAkB,W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,\n} from './constants';\nimport { SubscriptionServiceError } from './errors';\nimport type {\n AuthUtils,\n GetSubscriptionsResponse,\n ISubscriptionService,\n PricingResponse,\n StartSubscriptionRequest,\n StartSubscriptionResponse,\n} from './types';\n\nexport type SubscriptionServiceConfig = {\n env: Env;\n auth: AuthUtils;\n fetchFn: typeof globalThis.fetch;\n};\n\ntype ErrorMessage = {\n message: string;\n error: string;\n};\n\nexport const SUBSCRIPTION_URL = (env: Env, path: string) =>\n `${getEnvUrls(env).subscriptionApiUrl}/api/v1/${path}`;\n\nexport class SubscriptionService implements ISubscriptionService {\n readonly #env: Env;\n\n readonly #fetch: typeof globalThis.fetch;\n\n public authUtils: AuthUtils;\n\n constructor(config: SubscriptionServiceConfig) {\n this.#env = config.env;\n this.authUtils = config.auth;\n this.#fetch = config.fetchFn;\n }\n\n async getSubscriptions(): Promise<GetSubscriptionsResponse> {\n const path = 'subscriptions';\n return await this.#makeRequest(path);\n }\n\n async cancelSubscription(params: { subscriptionId: string }): Promise<void> {\n const path = `subscriptions/${params.subscriptionId}`;\n return await this.#makeRequest(path, 'DELETE');\n }\n\n async startSubscriptionWithCard(\n request: StartSubscriptionRequest,\n ): Promise<StartSubscriptionResponse> {\n if (request.products.length === 0) {\n throw new SubscriptionServiceError(\n SubscriptionControllerErrorMessage.SubscriptionProductsEmpty,\n );\n }\n const path = 'subscriptions/card';\n\n return await this.#makeRequest(path, 'POST', request);\n }\n\n async #makeRequest<Result>(\n path: string,\n method: 'GET' | 'POST' | 'DELETE' | 'PUT' | 'PATCH' = 'GET',\n body?: Record<string, unknown>,\n ): Promise<Result> {\n try {\n const headers = await this.#getAuthorizationHeader();\n const url = new URL(SUBSCRIPTION_URL(this.#env, path));\n\n const response = await this.#fetch(url.toString(), {\n method,\n headers: {\n 'Content-Type': 'application/json',\n ...headers,\n },\n body: body ? JSON.stringify(body) : undefined,\n });\n\n const responseBody = await response.json();\n if (!response.ok) {\n const { message, error } = responseBody as ErrorMessage;\n throw new Error(`HTTP error message: ${message}, error: ${error}`);\n }\n\n return responseBody as Result;\n } catch (e) {\n const errorMessage =\n e instanceof Error ? e.message : JSON.stringify(e ?? 'unknown error');\n\n throw new SubscriptionServiceError(\n `failed to make request. ${errorMessage}`,\n );\n }\n }\n\n async #getAuthorizationHeader(): Promise<{ Authorization: string }> {\n const accessToken = await this.authUtils.getAccessToken();\n return { Authorization: `Bearer ${accessToken}` };\n }\n\n async getPricing(): Promise<PricingResponse> {\n const path = 'pricing';\n return await this.#makeRequest<PricingResponse>(path);\n }\n}\n"]}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { type Env } from "./constants.cjs";
|
2
|
-
import type { AuthUtils, GetSubscriptionsResponse, ISubscriptionService, StartSubscriptionRequest, StartSubscriptionResponse } from "./types.cjs";
|
2
|
+
import type { AuthUtils, GetSubscriptionsResponse, ISubscriptionService, PricingResponse, StartSubscriptionRequest, StartSubscriptionResponse } from "./types.cjs";
|
3
3
|
export type SubscriptionServiceConfig = {
|
4
4
|
env: Env;
|
5
5
|
auth: AuthUtils;
|
@@ -15,5 +15,6 @@ export declare class SubscriptionService implements ISubscriptionService {
|
|
15
15
|
subscriptionId: string;
|
16
16
|
}): Promise<void>;
|
17
17
|
startSubscriptionWithCard(request: StartSubscriptionRequest): Promise<StartSubscriptionResponse>;
|
18
|
+
getPricing(): Promise<PricingResponse>;
|
18
19
|
}
|
19
20
|
//# sourceMappingURL=SubscriptionService.d.cts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"SubscriptionService.d.cts","sourceRoot":"","sources":["../src/SubscriptionService.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,GAAG,EACT,wBAAoB;AAErB,OAAO,KAAK,EACV,SAAS,EACT,wBAAwB,EACxB,oBAAoB,EACpB,wBAAwB,EACxB,yBAAyB,EAC1B,oBAAgB;AAEjB,MAAM,MAAM,yBAAyB,GAAG;IACtC,GAAG,EAAE,GAAG,CAAC;IACT,IAAI,EAAE,SAAS,CAAC;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UAAU,IAAI,OAAO,CAAC,eAAe,CAAC;CAI7C"}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { type Env } from "./constants.mjs";
|
2
|
-
import type { AuthUtils, GetSubscriptionsResponse, ISubscriptionService, StartSubscriptionRequest, StartSubscriptionResponse } from "./types.mjs";
|
2
|
+
import type { AuthUtils, GetSubscriptionsResponse, ISubscriptionService, PricingResponse, StartSubscriptionRequest, StartSubscriptionResponse } from "./types.mjs";
|
3
3
|
export type SubscriptionServiceConfig = {
|
4
4
|
env: Env;
|
5
5
|
auth: AuthUtils;
|
@@ -15,5 +15,6 @@ export declare class SubscriptionService implements ISubscriptionService {
|
|
15
15
|
subscriptionId: string;
|
16
16
|
}): Promise<void>;
|
17
17
|
startSubscriptionWithCard(request: StartSubscriptionRequest): Promise<StartSubscriptionResponse>;
|
18
|
+
getPricing(): Promise<PricingResponse>;
|
18
19
|
}
|
19
20
|
//# sourceMappingURL=SubscriptionService.d.mts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"SubscriptionService.d.mts","sourceRoot":"","sources":["../src/SubscriptionService.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,GAAG,EACT,wBAAoB;AAErB,OAAO,KAAK,EACV,SAAS,EACT,wBAAwB,EACxB,oBAAoB,EACpB,wBAAwB,EACxB,yBAAyB,EAC1B,oBAAgB;AAEjB,MAAM,MAAM,yBAAyB,GAAG;IACtC,GAAG,EAAE,GAAG,CAAC;IACT,IAAI,EAAE,SAAS,CAAC;IAChB,OAAO,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;CAClC,CAAC;AAOF,eAAO,MAAM,gBAAgB,QAAS,GAAG,QAAQ,MAAM,WACC,CAAC;AAEzD,qBAAa,mBAAoB,YAAW,oBAAoB;;IAKvD,SAAS,EAAE,SAAS,CAAC;gBAEhB,MAAM,EAAE,yBAAyB;IAMvC,gBAAgB,IAAI,OAAO,CAAC,wBAAwB,CAAC;IAKrD,kBAAkB,CAAC,MAAM,EAAE;QAAE,cAAc,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAKrE,yBAAyB,CAC7B,OAAO,EAAE,wBAAwB,GAChC,OAAO,CAAC,yBAAyB,CAAC;
|
1
|
+
{"version":3,"file":"SubscriptionService.d.mts","sourceRoot":"","sources":["../src/SubscriptionService.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,GAAG,EACT,wBAAoB;AAErB,OAAO,KAAK,EACV,SAAS,EACT,wBAAwB,EACxB,oBAAoB,EACpB,eAAe,EACf,wBAAwB,EACxB,yBAAyB,EAC1B,oBAAgB;AAEjB,MAAM,MAAM,yBAAyB,GAAG;IACtC,GAAG,EAAE,GAAG,CAAC;IACT,IAAI,EAAE,SAAS,CAAC;IAChB,OAAO,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;CAClC,CAAC;AAOF,eAAO,MAAM,gBAAgB,QAAS,GAAG,QAAQ,MAAM,WACC,CAAC;AAEzD,qBAAa,mBAAoB,YAAW,oBAAoB;;IAKvD,SAAS,EAAE,SAAS,CAAC;gBAEhB,MAAM,EAAE,yBAAyB;IAMvC,gBAAgB,IAAI,OAAO,CAAC,wBAAwB,CAAC;IAKrD,kBAAkB,CAAC,MAAM,EAAE;QAAE,cAAc,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAKrE,yBAAyB,CAC7B,OAAO,EAAE,wBAAwB,GAChC,OAAO,CAAC,yBAAyB,CAAC;IAmD/B,UAAU,IAAI,OAAO,CAAC,eAAe,CAAC;CAI7C"}
|
@@ -37,6 +37,10 @@ export class SubscriptionService {
|
|
37
37
|
const path = 'subscriptions/card';
|
38
38
|
return await __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_makeRequest).call(this, path, 'POST', request);
|
39
39
|
}
|
40
|
+
async getPricing() {
|
41
|
+
const path = 'pricing';
|
42
|
+
return await __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_makeRequest).call(this, path);
|
43
|
+
}
|
40
44
|
}
|
41
45
|
_SubscriptionService_env = new WeakMap(), _SubscriptionService_fetch = new WeakMap(), _SubscriptionService_instances = new WeakSet(), _SubscriptionService_makeRequest = async function _SubscriptionService_makeRequest(path, method = 'GET', body) {
|
42
46
|
try {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"SubscriptionService.mjs","sourceRoot":"","sources":["../src/SubscriptionService.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EACL,UAAU,EACV,kCAAkC,EAEnC,wBAAoB;AACrB,OAAO,EAAE,wBAAwB,EAAE,qBAAiB;
|
1
|
+
{"version":3,"file":"SubscriptionService.mjs","sourceRoot":"","sources":["../src/SubscriptionService.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EACL,UAAU,EACV,kCAAkC,EAEnC,wBAAoB;AACrB,OAAO,EAAE,wBAAwB,EAAE,qBAAiB;AAqBpD,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,GAAQ,EAAE,IAAY,EAAE,EAAE,CACzD,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,kBAAkB,WAAW,IAAI,EAAE,CAAC;AAEzD,MAAM,OAAO,mBAAmB;IAO9B,YAAY,MAAiC;;QANpC,2CAAU;QAEV,6CAAgC;QAKvC,uBAAA,IAAI,4BAAQ,MAAM,CAAC,GAAG,MAAA,CAAC;QACvB,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC;QAC7B,uBAAA,IAAI,8BAAU,MAAM,CAAC,OAAO,MAAA,CAAC;IAC/B,CAAC;IAED,KAAK,CAAC,gBAAgB;QACpB,MAAM,IAAI,GAAG,eAAe,CAAC;QAC7B,OAAO,MAAM,uBAAA,IAAI,wEAAa,MAAjB,IAAI,EAAc,IAAI,CAAC,CAAC;IACvC,CAAC;IAED,KAAK,CAAC,kBAAkB,CAAC,MAAkC;QACzD,MAAM,IAAI,GAAG,iBAAiB,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QAC3C,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE;YAChB,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,YAA4B,CAAC;YACxD,MAAM,IAAI,KAAK,CAAC,uBAAuB,OAAO,YAAY,KAAK,EAAE,CAAC,CAAC;SACpE;QAED,OAAO,YAAsB,CAAC;KAC/B;IAAC,OAAO,CAAC,EAAE;QACV,MAAM,YAAY,GAChB,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,IAAI,eAAe,CAAC,CAAC;QAExE,MAAM,IAAI,wBAAwB,CAChC,2BAA2B,YAAY,EAAE,CAC1C,CAAC;KACH;AACH,CAAC,gDAED,KAAK;IACH,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,cAAc,EAAE,CAAC;IAC1D,OAAO,EAAE,aAAa,EAAE,UAAU,WAAW,EAAE,EAAE,CAAC;AACpD,CAAC","sourcesContent":["import {\n getEnvUrls,\n SubscriptionControllerErrorMessage,\n type Env,\n} from './constants';\nimport { SubscriptionServiceError } from './errors';\nimport type {\n AuthUtils,\n GetSubscriptionsResponse,\n ISubscriptionService,\n PricingResponse,\n StartSubscriptionRequest,\n StartSubscriptionResponse,\n} from './types';\n\nexport type SubscriptionServiceConfig = {\n env: Env;\n auth: AuthUtils;\n fetchFn: typeof globalThis.fetch;\n};\n\ntype ErrorMessage = {\n message: string;\n error: string;\n};\n\nexport const SUBSCRIPTION_URL = (env: Env, path: string) =>\n `${getEnvUrls(env).subscriptionApiUrl}/api/v1/${path}`;\n\nexport class SubscriptionService implements ISubscriptionService {\n readonly #env: Env;\n\n readonly #fetch: typeof globalThis.fetch;\n\n public authUtils: AuthUtils;\n\n constructor(config: SubscriptionServiceConfig) {\n this.#env = config.env;\n this.authUtils = config.auth;\n this.#fetch = config.fetchFn;\n }\n\n async getSubscriptions(): Promise<GetSubscriptionsResponse> {\n const path = 'subscriptions';\n return await this.#makeRequest(path);\n }\n\n async cancelSubscription(params: { subscriptionId: string }): Promise<void> {\n const path = `subscriptions/${params.subscriptionId}`;\n return await this.#makeRequest(path, 'DELETE');\n }\n\n async startSubscriptionWithCard(\n request: StartSubscriptionRequest,\n ): Promise<StartSubscriptionResponse> {\n if (request.products.length === 0) {\n throw new SubscriptionServiceError(\n SubscriptionControllerErrorMessage.SubscriptionProductsEmpty,\n );\n }\n const path = 'subscriptions/card';\n\n return await this.#makeRequest(path, 'POST', request);\n }\n\n async #makeRequest<Result>(\n path: string,\n method: 'GET' | 'POST' | 'DELETE' | 'PUT' | 'PATCH' = 'GET',\n body?: Record<string, unknown>,\n ): Promise<Result> {\n try {\n const headers = await this.#getAuthorizationHeader();\n const url = new URL(SUBSCRIPTION_URL(this.#env, path));\n\n const response = await this.#fetch(url.toString(), {\n method,\n headers: {\n 'Content-Type': 'application/json',\n ...headers,\n },\n body: body ? JSON.stringify(body) : undefined,\n });\n\n const responseBody = await response.json();\n if (!response.ok) {\n const { message, error } = responseBody as ErrorMessage;\n throw new Error(`HTTP error message: ${message}, error: ${error}`);\n }\n\n return responseBody as Result;\n } catch (e) {\n const errorMessage =\n e instanceof Error ? e.message : JSON.stringify(e ?? 'unknown error');\n\n throw new SubscriptionServiceError(\n `failed to make request. ${errorMessage}`,\n );\n }\n }\n\n async #getAuthorizationHeader(): Promise<{ Authorization: string }> {\n const accessToken = await this.authUtils.getAccessToken();\n return { Authorization: `Bearer ${accessToken}` };\n }\n\n async getPricing(): Promise<PricingResponse> {\n const path = 'pricing';\n return await this.#makeRequest<PricingResponse>(path);\n }\n}\n"]}
|
package/dist/index.cjs.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAaA,uEAGkC;AAFhC,gIAAA,sBAAsB,OAAA;AACtB,+IAAA,qCAAqC,OAAA;AAiBvC,uCAAoD;AAA3C,kHAAA,wBAAwB,OAAA;AACjC,6CAAsE;AAA7D,gGAAA,GAAG,OAAA;AAAE,+HAAA,kCAAkC,OAAA;AAEhD,iEAA4D;AAAnD,0HAAA,mBAAmB,OAAA","sourcesContent":["export type {\n SubscriptionControllerActions,\n SubscriptionControllerState,\n SubscriptionControllerEvents,\n SubscriptionControllerGetSubscriptionsAction,\n SubscriptionControllerCancelSubscriptionAction,\n SubscriptionControllerStartShieldSubscriptionWithCardAction,\n SubscriptionControllerGetPricingAction,\n SubscriptionControllerGetStateAction,\n SubscriptionControllerMessenger,\n SubscriptionControllerOptions,\n SubscriptionControllerStateChangeEvent,\n} from './SubscriptionController';\nexport {\n SubscriptionController,\n getDefaultSubscriptionControllerState,\n} from './SubscriptionController';\nexport type {\n Subscription,\n AuthUtils,\n ISubscriptionService,\n PaymentMethod,\n PaymentType,\n Product,\n ProductType,\n ProductPrice,\n ProductPricing,\n TokenPaymentInfo,\n ChainPaymentInfo,\n PricingPaymentMethod,\n PricingResponse,\n} from './types';\nexport { SubscriptionServiceError } from './errors';\nexport { Env, SubscriptionControllerErrorMessage } from './constants';\nexport type { SubscriptionServiceConfig } from './SubscriptionService';\nexport { SubscriptionService } from './SubscriptionService';\n"]}
|
package/dist/index.d.cts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
export type { SubscriptionControllerActions, SubscriptionControllerState, SubscriptionControllerEvents, SubscriptionControllerGetSubscriptionsAction, SubscriptionControllerCancelSubscriptionAction, SubscriptionControllerStartShieldSubscriptionWithCardAction, SubscriptionControllerGetStateAction, SubscriptionControllerMessenger, SubscriptionControllerOptions, SubscriptionControllerStateChangeEvent, } from "./SubscriptionController.cjs";
|
1
|
+
export type { SubscriptionControllerActions, SubscriptionControllerState, SubscriptionControllerEvents, SubscriptionControllerGetSubscriptionsAction, SubscriptionControllerCancelSubscriptionAction, SubscriptionControllerStartShieldSubscriptionWithCardAction, SubscriptionControllerGetPricingAction, SubscriptionControllerGetStateAction, SubscriptionControllerMessenger, SubscriptionControllerOptions, SubscriptionControllerStateChangeEvent, } from "./SubscriptionController.cjs";
|
2
2
|
export { SubscriptionController, getDefaultSubscriptionControllerState, } from "./SubscriptionController.cjs";
|
3
|
-
export type { Subscription, AuthUtils, ISubscriptionService, PaymentMethod, PaymentType, Product, ProductType, } from "./types.cjs";
|
3
|
+
export type { Subscription, AuthUtils, ISubscriptionService, PaymentMethod, PaymentType, Product, ProductType, ProductPrice, ProductPricing, TokenPaymentInfo, ChainPaymentInfo, PricingPaymentMethod, PricingResponse, } from "./types.cjs";
|
4
4
|
export { SubscriptionServiceError } from "./errors.cjs";
|
5
5
|
export { Env, SubscriptionControllerErrorMessage } from "./constants.cjs";
|
6
6
|
export type { SubscriptionServiceConfig } from "./SubscriptionService.cjs";
|
package/dist/index.d.cts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,6BAA6B,EAC7B,2BAA2B,EAC3B,4BAA4B,EAC5B,4CAA4C,EAC5C,8CAA8C,EAC9C,2DAA2D,EAC3D,oCAAoC,EACpC,+BAA+B,EAC/B,6BAA6B,EAC7B,sCAAsC,GACvC,qCAAiC;AAClC,OAAO,EACL,sBAAsB,EACtB,qCAAqC,GACtC,qCAAiC;AAClC,YAAY,EACV,YAAY,EACZ,SAAS,EACT,oBAAoB,EACpB,aAAa,EACb,WAAW,EACX,OAAO,EACP,WAAW,
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,6BAA6B,EAC7B,2BAA2B,EAC3B,4BAA4B,EAC5B,4CAA4C,EAC5C,8CAA8C,EAC9C,2DAA2D,EAC3D,sCAAsC,EACtC,oCAAoC,EACpC,+BAA+B,EAC/B,6BAA6B,EAC7B,sCAAsC,GACvC,qCAAiC;AAClC,OAAO,EACL,sBAAsB,EACtB,qCAAqC,GACtC,qCAAiC;AAClC,YAAY,EACV,YAAY,EACZ,SAAS,EACT,oBAAoB,EACpB,aAAa,EACb,WAAW,EACX,OAAO,EACP,WAAW,EACX,YAAY,EACZ,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAChB,oBAAoB,EACpB,eAAe,GAChB,oBAAgB;AACjB,OAAO,EAAE,wBAAwB,EAAE,qBAAiB;AACpD,OAAO,EAAE,GAAG,EAAE,kCAAkC,EAAE,wBAAoB;AACtE,YAAY,EAAE,yBAAyB,EAAE,kCAA8B;AACvE,OAAO,EAAE,mBAAmB,EAAE,kCAA8B"}
|
package/dist/index.d.mts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
export type { SubscriptionControllerActions, SubscriptionControllerState, SubscriptionControllerEvents, SubscriptionControllerGetSubscriptionsAction, SubscriptionControllerCancelSubscriptionAction, SubscriptionControllerStartShieldSubscriptionWithCardAction, SubscriptionControllerGetStateAction, SubscriptionControllerMessenger, SubscriptionControllerOptions, SubscriptionControllerStateChangeEvent, } from "./SubscriptionController.mjs";
|
1
|
+
export type { SubscriptionControllerActions, SubscriptionControllerState, SubscriptionControllerEvents, SubscriptionControllerGetSubscriptionsAction, SubscriptionControllerCancelSubscriptionAction, SubscriptionControllerStartShieldSubscriptionWithCardAction, SubscriptionControllerGetPricingAction, SubscriptionControllerGetStateAction, SubscriptionControllerMessenger, SubscriptionControllerOptions, SubscriptionControllerStateChangeEvent, } from "./SubscriptionController.mjs";
|
2
2
|
export { SubscriptionController, getDefaultSubscriptionControllerState, } from "./SubscriptionController.mjs";
|
3
|
-
export type { Subscription, AuthUtils, ISubscriptionService, PaymentMethod, PaymentType, Product, ProductType, } from "./types.mjs";
|
3
|
+
export type { Subscription, AuthUtils, ISubscriptionService, PaymentMethod, PaymentType, Product, ProductType, ProductPrice, ProductPricing, TokenPaymentInfo, ChainPaymentInfo, PricingPaymentMethod, PricingResponse, } from "./types.mjs";
|
4
4
|
export { SubscriptionServiceError } from "./errors.mjs";
|
5
5
|
export { Env, SubscriptionControllerErrorMessage } from "./constants.mjs";
|
6
6
|
export type { SubscriptionServiceConfig } from "./SubscriptionService.mjs";
|
package/dist/index.d.mts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,6BAA6B,EAC7B,2BAA2B,EAC3B,4BAA4B,EAC5B,4CAA4C,EAC5C,8CAA8C,EAC9C,2DAA2D,EAC3D,oCAAoC,EACpC,+BAA+B,EAC/B,6BAA6B,EAC7B,sCAAsC,GACvC,qCAAiC;AAClC,OAAO,EACL,sBAAsB,EACtB,qCAAqC,GACtC,qCAAiC;AAClC,YAAY,EACV,YAAY,EACZ,SAAS,EACT,oBAAoB,EACpB,aAAa,EACb,WAAW,EACX,OAAO,EACP,WAAW,
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,6BAA6B,EAC7B,2BAA2B,EAC3B,4BAA4B,EAC5B,4CAA4C,EAC5C,8CAA8C,EAC9C,2DAA2D,EAC3D,sCAAsC,EACtC,oCAAoC,EACpC,+BAA+B,EAC/B,6BAA6B,EAC7B,sCAAsC,GACvC,qCAAiC;AAClC,OAAO,EACL,sBAAsB,EACtB,qCAAqC,GACtC,qCAAiC;AAClC,YAAY,EACV,YAAY,EACZ,SAAS,EACT,oBAAoB,EACpB,aAAa,EACb,WAAW,EACX,OAAO,EACP,WAAW,EACX,YAAY,EACZ,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAChB,oBAAoB,EACpB,eAAe,GAChB,oBAAgB;AACjB,OAAO,EAAE,wBAAwB,EAAE,qBAAiB;AACpD,OAAO,EAAE,GAAG,EAAE,kCAAkC,EAAE,wBAAoB;AACtE,YAAY,EAAE,yBAAyB,EAAE,kCAA8B;AACvE,OAAO,EAAE,mBAAmB,EAAE,kCAA8B"}
|
package/dist/index.mjs.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,OAAO,EACL,sBAAsB,EACtB,qCAAqC,EACtC,qCAAiC;AAgBlC,OAAO,EAAE,wBAAwB,EAAE,qBAAiB;AACpD,OAAO,EAAE,GAAG,EAAE,kCAAkC,EAAE,wBAAoB;AAEtE,OAAO,EAAE,mBAAmB,EAAE,kCAA8B","sourcesContent":["export type {\n SubscriptionControllerActions,\n SubscriptionControllerState,\n SubscriptionControllerEvents,\n SubscriptionControllerGetSubscriptionsAction,\n SubscriptionControllerCancelSubscriptionAction,\n SubscriptionControllerStartShieldSubscriptionWithCardAction,\n SubscriptionControllerGetPricingAction,\n SubscriptionControllerGetStateAction,\n SubscriptionControllerMessenger,\n SubscriptionControllerOptions,\n SubscriptionControllerStateChangeEvent,\n} from './SubscriptionController';\nexport {\n SubscriptionController,\n getDefaultSubscriptionControllerState,\n} from './SubscriptionController';\nexport type {\n Subscription,\n AuthUtils,\n ISubscriptionService,\n PaymentMethod,\n PaymentType,\n Product,\n ProductType,\n ProductPrice,\n ProductPricing,\n TokenPaymentInfo,\n ChainPaymentInfo,\n PricingPaymentMethod,\n PricingResponse,\n} from './types';\nexport { SubscriptionServiceError } from './errors';\nexport { Env, SubscriptionControllerErrorMessage } from './constants';\nexport type { SubscriptionServiceConfig } from './SubscriptionService';\nexport { SubscriptionService } from './SubscriptionService';\n"]}
|
package/dist/types.cjs.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAAA,IAAY,WAEX;AAFD,WAAY,WAAW;IACrB,gCAAiB,CAAA;AACnB,CAAC,EAFW,WAAW,2BAAX,WAAW,QAEtB;AASD,IAAY,WAGX;AAHD,WAAY,WAAW;IACrB,8BAAe,CAAA;IACf,kCAAmB,CAAA;AACrB,CAAC,EAHW,WAAW,2BAAX,WAAW,QAGtB;AAED,IAAY,iBAGX;AAHD,WAAY,iBAAiB;IAC3B,oCAAe,CAAA;IACf,kCAAa,CAAA;AACf,CAAC,EAHW,iBAAiB,iCAAjB,iBAAiB,QAG5B;AAWD,IAAY,kBAmBX;AAnBD,WAAY,kBAAkB;IAC5B,iBAAiB;IACjB,+CAAyB,CAAA;IACzB,8DAAwC,CAAA;IAExC,gBAAgB;IAChB,iDAA2B,CAAA;IAC3B,2CAAqB,CAAA;IACrB,uCAAiB,CAAA;IAEjB,iBAAiB;IACjB,0CAAoB,CAAA;IACpB,uCAAiB,CAAA;IAEjB,mBAAmB;IACnB,2CAAqB,CAAA;IAErB,gBAAgB;IAChB,uCAAiB,CAAA;AACnB,CAAC,EAnBW,kBAAkB,kCAAlB,kBAAkB,QAmB7B","sourcesContent":["export enum ProductType {\n SHIELD = 'shield',\n}\n\nexport type Product = {\n name: ProductType;\n id: string;\n currency: string;\n amount: number;\n};\n\nexport enum PaymentType {\n byCard = 'card',\n byCrypto = 'crypto',\n}\n\nexport enum RecurringInterval {\n month = 'month',\n year = 'year',\n}\n\nexport type PaymentMethod = {\n type: PaymentType;\n crypto?: {\n payerAddress: string;\n chainId: string;\n tokenSymbol: string;\n };\n};\n\nexport enum SubscriptionStatus {\n // Initial states\n incomplete = 'incomplete',\n incompleteExpired = 'incomplete_expired',\n\n // Active states\n provisional = 'provisional',\n trialing = 'trialing',\n active = 'active',\n\n // Payment issues\n pastDue = 'past_due',\n unpaid = 'unpaid',\n\n // Cancelled states\n canceled = 'canceled',\n\n // Paused states\n paused = 'paused',\n}\n\n// state\nexport type Subscription = {\n id: string;\n products: Product[];\n currentPeriodStart: string; // ISO 8601\n currentPeriodEnd: string; // ISO 8601\n status: SubscriptionStatus;\n interval: RecurringInterval;\n paymentMethod: PaymentMethod;\n};\n\nexport type GetSubscriptionsResponse = {\n customerId?: string;\n subscriptions: Subscription[];\n trialedProducts: ProductType[];\n};\n\nexport type StartSubscriptionRequest = {\n products: ProductType[];\n isTrialRequested: boolean;\n recurringInterval: RecurringInterval;\n};\n\nexport type StartSubscriptionResponse = {\n checkoutSessionUrl: string;\n};\n\nexport type AuthUtils = {\n getAccessToken: () => Promise<string>;\n};\n\nexport type ISubscriptionService = {\n getSubscriptions(): Promise<GetSubscriptionsResponse>;\n cancelSubscription(request: { subscriptionId: string }): Promise<void>;\n startSubscriptionWithCard(\n request: StartSubscriptionRequest,\n ): Promise<StartSubscriptionResponse>;\n};\n"]}
|
1
|
+
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAAA,IAAY,WAEX;AAFD,WAAY,WAAW;IACrB,gCAAiB,CAAA;AACnB,CAAC,EAFW,WAAW,2BAAX,WAAW,QAEtB;AASD,IAAY,WAGX;AAHD,WAAY,WAAW;IACrB,8BAAe,CAAA;IACf,kCAAmB,CAAA;AACrB,CAAC,EAHW,WAAW,2BAAX,WAAW,QAGtB;AAED,IAAY,iBAGX;AAHD,WAAY,iBAAiB;IAC3B,oCAAe,CAAA;IACf,kCAAa,CAAA;AACf,CAAC,EAHW,iBAAiB,iCAAjB,iBAAiB,QAG5B;AAWD,IAAY,kBAmBX;AAnBD,WAAY,kBAAkB;IAC5B,iBAAiB;IACjB,+CAAyB,CAAA;IACzB,8DAAwC,CAAA;IAExC,gBAAgB;IAChB,iDAA2B,CAAA;IAC3B,2CAAqB,CAAA;IACrB,uCAAiB,CAAA;IAEjB,iBAAiB;IACjB,0CAAoB,CAAA;IACpB,uCAAiB,CAAA;IAEjB,mBAAmB;IACnB,2CAAqB,CAAA;IAErB,gBAAgB;IAChB,uCAAiB,CAAA;AACnB,CAAC,EAnBW,kBAAkB,kCAAlB,kBAAkB,QAmB7B","sourcesContent":["export enum ProductType {\n SHIELD = 'shield',\n}\n\nexport type Product = {\n name: ProductType;\n id: string;\n currency: string;\n amount: number;\n};\n\nexport enum PaymentType {\n byCard = 'card',\n byCrypto = 'crypto',\n}\n\nexport enum RecurringInterval {\n month = 'month',\n year = 'year',\n}\n\nexport type PaymentMethod = {\n type: PaymentType;\n crypto?: {\n payerAddress: string;\n chainId: string;\n tokenSymbol: string;\n };\n};\n\nexport enum SubscriptionStatus {\n // Initial states\n incomplete = 'incomplete',\n incompleteExpired = 'incomplete_expired',\n\n // Active states\n provisional = 'provisional',\n trialing = 'trialing',\n active = 'active',\n\n // Payment issues\n pastDue = 'past_due',\n unpaid = 'unpaid',\n\n // Cancelled states\n canceled = 'canceled',\n\n // Paused states\n paused = 'paused',\n}\n\n// state\nexport type Subscription = {\n id: string;\n products: Product[];\n currentPeriodStart: string; // ISO 8601\n currentPeriodEnd: string; // ISO 8601\n status: SubscriptionStatus;\n interval: RecurringInterval;\n paymentMethod: PaymentMethod;\n};\n\nexport type GetSubscriptionsResponse = {\n customerId?: string;\n subscriptions: Subscription[];\n trialedProducts: ProductType[];\n};\n\nexport type StartSubscriptionRequest = {\n products: ProductType[];\n isTrialRequested: boolean;\n recurringInterval: RecurringInterval;\n};\n\nexport type StartSubscriptionResponse = {\n checkoutSessionUrl: string;\n};\n\nexport type AuthUtils = {\n getAccessToken: () => Promise<string>;\n};\n\nexport type ProductPrice = {\n interval: string; // \"month\" | \"year\"\n unitAmount: string; // 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 currency: string; // \"usd\"\n trialPeriodDays: number;\n minBillingCycles: number;\n};\n\nexport type ProductPricing = {\n name: string;\n prices: ProductPrice[];\n};\n\nexport type TokenPaymentInfo = {\n symbol: string;\n address: string;\n decimals: number;\n conversionRate: {\n usd: string;\n };\n};\n\nexport type ChainPaymentInfo = {\n chainId: string;\n paymentAddress: string;\n tokens: TokenPaymentInfo[];\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 ISubscriptionService = {\n getSubscriptions(): Promise<GetSubscriptionsResponse>;\n cancelSubscription(request: { subscriptionId: string }): Promise<void>;\n startSubscriptionWithCard(\n request: StartSubscriptionRequest,\n ): Promise<StartSubscriptionResponse>;\n getPricing(): Promise<PricingResponse>;\n};\n"]}
|
package/dist/types.d.cts
CHANGED
@@ -59,11 +59,45 @@ export type StartSubscriptionResponse = {
|
|
59
59
|
export type AuthUtils = {
|
60
60
|
getAccessToken: () => Promise<string>;
|
61
61
|
};
|
62
|
+
export type ProductPrice = {
|
63
|
+
interval: string;
|
64
|
+
unitAmount: string;
|
65
|
+
unitDecimals: number;
|
66
|
+
currency: string;
|
67
|
+
trialPeriodDays: number;
|
68
|
+
minBillingCycles: number;
|
69
|
+
};
|
70
|
+
export type ProductPricing = {
|
71
|
+
name: string;
|
72
|
+
prices: ProductPrice[];
|
73
|
+
};
|
74
|
+
export type TokenPaymentInfo = {
|
75
|
+
symbol: string;
|
76
|
+
address: string;
|
77
|
+
decimals: number;
|
78
|
+
conversionRate: {
|
79
|
+
usd: string;
|
80
|
+
};
|
81
|
+
};
|
82
|
+
export type ChainPaymentInfo = {
|
83
|
+
chainId: string;
|
84
|
+
paymentAddress: string;
|
85
|
+
tokens: TokenPaymentInfo[];
|
86
|
+
};
|
87
|
+
export type PricingPaymentMethod = {
|
88
|
+
type: PaymentType;
|
89
|
+
chains?: ChainPaymentInfo[];
|
90
|
+
};
|
91
|
+
export type PricingResponse = {
|
92
|
+
products: ProductPricing[];
|
93
|
+
paymentMethods: PricingPaymentMethod[];
|
94
|
+
};
|
62
95
|
export type ISubscriptionService = {
|
63
96
|
getSubscriptions(): Promise<GetSubscriptionsResponse>;
|
64
97
|
cancelSubscription(request: {
|
65
98
|
subscriptionId: string;
|
66
99
|
}): Promise<void>;
|
67
100
|
startSubscriptionWithCard(request: StartSubscriptionRequest): Promise<StartSubscriptionResponse>;
|
101
|
+
getPricing(): Promise<PricingResponse>;
|
68
102
|
};
|
69
103
|
//# sourceMappingURL=types.d.cts.map
|
package/dist/types.d.cts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,oBAAY,WAAW;IACrB,MAAM,WAAW;CAClB;AAED,MAAM,MAAM,OAAO,GAAG;IACpB,IAAI,EAAE,WAAW,CAAC;IAClB,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,oBAAY,WAAW;IACrB,MAAM,SAAS;IACf,QAAQ,WAAW;CACpB;AAED,oBAAY,iBAAiB;IAC3B,KAAK,UAAU;IACf,IAAI,SAAS;CACd;AAED,MAAM,MAAM,aAAa,GAAG;IAC1B,IAAI,EAAE,WAAW,CAAC;IAClB,MAAM,CAAC,EAAE;QACP,YAAY,EAAE,MAAM,CAAC;QACrB,OAAO,EAAE,MAAM,CAAC;QAChB,WAAW,EAAE,MAAM,CAAC;KACrB,CAAC;CACH,CAAC;AAEF,oBAAY,kBAAkB;IAE5B,UAAU,eAAe;IACzB,iBAAiB,uBAAuB;IAGxC,WAAW,gBAAgB;IAC3B,QAAQ,aAAa;IACrB,MAAM,WAAW;IAGjB,OAAO,aAAa;IACpB,MAAM,WAAW;IAGjB,QAAQ,aAAa;IAGrB,MAAM,WAAW;CAClB;AAGD,MAAM,MAAM,YAAY,GAAG;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,gBAAgB,EAAE,MAAM,CAAC;IACzB,MAAM,EAAE,kBAAkB,CAAC;IAC3B,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,aAAa,EAAE,aAAa,CAAC;CAC9B,CAAC;AAEF,MAAM,MAAM,w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C;IACxB,gBAAgB,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,YAAY,EAAE,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,EAAE;QACd,GAAG,EAAE,MAAM,CAAC;KACb,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,EAAE,MAAM,CAAC;IACvB,MAAM,EAAE,gBAAgB,EAAE,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,IAAI,EAAE,WAAW,CAAC;IAClB,MAAM,CAAC,EAAE,gBAAgB,EAAE,CAAC;CAC7B,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,EAAE,cAAc,EAAE,CAAC;IAC3B,cAAc,EAAE,oBAAoB,EAAE,CAAC;CACxC,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,gBAAgB,IAAI,OAAO,CAAC,wBAAwB,CAAC,CAAC;IACtD,kBAAkB,CAAC,OAAO,EAAE;QAAE,cAAc,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACvE,yBAAyB,CACvB,OAAO,EAAE,wBAAwB,GAChC,OAAO,CAAC,yBAAyB,CAAC,CAAC;IACtC,UAAU,IAAI,OAAO,CAAC,eAAe,CAAC,CAAC;CACxC,CAAC"}
|
package/dist/types.d.mts
CHANGED
@@ -59,11 +59,45 @@ export type StartSubscriptionResponse = {
|
|
59
59
|
export type AuthUtils = {
|
60
60
|
getAccessToken: () => Promise<string>;
|
61
61
|
};
|
62
|
+
export type ProductPrice = {
|
63
|
+
interval: string;
|
64
|
+
unitAmount: string;
|
65
|
+
unitDecimals: number;
|
66
|
+
currency: string;
|
67
|
+
trialPeriodDays: number;
|
68
|
+
minBillingCycles: number;
|
69
|
+
};
|
70
|
+
export type ProductPricing = {
|
71
|
+
name: string;
|
72
|
+
prices: ProductPrice[];
|
73
|
+
};
|
74
|
+
export type TokenPaymentInfo = {
|
75
|
+
symbol: string;
|
76
|
+
address: string;
|
77
|
+
decimals: number;
|
78
|
+
conversionRate: {
|
79
|
+
usd: string;
|
80
|
+
};
|
81
|
+
};
|
82
|
+
export type ChainPaymentInfo = {
|
83
|
+
chainId: string;
|
84
|
+
paymentAddress: string;
|
85
|
+
tokens: TokenPaymentInfo[];
|
86
|
+
};
|
87
|
+
export type PricingPaymentMethod = {
|
88
|
+
type: PaymentType;
|
89
|
+
chains?: ChainPaymentInfo[];
|
90
|
+
};
|
91
|
+
export type PricingResponse = {
|
92
|
+
products: ProductPricing[];
|
93
|
+
paymentMethods: PricingPaymentMethod[];
|
94
|
+
};
|
62
95
|
export type ISubscriptionService = {
|
63
96
|
getSubscriptions(): Promise<GetSubscriptionsResponse>;
|
64
97
|
cancelSubscription(request: {
|
65
98
|
subscriptionId: string;
|
66
99
|
}): Promise<void>;
|
67
100
|
startSubscriptionWithCard(request: StartSubscriptionRequest): Promise<StartSubscriptionResponse>;
|
101
|
+
getPricing(): Promise<PricingResponse>;
|
68
102
|
};
|
69
103
|
//# sourceMappingURL=types.d.mts.map
|
package/dist/types.d.mts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,oBAAY,WAAW;IACrB,MAAM,WAAW;CAClB;AAED,MAAM,MAAM,OAAO,GAAG;IACpB,IAAI,EAAE,WAAW,CAAC;IAClB,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,oBA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AAwC,CAAA;IAExC,gBAAgB;IAChB,iDAA2B,CAAA;IAC3B,2CAAqB,CAAA;IACrB,uCAAiB,CAAA;IAEjB,iBAAiB;IACjB,0CAAoB,CAAA;IACpB,uCAAiB,CAAA;IAEjB,mBAAmB;IACnB,2CAAqB,CAAA;IAErB,gBAAgB;IAChB,uCAAiB,CAAA;AACnB,CAAC,EAnBW,kBAAkB,KAAlB,kBAAkB,QAmB7B","sourcesContent":["export enum ProductType {\n SHIELD = 'shield',\n}\n\nexport type Product = {\n name: ProductType;\n id: string;\n currency: string;\n amount: number;\n};\n\nexport enum PaymentType {\n byCard = 'card',\n byCrypto = 'crypto',\n}\n\nexport enum RecurringInterval {\n month = 'month',\n year = 'year',\n}\n\nexport type PaymentMethod = {\n type: PaymentType;\n crypto?: {\n payerAddress: string;\n chainId: string;\n tokenSymbol: string;\n };\n};\n\nexport enum SubscriptionStatus {\n // Initial states\n incomplete = 'incomplete',\n incompleteExpired = 'incomplete_expired',\n\n // Active states\n provisional = 'provisional',\n trialing = 'trialing',\n active = 'active',\n\n // Payment issues\n pastDue = 'past_due',\n unpaid = 'unpaid',\n\n // Cancelled states\n canceled = 'canceled',\n\n // Paused states\n paused = 'paused',\n}\n\n// state\nexport type Subscription = {\n id: string;\n products: Product[];\n currentPeriodStart: string; // ISO 8601\n currentPeriodEnd: string; // ISO 8601\n status: SubscriptionStatus;\n interval: RecurringInterval;\n paymentMethod: PaymentMethod;\n};\n\nexport type GetSubscriptionsResponse = {\n customerId?: string;\n subscriptions: Subscription[];\n trialedProducts: ProductType[];\n};\n\nexport type StartSubscriptionRequest = {\n products: ProductType[];\n isTrialRequested: boolean;\n recurringInterval: RecurringInterval;\n};\n\nexport type StartSubscriptionResponse = {\n checkoutSessionUrl: string;\n};\n\nexport type AuthUtils = {\n getAccessToken: () => Promise<string>;\n};\n\nexport type ISubscriptionService = {\n getSubscriptions(): Promise<GetSubscriptionsResponse>;\n cancelSubscription(request: { subscriptionId: string }): Promise<void>;\n startSubscriptionWithCard(\n request: StartSubscriptionRequest,\n ): Promise<StartSubscriptionResponse>;\n};\n"]}
|
1
|
+
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,WAEX;AAFD,WAAY,WAAW;IACrB,gCAAiB,CAAA;AACnB,CAAC,EAFW,WAAW,KAAX,WAAW,QAEtB;AASD,MAAM,CAAN,IAAY,WAGX;AAHD,WAAY,WAAW;IACrB,8BAAe,CAAA;IACf,kCAAmB,CAAA;AACrB,CAAC,EAHW,WAAW,KAAX,WAAW,QAGtB;AAED,MAAM,CAAN,IAAY,iBAGX;AAHD,WAAY,iBAAiB;IAC3B,oCAAe,CAAA;IACf,kCAAa,CAAA;AACf,CAAC,EAHW,iBAAiB,KAAjB,iBAAiB,QAG5B;AAWD,MAAM,CAAN,IAAY,kBAmBX;AAnBD,WAAY,kBAAkB;IAC5B,iBAAiB;IACjB,+CAAyB,CAAA;IACzB,8DAAwC,CAAA;IAExC,gBAAgB;IAChB,iDAA2B,CAAA;IAC3B,2CAAqB,CAAA;IACrB,uCAAiB,CAAA;IAEjB,iBAAiB;IACjB,0CAAoB,CAAA;IACpB,uCAAiB,CAAA;IAEjB,mBAAmB;IACnB,2CAAqB,CAAA;IAErB,gBAAgB;IAChB,uCAAiB,CAAA;AACnB,CAAC,EAnBW,kBAAkB,KAAlB,kBAAkB,QAmB7B","sourcesContent":["export enum ProductType {\n SHIELD = 'shield',\n}\n\nexport type Product = {\n name: ProductType;\n id: string;\n currency: string;\n amount: number;\n};\n\nexport enum PaymentType {\n byCard = 'card',\n byCrypto = 'crypto',\n}\n\nexport enum RecurringInterval {\n month = 'month',\n year = 'year',\n}\n\nexport type PaymentMethod = {\n type: PaymentType;\n crypto?: {\n payerAddress: string;\n chainId: string;\n tokenSymbol: string;\n };\n};\n\nexport enum SubscriptionStatus {\n // Initial states\n incomplete = 'incomplete',\n incompleteExpired = 'incomplete_expired',\n\n // Active states\n provisional = 'provisional',\n trialing = 'trialing',\n active = 'active',\n\n // Payment issues\n pastDue = 'past_due',\n unpaid = 'unpaid',\n\n // Cancelled states\n canceled = 'canceled',\n\n // Paused states\n paused = 'paused',\n}\n\n// state\nexport type Subscription = {\n id: string;\n products: Product[];\n currentPeriodStart: string; // ISO 8601\n currentPeriodEnd: string; // ISO 8601\n status: SubscriptionStatus;\n interval: RecurringInterval;\n paymentMethod: PaymentMethod;\n};\n\nexport type GetSubscriptionsResponse = {\n customerId?: string;\n subscriptions: Subscription[];\n trialedProducts: ProductType[];\n};\n\nexport type StartSubscriptionRequest = {\n products: ProductType[];\n isTrialRequested: boolean;\n recurringInterval: RecurringInterval;\n};\n\nexport type StartSubscriptionResponse = {\n checkoutSessionUrl: string;\n};\n\nexport type AuthUtils = {\n getAccessToken: () => Promise<string>;\n};\n\nexport type ProductPrice = {\n interval: string; // \"month\" | \"year\"\n unitAmount: string; // 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 currency: string; // \"usd\"\n trialPeriodDays: number;\n minBillingCycles: number;\n};\n\nexport type ProductPricing = {\n name: string;\n prices: ProductPrice[];\n};\n\nexport type TokenPaymentInfo = {\n symbol: string;\n address: string;\n decimals: number;\n conversionRate: {\n usd: string;\n };\n};\n\nexport type ChainPaymentInfo = {\n chainId: string;\n paymentAddress: string;\n tokens: TokenPaymentInfo[];\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 ISubscriptionService = {\n getSubscriptions(): Promise<GetSubscriptionsResponse>;\n cancelSubscription(request: { subscriptionId: string }): Promise<void>;\n startSubscriptionWithCard(\n request: StartSubscriptionRequest,\n ): Promise<StartSubscriptionResponse>;\n getPricing(): Promise<PricingResponse>;\n};\n"]}
|