UNPKG

n8n-nodes-orderful

Version:
255 lines 9.72 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Orderful = void 0; const n8n_workflow_1 = require("n8n-workflow"); class Orderful { constructor() { this.description = { displayName: 'Orderful', name: 'orderful', icon: 'file:orderful.svg', group: ['transform'], version: 1, subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}', description: 'Interact with Orderful EDI platform', defaults: { name: 'Orderful', }, inputs: ["main"], outputs: ["main"], credentials: [ { name: 'orderfulApi', required: true, }, ], requestDefaults: { baseURL: '={{$credentials.baseUrl}}', headers: { Accept: 'application/json', 'Content-Type': 'application/json', Authorization: 'Bearer {{$credentials.apiKey}}', }, }, properties: [ { displayName: 'Resource', name: 'resource', type: 'options', noDataExpression: true, options: [ { name: 'Relationship', value: 'relationship', }, { name: 'Organization', value: 'organization', }, { name: 'Conversion', value: 'conversion', }, ], default: 'relationship', }, { displayName: 'Operation', name: 'operation', type: 'options', noDataExpression: true, displayOptions: { show: { resource: ['relationship'], }, }, options: [ { name: 'List', value: 'list', description: 'List all relationships', action: 'List relationships', }, ], default: 'list', }, { displayName: 'Operation', name: 'operation', type: 'options', noDataExpression: true, displayOptions: { show: { resource: ['organization'], }, }, options: [ { name: 'Get', value: 'get', description: 'Get organization details', action: 'Get organization details', }, ], default: 'get', }, { displayName: 'Operation', name: 'operation', type: 'options', noDataExpression: true, displayOptions: { show: { resource: ['conversion'], }, }, options: [ { name: 'Convert', value: 'convert', description: 'Convert data between formats', action: 'Convert data between formats', }, ], default: 'convert', }, { displayName: 'From Format', name: 'fromFormat', type: 'options', displayOptions: { show: { resource: ['conversion'], operation: ['convert'], }, }, options: [ { name: 'X12', value: 'x12', }, { name: 'JSON', value: 'json', }, { name: 'EDIFACT', value: 'edifact', }, ], default: 'x12', description: 'The format to convert from', }, { displayName: 'To Format', name: 'toFormat', type: 'options', displayOptions: { show: { resource: ['conversion'], operation: ['convert'], }, }, options: [ { name: 'JSON', value: 'json', }, { name: 'X12', value: 'x12', }, { name: 'EDIFACT', value: 'edifact', }, ], default: 'json', description: 'The format to convert to', }, { displayName: 'Data', name: 'data', type: 'string', typeOptions: { rows: 4, }, displayOptions: { show: { resource: ['conversion'], operation: ['convert'], }, }, default: '', description: 'The data to convert', required: true, }, ], }; } async execute() { const items = this.getInputData(); const returnData = []; for (let i = 0; i < items.length; i++) { try { const resource = this.getNodeParameter('resource', i); const operation = this.getNodeParameter('operation', i); let responseData = {}; if (resource === 'relationship') { if (operation === 'list') { const options = { method: 'GET', url: '/relationships', json: true, }; responseData = await this.helpers.requestWithAuthentication.call(this, 'orderfulApi', options); } } else if (resource === 'organization') { if (operation === 'get') { const options = { method: 'GET', url: '/organization', json: true, }; responseData = await this.helpers.requestWithAuthentication.call(this, 'orderfulApi', options); } } else if (resource === 'conversion') { if (operation === 'convert') { const fromFormat = this.getNodeParameter('fromFormat', i); const toFormat = this.getNodeParameter('toFormat', i); const data = this.getNodeParameter('data', i); const body = { from: fromFormat, to: toFormat, data: data, }; const options = { method: 'POST', url: '/conversion', body, json: true, }; responseData = await this.helpers.requestWithAuthentication.call(this, 'orderfulApi', options); } } const executionData = this.helpers.constructExecutionMetaData(this.helpers.returnJsonArray(responseData), { itemData: { item: i } }); returnData.push(...executionData); } catch (error) { if (this.continueOnFail()) { const executionErrorData = this.helpers.constructExecutionMetaData(this.helpers.returnJsonArray({ error: error.message }), { itemData: { item: i } }); returnData.push(...executionErrorData); continue; } throw new n8n_workflow_1.NodeOperationError(this.getNode(), error, { itemIndex: i, }); } } return [returnData]; } } exports.Orderful = Orderful; //# sourceMappingURL=Orderful.node.js.map