@metamask-previews/subscription-controller 8.0.1-preview-3866c0ff1 → 8.0.1-preview-e3275932a
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 +0 -1
- package/dist/SubscriptionController-method-action-types.cjs +7 -0
- package/dist/SubscriptionController-method-action-types.cjs.map +1 -0
- package/dist/{SubscriptionController-method-action-types.d.ts → SubscriptionController-method-action-types.d.cts} +2 -2
- package/dist/SubscriptionController-method-action-types.d.cts.map +1 -0
- package/dist/SubscriptionController-method-action-types.d.mts +250 -0
- package/dist/SubscriptionController-method-action-types.d.mts.map +1 -0
- package/dist/{SubscriptionController-method-action-types.js → SubscriptionController-method-action-types.mjs} +1 -1
- package/dist/SubscriptionController-method-action-types.mjs.map +1 -0
- package/dist/SubscriptionController.cjs +744 -0
- package/dist/SubscriptionController.cjs.map +1 -0
- package/dist/{SubscriptionController.d.ts → SubscriptionController.d.cts} +18 -18
- package/dist/SubscriptionController.d.cts.map +1 -0
- package/dist/SubscriptionController.d.mts +258 -0
- package/dist/SubscriptionController.d.mts.map +1 -0
- package/dist/{SubscriptionController.js → SubscriptionController.mjs} +180 -262
- package/dist/SubscriptionController.mjs.map +1 -0
- package/dist/SubscriptionService-method-action-types.cjs +7 -0
- package/dist/SubscriptionService-method-action-types.cjs.map +1 -0
- package/dist/{SubscriptionService-method-action-types.d.ts → SubscriptionService-method-action-types.d.cts} +2 -2
- package/dist/SubscriptionService-method-action-types.d.cts.map +1 -0
- package/dist/SubscriptionService-method-action-types.d.mts +155 -0
- package/dist/SubscriptionService-method-action-types.d.mts.map +1 -0
- package/dist/{SubscriptionService-method-action-types.js → SubscriptionService-method-action-types.mjs} +1 -1
- package/dist/SubscriptionService-method-action-types.mjs.map +1 -0
- package/dist/SubscriptionService-structs.cjs +158 -0
- package/dist/SubscriptionService-structs.cjs.map +1 -0
- package/dist/{SubscriptionService-structs.d.ts → SubscriptionService-structs.d.cts} +134 -134
- package/dist/SubscriptionService-structs.d.cts.map +1 -0
- package/dist/SubscriptionService-structs.d.mts +721 -0
- package/dist/SubscriptionService-structs.d.mts.map +1 -0
- package/dist/{SubscriptionService-structs.js → SubscriptionService-structs.mjs} +4 -4
- package/dist/SubscriptionService-structs.mjs.map +1 -0
- package/dist/SubscriptionService.cjs +477 -0
- package/dist/SubscriptionService.cjs.map +1 -0
- package/dist/{SubscriptionService.d.ts → SubscriptionService.d.cts} +10 -10
- package/dist/SubscriptionService.d.cts.map +1 -0
- package/dist/SubscriptionService.d.mts +149 -0
- package/dist/SubscriptionService.d.mts.map +1 -0
- package/dist/{SubscriptionService.js → SubscriptionService.mjs} +141 -139
- package/dist/SubscriptionService.mjs.map +1 -0
- package/dist/constants.cjs +73 -0
- package/dist/constants.cjs.map +1 -0
- package/dist/{constants.d.ts → constants.d.cts} +1 -1
- package/dist/constants.d.cts.map +1 -0
- package/dist/constants.d.mts +49 -0
- package/dist/constants.d.mts.map +1 -0
- package/dist/{constants.js → constants.mjs} +3 -3
- package/dist/constants.mjs.map +1 -0
- package/dist/errors.cjs +72 -0
- package/dist/errors.cjs.map +1 -0
- package/dist/{errors.d.ts → errors.d.cts} +2 -2
- package/dist/errors.d.cts.map +1 -0
- package/dist/errors.d.mts +34 -0
- package/dist/errors.d.mts.map +1 -0
- package/dist/{errors.js → errors.mjs} +1 -5
- package/dist/errors.mjs.map +1 -0
- package/dist/index.cjs +29 -0
- package/dist/index.cjs.map +1 -0
- package/dist/{index.d.ts → index.d.cts} +11 -11
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +11 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/{index.js → index.mjs} +6 -6
- package/dist/index.mjs.map +1 -0
- package/dist/logger.cjs +8 -0
- package/dist/logger.cjs.map +1 -0
- package/dist/logger.d.cts +5 -0
- package/dist/logger.d.cts.map +1 -0
- package/dist/logger.d.mts +5 -0
- package/dist/logger.d.mts.map +1 -0
- package/dist/logger.mjs +5 -0
- package/dist/logger.mjs.map +1 -0
- package/dist/types.cjs +90 -0
- package/dist/types.cjs.map +1 -0
- package/dist/{types.d.ts → types.d.cts} +41 -41
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.mts +574 -0
- package/dist/types.d.mts.map +1 -0
- package/dist/{types.js → types.mjs} +1 -1
- package/dist/types.mjs.map +1 -0
- package/package.json +16 -12
- package/dist/SubscriptionController-method-action-types.d.ts.map +0 -1
- package/dist/SubscriptionController-method-action-types.js.map +0 -1
- package/dist/SubscriptionController.d.ts.map +0 -1
- package/dist/SubscriptionController.js.map +0 -1
- package/dist/SubscriptionService-method-action-types.d.ts.map +0 -1
- package/dist/SubscriptionService-method-action-types.js.map +0 -1
- package/dist/SubscriptionService-structs.d.ts.map +0 -1
- package/dist/SubscriptionService-structs.js.map +0 -1
- package/dist/SubscriptionService.d.ts.map +0 -1
- package/dist/SubscriptionService.js.map +0 -1
- package/dist/constants.d.ts.map +0 -1
- package/dist/constants.js.map +0 -1
- package/dist/errors.d.ts.map +0 -1
- package/dist/errors.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/logger.d.ts +0 -4
- package/dist/logger.d.ts.map +0 -1
- package/dist/logger.js +0 -5
- package/dist/logger.js.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SubscriptionService.d.cts","sourceRoot":"","sources":["../src/SubscriptionService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,4BAA4B,EAC5B,oCAAoC,EACpC,kCAAkC,EACnC,oCAAoC;AACrC,OAAO,EAAE,eAAe,EAAE,oCAAoC;AAC9D,OAAO,KAAK,EAAE,0BAA0B,EAAE,mCAAmC;AAE7E,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EAAE,wBAAwB,EAAE,0CAA0C;AAGlF,OAAO,KAAK,EAAE,iBAAiB,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;;OAKG;IACG,kBAAkB,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;IAcrE;;;;;;;;OAQG;IACG,wBAAwB,CAC5B,OAAO,EAAE,+BAA+B,GACvC,OAAO,CAAC,IAAI,CAAC;IAehB;;;;;;OAMG;IACG,WAAW,CACf,OAAO,EAAE,kBAAkB,GAC1B,OAAO,CAAC,8BAA8B,CAAC;IAgB1C;;;;OAIG;IACG,UAAU,IAAI,OAAO,CAAC,eAAe,CAAC;IAc5C;;;;OAIG;IACG,mBAAmB,IAAI,OAAO,CAAC,qBAAqB,CAAC;CAgL5D"}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import type { DataServiceCacheUpdatedEvent, DataServiceGranularCacheUpdatedEvent, DataServiceInvalidateQueriesAction } from "@metamask/base-data-service";
|
|
2
|
+
import { BaseDataService } from "@metamask/base-data-service";
|
|
3
|
+
import type { CreateServicePolicyOptions } from "@metamask/controller-utils";
|
|
4
|
+
import type { Messenger } from "@metamask/messenger";
|
|
5
|
+
import type { AuthenticationController } from "@metamask/profile-sync-controller";
|
|
6
|
+
import type { QueryClientConfig } from "@tanstack/query-core";
|
|
7
|
+
import { Env } from "./constants.mjs";
|
|
8
|
+
import type { SubscriptionServiceMethodActions } from "./SubscriptionService-method-action-types.mjs";
|
|
9
|
+
import type { AssignCohortRequest, BillingPortalResponse, CancelSubscriptionRequest, GetSubscriptionsEligibilitiesRequest, GetSubscriptionsResponse, LinkRewardsRequest, PricingResponse, StartCryptoSubscriptionRequest, StartCryptoSubscriptionResponse, StartSubscriptionRequest, StartSubscriptionResponse, SubmitSponsorshipIntentsRequest, SubmitUserEventRequest, Subscription, SubscriptionApiGeneralResponse, SubscriptionEligibility, UpdatePaymentMethodCardRequest, UpdatePaymentMethodCardResponse, UpdatePaymentMethodCryptoRequest } from "./types.mjs";
|
|
10
|
+
export declare const serviceName = "SubscriptionService";
|
|
11
|
+
export declare const SUBSCRIPTION_URL: (env: Env, path: string) => string;
|
|
12
|
+
export type SubscriptionServiceInvalidateQueriesAction = DataServiceInvalidateQueriesAction<typeof serviceName>;
|
|
13
|
+
export type SubscriptionServiceActions = SubscriptionServiceMethodActions | SubscriptionServiceInvalidateQueriesAction;
|
|
14
|
+
type AllowedActions = AuthenticationController.AuthenticationControllerGetBearerTokenAction | AuthenticationController.AuthenticationControllerGetSessionProfileAction;
|
|
15
|
+
type AllowedEvents = never;
|
|
16
|
+
export type SubscriptionServiceCacheUpdatedEvent = DataServiceCacheUpdatedEvent<typeof serviceName>;
|
|
17
|
+
export type SubscriptionServiceGranularCacheUpdatedEvent = DataServiceGranularCacheUpdatedEvent<typeof serviceName>;
|
|
18
|
+
export type SubscriptionServiceEvents = SubscriptionServiceCacheUpdatedEvent | SubscriptionServiceGranularCacheUpdatedEvent;
|
|
19
|
+
export type SubscriptionServiceMessenger = Messenger<typeof serviceName, SubscriptionServiceActions | AllowedActions, SubscriptionServiceEvents | AllowedEvents>;
|
|
20
|
+
export type SubscriptionServiceOptions = {
|
|
21
|
+
messenger: SubscriptionServiceMessenger;
|
|
22
|
+
/**
|
|
23
|
+
* The `fetch` function to use for requests. Defaults to the global `fetch`.
|
|
24
|
+
*/
|
|
25
|
+
fetchFunction?: typeof fetch;
|
|
26
|
+
env?: Env;
|
|
27
|
+
captureException?: (error: Error) => void;
|
|
28
|
+
queryClientConfig?: QueryClientConfig;
|
|
29
|
+
policyOptions?: CreateServicePolicyOptions;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Data service for the Subscription API.
|
|
33
|
+
*
|
|
34
|
+
* All requests are authenticated via JWT Bearer tokens obtained from the
|
|
35
|
+
* `AuthenticationController:getBearerToken` messenger action. Cached queries
|
|
36
|
+
* are scoped by `profileId` from
|
|
37
|
+
* `AuthenticationController:getSessionProfile`.
|
|
38
|
+
*/
|
|
39
|
+
export declare class SubscriptionService extends BaseDataService<typeof serviceName, SubscriptionServiceMessenger> {
|
|
40
|
+
#private;
|
|
41
|
+
constructor({ messenger, fetchFunction, env, captureException, queryClientConfig, policyOptions, }: SubscriptionServiceOptions);
|
|
42
|
+
/**
|
|
43
|
+
* Fetches the user's subscriptions.
|
|
44
|
+
*
|
|
45
|
+
* @returns The subscriptions response.
|
|
46
|
+
*/
|
|
47
|
+
getSubscriptions(): Promise<GetSubscriptionsResponse>;
|
|
48
|
+
/**
|
|
49
|
+
* Cancels a subscription.
|
|
50
|
+
*
|
|
51
|
+
* @param params - The cancel subscription request.
|
|
52
|
+
* @returns The updated subscription.
|
|
53
|
+
*/
|
|
54
|
+
cancelSubscription(params: CancelSubscriptionRequest): Promise<Subscription>;
|
|
55
|
+
/**
|
|
56
|
+
* Reverses a pending subscription cancellation.
|
|
57
|
+
*
|
|
58
|
+
* @param params - The uncancel subscription request.
|
|
59
|
+
* @param params.subscriptionId - The subscription ID to uncancel.
|
|
60
|
+
* @returns The updated subscription.
|
|
61
|
+
*/
|
|
62
|
+
unCancelSubscription(params: {
|
|
63
|
+
subscriptionId: string;
|
|
64
|
+
}): Promise<Subscription>;
|
|
65
|
+
/**
|
|
66
|
+
* Starts a card-paid subscription checkout session for the requested products
|
|
67
|
+
* (e.g. Shield or Money Account Plus).
|
|
68
|
+
*
|
|
69
|
+
* @param request - The start subscription request.
|
|
70
|
+
* @returns The checkout session response.
|
|
71
|
+
*/
|
|
72
|
+
startSubscriptionWithCard(request: StartSubscriptionRequest): Promise<StartSubscriptionResponse>;
|
|
73
|
+
/**
|
|
74
|
+
* Starts a subscription with a crypto payment method.
|
|
75
|
+
*
|
|
76
|
+
* @param request - The start crypto subscription request.
|
|
77
|
+
* @returns The created subscription response.
|
|
78
|
+
* @throws If `products` is empty.
|
|
79
|
+
* @throws If the request does not use exactly one of `rawTransaction`
|
|
80
|
+
* (ERC-20 approval) or `delegationHash` (delegation).
|
|
81
|
+
*/
|
|
82
|
+
startSubscriptionWithCrypto(request: StartCryptoSubscriptionRequest): Promise<StartCryptoSubscriptionResponse>;
|
|
83
|
+
/**
|
|
84
|
+
* Updates a subscription's card payment method.
|
|
85
|
+
*
|
|
86
|
+
* @param request - The update payment method request.
|
|
87
|
+
* @returns The redirect URL response.
|
|
88
|
+
*/
|
|
89
|
+
updatePaymentMethodCard(request: UpdatePaymentMethodCardRequest): Promise<UpdatePaymentMethodCardResponse>;
|
|
90
|
+
/**
|
|
91
|
+
* Updates a subscription's crypto payment method.
|
|
92
|
+
*
|
|
93
|
+
* @param request - The update payment method request.
|
|
94
|
+
*/
|
|
95
|
+
updatePaymentMethodCrypto(request: UpdatePaymentMethodCryptoRequest): Promise<void>;
|
|
96
|
+
/**
|
|
97
|
+
* Get the eligibility for a shield subscription.
|
|
98
|
+
*
|
|
99
|
+
* @param request - Optional request object containing user balance category to check cohort eligibility
|
|
100
|
+
* @returns The eligibility for a shield subscription
|
|
101
|
+
*/
|
|
102
|
+
getSubscriptionsEligibilities(request?: GetSubscriptionsEligibilitiesRequest): Promise<SubscriptionEligibility[]>;
|
|
103
|
+
/**
|
|
104
|
+
* Submit a user event. (e.g. shield modal viewed)
|
|
105
|
+
*
|
|
106
|
+
* @param request - Request object containing the event to submit.
|
|
107
|
+
* @example { event: SubscriptionUserEvent.ShieldEntryModalViewed, cohort: 'post_tx' }
|
|
108
|
+
*/
|
|
109
|
+
submitUserEvent(request: SubmitUserEventRequest): Promise<void>;
|
|
110
|
+
/**
|
|
111
|
+
* Assign user to a cohort.
|
|
112
|
+
*
|
|
113
|
+
* @param request - Request object containing the cohort to assign the user to.
|
|
114
|
+
* @example { cohort: 'post_tx' }
|
|
115
|
+
*/
|
|
116
|
+
assignUserToCohort(request: AssignCohortRequest): Promise<void>;
|
|
117
|
+
/**
|
|
118
|
+
* Submit sponsorship intents to the Subscription Service backend.
|
|
119
|
+
*
|
|
120
|
+
* This is intended to be used together with the crypto subscription flow.
|
|
121
|
+
* When the user has enabled the smart transaction feature, we will sponsor the gas fees for the subscription approval transaction.
|
|
122
|
+
*
|
|
123
|
+
* @param request - Request object containing the address and products.
|
|
124
|
+
* @example { address: '0x1234567890123456789012345678901234567890', products: [ProductType.Shield] }
|
|
125
|
+
*/
|
|
126
|
+
submitSponsorshipIntents(request: SubmitSponsorshipIntentsRequest): Promise<void>;
|
|
127
|
+
/**
|
|
128
|
+
* Link rewards to a subscription.
|
|
129
|
+
*
|
|
130
|
+
* @param request - Request object containing the reward account ID.
|
|
131
|
+
* @example { rewardAccountId: 'eip155:1:0x1234567890123456789012345678901234567890' }
|
|
132
|
+
* @returns The response from the API.
|
|
133
|
+
*/
|
|
134
|
+
linkRewards(request: LinkRewardsRequest): Promise<SubscriptionApiGeneralResponse>;
|
|
135
|
+
/**
|
|
136
|
+
* Fetches subscription pricing information.
|
|
137
|
+
*
|
|
138
|
+
* @returns The pricing response.
|
|
139
|
+
*/
|
|
140
|
+
getPricing(): Promise<PricingResponse>;
|
|
141
|
+
/**
|
|
142
|
+
* Fetches the billing portal URL.
|
|
143
|
+
*
|
|
144
|
+
* @returns The billing portal response.
|
|
145
|
+
*/
|
|
146
|
+
getBillingPortalUrl(): Promise<BillingPortalResponse>;
|
|
147
|
+
}
|
|
148
|
+
export {};
|
|
149
|
+
//# sourceMappingURL=SubscriptionService.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SubscriptionService.d.mts","sourceRoot":"","sources":["../src/SubscriptionService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,4BAA4B,EAC5B,oCAAoC,EACpC,kCAAkC,EACnC,oCAAoC;AACrC,OAAO,EAAE,eAAe,EAAE,oCAAoC;AAC9D,OAAO,KAAK,EAAE,0BAA0B,EAAE,mCAAmC;AAE7E,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EAAE,wBAAwB,EAAE,0CAA0C;AAGlF,OAAO,KAAK,EAAE,iBAAiB,EAAE,6BAA6B;AAE9D,OAAO,EACL,GAAG,EAIJ,wBAAuB;AAOxB,OAAO,KAAK,EAAE,gCAAgC,EAAE,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OAQG;IACG,wBAAwB,CAC5B,OAAO,EAAE,+BAA+B,GACvC,OAAO,CAAC,IAAI,CAAC;IAehB;;;;;;OAMG;IACG,WAAW,CACf,OAAO,EAAE,kBAAkB,GAC1B,OAAO,CAAC,8BAA8B,CAAC;IAgB1C;;;;OAIG;IACG,UAAU,IAAI,OAAO,CAAC,eAAe,CAAC;IAc5C;;;;OAIG;IACG,mBAAmB,IAAI,OAAO,CAAC,qBAAqB,CAAC;CAgL5D"}
|
|
@@ -1,11 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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_captureException, _SubscriptionService_fetchJson, _SubscriptionService_assertValidCryptoAuthCombo, _SubscriptionService_getAuthenticatedContext, _SubscriptionService_headersForToken, _SubscriptionService_getSubscriptionApiUrl;
|
|
13
|
+
import { BaseDataService } from "@metamask/base-data-service";
|
|
14
|
+
import { handleWhen, HttpError } from "@metamask/controller-utils";
|
|
15
|
+
import { create } from "@metamask/superstruct";
|
|
16
|
+
import { Env, getEnvUrls, SubscriptionControllerErrorMessage, SubscriptionServiceErrorMessage } from "./constants.mjs";
|
|
17
|
+
import { createSentryError, getSubscriptionErrorFromResponse, SubscriptionServiceError } from "./errors.mjs";
|
|
18
|
+
import { createModuleLogger, projectLogger } from "./logger.mjs";
|
|
19
|
+
import { BillingPortalResponseStruct, GetSubscriptionsResponseStruct, PricingResponseStruct, StartCryptoSubscriptionResponseStruct, StartSubscriptionResponseStruct, SubscriptionApiGeneralResponseStruct, SubscriptionEligibilityArrayStruct, SubscriptionStruct, UpdatePaymentMethodCardResponseStruct } from "./SubscriptionService-structs.mjs";
|
|
20
|
+
import { CRYPTO_AUTH_METHODS } from "./types.mjs";
|
|
9
21
|
export const serviceName = 'SubscriptionService';
|
|
10
22
|
export const SUBSCRIPTION_URL = (env, path) => `${getEnvUrls(env).subscriptionApiUrl}/v1/${path}`;
|
|
11
23
|
const MESSENGER_EXPOSED_METHODS = [
|
|
@@ -46,9 +58,6 @@ const DEFAULT_POLICY_OPTIONS = {
|
|
|
46
58
|
* `AuthenticationController:getSessionProfile`.
|
|
47
59
|
*/
|
|
48
60
|
export class SubscriptionService extends BaseDataService {
|
|
49
|
-
#env;
|
|
50
|
-
#fetch;
|
|
51
|
-
#captureException;
|
|
52
61
|
constructor({ messenger, fetchFunction = globalThis.fetch, env = Env.PRD, captureException, queryClientConfig = {}, policyOptions = {}, }) {
|
|
53
62
|
super({
|
|
54
63
|
name: serviceName,
|
|
@@ -56,9 +65,13 @@ export class SubscriptionService extends BaseDataService {
|
|
|
56
65
|
queryClientConfig,
|
|
57
66
|
policyOptions: { ...DEFAULT_POLICY_OPTIONS, ...policyOptions },
|
|
58
67
|
});
|
|
59
|
-
this
|
|
60
|
-
this
|
|
61
|
-
this
|
|
68
|
+
_SubscriptionService_instances.add(this);
|
|
69
|
+
_SubscriptionService_env.set(this, void 0);
|
|
70
|
+
_SubscriptionService_fetch.set(this, void 0);
|
|
71
|
+
_SubscriptionService_captureException.set(this, void 0);
|
|
72
|
+
__classPrivateFieldSet(this, _SubscriptionService_env, env, "f");
|
|
73
|
+
__classPrivateFieldSet(this, _SubscriptionService_fetch, fetchFunction, "f");
|
|
74
|
+
__classPrivateFieldSet(this, _SubscriptionService_captureException, captureException, "f");
|
|
62
75
|
this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
|
|
63
76
|
}
|
|
64
77
|
/**
|
|
@@ -67,8 +80,8 @@ export class SubscriptionService extends BaseDataService {
|
|
|
67
80
|
* @returns The subscriptions response.
|
|
68
81
|
*/
|
|
69
82
|
async getSubscriptions() {
|
|
70
|
-
const { profileKey, bearerToken } = await this
|
|
71
|
-
const jsonResponse = await this
|
|
83
|
+
const { profileKey, bearerToken } = await __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_getAuthenticatedContext).call(this);
|
|
84
|
+
const jsonResponse = await __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_fetchJson).call(this, {
|
|
72
85
|
profileKey,
|
|
73
86
|
bearerToken,
|
|
74
87
|
methodName: 'getSubscriptions',
|
|
@@ -85,9 +98,9 @@ export class SubscriptionService extends BaseDataService {
|
|
|
85
98
|
* @returns The updated subscription.
|
|
86
99
|
*/
|
|
87
100
|
async cancelSubscription(params) {
|
|
88
|
-
const { profileKey, bearerToken } = await this
|
|
101
|
+
const { profileKey, bearerToken } = await __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_getAuthenticatedContext).call(this);
|
|
89
102
|
const path = `subscriptions/${params.subscriptionId}/cancel`;
|
|
90
|
-
const jsonResponse = await this
|
|
103
|
+
const jsonResponse = await __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_fetchJson).call(this, {
|
|
91
104
|
profileKey,
|
|
92
105
|
bearerToken,
|
|
93
106
|
methodName: 'cancelSubscription',
|
|
@@ -109,9 +122,9 @@ export class SubscriptionService extends BaseDataService {
|
|
|
109
122
|
* @returns The updated subscription.
|
|
110
123
|
*/
|
|
111
124
|
async unCancelSubscription(params) {
|
|
112
|
-
const { profileKey, bearerToken } = await this
|
|
125
|
+
const { profileKey, bearerToken } = await __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_getAuthenticatedContext).call(this);
|
|
113
126
|
const path = `subscriptions/${params.subscriptionId}/uncancel`;
|
|
114
|
-
const jsonResponse = await this
|
|
127
|
+
const jsonResponse = await __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_fetchJson).call(this, {
|
|
115
128
|
profileKey,
|
|
116
129
|
bearerToken,
|
|
117
130
|
methodName: 'unCancelSubscription',
|
|
@@ -134,8 +147,8 @@ export class SubscriptionService extends BaseDataService {
|
|
|
134
147
|
if (request.products.length === 0) {
|
|
135
148
|
throw new SubscriptionServiceError(SubscriptionControllerErrorMessage.SubscriptionProductsEmpty);
|
|
136
149
|
}
|
|
137
|
-
const { profileKey, bearerToken } = await this
|
|
138
|
-
const jsonResponse = await this
|
|
150
|
+
const { profileKey, bearerToken } = await __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_getAuthenticatedContext).call(this);
|
|
151
|
+
const jsonResponse = await __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_fetchJson).call(this, {
|
|
139
152
|
profileKey,
|
|
140
153
|
bearerToken,
|
|
141
154
|
methodName: 'startSubscriptionWithCard',
|
|
@@ -160,9 +173,9 @@ export class SubscriptionService extends BaseDataService {
|
|
|
160
173
|
if (request.products.length === 0) {
|
|
161
174
|
throw new SubscriptionServiceError(SubscriptionControllerErrorMessage.SubscriptionProductsEmpty);
|
|
162
175
|
}
|
|
163
|
-
this
|
|
164
|
-
const { profileKey, bearerToken } = await this
|
|
165
|
-
const jsonResponse = await this
|
|
176
|
+
__classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_assertValidCryptoAuthCombo).call(this, request);
|
|
177
|
+
const { profileKey, bearerToken } = await __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_getAuthenticatedContext).call(this);
|
|
178
|
+
const jsonResponse = await __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_fetchJson).call(this, {
|
|
166
179
|
profileKey,
|
|
167
180
|
bearerToken,
|
|
168
181
|
methodName: 'startSubscriptionWithCrypto',
|
|
@@ -181,9 +194,9 @@ export class SubscriptionService extends BaseDataService {
|
|
|
181
194
|
* @returns The redirect URL response.
|
|
182
195
|
*/
|
|
183
196
|
async updatePaymentMethodCard(request) {
|
|
184
|
-
const { profileKey, bearerToken } = await this
|
|
197
|
+
const { profileKey, bearerToken } = await __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_getAuthenticatedContext).call(this);
|
|
185
198
|
const path = `subscriptions/${request.subscriptionId}/payment-method/card`;
|
|
186
|
-
const jsonResponse = await this
|
|
199
|
+
const jsonResponse = await __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_fetchJson).call(this, {
|
|
187
200
|
profileKey,
|
|
188
201
|
bearerToken,
|
|
189
202
|
methodName: 'updatePaymentMethodCard',
|
|
@@ -204,9 +217,9 @@ export class SubscriptionService extends BaseDataService {
|
|
|
204
217
|
* @param request - The update payment method request.
|
|
205
218
|
*/
|
|
206
219
|
async updatePaymentMethodCrypto(request) {
|
|
207
|
-
const { profileKey, bearerToken } = await this
|
|
220
|
+
const { profileKey, bearerToken } = await __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_getAuthenticatedContext).call(this);
|
|
208
221
|
const path = `subscriptions/${request.subscriptionId}/payment-method/crypto`;
|
|
209
|
-
await this
|
|
222
|
+
await __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_fetchJson).call(this, {
|
|
210
223
|
profileKey,
|
|
211
224
|
bearerToken,
|
|
212
225
|
methodName: 'updatePaymentMethodCrypto',
|
|
@@ -227,12 +240,12 @@ export class SubscriptionService extends BaseDataService {
|
|
|
227
240
|
* @returns The eligibility for a shield subscription
|
|
228
241
|
*/
|
|
229
242
|
async getSubscriptionsEligibilities(request) {
|
|
230
|
-
const { profileKey, bearerToken } = await this
|
|
243
|
+
const { profileKey, bearerToken } = await __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_getAuthenticatedContext).call(this);
|
|
231
244
|
let queryParams;
|
|
232
245
|
if (request?.balanceCategory !== undefined) {
|
|
233
246
|
queryParams = { balanceCategory: request.balanceCategory };
|
|
234
247
|
}
|
|
235
|
-
const jsonResponse = await this
|
|
248
|
+
const jsonResponse = await __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_fetchJson).call(this, {
|
|
236
249
|
profileKey,
|
|
237
250
|
bearerToken,
|
|
238
251
|
methodName: 'getSubscriptionsEligibilities',
|
|
@@ -258,8 +271,8 @@ export class SubscriptionService extends BaseDataService {
|
|
|
258
271
|
* @example { event: SubscriptionUserEvent.ShieldEntryModalViewed, cohort: 'post_tx' }
|
|
259
272
|
*/
|
|
260
273
|
async submitUserEvent(request) {
|
|
261
|
-
const { profileKey, bearerToken } = await this
|
|
262
|
-
await this
|
|
274
|
+
const { profileKey, bearerToken } = await __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_getAuthenticatedContext).call(this);
|
|
275
|
+
await __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_fetchJson).call(this, {
|
|
263
276
|
profileKey,
|
|
264
277
|
bearerToken,
|
|
265
278
|
methodName: 'submitUserEvent',
|
|
@@ -277,8 +290,8 @@ export class SubscriptionService extends BaseDataService {
|
|
|
277
290
|
* @example { cohort: 'post_tx' }
|
|
278
291
|
*/
|
|
279
292
|
async assignUserToCohort(request) {
|
|
280
|
-
const { profileKey, bearerToken } = await this
|
|
281
|
-
await this
|
|
293
|
+
const { profileKey, bearerToken } = await __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_getAuthenticatedContext).call(this);
|
|
294
|
+
await __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_fetchJson).call(this, {
|
|
282
295
|
profileKey,
|
|
283
296
|
bearerToken,
|
|
284
297
|
methodName: 'assignUserToCohort',
|
|
@@ -299,8 +312,8 @@ export class SubscriptionService extends BaseDataService {
|
|
|
299
312
|
* @example { address: '0x1234567890123456789012345678901234567890', products: [ProductType.Shield] }
|
|
300
313
|
*/
|
|
301
314
|
async submitSponsorshipIntents(request) {
|
|
302
|
-
const { profileKey, bearerToken } = await this
|
|
303
|
-
await this
|
|
315
|
+
const { profileKey, bearerToken } = await __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_getAuthenticatedContext).call(this);
|
|
316
|
+
await __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_fetchJson).call(this, {
|
|
304
317
|
profileKey,
|
|
305
318
|
bearerToken,
|
|
306
319
|
methodName: 'submitSponsorshipIntents',
|
|
@@ -319,8 +332,8 @@ export class SubscriptionService extends BaseDataService {
|
|
|
319
332
|
* @returns The response from the API.
|
|
320
333
|
*/
|
|
321
334
|
async linkRewards(request) {
|
|
322
|
-
const { profileKey, bearerToken } = await this
|
|
323
|
-
const jsonResponse = await this
|
|
335
|
+
const { profileKey, bearerToken } = await __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_getAuthenticatedContext).call(this);
|
|
336
|
+
const jsonResponse = await __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_fetchJson).call(this, {
|
|
324
337
|
profileKey,
|
|
325
338
|
bearerToken,
|
|
326
339
|
methodName: 'linkRewards',
|
|
@@ -338,8 +351,8 @@ export class SubscriptionService extends BaseDataService {
|
|
|
338
351
|
* @returns The pricing response.
|
|
339
352
|
*/
|
|
340
353
|
async getPricing() {
|
|
341
|
-
const { profileKey, bearerToken } = await this
|
|
342
|
-
const jsonResponse = await this
|
|
354
|
+
const { profileKey, bearerToken } = await __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_getAuthenticatedContext).call(this);
|
|
355
|
+
const jsonResponse = await __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_fetchJson).call(this, {
|
|
343
356
|
profileKey,
|
|
344
357
|
bearerToken,
|
|
345
358
|
methodName: 'getPricing',
|
|
@@ -355,8 +368,8 @@ export class SubscriptionService extends BaseDataService {
|
|
|
355
368
|
* @returns The billing portal response.
|
|
356
369
|
*/
|
|
357
370
|
async getBillingPortalUrl() {
|
|
358
|
-
const { profileKey, bearerToken } = await this
|
|
359
|
-
const jsonResponse = await this
|
|
371
|
+
const { profileKey, bearerToken } = await __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_getAuthenticatedContext).call(this);
|
|
372
|
+
const jsonResponse = await __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_fetchJson).call(this, {
|
|
360
373
|
profileKey,
|
|
361
374
|
bearerToken,
|
|
362
375
|
methodName: 'getBillingPortalUrl',
|
|
@@ -366,105 +379,94 @@ export class SubscriptionService extends BaseDataService {
|
|
|
366
379
|
});
|
|
367
380
|
return create(jsonResponse, BillingPortalResponseStruct);
|
|
368
381
|
}
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
}
|
|
376
|
-
try {
|
|
377
|
-
return await this.fetchQuery({
|
|
378
|
-
queryKey: [
|
|
379
|
-
`${this.name}:${methodName}`,
|
|
380
|
-
profileKey,
|
|
381
|
-
requestParams,
|
|
382
|
-
],
|
|
383
|
-
staleTime: 0,
|
|
384
|
-
gcTime: 0,
|
|
385
|
-
queryFn: async () => {
|
|
386
|
-
const response = await this.#fetch(url.toString(), {
|
|
387
|
-
method,
|
|
388
|
-
headers: {
|
|
389
|
-
'Content-Type': 'application/json',
|
|
390
|
-
...this.#headersForToken(bearerToken),
|
|
391
|
-
},
|
|
392
|
-
body: body ? JSON.stringify(body) : undefined,
|
|
393
|
-
});
|
|
394
|
-
if (!response.ok) {
|
|
395
|
-
const apiError = await getSubscriptionErrorFromResponse(response);
|
|
396
|
-
throw new HttpError(response.status, apiError.message);
|
|
397
|
-
}
|
|
398
|
-
return response.json();
|
|
399
|
-
},
|
|
400
|
-
});
|
|
401
|
-
}
|
|
402
|
-
catch (error) {
|
|
403
|
-
log(errorMessage, error);
|
|
404
|
-
const errorMessageWithUrl = `${errorMessage} (url: ${url.toString()})`;
|
|
405
|
-
const errorToCapture = error instanceof Error ? error : new Error(errorMessage);
|
|
406
|
-
this.#captureException?.(createSentryError(errorMessageWithUrl, errorToCapture));
|
|
407
|
-
if (error instanceof SubscriptionServiceError) {
|
|
408
|
-
throw error;
|
|
409
|
-
}
|
|
410
|
-
throw new SubscriptionServiceError(`Failed to make request. ${errorMessageWithUrl}`, {
|
|
411
|
-
cause: errorToCapture,
|
|
412
|
-
});
|
|
413
|
-
}
|
|
382
|
+
}
|
|
383
|
+
_SubscriptionService_env = new WeakMap(), _SubscriptionService_fetch = new WeakMap(), _SubscriptionService_captureException = new WeakMap(), _SubscriptionService_instances = new WeakSet(), _SubscriptionService_fetchJson = async function _SubscriptionService_fetchJson({ profileKey, bearerToken, methodName, requestParams, path, method = 'GET', body, queryParams, errorMessage, }) {
|
|
384
|
+
const url = __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_getSubscriptionApiUrl).call(this, path);
|
|
385
|
+
if (queryParams) {
|
|
386
|
+
Object.entries(queryParams).forEach(([key, value]) => {
|
|
387
|
+
url.searchParams.append(key, value);
|
|
388
|
+
});
|
|
414
389
|
}
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
390
|
+
try {
|
|
391
|
+
return await this.fetchQuery({
|
|
392
|
+
queryKey: [
|
|
393
|
+
`${this.name}:${methodName}`,
|
|
394
|
+
profileKey,
|
|
395
|
+
requestParams,
|
|
396
|
+
],
|
|
397
|
+
staleTime: 0,
|
|
398
|
+
gcTime: 0,
|
|
399
|
+
queryFn: async () => {
|
|
400
|
+
const response = await __classPrivateFieldGet(this, _SubscriptionService_fetch, "f").call(this, url.toString(), {
|
|
401
|
+
method,
|
|
402
|
+
headers: {
|
|
403
|
+
'Content-Type': 'application/json',
|
|
404
|
+
...__classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_headersForToken).call(this, bearerToken),
|
|
405
|
+
},
|
|
406
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
407
|
+
});
|
|
408
|
+
if (!response.ok) {
|
|
409
|
+
const apiError = await getSubscriptionErrorFromResponse(response);
|
|
410
|
+
throw new HttpError(response.status, apiError.message);
|
|
411
|
+
}
|
|
412
|
+
return response.json();
|
|
413
|
+
},
|
|
414
|
+
});
|
|
435
415
|
}
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
}
|
|
444
|
-
catch (error) {
|
|
445
|
-
const errorMessage = error instanceof Error
|
|
446
|
-
? error.message
|
|
447
|
-
: 'Unknown error when getting authorization header';
|
|
448
|
-
this.#captureException?.(createSentryError(`Failed to get authorization header. ${errorMessage}`, error instanceof Error ? error : new Error(errorMessage)));
|
|
449
|
-
throw new SubscriptionServiceError(`Failed to get authorization header. ${errorMessage}`, {
|
|
450
|
-
cause: error instanceof Error ? error : new Error(errorMessage),
|
|
451
|
-
});
|
|
416
|
+
catch (error) {
|
|
417
|
+
log(errorMessage, error);
|
|
418
|
+
const errorMessageWithUrl = `${errorMessage} (url: ${url.toString()})`;
|
|
419
|
+
const errorToCapture = error instanceof Error ? error : new Error(errorMessage);
|
|
420
|
+
__classPrivateFieldGet(this, _SubscriptionService_captureException, "f")?.call(this, createSentryError(errorMessageWithUrl, errorToCapture));
|
|
421
|
+
if (error instanceof SubscriptionServiceError) {
|
|
422
|
+
throw error;
|
|
452
423
|
}
|
|
424
|
+
throw new SubscriptionServiceError(`Failed to make request. ${errorMessageWithUrl}`, {
|
|
425
|
+
cause: errorToCapture,
|
|
426
|
+
});
|
|
453
427
|
}
|
|
454
|
-
|
|
455
|
-
|
|
428
|
+
}, _SubscriptionService_assertValidCryptoAuthCombo = function _SubscriptionService_assertValidCryptoAuthCombo(request) {
|
|
429
|
+
const method = request.cryptoAuthMethod ?? CRYPTO_AUTH_METHODS.ERC20_APPROVAL;
|
|
430
|
+
const hasRawTransaction = Boolean(request.rawTransaction);
|
|
431
|
+
const hasDelegationHash = Boolean(request.delegationHash);
|
|
432
|
+
const isValidErc20Approval = method === CRYPTO_AUTH_METHODS.ERC20_APPROVAL &&
|
|
433
|
+
hasRawTransaction &&
|
|
434
|
+
!hasDelegationHash;
|
|
435
|
+
const isValidDelegation = method === CRYPTO_AUTH_METHODS.DELEGATION &&
|
|
436
|
+
hasDelegationHash &&
|
|
437
|
+
!hasRawTransaction;
|
|
438
|
+
if (!isValidErc20Approval && !isValidDelegation) {
|
|
439
|
+
throw new SubscriptionServiceError(SubscriptionServiceErrorMessage.InvalidCryptoAuthCombo);
|
|
456
440
|
}
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
: 'Unknown error when getting subscription API URL';
|
|
465
|
-
this.#captureException?.(createSentryError(`Failed to get subscription API URL. ${errorMessage}`, error instanceof Error ? error : new Error(errorMessage)));
|
|
466
|
-
throw error;
|
|
467
|
-
}
|
|
441
|
+
}, _SubscriptionService_getAuthenticatedContext = async function _SubscriptionService_getAuthenticatedContext() {
|
|
442
|
+
try {
|
|
443
|
+
const [bearerToken, sessionProfile] = await Promise.all([
|
|
444
|
+
this.messenger.call('AuthenticationController:getBearerToken'),
|
|
445
|
+
this.messenger.call('AuthenticationController:getSessionProfile'),
|
|
446
|
+
]);
|
|
447
|
+
return { profileKey: sessionProfile.profileId, bearerToken };
|
|
468
448
|
}
|
|
469
|
-
|
|
470
|
-
|
|
449
|
+
catch (error) {
|
|
450
|
+
const errorMessage = error instanceof Error
|
|
451
|
+
? error.message
|
|
452
|
+
: 'Unknown error when getting authorization header';
|
|
453
|
+
__classPrivateFieldGet(this, _SubscriptionService_captureException, "f")?.call(this, createSentryError(`Failed to get authorization header. ${errorMessage}`, error instanceof Error ? error : new Error(errorMessage)));
|
|
454
|
+
throw new SubscriptionServiceError(`Failed to get authorization header. ${errorMessage}`, {
|
|
455
|
+
cause: error instanceof Error ? error : new Error(errorMessage),
|
|
456
|
+
});
|
|
457
|
+
}
|
|
458
|
+
}, _SubscriptionService_headersForToken = function _SubscriptionService_headersForToken(bearerToken) {
|
|
459
|
+
return { Authorization: `Bearer ${bearerToken}` };
|
|
460
|
+
}, _SubscriptionService_getSubscriptionApiUrl = function _SubscriptionService_getSubscriptionApiUrl(path) {
|
|
461
|
+
try {
|
|
462
|
+
return new URL(SUBSCRIPTION_URL(__classPrivateFieldGet(this, _SubscriptionService_env, "f"), path));
|
|
463
|
+
}
|
|
464
|
+
catch (error) {
|
|
465
|
+
const errorMessage = error instanceof Error
|
|
466
|
+
? error.message
|
|
467
|
+
: 'Unknown error when getting subscription API URL';
|
|
468
|
+
__classPrivateFieldGet(this, _SubscriptionService_captureException, "f")?.call(this, createSentryError(`Failed to get subscription API URL. ${errorMessage}`, error instanceof Error ? error : new Error(errorMessage)));
|
|
469
|
+
throw error;
|
|
470
|
+
}
|
|
471
|
+
};
|
|
472
|
+
//# sourceMappingURL=SubscriptionService.mjs.map
|