@worktables/n8n-nodes-worktables 12.0.6 → 12.1.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.
@@ -3,7 +3,6 @@ export declare class Worktables implements INodeType {
3
3
  description: INodeTypeDescription;
4
4
  methods: {
5
5
  loadOptions: {
6
- getResources(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]>;
7
6
  getWorkspaces(): Promise<{
8
7
  name: string;
9
8
  value: string;
@@ -38,15 +38,45 @@ class Worktables {
38
38
  'Content-Type': 'application/json',
39
39
  },
40
40
  },
41
+ codex: {
42
+ categories: ['Collaboration'],
43
+ subcategories: {
44
+ Collaboration: [''],
45
+ },
46
+ alias: ['monday', 'boards', 'work management'],
47
+ resources: {
48
+ primaryDocumentation: [
49
+ {
50
+ url: '',
51
+ },
52
+ ],
53
+ credentialDocumentation: [
54
+ {
55
+ url: '',
56
+ },
57
+ ],
58
+ },
59
+ },
41
60
  properties: [
42
61
  {
43
62
  displayName: 'Resource',
44
63
  name: 'resource',
45
64
  type: 'options',
46
65
  noDataExpression: true,
47
- typeOptions: {
48
- loadOptionsMethod: 'getResources',
49
- },
66
+ options: [
67
+ { name: 'Board', value: 'board', description: 'Operations related to boards' },
68
+ { name: 'Item', value: 'item', description: 'Operations related to items' },
69
+ { name: 'Subitem', value: 'subitem', description: 'Operations related to subitems' },
70
+ { name: 'Update', value: 'update', description: 'Operations related to updates' },
71
+ { name: 'Team', value: 'team', description: 'Operations related to teams' },
72
+ { name: 'User', value: 'user', description: 'Operations related to users' },
73
+ {
74
+ name: 'Download File',
75
+ value: 'downloadFile',
76
+ description: 'Download a file from Monday.com',
77
+ },
78
+ { name: 'Query', value: 'query', description: 'Operations related to running queries' },
79
+ ],
50
80
  default: 'board',
51
81
  required: true,
52
82
  description: 'Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>',
@@ -178,6 +208,12 @@ class Worktables {
178
208
  value: 'updateItem',
179
209
  action: 'Update column values of an item',
180
210
  },
211
+ {
212
+ name: 'Create or Update Item',
213
+ value: 'createOrUpdateItem',
214
+ description: 'Create a new item or update existing one based on item ID',
215
+ action: 'Create or update an item',
216
+ },
181
217
  {
182
218
  name: 'Delete an Item',
183
219
  value: 'deleteItem',
@@ -220,7 +256,7 @@ class Worktables {
220
256
  action: 'Upload files to column',
221
257
  },
222
258
  ],
223
- default: 'createItem',
259
+ default: 'createOrUpdateItem',
224
260
  required: true,
225
261
  displayOptions: {
226
262
  show: { resource: ['item'] },
@@ -569,6 +605,7 @@ class Worktables {
569
605
  'createSubitem',
570
606
  'createItem',
571
607
  'updateItem',
608
+ 'createOrUpdateItem',
572
609
  'listBoardGroups',
573
610
  'createGroup',
574
611
  'duplicateGroup',
@@ -669,7 +706,7 @@ class Worktables {
669
706
  required: true,
670
707
  description: 'Select an item from the selected board. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.',
671
708
  displayOptions: {
672
- show: { operation: ['createItem'], isSubitem: [false] },
709
+ show: { operation: ['createItem', 'createOrUpdateItem'], isSubitem: [false] },
673
710
  },
674
711
  },
675
712
  {
@@ -948,6 +985,18 @@ class Worktables {
948
985
  },
949
986
  },
950
987
  },
988
+ {
989
+ displayName: 'Item ID (Optional)',
990
+ name: 'itemIdOptional',
991
+ type: 'string',
992
+ default: '',
993
+ description: 'Item ID to update. If left empty, a new item will be created. If provided, the existing item will be updated.',
994
+ displayOptions: {
995
+ show: {
996
+ operation: ['createOrUpdateItem'],
997
+ },
998
+ },
999
+ },
951
1000
  {
952
1001
  displayName: 'Item',
953
1002
  name: 'itemId',
@@ -1066,7 +1115,7 @@ class Worktables {
1066
1115
  displayOptions: {
1067
1116
  show: {
1068
1117
  resource: ['item', 'subitem'],
1069
- operation: ['createItem', 'createSubitem'],
1118
+ operation: ['createItem', 'createSubitem', 'createOrUpdateItem'],
1070
1119
  },
1071
1120
  },
1072
1121
  },
@@ -1079,7 +1128,7 @@ class Worktables {
1079
1128
  displayOptions: {
1080
1129
  show: {
1081
1130
  resource: ['item'],
1082
- operation: ['createItem'],
1131
+ operation: ['createItem', 'createOrUpdateItem'],
1083
1132
  },
1084
1133
  },
1085
1134
  },
@@ -1094,7 +1143,7 @@ class Worktables {
1094
1143
  displayOptions: {
1095
1144
  show: {
1096
1145
  resource: ['item'],
1097
- operation: ['createItem'],
1146
+ operation: ['createItem', 'createOrUpdateItem'],
1098
1147
  isSubitem: [true],
1099
1148
  },
1100
1149
  },
@@ -1113,7 +1162,7 @@ class Worktables {
1113
1162
  displayOptions: {
1114
1163
  show: {
1115
1164
  resource: ['item', 'subitem'],
1116
- operation: ['createItem', 'updateItem', 'createSubitem'],
1165
+ operation: ['createItem', 'updateItem', 'createSubitem', 'createOrUpdateItem'],
1117
1166
  },
1118
1167
  },
1119
1168
  options: [
@@ -1874,22 +1923,6 @@ class Worktables {
1874
1923
  };
1875
1924
  this.methods = {
1876
1925
  loadOptions: {
1877
- async getResources() {
1878
- return [
1879
- { name: 'Board', value: 'board', description: 'Operations related to boards' },
1880
- { name: 'Item', value: 'item', description: 'Operations related to items' },
1881
- { name: 'Subitem', value: 'subitem', description: 'Operations related to subitems' },
1882
- { name: 'Update', value: 'update', description: 'Operations related to updates' },
1883
- { name: 'Team', value: 'team', description: 'Operations related to teams' },
1884
- { name: 'User', value: 'user', description: 'Operations related to users' },
1885
- {
1886
- name: 'Download File',
1887
- value: 'downloadFile',
1888
- description: 'Download a file from Monday.com',
1889
- },
1890
- { name: 'Query', value: 'query', description: 'Operations related to running queries' },
1891
- ];
1892
- },
1893
1926
  async getWorkspaces() {
1894
1927
  const credentials = await this.getCredentials('WorktablesApi');
1895
1928
  const apiKey = credentials === null || credentials === void 0 ? void 0 : credentials.apiKey;
@@ -2502,7 +2535,7 @@ class Worktables {
2502
2535
  };
2503
2536
  }
2504
2537
  async execute() {
2505
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10;
2538
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11;
2506
2539
  const resource = this.getNodeParameter('resource', 0);
2507
2540
  const operation = this.getNodeParameter('operation', 0);
2508
2541
  const credentials = await this.getCredentials('WorktablesApi');
@@ -3868,6 +3901,234 @@ class Worktables {
3868
3901
  case 'updateColumnValues': {
3869
3902
  break;
3870
3903
  }
3904
+ case 'createOrUpdateItem': {
3905
+ const itemName = this.getNodeParameter('itemName', 0);
3906
+ const groupId = this.getNodeParameter('groupId', 0, false);
3907
+ const boardId = this.getNodeParameter('boardId', 0);
3908
+ const isSubitem = this.getNodeParameter('isSubitem', 0);
3909
+ const itemIdOptional = this.getNodeParameter('itemIdOptional', 0, false);
3910
+ const raw = this.getNodeParameter('columnValues', 0);
3911
+ const columnValues = raw.column;
3912
+ let column_values_object = {};
3913
+ console.log('Column Values:', JSON.stringify(raw, null, 2));
3914
+ if ((columnValues === null || columnValues === void 0 ? void 0 : columnValues.length) > 0) {
3915
+ const columnTypeResponse = await this.helpers.request({
3916
+ method: 'POST',
3917
+ url: 'https://api.monday.com/v2',
3918
+ headers: {
3919
+ Authorization: `Bearer ${apiKey}`,
3920
+ 'Content-Type': 'application/json',
3921
+ },
3922
+ body: {
3923
+ query: `query {
3924
+ boards(ids: ${boardId}) {
3925
+ columns {
3926
+ id
3927
+ type
3928
+ }
3929
+ }
3930
+ }`,
3931
+ },
3932
+ });
3933
+ const columnsType = JSON.parse(columnTypeResponse).data.boards[0].columns;
3934
+ for (const col of columnValues) {
3935
+ const columnId = col.columnId;
3936
+ const columnDef = columnsType.find((c) => c.id === columnId);
3937
+ const type = columnDef === null || columnDef === void 0 ? void 0 : columnDef.type;
3938
+ if (!type || type === 'text' || type === 'simple' || col.columnType === 'simple') {
3939
+ console.log('Processing text/simple column:', col);
3940
+ if (col.columnValue !== undefined) {
3941
+ const value = col.columnValue;
3942
+ if (typeof value === 'string' && type === 'file') {
3943
+ const links = value.split(',').map((item) => {
3944
+ const [link, ...nameParts] = item.trim().split(/\s+/);
3945
+ return {
3946
+ fileType: 'LINK',
3947
+ linkToFile: link,
3948
+ name: nameParts.join(' '),
3949
+ };
3950
+ });
3951
+ column_values_object[columnId] = { files: links };
3952
+ }
3953
+ else if (typeof value === 'string') {
3954
+ column_values_object[columnId] = value.replace(/\n/g, '\\n');
3955
+ }
3956
+ else {
3957
+ column_values_object[columnId] = value;
3958
+ }
3959
+ }
3960
+ continue;
3961
+ }
3962
+ else if (col.columnType === 'objectValue') {
3963
+ console.log('Processing objectValue for column:', columnId);
3964
+ try {
3965
+ const parsedValue = JSON.parse(col.objectValue || '{}');
3966
+ column_values_object[columnId] = parsedValue;
3967
+ }
3968
+ catch (error) {
3969
+ throw new n8n_workflow_1.NodeApiError(this.getNode(), {
3970
+ message: `Invalid JSON format for column ${columnId}: ${error.message}`,
3971
+ });
3972
+ }
3973
+ continue;
3974
+ }
3975
+ switch (type) {
3976
+ case 'checkbox':
3977
+ column_values_object[columnId] = col.checkboxValue ? { checked: 'true' } : { checked: 'false' };
3978
+ break;
3979
+ case 'status':
3980
+ column_values_object[columnId] = { label: col.statusLabel || 'Working on it' };
3981
+ break;
3982
+ case 'location':
3983
+ column_values_object[columnId] = {
3984
+ lat: col.latitude || '0',
3985
+ lng: col.longitude || '0',
3986
+ address: col.address || '',
3987
+ };
3988
+ break;
3989
+ case 'dropdown':
3990
+ column_values_object[columnId] = { label: col.dropdownValue || '' };
3991
+ break;
3992
+ case 'people':
3993
+ if (col.peopleValue) {
3994
+ const peopleIds = Array.isArray(col.peopleValue) ? col.peopleValue : [col.peopleValue];
3995
+ column_values_object[columnId] = { personsAndTeams: peopleIds.map(id => ({ id, kind: 'person' })) };
3996
+ }
3997
+ break;
3998
+ case 'team':
3999
+ if (col.teamsValue) {
4000
+ const teamIds = Array.isArray(col.teamsValue) ? col.teamsValue : [col.teamsValue];
4001
+ column_values_object[columnId] = { personsAndTeams: teamIds.map(id => ({ id, kind: 'team' })) };
4002
+ }
4003
+ break;
4004
+ case 'timeline':
4005
+ column_values_object[columnId] = {
4006
+ from: col.startDate || '',
4007
+ to: col.endDate || '',
4008
+ };
4009
+ break;
4010
+ case 'date':
4011
+ column_values_object[columnId] = { date: col.dateValue || '' };
4012
+ break;
4013
+ case 'email':
4014
+ column_values_object[columnId] = {
4015
+ email: col.emailValue || '',
4016
+ text: col.emailText || '',
4017
+ };
4018
+ break;
4019
+ case 'link':
4020
+ column_values_object[columnId] = {
4021
+ url: col.url || '',
4022
+ text: col.linkText || '',
4023
+ };
4024
+ break;
4025
+ case 'phone':
4026
+ column_values_object[columnId] = {
4027
+ phone: col.phoneValue || '',
4028
+ countryShortName: col.countryCode || 'US',
4029
+ };
4030
+ break;
4031
+ case 'file':
4032
+ if ((_v = col.fileLinks) === null || _v === void 0 ? void 0 : _v.file) {
4033
+ column_values_object[columnId] = { files: col.fileLinks.file };
4034
+ }
4035
+ break;
4036
+ default:
4037
+ if (col.columnValue !== undefined) {
4038
+ column_values_object[columnId] = col.columnValue;
4039
+ }
4040
+ }
4041
+ }
4042
+ }
4043
+ let mutation;
4044
+ let formatted;
4045
+ if (itemIdOptional && itemIdOptional.trim() !== '') {
4046
+ console.log('Updating existing item:', itemIdOptional);
4047
+ const updateMutations = Object.entries(column_values_object).map(([columnId, value]) => {
4048
+ return `change_column_value(
4049
+ item_id: ${itemIdOptional},
4050
+ column_id: "${columnId}",
4051
+ value: "${JSON.stringify(value).replace(/"/g, '\\"').replace(/(^|[^\\])\\n/g, '$1\\\\n')}"
4052
+ ) {
4053
+ id
4054
+ }`;
4055
+ });
4056
+ mutation = `mutation {
4057
+ ${updateMutations.join('\n\t\t\t\t\t')}
4058
+ }`;
4059
+ response = await this.helpers.request({
4060
+ method: 'POST',
4061
+ url: 'https://api.monday.com/v2',
4062
+ headers,
4063
+ body: { query: mutation },
4064
+ });
4065
+ formatted = {
4066
+ id: itemIdOptional,
4067
+ operation: 'update',
4068
+ board_id: boardId,
4069
+ column_values: column_values_object,
4070
+ };
4071
+ }
4072
+ else {
4073
+ console.log('Creating new item:', itemName);
4074
+ const parentId = this.getNodeParameter('parentId', 0, false);
4075
+ if (isSubitem && parentId) {
4076
+ mutation = `mutation {
4077
+ create_subitem(
4078
+ parent_item_id: ${parentId},
4079
+ item_name: "${itemName}",
4080
+ column_values: "${JSON.stringify(column_values_object).replace(/"/g, '\\"').replace(/(^|[^\\])\\n/g, '$1\\\\n')}"
4081
+ ) {
4082
+ id
4083
+ name
4084
+ url
4085
+ board {
4086
+ id
4087
+ }
4088
+ }
4089
+ }`;
4090
+ }
4091
+ else {
4092
+ mutation = `mutation {
4093
+ create_item(
4094
+ board_id: ${boardId},
4095
+ group_id: "${groupId}",
4096
+ item_name: "${itemName}",
4097
+ column_values: "${JSON.stringify(column_values_object).replace(/"/g, '\\"').replace(/(^|[^\\])\\n/g, '$1\\\\n')}"
4098
+ ) {
4099
+ id
4100
+ name
4101
+ url
4102
+ board {
4103
+ id
4104
+ }
4105
+ }
4106
+ }`;
4107
+ }
4108
+ response = await this.helpers.request({
4109
+ method: 'POST',
4110
+ url: 'https://api.monday.com/v2',
4111
+ headers,
4112
+ body: { query: mutation },
4113
+ });
4114
+ const responseData = JSON.parse(response);
4115
+ const itemData = isSubitem && parentId
4116
+ ? responseData.data.create_subitem
4117
+ : responseData.data.create_item;
4118
+ formatted = {
4119
+ id: itemData.id,
4120
+ name: itemData.name,
4121
+ url: itemData.url,
4122
+ operation: 'create',
4123
+ board_id: itemData.board.id,
4124
+ column_values: column_values_object,
4125
+ };
4126
+ if (isSubitem && parentId) {
4127
+ formatted.parent_item = { id: parentId };
4128
+ }
4129
+ }
4130
+ return [[{ json: formatted }]];
4131
+ }
3871
4132
  case 'deleteItem': {
3872
4133
  console.log('Delete an item');
3873
4134
  const itemId = this.getNodeParameter('itemId', 0);
@@ -3981,7 +4242,7 @@ class Worktables {
3981
4242
  const sortOptions = this.getNodeParameter('sortOptions', 0, { sortBy: [] });
3982
4243
  const logicalOperator = this.getNodeParameter('logicalOperator', 0);
3983
4244
  let rulesArray = [];
3984
- if (((_v = filterRules === null || filterRules === void 0 ? void 0 : filterRules.rule) === null || _v === void 0 ? void 0 : _v.length) > 0) {
4245
+ if (((_w = filterRules === null || filterRules === void 0 ? void 0 : filterRules.rule) === null || _w === void 0 ? void 0 : _w.length) > 0) {
3985
4246
  rulesArray = filterRules.rule.map((rule) => {
3986
4247
  let formattedValue;
3987
4248
  if (['is_empty', 'is_not_empty'].includes(rule.operator)) {
@@ -4025,7 +4286,7 @@ class Worktables {
4025
4286
  });
4026
4287
  }
4027
4288
  const orderByArray = [];
4028
- if (((_w = sortOptions === null || sortOptions === void 0 ? void 0 : sortOptions.sortBy) === null || _w === void 0 ? void 0 : _w.length) > 0) {
4289
+ if (((_x = sortOptions === null || sortOptions === void 0 ? void 0 : sortOptions.sortBy) === null || _x === void 0 ? void 0 : _x.length) > 0) {
4029
4290
  sortOptions.sortBy.forEach((sort) => {
4030
4291
  orderByArray.push(`{
4031
4292
  column_id: "${sort.columnId}",
@@ -4071,7 +4332,7 @@ class Worktables {
4071
4332
  body: { query },
4072
4333
  });
4073
4334
  const parsed = JSON.parse(rawResponse);
4074
- const items = ((_0 = (_z = (_y = (_x = parsed === null || parsed === void 0 ? void 0 : parsed.data) === null || _x === void 0 ? void 0 : _x.boards) === null || _y === void 0 ? void 0 : _y[0]) === null || _z === void 0 ? void 0 : _z.items_page) === null || _0 === void 0 ? void 0 : _0.items) || [];
4335
+ const items = ((_1 = (_0 = (_z = (_y = parsed === null || parsed === void 0 ? void 0 : parsed.data) === null || _y === void 0 ? void 0 : _y.boards) === null || _z === void 0 ? void 0 : _z[0]) === null || _0 === void 0 ? void 0 : _0.items_page) === null || _1 === void 0 ? void 0 : _1.items) || [];
4075
4336
  const formattedItems = await Promise.all(items.map(async (item) => {
4076
4337
  const formatted = {
4077
4338
  id: item.id,
@@ -4209,7 +4470,7 @@ class Worktables {
4209
4470
  body: { query },
4210
4471
  });
4211
4472
  const parsed = JSON.parse(rawResponse);
4212
- const items = ((_6 = (_5 = (_4 = (_3 = (_2 = (_1 = parsed === null || parsed === void 0 ? void 0 : parsed.data) === null || _1 === void 0 ? void 0 : _1.boards) === null || _2 === void 0 ? void 0 : _2[0]) === null || _3 === void 0 ? void 0 : _3.groups) === null || _4 === void 0 ? void 0 : _4[0]) === null || _5 === void 0 ? void 0 : _5.items_page) === null || _6 === void 0 ? void 0 : _6.items) || [];
4473
+ const items = ((_7 = (_6 = (_5 = (_4 = (_3 = (_2 = parsed === null || parsed === void 0 ? void 0 : parsed.data) === null || _2 === void 0 ? void 0 : _2.boards) === null || _3 === void 0 ? void 0 : _3[0]) === null || _4 === void 0 ? void 0 : _4.groups) === null || _5 === void 0 ? void 0 : _5[0]) === null || _6 === void 0 ? void 0 : _6.items_page) === null || _7 === void 0 ? void 0 : _7.items) || [];
4213
4474
  const formattedItems = await Promise.all(items.map(async (item) => {
4214
4475
  const formatted = {
4215
4476
  id: item.id,
@@ -4333,7 +4594,7 @@ class Worktables {
4333
4594
  body: { query: mutation },
4334
4595
  });
4335
4596
  console.log('Create Update Result:', JSON.stringify(response, null, 2));
4336
- const updateId = (_8 = (_7 = JSON.parse(response).data) === null || _7 === void 0 ? void 0 : _7.create_update) === null || _8 === void 0 ? void 0 : _8.id;
4597
+ const updateId = (_9 = (_8 = JSON.parse(response).data) === null || _8 === void 0 ? void 0 : _8.create_update) === null || _9 === void 0 ? void 0 : _9.id;
4337
4598
  if (!updateId) {
4338
4599
  throw new n8n_workflow_1.NodeApiError(this.getNode(), {
4339
4600
  message: 'Error creating update: Update not created, no ID returned',
@@ -4653,7 +4914,7 @@ class Worktables {
4653
4914
  body: { query },
4654
4915
  json: true,
4655
4916
  });
4656
- const asset = (_10 = (_9 = responseFile === null || responseFile === void 0 ? void 0 : responseFile.data) === null || _9 === void 0 ? void 0 : _9.assets) === null || _10 === void 0 ? void 0 : _10[0];
4917
+ const asset = (_11 = (_10 = responseFile === null || responseFile === void 0 ? void 0 : responseFile.data) === null || _10 === void 0 ? void 0 : _10.assets) === null || _11 === void 0 ? void 0 : _11[0];
4657
4918
  if (!(asset === null || asset === void 0 ? void 0 : asset.public_url)) {
4658
4919
  throw new n8n_workflow_1.NodeApiError(this.getNode(), {
4659
4920
  message: 'Public URL not found for the given file ID.',