@unisource/sdk 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +55 -23
- package/dist/index.d.mts +560 -21
- package/dist/index.mjs +433 -38
- package/package.json +8 -4
- package/src/client.ts +472 -233
- package/src/fileRecords.ts +99 -87
- package/src/folders.ts +97 -84
- package/src/index.ts +198 -106
- package/src/mainStorage.ts +40 -0
- package/src/primitives.ts +30 -25
- package/src/releases.ts +132 -0
- package/src/services.ts +135 -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,
|
|
@@ -228,6 +243,204 @@ const auditLogListResponseSchema = z.object({
|
|
|
228
243
|
next_cursor: z.string().nullable(),
|
|
229
244
|
limit: positiveInt
|
|
230
245
|
});
|
|
246
|
+
const adminUserSchema = z.object({
|
|
247
|
+
id: nonEmptyString,
|
|
248
|
+
name: z.string(),
|
|
249
|
+
email: z.string().email(),
|
|
250
|
+
status: z.boolean(),
|
|
251
|
+
labels: z.array(z.string()),
|
|
252
|
+
role: nonEmptyString,
|
|
253
|
+
has_service_access: z.boolean(),
|
|
254
|
+
max_storage_bytes: positiveInt.nullable(),
|
|
255
|
+
effective_max_storage_bytes: positiveInt,
|
|
256
|
+
current_used_bytes: z.number().int().nonnegative(),
|
|
257
|
+
registration: unixTimestamp,
|
|
258
|
+
email_verification: z.boolean()
|
|
259
|
+
});
|
|
260
|
+
const adminUserListResponseSchema = z.object({
|
|
261
|
+
items: z.array(adminUserSchema),
|
|
262
|
+
total: z.number().int().nonnegative(),
|
|
263
|
+
offset: z.number().int().nonnegative(),
|
|
264
|
+
limit: positiveInt
|
|
265
|
+
});
|
|
266
|
+
const adminUserUpdateRequestSchema = z.object({
|
|
267
|
+
name: z.string().trim().min(1).max(128).optional(),
|
|
268
|
+
email: z.string().trim().email().optional(),
|
|
269
|
+
status: z.boolean().optional(),
|
|
270
|
+
labels: z.array(z.string().trim().min(1)).max(32).optional(),
|
|
271
|
+
role: z.enum([
|
|
272
|
+
"user",
|
|
273
|
+
"plus",
|
|
274
|
+
"admin"
|
|
275
|
+
]).optional(),
|
|
276
|
+
max_storage_bytes: positiveInt.nullable().optional()
|
|
277
|
+
});
|
|
278
|
+
const adminUserUpdateResponseSchema = z.object({ user: adminUserSchema });
|
|
279
|
+
const adminUserPasswordResetRequestSchema = z.object({ password: z.string().min(8).max(256) });
|
|
280
|
+
const adminUserPasswordResetResponseSchema = z.object({
|
|
281
|
+
success: z.literal(true),
|
|
282
|
+
user_id: nonEmptyString
|
|
283
|
+
});
|
|
284
|
+
//#endregion
|
|
285
|
+
//#region src/mainStorage.ts
|
|
286
|
+
const mainStorageListQuerySchema = z.object({
|
|
287
|
+
limit: z.number().int().positive().optional(),
|
|
288
|
+
cursor: nonEmptyString.optional()
|
|
289
|
+
});
|
|
290
|
+
const mainStorageListResponseSchema = z.object({
|
|
291
|
+
items: z.array(fileRecordSchema),
|
|
292
|
+
next_cursor: z.string().nullable()
|
|
293
|
+
});
|
|
294
|
+
const mainStorageRenameRequestSchema = z.object({ filename: nonEmptyString });
|
|
295
|
+
const mainStorageDeleteResponseSchema = z.object({
|
|
296
|
+
success: z.boolean(),
|
|
297
|
+
file_id: nonEmptyString
|
|
298
|
+
});
|
|
299
|
+
const mainStorageRestoreResponseSchema = z.object({
|
|
300
|
+
success: z.boolean(),
|
|
301
|
+
file_id: nonEmptyString
|
|
302
|
+
});
|
|
303
|
+
//#endregion
|
|
304
|
+
//#region src/releases.ts
|
|
305
|
+
const releaseIdSchema = z.string().trim().min(1).max(128);
|
|
306
|
+
const releaseNameSchema = z.string().trim().min(1).max(256);
|
|
307
|
+
const releaseFilenameSchema = z.string().trim().min(1).max(255);
|
|
308
|
+
const releaseTagsSchema = z.array(z.string().trim().min(1).max(64)).max(32);
|
|
309
|
+
const releaseNotesSchema = z.string().trim().max(1e4).nullable().optional();
|
|
310
|
+
const releaseR2KeySchema = z.string().trim().min(1).max(1024);
|
|
311
|
+
const releaseDTOSchema = z.object({
|
|
312
|
+
id: nonEmptyString,
|
|
313
|
+
service_id: nonEmptyString,
|
|
314
|
+
name: nonEmptyString,
|
|
315
|
+
size: z.number().int().nonnegative(),
|
|
316
|
+
r2_key: nonEmptyString,
|
|
317
|
+
tags: z.array(nonEmptyString),
|
|
318
|
+
notes: z.string().nullable(),
|
|
319
|
+
force_update: z.boolean(),
|
|
320
|
+
uploaded_by: nonEmptyString,
|
|
321
|
+
upload_status: uploadStatusSchema,
|
|
322
|
+
created_at: nonEmptyString
|
|
323
|
+
});
|
|
324
|
+
const releaseUploadInitRequestSchema = z.object({
|
|
325
|
+
name: releaseNameSchema,
|
|
326
|
+
filename: releaseFilenameSchema,
|
|
327
|
+
tags: releaseTagsSchema.optional().default([]),
|
|
328
|
+
notes: releaseNotesSchema,
|
|
329
|
+
force_update: z.boolean().optional().default(false)
|
|
330
|
+
});
|
|
331
|
+
const releaseUploadInitResponseSchema = z.object({
|
|
332
|
+
release_id: nonEmptyString,
|
|
333
|
+
presigned_url: z.string().url(),
|
|
334
|
+
r2_key: nonEmptyString,
|
|
335
|
+
expires_at: positiveInt
|
|
336
|
+
});
|
|
337
|
+
const releaseUploadCompleteRequestSchema = z.object({
|
|
338
|
+
release_id: releaseIdSchema,
|
|
339
|
+
size: z.number().int().nonnegative()
|
|
340
|
+
});
|
|
341
|
+
const releaseUploadCompleteResponseSchema = z.object({
|
|
342
|
+
success: z.literal(true),
|
|
343
|
+
release_id: nonEmptyString,
|
|
344
|
+
status: z.literal("completed")
|
|
345
|
+
});
|
|
346
|
+
const releaseUploadFailResponseSchema = z.object({
|
|
347
|
+
success: z.literal(true),
|
|
348
|
+
release_id: nonEmptyString,
|
|
349
|
+
status: z.literal("failed")
|
|
350
|
+
});
|
|
351
|
+
const releasesListQuerySchema = z.object({
|
|
352
|
+
limit: z.number().int().positive().max(100).optional(),
|
|
353
|
+
cursor: nonEmptyString.optional()
|
|
354
|
+
});
|
|
355
|
+
const releasesListResponseSchema = z.object({
|
|
356
|
+
items: z.array(releaseDTOSchema),
|
|
357
|
+
next_cursor: z.string().nullable()
|
|
358
|
+
});
|
|
359
|
+
const releaseUpdateRequestSchema = z.object({
|
|
360
|
+
name: releaseNameSchema.optional(),
|
|
361
|
+
tags: releaseTagsSchema.optional(),
|
|
362
|
+
notes: releaseNotesSchema,
|
|
363
|
+
force_update: z.boolean().optional()
|
|
364
|
+
}).refine((body) => Object.values(body).some((value) => value !== void 0), { message: "At least one field must be provided" });
|
|
365
|
+
const releaseDeleteResponseSchema = z.object({
|
|
366
|
+
success: z.literal(true),
|
|
367
|
+
release_id: nonEmptyString
|
|
368
|
+
});
|
|
369
|
+
const releaseSyncManifestSchema = z.object({
|
|
370
|
+
id: releaseIdSchema.optional(),
|
|
371
|
+
name: releaseNameSchema,
|
|
372
|
+
r2_key: releaseR2KeySchema,
|
|
373
|
+
size: z.number().int().nonnegative(),
|
|
374
|
+
tags: releaseTagsSchema.optional().default([]),
|
|
375
|
+
notes: releaseNotesSchema,
|
|
376
|
+
force_update: z.boolean().optional().default(false)
|
|
377
|
+
});
|
|
378
|
+
const releaseSyncRequestSchema = z.object({ releases: z.array(releaseSyncManifestSchema).min(1).max(100) });
|
|
379
|
+
const releaseSyncResultSchema = z.object({
|
|
380
|
+
release_id: nonEmptyString,
|
|
381
|
+
success: z.boolean(),
|
|
382
|
+
status: uploadStatusSchema
|
|
383
|
+
});
|
|
384
|
+
const releaseSyncResponseSchema = z.object({
|
|
385
|
+
synced: z.number().int().nonnegative(),
|
|
386
|
+
results: z.array(releaseSyncResultSchema)
|
|
387
|
+
});
|
|
388
|
+
//#endregion
|
|
389
|
+
//#region src/shareLinks.ts
|
|
390
|
+
const shareLinkSchema = z.object({
|
|
391
|
+
id: nonEmptyString,
|
|
392
|
+
service_id: nonEmptyString,
|
|
393
|
+
file_id: nonEmptyString,
|
|
394
|
+
user_id: nonEmptyString,
|
|
395
|
+
slug: nonEmptyString,
|
|
396
|
+
name: z.string().nullable(),
|
|
397
|
+
has_password: z.boolean(),
|
|
398
|
+
expires_at: unixTimestamp.nullable(),
|
|
399
|
+
download_count: z.number().int().nonnegative(),
|
|
400
|
+
max_downloads: positiveInt.nullable(),
|
|
401
|
+
is_active: z.boolean(),
|
|
402
|
+
created_at: unixTimestamp,
|
|
403
|
+
updated_at: unixTimestamp
|
|
404
|
+
});
|
|
405
|
+
const shareLinkCreateRequestSchema = z.object({
|
|
406
|
+
slug: z.string().trim().min(3).max(64).optional(),
|
|
407
|
+
name: z.string().trim().max(128).optional(),
|
|
408
|
+
password: z.string().min(1).optional(),
|
|
409
|
+
expires_at: unixTimestamp.optional(),
|
|
410
|
+
max_downloads: positiveInt.optional()
|
|
411
|
+
});
|
|
412
|
+
const shareLinkUpdateRequestSchema = z.object({
|
|
413
|
+
name: z.string().trim().max(128).nullable().optional(),
|
|
414
|
+
is_active: z.boolean().optional(),
|
|
415
|
+
password: z.string().min(1).nullable().optional(),
|
|
416
|
+
expires_at: unixTimestamp.nullable().optional(),
|
|
417
|
+
max_downloads: positiveInt.nullable().optional()
|
|
418
|
+
}).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" });
|
|
419
|
+
const shareLinkListResponseSchema = z.object({ items: z.array(shareLinkSchema) });
|
|
420
|
+
const shareLinkCreateResponseSchema = z.object({ link: shareLinkSchema });
|
|
421
|
+
const shareLinkUpdateResponseSchema = z.object({ link: shareLinkSchema });
|
|
422
|
+
const publicFileAccessResponseSchema = z.object({
|
|
423
|
+
file_id: nonEmptyString,
|
|
424
|
+
filename: nonEmptyString,
|
|
425
|
+
size: positiveInt,
|
|
426
|
+
mime_type: nonEmptyString,
|
|
427
|
+
requires_password: z.literal(false),
|
|
428
|
+
download_url: z.string().url(),
|
|
429
|
+
url_expires_at: unixTimestamp,
|
|
430
|
+
link_name: z.string().nullable(),
|
|
431
|
+
link_expires_at: unixTimestamp.nullable()
|
|
432
|
+
});
|
|
433
|
+
const publicFileLockedResponseSchema = z.object({
|
|
434
|
+
filename: nonEmptyString,
|
|
435
|
+
size: positiveInt,
|
|
436
|
+
mime_type: nonEmptyString,
|
|
437
|
+
requires_password: z.literal(true),
|
|
438
|
+
link_name: z.string().nullable()
|
|
439
|
+
});
|
|
440
|
+
const shareLinkDeleteResponseSchema = z.object({
|
|
441
|
+
success: z.literal(true),
|
|
442
|
+
id: nonEmptyString
|
|
443
|
+
});
|
|
231
444
|
//#endregion
|
|
232
445
|
//#region src/client.ts
|
|
233
446
|
var UnisourceError = class extends Error {
|
|
@@ -245,21 +458,20 @@ var UnisourceNetworkError = class extends Error {
|
|
|
245
458
|
this.name = "UnisourceNetworkError";
|
|
246
459
|
}
|
|
247
460
|
};
|
|
248
|
-
async function
|
|
249
|
-
const
|
|
250
|
-
const url = new URL(path, config.baseUrl);
|
|
461
|
+
async function fetchApi(baseUrl, method, path, options = {}) {
|
|
462
|
+
const url = new URL(path, baseUrl);
|
|
251
463
|
if (options.query) {
|
|
252
464
|
for (const [key, value] of Object.entries(options.query)) if (value !== void 0 && value !== null) url.searchParams.set(key, String(value));
|
|
253
465
|
}
|
|
254
|
-
const headers = {
|
|
255
|
-
if (token) headers["Authorization"] = `Bearer ${token}`;
|
|
466
|
+
const headers = { ...options.authHeaders };
|
|
256
467
|
if (options.body !== void 0) headers["Content-Type"] = "application/json";
|
|
257
468
|
let response;
|
|
258
469
|
try {
|
|
259
470
|
response = await fetch(url.toString(), {
|
|
260
471
|
method,
|
|
261
472
|
headers,
|
|
262
|
-
body: options.body !== void 0 ? JSON.stringify(options.body) : void 0
|
|
473
|
+
body: options.body !== void 0 ? JSON.stringify(options.body) : void 0,
|
|
474
|
+
signal: options.signal
|
|
263
475
|
});
|
|
264
476
|
} catch (err) {
|
|
265
477
|
throw new UnisourceNetworkError("Network request failed", err);
|
|
@@ -278,38 +490,221 @@ async function apiRequest(config, method, path, options = {}) {
|
|
|
278
490
|
}
|
|
279
491
|
return response.json();
|
|
280
492
|
}
|
|
493
|
+
async function apiRequest(config, method, path, options = {}) {
|
|
494
|
+
const token = await config.getToken();
|
|
495
|
+
const authHeaders = {
|
|
496
|
+
...options.extraHeaders ?? {},
|
|
497
|
+
"X-Service-ID": config.serviceId
|
|
498
|
+
};
|
|
499
|
+
if (token) authHeaders["Authorization"] = `Bearer ${token}`;
|
|
500
|
+
return fetchApi(config.baseUrl, method, path, {
|
|
501
|
+
...options,
|
|
502
|
+
authHeaders
|
|
503
|
+
});
|
|
504
|
+
}
|
|
505
|
+
async function getPublicFileInfo(baseUrl, slug, signal) {
|
|
506
|
+
return fetchApi(baseUrl, "GET", `/public/${encodeURIComponent(slug)}`, { signal });
|
|
507
|
+
}
|
|
508
|
+
async function unlockPublicFile(baseUrl, slug, password, signal) {
|
|
509
|
+
return fetchApi(baseUrl, "POST", `/public/${encodeURIComponent(slug)}/unlock`, {
|
|
510
|
+
body: { password },
|
|
511
|
+
signal
|
|
512
|
+
});
|
|
513
|
+
}
|
|
281
514
|
var UnisourceClient = class {
|
|
282
515
|
config;
|
|
283
516
|
constructor(config) {
|
|
284
517
|
this.config = config;
|
|
285
518
|
}
|
|
519
|
+
request(method, path, options = {}) {
|
|
520
|
+
return apiRequest(this.config, method, path, options);
|
|
521
|
+
}
|
|
522
|
+
withAsUser(options) {
|
|
523
|
+
return options?.asUser ? { "X-Target-User-ID": options.asUser } : {};
|
|
524
|
+
}
|
|
286
525
|
upload = {
|
|
287
|
-
r2Init: (body) => apiRequest(this.config, "POST", "/upload/r2/init", {
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
526
|
+
r2Init: (body, signal) => apiRequest(this.config, "POST", "/upload/r2/init", {
|
|
527
|
+
body,
|
|
528
|
+
signal
|
|
529
|
+
}),
|
|
530
|
+
appwriteInit: (body, signal) => apiRequest(this.config, "POST", "/upload/appwrite/init", {
|
|
531
|
+
body,
|
|
532
|
+
signal
|
|
533
|
+
}),
|
|
534
|
+
complete: (body, signal) => apiRequest(this.config, "POST", "/upload/complete", {
|
|
535
|
+
body,
|
|
536
|
+
signal
|
|
537
|
+
}),
|
|
538
|
+
fail: (body, signal) => apiRequest(this.config, "POST", "/upload/fail", {
|
|
539
|
+
body,
|
|
540
|
+
signal
|
|
541
|
+
})
|
|
291
542
|
};
|
|
292
543
|
myFiles = {
|
|
293
|
-
list: (query) => apiRequest(this.config, "GET", "/my-files", {
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
544
|
+
list: (query, signal, options) => apiRequest(this.config, "GET", "/my-files", {
|
|
545
|
+
query,
|
|
546
|
+
signal,
|
|
547
|
+
extraHeaders: this.withAsUser(options)
|
|
548
|
+
}),
|
|
549
|
+
trash: (query, signal, options) => apiRequest(this.config, "GET", "/my-files/trash", {
|
|
550
|
+
query,
|
|
551
|
+
signal,
|
|
552
|
+
extraHeaders: this.withAsUser(options)
|
|
553
|
+
}),
|
|
554
|
+
get: (id, signal, options) => apiRequest(this.config, "GET", `/my-files/${id}`, {
|
|
555
|
+
signal,
|
|
556
|
+
extraHeaders: this.withAsUser(options)
|
|
557
|
+
}),
|
|
558
|
+
downloadUrl: (id, signal, options) => apiRequest(this.config, "GET", `/my-files/${id}/download-url`, {
|
|
559
|
+
signal,
|
|
560
|
+
extraHeaders: this.withAsUser(options)
|
|
561
|
+
}),
|
|
562
|
+
move: (id, body, signal, options) => apiRequest(this.config, "PATCH", `/my-files/${id}/move`, {
|
|
563
|
+
body,
|
|
564
|
+
signal,
|
|
565
|
+
extraHeaders: this.withAsUser(options)
|
|
566
|
+
}),
|
|
567
|
+
delete: (id, query, signal, options) => apiRequest(this.config, "DELETE", `/my-files/${id}`, {
|
|
568
|
+
query,
|
|
569
|
+
signal,
|
|
570
|
+
extraHeaders: this.withAsUser(options)
|
|
571
|
+
}),
|
|
572
|
+
restore: (id, signal, options) => apiRequest(this.config, "POST", `/my-files/${id}/restore`, {
|
|
573
|
+
signal,
|
|
574
|
+
extraHeaders: this.withAsUser(options)
|
|
575
|
+
}),
|
|
576
|
+
update: (id, body, signal, options) => apiRequest(this.config, "PATCH", `/my-files/${id}`, {
|
|
577
|
+
body,
|
|
578
|
+
signal,
|
|
579
|
+
extraHeaders: this.withAsUser(options)
|
|
580
|
+
})
|
|
299
581
|
};
|
|
300
582
|
folders = {
|
|
301
|
-
list: (query) => apiRequest(this.config, "GET", "/folders", {
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
583
|
+
list: (query, signal, options) => apiRequest(this.config, "GET", "/folders", {
|
|
584
|
+
query,
|
|
585
|
+
signal,
|
|
586
|
+
extraHeaders: this.withAsUser(options)
|
|
587
|
+
}),
|
|
588
|
+
get: (id, signal, options) => apiRequest(this.config, "GET", `/folders/${id}`, {
|
|
589
|
+
signal,
|
|
590
|
+
extraHeaders: this.withAsUser(options)
|
|
591
|
+
}),
|
|
592
|
+
create: (body, signal, options) => apiRequest(this.config, "POST", "/folders", {
|
|
593
|
+
body,
|
|
594
|
+
signal,
|
|
595
|
+
extraHeaders: this.withAsUser(options)
|
|
596
|
+
}),
|
|
597
|
+
update: (id, body, signal, options) => apiRequest(this.config, "PATCH", `/folders/${id}`, {
|
|
598
|
+
body,
|
|
599
|
+
signal,
|
|
600
|
+
extraHeaders: this.withAsUser(options)
|
|
601
|
+
}),
|
|
602
|
+
delete: (id, query, signal, options) => apiRequest(this.config, "DELETE", `/folders/${id}`, {
|
|
603
|
+
query,
|
|
604
|
+
signal,
|
|
605
|
+
extraHeaders: this.withAsUser(options)
|
|
606
|
+
}),
|
|
607
|
+
restore: (id, signal, options) => apiRequest(this.config, "POST", `/folders/${id}/restore`, {
|
|
608
|
+
signal,
|
|
609
|
+
extraHeaders: this.withAsUser(options)
|
|
610
|
+
})
|
|
611
|
+
};
|
|
612
|
+
mainStorage = {
|
|
613
|
+
list: (query) => this.request("GET", "/main", { query }),
|
|
614
|
+
get: (fileId) => this.request("GET", `/main/${fileId}`),
|
|
615
|
+
rename: (fileId, filename) => this.request("PATCH", `/main/${fileId}`, { body: { filename } }),
|
|
616
|
+
delete: (fileId, permanent = false) => this.request("DELETE", `/main/${fileId}${permanent ? "?permanent=true" : ""}`),
|
|
617
|
+
restore: (fileId) => this.request("POST", `/main/${fileId}/restore`),
|
|
618
|
+
upload: {
|
|
619
|
+
r2Init: (input) => this.request("POST", "/upload/r2/init", { body: {
|
|
620
|
+
...input,
|
|
621
|
+
is_main_storage: true
|
|
622
|
+
} }),
|
|
623
|
+
appwriteInit: (input) => this.request("POST", "/upload/appwrite/init", { body: {
|
|
624
|
+
...input,
|
|
625
|
+
is_main_storage: true
|
|
626
|
+
} }),
|
|
627
|
+
complete: (uploadId) => this.request("POST", "/upload/complete", { body: {
|
|
628
|
+
upload_id: uploadId,
|
|
629
|
+
is_main_storage: true
|
|
630
|
+
} }),
|
|
631
|
+
fail: (uploadId) => this.request("POST", "/upload/fail", { body: { upload_id: uploadId } })
|
|
632
|
+
}
|
|
633
|
+
};
|
|
634
|
+
releases = {
|
|
635
|
+
upload: {
|
|
636
|
+
init: (body, signal) => apiRequest(this.config, "POST", "/releases/upload/init", {
|
|
637
|
+
body,
|
|
638
|
+
signal
|
|
639
|
+
}),
|
|
640
|
+
complete: (body, signal) => apiRequest(this.config, "POST", "/releases/upload/complete", {
|
|
641
|
+
body,
|
|
642
|
+
signal
|
|
643
|
+
}),
|
|
644
|
+
fail: (releaseId, signal) => apiRequest(this.config, "POST", "/releases/upload/fail", {
|
|
645
|
+
body: { release_id: releaseId },
|
|
646
|
+
signal
|
|
647
|
+
})
|
|
648
|
+
},
|
|
649
|
+
list: (query, signal) => apiRequest(this.config, "GET", "/releases", {
|
|
650
|
+
query,
|
|
651
|
+
signal
|
|
652
|
+
}),
|
|
653
|
+
get: (releaseId, signal) => apiRequest(this.config, "GET", `/releases/${releaseId}`, { signal }),
|
|
654
|
+
latest: (signal) => apiRequest(this.config, "GET", "/releases/latest", { signal }),
|
|
655
|
+
update: (releaseId, body, signal) => apiRequest(this.config, "PATCH", `/releases/${releaseId}`, {
|
|
656
|
+
body,
|
|
657
|
+
signal
|
|
658
|
+
}),
|
|
659
|
+
delete: (releaseId, signal) => apiRequest(this.config, "DELETE", `/releases/${releaseId}`, { signal }),
|
|
660
|
+
sync: (body, signal) => apiRequest(this.config, "POST", "/releases/sync", {
|
|
661
|
+
body,
|
|
662
|
+
signal
|
|
663
|
+
})
|
|
306
664
|
};
|
|
307
665
|
admin = {
|
|
308
|
-
serviceDetail: () => apiRequest(this.config, "GET", "/admin/service"),
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
666
|
+
serviceDetail: (signal) => apiRequest(this.config, "GET", "/admin/service", { signal }),
|
|
667
|
+
updateService: (body, signal) => apiRequest(this.config, "PATCH", "/admin/service", {
|
|
668
|
+
body,
|
|
669
|
+
signal
|
|
670
|
+
}),
|
|
671
|
+
usage: (signal) => apiRequest(this.config, "GET", "/admin/service/usage", { signal }),
|
|
672
|
+
listUploads: (query, signal) => apiRequest(this.config, "GET", "/files", {
|
|
673
|
+
query,
|
|
674
|
+
signal
|
|
675
|
+
}),
|
|
676
|
+
getUpload: (id, signal) => apiRequest(this.config, "GET", `/files/${id}`, { signal }),
|
|
677
|
+
downloadUploadUrl: (id, signal) => apiRequest(this.config, "GET", `/files/${id}/download-url`, { signal }),
|
|
678
|
+
deleteUpload: (id, signal) => apiRequest(this.config, "DELETE", `/files/${id}`, { signal }),
|
|
679
|
+
auditLog: (query, signal) => apiRequest(this.config, "GET", "/admin/audit-log", {
|
|
680
|
+
query,
|
|
681
|
+
signal
|
|
682
|
+
}),
|
|
683
|
+
listUsers: (query, signal) => apiRequest(this.config, "GET", "/admin/users", {
|
|
684
|
+
query,
|
|
685
|
+
signal
|
|
686
|
+
}),
|
|
687
|
+
updateUser: (userId, body, signal) => apiRequest(this.config, "PATCH", `/admin/users/${userId}`, {
|
|
688
|
+
body,
|
|
689
|
+
signal
|
|
690
|
+
}),
|
|
691
|
+
resetUserPassword: (userId, body, signal) => apiRequest(this.config, "POST", `/admin/users/${userId}/password`, {
|
|
692
|
+
body,
|
|
693
|
+
signal
|
|
694
|
+
})
|
|
695
|
+
};
|
|
696
|
+
shareLinks = {
|
|
697
|
+
create: (fileId, body, signal) => apiRequest(this.config, "POST", `/my-files/${fileId}/share-links`, {
|
|
698
|
+
body,
|
|
699
|
+
signal
|
|
700
|
+
}),
|
|
701
|
+
list: (fileId, signal) => apiRequest(this.config, "GET", `/my-files/${fileId}/share-links`, { signal }),
|
|
702
|
+
update: (linkId, body, signal) => apiRequest(this.config, "PATCH", `/share-links/${linkId}`, {
|
|
703
|
+
body,
|
|
704
|
+
signal
|
|
705
|
+
}),
|
|
706
|
+
delete: (linkId, signal) => apiRequest(this.config, "DELETE", `/share-links/${linkId}`, { signal })
|
|
312
707
|
};
|
|
313
708
|
};
|
|
314
709
|
//#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 };
|
|
710
|
+
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, mainStorageListQuerySchema, mainStorageListResponseSchema, mainStorageRenameRequestSchema, 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.0",
|
|
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"
|