Feat: server-infoエンドポイント / Fix: logger.tsを追跡対象に / Feat: lynqchat-jsを利用可能に / Fix: lynqchat-jsに不足していたエンドポイントを追加
This commit is contained in:
@@ -1,8 +0,0 @@
|
||||
import SetupCreateAdmin from "./setup/create-admin";
|
||||
import SetupInitilization from "./setup/initialization";
|
||||
|
||||
type ApiMap =
|
||||
SetupInitilization &
|
||||
SetupCreateAdmin;
|
||||
|
||||
export default ApiMap;
|
||||
@@ -0,0 +1,12 @@
|
||||
import { InputError, InputNoneError } from "../../modules/error/input";
|
||||
import ErrorBase from "../../modules/error";
|
||||
import DatabaseError from "../../modules/error/database";
|
||||
import Success from "../../modules/response/success";
|
||||
import YetInitializationError from "../../modules/error/yet_init";
|
||||
|
||||
export default interface Me {
|
||||
"me": {
|
||||
body: never;
|
||||
response: Success | DatabaseError | InputError | InputNoneError | YetInitializationError;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import { InputError, InputNoneError } from "../../modules/error/input";
|
||||
import ErrorBase from "../../modules/error";
|
||||
import DatabaseError from "../../modules/error/database";
|
||||
import Success from "../../modules/response/success";
|
||||
import YetInitializationError from "../../modules/error/yet_init";
|
||||
import { UserSchema } from "./signup";
|
||||
|
||||
export default interface PrimarySignin {
|
||||
"primary/signin": {
|
||||
body: Pick<UserSchema, "userid" | "password">;
|
||||
response: (Success & {
|
||||
token: string;
|
||||
}) | DatabaseError | ErrorBase<{
|
||||
bad: "client",
|
||||
code: "auth_input_wrong",
|
||||
message: "ユーザー名かパスワードが違います。",
|
||||
}> | InputError | InputNoneError | YetInitializationError;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import { InputError, InputNoneError } from "../../modules/error/input";
|
||||
import ErrorBase from "../../modules/error";
|
||||
import DatabaseError from "../../modules/error/database";
|
||||
import Success from "../../modules/response/success";
|
||||
import YetInitializationError from "../../modules/error/yet_init";
|
||||
|
||||
export interface UserSchema {
|
||||
userid: string;
|
||||
username: string;
|
||||
email: string;
|
||||
password: string;
|
||||
}
|
||||
|
||||
export default interface PrimarySignup {
|
||||
"primary/signup": {
|
||||
body: UserSchema;
|
||||
response: Success | DatabaseError | InputError | InputNoneError | YetInitializationError;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import { InputError, InputNoneError } from "../../modules/error/input";
|
||||
import ErrorBase from "../../modules/error";
|
||||
import DatabaseError from "../../modules/error/database";
|
||||
|
||||
export default interface ServerInfo {
|
||||
"server-info": {
|
||||
body: {
|
||||
name: string;
|
||||
description: string;
|
||||
requiredInvitationCode: boolean;
|
||||
force?: "use_force_initialization";
|
||||
};
|
||||
response: Success | DatabaseError;
|
||||
};
|
||||
}
|
||||
@@ -1,23 +1,17 @@
|
||||
import { InputError, InputNoneError } from "../../modules/error/input";
|
||||
import ErrorBase from "../../modules/error";
|
||||
import DatabaseError from "../../modules/error/database";
|
||||
import Success from "../../modules/response/success";
|
||||
import YetInitializationError from "../../modules/error/yet_init";
|
||||
import { UserSchema } from "../primary/signup";
|
||||
|
||||
export default interface SetupCreateAdmin {
|
||||
"setup/create-admin": {
|
||||
body: {
|
||||
userid: string;
|
||||
username: string;
|
||||
email: string;
|
||||
password: string;
|
||||
};
|
||||
body: UserSchema;
|
||||
response: Success | DatabaseError | ErrorBase<{
|
||||
bad: "client",
|
||||
code: "yet_initialization",
|
||||
message: "初期設定が行われていません。",
|
||||
}> | ErrorBase<{
|
||||
bad: "client",
|
||||
code: "first_admin_already_exists",
|
||||
message: "最初の管理者ユーザーは既に存在します。",
|
||||
}> | InputError | InputNoneError;
|
||||
}> | InputError | InputNoneError | YetInitializationError;
|
||||
};
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import { InputError, InputNoneError } from "../../modules/error/input";
|
||||
import ErrorBase from "../../modules/error";
|
||||
import DatabaseError from "../../modules/error/database";
|
||||
import Success from "../../modules/response/success";
|
||||
|
||||
export default interface SetupInitilization {
|
||||
"setup/initilization": {
|
||||
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
import Me from "./api/me";
|
||||
import PrimarySignin from "./api/primary/signin";
|
||||
import PrimarySignup from "./api/primary/signup";
|
||||
import ServerInfo from "./api/server-info";
|
||||
import SetupCreateAdmin from "./api/setup/create-admin";
|
||||
import SetupInitilization from "./api/setup/initialization";
|
||||
|
||||
type ApiMap =
|
||||
SetupCreateAdmin &
|
||||
SetupInitilization &
|
||||
ServerInfo &
|
||||
PrimarySignin &
|
||||
PrimarySignup &
|
||||
Me;
|
||||
|
||||
export default ApiMap;
|
||||
@@ -5,9 +5,9 @@ type ErrorType<R = unknown> = {
|
||||
reason?: R,
|
||||
}
|
||||
|
||||
type ErrorBase<E extends ErrorType<any>> = {
|
||||
type ErrorBase<E extends ErrorType<any> = ErrorType> = {
|
||||
success: false;
|
||||
error: E;
|
||||
}
|
||||
};
|
||||
|
||||
export default ErrorBase;
|
||||
@@ -1,3 +1,5 @@
|
||||
import ErrorBase from ".";
|
||||
|
||||
export type InputError = ErrorBase<{
|
||||
bad: "client";
|
||||
code: "input_wrong";
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
type YetInitializationError = ErrorBase<{
|
||||
bad: "client";
|
||||
code: "yet_initialization";
|
||||
message: "初期設定が行われていません。";
|
||||
}>;
|
||||
|
||||
export default YetInitializationError;
|
||||
@@ -14,7 +14,7 @@ type BodyArgs<M, E extends keyof M> =
|
||||
[];
|
||||
|
||||
export default class LynqChat<
|
||||
M extends { [K in keyof M]: { body?: any; response: any } }
|
||||
M extends { [K in keyof M]: { body: any; response: any } }
|
||||
> {
|
||||
readonly origin: string;
|
||||
readonly retry: number;
|
||||
@@ -44,25 +44,20 @@ export default class LynqChat<
|
||||
public async request<E extends keyof M>(
|
||||
endpoint: E,
|
||||
...args: BodyArgs<M, E>
|
||||
): Promise<M[E]["response"]>;
|
||||
public async request(
|
||||
endpoint: string,
|
||||
body?: any
|
||||
): Promise<any>;
|
||||
public async request(
|
||||
endpoint: string,
|
||||
...args: any[]
|
||||
): Promise<any> {
|
||||
): Promise<M[E]["response"]> {
|
||||
const body = args[0] !== undefined
|
||||
? JSON.stringify(args[0])
|
||||
: undefined;
|
||||
|
||||
const req = await lynqFetch(
|
||||
this.origin,
|
||||
this.retry,
|
||||
this.waiting,
|
||||
endpoint,
|
||||
endpoint as string,
|
||||
{
|
||||
method: "POST",
|
||||
cache: "no-store",
|
||||
body: args[0],
|
||||
body,
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user