@in.pulse-crm/sdk 1.6.1 → 2.0.0
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/api-client.d.ts +9 -0
- package/dist/api-client.js +29 -0
- package/dist/{auth.d.ts → auth.client.d.ts} +4 -38
- package/dist/{auth.js → auth.client.js} +6 -10
- package/dist/customers.client.d.ts +37 -0
- package/dist/{customer.js → customers.client.js} +6 -10
- package/dist/files.client.d.ts +31 -0
- package/dist/{file.js → files.client.js} +6 -26
- package/dist/index.d.ts +9 -12
- package/dist/index.js +21 -41
- package/dist/{instance.d.ts → instance.client.d.ts} +3 -9
- package/dist/{instance.js → instance.client.js} +6 -10
- package/dist/reports.client.d.ts +9 -0
- package/dist/{report.js → reports.client.js} +6 -6
- package/dist/socket-server.client.d.ts +24 -0
- package/dist/socket-server.client.js +34 -0
- package/dist/socket.client.d.ts +49 -0
- package/dist/socket.client.js +74 -0
- package/dist/types/auth.types.d.ts +29 -0
- package/dist/{customer.d.ts → types/customers.types.d.ts} +0 -42
- package/dist/{file.d.ts → types/files.types.d.ts} +3 -38
- package/dist/types/files.types.js +15 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/index.js +23 -0
- package/dist/{report.d.ts → types/reports.types.d.ts} +0 -10
- package/dist/types/socket-events.types.d.ts +72 -0
- package/dist/types/socket-events.types.js +19 -0
- package/dist/types/socket-rooms.types.d.ts +15 -0
- package/dist/{user.d.ts → types/user.types.d.ts} +0 -41
- package/dist/types/user.types.js +19 -0
- package/dist/users.client.d.ts +40 -0
- package/dist/{user.js → users.client.js} +11 -27
- package/package.json +1 -1
- package/src/api-client.ts +33 -0
- package/src/{auth.ts → auth.client.ts} +4 -43
- package/src/customers.client.ts +66 -0
- package/src/files.client.ts +57 -0
- package/src/index.ts +9 -87
- package/src/{instance.ts → instance.client.ts} +4 -8
- package/src/reports.client.ts +34 -0
- package/src/socket-server.client.ts +32 -0
- package/src/socket.client.ts +78 -0
- package/src/types/auth.types.ts +31 -0
- package/src/types/customers.types.ts +68 -0
- package/src/types/files.types.ts +78 -0
- package/src/types/index.ts +7 -0
- package/src/types/reports.types.ts +24 -0
- package/src/types/socket-events.types.ts +76 -0
- package/src/types/socket-rooms.types.ts +31 -0
- package/src/{user.ts → types/user.types.ts} +1 -78
- package/src/users.client.ts +74 -0
- package/dist/auth.sdk.d.ts +0 -15
- package/dist/auth.sdk.js +0 -62
- package/dist/instance.sdk.d.ts +0 -10
- package/dist/instance.sdk.js +0 -27
- package/dist/socket-client.d.ts +0 -57
- package/dist/socket-client.js +0 -74
- package/dist/socket-server.d.ts +0 -17
- package/dist/socket-server.js +0 -22
- package/dist/src/sdks/auth.sdk.js +0 -52
- package/dist/src/sdks/index.js +0 -14
- package/dist/src/sdks/instance.sdk.js +0 -31
- package/dist/src/sdks/user.sdk.js +0 -42
- package/dist/src/types/user.types.js +0 -2
- package/dist/types/socket-client.types.d.ts +0 -97
- package/dist/types/socket-client.types.js +0 -2
- package/dist/types/socket-server.types.d.ts +0 -120
- package/dist/types/socket-server.types.js +0 -2
- package/dist/user.sdk.d.ts +0 -14
- package/dist/user.sdk.js +0 -39
- package/src/customer.ts +0 -140
- package/src/file.ts +0 -145
- package/src/report.ts +0 -60
- package/src/socket-client.ts +0 -78
- package/src/socket-server.ts +0 -20
- package/src/types/socket-client.types.ts +0 -114
- package/src/types/socket-server.types.ts +0 -171
- /package/dist/{src/types → types}/auth.types.js +0 -0
- /package/dist/{response.js → types/customers.types.js} +0 -0
- /package/dist/{src/types/index.js → types/reports.types.js} +0 -0
- /package/dist/{response.d.ts → types/response.types.d.ts} +0 -0
- /package/dist/{src/types → types}/response.types.js +0 -0
- /package/dist/{src/types/instance.types.js → types/socket-rooms.types.js} +0 -0
- /package/src/{response.ts → types/response.types.ts} +0 -0
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { AxiosInstance } from "axios";
|
|
2
1
|
export interface Customer {
|
|
3
2
|
CODIGO: number;
|
|
4
3
|
RAZAO: string;
|
|
@@ -66,44 +65,3 @@ export interface Customer {
|
|
|
66
65
|
}
|
|
67
66
|
export type CreateCustomerDTO = Pick<Customer, "RAZAO" | "FANTASIA" | "CPF_CNPJ" | "PESSOA" | "CIDADE" | "ESTADO" | "COD_ERP">;
|
|
68
67
|
export type UpdateCustomerDTO = Partial<CreateCustomerDTO>;
|
|
69
|
-
declare class CustomerSDK {
|
|
70
|
-
private readonly httpClient;
|
|
71
|
-
/**
|
|
72
|
-
* Cria uma instância do SDK de usuários.
|
|
73
|
-
* @param httpClient - A instância do cliente HTTP a ser usada para fazer requisições à API.
|
|
74
|
-
*/
|
|
75
|
-
constructor(httpClient: AxiosInstance);
|
|
76
|
-
/**
|
|
77
|
-
* Cria um novo cliente.
|
|
78
|
-
* @param data - Os dados do cliente a serem criados.
|
|
79
|
-
* @returns Uma Promise que resolve para o cliente criado.
|
|
80
|
-
*/
|
|
81
|
-
createCustomer(data: CreateCustomerDTO): Promise<any>;
|
|
82
|
-
/**
|
|
83
|
-
* Obtém um cliente pelo ID.
|
|
84
|
-
* @param customerId - O ID do cliente a ser obtido.
|
|
85
|
-
* @returns Uma Promise que resolve para o cliente obtido.
|
|
86
|
-
*/
|
|
87
|
-
getCustomerById(customerId: number): Promise<any>;
|
|
88
|
-
/**
|
|
89
|
-
* Atualiza um cliente existente.
|
|
90
|
-
* @param customerId - O ID do cliente a ser atualizado.
|
|
91
|
-
* @param data - Os dados atualizados do cliente.
|
|
92
|
-
* @returns Uma Promise que resolve para o cliente atualizado.
|
|
93
|
-
*/
|
|
94
|
-
updateCustomer(customerId: number, data: UpdateCustomerDTO): Promise<any>;
|
|
95
|
-
/**
|
|
96
|
-
* Obtém todos os clientes.
|
|
97
|
-
*
|
|
98
|
-
* @param filters - Filtros opcionais para a busca de clientes.
|
|
99
|
-
* @todo Implementar tipagem para os filtros.
|
|
100
|
-
* @returns Uma Promise que resolve para uma lista de clientes.
|
|
101
|
-
*/
|
|
102
|
-
getAllCustomers(filters: Record<string, string>): Promise<any>;
|
|
103
|
-
/**
|
|
104
|
-
* Define o token de autenticação para as requisições.
|
|
105
|
-
* @param token - O token de autenticação a ser definido.
|
|
106
|
-
*/
|
|
107
|
-
setAuth(token: string): void;
|
|
108
|
-
}
|
|
109
|
-
export default CustomerSDK;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
export interface UploadFileOptions {
|
|
3
4
|
/**
|
|
4
5
|
* Nome da instância onde o arquivo está armazenado.
|
|
5
6
|
*/
|
|
@@ -65,39 +66,3 @@ export interface File {
|
|
|
65
66
|
*/
|
|
66
67
|
created_at: Date;
|
|
67
68
|
}
|
|
68
|
-
/**
|
|
69
|
-
* SDK para operações de arquivos.
|
|
70
|
-
*/
|
|
71
|
-
declare class FileSDK {
|
|
72
|
-
private readonly httpClient;
|
|
73
|
-
/**
|
|
74
|
-
* Cria uma instância do SDK de arquivos.
|
|
75
|
-
* @param httpClient A instância do cliente HTTP a ser usada para fazer requisições à API.
|
|
76
|
-
*/
|
|
77
|
-
constructor(httpClient: AxiosInstance);
|
|
78
|
-
/**
|
|
79
|
-
* Busca um arquivo pelo ID.
|
|
80
|
-
* @param {number} id - ID do arquivo.
|
|
81
|
-
* @returns {Promise<Buffer>} Um buffer contendo os dados do arquivo.
|
|
82
|
-
*/
|
|
83
|
-
fetchFile(id: number): Promise<Buffer>;
|
|
84
|
-
/**
|
|
85
|
-
* Obtém a URL de download de um arquivo.
|
|
86
|
-
* @param {number} id - ID do arquivo.
|
|
87
|
-
* @returns {string} URL de download do arquivo.
|
|
88
|
-
*/
|
|
89
|
-
getFileDownloadUrl(id: number): string;
|
|
90
|
-
/**
|
|
91
|
-
* Faz o upload de um arquivo.
|
|
92
|
-
* @param {UploadFileOptions} props - Opções para o upload do arquivo.
|
|
93
|
-
* @returns {Promise<File>} Os dados do arquivo enviado.
|
|
94
|
-
*/
|
|
95
|
-
uploadFile(props: UploadFileOptions): Promise<File>;
|
|
96
|
-
/**
|
|
97
|
-
* Deleta um arquivo pelo ID.
|
|
98
|
-
* @param {number} id - ID do arquivo.
|
|
99
|
-
* @returns {Promise<void>}
|
|
100
|
-
*/
|
|
101
|
-
deleteFile(id: number): Promise<void>;
|
|
102
|
-
}
|
|
103
|
-
export default FileSDK;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FileDirType = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Enum que representa os tipos de diretórios de arquivos.
|
|
6
|
+
*
|
|
7
|
+
* @enum {string}
|
|
8
|
+
* @property {string} PUBLIC - Representa o diretório público.
|
|
9
|
+
* @property {string} MODELS - Representa o diretório de modelos.
|
|
10
|
+
*/
|
|
11
|
+
var FileDirType;
|
|
12
|
+
(function (FileDirType) {
|
|
13
|
+
FileDirType["PUBLIC"] = "public";
|
|
14
|
+
FileDirType["MODELS"] = "models";
|
|
15
|
+
})(FileDirType || (exports.FileDirType = FileDirType = {}));
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./response.types"), exports);
|
|
18
|
+
__exportStar(require("./socket-events.types"), exports);
|
|
19
|
+
__exportStar(require("./socket-rooms.types"), exports);
|
|
20
|
+
__exportStar(require("./auth.types"), exports);
|
|
21
|
+
__exportStar(require("./user.types"), exports);
|
|
22
|
+
__exportStar(require("./customers.types"), exports);
|
|
23
|
+
__exportStar(require("./files.types"), exports);
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { AxiosInstance } from "axios";
|
|
2
|
-
import { DataResponse, MessageResponse } from "./response";
|
|
3
1
|
export type ReportType = "chats";
|
|
4
2
|
export type ChatsReportFormat = "txt" | "csv" | "pdf";
|
|
5
3
|
export type ChatsReportStatus = "pending" | "completed" | "failed";
|
|
@@ -22,11 +20,3 @@ export interface GenerateChatsReportOptions {
|
|
|
22
20
|
startDate: string;
|
|
23
21
|
endDate: string;
|
|
24
22
|
}
|
|
25
|
-
export default class ReportSDK {
|
|
26
|
-
private readonly httpClient;
|
|
27
|
-
constructor(httpClient: AxiosInstance);
|
|
28
|
-
getChatsReports(): Promise<DataResponse<ChatsReport[]>>;
|
|
29
|
-
generateChatsReport(body: GenerateChatsReportOptions): Promise<DataResponse<ChatsReport>>;
|
|
30
|
-
deleteChatsReport(chatsReportId: number): Promise<MessageResponse>;
|
|
31
|
-
setAuth(token: string): void;
|
|
32
|
-
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { SocketServerAdminRoom, SocketServerChatRoom, SocketServerReportsRoom, SocketServerRoom } from "./socket-rooms.types";
|
|
2
|
+
import { MessageResponse } from "./response.types";
|
|
3
|
+
export declare enum SocketEventType {
|
|
4
|
+
WppChatStarted = "wpp_chat_started",
|
|
5
|
+
WppChatFinished = "wpp_chat_finished",
|
|
6
|
+
WppMessage = "wpp_message",
|
|
7
|
+
WppMessageStatus = "wpp_message_status",
|
|
8
|
+
WppMessageReaction = "wpp_message_reaction",
|
|
9
|
+
WwebjsQr = "wwebjs_qr",
|
|
10
|
+
WwebjsAuth = "wwebjs_auth",
|
|
11
|
+
ReportStatus = "report_status"
|
|
12
|
+
}
|
|
13
|
+
export interface EmitSocketEventFn {
|
|
14
|
+
(type: SocketEventType.WwebjsQr, room: SocketServerAdminRoom, data: WWEBJSQrEventData): Promise<MessageResponse>;
|
|
15
|
+
(type: SocketEventType.WwebjsAuth, room: SocketServerAdminRoom, data: WWEBJSAuthEventData): Promise<MessageResponse>;
|
|
16
|
+
(type: SocketEventType.WppChatStarted, room: SocketServerRoom, data: WppChatStartedEventData): Promise<MessageResponse>;
|
|
17
|
+
(type: SocketEventType.WppChatFinished, room: SocketServerRoom, data: WppChatFinishedEventData): Promise<MessageResponse>;
|
|
18
|
+
(type: SocketEventType.WppMessage, room: SocketServerChatRoom, data: WppMessageEventData): Promise<MessageResponse>;
|
|
19
|
+
(type: SocketEventType.WppMessageStatus, room: SocketServerChatRoom, data: WppMessageStatusEventData): Promise<MessageResponse>;
|
|
20
|
+
(type: SocketEventType.WppMessageReaction, room: SocketServerChatRoom, data: WppMessageReactionEventData): Promise<MessageResponse>;
|
|
21
|
+
(type: SocketEventType.ReportStatus, room: SocketServerReportsRoom, data: ReportStatusEventData): Promise<MessageResponse>;
|
|
22
|
+
}
|
|
23
|
+
export interface ListenSocketEventFn {
|
|
24
|
+
(type: SocketEventType.WwebjsQr, callback: (data: WWEBJSQrEventData) => void): void;
|
|
25
|
+
(type: SocketEventType.WwebjsAuth, callback: (data: WWEBJSAuthEventData) => void): void;
|
|
26
|
+
(type: SocketEventType.WppChatStarted, callback: (data: WppChatStartedEventData) => void): void;
|
|
27
|
+
(type: SocketEventType.WppChatFinished, callback: (data: WppChatFinishedEventData) => void): void;
|
|
28
|
+
(type: SocketEventType.WppMessage, callback: (data: WppMessageEventData) => void): void;
|
|
29
|
+
(type: SocketEventType.WppMessageStatus, callback: (data: WppMessageStatusEventData) => void): void;
|
|
30
|
+
(type: SocketEventType.WppMessageReaction, callback: (data: WppMessageReactionEventData) => void): void;
|
|
31
|
+
(type: SocketEventType.ReportStatus, callback: (data: ReportStatusEventData) => void): void;
|
|
32
|
+
}
|
|
33
|
+
export interface UnlistenSocketEventFn {
|
|
34
|
+
(type: SocketEventType): void;
|
|
35
|
+
}
|
|
36
|
+
export interface WWEBJSQrEventData {
|
|
37
|
+
qr: string;
|
|
38
|
+
phone: string;
|
|
39
|
+
}
|
|
40
|
+
export interface WWEBJSAuthEventData {
|
|
41
|
+
phone: string;
|
|
42
|
+
success: boolean;
|
|
43
|
+
message?: string;
|
|
44
|
+
}
|
|
45
|
+
export interface WppChatStartedEventData {
|
|
46
|
+
}
|
|
47
|
+
export interface WppChatFinishedEventData {
|
|
48
|
+
}
|
|
49
|
+
export interface WppMessageEventData {
|
|
50
|
+
}
|
|
51
|
+
export interface WppMessageStatusEventData {
|
|
52
|
+
}
|
|
53
|
+
export interface WppMessageReactionEventData {
|
|
54
|
+
}
|
|
55
|
+
export type ReportStatusEventData = {
|
|
56
|
+
id: number;
|
|
57
|
+
type: string;
|
|
58
|
+
} & ({
|
|
59
|
+
isCompleted: true;
|
|
60
|
+
isFailed: false;
|
|
61
|
+
fileId: number;
|
|
62
|
+
chats: number;
|
|
63
|
+
messages: number;
|
|
64
|
+
} | {
|
|
65
|
+
isCompleted: false;
|
|
66
|
+
isFailed: true;
|
|
67
|
+
error: string;
|
|
68
|
+
} | {
|
|
69
|
+
isCompleted: false;
|
|
70
|
+
isFailed: false;
|
|
71
|
+
progress: number;
|
|
72
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SocketEventType = void 0;
|
|
4
|
+
var SocketEventType;
|
|
5
|
+
(function (SocketEventType) {
|
|
6
|
+
SocketEventType["WppChatStarted"] = "wpp_chat_started";
|
|
7
|
+
SocketEventType["WppChatFinished"] = "wpp_chat_finished";
|
|
8
|
+
SocketEventType["WppMessage"] = "wpp_message";
|
|
9
|
+
SocketEventType["WppMessageStatus"] = "wpp_message_status";
|
|
10
|
+
SocketEventType["WppMessageReaction"] = "wpp_message_reaction";
|
|
11
|
+
SocketEventType["WwebjsQr"] = "wwebjs_qr";
|
|
12
|
+
SocketEventType["WwebjsAuth"] = "wwebjs_auth";
|
|
13
|
+
SocketEventType["ReportStatus"] = "report_status";
|
|
14
|
+
})(SocketEventType || (exports.SocketEventType = SocketEventType = {}));
|
|
15
|
+
;
|
|
16
|
+
;
|
|
17
|
+
;
|
|
18
|
+
;
|
|
19
|
+
;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
type ReportType = "chats";
|
|
2
|
+
type PhoneNumber = string;
|
|
3
|
+
export type SocketClientChatRoom = `chat:${PhoneNumber}`;
|
|
4
|
+
export type SocketClientAdminRoom = "admin";
|
|
5
|
+
export type SocketClientMonitorRoom = `monitor`;
|
|
6
|
+
export type SocketClientReportsRoom = `reports:${ReportType}`;
|
|
7
|
+
export type SocketClientRoom = SocketClientChatRoom | SocketClientAdminRoom | SocketClientReportsRoom | SocketClientMonitorRoom;
|
|
8
|
+
type SocketRoomWithInstance<T extends string> = `${string}:${T}`;
|
|
9
|
+
type SocketRoomWithSector<T extends string> = SocketRoomWithInstance<`${number}:${T}`>;
|
|
10
|
+
export type SocketServerAdminRoom = SocketRoomWithSector<SocketClientAdminRoom>;
|
|
11
|
+
export type SocketServerMonitorRoom = SocketRoomWithSector<SocketClientMonitorRoom>;
|
|
12
|
+
export type SocketServerReportsRoom = SocketRoomWithSector<SocketClientReportsRoom>;
|
|
13
|
+
export type SocketServerChatRoom = SocketRoomWithInstance<SocketClientChatRoom>;
|
|
14
|
+
export type SocketServerRoom = SocketServerChatRoom | SocketServerAdminRoom | SocketServerMonitorRoom | SocketServerReportsRoom;
|
|
15
|
+
export {};
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { AxiosInstance } from "axios";
|
|
2
|
-
import { DataResponse, PaginatedResponse } from "./response";
|
|
3
1
|
/**
|
|
4
2
|
* Enum que representa os diferentes papéis de usuário dentro do sistema.
|
|
5
3
|
*
|
|
@@ -148,42 +146,3 @@ export interface CreateUserDTO {
|
|
|
148
146
|
* Interface que representa o objeto de transferência de dados para atualizar um usuário.
|
|
149
147
|
*/
|
|
150
148
|
export type UpdateUserDTO = Partial<CreateUserDTO>;
|
|
151
|
-
/**
|
|
152
|
-
* SDK para operações de usuários.
|
|
153
|
-
*/
|
|
154
|
-
declare class UserSDK {
|
|
155
|
-
private readonly httpClient;
|
|
156
|
-
/**
|
|
157
|
-
* Cria uma instância do SDK de usuários.
|
|
158
|
-
* @param httpClient - A instância do cliente HTTP a ser usada para fazer requisições à API.
|
|
159
|
-
*/
|
|
160
|
-
constructor(httpClient: AxiosInstance);
|
|
161
|
-
/**
|
|
162
|
-
* Obtém a lista de usuários.
|
|
163
|
-
* @returns Uma resposta paginada contendo os usuários.
|
|
164
|
-
*/
|
|
165
|
-
getUsers(): Promise<PaginatedResponse<User>>;
|
|
166
|
-
/**
|
|
167
|
-
* Obtém um usuário pelo ID.
|
|
168
|
-
* @param userId - O ID do usuário.
|
|
169
|
-
* @returns Uma resposta contendo os dados do usuário.
|
|
170
|
-
*/
|
|
171
|
-
getUserById(userId: number): Promise<DataResponse<User>>;
|
|
172
|
-
/**
|
|
173
|
-
* Cria um novo usuário.
|
|
174
|
-
* @param data - Os dados para criação do usuário.
|
|
175
|
-
* @returns Uma resposta contendo os dados do usuário criado.
|
|
176
|
-
* @throws Um erro se a criação do usuário falhar.
|
|
177
|
-
*/
|
|
178
|
-
createUser(data: CreateUserDTO): Promise<DataResponse<User>>;
|
|
179
|
-
/**
|
|
180
|
-
* Atualiza um usuário existente.
|
|
181
|
-
* @param userId - O ID do usuário.
|
|
182
|
-
* @param data - Os dados para atualização do usuário.
|
|
183
|
-
* @returns Uma resposta contendo os dados do usuário atualizado.
|
|
184
|
-
* @throws Um erro se a atualização do usuário falhar.
|
|
185
|
-
*/
|
|
186
|
-
updateUser(userId: string, data: UpdateUserDTO): Promise<DataResponse<User>>;
|
|
187
|
-
setAuth(token: string): void;
|
|
188
|
-
}
|
|
189
|
-
export default UserSDK;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UserRole = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Enum que representa os diferentes papéis de usuário dentro do sistema.
|
|
6
|
+
*
|
|
7
|
+
* @enum {string}
|
|
8
|
+
* @property {string} ADMIN - Representa um papel de administrador.
|
|
9
|
+
* @property {string} ACTIVE - Representa um papel de usuário ativo.
|
|
10
|
+
* @property {string} RECEPTIONIST - Representa um papel de recepcionista.
|
|
11
|
+
* @property {string} BOTH - Representa um papel que combina tanto recepcionista quanto usuário ativo.
|
|
12
|
+
*/
|
|
13
|
+
var UserRole;
|
|
14
|
+
(function (UserRole) {
|
|
15
|
+
UserRole["ADMIN"] = "ADMIN";
|
|
16
|
+
UserRole["ACTIVE"] = "ATIVO";
|
|
17
|
+
UserRole["RECEPTIONIST"] = "RECEP";
|
|
18
|
+
UserRole["BOTH"] = "AMBOS";
|
|
19
|
+
})(UserRole || (exports.UserRole = UserRole = {}));
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { DataResponse, PaginatedResponse } from "./types/response.types";
|
|
2
|
+
import { CreateUserDTO, UpdateUserDTO, User } from "./types/user.types";
|
|
3
|
+
import ApiClient from "./api-client";
|
|
4
|
+
/**
|
|
5
|
+
* SDK para operações de usuários.
|
|
6
|
+
*/
|
|
7
|
+
export default class UsersClient extends ApiClient {
|
|
8
|
+
/**
|
|
9
|
+
* Obtém a lista de usuários.
|
|
10
|
+
* @returns Uma resposta paginada contendo os usuários.
|
|
11
|
+
*/
|
|
12
|
+
getUsers(): Promise<PaginatedResponse<User>>;
|
|
13
|
+
/**
|
|
14
|
+
* Obtém um usuário pelo ID.
|
|
15
|
+
* @param userId - O ID do usuário.
|
|
16
|
+
* @returns Uma resposta contendo os dados do usuário.
|
|
17
|
+
*/
|
|
18
|
+
getUserById(userId: number): Promise<DataResponse<User>>;
|
|
19
|
+
/**
|
|
20
|
+
* Cria um novo usuário.
|
|
21
|
+
* @param data - Os dados para criação do usuário.
|
|
22
|
+
* @returns Uma resposta contendo os dados do usuário criado.
|
|
23
|
+
* @throws Um erro se a criação do usuário falhar.
|
|
24
|
+
*/
|
|
25
|
+
createUser(data: CreateUserDTO): Promise<DataResponse<User>>;
|
|
26
|
+
/**
|
|
27
|
+
* Atualiza um usuário existente.
|
|
28
|
+
* @param userId - O ID do usuário.
|
|
29
|
+
* @param data - Os dados para atualização do usuário.
|
|
30
|
+
* @returns Uma resposta contendo os dados do usuário atualizado.
|
|
31
|
+
* @throws Um erro se a atualização do usuário falhar.
|
|
32
|
+
*/
|
|
33
|
+
updateUser(userId: string, data: UpdateUserDTO): Promise<DataResponse<User>>;
|
|
34
|
+
/**
|
|
35
|
+
* Sets the authorization token for HTTP requests.
|
|
36
|
+
*
|
|
37
|
+
* @param token - The authentication token to be used in the `Authorization` header.
|
|
38
|
+
*/
|
|
39
|
+
setAuth(token: string): void;
|
|
40
|
+
}
|
|
@@ -1,34 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Enum que representa os diferentes papéis de usuário dentro do sistema.
|
|
6
|
-
*
|
|
7
|
-
* @enum {string}
|
|
8
|
-
* @property {string} ADMIN - Representa um papel de administrador.
|
|
9
|
-
* @property {string} ACTIVE - Representa um papel de usuário ativo.
|
|
10
|
-
* @property {string} RECEPTIONIST - Representa um papel de recepcionista.
|
|
11
|
-
* @property {string} BOTH - Representa um papel que combina tanto recepcionista quanto usuário ativo.
|
|
12
|
-
*/
|
|
13
|
-
var UserRole;
|
|
14
|
-
(function (UserRole) {
|
|
15
|
-
UserRole["ADMIN"] = "ADMIN";
|
|
16
|
-
UserRole["ACTIVE"] = "ATIVO";
|
|
17
|
-
UserRole["RECEPTIONIST"] = "RECEP";
|
|
18
|
-
UserRole["BOTH"] = "AMBOS";
|
|
19
|
-
})(UserRole || (exports.UserRole = UserRole = {}));
|
|
6
|
+
const api_client_1 = __importDefault(require("./api-client"));
|
|
20
7
|
/**
|
|
21
8
|
* SDK para operações de usuários.
|
|
22
9
|
*/
|
|
23
|
-
class
|
|
24
|
-
httpClient;
|
|
25
|
-
/**
|
|
26
|
-
* Cria uma instância do SDK de usuários.
|
|
27
|
-
* @param httpClient - A instância do cliente HTTP a ser usada para fazer requisições à API.
|
|
28
|
-
*/
|
|
29
|
-
constructor(httpClient) {
|
|
30
|
-
this.httpClient = httpClient;
|
|
31
|
-
}
|
|
10
|
+
class UsersClient extends api_client_1.default {
|
|
32
11
|
/**
|
|
33
12
|
* Obtém a lista de usuários.
|
|
34
13
|
* @returns Uma resposta paginada contendo os usuários.
|
|
@@ -77,8 +56,13 @@ class UserSDK {
|
|
|
77
56
|
throw new Error("Failed to update user", { cause: error });
|
|
78
57
|
}
|
|
79
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* Sets the authorization token for HTTP requests.
|
|
61
|
+
*
|
|
62
|
+
* @param token - The authentication token to be used in the `Authorization` header.
|
|
63
|
+
*/
|
|
80
64
|
setAuth(token) {
|
|
81
65
|
this.httpClient.defaults.headers.common["Authorization"] = `Bearer ${token}`;
|
|
82
66
|
}
|
|
83
67
|
}
|
|
84
|
-
exports.default =
|
|
68
|
+
exports.default = UsersClient;
|
package/package.json
CHANGED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import axios, { AxiosInstance, AxiosError } from 'axios';
|
|
2
|
+
import { ErrorResponse } from './types/response.types';
|
|
3
|
+
|
|
4
|
+
export default class ApiClient {
|
|
5
|
+
protected readonly httpClient: AxiosInstance;
|
|
6
|
+
private baseUrl: string;
|
|
7
|
+
|
|
8
|
+
constructor(baseUrl: string) {
|
|
9
|
+
this.baseUrl = baseUrl;
|
|
10
|
+
|
|
11
|
+
this.httpClient = axios.create({
|
|
12
|
+
baseURL: `${this.baseUrl}`,
|
|
13
|
+
timeout: 10000,
|
|
14
|
+
headers: {
|
|
15
|
+
'Content-Type': 'application/json',
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
this.initializeResponseInterceptor();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
private initializeResponseInterceptor() {
|
|
23
|
+
this.httpClient.interceptors.response.use(
|
|
24
|
+
null,
|
|
25
|
+
this.handleError
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
protected handleError = (error: AxiosError<ErrorResponse>): Promise<never> => {
|
|
30
|
+
const errorMessage = error.response?.data?.message || error.message;
|
|
31
|
+
return Promise.reject(new Error(errorMessage));
|
|
32
|
+
};
|
|
33
|
+
}
|
|
@@ -1,51 +1,12 @@
|
|
|
1
|
-
import { AxiosInstance } from "axios";
|
|
2
|
-
import { User } from "./user";
|
|
3
1
|
import { sanitizeErrorMessage } from "@in.pulse-crm/utils";
|
|
4
|
-
import { DataResponse } from "./response";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Token de autenticação.
|
|
9
|
-
*/
|
|
10
|
-
token: string;
|
|
11
|
-
/**
|
|
12
|
-
* Dados do usuário.
|
|
13
|
-
*/
|
|
14
|
-
user: User;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export interface SessionData {
|
|
18
|
-
/**
|
|
19
|
-
* ID do usuário.
|
|
20
|
-
*/
|
|
21
|
-
userId: number;
|
|
22
|
-
/**
|
|
23
|
-
* ID do setor do usuário.
|
|
24
|
-
*/
|
|
25
|
-
sectorId: number
|
|
26
|
-
/**
|
|
27
|
-
* Papel do usuário.
|
|
28
|
-
*/
|
|
29
|
-
role: string;
|
|
30
|
-
/**
|
|
31
|
-
* Nome da instância.
|
|
32
|
-
*/
|
|
33
|
-
instance: string;
|
|
34
|
-
}
|
|
2
|
+
import { DataResponse } from "./types/response.types";
|
|
3
|
+
import ApiClient from "./api-client";
|
|
4
|
+
import { LoginData, SessionData } from "./types/auth.types";
|
|
35
5
|
|
|
36
6
|
/**
|
|
37
7
|
* Classe AuthSDK para interagir com a API de autenticação.
|
|
38
8
|
*/
|
|
39
|
-
export default class
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Cria uma instância do SDK de autenticação.
|
|
43
|
-
* @param {AxiosInstance} httpClient A instância do cliente HTTP a ser usada para fazer requisições à API.
|
|
44
|
-
*/
|
|
45
|
-
constructor(private readonly httpClient: AxiosInstance) {
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
|
|
9
|
+
export default class AuthClient extends ApiClient {
|
|
49
10
|
/**
|
|
50
11
|
* Realiza o login do usuário.
|
|
51
12
|
* @param {string} instance Nome da instância do Inpulse.
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import ApiClient from "./api-client";
|
|
2
|
+
import { CreateCustomerDTO, UpdateCustomerDTO } from "./types/customers.types";
|
|
3
|
+
|
|
4
|
+
class CustomersClient extends ApiClient {
|
|
5
|
+
/**
|
|
6
|
+
* Cria um novo cliente.
|
|
7
|
+
* @param data - Os dados do cliente a serem criados.
|
|
8
|
+
* @returns Uma Promise que resolve para o cliente criado.
|
|
9
|
+
*/
|
|
10
|
+
public async createCustomer(data: CreateCustomerDTO) {
|
|
11
|
+
const response = await this.httpClient.post(`/customers`, data);
|
|
12
|
+
|
|
13
|
+
return response.data;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Obtém um cliente pelo ID.
|
|
18
|
+
* @param customerId - O ID do cliente a ser obtido.
|
|
19
|
+
* @returns Uma Promise que resolve para o cliente obtido.
|
|
20
|
+
*/
|
|
21
|
+
public async getCustomerById(customerId: number) {
|
|
22
|
+
const response = await this.httpClient.get(`/customers/${customerId}`);
|
|
23
|
+
return response.data;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Atualiza um cliente existente.
|
|
28
|
+
* @param customerId - O ID do cliente a ser atualizado.
|
|
29
|
+
* @param data - Os dados atualizados do cliente.
|
|
30
|
+
* @returns Uma Promise que resolve para o cliente atualizado.
|
|
31
|
+
*/
|
|
32
|
+
public async updateCustomer(customerId: number, data: UpdateCustomerDTO) {
|
|
33
|
+
const response = await this.httpClient.patch(`/customers/${customerId}`, data);
|
|
34
|
+
return response.data;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Obtém todos os clientes.
|
|
39
|
+
*
|
|
40
|
+
* @param filters - Filtros opcionais para a busca de clientes.
|
|
41
|
+
* @todo Implementar tipagem para os filtros.
|
|
42
|
+
* @returns Uma Promise que resolve para uma lista de clientes.
|
|
43
|
+
*/
|
|
44
|
+
public async getAllCustomers(filters: Record<string, string>) {
|
|
45
|
+
let baseUrl = `/customers`;
|
|
46
|
+
const params = new URLSearchParams(filters);
|
|
47
|
+
|
|
48
|
+
if (params.toString()) {
|
|
49
|
+
baseUrl += `?${params.toString()}`;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const response = await this.httpClient.get(`/customers`);
|
|
53
|
+
|
|
54
|
+
return response.data;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Define o token de autenticação para as requisições.
|
|
59
|
+
* @param token - O token de autenticação a ser definido.
|
|
60
|
+
*/
|
|
61
|
+
public setAuth(token: string) {
|
|
62
|
+
this.httpClient.defaults.headers.common["Authorization"] = `Bearer ${token}`;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export default CustomersClient;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import ApiClient from "./api-client";
|
|
2
|
+
import { UploadFileOptions } from "./types/files.types";
|
|
3
|
+
import { DataResponse } from "./types/response.types";
|
|
4
|
+
|
|
5
|
+
class FilesClient extends ApiClient {
|
|
6
|
+
/**
|
|
7
|
+
* Busca um arquivo pelo ID.
|
|
8
|
+
* @param {number} id - ID do arquivo.
|
|
9
|
+
* @returns {Promise<Buffer>} Um buffer contendo os dados do arquivo.
|
|
10
|
+
*/
|
|
11
|
+
public async fetchFile(id: number): Promise<Buffer> {
|
|
12
|
+
const response = await this.httpClient.get(`/files/${id}`, {
|
|
13
|
+
responseType: "arraybuffer"
|
|
14
|
+
});
|
|
15
|
+
const buffer = Buffer.from(response.data, "binary");
|
|
16
|
+
|
|
17
|
+
return buffer;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Obtém a URL de download de um arquivo.
|
|
22
|
+
* @param {number} id - ID do arquivo.
|
|
23
|
+
* @returns {string} URL de download do arquivo.
|
|
24
|
+
*/
|
|
25
|
+
public getFileDownloadUrl(id: number): string {
|
|
26
|
+
return this.httpClient.defaults.baseURL + `/files/${id}`;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Faz o upload de um arquivo.
|
|
31
|
+
* @param {UploadFileOptions} props - Opções para o upload do arquivo.
|
|
32
|
+
* @returns {Promise<File>} Os dados do arquivo enviado.
|
|
33
|
+
*/
|
|
34
|
+
public async uploadFile(props: UploadFileOptions): Promise<File> {
|
|
35
|
+
const form = new FormData();
|
|
36
|
+
form.append("instance", props.instance);
|
|
37
|
+
form.append("dirType", props.dirType);
|
|
38
|
+
form.append("file", new Blob([props.buffer]), props.fileName);
|
|
39
|
+
|
|
40
|
+
const response = await this.httpClient.post<DataResponse<File>>("/files", form, {
|
|
41
|
+
headers: { "Content-Type": "multipart/form-data" }
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
return response.data.data;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Deleta um arquivo pelo ID.
|
|
49
|
+
* @param {number} id - ID do arquivo.
|
|
50
|
+
* @returns {Promise<void>}
|
|
51
|
+
*/
|
|
52
|
+
public async deleteFile(id: number): Promise<void> {
|
|
53
|
+
await this.httpClient.delete(`/files/${id}`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export default FilesClient;
|