@vol-a/client 0.0.0-stage → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +254 -2
- package/dist/body.d.ts +40 -0
- package/dist/body.d.ts.map +1 -0
- package/dist/body.js +112 -0
- package/dist/body.js.map +1 -0
- package/dist/client.d.ts +161 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +245 -0
- package/dist/client.js.map +1 -0
- package/dist/env.d.ts +19 -0
- package/dist/env.d.ts.map +1 -0
- package/dist/env.js +52 -0
- package/dist/env.js.map +1 -0
- package/dist/errors.d.ts +43 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +93 -0
- package/dist/errors.js.map +1 -0
- package/dist/files.d.ts +144 -0
- package/dist/files.d.ts.map +1 -0
- package/dist/files.js +239 -0
- package/dist/files.js.map +1 -0
- package/dist/folders.d.ts +35 -0
- package/dist/folders.d.ts.map +1 -0
- package/dist/folders.js +62 -0
- package/dist/folders.js.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/keyrings.d.ts +44 -0
- package/dist/keyrings.d.ts.map +1 -0
- package/dist/keyrings.js +111 -0
- package/dist/keyrings.js.map +1 -0
- package/dist/management.d.ts +47 -0
- package/dist/management.d.ts.map +1 -0
- package/dist/management.js +65 -0
- package/dist/management.js.map +1 -0
- package/dist/shares.d.ts +87 -0
- package/dist/shares.d.ts.map +1 -0
- package/dist/shares.js +144 -0
- package/dist/shares.js.map +1 -0
- package/dist/uploads.d.ts +112 -0
- package/dist/uploads.d.ts.map +1 -0
- package/dist/uploads.js +290 -0
- package/dist/uploads.js.map +1 -0
- package/package.json +48 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Digital Cube
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,255 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @vol-a/client
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The JSVola SDK: a `fetch`-based client for the `@vol-a/server` API. Runs in **Node 24+ and in
|
|
4
|
+
browsers**, depends on `@vol-a/core` (the protocol: Zod schemas and types) and `@jsudc/core`
|
|
5
|
+
(the UDC client behind `vola.udc`) and on nothing else. `fetch` can be injected.
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @vol-a/client
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import { VolaClient } from "@vol-a/client";
|
|
13
|
+
|
|
14
|
+
const vola = new VolaClient({
|
|
15
|
+
baseUrl: "https://files.example.com/vola", // the mount prefix included
|
|
16
|
+
apiKey: process.env.VOLA_API_KEY, // `Authorization: Bearer …`
|
|
17
|
+
userId: "user-42", // `X-User-Id`: attribution, and the keyring owner
|
|
18
|
+
// tenantSlug: "acme", // `X-Tenant-Slug`, for an ADMIN key
|
|
19
|
+
// fetch: myFetch, // tests, retries, a proxy
|
|
20
|
+
// validate: true, // check every answer against its @vol-a/core schema
|
|
21
|
+
});
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Every answer is typed by the `@vol-a/core` schema of its route (`FileInfo`, `FolderListing`,
|
|
25
|
+
`ShareCreated`, `KeyringStatus`, …). `validate: true` also parses it (a mismatch is a
|
|
26
|
+
`VolaError` with code `invalid_response`); off by default.
|
|
27
|
+
|
|
28
|
+
## Errors
|
|
29
|
+
|
|
30
|
+
A non-2xx answer throws a `VolaError` carrying the server's envelope:
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
import { VolaError, VolaLockedError, VolaIntegrityError } from "@vol-a/client";
|
|
34
|
+
|
|
35
|
+
try {
|
|
36
|
+
await vola.files.info("tickets", id, fileId);
|
|
37
|
+
} catch (error) {
|
|
38
|
+
if (error instanceof VolaLockedError) {
|
|
39
|
+
// 423 vola_locked: a keyring file without its unlock, a caller file without its key
|
|
40
|
+
} else if (error instanceof VolaIntegrityError) {
|
|
41
|
+
// 409 vola_integrity: a wrong key or secret, or damaged bytes
|
|
42
|
+
} else if (error instanceof VolaError) {
|
|
43
|
+
error.status; // 404
|
|
44
|
+
error.code; // "file_not_found" — snake_case, stable
|
|
45
|
+
error.message;
|
|
46
|
+
error.retryAfter; // seconds, when the server said so (429, lock-outs)
|
|
47
|
+
error.details; // the rest of the envelope: `required` scopes, `attempts`, `reason`…
|
|
48
|
+
error.requestId; // `X-Request-Id`
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Transport failures (no network, a refused connection) throw what `fetch` throws. An aborted
|
|
54
|
+
`signal` rejects with the `AbortError` of the platform.
|
|
55
|
+
|
|
56
|
+
No secret — the API key, an unlock token, a content key, a share secret, a PIN — is ever put
|
|
57
|
+
in a URL, an error message or a log line by the SDK.
|
|
58
|
+
|
|
59
|
+
## Files
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
// Upload: a File/Blob, a Uint8Array/Buffer, an ArrayBuffer, a ReadableStream or any async
|
|
63
|
+
// iterable of bytes (a Node Readable) — streams go up without being buffered.
|
|
64
|
+
const info = await vola.files.upload("tickets", ticketId, file, {
|
|
65
|
+
filename: "Izveštaj.pdf", // required unless the source is a File
|
|
66
|
+
contentType: "application/pdf",
|
|
67
|
+
folderPath: "docs/q4", // created when missing; or folderId
|
|
68
|
+
parentId: previousVersionId, // a new version
|
|
69
|
+
metadata: { year: 2026 },
|
|
70
|
+
encryption: "tenant", // "none" | "tenant" | "keyring" | "caller"
|
|
71
|
+
});
|
|
72
|
+
await vola.files.putSlug("user_profiles", userId, "avatar", blob, { filename: "me.png" });
|
|
73
|
+
|
|
74
|
+
// Download: a streaming Response, never a buffer.
|
|
75
|
+
const response = await vola.files.download("tickets", ticketId, info.id);
|
|
76
|
+
response.body; // ReadableStream
|
|
77
|
+
await response.blob();
|
|
78
|
+
const part = await vola.files.download("tickets", ticketId, info.id, {
|
|
79
|
+
range: { start: 0, end: 1023 }, // 206; also { suffix: 100 } or "bytes=0-99"
|
|
80
|
+
ifNoneMatch: '"<etag>"', // 304 resolves (empty body)
|
|
81
|
+
download: true, // Content-Disposition: attachment
|
|
82
|
+
});
|
|
83
|
+
await vola.files.head("tickets", ticketId, info.id);
|
|
84
|
+
await vola.files.byPath("tickets", ticketId, "docs/q4/Izveštaj.pdf");
|
|
85
|
+
await vola.files.bySlug("user_profiles", userId, "avatar");
|
|
86
|
+
await vola.files.public(fileId); // GET /public/:fileId, no key
|
|
87
|
+
|
|
88
|
+
// Metadata
|
|
89
|
+
const detail = await vola.files.info("tickets", ticketId, info.id, { ocr: "full" });
|
|
90
|
+
detail.processing_status; detail.ocr.text;
|
|
91
|
+
const page = await vola.files.list("tickets", ticketId, { limit: 50, cursor });
|
|
92
|
+
for await (const file of vola.files.iterate("tickets", ticketId)) { /* every page */ }
|
|
93
|
+
await vola.files.versions("tickets", ticketId, info.id);
|
|
94
|
+
await vola.files.patch("tickets", ticketId, info.id, { folder_path: "archive", is_public: true });
|
|
95
|
+
await vola.files.delete("tickets", ticketId, info.id); // soft
|
|
96
|
+
await vola.files.purge("tickets", ticketId, info.id); // rows and blobs
|
|
97
|
+
|
|
98
|
+
// Thumbnails: a 202 is NOT the image.
|
|
99
|
+
const thumb = await vola.files.thumb("tickets", ticketId, info.id, 256, { crop: "fit" });
|
|
100
|
+
if (thumb.status === "ready") img.src = URL.createObjectURL(thumb.blob);
|
|
101
|
+
else if (thumb.status === "generating") setTimeout(retry, 1000); // the worker is on it
|
|
102
|
+
else if (thumb.status === "failed") showPlaceholder(); // the file cannot be rendered
|
|
103
|
+
vola.files.thumbUrl("tickets", ticketId, info.id, 128); // a URL WITHOUT credentials
|
|
104
|
+
vola.files.downloadUrl("tickets", ticketId, info.id);
|
|
105
|
+
vola.files.publicUrl(fileId);
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Folders
|
|
109
|
+
|
|
110
|
+
```ts
|
|
111
|
+
await vola.folders.create("tickets", ticketId, "docs/q4"); // and missing parents
|
|
112
|
+
const { folder, subfolders, files } = await vola.folders.list("tickets", ticketId, "docs");
|
|
113
|
+
await vola.folders.rename("tickets", ticketId, "docs/q4", "q4-final");
|
|
114
|
+
await vola.folders.move("tickets", ticketId, "docs/q4-final", "archive");
|
|
115
|
+
await vola.folders.setDefaultKeyring("tickets", ticketId, "private", "me"); // encrypted folder
|
|
116
|
+
await vola.folders.delete("tickets", ticketId, "archive", { recursive: true });
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## Resumable uploads
|
|
120
|
+
|
|
121
|
+
```ts
|
|
122
|
+
const { fileId } = await vola.uploads.resumable("tickets", ticketId, file, {
|
|
123
|
+
filename: "video.mp4",
|
|
124
|
+
chunkSize: 8 * 1024 * 1024,
|
|
125
|
+
onProgress: ({ uploaded, total }) => setPercent((100 * uploaded) / total),
|
|
126
|
+
signal: controller.signal,
|
|
127
|
+
// fingerprint: "my-key", store: myStore, folderPath, parentId, slug, metadata, encryption…
|
|
128
|
+
});
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
The source must be sliceable (a `File`/`Blob`, a `Uint8Array`/`Buffer`, an `ArrayBuffer`; in
|
|
132
|
+
Node, `openAsBlob(path)` from `node:fs`). The upload is remembered under a fingerprint
|
|
133
|
+
(`localStorage` in a browser, memory in Node, or any `{get, set, remove}` store you pass): an
|
|
134
|
+
abort or a network failure in the middle of a chunk rejects, and the next call with the same
|
|
135
|
+
source `HEAD`s the server for its offset and `PATCH`es from there. The fingerprint is forgotten
|
|
136
|
+
once the file exists. The steps are available on their own: `uploads.create`, `uploads.status`,
|
|
137
|
+
`uploads.append`, `uploads.abort`, `uploads.protocol`.
|
|
138
|
+
|
|
139
|
+
## Shares
|
|
140
|
+
|
|
141
|
+
```ts
|
|
142
|
+
const share = await vola.shares.create({
|
|
143
|
+
file_id: info.id, // or folder: { instance_type, instance_id, path }
|
|
144
|
+
password: "lozinka",
|
|
145
|
+
expires_at: "2026-12-31T00:00:00Z",
|
|
146
|
+
max_downloads: 10,
|
|
147
|
+
});
|
|
148
|
+
share.url; // https://files.example.com/vola/s/<token> — for an ENCRYPTED file: …#<secret>
|
|
149
|
+
await vola.shares.list({ fileId: info.id });
|
|
150
|
+
await vola.shares.get(share.id);
|
|
151
|
+
await vola.shares.revoke(share.id);
|
|
152
|
+
|
|
153
|
+
// The recipient's side: anonymous, the fragment becomes `X-Share-Secret`.
|
|
154
|
+
const response = await VolaClient.openShare(share.url, { password: "lozinka", range: { start: 0 } });
|
|
155
|
+
const listing = await vola.shares.listing(folderShareUrl); // a folder share
|
|
156
|
+
await vola.shares.open(folderShareUrl, { path: "sub/report.pdf" }); // a file inside it
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
A `caller`-encrypted file (Node only) can be shared with a grant the caller makes itself,
|
|
160
|
+
since the server never holds that file's key: `vola.shares.createCallerGrant(fileId, fileKey)`
|
|
161
|
+
wraps the file key under a fresh secret with WebCrypto and returns a `url` with the fragment.
|
|
162
|
+
|
|
163
|
+
## Keyrings (PIN) and unlock
|
|
164
|
+
|
|
165
|
+
```ts
|
|
166
|
+
const { recovery_key } = await vola.keyrings.setup("493817"); // show it ONCE
|
|
167
|
+
const { expires_in } = await vola.keyrings.unlock("493817"); // the token is kept in memory
|
|
168
|
+
await vola.files.upload("tickets", ticketId, file, { filename: "Tajna.pdf", encryption: "keyring" });
|
|
169
|
+
await vola.files.download("tickets", ticketId, fileId); // `X-Vola-Unlock` goes along
|
|
170
|
+
await vola.keyrings.status(); // locked, unlock_expires_in, attempts…
|
|
171
|
+
await vola.lock(); // DELETE the token, forget it
|
|
172
|
+
await vola.keyrings.changePin("493817", "271828"); // every token dies
|
|
173
|
+
await vola.keyrings.recover(recovery_key, "271828"); // a NEW recovery key comes back
|
|
174
|
+
await vola.keyrings.deletePreview();
|
|
175
|
+
await vola.keyrings.reset(); // the crypto-shred — re-authenticate first
|
|
176
|
+
|
|
177
|
+
const other = vola.withUnlock(token); // a second instance that sends a token you obtained elsewhere
|
|
178
|
+
const off = vola.lockOnUnload(); // browser: `navigator.sendBeacon` ends the unlock on pagehide
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
The token lives in the instance's memory only; `lock()`, `changePin()`, `recover()` and
|
|
182
|
+
`reset()` clear it. A `423` — `VolaLockedError` — means the request needed an unlock it did not
|
|
183
|
+
have (or the token expired: the server's TTL slides with every request that carries it).
|
|
184
|
+
|
|
185
|
+
## Caller encryption (server-to-server)
|
|
186
|
+
|
|
187
|
+
```ts
|
|
188
|
+
const contentKey = crypto.getRandomValues(new Uint8Array(32)); // yours to keep; vola stores nothing
|
|
189
|
+
const info = await vola.files.upload("tickets", id, buffer, { filename: "x", encryption: "caller", contentKey });
|
|
190
|
+
await vola.files.download("tickets", id, info.id, { contentKey }); // on EVERY read
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
`contentKey` is refused in a browser (`caller_key_from_browser`, before any request): the
|
|
194
|
+
server rejects every request with an `Origin`, and the key would live in the page.
|
|
195
|
+
|
|
196
|
+
## Stats, keys, admin, lookups, UDC
|
|
197
|
+
|
|
198
|
+
```ts
|
|
199
|
+
await vola.stats.tenant({ recompute: true });
|
|
200
|
+
await vola.stats.instance("tickets", ticketId);
|
|
201
|
+
await vola.stats.storage();
|
|
202
|
+
await vola.instanceTypes();
|
|
203
|
+
await vola.lookups("sr"); // no key needed
|
|
204
|
+
await vola.live(); await vola.ready();
|
|
205
|
+
await vola.keys.create({ name: "ci", scopes: ["files:read"], env: "test" });
|
|
206
|
+
await vola.keys.list(); await vola.keys.revoke(id);
|
|
207
|
+
await vola.admin.transfer({ from_tenant: "a", to_tenant: "b", instances: [...], dry_run: true });
|
|
208
|
+
|
|
209
|
+
// The UDC collections (`files`, `menu`…) through @jsudc/core's UdcClient, same auth:
|
|
210
|
+
const { rows } = await vola.udc.list({ collection: "files", filter: { field: "kind", op: "eq", value: "image" } });
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
`vola.request(path, options)` and `vola.json(path, schema, options)` are the escape hatch every
|
|
214
|
+
group is built on — for a route this version of the SDK does not wrap yet.
|
|
215
|
+
|
|
216
|
+
## Migration from the vola-spp API
|
|
217
|
+
|
|
218
|
+
The API is new and not compatible with vola-spp (plan decision 1). Old route → SDK method:
|
|
219
|
+
|
|
220
|
+
| vola-spp | `@vol-a/client` |
|
|
221
|
+
|---|---|
|
|
222
|
+
| `POST /api/v1/files/{type}/id/{id}` (multipart, `folder_path` / `folder_id` / `parent_id`) | `vola.files.upload(type, id, source, { folderPath, folderId, parentId })` |
|
|
223
|
+
| `PUT /api/v1/files/{type}/id/{id}/slug/{slug}` | `vola.files.putSlug(type, id, slug, source)` |
|
|
224
|
+
| `GET\|HEAD …/id/{file_id}` (Range / 206) | `vola.files.download(type, id, fileId, { range })`, `vola.files.head(...)` |
|
|
225
|
+
| `GET …/path/{path}` | `vola.files.byPath(type, id, path)` |
|
|
226
|
+
| `GET …/slug/{slug}` | `vola.files.bySlug(type, id, slug)` |
|
|
227
|
+
| `GET …/info` | `vola.files.info(type, id, fileId)` |
|
|
228
|
+
| `GET …/thumb/{size}?crop=` (202 = placeholder) | `vola.files.thumb(type, id, fileId, size, { crop })` → `{status: "ready" \| "generating" \| "failed"}` |
|
|
229
|
+
| `PATCH …/visibility` | `vola.files.patch(type, id, fileId, { is_public, is_global_public })` |
|
|
230
|
+
| `PATCH …/move` | `vola.files.patch(type, id, fileId, { folder_path })` |
|
|
231
|
+
| `DELETE …` (soft) | `vola.files.delete(type, id, fileId)` |
|
|
232
|
+
| `DELETE …/purge` | `vola.files.purge(type, id, fileId)` |
|
|
233
|
+
| `POST /api/v1/folders/{type}/id/{id}/path/{path}` | `vola.folders.create(type, id, path)` |
|
|
234
|
+
| `GET …/folders/…/path/{path}` | `vola.folders.list(type, id, path)` |
|
|
235
|
+
| `PATCH …/folders/…/path/{path}` | `vola.folders.rename(...)`, `vola.folders.move(...)`, `vola.folders.patch(...)` |
|
|
236
|
+
| `DELETE …/folders/…/path/{path}` | `vola.folders.delete(type, id, path, { recursive })` |
|
|
237
|
+
| `POST /api/v1/share` | `vola.shares.create({ file_id \| folder, password, expires_at, max_downloads })` |
|
|
238
|
+
| `DELETE /api/v1/share/id/{id}` | `vola.shares.revoke(id)` |
|
|
239
|
+
| `GET\|HEAD /share/token/{t}[/download\|/path/{p}]` | `VolaClient.openShare(url, { password, path, download })`, `vola.shares.listing(url)` |
|
|
240
|
+
| `GET\|HEAD /public/file/{id}` | `vola.files.public(fileId)`, `vola.files.publicUrl(fileId)` |
|
|
241
|
+
| `GET /api/v1/stats/tenant` | `vola.stats.tenant()` |
|
|
242
|
+
| `GET /api/v1/stats/instance/{type}/id/{id}` | `vola.stats.instance(type, id)` |
|
|
243
|
+
| `GET /api/v1/stats/storage` | `vola.stats.storage()` |
|
|
244
|
+
| `GET /api/v1/instance-types` | `vola.instanceTypes()` |
|
|
245
|
+
| `POST /api/v1/keys` | `vola.keys.create(...)` (and `list`, `revoke`) |
|
|
246
|
+
| `POST /api/v1/admin/transfer` | `vola.admin.transfer(...)` |
|
|
247
|
+
| `POST /udc/list\|describe\|read` | `vola.udc.list(...)`, `vola.udc.describe(...)`, `vola.udc.read(...)` |
|
|
248
|
+
| `GET /api/lookups` | `vola.lookups(locale)` |
|
|
249
|
+
| `X-API-Key` header | `apiKey` option (sent as `Authorization: Bearer`); `X-Tenant-Slug` → `tenantSlug` |
|
|
250
|
+
| — (new) | `vola.uploads.resumable(...)`, `vola.keyrings.*`, `encryption` / `contentKey` on uploads, share grants |
|
|
251
|
+
|
|
252
|
+
What changed beyond the names: the id of an instance is in the path (`/files/:type/:id`, no
|
|
253
|
+
`/id/` segment); visibility and move are one `PATCH` with a JSON body; a share is created with
|
|
254
|
+
a JSON body and followed at `/s/<token>`; the error envelope is `{ error: { code, message } }`
|
|
255
|
+
with stable snake_case codes.
|
package/dist/body.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/** Bytes that are all in memory (or in a `Blob`): they can be sized and sliced, so they can be resumed. */
|
|
2
|
+
export type ByteSource = Blob | Uint8Array | ArrayBuffer;
|
|
3
|
+
/** Bytes that arrive over time: a web `ReadableStream`, or anything async-iterable (a Node `Readable`, a generator). */
|
|
4
|
+
export type StreamSource = ReadableStream<Uint8Array> | AsyncIterable<Uint8Array>;
|
|
5
|
+
/** What an upload accepts. A Node `Buffer` is a `Uint8Array`; a `File` is a `Blob` that also carries its name. */
|
|
6
|
+
export type UploadSource = ByteSource | StreamSource;
|
|
7
|
+
export declare function isBlob(value: unknown): value is Blob;
|
|
8
|
+
export declare function isStreamSource(value: unknown): value is StreamSource;
|
|
9
|
+
/** The byte length of an in-memory source. */
|
|
10
|
+
export declare function sizeOf(source: ByteSource): number;
|
|
11
|
+
/** `source[start, end)` as something `fetch` sends as a body. */
|
|
12
|
+
export declare function sliceOf(source: ByteSource, start: number, end: number): Blob | Uint8Array;
|
|
13
|
+
/** An in-memory source as a `Blob` of `type`. */
|
|
14
|
+
export declare function toBlob(source: ByteSource, type?: string): Blob;
|
|
15
|
+
/** The name a `File` carries, when the source is one. */
|
|
16
|
+
export declare function nameOf(source: UploadSource): string | undefined;
|
|
17
|
+
/** The MIME type a `Blob` carries, when it has one. */
|
|
18
|
+
export declare function typeOf(source: UploadSource): string | undefined;
|
|
19
|
+
export interface MultipartFile {
|
|
20
|
+
field: string;
|
|
21
|
+
filename: string;
|
|
22
|
+
contentType: string;
|
|
23
|
+
source: UploadSource;
|
|
24
|
+
}
|
|
25
|
+
export interface MultipartBody {
|
|
26
|
+
body: BodyInit;
|
|
27
|
+
/** Set when the body is a stream the SDK framed itself; `undefined` lets `fetch` frame the `FormData`. */
|
|
28
|
+
contentType: string | undefined;
|
|
29
|
+
/** `true`: the body is a `ReadableStream` (the request needs `duplex: "half"`). */
|
|
30
|
+
streaming: boolean;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The `multipart/form-data` body of an upload: the text `fields` FIRST, in order (the server
|
|
34
|
+
* reads the encryption mode and the folder before the file part starts), then the one file
|
|
35
|
+
* part. An in-memory source becomes a `FormData` (the platform frames it); a stream is framed
|
|
36
|
+
* here and sent as a `ReadableStream`, so a file of any size goes up without being read into
|
|
37
|
+
* memory (Node; in a browser, give a `File` or a `Blob`).
|
|
38
|
+
*/
|
|
39
|
+
export declare function multipartBody(fields: [string, string][], file: MultipartFile): MultipartBody;
|
|
40
|
+
//# sourceMappingURL=body.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"body.d.ts","sourceRoot":"","sources":["../src/body.ts"],"names":[],"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;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,EAAE,IAAI,EAAE,aAAa,GAAG,aAAa,CAiC5F"}
|
package/dist/body.js
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { randomHex } from "./env.js";
|
|
2
|
+
export function isBlob(value) {
|
|
3
|
+
return typeof Blob !== "undefined" && value instanceof Blob;
|
|
4
|
+
}
|
|
5
|
+
export function isStreamSource(value) {
|
|
6
|
+
if (typeof ReadableStream !== "undefined" && value instanceof ReadableStream)
|
|
7
|
+
return true;
|
|
8
|
+
return (typeof value === "object" &&
|
|
9
|
+
value !== null &&
|
|
10
|
+
!isBlob(value) &&
|
|
11
|
+
!(value instanceof Uint8Array) &&
|
|
12
|
+
!(value instanceof ArrayBuffer) &&
|
|
13
|
+
Symbol.asyncIterator in value);
|
|
14
|
+
}
|
|
15
|
+
/** The byte length of an in-memory source. */
|
|
16
|
+
export function sizeOf(source) {
|
|
17
|
+
if (isBlob(source))
|
|
18
|
+
return source.size;
|
|
19
|
+
return source.byteLength;
|
|
20
|
+
}
|
|
21
|
+
/** `source[start, end)` as something `fetch` sends as a body. */
|
|
22
|
+
export function sliceOf(source, start, end) {
|
|
23
|
+
if (isBlob(source))
|
|
24
|
+
return source.slice(start, end);
|
|
25
|
+
if (source instanceof ArrayBuffer)
|
|
26
|
+
return new Uint8Array(source, start, end - start);
|
|
27
|
+
return source.subarray(start, end);
|
|
28
|
+
}
|
|
29
|
+
/** An in-memory source as a `Blob` of `type`. */
|
|
30
|
+
export function toBlob(source, type) {
|
|
31
|
+
if (isBlob(source))
|
|
32
|
+
return type && source.type !== type ? source.slice(0, source.size, type) : source;
|
|
33
|
+
// A fresh copy: `Blob` takes the view as is, and a `Buffer` from a pool would drag its neighbours in.
|
|
34
|
+
const bytes = source instanceof ArrayBuffer ? new Uint8Array(source) : source;
|
|
35
|
+
return new Blob([bytes.slice()], type ? { type } : undefined);
|
|
36
|
+
}
|
|
37
|
+
/** The name a `File` carries, when the source is one. */
|
|
38
|
+
export function nameOf(source) {
|
|
39
|
+
if (isBlob(source) && "name" in source && typeof source.name === "string")
|
|
40
|
+
return source.name;
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
/** The MIME type a `Blob` carries, when it has one. */
|
|
44
|
+
export function typeOf(source) {
|
|
45
|
+
return isBlob(source) && source.type !== "" ? source.type : undefined;
|
|
46
|
+
}
|
|
47
|
+
/** A `"` or a line break in a filename would end the header early; percent-encode them. */
|
|
48
|
+
function quote(value) {
|
|
49
|
+
return value.replace(/["\r\n]/g, (c) => `%${c.charCodeAt(0).toString(16).padStart(2, "0")}`);
|
|
50
|
+
}
|
|
51
|
+
async function* chunksOf(source) {
|
|
52
|
+
if (typeof ReadableStream !== "undefined" && source instanceof ReadableStream) {
|
|
53
|
+
const reader = source.getReader();
|
|
54
|
+
try {
|
|
55
|
+
while (true) {
|
|
56
|
+
const { done, value } = await reader.read();
|
|
57
|
+
if (done)
|
|
58
|
+
return;
|
|
59
|
+
if (value)
|
|
60
|
+
yield value;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
finally {
|
|
64
|
+
reader.releaseLock();
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
for await (const chunk of source)
|
|
69
|
+
yield chunk;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* The `multipart/form-data` body of an upload: the text `fields` FIRST, in order (the server
|
|
74
|
+
* reads the encryption mode and the folder before the file part starts), then the one file
|
|
75
|
+
* part. An in-memory source becomes a `FormData` (the platform frames it); a stream is framed
|
|
76
|
+
* here and sent as a `ReadableStream`, so a file of any size goes up without being read into
|
|
77
|
+
* memory (Node; in a browser, give a `File` or a `Blob`).
|
|
78
|
+
*/
|
|
79
|
+
export function multipartBody(fields, file) {
|
|
80
|
+
if (!isStreamSource(file.source)) {
|
|
81
|
+
const form = new FormData();
|
|
82
|
+
for (const [name, value] of fields)
|
|
83
|
+
form.append(name, value);
|
|
84
|
+
form.append(file.field, toBlob(file.source, file.contentType), file.filename);
|
|
85
|
+
return { body: form, contentType: undefined, streaming: false };
|
|
86
|
+
}
|
|
87
|
+
const boundary = `----VolaFormBoundary${randomHex(12)}`;
|
|
88
|
+
const encoder = new TextEncoder();
|
|
89
|
+
const head = fields
|
|
90
|
+
.map(([name, value]) => `--${boundary}\r\nContent-Disposition: form-data; name="${quote(name)}"\r\n\r\n${value}\r\n`)
|
|
91
|
+
.join("") +
|
|
92
|
+
`--${boundary}\r\nContent-Disposition: form-data; name="${quote(file.field)}"; filename="${quote(file.filename)}"\r\nContent-Type: ${file.contentType}\r\n\r\n`;
|
|
93
|
+
const tail = `\r\n--${boundary}--\r\n`;
|
|
94
|
+
const source = file.source;
|
|
95
|
+
const body = new ReadableStream({
|
|
96
|
+
async start(controller) {
|
|
97
|
+
controller.enqueue(encoder.encode(head));
|
|
98
|
+
try {
|
|
99
|
+
for await (const chunk of chunksOf(source))
|
|
100
|
+
controller.enqueue(chunk);
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
controller.error(error);
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
controller.enqueue(encoder.encode(tail));
|
|
107
|
+
controller.close();
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
return { body, contentType: `multipart/form-data; boundary=${boundary}`, streaming: true };
|
|
111
|
+
}
|
|
112
|
+
//# sourceMappingURL=body.js.map
|
package/dist/body.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"body.js","sourceRoot":"","sources":["../src/body.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AASrC,MAAM,UAAU,MAAM,CAAC,KAAc;IACnC,OAAO,OAAO,IAAI,KAAK,WAAW,IAAI,KAAK,YAAY,IAAI,CAAC;AAC9D,CAAC;AAED,MAA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CAAC,KAAK,CAAC,gBAAgB,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,sBAAsB,IAAI,CAAC,WAAW,UAAU,CAAC;IAClK,MAAM,IAAI,GAAG,SAAS,QAAQ,QAAQ,CAAC;IACvC,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;IAC3B,MAAM,IAAI,GAAG,IAAI,cAAc,CAAa;QAC1C,KAAK,CAAC,KAAK,CAAC,UAAU;YACpB,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;YACzC,IAAI,CAAC;gBACH,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,QAAQ,CAAC,MAAM,CAAC;oBAAE,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;YACxE,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;gBACxB,OAAO;YACT,CAAC;YACD,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;YACzC,UAAU,CAAC,KAAK,EAAE,CAAC;QACrB,CAAC;KACF,CAAC,CAAC;IACH,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,iCAAiC,QAAQ,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;AAC7F,CAAC"}
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { UdcClient } from "@jsudc/core/client";
|
|
2
|
+
import { type InstanceTypesResponse, type LiveResponse, type LookupLocale, type LookupsResponse, type ReadyResponse } from "@vol-a/core";
|
|
3
|
+
import { FilesApi } from "./files.js";
|
|
4
|
+
import { FoldersApi } from "./folders.js";
|
|
5
|
+
import { KeyringsApi } from "./keyrings.js";
|
|
6
|
+
import { AdminApi, KeysApi, StatsApi } from "./management.js";
|
|
7
|
+
import { type OpenShareOptions, SharesApi } from "./shares.js";
|
|
8
|
+
import { UploadsApi } from "./uploads.js";
|
|
9
|
+
/** The `caller` content key: 32 bytes, or their base64. Node only (see `VolaClientOptions`). */
|
|
10
|
+
export type ContentKey = string | Uint8Array;
|
|
11
|
+
export interface VolaClientOptions {
|
|
12
|
+
/** API base URL including the mount prefix, e.g. `https://files.example.com/vola`. */
|
|
13
|
+
baseUrl: string;
|
|
14
|
+
/** API key, sent as `Authorization: Bearer …`. Optional only for the public routes (`health`, `lookups`, `/s/…`, `/public/…`). */
|
|
15
|
+
apiKey?: string | undefined;
|
|
16
|
+
/** `fetch` to use; default: the global one. Tests inject a fake; a host may inject one with retries or a proxy. */
|
|
17
|
+
fetch?: typeof fetch | undefined;
|
|
18
|
+
/** `X-User-Id`: the principal of the host application — attribution, and the owner of a keyring. */
|
|
19
|
+
userId?: string | undefined;
|
|
20
|
+
/** `X-Tenant-Slug`: the tenant an ADMIN key acts on (a tenant key already has one). */
|
|
21
|
+
tenantSlug?: string | undefined;
|
|
22
|
+
/** Validate every JSON answer against its `@vol-a/core` schema (`invalid_response` on a mismatch). Default `false`: the types are trusted. */
|
|
23
|
+
validate?: boolean | undefined;
|
|
24
|
+
/** An unlock token to start with (`withUnlock` sets it). Held in memory only. */
|
|
25
|
+
unlock?: string | undefined;
|
|
26
|
+
/** Extra headers on every request (a correlation id, a proxy token). */
|
|
27
|
+
headers?: Record<string, string> | undefined;
|
|
28
|
+
}
|
|
29
|
+
/** Options every call accepts. */
|
|
30
|
+
export interface CallOptions {
|
|
31
|
+
signal?: AbortSignal | undefined;
|
|
32
|
+
/** `X-Vola-Unlock` for this call only; default: the token the instance holds. */
|
|
33
|
+
unlock?: string | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* `X-Vola-Content-Key`, the `caller` encryption key (32 bytes or their base64). Refused in a
|
|
36
|
+
* browser: the server rejects any request with an `Origin`, and the key would sit in the page.
|
|
37
|
+
*/
|
|
38
|
+
contentKey?: ContentKey | undefined;
|
|
39
|
+
}
|
|
40
|
+
export type QueryValue = string | number | boolean | null | undefined;
|
|
41
|
+
/** What `VolaClient.request` takes: the escape hatch every group is built on. */
|
|
42
|
+
export interface RequestOptions extends CallOptions {
|
|
43
|
+
method?: string | undefined;
|
|
44
|
+
/** Query parameters; `undefined`/`null`/`false` are dropped, `true` is sent as `1` (the server's flag form). */
|
|
45
|
+
query?: Record<string, QueryValue> | undefined;
|
|
46
|
+
headers?: Record<string, string | undefined> | undefined;
|
|
47
|
+
body?: BodyInit | null | undefined;
|
|
48
|
+
/** A JSON body (`content-type: application/json`). */
|
|
49
|
+
json?: unknown;
|
|
50
|
+
/** Which statuses are an answer, not an error. Default: `2xx`. */
|
|
51
|
+
ok?: ((status: number) => boolean) | undefined;
|
|
52
|
+
/** No API key on this request (the public routes). */
|
|
53
|
+
anonymous?: boolean | undefined;
|
|
54
|
+
/** The body is a stream (`duplex: "half"` is needed). */
|
|
55
|
+
streaming?: boolean | undefined;
|
|
56
|
+
/** Validate the answer against its schema for this call (default: the instance setting). */
|
|
57
|
+
validate?: boolean | undefined;
|
|
58
|
+
}
|
|
59
|
+
export interface LockOnUnloadOptions {
|
|
60
|
+
/** The event the beacon goes on. Default `pagehide` (fires on every navigation and tab close, `beforeunload` does not on mobile). */
|
|
61
|
+
event?: "pagehide" | "beforeunload" | "visibilitychange" | undefined;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* What `json()` needs of a schema: the `safeParse` of a `@vol-a/core` Zod schema. Declared
|
|
65
|
+
* structurally so the SDK depends on `@vol-a/core` alone (Zod comes with it).
|
|
66
|
+
*/
|
|
67
|
+
export interface ResponseSchema<T> {
|
|
68
|
+
safeParse(data: unknown): {
|
|
69
|
+
success: true;
|
|
70
|
+
data: T;
|
|
71
|
+
} | {
|
|
72
|
+
success: false;
|
|
73
|
+
error: {
|
|
74
|
+
issues: readonly {
|
|
75
|
+
path: PropertyKey[];
|
|
76
|
+
message: string;
|
|
77
|
+
}[];
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
/** `true` for a `2xx`. */
|
|
82
|
+
export declare const ok2xx: (status: number) => boolean;
|
|
83
|
+
/**
|
|
84
|
+
* The SDK: one instance per API key (and per principal). Groups mirror the routes —
|
|
85
|
+
* `files`, `folders`, `uploads`, `shares`, `keyrings`, `stats`, `keys`, `admin`, `udc` —
|
|
86
|
+
* and `request()` / `json()` are the escape hatch they are built on.
|
|
87
|
+
*
|
|
88
|
+
* Secrets: the API key, the unlock token, the content key, a share secret and a PIN travel
|
|
89
|
+
* in headers or bodies only — never in a URL, never in an error message, never logged.
|
|
90
|
+
*/
|
|
91
|
+
export declare class VolaClient {
|
|
92
|
+
readonly baseUrl: string;
|
|
93
|
+
readonly files: FilesApi;
|
|
94
|
+
readonly folders: FoldersApi;
|
|
95
|
+
readonly uploads: UploadsApi;
|
|
96
|
+
readonly shares: SharesApi;
|
|
97
|
+
readonly keyrings: KeyringsApi;
|
|
98
|
+
readonly stats: StatsApi;
|
|
99
|
+
readonly keys: KeysApi;
|
|
100
|
+
readonly admin: AdminApi;
|
|
101
|
+
/** The options the instance was made with (the unlock token is NOT in here; see `withUnlock`). */
|
|
102
|
+
readonly options: Readonly<Omit<VolaClientOptions, "unlock">>;
|
|
103
|
+
private readonly fetchImpl;
|
|
104
|
+
private readonly validate;
|
|
105
|
+
private unlockToken;
|
|
106
|
+
private udcClient;
|
|
107
|
+
constructor(options: VolaClientOptions);
|
|
108
|
+
/** A client with the same options that sends `token` as `X-Vola-Unlock` (this instance is unchanged). */
|
|
109
|
+
withUnlock(token: string): VolaClient;
|
|
110
|
+
/** `true` while the instance holds an unlock token (it may still have expired on the server). */
|
|
111
|
+
get unlocked(): boolean;
|
|
112
|
+
/** Sets (or clears, with `null`) the unlock token the instance sends. `keyrings.unlock()` calls it. */
|
|
113
|
+
setUnlock(token: string | null): void;
|
|
114
|
+
/** Ends the unlock on the server (`DELETE /keyrings/me/unlock`) and forgets the token. Idempotent. */
|
|
115
|
+
lock(): Promise<void>;
|
|
116
|
+
/**
|
|
117
|
+
* Browser only: on `pagehide` (default) a `navigator.sendBeacon` to `/keyrings/me/unlock/close`
|
|
118
|
+
* ends the unlock the instance holds, so a closed tab leaves no live token behind. The token
|
|
119
|
+
* goes in the beacon's body (`text/plain`), never in the URL. Returns the function that
|
|
120
|
+
* removes the listener. A no-op outside a browser.
|
|
121
|
+
*/
|
|
122
|
+
lockOnUnload(options?: LockOnUnloadOptions): () => void;
|
|
123
|
+
/** `baseUrl + path + ?query`. `path` starts with `/` and is already encoded. */
|
|
124
|
+
url(path: string, query?: Record<string, QueryValue>): string;
|
|
125
|
+
/** The headers of a request: auth, principal, tenant, unlock, content key, extras, then `options.headers`. */
|
|
126
|
+
headers(options?: RequestOptions): Headers;
|
|
127
|
+
/**
|
|
128
|
+
* One request to `path` (already encoded, starting with `/`). Resolves with the `Response`
|
|
129
|
+
* for every status `options.ok` accepts (default `2xx`) and throws the `VolaError` of any
|
|
130
|
+
* other. Transport failures (no network, a refused connection) throw what `fetch` throws.
|
|
131
|
+
*/
|
|
132
|
+
request(path: string, options?: RequestOptions): Promise<Response>;
|
|
133
|
+
/** `request()` for a JSON answer, typed by (and, with `validate`, checked against) its `@vol-a/core` schema. */
|
|
134
|
+
json<T>(path: string, schema: ResponseSchema<T>, options?: RequestOptions): Promise<T>;
|
|
135
|
+
/** The `fetch` this instance was given (or the global one), without any header of its own: for the anonymous routes. */
|
|
136
|
+
get rawFetch(): typeof fetch;
|
|
137
|
+
/** Internal: `fetch` with this instance's headers merged in (what `udc` uses). */
|
|
138
|
+
fetchWithAuth(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
|
|
139
|
+
/** `GET /health/live`. No key needed (one is sent when the instance has it). */
|
|
140
|
+
live(): Promise<LiveResponse>;
|
|
141
|
+
/** `GET /health/ready`; a `503` resolves too (`status: "fail"`) — it is a valid answer. */
|
|
142
|
+
ready(): Promise<ReadyResponse>;
|
|
143
|
+
/** `GET /lookups[?locale=]`: the vocabulary of `lookups.yaml`, labelled in `locale`. No key needed. */
|
|
144
|
+
lookups(locale?: LookupLocale | string): Promise<LookupsResponse>;
|
|
145
|
+
/** `GET /instance-types`: the tenant's instance types with live files, with their counts. */
|
|
146
|
+
instanceTypes(options?: CallOptions): Promise<InstanceTypesResponse>;
|
|
147
|
+
/**
|
|
148
|
+
* The UDC collections of the server (`POST /udc/<action>`) through `@jsudc/core`'s
|
|
149
|
+
* `UdcClient`, with this instance's auth (key, principal, tenant, unlock token) on every call.
|
|
150
|
+
*/
|
|
151
|
+
get udc(): UdcClient;
|
|
152
|
+
/**
|
|
153
|
+
* Follows a share link (`…/s/<token>[#<secret>]`) anonymously: the fragment, when there is
|
|
154
|
+
* one, goes as `X-Share-Secret`; a password as `X-Share-Password`; `range` as `Range`. The
|
|
155
|
+
* `Response` streams the file (a folder share answers its JSON listing). Throws the
|
|
156
|
+
* `VolaError` of a refusal (`410 share_gone`, `401 share_password_required`, `401
|
|
157
|
+
* share_secret_required`, `409 vola_integrity`…).
|
|
158
|
+
*/
|
|
159
|
+
static openShare(url: string, options?: OpenShareOptions): Promise<Response>;
|
|
160
|
+
}
|
|
161
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAIL,KAAK,qBAAqB,EAE1B,KAAK,YAAY,EAGjB,KAAK,YAAY,EACjB,KAAK,eAAe,EAEpB,KAAK,aAAa,EAKnB,MAAM,aAAa,CAAC;AAGrB,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CA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