@tec.pet/tecpet-sdk 0.0.219 → 0.0.221
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.
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export interface PaReverseInvoiceReceivablePaymentRequest {
|
|
2
2
|
currentAmount: number;
|
|
3
3
|
source?: string;
|
|
4
|
+
/** Loja da fatura: o server só procura a transação nessa loja (externalId não é único entre lojas). */
|
|
5
|
+
shopId?: number;
|
|
4
6
|
}
|
|
5
7
|
export interface PaReverseInvoiceReceivablePaymentResponse {
|
|
6
8
|
success: boolean;
|
|
@@ -10,4 +10,11 @@ export declare class HttpClient {
|
|
|
10
10
|
delete<T>(path: string, shopId?: number): Promise<T>;
|
|
11
11
|
private headers;
|
|
12
12
|
private shop;
|
|
13
|
+
/**
|
|
14
|
+
* Repassa o corpo cru do erro da API. Sem resposta (timeout, falha de rede) ou com
|
|
15
|
+
* corpo vazio, lança um Error com a mensagem do axios: ler `error.response.data`
|
|
16
|
+
* direto virava `TypeError` e perdia a causa. O `AxiosError` não é relançado porque
|
|
17
|
+
* o `toJSON()` dele serializa o `config`, com o header `Authorization`.
|
|
18
|
+
*/
|
|
19
|
+
private failure;
|
|
13
20
|
}
|
|
@@ -29,9 +29,9 @@ class HttpClient {
|
|
|
29
29
|
stdout_logger_1.logger.debug('tecpet-sdk', `[HTTP] ${this.shop(response.config.headers)} ← ${response.status} ${response.config.url}`, response?.data);
|
|
30
30
|
return response;
|
|
31
31
|
}, (error) => {
|
|
32
|
-
stdout_logger_1.logger.error('tecpet-sdk', `[HTTP] ${this.shop(error)} ← Error: ${error.message}`);
|
|
32
|
+
stdout_logger_1.logger.error('tecpet-sdk', `[HTTP] ${this.shop(error?.config?.headers)} ← Error: ${error.message}`);
|
|
33
33
|
if (error.response) {
|
|
34
|
-
stdout_logger_1.logger.error('tecpet-sdk', `[HTTP] ${this.shop(error)} ← Response:`, error?.response?.data);
|
|
34
|
+
stdout_logger_1.logger.error('tecpet-sdk', `[HTTP] ${this.shop(error?.config?.headers)} ← Response:`, error?.response?.data);
|
|
35
35
|
}
|
|
36
36
|
return Promise.reject(error);
|
|
37
37
|
});
|
|
@@ -42,7 +42,7 @@ class HttpClient {
|
|
|
42
42
|
return response?.data;
|
|
43
43
|
}
|
|
44
44
|
catch (error) {
|
|
45
|
-
throw error
|
|
45
|
+
throw this.failure(error);
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
async post(path, payload, shopId) {
|
|
@@ -51,7 +51,7 @@ class HttpClient {
|
|
|
51
51
|
return response?.data;
|
|
52
52
|
}
|
|
53
53
|
catch (error) {
|
|
54
|
-
throw error
|
|
54
|
+
throw this.failure(error);
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
async put(path, payload, shopId) {
|
|
@@ -60,7 +60,7 @@ class HttpClient {
|
|
|
60
60
|
return response?.data;
|
|
61
61
|
}
|
|
62
62
|
catch (error) {
|
|
63
|
-
throw error
|
|
63
|
+
throw this.failure(error);
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
async patch(path, payload, shopId) {
|
|
@@ -69,7 +69,7 @@ class HttpClient {
|
|
|
69
69
|
return response?.data;
|
|
70
70
|
}
|
|
71
71
|
catch (error) {
|
|
72
|
-
throw error
|
|
72
|
+
throw this.failure(error);
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
async delete(path, shopId) {
|
|
@@ -78,7 +78,7 @@ class HttpClient {
|
|
|
78
78
|
return response?.data;
|
|
79
79
|
}
|
|
80
80
|
catch (error) {
|
|
81
|
-
throw error
|
|
81
|
+
throw this.failure(error);
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
headers({ shopId }) {
|
|
@@ -94,5 +94,14 @@ class HttpClient {
|
|
|
94
94
|
const shop = headers?.['x-shop']?.toString();
|
|
95
95
|
return shop ? `shop=${shop}` : '';
|
|
96
96
|
}
|
|
97
|
+
/**
|
|
98
|
+
* Repassa o corpo cru do erro da API. Sem resposta (timeout, falha de rede) ou com
|
|
99
|
+
* corpo vazio, lança um Error com a mensagem do axios: ler `error.response.data`
|
|
100
|
+
* direto virava `TypeError` e perdia a causa. O `AxiosError` não é relançado porque
|
|
101
|
+
* o `toJSON()` dele serializa o `config`, com o header `Authorization`.
|
|
102
|
+
*/
|
|
103
|
+
failure(error) {
|
|
104
|
+
return error?.response?.data || new Error(error?.message);
|
|
105
|
+
}
|
|
97
106
|
}
|
|
98
107
|
exports.HttpClient = HttpClient;
|