@pokash/n8n-nodes-optima-rest-api 1.0.4 → 1.0.6
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.
|
@@ -246,25 +246,12 @@ class OptimaRestApi {
|
|
|
246
246
|
],
|
|
247
247
|
default: 'printDocument',
|
|
248
248
|
},
|
|
249
|
-
// Print Document ID
|
|
250
|
-
{
|
|
251
|
-
displayName: 'Document ID',
|
|
252
|
-
name: 'documentId',
|
|
253
|
-
type: 'number',
|
|
254
|
-
displayOptions: {
|
|
255
|
-
show: {
|
|
256
|
-
resource: ['print'],
|
|
257
|
-
operation: ['printDocument'],
|
|
258
|
-
},
|
|
259
|
-
},
|
|
260
|
-
default: 0,
|
|
261
|
-
description: 'ID of the document to print (optional if using SQL filter)',
|
|
262
|
-
},
|
|
263
249
|
// Print SQL Filter
|
|
264
250
|
{
|
|
265
251
|
displayName: 'SQL Filter',
|
|
266
252
|
name: 'filtrSQL',
|
|
267
253
|
type: 'string',
|
|
254
|
+
required: true,
|
|
268
255
|
displayOptions: {
|
|
269
256
|
show: {
|
|
270
257
|
resource: ['print'],
|
|
@@ -273,7 +260,7 @@ class OptimaRestApi {
|
|
|
273
260
|
},
|
|
274
261
|
default: '',
|
|
275
262
|
placeholder: 'TrN_TrnId = 123',
|
|
276
|
-
description: 'SQL filter to select documents
|
|
263
|
+
description: 'SQL filter to select documents',
|
|
277
264
|
},
|
|
278
265
|
// Print Format ID
|
|
279
266
|
{
|
|
@@ -327,7 +314,7 @@ class OptimaRestApi {
|
|
|
327
314
|
},
|
|
328
315
|
json: true,
|
|
329
316
|
});
|
|
330
|
-
returnData.push(response);
|
|
317
|
+
returnData.push({ json: response });
|
|
331
318
|
}
|
|
332
319
|
else if (operation === 'getAll') {
|
|
333
320
|
const response = await this.helpers.request({
|
|
@@ -338,7 +325,8 @@ class OptimaRestApi {
|
|
|
338
325
|
},
|
|
339
326
|
json: true,
|
|
340
327
|
});
|
|
341
|
-
|
|
328
|
+
const items = response.map(item => ({ json: item }));
|
|
329
|
+
returnData.push(...items);
|
|
342
330
|
}
|
|
343
331
|
else if (operation === 'create') {
|
|
344
332
|
const customerData = JSON.parse(this.getNodeParameter('customerData', i));
|
|
@@ -351,7 +339,7 @@ class OptimaRestApi {
|
|
|
351
339
|
body: customerData,
|
|
352
340
|
json: true,
|
|
353
341
|
});
|
|
354
|
-
returnData.push(response);
|
|
342
|
+
returnData.push({ json: response });
|
|
355
343
|
}
|
|
356
344
|
else if (operation === 'update') {
|
|
357
345
|
const customerId = this.getNodeParameter('customerId', i);
|
|
@@ -367,7 +355,7 @@ class OptimaRestApi {
|
|
|
367
355
|
body: customerData,
|
|
368
356
|
json: true,
|
|
369
357
|
});
|
|
370
|
-
returnData.push(response);
|
|
358
|
+
returnData.push({ json: response });
|
|
371
359
|
}
|
|
372
360
|
else if (operation === 'delete') {
|
|
373
361
|
const customerId = this.getNodeParameter('customerId', i);
|
|
@@ -379,7 +367,7 @@ class OptimaRestApi {
|
|
|
379
367
|
},
|
|
380
368
|
json: true,
|
|
381
369
|
});
|
|
382
|
-
returnData.push({ success: true, id: customerId });
|
|
370
|
+
returnData.push({ json: { success: true, id: customerId } });
|
|
383
371
|
}
|
|
384
372
|
}
|
|
385
373
|
else if (resource === 'document') {
|
|
@@ -395,7 +383,7 @@ class OptimaRestApi {
|
|
|
395
383
|
body: documentData,
|
|
396
384
|
json: true,
|
|
397
385
|
});
|
|
398
|
-
returnData.push(response);
|
|
386
|
+
returnData.push({ json: response });
|
|
399
387
|
}
|
|
400
388
|
}
|
|
401
389
|
else if (resource === 'product') {
|
|
@@ -409,7 +397,7 @@ class OptimaRestApi {
|
|
|
409
397
|
},
|
|
410
398
|
json: true,
|
|
411
399
|
});
|
|
412
|
-
returnData.push(response);
|
|
400
|
+
returnData.push({ json: response });
|
|
413
401
|
}
|
|
414
402
|
else if (operation === 'getAll') {
|
|
415
403
|
const response = await this.helpers.request({
|
|
@@ -420,23 +408,18 @@ class OptimaRestApi {
|
|
|
420
408
|
},
|
|
421
409
|
json: true,
|
|
422
410
|
});
|
|
423
|
-
|
|
411
|
+
const items = response.map(item => ({ json: item }));
|
|
412
|
+
returnData.push(...items);
|
|
424
413
|
}
|
|
425
414
|
}
|
|
426
415
|
else if (resource === 'print') {
|
|
427
416
|
if (operation === 'printDocument') {
|
|
428
|
-
const
|
|
429
|
-
const filtrSQL = this.getNodeParameter('filtrSQL', i, '');
|
|
417
|
+
const filtrSQL = this.getNodeParameter('filtrSQL', i);
|
|
430
418
|
const formatId = this.getNodeParameter('formatId', i);
|
|
431
419
|
const requestBody = {
|
|
432
|
-
formatId,
|
|
420
|
+
FormatId: formatId,
|
|
421
|
+
FiltrSQL: filtrSQL,
|
|
433
422
|
};
|
|
434
|
-
if (documentId) {
|
|
435
|
-
requestBody.documentId = documentId;
|
|
436
|
-
}
|
|
437
|
-
if (filtrSQL) {
|
|
438
|
-
requestBody.filtrSQL = filtrSQL;
|
|
439
|
-
}
|
|
440
423
|
const response = await this.helpers.request({
|
|
441
424
|
method: 'POST',
|
|
442
425
|
url: `${gatewayUrl}/api/Documents/Print`,
|
|
@@ -444,13 +427,26 @@ class OptimaRestApi {
|
|
|
444
427
|
Authorization: `Bearer ${token}`,
|
|
445
428
|
},
|
|
446
429
|
body: requestBody,
|
|
447
|
-
json:
|
|
448
|
-
encoding: null, // Get binary data
|
|
430
|
+
json: false,
|
|
431
|
+
encoding: null, // Get binary data (PDF file)
|
|
449
432
|
});
|
|
450
|
-
//
|
|
433
|
+
// API returns PDF file directly as binary
|
|
434
|
+
const buffer = Buffer.isBuffer(response)
|
|
435
|
+
? response
|
|
436
|
+
: Buffer.from(response);
|
|
437
|
+
const fileName = `document_${Date.now()}.pdf`;
|
|
451
438
|
returnData.push({
|
|
452
|
-
|
|
453
|
-
|
|
439
|
+
json: {
|
|
440
|
+
success: true,
|
|
441
|
+
fileName: fileName,
|
|
442
|
+
},
|
|
443
|
+
binary: {
|
|
444
|
+
data: {
|
|
445
|
+
data: buffer.toString('base64'),
|
|
446
|
+
mimeType: 'application/pdf',
|
|
447
|
+
fileName: fileName,
|
|
448
|
+
},
|
|
449
|
+
},
|
|
454
450
|
});
|
|
455
451
|
}
|
|
456
452
|
}
|
|
@@ -458,13 +454,13 @@ class OptimaRestApi {
|
|
|
458
454
|
catch (error) {
|
|
459
455
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
460
456
|
if (this.continueOnFail()) {
|
|
461
|
-
returnData.push({ error: errorMessage });
|
|
457
|
+
returnData.push({ json: { error: errorMessage } });
|
|
462
458
|
continue;
|
|
463
459
|
}
|
|
464
460
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), errorMessage);
|
|
465
461
|
}
|
|
466
462
|
}
|
|
467
|
-
return [
|
|
463
|
+
return [returnData];
|
|
468
464
|
}
|
|
469
465
|
}
|
|
470
466
|
exports.OptimaRestApi = OptimaRestApi;
|