@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,8 +1,8 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import * as react from 'react';
3
3
  import { ReactNode, ElementType, ComponentType } from 'react';
4
- import { t as XeniaClientOptions, s as XeniaClient, r as ResolveResult, p as ResolveBatchResult, J as JsonValue, W as WebhookResponse, R as ResolveBatchItem, e as AnalyticsEventName, T as TrackOptions, d as XeniaAction, I as InteractionType, m as MessageMountContext, c as MessageComponentRenderer } from '../../actions-DfuHrjUL.cjs';
5
- export { A as AnalyticsContext, f as AnalyticsIdentity, g as AnalyticsIngestResponse, C as ClientEvent, h as ConsentState, i as ContentSwap, j as IdentifyRequest, k as IdentifyResponse, M as MessageCta, n as MessagePlacement, o as MessageRenderContext, b as MessageTemplateFn, P as PersonalizationSwap, q as ResolveOptions, X as XeniaConfig, a as XeniaEvent, u as createXeniaClient, v as extractContentSwaps, w as parseActions, x as spliceSlots } from '../../actions-DfuHrjUL.cjs';
4
+ import { t as XeniaClientOptions, s as XeniaClient, r as ResolveResult, p as ResolveBatchResult, J as JsonValue, W as WebhookResponse, R as ResolveBatchItem, e as AnalyticsEventName, T as TrackOptions, d as XeniaAction, I as InteractionType, m as MessageMountContext, c as MessageComponentRenderer } from '../../actions-CkiSdvSa.cjs';
5
+ export { A as AnalyticsContext, f as AnalyticsIdentity, g as AnalyticsIngestResponse, C as ClientEvent, h as ConsentState, i as ContentSwap, j as IdentifyRequest, k as IdentifyResponse, M as MessageCta, n as MessagePlacement, o as MessageRenderContext, b as MessageTemplateFn, P as PersonalizationSwap, q as ResolveOptions, X as XeniaConfig, a as XeniaEvent, u as createXeniaClient, v as extractContentSwaps, w as parseActions, x as spliceSlots } from '../../actions-CkiSdvSa.cjs';
6
6
 
