UNPKG

n8n-nodes-einvoice

Version:

n8n.io node to handle E-Invoices with PDF or XML Files (ZUGFeRD / XRechnung / Factur-X / EN-16931)

141 lines 5.32 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.description = exports.properties = void 0; exports.execute = execute; const n8n_workflow_1 = require("n8n-workflow"); const unset_1 = __importDefault(require("lodash/unset")); const einvoice_1 = require("../utils/einvoice"); exports.properties = [ { displayName: 'Input Binary Field', name: 'binaryPropertyName', type: 'string', default: 'data', required: true, placeholder: 'e.g data', hint: 'The name of the input binary field containing the file with embedded Invoice XML Informations to be extracted', }, { displayName: 'Options', name: 'options', type: 'collection', placeholder: 'Add option', default: {}, options: [ { displayName: 'Keep Source', name: 'keepSource', type: 'options', default: 'json', options: [ { name: 'JSON', value: 'json', description: 'Include JSON data of the input item', }, { name: 'Binary', value: 'binary', description: 'Include binary data of the input item', }, { name: 'Both', value: 'both', description: 'Include both JSON and binary data of the input item', }, ], }, { displayName: 'Password', name: 'password', type: 'string', typeOptions: { password: true }, default: '', description: 'Prowide password, if the PDF is encrypted', }, { displayName: 'Return Raw as JSON', name: 'returnRawJSON', type: 'boolean', default: false, displayOptions: { hide: { returnRawXML: [true], }, }, description: 'Whether to return the raw XML data of the e-invoice as JSON object', }, { displayName: 'Return Raw as XML', name: 'returnRawXML', type: 'boolean', default: false, displayOptions: { hide: { returnRawJSON: [true], }, }, description: 'Whether to return the raw XML data of the e-invoice as XML-String', }, ], }, ]; exports.description = exports.properties; async function execute(items) { const returnData = []; for (let itemIndex = 0; itemIndex < items.length; itemIndex++) { try { const item = items[itemIndex]; const options = this.getNodeParameter('options', itemIndex); const binaryPropertyName = this.getNodeParameter('binaryPropertyName', itemIndex); const resource = this.getNodeParameter('resource', itemIndex); var json = {}; if (resource === 'pdf') { json = await einvoice_1.extractEInvoiceFromPDF.call(this, binaryPropertyName, options.password, options.returnRawJSON ? 'json' : options.returnRawXML ? 'xml' : 'simple', itemIndex); } else if (resource === 'xml') { json = await einvoice_1.extractEInvoiceFromXML.call(this, binaryPropertyName, options.returnRawJSON ? 'json' : options.returnRawXML ? 'xml' : 'simple', itemIndex); } else { throw new Error("Invalid resource"); } const newItem = { json: {}, pairedItem: { item: itemIndex }, }; if (options.keepSource && options.keepSource !== 'binary') { newItem.json = { ...(0, n8n_workflow_1.deepCopy)(item.json), ...json }; } else { newItem.json = json; } if (options.keepSource === 'binary' || options.keepSource === 'both') { newItem.binary = item.binary; } else { newItem.binary = (0, n8n_workflow_1.deepCopy)(item.binary); (0, unset_1.default)(newItem.binary, binaryPropertyName); } returnData.push(newItem); } catch (error) { if (this.continueOnFail()) { returnData.push({ json: { error: error.message, }, pairedItem: { item: itemIndex, }, }); continue; } throw new n8n_workflow_1.NodeOperationError(this.getNode(), error, { itemIndex }); } } return returnData; } //# sourceMappingURL=exctraction.operation.js.map