@framed-dev/react 0.1.5 → 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 +41 -22
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +41 -22
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -36,7 +36,7 @@ interface FramedContextValue {
|
|
|
36
36
|
isWidgetReady: boolean;
|
|
37
37
|
}
|
|
38
38
|
interface FramedProviderProps {
|
|
39
|
-
config
|
|
39
|
+
config?: FramedProviderConfig;
|
|
40
40
|
children: ReactNode;
|
|
41
41
|
}
|
|
42
42
|
declare function FramedProvider({ config, children }: FramedProviderProps): react_jsx_runtime.JSX.Element;
|
|
@@ -60,7 +60,7 @@ interface AuthContextValue {
|
|
|
60
60
|
logout: () => void;
|
|
61
61
|
}
|
|
62
62
|
interface AuthProviderProps {
|
|
63
|
-
config
|
|
63
|
+
config?: AuthConfig;
|
|
64
64
|
projectId: string;
|
|
65
65
|
apiKey?: string;
|
|
66
66
|
supabaseUrl?: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -36,7 +36,7 @@ interface FramedContextValue {
|
|
|
36
36
|
isWidgetReady: boolean;
|
|
37
37
|
}
|
|
38
38
|
interface FramedProviderProps {
|
|
39
|
-
config
|
|
39
|
+
config?: FramedProviderConfig;
|
|
40
40
|
children: ReactNode;
|
|
41
41
|
}
|
|
42
42
|
declare function FramedProvider({ config, children }: FramedProviderProps): react_jsx_runtime.JSX.Element;
|
|
@@ -60,7 +60,7 @@ interface AuthContextValue {
|
|
|
60
60
|
logout: () => void;
|
|
61
61
|
}
|
|
62
62
|
interface AuthProviderProps {
|
|
63
|
-
config
|
|
63
|
+
config?: AuthConfig;
|
|
64
64
|
projectId: string;
|
|
65
65
|
apiKey?: string;
|
|
66
66
|
supabaseUrl?: string;
|
package/dist/index.js
CHANGED
|
@@ -12320,12 +12320,13 @@ function AuthProvider({
|
|
|
12320
12320
|
setIsLoading(true);
|
|
12321
12321
|
setError(null);
|
|
12322
12322
|
try {
|
|
12323
|
-
|
|
12323
|
+
const mode = config?.mode ?? "local";
|
|
12324
|
+
if (mode === "dev") {
|
|
12324
12325
|
setSession(createDevSession());
|
|
12325
12326
|
setIsLoading(false);
|
|
12326
12327
|
return;
|
|
12327
12328
|
}
|
|
12328
|
-
if (
|
|
12329
|
+
if (mode === "local") {
|
|
12329
12330
|
setSession(createLocalSession());
|
|
12330
12331
|
setIsLoading(false);
|
|
12331
12332
|
return;
|
|
@@ -12342,7 +12343,7 @@ function AuthProvider({
|
|
|
12342
12343
|
setIsLoading(false);
|
|
12343
12344
|
return;
|
|
12344
12345
|
}
|
|
12345
|
-
if (
|
|
12346
|
+
if (mode === "magic_link") {
|
|
12346
12347
|
const token = new URLSearchParams(window.location.search).get(
|
|
12347
12348
|
"framed_token"
|
|
12348
12349
|
);
|
|
@@ -12356,7 +12357,7 @@ function AuthProvider({
|
|
|
12356
12357
|
}
|
|
12357
12358
|
}
|
|
12358
12359
|
}
|
|
12359
|
-
if (
|
|
12360
|
+
if (mode === "framed_login") {
|
|
12360
12361
|
const sessionToken = new URLSearchParams(window.location.search).get(
|
|
12361
12362
|
"framed_session"
|
|
12362
12363
|
);
|
|
@@ -12375,15 +12376,16 @@ function AuthProvider({
|
|
|
12375
12376
|
} finally {
|
|
12376
12377
|
setIsLoading(false);
|
|
12377
12378
|
}
|
|
12378
|
-
}, [config
|
|
12379
|
+
}, [config?.mode, projectId, apiKey, supabaseUrl]);
|
|
12379
12380
|
useEffect(() => {
|
|
12380
12381
|
initAuth();
|
|
12381
12382
|
}, [initAuth]);
|
|
12382
12383
|
const login = useCallback(() => {
|
|
12383
|
-
|
|
12384
|
+
const mode = config?.mode ?? "local";
|
|
12385
|
+
if (mode !== "framed_login") return;
|
|
12384
12386
|
const returnUrl = encodeURIComponent(window.location.href);
|
|
12385
12387
|
window.location.href = `${FRAMED_AUTH_URL}?project=${projectId}&return=${returnUrl}`;
|
|
12386
|
-
}, [config
|
|
12388
|
+
}, [config?.mode, projectId]);
|
|
12387
12389
|
const logout = useCallback(() => {
|
|
12388
12390
|
if (apiKey && supabaseUrl) {
|
|
12389
12391
|
const dataLayer = new SyncDataLayer(projectId, { apiKey, supabaseUrl });
|
|
@@ -12605,6 +12607,13 @@ var LocalDataLayer = class {
|
|
|
12605
12607
|
}
|
|
12606
12608
|
};
|
|
12607
12609
|
var CDN_BASE_URL = "https://cdn.framed.dev/widget";
|
|
12610
|
+
var DEFAULT_CONFIG = {
|
|
12611
|
+
mode: "local",
|
|
12612
|
+
projectId: "default",
|
|
12613
|
+
auth: {
|
|
12614
|
+
mode: "local"
|
|
12615
|
+
}
|
|
12616
|
+
};
|
|
12608
12617
|
var FramedContext = createContext(null);
|
|
12609
12618
|
var DEFAULT_FEATURES = {
|
|
12610
12619
|
elementSelect: true,
|
|
@@ -12667,14 +12676,16 @@ function FramedProviderInner({ config, children }) {
|
|
|
12667
12676
|
}, [config.sync?.supabaseUrl, config.sync?.apiKey]);
|
|
12668
12677
|
const hasAIFeatures = framedApi.isEnabled;
|
|
12669
12678
|
const dataLayer = useMemo(() => {
|
|
12670
|
-
|
|
12671
|
-
|
|
12672
|
-
|
|
12673
|
-
|
|
12674
|
-
|
|
12675
|
-
|
|
12679
|
+
const mode = config?.mode ?? "local";
|
|
12680
|
+
const projectId = config?.projectId ?? "default";
|
|
12681
|
+
if (mode === "local") {
|
|
12682
|
+
return new LocalDataLayer(projectId);
|
|
12683
|
+
}
|
|
12684
|
+
return new SyncDataLayer(projectId, {
|
|
12685
|
+
apiKey: config?.sync?.apiKey || "",
|
|
12686
|
+
supabaseUrl: config?.sync?.supabaseUrl || ""
|
|
12676
12687
|
});
|
|
12677
|
-
}, [config
|
|
12688
|
+
}, [config?.mode, config?.projectId, config?.sync?.apiKey, config?.sync?.supabaseUrl]);
|
|
12678
12689
|
useEffect(() => {
|
|
12679
12690
|
const widgetSource = config.widgetSource || "cdn";
|
|
12680
12691
|
const widgetVersion = config.widgetVersion || "latest";
|
|
@@ -12724,13 +12735,13 @@ function FramedProviderInner({ config, children }) {
|
|
|
12724
12735
|
const features = useMemo(
|
|
12725
12736
|
() => ({
|
|
12726
12737
|
...DEFAULT_FEATURES,
|
|
12727
|
-
...config
|
|
12738
|
+
...config?.features
|
|
12728
12739
|
}),
|
|
12729
|
-
[config
|
|
12740
|
+
[config?.features]
|
|
12730
12741
|
);
|
|
12731
12742
|
const value = {
|
|
12732
12743
|
config,
|
|
12733
|
-
projectId: config
|
|
12744
|
+
projectId: config?.projectId ?? "default",
|
|
12734
12745
|
isAuthenticated: auth.isAuthenticated,
|
|
12735
12746
|
session: auth.session,
|
|
12736
12747
|
isAuthLoading: auth.isLoading,
|
|
@@ -12757,14 +12768,22 @@ function FramedProviderInner({ config, children }) {
|
|
|
12757
12768
|
return /* @__PURE__ */ jsx(FramedContext.Provider, { value, children });
|
|
12758
12769
|
}
|
|
12759
12770
|
function FramedProvider({ config, children }) {
|
|
12771
|
+
const mergedConfig = {
|
|
12772
|
+
...DEFAULT_CONFIG,
|
|
12773
|
+
...config,
|
|
12774
|
+
auth: {
|
|
12775
|
+
...DEFAULT_CONFIG.auth,
|
|
12776
|
+
...config?.auth
|
|
12777
|
+
}
|
|
12778
|
+
};
|
|
12760
12779
|
return /* @__PURE__ */ jsx(
|
|
12761
12780
|
AuthProvider,
|
|
12762
12781
|
{
|
|
12763
|
-
config:
|
|
12764
|
-
projectId:
|
|
12765
|
-
apiKey:
|
|
12766
|
-
supabaseUrl:
|
|
12767
|
-
children: /* @__PURE__ */ jsx(FramedProviderInner, { config, children })
|
|
12782
|
+
config: mergedConfig.auth,
|
|
12783
|
+
projectId: mergedConfig.projectId,
|
|
12784
|
+
apiKey: mergedConfig.sync?.apiKey,
|
|
12785
|
+
supabaseUrl: mergedConfig.sync?.supabaseUrl,
|
|
12786
|
+
children: /* @__PURE__ */ jsx(FramedProviderInner, { config: mergedConfig, children })
|
|
12768
12787
|
}
|
|
12769
12788
|
);
|
|
12770
12789
|
}
|