@interop/was-client 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/LICENSE.md +20 -0
  2. package/README.md +204 -0
  3. package/dist/Collection.d.ts +112 -0
  4. package/dist/Collection.d.ts.map +1 -0
  5. package/dist/Collection.js +209 -0
  6. package/dist/Collection.js.map +1 -0
  7. package/dist/Resource.d.ts +67 -0
  8. package/dist/Resource.d.ts.map +1 -0
  9. package/dist/Resource.js +124 -0
  10. package/dist/Resource.js.map +1 -0
  11. package/dist/Space.d.ts +99 -0
  12. package/dist/Space.d.ts.map +1 -0
  13. package/dist/Space.js +202 -0
  14. package/dist/Space.js.map +1 -0
  15. package/dist/WasClient.d.ts +115 -0
  16. package/dist/WasClient.d.ts.map +1 -0
  17. package/dist/WasClient.js +191 -0
  18. package/dist/WasClient.js.map +1 -0
  19. package/dist/errors.d.ts +72 -0
  20. package/dist/errors.d.ts.map +1 -0
  21. package/dist/errors.js +112 -0
  22. package/dist/errors.js.map +1 -0
  23. package/dist/index.d.ts +14 -0
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.js +13 -0
  26. package/dist/index.js.map +1 -0
  27. package/dist/internal/content.d.ts +43 -0
  28. package/dist/internal/content.d.ts.map +1 -0
  29. package/dist/internal/content.js +66 -0
  30. package/dist/internal/content.js.map +1 -0
  31. package/dist/internal/grant.d.ts +21 -0
  32. package/dist/internal/grant.d.ts.map +1 -0
  33. package/dist/internal/grant.js +19 -0
  34. package/dist/internal/grant.js.map +1 -0
  35. package/dist/internal/paths.d.ts +70 -0
  36. package/dist/internal/paths.d.ts.map +1 -0
  37. package/dist/internal/paths.js +92 -0
  38. package/dist/internal/paths.js.map +1 -0
  39. package/dist/internal/request.d.ts +64 -0
  40. package/dist/internal/request.d.ts.map +1 -0
  41. package/dist/internal/request.js +60 -0
  42. package/dist/internal/request.js.map +1 -0
  43. package/dist/internal/reserved.d.ts +16 -0
  44. package/dist/internal/reserved.d.ts.map +1 -0
  45. package/dist/internal/reserved.js +40 -0
  46. package/dist/internal/reserved.js.map +1 -0
  47. package/dist/types.d.ts +165 -0
  48. package/dist/types.d.ts.map +1 -0
  49. package/dist/types.js +2 -0
  50. package/dist/types.js.map +1 -0
  51. package/package.json +84 -0
