@rebasepro/client-firebase 0.2.1 → 0.2.4

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
@@ -336,7 +336,7 @@
336
336
  const blob = await response.blob();
337
337
  return new File([blob], path);
338
338
  } catch (e) {
339
- if (e?.code === "storage/object-not-found") return null;
339
+ if (typeof e === "object" && e !== null && "code" in e && e.code === "storage/object-not-found") return null;
340
340
  throw e;
341
341
  }
342
342
  },
@@ -368,7 +368,7 @@
368
368
  urlsCache[storagePathOrUrl] = result;
369
369
  return result;
370
370
  } catch (e) {
371
- if (e?.code === "storage/object-not-found") return {
371
+ if (typeof e === "object" && e !== null && "code" in e && e.code === "storage/object-not-found") return {
372
372
  url: null,
373
373
  fileNotFound: true
374
374
  };
@@ -427,7 +427,7 @@
427
427
  setFirebaseApp(initialisedFirebaseApp);
428
428
  } catch (e) {
429
429
  console.error("Error initialising Firebase", e);
430
- setConfigError(hostingError + "\n" + (e.message ?? JSON.stringify(e)));
430
+ setConfigError(hostingError + "\n" + (e instanceof Error ? e.message : JSON.stringify(e)));
431
431
  }
432
432
  }, [name]);
433
433
  React.useEffect(() => {
@@ -496,7 +496,7 @@
496
496
  }
497
497
  } catch (e) {
498
498
  console.error("App Check error:", e);
499
- setError(e.message);
499
+ setError(e instanceof Error ? e.message : String(e));
500
500
  }
501
501
  }, [options?.forceRefresh]);
502
502
  React.useEffect(() => {
@@ -852,7 +852,7 @@
852
852
  }
853
853
  } catch (error) {
854
854
  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}`);
855
+ 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
856
  }
857
857
  }
858
858
  if (!searchConfig) {
@@ -933,7 +933,7 @@
933
933
  schemaCache.set(collectionName, stringFields);
934
934
  return stringFields;
935
935
  } catch (error) {
936
- if (error.httpStatus === 404) {
936
+ if (error instanceof Error && "httpStatus" in error && error.httpStatus === 404) {
937
937
  throw new Error(`Collection "${collectionName}" not found in Typesense. Make sure the collection has been indexed. Try running the backfill function.`);
938
938
  }
939
939
  throw error;
@@ -973,7 +973,7 @@
973
973
  const ids = result.hits?.map((hit) => hit.document.id) ?? [];
974
974
  return ids;
975
975
  } catch (error) {
976
- const message = error.message || error.toString();
976
+ const message = error instanceof Error ? error.message : String(error);
977
977
  throw new Error(`Search failed: ${message}`);
978
978
  }
979
979
  };
@@ -1398,13 +1398,13 @@
1398
1398
  };
1399
1399
  function firestoreToCMSModel(data) {
1400
1400
  if (data === null || data === void 0) return null;
1401
- if (firestore.deleteField().isEqual(data)) {
1401
+ if (typeof data === "object" && data !== null && "isEqual" in data && typeof data.isEqual === "function" && firestore.deleteField().isEqual(data)) {
1402
1402
  return void 0;
1403
1403
  }
1404
- if (firestore.serverTimestamp().isEqual(data)) {
1404
+ if (typeof data === "object" && data !== null && "isEqual" in data && typeof data.isEqual === "function" && firestore.serverTimestamp().isEqual(data)) {
1405
1405
  return null;
1406
1406
  }
1407
- if (data instanceof firestore.Timestamp || typeof data.toDate === "function" && data.toDate() instanceof Date) {
1407
+ if (data instanceof firestore.Timestamp || typeof data === "object" && data !== null && "toDate" in data && typeof data.toDate === "function" && data.toDate() instanceof Date) {
1408
1408
  return data.toDate();
1409
1409
  }
1410
1410
  if (data instanceof Date) {
@@ -1413,7 +1413,7 @@
1413
1413
  if (typeof data === "object" && "__type__" in data && data.__type__ === "__vector__") {
1414
1414
  return data;
1415
1415
  }
1416
- if (data instanceof firestore.VectorValue || typeof data === "object" && data !== null && typeof data.toArray === "function" && data.constructor?.name === "VectorValue") {
1416
+ if (data instanceof firestore.VectorValue || typeof data === "object" && data !== null && "toArray" in data && typeof data.toArray === "function" && data.constructor?.name === "VectorValue") {
1417
1417
  return {
1418
1418
  __type__: "__vector__",
1419
1419
  value: data.toArray()
@@ -1455,11 +1455,13 @@
1455
1455
  return null;
1456
1456
  } else if (Array.isArray(data)) {
1457
1457
  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));
1458
+ } else if (typeof data === "object" && data !== null && "isEntityReference" in data && typeof data.isEntityReference === "function" && data.isEntityReference()) {
1459
+ const entityRef = data;
1460
+ const targetFirestore = entityRef.databaseId ? firestore.getFirestore(firestore$1.app, entityRef.databaseId) : firestore$1;
1461
+ return firestore.doc(targetFirestore, entityRef.path, entityRef.id);
1462
+ } else if (data && typeof data === "object" && "__type" in data && data.__type === "relation" && "path" in data && "id" in data) {
1463
+ const rel = data;
1464
+ return firestore.doc(firestore$1, rel.path, String(rel.id));
1463
1465
  } else if (data instanceof types.GeoPoint) {
1464
1466
  return new firestore.GeoPoint(data.latitude, data.longitude);
1465
1467
  } else if (data instanceof Date) {
@@ -1790,8 +1792,9 @@
1790
1792
  return null;
1791
1793
  } else if (Array.isArray(data)) {
1792
1794
  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}`);
