@pokash/n8n-nodes-optima-rest-api 1.12.1 → 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 = {
|
|
@@ -710,6 +717,13 @@ class OptimaRestApi {
|
|
|
710
717
|
default: '',
|
|
711
718
|
description: 'Part of the product name (case-insensitive)',
|
|
712
719
|
},
|
|
720
|
+
{
|
|
721
|
+
displayName: 'Name Equals',
|
|
722
|
+
name: 'nazwaRowna',
|
|
723
|
+
type: 'string',
|
|
724
|
+
default: '',
|
|
725
|
+
description: 'Whole product name (exact match, case-insensitive) — e.g. matching an invoice line to a product',
|
|
726
|
+
},
|
|
713
727
|
{
|
|
714
728
|
displayName: 'Type',
|
|
715
729
|
name: 'typ',
|
|
@@ -984,8 +998,9 @@ class OptimaRestApi {
|
|
|
984
998
|
queryParams.append('Filter', String(options.filter));
|
|
985
999
|
}
|
|
986
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ą.
|
|
987
1002
|
for (const pole of ['kod', 'nip', 'nazwa', 'email', 'grupa', 'aktywny', 'zmienionyOd']) {
|
|
988
|
-
if (options[pole] !== undefined && options[pole] !== '') {
|
|
1003
|
+
if (options[pole] !== undefined && (options[pole] !== '' || ['kod', 'nip', 'email', 'grupa'].includes(pole))) {
|
|
989
1004
|
queryParams.append(pole, String(options[pole]));
|
|
990
1005
|
}
|
|
991
1006
|
}
|
|
@@ -999,16 +1014,11 @@ class OptimaRestApi {
|
|
|
999
1014
|
const url = queryString
|
|
1000
1015
|
? `${gatewayUrl}/api/customer?${queryString}`
|
|
1001
1016
|
: `${gatewayUrl}/api/customer`;
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
: await makeAuthenticatedRequest({
|
|
1008
|
-
method: 'GET',
|
|
1009
|
-
url,
|
|
1010
|
-
json: true,
|
|
1011
|
-
});
|
|
1017
|
+
const response = await makeAuthenticatedRequest({
|
|
1018
|
+
method: 'GET',
|
|
1019
|
+
url,
|
|
1020
|
+
json: true,
|
|
1021
|
+
});
|
|
1012
1022
|
// API returns { Success: true, Customers: [...], TotalCount: ... }
|
|
1013
1023
|
const responseData = response;
|
|
1014
1024
|
// Extract customers array from response
|
|
@@ -1314,8 +1324,9 @@ class OptimaRestApi {
|
|
|
1314
1324
|
queryParams.append('Filter', String(options.filter));
|
|
1315
1325
|
}
|
|
1316
1326
|
// TNXP-791: jawne filtry
|
|
1317
|
-
|
|
1318
|
-
|
|
1327
|
+
// Filtr dokładny idzie także pusty: Gateway odpowiada wtedy 404, nie całą listą.
|
|
1328
|
+
for (const pole of ['kod', 'ean', 'nazwa', 'nazwaRowna', 'typ', 'grupa', 'aktywny', 'zmienionyOd']) {
|
|
1329
|
+
if (options[pole] !== undefined && (options[pole] !== '' || ['kod', 'ean', 'nazwaRowna', 'grupa'].includes(pole))) {
|
|
1319
1330
|
queryParams.append(pole, String(options[pole]));
|
|
1320
1331
|
}
|
|
1321
1332
|
}
|
|
@@ -1329,16 +1340,11 @@ class OptimaRestApi {
|
|
|
1329
1340
|
const url = queryString
|
|
1330
1341
|
? `${gatewayUrl}/api/product?${queryString}`
|
|
1331
1342
|
: `${gatewayUrl}/api/product`;
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
: await makeAuthenticatedRequest({
|
|
1338
|
-
method: 'GET',
|
|
1339
|
-
url,
|
|
1340
|
-
json: true,
|
|
1341
|
-
});
|
|
1343
|
+
const response = await makeAuthenticatedRequest({
|
|
1344
|
+
method: 'GET',
|
|
1345
|
+
url,
|
|
1346
|
+
json: true,
|
|
1347
|
+
});
|
|
1342
1348
|
// API returns { Success: true, Products: [...], TotalCount: ... }
|
|
1343
1349
|
const responseData = response;
|
|
1344
1350
|
// Extract products array from response
|
|
@@ -1454,9 +1460,10 @@ class OptimaRestApi {
|
|
|
1454
1460
|
}
|
|
1455
1461
|
catch (error) {
|
|
1456
1462
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1463
|
+
const statusCode = kodHttp(error);
|
|
1457
1464
|
if (this.continueOnFail()) {
|
|
1458
1465
|
const result = {
|
|
1459
|
-
json: { error: errorMessage }
|
|
1466
|
+
json: statusCode ? { error: errorMessage, statusCode } : { error: errorMessage }
|
|
1460
1467
|
};
|
|
1461
1468
|
if (items[i].binary) {
|
|
1462
1469
|
result.binary = items[i].binary;
|