@interop/was-client 0.6.0 → 0.7.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/README.md +95 -1
  2. package/dist/Collection.d.ts +28 -3
  3. package/dist/Collection.d.ts.map +1 -1
  4. package/dist/Collection.js +74 -13
  5. package/dist/Collection.js.map +1 -1
  6. package/dist/Resource.d.ts +58 -9
  7. package/dist/Resource.d.ts.map +1 -1
  8. package/dist/Resource.js +104 -26
  9. package/dist/Resource.js.map +1 -1
  10. package/dist/Space.d.ts +4 -0
  11. package/dist/Space.d.ts.map +1 -1
  12. package/dist/Space.js +4 -0
  13. package/dist/Space.js.map +1 -1
  14. package/dist/WasClient.d.ts +10 -2
  15. package/dist/WasClient.d.ts.map +1 -1
  16. package/dist/WasClient.js +11 -4
  17. package/dist/WasClient.js.map +1 -1
  18. package/dist/codec.d.ts +127 -0
  19. package/dist/codec.d.ts.map +1 -0
  20. package/dist/codec.js +2 -0
  21. package/dist/codec.js.map +1 -0
  22. package/dist/edv/EdvCodec.d.ts +148 -0
  23. package/dist/edv/EdvCodec.d.ts.map +1 -0
  24. package/dist/edv/EdvCodec.js +284 -0
  25. package/dist/edv/EdvCodec.js.map +1 -0
  26. package/dist/edv/index.d.ts +10 -0
  27. package/dist/edv/index.d.ts.map +1 -1
  28. package/dist/edv/index.js +10 -0
  29. package/dist/edv/index.js.map +1 -1
  30. package/dist/errors.d.ts +11 -0
  31. package/dist/errors.d.ts.map +1 -1
  32. package/dist/errors.js +17 -0
  33. package/dist/errors.js.map +1 -1
  34. package/dist/index.d.ts +2 -1
  35. package/dist/index.d.ts.map +1 -1
  36. package/dist/index.js +1 -1
  37. package/dist/index.js.map +1 -1
  38. package/dist/internal/codec.d.ts +27 -0
  39. package/dist/internal/codec.d.ts.map +1 -0
  40. package/dist/internal/codec.js +44 -0
  41. package/dist/internal/codec.js.map +1 -0
  42. package/dist/internal/conditional.d.ts +40 -0
  43. package/dist/internal/conditional.d.ts.map +1 -0
  44. package/dist/internal/conditional.js +35 -0
  45. package/dist/internal/conditional.js.map +1 -0
  46. package/dist/internal/request.d.ts +5 -1
  47. package/dist/internal/request.d.ts.map +1 -1
  48. package/dist/internal/request.js.map +1 -1
  49. package/dist/types.d.ts +6 -0
  50. package/dist/types.d.ts.map +1 -1
  51. package/package.json +3 -3
