uncial-cms 4.0.2 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/define-site.d.ts +13 -4
- package/dist/define-site.js +10 -0
- package/dist/editor-controller.d.ts +25 -0
- package/dist/editor-controller.js +174 -14
- package/dist/editor-session.d.ts +1 -1
- package/dist/editor-session.js +9 -1
- package/dist/github/adapter.js +1 -1
- package/dist/image-source.d.ts +2 -1
- package/dist/image-source.js +19 -5
- package/dist/index-actions.js +3 -3
- package/dist/index-page.d.ts +2 -0
- package/dist/index-page.js +38 -20
- package/dist/index.d.ts +4 -3
- package/dist/index.js +1 -1
- package/dist/served-url.js +2 -1
- package/dist/server/handlers.d.ts +45 -0
- package/dist/server/handlers.js +237 -0
- package/dist/server/index.d.ts +5 -0
- package/dist/server/index.js +4 -0
- package/dist/server/media.d.ts +69 -0
- package/dist/server/media.js +181 -0
- package/dist/server/migrations.d.ts +8 -0
- package/dist/server/migrations.js +47 -0
- package/dist/server/postgres-store.d.ts +72 -0
- package/dist/server/postgres-store.js +201 -0
- package/dist/server-forge/adapter.d.ts +17 -0
- package/dist/server-forge/adapter.js +95 -0
- package/dist/server-forge/media.d.ts +11 -0
- package/dist/server-forge/media.js +26 -0
- package/dist/server-forge/protocol.d.ts +65 -0
- package/dist/server-forge/protocol.js +27 -0
- package/dist/server-forge/session.d.ts +2 -0
- package/dist/server-forge/session.js +15 -0
- package/dist/svelte/EditorPage.svelte +217 -7
- package/dist/svelte/EditorPage.svelte.d.ts +6 -0
- package/dist/svelte/MediaLibrary.svelte +187 -0
- package/dist/svelte/MediaLibrary.svelte.d.ts +7 -0
- package/dist/svelte/index.d.ts +1 -0
- package/dist/svelte/index.js +1 -0
- package/dist/sveltekit/index.d.ts +7 -7
- package/dist/sveltekit/index.js +6 -6
- package/dist/types.d.ts +7 -1
- package/dist/upload-context.d.ts +2 -0
- package/dist/upload-context.js +4 -0
- package/package.json +18 -2
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { ConflictError, NotFoundError } from '../errors.js';
|
|
2
|
+
const UNIQUE_VIOLATION = '23505';
|
|
3
|
+
function toRecord(row) {
|
|
4
|
+
return {
|
|
5
|
+
id: row.id,
|
|
6
|
+
kind: row.kind,
|
|
7
|
+
path: row.path,
|
|
8
|
+
draft: row.draft,
|
|
9
|
+
published: row.published,
|
|
10
|
+
etag: row.etag,
|
|
11
|
+
publishedAt: row.published_at,
|
|
12
|
+
updatedAt: row.updated_at,
|
|
13
|
+
updatedBy: row.updated_by
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
function isUniqueViolation(error) {
|
|
17
|
+
return error?.code === UNIQUE_VIOLATION;
|
|
18
|
+
}
|
|
19
|
+
export function createPostgresContentStore(sql, opts) {
|
|
20
|
+
const json = (doc) => sql.json(doc);
|
|
21
|
+
async function lock(tx, path, etag) {
|
|
22
|
+
const [row] = await tx `select * from uncial_content where path = ${path} for update`;
|
|
23
|
+
if (!row)
|
|
24
|
+
throw new NotFoundError(`No content at ${path}.`);
|
|
25
|
+
if (row.etag !== etag)
|
|
26
|
+
throw new ConflictError();
|
|
27
|
+
return row;
|
|
28
|
+
}
|
|
29
|
+
async function prune(tx, contentId) {
|
|
30
|
+
const { retention } = opts;
|
|
31
|
+
if ('keep' in retention) {
|
|
32
|
+
await tx `
|
|
33
|
+
delete from uncial_content_versions
|
|
34
|
+
where content_id = ${contentId}
|
|
35
|
+
and id not in (
|
|
36
|
+
select id from uncial_content_versions
|
|
37
|
+
where content_id = ${contentId}
|
|
38
|
+
order by id desc
|
|
39
|
+
limit ${retention.keep}
|
|
40
|
+
)
|
|
41
|
+
`;
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
await tx `
|
|
45
|
+
delete from uncial_content_versions
|
|
46
|
+
where content_id = ${contentId}
|
|
47
|
+
and created_at < now() - make_interval(days => ${retention.days})
|
|
48
|
+
`;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
async get(path) {
|
|
53
|
+
const [row] = await sql `select * from uncial_content where path = ${path}`;
|
|
54
|
+
return row ? toRecord(row) : null;
|
|
55
|
+
},
|
|
56
|
+
async list({ kind, status = 'any' } = {}) {
|
|
57
|
+
const rows = await sql `
|
|
58
|
+
select * from uncial_content
|
|
59
|
+
where true
|
|
60
|
+
${kind === undefined ? sql `` : sql `and kind = ${kind}`}
|
|
61
|
+
${status === 'draft' ? sql `and draft is not null` : sql ``}
|
|
62
|
+
${status === 'published' ? sql `and published is not null` : sql ``}
|
|
63
|
+
order by path
|
|
64
|
+
`;
|
|
65
|
+
return rows.map(toRecord);
|
|
66
|
+
},
|
|
67
|
+
async create(path, kind, draft, { author }) {
|
|
68
|
+
try {
|
|
69
|
+
const [row] = await sql `
|
|
70
|
+
insert into uncial_content (kind, path, draft, updated_by)
|
|
71
|
+
values (${kind}, ${path}, ${json(draft)}, ${author})
|
|
72
|
+
returning *
|
|
73
|
+
`;
|
|
74
|
+
return toRecord(row);
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
if (isUniqueViolation(error))
|
|
78
|
+
throw new ConflictError(`Content already exists at ${path}.`);
|
|
79
|
+
throw error;
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
async saveDraft(path, draft, { etag, author }) {
|
|
83
|
+
return sql.begin(async (tx) => {
|
|
84
|
+
await lock(tx, path, etag);
|
|
85
|
+
const [row] = await tx `
|
|
86
|
+
update uncial_content
|
|
87
|
+
set draft = ${json(draft)}, etag = gen_random_uuid()::text,
|
|
88
|
+
updated_at = now(), updated_by = ${author}
|
|
89
|
+
where path = ${path}
|
|
90
|
+
returning *
|
|
91
|
+
`;
|
|
92
|
+
return toRecord(row);
|
|
93
|
+
});
|
|
94
|
+
},
|
|
95
|
+
async publish(path, { etag, author }) {
|
|
96
|
+
return sql.begin(async (tx) => {
|
|
97
|
+
const current = await lock(tx, path, etag);
|
|
98
|
+
if (current.draft === null)
|
|
99
|
+
throw new Error(`Nothing to publish: ${path} has no Draft.`);
|
|
100
|
+
if (current.published !== null) {
|
|
101
|
+
await tx `
|
|
102
|
+
insert into uncial_content_versions (content_id, doc, created_by)
|
|
103
|
+
values (${current.id}, ${json(current.published)}, ${author})
|
|
104
|
+
`;
|
|
105
|
+
}
|
|
106
|
+
const [row] = await tx `
|
|
107
|
+
update uncial_content
|
|
108
|
+
set published = draft, draft = null, published_at = now(),
|
|
109
|
+
etag = gen_random_uuid()::text, updated_at = now(), updated_by = ${author}
|
|
110
|
+
where id = ${current.id}
|
|
111
|
+
returning *
|
|
112
|
+
`;
|
|
113
|
+
await prune(tx, current.id);
|
|
114
|
+
return toRecord(row);
|
|
115
|
+
});
|
|
116
|
+
},
|
|
117
|
+
async unpublish(path, { etag, author }) {
|
|
118
|
+
return sql.begin(async (tx) => {
|
|
119
|
+
await lock(tx, path, etag);
|
|
120
|
+
const [row] = await tx `
|
|
121
|
+
update uncial_content
|
|
122
|
+
set published = null, published_at = null,
|
|
123
|
+
etag = gen_random_uuid()::text, updated_at = now(), updated_by = ${author}
|
|
124
|
+
where path = ${path}
|
|
125
|
+
returning *
|
|
126
|
+
`;
|
|
127
|
+
return toRecord(row);
|
|
128
|
+
});
|
|
129
|
+
},
|
|
130
|
+
async delete(path, { etag }) {
|
|
131
|
+
await sql.begin(async (tx) => {
|
|
132
|
+
await lock(tx, path, etag);
|
|
133
|
+
await tx `delete from uncial_content where path = ${path}`;
|
|
134
|
+
});
|
|
135
|
+
},
|
|
136
|
+
async move(from, to, { etag, author }) {
|
|
137
|
+
try {
|
|
138
|
+
return await sql.begin(async (tx) => {
|
|
139
|
+
await lock(tx, from, etag);
|
|
140
|
+
const [row] = await tx `
|
|
141
|
+
update uncial_content
|
|
142
|
+
set path = ${to}, etag = gen_random_uuid()::text,
|
|
143
|
+
updated_at = now(), updated_by = ${author}
|
|
144
|
+
where path = ${from}
|
|
145
|
+
returning *
|
|
146
|
+
`;
|
|
147
|
+
const record = toRecord(row);
|
|
148
|
+
await opts.onMove?.(tx, { from, to, record });
|
|
149
|
+
return record;
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
catch (error) {
|
|
153
|
+
if (isUniqueViolation(error))
|
|
154
|
+
throw new ConflictError(`Content already exists at ${to}.`);
|
|
155
|
+
throw error;
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
async versions(path) {
|
|
159
|
+
const rows = await sql `
|
|
160
|
+
select v.id::text, v.created_at, v.created_by from uncial_content_versions v
|
|
161
|
+
join uncial_content c on c.id = v.content_id
|
|
162
|
+
where c.path = ${path}
|
|
163
|
+
order by v.id desc
|
|
164
|
+
`;
|
|
165
|
+
return rows.map((row) => ({
|
|
166
|
+
id: row.id,
|
|
167
|
+
createdAt: row.created_at,
|
|
168
|
+
createdBy: row.created_by
|
|
169
|
+
}));
|
|
170
|
+
},
|
|
171
|
+
async getVersion(path, versionId) {
|
|
172
|
+
const [version] = await sql `
|
|
173
|
+
select v.doc from uncial_content_versions v
|
|
174
|
+
join uncial_content c on c.id = v.content_id
|
|
175
|
+
where c.path = ${path} and v.id::text = ${versionId}
|
|
176
|
+
`;
|
|
177
|
+
if (!version)
|
|
178
|
+
throw new NotFoundError(`No Version ${versionId} of ${path}.`);
|
|
179
|
+
return version.doc;
|
|
180
|
+
},
|
|
181
|
+
async restore(path, versionId, { etag, author }) {
|
|
182
|
+
return sql.begin(async (tx) => {
|
|
183
|
+
const current = await lock(tx, path, etag);
|
|
184
|
+
const [version] = await tx `
|
|
185
|
+
select doc from uncial_content_versions
|
|
186
|
+
where content_id = ${current.id} and id::text = ${versionId}
|
|
187
|
+
`;
|
|
188
|
+
if (!version)
|
|
189
|
+
throw new NotFoundError(`No Version ${versionId} of ${path}.`);
|
|
190
|
+
const [row] = await tx `
|
|
191
|
+
update uncial_content
|
|
192
|
+
set draft = ${json(version.doc)}, etag = gen_random_uuid()::text,
|
|
193
|
+
updated_at = now(), updated_by = ${author}
|
|
194
|
+
where id = ${current.id}
|
|
195
|
+
returning *
|
|
196
|
+
`;
|
|
197
|
+
return toRecord(row);
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ForgeAdapter } from '../types.js';
|
|
2
|
+
import type { ContentSummary, ContentView, VersionView } from './protocol.js';
|
|
3
|
+
export interface ServerForgeAdapter extends ForgeAdapter {
|
|
4
|
+
getRecord(path: string): Promise<ContentView>;
|
|
5
|
+
list(): Promise<ContentSummary[]>;
|
|
6
|
+
publish(path: string, etag: string): Promise<ContentView>;
|
|
7
|
+
unpublish(path: string, etag: string): Promise<ContentView>;
|
|
8
|
+
versions(path: string): Promise<VersionView[]>;
|
|
9
|
+
getVersion(path: string, versionId: string): Promise<unknown>;
|
|
10
|
+
restore(path: string, versionId: string, etag: string): Promise<ContentView>;
|
|
11
|
+
move(path: string, to: string, etag: string): Promise<ContentView>;
|
|
12
|
+
}
|
|
13
|
+
export declare function serverRequest<T>(apiBase: string, method: string, opts?: {
|
|
14
|
+
query?: Record<string, string>;
|
|
15
|
+
body?: unknown;
|
|
16
|
+
}): Promise<T>;
|
|
17
|
+
export declare function createServerAdapter(): ServerForgeAdapter;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { ConflictError, NotFoundError } from '../errors.js';
|
|
2
|
+
export async function serverRequest(apiBase, method, opts = {}) {
|
|
3
|
+
const url = new URL(apiBase, location.origin);
|
|
4
|
+
for (const [key, value] of Object.entries(opts.query ?? {}))
|
|
5
|
+
url.searchParams.set(key, value);
|
|
6
|
+
const response = await fetch(url, {
|
|
7
|
+
method,
|
|
8
|
+
credentials: 'same-origin',
|
|
9
|
+
...(opts.body === undefined
|
|
10
|
+
? {}
|
|
11
|
+
: opts.body instanceof FormData
|
|
12
|
+
? { body: opts.body }
|
|
13
|
+
: { headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(opts.body) })
|
|
14
|
+
});
|
|
15
|
+
if (response.status === 204)
|
|
16
|
+
return undefined;
|
|
17
|
+
if (response.ok)
|
|
18
|
+
return (await response.json());
|
|
19
|
+
const { error } = (await response.json().catch(() => ({})));
|
|
20
|
+
if (response.status === 401)
|
|
21
|
+
throw new Error('You are signed out. Sign in again to keep editing.');
|
|
22
|
+
if (response.status === 403)
|
|
23
|
+
throw new Error(error ?? 'You do not have permission to do that.');
|
|
24
|
+
if (response.status === 404)
|
|
25
|
+
throw new NotFoundError(error);
|
|
26
|
+
if (response.status === 409)
|
|
27
|
+
throw new ConflictError(error);
|
|
28
|
+
throw new Error(error ?? `Request failed (${response.status}).`);
|
|
29
|
+
}
|
|
30
|
+
class ServerAdapter {
|
|
31
|
+
#config = null;
|
|
32
|
+
async authenticate(config, provider) {
|
|
33
|
+
if (config.forge !== 'server') {
|
|
34
|
+
throw new Error('Server adapter requires a server site configuration.');
|
|
35
|
+
}
|
|
36
|
+
this.#config = config;
|
|
37
|
+
return provider(config);
|
|
38
|
+
}
|
|
39
|
+
getRecord(path) {
|
|
40
|
+
return this.#request('GET', { query: { path } });
|
|
41
|
+
}
|
|
42
|
+
async list() {
|
|
43
|
+
const { records } = await this.#request('GET');
|
|
44
|
+
return records;
|
|
45
|
+
}
|
|
46
|
+
publish(path, etag) {
|
|
47
|
+
return this.#request('POST', { body: { action: 'publish', path, etag } });
|
|
48
|
+
}
|
|
49
|
+
unpublish(path, etag) {
|
|
50
|
+
return this.#request('POST', { body: { action: 'unpublish', path, etag } });
|
|
51
|
+
}
|
|
52
|
+
versions(path) {
|
|
53
|
+
return this.#request('GET', { query: { path, history: '' } });
|
|
54
|
+
}
|
|
55
|
+
getVersion(path, versionId) {
|
|
56
|
+
return this.#request('GET', { query: { path, version: versionId } });
|
|
57
|
+
}
|
|
58
|
+
restore(path, versionId, etag) {
|
|
59
|
+
return this.#request('POST', { body: { action: 'restore', path, versionId, etag } });
|
|
60
|
+
}
|
|
61
|
+
move(path, to, etag) {
|
|
62
|
+
return this.#request('POST', { body: { action: 'move', path, to, etag } });
|
|
63
|
+
}
|
|
64
|
+
async readFile(path) {
|
|
65
|
+
const record = await this.getRecord(path);
|
|
66
|
+
return { content: JSON.stringify(record.draft ?? record.published), sha: record.etag };
|
|
67
|
+
}
|
|
68
|
+
async writeFile(path, content, opts) {
|
|
69
|
+
if (typeof content !== 'string') {
|
|
70
|
+
throw new Error('The server forge stores Content documents only; upload media separately.');
|
|
71
|
+
}
|
|
72
|
+
const draft = JSON.parse(content);
|
|
73
|
+
const record = opts.sha === undefined
|
|
74
|
+
? await this.#request('POST', { body: { action: 'create', path, draft } })
|
|
75
|
+
: await this.#request('PUT', { body: { path, draft, etag: opts.sha } });
|
|
76
|
+
return { sha: record.etag, commitSha: '', path: record.path };
|
|
77
|
+
}
|
|
78
|
+
async deleteFile(path, opts) {
|
|
79
|
+
await this.#request('DELETE', { body: { path, etag: opts.sha } });
|
|
80
|
+
}
|
|
81
|
+
async listDir() {
|
|
82
|
+
throw new Error('The server forge has no directories; list Content documents with list().');
|
|
83
|
+
}
|
|
84
|
+
async commitStatus() {
|
|
85
|
+
return 'success';
|
|
86
|
+
}
|
|
87
|
+
#request(method, opts) {
|
|
88
|
+
if (!this.#config)
|
|
89
|
+
throw new Error('Server adapter is not authenticated; call authenticate() first.');
|
|
90
|
+
return serverRequest(this.#config.apiBase, method, opts);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
export function createServerAdapter() {
|
|
94
|
+
return new ServerAdapter();
|
|
95
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { MediaItemView, MediaListView } from './protocol.js';
|
|
2
|
+
export declare function isMediaUrl(src: string): boolean;
|
|
3
|
+
export declare function listMedia(apiBase: string, query?: {
|
|
4
|
+
search?: string;
|
|
5
|
+
contentType?: string;
|
|
6
|
+
}): Promise<MediaListView>;
|
|
7
|
+
/** Uploads `file`, fitted first when it is a raster image, as Uncial's other forges do. */
|
|
8
|
+
export declare function uploadMedia(apiBase: string, file: File, opts?: {
|
|
9
|
+
title?: string;
|
|
10
|
+
}): Promise<MediaItemView>;
|
|
11
|
+
export declare function deleteMedia(apiBase: string, id: string): Promise<void>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { fitImage } from '../fit-image.js';
|
|
2
|
+
import { serverRequest } from './adapter.js';
|
|
3
|
+
/** A Media item's object key is `<sha256>.<ext>`, so its URL ends that way wherever it is served from. */
|
|
4
|
+
const MEDIA_URL = /\/[0-9a-f]{64}\.[a-z0-9]+$/;
|
|
5
|
+
export function isMediaUrl(src) {
|
|
6
|
+
return MEDIA_URL.test(src);
|
|
7
|
+
}
|
|
8
|
+
export function listMedia(apiBase, query = {}) {
|
|
9
|
+
const params = Object.fromEntries(Object.entries(query).filter(([, value]) => value));
|
|
10
|
+
return serverRequest(apiBase, 'GET', { query: params });
|
|
11
|
+
}
|
|
12
|
+
/** Uploads `file`, fitted first when it is a raster image, as Uncial's other forges do. */
|
|
13
|
+
export async function uploadMedia(apiBase, file, opts = {}) {
|
|
14
|
+
const raster = file.type.startsWith('image/') && file.type !== 'image/svg+xml';
|
|
15
|
+
const fitted = raster ? await fitImage(file) : null;
|
|
16
|
+
const form = new FormData();
|
|
17
|
+
form.set('file', fitted
|
|
18
|
+
? new File([fitted.bytes], fitted.filename, { type: fitted.contentType })
|
|
19
|
+
: file);
|
|
20
|
+
if (opts.title)
|
|
21
|
+
form.set('title', opts.title);
|
|
22
|
+
return serverRequest(apiBase, 'POST', { body: form });
|
|
23
|
+
}
|
|
24
|
+
export function deleteMedia(apiBase, id) {
|
|
25
|
+
return serverRequest(apiBase, 'DELETE', { body: { id } });
|
|
26
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The wire contract between the `server` forge's client adapter and the host's
|
|
3
|
+
* endpoint built by `createServerContentHandlers`. Types and pure helpers only,
|
|
4
|
+
* so both sides import it without pulling in the other.
|
|
5
|
+
*/
|
|
6
|
+
export declare const ACTIONS: readonly ["read-draft", "save-draft", "create", "publish", "unpublish", "delete", "move", "restore", "media-upload", "media-delete"];
|
|
7
|
+
export type Action = (typeof ACTIONS)[number];
|
|
8
|
+
export interface ServerUser {
|
|
9
|
+
id: string;
|
|
10
|
+
email: string;
|
|
11
|
+
name: string;
|
|
12
|
+
}
|
|
13
|
+
/** A Content document as the get, create and write endpoints return it. */
|
|
14
|
+
export interface ContentView {
|
|
15
|
+
path: string;
|
|
16
|
+
kind: string;
|
|
17
|
+
draft: unknown | null;
|
|
18
|
+
published: unknown | null;
|
|
19
|
+
etag: string;
|
|
20
|
+
publishedAt: string | null;
|
|
21
|
+
updatedAt: string;
|
|
22
|
+
updatedBy: string;
|
|
23
|
+
/** The actions `authorize` grants the requesting user on this record. */
|
|
24
|
+
allowed: Action[];
|
|
25
|
+
}
|
|
26
|
+
/** One row of the history endpoint, newest first. */
|
|
27
|
+
export interface VersionView {
|
|
28
|
+
id: string;
|
|
29
|
+
createdAt: string;
|
|
30
|
+
createdBy: string;
|
|
31
|
+
}
|
|
32
|
+
export type ContentStatus = 'draft' | 'published' | 'changed';
|
|
33
|
+
/** One row of the list endpoint. */
|
|
34
|
+
export interface ContentSummary {
|
|
35
|
+
path: string;
|
|
36
|
+
kind: string;
|
|
37
|
+
status: ContentStatus;
|
|
38
|
+
publishedAt: string | null;
|
|
39
|
+
updatedAt: string;
|
|
40
|
+
updatedBy: string;
|
|
41
|
+
}
|
|
42
|
+
export declare function contentStatus(hasDraft: boolean, hasPublished: boolean): ContentStatus;
|
|
43
|
+
export declare function describeContentStatus(status: ContentStatus): string;
|
|
44
|
+
/** One Media item as the media endpoint returns it. */
|
|
45
|
+
export interface MediaItemView {
|
|
46
|
+
id: string;
|
|
47
|
+
key: string;
|
|
48
|
+
url: string;
|
|
49
|
+
filename: string;
|
|
50
|
+
title: string;
|
|
51
|
+
contentType: string;
|
|
52
|
+
width: number | null;
|
|
53
|
+
height: number | null;
|
|
54
|
+
size: number;
|
|
55
|
+
uploadedBy: string;
|
|
56
|
+
uploadedAt: string;
|
|
57
|
+
}
|
|
58
|
+
/** The media list endpoint's body. */
|
|
59
|
+
export interface MediaListView {
|
|
60
|
+
items: Array<MediaItemView & {
|
|
61
|
+
usage: number;
|
|
62
|
+
}>;
|
|
63
|
+
/** Of `media-upload` and `media-delete`, the actions `authorize` grants the requesting user. */
|
|
64
|
+
allowed: Action[];
|
|
65
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The wire contract between the `server` forge's client adapter and the host's
|
|
3
|
+
* endpoint built by `createServerContentHandlers`. Types and pure helpers only,
|
|
4
|
+
* so both sides import it without pulling in the other.
|
|
5
|
+
*/
|
|
6
|
+
export const ACTIONS = [
|
|
7
|
+
'read-draft',
|
|
8
|
+
'save-draft',
|
|
9
|
+
'create',
|
|
10
|
+
'publish',
|
|
11
|
+
'unpublish',
|
|
12
|
+
'delete',
|
|
13
|
+
'move',
|
|
14
|
+
'restore',
|
|
15
|
+
'media-upload',
|
|
16
|
+
'media-delete'
|
|
17
|
+
];
|
|
18
|
+
export function contentStatus(hasDraft, hasPublished) {
|
|
19
|
+
if (!hasPublished)
|
|
20
|
+
return 'draft';
|
|
21
|
+
return hasDraft ? 'changed' : 'published';
|
|
22
|
+
}
|
|
23
|
+
export function describeContentStatus(status) {
|
|
24
|
+
if (status === 'draft')
|
|
25
|
+
return 'Draft only';
|
|
26
|
+
return status === 'published' ? 'Published' : 'Published with Draft changes';
|
|
27
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { serverRequest } from './adapter.js';
|
|
2
|
+
export const serverSessionProvider = async (config) => {
|
|
3
|
+
if (config.forge !== 'server') {
|
|
4
|
+
throw new Error('The server session provider requires a server site configuration.');
|
|
5
|
+
}
|
|
6
|
+
const { user } = await serverRequest(config.apiBase, 'GET', {
|
|
7
|
+
query: { session: '' }
|
|
8
|
+
});
|
|
9
|
+
return {
|
|
10
|
+
token: '',
|
|
11
|
+
expiresAt: null,
|
|
12
|
+
repo: config.apiBase,
|
|
13
|
+
user: { login: user.email, name: user.name, email: user.email }
|
|
14
|
+
};
|
|
15
|
+
};
|