@p11-core/cli 0.0.6 → 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 +40 -0
- package/docs/index.md +2 -1
- package/docs/sharing.md +7 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3650,6 +3650,10 @@ Environment:
|
|
|
3650
3650
|
await comments(target, normalizeCommentsOptions(options2));
|
|
3651
3651
|
});
|
|
3652
3652
|
allowLegacyParserBehavior(commentsCommand);
|
|
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);
|
|
3653
3657
|
program2.command("history").description("List saved read/edit links.").option("--json", "Print saved history as JSON.").action(async (options2) => {
|
|
3654
3658
|
await history(normalizeHistoryOptions(options2));
|
|
3655
3659
|
});
|
|
@@ -3684,6 +3688,12 @@ function normalizeCommentsOptions(options) {
|
|
|
3684
3688
|
apiUrl: optionString(options.apiUrl, "--api-url requires a URL.")
|
|
3685
3689
|
};
|
|
3686
3690
|
}
|
|
3691
|
+
function normalizeDeleteOptions(options) {
|
|
3692
|
+
return {
|
|
3693
|
+
json: options.json,
|
|
3694
|
+
apiUrl: optionString(options.apiUrl, "--api-url requires a URL.")
|
|
3695
|
+
};
|
|
3696
|
+
}
|
|
3687
3697
|
function normalizeHistoryOptions(options) {
|
|
3688
3698
|
return {
|
|
3689
3699
|
json: options.json
|
|
@@ -3815,6 +3825,30 @@ async function comments(target, options) {
|
|
|
3815
3825
|
printComments(data);
|
|
3816
3826
|
}
|
|
3817
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
|
+
}
|
|
3818
3852
|
async function appendPublishHistory(data, metadata = {}, filePath = historyFilePath()) {
|
|
3819
3853
|
const entry = publishHistoryEntry(data, metadata);
|
|
3820
3854
|
if (!entry.readUrl && !entry.editUrl) return;
|
|
@@ -4322,6 +4356,11 @@ function commentsApiUrlForTarget(value, options = {}) {
|
|
|
4322
4356
|
if (version !== void 0) url.searchParams.set("v", String(version));
|
|
4323
4357
|
return url;
|
|
4324
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
|
+
}
|
|
4325
4364
|
function parseAccessTarget(value, allowedKinds, expected, options = {}) {
|
|
4326
4365
|
const trimmed = value.trim();
|
|
4327
4366
|
if (!trimmed) throw new Error(`Missing ${expected}.`);
|
|
@@ -4435,6 +4474,7 @@ export {
|
|
|
4435
4474
|
commentsApiUrlForTarget,
|
|
4436
4475
|
commentsExportJson,
|
|
4437
4476
|
createCliProgram,
|
|
4477
|
+
deleteApiUrlForTarget,
|
|
4438
4478
|
isNewerVersion,
|
|
4439
4479
|
parseCommentsTarget,
|
|
4440
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.
|