n8n-nodes-base 1.90.1 → 1.91.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.
Files changed (65) hide show
  1. package/dist/credentials/GSuiteAdminOAuth2Api.credentials.js +3 -1
  2. package/dist/credentials/GSuiteAdminOAuth2Api.credentials.js.map +1 -1
  3. package/dist/methods/defined.json +2 -1
  4. package/dist/methods/referenced.json +1 -0
  5. package/dist/nodes/Calendly/CalendlyTrigger.node.js +11 -0
  6. package/dist/nodes/Calendly/CalendlyTrigger.node.js.map +1 -1
  7. package/dist/nodes/EmailReadImap/v1/EmailReadImapV1.node.js +2 -2
  8. package/dist/nodes/EmailReadImap/v1/EmailReadImapV1.node.js.map +1 -1
  9. package/dist/nodes/EmailReadImap/v2/EmailReadImapV2.node.js +2 -2
  10. package/dist/nodes/EmailReadImap/v2/EmailReadImapV2.node.js.map +1 -1
  11. package/dist/nodes/Files/ReadWriteFile/actions/read.operation.js +0 -1
  12. package/dist/nodes/Files/ReadWriteFile/actions/read.operation.js.map +1 -1
  13. package/dist/nodes/Form/utils.js.map +1 -1
  14. package/dist/nodes/Google/GSuiteAdmin/DeviceDescription.js +381 -0
  15. package/dist/nodes/Google/GSuiteAdmin/DeviceDescription.js.map +1 -0
  16. package/dist/nodes/Google/GSuiteAdmin/GSuiteAdmin.node.js +395 -88
  17. package/dist/nodes/Google/GSuiteAdmin/GSuiteAdmin.node.js.map +1 -1
  18. package/dist/nodes/Google/GSuiteAdmin/GenericFunctions.js +6 -2
  19. package/dist/nodes/Google/GSuiteAdmin/GenericFunctions.js.map +1 -1
  20. package/dist/nodes/Google/GSuiteAdmin/GroupDescripion.js +112 -88
  21. package/dist/nodes/Google/GSuiteAdmin/GroupDescripion.js.map +1 -1
  22. package/dist/nodes/Google/GSuiteAdmin/SearchFunctions.js +101 -0
  23. package/dist/nodes/Google/GSuiteAdmin/SearchFunctions.js.map +1 -0
  24. package/dist/nodes/Google/GSuiteAdmin/UserDescription.js +538 -195
  25. package/dist/nodes/Google/GSuiteAdmin/UserDescription.js.map +1 -1
  26. package/dist/nodes/Google/GSuiteAdmin/gSuiteAdmin.svg +1 -0
  27. package/dist/nodes/HttpRequest/V2/HttpRequestV2.node.js +11 -0
  28. package/dist/nodes/HttpRequest/V2/HttpRequestV2.node.js.map +1 -1
  29. package/dist/nodes/HttpRequest/V3/HttpRequestV3.node.js +8 -0
  30. package/dist/nodes/HttpRequest/V3/HttpRequestV3.node.js.map +1 -1
  31. package/dist/nodes/Jira/GenericFunctions.js +25 -12
  32. package/dist/nodes/Jira/GenericFunctions.js.map +1 -1
  33. package/dist/nodes/Jira/Jira.node.js +11 -7
  34. package/dist/nodes/Jira/Jira.node.js.map +1 -1
  35. package/dist/nodes/LocalFileTrigger/LocalFileTrigger.node.js +2 -2
  36. package/dist/nodes/LocalFileTrigger/LocalFileTrigger.node.js.map +1 -1
  37. package/dist/nodes/MQTT/MqttTrigger.node.js +2 -2
  38. package/dist/nodes/MQTT/MqttTrigger.node.js.map +1 -1
  39. package/dist/nodes/Postgres/PostgresTrigger.node.js +2 -2
  40. package/dist/nodes/Postgres/PostgresTrigger.node.js.map +1 -1
  41. package/dist/nodes/RabbitMQ/RabbitMQTrigger.node.js +2 -2
  42. package/dist/nodes/RabbitMQ/RabbitMQTrigger.node.js.map +1 -1
  43. package/dist/nodes/SeaTable/v2/actions/asset/upload.operation.js.map +1 -1
  44. package/dist/nodes/SeaTable/v2/actions/row/get.operation.js.map +1 -1
  45. package/dist/nodes/SeaTable/v2/actions/row/list.operation.js.map +1 -1
  46. package/dist/nodes/SeaTable/v2/actions/row/search.operation.js.map +1 -1
  47. package/dist/nodes/SseTrigger/SseTrigger.node.js +2 -2
  48. package/dist/nodes/SseTrigger/SseTrigger.node.js.map +1 -1
  49. package/dist/test/nodes/Helpers.d.ts +5 -0
  50. package/dist/test/nodes/Helpers.js +16 -170
  51. package/dist/test/nodes/Helpers.js.map +1 -1
  52. package/dist/types/credentials.json +1 -1
  53. package/dist/types/nodes.json +11 -11
  54. package/package.json +5 -5
  55. package/dist/nodes/Google/GSuiteAdmin/google-workspace-admin.png +0 -0
  56. package/dist/test/nodes/ExecuteWorkflow.js +0 -120
  57. package/dist/test/nodes/ExecuteWorkflow.js.map +0 -1
  58. package/dist/test/nodes/credential-types.js +0 -57
  59. package/dist/test/nodes/credential-types.js.map +0 -1
  60. package/dist/test/nodes/credentials-helper.js +0 -76
  61. package/dist/test/nodes/credentials-helper.js.map +0 -1
  62. package/dist/test/nodes/load-nodes-and-credentials.js +0 -68
  63. package/dist/test/nodes/load-nodes-and-credentials.js.map +0 -1
  64. package/dist/test/nodes/node-types.js +0 -56
  65. package/dist/test/nodes/node-types.js.map +0 -1
