@chrryai/chrry 1.4.76 → 1.4.78

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
@@ -489,7 +489,7 @@ var init_locales = __esm({
489
489
 
490
490
  // utils/siteConfig.ts
491
491
  function detectSiteModeDomain(hostname2) {
492
- const defaultMode = "vex";
492
+ const defaultMode = "atlas";
493
493
  const rawHost = hostname2 || (typeof window !== "undefined" ? window?.location?.hostname : "") || "";
494
494
  let host = rawHost?.trim().toLowerCase();
495
495
  if (host?.includes("://")) {
@@ -1899,7 +1899,7 @@ var init_utils = __esm({
1899
1899
  };
1900
1900
  isFirefox = typeof navigator !== "undefined" && navigator?.userAgent?.includes("Firefox");
1901
1901
  config = getSiteConfig(getClientHostname());
1902
- VERSION = config.version || "1.4.76";
1902
+ VERSION = config.version || "1.4.78";
1903
1903
  getSlugFromPathname = (path) => {
1904
1904
  return getAppAndStoreSlugs(path, {
1905
1905
  defaultAppSlug: config.slug,
@@ -2294,31 +2294,59 @@ var init_storage = __esm({
2294
2294
  });
2295
2295
 
2296
2296
  // platform/cookies.ts
2297
+ function stringifyOptions(options) {
2298
+ return Object.keys(options).reduce((acc, key) => {
2299
+ if (key === "days") {
2300
+ return acc;
2301
+ } else {
2302
+ const value = options[key];
2303
+ if (value === false) {
2304
+ return acc;
2305
+ } else if (value === true) {
2306
+ return `${acc}; ${key}`;
2307
+ } else if (value) {
2308
+ return `${acc}; ${key}=${value}`;
2309
+ }
2310
+ return acc;
2311
+ }
2312
+ }, "");
2313
+ }
2297
2314
  function useCookie(key, initialValue = "") {
2315
+ if (isBrowser && !isNative() && !isBrowserExtension()) {
2316
+ const [item, setItem] = (0, import_react2.useState)(() => {
2317
+ const existingCookie = getCookieWeb(key, "");
2318
+ if (!existingCookie && initialValue) {
2319
+ setCookieWeb(key, initialValue);
2320
+ return initialValue;
2321
+ }
2322
+ return existingCookie || initialValue;
2323
+ });
2324
+ const updateItem2 = (0, import_react2.useCallback)(
2325
+ (value2, options) => {
2326
+ setItem(value2);
2327
+ setCookieWeb(key, value2, options);
2328
+ },
2329
+ [key]
2330
+ );
2331
+ const removeItem2 = (0, import_react2.useCallback)(() => {
2332
+ setItem(initialValue);
2333
+ removeCookieWeb(key);
2334
+ }, [key, initialValue]);
2335
+ return [item, updateItem2, removeItem2];
2336
+ }
2298
2337
  const [value, setValue] = (0, import_react2.useState)(initialValue);
2299
- (0, import_react2.useEffect)(() => {
2300
- const loadCookie = async () => {
2301
- const cookieValue = await getCookie(key);
2302
- if (cookieValue !== null) {
2303
- setValue(cookieValue);
2304
- } else if (initialValue) {
2305
- await setCookieValue(key, initialValue);
2306
- }
2307
- };
2308
- loadCookie();
2309
- }, [key, initialValue]);
2310
- const setCookie = (0, import_react2.useCallback)(
2311
- async (newValue, options) => {
2338
+ const updateItem = (0, import_react2.useCallback)(
2339
+ (newValue, _options) => {
2312
2340
  setValue(newValue);
2313
- await setCookieValue(key, newValue, options);
2341
+ storage2.setItem(key, newValue);
2314
2342
  },
2315
2343
  [key]
2316
2344
  );
2317
- const removeCookie = (0, import_react2.useCallback)(async () => {
2345
+ const removeItem = (0, import_react2.useCallback)(() => {
2318
2346
  setValue(initialValue);
2319
- await deleteCookie(key);
2347
+ storage2.removeItem(key);
2320
2348
  }, [key, initialValue]);
2321
- return [value, setCookie, removeCookie];
2349
+ return [value, updateItem, removeItem];
2322
2350
  }
2323
2351
  function getCookieSync(key) {
2324
2352
  if (typeof document !== "undefined" && document.cookie) {
@@ -2332,129 +2360,7 @@ function getCookieSync(key) {
2332
2360
  }
2333
2361
  return null;
2334
2362
  }
2335
- async function getCookie(key) {
2336
- if (isNative()) {
2337
- return storage2.getItem(key);
2338
- }
2339
- if (isBrowserExtension()) {
2340
- try {
2341
- const websiteUrls = getExtensionUrls();
2342
- const final = [];
2343
- if (typeof chrome !== "undefined" && chrome.cookies) {
2344
- for (const url of websiteUrls) {
2345
- const cookie = await new Promise(
2346
- (resolve) => {
2347
- chrome.cookies.get({ url, name: key }, (cookie2) => {
2348
- if (chrome.runtime.lastError) {
2349
- resolve(null);
2350
- } else {
2351
- resolve(cookie2);
2352
- }
2353
- });
2354
- }
2355
- );
2356
- if (cookie?.value) {
2357
- final.push(cookie?.value);
2358
- }
2359
- }
2360
- if (key === "token") {
2361
- storage2.setItem("_cookiesReady", "true");
2362
- }
2363
- if (final.length) {
2364
- if (key === "token") {
2365
- return final.sort((a, b) => b.length - a.length)[0] || null;
2366
- }
2367
- return final[0] || null;
2368
- }
2369
- return await storage2.getItem(key);
2370
- }
2371
- if (typeof browser !== "undefined" && browser.cookies) {
2372
- for (const url of websiteUrls) {
2373
- const cookie = await browser.cookies.get({ url, name: key });
2374
- if (cookie?.value) {
2375
- return cookie.value;
2376
- }
2377
- }
2378
- return await storage2.getItem(key);
2379
- }
2380
- } catch {
2381
- }
2382
- return await storage2.getItem(key);
2383
- }
2384
- if (typeof document !== "undefined" && document.cookie) {
2385
- const cookies = document.cookie.split(";");
2386
- for (const cookie of cookies) {
2387
- const [cookieName, cookieValue] = cookie.split("=").map((c) => c.trim());
2388
- if (cookieName === key && cookieValue) {
2389
- return decodeURIComponent(cookieValue);
2390
- }
2391
- }
2392
- }
2393
- return null;
2394
- }
2395
- async function setCookieValue(key, value, options = {}) {
2396
- if (isNative()) {
2397
- storage2.setItem(key, value);
2398
- return;
2399
- }
2400
- if (isBrowserExtension()) {
2401
- console.log("Setting cookie in extension storage:", key, value);
2402
- storage2.setItem(key, value);
2403
- return;
2404
- }
2405
- if (typeof document !== "undefined") {
2406
- let cookieString = `${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
2407
- if (options.maxAge) {
2408
- cookieString += `; max-age=${options.maxAge}`;
2409
- }
2410
- if (options.expires) {
2411
- cookieString += `; expires=${options.expires.toUTCString()}`;
2412
- }
2413
- cookieString += `; path=${options.path || "/"}`;
2414
- if (options.domain) {
2415
- cookieString += `; domain=${options.domain}`;
2416
- }
2417
- if (options.secure) {
2418
- cookieString += "; secure";
2419
- }
2420
- if (options.sameSite) {
2421
- cookieString += `; samesite=${options.sameSite}`;
2422
- }
2423
- document.cookie = cookieString;
2424
- }
2425
- }
2426
- async function deleteCookie(key) {
2427
- if (isNative()) {
2428
- storage2.removeItem(key);
2429
- return;
2430
- }
2431
- if (isBrowserExtension()) {
2432
- try {
2433
- if (typeof chrome !== "undefined" && chrome.cookies) {
2434
- return new Promise((resolve) => {
2435
- chrome.cookies.remove(
2436
- { url: window.location.href, name: key },
2437
- () => resolve()
2438
- );
2439
- });
2440
- }
2441
- if (typeof browser !== "undefined" && browser.cookies) {
2442
- await browser.cookies.remove({
2443
- url: window.location.href,
2444
- name: key
2445
- });
2446
- return;
2447
- }
2448
- } catch {
2449
- }
2450
- storage2.removeItem(key);
2451
- return;
2452
- }
2453
- if (typeof document !== "undefined") {
2454
- document.cookie = `${encodeURIComponent(key)}=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/`;
2455
- }
2456
- }
2457
- var import_react2;
2363
+ var import_react2, isBrowser, setCookieWeb, getCookieWeb, removeCookieWeb;
2458
2364
  var init_cookies = __esm({
2459
2365
  "platform/cookies.ts"() {
2460
2366
  "use strict";
@@ -2462,6 +2368,29 @@ var init_cookies = __esm({
2462
2368
  init_PlatformProvider();
2463
2369
  init_storage();
2464
2370
  init_utils();
2371
+ isBrowser = typeof window !== "undefined";
2372
+ setCookieWeb = (name, value, options = {}) => {
2373
+ if (!isBrowser) return;
2374
+ const optionsWithDefaults = {
2375
+ days: 7,
2376
+ path: "/",
2377
+ ...options
2378
+ };
2379
+ const expires = new Date(
2380
+ Date.now() + (optionsWithDefaults.days || 7) * 864e5
2381
+ ).toUTCString();
2382
+ document.cookie = name + "=" + encodeURIComponent(value) + "; expires=" + expires + stringifyOptions(optionsWithDefaults);
2383
+ };
2384
+ getCookieWeb = (name, initialValue = "") => {
2385
+ return isBrowser && document.cookie.split("; ").reduce((r, v) => {
2386
+ const parts = v.split("=");
2387
+ return parts[0] === name && parts[1] ? decodeURIComponent(parts[1]) : r;
2388
+ }, "") || initialValue;
2389
+ };
2390
+ removeCookieWeb = (name) => {
2391
+ if (!isBrowser) return;
2392
+ document.cookie = `${name}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;`;
2393
+ };
2465
2394
  }
2466
2395
  });
2467
2396
 
@@ -5531,7 +5460,8 @@ var init_lib = __esm({
5531
5460
  ...appSlug ? { "x-app-slug": appId } : {},
5532
5461
  ...routeType ? { "x-route-type": routeType } : {},
5533
5462
  ...pathname ? { "x-pathname": pathname } : {},
5534
- ...locale4 ? { "x-locale": locale4 } : {}
5463
+ ...locale4 ? { "x-locale": locale4 } : {},
5464
+ ...fingerprint ? { "x-fp": fingerprint } : {}
5535
5465
  }
5536
5466
  });
5537
5467
  if (!response.ok) {
@@ -5910,7 +5840,7 @@ var init_ThemeContext = __esm({
5910
5840
  });
5911
5841
 
5912
5842
  // lib/db.ts
5913
- var import_idb, dbInstance, getDB, cacheData, getCachedData;
5843
+ var import_idb, dbInstance, getDB, cacheData, getCachedData, clearCache;
5914
5844
  var init_db = __esm({
5915
5845
  "lib/db.ts"() {
5916
5846
  "use strict";
@@ -5963,6 +5893,15 @@ var init_db = __esm({
5963
5893
  return null;
5964
5894
  }
5965
5895
  };
5896
+ clearCache = async () => {
5897
+ try {
5898
+ const db = await getDB();
5899
+ if (!db) return;
5900
+ await db.clear("cache");
5901
+ } catch (error) {
5902
+ console.error("Failed to clear cache:", error);
5903
+ }
5904
+ };
5966
5905
  }
5967
5906
  });
5968
5907
 
@@ -23046,15 +22985,18 @@ function AuthProvider({
23046
22985
  }, [deviceId, setDeviceId, isStorageReady]);
23047
22986
  const [enableNotifications, setEnableNotifications] = useLocalStorage2("enableNotifications", true);
23048
22987
  const [shouldFetchSession, setShouldFetchSession] = (0, import_react19.useState)(!session2);
23049
- const [fingerprint, setFingerprint] = useCookieOrLocalStorage(
22988
+ const [fingerprint, setFingerprintInternal] = useCookieOrLocalStorage(
23050
22989
  "fingerprint",
23051
22990
  session2?.guest?.fingerprint || session2?.user?.fingerprint || fingerprintParam
23052
22991
  );
22992
+ const setFingerprint = (fingerprint2) => {
22993
+ };
23053
22994
  const [token, setTokenInternal] = useCookieOrLocalStorage(
23054
22995
  "token",
23055
- apiKey || session2?.user?.token || session2?.guest?.fingerprint,
23056
- true
22996
+ session2?.user?.token || session2?.guest?.fingerprint || apiKey,
22997
+ isExtension2
23057
22998
  );
22999
+ console.log(`\u{1F680} ~ DataProvider ~ token:`, token);
23058
23000
  const [isCookieReady, setIsCookieReady] = (0, import_react19.useState)(false);
23059
23001
  (0, import_react19.useEffect)(() => {
23060
23002
  if (isExtension2) {
@@ -23081,6 +23023,7 @@ function AuthProvider({
23081
23023
  }
23082
23024
  }, [isExtension2]);
23083
23025
  const setToken = (token2) => {
23026
+ console.log(`\u{1F680} ~ setToken ~ token:`, token2);
23084
23027
  setTokenInternal(token2 || "");
23085
23028
  };
23086
23029
  (0, import_react19.useEffect)(() => {
@@ -23098,10 +23041,6 @@ function AuthProvider({
23098
23041
  );
23099
23042
  const TEST_MEMBER_FINGERPRINTS = session2?.TEST_MEMBER_FINGERPRINTS || [];
23100
23043
  const TEST_GUEST_FINGERPRINTS = session2?.TEST_GUEST_FINGERPRINTS || [];
23101
- console.log(
23102
- `\u{1F680} ~ AuthProvider ~ TEST_GUEST_FINGERPRINTS:`,
23103
- TEST_GUEST_FINGERPRINTS
23104
- );
23105
23044
  const TEST_MEMBER_EMAILS = session2?.TEST_MEMBER_EMAILS || [];
23106
23045
  const [taskId, setTaskId] = (0, import_react19.useState)(
23107
23046
  searchParams.get("taskId") || void 0
@@ -23120,7 +23059,7 @@ function AuthProvider({
23120
23059
  const isLiveTest = isGuestTest || isMemberTest;
23121
23060
  const [signInPart, setSignInPartInternal] = import_react19.default.useState(void 0);
23122
23061
  const setSignInPart = (part) => {
23123
- const newPart = part && isLiveTest ? "credentials" : !!user ? void 0 : part;
23062
+ const newPart = part && isE2E ? "credentials" : !!user ? void 0 : part;
23124
23063
  setSignInPartInternal(newPart);
23125
23064
  if (newPart) {
23126
23065
  addParams({ signIn: newPart });
@@ -23885,6 +23824,7 @@ function AuthProvider({
23885
23824
  const bloom = allApps.find((app2) => app2.slug === "bloom");
23886
23825
  const zarathustra = allApps.find((app2) => app2.slug === "zarathustra");
23887
23826
  const signOut = async () => {
23827
+ await clearCache();
23888
23828
  setShouldFetchSession(false);
23889
23829
  setUser(void 0);
23890
23830
  setGuest(void 0);
@@ -24130,7 +24070,7 @@ function DataProvider({ children, ...rest }) {
24130
24070
  const [instructions, setInstructions] = (0, import_react21.useState)([]);
24131
24071
  const [affiliateStats, setAffiliateStats] = (0, import_react21.useState)(null);
24132
24072
  const [loadingAffiliateStats, setLoadingAffiliateStats] = (0, import_react21.useState)(false);
24133
- const VERSION4 = "1.4.76";
24073
+ const VERSION4 = "1.4.78";
24134
24074
  const [weather, setWeather] = useLocalStorage2("weather", user?.weather || guest?.weather || void 0);
24135
24075
  const {
24136
24076
  API_URL: API_URL2,
@@ -26584,10 +26524,9 @@ function ChatProvider({
26584
26524
  const {
26585
26525
  data: threadSWR,
26586
26526
  mutate,
26587
- error,
26588
- isLoading: isLoadingThread
26527
+ error
26589
26528
  } = (0, import_swr3.default)(
26590
- shouldFetchThread && token && threadId ? ["thread", threadId, liked, until] : null,
26529
+ shouldFetchThread && token && threadId ? ["thread", threadId, liked, until, token] : null,
26591
26530
  async () => {
26592
26531
  if (!threadId) return;
26593
26532
  const threadData2 = await actions.getThread({
@@ -42294,10 +42233,14 @@ function SignIn({
42294
42233
  guest,
42295
42234
  isExtensionRedirect,
42296
42235
  fingerprint,
42297
- signInContext,
42236
+ signInContext: signInContextInternal,
42298
42237
  signInPart: part,
42299
42238
  setSignInPart: setPart
42300
42239
  } = useAuth();
42240
+ const signInContext = async (provider, options) => {
42241
+ await clearCache();
42242
+ return signInContextInternal?.(provider, options);
42243
+ };
42301
42244
  const { t: t6 } = useAppContext();
42302
42245
  const {
42303
42246
  FRONTEND_URL: FRONTEND_URL2,
@@ -42739,6 +42682,7 @@ var init_SignIn_web = __esm({
42739
42682
  init_Modal();
42740
42683
  init_providers();
42741
42684
  init_platform();
42685
+ init_db();
42742
42686
  }
42743
42687
  });
42744
42688