@extenshi/pay 0.7.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/LICENSE +21 -0
- package/README.md +260 -0
- package/dist/api/mock.d.ts +35 -0
- package/dist/api/mock.d.ts.map +1 -0
- package/dist/api/pay-api.d.ts +16 -0
- package/dist/api/pay-api.d.ts.map +1 -0
- package/dist/api/transport.d.ts +52 -0
- package/dist/api/transport.d.ts.map +1 -0
- package/dist/core/config.d.ts +5 -0
- package/dist/core/config.d.ts.map +1 -0
- package/dist/core/event-emitter.d.ts +10 -0
- package/dist/core/event-emitter.d.ts.map +1 -0
- package/dist/core/extenshi-pay.d.ts +90 -0
- package/dist/core/extenshi-pay.d.ts.map +1 -0
- package/dist/core/identity.d.ts +13 -0
- package/dist/core/identity.d.ts.map +1 -0
- package/dist/core/index.d.ts +25 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/storage.d.ts +42 -0
- package/dist/core/storage.d.ts.map +1 -0
- package/dist/core.d.mts +821 -0
- package/dist/core.d.ts +821 -0
- package/dist/core.esm.js +1681 -0
- package/dist/core.esm.js.map +1 -0
- package/dist/core.js +1806 -0
- package/dist/core.js.map +1 -0
- package/dist/core.mjs +1744 -0
- package/dist/core.mjs.map +1 -0
- package/dist/extenshi-pay-lite.esm.js +1664 -0
- package/dist/extenshi-pay-lite.esm.js.map +1 -0
- package/dist/extenshi-pay-lite.js +1743 -0
- package/dist/extenshi-pay-lite.js.map +1 -0
- package/dist/extenshi-pay-lite.min.js +7 -0
- package/dist/extenshi-pay-lite.min.js.map +1 -0
- package/dist/extenshi-pay-lite.mjs +1727 -0
- package/dist/extenshi-pay-lite.mjs.map +1 -0
- package/dist/extenshi-pay.cjs.js +2632 -0
- package/dist/extenshi-pay.cjs.js.map +1 -0
- package/dist/extenshi-pay.d.ts +32 -0
- package/dist/extenshi-pay.d.ts.map +1 -0
- package/dist/extenshi-pay.esm.js +2496 -0
- package/dist/extenshi-pay.esm.js.map +1 -0
- package/dist/extenshi-pay.esm.min.js +7 -0
- package/dist/extenshi-pay.esm.min.js.map +1 -0
- package/dist/extenshi-pay.js +2638 -0
- package/dist/extenshi-pay.js.map +1 -0
- package/dist/extenshi-pay.min.js +7 -0
- package/dist/extenshi-pay.min.js.map +1 -0
- package/dist/extenshi-pay.min.mjs +7 -0
- package/dist/extenshi-pay.min.mjs.map +1 -0
- package/dist/extenshi-pay.mjs +2559 -0
- package/dist/extenshi-pay.mjs.map +1 -0
- package/dist/index.d.mts +937 -0
- package/dist/index.d.ts +937 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/lite.d.mts +659 -0
- package/dist/lite.d.ts +659 -0
- package/dist/lite.d.ts.map +1 -0
- package/dist/payment/checkout.d.ts +47 -0
- package/dist/payment/checkout.d.ts.map +1 -0
- package/dist/payment/entitlement.d.ts +76 -0
- package/dist/payment/entitlement.d.ts.map +1 -0
- package/dist/payment/features.d.ts +12 -0
- package/dist/payment/features.d.ts.map +1 -0
- package/dist/payment/recovery.d.ts +29 -0
- package/dist/payment/recovery.d.ts.map +1 -0
- package/dist/payment/signature.d.ts +12 -0
- package/dist/payment/signature.d.ts.map +1 -0
- package/dist/paywall/billing-profile-picker.d.ts +8 -0
- package/dist/paywall/billing-profile-picker.d.ts.map +1 -0
- package/dist/paywall/format.d.ts +13 -0
- package/dist/paywall/format.d.ts.map +1 -0
- package/dist/paywall/index.d.ts +9 -0
- package/dist/paywall/index.d.ts.map +1 -0
- package/dist/paywall/license-panel.d.ts +10 -0
- package/dist/paywall/license-panel.d.ts.map +1 -0
- package/dist/paywall/renderer.d.ts +55 -0
- package/dist/paywall/renderer.d.ts.map +1 -0
- package/dist/paywall/seller-details.d.ts +5 -0
- package/dist/paywall/seller-details.d.ts.map +1 -0
- package/dist/paywall/strings.d.ts +10 -0
- package/dist/paywall/strings.d.ts.map +1 -0
- package/dist/paywall/templates.d.ts +14 -0
- package/dist/paywall/templates.d.ts.map +1 -0
- package/dist/paywall.d.mts +160 -0
- package/dist/paywall.d.ts +160 -0
- package/dist/paywall.esm.js +442 -0
- package/dist/paywall.esm.js.map +1 -0
- package/dist/paywall.js +462 -0
- package/dist/paywall.js.map +1 -0
- package/dist/paywall.mjs +442 -0
- package/dist/paywall.mjs.map +1 -0
- package/dist/types/config.d.ts +62 -0
- package/dist/types/config.d.ts.map +1 -0
- package/dist/types/contract.d.ts +172 -0
- package/dist/types/contract.d.ts.map +1 -0
- package/dist/types/entitlement.d.ts +71 -0
- package/dist/types/entitlement.d.ts.map +1 -0
- package/dist/types/errors.d.ts +31 -0
- package/dist/types/errors.d.ts.map +1 -0
- package/dist/types/events.d.ts +29 -0
- package/dist/types/events.d.ts.map +1 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/paywall.d.ts +37 -0
- package/dist/types/paywall.d.ts.map +1 -0
- package/dist/utils/logger.d.ts +16 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/version.d.ts +3 -0
- package/dist/version.d.ts.map +1 -0
- package/package.json +115 -0
package/dist/lite.d.ts
ADDED
|
@@ -0,0 +1,659 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wire contract between the SDK and catalog-bff `pay.*`.
|
|
3
|
+
*
|
|
4
|
+
* SOURCE OF TRUTH: `shared-types/pay.ts` in the extenshi.io monorepo. The SDK
|
|
5
|
+
* ships with zero runtime dependencies and must not import that workspace, so
|
|
6
|
+
* the types and constants it needs are copied here under identical names.
|
|
7
|
+
* `canonicalJson` is copied VERBATIM: the BFF signs its output and the SDK
|
|
8
|
+
* verifies it, so both sides must produce byte-identical strings
|
|
9
|
+
* (pinned by tests/unit/canonical-json.test.ts). When `shared-types/pay.ts`
|
|
10
|
+
* changes, mirror the change here.
|
|
11
|
+
*/
|
|
12
|
+
/** Bumped only when an older SDK could misread the response. */
|
|
13
|
+
declare const PAY_CONTRACT_VERSION = 1;
|
|
14
|
+
declare const PAY_GATEWAYS: readonly ["stripe", "paddle", "lemonsqueezy"];
|
|
15
|
+
type PayGatewayId = (typeof PAY_GATEWAYS)[number];
|
|
16
|
+
declare const PAY_OFFER_KINDS: readonly ["one_time", "subscription", "lifetime"];
|
|
17
|
+
type PayOfferKind = (typeof PAY_OFFER_KINDS)[number];
|
|
18
|
+
declare const PAY_OFFER_INTERVALS: readonly ["month", "year"];
|
|
19
|
+
type PayOfferInterval = (typeof PAY_OFFER_INTERVALS)[number];
|
|
20
|
+
/** ISO-4217 lowercase, matching what every gateway returns. */
|
|
21
|
+
declare const PAY_CURRENCIES: readonly ["usd", "eur", "gbp"];
|
|
22
|
+
type PayCurrency = (typeof PAY_CURRENCIES)[number];
|
|
23
|
+
/**
|
|
24
|
+
* active — paid and not expired
|
|
25
|
+
* grace — subscription past_due: keep access for a short window so a card
|
|
26
|
+
* hiccup does not lock a paying user out mid-session
|
|
27
|
+
* expired — was active, no longer is
|
|
28
|
+
* none — never had it
|
|
29
|
+
*/
|
|
30
|
+
declare const PAY_ENTITLEMENT_STATUSES: readonly ["active", "grace", "expired", "none"];
|
|
31
|
+
type PayEntitlementStatus = (typeof PAY_ENTITLEMENT_STATUSES)[number];
|
|
32
|
+
interface PayOfferDto {
|
|
33
|
+
sku: string;
|
|
34
|
+
kind: PayOfferKind;
|
|
35
|
+
interval: PayOfferInterval | null;
|
|
36
|
+
amountMinor: number;
|
|
37
|
+
currency: PayCurrency;
|
|
38
|
+
title: string;
|
|
39
|
+
description: string | null;
|
|
40
|
+
features: string[];
|
|
41
|
+
}
|
|
42
|
+
interface PayOfferResponse {
|
|
43
|
+
/** Optional during rolling upgrades; never infer this from the project name. */
|
|
44
|
+
seller?: PaySellerPublic | null;
|
|
45
|
+
v: typeof PAY_CONTRACT_VERSION;
|
|
46
|
+
projectName: string;
|
|
47
|
+
provider: PayGatewayId;
|
|
48
|
+
/** False while the seller cannot take money; the SDK renders the offer read-only. */
|
|
49
|
+
checkoutEnabled: boolean;
|
|
50
|
+
/** Optional for older servers; show recovery only when explicitly enabled. */
|
|
51
|
+
recoveryEnabled?: boolean;
|
|
52
|
+
offers: PayOfferDto[];
|
|
53
|
+
/** Base64 Ed25519 public key for `SignedEntitlement.signature`; null when unsigned. */
|
|
54
|
+
entitlementPublicKey: string | null;
|
|
55
|
+
}
|
|
56
|
+
interface PayEntitlementItem {
|
|
57
|
+
/** Optional for old signed caches and older servers. */
|
|
58
|
+
title?: string;
|
|
59
|
+
kind?: PayOfferKind;
|
|
60
|
+
subscriptions?: Array<{
|
|
61
|
+
status: string;
|
|
62
|
+
cancelAtPeriodEnd: boolean;
|
|
63
|
+
currentPeriodEnd: string | null;
|
|
64
|
+
}>;
|
|
65
|
+
sku: string;
|
|
66
|
+
status: PayEntitlementStatus;
|
|
67
|
+
/** ISO timestamp; null for lifetime / one-time grants. */
|
|
68
|
+
expiresAt: string | null;
|
|
69
|
+
features: string[];
|
|
70
|
+
}
|
|
71
|
+
interface PayEntitlementPayload {
|
|
72
|
+
v: typeof PAY_CONTRACT_VERSION;
|
|
73
|
+
/** Signed application scope; prevents moving a grant to another application. */
|
|
74
|
+
publishableKey: string;
|
|
75
|
+
endUserRef: string;
|
|
76
|
+
entitlements: PayEntitlementItem[];
|
|
77
|
+
/** ISO timestamp the projection was computed at; the SDK uses it for cache age. */
|
|
78
|
+
issuedAt: string;
|
|
79
|
+
}
|
|
80
|
+
interface SignedEntitlement {
|
|
81
|
+
payload: PayEntitlementPayload;
|
|
82
|
+
/** Base64 Ed25519 signature over the canonical JSON of `payload`; null when the server has no key. */
|
|
83
|
+
signature: string | null;
|
|
84
|
+
alg: 'ed25519' | null;
|
|
85
|
+
}
|
|
86
|
+
type PayCheckoutClaim = {
|
|
87
|
+
state: 'pending';
|
|
88
|
+
} | {
|
|
89
|
+
state: 'complete';
|
|
90
|
+
entitlement: SignedEntitlement;
|
|
91
|
+
} | {
|
|
92
|
+
state: 'expired';
|
|
93
|
+
} | {
|
|
94
|
+
state: 'canceled';
|
|
95
|
+
};
|
|
96
|
+
interface PayCheckoutSession {
|
|
97
|
+
url: string;
|
|
98
|
+
sessionId: string;
|
|
99
|
+
/** ISO timestamp. */
|
|
100
|
+
expiresAt: string;
|
|
101
|
+
}
|
|
102
|
+
interface PayRestoreSessionResponse {
|
|
103
|
+
sessionId: string;
|
|
104
|
+
expiresAt: string;
|
|
105
|
+
url: string;
|
|
106
|
+
}
|
|
107
|
+
type PayRestoreClaimResponse = {
|
|
108
|
+
state: 'pending';
|
|
109
|
+
} | {
|
|
110
|
+
state: 'complete';
|
|
111
|
+
endUserRef: string;
|
|
112
|
+
entitlement: SignedEntitlement;
|
|
113
|
+
};
|
|
114
|
+
/** A project-scoped billing profile; provider identifiers are never exposed. */
|
|
115
|
+
interface PayPortalAccount {
|
|
116
|
+
id: string;
|
|
117
|
+
label: string;
|
|
118
|
+
createdAt: string;
|
|
119
|
+
subscriptions: Array<{
|
|
120
|
+
title: string;
|
|
121
|
+
status: string;
|
|
122
|
+
cancelAtPeriodEnd: boolean;
|
|
123
|
+
currentPeriodEnd: string | null;
|
|
124
|
+
}>;
|
|
125
|
+
}
|
|
126
|
+
interface PayPortalResponse {
|
|
127
|
+
url: string | null;
|
|
128
|
+
/** Present when the buyer must choose among multiple billing profiles. */
|
|
129
|
+
accounts?: PayPortalAccount[];
|
|
130
|
+
}
|
|
131
|
+
/** Public author-provided contact details. Not a claim of identity verification. */
|
|
132
|
+
interface PaySellerPublic {
|
|
133
|
+
displayName: string;
|
|
134
|
+
/** HTTPS support page or plain email address. */
|
|
135
|
+
supportUrl: string;
|
|
136
|
+
termsUrl: string | null;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
declare const ERROR_CODES: {
|
|
140
|
+
readonly INVALID_CONFIG: "INVALID_CONFIG";
|
|
141
|
+
readonly INVALID_REQUEST: "INVALID_REQUEST";
|
|
142
|
+
readonly NETWORK_ERROR: "NETWORK_ERROR";
|
|
143
|
+
readonly TIMEOUT: "TIMEOUT";
|
|
144
|
+
readonly VERIFICATION_UNAVAILABLE: "VERIFICATION_UNAVAILABLE";
|
|
145
|
+
readonly INVALID_RESPONSE: "INVALID_RESPONSE";
|
|
146
|
+
readonly RATE_LIMITED: "RATE_LIMITED";
|
|
147
|
+
readonly INVALID_KEY: "INVALID_KEY";
|
|
148
|
+
readonly SELLER_NOT_ACTIVE: "SELLER_NOT_ACTIVE";
|
|
149
|
+
readonly OFFER_NOT_FOUND: "OFFER_NOT_FOUND";
|
|
150
|
+
readonly GATEWAY_UNAVAILABLE: "GATEWAY_UNAVAILABLE";
|
|
151
|
+
readonly CHECKOUT_UNAVAILABLE: "CHECKOUT_UNAVAILABLE";
|
|
152
|
+
readonly PAYWALL_UNAVAILABLE: "PAYWALL_UNAVAILABLE";
|
|
153
|
+
readonly UNKNOWN: "UNKNOWN";
|
|
154
|
+
};
|
|
155
|
+
type ErrorCode = (typeof ERROR_CODES)[keyof typeof ERROR_CODES];
|
|
156
|
+
interface ExtenshiPayErrorOptions {
|
|
157
|
+
retryAfterSec?: number;
|
|
158
|
+
httpStatus?: number;
|
|
159
|
+
cause?: unknown;
|
|
160
|
+
}
|
|
161
|
+
declare class ExtenshiPayError extends Error {
|
|
162
|
+
readonly code: ErrorCode;
|
|
163
|
+
readonly retryAfterSec: number | undefined;
|
|
164
|
+
readonly httpStatus: number | undefined;
|
|
165
|
+
readonly cause: unknown;
|
|
166
|
+
constructor(code: ErrorCode, message: string, options?: ExtenshiPayErrorOptions);
|
|
167
|
+
static from(error: unknown, fallback?: ErrorCode): ExtenshiPayError;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
type LogLevel = 'silent' | 'error' | 'warn' | 'info' | 'debug';
|
|
171
|
+
/** Reserved for future routing; today every environment talks to the same BFF. */
|
|
172
|
+
type Environment = 'production' | 'sandbox' | 'development';
|
|
173
|
+
interface ThemeConfig {
|
|
174
|
+
/** `auto` follows `prefers-color-scheme`. */
|
|
175
|
+
mode?: 'light' | 'dark' | 'auto';
|
|
176
|
+
primaryColor?: string;
|
|
177
|
+
fontFamily?: string;
|
|
178
|
+
borderRadius?: string;
|
|
179
|
+
/** Appended verbatim inside the paywall's shadow root. */
|
|
180
|
+
customCss?: string;
|
|
181
|
+
}
|
|
182
|
+
/** Offline development data used when `mock: true`. */
|
|
183
|
+
interface MockData {
|
|
184
|
+
entitlements?: PayEntitlementItem[];
|
|
185
|
+
offers?: PayOfferDto[];
|
|
186
|
+
projectName?: string;
|
|
187
|
+
/** Defaults to true. */
|
|
188
|
+
checkoutEnabled?: boolean;
|
|
189
|
+
/** How many `claimSession` polls answer `pending` before a mock checkout completes (default 1). */
|
|
190
|
+
claimAfterPolls?: number;
|
|
191
|
+
}
|
|
192
|
+
interface ExtenshiPayConfig {
|
|
193
|
+
/** `pk_ext_` + 32 hex characters, from the project's Monetization tab. */
|
|
194
|
+
publishableKey: string;
|
|
195
|
+
/** Defaults to `https://bff.extenshi.io`. */
|
|
196
|
+
apiUrl?: string;
|
|
197
|
+
/** Bundled raw Ed25519 public key (base64). Enables verified cache use after an offline restart. */
|
|
198
|
+
entitlementPublicKey?: string;
|
|
199
|
+
environment?: Environment;
|
|
200
|
+
/** Shorthand for `logLevel: 'debug'`. */
|
|
201
|
+
debug?: boolean;
|
|
202
|
+
logLevel?: LogLevel;
|
|
203
|
+
/** How long a fetched entitlement is served without a network round-trip (default 1 hour). */
|
|
204
|
+
cacheTtlMs?: number;
|
|
205
|
+
/** BCP-47 tag such as `en` or `de-DE`; sent to the backend for checkout/offer copy and used for price formatting. */
|
|
206
|
+
locale?: string;
|
|
207
|
+
mock?: boolean;
|
|
208
|
+
mockData?: MockData;
|
|
209
|
+
onReady?: () => void;
|
|
210
|
+
onError?: (error: ExtenshiPayError) => void;
|
|
211
|
+
theme?: ThemeConfig;
|
|
212
|
+
}
|
|
213
|
+
interface ResolvedConfig {
|
|
214
|
+
publishableKey: string;
|
|
215
|
+
apiUrl: string;
|
|
216
|
+
entitlementPublicKey: string | null;
|
|
217
|
+
environment: Environment;
|
|
218
|
+
debug: boolean;
|
|
219
|
+
logLevel: LogLevel;
|
|
220
|
+
cacheTtlMs: number;
|
|
221
|
+
locale: string | null;
|
|
222
|
+
mock: boolean;
|
|
223
|
+
mockData: MockData | null;
|
|
224
|
+
theme: ThemeConfig;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* HTTP transport for the BFF's tRPC endpoint (`/api/trpc/<procedure>`).
|
|
229
|
+
*
|
|
230
|
+
* Queries are header-less GETs with `?input=<json>` (a CORS "simple request",
|
|
231
|
+
* so no preflight); mutations POST a JSON body. The only things that leave the
|
|
232
|
+
* extension are payment inputs and optional recovery session/proof inputs
|
|
233
|
+
* and the browser's standard headers — `credentials: 'omit'` keeps cookies out.
|
|
234
|
+
* Queries are retried on network / 5xx errors; mutations never are.
|
|
235
|
+
*/
|
|
236
|
+
|
|
237
|
+
type ProcedureKind = 'query' | 'mutation';
|
|
238
|
+
interface Transport {
|
|
239
|
+
call<T>(procedure: string, kind: ProcedureKind, input: Record<string, unknown>): Promise<T>;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* In-memory stand-in for the BFF, used when `mock: true`. Lets an extension be
|
|
244
|
+
* developed with no backend: offers and entitlements come from `mockData`, a
|
|
245
|
+
* mock checkout completes after `claimAfterPolls` polls and grants the SKU.
|
|
246
|
+
*/
|
|
247
|
+
|
|
248
|
+
type SessionState = 'open' | 'complete' | 'canceled' | 'expired';
|
|
249
|
+
interface MockSession {
|
|
250
|
+
sku: string;
|
|
251
|
+
polls: number;
|
|
252
|
+
state: SessionState;
|
|
253
|
+
}
|
|
254
|
+
declare class MockTransport implements Transport {
|
|
255
|
+
private entitlements;
|
|
256
|
+
private readonly offers;
|
|
257
|
+
private readonly projectName;
|
|
258
|
+
private readonly checkoutEnabled;
|
|
259
|
+
private readonly claimAfterPolls;
|
|
260
|
+
readonly sessions: Map<string, MockSession>;
|
|
261
|
+
constructor(data?: MockData);
|
|
262
|
+
call<T>(procedure: string, _kind: ProcedureKind, input: Record<string, unknown>): Promise<T>;
|
|
263
|
+
/** Test/dev helpers. */
|
|
264
|
+
setEntitlements(items: PayEntitlementItem[]): void;
|
|
265
|
+
cancelSession(sessionId: string): void;
|
|
266
|
+
expireSession(sessionId: string): void;
|
|
267
|
+
private offerResponse;
|
|
268
|
+
private createCheckout;
|
|
269
|
+
private claim;
|
|
270
|
+
private grant;
|
|
271
|
+
private envelope;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/** Typed wrapper over the SDK-facing `pay.*` procedures. Nothing else is ever called. */
|
|
275
|
+
|
|
276
|
+
declare class PayApi {
|
|
277
|
+
private readonly transport;
|
|
278
|
+
private readonly publishableKey;
|
|
279
|
+
constructor(transport: Transport, publishableKey: string);
|
|
280
|
+
createRestoreSession(claimChallenge: string): Promise<PayRestoreSessionResponse>;
|
|
281
|
+
claimRestoreSession(sessionId: string, claimSecret: string): Promise<PayRestoreClaimResponse>;
|
|
282
|
+
getOffer(locale?: string | null): Promise<PayOfferResponse>;
|
|
283
|
+
createCheckout(sku: string, endUserRef: string, locale?: string | null): Promise<PayCheckoutSession>;
|
|
284
|
+
claimSession(sessionId: string, endUserRef: string): Promise<PayCheckoutClaim>;
|
|
285
|
+
getEntitlement(endUserRef: string): Promise<SignedEntitlement>;
|
|
286
|
+
getPortalUrl(endUserRef: string, customerId?: string): Promise<PayPortalResponse>;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* Persistent key/value storage for the SDK's own namespace.
|
|
291
|
+
*
|
|
292
|
+
* Preference order: `chrome.storage.local` (Chrome/Edge), `browser.storage.local`
|
|
293
|
+
* (Firefox), `localStorage` (non-extension contexts such as a dev page), then
|
|
294
|
+
* memory. Both promise-returning (MV3, Firefox) and callback-only (MV2) storage
|
|
295
|
+
* APIs are supported.
|
|
296
|
+
*/
|
|
297
|
+
interface StorageAdapter {
|
|
298
|
+
get(key: string): Promise<unknown>;
|
|
299
|
+
set(key: string, value: unknown): Promise<void>;
|
|
300
|
+
remove(key: string): Promise<void>;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
type PaywallMode = 'modal' | 'inline' | 'sidebar' | 'fullscreen' | 'minimal';
|
|
304
|
+
/** Every user-visible string the SDK adds on top of the templates (English only; iteration 12 T9 swaps locales). */
|
|
305
|
+
interface PaywallStrings {
|
|
306
|
+
title: string;
|
|
307
|
+
description: string;
|
|
308
|
+
upgrade: string;
|
|
309
|
+
cancel: string;
|
|
310
|
+
dismiss: string;
|
|
311
|
+
remindLater: string;
|
|
312
|
+
continueFree: string;
|
|
313
|
+
checkoutUnavailable: string;
|
|
314
|
+
periodMonth: string;
|
|
315
|
+
periodYear: string;
|
|
316
|
+
periodOnce: string;
|
|
317
|
+
footer: string;
|
|
318
|
+
restorePurchase: string;
|
|
319
|
+
}
|
|
320
|
+
interface PaywallOptions {
|
|
321
|
+
/** Template to render (default `modal`). */
|
|
322
|
+
mode?: PaywallMode;
|
|
323
|
+
/** Offer to feature; defaults to the first active offer. */
|
|
324
|
+
sku?: string;
|
|
325
|
+
title?: string;
|
|
326
|
+
description?: string;
|
|
327
|
+
/** Overrides the offer's `features[]`. */
|
|
328
|
+
features?: string[];
|
|
329
|
+
/** Free-tier bullets for the comparison templates (`inline`, `fullscreen`). */
|
|
330
|
+
freeFeatures?: string[];
|
|
331
|
+
theme?: ThemeConfig;
|
|
332
|
+
/** Mount point for `inline` mode (default `document.body`). */
|
|
333
|
+
container?: HTMLElement;
|
|
334
|
+
strings?: Partial<PaywallStrings>;
|
|
335
|
+
onUpgrade?: (sku: string) => void;
|
|
336
|
+
onClose?: () => void;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
type EntitlementSource = 'network' | 'cache' | 'mock' | 'none';
|
|
340
|
+
/** The SDK's view of the server projection, with `expiresAt` applied locally. */
|
|
341
|
+
interface Entitlement {
|
|
342
|
+
items: PayEntitlementItem[];
|
|
343
|
+
/** Union of `features[]` over active/grace items. */
|
|
344
|
+
features: string[];
|
|
345
|
+
/** True only when the Ed25519 signature was checked against the project's key. */
|
|
346
|
+
verified: boolean;
|
|
347
|
+
issuedAt: string | null;
|
|
348
|
+
/** `Date.now()` of the last successful fetch, or null when nothing was ever fetched. */
|
|
349
|
+
fetchedAt: number | null;
|
|
350
|
+
/** Paid access is paused until a successful online check, not a license expiry. */
|
|
351
|
+
requiresOnlineCheck?: boolean;
|
|
352
|
+
/** Local offline-access deadline; null for mock mode or no cached license. */
|
|
353
|
+
offlineUntil?: number | null;
|
|
354
|
+
source: EntitlementSource;
|
|
355
|
+
}
|
|
356
|
+
interface GetEntitlementOptions {
|
|
357
|
+
/** Skip the cache TTL and hit the network. */
|
|
358
|
+
force?: boolean;
|
|
359
|
+
}
|
|
360
|
+
type CheckoutState = 'complete' | 'canceled' | 'expired' | 'timeout';
|
|
361
|
+
interface CheckoutResult {
|
|
362
|
+
state: CheckoutState;
|
|
363
|
+
sku: string;
|
|
364
|
+
sessionId: string;
|
|
365
|
+
entitlement?: Entitlement;
|
|
366
|
+
}
|
|
367
|
+
interface CheckoutOptions {
|
|
368
|
+
locale?: string;
|
|
369
|
+
/** Stop polling `claimSession` after this long (default 10 minutes). */
|
|
370
|
+
timeoutMs?: number;
|
|
371
|
+
/** Poll interval (default 2 seconds). */
|
|
372
|
+
pollIntervalMs?: number;
|
|
373
|
+
/** Override how the hosted checkout URL is opened (default: `chrome.tabs.create`, then `window.open`). */
|
|
374
|
+
openUrl?: (url: string) => void | Promise<void>;
|
|
375
|
+
}
|
|
376
|
+
interface RequireFeatureOptions {
|
|
377
|
+
/** Full bundle only: show the paywall when the feature is locked (default true). */
|
|
378
|
+
showPaywall?: boolean;
|
|
379
|
+
onUnlock?: () => void;
|
|
380
|
+
onCancel?: () => void;
|
|
381
|
+
/** Paywall options used when `showPaywall` is true. */
|
|
382
|
+
paywall?: PaywallOptions;
|
|
383
|
+
}
|
|
384
|
+
interface RestoreOptions {
|
|
385
|
+
timeoutMs?: number;
|
|
386
|
+
pollIntervalMs?: number;
|
|
387
|
+
signal?: AbortSignal;
|
|
388
|
+
openUrl?: (url: string) => void | Promise<void>;
|
|
389
|
+
}
|
|
390
|
+
type RestoreResult = {
|
|
391
|
+
state: 'complete';
|
|
392
|
+
entitlement: Entitlement;
|
|
393
|
+
} | {
|
|
394
|
+
state: 'timeout' | 'expired' | 'canceled';
|
|
395
|
+
};
|
|
396
|
+
interface CustomerPortalOptions {
|
|
397
|
+
openUrl?: (url: string) => void | Promise<void>;
|
|
398
|
+
/** Return a listed profile ID, or null to cancel. Required by Lite for multiple profiles. */
|
|
399
|
+
selectAccount?: (accounts: PayPortalAccount[]) => string | null | Promise<string | null>;
|
|
400
|
+
}
|
|
401
|
+
interface LicenseSummary {
|
|
402
|
+
projectName: string | null;
|
|
403
|
+
seller: PaySellerPublic | null;
|
|
404
|
+
entitlement: Entitlement;
|
|
405
|
+
recoveryEnabled: boolean;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
interface ExtenshiPayEvents {
|
|
409
|
+
ready: {
|
|
410
|
+
endUserRef: string;
|
|
411
|
+
};
|
|
412
|
+
'entitlement:changed': Entitlement;
|
|
413
|
+
'checkout:started': {
|
|
414
|
+
sku: string;
|
|
415
|
+
sessionId: string;
|
|
416
|
+
url: string;
|
|
417
|
+
};
|
|
418
|
+
'checkout:completed': {
|
|
419
|
+
sku: string;
|
|
420
|
+
sessionId: string;
|
|
421
|
+
entitlement: Entitlement;
|
|
422
|
+
};
|
|
423
|
+
'checkout:canceled': {
|
|
424
|
+
sku: string;
|
|
425
|
+
sessionId: string;
|
|
426
|
+
};
|
|
427
|
+
'checkout:expired': {
|
|
428
|
+
sku: string;
|
|
429
|
+
sessionId: string;
|
|
430
|
+
};
|
|
431
|
+
error: ExtenshiPayError;
|
|
432
|
+
}
|
|
433
|
+
type ExtenshiPayEventName = keyof ExtenshiPayEvents;
|
|
434
|
+
|
|
435
|
+
/**
|
|
436
|
+
* Hosted checkout flow.
|
|
437
|
+
*
|
|
438
|
+
* `pay.createCheckout` returns a URL on the seller's provider; the SDK opens
|
|
439
|
+
* it in a new tab (`chrome.tabs.create`, falling back to `window.open`) and
|
|
440
|
+
* polls `pay.claimSession` every 2 s for up to 10 min — and immediately when
|
|
441
|
+
* the extension regains focus — until the webhook has landed. A pending
|
|
442
|
+
* session is persisted so a restarted service worker / reopened popup can
|
|
443
|
+
* finish the claim on the next `initialize()`.
|
|
444
|
+
*/
|
|
445
|
+
|
|
446
|
+
type OpenUrl = (url: string) => void | Promise<void>;
|
|
447
|
+
type Emit = <K extends keyof ExtenshiPayEvents>(event: K, payload: ExtenshiPayEvents[K]) => void;
|
|
448
|
+
interface CheckoutManagerOptions {
|
|
449
|
+
api: PayApi;
|
|
450
|
+
storage: StorageAdapter;
|
|
451
|
+
publishableKey: string;
|
|
452
|
+
locale: string | null;
|
|
453
|
+
getEndUserRef: () => Promise<string>;
|
|
454
|
+
/** Verifies + stores the envelope from a completed session. */
|
|
455
|
+
onComplete: (envelope: SignedEntitlement) => Promise<Entitlement>;
|
|
456
|
+
emit: Emit;
|
|
457
|
+
openUrl?: OpenUrl;
|
|
458
|
+
now?: () => number;
|
|
459
|
+
}
|
|
460
|
+
declare class CheckoutManager {
|
|
461
|
+
private readonly options;
|
|
462
|
+
private active;
|
|
463
|
+
private readonly now;
|
|
464
|
+
constructor(options: CheckoutManagerOptions);
|
|
465
|
+
get pendingKey(): string;
|
|
466
|
+
isActive(): boolean;
|
|
467
|
+
open(sku: string, options?: CheckoutOptions): Promise<CheckoutResult>;
|
|
468
|
+
/** Finishes a checkout that was started before a restart; null when there is nothing to resume. */
|
|
469
|
+
resumePending(): Promise<CheckoutResult | null>;
|
|
470
|
+
private poll;
|
|
471
|
+
private settle;
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
/**
|
|
475
|
+
* Entitlement cache + refresh.
|
|
476
|
+
*
|
|
477
|
+
* The cached envelope is a cache OF the server projection, never a second
|
|
478
|
+
* source of truth: it is verified when stored and re-verified on load (once
|
|
479
|
+
* the project's public key is known), served without a round-trip while the
|
|
480
|
+
* TTL holds, served for up to 48 hours after signed issuance when the network is down, and expired
|
|
481
|
+
* locally by `expiresAt`. Background refresh polls at most every 15 minutes
|
|
482
|
+
* and backs off exponentially on errors.
|
|
483
|
+
*/
|
|
484
|
+
|
|
485
|
+
interface EntitlementManagerOptions {
|
|
486
|
+
api: PayApi;
|
|
487
|
+
storage: StorageAdapter;
|
|
488
|
+
publishableKey: string;
|
|
489
|
+
cacheTtlMs: number;
|
|
490
|
+
source?: EntitlementSource;
|
|
491
|
+
getEndUserRef: () => Promise<string>;
|
|
492
|
+
/** Base64 raw Ed25519 public key from `getOffer`, or null when unknown/unsigned. */
|
|
493
|
+
getPublicKey: () => Promise<string | null>;
|
|
494
|
+
onChange?: (entitlement: Entitlement) => void;
|
|
495
|
+
onError?: (error: ExtenshiPayError) => void;
|
|
496
|
+
now?: () => number;
|
|
497
|
+
}
|
|
498
|
+
declare class EntitlementManager {
|
|
499
|
+
private readonly options;
|
|
500
|
+
private held;
|
|
501
|
+
private inflight;
|
|
502
|
+
private timer;
|
|
503
|
+
private refreshGeneration;
|
|
504
|
+
private deadlineTimer;
|
|
505
|
+
private refreshIntervalMs;
|
|
506
|
+
private backoffMs;
|
|
507
|
+
private autoRefresh;
|
|
508
|
+
private readonly online;
|
|
509
|
+
private lastFingerprint;
|
|
510
|
+
private readonly now;
|
|
511
|
+
private readonly source;
|
|
512
|
+
constructor(options: EntitlementManagerOptions);
|
|
513
|
+
get storageKey(): string;
|
|
514
|
+
/** Loads the persisted envelope (unverified until `reverify()`); no network. */
|
|
515
|
+
load(): Promise<Entitlement | null>;
|
|
516
|
+
/** Re-checks the loaded envelope against the project's key; discards it when the signature is invalid. */
|
|
517
|
+
reverify(): Promise<void>;
|
|
518
|
+
getCached(): Entitlement | null;
|
|
519
|
+
isFresh(): boolean;
|
|
520
|
+
get(options?: {
|
|
521
|
+
force?: boolean;
|
|
522
|
+
}): Promise<Entitlement>;
|
|
523
|
+
/** Fetches the projection from the backend, verifies and stores it. */
|
|
524
|
+
refresh(): Promise<Entitlement>;
|
|
525
|
+
/** Verifies and stores an envelope obtained elsewhere (e.g. from `claimSession`). */
|
|
526
|
+
accept(envelope: SignedEntitlement, source?: EntitlementSource): Promise<Entitlement>;
|
|
527
|
+
/** Drain an older installation refresh before changing identity. */
|
|
528
|
+
settleRefresh(): Promise<void>;
|
|
529
|
+
clear(): Promise<void>;
|
|
530
|
+
startAutoRefresh(intervalMs?: number): void;
|
|
531
|
+
stopAutoRefresh(): void;
|
|
532
|
+
private scheduleDeadline;
|
|
533
|
+
private schedule;
|
|
534
|
+
private safePublicKey;
|
|
535
|
+
private discard;
|
|
536
|
+
private fingerprint;
|
|
537
|
+
private notifyIfChanged;
|
|
538
|
+
private offlineDeadline;
|
|
539
|
+
private snapshot;
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
/** Email stays on the hosted page. Only this extension context holds the claim secret. */
|
|
543
|
+
|
|
544
|
+
interface RecoveryManagerOptions {
|
|
545
|
+
api: PayApi;
|
|
546
|
+
storage: StorageAdapter;
|
|
547
|
+
publishableKey: string;
|
|
548
|
+
onComplete: (endUserRef: string, envelope: SignedEntitlement) => Promise<Entitlement>;
|
|
549
|
+
openUrl?: (url: string) => void | Promise<void>;
|
|
550
|
+
now?: () => number;
|
|
551
|
+
}
|
|
552
|
+
declare class RecoveryManager {
|
|
553
|
+
private readonly options;
|
|
554
|
+
private active;
|
|
555
|
+
private stopped;
|
|
556
|
+
private wake;
|
|
557
|
+
constructor(options: RecoveryManagerOptions);
|
|
558
|
+
get pendingKey(): string;
|
|
559
|
+
isActive(): boolean;
|
|
560
|
+
stop(): void;
|
|
561
|
+
open(options?: RestoreOptions): Promise<RestoreResult>;
|
|
562
|
+
resumePending(): Promise<RestoreResult | null>;
|
|
563
|
+
private poll;
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
type Listener<T> = (payload: T) => void;
|
|
567
|
+
declare class EventEmitter<Events extends object> {
|
|
568
|
+
private readonly listeners;
|
|
569
|
+
on<K extends keyof Events>(event: K, listener: Listener<Events[K]>): () => void;
|
|
570
|
+
once<K extends keyof Events>(event: K, listener: Listener<Events[K]>): () => void;
|
|
571
|
+
off<K extends keyof Events>(event: K, listener: Listener<Events[K]>): void;
|
|
572
|
+
emit<K extends keyof Events>(event: K, payload: Events[K]): void;
|
|
573
|
+
removeAll(): void;
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
/**
|
|
577
|
+
* `ExtenshiPayLite` — entitlement, feature gating and hosted checkout, without
|
|
578
|
+
* the paywall UI. This is what the `lite` bundle exports; the full `ExtenshiPay`
|
|
579
|
+
* extends it with `getOffer()` / `showPaywall()`.
|
|
580
|
+
*
|
|
581
|
+
* Data that leaves the extension: `publishableKey`, `endUserRef`, `sku`,
|
|
582
|
+
* `locale` and checkout session IDs. Explicit recovery also sends its session ID,
|
|
583
|
+
* challenge and claim secret (POST body). Email stays on the hosted page.
|
|
584
|
+
*/
|
|
585
|
+
|
|
586
|
+
/** Injection points for tests and unusual hosts. */
|
|
587
|
+
interface ExtenshiPayDeps {
|
|
588
|
+
storage?: StorageAdapter;
|
|
589
|
+
/** Trusted extension-only storage; never share this adapter with content scripts. */
|
|
590
|
+
recoveryStorage?: StorageAdapter;
|
|
591
|
+
transport?: Transport;
|
|
592
|
+
fetch?: typeof fetch;
|
|
593
|
+
openUrl?: (url: string) => void | Promise<void>;
|
|
594
|
+
now?: () => number;
|
|
595
|
+
}
|
|
596
|
+
declare class ExtenshiPayLite {
|
|
597
|
+
static readonly version = "0.7.0";
|
|
598
|
+
protected readonly config: ResolvedConfig;
|
|
599
|
+
protected readonly emitter: EventEmitter<ExtenshiPayEvents>;
|
|
600
|
+
protected readonly storage: StorageAdapter;
|
|
601
|
+
protected readonly api: PayApi;
|
|
602
|
+
protected readonly entitlements: EntitlementManager;
|
|
603
|
+
protected readonly checkout: CheckoutManager;
|
|
604
|
+
protected readonly recovery: RecoveryManager;
|
|
605
|
+
private readonly now;
|
|
606
|
+
private endUserRef;
|
|
607
|
+
private endUserRefPromise;
|
|
608
|
+
private offer;
|
|
609
|
+
private offerInflight;
|
|
610
|
+
private readyPromise;
|
|
611
|
+
private destroyed;
|
|
612
|
+
constructor(config: ExtenshiPayConfig, deps?: ExtenshiPayDeps);
|
|
613
|
+
get version(): string;
|
|
614
|
+
/**
|
|
615
|
+
* Mints/loads `endUserRef`, loads the cached entitlement, re-verifies it and
|
|
616
|
+
* refreshes it when stale. Resolves once `isPaid()` can answer; network
|
|
617
|
+
* failures fall back to the cache and are reported through `error`.
|
|
618
|
+
*/
|
|
619
|
+
initialize(): Promise<void>;
|
|
620
|
+
private doInitialize;
|
|
621
|
+
private afterReady;
|
|
622
|
+
/** The anonymous, random id this install is known by. */
|
|
623
|
+
getEndUserRef(): Promise<string>;
|
|
624
|
+
getCachedEntitlement(): Entitlement | null;
|
|
625
|
+
getEntitlement(options?: GetEntitlementOptions): Promise<Entitlement>;
|
|
626
|
+
/** True when any active/grace entitlement exists, or the given `sku` is active/grace. */
|
|
627
|
+
isPaid(sku?: string): Promise<boolean>;
|
|
628
|
+
hasFeature(feature: string): Promise<boolean>;
|
|
629
|
+
checkFeatures(features: string[]): Promise<Record<string, boolean>>;
|
|
630
|
+
/** Resolves true when the feature is (or becomes) unlocked. */
|
|
631
|
+
requireFeature(feature: string, options?: RequireFeatureOptions): Promise<boolean>;
|
|
632
|
+
/** Lite has no UI: a locked feature stays locked. The full SDK shows the paywall here. */
|
|
633
|
+
protected onFeatureLocked(_feature: string, _options: RequireFeatureOptions): Promise<boolean>;
|
|
634
|
+
/** Opens hosted checkout for `sku` in a new tab and resolves when the session settles. */
|
|
635
|
+
openCheckout(sku: string, options?: CheckoutOptions): Promise<CheckoutResult>;
|
|
636
|
+
/** Opens email verification on the hosted page. No email is collected inside the extension. */
|
|
637
|
+
restorePurchase(options?: RestoreOptions): Promise<RestoreResult>;
|
|
638
|
+
/** Read-only license view. Entitlements retain cache/signature/offline semantics. */
|
|
639
|
+
getLicenseSummary(options?: GetEntitlementOptions): Promise<LicenseSummary>;
|
|
640
|
+
/** Opens the provider's self-service portal; resolves null when the provider has none. */
|
|
641
|
+
openCustomerPortal(options?: CustomerPortalOptions): Promise<string | null>;
|
|
642
|
+
on<K extends keyof ExtenshiPayEvents>(event: K, listener: Listener<ExtenshiPayEvents[K]>): () => void;
|
|
643
|
+
once<K extends keyof ExtenshiPayEvents>(event: K, listener: Listener<ExtenshiPayEvents[K]>): () => void;
|
|
644
|
+
off<K extends keyof ExtenshiPayEvents>(event: K, listener: Listener<ExtenshiPayEvents[K]>): void;
|
|
645
|
+
onEntitlementChange(listener: Listener<Entitlement>): () => void;
|
|
646
|
+
clearCache(): Promise<void>;
|
|
647
|
+
/** Stops background refresh and drops listeners. */
|
|
648
|
+
destroy(): void;
|
|
649
|
+
/** Offer + signing key. Public in the full SDK (`getOffer`), internal here. */
|
|
650
|
+
protected fetchOffer(force?: boolean): Promise<PayOfferResponse>;
|
|
651
|
+
private getPublicKey;
|
|
652
|
+
protected reportError(error: unknown): ExtenshiPayError;
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
/** Kept in sync with package.json by tests/unit/version.test.ts. */
|
|
656
|
+
declare const VERSION = "0.7.0";
|
|
657
|
+
|
|
658
|
+
export { ERROR_CODES, ExtenshiPayLite as ExtenshiPay, ExtenshiPayError, ExtenshiPayLite, MockTransport, VERSION, ExtenshiPayLite as default };
|
|
659
|
+
export type { CheckoutOptions, CheckoutResult, CheckoutState, CustomerPortalOptions, Entitlement, EntitlementSource, ErrorCode, ExtenshiPayConfig, ExtenshiPayDeps, ExtenshiPayEventName, ExtenshiPayEvents, GetEntitlementOptions, LicenseSummary, MockData, PayEntitlementItem, PayEntitlementStatus, PayOfferDto, PayPortalAccount, PayPortalResponse, PaySellerPublic, RequireFeatureOptions, RestoreOptions, RestoreResult, StorageAdapter, ThemeConfig, Transport };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lite.d.ts","sourceRoot":"","sources":["../src/lite.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAC7C,YAAY,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AACnD,YAAY,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAC7D,OAAO,EAAE,eAAe,EAAE,eAAe,IAAI,WAAW,EAAE,MAAM,wBAAwB,CAAA;AACxF,YAAY,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AACvD,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AACjE,YAAY,EACX,eAAe,EACf,cAAc,EACd,aAAa,EACb,qBAAqB,EACrB,WAAW,EACX,iBAAiB,EACjB,SAAS,EACT,iBAAiB,EACjB,oBAAoB,EACpB,iBAAiB,EACjB,qBAAqB,EACrB,cAAc,EACd,QAAQ,EACR,kBAAkB,EAClB,oBAAoB,EACpB,WAAW,EACX,gBAAgB,EAChB,iBAAiB,EACjB,eAAe,EACf,qBAAqB,EACrB,cAAc,EACd,aAAa,EACb,WAAW,GACX,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAEtC,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AACxD,eAAe,eAAe,CAAA"}
|