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

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/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.5
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
  */
@@ -5563,6 +5563,19 @@ function inAppTriggerFilterMatches(trigger, properties) {
5563
5563
  }
5564
5564
  }
5565
5565
 
5566
+ function joryioSubscription(stop) {
5567
+ let done = false;
5568
+ const cancel = () => {
5569
+ if (done)
5570
+ return;
5571
+ done = true;
5572
+ stop();
5573
+ };
5574
+ const sub = (() => cancel());
5575
+ sub.cancel = cancel;
5576
+ return sub;
5577
+ }
5578
+
5566
5579
  const PLACEMENT_VIEWABLE_FRACTION = 0.5;
5567
5580
  const PLACEMENT_MIN_REFRESH_SECONDS = 30;
5568
5581
  const PLACEMENT_BATCH_WINDOW_MS = 50;
@@ -5746,11 +5759,12 @@ class PlacementManager {
5746
5759
  }
5747
5760
  onPlacementsUpdated(callback) {
5748
5761
  if (typeof callback !== 'function')
5749
- return () => undefined;
5750
- this.listeners.add(callback);
5751
- return () => {
5752
- this.listeners.delete(callback);
5753
- };
5762
+ return joryioSubscription(() => undefined);
5763
+ const entry = (placements) => callback(placements);
5764
+ this.listeners.add(entry);
5765
+ return joryioSubscription(() => {
5766
+ this.listeners.delete(entry);
5767
+ });
5754
5768
  }
