@xenia-martech/sdk-js 1.0.0-dev.25 → 1.0.0-dev.27

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 (36) hide show
  1. package/README.md +31 -45
  2. package/dist/{actions-DfuHrjUL.d.cts → actions-CkiSdvSa.d.cts} +73 -11
  3. package/dist/{actions-DfuHrjUL.d.ts → actions-CkiSdvSa.d.ts} +73 -11
  4. package/dist/{chunk-PTYUK4P3.js → chunk-7D2HJMW6.js} +33 -4
  5. package/dist/chunk-7D2HJMW6.js.map +1 -0
  6. package/dist/{chunk-JEFNAD5J.cjs → chunk-UOW3GK4I.cjs} +34 -3
  7. package/dist/chunk-UOW3GK4I.cjs.map +1 -0
  8. package/dist/client/index.cjs +75 -9
  9. package/dist/client/index.cjs.map +1 -1
  10. package/dist/client/index.d.cts +2 -2
  11. package/dist/client/index.d.ts +2 -2
  12. package/dist/client/index.js +75 -9
  13. package/dist/client/index.js.map +1 -1
  14. package/dist/client/react/index.cjs +75 -9
  15. package/dist/client/react/index.cjs.map +1 -1
  16. package/dist/client/react/index.d.cts +3 -3
  17. package/dist/client/react/index.d.ts +3 -3
  18. package/dist/client/react/index.js +75 -9
  19. package/dist/client/react/index.js.map +1 -1
  20. package/dist/{cookie-names-BQ-L04A8.d.cts → cookie-names-C3LKDhsg.d.cts} +42 -6
  21. package/dist/{cookie-names-BQ-L04A8.d.ts → cookie-names-C3LKDhsg.d.ts} +42 -6
  22. package/dist/index.cjs +23 -19
  23. package/dist/index.d.cts +25 -4
  24. package/dist/index.d.ts +25 -4
  25. package/dist/index.js +1 -1
  26. package/dist/server/index.cjs +53 -22
  27. package/dist/server/index.cjs.map +1 -1
  28. package/dist/server/index.d.cts +37 -14
  29. package/dist/server/index.d.ts +37 -14
  30. package/dist/server/index.js +43 -12
  31. package/dist/server/index.js.map +1 -1
  32. package/dist/xenia-sdk.iife.js +3 -3
  33. package/dist/xenia-sdk.iife.js.map +1 -1
  34. package/package.json +1 -1
  35. package/dist/chunk-JEFNAD5J.cjs.map +0 -1
  36. package/dist/chunk-PTYUK4P3.js.map +0 -1
@@ -1,5 +1,5 @@
1
- import { I as InteractionType, X as XeniaConfig, a as XeniaEvent, M as MessageCta, b as MessageTemplateFn, c as MessageComponentRenderer, d as XeniaAction } from '../actions-DfuHrjUL.cjs';
2
- export { A as AnalyticsContext, e as AnalyticsEventName, f as AnalyticsIdentity, g as AnalyticsIngestResponse, C as ClientEvent, h as ConsentState, i as ContentSwap, j as IdentifyRequest, k as IdentifyResponse, l as Identity, J as JsonValue, m as MessageMountContext, n as MessagePlacement, o as MessageRenderContext, P as PersonalizationSwap, R as ResolveBatchItem, p as ResolveBatchResult, q as ResolveOptions, r as ResolveResult, T as TrackOptions, W as WebhookResponse, s as XeniaClient, t as XeniaClientOptions, u as createXeniaClient, v as extractContentSwaps, w as parseActions, x as spliceSlots } from '../actions-DfuHrjUL.cjs';
1
+ import { I as InteractionType, X as XeniaConfig, a as XeniaEvent, M as MessageCta, b as MessageTemplateFn, c as MessageComponentRenderer, d as XeniaAction } from '../actions-CkiSdvSa.cjs';
2
+ export { A as AnalyticsContext, e as AnalyticsEventName, f as AnalyticsIdentity, g as AnalyticsIngestResponse, C as ClientEvent, h as ConsentState, i as ContentSwap, j as IdentifyRequest, k as IdentifyResponse, l as Identity, J as JsonValue, m as MessageMountContext, n as MessagePlacement, o as MessageRenderContext, P as PersonalizationSwap, R as ResolveBatchItem, p as ResolveBatchResult, q as ResolveOptions, r as ResolveResult, T as TrackOptions, W as WebhookResponse, s as XeniaClient, t as XeniaClientOptions, u as createXeniaClient, v as extractContentSwaps, w as parseActions, x as spliceSlots } from '../actions-CkiSdvSa.cjs';
3
3
 
