@pokash/n8n-nodes-optima-rest-api 1.13.0 → 1.14.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.
|
@@ -3,6 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.OptimaRestApi = void 0;
|
|
4
4
|
const n8n_workflow_1 = require("n8n-workflow");
|
|
5
5
|
const tokenCache = new Map();
|
|
6
|
+
// TNXP-791: kod HTTP błędu (400, 403, 404, 500…) — z odpowiedzi API albo z błędu węzła; brak = błąd bez odpowiedzi (sieć, konfiguracja).
|
|
7
|
+
function kodHttp(error) {
|
|
8
|
+
var _a, _b, _c;
|
|
9
|
+
const kod = (_c = (_a = error === null || error === void 0 ? void 0 : error.statusCode) !== null && _a !== void 0 ? _a : (_b = error === null || error === void 0 ? void 0 : error.response) === null || _b === void 0 ? void 0 : _b.statusCode) !== null && _c !== void 0 ? _c : error === null || error === void 0 ? void 0 : error.httpCode;
|
|
10
|
+
const liczba = Number(kod);
|
|
11
|
+
return Number.isInteger(liczba) && liczba > 0 ? liczba : undefined;
|
|
12
|
+
}
|
|
6
13
|
class OptimaRestApi {
|
|
7
14
|
constructor() {
|
|
8
15
|
this.description = {
|
|
@@ -991,8 +998,9 @@ class OptimaRestApi {
|
|
|
991
998
|
queryParams.append('Filter', String(options.filter));
|
|
992
999
|
}
|
|
993
1000
|
// TNXP-791: jawne filtry
|
|
1001
|
+
// Filtr dokładny idzie także pusty (np. pusty akronim z wyrażenia): Gateway odpowiada wtedy 404, nie całą listą.
|
|
994
1002
|
for (const pole of ['kod', 'nip', 'nazwa', 'email', 'grupa', 'aktywny', 'zmienionyOd']) {
|
|
995
|
-
if (options[pole] !== undefined && options[pole] !== '') {
|
|
1003
|
+
if (options[pole] !== undefined && (options[pole] !== '' || ['kod', 'nip', 'email', 'grupa'].includes(pole))) {
|
|
996
1004
|
queryParams.append(pole, String(options[pole]));
|
|
997
1005
|
}
|
|
998
1006
|
}
|
|
@@ -1006,16 +1014,11 @@ class OptimaRestApi {
|
|
|
1006
1014
|
const url = queryString
|
|
1007
1015
|
? `${gatewayUrl}/api/customer?${queryString}`
|
|
1008
1016
|
: `${gatewayUrl}/api/customer`;
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
: await makeAuthenticatedRequest({
|
|
1015
|
-
method: 'GET',
|
|
1016
|
-
url,
|
|
1017
|
-
json: true,
|
|
1018
|
-
});
|
|
1017
|
+
const response = await makeAuthenticatedRequest({
|
|
1018
|
+
method: 'GET',
|
|
1019
|
+
url,
|
|
1020
|
+
json: true,
|
|
1021
|
+
});
|
|
1019
1022
|
// API returns { Success: true, Customers: [...], TotalCount: ... }
|
|
1020
1023
|
const responseData = response;
|
|
1021
1024
|
// Extract customers array from response
|
|
@@ -1321,8 +1324,9 @@ class OptimaRestApi {
|
|
|
1321
1324
|
queryParams.append('Filter', String(options.filter));
|
|
1322
1325
|
}
|
|
1323
1326
|
// TNXP-791: jawne filtry
|
|
1327
|
+
// Filtr dokładny idzie także pusty: Gateway odpowiada wtedy 404, nie całą listą.
|
|
1324
1328
|
for (const pole of ['kod', 'ean', 'nazwa', 'nazwaRowna', 'typ', 'grupa', 'aktywny', 'zmienionyOd']) {
|
|
1325
|
-
if (options[pole] !== undefined && options[pole] !== '') {
|
|
1329
|
+
if (options[pole] !== undefined && (options[pole] !== '' || ['kod', 'ean', 'nazwaRowna', 'grupa'].includes(pole))) {
|
|
1326
1330
|
queryParams.append(pole, String(options[pole]));
|
|
1327
1331
|
}
|
|
1328
1332
|
}
|
|
@@ -1336,16 +1340,11 @@ class OptimaRestApi {
|
|
|
1336
1340
|
const url = queryString
|
|
1337
1341
|
? `${gatewayUrl}/api/product?${queryString}`
|
|
1338
1342
|
: `${gatewayUrl}/api/product`;
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
: await makeAuthenticatedRequest({
|
|
1345
|
-
method: 'GET',
|
|
1346
|
-
url,
|
|
1347
|
-
json: true,
|
|
1348
|
-
});
|
|
1343
|
+
const response = await makeAuthenticatedRequest({
|
|
1344
|
+
method: 'GET',
|
|
1345
|
+
url,
|
|
1346
|
+
json: true,
|
|
1347
|
+
});
|
|
1349
1348
|
// API returns { Success: true, Products: [...], TotalCount: ... }
|
|
1350
1349
|
const responseData = response;
|
|
1351
1350
|
// Extract products array from response
|
|
@@ -1461,9 +1460,10 @@ class OptimaRestApi {
|
|
|
1461
1460
|
}
|
|
1462
1461
|
catch (error) {
|
|
1463
1462
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1463
|
+
const statusCode = kodHttp(error);
|
|
1464
1464
|
if (this.continueOnFail()) {
|
|
1465
1465
|
const result = {
|
|
1466
|
-
json: { error: errorMessage }
|
|
1466
|
+
json: statusCode ? { error: errorMessage, statusCode } : { error: errorMessage }
|
|
1467
1467
|
};
|
|
1468
1468
|
if (items[i].binary) {
|
|
1469
1469
|
result.binary = items[i].binary;
|