@couleetech/n8n-nodes-enlightenedmsp 1.6.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.
@@ -2,6 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SearchCoreCompanies = void 0;
4
4
  const GraphqlBase_1 = require("./GraphqlBase");
5
+ const tools_1 = require("@langchain/core/tools");
6
+ const zod_1 = require("zod");
5
7
  const DEFAULT_FIELDS = `id
6
8
  name
7
9
  defaultTicketLevel
@@ -10,6 +12,23 @@ const DEFAULT_FIELDS = `id
10
12
  active
11
13
  isOwnCompany
12
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
+ });
13
32
  class SearchCoreCompaniesGraphql extends GraphqlBase_1.GraphqlBase {
14
33
  async searchCompanies(variables) {
15
34
  const query = `
@@ -345,6 +364,83 @@ active`,
345
364
  const length = items.length;
346
365
  const { endpoint, apiKey } = await GraphqlBase_1.GraphqlBase.getCredentials(this);
347
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
+ });
348
444
  for (let i = 0; i < length; i++) {
349
445
  try {
350
446
  const nameFilter = this.getNodeParameter('nameFilter', i, {});
@@ -417,19 +513,15 @@ active`,
417
513
  variables.autotaskCompanyId = { eq: autotaskCompanyId };
418
514
  }
419
515
  const result = await searchCompaniesGraphql.searchCompanies(variables);
420
- const outputItem = {
516
+ returnData.push({
421
517
  json: result.findCoreCompaniesPaginated,
422
- };
423
- returnData.push(outputItem);
424
- const aiToolOutput = {
425
- json: {
426
- companies: result.findCoreCompaniesPaginated.data,
427
- totalCount: result.findCoreCompaniesPaginated.totalCount,
428
- page: result.findCoreCompaniesPaginated.page,
429
- limit: result.findCoreCompaniesPaginated.limit,
430
- },
431
- };
432
- void this.addOutputData("ai_tool", i, [[aiToolOutput]]);
518
+ });
519
+ void this.addOutputData("ai_tool", i, [[{
520
+ json: {
521
+ tool: searchCompaniesTool,
522
+ data: result.findCoreCompaniesPaginated,
523
+ },
524
+ }]]);
433
525
  }
434
526
  catch (error) {
435
527
  if (this.continueOnFail()) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@couleetech/n8n-nodes-enlightenedmsp",
3
- "version": "1.6.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",