@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.
Files changed (86) hide show
  1. package/README.md +13 -9
  2. package/dist/api/mock.d.ts +4 -0
  3. package/dist/api/mock.d.ts.map +1 -1
  4. package/dist/api/pay-api.d.ts +10 -3
  5. package/dist/api/pay-api.d.ts.map +1 -1
  6. package/dist/api/transport.d.ts.map +1 -1
  7. package/dist/core/config.d.ts.map +1 -1
  8. package/dist/core/extenshi-pay.d.ts +21 -2
  9. package/dist/core/extenshi-pay.d.ts.map +1 -1
  10. package/dist/core/locale.d.ts +13 -0
  11. package/dist/core/locale.d.ts.map +1 -0
  12. package/dist/core.d.mts +208 -113
  13. package/dist/core.d.ts +208 -113
  14. package/dist/core.js +204 -14
  15. package/dist/core.js.map +1 -1
  16. package/dist/core.mjs +204 -15
  17. package/dist/core.mjs.map +1 -1
  18. package/dist/extenshi-pay-lite.js +204 -14
  19. package/dist/extenshi-pay-lite.js.map +1 -1
  20. package/dist/extenshi-pay-lite.min.js +3 -2
  21. package/dist/extenshi-pay-lite.min.js.map +1 -1
  22. package/dist/extenshi-pay-lite.mjs +204 -15
  23. package/dist/extenshi-pay-lite.mjs.map +1 -1
  24. package/dist/extenshi-pay.cjs.js +1234 -180
  25. package/dist/extenshi-pay.cjs.js.map +1 -1
  26. package/dist/extenshi-pay.d.ts.map +1 -1
  27. package/dist/extenshi-pay.js +1234 -180
  28. package/dist/extenshi-pay.js.map +1 -1
  29. package/dist/extenshi-pay.min.js +3 -2
  30. package/dist/extenshi-pay.min.js.map +1 -1
  31. package/dist/extenshi-pay.min.mjs +3 -2
  32. package/dist/extenshi-pay.min.mjs.map +1 -1
  33. package/dist/extenshi-pay.mjs +1231 -181
  34. package/dist/extenshi-pay.mjs.map +1 -1
  35. package/dist/index.d.mts +268 -117
  36. package/dist/index.d.ts +268 -117
  37. package/dist/lite.d.mts +176 -82
  38. package/dist/lite.d.ts +176 -82
  39. package/dist/lite.d.ts.map +1 -1
  40. package/dist/payment/checkout.d.ts.map +1 -1
  41. package/dist/payment/recovery.d.ts +2 -0
  42. package/dist/payment/recovery.d.ts.map +1 -1
  43. package/dist/payment/withdrawal-waiver.d.ts +26 -0
  44. package/dist/payment/withdrawal-waiver.d.ts.map +1 -0
  45. package/dist/paywall/billing-profile-picker.d.ts +1 -1
  46. package/dist/paywall/billing-profile-picker.d.ts.map +1 -1
  47. package/dist/paywall/i18n.d.ts +94 -0
  48. package/dist/paywall/i18n.d.ts.map +1 -0
  49. package/dist/paywall/index.d.ts +2 -1
  50. package/dist/paywall/index.d.ts.map +1 -1
  51. package/dist/paywall/license-panel.d.ts +4 -1
  52. package/dist/paywall/license-panel.d.ts.map +1 -1
  53. package/dist/paywall/renderer.d.ts +16 -2
  54. package/dist/paywall/renderer.d.ts.map +1 -1
  55. package/dist/paywall/seller-details.d.ts +2 -1
  56. package/dist/paywall/seller-details.d.ts.map +1 -1
  57. package/dist/paywall/strings.d.ts +6 -4
  58. package/dist/paywall/strings.d.ts.map +1 -1
  59. package/dist/paywall.d.mts +93 -7
  60. package/dist/paywall.d.ts +93 -7
  61. package/dist/paywall.js +992 -41
  62. package/dist/paywall.js.map +1 -1
  63. package/dist/paywall.mjs +990 -42
  64. package/dist/paywall.mjs.map +1 -1
  65. package/dist/types/config.d.ts +6 -1
  66. package/dist/types/config.d.ts.map +1 -1
  67. package/dist/types/contract.d.ts +25 -0
  68. package/dist/types/contract.d.ts.map +1 -1
  69. package/dist/types/entitlement.d.ts +22 -0
  70. package/dist/types/entitlement.d.ts.map +1 -1
  71. package/dist/types/errors.d.ts +1 -0
  72. package/dist/types/errors.d.ts.map +1 -1
  73. package/dist/types/paywall.d.ts +15 -2
  74. package/dist/types/paywall.d.ts.map +1 -1
  75. package/dist/version.d.ts +1 -1
  76. package/package.json +3 -11
  77. package/dist/core.esm.js +0 -1681
  78. package/dist/core.esm.js.map +0 -1
  79. package/dist/extenshi-pay-lite.esm.js +0 -1664
  80. package/dist/extenshi-pay-lite.esm.js.map +0 -1
  81. package/dist/extenshi-pay.esm.js +0 -2496
  82. package/dist/extenshi-pay.esm.js.map +0 -1
  83. package/dist/extenshi-pay.esm.min.js +0 -7
  84. package/dist/extenshi-pay.esm.min.js.map +0 -1
  85. package/dist/paywall.esm.js +0 -442
  86. package/dist/paywall.esm.js.map +0 -1