1795
+ } else if (typeof data === "object" && data !== null && "isEntityReference" in data && typeof data.isEntityReference === "function" && data.isEntityReference()) {
1796
+ const entityRef = data;
1797
+ return database.ref(database$1, `${entityRef.slug}/${entityRef.id}`);
1795
1798
  } else if (data instanceof Date) {
1796
1799
  return data.toISOString();
1797
1800
  } else if (data && typeof data === "object") {
@@ -1836,8 +1839,7 @@
1836
1839
  roles: rolesProp,
1837
1840
  usersPath = "__FIRECMS/config/users",
1838
1841
  rolesPath = "__FIRECMS/config/roles",
1839
- allowDefaultRolesCreation,
1840
- includeCollectionConfigPermissions
1842
+ allowDefaultRolesCreation
1841
1843
  }) {
1842
1844
  if (!authController) {
1843
1845
  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 +1883,7 @@
1881
1883
  onError(e_0) {
1882
1884
  setRoles([]);
1883
1885
  console.error("Error loading roles", e_0);
1884
- setRolesError(e_0);
1886
+ setRolesError(e_0 instanceof Error ? e_0 : new Error(String(e_0)));
1885
1887
  setRolesLoading(false);
1886
1888
  }
1887
1889
  });
@@ -1913,7 +1915,7 @@
1913
1915
  onError(e_2) {
1914
1916
  console.error("Error loading users", e_2);
1915
1917
  setUsersWithRoleIds([]);
1916
- setUsersError(e_2);
1918
+ setUsersError(e_2 instanceof Error ? e_2 : new Error(String(e_2)));
1917
1919
  setUsersLoading(false);
1918
1920
  }
1919
1921
  });
@@ -2009,7 +2011,7 @@
2009
2011
  if (!mgmtUser || !mgmtUser.roles) return void 0;
2010
2012
  return roles.filter((r) => mgmtUser.roles.includes(r.id));
2011
2013
  }, [roles, usersWithRoleIds]);
