@xenia-martech/sdk-js 1.0.0-dev.26 → 1.0.0-dev.28

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 (37) hide show
  1. package/CSS_VARIABLES.md +7 -0
  2. package/README.md +71 -2
  3. package/dist/{actions-DFLoSXO_.d.cts → actions-CcBYV--3.d.cts} +242 -6
  4. package/dist/{actions-DFLoSXO_.d.ts → actions-CcBYV--3.d.ts} +242 -6
  5. package/dist/{chunk-3KYKKIIG.cjs → chunk-WYM4CQVG.cjs} +126 -4
  6. package/dist/chunk-WYM4CQVG.cjs.map +1 -0
  7. package/dist/{chunk-D37RD3UC.js → chunk-XXNDHYAS.js} +125 -5
  8. package/dist/chunk-XXNDHYAS.js.map +1 -0
  9. package/dist/client/index.cjs +613 -35
  10. package/dist/client/index.cjs.map +1 -1
  11. package/dist/client/index.d.cts +112 -3
  12. package/dist/client/index.d.ts +112 -3
  13. package/dist/client/index.js +610 -36
  14. package/dist/client/index.js.map +1 -1
  15. package/dist/client/react/index.cjs +609 -35
  16. package/dist/client/react/index.cjs.map +1 -1
  17. package/dist/client/react/index.d.cts +2 -2
  18. package/dist/client/react/index.d.ts +2 -2
  19. package/dist/client/react/index.js +609 -35
  20. package/dist/client/react/index.js.map +1 -1
  21. package/dist/{cookie-names-LgNDAreS.d.cts → cookie-names-B3b0XNc2.d.cts} +187 -1
  22. package/dist/{cookie-names-LgNDAreS.d.ts → cookie-names-B3b0XNc2.d.ts} +187 -1
  23. package/dist/index.cjs +23 -19
  24. package/dist/index.d.cts +23 -3
  25. package/dist/index.d.ts +23 -3
  26. package/dist/index.js +1 -1
  27. package/dist/server/index.cjs +53 -22
  28. package/dist/server/index.cjs.map +1 -1
  29. package/dist/server/index.d.cts +31 -11
  30. package/dist/server/index.d.ts +31 -11
  31. package/dist/server/index.js +43 -12
  32. package/dist/server/index.js.map +1 -1
  33. package/dist/xenia-sdk.iife.js +37 -3
  34. package/dist/xenia-sdk.iife.js.map +1 -1
  35. package/package.json +1 -1
  36. package/dist/chunk-3KYKKIIG.cjs.map +0 -1
  37. package/dist/chunk-D37RD3UC.js.map +0 -1
package/CSS_VARIABLES.md CHANGED
@@ -105,6 +105,13 @@ declaring the variables on a narrower ancestor element instead of `:root`.
105
105
  | `--xenia-close-size` | `20px` | Close (`×`) glyph font size. |
106
106
  | `--xenia-close-color` | `#999` | Close (`×`) glyph color. |
107
107
 
