@syntrologie/adapt-chatbot 2.29.0 → 2.29.1

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.
@@ -5,10 +5,11 @@
5
5
  * `packages/runtime-sdk/src/overlays/fetcher.ts` for the sibling pattern
6
6
  * — no shared HTTP client, no axios, no fetch wrapper).
7
7
  *
8
- * Auth: forwards the SDK token from `window.__SYNTRO_CONFIG__.token`
9
- * as a Bearer header, plus the runtime's visitor ids (`X-Distinct-Id` /
10
- * `X-Syntro-Session`) so the backend rehydrates mounts under the same
11
- * session-keyed Redis state the chat persisted to.
8
+ * Auth: forwards the caller-supplied SDK token (from the runtime handle,
9
+ * the single source `Syntro.init` populates BUG-1785360157: never a
10
+ * window global) as a Bearer header, plus the runtime's visitor ids
11
+ * (`X-Distinct-Id` / `X-Syntro-Session`) so the backend rehydrates
12
+ * mounts under the same session-keyed Redis state the chat persisted to.
12
13
  *
13
14
  * 404 contract: the backend returns 404 only when the workspace's SDK
14
15
  * token doesn't resolve to a workspace. The SDK treats 404 as
@@ -22,7 +23,9 @@ export interface FetchMountedElementsOptions {
22
23
  * `/api/adaptive/mounted_elements`). Tests + multi-environment
23
24
  * deploys use this. */
24
25
  endpoint?: string;
25
- /** SDK token. Defaults to `window.__SYNTRO_CONFIG__.token`. */
26
+ /** SDK token from the runtime handle (`runtime.token`). Absent →
27
+ * unauthenticated request; the backend 401s and the caller's null
28
+ * contract kicks in. No window-global fallback (BUG-1785360157). */
26
29
  token?: string;
27
30
  /** Custom fetch implementation — used by tests to mock the network. */
28
31
  fetchImpl?: typeof fetch;
