@protobase/ui 0.26.9 → 0.27.0
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/app/app.d.ts +1 -1
- package/dist/app/app.js +1 -0
- package/dist/app/main.js +2 -1
- package/dist/app/page-api-origin.js +18 -0
- package/dist/auth/auth-provider.js +9 -3
- package/dist/package.js +1 -1
- package/dist/shell/assets/{app-CKIJTg2U.js → app-BD3RltKN.js} +5 -5
- package/dist/shell/assets/index-B7TwOZvP.js +9 -0
- package/dist/shell/assets/{records-map-DG0dbm9k.js → records-map-BMBT0MNo.js} +1 -1
- package/dist/shell/assets/{shared-protobase-ui-CvcWMNa3.js → shared-protobase-ui-DGh3BpD8.js} +1 -1
- package/dist/shell/index.html +4 -4
- package/dist/shell/protobase.shell.json +1 -1
- package/dist/shell/protobase.sw.js +2 -2
- package/package.json +4 -4
- package/dist/shell/assets/index-nDDDN3FR.js +0 -9
package/dist/app/app.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export type AppProps = {
|
|
|
12
12
|
client?: Client;
|
|
13
13
|
/** Ready-made clients of the sources `/meta` names, by their URL, for stories and tests. */
|
|
14
14
|
sources?: Record<string, Client>;
|
|
15
|
-
/** Sign-in state for the app; made from
|
|
15
|
+
/** Sign-in state for the app; made from `baseUrl`'s origin when omitted. */
|
|
16
16
|
auth?: AuthSession;
|
|
17
17
|
/** Path prefix the app is mounted under, for example `/admin`. */
|
|
18
18
|
basePath?: string;
|
package/dist/app/app.js
CHANGED
|
@@ -309,6 +309,7 @@ const App = ({ auth, workspace, basePath, initialUrl, pluginLoader, locale, ...r
|
|
|
309
309
|
setFallbackLocale(locale ?? "en");
|
|
310
310
|
return /* @__PURE__ */ jsx(ThemeProvider, { children: /* @__PURE__ */ jsx(AuthProvider, {
|
|
311
311
|
session: auth,
|
|
312
|
+
...rest.baseUrl && { origin: new URL(rest.baseUrl, window.location.href).origin },
|
|
312
313
|
children: /* @__PURE__ */ jsx(Router, {
|
|
313
314
|
basePath,
|
|
314
315
|
initialUrl,
|
package/dist/app/main.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { browserLocale } from "../locale/active-locale.js";
|
|
2
2
|
import { uiFromModule } from "./pages/ui-from-module.js";
|
|
3
3
|
import { App } from "./app.js";
|
|
4
|
+
import { pageApiOrigin } from "./page-api-origin.js";
|
|
4
5
|
import { StrictMode } from "react";
|
|
5
6
|
import { jsx } from "react/jsx-runtime";
|
|
6
7
|
import { createRoot } from "react-dom/client";
|
|
@@ -10,7 +11,7 @@ import "../styles.css";
|
|
|
10
11
|
const root = document.getElementById("root");
|
|
11
12
|
if (!root) throw new Error("index.html needs an element with id \"root\"");
|
|
12
13
|
createRoot(root).render(/* @__PURE__ */ jsx(StrictMode, { children: /* @__PURE__ */ jsx(App, {
|
|
13
|
-
baseUrl: "/api/v1
|
|
14
|
+
baseUrl: `${pageApiOrigin() ?? ""}/api/v1`,
|
|
14
15
|
ui: uiFromModule(projectUi),
|
|
15
16
|
locale: browserLocale()
|
|
16
17
|
}) }));
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { apiOriginMeta } from "@protobase/schema/internal";
|
|
2
|
+
//#region src/app/page-api-origin.ts
|
|
3
|
+
/**
|
|
4
|
+
* The API origin the page's `<meta name="protobase-api-origin">` tags name: `undefined` without one. Anything but one
|
|
5
|
+
* tag holding exactly an http or https origin, such as `https://shop.example.com`, is an error.
|
|
6
|
+
*/
|
|
7
|
+
const apiOriginOf = (contents) => {
|
|
8
|
+
if (contents.length === 0) return void 0;
|
|
9
|
+
if (contents.length > 1) throw new Error(`The page has ${contents.length} ${apiOriginMeta} meta tags; it may have one`);
|
|
10
|
+
const value = contents[0];
|
|
11
|
+
const url = URL.canParse(value) ? new URL(value) : void 0;
|
|
12
|
+
if (!url || url.protocol !== "http:" && url.protocol !== "https:" || url.origin !== value) throw new Error(`The page's ${apiOriginMeta} meta tag holds "${value}", which is not an http or https origin such as https://shop.example.com`);
|
|
13
|
+
return value;
|
|
14
|
+
};
|
|
15
|
+
/** The API origin this page names in its `<meta name="protobase-api-origin">` (see `apiOriginOf`). */
|
|
16
|
+
const pageApiOrigin = () => apiOriginOf([...document.querySelectorAll(`meta[name="${apiOriginMeta}"]`)].map((meta) => meta.content));
|
|
17
|
+
//#endregion
|
|
18
|
+
export { apiOriginOf, pageApiOrigin };
|
|
@@ -10,8 +10,11 @@ const useAuth = () => {
|
|
|
10
10
|
if (!api) throw new Error("useAuth must be used inside AuthProvider");
|
|
11
11
|
return api;
|
|
12
12
|
};
|
|
13
|
-
/**
|
|
14
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Finds out whether the server has a login and who is signed in, and keeps that state for the app. Without a `session`,
|
|
15
|
+
* it makes one on `origin`, the page's own by default.
|
|
16
|
+
*/
|
|
17
|
+
const AuthProvider = ({ session: given, origin, children }) => {
|
|
15
18
|
const [state, setState] = useState({ kind: "loading" });
|
|
16
19
|
const [signInMethods, setSignInMethods] = useState(["password"]);
|
|
17
20
|
const [passwordReset, setPasswordReset] = useState(false);
|
|
@@ -29,7 +32,10 @@ const AuthProvider = ({ session: given, children }) => {
|
|
|
29
32
|
const markSignedOut = useCallback(() => setState((current) => current.kind === "signed-in" ? { kind: "signed-out" } : current), []);
|
|
30
33
|
const signedOut = useRef(markSignedOut);
|
|
31
34
|
signedOut.current = markSignedOut;
|
|
32
|
-
const session = useMemo(() => given ?? createAuthSession({
|
|
35
|
+
const session = useMemo(() => given ?? createAuthSession({
|
|
36
|
+
...origin && { origin },
|
|
37
|
+
onSignedOut: () => signedOut.current()
|
|
38
|
+
}), [given, origin]);
|
|
33
39
|
const enter = useCallback(async (user) => {
|
|
34
40
|
const [{ missing }, staff] = await Promise.all([session.account.signInMethods(), session.staff.current()]);
|
|
35
41
|
setState(missing.length > 0 ? {
|
package/dist/package.js
CHANGED