@joryio/web-sdk 1.4.0-beta.4 → 1.4.0-beta.6

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 (52) hide show
  1. package/CHANGELOG.md +11 -3
  2. package/dist/core/cards.d.ts +2 -1
  3. package/dist/core/cards.d.ts.map +1 -1
  4. package/dist/core/config.d.ts +1 -1
  5. package/dist/core/config.d.ts.map +1 -1
  6. package/dist/core/flags.d.ts +2 -1
  7. package/dist/core/flags.d.ts.map +1 -1
  8. package/dist/core/page-edits.d.ts +1 -1
  9. package/dist/core/page-edits.d.ts.map +1 -1
  10. package/dist/core/placements.d.ts +2 -1
  11. package/dist/core/placements.d.ts.map +1 -1
  12. package/dist/core/sdk-host-files.d.ts +1 -1
  13. package/dist/core/sdk-host-files.d.ts.map +1 -1
  14. package/dist/core/sdk.d.ts +4 -3
  15. package/dist/core/sdk.d.ts.map +1 -1
  16. package/dist/core/subscription.d.ts +6 -0
  17. package/dist/core/subscription.d.ts.map +1 -0
  18. package/dist/editor/editor-model.d.ts +13 -0
  19. package/dist/editor/editor-model.d.ts.map +1 -0
  20. package/dist/editor/editor-strings.d.ts +79 -0
  21. package/dist/editor/editor-strings.d.ts.map +1 -0
  22. package/dist/editor/editor-ui.d.ts +25 -0
  23. package/dist/editor/editor-ui.d.ts.map +1 -0
  24. package/dist/editor/visual-editor.d.ts +59 -8
  25. package/dist/editor/visual-editor.d.ts.map +1 -1
  26. package/dist/index.d.mts +10 -5
  27. package/dist/index.d.ts +1 -0
  28. package/dist/index.d.ts.map +1 -1
  29. package/dist/joryio-cards-ui.min.js +1 -1
  30. package/dist/joryio-cards-ui.min.js.map +1 -1
  31. package/dist/joryio-editor.min.js +2 -2
  32. package/dist/joryio-editor.min.js.map +1 -1
  33. package/dist/joryio-sw.js +1 -1
  34. package/dist/joryio.cjs.js +83 -46
  35. package/dist/joryio.min.js +2 -2
  36. package/dist/joryio.min.js.map +1 -1
  37. package/dist/joryio.mjs +83 -46
  38. package/dist/joryio.umd.js +83 -46
  39. package/package.json +1 -1
  40. package/src/core/cards.ts +10 -7
  41. package/src/core/config.ts +1 -1
  42. package/src/core/flags.ts +10 -4
  43. package/src/core/page-edits.ts +43 -22
  44. package/src/core/placements.ts +10 -7
  45. package/src/core/sdk-host-files.ts +15 -10
  46. package/src/core/sdk.ts +14 -9
  47. package/src/core/subscription.ts +27 -0
  48. package/src/editor/editor-model.ts +102 -0
  49. package/src/editor/editor-strings.ts +102 -0
  50. package/src/editor/editor-ui.ts +145 -0
  51. package/src/editor/visual-editor.ts +815 -105
  52. package/src/index.ts +2 -0
package/dist/joryio.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Joryio Web SDK v1.4.0-beta.4
2
+ * Joryio Web SDK v1.4.0-beta.6
3
3
  * (c) 2026 Joryio. All rights reserved.
4
4
  * @license Commercial - see https://github.com/joryio/joryio-web-sdk/blob/main/LICENSE
5
5
  */
@@ -25,7 +25,7 @@ function bucketHash(input) {
25
25
  return fmix32(hash >>> 0);
26
26
  }
27
27
 
28
- const SDK_VERSION = '1.4.0';
28
+ const SDK_VERSION = '1.4.0-beta.6';
29
29
  const SDK_PLATFORM_HEADER = 'X-Joryio-SDK';
30
30
  const SDK_VERSION_HEADER = 'X-Joryio-SDK-Version';
31
31
  const SDK_PLATFORM = 'web';
@@ -546,7 +546,7 @@ function pageTriggerMet(trigger, signal, progress) {
546
546
  }
547
547
  }
