강력한 API 타입 체크
This commit is contained in:
@@ -1,51 +1,10 @@
|
||||
import { APIPathGen } from "../api/APIPathGen";
|
||||
import { RawArgType } from "../api/base";
|
||||
import { APICallT, APITail, GET, POST, callClientAPI, extractHttpMethod } from "./clientAPI";
|
||||
import { extractHttpMethod } from "../apiStructure/defs";
|
||||
import type { APITail, RawArgType } from "../apiStructure/defs";
|
||||
import { structure } from "../apiStructure/sammoRootAPI";
|
||||
import { callClientAPI } from "./generator";
|
||||
|
||||
export type LoginResponse = {
|
||||
result: true,
|
||||
nextToken: [number, string] | undefined,
|
||||
}
|
||||
|
||||
export type LoginFailed = {
|
||||
result: false,
|
||||
reqOTP: boolean,
|
||||
reason: string,
|
||||
}
|
||||
|
||||
|
||||
export type AutoLoginNonceResponse = {
|
||||
result: true,
|
||||
loginNonce: string,
|
||||
};
|
||||
|
||||
export type AutoLoginResponse = {
|
||||
result: true,
|
||||
nextToken: [number, string] | undefined,
|
||||
}
|
||||
|
||||
|
||||
export type AutoLoginFailed = {
|
||||
result: false,
|
||||
silent: boolean,
|
||||
reason: string,
|
||||
}
|
||||
|
||||
const apiRealPath = {
|
||||
Login: {
|
||||
LoginByID: POST as APICallT<{
|
||||
username: string,
|
||||
password: string,
|
||||
}, LoginResponse, LoginFailed>,
|
||||
LoginByToken: POST as APICallT<{
|
||||
hashedToken: string,
|
||||
token_id: number,
|
||||
}, AutoLoginResponse, AutoLoginFailed>,
|
||||
ReqNonce: GET as APICallT<undefined, AutoLoginNonceResponse, AutoLoginFailed>
|
||||
},
|
||||
} as const;
|
||||
|
||||
export const SammoRootAPI = APIPathGen(apiRealPath, (path: string[], tail: APITail, pathParam) => {
|
||||
export const SammoRootAPI = APIPathGen(structure, (path: string[], tail: APITail, pathParam) => {
|
||||
const method = extractHttpMethod(tail);
|
||||
return (args?: RawArgType, returnError?: boolean) => {
|
||||
if (returnError) {
|
||||
|
||||
Reference in New Issue
Block a user