@metamask/subscription-controller 8.0.1 → 9.0.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 +38 -1
- package/dist/{SubscriptionController-method-action-types.d.mts → SubscriptionController-method-action-types.d.ts} +14 -3
- package/dist/SubscriptionController-method-action-types.d.ts.map +1 -0
- package/dist/{SubscriptionController-method-action-types.mjs → SubscriptionController-method-action-types.js} +1 -1
- package/dist/SubscriptionController-method-action-types.js.map +1 -0
- package/dist/{SubscriptionController.d.mts → SubscriptionController.d.ts} +29 -19
- package/dist/SubscriptionController.d.ts.map +1 -0
- package/dist/{SubscriptionController.mjs → SubscriptionController.js} +391 -190
- package/dist/SubscriptionController.js.map +1 -0
- package/dist/{SubscriptionService-method-action-types.d.mts → SubscriptionService-method-action-types.d.ts} +12 -3
- package/dist/SubscriptionService-method-action-types.d.ts.map +1 -0
- package/dist/{SubscriptionService-method-action-types.mjs → SubscriptionService-method-action-types.js} +1 -1
- package/dist/SubscriptionService-method-action-types.js.map +1 -0
- package/dist/{SubscriptionService-structs.d.mts → SubscriptionService-structs.d.ts} +302 -134
- package/dist/SubscriptionService-structs.d.ts.map +1 -0
- package/dist/{SubscriptionService-structs.mjs → SubscriptionService-structs.js} +55 -4
- package/dist/SubscriptionService-structs.js.map +1 -0
- package/dist/{SubscriptionService.d.cts → SubscriptionService.d.ts} +16 -10
- package/dist/SubscriptionService.d.ts.map +1 -0
- package/dist/{SubscriptionService.mjs → SubscriptionService.js} +159 -141
- package/dist/SubscriptionService.js.map +1 -0
- package/dist/{constants.d.cts → constants.d.ts} +2 -1
- package/dist/constants.d.ts.map +1 -0
- package/dist/{constants.mjs → constants.js} +4 -3
- package/dist/constants.js.map +1 -0
- package/dist/{errors.d.cts → errors.d.ts} +2 -2
- package/dist/errors.d.ts.map +1 -0
- package/dist/{errors.mjs → errors.js} +5 -1
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/logger.d.ts +4 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +5 -0
- package/dist/logger.js.map +1 -0
- package/dist/selectors.d.ts +38 -0
- package/dist/selectors.d.ts.map +1 -0
- package/dist/selectors.js +46 -0
- package/dist/selectors.js.map +1 -0
- package/dist/{types.d.mts → types.d.ts} +112 -41
- package/dist/types.d.ts.map +1 -0
- package/dist/{types.mjs → types.js} +11 -1
- package/dist/types.js.map +1 -0
- package/package.json +22 -25
- package/dist/SubscriptionController-method-action-types.cjs +0 -7
- package/dist/SubscriptionController-method-action-types.cjs.map +0 -1
- package/dist/SubscriptionController-method-action-types.d.cts +0 -250
- package/dist/SubscriptionController-method-action-types.d.cts.map +0 -1
- package/dist/SubscriptionController-method-action-types.d.mts.map +0 -1
- package/dist/SubscriptionController-method-action-types.mjs.map +0 -1
- package/dist/SubscriptionController.cjs +0 -744
- package/dist/SubscriptionController.cjs.map +0 -1
- package/dist/SubscriptionController.d.cts +0 -258
- package/dist/SubscriptionController.d.cts.map +0 -1
- package/dist/SubscriptionController.d.mts.map +0 -1
- package/dist/SubscriptionController.mjs.map +0 -1
- package/dist/SubscriptionService-method-action-types.cjs +0 -7
- package/dist/SubscriptionService-method-action-types.cjs.map +0 -1
- package/dist/SubscriptionService-method-action-types.d.cts +0 -155
- package/dist/SubscriptionService-method-action-types.d.cts.map +0 -1
- package/dist/SubscriptionService-method-action-types.d.mts.map +0 -1
- package/dist/SubscriptionService-method-action-types.mjs.map +0 -1
- package/dist/SubscriptionService-structs.cjs +0 -158
- package/dist/SubscriptionService-structs.cjs.map +0 -1
- package/dist/SubscriptionService-structs.d.cts +0 -721
- package/dist/SubscriptionService-structs.d.cts.map +0 -1
- package/dist/SubscriptionService-structs.d.mts.map +0 -1
- package/dist/SubscriptionService-structs.mjs.map +0 -1
- package/dist/SubscriptionService.cjs +0 -477
- package/dist/SubscriptionService.cjs.map +0 -1
- package/dist/SubscriptionService.d.cts.map +0 -1
- package/dist/SubscriptionService.d.mts +0 -149
- package/dist/SubscriptionService.d.mts.map +0 -1
- package/dist/SubscriptionService.mjs.map +0 -1
- package/dist/constants.cjs +0 -73
- package/dist/constants.cjs.map +0 -1
- package/dist/constants.d.cts.map +0 -1
- package/dist/constants.d.mts +0 -49
- package/dist/constants.d.mts.map +0 -1
- package/dist/constants.mjs.map +0 -1
- package/dist/errors.cjs +0 -72
- package/dist/errors.cjs.map +0 -1
- package/dist/errors.d.cts.map +0 -1
- package/dist/errors.d.mts +0 -34
- package/dist/errors.d.mts.map +0 -1
- package/dist/errors.mjs.map +0 -1
- package/dist/index.cjs +0 -29
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -11
- package/dist/index.d.cts.map +0 -1
- package/dist/index.d.mts +0 -11
- package/dist/index.d.mts.map +0 -1
- package/dist/index.mjs +0 -6
- package/dist/index.mjs.map +0 -1
- package/dist/logger.cjs +0 -8
- package/dist/logger.cjs.map +0 -1
- package/dist/logger.d.cts +0 -5
- package/dist/logger.d.cts.map +0 -1
- package/dist/logger.d.mts +0 -5
- package/dist/logger.d.mts.map +0 -1
- package/dist/logger.mjs +0 -5
- package/dist/logger.mjs.map +0 -1
- package/dist/types.cjs +0 -90
- package/dist/types.cjs.map +0 -1
- package/dist/types.d.cts +0 -574
- package/dist/types.d.cts.map +0 -1
- package/dist/types.d.mts.map +0 -1
- package/dist/types.mjs.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SubscriptionService-structs.d.ts","sourceRoot":"","sources":["../src/SubscriptionService-structs.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAcpD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAiEnD,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EASxC,CAAC;AAEH,eAAO,MAAM,kCAAkC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAE9C,CAAC"}
|
|
@@ -1,8 +1,27 @@
|
|
|
1
|
-
import { array, boolean, enums, lazy, literal, nullable, number, object, optional, string, type, union } from
|
|
2
|
-
import { StrictHexStruct, CaipAccountIdStruct } from
|
|
3
|
-
import { CANCEL_TYPES, CRYPTO_AUTH_METHODS, CRYPTO_PAYMENT_METHOD_ERRORS, PAYMENT_TYPES, PRODUCT_TYPES, RECURRING_INTERVALS, SUBSCRIPTION_STATUSES } from
|
|
1
|
+
import { array, boolean, enums, lazy, literal, nullable, number, object, optional, string, type, union, } from '@metamask/superstruct';
|
|
2
|
+
import { StrictHexStruct, CaipAccountIdStruct } from '@metamask/utils';
|
|
3
|
+
import { CANCEL_TYPES, CRYPTO_AUTH_METHODS, CRYPTO_PAYMENT_METHOD_ERRORS, PAYMENT_TYPES, PRODUCT_TYPES, RECURRING_INTERVALS, MoneyAccountFeature, ShieldFeature, SUBSCRIPTION_STATUSES, } from './types.js';
|
|
4
4
|
const ProductTypeStruct = enums(Object.values(PRODUCT_TYPES));
|
|
5
5
|
const CryptoAuthMethodStruct = enums(Object.values(CRYPTO_AUTH_METHODS));
|
|
6
|
+
const ShieldEntitlementsStruct = type({
|
|
7
|
+
[ShieldFeature.ShieldClaim]: boolean(),
|
|
8
|
+
[ShieldFeature.PrioritySupport]: boolean(),
|
|
9
|
+
});
|
|
10
|
+
const MoneyAccountEntitlementsStruct = type({
|
|
11
|
+
[MoneyAccountFeature.SwapFeeWaiver]: boolean(),
|
|
12
|
+
[MoneyAccountFeature.PerpsFeeWaiver]: boolean(),
|
|
13
|
+
[MoneyAccountFeature.PredictFreeTx]: boolean(),
|
|
14
|
+
[MoneyAccountFeature.PremiumApy]: boolean(),
|
|
15
|
+
});
|
|
16
|
+
const ProductEntitlementsStruct = type({
|
|
17
|
+
[PRODUCT_TYPES.SHIELD]: optional(type({
|
|
18
|
+
entitlements: ShieldEntitlementsStruct,
|
|
19
|
+
})),
|
|
20
|
+
[PRODUCT_TYPES.MONEY_ACCOUNT_PLUS]: optional(type({
|
|
21
|
+
plan: string(),
|
|
22
|
+
entitlements: MoneyAccountEntitlementsStruct,
|
|
23
|
+
})),
|
|
24
|
+
});
|
|
6
25
|
const RecurringIntervalStruct = enums(Object.values(RECURRING_INTERVALS));
|
|
7
26
|
const SubscriptionStatusStruct = enums(Object.values(SUBSCRIPTION_STATUSES));
|
|
8
27
|
const CancelTypeStruct = enums(Object.values(CANCEL_TYPES));
|
|
@@ -57,9 +76,41 @@ export const GetSubscriptionsResponseStruct = type({
|
|
|
57
76
|
customerId: optional(string()),
|
|
58
77
|
subscriptions: array(SubscriptionStruct),
|
|
59
78
|
trialedProducts: array(ProductTypeStruct),
|
|
79
|
+
productEntitlements: optional(ProductEntitlementsStruct),
|
|
60
80
|
lastSubscription: optional(SubscriptionStruct),
|
|
61
81
|
rewardAccountId: optional(CaipAccountIdStruct),
|
|
62
82
|
});
|
|
83
|
+
const SwapsBenefitUsageStruct = type({
|
|
84
|
+
feeBips: nullable(string()),
|
|
85
|
+
capMicroUsd: optional(number()),
|
|
86
|
+
consumedMicroUsd: optional(number()),
|
|
87
|
+
remainingMicroUsd: nullable(number()),
|
|
88
|
+
exhausted: boolean(),
|
|
89
|
+
});
|
|
90
|
+
const PerpsBenefitUsageStruct = type({
|
|
91
|
+
builderFeeBips: nullable(string()),
|
|
92
|
+
builderCode: nullable(string()),
|
|
93
|
+
capMicroUsd: optional(number()),
|
|
94
|
+
consumedMicroUsd: optional(number()),
|
|
95
|
+
remainingMicroUsd: nullable(number()),
|
|
96
|
+
exhausted: boolean(),
|
|
97
|
+
});
|
|
98
|
+
const PredictBenefitUsageStruct = type({
|
|
99
|
+
builderCode: nullable(string()),
|
|
100
|
+
capTxCount: optional(number()),
|
|
101
|
+
consumedTxCount: optional(number()),
|
|
102
|
+
remainingTxCount: nullable(number()),
|
|
103
|
+
exhausted: boolean(),
|
|
104
|
+
});
|
|
105
|
+
export const SubscriptionBenefitsResponseStruct = type({
|
|
106
|
+
eligible: boolean(),
|
|
107
|
+
billingPeriodId: nullable(string()),
|
|
108
|
+
products: type({
|
|
109
|
+
swaps: SwapsBenefitUsageStruct,
|
|
110
|
+
perps: PerpsBenefitUsageStruct,
|
|
111
|
+
predict: PredictBenefitUsageStruct,
|
|
112
|
+
}),
|
|
113
|
+
});
|
|
63
114
|
export const StartSubscriptionResponseStruct = type({
|
|
64
115
|
checkoutSessionUrl: string(),
|
|
65
116
|
});
|
|
@@ -152,4 +203,4 @@ export const SubscriptionEligibilityStruct = type({
|
|
|
152
203
|
hasAssignedCohortExpired: optional(boolean()),
|
|
153
204
|
});
|
|
154
205
|
export const SubscriptionEligibilityArrayStruct = array(SubscriptionEligibilityStruct);
|
|
155
|
-
//# sourceMappingURL=SubscriptionService-structs.
|
|
206
|
+
//# sourceMappingURL=SubscriptionService-structs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SubscriptionService-structs.js","sourceRoot":"","sources":["../src/SubscriptionService-structs.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,OAAO,EACP,KAAK,EACL,IAAI,EACJ,OAAO,EACP,QAAQ,EACR,MAAM,EACN,MAAM,EACN,QAAQ,EACR,MAAM,EACN,IAAI,EACJ,KAAK,GACN,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAEvE,OAAO,EACL,YAAY,EACZ,mBAAmB,EACnB,4BAA4B,EAC5B,aAAa,EACb,aAAa,EACb,mBAAmB,EACnB,mBAAmB,EACnB,aAAa,EACb,qBAAqB,GACtB,MAAM,YAAY,CAAC;AAGpB,MAAM,iBAAiB,GAAG,KAAK,CAAC,MAAM,CAAC,MAA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AAE,QAAQ,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;IACtC,OAAO,EAAE,QAAQ,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;IACtC,cAAc,EAAE,QAAQ,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;IAC5C,UAAU,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC;IAC9B,wBAAwB,EAAE,QAAQ,CAAC,OAAO,EAAE,CAAC;CAC9C,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,kCAAkC,GAAG,KAAK,CACrD,6BAA6B,CAC9B,CAAC","sourcesContent":["import {\n array,\n boolean,\n enums,\n lazy,\n literal,\n nullable,\n number,\n object,\n optional,\n string,\n type,\n union,\n} from '@metamask/superstruct';\nimport type { Struct } from '@metamask/superstruct';\nimport { StrictHexStruct, CaipAccountIdStruct } from '@metamask/utils';\n\nimport {\n CANCEL_TYPES,\n CRYPTO_AUTH_METHODS,\n CRYPTO_PAYMENT_METHOD_ERRORS,\n PAYMENT_TYPES,\n PRODUCT_TYPES,\n RECURRING_INTERVALS,\n MoneyAccountFeature,\n ShieldFeature,\n SUBSCRIPTION_STATUSES,\n} from './types.js';\nimport type { TokenPaymentInfo } from './types.js';\n\nconst ProductTypeStruct = enums(Object.values(PRODUCT_TYPES));\nconst CryptoAuthMethodStruct = enums(Object.values(CRYPTO_AUTH_METHODS));\nconst ShieldEntitlementsStruct = type({\n [ShieldFeature.ShieldClaim]: boolean(),\n [ShieldFeature.PrioritySupport]: boolean(),\n});\nconst MoneyAccountEntitlementsStruct = type({\n [MoneyAccountFeature.SwapFeeWaiver]: boolean(),\n [MoneyAccountFeature.PerpsFeeWaiver]: boolean(),\n [MoneyAccountFeature.PredictFreeTx]: boolean(),\n [MoneyAccountFeature.PremiumApy]: boolean(),\n});\nconst ProductEntitlementsStruct = type({\n [PRODUCT_TYPES.SHIELD]: optional(\n type({\n entitlements: ShieldEntitlementsStruct,\n }),\n ),\n [PRODUCT_TYPES.MONEY_ACCOUNT_PLUS]: optional(\n type({\n plan: string(),\n entitlements: MoneyAccountEntitlementsStruct,\n }),\n ),\n});\nconst RecurringIntervalStruct = enums(Object.values(RECURRING_INTERVALS));\nconst SubscriptionStatusStruct = enums(Object.values(SUBSCRIPTION_STATUSES));\nconst CancelTypeStruct = enums(Object.values(CANCEL_TYPES));\nconst CryptoPaymentMethodErrorStruct = enums(\n Object.values(CRYPTO_PAYMENT_METHOD_ERRORS),\n);\n\nconst ProductStruct = type({\n name: ProductTypeStruct,\n currency: enums(['usd']),\n unitAmount: number(),\n unitDecimals: number(),\n});\n\nconst SubscriptionCardPaymentMethodStruct = type({\n type: enums([PAYMENT_TYPES.byCard]),\n card: type({\n brand: string(),\n displayBrand: string(),\n last4: string(),\n }),\n});\n\nconst SubscriptionCryptoPaymentMethodStruct = type({\n type: enums([PAYMENT_TYPES.byCrypto]),\n crypto: type({\n payerAddress: StrictHexStruct,\n chainId: StrictHexStruct,\n tokenSymbol: string(),\n error: optional(CryptoPaymentMethodErrorStruct),\n }),\n});\n\nconst SubscriptionPaymentMethodStruct = union([\n SubscriptionCardPaymentMethodStruct,\n SubscriptionCryptoPaymentMethodStruct,\n]);\n\nexport const SubscriptionStruct = type({\n id: string(),\n products: array(ProductStruct),\n currentPeriodStart: string(),\n currentPeriodEnd: string(),\n cancelAtPeriodEnd: optional(boolean()),\n status: SubscriptionStatusStruct,\n interval: RecurringIntervalStruct,\n paymentMethod: SubscriptionPaymentMethodStruct,\n trialPeriodDays: optional(number()),\n trialStart: optional(string()),\n trialEnd: optional(string()),\n endDate: optional(string()),\n canceledAt: optional(string()),\n cancelType: CancelTypeStruct,\n inactiveAt: optional(string()),\n isEligibleForSupport: boolean(),\n billingCycles: optional(number()),\n});\n\nexport const GetSubscriptionsResponseStruct = type({\n customerId: optional(string()),\n subscriptions: array(SubscriptionStruct),\n trialedProducts: array(ProductTypeStruct),\n productEntitlements: optional(ProductEntitlementsStruct),\n lastSubscription: optional(SubscriptionStruct),\n rewardAccountId: optional(CaipAccountIdStruct),\n});\n\nconst SwapsBenefitUsageStruct = type({\n feeBips: nullable(string()),\n capMicroUsd: optional(number()),\n consumedMicroUsd: optional(number()),\n remainingMicroUsd: nullable(number()),\n exhausted: boolean(),\n});\n\nconst PerpsBenefitUsageStruct = type({\n builderFeeBips: nullable(string()),\n builderCode: nullable(string()),\n capMicroUsd: optional(number()),\n consumedMicroUsd: optional(number()),\n remainingMicroUsd: nullable(number()),\n exhausted: boolean(),\n});\n\nconst PredictBenefitUsageStruct = type({\n builderCode: nullable(string()),\n capTxCount: optional(number()),\n consumedTxCount: optional(number()),\n remainingTxCount: nullable(number()),\n exhausted: boolean(),\n});\n\nexport const SubscriptionBenefitsResponseStruct = type({\n eligible: boolean(),\n billingPeriodId: nullable(string()),\n products: type({\n swaps: SwapsBenefitUsageStruct,\n perps: PerpsBenefitUsageStruct,\n predict: PredictBenefitUsageStruct,\n }),\n});\n\nexport const StartSubscriptionResponseStruct = type({\n checkoutSessionUrl: string(),\n});\n\nexport const StartCryptoSubscriptionResponseStruct = type({\n subscriptionId: string(),\n status: SubscriptionStatusStruct,\n});\n\nexport const UpdatePaymentMethodCardResponseStruct = type({\n redirectUrl: string(),\n});\n\nexport const BillingPortalResponseStruct = type({\n url: string(),\n});\n\nexport const SubscriptionApiGeneralResponseStruct = type({\n success: boolean(),\n message: optional(string()),\n});\n\nconst ProductPriceStruct = type({\n interval: RecurringIntervalStruct,\n unitAmount: number(),\n unitDecimals: number(),\n currency: enums(['usd']),\n trialPeriodDays: number(),\n minBillingCycles: number(),\n minBillingCyclesForBalance: number(),\n});\n\nconst ProductPricingStruct = type({\n name: ProductTypeStruct,\n prices: array(ProductPriceStruct),\n});\n\nconst TokenPaymentInfoConversionRateStruct = type({\n usd: string(),\n});\n\nconst TokenPaymentInfoStruct: Struct<TokenPaymentInfo> = lazy(() =>\n union([\n object({\n symbol: string(),\n address: StrictHexStruct,\n decimals: number(),\n conversionRate: optional(TokenPaymentInfoConversionRateStruct),\n isVaultShare: literal(true),\n accountantAddress: StrictHexStruct,\n sources: optional(array(TokenPaymentInfoStruct)),\n }),\n object({\n symbol: string(),\n address: StrictHexStruct,\n decimals: number(),\n conversionRate: optional(TokenPaymentInfoConversionRateStruct),\n isVaultShare: optional(literal(false)),\n sources: optional(array(TokenPaymentInfoStruct)),\n }),\n ]),\n) as Struct<TokenPaymentInfo>;\n\nconst ChainPaymentInfoStruct = type({\n chainId: StrictHexStruct,\n paymentAddress: StrictHexStruct,\n delegateAddress: optional(StrictHexStruct),\n tokens: array(TokenPaymentInfoStruct),\n isSponsorshipSupported: optional(boolean()),\n});\n\nconst PricingPaymentMethodStruct = union([\n object({\n type: enums([PAYMENT_TYPES.byCard]),\n products: optional(array(ProductTypeStruct)),\n }),\n object({\n type: enums([PAYMENT_TYPES.byCrypto]),\n cryptoAuthMethod: optional(CryptoAuthMethodStruct),\n products: optional(array(ProductTypeStruct)),\n chains: optional(array(ChainPaymentInfoStruct)),\n }),\n]);\n\nexport const PricingResponseStruct = type({\n products: array(ProductPricingStruct),\n paymentMethods: array(PricingPaymentMethodStruct),\n});\n\nconst CohortStruct = type({\n cohort: string(),\n eligibilityRate: number(),\n priority: number(),\n eligible: boolean(),\n});\n\nexport const SubscriptionEligibilityStruct = type({\n product: ProductTypeStruct,\n canSubscribe: optional(boolean()),\n canViewEntryModal: optional(boolean()),\n modalType: optional(enums(['A', 'B'])),\n cohorts: optional(array(CohortStruct)),\n assignedCohort: optional(nullable(string())),\n assignedAt: optional(string()),\n hasAssignedCohortExpired: optional(boolean()),\n});\n\nexport const SubscriptionEligibilityArrayStruct = array(\n SubscriptionEligibilityStruct,\n);\n"]}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import type { DataServiceCacheUpdatedEvent, DataServiceGranularCacheUpdatedEvent, DataServiceInvalidateQueriesAction } from
|
|
2
|
-
import { BaseDataService } from
|
|
3
|
-
import type { CreateServicePolicyOptions } from
|
|
4
|
-
import type { Messenger } from
|
|
5
|
-
import type { AuthenticationController } from
|
|
6
|
-
import type { QueryClientConfig } from
|
|
7
|
-
import { Env } from
|
|
8
|
-
import type { SubscriptionServiceMethodActions } from
|
|
9
|
-
import type { AssignCohortRequest, BillingPortalResponse, CancelSubscriptionRequest, GetSubscriptionsEligibilitiesRequest, GetSubscriptionsResponse, LinkRewardsRequest, PricingResponse, StartCryptoSubscriptionRequest, StartCryptoSubscriptionResponse, StartSubscriptionRequest, StartSubscriptionResponse, SubmitSponsorshipIntentsRequest, SubmitUserEventRequest, Subscription, SubscriptionApiGeneralResponse, SubscriptionEligibility, UpdatePaymentMethodCardRequest, UpdatePaymentMethodCardResponse, UpdatePaymentMethodCryptoRequest } from
|
|
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.js';
|
|
8
|
+
import type { SubscriptionServiceMethodActions } from './SubscriptionService-method-action-types.js';
|
|
9
|
+
import type { AssignCohortRequest, BillingPortalResponse, CancelSubscriptionRequest, GetSubscriptionsEligibilitiesRequest, GetSubscriptionsResponse, LinkRewardsRequest, PricingResponse, StartCryptoSubscriptionRequest, StartCryptoSubscriptionResponse, StartSubscriptionRequest, StartSubscriptionResponse, SubmitSponsorshipIntentsRequest, SubmitUserEventRequest, Subscription, SubscriptionApiGeneralResponse, SubscriptionBenefitsResponse, SubscriptionEligibility, UpdatePaymentMethodCardRequest, UpdatePaymentMethodCardResponse, UpdatePaymentMethodCryptoRequest } from './types.js';
|
|
10
10
|
export declare const serviceName = "SubscriptionService";
|
|
11
11
|
export declare const SUBSCRIPTION_URL: (env: Env, path: string) => string;
|
|
12
12
|
export type SubscriptionServiceInvalidateQueriesAction = DataServiceInvalidateQueriesAction<typeof serviceName>;
|
|
@@ -45,6 +45,12 @@ export declare class SubscriptionService extends BaseDataService<typeof serviceN
|
|
|
45
45
|
* @returns The subscriptions response.
|
|
46
46
|
*/
|
|
47
47
|
getSubscriptions(): Promise<GetSubscriptionsResponse>;
|
|
48
|
+
/**
|
|
49
|
+
* Fetches the user's subscription benefits.
|
|
50
|
+
*
|
|
51
|
+
* @returns The benefits response.
|
|
52
|
+
*/
|
|
53
|
+
getBenefits(): Promise<SubscriptionBenefitsResponse>;
|
|
48
54
|
/**
|
|
49
55
|
* Cancels a subscription.
|
|
50
56
|
*
|
|
@@ -146,4 +152,4 @@ export declare class SubscriptionService extends BaseDataService<typeof serviceN
|
|
|
146
152
|
getBillingPortalUrl(): Promise<BillingPortalResponse>;
|
|
147
153
|
}
|
|
148
154
|
export {};
|
|
149
|
-
//# sourceMappingURL=SubscriptionService.d.
|
|
155
|
+
//# sourceMappingURL=SubscriptionService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SubscriptionService.d.ts","sourceRoot":"","sources":["../src/SubscriptionService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,4BAA4B,EAC5B,oCAAoC,EACpC,kCAAkC,EACnC,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,4BAA4B,CAAC;AAE7E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,mCAAmC,CAAC;AAGlF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAE9D,OAAO,EACL,GAAG,EAIJ,MAAM,gBAAgB,C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A4BpC;IAED;;;;;OAKG;IACG,eAAe,CAAC,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC,CAYpE;IAED;;;;;OAKG;IACG,kBAAkB,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC,CAYpE;IAED;;;;;;;;OAQG;IACG,wBAAwB,CAC5B,OAAO,EAAE,+BAA+B,GACvC,OAAO,CAAC,IAAI,CAAC,CAaf;IAED;;;;;;OAMG;IACG,WAAW,CACf,OAAO,EAAE,kBAAkB,GAC1B,OAAO,CAAC,8BAA8B,CAAC,CAczC;IAED;;;;OAIG;IACG,UAAU,IAAI,OAAO,CAAC,eAAe,CAAC,CAY3C;IAED;;;;OAIG;IACG,mBAAmB,IAAI,OAAO,CAAC,qBAAqB,CAAC,CAY1D;CAoKF"}
|
|
@@ -1,27 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
|
|
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";
|
|
1
|
+
import { BaseDataService } from '@metamask/base-data-service';
|
|
2
|
+
import { handleWhen, HttpError } from '@metamask/controller-utils';
|
|
3
|
+
import { create } from '@metamask/superstruct';
|
|
4
|
+
import { Env, getEnvUrls, SubscriptionControllerErrorMessage, SubscriptionServiceErrorMessage, } from './constants.js';
|
|
5
|
+
import { createSentryError, getSubscriptionErrorFromResponse, SubscriptionServiceError, } from './errors.js';
|
|
6
|
+
import { createModuleLogger, projectLogger } from './logger.js';
|
|
7
|
+
import { BillingPortalResponseStruct, GetSubscriptionsResponseStruct, PricingResponseStruct, StartCryptoSubscriptionResponseStruct, StartSubscriptionResponseStruct, SubscriptionApiGeneralResponseStruct, SubscriptionBenefitsResponseStruct, SubscriptionEligibilityArrayStruct, SubscriptionStruct, UpdatePaymentMethodCardResponseStruct, } from './SubscriptionService-structs.js';
|
|
8
|
+
import { CRYPTO_AUTH_METHODS } from './types.js';
|
|
21
9
|
export const serviceName = 'SubscriptionService';
|
|
22
10
|
export const SUBSCRIPTION_URL = (env, path) => `${getEnvUrls(env).subscriptionApiUrl}/v1/${path}`;
|
|
23
11
|
const MESSENGER_EXPOSED_METHODS = [
|
|
24
12
|
'getSubscriptions',
|
|
13
|
+
'getBenefits',
|
|
25
14
|
'cancelSubscription',
|
|
26
15
|
'unCancelSubscription',
|
|
27
16
|
'startSubscriptionWithCard',
|
|
@@ -58,6 +47,9 @@ const DEFAULT_POLICY_OPTIONS = {
|
|
|
58
47
|
* `AuthenticationController:getSessionProfile`.
|
|
59
48
|
*/
|
|
60
49
|
export class SubscriptionService extends BaseDataService {
|
|
50
|
+
#env;
|
|
51
|
+
#fetch;
|
|
52
|
+
#captureException;
|
|
61
53
|
constructor({ messenger, fetchFunction = globalThis.fetch, env = Env.PRD, captureException, queryClientConfig = {}, policyOptions = {}, }) {
|
|
62
54
|
super({
|
|
63
55
|
name: serviceName,
|
|
@@ -65,13 +57,9 @@ export class SubscriptionService extends BaseDataService {
|
|
|
65
57
|
queryClientConfig,
|
|
66
58
|
policyOptions: { ...DEFAULT_POLICY_OPTIONS, ...policyOptions },
|
|
67
59
|
});
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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");
|
|
60
|
+
this.#env = env;
|
|
61
|
+
this.#fetch = fetchFunction;
|
|
62
|
+
this.#captureException = captureException;
|
|
75
63
|
this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
|
|
76
64
|
}
|
|
77
65
|
/**
|
|
@@ -80,8 +68,8 @@ export class SubscriptionService extends BaseDataService {
|
|
|
80
68
|
* @returns The subscriptions response.
|
|
81
69
|
*/
|
|
82
70
|
async getSubscriptions() {
|
|
83
|
-
const { profileKey, bearerToken } = await
|
|
84
|
-
const jsonResponse = await
|
|
71
|
+
const { profileKey, bearerToken } = await this.#getAuthenticatedContext();
|
|
72
|
+
const jsonResponse = await this.#fetchJson({
|
|
85
73
|
profileKey,
|
|
86
74
|
bearerToken,
|
|
87
75
|
methodName: 'getSubscriptions',
|
|
@@ -91,6 +79,25 @@ export class SubscriptionService extends BaseDataService {
|
|
|
91
79
|
});
|
|
92
80
|
return create(jsonResponse, GetSubscriptionsResponseStruct);
|
|
93
81
|
}
|
|
82
|
+
/**
|
|
83
|
+
* Fetches the user's subscription benefits.
|
|
84
|
+
*
|
|
85
|
+
* @returns The benefits response.
|
|
86
|
+
*/
|
|
87
|
+
async getBenefits() {
|
|
88
|
+
const { profileKey, bearerToken } = await this.#getAuthenticatedContext();
|
|
89
|
+
const jsonResponse = await this.#fetchJson({
|
|
90
|
+
profileKey,
|
|
91
|
+
bearerToken,
|
|
92
|
+
methodName: 'getBenefits',
|
|
93
|
+
requestParams: null,
|
|
94
|
+
path: 'benefits',
|
|
95
|
+
method: 'POST',
|
|
96
|
+
body: {},
|
|
97
|
+
errorMessage: SubscriptionServiceErrorMessage.FailedToGetBenefits,
|
|
98
|
+
});
|
|
99
|
+
return create(jsonResponse, SubscriptionBenefitsResponseStruct);
|
|
100
|
+
}
|
|
94
101
|
/**
|
|
95
102
|
* Cancels a subscription.
|
|
96
103
|
*
|
|
@@ -98,9 +105,9 @@ export class SubscriptionService extends BaseDataService {
|
|
|
98
105
|
* @returns The updated subscription.
|
|
99
106
|
*/
|
|
100
107
|
async cancelSubscription(params) {
|
|
101
|
-
const { profileKey, bearerToken } = await
|
|
108
|
+
const { profileKey, bearerToken } = await this.#getAuthenticatedContext();
|
|
102
109
|
const path = `subscriptions/${params.subscriptionId}/cancel`;
|
|
103
|
-
const jsonResponse = await
|
|
110
|
+
const jsonResponse = await this.#fetchJson({
|
|
104
111
|
profileKey,
|
|
105
112
|
bearerToken,
|
|
106
113
|
methodName: 'cancelSubscription',
|
|
@@ -122,9 +129,9 @@ export class SubscriptionService extends BaseDataService {
|
|
|
122
129
|
* @returns The updated subscription.
|
|
123
130
|
*/
|
|
124
131
|
async unCancelSubscription(params) {
|
|
125
|
-
const { profileKey, bearerToken } = await
|
|
132
|
+
const { profileKey, bearerToken } = await this.#getAuthenticatedContext();
|
|
126
133
|
const path = `subscriptions/${params.subscriptionId}/uncancel`;
|
|
127
|
-
const jsonResponse = await
|
|
134
|
+
const jsonResponse = await this.#fetchJson({
|
|
128
135
|
profileKey,
|
|
129
136
|
bearerToken,
|
|
130
137
|
methodName: 'unCancelSubscription',
|
|
@@ -147,8 +154,8 @@ export class SubscriptionService extends BaseDataService {
|
|
|
147
154
|
if (request.products.length === 0) {
|
|
148
155
|
throw new SubscriptionServiceError(SubscriptionControllerErrorMessage.SubscriptionProductsEmpty);
|
|
149
156
|
}
|
|
150
|
-
const { profileKey, bearerToken } = await
|
|
151
|
-
const jsonResponse = await
|
|
157
|
+
const { profileKey, bearerToken } = await this.#getAuthenticatedContext();
|
|
158
|
+
const jsonResponse = await this.#fetchJson({
|
|
152
159
|
profileKey,
|
|
153
160
|
bearerToken,
|
|
154
161
|
methodName: 'startSubscriptionWithCard',
|
|
@@ -173,9 +180,9 @@ export class SubscriptionService extends BaseDataService {
|
|
|
173
180
|
if (request.products.length === 0) {
|
|
174
181
|
throw new SubscriptionServiceError(SubscriptionControllerErrorMessage.SubscriptionProductsEmpty);
|
|
175
182
|
}
|
|
176
|
-
|
|
177
|
-
const { profileKey, bearerToken } = await
|
|
178
|
-
const jsonResponse = await
|
|
183
|
+
this.#assertValidCryptoAuthCombo(request);
|
|
184
|
+
const { profileKey, bearerToken } = await this.#getAuthenticatedContext();
|
|
185
|
+
const jsonResponse = await this.#fetchJson({
|
|
179
186
|
profileKey,
|
|
180
187
|
bearerToken,
|
|
181
188
|
methodName: 'startSubscriptionWithCrypto',
|
|
@@ -194,9 +201,9 @@ export class SubscriptionService extends BaseDataService {
|
|
|
194
201
|
* @returns The redirect URL response.
|
|
195
202
|
*/
|
|
196
203
|
async updatePaymentMethodCard(request) {
|
|
197
|
-
const { profileKey, bearerToken } = await
|
|
204
|
+
const { profileKey, bearerToken } = await this.#getAuthenticatedContext();
|
|
198
205
|
const path = `subscriptions/${request.subscriptionId}/payment-method/card`;
|
|
199
|
-
const jsonResponse = await
|
|
206
|
+
const jsonResponse = await this.#fetchJson({
|
|
200
207
|
profileKey,
|
|
201
208
|
bearerToken,
|
|
202
209
|
methodName: 'updatePaymentMethodCard',
|
|
@@ -217,9 +224,9 @@ export class SubscriptionService extends BaseDataService {
|
|
|
217
224
|
* @param request - The update payment method request.
|
|
218
225
|
*/
|
|
219
226
|
async updatePaymentMethodCrypto(request) {
|
|
220
|
-
const { profileKey, bearerToken } = await
|
|
227
|
+
const { profileKey, bearerToken } = await this.#getAuthenticatedContext();
|
|
221
228
|
const path = `subscriptions/${request.subscriptionId}/payment-method/crypto`;
|
|
222
|
-
await
|
|
229
|
+
await this.#fetchJson({
|
|
223
230
|
profileKey,
|
|
224
231
|
bearerToken,
|
|
225
232
|
methodName: 'updatePaymentMethodCrypto',
|
|
@@ -240,12 +247,12 @@ export class SubscriptionService extends BaseDataService {
|
|
|
240
247
|
* @returns The eligibility for a shield subscription
|
|
241
248
|
*/
|
|
242
249
|
async getSubscriptionsEligibilities(request) {
|
|
243
|
-
const { profileKey, bearerToken } = await
|
|
250
|
+
const { profileKey, bearerToken } = await this.#getAuthenticatedContext();
|
|
244
251
|
let queryParams;
|
|
245
252
|
if (request?.balanceCategory !== undefined) {
|
|
246
253
|
queryParams = { balanceCategory: request.balanceCategory };
|
|
247
254
|
}
|
|
248
|
-
const jsonResponse = await
|
|
255
|
+
const jsonResponse = await this.#fetchJson({
|
|
249
256
|
profileKey,
|
|
250
257
|
bearerToken,
|
|
251
258
|
methodName: 'getSubscriptionsEligibilities',
|
|
@@ -271,8 +278,8 @@ export class SubscriptionService extends BaseDataService {
|
|
|
271
278
|
* @example { event: SubscriptionUserEvent.ShieldEntryModalViewed, cohort: 'post_tx' }
|
|
272
279
|
*/
|
|
273
280
|
async submitUserEvent(request) {
|
|
274
|
-
const { profileKey, bearerToken } = await
|
|
275
|
-
await
|
|
281
|
+
const { profileKey, bearerToken } = await this.#getAuthenticatedContext();
|
|
282
|
+
await this.#fetchJson({
|
|
276
283
|
profileKey,
|
|
277
284
|
bearerToken,
|
|
278
285
|
methodName: 'submitUserEvent',
|
|
@@ -290,8 +297,8 @@ export class SubscriptionService extends BaseDataService {
|
|
|
290
297
|
* @example { cohort: 'post_tx' }
|
|
291
298
|
*/
|
|
292
299
|
async assignUserToCohort(request) {
|
|
293
|
-
const { profileKey, bearerToken } = await
|
|
294
|
-
await
|
|
300
|
+
const { profileKey, bearerToken } = await this.#getAuthenticatedContext();
|
|
301
|
+
await this.#fetchJson({
|
|
295
302
|
profileKey,
|
|
296
303
|
bearerToken,
|
|
297
304
|
methodName: 'assignUserToCohort',
|
|
@@ -312,8 +319,8 @@ export class SubscriptionService extends BaseDataService {
|
|
|
312
319
|
* @example { address: '0x1234567890123456789012345678901234567890', products: [ProductType.Shield] }
|
|
313
320
|
*/
|
|
314
321
|
async submitSponsorshipIntents(request) {
|
|
315
|
-
const { profileKey, bearerToken } = await
|
|
316
|
-
await
|
|
322
|
+
const { profileKey, bearerToken } = await this.#getAuthenticatedContext();
|
|
323
|
+
await this.#fetchJson({
|
|
317
324
|
profileKey,
|
|
318
325
|
bearerToken,
|
|
319
326
|
methodName: 'submitSponsorshipIntents',
|
|
@@ -332,8 +339,8 @@ export class SubscriptionService extends BaseDataService {
|
|
|
332
339
|
* @returns The response from the API.
|
|
333
340
|
*/
|
|
334
341
|
async linkRewards(request) {
|
|
335
|
-
const { profileKey, bearerToken } = await
|
|
336
|
-
const jsonResponse = await
|
|
342
|
+
const { profileKey, bearerToken } = await this.#getAuthenticatedContext();
|
|
343
|
+
const jsonResponse = await this.#fetchJson({
|
|
337
344
|
profileKey,
|
|
338
345
|
bearerToken,
|
|
339
346
|
methodName: 'linkRewards',
|
|
@@ -351,8 +358,8 @@ export class SubscriptionService extends BaseDataService {
|
|
|
351
358
|
* @returns The pricing response.
|
|
352
359
|
*/
|
|
353
360
|
async getPricing() {
|
|
354
|
-
const { profileKey, bearerToken } = await
|
|
355
|
-
const jsonResponse = await
|
|
361
|
+
const { profileKey, bearerToken } = await this.#getAuthenticatedContext();
|
|
362
|
+
const jsonResponse = await this.#fetchJson({
|
|
356
363
|
profileKey,
|
|
357
364
|
bearerToken,
|
|
358
365
|
methodName: 'getPricing',
|
|
@@ -368,8 +375,8 @@ export class SubscriptionService extends BaseDataService {
|
|
|
368
375
|
* @returns The billing portal response.
|
|
369
376
|
*/
|
|
370
377
|
async getBillingPortalUrl() {
|
|
371
|
-
const { profileKey, bearerToken } = await
|
|
372
|
-
const jsonResponse = await
|
|
378
|
+
const { profileKey, bearerToken } = await this.#getAuthenticatedContext();
|
|
379
|
+
const jsonResponse = await this.#fetchJson({
|
|
373
380
|
profileKey,
|
|
374
381
|
bearerToken,
|
|
375
382
|
methodName: 'getBillingPortalUrl',
|
|
@@ -379,94 +386,105 @@ export class SubscriptionService extends BaseDataService {
|
|
|
379
386
|
});
|
|
380
387
|
return create(jsonResponse, BillingPortalResponseStruct);
|
|
381
388
|
}
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
389
|
+
async #fetchJson({ profileKey, bearerToken, methodName, requestParams, path, method = 'GET', body, queryParams, errorMessage, }) {
|
|
390
|
+
const url = this.#getSubscriptionApiUrl(path);
|
|
391
|
+
if (queryParams) {
|
|
392
|
+
Object.entries(queryParams).forEach(([key, value]) => {
|
|
393
|
+
url.searchParams.append(key, value);
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
try {
|
|
397
|
+
return await this.fetchQuery({
|
|
398
|
+
queryKey: [
|
|
399
|
+
`${this.name}:${methodName}`,
|
|
400
|
+
profileKey,
|
|
401
|
+
requestParams,
|
|
402
|
+
],
|
|
403
|
+
staleTime: 0,
|
|
404
|
+
gcTime: 0,
|
|
405
|
+
queryFn: async () => {
|
|
406
|
+
const response = await this.#fetch(url.toString(), {
|
|
407
|
+
method,
|
|
408
|
+
headers: {
|
|
409
|
+
'Content-Type': 'application/json',
|
|
410
|
+
...this.#headersForToken(bearerToken),
|
|
411
|
+
},
|
|
412
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
413
|
+
});
|
|
414
|
+
if (!response.ok) {
|
|
415
|
+
const apiError = await getSubscriptionErrorFromResponse(response);
|
|
416
|
+
throw new HttpError(response.status, apiError.message);
|
|
417
|
+
}
|
|
418
|
+
return response.json();
|
|
419
|
+
},
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
catch (error) {
|
|
423
|
+
log(errorMessage, error);
|
|
424
|
+
const errorMessageWithUrl = `${errorMessage} (url: ${url.toString()})`;
|
|
425
|
+
const errorToCapture = error instanceof Error ? error : new Error(errorMessage);
|
|
426
|
+
this.#captureException?.(createSentryError(errorMessageWithUrl, errorToCapture));
|
|
427
|
+
if (error instanceof SubscriptionServiceError) {
|
|
428
|
+
throw error;
|
|
429
|
+
}
|
|
430
|
+
throw new SubscriptionServiceError(`Failed to make request. ${errorMessageWithUrl}`, {
|
|
431
|
+
cause: errorToCapture,
|
|
432
|
+
});
|
|
423
433
|
}
|
|
424
|
-
throw new SubscriptionServiceError(`Failed to make request. ${errorMessageWithUrl}`, {
|
|
425
|
-
cause: errorToCapture,
|
|
426
|
-
});
|
|
427
|
-
}
|
|
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);
|
|
440
434
|
}
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
435
|
+
/**
|
|
436
|
+
* Ensures the request uses exactly one crypto auth method: ERC-20 approval
|
|
437
|
+
* (`rawTransaction`, default) or delegation (`delegationHash`).
|
|
438
|
+
*
|
|
439
|
+
* @param request - The start crypto subscription request.
|
|
440
|
+
* @throws If both, neither, or a mismatched combo of auth fields is provided.
|
|
441
|
+
*/
|
|
442
|
+
#assertValidCryptoAuthCombo(request) {
|
|
443
|
+
const method = request.cryptoAuthMethod ?? CRYPTO_AUTH_METHODS.ERC20_APPROVAL;
|
|
444
|
+
const hasRawTransaction = Boolean(request.rawTransaction);
|
|
445
|
+
const hasDelegationHash = Boolean(request.delegationHash);
|
|
446
|
+
const isValidErc20Approval = method === CRYPTO_AUTH_METHODS.ERC20_APPROVAL &&
|
|
447
|
+
hasRawTransaction &&
|
|
448
|
+
!hasDelegationHash;
|
|
449
|
+
const isValidDelegation = method === CRYPTO_AUTH_METHODS.DELEGATION &&
|
|
450
|
+
hasDelegationHash &&
|
|
451
|
+
!hasRawTransaction;
|
|
452
|
+
if (!isValidErc20Approval && !isValidDelegation) {
|
|
453
|
+
throw new SubscriptionServiceError(SubscriptionServiceErrorMessage.InvalidCryptoAuthCombo);
|
|
454
|
+
}
|
|
448
455
|
}
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
}
|
|
456
|
+
async #getAuthenticatedContext() {
|
|
457
|
+
try {
|
|
458
|
+
const [bearerToken, sessionProfile] = await Promise.all([
|
|
459
|
+
this.messenger.call('AuthenticationController:getBearerToken'),
|
|
460
|
+
this.messenger.call('AuthenticationController:getSessionProfile'),
|
|
461
|
+
]);
|
|
462
|
+
return { profileKey: sessionProfile.profileId, bearerToken };
|
|
463
|
+
}
|
|
464
|
+
catch (error) {
|
|
465
|
+
const errorMessage = error instanceof Error
|
|
466
|
+
? error.message
|
|
467
|
+
: 'Unknown error when getting authorization header';
|
|
468
|
+
this.#captureException?.(createSentryError(`Failed to get authorization header. ${errorMessage}`, error instanceof Error ? error : new Error(errorMessage)));
|
|
469
|
+
throw new SubscriptionServiceError(`Failed to get authorization header. ${errorMessage}`, {
|
|
470
|
+
cause: error instanceof Error ? error : new Error(errorMessage),
|
|
471
|
+
});
|
|
472
|
+
}
|
|
457
473
|
}
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
}, _SubscriptionService_getSubscriptionApiUrl = function _SubscriptionService_getSubscriptionApiUrl(path) {
|
|
461
|
-
try {
|
|
462
|
-
return new URL(SUBSCRIPTION_URL(__classPrivateFieldGet(this, _SubscriptionService_env, "f"), path));
|
|
474
|
+
#headersForToken(bearerToken) {
|
|
475
|
+
return { Authorization: `Bearer ${bearerToken}` };
|
|
463
476
|
}
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
477
|
+
#getSubscriptionApiUrl(path) {
|
|
478
|
+
try {
|
|
479
|
+
return new URL(SUBSCRIPTION_URL(this.#env, path));
|
|
480
|
+
}
|
|
481
|
+
catch (error) {
|
|
482
|
+
const errorMessage = error instanceof Error
|
|
483
|
+
? error.message
|
|
484
|
+
: 'Unknown error when getting subscription API URL';
|
|
485
|
+
this.#captureException?.(createSentryError(`Failed to get subscription API URL. ${errorMessage}`, error instanceof Error ? error : new Error(errorMessage)));
|
|
486
|
+
throw error;
|
|
487
|
+
}
|
|
470
488
|
}
|
|
471
|
-
}
|
|
472
|
-
//# sourceMappingURL=SubscriptionService.
|
|
489
|
+
}
|
|
490
|
+
//# sourceMappingURL=SubscriptionService.js.map
|