@p11-core/cli 0.0.6 → 0.0.8

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
@@ -3469,7 +3469,7 @@ var require_commander = __commonJS({
3469
3469
  import { realpathSync } from "fs";
3470
3470
  import { chmod, mkdir, mkdtemp, readFile, readdir, rename, rm, stat, writeFile } from "fs/promises";
3471
3471
  import { createRequire } from "module";
3472
- import { homedir } from "os";
3472
+ import { homedir, tmpdir } from "os";
3473
3473
  import path from "path";
3474
3474
  import { fileURLToPath } from "url";
3475
3475
  import process from "process";
@@ -3640,9 +3640,10 @@ function createCliProgram(options = {}) {
3640
3640
  `
3641
3641
 
3642
3642
  Environment:
3643
- P11_API_URL Defaults to ${builtDefaultApiUrl}`
3643
+ P11_API_URL Defaults to ${builtDefaultApiUrl}
3644
+ P11_BUILD_DIR Directory for temporary share build files. Defaults to the OS temp directory.`
3644
3645
  );
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
+ 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.").option("--build-dir [dir]", "Directory for temporary build files.").action(async (input, options2) => {
3646
3647
  await publish(input, normalizePublishOptions(options2));
3647
3648
  });
3648
3649
  allowLegacyParserBehavior(shareCommand);
@@ -3650,6 +3651,10 @@ Environment:
3650
3651
  await comments(target, normalizeCommentsOptions(options2));
3651
3652
  });
3652
3653
  allowLegacyParserBehavior(commentsCommand);
3654
+ 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) => {
3655
+ await deleteDocument(target, normalizeDeleteOptions(options2));
3656
+ });
3657
+ allowLegacyParserBehavior(deleteCommand);
3653
3658
  program2.command("history").description("List saved read/edit links.").option("--json", "Print saved history as JSON.").action(async (options2) => {
3654
3659
  await history(normalizeHistoryOptions(options2));
3655
3660
  });
@@ -3673,7 +3678,8 @@ function normalizePublishOptions(options) {
3673
3678
  return {
3674
3679
  json: options.json,
3675
3680
  editUrl: optionString(options.editUrl, "--edit-url requires a URL or edit id."),
3676
- apiUrl: optionString(options.apiUrl, "--api-url requires a URL.")
3681
+ apiUrl: optionString(options.apiUrl, "--api-url requires a URL."),
3682
+ buildDir: optionString(options.buildDir, "--build-dir requires a directory path.")
3677
3683
  };
3678
3684
  }
3679
3685
  function normalizeCommentsOptions(options) {
@@ -3684,6 +3690,12 @@ function normalizeCommentsOptions(options) {
3684
3690
  apiUrl: optionString(options.apiUrl, "--api-url requires a URL.")
3685
3691
  };
3686
3692
  }
3693
+ function normalizeDeleteOptions(options) {
3694
+ return {
3695
+ json: options.json,
3696
+ apiUrl: optionString(options.apiUrl, "--api-url requires a URL.")
3697
+ };
3698
+ }
3687
3699
  function normalizeHistoryOptions(options) {
3688
3700
  return {
3689
3701
  json: options.json
@@ -3709,10 +3721,12 @@ async function publish(input, options) {
3709
3721
  if (!/\.[cm]?[tj]sx?$/.test(resolvedInput)) {
3710
3722
  throw new Error("File input must be a .tsx, .jsx, .ts, or .js page file.");
3711
3723
  }
3712
- const cleanupDir = await mkdtemp(path.join(process.cwd(), ".p11-build-"));
3724
+ const buildParentDir = resolveBuildParentDir(options.buildDir);
3725
+ await mkdir(buildParentDir, { recursive: true });
3726
+ const cleanupDir = await mkdtemp(path.join(buildParentDir, "p11-build-"));
3713
3727
  const distDir = path.join(cleanupDir, "dist");
3714
- await buildPageModule(resolvedInput, distDir);
3715
3728
  try {
3729
+ await buildPageModule(resolvedInput, distDir);
3716
3730
  await ensureIndexHtml(distDir);
3717
3731
  const zipBytes = await zipDirectory(distDir);
3718
3732
  const editUrl = options.editUrl ?? "";
@@ -3815,6 +3829,30 @@ async function comments(target, options) {
3815
3829
  printComments(data);
3816
3830
  }
3817
3831
  }
3832
+ async function deleteDocument(target, options) {
3833
+ if (!target) {
3834
+ throw new Error("Usage: p11 delete <editUrl|editId> [--json] [--api-url URL]");
3835
+ }
3836
+ const url = deleteApiUrlForTarget(target, {
3837
+ apiUrl: options.apiUrl
3838
+ });
3839
+ const response = await fetch(url, {
3840
+ method: "DELETE"
3841
+ });
3842
+ const text = await response.text();
3843
+ if (!response.ok) {
3844
+ throw new Error(`Delete failed (${response.status}): ${responseErrorMessage(text)}`);
3845
+ }
3846
+ const data = JSON.parse(text);
3847
+ if (options.json) {
3848
+ console.log(JSON.stringify(data, null, 2));
3849
+ return;
3850
+ }
3851
+ console.log(`Deleted ${data.docId ?? "document"}`);
3852
+ if (data.readId) console.log(`readId: ${data.readId}`);
3853
+ if (data.editId) console.log(`editId: ${data.editId}`);
3854
+ if (data.deletedAt) console.log(`deletedAt: ${data.deletedAt}`);
3855
+ }
3818
3856
  async function appendPublishHistory(data, metadata = {}, filePath = historyFilePath()) {
3819
3857
  const entry = publishHistoryEntry(data, metadata);
3820
3858
  if (!entry.readUrl && !entry.editUrl) return;
@@ -4073,34 +4111,48 @@ async function buildPageModule(inputFile, outDir) {
4073
4111
  "</html>"
4074
4112
  ].join("\n")
4075
4113
  );
4076
- await build({
4077
- root: tempDir,
4078
- base: "./",
4079
- configFile: false,
4080
- logLevel: "warn",
4081
- plugins: [react(), tailwindcss()],
4082
- resolve: {
4083
- alias: {
4084
- "@p11-core/components/styles.css": componentStyles,
4085
- "@p11-core/components": componentEntry,
4086
- "@recogito/text-annotator/text-annotator.css": textAnnotatorStyles,
4087
- "@recogito/text-annotator": textAnnotatorEntry,
4088
- "react/jsx-runtime": nodeRequire.resolve("react/jsx-runtime"),
4089
- "react/jsx-dev-runtime": nodeRequire.resolve("react/jsx-dev-runtime"),
4090
- "react-dom/client": nodeRequire.resolve("react-dom/client"),
4091
- "react-dom": nodeRequire.resolve("react-dom"),
4092
- react: nodeRequire.resolve("react")
4114
+ const previousCwd = process.cwd();
4115
+ try {
4116
+ process.chdir(tempDir);
4117
+ await build({
4118
+ root: ".",
4119
+ base: "./",
4120
+ configFile: false,
4121
+ logLevel: "warn",
4122
+ plugins: [react(), tailwindcss()],
4123
+ resolve: {
4124
+ alias: {
4125
+ "@p11-core/components/styles.css": componentStyles,
4126
+ "@p11-core/components": componentEntry,
4127
+ "@recogito/text-annotator/text-annotator.css": textAnnotatorStyles,
4128
+ "@recogito/text-annotator": textAnnotatorEntry,
4129
+ "react/jsx-runtime": nodeRequire.resolve("react/jsx-runtime"),
4130
+ "react/jsx-dev-runtime": nodeRequire.resolve("react/jsx-dev-runtime"),
4131
+ "react-dom/client": nodeRequire.resolve("react-dom/client"),
4132
+ "react-dom": nodeRequire.resolve("react-dom"),
4133
+ react: nodeRequire.resolve("react")
4134
+ },
4135
+ dedupe: ["react", "react-dom"]
4093
4136
  },
4094
- dedupe: ["react", "react-dom"]
4095
- },
4096
- build: {
4097
- outDir: path.relative(tempDir, outDir),
4098
- emptyOutDir: true,
4099
- assetsDir: "assets"
4100
- }
4101
- });
4137
+ build: {
4138
+ outDir: path.relative(tempDir, outDir),
4139
+ emptyOutDir: true,
4140
+ assetsDir: "assets",
4141
+ rollupOptions: {
4142
+ input: {
4143
+ index: "index.html"
4144
+ }
4145
+ }
4146
+ }
4147
+ });
4148
+ } finally {
4149
+ process.chdir(previousCwd);
4150
+ }
4102
4151
  await writeFile(path.join(outDir, P11_MANIFEST_FILE), JSON.stringify({ runtimeVersion: P11_RUNTIME_VERSION }, null, 2));
4103
4152
  }
4153
+ function resolveBuildParentDir(buildDir) {
4154
+ return path.resolve(buildDir || process.env.P11_BUILD_DIR || tmpdir());
4155
+ }
4104
4156
  function validatePageSource(code, inputFile = "page.tsx") {
4105
4157
  validatePageAst(parsePageSource(code), inputFile);
4106
4158
  }
@@ -4322,6 +4374,11 @@ function commentsApiUrlForTarget(value, options = {}) {
4322
4374
  if (version !== void 0) url.searchParams.set("v", String(version));
4323
4375
  return url;
4324
4376
  }
4377
+ function deleteApiUrlForTarget(value, options = {}) {
4378
+ const target = parseEditTarget(value);
4379
+ const apiUrl = normalizeApiUrl(String(options.apiUrl ?? target.apiUrl ?? defaultApiUrl));
4380
+ return new URL(`/api/edit/${encodeURIComponent(target.editId)}`, apiUrl);
4381
+ }
4325
4382
  function parseAccessTarget(value, allowedKinds, expected, options = {}) {
4326
4383
  const trimmed = value.trim();
4327
4384
  if (!trimmed) throw new Error(`Missing ${expected}.`);
@@ -4435,10 +4492,12 @@ export {
4435
4492
  commentsApiUrlForTarget,
4436
4493
  commentsExportJson,
4437
4494
  createCliProgram,
4495
+ deleteApiUrlForTarget,
4438
4496
  isNewerVersion,
4439
4497
  parseCommentsTarget,
4440
4498
  parseEditId,
4441
4499
  parseReadId,
4442
4500
  readHistoryEntries,
4501
+ resolveBuildParentDir,
4443
4502
  validatePageSource
4444
4503
  };
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,15 @@ 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.
38
+ Temporary share builds are created under the OS temp directory by default. Use `P11_BUILD_DIR` or `--build-dir <dir>` only when you need to inspect or redirect the transient build workspace.
32
39
 
33
- Edit URLs are bearer credentials for updating a document. Keep them private.
40
+ 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.6",
3
+ "version": "0.0.8",
4
4
  "license": "UNLICENSED",
5
5
  "type": "module",
6
6
  "bin": {