@contentcredits/sdk 2.11.0 → 2.13.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.
@@ -11,7 +11,7 @@ function normalizeArticleUrl(articleUrl) {
11
11
  }
12
12
  }
13
13
  function resolveConfig(raw) {
14
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
14
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
15
15
  if (!raw.apiKey || typeof raw.apiKey !== 'string' || raw.apiKey.trim() === '') {
16
16
  throw new Error('[ContentCredits] apiKey is required. Get yours from the Content Credits admin panel.');
17
17
  }
@@ -20,7 +20,7 @@ function resolveConfig(raw) {
20
20
  try {
21
21
  hostName = new URL(articleUrl).hostname;
22
22
  }
23
- catch (_m) {
23
+ catch (_o) {
24
24
  throw new Error(`[ContentCredits] Invalid articleUrl: "${articleUrl}"`);
25
25
  }
26
26
  return {
@@ -34,9 +34,11 @@ function resolveConfig(raw) {
34
34
  extensionId: (_e = raw.extensionId) !== null && _e !== void 0 ? _e : "ljehdpabbhgccmanhjdfacjnaigpgcml",
35
35
  debug: (_f = raw.debug) !== null && _f !== void 0 ? _f : false,
36
36
  headless: (_g = raw.headless) !== null && _g !== void 0 ? _g : false,
37
+ paywallMode: (_h = raw.paywallMode) !== null && _h !== void 0 ? _h : 'overlay',
38
+ paywallTopSlot: raw.paywallTopSlot,
39
+ reactDOM: raw.reactDOM,
37
40
  apiBaseUrl: "https://api.contentcredits.com",
38
41
  accountsUrl: "https://accounts.contentcredits.com",
39
- paywallTemplate: raw.paywallTemplate,
40
42
  onAccessGranted: raw.onAccessGranted,
41
43
  onStateChange: raw.onStateChange,
42
44
  onReady: raw.onReady,
@@ -48,8 +50,8 @@ function resolveConfig(raw) {
48
50
  onUserLogout: raw.onUserLogout,
49
51
  onError: raw.onError,
50
52
  theme: {
51
- primaryColor: (_j = (_h = raw.theme) === null || _h === void 0 ? void 0 : _h.primaryColor) !== null && _j !== void 0 ? _j : '#44C678',
52
- fontFamily: (_l = (_k = raw.theme) === null || _k === void 0 ? void 0 : _k.fontFamily) !== null && _l !== void 0 ? _l : "-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif",
53
+ primaryColor: (_k = (_j = raw.theme) === null || _j === void 0 ? void 0 : _j.primaryColor) !== null && _k !== void 0 ? _k : '#44C678',
54
+ fontFamily: (_m = (_l = raw.theme) === null || _l === void 0 ? void 0 : _l.fontFamily) !== null && _m !== void 0 ? _m : "-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif",
53
55
  },
54
56
  };
55
57
  }
@@ -542,9 +544,9 @@ function createGate(options) {
542
544
  }
543
545
  contentEl.setAttribute(GATE_ATTR, 'true');
544
546
  gated = true;
545
- // Add a gradient fade at the bottom of the visible teaser so the cutoff
546
- // looks intentional rather than abrupt.
547
- if (!contentEl.querySelector('[data-cc-fade]')) {
547
+ // In overlay mode the gradient is part of the paywall panel itself.
548
+ // In inline mode inject a fade element at the bottom of the teaser.
549
+ if (options.paywallMode === 'inline' && !contentEl.querySelector('[data-cc-fade]')) {
548
550
  const prevPos = contentEl.style.position;
549
551
  if (!prevPos || prevPos === 'static')
550
552
  contentEl.style.position = 'relative';
@@ -643,7 +645,7 @@ function getPaywallStyles(primaryColor, fontFamily) {
643
645
  return `
644
646
  *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
645
647
 
646
- /* Inline paywall panel — sits below the teaser content in the page flow */
648
+ /* ── Inline paywall panel — sits below teaser in the page flow ── */
647
649
  .cc-paywall-inline {
648
650
  width: 100%;
649
651
  padding: 36px 24px 32px;
@@ -670,6 +672,87 @@ function getPaywallStyles(primaryColor, fontFamily) {
670
672
  line-height: 1.6;
671
673
  }
672
674
 
675
+ /* ── Overlay paywall panel — full-width white panel below gated content ── */
676
+ .cc-paywall-overlay {
677
+ /* Break out of any max-width container to span the full viewport */
678
+ width: 100vw;
679
+ margin-left: calc(50% - 50vw);
680
+ background: #fff;
681
+ font-family: ${fontFamily};
682
+ }
683
+
684
+ /* Gradient that fades the article into the white panel */
685
+ .cc-paywall-overlay-gradient {
686
+ width: 100%;
687
+ height: 120px;
688
+ background: linear-gradient(to bottom, transparent 0%, #fff 100%);
689
+ margin-top: -120px;
690
+ pointer-events: none;
691
+ position: relative;
692
+ z-index: 1;
693
+ }
694
+
695
+ /* Top slot — client-supplied content */
696
+ .cc-paywall-overlay-slot {
697
+ padding: 32px 24px 0;
698
+ display: flex;
699
+ flex-direction: column;
700
+ align-items: center;
701
+ gap: 12px;
702
+ }
703
+
704
+ /* Our SDK's unlock section below the slot */
705
+ .cc-paywall-overlay-body {
706
+ padding: 20px 24px 32px;
707
+ display: flex;
708
+ flex-direction: column;
709
+ align-items: center;
710
+ gap: 0;
711
+ text-align: center;
712
+ }
713
+
714
+ /* Slot item — heading */
715
+ .cc-slot-heading {
716
+ font-size: 22px;
717
+ font-weight: 700;
718
+ color: #111827;
719
+ text-align: center;
720
+ line-height: 1.3;
721
+ }
722
+
723
+ /* Slot item — subheading */
724
+ .cc-slot-subheading {
725
+ font-size: 16px;
726
+ font-weight: 600;
727
+ color: #374151;
728
+ text-align: center;
729
+ }
730
+
731
+ /* Slot item — body text */
732
+ .cc-slot-text {
733
+ font-size: 14px;
734
+ color: #6b7280;
735
+ text-align: center;
736
+ line-height: 1.6;
737
+ }
738
+
739
+ /* Slot item — divider with optional label */
740
+ .cc-slot-divider {
741
+ display: flex;
742
+ align-items: center;
743
+ gap: 12px;
744
+ width: 100%;
745
+ max-width: 320px;
746
+ font-size: 13px;
747
+ color: #9ca3af;
748
+ }
749
+ .cc-slot-divider::before,
750
+ .cc-slot-divider::after {
751
+ content: '';
752
+ flex: 1;
753
+ border-top: 1px solid #e5e7eb;
754
+ }
755
+
673
756
  .cc-btn {
674
757
  display: inline-flex;
675
758
  align-items: center;
@@ -1194,45 +1277,84 @@ function sanitizeUrl(url) {
1194
1277
  const HOST_ID = 'cc-paywall-host';
1195
1278
  function createPaywallRenderer(config) {
1196
1279
  let root = null;
1197
- let overlay = null;
1280
+ // In inline mode: the single panel div. In overlay mode: the body section only.
1281
+ let body = null;
1282
+ // Tracks a mounted React 18 root so we can unmount it on destroy.
1283
+ let reactRoot = null;
1198
1284
  function init() {
1199
- // Insert the shadow host immediately after the content element so the
1200
- // paywall panel flows inline below the teaser — no modal, no backdrop.
1201
1285
  const contentEl = document.querySelector(config.contentSelector);
1202
1286
  if (!contentEl)
1203
1287
  return;
1204
1288
  const { root: shadowRoot } = createInlineShadowHost(HOST_ID, contentEl);
1205
1289
  root = shadowRoot;
1206
1290
  injectStyles(root, getPaywallStyles(config.theme.primaryColor, config.theme.fontFamily));
1207
- overlay = el('div');
1208
- overlay.className = 'cc-paywall-inline';
1209
- root.appendChild(overlay);
1291
+ if (config.paywallMode === 'overlay') {
1292
+ initOverlay(root, contentEl);
1293
+ }
1294
+ else {
1295
+ initInline(root);
1296
+ }
1297
+ }
1298
+ function initInline(shadowRoot) {
1299
+ body = el('div');
1300
+ body.className = 'cc-paywall-inline';
1301
+ shadowRoot.appendChild(body);
1302
+ }
1303
+ function initOverlay(shadowRoot, contentEl) {
1304
+ var _a, _b;
1305
+ const panel = el('div');
1306
+ panel.className = 'cc-paywall-overlay';
1307
+ // Gradient that visually fades the article into the white panel.
1308
+ // We read the computed background of the content element's parent so the
1309
+ // gradient blends correctly on sites with non-white backgrounds.
1310
+ const gradient = el('div');
1311
+ gradient.className = 'cc-paywall-overlay-gradient';
1312
+ const parentBg = getComputedStyle((_a = contentEl.parentElement) !== null && _a !== void 0 ? _a : contentEl).backgroundColor;
1313
+ if (parentBg && parentBg !== 'rgba(0, 0, 0, 0)' && parentBg !== 'transparent') {
1314
+ gradient.style.background = `linear-gradient(to bottom, transparent 0%, ${parentBg} 100%)`;
1315
+ }
1316
+ panel.appendChild(gradient);
1317
+ // Top slot — client content
1318
+ const slot = el('div');
1319
+ slot.className = 'cc-paywall-overlay-slot';
1320
+ reactRoot = (_b = mountTopSlot(slot, config.paywallTopSlot, config.reactDOM)) !== null && _b !== void 0 ? _b : null;
1321
+ panel.appendChild(slot);
1322
+ // Only render the "or" divider between slot and body when the slot has content
1323
+ if (config.paywallTopSlot) {
1324
+ const divider = el('div');
1325
+ divider.className = 'cc-slot-divider';
1326
+ divider.style.cssText = 'margin: 4px auto 0; padding: 0 24px;';
1327
+ divider.textContent = 'or';
1328
+ panel.appendChild(divider);
1329
+ }
1330
+ // Our SDK's unlock body
1331
+ body = el('div');
1332
+ body.className = 'cc-paywall-overlay-body';
1333
+ panel.appendChild(body);
1334
+ shadowRoot.appendChild(panel);
1210
1335
  }
1211
1336
  function render(state, callbacks, meta) {
1212
1337
  var _a, _b, _c;
1213
- // During the initial access check the content is already hidden by the
1214
- // gate — no need to show a spinner in the paywall slot.
1215
1338
  if (state === 'checking')
1216
1339
  return;
1217
- if (!overlay)
1340
+ if (!body)
1218
1341
  init();
1219
- if (!overlay)
1342
+ if (!body)
1220
1343
  return;
1221
- // Clear previous content
1222
- while (overlay.firstChild)
1223
- overlay.removeChild(overlay.firstChild);
1344
+ while (body.firstChild)
1345
+ body.removeChild(body.firstChild);
1224
1346
  switch (state) {
1225
1347
  case 'login':
1226
- renderLogin(overlay, callbacks);
1348
+ renderLogin(body, callbacks);
1227
1349
  break;
1228
1350
  case 'purchase':
1229
- renderPurchase(overlay, callbacks, (_a = meta === null || meta === void 0 ? void 0 : meta.requiredCredits) !== null && _a !== void 0 ? _a : null);
1351
+ renderPurchase(body, callbacks, (_a = meta === null || meta === void 0 ? void 0 : meta.requiredCredits) !== null && _a !== void 0 ? _a : null);
1230
1352
  break;
1231
1353
  case 'insufficient':
1232
- renderInsufficient(overlay, callbacks, (_b = meta === null || meta === void 0 ? void 0 : meta.requiredCredits) !== null && _b !== void 0 ? _b : null, (_c = meta === null || meta === void 0 ? void 0 : meta.creditBalance) !== null && _c !== void 0 ? _c : null);
1354
+ renderInsufficient(body, callbacks, (_b = meta === null || meta === void 0 ? void 0 : meta.requiredCredits) !== null && _b !== void 0 ? _b : null, (_c = meta === null || meta === void 0 ? void 0 : meta.creditBalance) !== null && _c !== void 0 ? _c : null);
1233
1355
  break;
1234
1356
  case 'loading':
1235
- renderLoading(overlay);
1357
+ renderLoading(body);
1236
1358
  break;
1237
1359
  case 'granted':
1238
1360
  destroy();
@@ -1240,33 +1362,44 @@ function createPaywallRenderer(config) {
1240
1362
  }
1241
1363
  }
1242
1364
  function renderLogin(parent, cb) {
1243
- parent.appendChild(el('h2', 'This article requires a subscription'));
1244
- parent.appendChild(el('p', 'Log in with your Content Credits account to unlock this article.'));
1245
- const btn = el('button', 'Login & Buy with Content Credits');
1365
+ // Only show the heading/description in inline mode; in overlay mode the
1366
+ // client's top slot already provides the article context.
1367
+ if (config.paywallMode === 'inline') {
1368
+ parent.appendChild(el('h2', 'This article requires a subscription'));
1369
+ parent.appendChild(el('p', 'Log in with your Content Credits account to unlock this article.'));
1370
+ }
1371
+ const btn = el('button', 'Login & Unlock with Content Credits');
1246
1372
  btn.className = 'cc-btn cc-btn-primary';
1247
1373
  btn.addEventListener('click', () => { void cb.onLogin(); });
1248
1374
  parent.appendChild(btn);
1249
1375
  parent.appendChild(poweredBy());
1250
1376
  }
1251
1377
  function renderPurchase(parent, cb, credits) {
1252
- parent.appendChild(el('h2', 'Unlock this article'));
1253
- if (credits !== null) {
1254
- const badge = el('span', `${credits} credit${credits !== 1 ? 's' : ''}`);
1255
- badge.className = 'cc-credit-badge';
1256
- parent.appendChild(badge);
1257
- }
1258
- parent.appendChild(el('p', 'Use your Content Credits balance to instantly access this premium article.'));
1259
- const btn = el('button', credits !== null ? `Buy for ${credits} Credit${credits !== 1 ? 's' : ''}` : 'Buy with Content Credits');
1260
- btn.className = 'cc-btn cc-btn-primary';
1378
+ if (config.paywallMode === 'inline') {
1379
+ parent.appendChild(el('h2', 'Unlock this article'));
1380
+ if (credits !== null) {
1381
+ const badge = el('span', `${credits} credit${credits !== 1 ? 's' : ''}`);
1382
+ badge.className = 'cc-credit-badge';
1383
+ parent.appendChild(badge);
1384
+ }
1385
+ parent.appendChild(el('p', 'Use your Content Credits balance to instantly access this premium article.'));
1386
+ }
1387
+ const label = credits !== null
1388
+ ? `Unlock Just This Story · ${credits} Credit${credits !== 1 ? 's' : ''}`
1389
+ : 'Unlock Just This Story';
1390
+ const btn = el('button', label);
1391
+ btn.className = 'cc-btn cc-btn-outline';
1261
1392
  btn.addEventListener('click', () => { void cb.onPurchase(); });
1262
1393
  parent.appendChild(btn);
1263
1394
  parent.appendChild(poweredBy());
1264
1395
  }
1265
1396
  function renderInsufficient(parent, cb, required, available) {
1266
- parent.appendChild(el('h2', 'Not enough credits'));
1397
+ if (config.paywallMode === 'inline') {
1398
+ parent.appendChild(el('h2', 'Not enough credits'));
1399
+ }
1267
1400
  const detail = required !== null && available !== null
1268
- ? `You need ${required} credit${required !== 1 ? 's' : ''} but have ${available}. Top up to unlock this article.`
1269
- : 'You don\'t have enough credits to unlock this article. Purchase more to continue.';
1401
+ ? `You need ${required} credit${required !== 1 ? 's' : ''} but only have ${available}.`
1402
+ : 'You don\'t have enough credits to unlock this article.';
1270
1403
  parent.appendChild(el('p', detail));
1271
1404
  const btn = el('button', 'Buy More Credits');
1272
1405
  btn.className = 'cc-btn cc-btn-primary';
@@ -1276,7 +1409,7 @@ function createPaywallRenderer(config) {
1276
1409
  }
1277
1410
  function renderLoading(parent) {
1278
1411
  const btn = el('button');
1279
- btn.className = 'cc-btn cc-btn-primary';
1412
+ btn.className = 'cc-btn cc-btn-outline';
1280
1413
  btn.disabled = true;
1281
1414
  const spinner = el('span');
1282
1415
  spinner.className = 'cc-spinner';
@@ -1296,9 +1429,9 @@ function createPaywallRenderer(config) {
1296
1429
  return div;
1297
1430
  }
1298
1431
  function setButtonLoading(loading) {
1299
- if (!overlay)
1432
+ if (!body)
1300
1433
  return;
1301
- const btn = overlay.querySelector('.cc-btn');
1434
+ const btn = body.querySelector('.cc-btn');
1302
1435
  if (!btn)
1303
1436
  return;
1304
1437
  btn.disabled = loading;
@@ -1311,12 +1444,110 @@ function createPaywallRenderer(config) {
1311
1444
  }
1312
1445
  }
1313
1446
  function destroy() {
1447
+ reactRoot === null || reactRoot === void 0 ? void 0 : reactRoot.unmount();
1448
+ reactRoot = null;
1314
1449
  removeShadowHost(HOST_ID);
1315
1450
  root = null;
1316
- overlay = null;
1451
+ body = null;
1317
1452
  }
1318
1453
  return { init, render, setButtonLoading, destroy };
1319
1454
  }
1455
+ // ─── Top slot mounting ───────────────────────────────────────────────────────
1456
+ function mountTopSlot(container, slot, reactDOM) {
1457
+ if (!slot)
1458
+ return undefined;
1459
+ // React element — detected by the $$typeof symbol all React elements carry.
1460
+ if (isReactElement(slot)) {
1461
+ if (!reactDOM) {
1462
+ console.warn('[ContentCredits] paywallTopSlot is a React element but `reactDOM` was not provided. ' +
1463
+ 'Pass your ReactDOM instance: ContentCredits.init({ reactDOM, paywallTopSlot: <Widget /> })');
1464
+ return undefined;
1465
+ }
1466
+ return mountReactElement(container, slot, reactDOM);
1467
+ }
1468
+ if (typeof slot === 'function') {
1469
+ slot(container);
1470
+ return undefined;
1471
+ }
1472
+ if (slot instanceof HTMLElement) {
1473
+ container.appendChild(slot);
1474
+ return undefined;
1475
+ }
1476
+ // Structured PaywallSlotItem[]
1477
+ for (const item of slot) {
1478
+ container.appendChild(renderSlotItem(item));
1479
+ }
1480
+ return undefined;
1481
+ }
1482
+ function isReactElement(value) {
1483
+ // All React elements (JSX) have a $$typeof symbol set to Symbol.for('react.element')
1484
+ // or, in older builds, the integer 0xeac7.
1485
+ return (typeof value === 'object' &&
1486
+ value !== null &&
1487
+ '$$typeof' in value &&
1488
+ !Array.isArray(value) &&
1489
+ !(value instanceof HTMLElement));
1490
+ }
1491
+ function mountReactElement(container, element, reactDOM) {
1492
+ // React 18+: createRoot
1493
+ if (typeof reactDOM.createRoot === 'function') {
1494
+ const root = reactDOM.createRoot(container);
1495
+ root.render(element);
1496
+ return root;
1497
+ }
1498
+ // React 16/17: legacy render (no unmount handle needed — it cleans up on container removal)
1499
+ if (typeof reactDOM.render === 'function') {
1500
+ reactDOM.render(element, container);
1501
+ return {
1502
+ unmount() {
1503
+ var _a;
1504
+ // ReactDOM.unmountComponentAtNode is the React 16/17 equivalent
1505
+ const rdom = reactDOM;
1506
+ (_a = rdom.unmountComponentAtNode) === null || _a === void 0 ? void 0 : _a.call(rdom, container);
1507
+ },
1508
+ };
1509
+ }
1510
+ console.warn('[ContentCredits] The provided `reactDOM` has neither `createRoot` nor `render`. ' +
1511
+ 'Pass a valid ReactDOM instance.');
1512
+ return undefined;
1513
+ }
1514
+ function renderSlotItem(item) {
1515
+ var _a, _b, _c, _d, _e;
1516
+ switch (item.type) {
1517
+ case 'heading': {
1518
+ const h = el('span', (_a = item.content) !== null && _a !== void 0 ? _a : '');
1519
+ h.className = 'cc-slot-heading';
1520
+ return h;
1521
+ }
1522
+ case 'subheading': {
1523
+ const h = el('span', (_b = item.content) !== null && _b !== void 0 ? _b : '');
1524
+ h.className = 'cc-slot-subheading';
1525
+ return h;
1526
+ }
1527
+ case 'text': {
1528
+ const p = el('span', (_c = item.content) !== null && _c !== void 0 ? _c : '');
1529
+ p.className = 'cc-slot-text';
1530
+ return p;
1531
+ }
1532
+ case 'button': {
1533
+ const btn = el('button', (_d = item.content) !== null && _d !== void 0 ? _d : '');
1534
+ const variantClass = item.variant === 'outline'
1535
+ ? 'cc-btn-outline'
1536
+ : item.variant === 'secondary'
1537
+ ? 'cc-btn-secondary'
1538
+ : 'cc-btn-primary';
1539
+ btn.className = `cc-btn ${variantClass}`;
1540
+ if (item.onClick)
1541
+ btn.addEventListener('click', item.onClick);
1542
+ return btn;
1543
+ }
1544
+ case 'divider': {
1545
+ const d = el('div', (_e = item.content) !== null && _e !== void 0 ? _e : '');
1546
+ d.className = 'cc-slot-divider';
1547
+ return d;
1548
+ }
1549
+ }
1550
+ }
1320
1551
 
1321
1552
  const DETECTION_TIMEOUT_MS = 2000;
1322
1553
  /**
@@ -1650,12 +1881,18 @@ function openAuthPopup(authUrl) {
1650
1881
  });
1651
1882
  }
1652
1883
 
1884
+ // How long to wait for the extension to respond to an authorization request
1885
+ // before falling back to the direct API check. MV3 service workers can take
1886
+ // a moment to wake up, but if they don't respond within this window we
1887
+ // assume the extension isn't functional and proceed without it.
1888
+ const EXTENSION_RESPONSE_TIMEOUT_MS = 3000;
1653
1889
  function createPaywall(config, creditsApi, state, emitter, existingGate) {
1654
1890
  // Accept a pre-created gate so the caller can call gate.hide() synchronously
1655
1891
  // before any async work, preventing a flash of the full article content.
1656
1892
  const gate = existingGate !== null && existingGate !== void 0 ? existingGate : createGate({
1657
1893
  selector: config.contentSelector,
1658
1894
  teaserParagraphs: config.teaserParagraphs,
1895
+ paywallMode: config.paywallMode,
1659
1896
  });
1660
1897
  const renderer = createPaywallRenderer(config);
1661
1898
  const bridge = createExtensionBridge();
@@ -1766,6 +2003,43 @@ function createPaywall(config, creditsApi, state, emitter, existingGate) {
1766
2003
  function doBuyMoreCredits() {
1767
2004
  window.open(`${"https://accounts.contentcredits.com"}/consumer/dashboard`, '_blank', 'noopener,noreferrer');
1768
2005
  }
2006
+ // ── Extension auth response handler ──────────────────────────────────────
2007
+ function handleExtensionAuthResponse(data) {
2008
+ var _a, _b, _c, _d, _e, _f, _g;
2009
+ state.set({
2010
+ isLoggedIn: data.isAuthenticated,
2011
+ hasAccess: data.doesHaveAccess,
2012
+ isLoaded: true,
2013
+ isLoading: false,
2014
+ creditBalance: (_a = data.creditBalance) !== null && _a !== void 0 ? _a : null,
2015
+ requiredCredits: (_b = data.requiredCredits) !== null && _b !== void 0 ? _b : null,
2016
+ });
2017
+ if (!data.isAuthenticated) {
2018
+ if (!config.headless) {
2019
+ gate.hide();
2020
+ renderer.render('login', { onLogin: doLogin, onPurchase: doPurchase, onBuyMoreCredits: doBuyMoreCredits });
2021
+ }
2022
+ (_c = config.onLoginRequired) === null || _c === void 0 ? void 0 : _c.call(config);
2023
+ emitter.emit('paywall:shown', {});
2024
+ }
2025
+ else if (data.doesHaveAccess) {
2026
+ handleAccessGranted(0, (_d = data.creditBalance) !== null && _d !== void 0 ? _d : 0);
2027
+ }
2028
+ else {
2029
+ if (!config.headless) {
2030
+ gate.hide();
2031
+ renderer.render('purchase', { onLogin: doLogin, onPurchase: doPurchase, onBuyMoreCredits: doBuyMoreCredits }, {
2032
+ requiredCredits: data.requiredCredits,
2033
+ creditBalance: data.creditBalance,
2034
+ });
2035
+ }
2036
+ (_e = config.onPurchaseRequired) === null || _e === void 0 ? void 0 : _e.call(config, {
2037
+ requiredCredits: (_f = data.requiredCredits) !== null && _f !== void 0 ? _f : null,
2038
+ creditBalance: (_g = data.creditBalance) !== null && _g !== void 0 ? _g : null,
2039
+ });
2040
+ emitter.emit('paywall:shown', {});
2041
+ }
2042
+ }
1769
2043
  // ── Access Check ──────────────────────────────────────────────────────────
1770
2044
  async function checkAccess() {
1771
2045
  var _a, _b, _c;
@@ -1773,8 +2047,26 @@ function createPaywall(config, creditsApi, state, emitter, existingGate) {
1773
2047
  if (!config.headless)
1774
2048
  renderer.render('checking', { onLogin: doLogin, onPurchase: doPurchase, onBuyMoreCredits: doBuyMoreCredits });
1775
2049
  if (extensionAvailable) {
1776
- bridge.requestAuthorization(config.apiKey, config.hostName);
1777
- return; // response handled in onAuthorizationResponse
2050
+ // Race the extension response against a timeout. MV3 service workers can
2051
+ // be asleep and take time to wake — if they don't respond in time we mark
2052
+ // the extension as non-functional and fall through to the API check so the
2053
+ // logged-in user isn't left stuck on a blank/hidden article.
2054
+ const responded = await new Promise(resolve => {
2055
+ const timer = setTimeout(() => {
2056
+ extensionAvailable = false;
2057
+ state.set({ isExtensionAvailable: false });
2058
+ resolve(false);
2059
+ }, EXTENSION_RESPONSE_TIMEOUT_MS);
2060
+ bridge.onAuthorizationResponse(data => {
2061
+ clearTimeout(timer);
2062
+ handleExtensionAuthResponse(data);
2063
+ resolve(true);
2064
+ });
2065
+ bridge.requestAuthorization(config.apiKey, config.hostName);
2066
+ });
2067
+ if (responded)
2068
+ return;
2069
+ // Extension timed out — fall through to direct API check below.
1778
2070
  }
1779
2071
  if (!tokenStorage.has()) {
1780
2072
  state.set({ isLoading: false, isLoaded: true });
@@ -1840,42 +2132,6 @@ function createPaywall(config, creditsApi, state, emitter, existingGate) {
1840
2132
  state.set({ isExtensionAvailable: extensionAvailable });
1841
2133
  if (extensionAvailable) {
1842
2134
  bridge.attach();
1843
- bridge.onAuthorizationResponse(data => {
1844
- var _a, _b, _c, _d, _e, _f, _g;
1845
- state.set({
1846
- isLoggedIn: data.isAuthenticated,
1847
- hasAccess: data.doesHaveAccess,
1848
- isLoaded: true,
1849
- isLoading: false,
1850
- creditBalance: (_a = data.creditBalance) !== null && _a !== void 0 ? _a : null,
1851
- requiredCredits: (_b = data.requiredCredits) !== null && _b !== void 0 ? _b : null,
1852
- });
1853
- if (!data.isAuthenticated) {
1854
- if (!config.headless) {
1855
- gate.hide();
1856
- renderer.render('login', { onLogin: doLogin, onPurchase: doPurchase, onBuyMoreCredits: doBuyMoreCredits });
1857
- }
1858
- (_c = config.onLoginRequired) === null || _c === void 0 ? void 0 : _c.call(config);
1859
- emitter.emit('paywall:shown', {});
1860
- }
1861
- else if (data.doesHaveAccess) {
1862
- handleAccessGranted(0, (_d = data.creditBalance) !== null && _d !== void 0 ? _d : 0);
1863
- }
1864
- else {
1865
- if (!config.headless) {
1866
- gate.hide();
1867
- renderer.render('purchase', { onLogin: doLogin, onPurchase: doPurchase, onBuyMoreCredits: doBuyMoreCredits }, {
1868
- requiredCredits: data.requiredCredits,
1869
- creditBalance: data.creditBalance,
1870
- });
1871
- }
1872
- (_e = config.onPurchaseRequired) === null || _e === void 0 ? void 0 : _e.call(config, {
1873
- requiredCredits: (_f = data.requiredCredits) !== null && _f !== void 0 ? _f : null,
1874
- creditBalance: (_g = data.creditBalance) !== null && _g !== void 0 ? _g : null,
1875
- });
1876
- emitter.emit('paywall:shown', {});
1877
- }
1878
- });
1879
2135
  bridge.onPurchaseResponse(data => {
1880
2136
  var _a, _b;
1881
2137
  state.set({ isLoading: false, isLoaded: true, hasAccess: data.doesHaveAccess });
@@ -2795,6 +3051,7 @@ class ContentCredits {
2795
3051
  const earlyGate = createGate({
2796
3052
  selector: this.config.contentSelector,
2797
3053
  teaserParagraphs: this.config.teaserParagraphs,
3054
+ paywallMode: this.config.paywallMode,
2798
3055
  });
2799
3056
  if (!this.config.headless)
2800
3057
  earlyGate.hide();
@@ -2950,7 +3207,7 @@ class ContentCredits {
2950
3207
  }
2951
3208
  /** SDK version string. */
2952
3209
  static get version() {
2953
- return "2.11.0";
3210
+ return "2.13.0";
2954
3211
  }
2955
3212
  }
2956
3213
  // ── Auto-init from script data attributes (CDN usage) ────────────────────────