@metamask-previews/subscription-controller 5.4.2-preview-6dfa4aeba → 5.4.2-preview-5ff83bad8

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 CHANGED
@@ -7,9 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ### Added
11
+
12
+ - **BREAKING**: Added two new params, `captureException` and `fetchFunction` to `SubscriptionService` constructor args. ([#7835](https://github.com/MetaMask/core/pull/7835))
13
+ - `fetchFunction` is to use the client provided `Fetch` API.
14
+ - `captureException` is to capture the error thrown and report to Sentry.
15
+
10
16
  ### Changed
11
17
 
12
- - Bump `@metamask/transaction-controller` from `^62.12.0` to `^62.13.0` ([#7802](https://github.com/MetaMask/core/pull/7802))
18
+ - Updated `SubscriptionServiceError` to include more information for Sentry reporting. ([#7835](https://github.com/MetaMask/core/pull/7835))
19
+ - Bump `@metamask/profile-sync-controller` from `^27.0.0` to `^27.1.0` ([#7849](https://github.com/MetaMask/core/pull/7849))
20
+ - Bump `@metamask/transaction-controller` from `^62.12.0` to `^62.14.0` ([#7802](https://github.com/MetaMask/core/pull/7802), [#7832](https://github.com/MetaMask/core/pull/7832))
13
21
 
14
22
  ## [5.4.2]
15
23
 
@@ -10,10 +10,9 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
10
10
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
11
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
12
  };
13
- var _SubscriptionService_instances, _SubscriptionService_env, _SubscriptionService_makeRequest, _SubscriptionService_getAuthorizationHeader;
13
+ var _SubscriptionService_instances, _SubscriptionService_env, _SubscriptionService_fetch, _SubscriptionService_captureException, _SubscriptionService_makeRequest, _SubscriptionService_getAuthorizationHeader, _SubscriptionService_getSubscriptionApiUrl;
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.SubscriptionService = exports.SUBSCRIPTION_URL = void 0;
16
- const controller_utils_1 = require("@metamask/controller-utils");
17
16
  const constants_1 = require("./constants.cjs");
18
17
  const errors_1 = require("./errors.cjs");
19
18
  const SUBSCRIPTION_URL = (env, path) => `${(0, constants_1.getEnvUrls)(env).subscriptionApiUrl}/v1/${path}`;
@@ -22,46 +21,83 @@ class SubscriptionService {
22
21
  constructor(config) {
23
22
  _SubscriptionService_instances.add(this);
24
23
  _SubscriptionService_env.set(this, void 0);
24
+ _SubscriptionService_fetch.set(this, void 0);
25
+ _SubscriptionService_captureException.set(this, void 0);
25
26
  __classPrivateFieldSet(this, _SubscriptionService_env, config.env, "f");
26
27
  this.authUtils = config.auth;
28
+ __classPrivateFieldSet(this, _SubscriptionService_fetch, config.fetchFunction, "f");
29
+ __classPrivateFieldSet(this, _SubscriptionService_captureException, config.captureException, "f");
27
30
  }
28
31
  async getSubscriptions() {
29
32
  const path = 'subscriptions';
30
- return await __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_makeRequest).call(this, path);
33
+ return await __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_makeRequest).call(this, {
34
+ path,
35
+ errorMessage: constants_1.SubscriptionServiceErrorMessage.FailedToGetSubscriptions,
36
+ });
31
37
  }
32
38
  async cancelSubscription(params) {
33
39
  const path = `subscriptions/${params.subscriptionId}/cancel`;
34
- return await __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_makeRequest).call(this, path, 'POST', {
35
- cancelAtPeriodEnd: params.cancelAtPeriodEnd,
40
+ return await __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_makeRequest).call(this, {
41
+ path,
42
+ method: 'POST',
43
+ body: {
44
+ cancelAtPeriodEnd: params.cancelAtPeriodEnd,
45
+ },
46
+ errorMessage: constants_1.SubscriptionServiceErrorMessage.FailedToCancelSubscription,
36
47
  });
37
48
  }
38
49
  async unCancelSubscription(params) {
39
50
  const path = `subscriptions/${params.subscriptionId}/uncancel`;
40
- return await __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_makeRequest).call(this, path, 'POST', {});
51
+ return await __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_makeRequest).call(this, {
52
+ path,
53
+ method: 'POST',
54
+ body: {},
55
+ errorMessage: constants_1.SubscriptionServiceErrorMessage.FailedToUncancelSubscription,
56
+ });
41
57
  }
42
58
  async startSubscriptionWithCard(request) {
43
59
  if (request.products.length === 0) {
44
60
  throw new errors_1.SubscriptionServiceError(constants_1.SubscriptionControllerErrorMessage.SubscriptionProductsEmpty);
45
61
  }
46
62
  const path = 'subscriptions/card';
47
- return await __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_makeRequest).call(this, path, 'POST', request);
63
+ return await __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_makeRequest).call(this, {
64
+ path,
65
+ method: 'POST',
66
+ body: request,
67
+ errorMessage: constants_1.SubscriptionServiceErrorMessage.FailedToStartSubscriptionWithCard,
68
+ });
48
69
  }
49
70
  async startSubscriptionWithCrypto(request) {
50
71
  const path = 'subscriptions/crypto';
51
- return await __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_makeRequest).call(this, path, 'POST', request);
72
+ return await __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_makeRequest).call(this, {
73
+ path,
74
+ method: 'POST',
75
+ body: request,
76
+ errorMessage: constants_1.SubscriptionServiceErrorMessage.FailedToStartSubscriptionWithCrypto,
77
+ });
52
78
  }
53
79
  async updatePaymentMethodCard(request) {
54
80
  const path = `subscriptions/${request.subscriptionId}/payment-method/card`;
55
- return await __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_makeRequest).call(this, path, 'PATCH', {
56
- ...request,
57
- subscriptionId: undefined,
81
+ return await __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_makeRequest).call(this, {
82
+ path,
83
+ method: 'PATCH',
84
+ body: {
85
+ ...request,
86
+ subscriptionId: undefined,
87
+ },
88
+ errorMessage: constants_1.SubscriptionServiceErrorMessage.FailedToUpdatePaymentMethodCard,
58
89
  });
59
90
  }
60
91
  async updatePaymentMethodCrypto(request) {
61
92
  const path = `subscriptions/${request.subscriptionId}/payment-method/crypto`;
62
- await __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_makeRequest).call(this, path, 'PATCH', {
63
- ...request,
64
- subscriptionId: undefined,
93
+ await __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_makeRequest).call(this, {
94
+ path,
95
+ method: 'PATCH',
96
+ body: {
97
+ ...request,
98
+ subscriptionId: undefined,
99
+ },
100
+ errorMessage: constants_1.SubscriptionServiceErrorMessage.FailedToUpdatePaymentMethodCrypto,
65
101
  });
66
102
  }
67
103
  /**
@@ -76,7 +112,11 @@ class SubscriptionService {
76
112
  if (request?.balanceCategory !== undefined) {
77
113
  query = { balanceCategory: request.balanceCategory };
78
114
  }
79
- const results = await __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_makeRequest).call(this, path, 'GET', undefined, query);
115
+ const results = await __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_makeRequest).call(this, {
116
+ path,
117
+ queryParams: query,
118
+ errorMessage: constants_1.SubscriptionServiceErrorMessage.FailedToGetSubscriptionsEligibilities,
119
+ });
80
120
  return results.map((result) => ({
81
121
  ...result,
82
122
  canSubscribe: result.canSubscribe || false,
@@ -94,7 +134,12 @@ class SubscriptionService {
94
134
  */
95
135
  async submitUserEvent(request) {
96
136
  const path = 'user-events';
97
- await __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_makeRequest).call(this, path, 'POST', request);
137
+ await __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_makeRequest).call(this, {
138
+ path,
139
+ method: 'POST',
140
+ body: request,
141
+ errorMessage: constants_1.SubscriptionServiceErrorMessage.FailedToSubmitUserEvent,
142
+ });
98
143
  }
