@interop/did-cli 0.6.0 → 0.8.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.
Files changed (57) hide show
  1. package/CHANGELOG.md +64 -1
  2. package/README.md +144 -6
  3. package/dist/commands/did.d.ts.map +1 -1
  4. package/dist/commands/did.js +41 -12
  5. package/dist/commands/did.js.map +1 -1
  6. package/dist/commands/key.d.ts.map +1 -1
  7. package/dist/commands/key.js +46 -8
  8. package/dist/commands/key.js.map +1 -1
  9. package/dist/commands/was/collection.d.ts +121 -0
  10. package/dist/commands/was/collection.d.ts.map +1 -0
  11. package/dist/commands/was/collection.js +316 -0
  12. package/dist/commands/was/collection.js.map +1 -0
  13. package/dist/commands/was/policy.d.ts +50 -0
  14. package/dist/commands/was/policy.d.ts.map +1 -0
  15. package/dist/commands/was/policy.js +133 -0
  16. package/dist/commands/was/policy.js.map +1 -0
  17. package/dist/commands/was/publish.d.ts +67 -0
  18. package/dist/commands/was/publish.d.ts.map +1 -0
  19. package/dist/commands/was/publish.js +151 -0
  20. package/dist/commands/was/publish.js.map +1 -0
  21. package/dist/commands/was/resource.d.ts +148 -0
  22. package/dist/commands/was/resource.d.ts.map +1 -0
  23. package/dist/commands/was/resource.js +402 -0
  24. package/dist/commands/was/resource.js.map +1 -0
  25. package/dist/commands/was/shared.d.ts +156 -0
  26. package/dist/commands/was/shared.d.ts.map +1 -0
  27. package/dist/commands/was/shared.js +237 -0
  28. package/dist/commands/was/shared.js.map +1 -0
  29. package/dist/commands/was/space.d.ts +196 -0
  30. package/dist/commands/was/space.d.ts.map +1 -0
  31. package/dist/commands/was/space.js +516 -0
  32. package/dist/commands/was/space.js.map +1 -0
  33. package/dist/commands/was/tree.d.ts +44 -0
  34. package/dist/commands/was/tree.d.ts.map +1 -0
  35. package/dist/commands/was/tree.js +135 -0
  36. package/dist/commands/was/tree.js.map +1 -0
  37. package/dist/commands/was.d.ts +29 -496
  38. package/dist/commands/was.d.ts.map +1 -1
  39. package/dist/commands/was.js +84 -1473
  40. package/dist/commands/was.js.map +1 -1
  41. package/dist/commands/zcap.d.ts +22 -2
  42. package/dist/commands/zcap.d.ts.map +1 -1
  43. package/dist/commands/zcap.js +6 -20
  44. package/dist/commands/zcap.js.map +1 -1
  45. package/dist/meta.js +1 -1
  46. package/dist/meta.js.map +1 -1
  47. package/dist/was/capability.d.ts +10 -13
  48. package/dist/was/capability.d.ts.map +1 -1
  49. package/dist/was/capability.js +1 -59
  50. package/dist/was/capability.js.map +1 -1
  51. package/dist/zcap/delegate.d.ts +2 -2
  52. package/dist/zcap/delegate.js +2 -2
  53. package/dist/zcap/resolve.d.ts +15 -0
  54. package/dist/zcap/resolve.d.ts.map +1 -0
  55. package/dist/zcap/resolve.js +55 -0
  56. package/dist/zcap/resolve.js.map +1 -0
  57. package/package.json +29 -16
