import type AuthModel from './user.js'; import './express-extension.js'; import type Express from 'express'; import type { Tx } from '../database-layer/db.js'; import type { ApiKey, User } from '../sbvr-api/sbvr-utils.js'; import * as sbvrUtils from '../sbvr-api/sbvr-utils.js'; import { type HookReq } from './hooks.js'; import { PermissionError, PermissionParsingError } from './errors.js'; import { type ODataRequest } from './uri-parser.js'; export { PermissionError, PermissionParsingError }; export interface PermissionReq { user?: User; apiKey?: ApiKey; } export declare const root: PermissionReq; export declare const rootRead: PermissionReq; interface NestedCheckOr { or: NestedCheckArray; } interface NestedCheckAnd { and: NestedCheckArray; } type NestedCheckArray = Array>; type NestedCheck = NestedCheckOr | NestedCheckAnd | NestedCheckArray | T; type PermissionCheck = NestedCheck; type MappedType = O extends NestedCheck ? Exclude | T, boolean> : Exclude | O, boolean>; type MappedNestedCheck, I, O> = T extends NestedCheckOr ? NestedCheckOr> : T extends NestedCheckAnd ? NestedCheckAnd> : T extends NestedCheckArray ? NestedCheckArray> : Exclude | O; export declare function nestedCheck(check: I, stringCallback: (s: string) => O): O; export declare function nestedCheck(check: I, stringCallback: (s: string) => O): boolean; export declare function nestedCheck, O>(check: NestedCheck, stringCallback: (s: string) => O): Exclude | O | MappedNestedCheck; export declare const checkPassword: (username: string, password: string) => Promise<{ id: number; actor: number; username: string; permissions: string[]; }>; export declare const getUserPermissions: (userId: number, tx?: Tx) => Promise; export declare const getApiKeyPermissions: (apiKey: string, tx?: Tx) => Promise; export declare const checkApiKey: (apiKey: string, tx?: Tx) => Promise; export declare const resolveAuthHeader: (req: Pick, tx: Tx | undefined, expectedScheme?: string) => Promise; export declare const canAccess: { readonly $fn: { readonly $scope: "Auth"; readonly $method: "canAccess"; }; }; export declare const customAuthorizationMiddleware: (expectedScheme?: string) => (req: Express.Request, _res?: Express.Response, next?: Express.NextFunction) => Promise; export declare const authorizationMiddleware: (req: Express.Request, _res?: Express.Response, next?: Express.NextFunction) => Promise; export declare const resolveApiKey: (req: HookReq | Express.Request, tx: Tx | undefined, paramName?: string) => Promise; export declare const customApiKeyMiddleware: (paramName?: string) => (req: HookReq | Express.Request, _res?: Express.Response, next?: Express.NextFunction) => Promise; export declare const apiKeyMiddleware: (req: HookReq | Express.Request, _res?: Express.Response, next?: Express.NextFunction) => Promise; export declare const checkPermissions: (req: PermissionReq, actionList: PermissionCheck, resourceName?: string, vocabulary?: string) => Promise>; export declare const checkPermissionsMiddleware: (action: PermissionCheck) => Express.RequestHandler; export declare const addPermissions: (req: PermissionReq, request: ODataRequest & { permissionType?: PermissionCheck; }) => Promise; declare module './sbvr-utils.js' { interface API { [authModelConfig.apiRoot]: PinejsClient; } } declare const authModelConfig: { readonly apiRoot: "Auth"; readonly modelText: string; readonly customServerCode: { readonly setup: typeof setup; }; readonly migrations: { readonly '11.0.0-modified-at': "\n\t\t\tALTER TABLE \"actor\"\n\t\t\tADD COLUMN IF NOT EXISTS \"modified at\" TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL;\n\n\t\t\tALTER TABLE \"api key\"\n\t\t\tADD COLUMN IF NOT EXISTS \"modified at\" TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL;\n\t\t\tALTER TABLE \"api key-has-permission\"\n\t\t\tADD COLUMN IF NOT EXISTS \"modified at\" TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL;\n\t\t\tALTER TABLE \"api key-has-role\"\n\t\t\tADD COLUMN IF NOT EXISTS \"modified at\" TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL;\n\n\t\t\tALTER TABLE \"permission\"\n\t\t\tADD COLUMN IF NOT EXISTS \"modified at\" TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL;\n\n\t\t\tALTER TABLE \"role\"\n\t\t\tADD COLUMN IF NOT EXISTS \"modified at\" TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL;\n\n\t\t\tALTER TABLE \"user\"\n\t\t\tADD COLUMN IF NOT EXISTS \"modified at\" TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL;\n\t\t\tALTER TABLE \"user-has-role\"\n\t\t\tADD COLUMN IF NOT EXISTS \"modified at\" TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL;\n\t\t\tALTER TABLE \"user-has-permission\"\n\t\t\tADD COLUMN IF NOT EXISTS \"modified at\" TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL;\n\t\t"; readonly '11.0.1-modified-at': "\n\t\t\tALTER TABLE \"role-has-permission\"\n\t\t\tADD COLUMN IF NOT EXISTS \"modified at\" TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL;\n\t\t"; readonly '14.42.0-api-key-expiry-date': "\n\t\t\tALTER TABLE \"api key\"\n\t\t\tADD COLUMN IF NOT EXISTS \"expiry date\" TIMESTAMP NULL;\n\t\t"; readonly '22.0.0-timestamps': (tx: Tx, { db }: typeof sbvrUtils) => Promise; }; }; export declare const config: { models: { readonly apiRoot: "Auth"; readonly modelText: string; readonly customServerCode: { readonly setup: typeof setup; }; readonly migrations: { readonly '11.0.0-modified-at': "\n\t\t\tALTER TABLE \"actor\"\n\t\t\tADD COLUMN IF NOT EXISTS \"modified at\" TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL;\n\n\t\t\tALTER TABLE \"api key\"\n\t\t\tADD COLUMN IF NOT EXISTS \"modified at\" TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL;\n\t\t\tALTER TABLE \"api key-has-permission\"\n\t\t\tADD COLUMN IF NOT EXISTS \"modified at\" TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL;\n\t\t\tALTER TABLE \"api key-has-role\"\n\t\t\tADD COLUMN IF NOT EXISTS \"modified at\" TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL;\n\n\t\t\tALTER TABLE \"permission\"\n\t\t\tADD COLUMN IF NOT EXISTS \"modified at\" TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL;\n\n\t\t\tALTER TABLE \"role\"\n\t\t\tADD COLUMN IF NOT EXISTS \"modified at\" TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL;\n\n\t\t\tALTER TABLE \"user\"\n\t\t\tADD COLUMN IF NOT EXISTS \"modified at\" TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL;\n\t\t\tALTER TABLE \"user-has-role\"\n\t\t\tADD COLUMN IF NOT EXISTS \"modified at\" TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL;\n\t\t\tALTER TABLE \"user-has-permission\"\n\t\t\tADD COLUMN IF NOT EXISTS \"modified at\" TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL;\n\t\t"; readonly '11.0.1-modified-at': "\n\t\t\tALTER TABLE \"role-has-permission\"\n\t\t\tADD COLUMN IF NOT EXISTS \"modified at\" TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL;\n\t\t"; readonly '14.42.0-api-key-expiry-date': "\n\t\t\tALTER TABLE \"api key\"\n\t\t\tADD COLUMN IF NOT EXISTS \"expiry date\" TIMESTAMP NULL;\n\t\t"; readonly '22.0.0-timestamps': (tx: Tx, { db }: typeof sbvrUtils) => Promise; }; }[]; }; export declare function setup(): void;