webserver-framework/@types/Server.ts

225 lines
5.3 KiB
TypeScript
Raw Normal View History

2023-04-17 13:10:45 +02:00
import { LoggerClientOptions } from '@navy.gif/logger';
2023-05-08 19:47:10 +02:00
import { BrokerOptions, MariaOptions, MongoOptions, ObjectId } from '@navy.gif/wrappers';
2023-07-13 19:15:13 +02:00
import { Request as ExpressRequest, Response as ExpressResponse, NextFunction } from 'express';
2023-04-17 13:10:45 +02:00
import http from 'http';
2023-07-13 19:15:13 +02:00
import { UploadedFile } from 'express-fileupload';
import { Session } from 'express-session';
import AbstractUser from '../src/server/interfaces/AbstractUser.js';
import { Role } from '../src/server/structures/index.js';
2023-04-17 13:10:45 +02:00
/**
* TERMINOLOGY
* Data: Any JSON structured data stored in the database
* Opt(ion)s: Variables passed to functions/constructors
* Json: Any JSON structured data that can be passed to the consumers of the endpoints (i.e. returned to the user)
*
*/
export type PwResetToken = {
token: string,
valid: number,
user: string
}
export type PwResetTokenQuery = {
token?: string,
user?: string
}
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 = {
endpointsPath: string
2023-04-17 13:10:45 +02:00
}
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,
2023-05-15 17:05:30 +02:00
mongodb?: MongoOptions,
broker?: BrokerOptions
2023-04-17 13:10:45 +02:00
},
logger?: LoggerClientOptions,
domain: string,
serveFiles: string,
registrationEnabled: boolean,
requireCodeForRegister: boolean,
OAuthProviders: OAuthProvider[],
callbackPath: string,
discord: {
scope?: string[],
version?: number
2023-07-13 19:15:13 +02:00
},
sweeperInterval?: number
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,
permissionsDisabled?: boolean,
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,
roles?: (Role|RoleData|string)[],
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,
requestPasswordReset?: boolean,
requirePasswordReset?: boolean
2023-04-17 13:10:45 +02:00
} & 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 ParsedQuery = {
[key: string]: string | number | boolean | undefined,
page?: number,
pageSize?: number,
sort?: 'newest' | 'oldest',
userId?: string | number,
rangeStart?: number,
rangeEnd?: number,
timeInterval?: number
}
2023-04-17 13:10:45 +02:00
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,
parsedQuery?: ParsedQuery,
skipBodyLog?: boolean
2023-04-17 13:10:45 +02:00
} & ExpressRequest
export type Response = {
sentContent: string
2023-04-17 13:10:45 +02:00
} & 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 AuthFunction = (req: Request, res: Response, next: NextFunction) => void
export type ExtendedServerOptions = {
//
} & ServerOptions
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-07-16 23:56:49 +02:00
}
// Types for these don't matter for the server as they're only used by the client
export type GlobalClientSettings = object
export type UserClientSettings = object
export type ClientSettings = {
global: GlobalClientSettings,
user?: UserClientSettings
2023-05-01 22:41:54 +02:00
}