@interop/was-client 0.61.0 → 0.62.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 +58 -3
- package/dist/WasClient.d.ts +51 -6
- package/dist/WasClient.d.ts.map +1 -1
- package/dist/WasClient.js +84 -14
- package/dist/WasClient.js.map +1 -1
- package/dist/errors.d.ts +13 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +13 -0
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/internal/paths.d.ts +0 -4
- package/dist/internal/paths.d.ts.map +1 -1
- package/dist/internal/paths.js +4 -9
- package/dist/internal/paths.js.map +1 -1
- package/dist/internal/request.d.ts +22 -6
- package/dist/internal/request.d.ts.map +1 -1
- package/dist/internal/request.js +31 -13
- package/dist/internal/request.js.map +1 -1
- package/dist/internal/service.d.ts +61 -0
- package/dist/internal/service.d.ts.map +1 -0
- package/dist/internal/service.js +259 -0
- package/dist/internal/service.js.map +1 -0
- package/dist/types.d.ts +28 -2
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/internal/paths.js
CHANGED
|
@@ -4,9 +4,10 @@
|
|
|
4
4
|
/**
|
|
5
5
|
* URL path builders for the WAS server, encoding the trailing-slash
|
|
6
6
|
* canonicalization once. The convention: a trailing slash marks a container in
|
|
7
|
-
* canonical form (`/
|
|
8
|
-
*
|
|
9
|
-
*
|
|
7
|
+
* canonical form (`/space/{s}/`, `/space/{s}/{c}/`), everything else has
|
|
8
|
+
* none, and no two paths differ only by a trailing slash. Path segments are
|
|
9
|
+
* percent-encoded so ids never break out of their slot. The Spaces Repository
|
|
10
|
+
* has no builder: its URL is the `spaces` member of the service description.
|
|
10
11
|
*
|
|
11
12
|
* A container's own description is not at its URL: it lives at the reserved
|
|
12
13
|
* `meta` segment (`spaceMeta`, `collectionMeta`), beside the Resource-level
|
|
@@ -82,12 +83,6 @@ function encodeResourceId(resourceId) {
|
|
|
82
83
|
assertNotReserved({ id: resourceId, kind: 'resource' });
|
|
83
84
|
return encode(resourceId);
|
|
84
85
|
}
|
|
85
|
-
/**
|
|
86
|
-
* `/spaces/` -- the SpacesRepository (create / list spaces).
|
|
87
|
-
*/
|
|
88
|
-
export function spacesRoot() {
|
|
89
|
-
return '/spaces/';
|
|
90
|
-
}
|
|
91
86
|
/**
|
|
92
87
|
* `/space/:spaceId` -- the slash-less prefix the space-level sub-endpoints hang
|
|
93
88
|
* off. Module-private: the bare form is not a path this client ever requests
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paths.js","sourceRoot":"","sources":["../../src/internal/paths.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH
|
|
1
|
+
{"version":3,"file":"paths.js","sourceRoot":"","sources":["../../src/internal/paths.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,EACL,iBAAiB,EACjB,sBAAsB,EACtB,oBAAoB,EACrB,MAAM,eAAe,CAAA;AAEtB;;;;;;;;;;GAUG;AACH,SAAS,aAAa,CAAC,OAAe;IACpC,IAAI,OAAO,KAAK,EAAE,IAAI,OAAO,KAAK,GAAG,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;QAC1D,MAAM,IAAI,eAAe,CACvB,cAAc,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,+BAA+B;YAClE,qDAAqD,CACxD,CAAA;IACH,CAAC;AACH,CAAC;AAED,SAAS,MAAM,CAAC,OAAe;IAC7B,aAAa,CAAC,OAAO,CAAC,CAAA;IACtB,OAAO,kBAAkB,CAAC,OAAO,CAAC,CAAA;AACpC,CAAC;AAED;;;;;;;;;GASG;AACH,SAAS,kBAAkB,CAAC,YAAoB;IAC9C,iBAAiB,CAAC,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zE,CAAC;IACD,yEAAyE;IACzE,kDAAkD;IAClD,IAAI,oBAAoB,CAAC,IAAI,CAAC,CAAC,CAAW,CAAC,EAAE,CAAC;QAC5C,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAA;IAC1D,CAAC;IACD,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACtB,OAAO;YACL,IAAI,EAAE,UAAU;YAChB,OAAO;YACP,YAAY,EAAE,IAAI,CAAC,CAAC,CAAW;YAC/B,UAAU,EAAE,IAAI,CAAC,CAAC,CAAW;SAC9B,CAAA;IACH,CAAC;IACD,qEAAqE;IACrE,uDAAuD;IACvD,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAA;AAC1D,CAAC"}
|
|
@@ -6,23 +6,27 @@
|
|
|
6
6
|
* paths against the server URL and defaulting the capability `action` to the
|
|
7
7
|
* HTTP method (never ezcap's `read`/`write`). `send()` adds the typed-error
|
|
8
8
|
* mapping and the null-on-404 read translation; `rawRequest()` is the
|
|
9
|
-
* unmapped escape hatch used by `was.request()`.
|
|
9
|
+
* unmapped escape hatch used by `was.request()`. Every signed request first
|
|
10
|
+
* awaits the context's memoized service discovery, so no request reaches a
|
|
11
|
+
* server whose protocol version this client does not speak.
|
|
10
12
|
*/
|
|
11
13
|
import type { ZcapClient } from '@interop/ezcap';
|
|
12
14
|
import type { HttpResponse } from '@interop/http-client';
|
|
13
15
|
import type { EncryptionProvider } from '../codec.js';
|
|
14
|
-
import type { IZcap, RequestInput } from '../types.js';
|
|
16
|
+
import type { IZcap, RequestInput, ServiceInfo } from '../types.js';
|
|
15
17
|
/**
|
|
16
18
|
* The shared context threaded through every handle: the server base URL, the
|
|
17
|
-
* wrapped ezcap client, the cached controller DID of its signer,
|
|
18
|
-
*
|
|
19
|
-
*
|
|
19
|
+
* wrapped ezcap client, the cached controller DID of its signer, the optional
|
|
20
|
+
* encryption provider that supplies an encrypting codec for the collections
|
|
21
|
+
* the client holds keys for, and the memoized service discovery every signed
|
|
22
|
+
* request waits on.
|
|
20
23
|
*/
|
|
21
24
|
export interface ClientContext {
|
|
22
25
|
serverUrl: string;
|
|
23
26
|
zcapClient: ZcapClient;
|
|
24
27
|
controllerDid: string;
|
|
25
28
|
encryption?: EncryptionProvider;
|
|
29
|
+
service: () => Promise<ServiceInfo>;
|
|
26
30
|
}
|
|
27
31
|
/**
|
|
28
32
|
* A single signed request: the public `RequestInput` shape (either `path`,
|
|
@@ -43,13 +47,25 @@ export interface SendInput extends RequestInput {
|
|
|
43
47
|
/**
|
|
44
48
|
* Signs and sends a request via the wrapped ezcap client, returning the raw
|
|
45
49
|
* `HttpResponse` and throwing the raw ky/ezcap error. Does not apply error
|
|
46
|
-
* mapping or null-on-404 -- this is the escape-hatch primitive.
|
|
50
|
+
* mapping or null-on-404 -- this is the escape-hatch primitive. It waits on
|
|
51
|
+
* the context's service discovery first, and rejects with that discovery's
|
|
52
|
+
* error (such as `IncompatibleServerError`) before anything is signed.
|
|
47
53
|
*
|
|
48
54
|
* @param context {ClientContext}
|
|
49
55
|
* @param input {SendInput}
|
|
50
56
|
* @returns {Promise<HttpResponse>}
|
|
51
57
|
*/
|
|
52
58
|
export declare function rawRequest(context: ClientContext, input: SendInput): Promise<HttpResponse>;
|
|
59
|
+
/**
|
|
60
|
+
* A plain unsigned `fetch` that maps a network failure to a `WasError`, the
|
|
61
|
+
* way the rest of the transport does. The response is returned as is,
|
|
62
|
+
* whatever its status.
|
|
63
|
+
*
|
|
64
|
+
* @param url {string}
|
|
65
|
+
* @param init {RequestInit}
|
|
66
|
+
* @returns {Promise<Response>}
|
|
67
|
+
*/
|
|
68
|
+
export declare function fetchMapped(url: string, init: RequestInit): Promise<Response>;
|
|
53
69
|
/**
|
|
54
70
|
* Sends an **unsigned** request (a plain `fetch`, no capability invocation), for
|
|
55
71
|
* reading public (`PublicCanRead`) resources that need no authorization. Applies
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../src/internal/request.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH
|
|
1
|
+
{"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../src/internal/request.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH;;;;;;;;GAQG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAChD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAKxD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AACrD,OAAO,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAEnE;;;;;;GAMG;AACH,MAAM,WAAW,aAAa;IAC5B,SAAS,EAAE,MAAM,CAAA;IACjB,UAAU,EAAE,UAAU,CAAA;IACtB,aAAa,EAAE,MAAM,CAAA;IACrB,UAAU,CAAC,EAAE,kBAAkB,CAAA;IAC/B,OAAO,EAAE,MAAM,OAAO,CAAC,WAAW,CAAC,CAAA;CACpC;AAED;;;;GAIG;AACH,MAAM,WAAW,SAAU,SAAQ,YAAY;IAC7C;;OAEG;IACH,IAAI,CAAC,EAAE,OAAO,CAAA;IACd;;;OAGG;IACH,UAAU,CAAC,EAAE,OAAO,CAAA;CACrB;AAYD;;;;;;;;;;GAUG;AACH,wBAAsB,UAAU,CAC9B,OAAO,EAAE,aAAa,EACtB,KAAK,EAAE,SAAS,GACf,OAAO,CAAC,YAAY,CAAC,CAcvB;AAED;;;;;;;;GAQG;AACH,wBAAsB,WAAW,CAC/B,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,WAAW,GAChB,OAAO,CAAC,QAAQ,CAAC,CAMnB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,eAAe,CAAC,KAAK,EAAE;IAC3C,GAAG,EAAE,MAAM,CAAA;IACX,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAChC,IAAI,CAAC,EAAE,OAAO,CAAA;CACf,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CA4B/B;AAED;;;;;;;;GAQG;AACH,wBAAsB,IAAI,CACxB,OAAO,EAAE,aAAa,EACtB,KAAK,EAAE,SAAS,GACf,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAe9B;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,QAAQ,CAAC,CAAC,EAC9B,OAAO,EAAE,aAAa,EACtB,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,KAAK,CAAA;CAAE,GACzD,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,CAQnB;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,gBAAgB,CAAC,CAAC,EACtC,OAAO,EAAE,aAAa,EACtB,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,KAAK,CAAA;CAAE,GACzD,OAAO,CAAC;IAAE,IAAI,EAAE,CAAC,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAAC,CAY5C"}
|
package/dist/internal/request.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { mapError, httpStatus } from '../errors.js';
|
|
1
|
+
import { WasError, mapError, httpStatus } from '../errors.js';
|
|
2
2
|
import { toUrl } from './paths.js';
|
|
3
3
|
import { dataOrNull } from './content.js';
|
|
4
4
|
import { readEtag } from './conditional.js';
|
|
@@ -14,7 +14,9 @@ function resolveRequestUrl(context, input) {
|
|
|
14
14
|
/**
|
|
15
15
|
* Signs and sends a request via the wrapped ezcap client, returning the raw
|
|
16
16
|
* `HttpResponse` and throwing the raw ky/ezcap error. Does not apply error
|
|
17
|
-
* mapping or null-on-404 -- this is the escape-hatch primitive.
|
|
17
|
+
* mapping or null-on-404 -- this is the escape-hatch primitive. It waits on
|
|
18
|
+
* the context's service discovery first, and rejects with that discovery's
|
|
19
|
+
* error (such as `IncompatibleServerError`) before anything is signed.
|
|
18
20
|
*
|
|
19
21
|
* @param context {ClientContext}
|
|
20
22
|
* @param input {SendInput}
|
|
@@ -22,6 +24,7 @@ function resolveRequestUrl(context, input) {
|
|
|
22
24
|
*/
|
|
23
25
|
export async function rawRequest(context, input) {
|
|
24
26
|
const url = resolveRequestUrl(context, input);
|
|
27
|
+
await context.service();
|
|
25
28
|
const method = input.method ?? 'GET';
|
|
26
29
|
return context.zcapClient.request({
|
|
27
30
|
url,
|
|
@@ -34,6 +37,23 @@ export async function rawRequest(context, input) {
|
|
|
34
37
|
body: input.body
|
|
35
38
|
});
|
|
36
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* A plain unsigned `fetch` that maps a network failure to a `WasError`, the
|
|
42
|
+
* way the rest of the transport does. The response is returned as is,
|
|
43
|
+
* whatever its status.
|
|
44
|
+
*
|
|
45
|
+
* @param url {string}
|
|
46
|
+
* @param init {RequestInit}
|
|
47
|
+
* @returns {Promise<Response>}
|
|
48
|
+
*/
|
|
49
|
+
export async function fetchMapped(url, init) {
|
|
50
|
+
try {
|
|
51
|
+
return await fetch(url, init);
|
|
52
|
+
}
|
|
53
|
+
catch (err) {
|
|
54
|
+
throw mapError(err);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
37
57
|
/**
|
|
38
58
|
* Sends an **unsigned** request (a plain `fetch`, no capability invocation), for
|
|
39
59
|
* reading public (`PublicCanRead`) resources that need no authorization. Applies
|
|
@@ -49,16 +69,10 @@ export async function rawRequest(context, input) {
|
|
|
49
69
|
* @returns {Promise<HttpResponse | null>}
|
|
50
70
|
*/
|
|
51
71
|
export async function unsignedRequest(input) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
headers: input.headers
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
catch (err) {
|
|
60
|
-
throw mapError(err);
|
|
61
|
-
}
|
|
72
|
+
const response = await fetchMapped(input.url, {
|
|
73
|
+
method: input.method ?? 'GET',
|
|
74
|
+
headers: input.headers
|
|
75
|
+
});
|
|
62
76
|
if (response.ok) {
|
|
63
77
|
return response;
|
|
64
78
|
}
|
|
@@ -96,7 +110,11 @@ export async function send(context, input) {
|
|
|
96
110
|
return await rawRequest(context, input);
|
|
97
111
|
}
|
|
98
112
|
catch (err) {
|
|
99
|
-
|
|
113
|
+
// Only a raw transport error translates: a `WasError` (such as a discovery
|
|
114
|
+
// refusal) is already an answer and passes through whatever its status.
|
|
115
|
+
if ((input.read || input.idempotent) &&
|
|
116
|
+
!(err instanceof WasError) &&
|
|
117
|
+
httpStatus(err) === 404) {
|
|
100
118
|
return null;
|
|
101
119
|
}
|
|
102
120
|
throw mapError(err);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request.js","sourceRoot":"","sources":["../../src/internal/request.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"request.js","sourceRoot":"","sources":["../../src/internal/request.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAC7D,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAoC3C,SAAS,iBAAiB,CAAC,OAAsB,EAAE,KAAgB;IACjE,IAAI,KAAK,CAAC,GAAG,KAAK,SAAS,EAAE,CAAC;QAC5B,OAAO,KAAK,CAAC,GAAG,CAAA;IAClB,CAAC;IACD,IAAI,KAAK,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;QAC7B,MAAM,IAAI,SAAS,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AAsB,EACtB,EAAE,IAAI,EAAE,UAAU,EAAwC;IAE1D,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,OAAO,EAAE;QACnC,IAAI;QACJ,MAAM,EAAE,KAAK;QACb,UAAU;QACV,IAAI,EAAE,IAAI;KACX,CAAC,CAAA;IACF,OAAO,UAAU,CAAI,QAAQ,CAAC,CAAA;AAChC,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,OAAsB,EACtB,EAAE,IAAI,EAAE,UAAU,EAAwC;IAE1D,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,OAAO,EAAE;QACnC,IAAI;QACJ,MAAM,EAAE,KAAK;QACb,UAAU;QACV,IAAI,EAAE,IAAI;KACX,CAAC,CAAA;IACF,MAAM,IAAI,GAAG,UAAU,CAAI,QAAQ,CAAC,CAAA;IACpC,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;QAClB,OAAO,IAAI,CAAA;IACb,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAA;AAC3C,CAAC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { ServiceInfo } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* The WAS specification's identifier, the `specs` key its version entries sit
|
|
4
|
+
* under. Provisional until the spec's rename registers it.
|
|
5
|
+
*/
|
|
6
|
+
export declare const PWS_SPEC_ID = "https://w3id.org/pws";
|
|
7
|
+
/**
|
|
8
|
+
* The WAS specification versions this client speaks, newest first. Selection
|
|
9
|
+
* takes the first one the server lists.
|
|
10
|
+
*/
|
|
11
|
+
export declare const SUPPORTED_PWS_VERSIONS: string[];
|
|
12
|
+
/**
|
|
13
|
+
* Reads the target of the first `service` link in a `Link` header (RFC 8288),
|
|
14
|
+
* resolved against the URL of the response that carried it. Relation types
|
|
15
|
+
* compare case-insensitively, a `rel` may list several space-separated types,
|
|
16
|
+
* and only the first `rel` parameter of a link-value counts.
|
|
17
|
+
*
|
|
18
|
+
* @param options {object}
|
|
19
|
+
* @param options.header {string | null} the `Link` header value
|
|
20
|
+
* @param options.baseUrl {string} the URL the response came from
|
|
21
|
+
* @returns {string | undefined} the absolute service description URL
|
|
22
|
+
*/
|
|
23
|
+
export declare function serviceLinkTarget({ header, baseUrl }: {
|
|
24
|
+
header: string | null;
|
|
25
|
+
baseUrl: string;
|
|
26
|
+
}): string | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* Applies the spec's version-selection rules to a service description: a
|
|
29
|
+
* `specs` key other than the WAS identifier is ignored, a version entry
|
|
30
|
+
* without a string `version` is ignored, and the newest version this client
|
|
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 strings.
|
|
33
|
+
*
|
|
34
|
+
* @param description {unknown} the parsed service description
|
|
35
|
+
* @returns {ServiceInfo}
|
|
36
|
+
* @throws {IncompatibleServerError} when the document lacks `url` or `specs`,
|
|
37
|
+
* when no entry names a version this client speaks, or when the chosen
|
|
38
|
+
* entry's `spaces` or `features` is malformed
|
|
39
|
+
*/
|
|
40
|
+
export declare function selectServiceVersion(description: unknown): ServiceInfo;
|
|
41
|
+
/**
|
|
42
|
+
* Discovers the service description from a URL the client holds and selects
|
|
43
|
+
* the version to speak: an unsigned `HEAD` of `url` for its `service` link
|
|
44
|
+
* (the response status does not matter), then an unsigned `GET` of the linked
|
|
45
|
+
* document.
|
|
46
|
+
*
|
|
47
|
+
* A network failure, and a rate limit or temporary outage (429, 502, 503,
|
|
48
|
+
* 504) that comes without the link, reject with the mapped transport error,
|
|
49
|
+
* since they say nothing about the protocol the server speaks.
|
|
50
|
+
*
|
|
51
|
+
* @param options {object}
|
|
52
|
+
* @param options.url {string} any WAS URL, typically the client's `serverUrl`
|
|
53
|
+
* @returns {Promise<ServiceInfo>}
|
|
54
|
+
* @throws {IncompatibleServerError} when the response carries no `service`
|
|
55
|
+
* link, the linked document cannot be read or parsed, or version selection
|
|
56
|
+
* refuses it (see {@link selectServiceVersion})
|
|
57
|
+
*/
|
|
58
|
+
export declare function discoverService({ url }: {
|
|
59
|
+
url: string;
|
|
60
|
+
}): Promise<ServiceInfo>;
|
|
61
|
+
//# sourceMappingURL=service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../src/internal/service.ts"],"names":[],"mappings":"AAmBA,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;AA2BD;;;;;;;;;;;;GAYG;AACH,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,OAAO,GAAG,WAAW,CAiEtE;AAqCD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,eAAe,CAAC,EACpC,GAAG,EACJ,EAAE;IACD,GAAG,EAAE,MAAM,CAAA;CACZ,GAAG,OAAO,CAAC,WAAW,CAAC,CAuCvB"}
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
import { IncompatibleServerError, mapError } from '../errors.js';
|
|
2
|
+
import { fetchMapped } from './request.js';
|
|
3
|
+
/**
|
|
4
|
+
* The WAS specification's identifier, the `specs` key its version entries sit
|
|
5
|
+
* under. Provisional until the spec's rename registers it.
|
|
6
|
+
*/
|
|
7
|
+
export const PWS_SPEC_ID = 'https://w3id.org/pws';
|
|
8
|
+
/**
|
|
9
|
+
* The WAS specification versions this client speaks, newest first. Selection
|
|
10
|
+
* takes the first one the server lists.
|
|
11
|
+
*/
|
|
12
|
+
export const SUPPORTED_PWS_VERSIONS = ['0.5'];
|
|
13
|
+
/**
|
|
14
|
+
* The link relation that names the service description.
|
|
15
|
+
*/
|
|
16
|
+
const SERVICE_RELATION = 'service';
|
|
17
|
+
/**
|
|
18
|
+
* Splits a `Link` header value into its link-values: on commas outside a
|
|
19
|
+
* `<...>` target and outside a quoted parameter value.
|
|
20
|
+
*
|
|
21
|
+
* @param header {string}
|
|
22
|
+
* @returns {string[]}
|
|
23
|
+
*/
|
|
24
|
+
function splitLinkValues(header) {
|
|
25
|
+
const values = [];
|
|
26
|
+
let current = '';
|
|
27
|
+
let inTarget = false;
|
|
28
|
+
let inQuotes = false;
|
|
29
|
+
for (let index = 0; index < header.length; index++) {
|
|
30
|
+
const char = header[index];
|
|
31
|
+
if (inQuotes) {
|
|
32
|
+
current += char;
|
|
33
|
+
if (char === '\\' && index + 1 < header.length) {
|
|
34
|
+
current += header[++index];
|
|
35
|
+
}
|
|
36
|
+
else if (char === '"') {
|
|
37
|
+
inQuotes = false;
|
|
38
|
+
}
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
if (char === '<') {
|
|
42
|
+
inTarget = true;
|
|
43
|
+
}
|
|
44
|
+
else if (char === '>') {
|
|
45
|
+
inTarget = false;
|
|
46
|
+
}
|
|
47
|
+
else if (char === '"' && !inTarget) {
|
|
48
|
+
inQuotes = true;
|
|
49
|
+
}
|
|
50
|
+
else if (char === ',' && !inTarget) {
|
|
51
|
+
values.push(current);
|
|
52
|
+
current = '';
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
current += char;
|
|
56
|
+
}
|
|
57
|
+
values.push(current);
|
|
58
|
+
return values;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Reads the target of the first `service` link in a `Link` header (RFC 8288),
|
|
62
|
+
* resolved against the URL of the response that carried it. Relation types
|
|
63
|
+
* compare case-insensitively, a `rel` may list several space-separated types,
|
|
64
|
+
* and only the first `rel` parameter of a link-value counts.
|
|
65
|
+
*
|
|
66
|
+
* @param options {object}
|
|
67
|
+
* @param options.header {string | null} the `Link` header value
|
|
68
|
+
* @param options.baseUrl {string} the URL the response came from
|
|
69
|
+
* @returns {string | undefined} the absolute service description URL
|
|
70
|
+
*/
|
|
71
|
+
export function serviceLinkTarget({ header, baseUrl }) {
|
|
72
|
+
if (header === null) {
|
|
73
|
+
return undefined;
|
|
74
|
+
}
|
|
75
|
+
for (const linkValue of splitLinkValues(header)) {
|
|
76
|
+
const match = /^\s*<([^>]*)>(.*)$/s.exec(linkValue);
|
|
77
|
+
if (match === null) {
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
const [, target, rest] = match;
|
|
81
|
+
const relParam = rest
|
|
82
|
+
.split(';')
|
|
83
|
+
.map(param => /^\s*rel\s*=\s*(?:"((?:[^"\\]|\\.)*)"|([^\s;]*))/i.exec(param))
|
|
84
|
+
.find(paramMatch => paramMatch !== null);
|
|
85
|
+
const relValue = relParam?.[1] ?? relParam?.[2] ?? '';
|
|
86
|
+
const relations = relValue.toLowerCase().split(/\s+/);
|
|
87
|
+
if (relations.includes(SERVICE_RELATION)) {
|
|
88
|
+
try {
|
|
89
|
+
return new URL(target, baseUrl).toString();
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return undefined;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Whether a value is a JSON object (not `null`, not an array).
|
|
100
|
+
*
|
|
101
|
+
* @param value {unknown}
|
|
102
|
+
* @returns {boolean}
|
|
103
|
+
*/
|
|
104
|
+
function isObject(value) {
|
|
105
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
106
|
+
}
|
|
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
|
+
/**
|
|
123
|
+
* Applies the spec's version-selection rules to a service description: a
|
|
124
|
+
* `specs` key other than the WAS identifier is ignored, a version entry
|
|
125
|
+
* without a string `version` is ignored, and the newest version this client
|
|
126
|
+
* 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 strings.
|
|
128
|
+
*
|
|
129
|
+
* @param description {unknown} the parsed service description
|
|
130
|
+
* @returns {ServiceInfo}
|
|
131
|
+
* @throws {IncompatibleServerError} when the document lacks `url` or `specs`,
|
|
132
|
+
* when no entry names a version this client speaks, or when the chosen
|
|
133
|
+
* entry's `spaces` or `features` is malformed
|
|
134
|
+
*/
|
|
135
|
+
export function selectServiceVersion(description) {
|
|
136
|
+
if (!isObject(description) ||
|
|
137
|
+
typeof description.url !== 'string' ||
|
|
138
|
+
!isObject(description.specs)) {
|
|
139
|
+
throw new IncompatibleServerError('The service description is not a JSON object with `url` and `specs`.');
|
|
140
|
+
}
|
|
141
|
+
const candidates = description.specs[PWS_SPEC_ID];
|
|
142
|
+
const entries = (Array.isArray(candidates) ? candidates : []).filter((entry) => isObject(entry) && typeof entry.version === 'string');
|
|
143
|
+
let chosen;
|
|
144
|
+
for (const version of SUPPORTED_PWS_VERSIONS) {
|
|
145
|
+
chosen = entries.find(entry => entry.version === version);
|
|
146
|
+
if (chosen !== undefined) {
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
if (chosen === undefined) {
|
|
151
|
+
const offered = entries.map(entry => entry.version);
|
|
152
|
+
throw new IncompatibleServerError(`The server at "${description.url}" lists no version of ` +
|
|
153
|
+
`${PWS_SPEC_ID} this client speaks (offered: ` +
|
|
154
|
+
`${offered.length === 0 ? 'none' : offered.join(', ')}; supported: ` +
|
|
155
|
+
`${SUPPORTED_PWS_VERSIONS.join(', ')}).`);
|
|
156
|
+
}
|
|
157
|
+
const { spaces, features } = chosen;
|
|
158
|
+
if (spaces !== undefined &&
|
|
159
|
+
(typeof spaces !== 'string' || !isAbsoluteUrl(spaces))) {
|
|
160
|
+
throw new IncompatibleServerError(`The ${PWS_SPEC_ID} ${chosen.version} entry's \`spaces\` is not an ` +
|
|
161
|
+
'absolute URL.');
|
|
162
|
+
}
|
|
163
|
+
if (features !== undefined &&
|
|
164
|
+
(!Array.isArray(features) ||
|
|
165
|
+
!features.every(token => typeof token === 'string'))) {
|
|
166
|
+
throw new IncompatibleServerError(`The ${PWS_SPEC_ID} ${chosen.version} entry's \`features\` is not an ` +
|
|
167
|
+
'array of strings.');
|
|
168
|
+
}
|
|
169
|
+
const tokens = [...(features ?? [])];
|
|
170
|
+
return {
|
|
171
|
+
description: description,
|
|
172
|
+
version: chosen.version,
|
|
173
|
+
entry: chosen,
|
|
174
|
+
...(spaces !== undefined && { spacesUrl: spaces }),
|
|
175
|
+
features: tokens,
|
|
176
|
+
hasFeature(token) {
|
|
177
|
+
return tokens.includes(token);
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* The statuses that signal a transient failure (rate limiting, or a gateway
|
|
183
|
+
* or server that is temporarily unavailable) rather than an answer about the
|
|
184
|
+
* server's protocol. A lasting refusal such as 501, 505, or 507 is not in
|
|
185
|
+
* this set.
|
|
186
|
+
*/
|
|
187
|
+
const TRANSIENT_STATUSES = new Set([429, 502, 503, 504]);
|
|
188
|
+
/**
|
|
189
|
+
* Rejects a discovery step that answered `status` without what discovery
|
|
190
|
+
* needs: with the mapped transport error when the status is transient, since
|
|
191
|
+
* it says nothing about the protocol the server speaks, and with an
|
|
192
|
+
* `IncompatibleServerError` carrying `message` otherwise.
|
|
193
|
+
*
|
|
194
|
+
* @param options {object}
|
|
195
|
+
* @param options.status {number}
|
|
196
|
+
* @param options.requestUrl {string}
|
|
197
|
+
* @param options.message {string}
|
|
198
|
+
* @returns {never}
|
|
199
|
+
*/
|
|
200
|
+
function refuse({ status, requestUrl, message }) {
|
|
201
|
+
if (TRANSIENT_STATUSES.has(status)) {
|
|
202
|
+
throw mapError({ status, requestUrl });
|
|
203
|
+
}
|
|
204
|
+
throw new IncompatibleServerError(message, { requestUrl });
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Discovers the service description from a URL the client holds and selects
|
|
208
|
+
* the version to speak: an unsigned `HEAD` of `url` for its `service` link
|
|
209
|
+
* (the response status does not matter), then an unsigned `GET` of the linked
|
|
210
|
+
* document.
|
|
211
|
+
*
|
|
212
|
+
* A network failure, and a rate limit or temporary outage (429, 502, 503,
|
|
213
|
+
* 504) that comes without the link, reject with the mapped transport error,
|
|
214
|
+
* since they say nothing about the protocol the server speaks.
|
|
215
|
+
*
|
|
216
|
+
* @param options {object}
|
|
217
|
+
* @param options.url {string} any WAS URL, typically the client's `serverUrl`
|
|
218
|
+
* @returns {Promise<ServiceInfo>}
|
|
219
|
+
* @throws {IncompatibleServerError} when the response carries no `service`
|
|
220
|
+
* link, the linked document cannot be read or parsed, or version selection
|
|
221
|
+
* refuses it (see {@link selectServiceVersion})
|
|
222
|
+
*/
|
|
223
|
+
export async function discoverService({ url }) {
|
|
224
|
+
const probe = await fetchMapped(url, { method: 'HEAD' });
|
|
225
|
+
const serviceUrl = serviceLinkTarget({
|
|
226
|
+
header: probe.headers.get('link'),
|
|
227
|
+
baseUrl: probe.url || url
|
|
228
|
+
});
|
|
229
|
+
if (serviceUrl === undefined) {
|
|
230
|
+
refuse({
|
|
231
|
+
status: probe.status,
|
|
232
|
+
requestUrl: url,
|
|
233
|
+
message: `The response from "${url}" (${probe.status}) carries no ` +
|
|
234
|
+
'rel="service" link, so the server predates WAS v0.5, which this ' +
|
|
235
|
+
'client requires.'
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
const response = await fetchMapped(serviceUrl, {
|
|
239
|
+
method: 'GET',
|
|
240
|
+
headers: { accept: 'application/json' }
|
|
241
|
+
});
|
|
242
|
+
if (!response.ok) {
|
|
243
|
+
refuse({
|
|
244
|
+
status: response.status,
|
|
245
|
+
requestUrl: serviceUrl,
|
|
246
|
+
message: `The service description at "${serviceUrl}" answered ` +
|
|
247
|
+
`${response.status}.`
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
let description;
|
|
251
|
+
try {
|
|
252
|
+
description = await response.json();
|
|
253
|
+
}
|
|
254
|
+
catch (err) {
|
|
255
|
+
throw new IncompatibleServerError(`The service description at "${serviceUrl}" is not valid JSON.`, { requestUrl: serviceUrl, cause: err });
|
|
256
|
+
}
|
|
257
|
+
return selectServiceVersion(description);
|
|
258
|
+
}
|
|
259
|
+
//# sourceMappingURL=service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service.js","sourceRoot":"","sources":["../../src/internal/service.ts"],"names":[],"mappings":"AAiBA,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,E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,CAAC;IACD,IAAI,WAAoB,CAAA;IACxB,IAAI,CAAC;QACH,WAAW,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAA;IACrC,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,IAAI,uBAAuB,CAC/B,+BAA+B,UAAU,sBAAsB,EAC/D,EAAE,UAAU,EAAE,UAAU,EAAE,KAAK,EAAE,GAAG,EAAE,CACvC,CAAA;IACH,CAAC;IACD,OAAO,oBAAoB,CAAC,WAAW,CAAC,CAAA;AAC1C,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -25,8 +25,8 @@ export type { IZcap, IDelegatedZcap, IRootZcap, IDID, ISigner };
|
|
|
25
25
|
* `CollectionResourcesList` and the collections-in-a-space listing is
|
|
26
26
|
* `CollectionsList`.
|
|
27
27
|
*/
|
|
28
|
-
export type { Action, ActionInput, ChangeDocument, ChangesCheckpoint, ChangesPage, SpaceMetadata, CollectionEncryption, CollectionEncryptionEpoch, CollectionEncryptionRecipient, PolicyDocument, LinkSet, LinkSetEntry, CollectionSummary, CollectionsList, SpaceSummary, SpaceListing, ResourceSummary, CollectionResourcesList, ResourceMetadata, ResourceMetadataCustom, CollectionMetadata, ImportStats, BackendReference, BackendDescriptor, BackendRegistration, BackendConnectionInput, BackendConnectionPublic, StorageLimit, CollectionUsage, BackendUsage, SpaceQuotaReport } from '@interop/storage-core';
|
|
29
|
-
import type { BackendReference, CollectionEncryption, ResourceMetadataCustom } from '@interop/storage-core';
|
|
28
|
+
export type { Action, ActionInput, ChangeDocument, ChangesCheckpoint, ChangesPage, SpaceMetadata, CollectionEncryption, CollectionEncryptionEpoch, CollectionEncryptionRecipient, PolicyDocument, LinkSet, LinkSetEntry, CollectionSummary, CollectionsList, SpaceSummary, SpaceListing, ResourceSummary, CollectionResourcesList, ResourceMetadata, ResourceMetadataCustom, CollectionMetadata, ImportStats, BackendReference, BackendDescriptor, BackendRegistration, BackendConnectionInput, BackendConnectionPublic, StorageLimit, CollectionUsage, BackendUsage, SpaceQuotaReport, ServiceDescription, ServiceDescriptionVersionEntry, PwsVersionEntry } from '@interop/storage-core';
|
|
29
|
+
import type { BackendReference, CollectionEncryption, PwsVersionEntry, ResourceMetadataCustom, ServiceDescription } from '@interop/storage-core';
|
|
30
30
|
/**
|
|
31
31
|
* The user-writable metadata `custom` value as a caller passes it in. The
|
|
32
32
|
* second arm keeps `name` / `tags` checked at their stored types on an object
|
|
@@ -159,6 +159,32 @@ export interface FindPage {
|
|
|
159
159
|
export type EncryptionOverride = (CollectionEncryption & {
|
|
160
160
|
keys?: unknown;
|
|
161
161
|
}) | 'plaintext';
|
|
162
|
+
/**
|
|
163
|
+
* What service discovery learned about the server (`was.service()`): the
|
|
164
|
+
* service description as read, and the WAS version entry this client chose
|
|
165
|
+
* from it.
|
|
166
|
+
*
|
|
167
|
+
* - `description` -- the whole document, including `specs` entries for other
|
|
168
|
+
* specifications and the optional `instance` disclosure. The client gates no
|
|
169
|
+
* behavior on `instance`.
|
|
170
|
+
* - `version` -- the chosen WAS specification version, such as `"0.5"`.
|
|
171
|
+
* - `entry` -- the chosen version entry.
|
|
172
|
+
* - `spacesUrl` -- the absolute Spaces Repository URL from the entry's
|
|
173
|
+
* `spaces` member. Absent when the server does not implement the Spaces
|
|
174
|
+
* Repository.
|
|
175
|
+
* - `features` -- the entry's `features` tokens. The vocabulary is open: a
|
|
176
|
+
* token this client does not know is carried here and otherwise ignored.
|
|
177
|
+
* - `hasFeature(token)` -- whether the entry advertises `token`. An absent
|
|
178
|
+
* token (or an absent array) reads as unsupported.
|
|
179
|
+
*/
|
|
180
|
+
export interface ServiceInfo {
|
|
181
|
+
description: ServiceDescription;
|
|
182
|
+
version: string;
|
|
183
|
+
entry: PwsVersionEntry;
|
|
184
|
+
spacesUrl?: string;
|
|
185
|
+
features: string[];
|
|
186
|
+
hasFeature(token: string): boolean;
|
|
187
|
+
}
|
|
162
188
|
/**
|
|
163
189
|
* Options accepted by every handle factory (`space()`, `collection()`,
|
|
164
190
|
* `resource()`). A bound `capability` is attached to every request the handle
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH;;;;;;;;;;GAUG;AACH,OAAO,KAAK,EACV,KAAK,EACL,cAAc,EACd,SAAS,EACV,MAAM,mCAAmC,CAAA;AAC1C,OAAO,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,8BAA8B,CAAA;AAEjE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAExD,YAAY,EAAE,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,CAAA;AAE/D;;;;;;;;GAQG;AACH,YAAY,EACV,MAAM,EACN,WAAW,EACX,cAAc,EACd,iBAAiB,EACjB,WAAW,EACX,aAAa,EACb,oBAAoB,EACpB,yBAAyB,EACzB,6BAA6B,EAC7B,cAAc,EACd,OAAO,EACP,YAAY,EACZ,iBAAiB,EACjB,eAAe,EACf,YAAY,EACZ,YAAY,EACZ,eAAe,EACf,uBAAuB,EACvB,gBAAgB,EAChB,sBAAsB,EACtB,kBAAkB,EAClB,WAAW,EACX,gBAAgB,EAChB,iBAAiB,EACjB,mBAAmB,EACnB,sBAAsB,EACtB,uBAAuB,EACvB,YAAY,EACZ,eAAe,EACf,YAAY,EACZ,gBAAgB,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH;;;;;;;;;;GAUG;AACH,OAAO,KAAK,EACV,KAAK,EACL,cAAc,EACd,SAAS,EACV,MAAM,mCAAmC,CAAA;AAC1C,OAAO,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,8BAA8B,CAAA;AAEjE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAExD,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C,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE,MAAM,EAAE,CAAA;IAClB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAA;CACnC;AAED;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAC5B,UAAU,CAAC,EAAE,KAAK,CAAA;IAClB;;;OAGG;IACH,UAAU,CAAC,EAAE,kBAAkB,CAAA;CAChC;AAED;;;;;;;;;GASG;AACH,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAA;IACV,OAAO,EAAE,WAAW,EAAE,CAAA;IACtB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACvB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,UAAU,CAAC,EAAE,KAAK,CAAA;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAChC,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,IAAI,GAAG,UAAU,CAAA;IACxB,UAAU,CAAC,EAAE,KAAK,CAAA;CACnB"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@interop/was-client",
|
|
3
3
|
"description": "A developer-friendly client for Wallet Attached Storage (WAS) servers.",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.62.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"build": "pnpm run clear && tsc",
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
"@interop/ezcap": "^7.4.8",
|
|
75
75
|
"@interop/http-client": "^1.0.5",
|
|
76
76
|
"@interop/minimal-cipher": "^7.10.2",
|
|
77
|
-
"@interop/storage-core": "^0.
|
|
77
|
+
"@interop/storage-core": "^0.15.0",
|
|
78
78
|
"@interop/vh-resource-log": "^0.5.1",
|
|
79
79
|
"@interop/x25519-key-agreement-key": "^5.4.0",
|
|
80
80
|
"@noble/hashes": "^2.3.0",
|