@timpel/forumkit-sdk-react-native 0.2.3 → 0.2.5

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.ts CHANGED
@@ -16,6 +16,7 @@ type ThemeTokens = {
16
16
  type ForumKitConfig = {
17
17
  forumId: string;
18
18
  token: string;
19
+ getToken?: () => Promise<string>;
19
20
  theme?: ThemeTokens;
20
21
  apiUrl?: string;
21
22
  onLogout?: () => void;
package/dist/index.js CHANGED
@@ -833,11 +833,12 @@ function SessionProvider({ config, children }) {
833
833
  if (cancelled) return;
834
834
  expiresAtRef.current = Date.now() + expiresIn * 1e3;
835
835
  refreshTimer = setTimeout(() => {
836
- void refresh();
836
+ void refresh(true);
837
837
  }, expiresIn * 1e3 * 0.8);
838
838
  }
839
- function refresh() {
840
- return createSession(apiUrl, config.token).then((result) => {
839
+ function refresh(isRenewal = false) {
840
+ const tokenPromise = isRenewal && config.getToken ? config.getToken() : Promise.resolve(config.token);
841
+ return tokenPromise.then((hostToken) => createSession(apiUrl, hostToken)).then((result) => {
841
842
  if (cancelled) return;
842
843
  setState({ status: "ready", forumId: config.forumId, apiUrl, sessionToken: result.sessionToken, userId: result.userId, role: result.role, error: null });
843
844
  scheduleRefresh(result.expiresIn);
@@ -846,7 +847,7 @@ function SessionProvider({ config, children }) {
846
847
  const message = err instanceof Error ? err.message : "Failed to create session";
847
848
  setState({ status: "error", forumId: config.forumId, apiUrl, sessionToken: null, userId: null, role: null, error: message });
848
849
  retryTimer = setTimeout(() => {
849
- void refresh();
850
+ void refresh(true);
850
851
  }, RETRY_DELAY_MS);
851
852
  });
852
853
  }
@@ -855,10 +856,10 @@ function SessionProvider({ config, children }) {
855
856
  const msRemaining = expiresAtRef.current - Date.now();
856
857
  if (refreshTimer) clearTimeout(refreshTimer);
857
858
  if (msRemaining <= 0) {
858
- void refresh();
859
+ void refresh(true);
859
860
  } else {
860
861
  refreshTimer = setTimeout(() => {
861
- void refresh();
862
+ void refresh(true);
862
863
  }, msRemaining * 0.8);
863
864
  }
864
865
  });
@@ -7424,24 +7425,17 @@ function RootNavigator() {
7424
7425
  border: tokens.border
7425
7426
  }
7426
7427
  }), [mode, tokens]);
7427
- return (
7428
- // ForumKit is embedded inside a host app's own component tree, which in
7429
- // virtually every real RN app already has its own NavigationContainer at
7430
- // its root (see fix commit for the psos-app crash this addresses:
7431
- // "Looks like you have nested a 'NavigationContainer' inside another").
7432
- // NavigationIndependentTree marks this container as deliberately
7433
- // self-contained — its own back stack, its own everything, no state
7434
- // shared with (or visible to) whatever navigator the host already has.
7435
- /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(import_native11.NavigationIndependentTree, { children: /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(import_native11.NavigationContainer, { theme: navTheme, children: /* @__PURE__ */ (0, import_jsx_runtime49.jsxs)(Stack.Navigator, { screenOptions: { headerShown: false, statusBarTranslucent: true }, children: [
7436
- /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(Stack.Screen, { name: "Feed", component: FeedScreen }),
7437
- /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(Stack.Screen, { name: "Thread", component: ThreadScreen, options: { animation: "none" } }),
7438
- /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(Stack.Screen, { name: "Profile", component: ProfileScreen }),
7439
- /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(Stack.Screen, { name: "Search", component: SearchScreen }),
7440
- /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(Stack.Screen, { name: "SearchInput", component: SearchInputScreen, options: { headerShown: false } }),
7441
- /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(Stack.Screen, { name: "AskResult", component: AskResultScreen, options: { headerShown: false } }),
7442
- /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(Stack.Screen, { name: "Moderation", component: ModerationScreen })
7443
- ] }) }) })
7444
- );
7428
+ const containerProps = { theme: navTheme, independent: true };
7429
+ const container = /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(import_native11.NavigationContainer, { ...containerProps, children: /* @__PURE__ */ (0, import_jsx_runtime49.jsxs)(Stack.Navigator, { screenOptions: { headerShown: false, statusBarTranslucent: true }, children: [
7430
+ /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(Stack.Screen, { name: "Feed", component: FeedScreen }),
7431
+ /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(Stack.Screen, { name: "Thread", component: ThreadScreen, options: { animation: "none" } }),
7432
+ /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(Stack.Screen, { name: "Profile", component: ProfileScreen }),
7433
+ /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(Stack.Screen, { name: "Search", component: SearchScreen }),
7434
+ /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(Stack.Screen, { name: "SearchInput", component: SearchInputScreen, options: { headerShown: false } }),
7435
+ /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(Stack.Screen, { name: "AskResult", component: AskResultScreen, options: { headerShown: false } }),
7436
+ /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(Stack.Screen, { name: "Moderation", component: ModerationScreen })
7437
+ ] }) });
7438
+ return import_native11.NavigationIndependentTree ? /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(import_native11.NavigationIndependentTree, { children: container }) : container;
7445
7439
  }
7446
7440
 
7447
7441
  // src/ForumKit.tsx