@unisource/sdk 1.0.0 → 1.1.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +133 -48
- package/dist/index.d.mts +9 -83
- package/dist/index.mjs +5 -122
- package/dist/legacy-draft-7fqlx-KW.d.mts +84 -0
- package/dist/legacy-draft-D0hgtTqN.mjs +126 -0
- package/dist/v2/index.d.mts +212 -0
- package/dist/v2/index.mjs +194 -0
- package/package.json +19 -14
- package/src/client.ts +0 -700
- package/src/fileRecords.ts +0 -108
- package/src/folders.ts +0 -97
- package/src/index.ts +0 -289
- package/src/mainStorage.ts +0 -51
- package/src/primitives.ts +0 -43
- package/src/releases.ts +0 -236
- package/src/services.ts +0 -169
- package/src/shareLinks.ts +0 -109
- package/src/uploads.ts +0 -189
- package/src/v2.ts +0 -69
package/src/uploads.ts
DELETED
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { nonEmptyString, positiveInt, uploadDestinationSchema, uploadStatusSchema, FILES_DEFAULT_LIMIT, FILES_MAX_LIMIT } from './primitives';
|
|
3
|
-
|
|
4
|
-
// ─── Init: R2 ────────────────────────────────────────────────────────────────
|
|
5
|
-
|
|
6
|
-
export const uploadR2InitRequestSchema = z.object({
|
|
7
|
-
filename: nonEmptyString,
|
|
8
|
-
size: positiveInt,
|
|
9
|
-
mime_type: nonEmptyString,
|
|
10
|
-
folder_id: nonEmptyString.optional(),
|
|
11
|
-
is_main_storage: z.boolean().optional().default(false),
|
|
12
|
-
});
|
|
13
|
-
export type UploadR2InitRequest = z.input<typeof uploadR2InitRequestSchema>;
|
|
14
|
-
|
|
15
|
-
export const uploadR2InitResponseSchema = z.object({
|
|
16
|
-
upload_id: nonEmptyString,
|
|
17
|
-
destination: z.literal('r2'),
|
|
18
|
-
presigned_url: z.string().url(),
|
|
19
|
-
storage_key: nonEmptyString,
|
|
20
|
-
bucket: nonEmptyString,
|
|
21
|
-
expires_at: positiveInt,
|
|
22
|
-
});
|
|
23
|
-
export type UploadR2InitResponse = z.infer<typeof uploadR2InitResponseSchema>;
|
|
24
|
-
|
|
25
|
-
// ─── Init: Appwrite ───────────────────────────────────────────────────────────
|
|
26
|
-
|
|
27
|
-
export const uploadAppwriteInitRequestSchema = z.object({
|
|
28
|
-
filename: nonEmptyString,
|
|
29
|
-
size: positiveInt,
|
|
30
|
-
mime_type: nonEmptyString,
|
|
31
|
-
folder_id: nonEmptyString.optional(),
|
|
32
|
-
is_main_storage: z.boolean().optional().default(false),
|
|
33
|
-
});
|
|
34
|
-
export type UploadAppwriteInitRequest = z.input<typeof uploadAppwriteInitRequestSchema>;
|
|
35
|
-
|
|
36
|
-
export const uploadAppwriteInitResponseSchema = z.object({
|
|
37
|
-
upload_id: nonEmptyString,
|
|
38
|
-
destination: z.literal('appwrite'),
|
|
39
|
-
appwrite_endpoint: z.string().url(),
|
|
40
|
-
appwrite_project_id: nonEmptyString,
|
|
41
|
-
appwrite_bucket_id: nonEmptyString,
|
|
42
|
-
file_id: nonEmptyString,
|
|
43
|
-
expires_at: positiveInt,
|
|
44
|
-
/** Appwrite JWT to authenticate the client-side SDK upload. Only present for JWT-authenticated requests. */
|
|
45
|
-
jwt: nonEmptyString.optional(),
|
|
46
|
-
});
|
|
47
|
-
export type UploadAppwriteInitResponse = z.infer<typeof uploadAppwriteInitResponseSchema>;
|
|
48
|
-
|
|
49
|
-
// ─── Lifecycle ────────────────────────────────────────────────────────────────
|
|
50
|
-
|
|
51
|
-
export const uploadLifecycleRequestSchema = z.object({
|
|
52
|
-
upload_id: nonEmptyString,
|
|
53
|
-
is_main_storage: z.boolean().optional().default(false),
|
|
54
|
-
});
|
|
55
|
-
export type UploadLifecycleRequest = z.input<typeof uploadLifecycleRequestSchema>;
|
|
56
|
-
|
|
57
|
-
export const uploadCompleteResponseSchema = z.object({
|
|
58
|
-
success: z.literal(true),
|
|
59
|
-
upload_id: nonEmptyString,
|
|
60
|
-
status: z.literal('completed'),
|
|
61
|
-
});
|
|
62
|
-
export type UploadCompleteResponse = z.infer<typeof uploadCompleteResponseSchema>;
|
|
63
|
-
|
|
64
|
-
export const uploadFailResponseSchema = z.object({
|
|
65
|
-
success: z.literal(true),
|
|
66
|
-
upload_id: nonEmptyString,
|
|
67
|
-
status: z.literal('failed'),
|
|
68
|
-
});
|
|
69
|
-
export type UploadFailResponse = z.infer<typeof uploadFailResponseSchema>;
|
|
70
|
-
|
|
71
|
-
// ─── Multipart: Create ────────────────────────────────────────────────────────
|
|
72
|
-
|
|
73
|
-
export const multipartCreateRequestSchema = z.object({
|
|
74
|
-
filename: nonEmptyString,
|
|
75
|
-
size: positiveInt,
|
|
76
|
-
mime_type: nonEmptyString,
|
|
77
|
-
folder_id: nonEmptyString.optional(),
|
|
78
|
-
is_main_storage: z.boolean().optional().default(false),
|
|
79
|
-
});
|
|
80
|
-
export type MultipartCreateRequest = z.input<typeof multipartCreateRequestSchema>;
|
|
81
|
-
|
|
82
|
-
export const multipartCreateResponseSchema = z.object({
|
|
83
|
-
/** Internal UniSource upload record id. */
|
|
84
|
-
upload_id: nonEmptyString,
|
|
85
|
-
/** S3 (R2) multipart UploadId — required for every sign/complete/abort call. */
|
|
86
|
-
r2_upload_id: nonEmptyString,
|
|
87
|
-
/** R2 object key that the parts are being uploaded to. */
|
|
88
|
-
key: nonEmptyString,
|
|
89
|
-
bucket: nonEmptyString,
|
|
90
|
-
expires_at: positiveInt,
|
|
91
|
-
});
|
|
92
|
-
export type MultipartCreateResponse = z.infer<typeof multipartCreateResponseSchema>;
|
|
93
|
-
|
|
94
|
-
// ─── Multipart: Sign Part ─────────────────────────────────────────────────────
|
|
95
|
-
|
|
96
|
-
export const multipartSignPartQuerySchema = z.object({
|
|
97
|
-
upload_id: nonEmptyString,
|
|
98
|
-
part_number: z.coerce.number().int().min(1).max(10_000),
|
|
99
|
-
});
|
|
100
|
-
export type MultipartSignPartQuery = z.input<typeof multipartSignPartQuerySchema>;
|
|
101
|
-
|
|
102
|
-
export const multipartSignPartResponseSchema = z.object({
|
|
103
|
-
url: z.string().url(),
|
|
104
|
-
expires_at: positiveInt,
|
|
105
|
-
});
|
|
106
|
-
export type MultipartSignPartResponse = z.infer<typeof multipartSignPartResponseSchema>;
|
|
107
|
-
|
|
108
|
-
// ─── Multipart: List Parts ────────────────────────────────────────────────────
|
|
109
|
-
|
|
110
|
-
export const multipartListPartsQuerySchema = z.object({
|
|
111
|
-
upload_id: nonEmptyString,
|
|
112
|
-
});
|
|
113
|
-
export type MultipartListPartsQuery = z.input<typeof multipartListPartsQuerySchema>;
|
|
114
|
-
|
|
115
|
-
export const multipartPartSchema = z.object({
|
|
116
|
-
PartNumber: z.number().int().min(1).max(10_000),
|
|
117
|
-
ETag: nonEmptyString,
|
|
118
|
-
Size: z.number().int().nonnegative(),
|
|
119
|
-
});
|
|
120
|
-
export type MultipartPart = z.infer<typeof multipartPartSchema>;
|
|
121
|
-
|
|
122
|
-
export const multipartListPartsResponseSchema = z.object({
|
|
123
|
-
parts: z.array(multipartPartSchema),
|
|
124
|
-
});
|
|
125
|
-
export type MultipartListPartsResponse = z.infer<typeof multipartListPartsResponseSchema>;
|
|
126
|
-
|
|
127
|
-
// ─── Multipart: Complete ──────────────────────────────────────────────────────
|
|
128
|
-
|
|
129
|
-
export const multipartCompleteRequestSchema = z.object({
|
|
130
|
-
upload_id: nonEmptyString,
|
|
131
|
-
parts: z
|
|
132
|
-
.array(
|
|
133
|
-
z.object({
|
|
134
|
-
PartNumber: z.number().int().min(1).max(10_000),
|
|
135
|
-
ETag: nonEmptyString,
|
|
136
|
-
})
|
|
137
|
-
)
|
|
138
|
-
.min(1),
|
|
139
|
-
});
|
|
140
|
-
export type MultipartCompleteRequest = z.input<typeof multipartCompleteRequestSchema>;
|
|
141
|
-
|
|
142
|
-
export const multipartCompleteResponseSchema = uploadCompleteResponseSchema;
|
|
143
|
-
export type MultipartCompleteResponse = z.infer<typeof multipartCompleteResponseSchema>;
|
|
144
|
-
|
|
145
|
-
// ─── Multipart: Abort ─────────────────────────────────────────────────────────
|
|
146
|
-
|
|
147
|
-
export const multipartAbortRequestSchema = z.object({
|
|
148
|
-
upload_id: nonEmptyString,
|
|
149
|
-
});
|
|
150
|
-
export type MultipartAbortRequest = z.input<typeof multipartAbortRequestSchema>;
|
|
151
|
-
|
|
152
|
-
export const multipartAbortResponseSchema = uploadFailResponseSchema;
|
|
153
|
-
export type MultipartAbortResponse = z.infer<typeof multipartAbortResponseSchema>;
|
|
154
|
-
|
|
155
|
-
// ─── Admin: list uploads ──────────────────────────────────────────────────────
|
|
156
|
-
|
|
157
|
-
export { FILES_DEFAULT_LIMIT, FILES_MAX_LIMIT };
|
|
158
|
-
|
|
159
|
-
export const uploadTypeSchema = z.enum(['single', 'multipart']);
|
|
160
|
-
export type UploadType = z.infer<typeof uploadTypeSchema>;
|
|
161
|
-
|
|
162
|
-
/** Raw upload record — returned by admin `/files` endpoints. */
|
|
163
|
-
export const uploadRecordSchema = z.object({
|
|
164
|
-
id: nonEmptyString,
|
|
165
|
-
service_id: nonEmptyString,
|
|
166
|
-
user_id: nonEmptyString.nullable(),
|
|
167
|
-
filename: nonEmptyString,
|
|
168
|
-
size: positiveInt,
|
|
169
|
-
mime_type: nonEmptyString,
|
|
170
|
-
destination: uploadDestinationSchema,
|
|
171
|
-
status: uploadStatusSchema,
|
|
172
|
-
upload_type: uploadTypeSchema.optional(),
|
|
173
|
-
expires_at: positiveInt,
|
|
174
|
-
created_at: positiveInt,
|
|
175
|
-
updated_at: positiveInt,
|
|
176
|
-
});
|
|
177
|
-
export type UploadRecord = z.infer<typeof uploadRecordSchema>;
|
|
178
|
-
|
|
179
|
-
export const uploadsListResponseSchema = z.object({
|
|
180
|
-
items: z.array(uploadRecordSchema),
|
|
181
|
-
next_cursor: z.string().nullable(),
|
|
182
|
-
limit: positiveInt,
|
|
183
|
-
});
|
|
184
|
-
export type UploadsListResponse = z.infer<typeof uploadsListResponseSchema>;
|
|
185
|
-
|
|
186
|
-
export const uploadRecordDetailResponseSchema = z.object({
|
|
187
|
-
upload: uploadRecordSchema,
|
|
188
|
-
});
|
|
189
|
-
export type UploadRecordDetailResponse = z.infer<typeof uploadRecordDetailResponseSchema>;
|
package/src/v2.ts
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
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>;
|