@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.js CHANGED
@@ -269,69 +269,6 @@ var init_auth = __esm({
269
269
  }
270
270
  });
271
271
 
272
- // src/utils/session.ts
273
- var session_exports = {};
274
- __export(session_exports, {
275
- clearGuestSession: () => clearGuestSession,
276
- consumeGuestSession: () => consumeGuestSession,
277
- getExistingSessionId: () => getExistingSessionId,
278
- getGuestSessionId: () => getGuestSessionId,
279
- isGuestMode: () => isGuestMode
280
- });
281
- function getGuestSessionId() {
282
- if (typeof window === "undefined") return null;
283
- try {
284
- let sessionId = localStorage.getItem(GUEST_SESSION_KEY);
285
- if (!sessionId) {
286
- sessionId = crypto.randomUUID();
287
- localStorage.setItem(GUEST_SESSION_KEY, sessionId);
288
- }
289
- return sessionId;
290
- } catch {
291
- return null;
292
- }
293
- }
294
- function clearGuestSession() {
295
- if (typeof window === "undefined") return;
296
- try {
297
- localStorage.removeItem(GUEST_SESSION_KEY);
298
- } catch {
299
- }
300
- }
301
- function isGuestMode() {
302
- if (typeof window === "undefined") return false;
303
- const hasAuthToken = !!localStorage.getItem("auth_token");
304
- const hasSession = !!localStorage.getItem(GUEST_SESSION_KEY);
305
- return !hasAuthToken && hasSession;
306
- }
307
- function getExistingSessionId() {
308
- if (typeof window === "undefined") return null;
309
- try {
310
- return localStorage.getItem(GUEST_SESSION_KEY);
311
- } catch {
312
- return null;
313
- }
314
- }
315
- function consumeGuestSession() {
316
- if (typeof window === "undefined") return null;
317
- try {
318
- const sessionId = localStorage.getItem(GUEST_SESSION_KEY);
319
- if (sessionId) {
320
- localStorage.removeItem(GUEST_SESSION_KEY);
321
- }
322
- return sessionId;
323
- } catch {
324
- return null;
325
- }
326
- }
327
- var GUEST_SESSION_KEY;
328
- var init_session = __esm({
329
- "src/utils/session.ts"() {
330
- "use strict";
331
- GUEST_SESSION_KEY = "howone_guest_session";
332
- }
333
- });
334
-
335
272
  // src/index.ts
336
273
  var index_exports = {};
337
274
  __export(index_exports, {
@@ -1388,7 +1325,43 @@ var ElementSelectorProvider = ({ children }) => {
1388
1325
 
1389
1326
  // src/components/auth/HowoneProvider.tsx
1390
1327
  init_config();
1391
- init_session();
1328
+
1329
+ // src/utils/session.ts
1330
+ var GUEST_SESSION_KEY = "howone_guest_session";
1331
+ function getGuestSessionId() {
1332
+ if (typeof window === "undefined") return null;
1333
+ try {
1334
+ let sessionId = localStorage.getItem(GUEST_SESSION_KEY);
1335
+ if (!sessionId) {
1336
+ sessionId = crypto.randomUUID();
1337
+ localStorage.setItem(GUEST_SESSION_KEY, sessionId);
1338
+ }
1339
+ return sessionId;
1340
+ } catch {
1341
+ return null;
1342
+ }
1343
+ }
1344
+ function clearGuestSession() {
1345
+ if (typeof window === "undefined") return;
1346
+ try {
1347
+ localStorage.removeItem(GUEST_SESSION_KEY);
1348
+ } catch {
1349
+ }
1350
+ }
1351
+ function isGuestMode() {
1352
+ if (typeof window === "undefined") return false;
1353
+ const hasAuthToken = !!localStorage.getItem("auth_token");
1354
+ const hasSession = !!localStorage.getItem(GUEST_SESSION_KEY);
1355
+ return !hasAuthToken && hasSession;
1356
+ }
1357
+ function getExistingSessionId() {
1358
+ if (typeof window === "undefined") return null;
1359
+ try {
1360
+ return localStorage.getItem(GUEST_SESSION_KEY);
1361
+ } catch {
1362
+ return null;
1363
+ }
1364
+ }
1392
1365
 
1393
1366
  // src/components/ui/Toast/ClayxToast.tsx
1394
1367
  var import_react9 = __toESM(require("react"));
@@ -1895,9 +1868,14 @@ var HowOneProvider = ({
1895
1868
  }, [redirectOnUnauthenticated, resolvedAuthUrl, projectId]);
1896
1869
  (0, import_react11.useEffect)(() => {
1897
1870
  if (!hasCheckedUrlToken) return;
1898
- const guestMode = isGuestMode() || !!getExistingSessionId();
1871
+ if (token || user) {
1872
+ setIsGuest(false);
1873
+ return;
1874
+ }
1875
+ const sessionId = getGuestSessionId();
1876
+ const guestMode = !!sessionId;
1899
1877
  setIsGuest(guestMode);
1900
- if (token || user || guestMode) {
1878
+ if (guestMode) {
1901
1879
  return;
1902
1880
  }
1903
1881
  redirectToAuth();
@@ -2838,13 +2816,9 @@ async function executeSSEWorkflow(request, options = {}) {
2838
2816
  if (options.authToken) {
2839
2817
  headers["Authorization"] = `Bearer ${options.authToken}`;
2840
2818
  } else {
2841
- try {
2842
- const { getGuestSessionId: getGuestSessionId2 } = (init_session(), __toCommonJS(session_exports));
2843
- const sessionId = getGuestSessionId2?.();
2844
- if (sessionId) {
2845
- headers["X-Session-Id"] = sessionId;
2846
- }
2847
- } catch {
2819
+ const sessionId = getGuestSessionId();
2820
+ if (sessionId) {
2821
+ headers["X-Session-Id"] = sessionId;
2848
2822
  }
2849
2823
  }
2850
2824
  const method = request.method?.toUpperCase() ?? "POST";
@@ -3630,13 +3604,9 @@ function createClient(opts) {
3630
3604
  if (availableToken) {
3631
3605
  config.headers["Authorization"] = `Bearer ${availableToken}`;
3632
3606
  } else {
3633
- try {
3634
- const { getGuestSessionId: getGuestSessionId2 } = (init_session(), __toCommonJS(session_exports));
3635
- const sessionId = getGuestSessionId2?.();
3636
- if (sessionId) {
3637
- config.headers["X-Session-Id"] = sessionId;
3638
- }
3639
- } catch {
3607
+ const sessionId = getGuestSessionId();
3608
+ if (sessionId) {
3609
+ config.headers["X-Session-Id"] = sessionId;
3640
3610
  }
3641
3611
  }
3642
3612
  }
@@ -4440,9 +4410,6 @@ var elementSelector = {
4440
4410
  */
4441
4411
  isActive: () => getElementSelectorState().active
4442
4412
  };
4443
-
4444
- // src/index.ts
4445
- init_session();
4446
4413
  // Annotate the CommonJS export names for ESM import in node:
4447
4414
  0 && (module.exports = {
4448
4415
  AUTH_TOKEN_KEY,