n8n-nodes-pragma-bitrix24 1.0.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.
- package/LICENSE +51 -0
- package/README.md +340 -0
- package/dist/credentials/Bitrix24Api.credentials.js +55 -0
- package/dist/nodes/Bitrix24/Bitrix24.node.js +1410 -0
- package/dist/nodes/Bitrix24/Company.js +17 -0
- package/dist/nodes/Bitrix24/Contact.js +31 -0
- package/dist/nodes/Bitrix24/Deal.js +17 -0
- package/dist/nodes/Bitrix24/Helpers.js +300 -0
- package/dist/nodes/Bitrix24/Lead.js +17 -0
- package/dist/nodes/Bitrix24/SmartProcess.js +1 -0
- package/dist/nodes/Bitrix24/bitrix24.svg +7 -0
- package/dist/nodes/Bitrix24/types.js +58 -0
- package/dist/nodes/Bitrix24AI/Bitrix24AI.node.js +205 -0
- package/dist/nodes/Bitrix24App/Bitrix24App.node.js +179 -0
- package/dist/nodes/Bitrix24Auxiliary/Bitrix24Auxiliary.node.js +566 -0
- package/dist/nodes/Bitrix24Booking/Bitrix24Booking.node.js +871 -0
- package/dist/nodes/Bitrix24Calendar/Bitrix24Calendar.node.js +471 -0
- package/dist/nodes/Bitrix24ChatBot/Bitrix24ChatBot.node.js +522 -0
- package/dist/nodes/Bitrix24Commerce/Bitrix24Commerce.node.js +431 -0
- package/dist/nodes/Bitrix24Department/Bitrix24Department.node.js +317 -0
- package/dist/nodes/Bitrix24Disk/Bitrix24Disk.node.js +334 -0
- package/dist/nodes/Bitrix24Document/Bitrix24Document.node.js +280 -0
- package/dist/nodes/Bitrix24Entity/Bitrix24Entity.node.js +263 -0
- package/dist/nodes/Bitrix24Group/Bitrix24Group.node.js +327 -0
- package/dist/nodes/Bitrix24Lists/Bitrix24Lists.node.js +406 -0
- package/dist/nodes/Bitrix24Log/Bitrix24Log.node.js +309 -0
- package/dist/nodes/Bitrix24Mail/Bitrix24Mail.node.js +109 -0
- package/dist/nodes/Bitrix24MessageService/Bitrix24MessageService.node.js +218 -0
- package/dist/nodes/Bitrix24OpenChannels/Bitrix24OpenChannels.node.js +379 -0
- package/dist/nodes/Bitrix24PaySystem/Bitrix24PaySystem.node.js +241 -0
- package/dist/nodes/Bitrix24Pipeline/Bitrix24Pipeline.node.js +553 -0
- package/dist/nodes/Bitrix24Pipeline/bitrix24.svg +7 -0
- package/dist/nodes/Bitrix24Sale/Bitrix24Sale.node.js +391 -0
- package/dist/nodes/Bitrix24Scrum/Bitrix24Scrum.node.js +555 -0
- package/dist/nodes/Bitrix24Scrum/bitrix24.svg +7 -0
- package/dist/nodes/Bitrix24Sign/Bitrix24Sign.node.js +132 -0
- package/dist/nodes/Bitrix24Social/Bitrix24Social.node.js +224 -0
- package/dist/nodes/Bitrix24Task/Bitrix24Task.node.js +444 -0
- package/dist/nodes/Bitrix24Telephony/Bitrix24Telephony.node.js +511 -0
- package/dist/nodes/Bitrix24Timeman/Bitrix24Timeman.node.js +196 -0
- package/dist/nodes/Bitrix24Tool/Bitrix24Tool.node.js +1035 -0
- package/dist/nodes/Bitrix24Tool/bitrix24.svg +7 -0
- package/dist/nodes/Bitrix24Trigger/Bitrix24Trigger.node.js +184 -0
- package/dist/nodes/Bitrix24User/Bitrix24User.node.js +351 -0
- package/dist/nodes/Bitrix24UserField/Bitrix24UserField.node.js +386 -0
- package/dist/nodes/Bitrix24UserField/bitrix24.svg +7 -0
- package/dist/nodes/shared/bitrix24.svg +7 -0
- package/dist/nodes/shared/localization.js +189 -0
- package/dist/nodes/shared/types.js +22 -0
- package/index.js +10 -0
- package/package.json +108 -0
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Bitrix24 Department — Нода управления оргструктурой
|
|
4
|
+
*
|
|
5
|
+
* Bitrix24 PRAGMA.by nodes for n8n
|
|
6
|
+
* Профессиональная интеграция с Битрикс24.
|
|
7
|
+
*
|
|
8
|
+
* @author PRAGMA & Азбука Решений
|
|
9
|
+
* @copyright 2026 PRAGMA (https://pragma.by/) & Азбука Решений (https://abc-solution.ru/)
|
|
10
|
+
*
|
|
11
|
+
* Контакты:
|
|
12
|
+
* 🇧🇾 PRAGMA: +375 (44) 702-70-90 | https://pragma.by/
|
|
13
|
+
* 🇷🇺 Азбука Решений: +7 (939) 555-19-60 | https://abc-solution.ru/
|
|
14
|
+
*/
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.Bitrix24Department = void 0;
|
|
17
|
+
const Helpers_1 = require("../Bitrix24/Helpers");
|
|
18
|
+
class Bitrix24Department {
|
|
19
|
+
constructor() {
|
|
20
|
+
this.description = {
|
|
21
|
+
displayName: 'Bitrix24 Оргструктура',
|
|
22
|
+
name: 'bitrix24Department',
|
|
23
|
+
icon: 'file:bitrix24.svg',
|
|
24
|
+
group: ['transform'],
|
|
25
|
+
version: 1,
|
|
26
|
+
subtitle: '={{$parameter["operation"]}}',
|
|
27
|
+
description: 'Управление отделами и организационной структурой компании',
|
|
28
|
+
defaults: {
|
|
29
|
+
name: 'Bitrix24 Оргструктура',
|
|
30
|
+
},
|
|
31
|
+
inputs: ['main'],
|
|
32
|
+
outputs: ['main'],
|
|
33
|
+
credentials: [
|
|
34
|
+
{
|
|
35
|
+
name: 'bitrix24Api',
|
|
36
|
+
required: true,
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
properties: [
|
|
40
|
+
{
|
|
41
|
+
displayName: 'Operation',
|
|
42
|
+
name: 'operation',
|
|
43
|
+
type: 'options',
|
|
44
|
+
noDataExpression: true,
|
|
45
|
+
options: [
|
|
46
|
+
{
|
|
47
|
+
name: 'List',
|
|
48
|
+
value: 'list',
|
|
49
|
+
action: 'List departments',
|
|
50
|
+
description: 'Get all departments',
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
name: 'Get',
|
|
54
|
+
value: 'get',
|
|
55
|
+
action: 'Get a department',
|
|
56
|
+
description: 'Get a specific department by ID',
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
name: 'Create',
|
|
60
|
+
value: 'create',
|
|
61
|
+
action: 'Create a department',
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
name: 'Update',
|
|
65
|
+
value: 'update',
|
|
66
|
+
action: 'Update a department',
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
name: 'Delete',
|
|
70
|
+
value: 'delete',
|
|
71
|
+
action: 'Delete a department',
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
name: 'Get Tree (Visual)',
|
|
75
|
+
value: 'getTree',
|
|
76
|
+
action: 'Get nested structure',
|
|
77
|
+
description: 'Get full department tree',
|
|
78
|
+
},
|
|
79
|
+
],
|
|
80
|
+
default: 'list',
|
|
81
|
+
required: true,
|
|
82
|
+
},
|
|
83
|
+
// Fields
|
|
84
|
+
{
|
|
85
|
+
displayName: 'Department ID',
|
|
86
|
+
name: 'id',
|
|
87
|
+
type: 'string',
|
|
88
|
+
default: '',
|
|
89
|
+
required: true,
|
|
90
|
+
displayOptions: {
|
|
91
|
+
show: {
|
|
92
|
+
operation: ['get', 'update', 'delete'],
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
displayName: 'Name',
|
|
98
|
+
name: 'name',
|
|
99
|
+
type: 'string',
|
|
100
|
+
default: '',
|
|
101
|
+
required: true,
|
|
102
|
+
displayOptions: {
|
|
103
|
+
show: {
|
|
104
|
+
operation: ['create'],
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
displayName: 'Name',
|
|
110
|
+
name: 'name',
|
|
111
|
+
type: 'string',
|
|
112
|
+
default: '',
|
|
113
|
+
displayOptions: {
|
|
114
|
+
show: {
|
|
115
|
+
operation: ['update'],
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
displayName: 'Parent Department ID',
|
|
121
|
+
name: 'parentId',
|
|
122
|
+
type: 'string',
|
|
123
|
+
default: '',
|
|
124
|
+
displayOptions: {
|
|
125
|
+
show: {
|
|
126
|
+
operation: ['create', 'update'],
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
description: 'ID of the parent department (for hierarchy)',
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
displayName: 'Head User ID',
|
|
133
|
+
name: 'headId',
|
|
134
|
+
type: 'string',
|
|
135
|
+
default: '',
|
|
136
|
+
displayOptions: {
|
|
137
|
+
show: {
|
|
138
|
+
operation: ['create', 'update'],
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
description: 'User ID of the Head of Department',
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
displayName: 'Sort',
|
|
145
|
+
name: 'sort',
|
|
146
|
+
type: 'number',
|
|
147
|
+
default: 500,
|
|
148
|
+
displayOptions: {
|
|
149
|
+
show: {
|
|
150
|
+
operation: ['create', 'update'],
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
},
|
|
154
|
+
// List Options
|
|
155
|
+
{
|
|
156
|
+
displayName: 'Return All',
|
|
157
|
+
name: 'returnAll',
|
|
158
|
+
type: 'boolean',
|
|
159
|
+
default: false,
|
|
160
|
+
displayOptions: {
|
|
161
|
+
show: {
|
|
162
|
+
operation: ['list'],
|
|
163
|
+
},
|
|
164
|
+
},
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
displayName: 'Limit',
|
|
168
|
+
name: 'limit',
|
|
169
|
+
type: 'number',
|
|
170
|
+
default: 50,
|
|
171
|
+
displayOptions: {
|
|
172
|
+
show: {
|
|
173
|
+
operation: ['list'],
|
|
174
|
+
returnAll: [false],
|
|
175
|
+
},
|
|
176
|
+
},
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
displayName: 'Filter JSON',
|
|
180
|
+
name: 'filterJson',
|
|
181
|
+
type: 'json',
|
|
182
|
+
default: '{}',
|
|
183
|
+
displayOptions: {
|
|
184
|
+
show: {
|
|
185
|
+
operation: ['list'],
|
|
186
|
+
},
|
|
187
|
+
},
|
|
188
|
+
},
|
|
189
|
+
],
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
async execute() {
|
|
193
|
+
const items = this.getInputData();
|
|
194
|
+
const returnData = [];
|
|
195
|
+
const operation = this.getNodeParameter('operation', 0);
|
|
196
|
+
for (let i = 0; i < items.length; i++) {
|
|
197
|
+
try {
|
|
198
|
+
if (operation === 'list') {
|
|
199
|
+
const returnAll = this.getNodeParameter('returnAll', i);
|
|
200
|
+
const filterJson = this.getNodeParameter('filterJson', i, '{}');
|
|
201
|
+
let filter = {};
|
|
202
|
+
try {
|
|
203
|
+
filter = JSON.parse(filterJson);
|
|
204
|
+
}
|
|
205
|
+
catch (e) { }
|
|
206
|
+
const body = { FILTER: filter, SORT: 'ID' }; // department.get takes SORT params differently usually?
|
|
207
|
+
// Docs: department.get(SORT, ORDER, FILTER) usually. REST API generic usually { 'SORT': 'ASC', ... }
|
|
208
|
+
// department.get arguments: [SORT, ORDER, FILTER]
|
|
209
|
+
// But in batch/json: { SORT: 'ASC', ORDER: 'ASC', ... } or just flatten?
|
|
210
|
+
// Usually Bitrix REST standard is query params or body fields.
|
|
211
|
+
// Let's assume standard object body.
|
|
212
|
+
if (returnAll) {
|
|
213
|
+
// department.get usually returns all unless paginated.
|
|
214
|
+
// It typically returns full tree. Pagination might not be needed for departments (usually < 1000).
|
|
215
|
+
// But for safety, standard limit 50 usually.
|
|
216
|
+
// department.get logic is often "get all" by default in some versions, but let's assume limit.
|
|
217
|
+
// Actually, department.get might NOT support standard navigation?
|
|
218
|
+
// "The method returns list of departments."
|
|
219
|
+
// Let's assume standard behavior first.
|
|
220
|
+
const response = await Helpers_1.bitrixRequestWithRetry.call(this, 'POST', 'department.get.json', body);
|
|
221
|
+
const results = response.result || [];
|
|
222
|
+
for (const item of results) {
|
|
223
|
+
returnData.push({ json: item, pairedItem: { item: i } });
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
else {
|
|
227
|
+
const limit = this.getNodeParameter('limit', i);
|
|
228
|
+
const response = await Helpers_1.bitrixRequestWithRetry.call(this, 'POST', 'department.get.json', body);
|
|
229
|
+
let results = response.result || [];
|
|
230
|
+
if (limit < results.length)
|
|
231
|
+
results = results.slice(0, limit);
|
|
232
|
+
for (const item of results) {
|
|
233
|
+
returnData.push({ json: item, pairedItem: { item: i } });
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
if (operation === 'get') {
|
|
238
|
+
const id = this.getNodeParameter('id', i);
|
|
239
|
+
const body = { ID: id };
|
|
240
|
+
// department.get supports filtering by ID.
|
|
241
|
+
// Or just use list with filter ID.
|
|
242
|
+
const response = await Helpers_1.bitrixRequestWithRetry.call(this, 'POST', 'department.get.json', { ID: id });
|
|
243
|
+
const results = response.result || [];
|
|
244
|
+
if (results.length > 0) {
|
|
245
|
+
returnData.push({ json: results[0], pairedItem: { item: i } });
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
if (operation === 'create') {
|
|
249
|
+
const name = this.getNodeParameter('name', i);
|
|
250
|
+
const parentId = this.getNodeParameter('parentId', i); // Optional?
|
|
251
|
+
const headId = this.getNodeParameter('headId', i);
|
|
252
|
+
const sort = this.getNodeParameter('sort', i);
|
|
253
|
+
const body = { NAME: name, SORT: sort };
|
|
254
|
+
if (parentId)
|
|
255
|
+
body.PARENT = parentId;
|
|
256
|
+
if (headId)
|
|
257
|
+
body.UF_HEAD = headId;
|
|
258
|
+
const response = await Helpers_1.bitrixRequestWithRetry.call(this, 'POST', 'department.add.json', body);
|
|
259
|
+
returnData.push({ json: { id: response.result }, pairedItem: { item: i } });
|
|
260
|
+
}
|
|
261
|
+
if (operation === 'update') {
|
|
262
|
+
const id = this.getNodeParameter('id', i);
|
|
263
|
+
const body = { ID: id };
|
|
264
|
+
const name = this.getNodeParameter('name', i);
|
|
265
|
+
if (name)
|
|
266
|
+
body.NAME = name;
|
|
267
|
+
const parentId = this.getNodeParameter('parentId', i);
|
|
268
|
+
if (parentId)
|
|
269
|
+
body.PARENT = parentId;
|
|
270
|
+
const headId = this.getNodeParameter('headId', i);
|
|
271
|
+
if (headId)
|
|
272
|
+
body.UF_HEAD = headId;
|
|
273
|
+
const sort = this.getNodeParameter('sort', i);
|
|
274
|
+
if (sort)
|
|
275
|
+
body.SORT = sort;
|
|
276
|
+
const response = await Helpers_1.bitrixRequestWithRetry.call(this, 'POST', 'department.update.json', body);
|
|
277
|
+
returnData.push({ json: { success: true, result: response.result }, pairedItem: { item: i } });
|
|
278
|
+
}
|
|
279
|
+
if (operation === 'delete') {
|
|
280
|
+
const id = this.getNodeParameter('id', i);
|
|
281
|
+
const response = await Helpers_1.bitrixRequestWithRetry.call(this, 'POST', 'department.delete.json', { ID: id });
|
|
282
|
+
returnData.push({ json: { success: true, result: response.result }, pairedItem: { item: i } });
|
|
283
|
+
}
|
|
284
|
+
if (operation === 'getTree') {
|
|
285
|
+
// Fetch all flat
|
|
286
|
+
const response = await Helpers_1.bitrixRequestWithRetry.call(this, 'POST', 'department.get.json', {});
|
|
287
|
+
const allDepts = response.result || [];
|
|
288
|
+
// Build tree
|
|
289
|
+
const map = {};
|
|
290
|
+
allDepts.forEach((d) => {
|
|
291
|
+
d.children = [];
|
|
292
|
+
map[d.ID] = d;
|
|
293
|
+
});
|
|
294
|
+
const tree = [];
|
|
295
|
+
allDepts.forEach((d) => {
|
|
296
|
+
if (d.PARENT && map[d.PARENT]) {
|
|
297
|
+
map[d.PARENT].children.push(d);
|
|
298
|
+
}
|
|
299
|
+
else {
|
|
300
|
+
tree.push(d); // Root
|
|
301
|
+
}
|
|
302
|
+
});
|
|
303
|
+
returnData.push({ json: { tree }, pairedItem: { item: i } });
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
catch (error) {
|
|
307
|
+
if (this.continueOnFail()) {
|
|
308
|
+
returnData.push({ json: { error: error.message }, pairedItem: { item: i } });
|
|
309
|
+
continue;
|
|
310
|
+
}
|
|
311
|
+
throw error;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
return [returnData];
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
exports.Bitrix24Department = Bitrix24Department;
|
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Bitrix24 Disk — Нода управления файлами
|
|
4
|
+
*
|
|
5
|
+
* Bitrix24 PRAGMA.by nodes for n8n
|
|
6
|
+
* Профессиональная интеграция с Битрикс24.
|
|
7
|
+
*
|
|
8
|
+
* @author PRAGMA & Азбука Решений
|
|
9
|
+
* @copyright 2026 PRAGMA (https://pragma.by/) & Азбука Решений (https://abc-solution.ru/)
|
|
10
|
+
*
|
|
11
|
+
* Контакты:
|
|
12
|
+
* 🇧🇾 PRAGMA: +375 (44) 702-70-90 | https://pragma.by/
|
|
13
|
+
* 🇷🇺 Азбука Решений: +7 (939) 555-19-60 | https://abc-solution.ru/
|
|
14
|
+
*/
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.Bitrix24Disk = void 0;
|
|
17
|
+
const Helpers_1 = require("../Bitrix24/Helpers");
|
|
18
|
+
class Bitrix24Disk {
|
|
19
|
+
constructor() {
|
|
20
|
+
this.description = {
|
|
21
|
+
displayName: 'Bitrix24 Диск',
|
|
22
|
+
name: 'bitrix24Disk',
|
|
23
|
+
icon: 'file:bitrix24.svg',
|
|
24
|
+
group: ['transform'],
|
|
25
|
+
version: 1,
|
|
26
|
+
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
|
27
|
+
description: 'Управление файлами и папками в облачном хранилище Битрикс24',
|
|
28
|
+
defaults: {
|
|
29
|
+
name: 'Bitrix24 Диск',
|
|
30
|
+
},
|
|
31
|
+
inputs: ['main'],
|
|
32
|
+
outputs: ['main'],
|
|
33
|
+
credentials: [
|
|
34
|
+
{
|
|
35
|
+
name: 'bitrix24Api',
|
|
36
|
+
required: true,
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
properties: [
|
|
40
|
+
{
|
|
41
|
+
displayName: 'Resource',
|
|
42
|
+
name: 'resource',
|
|
43
|
+
type: 'options',
|
|
44
|
+
noDataExpression: true,
|
|
45
|
+
options: [
|
|
46
|
+
{
|
|
47
|
+
name: 'Storage',
|
|
48
|
+
value: 'storage',
|
|
49
|
+
description: 'Manage storages (drives)',
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
name: 'Folder',
|
|
53
|
+
value: 'folder',
|
|
54
|
+
description: 'Manage folders',
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
name: 'File',
|
|
58
|
+
value: 'file',
|
|
59
|
+
description: 'Manage files',
|
|
60
|
+
},
|
|
61
|
+
],
|
|
62
|
+
default: 'folder',
|
|
63
|
+
required: true,
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
displayName: 'Operation',
|
|
67
|
+
name: 'operation',
|
|
68
|
+
type: 'options',
|
|
69
|
+
noDataExpression: true,
|
|
70
|
+
options: [
|
|
71
|
+
{
|
|
72
|
+
name: 'Get',
|
|
73
|
+
value: 'get',
|
|
74
|
+
action: 'Get info',
|
|
75
|
+
displayOptions: {
|
|
76
|
+
show: {
|
|
77
|
+
resource: ['storage', 'folder', 'file'],
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
name: 'Get External Link',
|
|
83
|
+
value: 'getExternalLink',
|
|
84
|
+
action: 'Get public link (File)',
|
|
85
|
+
displayOptions: {
|
|
86
|
+
show: {
|
|
87
|
+
resource: ['file'],
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
name: 'List Children',
|
|
93
|
+
value: 'getchildren',
|
|
94
|
+
action: 'List items in folder/storage',
|
|
95
|
+
displayOptions: {
|
|
96
|
+
show: {
|
|
97
|
+
resource: ['storage', 'folder'],
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
name: 'Create',
|
|
103
|
+
value: 'addsubfolder',
|
|
104
|
+
action: 'Create a subfolder',
|
|
105
|
+
displayOptions: {
|
|
106
|
+
show: {
|
|
107
|
+
resource: ['folder', 'storage'],
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
name: 'Upload File',
|
|
113
|
+
value: 'uploadfile',
|
|
114
|
+
action: 'Upload a file',
|
|
115
|
+
displayOptions: {
|
|
116
|
+
show: {
|
|
117
|
+
resource: ['folder', 'storage'],
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
name: 'Upload Version',
|
|
123
|
+
value: 'uploadVersion',
|
|
124
|
+
action: 'Upload new version of file',
|
|
125
|
+
displayOptions: {
|
|
126
|
+
show: {
|
|
127
|
+
resource: ['file'],
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
name: 'Rename',
|
|
133
|
+
value: 'rename',
|
|
134
|
+
action: 'Rename item',
|
|
135
|
+
displayOptions: {
|
|
136
|
+
show: {
|
|
137
|
+
resource: ['folder', 'file', 'storage'],
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
name: 'Copy',
|
|
143
|
+
value: 'copy',
|
|
144
|
+
action: 'Copy item',
|
|
145
|
+
displayOptions: {
|
|
146
|
+
show: {
|
|
147
|
+
resource: ['folder', 'file'],
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
name: 'Move',
|
|
153
|
+
value: 'move',
|
|
154
|
+
action: 'Move item',
|
|
155
|
+
displayOptions: {
|
|
156
|
+
show: {
|
|
157
|
+
resource: ['folder', 'file'],
|
|
158
|
+
},
|
|
159
|
+
},
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
name: 'Delete',
|
|
163
|
+
value: 'delete',
|
|
164
|
+
action: 'Delete item',
|
|
165
|
+
displayOptions: {
|
|
166
|
+
show: {
|
|
167
|
+
resource: ['folder', 'file'],
|
|
168
|
+
},
|
|
169
|
+
},
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
name: 'Get Permissions',
|
|
173
|
+
value: 'getPermissions',
|
|
174
|
+
action: 'Get access rights',
|
|
175
|
+
displayOptions: {
|
|
176
|
+
show: {
|
|
177
|
+
resource: ['folder'],
|
|
178
|
+
},
|
|
179
|
+
},
|
|
180
|
+
},
|
|
181
|
+
],
|
|
182
|
+
default: 'getchildren',
|
|
183
|
+
required: true,
|
|
184
|
+
},
|
|
185
|
+
// Fields
|
|
186
|
+
{
|
|
187
|
+
displayName: 'ID',
|
|
188
|
+
name: 'id',
|
|
189
|
+
type: 'string',
|
|
190
|
+
default: '',
|
|
191
|
+
required: true,
|
|
192
|
+
displayOptions: {
|
|
193
|
+
show: {
|
|
194
|
+
operation: ['get', 'getchildren', 'addsubfolder', 'uploadfile', 'rename', 'delete', 'getExternalLink', 'copy', 'move'],
|
|
195
|
+
},
|
|
196
|
+
},
|
|
197
|
+
description: 'ID of the storage, folder or file',
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
displayName: 'Name',
|
|
201
|
+
name: 'name',
|
|
202
|
+
type: 'string',
|
|
203
|
+
default: '',
|
|
204
|
+
displayOptions: {
|
|
205
|
+
show: {
|
|
206
|
+
operation: ['rename', 'addsubfolder'],
|
|
207
|
+
},
|
|
208
|
+
},
|
|
209
|
+
description: 'New name',
|
|
210
|
+
},
|
|
211
|
+
{
|
|
212
|
+
displayName: 'File Content (Base64)',
|
|
213
|
+
name: 'fileContent',
|
|
214
|
+
type: 'string',
|
|
215
|
+
default: '',
|
|
216
|
+
displayOptions: {
|
|
217
|
+
show: {
|
|
218
|
+
operation: ['uploadfile', 'uploadVersion'],
|
|
219
|
+
},
|
|
220
|
+
},
|
|
221
|
+
description: 'Base64 encoded file content',
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
displayName: 'File Name',
|
|
225
|
+
name: 'fileName',
|
|
226
|
+
type: 'string',
|
|
227
|
+
default: '',
|
|
228
|
+
displayOptions: {
|
|
229
|
+
show: {
|
|
230
|
+
operation: ['uploadfile'], // Name usually taken from existing file or ignored in version update?
|
|
231
|
+
// actually disk.file.uploadversion doesn't strictly need name if updating content, but good to have if renaming.
|
|
232
|
+
// Docs: disk.file.uploadversion requires id, fileContent.
|
|
233
|
+
},
|
|
234
|
+
},
|
|
235
|
+
description: 'Name of the file to create',
|
|
236
|
+
},
|
|
237
|
+
{
|
|
238
|
+
displayName: 'Target Folder ID',
|
|
239
|
+
name: 'targetFolderId',
|
|
240
|
+
type: 'string',
|
|
241
|
+
default: '',
|
|
242
|
+
displayOptions: {
|
|
243
|
+
show: {
|
|
244
|
+
operation: ['copy', 'move'],
|
|
245
|
+
},
|
|
246
|
+
},
|
|
247
|
+
description: 'ID of the destination folder',
|
|
248
|
+
required: true,
|
|
249
|
+
},
|
|
250
|
+
],
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
async execute() {
|
|
254
|
+
const items = this.getInputData();
|
|
255
|
+
const returnData = [];
|
|
256
|
+
const resource = this.getNodeParameter('resource', 0);
|
|
257
|
+
const operation = this.getNodeParameter('operation', 0);
|
|
258
|
+
for (let i = 0; i < items.length; i++) {
|
|
259
|
+
try {
|
|
260
|
+
let endpoint = `disk.${resource}.${operation}`;
|
|
261
|
+
const id = this.getNodeParameter('id', i);
|
|
262
|
+
let body = { id };
|
|
263
|
+
if (operation === 'addsubfolder') {
|
|
264
|
+
const name = this.getNodeParameter('name', i);
|
|
265
|
+
body.data = { NAME: name };
|
|
266
|
+
}
|
|
267
|
+
if (operation === 'rename') {
|
|
268
|
+
const name = this.getNodeParameter('name', i);
|
|
269
|
+
body.newName = name;
|
|
270
|
+
}
|
|
271
|
+
if (operation === 'uploadfile') {
|
|
272
|
+
const fileContent = this.getNodeParameter('fileContent', i);
|
|
273
|
+
const fileName = this.getNodeParameter('fileName', i);
|
|
274
|
+
body.fileContent = fileContent;
|
|
275
|
+
body.data = { NAME: fileName };
|
|
276
|
+
}
|
|
277
|
+
if (operation === 'uploadVersion') {
|
|
278
|
+
endpoint = 'disk.file.uploadversion';
|
|
279
|
+
const fileContent = this.getNodeParameter('fileContent', i);
|
|
280
|
+
body.fileContent = fileContent;
|
|
281
|
+
}
|
|
282
|
+
if (operation === 'getExternalLink') {
|
|
283
|
+
endpoint = `disk.${resource}.getexternallink`;
|
|
284
|
+
}
|
|
285
|
+
if (operation === 'copy' || operation === 'move') {
|
|
286
|
+
endpoint = `disk.${resource}.${operation}to`;
|
|
287
|
+
const targetFolderId = this.getNodeParameter('targetFolderId', i);
|
|
288
|
+
body.targetFolderId = targetFolderId;
|
|
289
|
+
}
|
|
290
|
+
if (operation === 'getPermissions') {
|
|
291
|
+
// Only for folders? Files might not have separate rights (inherit).
|
|
292
|
+
// disk.folder.getFields usually returns RIGHTS
|
|
293
|
+
// API might need 'disk.folder.get' with show rights?
|
|
294
|
+
const response = await Helpers_1.bitrixRequestWithRetry.call(this, 'POST', `disk.${resource}.get`, { id });
|
|
295
|
+
const resultObj = response.result;
|
|
296
|
+
const rights = resultObj?.RIGHTS || {};
|
|
297
|
+
returnData.push({ json: { rights }, pairedItem: { item: i } });
|
|
298
|
+
continue; // Return just rights
|
|
299
|
+
}
|
|
300
|
+
// Special handling for upload, it needs proper endpoint sometimes depending on context (folder vs storage)
|
|
301
|
+
// Docs: disk.folder.uploadfile vs disk.storage.uploadfile. Both exist. My code uses disk.${resource}.${operation} which works.
|
|
302
|
+
const response = await Helpers_1.bitrixRequestWithRetry.call(this, 'POST', endpoint + '.json', body);
|
|
303
|
+
let result = response.result;
|
|
304
|
+
if (Array.isArray(result)) {
|
|
305
|
+
for (const item of result) {
|
|
306
|
+
returnData.push({
|
|
307
|
+
json: item,
|
|
308
|
+
pairedItem: { item: i },
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
else {
|
|
313
|
+
returnData.push({
|
|
314
|
+
json: result,
|
|
315
|
+
pairedItem: { item: i },
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
catch (error) {
|
|
320
|
+
if (this.continueOnFail()) {
|
|
321
|
+
const err = error;
|
|
322
|
+
returnData.push({
|
|
323
|
+
json: { error: err.message },
|
|
324
|
+
pairedItem: { item: i },
|
|
325
|
+
});
|
|
326
|
+
continue;
|
|
327
|
+
}
|
|
328
|
+
throw error;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
return [returnData];
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
exports.Bitrix24Disk = Bitrix24Disk;
|