@qooal/vault 0.0.0-stage → 0.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/CHANGELOG.md +39 -0
- package/LICENSE +21 -0
- package/README.md +270 -2
- package/dist/chunks/chunk-2AAWIHQO.js +1028 -0
- package/dist/chunks/chunk-MKUYQFGG.js +90 -0
- package/dist/chunks/chunk-PEWIUW3U.js +484 -0
- package/dist/chunks/chunk-Z5XT6XS2.js +115 -0
- package/dist/index.js +24 -0
- package/dist/next.js +65 -0
- package/dist/react.js +276 -0
- package/dist/server.js +357 -0
- package/dist/sign.js +20 -0
- package/dist/types/http.d.ts +49 -0
- package/dist/types/index.d.ts +8 -0
- package/dist/types/next.d.ts +39 -0
- package/dist/types/react/index.d.ts +93 -0
- package/dist/types/react/props.d.ts +62 -0
- package/dist/types/server/client.d.ts +160 -0
- package/dist/types/server/index.d.ts +16 -0
- package/dist/types/server/sign-url.d.ts +28 -0
- package/dist/types/server/webhook.d.ts +31 -0
- package/dist/types/sign.d.ts +48 -0
- package/dist/types/types.d.ts +415 -0
- package/dist/types/upload/element.d.ts +45 -0
- package/dist/types/upload/index.d.ts +14 -0
- package/dist/types/upload/perform.d.ts +66 -0
- package/dist/types/upload/uploader.d.ts +62 -0
- package/dist/types/url.d.ts +163 -0
- package/dist/upload.js +28 -0
- package/dist/widget.js +34 -0
- package/package.json +82 -4
|
@@ -0,0 +1,415 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Qooal Vault wire types: the JSON the public API and the upload routes answer, camelCase. Types only, no runtime
|
|
3
|
+
* code.
|
|
4
|
+
*/
|
|
5
|
+
import type { VaultResourceType } from "./url.js";
|
|
6
|
+
/** RFC 3339 timestamp, e.g. `2026-12-03T10:00:00Z`. */
|
|
7
|
+
export type VaultISODate = string;
|
|
8
|
+
export type VaultPlanId = "free" | "starter" | "growth" | "scale";
|
|
9
|
+
export type VaultAccess = "public" | "private" | "authenticated";
|
|
10
|
+
export type VaultAssetState = "uploading" | "processing" | "ready" | "failed" | "quarantined";
|
|
11
|
+
export type VaultFileClass = "image" | "image_convertible" | "svg" | "video" | "audio" | "pdf" | "font" | "model" | "document" | "archive" | "active" | "other";
|
|
12
|
+
export type VaultScanStatus = "not_required" | "pending" | "clean" | "infected" | "too_large" | "unavailable" | "error";
|
|
13
|
+
export type VaultHost = "media" | "video" | "files" | "dl";
|
|
14
|
+
export type VaultWebhookEventType = "vault.asset.created" | "vault.asset.ready" | "vault.asset.failed" | "vault.asset.updated" | "vault.asset.deleted" | "vault.asset.infected" | "vault.quota.warning" | "vault.quota.reached";
|
|
15
|
+
export interface VaultLibrarySettings {
|
|
16
|
+
strictTransforms: boolean;
|
|
17
|
+
widthSteps: number[] | null;
|
|
18
|
+
scanMode: "off" | "flag" | "block";
|
|
19
|
+
moderateUnsigned: boolean;
|
|
20
|
+
defaultAccess: VaultAccess;
|
|
21
|
+
allowedOrigins: string[];
|
|
22
|
+
blockedClasses: VaultFileClass[];
|
|
23
|
+
}
|
|
24
|
+
/** `limit: null` = no limit. Bytes, counts or seconds by meter. */
|
|
25
|
+
export interface VaultMeter {
|
|
26
|
+
used: number;
|
|
27
|
+
limit: number | null;
|
|
28
|
+
}
|
|
29
|
+
export interface VaultUsageSnapshot {
|
|
30
|
+
cycleStart: VaultISODate;
|
|
31
|
+
cycleEnd: VaultISODate;
|
|
32
|
+
storageBytes: VaultMeter;
|
|
33
|
+
bandwidthBytes: VaultMeter;
|
|
34
|
+
transforms: VaultMeter;
|
|
35
|
+
videoSeconds: VaultMeter;
|
|
36
|
+
blocked: {
|
|
37
|
+
uploads: string | null;
|
|
38
|
+
delivery: string | null;
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
export interface VaultLibrary {
|
|
42
|
+
id: string;
|
|
43
|
+
orgId: string;
|
|
44
|
+
projectId: string | null;
|
|
45
|
+
name: string;
|
|
46
|
+
slug: string;
|
|
47
|
+
planId: VaultPlanId;
|
|
48
|
+
overageEnabled: boolean;
|
|
49
|
+
status: "active" | "suspended" | "deleting";
|
|
50
|
+
/** the storage region its files are kept in (`us`, `sg`); chosen at create, never changed */
|
|
51
|
+
region: string;
|
|
52
|
+
/**
|
|
53
|
+
* base URLs including the slug, e.g. https://media.qooalcdn.com/acme-shop; `storage` is the region's bucket
|
|
54
|
+
* origin, which uploads and direct deliveries come from (allow it in your CSP)
|
|
55
|
+
*/
|
|
56
|
+
urls: {
|
|
57
|
+
media: string;
|
|
58
|
+
video: string;
|
|
59
|
+
files: string;
|
|
60
|
+
dl: string;
|
|
61
|
+
upload: string;
|
|
62
|
+
storage: string;
|
|
63
|
+
};
|
|
64
|
+
customDomains: string[];
|
|
65
|
+
settings: VaultLibrarySettings;
|
|
66
|
+
usage: VaultUsageSnapshot;
|
|
67
|
+
assetCount: number;
|
|
68
|
+
signingKeyVersion: number;
|
|
69
|
+
createdAt: VaultISODate;
|
|
70
|
+
updatedAt: VaultISODate;
|
|
71
|
+
}
|
|
72
|
+
export interface VaultFolder {
|
|
73
|
+
id: string;
|
|
74
|
+
libraryId: string;
|
|
75
|
+
parentId: string | null;
|
|
76
|
+
name: string;
|
|
77
|
+
path: string;
|
|
78
|
+
assetCount: number;
|
|
79
|
+
createdAt: VaultISODate;
|
|
80
|
+
}
|
|
81
|
+
export interface VaultVideo {
|
|
82
|
+
status: "pending" | "encoding" | "ready" | "failed";
|
|
83
|
+
progressPct: number | null;
|
|
84
|
+
renditions: {
|
|
85
|
+
name: "1080p" | "720p" | "480p";
|
|
86
|
+
width: number;
|
|
87
|
+
height: number;
|
|
88
|
+
bitrateKbps: number;
|
|
89
|
+
bytes: number;
|
|
90
|
+
}[];
|
|
91
|
+
encodedSeconds: number | null;
|
|
92
|
+
}
|
|
93
|
+
export interface VaultAsset {
|
|
94
|
+
id: string;
|
|
95
|
+
orgId: string;
|
|
96
|
+
libraryId: string;
|
|
97
|
+
folderId: string | null;
|
|
98
|
+
folderPath: string | null;
|
|
99
|
+
publicId: string;
|
|
100
|
+
resourceType: VaultResourceType;
|
|
101
|
+
fileClass: VaultFileClass;
|
|
102
|
+
format: string;
|
|
103
|
+
mime: string;
|
|
104
|
+
filename: string;
|
|
105
|
+
bytes: number;
|
|
106
|
+
width: number | null;
|
|
107
|
+
height: number | null;
|
|
108
|
+
durationMs: number | null;
|
|
109
|
+
animated: boolean | null;
|
|
110
|
+
hasAudio: boolean | null;
|
|
111
|
+
dominantColor: string | null;
|
|
112
|
+
version: number;
|
|
113
|
+
access: VaultAccess;
|
|
114
|
+
state: VaultAssetState;
|
|
115
|
+
failureCode: string | null;
|
|
116
|
+
scan: VaultScanStatus;
|
|
117
|
+
moderation: "none" | "pending" | "approved" | "rejected";
|
|
118
|
+
host: VaultHost;
|
|
119
|
+
disposition: "inline" | "attachment";
|
|
120
|
+
tags: string[];
|
|
121
|
+
title: string | null;
|
|
122
|
+
altText: string | null;
|
|
123
|
+
fields: {
|
|
124
|
+
key: string;
|
|
125
|
+
value: string;
|
|
126
|
+
}[];
|
|
127
|
+
/** canonical URLs; null for private/authenticated assets (sign them) and while not ready */
|
|
128
|
+
urls: {
|
|
129
|
+
original: string | null;
|
|
130
|
+
thumbnail: string | null;
|
|
131
|
+
hls: string | null;
|
|
132
|
+
mp4: string | null;
|
|
133
|
+
poster: string | null;
|
|
134
|
+
};
|
|
135
|
+
video: VaultVideo | null;
|
|
136
|
+
source: "console" | "api" | "widget" | "remote" | "url";
|
|
137
|
+
createdBy: {
|
|
138
|
+
kind: "member" | "api_key" | "upload_preset" | "remote_origin" | "system";
|
|
139
|
+
id: string;
|
|
140
|
+
label: string | null;
|
|
141
|
+
};
|
|
142
|
+
createdAt: VaultISODate;
|
|
143
|
+
updatedAt: VaultISODate;
|
|
144
|
+
deletedAt: VaultISODate | null;
|
|
145
|
+
}
|
|
146
|
+
export interface VaultPage<T> {
|
|
147
|
+
items: T[];
|
|
148
|
+
nextCursor: string | null;
|
|
149
|
+
total: number | null;
|
|
150
|
+
}
|
|
151
|
+
export type VaultAssetPage = VaultPage<VaultAsset>;
|
|
152
|
+
export interface VaultAssetQuery {
|
|
153
|
+
q?: string;
|
|
154
|
+
folder?: string;
|
|
155
|
+
recursive?: boolean;
|
|
156
|
+
type?: VaultResourceType[];
|
|
157
|
+
class?: VaultFileClass[];
|
|
158
|
+
format?: string[];
|
|
159
|
+
tag?: string[];
|
|
160
|
+
tagMode?: "all" | "any";
|
|
161
|
+
access?: VaultAccess[];
|
|
162
|
+
state?: (VaultAssetState | "deleted")[];
|
|
163
|
+
field?: {
|
|
164
|
+
key: string;
|
|
165
|
+
value: string;
|
|
166
|
+
}[];
|
|
167
|
+
createdFrom?: VaultISODate;
|
|
168
|
+
createdTo?: VaultISODate;
|
|
169
|
+
minBytes?: number;
|
|
170
|
+
maxBytes?: number;
|
|
171
|
+
sort?: "created" | "name" | "bytes";
|
|
172
|
+
order?: "asc" | "desc";
|
|
173
|
+
cursor?: string;
|
|
174
|
+
limit?: number;
|
|
175
|
+
}
|
|
176
|
+
export interface VaultAssetVersion {
|
|
177
|
+
version: number;
|
|
178
|
+
bytes: number;
|
|
179
|
+
format: string;
|
|
180
|
+
width: number | null;
|
|
181
|
+
height: number | null;
|
|
182
|
+
createdAt: VaultISODate;
|
|
183
|
+
replacedAt: VaultISODate | null;
|
|
184
|
+
expiresAt: VaultISODate | null;
|
|
185
|
+
current: boolean;
|
|
186
|
+
}
|
|
187
|
+
export type VaultBulkAction = {
|
|
188
|
+
type: "move";
|
|
189
|
+
folderId: string | null;
|
|
190
|
+
} | {
|
|
191
|
+
type: "tag";
|
|
192
|
+
add: string[];
|
|
193
|
+
remove: string[];
|
|
194
|
+
} | {
|
|
195
|
+
type: "access";
|
|
196
|
+
access: VaultAccess;
|
|
197
|
+
} | {
|
|
198
|
+
type: "delete";
|
|
199
|
+
};
|
|
200
|
+
export interface VaultHeader {
|
|
201
|
+
name: string;
|
|
202
|
+
value: string;
|
|
203
|
+
}
|
|
204
|
+
export interface VaultUploadPart {
|
|
205
|
+
n: number;
|
|
206
|
+
url: string;
|
|
207
|
+
}
|
|
208
|
+
/** What `POST …/uploads` answers. `uploadToken` (`vut_…`) is present for browser and API-key callers. */
|
|
209
|
+
export type VaultUploadInstructions = {
|
|
210
|
+
uploadId: string;
|
|
211
|
+
method: "proxy";
|
|
212
|
+
url: string;
|
|
213
|
+
headers: VaultHeader[];
|
|
214
|
+
expiresAt: VaultISODate;
|
|
215
|
+
asset: VaultAsset;
|
|
216
|
+
uploadToken?: string;
|
|
217
|
+
} | {
|
|
218
|
+
uploadId: string;
|
|
219
|
+
method: "single";
|
|
220
|
+
url: string;
|
|
221
|
+
headers: VaultHeader[];
|
|
222
|
+
expiresAt: VaultISODate;
|
|
223
|
+
asset: VaultAsset;
|
|
224
|
+
uploadToken?: string;
|
|
225
|
+
} | {
|
|
226
|
+
uploadId: string;
|
|
227
|
+
method: "multipart";
|
|
228
|
+
partSize: number;
|
|
229
|
+
partCount: number;
|
|
230
|
+
parts: VaultUploadPart[];
|
|
231
|
+
expiresAt: VaultISODate;
|
|
232
|
+
asset: VaultAsset;
|
|
233
|
+
uploadToken?: string;
|
|
234
|
+
}
|
|
235
|
+
/** sample data only: nothing is sent anywhere (`performUpload` refuses it) */
|
|
236
|
+
| {
|
|
237
|
+
uploadId: string;
|
|
238
|
+
method: "simulated";
|
|
239
|
+
expiresAt: VaultISODate;
|
|
240
|
+
asset: VaultAsset;
|
|
241
|
+
};
|
|
242
|
+
export interface VaultUploadInput {
|
|
243
|
+
filename: string;
|
|
244
|
+
bytes: number;
|
|
245
|
+
contentType: string;
|
|
246
|
+
folderId?: string | null;
|
|
247
|
+
publicId?: string;
|
|
248
|
+
overwrite?: boolean;
|
|
249
|
+
access?: VaultAccess;
|
|
250
|
+
tags?: string[];
|
|
251
|
+
uploadPreset?: string;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* `POST …/uploads` with an API key may import from a URL instead of sending bytes; answers 202 with
|
|
255
|
+
* `VaultUrlImportInstructions`.
|
|
256
|
+
*/
|
|
257
|
+
export interface VaultUploadFromUrlInput extends Omit<VaultUploadInput, "bytes" | "contentType" | "filename"> {
|
|
258
|
+
sourceUrl: string;
|
|
259
|
+
filename?: string;
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* The upload instructions for a URL import (`method: "url"`, answered with 202): Vault fetches the file itself, so
|
|
263
|
+
* there are no bytes to send. `asset` is the new asset, still `uploading`.
|
|
264
|
+
*/
|
|
265
|
+
export interface VaultUrlImportInstructions {
|
|
266
|
+
uploadId: string;
|
|
267
|
+
method: "url";
|
|
268
|
+
expiresAt: VaultISODate;
|
|
269
|
+
asset: VaultAsset;
|
|
270
|
+
}
|
|
271
|
+
/** `GET …/uploads/{upload}`. */
|
|
272
|
+
export interface VaultUploadStatus {
|
|
273
|
+
id: string;
|
|
274
|
+
state: "open" | "completing" | "completed" | "aborted" | "expired";
|
|
275
|
+
method: "proxy" | "single" | "multipart";
|
|
276
|
+
parts: {
|
|
277
|
+
n: number;
|
|
278
|
+
etag: string;
|
|
279
|
+
size: number;
|
|
280
|
+
}[];
|
|
281
|
+
}
|
|
282
|
+
export interface VaultCompletedPart {
|
|
283
|
+
n: number;
|
|
284
|
+
etag: string;
|
|
285
|
+
}
|
|
286
|
+
export interface VaultTransformPreset {
|
|
287
|
+
id: string;
|
|
288
|
+
libraryId: string;
|
|
289
|
+
name: string;
|
|
290
|
+
transformation: string;
|
|
291
|
+
eager: boolean;
|
|
292
|
+
description: string | null;
|
|
293
|
+
createdAt: VaultISODate;
|
|
294
|
+
updatedAt: VaultISODate;
|
|
295
|
+
}
|
|
296
|
+
export interface VaultUploadPreset {
|
|
297
|
+
id: string;
|
|
298
|
+
libraryId: string;
|
|
299
|
+
name: string;
|
|
300
|
+
mode: "signed" | "unsigned";
|
|
301
|
+
folderId: string | null;
|
|
302
|
+
publicIdMode: "random" | "filename" | "filename_unique";
|
|
303
|
+
overwrite: boolean;
|
|
304
|
+
access: VaultAccess;
|
|
305
|
+
tags: string[];
|
|
306
|
+
allowedClasses: VaultFileClass[];
|
|
307
|
+
maxBytes: number | null;
|
|
308
|
+
eagerPresets: string[];
|
|
309
|
+
allowedOrigins: string[];
|
|
310
|
+
ratePerMinute: number;
|
|
311
|
+
monthlyCap: number | null;
|
|
312
|
+
turnstile: boolean;
|
|
313
|
+
moderation: boolean;
|
|
314
|
+
disabled: boolean;
|
|
315
|
+
uploadsThisCycle: number;
|
|
316
|
+
createdAt: VaultISODate;
|
|
317
|
+
updatedAt: VaultISODate;
|
|
318
|
+
}
|
|
319
|
+
export interface VaultDownloadLink {
|
|
320
|
+
id: string;
|
|
321
|
+
libraryId: string;
|
|
322
|
+
assetId: string;
|
|
323
|
+
label: string | null;
|
|
324
|
+
expiresAt: VaultISODate;
|
|
325
|
+
maxDownloads: number | null;
|
|
326
|
+
downloads: number;
|
|
327
|
+
revokedAt: VaultISODate | null;
|
|
328
|
+
lastDownloadAt: VaultISODate | null;
|
|
329
|
+
createdBy: VaultAsset["createdBy"];
|
|
330
|
+
createdAt: VaultISODate;
|
|
331
|
+
}
|
|
332
|
+
export interface VaultUsage {
|
|
333
|
+
libraryId: string;
|
|
334
|
+
range: "7d" | "30d" | "cycle";
|
|
335
|
+
cycle: VaultUsageSnapshot;
|
|
336
|
+
daily: {
|
|
337
|
+
date: VaultISODate;
|
|
338
|
+
storageBytes: number;
|
|
339
|
+
bandwidthBytes: number;
|
|
340
|
+
transforms: number;
|
|
341
|
+
videoSeconds: number;
|
|
342
|
+
}[];
|
|
343
|
+
/** null unless overage is on; a preview while the catalog is pending */
|
|
344
|
+
overageEstimateCents: number | null;
|
|
345
|
+
}
|
|
346
|
+
/** `POST /libraries/{library}/upload-tickets`. */
|
|
347
|
+
export interface VaultUploadTicketInput {
|
|
348
|
+
folderId?: string | null;
|
|
349
|
+
/** a fixed public ID, for "replace this product's photo" */
|
|
350
|
+
publicId?: string;
|
|
351
|
+
overwrite?: boolean;
|
|
352
|
+
access?: VaultAccess;
|
|
353
|
+
tags?: string[];
|
|
354
|
+
allowedClasses?: VaultFileClass[];
|
|
355
|
+
maxBytes?: number;
|
|
356
|
+
/** 1-100 */
|
|
357
|
+
maxFiles?: number;
|
|
358
|
+
allowSourceUrl?: boolean;
|
|
359
|
+
allowedOrigins?: string[];
|
|
360
|
+
/** 60-3600; default 900 */
|
|
361
|
+
expiresInSeconds?: number;
|
|
362
|
+
}
|
|
363
|
+
export interface VaultUploadTicket {
|
|
364
|
+
/** the ticket's ID (`vtkt_…`), to revoke it */
|
|
365
|
+
id: string;
|
|
366
|
+
/** `vtk_…`: hand it to the browser; it is a secret until it expires */
|
|
367
|
+
ticket: string;
|
|
368
|
+
expiresAt: VaultISODate;
|
|
369
|
+
}
|
|
370
|
+
/** `POST /libraries/{library}/assets/{asset}/download-links`. */
|
|
371
|
+
export interface VaultDownloadLinkInput {
|
|
372
|
+
/** 60-2592000 (30 days) */
|
|
373
|
+
expiresInSeconds: number;
|
|
374
|
+
/** 1-1000; omit for unlimited */
|
|
375
|
+
maxDownloads?: number;
|
|
376
|
+
/** at most 100 characters, e.g. an order number */
|
|
377
|
+
label?: string;
|
|
378
|
+
}
|
|
379
|
+
export interface VaultCreatedDownloadLink {
|
|
380
|
+
link: VaultDownloadLink;
|
|
381
|
+
/** shown once */
|
|
382
|
+
url: string;
|
|
383
|
+
}
|
|
384
|
+
/** `POST /libraries/{library}/assets/{asset}/urls`. */
|
|
385
|
+
export interface VaultSignUrlInput {
|
|
386
|
+
transformation?: string;
|
|
387
|
+
/** 60-604800 */
|
|
388
|
+
expiresInSeconds?: number;
|
|
389
|
+
format?: string;
|
|
390
|
+
}
|
|
391
|
+
export interface VaultSignedUrl {
|
|
392
|
+
url: string;
|
|
393
|
+
expiresAt: VaultISODate | null;
|
|
394
|
+
}
|
|
395
|
+
/** The shortened asset a webhook carries: no folder, title, alt text, fields, creator or colour, never a signed URL. */
|
|
396
|
+
export type VaultWebhookAsset = Pick<VaultAsset, "id" | "libraryId" | "publicId" | "resourceType" | "fileClass" | "format" | "mime" | "filename" | "bytes" | "width" | "height" | "durationMs" | "version" | "access" | "state" | "failureCode" | "scan" | "tags" | "urls">;
|
|
397
|
+
/** A webhook body. */
|
|
398
|
+
export interface VaultWebhookEvent {
|
|
399
|
+
type: VaultWebhookEventType;
|
|
400
|
+
timestamp: VaultISODate;
|
|
401
|
+
data: {
|
|
402
|
+
libraryId: string;
|
|
403
|
+
librarySlug: string;
|
|
404
|
+
/** true on a test delivery sent from the console */
|
|
405
|
+
test?: boolean;
|
|
406
|
+
/** asset events */
|
|
407
|
+
asset?: VaultWebhookAsset;
|
|
408
|
+
/** quota events: the meter, how full it is (0-100), its use and limit, and the cycle's start (Unix seconds) */
|
|
409
|
+
meter?: string;
|
|
410
|
+
percent?: number;
|
|
411
|
+
used?: number;
|
|
412
|
+
limit?: number;
|
|
413
|
+
cycleStart?: number;
|
|
414
|
+
};
|
|
415
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { type Provider, type UploaderOptions } from "./uploader.js";
|
|
2
|
+
export declare const VAULT_UPLOADER_TAG = "qooal-vault-uploader";
|
|
3
|
+
export interface VaultUploaderLabels {
|
|
4
|
+
drop: string;
|
|
5
|
+
browse: string;
|
|
6
|
+
camera: string;
|
|
7
|
+
list: string;
|
|
8
|
+
waiting: string;
|
|
9
|
+
uploading: string;
|
|
10
|
+
processing: string;
|
|
11
|
+
done: string;
|
|
12
|
+
failed: string;
|
|
13
|
+
cancelled: string;
|
|
14
|
+
cancel: string;
|
|
15
|
+
retry: string;
|
|
16
|
+
remove: string;
|
|
17
|
+
tooLarge: string;
|
|
18
|
+
tooMany: string;
|
|
19
|
+
wrongType: string;
|
|
20
|
+
maxSize: string;
|
|
21
|
+
/** messages by Vault `reason`; `default` for anything else */
|
|
22
|
+
errors: Record<string, string>;
|
|
23
|
+
}
|
|
24
|
+
/** Default English labels. Override any of them with the element's `options.labels`. */
|
|
25
|
+
export declare const DEFAULT_LABELS: VaultUploaderLabels;
|
|
26
|
+
/** JS-only settings: what attributes cannot carry (functions, a custom fetch, labels). */
|
|
27
|
+
export interface VaultUploaderElementOptions extends Partial<Omit<UploaderOptions, "library" | "ticket" | "preset" | "turnstile">> {
|
|
28
|
+
ticket?: Provider<string>;
|
|
29
|
+
turnstile?: Provider<string>;
|
|
30
|
+
labels?: Partial<Omit<VaultUploaderLabels, "errors">> & {
|
|
31
|
+
errors?: Record<string, string>;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/** `1.2 MB` style sizes (decimal units, one decimal place). */
|
|
35
|
+
export declare function formatBytes(n: number): string;
|
|
36
|
+
/** Whether a file matches an `accept` list (MIME types, `type/*` and `.ext`), as a file picker would. */
|
|
37
|
+
export declare function acceptsFile(file: {
|
|
38
|
+
name: string;
|
|
39
|
+
type: string;
|
|
40
|
+
}, accept: string | null): boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Registers `<qooal-vault-uploader>` (or `tag`) once. Safe to call repeatedly and on the server (where it does
|
|
43
|
+
* nothing).
|
|
44
|
+
*/
|
|
45
|
+
export declare function defineVaultUploader(tag?: string): void;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@qooal/vault/upload` (browser): sending files to Qooal Vault.
|
|
3
|
+
*
|
|
4
|
+
* - `performUpload(file, instructions, opts)`: the bytes, for instructions you already have (proxy, single, multipart).
|
|
5
|
+
* - `createUploader({library, ticket | preset + turnstile})`: the whole flow over the public browser routes.
|
|
6
|
+
* - `defineVaultUploader()`: registers the `<qooal-vault-uploader>` element.
|
|
7
|
+
*
|
|
8
|
+
* Nothing here runs at import time, so the module is safe to import during server rendering.
|
|
9
|
+
*/
|
|
10
|
+
export { VAULT_API_BASE, VaultApiError, type VaultFieldError } from "../http.js";
|
|
11
|
+
export type { VaultAsset, VaultCompletedPart, VaultUploadInstructions, VaultUploadPart, VaultUploadStatus, } from "../types.js";
|
|
12
|
+
export { acceptsFile, DEFAULT_LABELS, defineVaultUploader, formatBytes, VAULT_UPLOADER_TAG, type VaultUploaderElementOptions, type VaultUploaderLabels, } from "./element.js";
|
|
13
|
+
export { fetchPut, type PerformUploadOptions, type PerformUploadResult, type PutFunction, type PutRequest, type PutResponse, performUpload, type UploadProgress, xhrPut, } from "./perform.js";
|
|
14
|
+
export { createUploader, type Provider, type ResumeStorage, type UploaderOptions, type UploadFileOptions, type VaultUploader, } from "./uploader.js";
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { VaultAsset, VaultCompletedPart, VaultUploadInstructions, VaultUploadPart } from "../types.js";
|
|
2
|
+
export interface PutRequest {
|
|
3
|
+
url: string;
|
|
4
|
+
body: Blob;
|
|
5
|
+
headers: Record<string, string>;
|
|
6
|
+
signal: AbortSignal;
|
|
7
|
+
/** bytes of `body` sent so far */
|
|
8
|
+
onProgress: (loaded: number) => void;
|
|
9
|
+
}
|
|
10
|
+
/** `status` 0 = no answer (network failure). `etag` is the `ETag` response header (S3 parts). */
|
|
11
|
+
export interface PutResponse {
|
|
12
|
+
status: number;
|
|
13
|
+
etag: string | null;
|
|
14
|
+
text: string;
|
|
15
|
+
retryAfter: string | null;
|
|
16
|
+
}
|
|
17
|
+
/** One HTTP PUT. Resolves for every HTTP answer (and with status 0 on a network failure); rejects only on abort. */
|
|
18
|
+
export type PutFunction = (req: PutRequest) => Promise<PutResponse>;
|
|
19
|
+
export interface UploadProgress {
|
|
20
|
+
/** bytes confirmed or in flight */
|
|
21
|
+
loaded: number;
|
|
22
|
+
total: number;
|
|
23
|
+
}
|
|
24
|
+
export interface PerformUploadOptions {
|
|
25
|
+
onProgress?: (progress: UploadProgress) => void;
|
|
26
|
+
signal?: AbortSignal;
|
|
27
|
+
/** parallel part uploads (multipart); default 4, 1-16 */
|
|
28
|
+
concurrency?: number;
|
|
29
|
+
/** extra attempts per request after the first; default 3, 0-10 */
|
|
30
|
+
retries?: number;
|
|
31
|
+
/**
|
|
32
|
+
* Multipart: fetches presigned URLs for more parts (`POST …/uploads/{id}/parts`, at most 100 numbers per call).
|
|
33
|
+
* Needed when the instructions carry fewer URLs than parts, and to replace an expired URL.
|
|
34
|
+
*/
|
|
35
|
+
requestParts?: (partNumbers: number[]) => Promise<VaultUploadPart[]>;
|
|
36
|
+
/** Multipart resume: parts already in S3 (from `GET …/uploads/{id}`); they are not sent again. */
|
|
37
|
+
done?: readonly VaultCompletedPart[];
|
|
38
|
+
/** Multipart: called as each part lands (persist it to resume later). */
|
|
39
|
+
onPartDone?: (part: VaultCompletedPart) => void;
|
|
40
|
+
/** Proxy: the `vut_…` upload token, when the instructions do not carry one and no header authorizes the PUT. */
|
|
41
|
+
uploadToken?: string;
|
|
42
|
+
/** The HTTP PUT to use; default XMLHttpRequest in browsers (upload progress), `fetch` elsewhere. */
|
|
43
|
+
put?: PutFunction;
|
|
44
|
+
/** The `fetch` used when `put` is not given and XMLHttpRequest is unavailable or `preferFetch` is set. */
|
|
45
|
+
fetch?: typeof fetch;
|
|
46
|
+
/** Milliseconds to wait before retry `attempt` (0-based); default full-jitter exponential, honouring Retry-After. */
|
|
47
|
+
retryDelay?: (attempt: number, retryAfterSeconds: number | null) => number;
|
|
48
|
+
}
|
|
49
|
+
export interface PerformUploadResult {
|
|
50
|
+
uploadId: string;
|
|
51
|
+
method: "proxy" | "single" | "multipart";
|
|
52
|
+
/** multipart: every part with its ETag, in order, for `POST …/complete {parts}` */
|
|
53
|
+
parts?: VaultCompletedPart[];
|
|
54
|
+
/** proxy: the ingest host's answer (201 ready, 202 processing) */
|
|
55
|
+
asset?: VaultAsset;
|
|
56
|
+
}
|
|
57
|
+
/** PUT through XMLHttpRequest, for upload progress events. */
|
|
58
|
+
export declare const xhrPut: PutFunction;
|
|
59
|
+
/** PUT through `fetch` (no upload progress: reports the whole body once it is accepted). */
|
|
60
|
+
export declare function fetchPut(f?: typeof fetch): PutFunction;
|
|
61
|
+
/**
|
|
62
|
+
* Sends `file` as `instructions` say. Resolves when every byte is stored (and, for `proxy`, with the asset); the
|
|
63
|
+
* caller then completes `single` and `multipart` uploads. Rejects with the signal's reason when aborted, and with a
|
|
64
|
+
* VaultApiError when a request fails for good.
|
|
65
|
+
*/
|
|
66
|
+
export declare function performUpload(file: Blob, instructions: VaultUploadInstructions, opts?: PerformUploadOptions): Promise<PerformUploadResult>;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { VaultAccess, VaultAsset } from "../types.js";
|
|
2
|
+
import { type PerformUploadOptions, type UploadProgress } from "./perform.js";
|
|
3
|
+
/** A value, or a function that produces it (called when needed; tickets and Turnstile tokens are fetched lazily). */
|
|
4
|
+
export type Provider<T> = T | (() => T | Promise<T>);
|
|
5
|
+
/** The subset of `Storage` the resume store needs. */
|
|
6
|
+
export type ResumeStorage = Pick<Storage, "getItem" | "setItem" | "removeItem">;
|
|
7
|
+
export interface UploaderOptions {
|
|
8
|
+
/** the library's slug (or `vlib_` ID) */
|
|
9
|
+
library: string;
|
|
10
|
+
/**
|
|
11
|
+
* An upload ticket (`vtk_…`), or a function that fetches one from your backend. A function is called again once
|
|
12
|
+
* when Vault refuses the ticket as expired or used up.
|
|
13
|
+
*/
|
|
14
|
+
ticket?: Provider<string>;
|
|
15
|
+
/** an unsigned upload preset's name (needs `turnstile`) */
|
|
16
|
+
preset?: string;
|
|
17
|
+
/** a Turnstile token provider for unsigned presets; called once per file (tokens are single-use) */
|
|
18
|
+
turnstile?: Provider<string>;
|
|
19
|
+
/** default https://api.qooal.com/v1/vault */
|
|
20
|
+
apiBase?: string;
|
|
21
|
+
fetch?: typeof fetch;
|
|
22
|
+
/** parallel part uploads; default 4 */
|
|
23
|
+
concurrency?: number;
|
|
24
|
+
/** retries per request; default 3 */
|
|
25
|
+
retries?: number;
|
|
26
|
+
/** where resumable uploads are remembered; default `localStorage` when available, `null` to switch off */
|
|
27
|
+
storage?: ResumeStorage | null;
|
|
28
|
+
/** advanced: the PUT used for bytes (tests, custom transports) */
|
|
29
|
+
put?: PerformUploadOptions["put"];
|
|
30
|
+
/** advanced: retry delay in ms (tests use 0) */
|
|
31
|
+
retryDelay?: PerformUploadOptions["retryDelay"];
|
|
32
|
+
}
|
|
33
|
+
export interface UploadFileOptions {
|
|
34
|
+
/** the file name sent to Vault; default `file.name` */
|
|
35
|
+
filename?: string;
|
|
36
|
+
/** default `file.type`, else `application/octet-stream` (Vault sniffs the bytes anyway) */
|
|
37
|
+
contentType?: string;
|
|
38
|
+
/**
|
|
39
|
+
* Tickets only (a preset fixes these): where the asset is stored. A ticket's own folder and public ID win when it
|
|
40
|
+
* sets them, and these tags are added to the ticket's.
|
|
41
|
+
*/
|
|
42
|
+
folderId?: string | null;
|
|
43
|
+
publicId?: string;
|
|
44
|
+
overwrite?: boolean;
|
|
45
|
+
/** ignored: an upload always takes the ticket's access (set it with `createUploadTicket({ access })`) */
|
|
46
|
+
access?: VaultAccess;
|
|
47
|
+
tags?: string[];
|
|
48
|
+
onProgress?: (progress: UploadProgress) => void;
|
|
49
|
+
signal?: AbortSignal;
|
|
50
|
+
/** default: a new UUIDv7 per call */
|
|
51
|
+
idempotencyKey?: string;
|
|
52
|
+
/** resume an interrupted multipart upload of the same file; default true */
|
|
53
|
+
resume?: boolean;
|
|
54
|
+
}
|
|
55
|
+
export interface VaultUploader {
|
|
56
|
+
/** Uploads one file; resolves with the asset (`ready`, or `processing` while Vault works on it). */
|
|
57
|
+
upload(file: Blob, opts?: UploadFileOptions): Promise<VaultAsset>;
|
|
58
|
+
/** Aborts an upload by ID and token (best effort; the uploader does this itself when `signal` aborts). */
|
|
59
|
+
abort(uploadId: string, uploadToken: string): Promise<void>;
|
|
60
|
+
}
|
|
61
|
+
/** Creates an uploader for one library. Exactly one of `ticket` and `preset` must be given. */
|
|
62
|
+
export declare function createUploader(options: UploaderOptions): VaultUploader;
|