@unisource/sdk 0.2.0 → 0.3.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/README.md +55 -23
- package/dist/index.d.mts +623 -21
- package/dist/index.mjs +438 -38
- package/package.json +8 -4
- package/src/client.ts +474 -233
- package/src/fileRecords.ts +99 -87
- package/src/folders.ts +97 -84
- package/src/index.ts +198 -106
- package/src/mainStorage.ts +51 -0
- package/src/primitives.ts +30 -25
- package/src/releases.ts +132 -0
- package/src/services.ts +137 -69
- package/src/shareLinks.ts +93 -0
- package/src/uploads.ts +99 -90
- package/dist/index.d.ts +0 -478
- package/src/uploadDestination.ts +0 -4
package/dist/index.mjs
CHANGED
|
@@ -3,6 +3,8 @@ import { z } from "zod";
|
|
|
3
3
|
const nonEmptyString = z.string().trim().min(1);
|
|
4
4
|
const positiveInt = z.number().int().positive();
|
|
5
5
|
const unixTimestamp = z.number().int().nonnegative();
|
|
6
|
+
const FILES_DEFAULT_LIMIT = 25;
|
|
7
|
+
const FILES_MAX_LIMIT = 100;
|
|
6
8
|
const uploadDestinationSchema = z.enum(["r2", "appwrite"]);
|
|
7
9
|
const uploadStatusSchema = z.enum([
|
|
8
10
|
"pending",
|
|
@@ -18,7 +20,9 @@ const apiErrorSchema = z.object({
|
|
|
18
20
|
const uploadR2InitRequestSchema = z.object({
|
|
19
21
|
filename: nonEmptyString,
|
|
20
22
|
size: positiveInt,
|
|
21
|
-
mime_type: nonEmptyString
|
|
23
|
+
mime_type: nonEmptyString,
|
|
24
|
+
folder_id: nonEmptyString.optional(),
|
|
25
|
+
is_main_storage: z.boolean().optional().default(false)
|
|
22
26
|
});
|
|
23
27
|
const uploadR2InitResponseSchema = z.object({
|
|
24
28
|
upload_id: nonEmptyString,
|
|
@@ -31,7 +35,9 @@ const uploadR2InitResponseSchema = z.object({
|
|
|
31
35
|
const uploadAppwriteInitRequestSchema = z.object({
|
|
32
36
|
filename: nonEmptyString,
|
|
33
37
|
size: positiveInt,
|
|
34
|
-
mime_type: nonEmptyString
|
|
38
|
+
mime_type: nonEmptyString,
|
|
39
|
+
folder_id: nonEmptyString.optional(),
|
|
40
|
+
is_main_storage: z.boolean().optional().default(false)
|
|
35
41
|
});
|
|
36
42
|
const uploadAppwriteInitResponseSchema = z.object({
|
|
37
43
|
upload_id: nonEmptyString,
|
|
@@ -42,7 +48,10 @@ const uploadAppwriteInitResponseSchema = z.object({
|
|
|
42
48
|
file_id: nonEmptyString,
|
|
43
49
|
expires_at: positiveInt
|
|
44
50
|
});
|
|
45
|
-
const uploadLifecycleRequestSchema = z.object({
|
|
51
|
+
const uploadLifecycleRequestSchema = z.object({
|
|
52
|
+
upload_id: nonEmptyString,
|
|
53
|
+
is_main_storage: z.boolean().optional().default(false)
|
|
54
|
+
});
|
|
46
55
|
const uploadCompleteResponseSchema = z.object({
|
|
47
56
|
success: z.literal(true),
|
|
48
57
|
upload_id: nonEmptyString,
|
|
@@ -53,8 +62,6 @@ const uploadFailResponseSchema = z.object({
|
|
|
53
62
|
upload_id: nonEmptyString,
|
|
54
63
|
status: z.literal("failed")
|
|
55
64
|
});
|
|
56
|
-
const FILES_DEFAULT_LIMIT = 25;
|
|
57
|
-
const FILES_MAX_LIMIT = 100;
|
|
58
65
|
/** Raw upload record — returned by admin `/files` endpoints. */
|
|
59
66
|
const uploadRecordSchema = z.object({
|
|
60
67
|
id: nonEmptyString,
|
|
@@ -64,11 +71,7 @@ const uploadRecordSchema = z.object({
|
|
|
64
71
|
size: positiveInt,
|
|
65
72
|
mime_type: nonEmptyString,
|
|
66
73
|
destination: uploadDestinationSchema,
|
|
67
|
-
status:
|
|
68
|
-
"pending",
|
|
69
|
-
"completed",
|
|
70
|
-
"failed"
|
|
71
|
-
]),
|
|
74
|
+
status: uploadStatusSchema,
|
|
72
75
|
expires_at: positiveInt,
|
|
73
76
|
created_at: positiveInt,
|
|
74
77
|
updated_at: positiveInt
|
|
@@ -78,6 +81,7 @@ const uploadsListResponseSchema = z.object({
|
|
|
78
81
|
next_cursor: z.string().nullable(),
|
|
79
82
|
limit: positiveInt
|
|
80
83
|
});
|
|
84
|
+
const uploadRecordDetailResponseSchema = z.object({ upload: uploadRecordSchema });
|
|
81
85
|
//#endregion
|
|
82
86
|
//#region src/fileRecords.ts
|
|
83
87
|
/**
|
|
@@ -127,6 +131,8 @@ const fileRestoreResponseSchema = z.object({
|
|
|
127
131
|
success: z.literal(true),
|
|
128
132
|
id: nonEmptyString
|
|
129
133
|
});
|
|
134
|
+
const fileUpdateRequestSchema = z.object({ filename: nonEmptyString });
|
|
135
|
+
const fileUpdateResponseSchema = z.object({ file: fileRecordSchema });
|
|
130
136
|
//#endregion
|
|
131
137
|
//#region src/folders.ts
|
|
132
138
|
const folderSchema = z.object({
|
|
@@ -143,10 +149,11 @@ const folderSchema = z.object({
|
|
|
143
149
|
});
|
|
144
150
|
const folderListQuerySchema = z.object({
|
|
145
151
|
parent_id: nonEmptyString.nullable().optional(),
|
|
152
|
+
trashed: z.boolean().optional(),
|
|
146
153
|
is_trashed: z.boolean().optional(),
|
|
147
154
|
cursor: nonEmptyString.optional(),
|
|
148
155
|
limit: z.number().int().min(1).max(100).optional()
|
|
149
|
-
});
|
|
156
|
+
}).refine((v) => !(v.trashed !== void 0 && v.is_trashed !== void 0), { message: "Use either trashed or is_trashed, not both" });
|
|
150
157
|
const folderListResponseSchema = z.object({
|
|
151
158
|
items: z.array(folderSchema),
|
|
152
159
|
next_cursor: z.string().nullable(),
|
|
@@ -169,6 +176,7 @@ const folderDeleteResponseSchema = z.object({
|
|
|
169
176
|
permanent: z.boolean(),
|
|
170
177
|
folders_deleted: z.number().int().nonnegative().optional()
|
|
171
178
|
});
|
|
179
|
+
const folderDetailResponseSchema = z.object({ folder: folderSchema });
|
|
172
180
|
const folderRestoreResponseSchema = z.object({
|
|
173
181
|
success: z.literal(true),
|
|
174
182
|
id: nonEmptyString
|
|
@@ -185,6 +193,11 @@ const serviceSchema = z.object({
|
|
|
185
193
|
created_at: unixTimestamp
|
|
186
194
|
});
|
|
187
195
|
const serviceDetailResponseSchema = z.object({ service: serviceSchema });
|
|
196
|
+
const adminServiceUpdateRequestSchema = z.object({
|
|
197
|
+
max_storage_bytes: positiveInt.optional(),
|
|
198
|
+
max_file_size_bytes: positiveInt.optional()
|
|
199
|
+
}).refine((v) => v.max_storage_bytes !== void 0 || v.max_file_size_bytes !== void 0, { message: "At least one of max_storage_bytes or max_file_size_bytes must be provided" });
|
|
200
|
+
const adminServiceUpdateResponseSchema = serviceDetailResponseSchema;
|
|
188
201
|
const serviceUsageResponseSchema = z.object({
|
|
189
202
|
service_id: nonEmptyString,
|
|
190
203
|
max_storage_bytes: positiveInt,
|
|
@@ -195,7 +208,9 @@ const auditEventActionSchema = z.enum([
|
|
|
195
208
|
"upload_completed",
|
|
196
209
|
"file_deleted",
|
|
197
210
|
"folder_deleted",
|
|
198
|
-
"quota_exceeded"
|
|
211
|
+
"quota_exceeded",
|
|
212
|
+
"share_link_accessed",
|
|
213
|
+
"quota_reconciled"
|
|
199
214
|
]);
|
|
200
215
|
const auditEventSchema = z.object({
|
|
201
216
|
id: nonEmptyString,
|
|
@@ -210,6 +225,8 @@ const auditEventSchema = z.object({
|
|
|
210
225
|
resource_id: nonEmptyString,
|
|
211
226
|
metadata: z.record(z.string(), z.unknown()).nullable(),
|
|
212
227
|
ip_address: z.string().nullable(),
|
|
228
|
+
actor_id: z.string().nullable().optional(),
|
|
229
|
+
target_user_id: z.string().nullable().optional(),
|
|
213
230
|
created_at: unixTimestamp
|
|
214
231
|
});
|
|
215
232
|
const auditLogListQuerySchema = z.object({
|
|
@@ -228,6 +245,207 @@ const auditLogListResponseSchema = z.object({
|
|
|
228
245
|
next_cursor: z.string().nullable(),
|
|
229
246
|
limit: positiveInt
|
|
230
247
|
});
|
|
248
|
+
const adminUserSchema = z.object({
|
|
249
|
+
id: nonEmptyString,
|
|
250
|
+
name: z.string(),
|
|
251
|
+
email: z.string().email(),
|
|
252
|
+
status: z.boolean(),
|
|
253
|
+
labels: z.array(z.string()),
|
|
254
|
+
role: nonEmptyString,
|
|
255
|
+
has_service_access: z.boolean(),
|
|
256
|
+
max_storage_bytes: positiveInt.nullable(),
|
|
257
|
+
effective_max_storage_bytes: positiveInt,
|
|
258
|
+
current_used_bytes: z.number().int().nonnegative(),
|
|
259
|
+
registration: unixTimestamp,
|
|
260
|
+
email_verification: z.boolean()
|
|
261
|
+
});
|
|
262
|
+
const adminUserListResponseSchema = z.object({
|
|
263
|
+
items: z.array(adminUserSchema),
|
|
264
|
+
total: z.number().int().nonnegative(),
|
|
265
|
+
offset: z.number().int().nonnegative(),
|
|
266
|
+
limit: positiveInt
|
|
267
|
+
});
|
|
268
|
+
const adminUserUpdateRequestSchema = z.object({
|
|
269
|
+
name: z.string().trim().min(1).max(128).optional(),
|
|
270
|
+
email: z.string().trim().email().optional(),
|
|
271
|
+
status: z.boolean().optional(),
|
|
272
|
+
labels: z.array(z.string().trim().min(1)).max(32).optional(),
|
|
273
|
+
role: z.enum([
|
|
274
|
+
"user",
|
|
275
|
+
"plus",
|
|
276
|
+
"admin"
|
|
277
|
+
]).optional(),
|
|
278
|
+
max_storage_bytes: positiveInt.nullable().optional()
|
|
279
|
+
});
|
|
280
|
+
const adminUserUpdateResponseSchema = z.object({ user: adminUserSchema });
|
|
281
|
+
const adminUserPasswordResetRequestSchema = z.object({ password: z.string().min(8).max(256) });
|
|
282
|
+
const adminUserPasswordResetResponseSchema = z.object({
|
|
283
|
+
success: z.literal(true),
|
|
284
|
+
user_id: nonEmptyString
|
|
285
|
+
});
|
|
286
|
+
//#endregion
|
|
287
|
+
//#region src/mainStorage.ts
|
|
288
|
+
const mainStorageListQuerySchema = z.object({
|
|
289
|
+
limit: z.number().int().min(1).max(100).optional(),
|
|
290
|
+
cursor: nonEmptyString.optional()
|
|
291
|
+
});
|
|
292
|
+
const mainStorageFileSchema = fileRecordSchema;
|
|
293
|
+
const mainStorageListResponseSchema = z.object({
|
|
294
|
+
items: z.array(mainStorageFileSchema),
|
|
295
|
+
next_cursor: z.string().nullable()
|
|
296
|
+
});
|
|
297
|
+
const mainStorageDetailResponseSchema = mainStorageFileSchema;
|
|
298
|
+
const mainStorageRenameRequestSchema = z.object({ filename: nonEmptyString.max(255) });
|
|
299
|
+
const mainStorageRenameResponseSchema = z.object({ file: mainStorageFileSchema });
|
|
300
|
+
const mainStorageDeleteResponseSchema = z.object({
|
|
301
|
+
success: z.boolean(),
|
|
302
|
+
file_id: nonEmptyString
|
|
303
|
+
});
|
|
304
|
+
const mainStorageRestoreResponseSchema = z.object({
|
|
305
|
+
success: z.boolean(),
|
|
306
|
+
file_id: nonEmptyString
|
|
307
|
+
});
|
|
308
|
+
//#endregion
|
|
309
|
+
//#region src/releases.ts
|
|
310
|
+
const releaseIdSchema = z.string().trim().min(1).max(128);
|
|
311
|
+
const releaseNameSchema = z.string().trim().min(1).max(256);
|
|
312
|
+
const releaseFilenameSchema = z.string().trim().min(1).max(255);
|
|
313
|
+
const releaseTagsSchema = z.array(z.string().trim().min(1).max(64)).max(32);
|
|
314
|
+
const releaseNotesSchema = z.string().trim().max(1e4).nullable().optional();
|
|
315
|
+
const releaseR2KeySchema = z.string().trim().min(1).max(1024);
|
|
316
|
+
const releaseDTOSchema = z.object({
|
|
317
|
+
id: nonEmptyString,
|
|
318
|
+
service_id: nonEmptyString,
|
|
319
|
+
name: nonEmptyString,
|
|
320
|
+
size: z.number().int().nonnegative(),
|
|
321
|
+
r2_key: nonEmptyString,
|
|
322
|
+
tags: z.array(nonEmptyString),
|
|
323
|
+
notes: z.string().nullable(),
|
|
324
|
+
force_update: z.boolean(),
|
|
325
|
+
uploaded_by: nonEmptyString,
|
|
326
|
+
upload_status: uploadStatusSchema,
|
|
327
|
+
created_at: nonEmptyString
|
|
328
|
+
});
|
|
329
|
+
const releaseUploadInitRequestSchema = z.object({
|
|
330
|
+
name: releaseNameSchema,
|
|
331
|
+
filename: releaseFilenameSchema,
|
|
332
|
+
tags: releaseTagsSchema.optional().default([]),
|
|
333
|
+
notes: releaseNotesSchema,
|
|
334
|
+
force_update: z.boolean().optional().default(false)
|
|
335
|
+
});
|
|
336
|
+
const releaseUploadInitResponseSchema = z.object({
|
|
337
|
+
release_id: nonEmptyString,
|
|
338
|
+
presigned_url: z.string().url(),
|
|
339
|
+
r2_key: nonEmptyString,
|
|
340
|
+
expires_at: positiveInt
|
|
341
|
+
});
|
|
342
|
+
const releaseUploadCompleteRequestSchema = z.object({
|
|
343
|
+
release_id: releaseIdSchema,
|
|
344
|
+
size: z.number().int().nonnegative()
|
|
345
|
+
});
|
|
346
|
+
const releaseUploadCompleteResponseSchema = z.object({
|
|
347
|
+
success: z.literal(true),
|
|
348
|
+
release_id: nonEmptyString,
|
|
349
|
+
status: z.literal("completed")
|
|
350
|
+
});
|
|
351
|
+
const releaseUploadFailResponseSchema = z.object({
|
|
352
|
+
success: z.literal(true),
|
|
353
|
+
release_id: nonEmptyString,
|
|
354
|
+
status: z.literal("failed")
|
|
355
|
+
});
|
|
356
|
+
const releasesListQuerySchema = z.object({
|
|
357
|
+
limit: z.number().int().positive().max(100).optional(),
|
|
358
|
+
cursor: nonEmptyString.optional()
|
|
359
|
+
});
|
|
360
|
+
const releasesListResponseSchema = z.object({
|
|
361
|
+
items: z.array(releaseDTOSchema),
|
|
362
|
+
next_cursor: z.string().nullable()
|
|
363
|
+
});
|
|
364
|
+
const releaseUpdateRequestSchema = z.object({
|
|
365
|
+
name: releaseNameSchema.optional(),
|
|
366
|
+
tags: releaseTagsSchema.optional(),
|
|
367
|
+
notes: releaseNotesSchema,
|
|
368
|
+
force_update: z.boolean().optional()
|
|
369
|
+
}).refine((body) => Object.values(body).some((value) => value !== void 0), { message: "At least one field must be provided" });
|
|
370
|
+
const releaseDeleteResponseSchema = z.object({
|
|
371
|
+
success: z.literal(true),
|
|
372
|
+
release_id: nonEmptyString
|
|
373
|
+
});
|
|
374
|
+
const releaseSyncManifestSchema = z.object({
|
|
375
|
+
id: releaseIdSchema.optional(),
|
|
376
|
+
name: releaseNameSchema,
|
|
377
|
+
r2_key: releaseR2KeySchema,
|
|
378
|
+
size: z.number().int().nonnegative(),
|
|
379
|
+
tags: releaseTagsSchema.optional().default([]),
|
|
380
|
+
notes: releaseNotesSchema,
|
|
381
|
+
force_update: z.boolean().optional().default(false)
|
|
382
|
+
});
|
|
383
|
+
const releaseSyncRequestSchema = z.object({ releases: z.array(releaseSyncManifestSchema).min(1).max(100) });
|
|
384
|
+
const releaseSyncResultSchema = z.object({
|
|
385
|
+
release_id: nonEmptyString,
|
|
386
|
+
success: z.boolean(),
|
|
387
|
+
status: uploadStatusSchema
|
|
388
|
+
});
|
|
389
|
+
const releaseSyncResponseSchema = z.object({
|
|
390
|
+
synced: z.number().int().nonnegative(),
|
|
391
|
+
results: z.array(releaseSyncResultSchema)
|
|
392
|
+
});
|
|
393
|
+
//#endregion
|
|
394
|
+
//#region src/shareLinks.ts
|
|
395
|
+
const shareLinkSchema = z.object({
|
|
396
|
+
id: nonEmptyString,
|
|
397
|
+
service_id: nonEmptyString,
|
|
398
|
+
file_id: nonEmptyString,
|
|
399
|
+
user_id: nonEmptyString,
|
|
400
|
+
slug: nonEmptyString,
|
|
401
|
+
name: z.string().nullable(),
|
|
402
|
+
has_password: z.boolean(),
|
|
403
|
+
expires_at: unixTimestamp.nullable(),
|
|
404
|
+
download_count: z.number().int().nonnegative(),
|
|
405
|
+
max_downloads: positiveInt.nullable(),
|
|
406
|
+
is_active: z.boolean(),
|
|
407
|
+
created_at: unixTimestamp,
|
|
408
|
+
updated_at: unixTimestamp
|
|
409
|
+
});
|
|
410
|
+
const shareLinkCreateRequestSchema = z.object({
|
|
411
|
+
slug: z.string().trim().min(3).max(64).optional(),
|
|
412
|
+
name: z.string().trim().max(128).optional(),
|
|
413
|
+
password: z.string().min(1).optional(),
|
|
414
|
+
expires_at: unixTimestamp.optional(),
|
|
415
|
+
max_downloads: positiveInt.optional()
|
|
416
|
+
});
|
|
417
|
+
const shareLinkUpdateRequestSchema = z.object({
|
|
418
|
+
name: z.string().trim().max(128).nullable().optional(),
|
|
419
|
+
is_active: z.boolean().optional(),
|
|
420
|
+
password: z.string().min(1).nullable().optional(),
|
|
421
|
+
expires_at: unixTimestamp.nullable().optional(),
|
|
422
|
+
max_downloads: positiveInt.nullable().optional()
|
|
423
|
+
}).refine((v) => v.name !== void 0 || v.is_active !== void 0 || v.password !== void 0 || v.expires_at !== void 0 || v.max_downloads !== void 0, { message: "At least one field must be provided" });
|
|
424
|
+
const shareLinkListResponseSchema = z.object({ items: z.array(shareLinkSchema) });
|
|
425
|
+
const shareLinkCreateResponseSchema = z.object({ link: shareLinkSchema });
|
|
426
|
+
const shareLinkUpdateResponseSchema = z.object({ link: shareLinkSchema });
|
|
427
|
+
const publicFileAccessResponseSchema = z.object({
|
|
428
|
+
file_id: nonEmptyString,
|
|
429
|
+
filename: nonEmptyString,
|
|
430
|
+
size: positiveInt,
|
|
431
|
+
mime_type: nonEmptyString,
|
|
432
|
+
requires_password: z.literal(false),
|
|
433
|
+
download_url: z.string().url(),
|
|
434
|
+
url_expires_at: unixTimestamp,
|
|
435
|
+
link_name: z.string().nullable(),
|
|
436
|
+
link_expires_at: unixTimestamp.nullable()
|
|
437
|
+
});
|
|
438
|
+
const publicFileLockedResponseSchema = z.object({
|
|
439
|
+
filename: nonEmptyString,
|
|
440
|
+
size: positiveInt,
|
|
441
|
+
mime_type: nonEmptyString,
|
|
442
|
+
requires_password: z.literal(true),
|
|
443
|
+
link_name: z.string().nullable()
|
|
444
|
+
});
|
|
445
|
+
const shareLinkDeleteResponseSchema = z.object({
|
|
446
|
+
success: z.literal(true),
|
|
447
|
+
id: nonEmptyString
|
|
448
|
+
});
|
|
231
449
|
//#endregion
|
|
232
450
|
//#region src/client.ts
|
|
233
451
|
var UnisourceError = class extends Error {
|
|
@@ -245,21 +463,20 @@ var UnisourceNetworkError = class extends Error {
|
|
|
245
463
|
this.name = "UnisourceNetworkError";
|
|
246
464
|
}
|
|
247
465
|
};
|
|
248
|
-
async function
|
|
249
|
-
const
|
|
250
|
-
const url = new URL(path, config.baseUrl);
|
|
466
|
+
async function fetchApi(baseUrl, method, path, options = {}) {
|
|
467
|
+
const url = new URL(path, baseUrl);
|
|
251
468
|
if (options.query) {
|
|
252
469
|
for (const [key, value] of Object.entries(options.query)) if (value !== void 0 && value !== null) url.searchParams.set(key, String(value));
|
|
253
470
|
}
|
|
254
|
-
const headers = {
|
|
255
|
-
if (token) headers["Authorization"] = `Bearer ${token}`;
|
|
471
|
+
const headers = { ...options.authHeaders };
|
|
256
472
|
if (options.body !== void 0) headers["Content-Type"] = "application/json";
|
|
257
473
|
let response;
|
|
258
474
|
try {
|
|
259
475
|
response = await fetch(url.toString(), {
|
|
260
476
|
method,
|
|
261
477
|
headers,
|
|
262
|
-
body: options.body !== void 0 ? JSON.stringify(options.body) : void 0
|
|
478
|
+
body: options.body !== void 0 ? JSON.stringify(options.body) : void 0,
|
|
479
|
+
signal: options.signal
|
|
263
480
|
});
|
|
264
481
|
} catch (err) {
|
|
265
482
|
throw new UnisourceNetworkError("Network request failed", err);
|
|
@@ -278,38 +495,221 @@ async function apiRequest(config, method, path, options = {}) {
|
|
|
278
495
|
}
|
|
279
496
|
return response.json();
|
|
280
497
|
}
|
|
498
|
+
async function apiRequest(config, method, path, options = {}) {
|
|
499
|
+
const token = await config.getToken();
|
|
500
|
+
const authHeaders = {
|
|
501
|
+
...options.extraHeaders ?? {},
|
|
502
|
+
"X-Service-ID": config.serviceId
|
|
503
|
+
};
|
|
504
|
+
if (token) authHeaders["Authorization"] = `Bearer ${token}`;
|
|
505
|
+
return fetchApi(config.baseUrl, method, path, {
|
|
506
|
+
...options,
|
|
507
|
+
authHeaders
|
|
508
|
+
});
|
|
509
|
+
}
|
|
510
|
+
async function getPublicFileInfo(baseUrl, slug, signal) {
|
|
511
|
+
return fetchApi(baseUrl, "GET", `/public/${encodeURIComponent(slug)}`, { signal });
|
|
512
|
+
}
|
|
513
|
+
async function unlockPublicFile(baseUrl, slug, password, signal) {
|
|
514
|
+
return fetchApi(baseUrl, "POST", `/public/${encodeURIComponent(slug)}/unlock`, {
|
|
515
|
+
body: { password },
|
|
516
|
+
signal
|
|
517
|
+
});
|
|
518
|
+
}
|
|
281
519
|
var UnisourceClient = class {
|
|
282
520
|
config;
|
|
283
521
|
constructor(config) {
|
|
284
522
|
this.config = config;
|
|
285
523
|
}
|
|
524
|
+
request(method, path, options = {}) {
|
|
525
|
+
return apiRequest(this.config, method, path, options);
|
|
526
|
+
}
|
|
527
|
+
withAsUser(options) {
|
|
528
|
+
return options?.asUser ? { "X-Target-User-ID": options.asUser } : {};
|
|
529
|
+
}
|
|
286
530
|
upload = {
|
|
287
|
-
r2Init: (body) => apiRequest(this.config, "POST", "/upload/r2/init", {
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
531
|
+
r2Init: (body, signal) => apiRequest(this.config, "POST", "/upload/r2/init", {
|
|
532
|
+
body,
|
|
533
|
+
signal
|
|
534
|
+
}),
|
|
535
|
+
appwriteInit: (body, signal) => apiRequest(this.config, "POST", "/upload/appwrite/init", {
|
|
536
|
+
body,
|
|
537
|
+
signal
|
|
538
|
+
}),
|
|
539
|
+
complete: (body, signal) => apiRequest(this.config, "POST", "/upload/complete", {
|
|
540
|
+
body,
|
|
541
|
+
signal
|
|
542
|
+
}),
|
|
543
|
+
fail: (body, signal) => apiRequest(this.config, "POST", "/upload/fail", {
|
|
544
|
+
body,
|
|
545
|
+
signal
|
|
546
|
+
})
|
|
291
547
|
};
|
|
292
548
|
myFiles = {
|
|
293
|
-
list: (query) => apiRequest(this.config, "GET", "/my-files", {
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
549
|
+
list: (query, signal, options) => apiRequest(this.config, "GET", "/my-files", {
|
|
550
|
+
query,
|
|
551
|
+
signal,
|
|
552
|
+
extraHeaders: this.withAsUser(options)
|
|
553
|
+
}),
|
|
554
|
+
trash: (query, signal, options) => apiRequest(this.config, "GET", "/my-files/trash", {
|
|
555
|
+
query,
|
|
556
|
+
signal,
|
|
557
|
+
extraHeaders: this.withAsUser(options)
|
|
558
|
+
}),
|
|
559
|
+
get: (id, signal, options) => apiRequest(this.config, "GET", `/my-files/${id}`, {
|
|
560
|
+
signal,
|
|
561
|
+
extraHeaders: this.withAsUser(options)
|
|
562
|
+
}),
|
|
563
|
+
downloadUrl: (id, signal, options) => apiRequest(this.config, "GET", `/my-files/${id}/download-url`, {
|
|
564
|
+
signal,
|
|
565
|
+
extraHeaders: this.withAsUser(options)
|
|
566
|
+
}),
|
|
567
|
+
move: (id, body, signal, options) => apiRequest(this.config, "PATCH", `/my-files/${id}/move`, {
|
|
568
|
+
body,
|
|
569
|
+
signal,
|
|
570
|
+
extraHeaders: this.withAsUser(options)
|
|
571
|
+
}),
|
|
572
|
+
delete: (id, query, signal, options) => apiRequest(this.config, "DELETE", `/my-files/${id}`, {
|
|
573
|
+
query,
|
|
574
|
+
signal,
|
|
575
|
+
extraHeaders: this.withAsUser(options)
|
|
576
|
+
}),
|
|
577
|
+
restore: (id, signal, options) => apiRequest(this.config, "POST", `/my-files/${id}/restore`, {
|
|
578
|
+
signal,
|
|
579
|
+
extraHeaders: this.withAsUser(options)
|
|
580
|
+
}),
|
|
581
|
+
update: (id, body, signal, options) => apiRequest(this.config, "PATCH", `/my-files/${id}`, {
|
|
582
|
+
body,
|
|
583
|
+
signal,
|
|
584
|
+
extraHeaders: this.withAsUser(options)
|
|
585
|
+
})
|
|
299
586
|
};
|
|
300
587
|
folders = {
|
|
301
|
-
list: (query) => apiRequest(this.config, "GET", "/folders", {
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
588
|
+
list: (query, signal, options) => apiRequest(this.config, "GET", "/folders", {
|
|
589
|
+
query,
|
|
590
|
+
signal,
|
|
591
|
+
extraHeaders: this.withAsUser(options)
|
|
592
|
+
}),
|
|
593
|
+
get: (id, signal, options) => apiRequest(this.config, "GET", `/folders/${id}`, {
|
|
594
|
+
signal,
|
|
595
|
+
extraHeaders: this.withAsUser(options)
|
|
596
|
+
}),
|
|
597
|
+
create: (body, signal, options) => apiRequest(this.config, "POST", "/folders", {
|
|
598
|
+
body,
|
|
599
|
+
signal,
|
|
600
|
+
extraHeaders: this.withAsUser(options)
|
|
601
|
+
}),
|
|
602
|
+
update: (id, body, signal, options) => apiRequest(this.config, "PATCH", `/folders/${id}`, {
|
|
603
|
+
body,
|
|
604
|
+
signal,
|
|
605
|
+
extraHeaders: this.withAsUser(options)
|
|
606
|
+
}),
|
|
607
|
+
delete: (id, query, signal, options) => apiRequest(this.config, "DELETE", `/folders/${id}`, {
|
|
608
|
+
query,
|
|
609
|
+
signal,
|
|
610
|
+
extraHeaders: this.withAsUser(options)
|
|
611
|
+
}),
|
|
612
|
+
restore: (id, signal, options) => apiRequest(this.config, "POST", `/folders/${id}/restore`, {
|
|
613
|
+
signal,
|
|
614
|
+
extraHeaders: this.withAsUser(options)
|
|
615
|
+
})
|
|
616
|
+
};
|
|
617
|
+
mainStorage = {
|
|
618
|
+
list: (query) => this.request("GET", "/main", { query }),
|
|
619
|
+
get: (fileId) => this.request("GET", `/main/${fileId}`),
|
|
620
|
+
rename: (fileId, filename) => this.request("PATCH", `/main/${fileId}`, { body: { filename } }),
|
|
621
|
+
delete: (fileId, permanent = false) => this.request("DELETE", `/main/${fileId}`, { query: { permanent: permanent || void 0 } }),
|
|
622
|
+
restore: (fileId) => this.request("POST", `/main/${fileId}/restore`),
|
|
623
|
+
upload: {
|
|
624
|
+
r2Init: (input) => this.request("POST", "/upload/r2/init", { body: {
|
|
625
|
+
...input,
|
|
626
|
+
is_main_storage: true
|
|
627
|
+
} }),
|
|
628
|
+
appwriteInit: (input) => this.request("POST", "/upload/appwrite/init", { body: {
|
|
629
|
+
...input,
|
|
630
|
+
is_main_storage: true
|
|
631
|
+
} }),
|
|
632
|
+
complete: (uploadId) => this.request("POST", "/upload/complete", { body: {
|
|
633
|
+
upload_id: uploadId,
|
|
634
|
+
is_main_storage: true
|
|
635
|
+
} }),
|
|
636
|
+
fail: (uploadId) => this.request("POST", "/upload/fail", { body: { upload_id: uploadId } })
|
|
637
|
+
}
|
|
638
|
+
};
|
|
639
|
+
releases = {
|
|
640
|
+
upload: {
|
|
641
|
+
init: (body, signal) => apiRequest(this.config, "POST", "/releases/upload/init", {
|
|
642
|
+
body,
|
|
643
|
+
signal
|
|
644
|
+
}),
|
|
645
|
+
complete: (body, signal) => apiRequest(this.config, "POST", "/releases/upload/complete", {
|
|
646
|
+
body,
|
|
647
|
+
signal
|
|
648
|
+
}),
|
|
649
|
+
fail: (releaseId, signal) => apiRequest(this.config, "POST", "/releases/upload/fail", {
|
|
650
|
+
body: { release_id: releaseId },
|
|
651
|
+
signal
|
|
652
|
+
})
|
|
653
|
+
},
|
|
654
|
+
list: (query, signal) => apiRequest(this.config, "GET", "/releases", {
|
|
655
|
+
query,
|
|
656
|
+
signal
|
|
657
|
+
}),
|
|
658
|
+
get: (releaseId, signal) => apiRequest(this.config, "GET", `/releases/${releaseId}`, { signal }),
|
|
659
|
+
latest: (signal) => apiRequest(this.config, "GET", "/releases/latest", { signal }),
|
|
660
|
+
update: (releaseId, body, signal) => apiRequest(this.config, "PATCH", `/releases/${releaseId}`, {
|
|
661
|
+
body,
|
|
662
|
+
signal
|
|
663
|
+
}),
|
|
664
|
+
delete: (releaseId, signal) => apiRequest(this.config, "DELETE", `/releases/${releaseId}`, { signal }),
|
|
665
|
+
sync: (body, signal) => apiRequest(this.config, "POST", "/releases/sync", {
|
|
666
|
+
body,
|
|
667
|
+
signal
|
|
668
|
+
})
|
|
306
669
|
};
|
|
307
670
|
admin = {
|
|
308
|
-
serviceDetail: () => apiRequest(this.config, "GET", "/admin/service"),
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
671
|
+
serviceDetail: (signal) => apiRequest(this.config, "GET", "/admin/service", { signal }),
|
|
672
|
+
updateService: (body, signal) => apiRequest(this.config, "PATCH", "/admin/service", {
|
|
673
|
+
body,
|
|
674
|
+
signal
|
|
675
|
+
}),
|
|
676
|
+
usage: (signal) => apiRequest(this.config, "GET", "/admin/service/usage", { signal }),
|
|
677
|
+
listUploads: (query, signal) => apiRequest(this.config, "GET", "/files", {
|
|
678
|
+
query,
|
|
679
|
+
signal
|
|
680
|
+
}),
|
|
681
|
+
getUpload: (id, signal) => apiRequest(this.config, "GET", `/files/${id}`, { signal }),
|
|
682
|
+
downloadUploadUrl: (id, signal) => apiRequest(this.config, "GET", `/files/${id}/download-url`, { signal }),
|
|
683
|
+
deleteUpload: (id, signal) => apiRequest(this.config, "DELETE", `/files/${id}`, { signal }),
|
|
684
|
+
auditLog: (query, signal) => apiRequest(this.config, "GET", "/admin/audit-log", {
|
|
685
|
+
query,
|
|
686
|
+
signal
|
|
687
|
+
}),
|
|
688
|
+
listUsers: (query, signal) => apiRequest(this.config, "GET", "/admin/users", {
|
|
689
|
+
query,
|
|
690
|
+
signal
|
|
691
|
+
}),
|
|
692
|
+
updateUser: (userId, body, signal) => apiRequest(this.config, "PATCH", `/admin/users/${userId}`, {
|
|
693
|
+
body,
|
|
694
|
+
signal
|
|
695
|
+
}),
|
|
696
|
+
resetUserPassword: (userId, body, signal) => apiRequest(this.config, "POST", `/admin/users/${userId}/password`, {
|
|
697
|
+
body,
|
|
698
|
+
signal
|
|
699
|
+
})
|
|
700
|
+
};
|
|
701
|
+
shareLinks = {
|
|
702
|
+
create: (fileId, body, signal) => apiRequest(this.config, "POST", `/my-files/${fileId}/share-links`, {
|
|
703
|
+
body,
|
|
704
|
+
signal
|
|
705
|
+
}),
|
|
706
|
+
list: (fileId, signal) => apiRequest(this.config, "GET", `/my-files/${fileId}/share-links`, { signal }),
|
|
707
|
+
update: (linkId, body, signal) => apiRequest(this.config, "PATCH", `/share-links/${linkId}`, {
|
|
708
|
+
body,
|
|
709
|
+
signal
|
|
710
|
+
}),
|
|
711
|
+
delete: (linkId, signal) => apiRequest(this.config, "DELETE", `/share-links/${linkId}`, { signal })
|
|
312
712
|
};
|
|
313
713
|
};
|
|
314
714
|
//#endregion
|
|
315
|
-
export { FILES_DEFAULT_LIMIT, FILES_MAX_LIMIT, UnisourceClient, UnisourceError, UnisourceNetworkError, apiErrorSchema, auditEventActionSchema, auditEventSchema, auditLogListQuerySchema, auditLogListResponseSchema, fileDeleteResponseSchema, fileDownloadUrlResponseSchema, fileMoveRequestSchema, fileRecordDetailResponseSchema, fileRecordSchema, fileRecordsListQuerySchema, fileRecordsListResponseSchema, fileRestoreResponseSchema, folderCreateRequestSchema, folderCreateResponseSchema, folderDeleteResponseSchema, folderListQuerySchema, folderListResponseSchema, folderRestoreResponseSchema, folderSchema, folderUpdateRequestSchema, folderUpdateResponseSchema, nonEmptyString, positiveInt, serviceDetailResponseSchema, serviceSchema, serviceUsageResponseSchema, unixTimestamp, uploadAppwriteInitRequestSchema, uploadAppwriteInitResponseSchema, uploadCompleteResponseSchema, uploadDestinationSchema, uploadFailResponseSchema, uploadLifecycleRequestSchema, uploadR2InitRequestSchema, uploadR2InitResponseSchema, uploadRecordSchema, uploadStatusSchema, uploadsListResponseSchema };
|
|
715
|
+
export { FILES_DEFAULT_LIMIT, FILES_MAX_LIMIT, UnisourceClient, UnisourceError, UnisourceNetworkError, adminServiceUpdateRequestSchema, adminServiceUpdateResponseSchema, adminUserListResponseSchema, adminUserPasswordResetRequestSchema, adminUserPasswordResetResponseSchema, adminUserSchema, adminUserUpdateRequestSchema, adminUserUpdateResponseSchema, apiErrorSchema, auditEventActionSchema, auditEventSchema, auditLogListQuerySchema, auditLogListResponseSchema, fileDeleteResponseSchema, fileDownloadUrlResponseSchema, fileMoveRequestSchema, fileRecordDetailResponseSchema, fileRecordSchema, fileRecordsListQuerySchema, fileRecordsListResponseSchema, fileRestoreResponseSchema, fileUpdateRequestSchema, fileUpdateResponseSchema, folderCreateRequestSchema, folderCreateResponseSchema, folderDeleteResponseSchema, folderDetailResponseSchema, folderListQuerySchema, folderListResponseSchema, folderRestoreResponseSchema, folderSchema, folderUpdateRequestSchema, folderUpdateResponseSchema, getPublicFileInfo, mainStorageDeleteResponseSchema, mainStorageDetailResponseSchema, mainStorageFileSchema, mainStorageListQuerySchema, mainStorageListResponseSchema, mainStorageRenameRequestSchema, mainStorageRenameResponseSchema, mainStorageRestoreResponseSchema, nonEmptyString, positiveInt, publicFileAccessResponseSchema, publicFileLockedResponseSchema, releaseDTOSchema, releaseDeleteResponseSchema, releaseSyncManifestSchema, releaseSyncRequestSchema, releaseSyncResponseSchema, releaseSyncResultSchema, releaseUpdateRequestSchema, releaseUploadCompleteRequestSchema, releaseUploadCompleteResponseSchema, releaseUploadFailResponseSchema, releaseUploadInitRequestSchema, releaseUploadInitResponseSchema, releasesListQuerySchema, releasesListResponseSchema, serviceDetailResponseSchema, serviceSchema, serviceUsageResponseSchema, shareLinkCreateRequestSchema, shareLinkCreateResponseSchema, shareLinkDeleteResponseSchema, shareLinkListResponseSchema, shareLinkSchema, shareLinkUpdateRequestSchema, shareLinkUpdateResponseSchema, unixTimestamp, unlockPublicFile, uploadAppwriteInitRequestSchema, uploadAppwriteInitResponseSchema, uploadCompleteResponseSchema, uploadDestinationSchema, uploadFailResponseSchema, uploadLifecycleRequestSchema, uploadR2InitRequestSchema, uploadR2InitResponseSchema, uploadRecordDetailResponseSchema, uploadRecordSchema, uploadStatusSchema, uploadsListResponseSchema };
|
package/package.json
CHANGED
|
@@ -2,17 +2,21 @@
|
|
|
2
2
|
"name": "@unisource/sdk",
|
|
3
3
|
"private": false,
|
|
4
4
|
"type": "module",
|
|
5
|
-
"version": "0.
|
|
5
|
+
"version": "0.3.1",
|
|
6
6
|
"description": "Wspolne kontrakty danych dla backendu i frontendu UniSource.",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"publishConfig": {
|
|
9
9
|
"access": "public"
|
|
10
10
|
},
|
|
11
11
|
"exports": {
|
|
12
|
-
".":
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.mts",
|
|
14
|
+
"import": "./dist/index.mjs",
|
|
15
|
+
"default": "./dist/index.mjs"
|
|
16
|
+
},
|
|
13
17
|
"./package.json": "./package.json"
|
|
14
18
|
},
|
|
15
|
-
"types": "./
|
|
19
|
+
"types": "./dist/index.d.mts",
|
|
16
20
|
"files": [
|
|
17
21
|
"dist",
|
|
18
22
|
"src"
|
|
@@ -28,7 +32,7 @@
|
|
|
28
32
|
"zod": "^4.3.6"
|
|
29
33
|
},
|
|
30
34
|
"scripts": {
|
|
31
|
-
"build": "tsdown
|
|
35
|
+
"build": "tsdown",
|
|
32
36
|
"dev": "tsdown --watch",
|
|
33
37
|
"test": "pnpm run build && vitest",
|
|
34
38
|
"typecheck": "tsc --noEmit"
|