Repository navigation
Expand file tree
/
Copy pathwirecat.config.ts
More file actions
148 lines (146 loc) · 6 KB
/
Copy pathwirecat.config.ts
File metadata and controls
148 lines (146 loc) · 6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import { defineCli } from "@wirecat/cli-core/manifest"
// WordPress's posts and pages: every status, sorted by id to list and by change time to sync.
const STATUSES = "publish,future,draft,pending,private,trash"
const ME = { operation: "getWpV2UsersMe", query: { context: "edit", _fields: "capabilities" } }
const posts = (operation: string, type: "post" | "page") => {
const list = { operation, query: { context: "edit", status: STATUSES, per_page: 100, orderby: "id", order: "asc" } }
return {
list,
changes: {
operation,
query: { ...list.query, orderby: "modified", modified_after: "{since}" },
since: "iso" as const,
keyset: { field: "modified_gmt" },
},
ids: { operation, query: { context: "edit", status: STATUSES, per_page: 100, orderby: "id", _fields: "id" } },
get: { operation: `${operation}ById`, path: { id: "{id}" }, query: { context: "edit" } },
map: {
externalId: "id",
type: { value: type },
title: "title.raw",
excerpt: "excerpt.raw",
url: "link",
slug: "slug",
status: {
path: "status",
map: {
publish: "published",
future: "scheduled",
draft: "draft",
pending: "pending",
private: "private",
trash: "trashed",
},
},
publishedAt: "date_gmt",
scheduledFor: "date_gmt",
updatedAt: "modified_gmt",
version: "modified_gmt",
authors: "author",
terms: { all: ["tags", "categories"] },
},
body: {
path: "content.raw",
format: "wp-blocks" as const,
fallback: { path: "content.rendered", format: "html" as const },
},
optional:
type === "post"
? {
message: "the sign-in may not read every post: an author or a contributor reads only their own",
scope: "edit_others_posts",
requires: { ...ME, check: "capabilities.edit_others_posts" },
}
: {
message: "the sign-in may not read every page",
scope: "edit_others_pages",
requires: { ...ME, check: "capabilities.edit_others_pages" },
// WordPress refuses an author or a contributor pages with a private status (HTTP 400, 403 inside).
needs: {
...ME,
check: "capabilities.edit_pages",
message: "only an editor or administrator reads the pages",
scope: "edit_pages",
},
},
}
}
export default defineCli({
identity: {
command: "wordpress",
package: "@wirecat/wordpress-cli",
prefix: "WCWP",
service: "WordPress",
owner: "WireCatLabs",
},
spec: { kind: "wp-json", from: "https://localhost:8443/wp-json/", version: "6.9.4" },
auth: { preset: "app-password", verify: { operation: "getWpV2UsersMe", id: "id", name: "name" } },
category: "content",
source: {
provider: "wordpress",
kinds: ["author", "term", "post"],
channel: { kind: "blog", network: "wordpress" },
entities: {
author: [
{
list: { operation: "getWpV2Users", query: { context: "edit", per_page: 100, orderby: "id" } },
// biome-ignore lint/security/noSecrets: an operation id, not a secret
get: { operation: "getWpV2UsersById", path: { id: "{id}" }, query: { context: "edit" } },
map: { externalId: "id", name: "name", email: "email", slug: "slug" },
optional: {
message: "only an administrator lists the users",
scope: "list_users",
// WordPress refuses context=edit without list_users, and lists in context=view the authors with published
// posts, without their e-mail (checked on 6.9.4 as an Editor and an Author).
fallback: {
query: { context: "view" },
message:
"only an administrator lists every user and their e-mail: these are the authors with published posts",
scope: "list_users",
},
},
},
],
// A tag's or category's name and slug are public. An Author or Contributor may not edit terms: no context=edit.
term: [
{
list: { operation: "getWpV2Tags", query: { per_page: 100, orderby: "id" } },
// biome-ignore lint/security/noSecrets: an operation id, not a secret
get: { operation: "getWpV2TagsById", path: { id: "{id}" } },
map: { externalId: "id", kind: { value: "tag" }, name: "name", slug: "slug" },
},
{
list: { operation: "getWpV2Categories", query: { per_page: 100, orderby: "id" } },
get: { operation: "getWpV2CategoriesById", path: { id: "{id}" } },
map: { externalId: "id", kind: { value: "category" }, name: "name", slug: "slug" },
},
],
post: [posts("getWpV2Posts", "post"), posts("getWpV2Pages", "page")],
},
writes: {
create: { operation: "postWpV2Posts", body: { status: "draft" } },
update: { operation: "postWpV2PostsById", path: { id: "{id}" } },
trash: { operation: "deleteWpV2PostsById", path: { id: "{id}" } },
delete: { operation: "deleteWpV2PostsById", path: { id: "{id}" }, query: { force: true } },
fields: {
title: "title.raw",
body: "content.raw",
excerpt: "excerpt.raw",
slug: "slug",
terms: { tag: "tags", category: "categories" },
},
publish: { status: "publish" },
schedule: { status: "future", date_gmt: "{at}" },
unpublish: { status: "draft" },
// A page has no tags or categories.
page: {
create: { operation: "postWpV2Pages", body: { status: "draft" } },
// biome-ignore lint/security/noSecrets: an operation id, not a secret
update: { operation: "postWpV2PagesById", path: { id: "{id}" } },
trash: { operation: "deleteWpV2PagesById", path: { id: "{id}" } },
delete: { operation: "deleteWpV2PagesById", path: { id: "{id}" }, query: { force: true } },
fields: { title: "title.raw", body: "content.raw", excerpt: "excerpt.raw", slug: "slug" },
},
},
},
})