@unisource/sdk 0.6.0 → 0.8.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 +56 -23
- package/dist/index.d.mts +170 -1
- package/dist/index.mjs +134 -5
- package/package.json +1 -1
- package/src/client.ts +77 -2
- package/src/fileRecords.ts +12 -3
- package/src/index.ts +34 -1
- package/src/primitives.ts +13 -0
- package/src/releases.ts +26 -0
- package/src/services.ts +3 -3
- package/src/v2.ts +69 -0
package/README.md
CHANGED
|
@@ -1,55 +1,88 @@
|
|
|
1
1
|
# @unisource/sdk
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Główne, współdzielone biblioteki oraz klient HTTP (SDK) wykorzystywane zarówno przez aplikację `frontend`, jak i `backend` (w ramach repozytorium UniSource).
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Zawartość pakietu
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
- `UnisourceClient` for authenticated app and admin API calls
|
|
9
|
-
- Standalone public share helpers: `getPublicFileInfo()` and `unlockPublicFile()`
|
|
10
|
-
- Typed error classes: `UnisourceError` and `UnisourceNetworkError`
|
|
7
|
+
SDK zapewnia pojedyncze źródło prawdy dla kontraktów API i upraszcza komunikację z backendem. Zawiera m.in.:
|
|
11
8
|
|
|
12
|
-
|
|
9
|
+
- **Zod Schemas & TypeScript Types**: Pełne definicje typów dla wszystkich encji w systemie: Pliki, Foldery, Udostępnienia (Share Links), Upload (w tym Multipart), Magazyn (Main Storage), Usługi (Services), Role Użytkowników oraz Audyty (Audit Logs).
|
|
10
|
+
- **UnisourceClient**: Silnie typowany klient HTTP służący do bezpiecznej komunikacji z API z uwzględnieniem identyfikacji usługi (`X-Service-ID`) oraz autoryzacji (JWT/API Key).
|
|
11
|
+
- **Publiczne Helpery**: Samodzielne metody do obsługi udostępnionych, publicznych linków (bez wymagania logowania) takie jak `getPublicFileInfo()` czy `unlockPublicFile()`.
|
|
12
|
+
- **Obsługa Błędów**: Precyzyjne klasy błędów `UnisourceError` oraz `UnisourceNetworkError`.
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
## Użycie (Usage)
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
pnpm install
|
|
18
|
-
pnpm --filter @unisource/sdk build
|
|
19
|
-
pnpm --filter @unisource/sdk test
|
|
20
|
-
pnpm --filter @unisource/sdk typecheck
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
## Usage
|
|
16
|
+
Przykład konfiguracji i pobrania listy plików przypisanych do użytkownika przy wykorzystaniu instancji klienta:
|
|
24
17
|
|
|
25
18
|
```ts
|
|
26
19
|
import { UnisourceClient } from '@unisource/sdk';
|
|
27
20
|
|
|
21
|
+
// 1. Konfiguracja klienta
|
|
28
22
|
const client = new UnisourceClient({
|
|
29
|
-
baseUrl: 'https://api.
|
|
23
|
+
baseUrl: 'https://api.usrc.dev',
|
|
30
24
|
serviceId: 'usrc',
|
|
31
|
-
getToken: async () => 'jwt-
|
|
25
|
+
getToken: async () => 'twoj-token-jwt-lub-api-key', // Zwróć null dla zapytań publicznych
|
|
32
26
|
});
|
|
33
27
|
|
|
28
|
+
// 2. Zapytanie API (np. lista plików z paginacją)
|
|
34
29
|
const files = await client.myFiles.list({ folder_id: null, limit: 25 });
|
|
35
30
|
```
|
|
36
31
|
|
|
37
|
-
|
|
32
|
+
### Obsługa udostępnień publicznych
|
|
33
|
+
Zapytania o zasoby publiczne nie wymagają pełnej inicjalizacji klienta i posiadają dedykowane, lekkie metody:
|
|
38
34
|
|
|
39
35
|
```ts
|
|
40
36
|
import { getPublicFileInfo, unlockPublicFile } from '@unisource/sdk';
|
|
41
37
|
|
|
42
|
-
|
|
43
|
-
const
|
|
38
|
+
// Pobranie metadanych udostępnionego pliku na podstawie slug'a
|
|
39
|
+
const info = await getPublicFileInfo('https://api.usrc.dev', 'moj-unikalny-slug');
|
|
40
|
+
|
|
41
|
+
// Odblokowanie dostępu do pliku chronionego hasłem
|
|
42
|
+
const unlocked = await unlockPublicFile('https://api.usrc.dev', 'moj-unikalny-slug', 'tajne-haslo123');
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Rozwój lokalny (Development)
|
|
46
|
+
|
|
47
|
+
W ramach monorepo (narzędzie pnpm):
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
# Instalacja wszystkich zależności (w roocie)
|
|
51
|
+
pnpm install
|
|
52
|
+
|
|
53
|
+
# Kompilacja SDK
|
|
54
|
+
pnpm --filter @unisource/sdk build
|
|
55
|
+
|
|
56
|
+
# Sprawdzanie typów
|
|
57
|
+
pnpm --filter @unisource/sdk typecheck
|
|
58
|
+
|
|
59
|
+
# Uruchomienie testów
|
|
60
|
+
pnpm --filter @unisource/sdk test
|
|
44
61
|
```
|
|
45
62
|
|
|
46
|
-
|
|
63
|
+
Pakiet może być linkowany lokalnie w ramach workspace, wystarczy w innym projekcie monorepo dodać zależność:
|
|
64
|
+
`"@unisource/sdk": "workspace:*"`
|
|
47
65
|
|
|
48
|
-
|
|
66
|
+
## Wydawanie nowej wersji (Release Workflow)
|
|
67
|
+
|
|
68
|
+
Pakiet `@unisource/sdk` jest pakietem publicznym na rejestrze NPM i korzysta z narzędzia [Changesets](https://github.com/changesets/changesets) do zarządzania wersjami.
|
|
69
|
+
|
|
70
|
+
Aby opublikować nową wersję, wykonaj poniższe kroki z głównego katalogu (root) monorepo:
|
|
49
71
|
|
|
50
72
|
```bash
|
|
73
|
+
# 1. Dodaj plik z opisem zmian (wybierz paczkę, typ bumpa i napisz komentarz)
|
|
51
74
|
pnpm changeset
|
|
75
|
+
|
|
76
|
+
# 2. Zatwierdź nową wersję na podstawie plików changeset (aktualizacja package.json oraz CHANGELOG.md)
|
|
52
77
|
pnpm changeset version
|
|
78
|
+
|
|
79
|
+
# 3. Zbuduj SDK by upewnić się, że kod wynikowy jest poprawny
|
|
53
80
|
pnpm --filter @unisource/sdk build
|
|
81
|
+
|
|
82
|
+
# 4. Sprawdź przed publikacją
|
|
83
|
+
pnpm --filter @unisource/sdk publish --dry-run --access public --no-git-checks
|
|
84
|
+
|
|
85
|
+
# 5. Opublikuj na rejestr NPM
|
|
54
86
|
pnpm changeset publish
|
|
55
87
|
```
|
|
88
|
+
Pamiętaj o dodaniu nowo powstałych tagów i commitów do głównego repozytorium po opublikowaniu paczki.
|
package/dist/index.d.mts
CHANGED
|
@@ -3,14 +3,30 @@ import { z } from "zod";
|
|
|
3
3
|
//#region src/primitives.d.ts
|
|
4
4
|
declare const nonEmptyString: z.ZodString;
|
|
5
5
|
declare const positiveInt: z.ZodNumber;
|
|
6
|
+
declare const nonNegativeInt: z.ZodNumber;
|
|
6
7
|
declare const unixTimestamp: z.ZodNumber;
|
|
7
8
|
declare const FILES_DEFAULT_LIMIT = 25;
|
|
8
9
|
declare const FILES_MAX_LIMIT = 100;
|
|
10
|
+
/**
|
|
11
|
+
* Storage backend a file lives on.
|
|
12
|
+
* - 'r2' — Cloudflare R2 via presigned PUT / multipart
|
|
13
|
+
* - 'appwrite' — Appwrite Storage via direct browser SDK upload
|
|
14
|
+
*
|
|
15
|
+
* `recommendedUploadDestinationSchema` adds the meta-value 'hybrid' which is
|
|
16
|
+
* only valid as a service-wide setting (the upload manager picks r2/appwrite
|
|
17
|
+
* per-file based on size).
|
|
18
|
+
*/
|
|
9
19
|
declare const uploadDestinationSchema: z.ZodEnum<{
|
|
10
20
|
appwrite: "appwrite";
|
|
11
21
|
r2: "r2";
|
|
12
22
|
}>;
|
|
13
23
|
type UploadDestination = z.infer<typeof uploadDestinationSchema>;
|
|
24
|
+
declare const recommendedUploadDestinationSchema: z.ZodEnum<{
|
|
25
|
+
appwrite: "appwrite";
|
|
26
|
+
hybrid: "hybrid";
|
|
27
|
+
r2: "r2";
|
|
28
|
+
}>;
|
|
29
|
+
type RecommendedUploadDestination = z.infer<typeof recommendedUploadDestinationSchema>;
|
|
14
30
|
declare const uploadStatusSchema: z.ZodEnum<{
|
|
15
31
|
completed: "completed";
|
|
16
32
|
failed: "failed";
|
|
@@ -333,6 +349,7 @@ declare const fileRestoreResponseSchema: z.ZodObject<{
|
|
|
333
349
|
id: z.ZodString;
|
|
334
350
|
}, z.core.$strip>;
|
|
335
351
|
type FileRestoreResponse = z.infer<typeof fileRestoreResponseSchema>;
|
|
352
|
+
/** SDK4: filename hard-capped to 255 to match backend Zod validation. */
|
|
336
353
|
declare const fileUpdateRequestSchema: z.ZodObject<{
|
|
337
354
|
filename: z.ZodString;
|
|
338
355
|
}, z.core.$strip>;
|
|
@@ -477,6 +494,7 @@ declare const serviceSchema: z.ZodObject<{
|
|
|
477
494
|
max_file_size_bytes: z.ZodNumber;
|
|
478
495
|
recommended_upload_destination: z.ZodOptional<z.ZodEnum<{
|
|
479
496
|
appwrite: "appwrite";
|
|
497
|
+
hybrid: "hybrid";
|
|
480
498
|
r2: "r2";
|
|
481
499
|
}>>;
|
|
482
500
|
created_at: z.ZodNumber;
|
|
@@ -491,6 +509,7 @@ declare const serviceDetailResponseSchema: z.ZodObject<{
|
|
|
491
509
|
max_file_size_bytes: z.ZodNumber;
|
|
492
510
|
recommended_upload_destination: z.ZodOptional<z.ZodEnum<{
|
|
493
511
|
appwrite: "appwrite";
|
|
512
|
+
hybrid: "hybrid";
|
|
494
513
|
r2: "r2";
|
|
495
514
|
}>>;
|
|
496
515
|
created_at: z.ZodNumber;
|
|
@@ -511,6 +530,7 @@ declare const adminServiceUpdateResponseSchema: z.ZodObject<{
|
|
|
511
530
|
max_file_size_bytes: z.ZodNumber;
|
|
512
531
|
recommended_upload_destination: z.ZodOptional<z.ZodEnum<{
|
|
513
532
|
appwrite: "appwrite";
|
|
533
|
+
hybrid: "hybrid";
|
|
514
534
|
r2: "r2";
|
|
515
535
|
}>>;
|
|
516
536
|
created_at: z.ZodNumber;
|
|
@@ -525,6 +545,7 @@ type AdminServiceUpdateResponse = z.infer<typeof adminServiceUpdateResponseSchem
|
|
|
525
545
|
declare const adminServiceSettingsRequestSchema: z.ZodObject<{
|
|
526
546
|
recommended_upload_destination: z.ZodOptional<z.ZodEnum<{
|
|
527
547
|
appwrite: "appwrite";
|
|
548
|
+
hybrid: "hybrid";
|
|
528
549
|
r2: "r2";
|
|
529
550
|
}>>;
|
|
530
551
|
}, z.core.$strip>;
|
|
@@ -538,6 +559,7 @@ declare const adminServiceSettingsResponseSchema: z.ZodObject<{
|
|
|
538
559
|
max_file_size_bytes: z.ZodNumber;
|
|
539
560
|
recommended_upload_destination: z.ZodOptional<z.ZodEnum<{
|
|
540
561
|
appwrite: "appwrite";
|
|
562
|
+
hybrid: "hybrid";
|
|
541
563
|
r2: "r2";
|
|
542
564
|
}>>;
|
|
543
565
|
created_at: z.ZodNumber;
|
|
@@ -1025,6 +1047,28 @@ declare const releaseSyncResponseSchema: z.ZodObject<{
|
|
|
1025
1047
|
}, z.core.$strip>>;
|
|
1026
1048
|
}, z.core.$strip>;
|
|
1027
1049
|
type ReleaseSyncResponse = z.infer<typeof releaseSyncResponseSchema>;
|
|
1050
|
+
/**
|
|
1051
|
+
* Response of `GET /app/releases/latest?channel=...` — used by client apps to
|
|
1052
|
+
* discover the most recent completed release for a given distribution channel
|
|
1053
|
+
* (e.g. `stable`, `beta`). Includes a short-lived presigned download URL.
|
|
1054
|
+
*/
|
|
1055
|
+
declare const appReleaseLatestQuerySchema: z.ZodObject<{
|
|
1056
|
+
channel: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
1057
|
+
}, z.core.$strip>;
|
|
1058
|
+
type AppReleaseLatestQuery = z.input<typeof appReleaseLatestQuerySchema>;
|
|
1059
|
+
declare const appReleaseLatestResponseSchema: z.ZodObject<{
|
|
1060
|
+
id: z.ZodString;
|
|
1061
|
+
name: z.ZodString;
|
|
1062
|
+
size: z.ZodNumber;
|
|
1063
|
+
r2_key: z.ZodString;
|
|
1064
|
+
tags: z.ZodArray<z.ZodString>;
|
|
1065
|
+
notes: z.ZodNullable<z.ZodString>;
|
|
1066
|
+
force_update: z.ZodBoolean;
|
|
1067
|
+
created_at: z.ZodString;
|
|
1068
|
+
download_url: z.ZodString;
|
|
1069
|
+
download_url_expires_at: z.ZodNumber;
|
|
1070
|
+
}, z.core.$strip>;
|
|
1071
|
+
type AppReleaseLatestResponse = z.infer<typeof appReleaseLatestResponseSchema>;
|
|
1028
1072
|
//#endregion
|
|
1029
1073
|
//#region src/shareLinks.d.ts
|
|
1030
1074
|
declare const shareLinkSchema: z.ZodObject<{
|
|
@@ -1165,6 +1209,87 @@ declare const sharesCreateRequestSchema: z.ZodObject<{
|
|
|
1165
1209
|
}, z.core.$strip>;
|
|
1166
1210
|
type SharesCreateRequest = z.infer<typeof sharesCreateRequestSchema>;
|
|
1167
1211
|
//#endregion
|
|
1212
|
+
//#region src/v2.d.ts
|
|
1213
|
+
declare const fileRecordsListV2QuerySchema: z.ZodObject<{
|
|
1214
|
+
folder_id: z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodString>>, z.ZodTransform<string | null | undefined, string | null | undefined>>;
|
|
1215
|
+
is_trashed: z.ZodOptional<z.ZodPipe<z.ZodEnum<{
|
|
1216
|
+
false: "false";
|
|
1217
|
+
true: "true";
|
|
1218
|
+
}>, z.ZodTransform<boolean, "false" | "true">>>;
|
|
1219
|
+
search: z.ZodOptional<z.ZodString>;
|
|
1220
|
+
mime_type: z.ZodOptional<z.ZodString>;
|
|
1221
|
+
sort_by: z.ZodOptional<z.ZodEnum<{
|
|
1222
|
+
created_at: "created_at";
|
|
1223
|
+
name: "name";
|
|
1224
|
+
size: "size";
|
|
1225
|
+
}>>;
|
|
1226
|
+
sort_dir: z.ZodOptional<z.ZodEnum<{
|
|
1227
|
+
asc: "asc";
|
|
1228
|
+
desc: "desc";
|
|
1229
|
+
}>>;
|
|
1230
|
+
cursor: z.ZodOptional<z.ZodString>;
|
|
1231
|
+
limit: z.ZodOptional<z.ZodCoercedNumber<unknown>>;
|
|
1232
|
+
}, z.core.$strip>;
|
|
1233
|
+
type FileRecordsListV2Query = z.infer<typeof fileRecordsListV2QuerySchema>;
|
|
1234
|
+
declare const bulkFileIdsSchema: z.ZodObject<{
|
|
1235
|
+
ids: z.ZodArray<z.ZodString>;
|
|
1236
|
+
}, z.core.$strip>;
|
|
1237
|
+
type BulkFileIds = z.infer<typeof bulkFileIdsSchema>;
|
|
1238
|
+
declare const bulkFileMoveRequestSchema: z.ZodObject<{
|
|
1239
|
+
ids: z.ZodArray<z.ZodString>;
|
|
1240
|
+
folder_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
1241
|
+
}, z.core.$strip>;
|
|
1242
|
+
type BulkFileMoveRequest = z.infer<typeof bulkFileMoveRequestSchema>;
|
|
1243
|
+
declare const bulkOperationResponseSchema: z.ZodObject<{
|
|
1244
|
+
success: z.ZodBoolean;
|
|
1245
|
+
processed_count: z.ZodNumber;
|
|
1246
|
+
failed_ids: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
1247
|
+
}, z.core.$strip>;
|
|
1248
|
+
type BulkOperationResponse = z.infer<typeof bulkOperationResponseSchema>;
|
|
1249
|
+
declare const folderListV2QuerySchema: z.ZodObject<{
|
|
1250
|
+
parent_id: z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodString>>, z.ZodTransform<string | null | undefined, string | null | undefined>>;
|
|
1251
|
+
is_trashed: z.ZodOptional<z.ZodPipe<z.ZodEnum<{
|
|
1252
|
+
false: "false";
|
|
1253
|
+
true: "true";
|
|
1254
|
+
}>, z.ZodTransform<boolean, "false" | "true">>>;
|
|
1255
|
+
search: z.ZodOptional<z.ZodString>;
|
|
1256
|
+
sort_by: z.ZodOptional<z.ZodEnum<{
|
|
1257
|
+
created_at: "created_at";
|
|
1258
|
+
name: "name";
|
|
1259
|
+
}>>;
|
|
1260
|
+
sort_dir: z.ZodOptional<z.ZodEnum<{
|
|
1261
|
+
asc: "asc";
|
|
1262
|
+
desc: "desc";
|
|
1263
|
+
}>>;
|
|
1264
|
+
cursor: z.ZodOptional<z.ZodString>;
|
|
1265
|
+
limit: z.ZodOptional<z.ZodCoercedNumber<unknown>>;
|
|
1266
|
+
}, z.core.$strip>;
|
|
1267
|
+
type FolderListV2Query = z.infer<typeof folderListV2QuerySchema>;
|
|
1268
|
+
declare const bulkFolderIdsSchema: z.ZodObject<{
|
|
1269
|
+
ids: z.ZodArray<z.ZodString>;
|
|
1270
|
+
}, z.core.$strip>;
|
|
1271
|
+
type BulkFolderIds = z.infer<typeof bulkFolderIdsSchema>;
|
|
1272
|
+
declare const bulkFolderMoveRequestSchema: z.ZodObject<{
|
|
1273
|
+
ids: z.ZodArray<z.ZodString>;
|
|
1274
|
+
parent_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
1275
|
+
}, z.core.$strip>;
|
|
1276
|
+
type BulkFolderMoveRequest = z.infer<typeof bulkFolderMoveRequestSchema>;
|
|
1277
|
+
declare const folderBreadcrumbsResponseSchema: z.ZodObject<{
|
|
1278
|
+
breadcrumbs: z.ZodArray<z.ZodObject<{
|
|
1279
|
+
id: z.ZodString;
|
|
1280
|
+
service_id: z.ZodString;
|
|
1281
|
+
user_id: z.ZodString;
|
|
1282
|
+
parent_id: z.ZodNullable<z.ZodString>;
|
|
1283
|
+
name: z.ZodString;
|
|
1284
|
+
color_tag: z.ZodNullable<z.ZodString>;
|
|
1285
|
+
is_trashed: z.ZodBoolean;
|
|
1286
|
+
trashed_at: z.ZodNullable<z.ZodNumber>;
|
|
1287
|
+
created_at: z.ZodNumber;
|
|
1288
|
+
updated_at: z.ZodNumber;
|
|
1289
|
+
}, z.core.$strip>>;
|
|
1290
|
+
}, z.core.$strip>;
|
|
1291
|
+
type FolderBreadcrumbsResponse = z.infer<typeof folderBreadcrumbsResponseSchema>;
|
|
1292
|
+
//#endregion
|
|
1168
1293
|
//#region src/client.d.ts
|
|
1169
1294
|
declare class UnisourceError extends Error {
|
|
1170
1295
|
readonly status: number;
|
|
@@ -1300,6 +1425,7 @@ declare class UnisourceClient {
|
|
|
1300
1425
|
updateServiceSettings: (body: AdminServiceSettingsRequest, signal?: AbortSignal) => Promise<AdminServiceSettingsResponse>; /** Get real-time storage usage for the service */
|
|
1301
1426
|
usage: (signal?: AbortSignal) => Promise<ServiceUsageResponse>; /** List all uploads (pending/completed/failed) for this service */
|
|
1302
1427
|
listUploads: (query?: {
|
|
1428
|
+
destination?: UploadDestination;
|
|
1303
1429
|
status?: UploadStatus;
|
|
1304
1430
|
cursor?: string;
|
|
1305
1431
|
limit?: number;
|
|
@@ -1349,6 +1475,49 @@ declare class UnisourceClient {
|
|
|
1349
1475
|
get: (id: string, signal?: AbortSignal) => Promise<ShareLinkDetailResponse>; /** Delete a share link */
|
|
1350
1476
|
delete: (id: string, signal?: AbortSignal) => Promise<ShareLinkDeleteResponse>;
|
|
1351
1477
|
};
|
|
1478
|
+
readonly v2: {
|
|
1479
|
+
files: {
|
|
1480
|
+
/** List files with advanced search, sorting, and filtering capabilities */list: (query?: FileRecordsListV2Query, signal?: AbortSignal, options?: {
|
|
1481
|
+
asUser?: string;
|
|
1482
|
+
}) => Promise<FileRecordsListResponse>; /** Move multiple files at once */
|
|
1483
|
+
bulkMove: (body: BulkFileMoveRequest, signal?: AbortSignal, options?: {
|
|
1484
|
+
asUser?: string;
|
|
1485
|
+
}) => Promise<BulkOperationResponse>; /** Move multiple files to trash */
|
|
1486
|
+
bulkTrash: (body: BulkFileIds, signal?: AbortSignal, options?: {
|
|
1487
|
+
asUser?: string;
|
|
1488
|
+
}) => Promise<BulkOperationResponse>; /** Restore multiple files from trash */
|
|
1489
|
+
bulkRestore: (body: BulkFileIds, signal?: AbortSignal, options?: {
|
|
1490
|
+
asUser?: string;
|
|
1491
|
+
}) => Promise<BulkOperationResponse>;
|
|
1492
|
+
};
|
|
1493
|
+
folders: {
|
|
1494
|
+
/** List folders with advanced search, sorting, and filtering capabilities */list: (query?: FolderListV2Query, signal?: AbortSignal, options?: {
|
|
1495
|
+
asUser?: string;
|
|
1496
|
+
}) => Promise<FolderListResponse>; /** Get the breadcrumb hierarchy for a specific folder */
|
|
1497
|
+
breadcrumbs: (id: string, signal?: AbortSignal, options?: {
|
|
1498
|
+
asUser?: string;
|
|
1499
|
+
}) => Promise<FolderBreadcrumbsResponse>; /** Move multiple folders at once */
|
|
1500
|
+
bulkMove: (body: BulkFolderMoveRequest, signal?: AbortSignal, options?: {
|
|
1501
|
+
asUser?: string;
|
|
1502
|
+
}) => Promise<BulkOperationResponse>; /** Move multiple folders to trash */
|
|
1503
|
+
bulkTrash: (body: BulkFolderIds, signal?: AbortSignal, options?: {
|
|
1504
|
+
asUser?: string;
|
|
1505
|
+
}) => Promise<BulkOperationResponse>; /** Restore multiple folders from trash */
|
|
1506
|
+
bulkRestore: (body: BulkFolderIds, signal?: AbortSignal, options?: {
|
|
1507
|
+
asUser?: string;
|
|
1508
|
+
}) => Promise<BulkOperationResponse>;
|
|
1509
|
+
};
|
|
1510
|
+
};
|
|
1511
|
+
readonly app: {
|
|
1512
|
+
releases: {
|
|
1513
|
+
/**
|
|
1514
|
+
* Get the latest completed release for a channel (e.g. `stable`, `beta`).
|
|
1515
|
+
* Backed by `GET /app/releases/latest`. Returns the release metadata plus
|
|
1516
|
+
* a short-lived presigned download URL.
|
|
1517
|
+
*/
|
|
1518
|
+
latest: (channel?: string, signal?: AbortSignal) => Promise<AppReleaseLatestResponse>;
|
|
1519
|
+
};
|
|
1520
|
+
};
|
|
1352
1521
|
}
|
|
1353
1522
|
//#endregion
|
|
1354
|
-
export { type AdminServiceSettingsRequest, type AdminServiceSettingsResponse, type AdminServiceUpdateRequest, type AdminServiceUpdateResponse, type AdminUser, type AdminUserListResponse, type AdminUserPasswordResetRequest, type AdminUserPasswordResetResponse, type AdminUserRoleUpdateRequest, type AdminUserStorageLimitUpdateRequest, type AdminUserUpdateRequest, type AdminUserUpdateResponse, type ApiError, type AuditEvent, type AuditEventAction, type AuditLogListQuery, type AuditLogListResponse, FILES_DEFAULT_LIMIT, FILES_MAX_LIMIT, type FileDeleteResponse, type FileDownloadUrlResponse, type FileMoveRequest, type FileRecord, type FileRecordDetailResponse, type FileRecordsListQuery, type FileRecordsListResponse, type FileRestoreResponse, type FileUpdateRequest, type FileUpdateResponse, type Folder, type FolderCreateRequest, type FolderCreateResponse, type FolderDeleteResponse, type FolderDetailResponse, type FolderListQuery, type FolderListResponse, type FolderRestoreResponse, type FolderUpdateRequest, type FolderUpdateResponse, MainStorageDeleteResponse, MainStorageDetailResponse, MainStorageFile, MainStorageListQuery, MainStorageListResponse, MainStorageRenameRequest, MainStorageRenameResponse, MainStorageRestoreResponse, type MultipartAbortRequest, type MultipartAbortResponse, type MultipartCompleteRequest, type MultipartCompleteResponse, type MultipartCreateRequest, type MultipartCreateResponse, type MultipartListPartsQuery, type MultipartListPartsResponse, type MultipartPart, type MultipartSignPartQuery, type MultipartSignPartResponse, type PublicFileAccessResponse, type PublicFileLockedResponse, type ReleaseDTO, type ReleaseDeleteResponse, type ReleaseMultipartAbortRequest, type ReleaseMultipartAbortResponse, type ReleaseMultipartCompleteRequest, type ReleaseMultipartCompleteResponse, type ReleaseMultipartCreateRequest, type ReleaseMultipartCreateResponse, type ReleaseMultipartListPartsQuery, type ReleaseMultipartListPartsResponse, type ReleaseMultipartPart, type ReleaseMultipartSignPartQuery, type ReleaseMultipartSignPartResponse, type ReleaseSyncManifest, type ReleaseSyncRequest, type ReleaseSyncResponse, type ReleaseSyncResult, type ReleaseUpdateRequest, type ReleaseUploadCompleteRequest, type ReleaseUploadCompleteResponse, type ReleaseUploadFailResponse, type ReleaseUploadInitRequest, type ReleaseUploadInitResponse, type ReleasesListQuery, type ReleasesListResponse, type Service, type ServiceDetailResponse, type ServiceUsageResponse, type ShareLink, type ShareLinkCreateRequest, type ShareLinkCreateResponse, type ShareLinkDeleteResponse, type ShareLinkDetailResponse, type ShareLinkListResponse, type ShareLinkUpdateRequest, type ShareLinkUpdateResponse, type SharesCreateRequest, UnisourceClient, type UnisourceClientConfig, UnisourceError, UnisourceNetworkError, type UploadAppwriteInitRequest, type UploadAppwriteInitResponse, type UploadCompleteResponse, type UploadDestination, type UploadFailResponse, type UploadLifecycleRequest, type UploadR2InitRequest, type UploadR2InitResponse, type UploadRecord, type UploadRecordDetailResponse, type UploadStatus, type UploadType, type UploadsListResponse, adminServiceSettingsRequestSchema, adminServiceSettingsResponseSchema, adminServiceUpdateRequestSchema, adminServiceUpdateResponseSchema, adminUserListResponseSchema, adminUserPasswordResetRequestSchema, adminUserPasswordResetResponseSchema, adminUserRoleUpdateRequestSchema, adminUserSchema, adminUserStorageLimitUpdateRequestSchema, 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, multipartAbortRequestSchema, multipartAbortResponseSchema, multipartCompleteRequestSchema, multipartCompleteResponseSchema, multipartCreateRequestSchema, multipartCreateResponseSchema, multipartListPartsQuerySchema, multipartListPartsResponseSchema, multipartPartSchema, multipartSignPartQuerySchema, multipartSignPartResponseSchema, nonEmptyString, positiveInt, publicFileAccessResponseSchema, publicFileLockedResponseSchema, releaseDTOSchema, releaseDeleteResponseSchema, releaseMultipartAbortRequestSchema, releaseMultipartAbortResponseSchema, releaseMultipartCompleteRequestSchema, releaseMultipartCompleteResponseSchema, releaseMultipartCreateRequestSchema, releaseMultipartCreateResponseSchema, releaseMultipartListPartsQuerySchema, releaseMultipartListPartsResponseSchema, releaseMultipartPartSchema, releaseMultipartSignPartQuerySchema, releaseMultipartSignPartResponseSchema, releaseSyncManifestSchema, releaseSyncRequestSchema, releaseSyncResponseSchema, releaseSyncResultSchema, releaseUpdateRequestSchema, releaseUploadCompleteRequestSchema, releaseUploadCompleteResponseSchema, releaseUploadFailResponseSchema, releaseUploadInitRequestSchema, releaseUploadInitResponseSchema, releasesListQuerySchema, releasesListResponseSchema, serviceDetailResponseSchema, serviceSchema, serviceUsageResponseSchema, shareLinkCreateRequestSchema, shareLinkCreateResponseSchema, shareLinkDeleteResponseSchema, shareLinkDetailResponseSchema, shareLinkListResponseSchema, shareLinkSchema, shareLinkUpdateRequestSchema, shareLinkUpdateResponseSchema, sharesCreateRequestSchema, unixTimestamp, unlockPublicFile, uploadAppwriteInitRequestSchema, uploadAppwriteInitResponseSchema, uploadCompleteResponseSchema, uploadDestinationSchema, uploadFailResponseSchema, uploadLifecycleRequestSchema, uploadR2InitRequestSchema, uploadR2InitResponseSchema, uploadRecordDetailResponseSchema, uploadRecordSchema, uploadStatusSchema, uploadTypeSchema, uploadsListResponseSchema };
|
|
1523
|
+
export { type AdminServiceSettingsRequest, type AdminServiceSettingsResponse, type AdminServiceUpdateRequest, type AdminServiceUpdateResponse, type AdminUser, type AdminUserListResponse, type AdminUserPasswordResetRequest, type AdminUserPasswordResetResponse, type AdminUserRoleUpdateRequest, type AdminUserStorageLimitUpdateRequest, type AdminUserUpdateRequest, type AdminUserUpdateResponse, type ApiError, type AppReleaseLatestQuery, type AppReleaseLatestResponse, type AuditEvent, type AuditEventAction, type AuditLogListQuery, type AuditLogListResponse, type BulkFileIds, type BulkFileMoveRequest, type BulkFolderIds, type BulkFolderMoveRequest, type BulkOperationResponse, FILES_DEFAULT_LIMIT, FILES_MAX_LIMIT, type FileDeleteResponse, type FileDownloadUrlResponse, type FileMoveRequest, type FileRecord, type FileRecordDetailResponse, type FileRecordsListQuery, type FileRecordsListResponse, type FileRecordsListV2Query, type FileRestoreResponse, type FileUpdateRequest, type FileUpdateResponse, type Folder, type FolderBreadcrumbsResponse, type FolderCreateRequest, type FolderCreateResponse, type FolderDeleteResponse, type FolderDetailResponse, type FolderListQuery, type FolderListResponse, type FolderListV2Query, type FolderRestoreResponse, type FolderUpdateRequest, type FolderUpdateResponse, MainStorageDeleteResponse, MainStorageDetailResponse, MainStorageFile, MainStorageListQuery, MainStorageListResponse, MainStorageRenameRequest, MainStorageRenameResponse, MainStorageRestoreResponse, type MultipartAbortRequest, type MultipartAbortResponse, type MultipartCompleteRequest, type MultipartCompleteResponse, type MultipartCreateRequest, type MultipartCreateResponse, type MultipartListPartsQuery, type MultipartListPartsResponse, type MultipartPart, type MultipartSignPartQuery, type MultipartSignPartResponse, type PublicFileAccessResponse, type PublicFileLockedResponse, type RecommendedUploadDestination, type ReleaseDTO, type ReleaseDeleteResponse, type ReleaseMultipartAbortRequest, type ReleaseMultipartAbortResponse, type ReleaseMultipartCompleteRequest, type ReleaseMultipartCompleteResponse, type ReleaseMultipartCreateRequest, type ReleaseMultipartCreateResponse, type ReleaseMultipartListPartsQuery, type ReleaseMultipartListPartsResponse, type ReleaseMultipartPart, type ReleaseMultipartSignPartQuery, type ReleaseMultipartSignPartResponse, type ReleaseSyncManifest, type ReleaseSyncRequest, type ReleaseSyncResponse, type ReleaseSyncResult, type ReleaseUpdateRequest, type ReleaseUploadCompleteRequest, type ReleaseUploadCompleteResponse, type ReleaseUploadFailResponse, type ReleaseUploadInitRequest, type ReleaseUploadInitResponse, type ReleasesListQuery, type ReleasesListResponse, type Service, type ServiceDetailResponse, type ServiceUsageResponse, type ShareLink, type ShareLinkCreateRequest, type ShareLinkCreateResponse, type ShareLinkDeleteResponse, type ShareLinkDetailResponse, type ShareLinkListResponse, type ShareLinkUpdateRequest, type ShareLinkUpdateResponse, type SharesCreateRequest, UnisourceClient, type UnisourceClientConfig, UnisourceError, UnisourceNetworkError, type UploadAppwriteInitRequest, type UploadAppwriteInitResponse, type UploadCompleteResponse, type UploadDestination, type UploadFailResponse, type UploadLifecycleRequest, type UploadR2InitRequest, type UploadR2InitResponse, type UploadRecord, type UploadRecordDetailResponse, type UploadStatus, type UploadType, type UploadsListResponse, adminServiceSettingsRequestSchema, adminServiceSettingsResponseSchema, adminServiceUpdateRequestSchema, adminServiceUpdateResponseSchema, adminUserListResponseSchema, adminUserPasswordResetRequestSchema, adminUserPasswordResetResponseSchema, adminUserRoleUpdateRequestSchema, adminUserSchema, adminUserStorageLimitUpdateRequestSchema, adminUserUpdateRequestSchema, adminUserUpdateResponseSchema, apiErrorSchema, appReleaseLatestQuerySchema, appReleaseLatestResponseSchema, auditEventActionSchema, auditEventSchema, auditLogListQuerySchema, auditLogListResponseSchema, bulkFileIdsSchema, bulkFileMoveRequestSchema, bulkFolderIdsSchema, bulkFolderMoveRequestSchema, bulkOperationResponseSchema, fileDeleteResponseSchema, fileDownloadUrlResponseSchema, fileMoveRequestSchema, fileRecordDetailResponseSchema, fileRecordSchema, fileRecordsListQuerySchema, fileRecordsListResponseSchema, fileRecordsListV2QuerySchema, fileRestoreResponseSchema, fileUpdateRequestSchema, fileUpdateResponseSchema, folderBreadcrumbsResponseSchema, folderCreateRequestSchema, folderCreateResponseSchema, folderDeleteResponseSchema, folderDetailResponseSchema, folderListQuerySchema, folderListResponseSchema, folderListV2QuerySchema, folderRestoreResponseSchema, folderSchema, folderUpdateRequestSchema, folderUpdateResponseSchema, getPublicFileInfo, mainStorageDeleteResponseSchema, mainStorageDetailResponseSchema, mainStorageFileSchema, mainStorageListQuerySchema, mainStorageListResponseSchema, mainStorageRenameRequestSchema, mainStorageRenameResponseSchema, mainStorageRestoreResponseSchema, multipartAbortRequestSchema, multipartAbortResponseSchema, multipartCompleteRequestSchema, multipartCompleteResponseSchema, multipartCreateRequestSchema, multipartCreateResponseSchema, multipartListPartsQuerySchema, multipartListPartsResponseSchema, multipartPartSchema, multipartSignPartQuerySchema, multipartSignPartResponseSchema, nonEmptyString, nonNegativeInt, positiveInt, publicFileAccessResponseSchema, publicFileLockedResponseSchema, recommendedUploadDestinationSchema, releaseDTOSchema, releaseDeleteResponseSchema, releaseMultipartAbortRequestSchema, releaseMultipartAbortResponseSchema, releaseMultipartCompleteRequestSchema, releaseMultipartCompleteResponseSchema, releaseMultipartCreateRequestSchema, releaseMultipartCreateResponseSchema, releaseMultipartListPartsQuerySchema, releaseMultipartListPartsResponseSchema, releaseMultipartPartSchema, releaseMultipartSignPartQuerySchema, releaseMultipartSignPartResponseSchema, releaseSyncManifestSchema, releaseSyncRequestSchema, releaseSyncResponseSchema, releaseSyncResultSchema, releaseUpdateRequestSchema, releaseUploadCompleteRequestSchema, releaseUploadCompleteResponseSchema, releaseUploadFailResponseSchema, releaseUploadInitRequestSchema, releaseUploadInitResponseSchema, releasesListQuerySchema, releasesListResponseSchema, serviceDetailResponseSchema, serviceSchema, serviceUsageResponseSchema, shareLinkCreateRequestSchema, shareLinkCreateResponseSchema, shareLinkDeleteResponseSchema, shareLinkDetailResponseSchema, shareLinkListResponseSchema, shareLinkSchema, shareLinkUpdateRequestSchema, shareLinkUpdateResponseSchema, sharesCreateRequestSchema, unixTimestamp, unlockPublicFile, uploadAppwriteInitRequestSchema, uploadAppwriteInitResponseSchema, uploadCompleteResponseSchema, uploadDestinationSchema, uploadFailResponseSchema, uploadLifecycleRequestSchema, uploadR2InitRequestSchema, uploadR2InitResponseSchema, uploadRecordDetailResponseSchema, uploadRecordSchema, uploadStatusSchema, uploadTypeSchema, uploadsListResponseSchema };
|
package/dist/index.mjs
CHANGED
|
@@ -2,10 +2,25 @@ import { z } from "zod";
|
|
|
2
2
|
//#region src/primitives.ts
|
|
3
3
|
const nonEmptyString = z.string().trim().min(1);
|
|
4
4
|
const positiveInt = z.number().int().positive();
|
|
5
|
+
const nonNegativeInt = z.number().int().nonnegative();
|
|
5
6
|
const unixTimestamp = z.number().int().nonnegative();
|
|
6
7
|
const FILES_DEFAULT_LIMIT = 25;
|
|
7
8
|
const FILES_MAX_LIMIT = 100;
|
|
9
|
+
/**
|
|
10
|
+
* Storage backend a file lives on.
|
|
11
|
+
* - 'r2' — Cloudflare R2 via presigned PUT / multipart
|
|
12
|
+
* - 'appwrite' — Appwrite Storage via direct browser SDK upload
|
|
13
|
+
*
|
|
14
|
+
* `recommendedUploadDestinationSchema` adds the meta-value 'hybrid' which is
|
|
15
|
+
* only valid as a service-wide setting (the upload manager picks r2/appwrite
|
|
16
|
+
* per-file based on size).
|
|
17
|
+
*/
|
|
8
18
|
const uploadDestinationSchema = z.enum(["r2", "appwrite"]);
|
|
19
|
+
const recommendedUploadDestinationSchema = z.enum([
|
|
20
|
+
"r2",
|
|
21
|
+
"appwrite",
|
|
22
|
+
"hybrid"
|
|
23
|
+
]);
|
|
9
24
|
const uploadStatusSchema = z.enum([
|
|
10
25
|
"pending",
|
|
11
26
|
"completed",
|
|
@@ -137,7 +152,7 @@ const fileRecordSchema = z.object({
|
|
|
137
152
|
folder_id: nonEmptyString.nullable(),
|
|
138
153
|
upload_id: nonEmptyString.nullable(),
|
|
139
154
|
filename: nonEmptyString,
|
|
140
|
-
size:
|
|
155
|
+
size: nonNegativeInt,
|
|
141
156
|
mime_type: nonEmptyString,
|
|
142
157
|
storage_destination: uploadDestinationSchema,
|
|
143
158
|
is_trashed: z.boolean(),
|
|
@@ -173,7 +188,8 @@ const fileRestoreResponseSchema = z.object({
|
|
|
173
188
|
success: z.literal(true),
|
|
174
189
|
id: nonEmptyString
|
|
175
190
|
});
|
|
176
|
-
|
|
191
|
+
/** SDK4: filename hard-capped to 255 to match backend Zod validation. */
|
|
192
|
+
const fileUpdateRequestSchema = z.object({ filename: z.string().trim().min(1).max(255) });
|
|
177
193
|
const fileUpdateResponseSchema = z.object({ file: fileRecordSchema });
|
|
178
194
|
//#endregion
|
|
179
195
|
//#region src/folders.ts
|
|
@@ -232,7 +248,7 @@ const serviceSchema = z.object({
|
|
|
232
248
|
max_storage_bytes: positiveInt,
|
|
233
249
|
current_used_bytes: z.number().int().nonnegative(),
|
|
234
250
|
max_file_size_bytes: positiveInt,
|
|
235
|
-
recommended_upload_destination:
|
|
251
|
+
recommended_upload_destination: recommendedUploadDestinationSchema.optional(),
|
|
236
252
|
created_at: unixTimestamp
|
|
237
253
|
});
|
|
238
254
|
const serviceDetailResponseSchema = z.object({ service: serviceSchema });
|
|
@@ -246,7 +262,7 @@ const adminServiceUpdateResponseSchema = serviceDetailResponseSchema;
|
|
|
246
262
|
* can flip the recommended default upload destination per service without
|
|
247
263
|
* disturbing quota-related fields.
|
|
248
264
|
*/
|
|
249
|
-
const adminServiceSettingsRequestSchema = z.object({ recommended_upload_destination:
|
|
265
|
+
const adminServiceSettingsRequestSchema = z.object({ recommended_upload_destination: recommendedUploadDestinationSchema.optional() }).refine((v) => v.recommended_upload_destination !== void 0, { message: "At least one setting must be provided" });
|
|
250
266
|
const adminServiceSettingsResponseSchema = serviceDetailResponseSchema;
|
|
251
267
|
const serviceUsageResponseSchema = z.object({
|
|
252
268
|
service_id: nonEmptyString,
|
|
@@ -486,6 +502,24 @@ const releaseSyncResponseSchema = z.object({
|
|
|
486
502
|
synced: z.number().int().nonnegative(),
|
|
487
503
|
results: z.array(releaseSyncResultSchema)
|
|
488
504
|
});
|
|
505
|
+
/**
|
|
506
|
+
* Response of `GET /app/releases/latest?channel=...` — used by client apps to
|
|
507
|
+
* discover the most recent completed release for a given distribution channel
|
|
508
|
+
* (e.g. `stable`, `beta`). Includes a short-lived presigned download URL.
|
|
509
|
+
*/
|
|
510
|
+
const appReleaseLatestQuerySchema = z.object({ channel: nonEmptyString.optional().default("stable") });
|
|
511
|
+
const appReleaseLatestResponseSchema = z.object({
|
|
512
|
+
id: nonEmptyString,
|
|
513
|
+
name: nonEmptyString,
|
|
514
|
+
size: z.number().int().nonnegative(),
|
|
515
|
+
r2_key: nonEmptyString,
|
|
516
|
+
tags: z.array(nonEmptyString),
|
|
517
|
+
notes: z.string().nullable(),
|
|
518
|
+
force_update: z.boolean(),
|
|
519
|
+
created_at: nonEmptyString,
|
|
520
|
+
download_url: z.string().url(),
|
|
521
|
+
download_url_expires_at: positiveInt
|
|
522
|
+
});
|
|
489
523
|
//#endregion
|
|
490
524
|
//#region src/shareLinks.ts
|
|
491
525
|
const shareLinkSchema = z.object({
|
|
@@ -909,6 +943,101 @@ var UnisourceClient = class {
|
|
|
909
943
|
get: (id, signal) => apiRequest(this.config, "GET", `/shares/${id}`, { signal }),
|
|
910
944
|
delete: (id, signal) => apiRequest(this.config, "DELETE", `/shares/${id}`, { signal })
|
|
911
945
|
};
|
|
946
|
+
v2 = {
|
|
947
|
+
files: {
|
|
948
|
+
list: (query, signal, options) => apiRequest(this.config, "GET", "/v2/files", {
|
|
949
|
+
query,
|
|
950
|
+
signal,
|
|
951
|
+
extraHeaders: this.withAsUser(options)
|
|
952
|
+
}),
|
|
953
|
+
bulkMove: (body, signal, options) => apiRequest(this.config, "POST", "/v2/files/bulk-move", {
|
|
954
|
+
body,
|
|
955
|
+
signal,
|
|
956
|
+
extraHeaders: this.withAsUser(options)
|
|
957
|
+
}),
|
|
958
|
+
bulkTrash: (body, signal, options) => apiRequest(this.config, "POST", "/v2/files/bulk-trash", {
|
|
959
|
+
body,
|
|
960
|
+
signal,
|
|
961
|
+
extraHeaders: this.withAsUser(options)
|
|
962
|
+
}),
|
|
963
|
+
bulkRestore: (body, signal, options) => apiRequest(this.config, "POST", "/v2/files/bulk-restore", {
|
|
964
|
+
body,
|
|
965
|
+
signal,
|
|
966
|
+
extraHeaders: this.withAsUser(options)
|
|
967
|
+
})
|
|
968
|
+
},
|
|
969
|
+
folders: {
|
|
970
|
+
list: (query, signal, options) => apiRequest(this.config, "GET", "/v2/folders", {
|
|
971
|
+
query,
|
|
972
|
+
signal,
|
|
973
|
+
extraHeaders: this.withAsUser(options)
|
|
974
|
+
}),
|
|
975
|
+
breadcrumbs: (id, signal, options) => apiRequest(this.config, "GET", `/v2/folders/${id}/breadcrumbs`, {
|
|
976
|
+
signal,
|
|
977
|
+
extraHeaders: this.withAsUser(options)
|
|
978
|
+
}),
|
|
979
|
+
bulkMove: (body, signal, options) => apiRequest(this.config, "POST", "/v2/folders/bulk-move", {
|
|
980
|
+
body,
|
|
981
|
+
signal,
|
|
982
|
+
extraHeaders: this.withAsUser(options)
|
|
983
|
+
}),
|
|
984
|
+
bulkTrash: (body, signal, options) => apiRequest(this.config, "POST", "/v2/folders/bulk-trash", {
|
|
985
|
+
body,
|
|
986
|
+
signal,
|
|
987
|
+
extraHeaders: this.withAsUser(options)
|
|
988
|
+
}),
|
|
989
|
+
bulkRestore: (body, signal, options) => apiRequest(this.config, "POST", "/v2/folders/bulk-restore", {
|
|
990
|
+
body,
|
|
991
|
+
signal,
|
|
992
|
+
extraHeaders: this.withAsUser(options)
|
|
993
|
+
})
|
|
994
|
+
}
|
|
995
|
+
};
|
|
996
|
+
app = { releases: { latest: (channel = "stable", signal) => apiRequest(this.config, "GET", "/app/releases/latest", {
|
|
997
|
+
query: { channel },
|
|
998
|
+
signal
|
|
999
|
+
}) } };
|
|
912
1000
|
};
|
|
913
1001
|
//#endregion
|
|
914
|
-
|
|
1002
|
+
//#region src/v2.ts
|
|
1003
|
+
const fileRecordsListV2QuerySchema = z.object({
|
|
1004
|
+
folder_id: nonEmptyString.nullable().optional().transform((v) => v === "null" ? null : v),
|
|
1005
|
+
is_trashed: z.enum(["true", "false"]).transform((v) => v === "true").optional(),
|
|
1006
|
+
search: z.string().optional(),
|
|
1007
|
+
mime_type: z.string().optional(),
|
|
1008
|
+
sort_by: z.enum([
|
|
1009
|
+
"created_at",
|
|
1010
|
+
"name",
|
|
1011
|
+
"size"
|
|
1012
|
+
]).optional(),
|
|
1013
|
+
sort_dir: z.enum(["asc", "desc"]).optional(),
|
|
1014
|
+
cursor: nonEmptyString.optional(),
|
|
1015
|
+
limit: z.coerce.number().int().min(1).max(100).optional()
|
|
1016
|
+
});
|
|
1017
|
+
const bulkFileIdsSchema = z.object({ ids: z.array(nonEmptyString).min(1).max(100) });
|
|
1018
|
+
const bulkFileMoveRequestSchema = z.object({
|
|
1019
|
+
ids: z.array(nonEmptyString).min(1).max(100),
|
|
1020
|
+
folder_id: nonEmptyString.nullable().optional()
|
|
1021
|
+
});
|
|
1022
|
+
const bulkOperationResponseSchema = z.object({
|
|
1023
|
+
success: z.boolean(),
|
|
1024
|
+
processed_count: z.number().int().nonnegative(),
|
|
1025
|
+
failed_ids: z.array(nonEmptyString).optional()
|
|
1026
|
+
});
|
|
1027
|
+
const folderListV2QuerySchema = z.object({
|
|
1028
|
+
parent_id: nonEmptyString.nullable().optional().transform((v) => v === "null" ? null : v),
|
|
1029
|
+
is_trashed: z.enum(["true", "false"]).transform((v) => v === "true").optional(),
|
|
1030
|
+
search: z.string().optional(),
|
|
1031
|
+
sort_by: z.enum(["created_at", "name"]).optional(),
|
|
1032
|
+
sort_dir: z.enum(["asc", "desc"]).optional(),
|
|
1033
|
+
cursor: nonEmptyString.optional(),
|
|
1034
|
+
limit: z.coerce.number().int().min(1).max(100).optional()
|
|
1035
|
+
});
|
|
1036
|
+
const bulkFolderIdsSchema = z.object({ ids: z.array(nonEmptyString).min(1).max(100) });
|
|
1037
|
+
const bulkFolderMoveRequestSchema = z.object({
|
|
1038
|
+
ids: z.array(nonEmptyString).min(1).max(100),
|
|
1039
|
+
parent_id: nonEmptyString.nullable().optional()
|
|
1040
|
+
});
|
|
1041
|
+
const folderBreadcrumbsResponseSchema = z.object({ breadcrumbs: z.array(folderSchema) });
|
|
1042
|
+
//#endregion
|
|
1043
|
+
export { FILES_DEFAULT_LIMIT, FILES_MAX_LIMIT, UnisourceClient, UnisourceError, UnisourceNetworkError, adminServiceSettingsRequestSchema, adminServiceSettingsResponseSchema, adminServiceUpdateRequestSchema, adminServiceUpdateResponseSchema, adminUserListResponseSchema, adminUserPasswordResetRequestSchema, adminUserPasswordResetResponseSchema, adminUserRoleUpdateRequestSchema, adminUserSchema, adminUserStorageLimitUpdateRequestSchema, adminUserUpdateRequestSchema, adminUserUpdateResponseSchema, apiErrorSchema, appReleaseLatestQuerySchema, appReleaseLatestResponseSchema, auditEventActionSchema, auditEventSchema, auditLogListQuerySchema, auditLogListResponseSchema, bulkFileIdsSchema, bulkFileMoveRequestSchema, bulkFolderIdsSchema, bulkFolderMoveRequestSchema, bulkOperationResponseSchema, fileDeleteResponseSchema, fileDownloadUrlResponseSchema, fileMoveRequestSchema, fileRecordDetailResponseSchema, fileRecordSchema, fileRecordsListQuerySchema, fileRecordsListResponseSchema, fileRecordsListV2QuerySchema, fileRestoreResponseSchema, fileUpdateRequestSchema, fileUpdateResponseSchema, folderBreadcrumbsResponseSchema, folderCreateRequestSchema, folderCreateResponseSchema, folderDeleteResponseSchema, folderDetailResponseSchema, folderListQuerySchema, folderListResponseSchema, folderListV2QuerySchema, folderRestoreResponseSchema, folderSchema, folderUpdateRequestSchema, folderUpdateResponseSchema, getPublicFileInfo, mainStorageDeleteResponseSchema, mainStorageDetailResponseSchema, mainStorageFileSchema, mainStorageListQuerySchema, mainStorageListResponseSchema, mainStorageRenameRequestSchema, mainStorageRenameResponseSchema, mainStorageRestoreResponseSchema, multipartAbortRequestSchema, multipartAbortResponseSchema, multipartCompleteRequestSchema, multipartCompleteResponseSchema, multipartCreateRequestSchema, multipartCreateResponseSchema, multipartListPartsQuerySchema, multipartListPartsResponseSchema, multipartPartSchema, multipartSignPartQuerySchema, multipartSignPartResponseSchema, nonEmptyString, nonNegativeInt, positiveInt, publicFileAccessResponseSchema, publicFileLockedResponseSchema, recommendedUploadDestinationSchema, releaseDTOSchema, releaseDeleteResponseSchema, releaseMultipartAbortRequestSchema, releaseMultipartAbortResponseSchema, releaseMultipartCompleteRequestSchema, releaseMultipartCompleteResponseSchema, releaseMultipartCreateRequestSchema, releaseMultipartCreateResponseSchema, releaseMultipartListPartsQuerySchema, releaseMultipartListPartsResponseSchema, releaseMultipartPartSchema, releaseMultipartSignPartQuerySchema, releaseMultipartSignPartResponseSchema, releaseSyncManifestSchema, releaseSyncRequestSchema, releaseSyncResponseSchema, releaseSyncResultSchema, releaseUpdateRequestSchema, releaseUploadCompleteRequestSchema, releaseUploadCompleteResponseSchema, releaseUploadFailResponseSchema, releaseUploadInitRequestSchema, releaseUploadInitResponseSchema, releasesListQuerySchema, releasesListResponseSchema, serviceDetailResponseSchema, serviceSchema, serviceUsageResponseSchema, shareLinkCreateRequestSchema, shareLinkCreateResponseSchema, shareLinkDeleteResponseSchema, shareLinkDetailResponseSchema, shareLinkListResponseSchema, shareLinkSchema, shareLinkUpdateRequestSchema, shareLinkUpdateResponseSchema, sharesCreateRequestSchema, unixTimestamp, unlockPublicFile, uploadAppwriteInitRequestSchema, uploadAppwriteInitResponseSchema, uploadCompleteResponseSchema, uploadDestinationSchema, uploadFailResponseSchema, uploadLifecycleRequestSchema, uploadR2InitRequestSchema, uploadR2InitResponseSchema, uploadRecordDetailResponseSchema, uploadRecordSchema, uploadStatusSchema, uploadTypeSchema, uploadsListResponseSchema };
|
package/package.json
CHANGED
package/src/client.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ApiError, UploadStatus } from './primitives';
|
|
1
|
+
import type { ApiError, UploadDestination, UploadStatus } from './primitives';
|
|
2
2
|
import type {
|
|
3
3
|
UploadR2InitRequest,
|
|
4
4
|
UploadR2InitResponse,
|
|
@@ -40,6 +40,16 @@ import type {
|
|
|
40
40
|
FolderDeleteResponse,
|
|
41
41
|
FolderRestoreResponse,
|
|
42
42
|
} from './folders';
|
|
43
|
+
import type {
|
|
44
|
+
FileRecordsListV2Query,
|
|
45
|
+
FolderListV2Query,
|
|
46
|
+
BulkFileIds,
|
|
47
|
+
BulkFileMoveRequest,
|
|
48
|
+
BulkFolderIds,
|
|
49
|
+
BulkFolderMoveRequest,
|
|
50
|
+
BulkOperationResponse,
|
|
51
|
+
FolderBreadcrumbsResponse,
|
|
52
|
+
} from './v2';
|
|
43
53
|
import type {
|
|
44
54
|
ServiceDetailResponse,
|
|
45
55
|
ServiceUsageResponse,
|
|
@@ -97,6 +107,7 @@ import type {
|
|
|
97
107
|
ReleaseMultipartCompleteRequest,
|
|
98
108
|
ReleaseMultipartCompleteResponse,
|
|
99
109
|
ReleaseMultipartAbortResponse,
|
|
110
|
+
AppReleaseLatestResponse,
|
|
100
111
|
} from './releases';
|
|
101
112
|
|
|
102
113
|
// ─── SDK Error classes ────────────────────────────────────────────────────────
|
|
@@ -501,7 +512,10 @@ export class UnisourceClient {
|
|
|
501
512
|
apiRequest(this.config, 'GET', '/admin/service/usage', { signal }),
|
|
502
513
|
|
|
503
514
|
/** List all uploads (pending/completed/failed) for this service */
|
|
504
|
-
listUploads: (
|
|
515
|
+
listUploads: (
|
|
516
|
+
query?: { destination?: UploadDestination; status?: UploadStatus; cursor?: string; limit?: number },
|
|
517
|
+
signal?: AbortSignal
|
|
518
|
+
): Promise<UploadsListResponse> =>
|
|
505
519
|
apiRequest(this.config, 'GET', '/admin/files', { query, signal }),
|
|
506
520
|
|
|
507
521
|
/** Get a single upload for this service */
|
|
@@ -622,4 +636,65 @@ export class UnisourceClient {
|
|
|
622
636
|
delete: (id: string, signal?: AbortSignal): Promise<ShareLinkDeleteResponse> =>
|
|
623
637
|
apiRequest(this.config, 'DELETE', `/shares/${id}`, { signal }),
|
|
624
638
|
};
|
|
639
|
+
|
|
640
|
+
// ─── V2 API Endpoints ───────────────────────────────────────────────────────
|
|
641
|
+
|
|
642
|
+
readonly v2 = {
|
|
643
|
+
files: {
|
|
644
|
+
/** List files with advanced search, sorting, and filtering capabilities */
|
|
645
|
+
list: (query?: FileRecordsListV2Query, signal?: AbortSignal, options?: { asUser?: string }): Promise<FileRecordsListResponse> =>
|
|
646
|
+
apiRequest(this.config, 'GET', '/v2/files', { query, signal, extraHeaders: this.withAsUser(options) }),
|
|
647
|
+
|
|
648
|
+
/** Move multiple files at once */
|
|
649
|
+
bulkMove: (body: BulkFileMoveRequest, signal?: AbortSignal, options?: { asUser?: string }): Promise<BulkOperationResponse> =>
|
|
650
|
+
apiRequest(this.config, 'POST', '/v2/files/bulk-move', { body, signal, extraHeaders: this.withAsUser(options) }),
|
|
651
|
+
|
|
652
|
+
/** Move multiple files to trash */
|
|
653
|
+
bulkTrash: (body: BulkFileIds, signal?: AbortSignal, options?: { asUser?: string }): Promise<BulkOperationResponse> =>
|
|
654
|
+
apiRequest(this.config, 'POST', '/v2/files/bulk-trash', { body, signal, extraHeaders: this.withAsUser(options) }),
|
|
655
|
+
|
|
656
|
+
/** Restore multiple files from trash */
|
|
657
|
+
bulkRestore: (body: BulkFileIds, signal?: AbortSignal, options?: { asUser?: string }): Promise<BulkOperationResponse> =>
|
|
658
|
+
apiRequest(this.config, 'POST', '/v2/files/bulk-restore', { body, signal, extraHeaders: this.withAsUser(options) }),
|
|
659
|
+
},
|
|
660
|
+
|
|
661
|
+
folders: {
|
|
662
|
+
/** List folders with advanced search, sorting, and filtering capabilities */
|
|
663
|
+
list: (query?: FolderListV2Query, signal?: AbortSignal, options?: { asUser?: string }): Promise<FolderListResponse> =>
|
|
664
|
+
apiRequest(this.config, 'GET', '/v2/folders', { query, signal, extraHeaders: this.withAsUser(options) }),
|
|
665
|
+
|
|
666
|
+
/** Get the breadcrumb hierarchy for a specific folder */
|
|
667
|
+
breadcrumbs: (id: string, signal?: AbortSignal, options?: { asUser?: string }): Promise<FolderBreadcrumbsResponse> =>
|
|
668
|
+
apiRequest(this.config, 'GET', `/v2/folders/${id}/breadcrumbs`, { signal, extraHeaders: this.withAsUser(options) }),
|
|
669
|
+
|
|
670
|
+
/** Move multiple folders at once */
|
|
671
|
+
bulkMove: (body: BulkFolderMoveRequest, signal?: AbortSignal, options?: { asUser?: string }): Promise<BulkOperationResponse> =>
|
|
672
|
+
apiRequest(this.config, 'POST', '/v2/folders/bulk-move', { body, signal, extraHeaders: this.withAsUser(options) }),
|
|
673
|
+
|
|
674
|
+
/** Move multiple folders to trash */
|
|
675
|
+
bulkTrash: (body: BulkFolderIds, signal?: AbortSignal, options?: { asUser?: string }): Promise<BulkOperationResponse> =>
|
|
676
|
+
apiRequest(this.config, 'POST', '/v2/folders/bulk-trash', { body, signal, extraHeaders: this.withAsUser(options) }),
|
|
677
|
+
|
|
678
|
+
/** Restore multiple folders from trash */
|
|
679
|
+
bulkRestore: (body: BulkFolderIds, signal?: AbortSignal, options?: { asUser?: string }): Promise<BulkOperationResponse> =>
|
|
680
|
+
apiRequest(this.config, 'POST', '/v2/folders/bulk-restore', { body, signal, extraHeaders: this.withAsUser(options) }),
|
|
681
|
+
}
|
|
682
|
+
};
|
|
683
|
+
|
|
684
|
+
// ─── App-facing endpoints (/app/*) — public release distribution ──────────────
|
|
685
|
+
|
|
686
|
+
readonly app = {
|
|
687
|
+
releases: {
|
|
688
|
+
/**
|
|
689
|
+
* Get the latest completed release for a channel (e.g. `stable`, `beta`).
|
|
690
|
+
* Backed by `GET /app/releases/latest`. Returns the release metadata plus
|
|
691
|
+
* a short-lived presigned download URL.
|
|
692
|
+
*/
|
|
693
|
+
latest: (
|
|
694
|
+
channel: string = 'stable',
|
|
695
|
+
signal?: AbortSignal
|
|
696
|
+
): Promise<AppReleaseLatestResponse> =>
|
|
697
|
+
apiRequest(this.config, 'GET', '/app/releases/latest', { query: { channel }, signal }),
|
|
698
|
+
},
|
|
699
|
+
};
|
|
625
700
|
}
|
package/src/fileRecords.ts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
nonEmptyString,
|
|
4
|
+
nonNegativeInt,
|
|
5
|
+
positiveInt,
|
|
6
|
+
uploadDestinationSchema,
|
|
7
|
+
FILES_DEFAULT_LIMIT,
|
|
8
|
+
FILES_MAX_LIMIT,
|
|
9
|
+
} from './primitives';
|
|
3
10
|
|
|
4
11
|
// ─── User-facing file record ──────────────────────────────────────────────────
|
|
5
12
|
|
|
@@ -14,7 +21,8 @@ export const fileRecordSchema = z.object({
|
|
|
14
21
|
folder_id: nonEmptyString.nullable(),
|
|
15
22
|
upload_id: nonEmptyString.nullable(),
|
|
16
23
|
filename: nonEmptyString,
|
|
17
|
-
|
|
24
|
+
/** SDK6: zero-byte uploads are valid (e.g. placeholders). */
|
|
25
|
+
size: nonNegativeInt,
|
|
18
26
|
mime_type: nonEmptyString,
|
|
19
27
|
storage_destination: uploadDestinationSchema,
|
|
20
28
|
is_trashed: z.boolean(),
|
|
@@ -88,8 +96,9 @@ export type FileRestoreResponse = z.infer<typeof fileRestoreResponseSchema>;
|
|
|
88
96
|
|
|
89
97
|
// ─── Update (rename) ──────────────────────────────────────────────────────────
|
|
90
98
|
|
|
99
|
+
/** SDK4: filename hard-capped to 255 to match backend Zod validation. */
|
|
91
100
|
export const fileUpdateRequestSchema = z.object({
|
|
92
|
-
filename:
|
|
101
|
+
filename: z.string().trim().min(1).max(255),
|
|
93
102
|
});
|
|
94
103
|
export type FileUpdateRequest = z.infer<typeof fileUpdateRequestSchema>;
|
|
95
104
|
|
package/src/index.ts
CHANGED
|
@@ -2,14 +2,21 @@
|
|
|
2
2
|
export {
|
|
3
3
|
nonEmptyString,
|
|
4
4
|
positiveInt,
|
|
5
|
+
nonNegativeInt,
|
|
5
6
|
unixTimestamp,
|
|
6
7
|
uploadDestinationSchema,
|
|
8
|
+
recommendedUploadDestinationSchema,
|
|
7
9
|
uploadStatusSchema,
|
|
8
10
|
apiErrorSchema,
|
|
9
11
|
FILES_DEFAULT_LIMIT,
|
|
10
12
|
FILES_MAX_LIMIT,
|
|
11
13
|
} from './primitives';
|
|
12
|
-
export type {
|
|
14
|
+
export type {
|
|
15
|
+
UploadDestination,
|
|
16
|
+
RecommendedUploadDestination,
|
|
17
|
+
UploadStatus,
|
|
18
|
+
ApiError,
|
|
19
|
+
} from './primitives';
|
|
13
20
|
|
|
14
21
|
|
|
15
22
|
// ─── Upload ───────────────────────────────────────────────────────────────────
|
|
@@ -188,6 +195,8 @@ export {
|
|
|
188
195
|
releaseMultipartCompleteResponseSchema,
|
|
189
196
|
releaseMultipartAbortRequestSchema,
|
|
190
197
|
releaseMultipartAbortResponseSchema,
|
|
198
|
+
appReleaseLatestQuerySchema,
|
|
199
|
+
appReleaseLatestResponseSchema,
|
|
191
200
|
} from './releases';
|
|
192
201
|
export type {
|
|
193
202
|
ReleaseDTO,
|
|
@@ -215,6 +224,8 @@ export type {
|
|
|
215
224
|
ReleaseMultipartCompleteResponse,
|
|
216
225
|
ReleaseMultipartAbortRequest,
|
|
217
226
|
ReleaseMultipartAbortResponse,
|
|
227
|
+
AppReleaseLatestQuery,
|
|
228
|
+
AppReleaseLatestResponse,
|
|
218
229
|
} from './releases';
|
|
219
230
|
|
|
220
231
|
// ─── Share Links ─────────────────────────────────────────────────────────────
|
|
@@ -254,3 +265,25 @@ export {
|
|
|
254
265
|
unlockPublicFile,
|
|
255
266
|
} from './client';
|
|
256
267
|
export type { UnisourceClientConfig } from './client';
|
|
268
|
+
|
|
269
|
+
// ─── V2 API ───────────────────────────────────────────────────────────────────
|
|
270
|
+
export {
|
|
271
|
+
fileRecordsListV2QuerySchema,
|
|
272
|
+
bulkFileIdsSchema,
|
|
273
|
+
bulkFileMoveRequestSchema,
|
|
274
|
+
bulkOperationResponseSchema,
|
|
275
|
+
folderListV2QuerySchema,
|
|
276
|
+
bulkFolderIdsSchema,
|
|
277
|
+
bulkFolderMoveRequestSchema,
|
|
278
|
+
folderBreadcrumbsResponseSchema,
|
|
279
|
+
} from './v2';
|
|
280
|
+
export type {
|
|
281
|
+
FileRecordsListV2Query,
|
|
282
|
+
BulkFileIds,
|
|
283
|
+
BulkFileMoveRequest,
|
|
284
|
+
BulkOperationResponse,
|
|
285
|
+
FolderListV2Query,
|
|
286
|
+
BulkFolderIds,
|
|
287
|
+
BulkFolderMoveRequest,
|
|
288
|
+
FolderBreadcrumbsResponse,
|
|
289
|
+
} from './v2';
|
package/src/primitives.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { z } from 'zod';
|
|
|
4
4
|
|
|
5
5
|
export const nonEmptyString = z.string().trim().min(1);
|
|
6
6
|
export const positiveInt = z.number().int().positive();
|
|
7
|
+
export const nonNegativeInt = z.number().int().nonnegative();
|
|
7
8
|
export const unixTimestamp = z.number().int().nonnegative();
|
|
8
9
|
|
|
9
10
|
// ─── Pagination constants ─────────────────────────────────────────────────────
|
|
@@ -13,9 +14,21 @@ export const FILES_MAX_LIMIT = 100;
|
|
|
13
14
|
|
|
14
15
|
// ─── Upload Destination ──────────────────────────────────────────────────────
|
|
15
16
|
|
|
17
|
+
/**
|
|
18
|
+
* Storage backend a file lives on.
|
|
19
|
+
* - 'r2' — Cloudflare R2 via presigned PUT / multipart
|
|
20
|
+
* - 'appwrite' — Appwrite Storage via direct browser SDK upload
|
|
21
|
+
*
|
|
22
|
+
* `recommendedUploadDestinationSchema` adds the meta-value 'hybrid' which is
|
|
23
|
+
* only valid as a service-wide setting (the upload manager picks r2/appwrite
|
|
24
|
+
* per-file based on size).
|
|
25
|
+
*/
|
|
16
26
|
export const uploadDestinationSchema = z.enum(['r2', 'appwrite']);
|
|
17
27
|
export type UploadDestination = z.infer<typeof uploadDestinationSchema>;
|
|
18
28
|
|
|
29
|
+
export const recommendedUploadDestinationSchema = z.enum(['r2', 'appwrite', 'hybrid']);
|
|
30
|
+
export type RecommendedUploadDestination = z.infer<typeof recommendedUploadDestinationSchema>;
|
|
31
|
+
|
|
19
32
|
// ─── Upload Status ────────────────────────────────────────────────────────────
|
|
20
33
|
|
|
21
34
|
export const uploadStatusSchema = z.enum(['pending', 'completed', 'failed']);
|
package/src/releases.ts
CHANGED
|
@@ -208,3 +208,29 @@ export const releaseSyncResponseSchema = z.object({
|
|
|
208
208
|
results: z.array(releaseSyncResultSchema),
|
|
209
209
|
});
|
|
210
210
|
export type ReleaseSyncResponse = z.infer<typeof releaseSyncResponseSchema>;
|
|
211
|
+
|
|
212
|
+
// ─── App-facing /app/releases/latest ─────────────────────────────────────────
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Response of `GET /app/releases/latest?channel=...` — used by client apps to
|
|
216
|
+
* discover the most recent completed release for a given distribution channel
|
|
217
|
+
* (e.g. `stable`, `beta`). Includes a short-lived presigned download URL.
|
|
218
|
+
*/
|
|
219
|
+
export const appReleaseLatestQuerySchema = z.object({
|
|
220
|
+
channel: nonEmptyString.optional().default('stable'),
|
|
221
|
+
});
|
|
222
|
+
export type AppReleaseLatestQuery = z.input<typeof appReleaseLatestQuerySchema>;
|
|
223
|
+
|
|
224
|
+
export const appReleaseLatestResponseSchema = z.object({
|
|
225
|
+
id: nonEmptyString,
|
|
226
|
+
name: nonEmptyString,
|
|
227
|
+
size: z.number().int().nonnegative(),
|
|
228
|
+
r2_key: nonEmptyString,
|
|
229
|
+
tags: z.array(nonEmptyString),
|
|
230
|
+
notes: z.string().nullable(),
|
|
231
|
+
force_update: z.boolean(),
|
|
232
|
+
created_at: nonEmptyString,
|
|
233
|
+
download_url: z.string().url(),
|
|
234
|
+
download_url_expires_at: positiveInt,
|
|
235
|
+
});
|
|
236
|
+
export type AppReleaseLatestResponse = z.infer<typeof appReleaseLatestResponseSchema>;
|
package/src/services.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { nonEmptyString, positiveInt,
|
|
2
|
+
import { nonEmptyString, positiveInt, recommendedUploadDestinationSchema, unixTimestamp } from './primitives';
|
|
3
3
|
|
|
4
4
|
// ─── Service record ───────────────────────────────────────────────────────────
|
|
5
5
|
|
|
@@ -10,7 +10,7 @@ export const serviceSchema = z.object({
|
|
|
10
10
|
max_storage_bytes: positiveInt,
|
|
11
11
|
current_used_bytes: z.number().int().nonnegative(),
|
|
12
12
|
max_file_size_bytes: positiveInt,
|
|
13
|
-
recommended_upload_destination:
|
|
13
|
+
recommended_upload_destination: recommendedUploadDestinationSchema.optional(),
|
|
14
14
|
created_at: unixTimestamp,
|
|
15
15
|
});
|
|
16
16
|
export type Service = z.infer<typeof serviceSchema>;
|
|
@@ -43,7 +43,7 @@ export type AdminServiceUpdateResponse = z.infer<typeof adminServiceUpdateRespon
|
|
|
43
43
|
*/
|
|
44
44
|
export const adminServiceSettingsRequestSchema = z
|
|
45
45
|
.object({
|
|
46
|
-
recommended_upload_destination:
|
|
46
|
+
recommended_upload_destination: recommendedUploadDestinationSchema.optional(),
|
|
47
47
|
})
|
|
48
48
|
.refine((v) => v.recommended_upload_destination !== undefined, {
|
|
49
49
|
message: 'At least one setting must be provided',
|
package/src/v2.ts
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { nonEmptyString, FILES_MAX_LIMIT } from './primitives';
|
|
3
|
+
import { folderSchema } from './folders';
|
|
4
|
+
|
|
5
|
+
// ─── File Records V2 ─────────────────────────────────────────────────────────
|
|
6
|
+
|
|
7
|
+
export const fileRecordsListV2QuerySchema = z.object({
|
|
8
|
+
folder_id: nonEmptyString.nullable().optional().transform(v => v === 'null' ? null : v),
|
|
9
|
+
is_trashed: z.enum(['true', 'false']).transform(v => v === 'true').optional(),
|
|
10
|
+
search: z.string().optional(),
|
|
11
|
+
mime_type: z.string().optional(),
|
|
12
|
+
sort_by: z.enum(['created_at', 'name', 'size']).optional(),
|
|
13
|
+
sort_dir: z.enum(['asc', 'desc']).optional(),
|
|
14
|
+
cursor: nonEmptyString.optional(),
|
|
15
|
+
limit: z.coerce.number().int().min(1).max(FILES_MAX_LIMIT).optional(),
|
|
16
|
+
});
|
|
17
|
+
export type FileRecordsListV2Query = z.infer<typeof fileRecordsListV2QuerySchema>;
|
|
18
|
+
|
|
19
|
+
// Bulk Operations for Files
|
|
20
|
+
export const bulkFileIdsSchema = z.object({
|
|
21
|
+
ids: z.array(nonEmptyString).min(1).max(100),
|
|
22
|
+
});
|
|
23
|
+
export type BulkFileIds = z.infer<typeof bulkFileIdsSchema>;
|
|
24
|
+
|
|
25
|
+
export const bulkFileMoveRequestSchema = z.object({
|
|
26
|
+
ids: z.array(nonEmptyString).min(1).max(100),
|
|
27
|
+
folder_id: nonEmptyString.nullable().optional(),
|
|
28
|
+
});
|
|
29
|
+
export type BulkFileMoveRequest = z.infer<typeof bulkFileMoveRequestSchema>;
|
|
30
|
+
|
|
31
|
+
export const bulkOperationResponseSchema = z.object({
|
|
32
|
+
success: z.boolean(),
|
|
33
|
+
processed_count: z.number().int().nonnegative(),
|
|
34
|
+
failed_ids: z.array(nonEmptyString).optional(),
|
|
35
|
+
});
|
|
36
|
+
export type BulkOperationResponse = z.infer<typeof bulkOperationResponseSchema>;
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
// ─── Folders V2 ──────────────────────────────────────────────────────────────
|
|
40
|
+
|
|
41
|
+
export const folderListV2QuerySchema = z.object({
|
|
42
|
+
parent_id: nonEmptyString.nullable().optional().transform(v => v === 'null' ? null : v),
|
|
43
|
+
is_trashed: z.enum(['true', 'false']).transform(v => v === 'true').optional(),
|
|
44
|
+
search: z.string().optional(),
|
|
45
|
+
sort_by: z.enum(['created_at', 'name']).optional(),
|
|
46
|
+
sort_dir: z.enum(['asc', 'desc']).optional(),
|
|
47
|
+
cursor: nonEmptyString.optional(),
|
|
48
|
+
limit: z.coerce.number().int().min(1).max(FILES_MAX_LIMIT).optional(),
|
|
49
|
+
});
|
|
50
|
+
export type FolderListV2Query = z.infer<typeof folderListV2QuerySchema>;
|
|
51
|
+
|
|
52
|
+
// Bulk Operations for Folders
|
|
53
|
+
export const bulkFolderIdsSchema = z.object({
|
|
54
|
+
ids: z.array(nonEmptyString).min(1).max(100),
|
|
55
|
+
});
|
|
56
|
+
export type BulkFolderIds = z.infer<typeof bulkFolderIdsSchema>;
|
|
57
|
+
|
|
58
|
+
export const bulkFolderMoveRequestSchema = z.object({
|
|
59
|
+
ids: z.array(nonEmptyString).min(1).max(100),
|
|
60
|
+
parent_id: nonEmptyString.nullable().optional(),
|
|
61
|
+
});
|
|
62
|
+
export type BulkFolderMoveRequest = z.infer<typeof bulkFolderMoveRequestSchema>;
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
// Breadcrumbs
|
|
66
|
+
export const folderBreadcrumbsResponseSchema = z.object({
|
|
67
|
+
breadcrumbs: z.array(folderSchema),
|
|
68
|
+
});
|
|
69
|
+
export type FolderBreadcrumbsResponse = z.infer<typeof folderBreadcrumbsResponseSchema>;
|