@metamask-previews/subscription-controller 0.0.0-preview-0b2bfc8a
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 +16 -0
- package/LICENSE +20 -0
- package/README.md +19 -0
- package/dist/SubscriptionController.cjs +94 -0
- package/dist/SubscriptionController.cjs.map +1 -0
- package/dist/SubscriptionController.d.cts +59 -0
- package/dist/SubscriptionController.d.cts.map +1 -0
- package/dist/SubscriptionController.d.mts +59 -0
- package/dist/SubscriptionController.d.mts.map +1 -0
- package/dist/SubscriptionController.mjs +89 -0
- package/dist/SubscriptionController.mjs.map +1 -0
- package/dist/SubscriptionService.cjs +65 -0
- package/dist/SubscriptionService.cjs.map +1 -0
- package/dist/SubscriptionService.d.cts +18 -0
- package/dist/SubscriptionService.d.cts.map +1 -0
- package/dist/SubscriptionService.d.mts +18 -0
- package/dist/SubscriptionService.d.mts.map +1 -0
- package/dist/SubscriptionService.mjs +60 -0
- package/dist/SubscriptionService.mjs.map +1 -0
- package/dist/constants.cjs +41 -0
- package/dist/constants.cjs.map +1 -0
- package/dist/constants.d.cts +23 -0
- package/dist/constants.d.cts.map +1 -0
- package/dist/constants.d.mts +23 -0
- package/dist/constants.d.mts.map +1 -0
- package/dist/constants.mjs +37 -0
- package/dist/constants.mjs.map +1 -0
- package/dist/errors.cjs +11 -0
- package/dist/errors.cjs.map +1 -0
- package/dist/errors.d.cts +4 -0
- package/dist/errors.d.cts.map +1 -0
- package/dist/errors.d.mts +4 -0
- package/dist/errors.d.mts.map +1 -0
- package/dist/errors.mjs +7 -0
- package/dist/errors.mjs.map +1 -0
- package/dist/index.cjs +14 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +8 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +8 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +5 -0
- package/dist/index.mjs.map +1 -0
- package/dist/types.cjs +13 -0
- package/dist/types.cjs.map +1 -0
- package/dist/types.d.cts +46 -0
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.mts +46 -0
- package/dist/types.d.mts.map +1 -0
- package/dist/types.mjs +10 -0
- package/dist/types.mjs.map +1 -0
- package/package.json +72 -0
package/CHANGELOG.md
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
All notable changes to this project will be documented in this file.
|
4
|
+
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
7
|
+
|
8
|
+
## [Unreleased]
|
9
|
+
|
10
|
+
### Added
|
11
|
+
|
12
|
+
- Initial release of the subscription controller ([#6233](https://github.com/MetaMask/core/pull/6233))
|
13
|
+
- `getSubscription`: Retrieve current user subscription info if exist.
|
14
|
+
- `cancelSubscription`: Cancel user active subscription.
|
15
|
+
|
16
|
+
[Unreleased]: https://github.com/MetaMask/core/
|
package/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2025 MetaMask
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
package/README.md
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# `@metamask/subscription-controller`
|
2
|
+
|
3
|
+
Handle user subscription
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
`yarn add @metamask/subscription-controller`
|
8
|
+
|
9
|
+
or
|
10
|
+
|
11
|
+
`npm install @metamask/subscription-controller`
|
12
|
+
|
13
|
+
## Architecture
|
14
|
+
|
15
|
+
[Reference](./ARCHITECTURE.md)
|
16
|
+
|
17
|
+
## Contributing
|
18
|
+
|
19
|
+
This package is part of a monorepo. Instructions for contributing can be found in the [monorepo README](https://github.com/MetaMask/core#readme).
|
@@ -0,0 +1,94 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
5
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
7
|
+
};
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
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
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
12
|
+
};
|
13
|
+
var _SubscriptionController_instances, _SubscriptionController_subscriptionService, _SubscriptionController_registerMessageHandlers, _SubscriptionController_assertIsUserSubscribed;
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
15
|
+
exports.SubscriptionController = exports.getDefaultSubscriptionControllerState = void 0;
|
16
|
+
const base_controller_1 = require("@metamask/base-controller");
|
17
|
+
const constants_1 = require("./constants.cjs");
|
18
|
+
/**
|
19
|
+
* Get the default state for the Subscription Controller.
|
20
|
+
*
|
21
|
+
* @returns The default state for the Subscription Controller.
|
22
|
+
*/
|
23
|
+
function getDefaultSubscriptionControllerState() {
|
24
|
+
return {
|
25
|
+
subscriptions: [],
|
26
|
+
};
|
27
|
+
}
|
28
|
+
exports.getDefaultSubscriptionControllerState = getDefaultSubscriptionControllerState;
|
29
|
+
/**
|
30
|
+
* Seedless Onboarding Controller State Metadata.
|
31
|
+
*
|
32
|
+
* This allows us to choose if fields of the state should be persisted or not
|
33
|
+
* using the `persist` flag; and if they can be sent to Sentry or not, using
|
34
|
+
* the `anonymous` flag.
|
35
|
+
*/
|
36
|
+
const subscriptionControllerMetadata = {
|
37
|
+
subscriptions: {
|
38
|
+
persist: true,
|
39
|
+
anonymous: false,
|
40
|
+
},
|
41
|
+
};
|
42
|
+
class SubscriptionController extends base_controller_1.BaseController {
|
43
|
+
/**
|
44
|
+
* Creates a new SubscriptionController instance.
|
45
|
+
*
|
46
|
+
* @param options - The options for the SubscriptionController.
|
47
|
+
* @param options.messenger - A restricted messenger.
|
48
|
+
* @param options.state - Initial state to set on this controller.
|
49
|
+
* @param options.subscriptionService - The subscription service for communicating with subscription server.
|
50
|
+
*/
|
51
|
+
constructor({ messenger, state, subscriptionService, }) {
|
52
|
+
super({
|
53
|
+
name: constants_1.controllerName,
|
54
|
+
metadata: subscriptionControllerMetadata,
|
55
|
+
state: {
|
56
|
+
...getDefaultSubscriptionControllerState(),
|
57
|
+
...state,
|
58
|
+
},
|
59
|
+
messenger,
|
60
|
+
});
|
61
|
+
_SubscriptionController_instances.add(this);
|
62
|
+
_SubscriptionController_subscriptionService.set(this, void 0);
|
63
|
+
__classPrivateFieldSet(this, _SubscriptionController_subscriptionService, subscriptionService, "f");
|
64
|
+
__classPrivateFieldGet(this, _SubscriptionController_instances, "m", _SubscriptionController_registerMessageHandlers).call(this);
|
65
|
+
}
|
66
|
+
async getSubscriptions() {
|
67
|
+
const { subscriptions } = await __classPrivateFieldGet(this, _SubscriptionController_subscriptionService, "f").getSubscriptions();
|
68
|
+
this.update((state) => {
|
69
|
+
state.subscriptions = subscriptions;
|
70
|
+
});
|
71
|
+
return subscriptions;
|
72
|
+
}
|
73
|
+
async cancelSubscription(request) {
|
74
|
+
__classPrivateFieldGet(this, _SubscriptionController_instances, "m", _SubscriptionController_assertIsUserSubscribed).call(this, { subscriptionId: request.subscriptionId });
|
75
|
+
await __classPrivateFieldGet(this, _SubscriptionController_subscriptionService, "f").cancelSubscription({
|
76
|
+
subscriptionId: request.subscriptionId,
|
77
|
+
});
|
78
|
+
this.update((state) => {
|
79
|
+
state.subscriptions = state.subscriptions.map((subscription) => subscription.id === request.subscriptionId
|
80
|
+
? { ...subscription, status: 'cancelled' }
|
81
|
+
: subscription);
|
82
|
+
});
|
83
|
+
}
|
84
|
+
}
|
85
|
+
exports.SubscriptionController = SubscriptionController;
|
86
|
+
_SubscriptionController_subscriptionService = new WeakMap(), _SubscriptionController_instances = new WeakSet(), _SubscriptionController_registerMessageHandlers = function _SubscriptionController_registerMessageHandlers() {
|
87
|
+
this.messagingSystem.registerActionHandler('SubscriptionController:getSubscriptions', this.getSubscriptions.bind(this));
|
88
|
+
this.messagingSystem.registerActionHandler('SubscriptionController:cancelSubscription', this.cancelSubscription.bind(this));
|
89
|
+
}, _SubscriptionController_assertIsUserSubscribed = function _SubscriptionController_assertIsUserSubscribed(request) {
|
90
|
+
if (!this.state.subscriptions.find((subscription) => subscription.id === request.subscriptionId)) {
|
91
|
+
throw new Error(constants_1.SubscriptionControllerErrorMessage.UserNotSubscribed);
|
92
|
+
}
|
93
|
+
};
|
94
|
+
//# sourceMappingURL=SubscriptionController.cjs.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"SubscriptionController.cjs","sourceRoot":"","sources":["../src/SubscriptionController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,+DAMmC;AAGnC,+CAGqB;AAgErB;;;;GAIG;AACH,SAAgB,qCAAqC;IACnD,OAAO;QACL,aAAa,EAAE,EAAE;KAClB,CAAC;AACJ,CAAC;AAJD,sFAIC;AAED;;;;;;GAMG;AACH,MAAM,8BAA8B,GAClC;IACE,aAAa,EAAE;QACb,OAAO,EAAE,IAAI;QACb,SAAS,EAAE,KAAK;KACjB;CACF,CAAC;AAEJ,MAAa,sBAAuB,SAAQ,gCAI3C;IAGC;;;;;;;OAOG;IACH,YAAY,EACV,SAAS,EACT,KAAK,EACL,mBAAmB,GACW;QAC9B,KAAK,CAAC;YACJ,IAAI,EAAE,0BAAc;YACpB,QAAQ,EAAE,8BAA8B;YACxC,KAAK,EAAE;gBACL,GAAG,qCAAqC,EAAE;gBAC1C,GAAG,KAAK;aACT;YACD,SAAS;SACV,CAAC,CAAC;;QAvBI,8DAA2C;QAyBlD,uBAAA,IAAI,+CAAwB,mBAAmB,MAAA,CAAC;QAEhD,uBAAA,IAAI,0FAAyB,MAA7B,IAAI,CAA2B,CAAC;IAClC,CAAC;IAkBD,KAAK,CAAC,gBAAgB;QACpB,MAAM,EAAE,aAAa,EAAE,GACrB,MAAM,uBAAA,IAAI,mDAAqB,CAAC,gBAAgB,EAAE,CAAC;QAErD,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;YACpB,KAAK,CAAC,aAAa,GAAG,aAAa,CAAC;QACtC,CAAC,CAAC,CAAC;QAEH,OAAO,aAAa,CAAC;IACvB,CAAC;IAED,KAAK,CAAC,kBAAkB,CAAC,OAAmC;QAC1D,uBAAA,IAAI,yFAAwB,MAA5B,IAAI,EAAyB,EAAE,cAAc,EAAE,OAAO,CAAC,cAAc,EAAE,CAAC,CAAC;QAEzE,MAAM,uBAAA,IAAI,mDAAqB,CAAC,kBAAkB,CAAC;YACjD,cAAc,EAAE,OAAO,CAAC,cAAc;SACvC,CAAC,CAAC;QAEH,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;YACpB,KAAK,CAAC,aAAa,GAAG,KAAK,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,YAAY,EAAE,EAAE,CAC7D,YAAY,CAAC,EAAE,KAAK,OAAO,CAAC,cAAc;gBACxC,CAAC,CAAC,EAAE,GAAG,YAAY,EAAE,MAAM,EAAE,WAAW,EAAE;gBAC1C,CAAC,CAAC,YAAY,CACjB,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;CAWF;AAvFD,wDAuFC;;IA/CG,IAAI,CAAC,eAAe,CAAC,qBAAqB,CACxC,yCAAyC,EACzC,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,CACjC,CAAC;IAEF,IAAI,CAAC,eAAe,CAAC,qBAAqB,CACxC,2CAA2C,EAC3C,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,CACnC,CAAC;AACJ,CAAC,2GA6BuB,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 type { ISubscriptionService, Subscription } from './types';\n\nexport type SubscriptionControllerState = {\n subscriptions: Subscription[];\n};\n\n// Messenger Actions\ntype CreateActionsObj<Controller extends keyof SubscriptionController> = {\n [K in Controller]: {\n type: `${typeof controllerName}:${K}`;\n handler: SubscriptionController[K];\n };\n};\ntype ActionsObj = CreateActionsObj<'getSubscriptions' | 'cancelSubscription'>;\n\nexport type SubscriptionControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n SubscriptionControllerState\n>;\nexport type SubscriptionControllerActions =\n | ActionsObj[keyof ActionsObj]\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\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: 'cancelled' }\n : subscription,\n );\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"]}
|
@@ -0,0 +1,59 @@
|
|
1
|
+
import { BaseController, type ControllerStateChangeEvent, type ControllerGetStateAction, type RestrictedMessenger } from "@metamask/base-controller";
|
2
|
+
import type { AuthenticationController } from "@metamask/profile-sync-controller";
|
3
|
+
import { controllerName } from "./constants.cjs";
|
4
|
+
import type { ISubscriptionService, Subscription } from "./types.cjs";
|
5
|
+
export type SubscriptionControllerState = {
|
6
|
+
subscriptions: Subscription[];
|
7
|
+
};
|
8
|
+
type CreateActionsObj<Controller extends keyof SubscriptionController> = {
|
9
|
+
[K in Controller]: {
|
10
|
+
type: `${typeof controllerName}:${K}`;
|
11
|
+
handler: SubscriptionController[K];
|
12
|
+
};
|
13
|
+
};
|
14
|
+
type ActionsObj = CreateActionsObj<'getSubscriptions' | 'cancelSubscription'>;
|
15
|
+
export type SubscriptionControllerGetStateAction = ControllerGetStateAction<typeof controllerName, SubscriptionControllerState>;
|
16
|
+
export type SubscriptionControllerActions = ActionsObj[keyof ActionsObj] | SubscriptionControllerGetStateAction;
|
17
|
+
export type AllowedActions = AuthenticationController.AuthenticationControllerGetBearerToken;
|
18
|
+
export type SubscriptionControllerStateChangeEvent = ControllerStateChangeEvent<typeof controllerName, SubscriptionControllerState>;
|
19
|
+
export type SubscriptionControllerEvents = SubscriptionControllerStateChangeEvent;
|
20
|
+
export type AllowedEvents = AuthenticationController.AuthenticationControllerStateChangeEvent;
|
21
|
+
export type SubscriptionControllerMessenger = RestrictedMessenger<typeof controllerName, SubscriptionControllerActions | AllowedActions, SubscriptionControllerEvents | AllowedEvents, AllowedActions['type'], AllowedEvents['type']>;
|
22
|
+
/**
|
23
|
+
* Subscription Controller Options.
|
24
|
+
*/
|
25
|
+
export type SubscriptionControllerOptions = {
|
26
|
+
messenger: SubscriptionControllerMessenger;
|
27
|
+
/**
|
28
|
+
* Initial state to set on this controller.
|
29
|
+
*/
|
30
|
+
state?: Partial<SubscriptionControllerState>;
|
31
|
+
/**
|
32
|
+
* Subscription service to use for the subscription controller.
|
33
|
+
*/
|
34
|
+
subscriptionService: ISubscriptionService;
|
35
|
+
};
|
36
|
+
/**
|
37
|
+
* Get the default state for the Subscription Controller.
|
38
|
+
*
|
39
|
+
* @returns The default state for the Subscription Controller.
|
40
|
+
*/
|
41
|
+
export declare function getDefaultSubscriptionControllerState(): SubscriptionControllerState;
|
42
|
+
export declare class SubscriptionController extends BaseController<typeof controllerName, SubscriptionControllerState, SubscriptionControllerMessenger> {
|
43
|
+
#private;
|
44
|
+
/**
|
45
|
+
* Creates a new SubscriptionController instance.
|
46
|
+
*
|
47
|
+
* @param options - The options for the SubscriptionController.
|
48
|
+
* @param options.messenger - A restricted messenger.
|
49
|
+
* @param options.state - Initial state to set on this controller.
|
50
|
+
* @param options.subscriptionService - The subscription service for communicating with subscription server.
|
51
|
+
*/
|
52
|
+
constructor({ messenger, state, subscriptionService, }: SubscriptionControllerOptions);
|
53
|
+
getSubscriptions(): Promise<Subscription[]>;
|
54
|
+
cancelSubscription(request: {
|
55
|
+
subscriptionId: string;
|
56
|
+
}): Promise<void>;
|
57
|
+
}
|
58
|
+
export {};
|
59
|
+
//# sourceMappingURL=SubscriptionController.d.cts.map
|
@@ -0,0 +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,EAAE,oBAAoB,EAAE,YAAY,EAAE,oBAAgB;AAElE,MAAM,MAAM,2BAA2B,GAAG;IACxC,aAAa,EAAE,YAAY,EAAE,CAAC;CAC/B,CAAC;AAGF,KAAK,gBAAgB,CAAC,UAAU,SAAS,MAAM,sBAAsB,IAAI;KACtE,CAAC,IAAI,UAAU,GAAG;QACjB,IAAI,EAAE,GAAG,OAAO,cAAc,IAAI,CAAC,EAAE,CAAC;QACtC,OAAO,EAAE,sBAAsB,CAAC,CAAC,CAAC,CAAC;KACpC;CACF,CAAC;AACF,KAAK,UAAU,GAAG,gBAAgB,CAAC,kBAAkB,GAAG,oBAAoB,CAAC,CAAC;AAE9E,MAAM,MAAM,oCAAoC,GAAG,wBAAwB,CACzE,OAAO,cAAc,EACrB,2BAA2B,CAC5B,CAAC;AACF,MAAM,MAAM,6BAA6B,GACrC,UAAU,CAAC,MAAM,UAAU,CAAC,GAC5B,oCAAoC,CAAC;AAEzC,MAAM,MAAM,cAAc,GACxB,wBAAwB,CAAC,sCAAsC,CAAC;AAGlE,MAAM,MAAM,sCAAsC,GAAG,0BAA0B,CAC7E,OAAO,cAAc,EACrB,2BAA2B,CAC5B,CAAC;AACF,MAAM,MAAM,4BAA4B,GACtC,sCAAsC,CAAC;AAEzC,MAAM,MAAM,aAAa,GACvB,wBAAwB,CAAC,wCAAwC,CAAC;AAGpE,MAAM,MAAM,+BAA+B,GAAG,mBAAmB,CAC/D,OAAO,cAAc,EACrB,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;IAgC1B,gBAAgB;IAWhB,kBAAkB,CAAC,OAAO,EAAE;QAAE,cAAc,EAAE,MAAM,CAAA;KAAE;CAyB7D"}
|
@@ -0,0 +1,59 @@
|
|
1
|
+
import { BaseController, type ControllerStateChangeEvent, type ControllerGetStateAction, type RestrictedMessenger } from "@metamask/base-controller";
|
2
|
+
import type { AuthenticationController } from "@metamask/profile-sync-controller";
|
3
|
+
import { controllerName } from "./constants.mjs";
|
4
|
+
import type { ISubscriptionService, Subscription } from "./types.mjs";
|
5
|
+
export type SubscriptionControllerState = {
|
6
|
+
subscriptions: Subscription[];
|
7
|
+
};
|
8
|
+
type CreateActionsObj<Controller extends keyof SubscriptionController> = {
|
9
|
+
[K in Controller]: {
|
10
|
+
type: `${typeof controllerName}:${K}`;
|
11
|
+
handler: SubscriptionController[K];
|
12
|
+
};
|
13
|
+
};
|
14
|
+
type ActionsObj = CreateActionsObj<'getSubscriptions' | 'cancelSubscription'>;
|
15
|
+
export type SubscriptionControllerGetStateAction = ControllerGetStateAction<typeof controllerName, SubscriptionControllerState>;
|
16
|
+
export type SubscriptionControllerActions = ActionsObj[keyof ActionsObj] | SubscriptionControllerGetStateAction;
|
17
|
+
export type AllowedActions = AuthenticationController.AuthenticationControllerGetBearerToken;
|
18
|
+
export type SubscriptionControllerStateChangeEvent = ControllerStateChangeEvent<typeof controllerName, SubscriptionControllerState>;
|
19
|
+
export type SubscriptionControllerEvents = SubscriptionControllerStateChangeEvent;
|
20
|
+
export type AllowedEvents = AuthenticationController.AuthenticationControllerStateChangeEvent;
|
21
|
+
export type SubscriptionControllerMessenger = RestrictedMessenger<typeof controllerName, SubscriptionControllerActions | AllowedActions, SubscriptionControllerEvents | AllowedEvents, AllowedActions['type'], AllowedEvents['type']>;
|
22
|
+
/**
|
23
|
+
* Subscription Controller Options.
|
24
|
+
*/
|
25
|
+
export type SubscriptionControllerOptions = {
|
26
|
+
messenger: SubscriptionControllerMessenger;
|
27
|
+
/**
|
28
|
+
* Initial state to set on this controller.
|
29
|
+
*/
|
30
|
+
state?: Partial<SubscriptionControllerState>;
|
31
|
+
/**
|
32
|
+
* Subscription service to use for the subscription controller.
|
33
|
+
*/
|
34
|
+
subscriptionService: ISubscriptionService;
|
35
|
+
};
|
36
|
+
/**
|
37
|
+
* Get the default state for the Subscription Controller.
|
38
|
+
*
|
39
|
+
* @returns The default state for the Subscription Controller.
|
40
|
+
*/
|
41
|
+
export declare function getDefaultSubscriptionControllerState(): SubscriptionControllerState;
|
42
|
+
export declare class SubscriptionController extends BaseController<typeof controllerName, SubscriptionControllerState, SubscriptionControllerMessenger> {
|
43
|
+
#private;
|
44
|
+
/**
|
45
|
+
* Creates a new SubscriptionController instance.
|
46
|
+
*
|
47
|
+
* @param options - The options for the SubscriptionController.
|
48
|
+
* @param options.messenger - A restricted messenger.
|
49
|
+
* @param options.state - Initial state to set on this controller.
|
50
|
+
* @param options.subscriptionService - The subscription service for communicating with subscription server.
|
51
|
+
*/
|
52
|
+
constructor({ messenger, state, subscriptionService, }: SubscriptionControllerOptions);
|
53
|
+
getSubscriptions(): Promise<Subscription[]>;
|
54
|
+
cancelSubscription(request: {
|
55
|
+
subscriptionId: string;
|
56
|
+
}): Promise<void>;
|
57
|
+
}
|
58
|
+
export {};
|
59
|
+
//# sourceMappingURL=SubscriptionController.d.mts.map
|
@@ -0,0 +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,EAAE,oBAAoB,EAAE,YAAY,EAAE,oBAAgB;AAElE,MAAM,MAAM,2BAA2B,GAAG;IACxC,aAAa,EAAE,YAAY,EAAE,CAAC;CAC/B,CAAC;AAGF,KAAK,gBAAgB,CAAC,UAAU,SAAS,MAAM,sBAAsB,IAAI;KACtE,CAAC,IAAI,UAAU,GAAG;QACjB,IAAI,EAAE,GAAG,OAAO,cAAc,IAAI,CAAC,EAAE,CAAC;QACtC,OAAO,EAAE,sBAAsB,CAAC,CAAC,CAAC,CAAC;KACpC;CACF,CAAC;AACF,KAAK,UAAU,GAAG,gBAAgB,CAAC,kBAAkB,GAAG,oBAAoB,CAAC,CAAC;AAE9E,MAAM,MAAM,oCAAoC,GAAG,wBAAwB,CACzE,OAAO,cAAc,EACrB,2BAA2B,CAC5B,CAAC;AACF,MAAM,MAAM,6BAA6B,GACrC,UAAU,CAAC,MAAM,UAAU,CAAC,GAC5B,oCAAoC,CAAC;AAEzC,MAAM,MAAM,cAAc,GACxB,wBAAwB,CAAC,sCAAsC,CAAC;AAGlE,MAAM,MAAM,sCAAsC,GAAG,0BAA0B,CAC7E,OAAO,cAAc,EACrB,2BAA2B,CAC5B,CAAC;AACF,MAAM,MAAM,4BAA4B,GACtC,sCAAsC,CAAC;AAEzC,MAAM,MAAM,aAAa,GACvB,wBAAwB,CAAC,wCAAwC,CAAC;AAGpE,MAAM,MAAM,+BAA+B,GAAG,mBAAmB,CAC/D,OAAO,cAAc,EACrB,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;IAgC1B,gBAAgB;IAWhB,kBAAkB,CAAC,OAAO,EAAE;QAAE,cAAc,EAAE,MAAM,CAAA;KAAE;CAyB7D"}
|
@@ -0,0 +1,89 @@
|
|
1
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
2
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
5
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
6
|
+
};
|
7
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
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
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
11
|
+
};
|
12
|
+
var _SubscriptionController_instances, _SubscriptionController_subscriptionService, _SubscriptionController_registerMessageHandlers, _SubscriptionController_assertIsUserSubscribed;
|
13
|
+
import { BaseController } from "@metamask/base-controller";
|
14
|
+
import { controllerName, SubscriptionControllerErrorMessage } from "./constants.mjs";
|
15
|
+
/**
|
16
|
+
* Get the default state for the Subscription Controller.
|
17
|
+
*
|
18
|
+
* @returns The default state for the Subscription Controller.
|
19
|
+
*/
|
20
|
+
export function getDefaultSubscriptionControllerState() {
|
21
|
+
return {
|
22
|
+
subscriptions: [],
|
23
|
+
};
|
24
|
+
}
|
25
|
+
/**
|
26
|
+
* Seedless Onboarding Controller State Metadata.
|
27
|
+
*
|
28
|
+
* This allows us to choose if fields of the state should be persisted or not
|
29
|
+
* using the `persist` flag; and if they can be sent to Sentry or not, using
|
30
|
+
* the `anonymous` flag.
|
31
|
+
*/
|
32
|
+
const subscriptionControllerMetadata = {
|
33
|
+
subscriptions: {
|
34
|
+
persist: true,
|
35
|
+
anonymous: false,
|
36
|
+
},
|
37
|
+
};
|
38
|
+
export class SubscriptionController extends BaseController {
|
39
|
+
/**
|
40
|
+
* Creates a new SubscriptionController instance.
|
41
|
+
*
|
42
|
+
* @param options - The options for the SubscriptionController.
|
43
|
+
* @param options.messenger - A restricted messenger.
|
44
|
+
* @param options.state - Initial state to set on this controller.
|
45
|
+
* @param options.subscriptionService - The subscription service for communicating with subscription server.
|
46
|
+
*/
|
47
|
+
constructor({ messenger, state, subscriptionService, }) {
|
48
|
+
super({
|
49
|
+
name: controllerName,
|
50
|
+
metadata: subscriptionControllerMetadata,
|
51
|
+
state: {
|
52
|
+
...getDefaultSubscriptionControllerState(),
|
53
|
+
...state,
|
54
|
+
},
|
55
|
+
messenger,
|
56
|
+
});
|
57
|
+
_SubscriptionController_instances.add(this);
|
58
|
+
_SubscriptionController_subscriptionService.set(this, void 0);
|
59
|
+
__classPrivateFieldSet(this, _SubscriptionController_subscriptionService, subscriptionService, "f");
|
60
|
+
__classPrivateFieldGet(this, _SubscriptionController_instances, "m", _SubscriptionController_registerMessageHandlers).call(this);
|
61
|
+
}
|
62
|
+
async getSubscriptions() {
|
63
|
+
const { subscriptions } = await __classPrivateFieldGet(this, _SubscriptionController_subscriptionService, "f").getSubscriptions();
|
64
|
+
this.update((state) => {
|
65
|
+
state.subscriptions = subscriptions;
|
66
|
+
});
|
67
|
+
return subscriptions;
|
68
|
+
}
|
69
|
+
async cancelSubscription(request) {
|
70
|
+
__classPrivateFieldGet(this, _SubscriptionController_instances, "m", _SubscriptionController_assertIsUserSubscribed).call(this, { subscriptionId: request.subscriptionId });
|
71
|
+
await __classPrivateFieldGet(this, _SubscriptionController_subscriptionService, "f").cancelSubscription({
|
72
|
+
subscriptionId: request.subscriptionId,
|
73
|
+
});
|
74
|
+
this.update((state) => {
|
75
|
+
state.subscriptions = state.subscriptions.map((subscription) => subscription.id === request.subscriptionId
|
76
|
+
? { ...subscription, status: 'cancelled' }
|
77
|
+
: subscription);
|
78
|
+
});
|
79
|
+
}
|
80
|
+
}
|
81
|
+
_SubscriptionController_subscriptionService = new WeakMap(), _SubscriptionController_instances = new WeakSet(), _SubscriptionController_registerMessageHandlers = function _SubscriptionController_registerMessageHandlers() {
|
82
|
+
this.messagingSystem.registerActionHandler('SubscriptionController:getSubscriptions', this.getSubscriptions.bind(this));
|
83
|
+
this.messagingSystem.registerActionHandler('SubscriptionController:cancelSubscription', this.cancelSubscription.bind(this));
|
84
|
+
}, _SubscriptionController_assertIsUserSubscribed = function _SubscriptionController_assertIsUserSubscribed(request) {
|
85
|
+
if (!this.state.subscriptions.find((subscription) => subscription.id === request.subscriptionId)) {
|
86
|
+
throw new Error(SubscriptionControllerErrorMessage.UserNotSubscribed);
|
87
|
+
}
|
88
|
+
};
|
89
|
+
//# sourceMappingURL=SubscriptionController.mjs.map
|
@@ -0,0 +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;AAgErB;;;;GAIG;AACH,MAAM,UAAU,qCAAqC;IACnD,OAAO;QACL,aAAa,EAAE,EAAE;KAClB,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,8BAA8B,GAClC;IACE,aAAa,EAAE;QACb,OAAO,EAAE,IAAI;QACb,SAAS,EAAE,KAAK;KACjB;CACF,CAAC;AAEJ,MAAM,OAAO,sBAAuB,SAAQ,cAI3C;IAGC;;;;;;;OAOG;IACH,YAAY,EACV,SAAS,EACT,KAAK,EACL,mBAAmB,GACW;QAC9B,KAAK,CAAC;YACJ,IAAI,EAAE,cAAc;YACpB,QAAQ,EAAE,8BAA8B;YACxC,KAAK,EAAE;gBACL,GAAG,qCAAqC,EAAE;gBAC1C,GAAG,KAAK;aACT;YACD,SAAS;SACV,CAAC,CAAC;;QAvBI,8DAA2C;QAyBlD,uBAAA,IAAI,+CAAwB,mBAAmB,MAAA,CAAC;QAEhD,uBAAA,IAAI,0FAAyB,MAA7B,IAAI,CAA2B,CAAC;IAClC,CAAC;IAkBD,KAAK,CAAC,gBAAgB;QACpB,MAAM,EAAE,aAAa,EAAE,GACrB,MAAM,uBAAA,IAAI,mDAAqB,CAAC,gBAAgB,EAAE,CAAC;QAErD,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;YACpB,KAAK,CAAC,aAAa,GAAG,aAAa,CAAC;QACtC,CAAC,CAAC,CAAC;QAEH,OAAO,aAAa,CAAC;IACvB,CAAC;IAED,KAAK,CAAC,kBAAkB,CAAC,OAAmC;QAC1D,uBAAA,IAAI,yFAAwB,MAA5B,IAAI,EAAyB,EAAE,cAAc,EAAE,OAAO,CAAC,cAAc,EAAE,CAAC,CAAC;QAEzE,MAAM,uBAAA,IAAI,mDAAqB,CAAC,kBAAkB,CAAC;YACjD,cAAc,EAAE,OAAO,CAAC,cAAc;SACvC,CAAC,CAAC;QAEH,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;YACpB,KAAK,CAAC,aAAa,GAAG,KAAK,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,YAAY,EAAE,EAAE,CAC7D,YAAY,CAAC,EAAE,KAAK,OAAO,CAAC,cAAc;gBACxC,CAAC,CAAC,EAAE,GAAG,YAAY,EAAE,MAAM,EAAE,WAAW,EAAE;gBAC1C,CAAC,CAAC,YAAY,CACjB,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;CAWF;;IA/CG,IAAI,CAAC,eAAe,CAAC,qBAAqB,CACxC,yCAAyC,EACzC,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,CACjC,CAAC;IAEF,IAAI,CAAC,eAAe,CAAC,qBAAqB,CACxC,2CAA2C,EAC3C,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,CACnC,CAAC;AACJ,CAAC,2GA6BuB,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 type { ISubscriptionService, Subscription } from './types';\n\nexport type SubscriptionControllerState = {\n subscriptions: Subscription[];\n};\n\n// Messenger Actions\ntype CreateActionsObj<Controller extends keyof SubscriptionController> = {\n [K in Controller]: {\n type: `${typeof controllerName}:${K}`;\n handler: SubscriptionController[K];\n };\n};\ntype ActionsObj = CreateActionsObj<'getSubscriptions' | 'cancelSubscription'>;\n\nexport type SubscriptionControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n SubscriptionControllerState\n>;\nexport type SubscriptionControllerActions =\n | ActionsObj[keyof ActionsObj]\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\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: 'cancelled' }\n : subscription,\n );\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"]}
|
@@ -0,0 +1,65 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
5
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
7
|
+
};
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
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
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
12
|
+
};
|
13
|
+
var _SubscriptionService_instances, _SubscriptionService_env, _SubscriptionService_fetch, _SubscriptionService_makeRequest, _SubscriptionService_getAuthorizationHeader;
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
15
|
+
exports.SubscriptionService = exports.SUBSCRIPTION_URL = void 0;
|
16
|
+
const constants_1 = require("./constants.cjs");
|
17
|
+
const errors_1 = require("./errors.cjs");
|
18
|
+
const SUBSCRIPTION_URL = (env, path) => `${(0, constants_1.getEnvUrls)(env).subscriptionApiUrl}/api/v1/${path}`;
|
19
|
+
exports.SUBSCRIPTION_URL = SUBSCRIPTION_URL;
|
20
|
+
class SubscriptionService {
|
21
|
+
constructor(config) {
|
22
|
+
_SubscriptionService_instances.add(this);
|
23
|
+
_SubscriptionService_env.set(this, void 0);
|
24
|
+
_SubscriptionService_fetch.set(this, void 0);
|
25
|
+
__classPrivateFieldSet(this, _SubscriptionService_env, config.env, "f");
|
26
|
+
this.authUtils = config.auth;
|
27
|
+
__classPrivateFieldSet(this, _SubscriptionService_fetch, config.fetchFn, "f");
|
28
|
+
}
|
29
|
+
async getSubscriptions() {
|
30
|
+
const path = 'subscriptions';
|
31
|
+
return await __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_makeRequest).call(this, path);
|
32
|
+
}
|
33
|
+
async cancelSubscription(params) {
|
34
|
+
const path = `subscriptions/${params.subscriptionId}`;
|
35
|
+
return await __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_makeRequest).call(this, path, 'DELETE');
|
36
|
+
}
|
37
|
+
}
|
38
|
+
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') {
|
40
|
+
try {
|
41
|
+
const headers = await __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_getAuthorizationHeader).call(this);
|
42
|
+
const url = new URL((0, exports.SUBSCRIPTION_URL)(__classPrivateFieldGet(this, _SubscriptionService_env, "f"), path));
|
43
|
+
const response = await __classPrivateFieldGet(this, _SubscriptionService_fetch, "f").call(this, url.toString(), {
|
44
|
+
method,
|
45
|
+
headers: {
|
46
|
+
'Content-Type': 'application/json',
|
47
|
+
...headers,
|
48
|
+
},
|
49
|
+
});
|
50
|
+
const responseBody = await response.json();
|
51
|
+
if (!response.ok) {
|
52
|
+
const { message, error } = responseBody;
|
53
|
+
throw new Error(`HTTP error message: ${message}, error: ${error}`);
|
54
|
+
}
|
55
|
+
return responseBody;
|
56
|
+
}
|
57
|
+
catch (e) {
|
58
|
+
const errorMessage = e instanceof Error ? e.message : JSON.stringify(e ?? 'unknown error');
|
59
|
+
throw new errors_1.SubscriptionServiceError(`failed to make request. ${errorMessage}`);
|
60
|
+
}
|
61
|
+
}, _SubscriptionService_getAuthorizationHeader = async function _SubscriptionService_getAuthorizationHeader() {
|
62
|
+
const accessToken = await this.authUtils.getAccessToken();
|
63
|
+
return { Authorization: `Bearer ${accessToken}` };
|
64
|
+
};
|
65
|
+
//# sourceMappingURL=SubscriptionService.cjs.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"SubscriptionService.cjs","sourceRoot":"","sources":["../src/SubscriptionService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,+CAAmD;AACnD,yCAAoD;AAkB7C,MAAM,gBAAgB,GAAG,CAAC,GAAQ,EAAE,IAAY,EAAE,EAAE,CACzD,GAAG,IAAA,sBAAU,EAAC,GAAG,CAAC,CAAC,kBAAkB,WAAW,IAAI,EAAE,CAAC;AAD5C,QAAA,gBAAgB,oBAC4B;AAEzD,MAAa,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,MAAM,CAAC,cAAc,EAAE,CAAC;QACtD,OAAO,MAAM,uBAAA,IAAI,wEAAa,MAAjB,IAAI,EAAc,IAAI,EAAE,QAAQ,CAAC,CAAC;IACjD,CAAC;CAuCF;AA5DD,kDA4DC;yKArCC,KAAK,2CACH,IAAY,EACZ,SAAsD,KAAK;IAE3D,IAAI;QACF,MAAM,OAAO,GAAG,MAAM,uBAAA,IAAI,mFAAwB,MAA5B,IAAI,CAA0B,CAAC;QACrD,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,IAAA,wBAAgB,EAAC,uBAAA,IAAI,gCAAK,EAAE,IAAI,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;SACF,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 { getEnvUrls, type Env } from './constants';\nimport { SubscriptionServiceError } from './errors';\nimport type {\n AuthUtils,\n GetSubscriptionsResponse,\n ISubscriptionService,\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 #makeRequest<Result>(\n path: string,\n method: 'GET' | 'POST' | 'DELETE' | 'PUT' | 'PATCH' = 'GET',\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 });\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"]}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import { type Env } from "./constants.cjs";
|
2
|
+
import type { AuthUtils, GetSubscriptionsResponse, ISubscriptionService } from "./types.cjs";
|
3
|
+
export type SubscriptionServiceConfig = {
|
4
|
+
env: Env;
|
5
|
+
auth: AuthUtils;
|
6
|
+
fetchFn: typeof globalThis.fetch;
|
7
|
+
};
|
8
|
+
export declare const SUBSCRIPTION_URL: (env: Env, path: string) => string;
|
9
|
+
export declare class SubscriptionService implements ISubscriptionService {
|
10
|
+
#private;
|
11
|
+
authUtils: AuthUtils;
|
12
|
+
constructor(config: SubscriptionServiceConfig);
|
13
|
+
getSubscriptions(): Promise<GetSubscriptionsResponse>;
|
14
|
+
cancelSubscription(params: {
|
15
|
+
subscriptionId: string;
|
16
|
+
}): Promise<void>;
|
17
|
+
}
|
18
|
+
//# sourceMappingURL=SubscriptionService.d.cts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"SubscriptionService.d.cts","sourceRoot":"","sources":["../src/SubscriptionService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,KAAK,GAAG,EAAE,wBAAoB;AAEnD,OAAO,KAAK,EACV,SAAS,EACT,wBAAwB,EACxB,oBAAoB,EACrB,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;CA0C5E"}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import { type Env } from "./constants.mjs";
|
2
|
+
import type { AuthUtils, GetSubscriptionsResponse, ISubscriptionService } from "./types.mjs";
|
3
|
+
export type SubscriptionServiceConfig = {
|
4
|
+
env: Env;
|
5
|
+
auth: AuthUtils;
|
6
|
+
fetchFn: typeof globalThis.fetch;
|
7
|
+
};
|
8
|
+
export declare const SUBSCRIPTION_URL: (env: Env, path: string) => string;
|
9
|
+
export declare class SubscriptionService implements ISubscriptionService {
|
10
|
+
#private;
|
11
|
+
authUtils: AuthUtils;
|
12
|
+
constructor(config: SubscriptionServiceConfig);
|
13
|
+
getSubscriptions(): Promise<GetSubscriptionsResponse>;
|
14
|
+
cancelSubscription(params: {
|
15
|
+
subscriptionId: string;
|
16
|
+
}): Promise<void>;
|
17
|
+
}
|
18
|
+
//# sourceMappingURL=SubscriptionService.d.mts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"SubscriptionService.d.mts","sourceRoot":"","sources":["../src/SubscriptionService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,KAAK,GAAG,EAAE,wBAAoB;AAEnD,OAAO,KAAK,EACV,SAAS,EACT,wBAAwB,EACxB,oBAAoB,EACrB,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;CA0C5E"}
|
@@ -0,0 +1,60 @@
|
|
1
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
2
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
5
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
6
|
+
};
|
7
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
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
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
11
|
+
};
|
12
|
+
var _SubscriptionService_instances, _SubscriptionService_env, _SubscriptionService_fetch, _SubscriptionService_makeRequest, _SubscriptionService_getAuthorizationHeader;
|
13
|
+
import { getEnvUrls } from "./constants.mjs";
|
14
|
+
import { SubscriptionServiceError } from "./errors.mjs";
|
15
|
+
export const SUBSCRIPTION_URL = (env, path) => `${getEnvUrls(env).subscriptionApiUrl}/api/v1/${path}`;
|
16
|
+
export class SubscriptionService {
|
17
|
+
constructor(config) {
|
18
|
+
_SubscriptionService_instances.add(this);
|
19
|
+
_SubscriptionService_env.set(this, void 0);
|
20
|
+
_SubscriptionService_fetch.set(this, void 0);
|
21
|
+
__classPrivateFieldSet(this, _SubscriptionService_env, config.env, "f");
|
22
|
+
this.authUtils = config.auth;
|
23
|
+
__classPrivateFieldSet(this, _SubscriptionService_fetch, config.fetchFn, "f");
|
24
|
+
}
|
25
|
+
async getSubscriptions() {
|
26
|
+
const path = 'subscriptions';
|
27
|
+
return await __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_makeRequest).call(this, path);
|
28
|
+
}
|
29
|
+
async cancelSubscription(params) {
|
30
|
+
const path = `subscriptions/${params.subscriptionId}`;
|
31
|
+
return await __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_makeRequest).call(this, path, 'DELETE');
|
32
|
+
}
|
33
|
+
}
|
34
|
+
_SubscriptionService_env = new WeakMap(), _SubscriptionService_fetch = new WeakMap(), _SubscriptionService_instances = new WeakSet(), _SubscriptionService_makeRequest = async function _SubscriptionService_makeRequest(path, method = 'GET') {
|
35
|
+
try {
|
36
|
+
const headers = await __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_getAuthorizationHeader).call(this);
|
37
|
+
const url = new URL(SUBSCRIPTION_URL(__classPrivateFieldGet(this, _SubscriptionService_env, "f"), path));
|
38
|
+
const response = await __classPrivateFieldGet(this, _SubscriptionService_fetch, "f").call(this, url.toString(), {
|
39
|
+
method,
|
40
|
+
headers: {
|
41
|
+
'Content-Type': 'application/json',
|
42
|
+
...headers,
|
43
|
+
},
|
44
|
+
});
|
45
|
+
const responseBody = await response.json();
|
46
|
+
if (!response.ok) {
|
47
|
+
const { message, error } = responseBody;
|
48
|
+
throw new Error(`HTTP error message: ${message}, error: ${error}`);
|
49
|
+
}
|
50
|
+
return responseBody;
|
51
|
+
}
|
52
|
+
catch (e) {
|
53
|
+
const errorMessage = e instanceof Error ? e.message : JSON.stringify(e ?? 'unknown error');
|
54
|
+
throw new SubscriptionServiceError(`failed to make request. ${errorMessage}`);
|
55
|
+
}
|
56
|
+
}, _SubscriptionService_getAuthorizationHeader = async function _SubscriptionService_getAuthorizationHeader() {
|
57
|
+
const accessToken = await this.authUtils.getAccessToken();
|
58
|
+
return { Authorization: `Bearer ${accessToken}` };
|
59
|
+
};
|
60
|
+
//# sourceMappingURL=SubscriptionService.mjs.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"SubscriptionService.mjs","sourceRoot":"","sources":["../src/SubscriptionService.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAY,wBAAoB;AACnD,OAAO,EAAE,wBAAwB,EAAE,qBAAiB;AAkBpD,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,MAAM,CAAC,cAAc,EAAE,CAAC;QACtD,OAAO,MAAM,uBAAA,IAAI,wEAAa,MAAjB,IAAI,EAAc,IAAI,EAAE,QAAQ,CAAC,CAAC;IACjD,CAAC;CAuCF;yKArCC,KAAK,2CACH,IAAY,EACZ,SAAsD,KAAK;IAE3D,IAAI;QACF,MAAM,OAAO,GAAG,MAAM,uBAAA,IAAI,mFAAwB,MAA5B,IAAI,CAA0B,CAAC;QACrD,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,gBAAgB,CAAC,uBAAA,IAAI,gCAAK,EAAE,IAAI,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;SACF,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 { getEnvUrls, type Env } from './constants';\nimport { SubscriptionServiceError } from './errors';\nimport type {\n AuthUtils,\n GetSubscriptionsResponse,\n ISubscriptionService,\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 #makeRequest<Result>(\n path: string,\n method: 'GET' | 'POST' | 'DELETE' | 'PUT' | 'PATCH' = 'GET',\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 });\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"]}
|
@@ -0,0 +1,41 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.SubscriptionControllerErrorMessage = exports.getEnvUrls = exports.Env = exports.controllerName = void 0;
|
4
|
+
exports.controllerName = 'SubscriptionController';
|
5
|
+
var Env;
|
6
|
+
(function (Env) {
|
7
|
+
Env["DEV"] = "dev";
|
8
|
+
Env["UAT"] = "uat";
|
9
|
+
Env["PRD"] = "prd";
|
10
|
+
})(Env || (exports.Env = Env = {}));
|
11
|
+
const ENV_URLS = {
|
12
|
+
dev: {
|
13
|
+
subscriptionApiUrl: 'https://subscription-service.dev-api.cx.metamask.io',
|
14
|
+
},
|
15
|
+
uat: {
|
16
|
+
subscriptionApiUrl: 'https://subscription-service.uat-api.cx.metamask.io',
|
17
|
+
},
|
18
|
+
prd: {
|
19
|
+
subscriptionApiUrl: 'https://subscription-service.api.cx.metamask.io',
|
20
|
+
},
|
21
|
+
};
|
22
|
+
/**
|
23
|
+
* Validates and returns correct environment endpoints
|
24
|
+
*
|
25
|
+
* @param env - environment field
|
26
|
+
* @returns the correct environment url
|
27
|
+
* @throws on invalid environment passed
|
28
|
+
*/
|
29
|
+
function getEnvUrls(env) {
|
30
|
+
if (!ENV_URLS[env]) {
|
31
|
+
throw new Error('invalid environment configuration');
|
32
|
+
}
|
33
|
+
return ENV_URLS[env];
|
34
|
+
}
|
35
|
+
exports.getEnvUrls = getEnvUrls;
|
36
|
+
var SubscriptionControllerErrorMessage;
|
37
|
+
(function (SubscriptionControllerErrorMessage) {
|
38
|
+
SubscriptionControllerErrorMessage["UserAlreadySubscribed"] = "SubscriptionController - User is already subscribed";
|
39
|
+
SubscriptionControllerErrorMessage["UserNotSubscribed"] = "SubscriptionController - User is not subscribed";
|
40
|
+
})(SubscriptionControllerErrorMessage || (exports.SubscriptionControllerErrorMessage = SubscriptionControllerErrorMessage = {}));
|
41
|
+
//# sourceMappingURL=constants.cjs.map
|
@@ -0,0 +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,kCAGX;AAHD,WAAY,kCAAkC;IAC5C,mHAAwE,CAAA;IACxE,2GAAgE,CAAA;AAClE,CAAC,EAHW,kCAAkC,kDAAlC,kCAAkC,QAG7C","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}\n"]}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
export declare const controllerName = "SubscriptionController";
|
2
|
+
export declare enum Env {
|
3
|
+
DEV = "dev",
|
4
|
+
UAT = "uat",
|
5
|
+
PRD = "prd"
|
6
|
+
}
|
7
|
+
type EnvUrlsEntry = {
|
8
|
+
subscriptionApiUrl: string;
|
9
|
+
};
|
10
|
+
/**
|
11
|
+
* Validates and returns correct environment endpoints
|
12
|
+
*
|
13
|
+
* @param env - environment field
|
14
|
+
* @returns the correct environment url
|
15
|
+
* @throws on invalid environment passed
|
16
|
+
*/
|
17
|
+
export declare function getEnvUrls(env: Env): EnvUrlsEntry;
|
18
|
+
export declare enum SubscriptionControllerErrorMessage {
|
19
|
+
UserAlreadySubscribed = "SubscriptionController - User is already subscribed",
|
20
|
+
UserNotSubscribed = "SubscriptionController - User is not subscribed"
|
21
|
+
}
|
22
|
+
export {};
|
23
|
+
//# sourceMappingURL=constants.d.cts.map
|
@@ -0,0 +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;CACjE"}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
export declare const controllerName = "SubscriptionController";
|
2
|
+
export declare enum Env {
|
3
|
+
DEV = "dev",
|
4
|
+
UAT = "uat",
|
5
|
+
PRD = "prd"
|
6
|
+
}
|
7
|
+
type EnvUrlsEntry = {
|
8
|
+
subscriptionApiUrl: string;
|
9
|
+
};
|
10
|
+
/**
|
11
|
+
* Validates and returns correct environment endpoints
|
12
|
+
*
|
13
|
+
* @param env - environment field
|
14
|
+
* @returns the correct environment url
|
15
|
+
* @throws on invalid environment passed
|
16
|
+
*/
|
17
|
+
export declare function getEnvUrls(env: Env): EnvUrlsEntry;
|
18
|
+
export declare enum SubscriptionControllerErrorMessage {
|
19
|
+
UserAlreadySubscribed = "SubscriptionController - User is already subscribed",
|
20
|
+
UserNotSubscribed = "SubscriptionController - User is not subscribed"
|
21
|
+
}
|
22
|
+
export {};
|
23
|
+
//# sourceMappingURL=constants.d.mts.map
|
@@ -0,0 +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;CACjE"}
|
@@ -0,0 +1,37 @@
|
|
1
|
+
export const controllerName = 'SubscriptionController';
|
2
|
+
export var Env;
|
3
|
+
(function (Env) {
|
4
|
+
Env["DEV"] = "dev";
|
5
|
+
Env["UAT"] = "uat";
|
6
|
+
Env["PRD"] = "prd";
|
7
|
+
})(Env || (Env = {}));
|
8
|
+
const ENV_URLS = {
|
9
|
+
dev: {
|
10
|
+
subscriptionApiUrl: 'https://subscription-service.dev-api.cx.metamask.io',
|
11
|
+
},
|
12
|
+
uat: {
|
13
|
+
subscriptionApiUrl: 'https://subscription-service.uat-api.cx.metamask.io',
|
14
|
+
},
|
15
|
+
prd: {
|
16
|
+
subscriptionApiUrl: 'https://subscription-service.api.cx.metamask.io',
|
17
|
+
},
|
18
|
+
};
|
19
|
+
/**
|
20
|
+
* Validates and returns correct environment endpoints
|
21
|
+
*
|
22
|
+
* @param env - environment field
|
23
|
+
* @returns the correct environment url
|
24
|
+
* @throws on invalid environment passed
|
25
|
+
*/
|
26
|
+
export function getEnvUrls(env) {
|
27
|
+
if (!ENV_URLS[env]) {
|
28
|
+
throw new Error('invalid environment configuration');
|
29
|
+
}
|
30
|
+
return ENV_URLS[env];
|
31
|
+
}
|
32
|
+
export var SubscriptionControllerErrorMessage;
|
33
|
+
(function (SubscriptionControllerErrorMessage) {
|
34
|
+
SubscriptionControllerErrorMessage["UserAlreadySubscribed"] = "SubscriptionController - User is already subscribed";
|
35
|
+
SubscriptionControllerErrorMessage["UserNotSubscribed"] = "SubscriptionController - User is not subscribed";
|
36
|
+
})(SubscriptionControllerErrorMessage || (SubscriptionControllerErrorMessage = {}));
|
37
|
+
//# sourceMappingURL=constants.mjs.map
|
@@ -0,0 +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,kCAGX;AAHD,WAAY,kCAAkC;IAC5C,mHAAwE,CAAA;IACxE,2GAAgE,CAAA;AAClE,CAAC,EAHW,kCAAkC,KAAlC,kCAAkC,QAG7C","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}\n"]}
|
package/dist/errors.cjs
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.SubscriptionServiceError = void 0;
|
4
|
+
class SubscriptionServiceError extends Error {
|
5
|
+
constructor(message) {
|
6
|
+
super(message);
|
7
|
+
this.name = 'SubscriptionServiceError';
|
8
|
+
}
|
9
|
+
}
|
10
|
+
exports.SubscriptionServiceError = SubscriptionServiceError;
|
11
|
+
//# sourceMappingURL=errors.cjs.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"errors.cjs","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";;;AAAA,MAAa,wBAAyB,SAAQ,KAAK;IACjD,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAC;IACzC,CAAC;CACF;AALD,4DAKC","sourcesContent":["export class SubscriptionServiceError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'SubscriptionServiceError';\n }\n}\n"]}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"errors.d.cts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,wBAAyB,SAAQ,KAAK;gBACrC,OAAO,EAAE,MAAM;CAI5B"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"errors.d.mts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,wBAAyB,SAAQ,KAAK;gBACrC,OAAO,EAAE,MAAM;CAI5B"}
|
package/dist/errors.mjs
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"errors.mjs","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,wBAAyB,SAAQ,KAAK;IACjD,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAC;IACzC,CAAC;CACF","sourcesContent":["export class SubscriptionServiceError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'SubscriptionServiceError';\n }\n}\n"]}
|
package/dist/index.cjs
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.SubscriptionService = exports.SubscriptionControllerErrorMessage = exports.Env = exports.SubscriptionServiceError = exports.getDefaultSubscriptionControllerState = exports.SubscriptionController = void 0;
|
4
|
+
var SubscriptionController_1 = require("./SubscriptionController.cjs");
|
5
|
+
Object.defineProperty(exports, "SubscriptionController", { enumerable: true, get: function () { return SubscriptionController_1.SubscriptionController; } });
|
6
|
+
Object.defineProperty(exports, "getDefaultSubscriptionControllerState", { enumerable: true, get: function () { return SubscriptionController_1.getDefaultSubscriptionControllerState; } });
|
7
|
+
var errors_1 = require("./errors.cjs");
|
8
|
+
Object.defineProperty(exports, "SubscriptionServiceError", { enumerable: true, get: function () { return errors_1.SubscriptionServiceError; } });
|
9
|
+
var constants_1 = require("./constants.cjs");
|
10
|
+
Object.defineProperty(exports, "Env", { enumerable: true, get: function () { return constants_1.Env; } });
|
11
|
+
Object.defineProperty(exports, "SubscriptionControllerErrorMessage", { enumerable: true, get: function () { return constants_1.SubscriptionControllerErrorMessage; } });
|
12
|
+
var SubscriptionService_1 = require("./SubscriptionService.cjs");
|
13
|
+
Object.defineProperty(exports, "SubscriptionService", { enumerable: true, get: function () { return SubscriptionService_1.SubscriptionService; } });
|
14
|
+
//# sourceMappingURL=index.cjs.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AASA,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 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
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
export type { SubscriptionControllerActions, SubscriptionControllerState, SubscriptionControllerEvents, SubscriptionControllerGetStateAction, SubscriptionControllerMessenger, SubscriptionControllerOptions, SubscriptionControllerStateChangeEvent, } from "./SubscriptionController.cjs";
|
2
|
+
export { SubscriptionController, getDefaultSubscriptionControllerState, } from "./SubscriptionController.cjs";
|
3
|
+
export type { Subscription, AuthUtils, ISubscriptionService, PaymentMethod, PaymentType, Product, ProductType, } from "./types.cjs";
|
4
|
+
export { SubscriptionServiceError } from "./errors.cjs";
|
5
|
+
export { Env, SubscriptionControllerErrorMessage } from "./constants.cjs";
|
6
|
+
export type { SubscriptionServiceConfig } from "./SubscriptionService.cjs";
|
7
|
+
export { SubscriptionService } from "./SubscriptionService.cjs";
|
8
|
+
//# sourceMappingURL=index.d.cts.map
|
@@ -0,0 +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"}
|
package/dist/index.d.mts
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
export type { SubscriptionControllerActions, SubscriptionControllerState, SubscriptionControllerEvents, SubscriptionControllerGetStateAction, SubscriptionControllerMessenger, SubscriptionControllerOptions, SubscriptionControllerStateChangeEvent, } from "./SubscriptionController.mjs";
|
2
|
+
export { SubscriptionController, getDefaultSubscriptionControllerState, } from "./SubscriptionController.mjs";
|
3
|
+
export type { Subscription, AuthUtils, ISubscriptionService, PaymentMethod, PaymentType, Product, ProductType, } from "./types.mjs";
|
4
|
+
export { SubscriptionServiceError } from "./errors.mjs";
|
5
|
+
export { Env, SubscriptionControllerErrorMessage } from "./constants.mjs";
|
6
|
+
export type { SubscriptionServiceConfig } from "./SubscriptionService.mjs";
|
7
|
+
export { SubscriptionService } from "./SubscriptionService.mjs";
|
8
|
+
//# sourceMappingURL=index.d.mts.map
|
@@ -0,0 +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"}
|
package/dist/index.mjs
ADDED
@@ -0,0 +1,5 @@
|
|
1
|
+
export { SubscriptionController, getDefaultSubscriptionControllerState } from "./SubscriptionController.mjs";
|
2
|
+
export { SubscriptionServiceError } from "./errors.mjs";
|
3
|
+
export { Env, SubscriptionControllerErrorMessage } from "./constants.mjs";
|
4
|
+
export { SubscriptionService } from "./SubscriptionService.mjs";
|
5
|
+
//# sourceMappingURL=index.mjs.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AASA,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 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
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.PaymentType = exports.ProductType = void 0;
|
4
|
+
var ProductType;
|
5
|
+
(function (ProductType) {
|
6
|
+
ProductType["SHIELD"] = "shield";
|
7
|
+
})(ProductType || (exports.ProductType = ProductType = {}));
|
8
|
+
var PaymentType;
|
9
|
+
(function (PaymentType) {
|
10
|
+
PaymentType["CARD"] = "card";
|
11
|
+
PaymentType["CRYPTO"] = "crypto";
|
12
|
+
})(PaymentType || (exports.PaymentType = PaymentType = {}));
|
13
|
+
//# sourceMappingURL=types.cjs.map
|
@@ -0,0 +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,4BAAa,CAAA;IACb,gCAAiB,CAAA;AACnB,CAAC,EAHW,WAAW,2BAAX,WAAW,QAGtB","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 CARD = 'card',\n CRYPTO = 'crypto',\n}\n\nexport type PaymentMethod = {\n type: PaymentType;\n crypto?: {\n payerAddress: string;\n chainId: string;\n tokenSymbol: string;\n };\n};\n\n// state\nexport type Subscription = {\n id: string;\n products: Product[];\n currentPeriodStart: string; // ISO 8601\n currentPeriodEnd: string; // ISO 8601\n billingCycles?: number;\n status: 'active' | 'inactive' | 'trialing' | 'cancelled';\n interval: 'month' | 'year';\n paymentMethod: PaymentMethod;\n};\n\nexport type GetSubscriptionsResponse = {\n customerId: string;\n subscriptions: Subscription[];\n trialedProducts: ProductType[];\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};\n"]}
|
package/dist/types.d.cts
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
export declare enum ProductType {
|
2
|
+
SHIELD = "shield"
|
3
|
+
}
|
4
|
+
export type Product = {
|
5
|
+
name: ProductType;
|
6
|
+
id: string;
|
7
|
+
currency: string;
|
8
|
+
amount: number;
|
9
|
+
};
|
10
|
+
export declare enum PaymentType {
|
11
|
+
CARD = "card",
|
12
|
+
CRYPTO = "crypto"
|
13
|
+
}
|
14
|
+
export type PaymentMethod = {
|
15
|
+
type: PaymentType;
|
16
|
+
crypto?: {
|
17
|
+
payerAddress: string;
|
18
|
+
chainId: string;
|
19
|
+
tokenSymbol: string;
|
20
|
+
};
|
21
|
+
};
|
22
|
+
export type Subscription = {
|
23
|
+
id: string;
|
24
|
+
products: Product[];
|
25
|
+
currentPeriodStart: string;
|
26
|
+
currentPeriodEnd: string;
|
27
|
+
billingCycles?: number;
|
28
|
+
status: 'active' | 'inactive' | 'trialing' | 'cancelled';
|
29
|
+
interval: 'month' | 'year';
|
30
|
+
paymentMethod: PaymentMethod;
|
31
|
+
};
|
32
|
+
export type GetSubscriptionsResponse = {
|
33
|
+
customerId: string;
|
34
|
+
subscriptions: Subscription[];
|
35
|
+
trialedProducts: ProductType[];
|
36
|
+
};
|
37
|
+
export type AuthUtils = {
|
38
|
+
getAccessToken: () => Promise<string>;
|
39
|
+
};
|
40
|
+
export type ISubscriptionService = {
|
41
|
+
getSubscriptions(): Promise<GetSubscriptionsResponse>;
|
42
|
+
cancelSubscription(request: {
|
43
|
+
subscriptionId: string;
|
44
|
+
}): Promise<void>;
|
45
|
+
};
|
46
|
+
//# sourceMappingURL=types.d.cts.map
|
@@ -0,0 +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,IAAI,SAAS;IACb,MAAM,WAAW;CAClB;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;AAGF,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,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,MAAM,EAAE,QAAQ,GAAG,UAAU,GAAG,UAAU,GAAG,WAAW,CAAC;IACzD,QAAQ,EAAE,OAAO,GAAG,MAAM,CAAC;IAC3B,aAAa,EAAE,aAAa,CAAC;CAC9B,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG;IACrC,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,YAAY,EAAE,CAAC;IAC9B,eAAe,EAAE,WAAW,EAAE,CAAC;CAChC,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;CACxE,CAAC"}
|
package/dist/types.d.mts
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
export declare enum ProductType {
|
2
|
+
SHIELD = "shield"
|
3
|
+
}
|
4
|
+
export type Product = {
|
5
|
+
name: ProductType;
|
6
|
+
id: string;
|
7
|
+
currency: string;
|
8
|
+
amount: number;
|
9
|
+
};
|
10
|
+
export declare enum PaymentType {
|
11
|
+
CARD = "card",
|
12
|
+
CRYPTO = "crypto"
|
13
|
+
}
|
14
|
+
export type PaymentMethod = {
|
15
|
+
type: PaymentType;
|
16
|
+
crypto?: {
|
17
|
+
payerAddress: string;
|
18
|
+
chainId: string;
|
19
|
+
tokenSymbol: string;
|
20
|
+
};
|
21
|
+
};
|
22
|
+
export type Subscription = {
|
23
|
+
id: string;
|
24
|
+
products: Product[];
|
25
|
+
currentPeriodStart: string;
|
26
|
+
currentPeriodEnd: string;
|
27
|
+
billingCycles?: number;
|
28
|
+
status: 'active' | 'inactive' | 'trialing' | 'cancelled';
|
29
|
+
interval: 'month' | 'year';
|
30
|
+
paymentMethod: PaymentMethod;
|
31
|
+
};
|
32
|
+
export type GetSubscriptionsResponse = {
|
33
|
+
customerId: string;
|
34
|
+
subscriptions: Subscription[];
|
35
|
+
trialedProducts: ProductType[];
|
36
|
+
};
|
37
|
+
export type AuthUtils = {
|
38
|
+
getAccessToken: () => Promise<string>;
|
39
|
+
};
|
40
|
+
export type ISubscriptionService = {
|
41
|
+
getSubscriptions(): Promise<GetSubscriptionsResponse>;
|
42
|
+
cancelSubscription(request: {
|
43
|
+
subscriptionId: string;
|
44
|
+
}): Promise<void>;
|
45
|
+
};
|
46
|
+
//# sourceMappingURL=types.d.mts.map
|
@@ -0,0 +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,IAAI,SAAS;IACb,MAAM,WAAW;CAClB;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;AAGF,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,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,MAAM,EAAE,QAAQ,GAAG,UAAU,GAAG,UAAU,GAAG,WAAW,CAAC;IACzD,QAAQ,EAAE,OAAO,GAAG,MAAM,CAAC;IAC3B,aAAa,EAAE,aAAa,CAAC;CAC9B,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG;IACrC,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,YAAY,EAAE,CAAC;IAC9B,eAAe,EAAE,WAAW,EAAE,CAAC;CAChC,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;CACxE,CAAC"}
|
package/dist/types.mjs
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
export var ProductType;
|
2
|
+
(function (ProductType) {
|
3
|
+
ProductType["SHIELD"] = "shield";
|
4
|
+
})(ProductType || (ProductType = {}));
|
5
|
+
export var PaymentType;
|
6
|
+
(function (PaymentType) {
|
7
|
+
PaymentType["CARD"] = "card";
|
8
|
+
PaymentType["CRYPTO"] = "crypto";
|
9
|
+
})(PaymentType || (PaymentType = {}));
|
10
|
+
//# sourceMappingURL=types.mjs.map
|
@@ -0,0 +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,4BAAa,CAAA;IACb,gCAAiB,CAAA;AACnB,CAAC,EAHW,WAAW,KAAX,WAAW,QAGtB","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 CARD = 'card',\n CRYPTO = 'crypto',\n}\n\nexport type PaymentMethod = {\n type: PaymentType;\n crypto?: {\n payerAddress: string;\n chainId: string;\n tokenSymbol: string;\n };\n};\n\n// state\nexport type Subscription = {\n id: string;\n products: Product[];\n currentPeriodStart: string; // ISO 8601\n currentPeriodEnd: string; // ISO 8601\n billingCycles?: number;\n status: 'active' | 'inactive' | 'trialing' | 'cancelled';\n interval: 'month' | 'year';\n paymentMethod: PaymentMethod;\n};\n\nexport type GetSubscriptionsResponse = {\n customerId: string;\n subscriptions: Subscription[];\n trialedProducts: ProductType[];\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};\n"]}
|
package/package.json
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
{
|
2
|
+
"name": "@metamask-previews/subscription-controller",
|
3
|
+
"version": "0.0.0-preview-0b2bfc8a",
|
4
|
+
"description": "Handle user subscription",
|
5
|
+
"keywords": [
|
6
|
+
"MetaMask",
|
7
|
+
"Ethereum"
|
8
|
+
],
|
9
|
+
"homepage": "https://github.com/MetaMask/core/tree/main/packages/subscription-controller#readme",
|
10
|
+
"bugs": {
|
11
|
+
"url": "https://github.com/MetaMask/core/issues"
|
12
|
+
},
|
13
|
+
"repository": {
|
14
|
+
"type": "git",
|
15
|
+
"url": "https://github.com/MetaMask/core.git"
|
16
|
+
},
|
17
|
+
"license": "MIT",
|
18
|
+
"sideEffects": false,
|
19
|
+
"exports": {
|
20
|
+
".": {
|
21
|
+
"import": {
|
22
|
+
"types": "./dist/index.d.mts",
|
23
|
+
"default": "./dist/index.mjs"
|
24
|
+
},
|
25
|
+
"require": {
|
26
|
+
"types": "./dist/index.d.cts",
|
27
|
+
"default": "./dist/index.cjs"
|
28
|
+
}
|
29
|
+
},
|
30
|
+
"./package.json": "./package.json"
|
31
|
+
},
|
32
|
+
"main": "./dist/index.cjs",
|
33
|
+
"types": "./dist/index.d.cts",
|
34
|
+
"files": [
|
35
|
+
"dist/"
|
36
|
+
],
|
37
|
+
"scripts": {
|
38
|
+
"build": "ts-bridge --project tsconfig.build.json --verbose --clean --no-references",
|
39
|
+
"build:docs": "typedoc",
|
40
|
+
"changelog:update": "../../scripts/update-changelog.sh @metamask/subscription-controller",
|
41
|
+
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/subscription-controller",
|
42
|
+
"since-latest-release": "../../scripts/since-latest-release.sh",
|
43
|
+
"publish:preview": "yarn npm publish --tag preview",
|
44
|
+
"test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter",
|
45
|
+
"test:clean": "NODE_OPTIONS=--experimental-vm-modules jest --clearCache",
|
46
|
+
"test:verbose": "NODE_OPTIONS=--experimental-vm-modules jest --verbose",
|
47
|
+
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
|
48
|
+
},
|
49
|
+
"dependencies": {
|
50
|
+
"@metamask/base-controller": "^8.2.0",
|
51
|
+
"@metamask/utils": "^11.4.2"
|
52
|
+
},
|
53
|
+
"devDependencies": {
|
54
|
+
"@metamask/auto-changelog": "^3.4.4",
|
55
|
+
"@metamask/profile-sync-controller": "^24.0.0",
|
56
|
+
"@types/jest": "^27.4.1",
|
57
|
+
"deepmerge": "^4.2.2",
|
58
|
+
"jest": "^27.5.1",
|
59
|
+
"nock": "^13.3.1",
|
60
|
+
"ts-jest": "^27.1.4",
|
61
|
+
"typedoc": "^0.24.8",
|
62
|
+
"typedoc-plugin-missing-exports": "^2.0.0",
|
63
|
+
"typescript": "~5.2.2"
|
64
|
+
},
|
65
|
+
"engines": {
|
66
|
+
"node": "^18.18 || >=20"
|
67
|
+
},
|
68
|
+
"publishConfig": {
|
69
|
+
"access": "public",
|
70
|
+
"registry": "https://registry.npmjs.org/"
|
71
|
+
}
|
72
|
+
}
|