@worktables/n8n-nodes-worktables 12.0.7 → 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.
|
@@ -208,6 +208,12 @@ class Worktables {
|
|
|
208
208
|
value: 'updateItem',
|
|
209
209
|
action: 'Update column values of an item',
|
|
210
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
|
+
},
|
|
211
217
|
{
|
|
212
218
|
name: 'Delete an Item',
|
|
213
219
|
value: 'deleteItem',
|
|
@@ -250,7 +256,7 @@ class Worktables {
|
|
|
250
256
|
action: 'Upload files to column',
|
|
251
257
|
},
|
|
252
258
|
],
|
|
253
|
-
default: '
|
|
259
|
+
default: 'createOrUpdateItem',
|
|
254
260
|
required: true,
|
|
255
261
|
displayOptions: {
|
|
256
262
|
show: { resource: ['item'] },
|
|
@@ -599,6 +605,7 @@ class Worktables {
|
|
|
599
605
|
'createSubitem',
|
|
600
606
|
'createItem',
|
|
601
607
|
'updateItem',
|
|
608
|
+
'createOrUpdateItem',
|
|
602
609
|
'listBoardGroups',
|
|
603
610
|
'createGroup',
|
|
604
611
|
'duplicateGroup',
|
|
@@ -699,7 +706,7 @@ class Worktables {
|
|
|
699
706
|
required: true,
|
|
700
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>.',
|
|
701
708
|
displayOptions: {
|
|
702
|
-
show: { operation: ['createItem'], isSubitem: [false] },
|
|
709
|
+
show: { operation: ['createItem', 'createOrUpdateItem'], isSubitem: [false] },
|
|
703
710
|
},
|
|
704
711
|
},
|
|
705
712
|
{
|
|
@@ -978,6 +985,18 @@ class Worktables {
|
|
|
978
985
|
},
|
|
979
986
|
},
|
|
980
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
|
+
},
|
|
981
1000
|
{
|
|
982
1001
|
displayName: 'Item',
|
|
983
1002
|
name: 'itemId',
|
|
@@ -1096,7 +1115,7 @@ class Worktables {
|
|
|
1096
1115
|
displayOptions: {
|
|
1097
1116
|
show: {
|
|
1098
1117
|
resource: ['item', 'subitem'],
|
|
1099
|
-
operation: ['createItem', 'createSubitem'],
|
|
1118
|
+
operation: ['createItem', 'createSubitem', 'createOrUpdateItem'],
|
|
1100
1119
|
},
|
|
1101
1120
|
},
|
|
1102
1121
|
},
|
|
@@ -1109,7 +1128,7 @@ class Worktables {
|
|
|
1109
1128
|
displayOptions: {
|
|
1110
1129
|
show: {
|
|
1111
1130
|
resource: ['item'],
|
|
1112
|
-
operation: ['createItem'],
|
|
1131
|
+
operation: ['createItem', 'createOrUpdateItem'],
|
|
1113
1132
|
},
|
|
1114
1133
|
},
|
|
1115
1134
|
},
|
|
@@ -1124,7 +1143,7 @@ class Worktables {
|
|
|
1124
1143
|
displayOptions: {
|
|
1125
1144
|
show: {
|
|
1126
1145
|
resource: ['item'],
|
|
1127
|
-
operation: ['createItem'],
|
|
1146
|
+
operation: ['createItem', 'createOrUpdateItem'],
|
|
1128
1147
|
isSubitem: [true],
|
|
1129
1148
|
},
|
|
1130
1149
|
},
|
|
@@ -1143,7 +1162,7 @@ class Worktables {
|
|
|
1143
1162
|
displayOptions: {
|
|
1144
1163
|
show: {
|
|
1145
1164
|
resource: ['item', 'subitem'],
|
|
1146
|
-
operation: ['createItem', 'updateItem', 'createSubitem'],
|
|
1165
|
+
operation: ['createItem', 'updateItem', 'createSubitem', 'createOrUpdateItem'],
|
|
1147
1166
|
},
|
|
1148
1167
|
},
|
|
1149
1168
|
options: [
|
|
@@ -2516,7 +2535,7 @@ class Worktables {
|
|
|
2516
2535
|
};
|
|
2517
2536
|
}
|
|
2518
2537
|
async execute() {
|
|
2519
|
-
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;
|
|
2520
2539
|
const resource = this.getNodeParameter('resource', 0);
|
|
2521
2540
|
const operation = this.getNodeParameter('operation', 0);
|
|
2522
2541
|
const credentials = await this.getCredentials('WorktablesApi');
|
|
@@ -3882,6 +3901,234 @@ class Worktables {
|
|
|
3882
3901
|
case 'updateColumnValues': {
|
|
3883
3902
|
break;
|
|
3884
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
|
+
}
|
|
3885
4132
|
case 'deleteItem': {
|
|
3886
4133
|
console.log('Delete an item');
|
|
3887
4134
|
const itemId = this.getNodeParameter('itemId', 0);
|
|
@@ -3995,7 +4242,7 @@ class Worktables {
|
|
|
3995
4242
|
const sortOptions = this.getNodeParameter('sortOptions', 0, { sortBy: [] });
|
|
3996
4243
|
const logicalOperator = this.getNodeParameter('logicalOperator', 0);
|
|
3997
4244
|
let rulesArray = [];
|
|
3998
|
-
if (((
|
|
4245
|
+
if (((_w = filterRules === null || filterRules === void 0 ? void 0 : filterRules.rule) === null || _w === void 0 ? void 0 : _w.length) > 0) {
|
|
3999
4246
|
rulesArray = filterRules.rule.map((rule) => {
|
|
4000
4247
|
let formattedValue;
|
|
4001
4248
|
if (['is_empty', 'is_not_empty'].includes(rule.operator)) {
|
|
@@ -4039,7 +4286,7 @@ class Worktables {
|
|
|
4039
4286
|
});
|
|
4040
4287
|
}
|
|
4041
4288
|
const orderByArray = [];
|
|
4042
|
-
if (((
|
|
4289
|
+
if (((_x = sortOptions === null || sortOptions === void 0 ? void 0 : sortOptions.sortBy) === null || _x === void 0 ? void 0 : _x.length) > 0) {
|
|
4043
4290
|
sortOptions.sortBy.forEach((sort) => {
|
|
4044
4291
|
orderByArray.push(`{
|
|
4045
4292
|
column_id: "${sort.columnId}",
|
|
@@ -4085,7 +4332,7 @@ class Worktables {
|
|
|
4085
4332
|
body: { query },
|
|
4086
4333
|
});
|
|
4087
4334
|
const parsed = JSON.parse(rawResponse);
|
|
4088
|
-
const 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) || [];
|
|
4089
4336
|
const formattedItems = await Promise.all(items.map(async (item) => {
|
|
4090
4337
|
const formatted = {
|
|
4091
4338
|
id: item.id,
|
|
@@ -4223,7 +4470,7 @@ class Worktables {
|
|
|
4223
4470
|
body: { query },
|
|
4224
4471
|
});
|
|
4225
4472
|
const parsed = JSON.parse(rawResponse);
|
|
4226
|
-
const items = ((_6 = (_5 = (_4 = (_3 = (_2 =
|
|
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) || [];
|
|
4227
4474
|
const formattedItems = await Promise.all(items.map(async (item) => {
|
|
4228
4475
|
const formatted = {
|
|
4229
4476
|
id: item.id,
|
|
@@ -4347,7 +4594,7 @@ class Worktables {
|
|
|
4347
4594
|
body: { query: mutation },
|
|
4348
4595
|
});
|
|
4349
4596
|
console.log('Create Update Result:', JSON.stringify(response, null, 2));
|
|
4350
|
-
const updateId = (
|
|
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;
|
|
4351
4598
|
if (!updateId) {
|
|
4352
4599
|
throw new n8n_workflow_1.NodeApiError(this.getNode(), {
|
|
4353
4600
|
message: 'Error creating update: Update not created, no ID returned',
|
|
@@ -4667,7 +4914,7 @@ class Worktables {
|
|
|
4667
4914
|
body: { query },
|
|
4668
4915
|
json: true,
|
|
4669
4916
|
});
|
|
4670
|
-
const asset = (
|
|
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];
|
|
4671
4918
|
if (!(asset === null || asset === void 0 ? void 0 : asset.public_url)) {
|
|
4672
4919
|
throw new n8n_workflow_1.NodeApiError(this.getNode(), {
|
|
4673
4920
|
message: 'Public URL not found for the given file ID.',
|