@in.pulse-crm/sdk 2.0.4 → 2.0.5
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/reports.client.d.ts +30 -0
- package/dist/reports.client.js +32 -1
- package/dist/socket.client.d.ts +2 -0
- package/dist/socket.client.js +4 -1
- package/dist/types/socket-rooms.types.d.ts +3 -0
- package/package.json +1 -1
- package/src/reports.client.ts +32 -1
- package/src/socket.client.ts +73 -64
- package/src/types/socket-rooms.types.ts +20 -5
package/dist/reports.client.d.ts
CHANGED
|
@@ -1,9 +1,39 @@
|
|
|
1
1
|
import ApiClient from "./api-client";
|
|
2
2
|
import { ChatsReport, GenerateChatsReportOptions } from "./types/reports.types";
|
|
3
3
|
import { DataResponse, MessageResponse } from "./types/response.types";
|
|
4
|
+
/**
|
|
5
|
+
* ReportsClient class to handle reports related API calls.
|
|
6
|
+
*
|
|
7
|
+
* This class extends the ApiClient class and provides methods to interact with the reports API.
|
|
8
|
+
* It includes methods to get, generate, and delete chat reports.
|
|
9
|
+
*/
|
|
4
10
|
export default class ReportsClient extends ApiClient {
|
|
11
|
+
/**
|
|
12
|
+
* Retrieves chat reports from the server.
|
|
13
|
+
*
|
|
14
|
+
* @returns A promise that resolves to an array of chat reports wrapped in a `DataResponse` object.
|
|
15
|
+
*/
|
|
5
16
|
getChatsReports(): Promise<DataResponse<ChatsReport[]>>;
|
|
17
|
+
/**
|
|
18
|
+
* Generates a report for chat interactions based on the provided options.
|
|
19
|
+
*
|
|
20
|
+
* @param body - The options for generating the chats report, including filters and parameters.
|
|
21
|
+
* @returns A promise that resolves to the data of the generated chats report.
|
|
22
|
+
*/
|
|
6
23
|
generateChatsReport(body: GenerateChatsReportOptions): Promise<DataResponse<ChatsReport>>;
|
|
24
|
+
/**
|
|
25
|
+
* Deletes a chat report by its unique identifier.
|
|
26
|
+
*
|
|
27
|
+
* @param chatsReportId - The unique identifier of the chat report to be deleted.
|
|
28
|
+
* @returns A promise that resolves to a `MessageResponse` object containing the result of the deletion operation.
|
|
29
|
+
*/
|
|
7
30
|
deleteChatsReport(chatsReportId: number): Promise<MessageResponse>;
|
|
31
|
+
/**
|
|
32
|
+
* Sets the authorization token for the HTTP client.
|
|
33
|
+
*
|
|
34
|
+
* @param token - The Bearer token to be used for authentication.
|
|
35
|
+
* This token will be included in the `Authorization` header
|
|
36
|
+
* of all HTTP requests made by the client.
|
|
37
|
+
*/
|
|
8
38
|
setAuth(token: string): void;
|
|
9
39
|
}
|
package/dist/reports.client.js
CHANGED
|
@@ -4,24 +4,55 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const api_client_1 = __importDefault(require("./api-client"));
|
|
7
|
+
/**
|
|
8
|
+
* ReportsClient class to handle reports related API calls.
|
|
9
|
+
*
|
|
10
|
+
* This class extends the ApiClient class and provides methods to interact with the reports API.
|
|
11
|
+
* It includes methods to get, generate, and delete chat reports.
|
|
12
|
+
*/
|
|
7
13
|
class ReportsClient extends api_client_1.default {
|
|
14
|
+
/**
|
|
15
|
+
* Retrieves chat reports from the server.
|
|
16
|
+
*
|
|
17
|
+
* @returns A promise that resolves to an array of chat reports wrapped in a `DataResponse` object.
|
|
18
|
+
*/
|
|
8
19
|
async getChatsReports() {
|
|
9
20
|
const url = `/api/reports/chats`;
|
|
10
21
|
const response = await this.httpClient.get(url);
|
|
11
22
|
return response.data;
|
|
12
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Generates a report for chat interactions based on the provided options.
|
|
26
|
+
*
|
|
27
|
+
* @param body - The options for generating the chats report, including filters and parameters.
|
|
28
|
+
* @returns A promise that resolves to the data of the generated chats report.
|
|
29
|
+
*/
|
|
13
30
|
async generateChatsReport(body) {
|
|
14
31
|
const url = `/api/reports/chats`;
|
|
15
32
|
const response = await this.httpClient.post(url, body);
|
|
16
33
|
return response.data;
|
|
17
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* Deletes a chat report by its unique identifier.
|
|
37
|
+
*
|
|
38
|
+
* @param chatsReportId - The unique identifier of the chat report to be deleted.
|
|
39
|
+
* @returns A promise that resolves to a `MessageResponse` object containing the result of the deletion operation.
|
|
40
|
+
*/
|
|
18
41
|
async deleteChatsReport(chatsReportId) {
|
|
19
42
|
const url = `/api/reports/chats/${chatsReportId}`;
|
|
20
43
|
const response = await this.httpClient.delete(url);
|
|
21
44
|
return response.data;
|
|
22
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* Sets the authorization token for the HTTP client.
|
|
48
|
+
*
|
|
49
|
+
* @param token - The Bearer token to be used for authentication.
|
|
50
|
+
* This token will be included in the `Authorization` header
|
|
51
|
+
* of all HTTP requests made by the client.
|
|
52
|
+
*/
|
|
23
53
|
setAuth(token) {
|
|
24
|
-
this.httpClient.defaults.headers.common["Authorization"] =
|
|
54
|
+
this.httpClient.defaults.headers.common["Authorization"] =
|
|
55
|
+
`Bearer ${token}`;
|
|
25
56
|
}
|
|
26
57
|
}
|
|
27
58
|
exports.default = ReportsClient;
|
package/dist/socket.client.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ListenSocketEventFn, UnlistenSocketEventFn } from "./types/socket-events.types";
|
|
2
|
+
import { JoinRoomFn } from "./types";
|
|
2
3
|
/**
|
|
3
4
|
* A client for interacting with a WebSocket server.
|
|
4
5
|
* This class provides methods to connect to the server, listen for events,
|
|
@@ -46,4 +47,5 @@ export default class SocketClient {
|
|
|
46
47
|
* @param callback - The callback function that was previously registered for the event.
|
|
47
48
|
*/
|
|
48
49
|
off: UnlistenSocketEventFn;
|
|
50
|
+
joinRoom: JoinRoomFn;
|
|
49
51
|
}
|
package/dist/socket.client.js
CHANGED
|
@@ -22,7 +22,7 @@ class SocketClient {
|
|
|
22
22
|
constructor(baseUrl) {
|
|
23
23
|
this.ws = (0, socket_io_client_1.io)(baseUrl, {
|
|
24
24
|
autoConnect: false,
|
|
25
|
-
transports: [
|
|
25
|
+
transports: ["websocket"],
|
|
26
26
|
});
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
@@ -70,5 +70,8 @@ class SocketClient {
|
|
|
70
70
|
return;
|
|
71
71
|
this.ws.off(event, listener);
|
|
72
72
|
};
|
|
73
|
+
joinRoom = (room) => {
|
|
74
|
+
this.ws.emit("join-room", room);
|
|
75
|
+
};
|
|
73
76
|
}
|
|
74
77
|
exports.default = SocketClient;
|
|
@@ -12,4 +12,7 @@ export type SocketServerMonitorRoom = SocketRoomWithSector<SocketClientMonitorRo
|
|
|
12
12
|
export type SocketServerReportsRoom = SocketRoomWithSector<SocketClientReportsRoom>;
|
|
13
13
|
export type SocketServerChatRoom = SocketRoomWithInstance<SocketClientChatRoom>;
|
|
14
14
|
export type SocketServerRoom = SocketServerChatRoom | SocketServerAdminRoom | SocketServerMonitorRoom | SocketServerReportsRoom;
|
|
15
|
+
export interface JoinRoomFn {
|
|
16
|
+
(room: SocketClientRoom): void;
|
|
17
|
+
}
|
|
15
18
|
export {};
|
package/package.json
CHANGED
package/src/reports.client.ts
CHANGED
|
@@ -2,7 +2,18 @@ import ApiClient from "./api-client";
|
|
|
2
2
|
import { ChatsReport, GenerateChatsReportOptions } from "./types/reports.types";
|
|
3
3
|
import { DataResponse, MessageResponse } from "./types/response.types";
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* ReportsClient class to handle reports related API calls.
|
|
7
|
+
*
|
|
8
|
+
* This class extends the ApiClient class and provides methods to interact with the reports API.
|
|
9
|
+
* It includes methods to get, generate, and delete chat reports.
|
|
10
|
+
*/
|
|
5
11
|
export default class ReportsClient extends ApiClient {
|
|
12
|
+
/**
|
|
13
|
+
* Retrieves chat reports from the server.
|
|
14
|
+
*
|
|
15
|
+
* @returns A promise that resolves to an array of chat reports wrapped in a `DataResponse` object.
|
|
16
|
+
*/
|
|
6
17
|
public async getChatsReports() {
|
|
7
18
|
const url = `/api/reports/chats`;
|
|
8
19
|
const response =
|
|
@@ -11,6 +22,12 @@ export default class ReportsClient extends ApiClient {
|
|
|
11
22
|
return response.data;
|
|
12
23
|
}
|
|
13
24
|
|
|
25
|
+
/**
|
|
26
|
+
* Generates a report for chat interactions based on the provided options.
|
|
27
|
+
*
|
|
28
|
+
* @param body - The options for generating the chats report, including filters and parameters.
|
|
29
|
+
* @returns A promise that resolves to the data of the generated chats report.
|
|
30
|
+
*/
|
|
14
31
|
public async generateChatsReport(body: GenerateChatsReportOptions) {
|
|
15
32
|
const url = `/api/reports/chats`;
|
|
16
33
|
const response = await this.httpClient.post<DataResponse<ChatsReport>>(
|
|
@@ -21,6 +38,12 @@ export default class ReportsClient extends ApiClient {
|
|
|
21
38
|
return response.data;
|
|
22
39
|
}
|
|
23
40
|
|
|
41
|
+
/**
|
|
42
|
+
* Deletes a chat report by its unique identifier.
|
|
43
|
+
*
|
|
44
|
+
* @param chatsReportId - The unique identifier of the chat report to be deleted.
|
|
45
|
+
* @returns A promise that resolves to a `MessageResponse` object containing the result of the deletion operation.
|
|
46
|
+
*/
|
|
24
47
|
public async deleteChatsReport(chatsReportId: number) {
|
|
25
48
|
const url = `/api/reports/chats/${chatsReportId}`;
|
|
26
49
|
const response = await this.httpClient.delete<MessageResponse>(url);
|
|
@@ -28,7 +51,15 @@ export default class ReportsClient extends ApiClient {
|
|
|
28
51
|
return response.data;
|
|
29
52
|
}
|
|
30
53
|
|
|
54
|
+
/**
|
|
55
|
+
* Sets the authorization token for the HTTP client.
|
|
56
|
+
*
|
|
57
|
+
* @param token - The Bearer token to be used for authentication.
|
|
58
|
+
* This token will be included in the `Authorization` header
|
|
59
|
+
* of all HTTP requests made by the client.
|
|
60
|
+
*/
|
|
31
61
|
public setAuth(token: string) {
|
|
32
|
-
this.httpClient.defaults.headers.common["Authorization"] =
|
|
62
|
+
this.httpClient.defaults.headers.common["Authorization"] =
|
|
63
|
+
`Bearer ${token}`;
|
|
33
64
|
}
|
|
34
65
|
}
|
package/src/socket.client.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { io, Socket } from "socket.io-client";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
ListenSocketEventFn,
|
|
4
|
+
SocketEventType,
|
|
5
|
+
UnlistenSocketEventFn,
|
|
6
|
+
} from "./types/socket-events.types";
|
|
7
|
+
import { JoinRoomFn } from "./types";
|
|
3
8
|
|
|
4
9
|
/**
|
|
5
10
|
* A client for interacting with a WebSocket server.
|
|
@@ -7,72 +12,76 @@ import { ListenSocketEventFn, SocketEventType, UnlistenSocketEventFn } from "./t
|
|
|
7
12
|
* and manage WebSocket connections.
|
|
8
13
|
*/
|
|
9
14
|
export default class SocketClient {
|
|
10
|
-
|
|
11
|
-
|
|
15
|
+
private readonly ws: Socket;
|
|
16
|
+
private readonly listeners: Map<SocketEventType, any> = new Map();
|
|
12
17
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Initializes a new instance of the socket client.
|
|
20
|
+
*
|
|
21
|
+
* @param baseUrl - The base URL of the WebSocket server to connect to.
|
|
22
|
+
* This URL is used to establish the WebSocket connection.
|
|
23
|
+
*
|
|
24
|
+
* The WebSocket client is configured with the following options:
|
|
25
|
+
* - `autoConnect`: Disabled by default to allow manual connection control.
|
|
26
|
+
* - `transports`: Uses the 'websocket' transport protocol exclusively.
|
|
27
|
+
*/
|
|
28
|
+
constructor(baseUrl: string) {
|
|
29
|
+
this.ws = io(baseUrl, {
|
|
30
|
+
autoConnect: false,
|
|
31
|
+
transports: ["websocket"],
|
|
32
|
+
});
|
|
33
|
+
}
|
|
29
34
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
35
|
+
/**
|
|
36
|
+
* Establishes a WebSocket connection using the provided authentication token.
|
|
37
|
+
*
|
|
38
|
+
* @param token - The authentication token to be used for the WebSocket connection.
|
|
39
|
+
* This token is sent as part of the WebSocket authentication payload.
|
|
40
|
+
*/
|
|
41
|
+
public connect(token: string) {
|
|
42
|
+
this.ws.auth = { token };
|
|
43
|
+
this.ws.connect();
|
|
44
|
+
}
|
|
40
45
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
/**
|
|
47
|
+
* Disconnects the WebSocket client from the server.
|
|
48
|
+
* This method terminates the current WebSocket connection
|
|
49
|
+
* by invoking the `disconnect` method on the WebSocket instance.
|
|
50
|
+
*/
|
|
51
|
+
public disconnect() {
|
|
52
|
+
this.ws.disconnect();
|
|
53
|
+
}
|
|
49
54
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
55
|
+
/**
|
|
56
|
+
* Registers an event listener for a specified WebSocket event and provides a way to remove it.
|
|
57
|
+
*
|
|
58
|
+
* @param event - The name of the WebSocket event to listen for.
|
|
59
|
+
* @param callback - A function to be executed when the event is triggered. The function receives the event data as its argument.
|
|
60
|
+
* @returns A function that, when called, removes the event listener for the specified event.
|
|
61
|
+
*/
|
|
62
|
+
public on: ListenSocketEventFn = (event, callback) => {
|
|
63
|
+
if (!this.listeners.get(event)) {
|
|
64
|
+
this.ws.on(event, (data) => {
|
|
65
|
+
callback(data);
|
|
66
|
+
});
|
|
62
67
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
68
|
+
this.listeners.set(event, callback);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
66
71
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
72
|
+
/**
|
|
73
|
+
* Removes a previously registered event listener from the WebSocket connection.
|
|
74
|
+
*
|
|
75
|
+
* @param event - The name of the event to stop listening for.
|
|
76
|
+
* @param callback - The callback function that was previously registered for the event.
|
|
77
|
+
*/
|
|
78
|
+
public off: UnlistenSocketEventFn = (event) => {
|
|
79
|
+
const listener = this.listeners.get(event);
|
|
80
|
+
if (!listener) return;
|
|
81
|
+
this.ws.off(event, listener);
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
public joinRoom: JoinRoomFn = (room) => {
|
|
85
|
+
this.ws.emit("join-room", room);
|
|
86
|
+
};
|
|
87
|
+
}
|
|
@@ -10,13 +10,18 @@ export type SocketClientChatRoom = `chat:${PhoneNumber}`;
|
|
|
10
10
|
export type SocketClientAdminRoom = "admin";
|
|
11
11
|
export type SocketClientMonitorRoom = `monitor`;
|
|
12
12
|
export type SocketClientReportsRoom = `reports:${ReportType}`;
|
|
13
|
-
export type SocketClientRoom =
|
|
13
|
+
export type SocketClientRoom =
|
|
14
|
+
| SocketClientChatRoom
|
|
15
|
+
| SocketClientAdminRoom
|
|
16
|
+
| SocketClientReportsRoom
|
|
17
|
+
| SocketClientMonitorRoom;
|
|
14
18
|
|
|
15
19
|
// Interface que incluí o nome da instancia na sala de socket;
|
|
16
20
|
type SocketRoomWithInstance<T extends string> = `${string}:${T}`;
|
|
17
21
|
|
|
18
22
|
// Interface que incluí o nome da instancia e o id do setor na sala de socket;
|
|
19
|
-
type SocketRoomWithSector<T extends string> =
|
|
23
|
+
type SocketRoomWithSector<T extends string> =
|
|
24
|
+
SocketRoomWithInstance<`${number}:${T}`>;
|
|
20
25
|
|
|
21
26
|
/*
|
|
22
27
|
Salas de Socket do lado do servidor;
|
|
@@ -25,7 +30,17 @@ type SocketRoomWithSector<T extends string> = SocketRoomWithInstance<`${number}:
|
|
|
25
30
|
pertence, e não as salas de outras instancias.
|
|
26
31
|
*/
|
|
27
32
|
export type SocketServerAdminRoom = SocketRoomWithSector<SocketClientAdminRoom>;
|
|
28
|
-
export type SocketServerMonitorRoom =
|
|
29
|
-
|
|
33
|
+
export type SocketServerMonitorRoom =
|
|
34
|
+
SocketRoomWithSector<SocketClientMonitorRoom>;
|
|
35
|
+
export type SocketServerReportsRoom =
|
|
36
|
+
SocketRoomWithSector<SocketClientReportsRoom>;
|
|
30
37
|
export type SocketServerChatRoom = SocketRoomWithInstance<SocketClientChatRoom>;
|
|
31
|
-
export type SocketServerRoom =
|
|
38
|
+
export type SocketServerRoom =
|
|
39
|
+
| SocketServerChatRoom
|
|
40
|
+
| SocketServerAdminRoom
|
|
41
|
+
| SocketServerMonitorRoom
|
|
42
|
+
| SocketServerReportsRoom;
|
|
43
|
+
|
|
44
|
+
export interface JoinRoomFn {
|
|
45
|
+
(room: SocketClientRoom): void;
|
|
46
|
+
}
|