@worktables/n8n-nodes-worktables 12.1.12 → 12.2.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.
@@ -9,6 +9,7 @@ const isErrorResponse_1 = require("../../utils/isErrorResponse");
9
9
  const form_data_1 = __importDefault(require("form-data"));
10
10
  const axios_1 = __importDefault(require("axios"));
11
11
  const parseValue_1 = require("../../utils/parseValue");
12
+ const worktablesHelpers_1 = require("../../utils/worktablesHelpers");
12
13
  const country_codes_json_1 = __importDefault(require("../../utils/country_codes.json"));
13
14
  class Worktables {
14
15
  constructor() {
@@ -2754,7 +2755,7 @@ class Worktables {
2754
2755
  };
2755
2756
  }
2756
2757
  async execute() {
2757
- 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, _12, _13, _14, _15, _16, _17, _18, _19, _20;
2758
+ 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, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23;
2758
2759
  const resource = this.getNodeParameter('resource', 0);
2759
2760
  const operation = this.getNodeParameter('operation', 0);
2760
2761
  const credentials = await this.getCredentials('WorktablesApi');
@@ -3514,21 +3515,10 @@ class Worktables {
3514
3515
  column_values: {},
3515
3516
  };
3516
3517
  for (const col of subitem.column_values || []) {
3517
- const subCol = {
3518
- type: col.type,
3519
- value: await (0, parseValue_1.parseValue)(col.value),
3520
- text: col.text,
3521
- };
3522
- if ('display_value' in col) {
3523
- subCol.display_value = col.display_value;
3518
+ const subCol = await (0, worktablesHelpers_1.formatColumnValue)(col);
3519
+ if (subCol) {
3520
+ subFormatted.column_values[col.id] = subCol;
3524
3521
  }
3525
- if ('linked_item_ids' in col) {
3526
- subCol.linked_item_ids = col.linked_item_ids;
3527
- }
3528
- if ('mirrored_items' in col) {
3529
- subCol.mirrored_items = col.mirrored_items;
3530
- }
3531
- subFormatted.column_values[col.id] = subCol;
3532
3522
  }
3533
3523
  return subFormatted;
3534
3524
  }));
@@ -3543,21 +3533,10 @@ class Worktables {
3543
3533
  column_values: {},
3544
3534
  };
3545
3535
  for (const col of parentItem.column_values || []) {
3546
- const subCol = {
3547
- type: col.type,
3548
- value: await (0, parseValue_1.parseValue)(col.value),
3549
- text: col.text,
3550
- };
3551
- if ('display_value' in col) {
3552
- subCol.display_value = col.display_value;
3553
- }
3554
- if ('linked_item_ids' in col) {
3555
- subCol.linked_item_ids = col.linked_item_ids;
3556
- }
3557
- if ('mirrored_items' in col) {
3558
- subCol.mirrored_items = col.mirrored_items;
3536
+ const subCol = await (0, worktablesHelpers_1.formatColumnValue)(col);
3537
+ if (subCol) {
3538
+ parentFormatted.column_values[col.id] = subCol;
3559
3539
  }
3560
- parentFormatted.column_values[col.id] = subCol;
3561
3540
  }
3562
3541
  formatted.parent_item = parentFormatted;
3563
3542
  }
@@ -4126,23 +4105,10 @@ class Worktables {
4126
4105
  column_values: {},
4127
4106
  };
4128
4107
  for (const col of itemData.column_values || []) {
4129
- if (col.type === 'subtasks')
4130
- continue;
4131
- const formattedCol = {
4132
- type: col.type,
4133
- value: col.value,
4134
- text: col.text,
4135
- };
4136
- if ('display_value' in col) {
4137
- formattedCol.display_value = col.display_value;
4138
- }
4139
- if ('linked_item_ids' in col) {
4140
- formattedCol.linked_item_ids = col.linked_item_ids;
4141
- }
4142
- if ('mirrored_items' in col) {
4143
- formattedCol.mirrored_items = col.mirrored_items;
4108
+ const formattedCol = await (0, worktablesHelpers_1.formatColumnValue)(col);
4109
+ if (formattedCol) {
4110
+ formattedResponse.column_values[col.id] = formattedCol;
4144
4111
  }
4145
- formattedResponse.column_values[col.id] = formattedCol;
4146
4112
  }
4147
4113
  response = JSON.stringify(formattedResponse);
4148
4114
  break;
@@ -4601,23 +4567,10 @@ class Worktables {
4601
4567
  if (!fetchColumnValues)
4602
4568
  return formatted;
4603
4569
  for (const col of item.column_values || []) {
4604
- if (col.type === 'subtasks')
4605
- continue;
4606
- const formattedCol = {
4607
- type: col.type,
4608
- value: await (0, parseValue_1.parseValue)(col.value),
4609
- text: col.text,
4610
- };
4611
- if ('display_value' in col) {
4612
- formattedCol.display_value = col.display_value;
4570
+ const formattedCol = await (0, worktablesHelpers_1.formatColumnValue)(col);
4571
+ if (formattedCol) {
4572
+ formatted.column_values[col.id] = formattedCol;
4613
4573
  }
4614
- if ('linked_item_ids' in col) {
4615
- formattedCol.linked_item_ids = col.linked_item_ids;
4616
- }
4617
- if ('mirrored_items' in col) {
4618
- formattedCol.mirrored_items = col.mirrored_items;
4619
- }
4620
- formatted.column_values[col.id] = formattedCol;
4621
4574
  }
4622
4575
  return formatted;
4623
4576
  }));
