@framed-dev/react 0.1.4 → 0.1.6

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.cjs CHANGED
@@ -12341,12 +12341,13 @@ function AuthProvider({
12341
12341
  setIsLoading(true);
12342
12342
  setError(null);
12343
12343
  try {
12344
- if (config.mode === "dev") {
12344
+ const mode = config?.mode ?? "local";
12345
+ if (mode === "dev") {
12345
12346
  setSession(createDevSession());
12346
12347
  setIsLoading(false);
12347
12348
  return;
12348
12349
  }
12349
- if (config.mode === "local") {
12350
+ if (mode === "local") {
12350
12351
  setSession(createLocalSession());
12351
12352
  setIsLoading(false);
12352
12353
  return;
@@ -12363,7 +12364,7 @@ function AuthProvider({
12363
12364
  setIsLoading(false);
12364
12365
  return;
12365
12366
  }
12366
- if (config.mode === "magic_link") {
12367
+ if (mode === "magic_link") {
12367
12368
  const token = new URLSearchParams(window.location.search).get(
12368
12369
  "framed_token"
12369
12370
  );
@@ -12377,7 +12378,7 @@ function AuthProvider({
12377
12378
  }
12378
12379
  }
12379
12380
  }
12380
- if (config.mode === "framed_login") {
12381
+ if (mode === "framed_login") {
12381
12382
  const sessionToken = new URLSearchParams(window.location.search).get(
12382
12383
  "framed_session"
12383
12384
  );
@@ -12396,15 +12397,16 @@ function AuthProvider({
12396
12397
  } finally {
12397
12398
  setIsLoading(false);
12398
12399
  }
12399
- }, [config.mode, projectId, apiKey, supabaseUrl]);
12400
+ }, [config?.mode, projectId, apiKey, supabaseUrl]);
12400
12401
  React40.useEffect(() => {
12401
12402
  initAuth();
12402
12403
  }, [initAuth]);
12403
12404
  const login = React40.useCallback(() => {
12404
- if (config.mode !== "framed_login") return;
12405
+ const mode = config?.mode ?? "local";
12406
+ if (mode !== "framed_login") return;
12405
12407
  const returnUrl = encodeURIComponent(window.location.href);
12406
12408
  window.location.href = `${FRAMED_AUTH_URL}?project=${projectId}&return=${returnUrl}`;
12407
- }, [config.mode, projectId]);
12409
+ }, [config?.mode, projectId]);
12408
12410
  const logout = React40.useCallback(() => {
12409
12411
  if (apiKey && supabaseUrl) {
12410
12412
  const dataLayer = new SyncDataLayer(projectId, { apiKey, supabaseUrl });
@@ -12626,6 +12628,13 @@ var LocalDataLayer = class {
12626
12628
  }
12627
12629
  };
12628
12630
  var CDN_BASE_URL = "https://cdn.framed.dev/widget";
12631
+ var DEFAULT_CONFIG = {
12632
+ mode: "local",
12633
+ projectId: "default",
12634
+ auth: {
12635
+ mode: "local"
12636
+ }
12637
+ };
12629
12638
  var FramedContext = React40.createContext(null);
12630
12639
  var DEFAULT_FEATURES = {
12631
12640
  elementSelect: true,
@@ -12688,14 +12697,16 @@ function FramedProviderInner({ config, children }) {
12688
12697
  }, [config.sync?.supabaseUrl, config.sync?.apiKey]);
12689
12698
  const hasAIFeatures = framedApi.isEnabled;
12690
12699
  const dataLayer = React40.useMemo(() => {
12691
- if (config.mode === "local") {
12692
- return new LocalDataLayer(config.projectId);
12693
- }
12694
- return new SyncDataLayer(config.projectId, {
12695
- apiKey: config.sync?.apiKey || "",
12696
- supabaseUrl: config.sync?.supabaseUrl || ""
12700
+ const mode = config?.mode ?? "local";
12701
+ const projectId = config?.projectId ?? "default";
12702
+ if (mode === "local") {
12703
+ return new LocalDataLayer(projectId);
12704
+ }
12705
+ return new SyncDataLayer(projectId, {
12706
+ apiKey: config?.sync?.apiKey || "",
12707
+ supabaseUrl: config?.sync?.supabaseUrl || ""
12697
12708
  });
12698
- }, [config.mode, config.projectId, config.sync?.apiKey, config.sync?.supabaseUrl]);
12709
+ }, [config?.mode, config?.projectId, config?.sync?.apiKey, config?.sync?.supabaseUrl]);
12699
12710
  React40.useEffect(() => {
12700
12711
  const widgetSource = config.widgetSource || "cdn";
12701
12712
  const widgetVersion = config.widgetVersion || "latest";
@@ -12745,13 +12756,13 @@ function FramedProviderInner({ config, children }) {
12745
12756
  const features = React40.useMemo(
12746
12757
  () => ({
12747
12758
  ...DEFAULT_FEATURES,
12748
- ...config.features
12759
+ ...config?.features
12749
12760
  }),
12750
- [config.features]
12761
+ [config?.features]
12751
12762
  );
12752
12763
  const value = {
12753
12764
  config,
12754
- projectId: config.projectId,
12765
+ projectId: config?.projectId ?? "default",
12755
12766
  isAuthenticated: auth.isAuthenticated,
12756
12767
  session: auth.session,
12757
12768
  isAuthLoading: auth.isLoading,
@@ -12778,14 +12789,22 @@ function FramedProviderInner({ config, children }) {
12778
12789
  return /* @__PURE__ */ jsxRuntime.jsx(FramedContext.Provider, { value, children });
12779
12790
  }
12780
12791
  function FramedProvider({ config, children }) {
12792
+ const mergedConfig = {
12793
+ ...DEFAULT_CONFIG,
12794
+ ...config,
12795
+ auth: {
12796
+ ...DEFAULT_CONFIG.auth,
12797
+ ...config?.auth
12798
+ }
12799
+ };
12781
12800
  return /* @__PURE__ */ jsxRuntime.jsx(
12782
12801
  AuthProvider,
12783
12802
  {
12784
- config: config.auth,
12785
- projectId: config.projectId,
12786
- apiKey: config.sync?.apiKey,
12787
- supabaseUrl: config.sync?.supabaseUrl,
12788
- children: /* @__PURE__ */ jsxRuntime.jsx(FramedProviderInner, { config, children })
12803
+ config: mergedConfig.auth,
12804
+ projectId: mergedConfig.projectId,
12805
+ apiKey: mergedConfig.sync?.apiKey,
12806
+ supabaseUrl: mergedConfig.sync?.supabaseUrl,
12807
+ children: /* @__PURE__ */ jsxRuntime.jsx(FramedProviderInner, { config: mergedConfig, children })
12789
12808
  }
12790
12809
  );
12791
12810
  }