@extenshi/pay 0.7.1 → 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 +11 -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 +2 -2
- 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
package/dist/core.js
CHANGED
|
@@ -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
|
(function (global, factory) {
|
|
7
8
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
@@ -51,6 +52,13 @@
|
|
|
51
52
|
* none — never had it
|
|
52
53
|
*/
|
|
53
54
|
const PAY_ENTITLEMENT_STATUSES = ['active', 'grace', 'expired', 'none'];
|
|
55
|
+
/**
|
|
56
|
+
* Version of the buyer-facing withdrawal waiver text the paywall shows (EU/EEA
|
|
57
|
+
* digital content, Directive 2011/83/EU art. 16(m); UK CCR 2013 reg. 37). The
|
|
58
|
+
* text itself lives in the SDK dictionary under the same version; bump both
|
|
59
|
+
* together so a recorded consent always names the words the buyer saw.
|
|
60
|
+
*/
|
|
61
|
+
const PAY_WITHDRAWAL_WAIVER_VERSION = '2026-10-v1';
|
|
54
62
|
/**
|
|
55
63
|
* The `endUserRef` an SDK mints on first run and keeps in `chrome.storage`.
|
|
56
64
|
* Opaque, random, never derived from anything identifying.
|
|
@@ -67,6 +75,7 @@
|
|
|
67
75
|
GATEWAY_UNAVAILABLE: 'PAY_GATEWAY_UNAVAILABLE',
|
|
68
76
|
RATE_LIMITED: 'PAY_RATE_LIMITED',
|
|
69
77
|
INVALID_KEY: 'PAY_INVALID_KEY',
|
|
78
|
+
WITHDRAWAL_WAIVER_REQUIRED: 'PAY_WITHDRAWAL_WAIVER_REQUIRED',
|
|
70
79
|
};
|
|
71
80
|
/**
|
|
72
81
|
* Canonical JSON for signing: keys sorted recursively, no whitespace. Both
|
|
@@ -98,6 +107,7 @@
|
|
|
98
107
|
GATEWAY_UNAVAILABLE: 'GATEWAY_UNAVAILABLE',
|
|
99
108
|
CHECKOUT_UNAVAILABLE: 'CHECKOUT_UNAVAILABLE',
|
|
100
109
|
PAYWALL_UNAVAILABLE: 'PAYWALL_UNAVAILABLE',
|
|
110
|
+
WITHDRAWAL_WAIVER_REQUIRED: 'WITHDRAWAL_WAIVER_REQUIRED',
|
|
101
111
|
UNKNOWN: 'UNKNOWN',
|
|
102
112
|
};
|
|
103
113
|
class ExtenshiPayError extends Error {
|
|
@@ -154,6 +164,13 @@
|
|
|
154
164
|
* mock checkout completes after `claimAfterPolls` polls and grants the SKU.
|
|
155
165
|
*/
|
|
156
166
|
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
167
|
+
/** Accepts the same optional `withdrawalWaiver` input as the BFF; anything else is no consent. */
|
|
168
|
+
function mockConsent(value) {
|
|
169
|
+
const consent = value;
|
|
170
|
+
return consent && typeof consent.version === 'string' && consent.accepted === true
|
|
171
|
+
? { version: consent.version, accepted: true }
|
|
172
|
+
: null;
|
|
173
|
+
}
|
|
157
174
|
class MockTransport {
|
|
158
175
|
constructor(data = {}) {
|
|
159
176
|
this.sessions = new Map();
|
|
@@ -162,13 +179,15 @@
|
|
|
162
179
|
this.projectName = data.projectName ?? 'Mock project';
|
|
163
180
|
this.checkoutEnabled = data.checkoutEnabled ?? true;
|
|
164
181
|
this.claimAfterPolls = data.claimAfterPolls ?? 1;
|
|
182
|
+
this.withdrawalWaiver =
|
|
183
|
+
data.withdrawalWaiver === undefined ? { version: PAY_WITHDRAWAL_WAIVER_VERSION } : data.withdrawalWaiver;
|
|
165
184
|
}
|
|
166
185
|
async call(procedure, _kind, input) {
|
|
167
186
|
switch (procedure) {
|
|
168
187
|
case 'pay.getOffer':
|
|
169
188
|
return this.offerResponse();
|
|
170
189
|
case 'pay.createCheckout':
|
|
171
|
-
return this.createCheckout(String(input.sku));
|
|
190
|
+
return this.createCheckout(String(input.sku), mockConsent(input.withdrawalWaiver));
|
|
172
191
|
case 'pay.claimSession':
|
|
173
192
|
return this.claim(String(input.sessionId), String(input.endUserRef), String(input.publishableKey));
|
|
174
193
|
case 'pay.getEntitlement':
|
|
@@ -201,9 +220,10 @@
|
|
|
201
220
|
checkoutEnabled: this.checkoutEnabled && this.offers.length > 0,
|
|
202
221
|
offers: [...this.offers],
|
|
203
222
|
entitlementPublicKey: null,
|
|
223
|
+
withdrawalWaiver: this.withdrawalWaiver ? { ...this.withdrawalWaiver } : null,
|
|
204
224
|
};
|
|
205
225
|
}
|
|
206
|
-
createCheckout(sku) {
|
|
226
|
+
createCheckout(sku, withdrawalWaiver) {
|
|
207
227
|
if (!this.checkoutEnabled) {
|
|
208
228
|
throw new ExtenshiPayError(ERROR_CODES.SELLER_NOT_ACTIVE, 'Mock seller cannot take payments');
|
|
209
229
|
}
|
|
@@ -211,7 +231,7 @@
|
|
|
211
231
|
throw new ExtenshiPayError(ERROR_CODES.OFFER_NOT_FOUND, `Unknown mock offer ${sku}`);
|
|
212
232
|
}
|
|
213
233
|
const sessionId = mintEndUserRef();
|
|
214
|
-
this.sessions.set(sessionId, { sku, polls: 0, state: 'open' });
|
|
234
|
+
this.sessions.set(sessionId, { sku, polls: 0, state: 'open', withdrawalWaiver });
|
|
215
235
|
return {
|
|
216
236
|
url: `https://mock.extenshi.io/checkout/${sessionId}`,
|
|
217
237
|
sessionId,
|
|
@@ -273,10 +293,12 @@
|
|
|
273
293
|
this.transport = transport;
|
|
274
294
|
this.publishableKey = publishableKey;
|
|
275
295
|
}
|
|
276
|
-
|
|
296
|
+
/** `locale` opens the hosted recovery page (and its email) in the user's language. */
|
|
297
|
+
createRestoreSession(claimChallenge, locale) {
|
|
277
298
|
return this.transport.call('pay.createRestoreSession', 'mutation', {
|
|
278
299
|
publishableKey: this.publishableKey,
|
|
279
300
|
claimChallenge,
|
|
301
|
+
...(locale ? { locale } : {}),
|
|
280
302
|
});
|
|
281
303
|
}
|
|
282
304
|
claimRestoreSession(sessionId, claimSecret) {
|
|
@@ -292,12 +314,20 @@
|
|
|
292
314
|
locale: locale ?? undefined,
|
|
293
315
|
});
|
|
294
316
|
}
|
|
295
|
-
|
|
317
|
+
/**
|
|
318
|
+
* `withdrawalWaiver` is sent only when given. Older BFFs parse the input with
|
|
319
|
+
* a non-strict zod object, which strips the unknown key, so it is safe there.
|
|
320
|
+
* Plain-JS callers passing anything but `accepted: true` send no consent.
|
|
321
|
+
*/
|
|
322
|
+
createCheckout(sku, endUserRef, locale, withdrawalWaiver) {
|
|
296
323
|
return this.transport.call('pay.createCheckout', 'mutation', {
|
|
297
324
|
publishableKey: this.publishableKey,
|
|
298
325
|
sku,
|
|
299
326
|
endUserRef,
|
|
300
327
|
locale: locale ?? undefined,
|
|
328
|
+
...(withdrawalWaiver?.accepted === true && typeof withdrawalWaiver.version === 'string'
|
|
329
|
+
? { withdrawalWaiver: { version: withdrawalWaiver.version, accepted: true } }
|
|
330
|
+
: {}),
|
|
301
331
|
});
|
|
302
332
|
}
|
|
303
333
|
claimSession(sessionId, endUserRef) {
|
|
@@ -313,11 +343,12 @@
|
|
|
313
343
|
endUserRef,
|
|
314
344
|
});
|
|
315
345
|
}
|
|
316
|
-
getPortalUrl(endUserRef, customerId) {
|
|
346
|
+
getPortalUrl(endUserRef, customerId, locale) {
|
|
317
347
|
return this.transport.call('pay.getPortalUrl', 'mutation', {
|
|
318
348
|
publishableKey: this.publishableKey,
|
|
319
349
|
endUserRef,
|
|
320
350
|
...(customerId ? { customerId } : {}),
|
|
351
|
+
...(locale ? { locale } : {}),
|
|
321
352
|
});
|
|
322
353
|
}
|
|
323
354
|
}
|
|
@@ -383,6 +414,7 @@
|
|
|
383
414
|
[PAY_ERRORS.AGREEMENT_REQUIRED]: ERROR_CODES.SELLER_NOT_ACTIVE,
|
|
384
415
|
[PAY_ERRORS.OFFER_NOT_FOUND]: ERROR_CODES.OFFER_NOT_FOUND,
|
|
385
416
|
[PAY_ERRORS.GATEWAY_UNAVAILABLE]: ERROR_CODES.GATEWAY_UNAVAILABLE,
|
|
417
|
+
[PAY_ERRORS.WITHDRAWAL_WAIVER_REQUIRED]: ERROR_CODES.WITHDRAWAL_WAIVER_REQUIRED,
|
|
386
418
|
};
|
|
387
419
|
function parseRetryAfter(message) {
|
|
388
420
|
const match = /retry in (\d+)s/i.exec(message);
|
|
@@ -412,6 +444,8 @@
|
|
|
412
444
|
return new ExtenshiPayError(ERROR_CODES.CHECKOUT_UNAVAILABLE, message, options);
|
|
413
445
|
return new ExtenshiPayError(ERROR_CODES.OFFER_NOT_FOUND, message, options);
|
|
414
446
|
case 'PRECONDITION_FAILED':
|
|
447
|
+
if (/withdrawal/i.test(message))
|
|
448
|
+
return new ExtenshiPayError(ERROR_CODES.WITHDRAWAL_WAIVER_REQUIRED, message, options);
|
|
415
449
|
return new ExtenshiPayError(ERROR_CODES.SELLER_NOT_ACTIVE, message, options);
|
|
416
450
|
case 'BAD_REQUEST':
|
|
417
451
|
return new ExtenshiPayError(ERROR_CODES.INVALID_REQUEST, message, options);
|
|
@@ -594,7 +628,7 @@
|
|
|
594
628
|
throw new ExtenshiPayError(ERROR_CODES.CHECKOUT_UNAVAILABLE, 'A checkout is already in progress');
|
|
595
629
|
}
|
|
596
630
|
const endUserRef = await this.options.getEndUserRef();
|
|
597
|
-
const session = await this.options.api.createCheckout(sku, endUserRef, options.locale ?? this.options.locale);
|
|
631
|
+
const session = await this.options.api.createCheckout(sku, endUserRef, options.locale ?? this.options.locale, options.withdrawalWaiver);
|
|
598
632
|
this.active = session.sessionId;
|
|
599
633
|
try {
|
|
600
634
|
const pending = { sessionId: session.sessionId, sku, expiresAt: session.expiresAt };
|
|
@@ -1238,7 +1272,7 @@
|
|
|
1238
1272
|
const secret = Array.from(cryptoApi.getRandomValues(new Uint8Array(32)), (b) => b.toString(16).padStart(2, '0')).join('');
|
|
1239
1273
|
const hash = await cryptoApi.subtle.digest('SHA-256', new TextEncoder().encode(secret));
|
|
1240
1274
|
const challenge = Array.from(new Uint8Array(hash), (b) => b.toString(16).padStart(2, '0')).join('');
|
|
1241
|
-
const created = await this.options.api.createRestoreSession(challenge);
|
|
1275
|
+
const created = await this.options.api.createRestoreSession(challenge, this.options.locale);
|
|
1242
1276
|
if (!Number.isFinite(Date.parse(created.expiresAt)))
|
|
1243
1277
|
throw new ExtenshiPayError(ERROR_CODES.INVALID_RESPONSE, 'Invalid recovery expiry');
|
|
1244
1278
|
const pending = { sessionId: created.sessionId, expiresAt: created.expiresAt, claimSecret: secret };
|
|
@@ -1330,7 +1364,49 @@
|
|
|
1330
1364
|
const MAX_CACHE_TTL_MS = 7 * 24 * 60 * 60 * 1000;
|
|
1331
1365
|
|
|
1332
1366
|
/** Kept in sync with package.json by tests/unit/version.test.ts. */
|
|
1333
|
-
const VERSION = '0.
|
|
1367
|
+
const VERSION = '0.8.0';
|
|
1368
|
+
|
|
1369
|
+
/**
|
|
1370
|
+
* The user's language as the SDK sends it. Kept apart from the paywall
|
|
1371
|
+
* dictionary (../paywall/i18n.ts) so the Lite and core bundles, which never
|
|
1372
|
+
* render UI, do not carry the translations.
|
|
1373
|
+
*/
|
|
1374
|
+
/** What the backend (and older backends) accept as a locale: `de`, `pt-BR`, `zh-CN`. */
|
|
1375
|
+
const WIRE_LOCALE_RE = /^[a-z]{2}(-[A-Za-z]{2,4})?$/;
|
|
1376
|
+
/**
|
|
1377
|
+
* A browser tag as the SDK sends it: `pt_BR` → `pt-BR`, `es-419` → `es`,
|
|
1378
|
+
* `zh-Hant-TW` → `zh-TW`; null for anything that is not a language tag.
|
|
1379
|
+
*/
|
|
1380
|
+
function wireLocale(raw) {
|
|
1381
|
+
if (typeof raw !== 'string')
|
|
1382
|
+
return null;
|
|
1383
|
+
const parts = raw.trim().replace(/_/g, '-').split('-').filter(Boolean);
|
|
1384
|
+
const lang = parts[0]?.toLowerCase();
|
|
1385
|
+
if (!lang || !/^[a-z]{2}$/.test(lang))
|
|
1386
|
+
return null;
|
|
1387
|
+
const script = parts
|
|
1388
|
+
.slice(1)
|
|
1389
|
+
.find((p) => /^[A-Za-z]{4}$/.test(p))
|
|
1390
|
+
?.toLowerCase();
|
|
1391
|
+
// zh-Hant without a region is Traditional Chinese: keep that, never let it read as zh-CN.
|
|
1392
|
+
const region = parts.slice(1).find((p) => /^[A-Za-z]{2}$/.test(p)) ??
|
|
1393
|
+
(lang === 'zh' && script === 'hant' ? 'TW' : undefined);
|
|
1394
|
+
const tag = region ? `${lang}-${region.toUpperCase()}` : lang;
|
|
1395
|
+
return WIRE_LOCALE_RE.test(tag) ? tag : lang;
|
|
1396
|
+
}
|
|
1397
|
+
/** The browser UI language (`chrome.i18n.getUILanguage()`, else `navigator.language`), or null. */
|
|
1398
|
+
function browserLocale() {
|
|
1399
|
+
const g = globalThis;
|
|
1400
|
+
try {
|
|
1401
|
+
const ui = g.chrome?.i18n?.getUILanguage?.() ?? g.browser?.i18n?.getUILanguage?.();
|
|
1402
|
+
if (ui)
|
|
1403
|
+
return wireLocale(ui);
|
|
1404
|
+
}
|
|
1405
|
+
catch {
|
|
1406
|
+
/* Not an extension context. */
|
|
1407
|
+
}
|
|
1408
|
+
return wireLocale(g.navigator?.language);
|
|
1409
|
+
}
|
|
1334
1410
|
|
|
1335
1411
|
const ENVIRONMENTS = new Set(['production', 'sandbox', 'development']);
|
|
1336
1412
|
const LOG_LEVELS = new Set(['silent', 'error', 'warn', 'info', 'debug']);
|
|
@@ -1371,7 +1447,10 @@
|
|
|
1371
1447
|
if (!Number.isFinite(cacheTtlMs) || cacheTtlMs < 0 || cacheTtlMs > MAX_CACHE_TTL_MS) {
|
|
1372
1448
|
errors.push(`cacheTtlMs must be between 0 and ${MAX_CACHE_TTL_MS}`);
|
|
1373
1449
|
}
|
|
1374
|
-
|
|
1450
|
+
// Default: the browser UI language, as README promises (it. 13 T10 L2).
|
|
1451
|
+
// `null` still opts out explicitly: prices then use the runtime default
|
|
1452
|
+
// and the paywall reads English.
|
|
1453
|
+
const locale = input.locale === undefined ? browserLocale() : input.locale;
|
|
1375
1454
|
if (locale !== null && !LOCALE_RE.test(locale))
|
|
1376
1455
|
errors.push('locale must be a BCP-47 tag such as en or de-DE');
|
|
1377
1456
|
const theme = input.theme ?? {};
|
|
@@ -1442,6 +1521,83 @@
|
|
|
1442
1521
|
}
|
|
1443
1522
|
}
|
|
1444
1523
|
|
|
1524
|
+
/**
|
|
1525
|
+
* Every string the SDK shows to the USER of an extension — paywall, license
|
|
1526
|
+
* dialog, billing-profile picker, seller details — in the end-user languages
|
|
1527
|
+
* (ROADMAP it. 13 T10, stage L2; closes it. 12 T9). Developer-facing error
|
|
1528
|
+
* messages stay English.
|
|
1529
|
+
*
|
|
1530
|
+
* Self-contained on purpose: the SDK ships inside third-party extensions with
|
|
1531
|
+
* no runtime dependencies and no remote code, so the dictionary is compiled
|
|
1532
|
+
* in. Placeholders are `{name}`, `{date}`, `{status}`. A missing
|
|
1533
|
+
* translation falls back to English, never to an empty string. The same
|
|
1534
|
+
* languages as the hosted pages (shared-types END_USER_LOCALES); keep the
|
|
1535
|
+
* lists in sync.
|
|
1536
|
+
*/
|
|
1537
|
+
const SDK_LOCALES = ['en', 'es', 'pt-BR', 'fr', 'de', 'it', 'ru', 'ja', 'ko', 'zh-CN', 'ar'];
|
|
1538
|
+
// END GENERATED TRANSLATIONS
|
|
1539
|
+
/** Our dictionary language for a tag: exact, then pt → pt-BR, zh(-CN/SG/Hans) → zh-CN, then the bare language. */
|
|
1540
|
+
function sdkLocale(locale) {
|
|
1541
|
+
const tag = wireLocale(locale);
|
|
1542
|
+
if (!tag)
|
|
1543
|
+
return 'en';
|
|
1544
|
+
const exact = SDK_LOCALES.find((l) => l.toLowerCase() === tag.toLowerCase());
|
|
1545
|
+
if (exact)
|
|
1546
|
+
return exact;
|
|
1547
|
+
const [lang, region] = tag.split('-');
|
|
1548
|
+
if (lang === 'pt')
|
|
1549
|
+
return 'pt-BR';
|
|
1550
|
+
// Traditional-script regions read English rather than Simplified characters.
|
|
1551
|
+
if (lang === 'zh')
|
|
1552
|
+
return region && ['TW', 'HK', 'MO'].includes(region) ? 'en' : 'zh-CN';
|
|
1553
|
+
return SDK_LOCALES.find((l) => l === lang) ?? 'en';
|
|
1554
|
+
}
|
|
1555
|
+
/** Fill `{placeholders}` once; a value containing braces is inserted literally. */
|
|
1556
|
+
function fill(message, values) {
|
|
1557
|
+
return message.replace(/\{([a-z]+)\}/g, (whole, key) => values[key] ?? whole);
|
|
1558
|
+
}
|
|
1559
|
+
|
|
1560
|
+
/**
|
|
1561
|
+
* Buyer-facing withdrawal-waiver text (EU/EEA digital content, Directive
|
|
1562
|
+
* 2011/83/EU art. 16(m); UK CCR 2013 reg. 37), per text version and SDK
|
|
1563
|
+
* language. Its own module, not part of the paywall dictionary, so Lite can
|
|
1564
|
+
* show it without bundling every paywall string.
|
|
1565
|
+
*
|
|
1566
|
+
* The recorded consent names the version, so a version's words never change:
|
|
1567
|
+
* new wording is a new version here and a new PAY_WITHDRAWAL_WAIVER_VERSION.
|
|
1568
|
+
*
|
|
1569
|
+
* MIRRORED in shared-types/pay-withdrawal-waiver.ts, which the purchase
|
|
1570
|
+
* confirmation email quotes; shared-types/pay-withdrawal-waiver.test.ts fails
|
|
1571
|
+
* unless both copies are byte-identical. Change them together.
|
|
1572
|
+
*/
|
|
1573
|
+
const WITHDRAWAL_WAIVER_TEXTS = {
|
|
1574
|
+
[PAY_WITHDRAWAL_WAIVER_VERSION]: {
|
|
1575
|
+
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.',
|
|
1576
|
+
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.',
|
|
1577
|
+
'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.',
|
|
1578
|
+
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.',
|
|
1579
|
+
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.',
|
|
1580
|
+
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.',
|
|
1581
|
+
ru: 'Я соглашаюсь с тем, что {seller} немедленно начнёт предоставление цифрового контента, и подтверждаю, что утрачиваю право на отказ от договора с момента начала предоставления.',
|
|
1582
|
+
ja: '{seller}がデジタルコンテンツの提供を直ちに開始することに同意し、提供の開始後は撤回権を失うことを了承します。',
|
|
1583
|
+
ko: '{seller}의 디지털 콘텐츠 제공이 즉시 시작되는 것에 동의하며, 제공이 시작되면 청약철회권을 상실한다는 점을 확인합니다.',
|
|
1584
|
+
'zh-CN': '我同意 {seller} 立即开始提供数字内容,并确认一旦开始提供,我将失去撤回权。',
|
|
1585
|
+
ar: 'أوافق على أن يبدأ {seller} فورًا في تقديم المحتوى الرقمي، وأُقرّ بأنني أفقد حقي في العدول عن العقد بمجرد بدء التقديم.',
|
|
1586
|
+
},
|
|
1587
|
+
};
|
|
1588
|
+
/**
|
|
1589
|
+
* The waiver text to show for `serverVersion`, and the version to send with
|
|
1590
|
+
* the consent. A version this SDK does not know (a newer server) shows this
|
|
1591
|
+
* SDK's current text and sends its version: the consent always names the words
|
|
1592
|
+
* actually shown.
|
|
1593
|
+
*/
|
|
1594
|
+
function withdrawalWaiverText(serverVersion, locale, seller) {
|
|
1595
|
+
// Own keys only: `toString` / `__proto__` from a server are just unknown versions.
|
|
1596
|
+
const known = Object.keys(WITHDRAWAL_WAIVER_TEXTS).includes(serverVersion);
|
|
1597
|
+
const version = known ? serverVersion : PAY_WITHDRAWAL_WAIVER_VERSION;
|
|
1598
|
+
return { version, text: fill(WITHDRAWAL_WAIVER_TEXTS[version][sdkLocale(locale)], { seller }) };
|
|
1599
|
+
}
|
|
1600
|
+
|
|
1445
1601
|
/**
|
|
1446
1602
|
* `ExtenshiPayLite` — entitlement, feature gating and hosted checkout, without
|
|
1447
1603
|
* the paywall UI. This is what the `lite` bundle exports; the full `ExtenshiPay`
|
|
@@ -1498,6 +1654,7 @@
|
|
|
1498
1654
|
});
|
|
1499
1655
|
this.recovery = new RecoveryManager({
|
|
1500
1656
|
api: this.api,
|
|
1657
|
+
locale: this.config.locale,
|
|
1501
1658
|
publishableKey: this.config.publishableKey,
|
|
1502
1659
|
storage: deps.recoveryStorage ?? createRecoveryStorage(),
|
|
1503
1660
|
openUrl: deps.openUrl,
|
|
@@ -1620,12 +1777,44 @@
|
|
|
1620
1777
|
async onFeatureLocked(_feature, _options) {
|
|
1621
1778
|
return false;
|
|
1622
1779
|
}
|
|
1623
|
-
/**
|
|
1780
|
+
/**
|
|
1781
|
+
* The withdrawal waiver this offer asks for, with the exact text to show
|
|
1782
|
+
* next to an unticked checkbox (buyer's language, seller's name filled in),
|
|
1783
|
+
* or null when the seller attested the extension is not distributed in the
|
|
1784
|
+
* EEA/UK. For UIs that call `openCheckout()` themselves — Lite, or a custom
|
|
1785
|
+
* paywall; the full SDK's paywall does this for you.
|
|
1786
|
+
*/
|
|
1787
|
+
async getWithdrawalWaiver() {
|
|
1788
|
+
await this.initialize();
|
|
1789
|
+
try {
|
|
1790
|
+
const offer = await this.fetchOffer();
|
|
1791
|
+
if (!offer.withdrawalWaiver)
|
|
1792
|
+
return null;
|
|
1793
|
+
const seller = offer.seller?.displayName?.trim() || offer.projectName;
|
|
1794
|
+
return withdrawalWaiverText(offer.withdrawalWaiver.version, this.config.locale, seller);
|
|
1795
|
+
}
|
|
1796
|
+
catch (error) {
|
|
1797
|
+
throw this.reportError(error);
|
|
1798
|
+
}
|
|
1799
|
+
}
|
|
1800
|
+
/**
|
|
1801
|
+
* Opens hosted checkout for `sku` in a new tab and resolves when the session settles.
|
|
1802
|
+
*
|
|
1803
|
+
* Called directly (not from the paywall), this does NOT collect the EU/UK
|
|
1804
|
+
* withdrawal waiver. If `getWithdrawalWaiver()` returns one, your UI must
|
|
1805
|
+
* collect the buyer's consent and pass it as `options.withdrawalWaiver`;
|
|
1806
|
+
* without it this rejects with `WITHDRAWAL_WAIVER_REQUIRED` (the server
|
|
1807
|
+
* refuses such a checkout too).
|
|
1808
|
+
*/
|
|
1624
1809
|
async openCheckout(sku, options = {}) {
|
|
1625
1810
|
await this.initialize();
|
|
1626
1811
|
try {
|
|
1627
1812
|
if (this.recovery.isActive())
|
|
1628
1813
|
throw new ExtenshiPayError(ERROR_CODES.INVALID_REQUEST, 'Recovery is in progress');
|
|
1814
|
+
// A cold cache is filled here; if the offer cannot be read, the server decides.
|
|
1815
|
+
const offer = await this.fetchOffer().catch(() => null);
|
|
1816
|
+
if (offer?.withdrawalWaiver && options.withdrawalWaiver?.accepted !== true)
|
|
1817
|
+
throw new ExtenshiPayError(ERROR_CODES.WITHDRAWAL_WAIVER_REQUIRED, 'This offer needs the buyer to accept the withdrawal waiver; pass options.withdrawalWaiver');
|
|
1629
1818
|
return await this.checkout.open(sku, options);
|
|
1630
1819
|
}
|
|
1631
1820
|
catch (error) {
|
|
@@ -1666,7 +1855,7 @@
|
|
|
1666
1855
|
await this.initialize();
|
|
1667
1856
|
try {
|
|
1668
1857
|
const endUserRef = await this.getEndUserRef();
|
|
1669
|
-
let result = await this.api.getPortalUrl(endUserRef);
|
|
1858
|
+
let result = await this.api.getPortalUrl(endUserRef, undefined, this.config.locale);
|
|
1670
1859
|
if (this.destroyed)
|
|
1671
1860
|
return null;
|
|
1672
1861
|
if (result.accounts?.length) {
|
|
@@ -1680,7 +1869,7 @@
|
|
|
1680
1869
|
// Recovery may replace this installation while the selector is open.
|
|
1681
1870
|
if (endUserRef !== (await this.getEndUserRef()))
|
|
1682
1871
|
throw new ExtenshiPayError(ERROR_CODES.INVALID_REQUEST, 'Installation changed; open the portal again');
|
|
1683
|
-
result = await this.api.getPortalUrl(endUserRef, customerId);
|
|
1872
|
+
result = await this.api.getPortalUrl(endUserRef, customerId, this.config.locale);
|
|
1684
1873
|
}
|
|
1685
1874
|
if (this.destroyed)
|
|
1686
1875
|
return null;
|
|
@@ -1779,6 +1968,7 @@
|
|
|
1779
1968
|
exports.PAY_PUBLISHABLE_KEY_HEX_LENGTH = PAY_PUBLISHABLE_KEY_HEX_LENGTH;
|
|
1780
1969
|
exports.PAY_PUBLISHABLE_KEY_PREFIX = PAY_PUBLISHABLE_KEY_PREFIX;
|
|
1781
1970
|
exports.PAY_SKU_RE = PAY_SKU_RE;
|
|
1971
|
+
exports.PAY_WITHDRAWAL_WAIVER_VERSION = PAY_WITHDRAWAL_WAIVER_VERSION;
|
|
1782
1972
|
exports.PayApi = PayApi;
|
|
1783
1973
|
exports.RecoveryManager = RecoveryManager;
|
|
1784
1974
|
exports.TRPC_PATH = TRPC_PATH;
|