@in.pulse-crm/sdk 1.3.9 → 1.3.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +6 -4
- package/dist/index.js +3 -5
- package/dist/report.d.ts +5 -12
- package/dist/report.js +0 -13
- package/dist/socket-client.d.ts +25 -65
- package/dist/socket-client.js +32 -7
- package/dist/socket-server.d.ts +1 -151
- package/dist/socket-server.js +0 -15
- package/dist/types/socket-client.types.d.ts +97 -0
- package/dist/types/socket-client.types.js +2 -0
- package/dist/types/socket-server.types.d.ts +116 -0
- package/dist/types/socket-server.types.js +2 -0
- package/package.json +1 -1
- package/src/index.ts +49 -26
- package/src/report.ts +5 -12
- package/src/socket-client.ts +20 -90
- package/src/socket-server.ts +1 -205
- package/src/types/socket-client.types.ts +114 -0
- package/src/types/socket-server.types.ts +169 -0
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,9 @@ import FileSDK, { File, FileDirType } from "./file";
|
|
|
3
3
|
import InstanceSDK from "./instance";
|
|
4
4
|
import UserSDK, { CreateUserDTO, UpdateUserDTO, User, UserRole } from "./user";
|
|
5
5
|
import { DataResponse, ErrorResponse, PaginatedResponse, QueryResponse } from "./response";
|
|
6
|
-
import ReportSDK, { ChatsReport,
|
|
7
|
-
import SocketClientSDK
|
|
8
|
-
import SocketServerSDK
|
|
9
|
-
|
|
6
|
+
import ReportSDK, { ChatsReport, ChatsReportFormat, GenerateChatsReportOptions } from "./report";
|
|
7
|
+
import SocketClientSDK from "./socket-client";
|
|
8
|
+
import SocketServerSDK from "./socket-server";
|
|
9
|
+
import { ChatsReportStatusData, SocketServerAdminRoom, SocketServerMonitorRoom, SocketServerReportsRoom, SocketServerRoom, ChatId, QRCode, SocketEventType } from "./types/socket-server.types";
|
|
10
|
+
import { SocketChatRoom, SocketClientAdminRoom, SocketClientMonitorRoom, SocketClientReportsRoom, SocketClientRoom } from "./types/socket-client.types";
|
|
11
|
+
export { AuthSDK, LoginData, SessionData, FileSDK, File, FileDirType, InstanceSDK, UserSDK, CreateUserDTO, UpdateUserDTO, User, UserRole, DataResponse, ErrorResponse, PaginatedResponse, QueryResponse, ReportSDK, ChatsReport, ChatsReportFormat as ChatsReportFileFormat, GenerateChatsReportOptions, SocketClientSDK, SocketChatRoom, SocketClientAdminRoom, SocketClientMonitorRoom, SocketClientReportsRoom, SocketClientRoom, SocketServerSDK, SocketEventType, ChatsReportStatusData, SocketServerAdminRoom, SocketServerMonitorRoom, SocketServerReportsRoom, SocketServerRoom, ChatId, QRCode, };
|
package/dist/index.js
CHANGED
|
@@ -36,7 +36,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
36
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.
|
|
39
|
+
exports.SocketServerSDK = exports.SocketClientSDK = exports.ReportSDK = exports.UserRole = exports.UserSDK = exports.InstanceSDK = exports.FileDirType = exports.FileSDK = exports.AuthSDK = void 0;
|
|
40
40
|
const auth_1 = __importDefault(require("./auth"));
|
|
41
41
|
exports.AuthSDK = auth_1.default;
|
|
42
42
|
const file_1 = __importStar(require("./file"));
|
|
@@ -47,11 +47,9 @@ exports.InstanceSDK = instance_1.default;
|
|
|
47
47
|
const user_1 = __importStar(require("./user"));
|
|
48
48
|
exports.UserSDK = user_1.default;
|
|
49
49
|
Object.defineProperty(exports, "UserRole", { enumerable: true, get: function () { return user_1.UserRole; } });
|
|
50
|
-
const report_1 =
|
|
50
|
+
const report_1 = __importDefault(require("./report"));
|
|
51
51
|
exports.ReportSDK = report_1.default;
|
|
52
|
-
Object.defineProperty(exports, "ChatReportFileFormat", { enumerable: true, get: function () { return report_1.ChatsReportFileFormat; } });
|
|
53
52
|
const socket_client_1 = __importDefault(require("./socket-client"));
|
|
54
53
|
exports.SocketClientSDK = socket_client_1.default;
|
|
55
|
-
const socket_server_1 =
|
|
54
|
+
const socket_server_1 = __importDefault(require("./socket-server"));
|
|
56
55
|
exports.SocketServerSDK = socket_server_1.default;
|
|
57
|
-
Object.defineProperty(exports, "SocketEventType", { enumerable: true, get: function () { return socket_server_1.SocketEventType; } });
|
package/dist/report.d.ts
CHANGED
|
@@ -1,35 +1,28 @@
|
|
|
1
1
|
import { AxiosInstance } from "axios";
|
|
2
2
|
import { DataResponse, MessageResponse } from "./response";
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
FAILED = "FAILED"
|
|
7
|
-
}
|
|
3
|
+
export type ReportType = "chats";
|
|
4
|
+
export type ChatsReportFormat = "txt" | "csv" | "pdf";
|
|
5
|
+
export type ChatsReportStatus = "pending" | "completed" | "failed";
|
|
8
6
|
export interface ChatsReport {
|
|
9
7
|
id: number;
|
|
10
8
|
userId: string;
|
|
11
9
|
fileId: number;
|
|
12
10
|
instance: string;
|
|
13
|
-
format: string;
|
|
14
11
|
startDate: string;
|
|
15
12
|
endDate: string;
|
|
16
13
|
exportDate: string;
|
|
17
14
|
chats: number;
|
|
18
15
|
messages: number;
|
|
16
|
+
format: ChatsReportFormat;
|
|
19
17
|
status: ChatsReportStatus;
|
|
20
18
|
}
|
|
21
19
|
export interface GenerateChatsReportOptions {
|
|
22
20
|
instance: string;
|
|
23
21
|
userId: string;
|
|
24
|
-
format:
|
|
22
|
+
format: ChatsReportFormat;
|
|
25
23
|
startDate: string;
|
|
26
24
|
endDate: string;
|
|
27
25
|
}
|
|
28
|
-
export declare enum ChatsReportFileFormat {
|
|
29
|
-
TXT = "txt",
|
|
30
|
-
CSV = "csv",
|
|
31
|
-
PDF = "pdf"
|
|
32
|
-
}
|
|
33
26
|
export default class ReportSDK {
|
|
34
27
|
private readonly httpClient;
|
|
35
28
|
constructor(httpClient: AxiosInstance);
|
package/dist/report.js
CHANGED
|
@@ -1,18 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ChatsReportFileFormat = exports.ChatsReportStatus = void 0;
|
|
4
|
-
var ChatsReportStatus;
|
|
5
|
-
(function (ChatsReportStatus) {
|
|
6
|
-
ChatsReportStatus["PENDING"] = "PENDING";
|
|
7
|
-
ChatsReportStatus["COMPLETED"] = "COMPLETED";
|
|
8
|
-
ChatsReportStatus["FAILED"] = "FAILED";
|
|
9
|
-
})(ChatsReportStatus || (exports.ChatsReportStatus = ChatsReportStatus = {}));
|
|
10
|
-
var ChatsReportFileFormat;
|
|
11
|
-
(function (ChatsReportFileFormat) {
|
|
12
|
-
ChatsReportFileFormat["TXT"] = "txt";
|
|
13
|
-
ChatsReportFileFormat["CSV"] = "csv";
|
|
14
|
-
ChatsReportFileFormat["PDF"] = "pdf";
|
|
15
|
-
})(ChatsReportFileFormat || (exports.ChatsReportFileFormat = ChatsReportFileFormat = {}));
|
|
16
3
|
class ReportSDK {
|
|
17
4
|
httpClient;
|
|
18
5
|
constructor(httpClient) {
|
package/dist/socket-client.d.ts
CHANGED
|
@@ -1,68 +1,5 @@
|
|
|
1
1
|
import { Socket } from "socket.io-client";
|
|
2
|
-
import {
|
|
3
|
-
import { ChatId, NotImplemented, QRCode, ChatsReportStatusData, SocketEventType, SocketRoomType } from "./socket-server";
|
|
4
|
-
/**
|
|
5
|
-
* Função para entrar em uma sala de socket.
|
|
6
|
-
*/
|
|
7
|
-
export type JoinRoomFunction = {
|
|
8
|
-
(room: SocketRoomType): void;
|
|
9
|
-
};
|
|
10
|
-
/**
|
|
11
|
-
* Função para entrar em um chat de socket.
|
|
12
|
-
*/
|
|
13
|
-
export type JoinChatFunction = {
|
|
14
|
-
(phone: PhoneNumber): void;
|
|
15
|
-
};
|
|
16
|
-
/**
|
|
17
|
-
* Função para escutar eventos de socket.
|
|
18
|
-
*/
|
|
19
|
-
export type ListenEventFunction = {
|
|
20
|
-
/**
|
|
21
|
-
* Escuta evento de mensagem
|
|
22
|
-
* Ainda não implementado.
|
|
23
|
-
*/
|
|
24
|
-
(event: SocketEventType.MESSAGE, listener: (data: NotImplemented) => void): void;
|
|
25
|
-
/**
|
|
26
|
-
* Escuta evento de edição de mensagem
|
|
27
|
-
* Ainda não implementado.
|
|
28
|
-
*/
|
|
29
|
-
(event: SocketEventType.MESSAGE_EDIT, listener: (data: NotImplemented) => void): void;
|
|
30
|
-
/**
|
|
31
|
-
* Escuta evento de status de mensagem
|
|
32
|
-
* Ainda não implementado.
|
|
33
|
-
*/
|
|
34
|
-
(event: SocketEventType.MESSAGE_STATUS, listener: (data: NotImplemented) => void): void;
|
|
35
|
-
/**
|
|
36
|
-
* Escuta evento de novo chat
|
|
37
|
-
* Ainda não implementado.
|
|
38
|
-
*/
|
|
39
|
-
(event: SocketEventType.NEW_CHAT, listener: (data: NotImplemented) => void): void;
|
|
40
|
-
/**
|
|
41
|
-
* Escuta evento de chat finalizado
|
|
42
|
-
* @trigger Quando um chat é finalizado
|
|
43
|
-
* @target Sala de monitoria e ao atendente do chat
|
|
44
|
-
* @data Um número contendo o ID do chat finalizado
|
|
45
|
-
*/
|
|
46
|
-
(event: SocketEventType.CHAT_FINISHED, listener: (chatId: ChatId) => void): void;
|
|
47
|
-
/**
|
|
48
|
-
* Escuta evento de notificação
|
|
49
|
-
* @trigger Quando uma notificação é enviada
|
|
50
|
-
* @target Sala de administração do setor
|
|
51
|
-
*/
|
|
52
|
-
(event: SocketEventType.NOTIFICATION, listener: (notification: NotImplemented) => void): void;
|
|
53
|
-
/**
|
|
54
|
-
* Escuta evento de QR Code
|
|
55
|
-
* @trigger Quando um QR Code é gerado
|
|
56
|
-
* @target Sala de administração do setor
|
|
57
|
-
*/
|
|
58
|
-
(event: SocketEventType.QR_CODE, listener: (qr: QRCode) => void): void;
|
|
59
|
-
/**
|
|
60
|
-
* Escuta evento de status de relatório
|
|
61
|
-
* @trigger Quando o status de um relatório é atualizado
|
|
62
|
-
* @target Sala de relatórios
|
|
63
|
-
*/
|
|
64
|
-
(event: SocketEventType.REPORT_STATUS, listener: (data: ChatsReportStatusData) => void): void;
|
|
65
|
-
};
|
|
2
|
+
import { JoinChatFunction, JoinRoomFunction, LeaveChatFunction, LeaveRoomFunction, ListenEventFunction } from "./types/socket-client.types";
|
|
66
3
|
/**
|
|
67
4
|
* Classe para consumo dos eventos de socket.
|
|
68
5
|
*/
|
|
@@ -76,6 +13,13 @@ export default class SocketClientSDK {
|
|
|
76
13
|
* @param listener - A função a ser chamada quando o evento ocorrer.
|
|
77
14
|
*/
|
|
78
15
|
on: ListenEventFunction;
|
|
16
|
+
/**
|
|
17
|
+
* Escuta eventos de socket.
|
|
18
|
+
*
|
|
19
|
+
* @param event - O tipo de evento a ser escutado.
|
|
20
|
+
* @param listener - A função a ser chamada quando o evento ocorrer.
|
|
21
|
+
*/
|
|
22
|
+
off: ListenEventFunction;
|
|
79
23
|
/**
|
|
80
24
|
* Entra em uma sala de socket.
|
|
81
25
|
*
|
|
@@ -83,15 +27,31 @@ export default class SocketClientSDK {
|
|
|
83
27
|
*/
|
|
84
28
|
joinRoom: JoinRoomFunction;
|
|
85
29
|
/**
|
|
86
|
-
* Entra em um chat
|
|
30
|
+
* Entra em um chat.
|
|
87
31
|
*
|
|
88
32
|
* @param phone - O número de telefone do chat a ser ingressado.
|
|
89
33
|
*/
|
|
90
34
|
joinChat: JoinChatFunction;
|
|
35
|
+
/**
|
|
36
|
+
* Sai de uma sala de socket.
|
|
37
|
+
*
|
|
38
|
+
* @param room - O tipo de sala a ser deixada.
|
|
39
|
+
* @description Remove o cliente da sala especificada no servidor de socket.
|
|
40
|
+
*/
|
|
41
|
+
leaveRoom: LeaveRoomFunction;
|
|
42
|
+
/**
|
|
43
|
+
* Sai de um chat.
|
|
44
|
+
*
|
|
45
|
+
* @param phone - O número de telefone do chat a ser deixado.
|
|
46
|
+
* @description Remove o cliente do chat especificado, utilizando o número de telefone.
|
|
47
|
+
*/
|
|
48
|
+
leaveChat: LeaveChatFunction;
|
|
91
49
|
/**
|
|
92
50
|
* Define o token de autenticação para o socket.
|
|
93
51
|
*
|
|
94
52
|
* @param token - O token de autenticação.
|
|
53
|
+
* @description Configura o token de autenticação para ser enviado em todas as conexões de socket subsequentes.
|
|
54
|
+
* Se o token for nulo ou vazio, a autenticação será removida.
|
|
95
55
|
*/
|
|
96
56
|
setAuth(token: string): void;
|
|
97
57
|
}
|
package/dist/socket-client.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const socket_server_1 = require("./socket-server");
|
|
4
3
|
/**
|
|
5
4
|
* Classe para consumo dos eventos de socket.
|
|
6
5
|
*/
|
|
@@ -8,9 +7,6 @@ class SocketClientSDK {
|
|
|
8
7
|
io;
|
|
9
8
|
constructor(io) {
|
|
10
9
|
this.io = io;
|
|
11
|
-
this.on(socket_server_1.SocketEventType.CHAT_FINISHED, (chatId) => {
|
|
12
|
-
console.log(`Chat ${chatId} finalizado.`);
|
|
13
|
-
});
|
|
14
10
|
}
|
|
15
11
|
/**
|
|
16
12
|
* Escuta eventos de socket.
|
|
@@ -21,26 +17,55 @@ class SocketClientSDK {
|
|
|
21
17
|
on = (event, listener) => {
|
|
22
18
|
this.io.on(event, listener);
|
|
23
19
|
};
|
|
20
|
+
/**
|
|
21
|
+
* Escuta eventos de socket.
|
|
22
|
+
*
|
|
23
|
+
* @param event - O tipo de evento a ser escutado.
|
|
24
|
+
* @param listener - A função a ser chamada quando o evento ocorrer.
|
|
25
|
+
*/
|
|
26
|
+
off = (event, listener) => {
|
|
27
|
+
this.io.off(event, listener);
|
|
28
|
+
};
|
|
24
29
|
/**
|
|
25
30
|
* Entra em uma sala de socket.
|
|
26
31
|
*
|
|
27
32
|
* @param room - O tipo de sala a ser ingressada.
|
|
28
33
|
*/
|
|
29
34
|
joinRoom = (room) => {
|
|
30
|
-
this.io.emit("join", `${room}`);
|
|
35
|
+
this.io.emit("join-room", `${room}`);
|
|
31
36
|
};
|
|
32
37
|
/**
|
|
33
|
-
* Entra em um chat
|
|
38
|
+
* Entra em um chat.
|
|
34
39
|
*
|
|
35
40
|
* @param phone - O número de telefone do chat a ser ingressado.
|
|
36
41
|
*/
|
|
37
42
|
joinChat = (phone) => {
|
|
38
|
-
this.
|
|
43
|
+
this.joinRoom(`chat:${phone}`);
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Sai de uma sala de socket.
|
|
47
|
+
*
|
|
48
|
+
* @param room - O tipo de sala a ser deixada.
|
|
49
|
+
* @description Remove o cliente da sala especificada no servidor de socket.
|
|
50
|
+
*/
|
|
51
|
+
leaveRoom = (room) => {
|
|
52
|
+
this.io.emit("leave-room", `${room}`);
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Sai de um chat.
|
|
56
|
+
*
|
|
57
|
+
* @param phone - O número de telefone do chat a ser deixado.
|
|
58
|
+
* @description Remove o cliente do chat especificado, utilizando o número de telefone.
|
|
59
|
+
*/
|
|
60
|
+
leaveChat = (phone) => {
|
|
61
|
+
this.leaveRoom(`chat:${phone}`);
|
|
39
62
|
};
|
|
40
63
|
/**
|
|
41
64
|
* Define o token de autenticação para o socket.
|
|
42
65
|
*
|
|
43
66
|
* @param token - O token de autenticação.
|
|
67
|
+
* @description Configura o token de autenticação para ser enviado em todas as conexões de socket subsequentes.
|
|
68
|
+
* Se o token for nulo ou vazio, a autenticação será removida.
|
|
44
69
|
*/
|
|
45
70
|
setAuth(token) {
|
|
46
71
|
this.io.auth = { token: token ? `Bearer ${token}` : null };
|
package/dist/socket-server.d.ts
CHANGED
|
@@ -1,155 +1,5 @@
|
|
|
1
|
-
import { PhoneNumber } from "@in.pulse-crm/utils";
|
|
2
1
|
import { AxiosInstance } from "axios";
|
|
3
|
-
|
|
4
|
-
* Tipos de eventos de socket.
|
|
5
|
-
*/
|
|
6
|
-
export declare enum SocketEventType {
|
|
7
|
-
MESSAGE = "message",
|
|
8
|
-
MESSAGE_EDIT = "message_edit",
|
|
9
|
-
MESSAGE_STATUS = "message_status",
|
|
10
|
-
NEW_CHAT = "new_chat",
|
|
11
|
-
CHAT_FINISHED = "chat_finished",
|
|
12
|
-
NOTIFICATION = "notification",
|
|
13
|
-
QR_CODE = "qr_code",
|
|
14
|
-
REPORT_STATUS = "report_status"
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Sala de chat, recebe todos eventos de um chat específico.
|
|
18
|
-
*/
|
|
19
|
-
export type SocketChatRoom = `chat:${PhoneNumber}`;
|
|
20
|
-
/**
|
|
21
|
-
* Sala de administrador, recebe eventos de adminstrador de um setor específico.
|
|
22
|
-
*/
|
|
23
|
-
export type SocketAdminRoom = `sector:${SectorId}:admin`;
|
|
24
|
-
/**
|
|
25
|
-
* Sala de monitoria, recebe eventos de monitoria de um setor específico.
|
|
26
|
-
*/
|
|
27
|
-
export type SocketMonitorRoom = `sector:${SectorId}:monitor`;
|
|
28
|
-
/**
|
|
29
|
-
* Sala de relatórios, recebe eventos de um tipo relatório específico de um setor específico.
|
|
30
|
-
*/
|
|
31
|
-
export type SocketReportsRoom = `sector:${number}:reports:${string}`;
|
|
32
|
-
/**
|
|
33
|
-
* Tipo de sala de socket.
|
|
34
|
-
*/
|
|
35
|
-
export type SocketRoomType = SocketChatRoom | SocketAdminRoom | SocketReportsRoom | SocketMonitorRoom;
|
|
36
|
-
/**
|
|
37
|
-
* Ainda não implementado.
|
|
38
|
-
*/
|
|
39
|
-
export type NotImplemented = unknown;
|
|
40
|
-
/**
|
|
41
|
-
* Dados de status de um relatório de conversas.
|
|
42
|
-
*/
|
|
43
|
-
export type ChatsReportStatusData = {
|
|
44
|
-
id: number;
|
|
45
|
-
type: "chats-report";
|
|
46
|
-
isCompleted: false;
|
|
47
|
-
isFailed: false;
|
|
48
|
-
progress: number;
|
|
49
|
-
} | {
|
|
50
|
-
id: number;
|
|
51
|
-
type: "chats-report";
|
|
52
|
-
isCompleted: true;
|
|
53
|
-
isFailed: false;
|
|
54
|
-
fileId: number;
|
|
55
|
-
chats: number;
|
|
56
|
-
messages: number;
|
|
57
|
-
} | {
|
|
58
|
-
id: number;
|
|
59
|
-
type: "chats-report";
|
|
60
|
-
isCompleted: false;
|
|
61
|
-
isFailed: true;
|
|
62
|
-
error: string;
|
|
63
|
-
};
|
|
64
|
-
/**
|
|
65
|
-
* String representando um QR Code.
|
|
66
|
-
*/
|
|
67
|
-
export type QRCode = string;
|
|
68
|
-
/**
|
|
69
|
-
* Id de um chat.
|
|
70
|
-
*/
|
|
71
|
-
export type ChatId = number;
|
|
72
|
-
/**
|
|
73
|
-
* Id de um setor.
|
|
74
|
-
*/
|
|
75
|
-
export type SectorId = number;
|
|
76
|
-
/**
|
|
77
|
-
* Nome de uma instância.
|
|
78
|
-
*/
|
|
79
|
-
export type InstanceName = string;
|
|
80
|
-
/**
|
|
81
|
-
* Represents a function type for emitting events to specific rooms in a socket server.
|
|
82
|
-
* This function type supports multiple overloads, each corresponding to a specific
|
|
83
|
-
* combination of room type, event type, and value type.
|
|
84
|
-
*
|
|
85
|
-
* @typedef EmitFunction
|
|
86
|
-
*
|
|
87
|
-
* @overload
|
|
88
|
-
* Emits a `NEW_CHAT` event to a chat or monitor room.
|
|
89
|
-
* @param instanceName - The name of the instance emitting the event.
|
|
90
|
-
* @param room - The target room, either a `SocketChatRoom` or `SocketMonitorRoom`.
|
|
91
|
-
* @param event - The event type, `SocketEventType.NEW_CHAT`.
|
|
92
|
-
* @param value - The value associated with the event (type not yet implemented).
|
|
93
|
-
*
|
|
94
|
-
* @overload
|
|
95
|
-
* Emits a `CHAT_FINISHED` event to a chat or monitor room.
|
|
96
|
-
* @param instanceName - The name of the instance emitting the event.
|
|
97
|
-
* @param room - The target room, either a `SocketChatRoom` or `SocketMonitorRoom`.
|
|
98
|
-
* @param event - The event type, `SocketEventType.CHAT_FINISHED`.
|
|
99
|
-
* @param value - The ID of the finished chat.
|
|
100
|
-
*
|
|
101
|
-
* @overload
|
|
102
|
-
* Emits a `QR_CODE` event to an admin room.
|
|
103
|
-
* @param instanceName - The name of the instance emitting the event.
|
|
104
|
-
* @param room - The target room, a `SocketAdminRoom`.
|
|
105
|
-
* @param event - The event type, `SocketEventType.QR_CODE`.
|
|
106
|
-
* @param value - The QR code data.
|
|
107
|
-
*
|
|
108
|
-
* @overload
|
|
109
|
-
* Emits a `MESSAGE` event to a chat room.
|
|
110
|
-
* @param instanceName - The name of the instance emitting the event.
|
|
111
|
-
* @param room - The target room, a `SocketChatRoom`.
|
|
112
|
-
* @param event - The event type, `SocketEventType.MESSAGE`.
|
|
113
|
-
* @param value - The value associated with the event (type not yet implemented).
|
|
114
|
-
*
|
|
115
|
-
* @overload
|
|
116
|
-
* Emits a `NOTIFICATION` event to an admin room.
|
|
117
|
-
* @param instanceName - The name of the instance emitting the event.
|
|
118
|
-
* @param room - The target room, a `SocketAdminRoom`.
|
|
119
|
-
* @param event - The event type, `SocketEventType.NOTIFICATION`.
|
|
120
|
-
* @param value - The value associated with the event (type not yet implemented).
|
|
121
|
-
*
|
|
122
|
-
* @overload
|
|
123
|
-
* Emits a `MESSAGE_EDIT` event to a chat room.
|
|
124
|
-
* @param instanceName - The name of the instance emitting the event.
|
|
125
|
-
* @param room - The target room, a `SocketChatRoom`.
|
|
126
|
-
* @param event - The event type, `SocketEventType.MESSAGE_EDIT`.
|
|
127
|
-
* @param value - The value associated with the event (type not yet implemented).
|
|
128
|
-
*
|
|
129
|
-
* @overload
|
|
130
|
-
* Emits a `MESSAGE_STATUS` event to a chat room.
|
|
131
|
-
* @param instanceName - The name of the instance emitting the event.
|
|
132
|
-
* @param room - The target room, a `SocketChatRoom`.
|
|
133
|
-
* @param event - The event type, `SocketEventType.MESSAGE_STATUS`.
|
|
134
|
-
* @param value - The value associated with the event (type not yet implemented).
|
|
135
|
-
*
|
|
136
|
-
* @overload
|
|
137
|
-
* Emits a `REPORT_STATUS` event to an admin room.
|
|
138
|
-
* @param instanceName - The name of the instance emitting the event.
|
|
139
|
-
* @param room - The target room, a `SocketAdminRoom`.
|
|
140
|
-
* @param event - The event type, `SocketEventType.REPORT_STATUS`.
|
|
141
|
-
* @param value - The report status data.
|
|
142
|
-
*/
|
|
143
|
-
export type EmitFunction = {
|
|
144
|
-
(instanceName: string, room: SocketChatRoom | SocketMonitorRoom, event: SocketEventType.NEW_CHAT, value: NotImplemented): void;
|
|
145
|
-
(instanceName: string, room: SocketChatRoom | SocketMonitorRoom, event: SocketEventType.CHAT_FINISHED, value: ChatId): void;
|
|
146
|
-
(instanceName: string, room: SocketAdminRoom, event: SocketEventType.QR_CODE, value: QRCode): void;
|
|
147
|
-
(instanceName: string, room: SocketChatRoom, event: SocketEventType.MESSAGE, value: NotImplemented): void;
|
|
148
|
-
(instanceName: string, room: SocketAdminRoom, event: SocketEventType.NOTIFICATION, value: NotImplemented): void;
|
|
149
|
-
(instanceName: string, room: SocketChatRoom, event: SocketEventType.MESSAGE_EDIT, value: NotImplemented): void;
|
|
150
|
-
(instanceName: string, room: SocketChatRoom, event: SocketEventType.MESSAGE_STATUS, value: NotImplemented): void;
|
|
151
|
-
(instanceName: string, room: SocketReportsRoom, event: SocketEventType.REPORT_STATUS, value: ChatsReportStatusData): void;
|
|
152
|
-
};
|
|
2
|
+
import { EmitFunction } from "./types/socket-server.types";
|
|
153
3
|
/**
|
|
154
4
|
* Classe para manipulação de eventos de socket.
|
|
155
5
|
*/
|
package/dist/socket-server.js
CHANGED
|
@@ -1,20 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SocketEventType = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Tipos de eventos de socket.
|
|
6
|
-
*/
|
|
7
|
-
var SocketEventType;
|
|
8
|
-
(function (SocketEventType) {
|
|
9
|
-
SocketEventType["MESSAGE"] = "message";
|
|
10
|
-
SocketEventType["MESSAGE_EDIT"] = "message_edit";
|
|
11
|
-
SocketEventType["MESSAGE_STATUS"] = "message_status";
|
|
12
|
-
SocketEventType["NEW_CHAT"] = "new_chat";
|
|
13
|
-
SocketEventType["CHAT_FINISHED"] = "chat_finished";
|
|
14
|
-
SocketEventType["NOTIFICATION"] = "notification";
|
|
15
|
-
SocketEventType["QR_CODE"] = "qr_code";
|
|
16
|
-
SocketEventType["REPORT_STATUS"] = "report_status";
|
|
17
|
-
})(SocketEventType || (exports.SocketEventType = SocketEventType = {}));
|
|
18
3
|
/**
|
|
19
4
|
* Classe para manipulação de eventos de socket.
|
|
20
5
|
*/
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { PhoneNumber } from "@in.pulse-crm/utils";
|
|
2
|
+
import { ReportType } from "../report";
|
|
3
|
+
import type { ChatsReportStatusData, QRCode } from "./socket-server.types";
|
|
4
|
+
/**
|
|
5
|
+
* Representa uma sala de chat identificada por um número de telefone.
|
|
6
|
+
*/
|
|
7
|
+
export type SocketChatRoom = `chat:${PhoneNumber}`;
|
|
8
|
+
/**
|
|
9
|
+
* Representa a sala de administração.
|
|
10
|
+
*/
|
|
11
|
+
export type SocketClientAdminRoom = "admin";
|
|
12
|
+
/**
|
|
13
|
+
* Representa a sala de monitoramento.
|
|
14
|
+
*/
|
|
15
|
+
export type SocketClientMonitorRoom = `monitor`;
|
|
16
|
+
/**
|
|
17
|
+
* Representa uma sala de relatórios identificada por um tipo de relatório.
|
|
18
|
+
*/
|
|
19
|
+
export type SocketClientReportsRoom = `reports:${ReportType}`;
|
|
20
|
+
/**
|
|
21
|
+
* Representa as salas disponíveis para clientes, incluindo chat, administração, relatórios e monitoramento.
|
|
22
|
+
*/
|
|
23
|
+
export type SocketClientRoom = SocketChatRoom | SocketClientAdminRoom | SocketClientReportsRoom | SocketClientMonitorRoom;
|
|
24
|
+
/**
|
|
25
|
+
* Função para entrar em uma sala de socket.
|
|
26
|
+
*/
|
|
27
|
+
export type JoinRoomFunction = {
|
|
28
|
+
(room: SocketClientRoom): void;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Função para entrar em um chat de socket.
|
|
32
|
+
*/
|
|
33
|
+
export type JoinChatFunction = {
|
|
34
|
+
(phone: PhoneNumber): void;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Função para sair de uma sala de socket.
|
|
38
|
+
*/
|
|
39
|
+
export type LeaveRoomFunction = {
|
|
40
|
+
(room: SocketClientRoom): void;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Função para sair de um chat de socket.
|
|
44
|
+
*/
|
|
45
|
+
export type LeaveChatFunction = {
|
|
46
|
+
(phone: PhoneNumber): void;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Função para escutar eventos de socket.
|
|
50
|
+
*/
|
|
51
|
+
export type ListenEventFunction = {
|
|
52
|
+
/**
|
|
53
|
+
* Escuta evento de mensagem
|
|
54
|
+
* Ainda não implementado.
|
|
55
|
+
*/
|
|
56
|
+
(event: "message", listener: (data: unknown) => void): void;
|
|
57
|
+
/**
|
|
58
|
+
* Escuta evento de edição de mensagem
|
|
59
|
+
* Ainda não implementado.
|
|
60
|
+
*/
|
|
61
|
+
(event: "message_edit", listener: (data: unknown) => void): void;
|
|
62
|
+
/**
|
|
63
|
+
* Escuta evento de status de mensagem
|
|
64
|
+
* Ainda não implementado.
|
|
65
|
+
*/
|
|
66
|
+
(event: "message_status", listener: (data: unknown) => void): void;
|
|
67
|
+
/**
|
|
68
|
+
* Escuta evento de novo chat
|
|
69
|
+
* Ainda não implementado.
|
|
70
|
+
*/
|
|
71
|
+
(event: "new_chat", listener: (data: unknown) => void): void;
|
|
72
|
+
/**
|
|
73
|
+
* Escuta evento de chat finalizado
|
|
74
|
+
* @trigger Quando um chat é finalizado
|
|
75
|
+
* @target Sala de monitoria e ao atendente do chat
|
|
76
|
+
* @data Um número contendo o ID do chat finalizado
|
|
77
|
+
*/
|
|
78
|
+
(event: "chat_finished", listener: (chatId: number) => void): void;
|
|
79
|
+
/**
|
|
80
|
+
* Escuta evento de notificação
|
|
81
|
+
* @trigger Quando uma notificação é enviada
|
|
82
|
+
* @target Sala de administração do setor
|
|
83
|
+
*/
|
|
84
|
+
(event: "notification", listener: (notification: unknown) => void): void;
|
|
85
|
+
/**
|
|
86
|
+
* Escuta evento de QR Code
|
|
87
|
+
* @trigger Quando um QR Code é gerado
|
|
88
|
+
* @target Sala de administração do setor
|
|
89
|
+
*/
|
|
90
|
+
(event: "qr_code", listener: (qr: QRCode) => void): void;
|
|
91
|
+
/**
|
|
92
|
+
* Escuta evento de status de relatório
|
|
93
|
+
* @trigger Quando o status de um relatório é atualizado
|
|
94
|
+
* @target Sala de relatórios
|
|
95
|
+
*/
|
|
96
|
+
(event: "report_status", listener: (data: ChatsReportStatusData) => void): void;
|
|
97
|
+
};
|