package/dist/core.mjs CHANGED
@@ -1,7 +1,8 @@
1
1
  /*!
2
- * ExtenshiPay SDK v0.7.0
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.*`.
@@ -45,6 +46,13 @@ const PAY_SKU_RE = /^[a-z0-9][a-z0-9_-]{1,39}$/;
45
46
  * none — never had it
46
47
  */
47
48
  const PAY_ENTITLEMENT_STATUSES = ['active', 'grace', 'expired', 'none'];
49
+ /**
50
+ * Version of the buyer-facing withdrawal waiver text the paywall shows (EU/EEA
51
+ * digital content, Directive 2011/83/EU art. 16(m); UK CCR 2013 reg. 37). The
52
+ * text itself lives in the SDK dictionary under the same version; bump both
53
+ * together so a recorded consent always names the words the buyer saw.
54
+ */
55
+ const PAY_WITHDRAWAL_WAIVER_VERSION = '2026-10-v1';
48
56
  /**
49
57
  * The `endUserRef` an SDK mints on first run and keeps in `chrome.storage`.
50
58
  * Opaque, random, never derived from anything identifying.
@@ -61,6 +69,7 @@ const PAY_ERRORS = {
61
69
  GATEWAY_UNAVAILABLE: 'PAY_GATEWAY_UNAVAILABLE',
62
70
  RATE_LIMITED: 'PAY_RATE_LIMITED',
63
71
  INVALID_KEY: 'PAY_INVALID_KEY',
72
+ WITHDRAWAL_WAIVER_REQUIRED: 'PAY_WITHDRAWAL_WAIVER_REQUIRED',
64
73
  };
65
74
  /**
66
75
  * Canonical JSON for signing: keys sorted recursively, no whitespace. Both
@@ -92,6 +101,7 @@ const ERROR_CODES = {
92
101
  GATEWAY_UNAVAILABLE: 'GATEWAY_UNAVAILABLE',
93
102
  CHECKOUT_UNAVAILABLE: 'CHECKOUT_UNAVAILABLE',
94
103
  PAYWALL_UNAVAILABLE: 'PAYWALL_UNAVAILABLE',
104
+ WITHDRAWAL_WAIVER_REQUIRED: 'WITHDRAWAL_WAIVER_REQUIRED',
95
105
  UNKNOWN: 'UNKNOWN',
96
106
  };
97
107
  class ExtenshiPayError extends Error {
@@ -148,6 +158,13 @@ async function getOrCreateEndUserRef(storage) {
148
158
  * mock checkout completes after `claimAfterPolls` polls and grants the SKU.
149
159
  */
150
160
  const DAY_MS = 24 * 60 * 60 * 1000;
