@rebasepro/client-firebase 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.umd.js CHANGED
@@ -19,9 +19,7 @@
19
19
  const [userRoles, _setUserRoles] = React.useState();
20
20
  const [extra, setExtra] = React.useState();
21
21
  const setUserRoles = React.useCallback((roles) => {
22
- const currentRoleIds = userRoles?.map((r) => r.id);
23
- const newRoleIds = roles?.map((r_0) => r_0.id);
24
- if (!fastEquals.deepEqual(currentRoleIds, newRoleIds)) {
22
+ if (!fastEquals.deepEqual(userRoles, roles)) {
25
23
  _setUserRoles(roles);
26
24
  }
27
25
  }, [userRoles]);
@@ -209,8 +207,7 @@
209
207
  }, []);
210
208
  const firebaseUserWrapper = loggedUser ? {
211
209
  ...loggedUser,
212
- roles: userRoles?.map((r_1) => r_1.id),
213
- // User.roles is string[], keep Role[] internally only
210
+ roles: userRoles,
214
211
  firebaseUser: loggedUser
215
212
  } : null;
216
213
  return {
@@ -336,7 +333,7 @@
336
333
  const blob = await response.blob();
337
334
  return new File([blob], path);
338
335
  } catch (e) {
339
- if (e?.code === "storage/object-not-found") return null;
336
+ if (typeof e === "object" && e !== null && "code" in e && e.code === "storage/object-not-found") return null;
340
337
  throw e;
341
338
  }
342
339
  },
@@ -368,7 +365,7 @@
368
365
  urlsCache[storagePathOrUrl] = result;
369
366
  return result;
370
367
  } catch (e) {
371
- if (e?.code === "storage/object-not-found") return {
368
+ if (typeof e === "object" && e !== null && "code" in e && e.code === "storage/object-not-found") return {
372
369
  url: null,
373
370
  fileNotFound: true
374
371
  };
@@ -427,7 +424,7 @@
427
424
  setFirebaseApp(initialisedFirebaseApp);
428
425
  } catch (e) {
429
426
  console.error("Error initialising Firebase", e);
430
- setConfigError(hostingError + "\n" + (e.message ?? JSON.stringify(e)));
427
+ setConfigError(hostingError + "\n" + (e instanceof Error ? e.message : JSON.stringify(e)));
431
428
  }
432
429
  }, [name]);
433
430
  React.useEffect(() => {
@@ -496,7 +493,7 @@
496
493
  }
497
494
  } catch (e) {
498
495
  console.error("App Check error:", e);
499
- setError(e.message);
496
+ setError(e instanceof Error ? e.message : String(e));
500
497
  }
501
498
  }, [options?.forceRefresh]);
502
499
  React.useEffect(() => {
@@ -852,7 +849,7 @@
852
849
  }
853
850
  } catch (error) {
854
851
  console.error("Failed to get search config from extension:", error);
855
- throw new Error(`Failed to initialize Rebase Search. Make sure the rebase-search extension is installed and configured. Error: ${error.message || error}`);
852
+ throw new Error(`Failed to initialize Rebase Search. Make sure the rebase-search extension is installed and configured. Error: ${error instanceof Error ? error.message : String(error)}`);
856
853
  }
857
854
  }
858
855
  if (!searchConfig) {
@@ -933,7 +930,7 @@
933
930
  schemaCache.set(collectionName, stringFields);
934
931
  return stringFields;
935
932
  } catch (error) {
936
- if (error.httpStatus === 404) {
933
+ if (error instanceof Error && "httpStatus" in error && error.httpStatus === 404) {
937
934
  throw new Error(`Collection "${collectionName}" not found in Typesense. Make sure the collection has been indexed. Try running the backfill function.`);
938
935
  }
939
936
  throw error;
@@ -973,7 +970,7 @@
973
970
  const ids = result.hits?.map((hit) => hit.document.id) ?? [];
974
971
  return ids;
975
972
  } catch (error) {
976
- const message = error.message || error.toString();
973
+ const message = error instanceof Error ? error.message : String(error);
977
974
  throw new Error(`Search failed: ${message}`);
978
975
  }
979
976
  };
@@ -1398,13 +1395,13 @@
1398
1395
  };
