Files
turnosxpress/server/src/Models/WapServer/WapServer.Interface.ts
T

263 lines
7.2 KiB
TypeScript

import { IPayload } from "../SysAdminPayload/SysAdminPayload.interface";
import { IWapServerDocument } from "./WapServer.Adapter.Mongoose";
export type FindWapServerParams = {
id?: string;
name?: string;
description?: string;
countBots?: number;
maxBots?: number;
port?: number;
active?: boolean;
countBotsFrom?: number;
countBotsTo?: number;
};
export type AssingAvailableServerParams = {
companyId: string;
sessionUser: string;
};
export type BotEventParams = AssingAvailableServerParams & {};
export type BotRunningStatus =
| "created"
| "running"
| "paused"
| "restarting"
| "removing"
| "exited"
| "dead";
export type BotEventError = {
error: string;
code: number;
};
export enum SERVER_STATE {
"RUNNING" = "running",
"NOT_WORKING" = "not_working",
"NOT_ASSIGNED" = "not_assigned",
}
export enum BOT_STATE {
"EXISTS" = "exists",
"NOT_EXISTS" = "not_exists",
}
export enum BOT_SESSION_STATUS {
"LOGED" = "ok",
"UNLOGED" = "fail",
}
export type BotCheckStatus = {
state: BOT_STATE;
status: BotRunningStatus;
serverState: SERVER_STATE;
};
export type BotCheckSession = {
session: BOT_SESSION_STATUS;
};
export type SendBotMessageParams = {
companyId: string;
number: string;
message: string;
sessionUser: string;
};
export enum VALIDATE_BOT_ENVENT_ERRORS {
"INVALID_USER" = "invalid_user",
"INVALID_ORG" = "invalid_org",
"NO_PERMISSION" = "no_permission",
"NO_BOT_ALLOWED" = "no_bot_allowed",
"NO_SUBSCRIPTION_ACTIVE" = "no_subscription_active",
"NO_SERVER_ASSIGNED" = "no_server_assigned",
}
export interface ValidateBotEventStatus {
status: boolean;
error: string;
serverUrl?: string;
code?: VALIDATE_BOT_ENVENT_ERRORS;
}
export interface BotView {
exists: boolean;
runningState: BotRunningStatus;
serverId?: string;
serverName?: string;
serverDescription?: string;
serverState?: SERVER_STATE;
botSession?: BOT_SESSION_STATUS;
automaticNotifications: boolean;
}
export interface IWapServer {
id?: string;
name?: string;
description?: string;
ipv4: string;
ipv6: string;
countBots: number;
maxBots: number;
port: number;
active: boolean;
}
export type UpdateWapServerParams = {
serverId: string;
name?: string;
ipv4?: string;
port?: number;
maxBots?: number;
active?: boolean;
};
export type PaginateWapServerParams = FindWapServerParams & {
page: number;
limit: number;
};
export type PaginateWapServerResults = {
data: IWapServer[];
page: number;
pages: number;
};
export type SysAdminWapServerByIdParams = {
serverId: string;
};
export type SysAdminWapServerAuditParams = SysAdminWapServerByIdParams;
export type SysAdminWapServerRecalculateCountParams = SysAdminWapServerByIdParams;
export type SysAdminDeleteWapServerParams = SysAdminWapServerByIdParams;
export type SysAdminDeleteWapServerResult = {
serverId: string;
deleted: true;
};
export type SysAdminWapServerOrganizationActionParams = SysAdminWapServerByIdParams & {
organizationId: string;
};
export type SysAdminWapServerQrResult = {
serverId: string;
organizationId: string;
qr: string;
};
export type SysAdminWapServerDetachResult = {
serverId: string;
organizationId: string;
botDeleted: boolean;
botAlreadyMissing: boolean;
before: number;
after: number;
};
export type SysAdminWapServerDeleteBotResult = {
serverId: string;
organizationId: string;
assignmentRemains: true;
before: number;
after: number;
};
export type SysAdminWapAssignedOrganization = {
id: string;
name?: string;
};
export type SysAdminWapContainerDto = {
id?: string;
name?: string;
organizationId?: string;
image?: string;
state?: string;
status?: string;
ports?: unknown[];
created?: number;
};
export type SysAdminWapServerAuditResult = {
serverId: string;
assignedOrganizations: SysAdminWapAssignedOrganization[];
detectedBots: SysAdminWapContainerDto[];
validBots: SysAdminWapContainerDto[];
ghostBots: SysAdminWapContainerDto[];
missingBots: SysAdminWapAssignedOrganization[];
expectedCountBots: number;
storedCountBots: number;
runtimeCountBots: number;
countMismatch: boolean;
};
export type SysAdminWapServerRecalculateCountResult = {
serverId: string;
before: number;
after: number;
};
export type SysAdminGetWapServerParams = PaginateWapServerParams & {
payload: IPayload;
};
export type SysAdminUpdateWapServerParams = UpdateWapServerParams & {
payload: IPayload;
};
export type SysAdminAuditWapServerParams = SysAdminWapServerAuditParams & {
payload: IPayload;
};
export type SysAdminRecalculateWapServerCountParams = SysAdminWapServerRecalculateCountParams & {
payload: IPayload;
};
export type SysAdminDeleteWapServerRequest = SysAdminDeleteWapServerParams & {
payload: IPayload;
};
export type SysAdminWapServerOrganizationActionRequest = SysAdminWapServerOrganizationActionParams & {
payload: IPayload;
};
export interface IWapServerAdapter {
find(data: FindWapServerParams): Promise<IWapServer[]>;
findOne(data: FindWapServerParams): Promise<IWapServerDocument | null>;
delete(id: string): Promise<void>;
paginate(filters: PaginateWapServerParams): Promise<PaginateWapServerResults>;
}
export interface IWapServerManager {
servers: IWapServerAdapter;
findServers(): Promise<IWapServer[]>;
getAvailableServer(): Promise<IWapServer>;
assignAvailableServer(data: AssingAvailableServerParams): Promise<IWapServer>;
quitServer(data: AssingAvailableServerParams): Promise<void>;
createBot(data: BotEventParams): Promise<void>;
startBot(data: BotEventParams): Promise<void>;
stopBot(data: BotEventParams): Promise<void>;
deleteBot(data: BotEventParams): Promise<void>;
checkBot(data: BotEventParams): Promise<BotCheckStatus>;
checkSession(data: BotEventParams): Promise<BotCheckSession>;
botView(data: BotEventParams): Promise<BotView>;
getQr(data: BotEventParams): Promise<string>;
sendMessage(data: SendBotMessageParams): Promise<void>;
sysAdminGetWapServers(data: PaginateWapServerParams): Promise<PaginateWapServerResults>;
sysAdminUpdateWapServer(data: UpdateWapServerParams): Promise<IWapServer>;
sysAdminAuditWapServer(data: SysAdminWapServerAuditParams): Promise<SysAdminWapServerAuditResult>;
sysAdminRecalculateWapServerCount(data: SysAdminWapServerRecalculateCountParams): Promise<SysAdminWapServerRecalculateCountResult>;
sysAdminDeleteWapServer(data: SysAdminDeleteWapServerParams): Promise<SysAdminDeleteWapServerResult>;
sysAdminStartBot(data: SysAdminWapServerOrganizationActionParams): Promise<void>;
sysAdminStopBot(data: SysAdminWapServerOrganizationActionParams): Promise<void>;
sysAdminRestartBot(data: SysAdminWapServerOrganizationActionParams): Promise<void>;
sysAdminGetQr(data: SysAdminWapServerOrganizationActionParams): Promise<SysAdminWapServerQrResult>;
sysAdminDeleteBot(data: SysAdminWapServerOrganizationActionParams): Promise<SysAdminWapServerDeleteBotResult>;
sysAdminDetachOrganizationServer(data: SysAdminWapServerOrganizationActionParams): Promise<SysAdminWapServerDetachResult>;
}