@dnet5/n8n-nodes-resend 0.1.3

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.
Files changed (48) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +56 -0
  3. package/dist/credentials/ResendApi.credentials.d.ts +10 -0
  4. package/dist/credentials/ResendApi.credentials.js +39 -0
  5. package/dist/credentials/ResendApi.credentials.js.map +1 -0
  6. package/dist/credentials/resend.svg +9 -0
  7. package/dist/nodes/Resend/GenericFunctions.d.ts +3 -0
  8. package/dist/nodes/Resend/GenericFunctions.js +43 -0
  9. package/dist/nodes/Resend/GenericFunctions.js.map +1 -0
  10. package/dist/nodes/Resend/Resend.node.d.ts +5 -0
  11. package/dist/nodes/Resend/Resend.node.js +616 -0
  12. package/dist/nodes/Resend/Resend.node.js.map +1 -0
  13. package/dist/nodes/Resend/Resend.node.json +17 -0
  14. package/dist/nodes/Resend/descriptions/ApiKeyDescription.d.ts +3 -0
  15. package/dist/nodes/Resend/descriptions/ApiKeyDescription.js +135 -0
  16. package/dist/nodes/Resend/descriptions/ApiKeyDescription.js.map +1 -0
  17. package/dist/nodes/Resend/descriptions/BroadcastDescription.d.ts +3 -0
  18. package/dist/nodes/Resend/descriptions/BroadcastDescription.js +337 -0
  19. package/dist/nodes/Resend/descriptions/BroadcastDescription.js.map +1 -0
  20. package/dist/nodes/Resend/descriptions/ContactDescription.d.ts +3 -0
  21. package/dist/nodes/Resend/descriptions/ContactDescription.js +290 -0
  22. package/dist/nodes/Resend/descriptions/ContactDescription.js.map +1 -0
  23. package/dist/nodes/Resend/descriptions/ContactPropertyDescription.d.ts +3 -0
  24. package/dist/nodes/Resend/descriptions/ContactPropertyDescription.js +198 -0
  25. package/dist/nodes/Resend/descriptions/ContactPropertyDescription.js.map +1 -0
  26. package/dist/nodes/Resend/descriptions/DomainDescription.d.ts +3 -0
  27. package/dist/nodes/Resend/descriptions/DomainDescription.js +273 -0
  28. package/dist/nodes/Resend/descriptions/DomainDescription.js.map +1 -0
  29. package/dist/nodes/Resend/descriptions/EmailDescription.d.ts +3 -0
  30. package/dist/nodes/Resend/descriptions/EmailDescription.js +422 -0
  31. package/dist/nodes/Resend/descriptions/EmailDescription.js.map +1 -0
  32. package/dist/nodes/Resend/descriptions/SegmentDescription.d.ts +3 -0
  33. package/dist/nodes/Resend/descriptions/SegmentDescription.js +158 -0
  34. package/dist/nodes/Resend/descriptions/SegmentDescription.js.map +1 -0
  35. package/dist/nodes/Resend/descriptions/TemplateDescription.d.ts +3 -0
  36. package/dist/nodes/Resend/descriptions/TemplateDescription.js +318 -0
  37. package/dist/nodes/Resend/descriptions/TemplateDescription.js.map +1 -0
  38. package/dist/nodes/Resend/descriptions/TopicDescription.d.ts +3 -0
  39. package/dist/nodes/Resend/descriptions/TopicDescription.js +242 -0
  40. package/dist/nodes/Resend/descriptions/TopicDescription.js.map +1 -0
  41. package/dist/nodes/Resend/descriptions/WebhookDescription.d.ts +3 -0
  42. package/dist/nodes/Resend/descriptions/WebhookDescription.js +214 -0
  43. package/dist/nodes/Resend/descriptions/WebhookDescription.js.map +1 -0
  44. package/dist/nodes/Resend/descriptions/index.d.ts +10 -0
  45. package/dist/nodes/Resend/descriptions/index.js +34 -0
  46. package/dist/nodes/Resend/descriptions/index.js.map +1 -0
  47. package/dist/nodes/Resend/resend.svg +9 -0
  48. package/package.json +53 -0