161
+ /** Accepts the same optional `withdrawalWaiver` input as the BFF; anything else is no consent. */
162
+ function mockConsent(value) {
163
+ const consent = value;
164
+ return consent && typeof consent.version === 'string' && consent.accepted === true
165
+ ? { version: consent.version, accepted: true }
166
+ : null;
167
+ }
151
168
  class MockTransport {
152
169
  constructor(data = {}) {
153
170
  this.sessions = new Map();
@@ -156,13 +173,15 @@ class MockTransport {
156
173
  this.projectName = data.projectName ?? 'Mock project';
157
174
  this.checkoutEnabled = data.checkoutEnabled ?? true;
158
175
  this.claimAfterPolls = data.claimAfterPolls ?? 1;
176
+ this.withdrawalWaiver =
177
+ data.withdrawalWaiver === undefined ? { version: PAY_WITHDRAWAL_WAIVER_VERSION } : data.withdrawalWaiver;
159
178
  }
160
179
  async call(procedure, _kind, input) {
161
180
  switch (procedure) {
162
181
  case 'pay.getOffer':
163
182
  return this.offerResponse();
164
183
  case 'pay.createCheckout':
165
- return this.createCheckout(String(input.sku));
184
+ return this.createCheckout(String(input.sku), mockConsent(input.withdrawalWaiver));
166
185
  case 'pay.claimSession':
167
186
  return this.claim(String(input.sessionId), String(input.endUserRef), String(input.publishableKey));
168
187
  case 'pay.getEntitlement':
@@ -195,9 +214,10 @@ class MockTransport {
195
214
  checkoutEnabled: this.checkoutEnabled && this.offers.length > 0,
196
215
  offers: [...this.offers],
197
216
  entitlementPublicKey: null,
217
+ withdrawalWaiver: this.withdrawalWaiver ? { ...this.withdrawalWaiver } : null,
198
218
  };
199
219
  }
200
- createCheckout(sku) {
220
+ createCheckout(sku, withdrawalWaiver) {
201
221
  if (!this.checkoutEnabled) {
202
222
  throw new ExtenshiPayError(ERROR_CODES.SELLER_NOT_ACTIVE, 'Mock seller cannot take payments');
203
223
  }
@@ -205,7 +225,7 @@ class MockTransport {
205
225
  throw new ExtenshiPayError(ERROR_CODES.OFFER_NOT_FOUND, `Unknown mock offer ${sku}`);
206
226
  }
207
227
  const sessionId = mintEndUserRef();
208
- this.sessions.set(sessionId, { sku, polls: 0, state: 'open' });
228
+ this.sessions.set(sessionId, { sku, polls: 0, state: 'open', withdrawalWaiver });
209
229
  return {
210
230
  url: `https://mock.extenshi.io/checkout/${sessionId}`,
211
231
  sessionId,
@@ -267,10 +287,12 @@ class PayApi {
267
287
  this.transport = transport;
268
288
  this.publishableKey = publishableKey;
269
289
  }
270
- createRestoreSession(claimChallenge) {
290
+ /** `locale` opens the hosted recovery page (and its email) in the user's language. */
291
+ createRestoreSession(claimChallenge, locale) {
271
292
  return this.transport.call('pay.createRestoreSession', 'mutation', {
272
293
  publishableKey: this.publishableKey,
273
294
  claimChallenge,
295
+ ...(locale ? { locale } : {}),
274
296
  });
275
297
  }
276
298
  claimRestoreSession(sessionId, claimSecret) {
@@ -286,12 +308,20 @@ class PayApi {
286
308
  locale: locale ?? undefined,
287
309
  });
288
310
  }
289
- createCheckout(sku, endUserRef, locale) {
311
+ /**
312
+ * `withdrawalWaiver` is sent only when given. Older BFFs parse the input with
313
+ * a non-strict zod object, which strips the unknown key, so it is safe there.
314
+ * Plain-JS callers passing anything but `accepted: true` send no consent.
315
+ */
316
+ createCheckout(sku, endUserRef, locale, withdrawalWaiver) {
290
317
  return this.transport.call('pay.createCheckout', 'mutation', {
291
318
  publishableKey: this.publishableKey,
292
319
  sku,
293
320
  endUserRef,
294
321
  locale: locale ?? undefined,
322
+ ...(withdrawalWaiver?.accepted === true && typeof withdrawalWaiver.version === 'string'
323
+ ? { withdrawalWaiver: { version: withdrawalWaiver.version, accepted: true } }
324
+ : {}),
295
325
  });
296
326
  }
297
327
  claimSession(sessionId, endUserRef) {
@@ -307,11 +337,12 @@ class PayApi {
307
337
  endUserRef,
308
338
  });
309
339
  }
310
- getPortalUrl(endUserRef, customerId) {
340
+ getPortalUrl(endUserRef, customerId, locale) {
311
341
  return this.transport.call('pay.getPortalUrl', 'mutation', {
312
342
  publishableKey: this.publishableKey,
313
343
  endUserRef,
314
344
  ...(customerId ? { customerId } : {}),
345
+ ...(locale ? { locale } : {}),
315
346
  });
316
347
  }
317
348
  }
@@ -377,6 +408,7 @@ const CAUSE_TO_CODE = {
377
408
  [PAY_ERRORS.AGREEMENT_REQUIRED]: ERROR_CODES.SELLER_NOT_ACTIVE,
378
409
  [PAY_ERRORS.OFFER_NOT_FOUND]: ERROR_CODES.OFFER_NOT_FOUND,
379
410
  [PAY_ERRORS.GATEWAY_UNAVAILABLE]: ERROR_CODES.GATEWAY_UNAVAILABLE,
411
+ [PAY_ERRORS.WITHDRAWAL_WAIVER_REQUIRED]: ERROR_CODES.WITHDRAWAL_WAIVER_REQUIRED,
380
412
  };
381
413
  function parseRetryAfter(message) {
382
414
  const match = /retry in (\d+)s/i.exec(message);
@@ -406,6 +438,8 @@ function trpcErrorToPayError(error, httpStatus) {
406
438
  return new ExtenshiPayError(ERROR_CODES.CHECKOUT_UNAVAILABLE, message, options);
407
439
  return new ExtenshiPayError(ERROR_CODES.OFFER_NOT_FOUND, message, options);
408
440
  case 'PRECONDITION_FAILED':
441
+ if (/withdrawal/i.test(message))
442
+ return new ExtenshiPayError(ERROR_CODES.WITHDRAWAL_WAIVER_REQUIRED, message, options);
409
443
  return new ExtenshiPayError(ERROR_CODES.SELLER_NOT_ACTIVE, message, options);
410
444
  case 'BAD_REQUEST':
411
445
  return new ExtenshiPayError(ERROR_CODES.INVALID_REQUEST, message, options);
@@ -588,7 +622,7 @@ class CheckoutManager {
588
622
  throw new ExtenshiPayError(ERROR_CODES.CHECKOUT_UNAVAILABLE, 'A checkout is already in progress');
589
623
  }
590
624
  const endUserRef = await this.options.getEndUserRef();
591
- const session = await this.options.api.createCheckout(sku, endUserRef, options.locale ?? this.options.locale);
625
+ const session = await this.options.api.createCheckout(sku, endUserRef, options.locale ?? this.options.locale, options.withdrawalWaiver);
592
626
  this.active = session.sessionId;
593
627
  try {
594
628
  const pending = { sessionId: session.sessionId, sku, expiresAt: session.expiresAt };
@@ -1232,7 +1266,7 @@ class RecoveryManager {
1232
1266
  const secret = Array.from(cryptoApi.getRandomValues(new Uint8Array(32)), (b) => b.toString(16).padStart(2, '0')).join('');
1233
1267
  const hash = await cryptoApi.subtle.digest('SHA-256', new TextEncoder().encode(secret));
1234
1268
  const challenge = Array.from(new Uint8Array(hash), (b) => b.toString(16).padStart(2, '0')).join('');
1235
- const created = await this.options.api.createRestoreSession(challenge);
1269
+ const created = await this.options.api.createRestoreSession(challenge, this.options.locale);
1236
1270
  if (!Number.isFinite(Date.parse(created.expiresAt)))
1237
1271
  throw new ExtenshiPayError(ERROR_CODES.INVALID_RESPONSE, 'Invalid recovery expiry');
1238
1272
  const pending = { sessionId: created.sessionId, expiresAt: created.expiresAt, claimSecret: secret };
@@ -1324,7 +1358,49 @@ const DEFAULT_CACHE_TTL_MS = 60 * 60 * 1000;
1324
1358
  const MAX_CACHE_TTL_MS = 7 * 24 * 60 * 60 * 1000;
1325
1359
 
1326
1360
  /** Kept in sync with package.json by tests/unit/version.test.ts. */
1327
- const VERSION = '0.7.0';
1361
+ const VERSION = '0.8.0';
1362
+
1363
+ /**
1364
+ * The user's language as the SDK sends it. Kept apart from the paywall
1365
+ * dictionary (../paywall/i18n.ts) so the Lite and core bundles, which never
1366
+ * render UI, do not carry the translations.
1367
+ */
1368
+ /** What the backend (and older backends) accept as a locale: `de`, `pt-BR`, `zh-CN`. */
1369
+ const WIRE_LOCALE_RE = /^[a-z]{2}(-[A-Za-z]{2,4})?$/;
1370
+ /**
1371
+ * A browser tag as the SDK sends it: `pt_BR` → `pt-BR`, `es-419` → `es`,
1372
+ * `zh-Hant-TW` → `zh-TW`; null for anything that is not a language tag.
1373
+ */
1374
+ function wireLocale(raw) {
1375
+ if (typeof raw !== 'string')
1376
+ return null;
1377
+ const parts = raw.trim().replace(/_/g, '-').split('-').filter(Boolean);
1378
+ const lang = parts[0]?.toLowerCase();
1379
+ if (!lang || !/^[a-z]{2}$/.test(lang))
1380
+ return null;
1381
+ const script = parts
1382
+ .slice(1)
1383
+ .find((p) => /^[A-Za-z]{4}$/.test(p))
1384
+ ?.toLowerCase();
1385
+ // zh-Hant without a region is Traditional Chinese: keep that, never let it read as zh-CN.
1386
+ const region = parts.slice(1).find((p) => /^[A-Za-z]{2}$/.test(p)) ??
1387
+ (lang === 'zh' && script === 'hant' ? 'TW' : undefined);
1388
+ const tag = region ? `${lang}-${region.toUpperCase()}` : lang;
1389
+ return WIRE_LOCALE_RE.test(tag) ? tag : lang;
1390
+ }
1391
+ /** The browser UI language (`chrome.i18n.getUILanguage()`, else `navigator.language`), or null. */
1392
+ function browserLocale() {
1393
+ const g = globalThis;
1394
+ try {
1395
+ const ui = g.chrome?.i18n?.getUILanguage?.() ?? g.browser?.i18n?.getUILanguage?.();
1396
+ if (ui)
1397
+ return wireLocale(ui);
1398
+ }
1399
+ catch {
1400
+ /* Not an extension context. */
1401
+ }
1402
+ return wireLocale(g.navigator?.language);
1403
+ }
1328
1404
 
1329
1405
  const ENVIRONMENTS = new Set(['production', 'sandbox', 'development']);
1330
1406
  const LOG_LEVELS = new Set(['silent', 'error', 'warn', 'info', 'debug']);
@@ -1365,7 +1441,10 @@ function resolveConfig(input) {
1365
1441
  if (!Number.isFinite(cacheTtlMs) || cacheTtlMs < 0 || cacheTtlMs > MAX_CACHE_TTL_MS) {
1366
1442
  errors.push(`cacheTtlMs must be between 0 and ${MAX_CACHE_TTL_MS}`);
1367
1443
  }
1368
- const locale = input.locale ?? null;
1444
+ // Default: the browser UI language, as README promises (it. 13 T10 L2).
1445
+ // `null` still opts out explicitly: prices then use the runtime default
1446
+ // and the paywall reads English.
1447
+ const locale = input.locale === undefined ? browserLocale() : input.locale;
1369
1448
  if (locale !== null && !LOCALE_RE.test(locale))
1370
1449
  errors.push('locale must be a BCP-47 tag such as en or de-DE');
1371
1450
  const theme = input.theme ?? {};
@@ -1436,6 +1515,83 @@ class EventEmitter {
1436
1515
  }
1437
1516
  }
1438
1517
 
1518
+ /**
1519
+ * Every string the SDK shows to the USER of an extension — paywall, license
1520
+ * dialog, billing-profile picker, seller details — in the end-user languages
1521
+ * (ROADMAP it. 13 T10, stage L2; closes it. 12 T9). Developer-facing error
1522
+ * messages stay English.
1523
+ *
1524
+ * Self-contained on purpose: the SDK ships inside third-party extensions with
1525
+ * no runtime dependencies and no remote code, so the dictionary is compiled
1526
+ * in. Placeholders are `{name}`, `{date}`, `{status}`. A missing
1527
+ * translation falls back to English, never to an empty string. The same
1528
+ * languages as the hosted pages (shared-types END_USER_LOCALES); keep the
1529
+ * lists in sync.
1530
+ */
1531
+ const SDK_LOCALES = ['en', 'es', 'pt-BR', 'fr', 'de', 'it', 'ru', 'ja', 'ko', 'zh-CN', 'ar'];
1532
+ // END GENERATED TRANSLATIONS
1533
+ /** Our dictionary language for a tag: exact, then pt → pt-BR, zh(-CN/SG/Hans) → zh-CN, then the bare language. */
1534
+ function sdkLocale(locale) {
1535
+ const tag = wireLocale(locale);
1536
+ if (!tag)
1537
+ return 'en';
1538
+ const exact = SDK_LOCALES.find((l) => l.toLowerCase() === tag.toLowerCase());
1539
+ if (exact)
1540
+ return exact;
1541
+ const [lang, region] = tag.split('-');
1542
+ if (lang === 'pt')
1543
+ return 'pt-BR';
1544
+ // Traditional-script regions read English rather than Simplified characters.
1545
+ if (lang === 'zh')
1546
+ return region && ['TW', 'HK', 'MO'].includes(region) ? 'en' : 'zh-CN';
1547
+ return SDK_LOCALES.find((l) => l === lang) ?? 'en';
1548
+ }
1549
+ /** Fill `{placeholders}` once; a value containing braces is inserted literally. */
1550
+ function fill(message, values) {
1551
+ return message.replace(/\{([a-z]+)\}/g, (whole, key) => values[key] ?? whole);
1552
+ }
1553
+
1554
+ /**
1555
+ * Buyer-facing withdrawal-waiver text (EU/EEA digital content, Directive
1556
+ * 2011/83/EU art. 16(m); UK CCR 2013 reg. 37), per text version and SDK
1557
+ * language. Its own module, not part of the paywall dictionary, so Lite can
1558
+ * show it without bundling every paywall string.
1559
+ *
1560
+ * The recorded consent names the version, so a version's words never change:
1561
+ * new wording is a new version here and a new PAY_WITHDRAWAL_WAIVER_VERSION.
1562
+ *
1563
+ * MIRRORED in shared-types/pay-withdrawal-waiver.ts, which the purchase
1564
+ * confirmation email quotes; shared-types/pay-withdrawal-waiver.test.ts fails
1565
+ * unless both copies are byte-identical. Change them together.
1566
+ */
1567
+ const WITHDRAWAL_WAIVER_TEXTS = {
1568
+ [PAY_WITHDRAWAL_WAIVER_VERSION]: {
1569
+ 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.',
1570
+ 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.',
1571
+ '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.',
1572
+ 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.',
1573
+ 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.',
1574
+ 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.',
1575
+ ru: 'Я соглашаюсь с тем, что {seller} немедленно начнёт предоставление цифрового контента, и подтверждаю, что утрачиваю право на отказ от договора с момента начала предоставления.',
1576
+ ja: '{seller}がデジタルコンテンツの提供を直ちに開始することに同意し、提供の開始後は撤回権を失うことを了承します。',
1577
+ ko: '{seller}의 디지털 콘텐츠 제공이 즉시 시작되는 것에 동의하며, 제공이 시작되면 청약철회권을 상실한다는 점을 확인합니다.',
1578
+ 'zh-CN': '我同意 {seller} 立即开始提供数字内容,并确认一旦开始提供,我将失去撤回权。',
1579
+ ar: 'أوافق على أن يبدأ {seller} فورًا في تقديم المحتوى الرقمي، وأُقرّ بأنني أفقد حقي في العدول عن العقد بمجرد بدء التقديم.',
1580
+ },
1581
+ };
1582
+ /**
1583
+ * The waiver text to show for `serverVersion`, and the version to send with
1584
+ * the consent. A version this SDK does not know (a newer server) shows this
1585
+ * SDK's current text and sends its version: the consent always names the words
1586
+ * actually shown.
1587
+ */
1588
+ function withdrawalWaiverText(serverVersion, locale, seller) {
1589
+ // Own keys only: `toString` / `__proto__` from a server are just unknown versions.
1590
+ const known = Object.keys(WITHDRAWAL_WAIVER_TEXTS).includes(serverVersion);
1591
+ const version = known ? serverVersion : PAY_WITHDRAWAL_WAIVER_VERSION;
1592
+ return { version, text: fill(WITHDRAWAL_WAIVER_TEXTS[version][sdkLocale(locale)], { seller }) };
1593
+ }
1594
+
1439
1595
  /**
1440
1596
  * `ExtenshiPayLite` — entitlement, feature gating and hosted checkout, without
1441
1597
  * the paywall UI. This is what the `lite` bundle exports; the full `ExtenshiPay`
@@ -1492,6 +1648,7 @@ class ExtenshiPayLite {
1492
1648
  });
1493
1649
  this.recovery = new RecoveryManager({
1494
1650
  api: this.api,
1651
+ locale: this.config.locale,
1495
1652
  publishableKey: this.config.publishableKey,
1496
1653
  storage: deps.recoveryStorage ?? createRecoveryStorage(),
1497
1654
  openUrl: deps.openUrl,
@@ -1614,12 +1771,44 @@ class ExtenshiPayLite {
1614
1771
  async onFeatureLocked(_feature, _options) {
1615
1772
  return false;
1616
1773
  }
1617
- /** Opens hosted checkout for `sku` in a new tab and resolves when the session settles. */
1774
+ /**
1775
+ * The withdrawal waiver this offer asks for, with the exact text to show
1776
+ * next to an unticked checkbox (buyer's language, seller's name filled in),
1777
+ * or null when the seller attested the extension is not distributed in the
1778
+ * EEA/UK. For UIs that call `openCheckout()` themselves — Lite, or a custom
1779
+ * paywall; the full SDK's paywall does this for you.
1780
+ */
1781
+ async getWithdrawalWaiver() {
1782
+ await this.initialize();
1783
+ try {
1784
+ const offer = await this.fetchOffer();
1785
+ if (!offer.withdrawalWaiver)
1786
+ return null;
1787
+ const seller = offer.seller?.displayName?.trim() || offer.projectName;
1788
+ return withdrawalWaiverText(offer.withdrawalWaiver.version, this.config.locale, seller);
1789
+ }
1790
+ catch (error) {
1791
+ throw this.reportError(error);
1792
+ }
1793
+ }
1794
+ /**
1795
+ * Opens hosted checkout for `sku` in a new tab and resolves when the session settles.
1796
+ *
1797
+ * Called directly (not from the paywall), this does NOT collect the EU/UK
1798
+ * withdrawal waiver. If `getWithdrawalWaiver()` returns one, your UI must
1799
+ * collect the buyer's consent and pass it as `options.withdrawalWaiver`;
1800
+ * without it this rejects with `WITHDRAWAL_WAIVER_REQUIRED` (the server
1801
+ * refuses such a checkout too).
1802
+ */
1618
1803
  async openCheckout(sku, options = {}) {
1619
1804
  await this.initialize();
1620
1805
  try {
1621
1806
  if (this.recovery.isActive())
1622
1807
  throw new ExtenshiPayError(ERROR_CODES.INVALID_REQUEST, 'Recovery is in progress');
1808
+ // A cold cache is filled here; if the offer cannot be read, the server decides.
1809
+ const offer = await this.fetchOffer().catch(() => null);
1810
+ if (offer?.withdrawalWaiver && options.withdrawalWaiver?.accepted !== true)
1811
+ throw new ExtenshiPayError(ERROR_CODES.WITHDRAWAL_WAIVER_REQUIRED, 'This offer needs the buyer to accept the withdrawal waiver; pass options.withdrawalWaiver');
1623
1812
  return await this.checkout.open(sku, options);
1624
1813
  }
1625
1814
  catch (error) {
@@ -1660,7 +1849,7 @@ class ExtenshiPayLite {
1660
1849
  await this.initialize();
1661
1850
  try {
1662
1851
  const endUserRef = await this.getEndUserRef();
1663
- let result = await this.api.getPortalUrl(endUserRef);
1852
+ let result = await this.api.getPortalUrl(endUserRef, undefined, this.config.locale);
1664
1853
  if (this.destroyed)
1665
1854
  return null;
1666
1855
  if (result.accounts?.length) {
@@ -1674,7 +1863,7 @@ class ExtenshiPayLite {
1674
1863
  // Recovery may replace this installation while the selector is open.
1675
1864
  if (endUserRef !== (await this.getEndUserRef()))
1676
1865
  throw new ExtenshiPayError(ERROR_CODES.INVALID_REQUEST, 'Installation changed; open the portal again');
1677
- result = await this.api.getPortalUrl(endUserRef, customerId);
1866
+ result = await this.api.getPortalUrl(endUserRef, customerId, this.config.locale);
1678
1867
  }
1679
1868
  if (this.destroyed)
1680
1869
  return null;
@@ -1740,5 +1929,5 @@ class ExtenshiPayLite {
1740
1929
  }
1741
1930
  ExtenshiPayLite.version = VERSION;
1742
1931
 
1743
- export { CHECKOUT_POLL_INTERVAL_MS, CHECKOUT_TIMEOUT_MS, CheckoutManager, DEFAULT_API_URL, DEFAULT_CACHE_TTL_MS, EMPTY_ENTITLEMENT, END_USER_REF_STORAGE_KEY, ERROR_CODES, EntitlementManager, EventEmitter, ExtenshiPayError, ExtenshiPayLite, ExtensionStorage, HttpTransport, LOCALE_RE, LocalStorageAdapter, Logger, MAX_CACHE_TTL_MS, MAX_REFRESH_BACKOFF_MS, MIN_REFRESH_INTERVAL_MS, MemoryStorage, MockTransport, PAY_CONTRACT_VERSION, PAY_CURRENCIES, PAY_END_USER_REF_RE, PAY_ENTITLEMENT_STATUSES, PAY_ERRORS, PAY_GATEWAYS, PAY_OFFER_INTERVALS, PAY_OFFER_KINDS, PAY_PUBLISHABLE_KEY_HEX_LENGTH, PAY_PUBLISHABLE_KEY_PREFIX, PAY_SKU_RE, PayApi, RecoveryManager, TRPC_PATH, VERSION, applyLocalExpiry, base64ToBytes, canonicalJson, checkFeatures, collectFeatures, createRecoveryStorage, createStorage, getOrCreateEndUserRef, hasFeature, isEntitled, isLive, isPayPublishableKey, logger, mintEndUserRef, openInNewTab, resolveConfig, trpcErrorToPayError, verifyEntitlementSignature };
1932
+ export { CHECKOUT_POLL_INTERVAL_MS, CHECKOUT_TIMEOUT_MS, CheckoutManager, DEFAULT_API_URL, DEFAULT_CACHE_TTL_MS, EMPTY_ENTITLEMENT, END_USER_REF_STORAGE_KEY, ERROR_CODES, EntitlementManager, EventEmitter, ExtenshiPayError, ExtenshiPayLite, ExtensionStorage, HttpTransport, LOCALE_RE, LocalStorageAdapter, Logger, MAX_CACHE_TTL_MS, MAX_REFRESH_BACKOFF_MS, MIN_REFRESH_INTERVAL_MS, MemoryStorage, MockTransport, PAY_CONTRACT_VERSION, PAY_CURRENCIES, PAY_END_USER_REF_RE, PAY_ENTITLEMENT_STATUSES, PAY_ERRORS, PAY_GATEWAYS, PAY_OFFER_INTERVALS, PAY_OFFER_KINDS, PAY_PUBLISHABLE_KEY_HEX_LENGTH, PAY_PUBLISHABLE_KEY_PREFIX, PAY_SKU_RE, PAY_WITHDRAWAL_WAIVER_VERSION, PayApi, RecoveryManager, TRPC_PATH, VERSION, applyLocalExpiry, base64ToBytes, canonicalJson, checkFeatures, collectFeatures, createRecoveryStorage, createStorage, getOrCreateEndUserRef, hasFeature, isEntitled, isLive, isPayPublishableKey, logger, mintEndUserRef, openInNewTab, resolveConfig, trpcErrorToPayError, verifyEntitlementSignature };
1744
1933
  //# sourceMappingURL=core.mjs.map