@interop/was-client 0.99.0 → 0.100.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 +94 -71
- package/dist/Collection.d.ts +20 -8
- package/dist/Collection.d.ts.map +1 -1
- package/dist/Collection.js +89 -69
- package/dist/Collection.js.map +1 -1
- package/dist/Resource.d.ts +14 -3
- package/dist/Resource.d.ts.map +1 -1
- package/dist/Resource.js +38 -27
- package/dist/Resource.js.map +1 -1
- package/dist/Space.d.ts +18 -4
- package/dist/Space.d.ts.map +1 -1
- package/dist/Space.js +64 -61
- package/dist/Space.js.map +1 -1
- package/dist/WasClient.d.ts +105 -58
- package/dist/WasClient.d.ts.map +1 -1
- package/dist/WasClient.js +216 -142
- package/dist/WasClient.js.map +1 -1
- package/dist/codec.d.ts +3 -2
- package/dist/codec.d.ts.map +1 -1
- package/dist/edv/EdvCodec.d.ts.map +1 -1
- package/dist/edv/EdvCodec.js +37 -26
- package/dist/edv/EdvCodec.js.map +1 -1
- package/dist/edv/WasTransport.d.ts +7 -4
- package/dist/edv/WasTransport.d.ts.map +1 -1
- package/dist/edv/WasTransport.js +39 -20
- package/dist/edv/WasTransport.js.map +1 -1
- package/dist/edv/acquire.d.ts +3 -3
- package/dist/edv/acquire.d.ts.map +1 -1
- package/dist/edv/acquire.js +3 -3
- package/dist/edv/acquire.js.map +1 -1
- package/dist/edv/cipher.d.ts +7 -4
- package/dist/edv/cipher.d.ts.map +1 -1
- package/dist/edv/cipher.js +7 -4
- package/dist/edv/cipher.js.map +1 -1
- package/dist/edv/core.d.ts +1 -1
- package/dist/edv/core.d.ts.map +1 -1
- package/dist/edv/core.js +1 -1
- package/dist/edv/core.js.map +1 -1
- package/dist/edv/docCipher.d.ts +10 -7
- package/dist/edv/docCipher.d.ts.map +1 -1
- package/dist/edv/docCipher.js +12 -8
- package/dist/edv/docCipher.js.map +1 -1
- package/dist/edv/encryption.d.ts +2 -2
- package/dist/edv/encryption.d.ts.map +1 -1
- package/dist/edv/encryption.js +8 -6
- package/dist/edv/encryption.js.map +1 -1
- package/dist/edv/epochCrypto.d.ts +12 -4
- package/dist/edv/epochCrypto.d.ts.map +1 -1
- package/dist/edv/epochCrypto.js +37 -10
- package/dist/edv/epochCrypto.js.map +1 -1
- package/dist/edv/epochKeys.d.ts +6 -2
- package/dist/edv/epochKeys.d.ts.map +1 -1
- package/dist/edv/epochKeys.js +25 -14
- package/dist/edv/epochKeys.js.map +1 -1
- package/dist/edv/hmacKey.d.ts +7 -1
- package/dist/edv/hmacKey.d.ts.map +1 -1
- package/dist/edv/hmacKey.js +9 -3
- package/dist/edv/hmacKey.js.map +1 -1
- package/dist/edv/index.d.ts +1 -1
- package/dist/edv/index.d.ts.map +1 -1
- package/dist/edv/index.js +1 -1
- package/dist/edv/index.js.map +1 -1
- package/dist/edv/recipients.d.ts.map +1 -1
- package/dist/edv/recipients.js +2 -0
- package/dist/edv/recipients.js.map +1 -1
- package/dist/edv/refreshingDocCipher.d.ts +3 -3
- package/dist/edv/refreshingDocCipher.d.ts.map +1 -1
- package/dist/edv/refreshingDocCipher.js +3 -3
- package/dist/edv/refreshingDocCipher.js.map +1 -1
- package/dist/edv/transportFactory.d.ts +3 -3
- package/dist/edv/transportFactory.d.ts.map +1 -1
- package/dist/edv/transportFactory.js +3 -3
- package/dist/edv/transportFactory.js.map +1 -1
- package/dist/errors.d.ts +6 -4
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +6 -4
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/internal/codec.d.ts +7 -7
- package/dist/internal/codec.d.ts.map +1 -1
- package/dist/internal/codec.js +19 -18
- package/dist/internal/codec.js.map +1 -1
- package/dist/internal/conditional.d.ts +3 -3
- package/dist/internal/conditional.d.ts.map +1 -1
- package/dist/internal/conditional.js +5 -5
- package/dist/internal/conditional.js.map +1 -1
- package/dist/internal/grant.d.ts +15 -26
- package/dist/internal/grant.d.ts.map +1 -1
- package/dist/internal/grant.js +95 -29
- package/dist/internal/grant.js.map +1 -1
- package/dist/internal/memo.d.ts +13 -4
- package/dist/internal/memo.d.ts.map +1 -1
- package/dist/internal/memo.js +18 -7
- package/dist/internal/memo.js.map +1 -1
- package/dist/internal/meta.d.ts +8 -8
- package/dist/internal/meta.d.ts.map +1 -1
- package/dist/internal/meta.js +13 -10
- package/dist/internal/meta.js.map +1 -1
- package/dist/internal/pagination.d.ts +30 -15
- package/dist/internal/pagination.d.ts.map +1 -1
- package/dist/internal/pagination.js +31 -17
- package/dist/internal/pagination.js.map +1 -1
- package/dist/internal/paths.d.ts +332 -195
- package/dist/internal/paths.d.ts.map +1 -1
- package/dist/internal/paths.js +400 -367
- package/dist/internal/paths.js.map +1 -1
- package/dist/internal/policy.d.ts +23 -23
- package/dist/internal/policy.d.ts.map +1 -1
- package/dist/internal/policy.js +20 -20
- package/dist/internal/policy.js.map +1 -1
- package/dist/internal/request.d.ts +17 -21
- package/dist/internal/request.d.ts.map +1 -1
- package/dist/internal/request.js +10 -21
- package/dist/internal/request.js.map +1 -1
- package/dist/internal/revoke.d.ts +34 -13
- package/dist/internal/revoke.d.ts.map +1 -1
- package/dist/internal/revoke.js +97 -28
- package/dist/internal/revoke.js.map +1 -1
- package/dist/internal/service.d.ts +25 -7
- package/dist/internal/service.d.ts.map +1 -1
- package/dist/internal/service.js +49 -45
- package/dist/internal/service.js.map +1 -1
- package/dist/internal/write.d.ts +18 -18
- package/dist/internal/write.d.ts.map +1 -1
- package/dist/internal/write.js +27 -27
- package/dist/internal/write.js.map +1 -1
- package/dist/paths.d.ts +32 -25
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +32 -25
- package/dist/paths.js.map +1 -1
- package/dist/sync/index.d.ts +4 -2
- package/dist/sync/index.d.ts.map +1 -1
- package/dist/sync/index.js +4 -2
- package/dist/sync/index.js.map +1 -1
- package/dist/sync/port.d.ts +3 -3
- package/dist/sync/port.d.ts.map +1 -1
- package/dist/sync/port.js +12 -12
- package/dist/sync/port.js.map +1 -1
- package/dist/sync/provisioning.d.ts +10 -9
- package/dist/sync/provisioning.d.ts.map +1 -1
- package/dist/sync/provisioning.js +19 -18
- package/dist/sync/provisioning.js.map +1 -1
- package/dist/sync/types.d.ts +2 -2
- package/dist/types.d.ts +13 -5
- package/dist/types.d.ts.map +1 -1
- package/package.json +4 -4
|
@@ -11,6 +11,15 @@ import type { IDelegatedZcap, IRootZcap, IZcap } from '../types.js';
|
|
|
11
11
|
* @returns {string}
|
|
12
12
|
*/
|
|
13
13
|
export declare function rootCapabilityId(target: string): string;
|
|
14
|
+
/**
|
|
15
|
+
* The invocation target a root capability id names: the inverse of
|
|
16
|
+
* {@link rootCapabilityId}. Returns `null` for an id that is not a root
|
|
17
|
+
* capability id, or whose encoded target is malformed.
|
|
18
|
+
*
|
|
19
|
+
* @param id {string} a capability id
|
|
20
|
+
* @returns {string | null}
|
|
21
|
+
*/
|
|
22
|
+
export declare function rootCapabilityTarget(id: string): string | null;
|
|
14
23
|
/**
|
|
15
24
|
* Builds the root capability for `target` in **object** form.
|
|
16
25
|
*
|
|
@@ -32,21 +41,33 @@ export declare function rootCapability({ target, controller }: {
|
|
|
32
41
|
controller: string;
|
|
33
42
|
}): IRootZcap;
|
|
34
43
|
/**
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
44
|
+
* The URL of the Space a capability is rooted in, read off its delegation
|
|
45
|
+
* chain: a Space-rooted capability's chain starts at the Space's root
|
|
46
|
+
* capability, whose id encodes the Space URL. The result is in canonical
|
|
47
|
+
* form.
|
|
48
|
+
*
|
|
49
|
+
* The root's target is taken to be the Space URL. A Space URL has no shape
|
|
50
|
+
* of its own (a Collection URL is an http(s) URL ending in a slash too), so
|
|
51
|
+
* this function cannot tell a chain rooted at a Space from one rooted at a
|
|
52
|
+
* Collection, a Resource, or a Spaces Repository: only the server, which
|
|
53
|
+
* knows its hierarchy, can, and it refuses a revocation whose chain does not
|
|
54
|
+
* root exactly in the Space. What is refused here is a root whose target
|
|
55
|
+
* cannot be a Space URL at all (an origin, a URL with a query, a URN) and a
|
|
56
|
+
* chain that starts at no root capability. A capability this client minted
|
|
57
|
+
* from a handle is always Space-rooted. A bare `was.grant({ target })` with
|
|
58
|
+
* no `spaceUrl`, the mode for a server with no Space hierarchy, roots at
|
|
59
|
+
* its target and is not revocable this way by design.
|
|
40
60
|
*
|
|
41
|
-
* @param context {ClientContext}
|
|
42
61
|
* @param zcap {IZcap} the capability to locate
|
|
43
62
|
* @returns {string}
|
|
63
|
+
* @throws {ValidationError} when the chain does not start at a root
|
|
64
|
+
* capability id, or that id names something that cannot be a Space URL
|
|
44
65
|
*/
|
|
45
|
-
export declare function
|
|
66
|
+
export declare function spaceUrlOf(zcap: IZcap): string;
|
|
46
67
|
/**
|
|
47
68
|
* Revokes a Space-rooted delegated capability: `POST`s it to
|
|
48
|
-
*
|
|
49
|
-
*
|
|
69
|
+
* `{spaceUrl}zcaps/revocations/:capabilityId`, invoking that URL's own root
|
|
70
|
+
* capability. Resolves on the server's 204.
|
|
50
71
|
*
|
|
51
72
|
* The `action` is deliberately left unset: `send()` defaults it to the HTTP
|
|
52
73
|
* method, and this route expects `POST` (WAS capabilities are scoped by HTTP
|
|
@@ -54,12 +75,12 @@ export declare function spaceIdOf(context: ClientContext, zcap: IZcap): string;
|
|
|
54
75
|
*
|
|
55
76
|
* @param context {ClientContext}
|
|
56
77
|
* @param options {object}
|
|
57
|
-
* @param options.
|
|
58
|
-
* @param options.zcap {IDelegatedZcap}
|
|
78
|
+
* @param options.spaceUrl {string} the Space the capability is rooted in
|
|
79
|
+
* @param options.zcap {IDelegatedZcap} the capability to revoke
|
|
59
80
|
* @returns {Promise<void>}
|
|
60
81
|
*/
|
|
61
|
-
export declare function submitRevocation(context: ClientContext, {
|
|
62
|
-
|
|
82
|
+
export declare function submitRevocation(context: ClientContext, { spaceUrl, zcap }: {
|
|
83
|
+
spaceUrl: string;
|
|
63
84
|
zcap: IDelegatedZcap;
|
|
64
85
|
}): Promise<void>;
|
|
65
86
|
//# sourceMappingURL=revoke.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"revoke.d.ts","sourceRoot":"","sources":["../../src/internal/revoke.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"revoke.d.ts","sourceRoot":"","sources":["../../src/internal/revoke.ts"],"names":[],"mappings":"AA4BA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAGjD,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAYnE;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEvD;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAS9D;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,cAAc,CAAC,EAC7B,MAAM,EACN,UAAU,EACX,EAAE;IACD,MAAM,EAAE,MAAM,CAAA;IACd,UAAU,EAAE,MAAM,CAAA;CACnB,GAAG,SAAS,CAOZ;AA+BD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,KAAK,GAAG,MAAM,CAmB9C;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,gBAAgB,CACpC,OAAO,EAAE,aAAa,EACtB,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,cAAc,CAAA;CAAE,GAC7D,OAAO,CAAC,IAAI,CAAC,CAgBf"}
|
package/dist/internal/revoke.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
/**
|
|
5
5
|
* The revocation primitive shared by `was.revoke()` and `space.revoke()` -- the
|
|
6
6
|
* inverse of `grant.ts`. Submits a delegated capability to its Space's
|
|
7
|
-
* revocation endpoint (`POST
|
|
7
|
+
* revocation endpoint (`POST {spaceUrl}zcaps/revocations/:capabilityId`),
|
|
8
8
|
* where the URL names the capability's `id` and the body is that capability
|
|
9
9
|
* verbatim, proof and capability chain included.
|
|
10
10
|
*
|
|
@@ -19,14 +19,23 @@
|
|
|
19
19
|
* A chain that no longer verifies (tampered, expired, or a delegating key
|
|
20
20
|
* gone from its controller document) synthesizes an empty controller set, so
|
|
21
21
|
* the invocation is denied.
|
|
22
|
+
*
|
|
23
|
+
* This module also owns the root capability id grammar and its inverse. A
|
|
24
|
+
* Space-rooted chain starts at the Space's root capability, whose id encodes
|
|
25
|
+
* the Space URL, so the Space a capability belongs to is read off its chain
|
|
26
|
+
* (`spaceUrlOf`) rather than assembled from any server root.
|
|
22
27
|
*/
|
|
23
|
-
import {
|
|
28
|
+
import { canonicalSpaceUrl, spaceRevocationUrl } from './paths.js';
|
|
24
29
|
import { send } from './request.js';
|
|
25
30
|
import { ValidationError } from '../errors.js';
|
|
26
31
|
/**
|
|
27
32
|
* The zcap JSON-LD context URL, the sole `@context` of a root capability.
|
|
28
33
|
*/
|
|
29
34
|
const ZCAP_CONTEXT_URL = 'https://w3id.org/zcap/v1';
|
|
35
|
+
/**
|
|
36
|
+
* The prefix of a root capability id.
|
|
37
|
+
*/
|
|
38
|
+
const ROOT_ID_PREFIX = 'urn:zcap:root:';
|
|
30
39
|
/**
|
|
31
40
|
* The root capability id for an invocation target URL
|
|
32
41
|
* (`urn:zcap:root:<encoded target>`) -- the id grammar shared by revocation
|
|
@@ -38,7 +47,26 @@ const ZCAP_CONTEXT_URL = 'https://w3id.org/zcap/v1';
|
|
|
38
47
|
* @returns {string}
|
|
39
48
|
*/
|
|
40
49
|
export function rootCapabilityId(target) {
|
|
41
|
-
return
|
|
50
|
+
return `${ROOT_ID_PREFIX}${encodeURIComponent(target)}`;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The invocation target a root capability id names: the inverse of
|
|
54
|
+
* {@link rootCapabilityId}. Returns `null` for an id that is not a root
|
|
55
|
+
* capability id, or whose encoded target is malformed.
|
|
56
|
+
*
|
|
57
|
+
* @param id {string} a capability id
|
|
58
|
+
* @returns {string | null}
|
|
59
|
+
*/
|
|
60
|
+
export function rootCapabilityTarget(id) {
|
|
61
|
+
if (!id.startsWith(ROOT_ID_PREFIX)) {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
try {
|
|
65
|
+
return decodeURIComponent(id.slice(ROOT_ID_PREFIX.length));
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
42
70
|
}
|
|
43
71
|
/**
|
|
44
72
|
* Builds the root capability for `target` in **object** form.
|
|
@@ -65,32 +93,76 @@ export function rootCapability({ target, controller }) {
|
|
|
65
93
|
};
|
|
66
94
|
}
|
|
67
95
|
/**
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
96
|
+
* The id of the root capability a chain starts at: the first entry of the
|
|
97
|
+
* delegation proof's `capabilityChain`, or the `parentCapability` of a
|
|
98
|
+
* capability delegated straight from a root, or the capability's own id when
|
|
99
|
+
* it is a root. `undefined` when the capability carries no proof and no
|
|
100
|
+
* parent that names a root.
|
|
101
|
+
*
|
|
102
|
+
* The delegation proof is the one carrying `capabilityChain`, wherever it
|
|
103
|
+
* sits in a proof set: a capability may also carry an assertion proof, and
|
|
104
|
+
* nothing fixes the order.
|
|
105
|
+
*
|
|
106
|
+
* @param zcap {IZcap}
|
|
107
|
+
* @returns {string | undefined}
|
|
108
|
+
*/
|
|
109
|
+
function chainRootId(zcap) {
|
|
110
|
+
if (!('parentCapability' in zcap)) {
|
|
111
|
+
return zcap.id;
|
|
112
|
+
}
|
|
113
|
+
const proofs = Array.isArray(zcap.proof) ? zcap.proof : [zcap.proof];
|
|
114
|
+
const delegation = proofs.find(proof => proof?.capabilityChain !== undefined);
|
|
115
|
+
const first = delegation?.capabilityChain?.[0];
|
|
116
|
+
if (typeof first === 'string') {
|
|
117
|
+
return first;
|
|
118
|
+
}
|
|
119
|
+
return typeof zcap.parentCapability === 'string'
|
|
120
|
+
? zcap.parentCapability
|
|
121
|
+
: undefined;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* The URL of the Space a capability is rooted in, read off its delegation
|
|
125
|
+
* chain: a Space-rooted capability's chain starts at the Space's root
|
|
126
|
+
* capability, whose id encodes the Space URL. The result is in canonical
|
|
127
|
+
* form.
|
|
128
|
+
*
|
|
129
|
+
* The root's target is taken to be the Space URL. A Space URL has no shape
|
|
130
|
+
* of its own (a Collection URL is an http(s) URL ending in a slash too), so
|
|
131
|
+
* this function cannot tell a chain rooted at a Space from one rooted at a
|
|
132
|
+
* Collection, a Resource, or a Spaces Repository: only the server, which
|
|
133
|
+
* knows its hierarchy, can, and it refuses a revocation whose chain does not
|
|
134
|
+
* root exactly in the Space. What is refused here is a root whose target
|
|
135
|
+
* cannot be a Space URL at all (an origin, a URL with a query, a URN) and a
|
|
136
|
+
* chain that starts at no root capability. A capability this client minted
|
|
137
|
+
* from a handle is always Space-rooted. A bare `was.grant({ target })` with
|
|
138
|
+
* no `spaceUrl`, the mode for a server with no Space hierarchy, roots at
|
|
139
|
+
* its target and is not revocable this way by design.
|
|
73
140
|
*
|
|
74
|
-
* @param context {ClientContext}
|
|
75
141
|
* @param zcap {IZcap} the capability to locate
|
|
76
142
|
* @returns {string}
|
|
143
|
+
* @throws {ValidationError} when the chain does not start at a root
|
|
144
|
+
* capability id, or that id names something that cannot be a Space URL
|
|
77
145
|
*/
|
|
78
|
-
export function
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
146
|
+
export function spaceUrlOf(zcap) {
|
|
147
|
+
const rootId = chainRootId(zcap);
|
|
148
|
+
const target = rootId === undefined ? null : rootCapabilityTarget(rootId);
|
|
149
|
+
if (target === null) {
|
|
150
|
+
throw new ValidationError(`Cannot derive a Space from capability "${zcap.id}": its chain does ` +
|
|
151
|
+
'not start at a root capability id (`urn:zcap:root:...`), so it is ' +
|
|
152
|
+
'not rooted in a Space.');
|
|
153
|
+
}
|
|
154
|
+
try {
|
|
155
|
+
return canonicalSpaceUrl(target);
|
|
156
|
+
}
|
|
157
|
+
catch (err) {
|
|
158
|
+
throw new ValidationError(`Cannot derive a Space from capability "${zcap.id}": its root ` +
|
|
159
|
+
`capability names "${target}", which is not a Space URL.`, { cause: err });
|
|
87
160
|
}
|
|
88
|
-
return parsed.spaceId;
|
|
89
161
|
}
|
|
90
162
|
/**
|
|
91
163
|
* Revokes a Space-rooted delegated capability: `POST`s it to
|
|
92
|
-
*
|
|
93
|
-
*
|
|
164
|
+
* `{spaceUrl}zcaps/revocations/:capabilityId`, invoking that URL's own root
|
|
165
|
+
* capability. Resolves on the server's 204.
|
|
94
166
|
*
|
|
95
167
|
* The `action` is deliberately left unset: `send()` defaults it to the HTTP
|
|
96
168
|
* method, and this route expects `POST` (WAS capabilities are scoped by HTTP
|
|
@@ -98,18 +170,15 @@ export function spaceIdOf(context, zcap) {
|
|
|
98
170
|
*
|
|
99
171
|
* @param context {ClientContext}
|
|
100
172
|
* @param options {object}
|
|
101
|
-
* @param options.
|
|
102
|
-
* @param options.zcap {IDelegatedZcap}
|
|
173
|
+
* @param options.spaceUrl {string} the Space the capability is rooted in
|
|
174
|
+
* @param options.zcap {IDelegatedZcap} the capability to revoke
|
|
103
175
|
* @returns {Promise<void>}
|
|
104
176
|
*/
|
|
105
|
-
export async function submitRevocation(context, {
|
|
177
|
+
export async function submitRevocation(context, { spaceUrl, zcap }) {
|
|
106
178
|
if (!('parentCapability' in zcap)) {
|
|
107
179
|
throw new ValidationError('A root capability cannot be revoked; only a delegated capability can.');
|
|
108
180
|
}
|
|
109
|
-
const url =
|
|
110
|
-
baseUrl: context.baseUrl,
|
|
111
|
-
path: spaceRevocation(spaceId, zcap.id)
|
|
112
|
-
});
|
|
181
|
+
const url = spaceRevocationUrl({ spaceUrl, capabilityId: zcap.id });
|
|
113
182
|
await send(context, {
|
|
114
183
|
url,
|
|
115
184
|
method: 'POST',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"revoke.js","sourceRoot":"","sources":["../../src/internal/revoke.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH
|
|
1
|
+
{"version":3,"file":"revoke.js","sourceRoot":"","sources":["../../src/internal/revoke.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAElE,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AACnC,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAG9C;;GAEG;AACH,MAAM,gBAAgB,GAAG,0BAA0B,CAAA;AAEnD;;GAEG;AACH,MAAM,cAAc,GAAG,gBAAgB,CAAA;AAEvC;;;;;;;;;GASG;AACH,MAAM,UAAU,gBAAgB,CAAC,MAAc;IAC7C,OAAO,GAAG,cAAc,GAAG,kBAAkB,CAAC,MAAM,CAAC,EAAE,CAAA;AACzD,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,oBAAoB,CAAC,EAAU;IAC7C,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,cAAc,CAAC,EAAE,CAAC;QACnC,OAAO,IAAI,CAAA;IACb,CAAC;IACD,IAAI,CAAC;QACH,OAAO,kBAAkB,CAAC,EAAE,CAAC,KAAK,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAA;IAC5D,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAA;IACb,CAAC;AACH,CAAC;AAED;;;;;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CAAC;QACpB,MAAM,IAAI,eAAe,CACvB,0CAA0C,IAAI,CAAC,EAAE,oBAAoB;YACnE,oEAAoE;YACpE,wBAAwB,CAC3B,CAAA;IACH,CAAC;IACD,IAAI,CAAC;QACH,OAAO,iBAAiB,CAAC,MAAM,CAAC,CAAA;IAClC,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,IAAI,eAAe,CACvB,0CAA0C,IAAI,CAAC,EAAE,cAAc;YAC7D,qBAAqB,MAAM,8BAA8B,EAC3D,EAAE,KAAK,EAAE,GAAG,EAAE,CACf,CAAA;IACH,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,OAAsB,EACtB,EAAE,QAAQ,EAAE,IAAI,EAA8C;IAE9D,IAAI,CAAC,CAAC,kBAAkB,IAAI,IAAI,CAAC,EAAE,CAAC;QAClC,MAAM,IAAI,eAAe,CACvB,uEAAuE,CACxE,CAAA;IACH,CAAC;IACD,MAAM,GAAG,GAAG,kBAAkB,CAAC,EAAE,QAAQ,EAAE,YAAY,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,CAAA;IACnE,MAAM,IAAI,CAAC,OAAO,EAAE;QAClB,GAAG;QACH,MAAM,EAAE,MAAM;QACd,UAAU,EAAE,cAAc,CAAC;YACzB,MAAM,EAAE,GAAG;YACX,UAAU,EAAE,OAAO,CAAC,aAAa;SAClC,CAAC;QACF,IAAI,EAAE,IAAI;KACX,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -29,7 +29,8 @@ export declare function serviceLinkTarget({ header, baseUrl }: {
|
|
|
29
29
|
* `specs` key other than the WAS identifier is ignored, a version entry
|
|
30
30
|
* without a string `version` is ignored, and the newest version this client
|
|
31
31
|
* speaks is chosen. The members the client acts on are checked before they are
|
|
32
|
-
* used: `spaces` must be an absolute URL and `features` an array of
|
|
32
|
+
* used: `spaces` must be an absolute `http(s)` URL and `features` an array of
|
|
33
|
+
* strings.
|
|
33
34
|
*
|
|
34
35
|
* @param description {unknown} the parsed service description
|
|
35
36
|
* @returns {ServiceInfo}
|
|
@@ -39,18 +40,35 @@ export declare function serviceLinkTarget({ header, baseUrl }: {
|
|
|
39
40
|
*/
|
|
40
41
|
export declare function selectServiceVersion(description: unknown): ServiceInfo;
|
|
41
42
|
/**
|
|
42
|
-
*
|
|
43
|
-
* the version to speak
|
|
44
|
-
*
|
|
45
|
-
*
|
|
43
|
+
* Reads the service description at `serviceUrl` with an unsigned `GET` and
|
|
44
|
+
* selects the version to speak.
|
|
45
|
+
*
|
|
46
|
+
* A network failure, and a rate limit or temporary outage (429, 502, 503,
|
|
47
|
+
* 504), reject with the mapped transport error, since they say nothing about
|
|
48
|
+
* the protocol the server speaks.
|
|
49
|
+
*
|
|
50
|
+
* @param options {object}
|
|
51
|
+
* @param options.serviceUrl {string} the service description's URL
|
|
52
|
+
* @returns {Promise<ServiceInfo>}
|
|
53
|
+
* @throws {IncompatibleServerError} when the document cannot be read or
|
|
54
|
+
* parsed, or version selection refuses it (see {@link selectServiceVersion})
|
|
55
|
+
*/
|
|
56
|
+
export declare function readServiceDescription({ serviceUrl }: {
|
|
57
|
+
serviceUrl: string;
|
|
58
|
+
}): Promise<ServiceInfo>;
|
|
59
|
+
/**
|
|
60
|
+
* Discovers the service description from a URL the server answers and
|
|
61
|
+
* selects the version to speak: an unsigned `HEAD` of `url` for its `service`
|
|
62
|
+
* link (the response status does not matter), then
|
|
63
|
+
* {@link readServiceDescription} of the linked document.
|
|
46
64
|
*
|
|
47
65
|
* A network failure, and a rate limit or temporary outage (429, 502, 503,
|
|
48
66
|
* 504) that comes without the link, reject with the mapped transport error,
|
|
49
67
|
* since they say nothing about the protocol the server speaks.
|
|
50
68
|
*
|
|
51
69
|
* @param options {object}
|
|
52
|
-
* @param options.url {string} any WAS
|
|
53
|
-
*
|
|
70
|
+
* @param options.url {string} any URL the WAS server answers, typically a
|
|
71
|
+
* Spaces Repository URL
|
|
54
72
|
* @returns {Promise<ServiceInfo>}
|
|
55
73
|
* @throws {IncompatibleServerError} when the response carries no `service`
|
|
56
74
|
* link, the linked document cannot be read or parsed, or version selection
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../src/internal/service.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../src/internal/service.ts"],"names":[],"mappings":"AAwBA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAE9C;;;GAGG;AACH,eAAO,MAAM,WAAW,yBAAyB,CAAA;AAEjD;;;GAGG;AACH,eAAO,MAAM,sBAAsB,UAAU,CAAA;AA+C7C;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAAC,EAChC,MAAM,EACN,OAAO,EACR,EAAE;IACD,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;IACrB,OAAO,EAAE,MAAM,CAAA;CAChB,GAAG,MAAM,GAAG,SAAS,CA2BrB;AAYD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,OAAO,GAAG,WAAW,CAiEtE;AAqCD;;;;;;;;;;;;;GAaG;AACH,wBAAsB,sBAAsB,CAAC,EAC3C,UAAU,EACX,EAAE;IACD,UAAU,EAAE,MAAM,CAAA;CACnB,GAAG,OAAO,CAAC,WAAW,CAAC,CAwBvB;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,eAAe,CAAC,EACpC,GAAG,EACJ,EAAE;IACD,GAAG,EAAE,MAAM,CAAA;CACZ,GAAG,OAAO,CAAC,WAAW,CAAC,CAiBvB"}
|
package/dist/internal/service.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { IncompatibleServerError, mapError } from '../errors.js';
|
|
2
|
+
import { canonicalContainerUrl, parseAbsoluteHttpUrl } from './paths.js';
|
|
2
3
|
import { fetchMapped } from './request.js';
|
|
3
4
|
/**
|
|
4
5
|
* The WAS specification's identifier, the `specs` key its version entries sit
|
|
@@ -104,27 +105,13 @@ export function serviceLinkTarget({ header, baseUrl }) {
|
|
|
104
105
|
function isObject(value) {
|
|
105
106
|
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
106
107
|
}
|
|
107
|
-
/**
|
|
108
|
-
* Whether a value parses as an absolute URL.
|
|
109
|
-
*
|
|
110
|
-
* @param value {string}
|
|
111
|
-
* @returns {boolean}
|
|
112
|
-
*/
|
|
113
|
-
function isAbsoluteUrl(value) {
|
|
114
|
-
try {
|
|
115
|
-
new URL(value);
|
|
116
|
-
return true;
|
|
117
|
-
}
|
|
118
|
-
catch {
|
|
119
|
-
return false;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
108
|
/**
|
|
123
109
|
* Applies the spec's version-selection rules to a service description: a
|
|
124
110
|
* `specs` key other than the WAS identifier is ignored, a version entry
|
|
125
111
|
* without a string `version` is ignored, and the newest version this client
|
|
126
112
|
* speaks is chosen. The members the client acts on are checked before they are
|
|
127
|
-
* used: `spaces` must be an absolute URL and `features` an array of
|
|
113
|
+
* used: `spaces` must be an absolute `http(s)` URL and `features` an array of
|
|
114
|
+
* strings.
|
|
128
115
|
*
|
|
129
116
|
* @param description {unknown} the parsed service description
|
|
130
117
|
* @returns {ServiceInfo}
|
|
@@ -156,9 +143,9 @@ export function selectServiceVersion(description) {
|
|
|
156
143
|
}
|
|
157
144
|
const { spaces, features } = chosen;
|
|
158
145
|
if (spaces !== undefined &&
|
|
159
|
-
(typeof spaces !== 'string' ||
|
|
146
|
+
(typeof spaces !== 'string' || parseAbsoluteHttpUrl(spaces) === null)) {
|
|
160
147
|
throw new IncompatibleServerError(`The ${PWS_SPEC_ID} ${chosen.version} entry's \`spaces\` is not an ` +
|
|
161
|
-
'absolute URL.');
|
|
148
|
+
'absolute http(s) URL.');
|
|
162
149
|
}
|
|
163
150
|
if (features !== undefined &&
|
|
164
151
|
(!Array.isArray(features) ||
|
|
@@ -171,7 +158,7 @@ export function selectServiceVersion(description) {
|
|
|
171
158
|
description: description,
|
|
172
159
|
version: chosen.version,
|
|
173
160
|
entry: chosen,
|
|
174
|
-
...(spaces !== undefined && { spacesUrl: spaces }),
|
|
161
|
+
...(spaces !== undefined && { spacesUrl: canonicalContainerUrl(spaces) }),
|
|
175
162
|
features: tokens,
|
|
176
163
|
hasFeature(token) {
|
|
177
164
|
return tokens.includes(token);
|
|
@@ -204,38 +191,20 @@ function refuse({ status, requestUrl, message }) {
|
|
|
204
191
|
throw new IncompatibleServerError(message, { requestUrl });
|
|
205
192
|
}
|
|
206
193
|
/**
|
|
207
|
-
*
|
|
208
|
-
* the version to speak
|
|
209
|
-
* (the response status does not matter), then an unsigned `GET` of the linked
|
|
210
|
-
* document.
|
|
194
|
+
* Reads the service description at `serviceUrl` with an unsigned `GET` and
|
|
195
|
+
* selects the version to speak.
|
|
211
196
|
*
|
|
212
197
|
* A network failure, and a rate limit or temporary outage (429, 502, 503,
|
|
213
|
-
* 504)
|
|
214
|
-
*
|
|
198
|
+
* 504), reject with the mapped transport error, since they say nothing about
|
|
199
|
+
* the protocol the server speaks.
|
|
215
200
|
*
|
|
216
201
|
* @param options {object}
|
|
217
|
-
* @param options.
|
|
218
|
-
* (its Spaces Repository URL)
|
|
202
|
+
* @param options.serviceUrl {string} the service description's URL
|
|
219
203
|
* @returns {Promise<ServiceInfo>}
|
|
220
|
-
* @throws {IncompatibleServerError} when the
|
|
221
|
-
*
|
|
222
|
-
* refuses it (see {@link selectServiceVersion})
|
|
204
|
+
* @throws {IncompatibleServerError} when the document cannot be read or
|
|
205
|
+
* parsed, or version selection refuses it (see {@link selectServiceVersion})
|
|
223
206
|
*/
|
|
224
|
-
export async function
|
|
225
|
-
const probe = await fetchMapped(url, { method: 'HEAD' });
|
|
226
|
-
const serviceUrl = serviceLinkTarget({
|
|
227
|
-
header: probe.headers.get('link'),
|
|
228
|
-
baseUrl: probe.url || url
|
|
229
|
-
});
|
|
230
|
-
if (serviceUrl === undefined) {
|
|
231
|
-
refuse({
|
|
232
|
-
status: probe.status,
|
|
233
|
-
requestUrl: url,
|
|
234
|
-
message: `The response from "${url}" (${probe.status}) carries no ` +
|
|
235
|
-
'rel="service" link, so the server predates WAS v0.5, which this ' +
|
|
236
|
-
'client requires.'
|
|
237
|
-
});
|
|
238
|
-
}
|
|
207
|
+
export async function readServiceDescription({ serviceUrl }) {
|
|
239
208
|
const response = await fetchMapped(serviceUrl, {
|
|
240
209
|
method: 'GET',
|
|
241
210
|
headers: { accept: 'application/json' }
|
|
@@ -257,4 +226,39 @@ export async function discoverService({ url }) {
|
|
|
257
226
|
}
|
|
258
227
|
return selectServiceVersion(description);
|
|
259
228
|
}
|
|
229
|
+
/**
|
|
230
|
+
* Discovers the service description from a URL the server answers and
|
|
231
|
+
* selects the version to speak: an unsigned `HEAD` of `url` for its `service`
|
|
232
|
+
* link (the response status does not matter), then
|
|
233
|
+
* {@link readServiceDescription} of the linked document.
|
|
234
|
+
*
|
|
235
|
+
* A network failure, and a rate limit or temporary outage (429, 502, 503,
|
|
236
|
+
* 504) that comes without the link, reject with the mapped transport error,
|
|
237
|
+
* since they say nothing about the protocol the server speaks.
|
|
238
|
+
*
|
|
239
|
+
* @param options {object}
|
|
240
|
+
* @param options.url {string} any URL the WAS server answers, typically a
|
|
241
|
+
* Spaces Repository URL
|
|
242
|
+
* @returns {Promise<ServiceInfo>}
|
|
243
|
+
* @throws {IncompatibleServerError} when the response carries no `service`
|
|
244
|
+
* link, the linked document cannot be read or parsed, or version selection
|
|
245
|
+
* refuses it (see {@link selectServiceVersion})
|
|
246
|
+
*/
|
|
247
|
+
export async function discoverService({ url }) {
|
|
248
|
+
const probe = await fetchMapped(url, { method: 'HEAD' });
|
|
249
|
+
const serviceUrl = serviceLinkTarget({
|
|
250
|
+
header: probe.headers.get('link'),
|
|
251
|
+
baseUrl: probe.url || url
|
|
252
|
+
});
|
|
253
|
+
if (serviceUrl === undefined) {
|
|
254
|
+
refuse({
|
|
255
|
+
status: probe.status,
|
|
256
|
+
requestUrl: url,
|
|
257
|
+
message: `The response from "${url}" (${probe.status}) carries no ` +
|
|
258
|
+
'rel="service" link, so the server predates WAS v0.5, which this ' +
|
|
259
|
+
'client requires.'
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
return readServiceDescription({ serviceUrl });
|
|
263
|
+
}
|
|
260
264
|
//# sourceMappingURL=service.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.js","sourceRoot":"","sources":["../../src/internal/service.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"service.js","sourceRoot":"","sources":["../../src/internal/service.ts"],"names":[],"mappings":"AAqBA,OAAO,EAAE,uBAAuB,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AAChE,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AACxE,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAG1C;;;GAGG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,sBAAsB,CAAA;AAEjD;;;GAGG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,KAAK,CAAC,CAAA;AAE7C;;GAEG;AACH,MAAM,gBAAgB,GAAG,SAAS,CAAA;AAElC;;;;;;GAMG;AACH,SAAS,eAAe,CAAC,MAAc;IACrC,MAAM,MAAM,GAAa,EAAE,CAAA;IAC3B,IAAI,OAAO,GAAG,EAAE,CAAA;IAChB,IAAI,QAAQ,GAAG,KAAK,CAAA;IACpB,IAAI,QAAQ,GAAG,KAAK,CAAA;IACpB,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC;QACnD,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAW,CAAA;QACpC,IAAI,QAAQ,EAAE,CAAC;YACb,OAAO,IAAI,IAAI,CAAA;YACf,IAAI,IAAI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sBAAsB,GAAG,MAAM,KAAK,CAAC,MAAM,eAAe;gBAC1D,kEAAkE;gBAClE,kBAAkB;SACrB,CAAC,CAAA;IACJ,CAAC;IACD,OAAO,sBAAsB,CAAC,EAAE,UAAU,EAAE,CAAC,CAAA;AAC/C,CAAC"}
|
package/dist/internal/write.d.ts
CHANGED
|
@@ -24,22 +24,22 @@ import type { IZcap, ResourceData } from '../types.js';
|
|
|
24
24
|
import type { ClientContext } from './request.js';
|
|
25
25
|
import type { WritePrecondition } from './conditional.js';
|
|
26
26
|
/**
|
|
27
|
-
* Sends an encoded write (`PUT`/`POST`) to a resource
|
|
27
|
+
* Sends an encoded write (`PUT`/`POST`) to a resource URL, applying the
|
|
28
28
|
* encoded body (`json` or `body`), its content-type, and the conditional-write
|
|
29
29
|
* precondition. A write is never a `read`, so the response is always present
|
|
30
30
|
* (errors throw via `send`).
|
|
31
31
|
*
|
|
32
32
|
* @param context {ClientContext}
|
|
33
33
|
* @param options {object}
|
|
34
|
-
* @param options.
|
|
34
|
+
* @param options.url {string} the resource URL to write
|
|
35
35
|
* @param options.method {string} `PUT` or `POST`
|
|
36
36
|
* @param options.encoded {EncodedWrite} the codec's encoded write
|
|
37
37
|
* @param [options.capability] {IZcap}
|
|
38
38
|
* @param [options.precondition] {WritePrecondition} conditional-write headers
|
|
39
39
|
* @returns {Promise<HttpResponse>}
|
|
40
40
|
*/
|
|
41
|
-
export declare function sendEncodedWrite(context: ClientContext, {
|
|
42
|
-
|
|
41
|
+
export declare function sendEncodedWrite(context: ClientContext, { url, method, encoded, capability, precondition }: {
|
|
42
|
+
url: string;
|
|
43
43
|
method: string;
|
|
44
44
|
encoded: EncodedWrite;
|
|
45
45
|
capability?: IZcap;
|
|
@@ -68,19 +68,19 @@ export declare function codecRequestContext(context: ClientContext, { capability
|
|
|
68
68
|
}): CodecRequestContext;
|
|
69
69
|
/**
|
|
70
70
|
* The outcome of {@link insertResource}: either the ordinary single-request
|
|
71
|
-
* write (the codec's encoding, the
|
|
71
|
+
* write (the codec's encoding, the URL written, and the response) or the
|
|
72
72
|
* result of a codec's multi-request {@link ChunkedWrite} plan, which has no one
|
|
73
73
|
* canonical response.
|
|
74
74
|
*/
|
|
75
75
|
export type InsertOutcome = {
|
|
76
76
|
chunked?: false;
|
|
77
77
|
encoded: EncodedWrite;
|
|
78
|
-
|
|
78
|
+
url: string;
|
|
79
79
|
response: HttpResponse;
|
|
80
80
|
} | {
|
|
81
81
|
chunked: true;
|
|
82
82
|
id: string;
|
|
83
|
-
|
|
83
|
+
url: string;
|
|
84
84
|
contentType?: string;
|
|
85
85
|
etag?: string;
|
|
86
86
|
};
|
|
@@ -95,21 +95,21 @@ export type InsertOutcome = {
|
|
|
95
95
|
* preconditions.
|
|
96
96
|
*
|
|
97
97
|
* A codec that mints its own id (e.g. the encrypting codec's EDV id) writes it
|
|
98
|
-
* by `PUT` to that id's
|
|
99
|
-
* `POST`s to the items
|
|
98
|
+
* by `PUT` to that id's URL; a codec that mints none (the identity codec)
|
|
99
|
+
* `POST`s to the items URL and lets the server mint one. A conditional codec
|
|
100
100
|
* computes the precondition itself (the EDV codec guards its fresh insert with
|
|
101
101
|
* `If-None-Match: *`); an insert through a non-conditional codec is
|
|
102
102
|
* unconditional, since `add()` names no target revision to pin against.
|
|
103
103
|
*
|
|
104
|
-
* Returns the codec's encoded write and the
|
|
104
|
+
* Returns the codec's encoded write and the URL actually written alongside the
|
|
105
105
|
* response, so the caller can shape its result (the created id and URL) without
|
|
106
106
|
* re-deriving either.
|
|
107
107
|
*
|
|
108
108
|
* @param context {ClientContext}
|
|
109
109
|
* @param options {object}
|
|
110
|
-
* @param options.
|
|
110
|
+
* @param options.itemsUrl {string} the collection's items URL, the
|
|
111
111
|
* `POST` target when the codec mints no id
|
|
112
|
-
* @param options.
|
|
112
|
+
* @param options.urlForId {function} builds the resource URL for a
|
|
113
113
|
* codec-minted id
|
|
114
114
|
* @param options.codec {ResourceCodec} the collection's resolved codec
|
|
115
115
|
* @param options.data {ResourceData} the plaintext value
|
|
@@ -117,9 +117,9 @@ export type InsertOutcome = {
|
|
|
117
117
|
* @param [options.capability] {IZcap}
|
|
118
118
|
* @returns {Promise<InsertOutcome>}
|
|
119
119
|
*/
|
|
120
|
-
export declare function insertResource(context: ClientContext, {
|
|
121
|
-
|
|
122
|
-
|
|
120
|
+
export declare function insertResource(context: ClientContext, { itemsUrl, urlForId, codec, data, contentType, capability }: {
|
|
121
|
+
itemsUrl: string;
|
|
122
|
+
urlForId: (id: string) => string;
|
|
123
123
|
codec: ResourceCodec;
|
|
124
124
|
data: ResourceData;
|
|
125
125
|
contentType?: string;
|
|
@@ -152,7 +152,7 @@ export declare function insertResource(context: ClientContext, { itemsPath, path
|
|
|
152
152
|
*
|
|
153
153
|
* @param context {ClientContext}
|
|
154
154
|
* @param options {object}
|
|
155
|
-
* @param options.
|
|
155
|
+
* @param options.url {string} the resource URL to write
|
|
156
156
|
* @param options.codec {ResourceCodec} the collection's resolved codec
|
|
157
157
|
* @param options.id {string} the resource id
|
|
158
158
|
* @param options.data {ResourceData} the plaintext value
|
|
@@ -162,8 +162,8 @@ export declare function insertResource(context: ClientContext, { itemsPath, path
|
|
|
162
162
|
* precondition (used only for a non-conditional codec)
|
|
163
163
|
* @returns {Promise<{ etag?: string }>} the stored resource's new ETag
|
|
164
164
|
*/
|
|
165
|
-
export declare function upsertResource(context: ClientContext, {
|
|
166
|
-
|
|
165
|
+
export declare function upsertResource(context: ClientContext, { url, codec, id, data, contentType, capability, precondition: callerPrecondition }: {
|
|
166
|
+
url: string;
|
|
167
167
|
codec: ResourceCodec;
|
|
168
168
|
id: string;
|
|
169
169
|
data: ResourceData;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"write.d.ts","sourceRoot":"","sources":["../../src/internal/write.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AACxD,O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