UNPKG

@couleetech/n8n-nodes-enlightenedmsp

Version:

n8n node for EnlightenedMSP ticketing and workflow automation

300 lines (299 loc) 11.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SearchDattormmDevices = void 0; const GraphqlBase_1 = require("./GraphqlBase"); const DEFAULT_FIELDS = `id uid siteId siteName hostname intIpAddress operatingSystem lastLoggedInUser domain online suspended deleted lastSeen lastReboot deviceClass softwareStatus patchStatus patchesApprovedPending patchesNotApproved patchesInstalled archived`; class SearchDattormmDevicesGraphql extends GraphqlBase_1.GraphqlBase { async searchDevices(variables) { const cleanVariables = { page: variables.page, limit: variables.limit, }; if (variables.fields) { cleanVariables.fields = variables.fields; } const queryParams = ['$page: Int!', '$limit: Int!']; const queryArgs = ['page: $page', 'limit: $limit']; const filterParams = { id: 'NumberProp', uid: 'StringProp', siteId: 'NumberProp', hostname: 'StringProp', intIpAddress: 'StringProp', operatingSystem: 'StringProp', deviceClass: 'StringProp', softwareStatus: 'StringProp', patchStatus: 'StringProp', }; Object.entries(variables).forEach(([key, value]) => { if (key !== 'page' && key !== 'limit' && key !== 'fields' && value !== undefined) { queryParams.push(`$${key}: ${filterParams[key]}`); queryArgs.push(`${key}: $${key}`); cleanVariables[key] = value; } }); const query = ` query SearchDattormmDevices(${queryParams.join(', ')}) { findDattormmDevicesPaginated(${queryArgs.join(', ')}) { data { ${variables.fields || DEFAULT_FIELDS} } totalCount page limit } } `; return this.executeGraphql(query, cleanVariables); } } class SearchDattormmDevices { constructor() { this.description = { displayName: 'Search Dattormm Devices', name: 'searchDattormmDevices', icon: 'file:enlightenedmsp.svg', group: ['transform'], version: 1, description: 'Search for devices in Dattormm', defaults: { name: 'Search Dattormm Devices', }, inputs: ["main"], outputs: ["main", "ai_tool"], outputNames: ['Output', 'Tool'], credentials: [ { name: 'enlightenedMspGraphql', required: true, }, ], codex: { categories: ['AI'], subcategories: { AI: ['Tools'], }, resources: { primaryDocumentation: [ { url: 'https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.searchdattormmdevices/', }, ], }, }, properties: [ { displayName: 'Device ID', name: 'id', type: 'number', default: 0, description: 'Filter by device ID', }, { displayName: 'UID', name: 'uid', type: 'string', default: '', description: 'Filter by device UID', }, { displayName: 'Site ID', name: 'siteId', type: 'number', default: 0, description: 'Filter by site ID', }, { displayName: 'Hostname', name: 'hostname', type: 'string', default: '', description: 'Filter by hostname', }, { displayName: 'IP Address', name: 'intIpAddress', type: 'string', default: '', description: 'Filter by internal IP address', }, { displayName: 'Operating System', name: 'operatingSystem', type: 'string', default: '', description: 'Filter by operating system', }, { displayName: 'Device Class', name: 'deviceClass', type: 'string', default: '', description: 'Filter by device class', }, { displayName: 'Software Status', name: 'softwareStatus', type: 'string', default: '', description: 'Filter by software status', }, { displayName: 'Patch Status', name: 'patchStatus', type: 'string', default: '', description: 'Filter by patch status', }, { displayName: 'Page', name: 'page', type: 'number', default: 0, description: 'Page number for pagination (0-indexed)', }, { displayName: 'Limit', name: 'limit', type: 'number', default: 10, description: 'Number of results per page', }, { displayName: 'Data Selection', name: 'dataSelection', type: 'string', typeOptions: { rows: 8, }, default: DEFAULT_FIELDS, required: false, noDataExpression: true, description: 'Fields to return in the response. Leave empty to use default fields.', placeholder: `Example fields: id uid hostname intIpAddress online deviceClass`, }, ], }; } async execute() { const items = this.getInputData(); const returnData = []; const { endpoint, apiKey } = await SearchDattormmDevicesGraphql.getCredentials(this); const graphqlClient = new SearchDattormmDevicesGraphql(endpoint, apiKey); for (let i = 0; i < items.length; i++) { try { const id = this.getNodeParameter('id', i); const uid = this.getNodeParameter('uid', i); const siteId = this.getNodeParameter('siteId', i); const hostname = this.getNodeParameter('hostname', i); const intIpAddress = this.getNodeParameter('intIpAddress', i); const operatingSystem = this.getNodeParameter('operatingSystem', i); const deviceClass = this.getNodeParameter('deviceClass', i); const softwareStatus = this.getNodeParameter('softwareStatus', i); const patchStatus = this.getNodeParameter('patchStatus', i); const page = this.getNodeParameter('page', i); const limit = this.getNodeParameter('limit', i); const dataSelection = this.getNodeParameter('dataSelection', i, undefined); const variables = { page, limit, }; if (dataSelection) { variables.fields = dataSelection; } const filters = {}; let hasFilters = false; if (id !== undefined && id !== null) { filters.id = { eq: id }; hasFilters = true; } if (uid) { filters.uid = { eq: uid }; hasFilters = true; } if (siteId !== undefined && siteId !== null) { filters.siteId = { eq: siteId }; hasFilters = true; } if (hostname && hostname.trim() !== '') { filters.hostname = { eq: hostname }; hasFilters = true; } if (intIpAddress && intIpAddress.trim() !== '') { filters.intIpAddress = { eq: intIpAddress }; hasFilters = true; } if (operatingSystem && operatingSystem.trim() !== '') { filters.operatingSystem = { eq: operatingSystem }; hasFilters = true; } if (deviceClass && deviceClass.trim() !== '') { filters.deviceClass = { eq: deviceClass }; hasFilters = true; } if (softwareStatus && softwareStatus.trim() !== '') { filters.softwareStatus = { eq: softwareStatus }; hasFilters = true; } if (patchStatus && patchStatus.trim() !== '') { filters.patchStatus = { eq: patchStatus }; hasFilters = true; } if (hasFilters) { Object.assign(variables, filters); } const result = await graphqlClient.searchDevices(variables); returnData.push({ json: result.findDattormmDevicesPaginated, }); } catch (error) { if (this.continueOnFail()) { returnData.push({ json: { error: error.message, }, }); continue; } throw error; } } const aiToolData = returnData.map(item => ({ json: { devices: item.json.data, totalCount: item.json.totalCount, page: item.json.page, limit: item.json.limit, }, })); return [returnData, aiToolData]; } } exports.SearchDattormmDevices = SearchDattormmDevices;