@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/src/fileRecords.ts
CHANGED
|
@@ -1,87 +1,99 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { nonEmptyString, positiveInt, uploadDestinationSchema } from './primitives';
|
|
3
|
-
|
|
4
|
-
// ─── User-facing file record ──────────────────────────────────────────────────
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* A confirmed file record owned by a user.
|
|
8
|
-
* Internal fields (storage_key, bucket) are intentionally excluded from the public API.
|
|
9
|
-
*/
|
|
10
|
-
export const fileRecordSchema = z.object({
|
|
11
|
-
id: nonEmptyString,
|
|
12
|
-
service_id: nonEmptyString,
|
|
13
|
-
user_id: nonEmptyString,
|
|
14
|
-
folder_id: nonEmptyString.nullable(),
|
|
15
|
-
upload_id: nonEmptyString.nullable(),
|
|
16
|
-
filename: nonEmptyString,
|
|
17
|
-
size: positiveInt,
|
|
18
|
-
mime_type: nonEmptyString,
|
|
19
|
-
storage_destination: uploadDestinationSchema,
|
|
20
|
-
is_trashed: z.boolean(),
|
|
21
|
-
trashed_at: positiveInt.nullable(),
|
|
22
|
-
created_at: positiveInt,
|
|
23
|
-
updated_at: positiveInt,
|
|
24
|
-
});
|
|
25
|
-
export type FileRecord = z.infer<typeof fileRecordSchema>;
|
|
26
|
-
|
|
27
|
-
// ─── List ─────────────────────────────────────────────────────────────────────
|
|
28
|
-
|
|
29
|
-
export
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
export const fileRecordsListQuerySchema = z.object({
|
|
33
|
-
folder_id: nonEmptyString.nullable().optional(),
|
|
34
|
-
is_trashed: z.boolean().optional(),
|
|
35
|
-
cursor: nonEmptyString.optional(),
|
|
36
|
-
limit: z.number().int().min(1).max(FILES_MAX_LIMIT).optional(),
|
|
37
|
-
});
|
|
38
|
-
export type FileRecordsListQuery = z.infer<typeof fileRecordsListQuerySchema>;
|
|
39
|
-
|
|
40
|
-
export const fileRecordsListResponseSchema = z.object({
|
|
41
|
-
items: z.array(fileRecordSchema),
|
|
42
|
-
next_cursor: z.string().nullable(),
|
|
43
|
-
limit: positiveInt,
|
|
44
|
-
});
|
|
45
|
-
export type FileRecordsListResponse = z.infer<typeof fileRecordsListResponseSchema>;
|
|
46
|
-
|
|
47
|
-
// ─── Single file detail ───────────────────────────────────────────────────────
|
|
48
|
-
|
|
49
|
-
export const fileRecordDetailResponseSchema = z.object({
|
|
50
|
-
file: fileRecordSchema,
|
|
51
|
-
});
|
|
52
|
-
export type FileRecordDetailResponse = z.infer<typeof fileRecordDetailResponseSchema>;
|
|
53
|
-
|
|
54
|
-
// ─── Move ────────────────────────────────────────────────────────────────────
|
|
55
|
-
|
|
56
|
-
export const fileMoveRequestSchema = z.object({
|
|
57
|
-
/** null = move to root, undefined = keep unchanged */
|
|
58
|
-
folder_id: nonEmptyString.nullable().optional(),
|
|
59
|
-
});
|
|
60
|
-
export type FileMoveRequest = z.infer<typeof fileMoveRequestSchema>;
|
|
61
|
-
|
|
62
|
-
// ─── Download URL ─────────────────────────────────────────────────────────────
|
|
63
|
-
|
|
64
|
-
export const fileDownloadUrlResponseSchema = z.object({
|
|
65
|
-
upload_id: nonEmptyString,
|
|
66
|
-
destination: uploadDestinationSchema,
|
|
67
|
-
download_url: z.string().url(),
|
|
68
|
-
expires_at: positiveInt,
|
|
69
|
-
});
|
|
70
|
-
export type FileDownloadUrlResponse = z.infer<typeof fileDownloadUrlResponseSchema>;
|
|
71
|
-
|
|
72
|
-
// ─── Delete ───────────────────────────────────────────────────────────────────
|
|
73
|
-
|
|
74
|
-
export const fileDeleteResponseSchema = z.object({
|
|
75
|
-
success: z.literal(true),
|
|
76
|
-
id: nonEmptyString,
|
|
77
|
-
permanent: z.boolean(),
|
|
78
|
-
});
|
|
79
|
-
export type FileDeleteResponse = z.infer<typeof fileDeleteResponseSchema>;
|
|
80
|
-
|
|
81
|
-
// ─── Restore ──────────────────────────────────────────────────────────────────
|
|
82
|
-
|
|
83
|
-
export const fileRestoreResponseSchema = z.object({
|
|
84
|
-
success: z.literal(true),
|
|
85
|
-
id: nonEmptyString,
|
|
86
|
-
});
|
|
87
|
-
export type FileRestoreResponse = z.infer<typeof fileRestoreResponseSchema>;
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { nonEmptyString, positiveInt, uploadDestinationSchema, FILES_DEFAULT_LIMIT, FILES_MAX_LIMIT } from './primitives';
|
|
3
|
+
|
|
4
|
+
// ─── User-facing file record ──────────────────────────────────────────────────
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A confirmed file record owned by a user.
|
|
8
|
+
* Internal fields (storage_key, bucket) are intentionally excluded from the public API.
|
|
9
|
+
*/
|
|
10
|
+
export const fileRecordSchema = z.object({
|
|
11
|
+
id: nonEmptyString,
|
|
12
|
+
service_id: nonEmptyString,
|
|
13
|
+
user_id: nonEmptyString,
|
|
14
|
+
folder_id: nonEmptyString.nullable(),
|
|
15
|
+
upload_id: nonEmptyString.nullable(),
|
|
16
|
+
filename: nonEmptyString,
|
|
17
|
+
size: positiveInt,
|
|
18
|
+
mime_type: nonEmptyString,
|
|
19
|
+
storage_destination: uploadDestinationSchema,
|
|
20
|
+
is_trashed: z.boolean(),
|
|
21
|
+
trashed_at: positiveInt.nullable(),
|
|
22
|
+
created_at: positiveInt,
|
|
23
|
+
updated_at: positiveInt,
|
|
24
|
+
});
|
|
25
|
+
export type FileRecord = z.infer<typeof fileRecordSchema>;
|
|
26
|
+
|
|
27
|
+
// ─── List ─────────────────────────────────────────────────────────────────────
|
|
28
|
+
|
|
29
|
+
export { FILES_DEFAULT_LIMIT, FILES_MAX_LIMIT };
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
export const fileRecordsListQuerySchema = z.object({
|
|
33
|
+
folder_id: nonEmptyString.nullable().optional(),
|
|
34
|
+
is_trashed: z.boolean().optional(),
|
|
35
|
+
cursor: nonEmptyString.optional(),
|
|
36
|
+
limit: z.number().int().min(1).max(FILES_MAX_LIMIT).optional(),
|
|
37
|
+
});
|
|
38
|
+
export type FileRecordsListQuery = z.infer<typeof fileRecordsListQuerySchema>;
|
|
39
|
+
|
|
40
|
+
export const fileRecordsListResponseSchema = z.object({
|
|
41
|
+
items: z.array(fileRecordSchema),
|
|
42
|
+
next_cursor: z.string().nullable(),
|
|
43
|
+
limit: positiveInt,
|
|
44
|
+
});
|
|
45
|
+
export type FileRecordsListResponse = z.infer<typeof fileRecordsListResponseSchema>;
|
|
46
|
+
|
|
47
|
+
// ─── Single file detail ───────────────────────────────────────────────────────
|
|
48
|
+
|
|
49
|
+
export const fileRecordDetailResponseSchema = z.object({
|
|
50
|
+
file: fileRecordSchema,
|
|
51
|
+
});
|
|
52
|
+
export type FileRecordDetailResponse = z.infer<typeof fileRecordDetailResponseSchema>;
|
|
53
|
+
|
|
54
|
+
// ─── Move ────────────────────────────────────────────────────────────────────
|
|
55
|
+
|
|
56
|
+
export const fileMoveRequestSchema = z.object({
|
|
57
|
+
/** null = move to root, undefined = keep unchanged */
|
|
58
|
+
folder_id: nonEmptyString.nullable().optional(),
|
|
59
|
+
});
|
|
60
|
+
export type FileMoveRequest = z.infer<typeof fileMoveRequestSchema>;
|
|
61
|
+
|
|
62
|
+
// ─── Download URL ─────────────────────────────────────────────────────────────
|
|
63
|
+
|
|
64
|
+
export const fileDownloadUrlResponseSchema = z.object({
|
|
65
|
+
upload_id: nonEmptyString,
|
|
66
|
+
destination: uploadDestinationSchema,
|
|
67
|
+
download_url: z.string().url(),
|
|
68
|
+
expires_at: positiveInt,
|
|
69
|
+
});
|
|
70
|
+
export type FileDownloadUrlResponse = z.infer<typeof fileDownloadUrlResponseSchema>;
|
|
71
|
+
|
|
72
|
+
// ─── Delete ───────────────────────────────────────────────────────────────────
|
|
73
|
+
|
|
74
|
+
export const fileDeleteResponseSchema = z.object({
|
|
75
|
+
success: z.literal(true),
|
|
76
|
+
id: nonEmptyString,
|
|
77
|
+
permanent: z.boolean(),
|
|
78
|
+
});
|
|
79
|
+
export type FileDeleteResponse = z.infer<typeof fileDeleteResponseSchema>;
|
|
80
|
+
|
|
81
|
+
// ─── Restore ──────────────────────────────────────────────────────────────────
|
|
82
|
+
|
|
83
|
+
export const fileRestoreResponseSchema = z.object({
|
|
84
|
+
success: z.literal(true),
|
|
85
|
+
id: nonEmptyString,
|
|
86
|
+
});
|
|
87
|
+
export type FileRestoreResponse = z.infer<typeof fileRestoreResponseSchema>;
|
|
88
|
+
|
|
89
|
+
// ─── Update (rename) ──────────────────────────────────────────────────────────
|
|
90
|
+
|
|
91
|
+
export const fileUpdateRequestSchema = z.object({
|
|
92
|
+
filename: nonEmptyString,
|
|
93
|
+
});
|
|
94
|
+
export type FileUpdateRequest = z.infer<typeof fileUpdateRequestSchema>;
|
|
95
|
+
|
|
96
|
+
export const fileUpdateResponseSchema = z.object({
|
|
97
|
+
file: fileRecordSchema,
|
|
98
|
+
});
|
|
99
|
+
export type FileUpdateResponse = z.infer<typeof fileUpdateResponseSchema>;
|
package/src/folders.ts
CHANGED
|
@@ -1,84 +1,97 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { nonEmptyString, positiveInt } from './primitives';
|
|
3
|
-
|
|
4
|
-
// ─── Folder record ────────────────────────────────────────────────────────────
|
|
5
|
-
|
|
6
|
-
export const folderSchema = z.object({
|
|
7
|
-
id: nonEmptyString,
|
|
8
|
-
service_id: nonEmptyString,
|
|
9
|
-
user_id: nonEmptyString,
|
|
10
|
-
parent_id: nonEmptyString.nullable(),
|
|
11
|
-
name: nonEmptyString,
|
|
12
|
-
color_tag: z.string().nullable(),
|
|
13
|
-
is_trashed: z.boolean(),
|
|
14
|
-
trashed_at: positiveInt.nullable(),
|
|
15
|
-
created_at: positiveInt,
|
|
16
|
-
updated_at: positiveInt,
|
|
17
|
-
});
|
|
18
|
-
export type Folder = z.infer<typeof folderSchema>;
|
|
19
|
-
|
|
20
|
-
// ─── List ─────────────────────────────────────────────────────────────────────
|
|
21
|
-
|
|
22
|
-
export const folderListQuerySchema = z
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
export
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { nonEmptyString, positiveInt, FILES_MAX_LIMIT } from './primitives';
|
|
3
|
+
|
|
4
|
+
// ─── Folder record ────────────────────────────────────────────────────────────
|
|
5
|
+
|
|
6
|
+
export const folderSchema = z.object({
|
|
7
|
+
id: nonEmptyString,
|
|
8
|
+
service_id: nonEmptyString,
|
|
9
|
+
user_id: nonEmptyString,
|
|
10
|
+
parent_id: nonEmptyString.nullable(),
|
|
11
|
+
name: nonEmptyString,
|
|
12
|
+
color_tag: z.string().nullable(),
|
|
13
|
+
is_trashed: z.boolean(),
|
|
14
|
+
trashed_at: positiveInt.nullable(),
|
|
15
|
+
created_at: positiveInt,
|
|
16
|
+
updated_at: positiveInt,
|
|
17
|
+
});
|
|
18
|
+
export type Folder = z.infer<typeof folderSchema>;
|
|
19
|
+
|
|
20
|
+
// ─── List ─────────────────────────────────────────────────────────────────────
|
|
21
|
+
|
|
22
|
+
export const folderListQuerySchema = z
|
|
23
|
+
.object({
|
|
24
|
+
parent_id: nonEmptyString.nullable().optional(),
|
|
25
|
+
trashed: z.boolean().optional(),
|
|
26
|
+
is_trashed: z.boolean().optional(),
|
|
27
|
+
cursor: nonEmptyString.optional(),
|
|
28
|
+
limit: z.number().int().min(1).max(FILES_MAX_LIMIT).optional(),
|
|
29
|
+
})
|
|
30
|
+
.refine(
|
|
31
|
+
(v) => !(v.trashed !== undefined && v.is_trashed !== undefined),
|
|
32
|
+
{ message: 'Use either trashed or is_trashed, not both' }
|
|
33
|
+
);
|
|
34
|
+
export type FolderListQuery = z.infer<typeof folderListQuerySchema>;
|
|
35
|
+
|
|
36
|
+
export const folderListResponseSchema = z.object({
|
|
37
|
+
items: z.array(folderSchema),
|
|
38
|
+
next_cursor: z.string().nullable(),
|
|
39
|
+
limit: positiveInt,
|
|
40
|
+
});
|
|
41
|
+
export type FolderListResponse = z.infer<typeof folderListResponseSchema>;
|
|
42
|
+
|
|
43
|
+
// ─── Create ───────────────────────────────────────────────────────────────────
|
|
44
|
+
|
|
45
|
+
export const folderCreateRequestSchema = z.object({
|
|
46
|
+
name: nonEmptyString,
|
|
47
|
+
parent_id: nonEmptyString.optional(),
|
|
48
|
+
color_tag: z.string().optional(),
|
|
49
|
+
});
|
|
50
|
+
export type FolderCreateRequest = z.infer<typeof folderCreateRequestSchema>;
|
|
51
|
+
|
|
52
|
+
export const folderCreateResponseSchema = z.object({
|
|
53
|
+
folder: folderSchema,
|
|
54
|
+
});
|
|
55
|
+
export type FolderCreateResponse = z.infer<typeof folderCreateResponseSchema>;
|
|
56
|
+
|
|
57
|
+
// ─── Update ───────────────────────────────────────────────────────────────────
|
|
58
|
+
|
|
59
|
+
export const folderUpdateRequestSchema = z
|
|
60
|
+
.object({
|
|
61
|
+
name: nonEmptyString.optional(),
|
|
62
|
+
color_tag: z.string().nullable().optional(),
|
|
63
|
+
})
|
|
64
|
+
.refine((v) => v.name !== undefined || v.color_tag !== undefined, {
|
|
65
|
+
message: 'At least one of name or color_tag must be provided',
|
|
66
|
+
});
|
|
67
|
+
export type FolderUpdateRequest = z.infer<typeof folderUpdateRequestSchema>;
|
|
68
|
+
|
|
69
|
+
export const folderUpdateResponseSchema = z.object({
|
|
70
|
+
folder: folderSchema,
|
|
71
|
+
});
|
|
72
|
+
export type FolderUpdateResponse = z.infer<typeof folderUpdateResponseSchema>;
|
|
73
|
+
|
|
74
|
+
// ─── Delete ───────────────────────────────────────────────────────────────────
|
|
75
|
+
|
|
76
|
+
export const folderDeleteResponseSchema = z.object({
|
|
77
|
+
success: z.literal(true),
|
|
78
|
+
id: nonEmptyString,
|
|
79
|
+
permanent: z.boolean(),
|
|
80
|
+
folders_deleted: z.number().int().nonnegative().optional(),
|
|
81
|
+
});
|
|
82
|
+
export type FolderDeleteResponse = z.infer<typeof folderDeleteResponseSchema>;
|
|
83
|
+
|
|
84
|
+
// ─── Single folder detail ─────────────────────────────────────────────────────
|
|
85
|
+
|
|
86
|
+
export const folderDetailResponseSchema = z.object({
|
|
87
|
+
folder: folderSchema,
|
|
88
|
+
});
|
|
89
|
+
export type FolderDetailResponse = z.infer<typeof folderDetailResponseSchema>;
|
|
90
|
+
|
|
91
|
+
// ─── Restore ──────────────────────────────────────────────────────────────────
|
|
92
|
+
|
|
93
|
+
export const folderRestoreResponseSchema = z.object({
|
|
94
|
+
success: z.literal(true),
|
|
95
|
+
id: nonEmptyString,
|
|
96
|
+
});
|
|
97
|
+
export type FolderRestoreResponse = z.infer<typeof folderRestoreResponseSchema>;
|