@interop/was-client 0.99.1 → 0.100.1
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 +127 -69
- package/dist/Collection.d.ts +17 -9
- package/dist/Collection.d.ts.map +1 -1
- package/dist/Collection.js +85 -70
- package/dist/Collection.js.map +1 -1
- package/dist/Resource.d.ts +11 -4
- package/dist/Resource.d.ts.map +1 -1
- package/dist/Resource.js +34 -28
- package/dist/Resource.js.map +1 -1
- package/dist/Space.d.ts +20 -5
- package/dist/Space.d.ts.map +1 -1
- package/dist/Space.js +69 -65
- package/dist/Space.js.map +1 -1
- package/dist/WasClient.d.ts +185 -57
- package/dist/WasClient.d.ts.map +1 -1
- package/dist/WasClient.js +340 -140
- 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.js +1 -1
- 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 +1 -1
- package/dist/edv/cipher.js +1 -1
- package/dist/edv/docCipher.d.ts +6 -5
- package/dist/edv/docCipher.d.ts.map +1 -1
- package/dist/edv/docCipher.js +6 -5
- 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/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/index.d.ts +1 -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/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/paths.d.ts +423 -195
- package/dist/internal/paths.d.ts.map +1 -1
- package/dist/internal/paths.js +582 -369
- 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/reserved.d.ts +15 -3
- package/dist/internal/reserved.d.ts.map +1 -1
- package/dist/internal/reserved.js +37 -8
- package/dist/internal/reserved.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 +27 -7
- package/dist/internal/service.d.ts.map +1 -1
- package/dist/internal/service.js +51 -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/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 +3 -3
|
@@ -11,16 +11,34 @@
|
|
|
11
11
|
* client-side `ValidationError`-throwing guard and the two membership
|
|
12
12
|
* predicates the path grammar asks with.
|
|
13
13
|
*/
|
|
14
|
-
import { RESERVED_COLLECTION_IDS, RESERVED_RESOURCE_IDS } from '@interop/storage-core';
|
|
14
|
+
import { ORIGIN_ROOT_RESERVED_COLLECTION_IDS, RESERVED_COLLECTION_IDS, RESERVED_RESOURCE_IDS } from '@interop/storage-core';
|
|
15
15
|
import { ValidationError } from '../errors.js';
|
|
16
16
|
/**
|
|
17
|
-
* Whether `id` is a reserved Collection-id path segment.
|
|
17
|
+
* Whether `id` is a reserved Collection-id path segment. At a Space served
|
|
18
|
+
* from an origin root the Collection id is the first path segment, where a
|
|
19
|
+
* server with a base server URL places its server-level endpoints, so the
|
|
20
|
+
* spec reserves those segments there too (and only there).
|
|
21
|
+
*
|
|
22
|
+
* @param id {string}
|
|
23
|
+
* @param options {object}
|
|
24
|
+
* @param [options.originRoot] {boolean} whether the Space is served from an
|
|
25
|
+
* origin root
|
|
26
|
+
* @returns {boolean}
|
|
27
|
+
*/
|
|
28
|
+
export function isReservedCollectionId(id, { originRoot = false } = {}) {
|
|
29
|
+
return (RESERVED_COLLECTION_IDS.has(id) ||
|
|
30
|
+
(originRoot && isOriginRootReservedCollectionId(id)));
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Whether `id` is one of the server-level endpoint segments (`service`,
|
|
34
|
+
* `spaces`, `space`), reserved as a Collection id only at a Space served
|
|
35
|
+
* from an origin root.
|
|
18
36
|
*
|
|
19
37
|
* @param id {string}
|
|
20
38
|
* @returns {boolean}
|
|
21
39
|
*/
|
|
22
|
-
|
|
23
|
-
return
|
|
40
|
+
function isOriginRootReservedCollectionId(id) {
|
|
41
|
+
return ORIGIN_ROOT_RESERVED_COLLECTION_IDS.has(id);
|
|
24
42
|
}
|
|
25
43
|
/**
|
|
26
44
|
* Whether `id` is a reserved Resource-id path segment.
|
|
@@ -39,12 +57,23 @@ export function isReservedResourceId(id) {
|
|
|
39
57
|
* @param options.id {string} the proposed collection or resource id
|
|
40
58
|
* @param options.kind {string} 'collection' or 'resource', selects the
|
|
41
59
|
* reserved set and is used in the message
|
|
60
|
+
* @param [options.originRoot] {boolean} whether the Space is served from an
|
|
61
|
+
* origin root, where the server-level endpoint segments are reserved as
|
|
62
|
+
* Collection ids too
|
|
42
63
|
* @returns {void}
|
|
43
64
|
*/
|
|
44
|
-
export function assertNotReserved({ id, kind }) {
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
65
|
+
export function assertNotReserved({ id, kind, originRoot = false }) {
|
|
66
|
+
const reserved = kind === 'collection'
|
|
67
|
+
? isReservedCollectionId(id, { originRoot })
|
|
68
|
+
: isReservedResourceId(id);
|
|
69
|
+
if (!reserved) {
|
|
70
|
+
return;
|
|
48
71
|
}
|
|
72
|
+
// The origin-root-only ids are reserved for a reason the plain message
|
|
73
|
+
// would not convey.
|
|
74
|
+
const where = RESERVED_COLLECTION_IDS.has(id) || kind === 'resource'
|
|
75
|
+
? ''
|
|
76
|
+
: ' at a Space served from an origin root';
|
|
77
|
+
throw new ValidationError(`Cannot use reserved path segment "${id}" as a ${kind} id${where}.`);
|
|
49
78
|
}
|
|
50
79
|
//# sourceMappingURL=reserved.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reserved.js","sourceRoot":"","sources":["../../src/internal/reserved.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH;;;;;;;;;GASG;AACH,OAAO,EACL,uBAAuB,EACvB,qBAAqB,EACtB,MAAM,uBAAuB,CAAA;AAE9B,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAE9C
|
|
1
|
+
{"version":3,"file":"reserved.js","sourceRoot":"","sources":["../../src/internal/reserved.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH;;;;;;;;;GASG;AACH,OAAO,EACL,mCAAmC,EACnC,uBAAuB,EACvB,qBAAqB,EACtB,MAAM,uBAAuB,CAAA;AAE9B,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAE9C;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,sBAAsB,CACpC,EAAU,EACV,EAAE,UAAU,GAAG,KAAK,KAA+B,EAAE;IAErD,OAAO,CACL,uBAAuB,CAAC,GAAG,CAAC,EAAE,CAAC;QAC/B,CAAC,UAAU,IAAI,gCAAgC,CAAC,EAAE,CAAC,CAAC,CACrD,CAAA;AACH,CAAC;AAED;;;;;;;GAOG;AACH,SAAS,gCAAgC,CAAC,EAAU;IAClD,OAAO,mCAAmC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;AACpD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,oBAAoB,CAAC,EAAU;IAC7C,OAAO,qBAAqB,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;AACtC,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,iBAAiB,CAAC,EAChC,EAAE,EACF,IAAI,EACJ,UAAU,GAAG,KAAK,EAKnB;IACC,MAAM,QAAQ,GACZ,IAAI,KAAK,YAAY;QACnB,CAAC,CAAC,sBAAsB,CAAC,EAAE,EAAE,EAAE,UAAU,EAAE,CAAC;QAC5C,CAAC,CAAC,oBAAoB,CAAC,EAAE,CAAC,CAAA;IAC9B,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,OAAM;IACR,CAAC;IACD,uEAAuE;IACvE,oBAAoB;IACpB,MAAM,KAAK,GACT,uBAAuB,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,IAAI,KAAK,UAAU;QACpD,CAAC,CAAC,EAAE;QACJ,CAAC,CAAC,wCAAwC,CAAA;IAC9C,MAAM,IAAI,eAAe,CACvB,qCAAqC,EAAE,UAAU,IAAI,MAAM,KAAK,GAAG,CACpE,CAAA;AACH,CAAC"}
|
|
@@ -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,K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AG,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAAA;IACzE,IAAI,MAAM,KAAK,IAAI,EAAE,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,37 @@ 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 any 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. The route for a
|
|
64
|
+
* client that holds no base server URL, such as one opened on a single fixed
|
|
65
|
+
* Space.
|
|
46
66
|
*
|
|
47
67
|
* A network failure, and a rate limit or temporary outage (429, 502, 503,
|
|
48
68
|
* 504) that comes without the link, reject with the mapped transport error,
|
|
49
69
|
* since they say nothing about the protocol the server speaks.
|
|
50
70
|
*
|
|
51
71
|
* @param options {object}
|
|
52
|
-
* @param options.url {string} any WAS
|
|
53
|
-
*
|
|
72
|
+
* @param options.url {string} any URL the WAS server answers, typically a
|
|
73
|
+
* Space URL
|
|
54
74
|
* @returns {Promise<ServiceInfo>}
|
|
55
75
|
* @throws {IncompatibleServerError} when the response carries no `service`
|
|
56
76
|
* 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":"AAsBA,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;;;;;;;;;;;;;;;;;;;GAmBG;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,41 @@ export async function discoverService({ url }) {
|
|
|
257
226
|
}
|
|
258
227
|
return selectServiceVersion(description);
|
|
259
228
|
}
|
|
229
|
+
/**
|
|
230
|
+
* Discovers the service description from any 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. The route for a
|
|
234
|
+
* client that holds no base server URL, such as one opened on a single fixed
|
|
235
|
+
* Space.
|
|
236
|
+
*
|
|
237
|
+
* A network failure, and a rate limit or temporary outage (429, 502, 503,
|
|
238
|
+
* 504) that comes without the link, reject with the mapped transport error,
|
|
239
|
+
* since they say nothing about the protocol the server speaks.
|
|
240
|
+
*
|
|
241
|
+
* @param options {object}
|
|
242
|
+
* @param options.url {string} any URL the WAS server answers, typically a
|
|
243
|
+
* Space URL
|
|
244
|
+
* @returns {Promise<ServiceInfo>}
|
|
245
|
+
* @throws {IncompatibleServerError} when the response carries no `service`
|
|
246
|
+
* link, the linked document cannot be read or parsed, or version selection
|
|
247
|
+
* refuses it (see {@link selectServiceVersion})
|
|
248
|
+
*/
|
|
249
|
+
export async function discoverService({ url }) {
|
|
250
|
+
const probe = await fetchMapped(url, { method: 'HEAD' });
|
|
251
|
+
const serviceUrl = serviceLinkTarget({
|
|
252
|
+
header: probe.headers.get('link'),
|
|
253
|
+
baseUrl: probe.url || url
|
|
254
|
+
});
|
|
255
|
+
if (serviceUrl === undefined) {
|
|
256
|
+
refuse({
|
|
257
|
+
status: probe.status,
|
|
258
|
+
requestUrl: url,
|
|
259
|
+
message: `The response from "${url}" (${probe.status}) carries no ` +
|
|
260
|
+
'rel="service" link, so the server predates WAS v0.5, which this ' +
|
|
261
|
+
'client requires.'
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
return readServiceDescription({ serviceUrl });
|
|
265
|
+
}
|
|
260
266
|
//# sourceMappingURL=service.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.js","sourceRoot":"","sources":["../../src/internal/service.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAE,uBAAuB,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AAChE,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,GAA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