@darco2903/auth-api 2.1.3 → 2.1.6
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/dist/client.d.ts +371 -363
- package/dist/client.js +2 -1
- package/dist/consts.d.ts +2 -3
- package/dist/contract/assets.d.ts +2 -2
- package/dist/contract/assets.js +2 -2
- package/dist/contract/auth.d.ts +12 -756
- package/dist/contract/auth.js +4 -77
- package/dist/contract/index.d.ts +906 -889
- package/dist/contract/index.js +2 -0
- package/dist/contract/requests.d.ts +2 -2
- package/dist/contract/requests.js +2 -2
- package/dist/contract/totp.d.ts +763 -0
- package/dist/contract/totp.js +81 -0
- package/dist/contract/user.d.ts +4 -4
- package/dist/contract/user.js +4 -4
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/otp.d.ts +2 -0
- package/dist/otp.js +7 -0
- package/dist/server.d.ts +2 -1
- package/dist/server.js +2 -1
- package/dist/types/auth.d.ts +17 -0
- package/dist/types/auth.js +4 -0
- package/dist/types/jwt.d.ts +2 -2
- package/package.json +5 -4
- package/LICENSE +0 -674
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { initContract, ZodErrorSchema } from "@ts-rest/core";
|
|
2
|
+
import z from "zod";
|
|
3
|
+
import { apiError, apiSuccess } from "../types.js";
|
|
4
|
+
import { authHeaderSchema, totpCodeSchema } from "../types/index.js";
|
|
5
|
+
const c = initContract();
|
|
6
|
+
export default c.router({
|
|
7
|
+
setup: {
|
|
8
|
+
method: "POST",
|
|
9
|
+
path: "/totp/setup",
|
|
10
|
+
headers: authHeaderSchema,
|
|
11
|
+
body: c.noBody(),
|
|
12
|
+
responses: {
|
|
13
|
+
200: apiSuccess(z.object({
|
|
14
|
+
secret: z.string(),
|
|
15
|
+
otpauthUrl: z.string(),
|
|
16
|
+
})),
|
|
17
|
+
400: z.union([
|
|
18
|
+
ZodErrorSchema,
|
|
19
|
+
apiError(z.literal("TOTP_ALREADY_SETUP"), z.string()),
|
|
20
|
+
]),
|
|
21
|
+
401: apiError(z.literal("UNAUTHORIZED"), z.literal("Unauthorized")),
|
|
22
|
+
500: apiError(z.literal("INTERNAL_SERVER_ERROR"), z.string()),
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
setupConfirm: {
|
|
26
|
+
method: "POST",
|
|
27
|
+
path: "/totp/setup/confirm",
|
|
28
|
+
headers: authHeaderSchema,
|
|
29
|
+
body: z.object({
|
|
30
|
+
totpCode: totpCodeSchema,
|
|
31
|
+
}),
|
|
32
|
+
responses: {
|
|
33
|
+
204: apiSuccess(c.noBody()),
|
|
34
|
+
400: z.union([
|
|
35
|
+
ZodErrorSchema,
|
|
36
|
+
apiError(z.literal("TOTP_NOT_SETUP"), z.string()),
|
|
37
|
+
apiError(z.literal("TOTP_ALREADY_SETUP"), z.string()),
|
|
38
|
+
apiError(z.literal("TOTP_INVALID"), z.string()),
|
|
39
|
+
]),
|
|
40
|
+
401: apiError(z.literal("UNAUTHORIZED"), z.literal("Unauthorized")),
|
|
41
|
+
500: apiError(z.literal("INTERNAL_SERVER_ERROR"), z.string()),
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
verify: {
|
|
45
|
+
method: "POST",
|
|
46
|
+
path: "/totp/verify",
|
|
47
|
+
headers: authHeaderSchema,
|
|
48
|
+
body: z.object({
|
|
49
|
+
totpCode: totpCodeSchema,
|
|
50
|
+
}),
|
|
51
|
+
responses: {
|
|
52
|
+
204: apiSuccess(c.noBody()),
|
|
53
|
+
400: z.union([
|
|
54
|
+
ZodErrorSchema,
|
|
55
|
+
apiError(z.literal("TOTP_NOT_SETUP"), z.string()),
|
|
56
|
+
apiError(z.literal("TOTP_NOT_REQUIRED"), z.string()),
|
|
57
|
+
apiError(z.literal("TOTP_INVALID"), z.string()),
|
|
58
|
+
]),
|
|
59
|
+
401: apiError(z.literal("UNAUTHORIZED"), z.literal("Unauthorized")),
|
|
60
|
+
500: apiError(z.literal("INTERNAL_SERVER_ERROR"), z.string()),
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
disable: {
|
|
64
|
+
method: "POST",
|
|
65
|
+
path: "/totp/disable",
|
|
66
|
+
headers: authHeaderSchema,
|
|
67
|
+
body: z.object({
|
|
68
|
+
totpCode: totpCodeSchema,
|
|
69
|
+
}),
|
|
70
|
+
responses: {
|
|
71
|
+
204: apiSuccess(c.noBody()),
|
|
72
|
+
400: z.union([
|
|
73
|
+
ZodErrorSchema,
|
|
74
|
+
apiError(z.literal("TOTP_NOT_SETUP"), z.string()),
|
|
75
|
+
apiError(z.literal("TOTP_INVALID"), z.string()),
|
|
76
|
+
]),
|
|
77
|
+
401: apiError(z.literal("UNAUTHORIZED"), z.literal("Unauthorized")),
|
|
78
|
+
500: apiError(z.literal("INTERNAL_SERVER_ERROR"), z.string()),
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
});
|
package/dist/contract/user.d.ts
CHANGED
|
@@ -472,7 +472,7 @@ declare const _default: {
|
|
|
472
472
|
authorization?: string | undefined;
|
|
473
473
|
}>;
|
|
474
474
|
responses: {
|
|
475
|
-
|
|
475
|
+
204: typeof import("@ts-rest/core").ContractNoBody;
|
|
476
476
|
400: z.ZodObject<{
|
|
477
477
|
name: z.ZodLiteral<"ZodError">;
|
|
478
478
|
issues: z.ZodArray<z.ZodObject<{
|
|
@@ -638,7 +638,7 @@ declare const _default: {
|
|
|
638
638
|
authorization?: string | undefined;
|
|
639
639
|
}>;
|
|
640
640
|
responses: {
|
|
641
|
-
|
|
641
|
+
204: typeof import("@ts-rest/core").ContractNoBody;
|
|
642
642
|
400: z.ZodObject<{
|
|
643
643
|
name: z.ZodLiteral<"ZodError">;
|
|
644
644
|
issues: z.ZodArray<z.ZodObject<{
|
|
@@ -801,7 +801,7 @@ declare const _default: {
|
|
|
801
801
|
authorization?: string | undefined;
|
|
802
802
|
}>;
|
|
803
803
|
responses: {
|
|
804
|
-
|
|
804
|
+
204: typeof import("@ts-rest/core").ContractNoBody;
|
|
805
805
|
400: z.ZodObject<{
|
|
806
806
|
name: z.ZodLiteral<"ZodError">;
|
|
807
807
|
issues: z.ZodArray<z.ZodObject<{
|
|
@@ -964,7 +964,7 @@ declare const _default: {
|
|
|
964
964
|
authorization?: string | undefined;
|
|
965
965
|
}>;
|
|
966
966
|
responses: {
|
|
967
|
-
|
|
967
|
+
204: typeof import("@ts-rest/core").ContractNoBody;
|
|
968
968
|
400: z.ZodObject<{
|
|
969
969
|
name: z.ZodLiteral<"ZodError">;
|
|
970
970
|
issues: z.ZodArray<z.ZodObject<{
|
package/dist/contract/user.js
CHANGED
|
@@ -52,7 +52,7 @@ export default c.router({
|
|
|
52
52
|
email: emailSchema,
|
|
53
53
|
}),
|
|
54
54
|
responses: {
|
|
55
|
-
|
|
55
|
+
204: apiSuccess(c.noBody()),
|
|
56
56
|
400: ZodErrorSchema,
|
|
57
57
|
401: apiError(z.literal("UNAUTHORIZED"), z.string()),
|
|
58
58
|
500: apiError(z.literal("INTERNAL_SERVER_ERROR"), z.string()),
|
|
@@ -68,7 +68,7 @@ export default c.router({
|
|
|
68
68
|
disconnectAll: z.boolean().default(true),
|
|
69
69
|
}),
|
|
70
70
|
responses: {
|
|
71
|
-
|
|
71
|
+
204: apiSuccess(c.noBody()),
|
|
72
72
|
400: ZodErrorSchema,
|
|
73
73
|
401: apiError(z.literal("UNAUTHORIZED"), z.string()),
|
|
74
74
|
500: apiError(z.literal("INTERNAL_SERVER_ERROR"), z.string()),
|
|
@@ -83,7 +83,7 @@ export default c.router({
|
|
|
83
83
|
username: usernameSchema,
|
|
84
84
|
}),
|
|
85
85
|
responses: {
|
|
86
|
-
|
|
86
|
+
204: apiSuccess(c.noBody()),
|
|
87
87
|
400: ZodErrorSchema,
|
|
88
88
|
401: apiError(z.literal("UNAUTHORIZED"), z.string()),
|
|
89
89
|
500: apiError(z.literal("INTERNAL_SERVER_ERROR"), z.string()),
|
|
@@ -98,7 +98,7 @@ export default c.router({
|
|
|
98
98
|
roundBorder: z.boolean(),
|
|
99
99
|
}),
|
|
100
100
|
responses: {
|
|
101
|
-
|
|
101
|
+
204: apiSuccess(c.noBody()),
|
|
102
102
|
400: ZodErrorSchema,
|
|
103
103
|
401: apiError(z.literal("UNAUTHORIZED"), z.literal("Unauthorized")),
|
|
104
104
|
500: apiError(z.literal("INTERNAL_SERVER_ERROR"), z.string()),
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/otp.d.ts
ADDED
package/dist/otp.js
ADDED
package/dist/server.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
export * from "./common.js";
|
|
2
1
|
import { ResultAsync } from "neverthrow";
|
|
3
2
|
import type { Time } from "@darco2903/secondthought";
|
|
4
3
|
import type { CdnAssetTokenData } from "@darco2903/cdn-api/server";
|
|
5
4
|
import { type JWTVerifyError, type AccessTokenData, type AccessTokenDataDecoded, type JWTSignError } from "./types/index.js";
|
|
5
|
+
export * from "./common.js";
|
|
6
|
+
export { verifyOTP } from "./otp.js";
|
|
6
7
|
export declare function JWTVerify(token: string, pubKey: string): ResultAsync<AccessTokenDataDecoded, JWTVerifyError>;
|
|
7
8
|
/**
|
|
8
9
|
* Sign a JWT token with the given payload and private key, with the specified expiration time.
|
package/dist/server.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
export * from "./common.js";
|
|
2
1
|
import jwt from "jsonwebtoken";
|
|
3
2
|
import { ResultAsync } from "neverthrow";
|
|
4
3
|
import { accessTokenDataDecodedSchema, } from "./types/index.js";
|
|
5
4
|
import { JWT_ALGORITHM, JWT_ALGORITHMS } from "./consts.js";
|
|
5
|
+
export * from "./common.js";
|
|
6
|
+
export { verifyOTP } from "./otp.js";
|
|
6
7
|
export function JWTVerify(token, pubKey) {
|
|
7
8
|
return ResultAsync.fromPromise(new Promise((resolve, reject) => {
|
|
8
9
|
jwt.verify(token, pubKey, { algorithms: JWT_ALGORITHMS }, (e, decoded) => {
|
package/dist/types/auth.d.ts
CHANGED
|
@@ -23,4 +23,21 @@ export declare const accessRefreshSchema: z.ZodObject<{
|
|
|
23
23
|
expiresIn: number;
|
|
24
24
|
refreshToken: string;
|
|
25
25
|
}>;
|
|
26
|
+
export declare const accessRefreshPendingSchema: z.ZodObject<{
|
|
27
|
+
accessToken: z.ZodString;
|
|
28
|
+
expiresIn: z.ZodNumber;
|
|
29
|
+
} & {
|
|
30
|
+
refreshToken: z.ZodNullable<z.ZodString>;
|
|
31
|
+
needTotp: z.ZodBoolean;
|
|
32
|
+
}, "strip", z.ZodTypeAny, {
|
|
33
|
+
accessToken: string;
|
|
34
|
+
expiresIn: number;
|
|
35
|
+
refreshToken: string | null;
|
|
36
|
+
needTotp: boolean;
|
|
37
|
+
}, {
|
|
38
|
+
accessToken: string;
|
|
39
|
+
expiresIn: number;
|
|
40
|
+
refreshToken: string | null;
|
|
41
|
+
needTotp: boolean;
|
|
42
|
+
}>;
|
|
26
43
|
export declare const totpCodeSchema: z.ZodString;
|
package/dist/types/auth.js
CHANGED
|
@@ -6,4 +6,8 @@ export const accessSchema = z.object({
|
|
|
6
6
|
export const accessRefreshSchema = accessSchema.extend({
|
|
7
7
|
refreshToken: z.string(),
|
|
8
8
|
});
|
|
9
|
+
export const accessRefreshPendingSchema = accessSchema.extend({
|
|
10
|
+
refreshToken: z.string().nullable(),
|
|
11
|
+
needTotp: z.boolean(),
|
|
12
|
+
});
|
|
9
13
|
export const totpCodeSchema = z.string().min(6).max(6);
|
package/dist/types/jwt.d.ts
CHANGED
|
@@ -39,11 +39,11 @@ export declare const accessTokenDataDecodedSchema: z.ZodIntersection<z.ZodObject
|
|
|
39
39
|
iat: z.ZodNumber;
|
|
40
40
|
exp: z.ZodNumber;
|
|
41
41
|
}, "strip", z.ZodTypeAny, {
|
|
42
|
-
exp: number;
|
|
43
42
|
iat: number;
|
|
44
|
-
}, {
|
|
45
43
|
exp: number;
|
|
44
|
+
}, {
|
|
46
45
|
iat: number;
|
|
46
|
+
exp: number;
|
|
47
47
|
}>, z.ZodObject<{
|
|
48
48
|
public_id: z.ZodString;
|
|
49
49
|
role: z.ZodNumber;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@darco2903/auth-api",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.6",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -22,16 +22,17 @@
|
|
|
22
22
|
"@darco2903/cdn-api": "^1.1.0",
|
|
23
23
|
"@ts-rest/core": "^3.52.1",
|
|
24
24
|
"@ts-rest/open-api": "^3.52.1",
|
|
25
|
-
"@types/jsonwebtoken": "^9.0.10",
|
|
26
25
|
"jsonwebtoken": "^9.0.3",
|
|
27
26
|
"neverthrow": "^8.2.0",
|
|
27
|
+
"otplib": "^13.4.0",
|
|
28
28
|
"zod": "^3.25.76"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
|
-
"@darco2903/secondthought": "^1.
|
|
31
|
+
"@darco2903/secondthought": "^1.3.0"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@types/
|
|
34
|
+
"@types/jsonwebtoken": "^9.0.10",
|
|
35
|
+
"@types/node": "^25.5.0",
|
|
35
36
|
"prettier": "^3.8.1",
|
|
36
37
|
"rimraf": "^6.1.3",
|
|
37
38
|
"tsx": "^4.21.0",
|