UNPKG

n8n-nodes-mallabe-barcodes

Version:

n8n community node that allows the generation & scanning of different barcodes, such as the popular QR code, UPC, EAN & others using Mallabe Barcodes

167 lines 7.16 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MallabeBarcodes = void 0; const GenericFunctions_1 = require("./GenericFunctions"); const GenerateBarcodeOperation_1 = require("./GenerateBarcodeOperation"); const GenerateQrCodeOperation_1 = require("./GenerateQrCodeOperation"); const ScanBarcodeOperation_1 = require("./ScanBarcodeOperation"); class MallabeBarcodes { constructor() { this.description = { displayName: 'Mallabe Barcodes', name: 'mallabeBarcodes', icon: 'file:mallabe.svg', group: ['transform'], version: 1, subtitle: '={{ $parameter["operation"] + ": " + $parameter["resource"] }}', description: 'Mallabe Barcodes is a utility tool that allows the generation & scanning of different barcodes, such as the popular QR code, UPC, EAN & others.', defaults: { name: 'Mallabe Barcodes', }, inputs: ['main'], outputs: ['main'], credentials: [ { name: 'mallabeBarcodesApi', required: true, }, ], properties: [ { displayName: 'Resource', name: 'resource', type: 'options', noDataExpression: true, options: [ { name: 'Barcode', value: 'barcode', }, ], default: 'barcode', required: true, }, { displayName: 'Operation', name: 'operation', type: 'options', noDataExpression: true, displayOptions: { show: { resource: ['barcode'], }, }, options: [ { name: 'Generate Barcode', value: 'generateBarcode', description: 'Generate a barcode of different types such as UPC, EAN, and more', action: 'Generate barcode', }, { name: 'Generate QR Code', value: 'generateQrCode', description: 'Generate a QR code', action: 'Generate a qr code', }, { name: 'Scan Barcode', value: 'scanBarcode', description: 'Scan a QR code or barcode', action: 'Scan barcode', } ], default: 'generateQrCode', }, ...GenerateBarcodeOperation_1.generateBarcodeFields, ...GenerateQrCodeOperation_1.generateQrCodeFields, ...ScanBarcodeOperation_1.scanBarcodeFields ], }; } async execute() { const items = this.getInputData(); const returnData = []; const length = items.length; const qs = {}; let response; let responseData; let download; for (let i = 0; i < length; i++) { try { const resource = this.getNodeParameter('resource', 0); const operation = this.getNodeParameter('operation', 0); if (resource === 'barcode') { if (operation === 'generateBarcode') { const type = this.getNodeParameter('type', i); const message = this.getNodeParameter('message', i); const webhookUrl = this.getNodeParameter('webhookUrl', i); download = this.getNodeParameter('download', i); const body = { type, message, webhookUrl }; response = await GenericFunctions_1.mallabeBarcodesRequest.call(this, 'POST', '/v1/barcodes/generate', body, qs); } else if (operation === 'generateQrCode') { const message = this.getNodeParameter('message', i); const size = this.getNodeParameter('size', i); const webhookUrl = this.getNodeParameter('webhookUrl', i); download = this.getNodeParameter('download', i); const body = { type: 'qrcode', message, size, webhookUrl }; response = await GenericFunctions_1.mallabeBarcodesRequest.call(this, 'POST', '/v1/barcodes/generate', body, qs); } else if (operation === 'scanBarcode') { const type = this.getNodeParameter('type', i); const url = this.getNodeParameter('url', i); const webhookUrl = this.getNodeParameter('webhookUrl', i); const body = { type, url, webhookUrl }; response = await GenericFunctions_1.mallabeBarcodesRequest.call(this, 'POST', '/v1/barcodes/scan', body, qs); } if (download) { const output = this.getNodeParameter('output', i); const buffer = (await GenericFunctions_1.mallabeBarcodesCdnRequest.call(this, response.data.url)); responseData = { json: response, binary: { [output]: await this.helpers.prepareBinaryData(buffer), }, }; } else { responseData = response; } } if (Array.isArray(responseData)) { returnData.push.apply(returnData, responseData); } else { returnData.push(responseData); } } catch (error) { if (this.continueOnFail()) { returnData.push({ error: error.message }); continue; } throw error; } } if (download) { return [returnData]; } return [this.helpers.returnJsonArray(returnData)]; } } exports.MallabeBarcodes = MallabeBarcodes; //# sourceMappingURL=MallabeBarcodes.node.js.map