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,280 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Bitrix24 Document — Нода генерации документов
|
|
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.Bitrix24Document = void 0;
|
|
17
|
+
const Helpers_1 = require("../Bitrix24/Helpers");
|
|
18
|
+
class Bitrix24Document {
|
|
19
|
+
constructor() {
|
|
20
|
+
this.description = {
|
|
21
|
+
displayName: 'Bitrix24 Документы',
|
|
22
|
+
name: 'bitrix24Document',
|
|
23
|
+
icon: 'file:bitrix24.svg',
|
|
24
|
+
group: ['transform'],
|
|
25
|
+
version: 1,
|
|
26
|
+
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
|
27
|
+
description: 'Генерация документов по шаблонам из CRM-сущностей',
|
|
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: 'Document',
|
|
48
|
+
value: 'document',
|
|
49
|
+
description: 'Manage generated documents',
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
name: 'Template',
|
|
53
|
+
value: 'template',
|
|
54
|
+
description: 'Manage document templates',
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
default: 'document',
|
|
58
|
+
required: true,
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
displayName: 'Operation',
|
|
62
|
+
name: 'operation',
|
|
63
|
+
type: 'options',
|
|
64
|
+
noDataExpression: true,
|
|
65
|
+
options: [
|
|
66
|
+
// Document
|
|
67
|
+
{
|
|
68
|
+
name: 'Generate',
|
|
69
|
+
value: 'generate', // documentgenerator.document.add
|
|
70
|
+
action: 'Generate a new document',
|
|
71
|
+
displayOptions: { show: { resource: ['document'] } },
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
name: 'Get Public URL',
|
|
75
|
+
value: 'getPublicUrl', // documentgenerator.document.getpublicurl
|
|
76
|
+
action: 'Get public link (PDF/Word)',
|
|
77
|
+
displayOptions: { show: { resource: ['document'] } },
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
name: 'List',
|
|
81
|
+
value: 'list', // documentgenerator.document.list
|
|
82
|
+
action: 'List generated documents',
|
|
83
|
+
displayOptions: { show: { resource: ['document'] } },
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
name: 'Download',
|
|
87
|
+
value: 'download',
|
|
88
|
+
action: 'Download document (PDF/Word)',
|
|
89
|
+
displayOptions: { show: { resource: ['document'] } },
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
name: 'Delete',
|
|
93
|
+
value: 'delete', // documentgenerator.document.delete ? No, check docs. usually delete.
|
|
94
|
+
// Docs: documentgenerator.document.delete doesn't explicitly exist in some versions, check.
|
|
95
|
+
// Assuming standard CRUD. If not, we skip.
|
|
96
|
+
// Actually documentgenerator.document.delete EXISTS.
|
|
97
|
+
action: 'Delete document',
|
|
98
|
+
displayOptions: { show: { resource: ['document'] } },
|
|
99
|
+
},
|
|
100
|
+
// Template
|
|
101
|
+
{
|
|
102
|
+
name: 'List',
|
|
103
|
+
value: 'list', // documentgenerator.template.list
|
|
104
|
+
action: 'List available templates',
|
|
105
|
+
displayOptions: { show: { resource: ['template'] } },
|
|
106
|
+
},
|
|
107
|
+
],
|
|
108
|
+
default: 'generate',
|
|
109
|
+
required: true,
|
|
110
|
+
},
|
|
111
|
+
// ----------------------------------
|
|
112
|
+
// Fields for Document Generate
|
|
113
|
+
// ----------------------------------
|
|
114
|
+
{
|
|
115
|
+
displayName: 'Template ID',
|
|
116
|
+
name: 'templateId',
|
|
117
|
+
type: 'string', // Actually number
|
|
118
|
+
default: '',
|
|
119
|
+
displayOptions: { show: { resource: ['document'], operation: ['generate'] } },
|
|
120
|
+
required: true,
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
displayName: 'Entity Type',
|
|
124
|
+
name: 'entityType',
|
|
125
|
+
type: 'options', // Changed to options for usability
|
|
126
|
+
options: [
|
|
127
|
+
{ name: 'Deal', value: 'CRM_DEAL' },
|
|
128
|
+
{ name: 'Lead', value: 'CRM_LEAD' },
|
|
129
|
+
{ name: 'Contact', value: 'CRM_CONTACT' },
|
|
130
|
+
{ name: 'Company', value: 'CRM_COMPANY' },
|
|
131
|
+
{ name: 'Invoice', value: 'CRM_INVOICE' },
|
|
132
|
+
{ name: 'Quote', value: 'CRM_QUOTE' },
|
|
133
|
+
{ name: 'Smart Process (Dynamic)', value: 'dynamic' }, // User provides numeric ID separately? Or just raw string.
|
|
134
|
+
],
|
|
135
|
+
default: 'CRM_DEAL',
|
|
136
|
+
displayOptions: { show: { resource: ['document', 'template'], operation: ['generate', 'list'] } },
|
|
137
|
+
required: true,
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
displayName: 'Entity Type ID (Number)',
|
|
141
|
+
name: 'entityTypeIdNum',
|
|
142
|
+
type: 'number',
|
|
143
|
+
default: 0,
|
|
144
|
+
displayOptions: {
|
|
145
|
+
show: {
|
|
146
|
+
resource: ['document', 'template'],
|
|
147
|
+
operation: ['generate', 'list'],
|
|
148
|
+
entityType: ['dynamic'],
|
|
149
|
+
}
|
|
150
|
+
},
|
|
151
|
+
description: 'For Smart Processes, enter the Numeric Entity Type ID (e.g. 150)',
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
displayName: 'Entity ID',
|
|
155
|
+
name: 'entityId',
|
|
156
|
+
type: 'string',
|
|
157
|
+
default: '',
|
|
158
|
+
displayOptions: { show: { resource: ['document'], operation: ['generate', 'list'] } }, // List can filter by entityId
|
|
159
|
+
required: true,
|
|
160
|
+
description: 'ID of the specific Deal, Lead, etc.',
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
displayName: 'Values (JSON)',
|
|
164
|
+
name: 'values',
|
|
165
|
+
type: 'json',
|
|
166
|
+
default: '{}',
|
|
167
|
+
displayOptions: { show: { resource: ['document'], operation: ['generate'] } },
|
|
168
|
+
description: 'Dynamic values for placeholders. E.g. {"MyPlaceholder": "Value"}',
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
displayName: 'Number',
|
|
172
|
+
name: 'number',
|
|
173
|
+
type: 'string',
|
|
174
|
+
default: '',
|
|
175
|
+
displayOptions: { show: { resource: ['document'], operation: ['generate'] } },
|
|
176
|
+
description: 'Document number',
|
|
177
|
+
},
|
|
178
|
+
// ----------------------------------
|
|
179
|
+
// Fields for Document Get/PublicUrl/Download/Delete
|
|
180
|
+
// ----------------------------------
|
|
181
|
+
{
|
|
182
|
+
displayName: 'Document ID',
|
|
183
|
+
name: 'documentId',
|
|
184
|
+
type: 'string',
|
|
185
|
+
default: '',
|
|
186
|
+
displayOptions: { show: { resource: ['document'], operation: ['get', 'getPublicUrl', 'download', 'delete'] } },
|
|
187
|
+
required: true,
|
|
188
|
+
},
|
|
189
|
+
// ----------------------------------
|
|
190
|
+
// Fields for Template List
|
|
191
|
+
// ----------------------------------
|
|
192
|
+
{
|
|
193
|
+
displayName: 'Entity Type Name',
|
|
194
|
+
name: 'entityType',
|
|
195
|
+
type: 'string',
|
|
196
|
+
default: '',
|
|
197
|
+
displayOptions: { show: { resource: ['template'], operation: ['list'] } },
|
|
198
|
+
description: 'Filter by entity type (e.g. CRM_DEAL)',
|
|
199
|
+
},
|
|
200
|
+
],
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
async execute() {
|
|
204
|
+
const items = this.getInputData();
|
|
205
|
+
const returnData = [];
|
|
206
|
+
const resource = this.getNodeParameter('resource', 0);
|
|
207
|
+
const operation = this.getNodeParameter('operation', 0);
|
|
208
|
+
for (let i = 0; i < items.length; i++) {
|
|
209
|
+
try {
|
|
210
|
+
let endpoint = '';
|
|
211
|
+
let body = {};
|
|
212
|
+
if (resource === 'document') {
|
|
213
|
+
if (operation === 'generate') {
|
|
214
|
+
endpoint = 'documentgenerator.document.add';
|
|
215
|
+
body.templateId = this.getNodeParameter('templateId', i);
|
|
216
|
+
body.entityTypeId = this.getNodeParameter('entityType', i); // Bitrix param is entityTypeId: 'CRM_DEAL' ? No.
|
|
217
|
+
// Checking docs: documentgenerator.document.add params: templateId, entityTypeId, entityId, values, fields
|
|
218
|
+
// entityTypeId is confusing in docs, sometimes it's number, sometimes 'CRM_DEAL'.
|
|
219
|
+
// Actually documentgenerator uses provider concept. Usually 'crm'.
|
|
220
|
+
// Let's rely on user inputting 'CRM_DEAL'.
|
|
221
|
+
body.entityTypeId = this.getNodeParameter('entityType', i);
|
|
222
|
+
body.entityId = this.getNodeParameter('entityId', i);
|
|
223
|
+
const values = this.getNodeParameter('values', i, '');
|
|
224
|
+
if (values) {
|
|
225
|
+
if (typeof values === 'string')
|
|
226
|
+
body.values = JSON.parse(values);
|
|
227
|
+
else
|
|
228
|
+
body.values = values;
|
|
229
|
+
}
|
|
230
|
+
const number = this.getNodeParameter('number', i, '');
|
|
231
|
+
if (number) {
|
|
232
|
+
body.fields = { Number: number };
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
else if (operation === 'getPublicUrl') {
|
|
236
|
+
endpoint = 'documentgenerator.document.getpublicurl';
|
|
237
|
+
body.id = this.getNodeParameter('documentId', i);
|
|
238
|
+
}
|
|
239
|
+
else if (operation === 'get') {
|
|
240
|
+
endpoint = 'documentgenerator.document.get';
|
|
241
|
+
body.id = this.getNodeParameter('documentId', i);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
else if (resource === 'template') {
|
|
245
|
+
if (operation === 'list') {
|
|
246
|
+
endpoint = 'documentgenerator.template.list';
|
|
247
|
+
const entityType = this.getNodeParameter('entityType', i, '');
|
|
248
|
+
if (entityType) {
|
|
249
|
+
body.filter = { module: 'crm', entityTypeId: entityType }; // Approximate filter
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
const response = await Helpers_1.bitrixRequestWithRetry.call(this, 'POST', endpoint, body);
|
|
254
|
+
let result = response.result;
|
|
255
|
+
const resultObj = result;
|
|
256
|
+
if (resource === 'document' && operation === 'generate' && resultObj?.documentId) {
|
|
257
|
+
// Add helpful field
|
|
258
|
+
result = resultObj; // it returns { documentId: 105, url: ..., publicUrl: ... } usually?
|
|
259
|
+
// API add returns { documentId: 123, ... }
|
|
260
|
+
// We can auto-fetch public url? No, keep it atomic.
|
|
261
|
+
}
|
|
262
|
+
if (Array.isArray(result)) {
|
|
263
|
+
result.forEach((item) => returnData.push({ json: item, pairedItem: { item: i } }));
|
|
264
|
+
}
|
|
265
|
+
else {
|
|
266
|
+
returnData.push({ json: result, pairedItem: { item: i } });
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
catch (error) {
|
|
270
|
+
if (this.continueOnFail()) {
|
|
271
|
+
returnData.push({ json: { error: error.message }, pairedItem: { item: i } });
|
|
272
|
+
continue;
|
|
273
|
+
}
|
|
274
|
+
throw error;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
return [returnData];
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
exports.Bitrix24Document = Bitrix24Document;
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Bitrix24 Entity — Нода хранилища данных приложения
|
|
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.Bitrix24Entity = void 0;
|
|
17
|
+
const Helpers_1 = require("../Bitrix24/Helpers");
|
|
18
|
+
class Bitrix24Entity {
|
|
19
|
+
constructor() {
|
|
20
|
+
this.description = {
|
|
21
|
+
displayName: 'Bitrix24 Хранилище',
|
|
22
|
+
name: 'bitrix24Entity',
|
|
23
|
+
icon: 'file:bitrix24.svg',
|
|
24
|
+
group: ['transform'],
|
|
25
|
+
version: 1,
|
|
26
|
+
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
|
|
27
|
+
description: 'Хранилище данных приложения (Entity): свойства и значения',
|
|
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: 'Item',
|
|
48
|
+
value: 'item',
|
|
49
|
+
description: 'Storage items',
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
name: 'Entity (Storage)',
|
|
53
|
+
value: 'entity',
|
|
54
|
+
description: 'Storage containers',
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
default: 'item',
|
|
58
|
+
required: true,
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
displayName: 'Operation',
|
|
62
|
+
name: 'operation',
|
|
63
|
+
type: 'options',
|
|
64
|
+
noDataExpression: true,
|
|
65
|
+
options: [
|
|
66
|
+
{
|
|
67
|
+
name: 'List',
|
|
68
|
+
value: 'list',
|
|
69
|
+
action: 'List items',
|
|
70
|
+
displayOptions: {
|
|
71
|
+
show: {
|
|
72
|
+
resource: ['item', 'entity'],
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
name: 'Add',
|
|
78
|
+
value: 'add',
|
|
79
|
+
action: 'Add item',
|
|
80
|
+
displayOptions: {
|
|
81
|
+
show: {
|
|
82
|
+
resource: ['item', 'entity'],
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
name: 'Get',
|
|
88
|
+
value: 'get',
|
|
89
|
+
action: 'Get item',
|
|
90
|
+
displayOptions: {
|
|
91
|
+
show: {
|
|
92
|
+
resource: ['item'], // entity get not standard, usually list
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
name: 'Update',
|
|
98
|
+
value: 'update',
|
|
99
|
+
action: 'Update item',
|
|
100
|
+
displayOptions: {
|
|
101
|
+
show: {
|
|
102
|
+
resource: ['item', 'entity'], // entity update rights
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
name: 'Delete',
|
|
108
|
+
value: 'delete',
|
|
109
|
+
action: 'Delete item',
|
|
110
|
+
displayOptions: {
|
|
111
|
+
show: {
|
|
112
|
+
resource: ['item', 'entity'],
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
],
|
|
117
|
+
default: 'list',
|
|
118
|
+
required: true,
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
displayName: 'Entity ID (Storage Name)',
|
|
122
|
+
name: 'entityId',
|
|
123
|
+
type: 'string',
|
|
124
|
+
default: '',
|
|
125
|
+
required: true,
|
|
126
|
+
displayOptions: {
|
|
127
|
+
show: {
|
|
128
|
+
resource: ['item', 'entity'],
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
description: 'Name of the storage container (ENTITY)',
|
|
132
|
+
},
|
|
133
|
+
// Item Fields
|
|
134
|
+
{
|
|
135
|
+
displayName: 'Item ID',
|
|
136
|
+
name: 'itemId',
|
|
137
|
+
type: 'string',
|
|
138
|
+
default: '',
|
|
139
|
+
required: true,
|
|
140
|
+
displayOptions: {
|
|
141
|
+
show: {
|
|
142
|
+
resource: ['item'],
|
|
143
|
+
operation: ['get', 'update', 'delete'],
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
displayName: 'Fields JSON',
|
|
149
|
+
name: 'fieldsJson',
|
|
150
|
+
type: 'json',
|
|
151
|
+
default: '{}',
|
|
152
|
+
description: 'Item fields (NAME, PROPERTY_VALUES, etc.)',
|
|
153
|
+
displayOptions: {
|
|
154
|
+
show: {
|
|
155
|
+
resource: ['item'],
|
|
156
|
+
operation: ['add', 'update'],
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
},
|
|
160
|
+
// Entity Fields
|
|
161
|
+
{
|
|
162
|
+
displayName: 'Entity Name',
|
|
163
|
+
name: 'name',
|
|
164
|
+
type: 'string',
|
|
165
|
+
default: '',
|
|
166
|
+
displayOptions: {
|
|
167
|
+
show: {
|
|
168
|
+
resource: ['entity'],
|
|
169
|
+
operation: ['add'],
|
|
170
|
+
},
|
|
171
|
+
},
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
displayName: 'Access Rights JSON',
|
|
175
|
+
name: 'accessJson',
|
|
176
|
+
type: 'json',
|
|
177
|
+
default: '{}',
|
|
178
|
+
displayOptions: {
|
|
179
|
+
show: {
|
|
180
|
+
resource: ['entity'],
|
|
181
|
+
operation: ['add', 'update'],
|
|
182
|
+
},
|
|
183
|
+
},
|
|
184
|
+
description: 'Example: {"AU": "W"} for All Users Write',
|
|
185
|
+
},
|
|
186
|
+
],
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
async execute() {
|
|
190
|
+
const items = this.getInputData();
|
|
191
|
+
const returnData = [];
|
|
192
|
+
const resource = this.getNodeParameter('resource', 0);
|
|
193
|
+
const operation = this.getNodeParameter('operation', 0);
|
|
194
|
+
for (let i = 0; i < items.length; i++) {
|
|
195
|
+
try {
|
|
196
|
+
const entityId = this.getNodeParameter('entityId', i);
|
|
197
|
+
if (resource === 'entity') {
|
|
198
|
+
if (operation === 'list') {
|
|
199
|
+
const response = await Helpers_1.bitrixRequestWithRetry.call(this, 'POST', 'entity.get.json', {});
|
|
200
|
+
// entity.get returns list of entities
|
|
201
|
+
const results = response.result || [];
|
|
202
|
+
for (const item of results) {
|
|
203
|
+
returnData.push({ json: item, pairedItem: { item: i } });
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
if (operation === 'add') {
|
|
207
|
+
const name = this.getNodeParameter('name', i);
|
|
208
|
+
const access = this.getNodeParameter('accessJson', i, '{}');
|
|
209
|
+
const body = { ENTITY: entityId, NAME: name, ACCESS: JSON.parse(access) };
|
|
210
|
+
const response = await Helpers_1.bitrixRequestWithRetry.call(this, 'POST', 'entity.add.json', body);
|
|
211
|
+
returnData.push({ json: { result: response.result }, pairedItem: { item: i } });
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
if (resource === 'item') {
|
|
215
|
+
if (operation === 'list') {
|
|
216
|
+
const body = { ENTITY: entityId, SORT: { DATE_ACTIVE_FROM: 'ASC' } };
|
|
217
|
+
const response = await Helpers_1.bitrixRequestWithRetry.call(this, 'POST', 'entity.item.get.json', body);
|
|
218
|
+
const results = response.result || [];
|
|
219
|
+
for (const item of results) {
|
|
220
|
+
returnData.push({ json: item, pairedItem: { item: i } });
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
if (operation === 'add') {
|
|
224
|
+
const property = this.getNodeParameter('property', i);
|
|
225
|
+
const value = this.getNodeParameter('value', i);
|
|
226
|
+
// entity.item.add parameters: ENTITY, NAME (Name of item), PROPERTY_...??
|
|
227
|
+
// NO. entity.item.add takes NAME, DATE_ACTIVE_FROM, DATE_ACTIVE_TO, PREVIEW_PICTURE, DETAIL_PICTURE, PROPERTY_VALUES.
|
|
228
|
+
// Wait, entity.item is flexible.
|
|
229
|
+
// Let's assume standard simple usage: Key-Value storage often uses 'NAME' as key or custom property.
|
|
230
|
+
// Simplest: Name = Key.
|
|
231
|
+
const body = {
|
|
232
|
+
ENTITY: entityId,
|
|
233
|
+
NAME: property, // Using 'property' input as Name/Key
|
|
234
|
+
PROPERTY_VALUES: {
|
|
235
|
+
value: value // Assuming a property 'value' exists? Or creating generic properties?
|
|
236
|
+
// 'entity' requires defined properties usually via entity.add -> or entity.update.
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
// Actually, better to just let user pass JSON for properties if advanced.
|
|
240
|
+
// For simple KV, we might need to assume 'name' and 'preview_text'.
|
|
241
|
+
// Let's stick to simple NAME for now.
|
|
242
|
+
// Correction: entity.item.add needs properties defined on the entity first?
|
|
243
|
+
// Yes, usually.
|
|
244
|
+
// But for simple usage, maybe just JSON body?
|
|
245
|
+
// Let's add 'jsonBody' for flexibility.
|
|
246
|
+
// Let's simplify: Just allow passing JSON fields.
|
|
247
|
+
// Re-thinking inputs: Remove 'property'/'value' and just use 'fieldsJson'.
|
|
248
|
+
// Much safer for generic entity.
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
catch (error) {
|
|
253
|
+
if (this.continueOnFail()) {
|
|
254
|
+
returnData.push({ json: { error: error.message }, pairedItem: { item: i } });
|
|
255
|
+
continue;
|
|
256
|
+
}
|
|
257
|
+
throw error;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
return [returnData];
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
exports.Bitrix24Entity = Bitrix24Entity;
|