@webda/core
Version:
Expose API with Lambda
223 lines (222 loc) • 5.51 kB
TypeScript
import { EventAuthenticationRegister, EventWithContext, Ident, OperationContext, Store, WebContext } from "../index.js";
import { CoreModel, CoreModelDefinition } from "../models/coremodel.js";
import { User } from "../models/user.js";
import { Authentication } from "./authentication.js";
import { NotificationService } from "./notificationservice.js";
import { DeepPartial, Service, ServiceParameters } from "./service.js";
interface InvitationAnswerBody {
accept: boolean;
}
interface Invitation {
/**
* User to invite to target
*/
users: string[];
/**
* Ident uuid to target
*/
idents: string[];
/**
* Any additional data to include with the invite
*/
metadata: any;
/**
* Notification info to pass to the notification service
*/
notification?: any;
}
/**
* Emitted when an invitation is sent
*/
export interface EventInvitationSent extends EventWithContext {
/**
* Invited users
*/
users: User[];
/**
* Invited idents if user is not registered yet
*/
idents: string[];
/**
* Metadata of the invite
*/
metadata: any;
/**
* Object targetted by the invite
*/
model: CoreModel;
}
/**
* Emitted when an invitation is removed
*/
export interface EventInvitationRemoved extends EventWithContext {
/**
* Invited users id
*/
users: string[];
/**
* Invited idents if user is not registered yet
*/
idents: string[];
/**
* Metadata of the invite
*/
metadata: any;
/**
* Object targetted by the invite
*/
model: CoreModel;
}
/**
* Emitted when an invitation is accepted
*/
export interface EventInvitationAnswered extends EventWithContext {
/**
* Object targetted by the invite
*/
model: CoreModel;
/**
* Metadata of the invite
*/
metadata: any;
/**
* If the invitation got accepted or not
*/
accept: boolean;
}
/**
*
*/
export declare class InvitationParameters extends ServiceParameters {
/**
* Name of the bean to use for Authentication
*
* @default Authentication
*/
authenticationService: string;
/**
* Notification service
*
* @default Mailer
*/
notificationService?: string;
/**
* Model to use
*/
model: string;
/**
* Used to store pending invitation
*/
invitationStore: string;
/**
* Fields to duplicate
*/
mapFields: string[];
/**
* Attribute to use for the mapping
*/
mapAttribute: string;
/**
* Attribute where to store once the invitation is accepted
*
* If attribute is __acls, the multiple will be ignored and the storage
* will be compatible with AclModel
*
* Where to store within the model User
*/
attribute: string;
/**
* Attribute where to store once the invitation is created and pending
*
* Where to store within the model Ident and User
*/
pendingAttribute: string;
/**
* Define if several invitation can be accepted or just one
*/
multiple: boolean;
/**
* Do not require a validation by the invitee
*/
autoAccept: boolean;
/**
* Email template to send to the user
*/
notification?: string;
constructor(params: any);
}
/**
* Allow to use invitation on AclModel
*
* Once you add a new ACE with a user, it will invite
* and act as Mapper
*
* @WebdaModda
*/
export default class InvitationService<T extends InvitationParameters = InvitationParameters> extends Service<T> {
authenticationService: Authentication;
notificationService: NotificationService;
invitationStore: Store<CoreModel>;
/**
* CoreModel to manage invitation on
*/
model: CoreModelDefinition;
/**
* @inheritdoc
*/
loadParameters(params: DeepPartial<T>): InvitationParameters;
/**
* @inheritdoc
*/
resolve(): this;
/**
* @inheritdoc
*/
init(): Promise<this>;
/**
* Accept or refuse for an invitation
* @param ctx
* @param model
*/
answerInvitation(ctx: WebContext<InvitationAnswerBody>, model: CoreModel): Promise<void>;
/**
* Update Model with pending and attribute
*
* @param model
*/
protected updateModel(model: CoreModel): Promise<void>;
/**
* Uninvite from previous invitations
* @param ctx
* @param model
*/
uninvite(ctx: OperationContext<Invitation>, model: CoreModel): Promise<void>;
/**
* Remove a model invitation from user
* @param user
*/
protected removeInvitationFromUser(user: string, model: string): Promise<void>;
/**
* Handle invitations all methods
*
* @param ctx
* @returns
*/
invite(ctx: WebContext): Promise<void>;
addInvitationToUser(model: CoreModel, user: User, inviter: User, metadata: any, notification?: any): Promise<void>;
sendNotification(user: User | Ident, replacements: any): Promise<void>;
/**
* Return which attribute would be used to store the invitation on ident invitation object
* @param uuid
* @returns
*/
getInvitationAttribute(uuid: string): string;
/**
* When a user register with an invited idents, managed the whole invitation process
*
* @param evt
* @returns
*/
registrationListener(evt: EventAuthenticationRegister): Promise<void>;
}
export {};