@chrryai/chrry 1.7.38 → 1.7.39

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.d.mts CHANGED
@@ -1629,13 +1629,14 @@ declare const getApps: ({ API_URL, token, chrryUrl, appId, }: {
1629
1629
  error: string;
1630
1630
  status: number;
1631
1631
  }>;
1632
- declare const getApp: ({ API_URL, token, appId, chrryUrl, skipCache, pathname, }: {
1632
+ declare const getApp: ({ API_URL, token, appId, chrryUrl, skipCache, pathname, storeSlug, }: {
1633
1633
  API_URL?: string;
1634
1634
  token: string;
1635
1635
  appId?: string;
1636
1636
  chrryUrl?: string;
1637
1637
  pathname?: string;
1638
1638
  skipCache?: boolean;
1639
+ storeSlug?: string;
1639
1640
  }) => Promise<appWithStore>;
1640
1641
  declare const getTranslations: ({ API_URL, token, locale, }?: {
1641
1642
  API_URL?: string;
package/dist/index.d.ts CHANGED
@@ -1629,13 +1629,14 @@ declare const getApps: ({ API_URL, token, chrryUrl, appId, }: {
1629
1629
  error: string;
1630
1630
  status: number;
1631
1631
  }>;
1632
- declare const getApp: ({ API_URL, token, appId, chrryUrl, skipCache, pathname, }: {
1632
+ declare const getApp: ({ API_URL, token, appId, chrryUrl, skipCache, pathname, storeSlug, }: {
1633
1633
  API_URL?: string;
1634
1634
  token: string;
1635
1635
  appId?: string;
1636
1636
  chrryUrl?: string;
1637
1637
  pathname?: string;
1638
1638
  skipCache?: boolean;
1639
+ storeSlug?: string;
1639
1640
  }) => Promise<appWithStore>;
1640
1641
  declare const getTranslations: ({ API_URL, token, locale, }?: {
1641
1642
  API_URL?: string;
package/dist/index.js CHANGED
@@ -2434,13 +2434,15 @@ var init_lib = __esm({
2434
2434
  appId,
2435
2435
  chrryUrl,
2436
2436
  skipCache,
2437
- pathname
2437
+ pathname,
2438
+ storeSlug
2438
2439
  }) => {
2439
2440
  const params = new URLSearchParams();
2440
2441
  if (chrryUrl) params.append("chrryUrl", chrryUrl);
2441
2442
  if (appId) params.append("appId", appId);
2442
2443
  if (pathname) params.append("pathname", encodeURIComponent(pathname));
2443
2444
  if (skipCache) params.append("skipCache", "true");
2445
+ if (storeSlug) params.append("storeSlug", storeSlug);
2444
2446
  const url = `${API_URL2}/apps${params.toString() ? `?${params.toString()}` : ""}`;
2445
2447
  const response = await fetch(url, {
2446
2448
  headers: {
@@ -3264,7 +3266,7 @@ var init_utils = __esm({
3264
3266
  };
3265
3267
  isFirefox = typeof navigator !== "undefined" && navigator?.userAgent?.includes("Firefox");
3266
3268
  config = getSiteConfig(getClientHostname2());
3267
- VERSION = config.version || "1.7.38";
3269
+ VERSION = config.version || "1.7.39";
3268
3270
  getSlugFromPathname = (path) => {
3269
3271
  return getAppAndStoreSlugs(path, {
3270
3272
  defaultAppSlug: config.slug,
@@ -23806,6 +23808,33 @@ function AuthProvider({
23806
23808
  setIsCookieReady(true);
23807
23809
  }
23808
23810
  }, [isExtension2]);
23811
+ const merge = (prevApps, newApps) => {
23812
+ const existingAppsMap = new Map(prevApps.map((app2) => [app2.id, app2]));
23813
+ newApps.forEach((newApp2) => {
23814
+ const existingApp = existingAppsMap.get(newApp2.id);
23815
+ if (newApp2.name === "MyAgent") {
23816
+ }
23817
+ if (existingApp && hasStoreApps(newApp2)) {
23818
+ existingAppsMap.set(newApp2.id, newApp2);
23819
+ } else {
23820
+ existingAppsMap.set(newApp2.id, newApp2);
23821
+ }
23822
+ });
23823
+ return Array.from(existingAppsMap.values());
23824
+ };
23825
+ const [userBaseApp, setUserBaseApp] = (0, import_react20.useState)(
23826
+ session2?.userBaseApp
23827
+ );
23828
+ const userBaseStore = userBaseApp?.store;
23829
+ const [guestBaseApp, setGuestBaseApp] = (0, import_react20.useState)(
23830
+ session2?.guestBaseApp
23831
+ );
23832
+ const accountApp = userBaseApp || guestBaseApp;
23833
+ const setBaseAccountApp = (app2) => {
23834
+ user && setUserBaseApp(app2);
23835
+ guest && setGuestBaseApp(app2);
23836
+ };
23837
+ const guestBaseStore = guestBaseApp?.store;
23809
23838
  function processSession(sessionData2) {
23810
23839
  if (sessionData2) {
23811
23840
  setSession(sessionData2);
@@ -23876,15 +23905,40 @@ function AuthProvider({
23876
23905
  removeParams("signIn");
23877
23906
  }
23878
23907
  };
23908
+ const [newApp, setNewApp] = (0, import_react20.useState)(void 0);
23909
+ const [updatedApp, setUpdatedApp] = (0, import_react20.useState)(
23910
+ void 0
23911
+ );
23912
+ const [loadingAppId, setLoadingAppId] = (0, import_react20.useState)(
23913
+ void 0
23914
+ );
23915
+ const allApps = merge(
23916
+ session2?.app?.store?.apps || [],
23917
+ userBaseApp ? [userBaseApp] : guestBaseApp ? [guestBaseApp] : []
23918
+ );
23919
+ const [storeApps, setAllApps] = (0, import_react20.useState)(allApps);
23920
+ const getAppSlug2 = (targetApp, defaultSlug = "/") => getAppSlug_default({ targetApp, defaultSlug, pathname, baseApp });
23921
+ const baseAppInternal = storeApps.find((item) => {
23922
+ if (!item) return false;
23923
+ if (siteConfig.slug === item.slug && item.store?.slug === siteConfig.storeSlug) {
23924
+ return true;
23925
+ }
23926
+ });
23927
+ const [baseApp, setBaseApp] = (0, import_react20.useState)(
23928
+ baseAppInternal
23929
+ );
23930
+ const [app, setAppInternal] = (0, import_react20.useState)(props.app || session2?.app || baseApp);
23931
+ const appId = newApp?.id || updatedApp?.id || loadingAppId || app?.id;
23932
+ const [isSavingApp, setIsSavingApp] = (0, import_react20.useState)(false);
23933
+ const [isManagingApp, setIsManagingApp] = (0, import_react20.useState)(false);
23879
23934
  const {
23880
23935
  data: sessionSwr,
23881
23936
  mutate: refetchSession,
23882
23937
  isLoading: isSessionLoading,
23883
23938
  error: sessionError
23884
23939
  } = (0, import_swr.default)(
23885
- (isExtension2 ? isStorageReady && isCookieReady : true) && fingerprint && token && deviceId && shouldFetchSession && !isRemovingApp ? "session" : null,
23940
+ (isExtension2 ? isStorageReady && isCookieReady : true) && fingerprint && token && deviceId && shouldFetchSession && !isRemovingApp && !isSavingApp && !isManagingApp ? "session" : null,
23886
23941
  async () => {
23887
- console.log(`\u{1F680} ~ fingerprint:`, fingerprint);
23888
23942
  try {
23889
23943
  const result = await getSession({
23890
23944
  deviceId,
@@ -24008,54 +24062,11 @@ function AuthProvider({
24008
24062
  isPWA
24009
24063
  });
24010
24064
  };
24011
- const merge = (prevApps, newApps) => {
24012
- const existingAppsMap = new Map(prevApps.map((app2) => [app2.id, app2]));
24013
- newApps.forEach((newApp2) => {
24014
- const existingApp = existingAppsMap.get(newApp2.id);
24015
- if (newApp2.name === "MyAgent") {
24016
- }
24017
- if (existingApp && hasStoreApps(newApp2)) {
24018
- existingAppsMap.set(newApp2.id, newApp2);
24019
- } else {
24020
- existingAppsMap.set(newApp2.id, newApp2);
24021
- }
24022
- });
24023
- return Array.from(existingAppsMap.values());
24024
- };
24025
- const [userBaseApp, setUserBaseApp] = (0, import_react20.useState)(
24026
- session2?.userBaseApp
24027
- );
24028
- const userBaseStore = userBaseApp?.store;
24029
- const [guestBaseApp, setGuestBaseApp] = (0, import_react20.useState)(
24030
- session2?.guestBaseApp
24031
- );
24032
- const accountApp = userBaseApp || guestBaseApp;
24033
- const setBaseAccountApp = (app2) => {
24034
- user && setUserBaseApp(app2);
24035
- guest && setGuestBaseApp(app2);
24036
- };
24037
- const guestBaseStore = guestBaseApp?.store;
24038
- const allApps = merge(
24039
- sessionData?.app?.store?.apps || [],
24040
- userBaseApp ? [userBaseApp] : guestBaseApp ? [guestBaseApp] : []
24041
- );
24042
- const [storeApps, setAllApps] = (0, import_react20.useState)(allApps);
24043
- const getAppSlug2 = (targetApp, defaultSlug = "/") => getAppSlug_default({ targetApp, defaultSlug, pathname, baseApp });
24044
- const baseAppInternal = storeApps.find((item) => {
24045
- if (!item) return false;
24046
- if (siteConfig.slug === item.slug && item.store?.slug === siteConfig.storeSlug) {
24047
- return true;
24048
- }
24049
- });
24050
- const [baseApp, setBaseApp] = (0, import_react20.useState)(
24051
- baseAppInternal
24052
- );
24053
24065
  (0, import_react20.useEffect)(() => {
24054
24066
  hasStoreApps(baseAppInternal) && setBaseApp(baseAppInternal);
24055
24067
  }, [baseAppInternal]);
24056
24068
  const threadId = getThreadId(pathname);
24057
24069
  const threadIdRef = (0, import_react20.useRef)(threadId);
24058
- const [app, setAppInternal] = (0, import_react20.useState)(props.app || session2?.app || baseApp);
24059
24070
  (0, import_react20.useEffect)(() => {
24060
24071
  const signInParam = searchParams.get("signIn");
24061
24072
  const currentPart = signInParam;
@@ -24177,10 +24188,6 @@ function AuthProvider({
24177
24188
  "lastAppId",
24178
24189
  void 0
24179
24190
  );
24180
- const [newApp, setNewApp] = (0, import_react20.useState)(void 0);
24181
- const [updatedApp, setUpdatedApp] = (0, import_react20.useState)(
24182
- void 0
24183
- );
24184
24191
  const mergeApps = (0, import_react20.useCallback)(
24185
24192
  (newApps) => {
24186
24193
  setAllApps(merge(storeApps, newApps));
@@ -24193,9 +24200,6 @@ function AuthProvider({
24193
24200
  shouldFetchSession && await refetchSession();
24194
24201
  };
24195
24202
  const [isSplash, setIsSplash] = (0, import_react20.useState)(true);
24196
- const [loadingAppId, setLoadingAppId] = (0, import_react20.useState)(
24197
- void 0
24198
- );
24199
24203
  const [loadingApp, setLoadingAppInternal] = (0, import_react20.useState)(void 0);
24200
24204
  const setLoadingApp = (appWithStore) => {
24201
24205
  setLoadingAppId(appWithStore?.id);
@@ -24207,8 +24211,6 @@ function AuthProvider({
24207
24211
  const sushi = storeApps?.find((app2) => app2.slug === "sushi");
24208
24212
  const focus2 = storeApps?.find((app2) => app2.slug === "focus");
24209
24213
  const accountAppId = userBaseApp?.id || guestBaseApp?.id;
24210
- const appId = newApp?.id || updatedApp?.id || loadingAppId || app?.id;
24211
- const [isManagingApp, setIsManagingApp] = (0, import_react20.useState)(false);
24212
24214
  const {
24213
24215
  data: storeAppsSwr,
24214
24216
  mutate: refetchApps,
@@ -24216,29 +24218,24 @@ function AuthProvider({
24216
24218
  } = (0, import_swr.default)(token && !isRemovingApp && ["app", appId], async () => {
24217
24219
  try {
24218
24220
  if (!token) return;
24219
- const app2 = await getApp({
24221
+ const result = await getApp({
24220
24222
  token,
24221
24223
  appId,
24222
24224
  chrryUrl,
24223
24225
  pathname,
24224
- skipCache: !!accountAppId || appId === accountAppId || !!newApp?.id || isManagingApp
24226
+ skipCache: appId !== app?.id || appId === accountAppId
24225
24227
  });
24226
- return app2;
24228
+ return result;
24227
24229
  } catch (error2) {
24228
24230
  captureException(error2);
24229
24231
  }
24230
24232
  });
24231
- (0, import_react20.useEffect)(() => {
24232
- if (newApp?.id || updatedApp?.id) {
24233
- refetchApps();
24234
- }
24235
- }, [newApp?.id, updatedApp?.id]);
24236
24233
  (0, import_react20.useEffect)(() => {
24237
24234
  if (storeAppsSwr) {
24238
24235
  storeAppsSwr.store?.apps?.find((app2) => app2.id === loadingAppId) && setLoadingApp(void 0);
24239
24236
  mergeApps(storeAppsSwr.store?.apps || []);
24240
24237
  }
24241
- }, [storeAppsSwr, guest, user, newApp, updatedApp, loadingAppId]);
24238
+ }, [storeAppsSwr]);
24242
24239
  const canShowFocus = !!(focus2 && app && app?.id === focus2.id && !threadId);
24243
24240
  const [showFocus, setShowFocus] = (0, import_react20.useState)(canShowFocus);
24244
24241
  (0, import_react20.useEffect)(() => {
@@ -24548,7 +24545,6 @@ function AuthProvider({
24548
24545
  console.warn("PerformanceObserver not supported:", error2);
24549
24546
  }
24550
24547
  }, [track]);
24551
- const [isSavingApp, setIsSavingApp] = (0, import_react20.useState)(false);
24552
24548
  const [shouldFetchTasks, setShouldFetchTasks] = (0, import_react20.useState)(false);
24553
24549
  const [isLoadingTasks, setIsLoadingTasks] = (0, import_react20.useState)(false);
24554
24550
  const { data: tasksData, mutate: refetchTasks } = (0, import_swr.default)(
@@ -24864,7 +24860,7 @@ function DataProvider({ children, ...rest }) {
24864
24860
  const [instructions, setInstructions] = (0, import_react21.useState)([]);
24865
24861
  const [affiliateStats, setAffiliateStats] = (0, import_react21.useState)(null);
24866
24862
  const [loadingAffiliateStats, setLoadingAffiliateStats] = (0, import_react21.useState)(false);
24867
- const VERSION4 = "1.7.38";
24863
+ const VERSION4 = "1.7.39";
24868
24864
  const [weather, setWeather] = useLocalStorage2("weather", user?.weather || guest?.weather || void 0);
24869
24865
  const {
24870
24866
  API_URL: API_URL2,
@@ -26029,7 +26025,7 @@ function AppProvider({ children }) {
26029
26025
  Object.entries(payload).forEach(([key, value]) => {
26030
26026
  newSearchParams.set(key, String(value));
26031
26027
  });
26032
- const slug2 = userBaseApp?.store?.slug || guestBaseApp?.store?.slug || baseApp?.store?.slug;
26028
+ const slug2 = baseApp?.store?.slug;
26033
26029
  const newUrl = `/${slug2 === chrry?.slug ? "" : slug2 ?? chrry?.slug}/${app?.slug}?${newSearchParams.toString()}`;
26034
26030
  push(newUrl);
26035
26031
  } else {