@@ -0,0 +1,124 @@
1
+ /*!
2
+ * Copyright (c) 2026 Interop Alliance. All rights reserved.
3
+ */
4
+ /**
5
+ * A navigational handle to a single Resource (a JSON object or binary blob
6
+ * keyed by id within a Collection). Sugar over the Collection item operations,
7
+ * with explicit `getText()` / `getBytes()` escape hatches.
8
+ */
9
+ import { resourcePath } from './internal/paths.js';
10
+ import { prepareBody, parseResource } from './internal/content.js';
11
+ import { assertNotReserved } from './internal/reserved.js';
12
+ import { send } from './internal/request.js';
13
+ export class Resource {
14
+ spaceId;
15
+ collectionId;
16
+ id;
17
+ _context;
18
+ _capability;
19
+ /**
20
+ * @param options {object}
21
+ * @param options.context {ClientContext}
22
+ * @param options.spaceId {string}
23
+ * @param options.collectionId {string}
24
+ * @param options.resourceId {string}
25
+ * @param [options.capability] {IZcap} capability attached to every request
26
+ */
27
+ constructor({ context, spaceId, collectionId, resourceId, capability }) {
28
+ this._context = context;
29
+ this.spaceId = spaceId;
30
+ this.collectionId = collectionId;
31
+ this.id = resourceId;
32
+ this._capability = capability;
33
+ }
34
+ get _path() {
35
+ return resourcePath(this.spaceId, this.collectionId, this.id);
36
+ }
37
+ /**
38
+ * Reads the resource, auto-parsing JSON to an object and returning binary as
39
+ * a `Blob`. Returns `null` if the resource is missing or not visible to you
40
+ * (WAS returns 404 for both not-found and unauthorized).
41
+ *
42
+ * @returns {Promise<Json | Blob | null>}
43
+ */
44
+ async get() {
45
+ const response = await send(this._context, {
46
+ path: this._path,
47
+ method: 'GET',
48
+ capability: this._capability,
49
+ read: true
50
+ });
51
+ return parseResource(response);
52
+ }
53
+ /**
54
+ * Reads the resource body as text. Returns `null` on a missing/unauthorized
55
+ * resource (404 conflation caveat).
56
+ *
57
+ * @returns {Promise<string | null>}
58
+ */
59
+ async getText() {
60
+ const response = await send(this._context, {
61
+ path: this._path,
62
+ method: 'GET',
63
+ capability: this._capability,
64
+ read: true
65
+ });
66
+ return response === null ? null : response.text();
67
+ }
68
+ /**
69
+ * Reads the resource body as raw bytes. Returns `null` on a
70
+ * missing/unauthorized resource (404 conflation caveat).
71
+ *
72
+ * @returns {Promise<Uint8Array | null>}
73
+ */
74
+ async getBytes() {
75
+ const response = await send(this._context, {
76
+ path: this._path,
77
+ method: 'GET',
78
+ capability: this._capability,
79
+ read: true
80
+ });
81
+ if (response === null) {
82
+ return null;
83
+ }
84
+ return new Uint8Array(await response.arrayBuffer());
85
+ }
86
+ /**
87
+ * Creates or replaces the resource by id (upsert). JSON for plain
88
+ * objects/arrays, binary for `Blob`/`Uint8Array`. Throws `NotFoundError` if
89
+ * the parent collection does not exist (WAS does not auto-create parents).
90
+ *
91
+ * @param data {Json | Blob | Uint8Array}
92
+ * @param options {object}
93
+ * @param [options.contentType] {string} content-type for binary data
94
+ * @returns {Promise<void>}
95
+ */
96
+ async put(data, options = {}) {
97
+ assertNotReserved(this.id, 'resource');
98
+ const prepared = prepareBody(data, options);
99
+ await send(this._context, {
100
+ path: this._path,
101
+ method: 'PUT',
102
+ capability: this._capability,
103
+ json: prepared.json,
104
+ body: prepared.body,
105
+ headers: prepared.contentType
106
+ ? { 'content-type': prepared.contentType }
107
+ : undefined
108
+ });
109
+ }
110
+ /**
111
+ * Deletes the resource. Idempotent.
112
+ *
113
+ * @returns {Promise<void>}
114
+ */
115
+ async delete() {
116
+ await send(this._context, {
117
+ path: this._path,
118
+ method: 'DELETE',
119
+ capability: this._capability,
120
+ idempotent: true
121
+ });
122
+ }
123
+ }
124
+ //# sourceMappingURL=Resource.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Resource.js","sourceRoot":"","sources":["../src/Resource.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH;;;;GAIG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MAAM;QACV,MAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;YACxB,IAAI,EAAE,IAAI,CAAC,KAAK;YAChB,MAAM,EAAE,QAAQ;YAChB,UAAU,EAAE,IAAI,CAAC,WAAW;YAC5B,UAAU,EAAE,IAAI;SACjB,CAAC,CAAA;IACJ,CAAC;CACF"}
@@ -0,0 +1,99 @@
1
+ import type { ClientContext } from './internal/request.js';
2
+ import { Collection } from './Collection.js';
3
+ import type { BackendReference, CollectionListing, GrantOptions, HandleOptions, IDelegatedZcap, IZcap, ImportStats, SpaceDescription } from './types.js';
4
+ export declare class Space {
5
+ readonly id: string;
6
+ private readonly _context;
7
+ private readonly _capability?;
8
+ /**
9
+ * @param options {object}
10
+ * @param options.context {ClientContext}
11
+ * @param options.spaceId {string}
12
+ * @param [options.capability] {IZcap} capability attached to every request
13
+ */
14
+ constructor({ context, spaceId, capability }: {
15
+ context: ClientContext;
16
+ spaceId: string;
17
+ capability?: IZcap;
18
+ });
19
+ private get _path();
20
+ /**
21
+ * Reads the Space Description. Returns `null` if the space is missing or not
22
+ * visible to you (WAS returns 404 for both not-found and unauthorized).
23
+ *
24
+ * @returns {Promise<SpaceDescription | null>}
25
+ */
26
+ describe(): Promise<SpaceDescription | null>;
27
+ /**
28
+ * Creates or updates the space by id (upsert). Merges the given fields over
29
+ * the current description; `controller` defaults to the wrapped signer's DID.
30
+ *
31
+ * @param desc {object}
32
+ * @param [desc.name] {string}
33
+ * @param [desc.controller] {string}
34
+ * @returns {Promise<SpaceDescription>}
35
+ */
36
+ configure(desc: {
37
+ name?: string;
38
+ controller?: string;
39
+ }): Promise<SpaceDescription>;
40
+ /**
41
+ * Deletes the space. Idempotent.
42
+ *
43
+ * @returns {Promise<void>}
44
+ */
45
+ delete(): Promise<void>;
46
+ /**
47
+ * Returns a lazy handle to a collection by id. No I/O.
48
+ *
49
+ * @param collectionId {string}
50
+ * @param options {object}
51
+ * @param [options.capability] {IZcap}
52
+ * @returns {Collection}
53
+ */
54
+ collection(collectionId: string, options?: HandleOptions): Collection;
55
+ /**
56
+ * Creates a collection within the space (server-generated id unless `id` is
57
+ * given). Throws `NotFoundError` if the space does not exist.
58
+ *
59
+ * @param desc {object}
60
+ * @param [desc.id] {string}
61
+ * @param [desc.name] {string}
62
+ * @param [desc.backend] {BackendReference}
63
+ * @returns {Promise<Collection>}
64
+ */
65
+ createCollection(desc?: {
66
+ id?: string;
67
+ name?: string;
68
+ backend?: BackendReference;
69
+ }): Promise<Collection>;
70
+ /**
71
+ * Lists the collections in the space. Returns `null` if the space is missing
72
+ * or not visible to you (404 conflation caveat).
73
+ *
74
+ * @returns {Promise<CollectionListing | null>}
75
+ */
76
+ collections(): Promise<CollectionListing | null>;
77
+ /**
78
+ * Delegates access to this space. Prefills the grant `target` with this
79
+ * space's URL (and the bound `capability`, if any, for re-delegation).
80
+ *
81
+ * @param options {GrantOptions}
82
+ * @returns {Promise<IDelegatedZcap>}
83
+ */
84
+ grant(options: GrantOptions): Promise<IDelegatedZcap>;
85
+ /**
86
+ * Exports the whole space as a tar (`application/x-tar`) archive.
87
+ *
88
+ * @returns {Promise<Uint8Array>}
89
+ */
90
+ export(): Promise<Uint8Array>;
91
+ /**
92
+ * Imports (merges) a tar archive into the space.
93
+ *
94
+ * @param tar {Uint8Array | Blob}
95
+ * @returns {Promise<ImportStats>}
96
+ */
97
+ import(tar: Uint8Array | Blob): Promise<ImportStats>;
98
+ }
99
+ //# sourceMappingURL=Space.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Space.d.ts","sourceRoot":"","sources":["../src/Space.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AAE1D,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,KAAK,EACV,gBAAgB,EAEhB,iBAAiB,EACjB,YAAY,EACZ,aAAa,EACb,cAAc,EACd,KAAK,EACL,WAAW,EACX,gBAAgB,EAC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AG,IAAI,GAAG,OAAO,CAAC,WAAW,CAAC;CAc3D"}
package/dist/Space.js ADDED
@@ -0,0 +1,202 @@
1
+ /*!
2
+ * Copyright (c) 2026 Interop Alliance. All rights reserved.
3
+ */
4
+ /**
5
+ * A navigational handle to a Space. Exposes its own lifecycle
6
+ * (`describe`/`configure`/`delete`), contained Collections
7
+ * (`collection`/`createCollection`/`collections`), delegation (`grant`), and
8
+ * whole-space `export`/`import`.
9
+ */
10
+ import { spacePath, spaceItems, spaceCollections, spaceExport, spaceImport, toUrl } from './internal/paths.js';
11
+ import { assertNotReserved } from './internal/reserved.js';
12
+ import { delegateGrant } from './internal/grant.js';
13
+ import { send } from './internal/request.js';
14
+ import { Collection } from './Collection.js';
15
+ export class Space {
16
+ id;
17
+ _context;
18
+ _capability;
19
+ /**
20
+ * @param options {object}
21
+ * @param options.context {ClientContext}
22
+ * @param options.spaceId {string}
23
+ * @param [options.capability] {IZcap} capability attached to every request
24
+ */
25
+ constructor({ context, spaceId, capability }) {
26
+ this._context = context;
27
+ this.id = spaceId;
28
+ this._capability = capability;
29
+ }
30
+ get _path() {
31
+ return spacePath(this.id);
32
+ }
33
+ /**
34
+ * Reads the Space Description. Returns `null` if the space is missing or not
35
+ * visible to you (WAS returns 404 for both not-found and unauthorized).
36
+ *
37
+ * @returns {Promise<SpaceDescription | null>}
38
+ */
39
+ async describe() {
40
+ const response = await send(this._context, {
41
+ path: this._path,
42
+ method: 'GET',
43
+ capability: this._capability,
44
+ read: true
45
+ });
46
+ return response === null ? null : response.data;
47
+ }
48
+ /**
49
+ * Creates or updates the space by id (upsert). Merges the given fields over
50
+ * the current description; `controller` defaults to the wrapped signer's DID.
51
+ *
52
+ * @param desc {object}
53
+ * @param [desc.name] {string}
54
+ * @param [desc.controller] {string}
55
+ * @returns {Promise<SpaceDescription>}
56
+ */
57
+ async configure(desc) {
58
+ const current = await this.describe();
59
+ const name = desc.name ?? current?.name;
60
+ const controller = desc.controller ?? current?.controller ?? this._context.controllerDid;
61
+ await send(this._context, {
62
+ path: this._path,
63
+ method: 'PUT',
64
+ capability: this._capability,
65
+ json: { id: this.id, name, controller }
66
+ });
67
+ return {
68
+ id: this.id,
69
+ type: current?.type ?? ['Space'],
70
+ ...(name !== undefined ? { name } : {}),
71
+ controller
72
+ };
73
+ }
74
+ /**
75
+ * Deletes the space. Idempotent.
76
+ *
77
+ * @returns {Promise<void>}
78
+ */
79
+ async delete() {
80
+ await send(this._context, {
81
+ path: this._path,
82
+ method: 'DELETE',
83
+ capability: this._capability,
84
+ idempotent: true
85
+ });
86
+ }
87
+ /**
88
+ * Returns a lazy handle to a collection by id. No I/O.
89
+ *
90
+ * @param collectionId {string}
91
+ * @param options {object}
92
+ * @param [options.capability] {IZcap}
93
+ * @returns {Collection}
94
+ */
95
+ collection(collectionId, options = {}) {
96
+ return new Collection({
97
+ context: this._context,
98
+ spaceId: this.id,
99
+ collectionId,
100
+ capability: options.capability ?? this._capability
101
+ });
102
+ }
103
+ /**
104
+ * Creates a collection within the space (server-generated id unless `id` is
105
+ * given). Throws `NotFoundError` if the space does not exist.
106
+ *
107
+ * @param desc {object}
108
+ * @param [desc.id] {string}
109
+ * @param [desc.name] {string}
110
+ * @param [desc.backend] {BackendReference}
111
+ * @returns {Promise<Collection>}
112
+ */
113
+ async createCollection(desc = {}) {
114
+ if (desc.id !== undefined) {
115
+ assertNotReserved(desc.id, 'collection');
116
+ }
117
+ const body = {};
118
+ if (desc.id !== undefined) {
119
+ body.id = desc.id;
120
+ }
121
+ if (desc.name !== undefined) {
122
+ body.name = desc.name;
123
+ }
124
+ if (desc.backend) {
125
+ body.backend = desc.backend;
126
+ }
127
+ const response = await send(this._context, {
128
+ path: spaceItems(this.id),
129
+ method: 'POST',
130
+ capability: this._capability,
131
+ json: body
132
+ });
133
+ const created = response
134
+ .data;
135
+ return this.collection(created.id);
136
+ }
137
+ /**
138
+ * Lists the collections in the space. Returns `null` if the space is missing
139
+ * or not visible to you (404 conflation caveat).
140
+ *
141
+ * @returns {Promise<CollectionListing | null>}
142
+ */
143
+ async collections() {
144
+ const response = await send(this._context, {
145
+ path: spaceCollections(this.id),
146
+ method: 'GET',
147
+ capability: this._capability,
148
+ read: true
149
+ });
150
+ return response === null ? null : response.data;
151
+ }
152
+ /**
153
+ * Delegates access to this space. Prefills the grant `target` with this
154
+ * space's URL (and the bound `capability`, if any, for re-delegation).
155
+ *
156
+ * @param options {GrantOptions}
157
+ * @returns {Promise<IDelegatedZcap>}
158
+ */
159
+ async grant(options) {
160
+ return delegateGrant(this._context, {
161
+ ...options,
162
+ target: options.target ??
163
+ toUrl({ serverUrl: this._context.serverUrl, path: this._path }),
164
+ capability: options.capability ?? this._capability
165
+ });
166
+ }
167
+ /**
168
+ * Exports the whole space as a tar (`application/x-tar`) archive.
169
+ *
170
+ * @returns {Promise<Uint8Array>}
171
+ */
172
+ async export() {
173
+ const response = await send(this._context, {
174
+ path: spaceExport(this.id),
175
+ method: 'POST',
176
+ capability: this._capability
177
+ });
178
+ // A successful export always returns a response (errors throw via send()).
179
+ const buffer = await response.arrayBuffer();
180
+ return new Uint8Array(buffer);
181
+ }
182
+ /**
183
+ * Imports (merges) a tar archive into the space.
184
+ *
185
+ * @param tar {Uint8Array | Blob}
186
+ * @returns {Promise<ImportStats>}
187
+ */
188
+ async import(tar) {
189
+ const body = tar instanceof Uint8Array && tar.constructor !== Uint8Array
190
+ ? new Uint8Array(tar.buffer, tar.byteOffset, tar.byteLength)
191
+ : tar;
192
+ const response = await send(this._context, {
193
+ path: spaceImport(this.id),
194
+ method: 'POST',
195
+ capability: this._capability,
196
+ body,
197
+ headers: { 'content-type': 'application/x-tar' }
198
+ });
199
+ return response.data;
200
+ }
201
+ }
202
+ //# sourceMappingURL=Space.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Space.js","sourceRoot":"","sources":["../src/Space.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH;;;;;GAKG;AACH,OAAO,EACL,SAAS,EACT,UAAU,EACV,gBAA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0 +1,115 @@
1
+ /*!
2
+ * Copyright (c) 2026 Interop Alliance. All rights reserved.
3
+ */
4
+ /**
5
+ * The top-level WAS client. Wraps an ezcap `ZcapClient` (which holds the active
6
+ * signer) and exposes the WAS containment model
7
+ * (`SpacesRepository > Space > Collection > Resource`) through lazy
8
+ * navigational handles. Also hosts the general delegation primitive
9
+ * (`grant`), capability-rebuilding (`fromCapability`), and the signed
10
+ * escape-hatch (`request`).
11
+ */
12
+ import { ZcapClient } from '@interop/ezcap';
13
+ import type { HttpResponse } from '@interop/http-client';
14
+ import { Space } from './Space.js';
15
+ import { Collection } from './Collection.js';
16
+ import { Resource } from './Resource.js';
17
+ import type { GrantOptions, HandleOptions, IDelegatedZcap, ISigner, IZcap, RequestInput, SpaceListing } from './types.js';
18
+ export declare class WasClient {
19
+ readonly serverUrl: string;
20
+ readonly zcapClient: ZcapClient;
21
+ /**
22
+ * @param options {object}
23
+ * @param options.serverUrl {string} base URL for both URL building and
24
+ * zcap `invocationTarget`s
25
+ * @param options.zcapClient {ZcapClient} an ezcap client holding the signer
26
+ */
27
+ constructor({ serverUrl, zcapClient }: {
28
+ serverUrl: string;
29
+ zcapClient: ZcapClient;
30
+ });
31
+ /**
32
+ * Convenience constructor that builds the ezcap `ZcapClient` internally from
33
+ * a signer, using the `Ed25519Signature2020` suite.
34
+ *
35
+ * @param options {object}
36
+ * @param options.serverUrl {string}
37
+ * @param options.signer {ISigner}
38
+ * @returns {WasClient}
39
+ */
40
+ static fromSigner({ serverUrl, signer }: {
41
+ serverUrl: string;
42
+ signer: ISigner;
43
+ }): WasClient;
44
+ /**
45
+ * The DID controlling the wrapped signer (`signer.id` without the key
46
+ * fragment). Used to default `controller` on `createSpace`.
47
+ *
48
+ * @returns {string}
49
+ */
50
+ get controllerDid(): string;
51
+ private get _context();
52
+ /**
53
+ * Returns a lazy handle to a space by id. No I/O.
54
+ *
55
+ * @param spaceId {string}
56
+ * @param options {object}
57
+ * @param [options.capability] {IZcap}
58
+ * @returns {Space}
59
+ */
60
+ space(spaceId: string, options?: HandleOptions): Space;
61
+ /**
62
+ * Creates a space (server-generated id unless `id` is given). The server
63
+ * requires `name`, and `controller` must match the wrapped signer's DID
64
+ * (which is the default).
65
+ *
66
+ * @param desc {object}
67
+ * @param [desc.id] {string}
68
+ * @param [desc.name] {string}
69
+ * @param [desc.controller] {string}
70
+ * @returns {Promise<Space>}
71
+ */
72
+ createSpace(desc?: {
73
+ id?: string;
74
+ name?: string;
75
+ controller?: string;
76
+ }): Promise<Space>;
77
+ /**
78
+ * Lists the spaces in the repository. Not yet implemented by the reference
79
+ * server, which answers 501 -- so this currently throws
80
+ * `NotImplementedError`.
81
+ *
82
+ * @returns {Promise<SpaceListing>}
83
+ */
84
+ listSpaces(): Promise<SpaceListing>;
85
+ /**
86
+ * Rebuilds an access handle from a received capability, returning a handle at
87
+ * the depth implied by the capability's `invocationTarget` (space /
88
+ * collection / resource), pre-bound with that capability.
89
+ *
90
+ * @param zcap {IZcap}
91
+ * @returns {Space | Collection | Resource}
92
+ */
93
+ fromCapability(zcap: IZcap): Space | Collection | Resource;
94
+ /**
95
+ * The general delegation primitive. Delegates a capability per `GrantOptions`
96
+ * and returns the signed zcap to hand off out-of-band. `target` (any URL) and
97
+ * `capability` (a parent capability to attenuate) make this a superset of the
98
+ * `space`/`collection` grant sugar.
99
+ *
100
+ * @param options {GrantOptions}
101
+ * @returns {Promise<IDelegatedZcap>}
102
+ */
103
+ grant(options: GrantOptions): Promise<IDelegatedZcap>;
104
+ /**
105
+ * The signed escape hatch, mirroring ezcap's generic `request()`. Resolves
106
+ * `path` against `serverUrl`, defaults `action` to `method`, and signs via the
107
+ * wrapped client. Returns the raw `HttpResponse` and throws raw ky/ezcap
108
+ * errors -- it does not apply the null-on-404 or typed-error conveniences.
109
+ *
110
+ * @param options {RequestInput}
111
+ * @returns {Promise<HttpResponse>}
112
+ */
113
+ request(options: RequestInput): Promise<HttpResponse>;
114
+ }
115
+ //# sourceMappingURL=WasClient.d.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