@pokash/n8n-nodes-optima-rest-api 1.1.0 → 1.1.2
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.
Potentially problematic release.
This version of @pokash/n8n-nodes-optima-rest-api might be problematic. Click here for more details.
|
@@ -34,6 +34,10 @@ class OptimaRestApi {
|
|
|
34
34
|
name: 'Customer',
|
|
35
35
|
value: 'customer',
|
|
36
36
|
},
|
|
37
|
+
{
|
|
38
|
+
name: 'Dictionary',
|
|
39
|
+
value: 'dictionary',
|
|
40
|
+
},
|
|
37
41
|
{
|
|
38
42
|
name: 'Document',
|
|
39
43
|
value: 'document',
|
|
@@ -169,6 +173,51 @@ class OptimaRestApi {
|
|
|
169
173
|
default: '{\n "akronim": "KLIENT01",\n "nazwa": "Firma Example",\n "nip": "1234567890"\n}',
|
|
170
174
|
description: 'Customer data in JSON format',
|
|
171
175
|
},
|
|
176
|
+
// Dictionary Operations
|
|
177
|
+
{
|
|
178
|
+
displayName: 'Dictionary Type',
|
|
179
|
+
name: 'operation',
|
|
180
|
+
type: 'options',
|
|
181
|
+
noDataExpression: true,
|
|
182
|
+
displayOptions: {
|
|
183
|
+
show: {
|
|
184
|
+
resource: ['dictionary'],
|
|
185
|
+
},
|
|
186
|
+
},
|
|
187
|
+
options: [
|
|
188
|
+
{
|
|
189
|
+
name: 'Payment Methods',
|
|
190
|
+
value: 'paymentMethods',
|
|
191
|
+
description: 'Get payment methods dictionary',
|
|
192
|
+
action: 'Get payment methods',
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
name: 'Warehouses',
|
|
196
|
+
value: 'warehouses',
|
|
197
|
+
description: 'Get warehouses dictionary',
|
|
198
|
+
action: 'Get warehouses',
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
name: 'Currencies',
|
|
202
|
+
value: 'currencies',
|
|
203
|
+
description: 'Get currencies dictionary',
|
|
204
|
+
action: 'Get currencies',
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
name: 'Document Definitions',
|
|
208
|
+
value: 'documentDefinitions',
|
|
209
|
+
description: 'Get document definitions dictionary',
|
|
210
|
+
action: 'Get document definitions',
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
name: 'Accounting Categories',
|
|
214
|
+
value: 'accountingCategories',
|
|
215
|
+
description: 'Get accounting categories dictionary',
|
|
216
|
+
action: 'Get accounting categories',
|
|
217
|
+
},
|
|
218
|
+
],
|
|
219
|
+
default: 'paymentMethods',
|
|
220
|
+
},
|
|
172
221
|
// Document Operations
|
|
173
222
|
{
|
|
174
223
|
displayName: 'Operation',
|
|
@@ -351,19 +400,19 @@ class OptimaRestApi {
|
|
|
351
400
|
if (resource === 'customer') {
|
|
352
401
|
if (operation === 'get' || operation === 'getAll') {
|
|
353
402
|
const options = this.getNodeParameter('options', i, {});
|
|
354
|
-
// Build query parameters
|
|
403
|
+
// Build query parameters (use PascalCase to match C# API)
|
|
355
404
|
const queryParams = new URLSearchParams();
|
|
356
405
|
if (options.id) {
|
|
357
|
-
queryParams.append('
|
|
406
|
+
queryParams.append('Id', String(options.id));
|
|
358
407
|
}
|
|
359
408
|
if (options.filter) {
|
|
360
|
-
queryParams.append('
|
|
409
|
+
queryParams.append('Filter', String(options.filter));
|
|
361
410
|
}
|
|
362
411
|
if (options.skip) {
|
|
363
|
-
queryParams.append('
|
|
412
|
+
queryParams.append('Skip', String(options.skip));
|
|
364
413
|
}
|
|
365
414
|
if (options.take) {
|
|
366
|
-
queryParams.append('
|
|
415
|
+
queryParams.append('Take', String(options.take));
|
|
367
416
|
}
|
|
368
417
|
const queryString = queryParams.toString();
|
|
369
418
|
const url = queryString
|
|
@@ -377,13 +426,20 @@ class OptimaRestApi {
|
|
|
377
426
|
},
|
|
378
427
|
json: true,
|
|
379
428
|
});
|
|
380
|
-
//
|
|
381
|
-
|
|
382
|
-
|
|
429
|
+
// API returns { Success: true, Customers: [...], TotalCount: ... }
|
|
430
|
+
const responseData = response;
|
|
431
|
+
// Extract customers array from response
|
|
432
|
+
if (responseData.Customers && Array.isArray(responseData.Customers)) {
|
|
433
|
+
const items = responseData.Customers.map(item => ({ json: item }));
|
|
383
434
|
returnData.push(...items);
|
|
384
435
|
}
|
|
436
|
+
else if (responseData.Customers) {
|
|
437
|
+
// Single customer
|
|
438
|
+
returnData.push({ json: responseData.Customers });
|
|
439
|
+
}
|
|
385
440
|
else {
|
|
386
|
-
|
|
441
|
+
// Fallback - return entire response if structure is unexpected
|
|
442
|
+
returnData.push({ json: responseData });
|
|
387
443
|
}
|
|
388
444
|
}
|
|
389
445
|
else if (operation === 'create') {
|
|
@@ -444,6 +500,38 @@ class OptimaRestApi {
|
|
|
444
500
|
returnData.push({ json: response });
|
|
445
501
|
}
|
|
446
502
|
}
|
|
503
|
+
else if (resource === 'dictionary') {
|
|
504
|
+
// Dictionary operations - map operation names to API endpoints
|
|
505
|
+
const dictionaryEndpoints = {
|
|
506
|
+
paymentMethods: { endpoint: 'Dictionary/PaymentMethods', dataKey: 'PaymentMethods' },
|
|
507
|
+
warehouses: { endpoint: 'Dictionary/Warehouses', dataKey: 'Warehouses' },
|
|
508
|
+
currencies: { endpoint: 'Dictionary/Currencies', dataKey: 'Currencies' },
|
|
509
|
+
documentDefinitions: { endpoint: 'Dictionary/DocumentDefinitions', dataKey: 'DocumentDefinitions' },
|
|
510
|
+
accountingCategories: { endpoint: 'Dictionary/AccountingCategories', dataKey: 'AccountingCategories' },
|
|
511
|
+
};
|
|
512
|
+
const dictConfig = dictionaryEndpoints[operation];
|
|
513
|
+
if (dictConfig) {
|
|
514
|
+
const response = await this.helpers.request({
|
|
515
|
+
method: 'GET',
|
|
516
|
+
url: `${gatewayUrl}/api/${dictConfig.endpoint}`,
|
|
517
|
+
headers: {
|
|
518
|
+
Authorization: `Bearer ${token}`,
|
|
519
|
+
},
|
|
520
|
+
json: true,
|
|
521
|
+
});
|
|
522
|
+
// API returns { Success: true, [DataKey]: [...], TotalCount: ... }
|
|
523
|
+
const responseData = response;
|
|
524
|
+
// Extract dictionary array from response
|
|
525
|
+
if (responseData[dictConfig.dataKey] && Array.isArray(responseData[dictConfig.dataKey])) {
|
|
526
|
+
const items = responseData[dictConfig.dataKey].map(item => ({ json: item }));
|
|
527
|
+
returnData.push(...items);
|
|
528
|
+
}
|
|
529
|
+
else {
|
|
530
|
+
// Fallback - return entire response if structure is unexpected
|
|
531
|
+
returnData.push({ json: responseData });
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
}
|
|
447
535
|
else if (resource === 'product') {
|
|
448
536
|
if (operation === 'get') {
|
|
449
537
|
const productId = this.getNodeParameter('productId', i);
|