rootAPI to gatewayAPI

This commit is contained in:
2023-08-20 06:07:06 +00:00
parent 56a9c5bc45
commit f4640abe17
14 changed files with 21 additions and 21 deletions
@@ -0,0 +1,25 @@
import { GET } from "../defs.js";
import type { structure } from "../../apiStructure/sammoGatewayAPI.js";
import type { ExtractError, ExtractQuery, ExtractResponse } from "../../apiStructure/defs.js";
import { StartSession } from "../../ProcDecorator/StartSession.js";
import { declProcDecorators } from "../../ProcDecorator/base.js";
import { ReqLogin } from "../../ProcDecorator/ReqLogin.js";
type BaseAPI = typeof structure.GetGameLoginToken;
type RType = ExtractResponse<BaseAPI>;
type EType = ExtractError<BaseAPI>;
type QType = ExtractQuery<BaseAPI>;
export const GameLoginTokenSessionKey = "GameLoginToken";
export const GetGameLoginToken = GET<RType, EType, QType>(undefined)(declProcDecorators(
StartSession,
ReqLogin,
))(
async (query, ctx) => {
return {
result: false,
reason: 'NotYetImplemented',
};
}
);
@@ -0,0 +1,21 @@
import { GET } from "../../defs.js";
import type { structure } from "../../../apiStructure/sammoGatewayAPI.js";
import type { ExtractError, ExtractQuery, ExtractResponse } from "../../../apiStructure/defs.js";
import { declProcDecorators } from "../../../ProcDecorator/base.js";
import { ReqLogin } from "../../../ProcDecorator/ReqLogin.js";
import { StartSession } from "../../../ProcDecorator/StartSession.js";
type BaseAPI = typeof structure.Login.ReqNonce;
type RType = ExtractResponse<BaseAPI>;
type EType = ExtractError<BaseAPI>;
type QType = ExtractQuery<BaseAPI>;
const argValidator = undefined;
export const ReqNonce = GET<RType, EType, QType>(argValidator)(declProcDecorators(
StartSession,
ReqLogin,
))(
(query, ctx) => {
throw new Error("Method not implemented.");
}
);
+64
View File
@@ -0,0 +1,64 @@
import { POST } from "../../defs.js";
import type { structure } from "../../../apiStructure/sammoGatewayAPI.js";
import type { ExtractError, ExtractQuery, ExtractResponse } from "../../../apiStructure/defs.js";
import { StartSession } from "../../../ProcDecorator/StartSession.js";
import { delay } from "../../../util/delay.js";
import { declProcDecorators } from "../../../ProcDecorator/base.js";
import { z } from "zod";
import { type LoginCtx, loginCtxSessionKey } from "../../../ProcDecorator/ReqLogin.js";
type BaseAPI = typeof structure.Login.LoginByID;
type RType = ExtractResponse<BaseAPI>;
type EType = ExtractError<BaseAPI>;
type QType = ExtractQuery<BaseAPI>;
const LoginByIDReq = z.object({
id: z.string(),
password: z.string(),
}) satisfies z.ZodType<QType>
export const LoginByID = POST<RType, EType, QType>(LoginByIDReq)(declProcDecorators(
StartSession,
))(
async (query, ctx, req, res) => {
const id = query.id;
const password = query.password;
//TODO: DB에서 뭔가 가져와야 함
await delay(1);
if (Math.random() < 0.3) {
return {
result: false,
reason: "로그인 실패",
reqOTP: false,
}
}
if (Math.random() < 0.5) {
return {
result: false,
reason: "OTP 인증 필요",
reqOTP: true,
}
}
const userID = 1;
const userName = "test";
const userLevel = 1;
const nextToken: [number, string] = [1, "1234567890"];
const loginCtx: LoginCtx = {
userID,
userName,
userLevel,
allowServerAction: new Set(),
loginDate: new Date(),
}
ctx.session.setItem(loginCtxSessionKey, loginCtx);
return {
result: true,
nextToken,
}
});
@@ -0,0 +1,51 @@
import { POST } from "../../defs.js";
import type { structure } from "../../../apiStructure/sammoGatewayAPI.js";
import type { ExtractError, ExtractQuery, ExtractResponse } from "../../../apiStructure/defs.js";
import { StartSession } from "../../../ProcDecorator/StartSession.js";
import { delay } from "../../../util/delay.js";
import { declProcDecorators } from "../../../ProcDecorator/base.js";
import { type LoginCtx, loginCtxSessionKey } from "../../../ProcDecorator/ReqLogin.js";
import { z } from "zod";
type BaseAPI = typeof structure.Login.LoginByToken;
type RType = ExtractResponse<BaseAPI>;
type EType = ExtractError<BaseAPI>;
type QType = ExtractQuery<BaseAPI>;
const LoginByTokenReq = z.object({
token_id: z.number(),
hashedToken: z.string(),
}) satisfies z.ZodType<QType>
export const LoginByToken = POST<RType, EType, QType>(LoginByTokenReq)(declProcDecorators(
StartSession,
))
(async (query, ctx) => {
query.hashedToken;
ctx.session.clear();
await delay(1);
//무언가 로그인
//TODO: DB는 어디서 들고옴?
const userID = 1;
const userName = "test";
const userLevel = 1;
const nextToken: [number, string] = [1, "1234567890"];
const loginCtx: LoginCtx = {
userID,
userName,
userLevel,
allowServerAction: new Set(),
loginDate: new Date(),
}
ctx.session.setItem(loginCtxSessionKey, loginCtx);
//throw new Error("Method not implemented.");
return {
result: true,
nextToken,
}
});
+33
View File
@@ -0,0 +1,33 @@
import { GET } from "../../defs.js";
import type { structure } from "../../../apiStructure/sammoGatewayAPI.js";
import type { ExtractError, ExtractQuery, ExtractResponse } from "../../../apiStructure/defs.js";
import { StartSession } from "../../../ProcDecorator/StartSession.js";
import { declProcDecorators } from "../../../ProcDecorator/base.js";
type BaseAPI = typeof structure.Login.ReqNonce;
type RType = ExtractResponse<BaseAPI>;
type EType = ExtractError<BaseAPI>;
type QType = ExtractQuery<BaseAPI>;
export const ReqNonceSessionKey = 'loginNonce';
export const ReqNonce = GET<RType, EType, QType>(undefined)(declProcDecorators(
StartSession,
))(
async (query, ctx) => {
const nonce = ctx.session.getItem<string>(ReqNonceSessionKey);
if (nonce !== undefined) {
return {
loginNonce: nonce,
result: true,
}
}
const newNonce = "1234567890";
ctx.session.setItem(ReqNonceSessionKey, newNonce);
return {
loginNonce: newNonce,
result: true,
}
}
)
+13
View File
@@ -0,0 +1,13 @@
import type { structure } from "../../../apiStructure/sammoGatewayAPI.js";
import type { APINamespaceType } from "../../defs.js";
import { LoginByID } from "./LoginByID.js";
import { LoginByToken } from "./LoginByToken.js";
import { ReqNonce } from "./ReqNonce.js";
import { test } from "./test.js";
export const Login = {
LoginByID,
LoginByToken,
ReqNonce,
test,
} satisfies APINamespaceType<typeof structure.Login>;
+15
View File
@@ -0,0 +1,15 @@
import { GET } from "../../defs.js";
import type { structure } from "../../../apiStructure/sammoGatewayAPI.js";
import type { ExtractError, ExtractQuery, ExtractResponse } from "../../../apiStructure/defs.js";
import { EmptyProcDecorator } from "../../../ProcDecorator/base.js";
type BaseAPI = typeof structure.Login.test;
type RType = ExtractResponse<BaseAPI>;
type EType = ExtractError<BaseAPI>;
type QType = ExtractQuery<BaseAPI>;
export const test = GET<RType, EType, QType>(undefined)(EmptyProcDecorator)(
() => {
throw new Error("Method not implemented.");
}
);