@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
|
(function (global, factory) {
|
|
7
8
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
@@ -34,6 +35,13 @@
|
|
|
34
35
|
function isPayPublishableKey(value) {
|
|
35
36
|
return typeof value === 'string' && PUBLISHABLE_KEY_RE.test(value);
|
|
36
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Version of the buyer-facing withdrawal waiver text the paywall shows (EU/EEA
|
|
40
|
+
* digital content, Directive 2011/83/EU art. 16(m); UK CCR 2013 reg. 37). The
|
|
41
|
+
* text itself lives in the SDK dictionary under the same version; bump both
|
|
42
|
+
* together so a recorded consent always names the words the buyer saw.
|
|
43
|
+
*/
|
|
44
|
+
const PAY_WITHDRAWAL_WAIVER_VERSION = '2026-10-v1';
|
|
37
45
|
/**
|
|
38
46
|
* The `endUserRef` an SDK mints on first run and keeps in `chrome.storage`.
|
|
39
47
|
* Opaque, random, never derived from anything identifying.
|
|
@@ -48,6 +56,7 @@
|
|
|
48
56
|
GATEWAY_UNAVAILABLE: 'PAY_GATEWAY_UNAVAILABLE',
|
|
49
57
|
RATE_LIMITED: 'PAY_RATE_LIMITED',
|
|
50
58
|
INVALID_KEY: 'PAY_INVALID_KEY',
|
|
59
|
+
WITHDRAWAL_WAIVER_REQUIRED: 'PAY_WITHDRAWAL_WAIVER_REQUIRED',
|
|
51
60
|
};
|
|
52
61
|
/**
|
|
53
62
|
* Canonical JSON for signing: keys sorted recursively, no whitespace. Both
|
|
@@ -79,6 +88,7 @@
|
|
|
79
88
|
GATEWAY_UNAVAILABLE: 'GATEWAY_UNAVAILABLE',
|
|
80
89
|
CHECKOUT_UNAVAILABLE: 'CHECKOUT_UNAVAILABLE',
|
|
81
90
|
PAYWALL_UNAVAILABLE: 'PAYWALL_UNAVAILABLE',
|
|
91
|
+
WITHDRAWAL_WAIVER_REQUIRED: 'WITHDRAWAL_WAIVER_REQUIRED',
|
|
82
92
|
UNKNOWN: 'UNKNOWN',
|
|
83
93
|
};
|
|
84
94
|
class ExtenshiPayError extends Error {
|
|
@@ -135,6 +145,13 @@
|
|
|
135
145
|
* mock checkout completes after `claimAfterPolls` polls and grants the SKU.
|
|
136
146
|
*/
|
|
137
147
|
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
148
|
+
/** Accepts the same optional `withdrawalWaiver` input as the BFF; anything else is no consent. */
|
|
149
|
+
function mockConsent(value) {
|
|
150
|
+
const consent = value;
|
|
151
|
+
return consent && typeof consent.version === 'string' && consent.accepted === true
|
|
152
|
+
? { version: consent.version, accepted: true }
|
|
153
|
+
: null;
|
|
154
|
+
}
|
|
138
155
|
class MockTransport {
|
|
139
156
|
constructor(data = {}) {
|
|
140
157
|
this.sessions = new Map();
|
|
@@ -143,13 +160,15 @@
|
|
|
143
160
|
this.projectName = data.projectName ?? 'Mock project';
|
|
144
161
|
this.checkoutEnabled = data.checkoutEnabled ?? true;
|
|
145
162
|
this.claimAfterPolls = data.claimAfterPolls ?? 1;
|
|
163
|
+
this.withdrawalWaiver =
|
|
164
|
+
data.withdrawalWaiver === undefined ? { version: PAY_WITHDRAWAL_WAIVER_VERSION } : data.withdrawalWaiver;
|
|
146
165
|
}
|
|
147
166
|
async call(procedure, _kind, input) {
|
|
148
167
|
switch (procedure) {
|
|
149
168
|
case 'pay.getOffer':
|
|
150
169
|
return this.offerResponse();
|
|
151
170
|
case 'pay.createCheckout':
|
|
152
|
-
return this.createCheckout(String(input.sku));
|
|
171
|
+
return this.createCheckout(String(input.sku), mockConsent(input.withdrawalWaiver));
|
|
153
172
|
case 'pay.claimSession':
|
|
154
173
|
return this.claim(String(input.sessionId), String(input.endUserRef), String(input.publishableKey));
|
|
155
174
|
case 'pay.getEntitlement':
|
|
@@ -182,9 +201,10 @@
|
|
|
182
201
|
checkoutEnabled: this.checkoutEnabled && this.offers.length > 0,
|
|
183
202
|
offers: [...this.offers],
|
|
184
203
|
entitlementPublicKey: null,
|
|
204
|
+
withdrawalWaiver: this.withdrawalWaiver ? { ...this.withdrawalWaiver } : null,
|
|
185
205
|
};
|
|
186
206
|
}
|
|
187
|
-
createCheckout(sku) {
|
|
207
|
+
createCheckout(sku, withdrawalWaiver) {
|
|
188
208
|
if (!this.checkoutEnabled) {
|
|
189
209
|
throw new ExtenshiPayError(ERROR_CODES.SELLER_NOT_ACTIVE, 'Mock seller cannot take payments');
|
|
190
210
|
}
|
|
@@ -192,7 +212,7 @@
|
|
|
192
212
|
throw new ExtenshiPayError(ERROR_CODES.OFFER_NOT_FOUND, `Unknown mock offer ${sku}`);
|
|
193
213
|
}
|
|
194
214
|
const sessionId = mintEndUserRef();
|
|
195
|
-
this.sessions.set(sessionId, { sku, polls: 0, state: 'open' });
|
|
215
|
+
this.sessions.set(sessionId, { sku, polls: 0, state: 'open', withdrawalWaiver });
|
|
196
216
|
return {
|
|
197
217
|
url: `https://mock.extenshi.io/checkout/${sessionId}`,
|
|
198
218
|
sessionId,
|
|
@@ -254,10 +274,12 @@
|
|
|
254
274
|
this.transport = transport;
|
|
255
275
|
this.publishableKey = publishableKey;
|
|
256
276
|
}
|
|
257
|
-
|
|
277
|
+
/** `locale` opens the hosted recovery page (and its email) in the user's language. */
|
|
278
|
+
createRestoreSession(claimChallenge, locale) {
|
|
258
279
|
return this.transport.call('pay.createRestoreSession', 'mutation', {
|
|
259
280
|
publishableKey: this.publishableKey,
|
|
260
281
|
claimChallenge,
|
|
282
|
+
...(locale ? { locale } : {}),
|
|
261
283
|
});
|
|
262
284
|
}
|
|
263
285
|
claimRestoreSession(sessionId, claimSecret) {
|
|
@@ -273,12 +295,20 @@
|
|
|
273
295
|
locale: locale ?? undefined,
|
|
274
296
|
});
|
|
275
297
|
}
|
|
276
|
-
|
|
298
|
+
/**
|
|
299
|
+
* `withdrawalWaiver` is sent only when given. Older BFFs parse the input with
|
|
300
|
+
* a non-strict zod object, which strips the unknown key, so it is safe there.
|
|
301
|
+
* Plain-JS callers passing anything but `accepted: true` send no consent.
|
|
302
|
+
*/
|
|
303
|
+
createCheckout(sku, endUserRef, locale, withdrawalWaiver) {
|
|
277
304
|
return this.transport.call('pay.createCheckout', 'mutation', {
|
|
278
305
|
publishableKey: this.publishableKey,
|
|
279
306
|
sku,
|
|
280
307
|
endUserRef,
|
|
281
308
|
locale: locale ?? undefined,
|
|
309
|
+
...(withdrawalWaiver?.accepted === true && typeof withdrawalWaiver.version === 'string'
|
|
310
|
+
? { withdrawalWaiver: { version: withdrawalWaiver.version, accepted: true } }
|
|
311
|
+
: {}),
|
|
282
312
|
});
|
|
283
313
|
}
|
|
284
314
|
claimSession(sessionId, endUserRef) {
|
|
@@ -294,11 +324,12 @@
|
|
|
294
324
|
endUserRef,
|
|
295
325
|
});
|
|
296
326
|
}
|
|
297
|
-
getPortalUrl(endUserRef, customerId) {
|
|
327
|
+
getPortalUrl(endUserRef, customerId, locale) {
|
|
298
328
|
return this.transport.call('pay.getPortalUrl', 'mutation', {
|
|
299
329
|
publishableKey: this.publishableKey,
|
|
300
330
|
endUserRef,
|
|
301
331
|
...(customerId ? { customerId } : {}),
|
|
332
|
+
...(locale ? { locale } : {}),
|
|
302
333
|
});
|
|
303
334
|
}
|
|
304
335
|
}
|
|
@@ -364,6 +395,7 @@
|
|
|
364
395
|
[PAY_ERRORS.AGREEMENT_REQUIRED]: ERROR_CODES.SELLER_NOT_ACTIVE,
|
|
365
396
|
[PAY_ERRORS.OFFER_NOT_FOUND]: ERROR_CODES.OFFER_NOT_FOUND,
|
|
366
397
|
[PAY_ERRORS.GATEWAY_UNAVAILABLE]: ERROR_CODES.GATEWAY_UNAVAILABLE,
|
|
398
|
+
[PAY_ERRORS.WITHDRAWAL_WAIVER_REQUIRED]: ERROR_CODES.WITHDRAWAL_WAIVER_REQUIRED,
|
|
367
399
|
};
|
|
368
400
|
function parseRetryAfter(message) {
|
|
369
401
|
const match = /retry in (\d+)s/i.exec(message);
|
|
@@ -393,6 +425,8 @@
|
|
|
393
425
|
return new ExtenshiPayError(ERROR_CODES.CHECKOUT_UNAVAILABLE, message, options);
|
|
394
426
|
return new ExtenshiPayError(ERROR_CODES.OFFER_NOT_FOUND, message, options);
|
|
395
427
|
case 'PRECONDITION_FAILED':
|
|
428
|
+
if (/withdrawal/i.test(message))
|
|
429
|
+
return new ExtenshiPayError(ERROR_CODES.WITHDRAWAL_WAIVER_REQUIRED, message, options);
|
|
396
430
|
return new ExtenshiPayError(ERROR_CODES.SELLER_NOT_ACTIVE, message, options);
|
|
397
431
|
case 'BAD_REQUEST':
|
|
398
432
|
return new ExtenshiPayError(ERROR_CODES.INVALID_REQUEST, message, options);
|
|
@@ -575,7 +609,7 @@
|
|
|
575
609
|
throw new ExtenshiPayError(ERROR_CODES.CHECKOUT_UNAVAILABLE, 'A checkout is already in progress');
|
|
576
610
|
}
|
|
577
611
|
const endUserRef = await this.options.getEndUserRef();
|
|
578
|
-
const session = await this.options.api.createCheckout(sku, endUserRef, options.locale ?? this.options.locale);
|
|
612
|
+
const session = await this.options.api.createCheckout(sku, endUserRef, options.locale ?? this.options.locale, options.withdrawalWaiver);
|
|
579
613
|
this.active = session.sessionId;
|
|
580
614
|
try {
|
|
581
615
|
const pending = { sessionId: session.sessionId, sku, expiresAt: session.expiresAt };
|
|
@@ -1219,7 +1253,7 @@
|
|
|
1219
1253
|
const secret = Array.from(cryptoApi.getRandomValues(new Uint8Array(32)), (b) => b.toString(16).padStart(2, '0')).join('');
|
|
1220
1254
|
const hash = await cryptoApi.subtle.digest('SHA-256', new TextEncoder().encode(secret));
|
|
1221
1255
|
const challenge = Array.from(new Uint8Array(hash), (b) => b.toString(16).padStart(2, '0')).join('');
|
|
1222
|
-
const created = await this.options.api.createRestoreSession(challenge);
|
|
1256
|
+
const created = await this.options.api.createRestoreSession(challenge, this.options.locale);
|
|
1223
1257
|
if (!Number.isFinite(Date.parse(created.expiresAt)))
|
|
1224
1258
|
throw new ExtenshiPayError(ERROR_CODES.INVALID_RESPONSE, 'Invalid recovery expiry');
|
|
1225
1259
|
const pending = { sessionId: created.sessionId, expiresAt: created.expiresAt, claimSecret: secret };
|
|
@@ -1306,8 +1340,127 @@
|
|
|
1306
1340
|
}
|
|
1307
1341
|
}
|
|
1308
1342
|
|
|
1343
|
+
/**
|
|
1344
|
+
* The user's language as the SDK sends it. Kept apart from the paywall
|
|
1345
|
+
* dictionary (../paywall/i18n.ts) so the Lite and core bundles, which never
|
|
1346
|
+
* render UI, do not carry the translations.
|
|
1347
|
+
*/
|
|
1348
|
+
/** What the backend (and older backends) accept as a locale: `de`, `pt-BR`, `zh-CN`. */
|
|
1349
|
+
const WIRE_LOCALE_RE = /^[a-z]{2}(-[A-Za-z]{2,4})?$/;
|
|
1350
|
+
/**
|
|
1351
|
+
* A browser tag as the SDK sends it: `pt_BR` → `pt-BR`, `es-419` → `es`,
|
|
1352
|
+
* `zh-Hant-TW` → `zh-TW`; null for anything that is not a language tag.
|
|
1353
|
+
*/
|
|
1354
|
+
function wireLocale(raw) {
|
|
1355
|
+
if (typeof raw !== 'string')
|
|
1356
|
+
return null;
|
|
1357
|
+
const parts = raw.trim().replace(/_/g, '-').split('-').filter(Boolean);
|
|
1358
|
+
const lang = parts[0]?.toLowerCase();
|
|
1359
|
+
if (!lang || !/^[a-z]{2}$/.test(lang))
|
|
1360
|
+
return null;
|
|
1361
|
+
const script = parts
|
|
1362
|
+
.slice(1)
|
|
1363
|
+
.find((p) => /^[A-Za-z]{4}$/.test(p))
|
|
1364
|
+
?.toLowerCase();
|
|
1365
|
+
// zh-Hant without a region is Traditional Chinese: keep that, never let it read as zh-CN.
|
|
1366
|
+
const region = parts.slice(1).find((p) => /^[A-Za-z]{2}$/.test(p)) ??
|
|
1367
|
+
(lang === 'zh' && script === 'hant' ? 'TW' : undefined);
|
|
1368
|
+
const tag = region ? `${lang}-${region.toUpperCase()}` : lang;
|
|
1369
|
+
return WIRE_LOCALE_RE.test(tag) ? tag : lang;
|
|
1370
|
+
}
|
|
1371
|
+
/** The browser UI language (`chrome.i18n.getUILanguage()`, else `navigator.language`), or null. */
|
|
1372
|
+
function browserLocale() {
|
|
1373
|
+
const g = globalThis;
|
|
1374
|
+
try {
|
|
1375
|
+
const ui = g.chrome?.i18n?.getUILanguage?.() ?? g.browser?.i18n?.getUILanguage?.();
|
|
1376
|
+
if (ui)
|
|
1377
|
+
return wireLocale(ui);
|
|
1378
|
+
}
|
|
1379
|
+
catch {
|
|
1380
|
+
/* Not an extension context. */
|
|
1381
|
+
}
|
|
1382
|
+
return wireLocale(g.navigator?.language);
|
|
1383
|
+
}
|
|
1384
|
+
|
|
1385
|
+
/**
|
|
1386
|
+
* Every string the SDK shows to the USER of an extension — paywall, license
|
|
1387
|
+
* dialog, billing-profile picker, seller details — in the end-user languages
|
|
1388
|
+
* (ROADMAP it. 13 T10, stage L2; closes it. 12 T9). Developer-facing error
|
|
1389
|
+
* messages stay English.
|
|
1390
|
+
*
|
|
1391
|
+
* Self-contained on purpose: the SDK ships inside third-party extensions with
|
|
1392
|
+
* no runtime dependencies and no remote code, so the dictionary is compiled
|
|
1393
|
+
* in. Placeholders are `{name}`, `{date}`, `{status}`. A missing
|
|
1394
|
+
* translation falls back to English, never to an empty string. The same
|
|
1395
|
+
* languages as the hosted pages (shared-types END_USER_LOCALES); keep the
|
|
1396
|
+
* lists in sync.
|
|
1397
|
+
*/
|
|
1398
|
+
const SDK_LOCALES = ['en', 'es', 'pt-BR', 'fr', 'de', 'it', 'ru', 'ja', 'ko', 'zh-CN', 'ar'];
|
|
1399
|
+
// END GENERATED TRANSLATIONS
|
|
1400
|
+
/** Our dictionary language for a tag: exact, then pt → pt-BR, zh(-CN/SG/Hans) → zh-CN, then the bare language. */
|
|
1401
|
+
function sdkLocale(locale) {
|
|
1402
|
+
const tag = wireLocale(locale);
|
|
1403
|
+
if (!tag)
|
|
1404
|
+
return 'en';
|
|
1405
|
+
const exact = SDK_LOCALES.find((l) => l.toLowerCase() === tag.toLowerCase());
|
|
1406
|
+
if (exact)
|
|
1407
|
+
return exact;
|
|
1408
|
+
const [lang, region] = tag.split('-');
|
|
1409
|
+
if (lang === 'pt')
|
|
1410
|
+
return 'pt-BR';
|
|
1411
|
+
// Traditional-script regions read English rather than Simplified characters.
|
|
1412
|
+
if (lang === 'zh')
|
|
1413
|
+
return region && ['TW', 'HK', 'MO'].includes(region) ? 'en' : 'zh-CN';
|
|
1414
|
+
return SDK_LOCALES.find((l) => l === lang) ?? 'en';
|
|
1415
|
+
}
|
|
1416
|
+
/** Fill `{placeholders}` once; a value containing braces is inserted literally. */
|
|
1417
|
+
function fill(message, values) {
|
|
1418
|
+
return message.replace(/\{([a-z]+)\}/g, (whole, key) => values[key] ?? whole);
|
|
1419
|
+
}
|
|
1420
|
+
|
|
1421
|
+
/**
|
|
1422
|
+
* Buyer-facing withdrawal-waiver text (EU/EEA digital content, Directive
|
|
1423
|
+
* 2011/83/EU art. 16(m); UK CCR 2013 reg. 37), per text version and SDK
|
|
1424
|
+
* language. Its own module, not part of the paywall dictionary, so Lite can
|
|
1425
|
+
* show it without bundling every paywall string.
|
|
1426
|
+
*
|
|
1427
|
+
* The recorded consent names the version, so a version's words never change:
|
|
1428
|
+
* new wording is a new version here and a new PAY_WITHDRAWAL_WAIVER_VERSION.
|
|
1429
|
+
*
|
|
1430
|
+
* MIRRORED in shared-types/pay-withdrawal-waiver.ts, which the purchase
|
|
1431
|
+
* confirmation email quotes; shared-types/pay-withdrawal-waiver.test.ts fails
|
|
1432
|
+
* unless both copies are byte-identical. Change them together.
|
|
1433
|
+
*/
|
|
1434
|
+
const WITHDRAWAL_WAIVER_TEXTS = {
|
|
1435
|
+
[PAY_WITHDRAWAL_WAIVER_VERSION]: {
|
|
1436
|
+
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.',
|
|
1437
|
+
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.',
|
|
1438
|
+
'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.',
|
|
1439
|
+
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.',
|
|
1440
|
+
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.',
|
|
1441
|
+
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.',
|
|
1442
|
+
ru: 'Я соглашаюсь с тем, что {seller} немедленно начнёт предоставление цифрового контента, и подтверждаю, что утрачиваю право на отказ от договора с момента начала предоставления.',
|
|
1443
|
+
ja: '{seller}がデジタルコンテンツの提供を直ちに開始することに同意し、提供の開始後は撤回権を失うことを了承します。',
|
|
1444
|
+
ko: '{seller}의 디지털 콘텐츠 제공이 즉시 시작되는 것에 동의하며, 제공이 시작되면 청약철회권을 상실한다는 점을 확인합니다.',
|
|
1445
|
+
'zh-CN': '我同意 {seller} 立即开始提供数字内容,并确认一旦开始提供,我将失去撤回权。',
|
|
1446
|
+
ar: 'أوافق على أن يبدأ {seller} فورًا في تقديم المحتوى الرقمي، وأُقرّ بأنني أفقد حقي في العدول عن العقد بمجرد بدء التقديم.',
|
|
1447
|
+
},
|
|
1448
|
+
};
|
|
1449
|
+
/**
|
|
1450
|
+
* The waiver text to show for `serverVersion`, and the version to send with
|
|
1451
|
+
* the consent. A version this SDK does not know (a newer server) shows this
|
|
1452
|
+
* SDK's current text and sends its version: the consent always names the words
|
|
1453
|
+
* actually shown.
|
|
1454
|
+
*/
|
|
1455
|
+
function withdrawalWaiverText(serverVersion, locale, seller) {
|
|
1456
|
+
// Own keys only: `toString` / `__proto__` from a server are just unknown versions.
|
|
1457
|
+
const known = Object.keys(WITHDRAWAL_WAIVER_TEXTS).includes(serverVersion);
|
|
1458
|
+
const version = known ? serverVersion : PAY_WITHDRAWAL_WAIVER_VERSION;
|
|
1459
|
+
return { version, text: fill(WITHDRAWAL_WAIVER_TEXTS[version][sdkLocale(locale)], { seller }) };
|
|
1460
|
+
}
|
|
1461
|
+
|
|
1309
1462
|
/** Kept in sync with package.json by tests/unit/version.test.ts. */
|
|
1310
|
-
const VERSION = '0.
|
|
1463
|
+
const VERSION = '0.8.0';
|
|
1311
1464
|
|
|
1312
1465
|
const DEFAULT_API_URL = 'https://bff.extenshi.io';
|
|
1313
1466
|
const DEFAULT_CACHE_TTL_MS = 60 * 60 * 1000;
|
|
@@ -1352,7 +1505,10 @@
|
|
|
1352
1505
|
if (!Number.isFinite(cacheTtlMs) || cacheTtlMs < 0 || cacheTtlMs > MAX_CACHE_TTL_MS) {
|
|
1353
1506
|
errors.push(`cacheTtlMs must be between 0 and ${MAX_CACHE_TTL_MS}`);
|
|
1354
1507
|
}
|
|
1355
|
-
|
|
1508
|
+
// Default: the browser UI language, as README promises (it. 13 T10 L2).
|
|
1509
|
+
// `null` still opts out explicitly: prices then use the runtime default
|
|
1510
|
+
// and the paywall reads English.
|
|
1511
|
+
const locale = input.locale === undefined ? browserLocale() : input.locale;
|
|
1356
1512
|
if (locale !== null && !LOCALE_RE.test(locale))
|
|
1357
1513
|
errors.push('locale must be a BCP-47 tag such as en or de-DE');
|
|
1358
1514
|
const theme = input.theme ?? {};
|
|
@@ -1479,6 +1635,7 @@
|
|
|
1479
1635
|
});
|
|
1480
1636
|
this.recovery = new RecoveryManager({
|
|
1481
1637
|
api: this.api,
|
|
1638
|
+
locale: this.config.locale,
|
|
1482
1639
|
publishableKey: this.config.publishableKey,
|
|
1483
1640
|
storage: deps.recoveryStorage ?? createRecoveryStorage(),
|
|
1484
1641
|
openUrl: deps.openUrl,
|
|
@@ -1601,12 +1758,44 @@
|
|
|
1601
1758
|
async onFeatureLocked(_feature, _options) {
|
|
1602
1759
|
return false;
|
|
1603
1760
|
}
|
|
1604
|
-
/**
|
|
1761
|
+
/**
|
|
1762
|
+
* The withdrawal waiver this offer asks for, with the exact text to show
|
|
1763
|
+
* next to an unticked checkbox (buyer's language, seller's name filled in),
|
|
1764
|
+
* or null when the seller attested the extension is not distributed in the
|
|
1765
|
+
* EEA/UK. For UIs that call `openCheckout()` themselves — Lite, or a custom
|
|
1766
|
+
* paywall; the full SDK's paywall does this for you.
|
|
1767
|
+
*/
|
|
1768
|
+
async getWithdrawalWaiver() {
|
|
1769
|
+
await this.initialize();
|
|
1770
|
+
try {
|
|
1771
|
+
const offer = await this.fetchOffer();
|
|
1772
|
+
if (!offer.withdrawalWaiver)
|
|
1773
|
+
return null;
|
|
1774
|
+
const seller = offer.seller?.displayName?.trim() || offer.projectName;
|
|
1775
|
+
return withdrawalWaiverText(offer.withdrawalWaiver.version, this.config.locale, seller);
|
|
1776
|
+
}
|
|
1777
|
+
catch (error) {
|
|
1778
|
+
throw this.reportError(error);
|
|
1779
|
+
}
|
|
1780
|
+
}
|
|
1781
|
+
/**
|
|
1782
|
+
* Opens hosted checkout for `sku` in a new tab and resolves when the session settles.
|
|
1783
|
+
*
|
|
1784
|
+
* Called directly (not from the paywall), this does NOT collect the EU/UK
|
|
1785
|
+
* withdrawal waiver. If `getWithdrawalWaiver()` returns one, your UI must
|
|
1786
|
+
* collect the buyer's consent and pass it as `options.withdrawalWaiver`;
|
|
1787
|
+
* without it this rejects with `WITHDRAWAL_WAIVER_REQUIRED` (the server
|
|
1788
|
+
* refuses such a checkout too).
|
|
1789
|
+
*/
|
|
1605
1790
|
async openCheckout(sku, options = {}) {
|
|
1606
1791
|
await this.initialize();
|
|
1607
1792
|
try {
|
|
1608
1793
|
if (this.recovery.isActive())
|
|
1609
1794
|
throw new ExtenshiPayError(ERROR_CODES.INVALID_REQUEST, 'Recovery is in progress');
|
|
1795
|
+
// A cold cache is filled here; if the offer cannot be read, the server decides.
|
|
1796
|
+
const offer = await this.fetchOffer().catch(() => null);
|
|
1797
|
+
if (offer?.withdrawalWaiver && options.withdrawalWaiver?.accepted !== true)
|
|
1798
|
+
throw new ExtenshiPayError(ERROR_CODES.WITHDRAWAL_WAIVER_REQUIRED, 'This offer needs the buyer to accept the withdrawal waiver; pass options.withdrawalWaiver');
|
|
1610
1799
|
return await this.checkout.open(sku, options);
|
|
1611
1800
|
}
|
|
1612
1801
|
catch (error) {
|
|
@@ -1647,7 +1836,7 @@
|
|
|
1647
1836
|
await this.initialize();
|
|
1648
1837
|
try {
|
|
1649
1838
|
const endUserRef = await this.getEndUserRef();
|
|
1650
|
-
let result = await this.api.getPortalUrl(endUserRef);
|
|
1839
|
+
let result = await this.api.getPortalUrl(endUserRef, undefined, this.config.locale);
|
|
1651
1840
|
if (this.destroyed)
|
|
1652
1841
|
return null;
|
|
1653
1842
|
if (result.accounts?.length) {
|
|
@@ -1661,7 +1850,7 @@
|
|
|
1661
1850
|
// Recovery may replace this installation while the selector is open.
|
|
1662
1851
|
if (endUserRef !== (await this.getEndUserRef()))
|
|
1663
1852
|
throw new ExtenshiPayError(ERROR_CODES.INVALID_REQUEST, 'Installation changed; open the portal again');
|
|
1664
|
-
result = await this.api.getPortalUrl(endUserRef, customerId);
|
|
1853
|
+
result = await this.api.getPortalUrl(endUserRef, customerId, this.config.locale);
|
|
1665
1854
|
}
|
|
1666
1855
|
if (this.destroyed)
|
|
1667
1856
|
return null;
|
|
@@ -1734,6 +1923,7 @@
|
|
|
1734
1923
|
exports.ExtenshiPayError = ExtenshiPayError;
|
|
1735
1924
|
exports.ExtenshiPayLite = ExtenshiPayLite;
|
|
1736
1925
|
exports.MockTransport = MockTransport;
|
|
1926
|
+
exports.PAY_WITHDRAWAL_WAIVER_VERSION = PAY_WITHDRAWAL_WAIVER_VERSION;
|
|
1737
1927
|
exports.VERSION = VERSION;
|
|
1738
1928
|
exports.default = ExtenshiPayLite;
|
|
1739
1929
|
|