@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
package/dist/internal/paths.js
CHANGED
|
@@ -2,36 +2,37 @@
|
|
|
2
2
|
* Copyright (c) 2026 Interop Alliance. All rights reserved.
|
|
3
3
|
*/
|
|
4
4
|
/**
|
|
5
|
-
* URL
|
|
6
|
-
* canonicalization once.
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
5
|
+
* URL builders for the hierarchy beneath a Space, encoding the trailing-slash
|
|
6
|
+
* canonicalization once. Every URL this client requests is derived from a
|
|
7
|
+
* Space URL the server handed out (the `Location` of the create response, a
|
|
8
|
+
* listing item, a linkset, or the caller's stored pointer) and from nothing
|
|
9
|
+
* above it: the spec places no Space beside the Spaces Repository, so no
|
|
10
|
+
* builder here forms a Space URL, and none takes a server root. The Spaces
|
|
11
|
+
* Repository URL is the `spaces` member of the service description.
|
|
12
|
+
*
|
|
13
|
+
* The convention: a trailing slash marks a container in canonical form (the
|
|
14
|
+
* Space URL itself, and `{spaceUrl}{collectionId}/`), everything else has
|
|
15
|
+
* none, and no two URLs differ only by a trailing slash. Path segments are
|
|
16
|
+
* percent-encoded so ids never break out of their slot.
|
|
11
17
|
*
|
|
12
18
|
* A container's own description is not at its URL: it lives at the reserved
|
|
13
|
-
* `meta` segment (`
|
|
14
|
-
* `
|
|
15
|
-
* 308-redirects, and a signed invocation covers the target it was
|
|
16
|
-
* so no builder here emits the bare form -- a redirect would have
|
|
17
|
-
* again.
|
|
18
|
-
*
|
|
19
|
-
* The parser is deliberately laxer than the builders. `
|
|
20
|
-
* the bare form too, because the targets it classifies are
|
|
21
|
-
* own URLs: they are the `invocationTarget` strings of
|
|
22
|
-
* a third party minted, and those name containers in
|
|
23
|
-
* as the
|
|
24
|
-
*
|
|
25
|
-
*
|
|
19
|
+
* `meta` segment (`spaceMetaUrl`, `collectionMetaUrl`), beside the
|
|
20
|
+
* Resource-level `resourceMetaUrl`. The bare (slash-less) form of a container
|
|
21
|
+
* URL only 308-redirects, and a signed invocation covers the target it was
|
|
22
|
+
* signed for, so no builder here emits the bare form -- a redirect would have
|
|
23
|
+
* to be signed again.
|
|
24
|
+
*
|
|
25
|
+
* The parser is deliberately laxer than the builders. `parseSpaceTarget`
|
|
26
|
+
* accepts the bare container form too, because the targets it classifies are
|
|
27
|
+
* not this client's own URLs: they are the `invocationTarget` strings of
|
|
28
|
+
* delegated capabilities a third party minted, and those name containers in
|
|
29
|
+
* either form. Reading one as the Collection or Resource it addresses is what
|
|
30
|
+
* `WasClient.fromCapability` does; refusing the bare form there would reject
|
|
31
|
+
* valid capabilities over a form this client does not control.
|
|
26
32
|
*
|
|
27
33
|
* The zcap `invocationTarget` is derived from the request URL, so these
|
|
28
34
|
* trailing-slash rules must match the server's per-operation `allowedTarget`
|
|
29
35
|
* exactly or signature verification fails.
|
|
30
|
-
*
|
|
31
|
-
* This module also owns the inverse grammar: `parseSpacePath` classifies a
|
|
32
|
-
* server pathname back into the handle depth it addresses (space / collection /
|
|
33
|
-
* resource / sub-resource), so `WasClient.fromCapability` and the builders stay
|
|
34
|
-
* in lockstep.
|
|
35
36
|
*/
|
|
36
37
|
import { ValidationError } from '../errors.js';
|
|
37
38
|
import { assertNotReserved, isReservedCollectionId, isReservedResourceId } from './reserved.js';
|
|
@@ -58,10 +59,10 @@ function encode(segment) {
|
|
|
58
59
|
}
|
|
59
60
|
/**
|
|
60
61
|
* Encodes a collection-id slot, additionally rejecting an id from the Reserved
|
|
61
|
-
* Path Segment Registry: `
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
62
|
+
* Path Segment Registry: `collectionUrl` of `policy` is byte-identical to the
|
|
63
|
+
* space policy URL, so a reserved id would silently mis-target a space-level
|
|
64
|
+
* endpoint. Guarding in the builders covers every URL-forming entry point
|
|
65
|
+
* (handle constructors guard too, for the earlier failure).
|
|
65
66
|
*
|
|
66
67
|
* @param collectionId {string}
|
|
67
68
|
* @returns {string}
|
|
@@ -72,8 +73,8 @@ function encodeCollectionId(collectionId) {
|
|
|
72
73
|
}
|
|
73
74
|
/**
|
|
74
75
|
* Encodes a resource-id slot, additionally rejecting an id from the Reserved
|
|
75
|
-
* Path Segment Registry: `
|
|
76
|
-
*
|
|
76
|
+
* Path Segment Registry: `resourceUrl` of `policy` is byte-identical to the
|
|
77
|
+
* collection policy URL, so a reserved id would silently mis-target a
|
|
77
78
|
* collection-level endpoint.
|
|
78
79
|
*
|
|
79
80
|
* @param resourceId {string}
|
|
@@ -84,500 +85,532 @@ function encodeResourceId(resourceId) {
|
|
|
84
85
|
return encode(resourceId);
|
|
85
86
|
}
|
|
86
87
|
/**
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
* builder's return value. It is still a form the parser below reads, since a
|
|
91
|
-
* third party's capability target may be written that way.
|
|
88
|
+
* Parses an absolute `http(s)` URL, or returns `null`. The one rule for which
|
|
89
|
+
* URLs may name a server, a Spaces Repository, or a container here; the
|
|
90
|
+
* callers that need more (no query, a path) narrow it.
|
|
92
91
|
*
|
|
93
|
-
* @param
|
|
92
|
+
* @param url {string}
|
|
93
|
+
* @returns {URL | null}
|
|
94
|
+
*/
|
|
95
|
+
export function parseAbsoluteHttpUrl(url) {
|
|
96
|
+
let parsed;
|
|
97
|
+
try {
|
|
98
|
+
parsed = new URL(url);
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
if (parsed.protocol !== 'https:' && parsed.protocol !== 'http:') {
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
return parsed;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* {@link parseAbsoluteHttpUrl} narrowed to a URL with no query or fragment:
|
|
110
|
+
* the rule for which URLs may name a container.
|
|
111
|
+
*
|
|
112
|
+
* @param url {string}
|
|
113
|
+
* @returns {URL | null}
|
|
114
|
+
*/
|
|
115
|
+
function parseContainerUrl(url) {
|
|
116
|
+
const parsed = parseAbsoluteHttpUrl(url);
|
|
117
|
+
if (parsed === null || parsed.search !== '' || parsed.hash !== '') {
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
return parsed;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* The Space URL in canonical form: an absolute `http(s)` URL, serialized by
|
|
124
|
+
* `URL` (lower-case host, default port dropped), ending in exactly one
|
|
125
|
+
* slash. A server names a Space in this form (the `Location` of the create
|
|
126
|
+
* response, a listing item's `url`), and every URL beneath the Space, and
|
|
127
|
+
* every zcap `invocationTarget`, is derived from it, so a caller's own
|
|
128
|
+
* serialization of the same Space must reduce to the same string. A missing
|
|
129
|
+
* trailing slash is added, since the bare form names the same container; a
|
|
130
|
+
* run of trailing slashes is collapsed to one.
|
|
131
|
+
*
|
|
132
|
+
* @param spaceUrl {string} a Space URL, as the server named it or as the
|
|
133
|
+
* caller stored it
|
|
134
|
+
* @returns {string}
|
|
135
|
+
* @throws {ValidationError} when `spaceUrl` is not an absolute `http(s)`
|
|
136
|
+
* URL, carries a query or fragment, or has no path segment (an origin is
|
|
137
|
+
* not a Space)
|
|
138
|
+
*/
|
|
139
|
+
export function canonicalSpaceUrl(spaceUrl) {
|
|
140
|
+
const parsed = parseContainerUrl(spaceUrl);
|
|
141
|
+
if (parsed === null) {
|
|
142
|
+
throw new ValidationError(`"${spaceUrl}" is not a Space URL: an absolute http(s) URL with no ` +
|
|
143
|
+
'query or fragment is required.');
|
|
144
|
+
}
|
|
145
|
+
const pathname = parsed.pathname.replace(/\/+$/, '');
|
|
146
|
+
if (pathname === '' || pathname.split('/').slice(1).includes('')) {
|
|
147
|
+
throw new ValidationError(`"${spaceUrl}" is not a Space URL: a Space has at least one path ` +
|
|
148
|
+
'segment beneath its origin, with no empty segment.');
|
|
149
|
+
}
|
|
150
|
+
return `${parsed.origin}${pathname}/`;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* The Space's id as its URL names it: the last path segment of the Space
|
|
154
|
+
* URL, percent-decoded. The spec's hierarchy and its did:webvh profile both
|
|
155
|
+
* place the id there (`.../space/{space_id}/`), and it is the value the Space
|
|
156
|
+
* Metadata object's `id` carries.
|
|
157
|
+
*
|
|
158
|
+
* @param spaceUrl {string} a Space URL
|
|
94
159
|
* @returns {string}
|
|
160
|
+
* @throws {ValidationError} when `spaceUrl` is not a Space URL (see
|
|
161
|
+
* {@link canonicalSpaceUrl}) or its last segment is a malformed percent
|
|
162
|
+
* escape
|
|
95
163
|
*/
|
|
96
|
-
function
|
|
97
|
-
return
|
|
164
|
+
export function spaceIdOfUrl(spaceUrl) {
|
|
165
|
+
return spaceIdOfCanonicalUrl(canonicalSpaceUrl(spaceUrl));
|
|
98
166
|
}
|
|
99
167
|
/**
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
* Collections, whose `POST` creates one, and whose `DELETE` removes the Space.
|
|
103
|
-
* The Space is an ordinary container, so its members are listed and created at
|
|
104
|
-
* the container itself -- there is no second builder for that.
|
|
168
|
+
* {@link spaceIdOfUrl} for a Space URL already in canonical form (a handle's
|
|
169
|
+
* `url`, the result of {@link canonicalSpaceUrl}), sparing the second parse.
|
|
105
170
|
*
|
|
106
|
-
* @param
|
|
171
|
+
* @param canonical {string} a canonical Space URL
|
|
107
172
|
* @returns {string}
|
|
173
|
+
* @throws {ValidationError} when the last segment is a malformed percent
|
|
174
|
+
* escape
|
|
108
175
|
*/
|
|
109
|
-
export function
|
|
110
|
-
|
|
176
|
+
export function spaceIdOfCanonicalUrl(canonical) {
|
|
177
|
+
const segment = canonical.split('/').filter(Boolean).pop();
|
|
178
|
+
try {
|
|
179
|
+
return decodeURIComponent(segment);
|
|
180
|
+
}
|
|
181
|
+
catch (err) {
|
|
182
|
+
throw new ValidationError(`"${canonical}" is not a Space URL: its last segment is not a ` +
|
|
183
|
+
'well-formed percent-encoded id.', { cause: err });
|
|
184
|
+
}
|
|
111
185
|
}
|
|
112
186
|
/**
|
|
113
|
-
*
|
|
187
|
+
* `{spaceUrl}meta` -- the Space Metadata object: the Space's description
|
|
114
188
|
* (`name`, `controller`, `type`), read with `GET` and replaced with `PUT`.
|
|
189
|
+
* The Space container itself (the canonical Space URL) is the target a Space
|
|
190
|
+
* root capability names, the URL whose `GET` lists the Space's Collections,
|
|
191
|
+
* whose `POST` creates one, and whose `DELETE` removes the Space; it has no
|
|
192
|
+
* builder, since the caller holds it.
|
|
115
193
|
*
|
|
116
|
-
* @param
|
|
194
|
+
* @param options {object}
|
|
195
|
+
* @param options.spaceUrl {string}
|
|
117
196
|
* @returns {string}
|
|
118
197
|
*/
|
|
119
|
-
export function
|
|
120
|
-
return `${
|
|
198
|
+
export function spaceMetaUrl({ spaceUrl }) {
|
|
199
|
+
return `${canonicalSpaceUrl(spaceUrl)}meta`;
|
|
121
200
|
}
|
|
122
201
|
/**
|
|
123
|
-
*
|
|
202
|
+
* `{spaceUrl}export` -- export a space as a tar archive.
|
|
203
|
+
*
|
|
204
|
+
* @param options {object}
|
|
205
|
+
* @param options.spaceUrl {string}
|
|
206
|
+
* @returns {string}
|
|
124
207
|
*/
|
|
125
|
-
export function
|
|
126
|
-
return `${
|
|
208
|
+
export function spaceExportUrl({ spaceUrl }) {
|
|
209
|
+
return `${canonicalSpaceUrl(spaceUrl)}export`;
|
|
127
210
|
}
|
|
128
211
|
/**
|
|
129
|
-
*
|
|
212
|
+
* `{spaceUrl}import` -- import a tar archive into a space.
|
|
213
|
+
*
|
|
214
|
+
* @param options {object}
|
|
215
|
+
* @param options.spaceUrl {string}
|
|
216
|
+
* @returns {string}
|
|
130
217
|
*/
|
|
131
|
-
export function
|
|
132
|
-
return `${
|
|
218
|
+
export function spaceImportUrl({ spaceUrl }) {
|
|
219
|
+
return `${canonicalSpaceUrl(spaceUrl)}import`;
|
|
133
220
|
}
|
|
134
221
|
/**
|
|
135
|
-
*
|
|
222
|
+
* `{spaceUrl}backends` -- the backends available within a space (list, and
|
|
136
223
|
* register a new `external` backend).
|
|
224
|
+
*
|
|
225
|
+
* @param options {object}
|
|
226
|
+
* @param options.spaceUrl {string}
|
|
227
|
+
* @returns {string}
|
|
137
228
|
*/
|
|
138
|
-
export function
|
|
139
|
-
return `${
|
|
229
|
+
export function spaceBackendsUrl({ spaceUrl }) {
|
|
230
|
+
return `${canonicalSpaceUrl(spaceUrl)}backends`;
|
|
140
231
|
}
|
|
141
232
|
/**
|
|
142
|
-
*
|
|
143
|
-
*
|
|
233
|
+
* `{spaceUrl}backends/{backendId}` -- a single registered `external` backend
|
|
234
|
+
* (replace / deregister by id).
|
|
235
|
+
*
|
|
236
|
+
* @param options {object}
|
|
237
|
+
* @param options.spaceUrl {string}
|
|
238
|
+
* @param options.backendId {string}
|
|
239
|
+
* @returns {string}
|
|
144
240
|
*/
|
|
145
|
-
export function
|
|
146
|
-
return `${
|
|
241
|
+
export function registeredBackendUrl({ spaceUrl, backendId }) {
|
|
242
|
+
return `${spaceBackendsUrl({ spaceUrl })}/${encode(backendId)}`;
|
|
147
243
|
}
|
|
148
244
|
/**
|
|
149
|
-
*
|
|
245
|
+
* `{spaceUrl}quotas` -- the space-level storage quota report.
|
|
246
|
+
*
|
|
247
|
+
* @param options {object}
|
|
248
|
+
* @param options.spaceUrl {string}
|
|
249
|
+
* @returns {string}
|
|
150
250
|
*/
|
|
151
|
-
export function
|
|
152
|
-
return `${
|
|
251
|
+
export function spaceQuotasUrl({ spaceUrl }) {
|
|
252
|
+
return `${canonicalSpaceUrl(spaceUrl)}quotas`;
|
|
153
253
|
}
|
|
154
254
|
/**
|
|
155
|
-
*
|
|
255
|
+
* `{spaceUrl}policy` -- the space-level access-control policy resource.
|
|
256
|
+
*
|
|
257
|
+
* @param options {object}
|
|
258
|
+
* @param options.spaceUrl {string}
|
|
259
|
+
* @returns {string}
|
|
156
260
|
*/
|
|
157
|
-
export function
|
|
158
|
-
return `${
|
|
261
|
+
export function spacePolicyUrl({ spaceUrl }) {
|
|
262
|
+
return `${canonicalSpaceUrl(spaceUrl)}policy`;
|
|
159
263
|
}
|
|
160
264
|
/**
|
|
161
|
-
*
|
|
265
|
+
* `{spaceUrl}linkset` -- the space-level linkset (policy discovery).
|
|
266
|
+
*
|
|
267
|
+
* @param options {object}
|
|
268
|
+
* @param options.spaceUrl {string}
|
|
269
|
+
* @returns {string}
|
|
162
270
|
*/
|
|
163
|
-
export function
|
|
164
|
-
return `${
|
|
271
|
+
export function spaceLinksetUrl({ spaceUrl }) {
|
|
272
|
+
return `${canonicalSpaceUrl(spaceUrl)}linkset`;
|
|
165
273
|
}
|
|
166
274
|
/**
|
|
167
|
-
*
|
|
168
|
-
*
|
|
275
|
+
* `{spaceUrl}replicas` -- the Space's replica registrations: `GET` lists them
|
|
276
|
+
* and `POST` registers one. Controller-only, both forms.
|
|
277
|
+
*
|
|
278
|
+
* @param options {object}
|
|
279
|
+
* @param options.spaceUrl {string}
|
|
280
|
+
* @returns {string}
|
|
169
281
|
*/
|
|
170
|
-
export function
|
|
171
|
-
return `${
|
|
282
|
+
export function spaceReplicasUrl({ spaceUrl }) {
|
|
283
|
+
return `${canonicalSpaceUrl(spaceUrl)}replicas`;
|
|
172
284
|
}
|
|
173
285
|
/**
|
|
174
|
-
*
|
|
286
|
+
* `{spaceUrl}replicas/{replicaId}` -- one replica registration (read and
|
|
175
287
|
* delete by id).
|
|
288
|
+
*
|
|
289
|
+
* @param options {object}
|
|
290
|
+
* @param options.spaceUrl {string}
|
|
291
|
+
* @param options.replicaId {string}
|
|
292
|
+
* @returns {string}
|
|
176
293
|
*/
|
|
177
|
-
export function
|
|
178
|
-
return `${
|
|
294
|
+
export function replicaRegistrationUrl({ spaceUrl, replicaId }) {
|
|
295
|
+
return `${spaceReplicasUrl({ spaceUrl })}/${encode(replicaId)}`;
|
|
179
296
|
}
|
|
180
297
|
/**
|
|
181
|
-
*
|
|
182
|
-
*
|
|
298
|
+
* `{spaceUrl}replicas/{replicaId}/status` -- the pull loop's runtime state
|
|
299
|
+
* for one registration.
|
|
300
|
+
*
|
|
301
|
+
* @param options {object}
|
|
302
|
+
* @param options.spaceUrl {string}
|
|
303
|
+
* @param options.replicaId {string}
|
|
304
|
+
* @returns {string}
|
|
183
305
|
*/
|
|
184
|
-
export function
|
|
185
|
-
return `${
|
|
306
|
+
export function replicaStatusUrl({ spaceUrl, replicaId }) {
|
|
307
|
+
return `${replicaRegistrationUrl({ spaceUrl, replicaId })}/status`;
|
|
186
308
|
}
|
|
187
309
|
/**
|
|
188
|
-
*
|
|
310
|
+
* `{spaceUrl}zcaps/revocations/{capabilityId}` -- submit a revocation of a
|
|
189
311
|
* Space-rooted capability. The capability's `id` (typically a `urn:uuid:`) is
|
|
190
312
|
* percent-encoded into the single final segment. `zcaps` is in the Reserved
|
|
191
313
|
* Path Segment Registry, so no Collection can take that slot.
|
|
314
|
+
*
|
|
315
|
+
* @param options {object}
|
|
316
|
+
* @param options.spaceUrl {string}
|
|
317
|
+
* @param options.capabilityId {string}
|
|
318
|
+
* @returns {string}
|
|
192
319
|
*/
|
|
193
|
-
export function
|
|
194
|
-
return `${
|
|
320
|
+
export function spaceRevocationUrl({ spaceUrl, capabilityId }) {
|
|
321
|
+
return `${canonicalSpaceUrl(spaceUrl)}zcaps/revocations/${encode(capabilityId)}`;
|
|
195
322
|
}
|
|
196
323
|
/**
|
|
197
|
-
*
|
|
198
|
-
* sub-endpoints and the Resource ids hang off. Module-private
|
|
199
|
-
*
|
|
324
|
+
* `{spaceUrl}{collectionId}` -- the slash-less prefix the collection-level
|
|
325
|
+
* sub-endpoints and the Resource ids hang off. Module-private: the bare form
|
|
326
|
+
* is not a URL this client ever requests (the server only 308-redirects it),
|
|
327
|
+
* so it is a prefix here and never a builder's return value.
|
|
200
328
|
*
|
|
201
|
-
* @param
|
|
202
|
-
* @param
|
|
329
|
+
* @param options {object}
|
|
330
|
+
* @param options.spaceUrl {string}
|
|
331
|
+
* @param options.collectionId {string}
|
|
203
332
|
* @returns {string}
|
|
204
333
|
*/
|
|
205
|
-
function collectionPrefix(
|
|
206
|
-
return `${
|
|
334
|
+
function collectionPrefix({ spaceUrl, collectionId }) {
|
|
335
|
+
return `${canonicalSpaceUrl(spaceUrl)}${encodeCollectionId(collectionId)}`;
|
|
207
336
|
}
|
|
208
337
|
/**
|
|
209
|
-
*
|
|
210
|
-
*
|
|
211
|
-
*
|
|
212
|
-
*
|
|
338
|
+
* `{spaceUrl}{collectionId}/` -- the Collection container in canonical form:
|
|
339
|
+
* the target a "share this collection" capability names, the URL whose `GET`
|
|
340
|
+
* lists its Resources, whose `POST` adds one, and whose `DELETE` removes the
|
|
341
|
+
* Collection.
|
|
213
342
|
*
|
|
214
|
-
* @param
|
|
215
|
-
* @param
|
|
343
|
+
* @param options {object}
|
|
344
|
+
* @param options.spaceUrl {string}
|
|
345
|
+
* @param options.collectionId {string}
|
|
216
346
|
* @returns {string}
|
|
217
347
|
*/
|
|
218
|
-
export function
|
|
219
|
-
return `${collectionPrefix(
|
|
348
|
+
export function collectionUrl({ spaceUrl, collectionId }) {
|
|
349
|
+
return `${collectionPrefix({ spaceUrl, collectionId })}/`;
|
|
220
350
|
}
|
|
221
351
|
/**
|
|
222
|
-
*
|
|
352
|
+
* `{spaceUrl}{collectionId}/policy` -- the collection-level access-control
|
|
223
353
|
* policy resource.
|
|
354
|
+
*
|
|
355
|
+
* @param options {object}
|
|
356
|
+
* @param options.spaceUrl {string}
|
|
357
|
+
* @param options.collectionId {string}
|
|
358
|
+
* @returns {string}
|
|
224
359
|
*/
|
|
225
|
-
export function
|
|
226
|
-
return `${collectionPrefix(
|
|
360
|
+
export function collectionPolicyUrl({ spaceUrl, collectionId }) {
|
|
361
|
+
return `${collectionPrefix({ spaceUrl, collectionId })}/policy`;
|
|
227
362
|
}
|
|
228
363
|
/**
|
|
229
|
-
*
|
|
230
|
-
*
|
|
364
|
+
* `{spaceUrl}{collectionId}/linkset` -- the collection-level linkset (policy
|
|
365
|
+
* discovery).
|
|
366
|
+
*
|
|
367
|
+
* @param options {object}
|
|
368
|
+
* @param options.spaceUrl {string}
|
|
369
|
+
* @param options.collectionId {string}
|
|
370
|
+
* @returns {string}
|
|
231
371
|
*/
|
|
232
|
-
export function
|
|
233
|
-
return `${collectionPrefix(
|
|
372
|
+
export function collectionLinksetUrl({ spaceUrl, collectionId }) {
|
|
373
|
+
return `${collectionPrefix({ spaceUrl, collectionId })}/linkset`;
|
|
234
374
|
}
|
|
235
375
|
/**
|
|
236
|
-
*
|
|
376
|
+
* `{spaceUrl}{collectionId}/backend` -- the "Collection Backend Selected"
|
|
237
377
|
* descriptor (the backend this collection is stored on).
|
|
378
|
+
*
|
|
379
|
+
* @param options {object}
|
|
380
|
+
* @param options.spaceUrl {string}
|
|
381
|
+
* @param options.collectionId {string}
|
|
382
|
+
* @returns {string}
|
|
238
383
|
*/
|
|
239
|
-
export function
|
|
240
|
-
return `${collectionPrefix(
|
|
384
|
+
export function collectionBackendUrl({ spaceUrl, collectionId }) {
|
|
385
|
+
return `${collectionPrefix({ spaceUrl, collectionId })}/backend`;
|
|
241
386
|
}
|
|
242
387
|
/**
|
|
243
|
-
*
|
|
244
|
-
*
|
|
388
|
+
* `{spaceUrl}{collectionId}/quota` -- the per-collection storage quota report
|
|
389
|
+
* (spec "Quotas").
|
|
390
|
+
*
|
|
391
|
+
* @param options {object}
|
|
392
|
+
* @param options.spaceUrl {string}
|
|
393
|
+
* @param options.collectionId {string}
|
|
394
|
+
* @returns {string}
|
|
245
395
|
*/
|
|
246
|
-
export function
|
|
247
|
-
return `${collectionPrefix(
|
|
396
|
+
export function collectionQuotaUrl({ spaceUrl, collectionId }) {
|
|
397
|
+
return `${collectionPrefix({ spaceUrl, collectionId })}/quota`;
|
|
248
398
|
}
|
|
249
399
|
/**
|
|
250
|
-
*
|
|
400
|
+
* `{spaceUrl}{collectionId}/meta` -- the Collection Metadata object: the
|
|
251
401
|
* Collection's configuration (`name`, `backend`, `encryption`, `generator`)
|
|
252
402
|
* together with the server-managed timestamps / `createdBy` and the
|
|
253
403
|
* user-writable `custom` and `epoch`, as one object under one validator.
|
|
404
|
+
*
|
|
405
|
+
* @param options {object}
|
|
406
|
+
* @param options.spaceUrl {string}
|
|
407
|
+
* @param options.collectionId {string}
|
|
408
|
+
* @returns {string}
|
|
254
409
|
*/
|
|
255
|
-
export function
|
|
256
|
-
return `${collectionPrefix(
|
|
410
|
+
export function collectionMetaUrl({ spaceUrl, collectionId }) {
|
|
411
|
+
return `${collectionPrefix({ spaceUrl, collectionId })}/meta`;
|
|
257
412
|
}
|
|
258
413
|
/**
|
|
259
|
-
*
|
|
260
|
-
*
|
|
261
|
-
*
|
|
414
|
+
* `{spaceUrl}{collectionId}/meta/log` -- the Collection's governing history
|
|
415
|
+
* log sub-resource (JSON Lines). Not a Resource of the Collection: absent from
|
|
416
|
+
* listings and the `changes` feed, and versioned by its own ETag.
|
|
417
|
+
*
|
|
418
|
+
* @param options {object}
|
|
419
|
+
* @param options.spaceUrl {string}
|
|
420
|
+
* @param options.collectionId {string}
|
|
421
|
+
* @returns {string}
|
|
262
422
|
*/
|
|
263
|
-
export function
|
|
264
|
-
return `${
|
|
423
|
+
export function collectionLogUrl({ spaceUrl, collectionId }) {
|
|
424
|
+
return `${collectionMetaUrl({ spaceUrl, collectionId })}/log`;
|
|
265
425
|
}
|
|
266
426
|
/**
|
|
267
|
-
*
|
|
427
|
+
* `{spaceUrl}{collectionId}/query` -- the collection-level query endpoint,
|
|
268
428
|
* whose body's `profile` selects the query (e.g. `changes`, `blinded-index`).
|
|
429
|
+
*
|
|
430
|
+
* @param options {object}
|
|
431
|
+
* @param options.spaceUrl {string}
|
|
432
|
+
* @param options.collectionId {string}
|
|
433
|
+
* @returns {string}
|
|
269
434
|
*/
|
|
270
|
-
export function
|
|
271
|
-
return `${collectionPrefix(
|
|
435
|
+
export function collectionQueryUrl({ spaceUrl, collectionId }) {
|
|
436
|
+
return `${collectionPrefix({ spaceUrl, collectionId })}/query`;
|
|
272
437
|
}
|
|
273
438
|
/**
|
|
274
|
-
*
|
|
439
|
+
* `{spaceUrl}{collectionId}/{resourceId}` -- get / put / delete a resource
|
|
275
440
|
* (no trailing slash).
|
|
441
|
+
*
|
|
442
|
+
* @param options {object}
|
|
443
|
+
* @param options.spaceUrl {string}
|
|
444
|
+
* @param options.collectionId {string}
|
|
445
|
+
* @param options.resourceId {string}
|
|
446
|
+
* @returns {string}
|
|
276
447
|
*/
|
|
277
|
-
export function
|
|
278
|
-
return `${collectionPrefix(
|
|
448
|
+
export function resourceUrl({ spaceUrl, collectionId, resourceId }) {
|
|
449
|
+
return `${collectionPrefix({ spaceUrl, collectionId })}/${encodeResourceId(resourceId)}`;
|
|
279
450
|
}
|
|
280
451
|
/**
|
|
281
|
-
*
|
|
452
|
+
* `{spaceUrl}{collectionId}/{resourceId}/meta` -- the resource metadata
|
|
282
453
|
* object (server-managed properties plus the user-writable `custom` object).
|
|
283
|
-
*/
|
|
284
|
-
export function resourceMeta(spaceId, collectionId, resourceId) {
|
|
285
|
-
return `${resourcePath(spaceId, collectionId, resourceId)}/meta`;
|
|
286
|
-
}
|
|
287
|
-
/**
|
|
288
|
-
* `/space/:spaceId/:collectionId/:resourceId/policy` -- the resource-level
|
|
289
|
-
* access-control policy resource.
|
|
290
|
-
*/
|
|
291
|
-
export function resourcePolicy(spaceId, collectionId, resourceId) {
|
|
292
|
-
return `${resourcePath(spaceId, collectionId, resourceId)}/policy`;
|
|
293
|
-
}
|
|
294
|
-
/**
|
|
295
|
-
* `/space/:spaceId/:collectionId/:resourceId/chunks/:chunkIndex` -- a single
|
|
296
|
-
* stored chunk of a chunked Resource. Member
|
|
297
|
-
* form, no trailing slash: get / put / delete one chunk by its ordinal index.
|
|
298
|
-
* The `chunkIndex` is a non-negative integer, emitted verbatim (it is never a
|
|
299
|
-
* reserved or dot segment, so it needs no percent-encoding).
|
|
300
454
|
*
|
|
301
|
-
* @param
|
|
302
|
-
* @param
|
|
303
|
-
* @param
|
|
304
|
-
* @param
|
|
455
|
+
* @param options {object}
|
|
456
|
+
* @param options.spaceUrl {string}
|
|
457
|
+
* @param options.collectionId {string}
|
|
458
|
+
* @param options.resourceId {string}
|
|
305
459
|
* @returns {string}
|
|
306
460
|
*/
|
|
307
|
-
export function
|
|
308
|
-
return `${
|
|
461
|
+
export function resourceMetaUrl({ spaceUrl, collectionId, resourceId }) {
|
|
462
|
+
return `${resourceUrl({ spaceUrl, collectionId, resourceId })}/meta`;
|
|
309
463
|
}
|
|
310
464
|
/**
|
|
311
|
-
*
|
|
312
|
-
*
|
|
313
|
-
* slash (the member form, {@link resourceChunkPath}, has none).
|
|
465
|
+
* `{spaceUrl}{collectionId}/{resourceId}/policy` -- the resource-level
|
|
466
|
+
* access-control policy resource.
|
|
314
467
|
*
|
|
315
|
-
* @param
|
|
316
|
-
* @param
|
|
317
|
-
* @param
|
|
468
|
+
* @param options {object}
|
|
469
|
+
* @param options.spaceUrl {string}
|
|
470
|
+
* @param options.collectionId {string}
|
|
471
|
+
* @param options.resourceId {string}
|
|
318
472
|
* @returns {string}
|
|
319
473
|
*/
|
|
320
|
-
export function
|
|
321
|
-
return `${
|
|
474
|
+
export function resourcePolicyUrl({ spaceUrl, collectionId, resourceId }) {
|
|
475
|
+
return `${resourceUrl({ spaceUrl, collectionId, resourceId })}/policy`;
|
|
322
476
|
}
|
|
323
477
|
/**
|
|
324
|
-
*
|
|
325
|
-
*
|
|
326
|
-
*
|
|
327
|
-
*
|
|
328
|
-
*
|
|
478
|
+
* `{spaceUrl}{collectionId}/{resourceId}/chunks/{chunkIndex}` -- a single
|
|
479
|
+
* stored chunk of a chunked Resource. Member form, no trailing slash: get /
|
|
480
|
+
* put / delete one chunk by its ordinal index. The `chunkIndex` is a
|
|
481
|
+
* non-negative integer, emitted verbatim (it is never a reserved or dot
|
|
482
|
+
* segment, so it needs no percent-encoding).
|
|
329
483
|
*
|
|
330
484
|
* @param options {object}
|
|
331
|
-
* @param options.
|
|
485
|
+
* @param options.spaceUrl {string}
|
|
486
|
+
* @param options.collectionId {string}
|
|
487
|
+
* @param options.resourceId {string}
|
|
488
|
+
* @param options.chunkIndex {number}
|
|
332
489
|
* @returns {string}
|
|
333
490
|
*/
|
|
334
|
-
export function
|
|
335
|
-
return
|
|
491
|
+
export function resourceChunkUrl({ spaceUrl, collectionId, resourceId, chunkIndex }) {
|
|
492
|
+
return `${resourceUrl({ spaceUrl, collectionId, resourceId })}/chunks/${chunkIndex}`;
|
|
336
493
|
}
|
|
337
494
|
/**
|
|
338
|
-
*
|
|
339
|
-
*
|
|
340
|
-
*
|
|
341
|
-
* part of the base, or `-1` when there is none. The base is everything before
|
|
342
|
-
* it, without a trailing slash and in `URL` canonical form (lower-case host,
|
|
343
|
-
* default port dropped), so two serializations of one URL compare equal:
|
|
344
|
-
* `https://host/was/x/...` with the index of `x` yields `https://host/was`,
|
|
345
|
-
* and `https://host/x/...` yields `https://host`.
|
|
346
|
-
*
|
|
347
|
-
* This is the one rule for which base URLs are well formed, shared by
|
|
348
|
-
* `baseUrlOfSpacesUrl` and `parseAbsoluteSpaceTarget` so a base read off a
|
|
349
|
-
* Space URL always survives `spacesUrl` and the `WasClient` constructor.
|
|
350
|
-
* Returns `null` when `url` is not an absolute `http(s)` URL, carries a query
|
|
351
|
-
* or fragment, when `boundary` finds no segment, or when a segment before it
|
|
352
|
-
* is empty (`https://host//was/x`): a doubled slash would leave the base with
|
|
353
|
-
* a trailing slash.
|
|
354
|
-
*
|
|
355
|
-
* @param options {object}
|
|
356
|
-
* @param options.url {string} an absolute URL
|
|
357
|
-
* @param options.boundary {(segments: string[]) => number} the index of the
|
|
358
|
-
* first segment beneath the base, or `-1`
|
|
359
|
-
* @returns {{ baseUrl: string; rest: string[] } | null} the base URL and
|
|
360
|
-
* the segments from the boundary on
|
|
361
|
-
*/
|
|
362
|
-
function splitAtBase({ url, boundary }) {
|
|
363
|
-
let parsed;
|
|
364
|
-
try {
|
|
365
|
-
parsed = new URL(url);
|
|
366
|
-
}
|
|
367
|
-
catch {
|
|
368
|
-
return null;
|
|
369
|
-
}
|
|
370
|
-
if ((parsed.protocol !== 'https:' && parsed.protocol !== 'http:') ||
|
|
371
|
-
parsed.search !== '' ||
|
|
372
|
-
parsed.hash !== '') {
|
|
373
|
-
return null;
|
|
374
|
-
}
|
|
375
|
-
const segments = parsed.pathname.split('/').slice(1);
|
|
376
|
-
const index = boundary(segments);
|
|
377
|
-
if (index === -1) {
|
|
378
|
-
return null;
|
|
379
|
-
}
|
|
380
|
-
const basePath = segments.slice(0, index);
|
|
381
|
-
if (basePath.some(segment => segment === '')) {
|
|
382
|
-
return null;
|
|
383
|
-
}
|
|
384
|
-
const baseUrl = basePath.length === 0
|
|
385
|
-
? parsed.origin
|
|
386
|
-
: `${parsed.origin}/${basePath.join('/')}`;
|
|
387
|
-
return { baseUrl, rest: segments.slice(index) };
|
|
388
|
-
}
|
|
389
|
-
/**
|
|
390
|
-
* The server base URL a Spaces Repository URL sits beneath: everything before
|
|
391
|
-
* its final `spaces` segment, without a trailing slash, so
|
|
392
|
-
* `https://host/was/spaces/` yields `https://host/was` and
|
|
393
|
-
* `https://host/spaces/` yields `https://host`. A trailing run of slashes is
|
|
394
|
-
* collapsed first, so `https://host/spaces` and `https://host/spaces//` read
|
|
395
|
-
* the same. The result is in `URL` canonical form (lower-case host, default
|
|
396
|
-
* port dropped), so two serializations of one URL compare equal.
|
|
397
|
-
*
|
|
398
|
-
* Returns `null` when `url` is not an absolute `http(s)` URL, its last path
|
|
399
|
-
* segment is not `spaces`, it has an empty path segment (`https://host//spaces`),
|
|
400
|
-
* or it carries a query or fragment; the caller chooses the error.
|
|
401
|
-
*
|
|
402
|
-
* @param url {string} a Spaces Repository URL
|
|
403
|
-
* @returns {string | null}
|
|
404
|
-
*/
|
|
405
|
-
export function baseUrlOfSpacesUrl(url) {
|
|
406
|
-
const split = splitAtBase({
|
|
407
|
-
url,
|
|
408
|
-
boundary: segments => {
|
|
409
|
-
// Trailing empty segments are the collapsed run of slashes.
|
|
410
|
-
let last = segments.length - 1;
|
|
411
|
-
while (last >= 0 && segments[last] === '') {
|
|
412
|
-
last -= 1;
|
|
413
|
-
}
|
|
414
|
-
return segments[last] === 'spaces' ? last : -1;
|
|
415
|
-
}
|
|
416
|
-
});
|
|
417
|
-
return split?.baseUrl ?? null;
|
|
418
|
-
}
|
|
419
|
-
/**
|
|
420
|
-
* Resolves a path against the server base URL, producing an absolute URL
|
|
421
|
-
* string suitable for zcap `invocationTarget`s.
|
|
422
|
-
*
|
|
423
|
-
* The path is joined onto `baseUrl`'s path rather than its origin, so a WAS
|
|
424
|
-
* deployment mounted under a sub-path (e.g. `https://host/was`) keeps that
|
|
425
|
-
* prefix. A bare-origin `baseUrl` behaves as before.
|
|
495
|
+
* `{spaceUrl}{collectionId}/{resourceId}/chunks/` -- the chunk container of a
|
|
496
|
+
* chunked Resource: its stored chunks, listed. Container form, trailing slash
|
|
497
|
+
* (the member form, {@link resourceChunkUrl}, has none).
|
|
426
498
|
*
|
|
427
499
|
* @param options {object}
|
|
428
|
-
* @param options.
|
|
429
|
-
* @param options.
|
|
500
|
+
* @param options.spaceUrl {string}
|
|
501
|
+
* @param options.collectionId {string}
|
|
502
|
+
* @param options.resourceId {string}
|
|
430
503
|
* @returns {string}
|
|
431
504
|
*/
|
|
432
|
-
export function
|
|
433
|
-
|
|
434
|
-
// any base-path prefix on `baseUrl`. Ensure the base ends in a slash and
|
|
435
|
-
// make the path relative so the prefix is preserved.
|
|
436
|
-
const base = baseUrl.endsWith('/') ? baseUrl : `${baseUrl}/`;
|
|
437
|
-
const relative = path.startsWith('/') ? path.slice(1) : path;
|
|
438
|
-
return new URL(relative, base).toString();
|
|
505
|
+
export function resourceChunksUrl({ spaceUrl, collectionId, resourceId }) {
|
|
506
|
+
return `${resourceUrl({ spaceUrl, collectionId, resourceId })}/chunks/`;
|
|
439
507
|
}
|
|
440
508
|
/**
|
|
441
|
-
*
|
|
442
|
-
*
|
|
443
|
-
*
|
|
444
|
-
*
|
|
509
|
+
* The canonical (trailing-slash) form of a container URL received from
|
|
510
|
+
* outside and requested as given: the Spaces Repository URL a service
|
|
511
|
+
* description advertises, a public Collection link. The bare form only
|
|
512
|
+
* 308-redirects, and a signed invocation does not survive the redirect, so
|
|
513
|
+
* the slash is added here before the URL is ever requested. This module owns
|
|
514
|
+
* the trailing-slash rules; callers normalize here rather than re-encoding
|
|
515
|
+
* the rule.
|
|
445
516
|
*
|
|
446
|
-
* @param
|
|
517
|
+
* @param url {string} an absolute container URL, in either form
|
|
447
518
|
* @returns {string}
|
|
448
519
|
*/
|
|
449
|
-
export function
|
|
450
|
-
|
|
520
|
+
export function canonicalContainerUrl(url) {
|
|
521
|
+
// The slash marks the end of the path, so it goes before any query or
|
|
522
|
+
// fragment; the rest of the URL is kept as given.
|
|
523
|
+
const pathEnd = url.search(/[?#]/);
|
|
524
|
+
const path = pathEnd === -1 ? url : url.slice(0, pathEnd);
|
|
525
|
+
if (path.endsWith('/')) {
|
|
526
|
+
return url;
|
|
527
|
+
}
|
|
528
|
+
return pathEnd === -1 ? `${url}/` : `${path}/${url.slice(pathEnd)}`;
|
|
451
529
|
}
|
|
452
530
|
/**
|
|
453
|
-
* Classifies an absolute `target` URL
|
|
454
|
-
*
|
|
455
|
-
*
|
|
456
|
-
*
|
|
531
|
+
* Classifies an absolute `target` URL by where it sits beneath `spaceUrl`:
|
|
532
|
+
* the Space itself, one of its Collections, a Resource, or a reserved
|
|
533
|
+
* sub-endpoint. The inverse of the builders above, kept next to them so the
|
|
534
|
+
* grammar is owned in one place: `WasClient.fromCapability` reads a
|
|
535
|
+
* capability's `invocationTarget` through it, and the builders stay in
|
|
536
|
+
* lockstep.
|
|
537
|
+
*
|
|
538
|
+
* Both URLs are compared in parsed form, so a target serialized by another
|
|
539
|
+
* party (an upper-case host, a default port) still matches. Segments are
|
|
540
|
+
* percent-decoded (the builders re-encode them). Empty segments are dropped,
|
|
541
|
+
* so a container addressed in either form classifies the same: the bare and
|
|
542
|
+
* the trailing-slash form of a Collection are both the Collection. That is
|
|
543
|
+
* deliberate: the builders emit only the canonical form, but the targets
|
|
544
|
+
* parsed here come from capabilities minted elsewhere, and a client that
|
|
545
|
+
* reads only one form would refuse valid ones.
|
|
457
546
|
*
|
|
458
|
-
* Returns `null` when `target` is not beneath `
|
|
459
|
-
* another
|
|
460
|
-
*
|
|
461
|
-
* an error.
|
|
547
|
+
* Returns `null` when `target` is not beneath `spaceUrl` (another origin, or
|
|
548
|
+
* another path), carries a query or fragment, or either URL is malformed.
|
|
549
|
+
* The caller chooses whether that is an error.
|
|
462
550
|
*
|
|
463
551
|
* @param options {object}
|
|
464
|
-
* @param options.
|
|
465
|
-
* @param options.target {string}
|
|
552
|
+
* @param options.spaceUrl {string} the Space URL
|
|
553
|
+
* @param options.target {string} an absolute URL expected beneath it
|
|
466
554
|
* @returns {ParsedSpacePath | null}
|
|
467
555
|
*/
|
|
468
|
-
export function parseSpaceTarget({
|
|
469
|
-
// Compare the parsed forms, not the strings: `baseUrl` is canonical (the
|
|
470
|
-
// constructor derives it through `URL`) while a target serialized by another
|
|
471
|
-
// party may write the host in upper case or carry a default port.
|
|
472
|
-
let url;
|
|
556
|
+
export function parseSpaceTarget({ spaceUrl, target }) {
|
|
473
557
|
let base;
|
|
474
558
|
try {
|
|
475
|
-
|
|
476
|
-
base = new URL(baseUrl.endsWith('/') ? baseUrl : `${baseUrl}/`);
|
|
559
|
+
base = new URL(canonicalSpaceUrl(spaceUrl));
|
|
477
560
|
}
|
|
478
561
|
catch {
|
|
479
562
|
return null;
|
|
480
563
|
}
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
url.origin !== base.origin ||
|
|
484
|
-
!url.pathname.startsWith(base.pathname)) {
|
|
564
|
+
const url = parseContainerUrl(target);
|
|
565
|
+
if (url === null || url.origin !== base.origin) {
|
|
485
566
|
return null;
|
|
486
567
|
}
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
* the base URL is read off the target itself, as everything before its first
|
|
492
|
-
* `space` path segment, so a WAS mounted under a sub-path
|
|
493
|
-
* (`https://host/was/space/...`) yields `https://host/was`. For a target on a
|
|
494
|
-
* known server, `parseSpaceTarget` is the stricter check (it refuses a target
|
|
495
|
-
* beneath any other base). This is the one for a capability received from
|
|
496
|
-
* another party, whose `invocationTarget` may name any host.
|
|
497
|
-
*
|
|
498
|
-
* Returns `null` when `target` is not an absolute `http(s)` URL, has no
|
|
499
|
-
* `space` segment, carries a query or fragment, or has an empty segment in
|
|
500
|
-
* the base before it (`https://host//was/space/x`); these are the rules
|
|
501
|
-
* `baseUrlOfSpacesUrl` applies too. Also `null` from the path grammar for a
|
|
502
|
-
* path it cannot classify. The caller chooses whether that is an error.
|
|
503
|
-
*
|
|
504
|
-
* @param target {string} an absolute WAS URL
|
|
505
|
-
* @returns {{ baseUrl: string; path: ParsedSpacePath } | null} the server
|
|
506
|
-
* base URL (no trailing slash) and the parsed target beneath it
|
|
507
|
-
*/
|
|
508
|
-
export function parseAbsoluteSpaceTarget(target) {
|
|
509
|
-
const split = splitAtBase({
|
|
510
|
-
url: target,
|
|
511
|
-
boundary: segments => segments.indexOf('space')
|
|
512
|
-
});
|
|
513
|
-
if (split === null) {
|
|
568
|
+
// The bare form of the Space itself (`.../space/s`, no slash) names the
|
|
569
|
+
// Space too, so the prefix check reads the path without its final slash.
|
|
570
|
+
const basePath = base.pathname.slice(0, -1);
|
|
571
|
+
if (url.pathname !== basePath && !url.pathname.startsWith(`${basePath}/`)) {
|
|
514
572
|
return null;
|
|
515
573
|
}
|
|
516
|
-
const path = parseSpacePath(`/${split.rest.join('/')}`);
|
|
517
|
-
return path === null ? null : { baseUrl: split.baseUrl, path };
|
|
518
|
-
}
|
|
519
|
-
/**
|
|
520
|
-
* Parses a server pathname back into the containment depth it addresses -- the
|
|
521
|
-
* inverse of the builders above, kept next to them so the grammar is owned in
|
|
522
|
-
* one place. Segments are percent-decoded (the builders re-encode them).
|
|
523
|
-
* Returns `null` for a pathname outside the `/space/...` tree; the caller
|
|
524
|
-
* chooses the error. A path that addresses a reserved sub-endpoint rather than
|
|
525
|
-
* a space/collection/resource -- e.g. `/space/s/policy`, `/space/s/c/backend`,
|
|
526
|
-
* or any 5-segment target like `/space/s/c/r/meta` -- is classified
|
|
527
|
-
* `sub-resource`, never silently truncated to the nearest handle.
|
|
528
|
-
*
|
|
529
|
-
* Empty segments are dropped, so a container addressed in either form
|
|
530
|
-
* classifies the same: `/space/s` and `/space/s/` are both the Space, and
|
|
531
|
-
* `/space/s/c` and `/space/s/c/` both the Collection. That is deliberate. The
|
|
532
|
-
* builders emit only the canonical trailing-slash form, but the targets parsed
|
|
533
|
-
* here come from capabilities minted elsewhere, and a client that reads only
|
|
534
|
-
* one spelling would refuse valid ones.
|
|
535
|
-
*
|
|
536
|
-
* @param pathname {string} a URL pathname (e.g. from `new URL(...).pathname`)
|
|
537
|
-
* @returns {ParsedSpacePath | null}
|
|
538
|
-
*/
|
|
539
|
-
export function parseSpacePath(pathname) {
|
|
540
574
|
let segments;
|
|
541
575
|
try {
|
|
542
|
-
segments = pathname
|
|
576
|
+
segments = url.pathname
|
|
577
|
+
.slice(basePath.length)
|
|
578
|
+
.split('/')
|
|
579
|
+
.filter(Boolean)
|
|
580
|
+
.map(decodeURIComponent);
|
|
543
581
|
}
|
|
544
582
|
catch {
|
|
545
583
|
// A malformed percent-escape (e.g. `%ff`) makes `decodeURIComponent` throw
|
|
546
|
-
// a `URIError`: the path is not a well-formed
|
|
584
|
+
// a `URIError`: the path is not a well-formed target, so classify it as
|
|
547
585
|
// unparseable (the caller converts `null` to its own typed error).
|
|
548
586
|
return null;
|
|
549
587
|
}
|
|
550
|
-
if (segments
|
|
551
|
-
return
|
|
552
|
-
}
|
|
553
|
-
const [, spaceId, ...rest] = segments;
|
|
554
|
-
if (rest.length === 0) {
|
|
555
|
-
return { kind: 'space', spaceId };
|
|
588
|
+
if (segments.length === 0) {
|
|
589
|
+
return { kind: 'space' };
|
|
556
590
|
}
|
|
557
591
|
// A reserved segment directly under the space (`policy`, `backends`,
|
|
558
592
|
// `export`, ...) addresses a space-level sub-endpoint, as does anything
|
|
559
|
-
// nested beneath one (
|
|
560
|
-
if (isReservedCollectionId(
|
|
561
|
-
return { kind: 'sub-resource',
|
|
593
|
+
// nested beneath one (`backends/{backendId}`).
|
|
594
|
+
if (isReservedCollectionId(segments[0])) {
|
|
595
|
+
return { kind: 'sub-resource', segments };
|
|
562
596
|
}
|
|
563
|
-
if (
|
|
564
|
-
return { kind: 'collection',
|
|
597
|
+
if (segments.length === 1) {
|
|
598
|
+
return { kind: 'collection', collectionId: segments[0] };
|
|
565
599
|
}
|
|
566
600
|
// A reserved segment under the collection (`policy`, `backend`, `quota`,
|
|
567
601
|
// ...) addresses a collection-level sub-endpoint.
|
|
568
|
-
if (isReservedResourceId(
|
|
569
|
-
return { kind: 'sub-resource',
|
|
602
|
+
if (isReservedResourceId(segments[1])) {
|
|
603
|
+
return { kind: 'sub-resource', segments };
|
|
570
604
|
}
|
|
571
|
-
if (
|
|
605
|
+
if (segments.length === 2) {
|
|
572
606
|
return {
|
|
573
607
|
kind: 'resource',
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
resourceId: rest[1]
|
|
608
|
+
collectionId: segments[0],
|
|
609
|
+
resourceId: segments[1]
|
|
577
610
|
};
|
|
578
611
|
}
|
|
579
|
-
// Anything deeper (
|
|
580
|
-
//
|
|
581
|
-
return { kind: 'sub-resource',
|
|
612
|
+
// Anything deeper (`{c}/{r}/meta`, `{c}/{r}/policy`, chunk sub-segments,
|
|
613
|
+
// ...) is a resource-level sub-endpoint.
|
|
614
|
+
return { kind: 'sub-resource', segments };
|
|
582
615
|
}
|
|
583
616
|
//# sourceMappingURL=paths.js.map
|