UNPKG

@ev1lc0rp/n8n-nodes-ninjaone

Version:

Professional NinjaOne RMM integration for n8n with complete ticketing and device management

119 lines 4.54 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.NinjaOneLegacy = void 0; const crypto_1 = require("crypto"); class NinjaOneLegacy { constructor() { this.description = { displayName: 'NinjaOne Legacy', name: 'ninjaOneLegacy', icon: { light: 'file:ninjaone.svg', dark: 'file:ninjaone.svg' }, group: ['transform'], version: 1, subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}', description: 'Interact with the NinjaOne Legacy API', defaults: { name: 'NinjaOne Legacy', }, inputs: ["main"], outputs: ["main"], usableAsTool: true, credentials: [ { name: 'ninjaOneLegacyApi', required: true, }, ], properties: [ { displayName: 'Resource', name: 'resource', type: 'options', noDataExpression: true, options: [ { name: 'Customer', value: 'customer', }, ], default: 'customer', }, { displayName: 'Operation', name: 'operation', type: 'options', noDataExpression: true, displayOptions: { show: { resource: ['customer'], }, }, options: [ { name: 'Get Many', value: 'getAll', action: 'Get many customers', }, { name: 'Get', value: 'get', action: 'Get a customer', }, ], default: 'getAll', }, { displayName: 'Customer ID', name: 'customerId', type: 'number', displayOptions: { show: { resource: ['customer'], operation: ['get'], }, }, default: 0, }, ], }; } async execute() { const items = this.getInputData(); const returnData = []; const credentials = await this.getCredentials('ninjaOneLegacyApi'); for (let i = 0; i < items.length; i++) { const resource = this.getNodeParameter('resource', i); const operation = this.getNodeParameter('operation', i); let requestOptions = { method: 'GET', url: '', baseURL: 'https://app.ninjarmm.com', headers: { Accept: 'application/json', 'Content-Type': 'application/json', }, }; if (resource === 'customer') { if (operation === 'getAll') { requestOptions.url = '/v1/customers'; } else if (operation === 'get') { const id = this.getNodeParameter('customerId', i); requestOptions.url = `/v1/customers/${id}`; } } const date = new Date().toUTCString(); const stringToSign = `${requestOptions.method}\n\n${requestOptions.headers['Content-Type']}\n${date}\n${requestOptions.url}`; const hmac = (0, crypto_1.createHmac)('sha1', credentials.secretAccessKey); hmac.update(Buffer.from(stringToSign, 'utf8')); const signature = hmac.digest('base64'); requestOptions.headers.Authorization = `NJ ${credentials.accessKeyId}:${signature}`; requestOptions.headers.Date = date; const response = await this.helpers.httpRequest(requestOptions); returnData.push({ json: response }); } return [returnData]; } } exports.NinjaOneLegacy = NinjaOneLegacy; //# sourceMappingURL=NinjaOneLegacy.node.js.map