99
144
  /**
100
145
  * Assign user to a cohort.
@@ -104,7 +149,12 @@ class SubscriptionService {
104
149
  */
105
150
  async assignUserToCohort(request) {
106
151
  const path = 'cohorts/assign';
107
- await __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_makeRequest).call(this, path, 'POST', request);
152
+ await __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_makeRequest).call(this, {
153
+ path,
154
+ method: 'POST',
155
+ body: request,
156
+ errorMessage: constants_1.SubscriptionServiceErrorMessage.FailedToAssignUserToCohort,
157
+ });
108
158
  }
109
159
  /**
110
160
  * Submit sponsorship intents to the Subscription Service backend.
@@ -117,7 +167,12 @@ class SubscriptionService {
117
167
  */
118
168
  async submitSponsorshipIntents(request) {
119
169
  const path = 'transaction-sponsorship/intents';
120
- await __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_makeRequest).call(this, path, 'POST', request);
170
+ await __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_makeRequest).call(this, {
171
+ path,
172
+ method: 'POST',
173
+ body: request,
174
+ errorMessage: constants_1.SubscriptionServiceErrorMessage.FailedToSubmitSponsorshipIntents,
175
+ });
121
176
  }
122
177
  /**
123
178
  * Link rewards to a subscription.
@@ -128,28 +183,51 @@ class SubscriptionService {
128
183
  */
129
184
  async linkRewards(request) {
130
185
  const path = 'rewards/link';
131
- return await __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_makeRequest).call(this, path, 'POST', request);
186
+ return await __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_makeRequest).call(this, {
187
+ path,
188
+ method: 'POST',
189
+ body: request,
190
+ errorMessage: constants_1.SubscriptionServiceErrorMessage.FailedToLinkRewards,
191
+ });
132
192
  }
133
193
  async getPricing() {
134
194
  const path = 'pricing';
135
- return await __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_makeRequest).call(this, path);
195
+ return await __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_makeRequest).call(this, {
196
+ path,
197
+ errorMessage: constants_1.SubscriptionServiceErrorMessage.FailedToGetPricing,
198
+ });
136
199
  }
137
200
  async getBillingPortalUrl() {
138
201
  const path = 'billing-portal';
139
- return await __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_makeRequest).call(this, path);
202
+ return await __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_makeRequest).call(this, {
203
+ path,
204
+ errorMessage: constants_1.SubscriptionServiceErrorMessage.FailedToGetBillingPortalUrl,
205
+ });
140
206
  }
141
207
  }
142
208
  exports.SubscriptionService = SubscriptionService;
