@tryghost/ghst 0.19.1 → 0.20.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 CHANGED
@@ -358,6 +358,7 @@ Notes:
358
358
  - Exposed MCP tools include `ghst/toolGroup` and `ghst/toolGroupTitle` metadata for clients that render grouped tools.
359
359
  - MCP tools also carry standard `readOnlyHint`/`destructiveHint` annotations so clients like Claude Desktop group them into read-only and write/delete buckets automatically.
360
360
  - MCP tools accept an optional `site` argument to target a configured site alias per call. When omitted, `ghst` uses the normal site resolution order.
361
+ - `ghost_post_create` and `ghost_page_create` accept an optional `authors` list of author emails. When it is omitted, the post or page is authored by the token's own user, which lets Contributor and Author tokens create drafts; those tokens should omit `authors`, because Ghost checks the author's user id, not the email.
361
362
  - Use `ghost_site_list` to list configured site aliases without exposing stored credentials.
362
363
 
363
364
  Example multi-instance workflow:
package/dist/index.js CHANGED
@@ -4513,142 +4513,6 @@ async function bulkOffers(global, options) {
4513
4513
  };
4514
4514
  }
4515
4515
 
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
4516
  // src/lib/posts.ts
4653
4517
  function buildEmailParams(options = {}) {
4654
4518
  const params = {};
@@ -4673,7 +4537,7 @@ function getFirstPost(payload) {
4673
4537
  }
4674
4538
  return posts[0] ?? {};
4675
4539
  }