@@ -0,0 +1,148 @@
1
+ /*!
2
+ * Copyright (c) 2026 Interop Alliance. All rights reserved.
3
+ */
4
+ /**
5
+ * The EDV (Encrypted Data Vault) resource codec and its `EncryptionProvider`
6
+ * factory -- the encrypting half of the codec seam. Bound to an
7
+ * encrypted collection, it encrypts a caller's value into an EDV envelope
8
+ * (`{ id, sequence, indexed, jwe }`) on write and decrypts it on read, so
9
+ * `collection.put(id, obj)` / `collection.get(id)` transparently round-trip
10
+ * ciphertext. Keys live in the wallet and are supplied per-collection by the
11
+ * app's `resolveKeys`; they never reach the server, which stores only opaque
12
+ * JWE envelopes.
13
+ *
14
+ * This reuses `EdvClientCore`'s encrypt/decrypt primitives (the same JWE
15
+ * machinery as the standalone `WasTransport`), but here the WAS Resource CRUD --
16
+ * the transport role -- is played by core was-client's `Collection`/`Resource`
17
+ * I/O, so the codec is a pure encode/decode transform and needs no transport of
18
+ * its own.
19
+ *
20
+ * Scope (documents-only):
21
+ *
22
+ * - **Restrict-mode ids.** `add()` mints a 128-bit multibase EDV id; the WAS
23
+ * resource id IS that EDV id. `put(id, ...)` accepts only an EDV-format id --
24
+ * a human-readable id is rejected (it would leak onto the URL). Carry a
25
+ * human-readable label inside the encrypted content instead. (Blind-derived
26
+ * ids are a deferred future item.)
27
+ * - **Small binary as a single JWE.** A `Blob`/`Uint8Array` under the size cap
28
+ * is wrapped and encrypted as one document; an oversized one is rejected
29
+ * (chunked encrypted blobs need the server's `chunked-streams` affordance).
30
+ * - **Enforced sequence (conditional writes).** The codec sets
31
+ * `conditionalWrites`, so the write path pre-reads the current envelope and
32
+ * hands it to `encode`: an update advances `sequence` from its prior value and
33
+ * pins the write to the server's current ETag via `If-Match`, while a fresh
34
+ * insert (`sequence: 0`) is guarded by `If-None-Match: *`. A stale write
35
+ * surfaces as a `PreconditionFailedError` (412) -- the lost-update guard --
36
+ * rather than the old advisory last-writer-wins. Against a backend that does
37
+ * not advertise `conditional-writes` (no ETag) it degrades to advisory.
38
+ * - **No server-visible metadata.** `allowsServerMetadata` is `false`, so
39
+ * `setName`/`setTags` throw on an encrypted collection (the core seam enforces
40
+ * this).
41
+ */
42
+ import { EdvClientCore } from '@interop/edv-client';
43
+ import type { HttpResponse } from '@interop/http-client';
44
+ import type { IKeyAgreementKey, IKeyResolver } from '@interop/data-integrity-core';
45
+ import type { EncodedWrite, EncryptionProvider, ResourceCodec } from '../codec.js';
46
+ import type { Json } from '../types.js';
47
+ import { EDV_CONTENT_TYPE } from './WasTransport.js';
48
+ /**
49
+ * A {@link ResourceCodec} that encrypts on write and decrypts on read using an
50
+ * `EdvClientCore`'s JWE primitives. One instance is bound per encrypted
51
+ * collection handle.
52
+ */
53
+ export declare class EdvCodec implements ResourceCodec {
54
+ readonly allowsServerMetadata = false;
55
+ readonly conditionalWrites = true;
56
+ private readonly _edv;
57
+ private readonly _keyAgreementKey;
58
+ private readonly _contentType;
59
+ private readonly _maxBlobBytes;
60
+ /**
61
+ * @param options {object}
62
+ * @param options.edv {EdvClientCore} holds the cipher + key resolver
63
+ * @param options.keyAgreementKey {IKeyAgreementKey} the recipient/decrypt key
64
+ * @param options.contentType {string} stored envelope content type
65
+ * @param options.maxBlobBytes {number} single-document binary cap
66
+ */
67
+ constructor({ edv, keyAgreementKey, contentType, maxBlobBytes }: {
68
+ edv: EdvClientCore;
69
+ keyAgreementKey: IKeyAgreementKey;
70
+ contentType: string;
71
+ maxBlobBytes: number;
72
+ });
73
+ /**
74
+ * @inheritdoc
75
+ */
76
+ encode({ id, data, contentType, current }: {
77
+ id?: string;
78
+ data: Json | Blob | Uint8Array;
79
+ contentType?: string;
80
+ current?: HttpResponse | null;
81
+ }): Promise<EncodedWrite>;
82
+ /**
83
+ * @inheritdoc
84
+ */
85
+ decode(response: {
86
+ data?: unknown;
87
+ json(): Promise<unknown>;
88
+ }): Promise<Json | Blob>;
89
+ /**
90
+ * Resolves a caller value to the EDV document `content`: a JSON object/array
91
+ * passes through; a `Blob`/`Uint8Array` (under the cap) is wrapped as a
92
+ * base64 blob record; a bare primitive is rejected (mirroring the plaintext
93
+ * `prepareBody` contract).
94
+ *
95
+ * @param data {Json | Blob | Uint8Array}
96
+ * @param [contentType] {string}
97
+ * @returns {Promise<object>}
98
+ */
99
+ private _toContent;
100
+ /**
101
+ * Wraps binary bytes as an EDV document content record, enforcing the
102
+ * single-document size cap.
103
+ *
104
+ * @param bytes {Uint8Array}
105
+ * @param contentType {string}
106
+ * @returns {object}
107
+ */
108
+ private _blobContent;
109
+ /**
110
+ * Reconstructs a caller value from decrypted EDV document content: a `Blob`
111
+ * for a wrapped blob record, otherwise the JSON content verbatim.
112
+ *
113
+ * @param content {unknown}
114
+ * @returns {Json | Blob}
115
+ */
116
+ private _fromContent;
117
+ }
118
+ /**
119
+ * Builds an {@link EncryptionProvider} that encrypts the collections the client
120
+ * holds keys for, wiring the per-collection keys (from `resolveKeys`) into an
121
+ * {@link EdvCodec}. Pass the result as `WasClient`'s `encryption` option; core
122
+ * resolves a codec for a collection exactly when `resolveKeys` returns keys for
123
+ * it (the switch is keys alone -- encryption is not a backend feature).
124
+ *
125
+ * @param options {object}
126
+ * @param options.resolveKeys {function} returns the collection's
127
+ * `{ keyAgreementKey, keyResolver }`, or `null` to read/write it as plaintext
128
+ * @param [options.contentType] {string} stored envelope content type;
129
+ * defaults to `application/json`. Pass `EDV_CONTENT_TYPE`
130
+ * (`application/edv+json`) against a server that registers an
131
+ * `application/*+json` parser.
132
+ * @param [options.maxBlobBytes] {number} single-document binary cap (default
133
+ * 1 MiB)
134
+ * @returns {EncryptionProvider}
135
+ */
136
+ export declare function createEdvEncryption({ resolveKeys, contentType, maxBlobBytes }: {
137
+ resolveKeys: (ref: {
138
+ spaceId: string;
139
+ collectionId: string;
140
+ }) => Promise<{
141
+ keyAgreementKey: IKeyAgreementKey;
142
+ keyResolver: IKeyResolver;
143
+ } | null>;
144
+ contentType?: string;
145
+ maxBlobBytes?: number;
146
+ }): EncryptionProvider;
147
+ export { EDV_CONTENT_TYPE };
148
+ //# sourceMappingURL=EdvCodec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EdvCodec.d.ts","sourceRoot":"","sources":["../../src/edv/EdvCodec.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AACnD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AACxD,OAAO,KAAK,EAEV,gBAAgB,EAChB,YAAY,EACb,MAAM,8BAA8B,CAAA;AACrC,OAAO,KAAK,EACV,YAAY,EACZ,kBAAkB,EAClB,aAAa,EACd,MAAM,aAAa,CAAA;AAGpB,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AACvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AAsEpD;;;;GAIG;AACH,qBAAa,QAAS,YAAW,aAAa;IAC5C,QAAQ,CAAC,oBAAoB,SAAQ;IACrC,QAAQ,CAAC,iBAAiB,QAAO;IAEjC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAe;IACpC,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAkB;IACnD,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAQ;IACrC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAQ;IAEtC;;;;;;OAMG;gBACS,EACV,GAAG,EACH,eAAe,EACf,WAAW,EACX,YAAY,EACb,EAAE;QACD,GAAG,EAAE,aAAa,CAAA;QAClB,eAAe,EAAE,gBAAgB,CAA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vault) resource codec and its `EncryptionProvider`
6
+ * factory -- the encrypting half of the codec seam. Bound to an
7
+ * encrypted collection, it encrypts a caller's value into an EDV envelope
8
+ * (`{ id, sequence, indexed, jwe }`) on write and decrypts it on read, so
9
+ * `collection.put(id, obj)` / `collection.get(id)` transparently round-trip
10
+ * ciphertext. Keys live in the wallet and are supplied per-collection by the
11
+ * app's `resolveKeys`; they never reach the server, which stores only opaque
12
+ * JWE envelopes.
13
+ *
14
+ * This reuses `EdvClientCore`'s encrypt/decrypt primitives (the same JWE
15
+ * machinery as the standalone `WasTransport`), but here the WAS Resource CRUD --
16
+ * the transport role -- is played by core was-client's `Collection`/`Resource`
17
+ * I/O, so the codec is a pure encode/decode transform and needs no transport of
18
+ * its own.
19
+ *
20
+ * Scope (documents-only):
21
+ *
22
+ * - **Restrict-mode ids.** `add()` mints a 128-bit multibase EDV id; the WAS
23
+ * resource id IS that EDV id. `put(id, ...)` accepts only an EDV-format id --
24
+ * a human-readable id is rejected (it would leak onto the URL). Carry a
25
+ * human-readable label inside the encrypted content instead. (Blind-derived
26
+ * ids are a deferred future item.)
27
+ * - **Small binary as a single JWE.** A `Blob`/`Uint8Array` under the size cap
28
+ * is wrapped and encrypted as one document; an oversized one is rejected
29
+ * (chunked encrypted blobs need the server's `chunked-streams` affordance).
30
+ * - **Enforced sequence (conditional writes).** The codec sets
31
+ * `conditionalWrites`, so the write path pre-reads the current envelope and
32
+ * hands it to `encode`: an update advances `sequence` from its prior value and
33
+ * pins the write to the server's current ETag via `If-Match`, while a fresh
34
+ * insert (`sequence: 0`) is guarded by `If-None-Match: *`. A stale write
35
+ * surfaces as a `PreconditionFailedError` (412) -- the lost-update guard --
36
+ * rather than the old advisory last-writer-wins. Against a backend that does
37
+ * not advertise `conditional-writes` (no ETag) it degrades to advisory.
38
+ * - **No server-visible metadata.** `allowsServerMetadata` is `false`, so
39
+ * `setName`/`setTags` throw on an encrypted collection (the core seam enforces
40
+ * this).
41
+ */
42
+ import { EdvClientCore } from '@interop/edv-client';
43
+ import { ValidationError } from '../errors.js';
44
+ import { readJsonData } from '../internal/content.js';
45
+ import { EDV_CONTENT_TYPE } from './WasTransport.js';
46
+ /**
47
+ * Default ceiling for a single-document (unchunked) encrypted binary write.
48
+ * Past this a `Blob`/`Uint8Array` is rejected until chunked encrypted blobs are
49
+ * supported. 1 MiB before the ~33% base64 inflation.
50
+ */
51
+ const DEFAULT_MAX_BLOB_BYTES = 1024 * 1024;
52
+ /**
53
+ * The default stored content type. Plain JSON keeps the codec portable across
54
+ * any document-capable server (the envelope is still self-identifying by its
55
+ * `jwe` field). Pass `contentType: EDV_CONTENT_TYPE`
56
+ * (`application/edv+json`) against a server that registers an
57
+ * `application/*+json` parser to mark envelopes distinctly in listings.
58
+ */
59
+ const DEFAULT_CONTENT_TYPE = 'application/json';
60
+ /**
61
+ * Marker property tagging an encrypted document whose decrypted content is a
62
+ * binary blob (rather than a JSON value), so `decode` can reconstruct a `Blob`.
63
+ * Namespaced to avoid colliding with caller JSON.
64
+ */
65
+ const BLOB_MARKER = '@interop/was-client:edvBlob';
66
+ /**
67
+ * Heuristic for an EDV document id: multibase base58btc (leading `z`) of a
68
+ * 128-bit value. Used to reject human-readable ids on `put()`. Deliberately a
69
+ * loose, dependency-free check (base58 charset, leading `z`, minimum length) --
70
+ * it rejects ids with human separators (`.`/`-`/`_`/spaces) and is not a full
71
+ * decode-and-length verification.
72
+ */
73
+ const EDV_DOC_ID = /^z[1-9A-HJ-NP-Za-km-z]{21,}$/;
74
+ const ENCODER = new TextEncoder();
75
+ function isBlob(value) {
76
+ return typeof Blob !== 'undefined' && value instanceof Blob;
77
+ }
78
+ /**
79
+ * Encodes bytes to standard base64 using the platform `btoa` (present in modern
80
+ * Node and browsers), via a binary string.
81
+ *
82
+ * @param bytes {Uint8Array}
83
+ * @returns {string}
84
+ */
85
+ function bytesToBase64(bytes) {
86
+ let binary = '';
87
+ for (const byte of bytes) {
88
+ binary += String.fromCharCode(byte);
89
+ }
90
+ return btoa(binary);
91
+ }
92
+ /**
93
+ * Decodes standard base64 to bytes using the platform `atob`.
94
+ *
95
+ * @param base64 {string}
96
+ * @returns {Uint8Array}
97
+ */
98
+ function base64ToBytes(base64) {
99
+ const binary = atob(base64);
100
+ const bytes = new Uint8Array(binary.length);
101
+ for (let index = 0; index < binary.length; index++) {
102
+ bytes[index] = binary.charCodeAt(index);
103
+ }
104
+ return bytes;
105
+ }
106
+ /**
107
+ * A {@link ResourceCodec} that encrypts on write and decrypts on read using an
108
+ * `EdvClientCore`'s JWE primitives. One instance is bound per encrypted
109
+ * collection handle.
110
+ */
111
+ export class EdvCodec {
112
+ allowsServerMetadata = false;
113
+ conditionalWrites = true;
114
+ _edv;
115
+ _keyAgreementKey;
116
+ _contentType;
117
+ _maxBlobBytes;
118
+ /**
119
+ * @param options {object}
120
+ * @param options.edv {EdvClientCore} holds the cipher + key resolver
121
+ * @param options.keyAgreementKey {IKeyAgreementKey} the recipient/decrypt key
122
+ * @param options.contentType {string} stored envelope content type
123
+ * @param options.maxBlobBytes {number} single-document binary cap
124
+ */
125
+ constructor({ edv, keyAgreementKey, contentType, maxBlobBytes }) {
126
+ this._edv = edv;
127
+ this._keyAgreementKey = keyAgreementKey;
128
+ this._contentType = contentType;
129
+ this._maxBlobBytes = maxBlobBytes;
130
+ }
131
+ /**
132
+ * @inheritdoc
133
+ */
134
+ async encode({ id, data, contentType, current }) {
135
+ if (id !== undefined && !EDV_DOC_ID.test(id)) {
136
+ throw new ValidationError(`Cannot write a human-readable id "${id}" to an encrypted collection ` +
137
+ '-- it would leak onto the URL. Use add() to mint an EDV document ' +
138
+ 'id, or carry the human-readable label inside the encrypted content.');
139
+ }
140
+ const docId = id ?? (await this._edv.generateId());
141
+ const content = await this._toContent(data, contentType);
142
+ // When the write path pre-read a current envelope, advance `sequence` from
143
+ // its prior value (`_encrypt({ update: true })` increments it) and pin the
144
+ // write to the server's current ETag with `If-Match`. With no prior envelope
145
+ // this is a fresh insert (`sequence: 0`) guarded by `If-None-Match: *`
146
+ // (create-if-absent), so a concurrent first writer cannot be clobbered.
147
+ const priorDoc = current
148
+ ? (await readJsonData(current))
149
+ : null;
150
+ const recipients = this._edv._createDefaultRecipients(this._keyAgreementKey);
151
+ const encrypted = await this._edv._encrypt({
152
+ doc: {
153
+ id: docId,
154
+ content,
155
+ ...(priorDoc && { sequence: priorDoc.sequence })
156
+ },
157
+ recipients,
158
+ keyResolver: this._edv.keyResolver,
159
+ hmac: undefined,
160
+ update: priorDoc !== null
161
+ });
162
+ return {
163
+ id: docId,
164
+ body: ENCODER.encode(JSON.stringify(encrypted)),
165
+ contentType: this._contentType,
166
+ // Pin an update to the server's current ETag; guard a fresh insert with
167
+ // create-if-absent. (An ETag is absent only against a backend without the
168
+ // conditional-writes feature, where this degrades to an advisory write.)
169
+ ...(priorDoc
170
+ ? { ifMatch: current.headers.get('etag') ?? undefined }
171
+ : { ifNoneMatch: true })
172
+ };
173
+ }
174
+ /**
175
+ * @inheritdoc
176
+ */
177
+ async decode(response) {
178
+ const encryptedDoc = (await readJsonData(response));
179
+ const decrypted = await this._edv._decrypt({
180
+ encryptedDoc,
181
+ keyAgreementKey: this._keyAgreementKey
182
+ });
183
+ return this._fromContent(decrypted.content);
184
+ }
185
+ /**
186
+ * Resolves a caller value to the EDV document `content`: a JSON object/array
187
+ * passes through; a `Blob`/`Uint8Array` (under the cap) is wrapped as a
188
+ * base64 blob record; a bare primitive is rejected (mirroring the plaintext
189
+ * `prepareBody` contract).
190
+ *
191
+ * @param data {Json | Blob | Uint8Array}
192
+ * @param [contentType] {string}
193
+ * @returns {Promise<object>}
194
+ */
195
+ async _toContent(data, contentType) {
196
+ if (isBlob(data)) {
197
+ const bytes = new Uint8Array(await data.arrayBuffer());
198
+ return this._blobContent(bytes, contentType || data.type || 'application/octet-stream');
199
+ }
200
+ if (data instanceof Uint8Array) {
201
+ return this._blobContent(data, contentType || 'application/octet-stream');
202
+ }
203
+ if (data !== null && typeof data === 'object') {
204
+ return data;
205
+ }
206
+ throw new ValidationError('Encrypted resource data must be a plain object/array (JSON) or a ' +
207
+ 'Blob/Uint8Array (binary).');
208
+ }
209
+ /**
210
+ * Wraps binary bytes as an EDV document content record, enforcing the
211
+ * single-document size cap.
212
+ *
213
+ * @param bytes {Uint8Array}
214
+ * @param contentType {string}
215
+ * @returns {object}
216
+ */
217
+ _blobContent(bytes, contentType) {
218
+ if (bytes.length > this._maxBlobBytes) {
219
+ throw new ValidationError(`Encrypted binary write of ${bytes.length} bytes exceeds the ` +
220
+ `single-document limit of ${this._maxBlobBytes} bytes. Chunked ` +
221
+ "encrypted blobs need the server's chunked-streams affordance " +
222
+ '(not yet available).');
223
+ }
224
+ return { [BLOB_MARKER]: true, contentType, base64: bytesToBase64(bytes) };
225
+ }
226
+ /**
227
+ * Reconstructs a caller value from decrypted EDV document content: a `Blob`
228
+ * for a wrapped blob record, otherwise the JSON content verbatim.
229
+ *
230
+ * @param content {unknown}
231
+ * @returns {Json | Blob}
232
+ */
233
+ _fromContent(content) {
234
+ if (content !== null &&
235
+ typeof content === 'object' &&
236
+ content[BLOB_MARKER] === true) {
237
+ const record = content;
238
+ return new Blob([base64ToBytes(record.base64)], {
239
+ type: record.contentType
240
+ });
241
+ }
242
+ return content;
243
+ }
244
+ }
245
+ /**
246
+ * Builds an {@link EncryptionProvider} that encrypts the collections the client
247
+ * holds keys for, wiring the per-collection keys (from `resolveKeys`) into an
248
+ * {@link EdvCodec}. Pass the result as `WasClient`'s `encryption` option; core
249
+ * resolves a codec for a collection exactly when `resolveKeys` returns keys for
250
+ * it (the switch is keys alone -- encryption is not a backend feature).
251
+ *
252
+ * @param options {object}
253
+ * @param options.resolveKeys {function} returns the collection's
254
+ * `{ keyAgreementKey, keyResolver }`, or `null` to read/write it as plaintext
255
+ * @param [options.contentType] {string} stored envelope content type;
256
+ * defaults to `application/json`. Pass `EDV_CONTENT_TYPE`
257
+ * (`application/edv+json`) against a server that registers an
258
+ * `application/*+json` parser.
259
+ * @param [options.maxBlobBytes] {number} single-document binary cap (default
260
+ * 1 MiB)
261
+ * @returns {EncryptionProvider}
262
+ */
263
+ export function createEdvEncryption({ resolveKeys, contentType = DEFAULT_CONTENT_TYPE, maxBlobBytes = DEFAULT_MAX_BLOB_BYTES }) {
264
+ return {
265
+ async resolveCodec({ spaceId, collectionId }) {
266
+ const keys = await resolveKeys({ spaceId, collectionId });
267
+ if (!keys) {
268
+ return null;
269
+ }
270
+ const edv = new EdvClientCore({
271
+ keyAgreementKey: keys.keyAgreementKey,
272
+ keyResolver: keys.keyResolver
273
+ });
274
+ return new EdvCodec({
275
+ edv,
276
+ keyAgreementKey: keys.keyAgreementKey,
277
+ contentType,
278
+ maxBlobBytes
279
+ });
280
+ }
281
+ };
282
+ }
283
+ export { EDV_CONTENT_TYPE };
284
+ //# sourceMappingURL=EdvCodec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EdvCodec.js","sourceRoot":"","sources":["../../src/edv/EdvCodec.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAYnD,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAA;AAErD,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AAEpD;;;;GAIG;AACH,MAAM,sBAAsB,GAAG,IAAI,GAAG,IAAI,CAAA;AAE1C;;;;;;GAMG;AACH,MAAM,oBAAoB,GAAG,kBAAkB,CAAA;AAE/C;;;;GAIG;AACH,MAAM,WAAW,GAAG,6BAA6B,CAAA;AAEjD;;;;;;GAMG;AACH,MAAM,UAAU,GAAG,8BAA8B,CAAA;AAEjD,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAA;AAEjC,SAAS,MAAM,CAAC,KAAc;IAC5B,OAAO,OAAO,IAAI,KA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B,CAAC,CAAA;YACF,OAAO,IAAI,QAAQ,CAAC;gBAClB,GAAG;gBACH,eAAe,EAAE,IAAI,CAAC,eAAe;gBACrC,WAAW;gBACX,YAAY;aACb,CAAC,CAAA;QACJ,CAAC;KACF,CAAA;AACH,CAAC;AAED,OAAO,EAAE,gBAAgB,EAAE,CAAA"}
@@ -6,6 +6,16 @@
6
6
  * support. Kept off the core `@interop/was-client` entry so plaintext consumers
7
7
  * do not pull the `@interop/edv-client` / `@interop/minimal-cipher` crypto graph
8
8
  * unless they opt in by importing this subpath.
9
+ *
10
+ * Two integration levels:
11
+ *
12
+ * - `createEdvEncryption` -- the encrypting codec for the handle
13
+ * seam. Pass its result as `WasClient`'s `encryption` option to make
14
+ * `collection.put`/`get` transparently encrypt the collections the client
15
+ * holds keys for.
16
+ * - `WasTransport` -- the standalone `@interop/edv-client`
17
+ * transport, for driving an `EdvClient` directly against WAS.
9
18
  */
19
+ export { createEdvEncryption, EdvCodec } from './EdvCodec.js';
10
20
  export { WasTransport, EDV_CONTENT_TYPE } from './WasTransport.js';
11
21
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/edv/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH;;;;;GAKG;AACH,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/edv/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,mBAAmB,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAC7D,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA"}
package/dist/edv/index.js CHANGED
@@ -6,6 +6,16 @@
6
6
  * support. Kept off the core `@interop/was-client` entry so plaintext consumers
7
7
  * do not pull the `@interop/edv-client` / `@interop/minimal-cipher` crypto graph
8
8
  * unless they opt in by importing this subpath.
9
+ *
10
+ * Two integration levels:
11
+ *
12
+ * - `createEdvEncryption` -- the encrypting codec for the handle
13
+ * seam. Pass its result as `WasClient`'s `encryption` option to make
14
+ * `collection.put`/`get` transparently encrypt the collections the client
15
+ * holds keys for.
16
+ * - `WasTransport` -- the standalone `@interop/edv-client`
17
+ * transport, for driving an `EdvClient` directly against WAS.
9
18
  */
19
+ export { createEdvEncryption, EdvCodec } from './EdvCodec.js';
10
20
  export { WasTransport, EDV_CONTENT_TYPE } from './WasTransport.js';
11
21
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/edv/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH;;;;;GAKG;AACH,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/edv/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,mBAAmB,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAC7D,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA"}
package/dist/errors.d.ts CHANGED
@@ -61,6 +61,17 @@ export declare class NotImplementedError extends WasError {
61
61
  export declare class ConflictError extends WasError {
62
62
  constructor(message: string, options?: WasErrorOptions);
63
63
  }
64
+ /**
65
+ * A conditional write's precondition evaluated false (HTTP 412): an `ifMatch`
66
+ * ETag did not match the Resource's current version (a lost-update conflict), or
67
+ * an `ifNoneMatch` create-if-absent target already exists. Recover by re-reading
68
+ * the current Resource (its new `etag`), re-applying the change, and retrying.
69
+ * Distinct from `ConflictError` (409), which is the header-less id/backend
70
+ * conflict family.
71
+ */
72
+ export declare class PreconditionFailedError extends WasError {
73
+ constructor(message: string, options?: WasErrorOptions);
74
+ }
64
75
  /**
65
76
  * A single upload exceeded the target backend's `maxUploadBytes` constraint
66
77
  * (HTTP 413). Unlike `QuotaExceededError`, this is per-request -- a smaller
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAWA;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAA;IACf;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;IAClB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB;AAED;;GAEG;AACH,qBAAa,QAAS,SAAQ,KAAK;IACjC,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;IAClB,UAAU,CAAC,EAAE,MAAM,CAAA;gBAEP,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,eAAoB;CAU3D;AAED;;;;GAIG;AACH,qBAAa,aAAc,SAAQ,QAAQ;gBAC7B,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,eAAoB;CAI3D;AAED;;GAEG;AACH,qBAAa,eAAgB,SAAQ,QAAQ;gBAC/B,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,eAAoB;CAI3D;AAED;;GAEG;AACH,qBAAa,iBAAkB,SAAQ,QAAQ;gBACjC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,eAAoB;CAI3D;AAED;;;GAGG;AACH,qBAAa,mBAAoB,SAAQ,QAAQ;gBACnC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,eAAoB;CAI3D;AAED;;;;;GAKG;AACH,qBAAa,aAAc,SAAQ,QAAQ;gBAC7B,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,eAA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AoB;CAI3D;AAED;;GAEG;AACH,qBAAa,eAAgB,SAAQ,QAAQ;gBAC/B,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,eAAoB;CAI3D;AAED;;GAEG;AACH,qBAAa,iBAAkB,SAAQ,QAAQ;gBACjC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,eAAoB;CAI3D;AAED;;;GAGG;AACH,qBAAa,mBAAoB,SAAQ,QAAQ;gBACnC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,eAAoB;CAI3D;AAED;;;;;GAKG;AACH,qBAAa,aAAc,SAAQ,QAAQ;gBAC7B,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,eAAoB;CAI3D;AAED;;;;;;;GAOG;AACH,qBAAa,uBAAwB,SAAQ,QAAQ;gBACvC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,eAAoB;CAI3D;AAED;;;;GAIG;AACH,qBAAa,oBAAqB,SAAQ,QAAQ;gBACpC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,eAAoB;CAI3D;AAED;;;;GAIG;AACH,qBAAa,kBAAmB,SAAQ,QAAQ;gBAClC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,eAAoB;CAI3D;AAED;;GAEG;AACH,qBAAa,cAAe,SAAQ,QAAQ;gBAC9B,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,eAAoB;CAI3D;AA8ED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAG3D;AAED;;;;;;;;GAQG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,OAAO,GAAG,QAAQ,CA+C/C"}
package/dist/errors.js CHANGED
@@ -79,6 +79,20 @@ export class ConflictError extends WasError {
79
79
  this.name = 'ConflictError';
80
80
  }
81
81
  }
82
+ /**
83
+ * A conditional write's precondition evaluated false (HTTP 412): an `ifMatch`
84
+ * ETag did not match the Resource's current version (a lost-update conflict), or
85
+ * an `ifNoneMatch` create-if-absent target already exists. Recover by re-reading
86
+ * the current Resource (its new `etag`), re-applying the change, and retrying.
87
+ * Distinct from `ConflictError` (409), which is the header-less id/backend
88
+ * conflict family.
89
+ */
90
+ export class PreconditionFailedError extends WasError {
91
+ constructor(message, options = {}) {
92
+ super(message, options);
93
+ this.name = 'PreconditionFailedError';
94
+ }
95
+ }
82
96
  /**
83
97
  * A single upload exceeded the target backend's `maxUploadBytes` constraint
84
98
  * (HTTP 413). Unlike `QuotaExceededError`, this is per-request -- a smaller
@@ -137,6 +151,7 @@ const ERROR_CLASS_BY_KIND = {
137
151
  [problemFragment(ProblemTypes.RESERVED_ID)]: ConflictError,
138
152
  [problemFragment(ProblemTypes.ID_CONFLICT)]: ConflictError,
139
153
  [problemFragment(ProblemTypes.UNSUPPORTED_BACKEND)]: ConflictError,
154
+ [problemFragment(ProblemTypes.PRECONDITION_FAILED)]: PreconditionFailedError,
140
155
  [problemFragment(ProblemTypes.PAYLOAD_TOO_LARGE)]: PayloadTooLargeError,
141
156
  [problemFragment(ProblemTypes.QUOTA_EXCEEDED)]: QuotaExceededError,
142
157
  [problemFragment(ProblemTypes.UNSUPPORTED_OPERATION)]: NotImplementedError,
@@ -206,6 +221,8 @@ export function mapError(err) {
206
221
  return new NotFoundError(message, options);
207
222
  case 409:
208
223
  return new ConflictError(message, options);
224
+ case 412:
225
+ return new PreconditionFailedError(message, options);
209
226
  case 413:
210
227
  return new PayloadTooLargeError(message, options);
211
228
  case 501:
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH;;;;;GAKG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AAmBpD;;GAEG;AACH,MAAM,OAAO,QAAS,SAAQ,KAAK;IACjC,MAAM,CAAS;IACf,IAAI,CAAS;IACb,KAAK,CAAS;IACd,OAAO,CAAW;IAClB,UAAU,CAAS;IAEnB,YAAY,OA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OAAO,IAAI,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;AACvC,CAAC"}
package/dist/index.d.ts CHANGED
@@ -9,6 +9,7 @@ export { WasClient } from './WasClient.js';
9
9
  export { Space } from './Space.js';
10
10
  export { Collection } from './Collection.js';
11
11
  export { Resource } from './Resource.js';
12
- export { WasError, NotFoundError, ValidationError, AuthRequiredError, NotImplementedError, ConflictError, PayloadTooLargeError, QuotaExceededError, WasServerError, mapError } from './errors.js';
12
+ export { WasError, NotFoundError, ValidationError, AuthRequiredError, NotImplementedError, ConflictError, PreconditionFailedError, PayloadTooLargeError, QuotaExceededError, WasServerError, mapError } from './errors.js';
13
+ export type { ResourceCodec, EncryptionProvider, EncodedWrite } from './codec.js';
13
14
  export type { Json, JsonPrimitive, JsonObject, JsonArray, Action, ActionInput, SpaceDescription, CollectionDescription, CollectionSummary, CollectionsList, SpaceSummary, SpaceListing, ResourceSummary, CollectionResourcesList, ResourceMetadata, ResourceMetadataCustom, AddResult, ImportStats, PolicyDocument, LinkSet, LinkSetEntry, HandleOptions, BackendReference, BackendDescriptor, StorageLimit, CollectionUsage, BackendUsage, SpaceQuotaReport, GrantOptions, RequestInput, IZcap, IDelegatedZcap, ISigner } from './types.js';
14
15
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH;;;GAGG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAExC,OAAO,EACL,QAAQ,EACR,aAAa,EACb,eAAe,EACf,iBAAiB,EACjB,mBAAmB,EACnB,aAAa,EACb,oBAAoB,EACpB,kBAAkB,EAClB,cAAc,EACd,QAAQ,EACT,MAAM,aAAa,CAAA;AAEpB,YAAY,EACV,IAAI,EACJ,aAAa,EACb,UAAU,EACV,SAAS,EACT,MAAM,EACN,WAAW,EACX,gBAAgB,EAChB,qBAAqB,EACrB,iBAAiB,EACjB,eAAe,EACf,YAAY,EACZ,YAAY,EACZ,eAAe,EACf,uBAAuB,EACvB,gBAAgB,EAChB,sBAAsB,EACtB,SAAS,EACT,WAAW,EACX,cAAc,EACd,OAAO,EACP,YAAY,EACZ,aAAa,EACb,gBAAgB,EAChB,iBAAiB,EACjB,YAAY,EACZ,eAAe,EACf,YAAY,EACZ,gBAAgB,EAChB,YAAY,EACZ,YAAY,EACZ,KAAK,EACL,cAAc,EACd,OAAO,EACR,MAAM,YAAY,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH;;;GAGG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAExC,OAAO,EACL,QAAQ,EACR,aAAa,EACb,eAAe,EACf,iBAAiB,EACjB,mBAAmB,EACnB,aAAa,EACb,uBAAuB,EACvB,oBAAoB,EACpB,kBAAkB,EAClB,cAAc,EACd,QAAQ,EACT,MAAM,aAAa,CAAA;AAEpB,YAAY,EACV,aAAa,EACb,kBAAkB,EAClB,YAAY,EACb,MAAM,YAAY,CAAA;AAEnB,YAAY,EACV,IAAI,EACJ,aAAa,EACb,UAAU,EACV,SAAS,EACT,MAAM,EACN,WAAW,EACX,gBAAgB,EAChB,qBAAqB,EACrB,iBAAiB,EACjB,eAAe,EACf,YAAY,EACZ,YAAY,EACZ,eAAe,EACf,uBAAuB,EACvB,gBAAgB,EAChB,sBAAsB,EACtB,SAAS,EACT,WAAW,EACX,cAAc,EACd,OAAO,EACP,YAAY,EACZ,aAAa,EACb,gBAAgB,EAChB,iBAAiB,EACjB,YAAY,EACZ,eAAe,EACf,YAAY,EACZ,gBAAgB,EAChB,YAAY,EACZ,YAAY,EACZ,KAAK,EACL,cAAc,EACd,OAAO,EACR,MAAM,YAAY,CAAA"}
package/dist/index.js CHANGED
@@ -9,5 +9,5 @@ export { WasClient } from './WasClient.js';
9
9
  export { Space } from './Space.js';
10
10
  export { Collection } from './Collection.js';
11
11
  export { Resource } from './Resource.js';
12
- export { WasError, NotFoundError, ValidationError, AuthRequiredError, NotImplementedError, ConflictError, PayloadTooLargeError, QuotaExceededError, WasServerError, mapError } from './errors.js';
12
+ export { WasError, NotFoundError, ValidationError, AuthRequiredError, NotImplementedError, ConflictError, PreconditionFailedError, PayloadTooLargeError, QuotaExceededError, WasServerError, mapError } from './errors.js';
13
13
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH;;;GAGG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAExC,OAAO,EACL,QAAQ,EACR,aAAa,EACb,eAAe,EACf,iBAAiB,EACjB,mBAAmB,EACnB,aAAa,EACb,oBAAoB,EACpB,kBAAkB,EAClB,cAAc,EACd,QAAQ,EACT,MAAM,aAAa,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH;;;GAGG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAExC,OAAO,EACL,QAAQ,EACR,aAAa,EACb,eAAe,EACf,iBAAiB,EACjB,mBAAmB,EACnB,aAAa,EACb,uBAAuB,EACvB,oBAAoB,EACpB,kBAAkB,EAClB,cAAc,EACd,QAAQ,EACT,MAAM,aAAa,CAAA"}
@@ -0,0 +1,27 @@
1
+ import type { ResourceCodec } from '../codec.js';
2
+ import type { ClientContext } from './request.js';
3
+ /**
4
+ * The default codec: passes plaintext through unchanged. `encode` echoes the
5
+ * caller's `id` (so `put(id, ...)` is a `PUT` and `add(...)`, with no id, stays
6
+ * a server-minting `POST`) and reuses `prepareBody` -- including the
7
+ * filename-extension content-type guess when an id is present. `decode` reuses
8
+ * `parseResource`.
9
+ */
10
+ export declare const identityCodec: ResourceCodec;
11
+ /**
12
+ * Resolves the codec for a collection. Returns {@link identityCodec} unless an
13
+ * {@link EncryptionProvider} is injected and returns a codec for the collection
14
+ * (i.e. the client holds keys for it). No backend round-trip: whether a
15
+ * collection is encrypted is a client/key concern, not a backend capability.
16
+ *
17
+ * @param context {ClientContext}
18
+ * @param options {object}
19
+ * @param options.spaceId {string}
20
+ * @param options.collectionId {string}
21
+ * @returns {Promise<ResourceCodec>}
22
+ */
23
+ export declare function resolveCodec(context: ClientContext, { spaceId, collectionId }: {
24
+ spaceId: string;
25
+ collectionId: string;
26
+ }): Promise<ResourceCodec>;
27
+ //# sourceMappingURL=codec.d.ts.map