webserver-framework/@types/Server.ts

175 lines
4.0 KiB
TypeScript
Raw Normal View History

2023-04-17 13:10:45 +02:00
import { AbstractUser } from "../src/server/interfaces/index.js";
import { LoggerClientOptions } from '@navy.gif/logger';
2023-05-08 19:47:10 +02:00
import { BrokerOptions, MariaOptions, MongoOptions, ObjectId } from '@navy.gif/wrappers';
2023-04-17 13:10:45 +02:00
import { Request as ExpressRequest, Response as ExpressResponse, NextFunction } from "express";
import http from 'http';
import { UploadedFile } from "express-fileupload";
import { Session } from "express-session";
2023-04-22 19:16:58 +02:00
import Role from "../src/server/structures/Role.js";
2023-04-17 13:10:45 +02:00
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
2023-05-08 19:47:10 +02:00
},
rabbitConfig: BrokerOptions
2023-04-17 13:10:45 +02:00
}
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,
2023-04-22 19:16:58 +02:00
createdTimestamp?: number,
note?: string | null
2023-04-17 13:10:45 +02:00
}
2023-04-22 19:16:58 +02:00
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
2023-04-17 13:10:45 +02:00
export type AbstractUserData = {
icon?: string | null,
2023-04-22 19:16:58 +02:00
roles?: (Role|RoleData)[],
2023-04-17 13:10:45 +02:00
temporary?: boolean
} & EntityData
2023-04-22 19:16:58 +02:00
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
2023-04-17 13:10:45 +02:00
export type UserData = {
applications?: string[],
externalProfiles?: { [key: string]: ExternalProfile },
password?: string | null,
otpSecret?: string | null,
twoFactor?: boolean,
displayName?: string | null
} & AbstractUserData
2023-04-22 19:16:58 +02:00
export type UserJson = {
applications: string[]
externalProfiles: { [key: string]: ExternalProfile },
twoFactor: boolean,
displayName: string | null
} & AbstractUserJson
2023-04-17 13:10:45 +02:00
2023-04-22 19:16:58 +02:00
// export type EntityJson = { [key: string]: string | string[] | number | boolean | null | ObjectId | Permissions | unknown }
2023-04-17 13:10:45 +02:00
// export type UserJson = { externalProfiles: {[key: string]: ExternalProfile} } & EntityJson;
export type Request = {
user: AbstractUser,
session: {
verified: boolean,
loginMethod: string
} & Session,
2023-04-30 21:19:50 +02:00
files: { [key: string]: UploadedFile },
remoteAddress: string
2023-04-17 13:10:45 +02:00
} & 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
}
2023-05-01 22:41:54 +02:00
export type EndpointOptions = {
path: string,
name: string,
auth?: MiddlewareFunction | true | null,
loadOrder?: number
2023-05-07 17:53:06 +02:00
}
export type RegistrationInvite = {
code: string,
validFor: number,
created: number
2023-05-01 22:41:54 +02:00
}