@tryghost/ghst 0.20.0 → 0.21.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/README.md +10 -2
- package/dist/index.js +135 -77
- package/dist/index.js.map +1 -1
- package/package.json +12 -12
package/README.md
CHANGED
|
@@ -167,10 +167,12 @@ Interactive destructive confirmations also emit `GHST_AGENT_NOTICE:` lines on st
|
|
|
167
167
|
Create and publish:
|
|
168
168
|
|
|
169
169
|
```bash
|
|
170
|
-
ghst post create --title "Launch" --markdown-file ./launch.md
|
|
170
|
+
ghst post create --title "Launch" --slug launch --markdown-file ./launch.md
|
|
171
171
|
ghst post publish <post-id> --newsletter weekly --email-segment all
|
|
172
172
|
```
|
|
173
173
|
|
|
174
|
+
A leading YAML front-matter block (`---` ... `---`) in Markdown input is dropped rather than rendered into the post body. Its keys are not read, so set the title, tags, slug, and excerpt with flags or `--from-json`.
|
|
175
|
+
|
|
174
176
|
The email delivery flags (`--newsletter`, `--email-only`, `--email-segment`) belong on `post publish` (or `post schedule` / `post update`) — Ghost's email send pipeline fires on the publish transition, not on create.
|
|
175
177
|
|
|
176
178
|
Pages share the same content flags as posts, including `--slug`, `--tags`, `--from-json`, and `--markdown-file`:
|
|
@@ -254,7 +256,7 @@ ghst socialweb reply https://example.com/users/alice/statuses/1 --content "Reply
|
|
|
254
256
|
|
|
255
257
|
Social web auth note:
|
|
256
258
|
- `ghst socialweb` bootstraps a short-lived identity JWT from `/ghost/api/admin/identities/`.
|
|
257
|
-
-
|
|
259
|
+
- Social web requires an Owner or Administrator staff access token.
|
|
258
260
|
- `ghst socialweb delete` requires `--enable-destructive-actions` and confirmation; use `--yes` in non-interactive scripts.
|
|
259
261
|
- Public Ghost post publishing still lives under `ghst post`; `ghst socialweb` is for notes, interactions, profile, feed, and moderation flows.
|
|
260
262
|
|
|
@@ -414,6 +416,12 @@ the CLI.
|
|
|
414
416
|
|
|
415
417
|
- Re-run auth with `--non-interactive` and explicit credentials.
|
|
416
418
|
|
|
419
|
+
`Ghost Admin discovery ... was redirected to ..., which does not serve the Ghost Admin API`:
|
|
420
|
+
|
|
421
|
+
- Something in front of Ghost, such as Cloudflare Access or an SSO gateway, redirected `ghst auth login` to its own login page.
|
|
422
|
+
- Re-run with `--url` set to an address that reaches Ghost without the proxy, or
|
|
423
|
+
- Set `GHOST_URL` to that address and `GHOST_STAFF_ACCESS_TOKEN` instead of logging in.
|
|
424
|
+
|
|
417
425
|
Commands and flags drift:
|
|
418
426
|
|
|
419
427
|
- Re-check current command docs with `ghst <resource> --help`.
|
package/dist/index.js
CHANGED
|
@@ -2507,6 +2507,64 @@ async function confirmDestructiveAction(question, notice) {
|
|
|
2507
2507
|
return confirm(question);
|
|
2508
2508
|
}
|
|
2509
2509
|
|
|
2510
|
+
// src/lib/site.ts
|
|
2511
|
+
async function getClient(global) {
|
|
2512
|
+
const connection = await resolveConnectionConfig(global);
|
|
2513
|
+
return new GhostClient({
|
|
2514
|
+
url: connection.url,
|
|
2515
|
+
staffToken: connection.staffToken,
|
|
2516
|
+
version: connection.apiVersion
|
|
2517
|
+
});
|
|
2518
|
+
}
|
|
2519
|
+
async function getSiteInfo(global) {
|
|
2520
|
+
const client = await getClient(global);
|
|
2521
|
+
return client.siteInfo();
|
|
2522
|
+
}
|
|
2523
|
+
function probeNetworkError(probeUrl, error) {
|
|
2524
|
+
return new GhstError(
|
|
2525
|
+
`Unable to reach Ghost Admin URL '${probeUrl}': ${error.message}`,
|
|
2526
|
+
{
|
|
2527
|
+
exitCode: 1 /* GENERAL_ERROR */,
|
|
2528
|
+
code: "NETWORK_ERROR"
|
|
2529
|
+
}
|
|
2530
|
+
);
|
|
2531
|
+
}
|
|
2532
|
+
async function servesGhostAdminApi(origin) {
|
|
2533
|
+
const probeUrl = `${origin}/ghost/api/admin/site/`;
|
|
2534
|
+
let response;
|
|
2535
|
+
let body;
|
|
2536
|
+
try {
|
|
2537
|
+
response = await fetch(probeUrl, {
|
|
2538
|
+
method: "GET",
|
|
2539
|
+
redirect: "manual",
|
|
2540
|
+
headers: { Accept: "application/json" }
|
|
2541
|
+
});
|
|
2542
|
+
body = await response.text();
|
|
2543
|
+
} catch (error) {
|
|
2544
|
+
throw probeNetworkError(probeUrl, error);
|
|
2545
|
+
}
|
|
2546
|
+
if (response.status === 429 || response.status >= 500) {
|
|
2547
|
+
throw new GhstError(
|
|
2548
|
+
`Ghost Admin URL '${probeUrl}' responded with HTTP ${response.status}. Try again later.`,
|
|
2549
|
+
{
|
|
2550
|
+
exitCode: 1 /* GENERAL_ERROR */,
|
|
2551
|
+
code: "NETWORK_ERROR",
|
|
2552
|
+
status: response.status
|
|
2553
|
+
}
|
|
2554
|
+
);
|
|
2555
|
+
}
|
|
2556
|
+
if (!response.ok) {
|
|
2557
|
+
return false;
|
|
2558
|
+
}
|
|
2559
|
+
let payload;
|
|
2560
|
+
try {
|
|
2561
|
+
payload = JSON.parse(body);
|
|
2562
|
+
} catch {
|
|
2563
|
+
return false;
|
|
2564
|
+
}
|
|
2565
|
+
return typeof payload?.site === "object" && payload.site !== null;
|
|
2566
|
+
}
|
|
2567
|
+
|
|
2510
2568
|
// src/commands/auth.ts
|
|
2511
2569
|
var LOGIN_GUIDANCE_BORDER = "------------------------------------------------------------";
|
|
2512
2570
|
var LOGIN_GUIDANCE_TITLE = "Continue In Ghost Admin";
|
|
@@ -2815,6 +2873,15 @@ function registerAuthCommands(program) {
|
|
|
2815
2873
|
const resolvedOrigin = await resolveGhostAdminOrigin(requestedOrigin);
|
|
2816
2874
|
urlInput = resolvedOrigin.resolvedOrigin;
|
|
2817
2875
|
if (hasOriginChanged(resolvedOrigin.inputOrigin, resolvedOrigin.resolvedOrigin)) {
|
|
2876
|
+
if (!await servesGhostAdminApi(resolvedOrigin.resolvedOrigin)) {
|
|
2877
|
+
throw new GhstError(
|
|
2878
|
+
`Ghost Admin discovery for '${resolvedOrigin.inputOrigin}' was redirected to '${resolvedOrigin.resolvedOrigin}', which does not serve the Ghost Admin API. An authenticating proxy (such as Cloudflare Access or an SSO gateway) may be in front of the site, or Ghost is not served at that address. Re-run with --url set to an address that reaches Ghost without the proxy, or set GHOST_URL to that address with GHOST_STAFF_ACCESS_TOKEN instead of logging in.`,
|
|
2879
|
+
{
|
|
2880
|
+
exitCode: 2 /* USAGE_ERROR */,
|
|
2881
|
+
code: "USAGE_ERROR"
|
|
2882
|
+
}
|
|
2883
|
+
);
|
|
2884
|
+
}
|
|
2818
2885
|
if (nonInteractive) {
|
|
2819
2886
|
throw new GhstError(
|
|
2820
2887
|
`Ghost Admin discovery resolved to '${resolvedOrigin.resolvedOrigin}' instead of '${resolvedOrigin.inputOrigin}'. Re-run with --url ${resolvedOrigin.resolvedOrigin}.`,
|
|
@@ -3141,7 +3208,7 @@ async function collectAllPages(key, fetchPage) {
|
|
|
3141
3208
|
}
|
|
3142
3209
|
|
|
3143
3210
|
// src/lib/comments.ts
|
|
3144
|
-
async function
|
|
3211
|
+
async function getClient2(global) {
|
|
3145
3212
|
const connection = await resolveConnectionConfig(global);
|
|
3146
3213
|
return new GhostClient({
|
|
3147
3214
|
url: connection.url,
|
|
@@ -3156,7 +3223,7 @@ function withDefaultLimit(params) {
|
|
|
3156
3223
|
};
|
|
3157
3224
|
}
|
|
3158
3225
|
async function listComments(global, options, allPages) {
|
|
3159
|
-
const client = await
|
|
3226
|
+
const client = await getClient2(global);
|
|
3160
3227
|
const params = withDefaultLimit({
|
|
3161
3228
|
limit: options.limit,
|
|
3162
3229
|
page: options.page,
|
|
@@ -3171,11 +3238,11 @@ async function listComments(global, options, allPages) {
|
|
|
3171
3238
|
return collectAllPages("comments", (page) => client.comments.browseAll({ ...params, page }));
|
|
3172
3239
|
}
|
|
3173
3240
|
async function getComment(global, id) {
|
|
3174
|
-
const client = await
|
|
3241
|
+
const client = await getClient2(global);
|
|
3175
3242
|
return client.comments.readForModeration(id);
|
|
3176
3243
|
}
|
|
3177
3244
|
async function getCommentThread(global, id) {
|
|
3178
|
-
const client = await
|
|
3245
|
+
const client = await getClient2(global);
|
|
3179
3246
|
const [selectedPayload, threadPayload] = await Promise.all([
|
|
3180
3247
|
client.comments.readForModeration(id),
|
|
3181
3248
|
collectAllPages("comments", (page) => client.comments.browseThread(id, { page }))
|
|
@@ -3189,7 +3256,7 @@ async function getCommentThread(global, id) {
|
|
|
3189
3256
|
};
|
|
3190
3257
|
}
|
|
3191
3258
|
async function listCommentReplies(global, id, options, allPages) {
|
|
3192
|
-
const client = await
|
|
3259
|
+
const client = await getClient2(global);
|
|
3193
3260
|
const params = withDefaultLimit({
|
|
3194
3261
|
limit: options.limit,
|
|
3195
3262
|
page: options.page,
|
|
@@ -3202,7 +3269,7 @@ async function listCommentReplies(global, id, options, allPages) {
|
|
|
3202
3269
|
return collectAllPages("comments", (page) => client.comments.replies(id, { ...params, page }));
|
|
3203
3270
|
}
|
|
3204
3271
|
async function listCommentLikes(global, id, options, allPages) {
|
|
3205
|
-
const client = await
|
|
3272
|
+
const client = await getClient2(global);
|
|
3206
3273
|
const params = withDefaultLimit({
|
|
3207
3274
|
limit: options.limit,
|
|
3208
3275
|
page: options.page,
|
|
@@ -3215,7 +3282,7 @@ async function listCommentLikes(global, id, options, allPages) {
|
|
|
3215
3282
|
return collectAllPages("comment_likes", (page) => client.comments.likes(id, { ...params, page }));
|
|
3216
3283
|
}
|
|
3217
3284
|
async function listCommentReports(global, id, options, allPages) {
|
|
3218
|
-
const client = await
|
|
3285
|
+
const client = await getClient2(global);
|
|
3219
3286
|
const params = withDefaultLimit({
|
|
3220
3287
|
limit: options.limit,
|
|
3221
3288
|
page: options.page
|
|
@@ -3229,7 +3296,7 @@ async function listCommentReports(global, id, options, allPages) {
|
|
|
3229
3296
|
);
|
|
3230
3297
|
}
|
|
3231
3298
|
async function setCommentStatus(global, id, status) {
|
|
3232
|
-
const client = await
|
|
3299
|
+
const client = await getClient2(global);
|
|
3233
3300
|
return client.comments.setStatus(id, status);
|
|
3234
3301
|
}
|
|
3235
3302
|
|
|
@@ -3735,7 +3802,7 @@ function inferImageMimeType(filePath) {
|
|
|
3735
3802
|
const extension = path2.extname(filePath).toLowerCase();
|
|
3736
3803
|
return IMAGE_MIME_BY_EXT[extension] ?? "application/octet-stream";
|
|
3737
3804
|
}
|
|
3738
|
-
async function
|
|
3805
|
+
async function getClient3(global) {
|
|
3739
3806
|
const connection = await resolveConnectionConfig(global);
|
|
3740
3807
|
return new GhostClient({
|
|
3741
3808
|
url: connection.url,
|
|
@@ -3744,7 +3811,7 @@ async function getClient2(global) {
|
|
|
3744
3811
|
});
|
|
3745
3812
|
}
|
|
3746
3813
|
async function uploadImage(global, options) {
|
|
3747
|
-
const client = await
|
|
3814
|
+
const client = await getClient3(global);
|
|
3748
3815
|
const bytes = await fs3.readFile(options.filePath);
|
|
3749
3816
|
const mimeType = inferImageMimeType(options.filePath);
|
|
3750
3817
|
const formData = new FormData();
|
|
@@ -3821,7 +3888,7 @@ function getFirstLabel(payload) {
|
|
|
3821
3888
|
}
|
|
3822
3889
|
return labels[0] ?? {};
|
|
3823
3890
|
}
|
|
3824
|
-
async function
|
|
3891
|
+
async function getClient4(global) {
|
|
3825
3892
|
const connection = await resolveConnectionConfig(global);
|
|
3826
3893
|
return new GhostClient({
|
|
3827
3894
|
url: connection.url,
|
|
@@ -3830,7 +3897,7 @@ async function getClient3(global) {
|
|
|
3830
3897
|
});
|
|
3831
3898
|
}
|
|
3832
3899
|
async function listLabels(global, params, allPages) {
|
|
3833
|
-
const client = await
|
|
3900
|
+
const client = await getClient4(global);
|
|
3834
3901
|
if (!allPages) {
|
|
3835
3902
|
return client.labels.browse(params);
|
|
3836
3903
|
}
|
|
@@ -3838,15 +3905,15 @@ async function listLabels(global, params, allPages) {
|
|
|
3838
3905
|
return collectAllPages("labels", (page) => client.labels.browse({ ...params, page, limit }));
|
|
3839
3906
|
}
|
|
3840
3907
|
async function getLabel(global, idOrSlug, options) {
|
|
3841
|
-
const client = await
|
|
3908
|
+
const client = await getClient4(global);
|
|
3842
3909
|
return client.labels.read(idOrSlug, options);
|
|
3843
3910
|
}
|
|
3844
3911
|
async function createLabel(global, label) {
|
|
3845
|
-
const client = await
|
|
3912
|
+
const client = await getClient4(global);
|
|
3846
3913
|
return client.labels.add(label);
|
|
3847
3914
|
}
|
|
3848
3915
|
async function updateLabel(global, options) {
|
|
3849
|
-
const client = await
|
|
3916
|
+
const client = await getClient4(global);
|
|
3850
3917
|
let id = options.id;
|
|
3851
3918
|
if (!id && options.slug) {
|
|
3852
3919
|
const payload = await client.labels.read(options.slug, { bySlug: true });
|
|
@@ -3862,7 +3929,7 @@ async function updateLabel(global, options) {
|
|
|
3862
3929
|
return client.labels.edit(id, options.patch);
|
|
3863
3930
|
}
|
|
3864
3931
|
async function deleteLabel(global, id) {
|
|
3865
|
-
const client = await
|
|
3932
|
+
const client = await getClient4(global);
|
|
3866
3933
|
return client.labels.delete(id);
|
|
3867
3934
|
}
|
|
3868
3935
|
function extractLabelIds(payload) {
|
|
@@ -4185,7 +4252,7 @@ function emailFilter(email) {
|
|
|
4185
4252
|
const escaped = email.replace(/\\/g, "\\\\").replace(/'/g, "\\'");
|
|
4186
4253
|
return `email:'${escaped}'`;
|
|
4187
4254
|
}
|
|
4188
|
-
async function
|
|
4255
|
+
async function getClient5(global) {
|
|
4189
4256
|
const connection = await resolveConnectionConfig(global);
|
|
4190
4257
|
return new GhostClient({
|
|
4191
4258
|
url: connection.url,
|
|
@@ -4194,7 +4261,7 @@ async function getClient4(global) {
|
|
|
4194
4261
|
});
|
|
4195
4262
|
}
|
|
4196
4263
|
async function listMembers(global, params, allPages) {
|
|
4197
|
-
const client = await
|
|
4264
|
+
const client = await getClient5(global);
|
|
4198
4265
|
if (!allPages) {
|
|
4199
4266
|
return client.members.browse(params);
|
|
4200
4267
|
}
|
|
@@ -4202,7 +4269,7 @@ async function listMembers(global, params, allPages) {
|
|
|
4202
4269
|
return collectAllPages("members", (page) => client.members.browse({ ...params, page, limit }));
|
|
4203
4270
|
}
|
|
4204
4271
|
async function getMember(global, options) {
|
|
4205
|
-
const client = await
|
|
4272
|
+
const client = await getClient5(global);
|
|
4206
4273
|
if (options.id) {
|
|
4207
4274
|
return client.members.read(options.id, options.params);
|
|
4208
4275
|
}
|
|
@@ -4221,11 +4288,11 @@ async function getMember(global, options) {
|
|
|
4221
4288
|
});
|
|
4222
4289
|
}
|
|
4223
4290
|
async function createMember(global, member, params) {
|
|
4224
|
-
const client = await
|
|
4291
|
+
const client = await getClient5(global);
|
|
4225
4292
|
return client.members.add(member, params);
|
|
4226
4293
|
}
|
|
4227
4294
|
async function updateMember(global, options) {
|
|
4228
|
-
const client = await
|
|
4295
|
+
const client = await getClient5(global);
|
|
4229
4296
|
let id = options.id;
|
|
4230
4297
|
if (!id && options.email) {
|
|
4231
4298
|
const payload = await client.members.browse({
|
|
@@ -4244,16 +4311,16 @@ async function updateMember(global, options) {
|
|
|
4244
4311
|
return client.members.edit(id, options.patch);
|
|
4245
4312
|
}
|
|
4246
4313
|
async function deleteMember(global, id, options) {
|
|
4247
|
-
const client = await
|
|
4314
|
+
const client = await getClient5(global);
|
|
4248
4315
|
const params = options?.cancel ? { cancel: true } : void 0;
|
|
4249
4316
|
return client.members.delete(id, params);
|
|
4250
4317
|
}
|
|
4251
4318
|
async function exportMembersCsv(global, params) {
|
|
4252
|
-
const client = await
|
|
4319
|
+
const client = await getClient5(global);
|
|
4253
4320
|
return client.members.exportCsv(params);
|
|
4254
4321
|
}
|
|
4255
4322
|
async function importMembersCsv(global, options) {
|
|
4256
|
-
const client = await
|
|
4323
|
+
const client = await getClient5(global);
|
|
4257
4324
|
const bytes = await fs4.readFile(options.filePath);
|
|
4258
4325
|
const formData = new FormData();
|
|
4259
4326
|
const fileBlob = new Blob([bytes], { type: "text/csv" });
|
|
@@ -4267,7 +4334,7 @@ async function importMembersCsv(global, options) {
|
|
|
4267
4334
|
return client.members.importCsv(formData);
|
|
4268
4335
|
}
|
|
4269
4336
|
async function bulkMembers(global, options) {
|
|
4270
|
-
const client = await
|
|
4337
|
+
const client = await getClient5(global);
|
|
4271
4338
|
const params = {
|
|
4272
4339
|
all: options.all,
|
|
4273
4340
|
filter: options.filter,
|
|
@@ -4349,7 +4416,7 @@ async function bulkMembers(global, options) {
|
|
|
4349
4416
|
}
|
|
4350
4417
|
|
|
4351
4418
|
// src/lib/newsletters.ts
|
|
4352
|
-
async function
|
|
4419
|
+
async function getClient6(global) {
|
|
4353
4420
|
const connection = await resolveConnectionConfig(global);
|
|
4354
4421
|
return new GhostClient({
|
|
4355
4422
|
url: connection.url,
|
|
@@ -4358,7 +4425,7 @@ async function getClient5(global) {
|
|
|
4358
4425
|
});
|
|
4359
4426
|
}
|
|
4360
4427
|
async function listNewsletters(global, params, allPages) {
|
|
4361
|
-
const client = await
|
|
4428
|
+
const client = await getClient6(global);
|
|
4362
4429
|
if (!allPages) {
|
|
4363
4430
|
return client.newsletters.browse(params);
|
|
4364
4431
|
}
|
|
@@ -4369,15 +4436,15 @@ async function listNewsletters(global, params, allPages) {
|
|
|
4369
4436
|
);
|
|
4370
4437
|
}
|
|
4371
4438
|
async function getNewsletter(global, id, params) {
|
|
4372
|
-
const client = await
|
|
4439
|
+
const client = await getClient6(global);
|
|
4373
4440
|
return client.newsletters.read(id, params);
|
|
4374
4441
|
}
|
|
4375
4442
|
async function createNewsletter(global, newsletter, params) {
|
|
4376
|
-
const client = await
|
|
4443
|
+
const client = await getClient6(global);
|
|
4377
4444
|
return client.newsletters.add(newsletter, params);
|
|
4378
4445
|
}
|
|
4379
4446
|
async function updateNewsletter(global, id, patch, params) {
|
|
4380
|
-
const client = await
|
|
4447
|
+
const client = await getClient6(global);
|
|
4381
4448
|
return client.newsletters.edit(id, patch, params);
|
|
4382
4449
|
}
|
|
4383
4450
|
async function bulkNewsletters(global, options) {
|
|
@@ -4433,7 +4500,7 @@ async function bulkNewsletters(global, options) {
|
|
|
4433
4500
|
}
|
|
4434
4501
|
|
|
4435
4502
|
// src/lib/offers.ts
|
|
4436
|
-
async function
|
|
4503
|
+
async function getClient7(global) {
|
|
4437
4504
|
const connection = await resolveConnectionConfig(global);
|
|
4438
4505
|
return new GhostClient({
|
|
4439
4506
|
url: connection.url,
|
|
@@ -4442,7 +4509,7 @@ async function getClient6(global) {
|
|
|
4442
4509
|
});
|
|
4443
4510
|
}
|
|
4444
4511
|
async function listOffers(global, params, allPages) {
|
|
4445
|
-
const client = await
|
|
4512
|
+
const client = await getClient7(global);
|
|
4446
4513
|
if (!allPages) {
|
|
4447
4514
|
return client.offers.browse(params);
|
|
4448
4515
|
}
|
|
@@ -4450,15 +4517,15 @@ async function listOffers(global, params, allPages) {
|
|
|
4450
4517
|
return collectAllPages("offers", (page) => client.offers.browse({ ...params, page, limit }));
|
|
4451
4518
|
}
|
|
4452
4519
|
async function getOffer(global, id) {
|
|
4453
|
-
const client = await
|
|
4520
|
+
const client = await getClient7(global);
|
|
4454
4521
|
return client.offers.read(id);
|
|
4455
4522
|
}
|
|
4456
4523
|
async function createOffer(global, offer) {
|
|
4457
|
-
const client = await
|
|
4524
|
+
const client = await getClient7(global);
|
|
4458
4525
|
return client.offers.add(offer);
|
|
4459
4526
|
}
|
|
4460
4527
|
async function updateOffer(global, id, patch) {
|
|
4461
|
-
const client = await
|
|
4528
|
+
const client = await getClient7(global);
|
|
4462
4529
|
return client.offers.edit(id, patch);
|
|
4463
4530
|
}
|
|
4464
4531
|
async function bulkOffers(global, options) {
|
|
@@ -4537,7 +4604,7 @@ function getFirstPost(payload) {
|
|
|
4537
4604
|
}
|
|
4538
4605
|
return posts[0] ?? {};
|
|
4539
4606
|
}
|
|
4540
|
-
async function
|
|
4607
|
+
async function getClient8(global) {
|
|
4541
4608
|
const connection = await resolveConnectionConfig(global);
|
|
4542
4609
|
return new GhostClient({
|
|
4543
4610
|
url: connection.url,
|
|
@@ -4546,7 +4613,7 @@ async function getClient7(global) {
|
|
|
4546
4613
|
});
|
|
4547
4614
|
}
|
|
4548
4615
|
async function listPosts(global, params, allPages) {
|
|
4549
|
-
const client = await
|
|
4616
|
+
const client = await getClient8(global);
|
|
4550
4617
|
if (!allPages) {
|
|
4551
4618
|
return client.posts.browse(params);
|
|
4552
4619
|
}
|
|
@@ -4558,7 +4625,7 @@ function looksLikeGhostId(value) {
|
|
|
4558
4625
|
return GHOST_OBJECT_ID.test(value);
|
|
4559
4626
|
}
|
|
4560
4627
|
async function getPost(global, idOrSlug, options) {
|
|
4561
|
-
const client = await
|
|
4628
|
+
const client = await getClient8(global);
|
|
4562
4629
|
return client.posts.read(idOrSlug, options);
|
|
4563
4630
|
}
|
|
4564
4631
|
async function withDefaultAuthor(client, resource) {
|
|
@@ -4578,11 +4645,11 @@ async function withDefaultAuthor(client, resource) {
|
|
|
4578
4645
|
}
|
|
4579
4646
|
}
|
|
4580
4647
|
async function createPost(global, post, source) {
|
|
4581
|
-
const client = await
|
|
4648
|
+
const client = await getClient8(global);
|
|
4582
4649
|
return client.posts.add(await withDefaultAuthor(client, post), source);
|
|
4583
4650
|
}
|
|
4584
4651
|
async function updatePost(global, options) {
|
|
4585
|
-
const client = await
|
|
4652
|
+
const client = await getClient8(global);
|
|
4586
4653
|
const lookup = options.slug ?? options.id;
|
|
4587
4654
|
if (!lookup) {
|
|
4588
4655
|
throw new GhstError("Provide an id or --slug.", {
|
|
@@ -4622,7 +4689,7 @@ async function updatePost(global, options) {
|
|
|
4622
4689
|
}
|
|
4623
4690
|
}
|
|
4624
4691
|
async function deletePost(global, id) {
|
|
4625
|
-
const client = await
|
|
4692
|
+
const client = await getClient8(global);
|
|
4626
4693
|
return client.posts.delete(id);
|
|
4627
4694
|
}
|
|
4628
4695
|
async function publishPost(global, id, options) {
|
|
@@ -4652,7 +4719,7 @@ async function unschedulePost(global, id) {
|
|
|
4652
4719
|
});
|
|
4653
4720
|
}
|
|
4654
4721
|
async function copyPost(global, id) {
|
|
4655
|
-
const client = await
|
|
4722
|
+
const client = await getClient8(global);
|
|
4656
4723
|
return client.posts.copy(id);
|
|
4657
4724
|
}
|
|
4658
4725
|
function extractPostIds(payload) {
|
|
@@ -4747,7 +4814,7 @@ function getFirstPage(payload) {
|
|
|
4747
4814
|
}
|
|
4748
4815
|
return pages[0] ?? {};
|
|
4749
4816
|
}
|
|
4750
|
-
async function
|
|
4817
|
+
async function getClient9(global) {
|
|
4751
4818
|
const connection = await resolveConnectionConfig(global);
|
|
4752
4819
|
return new GhostClient({
|
|
4753
4820
|
url: connection.url,
|
|
@@ -4756,7 +4823,7 @@ async function getClient8(global) {
|
|
|
4756
4823
|
});
|
|
4757
4824
|
}
|
|
4758
4825
|
async function listPages(global, params, allPages) {
|
|
4759
|
-
const client = await
|
|
4826
|
+
const client = await getClient9(global);
|
|
4760
4827
|
if (!allPages) {
|
|
4761
4828
|
return client.pages.browse(params);
|
|
4762
4829
|
}
|
|
@@ -4764,15 +4831,15 @@ async function listPages(global, params, allPages) {
|
|
|
4764
4831
|
return collectAllPages("pages", (page) => client.pages.browse({ ...params, page, limit }));
|
|
4765
4832
|
}
|
|
4766
4833
|
async function getPage(global, idOrSlug, options) {
|
|
4767
|
-
const client = await
|
|
4834
|
+
const client = await getClient9(global);
|
|
4768
4835
|
return client.pages.read(idOrSlug, options);
|
|
4769
4836
|
}
|
|
4770
4837
|
async function createPage(global, page, source) {
|
|
4771
|
-
const client = await
|
|
4838
|
+
const client = await getClient9(global);
|
|
4772
4839
|
return client.pages.add(await withDefaultAuthor(client, page), source);
|
|
4773
4840
|
}
|
|
4774
4841
|
async function updatePage(global, options) {
|
|
4775
|
-
const client = await
|
|
4842
|
+
const client = await getClient9(global);
|
|
4776
4843
|
const lookup = options.slug ?? options.id;
|
|
4777
4844
|
if (!lookup) {
|
|
4778
4845
|
throw new GhstError("Provide an id or --slug.", {
|
|
@@ -4801,11 +4868,11 @@ async function updatePage(global, options) {
|
|
|
4801
4868
|
);
|
|
4802
4869
|
}
|
|
4803
4870
|
async function deletePage(global, id) {
|
|
4804
|
-
const client = await
|
|
4871
|
+
const client = await getClient9(global);
|
|
4805
4872
|
return client.pages.delete(id);
|
|
4806
4873
|
}
|
|
4807
4874
|
async function copyPage(global, id) {
|
|
4808
|
-
const client = await
|
|
4875
|
+
const client = await getClient9(global);
|
|
4809
4876
|
return client.pages.copy(id);
|
|
4810
4877
|
}
|
|
4811
4878
|
function extractPageIds(payload) {
|
|
@@ -4873,7 +4940,7 @@ async function bulkPages(global, options) {
|
|
|
4873
4940
|
}
|
|
4874
4941
|
|
|
4875
4942
|
// src/lib/settings.ts
|
|
4876
|
-
async function
|
|
4943
|
+
async function getClient10(global) {
|
|
4877
4944
|
const connection = await resolveConnectionConfig(global);
|
|
4878
4945
|
return new GhostClient({
|
|
4879
4946
|
url: connection.url,
|
|
@@ -4882,7 +4949,7 @@ async function getClient9(global) {
|
|
|
4882
4949
|
});
|
|
4883
4950
|
}
|
|
4884
4951
|
async function listSettings(global) {
|
|
4885
|
-
const client = await
|
|
4952
|
+
const client = await getClient10(global);
|
|
4886
4953
|
return client.settings.browse();
|
|
4887
4954
|
}
|
|
4888
4955
|
async function getSetting(global, key) {
|
|
@@ -4900,7 +4967,7 @@ async function getSetting(global, key) {
|
|
|
4900
4967
|
};
|
|
4901
4968
|
}
|
|
4902
4969
|
async function setSetting(global, key, value) {
|
|
4903
|
-
const client = await
|
|
4970
|
+
const client = await getClient10(global);
|
|
4904
4971
|
try {
|
|
4905
4972
|
return await client.settings.edit([{ key, value }]);
|
|
4906
4973
|
} catch (error) {
|
|
@@ -4919,20 +4986,6 @@ async function setSetting(global, key, value) {
|
|
|
4919
4986
|
}
|
|
4920
4987
|
}
|
|
4921
4988
|
|
|
4922
|
-
// src/lib/site.ts
|
|
4923
|
-
async function getClient10(global) {
|
|
4924
|
-
const connection = await resolveConnectionConfig(global);
|
|
4925
|
-
return new GhostClient({
|
|
4926
|
-
url: connection.url,
|
|
4927
|
-
staffToken: connection.staffToken,
|
|
4928
|
-
version: connection.apiVersion
|
|
4929
|
-
});
|
|
4930
|
-
}
|
|
4931
|
-
async function getSiteInfo(global) {
|
|
4932
|
-
const client = await getClient10(global);
|
|
4933
|
-
return client.siteInfo();
|
|
4934
|
-
}
|
|
4935
|
-
|
|
4936
4989
|
// src/lib/socialweb-client.ts
|
|
4937
4990
|
import fs5 from "fs/promises";
|
|
4938
4991
|
import path4 from "path";
|
|
@@ -5039,15 +5092,12 @@ var SocialWebClient = class {
|
|
|
5039
5092
|
} catch (error) {
|
|
5040
5093
|
const normalized = error;
|
|
5041
5094
|
if (normalized.status === 403) {
|
|
5042
|
-
throw new GhstError(
|
|
5043
|
-
|
|
5044
|
-
|
|
5045
|
-
|
|
5046
|
-
|
|
5047
|
-
|
|
5048
|
-
details: normalized.payload
|
|
5049
|
-
}
|
|
5050
|
-
);
|
|
5095
|
+
throw new GhstError("Ghost refused to issue an identity token.", {
|
|
5096
|
+
code: "AUTH_ERROR",
|
|
5097
|
+
exitCode: 3 /* AUTH_ERROR */,
|
|
5098
|
+
status: 403,
|
|
5099
|
+
details: normalized.payload
|
|
5100
|
+
});
|
|
5051
5101
|
}
|
|
5052
5102
|
throw error;
|
|
5053
5103
|
}
|
|
@@ -5124,6 +5174,8 @@ var SocialWebClient = class {
|
|
|
5124
5174
|
}
|
|
5125
5175
|
if (detailObject?.code === "SITE_MISSING") {
|
|
5126
5176
|
message = "Social web is not enabled on this site.";
|
|
5177
|
+
} else if (detailObject?.code === "ROLE_MISSING") {
|
|
5178
|
+
message = "Social web requires an Owner or Administrator staff token.";
|
|
5127
5179
|
}
|
|
5128
5180
|
} else {
|
|
5129
5181
|
const text2 = await response.text();
|
|
@@ -7416,6 +7468,7 @@ function registerCoreTools(server, global, enabledGroups) {
|
|
|
7416
7468
|
description: "Create a Ghost post.",
|
|
7417
7469
|
inputSchema: z6.object({
|
|
7418
7470
|
title: z6.string(),
|
|
7471
|
+
slug: z6.string().optional(),
|
|
7419
7472
|
html: z6.string().optional(),
|
|
7420
7473
|
status: z6.enum(["draft", "published", "scheduled"]).optional(),
|
|
7421
7474
|
publish_at: z6.string().datetime().optional(),
|
|
@@ -7434,6 +7487,7 @@ function registerCoreTools(server, global, enabledGroups) {
|
|
|
7434
7487
|
global2,
|
|
7435
7488
|
{
|
|
7436
7489
|
title: args.title,
|
|
7490
|
+
slug: args.slug,
|
|
7437
7491
|
html: args.html,
|
|
7438
7492
|
status: args.status,
|
|
7439
7493
|
published_at: args.publish_at,
|
|
@@ -10857,8 +10911,9 @@ function registerOfferCommands(program) {
|
|
|
10857
10911
|
import fs10 from "fs/promises";
|
|
10858
10912
|
import MarkdownIt2 from "markdown-it";
|
|
10859
10913
|
var markdownRenderer2 = new MarkdownIt2({ html: true, linkify: true, breaks: true });
|
|
10914
|
+
var frontMatterPattern = /^\uFEFF?---[ \t]*\r?\n(?:[\s\S]*?\r?\n)??(?:---|\.\.\.)[ \t]*(?:\r?\n|$)/;
|
|
10860
10915
|
function renderMarkdown(markdown) {
|
|
10861
|
-
return markdownRenderer2.render(markdown);
|
|
10916
|
+
return markdownRenderer2.render(markdown.replace(frontMatterPattern, ""));
|
|
10862
10917
|
}
|
|
10863
10918
|
async function readOptionalFile(filePath) {
|
|
10864
10919
|
if (!filePath) {
|
|
@@ -11353,6 +11408,7 @@ var PostGetInputSchema = z12.object({
|
|
|
11353
11408
|
var PostCreateInputSchema = withSingleContentSource2(
|
|
11354
11409
|
z12.object({
|
|
11355
11410
|
title: z12.string().min(1).optional(),
|
|
11411
|
+
slug: z12.string().min(1).optional(),
|
|
11356
11412
|
status: StatusSchema2.optional(),
|
|
11357
11413
|
publishAt: z12.string().datetime({ offset: true }).optional(),
|
|
11358
11414
|
html: z12.string().optional(),
|
|
@@ -11581,10 +11637,11 @@ function registerPostCommands(program) {
|
|
|
11581
11637
|
}
|
|
11582
11638
|
printPostHuman(payload);
|
|
11583
11639
|
});
|
|
11584
|
-
post.command("create").description("Create a post").option("--title <title>", "Post title").option("--status <status>", "Post status").option("--publish-at <datetime>", "Publish date-time for scheduled posts").option("--html <html>", "Post HTML content").option("--html-file <path>", "Path to HTML file").option("--lexical-file <path>", "Path to Lexical JSON file").option("--markdown-file <path>", "Path to Markdown file").option("--markdown-stdin", "Read Markdown content from stdin").option("--html-raw-file <path>", "Path to raw HTML file wrapped in an HTML card").option("--from-json <path>", "Read post payload from JSON file").option("--tags <tags>", "Comma separated tag names").option("--authors <authors>", "Comma separated author emails").option("--featured", "Mark as featured").option("--visibility <visibility>", "public|members|paid|tiers").option("--tier <slug>", "Tier slug for tier visibility access").option("--feature-image <url>", "Feature image URL").option("--excerpt <excerpt>", "Custom excerpt").option("--meta-title <title>", "Meta title").option("--meta-description <description>", "Meta description").option("--og-title <title>", "Open Graph title").option("--og-image <url>", "Open Graph image URL").option("--code-injection-head <value>", "Code injection head HTML").action(async (options, command) => {
|
|
11640
|
+
post.command("create").description("Create a post").option("--title <title>", "Post title").option("--slug <slug>", "Post slug").option("--status <status>", "Post status").option("--publish-at <datetime>", "Publish date-time for scheduled posts").option("--html <html>", "Post HTML content").option("--html-file <path>", "Path to HTML file").option("--lexical-file <path>", "Path to Lexical JSON file").option("--markdown-file <path>", "Path to Markdown file").option("--markdown-stdin", "Read Markdown content from stdin").option("--html-raw-file <path>", "Path to raw HTML file wrapped in an HTML card").option("--from-json <path>", "Read post payload from JSON file").option("--tags <tags>", "Comma separated tag names").option("--authors <authors>", "Comma separated author emails").option("--featured", "Mark as featured").option("--visibility <visibility>", "public|members|paid|tiers").option("--tier <slug>", "Tier slug for tier visibility access").option("--feature-image <url>", "Feature image URL").option("--excerpt <excerpt>", "Custom excerpt").option("--meta-title <title>", "Meta title").option("--meta-description <description>", "Meta description").option("--og-title <title>", "Open Graph title").option("--og-image <url>", "Open Graph image URL").option("--code-injection-head <value>", "Code injection head HTML").action(async (options, command) => {
|
|
11585
11641
|
const global = getGlobalOptions(command);
|
|
11586
11642
|
const parsed = PostCreateInputSchema.safeParse({
|
|
11587
11643
|
title: options.title,
|
|
11644
|
+
slug: options.slug,
|
|
11588
11645
|
status: options.status,
|
|
11589
11646
|
publishAt: options.publishAt,
|
|
11590
11647
|
html: options.html,
|
|
@@ -11626,6 +11683,7 @@ function registerPostCommands(program) {
|
|
|
11626
11683
|
{ ...fromJson },
|
|
11627
11684
|
{
|
|
11628
11685
|
title: parsed.data.title,
|
|
11686
|
+
slug: parsed.data.slug,
|
|
11629
11687
|
status: parsed.data.status ?? (typeof fromJson.status === "string" ? fromJson.status : void 0) ?? "draft",
|
|
11630
11688
|
published_at: parsed.data.publishAt,
|
|
11631
11689
|
html,
|