7
7
  interface XeniaProviderProps extends XeniaClientOptions {
8
8
  children: ReactNode;
@@ -19,7 +19,7 @@ interface XeniaProviderProps extends XeniaClientOptions {
19
19
  *
20
20
  * @example
21
21
  * ```tsx
22
- * <XeniaProvider baseUrl="/xenia" tenantId="t1" environmentKey="prod">
22
+ * <XeniaProvider tenantId="t1" environmentKey="prod">
23
23
  * <App />
24
24
  * </XeniaProvider>
25
25
  * ```
@@ -1,8 +1,8 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import * as react from 'react';
3
3
  import { ReactNode, ElementType, ComponentType } from 'react';
4
- import { t as XeniaClientOptions, s as XeniaClient, r as ResolveResult, p as ResolveBatchResult, J as JsonValue, W as WebhookResponse, R as ResolveBatchItem, e as AnalyticsEventName, T as TrackOptions, d as XeniaAction, I as InteractionType, m as MessageMountContext, c as MessageComponentRenderer } from '../../actions-DfuHrjUL.js';
5
- export { A as AnalyticsContext, f as AnalyticsIdentity, g as AnalyticsIngestResponse, C as ClientEvent, h as ConsentState, i as ContentSwap, j as IdentifyRequest, k as IdentifyResponse, M as MessageCta, n as MessagePlacement, o as MessageRenderContext, b as MessageTemplateFn, P as PersonalizationSwap, q as ResolveOptions, X as XeniaConfig, a as XeniaEvent, u as createXeniaClient, v as extractContentSwaps, w as parseActions, x as spliceSlots } from '../../actions-DfuHrjUL.js';
4
+ import { t as XeniaClientOptions, s as XeniaClient, r as ResolveResult, p as ResolveBatchResult, J as JsonValue, W as WebhookResponse, R as ResolveBatchItem, e as AnalyticsEventName, T as TrackOptions, d as XeniaAction, I as InteractionType, m as MessageMountContext, c as MessageComponentRenderer } from '../../actions-CkiSdvSa.js';
5
+ export { A as AnalyticsContext, f as AnalyticsIdentity, g as AnalyticsIngestResponse, C as ClientEvent, h as ConsentState, i as ContentSwap, j as IdentifyRequest, k as IdentifyResponse, M as MessageCta, n as MessagePlacement, o as MessageRenderContext, b as MessageTemplateFn, P as PersonalizationSwap, q as ResolveOptions, X as XeniaConfig, a as XeniaEvent, u as createXeniaClient, v as extractContentSwaps, w as parseActions, x as spliceSlots } from '../../actions-CkiSdvSa.js';
6
6
 
7
7
  interface XeniaProviderProps extends XeniaClientOptions {
8
8
  children: ReactNode;
@@ -19,7 +19,7 @@ interface XeniaProviderProps extends XeniaClientOptions {
19
19
  *
20
20
  * @example
21
21
  * ```tsx
22
- * <XeniaProvider baseUrl="/xenia" tenantId="t1" environmentKey="prod">
22
+ * <XeniaProvider tenantId="t1" environmentKey="prod">
23
23
  * <App />
24
24
  * </XeniaProvider>
25
25
  * ```
@@ -92,6 +92,7 @@ function parseActions(body) {
92
92
  }
93
93
 
94
94
  // src/core/http-client.ts
95
+ var DEFAULT_BASE_URL = "https://engine.xeniamartech.com/xenia";
95
96
  function isBrowser() {
96
97
  return typeof window !== "undefined" && typeof document !== "undefined";
97
98
  }
@@ -121,7 +122,7 @@ var HttpClient = class {
121
122
  retry;
122
123
  debug;
123
124
  constructor(opts) {
124
- this.baseUrl = opts.baseUrl.replace(/\/+$/, "");
125
+ this.baseUrl = (opts.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
125
126
  this.defaultHeaders = opts.defaultHeaders ?? {};
126
127
  this.timeout = opts.timeout ?? 8e3;
127
128
  this.retry = {
@@ -970,6 +971,40 @@ var Identity = class {
970
971
  return null;
971
972
  }
972
973
  }
974
+ // ── Customer id / email ──────────────────────────────────────────────────
975
+ //
976
+ // Ambient, persisted the same way as the visitor id, so a value set once
977
+ // (typically alongside `identify()`) rides on every later `resolve()` call
978
+ // without the caller having to pass it again — the SDK-provided-fields
979
+ // parity list on the Personalization Resolve trigger includes both.
980
+ setCustomerId(customerId) {
981
+ try {
982
+ if (customerId) localStorage.setItem(this.key("customer_id"), customerId);
983
+ else localStorage.removeItem(this.key("customer_id"));
984
+ } catch {
985
+ }
986
+ }
987
+ getCustomerId() {
988
+ try {
989
+ return localStorage.getItem(this.key("customer_id"));
990
+ } catch {
991
+ return null;
992
+ }
993
+ }
994
+ setEmail(email) {
995
+ try {
996
+ if (email) localStorage.setItem(this.key("email"), email);
997
+ else localStorage.removeItem(this.key("email"));
998
+ } catch {
999
+ }
1000
+ }
1001
+ getEmail() {
1002
+ try {
1003
+ return localStorage.getItem(this.key("email"));
1004
+ } catch {
1005
+ return null;
1006
+ }
1007
+ }
973
1008
  // ── Session id ───────────────────────────────────────────────────────────────
974
1009
  /**
975
1010
  * Resolve the current session id: reused while activity continues within
@@ -1433,10 +1468,16 @@ var XeniaClient = class {
1433
1468
  * Persist a visitor id, attached to every subsequent event, and bind it to
1434
1469
  * a known user server-side (`POST /api/events/v1/identify`, fire-and-
1435
1470
  * forget — resolves to an `"identify"` client event carrying `personId`).
1471
+ *
1472
+ * `extra.customerId`/`extra.email`, when supplied, are also persisted
1473
+ * ambiently (like the visitor id) so they ride on every later `resolve()`
1474
+ * call automatically — part of the SDK-provided-fields parity list.
1436
1475
  */
1437
- identify(visitorId) {
1476
+ identify(visitorId, extra) {
1438
1477
  this.identity.identify(visitorId);
1439
- void this.api.identify({ xeniaVisitorId: visitorId }).then((res) => this.emit("identify", res)).catch((err) => this.emitError(err));
1478
+ if (extra?.customerId !== void 0) this.identity.setCustomerId(extra.customerId);
1479
+ if (extra?.email !== void 0) this.identity.setEmail(extra.email);
1480
+ void this.api.identify({ xeniaVisitorId: visitorId, userId: extra?.customerId, email: extra?.email }).then((res) => this.emit("identify", res)).catch((err) => this.emitError(err));
1440
1481
  }
1441
1482
  /** Override the customer-journey UUID (else derived from utm_id). */
1442
1483
  setJourneyId(id) {
@@ -1554,15 +1595,40 @@ var XeniaClient = class {
1554
1595
  return this.identity.getVisitorId() ?? this.identity.getDeviceId() ?? void 0;
1555
1596
  }
1556
1597
  /**
1557
- * Stamp the SDK-owned visitor id into the resolve `data` under the reserved
1558
- * `_xenia_vid` key so the backend can bucket holdout experiments and record
1559
- * exposure per visitor (it reads visitor identity from `data`). Set last so a
1560
- * caller can't override it; a no-op when no visitor id is resolvable yet.
1598
+ * Stamp the full set of SDK-provided fields into the resolve `data` —
1599
+ * `path`, `query`, `deviceId`, `visitorId`, `customerId`, `email`, `url`,
1600
+ * `referrer`, and the five `utm*` fields — the same field-name/type parity
1601
+ * the webhook trigger's "SDK-provided fields" already promises, now native
1602
+ * (always attached, no marketer toggle) for the Personalization Resolve
1603
+ * trigger too. Plus the reserved `_xenia_vid` key the backend reads for
1604
+ * holdout/exposure bucketing. All of these are spread LAST (after the
1605
+ * caller's own `data`) so none can be overridden per call — the same
1606
+ * override-protection guarantee `_xenia_vid` alone used to have, now
1607
+ * widened to the full set. A no-op (returns `opts` unchanged) when nothing
1608
+ * is resolvable yet (e.g. called before `init()` on a fresh visit with no
1609
+ * page context available).
1561
1610
  */
1562
1611
  withVisitor(opts) {
1612
+ const ctx = this.identity.collectContext();
1563
1613
  const vid = this.resolveVisitorId();
1564
- if (!vid) return opts;
1565
- return { ...opts, data: { ...opts?.data ?? {}, _xenia_vid: vid } };
1614
+ const sdkFields = compact({
1615
+ path: ctx.path,
1616
+ query: ctx.query,
1617
+ deviceId: this.identity.getDeviceId() ?? void 0,
1618
+ visitorId: vid,
1619
+ customerId: this.identity.getCustomerId() ?? void 0,
1620
+ email: this.identity.getEmail() ?? void 0,
1621
+ url: ctx.url,
1622
+ referrer: ctx.referrer,
1623
+ utmSource: ctx.utmSource,
1624
+ utmMedium: ctx.utmMedium,
1625
+ utmCampaign: ctx.utmCampaign,
1626
+ utmContent: ctx.utmContent,
1627
+ utmId: ctx.utmId
1628
+ });
1629
+ if (vid) sdkFields._xenia_vid = vid;
1630
+ if (Object.keys(sdkFields).length === 0) return opts;
1631
+ return { ...opts, data: { ...opts?.data ?? {}, ...sdkFields } };
1566
1632
  }
1567
1633
  dntBlocked() {
1568
1634
  if (this.options.respectDnt === false) return false;