2012
- const authenticator = React.useCallback(({
2014
+ const accessGate = React.useCallback(({
2013
2015
  user: user_2
2014
2016
  }) => {
2015
2017
  if (loading) {
@@ -2074,9 +2076,8 @@
2074
2076
  usersError,
2075
2077
  isAdmin,
2076
2078
  allowDefaultRolesCreation: allowDefaultRolesCreation === void 0 ? true : allowDefaultRolesCreation,
2077
- includeCollectionConfigPermissions: Boolean(includeCollectionConfigPermissions),
2078
2079
  defineRolesFor,
2079
- authenticator,
2080
+ accessGate,
2080
2081
  ...authController,
2081
2082
  initialLoading: authController.initialLoading || loading,
2082
2083
  userRoles,
@@ -2092,8 +2093,8 @@
2092
2093
  const data = doc.values;
2093
2094
  const record = data;
2094
2095
  const newVar = {
2095
- uid: doc.id,
2096
2096
  ...data,
2097
+ uid: doc.id,
2097
2098
  created_on: record.created_on,
2098
2099
  updated_on: record.updated_on
2099
2100
  };
@@ -2106,6 +2107,128 @@
2106
2107
  ...doc.values
2107
2108
  }));
2108
2109
  };
2110
+ function useFirebaseAccessGate(t0) {
2111
+ const $ = reactCompilerRuntime.c(17);
2112
+ const {
2113
+ disabled,
2114
+ authController,
2115
+ accessGate,
2116
+ storageSource,
2117
+ data
2118
+ } = t0;
2119
+ const gateEnabled = Boolean(accessGate);
2120
+ const [authLoading, setAuthLoading] = React.useState(gateEnabled);
2121
+ const [notAllowedError, setNotAllowedError] = React.useState(false);
2122
+ const [authVerified, setAuthVerified] = React.useState(!gateEnabled || Boolean(authController.loginSkipped));
2123
+ const canAccessMainView = authVerified && (!gateEnabled || Boolean(authController.user) || Boolean(authController.loginSkipped)) && !notAllowedError;
2124
+ let t1;
2125
+ let t2;
2126
+ if ($[0] !== authController.loginSkipped) {
2127
+ t1 = () => {
2128
+ if (authController.loginSkipped) {
2129
+ setAuthVerified(true);
2130
+ }
2131
+ };
2132
+ t2 = [authController.loginSkipped];
2133
+ $[0] = authController.loginSkipped;
2134
+ $[1] = t1;
2135
+ $[2] = t2;
2136
+ } else {
2137
+ t1 = $[1];
2138
+ t2 = $[2];
2139
+ }
2140
+ React.useEffect(t1, t2);
2141
+ const checkedUserRef = React.useRef(void 0);
2142
+ let t3;
2143
+ if ($[3] !== accessGate || $[4] !== authController || $[5] !== data || $[6] !== disabled || $[7] !== storageSource) {
2144
+ t3 = async () => {
2145
+ if (disabled) {
2146
+ return;
2147
+ }
2148
+ if (authController.initialLoading) {
2149
+ return;
2150
+ }
2151
+ if (!authController.user && !authController.loginSkipped) {
2152
+ checkedUserRef.current = void 0;
2153
+ setAuthLoading(false);
2154
+ setAuthVerified(false);
2155
+ return;
2156
+ }
2157
+ const delegateUser = authController.user;
2158
+ if (accessGate instanceof Function && delegateUser && !fastEquals.deepEqual(checkedUserRef.current?.uid, delegateUser.uid)) {
2159
+ setAuthLoading(true);
2160
+ try {
2161
+ const allowed = await accessGate({
2162
+ user: delegateUser,
2163
+ authController,
2164
+ data,
2165
+ storageSource
2166
+ });
2167
+ if (!allowed) {
2168
+ authController.signOut();
2169
+ setNotAllowedError(true);
2170
+ }
2171
+ } catch (t42) {
2172
+ const e = t42;
2173
+ setNotAllowedError(e);
2174
+ authController.signOut();
2175
+ }
2176
+ setAuthLoading(false);
2177
+ setAuthVerified(true);
2178
+ checkedUserRef.current = delegateUser;
2179
+ } else {
2180
+ setAuthLoading(false);
2181
+ }
2182
+ if (!authController.initialLoading && !delegateUser) {
2183
+ setAuthVerified(true);
2184
+ }
2185
+ };
2186
+ $[3] = accessGate;
2187
+ $[4] = authController;
2188
+ $[5] = data;
2189
+ $[6] = disabled;
2190
+ $[7] = storageSource;
2191
+ $[8] = t3;
2192
+ } else {
2193
+ t3 = $[8];
2194
+ }
2195
+ const checkAccess = t3;
2196
+ let t4;
2197
+ let t5;
2198
+ if ($[9] !== checkAccess) {
2199
+ t4 = () => {
2200
+ checkAccess();
2201
+ };
2202
+ t5 = [checkAccess];
2203
+ $[9] = checkAccess;
2204
+ $[10] = t4;
2205
+ $[11] = t5;
2206
+ } else {
2207
+ t4 = $[10];
2208
+ t5 = $[11];
2209
+ }
2210
+ React.useEffect(t4, t5);
2211
+ let t6;
2212
+ const t7 = gateEnabled && authLoading;
2213
+ let t8;
2214
+ if ($[12] !== authVerified || $[13] !== canAccessMainView || $[14] !== notAllowedError || $[15] !== t7) {
2215
+ t8 = {
2216
+ canAccessMainView,
2217
+ authLoading: t7,
2218
+ notAllowedError,
2219
+ authVerified
2220
+ };
2221
+ $[12] = authVerified;
2222
+ $[13] = canAccessMainView;
2223
+ $[14] = notAllowedError;
2224
+ $[15] = t7;
2225
+ $[16] = t8;
2226
+ } else {
2227
+ t8 = $[16];
2228
+ }
2229
+ t6 = t8;
2230
+ return t6;
2231
+ }
2109
2232
  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
2233
  /* @__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
2234
  /* @__PURE__ */ jsxRuntime.jsx("stop", { offset: "0", stopColor: "#ff5840" }),
@@ -2237,7 +2360,7 @@
2237
2360
  } else if (notAllowedError instanceof Error) {
2238
2361
  notAllowedMessage = notAllowedError.message;
2239
2362
  } else {
2240
- notAllowedMessage = "It looks like you don't have access to the CMS, based on the specified Authenticator configuration";
2363
+ notAllowedMessage = "It looks like you don't have access to the CMS, based on the specified access gate configuration";
2241
2364
  }
2242
2365
  }
