@couleetech/n8n-nodes-enlightenedmsp 1.5.0 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,5 @@
1
+ import { IExecuteFunctions, INodeExecutionData, INodeType, INodeTypeDescription } from 'n8n-workflow';
2
+ export declare class SearchCoreCompanies implements INodeType {
3
+ description: INodeTypeDescription;
4
+ execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]>;
5
+ }
@@ -0,0 +1,543 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SearchCoreCompanies = void 0;
4
+ const GraphqlBase_1 = require("./GraphqlBase");
5
+ const tools_1 = require("@langchain/core/tools");
6
+ const zod_1 = require("zod");
7
+ const DEFAULT_FIELDS = `id
8
+ name
9
+ defaultTicketLevel
10
+ defaultHourlyRate
11
+ billingConfigured
12
+ active
13
+ isOwnCompany
14
+ autotaskCompanyId`;
15
+ const searchCompaniesSchema = zod_1.z.object({
16
+ name: zod_1.z.string().optional().describe('Company name to search for'),
17
+ nameOperation: zod_1.z.enum(['equals', 'notEquals', 'contains', 'notContains']).optional().describe('How to match the company name'),
18
+ defaultTicketLevel: zod_1.z.string().optional().describe('Default ticket level to filter by'),
19
+ defaultTicketLevelOperation: zod_1.z.enum(['equals', 'notEquals', 'contains', 'notContains']).optional().describe('How to match the ticket level'),
20
+ defaultHourlyRate: zod_1.z.number().optional().describe('Default hourly rate to filter by'),
21
+ defaultHourlyRateOperation: zod_1.z.enum(['equals', 'greaterThan', 'lessThan']).optional().describe('How to compare the hourly rate'),
22
+ billingConfigured: zod_1.z.boolean().optional().describe('Filter by billing configured status'),
23
+ active: zod_1.z.boolean().optional().describe('Filter by active status'),
24
+ isOwnCompany: zod_1.z.boolean().optional().describe('Filter by own company status'),
25
+ autotaskCompanyId: zod_1.z.number().optional().describe('Filter by Autotask company ID'),
26
+ sortBy: zod_1.z.enum(['name', 'defaultHourlyRate', 'id']).optional().describe('Field to sort results by'),
27
+ sortOrder: zod_1.z.enum(['ASC', 'DESC']).optional().describe('Sort order for the results'),
28
+ page: zod_1.z.number().optional().describe('Page number for pagination'),
29
+ limit: zod_1.z.number().optional().describe('Number of results per page'),
30
+ fields: zod_1.z.string().optional().describe('Fields to return in the response')
31
+ });
32
+ class SearchCoreCompaniesGraphql extends GraphqlBase_1.GraphqlBase {
33
+ async searchCompanies(variables) {
34
+ const query = `
35
+ query SearchCoreCompanies(
36
+ $page: Int
37
+ $limit: Int
38
+ $id: NumberProp
39
+ $name: StringProp
40
+ $defaultTicketLevel: StringProp
41
+ $defaultHourlyRate: NumberProp
42
+ $billingConfigured: BooleanProp
43
+ $active: BooleanProp
44
+ $isOwnCompany: BooleanProp
45
+ $autotaskCompanyId: NumberProp
46
+ $order: SortCoreCompaniesArgs
47
+ ) {
48
+ findCoreCompaniesPaginated(
49
+ page: $page
50
+ limit: $limit
51
+ id: $id
52
+ name: $name
53
+ defaultTicketLevel: $defaultTicketLevel
54
+ defaultHourlyRate: $defaultHourlyRate
55
+ billingConfigured: $billingConfigured
56
+ active: $active
57
+ isOwnCompany: $isOwnCompany
58
+ autotaskCompanyId: $autotaskCompanyId
59
+ order: $order
60
+ ) {
61
+ data {
62
+ ${variables.fields || DEFAULT_FIELDS}
63
+ }
64
+ totalCount
65
+ page
66
+ limit
67
+ }
68
+ }
69
+ `;
70
+ return this.executeGraphql(query, variables);
71
+ }
72
+ }
73
+ class SearchCoreCompanies {
74
+ constructor() {
75
+ this.description = {
76
+ displayName: 'Search Core Companies',
77
+ name: 'searchCoreCompanies',
78
+ icon: 'file:enlightenedmsp.svg',
79
+ group: ['transform'],
80
+ version: 1,
81
+ description: 'Search for companies in EnlightenedMSP',
82
+ defaults: {
83
+ name: 'Search Core Companies',
84
+ },
85
+ inputs: ['main'],
86
+ outputs: ['main', "ai_tool"],
87
+ outputNames: ['Output', 'Tool'],
88
+ credentials: [
89
+ {
90
+ name: 'enlightenedMspGraphql',
91
+ required: true,
92
+ },
93
+ ],
94
+ codex: {
95
+ categories: ['AI'],
96
+ subcategories: {
97
+ AI: ['Tools'],
98
+ },
99
+ resources: {
100
+ primaryDocumentation: [
101
+ {
102
+ url: 'https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.searchcorecompanies/',
103
+ },
104
+ ],
105
+ },
106
+ },
107
+ properties: [
108
+ {
109
+ displayName: 'Name Filter',
110
+ name: 'nameFilter',
111
+ type: 'fixedCollection',
112
+ default: {},
113
+ options: [
114
+ {
115
+ displayName: 'Filter',
116
+ name: 'filter',
117
+ values: [
118
+ {
119
+ displayName: 'Operation',
120
+ name: 'operation',
121
+ type: 'options',
122
+ options: [
123
+ {
124
+ name: 'Equals',
125
+ value: 'equals',
126
+ },
127
+ {
128
+ name: 'Not Equals',
129
+ value: 'notEquals',
130
+ },
131
+ {
132
+ name: 'Contains',
133
+ value: 'contains',
134
+ },
135
+ {
136
+ name: 'Not Contains',
137
+ value: 'notContains',
138
+ },
139
+ ],
140
+ default: 'equals',
141
+ typeOptions: {
142
+ minWidth: '100px',
143
+ display: 'inline',
144
+ },
145
+ },
146
+ {
147
+ displayName: 'Value',
148
+ name: 'value',
149
+ type: 'string',
150
+ default: '',
151
+ typeOptions: {
152
+ minWidth: '100px',
153
+ display: 'inline',
154
+ },
155
+ },
156
+ ],
157
+ },
158
+ ],
159
+ },
160
+ {
161
+ displayName: 'Default Ticket Level Filter',
162
+ name: 'defaultTicketLevelFilter',
163
+ type: 'fixedCollection',
164
+ default: {},
165
+ options: [
166
+ {
167
+ displayName: 'Filter',
168
+ name: 'filter',
169
+ values: [
170
+ {
171
+ displayName: 'Operation',
172
+ name: 'operation',
173
+ type: 'options',
174
+ options: [
175
+ {
176
+ name: 'Equals',
177
+ value: 'equals',
178
+ },
179
+ {
180
+ name: 'Not Equals',
181
+ value: 'notEquals',
182
+ },
183
+ {
184
+ name: 'Contains',
185
+ value: 'contains',
186
+ },
187
+ {
188
+ name: 'Not Contains',
189
+ value: 'notContains',
190
+ },
191
+ ],
192
+ default: 'equals',
193
+ typeOptions: {
194
+ minWidth: '100px',
195
+ display: 'inline',
196
+ },
197
+ },
198
+ {
199
+ displayName: 'Value',
200
+ name: 'value',
201
+ type: 'string',
202
+ default: '',
203
+ typeOptions: {
204
+ minWidth: '100px',
205
+ display: 'inline',
206
+ },
207
+ },
208
+ ],
209
+ },
210
+ ],
211
+ },
212
+ {
213
+ displayName: 'Default Hourly Rate Filter',
214
+ name: 'defaultHourlyRateFilter',
215
+ type: 'fixedCollection',
216
+ default: {},
217
+ options: [
218
+ {
219
+ displayName: 'Filter',
220
+ name: 'filter',
221
+ values: [
222
+ {
223
+ displayName: 'Operation',
224
+ name: 'operation',
225
+ type: 'options',
226
+ options: [
227
+ {
228
+ name: 'Equals',
229
+ value: 'equals',
230
+ },
231
+ {
232
+ name: 'Greater Than',
233
+ value: 'greaterThan',
234
+ },
235
+ {
236
+ name: 'Less Than',
237
+ value: 'lessThan',
238
+ },
239
+ ],
240
+ default: 'equals',
241
+ typeOptions: {
242
+ minWidth: '100px',
243
+ display: 'inline',
244
+ },
245
+ },
246
+ {
247
+ displayName: 'Value',
248
+ name: 'value',
249
+ type: 'number',
250
+ default: 0,
251
+ typeOptions: {
252
+ minWidth: '100px',
253
+ display: 'inline',
254
+ },
255
+ },
256
+ ],
257
+ },
258
+ ],
259
+ },
260
+ {
261
+ displayName: 'Billing Configured',
262
+ name: 'billingConfigured',
263
+ type: 'boolean',
264
+ default: false,
265
+ description: 'Filter by billing configured status',
266
+ },
267
+ {
268
+ displayName: 'Active',
269
+ name: 'active',
270
+ type: 'boolean',
271
+ default: true,
272
+ description: 'Filter by active status',
273
+ },
274
+ {
275
+ displayName: 'Is Own Company',
276
+ name: 'isOwnCompany',
277
+ type: 'boolean',
278
+ default: false,
279
+ description: 'Filter by own company status',
280
+ },
281
+ {
282
+ displayName: 'Autotask Company ID',
283
+ name: 'autotaskCompanyId',
284
+ type: 'number',
285
+ default: 0,
286
+ description: 'Filter by Autotask company ID',
287
+ },
288
+ {
289
+ displayName: 'Sort By',
290
+ name: 'sortBy',
291
+ type: 'options',
292
+ options: [
293
+ {
294
+ name: 'Company Name',
295
+ value: 'name',
296
+ },
297
+ {
298
+ name: 'Default Hourly Rate',
299
+ value: 'defaultHourlyRate',
300
+ },
301
+ {
302
+ name: 'ID',
303
+ value: 'id',
304
+ },
305
+ ],
306
+ default: 'name',
307
+ description: 'Field to sort results by',
308
+ },
309
+ {
310
+ displayName: 'Sort Order',
311
+ name: 'sortOrder',
312
+ type: 'options',
313
+ options: [
314
+ {
315
+ name: 'Ascending',
316
+ value: 'ASC',
317
+ },
318
+ {
319
+ name: 'Descending',
320
+ value: 'DESC',
321
+ },
322
+ ],
323
+ default: 'ASC',
324
+ description: 'Sort order for the results',
325
+ },
326
+ {
327
+ displayName: 'Page',
328
+ name: 'page',
329
+ type: 'number',
330
+ default: 1,
331
+ description: 'Page number for pagination',
332
+ },
333
+ {
334
+ displayName: 'Limit',
335
+ name: 'limit',
336
+ type: 'number',
337
+ default: 10,
338
+ description: 'Number of results per page',
339
+ },
340
+ {
341
+ displayName: 'Data Selection',
342
+ name: 'dataSelection',
343
+ type: 'string',
344
+ typeOptions: {
345
+ rows: 8,
346
+ },
347
+ default: DEFAULT_FIELDS,
348
+ required: false,
349
+ noDataExpression: true,
350
+ description: 'Fields to return in the response. Leave empty to use default fields.',
351
+ placeholder: `Example fields:
352
+ id
353
+ name
354
+ defaultTicketLevel
355
+ defaultHourlyRate
356
+ active`,
357
+ },
358
+ ],
359
+ };
360
+ }
361
+ async execute() {
362
+ const items = this.getInputData();
363
+ const returnData = [];
364
+ const length = items.length;
365
+ const { endpoint, apiKey } = await GraphqlBase_1.GraphqlBase.getCredentials(this);
366
+ const searchCompaniesGraphql = new SearchCoreCompaniesGraphql(endpoint, apiKey);
367
+ const searchCompaniesTool = new tools_1.DynamicStructuredTool({
368
+ name: 'searchCompanies',
369
+ description: 'Search for companies in EnlightenedMSP with various filters and sorting options',
370
+ schema: searchCompaniesSchema,
371
+ func: async (args) => {
372
+ const variables = {
373
+ page: args.page || 1,
374
+ limit: args.limit || 10,
375
+ fields: args.fields || DEFAULT_FIELDS,
376
+ order: args.sortBy ? { [args.sortBy]: args.sortOrder || 'ASC' } : { name: 'ASC' }
377
+ };
378
+ if (args.name) {
379
+ switch (args.nameOperation) {
380
+ case 'equals':
381
+ variables.name = { eq: args.name };
382
+ break;
383
+ case 'notEquals':
384
+ variables.name = { not: args.name };
385
+ break;
386
+ case 'contains':
387
+ variables.name = { like: args.name };
388
+ break;
389
+ case 'notContains':
390
+ variables.name = { notlike: args.name };
391
+ break;
392
+ }
393
+ }
394
+ if (args.defaultTicketLevel) {
395
+ switch (args.defaultTicketLevelOperation) {
396
+ case 'equals':
397
+ variables.defaultTicketLevel = { eq: args.defaultTicketLevel };
398
+ break;
399
+ case 'notEquals':
400
+ variables.defaultTicketLevel = { not: args.defaultTicketLevel };
401
+ break;
402
+ case 'contains':
403
+ variables.defaultTicketLevel = { like: args.defaultTicketLevel };
404
+ break;
405
+ case 'notContains':
406
+ variables.defaultTicketLevel = { notlike: args.defaultTicketLevel };
407
+ break;
408
+ }
409
+ }
410
+ if (args.defaultHourlyRate !== undefined) {
411
+ switch (args.defaultHourlyRateOperation) {
412
+ case 'equals':
413
+ variables.defaultHourlyRate = { eq: args.defaultHourlyRate };
414
+ break;
415
+ case 'greaterThan':
416
+ variables.defaultHourlyRate = { gte: args.defaultHourlyRate };
417
+ break;
418
+ case 'lessThan':
419
+ variables.defaultHourlyRate = { lte: args.defaultHourlyRate };
420
+ break;
421
+ }
422
+ }
423
+ if (args.billingConfigured !== undefined) {
424
+ variables.billingConfigured = { eq: args.billingConfigured };
425
+ }
426
+ if (args.active !== undefined) {
427
+ variables.active = { eq: args.active };
428
+ }
429
+ if (args.isOwnCompany !== undefined) {
430
+ variables.isOwnCompany = { eq: args.isOwnCompany };
431
+ }
432
+ if (args.autotaskCompanyId) {
433
+ variables.autotaskCompanyId = { eq: args.autotaskCompanyId };
434
+ }
435
+ const result = await searchCompaniesGraphql.searchCompanies(variables);
436
+ return JSON.stringify({
437
+ companies: result.findCoreCompaniesPaginated.data,
438
+ totalCount: result.findCoreCompaniesPaginated.totalCount,
439
+ page: result.findCoreCompaniesPaginated.page,
440
+ limit: result.findCoreCompaniesPaginated.limit,
441
+ });
442
+ }
443
+ });
444
+ for (let i = 0; i < length; i++) {
445
+ try {
446
+ const nameFilter = this.getNodeParameter('nameFilter', i, {});
447
+ const defaultTicketLevelFilter = this.getNodeParameter('defaultTicketLevelFilter', i, {});
448
+ const defaultHourlyRateFilter = this.getNodeParameter('defaultHourlyRateFilter', i, {});
449
+ const billingConfigured = this.getNodeParameter('billingConfigured', i);
450
+ const active = this.getNodeParameter('active', i);
451
+ const isOwnCompany = this.getNodeParameter('isOwnCompany', i);
452
+ const autotaskCompanyId = this.getNodeParameter('autotaskCompanyId', i);
453
+ const sortBy = this.getNodeParameter('sortBy', i);
454
+ const sortOrder = this.getNodeParameter('sortOrder', i);
455
+ const page = this.getNodeParameter('page', i);
456
+ const limit = this.getNodeParameter('limit', i);
457
+ const dataSelection = this.getNodeParameter('dataSelection', i, DEFAULT_FIELDS);
458
+ const variables = {
459
+ page,
460
+ limit,
461
+ fields: dataSelection,
462
+ billingConfigured: { eq: billingConfigured },
463
+ active: { eq: active },
464
+ isOwnCompany: { eq: isOwnCompany },
465
+ order: { [sortBy]: sortOrder },
466
+ };
467
+ if (nameFilter.filter) {
468
+ switch (nameFilter.filter.operation) {
469
+ case 'equals':
470
+ variables.name = { eq: nameFilter.filter.value };
471
+ break;
472
+ case 'notEquals':
473
+ variables.name = { not: nameFilter.filter.value };
474
+ break;
475
+ case 'contains':
476
+ variables.name = { like: nameFilter.filter.value };
477
+ break;
478
+ case 'notContains':
479
+ variables.name = { notlike: nameFilter.filter.value };
480
+ break;
481
+ }
482
+ }
483
+ if (defaultTicketLevelFilter.filter) {
484
+ switch (defaultTicketLevelFilter.filter.operation) {
485
+ case 'equals':
486
+ variables.defaultTicketLevel = { eq: defaultTicketLevelFilter.filter.value };
487
+ break;
488
+ case 'notEquals':
489
+ variables.defaultTicketLevel = { not: defaultTicketLevelFilter.filter.value };
490
+ break;
491
+ case 'contains':
492
+ variables.defaultTicketLevel = { like: defaultTicketLevelFilter.filter.value };
493
+ break;
494
+ case 'notContains':
495
+ variables.defaultTicketLevel = { notlike: defaultTicketLevelFilter.filter.value };
496
+ break;
497
+ }
498
+ }
499
+ if (defaultHourlyRateFilter.filter) {
500
+ switch (defaultHourlyRateFilter.filter.operation) {
501
+ case 'equals':
502
+ variables.defaultHourlyRate = { eq: defaultHourlyRateFilter.filter.value };
503
+ break;
504
+ case 'greaterThan':
505
+ variables.defaultHourlyRate = { gte: defaultHourlyRateFilter.filter.value };
506
+ break;
507
+ case 'lessThan':
508
+ variables.defaultHourlyRate = { lte: defaultHourlyRateFilter.filter.value };
509
+ break;
510
+ }
511
+ }
512
+ if (autotaskCompanyId) {
513
+ variables.autotaskCompanyId = { eq: autotaskCompanyId };
514
+ }
515
+ const result = await searchCompaniesGraphql.searchCompanies(variables);
516
+ returnData.push({
517
+ json: result.findCoreCompaniesPaginated,
518
+ });
519
+ void this.addOutputData("ai_tool", i, [[{
520
+ json: {
521
+ tool: searchCompaniesTool,
522
+ data: result.findCoreCompaniesPaginated,
523
+ },
524
+ }]]);
525
+ }
526
+ catch (error) {
527
+ if (this.continueOnFail()) {
528
+ const errorOutput = {
529
+ json: {
530
+ error: error.message,
531
+ },
532
+ };
533
+ returnData.push(errorOutput);
534
+ void this.addOutputData("ai_tool", i, [[errorOutput]]);
535
+ continue;
536
+ }
537
+ throw error;
538
+ }
539
+ }
540
+ return [returnData];
541
+ }
542
+ }
543
+ exports.SearchCoreCompanies = SearchCoreCompanies;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@couleetech/n8n-nodes-enlightenedmsp",
3
- "version": "1.5.0",
3
+ "version": "1.7.0",
4
4
  "description": "n8n node for EnlightenedMSP ticketing and workflow automation",
5
5
  "keywords": [
6
6
  "n8n-community-node-package",
@@ -43,7 +43,8 @@
43
43
  "dist/nodes/EnlightenedMsp/TicketCreated.node.js",
44
44
  "dist/nodes/EnlightenedMsp/TimeclockClockIn.node.js",
45
45
  "dist/nodes/EnlightenedMsp/TimeclockClockOut.node.js",
46
- "dist/nodes/EnlightenedMsp/SearchDattormmDevices.node.js"
46
+ "dist/nodes/EnlightenedMsp/SearchDattormmDevices.node.js",
47
+ "dist/nodes/EnlightenedMsp/SearchCoreCompanies.node.js"
47
48
  ],
48
49
  "credentials": [
49
50
  "dist/credentials/EnlightenedMspApi.credentials.js",