548
548
 
549
- const PAGE_EDIT_POSITIONS = ['before', 'after', 'prepend', 'append'];
549
+ const PAGE_EDIT_POSITIONS = ['before', 'after', 'prepend', 'append', 'replace'];
550
550
  const PAGE_EDITS_CAPABILITY = 'page_edits';
551
551
  const PAGE_EDIT_ANTI_FLICKER_MS = 300;
552
552
  const MAX_SELECTOR_LENGTH = 500;
@@ -602,6 +602,27 @@ function safeRestoredUrl(v) {
602
602
  }
603
603
  const safeRestoredSrcset = (v) => typeof v === 'string' && v.split(',').every((c) => !c.trim() || safeRestoredUrl(c.trim().split(/\s+/)[0]) !== null) ? v : null;
604
604
  const HIDE_DECLARATION = 'display:none !important';
605
+ function hideElement(h) {
606
+ const display = h.style.getPropertyValue('display');
607
+ const priority = h.style.getPropertyPriority('display');
608
+ h.style.setProperty('display', 'none', 'important');
609
+ return () => (display ? h.style.setProperty('display', display, priority) : h.style.removeProperty('display'));
610
+ }
611
+ function undoServerHide(el, orig) {
612
+ var _a;
613
+ const current = el.getAttribute('style') || '';
614
+ const before = typeof orig.style === 'string' ? orig.style : null;
615
+ const base = before === null ? '' : before.trim().replace(/;+$/, '');
616
+ if (current === (base ? base + ';' : '') + HIDE_DECLARATION) {
617
+ if (before === null)
618
+ el.removeAttribute('style');
619
+ else
620
+ el.setAttribute('style', before);
621
+ }
622
+ else if (((_a = el.style) === null || _a === void 0 ? void 0 : _a.getPropertyValue('display')) === 'none') {
623
+ el.style.removeProperty('display');
624
+ }
625
+ }
605
626
  const RESTORE_ELEMENTS = new Set(['A', 'ABBR', 'B', 'BDI', 'BDO', 'BR', 'CITE', 'CODE', 'DATA', 'DEL', 'DFN', 'EM', 'I', 'IMG', 'INS', 'KBD', 'MARK', 'Q', 'S', 'SAMP', 'SMALL', 'SPAN', 'STRONG', 'SUB', 'SUP', 'TIME', 'U', 'VAR', 'WBR']);
606
627
  const RESTORE_ATTRIBUTES = new Set(['class', 'id', 'title', 'lang', 'dir', 'alt', 'width', 'height', 'datetime', 'href', 'src', 'srcset', 'rel', 'target']);
607
628
  const MAX_RESTORE_NODES = 500;
@@ -1063,19 +1084,21 @@ class PageEditManager {
1063
1084
  el.setAttribute('href', edit.value);
1064
1085
  return () => (href === null ? el.removeAttribute('href') : el.setAttribute('href', href));
1065
1086
  }
1066
- case 'hide': {
1067
- const display = h.style.getPropertyValue('display');
1068
- const priority = h.style.getPropertyPriority('display');
1069
- h.style.setProperty('display', 'none', 'important');
1070
- return () => (display ? h.style.setProperty('display', display, priority) : h.style.removeProperty('display'));
1071
- }
1087
+ case 'hide':
1088
+ return hideElement(h);
1072
1089
  case 'insert_placement': {
1073
1090
  const spot = document.createElement('div');
1074
1091
  spot.setAttribute('data-joryio-placement', edit.placementKey);
1075
1092
  spot.setAttribute('data-joryio-edit', edit.id);
1076
1093
  const where = edit.position === 'before' ? 'beforebegin' : edit.position === 'prepend' ? 'afterbegin' : edit.position === 'append' ? 'beforeend' : 'afterend';
1077
1094
  el.insertAdjacentElement(where, spot);
1078
- return () => spot.remove();
1095
+ if (edit.position !== 'replace')
1096
+ return () => spot.remove();
1097
+ const show = hideElement(h);
1098
+ return () => {
1099
+ spot.remove();
1100
+ show();
1101
+ };
1079
1102
  }
1080
1103
  default:
1081
1104
  return null;
@@ -1256,7 +1279,6 @@ class PageEditManager {
1256
1279
  }
