@darco2903/cdn-api 1.0.7-beta.0 → 1.0.7-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.
Files changed (71) hide show
  1. package/README.md +49 -9
  2. package/dist/client.d.ts +1039 -0
  3. package/{src/client.ts → dist/client.js} +15 -18
  4. package/{src/common.ts → dist/common.d.ts} +4 -4
  5. package/dist/common.js +4 -0
  6. package/dist/consts.d.ts +5 -0
  7. package/{src/consts.ts → dist/consts.js} +4 -8
  8. package/dist/contract/auth.d.ts +35 -0
  9. package/{src/contract/auth.ts → dist/contract/auth.js} +18 -22
  10. package/dist/contract/endpoint.d.ts +396 -0
  11. package/{src/contract/endpoint.ts → dist/contract/endpoint.js} +42 -53
  12. package/dist/contract/index.d.ts +2039 -0
  13. package/{src/contract/index.ts → dist/contract/index.js} +22 -27
  14. package/dist/contract/key.d.ts +15 -0
  15. package/{src/contract/key.ts → dist/contract/key.js} +15 -19
  16. package/dist/contract/list.d.ts +134 -0
  17. package/{src/contract/list.ts → dist/contract/list.js} +28 -30
  18. package/dist/contract/record.d.ts +412 -0
  19. package/{src/contract/record.ts → dist/contract/record.js} +71 -82
  20. package/dist/contract/service.d.ts +240 -0
  21. package/{src/contract/service.ts → dist/contract/service.js} +33 -44
  22. package/dist/contract/stats.d.ts +32 -0
  23. package/{src/contract/stats.ts → dist/contract/stats.js} +34 -36
  24. package/dist/contract/upload.d.ts +790 -0
  25. package/{src/contract/upload.ts → dist/contract/upload.js} +78 -82
  26. package/{src/index.ts → dist/index.d.ts} +2 -2
  27. package/dist/index.js +2 -0
  28. package/dist/server.d.ts +10 -0
  29. package/dist/server.js +58 -0
  30. package/{src/socket/index.ts → dist/socket/index.d.ts} +2 -2
  31. package/dist/socket/index.js +2 -0
  32. package/dist/socket/interface/index.d.ts +5 -0
  33. package/dist/socket/interface/index.js +1 -0
  34. package/{src/socket/interface/template.ts → dist/socket/interface/template.d.ts} +6 -7
  35. package/dist/socket/interface/template.js +1 -0
  36. package/dist/socket/types.d.ts +3 -0
  37. package/dist/socket/types.js +1 -0
  38. package/dist/types/creds.d.ts +8 -0
  39. package/{src/types/creds.ts → dist/types/creds.js} +5 -7
  40. package/dist/types/endpoint.d.ts +25 -0
  41. package/{src/types/endpoint.ts → dist/types/endpoint.js} +12 -19
  42. package/{src/types/index.ts → dist/types/index.d.ts} +6 -6
  43. package/dist/types/index.js +6 -0
  44. package/dist/types/jwt.d.ts +128 -0
  45. package/dist/types/jwt.js +33 -0
  46. package/dist/types/record.d.ts +97 -0
  47. package/{src/types/record.ts → dist/types/record.js} +25 -35
  48. package/dist/types/stats.d.ts +15 -0
  49. package/{src/types/stats.ts → dist/types/stats.js} +6 -9
  50. package/dist/types/upload.d.ts +45 -0
  51. package/{src/types/upload.ts → dist/types/upload.js} +12 -18
  52. package/dist/types.d.ts +32 -0
  53. package/dist/types.js +27 -0
  54. package/dist/uploader.d.ts +1044 -0
  55. package/{src/uploader.ts → dist/uploader.js} +72 -99
  56. package/package.json +2 -2
  57. package/.gitattributes +0 -2
  58. package/.github/workflows/release.yml +0 -116
  59. package/TODO.md +0 -0
  60. package/prettier.config.js +0 -24
  61. package/src/server.ts +0 -89
  62. package/src/socket/interface/index.ts +0 -12
  63. package/src/socket/types.ts +0 -7
  64. package/src/types/jwt.ts +0 -78
  65. package/src/types.ts +0 -38
  66. package/tests/keys/private.pem +0 -5
  67. package/tests/keys/public.pem +0 -4
  68. package/tests/keys.ts +0 -11
  69. package/tests/tsconfig.json +0 -12
  70. package/tests/vitest/jwt.test.ts +0 -38
  71. package/tsconfig.json +0 -14
