@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.
- 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,82 +1,78 @@
|
|
|
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, jsonStringAs } from "../types.js";
|
|
5
|
-
import { uploadDataSchema, uploadInitSchema } from "../types/index.js";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
77
|
-
|
|
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, jsonStringAs } from "../types.js";
|
|
5
|
+
import { uploadDataSchema, uploadInitSchema } from "../types/index.js";
|
|
6
|
+
const c = initContract();
|
|
7
|
+
export default c.router({
|
|
8
|
+
upload: {
|
|
9
|
+
method: "POST",
|
|
10
|
+
path: "/upload",
|
|
11
|
+
headers: authHeaderSchema,
|
|
12
|
+
contentType: "multipart/form-data",
|
|
13
|
+
body: z.object({
|
|
14
|
+
file: z.any(),
|
|
15
|
+
data: jsonStringAs(uploadDataSchema),
|
|
16
|
+
}),
|
|
17
|
+
responses: {
|
|
18
|
+
200: apiSuccess(z.null()),
|
|
19
|
+
400: z.union([
|
|
20
|
+
ZodErrorSchema,
|
|
21
|
+
apiError(z.literal("BAD_REQUEST"), z.string()),
|
|
22
|
+
]),
|
|
23
|
+
401: apiError(z.literal("UNAUTHORIZED"), z.literal("Unauthorized")),
|
|
24
|
+
403: apiError(z.literal("FORBIDDEN"), z.literal("Forbidden")),
|
|
25
|
+
500: apiError(z.literal("INTERNAL_SERVER_ERROR"), z.string()),
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
uploadInit: {
|
|
29
|
+
method: "POST",
|
|
30
|
+
path: "/upload/init",
|
|
31
|
+
body: uploadInitSchema,
|
|
32
|
+
responses: {
|
|
33
|
+
200: apiSuccess(z.object({
|
|
34
|
+
uploadId: z.string(),
|
|
35
|
+
})),
|
|
36
|
+
400: z.union([
|
|
37
|
+
ZodErrorSchema,
|
|
38
|
+
apiError(z.literal("BAD_REQUEST"), z.string()),
|
|
39
|
+
]),
|
|
40
|
+
401: apiError(z.literal("UNAUTHORIZED"), z.literal("Unauthorized")),
|
|
41
|
+
403: apiError(z.literal("FORBIDDEN"), z.literal("Forbidden")),
|
|
42
|
+
500: apiError(z.literal("INTERNAL_SERVER_ERROR"), z.string()),
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
uploadPart: {
|
|
46
|
+
method: "POST",
|
|
47
|
+
path: "/upload/part/:upload_id/:part",
|
|
48
|
+
contentType: "multipart/form-data",
|
|
49
|
+
body: z.object({
|
|
50
|
+
file: z.any(),
|
|
51
|
+
}),
|
|
52
|
+
responses: {
|
|
53
|
+
200: apiSuccess(z.null()),
|
|
54
|
+
400: z.union([
|
|
55
|
+
ZodErrorSchema,
|
|
56
|
+
apiError(z.literal("BAD_REQUEST"), z.string()),
|
|
57
|
+
]),
|
|
58
|
+
401: apiError(z.literal("UNAUTHORIZED"), z.literal("Unauthorized")),
|
|
59
|
+
403: apiError(z.literal("FORBIDDEN"), z.literal("Forbidden")),
|
|
60
|
+
404: apiError(z.literal("NOT_FOUND"), z.string()),
|
|
61
|
+
409: apiError(z.literal("CONFLICT"), z.string()),
|
|
62
|
+
500: apiError(z.literal("INTERNAL_SERVER_ERROR"), z.string()),
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
uploadEnd: {
|
|
66
|
+
method: "POST",
|
|
67
|
+
path: "/upload/end/:upload_id",
|
|
68
|
+
body: z.undefined(),
|
|
69
|
+
responses: {
|
|
70
|
+
200: apiSuccess(z.null()),
|
|
71
|
+
400: ZodErrorSchema,
|
|
72
|
+
401: apiError(z.literal("UNAUTHORIZED"), z.literal("Unauthorized")),
|
|
73
|
+
403: apiError(z.literal("FORBIDDEN"), z.literal("Forbidden")),
|
|
74
|
+
404: apiError(z.literal("NOT_FOUND"), z.string()),
|
|
75
|
+
500: apiError(z.literal("INTERNAL_SERVER_ERROR"), z.string()),
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
});
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from "./client.js";
|
|
2
|
-
export * from "./server.js";
|
|
1
|
+
export * from "./client.js";
|
|
2
|
+
export * from "./server.js";
|
package/dist/index.js
ADDED
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from "./common.js";
|
|
2
|
+
import { ResultAsync } from "neverthrow";
|
|
3
|
+
import type { Time } from "@darco2903/secondthought";
|
|
4
|
+
import { type JWTVerifyError, type CdnFeedbackTokenData, type CdnAssetTokenDataDecoded, type JWTSignError } from "./common.js";
|
|
5
|
+
export declare function JWTVerify(token: string, pubKey: string): ResultAsync<CdnAssetTokenDataDecoded, JWTVerifyError>;
|
|
6
|
+
/**
|
|
7
|
+
* Sign a JWT token with the given payload and private key, with the specified expiration time.
|
|
8
|
+
* @param expiresIn Expiration time in seconds or a Time object.
|
|
9
|
+
*/
|
|
10
|
+
export declare function JWTSign(payload: CdnFeedbackTokenData, privKey: string, expiresIn: number | Time): ResultAsync<string, JWTSignError>;
|
package/dist/server.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
export * from "./common.js";
|
|
2
|
+
import jwt from "jsonwebtoken";
|
|
3
|
+
import { ResultAsync } from "neverthrow";
|
|
4
|
+
import { cdnAssetTokenDataDecodedSchema, } from "./common.js";
|
|
5
|
+
import { JWT_ALGORITHM } from "./consts.js";
|
|
6
|
+
export function JWTVerify(token, pubKey) {
|
|
7
|
+
return ResultAsync.fromPromise(new Promise((resolve, reject) => {
|
|
8
|
+
jwt.verify(token, pubKey, { algorithms: [JWT_ALGORITHM] }, (e, decoded) => {
|
|
9
|
+
if (e) {
|
|
10
|
+
reject({
|
|
11
|
+
name: e.name,
|
|
12
|
+
message: e.message,
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
else if (decoded === undefined) {
|
|
16
|
+
reject({
|
|
17
|
+
name: "InvalidToken",
|
|
18
|
+
message: "Token is undefined",
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
const res = cdnAssetTokenDataDecodedSchema.safeParse(decoded);
|
|
23
|
+
if (res.success) {
|
|
24
|
+
resolve(res.data);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
reject({
|
|
28
|
+
name: "InvalidTokenData",
|
|
29
|
+
message: "Invalid token data",
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}), (e) => e);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Sign a JWT token with the given payload and private key, with the specified expiration time.
|
|
38
|
+
* @param expiresIn Expiration time in seconds or a Time object.
|
|
39
|
+
*/
|
|
40
|
+
export function JWTSign(payload, privKey, expiresIn) {
|
|
41
|
+
const expiresInSec = typeof expiresIn === "number" ? expiresIn : expiresIn.toSecond().time;
|
|
42
|
+
return ResultAsync.fromPromise(new Promise((resolve, reject) => {
|
|
43
|
+
jwt.sign(payload, privKey, {
|
|
44
|
+
algorithm: JWT_ALGORITHM,
|
|
45
|
+
expiresIn: expiresInSec,
|
|
46
|
+
}, (e, token) => {
|
|
47
|
+
if (e || token === undefined) {
|
|
48
|
+
reject({
|
|
49
|
+
name: "JsonWebTokenError",
|
|
50
|
+
message: e?.message ?? "Failed to sign token",
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
resolve(token);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}), (e) => e);
|
|
58
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from "./interface/index.js";
|
|
2
|
-
export * from "./types.js";
|
|
1
|
+
export * from "./interface/index.js";
|
|
2
|
+
export * from "./types.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
export interface SocketClientToServerTemplate {
|
|
2
|
-
ping: (message: string, callback: (message: string) => void) => void;
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
1
|
+
export interface SocketClientToServerTemplate {
|
|
2
|
+
ping: (message: string, callback: (message: string) => void) => void;
|
|
3
|
+
}
|
|
4
|
+
export interface SocketServerToClientTemplate {
|
|
5
|
+
pong: (message: string) => void;
|
|
6
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import z from "zod";
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
authorization: jwtSchema,
|
|
7
|
-
});
|
|
1
|
+
import z from "zod";
|
|
2
|
+
const jwtSchema = z.string().startsWith("Bearer ");
|
|
3
|
+
export const cdnHeaderSchema = z.object({
|
|
4
|
+
authorization: jwtSchema,
|
|
5
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import z from "zod";
|
|
2
|
+
export declare const endpointPathSchema: z.ZodString;
|
|
3
|
+
export declare const endpointPublicSchema: z.ZodObject<{
|
|
4
|
+
endpoint: z.ZodString;
|
|
5
|
+
}, "strip", z.ZodTypeAny, {
|
|
6
|
+
endpoint: string;
|
|
7
|
+
}, {
|
|
8
|
+
endpoint: string;
|
|
9
|
+
}>;
|
|
10
|
+
export type EndpointPublic = z.infer<typeof endpointPublicSchema>;
|
|
11
|
+
export declare const endpointSchema: z.ZodObject<{
|
|
12
|
+
endpoint: z.ZodString;
|
|
13
|
+
} & {
|
|
14
|
+
created_at: z.ZodDate;
|
|
15
|
+
updated_at: z.ZodDate;
|
|
16
|
+
}, "strip", z.ZodTypeAny, {
|
|
17
|
+
created_at: Date;
|
|
18
|
+
updated_at: Date;
|
|
19
|
+
endpoint: string;
|
|
20
|
+
}, {
|
|
21
|
+
created_at: Date;
|
|
22
|
+
updated_at: Date;
|
|
23
|
+
endpoint: string;
|
|
24
|
+
}>;
|
|
25
|
+
export type Endpoint = z.infer<typeof endpointSchema>;
|
|
@@ -1,19 +1,12 @@
|
|
|
1
|
-
import z from "zod";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
.
|
|
5
|
-
.
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
export const endpointSchema = endpointPublicSchema.extend({
|
|
15
|
-
created_at: z.coerce.date(),
|
|
16
|
-
updated_at: z.coerce.date(),
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
export type Endpoint = z.infer<typeof endpointSchema>;
|
|
1
|
+
import z from "zod";
|
|
2
|
+
export const endpointPathSchema = z
|
|
3
|
+
.string()
|
|
4
|
+
.max(256)
|
|
5
|
+
.regex(/^(\/[a-zA-Z0-9]+([_.-][a-zA-Z0-9]+)*)*$/, "Invalid endpoint");
|
|
6
|
+
export const endpointPublicSchema = z.object({
|
|
7
|
+
endpoint: endpointPathSchema,
|
|
8
|
+
});
|
|
9
|
+
export const endpointSchema = endpointPublicSchema.extend({
|
|
10
|
+
created_at: z.coerce.date(),
|
|
11
|
+
updated_at: z.coerce.date(),
|
|
12
|
+
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export * from "./creds.js";
|
|
2
|
-
export * from "./endpoint.js";
|
|
3
|
-
export * from "./jwt.js";
|
|
4
|
-
export * from "./record.js";
|
|
5
|
-
export * from "./stats.js";
|
|
6
|
-
export * from "./upload.js";
|
|
1
|
+
export * from "./creds.js";
|
|
2
|
+
export * from "./endpoint.js";
|
|
3
|
+
export * from "./jwt.js";
|
|
4
|
+
export * from "./record.js";
|
|
5
|
+
export * from "./stats.js";
|
|
6
|
+
export * from "./upload.js";
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import z from "zod";
|
|
2
|
+
export type JWTVerifyError = {
|
|
3
|
+
name: "TokenExpiredError" | "JsonWebTokenError" | "NotBeforeError" | "InvalidToken" | "InvalidTokenData";
|
|
4
|
+
message: string;
|
|
5
|
+
};
|
|
6
|
+
export type JWTSignError = {
|
|
7
|
+
name: "InvalidTokenData" | "JsonWebTokenError";
|
|
8
|
+
message: string;
|
|
9
|
+
};
|
|
10
|
+
export declare const jwtSchema: z.ZodString;
|
|
11
|
+
export declare const cdnAssetHeaderSchema: z.ZodObject<{
|
|
12
|
+
"x-cdn-asset": z.ZodOptional<z.ZodString>;
|
|
13
|
+
}, "strip", z.ZodTypeAny, {
|
|
14
|
+
"x-cdn-asset"?: string | undefined;
|
|
15
|
+
}, {
|
|
16
|
+
"x-cdn-asset"?: string | undefined;
|
|
17
|
+
}>;
|
|
18
|
+
export declare const cdnAssetTokenDataSchema: z.ZodObject<{
|
|
19
|
+
service: z.ZodLiteral<"auth">;
|
|
20
|
+
type: z.ZodLiteral<"avatar">;
|
|
21
|
+
endpoint: z.ZodString;
|
|
22
|
+
user_public_id: z.ZodString;
|
|
23
|
+
file_size_max: z.ZodOptional<z.ZodNumber>;
|
|
24
|
+
allowed_file_types: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
25
|
+
callback_url: z.ZodOptional<z.ZodString>;
|
|
26
|
+
}, "strip", z.ZodTypeAny, {
|
|
27
|
+
type: "avatar";
|
|
28
|
+
endpoint: string;
|
|
29
|
+
service: "auth";
|
|
30
|
+
user_public_id: string;
|
|
31
|
+
file_size_max?: number | undefined;
|
|
32
|
+
allowed_file_types?: string[] | undefined;
|
|
33
|
+
callback_url?: string | undefined;
|
|
34
|
+
}, {
|
|
35
|
+
type: "avatar";
|
|
36
|
+
endpoint: string;
|
|
37
|
+
service: "auth";
|
|
38
|
+
user_public_id: string;
|
|
39
|
+
file_size_max?: number | undefined;
|
|
40
|
+
allowed_file_types?: string[] | undefined;
|
|
41
|
+
callback_url?: string | undefined;
|
|
42
|
+
}>;
|
|
43
|
+
export declare const cdnAssetTokenDataDecodedSchema: z.ZodIntersection<z.ZodObject<{
|
|
44
|
+
service: z.ZodLiteral<"auth">;
|
|
45
|
+
type: z.ZodLiteral<"avatar">;
|
|
46
|
+
endpoint: z.ZodString;
|
|
47
|
+
user_public_id: z.ZodString;
|
|
48
|
+
file_size_max: z.ZodOptional<z.ZodNumber>;
|
|
49
|
+
allowed_file_types: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
50
|
+
callback_url: z.ZodOptional<z.ZodString>;
|
|
51
|
+
}, "strip", z.ZodTypeAny, {
|
|
52
|
+
type: "avatar";
|
|
53
|
+
endpoint: string;
|
|
54
|
+
service: "auth";
|
|
55
|
+
user_public_id: string;
|
|
56
|
+
file_size_max?: number | undefined;
|
|
57
|
+
allowed_file_types?: string[] | undefined;
|
|
58
|
+
callback_url?: string | undefined;
|
|
59
|
+
}, {
|
|
60
|
+
type: "avatar";
|
|
61
|
+
endpoint: string;
|
|
62
|
+
service: "auth";
|
|
63
|
+
user_public_id: string;
|
|
64
|
+
file_size_max?: number | undefined;
|
|
65
|
+
allowed_file_types?: string[] | undefined;
|
|
66
|
+
callback_url?: string | undefined;
|
|
67
|
+
}>, z.ZodObject<{
|
|
68
|
+
iat: z.ZodNumber;
|
|
69
|
+
exp: z.ZodNumber;
|
|
70
|
+
}, "strip", z.ZodTypeAny, {
|
|
71
|
+
iat: number;
|
|
72
|
+
exp: number;
|
|
73
|
+
}, {
|
|
74
|
+
iat: number;
|
|
75
|
+
exp: number;
|
|
76
|
+
}>>;
|
|
77
|
+
export type CdnAssetTokenData = z.infer<typeof cdnAssetTokenDataSchema>;
|
|
78
|
+
export type CdnAssetTokenDataDecoded = z.infer<typeof cdnAssetTokenDataDecodedSchema>;
|
|
79
|
+
export declare const cdnFeedbackHeaderSchema: z.ZodObject<{
|
|
80
|
+
authorization: z.ZodOptional<z.ZodString>;
|
|
81
|
+
}, "strip", z.ZodTypeAny, {
|
|
82
|
+
authorization?: string | undefined;
|
|
83
|
+
}, {
|
|
84
|
+
authorization?: string | undefined;
|
|
85
|
+
}>;
|
|
86
|
+
export declare const cdnFeedbackTokenDataSchema: z.ZodObject<{
|
|
87
|
+
service: z.ZodLiteral<"auth">;
|
|
88
|
+
type: z.ZodEnum<["avatar"]>;
|
|
89
|
+
endpoint: z.ZodString;
|
|
90
|
+
user_public_id: z.ZodString;
|
|
91
|
+
}, "strip", z.ZodTypeAny, {
|
|
92
|
+
type: "avatar";
|
|
93
|
+
endpoint: string;
|
|
94
|
+
service: "auth";
|
|
95
|
+
user_public_id: string;
|
|
96
|
+
}, {
|
|
97
|
+
type: "avatar";
|
|
98
|
+
endpoint: string;
|
|
99
|
+
service: "auth";
|
|
100
|
+
user_public_id: string;
|
|
101
|
+
}>;
|
|
102
|
+
export declare const cdnFeedbackTokenDecodedSchema: z.ZodIntersection<z.ZodObject<{
|
|
103
|
+
service: z.ZodLiteral<"auth">;
|
|
104
|
+
type: z.ZodEnum<["avatar"]>;
|
|
105
|
+
endpoint: z.ZodString;
|
|
106
|
+
user_public_id: z.ZodString;
|
|
107
|
+
}, "strip", z.ZodTypeAny, {
|
|
108
|
+
type: "avatar";
|
|
109
|
+
endpoint: string;
|
|
110
|
+
service: "auth";
|
|
111
|
+
user_public_id: string;
|
|
112
|
+
}, {
|
|
113
|
+
type: "avatar";
|
|
114
|
+
endpoint: string;
|
|
115
|
+
service: "auth";
|
|
116
|
+
user_public_id: string;
|
|
117
|
+
}>, z.ZodObject<{
|
|
118
|
+
iat: z.ZodNumber;
|
|
119
|
+
exp: z.ZodNumber;
|
|
120
|
+
}, "strip", z.ZodTypeAny, {
|
|
121
|
+
iat: number;
|
|
122
|
+
exp: number;
|
|
123
|
+
}, {
|
|
124
|
+
iat: number;
|
|
125
|
+
exp: number;
|
|
126
|
+
}>>;
|
|
127
|
+
export type CdnFeedbackTokenData = z.infer<typeof cdnFeedbackTokenDataSchema>;
|
|
128
|
+
export type CdnFeedbackTokenDataDecoded = z.infer<typeof cdnFeedbackTokenDecodedSchema>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import z from "zod";
|
|
2
|
+
import { authAssetTypeSchema, authServiceSchema, userPublicIdSchema, } from "@darco2903/auth-api/client";
|
|
3
|
+
import { endpointPathSchema } from "./endpoint.js";
|
|
4
|
+
const JWTData = z.object({
|
|
5
|
+
iat: z.number(),
|
|
6
|
+
exp: z.number(),
|
|
7
|
+
});
|
|
8
|
+
export const jwtSchema = z.string().startsWith("Bearer ");
|
|
9
|
+
///////////////////////////////////
|
|
10
|
+
export const cdnAssetHeaderSchema = z.object({
|
|
11
|
+
"x-cdn-asset": jwtSchema.optional(),
|
|
12
|
+
});
|
|
13
|
+
export const cdnAssetTokenDataSchema = z.object({
|
|
14
|
+
service: authServiceSchema,
|
|
15
|
+
type: z.literal("avatar"),
|
|
16
|
+
endpoint: endpointPathSchema,
|
|
17
|
+
user_public_id: userPublicIdSchema,
|
|
18
|
+
file_size_max: z.number().min(0).optional(),
|
|
19
|
+
allowed_file_types: z.array(z.string()).optional(),
|
|
20
|
+
callback_url: z.string().url().optional(),
|
|
21
|
+
});
|
|
22
|
+
export const cdnAssetTokenDataDecodedSchema = z.intersection(cdnAssetTokenDataSchema, JWTData);
|
|
23
|
+
///////////////////////////////////
|
|
24
|
+
export const cdnFeedbackHeaderSchema = z.object({
|
|
25
|
+
authorization: jwtSchema.optional(),
|
|
26
|
+
});
|
|
27
|
+
export const cdnFeedbackTokenDataSchema = z.object({
|
|
28
|
+
service: authServiceSchema,
|
|
29
|
+
type: authAssetTypeSchema,
|
|
30
|
+
endpoint: endpointPathSchema,
|
|
31
|
+
user_public_id: userPublicIdSchema,
|
|
32
|
+
});
|
|
33
|
+
export const cdnFeedbackTokenDecodedSchema = z.intersection(cdnFeedbackTokenDataSchema, JWTData);
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import z from "zod";
|
|
2
|
+
export declare const storagePublicIdSchema: z.ZodString;
|
|
3
|
+
export declare const recordPublicSchema: z.ZodObject<{
|
|
4
|
+
storage_id: z.ZodString;
|
|
5
|
+
filename: z.ZodString;
|
|
6
|
+
size: z.ZodNumber;
|
|
7
|
+
mime_type: z.ZodString;
|
|
8
|
+
endpoints: z.ZodArray<z.ZodObject<{
|
|
9
|
+
endpoint: z.ZodString;
|
|
10
|
+
}, "strip", z.ZodTypeAny, {
|
|
11
|
+
endpoint: string;
|
|
12
|
+
}, {
|
|
13
|
+
endpoint: string;
|
|
14
|
+
}>, "many">;
|
|
15
|
+
}, "strip", z.ZodTypeAny, {
|
|
16
|
+
filename: string;
|
|
17
|
+
size: number;
|
|
18
|
+
storage_id: string;
|
|
19
|
+
mime_type: string;
|
|
20
|
+
endpoints: {
|
|
21
|
+
endpoint: string;
|
|
22
|
+
}[];
|
|
23
|
+
}, {
|
|
24
|
+
filename: string;
|
|
25
|
+
size: number;
|
|
26
|
+
storage_id: string;
|
|
27
|
+
mime_type: string;
|
|
28
|
+
endpoints: {
|
|
29
|
+
endpoint: string;
|
|
30
|
+
}[];
|
|
31
|
+
}>;
|
|
32
|
+
export type RecordPublic = z.infer<typeof recordPublicSchema>;
|
|
33
|
+
export declare const recordTypeSchema: z.ZodEnum<["service", "system", "user"]>;
|
|
34
|
+
export type RecordType = z.infer<typeof recordTypeSchema>;
|
|
35
|
+
export declare const recordSchema: z.ZodObject<{
|
|
36
|
+
storage_id: z.ZodString;
|
|
37
|
+
filename: z.ZodString;
|
|
38
|
+
size: z.ZodNumber;
|
|
39
|
+
mime_type: z.ZodString;
|
|
40
|
+
} & {
|
|
41
|
+
endpoints: z.ZodArray<z.ZodObject<{
|
|
42
|
+
endpoint: z.ZodString;
|
|
43
|
+
} & {
|
|
44
|
+
created_at: z.ZodDate;
|
|
45
|
+
updated_at: z.ZodDate;
|
|
46
|
+
}, "strip", z.ZodTypeAny, {
|
|
47
|
+
created_at: Date;
|
|
48
|
+
updated_at: Date;
|
|
49
|
+
endpoint: string;
|
|
50
|
+
}, {
|
|
51
|
+
created_at: Date;
|
|
52
|
+
updated_at: Date;
|
|
53
|
+
endpoint: string;
|
|
54
|
+
}>, "many">;
|
|
55
|
+
role: z.ZodNumber;
|
|
56
|
+
user_id: z.ZodNullable<z.ZodString>;
|
|
57
|
+
type: z.ZodEnum<["service", "system", "user"]>;
|
|
58
|
+
visible: z.ZodBoolean;
|
|
59
|
+
active: z.ZodBoolean;
|
|
60
|
+
created_at: z.ZodDate;
|
|
61
|
+
updated_at: z.ZodDate;
|
|
62
|
+
}, "strip", z.ZodTypeAny, {
|
|
63
|
+
type: "user" | "service" | "system";
|
|
64
|
+
filename: string;
|
|
65
|
+
active: boolean;
|
|
66
|
+
visible: boolean;
|
|
67
|
+
role: number;
|
|
68
|
+
size: number;
|
|
69
|
+
created_at: Date;
|
|
70
|
+
updated_at: Date;
|
|
71
|
+
storage_id: string;
|
|
72
|
+
mime_type: string;
|
|
73
|
+
endpoints: {
|
|
74
|
+
created_at: Date;
|
|
75
|
+
updated_at: Date;
|
|
76
|
+
endpoint: string;
|
|
77
|
+
}[];
|
|
78
|
+
user_id: string | null;
|
|
79
|
+
}, {
|
|
80
|
+
type: "user" | "service" | "system";
|
|
81
|
+
filename: string;
|
|
82
|
+
active: boolean;
|
|
83
|
+
visible: boolean;
|
|
84
|
+
role: number;
|
|
85
|
+
size: number;
|
|
86
|
+
created_at: Date;
|
|
87
|
+
updated_at: Date;
|
|
88
|
+
storage_id: string;
|
|
89
|
+
mime_type: string;
|
|
90
|
+
endpoints: {
|
|
91
|
+
created_at: Date;
|
|
92
|
+
updated_at: Date;
|
|
93
|
+
endpoint: string;
|
|
94
|
+
}[];
|
|
95
|
+
user_id: string | null;
|
|
96
|
+
}>;
|
|
97
|
+
export type Record = z.infer<typeof recordSchema>;
|