1257
1280
  }
1258
1281
  undoServerEdit(token, edit) {
1259
- var _a;
1260
1282
  for (const el of Array.from(document.querySelectorAll(`[${SERVER_APPLIED_ATTR}]`))) {
1261
1283
  const tokens = tokensOf(el);
1262
1284
  if (!tokens.includes(token))
@@ -1265,7 +1287,7 @@ class PageEditManager {
1265
1287
  try {
1266
1288
  all = JSON.parse(el.getAttribute(SERVER_ORIG_ATTR) || '{}') || {};
1267
1289
  }
1268
- catch (_b) {
1290
+ catch (_a) {
1269
1291
  all = {};
1270
1292
  }
1271
1293
  const orig = all[token] || {};
@@ -1301,26 +1323,18 @@ class PageEditManager {
1301
1323
  el.setAttribute('href', href);
1302
1324
  }
1303
1325
  break;
1304
- case 'hide': {
1305
- const current = el.getAttribute('style') || '';
1306
- const before = typeof orig.style === 'string' ? orig.style : null;
1307
- const base = before === null ? '' : before.trim().replace(/;+$/, '');
1308
- if (current === (base ? base + ';' : '') + HIDE_DECLARATION) {
1309
- if (before === null)
1310
- el.removeAttribute('style');
1311
- else
1312
- el.setAttribute('style', before);
1313
- }
1314
- else if (((_a = el.style) === null || _a === void 0 ? void 0 : _a.getPropertyValue('display')) === 'none') {
1315
- el.style.removeProperty('display');
1316
- }
1326
+ case 'hide':
1327
+ undoServerHide(el, orig);
1328
+ break;
1329
+ case 'insert_placement':
1330
+ if (edit.position === 'replace')
1331
+ undoServerHide(el, orig);
1317
1332
  break;
1318
- }
1319
1333
  default:
1320
1334
  break;
1321
1335
  }
1322
1336
  }
1323
- catch (_c) {
1337
+ catch (_b) {
1324
1338
  }
1325
1339
  const left = tokens.filter((t) => t !== token);
1326
1340
  if (left.length)
@@ -1413,13 +1427,16 @@ function readOwnFolder() {
1413
1427
  return null;
1414
1428
  }
1415
1429
  const OWN_FOLDER = readOwnFolder();
1416
- function sdkHostFileUrls(file, override, ownFolder = OWN_FOLDER) {
1430
+ function sdkHostFileUrls(file, override, ownFolder = OWN_FOLDER, version = SDK_VERSION) {
1417
1431
  if (override)
1418
1432
  return [override];
1419
- const major = SDK_VERSION.split('.')[0];
1420
- const exact = `${SDK_HOST}/web/${SDK_VERSION}/${file}`;
1433
+ const major = version.split('.')[0];
1434
+ const exact = `${SDK_HOST}/web/${version}/${file}`;
1421
1435
  const channel = `${SDK_HOST}/web/${major}/${file}`;
1422
- const urls = ownFolder && ownFolder !== `${SDK_HOST}/web/${major}/` ? [`${ownFolder}${file}`, exact, channel] : [exact, channel];
1436
+ const prerelease = version.includes('-');
1437
+ let urls = ownFolder && ownFolder !== `${SDK_HOST}/web/${major}/` ? [`${ownFolder}${file}`, exact, channel] : [exact, channel];
1438
+ if (prerelease)
1439
+ urls = urls.filter((u) => u !== channel);
1423
1440
  return urls.filter((u, i) => urls.indexOf(u) === i);
1424
1441
  }
1425
1442
  function loadSdkScript(src, marker) {
@@ -5563,6 +5580,19 @@ function inAppTriggerFilterMatches(trigger, properties) {
5563
5580
  }
5564
5581
  }
5565
5582
 
5583
+ function joryioSubscription(stop) {
5584
+ let done = false;
5585
+ const cancel = () => {
5586
+ if (done)
5587
+ return;
5588
+ done = true;
5589
+ stop();
5590
+ };
5591
+ const sub = (() => cancel());
5592
+ sub.cancel = cancel;
5593
+ return sub;
5594
+ }
5595
+
5566
5596
  const PLACEMENT_VIEWABLE_FRACTION = 0.5;
5567
5597
  const PLACEMENT_MIN_REFRESH_SECONDS = 30;
5568
5598
  const PLACEMENT_BATCH_WINDOW_MS = 50;
@@ -5746,11 +5776,12 @@ class PlacementManager {
5746
5776
  }
5747
5777
  onPlacementsUpdated(callback) {
5748
5778
  if (typeof callback !== 'function')
5749
- return () => undefined;
5750
- this.listeners.add(callback);
5751
- return () => {
5752
- this.listeners.delete(callback);
5753
- };
5779
+ return joryioSubscription(() => undefined);
5780
+ const entry = (placements) => callback(placements);
5781
+ this.listeners.add(entry);
5782
+ return joryioSubscription(() => {
5783
+ this.listeners.delete(entry);
5784
+ });
5754
5785
  }
5755
5786
  autoMount() {
5756
5787
  if (typeof document === 'undefined' || typeof document.querySelectorAll !== 'function')
@@ -6715,11 +6746,12 @@ class CardManager {
6715
6746
  }
6716
6747
  onCardsUpdated(callback) {
6717
6748
  if (typeof callback !== 'function')
6718
- return () => undefined;
6719
- this.listeners.add(callback);
6720
- return () => {
6721
- this.listeners.delete(callback);
6722
- };
6749
+ return joryioSubscription(() => undefined);
6750
+ const entry = (feed) => callback(feed);
6751
+ this.listeners.add(entry);
6752
+ return joryioSubscription(() => {
6753
+ this.listeners.delete(entry);
6754
+ });
6723
6755
  }
6724
6756
  markCardViewed(card) {
6725
6757
  this.report(card, CARD_ACTIONS.VIEWED);
@@ -7370,9 +7402,14 @@ class FlagsManager {
7370
7402
  await this.refresh(true);
7371
7403
  }
7372
7404
  onFlagsUpdated(callback) {
7373
- this.listeners.add(callback);
7405
+ if (typeof callback !== 'function')
7406
+ return joryioSubscription(() => undefined);
7407
+ const entry = (keys) => callback(keys);
7408
+ this.listeners.add(entry);
7374
7409
  this.use();
7375
- return () => this.listeners.delete(callback);
7410
+ return joryioSubscription(() => {
7411
+ this.listeners.delete(entry);
7412
+ });
7376
7413
  }
7377
7414
  read(key, type) {
7378
7415
  if (!this.runtime.canSend())
@@ -11256,7 +11293,7 @@ class JoryioSDK {
11256
11293
  onPlacementsUpdated(callback) {
11257
11294
  if (!this.isInitialized) {
11258
11295
  this.logger.error('SDK not initialized');
11259
- return () => undefined;
11296
+ return joryioSubscription(() => undefined);
11260
11297
  }
11261
11298
  return this.placements.onPlacementsUpdated(callback);
11262
11299
  }
@@ -11300,7 +11337,7 @@ class JoryioSDK {
11300
11337
  onCardsUpdated(callback) {
11301
11338
  if (!this.isInitialized) {
11302
11339
  this.logger.error('SDK not initialized');
11303
- return () => undefined;
11340
+ return joryioSubscription(() => undefined);
11304
11341
  }
11305
11342
  return this.cards.onCardsUpdated(callback);
11306
11343
  }
@@ -11339,7 +11376,7 @@ class JoryioSDK {
11339
11376
  onFlagsUpdated(callback) {
11340
11377
  if (!this.isInitialized) {
11341
11378
  this.logger.error('SDK not initialized');
11342
- return () => undefined;
11379
+ return joryioSubscription(() => undefined);
11343
11380
  }
11344
11381
  return this.flags.onFlagsUpdated(callback);
11345
11382
  }
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Joryio Web SDK v1.4.0-beta.4
2
+ * Joryio Web SDK v1.4.0-beta.6
3
3
  * (c) 2026 Joryio. All rights reserved.
4
4
  * @license Commercial - see https://github.com/joryio/joryio-web-sdk/blob/main/LICENSE
5
5
  */
@@ -28,7 +28,7 @@ var JoryioSDK = (function (exports) {
28
28
  return fmix32(hash >>> 0);
29
29
  }
30
30
 
31
- const SDK_VERSION = '1.4.0';
31
+ const SDK_VERSION = '1.4.0-beta.6';
32
32
  const SDK_PLATFORM_HEADER = 'X-Joryio-SDK';
33
33
  const SDK_VERSION_HEADER = 'X-Joryio-SDK-Version';
34
34
  const SDK_PLATFORM = 'web';
@@ -549,7 +549,7 @@ var JoryioSDK = (function (exports) {
549
549
  }
550
550
  }
551
551
 
552
- const PAGE_EDIT_POSITIONS = ['before', 'after', 'prepend', 'append'];
552
+ const PAGE_EDIT_POSITIONS = ['before', 'after', 'prepend', 'append', 'replace'];
553
553
  const PAGE_EDITS_CAPABILITY = 'page_edits';
554
554
  const PAGE_EDIT_ANTI_FLICKER_MS = 300;
555
555
  const MAX_SELECTOR_LENGTH = 500;
@@ -605,6 +605,27 @@ var JoryioSDK = (function (exports) {
605
605
  }
606
606
  const safeRestoredSrcset = (v) => typeof v === 'string' && v.split(',').every((c) => !c.trim() || safeRestoredUrl(c.trim().split(/\s+/)[0]) !== null) ? v : null;
607
607
  const HIDE_DECLARATION = 'display:none !important';
608
+ function hideElement(h) {
609
+ const display = h.style.getPropertyValue('display');
610
+ const priority = h.style.getPropertyPriority('display');
611
+ h.style.setProperty('display', 'none', 'important');
612
+ return () => (display ? h.style.setProperty('display', display, priority) : h.style.removeProperty('display'));
613
+ }
614
+ function undoServerHide(el, orig) {
615
+ var _a;
616
+ const current = el.getAttribute('style') || '';
617
+ const before = typeof orig.style === 'string' ? orig.style : null;
618
+ const base = before === null ? '' : before.trim().replace(/;+$/, '');
619
+ if (current === (base ? base + ';' : '') + HIDE_DECLARATION) {
620
+ if (before === null)
621
+ el.removeAttribute('style');
622
+ else
623
+ el.setAttribute('style', before);
624
+ }
625
+ else if (((_a = el.style) === null || _a === void 0 ? void 0 : _a.getPropertyValue('display')) === 'none') {
626
+ el.style.removeProperty('display');
627
+ }
628
+ }
608
629
  const RESTORE_ELEMENTS = new Set(['A', 'ABBR', 'B', 'BDI', 'BDO', 'BR', 'CITE', 'CODE', 'DATA', 'DEL', 'DFN', 'EM', 'I', 'IMG', 'INS', 'KBD', 'MARK', 'Q', 'S', 'SAMP', 'SMALL', 'SPAN', 'STRONG', 'SUB', 'SUP', 'TIME', 'U', 'VAR', 'WBR']);
609
630
  const RESTORE_ATTRIBUTES = new Set(['class', 'id', 'title', 'lang', 'dir', 'alt', 'width', 'height', 'datetime', 'href', 'src', 'srcset', 'rel', 'target']);
610
631
  const MAX_RESTORE_NODES = 500;
@@ -1066,19 +1087,21 @@ var JoryioSDK = (function (exports) {
1066
1087
  el.setAttribute('href', edit.value);
1067
1088
  return () => (href === null ? el.removeAttribute('href') : el.setAttribute('href', href));
1068
1089
  }
1069
- case 'hide': {
1070
- const display = h.style.getPropertyValue('display');
1071
- const priority = h.style.getPropertyPriority('display');
1072
- h.style.setProperty('display', 'none', 'important');
1073
- return () => (display ? h.style.setProperty('display', display, priority) : h.style.removeProperty('display'));
1074
- }
1090
+ case 'hide':
1091
+ return hideElement(h);
1075
1092
  case 'insert_placement': {
1076
1093
  const spot = document.createElement('div');
1077
1094
  spot.setAttribute('data-joryio-placement', edit.placementKey);
1078
1095
  spot.setAttribute('data-joryio-edit', edit.id);
1079
1096
  const where = edit.position === 'before' ? 'beforebegin' : edit.position === 'prepend' ? 'afterbegin' : edit.position === 'append' ? 'beforeend' : 'afterend';
1080
1097
  el.insertAdjacentElement(where, spot);
1081
- return () => spot.remove();
1098
+ if (edit.position !== 'replace')
1099
+ return () => spot.remove();
1100
+ const show = hideElement(h);
1101
+ return () => {
1102
+ spot.remove();
1103
+ show();
1104
+ };
1082
1105
  }
1083
1106
  default:
1084
1107
  return null;
@@ -1259,7 +1282,6 @@ var JoryioSDK = (function (exports) {
1259
1282
  }
1260
1283
  }
1261
1284
  undoServerEdit(token, edit) {
1262
- var _a;
1263
1285
  for (const el of Array.from(document.querySelectorAll(`[${SERVER_APPLIED_ATTR}]`))) {
1264
1286
  const tokens = tokensOf(el);
1265
1287
  if (!tokens.includes(token))
@@ -1268,7 +1290,7 @@ var JoryioSDK = (function (exports) {
1268
1290
  try {
1269
1291
  all = JSON.parse(el.getAttribute(SERVER_ORIG_ATTR) || '{}') || {};
1270
1292
  }
1271
- catch (_b) {
1293
+ catch (_a) {
1272
1294
  all = {};
1273
1295
  }
1274
1296
  const orig = all[token] || {};
@@ -1304,26 +1326,18 @@ var JoryioSDK = (function (exports) {
1304
1326
  el.setAttribute('href', href);
1305
1327
  }
1306
1328
  break;
1307
- case 'hide': {
1308
- const current = el.getAttribute('style') || '';
1309
- const before = typeof orig.style === 'string' ? orig.style : null;
1310
- const base = before === null ? '' : before.trim().replace(/;+$/, '');
1311
- if (current === (base ? base + ';' : '') + HIDE_DECLARATION) {
1312
- if (before === null)
1313
- el.removeAttribute('style');
1314
- else
1315
- el.setAttribute('style', before);
1316
- }
1317
- else if (((_a = el.style) === null || _a === void 0 ? void 0 : _a.getPropertyValue('display')) === 'none') {
1318
- el.style.removeProperty('display');
1319
- }
1329
+ case 'hide':
1330
+ undoServerHide(el, orig);
1331
+ break;
1332
+ case 'insert_placement':
1333
+ if (edit.position === 'replace')
1334
+ undoServerHide(el, orig);
1320
1335
  break;
1321
- }
1322
1336
  default:
1323
1337
  break;
1324
1338
  }
1325
1339
  }
1326
- catch (_c) {
1340
+ catch (_b) {
1327
1341
  }
1328
1342
  const left = tokens.filter((t) => t !== token);
1329
1343
  if (left.length)
@@ -1416,13 +1430,16 @@ var JoryioSDK = (function (exports) {
1416
1430
  return null;
1417
1431
  }
1418
1432
  const OWN_FOLDER = readOwnFolder();
1419
- function sdkHostFileUrls(file, override, ownFolder = OWN_FOLDER) {
1433
+ function sdkHostFileUrls(file, override, ownFolder = OWN_FOLDER, version = SDK_VERSION) {
1420
1434
  if (override)
1421
1435
  return [override];
1422
- const major = SDK_VERSION.split('.')[0];
1423
- const exact = `${SDK_HOST}/web/${SDK_VERSION}/${file}`;
1436
+ const major = version.split('.')[0];
1437
+ const exact = `${SDK_HOST}/web/${version}/${file}`;
1424
1438
  const channel = `${SDK_HOST}/web/${major}/${file}`;
1425
- const urls = ownFolder && ownFolder !== `${SDK_HOST}/web/${major}/` ? [`${ownFolder}${file}`, exact, channel] : [exact, channel];
1439
+ const prerelease = version.includes('-');
1440
+ let urls = ownFolder && ownFolder !== `${SDK_HOST}/web/${major}/` ? [`${ownFolder}${file}`, exact, channel] : [exact, channel];
1441
+ if (prerelease)
1442
+ urls = urls.filter((u) => u !== channel);
1426
1443
  return urls.filter((u, i) => urls.indexOf(u) === i);
1427
1444
  }
1428
1445
  function loadSdkScript(src, marker) {
@@ -5566,6 +5583,19 @@ var JoryioSDK = (function (exports) {
5566
5583
  }
5567
5584
  }
5568
5585
 
5586
+ function joryioSubscription(stop) {
5587
+ let done = false;
5588
+ const cancel = () => {
5589
+ if (done)
5590
+ return;
5591
+ done = true;
5592
+ stop();
5593
+ };
5594
+ const sub = (() => cancel());
5595
+ sub.cancel = cancel;
5596
+ return sub;
5597
+ }
5598
+
5569
5599
  const PLACEMENT_VIEWABLE_FRACTION = 0.5;
5570
5600
  const PLACEMENT_MIN_REFRESH_SECONDS = 30;
5571
5601
  const PLACEMENT_BATCH_WINDOW_MS = 50;
@@ -5749,11 +5779,12 @@ var JoryioSDK = (function (exports) {
5749
5779
  }
5750
5780
  onPlacementsUpdated(callback) {
5751
5781
  if (typeof callback !== 'function')
5752
- return () => undefined;
5753
- this.listeners.add(callback);
5754
- return () => {
5755
- this.listeners.delete(callback);
5756
- };
5782
+ return joryioSubscription(() => undefined);
5783
+ const entry = (placements) => callback(placements);
5784
+ this.listeners.add(entry);
5785
+ return joryioSubscription(() => {
5786
+ this.listeners.delete(entry);
5787
+ });
5757
5788
  }
5758
5789
  autoMount() {
5759
5790
  if (typeof document === 'undefined' || typeof document.querySelectorAll !== 'function')
@@ -6718,11 +6749,12 @@ var JoryioSDK = (function (exports) {
6718
6749
  }
6719
6750
  onCardsUpdated(callback) {
6720
6751
  if (typeof callback !== 'function')
6721
- return () => undefined;
6722
- this.listeners.add(callback);
6723
- return () => {
6724
- this.listeners.delete(callback);
6725
- };
6752
+ return joryioSubscription(() => undefined);
6753
+ const entry = (feed) => callback(feed);
6754
+ this.listeners.add(entry);
6755
+ return joryioSubscription(() => {
6756
+ this.listeners.delete(entry);
6757
+ });
6726
6758
  }
6727
6759
  markCardViewed(card) {
6728
6760
  this.report(card, CARD_ACTIONS.VIEWED);
@@ -7373,9 +7405,14 @@ var JoryioSDK = (function (exports) {
7373
7405
  await this.refresh(true);
7374
7406
  }
7375
7407
  onFlagsUpdated(callback) {
7376
- this.listeners.add(callback);
7408
+ if (typeof callback !== 'function')
7409
+ return joryioSubscription(() => undefined);
7410
+ const entry = (keys) => callback(keys);
7411
+ this.listeners.add(entry);
7377
7412
  this.use();
7378
- return () => this.listeners.delete(callback);
7413
+ return joryioSubscription(() => {
7414
+ this.listeners.delete(entry);
7415
+ });
7379
7416
  }
7380
7417
  read(key, type) {
7381
7418
  if (!this.runtime.canSend())
@@ -11259,7 +11296,7 @@ var JoryioSDK = (function (exports) {
11259
11296
  onPlacementsUpdated(callback) {
11260
11297
  if (!this.isInitialized) {
11261
11298
  this.logger.error('SDK not initialized');
11262
- return () => undefined;
11299
+ return joryioSubscription(() => undefined);
11263
11300
  }
11264
11301
  return this.placements.onPlacementsUpdated(callback);
11265
11302
  }
@@ -11303,7 +11340,7 @@ var JoryioSDK = (function (exports) {
11303
11340
  onCardsUpdated(callback) {
11304
11341
  if (!this.isInitialized) {
11305
11342
  this.logger.error('SDK not initialized');
11306
- return () => undefined;
11343
+ return joryioSubscription(() => undefined);
11307
11344
  }
11308
11345
  return this.cards.onCardsUpdated(callback);
11309
11346
  }
@@ -11342,7 +11379,7 @@ var JoryioSDK = (function (exports) {
11342
11379
  onFlagsUpdated(callback) {
11343
11380
  if (!this.isInitialized) {
11344
11381
  this.logger.error('SDK not initialized');
11345
- return () => undefined;
11382
+ return joryioSubscription(() => undefined);
11346
11383
  }
11347
11384
  return this.flags.onFlagsUpdated(callback);
11348
11385
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@joryio/web-sdk",
3
- "version": "1.4.0-beta.4",
3
+ "version": "1.4.0-beta.6",
4
4
  "description": "Joryio Web Tracking SDK - Lightweight analytics and event tracking",
5
5
  "main": "dist/joryio.cjs.js",
6
6
  "module": "dist/joryio.mjs",
package/src/core/cards.ts CHANGED
@@ -34,6 +34,7 @@
34
34
  * identity and consent changes.
35
35
  */
36
36
 
37
+ import { JoryioSubscription, joryioSubscription } from './subscription';
37
38
  import { Logger } from '../utils/logger';
38
39
  import { bucketHash } from '../utils/bucket-hash';
39
40
  import { sdkIdentityHeaders } from './config';
@@ -292,13 +293,15 @@ export class CardManager {
292
293
  await this.fetch(true);
293
294
  }
294
295
 
295
- /** Called with the whole feed whenever it changes. Returns an unsubscribe. */
296
- onCardsUpdated(callback: CardsUpdatedCallback): () => void {
297
- if (typeof callback !== 'function') return () => undefined;
298
- this.listeners.add(callback);
299
- return () => {
300
- this.listeners.delete(callback);
301
- };
296
+ /** Called with the whole feed whenever it changes. Returns a JoryioSubscription. */
297
+ onCardsUpdated(callback: CardsUpdatedCallback): JoryioSubscription {
298
+ if (typeof callback !== 'function') return joryioSubscription(() => undefined);
299
+ // One entry per subscription, so the same function subscribed twice is two subscriptions.
300
+ const entry: CardsUpdatedCallback = (feed) => callback(feed);
301
+ this.listeners.add(entry);
302
+ return joryioSubscription(() => {
303
+ this.listeners.delete(entry);
304
+ });
302
305
  }
303
306
 
304
307
  markCardViewed(card: Card | string): void {
@@ -2,7 +2,7 @@
2
2
  * SDK Configuration Types and Defaults
3
3
  */
4
4
 
5
- export const SDK_VERSION = '1.4.0'; // keep in sync with package.json (sdk-version-parity.spec.ts pins it)
5
+ export const SDK_VERSION = '1.4.0-beta.6'; // keep in sync with package.json (sdk-version-parity.spec.ts pins it)
6
6
 
7
7
  /**
8
8
  * Sent on EVERY request to the API, so the dashboard can show which SDK
package/src/core/flags.ts CHANGED
@@ -23,6 +23,7 @@
23
23
  *
24
24
  * The same names and wire values on all five SDKs.
25
25
  */
26
+ import { JoryioSubscription, joryioSubscription } from './subscription';
26
27
  import { Logger } from '../utils/logger';
27
28
  import { bucketHash } from '../utils/bucket-hash';
28
29
  import { sdkIdentityHeaders } from './config';
@@ -198,11 +199,16 @@ export class FlagsManager {
198
199
  await this.refresh(true);
199
200
  }
200
201
 
201
- /** Called with the keys whose value changed. Returns an unsubscribe function. */
202
- onFlagsUpdated(callback: FlagsUpdatedCallback): () => void {
203
- this.listeners.add(callback);
202
+ /** Called with the keys whose value changed. Returns a JoryioSubscription. */
203
+ onFlagsUpdated(callback: FlagsUpdatedCallback): JoryioSubscription {
204
+ if (typeof callback !== 'function') return joryioSubscription(() => undefined);
205
+ // One entry per subscription, so the same function subscribed twice is two subscriptions.
206
+ const entry: FlagsUpdatedCallback = (keys) => callback(keys);
207
+ this.listeners.add(entry);
204
208
  this.use();
205
- return () => this.listeners.delete(callback);
209
+ return joryioSubscription(() => {
210
+ this.listeners.delete(entry);
211
+ });
206
212
  }
207
213
 
208
214
  // ── internals ────────────────────────────────────────────────────────────