143
- _SubscriptionService_env = new WeakMap(), _SubscriptionService_instances = new WeakSet(), _SubscriptionService_makeRequest = async function _SubscriptionService_makeRequest(path, method = 'GET', body, queryParams) {
209
+ _SubscriptionService_env = new WeakMap(), _SubscriptionService_fetch = new WeakMap(), _SubscriptionService_captureException = new WeakMap(), _SubscriptionService_instances = new WeakSet(), _SubscriptionService_makeRequest =
210
+ /**
211
+ * Makes a request to the Subscription Service backend.
212
+ *
213
+ * @param params - The request object containing the path, method, body, query parameters, and error message.
214
+ * @param params.path - The path of the request.
215
+ * @param params.method - The method of the request.
216
+ * @param params.body - The body of the request.
217
+ * @param params.queryParams - The query parameters of the request.
218
+ * @param params.errorMessage - The error message to throw if the request fails.
219
+ * @returns The result of the request.
220
+ */
221
+ async function _SubscriptionService_makeRequest({ path, method = 'GET', body, queryParams, errorMessage, }) {
222
+ const url = __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_getSubscriptionApiUrl).call(this, path);
223
+ const headers = await __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_getAuthorizationHeader).call(this);
144
224
  try {
145
- const headers = await __classPrivateFieldGet(this, _SubscriptionService_instances, "m", _SubscriptionService_getAuthorizationHeader).call(this);
146
- const url = new URL((0, exports.SUBSCRIPTION_URL)(__classPrivateFieldGet(this, _SubscriptionService_env, "f"), path));
147
225
  if (queryParams) {
148
226
  Object.entries(queryParams).forEach(([key, value]) => {
149
227
  url.searchParams.append(key, value);
150
228
  });
151
229
  }
152
- const response = await (0, controller_utils_1.handleFetch)(url.toString(), {
230
+ const response = await __classPrivateFieldGet(this, _SubscriptionService_fetch, "f").call(this, url.toString(), {
153
231
  method,
154
232
  headers: {
155
233
  'Content-Type': 'application/json',
@@ -157,16 +235,49 @@ _SubscriptionService_env = new WeakMap(), _SubscriptionService_instances = new W
157
235
  },
158
236
  body: body ? JSON.stringify(body) : undefined,
159
237
  });
160
- return response;
238
+ if (!response.ok) {
239
+ const error = await (0, errors_1.getErrorFromResponse)(response);
240
+ throw error;
241
+ }
242
+ const data = await response.json();
243
+ return data;
161
244
  }
162
245
  catch (error) {
163
- const errorMessage = error instanceof Error ? error.message : JSON.stringify(error);
164
- throw new errors_1.SubscriptionServiceError(`failed to make request. ${errorMessage}`);
246
+ console.error(errorMessage, error);
247
+ const errorMessageWithUrl = `${errorMessage} (url: ${url.toString()})`;
248
+ const errorToCapture = error instanceof Error ? error : new Error(errorMessage);
249
+ __classPrivateFieldGet(this, _SubscriptionService_captureException, "f")?.call(this, (0, errors_1.createSentryError)(errorMessageWithUrl, errorToCapture));
250
+ throw new errors_1.SubscriptionServiceError(`Failed to make request. ${errorMessageWithUrl}`, {
251
+ cause: errorToCapture,
252
+ });
165
253
  }
166
254
  }, _SubscriptionService_getAuthorizationHeader =
167
255
  // eslint-disable-next-line @typescript-eslint/naming-convention
168
256
  async function _SubscriptionService_getAuthorizationHeader() {
169
- const accessToken = await this.authUtils.getAccessToken();
170
- return { Authorization: `Bearer ${accessToken}` };
257
+ try {
258
+ const accessToken = await this.authUtils.getAccessToken();
259
+ return { Authorization: `Bearer ${accessToken}` };
260
+ }
261
+ catch (error) {
262
+ const errorMessage = error instanceof Error
263
+ ? error.message
264
+ : 'Unknown error when getting authorization header';
265
+ __classPrivateFieldGet(this, _SubscriptionService_captureException, "f")?.call(this, (0, errors_1.createSentryError)(`Failed to get authorization header. ${errorMessage}`, error instanceof Error ? error : new Error(errorMessage)));
266
+ throw new errors_1.SubscriptionServiceError(`Failed to get authorization header. ${errorMessage}`, {
267
+ cause: error instanceof Error ? error : new Error(errorMessage),
268
+ });
269
+ }
270
+ }, _SubscriptionService_getSubscriptionApiUrl = function _SubscriptionService_getSubscriptionApiUrl(path) {
271
+ try {
272
+ const url = new URL((0, exports.SUBSCRIPTION_URL)(__classPrivateFieldGet(this, _SubscriptionService_env, "f"), path));
273
+ return url;
274
+ }
275
+ catch (error) {
276
+ const errorMessage = error instanceof Error
277
+ ? error.message
278
+ : 'Unknown error when getting subscription API URL';
279
+ __classPrivateFieldGet(this, _SubscriptionService_captureException, "f")?.call(this, (0, errors_1.createSentryError)(`Failed to get subscription API URL. ${errorMessage}`, error instanceof Error ? error : new Error(errorMessage)));
280
+ throw error;
281
+ }
171
282
  };
172
283
  //# sourceMappingURL=SubscriptionService.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"SubscriptionService.cjs","sourceRoot":"","sources":["../src/SubscriptionService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,iEAAyD;AAEzD,+CAA6E;AAE7E,yCAAoD;AA8B7C,MAAM,gBAAgB,GAAG,CAAC,GAAQ,EAAE,IAAY,EAAU,EAAE,CACjE,GAAG,IAAA,sBAAU,EAAC,GAAG,CAAC,CAAC,kBAAkB,OAAO,IAAI,EAAE,CAAC;AADxC,QAAA,gBAAgB,oBACwB;AAErD,MAAa,mBAAmB;IAK9B,YAAY,MAAiC;;QAJpC,2CAAU;QAKjB,uBAAA,IAAI,4BAAQ,MAAM,CAAC,GAAG,MAAA,CAAC;QACvB,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC;IAC/B,CAAC;IAED,KAAK,CAAC,gB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GAAG,GAAG,IAAI,GAAG,CAAC,IAAA,wBAAgB,EAAC,uBAAA,IAAI,gCAAK,EAAE,IAAI,CAAC,CAAC,CAAC;QAEvD,IAAI,WAAW,EAAE,CAAC;YAChB,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;gBACnD,GAAG,CAAC,YAAY,CAAC,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;YACtC,CAAC,CAAC,CAAC;QACL,CAAC;QAED,MAAM,QAAQ,GAAG,MAAM,IAAA,8BAAW,EAAC,GAAG,CAAC,QAAQ,EAAE,EAAE;YACjD,MAAM;YACN,OAAO,EAAE;gBACP,cAAc,EAAE,kBAAkB;gBAClC,GAAG,OAAO;aACX;YACD,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS;SAC9C,CAAC,CAAC;QAEH,OAAO,QAAQ,CAAC;IAClB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,YAAY,GAChB,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QAEjE,MAAM,IAAI,iCAAwB,CAChC,2BAA2B,YAAY,EAAE,CAC1C,CAAC;IACJ,CAAC;AACH,CAAC;AAED,gEAAgE;AAChE,KAAK;IACH,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,cAAc,EAAE,CAAC;IAC1D,OAAO,EAAE,aAAa,EAAE,UAAU,WAAW,EAAE,EAAE,CAAC;AACpD,CAAC","sourcesContent":["import { handleFetch } from '@metamask/controller-utils';\n\nimport { getEnvUrls, SubscriptionControllerErrorMessage } from './constants';\nimport type { Env } from './constants';\nimport { SubscriptionServiceError } from './errors';\nimport type {\n AssignCohortRequest,\n AuthUtils,\n BillingPortalResponse,\n GetSubscriptionsEligibilitiesRequest,\n GetSubscriptionsResponse,\n ISubscriptionService,\n PricingResponse,\n SubscriptionEligibility,\n StartCryptoSubscriptionRequest,\n StartCryptoSubscriptionResponse,\n StartSubscriptionRequest,\n StartSubscriptionResponse,\n SubmitUserEventRequest,\n Subscription,\n UpdatePaymentMethodCardRequest,\n UpdatePaymentMethodCardResponse,\n UpdatePaymentMethodCryptoRequest,\n SubmitSponsorshipIntentsRequest,\n LinkRewardsRequest,\n SubscriptionApiGeneralResponse,\n CancelSubscriptionRequest,\n} from './types';\n\nexport type SubscriptionServiceConfig = {\n env: Env;\n auth: AuthUtils;\n};\n\nexport const SUBSCRIPTION_URL = (env: Env, path: string): string =>\n `${getEnvUrls(env).subscriptionApiUrl}/v1/${path}`;\n\nexport class SubscriptionService implements ISubscriptionService {\n readonly #env: Env;\n\n public authUtils: AuthUtils;\n\n constructor(config: SubscriptionServiceConfig) {\n this.#env = config.env;\n this.authUtils = config.auth;\n }\n\n async getSubscriptions(): Promise<GetSubscriptionsResponse> {\n const path = 'subscriptions';\n return await this.#makeRequest(path);\n }\n\n async cancelSubscription(\n params: CancelSubscriptionRequest,\n ): Promise<Subscription> {\n const path = `subscriptions/${params.subscriptionId}/cancel`;\n return await this.#makeRequest(path, 'POST', {\n cancelAtPeriodEnd: params.cancelAtPeriodEnd,\n });\n }\n\n async unCancelSubscription(params: {\n subscriptionId: string;\n }): Promise<Subscription> {\n const path = `subscriptions/${params.subscriptionId}/uncancel`;\n return await this.#makeRequest(path, 'POST', {});\n }\n\n async startSubscriptionWithCard(\n request: StartSubscriptionRequest,\n ): Promise<StartSubscriptionResponse> {\n if (request.products.length === 0) {\n throw new SubscriptionServiceError(\n SubscriptionControllerErrorMessage.SubscriptionProductsEmpty,\n );\n }\n const path = 'subscriptions/card';\n\n return await this.#makeRequest(path, 'POST', request);\n }\n\n async startSubscriptionWithCrypto(\n request: StartCryptoSubscriptionRequest,\n ): Promise<StartCryptoSubscriptionResponse> {\n const path = 'subscriptions/crypto';\n return await this.#makeRequest(path, 'POST', request);\n }\n\n async updatePaymentMethodCard(\n request: UpdatePaymentMethodCardRequest,\n ): Promise<UpdatePaymentMethodCardResponse> {\n const path = `subscriptions/${request.subscriptionId}/payment-method/card`;\n return await this.#makeRequest<UpdatePaymentMethodCardResponse>(\n path,\n 'PATCH',\n {\n ...request,\n subscriptionId: undefined,\n },\n );\n }\n\n async updatePaymentMethodCrypto(\n request: UpdatePaymentMethodCryptoRequest,\n ): Promise<void> {\n const path = `subscriptions/${request.subscriptionId}/payment-method/crypto`;\n await this.#makeRequest(path, 'PATCH', {\n ...request,\n subscriptionId: undefined,\n });\n }\n\n /**\n * Get the eligibility for a shield subscription.\n *\n * @param request - Optional request object containing user balance category to check cohort eligibility\n * @returns The eligibility for a shield subscription\n */\n async getSubscriptionsEligibilities(\n request?: GetSubscriptionsEligibilitiesRequest,\n ): Promise<SubscriptionEligibility[]> {\n const path = 'subscriptions/eligibility';\n let query: Record<string, string> | undefined;\n if (request?.balanceCategory !== undefined) {\n query = { balanceCategory: request.balanceCategory };\n }\n const results = await this.#makeRequest<SubscriptionEligibility[]>(\n path,\n 'GET',\n undefined,\n query,\n );\n\n return results.map((result) => ({\n ...result,\n canSubscribe: result.canSubscribe || false,\n canViewEntryModal: result.canViewEntryModal || false,\n cohorts: result.cohorts || [],\n assignedCohort: result.assignedCohort ?? null,\n hasAssignedCohortExpired: result.hasAssignedCohortExpired || false,\n }));\n }\n\n /**\n * Submit a user event. (e.g. shield modal viewed)\n *\n * @param request - Request object containing the event to submit.\n * @example { event: SubscriptionUserEvent.ShieldEntryModalViewed, cohort: 'post_tx' }\n */\n async submitUserEvent(request: SubmitUserEventRequest): Promise<void> {\n const path = 'user-events';\n await this.#makeRequest(path, 'POST', request);\n }\n\n /**\n * Assign user to a cohort.\n *\n * @param request - Request object containing the cohort to assign the user to.\n * @example { cohort: 'post_tx' }\n */\n async assignUserToCohort(request: AssignCohortRequest): Promise<void> {\n const path = 'cohorts/assign';\n await this.#makeRequest(path, 'POST', request);\n }\n\n /**\n * Submit sponsorship intents to the Subscription Service backend.\n *\n * This is intended to be used together with the crypto subscription flow.\n * When the user has enabled the smart transaction feature, we will sponsor the gas fees for the subscription approval transaction.\n *\n * @param request - Request object containing the address and products.\n * @example { address: '0x1234567890123456789012345678901234567890', products: [ProductType.Shield] }\n */\n async submitSponsorshipIntents(\n request: SubmitSponsorshipIntentsRequest,\n ): Promise<void> {\n const path = 'transaction-sponsorship/intents';\n await this.#makeRequest(path, 'POST', request);\n }\n\n /**\n * Link rewards to a subscription.\n *\n * @param request - Request object containing the reward account ID.\n * @example { rewardAccountId: 'eip155:1:0x1234567890123456789012345678901234567890' }\n * @returns The response from the API.\n */\n async linkRewards(\n request: LinkRewardsRequest,\n ): Promise<SubscriptionApiGeneralResponse> {\n const path = 'rewards/link';\n return await this.#makeRequest<SubscriptionApiGeneralResponse>(\n path,\n 'POST',\n request,\n );\n }\n\n async #makeRequest<Result>(\n path: string,\n method: 'GET' | 'POST' | 'DELETE' | 'PUT' | 'PATCH' = 'GET',\n body?: Record<string, unknown>,\n queryParams?: Record<string, string>,\n ): Promise<Result> {\n try {\n const headers = await this.#getAuthorizationHeader();\n const url = new URL(SUBSCRIPTION_URL(this.#env, path));\n\n if (queryParams) {\n Object.entries(queryParams).forEach(([key, value]) => {\n url.searchParams.append(key, value);\n });\n }\n\n const response = await handleFetch(url.toString(), {\n method,\n headers: {\n 'Content-Type': 'application/json',\n ...headers,\n },\n body: body ? JSON.stringify(body) : undefined,\n });\n\n return response;\n } catch (error) {\n const errorMessage =\n error instanceof Error ? error.message : JSON.stringify(error);\n\n throw new SubscriptionServiceError(\n `failed to make request. ${errorMessage}`,\n );\n }\n }\n\n // eslint-disable-next-line @typescript-eslint/naming-convention\n async #getAuthorizationHeader(): Promise<{ Authorization: string }> {\n const accessToken = await this.authUtils.getAccessToken();\n return { Authorization: `Bearer ${accessToken}` };\n }\n\n async getPricing(): Promise<PricingResponse> {\n const path = 'pricing';\n return await this.#makeRequest<PricingResponse>(path);\n }\n\n async getBillingPortalUrl(): Promise<BillingPortalResponse> {\n const path = 'billing-portal';\n return await this.#makeRequest<BillingPortalResponse>(path);\n }\n}\n"]}
1
+ {"version":3,"file":"SubscriptionService.cjs","sourceRoot":"","sources":["../src/SubscriptionService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,+CAIqB;AAErB,yCAIkB;AAgCX,MAAM,gBAAgB,GAAG,CAAC,GAAQ,EAAE,IAAY,EAAU,EAAE,CACjE,GAAG,IAAA,sBAAU,EAAC,GAAG,CAAC,CAAC,kBAAkB,OAAO,IAAI,EAAE,CAAC;AADxC,QAAA,gBAAgB,oBACwB;AAErD,MAAa,mBAAmB;IAS9B,YAAY,MAAiC;;QARpC,2CAAU;QAEV,6CAAqB;QAErB,wDAA2C;QAKlD,uBAAA,IAAI,4BAAQ,MAAM,CAAC,GAAG,MAAA,CAAC;QACvB,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC;QAC7B,uBAAA,IAAI,8BAAU,MAAM,CAAC,aAAa,MAAA,CAAC;QACnC,uBAAA,IAAI,yCAAqB,MAAM,CAAC,gBAAgB,MAAA,CAAC;IACnD,CAAC;IAED,KAAK,CAAC,gBAAgB;QACpB,MAAM,IAAI,GAAG,eAAe,CAAC;QAC7B,OAAO,MAAM,uBAAA,IAAI,wEAAa,MAAjB,IAAI,EAAwC;YACvD,IAAI;YACJ,YAAY,EAAE,2CAA+B,CAAC,wBAAwB;SACvE,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,kBAAkB,CACtB,MAAiC;QAEjC,MAAM,IAAI,GAAG,iBAAiB,MAAM,CAAC,cAAc,SAAS,CAAC;QAC7D,OAAO,MAAM,uBAAA,IAAI,wEAAa,MAAjB,IAAI,EAA4B;YAC3C,IAAI;YACJ,MAAM,EAAE,MAAM;YACd,IAAI,EAAE;gBACJ,iBAAiB,E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AC,IAAI,KAAK,CAAC,YAAY,CAAC,CACzD,CACF,CAAC;QAEF,MAAM,IAAI,iCAAwB,CAChC,uCAAuC,YAAY,EAAE,EACrD;YACE,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,YAAY,CAAC;SAChE,CACF,CAAC;IACJ,CAAC;AACH,CAAC,mGAEsB,IAAY;IACjC,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,IAAA,wBAAgB,EAAC,uBAAA,IAAI,gCAAK,EAAE,IAAI,CAAC,CAAC,CAAC;QACvD,OAAO,GAAG,CAAC;IACb,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,YAAY,GAChB,KAAK,YAAY,KAAK;YACpB,CAAC,CAAC,KAAK,CAAC,OAAO;YACf,CAAC,CAAC,iDAAiD,CAAC;QACxD,uBAAA,IAAI,6CAAkB,EAAE,KAAxB,IAAI,EACF,IAAA,0BAAiB,EACf,uCAAuC,YAAY,EAAE,EACrD,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,YAAY,CAAC,CACzD,CACF,CAAC;QAEF,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC","sourcesContent":["import {\n getEnvUrls,\n SubscriptionControllerErrorMessage,\n SubscriptionServiceErrorMessage,\n} from './constants';\nimport type { Env } from './constants';\nimport {\n createSentryError,\n getErrorFromResponse,\n SubscriptionServiceError,\n} from './errors';\nimport type {\n AssignCohortRequest,\n AuthUtils,\n BillingPortalResponse,\n GetSubscriptionsEligibilitiesRequest,\n GetSubscriptionsResponse,\n ISubscriptionService,\n PricingResponse,\n SubscriptionEligibility,\n StartCryptoSubscriptionRequest,\n StartCryptoSubscriptionResponse,\n StartSubscriptionRequest,\n StartSubscriptionResponse,\n SubmitUserEventRequest,\n Subscription,\n UpdatePaymentMethodCardRequest,\n UpdatePaymentMethodCardResponse,\n UpdatePaymentMethodCryptoRequest,\n SubmitSponsorshipIntentsRequest,\n LinkRewardsRequest,\n SubscriptionApiGeneralResponse,\n CancelSubscriptionRequest,\n} from './types';\n\nexport type SubscriptionServiceConfig = {\n env: Env;\n auth: AuthUtils;\n fetchFunction: typeof fetch;\n captureException?: (error: Error) => void;\n};\n\nexport const SUBSCRIPTION_URL = (env: Env, path: string): string =>\n `${getEnvUrls(env).subscriptionApiUrl}/v1/${path}`;\n\nexport class SubscriptionService implements ISubscriptionService {\n readonly #env: Env;\n\n readonly #fetch: typeof fetch;\n\n readonly #captureException?: (error: Error) => void;\n\n public authUtils: AuthUtils;\n\n constructor(config: SubscriptionServiceConfig) {\n this.#env = config.env;\n this.authUtils = config.auth;\n this.#fetch = config.fetchFunction;\n this.#captureException = config.captureException;\n }\n\n async getSubscriptions(): Promise<GetSubscriptionsResponse> {\n const path = 'subscriptions';\n return await this.#makeRequest<GetSubscriptionsResponse>({\n path,\n errorMessage: SubscriptionServiceErrorMessage.FailedToGetSubscriptions,\n });\n }\n\n async cancelSubscription(\n params: CancelSubscriptionRequest,\n ): Promise<Subscription> {\n const path = `subscriptions/${params.subscriptionId}/cancel`;\n return await this.#makeRequest<Subscription>({\n path,\n method: 'POST',\n body: {\n cancelAtPeriodEnd: params.cancelAtPeriodEnd,\n },\n errorMessage: SubscriptionServiceErrorMessage.FailedToCancelSubscription,\n });\n }\n\n async unCancelSubscription(params: {\n subscriptionId: string;\n }): Promise<Subscription> {\n const path = `subscriptions/${params.subscriptionId}/uncancel`;\n return await this.#makeRequest<Subscription>({\n path,\n method: 'POST',\n body: {},\n errorMessage:\n SubscriptionServiceErrorMessage.FailedToUncancelSubscription,\n });\n }\n\n async startSubscriptionWithCard(\n request: StartSubscriptionRequest,\n ): Promise<StartSubscriptionResponse> {\n if (request.products.length === 0) {\n throw new SubscriptionServiceError(\n SubscriptionControllerErrorMessage.SubscriptionProductsEmpty,\n );\n }\n const path = 'subscriptions/card';\n\n return await this.#makeRequest<StartSubscriptionResponse>({\n path,\n method: 'POST',\n body: request,\n errorMessage:\n SubscriptionServiceErrorMessage.FailedToStartSubscriptionWithCard,\n });\n }\n\n async startSubscriptionWithCrypto(\n request: StartCryptoSubscriptionRequest,\n ): Promise<StartCryptoSubscriptionResponse> {\n const path = 'subscriptions/crypto';\n return await this.#makeRequest<StartCryptoSubscriptionResponse>({\n path,\n method: 'POST',\n body: request,\n errorMessage:\n SubscriptionServiceErrorMessage.FailedToStartSubscriptionWithCrypto,\n });\n }\n\n async updatePaymentMethodCard(\n request: UpdatePaymentMethodCardRequest,\n ): Promise<UpdatePaymentMethodCardResponse> {\n const path = `subscriptions/${request.subscriptionId}/payment-method/card`;\n return await this.#makeRequest<UpdatePaymentMethodCardResponse>({\n path,\n method: 'PATCH',\n body: {\n ...request,\n subscriptionId: undefined,\n },\n errorMessage:\n SubscriptionServiceErrorMessage.FailedToUpdatePaymentMethodCard,\n });\n }\n\n async updatePaymentMethodCrypto(\n request: UpdatePaymentMethodCryptoRequest,\n ): Promise<void> {\n const path = `subscriptions/${request.subscriptionId}/payment-method/crypto`;\n await this.#makeRequest({\n path,\n method: 'PATCH',\n body: {\n ...request,\n subscriptionId: undefined,\n },\n errorMessage:\n SubscriptionServiceErrorMessage.FailedToUpdatePaymentMethodCrypto,\n });\n }\n\n /**\n * Get the eligibility for a shield subscription.\n *\n * @param request - Optional request object containing user balance category to check cohort eligibility\n * @returns The eligibility for a shield subscription\n */\n async getSubscriptionsEligibilities(\n request?: GetSubscriptionsEligibilitiesRequest,\n ): Promise<SubscriptionEligibility[]> {\n const path = 'subscriptions/eligibility';\n let query: Record<string, string> | undefined;\n if (request?.balanceCategory !== undefined) {\n query = { balanceCategory: request.balanceCategory };\n }\n const results = await this.#makeRequest<SubscriptionEligibility[]>({\n path,\n queryParams: query,\n errorMessage:\n SubscriptionServiceErrorMessage.FailedToGetSubscriptionsEligibilities,\n });\n\n return results.map((result) => ({\n ...result,\n canSubscribe: result.canSubscribe || false,\n canViewEntryModal: result.canViewEntryModal || false,\n cohorts: result.cohorts || [],\n assignedCohort: result.assignedCohort ?? null,\n hasAssignedCohortExpired: result.hasAssignedCohortExpired || false,\n }));\n }\n\n /**\n * Submit a user event. (e.g. shield modal viewed)\n *\n * @param request - Request object containing the event to submit.\n * @example { event: SubscriptionUserEvent.ShieldEntryModalViewed, cohort: 'post_tx' }\n */\n async submitUserEvent(request: SubmitUserEventRequest): Promise<void> {\n const path = 'user-events';\n await this.#makeRequest({\n path,\n method: 'POST',\n body: request,\n errorMessage: SubscriptionServiceErrorMessage.FailedToSubmitUserEvent,\n });\n }\n\n /**\n * Assign user to a cohort.\n *\n * @param request - Request object containing the cohort to assign the user to.\n * @example { cohort: 'post_tx' }\n */\n async assignUserToCohort(request: AssignCohortRequest): Promise<void> {\n const path = 'cohorts/assign';\n await this.#makeRequest({\n path,\n method: 'POST',\n body: request,\n errorMessage: SubscriptionServiceErrorMessage.FailedToAssignUserToCohort,\n });\n }\n\n /**\n * Submit sponsorship intents to the Subscription Service backend.\n *\n * This is intended to be used together with the crypto subscription flow.\n * When the user has enabled the smart transaction feature, we will sponsor the gas fees for the subscription approval transaction.\n *\n * @param request - Request object containing the address and products.\n * @example { address: '0x1234567890123456789012345678901234567890', products: [ProductType.Shield] }\n */\n async submitSponsorshipIntents(\n request: SubmitSponsorshipIntentsRequest,\n ): Promise<void> {\n const path = 'transaction-sponsorship/intents';\n await this.#makeRequest({\n path,\n method: 'POST',\n body: request,\n errorMessage:\n SubscriptionServiceErrorMessage.FailedToSubmitSponsorshipIntents,\n });\n }\n\n /**\n * Link rewards to a subscription.\n *\n * @param request - Request object containing the reward account ID.\n * @example { rewardAccountId: 'eip155:1:0x1234567890123456789012345678901234567890' }\n * @returns The response from the API.\n */\n async linkRewards(\n request: LinkRewardsRequest,\n ): Promise<SubscriptionApiGeneralResponse> {\n const path = 'rewards/link';\n return await this.#makeRequest<SubscriptionApiGeneralResponse>({\n path,\n method: 'POST',\n body: request,\n errorMessage: SubscriptionServiceErrorMessage.FailedToLinkRewards,\n });\n }\n\n async getPricing(): Promise<PricingResponse> {\n const path = 'pricing';\n return await this.#makeRequest<PricingResponse>({\n path,\n errorMessage: SubscriptionServiceErrorMessage.FailedToGetPricing,\n });\n }\n\n async getBillingPortalUrl(): Promise<BillingPortalResponse> {\n const path = 'billing-portal';\n return await this.#makeRequest<BillingPortalResponse>({\n path,\n errorMessage: SubscriptionServiceErrorMessage.FailedToGetBillingPortalUrl,\n });\n }\n\n /**\n * Makes a request to the Subscription Service backend.\n *\n * @param params - The request object containing the path, method, body, query parameters, and error message.\n * @param params.path - The path of the request.\n * @param params.method - The method of the request.\n * @param params.body - The body of the request.\n * @param params.queryParams - The query parameters of the request.\n * @param params.errorMessage - The error message to throw if the request fails.\n * @returns The result of the request.\n */\n async #makeRequest<Result>({\n path,\n method = 'GET',\n body,\n queryParams,\n errorMessage,\n }: {\n path: string;\n method?: 'GET' | 'POST' | 'DELETE' | 'PUT' | 'PATCH';\n body?: Record<string, unknown>;\n queryParams?: Record<string, string>;\n errorMessage: string;\n }): Promise<Result> {\n const url = this.#getSubscriptionApiUrl(path);\n const headers = await this.#getAuthorizationHeader();\n\n try {\n if (queryParams) {\n Object.entries(queryParams).forEach(([key, value]) => {\n url.searchParams.append(key, value);\n });\n }\n\n const response = await this.#fetch(url.toString(), {\n method,\n headers: {\n 'Content-Type': 'application/json',\n ...headers,\n },\n body: body ? JSON.stringify(body) : undefined,\n });\n\n if (!response.ok) {\n const error = await getErrorFromResponse(response);\n throw error;\n }\n\n const data = await response.json();\n return data;\n } catch (error) {\n console.error(errorMessage, error);\n\n const errorMessageWithUrl = `${errorMessage} (url: ${url.toString()})`;\n const errorToCapture =\n error instanceof Error ? error : new Error(errorMessage);\n this.#captureException?.(\n createSentryError(errorMessageWithUrl, errorToCapture),\n );\n\n throw new SubscriptionServiceError(\n `Failed to make request. ${errorMessageWithUrl}`,\n {\n cause: errorToCapture,\n },\n );\n }\n }\n\n // eslint-disable-next-line @typescript-eslint/naming-convention\n async #getAuthorizationHeader(): Promise<{ Authorization: string }> {\n try {\n const accessToken = await this.authUtils.getAccessToken();\n return { Authorization: `Bearer ${accessToken}` };\n } catch (error) {\n const errorMessage =\n error instanceof Error\n ? error.message\n : 'Unknown error when getting authorization header';\n\n this.#captureException?.(\n createSentryError(\n `Failed to get authorization header. ${errorMessage}`,\n error instanceof Error ? error : new Error(errorMessage),\n ),\n );\n\n throw new SubscriptionServiceError(\n `Failed to get authorization header. ${errorMessage}`,\n {\n cause: error instanceof Error ? error : new Error(errorMessage),\n },\n );\n }\n }\n\n #getSubscriptionApiUrl(path: string): URL {\n try {\n const url = new URL(SUBSCRIPTION_URL(this.#env, path));\n return url;\n } catch (error) {\n const errorMessage =\n error instanceof Error\n ? error.message\n : 'Unknown error when getting subscription API URL';\n this.#captureException?.(\n createSentryError(\n `Failed to get subscription API URL. ${errorMessage}`,\n error instanceof Error ? error : new Error(errorMessage),\n ),\n );\n\n throw error;\n }\n }\n}\n"]}
@@ -3,6 +3,8 @@ import type { AssignCohortRequest, AuthUtils, BillingPortalResponse, GetSubscrip
3
3
  export type SubscriptionServiceConfig = {
4
4
  env: Env;
5
5
  auth: AuthUtils;
6
+ fetchFunction: typeof fetch;
7
+ captureException?: (error: Error) => void;
6
8
  };
7
9
  export declare const SUBSCRIPTION_URL: (env: Env, path: string) => string;
8
10
  export declare class SubscriptionService implements ISubscriptionService {
@@ -1 +1 @@
1
- {"version":3,"file":"SubscriptionService.d.cts","sourceRoot":"","sources":["../src/SubscriptionService.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAoB;AAEvC,OAAO,KAAK,EACV,mBAAmB,EACnB,SAAS,EACT,qBAAqB,EACrB,oCAAoC,EACpC,wBAAwB,EACxB,oBAAoB,EACpB,eAAe,EACf,uBAAuB,EACvB,8BAA8B,EAC9B,+BAA+B,EAC/B,wBAAwB,EACxB,yBAAyB,EACzB,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oB,CAAC,MAAM,EAAE;QACjC,cAAc,EAAE,MAAM,CAAC;KACxB,GAAG,OAAO,CAAC,YAAY,CAAC;IAWnB,yBAAyB,CAC7B,OAAO,EAAE,wBAAwB,GAChC,OAAO,CAAC,yBAAyB,CAAC;IAiB/B,2BAA2B,CAC/B,OAAO,EAAE,8BAA8B,GACtC,OAAO,CAAC,+BAA+B,CAAC;IAWrC,uBAAuB,CAC3B,OAAO,EAAE,8BAA8B,GACtC,OAAO,CAAC,+BAA+B,CAAC;IAcrC,yBAAyB,CAC7B,OAAO,EAAE,gCAAgC,GACxC,OAAO,CAAC,IAAI,CAAC;IAchB;;;;;OAKG;IACG,6BAA6B,CACjC,OAAO,CAAC,EAAE,oCAAoC,GAC7C,OAAO,CAAC,uBAAuB,EAAE,CAAC;IAuBrC;;;;;OAKG;IACG,eAAe,CAAC,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC;IAUrE;;;;;OAKG;IACG,kBAAkB,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;IAUrE;;;;;;;;OAQG;IACG,wBAAwB,CAC5B,OAAO,EAAE,+BAA+B,GACvC,OAAO,CAAC,IAAI,CAAC;IAWhB;;;;;;OAMG;IACG,WAAW,CACf,OAAO,EAAE,kBAAkB,GAC1B,OAAO,CAAC,8BAA8B,CAAC;IAUpC,UAAU,IAAI,OAAO,CAAC,eAAe,CAAC;IAQtC,mBAAmB,IAAI,OAAO,CAAC,qBAAqB,CAAC;CA2H5D"}
@@ -3,6 +3,8 @@ import type { AssignCohortRequest, AuthUtils, BillingPortalResponse, GetSubscrip
3
3
  export type SubscriptionServiceConfig = {
4
4
  env: Env;
5
5
  auth: AuthUtils;
6
+ fetchFunction: typeof fetch;
7
+ captureException?: (error: Error) => void;
6
8
  };
7
9
  export declare const SUBSCRIPTION_URL: (env: Env, path: string) => string;
8
10
  export declare class SubscriptionService implements ISubscriptionService {
@@ -1 +1 @@
1
- {"version":3,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