@basicbenframework/cms 0.7.3 → 0.9.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/db/migrations/043_add_private_content.js +32 -0
- package/db/migrations/044_add_post_autosave_key.js +20 -0
- package/lib/client/components/admin/MediaPicker.js +3 -1
- package/lib/client/components/admin/SnippetPicker.js +3 -1
- package/lib/client/components/admin/SocialImageField.d.ts +24 -0
- package/lib/client/components/admin/SocialImageField.js +70 -0
- package/lib/client/i18n/locales/es/content.js +2 -0
- package/lib/client/i18n/locales/es/editor.js +18 -1
- package/lib/client/pages/Authentication.js +1 -1
- package/lib/client/pages/Database.js +15 -10
- package/lib/client/pages/Testing.js +1 -1
- package/lib/client/pages/admin/Pages.js +2 -2
- package/lib/client/pages/admin/PostEditor.js +103 -9
- package/lib/client/pages/admin/Posts.js +2 -2
- package/lib/controllers/FeedController.js +2 -2
- package/lib/controllers/MediaController.js +18 -1
- package/lib/controllers/PageController.js +5 -1
- package/lib/controllers/PostController.d.ts +14 -0
- package/lib/controllers/PostController.js +83 -1
- package/lib/features/members/Member.js +3 -2
- package/lib/helpers/autosave.d.ts +13 -0
- package/lib/helpers/autosave.js +19 -0
- package/lib/helpers/comment-mail.js +8 -3
- package/lib/helpers/insert-row.d.ts +18 -0
- package/lib/helpers/insert-row.js +18 -0
- package/lib/helpers/redirects.d.ts +7 -1
- package/lib/helpers/redirects.js +7 -1
- package/lib/helpers/seo-fields.d.ts +7 -0
- package/lib/helpers/seo-fields.js +9 -0
- package/lib/hooks.js +21 -0
- package/lib/models/Category.js +3 -2
- package/lib/models/Comment.js +3 -2
- package/lib/models/ContentType.js +3 -2
- package/lib/models/Credential.js +5 -1
- package/lib/models/Media.d.ts +4 -1
- package/lib/models/Media.js +21 -3
- package/lib/models/Menu.js +7 -6
- package/lib/models/Page.d.ts +2 -0
- package/lib/models/Page.js +9 -5
- package/lib/models/Post.d.ts +16 -0
- package/lib/models/Post.js +24 -3
- package/lib/models/PostRevision.js +4 -3
- package/lib/models/PublicContent.d.ts +1 -1
- package/lib/models/PublicContent.js +5 -5
- package/lib/models/Snippet.js +3 -2
- package/lib/models/Tag.js +3 -2
- package/lib/models/Taxonomy.js +5 -2
- package/lib/models/User.js +5 -1
- package/lib/models/visibility.d.ts +9 -0
- package/lib/models/visibility.js +15 -1
- package/lib/routes/api/posts.js +3 -0
- package/lib/types/index.d.ts +4 -0
- package/package.json +3 -3
package/lib/models/Page.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { SEO_COLUMNS } from "../helpers/seo-fields.js";
|
|
2
|
-
import { getDb
|
|
2
|
+
import { getDb } from '@basicbenframework/core/db';
|
|
3
|
+
import { insertRow } from "../helpers/insert-row.js";
|
|
3
4
|
import { hooks, HOOKS } from '@basicbenframework/core/hooks';
|
|
4
5
|
import { renderContent } from '@basicbenframework/core/content';
|
|
5
6
|
import { getStorage } from '@basicbenframework/core/storage';
|
|
6
7
|
import { uniqueSlug } from "./derive.js";
|
|
8
|
+
import { livePage } from "./visibility.js";
|
|
7
9
|
/**
|
|
8
10
|
* Columns `update()` will write.
|
|
9
11
|
*
|
|
@@ -12,7 +14,7 @@ import { uniqueSlug } from "./derive.js";
|
|
|
12
14
|
*/
|
|
13
15
|
const UPDATABLE = [
|
|
14
16
|
'title', 'slug', 'content', 'content_html', 'featured_image', 'template',
|
|
15
|
-
'published', 'parent_id', 'menu_order', 'meta_title', 'meta_description',
|
|
17
|
+
'published', 'is_private', 'parent_id', 'menu_order', 'meta_title', 'meta_description',
|
|
16
18
|
'updated_at', ...SEO_COLUMNS
|
|
17
19
|
];
|
|
18
20
|
export const Page = {
|
|
@@ -50,13 +52,13 @@ export const Page = {
|
|
|
50
52
|
const db = await getDb();
|
|
51
53
|
return withFeaturedImages(await db.all(`
|
|
52
54
|
${SELECT_PAGE}
|
|
53
|
-
WHERE pages
|
|
55
|
+
WHERE ${livePage('pages')}
|
|
54
56
|
ORDER BY pages.menu_order ASC, pages.title ASC
|
|
55
57
|
`));
|
|
56
58
|
},
|
|
57
59
|
async findPublishedBySlug(slug) {
|
|
58
60
|
const db = await getDb();
|
|
59
|
-
return first(await db.get(`${SELECT_PAGE} WHERE pages.slug = ? AND pages
|
|
61
|
+
return first(await db.get(`${SELECT_PAGE} WHERE pages.slug = ? AND ${livePage('pages')}`, [slug]));
|
|
60
62
|
},
|
|
61
63
|
async tree() {
|
|
62
64
|
const pages = await this.all();
|
|
@@ -79,7 +81,7 @@ export const Page = {
|
|
|
79
81
|
// Through the query builder, which appends RETURNING id on Postgres. A raw
|
|
80
82
|
// INSERT there reports lastInsertRowid as null, so the row is written and
|
|
81
83
|
// the caller is handed an object with no id.
|
|
82
|
-
const result = await (
|
|
84
|
+
const result = await insertRow('pages', {
|
|
83
85
|
title: data.title,
|
|
84
86
|
slug,
|
|
85
87
|
content: data.content || null,
|
|
@@ -87,6 +89,7 @@ export const Page = {
|
|
|
87
89
|
featured_image: data.featured_image ?? null,
|
|
88
90
|
template: data.template || 'default',
|
|
89
91
|
published: data.published ? 1 : 0,
|
|
92
|
+
is_private: data.is_private ? 1 : 0,
|
|
90
93
|
parent_id: data.parent_id || null,
|
|
91
94
|
menu_order: data.menu_order || 0,
|
|
92
95
|
meta_title: data.meta_title || null,
|
|
@@ -105,6 +108,7 @@ export const Page = {
|
|
|
105
108
|
featured_image: data.featured_image ?? null,
|
|
106
109
|
template: data.template || 'default',
|
|
107
110
|
published: data.published || false,
|
|
111
|
+
is_private: data.is_private ? 1 : 0,
|
|
108
112
|
parent_id: data.parent_id,
|
|
109
113
|
menu_order: data.menu_order || 0,
|
|
110
114
|
meta_title: data.meta_title,
|
package/lib/models/Post.d.ts
CHANGED
|
@@ -22,10 +22,13 @@ interface CreatePostData {
|
|
|
22
22
|
noindex?: number;
|
|
23
23
|
visibility?: string;
|
|
24
24
|
send_newsletter?: number;
|
|
25
|
+
is_private?: number;
|
|
25
26
|
/** Content type key (migration 038). Absent means `post`. */
|
|
26
27
|
post_type?: string;
|
|
27
28
|
/** Custom field values as stored: a JSON string, already validated. */
|
|
28
29
|
fields?: string | null;
|
|
30
|
+
/** The editor's idempotency key for a first autosave (migration 044). */
|
|
31
|
+
autosave_key?: string;
|
|
29
32
|
}
|
|
30
33
|
interface UpdatePostData {
|
|
31
34
|
user_id?: number;
|
|
@@ -51,6 +54,7 @@ interface UpdatePostData {
|
|
|
51
54
|
noindex?: number;
|
|
52
55
|
visibility?: string;
|
|
53
56
|
send_newsletter?: number;
|
|
57
|
+
is_private?: number;
|
|
54
58
|
post_type?: string;
|
|
55
59
|
fields?: string | null;
|
|
56
60
|
}
|
|
@@ -130,6 +134,18 @@ export declare const Post: {
|
|
|
130
134
|
findPublishedById(id: number): Promise<PostType | undefined>;
|
|
131
135
|
create(data: CreatePostData): Promise<PostType>;
|
|
132
136
|
update(id: number, data: UpdatePostData): Promise<PostType>;
|
|
137
|
+
/**
|
|
138
|
+
* Forget a draft's slug, so the first real save derives one.
|
|
139
|
+
*
|
|
140
|
+
* For the draft an autosave makes from a new post's first words (see
|
|
141
|
+
* `PostController.autosaveNew`): a slug derived then would come from "He",
|
|
142
|
+
* or be `post` for a draft with only a body, and the editor would load it
|
|
143
|
+
* back as if the author had chosen it. Null is what a post with no slug yet
|
|
144
|
+
* already means, and the unique index allows any number of them.
|
|
145
|
+
*/
|
|
146
|
+
/** The draft a first autosave with this key already made, if any (migration 044). */
|
|
147
|
+
findByAutosaveKey(userId: number, key: string): Promise<PostType | undefined>;
|
|
148
|
+
forgetSlug(id: number): Promise<void>;
|
|
133
149
|
/** Gone for good. Only ever called on a post already in the trash. */
|
|
134
150
|
delete(id: number): Promise<void>;
|
|
135
151
|
};
|
package/lib/models/Post.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { getDb
|
|
1
|
+
import { getDb } from '@basicbenframework/core/db';
|
|
2
|
+
import { insertRow } from "../helpers/insert-row.js";
|
|
2
3
|
import { hooks, HOOKS } from '@basicbenframework/core/hooks';
|
|
3
4
|
import { renderContent } from '@basicbenframework/core/content';
|
|
4
5
|
import { getStorage } from '@basicbenframework/core/storage';
|
|
@@ -19,7 +20,7 @@ const UPDATABLE = [
|
|
|
19
20
|
'status', 'deleted_at', 'live_notified',
|
|
20
21
|
'og_title', 'og_description', 'og_image', 'twitter_title', 'twitter_description',
|
|
21
22
|
'twitter_image', 'canonical_url', 'noindex',
|
|
22
|
-
'visibility', 'send_newsletter',
|
|
23
|
+
'visibility', 'send_newsletter', 'is_private',
|
|
23
24
|
// Content types (migrations 038–039). Validated by helpers/content-model.ts
|
|
24
25
|
// before they reach here.
|
|
25
26
|
'post_type', 'fields'
|
|
@@ -246,7 +247,7 @@ export const Post = {
|
|
|
246
247
|
// INSERT there reports lastInsertRowid as null, so the row is written and
|
|
247
248
|
// the caller is handed an object with no id — the failure looks like a bug
|
|
248
249
|
// in whatever used the id next.
|
|
249
|
-
const result = await (
|
|
250
|
+
const result = await insertRow('posts', {
|
|
250
251
|
user_id: data.user_id,
|
|
251
252
|
title: data.title,
|
|
252
253
|
content: data.content,
|
|
@@ -262,8 +263,10 @@ export const Post = {
|
|
|
262
263
|
live_notified: data.live_notified ?? 1,
|
|
263
264
|
visibility: data.visibility ?? 'public',
|
|
264
265
|
send_newsletter: data.send_newsletter ?? 0,
|
|
266
|
+
is_private: data.is_private ? 1 : 0,
|
|
265
267
|
post_type: data.post_type ?? 'post',
|
|
266
268
|
fields: data.fields ?? null,
|
|
269
|
+
...(data.autosave_key ? { autosave_key: data.autosave_key } : {}),
|
|
267
270
|
...Object.fromEntries(SEO_FIELDS.filter((key) => data[key] !== undefined).map((key) => [key, data[key]]))
|
|
268
271
|
});
|
|
269
272
|
const now = new Date().toISOString();
|
|
@@ -309,6 +312,24 @@ export const Post = {
|
|
|
309
312
|
await db.run(`UPDATE posts SET ${fields}, updated_at = CURRENT_TIMESTAMP WHERE id = ?`, [...writable.map(([, value]) => value), id]);
|
|
310
313
|
return this.find(id);
|
|
311
314
|
},
|
|
315
|
+
/**
|
|
316
|
+
* Forget a draft's slug, so the first real save derives one.
|
|
317
|
+
*
|
|
318
|
+
* For the draft an autosave makes from a new post's first words (see
|
|
319
|
+
* `PostController.autosaveNew`): a slug derived then would come from "He",
|
|
320
|
+
* or be `post` for a draft with only a body, and the editor would load it
|
|
321
|
+
* back as if the author had chosen it. Null is what a post with no slug yet
|
|
322
|
+
* already means, and the unique index allows any number of them.
|
|
323
|
+
*/
|
|
324
|
+
/** The draft a first autosave with this key already made, if any (migration 044). */
|
|
325
|
+
async findByAutosaveKey(userId, key) {
|
|
326
|
+
const db = await getDb();
|
|
327
|
+
return db.get('SELECT * FROM posts WHERE user_id = ? AND autosave_key = ?', [userId, key]);
|
|
328
|
+
},
|
|
329
|
+
async forgetSlug(id) {
|
|
330
|
+
const db = await getDb();
|
|
331
|
+
await db.run('UPDATE posts SET slug = NULL WHERE id = ?', [id]);
|
|
332
|
+
},
|
|
312
333
|
/** Gone for good. Only ever called on a post already in the trash. */
|
|
313
334
|
async delete(id) {
|
|
314
335
|
const db = await getDb();
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { getDb
|
|
1
|
+
import { getDb } from '@basicbenframework/core/db';
|
|
2
|
+
import { insertRow } from "../helpers/insert-row.js";
|
|
2
3
|
import { parseStoredTimestamp } from "./visibility.js";
|
|
3
4
|
/** How many saved revisions a post keeps. The oldest beyond this are pruned. */
|
|
4
5
|
const KEEP = 50;
|
|
@@ -18,7 +19,7 @@ export const PostRevision = {
|
|
|
18
19
|
(after.excerpt !== undefined && (after.excerpt ?? null) !== (before.excerpt ?? null));
|
|
19
20
|
if (!changed)
|
|
20
21
|
return;
|
|
21
|
-
await (
|
|
22
|
+
await insertRow('post_revisions', {
|
|
22
23
|
post_id: before.id,
|
|
23
24
|
user_id: userId,
|
|
24
25
|
title: before.title,
|
|
@@ -48,7 +49,7 @@ export const PostRevision = {
|
|
|
48
49
|
async autosave(postId, userId, data) {
|
|
49
50
|
const db = await getDb();
|
|
50
51
|
await db.run('DELETE FROM post_revisions WHERE post_id = ? AND user_id = ? AND autosave = 1', [postId, userId]);
|
|
51
|
-
const result = await (
|
|
52
|
+
const result = await insertRow('post_revisions', {
|
|
52
53
|
post_id: postId,
|
|
53
54
|
user_id: userId,
|
|
54
55
|
title: data.title,
|
|
@@ -173,7 +173,7 @@ export declare const PublicContent: {
|
|
|
173
173
|
*
|
|
174
174
|
* Only people who have published: an account with no posts is a user, not an
|
|
175
175
|
* author, and listing one exposes that the account exists to anyone who asks
|
|
176
|
-
* for the author index. Counts come from the same `
|
|
176
|
+
* for the author index. Counts come from the same `livePost` filter the
|
|
177
177
|
* post listing uses, so an archive link never leads to an empty page.
|
|
178
178
|
*/
|
|
179
179
|
authors(): Promise<PublicAuthor[]>;
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
*/
|
|
14
14
|
import { getDb } from '@basicbenframework/core/db';
|
|
15
15
|
import { getStorage, absoluteUrl } from '@basicbenframework/core/storage';
|
|
16
|
-
import { livePost, parseStoredTimestamp } from "./visibility.js";
|
|
16
|
+
import { livePost, livePage, parseStoredTimestamp } from "./visibility.js";
|
|
17
17
|
import { responsiveImage } from "../helpers/images.js";
|
|
18
18
|
import { siteUrl } from "../helpers/site.js";
|
|
19
19
|
import { publicExcerpt } from "../helpers/gating.js";
|
|
@@ -194,9 +194,9 @@ export const PublicContent = {
|
|
|
194
194
|
async pages(options = {}) {
|
|
195
195
|
const db = await getDb();
|
|
196
196
|
const { perPage = 10, offset = 0, format = 'html' } = options;
|
|
197
|
-
const counted = (await db.get(
|
|
197
|
+
const counted = (await db.get(`SELECT COUNT(*) AS total FROM pages WHERE ${livePage('pages')}`));
|
|
198
198
|
const rows = (await db.all(`SELECT ${PAGE_COLUMNS} ${PAGE_JOINS}
|
|
199
|
-
WHERE pages
|
|
199
|
+
WHERE ${livePage('pages')}
|
|
200
200
|
ORDER BY pages.created_at DESC
|
|
201
201
|
LIMIT ? OFFSET ?`, [perPage, offset]));
|
|
202
202
|
return { pages: await shapePages(rows, format), total: Number(counted?.total) || 0 };
|
|
@@ -205,7 +205,7 @@ export const PublicContent = {
|
|
|
205
205
|
async page(identifier, format = 'html') {
|
|
206
206
|
const db = await getDb();
|
|
207
207
|
const row = (await db.get(`SELECT ${PAGE_COLUMNS} ${PAGE_JOINS}
|
|
208
|
-
WHERE pages
|
|
208
|
+
WHERE ${livePage('pages')} AND (pages.slug = ? OR pages.id = ?)`, [identifier, Number(identifier) || -1]));
|
|
209
209
|
return row ? (await shapePages([row], format))[0] : null;
|
|
210
210
|
},
|
|
211
211
|
/**
|
|
@@ -247,7 +247,7 @@ export const PublicContent = {
|
|
|
247
247
|
*
|
|
248
248
|
* Only people who have published: an account with no posts is a user, not an
|
|
249
249
|
* author, and listing one exposes that the account exists to anyone who asks
|
|
250
|
-
* for the author index. Counts come from the same `
|
|
250
|
+
* for the author index. Counts come from the same `livePost` filter the
|
|
251
251
|
* post listing uses, so an archive link never leads to an empty page.
|
|
252
252
|
*/
|
|
253
253
|
async authors() {
|
package/lib/models/Snippet.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { getDb
|
|
1
|
+
import { getDb } from '@basicbenframework/core/db';
|
|
2
|
+
import { insertRow } from "../helpers/insert-row.js";
|
|
2
3
|
const SELECT = `
|
|
3
4
|
SELECT snippets.id, snippets.name, snippets.content, snippets.created_by,
|
|
4
5
|
snippets.created_at, snippets.updated_at, users.name AS author_name
|
|
@@ -31,7 +32,7 @@ export const Snippet = {
|
|
|
31
32
|
const now = new Date().toISOString();
|
|
32
33
|
// Through the query builder, which appends RETURNING id on Postgres; a raw
|
|
33
34
|
// INSERT there reports no id (see Tag.create).
|
|
34
|
-
const result = await (
|
|
35
|
+
const result = await insertRow('snippets', {
|
|
35
36
|
name: data.name,
|
|
36
37
|
content: data.content,
|
|
37
38
|
created_by: data.created_by,
|
package/lib/models/Tag.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { getDb
|
|
1
|
+
import { getDb } from '@basicbenframework/core/db';
|
|
2
|
+
import { insertRow } from "../helpers/insert-row.js";
|
|
2
3
|
import { livePost } from "./visibility.js";
|
|
3
4
|
function slugify(text) {
|
|
4
5
|
return text
|
|
@@ -64,7 +65,7 @@ export const Tag = {
|
|
|
64
65
|
// INSERT there reports lastInsertRowid as null, so the row is written and
|
|
65
66
|
// the caller is handed an object with no id — the failure looks like a bug
|
|
66
67
|
// in whatever used the id next.
|
|
67
|
-
const result = await (
|
|
68
|
+
const result = await insertRow('tags', { name: data.name, slug });
|
|
68
69
|
return {
|
|
69
70
|
id: result.lastInsertRowid,
|
|
70
71
|
name: data.name,
|
package/lib/models/Taxonomy.js
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
* so this loads under plain Node too.
|
|
12
12
|
*/
|
|
13
13
|
import { getDb, query } from '@basicbenframework/core/db';
|
|
14
|
+
import { insertRow } from "../helpers/insert-row.js";
|
|
14
15
|
import { slugify } from '@basicbenframework/core/content';
|
|
15
16
|
import { livePost } from "./visibility.js";
|
|
16
17
|
/** Keys the built-in taxonomies answer to, and words the API already uses. */
|
|
@@ -197,7 +198,7 @@ export const Taxonomy = {
|
|
|
197
198
|
return keys.filter((key) => !known.has(key));
|
|
198
199
|
},
|
|
199
200
|
async create(values) {
|
|
200
|
-
const result = await (
|
|
201
|
+
const result = await insertRow('taxonomies', {
|
|
201
202
|
key: values.key,
|
|
202
203
|
singular_label: values.singular_label,
|
|
203
204
|
plural_label: values.plural_label,
|
|
@@ -270,7 +271,9 @@ export const Taxonomy = {
|
|
|
270
271
|
return Boolean(row);
|
|
271
272
|
},
|
|
272
273
|
async createTerm(taxonomyId, values) {
|
|
273
|
-
const result = await (await query('terms'))
|
|
274
|
+
const result = await (await query('terms'))
|
|
275
|
+
.only('taxonomy_id', 'name', 'slug', 'description', 'parent_id')
|
|
276
|
+
.insert({ taxonomy_id: taxonomyId, ...values });
|
|
274
277
|
return (await this.findTerm(Number(result.lastInsertRowid)));
|
|
275
278
|
},
|
|
276
279
|
async updateTerm(id, values) {
|
package/lib/models/User.js
CHANGED
|
@@ -43,8 +43,12 @@ export const User = {
|
|
|
43
43
|
const slug = await uniqueSlug('users', data.slug || data.name, { fallback: 'author' });
|
|
44
44
|
// Goes through the query builder so Postgres gets a RETURNING clause and
|
|
45
45
|
// the new id comes back — a raw INSERT yields a null id there.
|
|
46
|
+
// The caller's data is spread in, so the columns are named: a key added to
|
|
47
|
+
// CreateUserData, or smuggled in by a caller, never reaches the table.
|
|
46
48
|
const users = await query('users');
|
|
47
|
-
const result = await users
|
|
49
|
+
const result = await users
|
|
50
|
+
.only('name', 'email', 'password', 'role', 'slug', 'email_verified', 'email_verified_at')
|
|
51
|
+
.insert({ ...data, role, slug });
|
|
48
52
|
return {
|
|
49
53
|
id: result.lastInsertRowid,
|
|
50
54
|
...data,
|
|
@@ -14,8 +14,17 @@
|
|
|
14
14
|
* Scheduling needs no cron: a scheduled post simply starts matching when its
|
|
15
15
|
* time comes. What does need a tick is telling webhooks — see `publishDue()` in
|
|
16
16
|
* `src/hooks.ts`.
|
|
17
|
+
*
|
|
18
|
+
* Not private (migration 043): a private post is published for the people who
|
|
19
|
+
* can edit it, in the admin, and for nobody on any public surface. Folding it
|
|
20
|
+
* into this fragment is what makes that true everywhere at once.
|
|
17
21
|
*/
|
|
18
22
|
export declare function livePost(alias?: string): string;
|
|
23
|
+
/**
|
|
24
|
+
* When a page is on the public site: published and not private. The page
|
|
25
|
+
* counterpart of `livePost`, for the same reason — one copy of the rule.
|
|
26
|
+
*/
|
|
27
|
+
export declare function livePage(alias?: string): string;
|
|
19
28
|
/** Normalise a date to the stored form, or null. Throws on nonsense. */
|
|
20
29
|
export declare function toStoredTimestamp(value: unknown): string | null;
|
|
21
30
|
/** The editorial states a post can be in. Scheduled is published-in-the-future. */
|
package/lib/models/visibility.js
CHANGED
|
@@ -14,10 +14,24 @@
|
|
|
14
14
|
* Scheduling needs no cron: a scheduled post simply starts matching when its
|
|
15
15
|
* time comes. What does need a tick is telling webhooks — see `publishDue()` in
|
|
16
16
|
* `src/hooks.ts`.
|
|
17
|
+
*
|
|
18
|
+
* Not private (migration 043): a private post is published for the people who
|
|
19
|
+
* can edit it, in the admin, and for nobody on any public surface. Folding it
|
|
20
|
+
* into this fragment is what makes that true everywhere at once.
|
|
17
21
|
*/
|
|
18
22
|
export function livePost(alias = 'posts') {
|
|
19
23
|
const now = new Date().toISOString();
|
|
20
|
-
return `(${alias}.published = 1 AND ${alias}.deleted_at IS NULL AND (${alias}.publish_at IS NULL OR ${alias}.publish_at <= '${now}'))`;
|
|
24
|
+
return `(${alias}.published = 1 AND ${alias}.deleted_at IS NULL AND (${alias}.publish_at IS NULL OR ${alias}.publish_at <= '${now}') AND ${notPrivate(alias)})`;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* When a page is on the public site: published and not private. The page
|
|
28
|
+
* counterpart of `livePost`, for the same reason — one copy of the rule.
|
|
29
|
+
*/
|
|
30
|
+
export function livePage(alias = 'pages') {
|
|
31
|
+
return `(${alias}.published = 1 AND ${notPrivate(alias)})`;
|
|
32
|
+
}
|
|
33
|
+
function notPrivate(alias) {
|
|
34
|
+
return `${alias}.is_private = 0`;
|
|
21
35
|
}
|
|
22
36
|
/** Normalise a date to the stored form, or null. Throws on nonsense. */
|
|
23
37
|
export function toStoredTimestamp(value) {
|
package/lib/routes/api/posts.js
CHANGED
|
@@ -21,6 +21,9 @@ export default (router) => {
|
|
|
21
21
|
router.post('/api/posts', contentWrite, requireCapability('post.create'), PostController.store);
|
|
22
22
|
// Before the /:id routes, which would otherwise read `bulk` as an id.
|
|
23
23
|
router.post('/api/posts/bulk', auth, PostController.bulk);
|
|
24
|
+
// The editor's first autosave of a post that has never been saved: a draft,
|
|
25
|
+
// from whatever has been typed so far. A person's, like autosave itself.
|
|
26
|
+
router.post('/api/posts/autosave', auth, requireCapability('post.create'), PostController.autosaveNew);
|
|
24
27
|
router.get('/api/posts/:id', contentWrite, PostController.show);
|
|
25
28
|
router.post('/api/posts/:id/restore', auth, PostController.restore);
|
|
26
29
|
router.put('/api/posts/:id/autosave', auth, PostController.autosave);
|
package/lib/types/index.d.ts
CHANGED
|
@@ -83,6 +83,8 @@ export interface Post {
|
|
|
83
83
|
noindex?: number | boolean;
|
|
84
84
|
/** Who may read the body: `public`, or a level the access policy defines (helpers/access.ts). */
|
|
85
85
|
visibility?: string;
|
|
86
|
+
/** 1 when private: published, but only for people who can edit it, in the admin (migration 043). */
|
|
87
|
+
is_private?: number | boolean;
|
|
86
88
|
/** Written by the members feature: the author asked for this post to be emailed when it goes live. */
|
|
87
89
|
send_newsletter?: number | boolean;
|
|
88
90
|
/** Content type key (migration 038). `post` for every post that predates types. */
|
|
@@ -126,6 +128,8 @@ export interface Page {
|
|
|
126
128
|
content_html?: string;
|
|
127
129
|
template: string;
|
|
128
130
|
published: boolean;
|
|
131
|
+
/** 1 when private: published, but only for people who can edit it, in the admin (migration 043). */
|
|
132
|
+
is_private?: number | boolean;
|
|
129
133
|
parent_id?: number;
|
|
130
134
|
menu_order: number;
|
|
131
135
|
/** Foreign key into `media`. Not a filename — see `featured_image_url`. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@basicbenframework/cms",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "The BasicBen CMS. Posts, pages, media, an admin UI, and a headless content API.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"restore": "npm run restore --workspace site --"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
58
|
-
"@basicbenframework/core": "^0.
|
|
58
|
+
"@basicbenframework/core": "^0.9.0",
|
|
59
59
|
"react": "^19.2.0",
|
|
60
60
|
"react-dom": "^19.2.0"
|
|
61
61
|
},
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
"tailwindcss": "^4.3.3"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
|
-
"@basicbenframework/core": "^0.
|
|
68
|
+
"@basicbenframework/core": "^0.9.0",
|
|
69
69
|
"@types/node": "^24",
|
|
70
70
|
"@types/react": "^19",
|
|
71
71
|
"@types/react-dom": "^19",
|