108
+ ### Spin-wheel widget
109
+
110
+ | Variable | Default | Affects |
111
+ |---|---|---|
112
+ | `--xenia-cta-bg` / `--xenia-cta-color` / `--xenia-cta-radius` / `--xenia-cta-padding` / `--xenia-cta-size` | see [Call-to-action button](#call-to-action-button) | The wheel's "Spin" button — shares the same variables as the generic CTA button, so both stay visually consistent by default. |
113
+ | `--xenia-wheel-pointer-color` | `#111` | Color of the pointer triangle above the wheel and the center hub cap. |
114
+
108
115
  ## Notes
109
116
 
110
117
  - Variables only affect the SDK's **built-in** card markup. If you set `html` on an action, or
package/README.md CHANGED
@@ -502,6 +502,54 @@ function OfferCard({ action, close, fireCta }: XeniaMessageComponentProps) {
502
502
 
503
503
  Your component owns 100% of the card's markup and styling (same as a per-action `html` override) — the SDK still owns placement, z-index, and (for `modal`) the backdrop, so `--xenia-z-index`/`--xenia-popup-offset`/`--xenia-modal-backdrop`/etc. from [Theming with CSS variables](#theming-with-css-variables) still apply; the card-specific variables (`--xenia-card-*`, `--xenia-title-*`, `--xenia-cta-*`, …) don't, since there's no built-in card element to style.
504
504
 
505
+ ### Interactive widgets (spin-wheel)
506
+
507
+ An action can also carry `widgetType: "spin-wheel"` — a gamified outcome the server resolves (a discount code, a "try again"), rendered and submitted differently from a plain message action:
508
+
509
+ ```jsonc
510
+ {
511
+ "type": "popup",
512
+ "widgetType": "spin-wheel",
513
+ "segments": [
514
+ { "id": "s1", "label": "10% off", "colorHex": "#7c3aed" },
515
+ { "id": "s2", "label": "Try again", "colorHex": "#2563eb", "isLoss": true }
516
+ ],
517
+ "formSubmit": { "requiresResolve": true, "mode": "journey", "bindingRef": "wsb_abc123" },
518
+ "spinnerHtml": "<div class=\"wheel-screen\">…</div>",
519
+ "winHtml": "<div class=\"win-screen\">…</div>",
520
+ "lossHtml": "<div class=\"loss-screen\">…</div>"
521
+ }
522
+ ```
523
+
524
+ `segments` is label/color/`isLoss` **only** — the real prize weighting and any prize code are marketer-configured server-side on the webhook-response node and never reach the browser. `formSubmit` is likewise entirely server-driven: `requiresResolve: true` means the widget must call the server and get back a resolved segment before showing any outcome — there is never a client-guessed or optimistic result.
525
+
526
+ **Authoring the three screens.** `spinnerHtml`/`winHtml`/`lossHtml` are full marketer/AI-authored HTML, exactly like a popup's `html` override — there's no generated fallback design, so your markup **is** the widget. The SDK only needs a few `data-xenia-*` hooks inside it to wire behavior:
527
+
528
+ | Attribute | Goes in | Effect |
529
+ |---|---|---|
530
+ | `data-xenia-wheel-slot` | `spinnerHtml` | Where the SDK mounts its generated SVG wheel + pointer. |
531
+ | `data-xenia-spin` | `spinnerHtml` | Click starts the spin — calls `submitWidgetForm()`, waits for the server-resolved segment, then animates the wheel to land on it. |
532
+ | `data-xenia-wheel-prize` | `winHtml` / `lossHtml` (either or both) | Filled with the resolved segment's `label` once known. A losing segment still has a label (e.g. "Try again"), so this works on the loss screen too. |
533
+ | `data-xenia-wheel-cta` | `winHtml` / `lossHtml` | Click fires the action's `cta.event`/`cta.url` (same as a message action's CTA) before dismissing. |
534
+ | `data-xenia-spin-again` | `winHtml` / `lossHtml` | Optional "try again" button — swaps back to `spinnerHtml` and re-arms the spin button. Hidden automatically once the server reports no plays remain (`alreadyPlayed`). This never grants another spin by itself — the server's own play-limit/win-lock decides what the next `data-xenia-spin` click actually resolves to. |
535
+ | `data-xenia-close`, or any element whose class/id contains "close"/"backdrop" | any of the three | Dismisses the widget — the same close-affordance convention every custom-HTML surface in the SDK honors, so a design pasted from elsewhere (e.g. an inline `onclick`) still closes correctly. |
536
+ | `data-xenia-field="<name>"` / `data-xenia-submit` | `spinnerHtml`, or any widget's markup | The shared field-capture convention (see below) — wrap real inputs in a `<form>` for free Enter-to-submit, or mark a plain click trigger with `data-xenia-submit`. |
537
+
538
+ If a click on `data-xenia-spin`/`data-xenia-submit` fires before the widget has a configured `formSubmit` (the marketer hasn't wired the webhook-response node's Form-submission panel yet), the SDK shows an inert `data-xenia-error` message instead of silently doing nothing or reloading the page.
539
+
540
+ **Replays.** A visitor who already played sees the same resolved outcome again rather than a fresh roll — `WidgetSubmitResponse.alreadyPlayed` is `true` in that case, and the wheel skips its spin animation and jumps straight to the reveal (there's nothing new to animate toward).
541
+
542
+ **The shared field/submit/success convention** (`collectFields`/`wireFormSubmit`, also used by plain `standard` popups with a capturable form) applies inside widget HTML too:
543
+
544
+ - Mark real inputs `data-xenia-field="<name>"`; the submit trigger is `data-xenia-submit` (a `<form>` wrapper is optional — the SDK intercepts its native `submit` either way).
545
+ - The submit control grows a small built-in spinner while the request is in flight (no markup needed for this).
546
+ - On success, if you authored a `<div data-xenia-success hidden>…</div>` block anywhere in the HTML, it's revealed in place of the form for at least `formSubmit.successDisplayMs` (default 900ms — long enough for a visitor to register it worked, since the real round-trip is often under 100ms) before the widget dismisses itself. No success block just means a plain wait-then-dismiss.
547
+ - On error, the spinner clears, the control re-enables, and `data-xenia-error` shows a retry message.
548
+
549
+ **Per-widget style overrides** — `style: { hideCloseButton?, hideOverlay? }` — control the SDK's own chrome around the widget (not authored content). `hideCloseButton` isn't currently exposed in Content Studio's AI schema or read by any renderer yet; `hideOverlay` suppresses the dimmed backdrop, default shown.
550
+
551
+ See [Theming with CSS variables](#theming-with-css-variables) for the wheel's own variables (`--xenia-wheel-pointer-color`, plus the shared `--xenia-cta-*` set for the Spin button).
552
+
505
553
  ---
506
554
 
507
555
  ## Theming with CSS variables
@@ -535,7 +583,27 @@ Each entry in `swaps` is `{ identifier, replacementEntryId, mode }` — `identif
535
583
 
536
584
  **Auth:** resolve **requires** the SDK Bearer token — the *same* `token` / `getToken` config as events (there is no separate personalization token). Events *optionally* send it (public otherwise); resolve *requires* it (401 without). Set it server-side; a browser without a token can still `track()` publicly but cannot `resolve()`.
537
585
 
538
- **Visitor id is attached automatically.** The SDK-owned visitor id (see [Analytics](#analytics--conversions)) is injected into the resolve `data` as `_xenia_vid`, so the backend can bucket holdout experiments and record per-visitor exposure — you don't add it yourself, and it can't be overridden per call. The webhook path (`request()` / `usePersonalization()`) carries the same id on the `/flow` body. Browser: resolved from `identify()`/device id; server: from `config.visitorId` (bind the `xenia_vid` cookie per request).
586
+ **SDK-provided fields are attached automatically.** Every `resolve()`/`resolveBatch()` call carries a fixed set of fields into `data` — `path`, `query`, `deviceId`, `visitorId`, `customerId`, `email`, `url`, `referrer`, `utmSource`, `utmMedium`, `utmCampaign`, `utmContent`, `utmId` — plus the reserved `_xenia_vid` key the backend reads for holdout/exposure bucketing. These are the same "SDK-provided fields" a Personalization Resolve journey trigger exposes natively to downstream nodes. None of them can be overridden per call — the SDK's own values always win, even if your `data` happens to use one of these names.
587
+
588
+ - **Browser:** collected ambiently — page URL/path/query/referrer/UTMs come from `window`/`document`; `visitorId`/`deviceId` from `identify()`/the auto-resolved device id; `customerId`/`email` from `identify(visitorId, { customerId, email })`. Nothing to configure.
589
+ - **Server:** there's no ambient `window`/`document`, so bind the request **once** when you construct the per-request client and every call carries the fields automatically — no per-call wiring:
590
+
591
+ ```ts
592
+ import { createXeniaServer } from "@xenia-martech/sdk-js/server";
593
+ import { contextFromUrl } from "@xenia-martech/sdk-js";
594
+
595
+ const xenia = createXeniaServer({
596
+ tenantId, environmentKey, token,
597
+ visitorId: getVisitorId(cookieHeader), // the browser's xenia_vid cookie
598
+ context: contextFromUrl(currentUrl, referrer), // path / query / url / referrer / utm*
599
+ });
600
+
601
+ await xenia.resolve("hero"); // ← fields already attached
602
+ ```
603
+
604
+ `contextFromUrl(url, referrer?)` derives the same fields the browser reads off `window.location`, so a rule can gate on `query.<name>` or `path` on a server-rendered page. In a framework where the render context can't see its own URL (e.g. a Next.js RSC), stamp the URL onto the request in middleware and read it back from `headers()` — see the `nextjs` example.
605
+
606
+ `opts.context`/`opts.identity` remain available per call, as an override on top of the ambient context or for values known only at that call site (e.g. `identity: { customerId: "c1", email: "a@b.com" }`). `visitorId`/`_xenia_vid` still come from `config.visitorId` and win over a per-call `identity.visitorId`. A client with neither bound behaves exactly as before.
539
607
 
540
608
  ```tsx
541
609
  import { usePersonalizationResolve } from "@xenia-martech/sdk-js/client/react";
@@ -821,6 +889,7 @@ Never block the page on this — render `baseHero` immediately and swap in the p
821
889
  - `resolve(contentKey, opts?: ResolveOptions)` → `ResolveResult` · `resolveBatch(items, opts?)` → `ResolveBatchResult[]` — REST personalization (requires the SDK token)
822
890
  - `identify(visitorId)` · `setJourneyId(id)` · `consent(state)`
823
891
  - `request(triggerId, data?, { apply?, method? })` → `WebhookResponse`
892
+ - `submitWidgetForm(formSubmit, fields, opts?: { idempotencyKey?, apply? })` → `WidgetSubmitResponse` — submits a widget's captured fields (spin-wheel resolve, or a plain custom-widget form submit); see [Interactive widgets](#interactive-widgets-spin-wheel)
824
893
  - `getResponse(key)` → `WebhookResponse | undefined`
825
894
  - `swapContent(target, {html?|text?})` · `hideContent(target)` · `showContent(target)` · `applyActions(actions)`
826
895
  - `on(event, cb)` — `"event" | "response" | "actions" | "error" | "identify"`
@@ -879,7 +948,7 @@ Never block the page on this — render `baseHero` immediately and swap in the p
879
948
  - `parseActions(body)`, `generateUlid()`, `toEventId(raw)`, `MAX_EVENT_ID_LENGTH`, `spliceSlots(slots, swaps)`, `extractContentSwaps(body)`, `VISITOR_COOKIE`, `CONSENT_COOKIE`.
880
949
  - `HttpClient`, `HttpError`, `buildUrl(base, path)`, `isBrowser()` — the underlying HTTP layer; `isBrowser()` is handy for guarding SSR-unsafe code in your own app.
881
950
  - `MemoryResponseStore`, `LocalStorageResponseStore` (implementations of the `ResponseStore` interface).
882
- - All types (`XeniaConfig`, `VisitorCookieOptions`, `XeniaEvent`, `TrackOptions`, `WebhookResponse`, `XeniaAction`, `MessagePosition`, `AnalyticsEventName`, `AnalyticsIngestResponse`, `AnalyticsContext`, `ResolveResult`, `ResolveBatchResult`, `PersonalizationSwap`, `ContentSwap`, …).
951
+ - All types (`XeniaConfig`, `VisitorCookieOptions`, `XeniaEvent`, `TrackOptions`, `WebhookResponse`, `XeniaAction`, `MessagePosition`, `AnalyticsEventName`, `AnalyticsIngestResponse`, `AnalyticsContext`, `ResolveResult`, `ResolveBatchResult`, `PersonalizationSwap`, `ContentSwap`, `WidgetType`, `WidgetSegment`, `WidgetFormSubmit`, `WidgetStyle`, `WidgetPrize`, `WidgetSubmitResponse`, …).
883
952
 
884
953
  </details>
885
954
 
@@ -80,6 +80,23 @@ interface XeniaConfig {
80
80
  * cookie read via `getVisitorId()`.
81
81
  */
82
82
  visitorId?: string;
83
+ /**
84
+ * The ambient request context for a **server** client — the SDK-provided page/campaign fields
85
+ * (`path`, `query`, `url`, `referrer`, `utmSource`/`utmMedium`/`utmCampaign`/`utmContent`/`utmId`)
86
+ * that get attached to EVERY `resolve()`/`resolveBatch()`/`webhook()` made with this client, so
87
+ * journey rules can gate on `query.<name>` or `path` without any per-call wiring.
88
+ *
89
+ * The browser client needs nothing here — it reads these off `window.location` itself. A server
90
+ * runtime has no ambient request, so bind it once when constructing the per-request client:
91
+ *
92
+ * ```ts
93
+ * createXeniaServer({ …, context: contextFromUrl(currentUrl, referrer) })
94
+ * ```
95
+ *
96
+ * Lowest precedence: a per-call `context`/`identity` overrides it, and the SDK-owned `visitorId`
97
+ * still wins over everything.
98
+ */
99
+ context?: EventContext;
83
100
  /**
84
101
  * Persist the SDK visitor id to a first-party `xenia_vid` cookie so your
85
102
  * **same-origin** server can read it (`getVisitorId(cookieHeader)`) and bind
@@ -115,6 +132,13 @@ interface VisitorCookieOptions {
115
132
  /** Cookie lifetime in days. Default 365. */
116
133
  maxAgeDays?: number;
117
134
  }
135
+ /** Well-known event fields understood by the backend event-trigger node. */
136
+ interface EventIdentity {
137
+ deviceId?: string;
138
+ visitorId?: string;
139
+ customerId?: string;
140
+ email?: string;
141
+ }
118
142
  /** UTM + page context captured automatically by the client. */
119
143
  interface EventContext {
120
144
  utmSource?: string;
@@ -291,6 +315,23 @@ interface ResolveOptions {
291
315
  locale?: string;
292
316
  /** When true, ask the server to splice and return `content`. */
293
317
  merge?: boolean;
318
+ /**
319
+ * Caller-supplied identity fields (`deviceId`/`visitorId`/`customerId`/
320
+ * `email`), merged into `data` the same way `ServerWebhookOptions.identity`
321
+ * is merged for `webhook()`. Only relevant server-side — the browser client
322
+ * collects these ambiently instead and ignores this field. The SDK-owned
323
+ * `visitorId` (from `config.visitorId`) still wins over a value supplied
324
+ * here, same precedence as `webhook()`.
325
+ */
326
+ identity?: EventIdentity;
327
+ /**
328
+ * Caller-supplied page context (`path`/`query`/`url`/`referrer`/`utm*`),
329
+ * merged into `data` the same way `ServerWebhookOptions.context` is merged
330
+ * for `webhook()`. There's no ambient `window`/`document` server-side, so a
331
+ * server caller who wants these SDK-provided fields on a resolve() call
332
+ * must pass them explicitly (e.g. from the current request's headers).
333
+ */
334
+ context?: EventContext;
294
335
  }
295
336
  /** Body posted to `POST /api/events/v1/identify` — binds visitor to a known user. */
296
337
  interface IdentifyRequest {
@@ -334,6 +375,109 @@ interface MessageCta {
334
375
  /** Optional event fired when the CTA is clicked. */
335
376
  event?: string;
336
377
  }
378
+ /**
379
+ * Widget-specific rendering/interaction behavior for a message-placement action —
380
+ * ORTHOGONAL to `type` (the existing `banner|popup|modal|inline` placement enum, which
381
+ * stays exactly as-is). `type` says WHERE it renders; `widgetType` says WHAT it is.
382
+ * Keeping these separate is what lets `core/actions.ts`'s `MESSAGE_TYPES` allowlist AND
383
+ * the PHP SDK's `XeniaActions::KNOWN_TYPES` allowlist (same value set) stay completely
384
+ * unchanged — the PHP SDK needs zero code changes for widget support.
385
+ *
386
+ * `"standard"` (or omitted) is a plain message/popup — the existing card path, unmodified.
387
+ * A future 3rd widget type is one new literal here + one new dispatch-table entry in
388
+ * `client/widgets/index.ts`, not a rewrite.
389
+ */
390
+ type WidgetType = "standard" | "spin-wheel";
391
+ /**
392
+ * A prize/outcome segment shown to the visitor for a spin-wheel widget — label/color ONLY.
393
+ * Real weight/prize-code are marketer-authored server-side config (`config.widgetSubmissions`)
394
+ * and never leave the backend; they never appear here.
395
+ */
396
+ interface WidgetSegment {
397
+ id: string;
398
+ label: string;
399
+ colorHex?: string;
400
+ /** Marks this segment as a non-winning outcome (e.g. "Try Again") — drives which of the
401
+ * win/loss reveal screens (see WidgetStyle) the widget shows once this segment resolves. */
402
+ isLoss?: boolean;
403
+ }
404
+ /**
405
+ * The SAFE runtime envelope describing how a widget's captured form submission is
406
+ * dispatched — never a credential, never a prize weight/code (see the cross-repo
407
+ * contract). The SDK does not branch on `mode`'s value itself; it only follows whichever
408
+ * ref field is present (`flowRef` vs `bindingRef`) to pick an endpoint — `mode`/`ref` are
409
+ * otherwise relayed to the backend verbatim, uninterpreted.
410
+ */
411
+ interface WidgetFormSubmit {
412
+ /** `true` for spin-wheel (server must resolve an outcome before anything renders). */
413
+ requiresResolve: boolean;
414
+ /** `"journey"` or `"endpoint"` — informational only; the SDK never branches on this value. */
415
+ mode: "journey" | "endpoint" | (string & {});
416
+ /** Present only when `mode === "journey" && !requiresResolve` — the direct `/flow` fast path, no secret. */
417
+ flowRef?: string;
418
+ /** Present whenever `requiresResolve || mode === "endpoint"`. */
419
+ bindingRef?: string;
420
+ /**
421
+ * Minimum time (ms) to keep the success state visible after a submit resolves, before the
422
+ * card dismisses itself — configured marketer-side on the webhook-response node's
423
+ * Form-submission panel. The real dispatch typically responds in well under 100ms, which
424
+ * would otherwise make the card vanish before a visitor registers it succeeded at all.
425
+ * Defaults to 900 when absent (an older/unconfigured binding).
426
+ */
427
+ successDisplayMs?: number;
428
+ }
429
+ /**
430
+ * Per-action visual overrides for a widget's own window chrome (spin-wheel).
431
+ * Deliberately narrow — everything about the widget's actual CONTENT (spinner/win/loss screens)
432
+ * is full marketer/AI-authored HTML (`spinnerHtml`/`winHtml`/`lossHtml` on `XeniaAction`, same
433
+ * pattern as a popup's `body`), not a field here. This only covers the two things that live
434
+ * OUTSIDE that HTML, in the SDK's own generated chrome around it.
435
+ */
436
+ interface WidgetStyle {
437
+ /**
438
+ * Hides the built-in close (×) button. No spin-wheel renderer draws one of its own anymore
439
+ * (see `spin-wheel.ts`'s `html()`) — every screen's own `spinnerHtml`/`winHtml`/`lossHtml`
440
+ * carries its own close affordance, matched by the same heuristic every custom-HTML surface
441
+ * honors (`wireCloseAffordances`). Currently vestigial: not exposed in Content Studio's AI
442
+ * schema, and not read by any widget renderer's `html()`.
443
+ */
444
+ hideCloseButton?: boolean;
445
+ /** Hides the dimmed backdrop behind the modal/popup/banner. Defaults to shown. */
446
+ hideOverlay?: boolean;
447
+ }
448
+ /**
449
+ * Server-resolved outcome for a spin-wheel submission
450
+ * (`XeniaClient.submitWidgetForm`'s response). Absent for a plain form submit.
451
+ * `segmentId` matches an `id` in the action's `segments` list. Never the whole prize
452
+ * config (weight/internal code) — only what the backend decides is safe to reveal.
453
+ */
454
+ interface WidgetPrize {
455
+ segmentId?: string;
456
+ label?: string;
457
+ colorHex?: string;
458
+ [key: string]: JsonValue | undefined;
459
+ }
460
+ /**
461
+ * Response from a widget form submission (`XeniaClient.submitWidgetForm`) — whichever
462
+ * endpoint was actually hit (the `/flow` fast path or `/widget-submissions`), normalized
463
+ * to one shape. `actions` flows through the existing `parseActions()`/`ActionRenderer.apply()`
464
+ * pipeline unchanged; `prize` is read directly by the spin-wheel widget module to drive
465
+ * its reveal.
466
+ */
467
+ interface WidgetSubmitResponse {
468
+ status: number;
469
+ body: JsonValue;
470
+ actions: XeniaAction[];
471
+ prize?: WidgetPrize;
472
+ /** True when this visitor already played and the stored result is being replayed, not re-rolled. */
473
+ alreadyPlayed?: boolean;
474
+ /** Whether the configured dispatch (journey invoke / outbound endpoint call) actually fired. */
475
+ dispatched?: boolean;
476
+ /** Present when `dispatched` is false and the server attempted but failed the configured dispatch. */
477
+ dispatchError?: string;
478
+ widgetType?: WidgetType;
479
+ receivedAt: number;
480
+ }
337
481
  /**
338
482
  * A render directive the SDK executes in the browser. Marketers emit these in
339
483
  * a `webhook-response` node body under the `xeniaActions` key.
@@ -369,6 +513,43 @@ type XeniaAction = {
369
513
  /** Anchor within the placement (see {@link MessagePosition}). Defaults to the
370
514
  * SDK's built-in default per type (popup: bottom-right; banner: bottom). */
371
515
  position?: MessagePosition;
516
+ /** Orthogonal widget-behavior driver — see {@link WidgetType}. Omitted/`"standard"` renders
517
+ * exactly like today. */
518
+ widgetType?: WidgetType;
519
+ /** Label/color-only outcome segments for `spin-wheel` widgets. */
520
+ segments?: WidgetSegment[];
521
+ /** Safe form-submission envelope — see {@link WidgetFormSubmit}. Absent when the action has
522
+ * no capturable outcome. */
523
+ formSubmit?: WidgetFormSubmit;
524
+ /** Per-action visual overrides for the widget's own window — see {@link WidgetStyle}. */
525
+ style?: WidgetStyle;
526
+ /**
527
+ * Full marketer/AI-authored HTML for `spin-wheel`'s pre-spin face (title/subtitle/spin
528
+ * button/background — the whole visual design) — independent of the generic `html` field
529
+ * above, which spin-wheel never reads. The primary, ordinary way this screen
530
+ * is authored (same role `body` plays for a popup) — there is no separate generated
531
+ * template to fall back to. To keep the wheel and spin button working, include an element
532
+ * carrying `data-xenia-wheel-slot` (the SDK mounts the generated SVG wheel + pointer
533
+ * there) and one carrying `data-xenia-spin` (the SDK wires the spin click there) —
534
+ * omitting either simply drops that capability, same as any other custom-HTML widget.
535
+ */
536
+ spinnerHtml?: string;
537
+ /**
538
+ * Full marketer/AI-authored HTML for the win-reveal screen (`spin-wheel`), shown once a
539
+ * spin resolves to a non-`isLoss` segment — the primary way this screen is authored,
540
+ * same role as {@link spinnerHtml}. Include `data-xenia-wheel-prize` on any element to
541
+ * receive the resolved prize label, and `data-xenia-wheel-cta` on a button to wire its
542
+ * click to dismiss (same close-affordance heuristics as any other custom-HTML widget also
543
+ * apply here — see `wireCloseAffordances`).
544
+ */
545
+ winHtml?: string;
546
+ /**
547
+ * Full marketer/AI-authored HTML for the loss/"try again" screen, shown once a
548
+ * spin resolves to a segment with {@link WidgetSegment.isLoss} set. Same hooks and
549
+ * same primary-authoring role as {@link winHtml} (a losing outcome still has a `label`,
550
+ * e.g. "Try Again", so `data-xenia-wheel-prize` is still honored here).
551
+ */
552
+ lossHtml?: string;
372
553
  } | {
373
554
  type: "redirect";
374
555
  url: string;
@@ -455,6 +636,18 @@ declare class XeniaApi {
455
636
  * duplicate the journey run.
456
637
  */
457
638
  webhook(triggerId: string, data?: JsonValue, method?: "GET" | "POST"): Promise<WebhookResponse>;
639
+ /**
640
+ * Widget form submission — `POST /widget-submissions?ref={bindingRef}`. Used whenever the
641
+ * action's `formSubmit.requiresResolve` is true (spin-wheel, which must have a
642
+ * server-resolved outcome before anything renders) or `mode === "endpoint"` — the common
643
+ * plain-popup case (`mode === "journey" && !requiresResolve`) bypasses this entirely and calls
644
+ * {@link webhook} against `flowRef` instead (see `XeniaClient.submitWidgetForm`'s endpoint
645
+ * selection).
646
+ *
647
+ * Not retried (`noRetry: true`), styled like {@link webhook} — a retried POST must never
648
+ * double-fire a journey or double-resolve a prize server-side.
649
+ */
650
+ submitWidget(ref: string, body?: JsonValue): Promise<WidgetSubmitResponse>;
458
651
  /**
459
652
  * Unified event batch (max 100/request per the backend) — `POST /api/events/v1`.
460
653
  * Records analytics for every event and matches/advances a journey for any
@@ -543,6 +736,10 @@ declare class Identity {
543
736
  /** Persist a visitor id so it rides on every future event. */
544
737
  identify(visitorId: string): void;
545
738
  getVisitorId(): string | null;
739
+ setCustomerId(customerId: string | null): void;
740
+ getCustomerId(): string | null;
741
+ setEmail(email: string | null): void;
742
+ getEmail(): string | null;
546
743
  /**
547
744
  * Resolve the current session id: reused while activity continues within
548
745
  * {@link SESSION_TIMEOUT_MS}, otherwise a new one is minted. Persisted in
@@ -628,8 +825,15 @@ declare class XeniaClient {
628
825
  * Persist a visitor id, attached to every subsequent event, and bind it to
629
826
  * a known user server-side (`POST /api/events/v1/identify`, fire-and-
630
827
  * forget — resolves to an `"identify"` client event carrying `personId`).
828
+ *
829
+ * `extra.customerId`/`extra.email`, when supplied, are also persisted
830
+ * ambiently (like the visitor id) so they ride on every later `resolve()`
831
+ * call automatically — part of the SDK-provided-fields parity list.
631
832
  */
632
- identify(visitorId: string): void;
833
+ identify(visitorId: string, extra?: {
834
+ customerId?: string;
835
+ email?: string;
836
+ }): void;
633
837
  /** Override the customer-journey UUID (else derived from utm_id). */
634
838
  setJourneyId(id: string | null): void;
635
839
  /**
@@ -675,10 +879,18 @@ declare class XeniaClient {
675
879
  /** The SDK-owned visitor anchor: the `identify()`/`config.visitorId` id, else the device id. */
676
880
  private resolveVisitorId;
677
881
  /**
678
- * Stamp the SDK-owned visitor id into the resolve `data` under the reserved
679
- * `_xenia_vid` key so the backend can bucket holdout experiments and record
680
- * exposure per visitor (it reads visitor identity from `data`). Set last so a
681
- * caller can't override it; a no-op when no visitor id is resolvable yet.
882
+ * Stamp the full set of SDK-provided fields into the resolve `data` —
883
+ * `path`, `query`, `deviceId`, `visitorId`, `customerId`, `email`, `url`,
884
+ * `referrer`, and the five `utm*` fields — the same field-name/type parity
885
+ * the webhook trigger's "SDK-provided fields" already promises, now native
886
+ * (always attached, no marketer toggle) for the Personalization Resolve
887
+ * trigger too. Plus the reserved `_xenia_vid` key the backend reads for
888
+ * holdout/exposure bucketing. All of these are spread LAST (after the
889
+ * caller's own `data`) so none can be overridden per call — the same
890
+ * override-protection guarantee `_xenia_vid` alone used to have, now
891
+ * widened to the full set. A no-op (returns `opts` unchanged) when nothing
892
+ * is resolvable yet (e.g. called before `init()` on a fresh visit with no
893
+ * page context available).
682
894
  */
683
895
  private withVisitor;
684
896
  private dntBlocked;
@@ -694,6 +906,30 @@ declare class XeniaClient {
694
906
  }): Promise<WebhookResponse>;
695
907
  /** Read the last saved webhook response for a key (triggerId/eventId). */
696
908
  getResponse(key: string): WebhookResponse | undefined;
909
+ /**
910
+ * Submit a widget's captured form values (standard/custom popup submit, or a spin-wheel/
911
+ * spin-wheel's resolve request) and apply any returned `xeniaActions`, exactly like
912
+ * {@link request}.
913
+ *
914
+ * **Endpoint selection is config-driven, not SDK-decided** (per the cross-repo contract): a
915
+ * `flowRef` (present only when `mode === "journey" && !requiresResolve` — the common
916
+ * plain-popup case) bypasses the resolve endpoint entirely and POSTs straight to the existing
917
+ * public `/flow` fast path; otherwise this POSTs to `/widget-submissions` via `bindingRef`. The
918
+ * SDK is agnostic to *why* — it just follows whichever ref field the backend populated.
919
+ *
920
+ * The full ambient-context parity list {@link request}/`withVisitor()` already build
921
+ * (visitorId, deviceId, url, referrer, path, query, `utm*`) rides on every call, plus `fields`
922
+ * and `submit.mode`/the resolved ref, relayed verbatim/uninterpreted — the SDK never branches
923
+ * on `mode`'s value itself, that's server-side.
924
+ *
925
+ * `opts.idempotencyKey` defaults to a freshly generated ULID; pass the SAME key back in on a
926
+ * retried submit of the same interaction so a network retry can't double-fire a journey or
927
+ * double-resolve a prize server-side.
928
+ */
929
+ submitWidgetForm(submit: WidgetFormSubmit, fields: Record<string, string>, opts?: {
930
+ idempotencyKey?: string;
931
+ apply?: boolean;
932
+ }): Promise<WidgetSubmitResponse>;
697
933
  swapContent(target: string, content: {
698
934
  html?: string;
699
935
  text?: string;
@@ -748,4 +984,4 @@ declare function extractContentSwaps(body: JsonValue): ContentSwap[] | undefined
748
984
  */
749
985
  declare function parseActions(body: JsonValue): XeniaAction[];
750
986
 
751
- export { type AnalyticsContext as A, type ClientEvent as C, type InteractionType as I, type JsonValue as J, type MessageCta as M, type PersonalizationSwap as P, type ResolveBatchItem as R, type TrackOptions as T, type WebhookResponse as W, type XeniaConfig as X, type XeniaEvent as a, type MessageTemplateFn as b, type MessageComponentRenderer as c, type XeniaAction as d, type AnalyticsEventName as e, type AnalyticsIdentity as f, type AnalyticsIngestResponse as g, type ConsentState as h, type ContentSwap as i, type IdentifyRequest as j, type IdentifyResponse as k, Identity as l, type MessageMountContext as m, type MessagePlacement as n, type MessageRenderContext as o, type ResolveBatchResult as p, type ResolveOptions as q, type ResolveResult as r, XeniaClient as s, type XeniaClientOptions as t, createXeniaClient as u, extractContentSwaps as v, parseActions as w, spliceSlots as x };
987
+ export { type AnalyticsContext as A, extractContentSwaps as B, type ClientEvent as C, parseActions as D, spliceSlots as E, type InteractionType as I, type JsonValue as J, type MessageCta as M, type PersonalizationSwap as P, type ResolveBatchItem as R, type TrackOptions as T, type WidgetFormSubmit as W, type XeniaConfig as X, type XeniaEvent as a, type MessageTemplateFn as b, type MessageComponentRenderer as c, type WidgetSubmitResponse as d, type XeniaAction as e, type MessagePlacement as f, type AnalyticsEventName as g, type AnalyticsIdentity as h, type AnalyticsIngestResponse as i, type ConsentState as j, type ContentSwap as k, type IdentifyRequest as l, type IdentifyResponse as m, Identity as n, type MessageMountContext as o, type MessageRenderContext as p, type ResolveBatchResult as q, type ResolveOptions as r, type ResolveResult as s, type WebhookResponse as t, type WidgetPrize as u, type WidgetSegment as v, type WidgetType as w, XeniaClient as x, type XeniaClientOptions as y, createXeniaClient as z };