@@ -1 +1 @@
1
- {"version":3,"file":"fetcher.d.ts","sourceRoot":"","sources":["../../src/elements/fetcher.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AAIvD,MAAM,WAAW,2BAA2B;IAC1C;;4BAEwB;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,+DAA+D;IAC/D,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,uEAAuE;IACvE,SAAS,CAAC,EAAE,OAAO,KAAK,CAAC;IACzB,oDAAoD;IACpD,MAAM,CAAC,EAAE,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;CAChC;AAED;;;;;;GAMG;AACH,wBAAsB,oBAAoB,CACxC,OAAO,GAAE,2BAAgC,GACxC,OAAO,CAAC,uBAAuB,GAAG,IAAI,CAAC,CA2DzC"}
1
+ {"version":3,"file":"fetcher.d.ts","sourceRoot":"","sources":["../../src/elements/fetcher.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AAIvD,MAAM,WAAW,2BAA2B;IAC1C;;4BAEwB;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;yEAEqE;IACrE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,uEAAuE;IACvE,SAAS,CAAC,EAAE,OAAO,KAAK,CAAC;IACzB,oDAAoD;IACpD,MAAM,CAAC,EAAE,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;CAChC;AAED;;;;;;GAMG;AACH,wBAAsB,oBAAoB,CACxC,OAAO,GAAE,2BAAgC,GACxC,OAAO,CAAC,uBAAuB,GAAG,IAAI,CAAC,CA2DzC"}
package/dist/runtime.js CHANGED
@@ -9,7 +9,7 @@ import {
9
9
  decodeMutationEnvelope,
10
10
  fetchMountedElements,
11
11
  renderFallbackHtml
12
- } from "./chunk-ZXV4GXMO.js";
12
+ } from "./chunk-A3TIGA4G.js";
13
13
  import {
14
14
  pickPersona
15
15
  } from "./chunk-FXHYE6FY.js";
@@ -364,10 +364,8 @@ var chatSession = new ChatSession();
364
364
  // src/ChatTransport.ts
365
365
  var SESSION_READ_DEADLINE_MS = 6e4;
366
366
  var FALLBACK_DEBOUNCE_MS = 1500;
367
- function readSyntroToken() {
368
- if (typeof window === "undefined") return void 0;
369
- const cfg = window.__SYNTRO_CONFIG__;
370
- const token = cfg?.token;
367
+ function readRuntimeToken(runtime2) {
368
+ const token = runtime2?.token;
371
369
  return typeof token === "string" && token.length > 0 ? token : void 0;
372
370
  }
373
371
  function debug(...args) {
@@ -649,7 +647,7 @@ var ChatTransport = class {
649
647
  const baseUrl = this._config.backendUrl.replace(/\/$/, "");
650
648
  const url = `${baseUrl}/api/adaptive/session`;
651
649
  const headers = {};
652
- const token = readSyntroToken();
650
+ const token = readRuntimeToken(this._config?.runtime);
653
651
  if (token) headers.Authorization = `Bearer ${token}`;
654
652
  const cft = await this._acquireTurnstileWithChallenge();
655
653
  if (cft) headers["CF-Turnstile-Token"] = cft;
@@ -932,7 +930,7 @@ var ChatTransport = class {
932
930
  if (this._config === null) return false;
933
931
  const baseUrl = this._config.backendUrl.replace(/\/$/, "");
934
932
  const streamUrl = `${baseUrl}/api/adaptive/stream`;
935
- const token = readSyntroToken();
933
+ const token = readRuntimeToken(this._config?.runtime);
936
934
  const buildHeaders = () => {
937
935
  const h = {};
938
936
  if (token) h.Authorization = `Bearer ${token}`;
@@ -1814,7 +1812,7 @@ function hydrateOnce(runtime2, backendUrl) {
1814
1812
  const store = getOrCreateElementStore(runtime2);
1815
1813
  const trimmed = backendUrl.replace(/\/$/, "");
1816
1814
  const endpoint = trimmed ? `${trimmed}/api/adaptive/mounted_elements` : "/api/adaptive/mounted_elements";
1817
- fetchMountedElements({ endpoint }).then((response) => {
1815
+ fetchMountedElements({ endpoint, token: runtime2.token }).then((response) => {
1818
1816
  if (!response) return;
1819
1817
  void store.hydrate(response.mounted_elements);
1820
1818
  });
@@ -1866,7 +1864,7 @@ function wireNudgeSurface(runtime2, backendUrl) {
1866
1864
  const store = getOrCreateElementStore(runtime2);
1867
1865
  const trimmed = backendUrl.replace(/\/$/, "");
1868
1866
  const endpoint = trimmed ? `${trimmed}/api/adaptive/mounted_elements` : "/api/adaptive/mounted_elements";
1869
- void fetchMountedElements({ endpoint }).then((response) => {
1867
+ void fetchMountedElements({ endpoint, token: runtime2.token }).then((response) => {
1870
1868
  if (!response) return;
1871
1869
  void store.hydrate(response.mounted_elements);
1872
1870
  });
@@ -1905,7 +1903,7 @@ function configureTransportIfPossible(cfg) {
1905
1903
  const elementsActive = cfg.elementsEnabled === true && cfg.uiTemplates != null;
1906
1904
  refreshTemplateWidgetMap(elementsActive ? cfg.uiTemplates : void 0);
1907
1905
  const forwardedProps = elementsActive ? { elementsEnabled: true, uiTemplates: cfg.uiTemplates } : void 0;
1908
- if (elementsActive) publishTemplatesIfPossible(backendUrl, cfg.uiTemplates);
1906
+ if (elementsActive) publishTemplatesIfPossible(backendUrl, cfg.uiTemplates, cfg.runtime?.token);
1909
1907
  const runtime2 = cfg.runtime;
1910
1908
  const onElementMutation = elementsActive ? (mutations) => {
1911
1909
  void getOrCreateElementStore(runtime2).apply(mutations);
@@ -1929,12 +1927,10 @@ function configureTransportIfPossible(cfg) {
1929
1927
  startObserverIfPossible(cfg);
1930
1928
  }
1931
1929
  var _templatesPublished = false;
1932
- function publishTemplatesIfPossible(backendUrl, uiTemplates) {
1930
+ function publishTemplatesIfPossible(backendUrl, uiTemplates, token) {
1933
1931
  if (_templatesPublished || typeof window === "undefined") return;
1934
1932
  if (!uiTemplates || typeof uiTemplates !== "object") return;
1935
1933
  _templatesPublished = true;
1936
- const cfg = window.__SYNTRO_CONFIG__;
1937
- const token = typeof cfg?.token === "string" && cfg.token.length > 0 ? cfg.token : void 0;
1938
1934
  const headers = { "Content-Type": "application/json" };
1939
1935
  if (token) headers.Authorization = `Bearer ${token}`;
1940
1936
  const trimmed = backendUrl.replace(/\/$/, "");
@@ -1992,8 +1988,8 @@ function startObserverIfPossible(cfg) {
1992
1988
  const getDistinctId = () => runtimeId("getDistinctId");
1993
1989
  const getSessionId = () => runtimeId("getSessionId");
1994
1990
  const token = () => {
1995
- const c = window.__SYNTRO_CONFIG__;
1996
- return typeof c?.token === "string" ? c.token : "";
1991
+ const t = runtimeRef.token;
1992
+ return typeof t === "string" ? t : "";
1997
1993
  };
1998
1994
  const enrich = buildObserverEnrich(runtimeRef);
1999
1995
  const handle = startObserver({ url, token, getDistinctId, getSessionId, enrich });