UNPKG

@perfood/couch-auth

Version:

Easy and secure authentication for CouchDB/Cloudant. Based on SuperLogin, updated and rewritten in Typescript.

60 lines (59 loc) 3.02 kB
import { Request } from 'express'; import { DocumentScope, ServerScope } from 'nano'; import { Config, DBServerConfig, SessionConfigEntry } from './types/config'; import { ConsentRequest, ConsentSlEntry, SlUserDoc } from './types/typings'; export declare const EMAIL_REGEXP: RegExp; export declare const USER_REGEXP: RegExp; export declare function URLSafeUUID(): string; export declare function getSessionKey(): string; export declare function generateSlUserKey(): string; export declare function hyphenizeUUID(uuid: string): string; export declare function removeHyphens(uuid: string): string; export declare function hashToken(token: string): string; export declare function putSecurityDoc(server: ServerScope, db: DocumentScope<any>, doc: any): Promise<any>; export declare function getSecurityDoc(server: ServerScope, db: DocumentScope<any>): Promise<any>; /** returns the Cloudant url - including credentials, if `CLOUDANT_PASS` is provided. */ export declare function getCloudantURL(): string; /** @internal @deprecated - only used in tests */ export declare function getDBURL(db: DBServerConfig): any; export declare function getFullDBURL(dbConfig: DBServerConfig, dbName: string): string; export declare function toArray<T>(obj: T): Array<T>; /** * extracts the session keys from the SlUserDoc */ export declare function getSessions(userDoc: SlUserDoc): string[]; export declare function getExpiredSessions(userDoc: SlUserDoc, now: number): string[]; /** * Takes a req object and returns the bearer token, or undefined if it is not found */ export declare function getSessionToken(req: Request): string; /** * Generates views for each registered provider in the user design doc */ export declare function addProvidersToDesignDoc(config: Partial<Config>, ddoc: any): any; /** Capitalizes the first letter of a string */ export declare function capitalizeFirstLetter(str: string): string; /** * adds the nested properties of `source` to `dest`, overwriting present entries */ export declare function mergeConfig(dest: any, source: any): any; /** * Concatenates two arrays and removes duplicate elements * * @param a First array * @param b Second array * @return resulting array */ export declare function arrayUnion<T>(a: Array<T>, b: Array<T>): T[]; /** * return `true` if the passed object has the format * of errors thrown by SuperLogin itself, i.e. it has * `status`, `error` and optionally one of * `validationErrors` or `message`. */ export declare function isUserFacingError(errObj: any): boolean; export declare function replaceAt(str: string, idx: number, repl: string): string; export declare function timeoutPromise(duration: any): Promise<unknown>; export declare function extractCurrentConsents(userDoc: SlUserDoc): Record<string, ConsentSlEntry>; export declare function verifyConsentUpdate(consentUpdate: Record<string, ConsentRequest>, config: Config): string | void; export declare function verifySessionConfigRoles(roles: string[], sessionConfig: SessionConfigEntry): void;