@metamask-previews/subscription-controller 0.0.0-preview-747c1cb → 0.0.0-preview-cc039d53
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 +12 -2
- package/dist/SubscriptionController.cjs.map +1 -1
- package/dist/SubscriptionController.d.cts +14 -9
- package/dist/SubscriptionController.d.cts.map +1 -1
- package/dist/SubscriptionController.d.mts +14 -9
- package/dist/SubscriptionController.d.mts.map +1 -1
- package/dist/SubscriptionController.mjs +12 -2
- package/dist/SubscriptionController.mjs.map +1 -1
- package/dist/SubscriptionService.cjs +9 -1
- 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 +10 -2
- package/dist/SubscriptionService.mjs.map +1 -1
- package/dist/constants.cjs +1 -0
- package/dist/constants.cjs.map +1 -1
- package/dist/constants.d.cts +2 -1
- package/dist/constants.d.cts.map +1 -1
- package/dist/constants.d.mts +2 -1
- package/dist/constants.d.mts.map +1 -1
- package/dist/constants.mjs +1 -0
- package/dist/constants.mjs.map +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/types.cjs +25 -3
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +29 -6
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +29 -6
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs +24 -2
- package/dist/types.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
@@ -12,5 +12,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
12
12
|
- Initial release of the subscription controller ([#6233](https://github.com/MetaMask/core/pull/6233))
|
13
13
|
- `getSubscription`: Retrieve current user subscription info if exist.
|
14
14
|
- `cancelSubscription`: Cancel user active subscription.
|
15
|
+
- `startShieldSubscriptionWithCard`: start shield subscription via card (with trial option) ([#6300](https://github.com/MetaMask/core/pull/6300))
|
15
16
|
|
16
17
|
[Unreleased]: https://github.com/MetaMask/core/
|
@@ -10,11 +10,12 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
10
10
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
11
11
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
12
12
|
};
|
13
|
-
var _SubscriptionController_instances, _SubscriptionController_subscriptionService, _SubscriptionController_registerMessageHandlers, _SubscriptionController_assertIsUserSubscribed;
|
13
|
+
var _SubscriptionController_instances, _SubscriptionController_subscriptionService, _SubscriptionController_registerMessageHandlers, _SubscriptionController_assertIsUserNotSubscribed, _SubscriptionController_assertIsUserSubscribed;
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
15
15
|
exports.SubscriptionController = exports.getDefaultSubscriptionControllerState = void 0;
|
16
16
|
const base_controller_1 = require("@metamask/base-controller");
|
17
17
|
const constants_1 = require("./constants.cjs");
|
18
|
+
const types_1 = require("./types.cjs");
|
18
19
|
/**
|
19
20
|
* Get the default state for the Subscription Controller.
|
20
21
|
*
|
@@ -77,15 +78,24 @@ class SubscriptionController extends base_controller_1.BaseController {
|
|
77
78
|
});
|
78
79
|
this.update((state) => {
|
79
80
|
state.subscriptions = state.subscriptions.map((subscription) => subscription.id === request.subscriptionId
|
80
|
-
? { ...subscription, status:
|
81
|
+
? { ...subscription, status: types_1.SubscriptionStatus.canceled }
|
81
82
|
: subscription);
|
82
83
|
});
|
83
84
|
}
|
85
|
+
async startShieldSubscriptionWithCard(request) {
|
86
|
+
__classPrivateFieldGet(this, _SubscriptionController_instances, "m", _SubscriptionController_assertIsUserNotSubscribed).call(this, { products: request.products });
|
87
|
+
return await __classPrivateFieldGet(this, _SubscriptionController_subscriptionService, "f").startSubscriptionWithCard(request);
|
88
|
+
}
|
84
89
|
}
|
85
90
|
exports.SubscriptionController = SubscriptionController;
|
86
91
|
_SubscriptionController_subscriptionService = new WeakMap(), _SubscriptionController_instances = new WeakSet(), _SubscriptionController_registerMessageHandlers = function _SubscriptionController_registerMessageHandlers() {
|
87
92
|
this.messagingSystem.registerActionHandler('SubscriptionController:getSubscriptions', this.getSubscriptions.bind(this));
|
88
93
|
this.messagingSystem.registerActionHandler('SubscriptionController:cancelSubscription', this.cancelSubscription.bind(this));
|
94
|
+
this.messagingSystem.registerActionHandler('SubscriptionController:startShieldSubscriptionWithCard', this.startShieldSubscriptionWithCard.bind(this));
|
95
|
+
}, _SubscriptionController_assertIsUserNotSubscribed = function _SubscriptionController_assertIsUserNotSubscribed({ products }) {
|
96
|
+
if (this.state.subscriptions.find((subscription) => subscription.products.some((p) => products.includes(p.name)))) {
|
97
|
+
throw new Error(constants_1.SubscriptionControllerErrorMessage.UserAlreadySubscribed);
|
98
|
+
}
|
89
99
|
}, _SubscriptionController_assertIsUserSubscribed = function _SubscriptionController_assertIsUserSubscribed(request) {
|
90
100
|
if (!this.state.subscriptions.find((subscription) => subscription.id === request.subscriptionId)) {
|
91
101
|
throw new Error(constants_1.SubscriptionControllerErrorMessage.UserNotSubscribed);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"SubscriptionController.cjs","sourceRoot":"","sources":["../src/SubscriptionController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,+DAMmC;AAGnC,+CAGqB;
|
1
|
+
{"version":3,"file":"SubscriptionController.cjs","sourceRoot":"","sources":["../src/SubscriptionController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,+DAMmC;AAGnC,+CAGqB;AACrB,uCAMiB;AAsEjB;;;;G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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,19 +1,24 @@
|
|
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
|
4
|
+
import { type ISubscriptionService, type StartSubscriptionRequest, type Subscription } from "./types.cjs";
|
5
5
|
export type SubscriptionControllerState = {
|
6
6
|
subscriptions: Subscription[];
|
7
7
|
};
|
8
|
-
type
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
8
|
+
export type SubscriptionControllerGetSubscriptionsAction = {
|
9
|
+
type: `${typeof controllerName}:getSubscriptions`;
|
10
|
+
handler: SubscriptionController['getSubscriptions'];
|
11
|
+
};
|
12
|
+
export type SubscriptionControllerCancelSubscriptionAction = {
|
13
|
+
type: `${typeof controllerName}:cancelSubscription`;
|
14
|
+
handler: SubscriptionController['cancelSubscription'];
|
15
|
+
};
|
16
|
+
export type SubscriptionControllerStartShieldSubscriptionWithCardAction = {
|
17
|
+
type: `${typeof controllerName}:startShieldSubscriptionWithCard`;
|
18
|
+
handler: SubscriptionController['startShieldSubscriptionWithCard'];
|
13
19
|
};
|
14
|
-
type ActionsObj = CreateActionsObj<'getSubscriptions' | 'cancelSubscription'>;
|
15
20
|
export type SubscriptionControllerGetStateAction = ControllerGetStateAction<typeof controllerName, SubscriptionControllerState>;
|
16
|
-
export type SubscriptionControllerActions =
|
21
|
+
export type SubscriptionControllerActions = SubscriptionControllerGetSubscriptionsAction | SubscriptionControllerCancelSubscriptionAction | SubscriptionControllerStartShieldSubscriptionWithCardAction | SubscriptionControllerGetStateAction;
|
17
22
|
export type AllowedActions = AuthenticationController.AuthenticationControllerGetBearerToken;
|
18
23
|
export type SubscriptionControllerStateChangeEvent = ControllerStateChangeEvent<typeof controllerName, SubscriptionControllerState>;
|
19
24
|
export type SubscriptionControllerEvents = SubscriptionControllerStateChangeEvent;
|
@@ -54,6 +59,6 @@ export declare class SubscriptionController extends BaseController<typeof contro
|
|
54
59
|
cancelSubscription(request: {
|
55
60
|
subscriptionId: string;
|
56
61
|
}): Promise<void>;
|
62
|
+
startShieldSubscriptionWithCard(request: StartSubscriptionRequest): Promise<import("./types.cjs").StartSubscriptionResponse>;
|
57
63
|
}
|
58
|
-
export {};
|
59
64
|
//# sourceMappingURL=SubscriptionController.d.cts.map
|
@@ -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,KAAK,
|
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,EAEzB,KAAK,wBAAwB,EAC7B,KAAK,YAAY,EAClB,oBAAgB;AAEjB,MAAM,MAAM,2BAA2B,GAAG;IACxC,aAAa,EAAE,YAAY,EAAE,CAAC;CAC/B,CAAC;AAGF,MAAM,MAAM,4CAA4C,GAAG;IACzD,IAAI,EAAE,GAAG,OAAO,cAAc,mBAAmB,CAAC;IAClD,OAAO,EAAE,sBAAsB,CAAC,kBAAkB,CAAC,CAAC;CACrD,CAAC;AACF,MAAM,MAAM,8CAA8C,GAAG;IAC3D,IAAI,EAAE,GAAG,OAAO,cAAc,qBAAqB,CAAC;IACpD,OAAO,EAAE,sBAAsB,CAAC,oBAAoB,CAAC,CAAC;CACvD,CAAC;AACF,MAAM,MAAM,2DAA2D,GAAG;IACxE,IAAI,EAAE,GAAG,OAAO,cAAc,kCAAkC,CAAC;IACjE,OAAO,EAAE,sBAAsB,CAAC,iCAAiC,CAAC,CAAC;CAC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@
|
|
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
|
4
|
+
import { type ISubscriptionService, type StartSubscriptionRequest, type Subscription } from "./types.mjs";
|
5
5
|
export type SubscriptionControllerState = {
|
6
6
|
subscriptions: Subscription[];
|
7
7
|
};
|
8
|
-
type
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
8
|
+
export type SubscriptionControllerGetSubscriptionsAction = {
|
9
|
+
type: `${typeof controllerName}:getSubscriptions`;
|
10
|
+
handler: SubscriptionController['getSubscriptions'];
|
11
|
+
};
|
12
|
+
export type SubscriptionControllerCancelSubscriptionAction = {
|
13
|
+
type: `${typeof controllerName}:cancelSubscription`;
|
14
|
+
handler: SubscriptionController['cancelSubscription'];
|
15
|
+
};
|
16
|
+
export type SubscriptionControllerStartShieldSubscriptionWithCardAction = {
|
17
|
+
type: `${typeof controllerName}:startShieldSubscriptionWithCard`;
|
18
|
+
handler: SubscriptionController['startShieldSubscriptionWithCard'];
|
13
19
|
};
|
14
|
-
type ActionsObj = CreateActionsObj<'getSubscriptions' | 'cancelSubscription'>;
|
15
20
|
export type SubscriptionControllerGetStateAction = ControllerGetStateAction<typeof controllerName, SubscriptionControllerState>;
|
16
|
-
export type SubscriptionControllerActions =
|
21
|
+
export type SubscriptionControllerActions = SubscriptionControllerGetSubscriptionsAction | SubscriptionControllerCancelSubscriptionAction | SubscriptionControllerStartShieldSubscriptionWithCardAction | SubscriptionControllerGetStateAction;
|
17
22
|
export type AllowedActions = AuthenticationController.AuthenticationControllerGetBearerToken;
|
18
23
|
export type SubscriptionControllerStateChangeEvent = ControllerStateChangeEvent<typeof controllerName, SubscriptionControllerState>;
|
19
24
|
export type SubscriptionControllerEvents = SubscriptionControllerStateChangeEvent;
|
@@ -54,6 +59,6 @@ export declare class SubscriptionController extends BaseController<typeof contro
|
|
54
59
|
cancelSubscription(request: {
|
55
60
|
subscriptionId: string;
|
56
61
|
}): Promise<void>;
|
62
|
+
startShieldSubscriptionWithCard(request: StartSubscriptionRequest): Promise<import("./types.mjs").StartSubscriptionResponse>;
|
57
63
|
}
|
58
|
-
export {};
|
59
64
|
//# sourceMappingURL=SubscriptionController.d.mts.map
|
@@ -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,EAC7B,KAAK,mBAAmB,EACzB,kCAAkC;AACnC,OAAO,KAAK,EAAE,wBAAwB,EAAE,0CAA0C;AAElF,OAAO,EACL,cAAc,EAEf,wBAAoB;AACrB,OAAO,KAAK,
|
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,EAC7B,KAAK,mBAAmB,EACzB,kCAAkC;AACnC,OAAO,KAAK,EAAE,wBAAwB,EAAE,0CAA0C;AAElF,OAAO,EACL,cAAc,EAEf,wBAAoB;AACrB,OAAO,EAEL,KAAK,oBAAoB,EAEzB,KAAK,wBAAwB,EAC7B,KAAK,YAAY,EAClB,oBAAgB;AAEjB,MAAM,MAAM,2BAA2B,GAAG;IACxC,aAAa,EAAE,YAAY,EAAE,CAAC;CAC/B,CAAC;AAGF,MAAM,MAAM,4CAA4C,GAAG;IACzD,IAAI,EAAE,GAAG,OAAO,cAAc,mBAAmB,CAAC;IAClD,OAAO,EAAE,sBAAsB,CAAC,kBAAkB,CAAC,CAAC;CACrD,CAAC;AACF,MAAM,MAAM,8CAA8C,GAAG;IAC3D,IAAI,EAAE,GAAG,OAAO,cAAc,qBAAqB,CAAC;IACpD,OAAO,EAAE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AmB,GACpB,EAAE,6BAA6B;IAqC1B,gBAAgB;IAWhB,kBAAkB,CAAC,OAAO,EAAE;QAAE,cAAc,EAAE,MAAM,CAAA;KAAE;IAgBtD,+BAA+B,CAAC,OAAO,EAAE,wBAAwB;CAyBxE"}
|
@@ -9,9 +9,10 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
9
9
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
11
11
|
};
|
12
|
-
var _SubscriptionController_instances, _SubscriptionController_subscriptionService, _SubscriptionController_registerMessageHandlers, _SubscriptionController_assertIsUserSubscribed;
|
12
|
+
var _SubscriptionController_instances, _SubscriptionController_subscriptionService, _SubscriptionController_registerMessageHandlers, _SubscriptionController_assertIsUserNotSubscribed, _SubscriptionController_assertIsUserSubscribed;
|
13
13
|
import { BaseController } from "@metamask/base-controller";
|
14
14
|
import { controllerName, SubscriptionControllerErrorMessage } from "./constants.mjs";
|
15
|
+
import { SubscriptionStatus } from "./types.mjs";
|
15
16
|
/**
|
16
17
|
* Get the default state for the Subscription Controller.
|
17
18
|
*
|
@@ -73,14 +74,23 @@ export class SubscriptionController extends BaseController {
|
|
73
74
|
});
|
74
75
|
this.update((state) => {
|
75
76
|
state.subscriptions = state.subscriptions.map((subscription) => subscription.id === request.subscriptionId
|
76
|
-
? { ...subscription, status:
|
77
|
+
? { ...subscription, status: SubscriptionStatus.canceled }
|
77
78
|
: subscription);
|
78
79
|
});
|
79
80
|
}
|
81
|
+
async startShieldSubscriptionWithCard(request) {
|
82
|
+
__classPrivateFieldGet(this, _SubscriptionController_instances, "m", _SubscriptionController_assertIsUserNotSubscribed).call(this, { products: request.products });
|
83
|
+
return await __classPrivateFieldGet(this, _SubscriptionController_subscriptionService, "f").startSubscriptionWithCard(request);
|
84
|
+
}
|
80
85
|
}
|
81
86
|
_SubscriptionController_subscriptionService = new WeakMap(), _SubscriptionController_instances = new WeakSet(), _SubscriptionController_registerMessageHandlers = function _SubscriptionController_registerMessageHandlers() {
|
82
87
|
this.messagingSystem.registerActionHandler('SubscriptionController:getSubscriptions', this.getSubscriptions.bind(this));
|
83
88
|
this.messagingSystem.registerActionHandler('SubscriptionController:cancelSubscription', this.cancelSubscription.bind(this));
|
89
|
+
this.messagingSystem.registerActionHandler('SubscriptionController:startShieldSubscriptionWithCard', this.startShieldSubscriptionWithCard.bind(this));
|
90
|
+
}, _SubscriptionController_assertIsUserNotSubscribed = function _SubscriptionController_assertIsUserNotSubscribed({ products }) {
|
91
|
+
if (this.state.subscriptions.find((subscription) => subscription.products.some((p) => products.includes(p.name)))) {
|
92
|
+
throw new Error(SubscriptionControllerErrorMessage.UserAlreadySubscribed);
|
93
|
+
}
|
84
94
|
}, _SubscriptionController_assertIsUserSubscribed = function _SubscriptionController_assertIsUserSubscribed(request) {
|
85
95
|
if (!this.state.subscriptions.find((subscription) => subscription.id === request.subscriptionId)) {
|
86
96
|
throw new Error(SubscriptionControllerErrorMessage.UserNotSubscribed);
|
@@ -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,wBAAoB;
|
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,wBAAoB;AACrB,OAAO,EACL,kBAAkB,EAKnB,oBAAgB;AAsEjB;;;;GAIG;AACH,MAAM,UAAU,qCAAqC;IACnD,OAAO;QACL,aAAa,EAAE,EAAE;KAClB,CAAC;AACJ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AC,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"]}
|
@@ -34,9 +34,16 @@ class SubscriptionService {
|
|
34
34
|
const path = `subscriptions/${params.subscriptionId}`;
|
35
35
|
return await __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_makeRequest).call(this, path, 'DELETE');
|
36
36
|
}
|
37
|
+
async startSubscriptionWithCard(request) {
|
38
|
+
if (request.products.length === 0) {
|
39
|
+
throw new errors_1.SubscriptionServiceError(constants_1.SubscriptionControllerErrorMessage.SubscriptionProductsEmpty);
|
40
|
+
}
|
41
|
+
const path = 'subscriptions/card';
|
42
|
+
return await __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_makeRequest).call(this, path, 'POST', request);
|
43
|
+
}
|
37
44
|
}
|
38
45
|
exports.SubscriptionService = SubscriptionService;
|
39
|
-
_SubscriptionService_env = new WeakMap(), _SubscriptionService_fetch = new WeakMap(), _SubscriptionService_instances = new WeakSet(), _SubscriptionService_makeRequest = async function _SubscriptionService_makeRequest(path, method = 'GET') {
|
46
|
+
_SubscriptionService_env = new WeakMap(), _SubscriptionService_fetch = new WeakMap(), _SubscriptionService_instances = new WeakSet(), _SubscriptionService_makeRequest = async function _SubscriptionService_makeRequest(path, method = 'GET', body) {
|
40
47
|
try {
|
41
48
|
const headers = await __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_getAuthorizationHeader).call(this);
|
42
49
|
const url = new URL((0, exports.SUBSCRIPTION_URL)(__classPrivateFieldGet(this, _SubscriptionService_env, "f"), path));
|
@@ -46,6 +53,7 @@ _SubscriptionService_env = new WeakMap(), _SubscriptionService_fetch = new WeakM
|
|
46
53
|
'Content-Type': 'application/json',
|
47
54
|
...headers,
|
48
55
|
},
|
56
|
+
body: body ? JSON.stringify(body) : undefined,
|
49
57
|
});
|
50
58
|
const responseBody = await response.json();
|
51
59
|
if (!response.ok) {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"SubscriptionService.cjs","sourceRoot":"","sources":["../src/SubscriptionService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,+
|
1
|
+
{"version":3,"file":"SubscriptionService.cjs","sourceRoot":"","sources":["../src/SubscriptionService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,+CAIqB;AACrB,yCAAoD;AAoB7C,MAAM,gBAAgB,GAAG,CAAC,GAAQ,EAAE,IAAY,EAAE,EAAE,CACzD,GAAG,IAAA,sBAAU,EAAC,GAAG,CAAC,CAAC,kBAAkB,WAAW,IAAI,EAAE,CAA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,CAAC,CAAC,CAAC;QAEvD,MAAM,QAAQ,GAAG,MAAM,uBAAA,IAAI,kCAAO,MAAX,IAAI,EAAQ,GAAG,CAAC,QAAQ,EAAE,EAAE;YACjD,MAAM;YACN,OAAO,EAAE;gBACP,cAAc,EAAE,kBAAkB;gBAClC,GAAG,OAAO;aACX;YACD,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS;SAC9C,CAAC,CAAC;QAEH,MAAM,YAAY,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;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,iCAAwB,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 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"]}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { type Env } from "./constants.cjs";
|
2
|
-
import type { AuthUtils, GetSubscriptionsResponse, ISubscriptionService } from "./types.cjs";
|
2
|
+
import type { AuthUtils, GetSubscriptionsResponse, ISubscriptionService, StartSubscriptionRequest, StartSubscriptionResponse } from "./types.cjs";
|
3
3
|
export type SubscriptionServiceConfig = {
|
4
4
|
env: Env;
|
5
5
|
auth: AuthUtils;
|
@@ -14,5 +14,6 @@ export declare class SubscriptionService implements ISubscriptionService {
|
|
14
14
|
cancelSubscription(params: {
|
15
15
|
subscriptionId: string;
|
16
16
|
}): Promise<void>;
|
17
|
+
startSubscriptionWithCard(request: StartSubscriptionRequest): Promise<StartSubscriptionResponse>;
|
17
18
|
}
|
18
19
|
//# sourceMappingURL=SubscriptionService.d.cts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"SubscriptionService.d.cts","sourceRoot":"","sources":["../src/SubscriptionService.ts"],"names":[],"mappings":"AAAA,OAAO,
|
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;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;CAkDtC"}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { type Env } from "./constants.mjs";
|
2
|
-
import type { AuthUtils, GetSubscriptionsResponse, ISubscriptionService } from "./types.mjs";
|
2
|
+
import type { AuthUtils, GetSubscriptionsResponse, ISubscriptionService, StartSubscriptionRequest, StartSubscriptionResponse } from "./types.mjs";
|
3
3
|
export type SubscriptionServiceConfig = {
|
4
4
|
env: Env;
|
5
5
|
auth: AuthUtils;
|
@@ -14,5 +14,6 @@ export declare class SubscriptionService implements ISubscriptionService {
|
|
14
14
|
cancelSubscription(params: {
|
15
15
|
subscriptionId: string;
|
16
16
|
}): Promise<void>;
|
17
|
+
startSubscriptionWithCard(request: StartSubscriptionRequest): Promise<StartSubscriptionResponse>;
|
17
18
|
}
|
18
19
|
//# sourceMappingURL=SubscriptionService.d.mts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"SubscriptionService.d.mts","sourceRoot":"","sources":["../src/SubscriptionService.ts"],"names":[],"mappings":"AAAA,OAAO,
|
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;CAkDtC"}
|
@@ -10,7 +10,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
11
11
|
};
|
12
12
|
var _SubscriptionService_instances, _SubscriptionService_env, _SubscriptionService_fetch, _SubscriptionService_makeRequest, _SubscriptionService_getAuthorizationHeader;
|
13
|
-
import { getEnvUrls } from "./constants.mjs";
|
13
|
+
import { getEnvUrls, SubscriptionControllerErrorMessage } from "./constants.mjs";
|
14
14
|
import { SubscriptionServiceError } from "./errors.mjs";
|
15
15
|
export const SUBSCRIPTION_URL = (env, path) => `${getEnvUrls(env).subscriptionApiUrl}/api/v1/${path}`;
|
16
16
|
export class SubscriptionService {
|
@@ -30,8 +30,15 @@ export class SubscriptionService {
|
|
30
30
|
const path = `subscriptions/${params.subscriptionId}`;
|
31
31
|
return await __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_makeRequest).call(this, path, 'DELETE');
|
32
32
|
}
|
33
|
+
async startSubscriptionWithCard(request) {
|
34
|
+
if (request.products.length === 0) {
|
35
|
+
throw new SubscriptionServiceError(SubscriptionControllerErrorMessage.SubscriptionProductsEmpty);
|
36
|
+
}
|
37
|
+
const path = 'subscriptions/card';
|
38
|
+
return await __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_makeRequest).call(this, path, 'POST', request);
|
39
|
+
}
|
33
40
|
}
|
34
|
-
_SubscriptionService_env = new WeakMap(), _SubscriptionService_fetch = new WeakMap(), _SubscriptionService_instances = new WeakSet(), _SubscriptionService_makeRequest = async function _SubscriptionService_makeRequest(path, method = 'GET') {
|
41
|
+
_SubscriptionService_env = new WeakMap(), _SubscriptionService_fetch = new WeakMap(), _SubscriptionService_instances = new WeakSet(), _SubscriptionService_makeRequest = async function _SubscriptionService_makeRequest(path, method = 'GET', body) {
|
35
42
|
try {
|
36
43
|
const headers = await __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_getAuthorizationHeader).call(this);
|
37
44
|
const url = new URL(SUBSCRIPTION_URL(__classPrivateFieldGet(this, _SubscriptionService_env, "f"), path));
|
@@ -41,6 +48,7 @@ _SubscriptionService_env = new WeakMap(), _SubscriptionService_fetch = new WeakM
|
|
41
48
|
'Content-Type': 'application/json',
|
42
49
|
...headers,
|
43
50
|
},
|
51
|
+
body: body ? JSON.stringify(body) : undefined,
|
44
52
|
});
|
45
53
|
const responseBody = await response.json();
|
46
54
|
if (!response.ok) {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"SubscriptionService.mjs","sourceRoot":"","sources":["../src/SubscriptionService.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,
|
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;AAoBpD,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,OA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,kCAAO,MAAX,IAAI,EAAQ,GAAG,CAAC,QAAQ,EAAE,EAAE;YACjD,MAAM;YACN,OAAO,EAAE;gBACP,cAAc,EAAE,kBAAkB;gBAClC,GAAG,OAAO;aACX;YACD,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS;SAC9C,CAAC,CAAC;QAEH,MAAM,YAAY,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;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 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"]}
|
package/dist/constants.cjs
CHANGED
@@ -37,5 +37,6 @@ var SubscriptionControllerErrorMessage;
|
|
37
37
|
(function (SubscriptionControllerErrorMessage) {
|
38
38
|
SubscriptionControllerErrorMessage["UserAlreadySubscribed"] = "SubscriptionController - User is already subscribed";
|
39
39
|
SubscriptionControllerErrorMessage["UserNotSubscribed"] = "SubscriptionController - User is not subscribed";
|
40
|
+
SubscriptionControllerErrorMessage["SubscriptionProductsEmpty"] = "SubscriptionController - Subscription products array cannot be empty";
|
40
41
|
})(SubscriptionControllerErrorMessage || (exports.SubscriptionControllerErrorMessage = SubscriptionControllerErrorMessage = {}));
|
41
42
|
//# sourceMappingURL=constants.cjs.map
|
package/dist/constants.cjs.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"constants.cjs","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,cAAc,GAAG,wBAAwB,CAAC;AAEvD,IAAY,GAIX;AAJD,WAAY,GAAG;IACb,kBAAW,CAAA;IACX,kBAAW,CAAA;IACX,kBAAW,CAAA;AACb,CAAC,EAJW,GAAG,mBAAH,GAAG,QAId;AAMD,MAAM,QAAQ,GAA8B;IAC1C,GAAG,EAAE;QACH,kBAAkB,EAAE,qDAAqD;KAC1E;IACD,GAAG,EAAE;QACH,kBAAkB,EAAE,qDAAqD;KAC1E;IACD,GAAG,EAAE;QACH,kBAAkB,EAAE,iDAAiD;KACtE;CACF,CAAC;AAEF;;;;;;GAMG;AACH,SAAgB,UAAU,CAAC,GAAQ;IACjC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;QAClB,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;KACtD;IACD,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC;AACvB,CAAC;AALD,gCAKC;AAED,IAAY,
|
1
|
+
{"version":3,"file":"constants.cjs","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,cAAc,GAAG,wBAAwB,CAAC;AAEvD,IAAY,GAIX;AAJD,WAAY,GAAG;IACb,kBAAW,CAAA;IACX,kBAAW,CAAA;IACX,kBAAW,CAAA;AACb,CAAC,EAJW,GAAG,mBAAH,GAAG,QAId;AAMD,MAAM,QAAQ,GAA8B;IAC1C,GAAG,EAAE;QACH,kBAAkB,EAAE,qDAAqD;KAC1E;IACD,GAAG,EAAE;QACH,kBAAkB,EAAE,qDAAqD;KAC1E;IACD,GAAG,EAAE;QACH,kBAAkB,EAAE,iDAAiD;KACtE;CACF,CAAC;AAEF;;;;;;GAMG;AACH,SAAgB,UAAU,CAAC,GAAQ;IACjC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;QAClB,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;KACtD;IACD,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC;AACvB,CAAC;AALD,gCAKC;AAED,IAAY,kCAIX;AAJD,WAAY,kCAAkC;IAC5C,mHAAwE,CAAA;IACxE,2GAAgE,CAAA;IAChE,wIAA6F,CAAA;AAC/F,CAAC,EAJW,kCAAkC,kDAAlC,kCAAkC,QAI7C","sourcesContent":["export const controllerName = 'SubscriptionController';\n\nexport enum Env {\n DEV = 'dev',\n UAT = 'uat',\n PRD = 'prd',\n}\n\ntype EnvUrlsEntry = {\n subscriptionApiUrl: string;\n};\n\nconst ENV_URLS: Record<Env, EnvUrlsEntry> = {\n dev: {\n subscriptionApiUrl: 'https://subscription-service.dev-api.cx.metamask.io',\n },\n uat: {\n subscriptionApiUrl: 'https://subscription-service.uat-api.cx.metamask.io',\n },\n prd: {\n subscriptionApiUrl: 'https://subscription-service.api.cx.metamask.io',\n },\n};\n\n/**\n * Validates and returns correct environment endpoints\n *\n * @param env - environment field\n * @returns the correct environment url\n * @throws on invalid environment passed\n */\nexport function getEnvUrls(env: Env): EnvUrlsEntry {\n if (!ENV_URLS[env]) {\n throw new Error('invalid environment configuration');\n }\n return ENV_URLS[env];\n}\n\nexport enum SubscriptionControllerErrorMessage {\n UserAlreadySubscribed = `${controllerName} - User is already subscribed`,\n UserNotSubscribed = `${controllerName} - User is not subscribed`,\n SubscriptionProductsEmpty = `${controllerName} - Subscription products array cannot be empty`,\n}\n"]}
|
package/dist/constants.d.cts
CHANGED
@@ -17,7 +17,8 @@ type EnvUrlsEntry = {
|
|
17
17
|
export declare function getEnvUrls(env: Env): EnvUrlsEntry;
|
18
18
|
export declare enum SubscriptionControllerErrorMessage {
|
19
19
|
UserAlreadySubscribed = "SubscriptionController - User is already subscribed",
|
20
|
-
UserNotSubscribed = "SubscriptionController - User is not subscribed"
|
20
|
+
UserNotSubscribed = "SubscriptionController - User is not subscribed",
|
21
|
+
SubscriptionProductsEmpty = "SubscriptionController - Subscription products array cannot be empty"
|
21
22
|
}
|
22
23
|
export {};
|
23
24
|
//# sourceMappingURL=constants.d.cts.map
|
package/dist/constants.d.cts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"constants.d.cts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,2BAA2B,CAAC;AAEvD,oBAAY,GAAG;IACb,GAAG,QAAQ;IACX,GAAG,QAAQ;IACX,GAAG,QAAQ;CACZ;AAED,KAAK,YAAY,GAAG;IAClB,kBAAkB,EAAE,MAAM,CAAC;CAC5B,CAAC;AAcF;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,GAAG,GAAG,YAAY,CAKjD;AAED,oBAAY,kCAAkC;IAC5C,qBAAqB,wDAAmD;IACxE,iBAAiB,oDAA+C;
|
1
|
+
{"version":3,"file":"constants.d.cts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,2BAA2B,CAAC;AAEvD,oBAAY,GAAG;IACb,GAAG,QAAQ;IACX,GAAG,QAAQ;IACX,GAAG,QAAQ;CACZ;AAED,KAAK,YAAY,GAAG;IAClB,kBAAkB,EAAE,MAAM,CAAC;CAC5B,CAAC;AAcF;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,GAAG,GAAG,YAAY,CAKjD;AAED,oBAAY,kCAAkC;IAC5C,qBAAqB,wDAAmD;IACxE,iBAAiB,oDAA+C;IAChE,yBAAyB,yEAAoE;CAC9F"}
|
package/dist/constants.d.mts
CHANGED
@@ -17,7 +17,8 @@ type EnvUrlsEntry = {
|
|
17
17
|
export declare function getEnvUrls(env: Env): EnvUrlsEntry;
|
18
18
|
export declare enum SubscriptionControllerErrorMessage {
|
19
19
|
UserAlreadySubscribed = "SubscriptionController - User is already subscribed",
|
20
|
-
UserNotSubscribed = "SubscriptionController - User is not subscribed"
|
20
|
+
UserNotSubscribed = "SubscriptionController - User is not subscribed",
|
21
|
+
SubscriptionProductsEmpty = "SubscriptionController - Subscription products array cannot be empty"
|
21
22
|
}
|
22
23
|
export {};
|
23
24
|
//# sourceMappingURL=constants.d.mts.map
|
package/dist/constants.d.mts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"constants.d.mts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,2BAA2B,CAAC;AAEvD,oBAAY,GAAG;IACb,GAAG,QAAQ;IACX,GAAG,QAAQ;IACX,GAAG,QAAQ;CACZ;AAED,KAAK,YAAY,GAAG;IAClB,kBAAkB,EAAE,MAAM,CAAC;CAC5B,CAAC;AAcF;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,GAAG,GAAG,YAAY,CAKjD;AAED,oBAAY,kCAAkC;IAC5C,qBAAqB,wDAAmD;IACxE,iBAAiB,oDAA+C;
|
1
|
+
{"version":3,"file":"constants.d.mts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,2BAA2B,CAAC;AAEvD,oBAAY,GAAG;IACb,GAAG,QAAQ;IACX,GAAG,QAAQ;IACX,GAAG,QAAQ;CACZ;AAED,KAAK,YAAY,GAAG;IAClB,kBAAkB,EAAE,MAAM,CAAC;CAC5B,CAAC;AAcF;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,GAAG,GAAG,YAAY,CAKjD;AAED,oBAAY,kCAAkC;IAC5C,qBAAqB,wDAAmD;IACxE,iBAAiB,oDAA+C;IAChE,yBAAyB,yEAAoE;CAC9F"}
|
package/dist/constants.mjs
CHANGED
@@ -33,5 +33,6 @@ export var SubscriptionControllerErrorMessage;
|
|
33
33
|
(function (SubscriptionControllerErrorMessage) {
|
34
34
|
SubscriptionControllerErrorMessage["UserAlreadySubscribed"] = "SubscriptionController - User is already subscribed";
|
35
35
|
SubscriptionControllerErrorMessage["UserNotSubscribed"] = "SubscriptionController - User is not subscribed";
|
36
|
+
SubscriptionControllerErrorMessage["SubscriptionProductsEmpty"] = "SubscriptionController - Subscription products array cannot be empty";
|
36
37
|
})(SubscriptionControllerErrorMessage || (SubscriptionControllerErrorMessage = {}));
|
37
38
|
//# sourceMappingURL=constants.mjs.map
|
package/dist/constants.mjs.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"constants.mjs","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,cAAc,GAAG,wBAAwB,CAAC;AAEvD,MAAM,CAAN,IAAY,GAIX;AAJD,WAAY,GAAG;IACb,kBAAW,CAAA;IACX,kBAAW,CAAA;IACX,kBAAW,CAAA;AACb,CAAC,EAJW,GAAG,KAAH,GAAG,QAId;AAMD,MAAM,QAAQ,GAA8B;IAC1C,GAAG,EAAE;QACH,kBAAkB,EAAE,qDAAqD;KAC1E;IACD,GAAG,EAAE;QACH,kBAAkB,EAAE,qDAAqD;KAC1E;IACD,GAAG,EAAE;QACH,kBAAkB,EAAE,iDAAiD;KACtE;CACF,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CAAC,GAAQ;IACjC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;QAClB,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;KACtD;IACD,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC;AACvB,CAAC;AAED,MAAM,CAAN,IAAY,
|
1
|
+
{"version":3,"file":"constants.mjs","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,cAAc,GAAG,wBAAwB,CAAC;AAEvD,MAAM,CAAN,IAAY,GAIX;AAJD,WAAY,GAAG;IACb,kBAAW,CAAA;IACX,kBAAW,CAAA;IACX,kBAAW,CAAA;AACb,CAAC,EAJW,GAAG,KAAH,GAAG,QAId;AAMD,MAAM,QAAQ,GAA8B;IAC1C,GAAG,EAAE;QACH,kBAAkB,EAAE,qDAAqD;KAC1E;IACD,GAAG,EAAE;QACH,kBAAkB,EAAE,qDAAqD;KAC1E;IACD,GAAG,EAAE;QACH,kBAAkB,EAAE,iDAAiD;KACtE;CACF,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CAAC,GAAQ;IACjC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;QAClB,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;KACtD;IACD,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC;AACvB,CAAC;AAED,MAAM,CAAN,IAAY,kCAIX;AAJD,WAAY,kCAAkC;IAC5C,mHAAwE,CAAA;IACxE,2GAAgE,CAAA;IAChE,wIAA6F,CAAA;AAC/F,CAAC,EAJW,kCAAkC,KAAlC,kCAAkC,QAI7C","sourcesContent":["export const controllerName = 'SubscriptionController';\n\nexport enum Env {\n DEV = 'dev',\n UAT = 'uat',\n PRD = 'prd',\n}\n\ntype EnvUrlsEntry = {\n subscriptionApiUrl: string;\n};\n\nconst ENV_URLS: Record<Env, EnvUrlsEntry> = {\n dev: {\n subscriptionApiUrl: 'https://subscription-service.dev-api.cx.metamask.io',\n },\n uat: {\n subscriptionApiUrl: 'https://subscription-service.uat-api.cx.metamask.io',\n },\n prd: {\n subscriptionApiUrl: 'https://subscription-service.api.cx.metamask.io',\n },\n};\n\n/**\n * Validates and returns correct environment endpoints\n *\n * @param env - environment field\n * @returns the correct environment url\n * @throws on invalid environment passed\n */\nexport function getEnvUrls(env: Env): EnvUrlsEntry {\n if (!ENV_URLS[env]) {\n throw new Error('invalid environment configuration');\n }\n return ENV_URLS[env];\n}\n\nexport enum SubscriptionControllerErrorMessage {\n UserAlreadySubscribed = `${controllerName} - User is already subscribed`,\n UserNotSubscribed = `${controllerName} - User is not subscribed`,\n SubscriptionProductsEmpty = `${controllerName} - Subscription products array cannot be empty`,\n}\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":";;;AAYA,uEAGkC;AAFhC,gIAAA,sBAAsB,OAAA;AACtB,+IAAA,qCAAqC,OAAA;AAWvC,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 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} 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,4 +1,4 @@
|
|
1
|
-
export type { SubscriptionControllerActions, SubscriptionControllerState, SubscriptionControllerEvents, SubscriptionControllerGetStateAction, SubscriptionControllerMessenger, SubscriptionControllerOptions, SubscriptionControllerStateChangeEvent, } from "./SubscriptionController.cjs";
|
1
|
+
export type { SubscriptionControllerActions, SubscriptionControllerState, SubscriptionControllerEvents, SubscriptionControllerGetSubscriptionsAction, SubscriptionControllerCancelSubscriptionAction, SubscriptionControllerStartShieldSubscriptionWithCardAction, SubscriptionControllerGetStateAction, SubscriptionControllerMessenger, SubscriptionControllerOptions, SubscriptionControllerStateChangeEvent, } from "./SubscriptionController.cjs";
|
2
2
|
export { SubscriptionController, getDefaultSubscriptionControllerState, } from "./SubscriptionController.cjs";
|
3
3
|
export type { Subscription, AuthUtils, ISubscriptionService, PaymentMethod, PaymentType, Product, ProductType, } from "./types.cjs";
|
4
4
|
export { SubscriptionServiceError } from "./errors.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,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,GACZ,oBAAgB;AACjB,OAAO,EAAE,wBAAwB,EAAE,qBAAiB;AACpD,OAAO,EAAE,GAAG,EAAE,kCAAkC,EAAE,wBAAoB;AACtE,YAAY,EAAE,yBAAyB,EAAE,kCAA8B;AACvE,OAAO,EAAE,mBAAmB,EAAE,kCAA8B"}
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,6BAA6B,EAC7B,2BAA2B,EAC3B,4BAA4B,EAC5B,4CAA4C,EAC5C,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,GACZ,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,4 +1,4 @@
|
|
1
|
-
export type { SubscriptionControllerActions, SubscriptionControllerState, SubscriptionControllerEvents, SubscriptionControllerGetStateAction, SubscriptionControllerMessenger, SubscriptionControllerOptions, SubscriptionControllerStateChangeEvent, } from "./SubscriptionController.mjs";
|
1
|
+
export type { SubscriptionControllerActions, SubscriptionControllerState, SubscriptionControllerEvents, SubscriptionControllerGetSubscriptionsAction, SubscriptionControllerCancelSubscriptionAction, SubscriptionControllerStartShieldSubscriptionWithCardAction, SubscriptionControllerGetStateAction, SubscriptionControllerMessenger, SubscriptionControllerOptions, SubscriptionControllerStateChangeEvent, } from "./SubscriptionController.mjs";
|
2
2
|
export { SubscriptionController, getDefaultSubscriptionControllerState, } from "./SubscriptionController.mjs";
|
3
3
|
export type { Subscription, AuthUtils, ISubscriptionService, PaymentMethod, PaymentType, Product, ProductType, } from "./types.mjs";
|
4
4
|
export { SubscriptionServiceError } from "./errors.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,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,GACZ,oBAAgB;AACjB,OAAO,EAAE,wBAAwB,EAAE,qBAAiB;AACpD,OAAO,EAAE,GAAG,EAAE,kCAAkC,EAAE,wBAAoB;AACtE,YAAY,EAAE,yBAAyB,EAAE,kCAA8B;AACvE,OAAO,EAAE,mBAAmB,EAAE,kCAA8B"}
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,6BAA6B,EAC7B,2BAA2B,EAC3B,4BAA4B,EAC5B,4CAA4C,EAC5C,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,GACZ,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":"AAYA,OAAO,EACL,sBAAsB,EACtB,qCAAqC,EACtC,qCAAiC;AAUlC,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 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} 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
CHANGED
@@ -1,13 +1,35 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.PaymentType = exports.ProductType = void 0;
|
3
|
+
exports.SubscriptionStatus = exports.RecurringInterval = exports.PaymentType = exports.ProductType = void 0;
|
4
4
|
var ProductType;
|
5
5
|
(function (ProductType) {
|
6
6
|
ProductType["SHIELD"] = "shield";
|
7
7
|
})(ProductType || (exports.ProductType = ProductType = {}));
|
8
8
|
var PaymentType;
|
9
9
|
(function (PaymentType) {
|
10
|
-
PaymentType["
|
11
|
-
PaymentType["
|
10
|
+
PaymentType["byCard"] = "card";
|
11
|
+
PaymentType["byCrypto"] = "crypto";
|
12
12
|
})(PaymentType || (exports.PaymentType = PaymentType = {}));
|
13
|
+
var RecurringInterval;
|
14
|
+
(function (RecurringInterval) {
|
15
|
+
RecurringInterval["month"] = "month";
|
16
|
+
RecurringInterval["year"] = "year";
|
17
|
+
})(RecurringInterval || (exports.RecurringInterval = RecurringInterval = {}));
|
18
|
+
var SubscriptionStatus;
|
19
|
+
(function (SubscriptionStatus) {
|
20
|
+
// Initial states
|
21
|
+
SubscriptionStatus["incomplete"] = "incomplete";
|
22
|
+
SubscriptionStatus["incompleteExpired"] = "incomplete_expired";
|
23
|
+
// Active states
|
24
|
+
SubscriptionStatus["provisional"] = "provisional";
|
25
|
+
SubscriptionStatus["trialing"] = "trialing";
|
26
|
+
SubscriptionStatus["active"] = "active";
|
27
|
+
// Payment issues
|
28
|
+
SubscriptionStatus["pastDue"] = "past_due";
|
29
|
+
SubscriptionStatus["unpaid"] = "unpaid";
|
30
|
+
// Cancelled states
|
31
|
+
SubscriptionStatus["canceled"] = "canceled";
|
32
|
+
// Paused states
|
33
|
+
SubscriptionStatus["paused"] = "paused";
|
34
|
+
})(SubscriptionStatus || (exports.SubscriptionStatus = SubscriptionStatus = {}));
|
13
35
|
//# sourceMappingURL=types.cjs.map
|
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,
|
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"]}
|
package/dist/types.d.cts
CHANGED
@@ -8,8 +8,12 @@ export type Product = {
|
|
8
8
|
amount: number;
|
9
9
|
};
|
10
10
|
export declare enum PaymentType {
|
11
|
-
|
12
|
-
|
11
|
+
byCard = "card",
|
12
|
+
byCrypto = "crypto"
|
13
|
+
}
|
14
|
+
export declare enum RecurringInterval {
|
15
|
+
month = "month",
|
16
|
+
year = "year"
|
13
17
|
}
|
14
18
|
export type PaymentMethod = {
|
15
19
|
type: PaymentType;
|
@@ -19,21 +23,39 @@ export type PaymentMethod = {
|
|
19
23
|
tokenSymbol: string;
|
20
24
|
};
|
21
25
|
};
|
26
|
+
export declare enum SubscriptionStatus {
|
27
|
+
incomplete = "incomplete",
|
28
|
+
incompleteExpired = "incomplete_expired",
|
29
|
+
provisional = "provisional",
|
30
|
+
trialing = "trialing",
|
31
|
+
active = "active",
|
32
|
+
pastDue = "past_due",
|
33
|
+
unpaid = "unpaid",
|
34
|
+
canceled = "canceled",
|
35
|
+
paused = "paused"
|
36
|
+
}
|
22
37
|
export type Subscription = {
|
23
38
|
id: string;
|
24
39
|
products: Product[];
|
25
40
|
currentPeriodStart: string;
|
26
41
|
currentPeriodEnd: string;
|
27
|
-
|
28
|
-
|
29
|
-
interval: 'month' | 'year';
|
42
|
+
status: SubscriptionStatus;
|
43
|
+
interval: RecurringInterval;
|
30
44
|
paymentMethod: PaymentMethod;
|
31
45
|
};
|
32
46
|
export type GetSubscriptionsResponse = {
|
33
|
-
customerId
|
47
|
+
customerId?: string;
|
34
48
|
subscriptions: Subscription[];
|
35
49
|
trialedProducts: ProductType[];
|
36
50
|
};
|
51
|
+
export type StartSubscriptionRequest = {
|
52
|
+
products: ProductType[];
|
53
|
+
isTrialRequested: boolean;
|
54
|
+
recurringInterval: RecurringInterval;
|
55
|
+
};
|
56
|
+
export type StartSubscriptionResponse = {
|
57
|
+
checkoutSessionUrl: string;
|
58
|
+
};
|
37
59
|
export type AuthUtils = {
|
38
60
|
getAccessToken: () => Promise<string>;
|
39
61
|
};
|
@@ -42,5 +64,6 @@ export type ISubscriptionService = {
|
|
42
64
|
cancelSubscription(request: {
|
43
65
|
subscriptionId: string;
|
44
66
|
}): Promise<void>;
|
67
|
+
startSubscriptionWithCard(request: StartSubscriptionRequest): Promise<StartSubscriptionResponse>;
|
45
68
|
};
|
46
69
|
//# 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,
|
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,IA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F,MAAM,MAAM,yBAAyB,GAAG;IACtC,kBAAkB,EAAE,MAAM,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG;IACtB,cAAc,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC;CACvC,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;CACvC,CAAC"}
|
package/dist/types.d.mts
CHANGED
@@ -8,8 +8,12 @@ export type Product = {
|
|
8
8
|
amount: number;
|
9
9
|
};
|
10
10
|
export declare enum PaymentType {
|
11
|
-
|
12
|
-
|
11
|
+
byCard = "card",
|
12
|
+
byCrypto = "crypto"
|
13
|
+
}
|
14
|
+
export declare enum RecurringInterval {
|
15
|
+
month = "month",
|
16
|
+
year = "year"
|
13
17
|
}
|
14
18
|
export type PaymentMethod = {
|
15
19
|
type: PaymentType;
|
@@ -19,21 +23,39 @@ export type PaymentMethod = {
|
|
19
23
|
tokenSymbol: string;
|
20
24
|
};
|
21
25
|
};
|
26
|
+
export declare enum SubscriptionStatus {
|
27
|
+
incomplete = "incomplete",
|
28
|
+
incompleteExpired = "incomplete_expired",
|
29
|
+
provisional = "provisional",
|
30
|
+
trialing = "trialing",
|
31
|
+
active = "active",
|
32
|
+
pastDue = "past_due",
|
33
|
+
unpaid = "unpaid",
|
34
|
+
canceled = "canceled",
|
35
|
+
paused = "paused"
|
36
|
+
}
|
22
37
|
export type Subscription = {
|
23
38
|
id: string;
|
24
39
|
products: Product[];
|
25
40
|
currentPeriodStart: string;
|
26
41
|
currentPeriodEnd: string;
|
27
|
-
|
28
|
-
|
29
|
-
interval: 'month' | 'year';
|
42
|
+
status: SubscriptionStatus;
|
43
|
+
interval: RecurringInterval;
|
30
44
|
paymentMethod: PaymentMethod;
|
31
45
|
};
|
32
46
|
export type GetSubscriptionsResponse = {
|
33
|
-
customerId
|
47
|
+
customerId?: string;
|
34
48
|
subscriptions: Subscription[];
|
35
49
|
trialedProducts: ProductType[];
|
36
50
|
};
|
51
|
+
export type StartSubscriptionRequest = {
|
52
|
+
products: ProductType[];
|
53
|
+
isTrialRequested: boolean;
|
54
|
+
recurringInterval: RecurringInterval;
|
55
|
+
};
|
56
|
+
export type StartSubscriptionResponse = {
|
57
|
+
checkoutSessionUrl: string;
|
58
|
+
};
|
37
59
|
export type AuthUtils = {
|
38
60
|
getAccessToken: () => Promise<string>;
|
39
61
|
};
|
@@ -42,5 +64,6 @@ export type ISubscriptionService = {
|
|
42
64
|
cancelSubscription(request: {
|
43
65
|
subscriptionId: string;
|
44
66
|
}): Promise<void>;
|
67
|
+
startSubscriptionWithCard(request: StartSubscriptionRequest): Promise<StartSubscriptionResponse>;
|
45
68
|
};
|
46
69
|
//# 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,oBAAY,WAAW;IACrB,
|
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,Q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AC;CAC5B,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG;IACtB,cAAc,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC;CACvC,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;CACvC,CAAC"}
|
package/dist/types.mjs
CHANGED
@@ -4,7 +4,29 @@ export var ProductType;
|
|
4
4
|
})(ProductType || (ProductType = {}));
|
5
5
|
export var PaymentType;
|
6
6
|
(function (PaymentType) {
|
7
|
-
PaymentType["
|
8
|
-
PaymentType["
|
7
|
+
PaymentType["byCard"] = "card";
|
8
|
+
PaymentType["byCrypto"] = "crypto";
|
9
9
|
})(PaymentType || (PaymentType = {}));
|
10
|
+
export var RecurringInterval;
|
11
|
+
(function (RecurringInterval) {
|
12
|
+
RecurringInterval["month"] = "month";
|
13
|
+
RecurringInterval["year"] = "year";
|
14
|
+
})(RecurringInterval || (RecurringInterval = {}));
|
15
|
+
export var SubscriptionStatus;
|
16
|
+
(function (SubscriptionStatus) {
|
17
|
+
// Initial states
|
18
|
+
SubscriptionStatus["incomplete"] = "incomplete";
|
19
|
+
SubscriptionStatus["incompleteExpired"] = "incomplete_expired";
|
20
|
+
// Active states
|
21
|
+
SubscriptionStatus["provisional"] = "provisional";
|
22
|
+
SubscriptionStatus["trialing"] = "trialing";
|
23
|
+
SubscriptionStatus["active"] = "active";
|
24
|
+
// Payment issues
|
25
|
+
SubscriptionStatus["pastDue"] = "past_due";
|
26
|
+
SubscriptionStatus["unpaid"] = "unpaid";
|
27
|
+
// Cancelled states
|
28
|
+
SubscriptionStatus["canceled"] = "canceled";
|
29
|
+
// Paused states
|
30
|
+
SubscriptionStatus["paused"] = "paused";
|
31
|
+
})(SubscriptionStatus || (SubscriptionStatus = {}));
|
10
32
|
//# sourceMappingURL=types.mjs.map
|
package/dist/types.mjs.map
CHANGED
@@ -1 +1 @@
|
|
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,
|
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 ISubscriptionService = {\n getSubscriptions(): Promise<GetSubscriptionsResponse>;\n cancelSubscription(request: { subscriptionId: string }): Promise<void>;\n startSubscriptionWithCard(\n request: StartSubscriptionRequest,\n ): Promise<StartSubscriptionResponse>;\n};\n"]}
|