@logickernel/bridge 0.9.0 → 0.9.2

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.
@@ -1188,18 +1188,37 @@ function useNavigation({
1188
1188
  const [loading, setLoading] = useState(false);
1189
1189
  const [error, setError] = useState(null);
1190
1190
  useEffect(() => {
1191
+ if (typeof window !== "undefined" && process.env.NODE_ENV === "development") {
1192
+ console.log("[useNavigation] Hook called:", {
1193
+ enabled,
1194
+ organizationId,
1195
+ apiBaseUrl,
1196
+ willFetch: enabled && !!organizationId
1197
+ });
1198
+ }
1191
1199
  if (!enabled || !organizationId) {
1200
+ if (typeof window !== "undefined" && process.env.NODE_ENV === "development") {
1201
+ console.log("[useNavigation] Skipping fetch:", {
1202
+ reason: !enabled ? "disabled" : "no organizationId",
1203
+ enabled,
1204
+ organizationId
1205
+ });
1206
+ }
1192
1207
  setItems([]);
1193
1208
  setOrganizations([]);
1194
1209
  setUser(null);
1195
1210
  return;
1196
1211
  }
1197
1212
  const fetchNavigation = async () => {
1213
+ const url = `${apiBaseUrl}/navigation/${organizationId}`;
1214
+ if (typeof window !== "undefined" && process.env.NODE_ENV === "development") {
1215
+ console.log("[useNavigation] Fetching navigation:", url);
1216
+ }
1198
1217
  setLoading(true);
1199
1218
  setError(null);
1200
1219
  try {
1201
1220
  const response = await fetch(
1202
- `${apiBaseUrl}/navigation/${organizationId}`,
1221
+ url,
1203
1222
  {
1204
1223
  credentials: "include"
1205
1224
  // Include cookies for auth
@@ -1215,11 +1234,25 @@ function useNavigation({
1215
1234
  throw new Error(`Failed to fetch navigation: ${response.statusText}`);
1216
1235
  }
1217
1236
  const data = await response.json();
1237
+ if (typeof window !== "undefined" && process.env.NODE_ENV === "development") {
1238
+ console.log("[useNavigation] Navigation data received:", {
1239
+ itemsCount: data.items?.length || 0,
1240
+ organizationsCount: data.organizations?.length || 0,
1241
+ hasUser: !!data.user
1242
+ });
1243
+ }
1218
1244
  setItems(data.items || []);
1219
1245
  setOrganizations(data.organizations || []);
1220
1246
  setUser(data.user || null);
1221
1247
  } catch (err) {
1222
1248
  const error2 = err instanceof Error ? err : new Error("Unknown error");
1249
+ if (typeof window !== "undefined" && process.env.NODE_ENV === "development") {
1250
+ console.error("[useNavigation] Fetch error:", {
1251
+ error: error2.message,
1252
+ url,
1253
+ organizationId
1254
+ });
1255
+ }
1223
1256
  setError(error2);
1224
1257
  setItems([]);
1225
1258
  setOrganizations([]);
@@ -1239,21 +1272,69 @@ function AppSidebar({
1239
1272
  ...props
1240
1273
  }) {
1241
1274
  const currentPathname = usePathname();
1242
- const pathSegments = currentPathname.split("/");
1243
- const isAppOrgRoute = currentPathname.startsWith("/app/") && pathSegments.length > 2 && pathSegments[2] !== "user";
1244
- const pathOrgId = isAppOrgRoute ? pathSegments[2] : null;
1275
+ const pathSegments = currentPathname.split("/").filter(Boolean);
1276
+ let pathOrgId = null;
1277
+ if (pathSegments.length >= 2 && pathSegments[0] === "app") {
1278
+ const potentialOrgId = pathSegments[1];
1279
+ if (potentialOrgId && potentialOrgId !== "user") {
1280
+ pathOrgId = potentialOrgId;
1281
+ }
1282
+ } else if (pathSegments.length >= 1) {
1283
+ const potentialOrgId = pathSegments[0];
1284
+ const skipSegments = ["user", "api", "auth", "dashboard", "settings", "app"];
1285
+ if (potentialOrgId && !skipSegments.includes(potentialOrgId)) {
1286
+ if (potentialOrgId.includes("-") || potentialOrgId.length >= 8) {
1287
+ pathOrgId = potentialOrgId;
1288
+ }
1289
+ }
1290
+ }
1291
+ const detectedOrgId = organizationId || pathOrgId || void 0;
1292
+ if (typeof window !== "undefined" && process.env.NODE_ENV === "development") {
1293
+ console.log("[AppSidebar] Debug:", {
1294
+ currentPathname,
1295
+ pathSegments,
1296
+ pathOrgId,
1297
+ organizationId,
1298
+ detectedOrgId,
1299
+ apiBaseUrl
1300
+ });
1301
+ }
1245
1302
  const {
1246
1303
  items: apiNavigationItems,
1247
1304
  organizations: apiOrganizations,
1248
1305
  user: navigationUser,
1249
- loading: navigationLoading
1306
+ loading: navigationLoading,
1307
+ error: navigationError
1250
1308
  } = useNavigation({
1251
- organizationId: organizationId || pathOrgId || void 0,
1309
+ organizationId: detectedOrgId,
1252
1310
  apiBaseUrl,
1253
1311
  enabled: true
1254
1312
  });
1313
+ React2.useEffect(() => {
1314
+ if (process.env.NODE_ENV === "development") {
1315
+ const orgIds = apiOrganizations.map((org) => org.id);
1316
+ const pathOrgIdInList = pathOrgId ? apiOrganizations.some((org) => org.id === pathOrgId) : false;
1317
+ const computedCurrentOrgId = organizationId || (pathOrgId && pathOrgIdInList ? pathOrgId : void 0);
1318
+ console.log("[AppSidebar] Navigation state:", {
1319
+ currentPathname,
1320
+ pathOrgId,
1321
+ organizationId,
1322
+ detectedOrgId,
1323
+ apiBaseUrl,
1324
+ itemsCount: apiNavigationItems.length,
1325
+ organizationsCount: apiOrganizations.length,
1326
+ organizationIds: orgIds,
1327
+ pathOrgIdInList,
1328
+ computedCurrentOrgId,
1329
+ displayItemsCount: computedCurrentOrgId ? apiNavigationItems.length : 0,
1330
+ loading: navigationLoading,
1331
+ error: navigationError?.message,
1332
+ navigationUrl: detectedOrgId ? `${apiBaseUrl}/navigation/${detectedOrgId}` : "N/A"
1333
+ });
1334
+ }
1335
+ }, [currentPathname, pathOrgId, organizationId, detectedOrgId, apiBaseUrl, apiNavigationItems.length, apiOrganizations.length, navigationLoading, navigationError, apiOrganizations, apiNavigationItems]);
1255
1336
  const user = navigationUser || userProp;
1256
- const currentOrgId = organizationId || (pathOrgId && apiOrganizations.some((org) => org.id === pathOrgId) ? pathOrgId : void 0);
1337
+ const currentOrgId = organizationId || (pathOrgId && (apiOrganizations.length === 0 || apiOrganizations.some((org) => org.id === pathOrgId)) ? pathOrgId : void 0) || (detectedOrgId && apiNavigationItems.length > 0 ? detectedOrgId : void 0);
1257
1338
  let navigationItems = apiNavigationItems;
1258
1339
  if (currentOrgId && navigationItems.length > 0) {
1259
1340
  navigationItems = navigationItems.map((item) => ({