4676
- async function getClient8(global) {
4540
+ async function getClient7(global) {
4677
4541
  const connection = await resolveConnectionConfig(global);
4678
4542
  return new GhostClient({
4679
4543
  url: connection.url,
@@ -4682,7 +4546,7 @@ async function getClient8(global) {
4682
4546
  });
4683
4547
  }
4684
4548
  async function listPosts(global, params, allPages) {
4685
- const client = await getClient8(global);
4549
+ const client = await getClient7(global);
4686
4550
  if (!allPages) {
4687
4551
  return client.posts.browse(params);
4688
4552
  }
@@ -4694,15 +4558,31 @@ function looksLikeGhostId(value) {
4694
4558
  return GHOST_OBJECT_ID.test(value);
4695
4559
  }
4696
4560
  async function getPost(global, idOrSlug, options) {
4697
- const client = await getClient8(global);
4561
+ const client = await getClient7(global);
4698
4562
  return client.posts.read(idOrSlug, options);
4699
4563
  }
4564
+ async function withDefaultAuthor(client, resource) {
4565
+ if (resource.authors !== void 0) {
4566
+ return resource;
4567
+ }
4568
+ try {
4569
+ const payload = await client.users.me();
4570
+ const users = Array.isArray(payload.users) ? payload.users : [];
4571
+ const id = users[0]?.id;
4572
+ return typeof id === "string" ? { ...resource, authors: [{ id }] } : resource;
4573
+ } catch (error) {
4574
+ if (error instanceof GhostApiError && (error.status === 403 || error.status === 404)) {
4575
+ return resource;
4576
+ }
4577
+ throw error;
4578
+ }
4579
+ }
4700
4580
  async function createPost(global, post, source) {
4701
- const client = await getClient8(global);
4702
- return client.posts.add(post, source);
4581
+ const client = await getClient7(global);
4582
+ return client.posts.add(await withDefaultAuthor(client, post), source);
4703
4583
  }
4704
4584
  async function updatePost(global, options) {
4705
- const client = await getClient8(global);
4585
+ const client = await getClient7(global);
4706
4586
  const lookup = options.slug ?? options.id;
4707
4587
  if (!lookup) {
4708
4588
  throw new GhstError("Provide an id or --slug.", {
@@ -4742,7 +4622,7 @@ async function updatePost(global, options) {
4742
4622
  }
4743
4623
  }
4744
4624
  async function deletePost(global, id) {
4745
- const client = await getClient8(global);
4625
+ const client = await getClient7(global);
4746
4626
  return client.posts.delete(id);
4747
4627
  }
4748
4628
  async function publishPost(global, id, options) {
@@ -4772,7 +4652,7 @@ async function unschedulePost(global, id) {
4772
4652
  });
4773
4653
  }
4774
4654
  async function copyPost(global, id) {
4775
- const client = await getClient8(global);
4655
+ const client = await getClient7(global);
4776
4656
  return client.posts.copy(id);
4777
4657
  }
4778
4658
  function extractPostIds(payload) {
@@ -4856,6 +4736,142 @@ async function bulkPosts(global, options) {
4856
4736
  };
4857
4737
  }
4858
4738
 
4739
+ // src/lib/pages.ts
4740
+ function getFirstPage(payload) {
4741
+ const pages = payload.pages;
4742
+ if (!Array.isArray(pages) || pages.length === 0) {
4743
+ throw new GhstError("Page not found", {
4744
+ exitCode: 5 /* NOT_FOUND */,
4745
+ code: "NOT_FOUND"
4746
+ });
4747
+ }
4748
+ return pages[0] ?? {};
4749
+ }
4750
+ async function getClient8(global) {
4751
+ const connection = await resolveConnectionConfig(global);
4752
+ return new GhostClient({
4753
+ url: connection.url,
4754
+ staffToken: connection.staffToken,
4755
+ version: connection.apiVersion
4756
+ });
4757
+ }
4758
+ async function listPages(global, params, allPages) {
4759
+ const client = await getClient8(global);
4760
+ if (!allPages) {
4761
+ return client.pages.browse(params);
4762
+ }
4763
+ const limit = typeof params.limit === "number" ? params.limit : 100;
4764
+ return collectAllPages("pages", (page) => client.pages.browse({ ...params, page, limit }));
4765
+ }
4766
+ async function getPage(global, idOrSlug, options) {
4767
+ const client = await getClient8(global);
4768
+ return client.pages.read(idOrSlug, options);
4769
+ }
4770
+ async function createPage(global, page, source) {
4771
+ const client = await getClient8(global);
4772
+ return client.pages.add(await withDefaultAuthor(client, page), source);
4773
+ }
4774
+ async function updatePage(global, options) {
4775
+ const client = await getClient8(global);
4776
+ const lookup = options.slug ?? options.id;
4777
+ if (!lookup) {
4778
+ throw new GhstError("Provide an id or --slug.", {
4779
+ code: "USAGE_ERROR",
4780
+ exitCode: 2 /* USAGE_ERROR */
4781
+ });
4782
+ }
4783
+ const bySlug = Boolean(options.slug);
4784
+ const existingPayload = await client.pages.read(lookup, { bySlug });
4785
+ const existing = getFirstPage(existingPayload);
4786
+ const id = String(existing.id ?? "");
4787
+ const updatedAt = existing.updated_at;
4788
+ if (!id || typeof updatedAt !== "string") {
4789
+ throw new GhstError("Page is missing required id/updated_at for update.", {
4790
+ code: "CONFLICT",
4791
+ exitCode: 6 /* CONFLICT */
4792
+ });
4793
+ }
4794
+ return client.pages.edit(
4795
+ id,
4796
+ {
4797
+ ...options.patch,
4798
+ updated_at: updatedAt
4799
+ },
4800
+ options.source
4801
+ );
4802
+ }
4803
+ async function deletePage(global, id) {
4804
+ const client = await getClient8(global);
4805
+ return client.pages.delete(id);
4806
+ }
4807
+ async function copyPage(global, id) {
4808
+ const client = await getClient8(global);
4809
+ return client.pages.copy(id);
4810
+ }
4811
+ function extractPageIds(payload) {
4812
+ const pages = Array.isArray(payload.pages) ? payload.pages : [];
4813
+ return pages.map((entry) => String(entry?.id ?? "").trim()).filter(Boolean);
4814
+ }
4815
+ async function bulkPages(global, options) {
4816
+ const list = await listPages(
4817
+ global,
4818
+ {
4819
+ filter: options.filter,
4820
+ limit: 100
4821
+ },
4822
+ true
4823
+ );
4824
+ const ids = extractPageIds(list);
4825
+ if (ids.length === 0) {
4826
+ return {
4827
+ bulk: {
4828
+ meta: {
4829
+ stats: {
4830
+ successful: 0,
4831
+ unsuccessful: 0
4832
+ }
4833
+ },
4834
+ errors: []
4835
+ }
4836
+ };
4837
+ }
4838
+ let successful = 0;
4839
+ let unsuccessful = 0;
4840
+ const errors = [];
4841
+ for (const id of ids) {
4842
+ try {
4843
+ if (options.delete) {
4844
+ await deletePage(global, id);
4845
+ } else {
4846
+ await updatePage(global, {
4847
+ id,
4848
+ patch: {
4849
+ status: options.status
4850
+ }
4851
+ });
4852
+ }
4853
+ successful += 1;
4854
+ } catch (error) {
4855
+ unsuccessful += 1;
4856
+ errors.push({
4857
+ id,
4858
+ message: error.message
4859
+ });
4860
+ }
4861
+ }
4862
+ return {
4863
+ bulk: {
4864
+ meta: {
4865
+ stats: {
4866
+ successful,
4867
+ unsuccessful
4868
+ }
4869
+ },
4870
+ errors
4871
+ }
4872
+ };
4873
+ }
4874
+
4859
4875
  // src/lib/settings.ts
4860
4876
  async function getClient9(global) {
4861
4877
  const connection = await resolveConnectionConfig(global);
@@ -7404,6 +7420,9 @@ function registerCoreTools(server, global, enabledGroups) {
7404
7420
  status: z6.enum(["draft", "published", "scheduled"]).optional(),
7405
7421
  publish_at: z6.string().datetime().optional(),
7406
7422
  tags: z6.array(z6.string()).optional(),
7423
+ authors: z6.array(z6.string()).optional().describe(
7424
+ "Author emails; the first is the primary author. Omit to use the authenticated staff user, which Contributor and Author tokens require."
7425
+ ),
7407
7426
  visibility: z6.enum(["public", "members", "paid", "tiers"]).optional(),
7408
7427
  feature_image: z6.string().url().optional(),
7409
7428
  feature_image_alt: z6.string().max(191).optional(),
@@ -7419,6 +7438,7 @@ function registerCoreTools(server, global, enabledGroups) {
7419
7438
  status: args.status,
7420
7439
  published_at: args.publish_at,
7421
7440
  tags: args.tags,
7441
+ authors: args.authors,
7422
7442
  visibility: args.visibility,
7423
7443
  feature_image: args.feature_image,
7424
7444
  feature_image_alt: args.feature_image_alt,
@@ -7631,6 +7651,9 @@ function registerCoreTools(server, global, enabledGroups) {
7631
7651
  status: z6.enum(["draft", "published", "scheduled"]).optional(),
7632
7652
  publish_at: z6.string().datetime().optional(),
7633
7653
  tags: z6.array(z6.string()).optional(),
7654
+ authors: z6.array(z6.string()).optional().describe(
7655
+ "Author emails; the first is the primary author. Omit to use the authenticated staff user, which Contributor and Author tokens require."
7656
+ ),
7634
7657
  visibility: z6.enum(["public", "members", "paid", "tiers"]).optional()
7635
7658
  })
7636
7659
  },
@@ -7644,6 +7667,7 @@ function registerCoreTools(server, global, enabledGroups) {
7644
7667
  status: args.status,
7645
7668
  published_at: args.publish_at,
7646
7669
  tags: args.tags,
7670
+ authors: args.authors,
7647
7671
  visibility: args.visibility
7648
7672
  },
7649
7673
  args.html ? "html" : void 0