@unisource/sdk 0.1.2

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 ADDED
@@ -0,0 +1,23 @@
1
+ # tsdown-starter
2
+
3
+ A starter for creating a TypeScript package.
4
+
5
+ ## Development
6
+
7
+ - Install dependencies:
8
+
9
+ ```bash
10
+ npm install
11
+ ```
12
+
13
+ - Run the unit tests:
14
+
15
+ ```bash
16
+ npm run test
17
+ ```
18
+
19
+ - Build the library:
20
+
21
+ ```bash
22
+ npm run build
23
+ ```
@@ -0,0 +1,174 @@
1
+ import { z } from "zod";
2
+
3
+ //#region src/index.d.ts
4
+ declare const FILES_DEFAULT_LIMIT = 25;
5
+ declare const FILES_MAX_LIMIT = 100;
6
+ declare const uploadDestinationSchema: z.ZodEnum<{
7
+ appwrite: "appwrite";
8
+ r2: "r2";
9
+ }>;
10
+ type UploadDestination = z.infer<typeof uploadDestinationSchema>;
11
+ declare const uploadStatusSchema: z.ZodEnum<{
12
+ completed: "completed";
13
+ failed: "failed";
14
+ pending: "pending";
15
+ }>;
16
+ type UploadStatus = z.infer<typeof uploadStatusSchema>;
17
+ declare const apiErrorSchema: z.ZodObject<{
18
+ error: z.ZodString;
19
+ message: z.ZodString;
20
+ }, z.core.$strip>;
21
+ type ApiError = z.infer<typeof apiErrorSchema>;
22
+ declare const uploadR2InitRequestSchema: z.ZodObject<{
23
+ filename: z.ZodString;
24
+ size: z.ZodNumber;
25
+ mime_type: z.ZodString;
26
+ bucket: z.ZodOptional<z.ZodString>;
27
+ }, z.core.$strip>;
28
+ type UploadR2InitRequest = z.infer<typeof uploadR2InitRequestSchema>;
29
+ declare const uploadR2InitResponseSchema: z.ZodObject<{
30
+ upload_id: z.ZodString;
31
+ destination: z.ZodLiteral<"r2">;
32
+ presigned_url: z.ZodString;
33
+ storage_key: z.ZodString;
34
+ bucket: z.ZodString;
35
+ expires_at: z.ZodNumber;
36
+ }, z.core.$strip>;
37
+ type UploadR2InitResponse = z.infer<typeof uploadR2InitResponseSchema>;
38
+ declare const uploadAppwriteInitRequestSchema: z.ZodObject<{
39
+ filename: z.ZodString;
40
+ size: z.ZodNumber;
41
+ mime_type: z.ZodString;
42
+ }, z.core.$strip>;
43
+ type UploadAppwriteInitRequest = z.infer<typeof uploadAppwriteInitRequestSchema>;
44
+ declare const uploadAppwriteInitResponseSchema: z.ZodObject<{
45
+ upload_id: z.ZodString;
46
+ destination: z.ZodLiteral<"appwrite">;
47
+ appwrite_endpoint: z.ZodString;
48
+ appwrite_project_id: z.ZodString;
49
+ appwrite_bucket_id: z.ZodString;
50
+ file_id: z.ZodString;
51
+ expires_at: z.ZodNumber;
52
+ }, z.core.$strip>;
53
+ type UploadAppwriteInitResponse = z.infer<typeof uploadAppwriteInitResponseSchema>;
54
+ declare const uploadLifecycleRequestSchema: z.ZodObject<{
55
+ upload_id: z.ZodString;
56
+ }, z.core.$strip>;
57
+ type UploadLifecycleRequest = z.infer<typeof uploadLifecycleRequestSchema>;
58
+ declare const uploadCompleteResponseSchema: z.ZodObject<{
59
+ success: z.ZodLiteral<true>;
60
+ upload_id: z.ZodString;
61
+ status: z.ZodLiteral<"completed">;
62
+ }, z.core.$strip>;
63
+ type UploadCompleteResponse = z.infer<typeof uploadCompleteResponseSchema>;
64
+ declare const uploadFailResponseSchema: z.ZodObject<{
65
+ success: z.ZodLiteral<true>;
66
+ upload_id: z.ZodString;
67
+ status: z.ZodLiteral<"failed">;
68
+ }, z.core.$strip>;
69
+ type UploadFailResponse = z.infer<typeof uploadFailResponseSchema>;
70
+ declare const fileRecordSchema: z.ZodObject<{
71
+ id: z.ZodString;
72
+ filename: z.ZodString;
73
+ size: z.ZodNumber;
74
+ mime_type: z.ZodString;
75
+ destination: z.ZodEnum<{
76
+ appwrite: "appwrite";
77
+ r2: "r2";
78
+ }>;
79
+ storage_key: z.ZodString;
80
+ bucket: z.ZodString;
81
+ status: z.ZodEnum<{
82
+ completed: "completed";
83
+ failed: "failed";
84
+ pending: "pending";
85
+ }>;
86
+ expires_at: z.ZodNumber;
87
+ created_at: z.ZodNumber;
88
+ updated_at: z.ZodNumber;
89
+ }, z.core.$strip>;
90
+ type FileRecord = z.infer<typeof fileRecordSchema>;
91
+ declare const filesListQuerySchema: z.ZodObject<{
92
+ limit: z.ZodOptional<z.ZodNumber>;
93
+ cursor: z.ZodOptional<z.ZodString>;
94
+ destination: z.ZodOptional<z.ZodEnum<{
95
+ appwrite: "appwrite";
96
+ r2: "r2";
97
+ }>>;
98
+ status: z.ZodOptional<z.ZodEnum<{
99
+ completed: "completed";
100
+ failed: "failed";
101
+ pending: "pending";
102
+ }>>;
103
+ }, z.core.$strip>;
104
+ type FilesListQuery = z.infer<typeof filesListQuerySchema>;
105
+ declare const filesListResponseSchema: z.ZodObject<{
106
+ items: z.ZodArray<z.ZodObject<{
107
+ id: z.ZodString;
108
+ filename: z.ZodString;
109
+ size: z.ZodNumber;
110
+ mime_type: z.ZodString;
111
+ destination: z.ZodEnum<{
112
+ appwrite: "appwrite";
113
+ r2: "r2";
114
+ }>;
115
+ storage_key: z.ZodString;
116
+ bucket: z.ZodString;
117
+ status: z.ZodEnum<{
118
+ completed: "completed";
119
+ failed: "failed";
120
+ pending: "pending";
121
+ }>;
122
+ expires_at: z.ZodNumber;
123
+ created_at: z.ZodNumber;
124
+ updated_at: z.ZodNumber;
125
+ }, z.core.$strip>>;
126
+ next_cursor: z.ZodNullable<z.ZodString>;
127
+ limit: z.ZodNumber;
128
+ }, z.core.$strip>;
129
+ type FilesListResponse = z.infer<typeof filesListResponseSchema>;
130
+ declare const fileDetailsResponseSchema: z.ZodObject<{
131
+ file: z.ZodObject<{
132
+ id: z.ZodString;
133
+ filename: z.ZodString;
134
+ size: z.ZodNumber;
135
+ mime_type: z.ZodString;
136
+ destination: z.ZodEnum<{
137
+ appwrite: "appwrite";
138
+ r2: "r2";
139
+ }>;
140
+ storage_key: z.ZodString;
141
+ bucket: z.ZodString;
142
+ status: z.ZodEnum<{
143
+ completed: "completed";
144
+ failed: "failed";
145
+ pending: "pending";
146
+ }>;
147
+ expires_at: z.ZodNumber;
148
+ created_at: z.ZodNumber;
149
+ updated_at: z.ZodNumber;
150
+ }, z.core.$strip>;
151
+ }, z.core.$strip>;
152
+ type FileDetailsResponse = z.infer<typeof fileDetailsResponseSchema>;
153
+ declare const fileDownloadUrlResponseSchema: z.ZodObject<{
154
+ upload_id: z.ZodString;
155
+ destination: z.ZodEnum<{
156
+ appwrite: "appwrite";
157
+ r2: "r2";
158
+ }>;
159
+ download_url: z.ZodString;
160
+ expires_at: z.ZodNumber;
161
+ }, z.core.$strip>;
162
+ type FileDownloadUrlResponse = z.infer<typeof fileDownloadUrlResponseSchema>;
163
+ declare const fileDeleteResponseSchema: z.ZodObject<{
164
+ success: z.ZodLiteral<true>;
165
+ upload_id: z.ZodString;
166
+ destination: z.ZodEnum<{
167
+ appwrite: "appwrite";
168
+ r2: "r2";
169
+ }>;
170
+ storage_not_found: z.ZodBoolean;
171
+ }, z.core.$strip>;
172
+ type FileDeleteResponse = z.infer<typeof fileDeleteResponseSchema>;
173
+ //#endregion
174
+ export { ApiError, FILES_DEFAULT_LIMIT, FILES_MAX_LIMIT, FileDeleteResponse, FileDetailsResponse, FileDownloadUrlResponse, FileRecord, FilesListQuery, FilesListResponse, UploadAppwriteInitRequest, UploadAppwriteInitResponse, UploadCompleteResponse, UploadDestination, UploadFailResponse, UploadLifecycleRequest, UploadR2InitRequest, UploadR2InitResponse, UploadStatus, apiErrorSchema, fileDeleteResponseSchema, fileDetailsResponseSchema, fileDownloadUrlResponseSchema, fileRecordSchema, filesListQuerySchema, filesListResponseSchema, uploadAppwriteInitRequestSchema, uploadAppwriteInitResponseSchema, uploadCompleteResponseSchema, uploadDestinationSchema, uploadFailResponseSchema, uploadLifecycleRequestSchema, uploadR2InitRequestSchema, uploadR2InitResponseSchema, uploadStatusSchema };
@@ -0,0 +1,174 @@
1
+ import { z } from "zod";
2
+
3
+ //#region src/index.d.ts
4
+ declare const FILES_DEFAULT_LIMIT = 25;
5
+ declare const FILES_MAX_LIMIT = 100;
6
+ declare const uploadDestinationSchema: z.ZodEnum<{
7
+ appwrite: "appwrite";
8
+ r2: "r2";
9
+ }>;
10
+ type UploadDestination = z.infer<typeof uploadDestinationSchema>;
11
+ declare const uploadStatusSchema: z.ZodEnum<{
12
+ completed: "completed";
13
+ failed: "failed";
14
+ pending: "pending";
15
+ }>;
16
+ type UploadStatus = z.infer<typeof uploadStatusSchema>;
17
+ declare const apiErrorSchema: z.ZodObject<{
18
+ error: z.ZodString;
19
+ message: z.ZodString;
20
+ }, z.core.$strip>;
21
+ type ApiError = z.infer<typeof apiErrorSchema>;
22
+ declare const uploadR2InitRequestSchema: z.ZodObject<{
23
+ filename: z.ZodString;
24
+ size: z.ZodNumber;
25
+ mime_type: z.ZodString;
26
+ bucket: z.ZodOptional<z.ZodString>;
27
+ }, z.core.$strip>;
28
+ type UploadR2InitRequest = z.infer<typeof uploadR2InitRequestSchema>;
29
+ declare const uploadR2InitResponseSchema: z.ZodObject<{
30
+ upload_id: z.ZodString;
31
+ destination: z.ZodLiteral<"r2">;
32
+ presigned_url: z.ZodString;
33
+ storage_key: z.ZodString;
34
+ bucket: z.ZodString;
35
+ expires_at: z.ZodNumber;
36
+ }, z.core.$strip>;
37
+ type UploadR2InitResponse = z.infer<typeof uploadR2InitResponseSchema>;
38
+ declare const uploadAppwriteInitRequestSchema: z.ZodObject<{
39
+ filename: z.ZodString;
40
+ size: z.ZodNumber;
41
+ mime_type: z.ZodString;
42
+ }, z.core.$strip>;
43
+ type UploadAppwriteInitRequest = z.infer<typeof uploadAppwriteInitRequestSchema>;
44
+ declare const uploadAppwriteInitResponseSchema: z.ZodObject<{
45
+ upload_id: z.ZodString;
46
+ destination: z.ZodLiteral<"appwrite">;
47
+ appwrite_endpoint: z.ZodString;
48
+ appwrite_project_id: z.ZodString;
49
+ appwrite_bucket_id: z.ZodString;
50
+ file_id: z.ZodString;
51
+ expires_at: z.ZodNumber;
52
+ }, z.core.$strip>;
53
+ type UploadAppwriteInitResponse = z.infer<typeof uploadAppwriteInitResponseSchema>;
54
+ declare const uploadLifecycleRequestSchema: z.ZodObject<{
55
+ upload_id: z.ZodString;
56
+ }, z.core.$strip>;
57
+ type UploadLifecycleRequest = z.infer<typeof uploadLifecycleRequestSchema>;
58
+ declare const uploadCompleteResponseSchema: z.ZodObject<{
59
+ success: z.ZodLiteral<true>;
60
+ upload_id: z.ZodString;
61
+ status: z.ZodLiteral<"completed">;
62
+ }, z.core.$strip>;
63
+ type UploadCompleteResponse = z.infer<typeof uploadCompleteResponseSchema>;
64
+ declare const uploadFailResponseSchema: z.ZodObject<{
65
+ success: z.ZodLiteral<true>;
66
+ upload_id: z.ZodString;
67
+ status: z.ZodLiteral<"failed">;
68
+ }, z.core.$strip>;
69
+ type UploadFailResponse = z.infer<typeof uploadFailResponseSchema>;
70
+ declare const fileRecordSchema: z.ZodObject<{
71
+ id: z.ZodString;
72
+ filename: z.ZodString;
73
+ size: z.ZodNumber;
74
+ mime_type: z.ZodString;
75
+ destination: z.ZodEnum<{
76
+ appwrite: "appwrite";
77
+ r2: "r2";
78
+ }>;
79
+ storage_key: z.ZodString;
80
+ bucket: z.ZodString;
81
+ status: z.ZodEnum<{
82
+ completed: "completed";
83
+ failed: "failed";
84
+ pending: "pending";
85
+ }>;
86
+ expires_at: z.ZodNumber;
87
+ created_at: z.ZodNumber;
88
+ updated_at: z.ZodNumber;
89
+ }, z.core.$strip>;
90
+ type FileRecord = z.infer<typeof fileRecordSchema>;
91
+ declare const filesListQuerySchema: z.ZodObject<{
92
+ limit: z.ZodOptional<z.ZodNumber>;
93
+ cursor: z.ZodOptional<z.ZodString>;
94
+ destination: z.ZodOptional<z.ZodEnum<{
95
+ appwrite: "appwrite";
96
+ r2: "r2";
97
+ }>>;
98
+ status: z.ZodOptional<z.ZodEnum<{
99
+ completed: "completed";
100
+ failed: "failed";
101
+ pending: "pending";
102
+ }>>;
103
+ }, z.core.$strip>;
104
+ type FilesListQuery = z.infer<typeof filesListQuerySchema>;
105
+ declare const filesListResponseSchema: z.ZodObject<{
106
+ items: z.ZodArray<z.ZodObject<{
107
+ id: z.ZodString;
108
+ filename: z.ZodString;
109
+ size: z.ZodNumber;
110
+ mime_type: z.ZodString;
111
+ destination: z.ZodEnum<{
112
+ appwrite: "appwrite";
113
+ r2: "r2";
114
+ }>;
115
+ storage_key: z.ZodString;
116
+ bucket: z.ZodString;
117
+ status: z.ZodEnum<{
118
+ completed: "completed";
119
+ failed: "failed";
120
+ pending: "pending";
121
+ }>;
122
+ expires_at: z.ZodNumber;
123
+ created_at: z.ZodNumber;
124
+ updated_at: z.ZodNumber;
125
+ }, z.core.$strip>>;
126
+ next_cursor: z.ZodNullable<z.ZodString>;
127
+ limit: z.ZodNumber;
128
+ }, z.core.$strip>;
129
+ type FilesListResponse = z.infer<typeof filesListResponseSchema>;
130
+ declare const fileDetailsResponseSchema: z.ZodObject<{
131
+ file: z.ZodObject<{
132
+ id: z.ZodString;
133
+ filename: z.ZodString;
134
+ size: z.ZodNumber;
135
+ mime_type: z.ZodString;
136
+ destination: z.ZodEnum<{
137
+ appwrite: "appwrite";
138
+ r2: "r2";
139
+ }>;
140
+ storage_key: z.ZodString;
141
+ bucket: z.ZodString;
142
+ status: z.ZodEnum<{
143
+ completed: "completed";
144
+ failed: "failed";
145
+ pending: "pending";
146
+ }>;
147
+ expires_at: z.ZodNumber;
148
+ created_at: z.ZodNumber;
149
+ updated_at: z.ZodNumber;
150
+ }, z.core.$strip>;
151
+ }, z.core.$strip>;
152
+ type FileDetailsResponse = z.infer<typeof fileDetailsResponseSchema>;
153
+ declare const fileDownloadUrlResponseSchema: z.ZodObject<{
154
+ upload_id: z.ZodString;
155
+ destination: z.ZodEnum<{
156
+ appwrite: "appwrite";
157
+ r2: "r2";
158
+ }>;
159
+ download_url: z.ZodString;
160
+ expires_at: z.ZodNumber;
161
+ }, z.core.$strip>;
162
+ type FileDownloadUrlResponse = z.infer<typeof fileDownloadUrlResponseSchema>;
163
+ declare const fileDeleteResponseSchema: z.ZodObject<{
164
+ success: z.ZodLiteral<true>;
165
+ upload_id: z.ZodString;
166
+ destination: z.ZodEnum<{
167
+ appwrite: "appwrite";
168
+ r2: "r2";
169
+ }>;
170
+ storage_not_found: z.ZodBoolean;
171
+ }, z.core.$strip>;
172
+ type FileDeleteResponse = z.infer<typeof fileDeleteResponseSchema>;
173
+ //#endregion
174
+ export { ApiError, FILES_DEFAULT_LIMIT, FILES_MAX_LIMIT, FileDeleteResponse, FileDetailsResponse, FileDownloadUrlResponse, FileRecord, FilesListQuery, FilesListResponse, UploadAppwriteInitRequest, UploadAppwriteInitResponse, UploadCompleteResponse, UploadDestination, UploadFailResponse, UploadLifecycleRequest, UploadR2InitRequest, UploadR2InitResponse, UploadStatus, apiErrorSchema, fileDeleteResponseSchema, fileDetailsResponseSchema, fileDownloadUrlResponseSchema, fileRecordSchema, filesListQuerySchema, filesListResponseSchema, uploadAppwriteInitRequestSchema, uploadAppwriteInitResponseSchema, uploadCompleteResponseSchema, uploadDestinationSchema, uploadFailResponseSchema, uploadLifecycleRequestSchema, uploadR2InitRequestSchema, uploadR2InitResponseSchema, uploadStatusSchema };
package/dist/index.mjs ADDED
@@ -0,0 +1,94 @@
1
+ import { z } from "zod";
2
+ //#region src/index.ts
3
+ const FILES_DEFAULT_LIMIT = 25;
4
+ const FILES_MAX_LIMIT = 100;
5
+ const nonEmptyStringSchema = z.string().trim().min(1);
6
+ const positiveIntegerSchema = z.number().int().positive();
7
+ const uploadDestinationSchema = z.enum(["r2", "appwrite"]);
8
+ const uploadStatusSchema = z.enum([
9
+ "pending",
10
+ "completed",
11
+ "failed"
12
+ ]);
13
+ const apiErrorSchema = z.object({
14
+ error: nonEmptyStringSchema,
15
+ message: nonEmptyStringSchema
16
+ });
17
+ const uploadR2InitRequestSchema = z.object({
18
+ filename: nonEmptyStringSchema,
19
+ size: positiveIntegerSchema,
20
+ mime_type: nonEmptyStringSchema,
21
+ bucket: nonEmptyStringSchema.optional()
22
+ });
23
+ const uploadR2InitResponseSchema = z.object({
24
+ upload_id: nonEmptyStringSchema,
25
+ destination: z.literal("r2"),
26
+ presigned_url: z.string().url(),
27
+ storage_key: nonEmptyStringSchema,
28
+ bucket: nonEmptyStringSchema,
29
+ expires_at: positiveIntegerSchema
30
+ });
31
+ const uploadAppwriteInitRequestSchema = z.object({
32
+ filename: nonEmptyStringSchema,
33
+ size: positiveIntegerSchema,
34
+ mime_type: nonEmptyStringSchema
35
+ });
36
+ const uploadAppwriteInitResponseSchema = z.object({
37
+ upload_id: nonEmptyStringSchema,
38
+ destination: z.literal("appwrite"),
39
+ appwrite_endpoint: z.string().url(),
40
+ appwrite_project_id: nonEmptyStringSchema,
41
+ appwrite_bucket_id: nonEmptyStringSchema,
42
+ file_id: nonEmptyStringSchema,
43
+ expires_at: positiveIntegerSchema
44
+ });
45
+ const uploadLifecycleRequestSchema = z.object({ upload_id: nonEmptyStringSchema });
46
+ const uploadCompleteResponseSchema = z.object({
47
+ success: z.literal(true),
48
+ upload_id: nonEmptyStringSchema,
49
+ status: z.literal("completed")
50
+ });
51
+ const uploadFailResponseSchema = z.object({
52
+ success: z.literal(true),
53
+ upload_id: nonEmptyStringSchema,
54
+ status: z.literal("failed")
55
+ });
56
+ const fileRecordSchema = z.object({
57
+ id: nonEmptyStringSchema,
58
+ filename: nonEmptyStringSchema,
59
+ size: positiveIntegerSchema,
60
+ mime_type: nonEmptyStringSchema,
61
+ destination: uploadDestinationSchema,
62
+ storage_key: nonEmptyStringSchema,
63
+ bucket: nonEmptyStringSchema,
64
+ status: uploadStatusSchema,
65
+ expires_at: positiveIntegerSchema,
66
+ created_at: positiveIntegerSchema,
67
+ updated_at: positiveIntegerSchema
68
+ });
69
+ const filesListQuerySchema = z.object({
70
+ limit: z.number().int().min(1).max(100).optional(),
71
+ cursor: nonEmptyStringSchema.optional(),
72
+ destination: uploadDestinationSchema.optional(),
73
+ status: uploadStatusSchema.optional()
74
+ });
75
+ const filesListResponseSchema = z.object({
76
+ items: z.array(fileRecordSchema),
77
+ next_cursor: z.string().nullable(),
78
+ limit: z.number().int().min(1).max(100)
79
+ });
80
+ const fileDetailsResponseSchema = z.object({ file: fileRecordSchema });
81
+ const fileDownloadUrlResponseSchema = z.object({
82
+ upload_id: nonEmptyStringSchema,
83
+ destination: uploadDestinationSchema,
84
+ download_url: z.string().url(),
85
+ expires_at: positiveIntegerSchema
86
+ });
87
+ const fileDeleteResponseSchema = z.object({
88
+ success: z.literal(true),
89
+ upload_id: nonEmptyStringSchema,
90
+ destination: uploadDestinationSchema,
91
+ storage_not_found: z.boolean()
92
+ });
93
+ //#endregion
94
+ export { FILES_DEFAULT_LIMIT, FILES_MAX_LIMIT, apiErrorSchema, fileDeleteResponseSchema, fileDetailsResponseSchema, fileDownloadUrlResponseSchema, fileRecordSchema, filesListQuerySchema, filesListResponseSchema, uploadAppwriteInitRequestSchema, uploadAppwriteInitResponseSchema, uploadCompleteResponseSchema, uploadDestinationSchema, uploadFailResponseSchema, uploadLifecycleRequestSchema, uploadR2InitRequestSchema, uploadR2InitResponseSchema, uploadStatusSchema };
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@unisource/sdk",
3
+ "private": false,
4
+ "type": "module",
5
+ "version": "0.1.2",
6
+ "description": "Wspolne kontrakty danych dla backendu i frontendu UniSource.",
7
+ "license": "MIT",
8
+ "publishConfig": {
9
+ "access": "public"
10
+ },
11
+ "exports": {
12
+ ".": "./dist/index.mjs",
13
+ "./package.json": "./package.json"
14
+ },
15
+ "types": "./src/index.ts",
16
+ "files": [
17
+ "dist",
18
+ "src"
19
+ ],
20
+ "devDependencies": {
21
+ "@types/node": "^25.5.0",
22
+ "@typescript/native-preview": "7.0.0-dev.20260328.1",
23
+ "tsdown": "^0.21.7",
24
+ "typescript": "^6.0.2",
25
+ "vitest": "^4.1.2"
26
+ },
27
+ "dependencies": {
28
+ "zod": "^4.3.6"
29
+ },
30
+ "scripts": {
31
+ "build": "tsdown && node -e \"const fs=require('node:fs'); if (fs.existsSync('dist/index.d.mts')) fs.copyFileSync('dist/index.d.mts','dist/index.d.ts');\"",
32
+ "dev": "tsdown --watch",
33
+ "test": "vitest",
34
+ "typecheck": "tsc --noEmit"
35
+ }
36
+ }
package/src/index.ts ADDED
@@ -0,0 +1,125 @@
1
+ import { z } from 'zod';
2
+
3
+ export const FILES_DEFAULT_LIMIT = 25;
4
+ export const FILES_MAX_LIMIT = 100;
5
+
6
+ const nonEmptyStringSchema = z.string().trim().min(1);
7
+ const positiveIntegerSchema = z.number().int().positive();
8
+
9
+ export const uploadDestinationSchema = z.enum(['r2', 'appwrite']);
10
+ export type UploadDestination = z.infer<typeof uploadDestinationSchema>;
11
+
12
+ export const uploadStatusSchema = z.enum(['pending', 'completed', 'failed']);
13
+ export type UploadStatus = z.infer<typeof uploadStatusSchema>;
14
+
15
+ export const apiErrorSchema = z.object({
16
+ error: nonEmptyStringSchema,
17
+ message: nonEmptyStringSchema,
18
+ });
19
+ export type ApiError = z.infer<typeof apiErrorSchema>;
20
+
21
+ export const uploadR2InitRequestSchema = z.object({
22
+ filename: nonEmptyStringSchema,
23
+ size: positiveIntegerSchema,
24
+ mime_type: nonEmptyStringSchema,
25
+ bucket: nonEmptyStringSchema.optional(),
26
+ });
27
+ export type UploadR2InitRequest = z.infer<typeof uploadR2InitRequestSchema>;
28
+
29
+ export const uploadR2InitResponseSchema = z.object({
30
+ upload_id: nonEmptyStringSchema,
31
+ destination: z.literal('r2'),
32
+ presigned_url: z.string().url(),
33
+ storage_key: nonEmptyStringSchema,
34
+ bucket: nonEmptyStringSchema,
35
+ expires_at: positiveIntegerSchema,
36
+ });
37
+ export type UploadR2InitResponse = z.infer<typeof uploadR2InitResponseSchema>;
38
+
39
+ export const uploadAppwriteInitRequestSchema = z.object({
40
+ filename: nonEmptyStringSchema,
41
+ size: positiveIntegerSchema,
42
+ mime_type: nonEmptyStringSchema,
43
+ });
44
+ export type UploadAppwriteInitRequest = z.infer<typeof uploadAppwriteInitRequestSchema>;
45
+
46
+ export const uploadAppwriteInitResponseSchema = z.object({
47
+ upload_id: nonEmptyStringSchema,
48
+ destination: z.literal('appwrite'),
49
+ appwrite_endpoint: z.string().url(),
50
+ appwrite_project_id: nonEmptyStringSchema,
51
+ appwrite_bucket_id: nonEmptyStringSchema,
52
+ file_id: nonEmptyStringSchema,
53
+ expires_at: positiveIntegerSchema,
54
+ });
55
+ export type UploadAppwriteInitResponse = z.infer<typeof uploadAppwriteInitResponseSchema>;
56
+
57
+ export const uploadLifecycleRequestSchema = z.object({
58
+ upload_id: nonEmptyStringSchema,
59
+ });
60
+ export type UploadLifecycleRequest = z.infer<typeof uploadLifecycleRequestSchema>;
61
+
62
+ export const uploadCompleteResponseSchema = z.object({
63
+ success: z.literal(true),
64
+ upload_id: nonEmptyStringSchema,
65
+ status: z.literal('completed'),
66
+ });
67
+ export type UploadCompleteResponse = z.infer<typeof uploadCompleteResponseSchema>;
68
+
69
+ export const uploadFailResponseSchema = z.object({
70
+ success: z.literal(true),
71
+ upload_id: nonEmptyStringSchema,
72
+ status: z.literal('failed'),
73
+ });
74
+ export type UploadFailResponse = z.infer<typeof uploadFailResponseSchema>;
75
+
76
+ export const fileRecordSchema = z.object({
77
+ id: nonEmptyStringSchema,
78
+ filename: nonEmptyStringSchema,
79
+ size: positiveIntegerSchema,
80
+ mime_type: nonEmptyStringSchema,
81
+ destination: uploadDestinationSchema,
82
+ storage_key: nonEmptyStringSchema,
83
+ bucket: nonEmptyStringSchema,
84
+ status: uploadStatusSchema,
85
+ expires_at: positiveIntegerSchema,
86
+ created_at: positiveIntegerSchema,
87
+ updated_at: positiveIntegerSchema,
88
+ });
89
+ export type FileRecord = z.infer<typeof fileRecordSchema>;
90
+
91
+ export const filesListQuerySchema = z.object({
92
+ limit: z.number().int().min(1).max(FILES_MAX_LIMIT).optional(),
93
+ cursor: nonEmptyStringSchema.optional(),
94
+ destination: uploadDestinationSchema.optional(),
95
+ status: uploadStatusSchema.optional(),
96
+ });
97
+ export type FilesListQuery = z.infer<typeof filesListQuerySchema>;
98
+
99
+ export const filesListResponseSchema = z.object({
100
+ items: z.array(fileRecordSchema),
101
+ next_cursor: z.string().nullable(),
102
+ limit: z.number().int().min(1).max(FILES_MAX_LIMIT),
103
+ });
104
+ export type FilesListResponse = z.infer<typeof filesListResponseSchema>;
105
+
106
+ export const fileDetailsResponseSchema = z.object({
107
+ file: fileRecordSchema,
108
+ });
109
+ export type FileDetailsResponse = z.infer<typeof fileDetailsResponseSchema>;
110
+
111
+ export const fileDownloadUrlResponseSchema = z.object({
112
+ upload_id: nonEmptyStringSchema,
113
+ destination: uploadDestinationSchema,
114
+ download_url: z.string().url(),
115
+ expires_at: positiveIntegerSchema,
116
+ });
117
+ export type FileDownloadUrlResponse = z.infer<typeof fileDownloadUrlResponseSchema>;
118
+
119
+ export const fileDeleteResponseSchema = z.object({
120
+ success: z.literal(true),
121
+ upload_id: nonEmptyStringSchema,
122
+ destination: uploadDestinationSchema,
123
+ storage_not_found: z.boolean(),
124
+ });
125
+ export type FileDeleteResponse = z.infer<typeof fileDeleteResponseSchema>;