4
4
  interface Parsed {
5
5
  eventId: string;
@@ -1,5 +1,5 @@
1
- import { I as InteractionType, X as XeniaConfig, a as XeniaEvent, M as MessageCta, b as MessageTemplateFn, c as MessageComponentRenderer, d as XeniaAction } from '../actions-DfuHrjUL.js';
2
- export { A as AnalyticsContext, e as AnalyticsEventName, f as AnalyticsIdentity, g as AnalyticsIngestResponse, C as ClientEvent, h as ConsentState, i as ContentSwap, j as IdentifyRequest, k as IdentifyResponse, l as Identity, J as JsonValue, m as MessageMountContext, n as MessagePlacement, o as MessageRenderContext, P as PersonalizationSwap, R as ResolveBatchItem, p as ResolveBatchResult, q as ResolveOptions, r as ResolveResult, T as TrackOptions, W as WebhookResponse, s as XeniaClient, t as XeniaClientOptions, u as createXeniaClient, v as extractContentSwaps, w as parseActions, x as spliceSlots } from '../actions-DfuHrjUL.js';
1
+ import { I as InteractionType, X as XeniaConfig, a as XeniaEvent, M as MessageCta, b as MessageTemplateFn, c as MessageComponentRenderer, d as XeniaAction } from '../actions-CkiSdvSa.js';
2
+ export { A as AnalyticsContext, e as AnalyticsEventName, f as AnalyticsIdentity, g as AnalyticsIngestResponse, C as ClientEvent, h as ConsentState, i as ContentSwap, j as IdentifyRequest, k as IdentifyResponse, l as Identity, J as JsonValue, m as MessageMountContext, n as MessagePlacement, o as MessageRenderContext, P as PersonalizationSwap, R as ResolveBatchItem, p as ResolveBatchResult, q as ResolveOptions, r as ResolveResult, T as TrackOptions, W as WebhookResponse, s as XeniaClient, t as XeniaClientOptions, u as createXeniaClient, v as extractContentSwaps, w as parseActions, x as spliceSlots } from '../actions-CkiSdvSa.js';
3
3
 
4
4
  interface Parsed {
5
5
  eventId: string;
@@ -85,6 +85,7 @@ function parseActions(body) {
85
85
  }
86
86
 
87
87
  // src/core/http-client.ts
88
+ var DEFAULT_BASE_URL = "https://engine.xeniamartech.com/xenia";
88
89
  function isBrowser() {
89
90
  return typeof window !== "undefined" && typeof document !== "undefined";
90
91
  }
@@ -114,7 +115,7 @@ var HttpClient = class {
114
115
  retry;
115
116
  debug;
116
117
  constructor(opts) {
117
- this.baseUrl = opts.baseUrl.replace(/\/+$/, "");
118
+ this.baseUrl = (opts.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
118
119
  this.defaultHeaders = opts.defaultHeaders ?? {};
119
120
  this.timeout = opts.timeout ?? 8e3;
120
121
  this.retry = {
@@ -963,6 +964,40 @@ var Identity = class {
963
964
  return null;
964
965
  }
965
966
  }
967
+ // ── Customer id / email ──────────────────────────────────────────────────
968
+ //
969
+ // Ambient, persisted the same way as the visitor id, so a value set once
970
+ // (typically alongside `identify()`) rides on every later `resolve()` call
971
+ // without the caller having to pass it again — the SDK-provided-fields
972
+ // parity list on the Personalization Resolve trigger includes both.
973
+ setCustomerId(customerId) {
974
+ try {
975
+ if (customerId) localStorage.setItem(this.key("customer_id"), customerId);
976
+ else localStorage.removeItem(this.key("customer_id"));
977
+ } catch {
978
+ }
979
+ }
980
+ getCustomerId() {
981
+ try {
982
+ return localStorage.getItem(this.key("customer_id"));
983
+ } catch {
984
+ return null;
985
+ }
986
+ }
987
+ setEmail(email) {
988
+ try {
989
+ if (email) localStorage.setItem(this.key("email"), email);
990
+ else localStorage.removeItem(this.key("email"));
991
+ } catch {
992
+ }
993
+ }
994
+ getEmail() {
995
+ try {
996
+ return localStorage.getItem(this.key("email"));
997
+ } catch {
998
+ return null;
999
+ }
1000
+ }
966
1001
  // ── Session id ───────────────────────────────────────────────────────────────
967
1002
  /**
968
1003
  * Resolve the current session id: reused while activity continues within
@@ -1426,10 +1461,16 @@ var XeniaClient = class {
1426
1461
  * Persist a visitor id, attached to every subsequent event, and bind it to
1427
1462
  * a known user server-side (`POST /api/events/v1/identify`, fire-and-
1428
1463
  * forget — resolves to an `"identify"` client event carrying `personId`).
1464
+ *
1465
+ * `extra.customerId`/`extra.email`, when supplied, are also persisted
1466
+ * ambiently (like the visitor id) so they ride on every later `resolve()`
1467
+ * call automatically — part of the SDK-provided-fields parity list.
1429
1468
  */
1430
- identify(visitorId) {
1469
+ identify(visitorId, extra) {
1431
1470
  this.identity.identify(visitorId);
1432
- void this.api.identify({ xeniaVisitorId: visitorId }).then((res) => this.emit("identify", res)).catch((err) => this.emitError(err));
1471
+ if (extra?.customerId !== void 0) this.identity.setCustomerId(extra.customerId);
1472
+ if (extra?.email !== void 0) this.identity.setEmail(extra.email);
1473
+ void this.api.identify({ xeniaVisitorId: visitorId, userId: extra?.customerId, email: extra?.email }).then((res) => this.emit("identify", res)).catch((err) => this.emitError(err));
1433
1474
  }
1434
1475
  /** Override the customer-journey UUID (else derived from utm_id). */
1435
1476
  setJourneyId(id) {
@@ -1547,15 +1588,40 @@ var XeniaClient = class {
1547
1588
  return this.identity.getVisitorId() ?? this.identity.getDeviceId() ?? void 0;
1548
1589
  }
1549
1590
  /**
1550
- * Stamp the SDK-owned visitor id into the resolve `data` under the reserved
1551
- * `_xenia_vid` key so the backend can bucket holdout experiments and record
1552
- * exposure per visitor (it reads visitor identity from `data`). Set last so a
1553
- * caller can't override it; a no-op when no visitor id is resolvable yet.
1591
+ * Stamp the full set of SDK-provided fields into the resolve `data` —
1592
+ * `path`, `query`, `deviceId`, `visitorId`, `customerId`, `email`, `url`,
1593
+ * `referrer`, and the five `utm*` fields — the same field-name/type parity
1594
+ * the webhook trigger's "SDK-provided fields" already promises, now native
1595
+ * (always attached, no marketer toggle) for the Personalization Resolve
1596
+ * trigger too. Plus the reserved `_xenia_vid` key the backend reads for
1597
+ * holdout/exposure bucketing. All of these are spread LAST (after the
1598
+ * caller's own `data`) so none can be overridden per call — the same
1599
+ * override-protection guarantee `_xenia_vid` alone used to have, now
1600
+ * widened to the full set. A no-op (returns `opts` unchanged) when nothing
1601
+ * is resolvable yet (e.g. called before `init()` on a fresh visit with no
1602
+ * page context available).
1554
1603
  */
1555
1604
  withVisitor(opts) {
1605
+ const ctx = this.identity.collectContext();
1556
1606
  const vid = this.resolveVisitorId();
1557
- if (!vid) return opts;
1558
- return { ...opts, data: { ...opts?.data ?? {}, _xenia_vid: vid } };
1607
+ const sdkFields = compact({
1608
+ path: ctx.path,
1609
+ query: ctx.query,
1610
+ deviceId: this.identity.getDeviceId() ?? void 0,
1611
+ visitorId: vid,
1612
+ customerId: this.identity.getCustomerId() ?? void 0,
1613
+ email: this.identity.getEmail() ?? void 0,
1614
+ url: ctx.url,
1615
+ referrer: ctx.referrer,
1616
+ utmSource: ctx.utmSource,
1617
+ utmMedium: ctx.utmMedium,
1618
+ utmCampaign: ctx.utmCampaign,
1619
+ utmContent: ctx.utmContent,
1620
+ utmId: ctx.utmId
1621
+ });
1622
+ if (vid) sdkFields._xenia_vid = vid;
1623
+ if (Object.keys(sdkFields).length === 0) return opts;
1624
+ return { ...opts, data: { ...opts?.data ?? {}, ...sdkFields } };
1559
1625
  }
1560
1626
  dntBlocked() {
1561
1627
  if (this.options.respectDnt === false) return false;