@tryghost/ghst 0.19.1 → 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 +11 -2
- package/dist/index.js +282 -200
- package/dist/index.js.map +1 -1
- package/package.json +13 -13
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) {
|
|
@@ -4513,142 +4580,6 @@ async function bulkOffers(global, options) {
|
|
|
4513
4580
|
};
|
|
4514
4581
|
}
|
|
4515
4582
|
|
|
4516
|
-
// src/lib/pages.ts
|
|
4517
|
-
function getFirstPage(payload) {
|
|
4518
|
-
const pages = payload.pages;
|
|
4519
|
-
if (!Array.isArray(pages) || pages.length === 0) {
|
|
4520
|
-
throw new GhstError("Page not found", {
|
|
4521
|
-
exitCode: 5 /* NOT_FOUND */,
|
|
4522
|
-
code: "NOT_FOUND"
|
|
4523
|
-
});
|
|
4524
|
-
}
|
|
4525
|
-
return pages[0] ?? {};
|
|
4526
|
-
}
|
|
4527
|
-
async function getClient7(global) {
|
|
4528
|
-
const connection = await resolveConnectionConfig(global);
|
|
4529
|
-
return new GhostClient({
|
|
4530
|
-
url: connection.url,
|
|
4531
|
-
staffToken: connection.staffToken,
|
|
4532
|
-
version: connection.apiVersion
|
|
4533
|
-
});
|
|
4534
|
-
}
|
|
4535
|
-
async function listPages(global, params, allPages) {
|
|
4536
|
-
const client = await getClient7(global);
|
|
4537
|
-
if (!allPages) {
|
|
4538
|
-
return client.pages.browse(params);
|
|
4539
|
-
}
|
|
4540
|
-
const limit = typeof params.limit === "number" ? params.limit : 100;
|
|
4541
|
-
return collectAllPages("pages", (page) => client.pages.browse({ ...params, page, limit }));
|
|
4542
|
-
}
|
|
4543
|
-
async function getPage(global, idOrSlug, options) {
|
|
4544
|
-
const client = await getClient7(global);
|
|
4545
|
-
return client.pages.read(idOrSlug, options);
|
|
4546
|
-
}
|
|
4547
|
-
async function createPage(global, page, source) {
|
|
4548
|
-
const client = await getClient7(global);
|
|
4549
|
-
return client.pages.add(page, source);
|
|
4550
|
-
}
|
|
4551
|
-
async function updatePage(global, options) {
|
|
4552
|
-
const client = await getClient7(global);
|
|
4553
|
-
const lookup = options.slug ?? options.id;
|
|
4554
|
-
if (!lookup) {
|
|
4555
|
-
throw new GhstError("Provide an id or --slug.", {
|
|
4556
|
-
code: "USAGE_ERROR",
|
|
4557
|
-
exitCode: 2 /* USAGE_ERROR */
|
|
4558
|
-
});
|
|
4559
|
-
}
|
|
4560
|
-
const bySlug = Boolean(options.slug);
|
|
4561
|
-
const existingPayload = await client.pages.read(lookup, { bySlug });
|
|
4562
|
-
const existing = getFirstPage(existingPayload);
|
|
4563
|
-
const id = String(existing.id ?? "");
|
|
4564
|
-
const updatedAt = existing.updated_at;
|
|
4565
|
-
if (!id || typeof updatedAt !== "string") {
|
|
4566
|
-
throw new GhstError("Page is missing required id/updated_at for update.", {
|
|
4567
|
-
code: "CONFLICT",
|
|
4568
|
-
exitCode: 6 /* CONFLICT */
|
|
4569
|
-
});
|
|
4570
|
-
}
|
|
4571
|
-
return client.pages.edit(
|
|
4572
|
-
id,
|
|
4573
|
-
{
|
|
4574
|
-
...options.patch,
|
|
4575
|
-
updated_at: updatedAt
|
|
4576
|
-
},
|
|
4577
|
-
options.source
|
|
4578
|
-
);
|
|
4579
|
-
}
|
|
4580
|
-
async function deletePage(global, id) {
|
|
4581
|
-
const client = await getClient7(global);
|
|
4582
|
-
return client.pages.delete(id);
|
|
4583
|
-
}
|
|
4584
|
-
async function copyPage(global, id) {
|
|
4585
|
-
const client = await getClient7(global);
|
|
4586
|
-
return client.pages.copy(id);
|
|
4587
|
-
}
|
|
4588
|
-
function extractPageIds(payload) {
|
|
4589
|
-
const pages = Array.isArray(payload.pages) ? payload.pages : [];
|
|
4590
|
-
return pages.map((entry) => String(entry?.id ?? "").trim()).filter(Boolean);
|
|
4591
|
-
}
|
|
4592
|
-
async function bulkPages(global, options) {
|
|
4593
|
-
const list = await listPages(
|
|
4594
|
-
global,
|
|
4595
|
-
{
|
|
4596
|
-
filter: options.filter,
|
|
4597
|
-
limit: 100
|
|
4598
|
-
},
|
|
4599
|
-
true
|
|
4600
|
-
);
|
|
4601
|
-
const ids = extractPageIds(list);
|
|
4602
|
-
if (ids.length === 0) {
|
|
4603
|
-
return {
|
|
4604
|
-
bulk: {
|
|
4605
|
-
meta: {
|
|
4606
|
-
stats: {
|
|
4607
|
-
successful: 0,
|
|
4608
|
-
unsuccessful: 0
|
|
4609
|
-
}
|
|
4610
|
-
},
|
|
4611
|
-
errors: []
|
|
4612
|
-
}
|
|
4613
|
-
};
|
|
4614
|
-
}
|
|
4615
|
-
let successful = 0;
|
|
4616
|
-
let unsuccessful = 0;
|
|
4617
|
-
const errors = [];
|
|
4618
|
-
for (const id of ids) {
|
|
4619
|
-
try {
|
|
4620
|
-
if (options.delete) {
|
|
4621
|
-
await deletePage(global, id);
|
|
4622
|
-
} else {
|
|
4623
|
-
await updatePage(global, {
|
|
4624
|
-
id,
|
|
4625
|
-
patch: {
|
|
4626
|
-
status: options.status
|
|
4627
|
-
}
|
|
4628
|
-
});
|
|
4629
|
-
}
|
|
4630
|
-
successful += 1;
|
|
4631
|
-
} catch (error) {
|
|
4632
|
-
unsuccessful += 1;
|
|
4633
|
-
errors.push({
|
|
4634
|
-
id,
|
|
4635
|
-
message: error.message
|
|
4636
|
-
});
|
|
4637
|
-
}
|
|
4638
|
-
}
|
|
4639
|
-
return {
|
|
4640
|
-
bulk: {
|
|
4641
|
-
meta: {
|
|
4642
|
-
stats: {
|
|
4643
|
-
successful,
|
|
4644
|
-
unsuccessful
|
|
4645
|
-
}
|
|
4646
|
-
},
|
|
4647
|
-
errors
|
|
4648
|
-
}
|
|
4649
|
-
};
|
|
4650
|
-
}
|
|
4651
|
-
|
|
4652
4583
|
// src/lib/posts.ts
|
|
4653
4584
|
function buildEmailParams(options = {}) {
|
|
4654
4585
|
const params = {};
|
|
@@ -4697,9 +4628,25 @@ async function getPost(global, idOrSlug, options) {
|
|
|
4697
4628
|
const client = await getClient8(global);
|
|
4698
4629
|
return client.posts.read(idOrSlug, options);
|
|
4699
4630
|
}
|
|
4631
|
+
async function withDefaultAuthor(client, resource) {
|
|
4632
|
+
if (resource.authors !== void 0) {
|
|
4633
|
+
return resource;
|
|
4634
|
+
}
|
|
4635
|
+
try {
|
|
4636
|
+
const payload = await client.users.me();
|
|
4637
|
+
const users = Array.isArray(payload.users) ? payload.users : [];
|
|
4638
|
+
const id = users[0]?.id;
|
|
4639
|
+
return typeof id === "string" ? { ...resource, authors: [{ id }] } : resource;
|
|
4640
|
+
} catch (error) {
|
|
4641
|
+
if (error instanceof GhostApiError && (error.status === 403 || error.status === 404)) {
|
|
4642
|
+
return resource;
|
|
4643
|
+
}
|
|
4644
|
+
throw error;
|
|
4645
|
+
}
|
|
4646
|
+
}
|
|
4700
4647
|
async function createPost(global, post, source) {
|
|
4701
4648
|
const client = await getClient8(global);
|
|
4702
|
-
return client.posts.add(post, source);
|
|
4649
|
+
return client.posts.add(await withDefaultAuthor(client, post), source);
|
|
4703
4650
|
}
|
|
4704
4651
|
async function updatePost(global, options) {
|
|
4705
4652
|
const client = await getClient8(global);
|
|
@@ -4856,7 +4803,17 @@ async function bulkPosts(global, options) {
|
|
|
4856
4803
|
};
|
|
4857
4804
|
}
|
|
4858
4805
|
|
|
4859
|
-
// src/lib/
|
|
4806
|
+
// src/lib/pages.ts
|
|
4807
|
+
function getFirstPage(payload) {
|
|
4808
|
+
const pages = payload.pages;
|
|
4809
|
+
if (!Array.isArray(pages) || pages.length === 0) {
|
|
4810
|
+
throw new GhstError("Page not found", {
|
|
4811
|
+
exitCode: 5 /* NOT_FOUND */,
|
|
4812
|
+
code: "NOT_FOUND"
|
|
4813
|
+
});
|
|
4814
|
+
}
|
|
4815
|
+
return pages[0] ?? {};
|
|
4816
|
+
}
|
|
4860
4817
|
async function getClient9(global) {
|
|
4861
4818
|
const connection = await resolveConnectionConfig(global);
|
|
4862
4819
|
return new GhostClient({
|
|
@@ -4865,8 +4822,134 @@ async function getClient9(global) {
|
|
|
4865
4822
|
version: connection.apiVersion
|
|
4866
4823
|
});
|
|
4867
4824
|
}
|
|
4868
|
-
async function
|
|
4825
|
+
async function listPages(global, params, allPages) {
|
|
4826
|
+
const client = await getClient9(global);
|
|
4827
|
+
if (!allPages) {
|
|
4828
|
+
return client.pages.browse(params);
|
|
4829
|
+
}
|
|
4830
|
+
const limit = typeof params.limit === "number" ? params.limit : 100;
|
|
4831
|
+
return collectAllPages("pages", (page) => client.pages.browse({ ...params, page, limit }));
|
|
4832
|
+
}
|
|
4833
|
+
async function getPage(global, idOrSlug, options) {
|
|
4834
|
+
const client = await getClient9(global);
|
|
4835
|
+
return client.pages.read(idOrSlug, options);
|
|
4836
|
+
}
|
|
4837
|
+
async function createPage(global, page, source) {
|
|
4838
|
+
const client = await getClient9(global);
|
|
4839
|
+
return client.pages.add(await withDefaultAuthor(client, page), source);
|
|
4840
|
+
}
|
|
4841
|
+
async function updatePage(global, options) {
|
|
4842
|
+
const client = await getClient9(global);
|
|
4843
|
+
const lookup = options.slug ?? options.id;
|
|
4844
|
+
if (!lookup) {
|
|
4845
|
+
throw new GhstError("Provide an id or --slug.", {
|
|
4846
|
+
code: "USAGE_ERROR",
|
|
4847
|
+
exitCode: 2 /* USAGE_ERROR */
|
|
4848
|
+
});
|
|
4849
|
+
}
|
|
4850
|
+
const bySlug = Boolean(options.slug);
|
|
4851
|
+
const existingPayload = await client.pages.read(lookup, { bySlug });
|
|
4852
|
+
const existing = getFirstPage(existingPayload);
|
|
4853
|
+
const id = String(existing.id ?? "");
|
|
4854
|
+
const updatedAt = existing.updated_at;
|
|
4855
|
+
if (!id || typeof updatedAt !== "string") {
|
|
4856
|
+
throw new GhstError("Page is missing required id/updated_at for update.", {
|
|
4857
|
+
code: "CONFLICT",
|
|
4858
|
+
exitCode: 6 /* CONFLICT */
|
|
4859
|
+
});
|
|
4860
|
+
}
|
|
4861
|
+
return client.pages.edit(
|
|
4862
|
+
id,
|
|
4863
|
+
{
|
|
4864
|
+
...options.patch,
|
|
4865
|
+
updated_at: updatedAt
|
|
4866
|
+
},
|
|
4867
|
+
options.source
|
|
4868
|
+
);
|
|
4869
|
+
}
|
|
4870
|
+
async function deletePage(global, id) {
|
|
4869
4871
|
const client = await getClient9(global);
|
|
4872
|
+
return client.pages.delete(id);
|
|
4873
|
+
}
|
|
4874
|
+
async function copyPage(global, id) {
|
|
4875
|
+
const client = await getClient9(global);
|
|
4876
|
+
return client.pages.copy(id);
|
|
4877
|
+
}
|
|
4878
|
+
function extractPageIds(payload) {
|
|
4879
|
+
const pages = Array.isArray(payload.pages) ? payload.pages : [];
|
|
4880
|
+
return pages.map((entry) => String(entry?.id ?? "").trim()).filter(Boolean);
|
|
4881
|
+
}
|
|
4882
|
+
async function bulkPages(global, options) {
|
|
4883
|
+
const list = await listPages(
|
|
4884
|
+
global,
|
|
4885
|
+
{
|
|
4886
|
+
filter: options.filter,
|
|
4887
|
+
limit: 100
|
|
4888
|
+
},
|
|
4889
|
+
true
|
|
4890
|
+
);
|
|
4891
|
+
const ids = extractPageIds(list);
|
|
4892
|
+
if (ids.length === 0) {
|
|
4893
|
+
return {
|
|
4894
|
+
bulk: {
|
|
4895
|
+
meta: {
|
|
4896
|
+
stats: {
|
|
4897
|
+
successful: 0,
|
|
4898
|
+
unsuccessful: 0
|
|
4899
|
+
}
|
|
4900
|
+
},
|
|
4901
|
+
errors: []
|
|
4902
|
+
}
|
|
4903
|
+
};
|
|
4904
|
+
}
|
|
4905
|
+
let successful = 0;
|
|
4906
|
+
let unsuccessful = 0;
|
|
4907
|
+
const errors = [];
|
|
4908
|
+
for (const id of ids) {
|
|
4909
|
+
try {
|
|
4910
|
+
if (options.delete) {
|
|
4911
|
+
await deletePage(global, id);
|
|
4912
|
+
} else {
|
|
4913
|
+
await updatePage(global, {
|
|
4914
|
+
id,
|
|
4915
|
+
patch: {
|
|
4916
|
+
status: options.status
|
|
4917
|
+
}
|
|
4918
|
+
});
|
|
4919
|
+
}
|
|
4920
|
+
successful += 1;
|
|
4921
|
+
} catch (error) {
|
|
4922
|
+
unsuccessful += 1;
|
|
4923
|
+
errors.push({
|
|
4924
|
+
id,
|
|
4925
|
+
message: error.message
|
|
4926
|
+
});
|
|
4927
|
+
}
|
|
4928
|
+
}
|
|
4929
|
+
return {
|
|
4930
|
+
bulk: {
|
|
4931
|
+
meta: {
|
|
4932
|
+
stats: {
|
|
4933
|
+
successful,
|
|
4934
|
+
unsuccessful
|
|
4935
|
+
}
|
|
4936
|
+
},
|
|
4937
|
+
errors
|
|
4938
|
+
}
|
|
4939
|
+
};
|
|
4940
|
+
}
|
|
4941
|
+
|
|
4942
|
+
// src/lib/settings.ts
|
|
4943
|
+
async function getClient10(global) {
|
|
4944
|
+
const connection = await resolveConnectionConfig(global);
|
|
4945
|
+
return new GhostClient({
|
|
4946
|
+
url: connection.url,
|
|
4947
|
+
staffToken: connection.staffToken,
|
|
4948
|
+
version: connection.apiVersion
|
|
4949
|
+
});
|
|
4950
|
+
}
|
|
4951
|
+
async function listSettings(global) {
|
|
4952
|
+
const client = await getClient10(global);
|
|
4870
4953
|
return client.settings.browse();
|
|
4871
4954
|
}
|
|
4872
4955
|
async function getSetting(global, key) {
|
|
@@ -4884,7 +4967,7 @@ async function getSetting(global, key) {
|
|
|
4884
4967
|
};
|
|
4885
4968
|
}
|
|
4886
4969
|
async function setSetting(global, key, value) {
|
|
4887
|
-
const client = await
|
|
4970
|
+
const client = await getClient10(global);
|
|
4888
4971
|
try {
|
|
4889
4972
|
return await client.settings.edit([{ key, value }]);
|
|
4890
4973
|
} catch (error) {
|
|
@@ -4903,20 +4986,6 @@ async function setSetting(global, key, value) {
|
|
|
4903
4986
|
}
|
|
4904
4987
|
}
|
|
4905
4988
|
|
|
4906
|
-
// src/lib/site.ts
|
|
4907
|
-
async function getClient10(global) {
|
|
4908
|
-
const connection = await resolveConnectionConfig(global);
|
|
4909
|
-
return new GhostClient({
|
|
4910
|
-
url: connection.url,
|
|
4911
|
-
staffToken: connection.staffToken,
|
|
4912
|
-
version: connection.apiVersion
|
|
4913
|
-
});
|
|
4914
|
-
}
|
|
4915
|
-
async function getSiteInfo(global) {
|
|
4916
|
-
const client = await getClient10(global);
|
|
4917
|
-
return client.siteInfo();
|
|
4918
|
-
}
|
|
4919
|
-
|
|
4920
4989
|
// src/lib/socialweb-client.ts
|
|
4921
4990
|
import fs5 from "fs/promises";
|
|
4922
4991
|
import path4 from "path";
|
|
@@ -5023,15 +5092,12 @@ var SocialWebClient = class {
|
|
|
5023
5092
|
} catch (error) {
|
|
5024
5093
|
const normalized = error;
|
|
5025
5094
|
if (normalized.status === 403) {
|
|
5026
|
-
throw new GhstError(
|
|
5027
|
-
|
|
5028
|
-
|
|
5029
|
-
|
|
5030
|
-
|
|
5031
|
-
|
|
5032
|
-
details: normalized.payload
|
|
5033
|
-
}
|
|
5034
|
-
);
|
|
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
|
+
});
|
|
5035
5101
|
}
|
|
5036
5102
|
throw error;
|
|
5037
5103
|
}
|
|
@@ -5108,6 +5174,8 @@ var SocialWebClient = class {
|
|
|
5108
5174
|
}
|
|
5109
5175
|
if (detailObject?.code === "SITE_MISSING") {
|
|
5110
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.";
|
|
5111
5179
|
}
|
|
5112
5180
|
} else {
|
|
5113
5181
|
const text2 = await response.text();
|
|
@@ -7400,10 +7468,14 @@ function registerCoreTools(server, global, enabledGroups) {
|
|
|
7400
7468
|
description: "Create a Ghost post.",
|
|
7401
7469
|
inputSchema: z6.object({
|
|
7402
7470
|
title: z6.string(),
|
|
7471
|
+
slug: z6.string().optional(),
|
|
7403
7472
|
html: z6.string().optional(),
|
|
7404
7473
|
status: z6.enum(["draft", "published", "scheduled"]).optional(),
|
|
7405
7474
|
publish_at: z6.string().datetime().optional(),
|
|
7406
7475
|
tags: z6.array(z6.string()).optional(),
|
|
7476
|
+
authors: z6.array(z6.string()).optional().describe(
|
|
7477
|
+
"Author emails; the first is the primary author. Omit to use the authenticated staff user, which Contributor and Author tokens require."
|
|
7478
|
+
),
|
|
7407
7479
|
visibility: z6.enum(["public", "members", "paid", "tiers"]).optional(),
|
|
7408
7480
|
feature_image: z6.string().url().optional(),
|
|
7409
7481
|
feature_image_alt: z6.string().max(191).optional(),
|
|
@@ -7415,10 +7487,12 @@ function registerCoreTools(server, global, enabledGroups) {
|
|
|
7415
7487
|
global2,
|
|
7416
7488
|
{
|
|
7417
7489
|
title: args.title,
|
|
7490
|
+
slug: args.slug,
|
|
7418
7491
|
html: args.html,
|
|
7419
7492
|
status: args.status,
|
|
7420
7493
|
published_at: args.publish_at,
|
|
7421
7494
|
tags: args.tags,
|
|
7495
|
+
authors: args.authors,
|
|
7422
7496
|
visibility: args.visibility,
|
|
7423
7497
|
feature_image: args.feature_image,
|
|
7424
7498
|
feature_image_alt: args.feature_image_alt,
|
|
@@ -7631,6 +7705,9 @@ function registerCoreTools(server, global, enabledGroups) {
|
|
|
7631
7705
|
status: z6.enum(["draft", "published", "scheduled"]).optional(),
|
|
7632
7706
|
publish_at: z6.string().datetime().optional(),
|
|
7633
7707
|
tags: z6.array(z6.string()).optional(),
|
|
7708
|
+
authors: z6.array(z6.string()).optional().describe(
|
|
7709
|
+
"Author emails; the first is the primary author. Omit to use the authenticated staff user, which Contributor and Author tokens require."
|
|
7710
|
+
),
|
|
7634
7711
|
visibility: z6.enum(["public", "members", "paid", "tiers"]).optional()
|
|
7635
7712
|
})
|
|
7636
7713
|
},
|
|
@@ -7644,6 +7721,7 @@ function registerCoreTools(server, global, enabledGroups) {
|
|
|
7644
7721
|
status: args.status,
|
|
7645
7722
|
published_at: args.publish_at,
|
|
7646
7723
|
tags: args.tags,
|
|
7724
|
+
authors: args.authors,
|
|
7647
7725
|
visibility: args.visibility
|
|
7648
7726
|
},
|
|
7649
7727
|
args.html ? "html" : void 0
|
|
@@ -10833,8 +10911,9 @@ function registerOfferCommands(program) {
|
|
|
10833
10911
|
import fs10 from "fs/promises";
|
|
10834
10912
|
import MarkdownIt2 from "markdown-it";
|
|
10835
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|$)/;
|
|
10836
10915
|
function renderMarkdown(markdown) {
|
|
10837
|
-
return markdownRenderer2.render(markdown);
|
|
10916
|
+
return markdownRenderer2.render(markdown.replace(frontMatterPattern, ""));
|
|
10838
10917
|
}
|
|
10839
10918
|
async function readOptionalFile(filePath) {
|
|
10840
10919
|
if (!filePath) {
|
|
@@ -11329,6 +11408,7 @@ var PostGetInputSchema = z12.object({
|
|
|
11329
11408
|
var PostCreateInputSchema = withSingleContentSource2(
|
|
11330
11409
|
z12.object({
|
|
11331
11410
|
title: z12.string().min(1).optional(),
|
|
11411
|
+
slug: z12.string().min(1).optional(),
|
|
11332
11412
|
status: StatusSchema2.optional(),
|
|
11333
11413
|
publishAt: z12.string().datetime({ offset: true }).optional(),
|
|
11334
11414
|
html: z12.string().optional(),
|
|
@@ -11557,10 +11637,11 @@ function registerPostCommands(program) {
|
|
|
11557
11637
|
}
|
|
11558
11638
|
printPostHuman(payload);
|
|
11559
11639
|
});
|
|
11560
|
-
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) => {
|
|
11561
11641
|
const global = getGlobalOptions(command);
|
|
11562
11642
|
const parsed = PostCreateInputSchema.safeParse({
|
|
11563
11643
|
title: options.title,
|
|
11644
|
+
slug: options.slug,
|
|
11564
11645
|
status: options.status,
|
|
11565
11646
|
publishAt: options.publishAt,
|
|
11566
11647
|
html: options.html,
|
|
@@ -11602,6 +11683,7 @@ function registerPostCommands(program) {
|
|
|
11602
11683
|
{ ...fromJson },
|
|
11603
11684
|
{
|
|
11604
11685
|
title: parsed.data.title,
|
|
11686
|
+
slug: parsed.data.slug,
|
|
11605
11687
|
status: parsed.data.status ?? (typeof fromJson.status === "string" ? fromJson.status : void 0) ?? "draft",
|
|
11606
11688
|
published_at: parsed.data.publishAt,
|
|
11607
11689
|
html,
|