@@ -22,16 +22,17 @@ __export(GSuiteAdmin_node_exports, {
22
22
  });
23
23
  module.exports = __toCommonJS(GSuiteAdmin_node_exports);
24
24
  var import_n8n_workflow = require("n8n-workflow");
25
+ var import_DeviceDescription = require("./DeviceDescription");
25
26
  var import_GenericFunctions = require("./GenericFunctions");
26
27
  var import_GroupDescripion = require("./GroupDescripion");
28
+ var import_SearchFunctions = require("./SearchFunctions");
27
29
  var import_UserDescription = require("./UserDescription");
28
30
  class GSuiteAdmin {
29
31
  constructor() {
30
32
  this.description = {
31
33
  displayName: "Google Workspace Admin",
32
34
  name: "gSuiteAdmin",
33
- // eslint-disable-next-line n8n-nodes-base/node-class-description-icon-not-svg
34
- icon: "file:google-workspace-admin.png",
35
+ icon: "file:gSuiteAdmin.svg",
35
36
  group: ["input"],
36
37
  version: 1,
37
38
  subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
@@ -55,6 +56,10 @@ class GSuiteAdmin {
55
56
  type: "options",
56
57
  noDataExpression: true,
57
58
  options: [
59
+ {
60
+ name: "ChromeOS Device",
61
+ value: "device"
62
+ },
58
63
  {
59
64
  name: "Group",
60
65
  value: "group"
@@ -66,6 +71,8 @@ class GSuiteAdmin {
66
71
  ],
67
72
  default: "user"
68
73
  },
74
+ ...import_DeviceDescription.deviceOperations,
75
+ ...import_DeviceDescription.deviceFields,
69
76
  ...import_GroupDescripion.groupOperations,
70
77
  ...import_GroupDescripion.groupFields,
71
78
  ...import_UserDescription.userOperations,
@@ -74,8 +81,6 @@ class GSuiteAdmin {
74
81
  };
75
82
  this.methods = {
76
83
  loadOptions: {
77
- // Get all the domains to display them to user so that they can
78
- // select them easily
79
84
  async getDomains() {
80
85
  const returnData = [];
81
86
  const domains = await import_GenericFunctions.googleApiRequestAllItems.call(
@@ -94,26 +99,40 @@ class GSuiteAdmin {
94
99
  }
95
100
  return returnData;
96
101
  },
97
- // Get all the schemas to display them to user so that they can
98
- // select them easily
99
102
  async getSchemas() {
100
- const returnData = [];
101
103
  const schemas = await import_GenericFunctions.googleApiRequestAllItems.call(
102
104
  this,
103
105
  "schemas",
104
106
  "GET",
105
107
  "/directory/v1/customer/my_customer/schemas"
106
108
  );
107
- for (const schema of schemas) {
108
- const schemaName = schema.displayName;
109
- const schemaId = schema.schemaName;
109
+ return schemas.map((schema) => ({
110
+ name: schema.displayName || schema.schemaName,
111
+ value: schema.schemaName
112
+ }));
113
+ },
114
+ async getOrgUnits() {
115
+ const returnData = [];
116
+ const orgUnits = await import_GenericFunctions.googleApiRequest.call(
117
+ this,
118
+ "GET",
119
+ "/directory/v1/customer/my_customer/orgunits",
120
+ {},
121
+ { orgUnitPath: "/", type: "all" }
122
+ );
123
+ for (const unit of orgUnits.organizationUnits) {
110
124
  returnData.push({
111
- name: schemaName,
112
- value: schemaId
125
+ name: unit.name,
126
+ value: unit.orgUnitPath
113
127
  });
114
128
  }
115
129
  return returnData;
116
130
  }
131
+ },
132
+ listSearch: {
133
+ searchDevices: import_SearchFunctions.searchDevices,
134
+ searchGroups: import_SearchFunctions.searchGroups,
135
+ searchUsers: import_SearchFunctions.searchUsers
117
136
  }
118
137
  };
119
138
  }
@@ -121,34 +140,115 @@ class GSuiteAdmin {
121
140
  const items = this.getInputData();
122
141
  const returnData = [];
123
142
  const length = items.length;
124
- const qs = {};
125
143
  let responseData;
126
144
  const resource = this.getNodeParameter("resource", 0);
127
145
  const operation = this.getNodeParameter("operation", 0);
128
146
  for (let i = 0; i < length; i++) {
147
+ const qs = {};
129
148
  try {
130
- if (resource === "group") {
149
+ if (resource === "device") {
150
+ if (operation === "get") {
151
+ const deviceId = this.getNodeParameter("deviceId", i, void 0, {
152
+ extractValue: true
153
+ });
154
+ const output = this.getNodeParameter("projection", 1);
155
+ responseData = await import_GenericFunctions.googleApiRequest.call(
156
+ this,
157
+ "GET",
158
+ `/directory/v1/customer/my_customer/devices/chromeos/${deviceId}?projection=${output}`,
159
+ {}
160
+ );
161
+ }
162
+ if (operation === "getAll") {
163
+ const returnAll = this.getNodeParameter("returnAll", i);
164
+ const output = this.getNodeParameter("projection", 1);
165
+ const includeChildren = this.getNodeParameter("includeChildOrgunits", i);
166
+ const filter = this.getNodeParameter("filter", i, {});
167
+ const sort = this.getNodeParameter("sort", i, {});
168
+ qs.projection = output;
169
+ qs.includeChildOrgunits = includeChildren;
170
+ if (qs.customer === void 0) {
171
+ qs.customer = "my_customer";
172
+ }
173
+ if (filter.orgUnitPath) {
174
+ qs.orgUnitPath = filter.orgUnitPath;
175
+ }
176
+ if (filter.query) {
177
+ qs.query = filter.query.trim();
178
+ }
179
+ if (sort.sortRules) {
180
+ const { orderBy, sortOrder } = sort.sortRules;
181
+ if (orderBy) {
182
+ qs.orderBy = orderBy;
183
+ }
184
+ if (sortOrder) {
185
+ qs.sortOrder = sortOrder;
186
+ }
187
+ }
188
+ if (!returnAll) {
189
+ qs.maxResults = this.getNodeParameter("limit", i);
190
+ }
191
+ responseData = await import_GenericFunctions.googleApiRequest.call(
192
+ this,
193
+ "GET",
194
+ `/directory/v1/customer/${qs.customer}/devices/chromeos/`,
195
+ {},
196
+ qs
197
+ );
198
+ if (!Array.isArray(responseData) || responseData.length === 0) {
199
+ return [this.helpers.returnJsonArray({})];
200
+ }
201
+ return [this.helpers.returnJsonArray(responseData)];
202
+ }
203
+ if (operation === "update") {
204
+ const deviceId = this.getNodeParameter("deviceId", i, void 0, {
205
+ extractValue: true
206
+ });
207
+ const updateOptions = this.getNodeParameter("updateOptions", 1);
208
+ Object.assign(qs, updateOptions);
209
+ responseData = await import_GenericFunctions.googleApiRequest.call(
210
+ this,
211
+ "PUT",
212
+ `/directory/v1/customer/my_customer/devices/chromeos/${deviceId}`,
213
+ qs
214
+ );
215
+ }
216
+ if (operation === "changeStatus") {
217
+ const deviceId = this.getNodeParameter("deviceId", i, void 0, {
218
+ extractValue: true
219
+ });
220
+ const action = this.getNodeParameter("action", 1);
221
+ qs.action = action;
222
+ responseData = await import_GenericFunctions.googleApiRequest.call(
223
+ this,
224
+ "POST",
225
+ `/directory/v1/customer/my_customer/devices/chromeos/${deviceId}/action`,
226
+ qs
227
+ );
228
+ }
229
+ } else if (resource === "group") {
131
230
  if (operation === "create") {
231
+ const name = this.getNodeParameter("name", i);
132
232
  const email = this.getNodeParameter("email", i);
133
233
  const additionalFields = this.getNodeParameter("additionalFields", i);
134
234
  const body = {
235
+ name,
135
236
  email
136
237
  };
137
238
  Object.assign(body, additionalFields);
138
239
  responseData = await import_GenericFunctions.googleApiRequest.call(this, "POST", "/directory/v1/groups", body);
139
240
  }
140
241
  if (operation === "delete") {
141
- const groupId = this.getNodeParameter("groupId", i);
142
- responseData = await import_GenericFunctions.googleApiRequest.call(
143
- this,
144
- "DELETE",
145
- `/directory/v1/groups/${groupId}`,
146
- {}
147
- );
242
+ const groupId = this.getNodeParameter("groupId", i, void 0, {
243
+ extractValue: true
244
+ });
245
+ await import_GenericFunctions.googleApiRequest.call(this, "DELETE", `/directory/v1/groups/${groupId}`, {});
148
246
  responseData = { success: true };
149
247
  }
150
248
  if (operation === "get") {
151
- const groupId = this.getNodeParameter("groupId", i);
249
+ const groupId = this.getNodeParameter("groupId", i, void 0, {
250
+ extractValue: true
251
+ });
152
252
  responseData = await import_GenericFunctions.googleApiRequest.call(
153
253
  this,
154
254
  "GET",
@@ -158,11 +258,43 @@ class GSuiteAdmin {
158
258
  }
159
259
  if (operation === "getAll") {
160
260
  const returnAll = this.getNodeParameter("returnAll", i);
161
- const options = this.getNodeParameter("options", i);
162
- Object.assign(qs, options);
163
- if (qs.customer === void 0) {
261
+ const filter = this.getNodeParameter("filter", i, {});
262
+ const sort = this.getNodeParameter("sort", i, {});
263
+ if (filter.customer) {
264
+ qs.customer = filter.customer;
265
+ }
266
+ if (filter.domain) {
267
+ qs.domain = filter.domain;
268
+ }
269
+ if (filter.query) {
270
+ const query = filter.query.trim();
271
+ const regex = /^(name|email):\S+$/;
272
+ if (!regex.test(query)) {
273
+ throw new import_n8n_workflow.NodeOperationError(
274
+ this.getNode(),
275
+ 'Invalid query format. Query must follow the format "displayName:<value>" or "email:<value>".'
276
+ );
277
+ }
278
+ qs.query = query;
279
+ }
280
+ if (filter.userId) {
281
+ qs.userId = filter.userId;
282
+ }
283
+ if (sort.sortRules) {
284
+ const { orderBy, sortOrder } = sort.sortRules;
285
+ if (orderBy) {
286
+ qs.orderBy = orderBy;
287
+ }
288
+ if (sortOrder) {
289
+ qs.sortOrder = sortOrder;
290
+ }
291
+ }
292
+ if (!qs.customer) {
164
293
  qs.customer = "my_customer";
165
294
  }
295
+ if (!returnAll) {
296
+ qs.maxResults = this.getNodeParameter("limit", i);
297
+ }
166
298
  if (returnAll) {
167
299
  responseData = await import_GenericFunctions.googleApiRequestAllItems.call(
168
300
  this,
@@ -181,11 +313,13 @@ class GSuiteAdmin {
181
313
  {},
182
314
  qs
183
315
  );
184
- responseData = responseData.groups;
316
+ responseData = responseData.groups || [];
185
317
  }
186
318
  }
187
319
  if (operation === "update") {
188
- const groupId = this.getNodeParameter("groupId", i);
320
+ const groupId = this.getNodeParameter("groupId", i, void 0, {
321
+ extractValue: true
322
+ });
189
323
  const updateFields = this.getNodeParameter("updateFields", i);
190
324
  const body = {};
191
325
  Object.assign(body, updateFields);
@@ -196,15 +330,50 @@ class GSuiteAdmin {
196
330
  body
197
331
  );
198
332
  }
199
- }
200
- if (resource === "user") {
333
+ } else if (resource === "user") {
334
+ if (operation === "addToGroup") {
335
+ const groupId = this.getNodeParameter("groupId", i, void 0, {
336
+ extractValue: true
337
+ });
338
+ const userId = this.getNodeParameter("userId", i, void 0, {
339
+ extractValue: true
340
+ });
341
+ let userEmail;
342
+ if (!userId.includes("@")) {
343
+ const userDetails = await import_GenericFunctions.googleApiRequest.call(
344
+ this,
345
+ "GET",
346
+ `/directory/v1/users/${userId}`
347
+ );
348
+ userEmail = userDetails.primaryEmail;
349
+ } else {
350
+ userEmail = userId;
351
+ }
352
+ if (!userEmail) {
353
+ throw new import_n8n_workflow.NodeOperationError(
354
+ this.getNode(),
355
+ "Unable to determine the user email for adding to the group",
356
+ { itemIndex: i }
357
+ );
358
+ }
359
+ const body = {
360
+ email: userEmail,
361
+ role: "MEMBER"
362
+ };
363
+ await import_GenericFunctions.googleApiRequest.call(
364
+ this,
365
+ "POST",
366
+ `/directory/v1/groups/${groupId}/members`,
367
+ body
368
+ );
369
+ responseData = { added: true };
370
+ }
201
371
  if (operation === "create") {
202
372
  const domain = this.getNodeParameter("domain", i);
203
373
  const firstName = this.getNodeParameter("firstName", i);
204
374
  const lastName = this.getNodeParameter("lastName", i);
205
375
  const password = this.getNodeParameter("password", i);
206
376
  const username = this.getNodeParameter("username", i);
207
- const makeAdmin = this.getNodeParameter("makeAdmin", i);
208
377
  const additionalFields = this.getNodeParameter("additionalFields", i);
209
378
  const body = {
210
379
  name: {
@@ -214,16 +383,51 @@ class GSuiteAdmin {
214
383
  password,
215
384
  primaryEmail: `${username}@${domain}`
216
385
  };
217
- Object.assign(body, additionalFields);
386
+ if (!username) {
387
+ throw new import_n8n_workflow.NodeOperationError(this.getNode(), "The parameter 'Username' is empty", {
388
+ itemIndex: i,
389
+ description: "Please fill in the 'Username' parameter to create the user"
390
+ });
391
+ }
218
392
  if (additionalFields.phoneUi) {
219
- const phones = additionalFields.phoneUi.phoneValues;
220
- body.phones = phones;
221
- delete body.phoneUi;
393
+ body.phones = additionalFields.phoneUi.phoneValues;
222
394
  }
223
395
  if (additionalFields.emailUi) {
224
- const emails = additionalFields.emailUi.emailValues;
225
- body.emails = emails;
226
- delete body.emailUi;
396
+ body.emails = additionalFields.emailUi.emailValues;
397
+ }
398
+ if (additionalFields.roles) {
399
+ const roles = additionalFields.roles;
400
+ body.roles = {
401
+ superAdmin: roles.includes("superAdmin"),
402
+ groupsAdmin: roles.includes("groupsAdmin"),
403
+ groupsReader: roles.includes("groupsReader"),
404
+ groupsEditor: roles.includes("groupsEditor"),
405
+ userManagement: roles.includes("userManagement"),
406
+ helpDeskAdmin: roles.includes("helpDeskAdmin"),
407
+ servicesAdmin: roles.includes("servicesAdmin"),
408
+ inventoryReportingAdmin: roles.includes("inventoryReportingAdmin"),
409
+ storageAdmin: roles.includes("storageAdmin"),
410
+ directorySyncAdmin: roles.includes("directorySyncAdmin"),
411
+ mobileAdmin: roles.includes("mobileAdmin")
412
+ };
413
+ }
414
+ if (additionalFields.customFields) {
415
+ const customFields = additionalFields.customFields.fieldValues;
416
+ const customSchemas = {};
417
+ customFields.forEach((field) => {
418
+ const { schemaName, fieldName, value } = field;
419
+ if (!schemaName || !fieldName || !value) {
420
+ throw new import_n8n_workflow.NodeOperationError(this.getNode(), "Invalid custom field data", {
421
+ itemIndex: i,
422
+ description: "Schema name, field name, and value are required."
423
+ });
424
+ }
425
+ customSchemas[schemaName] ??= {};
426
+ customSchemas[schemaName][fieldName] = value;
427
+ });
428
+ if (Object.keys(customSchemas).length > 0) {
429
+ body.customSchemas = customSchemas;
430
+ }
227
431
  }
228
432
  responseData = await import_GenericFunctions.googleApiRequest.call(
229
433
  this,
@@ -232,41 +436,37 @@ class GSuiteAdmin {
232
436
  body,
233
437
  qs
234
438
  );
235
- if (makeAdmin) {
236
- await import_GenericFunctions.googleApiRequest.call(
237
- this,
238
- "POST",
239
- `/directory/v1/users/${responseData.id}/makeAdmin`,
240
- { status: true }
241
- );
242
- responseData.isAdmin = true;
243
- }
244
439
  }
245
440
  if (operation === "delete") {
246
- const userId = this.getNodeParameter("userId", i);
441
+ const userId = this.getNodeParameter("userId", i, void 0, {
442
+ extractValue: true
443
+ });
247
444
  responseData = await import_GenericFunctions.googleApiRequest.call(
248
445
  this,
249
446
  "DELETE",
250
447
  `/directory/v1/users/${userId}`,
251
448
  {}
252
449
  );
253
- responseData = { success: true };
450
+ responseData = { deleted: true };
254
451
  }
255
452
  if (operation === "get") {
256
- const userId = this.getNodeParameter("userId", i);
453
+ const userId = this.getNodeParameter("userId", i, void 0, {
454
+ extractValue: true
455
+ });
456
+ const output = this.getNodeParameter("output", i);
257
457
  const projection = this.getNodeParameter("projection", i);
258
- const options = this.getNodeParameter("options", i);
259
- qs.projection = projection;
260
- Object.assign(qs, options);
261
- if (qs.customFieldMask) {
262
- qs.customFieldMask = qs.customFieldMask.join(" ");
458
+ const fields = this.getNodeParameter("fields", i, []);
459
+ if (projection) {
460
+ qs.projection = projection;
263
461
  }
264
- if (qs.projection === "custom" && qs.customFieldMask === void 0) {
265
- throw new import_n8n_workflow.NodeOperationError(
266
- this.getNode(),
267
- "When projection is set to custom, the custom schemas field must be defined",
268
- { itemIndex: i }
269
- );
462
+ if (projection === "custom" && qs.customFieldMask) {
463
+ qs.customFieldMask = qs.customFieldMask.join(",");
464
+ }
465
+ if (output === "select") {
466
+ if (!fields.includes("id")) {
467
+ fields.push("id");
468
+ }
469
+ qs.fields = fields.join(",");
270
470
  }
271
471
  responseData = await import_GenericFunctions.googleApiRequest.call(
272
472
  this,
@@ -275,25 +475,59 @@ class GSuiteAdmin {
275
475
  {},
276
476
  qs
277
477
  );
478
+ if (output === "simplified") {
479
+ responseData = {
480
+ kind: responseData.kind,
481
+ id: responseData.id,
482
+ primaryEmail: responseData.primaryEmail,
483
+ name: responseData.name,
484
+ isAdmin: responseData.isAdmin,
485
+ lastLoginTime: responseData.lastLoginTime,
486
+ creationTime: responseData.creationTime,
487
+ suspended: responseData.suspended
488
+ };
489
+ }
278
490
  }
279
491
  if (operation === "getAll") {
280
492
  const returnAll = this.getNodeParameter("returnAll", i);
493
+ const output = this.getNodeParameter("output", i);
494
+ const fields = this.getNodeParameter("fields", i, []);
281
495
  const projection = this.getNodeParameter("projection", i);
282
- const options = this.getNodeParameter("options", i);
496
+ const filter = this.getNodeParameter("filter", i, {});
497
+ const sort = this.getNodeParameter("sort", i, {});
498
+ if (filter.customer) {
499
+ qs.customer = filter.customer;
500
+ }
501
+ if (filter.domain) {
502
+ qs.domain = filter.domain;
503
+ }
504
+ if (filter.query) {
505
+ qs.query = filter.query.trim();
506
+ }
507
+ if (filter.showDeleted) {
508
+ qs.showDeleted = filter.showDeleted ? "true" : "false";
509
+ }
510
+ if (sort.sortRules) {
511
+ const { orderBy, sortOrder } = sort.sortRules;
512
+ if (orderBy) {
513
+ qs.orderBy = orderBy;
514
+ }
515
+ if (sortOrder) {
516
+ qs.sortOrder = sortOrder;
517
+ }
518
+ }
283
519
  qs.projection = projection;
284
- Object.assign(qs, options);
285
- if (qs.customer === void 0) {
286
- qs.customer = "my_customer";
520
+ if (projection === "custom" && qs.customFieldMask) {
521
+ qs.customFieldMask = qs.customFieldMask.join(",");
287
522
  }
288
- if (qs.customFieldMask) {
289
- qs.customFieldMask = qs.customFieldMask.join(" ");
523
+ if (output === "select") {
524
+ if (!fields.includes("id")) {
525
+ fields.push("id");
526
+ }
527
+ qs.fields = `users(${fields.join(",")})`;
290
528
  }
291
- if (qs.projection === "custom" && qs.customFieldMask === void 0) {
292
- throw new import_n8n_workflow.NodeOperationError(
293
- this.getNode(),
294
- "When projection is set to custom, the custom schemas field must be defined",
295
- { itemIndex: i }
296
- );
529
+ if (!qs.customer) {
530
+ qs.customer = "my_customer";
297
531
  }
298
532
  if (returnAll) {
299
533
  responseData = await import_GenericFunctions.googleApiRequestAllItems.call(
@@ -315,32 +549,92 @@ class GSuiteAdmin {
315
549
  );
316
550
  responseData = responseData.users;
317
551
  }
552
+ if (output === "simplified") {
553
+ responseData = responseData.map((user) => ({
554
+ kind: user.kind,
555
+ id: user.id,
556
+ primaryEmail: user.primaryEmail,
557
+ name: user.name,
558
+ isAdmin: user.isAdmin,
559
+ lastLoginTime: user.lastLoginTime,
560
+ creationTime: user.creationTime,
561
+ suspended: user.suspended
562
+ }));
563
+ }
564
+ }
565
+ if (operation === "removeFromGroup") {
566
+ const groupId = this.getNodeParameter("groupId", i, void 0, {
567
+ extractValue: true
568
+ });
569
+ const userId = this.getNodeParameter("userId", i, void 0, {
570
+ extractValue: true
571
+ });
572
+ await import_GenericFunctions.googleApiRequest.call(
573
+ this,
574
+ "DELETE",
575
+ `/directory/v1/groups/${groupId}/members/${userId}`
576
+ );
577
+ responseData = { removed: true };
318
578
  }
319
579
  if (operation === "update") {
320
- const userId = this.getNodeParameter("userId", i);
580
+ const userId = this.getNodeParameter("userId", i, void 0, {
581
+ extractValue: true
582
+ });
321
583
  const updateFields = this.getNodeParameter("updateFields", i);
322
- const body = { name: {} };
323
- Object.assign(body, updateFields);
584
+ const body = {};
324
585
  if (updateFields.firstName) {
586
+ body.name ??= {};
325
587
  body.name.givenName = updateFields.firstName;
326
- delete body.firstName;
327
588
  }
328
589
  if (updateFields.lastName) {
590
+ body.name ??= {};
329
591
  body.name.familyName = updateFields.lastName;
330
- delete body.lastName;
331
- }
332
- if (Object.keys(body.name).length === 0) {
333
- delete body.name;
334
592
  }
335
593
  if (updateFields.phoneUi) {
336
- const phones = updateFields.phoneUi.phoneValues;
337
- body.phones = phones;
338
- delete body.phoneUi;
594
+ body.phones = updateFields.phoneUi.phoneValues;
339
595
  }
340
596
  if (updateFields.emailUi) {
341
- const emails = updateFields.emailUi.emailValues;
342
- body.emails = emails;
343
- delete body.emailUi;
597
+ body.emails = updateFields.emailUi.emailValues;
598
+ }
599
+ if (updateFields.primaryEmail) {
600
+ body.primaryEmail = updateFields.primaryEmail;
601
+ }
602
+ if (updateFields.suspendUi) {
603
+ body.suspended = updateFields.suspendUi;
604
+ }
605
+ if (updateFields.roles) {
606
+ const roles = updateFields.roles;
607
+ body.roles = {
608
+ superAdmin: roles.includes("superAdmin"),
609
+ groupsAdmin: roles.includes("groupsAdmin"),
610
+ groupsReader: roles.includes("groupsReader"),
611
+ groupsEditor: roles.includes("groupsEditor"),
612
+ userManagement: roles.includes("userManagement"),
613
+ helpDeskAdmin: roles.includes("helpDeskAdmin"),
614
+ servicesAdmin: roles.includes("servicesAdmin"),
615
+ inventoryReportingAdmin: roles.includes("inventoryReportingAdmin"),
616
+ storageAdmin: roles.includes("storageAdmin"),
617
+ directorySyncAdmin: roles.includes("directorySyncAdmin"),
618
+ mobileAdmin: roles.includes("mobileAdmin")
619
+ };
620
+ }
621
+ if (updateFields.customFields) {
622
+ const customFields = updateFields.customFields.fieldValues;
623
+ const customSchemas = {};
624
+ customFields.forEach((field) => {
625
+ const { schemaName, fieldName, value } = field;
626
+ if (!schemaName || !fieldName || !value) {
627
+ throw new import_n8n_workflow.NodeOperationError(this.getNode(), "Invalid custom field data", {
628
+ itemIndex: i,
629
+ description: "Schema name, field name, and value are required."
630
+ });
631
+ }
632
+ customSchemas[schemaName] ??= {};
633
+ customSchemas[schemaName][fieldName] = value;
634
+ });
635
+ if (Object.keys(customSchemas).length > 0) {
636
+ body.customSchemas = customSchemas;
637
+ }
344
638
  }
345
639
  responseData = await import_GenericFunctions.googleApiRequest.call(
346
640
  this,
@@ -357,15 +651,28 @@ class GSuiteAdmin {
357
651
  );
358
652
  returnData.push(...executionData);
359
653
  } catch (error) {
654
+ if (error instanceof import_n8n_workflow.NodeOperationError) {
655
+ throw error;
656
+ }
360
657
  if (this.continueOnFail()) {
361
658
  const executionErrorData = this.helpers.constructExecutionMetaData(
362
- this.helpers.returnJsonArray({ error: error.message }),
659
+ this.helpers.returnJsonArray({
660
+ message: `Operation "${operation}" failed for resource "${resource}".`,
661
+ description: error.message
662
+ }),
363
663
  { itemData: { item: i } }
364
664
  );
365
665
  returnData.push(...executionErrorData);
366
666
  continue;
367
667
  }
368
- throw error;
668
+ throw new import_n8n_workflow.NodeOperationError(
669
+ this.getNode(),
670
+ `Operation "${operation}" failed for resource "${resource}".`,
671
+ {
672
+ description: `Please check the input parameters and ensure the API request is correctly formatted. Details: ${error.description}`,
673
+ itemIndex: i
674
+ }
675
+ );
369
676
  }
370
677
  }
371
678
  return [returnData];