@bygghammar/cms-platform 0.13.0 → 0.14.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/package.json +1 -1
- package/src/platform/index.ts +173 -14
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bygghammar/cms-platform",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.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,
|
package/src/platform/index.ts
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
* Host platform contract.
|
|
3
3
|
*
|
|
4
4
|
* Blocks and inspectors already reach the host through `../host`. Backoffice
|
|
5
|
-
* *screens* additionally need data: pages, forms,
|
|
6
|
-
* Those calls are per-site (each site
|
|
7
|
-
* and auth), while the screens
|
|
8
|
-
*
|
|
9
|
-
* startup.
|
|
5
|
+
* *screens* additionally need data: pages, global sections, forms, submissions,
|
|
6
|
+
* media, SEO, redirects and audit access. Those calls are per-site (each site
|
|
7
|
+
* owns its own database, server functions and auth), while the screens
|
|
8
|
+
* themselves are identical everywhere — so the package declares the contract
|
|
9
|
+
* here and each site registers an adapter at startup.
|
|
10
10
|
*
|
|
11
11
|
* Adapters return plain data. No Supabase client, request or response object
|
|
12
12
|
* ever crosses this boundary, which keeps the package usable by a site that is
|
|
@@ -15,17 +15,60 @@
|
|
|
15
15
|
|
|
16
16
|
import type { Json } from "../i18n/json";
|
|
17
17
|
|
|
18
|
+
/** Contract revision. Bump when a required member is added or changed. */
|
|
19
|
+
export const PLATFORM_DATA_VERSION = 2;
|
|
20
|
+
|
|
21
|
+
export type BlockInstanceLike = {
|
|
22
|
+
id: string;
|
|
23
|
+
type: string;
|
|
24
|
+
name?: string;
|
|
25
|
+
props?: Record<string, unknown>;
|
|
26
|
+
visible?: boolean;
|
|
27
|
+
};
|
|
28
|
+
|
|
18
29
|
export type PageSummary = {
|
|
30
|
+
id: string;
|
|
19
31
|
key: string;
|
|
20
|
-
|
|
32
|
+
name: string;
|
|
33
|
+
isSystem: boolean;
|
|
34
|
+
status: string;
|
|
21
35
|
updatedAt: string | null;
|
|
22
|
-
|
|
36
|
+
currentVersionId: string | null;
|
|
23
37
|
};
|
|
24
38
|
|
|
25
|
-
export type
|
|
26
|
-
|
|
39
|
+
export type PageEditState = {
|
|
40
|
+
page: {
|
|
41
|
+
id: string;
|
|
42
|
+
key: string;
|
|
43
|
+
name: string;
|
|
44
|
+
isSystem: boolean;
|
|
45
|
+
status: string;
|
|
46
|
+
currentVersionId: string | null;
|
|
47
|
+
};
|
|
48
|
+
blocks: BlockInstanceLike[];
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export type PageVersionSummary = {
|
|
52
|
+
id: string;
|
|
27
53
|
versionNo: number;
|
|
28
|
-
|
|
54
|
+
note: string | null;
|
|
55
|
+
createdAt: string | null;
|
|
56
|
+
createdByEmail: string | null;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export type SavePageVersionInput = {
|
|
60
|
+
pageId: string;
|
|
61
|
+
blocks: BlockInstanceLike[];
|
|
62
|
+
publish?: boolean;
|
|
63
|
+
note?: string;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export type GlobalSectionSummary = {
|
|
67
|
+
id: string;
|
|
68
|
+
key: string;
|
|
69
|
+
name: string;
|
|
70
|
+
kind: string | null;
|
|
71
|
+
updatedAt: string | null;
|
|
29
72
|
};
|
|
30
73
|
|
|
31
74
|
export type MediaEntry = {
|
|
@@ -36,17 +79,102 @@ export type MediaEntry = {
|
|
|
36
79
|
updatedAt: string | null;
|
|
37
80
|
};
|
|
38
81
|
|
|
82
|
+
/** A file in the site's media bin (soft-deleted, restorable by id). */
|
|
83
|
+
export type MediaTrashEntry = {
|
|
84
|
+
id: string;
|
|
85
|
+
originalPath: string;
|
|
86
|
+
size: number;
|
|
87
|
+
contentType: string | null;
|
|
88
|
+
deletedAt: string | null;
|
|
89
|
+
url: string;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
export type RedirectEntry = {
|
|
93
|
+
id?: string;
|
|
94
|
+
fromPath: string;
|
|
95
|
+
toPath: string;
|
|
96
|
+
/** 301 or 302. */
|
|
97
|
+
status: number;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* SEO overrides are stored per page key, with per-locale slug and meta maps —
|
|
102
|
+
* one row covers every locale of a page.
|
|
103
|
+
*/
|
|
104
|
+
export type PageSeoRow = {
|
|
105
|
+
pageKey: string;
|
|
106
|
+
/** locale -> slug */
|
|
107
|
+
slugs: Json;
|
|
108
|
+
/** locale -> meta values */
|
|
109
|
+
seo: Json;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
export type FormSummary = {
|
|
113
|
+
id: string;
|
|
114
|
+
key: string;
|
|
115
|
+
name: string;
|
|
116
|
+
updatedAt: string | null;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
export type SubmissionSummary = {
|
|
120
|
+
id: string;
|
|
121
|
+
formKey: string;
|
|
122
|
+
status: string | null;
|
|
123
|
+
createdAt: string | null;
|
|
124
|
+
payload: Json;
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
export type SubmissionQuery = {
|
|
128
|
+
formKey?: string;
|
|
129
|
+
status?: string;
|
|
130
|
+
page?: number;
|
|
131
|
+
pageSize?: number;
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
export type SubmissionPage = {
|
|
135
|
+
rows: SubmissionSummary[];
|
|
136
|
+
total: number;
|
|
137
|
+
};
|
|
138
|
+
|
|
39
139
|
/** Data access the shared backoffice screens need from the host site. */
|
|
40
140
|
export type PlatformData = {
|
|
41
141
|
pages: {
|
|
42
142
|
list: () => Promise<PageSummary[]>;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
143
|
+
loadForEdit: (key: string) => Promise<PageEditState>;
|
|
144
|
+
saveVersion: (input: SavePageVersionInput) => Promise<{ versionId: string; versionNo: number }>;
|
|
145
|
+
listVersions?: (pageId: string) => Promise<PageVersionSummary[]>;
|
|
146
|
+
restoreVersion?: (input: { pageId: string; versionId: string }) => Promise<void>;
|
|
147
|
+
create?: (input: { key: string; name: string }) => Promise<{ id: string }>;
|
|
148
|
+
rename?: (input: { id: string; name: string }) => Promise<void>;
|
|
149
|
+
remove?: (id: string) => Promise<void>;
|
|
150
|
+
};
|
|
151
|
+
globalSections?: {
|
|
152
|
+
list: () => Promise<GlobalSectionSummary[]>;
|
|
153
|
+
loadForEdit: (key: string) => Promise<PageEditState>;
|
|
154
|
+
saveVersion: (input: SavePageVersionInput) => Promise<{ versionId: string; versionNo: number }>;
|
|
46
155
|
};
|
|
47
156
|
media: {
|
|
48
157
|
list: () => Promise<MediaEntry[]>;
|
|
49
|
-
|
|
158
|
+
/** Soft delete a single library path (variants included by the host). */
|
|
159
|
+
remove: (path: string) => Promise<void>;
|
|
160
|
+
listTrash?: () => Promise<MediaTrashEntry[]>;
|
|
161
|
+
restore?: (trashId: string) => Promise<void>;
|
|
162
|
+
purge?: (trashId: string) => Promise<void>;
|
|
163
|
+
};
|
|
164
|
+
seo?: {
|
|
165
|
+
list: () => Promise<PageSeoRow[]>;
|
|
166
|
+
save: (row: PageSeoRow) => Promise<void>;
|
|
167
|
+
removeOverride: (input: { pageKey: string }) => Promise<void>;
|
|
168
|
+
};
|
|
169
|
+
redirects?: {
|
|
170
|
+
list: () => Promise<RedirectEntry[]>;
|
|
171
|
+
save: (entry: RedirectEntry) => Promise<void>;
|
|
172
|
+
remove: (id: string) => Promise<void>;
|
|
173
|
+
};
|
|
174
|
+
forms?: {
|
|
175
|
+
list: () => Promise<FormSummary[]>;
|
|
176
|
+
listSubmissions: (query?: SubmissionQuery) => Promise<SubmissionPage>;
|
|
177
|
+
setSubmissionStatus: (input: { ids: string[]; status: string }) => Promise<void>;
|
|
50
178
|
};
|
|
51
179
|
audit?: {
|
|
52
180
|
log: (event: { action: string; target: string; detail?: Json }) => Promise<void>;
|
|
@@ -61,6 +189,8 @@ export type PlatformSite = {
|
|
|
61
189
|
backofficeBasePath: string;
|
|
62
190
|
/** Public site origin, used for preview links. */
|
|
63
191
|
publicOrigin?: string;
|
|
192
|
+
/** Locales the site authors content in; first entry is the default. */
|
|
193
|
+
locales?: string[];
|
|
64
194
|
};
|
|
65
195
|
|
|
66
196
|
export type HostPlatform = {
|
|
@@ -88,3 +218,32 @@ export function getHostPlatform(): HostPlatform {
|
|
|
88
218
|
export function hasHostPlatform(): boolean {
|
|
89
219
|
return platform !== null;
|
|
90
220
|
}
|
|
221
|
+
|
|
222
|
+
/** Required members every adapter must implement, used by host-side tests. */
|
|
223
|
+
export const REQUIRED_PLATFORM_DATA: Record<string, readonly string[]> = {
|
|
224
|
+
pages: ["list", "loadForEdit", "saveVersion"],
|
|
225
|
+
media: ["list", "remove"],
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Assert an adapter implements every required member. Sites call this in a test
|
|
230
|
+
* (or at startup) so a contract bump fails loudly instead of at click time.
|
|
231
|
+
*/
|
|
232
|
+
export function assertPlatformData(data: PlatformData): void {
|
|
233
|
+
const missing: string[] = [];
|
|
234
|
+
for (const [group, members] of Object.entries(REQUIRED_PLATFORM_DATA)) {
|
|
235
|
+
const bag = (data as unknown as Record<string, Record<string, unknown> | undefined>)[group];
|
|
236
|
+
if (!bag) {
|
|
237
|
+
missing.push(group);
|
|
238
|
+
continue;
|
|
239
|
+
}
|
|
240
|
+
for (const member of members) {
|
|
241
|
+
if (typeof bag[member] !== "function") missing.push(`${group}.${member}`);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
if (missing.length > 0) {
|
|
245
|
+
throw new Error(
|
|
246
|
+
`@bygghammar/cms-platform: host platform adapter is missing ${missing.join(", ")}`,
|
|
247
|
+
);
|
|
248
|
+
}
|
|
249
|
+
}
|