@metamask/subscription-controller 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +32 -0
- package/LICENSE +20 -0
- package/README.md +19 -0
- package/dist/SubscriptionController.cjs +266 -0
- package/dist/SubscriptionController.cjs.map +1 -0
- package/dist/SubscriptionController.d.cts +124 -0
- package/dist/SubscriptionController.d.cts.map +1 -0
- package/dist/SubscriptionController.d.mts +124 -0
- package/dist/SubscriptionController.d.mts.map +1 -0
- package/dist/SubscriptionController.mjs +261 -0
- package/dist/SubscriptionController.mjs.map +1 -0
- package/dist/SubscriptionService.cjs +97 -0
- package/dist/SubscriptionService.cjs.map +1 -0
- package/dist/SubscriptionService.d.cts +26 -0
- package/dist/SubscriptionService.d.cts.map +1 -0
- package/dist/SubscriptionService.d.mts +26 -0
- package/dist/SubscriptionService.d.mts.map +1 -0
- package/dist/SubscriptionService.mjs +92 -0
- package/dist/SubscriptionService.mjs.map +1 -0
- package/dist/constants.cjs +42 -0
- package/dist/constants.cjs.map +1 -0
- package/dist/constants.d.cts +24 -0
- package/dist/constants.d.cts.map +1 -0
- package/dist/constants.d.mts +24 -0
- package/dist/constants.d.mts.map +1 -0
- package/dist/constants.mjs +38 -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 +19 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +9 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +9 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +6 -0
- package/dist/index.mjs.map +1 -0
- package/dist/types.cjs +31 -0
- package/dist/types.cjs.map +1 -0
- package/dist/types.d.cts +211 -0
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.mts +211 -0
- package/dist/types.d.mts.map +1 -0
- package/dist/types.mjs +28 -0
- package/dist/types.mjs.map +1 -0
- package/package.json +75 -0
|
@@ -0,0 +1,42 @@
|
|
|
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.dev-api.cx.metamask.io',
|
|
14
|
+
},
|
|
15
|
+
uat: {
|
|
16
|
+
subscriptionApiUrl: 'https://subscription.uat-api.cx.metamask.io',
|
|
17
|
+
},
|
|
18
|
+
prd: {
|
|
19
|
+
subscriptionApiUrl: 'https://subscription.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["SubscriptionProductsEmpty"] = "SubscriptionController - Subscription products array cannot be empty";
|
|
41
|
+
})(SubscriptionControllerErrorMessage || (exports.SubscriptionControllerErrorMessage = SubscriptionControllerErrorMessage = {}));
|
|
42
|
+
//# 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,6CAA6C;KAClE;IACD,GAAG,EAAE;QACH,kBAAkB,EAAE,6CAA6C;KAClE;IACD,GAAG,EAAE;QACH,kBAAkB,EAAE,yCAAyC;KAC9D;CACF,CAAC;AAEF;;;;;;GAMG;AACH,SAAgB,UAAU,CAAC,GAAQ;IACjC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;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.dev-api.cx.metamask.io',\n },\n uat: {\n subscriptionApiUrl: 'https://subscription.uat-api.cx.metamask.io',\n },\n prd: {\n subscriptionApiUrl: 'https://subscription.api.cx.metamask.io',\n },\n};\n\n/**\n * Validates and returns correct environment endpoints\n *\n * @param env - environment field\n * @returns the correct environment url\n * @throws on invalid environment passed\n */\nexport function getEnvUrls(env: Env): EnvUrlsEntry {\n if (!ENV_URLS[env]) {\n throw new Error('invalid environment configuration');\n }\n return ENV_URLS[env];\n}\n\nexport enum SubscriptionControllerErrorMessage {\n UserAlreadySubscribed = `${controllerName} - User is already subscribed`,\n UserNotSubscribed = `${controllerName} - User is not subscribed`,\n SubscriptionProductsEmpty = `${controllerName} - Subscription products array cannot be empty`,\n}\n"]}
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
SubscriptionProductsEmpty = "SubscriptionController - Subscription products array cannot be empty"
|
|
22
|
+
}
|
|
23
|
+
export {};
|
|
24
|
+
//# 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;IAChE,yBAAyB,yEAAoE;CAC9F"}
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
SubscriptionProductsEmpty = "SubscriptionController - Subscription products array cannot be empty"
|
|
22
|
+
}
|
|
23
|
+
export {};
|
|
24
|
+
//# 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;IAChE,yBAAyB,yEAAoE;CAC9F"}
|
|
@@ -0,0 +1,38 @@
|
|
|
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.dev-api.cx.metamask.io',
|
|
11
|
+
},
|
|
12
|
+
uat: {
|
|
13
|
+
subscriptionApiUrl: 'https://subscription.uat-api.cx.metamask.io',
|
|
14
|
+
},
|
|
15
|
+
prd: {
|
|
16
|
+
subscriptionApiUrl: 'https://subscription.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["SubscriptionProductsEmpty"] = "SubscriptionController - Subscription products array cannot be empty";
|
|
37
|
+
})(SubscriptionControllerErrorMessage || (SubscriptionControllerErrorMessage = {}));
|
|
38
|
+
//# 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,6CAA6C;KAClE;IACD,GAAG,EAAE;QACH,kBAAkB,EAAE,6CAA6C;KAClE;IACD,GAAG,EAAE;QACH,kBAAkB,EAAE,yCAAyC;KAC9D;CACF,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CAAC,GAAQ;IACjC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;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.dev-api.cx.metamask.io',\n },\n uat: {\n subscriptionApiUrl: 'https://subscription.uat-api.cx.metamask.io',\n },\n prd: {\n subscriptionApiUrl: 'https://subscription.api.cx.metamask.io',\n },\n};\n\n/**\n * Validates and returns correct environment endpoints\n *\n * @param env - environment field\n * @returns the correct environment url\n * @throws on invalid environment passed\n */\nexport function getEnvUrls(env: Env): EnvUrlsEntry {\n if (!ENV_URLS[env]) {\n throw new Error('invalid environment configuration');\n }\n return ENV_URLS[env];\n}\n\nexport enum SubscriptionControllerErrorMessage {\n UserAlreadySubscribed = `${controllerName} - User is already subscribed`,\n UserNotSubscribed = `${controllerName} - User is not subscribed`,\n SubscriptionProductsEmpty = `${controllerName} - Subscription products array cannot be empty`,\n}\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,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SubscriptionService = exports.SubscriptionControllerErrorMessage = exports.Env = exports.SubscriptionServiceError = exports.PAYMENT_TYPES = exports.RECURRING_INTERVALS = exports.PRODUCT_TYPES = exports.SUBSCRIPTION_STATUSES = 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 types_1 = require("./types.cjs");
|
|
8
|
+
Object.defineProperty(exports, "SUBSCRIPTION_STATUSES", { enumerable: true, get: function () { return types_1.SUBSCRIPTION_STATUSES; } });
|
|
9
|
+
Object.defineProperty(exports, "PRODUCT_TYPES", { enumerable: true, get: function () { return types_1.PRODUCT_TYPES; } });
|
|
10
|
+
Object.defineProperty(exports, "RECURRING_INTERVALS", { enumerable: true, get: function () { return types_1.RECURRING_INTERVALS; } });
|
|
11
|
+
Object.defineProperty(exports, "PAYMENT_TYPES", { enumerable: true, get: function () { return types_1.PAYMENT_TYPES; } });
|
|
12
|
+
var errors_1 = require("./errors.cjs");
|
|
13
|
+
Object.defineProperty(exports, "SubscriptionServiceError", { enumerable: true, get: function () { return errors_1.SubscriptionServiceError; } });
|
|
14
|
+
var constants_1 = require("./constants.cjs");
|
|
15
|
+
Object.defineProperty(exports, "Env", { enumerable: true, get: function () { return constants_1.Env; } });
|
|
16
|
+
Object.defineProperty(exports, "SubscriptionControllerErrorMessage", { enumerable: true, get: function () { return constants_1.SubscriptionControllerErrorMessage; } });
|
|
17
|
+
var SubscriptionService_1 = require("./SubscriptionService.cjs");
|
|
18
|
+
Object.defineProperty(exports, "SubscriptionService", { enumerable: true, get: function () { return SubscriptionService_1.SubscriptionService; } });
|
|
19
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAeA,uEAGkC;AAFhC,gIAAA,sBAAsB,OAAA;AACtB,+IAAA,qCAAqC,OAAA;AA8BvC,qCAKiB;AAJf,8GAAA,qBAAqB,OAAA;AACrB,sGAAA,aAAa,OAAA;AACb,4GAAA,mBAAmB,OAAA;AACnB,sGAAA,aAAa,OAAA;AAEf,uCAAoD;AAA3C,kHAAA,wBAAwB,OAAA;AACjC,6CAAsE;AAA7D,gGAAA,GAAG,OAAA;AAAE,+HAAA,kCAAkC,OAAA;AAEhD,iEAA4D;AAAnD,0HAAA,mBAAmB,OAAA","sourcesContent":["export type {\n SubscriptionControllerActions,\n SubscriptionControllerState,\n SubscriptionControllerEvents,\n SubscriptionControllerGetSubscriptionsAction,\n SubscriptionControllerCancelSubscriptionAction,\n SubscriptionControllerStartShieldSubscriptionWithCardAction,\n SubscriptionControllerGetPricingAction,\n SubscriptionControllerGetCryptoApproveTransactionParamsAction,\n SubscriptionControllerStartSubscriptionWithCryptoAction,\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 StartCryptoSubscriptionRequest,\n StartCryptoSubscriptionResponse,\n StartSubscriptionRequest,\n StartSubscriptionResponse,\n GetCryptoApproveTransactionRequest,\n GetCryptoApproveTransactionResponse,\n SubscriptionCardPaymentMethod,\n SubscriptionCryptoPaymentMethod,\n SubscriptionPaymentMethod,\n RecurringInterval,\n SubscriptionStatus,\n PaymentType,\n Product,\n ProductType,\n ProductPrice,\n ProductPricing,\n TokenPaymentInfo,\n ChainPaymentInfo,\n Currency,\n PricingPaymentMethod,\n PricingResponse,\n UpdatePaymentMethodOpts,\n BillingPortalResponse,\n} from './types';\nexport {\n SUBSCRIPTION_STATUSES,\n PRODUCT_TYPES,\n RECURRING_INTERVALS,\n PAYMENT_TYPES,\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,9 @@
|
|
|
1
|
+
export type { SubscriptionControllerActions, SubscriptionControllerState, SubscriptionControllerEvents, SubscriptionControllerGetSubscriptionsAction, SubscriptionControllerCancelSubscriptionAction, SubscriptionControllerStartShieldSubscriptionWithCardAction, SubscriptionControllerGetPricingAction, SubscriptionControllerGetCryptoApproveTransactionParamsAction, SubscriptionControllerStartSubscriptionWithCryptoAction, SubscriptionControllerGetStateAction, SubscriptionControllerMessenger, SubscriptionControllerOptions, SubscriptionControllerStateChangeEvent, } from "./SubscriptionController.cjs";
|
|
2
|
+
export { SubscriptionController, getDefaultSubscriptionControllerState, } from "./SubscriptionController.cjs";
|
|
3
|
+
export type { Subscription, AuthUtils, ISubscriptionService, StartCryptoSubscriptionRequest, StartCryptoSubscriptionResponse, StartSubscriptionRequest, StartSubscriptionResponse, GetCryptoApproveTransactionRequest, GetCryptoApproveTransactionResponse, SubscriptionCardPaymentMethod, SubscriptionCryptoPaymentMethod, SubscriptionPaymentMethod, RecurringInterval, SubscriptionStatus, PaymentType, Product, ProductType, ProductPrice, ProductPricing, TokenPaymentInfo, ChainPaymentInfo, Currency, PricingPaymentMethod, PricingResponse, UpdatePaymentMethodOpts, BillingPortalResponse, } from "./types.cjs";
|
|
4
|
+
export { SUBSCRIPTION_STATUSES, PRODUCT_TYPES, RECURRING_INTERVALS, PAYMENT_TYPES, } from "./types.cjs";
|
|
5
|
+
export { SubscriptionServiceError } from "./errors.cjs";
|
|
6
|
+
export { Env, SubscriptionControllerErrorMessage } from "./constants.cjs";
|
|
7
|
+
export type { SubscriptionServiceConfig } from "./SubscriptionService.cjs";
|
|
8
|
+
export { SubscriptionService } from "./SubscriptionService.cjs";
|
|
9
|
+
//# 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,4CAA4C,EAC5C,8CAA8C,EAC9C,2DAA2D,EAC3D,sCAAsC,EACtC,6DAA6D,EAC7D,uDAAuD,EACvD,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,8BAA8B,EAC9B,+BAA+B,EAC/B,wBAAwB,EACxB,yBAAyB,EACzB,kCAAkC,EAClC,mCAAmC,EACnC,6BAA6B,EAC7B,+BAA+B,EAC/B,yBAAyB,EACzB,iBAAiB,EACjB,kBAAkB,EAClB,WAAW,EACX,OAAO,EACP,WAAW,EACX,YAAY,EACZ,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAChB,QAAQ,EACR,oBAAoB,EACpB,eAAe,EACf,uBAAuB,EACvB,qBAAqB,GACtB,oBAAgB;AACjB,OAAO,EACL,qBAAqB,EACrB,aAAa,EACb,mBAAmB,EACnB,aAAa,GACd,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,9 @@
|
|
|
1
|
+
export type { SubscriptionControllerActions, SubscriptionControllerState, SubscriptionControllerEvents, SubscriptionControllerGetSubscriptionsAction, SubscriptionControllerCancelSubscriptionAction, SubscriptionControllerStartShieldSubscriptionWithCardAction, SubscriptionControllerGetPricingAction, SubscriptionControllerGetCryptoApproveTransactionParamsAction, SubscriptionControllerStartSubscriptionWithCryptoAction, SubscriptionControllerGetStateAction, SubscriptionControllerMessenger, SubscriptionControllerOptions, SubscriptionControllerStateChangeEvent, } from "./SubscriptionController.mjs";
|
|
2
|
+
export { SubscriptionController, getDefaultSubscriptionControllerState, } from "./SubscriptionController.mjs";
|
|
3
|
+
export type { Subscription, AuthUtils, ISubscriptionService, StartCryptoSubscriptionRequest, StartCryptoSubscriptionResponse, StartSubscriptionRequest, StartSubscriptionResponse, GetCryptoApproveTransactionRequest, GetCryptoApproveTransactionResponse, SubscriptionCardPaymentMethod, SubscriptionCryptoPaymentMethod, SubscriptionPaymentMethod, RecurringInterval, SubscriptionStatus, PaymentType, Product, ProductType, ProductPrice, ProductPricing, TokenPaymentInfo, ChainPaymentInfo, Currency, PricingPaymentMethod, PricingResponse, UpdatePaymentMethodOpts, BillingPortalResponse, } from "./types.mjs";
|
|
4
|
+
export { SUBSCRIPTION_STATUSES, PRODUCT_TYPES, RECURRING_INTERVALS, PAYMENT_TYPES, } from "./types.mjs";
|
|
5
|
+
export { SubscriptionServiceError } from "./errors.mjs";
|
|
6
|
+
export { Env, SubscriptionControllerErrorMessage } from "./constants.mjs";
|
|
7
|
+
export type { SubscriptionServiceConfig } from "./SubscriptionService.mjs";
|
|
8
|
+
export { SubscriptionService } from "./SubscriptionService.mjs";
|
|
9
|
+
//# 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,4CAA4C,EAC5C,8CAA8C,EAC9C,2DAA2D,EAC3D,sCAAsC,EACtC,6DAA6D,EAC7D,uDAAuD,EACvD,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,8BAA8B,EAC9B,+BAA+B,EAC/B,wBAAwB,EACxB,yBAAyB,EACzB,kCAAkC,EAClC,mCAAmC,EACnC,6BAA6B,EAC7B,+BAA+B,EAC/B,yBAAyB,EACzB,iBAAiB,EACjB,kBAAkB,EAClB,WAAW,EACX,OAAO,EACP,WAAW,EACX,YAAY,EACZ,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAChB,QAAQ,EACR,oBAAoB,EACpB,eAAe,EACf,uBAAuB,EACvB,qBAAqB,GACtB,oBAAgB;AACjB,OAAO,EACL,qBAAqB,EACrB,aAAa,EACb,mBAAmB,EACnB,aAAa,GACd,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,6 @@
|
|
|
1
|
+
export { SubscriptionController, getDefaultSubscriptionControllerState } from "./SubscriptionController.mjs";
|
|
2
|
+
export { SUBSCRIPTION_STATUSES, PRODUCT_TYPES, RECURRING_INTERVALS, PAYMENT_TYPES } from "./types.mjs";
|
|
3
|
+
export { SubscriptionServiceError } from "./errors.mjs";
|
|
4
|
+
export { Env, SubscriptionControllerErrorMessage } from "./constants.mjs";
|
|
5
|
+
export { SubscriptionService } from "./SubscriptionService.mjs";
|
|
6
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAeA,OAAO,EACL,sBAAsB,EACtB,qCAAqC,EACtC,qCAAiC;AA6BlC,OAAO,EACL,qBAAqB,EACrB,aAAa,EACb,mBAAmB,EACnB,aAAa,EACd,oBAAgB;AACjB,OAAO,EAAE,wBAAwB,EAAE,qBAAiB;AACpD,OAAO,EAAE,GAAG,EAAE,kCAAkC,EAAE,wBAAoB;AAEtE,OAAO,EAAE,mBAAmB,EAAE,kCAA8B","sourcesContent":["export type {\n SubscriptionControllerActions,\n SubscriptionControllerState,\n SubscriptionControllerEvents,\n SubscriptionControllerGetSubscriptionsAction,\n SubscriptionControllerCancelSubscriptionAction,\n SubscriptionControllerStartShieldSubscriptionWithCardAction,\n SubscriptionControllerGetPricingAction,\n SubscriptionControllerGetCryptoApproveTransactionParamsAction,\n SubscriptionControllerStartSubscriptionWithCryptoAction,\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 StartCryptoSubscriptionRequest,\n StartCryptoSubscriptionResponse,\n StartSubscriptionRequest,\n StartSubscriptionResponse,\n GetCryptoApproveTransactionRequest,\n GetCryptoApproveTransactionResponse,\n SubscriptionCardPaymentMethod,\n SubscriptionCryptoPaymentMethod,\n SubscriptionPaymentMethod,\n RecurringInterval,\n SubscriptionStatus,\n PaymentType,\n Product,\n ProductType,\n ProductPrice,\n ProductPricing,\n TokenPaymentInfo,\n ChainPaymentInfo,\n Currency,\n PricingPaymentMethod,\n PricingResponse,\n UpdatePaymentMethodOpts,\n BillingPortalResponse,\n} from './types';\nexport {\n SUBSCRIPTION_STATUSES,\n PRODUCT_TYPES,\n RECURRING_INTERVALS,\n PAYMENT_TYPES,\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,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SUBSCRIPTION_STATUSES = exports.RECURRING_INTERVALS = exports.PAYMENT_TYPES = exports.PRODUCT_TYPES = void 0;
|
|
4
|
+
exports.PRODUCT_TYPES = {
|
|
5
|
+
SHIELD: 'shield',
|
|
6
|
+
};
|
|
7
|
+
exports.PAYMENT_TYPES = {
|
|
8
|
+
byCard: 'card',
|
|
9
|
+
byCrypto: 'crypto',
|
|
10
|
+
};
|
|
11
|
+
exports.RECURRING_INTERVALS = {
|
|
12
|
+
month: 'month',
|
|
13
|
+
year: 'year',
|
|
14
|
+
};
|
|
15
|
+
exports.SUBSCRIPTION_STATUSES = {
|
|
16
|
+
// Initial states
|
|
17
|
+
incomplete: 'incomplete',
|
|
18
|
+
incompleteExpired: 'incomplete_expired',
|
|
19
|
+
// Active states
|
|
20
|
+
provisional: 'provisional',
|
|
21
|
+
trialing: 'trialing',
|
|
22
|
+
active: 'active',
|
|
23
|
+
// Payment issues
|
|
24
|
+
pastDue: 'past_due',
|
|
25
|
+
unpaid: 'unpaid',
|
|
26
|
+
// Cancelled states
|
|
27
|
+
canceled: 'canceled',
|
|
28
|
+
// Paused states
|
|
29
|
+
paused: 'paused',
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=types.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAEa,QAAA,aAAa,GAAG;IAC3B,MAAM,EAAE,QAAQ;CACR,CAAC;AAIE,QAAA,aAAa,GAAG;IAC3B,MAAM,EAAE,MAAM;IACd,QAAQ,EAAE,QAAQ;CACV,CAAC;AAIE,QAAA,mBAAmB,GAAG;IACjC,KAAK,EAAE,OAAO;IACd,IAAI,EAAE,MAAM;CACJ,CAAC;AAKE,QAAA,qBAAqB,GAAG;IACnC,iBAAiB;IACjB,UAAU,EAAE,YAAY;IACxB,iBAAiB,EAAE,oBAAoB;IACvC,gBAAgB;IAChB,WAAW,EAAE,aAAa;IAC1B,QAAQ,EAAE,UAAU;IACpB,MAAM,EAAE,QAAQ;IAChB,iBAAiB;IACjB,OAAO,EAAE,UAAU;IACnB,MAAM,EAAE,QAAQ;IAChB,mBAAmB;IACnB,QAAQ,EAAE,UAAU;IACpB,gBAAgB;IAChB,MAAM,EAAE,QAAQ;CACR,CAAC","sourcesContent":["import type { Hex } from '@metamask/utils';\n\nexport const PRODUCT_TYPES = {\n SHIELD: 'shield',\n} as const;\n\nexport type ProductType = (typeof PRODUCT_TYPES)[keyof typeof PRODUCT_TYPES];\n\nexport const PAYMENT_TYPES = {\n byCard: 'card',\n byCrypto: 'crypto',\n} as const;\n\nexport type PaymentType = (typeof PAYMENT_TYPES)[keyof typeof PAYMENT_TYPES];\n\nexport const RECURRING_INTERVALS = {\n month: 'month',\n year: 'year',\n} as const;\n\nexport type RecurringInterval =\n (typeof RECURRING_INTERVALS)[keyof typeof RECURRING_INTERVALS];\n\nexport const SUBSCRIPTION_STATUSES = {\n // Initial states\n incomplete: 'incomplete',\n incompleteExpired: 'incomplete_expired',\n // Active states\n provisional: 'provisional',\n trialing: 'trialing',\n active: 'active',\n // Payment issues\n pastDue: 'past_due',\n unpaid: 'unpaid',\n // Cancelled states\n canceled: 'canceled',\n // Paused states\n paused: 'paused',\n} as const;\n\nexport type SubscriptionStatus =\n (typeof SUBSCRIPTION_STATUSES)[keyof typeof SUBSCRIPTION_STATUSES];\n\n/** only usd for now */\nexport type Currency = 'usd';\n\nexport type Product = {\n name: ProductType;\n currency: Currency;\n unitAmount: number;\n unitDecimals: number;\n};\n\n// state\nexport type Subscription = {\n id: string;\n products: Product[];\n currentPeriodStart: string; // ISO 8601\n currentPeriodEnd: string; // ISO 8601\n /** is subscription scheduled for cancellation */\n cancelAtPeriodEnd?: boolean;\n status: SubscriptionStatus;\n interval: RecurringInterval;\n paymentMethod: SubscriptionPaymentMethod;\n trialPeriodDays?: number;\n trialStart?: string; // ISO 8601\n trialEnd?: string; // ISO 8601\n /** is subscription ending soon */\n endDate?: string; // ISO 8601\n billingCycles?: number;\n};\n\nexport type SubscriptionCardPaymentMethod = {\n type: Extract<PaymentType, 'card'>;\n card: {\n brand: string;\n last4: string;\n };\n};\n\nexport type SubscriptionCryptoPaymentMethod = {\n type: Extract<PaymentType, 'crypto'>;\n crypto: {\n payerAddress: Hex;\n chainId: Hex;\n tokenSymbol: string;\n };\n};\n\nexport type SubscriptionPaymentMethod =\n | SubscriptionCardPaymentMethod\n | SubscriptionCryptoPaymentMethod;\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 StartCryptoSubscriptionRequest = {\n products: ProductType[];\n isTrialRequested: boolean;\n recurringInterval: RecurringInterval;\n billingCycles: number;\n chainId: Hex;\n payerAddress: Hex;\n /**\n * e.g. \"USDC\"\n */\n tokenSymbol: string;\n rawTransaction: Hex;\n};\n\nexport type StartCryptoSubscriptionResponse = {\n subscriptionId: string;\n status: SubscriptionStatus;\n};\n\nexport type AuthUtils = {\n getAccessToken: () => Promise<string>;\n};\n\nexport type ProductPrice = {\n interval: RecurringInterval;\n unitAmount: number; // amount in the smallest unit of the currency, e.g., cents\n unitDecimals: number; // number of decimals for the smallest unit of the currency\n /** only usd for now */\n currency: Currency;\n trialPeriodDays: number;\n minBillingCycles: number;\n};\n\nexport type ProductPricing = {\n name: ProductType;\n prices: ProductPrice[];\n};\n\nexport type TokenPaymentInfo = {\n symbol: string;\n address: Hex;\n decimals: number;\n /**\n * example: {\n usd: '1.0',\n },\n */\n conversionRate: {\n usd: string;\n };\n};\n\nexport type ChainPaymentInfo = {\n chainId: Hex;\n paymentAddress: Hex;\n tokens: TokenPaymentInfo[];\n};\n\nexport type PricingPaymentMethod = {\n type: PaymentType;\n chains?: ChainPaymentInfo[];\n};\n\nexport type PricingResponse = {\n products: ProductPricing[];\n paymentMethods: PricingPaymentMethod[];\n};\n\nexport type GetCryptoApproveTransactionRequest = {\n /**\n * payment chain ID\n */\n chainId: Hex;\n /**\n * Payment token address\n */\n paymentTokenAddress: Hex;\n productType: ProductType;\n interval: RecurringInterval;\n};\n\nexport type GetCryptoApproveTransactionResponse = {\n /**\n * The amount to approve\n * e.g: \"100000000\"\n */\n approveAmount: string;\n /**\n * The contract address (spender)\n */\n paymentAddress: Hex;\n /**\n * The payment token address\n */\n paymentTokenAddress: Hex;\n chainId: Hex;\n};\n\nexport type ISubscriptionService = {\n getSubscriptions(): Promise<GetSubscriptionsResponse>;\n cancelSubscription(request: {\n subscriptionId: string;\n }): Promise<Subscription>;\n unCancelSubscription(request: {\n subscriptionId: string;\n }): Promise<Subscription>;\n startSubscriptionWithCard(\n request: StartSubscriptionRequest,\n ): Promise<StartSubscriptionResponse>;\n getBillingPortalUrl(): Promise<BillingPortalResponse>;\n getPricing(): Promise<PricingResponse>;\n startSubscriptionWithCrypto(\n request: StartCryptoSubscriptionRequest,\n ): Promise<StartCryptoSubscriptionResponse>;\n updatePaymentMethodCard(\n request: UpdatePaymentMethodCardRequest,\n ): Promise<void>;\n updatePaymentMethodCrypto(\n request: UpdatePaymentMethodCryptoRequest,\n ): Promise<void>;\n};\n\nexport type UpdatePaymentMethodOpts =\n | ({\n paymentType: Extract<PaymentType, 'card'>;\n } & UpdatePaymentMethodCardRequest)\n | ({\n paymentType: Extract<PaymentType, 'crypto'>;\n } & UpdatePaymentMethodCryptoRequest);\n\nexport type UpdatePaymentMethodCardRequest = {\n /**\n * Subscription ID\n */\n subscriptionId: string;\n\n /**\n * Recurring interval\n */\n recurringInterval: RecurringInterval;\n};\n\nexport type UpdatePaymentMethodCryptoRequest = {\n subscriptionId: string;\n chainId: Hex;\n payerAddress: Hex;\n tokenSymbol: string;\n rawTransaction: Hex;\n recurringInterval: RecurringInterval;\n billingCycles: number;\n};\n\nexport type BillingPortalResponse = {\n url: string;\n};\n"]}
|
package/dist/types.d.cts
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import type { Hex } from "@metamask/utils";
|
|
2
|
+
export declare const PRODUCT_TYPES: {
|
|
3
|
+
readonly SHIELD: "shield";
|
|
4
|
+
};
|
|
5
|
+
export type ProductType = (typeof PRODUCT_TYPES)[keyof typeof PRODUCT_TYPES];
|
|
6
|
+
export declare const PAYMENT_TYPES: {
|
|
7
|
+
readonly byCard: "card";
|
|
8
|
+
readonly byCrypto: "crypto";
|
|
9
|
+
};
|
|
10
|
+
export type PaymentType = (typeof PAYMENT_TYPES)[keyof typeof PAYMENT_TYPES];
|
|
11
|
+
export declare const RECURRING_INTERVALS: {
|
|
12
|
+
readonly month: "month";
|
|
13
|
+
readonly year: "year";
|
|
14
|
+
};
|
|
15
|
+
export type RecurringInterval = (typeof RECURRING_INTERVALS)[keyof typeof RECURRING_INTERVALS];
|
|
16
|
+
export declare const SUBSCRIPTION_STATUSES: {
|
|
17
|
+
readonly incomplete: "incomplete";
|
|
18
|
+
readonly incompleteExpired: "incomplete_expired";
|
|
19
|
+
readonly provisional: "provisional";
|
|
20
|
+
readonly trialing: "trialing";
|
|
21
|
+
readonly active: "active";
|
|
22
|
+
readonly pastDue: "past_due";
|
|
23
|
+
readonly unpaid: "unpaid";
|
|
24
|
+
readonly canceled: "canceled";
|
|
25
|
+
readonly paused: "paused";
|
|
26
|
+
};
|
|
27
|
+
export type SubscriptionStatus = (typeof SUBSCRIPTION_STATUSES)[keyof typeof SUBSCRIPTION_STATUSES];
|
|
28
|
+
/** only usd for now */
|
|
29
|
+
export type Currency = 'usd';
|
|
30
|
+
export type Product = {
|
|
31
|
+
name: ProductType;
|
|
32
|
+
currency: Currency;
|
|
33
|
+
unitAmount: number;
|
|
34
|
+
unitDecimals: number;
|
|
35
|
+
};
|
|
36
|
+
export type Subscription = {
|
|
37
|
+
id: string;
|
|
38
|
+
products: Product[];
|
|
39
|
+
currentPeriodStart: string;
|
|
40
|
+
currentPeriodEnd: string;
|
|
41
|
+
/** is subscription scheduled for cancellation */
|
|
42
|
+
cancelAtPeriodEnd?: boolean;
|
|
43
|
+
status: SubscriptionStatus;
|
|
44
|
+
interval: RecurringInterval;
|
|
45
|
+
paymentMethod: SubscriptionPaymentMethod;
|
|
46
|
+
trialPeriodDays?: number;
|
|
47
|
+
trialStart?: string;
|
|
48
|
+
trialEnd?: string;
|
|
49
|
+
/** is subscription ending soon */
|
|
50
|
+
endDate?: string;
|
|
51
|
+
billingCycles?: number;
|
|
52
|
+
};
|
|
53
|
+
export type SubscriptionCardPaymentMethod = {
|
|
54
|
+
type: Extract<PaymentType, 'card'>;
|
|
55
|
+
card: {
|
|
56
|
+
brand: string;
|
|
57
|
+
last4: string;
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
export type SubscriptionCryptoPaymentMethod = {
|
|
61
|
+
type: Extract<PaymentType, 'crypto'>;
|
|
62
|
+
crypto: {
|
|
63
|
+
payerAddress: Hex;
|
|
64
|
+
chainId: Hex;
|
|
65
|
+
tokenSymbol: string;
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
export type SubscriptionPaymentMethod = SubscriptionCardPaymentMethod | SubscriptionCryptoPaymentMethod;
|
|
69
|
+
export type GetSubscriptionsResponse = {
|
|
70
|
+
customerId?: string;
|
|
71
|
+
subscriptions: Subscription[];
|
|
72
|
+
trialedProducts: ProductType[];
|
|
73
|
+
};
|
|
74
|
+
export type StartSubscriptionRequest = {
|
|
75
|
+
products: ProductType[];
|
|
76
|
+
isTrialRequested: boolean;
|
|
77
|
+
recurringInterval: RecurringInterval;
|
|
78
|
+
};
|
|
79
|
+
export type StartSubscriptionResponse = {
|
|
80
|
+
checkoutSessionUrl: string;
|
|
81
|
+
};
|
|
82
|
+
export type StartCryptoSubscriptionRequest = {
|
|
83
|
+
products: ProductType[];
|
|
84
|
+
isTrialRequested: boolean;
|
|
85
|
+
recurringInterval: RecurringInterval;
|
|
86
|
+
billingCycles: number;
|
|
87
|
+
chainId: Hex;
|
|
88
|
+
payerAddress: Hex;
|
|
89
|
+
/**
|
|
90
|
+
* e.g. "USDC"
|
|
91
|
+
*/
|
|
92
|
+
tokenSymbol: string;
|
|
93
|
+
rawTransaction: Hex;
|
|
94
|
+
};
|
|
95
|
+
export type StartCryptoSubscriptionResponse = {
|
|
96
|
+
subscriptionId: string;
|
|
97
|
+
status: SubscriptionStatus;
|
|
98
|
+
};
|
|
99
|
+
export type AuthUtils = {
|
|
100
|
+
getAccessToken: () => Promise<string>;
|
|
101
|
+
};
|
|
102
|
+
export type ProductPrice = {
|
|
103
|
+
interval: RecurringInterval;
|
|
104
|
+
unitAmount: number;
|
|
105
|
+
unitDecimals: number;
|
|
106
|
+
/** only usd for now */
|
|
107
|
+
currency: Currency;
|
|
108
|
+
trialPeriodDays: number;
|
|
109
|
+
minBillingCycles: number;
|
|
110
|
+
};
|
|
111
|
+
export type ProductPricing = {
|
|
112
|
+
name: ProductType;
|
|
113
|
+
prices: ProductPrice[];
|
|
114
|
+
};
|
|
115
|
+
export type TokenPaymentInfo = {
|
|
116
|
+
symbol: string;
|
|
117
|
+
address: Hex;
|
|
118
|
+
decimals: number;
|
|
119
|
+
/**
|
|
120
|
+
* example: {
|
|
121
|
+
usd: '1.0',
|
|
122
|
+
},
|
|
123
|
+
*/
|
|
124
|
+
conversionRate: {
|
|
125
|
+
usd: string;
|
|
126
|
+
};
|
|
127
|
+
};
|
|
128
|
+
export type ChainPaymentInfo = {
|
|
129
|
+
chainId: Hex;
|
|
130
|
+
paymentAddress: Hex;
|
|
131
|
+
tokens: TokenPaymentInfo[];
|
|
132
|
+
};
|
|
133
|
+
export type PricingPaymentMethod = {
|
|
134
|
+
type: PaymentType;
|
|
135
|
+
chains?: ChainPaymentInfo[];
|
|
136
|
+
};
|
|
137
|
+
export type PricingResponse = {
|
|
138
|
+
products: ProductPricing[];
|
|
139
|
+
paymentMethods: PricingPaymentMethod[];
|
|
140
|
+
};
|
|
141
|
+
export type GetCryptoApproveTransactionRequest = {
|
|
142
|
+
/**
|
|
143
|
+
* payment chain ID
|
|
144
|
+
*/
|
|
145
|
+
chainId: Hex;
|
|
146
|
+
/**
|
|
147
|
+
* Payment token address
|
|
148
|
+
*/
|
|
149
|
+
paymentTokenAddress: Hex;
|
|
150
|
+
productType: ProductType;
|
|
151
|
+
interval: RecurringInterval;
|
|
152
|
+
};
|
|
153
|
+
export type GetCryptoApproveTransactionResponse = {
|
|
154
|
+
/**
|
|
155
|
+
* The amount to approve
|
|
156
|
+
* e.g: "100000000"
|
|
157
|
+
*/
|
|
158
|
+
approveAmount: string;
|
|
159
|
+
/**
|
|
160
|
+
* The contract address (spender)
|
|
161
|
+
*/
|
|
162
|
+
paymentAddress: Hex;
|
|
163
|
+
/**
|
|
164
|
+
* The payment token address
|
|
165
|
+
*/
|
|
166
|
+
paymentTokenAddress: Hex;
|
|
167
|
+
chainId: Hex;
|
|
168
|
+
};
|
|
169
|
+
export type ISubscriptionService = {
|
|
170
|
+
getSubscriptions(): Promise<GetSubscriptionsResponse>;
|
|
171
|
+
cancelSubscription(request: {
|
|
172
|
+
subscriptionId: string;
|
|
173
|
+
}): Promise<Subscription>;
|
|
174
|
+
unCancelSubscription(request: {
|
|
175
|
+
subscriptionId: string;
|
|
176
|
+
}): Promise<Subscription>;
|
|
177
|
+
startSubscriptionWithCard(request: StartSubscriptionRequest): Promise<StartSubscriptionResponse>;
|
|
178
|
+
getBillingPortalUrl(): Promise<BillingPortalResponse>;
|
|
179
|
+
getPricing(): Promise<PricingResponse>;
|
|
180
|
+
startSubscriptionWithCrypto(request: StartCryptoSubscriptionRequest): Promise<StartCryptoSubscriptionResponse>;
|
|
181
|
+
updatePaymentMethodCard(request: UpdatePaymentMethodCardRequest): Promise<void>;
|
|
182
|
+
updatePaymentMethodCrypto(request: UpdatePaymentMethodCryptoRequest): Promise<void>;
|
|
183
|
+
};
|
|
184
|
+
export type UpdatePaymentMethodOpts = ({
|
|
185
|
+
paymentType: Extract<PaymentType, 'card'>;
|
|
186
|
+
} & UpdatePaymentMethodCardRequest) | ({
|
|
187
|
+
paymentType: Extract<PaymentType, 'crypto'>;
|
|
188
|
+
} & UpdatePaymentMethodCryptoRequest);
|
|
189
|
+
export type UpdatePaymentMethodCardRequest = {
|
|
190
|
+
/**
|
|
191
|
+
* Subscription ID
|
|
192
|
+
*/
|
|
193
|
+
subscriptionId: string;
|
|
194
|
+
/**
|
|
195
|
+
* Recurring interval
|
|
196
|
+
*/
|
|
197
|
+
recurringInterval: RecurringInterval;
|
|
198
|
+
};
|
|
199
|
+
export type UpdatePaymentMethodCryptoRequest = {
|
|
200
|
+
subscriptionId: string;
|
|
201
|
+
chainId: Hex;
|
|
202
|
+
payerAddress: Hex;
|
|
203
|
+
tokenSymbol: string;
|
|
204
|
+
rawTransaction: Hex;
|
|
205
|
+
recurringInterval: RecurringInterval;
|
|
206
|
+
billingCycles: number;
|
|
207
|
+
};
|
|
208
|
+
export type BillingPortalResponse = {
|
|
209
|
+
url: string;
|
|
210
|
+
};
|
|
211
|
+
//# sourceMappingURL=types.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAE3C,eAAO,MAAM,aAAa;;CAEhB,CAAC;AAEX,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,OAAO,aAAa,CAAC,CAAC;AAE7E,eAAO,MAAM,aAAa;;;CAGhB,CAAC;AAEX,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,OAAO,aAAa,CAAC,CAAC;AAE7E,eAAO,MAAM,mBAAmB;;;CAGtB,CAAC;AAEX,MAAM,MAAM,iBAAiB,GAC3B,CAAC,OAAO,mBAAmB,CAAC,CAAC,MAAM,OAAO,mBAAmB,CAAC,CAAC;AAEjE,eAAO,MAAM,qBAAqB;;;;;;;;;;CAexB,CAAC;AAEX,MAAM,MAAM,kBAAk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