34 lines
1.3 KiB
TypeScript
34 lines
1.3 KiB
TypeScript
import type { AutoLoginFailed, AutoLoginNonceResponse, AutoLoginResponse, LoginFailed, LoginResponse } from "./defs/API/Login";
|
|
import { APIPathGen } from "./util/APIPathGen";
|
|
import { callSammoAPI, extractHttpMethod, POST, type APICallT, type APITail, type InvalidResponse, type RawArgType, type ValidResponse } from "./util/callSammoAPI";
|
|
export type { ValidResponse, InvalidResponse };
|
|
|
|
const apiRealPath = {
|
|
Admin: {
|
|
BanEmailAddress: POST as APICallT<{
|
|
email: string,
|
|
}>
|
|
},
|
|
Login: {
|
|
LoginByID: POST as APICallT<{
|
|
username: string,
|
|
password: string,
|
|
}, LoginResponse, LoginFailed>,
|
|
LoginByToken: POST as APICallT<{
|
|
hashedToken: string,
|
|
token_id: number,
|
|
}, AutoLoginResponse, AutoLoginFailed>,
|
|
ReqNonce: POST as APICallT<undefined, AutoLoginNonceResponse, AutoLoginFailed>
|
|
},
|
|
} as const;
|
|
|
|
export const SammoRootAPI = APIPathGen(apiRealPath, (path: string[], tail: APITail, pathParam) => {
|
|
const method = extractHttpMethod(tail);
|
|
return (args?: RawArgType, returnError?: boolean) => {
|
|
if (returnError) {
|
|
return callSammoAPI(method, path.join('/'), args, pathParam, true);
|
|
}
|
|
return callSammoAPI(method, path.join('/'), args, pathParam);
|
|
};
|
|
});
|