@@ -0,0 +1,616 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Resend = void 0;
4
+ const n8n_workflow_1 = require("n8n-workflow");
5
+ const GenericFunctions_1 = require("./GenericFunctions");
6
+ const descriptions_1 = require("./descriptions");
7
+ class Resend {
8
+ constructor() {
9
+ this.description = {
10
+ displayName: 'Resend',
11
+ name: 'resend',
12
+ icon: 'file:resend.svg',
13
+ group: ['transform'],
14
+ version: 1,
15
+ subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
16
+ description: 'Interact with the Resend API',
17
+ defaults: {
18
+ name: 'Resend',
19
+ },
20
+ inputs: [n8n_workflow_1.NodeConnectionTypes.Main],
21
+ outputs: [n8n_workflow_1.NodeConnectionTypes.Main],
22
+ usableAsTool: true,
23
+ credentials: [
24
+ {
25
+ name: 'resendApi',
26
+ required: true,
27
+ },
28
+ ],
29
+ properties: [
30
+ {
31
+ displayName: 'Resource',
32
+ name: 'resource',
33
+ type: 'options',
34
+ noDataExpression: true,
35
+ options: [
36
+ { name: 'API Key', value: 'apiKey' },
37
+ { name: 'Broadcast', value: 'broadcast' },
38
+ { name: 'Contact', value: 'contact' },
39
+ { name: 'Contact Property', value: 'contactProperty' },
40
+ { name: 'Domain', value: 'domain' },
41
+ { name: 'Email', value: 'email' },
42
+ { name: 'Segment', value: 'segment' },
43
+ { name: 'Template', value: 'template' },
44
+ { name: 'Topic', value: 'topic' },
45
+ { name: 'Webhook', value: 'webhook' },
46
+ ],
47
+ default: 'email',
48
+ },
49
+ ...descriptions_1.emailOperations,
50
+ ...descriptions_1.emailFields,
51
+ ...descriptions_1.domainOperations,
52
+ ...descriptions_1.domainFields,
53
+ ...descriptions_1.apiKeyOperations,
54
+ ...descriptions_1.apiKeyFields,
55
+ ...descriptions_1.contactOperations,
56
+ ...descriptions_1.contactFields,
57
+ ...descriptions_1.broadcastOperations,
58
+ ...descriptions_1.broadcastFields,
59
+ ...descriptions_1.segmentOperations,
60
+ ...descriptions_1.segmentFields,
61
+ ...descriptions_1.topicOperations,
62
+ ...descriptions_1.topicFields,
63
+ ...descriptions_1.templateOperations,
64
+ ...descriptions_1.templateFields,
65
+ ...descriptions_1.webhookOperations,
66
+ ...descriptions_1.webhookFields,
67
+ ...descriptions_1.contactPropertyOperations,
68
+ ...descriptions_1.contactPropertyFields,
69
+ ],
70
+ };
71
+ }
72
+ async execute() {
73
+ const items = this.getInputData();
74
+ const returnData = [];
75
+ const resource = this.getNodeParameter('resource', 0);
76
+ const operation = this.getNodeParameter('operation', 0);
77
+ for (let i = 0; i < items.length; i++) {
78
+ try {
79
+ let responseData;
80
+ // ──────────────────── EMAIL ────────────────────
81
+ if (resource === 'email') {
82
+ if (operation === 'send') {
83
+ const body = {
84
+ from: this.getNodeParameter('from', i),
85
+ to: this.getNodeParameter('to', i)
86
+ .split(',')
87
+ .map((e) => e.trim()),
88
+ subject: this.getNodeParameter('subject', i),
89
+ };
90
+ const additionalFields = this.getNodeParameter('additionalFields', i);
91
+ const headers = {};
92
+ if (additionalFields.html)
93
+ body.html = additionalFields.html;
94
+ if (additionalFields.text)
95
+ body.text = additionalFields.text;
96
+ if (additionalFields.scheduled_at)
97
+ body.scheduled_at = additionalFields.scheduled_at;
98
+ if (additionalFields.template_id)
99
+ body.template_id = additionalFields.template_id;
100
+ if (additionalFields.topic_id)
101
+ body.topic_id = additionalFields.topic_id;
102
+ if (additionalFields.template_variables) {
103
+ body.template_variables =
104
+ typeof additionalFields.template_variables === 'string'
105
+ ? JSON.parse(additionalFields.template_variables)
106
+ : additionalFields.template_variables;
107
+ }
108
+ if (additionalFields.cc) {
109
+ body.cc = additionalFields.cc
110
+ .split(',')
111
+ .map((e) => e.trim());
112
+ }
113
+ if (additionalFields.bcc) {
114
+ body.bcc = additionalFields.bcc
115
+ .split(',')
116
+ .map((e) => e.trim());
117
+ }
118
+ if (additionalFields.reply_to) {
119
+ body.reply_to = additionalFields.reply_to
120
+ .split(',')
121
+ .map((e) => e.trim());
122
+ }
123
+ if (additionalFields.idempotencyKey) {
124
+ headers['Idempotency-Key'] = additionalFields.idempotencyKey;
125
+ }
126
+ const headersUi = additionalFields.headersUi;
127
+ if (headersUi === null || headersUi === void 0 ? void 0 : headersUi.headerValues) {
128
+ const customHeaders = {};
129
+ for (const header of headersUi.headerValues) {
130
+ customHeaders[header.name] = header.value;
131
+ }
132
+ body.headers = customHeaders;
133
+ }
134
+ const tagsUi = additionalFields.tagsUi;
135
+ if (tagsUi === null || tagsUi === void 0 ? void 0 : tagsUi.tagValues) {
136
+ body.tags = tagsUi.tagValues;
137
+ }
138
+ const attachmentsUi = additionalFields.attachmentsUi;
139
+ if (attachmentsUi === null || attachmentsUi === void 0 ? void 0 : attachmentsUi.attachmentValues) {
140
+ body.attachments = attachmentsUi.attachmentValues;
141
+ }
142
+ responseData = await GenericFunctions_1.resendApiRequest.call(this, 'POST', '/emails', body, {}, headers);
143
+ }
144
+ else if (operation === 'sendBatch') {
145
+ const emailsJson = this.getNodeParameter('emails', i);
146
+ const emails = typeof emailsJson === 'string' ? JSON.parse(emailsJson) : emailsJson;
147
+ const headers = {};
148
+ const idempotencyKey = this.getNodeParameter('idempotencyKey', i, '');
149
+ if (idempotencyKey) {
150
+ headers['Idempotency-Key'] = idempotencyKey;
151
+ }
152
+ responseData = await GenericFunctions_1.resendApiRequest.call(this, 'POST', '/emails/batch', emails, {}, headers);
153
+ }
154
+ else if (operation === 'get') {
155
+ const emailId = this.getNodeParameter('emailId', i);
156
+ responseData = await GenericFunctions_1.resendApiRequest.call(this, 'GET', `/emails/${emailId}`);
157
+ }
158
+ else if (operation === 'getMany') {
159
+ const returnAll = this.getNodeParameter('returnAll', i);
160
+ if (returnAll) {
161
+ responseData = await GenericFunctions_1.resendApiRequestAllItems.call(this, 'GET', '/emails');
162
+ }
163
+ else {
164
+ const limit = this.getNodeParameter('limit', i);
165
+ const qs = { limit };
166
+ const response = await GenericFunctions_1.resendApiRequest.call(this, 'GET', '/emails', {}, qs);
167
+ responseData = response.data || response;
168
+ }
169
+ }
170
+ else if (operation === 'update') {
171
+ const emailId = this.getNodeParameter('emailId', i);
172
+ const body = {
173
+ scheduled_at: this.getNodeParameter('scheduled_at', i),
174
+ };
175
+ responseData = await GenericFunctions_1.resendApiRequest.call(this, 'PATCH', `/emails/${emailId}`, body);
176
+ }
177
+ else if (operation === 'cancel') {
178
+ const emailId = this.getNodeParameter('emailId', i);
179
+ responseData = await GenericFunctions_1.resendApiRequest.call(this, 'POST', `/emails/${emailId}/cancel`);
180
+ }
181
+ }
182
+ // ──────────────────── DOMAIN ──────────────────
183
+ else if (resource === 'domain') {
184
+ if (operation === 'create') {
185
+ const body = {
186
+ name: this.getNodeParameter('name', i),
187
+ };
188
+ const additionalFields = this.getNodeParameter('additionalFields', i);
189
+ Object.assign(body, additionalFields);
190
+ responseData = await GenericFunctions_1.resendApiRequest.call(this, 'POST', '/domains', body);
191
+ }
192
+ else if (operation === 'get') {
193
+ const domainId = this.getNodeParameter('domainId', i);
194
+ responseData = await GenericFunctions_1.resendApiRequest.call(this, 'GET', `/domains/${domainId}`);
195
+ }
196
+ else if (operation === 'getMany') {
197
+ const returnAll = this.getNodeParameter('returnAll', i);
198
+ if (returnAll) {
199
+ responseData = await GenericFunctions_1.resendApiRequestAllItems.call(this, 'GET', '/domains');
200
+ }
201
+ else {
202
+ const limit = this.getNodeParameter('limit', i);
203
+ const qs = { limit };
204
+ const response = await GenericFunctions_1.resendApiRequest.call(this, 'GET', '/domains', {}, qs);
205
+ responseData = response.data || response;
206
+ }
207
+ }
208
+ else if (operation === 'update') {
209
+ const domainId = this.getNodeParameter('domainId', i);
210
+ const updateFields = this.getNodeParameter('updateFields', i);
211
+ responseData = await GenericFunctions_1.resendApiRequest.call(this, 'PATCH', `/domains/${domainId}`, updateFields);
212
+ }
213
+ else if (operation === 'delete') {
214
+ const domainId = this.getNodeParameter('domainId', i);
215
+ responseData = await GenericFunctions_1.resendApiRequest.call(this, 'DELETE', `/domains/${domainId}`);
216
+ }
217
+ else if (operation === 'verify') {
218
+ const domainId = this.getNodeParameter('domainId', i);
219
+ responseData = await GenericFunctions_1.resendApiRequest.call(this, 'POST', `/domains/${domainId}/verify`);
220
+ }
221
+ }
222
+ // ──────────────────── API KEY ─────────────────
223
+ else if (resource === 'apiKey') {
224
+ if (operation === 'create') {
225
+ const body = {
226
+ name: this.getNodeParameter('name', i),
227
+ };
228
+ const additionalFields = this.getNodeParameter('additionalFields', i);
229
+ Object.assign(body, additionalFields);
230
+ responseData = await GenericFunctions_1.resendApiRequest.call(this, 'POST', '/api-keys', body);
231
+ }
232
+ else if (operation === 'getMany') {
233
+ const returnAll = this.getNodeParameter('returnAll', i);
234
+ if (returnAll) {
235
+ responseData = await GenericFunctions_1.resendApiRequestAllItems.call(this, 'GET', '/api-keys');
236
+ }
237
+ else {
238
+ const limit = this.getNodeParameter('limit', i);
239
+ const qs = { limit };
240
+ const response = await GenericFunctions_1.resendApiRequest.call(this, 'GET', '/api-keys', {}, qs);
241
+ responseData = response.data || response;
242
+ }
243
+ }
244
+ else if (operation === 'delete') {
245
+ const apiKeyId = this.getNodeParameter('apiKeyId', i);
246
+ responseData = await GenericFunctions_1.resendApiRequest.call(this, 'DELETE', `/api-keys/${apiKeyId}`);
247
+ }
248
+ }
249
+ // ──────────────────── CONTACT ─────────────────
250
+ else if (resource === 'contact') {
251
+ if (operation === 'create') {
252
+ const body = {
253
+ email: this.getNodeParameter('email', i),
254
+ };
255
+ const additionalFields = this.getNodeParameter('additionalFields', i);
256
+ if (additionalFields.first_name)
257
+ body.first_name = additionalFields.first_name;
258
+ if (additionalFields.last_name)
259
+ body.last_name = additionalFields.last_name;
260
+ if (additionalFields.unsubscribed !== undefined)
261
+ body.unsubscribed = additionalFields.unsubscribed;
262
+ if (additionalFields.properties) {
263
+ body.properties =
264
+ typeof additionalFields.properties === 'string'
265
+ ? JSON.parse(additionalFields.properties)
266
+ : additionalFields.properties;
267
+ }
268
+ if (additionalFields.segments) {
269
+ body.segments = additionalFields.segments
270
+ .split(',')
271
+ .map((s) => s.trim());
272
+ }
273
+ const topicsUi = additionalFields.topicsUi;
274
+ if (topicsUi === null || topicsUi === void 0 ? void 0 : topicsUi.topicValues) {
275
+ body.topics = topicsUi.topicValues;
276
+ }
277
+ responseData = await GenericFunctions_1.resendApiRequest.call(this, 'POST', '/contacts', body);
278
+ }
279
+ else if (operation === 'get') {
280
+ const contactIdOrEmail = this.getNodeParameter('contactIdOrEmail', i);
281
+ responseData = await GenericFunctions_1.resendApiRequest.call(this, 'GET', `/contacts/${contactIdOrEmail}`);
282
+ }
283
+ else if (operation === 'getMany') {
284
+ const returnAll = this.getNodeParameter('returnAll', i);
285
+ const filters = this.getNodeParameter('filters', i, {});
286
+ const qs = {};
287
+ if (filters.segment_id)
288
+ qs.segment_id = filters.segment_id;
289
+ if (returnAll) {
290
+ responseData = await GenericFunctions_1.resendApiRequestAllItems.call(this, 'GET', '/contacts', {}, qs);
291
+ }
292
+ else {
293
+ const limit = this.getNodeParameter('limit', i);
294
+ qs.limit = limit;
295
+ const response = await GenericFunctions_1.resendApiRequest.call(this, 'GET', '/contacts', {}, qs);
296
+ responseData = response.data || response;
297
+ }
298
+ }
299
+ else if (operation === 'update') {
300
+ const contactIdOrEmail = this.getNodeParameter('contactIdOrEmail', i);
301
+ const updateFields = this.getNodeParameter('updateFields', i);
302
+ const body = {};
303
+ if (updateFields.first_name !== undefined)
304
+ body.first_name = updateFields.first_name;
305
+ if (updateFields.last_name !== undefined)
306
+ body.last_name = updateFields.last_name;
307
+ if (updateFields.unsubscribed !== undefined)
308
+ body.unsubscribed = updateFields.unsubscribed;
309
+ if (updateFields.properties) {
310
+ body.properties =
311
+ typeof updateFields.properties === 'string'
312
+ ? JSON.parse(updateFields.properties)
313
+ : updateFields.properties;
314
+ }
315
+ responseData = await GenericFunctions_1.resendApiRequest.call(this, 'PATCH', `/contacts/${contactIdOrEmail}`, body);
316
+ }
317
+ else if (operation === 'delete') {
318
+ const contactIdOrEmail = this.getNodeParameter('contactIdOrEmail', i);
319
+ responseData = await GenericFunctions_1.resendApiRequest.call(this, 'DELETE', `/contacts/${contactIdOrEmail}`);
320
+ }
321
+ }
322
+ // ──────────────────── BROADCAST ───────────────
323
+ else if (resource === 'broadcast') {
324
+ if (operation === 'create') {
325
+ const body = {
326
+ segment_id: this.getNodeParameter('segment_id', i),
327
+ from: this.getNodeParameter('from', i),
328
+ subject: this.getNodeParameter('subject', i),
329
+ };
330
+ const additionalFields = this.getNodeParameter('additionalFields', i);
331
+ if (additionalFields.html)
332
+ body.html = additionalFields.html;
333
+ if (additionalFields.text)
334
+ body.text = additionalFields.text;
335
+ if (additionalFields.name)
336
+ body.name = additionalFields.name;
337
+ if (additionalFields.topic_id)
338
+ body.topic_id = additionalFields.topic_id;
339
+ if (additionalFields.reply_to) {
340
+ body.reply_to = additionalFields.reply_to
341
+ .split(',')
342
+ .map((e) => e.trim());
343
+ }
344
+ responseData = await GenericFunctions_1.resendApiRequest.call(this, 'POST', '/broadcasts', body);
345
+ }
346
+ else if (operation === 'get') {
347
+ const broadcastId = this.getNodeParameter('broadcastId', i);
348
+ responseData = await GenericFunctions_1.resendApiRequest.call(this, 'GET', `/broadcasts/${broadcastId}`);
349
+ }
350
+ else if (operation === 'getMany') {
351
+ const returnAll = this.getNodeParameter('returnAll', i);
352
+ if (returnAll) {
353
+ responseData = await GenericFunctions_1.resendApiRequestAllItems.call(this, 'GET', '/broadcasts');
354
+ }
355
+ else {
356
+ const limit = this.getNodeParameter('limit', i);
357
+ const qs = { limit };
358
+ const response = await GenericFunctions_1.resendApiRequest.call(this, 'GET', '/broadcasts', {}, qs);
359
+ responseData = response.data || response;
360
+ }
361
+ }
362
+ else if (operation === 'send') {
363
+ const broadcastId = this.getNodeParameter('broadcastId', i);
364
+ const additionalFields = this.getNodeParameter('additionalFields', i);
365
+ const body = {};
366
+ if (additionalFields.scheduled_at)
367
+ body.scheduled_at = additionalFields.scheduled_at;
368
+ responseData = await GenericFunctions_1.resendApiRequest.call(this, 'POST', `/broadcasts/${broadcastId}/send`, body);
369
+ }
370
+ else if (operation === 'update') {
371
+ const broadcastId = this.getNodeParameter('broadcastId', i);
372
+ const updateFields = this.getNodeParameter('updateFields', i);
373
+ const body = { ...updateFields };
374
+ if (body.reply_to && typeof body.reply_to === 'string') {
375
+ body.reply_to = body.reply_to
376
+ .split(',')
377
+ .map((e) => e.trim());
378
+ }
379
+ responseData = await GenericFunctions_1.resendApiRequest.call(this, 'PATCH', `/broadcasts/${broadcastId}`, body);
380
+ }
381
+ else if (operation === 'delete') {
382
+ const broadcastId = this.getNodeParameter('broadcastId', i);
383
+ responseData = await GenericFunctions_1.resendApiRequest.call(this, 'DELETE', `/broadcasts/${broadcastId}`);
384
+ }
385
+ }
386
+ // ──────────────────── SEGMENT ─────────────────
387
+ else if (resource === 'segment') {
388
+ if (operation === 'create') {
389
+ const body = {
390
+ name: this.getNodeParameter('name', i),
391
+ };
392
+ responseData = await GenericFunctions_1.resendApiRequest.call(this, 'POST', '/segments', body);
393
+ }
394
+ else if (operation === 'get') {
395
+ const segmentId = this.getNodeParameter('segmentId', i);
396
+ responseData = await GenericFunctions_1.resendApiRequest.call(this, 'GET', `/segments/${segmentId}`);
397
+ }
398
+ else if (operation === 'getMany') {
399
+ const returnAll = this.getNodeParameter('returnAll', i);
400
+ if (returnAll) {
401
+ responseData = await GenericFunctions_1.resendApiRequestAllItems.call(this, 'GET', '/segments');
402
+ }
403
+ else {
404
+ const limit = this.getNodeParameter('limit', i);
405
+ const qs = { limit };
406
+ const response = await GenericFunctions_1.resendApiRequest.call(this, 'GET', '/segments', {}, qs);
407
+ responseData = response.data || response;
408
+ }
409
+ }
410
+ else if (operation === 'update') {
411
+ const segmentId = this.getNodeParameter('segmentId', i);
412
+ const body = {
413
+ name: this.getNodeParameter('name', i),
414
+ };
415
+ responseData = await GenericFunctions_1.resendApiRequest.call(this, 'PATCH', `/segments/${segmentId}`, body);
416
+ }
417
+ else if (operation === 'delete') {
418
+ const segmentId = this.getNodeParameter('segmentId', i);
419
+ responseData = await GenericFunctions_1.resendApiRequest.call(this, 'DELETE', `/segments/${segmentId}`);
420
+ }
421
+ }
422
+ // ──────────────────── TOPIC ───────────────────
423
+ else if (resource === 'topic') {
424
+ if (operation === 'create') {
425
+ const body = {
426
+ name: this.getNodeParameter('name', i),
427
+ default_subscription: this.getNodeParameter('default_subscription', i),
428
+ };
429
+ const additionalFields = this.getNodeParameter('additionalFields', i);
430
+ Object.assign(body, additionalFields);
431
+ responseData = await GenericFunctions_1.resendApiRequest.call(this, 'POST', '/topics', body);
432
+ }
433
+ else if (operation === 'get') {
434
+ const topicId = this.getNodeParameter('topicId', i);
435
+ responseData = await GenericFunctions_1.resendApiRequest.call(this, 'GET', `/topics/${topicId}`);
436
+ }
437
+ else if (operation === 'getMany') {
438
+ const returnAll = this.getNodeParameter('returnAll', i);
439
+ if (returnAll) {
440
+ responseData = await GenericFunctions_1.resendApiRequestAllItems.call(this, 'GET', '/topics');
441
+ }
442
+ else {
443
+ const limit = this.getNodeParameter('limit', i);
444
+ const qs = { limit };
445
+ const response = await GenericFunctions_1.resendApiRequest.call(this, 'GET', '/topics', {}, qs);
446
+ responseData = response.data || response;
447
+ }
448
+ }
449
+ else if (operation === 'update') {
450
+ const topicId = this.getNodeParameter('topicId', i);
451
+ const updateFields = this.getNodeParameter('updateFields', i);
452
+ responseData = await GenericFunctions_1.resendApiRequest.call(this, 'PATCH', `/topics/${topicId}`, updateFields);
453
+ }
454
+ else if (operation === 'delete') {
455
+ const topicId = this.getNodeParameter('topicId', i);
456
+ responseData = await GenericFunctions_1.resendApiRequest.call(this, 'DELETE', `/topics/${topicId}`);
457
+ }
458
+ }
459
+ // ──────────────────── TEMPLATE ────────────────
460
+ else if (resource === 'template') {
461
+ if (operation === 'create') {
462
+ const body = {
463
+ name: this.getNodeParameter('name', i),
464
+ };
465
+ const additionalFields = this.getNodeParameter('additionalFields', i);
466
+ if (additionalFields.html)
467
+ body.html = additionalFields.html;
468
+ if (additionalFields.subject)
469
+ body.subject = additionalFields.subject;
470
+ if (additionalFields.from)
471
+ body.from = additionalFields.from;
472
+ if (additionalFields.reply_to)
473
+ body.reply_to = additionalFields.reply_to;
474
+ if (additionalFields.text)
475
+ body.text = additionalFields.text;
476
+ if (additionalFields.alias)
477
+ body.alias = additionalFields.alias;
478
+ if (additionalFields.variables) {
479
+ body.variables =
480
+ typeof additionalFields.variables === 'string'
481
+ ? JSON.parse(additionalFields.variables)
482
+ : additionalFields.variables;
483
+ }
484
+ responseData = await GenericFunctions_1.resendApiRequest.call(this, 'POST', '/templates', body);
485
+ }
486
+ else if (operation === 'get') {
487
+ const templateId = this.getNodeParameter('templateId', i);
488
+ responseData = await GenericFunctions_1.resendApiRequest.call(this, 'GET', `/templates/${templateId}`);
489
+ }
490
+ else if (operation === 'getMany') {
491
+ const returnAll = this.getNodeParameter('returnAll', i);
492
+ if (returnAll) {
493
+ responseData = await GenericFunctions_1.resendApiRequestAllItems.call(this, 'GET', '/templates');
494
+ }
495
+ else {
496
+ const limit = this.getNodeParameter('limit', i);
497
+ const qs = { limit };
498
+ const response = await GenericFunctions_1.resendApiRequest.call(this, 'GET', '/templates', {}, qs);
499
+ responseData = response.data || response;
500
+ }
501
+ }
502
+ else if (operation === 'update') {
503
+ const templateId = this.getNodeParameter('templateId', i);
504
+ const updateFields = this.getNodeParameter('updateFields', i);
505
+ const body = { ...updateFields };
506
+ if (body.variables && typeof body.variables === 'string') {
507
+ body.variables = JSON.parse(body.variables);
508
+ }
509
+ responseData = await GenericFunctions_1.resendApiRequest.call(this, 'PATCH', `/templates/${templateId}`, body);
510
+ }
511
+ else if (operation === 'delete') {
512
+ const templateId = this.getNodeParameter('templateId', i);
513
+ responseData = await GenericFunctions_1.resendApiRequest.call(this, 'DELETE', `/templates/${templateId}`);
514
+ }
515
+ else if (operation === 'publish') {
516
+ const templateId = this.getNodeParameter('templateId', i);
517
+ responseData = await GenericFunctions_1.resendApiRequest.call(this, 'POST', `/templates/${templateId}/publish`);
518
+ }
519
+ else if (operation === 'duplicate') {
520
+ const templateId = this.getNodeParameter('templateId', i);
521
+ responseData = await GenericFunctions_1.resendApiRequest.call(this, 'POST', `/templates/${templateId}/duplicate`);
522
+ }
523
+ }
524
+ // ──────────────────── WEBHOOK ─────────────────
525
+ else if (resource === 'webhook') {
526
+ if (operation === 'create') {
527
+ const body = {
528
+ endpoint: this.getNodeParameter('endpoint', i),
529
+ events: this.getNodeParameter('events', i),
530
+ };
531
+ responseData = await GenericFunctions_1.resendApiRequest.call(this, 'POST', '/webhooks', body);
532
+ }
533
+ else if (operation === 'get') {
534
+ const webhookId = this.getNodeParameter('webhookId', i);
535
+ responseData = await GenericFunctions_1.resendApiRequest.call(this, 'GET', `/webhooks/${webhookId}`);
536
+ }
537
+ else if (operation === 'getMany') {
538
+ const returnAll = this.getNodeParameter('returnAll', i);
539
+ if (returnAll) {
540
+ responseData = await GenericFunctions_1.resendApiRequestAllItems.call(this, 'GET', '/webhooks');
541
+ }
542
+ else {
543
+ const limit = this.getNodeParameter('limit', i);
544
+ const qs = { limit };
545
+ const response = await GenericFunctions_1.resendApiRequest.call(this, 'GET', '/webhooks', {}, qs);
546
+ responseData = response.data || response;
547
+ }
548
+ }
549
+ else if (operation === 'update') {
550
+ const webhookId = this.getNodeParameter('webhookId', i);
551
+ const updateFields = this.getNodeParameter('updateFields', i);
552
+ responseData = await GenericFunctions_1.resendApiRequest.call(this, 'PATCH', `/webhooks/${webhookId}`, updateFields);
553
+ }
554
+ else if (operation === 'delete') {
555
+ const webhookId = this.getNodeParameter('webhookId', i);
556
+ responseData = await GenericFunctions_1.resendApiRequest.call(this, 'DELETE', `/webhooks/${webhookId}`);
557
+ }
558
+ }
559
+ // ──────────────────── CONTACT PROPERTY ────────
560
+ else if (resource === 'contactProperty') {
561
+ if (operation === 'create') {
562
+ const body = {
563
+ key: this.getNodeParameter('key', i),
564
+ type: this.getNodeParameter('type', i),
565
+ };
566
+ const additionalFields = this.getNodeParameter('additionalFields', i);
567
+ if (additionalFields.fallback_value)
568
+ body.fallback_value = additionalFields.fallback_value;
569
+ responseData = await GenericFunctions_1.resendApiRequest.call(this, 'POST', '/contact-properties', body);
570
+ }
571
+ else if (operation === 'get') {
572
+ const propertyId = this.getNodeParameter('propertyId', i);
573
+ responseData = await GenericFunctions_1.resendApiRequest.call(this, 'GET', `/contact-properties/${propertyId}`);
574
+ }
575
+ else if (operation === 'getMany') {
576
+ const returnAll = this.getNodeParameter('returnAll', i);
577
+ if (returnAll) {
578
+ responseData = await GenericFunctions_1.resendApiRequestAllItems.call(this, 'GET', '/contact-properties');
579
+ }
580
+ else {
581
+ const limit = this.getNodeParameter('limit', i);
582
+ const qs = { limit };
583
+ const response = await GenericFunctions_1.resendApiRequest.call(this, 'GET', '/contact-properties', {}, qs);
584
+ responseData = response.data || response;
585
+ }
586
+ }
587
+ else if (operation === 'update') {
588
+ const propertyId = this.getNodeParameter('propertyId', i);
589
+ const body = {
590
+ fallback_value: this.getNodeParameter('fallback_value', i),
591
+ };
592
+ responseData = await GenericFunctions_1.resendApiRequest.call(this, 'PATCH', `/contact-properties/${propertyId}`, body);
593
+ }
594
+ else if (operation === 'delete') {
595
+ const propertyId = this.getNodeParameter('propertyId', i);
596
+ responseData = await GenericFunctions_1.resendApiRequest.call(this, 'DELETE', `/contact-properties/${propertyId}`);
597
+ }
598
+ }
599
+ // ──── Normalize response ──────────────────────
600
+ const executionData = this.helpers.constructExecutionMetaData(this.helpers.returnJsonArray(responseData), { itemData: { item: i } });
601
+ returnData.push(...executionData);
602
+ }
603
+ catch (error) {
604
+ if (this.continueOnFail()) {
605
+ const executionData = this.helpers.constructExecutionMetaData(this.helpers.returnJsonArray({ error: error.message }), { itemData: { item: i } });
606
+ returnData.push(...executionData);
607
+ continue;
608
+ }
609
+ throw error;
610
+ }
611
+ }
612
+ return [returnData];
613
+ }
614
+ }
615
+ exports.Resend = Resend;
616
+ //# sourceMappingURL=Resend.node.js.map