@base44-preview/sdk 0.8.32-pr.185.2dc1fa1 → 0.8.32-pr.198.9e03952

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.
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Returns a stable per-browser identifier for an unauthenticated ("anonymous")
3
+ * visitor, creating and persisting one on first use.
4
+ *
5
+ * Sent as the `X-Base44-Anonymous-Id` header on unauthenticated requests so the
6
+ * backend can group an anonymous user's agent conversations and enforce
7
+ * ownership (the header is treated as a bearer-style credential). Persisted in
8
+ * localStorage so it survives reloads; a new browser/device or cleared storage
9
+ * starts a fresh anonymous identity.
10
+ *
11
+ * Returns `null` outside the browser (no `localStorage` / SSR) so callers can
12
+ * skip the header on the server.
13
+ *
14
+ * @internal
15
+ */
16
+ export declare function getOrCreateAnonymousVisitorId(): string | null;
@@ -0,0 +1,39 @@
1
+ import { v4 as uuidv4 } from "uuid";
2
+ /**
3
+ * localStorage key holding the anonymous visitor id.
4
+ * @internal
5
+ */
6
+ const ANONYMOUS_VISITOR_ID_STORAGE_KEY = "base44_anonymous_visitor_id";
7
+ /**
8
+ * Returns a stable per-browser identifier for an unauthenticated ("anonymous")
9
+ * visitor, creating and persisting one on first use.
10
+ *
11
+ * Sent as the `X-Base44-Anonymous-Id` header on unauthenticated requests so the
12
+ * backend can group an anonymous user's agent conversations and enforce
13
+ * ownership (the header is treated as a bearer-style credential). Persisted in
14
+ * localStorage so it survives reloads; a new browser/device or cleared storage
15
+ * starts a fresh anonymous identity.
16
+ *
17
+ * Returns `null` outside the browser (no `localStorage` / SSR) so callers can
18
+ * skip the header on the server.
19
+ *
20
+ * @internal
21
+ */
22
+ export function getOrCreateAnonymousVisitorId() {
23
+ if (typeof window === "undefined" || !window.localStorage) {
24
+ return null;
25
+ }
26
+ try {
27
+ const existing = window.localStorage.getItem(ANONYMOUS_VISITOR_ID_STORAGE_KEY);
28
+ if (existing) {
29
+ return existing;
30
+ }
31
+ const minted = uuidv4();
32
+ window.localStorage.setItem(ANONYMOUS_VISITOR_ID_STORAGE_KEY, minted);
33
+ return minted;
34
+ }
35
+ catch (_a) {
36
+ // localStorage unavailable (private mode / sandboxed iframe): no stable id.
37
+ return null;
38
+ }
39
+ }
@@ -1,6 +1,7 @@
1
1
  import axios from "axios";
2
2
  import { isInIFrame } from "./common.js";
3
3
  import { v4 as uuidv4 } from "uuid";
4
+ import { getOrCreateAnonymousVisitorId } from "./anon-visitor.js";
4
5
  /**
5
6
  * Custom error class for Base44 SDK errors.
6
7
  *
@@ -131,6 +132,15 @@ export function createAxiosClient({ baseURL, headers = {}, token, interceptRespo
131
132
  client.interceptors.request.use((config) => {
132
133
  if (typeof window !== "undefined") {
133
134
  config.headers.set("X-Origin-URL", window.location.href);
135
+ // On unauthenticated clients, attach a stable anonymous visitor id so the
136
+ // backend can support anonymous agent access (conversation grouping +
137
+ // ownership). Authenticated clients are identified by their token instead.
138
+ if (!token) {
139
+ const anonymousVisitorId = getOrCreateAnonymousVisitorId();
140
+ if (anonymousVisitorId) {
141
+ config.headers.set("X-Base44-Anonymous-Id", anonymousVisitorId);
142
+ }
143
+ }
134
144
  }
135
145
  const requestId = uuidv4();
136
146
  config.requestId = requestId;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@base44-preview/sdk",
3
- "version": "0.8.32-pr.185.2dc1fa1",
3
+ "version": "0.8.32-pr.198.9e03952",
4
4
  "description": "JavaScript SDK for Base44 API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",