@plumile/backoffice-react 0.1.198 → 0.1.200
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/README.md +5 -0
- package/lib/esm/auth/backofficeAuthHeaders.js +18 -0
- package/lib/esm/auth/backofficeAuthHeaders.js.map +1 -0
- package/lib/esm/index.js +76 -75
- package/lib/esm/pages/BackofficeAcceptInvitationPage.js +7 -7
- package/lib/esm/pages/BackofficeEntityDetailPage.view-helpers.js +6 -4
- package/lib/esm/pages/BackofficeEntityDetailPage.view-helpers.js.map +1 -1
- package/lib/esm/pages/BackofficeLayoutPage.js +41 -41
- package/lib/esm/pages/BackofficeLayoutPage.js.map +1 -1
- package/lib/esm/pages/BackofficeLoginPage.js +11 -11
- package/lib/esm/pages/BackofficePasswordResetCompletePage.js +14 -14
- package/lib/esm/pages/BackofficeVerifyEmailPage.js +14 -14
- package/lib/esm/provider/BackofficeProvider.js +78 -77
- package/lib/esm/provider/BackofficeProvider.js.map +1 -1
- package/lib/esm/provider/useBackofficeAuthRouteGate.js +39 -0
- package/lib/esm/provider/useBackofficeAuthRouteGate.js.map +1 -0
- package/lib/esm/router/backofficeAuthPaths.js +11 -2
- package/lib/esm/router/backofficeAuthPaths.js.map +1 -1
- package/lib/esm/router/createBackofficeRoutes.js +4 -4
- package/lib/esm/router/createBackofficeRoutes.js.map +1 -1
- package/lib/types/auth/backofficeAuthHeaders.d.ts +5 -0
- package/lib/types/auth/backofficeAuthHeaders.d.ts.map +1 -0
- package/lib/types/index.d.ts +1 -0
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/provider/BackofficeProvider.d.ts.map +1 -1
- package/lib/types/provider/useBackofficeAuthRouteGate.d.ts +2 -0
- package/lib/types/provider/useBackofficeAuthRouteGate.d.ts.map +1 -0
- package/lib/types/router/backofficeAuthPaths.d.ts +1 -0
- package/lib/types/router/backofficeAuthPaths.d.ts.map +1 -1
- package/package.json +16 -16
|
@@ -7,31 +7,32 @@ import { withBackofficeReactI18nResources as o } from "../i18n/resources.js";
|
|
|
7
7
|
import { createBackofficeRoutes as s } from "../router/createBackofficeRoutes.js";
|
|
8
8
|
import { createBackofficeEntityRegistry as c } from "./entityRegistry.js";
|
|
9
9
|
import { BackofficeListUiStateProvider as l } from "./BackofficeListUiStateContext.js";
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import v from "
|
|
14
|
-
import
|
|
15
|
-
import {
|
|
16
|
-
import C from "
|
|
17
|
-
import w from "@plumile/router/routing/
|
|
18
|
-
import
|
|
19
|
-
import {
|
|
10
|
+
import { useBackofficeAuthRouteGate as u } from "./useBackofficeAuthRouteGate.js";
|
|
11
|
+
import { StrictMode as d, useEffect as f, useMemo as p, useRef as m, useState as h } from "react";
|
|
12
|
+
import { jsx as g, jsxs as _ } from "react/jsx-runtime";
|
|
13
|
+
import { I18nextProvider as v } from "react-i18next";
|
|
14
|
+
import y from "@plumile/router/routing/RoutingContext.js";
|
|
15
|
+
import { RelayProvider as b, configureRelayEnvironment as x, useRelayOperationActivity as S } from "@plumile/relay";
|
|
16
|
+
import { createInstance as C } from "i18next";
|
|
17
|
+
import w from "@plumile/router/routing/createRouter.js";
|
|
18
|
+
import T from "@plumile/router/routing/RouterRenderer.js";
|
|
19
|
+
import { BackofficeThemeProvider as E } from "@plumile/ui/admin/theme/BackofficeThemeProvider.js";
|
|
20
|
+
import { RoutePendingBar as D } from "@plumile/ui/components/routing/RoutePendingBar.js";
|
|
20
21
|
//#region src/provider/BackofficeProvider.tsx
|
|
21
|
-
var
|
|
22
|
-
let n =
|
|
22
|
+
var O = (e) => e.trim() === "" || e === "/" ? "/" : e.startsWith("/") ? e.endsWith("/") ? e.slice(0, -1) : e : `/${e}`, k = (e, t) => {
|
|
23
|
+
let n = O(t), r = O(e);
|
|
23
24
|
return r === "/" || n === r || n.startsWith(`${r}/`) ? n : n === "/" ? r : `${r}${n}`;
|
|
24
|
-
},
|
|
25
|
+
}, A = (e, t) => Object.fromEntries(Object.entries(e).map(([e, n]) => [e, {
|
|
25
26
|
...n,
|
|
26
27
|
routes: {
|
|
27
|
-
list:
|
|
28
|
-
detail: (e) =>
|
|
29
|
-
detailPage: (e, r) =>
|
|
28
|
+
list: k(t, n.routes.list),
|
|
29
|
+
detail: (e) => k(t, n.routes.detail(e)),
|
|
30
|
+
detailPage: (e, r) => k(t, n.routes.detailPage(e, r))
|
|
30
31
|
}
|
|
31
|
-
}])),
|
|
32
|
-
let [r, i] =
|
|
33
|
-
return
|
|
34
|
-
let r =
|
|
32
|
+
}])), j = ({ routes: e, context: t, instrumentations: n }) => {
|
|
33
|
+
let [r, i] = h(null), a = m(null);
|
|
34
|
+
return f(() => {
|
|
35
|
+
let r = w(e, {
|
|
35
36
|
context: t,
|
|
36
37
|
instrumentations: n
|
|
37
38
|
});
|
|
@@ -43,58 +44,58 @@ var D = (e) => e.trim() === "" || e === "/" ? "/" : e.startsWith("/") ? e.endsWi
|
|
|
43
44
|
n,
|
|
44
45
|
e
|
|
45
46
|
]), r;
|
|
46
|
-
},
|
|
47
|
-
let r = i(), a =
|
|
47
|
+
}, M = ({ routes: e, instrumentations: t }) => {
|
|
48
|
+
let r = i(), a = S(), o = j({
|
|
48
49
|
routes: e,
|
|
49
|
-
context:
|
|
50
|
+
context: p(() => ({ relayEnvironment: r }), [r]),
|
|
50
51
|
instrumentations: t
|
|
51
52
|
});
|
|
52
|
-
return o == null ? /* @__PURE__ */
|
|
53
|
+
return o == null ? /* @__PURE__ */ g(n, {}) : /* @__PURE__ */ g(y.Provider, {
|
|
53
54
|
value: o.context,
|
|
54
|
-
children: /* @__PURE__ */
|
|
55
|
+
children: /* @__PURE__ */ g(T, {
|
|
55
56
|
enableTransition: !0,
|
|
56
57
|
externalPending: a.pendingCount > 0,
|
|
57
|
-
fallback: /* @__PURE__ */
|
|
58
|
-
pending: /* @__PURE__ */
|
|
58
|
+
fallback: /* @__PURE__ */ g(n, {}),
|
|
59
|
+
pending: /* @__PURE__ */ g(D, {})
|
|
59
60
|
})
|
|
60
61
|
});
|
|
61
|
-
},
|
|
62
|
-
let i =
|
|
63
|
-
|
|
64
|
-
let e =
|
|
65
|
-
|
|
62
|
+
}, N = (n) => {
|
|
63
|
+
let i = O(n.basePath ?? "/"), m = u(i), y = p(() => A(n.entityManifest, i), [i, n.entityManifest]), S = p(() => c(y, { basePath: i }), [i, y]), w = n.graphql, T = p(() => t(n.dashboards), [n.dashboards]);
|
|
64
|
+
f(() => {
|
|
65
|
+
let e = w.httpUrl ?? w.endpoint, t = w.wsUrl ?? w.wsEndpoint;
|
|
66
|
+
x({
|
|
66
67
|
httpUrl: e,
|
|
67
68
|
wsUrl: t,
|
|
68
|
-
getDataId:
|
|
69
|
-
logEvents:
|
|
70
|
-
getAuthHeaders:
|
|
69
|
+
getDataId: w.getDataId,
|
|
70
|
+
logEvents: w.logEvents,
|
|
71
|
+
getAuthHeaders: w.getAuthHeaders
|
|
71
72
|
});
|
|
72
73
|
}, [
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
74
|
+
w.endpoint,
|
|
75
|
+
w.getAuthHeaders,
|
|
76
|
+
w.getDataId,
|
|
77
|
+
w.httpUrl,
|
|
78
|
+
w.logEvents,
|
|
79
|
+
w.wsEndpoint,
|
|
80
|
+
w.wsUrl
|
|
80
81
|
]);
|
|
81
|
-
let
|
|
82
|
-
|
|
82
|
+
let D = p(() => o(n.i18n?.resources ?? {}), [n.i18n?.resources]), k = p(() => n.i18n?.instance ?? C(), [n.i18n?.instance]), [j, N] = h(k.isInitialized);
|
|
83
|
+
f(() => {
|
|
83
84
|
let e = !0, t = () => {
|
|
84
|
-
e &&
|
|
85
|
+
e && N(!0);
|
|
85
86
|
};
|
|
86
|
-
if (
|
|
87
|
-
e = !1,
|
|
87
|
+
if (k.on("initialized", t), k.isInitialized) return t(), () => {
|
|
88
|
+
e = !1, k.off("initialized", t);
|
|
88
89
|
};
|
|
89
90
|
let r = globalThis.setTimeout(() => {
|
|
90
|
-
|
|
91
|
+
k.isInitialized && t();
|
|
91
92
|
}, 0), i = n.i18n?.initOptions ?? {}, o = i.defaultNS ?? "translations", s = i.ns ?? [
|
|
92
93
|
"backofficeReact",
|
|
93
94
|
"translations",
|
|
94
95
|
"ui"
|
|
95
96
|
];
|
|
96
97
|
return a({
|
|
97
|
-
resources:
|
|
98
|
+
resources: D,
|
|
98
99
|
lng: n.i18n?.lng,
|
|
99
100
|
fallbackLng: n.i18n?.fallbackLng,
|
|
100
101
|
initOptions: {
|
|
@@ -106,75 +107,75 @@ var D = (e) => e.trim() === "" || e === "/" ? "/" : e.startsWith("/") ? e.endsWi
|
|
|
106
107
|
...i.react
|
|
107
108
|
}
|
|
108
109
|
},
|
|
109
|
-
instance:
|
|
110
|
+
instance: k,
|
|
110
111
|
useLanguageDetector: n.i18n?.useLanguageDetector,
|
|
111
112
|
detection: n.i18n?.detection
|
|
112
113
|
}).then(t).catch((e) => {
|
|
113
114
|
t(), console.error(e);
|
|
114
115
|
}), () => {
|
|
115
|
-
e = !1, globalThis.clearTimeout(r),
|
|
116
|
+
e = !1, globalThis.clearTimeout(r), k.off("initialized", t);
|
|
116
117
|
};
|
|
117
118
|
}, [
|
|
118
|
-
|
|
119
|
-
|
|
119
|
+
k,
|
|
120
|
+
D,
|
|
120
121
|
n.i18n?.initOptions,
|
|
121
122
|
n.i18n?.detection,
|
|
122
123
|
n.i18n?.fallbackLng,
|
|
123
124
|
n.i18n?.lng,
|
|
124
125
|
n.i18n?.useLanguageDetector
|
|
125
126
|
]);
|
|
126
|
-
let
|
|
127
|
+
let P = p(() => ({
|
|
127
128
|
basePath: i,
|
|
128
|
-
entities:
|
|
129
|
-
entityManifest:
|
|
130
|
-
entityRegistry:
|
|
129
|
+
entities: y,
|
|
130
|
+
entityManifest: y,
|
|
131
|
+
entityRegistry: S,
|
|
131
132
|
filterColumnAliases: n.filterColumnAliases,
|
|
132
133
|
sidebar: n.sidebar,
|
|
133
134
|
dashboard: n.dashboard,
|
|
134
|
-
dashboards:
|
|
135
|
+
dashboards: T,
|
|
135
136
|
auth: n.auth,
|
|
136
137
|
graphql: n.graphql
|
|
137
138
|
}), [
|
|
138
139
|
i,
|
|
139
140
|
n.auth,
|
|
140
141
|
n.dashboard,
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
142
|
+
T,
|
|
143
|
+
y,
|
|
144
|
+
S,
|
|
144
145
|
n.filterColumnAliases,
|
|
145
146
|
n.graphql,
|
|
146
147
|
n.sidebar
|
|
147
|
-
]),
|
|
148
|
+
]), F = p(() => s({
|
|
148
149
|
basePath: i,
|
|
149
|
-
entityManifest:
|
|
150
|
-
entityRegistry:
|
|
150
|
+
entityManifest: y,
|
|
151
|
+
entityRegistry: S,
|
|
151
152
|
sidebar: n.sidebar,
|
|
152
153
|
auth: n.auth,
|
|
153
154
|
dashboard: n.dashboard,
|
|
154
|
-
dashboards:
|
|
155
|
+
dashboards: T,
|
|
155
156
|
toolsOperationPage: n.toolsOperationPage
|
|
156
157
|
}), [
|
|
157
158
|
i,
|
|
158
|
-
|
|
159
|
-
|
|
159
|
+
y,
|
|
160
|
+
S,
|
|
160
161
|
n.auth,
|
|
161
162
|
n.dashboard,
|
|
162
|
-
|
|
163
|
+
T,
|
|
163
164
|
n.toolsOperationPage,
|
|
164
165
|
n.sidebar
|
|
165
|
-
]),
|
|
166
|
-
return
|
|
167
|
-
value:
|
|
168
|
-
children: [n.overlay, /* @__PURE__ */
|
|
169
|
-
routes:
|
|
166
|
+
]), I = /* @__PURE__ */ g(r, { label: "Loading..." });
|
|
167
|
+
return j && m && (I = /* @__PURE__ */ g(E, { children: /* @__PURE__ */ g(b, { children: /* @__PURE__ */ _(e, {
|
|
168
|
+
value: P,
|
|
169
|
+
children: [n.overlay, /* @__PURE__ */ g(l, { children: /* @__PURE__ */ g(M, {
|
|
170
|
+
routes: F,
|
|
170
171
|
instrumentations: n.instrumentations
|
|
171
172
|
}) })]
|
|
172
|
-
}) }) })), /* @__PURE__ */
|
|
173
|
-
i18n:
|
|
174
|
-
children:
|
|
173
|
+
}) }) })), /* @__PURE__ */ g(d, { children: /* @__PURE__ */ g(v, {
|
|
174
|
+
i18n: k,
|
|
175
|
+
children: I
|
|
175
176
|
}) });
|
|
176
177
|
};
|
|
177
178
|
//#endregion
|
|
178
|
-
export {
|
|
179
|
+
export { N as BackofficeProvider, N as default };
|
|
179
180
|
|
|
180
181
|
//# sourceMappingURL=BackofficeProvider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BackofficeProvider.js","names":[],"sources":["../../../src/provider/BackofficeProvider.tsx"],"sourcesContent":["import {\n StrictMode,\n useEffect,\n useMemo,\n useRef,\n useState,\n type ContextType,\n type JSX,\n} from 'react';\nimport { createInstance } from 'i18next';\nimport { I18nextProvider } from 'react-i18next';\nimport createRouter from '@plumile/router/routing/createRouter.js';\nimport RouterRenderer from '@plumile/router/routing/RouterRenderer.js';\nimport RoutingContext from '@plumile/router/routing/RoutingContext.js';\nimport { BackofficeThemeProvider } from '@plumile/ui/admin/theme/BackofficeThemeProvider.js';\nimport { RoutePendingBar } from '@plumile/ui/components/routing/RoutePendingBar.js';\n\nimport { type BackofficeEntityManifestMap } from '@plumile/backoffice-core/types.js';\nimport {\n RelayProvider,\n configureRelayEnvironment,\n useRelayOperationActivity,\n} from '@plumile/relay';\n\nimport { createI18nInstance } from '../i18n/createI18nInstance.js';\nimport { withBackofficeReactI18nResources } from '../i18n/resources.js';\nimport { useRelayEnvironment } from '../relay/useRelayEnvironment.js';\nimport { BackofficeConfigProvider } from './BackofficeConfigContext.js';\nimport {\n createBackofficeRoutes,\n type BackofficeRouterContext,\n} from '../router/createBackofficeRoutes.js';\nimport type { BackofficeProviderProps } from './types.js';\nimport { validateBackofficeDashboardRegistrations } from './dashboardRegistrations.js';\nimport {\n BackofficeRouteFallback,\n BackofficeStaticRouteFallback,\n} from '../components/backoffice/routing/BackofficeRouteFallback.js';\nimport { createBackofficeEntityRegistry } from './entityRegistry.js';\nimport { BackofficeListUiStateProvider } from './BackofficeListUiStateContext.js';\n\nconst normalizeAbsolutePath = (value: string): string => {\n if (value.trim() === '' || value === '/') {\n return '/';\n }\n if (!value.startsWith('/')) {\n return `/${value}`;\n }\n if (value.endsWith('/')) {\n return value.slice(0, -1);\n }\n return value;\n};\n\nconst prefixRoutePath = (basePath: string, value: string): string => {\n const normalizedPath = normalizeAbsolutePath(value);\n const normalizedBasePath = normalizeAbsolutePath(basePath);\n if (normalizedBasePath === '/') {\n return normalizedPath;\n }\n if (\n normalizedPath === normalizedBasePath ||\n normalizedPath.startsWith(`${normalizedBasePath}/`)\n ) {\n return normalizedPath;\n }\n if (normalizedPath === '/') {\n return normalizedBasePath;\n }\n return `${normalizedBasePath}${normalizedPath}`;\n};\n\nconst resolveEntityManifest = (\n manifest: BackofficeEntityManifestMap,\n basePath: string,\n): BackofficeEntityManifestMap => {\n return Object.fromEntries(\n Object.entries(manifest).map(([entityId, item]) => {\n return [\n entityId,\n {\n ...item,\n routes: {\n list: prefixRoutePath(basePath, item.routes.list),\n detail: (id: string) => {\n return prefixRoutePath(basePath, item.routes.detail(id));\n },\n detailPage: (id: string, pageId: string) => {\n return prefixRoutePath(\n basePath,\n item.routes.detailPage(id, pageId),\n );\n },\n },\n } satisfies BackofficeEntityManifestMap[string],\n ] as const;\n }),\n );\n};\n\ntype RouterShellProps = {\n routes: ReturnType<typeof createBackofficeRoutes>;\n instrumentations?: BackofficeProviderProps['instrumentations'];\n};\n\ntype BackofficeRouterInstance = {\n context: NonNullable<ContextType<typeof RoutingContext>>;\n cleanup: () => void;\n};\n\nconst useBackofficeRouterInstance = ({\n routes,\n context,\n instrumentations,\n}: {\n routes: ReturnType<typeof createBackofficeRoutes>;\n context: BackofficeRouterContext;\n instrumentations?: BackofficeProviderProps['instrumentations'];\n}): BackofficeRouterInstance | null => {\n const [router, setRouter] = useState<BackofficeRouterInstance | null>(null);\n const routerRef = useRef<BackofficeRouterInstance | null>(null);\n\n useEffect(() => {\n const nextRouter = createRouter(routes, {\n context,\n instrumentations,\n });\n routerRef.current = nextRouter;\n setRouter(nextRouter);\n\n return () => {\n if (routerRef.current === nextRouter) {\n routerRef.current = null;\n }\n nextRouter.cleanup();\n };\n }, [context, instrumentations, routes]);\n\n return router;\n};\n\nconst RouterShell = ({\n routes,\n instrumentations,\n}: RouterShellProps): JSX.Element => {\n const relayEnvironment = useRelayEnvironment();\n const relayOperationActivity = useRelayOperationActivity();\n\n const routerContext = useMemo(() => {\n return { relayEnvironment };\n }, [relayEnvironment]);\n\n const router = useBackofficeRouterInstance({\n routes,\n context: routerContext,\n instrumentations,\n });\n\n if (router == null) {\n return <BackofficeRouteFallback />;\n }\n\n return (\n <RoutingContext.Provider value={router.context}>\n <RouterRenderer\n enableTransition\n externalPending={relayOperationActivity.pendingCount > 0}\n fallback={<BackofficeRouteFallback />}\n pending={<RoutePendingBar />}\n />\n </RoutingContext.Provider>\n );\n};\n\nexport const BackofficeProvider = (\n props: BackofficeProviderProps,\n): JSX.Element => {\n const basePath = normalizeAbsolutePath(props.basePath ?? '/');\n\n const entityManifest = useMemo(() => {\n return resolveEntityManifest(props.entityManifest, basePath);\n }, [basePath, props.entityManifest]);\n const entityRegistry = useMemo(() => {\n return createBackofficeEntityRegistry(entityManifest, { basePath });\n }, [basePath, entityManifest]);\n\n const graphQLConfig = props.graphql;\n const dashboards = useMemo(() => {\n return validateBackofficeDashboardRegistrations(props.dashboards);\n }, [props.dashboards]);\n\n useEffect(() => {\n const httpUrl = graphQLConfig.httpUrl ?? graphQLConfig.endpoint;\n const wsUrl = graphQLConfig.wsUrl ?? graphQLConfig.wsEndpoint;\n configureRelayEnvironment({\n httpUrl,\n wsUrl,\n getDataId: graphQLConfig.getDataId,\n logEvents: graphQLConfig.logEvents,\n getAuthHeaders: graphQLConfig.getAuthHeaders,\n });\n }, [\n graphQLConfig.endpoint,\n graphQLConfig.getAuthHeaders,\n graphQLConfig.getDataId,\n graphQLConfig.httpUrl,\n graphQLConfig.logEvents,\n graphQLConfig.wsEndpoint,\n graphQLConfig.wsUrl,\n ]);\n\n const mergedResources = useMemo(() => {\n return withBackofficeReactI18nResources(props.i18n?.resources ?? {});\n }, [props.i18n?.resources]);\n\n const i18nInstance = useMemo(() => {\n return props.i18n?.instance ?? createInstance();\n }, [props.i18n?.instance]);\n const [isI18nReady, setIsI18nReady] = useState(i18nInstance.isInitialized);\n\n useEffect(() => {\n let isCurrent = true;\n const markI18nReady = (): void => {\n if (isCurrent) {\n setIsI18nReady(true);\n }\n };\n\n i18nInstance.on('initialized', markI18nReady);\n if (i18nInstance.isInitialized) {\n markI18nReady();\n return () => {\n isCurrent = false;\n i18nInstance.off('initialized', markI18nReady);\n };\n }\n\n const readyCheck = globalThis.setTimeout(() => {\n if (i18nInstance.isInitialized) {\n markI18nReady();\n }\n }, 0);\n\n const initOptions = props.i18n?.initOptions ?? {};\n const defaultNs = initOptions.defaultNS ?? 'translations';\n const ns = initOptions.ns ?? ['backofficeReact', 'translations', 'ui'];\n createI18nInstance({\n resources: mergedResources,\n lng: props.i18n?.lng,\n fallbackLng: props.i18n?.fallbackLng,\n initOptions: {\n ...initOptions,\n defaultNS: defaultNs,\n ns,\n react: {\n useSuspense: false,\n ...initOptions.react,\n },\n },\n instance: i18nInstance,\n useLanguageDetector: props.i18n?.useLanguageDetector,\n detection: props.i18n?.detection,\n })\n .then(markI18nReady)\n .catch((error: unknown) => {\n markI18nReady();\n // eslint-disable-next-line no-console\n console.error(error);\n });\n\n return () => {\n isCurrent = false;\n globalThis.clearTimeout(readyCheck);\n i18nInstance.off('initialized', markI18nReady);\n };\n }, [\n i18nInstance,\n mergedResources,\n props.i18n?.initOptions,\n props.i18n?.detection,\n props.i18n?.fallbackLng,\n props.i18n?.lng,\n props.i18n?.useLanguageDetector,\n ]);\n\n const configValue = useMemo(() => {\n return {\n basePath,\n entities: entityManifest,\n entityManifest,\n entityRegistry,\n filterColumnAliases: props.filterColumnAliases,\n sidebar: props.sidebar,\n dashboard: props.dashboard,\n dashboards,\n auth: props.auth,\n graphql: props.graphql,\n };\n }, [\n basePath,\n props.auth,\n props.dashboard,\n dashboards,\n entityManifest,\n entityRegistry,\n props.filterColumnAliases,\n props.graphql,\n props.sidebar,\n ]);\n\n const routes = useMemo(() => {\n return createBackofficeRoutes({\n basePath,\n entityManifest,\n entityRegistry,\n sidebar: props.sidebar,\n auth: props.auth,\n dashboard: props.dashboard,\n dashboards,\n toolsOperationPage: props.toolsOperationPage,\n });\n }, [\n basePath,\n entityManifest,\n entityRegistry,\n props.auth,\n props.dashboard,\n dashboards,\n props.toolsOperationPage,\n props.sidebar,\n ]);\n\n let contentNode = <BackofficeStaticRouteFallback label=\"Loading...\" />;\n if (isI18nReady) {\n contentNode = (\n <BackofficeThemeProvider>\n <RelayProvider>\n <BackofficeConfigProvider value={configValue}>\n {props.overlay}\n <BackofficeListUiStateProvider>\n <RouterShell\n routes={routes}\n instrumentations={props.instrumentations}\n />\n </BackofficeListUiStateProvider>\n </BackofficeConfigProvider>\n </RelayProvider>\n </BackofficeThemeProvider>\n );\n }\n\n return (\n <StrictMode>\n <I18nextProvider i18n={i18nInstance}>{contentNode}</I18nextProvider>\n </StrictMode>\n );\n};\n\nexport default BackofficeProvider;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAyCA,IAAM,KAAyB,MACzB,EAAM,KAAK,MAAM,MAAM,MAAU,MAC5B,MAEJ,EAAM,WAAW,GAAG,IAGrB,EAAM,SAAS,GAAG,IACb,EAAM,MAAM,GAAG,EAAE,IAEnB,IALE,IAAI,KAQT,KAAmB,GAAkB,MAA0B;CACnE,IAAM,IAAiB,EAAsB,CAAK,GAC5C,IAAqB,EAAsB,CAAQ;CAazD,OAZI,MAAuB,OAIzB,MAAmB,KACnB,EAAe,WAAW,GAAG,EAAmB,EAAE,IAE3C,IAEL,MAAmB,MACd,IAEF,GAAG,IAAqB;AACjC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A;CAA6B,CAAA,EACzD,CAAA;AAEhB"}
|
|
1
|
+
{"version":3,"file":"BackofficeProvider.js","names":[],"sources":["../../../src/provider/BackofficeProvider.tsx"],"sourcesContent":["import {\n StrictMode,\n useEffect,\n useMemo,\n useRef,\n useState,\n type ContextType,\n type JSX,\n} from 'react';\nimport { createInstance } from 'i18next';\nimport { I18nextProvider } from 'react-i18next';\nimport createRouter from '@plumile/router/routing/createRouter.js';\nimport RouterRenderer from '@plumile/router/routing/RouterRenderer.js';\nimport RoutingContext from '@plumile/router/routing/RoutingContext.js';\nimport { BackofficeThemeProvider } from '@plumile/ui/admin/theme/BackofficeThemeProvider.js';\nimport { RoutePendingBar } from '@plumile/ui/components/routing/RoutePendingBar.js';\n\nimport { type BackofficeEntityManifestMap } from '@plumile/backoffice-core/types.js';\nimport {\n RelayProvider,\n configureRelayEnvironment,\n useRelayOperationActivity,\n} from '@plumile/relay';\n\nimport { createI18nInstance } from '../i18n/createI18nInstance.js';\nimport { withBackofficeReactI18nResources } from '../i18n/resources.js';\nimport { useRelayEnvironment } from '../relay/useRelayEnvironment.js';\nimport { BackofficeConfigProvider } from './BackofficeConfigContext.js';\nimport {\n createBackofficeRoutes,\n type BackofficeRouterContext,\n} from '../router/createBackofficeRoutes.js';\nimport type { BackofficeProviderProps } from './types.js';\nimport { validateBackofficeDashboardRegistrations } from './dashboardRegistrations.js';\nimport {\n BackofficeRouteFallback,\n BackofficeStaticRouteFallback,\n} from '../components/backoffice/routing/BackofficeRouteFallback.js';\nimport { createBackofficeEntityRegistry } from './entityRegistry.js';\nimport { BackofficeListUiStateProvider } from './BackofficeListUiStateContext.js';\nimport { useBackofficeAuthRouteGate } from './useBackofficeAuthRouteGate.js';\n\nconst normalizeAbsolutePath = (value: string): string => {\n if (value.trim() === '' || value === '/') {\n return '/';\n }\n if (!value.startsWith('/')) {\n return `/${value}`;\n }\n if (value.endsWith('/')) {\n return value.slice(0, -1);\n }\n return value;\n};\n\nconst prefixRoutePath = (basePath: string, value: string): string => {\n const normalizedPath = normalizeAbsolutePath(value);\n const normalizedBasePath = normalizeAbsolutePath(basePath);\n if (normalizedBasePath === '/') {\n return normalizedPath;\n }\n if (\n normalizedPath === normalizedBasePath ||\n normalizedPath.startsWith(`${normalizedBasePath}/`)\n ) {\n return normalizedPath;\n }\n if (normalizedPath === '/') {\n return normalizedBasePath;\n }\n return `${normalizedBasePath}${normalizedPath}`;\n};\n\nconst resolveEntityManifest = (\n manifest: BackofficeEntityManifestMap,\n basePath: string,\n): BackofficeEntityManifestMap => {\n return Object.fromEntries(\n Object.entries(manifest).map(([entityId, item]) => {\n return [\n entityId,\n {\n ...item,\n routes: {\n list: prefixRoutePath(basePath, item.routes.list),\n detail: (id: string) => {\n return prefixRoutePath(basePath, item.routes.detail(id));\n },\n detailPage: (id: string, pageId: string) => {\n return prefixRoutePath(\n basePath,\n item.routes.detailPage(id, pageId),\n );\n },\n },\n } satisfies BackofficeEntityManifestMap[string],\n ] as const;\n }),\n );\n};\n\ntype RouterShellProps = {\n routes: ReturnType<typeof createBackofficeRoutes>;\n instrumentations?: BackofficeProviderProps['instrumentations'];\n};\n\ntype BackofficeRouterInstance = {\n context: NonNullable<ContextType<typeof RoutingContext>>;\n cleanup: () => void;\n};\n\nconst useBackofficeRouterInstance = ({\n routes,\n context,\n instrumentations,\n}: {\n routes: ReturnType<typeof createBackofficeRoutes>;\n context: BackofficeRouterContext;\n instrumentations?: BackofficeProviderProps['instrumentations'];\n}): BackofficeRouterInstance | null => {\n const [router, setRouter] = useState<BackofficeRouterInstance | null>(null);\n const routerRef = useRef<BackofficeRouterInstance | null>(null);\n\n useEffect(() => {\n const nextRouter = createRouter(routes, {\n context,\n instrumentations,\n });\n routerRef.current = nextRouter;\n setRouter(nextRouter);\n\n return () => {\n if (routerRef.current === nextRouter) {\n routerRef.current = null;\n }\n nextRouter.cleanup();\n };\n }, [context, instrumentations, routes]);\n\n return router;\n};\n\nconst RouterShell = ({\n routes,\n instrumentations,\n}: RouterShellProps): JSX.Element => {\n const relayEnvironment = useRelayEnvironment();\n const relayOperationActivity = useRelayOperationActivity();\n\n const routerContext = useMemo(() => {\n return { relayEnvironment };\n }, [relayEnvironment]);\n\n const router = useBackofficeRouterInstance({\n routes,\n context: routerContext,\n instrumentations,\n });\n\n if (router == null) {\n return <BackofficeRouteFallback />;\n }\n\n return (\n <RoutingContext.Provider value={router.context}>\n <RouterRenderer\n enableTransition\n externalPending={relayOperationActivity.pendingCount > 0}\n fallback={<BackofficeRouteFallback />}\n pending={<RoutePendingBar />}\n />\n </RoutingContext.Provider>\n );\n};\n\nexport const BackofficeProvider = (\n props: BackofficeProviderProps,\n): JSX.Element => {\n const basePath = normalizeAbsolutePath(props.basePath ?? '/');\n const canMountRouter = useBackofficeAuthRouteGate(basePath);\n\n const entityManifest = useMemo(() => {\n return resolveEntityManifest(props.entityManifest, basePath);\n }, [basePath, props.entityManifest]);\n const entityRegistry = useMemo(() => {\n return createBackofficeEntityRegistry(entityManifest, { basePath });\n }, [basePath, entityManifest]);\n\n const graphQLConfig = props.graphql;\n const dashboards = useMemo(() => {\n return validateBackofficeDashboardRegistrations(props.dashboards);\n }, [props.dashboards]);\n\n useEffect(() => {\n const httpUrl = graphQLConfig.httpUrl ?? graphQLConfig.endpoint;\n const wsUrl = graphQLConfig.wsUrl ?? graphQLConfig.wsEndpoint;\n configureRelayEnvironment({\n httpUrl,\n wsUrl,\n getDataId: graphQLConfig.getDataId,\n logEvents: graphQLConfig.logEvents,\n getAuthHeaders: graphQLConfig.getAuthHeaders,\n });\n }, [\n graphQLConfig.endpoint,\n graphQLConfig.getAuthHeaders,\n graphQLConfig.getDataId,\n graphQLConfig.httpUrl,\n graphQLConfig.logEvents,\n graphQLConfig.wsEndpoint,\n graphQLConfig.wsUrl,\n ]);\n\n const mergedResources = useMemo(() => {\n return withBackofficeReactI18nResources(props.i18n?.resources ?? {});\n }, [props.i18n?.resources]);\n\n const i18nInstance = useMemo(() => {\n return props.i18n?.instance ?? createInstance();\n }, [props.i18n?.instance]);\n const [isI18nReady, setIsI18nReady] = useState(i18nInstance.isInitialized);\n\n useEffect(() => {\n let isCurrent = true;\n const markI18nReady = (): void => {\n if (isCurrent) {\n setIsI18nReady(true);\n }\n };\n\n i18nInstance.on('initialized', markI18nReady);\n if (i18nInstance.isInitialized) {\n markI18nReady();\n return () => {\n isCurrent = false;\n i18nInstance.off('initialized', markI18nReady);\n };\n }\n\n const readyCheck = globalThis.setTimeout(() => {\n if (i18nInstance.isInitialized) {\n markI18nReady();\n }\n }, 0);\n\n const initOptions = props.i18n?.initOptions ?? {};\n const defaultNs = initOptions.defaultNS ?? 'translations';\n const ns = initOptions.ns ?? ['backofficeReact', 'translations', 'ui'];\n createI18nInstance({\n resources: mergedResources,\n lng: props.i18n?.lng,\n fallbackLng: props.i18n?.fallbackLng,\n initOptions: {\n ...initOptions,\n defaultNS: defaultNs,\n ns,\n react: {\n useSuspense: false,\n ...initOptions.react,\n },\n },\n instance: i18nInstance,\n useLanguageDetector: props.i18n?.useLanguageDetector,\n detection: props.i18n?.detection,\n })\n .then(markI18nReady)\n .catch((error: unknown) => {\n markI18nReady();\n // eslint-disable-next-line no-console\n console.error(error);\n });\n\n return () => {\n isCurrent = false;\n globalThis.clearTimeout(readyCheck);\n i18nInstance.off('initialized', markI18nReady);\n };\n }, [\n i18nInstance,\n mergedResources,\n props.i18n?.initOptions,\n props.i18n?.detection,\n props.i18n?.fallbackLng,\n props.i18n?.lng,\n props.i18n?.useLanguageDetector,\n ]);\n\n const configValue = useMemo(() => {\n return {\n basePath,\n entities: entityManifest,\n entityManifest,\n entityRegistry,\n filterColumnAliases: props.filterColumnAliases,\n sidebar: props.sidebar,\n dashboard: props.dashboard,\n dashboards,\n auth: props.auth,\n graphql: props.graphql,\n };\n }, [\n basePath,\n props.auth,\n props.dashboard,\n dashboards,\n entityManifest,\n entityRegistry,\n props.filterColumnAliases,\n props.graphql,\n props.sidebar,\n ]);\n\n const routes = useMemo(() => {\n return createBackofficeRoutes({\n basePath,\n entityManifest,\n entityRegistry,\n sidebar: props.sidebar,\n auth: props.auth,\n dashboard: props.dashboard,\n dashboards,\n toolsOperationPage: props.toolsOperationPage,\n });\n }, [\n basePath,\n entityManifest,\n entityRegistry,\n props.auth,\n props.dashboard,\n dashboards,\n props.toolsOperationPage,\n props.sidebar,\n ]);\n\n let contentNode = <BackofficeStaticRouteFallback label=\"Loading...\" />;\n if (isI18nReady && canMountRouter) {\n contentNode = (\n <BackofficeThemeProvider>\n <RelayProvider>\n <BackofficeConfigProvider value={configValue}>\n {props.overlay}\n <BackofficeListUiStateProvider>\n <RouterShell\n routes={routes}\n instrumentations={props.instrumentations}\n />\n </BackofficeListUiStateProvider>\n </BackofficeConfigProvider>\n </RelayProvider>\n </BackofficeThemeProvider>\n );\n }\n\n return (\n <StrictMode>\n <I18nextProvider i18n={i18nInstance}>{contentNode}</I18nextProvider>\n </StrictMode>\n );\n};\n\nexport default BackofficeProvider;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA0CA,IAAM,KAAyB,MACzB,EAAM,KAAK,MAAM,MAAM,MAAU,MAC5B,MAEJ,EAAM,WAAW,GAAG,IAGrB,EAAM,SAAS,GAAG,IACb,EAAM,MAAM,GAAG,EAAE,IAEnB,IALE,IAAI,KAQT,KAAmB,GAAkB,MAA0B;CACnE,IAAM,IAAiB,EAAsB,CAAK,GAC5C,IAAqB,EAAsB,CAAQ;CAazD,OAZI,MAAuB,OAIzB,MAAmB,KACnB,EAAe,WAAW,GAAG,EAAmB,EAAE,IAE3C,IAEL,MAAmB,MACd,IAEF,GAAG,IAAqB;AACjC,GAEM,KACJ,GACA,MAEO,OAAO,YACZ,OAAO,QAAQ,CAAQ,CAAC,CAAC,KAAK,CAAC,GAAU,OAChC,CACL,GACA;CACE,GAAG;CACH,QAAQ;EACN,MAAM,EAAgB,GAAU,EAAK,OAAO,IAAI;EAChD,SAAS,MACA,EAAgB,GAAU,EAAK,OAAO,OAAO,CAAE,CAAC;EAEzD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SAEU;GAGX,AAFA,IAAY,IACZ,WAAW,aAAa,CAAU,GAClC,EAAa,IAAI,eAAe,CAAa;EAC/C;CACF,GAAG;EACD;EACA;EACA,EAAM,MAAM;EACZ,EAAM,MAAM;EACZ,EAAM,MAAM;EACZ,EAAM,MAAM;EACZ,EAAM,MAAM;CACd,CAAC;CAED,IAAM,IAAc,SACX;EACL;EACA,UAAU;EACV;EACA;EACA,qBAAqB,EAAM;EAC3B,SAAS,EAAM;EACf,WAAW,EAAM;EACjB;EACA,MAAM,EAAM;EACZ,SAAS,EAAM;CACjB,IACC;EACD;EACA,EAAM;EACN,EAAM;EACN;EACA;EACA;EACA,EAAM;EACN,EAAM;EACN,EAAM;CACR,CAAC,GAEK,IAAS,QACN,EAAuB;EAC5B;EACA;EACA;EACA,SAAS,EAAM;EACf,MAAM,EAAM;EACZ,WAAW,EAAM;EACjB;EACA,oBAAoB,EAAM;CAC5B,CAAC,GACA;EACD;EACA;EACA;EACA,EAAM;EACN,EAAM;EACN;EACA,EAAM;EACN,EAAM;CACR,CAAC,GAEG,IAAc,kBAAC,GAAD,EAA+B,OAAM,aAAc,CAAA;CAmBrE,OAlBI,KAAe,MACjB,IACE,kBAAC,GAAD,EAAA,UACE,kBAAC,GAAD,EAAA,UACE,kBAAC,GAAD;EAA0B,OAAO;EAAjC,UAAA,CACG,EAAM,SACP,kBAAC,GAAD,EAAA,UACE,kBAAC,GAAD;GACU;GACR,kBAAkB,EAAM;EACzB,CAAA,EAC4B,CAAA,CACP;CACb,CAAA,EAAA,CAAA,EACQ,CAAA,IAK3B,kBAAC,GAAD,EAAA,UACE,kBAAC,GAAD;EAAiB,MAAM;EAAe,UAAA;CAA6B,CAAA,EACzD,CAAA;AAEhB"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { getBackofficeLoginPath as e, isBackofficeAuthPath as t } from "../router/backofficeAuthPaths.js";
|
|
2
|
+
import { useEffect as n, useState as r, useSyncExternalStore as i } from "react";
|
|
3
|
+
import { addAuthRefreshStateListener as a, getAuthRefreshState as o, getShortAccessToken as s } from "@plumile/auth/shortAccessToken.js";
|
|
4
|
+
//#region src/provider/useBackofficeAuthRouteGate.ts
|
|
5
|
+
var c = (e) => a(e), l = () => o(), u = () => typeof window > "u" ? "/" : window.location.pathname, d = (a) => {
|
|
6
|
+
let o = i(c, l, l), [d, f] = r(u), p = t(a, d);
|
|
7
|
+
return n(() => {
|
|
8
|
+
if (p || o.status === "authenticated") return;
|
|
9
|
+
if (o.status === "session_expired") {
|
|
10
|
+
if (typeof window < "u") {
|
|
11
|
+
let t = e(a);
|
|
12
|
+
window.history.replaceState(window.history.state, "", t), f(t);
|
|
13
|
+
}
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
if (o.status === "refreshing") return;
|
|
17
|
+
let t = !1, n, r = () => {
|
|
18
|
+
s().catch(() => {});
|
|
19
|
+
};
|
|
20
|
+
if (o.status === "temporarily_unavailable") {
|
|
21
|
+
let { retryAtMs: e } = o;
|
|
22
|
+
if (e == null) return;
|
|
23
|
+
n = setTimeout(() => {
|
|
24
|
+
t || r();
|
|
25
|
+
}, Math.max(0, e - Date.now()));
|
|
26
|
+
} else r();
|
|
27
|
+
return () => {
|
|
28
|
+
t = !0, n != null && clearTimeout(n);
|
|
29
|
+
};
|
|
30
|
+
}, [
|
|
31
|
+
o,
|
|
32
|
+
a,
|
|
33
|
+
p
|
|
34
|
+
]), p || o.status === "authenticated";
|
|
35
|
+
};
|
|
36
|
+
//#endregion
|
|
37
|
+
export { d as useBackofficeAuthRouteGate };
|
|
38
|
+
|
|
39
|
+
//# sourceMappingURL=useBackofficeAuthRouteGate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useBackofficeAuthRouteGate.js","names":[],"sources":["../../../src/provider/useBackofficeAuthRouteGate.ts"],"sourcesContent":["import { useEffect, useState, useSyncExternalStore } from 'react';\nimport {\n addAuthRefreshStateListener,\n getAuthRefreshState,\n getShortAccessToken,\n} from '@plumile/auth/shortAccessToken.js';\nimport type { AuthRefreshState } from '@plumile/auth/authRefreshState.js';\n\nimport {\n getBackofficeLoginPath,\n isBackofficeAuthPath,\n} from '../router/backofficeAuthPaths.js';\n\nconst subscribe = (onStoreChange: () => void): (() => void) => {\n return addAuthRefreshStateListener(onStoreChange);\n};\n\nconst getSnapshot = (): AuthRefreshState => {\n return getAuthRefreshState();\n};\n\nconst currentPathname = (): string => {\n if (typeof window === 'undefined') {\n return '/';\n }\n return window.location.pathname;\n};\n\nexport const useBackofficeAuthRouteGate = (basePath: string): boolean => {\n const authState = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n const [pathname, setPathname] = useState(currentPathname);\n const isAuthPath = isBackofficeAuthPath(basePath, pathname);\n\n useEffect(() => {\n if (isAuthPath || authState.status === 'authenticated') {\n return undefined;\n }\n\n if (authState.status === 'session_expired') {\n if (typeof window !== 'undefined') {\n const loginPath = getBackofficeLoginPath(basePath);\n window.history.replaceState(window.history.state, '', loginPath);\n setPathname(loginPath);\n }\n return undefined;\n }\n\n if (authState.status === 'refreshing') {\n return undefined;\n }\n\n let cancelled = false;\n let retryTimer: ReturnType<typeof setTimeout> | undefined;\n const authenticate = (): void => {\n getShortAccessToken().catch(() => {\n // The shared auth state carries the typed failure and drives the next render.\n });\n };\n\n if (authState.status === 'temporarily_unavailable') {\n const { retryAtMs } = authState;\n if (retryAtMs == null) {\n return undefined;\n }\n retryTimer = setTimeout(\n () => {\n if (!cancelled) {\n authenticate();\n }\n },\n Math.max(0, retryAtMs - Date.now()),\n );\n } else {\n authenticate();\n }\n\n return () => {\n cancelled = true;\n if (retryTimer != null) {\n clearTimeout(retryTimer);\n }\n };\n }, [authState, basePath, isAuthPath]);\n\n return isAuthPath || authState.status === 'authenticated';\n};\n"],"mappings":";;;;AAaA,IAAM,KAAa,MACV,EAA4B,CAAa,GAG5C,UACG,EAAoB,GAGvB,UACA,OAAO,SAAW,MACb,MAEF,OAAO,SAAS,UAGZ,KAA8B,MAA8B;CACvE,IAAM,IAAY,EAAqB,GAAW,GAAa,CAAW,GACpE,CAAC,GAAU,KAAe,EAAS,CAAe,GAClD,IAAa,EAAqB,GAAU,CAAQ;CAqD1D,OAnDA,QAAgB;EACd,IAAI,KAAc,EAAU,WAAW,iBACrC;EAGF,IAAI,EAAU,WAAW,mBAAmB;GAC1C,IAAI,OAAO,SAAW,KAAa;IACjC,IAAM,IAAY,EAAuB,CAAQ;IAEjD,AADA,OAAO,QAAQ,aAAa,OAAO,QAAQ,OAAO,IAAI,CAAS,GAC/D,EAAY,CAAS;GACvB;GACA;EACF;EAEA,IAAI,EAAU,WAAW,cACvB;EAGF,IAAI,IAAY,IACZ,GACE,UAA2B;GAC/B,EAAoB,CAAC,CAAC,YAAY,CAElC,CAAC;EACH;EAEA,IAAI,EAAU,WAAW,2BAA2B;GAClD,IAAM,EAAE,iBAAc;GACtB,IAAI,KAAa,MACf;GAEF,IAAa,iBACL;IACJ,AAAK,KACH,EAAa;GAEjB,GACA,KAAK,IAAI,GAAG,IAAY,KAAK,IAAI,CAAC,CACpC;EACF,OACE,EAAa;EAGf,aAAa;GAEX,AADA,IAAY,IACR,KAAc,QAChB,aAAa,CAAU;EAE3B;CACF,GAAG;EAAC;EAAW;EAAU;CAAU,CAAC,GAE7B,KAAc,EAAU,WAAW;AAC5C"}
|
|
@@ -6,8 +6,17 @@ var e = (e) => {
|
|
|
6
6
|
}, t = (t, n) => {
|
|
7
7
|
let r = e(n), i = e(t);
|
|
8
8
|
return i === "/" || r === i || r.startsWith(`${i}/`) ? r : r === "/" ? i : `${i}${r}`;
|
|
9
|
-
}, n = (e) => t(e, "/login"), r = (e) => t(e, "/login/reset")
|
|
9
|
+
}, n = (e) => t(e, "/login"), r = (e) => t(e, "/login/reset"), i = [
|
|
10
|
+
"/login",
|
|
11
|
+
"/login/reset",
|
|
12
|
+
"/login/reset/complete",
|
|
13
|
+
"/verify-email",
|
|
14
|
+
"/accept-invitation"
|
|
15
|
+
], a = (n, r) => {
|
|
16
|
+
let a = e(r);
|
|
17
|
+
return i.some((e) => a === t(n, e));
|
|
18
|
+
};
|
|
10
19
|
//#endregion
|
|
11
|
-
export { n as getBackofficeLoginPath, r as getBackofficePasswordResetPath };
|
|
20
|
+
export { n as getBackofficeLoginPath, r as getBackofficePasswordResetPath, a as isBackofficeAuthPath };
|
|
12
21
|
|
|
13
22
|
//# sourceMappingURL=backofficeAuthPaths.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"backofficeAuthPaths.js","names":[],"sources":["../../../src/router/backofficeAuthPaths.ts"],"sourcesContent":["const normalizeAbsolutePath = (value: string): string => {\n if (value.trim() === '' || value === '/') {\n return '/';\n }\n let withLeadingSlash = value;\n if (!value.startsWith('/')) {\n withLeadingSlash = `/${value}`;\n }\n if (withLeadingSlash.endsWith('/')) {\n return withLeadingSlash.slice(0, -1);\n }\n return withLeadingSlash;\n};\n\nconst prefixBackofficePath = (basePath: string, value: string): string => {\n const normalizedPath = normalizeAbsolutePath(value);\n const normalizedBasePath = normalizeAbsolutePath(basePath);\n\n if (normalizedBasePath === '/') {\n return normalizedPath;\n }\n if (\n normalizedPath === normalizedBasePath ||\n normalizedPath.startsWith(`${normalizedBasePath}/`)\n ) {\n return normalizedPath;\n }\n if (normalizedPath === '/') {\n return normalizedBasePath;\n }\n return `${normalizedBasePath}${normalizedPath}`;\n};\n\nexport const getBackofficeLoginPath = (basePath: string): string => {\n return prefixBackofficePath(basePath, '/login');\n};\n\nexport const getBackofficePasswordResetPath = (basePath: string): string => {\n return prefixBackofficePath(basePath, '/login/reset');\n};\n"],"mappings":";AAAA,IAAM,KAAyB,MAA0B;CACvD,IAAI,EAAM,KAAK,MAAM,MAAM,MAAU,KACnC,OAAO;CAET,IAAI,IAAmB;CAOvB,OANK,EAAM,WAAW,GAAG,MACvB,IAAmB,IAAI,MAErB,EAAiB,SAAS,GAAG,IACxB,EAAiB,MAAM,GAAG,EAAE,IAE9B;AACT,GAEM,KAAwB,GAAkB,MAA0B;CACxE,IAAM,IAAiB,EAAsB,CAAK,GAC5C,IAAqB,EAAsB,CAAQ;CAczD,OAZI,MAAuB,OAIzB,MAAmB,KACnB,EAAe,WAAW,GAAG,EAAmB,EAAE,IAE3C,IAEL,MAAmB,MACd,IAEF,GAAG,IAAqB;AACjC,GAEa,KAA0B,MAC9B,EAAqB,GAAU,QAAQ,GAGnC,KAAkC,MACtC,EAAqB,GAAU,cAAc"}
|
|
1
|
+
{"version":3,"file":"backofficeAuthPaths.js","names":[],"sources":["../../../src/router/backofficeAuthPaths.ts"],"sourcesContent":["const normalizeAbsolutePath = (value: string): string => {\n if (value.trim() === '' || value === '/') {\n return '/';\n }\n let withLeadingSlash = value;\n if (!value.startsWith('/')) {\n withLeadingSlash = `/${value}`;\n }\n if (withLeadingSlash.endsWith('/')) {\n return withLeadingSlash.slice(0, -1);\n }\n return withLeadingSlash;\n};\n\nconst prefixBackofficePath = (basePath: string, value: string): string => {\n const normalizedPath = normalizeAbsolutePath(value);\n const normalizedBasePath = normalizeAbsolutePath(basePath);\n\n if (normalizedBasePath === '/') {\n return normalizedPath;\n }\n if (\n normalizedPath === normalizedBasePath ||\n normalizedPath.startsWith(`${normalizedBasePath}/`)\n ) {\n return normalizedPath;\n }\n if (normalizedPath === '/') {\n return normalizedBasePath;\n }\n return `${normalizedBasePath}${normalizedPath}`;\n};\n\nexport const getBackofficeLoginPath = (basePath: string): string => {\n return prefixBackofficePath(basePath, '/login');\n};\n\nexport const getBackofficePasswordResetPath = (basePath: string): string => {\n return prefixBackofficePath(basePath, '/login/reset');\n};\n\nconst AUTH_ROUTE_SUFFIXES = [\n '/login',\n '/login/reset',\n '/login/reset/complete',\n '/verify-email',\n '/accept-invitation',\n] as const;\n\nexport const isBackofficeAuthPath = (\n basePath: string,\n pathname: string,\n): boolean => {\n const normalizedPathname = normalizeAbsolutePath(pathname);\n return AUTH_ROUTE_SUFFIXES.some((suffix) => {\n return normalizedPathname === prefixBackofficePath(basePath, suffix);\n });\n};\n"],"mappings":";AAAA,IAAM,KAAyB,MAA0B;CACvD,IAAI,EAAM,KAAK,MAAM,MAAM,MAAU,KACnC,OAAO;CAET,IAAI,IAAmB;CAOvB,OANK,EAAM,WAAW,GAAG,MACvB,IAAmB,IAAI,MAErB,EAAiB,SAAS,GAAG,IACxB,EAAiB,MAAM,GAAG,EAAE,IAE9B;AACT,GAEM,KAAwB,GAAkB,MAA0B;CACxE,IAAM,IAAiB,EAAsB,CAAK,GAC5C,IAAqB,EAAsB,CAAQ;CAczD,OAZI,MAAuB,OAIzB,MAAmB,KACnB,EAAe,WAAW,GAAG,EAAmB,EAAE,IAE3C,IAEL,MAAmB,MACd,IAEF,GAAG,IAAqB;AACjC,GAEa,KAA0B,MAC9B,EAAqB,GAAU,QAAQ,GAGnC,KAAkC,MACtC,EAAqB,GAAU,cAAc,GAGhD,IAAsB;CAC1B;CACA;CACA;CACA;CACA;AACF,GAEa,KACX,GACA,MACY;CACZ,IAAM,IAAqB,EAAsB,CAAQ;CACzD,OAAO,EAAoB,MAAM,MACxB,MAAuB,EAAqB,GAAU,CAAM,CACpE;AACH"}
|
|
@@ -131,7 +131,7 @@ function H(a) {
|
|
|
131
131
|
return e.groupId != null && q.set(t, e.groupId), t;
|
|
132
132
|
}), _e = he.map((e) => {
|
|
133
133
|
let t = e.routes.list, n = L(t, I), r = [], a = ({ match: t }) => {
|
|
134
|
-
let n = String(t?.params.id ?? ""), r = typeof t?.params.pagePath == "string" ? t.params.pagePath : null, a = r == null ? e.defaultDetailPageId
|
|
134
|
+
let n = String(t?.params.id ?? ""), r = typeof t?.params.pagePath == "string" ? t.params.pagePath : null, a = r == null ? e.defaultDetailPageId : B(e, r);
|
|
135
135
|
return /* @__PURE__ */ s(i, {
|
|
136
136
|
entityManifest: e,
|
|
137
137
|
id: n,
|
|
@@ -213,7 +213,7 @@ function H(a) {
|
|
|
213
213
|
});
|
|
214
214
|
K.set(i, e.id), r.push(i);
|
|
215
215
|
}
|
|
216
|
-
let o =
|
|
216
|
+
let o = e.detailPages.map((t) => {
|
|
217
217
|
let n = V({
|
|
218
218
|
path: "",
|
|
219
219
|
resourcePage: te,
|
|
@@ -295,7 +295,7 @@ function H(a) {
|
|
|
295
295
|
resourcePage: m,
|
|
296
296
|
prepare: ({ variables: t }) => {
|
|
297
297
|
let n = String(t.id ?? "").trim();
|
|
298
|
-
return { redirectTo: n === "" ? null : e.routes.detailPage(n, e.defaultDetailPageId
|
|
298
|
+
return { redirectTo: n === "" ? null : e.routes.detailPage(n, e.defaultDetailPageId) };
|
|
299
299
|
},
|
|
300
300
|
render: ({ prepared: e }) => {
|
|
301
301
|
let t = e.redirectTo ?? null;
|
|
@@ -337,7 +337,7 @@ function H(a) {
|
|
|
337
337
|
suspenseBoundary: "segment",
|
|
338
338
|
fallback: a,
|
|
339
339
|
prepare: ({ variables: t }) => {
|
|
340
|
-
let n = String(t.id ?? ""), r = typeof t.pagePath == "string" ? t.pagePath : null, i = r == null ? e.defaultDetailPageId
|
|
340
|
+
let n = String(t.id ?? ""), r = typeof t.pagePath == "string" ? t.pagePath : null, i = r == null ? e.defaultDetailPageId : B(e, r);
|
|
341
341
|
return {
|
|
342
342
|
entityId: e.id,
|
|
343
343
|
entityManifest: e,
|