@webda/core
Version:
Expose API with Lambda
127 lines (126 loc) • 3.02 kB
TypeScript
import { CoreModel } from "../models/coremodel.js";
import CryptoService, { JWTOptions } from "../services/cryptoservice.js";
import { DeepPartial, Service, ServiceParameters } from "../services/service.js";
import { Store } from "../stores/store.js";
import { OperationContext } from "./context.js";
import { CookieOptions } from "./cookie.js";
/**
* Manage load and save of sessions
*/
export declare abstract class SessionManager<T extends ServiceParameters = ServiceParameters> extends Service<T> {
/**
* Load a session based on context
* @param context
*/
abstract load(context: OperationContext): Promise<Session>;
/**
* Save the session within the context
* @param context
* @param session
*/
abstract save(context: OperationContext, session: Session): Promise<void>;
/**
* Create a new session
*/
abstract newSession(context: OperationContext): Promise<Session>;
}
export declare class CookieSessionParameters extends ServiceParameters {
/**
* Options for issue JWT token
*/
jwt?: JWTOptions;
/**
* Cookie configuration for session
*/
cookie?: CookieOptions;
constructor(params: any);
}
/**
* SessionManager that store info in a cookie
*
* If SessionStore service exists, only uuid is in the cookie
* the rest of data is stored within the session store
*
* @WebdaModda
*/
export declare class CookieSessionManager<T extends CookieSessionParameters = CookieSessionParameters> extends SessionManager<T> {
cryptoService: CryptoService;
sessionStore: Store<CoreModel & {
session: any;
}>;
/**
* @override
*/
loadParameters(params: DeepPartial<T>): ServiceParameters;
/**
* @override
*/
resolve(): this;
/**
* @override
*/
load(context: OperationContext): Promise<Session>;
/**
* @override
*/
newSession(context: OperationContext<any, any>): Promise<Session>;
/**
* @override
*/
save(context: OperationContext, session: Session): Promise<void>;
}
/**
* Session
*/
export declare class Session {
protected changed: boolean;
/**
* Session uuid
*/
uuid: string;
/**
* User id
*/
userId: string;
/**
* Ident used
*/
identUsed: string;
/**
* User current roles
*/
roles: string[];
/**
* Login
* @param userId
* @param identUsed
*/
login(userId: string, identUsed: string): void;
/**
* Logout
*/
logout(): void;
/**
* If session is authenticated
*/
isLogged(): boolean;
/**
* Session is dirty and requires save
* @returns
*/
isDirty(): boolean;
/**
* Get the proxy to be able to track modification
* @returns
*/
getProxy(): this;
}
/**
* Unknown session that allows all keys
*/
export declare class UnknownSession extends Session {
/**
* Allow any type of fields
*/
[key: string]: any;
}