5755
5769
  autoMount() {
5756
5770
  if (typeof document === 'undefined' || typeof document.querySelectorAll !== 'function')
@@ -6715,11 +6729,12 @@ class CardManager {
6715
6729
  }
6716
6730
  onCardsUpdated(callback) {
6717
6731
  if (typeof callback !== 'function')
6718
- return () => undefined;
6719
- this.listeners.add(callback);
6720
- return () => {
6721
- this.listeners.delete(callback);
6722
- };
6732
+ return joryioSubscription(() => undefined);
6733
+ const entry = (feed) => callback(feed);
6734
+ this.listeners.add(entry);
6735
+ return joryioSubscription(() => {
6736
+ this.listeners.delete(entry);
6737
+ });
6723
6738
  }
6724
6739
  markCardViewed(card) {
6725
6740
  this.report(card, CARD_ACTIONS.VIEWED);
@@ -7370,9 +7385,14 @@ class FlagsManager {
7370
7385
  await this.refresh(true);
7371
7386
  }
7372
7387
  onFlagsUpdated(callback) {
7373
- this.listeners.add(callback);
7388
+ if (typeof callback !== 'function')
7389
+ return joryioSubscription(() => undefined);
7390
+ const entry = (keys) => callback(keys);
7391
+ this.listeners.add(entry);
7374
7392
  this.use();
7375
- return () => this.listeners.delete(callback);
7393
+ return joryioSubscription(() => {
7394
+ this.listeners.delete(entry);
7395
+ });
7376
7396
  }
7377
7397
  read(key, type) {
7378
7398
  if (!this.runtime.canSend())
@@ -11256,7 +11276,7 @@ class JoryioSDK {
11256
11276
  onPlacementsUpdated(callback) {
11257
11277
  if (!this.isInitialized) {
11258
11278
  this.logger.error('SDK not initialized');
11259
- return () => undefined;
11279
+ return joryioSubscription(() => undefined);
11260
11280
  }
11261
11281
  return this.placements.onPlacementsUpdated(callback);
11262
11282
  }
@@ -11300,7 +11320,7 @@ class JoryioSDK {
11300
11320
  onCardsUpdated(callback) {
11301
11321
  if (!this.isInitialized) {
11302
11322
  this.logger.error('SDK not initialized');
11303
- return () => undefined;
11323
+ return joryioSubscription(() => undefined);
11304
11324
  }
11305
11325
  return this.cards.onCardsUpdated(callback);
11306
11326
  }
@@ -11339,7 +11359,7 @@ class JoryioSDK {
11339
11359
  onFlagsUpdated(callback) {
11340
11360
  if (!this.isInitialized) {
11341
11361
  this.logger.error('SDK not initialized');
11342
- return () => undefined;
11362
+ return joryioSubscription(() => undefined);
11343
11363
  }
11344
11364
  return this.flags.onFlagsUpdated(callback);
11345
11365
  }
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Joryio Web SDK v1.4.0-beta.4
2
+ * Joryio Web SDK v1.4.0-beta.5
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
  */
@@ -5566,6 +5566,19 @@ var JoryioSDK = (function (exports) {
5566
5566
  }
5567
5567
  }
5568
5568
 
5569
+ function joryioSubscription(stop) {
5570
+ let done = false;
5571
+ const cancel = () => {
5572
+ if (done)
5573
+ return;
5574
+ done = true;
5575
+ stop();
5576
+ };
5577
+ const sub = (() => cancel());
5578
+ sub.cancel = cancel;
5579
+ return sub;
5580
+ }
5581
+
5569
5582
  const PLACEMENT_VIEWABLE_FRACTION = 0.5;
5570
5583
  const PLACEMENT_MIN_REFRESH_SECONDS = 30;
5571
5584
  const PLACEMENT_BATCH_WINDOW_MS = 50;
@@ -5749,11 +5762,12 @@ var JoryioSDK = (function (exports) {
5749
5762
  }
5750
5763
  onPlacementsUpdated(callback) {
5751
5764
  if (typeof callback !== 'function')
5752
- return () => undefined;
5753
- this.listeners.add(callback);
5754
- return () => {
5755
- this.listeners.delete(callback);
5756
- };
5765
+ return joryioSubscription(() => undefined);
5766
+ const entry = (placements) => callback(placements);
5767
+ this.listeners.add(entry);
5768
+ return joryioSubscription(() => {
5769
+ this.listeners.delete(entry);
5770
+ });
5757
5771
  }
5758
5772
  autoMount() {
5759
5773
  if (typeof document === 'undefined' || typeof document.querySelectorAll !== 'function')
@@ -6718,11 +6732,12 @@ var JoryioSDK = (function (exports) {
6718
6732
  }
6719
6733
  onCardsUpdated(callback) {
6720
6734
  if (typeof callback !== 'function')
6721
- return () => undefined;
6722
- this.listeners.add(callback);
6723
- return () => {
6724
- this.listeners.delete(callback);
6725
- };
6735
+ return joryioSubscription(() => undefined);
6736
+ const entry = (feed) => callback(feed);
6737
+ this.listeners.add(entry);
6738
+ return joryioSubscription(() => {
6739
+ this.listeners.delete(entry);
6740
+ });
6726
6741
  }
6727
6742
  markCardViewed(card) {
6728
6743
  this.report(card, CARD_ACTIONS.VIEWED);
@@ -7373,9 +7388,14 @@ var JoryioSDK = (function (exports) {
7373
7388
  await this.refresh(true);
7374
7389
  }
7375
7390
  onFlagsUpdated(callback) {
7376
- this.listeners.add(callback);
7391
+ if (typeof callback !== 'function')
7392
+ return joryioSubscription(() => undefined);
7393
+ const entry = (keys) => callback(keys);
7394
+ this.listeners.add(entry);
7377
7395
  this.use();
7378
- return () => this.listeners.delete(callback);
7396
+ return joryioSubscription(() => {
7397
+ this.listeners.delete(entry);
7398
+ });
7379
7399
  }
7380
7400
  read(key, type) {
7381
7401
  if (!this.runtime.canSend())
@@ -11259,7 +11279,7 @@ var JoryioSDK = (function (exports) {
11259
11279
  onPlacementsUpdated(callback) {
11260
11280
  if (!this.isInitialized) {
11261
11281
  this.logger.error('SDK not initialized');
11262
- return () => undefined;
11282
+ return joryioSubscription(() => undefined);
11263
11283
  }
11264
11284
  return this.placements.onPlacementsUpdated(callback);
11265
11285
  }
@@ -11303,7 +11323,7 @@ var JoryioSDK = (function (exports) {
11303
11323
  onCardsUpdated(callback) {
11304
11324
  if (!this.isInitialized) {
11305
11325
  this.logger.error('SDK not initialized');
11306
- return () => undefined;
11326
+ return joryioSubscription(() => undefined);
11307
11327
  }
11308
11328
  return this.cards.onCardsUpdated(callback);
11309
11329
  }
@@ -11342,7 +11362,7 @@ var JoryioSDK = (function (exports) {
11342
11362
  onFlagsUpdated(callback) {
11343
11363
  if (!this.isInitialized) {
11344
11364
  this.logger.error('SDK not initialized');
11345
- return () => undefined;
11365
+ return joryioSubscription(() => undefined);
11346
11366
  }
11347
11367
  return this.flags.onFlagsUpdated(callback);
11348
11368
  }
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.5",
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 {
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 ────────────────────────────────────────────────────────────
@@ -32,6 +32,7 @@
32
32
  * only when `allowHtmlJsInAppMessages` is on.
33
33
  */
34
34
 
35
+ import { JoryioSubscription, joryioSubscription } from './subscription';
35
36
  import { bucketHash } from '../utils/bucket-hash';
36
37
  import { currentPageUrl, PAGE_CONTEXT_CAPABILITY, type PageContextTracker } from './page-context';
37
38
  import { Logger } from '../utils/logger';
@@ -488,13 +489,15 @@ export class PlacementManager {
488
489
  await this.fetchKeys(wanted, true);
489
490
  }
490
491
 
491
- /** Called with the placements that changed after each answer. Returns an unsubscribe. */
492
- onPlacementsUpdated(callback: PlacementsUpdatedCallback): () => void {
493
- if (typeof callback !== 'function') return () => undefined;
494
- this.listeners.add(callback);
495
- return () => {
496
- this.listeners.delete(callback);
497
- };
492
+ /** Called with the placements that changed after each answer. Returns a JoryioSubscription. */
493
+ onPlacementsUpdated(callback: PlacementsUpdatedCallback): JoryioSubscription {
494
+ if (typeof callback !== 'function') return joryioSubscription(() => undefined);
495
+ // One entry per subscription, so the same function subscribed twice is two subscriptions.
496
+ const entry: PlacementsUpdatedCallback = (placements) => callback(placements);
497
+ this.listeners.add(entry);
498
+ return joryioSubscription(() => {
499
+ this.listeners.delete(entry);
500
+ });
498
501
  }
499
502
 
500
503
  /** Mount every `[data-joryio-placement]` element on the page, now and as the page changes. */
package/src/core/sdk.ts CHANGED
@@ -23,6 +23,7 @@ import { UTMManager } from './utm';
23
23
  import { InAppMessagingManager, InAppCampaign } from './inapp';
24
24
  import { PlacementManager, Placement, PlacementHandle, InsertPlacementOptions, PlacementsUpdatedCallback, PlacementConsent } from './placements';
25
25
  import { CardManager, Card, CardFeed, CardFeedHandle, CardsUpdatedCallback, GetCardsOptions, MountCardFeedOptions } from './cards';
26
+ import { JoryioSubscription, joryioSubscription } from './subscription';
26
27
  import { LinkRouter, JoryioLinkHandler } from './links';
27
28
  import { FlagsManager, FlagsUpdatedCallback } from './flags';
28
29
  import { User } from './user';
@@ -3483,11 +3484,11 @@ export class JoryioSDK {
3483
3484
  await this.placements.refreshPlacements(placementKeys);
3484
3485
  }
3485
3486
 
3486
- /** Called with the placements whose content changed. Returns an unsubscribe function. */
3487
- onPlacementsUpdated(callback: PlacementsUpdatedCallback): () => void {
3487
+ /** Called with the placements whose content changed. Returns a JoryioSubscription: `cancel()` it to stop (calling it is the same). */
3488
+ onPlacementsUpdated(callback: PlacementsUpdatedCallback): JoryioSubscription {
3488
3489
  if (!this.isInitialized) {
3489
3490
  this.logger.error('SDK not initialized');
3490
- return () => undefined;
3491
+ return joryioSubscription(() => undefined);
3491
3492
  }
3492
3493
  return this.placements.onPlacementsUpdated(callback);
3493
3494
  }
@@ -3542,11 +3543,15 @@ export class JoryioSDK {
3542
3543
  await this.cards.refreshCards();
3543
3544
  }
3544
3545
 
3545
- /** Called with the whole feed whenever it changes. Returns an unsubscribe function. */
3546
- onCardsUpdated(callback: CardsUpdatedCallback): () => void {
3546
+ /**
3547
+ * Called with the whole feed whenever it changes - the way to keep a feed UI
3548
+ * of your own up to date. Returns a JoryioSubscription: `cancel()` it to stop
3549
+ * (calling it, `sub()`, is the same).
3550
+ */
3551
+ onCardsUpdated(callback: CardsUpdatedCallback): JoryioSubscription {
3547
3552
  if (!this.isInitialized) {
3548
3553
  this.logger.error('SDK not initialized');
3549
- return () => undefined;
3554
+ return joryioSubscription(() => undefined);
3550
3555
  }
3551
3556
  return this.cards.onCardsUpdated(callback);
3552
3557
  }
@@ -3611,11 +3616,11 @@ export class JoryioSDK {
3611
3616
  await this.flags.refreshFlags();
3612
3617
  }
3613
3618
 
3614
- /** Called with the keys whose value changed. Returns an unsubscribe function. */
3615
- onFlagsUpdated(callback: FlagsUpdatedCallback): () => void {
3619
+ /** Called with the keys whose value changed. Returns a JoryioSubscription: `cancel()` it to stop (calling it is the same). */
3620
+ onFlagsUpdated(callback: FlagsUpdatedCallback): JoryioSubscription {
3616
3621
  if (!this.isInitialized) {
3617
3622
  this.logger.error('SDK not initialized');
3618
- return () => undefined;
3623
+ return joryioSubscription(() => undefined);
3619
3624
  }
3620
3625
  return this.flags.onFlagsUpdated(callback);
3621
3626
  }
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Returned by every `on...Updated` listener - `onCardsUpdated`,
3
+ * `onPlacementsUpdated` and `onFlagsUpdated`: `cancel()` stops the updates.
4
+ * It is also callable, `sub()` being `sub.cancel()`, so code that called the
5
+ * returned function keeps working. Cancelling twice is harmless.
6
+ *
7
+ * One type with the same name and the same `cancel()` on every Joryio SDK
8
+ * (iOS, Android, React Native; Unity `JoryioSubscription.Cancel()`), pinned by
9
+ * the backend's SDK parity spec.
10
+ */
11
+ export interface JoryioSubscription {
12
+ (): void;
13
+ cancel(): void;
14
+ }
15
+
16
+ /** A JoryioSubscription that runs `stop` once. */
17
+ export function joryioSubscription(stop: () => void): JoryioSubscription {
18
+ let done = false;
19
+ const cancel = (): void => {
20
+ if (done) return;
21
+ done = true;
22
+ stop();
23
+ };
24
+ const sub = (() => cancel()) as JoryioSubscription;
25
+ sub.cancel = cancel;
26
+ return sub;
27
+ }
package/src/index.ts CHANGED
@@ -100,6 +100,8 @@ export type {
100
100
  MountCardFeedOptions,
101
101
  CardsUpdatedCallback,
102
102
  } from './core/cards';
103
+ // The one subscription every on...Updated listener returns (the same name on every Joryio SDK).
104
+ export type { JoryioSubscription } from './core/subscription';
103
105
  // Feature flags + remote config (the same names and values on every Joryio SDK).
104
106
  export { FLAGS_MIN_REFRESH_SECONDS, FLAG_SYNC_PUSH_VALUE } from './core/flags';
105
107
  export type { FlagResult, FlagValueType, FlagReason, FlagsUpdatedCallback } from './core/flags';