@bygghammar/cms-platform 0.40.0 → 0.41.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/CHANGELOG.md +7 -0
- package/package.json +4 -2
- package/src/backoffice/routes/host.ts +93 -0
- package/src/backoffice/routes/index.tsx +231 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.41.0
|
|
4
|
+
|
|
5
|
+
- New `backoffice/routes`: a host registry (`registerBackofficeHost`) plus package-owned
|
|
6
|
+
route components for audit, email logs, log index, roles, users, version, site
|
|
7
|
+
settings, redirects, tracking, contact details and form settings. A site route
|
|
8
|
+
file is now just `createFileRoute(...)({ component: XRoute })`.
|
|
9
|
+
|
|
3
10
|
## 0.40.0
|
|
4
11
|
|
|
5
12
|
- New `backoffice/shell`: shared `BackofficeShell` (auth gate, no-access screen,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bygghammar/cms-platform",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.41.0",
|
|
4
4
|
"description": "Shared CMS platform: blocks, block types, i18n core, UI primitives and design-token contract used by every Bygghammar/Voyara site.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -155,7 +155,9 @@
|
|
|
155
155
|
"./server/forms-delivery-core": "./src/server/forms-delivery-core.ts",
|
|
156
156
|
"./server/forms-submissions-core": "./src/server/forms-submissions-core.ts",
|
|
157
157
|
"./server/backup-core": "./src/server/backup-core.ts",
|
|
158
|
-
"./backoffice/shell": "./src/backoffice/shell/index.ts"
|
|
158
|
+
"./backoffice/shell": "./src/backoffice/shell/index.ts",
|
|
159
|
+
"./backoffice/routes": "./src/backoffice/routes/index.tsx",
|
|
160
|
+
"./backoffice/routes/host": "./src/backoffice/routes/host.ts"
|
|
159
161
|
},
|
|
160
162
|
"dependencies": {
|
|
161
163
|
"fflate": "^0.8.3"
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Backoffice host registry.
|
|
3
|
+
*
|
|
4
|
+
* A site registers its server functions and site-level facts once; the package
|
|
5
|
+
* then owns the backoffice route components themselves, so a site's route file
|
|
6
|
+
* is a two-line `createFileRoute(...)({ component: XRoute })`.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import type { SiteConfig } from "../../config/site-config";
|
|
10
|
+
|
|
11
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
12
|
+
/** A TanStack server function as seen from the host (called via `useServerFn`). */
|
|
13
|
+
export type HostServerFn = (...args: any[]) => Promise<any>;
|
|
14
|
+
/* eslint-enable @typescript-eslint/no-explicit-any */
|
|
15
|
+
|
|
16
|
+
/** Everything the package needs from a host to render the backoffice routes. */
|
|
17
|
+
export type BackofficeHost = {
|
|
18
|
+
/** Site configuration used for defaults on the settings screen. */
|
|
19
|
+
siteConfig: SiteConfig;
|
|
20
|
+
/** Locales the site publishes, used by tracking/domain screens. */
|
|
21
|
+
locales: readonly string[];
|
|
22
|
+
/** Role identifiers this platform build supports. */
|
|
23
|
+
allRoles: string[];
|
|
24
|
+
/** Company details used as code defaults on the contact screen. */
|
|
25
|
+
company: Record<string, string>;
|
|
26
|
+
/** Locale used to preview form copy in the backoffice. */
|
|
27
|
+
previewLocale?: string;
|
|
28
|
+
/** Server functions, grouped per module. */
|
|
29
|
+
fns: {
|
|
30
|
+
// admin
|
|
31
|
+
listAuditLogs: HostServerFn;
|
|
32
|
+
listEmailLogs: HostServerFn;
|
|
33
|
+
listUsers: HostServerFn;
|
|
34
|
+
getMyRoles: HostServerFn;
|
|
35
|
+
createUser: HostServerFn;
|
|
36
|
+
deleteUser: HostServerFn;
|
|
37
|
+
setUserPassword: HostServerFn;
|
|
38
|
+
sendPasswordResetEmail: HostServerFn;
|
|
39
|
+
setUserRoles: HostServerFn;
|
|
40
|
+
getSystemVersion: HostServerFn;
|
|
41
|
+
// site settings
|
|
42
|
+
getSiteSettings: HostServerFn;
|
|
43
|
+
saveSiteSettings: HostServerFn;
|
|
44
|
+
clearSiteSetting: HostServerFn;
|
|
45
|
+
// redirects
|
|
46
|
+
listRedirects: HostServerFn;
|
|
47
|
+
saveRedirect: HostServerFn;
|
|
48
|
+
deleteRedirect: HostServerFn;
|
|
49
|
+
// tracking + domains
|
|
50
|
+
listInjections: HostServerFn;
|
|
51
|
+
saveInjection: HostServerFn;
|
|
52
|
+
deleteInjection: HostServerFn;
|
|
53
|
+
getLocaleDomains: HostServerFn;
|
|
54
|
+
// shared content
|
|
55
|
+
getContentOverrides: HostServerFn;
|
|
56
|
+
saveContentSection: HostServerFn;
|
|
57
|
+
// forms
|
|
58
|
+
getFormDefaults: HostServerFn;
|
|
59
|
+
saveFormDefaults: HostServerFn;
|
|
60
|
+
purgeOldSubmissions: HostServerFn;
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
let current: BackofficeHost | null = null;
|
|
65
|
+
|
|
66
|
+
/** Registers the host adapters. Call once, from a module the routes import. */
|
|
67
|
+
export function registerBackofficeHost(host: BackofficeHost): BackofficeHost {
|
|
68
|
+
current = host;
|
|
69
|
+
return host;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Reads the registered host, failing loudly when a site forgot to register. */
|
|
73
|
+
export function backofficeHost(): BackofficeHost {
|
|
74
|
+
if (!current) {
|
|
75
|
+
throw new Error(
|
|
76
|
+
"Backoffice host not registered — call registerBackofficeHost() before rendering backoffice routes.",
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
return current;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** Absolute backoffice paths derived from the site's configured base path. */
|
|
83
|
+
export function backofficePaths(host: BackofficeHost = backofficeHost()) {
|
|
84
|
+
const base = host.siteConfig.backofficePath;
|
|
85
|
+
return {
|
|
86
|
+
base,
|
|
87
|
+
admin: `${base}/admin`,
|
|
88
|
+
audit: `${base}/admin/audit`,
|
|
89
|
+
emailLogs: `${base}/admin/email-logs`,
|
|
90
|
+
users: `${base}/admin/users`,
|
|
91
|
+
forms: `${base}/forms`,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Package-owned backoffice route components.
|
|
3
|
+
*
|
|
4
|
+
* Each component is a complete screen: it reads the host adapters from the
|
|
5
|
+
* registry, wires queries/mutations and renders the shared view. A site route
|
|
6
|
+
* file only maps a URL to one of these.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { Link, useNavigate } from "@tanstack/react-router";
|
|
10
|
+
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
|
11
|
+
import { useServerFn } from "@tanstack/react-start";
|
|
12
|
+
|
|
13
|
+
import type { SiteSettingOverrides } from "../../config/site-config";
|
|
14
|
+
import { AuditView } from "../AuditView";
|
|
15
|
+
import { ContactDetailsView } from "../ContactDetailsView";
|
|
16
|
+
import { EmailLogsView } from "../EmailLogsView";
|
|
17
|
+
import { FormSettingsView } from "../FormSettingsView";
|
|
18
|
+
import { LogsView } from "../LogsView";
|
|
19
|
+
import { RedirectsView } from "../RedirectsView";
|
|
20
|
+
import { RolesView } from "../RolesView";
|
|
21
|
+
import { SiteSettingsView } from "../SiteSettingsView";
|
|
22
|
+
import { TrackingView } from "../TrackingView";
|
|
23
|
+
import { UsersView } from "../UsersView";
|
|
24
|
+
import { VersionView } from "../VersionView";
|
|
25
|
+
import { backofficeHost, backofficePaths } from "./host";
|
|
26
|
+
|
|
27
|
+
export * from "./host";
|
|
28
|
+
|
|
29
|
+
/** Audit trail screen. */
|
|
30
|
+
export function AuditRoute() {
|
|
31
|
+
const { fns } = backofficeHost();
|
|
32
|
+
const fetchLogs = useServerFn(fns.listAuditLogs);
|
|
33
|
+
const q = useQuery({
|
|
34
|
+
queryKey: ["admin", "audit"],
|
|
35
|
+
queryFn: () => fetchLogs({ data: { limit: 300 } }),
|
|
36
|
+
});
|
|
37
|
+
return <AuditView rows={(q.data ?? []) as never} />;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Outbound email log screen. */
|
|
41
|
+
export function EmailLogsRoute() {
|
|
42
|
+
const { fns } = backofficeHost();
|
|
43
|
+
const fetchLogs = useServerFn(fns.listEmailLogs);
|
|
44
|
+
const q = useQuery({
|
|
45
|
+
queryKey: ["admin", "email-logs"],
|
|
46
|
+
queryFn: () => fetchLogs({ data: { limit: 300 } }),
|
|
47
|
+
});
|
|
48
|
+
return <EmailLogsView rows={(q.data ?? []) as never} />;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Log index linking the audit trail and email log. */
|
|
52
|
+
export function LogsRoute() {
|
|
53
|
+
const paths = backofficePaths();
|
|
54
|
+
return <LogsView auditPath={paths.audit} emailLogsPath={paths.emailLogs} />;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Role reference screen. */
|
|
58
|
+
export function RolesRoute() {
|
|
59
|
+
const host = backofficeHost();
|
|
60
|
+
return <RolesView allRoles={host.allRoles} usersPath={backofficePaths(host).users} />;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** User administration screen. */
|
|
64
|
+
export function UsersRoute() {
|
|
65
|
+
const { fns, allRoles } = backofficeHost();
|
|
66
|
+
const qc = useQueryClient();
|
|
67
|
+
const fetchUsers = useServerFn(fns.listUsers);
|
|
68
|
+
const fetchMyRoles = useServerFn(fns.getMyRoles);
|
|
69
|
+
const runCreate = useServerFn(fns.createUser);
|
|
70
|
+
const runDelete = useServerFn(fns.deleteUser);
|
|
71
|
+
const runSetPw = useServerFn(fns.setUserPassword);
|
|
72
|
+
const runReset = useServerFn(fns.sendPasswordResetEmail);
|
|
73
|
+
const runSetRoles = useServerFn(fns.setUserRoles);
|
|
74
|
+
|
|
75
|
+
const usersQ = useQuery({ queryKey: ["admin", "users"], queryFn: () => fetchUsers() });
|
|
76
|
+
const myRolesQ = useQuery({ queryKey: ["admin", "my-roles"], queryFn: () => fetchMyRoles() });
|
|
77
|
+
|
|
78
|
+
return (
|
|
79
|
+
<UsersView
|
|
80
|
+
deps={{
|
|
81
|
+
users: (usersQ.data ?? []) as never,
|
|
82
|
+
myRoles: myRolesQ.data ?? [],
|
|
83
|
+
allRoles,
|
|
84
|
+
createUser: (input) => runCreate(input as never),
|
|
85
|
+
deleteUser: (input) => runDelete(input),
|
|
86
|
+
setUserPassword: (input) => runSetPw(input),
|
|
87
|
+
sendPasswordResetEmail: (input) => runReset(input),
|
|
88
|
+
setUserRoles: (input) => runSetRoles(input as never),
|
|
89
|
+
refresh: () => qc.invalidateQueries({ queryKey: ["admin", "users"] }),
|
|
90
|
+
}}
|
|
91
|
+
/>
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** CMS build and platform version screen. */
|
|
96
|
+
export function VersionRoute() {
|
|
97
|
+
const { fns } = backofficeHost();
|
|
98
|
+
const fetchVersion = useServerFn(fns.getSystemVersion);
|
|
99
|
+
const q = useQuery({ queryKey: ["admin", "system-version"], queryFn: () => fetchVersion() });
|
|
100
|
+
return (
|
|
101
|
+
<VersionView
|
|
102
|
+
deps={{ build: q.data?.build, releases: q.data?.releases ?? [], loading: q.isLoading }}
|
|
103
|
+
/>
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** Site settings screen (code defaults plus database overrides). */
|
|
108
|
+
export function SiteSettingsRoute() {
|
|
109
|
+
const { fns, siteConfig } = backofficeHost();
|
|
110
|
+
const load = useServerFn(fns.getSiteSettings);
|
|
111
|
+
const save = useServerFn(fns.saveSiteSettings);
|
|
112
|
+
const clear = useServerFn(fns.clearSiteSetting);
|
|
113
|
+
const q = useQuery({ queryKey: ["admin", "site-settings"], queryFn: () => load() });
|
|
114
|
+
|
|
115
|
+
return (
|
|
116
|
+
<SiteSettingsView
|
|
117
|
+
deps={{
|
|
118
|
+
config: q.data?.config ?? siteConfig,
|
|
119
|
+
overrides: (q.data?.overrides ?? {}) as SiteSettingOverrides,
|
|
120
|
+
saveSettings: (input) => save(input as never),
|
|
121
|
+
clearSetting: (input) => clear(input as never),
|
|
122
|
+
refresh: () => q.refetch(),
|
|
123
|
+
originSource: q.data?.originSource ?? "code",
|
|
124
|
+
}}
|
|
125
|
+
/>
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** URL redirect administration. */
|
|
130
|
+
export function RedirectsRoute() {
|
|
131
|
+
const { fns } = backofficeHost();
|
|
132
|
+
const list = useServerFn(fns.listRedirects);
|
|
133
|
+
const save = useServerFn(fns.saveRedirect);
|
|
134
|
+
const remove = useServerFn(fns.deleteRedirect);
|
|
135
|
+
const q = useQuery({ queryKey: ["cms", "redirects"], queryFn: () => list() });
|
|
136
|
+
|
|
137
|
+
return (
|
|
138
|
+
<RedirectsView
|
|
139
|
+
deps={{
|
|
140
|
+
rows: q.data ?? [],
|
|
141
|
+
saveRedirect: (input) => save(input),
|
|
142
|
+
deleteRedirect: (input) => remove(input),
|
|
143
|
+
refresh: () => q.refetch(),
|
|
144
|
+
}}
|
|
145
|
+
/>
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** Code & tracking injection screen. */
|
|
150
|
+
export function TrackingRoute() {
|
|
151
|
+
const { fns, locales } = backofficeHost();
|
|
152
|
+
const list = useServerFn(fns.listInjections);
|
|
153
|
+
const save = useServerFn(fns.saveInjection);
|
|
154
|
+
const remove = useServerFn(fns.deleteInjection);
|
|
155
|
+
const domains = useServerFn(fns.getLocaleDomains);
|
|
156
|
+
|
|
157
|
+
const q = useQuery({ queryKey: ["admin", "injections"], queryFn: () => list() });
|
|
158
|
+
const domainsQ = useQuery({ queryKey: ["admin", "locale-domains"], queryFn: () => domains() });
|
|
159
|
+
|
|
160
|
+
return (
|
|
161
|
+
<TrackingView
|
|
162
|
+
deps={{
|
|
163
|
+
profiles: q.data ?? [],
|
|
164
|
+
domains: domainsQ.data ?? [],
|
|
165
|
+
locales: locales as never,
|
|
166
|
+
saveInjection: (input) => save(input as never),
|
|
167
|
+
deleteInjection: (input) => remove(input),
|
|
168
|
+
refresh: () => q.refetch(),
|
|
169
|
+
}}
|
|
170
|
+
/>
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** Company contact details screen. */
|
|
175
|
+
export function ContactDetailsRoute() {
|
|
176
|
+
const { fns, company } = backofficeHost();
|
|
177
|
+
const fetchOverrides = useServerFn(fns.getContentOverrides);
|
|
178
|
+
const save = useServerFn(fns.saveContentSection);
|
|
179
|
+
const qc = useQueryClient();
|
|
180
|
+
const overridesQ = useQuery({
|
|
181
|
+
queryKey: ["cms", "content-overrides"],
|
|
182
|
+
queryFn: () => fetchOverrides(),
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
return (
|
|
186
|
+
<ContactDetailsView
|
|
187
|
+
deps={{
|
|
188
|
+
defaults: company,
|
|
189
|
+
stored: overridesQ.data?.company as Record<string, string> | undefined,
|
|
190
|
+
loading: overridesQ.isLoading,
|
|
191
|
+
saveSection: (input) => save(input as never),
|
|
192
|
+
refresh: () => qc.invalidateQueries({ queryKey: ["cms", "content-overrides"] }),
|
|
193
|
+
}}
|
|
194
|
+
/>
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/** Form defaults and retention screen. */
|
|
199
|
+
export function FormSettingsRoute() {
|
|
200
|
+
const host = backofficeHost();
|
|
201
|
+
const { fns } = host;
|
|
202
|
+
const load = useServerFn(fns.getFormDefaults);
|
|
203
|
+
const save = useServerFn(fns.saveFormDefaults);
|
|
204
|
+
const purge = useServerFn(fns.purgeOldSubmissions);
|
|
205
|
+
const formsPath = backofficePaths(host).forms;
|
|
206
|
+
const { data, isLoading } = useQuery({ queryKey: ["form-defaults"], queryFn: () => load() });
|
|
207
|
+
|
|
208
|
+
return (
|
|
209
|
+
<FormSettingsView
|
|
210
|
+
deps={{
|
|
211
|
+
defaults: data,
|
|
212
|
+
isLoading,
|
|
213
|
+
saveDefaults: (input) => save(input as never),
|
|
214
|
+
purgeOldSubmissions: (input) => purge(input),
|
|
215
|
+
previewLocale: host.previewLocale ?? host.siteConfig.defaultLocale,
|
|
216
|
+
BackLink: ({ className, children }) => (
|
|
217
|
+
<Link to={formsPath} className={className}>
|
|
218
|
+
{children}
|
|
219
|
+
</Link>
|
|
220
|
+
),
|
|
221
|
+
}}
|
|
222
|
+
/>
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/** Shared-content SEO detail helper: back navigation to the SEO list. */
|
|
227
|
+
export function useSeoListNavigate() {
|
|
228
|
+
const navigate = useNavigate();
|
|
229
|
+
const paths = backofficePaths();
|
|
230
|
+
return () => navigate({ to: `${paths.base}/seo` });
|
|
231
|
+
}
|