@@ -4992,10 +4945,7 @@ class Worktables {
4992
4945
  message: 'Item ID, Column ID, and Binary Property Name(s) are required.',
4993
4946
  });
4994
4947
  }
4995
- const binaryNames = binaryNamesRaw
4996
- .split(',')
4997
- .map((name) => name.trim())
4998
- .filter(Boolean);
4948
+ const binaryNames = (0, worktablesHelpers_1.parseBinaryNames)(binaryNamesRaw);
4999
4949
  for (const binaryName of binaryNames) {
5000
4950
  let binaryData;
5001
4951
  try {
@@ -5006,7 +4956,7 @@ class Worktables {
5006
4956
  continue;
5007
4957
  }
5008
4958
  const fileBuffer = Buffer.from(binaryData.data, 'base64');
5009
- const fileName = `${binaryData.fileName || 'upload'}.${binaryData.fileExtension || 'dat'}`;
4959
+ const fileName = (0, worktablesHelpers_1.formatFileName)(binaryData.fileName, binaryData.fileExtension);
5010
4960
  console.log('Binary Data:', binaryData);
5011
4961
  console.log('fileName:', fileName);
5012
4962
  const form = new form_data_1.default();
@@ -5096,28 +5046,14 @@ class Worktables {
5096
5046
  column_values: {},
5097
5047
  };
5098
5048
  for (const col of item.column_values || []) {
5099
- if (col.type === 'subtasks')
5100
- continue;
5101
- const formattedCol = {
5102
- type: col.type,
5103
- value: await (0, parseValue_1.parseValue)(col.value),
5104
- text: col.text,
5105
- };
5106
- if ('display_value' in col) {
5107
- formattedCol.display_value = col.display_value;
5108
- }
5109
- if ('linked_item_ids' in col) {
5110
- formattedCol.linked_item_ids = col.linked_item_ids;
5111
- }
5112
- if ('mirrored_items' in col) {
5113
- formattedCol.mirrored_items = col.mirrored_items;
5049
+ const formattedCol = await (0, worktablesHelpers_1.formatColumnValue)(col);
5050
+ if (formattedCol) {
5051
+ formatted.column_values[col.id] = formattedCol;
5114
5052
  }
5115
- formatted.column_values[col.id] = formattedCol;
5116
5053
  }
5117
5054
  return formatted;
5118
5055
  }));
5119
- response = JSON.stringify(formattedItems);
5120
- break;
5056
+ return [formattedItems.map((item) => ({ json: item }))];
5121
5057
  }
5122
5058
  default:
5123
5059
  throw new n8n_workflow_1.NodeApiError(this.getNode(), {
@@ -5168,7 +5104,20 @@ class Worktables {
5168
5104
  headers,
5169
5105
  body: { query },
5170
5106
  });
5171
- break;
5107
+ response = await (0, isErrorResponse_1.parseApiResponse)(response);
5108
+ if (response.success) {
5109
+ const parsed = JSON.parse(response.data);
5110
+ const updates = ((_19 = (_18 = (_17 = parsed === null || parsed === void 0 ? void 0 : parsed.data) === null || _17 === void 0 ? void 0 : _17.items) === null || _18 === void 0 ? void 0 : _18[0]) === null || _19 === void 0 ? void 0 : _19.updates) || [];
5111
+ return [updates.map((update) => ({ json: update }))];
5112
+ }
5113
+ else {
5114
+ const parsed = JSON.parse(response.data);
5115
+ const firstError = parsed.errors || { message: 'Unknown error' };
5116
+ throw new n8n_workflow_1.NodeApiError(this.getNode(), firstError, {
5117
+ message: firstError.message,
5118
+ description: JSON.stringify(firstError, null, 2),
5119
+ });
5120
+ }
5172
5121
  }
