@extenshi/pay 0.7.0 → 0.8.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/README.md +13 -9
- package/dist/api/mock.d.ts +4 -0
- package/dist/api/mock.d.ts.map +1 -1
- package/dist/api/pay-api.d.ts +10 -3
- package/dist/api/pay-api.d.ts.map +1 -1
- package/dist/api/transport.d.ts.map +1 -1
- package/dist/core/config.d.ts.map +1 -1
- package/dist/core/extenshi-pay.d.ts +21 -2
- package/dist/core/extenshi-pay.d.ts.map +1 -1
- package/dist/core/locale.d.ts +13 -0
- package/dist/core/locale.d.ts.map +1 -0
- package/dist/core.d.mts +208 -113
- package/dist/core.d.ts +208 -113
- package/dist/core.js +204 -14
- package/dist/core.js.map +1 -1
- package/dist/core.mjs +204 -15
- package/dist/core.mjs.map +1 -1
- package/dist/extenshi-pay-lite.js +204 -14
- package/dist/extenshi-pay-lite.js.map +1 -1
- package/dist/extenshi-pay-lite.min.js +3 -2
- package/dist/extenshi-pay-lite.min.js.map +1 -1
- package/dist/extenshi-pay-lite.mjs +204 -15
- package/dist/extenshi-pay-lite.mjs.map +1 -1
- package/dist/extenshi-pay.cjs.js +1234 -180
- package/dist/extenshi-pay.cjs.js.map +1 -1
- package/dist/extenshi-pay.d.ts.map +1 -1
- package/dist/extenshi-pay.js +1234 -180
- package/dist/extenshi-pay.js.map +1 -1
- package/dist/extenshi-pay.min.js +3 -2
- package/dist/extenshi-pay.min.js.map +1 -1
- package/dist/extenshi-pay.min.mjs +3 -2
- package/dist/extenshi-pay.min.mjs.map +1 -1
- package/dist/extenshi-pay.mjs +1231 -181
- package/dist/extenshi-pay.mjs.map +1 -1
- package/dist/index.d.mts +268 -117
- package/dist/index.d.ts +268 -117
- package/dist/lite.d.mts +176 -82
- package/dist/lite.d.ts +176 -82
- package/dist/lite.d.ts.map +1 -1
- package/dist/payment/checkout.d.ts.map +1 -1
- package/dist/payment/recovery.d.ts +2 -0
- package/dist/payment/recovery.d.ts.map +1 -1
- package/dist/payment/withdrawal-waiver.d.ts +26 -0
- package/dist/payment/withdrawal-waiver.d.ts.map +1 -0
- package/dist/paywall/billing-profile-picker.d.ts +1 -1
- package/dist/paywall/billing-profile-picker.d.ts.map +1 -1
- package/dist/paywall/i18n.d.ts +94 -0
- package/dist/paywall/i18n.d.ts.map +1 -0
- package/dist/paywall/index.d.ts +2 -1
- package/dist/paywall/index.d.ts.map +1 -1
- package/dist/paywall/license-panel.d.ts +4 -1
- package/dist/paywall/license-panel.d.ts.map +1 -1
- package/dist/paywall/renderer.d.ts +16 -2
- package/dist/paywall/renderer.d.ts.map +1 -1
- package/dist/paywall/seller-details.d.ts +2 -1
- package/dist/paywall/seller-details.d.ts.map +1 -1
- package/dist/paywall/strings.d.ts +6 -4
- package/dist/paywall/strings.d.ts.map +1 -1
- package/dist/paywall.d.mts +93 -7
- package/dist/paywall.d.ts +93 -7
- package/dist/paywall.js +992 -41
- package/dist/paywall.js.map +1 -1
- package/dist/paywall.mjs +990 -42
- package/dist/paywall.mjs.map +1 -1
- package/dist/types/config.d.ts +6 -1
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/contract.d.ts +25 -0
- package/dist/types/contract.d.ts.map +1 -1
- package/dist/types/entitlement.d.ts +22 -0
- package/dist/types/entitlement.d.ts.map +1 -1
- package/dist/types/errors.d.ts +1 -0
- package/dist/types/errors.d.ts.map +1 -1
- package/dist/types/paywall.d.ts +15 -2
- package/dist/types/paywall.d.ts.map +1 -1
- package/dist/version.d.ts +1 -1
- package/package.json +3 -11
- package/dist/core.esm.js +0 -1681
- package/dist/core.esm.js.map +0 -1
- package/dist/extenshi-pay-lite.esm.js +0 -1664
- package/dist/extenshi-pay-lite.esm.js.map +0 -1
- package/dist/extenshi-pay.esm.js +0 -2496
- package/dist/extenshi-pay.esm.js.map +0 -1
- package/dist/extenshi-pay.esm.min.js +0 -7
- package/dist/extenshi-pay.esm.min.js.map +0 -1
- package/dist/paywall.esm.js +0 -442
- package/dist/paywall.esm.js.map +0 -1
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* ExtenshiPay SDK v0.
|
|
2
|
+
* ExtenshiPay SDK v0.8.0
|
|
3
3
|
* (c) 2026 Extenshi.io
|
|
4
4
|
* Released under the MIT License.
|
|
5
|
+
* commit c6d87d374d371c8ddcb3345a25c72926538c5c05 · built by `rollup -c`
|
|
5
6
|
*/
|
|
6
7
|
/**
|
|
7
8
|
* Wire contract between the SDK and catalog-bff `pay.*`.
|
|
@@ -28,6 +29,13 @@ const PUBLISHABLE_KEY_RE = new RegExp(`^${PAY_PUBLISHABLE_KEY_PREFIX}[0-9a-f]{${
|
|
|
28
29
|
function isPayPublishableKey(value) {
|
|
29
30
|
return typeof value === 'string' && PUBLISHABLE_KEY_RE.test(value);
|
|
30
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Version of the buyer-facing withdrawal waiver text the paywall shows (EU/EEA
|
|
34
|
+
* digital content, Directive 2011/83/EU art. 16(m); UK CCR 2013 reg. 37). The
|
|
35
|
+
* text itself lives in the SDK dictionary under the same version; bump both
|
|
36
|
+
* together so a recorded consent always names the words the buyer saw.
|
|
37
|
+
*/
|
|
38
|
+
const PAY_WITHDRAWAL_WAIVER_VERSION = '2026-10-v1';
|
|
31
39
|
/**
|
|
32
40
|
* The `endUserRef` an SDK mints on first run and keeps in `chrome.storage`.
|
|
33
41
|
* Opaque, random, never derived from anything identifying.
|
|
@@ -42,6 +50,7 @@ const PAY_ERRORS = {
|
|
|
42
50
|
GATEWAY_UNAVAILABLE: 'PAY_GATEWAY_UNAVAILABLE',
|
|
43
51
|
RATE_LIMITED: 'PAY_RATE_LIMITED',
|
|
44
52
|
INVALID_KEY: 'PAY_INVALID_KEY',
|
|
53
|
+
WITHDRAWAL_WAIVER_REQUIRED: 'PAY_WITHDRAWAL_WAIVER_REQUIRED',
|
|
45
54
|
};
|
|
46
55
|
/**
|
|
47
56
|
* Canonical JSON for signing: keys sorted recursively, no whitespace. Both
|
|
@@ -73,6 +82,7 @@ const ERROR_CODES = {
|
|
|
73
82
|
GATEWAY_UNAVAILABLE: 'GATEWAY_UNAVAILABLE',
|
|
74
83
|
CHECKOUT_UNAVAILABLE: 'CHECKOUT_UNAVAILABLE',
|
|
75
84
|
PAYWALL_UNAVAILABLE: 'PAYWALL_UNAVAILABLE',
|
|
85
|
+
WITHDRAWAL_WAIVER_REQUIRED: 'WITHDRAWAL_WAIVER_REQUIRED',
|
|
76
86
|
UNKNOWN: 'UNKNOWN',
|
|
77
87
|
};
|
|
78
88
|
class ExtenshiPayError extends Error {
|
|
@@ -129,6 +139,13 @@ async function getOrCreateEndUserRef(storage) {
|
|
|
129
139
|
* mock checkout completes after `claimAfterPolls` polls and grants the SKU.
|
|
130
140
|
*/
|
|
131
141
|
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
142
|
+
/** Accepts the same optional `withdrawalWaiver` input as the BFF; anything else is no consent. */
|
|
143
|
+
function mockConsent(value) {
|
|
144
|
+
const consent = value;
|
|
145
|
+
return consent && typeof consent.version === 'string' && consent.accepted === true
|
|
146
|
+
? { version: consent.version, accepted: true }
|
|
147
|
+
: null;
|
|
148
|
+
}
|
|
132
149
|
class MockTransport {
|
|
133
150
|
constructor(data = {}) {
|
|
134
151
|
this.sessions = new Map();
|
|
@@ -137,13 +154,15 @@ class MockTransport {
|
|
|
137
154
|
this.projectName = data.projectName ?? 'Mock project';
|
|
138
155
|
this.checkoutEnabled = data.checkoutEnabled ?? true;
|
|
139
156
|
this.claimAfterPolls = data.claimAfterPolls ?? 1;
|
|
157
|
+
this.withdrawalWaiver =
|
|
158
|
+
data.withdrawalWaiver === undefined ? { version: PAY_WITHDRAWAL_WAIVER_VERSION } : data.withdrawalWaiver;
|
|
140
159
|
}
|
|
141
160
|
async call(procedure, _kind, input) {
|
|
142
161
|
switch (procedure) {
|
|
143
162
|
case 'pay.getOffer':
|
|
144
163
|
return this.offerResponse();
|
|
145
164
|
case 'pay.createCheckout':
|
|
146
|
-
return this.createCheckout(String(input.sku));
|
|
165
|
+
return this.createCheckout(String(input.sku), mockConsent(input.withdrawalWaiver));
|
|
147
166
|
case 'pay.claimSession':
|
|
148
167
|
return this.claim(String(input.sessionId), String(input.endUserRef), String(input.publishableKey));
|
|
149
168
|
case 'pay.getEntitlement':
|
|
@@ -176,9 +195,10 @@ class MockTransport {
|
|
|
176
195
|
checkoutEnabled: this.checkoutEnabled && this.offers.length > 0,
|
|
177
196
|
offers: [...this.offers],
|
|
178
197
|
entitlementPublicKey: null,
|
|
198
|
+
withdrawalWaiver: this.withdrawalWaiver ? { ...this.withdrawalWaiver } : null,
|
|
179
199
|
};
|
|
180
200
|
}
|
|
181
|
-
createCheckout(sku) {
|
|
201
|
+
createCheckout(sku, withdrawalWaiver) {
|
|
182
202
|
if (!this.checkoutEnabled) {
|
|
183
203
|
throw new ExtenshiPayError(ERROR_CODES.SELLER_NOT_ACTIVE, 'Mock seller cannot take payments');
|
|
184
204
|
}
|
|
@@ -186,7 +206,7 @@ class MockTransport {
|
|
|
186
206
|
throw new ExtenshiPayError(ERROR_CODES.OFFER_NOT_FOUND, `Unknown mock offer ${sku}`);
|
|
187
207
|
}
|
|
188
208
|
const sessionId = mintEndUserRef();
|
|
189
|
-
this.sessions.set(sessionId, { sku, polls: 0, state: 'open' });
|
|
209
|
+
this.sessions.set(sessionId, { sku, polls: 0, state: 'open', withdrawalWaiver });
|
|
190
210
|
return {
|
|
191
211
|
url: `https://mock.extenshi.io/checkout/${sessionId}`,
|
|
192
212
|
sessionId,
|
|
@@ -248,10 +268,12 @@ class PayApi {
|
|
|
248
268
|
this.transport = transport;
|
|
249
269
|
this.publishableKey = publishableKey;
|
|
250
270
|
}
|
|
251
|
-
|
|
271
|
+
/** `locale` opens the hosted recovery page (and its email) in the user's language. */
|
|
272
|
+
createRestoreSession(claimChallenge, locale) {
|
|
252
273
|
return this.transport.call('pay.createRestoreSession', 'mutation', {
|
|
253
274
|
publishableKey: this.publishableKey,
|
|
254
275
|
claimChallenge,
|
|
276
|
+
...(locale ? { locale } : {}),
|
|
255
277
|
});
|
|
256
278
|
}
|
|
257
279
|
claimRestoreSession(sessionId, claimSecret) {
|
|
@@ -267,12 +289,20 @@ class PayApi {
|
|
|
267
289
|
locale: locale ?? undefined,
|
|
268
290
|
});
|
|
269
291
|
}
|
|
270
|
-
|
|
292
|
+
/**
|
|
293
|
+
* `withdrawalWaiver` is sent only when given. Older BFFs parse the input with
|
|
294
|
+
* a non-strict zod object, which strips the unknown key, so it is safe there.
|
|
295
|
+
* Plain-JS callers passing anything but `accepted: true` send no consent.
|
|
296
|
+
*/
|
|
297
|
+
createCheckout(sku, endUserRef, locale, withdrawalWaiver) {
|
|
271
298
|
return this.transport.call('pay.createCheckout', 'mutation', {
|
|
272
299
|
publishableKey: this.publishableKey,
|
|
273
300
|
sku,
|
|
274
301
|
endUserRef,
|
|
275
302
|
locale: locale ?? undefined,
|
|
303
|
+
...(withdrawalWaiver?.accepted === true && typeof withdrawalWaiver.version === 'string'
|
|
304
|
+
? { withdrawalWaiver: { version: withdrawalWaiver.version, accepted: true } }
|
|
305
|
+
: {}),
|
|
276
306
|
});
|
|
277
307
|
}
|
|
278
308
|
claimSession(sessionId, endUserRef) {
|
|
@@ -288,11 +318,12 @@ class PayApi {
|
|
|
288
318
|
endUserRef,
|
|
289
319
|
});
|
|
290
320
|
}
|
|
291
|
-
getPortalUrl(endUserRef, customerId) {
|
|
321
|
+
getPortalUrl(endUserRef, customerId, locale) {
|
|
292
322
|
return this.transport.call('pay.getPortalUrl', 'mutation', {
|
|
293
323
|
publishableKey: this.publishableKey,
|
|
294
324
|
endUserRef,
|
|
295
325
|
...(customerId ? { customerId } : {}),
|
|
326
|
+
...(locale ? { locale } : {}),
|
|
296
327
|
});
|
|
297
328
|
}
|
|
298
329
|
}
|
|
@@ -358,6 +389,7 @@ const CAUSE_TO_CODE = {
|
|
|
358
389
|
[PAY_ERRORS.AGREEMENT_REQUIRED]: ERROR_CODES.SELLER_NOT_ACTIVE,
|
|
359
390
|
[PAY_ERRORS.OFFER_NOT_FOUND]: ERROR_CODES.OFFER_NOT_FOUND,
|
|
360
391
|
[PAY_ERRORS.GATEWAY_UNAVAILABLE]: ERROR_CODES.GATEWAY_UNAVAILABLE,
|
|
392
|
+
[PAY_ERRORS.WITHDRAWAL_WAIVER_REQUIRED]: ERROR_CODES.WITHDRAWAL_WAIVER_REQUIRED,
|
|
361
393
|
};
|
|
362
394
|
function parseRetryAfter(message) {
|
|
363
395
|
const match = /retry in (\d+)s/i.exec(message);
|
|
@@ -387,6 +419,8 @@ function trpcErrorToPayError(error, httpStatus) {
|
|
|
387
419
|
return new ExtenshiPayError(ERROR_CODES.CHECKOUT_UNAVAILABLE, message, options);
|
|
388
420
|
return new ExtenshiPayError(ERROR_CODES.OFFER_NOT_FOUND, message, options);
|
|
389
421
|
case 'PRECONDITION_FAILED':
|
|
422
|
+
if (/withdrawal/i.test(message))
|
|
423
|
+
return new ExtenshiPayError(ERROR_CODES.WITHDRAWAL_WAIVER_REQUIRED, message, options);
|
|
390
424
|
return new ExtenshiPayError(ERROR_CODES.SELLER_NOT_ACTIVE, message, options);
|
|
391
425
|
case 'BAD_REQUEST':
|
|
392
426
|
return new ExtenshiPayError(ERROR_CODES.INVALID_REQUEST, message, options);
|
|
@@ -569,7 +603,7 @@ class CheckoutManager {
|
|
|
569
603
|
throw new ExtenshiPayError(ERROR_CODES.CHECKOUT_UNAVAILABLE, 'A checkout is already in progress');
|
|
570
604
|
}
|
|
571
605
|
const endUserRef = await this.options.getEndUserRef();
|
|
572
|
-
const session = await this.options.api.createCheckout(sku, endUserRef, options.locale ?? this.options.locale);
|
|
606
|
+
const session = await this.options.api.createCheckout(sku, endUserRef, options.locale ?? this.options.locale, options.withdrawalWaiver);
|
|
573
607
|
this.active = session.sessionId;
|
|
574
608
|
try {
|
|
575
609
|
const pending = { sessionId: session.sessionId, sku, expiresAt: session.expiresAt };
|
|
@@ -1213,7 +1247,7 @@ class RecoveryManager {
|
|
|
1213
1247
|
const secret = Array.from(cryptoApi.getRandomValues(new Uint8Array(32)), (b) => b.toString(16).padStart(2, '0')).join('');
|
|
1214
1248
|
const hash = await cryptoApi.subtle.digest('SHA-256', new TextEncoder().encode(secret));
|
|
1215
1249
|
const challenge = Array.from(new Uint8Array(hash), (b) => b.toString(16).padStart(2, '0')).join('');
|
|
1216
|
-
const created = await this.options.api.createRestoreSession(challenge);
|
|
1250
|
+
const created = await this.options.api.createRestoreSession(challenge, this.options.locale);
|
|
1217
1251
|
if (!Number.isFinite(Date.parse(created.expiresAt)))
|
|
1218
1252
|
throw new ExtenshiPayError(ERROR_CODES.INVALID_RESPONSE, 'Invalid recovery expiry');
|
|
1219
1253
|
const pending = { sessionId: created.sessionId, expiresAt: created.expiresAt, claimSecret: secret };
|
|
@@ -1300,8 +1334,127 @@ class RecoveryManager {
|
|
|
1300
1334
|
}
|
|
1301
1335
|
}
|
|
1302
1336
|
|
|
1337
|
+
/**
|
|
1338
|
+
* The user's language as the SDK sends it. Kept apart from the paywall
|
|
1339
|
+
* dictionary (../paywall/i18n.ts) so the Lite and core bundles, which never
|
|
1340
|
+
* render UI, do not carry the translations.
|
|
1341
|
+
*/
|
|
1342
|
+
/** What the backend (and older backends) accept as a locale: `de`, `pt-BR`, `zh-CN`. */
|
|
1343
|
+
const WIRE_LOCALE_RE = /^[a-z]{2}(-[A-Za-z]{2,4})?$/;
|
|
1344
|
+
/**
|
|
1345
|
+
* A browser tag as the SDK sends it: `pt_BR` → `pt-BR`, `es-419` → `es`,
|
|
1346
|
+
* `zh-Hant-TW` → `zh-TW`; null for anything that is not a language tag.
|
|
1347
|
+
*/
|
|
1348
|
+
function wireLocale(raw) {
|
|
1349
|
+
if (typeof raw !== 'string')
|
|
1350
|
+
return null;
|
|
1351
|
+
const parts = raw.trim().replace(/_/g, '-').split('-').filter(Boolean);
|
|
1352
|
+
const lang = parts[0]?.toLowerCase();
|
|
1353
|
+
if (!lang || !/^[a-z]{2}$/.test(lang))
|
|
1354
|
+
return null;
|
|
1355
|
+
const script = parts
|
|
1356
|
+
.slice(1)
|
|
1357
|
+
.find((p) => /^[A-Za-z]{4}$/.test(p))
|
|
1358
|
+
?.toLowerCase();
|
|
1359
|
+
// zh-Hant without a region is Traditional Chinese: keep that, never let it read as zh-CN.
|
|
1360
|
+
const region = parts.slice(1).find((p) => /^[A-Za-z]{2}$/.test(p)) ??
|
|
1361
|
+
(lang === 'zh' && script === 'hant' ? 'TW' : undefined);
|
|
1362
|
+
const tag = region ? `${lang}-${region.toUpperCase()}` : lang;
|
|
1363
|
+
return WIRE_LOCALE_RE.test(tag) ? tag : lang;
|
|
1364
|
+
}
|
|
1365
|
+
/** The browser UI language (`chrome.i18n.getUILanguage()`, else `navigator.language`), or null. */
|
|
1366
|
+
function browserLocale() {
|
|
1367
|
+
const g = globalThis;
|
|
1368
|
+
try {
|
|
1369
|
+
const ui = g.chrome?.i18n?.getUILanguage?.() ?? g.browser?.i18n?.getUILanguage?.();
|
|
1370
|
+
if (ui)
|
|
1371
|
+
return wireLocale(ui);
|
|
1372
|
+
}
|
|
1373
|
+
catch {
|
|
1374
|
+
/* Not an extension context. */
|
|
1375
|
+
}
|
|
1376
|
+
return wireLocale(g.navigator?.language);
|
|
1377
|
+
}
|
|
1378
|
+
|
|
1379
|
+
/**
|
|
1380
|
+
* Every string the SDK shows to the USER of an extension — paywall, license
|
|
1381
|
+
* dialog, billing-profile picker, seller details — in the end-user languages
|
|
1382
|
+
* (ROADMAP it. 13 T10, stage L2; closes it. 12 T9). Developer-facing error
|
|
1383
|
+
* messages stay English.
|
|
1384
|
+
*
|
|
1385
|
+
* Self-contained on purpose: the SDK ships inside third-party extensions with
|
|
1386
|
+
* no runtime dependencies and no remote code, so the dictionary is compiled
|
|
1387
|
+
* in. Placeholders are `{name}`, `{date}`, `{status}`. A missing
|
|
1388
|
+
* translation falls back to English, never to an empty string. The same
|
|
1389
|
+
* languages as the hosted pages (shared-types END_USER_LOCALES); keep the
|
|
1390
|
+
* lists in sync.
|
|
1391
|
+
*/
|
|
1392
|
+
const SDK_LOCALES = ['en', 'es', 'pt-BR', 'fr', 'de', 'it', 'ru', 'ja', 'ko', 'zh-CN', 'ar'];
|
|
1393
|
+
// END GENERATED TRANSLATIONS
|
|
1394
|
+
/** Our dictionary language for a tag: exact, then pt → pt-BR, zh(-CN/SG/Hans) → zh-CN, then the bare language. */
|
|
1395
|
+
function sdkLocale(locale) {
|
|
1396
|
+
const tag = wireLocale(locale);
|
|
1397
|
+
if (!tag)
|
|
1398
|
+
return 'en';
|
|
1399
|
+
const exact = SDK_LOCALES.find((l) => l.toLowerCase() === tag.toLowerCase());
|
|
1400
|
+
if (exact)
|
|
1401
|
+
return exact;
|
|
1402
|
+
const [lang, region] = tag.split('-');
|
|
1403
|
+
if (lang === 'pt')
|
|
1404
|
+
return 'pt-BR';
|
|
1405
|
+
// Traditional-script regions read English rather than Simplified characters.
|
|
1406
|
+
if (lang === 'zh')
|
|
1407
|
+
return region && ['TW', 'HK', 'MO'].includes(region) ? 'en' : 'zh-CN';
|
|
1408
|
+
return SDK_LOCALES.find((l) => l === lang) ?? 'en';
|
|
1409
|
+
}
|
|
1410
|
+
/** Fill `{placeholders}` once; a value containing braces is inserted literally. */
|
|
1411
|
+
function fill(message, values) {
|
|
1412
|
+
return message.replace(/\{([a-z]+)\}/g, (whole, key) => values[key] ?? whole);
|
|
1413
|
+
}
|
|
1414
|
+
|
|
1415
|
+
/**
|
|
1416
|
+
* Buyer-facing withdrawal-waiver text (EU/EEA digital content, Directive
|
|
1417
|
+
* 2011/83/EU art. 16(m); UK CCR 2013 reg. 37), per text version and SDK
|
|
1418
|
+
* language. Its own module, not part of the paywall dictionary, so Lite can
|
|
1419
|
+
* show it without bundling every paywall string.
|
|
1420
|
+
*
|
|
1421
|
+
* The recorded consent names the version, so a version's words never change:
|
|
1422
|
+
* new wording is a new version here and a new PAY_WITHDRAWAL_WAIVER_VERSION.
|
|
1423
|
+
*
|
|
1424
|
+
* MIRRORED in shared-types/pay-withdrawal-waiver.ts, which the purchase
|
|
1425
|
+
* confirmation email quotes; shared-types/pay-withdrawal-waiver.test.ts fails
|
|
1426
|
+
* unless both copies are byte-identical. Change them together.
|
|
1427
|
+
*/
|
|
1428
|
+
const WITHDRAWAL_WAIVER_TEXTS = {
|
|
1429
|
+
[PAY_WITHDRAWAL_WAIVER_VERSION]: {
|
|
1430
|
+
en: 'I agree that {seller} starts supplying the digital content immediately, and I acknowledge that I lose my right of withdrawal once supply has begun.',
|
|
1431
|
+
es: 'Acepto que {seller} comience a suministrar el contenido digital de inmediato y reconozco que pierdo mi derecho de desistimiento una vez iniciado el suministro.',
|
|
1432
|
+
'pt-BR': 'Concordo que {seller} comece a fornecer o conteúdo digital imediatamente e reconheço que perco meu direito de arrependimento assim que o fornecimento tiver início.',
|
|
1433
|
+
fr: 'J’accepte que {seller} commence immédiatement la fourniture du contenu numérique et je reconnais perdre mon droit de rétractation dès le début de la fourniture.',
|
|
1434
|
+
de: 'Ich stimme zu, dass {seller} sofort mit der Bereitstellung der digitalen Inhalte beginnt, und ich nehme zur Kenntnis, dass ich mit Beginn der Bereitstellung mein Widerrufsrecht verliere.',
|
|
1435
|
+
it: 'Accetto che {seller} inizi immediatamente la fornitura del contenuto digitale e riconosco di perdere il mio diritto di recesso una volta iniziata la fornitura.',
|
|
1436
|
+
ru: 'Я соглашаюсь с тем, что {seller} немедленно начнёт предоставление цифрового контента, и подтверждаю, что утрачиваю право на отказ от договора с момента начала предоставления.',
|
|
1437
|
+
ja: '{seller}がデジタルコンテンツの提供を直ちに開始することに同意し、提供の開始後は撤回権を失うことを了承します。',
|
|
1438
|
+
ko: '{seller}의 디지털 콘텐츠 제공이 즉시 시작되는 것에 동의하며, 제공이 시작되면 청약철회권을 상실한다는 점을 확인합니다.',
|
|
1439
|
+
'zh-CN': '我同意 {seller} 立即开始提供数字内容,并确认一旦开始提供,我将失去撤回权。',
|
|
1440
|
+
ar: 'أوافق على أن يبدأ {seller} فورًا في تقديم المحتوى الرقمي، وأُقرّ بأنني أفقد حقي في العدول عن العقد بمجرد بدء التقديم.',
|
|
1441
|
+
},
|
|
1442
|
+
};
|
|
1443
|
+
/**
|
|
1444
|
+
* The waiver text to show for `serverVersion`, and the version to send with
|
|
1445
|
+
* the consent. A version this SDK does not know (a newer server) shows this
|
|
1446
|
+
* SDK's current text and sends its version: the consent always names the words
|
|
1447
|
+
* actually shown.
|
|
1448
|
+
*/
|
|
1449
|
+
function withdrawalWaiverText(serverVersion, locale, seller) {
|
|
1450
|
+
// Own keys only: `toString` / `__proto__` from a server are just unknown versions.
|
|
1451
|
+
const known = Object.keys(WITHDRAWAL_WAIVER_TEXTS).includes(serverVersion);
|
|
1452
|
+
const version = known ? serverVersion : PAY_WITHDRAWAL_WAIVER_VERSION;
|
|
1453
|
+
return { version, text: fill(WITHDRAWAL_WAIVER_TEXTS[version][sdkLocale(locale)], { seller }) };
|
|
1454
|
+
}
|
|
1455
|
+
|
|
1303
1456
|
/** Kept in sync with package.json by tests/unit/version.test.ts. */
|
|
1304
|
-
const VERSION = '0.
|
|
1457
|
+
const VERSION = '0.8.0';
|
|
1305
1458
|
|
|
1306
1459
|
const DEFAULT_API_URL = 'https://bff.extenshi.io';
|
|
1307
1460
|
const DEFAULT_CACHE_TTL_MS = 60 * 60 * 1000;
|
|
@@ -1346,7 +1499,10 @@ function resolveConfig(input) {
|
|
|
1346
1499
|
if (!Number.isFinite(cacheTtlMs) || cacheTtlMs < 0 || cacheTtlMs > MAX_CACHE_TTL_MS) {
|
|
1347
1500
|
errors.push(`cacheTtlMs must be between 0 and ${MAX_CACHE_TTL_MS}`);
|
|
1348
1501
|
}
|
|
1349
|
-
|
|
1502
|
+
// Default: the browser UI language, as README promises (it. 13 T10 L2).
|
|
1503
|
+
// `null` still opts out explicitly: prices then use the runtime default
|
|
1504
|
+
// and the paywall reads English.
|
|
1505
|
+
const locale = input.locale === undefined ? browserLocale() : input.locale;
|
|
1350
1506
|
if (locale !== null && !LOCALE_RE.test(locale))
|
|
1351
1507
|
errors.push('locale must be a BCP-47 tag such as en or de-DE');
|
|
1352
1508
|
const theme = input.theme ?? {};
|
|
@@ -1473,6 +1629,7 @@ class ExtenshiPayLite {
|
|
|
1473
1629
|
});
|
|
1474
1630
|
this.recovery = new RecoveryManager({
|
|
1475
1631
|
api: this.api,
|
|
1632
|
+
locale: this.config.locale,
|
|
1476
1633
|
publishableKey: this.config.publishableKey,
|
|
1477
1634
|
storage: deps.recoveryStorage ?? createRecoveryStorage(),
|
|
1478
1635
|
openUrl: deps.openUrl,
|
|
@@ -1595,12 +1752,44 @@ class ExtenshiPayLite {
|
|
|
1595
1752
|
async onFeatureLocked(_feature, _options) {
|
|
1596
1753
|
return false;
|
|
1597
1754
|
}
|
|
1598
|
-
/**
|
|
1755
|
+
/**
|
|
1756
|
+
* The withdrawal waiver this offer asks for, with the exact text to show
|
|
1757
|
+
* next to an unticked checkbox (buyer's language, seller's name filled in),
|
|
1758
|
+
* or null when the seller attested the extension is not distributed in the
|
|
1759
|
+
* EEA/UK. For UIs that call `openCheckout()` themselves — Lite, or a custom
|
|
1760
|
+
* paywall; the full SDK's paywall does this for you.
|
|
1761
|
+
*/
|
|
1762
|
+
async getWithdrawalWaiver() {
|
|
1763
|
+
await this.initialize();
|
|
1764
|
+
try {
|
|
1765
|
+
const offer = await this.fetchOffer();
|
|
1766
|
+
if (!offer.withdrawalWaiver)
|
|
1767
|
+
return null;
|
|
1768
|
+
const seller = offer.seller?.displayName?.trim() || offer.projectName;
|
|
1769
|
+
return withdrawalWaiverText(offer.withdrawalWaiver.version, this.config.locale, seller);
|
|
1770
|
+
}
|
|
1771
|
+
catch (error) {
|
|
1772
|
+
throw this.reportError(error);
|
|
1773
|
+
}
|
|
1774
|
+
}
|
|
1775
|
+
/**
|
|
1776
|
+
* Opens hosted checkout for `sku` in a new tab and resolves when the session settles.
|
|
1777
|
+
*
|
|
1778
|
+
* Called directly (not from the paywall), this does NOT collect the EU/UK
|
|
1779
|
+
* withdrawal waiver. If `getWithdrawalWaiver()` returns one, your UI must
|
|
1780
|
+
* collect the buyer's consent and pass it as `options.withdrawalWaiver`;
|
|
1781
|
+
* without it this rejects with `WITHDRAWAL_WAIVER_REQUIRED` (the server
|
|
1782
|
+
* refuses such a checkout too).
|
|
1783
|
+
*/
|
|
1599
1784
|
async openCheckout(sku, options = {}) {
|
|
1600
1785
|
await this.initialize();
|
|
1601
1786
|
try {
|
|
1602
1787
|
if (this.recovery.isActive())
|
|
1603
1788
|
throw new ExtenshiPayError(ERROR_CODES.INVALID_REQUEST, 'Recovery is in progress');
|
|
1789
|
+
// A cold cache is filled here; if the offer cannot be read, the server decides.
|
|
1790
|
+
const offer = await this.fetchOffer().catch(() => null);
|
|
1791
|
+
if (offer?.withdrawalWaiver && options.withdrawalWaiver?.accepted !== true)
|
|
1792
|
+
throw new ExtenshiPayError(ERROR_CODES.WITHDRAWAL_WAIVER_REQUIRED, 'This offer needs the buyer to accept the withdrawal waiver; pass options.withdrawalWaiver');
|
|
1604
1793
|
return await this.checkout.open(sku, options);
|
|
1605
1794
|
}
|
|
1606
1795
|
catch (error) {
|
|
@@ -1641,7 +1830,7 @@ class ExtenshiPayLite {
|
|
|
1641
1830
|
await this.initialize();
|
|
1642
1831
|
try {
|
|
1643
1832
|
const endUserRef = await this.getEndUserRef();
|
|
1644
|
-
let result = await this.api.getPortalUrl(endUserRef);
|
|
1833
|
+
let result = await this.api.getPortalUrl(endUserRef, undefined, this.config.locale);
|
|
1645
1834
|
if (this.destroyed)
|
|
1646
1835
|
return null;
|
|
1647
1836
|
if (result.accounts?.length) {
|
|
@@ -1655,7 +1844,7 @@ class ExtenshiPayLite {
|
|
|
1655
1844
|
// Recovery may replace this installation while the selector is open.
|
|
1656
1845
|
if (endUserRef !== (await this.getEndUserRef()))
|
|
1657
1846
|
throw new ExtenshiPayError(ERROR_CODES.INVALID_REQUEST, 'Installation changed; open the portal again');
|
|
1658
|
-
result = await this.api.getPortalUrl(endUserRef, customerId);
|
|
1847
|
+
result = await this.api.getPortalUrl(endUserRef, customerId, this.config.locale);
|
|
1659
1848
|
}
|
|
1660
1849
|
if (this.destroyed)
|
|
1661
1850
|
return null;
|
|
@@ -1723,5 +1912,5 @@ ExtenshiPayLite.version = VERSION;
|
|
|
1723
1912
|
|
|
1724
1913
|
// Lite entry point: entitlement + feature gating + hosted checkout, no paywall UI, no getOffer().
|
|
1725
1914
|
|
|
1726
|
-
export { ERROR_CODES, ExtenshiPayLite as ExtenshiPay, ExtenshiPayError, ExtenshiPayLite, MockTransport, VERSION, ExtenshiPayLite as default };
|
|
1915
|
+
export { ERROR_CODES, ExtenshiPayLite as ExtenshiPay, ExtenshiPayError, ExtenshiPayLite, MockTransport, PAY_WITHDRAWAL_WAIVER_VERSION, VERSION, ExtenshiPayLite as default };
|
|
1727
1916
|
//# sourceMappingURL=extenshi-pay-lite.mjs.map
|