@in.pulse-crm/sdk 1.3.0 → 1.3.2
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/file.d.ts +2 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +13 -18
- package/dist/socket-client.d.ts +97 -0
- package/dist/socket-client.js +49 -0
- package/dist/socket-server.d.ts +91 -0
- package/dist/socket-server.js +37 -0
- package/package.json +35 -35
- package/src/index.ts +55 -29
- package/src/{socket.ts → socket-client.ts} +10 -60
- package/src/socket-server.ts +148 -0
package/dist/file.d.ts
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -4,4 +4,6 @@ import InstanceSDK from "./instance";
|
|
|
4
4
|
import UserSDK, { CreateUserDTO, UpdateUserDTO, User, UserRole } from "./user";
|
|
5
5
|
import { DataResponse, ErrorResponse, PaginatedResponse, QueryResponse } from "./response";
|
|
6
6
|
import ReportSDK, { ChatReport, ChatReportFileFormat, GenerateChatReportOptions } from "./report";
|
|
7
|
-
|
|
7
|
+
import SocketClientSDK, { JoinChatFunction, JoinRoomFunction, ListenEventFunction } from "./socket-client";
|
|
8
|
+
import SocketServerSDK, { EmitFunction, InstanceName, SocketAdminRoom, SocketChatRoom, SocketMonitorRoom, SocketReportsRoom, SocketRoomType, SocketEventType } from "./socket-server";
|
|
9
|
+
export { AuthSDK, LoginData, SessionData, FileSDK, File, FileDirType, InstanceSDK, UserSDK, CreateUserDTO, UpdateUserDTO, User, UserRole, DataResponse, ErrorResponse, PaginatedResponse, QueryResponse, ReportSDK, ChatReport, ChatReportFileFormat, GenerateChatReportOptions, SocketClientSDK, JoinChatFunction, JoinRoomFunction, ListenEventFunction, SocketServerSDK, EmitFunction, InstanceName, SocketAdminRoom, SocketReportsRoom, SocketChatRoom, SocketEventType, SocketMonitorRoom, SocketRoomType };
|
package/dist/index.js
CHANGED
|
@@ -15,28 +15,18 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) ||
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
35
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
27
|
};
|
|
38
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.ChatReportFileFormat = exports.ReportSDK = exports.UserRole = exports.UserSDK = exports.InstanceSDK = exports.FileDirType = exports.FileSDK = exports.AuthSDK = void 0;
|
|
29
|
+
exports.SocketEventType = exports.SocketServerSDK = exports.SocketClientSDK = exports.ChatReportFileFormat = exports.ReportSDK = exports.UserRole = exports.UserSDK = exports.InstanceSDK = exports.FileDirType = exports.FileSDK = exports.AuthSDK = void 0;
|
|
40
30
|
const auth_1 = __importDefault(require("./auth"));
|
|
41
31
|
exports.AuthSDK = auth_1.default;
|
|
42
32
|
const file_1 = __importStar(require("./file"));
|
|
@@ -50,3 +40,8 @@ Object.defineProperty(exports, "UserRole", { enumerable: true, get: function ()
|
|
|
50
40
|
const report_1 = __importStar(require("./report"));
|
|
51
41
|
exports.ReportSDK = report_1.default;
|
|
52
42
|
Object.defineProperty(exports, "ChatReportFileFormat", { enumerable: true, get: function () { return report_1.ChatReportFileFormat; } });
|
|
43
|
+
const socket_client_1 = __importDefault(require("./socket-client"));
|
|
44
|
+
exports.SocketClientSDK = socket_client_1.default;
|
|
45
|
+
const socket_server_1 = __importStar(require("./socket-server"));
|
|
46
|
+
exports.SocketServerSDK = socket_server_1.default;
|
|
47
|
+
Object.defineProperty(exports, "SocketEventType", { enumerable: true, get: function () { return socket_server_1.SocketEventType; } });
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { Socket } from "socket.io-client";
|
|
2
|
+
import { PhoneNumber } from "@in.pulse-crm/utils";
|
|
3
|
+
import { ChatId, NotImplemented, QRCode, ReportStatusData, 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: ReportStatusData) => void): void;
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Classe para consumo dos eventos de socket.
|
|
68
|
+
*/
|
|
69
|
+
export default class SocketClientSDK {
|
|
70
|
+
private readonly io;
|
|
71
|
+
constructor(io: Socket);
|
|
72
|
+
/**
|
|
73
|
+
* Escuta eventos de socket.
|
|
74
|
+
*
|
|
75
|
+
* @param event - O tipo de evento a ser escutado.
|
|
76
|
+
* @param listener - A função a ser chamada quando o evento ocorrer.
|
|
77
|
+
*/
|
|
78
|
+
on: ListenEventFunction;
|
|
79
|
+
/**
|
|
80
|
+
* Entra em uma sala de socket.
|
|
81
|
+
*
|
|
82
|
+
* @param room - O tipo de sala a ser ingressada.
|
|
83
|
+
*/
|
|
84
|
+
joinRoom: JoinRoomFunction;
|
|
85
|
+
/**
|
|
86
|
+
* Entra em um chat de socket.
|
|
87
|
+
*
|
|
88
|
+
* @param phone - O número de telefone do chat a ser ingressado.
|
|
89
|
+
*/
|
|
90
|
+
joinChat: JoinChatFunction;
|
|
91
|
+
/**
|
|
92
|
+
* Define o token de autenticação para o socket.
|
|
93
|
+
*
|
|
94
|
+
* @param token - O token de autenticação.
|
|
95
|
+
*/
|
|
96
|
+
setAuth(token: string): void;
|
|
97
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const socket_server_1 = require("./socket-server");
|
|
4
|
+
/**
|
|
5
|
+
* Classe para consumo dos eventos de socket.
|
|
6
|
+
*/
|
|
7
|
+
class SocketClientSDK {
|
|
8
|
+
io;
|
|
9
|
+
constructor(io) {
|
|
10
|
+
this.io = io;
|
|
11
|
+
this.on(socket_server_1.SocketEventType.CHAT_FINISHED, (chatId) => {
|
|
12
|
+
console.log(`Chat ${chatId} finalizado.`);
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Escuta eventos de socket.
|
|
17
|
+
*
|
|
18
|
+
* @param event - O tipo de evento a ser escutado.
|
|
19
|
+
* @param listener - A função a ser chamada quando o evento ocorrer.
|
|
20
|
+
*/
|
|
21
|
+
on = (event, listener) => {
|
|
22
|
+
this.io.on(event, listener);
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Entra em uma sala de socket.
|
|
26
|
+
*
|
|
27
|
+
* @param room - O tipo de sala a ser ingressada.
|
|
28
|
+
*/
|
|
29
|
+
joinRoom = (room) => {
|
|
30
|
+
this.io.emit("join", `${room}`);
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Entra em um chat de socket.
|
|
34
|
+
*
|
|
35
|
+
* @param phone - O número de telefone do chat a ser ingressado.
|
|
36
|
+
*/
|
|
37
|
+
joinChat = (phone) => {
|
|
38
|
+
this.io.emit("join", `chat:${phone}`);
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Define o token de autenticação para o socket.
|
|
42
|
+
*
|
|
43
|
+
* @param token - O token de autenticação.
|
|
44
|
+
*/
|
|
45
|
+
setAuth(token) {
|
|
46
|
+
this.io.auth = { token: token ? `Bearer ${token}` : null };
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.default = SocketClientSDK;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { PhoneNumber } from "@in.pulse-crm/utils";
|
|
2
|
+
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.
|
|
42
|
+
*/
|
|
43
|
+
export type ReportStatusData = {
|
|
44
|
+
id: number;
|
|
45
|
+
type: string;
|
|
46
|
+
progress: number;
|
|
47
|
+
isCompleted: boolean;
|
|
48
|
+
isFailed: boolean;
|
|
49
|
+
error?: string;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* String representando um QR Code.
|
|
53
|
+
*/
|
|
54
|
+
export type QRCode = string;
|
|
55
|
+
/**
|
|
56
|
+
* Id de um chat.
|
|
57
|
+
*/
|
|
58
|
+
export type ChatId = number;
|
|
59
|
+
/**
|
|
60
|
+
* Id de um setor.
|
|
61
|
+
*/
|
|
62
|
+
export type SectorId = number;
|
|
63
|
+
/**
|
|
64
|
+
* Nome de uma instância.
|
|
65
|
+
*/
|
|
66
|
+
export type InstanceName = string;
|
|
67
|
+
export type EmitFunction = {
|
|
68
|
+
(instanceName: string, room: SocketChatRoom | SocketMonitorRoom, event: SocketEventType.NEW_CHAT, value: NotImplemented): void;
|
|
69
|
+
(instanceName: string, room: SocketChatRoom | SocketMonitorRoom, event: SocketEventType.CHAT_FINISHED, value: ChatId): void;
|
|
70
|
+
(instanceName: string, room: SocketAdminRoom, event: SocketEventType.QR_CODE, value: QRCode): void;
|
|
71
|
+
(instanceName: string, room: SocketChatRoom, event: SocketEventType.MESSAGE, value: NotImplemented): void;
|
|
72
|
+
(instanceName: string, room: SocketAdminRoom, event: SocketEventType.NOTIFICATION, value: NotImplemented): void;
|
|
73
|
+
(instanceName: string, room: SocketChatRoom, event: SocketEventType.MESSAGE_EDIT, value: NotImplemented): void;
|
|
74
|
+
(instanceName: string, room: SocketChatRoom, event: SocketEventType.MESSAGE_STATUS, value: NotImplemented): void;
|
|
75
|
+
(instanceName: string, room: SocketAdminRoom, event: SocketEventType.REPORT_STATUS, value: ReportStatusData): void;
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* Classe para manipulação de eventos de socket.
|
|
79
|
+
*/
|
|
80
|
+
export default class SocketServerSDK {
|
|
81
|
+
private readonly httpClient;
|
|
82
|
+
constructor(httpClient: AxiosInstance);
|
|
83
|
+
/**
|
|
84
|
+
* Emite um evento de socket.
|
|
85
|
+
* @param instanceName - O nome da instância.
|
|
86
|
+
* @param room - A sala de destino.
|
|
87
|
+
* @param event - O tipo do evento.
|
|
88
|
+
* @param value - O valor do evento.
|
|
89
|
+
*/
|
|
90
|
+
emit: EmitFunction;
|
|
91
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
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
|
+
/**
|
|
19
|
+
* Classe para manipulação de eventos de socket.
|
|
20
|
+
*/
|
|
21
|
+
class SocketServerSDK {
|
|
22
|
+
httpClient;
|
|
23
|
+
constructor(httpClient) {
|
|
24
|
+
this.httpClient = httpClient;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Emite um evento de socket.
|
|
28
|
+
* @param instanceName - O nome da instância.
|
|
29
|
+
* @param room - A sala de destino.
|
|
30
|
+
* @param event - O tipo do evento.
|
|
31
|
+
* @param value - O valor do evento.
|
|
32
|
+
*/
|
|
33
|
+
emit = async (instanceName, room, event, value) => {
|
|
34
|
+
await this.httpClient.post(`/emit/${instanceName}/${room}/${event}`, value);
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
exports.default = SocketServerSDK;
|
package/package.json
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@in.pulse-crm/sdk",
|
|
3
|
-
"version": "1.3.
|
|
4
|
-
"description": "SDKs for abstraction of api consumption of in.pulse-crm application",
|
|
5
|
-
"main": "./dist/index.js",
|
|
6
|
-
"types": "./dist/index.d.ts",
|
|
7
|
-
"module": "./dist/index.js",
|
|
8
|
-
"exports": {
|
|
9
|
-
".": {
|
|
10
|
-
"import": "./dist/index.js",
|
|
11
|
-
"require": "./dist/index.js"
|
|
12
|
-
}
|
|
13
|
-
},
|
|
14
|
-
"scripts": {
|
|
15
|
-
"build": "tsc",
|
|
16
|
-
"prettier": "prettier --write .",
|
|
17
|
-
"prettier:check": "prettier --check ."
|
|
18
|
-
},
|
|
19
|
-
"repository": {
|
|
20
|
-
"type": "git",
|
|
21
|
-
"url": "in.pulse-crm"
|
|
22
|
-
},
|
|
23
|
-
"author": "Renan G. Dutra <r.granatodutra@gmail.com>",
|
|
24
|
-
"license": "ISC",
|
|
25
|
-
"dependencies": {
|
|
26
|
-
"@in.pulse-crm/utils": "^1.3.0",
|
|
27
|
-
"axios": "^1.8.3",
|
|
28
|
-
"socket.io-client": "^4.8.1"
|
|
29
|
-
},
|
|
30
|
-
"devDependencies": {
|
|
31
|
-
"@types/node": "^22.13.10",
|
|
32
|
-
"prettier": "^3.5.3",
|
|
33
|
-
"typescript": "^5.8.2"
|
|
34
|
-
}
|
|
35
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@in.pulse-crm/sdk",
|
|
3
|
+
"version": "1.3.2",
|
|
4
|
+
"description": "SDKs for abstraction of api consumption of in.pulse-crm application",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"require": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "tsc",
|
|
16
|
+
"prettier": "prettier --write .",
|
|
17
|
+
"prettier:check": "prettier --check ."
|
|
18
|
+
},
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "in.pulse-crm"
|
|
22
|
+
},
|
|
23
|
+
"author": "Renan G. Dutra <r.granatodutra@gmail.com>",
|
|
24
|
+
"license": "ISC",
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@in.pulse-crm/utils": "^1.3.0",
|
|
27
|
+
"axios": "^1.8.3",
|
|
28
|
+
"socket.io-client": "^4.8.1"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@types/node": "^22.13.10",
|
|
32
|
+
"prettier": "^3.5.3",
|
|
33
|
+
"typescript": "^5.8.2"
|
|
34
|
+
}
|
|
35
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,29 +1,55 @@
|
|
|
1
|
-
import AuthSDK, { LoginData, SessionData } from "./auth";
|
|
2
|
-
import FileSDK, { File, FileDirType } from "./file";
|
|
3
|
-
import InstanceSDK from "./instance";
|
|
4
|
-
import UserSDK, { CreateUserDTO, UpdateUserDTO, User, UserRole } from "./user";
|
|
5
|
-
import { DataResponse, ErrorResponse, PaginatedResponse, QueryResponse } from "./response";
|
|
6
|
-
import ReportSDK, { ChatReport, ChatReportFileFormat, GenerateChatReportOptions } from "./report";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
1
|
+
import AuthSDK, { LoginData, SessionData } from "./auth";
|
|
2
|
+
import FileSDK, { File, FileDirType } from "./file";
|
|
3
|
+
import InstanceSDK from "./instance";
|
|
4
|
+
import UserSDK, { CreateUserDTO, UpdateUserDTO, User, UserRole } from "./user";
|
|
5
|
+
import { DataResponse, ErrorResponse, PaginatedResponse, QueryResponse } from "./response";
|
|
6
|
+
import ReportSDK, { ChatReport, ChatReportFileFormat, GenerateChatReportOptions } from "./report";
|
|
7
|
+
import SocketClientSDK, { JoinChatFunction, JoinRoomFunction, ListenEventFunction } from "./socket-client";
|
|
8
|
+
import
|
|
9
|
+
SocketServerSDK,
|
|
10
|
+
{
|
|
11
|
+
EmitFunction,
|
|
12
|
+
InstanceName,
|
|
13
|
+
SocketAdminRoom,
|
|
14
|
+
SocketChatRoom,
|
|
15
|
+
SocketMonitorRoom,
|
|
16
|
+
SocketReportsRoom,
|
|
17
|
+
SocketRoomType,
|
|
18
|
+
SocketEventType,
|
|
19
|
+
} from "./socket-server";
|
|
20
|
+
|
|
21
|
+
export {
|
|
22
|
+
AuthSDK,
|
|
23
|
+
LoginData,
|
|
24
|
+
SessionData,
|
|
25
|
+
FileSDK,
|
|
26
|
+
File,
|
|
27
|
+
FileDirType,
|
|
28
|
+
InstanceSDK,
|
|
29
|
+
UserSDK,
|
|
30
|
+
CreateUserDTO,
|
|
31
|
+
UpdateUserDTO,
|
|
32
|
+
User,
|
|
33
|
+
UserRole,
|
|
34
|
+
DataResponse,
|
|
35
|
+
ErrorResponse,
|
|
36
|
+
PaginatedResponse,
|
|
37
|
+
QueryResponse,
|
|
38
|
+
ReportSDK,
|
|
39
|
+
ChatReport,
|
|
40
|
+
ChatReportFileFormat,
|
|
41
|
+
GenerateChatReportOptions,
|
|
42
|
+
SocketClientSDK,
|
|
43
|
+
JoinChatFunction,
|
|
44
|
+
JoinRoomFunction,
|
|
45
|
+
ListenEventFunction,
|
|
46
|
+
SocketServerSDK,
|
|
47
|
+
EmitFunction,
|
|
48
|
+
InstanceName,
|
|
49
|
+
SocketAdminRoom,
|
|
50
|
+
SocketReportsRoom,
|
|
51
|
+
SocketChatRoom,
|
|
52
|
+
SocketEventType,
|
|
53
|
+
SocketMonitorRoom,
|
|
54
|
+
SocketRoomType
|
|
55
|
+
};
|
|
@@ -1,63 +1,6 @@
|
|
|
1
1
|
import { Socket } from "socket.io-client";
|
|
2
2
|
import { PhoneNumber } from "@in.pulse-crm/utils";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Tipos de eventos de socket.
|
|
6
|
-
*/
|
|
7
|
-
export enum SocketEventType {
|
|
8
|
-
MESSAGE = "message",
|
|
9
|
-
MESSAGE_EDIT = "message_edit",
|
|
10
|
-
MESSAGE_STATUS = "message_status",
|
|
11
|
-
NEW_CHAT = "new_chat",
|
|
12
|
-
CHAT_FINISHED = "chat_finished",
|
|
13
|
-
NOTIFICATION = "notification",
|
|
14
|
-
QR_CODE = "qr_code"
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Sala de chat, recebe todos eventos de um chat específico.
|
|
19
|
-
*/
|
|
20
|
-
export type SocketChatRoom = `chat:${PhoneNumber}`;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Sala de administrador, recebe eventos de adminstrador de um setor específico.
|
|
24
|
-
*/
|
|
25
|
-
export type SocketAdminRoom = `sector:${SectorId}:admin`;
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Sala de relatórios de chat, recebe eventos de relatórios de chat de um setor específico.
|
|
29
|
-
*/
|
|
30
|
-
export type SocketChatReportsRoom = `sector:${SectorId}:chat_reports`;
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Tipo de sala de socket.
|
|
34
|
-
*/
|
|
35
|
-
export type SocketRoomType = SocketChatRoom | SocketAdminRoom | SocketChatReportsRoom;
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Ainda não implementado.
|
|
39
|
-
*/
|
|
40
|
-
export type NotImplemented = never;
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* String representando um QR Code.
|
|
44
|
-
*/
|
|
45
|
-
export type QRCode = string;
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Id de um chat.
|
|
49
|
-
*/
|
|
50
|
-
export type ChatId = number;
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Id de um setor.
|
|
54
|
-
*/
|
|
55
|
-
export type SectorId = number;
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Nome de uma instância.
|
|
59
|
-
*/
|
|
60
|
-
export type InstanceName = string;
|
|
3
|
+
import { ChatId, NotImplemented, QRCode, ReportStatusData, SocketEventType, SocketRoomType } from "./socket-server";
|
|
61
4
|
|
|
62
5
|
/**
|
|
63
6
|
* Função para entrar em uma sala de socket.
|
|
@@ -122,12 +65,19 @@ export type ListenEventFunction = {
|
|
|
122
65
|
* @target Sala de administração do setor
|
|
123
66
|
*/
|
|
124
67
|
(event: SocketEventType.QR_CODE, listener: (qr: QRCode) => void): void;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Escuta evento de status de relatório
|
|
71
|
+
* @trigger Quando o status de um relatório é atualizado
|
|
72
|
+
* @target Sala de relatórios
|
|
73
|
+
*/
|
|
74
|
+
(event: SocketEventType.REPORT_STATUS, listener: (data: ReportStatusData) => void): void;
|
|
125
75
|
}
|
|
126
76
|
|
|
127
77
|
/**
|
|
128
|
-
* Classe para
|
|
78
|
+
* Classe para consumo dos eventos de socket.
|
|
129
79
|
*/
|
|
130
|
-
export default class
|
|
80
|
+
export default class SocketClientSDK {
|
|
131
81
|
constructor(private readonly io: Socket) {
|
|
132
82
|
|
|
133
83
|
this.on(SocketEventType.CHAT_FINISHED, (chatId) => {
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { PhoneNumber } from "@in.pulse-crm/utils";
|
|
2
|
+
import { AxiosInstance } from "axios";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Tipos de eventos de socket.
|
|
6
|
+
*/
|
|
7
|
+
export enum SocketEventType {
|
|
8
|
+
MESSAGE = "message",
|
|
9
|
+
MESSAGE_EDIT = "message_edit",
|
|
10
|
+
MESSAGE_STATUS = "message_status",
|
|
11
|
+
NEW_CHAT = "new_chat",
|
|
12
|
+
CHAT_FINISHED = "chat_finished",
|
|
13
|
+
NOTIFICATION = "notification",
|
|
14
|
+
QR_CODE = "qr_code",
|
|
15
|
+
REPORT_STATUS = "report_status"
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Sala de chat, recebe todos eventos de um chat específico.
|
|
20
|
+
*/
|
|
21
|
+
export type SocketChatRoom = `chat:${PhoneNumber}`;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Sala de administrador, recebe eventos de adminstrador de um setor específico.
|
|
25
|
+
*/
|
|
26
|
+
export type SocketAdminRoom = `sector:${SectorId}:admin`;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Sala de monitoria, recebe eventos de monitoria de um setor específico.
|
|
30
|
+
*/
|
|
31
|
+
export type SocketMonitorRoom = `sector:${SectorId}:monitor`;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Sala de relatórios, recebe eventos de um tipo relatório específico de um setor específico.
|
|
35
|
+
*/
|
|
36
|
+
export type SocketReportsRoom = `sector:${number}:reports:${string}`;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Tipo de sala de socket.
|
|
40
|
+
*/
|
|
41
|
+
export type SocketRoomType = SocketChatRoom | SocketAdminRoom | SocketReportsRoom | SocketMonitorRoom;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Ainda não implementado.
|
|
45
|
+
*/
|
|
46
|
+
export type NotImplemented = unknown;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Dados de status de um relatório.
|
|
50
|
+
*/
|
|
51
|
+
export type ReportStatusData = {
|
|
52
|
+
id: number;
|
|
53
|
+
type: string;
|
|
54
|
+
progress: number;
|
|
55
|
+
isCompleted: boolean;
|
|
56
|
+
isFailed: boolean;
|
|
57
|
+
error?: string;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* String representando um QR Code.
|
|
62
|
+
*/
|
|
63
|
+
export type QRCode = string;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Id de um chat.
|
|
67
|
+
*/
|
|
68
|
+
export type ChatId = number;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Id de um setor.
|
|
72
|
+
*/
|
|
73
|
+
export type SectorId = number;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Nome de uma instância.
|
|
77
|
+
*/
|
|
78
|
+
export type InstanceName = string;
|
|
79
|
+
|
|
80
|
+
export type EmitFunction = {
|
|
81
|
+
(
|
|
82
|
+
instanceName: string,
|
|
83
|
+
room: SocketChatRoom | SocketMonitorRoom,
|
|
84
|
+
event: SocketEventType.NEW_CHAT,
|
|
85
|
+
value: NotImplemented
|
|
86
|
+
): void;
|
|
87
|
+
(
|
|
88
|
+
instanceName: string,
|
|
89
|
+
room: SocketChatRoom | SocketMonitorRoom,
|
|
90
|
+
event: SocketEventType.CHAT_FINISHED,
|
|
91
|
+
value: ChatId
|
|
92
|
+
): void;
|
|
93
|
+
(
|
|
94
|
+
instanceName: string,
|
|
95
|
+
room: SocketAdminRoom,
|
|
96
|
+
event: SocketEventType.QR_CODE,
|
|
97
|
+
value: QRCode
|
|
98
|
+
): void;
|
|
99
|
+
(
|
|
100
|
+
instanceName: string,
|
|
101
|
+
room: SocketChatRoom,
|
|
102
|
+
event: SocketEventType.MESSAGE,
|
|
103
|
+
value: NotImplemented
|
|
104
|
+
): void;
|
|
105
|
+
(
|
|
106
|
+
instanceName: string,
|
|
107
|
+
room: SocketAdminRoom,
|
|
108
|
+
event: SocketEventType.NOTIFICATION,
|
|
109
|
+
value: NotImplemented
|
|
110
|
+
): void;
|
|
111
|
+
(
|
|
112
|
+
instanceName: string,
|
|
113
|
+
room: SocketChatRoom,
|
|
114
|
+
event: SocketEventType.MESSAGE_EDIT,
|
|
115
|
+
value: NotImplemented
|
|
116
|
+
): void;
|
|
117
|
+
(
|
|
118
|
+
instanceName: string,
|
|
119
|
+
room: SocketChatRoom,
|
|
120
|
+
event: SocketEventType.MESSAGE_STATUS,
|
|
121
|
+
value: NotImplemented
|
|
122
|
+
): void;
|
|
123
|
+
(
|
|
124
|
+
instanceName: string,
|
|
125
|
+
room: SocketAdminRoom,
|
|
126
|
+
event: SocketEventType.REPORT_STATUS,
|
|
127
|
+
value: ReportStatusData
|
|
128
|
+
): void;
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Classe para manipulação de eventos de socket.
|
|
133
|
+
*/
|
|
134
|
+
export default class SocketServerSDK {
|
|
135
|
+
|
|
136
|
+
constructor(private readonly httpClient: AxiosInstance) { }
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Emite um evento de socket.
|
|
140
|
+
* @param instanceName - O nome da instância.
|
|
141
|
+
* @param room - A sala de destino.
|
|
142
|
+
* @param event - O tipo do evento.
|
|
143
|
+
* @param value - O valor do evento.
|
|
144
|
+
*/
|
|
145
|
+
public emit: EmitFunction = async (instanceName, room, event, value) => {
|
|
146
|
+
await this.httpClient.post(`/emit/${instanceName}/${room}/${event}`, value);
|
|
147
|
+
}
|
|
148
|
+
}
|