@darco2903/cdn-api 1.0.7-beta.0 → 1.1.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 +49 -9
- package/dist/client.d.ts +1039 -0
- package/{src/client.ts → dist/client.js} +15 -18
- package/{src/common.ts → dist/common.d.ts} +4 -4
- package/dist/common.js +4 -0
- package/dist/consts.d.ts +5 -0
- package/{src/consts.ts → dist/consts.js} +4 -8
- package/dist/contract/auth.d.ts +35 -0
- package/{src/contract/auth.ts → dist/contract/auth.js} +18 -22
- package/dist/contract/endpoint.d.ts +396 -0
- package/{src/contract/endpoint.ts → dist/contract/endpoint.js} +42 -53
- package/dist/contract/index.d.ts +2039 -0
- package/{src/contract/index.ts → dist/contract/index.js} +22 -27
- package/dist/contract/key.d.ts +15 -0
- package/{src/contract/key.ts → dist/contract/key.js} +15 -19
- package/dist/contract/list.d.ts +134 -0
- package/{src/contract/list.ts → dist/contract/list.js} +28 -30
- package/dist/contract/record.d.ts +412 -0
- package/{src/contract/record.ts → dist/contract/record.js} +71 -82
- package/dist/contract/service.d.ts +240 -0
- package/{src/contract/service.ts → dist/contract/service.js} +33 -44
- package/dist/contract/stats.d.ts +32 -0
- package/{src/contract/stats.ts → dist/contract/stats.js} +34 -36
- package/dist/contract/upload.d.ts +790 -0
- package/{src/contract/upload.ts → dist/contract/upload.js} +78 -82
- package/{src/index.ts → dist/index.d.ts} +2 -2
- package/dist/index.js +2 -0
- package/dist/server.d.ts +10 -0
- package/dist/server.js +58 -0
- package/{src/socket/index.ts → dist/socket/index.d.ts} +2 -2
- package/dist/socket/index.js +2 -0
- package/dist/socket/interface/index.d.ts +5 -0
- package/dist/socket/interface/index.js +1 -0
- package/{src/socket/interface/template.ts → dist/socket/interface/template.d.ts} +6 -7
- package/dist/socket/interface/template.js +1 -0
- package/dist/socket/types.d.ts +3 -0
- package/dist/socket/types.js +1 -0
- package/dist/types/creds.d.ts +8 -0
- package/{src/types/creds.ts → dist/types/creds.js} +5 -7
- package/dist/types/endpoint.d.ts +25 -0
- package/{src/types/endpoint.ts → dist/types/endpoint.js} +12 -19
- package/{src/types/index.ts → dist/types/index.d.ts} +6 -6
- package/dist/types/index.js +6 -0
- package/dist/types/jwt.d.ts +128 -0
- package/dist/types/jwt.js +33 -0
- package/dist/types/record.d.ts +97 -0
- package/{src/types/record.ts → dist/types/record.js} +25 -35
- package/dist/types/stats.d.ts +15 -0
- package/{src/types/stats.ts → dist/types/stats.js} +6 -9
- package/dist/types/upload.d.ts +45 -0
- package/{src/types/upload.ts → dist/types/upload.js} +12 -18
- package/dist/types.d.ts +32 -0
- package/dist/types.js +27 -0
- package/dist/uploader.d.ts +1044 -0
- package/{src/uploader.ts → dist/uploader.js} +72 -99
- package/package.json +2 -2
- package/.gitattributes +0 -2
- package/.github/workflows/release.yml +0 -116
- package/TODO.md +0 -0
- package/prettier.config.js +0 -24
- package/src/server.ts +0 -89
- package/src/socket/interface/index.ts +0 -12
- package/src/socket/types.ts +0 -7
- package/src/types/jwt.ts +0 -78
- package/src/types.ts +0 -38
- package/tests/keys/private.pem +0 -5
- package/tests/keys/public.pem +0 -4
- package/tests/keys.ts +0 -11
- package/tests/tsconfig.json +0 -12
- package/tests/vitest/jwt.test.ts +0 -38
- package/tsconfig.json +0 -14
|
@@ -1,35 +1,25 @@
|
|
|
1
|
-
import z from "zod";
|
|
2
|
-
import { userPublicIdSchema } from "@darco2903/auth-api/client";
|
|
3
|
-
import { endpointPublicSchema, endpointSchema } from "./endpoint.js";
|
|
4
|
-
import { STORAGE_PUBLIC_ID_LENGTH } from "../consts.js";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
.
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
role: z.number().int().min(-1).max(255),
|
|
27
|
-
user_id: userPublicIdSchema.nullable(),
|
|
28
|
-
type: recordTypeSchema,
|
|
29
|
-
visible: z.boolean(),
|
|
30
|
-
active: z.boolean(),
|
|
31
|
-
created_at: z.coerce.date(),
|
|
32
|
-
updated_at: z.coerce.date(),
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
export type Record = z.infer<typeof recordSchema>;
|
|
1
|
+
import z from "zod";
|
|
2
|
+
import { userPublicIdSchema } from "@darco2903/auth-api/client";
|
|
3
|
+
import { endpointPublicSchema, endpointSchema } from "./endpoint.js";
|
|
4
|
+
import { STORAGE_PUBLIC_ID_LENGTH } from "../consts.js";
|
|
5
|
+
export const storagePublicIdSchema = z
|
|
6
|
+
.string()
|
|
7
|
+
.length(STORAGE_PUBLIC_ID_LENGTH);
|
|
8
|
+
export const recordPublicSchema = z.object({
|
|
9
|
+
storage_id: storagePublicIdSchema,
|
|
10
|
+
filename: z.string(),
|
|
11
|
+
size: z.number().int().gte(0),
|
|
12
|
+
mime_type: z.string(),
|
|
13
|
+
endpoints: z.array(endpointPublicSchema),
|
|
14
|
+
});
|
|
15
|
+
export const recordTypeSchema = z.enum(["service", "system", "user"]);
|
|
16
|
+
export const recordSchema = recordPublicSchema.extend({
|
|
17
|
+
endpoints: z.array(endpointSchema),
|
|
18
|
+
role: z.number().int().min(-1).max(255),
|
|
19
|
+
user_id: userPublicIdSchema.nullable(),
|
|
20
|
+
type: recordTypeSchema,
|
|
21
|
+
visible: z.boolean(),
|
|
22
|
+
active: z.boolean(),
|
|
23
|
+
created_at: z.coerce.date(),
|
|
24
|
+
updated_at: z.coerce.date(),
|
|
25
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import z from "zod";
|
|
2
|
+
export declare const statsGlobalSchema: z.ZodObject<{
|
|
3
|
+
record_count: z.ZodNumber;
|
|
4
|
+
total_size: z.ZodNumber;
|
|
5
|
+
max_size: z.ZodNumber;
|
|
6
|
+
}, "strip", z.ZodTypeAny, {
|
|
7
|
+
record_count: number;
|
|
8
|
+
total_size: number;
|
|
9
|
+
max_size: number;
|
|
10
|
+
}, {
|
|
11
|
+
record_count: number;
|
|
12
|
+
total_size: number;
|
|
13
|
+
max_size: number;
|
|
14
|
+
}>;
|
|
15
|
+
export type StatsGlobal = z.infer<typeof statsGlobalSchema>;
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import z from "zod";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
});
|
|
8
|
-
|
|
9
|
-
export type StatsGlobal = z.infer<typeof statsGlobalSchema>;
|
|
1
|
+
import z from "zod";
|
|
2
|
+
export const statsGlobalSchema = z.object({
|
|
3
|
+
record_count: z.number().int().gte(0),
|
|
4
|
+
total_size: z.number().int().gte(0),
|
|
5
|
+
max_size: z.number().int().gte(0),
|
|
6
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import z from "zod";
|
|
2
|
+
export declare const uploadDataSchema: z.ZodObject<{
|
|
3
|
+
filename: z.ZodString;
|
|
4
|
+
role: z.ZodNumber;
|
|
5
|
+
visible: z.ZodBoolean;
|
|
6
|
+
active: z.ZodBoolean;
|
|
7
|
+
}, "strip", z.ZodTypeAny, {
|
|
8
|
+
filename: string;
|
|
9
|
+
active: boolean;
|
|
10
|
+
visible: boolean;
|
|
11
|
+
role: number;
|
|
12
|
+
}, {
|
|
13
|
+
filename: string;
|
|
14
|
+
active: boolean;
|
|
15
|
+
visible: boolean;
|
|
16
|
+
role: number;
|
|
17
|
+
}>;
|
|
18
|
+
export type UploadData = z.infer<typeof uploadDataSchema>;
|
|
19
|
+
export declare const uploadInitSchema: z.ZodObject<{
|
|
20
|
+
filename: z.ZodString;
|
|
21
|
+
role: z.ZodNumber;
|
|
22
|
+
visible: z.ZodBoolean;
|
|
23
|
+
active: z.ZodBoolean;
|
|
24
|
+
} & {
|
|
25
|
+
size: z.ZodNumber;
|
|
26
|
+
mimeType: z.ZodString;
|
|
27
|
+
parts: z.ZodNumber;
|
|
28
|
+
}, "strip", z.ZodTypeAny, {
|
|
29
|
+
filename: string;
|
|
30
|
+
active: boolean;
|
|
31
|
+
visible: boolean;
|
|
32
|
+
role: number;
|
|
33
|
+
size: number;
|
|
34
|
+
mimeType: string;
|
|
35
|
+
parts: number;
|
|
36
|
+
}, {
|
|
37
|
+
filename: string;
|
|
38
|
+
active: boolean;
|
|
39
|
+
visible: boolean;
|
|
40
|
+
role: number;
|
|
41
|
+
size: number;
|
|
42
|
+
mimeType: string;
|
|
43
|
+
parts: number;
|
|
44
|
+
}>;
|
|
45
|
+
export type UploadInit = z.infer<typeof uploadInitSchema>;
|
|
@@ -1,18 +1,12 @@
|
|
|
1
|
-
import z from "zod";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
size: z.number().int().min(1),
|
|
14
|
-
mimeType: z.string().min(3).max(100),
|
|
15
|
-
parts: z.number().int().min(1),
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
export type UploadInit = z.infer<typeof uploadInitSchema>;
|
|
1
|
+
import z from "zod";
|
|
2
|
+
export const uploadDataSchema = z.object({
|
|
3
|
+
filename: z.string().min(3).max(100),
|
|
4
|
+
role: z.number().int().min(0).max(255),
|
|
5
|
+
visible: z.boolean(),
|
|
6
|
+
active: z.boolean(),
|
|
7
|
+
});
|
|
8
|
+
export const uploadInitSchema = uploadDataSchema.extend({
|
|
9
|
+
size: z.number().int().min(1),
|
|
10
|
+
mimeType: z.string().min(3).max(100),
|
|
11
|
+
parts: z.number().int().min(1),
|
|
12
|
+
});
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { z, type ZodType } from "zod";
|
|
2
|
+
export declare const apiSuccess: <T>(schema: ZodType<T>) => z.ZodType<T, z.ZodTypeDef, T>;
|
|
3
|
+
export declare const apiError: <T, U>(code: ZodType<T>, error: ZodType<U>) => z.ZodObject<{
|
|
4
|
+
code: z.ZodType<T, z.ZodTypeDef, T>;
|
|
5
|
+
error: z.ZodType<U, z.ZodTypeDef, U>;
|
|
6
|
+
name: z.ZodLiteral<"APIError">;
|
|
7
|
+
}, "strip", z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
|
|
8
|
+
code: z.ZodType<T, z.ZodTypeDef, T>;
|
|
9
|
+
error: z.ZodType<U, z.ZodTypeDef, U>;
|
|
10
|
+
name: z.ZodLiteral<"APIError">;
|
|
11
|
+
}>, any> extends infer T_1 ? { [k in keyof T_1]: T_1[k]; } : never, z.baseObjectInputType<{
|
|
12
|
+
code: z.ZodType<T, z.ZodTypeDef, T>;
|
|
13
|
+
error: z.ZodType<U, z.ZodTypeDef, U>;
|
|
14
|
+
name: z.ZodLiteral<"APIError">;
|
|
15
|
+
}> extends infer T_2 ? { [k_1 in keyof T_2]: T_2[k_1]; } : never>;
|
|
16
|
+
export declare const apiErrorData: <T, U, V>(code: ZodType<T>, error: ZodType<U>, data: ZodType<V>) => z.ZodObject<{
|
|
17
|
+
code: z.ZodType<T, z.ZodTypeDef, T>;
|
|
18
|
+
error: z.ZodType<U, z.ZodTypeDef, U>;
|
|
19
|
+
name: z.ZodLiteral<"APIError">;
|
|
20
|
+
data: z.ZodType<V, z.ZodTypeDef, V>;
|
|
21
|
+
}, "strip", z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{
|
|
22
|
+
code: z.ZodType<T, z.ZodTypeDef, T>;
|
|
23
|
+
error: z.ZodType<U, z.ZodTypeDef, U>;
|
|
24
|
+
name: z.ZodLiteral<"APIError">;
|
|
25
|
+
data: z.ZodType<V, z.ZodTypeDef, V>;
|
|
26
|
+
}>, any> extends infer T_1 ? { [k in keyof T_1]: T_1[k]; } : never, z.baseObjectInputType<{
|
|
27
|
+
code: z.ZodType<T, z.ZodTypeDef, T>;
|
|
28
|
+
error: z.ZodType<U, z.ZodTypeDef, U>;
|
|
29
|
+
name: z.ZodLiteral<"APIError">;
|
|
30
|
+
data: z.ZodType<V, z.ZodTypeDef, V>;
|
|
31
|
+
}> extends infer T_2 ? { [k_1 in keyof T_2]: T_2[k_1]; } : never>;
|
|
32
|
+
export declare function jsonStringAs<T extends z.ZodTypeAny>(schema: T): z.ZodEffects<z.ZodString, z.infer<T>>;
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export const apiSuccess = (schema) => schema;
|
|
3
|
+
export const apiError = (code, error) => z.object({
|
|
4
|
+
code,
|
|
5
|
+
error,
|
|
6
|
+
name: z.literal("APIError"),
|
|
7
|
+
});
|
|
8
|
+
export const apiErrorData = (code, error, data) => z.object({
|
|
9
|
+
code,
|
|
10
|
+
error,
|
|
11
|
+
name: z.literal("APIError"),
|
|
12
|
+
data,
|
|
13
|
+
});
|
|
14
|
+
export function jsonStringAs(schema) {
|
|
15
|
+
return z.string().transform((str, ctx) => {
|
|
16
|
+
try {
|
|
17
|
+
return schema.parse(JSON.parse(str));
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
ctx.addIssue({
|
|
21
|
+
code: z.ZodIssueCode.custom,
|
|
22
|
+
message: "Invalid JSON",
|
|
23
|
+
});
|
|
24
|
+
return z.NEVER;
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|