2243
2366
  const fadeStyle = {
@@ -2624,7 +2747,7 @@
2624
2747
  name,
2625
2748
  logo,
2626
2749
  logoDark,
2627
- authenticator,
2750
+ accessGate,
2628
2751
  collections,
2629
2752
  views,
2630
2753
  adminViews,
@@ -2752,15 +2875,15 @@
2752
2875
  t10 = $[21];
2753
2876
  }
2754
2877
  let t11;
2755
- if ($[22] !== authController || $[23] !== authenticator || $[24] !== storageSource || $[25] !== t10) {
2878
+ if ($[22] !== accessGate || $[23] !== authController || $[24] !== storageSource || $[25] !== t10) {
2756
2879
  t11 = {
2757
2880
  authController,
2758
- authenticator,
2881
+ accessGate,
2759
2882
  data: t10,
2760
2883
  storageSource
2761
2884
  };
2762
- $[22] = authController;
2763
- $[23] = authenticator;
2885
+ $[22] = accessGate;
2886
+ $[23] = authController;
2764
2887
  $[24] = storageSource;
2765
2888
  $[25] = t10;
2766
2889
  $[26] = t11;
@@ -2771,7 +2894,7 @@
2771
2894
  authLoading,
2772
2895
  canAccessMainView,
2773
2896
  notAllowedError
2774
- } = core.useValidateAuthenticator(t11);
2897
+ } = useFirebaseAccessGate(t11);
2775
2898
  let t12;
2776
2899
  if ($[27] !== userConfigPersistence) {
2777
2900
  t12 = {
@@ -2899,7 +3022,7 @@
2899
3022
  const usedLogo = modeController.mode === "dark" && logoDark ? logoDark : logo;
2900
3023
  if (!canAccessMainView) {
2901
3024
  const LoginViewUsed = components?.LoginView ?? FirebaseLoginView;
2902
- component = /* @__PURE__ */ jsxRuntime.jsx(LoginViewUsed, { logo: usedLogo, allowSkipLogin, signInOptions: signInOptions ?? DEFAULT_SIGN_IN_OPTIONS, firebaseApp, authController, notAllowedError });
3025
+ 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
3026
  } else {
2904
3027
  const firstCollectionEntry = navigationStateController.topLevelNavigation?.navigationEntries.find(_temp3);
2905
3028
  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 +3156,7 @@
3033
3156
  exports2.performPineconeTextSearch = performPineconeTextSearch;
3034
3157
  exports2.useAppCheck = useAppCheck;
3035
3158
  exports2.useBuildUserManagement = useBuildUserManagement;
3159
+ exports2.useFirebaseAccessGate = useFirebaseAccessGate;
3036
3160
  exports2.useFirebaseAuthController = useFirebaseAuthController;
3037
3161
  exports2.useFirebaseRTDBDelegate = useFirebaseRTDBDelegate;
3038
3162
  exports2.useFirebaseStorageSource = useFirebaseStorageSource;