import { ClearHttpContext, Request, Response } from "clear-router"; import { MiddlewareClass, MiddlewareInstance, RequestData } from "clear-router/types/basic"; import { User } from "@app/models/User"; //#region src/Response.d.ts declare const setResponseResolver: (resolver?: () => Response$1 | undefined) => void; /** * Represents an HTTP response, providing a consistent interface for accessing response data. * * @author 3m1n3nc3 */ declare class Response$1 extends Response { body: TBody; readonly source?: unknown; constructor(options?: { statusCode?: number; headers?: HeaderSource; body?: TBody; source?: unknown; }); static from(source?: Response$1 | ResponseSource): Response$1 | undefined; status(code: number): this; header(name: string, value: string): this; getHeaders(): HeaderMap; json(body: TBody): any; send(body: TBody): any; } //#endregion //#region src/session/FlashBag.d.ts declare class FlashBag { protected bag: Record; private sweepKeys; constructor(items?: Record); put(key: string, value: T): this; set(key: string, value: T): this; get(key: string, defaultValue?: T): T; has(key?: string | string[] | null): boolean; any(): boolean; isEmpty(): boolean; isNotEmpty(): boolean; keys(): string[]; all(): { [x: string]: T; }; clear(key?: string | string[]): this; forget(key: string): this; markForSweep(keys?: string[]): this; sweep(): this; toJSON(): { [x: string]: T; }; } //#endregion //#region src/session/types.d.ts type SessionDriverType = 'file' | 'cookie' | 'database' | SessionDriver; type SessionErrorValue = string | string[] | Error | unknown; type SessionErrorRecord = Record; interface SessionMessageProvider { getMessageBag?: () => SessionMessageProvider; getMessages?: () => SessionErrorRecord; messagesRaw?: () => SessionErrorRecord; toArray?: () => SessionErrorRecord; all?: (...args: any[]) => SessionErrorRecord | string[]; errors?: (() => SessionErrorRecord | SessionMessageProvider) | SessionErrorRecord | SessionMessageProvider; } type SessionErrorSource = SessionErrorRecord | ErrorBag | SessionMessageProvider; interface SessionInitialState { data?: Record; errors?: SessionErrorSource; flash?: Record | FlashBag; } type SessionPayload = { data?: Record; errors?: SessionErrorRecord; flash?: Record; }; type cookie_options = { path?: string; domain?: string; httpOnly?: boolean; secure?: boolean; sameSite?: 'Strict' | 'Lax' | 'None'; maxAge?: number; expires?: Date; }; type HttpContextLike = Record; type SessionDriverResult = { id: string; state?: SessionPayload; save: (payload: SessionPayload) => void | Promise; destroy?: () => void | Promise; }; interface SessionDriver { start(context: HttpContextLike): Promise; } type BaseSessionDriverOptions = { cookie?: string; secret?: string; ttl?: number; cookie_options?: cookie_options; }; type DatabaseSessionDriverOptions = BaseSessionDriverOptions & { table?: string; }; type PersistentSessionConfig = { driver?: SessionDriverType; cookie?: string; secret?: string; ttl?: number; cookie_options?: cookie_options; file?: { directory?: string; }; database?: { table?: string; }; }; type SessionConfig = { secret?: string; driver?: SessionDriverType; cookie?: string; ttl?: number; http_only?: boolean; secure?: boolean; same_site?: cookie_options['sameSite']; path?: string; table?: string; directory?: string; }; //#endregion //#region src/session/ErrorBag.d.ts declare class ErrorBag extends FlashBag { constructor(errors?: SessionErrorSource); add(field: string, message: SessionErrorValue): this; addIf(condition: boolean, field: string, message: SessionErrorValue): this; merge(errors: SessionErrorSource): ErrorBag; validation(error: unknown): ErrorBag; keys(): string[]; get(field?: string): string[]; first(field?: string | null): string; has(field?: string | string[] | null): boolean; hasAny(fields: string | string[]): boolean; missing(fields: string | string[]): boolean; any(): boolean; isEmpty(): boolean; isNotEmpty(): boolean; count(): number; all(): never; unique(): unknown[]; clear(field?: string | string[]): this; forget(field: string): this; messagesRaw(): Record; getMessages(): Record; getMessageBag(): this; toArray(): Record; toJSON(): Record; } //#endregion //#region src/session/Session.d.ts declare const setSessionResolver: (resolver?: () => Session | undefined) => void; declare const clearFallbackSession: () => void; declare class Session { readonly errors: ErrorBag; readonly flashBag: FlashBag; readonly id?: string; private data; private persistent?; private saveQueue; constructor(initial?: SessionInitialState | Record | Session, persistent?: SessionDriverResult); private snapshot; private queuePersist; save(): Promise; destroy(): Promise; /** * Get an item from the session bag * * @param key * @param defaultValue * @returns */ get(key: string, defaultValue?: T): T; /** * Add an item to the session bag * * @param key * @param defaultValue * @returns */ put(key: string, value: T): this; /** * Add an item to the session bag * * @param key * @param defaultValue * @returns */ set(key: string, value: T): this; /** * Check if an item exist in the session bag * * @param key * @returns */ has(key: string): boolean; /** * Remove an item from the session bag * * @param key * @returns */ forget(key: string): this; /** * Clear the session bag * * @returns */ clear(): this; /** * Get all items in the session bag * * @returns */ all(): { [x: string]: any; }; /** * Add a flash item for the next request * * @param key * @param value * @returns */ flash(key: string, value: T): this; /** * Get a flash item * * @param key * @param defaultValue * @returns */ getFlash(key: string, defaultValue?: T): T; /** * Sweep flashed data that was loaded for this request * * @returns */ sweepFlash(): Promise; /** * Add an error to the session error bag * * @param field * @param message * @returns */ addError(field: string, message: SessionErrorValue): this; /** * Add multiple errors to the session error bag * * @param errors * @returns */ addErrors(errors: SessionErrorRecord | ErrorBag): this; /** * Add a validation error to the session error bag * * @param error * @returns */ addValidationErrors(error: unknown): this; /** * Check if the session error bag has any errors * * @param field * @returns */ hasErrors(field?: string): boolean; /** * Clear all errors in the session error bag * * @param field * @returns */ clearErrors(field?: string): this; /** * Parse session for views * * @returns */ forView(): { errors: ErrorBag; flash: FlashBag; }; /** * Return session as json * * @returns */ toJSON(): { errors: Record; flash: { [x: string]: unknown; }; }; } //#endregion //#region src/plugins.d.ts declare const arkstackHttpPlugin: import("clear-router").ClearRouterPlugin; declare const kanunSessionPlugin: import("kanun").ValidatorPlugin; //#endregion //#region src/session/helpers.d.ts declare const registerResponseFlashSweep: (target: unknown, session?: Session) => void; declare const attachViewState: (target: Record, session: Session) => void; /** * Ensure a valid session exists * * @param ctx * @param initial * @returns */ declare const ensureSession: (ctx: unknown, initial?: SessionInitialState | Record, persistent?: SessionDriverResult) => Session; /** * Get the current session * * @param ctx * @returns */ declare const getSession: (ctx: unknown) => Session | undefined; //#endregion //#region src/session/config.d.ts declare const createSessionDriver: (config?: PersistentSessionConfig) => SessionDriver; declare const configureSession: (config: PersistentSessionConfig | SessionDriver) => SessionDriver; declare const getSessionDriver: () => SessionDriver; //#endregion //#region src/session/cookie.d.ts declare const generateSessionId: () => string; declare const signValue: (value: string, secret: string) => string; declare const encodeSignedValue: (value: string, secret: string) => string; declare const decodeSignedValue: (value: string | undefined, secret: string) => string | undefined; declare const encodeJson: (value: unknown) => string; declare const decodeJson: (value: string | undefined) => T | undefined; declare const parseCookies: (header?: string | string[] | null) => Record; declare const getCookie: (context: HttpContextLike, name: string) => string; declare const serializeCookie: (name: string, value: string, options?: cookie_options) => string; declare const setCookie: (context: HttpContextLike, name: string, value: string, options?: cookie_options) => string; //#endregion //#region src/session/encryption.d.ts declare const encryptSessionValue: (value: string, secret: string) => string; declare const decryptSessionValue: (payload: string | undefined, secret: string) => string | undefined; //#endregion //#region src/session/serialization.d.ts declare const encodeSessionPayload: (payload: SessionPayload & { id?: string; }) => string; declare const decodeSessionPayload: (value: string | undefined) => T | undefined; //#endregion //#region src/session/drivers/BaseSessionDriver.d.ts declare abstract class BaseSessionDriver implements SessionDriver { readonly cookie: string; readonly secret: string; readonly ttl?: number; readonly cookie_options: cookie_options; constructor(options?: BaseSessionDriverOptions); protected readSessionId(context: HttpContextLike): string | undefined; protected encryptPayload(value: string): string; protected decryptPayload(value: string | undefined): string | undefined; protected writeSessionId(context: HttpContextLike, id: string): void; abstract start(context: HttpContextLike): Promise; } //#endregion //#region src/session/drivers/CookieSessionDriver.d.ts declare class CookieSessionDriver extends BaseSessionDriver { start(context: HttpContextLike): Promise; } //#endregion //#region src/session/drivers/DatabaseSessionDriver.d.ts declare class DatabaseSessionDriver extends BaseSessionDriver { readonly tableName: string; constructor(options?: DatabaseSessionDriverOptions); start(context: HttpContextLike): Promise; } //#endregion //#region src/session/drivers/FileSessionDriver.d.ts declare class FileSessionDriver extends BaseSessionDriver { readonly directory: string; constructor(options?: BaseSessionDriverOptions & { directory?: string; }); private path; start(context: HttpContextLike): Promise; } //#endregion //#region src/types/Http.d.ts type HeaderValue = string | string[] | number | boolean | null | undefined; type HeaderMap = Record; type HeaderSource = Headers | Record; type FunctionMiddleware = (...args: any[]) => any; type ClassMiddleware = new (...args: any[]) => { handle: FunctionMiddleware; }; type RequestSource = { headers?: HeaderSource; method?: string; url?: string; originalUrl?: string; path?: string; ip?: string; user?: TUser; auth?: unknown; authUser?: TUser; authToken?: string; req?: RequestSource; request?: RequestSource; original?: RequestSource; }; type ResponseSource = { statusCode?: number; status?: number | ((code: number) => unknown); headers?: HeaderSource; setHeader?: (name: string, value: string | string[]) => unknown; getHeader?: (name: string) => string | string[] | number | undefined; json?: (body: unknown) => unknown; send?: (body: unknown) => unknown; redirect?: (status: number, path: string) => unknown; }; type RequestOptions = { body?: Record; query?: Record; params?: Record; route?: any; ctx?: any; headers?: HeaderSource; method?: string; url?: string; path?: string; ip?: string | null; user?: TUser; auth?: unknown; authUser?: TUser; authToken?: string; source?: unknown; original?: unknown; }; interface RequestHelper { (): Request$1; (key: X): Request$1['body'][X]; } interface SessionHelper { (): Session; (key: X): any; } interface RedirectHelper { (): Response$1; (to?: string, status?: number): Response$1; } interface OldHelper { (): Record; (key: string, defaultValue?: T): T; } //#endregion //#region src/Request.d.ts declare const setRequestResolver: (resolver?: () => Request$1 | undefined) => void; /** * Represents an HTTP request, providing a consistent interface for accessing request data. * * @author 3m1n3nc3 */ declare class Request$1 extends Request { readonly headers: HeaderMap; readonly ip: string | null; readonly source?: unknown; private currentUser?; private currentAuth?; private currentAuthUser?; private currentAuthToken?; get user(): TUser | undefined; set user(user: TUser | undefined); get auth(): unknown; set auth(auth: unknown); get authUser(): TUser | undefined; set authUser(user: TUser | undefined); get authToken(): string | undefined; set authToken(token: string | undefined); constructor(options?: RequestOptions); static from(source?: Request$1 | RequestSource): Request$1 | undefined; header(name: string): string; bearerToken(): string | null; setUser(user: TUser): this; setAuthentication(auth: TAuth, user: TUser, token?: string): this; syncFromSource(): this; private getSourceRequest; clearAuthentication(): this; } //#endregion //#region src/helpers.d.ts declare const unwrapRequestSource: (source: RequestSource) => RequestSource; declare const makeHeaders: (headers?: HeaderSource) => Headers; declare const normalizeHeaders: (headers?: HeaderSource) => HeaderMap; declare const normalizeHeaderValue: (value: HeaderValue) => string | undefined; declare const isHeaders: (value: unknown) => value is Headers; declare const isRecord: (value: unknown) => value is Record; /** * Resolve Middleware * * @param middleware * @returns */ declare const resolveMiddleware: (middleware: T) => T extends MiddlewareClass ? InstanceType["handle"] : T extends MiddlewareInstance ? T["handle"] : T; //#endregion //#region src/redirect.d.ts declare const redirectBackTarget: (fallback?: string) => string; declare const resolveRedirectTarget: (to?: string, fallback?: string) => string; declare const redirect: (to?: string, status?: number) => Response$1; //#endregion //#region src/old.d.ts declare const old: (key?: string, defaultValue?: T) => T; //#endregion //#region src/middlewares/web.d.ts declare const webMiddlewareKey: unique symbol; declare const web: (...args: any[]) => Promise; declare const isWebRequest: (target: unknown) => boolean; //#endregion export { registerResponseFlashSweep as $, DatabaseSessionDriver as A, encodeSignedValue as B, RedirectHelper as C, setResponseResolver as Ct, ResponseSource as D, RequestSource as E, decryptSessionValue as F, setCookie as G, getCookie as H, encryptSessionValue as I, createSessionDriver as J, signValue as K, decodeJson as L, BaseSessionDriver as M, decodeSessionPayload as N, SessionHelper as O, encodeSessionPayload as P, getSession as Q, decodeSignedValue as R, OldHelper as S, Response$1 as St, RequestOptions as T, parseCookies as U, generateSessionId as V, serializeCookie as W, attachViewState as X, getSessionDriver as Y, ensureSession as Z, ClassMiddleware as _, SessionInitialState as _t, redirect as a, ErrorBag as at, HeaderSource as b, cookie_options as bt, isHeaders as c, HttpContextLike as ct, normalizeHeaderValue as d, SessionDriver as dt, arkstackHttpPlugin as et, normalizeHeaders as f, SessionDriverResult as ft, setRequestResolver as g, SessionErrorValue as gt, Request$1 as h, SessionErrorSource as ht, old as i, setSessionResolver as it, CookieSessionDriver as j, FileSessionDriver as k, isRecord as l, PersistentSessionConfig as lt, unwrapRequestSource as m, SessionErrorRecord as mt, web as n, Session as nt, redirectBackTarget as o, BaseSessionDriverOptions as ot, resolveMiddleware as p, SessionDriverType as pt, configureSession as q, webMiddlewareKey as r, clearFallbackSession as rt, resolveRedirectTarget as s, DatabaseSessionDriverOptions as st, isWebRequest as t, kanunSessionPlugin as tt, makeHeaders as u, SessionConfig as ut, FunctionMiddleware as v, SessionMessageProvider as vt, RequestHelper as w, HeaderValue as x, FlashBag as xt, HeaderMap as y, SessionPayload as yt, encodeJson as z };