import { Constructor } from "@bluelibs/core" ; import { ObjectId } from "@bluelibs/ejson" ; export interface ISecurityBundleConfig { userPersistance ? : Constructor < IUserPersistance > ; sessionPersistance ? : Constructor < ISessionPersistance > ; permissionPersistance ? : Constructor < IPermissionPersistance > ; permissionTree ? : IPermissionTree ; session ? : { expiresIn ? : string ; cleanup ? : boolean ; cleanupInterval ? : string ; } ; } export type UserId = number | string | ObjectId ; export interface IUser { _id ? : UserId ; isEnabled : boolean ; createdAt : Date ; lastLoginAt ? : Date ; roles ? : string [ ] ; } export interface IFieldMap { [ key ] : number ; } export interface IPermissioning { addPermission ( userPermission ) : any ; hasPermission ( userId , permission , domain ? , domainIdentifier ? ) : boolean ; findPermission ( permission ? , userId ? , domain ? , domainIdentifier ? ) : IPermission ; findPermissions ( userId ? , permission ? , domain ? , domainIdentifier ? ) : IPermission [ ] ; removePermission ( userId , permission , domain ? , domainIdentifier ? ) : void ; removePermissions ( userId , permission ? , domain ? , domainIdentifier ? ) : void ; } export interface IUserPersistance { insertUser ( data ) : Promise < any > ; updateUser ( userId , data ) : Promise < void > ; deleteUser ( userId ) : Promise < void > ; findUser ( filters , fields ? ) : Promise < IUser > ; findUserById ( userId , fields ? ) : Promise < IUser > ; findThroughAuthenticationStrategy < T = any > ( strategyName , filters , fields ? ) : Promise < null | FindAuthenticationStrategyResponse < T > > ; removeAuthenticationStrategyData ( userId , authenticationStrategyName ) : Promise < void > ; updateAuthenticationStrategyData < T = any > ( userId , authenticationStrategyName , data ) : Promise < void > ; getAuthenticationStrategyData < T = any > ( userId , authenticationStrategyName , fields ? ) : Promise < Partial < T > > ; } export interface ISession { token : string ; userId : UserId ; expiresAt : Date ; data ? : ISessionData ; } export interface ISessionData { } export interface ISessionPersistance { param sessionData newSession ( userId , expiresAt , data ? ) : Promise < string > ; getSession ( token ) : Promise < ISession > ; deleteSession ( token ) : Promise < void > ; deleteAllSessionsForUser ( userId ) : Promise < void > ; /**
     * Cleanup old, no longer available, expired tokens
     */ cleanExpiredTokens ( ) : Promise < void > ; } export interface IPermissionPersistance { insertPermission ( permission ) : Promise < any > ; removePermission ( filters ) : Promise < void > ; countPermissions ( filters ) : Promise < number > ; findPermissions ( search ) : Promise < IPermission [ ] > ; findPermission ( search ) : Promise < IPermission > ; findDomains ( userId ) : Promise < string [ ] > ; } export interface IPermissionSearchFilter { userId ? : UserId | UserId [ ] ; permission ? : string | string [ ] ; domain ? : string | string [ ] ; domainIdentifier ? : string | string [ ] | ObjectId | ObjectId [ ] ; createdById ? : UserId | UserId [ ] ; } export interface IPermissionSearchFilters { userId ? : any [ ] ; permission ? : string [ ] ; domain ? : string [ ] ; domainIdentifier ? : string [ ] | ObjectId [ ] ; createdById ? : any [ ] ; } export interface IPermissionSearch { userId ? : any ; permission ? : string ; domain ? : string ; domainIdentifier ? : string | ObjectId ; createdById ? : any ; } export interface IPermission { userId : UserId ; permission : string ; domain : string ; domainIdentifier ? : string | ObjectId ; createdById ? : UserId ; } export interface IPermissionTree { [ key ] : number | IPermissionTree ; } export interface IPermissionService { add ( permission ) : Promise < void > ; remove ( permission ) : Promise < void > ; has ( permission ) : Promise < boolean > ; findPermissions ( search ) : Promise < IPermission [ ] > ; findPermission ( search ) : Promise < IPermission > ; findDomains ( userId ) : Promise < string [ ] > ; } export interface ISecurityService { /**
     * Returns userId
     */ createUser ( data ) : Promise < any > ; updateUser ( userId , data ) : Promise < void > ; deleteUser ( userId ) : Promise < void > ; findUser ( filters , fields ? ) : Promise < Partial < IUser > > ; findUserById ( userId , fields ? ) : Promise < Partial < IUser > > ; login ( userId , options ) : Promise < string > ; logout ( userId ) : Promise < void > ; createSession ( userId , options ? ) : Promise < string > ; getSession ( token ) : Promise < ISession > ; updateAuthenticationStrategyData < T = any > ( userId , strategyName , data ) : Promise < void > ; findThroughAuthenticationStrategy < T = any > ( strategyName , filters , fields ? ) : Promise < null | FindAuthenticationStrategyResponse < T > > ; getAuthenticationStrategyData < T = any > ( userId , strategyName , fields ? ) : Promise < Partial < T > > ; removeAuthenticationStrategyData ( userId , strategyName ) : Promise < any > ; isUserEnabled ( userId ) : Promise < boolean > ; enableUser ( userId ) : Promise < void > ; disableUser ( userId ) : Promise < void > ; } export interface FindAuthenticationStrategyResponse < T = any > { userId : UserId ; strategy : T ; } export interface ICreateSessionOptions { authenticationStrategy ? : string ; /**
     * This is for storing additional data inside the token that we may need later
     */ data ? : any ; /**
     * npm package zeit/ms format
     */ expiresIn ? : string ; }