@trg-admin/n8n-nodes-zoho-desk 0.1.24 → 0.1.26

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.
@@ -14,6 +14,7 @@ import type { IExecuteFunctions, INodeExecutionData, INodeType, INodeTypeDescrip
14
14
  * API answer. Upgrade to GET /layouts/{layoutId}/fields/{fieldId}/dependentValues if users
15
15
  * hit rejections in tenants that do enforce the mapping.
16
16
  */
17
+ export declare function readDepartmentScope(context: ILoadOptionsFunctions): string;
17
18
  export declare function loadTaxonomyOptions(context: ILoadOptionsFunctions, apiName: string): Promise<Array<{
18
19
  name: string;
19
20
  value: string;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ZohoDesk = void 0;
4
+ exports.readDepartmentScope = readDepartmentScope;
4
5
  exports.loadTaxonomyOptions = loadTaxonomyOptions;
5
6
  const n8n_workflow_1 = require("n8n-workflow");
6
7
  const GenericFunctions_1 = require("./GenericFunctions");
@@ -29,12 +30,44 @@ function cleanCommaSeparated(value) {
29
30
  * API answer. Upgrade to GET /layouts/{layoutId}/fields/{fieldId}/dependentValues if users
30
31
  * hit rejections in tenants that do enforce the mapping.
31
32
  */
33
+ function readDepartmentScope(context) {
34
+ const ctx = context;
35
+ // Top level: the ticket create form carries departmentId directly.
36
+ try {
37
+ const current = ctx.getCurrentNodeParameter?.('departmentId');
38
+ if (current !== undefined && current !== null && current !== '') {
39
+ return String(current).trim();
40
+ }
41
+ }
42
+ catch {
43
+ // Not available in this context; fall through.
44
+ }
45
+ // Fall back to the raw parameters: on create the value is also top-level, but this keeps
46
+ // the reader working if Department is ever nested inside a collection again.
47
+ try {
48
+ const raw = ctx.getCurrentNodeParameters?.();
49
+ const candidates = [
50
+ raw?.departmentId,
51
+ raw?.additionalFields?.departmentId,
52
+ ];
53
+ for (const candidate of candidates) {
54
+ if (candidate !== undefined && candidate !== null && candidate !== '') {
55
+ return String(candidate).trim();
56
+ }
57
+ }
58
+ }
59
+ catch {
60
+ // Treat as unscoped.
61
+ }
62
+ return '';
63
+ }
32
64
  async function loadTaxonomyOptions(context, apiName) {
33
- // Taxonomy is department-scoped; only top-level ticket parameters carry a department.
34
- const departmentId = context.getCurrentNodeParameter('departmentId');
65
+ // Taxonomy is department-scoped: without a department the API returns the whole org,
66
+ // which offers values that the target department's layout may reject.
67
+ const departmentId = readDepartmentScope(context);
35
68
  const qs = { module: 'tickets', apiNames: apiName };
36
69
  if (departmentId) {
37
- qs.departmentId = String(departmentId);
70
+ qs.departmentId = departmentId;
38
71
  }
39
72
  try {
40
73
  const responseData = await GenericFunctions_1.zohoDeskApiRequest.call(context, 'GET', '/organizationFields', {}, qs, 0);
@@ -206,6 +239,22 @@ class ZohoDesk {
206
239
  displayOptions: { show: { resource: ['ticket'], operation: ['create'] } },
207
240
  description: 'Department to assign ticket to. Make sure Organization ID is filled in first.',
208
241
  },
242
+ {
243
+ // Scopes the Classification / Category / Sub-Category / Channel dropdowns to one
244
+ // department's layout. Left blank, those dropdowns list the whole organization.
245
+ // Kept top-level rather than inside Additional Fields so it is visible without
246
+ // expanding the collection. Note: sending it also moves the ticket.
247
+ displayName: 'Department',
248
+ name: 'departmentId',
249
+ type: 'options',
250
+ typeOptions: {
251
+ loadOptionsMethod: 'getDepartments',
252
+ loadOptionsDependsOn: ['organizationId'],
253
+ },
254
+ default: '',
255
+ displayOptions: { show: { resource: ['ticket'], operation: ['update'] } },
256
+ description: "Department whose layout defines the values offered by the Classification, Category and Sub-Category fields below. Leave blank to list values from every department in the organization. Note: setting this also moves the ticket into that department, so set it to the ticket's current department unless you intend to move it.",
257
+ },
209
258
  {
210
259
  displayName: 'Description',
211
260
  name: 'description',
@@ -236,10 +285,10 @@ class ZohoDesk {
236
285
  type: 'options',
237
286
  typeOptions: {
238
287
  loadOptionsMethod: 'getChannels',
239
- loadOptionsDependsOn: ['organizationId'],
288
+ loadOptionsDependsOn: ['organizationId', 'departmentId'],
240
289
  },
241
290
  default: 'Email',
242
- description: 'Channel through which the ticket was received or created. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
291
+ description: 'Channel through which the ticket was received or created, scoped to the selected Department. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
243
292
  },
244
293
  {
245
294
  displayName: 'Classification',
@@ -920,7 +969,13 @@ class ZohoDesk {
920
969
  }
921
970
  catch {
922
971
  try {
923
- const fieldsResponse = await GenericFunctions_1.zohoDeskApiRequest.call(this, 'GET', '/organizationFields', {}, { module: 'tickets' }, 0);
972
+ // Channel is department-scoped too, so honour the same scope as the taxonomy.
973
+ const channelQs = { module: 'tickets', apiNames: 'channel' };
974
+ const channelDepartmentId = readDepartmentScope(this);
975
+ if (channelDepartmentId) {
976
+ channelQs.departmentId = channelDepartmentId;
977
+ }
978
+ const fieldsResponse = await GenericFunctions_1.zohoDeskApiRequest.call(this, 'GET', '/organizationFields', {}, channelQs, 0);
924
979
  const fields = Array.isArray(fieldsResponse.data)
925
980
  ? fieldsResponse.data
926
981
  : Array.isArray(fieldsResponse)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trg-admin/n8n-nodes-zoho-desk",
3
- "version": "0.1.24",
3
+ "version": "0.1.26",
4
4
  "description": "Community n8n node starter for Zoho Desk using built-in Zoho OAuth2 auth behavior",
5
5
  "license": "MIT",
6
6
  "type": "commonjs",