@howone/sdk 0.3.23 → 0.3.25

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.
package/dist/index.mjs CHANGED
@@ -258,69 +258,6 @@ var init_auth = __esm({
258
258
  }
259
259
  });
260
260
 
261
- // src/utils/session.ts
262
- var session_exports = {};
263
- __export(session_exports, {
264
- clearGuestSession: () => clearGuestSession,
265
- consumeGuestSession: () => consumeGuestSession,
266
- getExistingSessionId: () => getExistingSessionId,
267
- getGuestSessionId: () => getGuestSessionId,
268
- isGuestMode: () => isGuestMode
269
- });
270
- function getGuestSessionId() {
271
- if (typeof window === "undefined") return null;
272
- try {
273
- let sessionId = localStorage.getItem(GUEST_SESSION_KEY);
274
- if (!sessionId) {
275
- sessionId = crypto.randomUUID();
276
- localStorage.setItem(GUEST_SESSION_KEY, sessionId);
277
- }
278
- return sessionId;
279
- } catch {
280
- return null;
281
- }
282
- }
283
- function clearGuestSession() {
284
- if (typeof window === "undefined") return;
285
- try {
286
- localStorage.removeItem(GUEST_SESSION_KEY);
287
- } catch {
288
- }
289
- }
290
- function isGuestMode() {
291
- if (typeof window === "undefined") return false;
292
- const hasAuthToken = !!localStorage.getItem("auth_token");
293
- const hasSession = !!localStorage.getItem(GUEST_SESSION_KEY);
294
- return !hasAuthToken && hasSession;
295
- }
296
- function getExistingSessionId() {
297
- if (typeof window === "undefined") return null;
298
- try {
299
- return localStorage.getItem(GUEST_SESSION_KEY);
300
- } catch {
301
- return null;
302
- }
303
- }
304
- function consumeGuestSession() {
305
- if (typeof window === "undefined") return null;
306
- try {
307
- const sessionId = localStorage.getItem(GUEST_SESSION_KEY);
308
- if (sessionId) {
309
- localStorage.removeItem(GUEST_SESSION_KEY);
310
- }
311
- return sessionId;
312
- } catch {
313
- return null;
314
- }
315
- }
316
- var GUEST_SESSION_KEY;
317
- var init_session = __esm({
318
- "src/utils/session.ts"() {
319
- "use strict";
320
- GUEST_SESSION_KEY = "howone_guest_session";
321
- }
322
- });
323
-
324
261
  // src/components/FloatingButton.tsx
325
262
  import { Icon } from "@iconify/react/dist/iconify.js";
326
263
  import { jsx, jsxs } from "react/jsx-runtime";
@@ -1312,7 +1249,43 @@ var ElementSelectorProvider = ({ children }) => {
1312
1249
 
1313
1250
  // src/components/auth/HowoneProvider.tsx
1314
1251
  init_config();
1315
- init_session();
1252
+
1253
+ // src/utils/session.ts
1254
+ var GUEST_SESSION_KEY = "howone_guest_session";
1255
+ function getGuestSessionId() {
1256
+ if (typeof window === "undefined") return null;
1257
+ try {
1258
+ let sessionId = localStorage.getItem(GUEST_SESSION_KEY);
1259
+ if (!sessionId) {
1260
+ sessionId = crypto.randomUUID();
1261
+ localStorage.setItem(GUEST_SESSION_KEY, sessionId);
1262
+ }
1263
+ return sessionId;
1264
+ } catch {
1265
+ return null;
1266
+ }
1267
+ }
1268
+ function clearGuestSession() {
1269
+ if (typeof window === "undefined") return;
1270
+ try {
1271
+ localStorage.removeItem(GUEST_SESSION_KEY);
1272
+ } catch {
1273
+ }
1274
+ }
1275
+ function isGuestMode() {
1276
+ if (typeof window === "undefined") return false;
1277
+ const hasAuthToken = !!localStorage.getItem("auth_token");
1278
+ const hasSession = !!localStorage.getItem(GUEST_SESSION_KEY);
1279
+ return !hasAuthToken && hasSession;
1280
+ }
1281
+ function getExistingSessionId() {
1282
+ if (typeof window === "undefined") return null;
1283
+ try {
1284
+ return localStorage.getItem(GUEST_SESSION_KEY);
1285
+ } catch {
1286
+ return null;
1287
+ }
1288
+ }
1316
1289
 
1317
1290
  // src/components/ui/Toast/ClayxToast.tsx
1318
1291
  import React5, { useCallback as useCallback4 } from "react";
@@ -1819,9 +1792,14 @@ var HowOneProvider = ({
1819
1792
  }, [redirectOnUnauthenticated, resolvedAuthUrl, projectId]);
1820
1793
  useEffect7(() => {
1821
1794
  if (!hasCheckedUrlToken) return;
1822
- const guestMode = isGuestMode() || !!getExistingSessionId();
1795
+ if (token || user) {
1796
+ setIsGuest(false);
1797
+ return;
1798
+ }
1799
+ const sessionId = getGuestSessionId();
1800
+ const guestMode = !!sessionId;
1823
1801
  setIsGuest(guestMode);
1824
- if (token || user || guestMode) {
1802
+ if (guestMode) {
1825
1803
  return;
1826
1804
  }
1827
1805
  redirectToAuth();
@@ -2762,13 +2740,9 @@ async function executeSSEWorkflow(request, options = {}) {
2762
2740
  if (options.authToken) {
2763
2741
  headers["Authorization"] = `Bearer ${options.authToken}`;
2764
2742
  } else {
2765
- try {
2766
- const { getGuestSessionId: getGuestSessionId2 } = (init_session(), __toCommonJS(session_exports));
2767
- const sessionId = getGuestSessionId2?.();
2768
- if (sessionId) {
2769
- headers["X-Session-Id"] = sessionId;
2770
- }
2771
- } catch {
2743
+ const sessionId = getGuestSessionId();
2744
+ if (sessionId) {
2745
+ headers["X-Session-Id"] = sessionId;
2772
2746
  }
2773
2747
  }
2774
2748
  const method = request.method?.toUpperCase() ?? "POST";
@@ -3554,13 +3528,9 @@ function createClient(opts) {
3554
3528
  if (availableToken) {
3555
3529
  config.headers["Authorization"] = `Bearer ${availableToken}`;
3556
3530
  } else {
3557
- try {
3558
- const { getGuestSessionId: getGuestSessionId2 } = (init_session(), __toCommonJS(session_exports));
3559
- const sessionId = getGuestSessionId2?.();
3560
- if (sessionId) {
3561
- config.headers["X-Session-Id"] = sessionId;
3562
- }
3563
- } catch {
3531
+ const sessionId = getGuestSessionId();
3532
+ if (sessionId) {
3533
+ config.headers["X-Session-Id"] = sessionId;
3564
3534
  }
3565
3535
  }
3566
3536
  }
@@ -4364,9 +4334,6 @@ var elementSelector = {
4364
4334
  */
4365
4335
  isActive: () => getElementSelectorState().active
4366
4336
  };
4367
-
4368
- // src/index.ts
4369
- init_session();
4370
4337
  export {
4371
4338
  AUTH_TOKEN_KEY,
4372
4339
  ClayxButton,