webserver-framework/@types/Server.ts

169 lines
3.9 KiB
TypeScript

import { AbstractUser } from "../src/server/interfaces/index.js";
import { ObjectId } from 'mongodb';
import { LoggerClientOptions } from '@navy.gif/logger';
import { MariaOptions, MongoOptions } from '@navy.gif/wrappers';
import { Request as ExpressRequest, Response as ExpressResponse, NextFunction } from "express";
import http from 'http';
import { UploadedFile } from "express-fileupload";
import { Session } from "express-session";
import Role from "../src/server/structures/Role.js";
export type RateLimit = {
limit: number,
time: number,
disabled?: boolean
}
export type RateLimits = {
[key: string]: RateLimit
}
export type RegistryOptions = {
path: string
}
type HttpOptions = {
port: number
} & http.ServerOptions
export type OAuthProvider = {
name: string,
iconURL: string,
authoriseURL: string,
tokenURL: string,
profileURL: string
}
export type ServerOptions = {
dir: string,
name: string,
http: HttpOptions,
databases: {
mariadb?: MariaOptions,
mongodb?: MongoOptions
},
logger?: LoggerClientOptions,
domain: string,
serveFiles: string,
registrationEnabled: boolean,
requireCodeForRegister: boolean,
OAuthProviders: OAuthProvider[],
callbackPath: string,
discord: {
scope?: string[],
version?: number
}
}
export type Permissions = {
[key: string]: number | Permissions
}
export type ExternalProfile = {
provider: string,
username: string,
id: string,
accessToken?: string
}
export type EntityData = {
[key:string]: unknown
id?: string | ObjectId,
name?: string,
disabled?: boolean,
permissions?: Permissions,
createdTimestamp?: number,
note?: string | null
}
export type EntityJson = {
[key: string]: string | string[] | number | boolean | null | ObjectId | Permissions | unknown,
id: string,
name: string,
disabled: boolean,
permissions: Permissions,
createdTimestamp: number,
note: string | null
}
export type RoleData = {
position: number,
rateLimits?: RateLimits
} & EntityData
export type RoleJson = {
position: number,
rateLimits: RateLimits
} & EntityJson
export type AbstractUserData = {
icon?: string | null,
roles?: (Role|RoleData)[],
temporary?: boolean
} & EntityData
export type AbstractUserJson = {
icon: string,
roles: RoleJson[],
temporary: boolean
} & EntityJson
export type ApplicationData = {
token: string,
ownerId: string | ObjectId,
description: string | null
} & AbstractUserData
export type ApplicationJson = {
token: string,
ownerId: string,
description: string | null
} & AbstractUserJson
export type UserData = {
applications?: string[],
externalProfiles?: { [key: string]: ExternalProfile },
password?: string | null,
otpSecret?: string | null,
twoFactor?: boolean,
displayName?: string | null
} & AbstractUserData
export type UserJson = {
applications: string[]
externalProfiles: { [key: string]: ExternalProfile },
twoFactor: boolean,
displayName: string | null
} & AbstractUserJson
// export type EntityJson = { [key: string]: string | string[] | number | boolean | null | ObjectId | Permissions | unknown }
// export type UserJson = { externalProfiles: {[key: string]: ExternalProfile} } & EntityJson;
export type Request = {
user: AbstractUser,
session: {
verified: boolean,
loginMethod: string
} & Session,
files: { [key: string]: UploadedFile },
remoteAddress: string
} & ExpressRequest
export type Response = {
//
} & ExpressResponse
export type MiddlewareFunction = (req: Request, res: Response, next: NextFunction) => void
export type HandlerFunction = (req: Request, res: Response) => void
export type SessionLimit = {
budget: number,
reset: number
}
export type EndpointOptions = {
path: string,
name: string,
auth?: MiddlewareFunction | true | null,
loadOrder?: number
}