1399
1396
  function firestoreToCMSModel(data) {
1400
1397
  if (data === null || data === void 0) return null;
1401
- if (firestore.deleteField().isEqual(data)) {
1398
+ if (typeof data === "object" && data !== null && "isEqual" in data && typeof data.isEqual === "function" && firestore.deleteField().isEqual(data)) {
1402
1399
  return void 0;
1403
1400
  }
1404
- if (firestore.serverTimestamp().isEqual(data)) {
1401
+ if (typeof data === "object" && data !== null && "isEqual" in data && typeof data.isEqual === "function" && firestore.serverTimestamp().isEqual(data)) {
1405
1402
  return null;
1406
1403
  }
1407
- if (data instanceof firestore.Timestamp || typeof data.toDate === "function" && data.toDate() instanceof Date) {
1404
+ if (data instanceof firestore.Timestamp || typeof data === "object" && data !== null && "toDate" in data && typeof data.toDate === "function" && data.toDate() instanceof Date) {
1408
1405
  return data.toDate();
1409
1406
  }
1410
1407
  if (data instanceof Date) {
@@ -1413,7 +1410,7 @@
1413
1410
  if (typeof data === "object" && "__type__" in data && data.__type__ === "__vector__") {
1414
1411
  return data;
1415
1412
  }
1416
- if (data instanceof firestore.VectorValue || typeof data === "object" && data !== null && typeof data.toArray === "function" && data.constructor?.name === "VectorValue") {
1413
+ if (data instanceof firestore.VectorValue || typeof data === "object" && data !== null && "toArray" in data && typeof data.toArray === "function" && data.constructor?.name === "VectorValue") {
1417
1414
  return {
1418
1415
  __type__: "__vector__",
1419
1416
  value: data.toArray()
@@ -1455,11 +1452,13 @@
1455
1452
  return null;
1456
1453
  } else if (Array.isArray(data)) {
1457
1454
  return data.filter((v) => v !== void 0).map((v) => cmsToFirestoreModel(v, firestore$1, true));
1458
- } else if (data.isEntityReference && data.isEntityReference()) {
1459
- const targetFirestore = data.databaseId ? firestore.getFirestore(firestore$1.app, data.databaseId) : firestore$1;
1460
- return firestore.doc(targetFirestore, data.path, data.id);
1461
- } else if (data && typeof data === "object" && data.__type === "relation" && data.path && data.id) {
1462
- return firestore.doc(firestore$1, data.path, String(data.id));
1455
+ } else if (typeof data === "object" && data !== null && "isEntityReference" in data && typeof data.isEntityReference === "function" && data.isEntityReference()) {
1456
+ const entityRef = data;
1457
+ const targetFirestore = entityRef.databaseId ? firestore.getFirestore(firestore$1.app, entityRef.databaseId) : firestore$1;
1458
+ return firestore.doc(targetFirestore, entityRef.path, entityRef.id);
1459
+ } else if (data && typeof data === "object" && "__type" in data && data.__type === "relation" && "path" in data && "id" in data) {
1460
+ const rel = data;
1461
+ return firestore.doc(firestore$1, rel.path, String(rel.id));
1463
1462
  } else if (data instanceof types.GeoPoint) {
1464
1463
  return new firestore.GeoPoint(data.latitude, data.longitude);
1465
1464
  } else if (data instanceof Date) {
@@ -1790,8 +1789,9 @@
1790
1789
  return null;
1791
1790
  } else if (Array.isArray(data)) {
1792
1791
  return data.filter((v) => v !== void 0).map((v) => cmsToRTDBModel(v, database$1));
1793
- } else if (data.isEntityReference && data.isEntityReference()) {
1794
- return database.ref(database$1, `${data.slug}/${data.id}`);
1792
+ } else if (typeof data === "object" && data !== null && "isEntityReference" in data && typeof data.isEntityReference === "function" && data.isEntityReference()) {
1793
+ const entityRef = data;
1794
+ return database.ref(database$1, `${entityRef.slug}/${entityRef.id}`);
1795
1795
  } else if (data instanceof Date) {
1796
1796
  return data.toISOString();
1797
1797
  } else if (data && typeof data === "object") {
@@ -1836,8 +1836,7 @@
1836
1836
  roles: rolesProp,
1837
1837
  usersPath = "__FIRECMS/config/users",
1838
1838
  rolesPath = "__FIRECMS/config/roles",
1839
- allowDefaultRolesCreation,
1840
- includeCollectionConfigPermissions
1839
+ allowDefaultRolesCreation
1841
1840
  }) {
1842
1841
  if (!authController) {
1843
1842
  throw Error("useBuildUserManagement: You need to provide an authController since version 3.0.0-beta.11. Check https://firecms.co/docs/pro/migrating_from_v3_beta");
@@ -1881,7 +1880,7 @@
1881
1880
  onError(e_0) {
1882
1881
  setRoles([]);
1883
1882
  console.error("Error loading roles", e_0);
1884
- setRolesError(e_0);
1883
+ setRolesError(e_0 instanceof Error ? e_0 : new Error(String(e_0)));
1885
1884
  setRolesLoading(false);
1886
1885
  }
1887
1886
  });
@@ -1913,7 +1912,7 @@
1913
1912
  onError(e_2) {
1914
1913
  console.error("Error loading users", e_2);
1915
1914
  setUsersWithRoleIds([]);
1916
- setUsersError(e_2);
1915
+ setUsersError(e_2 instanceof Error ? e_2 : new Error(String(e_2)));
1917
1916
  setUsersLoading(false);
1918
1917
  }
1919
1918
  });
@@ -2007,9 +2006,9 @@
2007
2006
  if (!usersWithRoleIds) throw Error("Users not loaded");
2008
2007
  const mgmtUser = usersWithRoleIds.find((u_1) => u_1.email?.toLowerCase() === user_1?.email?.toLowerCase());
2009
2008
  if (!mgmtUser || !mgmtUser.roles) return void 0;
2010
- return roles.filter((r) => mgmtUser.roles.includes(r.id));
2011
- }, [roles, usersWithRoleIds]);
2012
- const authenticator = React.useCallback(({
2009
+ return mgmtUser.roles;
2010
+ }, [usersWithRoleIds]);
2011
+ const accessGate = React.useCallback(({
2013
2012
  user: user_2
2014
2013
  }) => {
2015
2014
  if (loading) {
@@ -2048,8 +2047,8 @@
2048
2047
  throw Error("Could not find a user with the provided email in the user management system.");
2049
2048
  }, [loading, users]);
2050
2049
  const userRoles = authController.user ? defineRolesFor(authController.user) : void 0;
2051
- const isAdmin = (userRoles ?? []).some((r_0) => r_0.id === "admin");
2052
- const userRoleIds = userRoles?.map((r_1) => r_1.id);
2050
+ const isAdmin = (userRoles ?? []).some((r) => r === "admin");
2051
+ const userRoleIds = userRoles;
2053
2052
  React.useEffect(() => {
2054
2053
  console.debug("Setting user roles", {
2055
2054
  userRoles,
@@ -2074,9 +2073,8 @@
2074
2073
  usersError,
2075
2074
  isAdmin,
2076
2075
  allowDefaultRolesCreation: allowDefaultRolesCreation === void 0 ? true : allowDefaultRolesCreation,
2077
- includeCollectionConfigPermissions: Boolean(includeCollectionConfigPermissions),
2078
2076
  defineRolesFor,
2079
- authenticator,
2077
+ accessGate,
2080
2078
  ...authController,
2081
2079
  initialLoading: authController.initialLoading || loading,
2082
2080
  userRoles,
@@ -2092,8 +2090,8 @@
2092
2090
  const data = doc.values;
2093
2091
  const record = data;
2094
2092
  const newVar = {
2095
- uid: doc.id,
2096
2093
  ...data,
2094
+ uid: doc.id,
2097
2095
  created_on: record.created_on,
2098
2096
  updated_on: record.updated_on
2099
2097
  };
@@ -2106,6 +2104,128 @@
2106
2104
  ...doc.values
2107
2105
  }));
2108
2106
  };
2107
+ function useFirebaseAccessGate(t0) {
2108
+ const $ = reactCompilerRuntime.c(17);
2109
+ const {
2110
+ disabled,
2111
+ authController,
2112
+ accessGate,
2113
+ storageSource,
2114
+ data
2115
+ } = t0;
2116
+ const gateEnabled = Boolean(accessGate);
2117
+ const [authLoading, setAuthLoading] = React.useState(gateEnabled);
2118
+ const [notAllowedError, setNotAllowedError] = React.useState(false);
2119
+ const [authVerified, setAuthVerified] = React.useState(!gateEnabled || Boolean(authController.loginSkipped));
2120
+ const canAccessMainView = authVerified && (!gateEnabled || Boolean(authController.user) || Boolean(authController.loginSkipped)) && !notAllowedError;
2121
+ let t1;
2122
+ let t2;
2123
+ if ($[0] !== authController.loginSkipped) {
2124
+ t1 = () => {
2125
+ if (authController.loginSkipped) {
2126
+ setAuthVerified(true);
2127
+ }
2128
+ };
2129
+ t2 = [authController.loginSkipped];
2130
+ $[0] = authController.loginSkipped;
2131
+ $[1] = t1;
2132
+ $[2] = t2;
2133
+ } else {
2134
+ t1 = $[1];
2135
+ t2 = $[2];
2136
+ }
2137
+ React.useEffect(t1, t2);
2138
+ const checkedUserRef = React.useRef(void 0);
2139
+ let t3;
2140
+ if ($[3] !== accessGate || $[4] !== authController || $[5] !== data || $[6] !== disabled || $[7] !== storageSource) {
2141
+ t3 = async () => {
2142
+ if (disabled) {
2143
+ return;
2144
+ }
2145
+ if (authController.initialLoading) {
2146
+ return;
2147
+ }
2148
+ if (!authController.user && !authController.loginSkipped) {
2149
+ checkedUserRef.current = void 0;
2150
+ setAuthLoading(false);
2151
+ setAuthVerified(false);
2152
+ return;
2153
+ }
2154
+ const delegateUser = authController.user;
2155
+ if (accessGate instanceof Function && delegateUser && !fastEquals.deepEqual(checkedUserRef.current?.uid, delegateUser.uid)) {
2156
+ setAuthLoading(true);
2157
+ try {
2158
+ const allowed = await accessGate({
2159
+ user: delegateUser,
2160
+ authController,
2161
+ data,
2162
+ storageSource
2163
+ });
2164
+ if (!allowed) {
2165
+ authController.signOut();
2166
+ setNotAllowedError(true);
2167
+ }
2168
+ } catch (t42) {
2169
+ const e = t42;
2170
+ setNotAllowedError(e);
2171
+ authController.signOut();
2172
+ }
2173
+ setAuthLoading(false);
2174
+ setAuthVerified(true);
2175
+ checkedUserRef.current = delegateUser;
2176
+ } else {
2177
+ setAuthLoading(false);
2178
+ }
2179
+ if (!authController.initialLoading && !delegateUser) {
2180
+ setAuthVerified(true);
2181
+ }
2182
+ };
2183
+ $[3] = accessGate;
2184
+ $[4] = authController;
2185
+ $[5] = data;
2186
+ $[6] = disabled;
2187
+ $[7] = storageSource;
2188
+ $[8] = t3;
2189
+ } else {
2190
+ t3 = $[8];
2191
+ }
2192
+ const checkAccess = t3;
2193
+ let t4;
2194
+ let t5;
2195
+ if ($[9] !== checkAccess) {
2196
+ t4 = () => {
2197
+ checkAccess();
2198
+ };
2199
+ t5 = [checkAccess];
2200
+ $[9] = checkAccess;
2201
+ $[10] = t4;
2202
+ $[11] = t5;
2203
+ } else {
2204
+ t4 = $[10];
2205
+ t5 = $[11];
2206
+ }
2207
+ React.useEffect(t4, t5);
2208
+ let t6;
2209
+ const t7 = gateEnabled && authLoading;
2210
+ let t8;
2211
+ if ($[12] !== authVerified || $[13] !== canAccessMainView || $[14] !== notAllowedError || $[15] !== t7) {
2212
+ t8 = {
2213
+ canAccessMainView,
2214
+ authLoading: t7,
2215
+ notAllowedError,
2216
+ authVerified
2217
+ };
2218
+ $[12] = authVerified;
2219
+ $[13] = canAccessMainView;
2220
+ $[14] = notAllowedError;
2221
+ $[15] = t7;
2222
+ $[16] = t8;
2223
+ } else {
2224
+ t8 = $[16];
2225
+ }
2226
+ t6 = t8;
2227
+ return t6;
2228
+ }
2109
2229
  const googleIcon = (mode) => /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: /* @__PURE__ */ jsxRuntime.jsxs("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 64 64", width: 24, height: 24, children: [
2110
2230
  /* @__PURE__ */ jsxRuntime.jsxs("linearGradient", { id: "95yY7w43Oj6n2vH63j6HJb", x1: "29.401", x2: "29.401", y1: "4.064", y2: "106.734", gradientTransform: "matrix(1 0 0 -1 0 66)", gradientUnits: "userSpaceOnUse", children: [
2111
2231
  /* @__PURE__ */ jsxRuntime.jsx("stop", { offset: "0", stopColor: "#ff5840" }),
@@ -2237,7 +2357,7 @@
2237
2357
  } else if (notAllowedError instanceof Error) {
2238
2358
  notAllowedMessage = notAllowedError.message;
2239
2359
  } else {
2240
- notAllowedMessage = "It looks like you don't have access to the CMS, based on the specified Authenticator configuration";
2360
+ notAllowedMessage = "It looks like you don't have access to the CMS, based on the specified access gate configuration";
2241
2361
  }
2242
2362
  }
2243
2363
  const fadeStyle = {
@@ -2624,7 +2744,7 @@
2624
2744
  name,
2625
2745
  logo,
2626
2746
  logoDark,
2627
- authenticator,
2747
+ accessGate,
2628
2748
  collections,
2629
2749
  views,
2630
2750
  adminViews,
@@ -2752,15 +2872,15 @@
2752
2872
  t10 = $[21];
2753
2873
  }
2754
2874
  let t11;
2755
- if ($[22] !== authController || $[23] !== authenticator || $[24] !== storageSource || $[25] !== t10) {
2875
+ if ($[22] !== accessGate || $[23] !== authController || $[24] !== storageSource || $[25] !== t10) {
2756
2876
  t11 = {
2757
2877
  authController,
2758
- authenticator,
2878
+ accessGate,
2759
2879
  data: t10,
2760
2880
  storageSource
2761
2881
  };
2762
- $[22] = authController;
2763
- $[23] = authenticator;
2882
+ $[22] = accessGate;
2883
+ $[23] = authController;
2764
2884
  $[24] = storageSource;
2765
2885
  $[25] = t10;
2766
2886
  $[26] = t11;
@@ -2771,7 +2891,7 @@
2771
2891
  authLoading,
2772
2892
  canAccessMainView,
2773
2893
  notAllowedError
2774
- } = core.useValidateAuthenticator(t11);
2894
+ } = useFirebaseAccessGate(t11);
2775
2895
  let t12;
2776
2896
  if ($[27] !== userConfigPersistence) {
2777
2897
  t12 = {
@@ -2899,7 +3019,7 @@
2899
3019
  const usedLogo = modeController.mode === "dark" && logoDark ? logoDark : logo;
2900
3020
  if (!canAccessMainView) {
2901
3021
  const LoginViewUsed = components?.LoginView ?? FirebaseLoginView;
2902
- component = /* @__PURE__ */ jsxRuntime.jsx(LoginViewUsed, { logo: usedLogo, allowSkipLogin, signInOptions: signInOptions ?? DEFAULT_SIGN_IN_OPTIONS, firebaseApp, authController, notAllowedError });
3022
+ component = /* @__PURE__ */ jsxRuntime.jsx(LoginViewUsed, { logo: usedLogo, allowSkipLogin, signInOptions: signInOptions ?? DEFAULT_SIGN_IN_OPTIONS, firebaseApp, authController, notAllowedError: notAllowedError instanceof Error ? notAllowedError : typeof notAllowedError === "string" ? notAllowedError : void 0 });
2903
3023
  } else {
2904
3024
  const firstCollectionEntry = navigationStateController.topLevelNavigation?.navigationEntries.find(_temp3);
2905
3025
  const fallbackRoute = firstCollectionEntry ? /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Navigate, { to: urlController.buildUrlCollectionPath(firstCollectionEntry.id), replace: true }) : /* @__PURE__ */ jsxRuntime.jsx(ui.CenteredView, { children: "No home page or collections provided." });
@@ -3033,6 +3153,7 @@
3033
3153
  exports2.performPineconeTextSearch = performPineconeTextSearch;
3034
3154
  exports2.useAppCheck = useAppCheck;
3035
3155
  exports2.useBuildUserManagement = useBuildUserManagement;
3156
+ exports2.useFirebaseAccessGate = useFirebaseAccessGate;
3036
3157
  exports2.useFirebaseAuthController = useFirebaseAuthController;
3037
3158
  exports2.useFirebaseRTDBDelegate = useFirebaseRTDBDelegate;
3038
3159
  exports2.useFirebaseStorageSource = useFirebaseStorageSource;