@@ -0,0 +1,412 @@
1
+ import z from "zod";
2
+ declare const _default: {
3
+ get: {
4
+ method: "GET";
5
+ path: "/record/:storage_id";
6
+ headers: z.ZodObject<{
7
+ authorization: z.ZodOptional<z.ZodString>;
8
+ }, "strip", z.ZodTypeAny, {
9
+ authorization?: string | undefined;
10
+ }, {
11
+ authorization?: string | undefined;
12
+ }>;
13
+ responses: {
14
+ 200: z.ZodType<{
15
+ type: "user" | "service" | "system";
16
+ filename: string;
17
+ active: boolean;
18
+ visible: boolean;
19
+ role: number;
20
+ size: number;
21
+ created_at: Date;
22
+ updated_at: Date;
23
+ storage_id: string;
24
+ mime_type: string;
25
+ endpoints: {
26
+ created_at: Date;
27
+ updated_at: Date;
28
+ endpoint: string;
29
+ }[];
30
+ user_id: string | null;
31
+ }, z.ZodTypeDef, {
32
+ type: "user" | "service" | "system";
33
+ filename: string;
34
+ active: boolean;
35
+ visible: boolean;
36
+ role: number;
37
+ size: number;
38
+ created_at: Date;
39
+ updated_at: Date;
40
+ storage_id: string;
41
+ mime_type: string;
42
+ endpoints: {
43
+ created_at: Date;
44
+ updated_at: Date;
45
+ endpoint: string;
46
+ }[];
47
+ user_id: string | null;
48
+ }>;
49
+ 401: z.ZodObject<{
50
+ code: z.ZodType<"UNAUTHORIZED", z.ZodTypeDef, "UNAUTHORIZED">;
51
+ error: z.ZodType<"Unauthorized", z.ZodTypeDef, "Unauthorized">;
52
+ name: z.ZodLiteral<"APIError">;
53
+ }, "strip", z.ZodTypeAny, {
54
+ code: "UNAUTHORIZED";
55
+ name: "APIError";
56
+ error: "Unauthorized";
57
+ }, {
58
+ code: "UNAUTHORIZED";
59
+ name: "APIError";
60
+ error: "Unauthorized";
61
+ }>;
62
+ 403: z.ZodObject<{
63
+ code: z.ZodType<"FORBIDDEN", z.ZodTypeDef, "FORBIDDEN">;
64
+ error: z.ZodType<"Forbidden", z.ZodTypeDef, "Forbidden">;
65
+ name: z.ZodLiteral<"APIError">;
66
+ }, "strip", z.ZodTypeAny, {
67
+ code: "FORBIDDEN";
68
+ name: "APIError";
69
+ error: "Forbidden";
70
+ }, {
71
+ code: "FORBIDDEN";
72
+ name: "APIError";
73
+ error: "Forbidden";
74
+ }>;
75
+ 404: z.ZodObject<{
76
+ code: z.ZodType<"NOT_FOUND", z.ZodTypeDef, "NOT_FOUND">;
77
+ error: z.ZodType<"Record not found", z.ZodTypeDef, "Record not found">;
78
+ name: z.ZodLiteral<"APIError">;
79
+ }, "strip", z.ZodTypeAny, {
80
+ code: "NOT_FOUND";
81
+ name: "APIError";
82
+ error: "Record not found";
83
+ }, {
84
+ code: "NOT_FOUND";
85
+ name: "APIError";
86
+ error: "Record not found";
87
+ }>;
88
+ 500: z.ZodObject<{
89
+ code: z.ZodType<"INTERNAL_SERVER_ERROR", z.ZodTypeDef, "INTERNAL_SERVER_ERROR">;
90
+ error: z.ZodType<string, z.ZodTypeDef, string>;
91
+ name: z.ZodLiteral<"APIError">;
92
+ }, "strip", z.ZodTypeAny, {
93
+ code: "INTERNAL_SERVER_ERROR";
94
+ name: "APIError";
95
+ error: string;
96
+ }, {
97
+ code: "INTERNAL_SERVER_ERROR";
98
+ name: "APIError";
99
+ error: string;
100
+ }>;
101
+ };
102
+ };
103
+ update: {
104
+ body: z.ZodUnion<[z.ZodObject<{
105
+ filename: z.ZodString;
106
+ role: z.ZodOptional<z.ZodNumber>;
107
+ active: z.ZodOptional<z.ZodBoolean>;
108
+ visible: z.ZodOptional<z.ZodBoolean>;
109
+ }, "strip", z.ZodTypeAny, {
110
+ filename: string;
111
+ active?: boolean | undefined;
112
+ visible?: boolean | undefined;
113
+ role?: number | undefined;
114
+ }, {
115
+ filename: string;
116
+ active?: boolean | undefined;
117
+ visible?: boolean | undefined;
118
+ role?: number | undefined;
119
+ }>, z.ZodObject<{
120
+ filename: z.ZodOptional<z.ZodString>;
121
+ role: z.ZodNumber;
122
+ active: z.ZodOptional<z.ZodBoolean>;
123
+ visible: z.ZodOptional<z.ZodBoolean>;
124
+ }, "strip", z.ZodTypeAny, {
125
+ role: number;
126
+ filename?: string | undefined;
127
+ active?: boolean | undefined;
128
+ visible?: boolean | undefined;
129
+ }, {
130
+ role: number;
131
+ filename?: string | undefined;
132
+ active?: boolean | undefined;
133
+ visible?: boolean | undefined;
134
+ }>, z.ZodObject<{
135
+ filename: z.ZodOptional<z.ZodString>;
136
+ role: z.ZodOptional<z.ZodNumber>;
137
+ active: z.ZodBoolean;
138
+ visible: z.ZodOptional<z.ZodBoolean>;
139
+ }, "strip", z.ZodTypeAny, {
140
+ active: boolean;
141
+ filename?: string | undefined;
142
+ visible?: boolean | undefined;
143
+ role?: number | undefined;
144
+ }, {
145
+ active: boolean;
146
+ filename?: string | undefined;
147
+ visible?: boolean | undefined;
148
+ role?: number | undefined;
149
+ }>, z.ZodObject<{
150
+ filename: z.ZodOptional<z.ZodString>;
151
+ role: z.ZodOptional<z.ZodNumber>;
152
+ active: z.ZodOptional<z.ZodBoolean>;
153
+ visible: z.ZodBoolean;
154
+ }, "strip", z.ZodTypeAny, {
155
+ visible: boolean;
156
+ filename?: string | undefined;
157
+ active?: boolean | undefined;
158
+ role?: number | undefined;
159
+ }, {
160
+ visible: boolean;
161
+ filename?: string | undefined;
162
+ active?: boolean | undefined;
163
+ role?: number | undefined;
164
+ }>]>;
165
+ method: "POST";
166
+ path: "/record/:storage_id";
167
+ headers: z.ZodObject<{
168
+ authorization: z.ZodOptional<z.ZodString>;
169
+ }, "strip", z.ZodTypeAny, {
170
+ authorization?: string | undefined;
171
+ }, {
172
+ authorization?: string | undefined;
173
+ }>;
174
+ responses: {
175
+ 200: z.ZodType<null, z.ZodTypeDef, null>;
176
+ 400: z.ZodObject<{
177
+ name: z.ZodLiteral<"ZodError">;
178
+ issues: z.ZodArray<z.ZodObject<{
179
+ path: z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodNumber]>, "many">;
180
+ message: z.ZodOptional<z.ZodString>;
181
+ code: z.ZodNativeEnum<{
182
+ invalid_type: "invalid_type";
183
+ invalid_literal: "invalid_literal";
184
+ custom: "custom";
185
+ invalid_union: "invalid_union";
186
+ invalid_union_discriminator: "invalid_union_discriminator";
187
+ invalid_enum_value: "invalid_enum_value";
188
+ unrecognized_keys: "unrecognized_keys";
189
+ invalid_arguments: "invalid_arguments";
190
+ invalid_return_type: "invalid_return_type";
191
+ invalid_date: "invalid_date";
192
+ invalid_string: "invalid_string";
193
+ too_small: "too_small";
194
+ too_big: "too_big";
195
+ invalid_intersection_types: "invalid_intersection_types";
196
+ not_multiple_of: "not_multiple_of";
197
+ not_finite: "not_finite";
198
+ }>;
199
+ }, "strip", z.ZodAny, z.objectOutputType<{
200
+ path: z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodNumber]>, "many">;
201
+ message: z.ZodOptional<z.ZodString>;
202
+ code: z.ZodNativeEnum<{
203
+ invalid_type: "invalid_type";
204
+ invalid_literal: "invalid_literal";
205
+ custom: "custom";
206
+ invalid_union: "invalid_union";
207
+ invalid_union_discriminator: "invalid_union_discriminator";
208
+ invalid_enum_value: "invalid_enum_value";
209
+ unrecognized_keys: "unrecognized_keys";
210
+ invalid_arguments: "invalid_arguments";
211
+ invalid_return_type: "invalid_return_type";
212
+ invalid_date: "invalid_date";
213
+ invalid_string: "invalid_string";
214
+ too_small: "too_small";
215
+ too_big: "too_big";
216
+ invalid_intersection_types: "invalid_intersection_types";
217
+ not_multiple_of: "not_multiple_of";
218
+ not_finite: "not_finite";
219
+ }>;
220
+ }, z.ZodAny, "strip">, z.objectInputType<{
221
+ path: z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodNumber]>, "many">;
222
+ message: z.ZodOptional<z.ZodString>;
223
+ code: z.ZodNativeEnum<{
224
+ invalid_type: "invalid_type";
225
+ invalid_literal: "invalid_literal";
226
+ custom: "custom";
227
+ invalid_union: "invalid_union";
228
+ invalid_union_discriminator: "invalid_union_discriminator";
229
+ invalid_enum_value: "invalid_enum_value";
230
+ unrecognized_keys: "unrecognized_keys";
231
+ invalid_arguments: "invalid_arguments";
232
+ invalid_return_type: "invalid_return_type";
233
+ invalid_date: "invalid_date";
234
+ invalid_string: "invalid_string";
235
+ too_small: "too_small";
236
+ too_big: "too_big";
237
+ invalid_intersection_types: "invalid_intersection_types";
238
+ not_multiple_of: "not_multiple_of";
239
+ not_finite: "not_finite";
240
+ }>;
241
+ }, z.ZodAny, "strip">>, "many">;
242
+ }, "strip", z.ZodTypeAny, {
243
+ name: "ZodError";
244
+ issues: z.objectOutputType<{
245
+ path: z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodNumber]>, "many">;
246
+ message: z.ZodOptional<z.ZodString>;
247
+ code: z.ZodNativeEnum<{
248
+ invalid_type: "invalid_type";
249
+ invalid_literal: "invalid_literal";
250
+ custom: "custom";
251
+ invalid_union: "invalid_union";
252
+ invalid_union_discriminator: "invalid_union_discriminator";
253
+ invalid_enum_value: "invalid_enum_value";
254
+ unrecognized_keys: "unrecognized_keys";
255
+ invalid_arguments: "invalid_arguments";
256
+ invalid_return_type: "invalid_return_type";
257
+ invalid_date: "invalid_date";
258
+ invalid_string: "invalid_string";
259
+ too_small: "too_small";
260
+ too_big: "too_big";
261
+ invalid_intersection_types: "invalid_intersection_types";
262
+ not_multiple_of: "not_multiple_of";
263
+ not_finite: "not_finite";
264
+ }>;
265
+ }, z.ZodAny, "strip">[];
266
+ }, {
267
+ name: "ZodError";
268
+ issues: z.objectInputType<{
269
+ path: z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodNumber]>, "many">;
270
+ message: z.ZodOptional<z.ZodString>;
271
+ code: z.ZodNativeEnum<{
272
+ invalid_type: "invalid_type";
273
+ invalid_literal: "invalid_literal";
274
+ custom: "custom";
275
+ invalid_union: "invalid_union";
276
+ invalid_union_discriminator: "invalid_union_discriminator";
277
+ invalid_enum_value: "invalid_enum_value";
278
+ unrecognized_keys: "unrecognized_keys";
279
+ invalid_arguments: "invalid_arguments";
280
+ invalid_return_type: "invalid_return_type";
281
+ invalid_date: "invalid_date";
282
+ invalid_string: "invalid_string";
283
+ too_small: "too_small";
284
+ too_big: "too_big";
285
+ invalid_intersection_types: "invalid_intersection_types";
286
+ not_multiple_of: "not_multiple_of";
287
+ not_finite: "not_finite";
288
+ }>;
289
+ }, z.ZodAny, "strip">[];
290
+ }>;
291
+ 401: z.ZodObject<{
292
+ code: z.ZodType<"UNAUTHORIZED", z.ZodTypeDef, "UNAUTHORIZED">;
293
+ error: z.ZodType<"Unauthorized", z.ZodTypeDef, "Unauthorized">;
294
+ name: z.ZodLiteral<"APIError">;
295
+ }, "strip", z.ZodTypeAny, {
296
+ code: "UNAUTHORIZED";
297
+ name: "APIError";
298
+ error: "Unauthorized";
299
+ }, {
300
+ code: "UNAUTHORIZED";
301
+ name: "APIError";
302
+ error: "Unauthorized";
303
+ }>;
304
+ 403: z.ZodObject<{
305
+ code: z.ZodType<"FORBIDDEN", z.ZodTypeDef, "FORBIDDEN">;
306
+ error: z.ZodType<"Forbidden", z.ZodTypeDef, "Forbidden">;
307
+ name: z.ZodLiteral<"APIError">;
308
+ }, "strip", z.ZodTypeAny, {
309
+ code: "FORBIDDEN";
310
+ name: "APIError";
311
+ error: "Forbidden";
312
+ }, {
313
+ code: "FORBIDDEN";
314
+ name: "APIError";
315
+ error: "Forbidden";
316
+ }>;
317
+ 404: z.ZodObject<{
318
+ code: z.ZodType<"NOT_FOUND", z.ZodTypeDef, "NOT_FOUND">;
319
+ error: z.ZodType<"Record not found", z.ZodTypeDef, "Record not found">;
320
+ name: z.ZodLiteral<"APIError">;
321
+ }, "strip", z.ZodTypeAny, {
322
+ code: "NOT_FOUND";
323
+ name: "APIError";
324
+ error: "Record not found";
325
+ }, {
326
+ code: "NOT_FOUND";
327
+ name: "APIError";
328
+ error: "Record not found";
329
+ }>;
330
+ 500: z.ZodObject<{
331
+ code: z.ZodType<"INTERNAL_SERVER_ERROR", z.ZodTypeDef, "INTERNAL_SERVER_ERROR">;
332
+ error: z.ZodType<string, z.ZodTypeDef, string>;
333
+ name: z.ZodLiteral<"APIError">;
334
+ }, "strip", z.ZodTypeAny, {
335
+ code: "INTERNAL_SERVER_ERROR";
336
+ name: "APIError";
337
+ error: string;
338
+ }, {
339
+ code: "INTERNAL_SERVER_ERROR";
340
+ name: "APIError";
341
+ error: string;
342
+ }>;
343
+ };
344
+ };
345
+ delete: {
346
+ method: "DELETE";
347
+ path: "/record/:storage_id";
348
+ headers: z.ZodObject<{
349
+ authorization: z.ZodOptional<z.ZodString>;
350
+ }, "strip", z.ZodTypeAny, {
351
+ authorization?: string | undefined;
352
+ }, {
353
+ authorization?: string | undefined;
354
+ }>;
355
+ responses: {
356
+ 200: z.ZodType<null, z.ZodTypeDef, null>;
357
+ 401: z.ZodObject<{
358
+ code: z.ZodType<"UNAUTHORIZED", z.ZodTypeDef, "UNAUTHORIZED">;
359
+ error: z.ZodType<"Unauthorized", z.ZodTypeDef, "Unauthorized">;
360
+ name: z.ZodLiteral<"APIError">;
361
+ }, "strip", z.ZodTypeAny, {
362
+ code: "UNAUTHORIZED";
363
+ name: "APIError";
364
+ error: "Unauthorized";
365
+ }, {
366
+ code: "UNAUTHORIZED";
367
+ name: "APIError";
368
+ error: "Unauthorized";
369
+ }>;
370
+ 403: z.ZodObject<{
371
+ code: z.ZodType<"FORBIDDEN", z.ZodTypeDef, "FORBIDDEN">;
372
+ error: z.ZodType<"Forbidden", z.ZodTypeDef, "Forbidden">;
373
+ name: z.ZodLiteral<"APIError">;
374
+ }, "strip", z.ZodTypeAny, {
375
+ code: "FORBIDDEN";
376
+ name: "APIError";
377
+ error: "Forbidden";
378
+ }, {
379
+ code: "FORBIDDEN";
380
+ name: "APIError";
381
+ error: "Forbidden";
382
+ }>;
383
+ 404: z.ZodObject<{
384
+ code: z.ZodType<"NOT_FOUND", z.ZodTypeDef, "NOT_FOUND">;
385
+ error: z.ZodType<"Record not found", z.ZodTypeDef, "Record not found">;
386
+ name: z.ZodLiteral<"APIError">;
387
+ }, "strip", z.ZodTypeAny, {
388
+ code: "NOT_FOUND";
389
+ name: "APIError";
390
+ error: "Record not found";
391
+ }, {
392
+ code: "NOT_FOUND";
393
+ name: "APIError";
394
+ error: "Record not found";
395
+ }>;
396
+ 500: z.ZodObject<{
397
+ code: z.ZodType<"INTERNAL_SERVER_ERROR", z.ZodTypeDef, "INTERNAL_SERVER_ERROR">;
398
+ error: z.ZodType<string, z.ZodTypeDef, string>;
399
+ name: z.ZodLiteral<"APIError">;
400
+ }, "strip", z.ZodTypeAny, {
401
+ code: "INTERNAL_SERVER_ERROR";
402
+ name: "APIError";
403
+ error: string;
404
+ }, {
405
+ code: "INTERNAL_SERVER_ERROR";
406
+ name: "APIError";
407
+ error: string;
408
+ }>;
409
+ };
410
+ };
411
+ };
412
+ export default _default;
@@ -1,82 +1,71 @@
1
- import { initContract, ZodErrorSchema } from "@ts-rest/core";
2
- import z from "zod";
3
- import { authHeaderSchema } from "@darco2903/auth-api/client";
4
- import { apiError, apiSuccess } from "../types.js";
5
- import { recordSchema } from "../types/index.js";
6
-
7
- const c = initContract();
8
-
9
- export default c.router({
10
- get: {
11
- method: "GET",
12
- path: "/record/:storage_id",
13
- headers: authHeaderSchema,
14
- responses: {
15
- 200: apiSuccess(recordSchema),
16
- 401: apiError(z.literal("UNAUTHORIZED"), z.literal("Unauthorized")),
17
- 403: apiError(z.literal("FORBIDDEN"), z.literal("Forbidden")),
18
- 404: apiError(
19
- z.literal("NOT_FOUND"),
20
- z.literal("Record not found")
21
- ),
22
- 500: apiError(z.literal("INTERNAL_SERVER_ERROR"), z.string()),
23
- },
24
- },
25
- update: {
26
- method: "POST",
27
- path: "/record/:storage_id",
28
- headers: authHeaderSchema,
29
- body: z.union([
30
- z.object({
31
- filename: z.string().max(128),
32
- role: z.number().gte(0).optional(),
33
- active: z.boolean().optional(),
34
- visible: z.boolean().optional(),
35
- }),
36
- z.object({
37
- filename: z.string().max(128).optional(),
38
- role: z.number().gte(0),
39
- active: z.boolean().optional(),
40
- visible: z.boolean().optional(),
41
- }),
42
- z.object({
43
- filename: z.string().max(128).optional(),
44
- role: z.number().gte(0).optional(),
45
- active: z.boolean(),
46
- visible: z.boolean().optional(),
47
- }),
48
- z.object({
49
- filename: z.string().max(128).optional(),
50
- role: z.number().gte(0).optional(),
51
- active: z.boolean().optional(),
52
- visible: z.boolean(),
53
- }),
54
- ]),
55
- responses: {
56
- 200: apiSuccess(z.null()),
57
- 400: ZodErrorSchema,
58
- 401: apiError(z.literal("UNAUTHORIZED"), z.literal("Unauthorized")),
59
- 403: apiError(z.literal("FORBIDDEN"), z.literal("Forbidden")),
60
- 404: apiError(
61
- z.literal("NOT_FOUND"),
62
- z.literal("Record not found")
63
- ),
64
- 500: apiError(z.literal("INTERNAL_SERVER_ERROR"), z.string()),
65
- },
66
- },
67
- delete: {
68
- method: "DELETE",
69
- path: "/record/:storage_id",
70
- headers: authHeaderSchema,
71
- responses: {
72
- 200: apiSuccess(z.null()),
73
- 401: apiError(z.literal("UNAUTHORIZED"), z.literal("Unauthorized")),
74
- 403: apiError(z.literal("FORBIDDEN"), z.literal("Forbidden")),
75
- 404: apiError(
76
- z.literal("NOT_FOUND"),
77
- z.literal("Record not found")
78
- ),
79
- 500: apiError(z.literal("INTERNAL_SERVER_ERROR"), z.string()),
80
- },
81
- },
82
- });
1
+ import { initContract, ZodErrorSchema } from "@ts-rest/core";
2
+ import z from "zod";
3
+ import { authHeaderSchema } from "@darco2903/auth-api/client";
4
+ import { apiError, apiSuccess } from "../types.js";
5
+ import { recordSchema } from "../types/index.js";
6
+ const c = initContract();
7
+ export default c.router({
8
+ get: {
9
+ method: "GET",
10
+ path: "/record/:storage_id",
11
+ headers: authHeaderSchema,
12
+ responses: {
13
+ 200: apiSuccess(recordSchema),
14
+ 401: apiError(z.literal("UNAUTHORIZED"), z.literal("Unauthorized")),
15
+ 403: apiError(z.literal("FORBIDDEN"), z.literal("Forbidden")),
16
+ 404: apiError(z.literal("NOT_FOUND"), z.literal("Record not found")),
17
+ 500: apiError(z.literal("INTERNAL_SERVER_ERROR"), z.string()),
18
+ },
19
+ },
20
+ update: {
21
+ method: "POST",
22
+ path: "/record/:storage_id",
23
+ headers: authHeaderSchema,
24
+ body: z.union([
25
+ z.object({
26
+ filename: z.string().max(128),
27
+ role: z.number().gte(0).optional(),
28
+ active: z.boolean().optional(),
29
+ visible: z.boolean().optional(),
30
+ }),
31
+ z.object({
32
+ filename: z.string().max(128).optional(),
33
+ role: z.number().gte(0),
34
+ active: z.boolean().optional(),
35
+ visible: z.boolean().optional(),
36
+ }),
37
+ z.object({
38
+ filename: z.string().max(128).optional(),
39
+ role: z.number().gte(0).optional(),
40
+ active: z.boolean(),
41
+ visible: z.boolean().optional(),
42
+ }),
43
+ z.object({
44
+ filename: z.string().max(128).optional(),
45
+ role: z.number().gte(0).optional(),
46
+ active: z.boolean().optional(),
47
+ visible: z.boolean(),
48
+ }),
49
+ ]),
50
+ responses: {
51
+ 200: apiSuccess(z.null()),
52
+ 400: ZodErrorSchema,
53
+ 401: apiError(z.literal("UNAUTHORIZED"), z.literal("Unauthorized")),
54
+ 403: apiError(z.literal("FORBIDDEN"), z.literal("Forbidden")),
55
+ 404: apiError(z.literal("NOT_FOUND"), z.literal("Record not found")),
56
+ 500: apiError(z.literal("INTERNAL_SERVER_ERROR"), z.string()),
57
+ },
58
+ },
59
+ delete: {
60
+ method: "DELETE",
61
+ path: "/record/:storage_id",
62
+ headers: authHeaderSchema,
63
+ responses: {
64
+ 200: apiSuccess(z.null()),
65
+ 401: apiError(z.literal("UNAUTHORIZED"), z.literal("Unauthorized")),
66
+ 403: apiError(z.literal("FORBIDDEN"), z.literal("Forbidden")),
67
+ 404: apiError(z.literal("NOT_FOUND"), z.literal("Record not found")),
68
+ 500: apiError(z.literal("INTERNAL_SERVER_ERROR"), z.string()),
69
+ },
70
+ },
71
+ });