admin-lib-cms 1.0.5
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 +248 -0
- package/dist/auth.d.mts +15 -0
- package/dist/auth.d.ts +15 -0
- package/dist/auth.js +122 -0
- package/dist/auth.mjs +87 -0
- package/dist/chunk-6DZX6EAA.mjs +37 -0
- package/dist/chunk-CQW7KMB2.mjs +120 -0
- package/dist/email.d.mts +3 -0
- package/dist/email.d.ts +3 -0
- package/dist/email.js +144 -0
- package/dist/email.mjs +6 -0
- package/dist/index.d.mts +126 -0
- package/dist/index.d.ts +126 -0
- package/dist/index.js +2344 -0
- package/dist/index.mjs +2223 -0
- package/dist/storage.d.mts +25 -0
- package/dist/storage.d.ts +25 -0
- package/dist/storage.js +412 -0
- package/dist/storage.mjs +383 -0
- package/dist/types-uBvGNd4_.d.mts +78 -0
- package/dist/types-uBvGNd4_.d.ts +78 -0
- package/dist/types.d.mts +78 -0
- package/dist/types.d.ts +78 -0
- package/dist/types.js +18 -0
- package/dist/types.mjs +0 -0
- package/package.json +90 -0
package/dist/storage.mjs
ADDED
|
@@ -0,0 +1,383 @@
|
|
|
1
|
+
// src/storage/localStorage.ts
|
|
2
|
+
var KEY_OVERRIDES = "admin-cms:overrides";
|
|
3
|
+
var KEY_COLL = (id) => `admin-cms:coll:${id}`;
|
|
4
|
+
var KEY_SUBMISSIONS = "admin-cms:submissions";
|
|
5
|
+
function safeParse(raw, fallback) {
|
|
6
|
+
if (!raw) return fallback;
|
|
7
|
+
try {
|
|
8
|
+
return JSON.parse(raw);
|
|
9
|
+
} catch {
|
|
10
|
+
return fallback;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
function createLocalStorageAdapter() {
|
|
14
|
+
const isBrowser = typeof window !== "undefined" && !!window.localStorage;
|
|
15
|
+
return {
|
|
16
|
+
name: "localStorage",
|
|
17
|
+
async getOverrides() {
|
|
18
|
+
if (!isBrowser) return {};
|
|
19
|
+
return safeParse(localStorage.getItem(KEY_OVERRIDES), {});
|
|
20
|
+
},
|
|
21
|
+
async setOverrides(map) {
|
|
22
|
+
if (!isBrowser) return;
|
|
23
|
+
localStorage.setItem(KEY_OVERRIDES, JSON.stringify(map));
|
|
24
|
+
},
|
|
25
|
+
async listEntries(collectionId) {
|
|
26
|
+
if (!isBrowser) return [];
|
|
27
|
+
return safeParse(
|
|
28
|
+
localStorage.getItem(KEY_COLL(collectionId)),
|
|
29
|
+
[]
|
|
30
|
+
);
|
|
31
|
+
},
|
|
32
|
+
async putEntry(collectionId, entry) {
|
|
33
|
+
if (!isBrowser) return;
|
|
34
|
+
const list = safeParse(
|
|
35
|
+
localStorage.getItem(KEY_COLL(collectionId)),
|
|
36
|
+
[]
|
|
37
|
+
);
|
|
38
|
+
const idx = list.findIndex((e) => e.id === entry.id);
|
|
39
|
+
if (idx >= 0) list[idx] = entry;
|
|
40
|
+
else list.push(entry);
|
|
41
|
+
localStorage.setItem(KEY_COLL(collectionId), JSON.stringify(list));
|
|
42
|
+
},
|
|
43
|
+
async deleteEntry(collectionId, entryId) {
|
|
44
|
+
if (!isBrowser) return;
|
|
45
|
+
const list = safeParse(
|
|
46
|
+
localStorage.getItem(KEY_COLL(collectionId)),
|
|
47
|
+
[]
|
|
48
|
+
);
|
|
49
|
+
localStorage.setItem(
|
|
50
|
+
KEY_COLL(collectionId),
|
|
51
|
+
JSON.stringify(list.filter((e) => e.id !== entryId))
|
|
52
|
+
);
|
|
53
|
+
},
|
|
54
|
+
async saveSubmission(submission) {
|
|
55
|
+
if (!isBrowser) return;
|
|
56
|
+
const list = safeParse(localStorage.getItem(KEY_SUBMISSIONS), []);
|
|
57
|
+
list.unshift(submission);
|
|
58
|
+
localStorage.setItem(KEY_SUBMISSIONS, JSON.stringify(list));
|
|
59
|
+
},
|
|
60
|
+
async listSubmissions(formId) {
|
|
61
|
+
if (!isBrowser) return [];
|
|
62
|
+
const list = safeParse(localStorage.getItem(KEY_SUBMISSIONS), []);
|
|
63
|
+
if (formId) return list.filter((s) => s.formId === formId);
|
|
64
|
+
return list;
|
|
65
|
+
},
|
|
66
|
+
async deleteSubmission(id) {
|
|
67
|
+
if (!isBrowser) return;
|
|
68
|
+
const list = safeParse(localStorage.getItem(KEY_SUBMISSIONS), []);
|
|
69
|
+
localStorage.setItem(KEY_SUBMISSIONS, JSON.stringify(list.filter((s) => s.id !== id)));
|
|
70
|
+
},
|
|
71
|
+
async markSubmissionRead(id) {
|
|
72
|
+
if (!isBrowser) return;
|
|
73
|
+
const list = safeParse(localStorage.getItem(KEY_SUBMISSIONS), []);
|
|
74
|
+
const idx = list.findIndex((s) => s.id === id);
|
|
75
|
+
if (idx >= 0) list[idx].read = true;
|
|
76
|
+
localStorage.setItem(KEY_SUBMISSIONS, JSON.stringify(list));
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// src/storage/memory.ts
|
|
82
|
+
function createMemoryAdapter() {
|
|
83
|
+
let overrides = {};
|
|
84
|
+
const collections = /* @__PURE__ */ new Map();
|
|
85
|
+
let submissions = [];
|
|
86
|
+
return {
|
|
87
|
+
name: "memory",
|
|
88
|
+
async getOverrides() {
|
|
89
|
+
return { ...overrides };
|
|
90
|
+
},
|
|
91
|
+
async setOverrides(map) {
|
|
92
|
+
overrides = { ...map };
|
|
93
|
+
},
|
|
94
|
+
async listEntries(id) {
|
|
95
|
+
return [...collections.get(id) ?? []];
|
|
96
|
+
},
|
|
97
|
+
async putEntry(id, entry) {
|
|
98
|
+
const list = collections.get(id) ?? [];
|
|
99
|
+
const idx = list.findIndex((e) => e.id === entry.id);
|
|
100
|
+
if (idx >= 0) list[idx] = entry;
|
|
101
|
+
else list.push(entry);
|
|
102
|
+
collections.set(id, list);
|
|
103
|
+
},
|
|
104
|
+
async deleteEntry(id, entryId) {
|
|
105
|
+
const list = collections.get(id) ?? [];
|
|
106
|
+
collections.set(
|
|
107
|
+
id,
|
|
108
|
+
list.filter((e) => e.id !== entryId)
|
|
109
|
+
);
|
|
110
|
+
},
|
|
111
|
+
async saveSubmission(submission) {
|
|
112
|
+
submissions.unshift(submission);
|
|
113
|
+
},
|
|
114
|
+
async listSubmissions(formId) {
|
|
115
|
+
if (formId) return submissions.filter((s) => s.formId === formId);
|
|
116
|
+
return [...submissions];
|
|
117
|
+
},
|
|
118
|
+
async deleteSubmission(id) {
|
|
119
|
+
submissions = submissions.filter((s) => s.id !== id);
|
|
120
|
+
},
|
|
121
|
+
async markSubmissionRead(id) {
|
|
122
|
+
const s = submissions.find((s2) => s2.id === id);
|
|
123
|
+
if (s) s.read = true;
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// src/storage/sanity.ts
|
|
129
|
+
import { createClient } from "@sanity/client";
|
|
130
|
+
var OVERRIDES_DOC_ID = "cms_overrides_global";
|
|
131
|
+
function createReadClient(config) {
|
|
132
|
+
return createClient({
|
|
133
|
+
projectId: config.projectId,
|
|
134
|
+
dataset: config.dataset,
|
|
135
|
+
useCdn: true,
|
|
136
|
+
apiVersion: config.apiVersion || "2024-01-01"
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
function createWriteClient(config) {
|
|
140
|
+
return createClient({
|
|
141
|
+
projectId: config.projectId,
|
|
142
|
+
dataset: config.dataset,
|
|
143
|
+
useCdn: false,
|
|
144
|
+
apiVersion: config.apiVersion || "2024-01-01",
|
|
145
|
+
token: config.token
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
async function apiRequest(apiBase, path, init) {
|
|
149
|
+
const res = await fetch(`${apiBase}${path}`, init);
|
|
150
|
+
if (!res.ok) {
|
|
151
|
+
const text = await res.text();
|
|
152
|
+
throw new Error(text || `API error ${res.status}`);
|
|
153
|
+
}
|
|
154
|
+
if (res.status === 204) return void 0;
|
|
155
|
+
return res.json();
|
|
156
|
+
}
|
|
157
|
+
function createSanityAdapter(config) {
|
|
158
|
+
const readClient = createReadClient(config);
|
|
159
|
+
const writeClient = config.token ? createWriteClient(config) : null;
|
|
160
|
+
const apiBase = config.apiBase?.replace(/\/$/, "");
|
|
161
|
+
async function writeOverrides(map) {
|
|
162
|
+
if (apiBase) {
|
|
163
|
+
await apiRequest(apiBase, "/overrides", {
|
|
164
|
+
method: "PUT",
|
|
165
|
+
headers: { "Content-Type": "application/json" },
|
|
166
|
+
body: JSON.stringify(map)
|
|
167
|
+
});
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
if (!writeClient) {
|
|
171
|
+
console.warn("Sanity Adapter: No token or apiBase, cannot write overrides.");
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
await writeClient.transaction().createIfNotExists({ _id: OVERRIDES_DOC_ID, _type: "cms_overrides" }).patch(OVERRIDES_DOC_ID, (p) => p.set({ data: JSON.stringify(map) })).commit();
|
|
175
|
+
}
|
|
176
|
+
async function writeEntry(collectionId, entry) {
|
|
177
|
+
if (apiBase) {
|
|
178
|
+
await apiRequest(apiBase, "/entries", {
|
|
179
|
+
method: "PUT",
|
|
180
|
+
headers: { "Content-Type": "application/json" },
|
|
181
|
+
body: JSON.stringify({ collectionId, entry })
|
|
182
|
+
});
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
if (!writeClient) {
|
|
186
|
+
console.warn("Sanity Adapter: No token or apiBase, cannot write entry.");
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
const docId = `cms_entry_${collectionId}_${entry.id}`;
|
|
190
|
+
await writeClient.transaction().createIfNotExists({
|
|
191
|
+
_id: docId,
|
|
192
|
+
_type: "cms_entry",
|
|
193
|
+
collectionId,
|
|
194
|
+
entryId: entry.id
|
|
195
|
+
}).patch(docId, (p) => p.set({ data: JSON.stringify(entry) })).commit();
|
|
196
|
+
}
|
|
197
|
+
async function removeEntry(collectionId, entryId) {
|
|
198
|
+
if (apiBase) {
|
|
199
|
+
await apiRequest(
|
|
200
|
+
apiBase,
|
|
201
|
+
`/entries?collectionId=${encodeURIComponent(collectionId)}&entryId=${encodeURIComponent(entryId)}`,
|
|
202
|
+
{ method: "DELETE" }
|
|
203
|
+
);
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
if (!writeClient) {
|
|
207
|
+
console.warn("Sanity Adapter: No token or apiBase, cannot delete entry.");
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
await writeClient.delete(`cms_entry_${collectionId}_${entryId}`);
|
|
211
|
+
}
|
|
212
|
+
return {
|
|
213
|
+
name: "sanity",
|
|
214
|
+
async getOverrides() {
|
|
215
|
+
try {
|
|
216
|
+
if (apiBase) {
|
|
217
|
+
return await apiRequest(apiBase, "/overrides");
|
|
218
|
+
}
|
|
219
|
+
const doc = await readClient.getDocument(OVERRIDES_DOC_ID);
|
|
220
|
+
if (doc && typeof doc.data === "string") {
|
|
221
|
+
return JSON.parse(doc.data);
|
|
222
|
+
}
|
|
223
|
+
} catch (err) {
|
|
224
|
+
console.error("Sanity Adapter: failed to fetch overrides", err);
|
|
225
|
+
}
|
|
226
|
+
return {};
|
|
227
|
+
},
|
|
228
|
+
async setOverrides(map) {
|
|
229
|
+
try {
|
|
230
|
+
await writeOverrides(map);
|
|
231
|
+
} catch (err) {
|
|
232
|
+
console.error("Sanity Adapter: failed to save overrides", err);
|
|
233
|
+
}
|
|
234
|
+
},
|
|
235
|
+
async listEntries(collectionId) {
|
|
236
|
+
try {
|
|
237
|
+
if (apiBase) {
|
|
238
|
+
return await apiRequest(
|
|
239
|
+
apiBase,
|
|
240
|
+
`/entries?collectionId=${encodeURIComponent(collectionId)}`
|
|
241
|
+
);
|
|
242
|
+
}
|
|
243
|
+
const query = `*[_type == "cms_entry" && collectionId == $collectionId]`;
|
|
244
|
+
const docs = await readClient.fetch(query, { collectionId });
|
|
245
|
+
return docs.map((doc) => JSON.parse(doc.data));
|
|
246
|
+
} catch (err) {
|
|
247
|
+
console.error(
|
|
248
|
+
`Sanity Adapter: failed to list entries for ${collectionId}`,
|
|
249
|
+
err
|
|
250
|
+
);
|
|
251
|
+
return [];
|
|
252
|
+
}
|
|
253
|
+
},
|
|
254
|
+
async putEntry(collectionId, entry) {
|
|
255
|
+
try {
|
|
256
|
+
await writeEntry(collectionId, entry);
|
|
257
|
+
} catch (err) {
|
|
258
|
+
console.error(`Sanity Adapter: failed to save entry ${entry.id}`, err);
|
|
259
|
+
}
|
|
260
|
+
},
|
|
261
|
+
async deleteEntry(collectionId, entryId) {
|
|
262
|
+
try {
|
|
263
|
+
await removeEntry(collectionId, entryId);
|
|
264
|
+
} catch (err) {
|
|
265
|
+
console.error(`Sanity Adapter: failed to delete entry ${entryId}`, err);
|
|
266
|
+
}
|
|
267
|
+
},
|
|
268
|
+
async saveSubmission(submission) {
|
|
269
|
+
try {
|
|
270
|
+
if (apiBase) {
|
|
271
|
+
await apiRequest(apiBase, "/submissions", {
|
|
272
|
+
method: "POST",
|
|
273
|
+
headers: { "Content-Type": "application/json" },
|
|
274
|
+
body: JSON.stringify(submission)
|
|
275
|
+
});
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
if (!writeClient) {
|
|
279
|
+
console.warn("Sanity Adapter: No token or apiBase, cannot save submission.");
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
const docId = `cms_submission_${submission.id}`;
|
|
283
|
+
await writeClient.transaction().createIfNotExists({
|
|
284
|
+
_id: docId,
|
|
285
|
+
_type: "cms_submission",
|
|
286
|
+
submissionId: submission.id,
|
|
287
|
+
formId: submission.formId
|
|
288
|
+
}).patch(
|
|
289
|
+
docId,
|
|
290
|
+
(p) => p.set({
|
|
291
|
+
submittedAt: submission.submittedAt,
|
|
292
|
+
data: JSON.stringify(submission.data),
|
|
293
|
+
read: submission.read ?? false
|
|
294
|
+
})
|
|
295
|
+
).commit();
|
|
296
|
+
} catch (err) {
|
|
297
|
+
console.error("Sanity Adapter: failed to save submission", err);
|
|
298
|
+
}
|
|
299
|
+
},
|
|
300
|
+
async listSubmissions(formId) {
|
|
301
|
+
try {
|
|
302
|
+
if (apiBase) {
|
|
303
|
+
const qs = formId ? `?formId=${encodeURIComponent(formId)}` : "";
|
|
304
|
+
return await apiRequest(apiBase, `/submissions${qs}`);
|
|
305
|
+
}
|
|
306
|
+
const query = formId ? `*[_type == "cms_submission" && formId == $formId] | order(submittedAt desc)` : `*[_type == "cms_submission"] | order(submittedAt desc)`;
|
|
307
|
+
const docs = await readClient.fetch(query, formId ? { formId } : {});
|
|
308
|
+
return docs.map(
|
|
309
|
+
(doc) => ({
|
|
310
|
+
id: doc.submissionId,
|
|
311
|
+
formId: doc.formId,
|
|
312
|
+
submittedAt: doc.submittedAt,
|
|
313
|
+
data: JSON.parse(doc.data),
|
|
314
|
+
read: doc.read ?? false
|
|
315
|
+
})
|
|
316
|
+
);
|
|
317
|
+
} catch (err) {
|
|
318
|
+
console.error("Sanity Adapter: failed to list submissions", err);
|
|
319
|
+
return [];
|
|
320
|
+
}
|
|
321
|
+
},
|
|
322
|
+
async deleteSubmission(id) {
|
|
323
|
+
try {
|
|
324
|
+
if (apiBase) {
|
|
325
|
+
await apiRequest(
|
|
326
|
+
apiBase,
|
|
327
|
+
`/submissions?id=${encodeURIComponent(id)}`,
|
|
328
|
+
{ method: "DELETE" }
|
|
329
|
+
);
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
if (!writeClient) return;
|
|
333
|
+
await writeClient.delete(`cms_submission_${id}`);
|
|
334
|
+
} catch (err) {
|
|
335
|
+
console.error("Sanity Adapter: failed to delete submission", err);
|
|
336
|
+
}
|
|
337
|
+
},
|
|
338
|
+
async markSubmissionRead(id) {
|
|
339
|
+
try {
|
|
340
|
+
if (apiBase) {
|
|
341
|
+
await apiRequest(apiBase, "/submissions", {
|
|
342
|
+
method: "PATCH",
|
|
343
|
+
headers: { "Content-Type": "application/json" },
|
|
344
|
+
body: JSON.stringify({ id })
|
|
345
|
+
});
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
if (!writeClient) return;
|
|
349
|
+
await writeClient.patch(`cms_submission_${id}`).set({ read: true }).commit();
|
|
350
|
+
} catch (err) {
|
|
351
|
+
console.error("Sanity Adapter: failed to mark submission read", err);
|
|
352
|
+
}
|
|
353
|
+
},
|
|
354
|
+
async uploadImage(file) {
|
|
355
|
+
if (apiBase) {
|
|
356
|
+
const formData = new FormData();
|
|
357
|
+
formData.append("file", file);
|
|
358
|
+
const res = await fetch(`${apiBase}/upload`, {
|
|
359
|
+
method: "POST",
|
|
360
|
+
body: formData
|
|
361
|
+
});
|
|
362
|
+
if (!res.ok) {
|
|
363
|
+
const text = await res.text();
|
|
364
|
+
throw new Error(text || "Image upload failed");
|
|
365
|
+
}
|
|
366
|
+
const { url } = await res.json();
|
|
367
|
+
return url;
|
|
368
|
+
}
|
|
369
|
+
if (!writeClient) {
|
|
370
|
+
throw new Error("Sanity Adapter: No token or apiBase for image upload.");
|
|
371
|
+
}
|
|
372
|
+
const asset = await writeClient.assets.upload("image", file, {
|
|
373
|
+
filename: file.name
|
|
374
|
+
});
|
|
375
|
+
return asset.url;
|
|
376
|
+
}
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
export {
|
|
380
|
+
createLocalStorageAdapter,
|
|
381
|
+
createMemoryAdapter,
|
|
382
|
+
createSanityAdapter
|
|
383
|
+
};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
type FieldType = "text" | "textarea" | "richtext" | "image" | "link" | "color" | "list" | "password";
|
|
2
|
+
interface EditableMeta {
|
|
3
|
+
id: string;
|
|
4
|
+
label?: string;
|
|
5
|
+
type: FieldType;
|
|
6
|
+
section?: string;
|
|
7
|
+
pageId?: string;
|
|
8
|
+
defaultValue?: unknown;
|
|
9
|
+
itemSchema?: {
|
|
10
|
+
key: string;
|
|
11
|
+
type: "text" | "textarea" | "boolean" | "icon" | "image" | "number";
|
|
12
|
+
label?: string;
|
|
13
|
+
options?: string[];
|
|
14
|
+
}[];
|
|
15
|
+
fixedLength?: boolean;
|
|
16
|
+
}
|
|
17
|
+
interface PageDef {
|
|
18
|
+
id: string;
|
|
19
|
+
name: string;
|
|
20
|
+
path: string;
|
|
21
|
+
description?: string;
|
|
22
|
+
}
|
|
23
|
+
interface CollectionField {
|
|
24
|
+
id: string;
|
|
25
|
+
label: string;
|
|
26
|
+
type: FieldType | "number" | "boolean" | "select" | "icon";
|
|
27
|
+
options?: string[] | {
|
|
28
|
+
label: string;
|
|
29
|
+
value: string;
|
|
30
|
+
}[];
|
|
31
|
+
defaultValue?: unknown;
|
|
32
|
+
}
|
|
33
|
+
interface CollectionDef {
|
|
34
|
+
id: string;
|
|
35
|
+
name: string;
|
|
36
|
+
description?: string;
|
|
37
|
+
fields: CollectionField[];
|
|
38
|
+
}
|
|
39
|
+
interface GlobalGroup {
|
|
40
|
+
id: string;
|
|
41
|
+
label: string;
|
|
42
|
+
fields: EditableMeta[];
|
|
43
|
+
}
|
|
44
|
+
interface CmsConfig {
|
|
45
|
+
siteName?: string;
|
|
46
|
+
pages: PageDef[];
|
|
47
|
+
collections?: CollectionDef[];
|
|
48
|
+
globals?: GlobalGroup[];
|
|
49
|
+
components?: PageDef[];
|
|
50
|
+
}
|
|
51
|
+
type OverridesMap = Record<string, unknown>;
|
|
52
|
+
type CollectionEntry = {
|
|
53
|
+
id: string;
|
|
54
|
+
[k: string]: unknown;
|
|
55
|
+
};
|
|
56
|
+
interface Submission {
|
|
57
|
+
id: string;
|
|
58
|
+
formId: string;
|
|
59
|
+
submittedAt: string;
|
|
60
|
+
data: Record<string, unknown>;
|
|
61
|
+
read?: boolean;
|
|
62
|
+
}
|
|
63
|
+
interface StorageAdapter {
|
|
64
|
+
name: string;
|
|
65
|
+
getOverrides(): Promise<OverridesMap>;
|
|
66
|
+
setOverrides(map: OverridesMap): Promise<void>;
|
|
67
|
+
listEntries(collectionId: string): Promise<CollectionEntry[]>;
|
|
68
|
+
putEntry(collectionId: string, entry: CollectionEntry): Promise<void>;
|
|
69
|
+
deleteEntry(collectionId: string, entryId: string): Promise<void>;
|
|
70
|
+
saveSubmission(submission: Submission): Promise<void>;
|
|
71
|
+
listSubmissions(formId?: string): Promise<Submission[]>;
|
|
72
|
+
deleteSubmission(id: string): Promise<void>;
|
|
73
|
+
markSubmissionRead(id: string): Promise<void>;
|
|
74
|
+
/** Upload an image file and return its public URL (Sanity CDN, etc.) */
|
|
75
|
+
uploadImage?: (file: File) => Promise<string>;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export type { CmsConfig as C, EditableMeta as E, FieldType as F, GlobalGroup as G, OverridesMap as O, PageDef as P, StorageAdapter as S, CollectionDef as a, CollectionEntry as b, CollectionField as c, Submission as d };
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
type FieldType = "text" | "textarea" | "richtext" | "image" | "link" | "color" | "list" | "password";
|
|
2
|
+
interface EditableMeta {
|
|
3
|
+
id: string;
|
|
4
|
+
label?: string;
|
|
5
|
+
type: FieldType;
|
|
6
|
+
section?: string;
|
|
7
|
+
pageId?: string;
|
|
8
|
+
defaultValue?: unknown;
|
|
9
|
+
itemSchema?: {
|
|
10
|
+
key: string;
|
|
11
|
+
type: "text" | "textarea" | "boolean" | "icon" | "image" | "number";
|
|
12
|
+
label?: string;
|
|
13
|
+
options?: string[];
|
|
14
|
+
}[];
|
|
15
|
+
fixedLength?: boolean;
|
|
16
|
+
}
|
|
17
|
+
interface PageDef {
|
|
18
|
+
id: string;
|
|
19
|
+
name: string;
|
|
20
|
+
path: string;
|
|
21
|
+
description?: string;
|
|
22
|
+
}
|
|
23
|
+
interface CollectionField {
|
|
24
|
+
id: string;
|
|
25
|
+
label: string;
|
|
26
|
+
type: FieldType | "number" | "boolean" | "select" | "icon";
|
|
27
|
+
options?: string[] | {
|
|
28
|
+
label: string;
|
|
29
|
+
value: string;
|
|
30
|
+
}[];
|
|
31
|
+
defaultValue?: unknown;
|
|
32
|
+
}
|
|
33
|
+
interface CollectionDef {
|
|
34
|
+
id: string;
|
|
35
|
+
name: string;
|
|
36
|
+
description?: string;
|
|
37
|
+
fields: CollectionField[];
|
|
38
|
+
}
|
|
39
|
+
interface GlobalGroup {
|
|
40
|
+
id: string;
|
|
41
|
+
label: string;
|
|
42
|
+
fields: EditableMeta[];
|
|
43
|
+
}
|
|
44
|
+
interface CmsConfig {
|
|
45
|
+
siteName?: string;
|
|
46
|
+
pages: PageDef[];
|
|
47
|
+
collections?: CollectionDef[];
|
|
48
|
+
globals?: GlobalGroup[];
|
|
49
|
+
components?: PageDef[];
|
|
50
|
+
}
|
|
51
|
+
type OverridesMap = Record<string, unknown>;
|
|
52
|
+
type CollectionEntry = {
|
|
53
|
+
id: string;
|
|
54
|
+
[k: string]: unknown;
|
|
55
|
+
};
|
|
56
|
+
interface Submission {
|
|
57
|
+
id: string;
|
|
58
|
+
formId: string;
|
|
59
|
+
submittedAt: string;
|
|
60
|
+
data: Record<string, unknown>;
|
|
61
|
+
read?: boolean;
|
|
62
|
+
}
|
|
63
|
+
interface StorageAdapter {
|
|
64
|
+
name: string;
|
|
65
|
+
getOverrides(): Promise<OverridesMap>;
|
|
66
|
+
setOverrides(map: OverridesMap): Promise<void>;
|
|
67
|
+
listEntries(collectionId: string): Promise<CollectionEntry[]>;
|
|
68
|
+
putEntry(collectionId: string, entry: CollectionEntry): Promise<void>;
|
|
69
|
+
deleteEntry(collectionId: string, entryId: string): Promise<void>;
|
|
70
|
+
saveSubmission(submission: Submission): Promise<void>;
|
|
71
|
+
listSubmissions(formId?: string): Promise<Submission[]>;
|
|
72
|
+
deleteSubmission(id: string): Promise<void>;
|
|
73
|
+
markSubmissionRead(id: string): Promise<void>;
|
|
74
|
+
/** Upload an image file and return its public URL (Sanity CDN, etc.) */
|
|
75
|
+
uploadImage?: (file: File) => Promise<string>;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export type { CmsConfig as C, EditableMeta as E, FieldType as F, GlobalGroup as G, OverridesMap as O, PageDef as P, StorageAdapter as S, CollectionDef as a, CollectionEntry as b, CollectionField as c, Submission as d };
|
package/dist/types.d.mts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
type FieldType = "text" | "textarea" | "richtext" | "image" | "link" | "color" | "list" | "password";
|
|
2
|
+
interface EditableMeta {
|
|
3
|
+
id: string;
|
|
4
|
+
label?: string;
|
|
5
|
+
type: FieldType;
|
|
6
|
+
section?: string;
|
|
7
|
+
pageId?: string;
|
|
8
|
+
defaultValue?: unknown;
|
|
9
|
+
itemSchema?: {
|
|
10
|
+
key: string;
|
|
11
|
+
type: "text" | "textarea" | "boolean" | "icon" | "image" | "number";
|
|
12
|
+
label?: string;
|
|
13
|
+
options?: string[];
|
|
14
|
+
}[];
|
|
15
|
+
fixedLength?: boolean;
|
|
16
|
+
}
|
|
17
|
+
interface PageDef {
|
|
18
|
+
id: string;
|
|
19
|
+
name: string;
|
|
20
|
+
path: string;
|
|
21
|
+
description?: string;
|
|
22
|
+
}
|
|
23
|
+
interface CollectionField {
|
|
24
|
+
id: string;
|
|
25
|
+
label: string;
|
|
26
|
+
type: FieldType | "number" | "boolean" | "select" | "icon";
|
|
27
|
+
options?: string[] | {
|
|
28
|
+
label: string;
|
|
29
|
+
value: string;
|
|
30
|
+
}[];
|
|
31
|
+
defaultValue?: unknown;
|
|
32
|
+
}
|
|
33
|
+
interface CollectionDef {
|
|
34
|
+
id: string;
|
|
35
|
+
name: string;
|
|
36
|
+
description?: string;
|
|
37
|
+
fields: CollectionField[];
|
|
38
|
+
}
|
|
39
|
+
interface GlobalGroup {
|
|
40
|
+
id: string;
|
|
41
|
+
label: string;
|
|
42
|
+
fields: EditableMeta[];
|
|
43
|
+
}
|
|
44
|
+
interface CmsConfig {
|
|
45
|
+
siteName?: string;
|
|
46
|
+
pages: PageDef[];
|
|
47
|
+
collections?: CollectionDef[];
|
|
48
|
+
globals?: GlobalGroup[];
|
|
49
|
+
components?: PageDef[];
|
|
50
|
+
}
|
|
51
|
+
type OverridesMap = Record<string, unknown>;
|
|
52
|
+
type CollectionEntry = {
|
|
53
|
+
id: string;
|
|
54
|
+
[k: string]: unknown;
|
|
55
|
+
};
|
|
56
|
+
interface Submission {
|
|
57
|
+
id: string;
|
|
58
|
+
formId: string;
|
|
59
|
+
submittedAt: string;
|
|
60
|
+
data: Record<string, unknown>;
|
|
61
|
+
read?: boolean;
|
|
62
|
+
}
|
|
63
|
+
interface StorageAdapter {
|
|
64
|
+
name: string;
|
|
65
|
+
getOverrides(): Promise<OverridesMap>;
|
|
66
|
+
setOverrides(map: OverridesMap): Promise<void>;
|
|
67
|
+
listEntries(collectionId: string): Promise<CollectionEntry[]>;
|
|
68
|
+
putEntry(collectionId: string, entry: CollectionEntry): Promise<void>;
|
|
69
|
+
deleteEntry(collectionId: string, entryId: string): Promise<void>;
|
|
70
|
+
saveSubmission(submission: Submission): Promise<void>;
|
|
71
|
+
listSubmissions(formId?: string): Promise<Submission[]>;
|
|
72
|
+
deleteSubmission(id: string): Promise<void>;
|
|
73
|
+
markSubmissionRead(id: string): Promise<void>;
|
|
74
|
+
/** Upload an image file and return its public URL (Sanity CDN, etc.) */
|
|
75
|
+
uploadImage?: (file: File) => Promise<string>;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export type { CmsConfig, CollectionDef, CollectionEntry, CollectionField, EditableMeta, FieldType, GlobalGroup, OverridesMap, PageDef, StorageAdapter, Submission };
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
type FieldType = "text" | "textarea" | "richtext" | "image" | "link" | "color" | "list" | "password";
|
|
2
|
+
interface EditableMeta {
|
|
3
|
+
id: string;
|
|
4
|
+
label?: string;
|
|
5
|
+
type: FieldType;
|
|
6
|
+
section?: string;
|
|
7
|
+
pageId?: string;
|
|
8
|
+
defaultValue?: unknown;
|
|
9
|
+
itemSchema?: {
|
|
10
|
+
key: string;
|
|
11
|
+
type: "text" | "textarea" | "boolean" | "icon" | "image" | "number";
|
|
12
|
+
label?: string;
|
|
13
|
+
options?: string[];
|
|
14
|
+
}[];
|
|
15
|
+
fixedLength?: boolean;
|
|
16
|
+
}
|
|
17
|
+
interface PageDef {
|
|
18
|
+
id: string;
|
|
19
|
+
name: string;
|
|
20
|
+
path: string;
|
|
21
|
+
description?: string;
|
|
22
|
+
}
|
|
23
|
+
interface CollectionField {
|
|
24
|
+
id: string;
|
|
25
|
+
label: string;
|
|
26
|
+
type: FieldType | "number" | "boolean" | "select" | "icon";
|
|
27
|
+
options?: string[] | {
|
|
28
|
+
label: string;
|
|
29
|
+
value: string;
|
|
30
|
+
}[];
|
|
31
|
+
defaultValue?: unknown;
|
|
32
|
+
}
|
|
33
|
+
interface CollectionDef {
|
|
34
|
+
id: string;
|
|
35
|
+
name: string;
|
|
36
|
+
description?: string;
|
|
37
|
+
fields: CollectionField[];
|
|
38
|
+
}
|
|
39
|
+
interface GlobalGroup {
|
|
40
|
+
id: string;
|
|
41
|
+
label: string;
|
|
42
|
+
fields: EditableMeta[];
|
|
43
|
+
}
|
|
44
|
+
interface CmsConfig {
|
|
45
|
+
siteName?: string;
|
|
46
|
+
pages: PageDef[];
|
|
47
|
+
collections?: CollectionDef[];
|
|
48
|
+
globals?: GlobalGroup[];
|
|
49
|
+
components?: PageDef[];
|
|
50
|
+
}
|
|
51
|
+
type OverridesMap = Record<string, unknown>;
|
|
52
|
+
type CollectionEntry = {
|
|
53
|
+
id: string;
|
|
54
|
+
[k: string]: unknown;
|
|
55
|
+
};
|
|
56
|
+
interface Submission {
|
|
57
|
+
id: string;
|
|
58
|
+
formId: string;
|
|
59
|
+
submittedAt: string;
|
|
60
|
+
data: Record<string, unknown>;
|
|
61
|
+
read?: boolean;
|
|
62
|
+
}
|
|
63
|
+
interface StorageAdapter {
|
|
64
|
+
name: string;
|
|
65
|
+
getOverrides(): Promise<OverridesMap>;
|
|
66
|
+
setOverrides(map: OverridesMap): Promise<void>;
|
|
67
|
+
listEntries(collectionId: string): Promise<CollectionEntry[]>;
|
|
68
|
+
putEntry(collectionId: string, entry: CollectionEntry): Promise<void>;
|
|
69
|
+
deleteEntry(collectionId: string, entryId: string): Promise<void>;
|
|
70
|
+
saveSubmission(submission: Submission): Promise<void>;
|
|
71
|
+
listSubmissions(formId?: string): Promise<Submission[]>;
|
|
72
|
+
deleteSubmission(id: string): Promise<void>;
|
|
73
|
+
markSubmissionRead(id: string): Promise<void>;
|
|
74
|
+
/** Upload an image file and return its public URL (Sanity CDN, etc.) */
|
|
75
|
+
uploadImage?: (file: File) => Promise<string>;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export type { CmsConfig, CollectionDef, CollectionEntry, CollectionField, EditableMeta, FieldType, GlobalGroup, OverridesMap, PageDef, StorageAdapter, Submission };
|