@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
package/dist/types.d.mts
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.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.mts","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,mB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AG,CAAC;IACb,YAAY,EAAE,GAAG,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,GAAG,CAAC;IACpB,iBAAiB,EAAE,iBAAiB,CAAC;IACrC,aAAa,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,GAAG,EAAE,MAAM,CAAC;CACb,CAAC"}
|
package/dist/types.mjs
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export const PRODUCT_TYPES = {
|
|
2
|
+
SHIELD: 'shield',
|
|
3
|
+
};
|
|
4
|
+
export const PAYMENT_TYPES = {
|
|
5
|
+
byCard: 'card',
|
|
6
|
+
byCrypto: 'crypto',
|
|
7
|
+
};
|
|
8
|
+
export const RECURRING_INTERVALS = {
|
|
9
|
+
month: 'month',
|
|
10
|
+
year: 'year',
|
|
11
|
+
};
|
|
12
|
+
export const SUBSCRIPTION_STATUSES = {
|
|
13
|
+
// Initial states
|
|
14
|
+
incomplete: 'incomplete',
|
|
15
|
+
incompleteExpired: 'incomplete_expired',
|
|
16
|
+
// Active states
|
|
17
|
+
provisional: 'provisional',
|
|
18
|
+
trialing: 'trialing',
|
|
19
|
+
active: 'active',
|
|
20
|
+
// Payment issues
|
|
21
|
+
pastDue: 'past_due',
|
|
22
|
+
unpaid: 'unpaid',
|
|
23
|
+
// Cancelled states
|
|
24
|
+
canceled: 'canceled',
|
|
25
|
+
// Paused states
|
|
26
|
+
paused: 'paused',
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=types.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,MAAM,EAAE,QAAQ;CACR,CAAC;AAIX,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,MAAM,EAAE,MAAM;IACd,QAAQ,EAAE,QAAQ;CACV,CAAC;AAIX,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,KAAK,EAAE,OAAO;IACd,IAAI,EAAE,MAAM;CACJ,CAAC;AAKX,MAAM,CAAC,MAAM,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/package.json
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@metamask/subscription-controller",
|
|
3
|
+
"version": "0.1.0",
|
|
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.3.0",
|
|
51
|
+
"@metamask/controller-utils": "^11.14.0",
|
|
52
|
+
"@metamask/utils": "^11.8.0"
|
|
53
|
+
},
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"@metamask/auto-changelog": "^3.4.4",
|
|
56
|
+
"@metamask/profile-sync-controller": "^25.0.0",
|
|
57
|
+
"@types/jest": "^27.4.1",
|
|
58
|
+
"deepmerge": "^4.2.2",
|
|
59
|
+
"jest": "^27.5.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
|
+
"peerDependencies": {
|
|
66
|
+
"@metamask/profile-sync-controller": "^25.0.0"
|
|
67
|
+
},
|
|
68
|
+
"engines": {
|
|
69
|
+
"node": "^18.18 || >=20"
|
|
70
|
+
},
|
|
71
|
+
"publishConfig": {
|
|
72
|
+
"access": "public",
|
|
73
|
+
"registry": "https://registry.npmjs.org/"
|
|
74
|
+
}
|
|
75
|
+
}
|