@@ -0,0 +1,133 @@
1
+ /**
2
+ * `was policy` run functions: show, set (from `--type` or a JSON file), and
3
+ * clear the access-control policy of a space, collection, or resource.
4
+ */
5
+ import { readFile } from 'node:fs/promises';
6
+ import { resolveWasTarget } from '../../was/client.js';
7
+ import { handleForTarget, reportError } from './shared.js';
8
+ /**
9
+ * Shows the access-control policy of a space, collection, or resource.
10
+ *
11
+ * @param options {object}
12
+ * @param options.address {string} A space/collection/resource address.
13
+ * @param [options.server] {string} The server base URL.
14
+ * @param [options.did] {string} The signing DID or stored-DID handle.
15
+ * @returns {Promise<number>} The process exit code.
16
+ */
17
+ export async function runPolicyShow(options) {
18
+ try {
19
+ const target = await resolveWasTarget({
20
+ address: options.address,
21
+ server: options.server,
22
+ did: options.did
23
+ });
24
+ const { handle, url } = handleForTarget(target);
25
+ const policy = await handle.getPolicy();
26
+ if (policy === null) {
27
+ console.error(`No policy set (or not visible to you): ${url}`);
28
+ return 1;
29
+ }
30
+ console.log(JSON.stringify(policy, null, 2));
31
+ return 0;
32
+ }
33
+ catch (err) {
34
+ return reportError({ action: 'show the policy', err });
35
+ }
36
+ }
37
+ /**
38
+ * Parses the `policy set` arguments -- `--type <type>` for a simple
39
+ * type-only policy, or a JSON file for richer ones -- into a policy
40
+ * document.
41
+ *
42
+ * @param options {object}
43
+ * @param [options.type] {string}
44
+ * @param [options.file] {string}
45
+ * @returns {Promise<PolicyDocument>}
46
+ */
47
+ async function resolvePolicyInput({ type, file }) {
48
+ if (type && file) {
49
+ throw new Error('Provide either --type or a policy file, not both.');
50
+ }
51
+ if (type) {
52
+ return { type };
53
+ }
54
+ if (!file) {
55
+ throw new Error('Provide --type <type> or a policy JSON file.');
56
+ }
57
+ let parsed;
58
+ try {
59
+ parsed = JSON.parse(await readFile(file, 'utf8'));
60
+ }
61
+ catch (err) {
62
+ throw new Error(`${file} does not contain policy JSON: ` +
63
+ `${err instanceof Error ? err.message : String(err)}`, { cause: err });
64
+ }
65
+ if (parsed === null ||
66
+ typeof parsed !== 'object' ||
67
+ Array.isArray(parsed) ||
68
+ typeof parsed.type !== 'string') {
69
+ throw new Error(`${file} must hold a policy object with a "type" field.`);
70
+ }
71
+ return parsed;
72
+ }
73
+ /**
74
+ * Sets (creates or replaces) the access-control policy of a space,
75
+ * collection, or resource, and prints the policy document that was set.
76
+ *
77
+ * @param options {object}
78
+ * @param options.address {string} A space/collection/resource address.
79
+ * @param [options.file] {string} A policy JSON file.
80
+ * @param [options.type] {string} A simple type-only policy (e.g.
81
+ * PublicCanRead).
82
+ * @param [options.server] {string} The server base URL.
83
+ * @param [options.did] {string} The signing DID or stored-DID handle.
84
+ * @returns {Promise<number>} The process exit code.
85
+ */
86
+ export async function runPolicySet(options) {
87
+ try {
88
+ const policy = await resolvePolicyInput({
89
+ type: options.type,
90
+ file: options.file
91
+ });
92
+ const target = await resolveWasTarget({
93
+ address: options.address,
94
+ server: options.server,
95
+ did: options.did
96
+ });
97
+ const { handle, url } = handleForTarget(target);
98
+ await handle.setPolicy(policy);
99
+ console.error(`Policy set on ${url}`);
100
+ console.log(JSON.stringify(policy, null, 2));
101
+ return 0;
102
+ }
103
+ catch (err) {
104
+ return reportError({ action: 'set the policy', err });
105
+ }
106
+ }
107
+ /**
108
+ * Removes the access-control policy of a space, collection, or resource,
109
+ * reverting it to capability-only access. Idempotent.
110
+ *
111
+ * @param options {object}
112
+ * @param options.address {string} A space/collection/resource address.
113
+ * @param [options.server] {string} The server base URL.
114
+ * @param [options.did] {string} The signing DID or stored-DID handle.
115
+ * @returns {Promise<number>} The process exit code.
116
+ */
117
+ export async function runPolicyClear(options) {
118
+ try {
119
+ const target = await resolveWasTarget({
120
+ address: options.address,
121
+ server: options.server,
122
+ did: options.did
123
+ });
124
+ const { handle, url } = handleForTarget(target);
125
+ await handle.clearPolicy();
126
+ console.error(`Cleared the policy on ${url} (capability-only access).`);
127
+ return 0;
128
+ }
129
+ catch (err) {
130
+ return reportError({ action: 'clear the policy', err });
131
+ }
132
+ }
133
+ //# sourceMappingURL=policy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"policy.js","sourceRoot":"","sources":["../../../src/commands/was/policy.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAE3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAA;AACtD,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAE1D;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,OAInC;IACC,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,gBAAgB,CAAC;YACpC,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,MAAM,EAAE,OAAO,CAAC,MAAM;YACtB,GAAG,EAAE,OAAO,CAAC,GAAG;SACjB,CAAC,CAAA;QACF,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,eAAe,CAAC,MAAM,CAAC,CAAA;QAC/C,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,SAAS,EAAE,CAAA;QACvC,IAAI,MAAM,KAAK,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MAAM;YACtB,GAAG,EAAE,OAAO,CAAC,GAAG;SACjB,CAAC,CAAA;QACF,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,eAAe,CAAC,MAAM,CAAC,CAAA;QAC/C,MAAM,MAAM,CAAC,WAAW,EAAE,CAAA;QAC1B,OAAO,CAAC,KAAK,CAAC,yBAAyB,GAAG,4BAA4B,CAAC,CAAA;QACvE,OAAO,CAAC,CAAA;IACV,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,WAAW,CAAC,EAAE,MAAM,EAAE,kBAAkB,EAAE,GAAG,EAAE,CAAC,CAAA;IACzD,CAAC;AACH,CAAC"}
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Makes a space, collection, or resource world-readable (the
3
+ * `PublicCanRead` policy) and prints its public URL -- the "share via
4
+ * public link" case.
5
+ *
6
+ * @param options {object}
7
+ * @param options.address {string} A space/collection/resource address.
8
+ * @param [options.server] {string} The server base URL.
9
+ * @param [options.did] {string} The signing DID or stored-DID handle.
10
+ * @returns {Promise<number>} The process exit code.
11
+ */
12
+ export declare function runPublish(options: {
13
+ address: string;
14
+ server?: string;
15
+ did?: string;
16
+ }): Promise<number>;
17
+ /**
18
+ * Reverts a published space, collection, or resource to capability-only
19
+ * access (clears its policy). Idempotent.
20
+ *
21
+ * @param options {object}
22
+ * @param options.address {string} A space/collection/resource address.
23
+ * @param [options.server] {string} The server base URL.
24
+ * @param [options.did] {string} The signing DID or stored-DID handle.
25
+ * @returns {Promise<number>} The process exit code.
26
+ */
27
+ export declare function runUnpublish(options: {
28
+ address: string;
29
+ server?: string;
30
+ did?: string;
31
+ }): Promise<number>;
32
+ /**
33
+ * Delegates access to a space, collection, or resource: signs a capability
34
+ * for the `--to` DID with the given actions and expiration, and prints
35
+ * `{ delegatedCapability, encoded }` (the same shape as `zcap delegate`).
36
+ * `--save` stores the capability in the local zcap store
37
+ * (`~/.config/did-cli-wallet/zcaps/`).
38
+ *
39
+ * @param options {object}
40
+ * @param options.address {string} The space/collection/resource address.
41
+ * @param options.to {string} The delegatee DID (or stored-DID handle).
42
+ * @param options.action {string[]} Allowed actions (HTTP verbs; lowercase
43
+ * accepted).
44
+ * @param [options.ttl] {string} Time-to-live for expiration (default 1y).
45
+ * @param [options.expires] {string} Explicit ISO 8601 expiration
46
+ * (overrides --ttl).
47
+ * @param [options.save] {boolean} Save the capability to the zcap store.
48
+ * @param [options.handle] {string} Short tag for the saved zcap.
49
+ * @param [options.description] {string} Longer description for the saved
50
+ * zcap.
51
+ * @param [options.server] {string} The server base URL.
52
+ * @param [options.did] {string} The signing DID or stored-DID handle.
53
+ * @returns {Promise<number>} The process exit code.
54
+ */
55
+ export declare function runGrant(options: {
56
+ address: string;
57
+ to: string;
58
+ action: string[];
59
+ ttl?: string;
60
+ expires?: string;
61
+ save?: boolean;
62
+ handle?: string;
63
+ description?: string;
64
+ server?: string;
65
+ did?: string;
66
+ }): Promise<number>;
67
+ //# sourceMappingURL=publish.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"publish.d.ts","sourceRoot":"","sources":["../../../src/commands/was/publish.ts"],"names":[],"mappings":"AAmCA;;;;;;;;;;GAUG;AACH,wBAAsB,UAAU,CAAC,OAAO,EAAE;IACxC,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,GAAG,CAAC,EAAE,MAAM,CAAA;CACb,GAAG,OAAO,CAAC,MAAM,CAAC,CAelB;AAED;;;;;;;;;GASG;AACH,wBAAsB,YAAY,CAAC,OAAO,EAAE;IAC1C,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,GAAG,CAAC,EAAE,MAAM,CAAA;CACb,GAAG,OAAO,CAAC,MAAM,CAAC,CAclB;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAsB,QAAQ,CAAC,OAAO,EAAE;IACtC,OAAO,EAAE,MAAM,CAAA;IACf,EAAE,EAAE,MAAM,CAAA;IACV,MAAM,EAAE,MAAM,EAAE,CAAA;IAChB,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,GAAG,CAAC,EAAE,MAAM,CAAA;CACb,GAAG,OAAO,CAAC,MAAM,CAAC,CA+ClB"}
@@ -0,0 +1,151 @@
1
+ /**
2
+ * `was publish`/`unpublish` (the world-readable `PublicCanRead` toggle) and
3
+ * `was grant` (delegate a signed capability to another DID) run functions.
4
+ */
5
+ import { resolveDidRef } from '../../meta.js';
6
+ import { saveToCollection } from '../../storage.js';
7
+ import { encodeCapability } from '../../zcap/encoding.js';
8
+ import { expiresFromTtl } from '../../zcap/ttl.js';
9
+ import { resolveWasTarget } from '../../was/client.js';
10
+ import { storageIdFor, writeCreateMeta } from '../zcap.js';
11
+ import { handleForTarget, reportError, wasUrl } from './shared.js';
12
+ /** The capability actions WAS servers match against (HTTP verbs). */
13
+ const WAS_ACTIONS = ['GET', 'PUT', 'POST', 'DELETE'];
14
+ /**
15
+ * Normalizes grant action verbs to their canonical uppercase form,
16
+ * rejecting anything that is not a WAS-supported HTTP verb.
17
+ *
18
+ * @param actions {string[]}
19
+ * @returns {WasAction[]}
20
+ */
21
+ function normalizeActions(actions) {
22
+ return actions.map(action => {
23
+ const verb = action.toUpperCase();
24
+ if (!WAS_ACTIONS.includes(verb)) {
25
+ throw new Error(`Unknown action "${action}" (supported: GET, PUT, POST, DELETE).`);
26
+ }
27
+ return verb;
28
+ });
29
+ }
30
+ /**
31
+ * Makes a space, collection, or resource world-readable (the
32
+ * `PublicCanRead` policy) and prints its public URL -- the "share via
33
+ * public link" case.
34
+ *
35
+ * @param options {object}
36
+ * @param options.address {string} A space/collection/resource address.
37
+ * @param [options.server] {string} The server base URL.
38
+ * @param [options.did] {string} The signing DID or stored-DID handle.
39
+ * @returns {Promise<number>} The process exit code.
40
+ */
41
+ export async function runPublish(options) {
42
+ try {
43
+ const target = await resolveWasTarget({
44
+ address: options.address,
45
+ server: options.server,
46
+ did: options.did
47
+ });
48
+ const { handle, url } = handleForTarget(target);
49
+ await handle.setPublic();
50
+ console.error(`Published (world-readable): ${url}`);
51
+ console.log(url);
52
+ return 0;
53
+ }
54
+ catch (err) {
55
+ return reportError({ action: 'publish the path', err });
56
+ }
57
+ }
58
+ /**
59
+ * Reverts a published space, collection, or resource to capability-only
60
+ * access (clears its policy). Idempotent.
61
+ *
62
+ * @param options {object}
63
+ * @param options.address {string} A space/collection/resource address.
64
+ * @param [options.server] {string} The server base URL.
65
+ * @param [options.did] {string} The signing DID or stored-DID handle.
66
+ * @returns {Promise<number>} The process exit code.
67
+ */
68
+ export async function runUnpublish(options) {
69
+ try {
70
+ const target = await resolveWasTarget({
71
+ address: options.address,
72
+ server: options.server,
73
+ did: options.did
74
+ });
75
+ const { handle, url } = handleForTarget(target);
76
+ await handle.clearPolicy();
77
+ console.error(`Unpublished (capability-only access): ${url}`);
78
+ return 0;
79
+ }
80
+ catch (err) {
81
+ return reportError({ action: 'unpublish the path', err });
82
+ }
83
+ }
84
+ /**
85
+ * Delegates access to a space, collection, or resource: signs a capability
86
+ * for the `--to` DID with the given actions and expiration, and prints
87
+ * `{ delegatedCapability, encoded }` (the same shape as `zcap delegate`).
88
+ * `--save` stores the capability in the local zcap store
89
+ * (`~/.config/did-cli-wallet/zcaps/`).
90
+ *
91
+ * @param options {object}
92
+ * @param options.address {string} The space/collection/resource address.
93
+ * @param options.to {string} The delegatee DID (or stored-DID handle).
94
+ * @param options.action {string[]} Allowed actions (HTTP verbs; lowercase
95
+ * accepted).
96
+ * @param [options.ttl] {string} Time-to-live for expiration (default 1y).
97
+ * @param [options.expires] {string} Explicit ISO 8601 expiration
98
+ * (overrides --ttl).
99
+ * @param [options.save] {boolean} Save the capability to the zcap store.
100
+ * @param [options.handle] {string} Short tag for the saved zcap.
101
+ * @param [options.description] {string} Longer description for the saved
102
+ * zcap.
103
+ * @param [options.server] {string} The server base URL.
104
+ * @param [options.did] {string} The signing DID or stored-DID handle.
105
+ * @returns {Promise<number>} The process exit code.
106
+ */
107
+ export async function runGrant(options) {
108
+ try {
109
+ const actions = normalizeActions(options.action);
110
+ const delegatee = await resolveDidRef({ ref: options.to });
111
+ if (!delegatee) {
112
+ throw new Error(`No locally stored DID found for "${options.to}".`);
113
+ }
114
+ const expires = options.expires ?? expiresFromTtl(options.ttl ?? '1y').toISOString();
115
+ const target = await resolveWasTarget({
116
+ address: options.address,
117
+ server: options.server,
118
+ did: options.did
119
+ });
120
+ const url = wasUrl({
121
+ server: target.server,
122
+ spaceId: target.spaceId,
123
+ collectionId: target.collectionId,
124
+ resourceId: target.resourceId
125
+ });
126
+ const delegatedCapability = await target.client.grant({
127
+ to: delegatee,
128
+ actions,
129
+ expires,
130
+ target: url
131
+ });
132
+ const encoded = encodeCapability(delegatedCapability);
133
+ if (options.save) {
134
+ const storageId = storageIdFor(delegatedCapability.id);
135
+ const filePath = await saveToCollection('zcaps', storageId, delegatedCapability);
136
+ await writeCreateMeta({
137
+ storageId,
138
+ created: new Date().toISOString(),
139
+ handle: options.handle,
140
+ description: options.description
141
+ });
142
+ console.error(`Capability saved to ${filePath}`);
143
+ }
144
+ console.log(JSON.stringify({ delegatedCapability, encoded }, null, 2));
145
+ return 0;
146
+ }
147
+ catch (err) {
148
+ return reportError({ action: 'grant access', err });
149
+ }
150
+ }
151
+ //# sourceMappingURL=publish.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"publish.js","sourceRoot":"","sources":["../../../src/commands/was/publish.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AACnD,OAAO,EAA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ACV,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,WAAW,CAAC,EAAE,MAAM,EAAE,cAAc,EAAE,GAAG,EAAE,CAAC,CAAA;IACrD,CAAC;AACH,CAAC"}
@@ -0,0 +1,148 @@
1
+ /**
2
+ * Adds a resource to a collection (server-generated id) and prints the
3
+ * `{ id, url, contentType }` add result. The collection comes from a path
4
+ * or a `--capability` targeting one.
5
+ *
6
+ * @param options {object}
7
+ * @param [options.address] {string} The collection address.
8
+ * @param [options.capability] {string} A capability reference instead of
9
+ * a path.
10
+ * @param [options.file] {string} The payload file; stdin when omitted.
11
+ * @param [options.contentType] {string} Explicit payload content type.
12
+ * @param [options.server] {string} The server base URL.
13
+ * @param [options.did] {string} The signing DID or stored-DID handle.
14
+ * @returns {Promise<number>} The process exit code.
15
+ */
16
+ export declare function runResourceAdd(options: {
17
+ address?: string;
18
+ capability?: string;
19
+ file?: string;
20
+ contentType?: string;
21
+ server?: string;
22
+ did?: string;
23
+ }): Promise<number>;
24
+ /**
25
+ * Creates or replaces a resource at a known id (upsert) and prints
26
+ * `{ id, url }`. The resource comes from a path or a `--capability`
27
+ * targeting one.
28
+ *
29
+ * @param options {object}
30
+ * @param [options.address] {string} The resource address.
31
+ * @param [options.capability] {string} A capability reference instead of
32
+ * a path.
33
+ * @param [options.file] {string} The payload file; stdin when omitted.
34
+ * @param [options.contentType] {string} Explicit payload content type.
35
+ * @param [options.server] {string} The server base URL.
36
+ * @param [options.did] {string} The signing DID or stored-DID handle.
37
+ * @returns {Promise<number>} The process exit code.
38
+ */
39
+ export declare function runResourcePut(options: {
40
+ address?: string;
41
+ capability?: string;
42
+ file?: string;
43
+ contentType?: string;
44
+ server?: string;
45
+ did?: string;
46
+ }): Promise<number>;
47
+ /**
48
+ * Reads a resource: JSON pretty-printed to stdout, binary written raw
49
+ * (`--output` for files). The resource comes from a path or a
50
+ * `--capability` targeting one.
51
+ *
52
+ * @param options {object}
53
+ * @param [options.address] {string} The resource address.
54
+ * @param [options.capability] {string} A capability reference instead of
55
+ * a path.
56
+ * @param [options.output] {string} The output file path; stdout when
57
+ * omitted.
58
+ * @param [options.server] {string} The server base URL.
59
+ * @param [options.did] {string} The signing DID or stored-DID handle.
60
+ * @returns {Promise<number>} The process exit code.
61
+ */
62
+ export declare function runResourceGet(options: {
63
+ address?: string;
64
+ capability?: string;
65
+ output?: string;
66
+ server?: string;
67
+ did?: string;
68
+ }): Promise<number>;
69
+ /**
70
+ * Reads a resource's metadata object (server-managed `contentType` / `size` /
71
+ * timestamps plus the user-writable `custom`) and pretty-prints it. The
72
+ * resource comes from a path or a `--capability` targeting one.
73
+ *
74
+ * @param options {object}
75
+ * @param [options.address] {string} The resource address.
76
+ * @param [options.capability] {string} A capability reference instead of
77
+ * a path.
78
+ * @param [options.server] {string} The server base URL.
79
+ * @param [options.did] {string} The signing DID or stored-DID handle.
80
+ * @returns {Promise<number>} The process exit code.
81
+ */
82
+ export declare function runResourceMetaGet(options: {
83
+ address?: string;
84
+ capability?: string;
85
+ server?: string;
86
+ did?: string;
87
+ }): Promise<number>;
88
+ /**
89
+ * Updates a resource's user-writable metadata and prints the resulting
90
+ * metadata. `--name`/`--tag` are read-modify-write sugar that preserve the
91
+ * other field; giving both, or `--json`, is a full `custom` replacement so
92
+ * any omitted property is cleared. The resource comes from a path or a
93
+ * `--capability` targeting one.
94
+ *
95
+ * @param options {object}
96
+ * @param [options.address] {string} The resource address.
97
+ * @param [options.capability] {string} A capability reference instead of
98
+ * a path.
99
+ * @param [options.name] {string} The resource's display name.
100
+ * @param options.tag {string[]} Repeatable `key=value` tag pairs.
101
+ * @param [options.json] {string} Full `custom` JSON (inline or a file
102
+ * path); mutually exclusive with `--name`/`--tag`.
103
+ * @param [options.server] {string} The server base URL.
104
+ * @param [options.did] {string} The signing DID or stored-DID handle.
105
+ * @returns {Promise<number>} The process exit code.
106
+ */
107
+ export declare function runResourceMetaPut(options: {
108
+ address?: string;
109
+ capability?: string;
110
+ name?: string;
111
+ tag: string[];
112
+ json?: string;
113
+ server?: string;
114
+ did?: string;
115
+ }): Promise<number>;
116
+ /**
117
+ * Lists the resources in a collection.
118
+ *
119
+ * @param options {object}
120
+ * @param options.address {string} The collection address.
121
+ * @param [options.json] {boolean} Output the raw listing JSON.
122
+ * @param [options.plain] {boolean} Output one resource id per line.
123
+ * @param [options.server] {string} The server base URL.
124
+ * @param [options.did] {string} The signing DID or stored-DID handle.
125
+ * @returns {Promise<number>} The process exit code.
126
+ */
127
+ export declare function runResourceList(options: {
128
+ address: string;
129
+ json?: boolean;
130
+ plain?: boolean;
131
+ server?: string;
132
+ did?: string;
133
+ }): Promise<number>;
134
+ /**
135
+ * Deletes a resource on the server. Idempotent.
136
+ *
137
+ * @param options {object}
138
+ * @param options.address {string} The resource address.
139
+ * @param [options.server] {string} The server base URL.
140
+ * @param [options.did] {string} The signing DID or stored-DID handle.
141
+ * @returns {Promise<number>} The process exit code.
142
+ */
143
+ export declare function runResourceDelete(options: {
144
+ address: string;
145
+ server?: string;
146
+ did?: string;
147
+ }): Promise<number>;
148
+ //# sourceMappingURL=resource.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resource.d.ts","sourceRoot":"","sources":["../../../src/commands/was/resource.ts"],"names":[],"mappings":"AAoFA;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,cAAc,CAAC,OAAO,EAAE;IAC5C,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,GAAG,CAAC,EAAE,MAAM,CAAA;CACb,GAAG,OAAO,CAAC,MAAM,CAAC,CA2ClB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,cAAc,CAAC,OAAO,EAAE;IAC5C,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,UAAU,CAAC,EAAE,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