import { Topic } from "@webiny/pubsub/types"; import { SecurityContext } from "@webiny/api-security/types"; import { TenancyContext } from "@webiny/api-tenancy/types"; export interface AdminUsersContext extends SecurityContext, TenancyContext { adminUsers: AdminUsers; } export interface CreatedBy { id: string; displayName: string | null; type: string; } export interface BaseUserAttributes { id: string; displayName: string; email: string; groups?: string[]; teams?: string[]; firstName?: string; lastName?: string; avatar?: Record; external?: boolean; } export interface CreateUserInput extends Omit { id?: string; displayName?: string; password?: string; } export type UpdateUserInput = Partial>; export interface AdminUser extends BaseUserAttributes { tenant: string; createdOn: string; createdBy: CreatedBy | null | undefined; webinyVersion: string; } export interface GetUserParams { where: { id?: string; email?: string; tenant?: string; }; } export interface ListUsersParams { where?: { id_in?: string[]; }; sort?: string[]; } export interface CreateUserEvent { /** * New user attributes. */ user: AdminUser; /** * Input data used to create the new user (e.g., from GraphQL resolver). */ inputData: CreateUserInput; } export interface BeforeUpdateEvent { /** * User object that will be updated. */ user: AdminUser; /** * Input data that should update the existing user (e.g., from GraphQL resolver). */ readonly inputData: Record; /** * An object containing values that will be assigned to `user`. * This object is a clone of the `inputData`, and it gives you an opportunity to validate input, * or add/remove/modify attributes before they're assigned to the original `user` record. * `updateData` is assigned to the `user` object using simple `Object.assign`. */ updateData: Partial>; } export interface AfterUpdateEvent { /** * User object that was updated. */ updatedUser: AdminUser; /** * User object prior to being updated. */ originalUser: AdminUser; /** * Input data (e.g., from GraphQL resolver). */ readonly inputData: Record; } export interface BeforeDeleteEvent { /** * User to be deleted. */ user: AdminUser; } export interface AfterDeleteEvent { /** * User that was deleted. */ user: AdminUser; } export interface CreateErrorEvent { user: AdminUser; inputData: CreateUserInput; error: Error; } export interface UpdateErrorEvent { user: AdminUser; inputData: UpdateUserInput; error: Error; } export interface DeleteErrorEvent { user: AdminUser; error: Error; } export interface ErrorEvent extends InstallEvent { error: Error; } export interface InstallEvent { tenant: string; user: InstallParams; } export interface InstallParams { firstName: string; lastName: string; email: string; password: string; groups?: string[]; teams?: string[]; } export interface AdminUsers { onUserBeforeCreate: Topic; onUserAfterCreate: Topic; onUserBeforeUpdate: Topic; onUserAfterUpdate: Topic; onUserBeforeDelete: Topic; onUserAfterDelete: Topic; onSystemBeforeInstall: Topic; /** * Errors */ onUserCreateError: Topic; onUserUpdateError: Topic; onUserDeleteError: Topic; /** * This will be executed during Webiny installation. */ onInstall: Topic; onSystemAfterInstall: Topic; onCleanup: Topic; getStorageOperations(): AdminUsersStorageOperations; isEmailTaken(email: string): Promise; getUser(params: GetUserParams): Promise; listUsers(params?: ListUsersParams): Promise; createUser(data: CreateUserInput): Promise; updateUser(id: string, data: UpdateUserInput): Promise; deleteUser(id: string): Promise; getVersion(): Promise; setVersion(version: string): Promise; install(params: InstallParams): Promise; } export interface StorageOperationsListUsersParams extends ListUsersParams { where: ListUsersParams["where"] & { tenant: string; }; } export interface StorageOperationsGetUserParams extends GetUserParams { where: GetUserParams["where"] & { tenant: string; }; } export interface StorageOperationsCreateUserParams { user: TUser; } export interface StorageOperationsUpdateUserParams { user: TUser; } export interface StorageOperationsDeleteUserParams { user: TUser; } export interface System { tenant: string; version: string; } export interface StorageOperationsGetSystemParams { tenant: string; } export interface StorageOperationsCreateSystemParams { system: System; } export interface StorageOperationsUpdateSystemParams { system: System; } export interface AdminUsersStorageOperations { getUser(params: StorageOperationsGetUserParams): Promise; listUsers(params: StorageOperationsListUsersParams): Promise; createUser(params: StorageOperationsCreateUserParams): Promise; updateUser(params: StorageOperationsUpdateUserParams): Promise; deleteUser(params: StorageOperationsDeleteUserParams): Promise; getSystemData(params: StorageOperationsGetSystemParams): Promise; createSystemData(params: StorageOperationsCreateSystemParams): Promise; updateSystemData(params: StorageOperationsUpdateSystemParams): Promise; }