5173
5122
  case 'createUpdate': {
5174
5123
  const items = this.getInputData();
@@ -5183,32 +5132,39 @@ class Worktables {
5183
5132
  }
5184
5133
  console.log('Mentions Collection:', JSON.stringify(mentionsCollection, null, 2));
5185
5134
  console.log('Should Mention:', shouldMention);
5186
- let mentionsGraphQL = '';
5187
- if (shouldMention && mentionsCollection.mention.length > 0) {
5188
- const mentions = mentionsCollection.mention
5189
- .map((m) => `{id: ${m.id}, type: ${m.type}}`)
5190
- .join(', ');
5191
- mentionsGraphQL = `, mentions_list: [${mentions}]`;
5135
+ const mentionsGraphQL = (0, worktablesHelpers_1.buildMentionsGraphQL)(shouldMention, mentionsCollection);
5136
+ const mutation = isReply
5137
+ ? `
5138
+ mutation ($body: String!, $itemId: ID!, $parentId: ID!) {
5139
+ create_update (
5140
+ item_id: $itemId,
5141
+ body: $body,
5142
+ parent_id: $parentId${mentionsGraphQL}
5143
+ ) {
5144
+ id
5145
+ }
5146
+ }`
5147
+ : `
5148
+ mutation ($body: String!, $itemId: ID!) {
5149
+ create_update (
5150
+ item_id: $itemId,
5151
+ body: $body${mentionsGraphQL}
5152
+ ) {
5153
+ id
5154
+ }
5155
+ }`;
5156
+ const variables = {
5157
+ body,
5158
+ itemId: itemId.toString(),
5159
+ };
5160
+ if (isReply) {
5161
+ variables.parentId = parentUpdateId;
5192
5162
  }
5193
- const mutation = `
5194
- mutation {
5195
- create_update (
5196
- item_id: ${itemId},
5197
- body: "${body}" ${isReply ? `, parent_id: ${parentUpdateId}` : ''}${mentionsGraphQL}
5198
- ) {
5199
- id
5200
- }
5201
- }
5202
- `;
5203
5163
  console.log('mutation:', mutation);
5204
- response = await this.helpers.request({
5205
- method: 'POST',
5206
- url: 'https://api.monday.com/v2',
5207
- headers,
5208
- body: { query: mutation },
5209
- });
5164
+ console.log('variables:', variables);
5165
+ response = await (0, worktablesHelpers_1.makeGraphQLRequest)(this, mutation, headers, variables);
5210
5166
  console.log('Create Update Result:', JSON.stringify(response, null, 2));
5211
- const updateId = (_18 = (_17 = JSON.parse(response).data) === null || _17 === void 0 ? void 0 : _17.create_update) === null || _18 === void 0 ? void 0 : _18.id;
5167
+ const updateId = (_21 = (_20 = JSON.parse(response).data) === null || _20 === void 0 ? void 0 : _20.create_update) === null || _21 === void 0 ? void 0 : _21.id;
5212
5168
  if (!updateId) {
5213
5169
  throw new n8n_workflow_1.NodeApiError(this.getNode(), {
5214
5170
  message: 'Error creating update: Update not created, no ID returned',
@@ -5216,10 +5172,7 @@ class Worktables {
5216
5172
  }
5217
5173
  for (let i = 0; i < items.length; i++) {
5218
5174
  const attachmentsString = this.getNodeParameter('attachmentsUpdate', i);
5219
- const binaryNames = attachmentsString
5220
- .split(',')
5221
- .map((name) => name.trim())
5222
- .filter(Boolean);
5175
+ const binaryNames = (0, worktablesHelpers_1.parseBinaryNames)(attachmentsString);
5223
5176
  console.log(`Item ${i} - Binary names to process:`, binaryNames);
5224
5177
  for (const binaryName of binaryNames) {
5225
5178
  let binaryData;
@@ -5231,7 +5184,7 @@ class Worktables {
5231
5184
  continue;
5232
5185
  }
5233
5186
  const fileBuffer = Buffer.from(binaryData.data, 'base64');
5234
- const fileName = binaryData.fileName || 'upload.dat';
5187
+ const fileName = (0, worktablesHelpers_1.formatFileName)(binaryData.fileName, binaryData.fileExtension, 'upload', 'dat');
5235
5188
  const form = new form_data_1.default();
5236
5189
  form.append('query', `mutation ($file: File!) {
5237
5190
  add_file_to_update (update_id: ${updateId}, file: $file) {
@@ -5263,32 +5216,24 @@ class Worktables {
5263
5216
  const mentionsCollection = this.getNodeParameter('mentionsList', 0, []);
5264
5217
  console.log('Mentions Collection:', JSON.stringify(mentionsCollection, null, 2));
5265
5218
  console.log('Should Mention:', shouldMention);
5266
- let mentionsGraphQL = '';
5267
- if (shouldMention && mentionsCollection.mention.length > 0) {
5268
- const mentions = mentionsCollection.mention
5269
- .map((m) => `{id: ${m.id}, type: ${m.type}}`)
5270
- .join(', ');
5271
- mentionsGraphQL = `, mentions_list: [${mentions}]`;
5272
- }
5219
+ const mentionsGraphQL = (0, worktablesHelpers_1.buildMentionsGraphQL)(shouldMention, mentionsCollection);
5273
5220
  const mutation = `
5274
- mutation {
5275
- edit_update (id: ${updateId}, body: "${body}" ${mentionsGraphQL}) {
5221
+ mutation ($body: String!, $updateId: ID!) {
5222
+ edit_update (id: $updateId, body: $body${mentionsGraphQL}) {
5276
5223
  id
5277
5224
  }
5278
5225
  }
5279
5226
  `;
5280
- response = await this.helpers.request({
5281
- method: 'POST',
5282
- url: 'https://api.monday.com/v2',
5283
- headers,
5284
- body: { query: mutation },
5285
- });
5227
+ const variables = {
5228
+ body,
5229
+ updateId: updateId.toString(),
5230
+ };
5231
+ console.log('mutation:', mutation);
5232
+ console.log('variables:', variables);
5233
+ response = await (0, worktablesHelpers_1.makeGraphQLRequest)(this, mutation, headers, variables);
5286
5234
  for (let i = 0; i < items.length; i++) {
5287
5235
  const attachmentsString = this.getNodeParameter('attachmentsUpdate', i);
5288
- const binaryNames = attachmentsString
5289
- .split(',')
5290
- .map((name) => name.trim())
5291
- .filter(Boolean);
5236
+ const binaryNames = (0, worktablesHelpers_1.parseBinaryNames)(attachmentsString);
5292
5237
  console.log(`Item ${i} - Binary names to process:`, binaryNames);
5293
5238
  for (const binaryName of binaryNames) {
5294
5239
  let binaryData;
@@ -5300,7 +5245,7 @@ class Worktables {
5300
5245
  continue;
5301
5246
  }
5302
5247
  const fileBuffer = Buffer.from(binaryData.data, 'base64');
5303
- const fileName = binaryData.fileName || 'upload.dat';
5248
+ const fileName = (0, worktablesHelpers_1.formatFileName)(binaryData.fileName, binaryData.fileExtension, 'upload', 'dat');
5304
5249
  const form = new form_data_1.default();
5305
5250
  form.append('query', `mutation ($file: File!) {
5306
5251
  add_file_to_update (update_id: ${updateId}, file: $file) {
@@ -5350,10 +5295,7 @@ class Worktables {
5350
5295
  message: 'Update ID and attachmentsUpdate (binary names) are required.',
5351
5296
  });
5352
5297
  }
5353
- const binaryNames = attachmentsRaw
5354
- .split(',')
5355
- .map((name) => name.trim())
5356
- .filter(Boolean);
5298
+ const binaryNames = (0, worktablesHelpers_1.parseBinaryNames)(attachmentsRaw);
5357
5299
  for (let i = 0; i < items.length; i++) {
5358
5300
  for (const binaryName of binaryNames) {
5359
5301
  let binaryData;
@@ -5365,7 +5307,7 @@ class Worktables {
5365
5307
  continue;
5366
5308
  }
5367
5309
  const fileBuffer = Buffer.from(binaryData.data, 'base64');
5368
- const fileName = `${binaryData.fileName || 'upload'}.${binaryData.fileExtension || 'dat'}`;
5310
+ const fileName = (0, worktablesHelpers_1.formatFileName)(binaryData.fileName, binaryData.fileExtension);
5369
5311
  console.log(`Item ${i} - Uploading file '${fileName}' from '${binaryName}'`);
5370
5312
  const form = new form_data_1.default();
5371
5313
  form.append('query', `mutation ($file: File!) {
@@ -5528,7 +5470,7 @@ class Worktables {
5528
5470
  body: { query },
5529
5471
  json: true,
5530
5472
  });
5531
- const asset = (_20 = (_19 = responseFile === null || responseFile === void 0 ? void 0 : responseFile.data) === null || _19 === void 0 ? void 0 : _19.assets) === null || _20 === void 0 ? void 0 : _20[0];
5473
+ const asset = (_23 = (_22 = responseFile === null || responseFile === void 0 ? void 0 : responseFile.data) === null || _22 === void 0 ? void 0 : _22.assets) === null || _23 === void 0 ? void 0 : _23[0];
5532
5474
  if (!(asset === null || asset === void 0 ? void 0 : asset.public_url)) {
5533
5475
  throw new n8n_workflow_1.NodeApiError(this.getNode(), {
5534
5476
  message: 'Public URL not found for the given file ID.',