@p11-core/cli 0.0.5 → 0.0.7

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/dist/index.js CHANGED
@@ -3628,9 +3628,13 @@ async function main() {
3628
3628
  if (!isKnownTopLevelCommand(program2, command)) throw new Error(`Unknown command: ${command}`);
3629
3629
  await program2.parseAsync(process.argv);
3630
3630
  }
3631
- function createCliProgram() {
3631
+ function createCliProgram(options = {}) {
3632
3632
  const program2 = new Command();
3633
+ const warnBeforeAction = options.warnIfUpdateAvailable ?? warnIfUpdateAvailable;
3633
3634
  program2.name("p11").description("Share and inspect p11 document pages.");
3635
+ program2.hook("preAction", async () => {
3636
+ await warnBeforeAction();
3637
+ });
3634
3638
  program2.addHelpText(
3635
3639
  "after",
3636
3640
  `
@@ -3638,25 +3642,27 @@ function createCliProgram() {
3638
3642
  Environment:
3639
3643
  P11_API_URL Defaults to ${builtDefaultApiUrl}`
3640
3644
  );
3641
- const shareCommand = program2.command("share").description("Share a review link for a page.").argument("[page.tsx]").option("--json", "Print the API response as JSON.").option("--edit-url [url]", "Share a new version using an edit URL or edit id.").option("--api-url [url]", "Override the p11 API URL.").action(async (input, options) => {
3642
- await warnIfUpdateAvailable();
3643
- await publish(input, normalizePublishOptions(options));
3645
+ const shareCommand = program2.command("share").description("Share a review link for a page.").argument("[page.tsx]").option("--json", "Print the API response as JSON.").option("--edit-url [url]", "Share a new version using an edit URL or edit id.").option("--api-url [url]", "Override the p11 API URL.").action(async (input, options2) => {
3646
+ await publish(input, normalizePublishOptions(options2));
3644
3647
  });
3645
3648
  allowLegacyParserBehavior(shareCommand);
3646
- const commentsCommand = program2.command("comments").description("Fetch exported comments for a read/edit URL or id.").argument("[readUrl|editUrl|readId|editId]").option("--json", "Print comments as JSON.").option("--output [file]", "Write comments JSON to a file.").option("--version [n]", "Fetch comments for a specific page version.").option("--api-url [url]", "Override the p11 API URL.").action(async (target, options) => {
3647
- await warnIfUpdateAvailable();
3648
- await comments(target, normalizeCommentsOptions(options));
3649
+ const commentsCommand = program2.command("comments").description("Fetch exported comments for a read/edit URL or id.").argument("[readUrl|editUrl|readId|editId]").option("--json", "Print comments as JSON.").option("--output [file]", "Write comments JSON to a file.").option("--version [n]", "Fetch comments for a specific page version.").option("--api-url [url]", "Override the p11 API URL.").action(async (target, options2) => {
3650
+ await comments(target, normalizeCommentsOptions(options2));
3649
3651
  });
3650
3652
  allowLegacyParserBehavior(commentsCommand);
3651
- program2.command("history").description("List saved read/edit links.").option("--json", "Print saved history as JSON.").action(async (options) => {
3652
- await history(normalizeHistoryOptions(options));
3653
+ const deleteCommand = program2.command("delete").description("Delete a document and all of its versions and comments.").argument("[editUrl|editId]").option("--json", "Print the API response as JSON.").option("--api-url [url]", "Override the p11 API URL.").action(async (target, options2) => {
3654
+ await deleteDocument(target, normalizeDeleteOptions(options2));
3655
+ });
3656
+ allowLegacyParserBehavior(deleteCommand);
3657
+ program2.command("history").description("List saved read/edit links.").option("--json", "Print saved history as JSON.").action(async (options2) => {
3658
+ await history(normalizeHistoryOptions(options2));
3653
3659
  });
3654
3660
  const docsCommand = program2.command("docs").description("Print p11 authoring docs.").argument("[topic]", "Docs topic: components or sharing.").action(async (topic) => {
3655
3661
  await docs(topic);
3656
3662
  });
3657
3663
  allowLegacyParserBehavior(docsCommand);
3658
- const exampleCommand = program2.command("example").description("Print or write a p11 example document.").argument("[name]", "Example name: all-components.").option("--output [file]", "Write the example to a file.").action(async (name, options) => {
3659
- await example(name, normalizeExampleOptions(options));
3664
+ const exampleCommand = program2.command("example").description("Print or write a p11 example document.").argument("[name]", "Example name: all-components.").option("--output [file]", "Write the example to a file.").action(async (name, options2) => {
3665
+ await example(name, normalizeExampleOptions(options2));
3660
3666
  });
3661
3667
  allowLegacyParserBehavior(exampleCommand);
3662
3668
  return program2;
@@ -3682,6 +3688,12 @@ function normalizeCommentsOptions(options) {
3682
3688
  apiUrl: optionString(options.apiUrl, "--api-url requires a URL.")
3683
3689
  };
3684
3690
  }
3691
+ function normalizeDeleteOptions(options) {
3692
+ return {
3693
+ json: options.json,
3694
+ apiUrl: optionString(options.apiUrl, "--api-url requires a URL.")
3695
+ };
3696
+ }
3685
3697
  function normalizeHistoryOptions(options) {
3686
3698
  return {
3687
3699
  json: options.json
@@ -3813,6 +3825,30 @@ async function comments(target, options) {
3813
3825
  printComments(data);
3814
3826
  }
3815
3827
  }
3828
+ async function deleteDocument(target, options) {
3829
+ if (!target) {
3830
+ throw new Error("Usage: p11 delete <editUrl|editId> [--json] [--api-url URL]");
3831
+ }
3832
+ const url = deleteApiUrlForTarget(target, {
3833
+ apiUrl: options.apiUrl
3834
+ });
3835
+ const response = await fetch(url, {
3836
+ method: "DELETE"
3837
+ });
3838
+ const text = await response.text();
3839
+ if (!response.ok) {
3840
+ throw new Error(`Delete failed (${response.status}): ${responseErrorMessage(text)}`);
3841
+ }
3842
+ const data = JSON.parse(text);
3843
+ if (options.json) {
3844
+ console.log(JSON.stringify(data, null, 2));
3845
+ return;
3846
+ }
3847
+ console.log(`Deleted ${data.docId ?? "document"}`);
3848
+ if (data.readId) console.log(`readId: ${data.readId}`);
3849
+ if (data.editId) console.log(`editId: ${data.editId}`);
3850
+ if (data.deletedAt) console.log(`deletedAt: ${data.deletedAt}`);
3851
+ }
3816
3852
  async function appendPublishHistory(data, metadata = {}, filePath = historyFilePath()) {
3817
3853
  const entry = publishHistoryEntry(data, metadata);
3818
3854
  if (!entry.readUrl && !entry.editUrl) return;
@@ -4320,6 +4356,11 @@ function commentsApiUrlForTarget(value, options = {}) {
4320
4356
  if (version !== void 0) url.searchParams.set("v", String(version));
4321
4357
  return url;
4322
4358
  }
4359
+ function deleteApiUrlForTarget(value, options = {}) {
4360
+ const target = parseEditTarget(value);
4361
+ const apiUrl = normalizeApiUrl(String(options.apiUrl ?? target.apiUrl ?? defaultApiUrl));
4362
+ return new URL(`/api/edit/${encodeURIComponent(target.editId)}`, apiUrl);
4363
+ }
4323
4364
  function parseAccessTarget(value, allowedKinds, expected, options = {}) {
4324
4365
  const trimmed = value.trim();
4325
4366
  if (!trimmed) throw new Error(`Missing ${expected}.`);
@@ -4432,6 +4473,8 @@ export {
4432
4473
  buildPageModule,
4433
4474
  commentsApiUrlForTarget,
4434
4475
  commentsExportJson,
4476
+ createCliProgram,
4477
+ deleteApiUrlForTarget,
4435
4478
  isNewerVersion,
4436
4479
  parseCommentsTarget,
4437
4480
  parseEditId,
package/docs/index.md CHANGED
@@ -9,6 +9,7 @@ p11 share <page.tsx>
9
9
  p11 share <page.tsx> --edit-url <editUrl>
10
10
  p11 history
11
11
  p11 comments <readUrl|editUrl|readId|editId>
12
+ p11 delete <editUrl|editId>
12
13
  ```
13
14
 
14
15
  Add `--json` when scripting or when exact structured fields are needed.
@@ -28,4 +29,4 @@ p11 example all-components
28
29
  p11 example all-components --output ./all-components.tsx
29
30
  ```
30
31
 
31
- Use `p11 share --help`, `p11 comments --help`, and `p11 history --help` for command-specific flags.
32
+ Use `p11 share --help`, `p11 comments --help`, `p11 delete --help`, and `p11 history --help` for command-specific flags.
package/docs/sharing.md CHANGED
@@ -26,8 +26,14 @@ p11 comments <readUrl|editUrl|readId|editId> --version 1
26
26
  p11 comments <readUrl|editUrl|readId|editId> --output comments.json
27
27
  ```
28
28
 
29
+ Delete a shared document and all of its versions, comments, and replies:
30
+
31
+ ```bash
32
+ p11 delete <editUrl|editId>
33
+ ```
34
+
29
35
  Add `--json` when scripting or when exact structured fields are needed.
30
36
 
31
37
  `P11_API_URL` overrides the default API URL. `--api-url <url>` can override it per command.
32
38
 
33
- Edit URLs are bearer credentials for updating a document. Keep them private.
39
+ Edit URLs are bearer credentials for updating or deleting a document. Keep them private.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@p11-core/cli",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "license": "UNLICENSED",
5
5
  "type": "module",
6
6
  "bin": {