n8n-nodes-resend 3.1.1 → 3.2.1

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.
@@ -422,38 +422,40 @@ async function execute(index) {
422
422
  });
423
423
  if (additionalOptions.topicId) requestBody.topic_id = additionalOptions.topicId;
424
424
  if (additionalOptions.scheduledAt) requestBody.scheduled_at = additionalOptions.scheduledAt;
425
- if ((_additionalOptions$at = additionalOptions.attachments) === null || _additionalOptions$at === void 0 || (_additionalOptions$at = _additionalOptions$at.attachments) === null || _additionalOptions$at === void 0 ? void 0 : _additionalOptions$at.length) requestBody.attachments = additionalOptions.attachments.attachments.map((attachment) => {
426
- var _attachment$content_i, _attachment$content_t;
427
- const contentId = (_attachment$content_i = attachment.content_id) !== null && _attachment$content_i !== void 0 ? _attachment$content_i : attachment.contentId;
428
- const contentType = (_attachment$content_t = attachment.content_type) !== null && _attachment$content_t !== void 0 ? _attachment$content_t : attachment.contentType;
429
- if (attachment.attachmentType === "binaryData") {
430
- var _items$index$binary;
431
- const binaryPropertyName = attachment.binaryPropertyName || "data";
432
- const binaryData = (_items$index$binary = items[index].binary) === null || _items$index$binary === void 0 ? void 0 : _items$index$binary[binaryPropertyName];
433
- if (!binaryData) throw new n8n_workflow.NodeOperationError(this.getNode(), `Binary property "${binaryPropertyName}" not found in item ${index}`, { itemIndex: index });
434
- const filename = attachment.filename || binaryData.fileName;
435
- if (!filename) throw new n8n_workflow.NodeOperationError(this.getNode(), "File Name is required for binary attachments.", { itemIndex: index });
436
- const attachmentEntry = {
437
- filename,
438
- content: binaryData.data
439
- };
440
- if (contentId) attachmentEntry.content_id = contentId;
441
- if (contentType) attachmentEntry.content_type = contentType;
442
- return attachmentEntry;
443
- }
444
- if (attachment.attachmentType === "url") {
445
- if (!attachment.filename) throw new n8n_workflow.NodeOperationError(this.getNode(), "File Name is required for URL attachments.", { itemIndex: index });
446
- if (!attachment.fileUrl) throw new n8n_workflow.NodeOperationError(this.getNode(), "File URL is required for URL attachments.", { itemIndex: index });
447
- const attachmentEntry = {
448
- filename: attachment.filename,
449
- path: attachment.fileUrl
450
- };
451
- if (contentId) attachmentEntry.content_id = contentId;
452
- if (contentType) attachmentEntry.content_type = contentType;
453
- return attachmentEntry;
425
+ if ((_additionalOptions$at = additionalOptions.attachments) === null || _additionalOptions$at === void 0 || (_additionalOptions$at = _additionalOptions$at.attachments) === null || _additionalOptions$at === void 0 ? void 0 : _additionalOptions$at.length) {
426
+ const attachments = [];
427
+ for (const attachment of additionalOptions.attachments.attachments) {
428
+ var _attachment$content_i, _attachment$content_t;
429
+ const contentId = (_attachment$content_i = attachment.content_id) !== null && _attachment$content_i !== void 0 ? _attachment$content_i : attachment.contentId;
430
+ const contentType = (_attachment$content_t = attachment.content_type) !== null && _attachment$content_t !== void 0 ? _attachment$content_t : attachment.contentType;
431
+ if (attachment.attachmentType === "binaryData") {
432
+ var _items$index$binary;
433
+ const binaryPropertyName = attachment.binaryPropertyName || "data";
434
+ const binaryData = (_items$index$binary = items[index].binary) === null || _items$index$binary === void 0 ? void 0 : _items$index$binary[binaryPropertyName];
435
+ if (!binaryData) throw new n8n_workflow.NodeOperationError(this.getNode(), `Binary property "${binaryPropertyName}" not found in item ${index}`, { itemIndex: index });
436
+ const filename = attachment.filename || binaryData.fileName;
437
+ if (!filename) throw new n8n_workflow.NodeOperationError(this.getNode(), "File Name is required for binary attachments.", { itemIndex: index });
438
+ const attachmentEntry = {
439
+ filename,
440
+ content: (await this.helpers.getBinaryDataBuffer(index, binaryPropertyName)).toString("base64")
441
+ };
442
+ if (contentId) attachmentEntry.content_id = contentId;
443
+ if (contentType) attachmentEntry.content_type = contentType;
444
+ attachments.push(attachmentEntry);
445
+ } else if (attachment.attachmentType === "url") {
446
+ if (!attachment.filename) throw new n8n_workflow.NodeOperationError(this.getNode(), "File Name is required for URL attachments.", { itemIndex: index });
447
+ if (!attachment.fileUrl) throw new n8n_workflow.NodeOperationError(this.getNode(), "File URL is required for URL attachments.", { itemIndex: index });
448
+ const attachmentEntry = {
449
+ filename: attachment.filename,
450
+ path: attachment.fileUrl
451
+ };
452
+ if (contentId) attachmentEntry.content_id = contentId;
453
+ if (contentType) attachmentEntry.content_type = contentType;
454
+ attachments.push(attachmentEntry);
455
+ }
454
456
  }
455
- return null;
456
- }).filter((attachment) => attachment !== null);
457
+ requestBody.attachments = attachments;
458
+ }
457
459
  const requestHeaders = { "Content-Type": "application/json" };
458
460
  if (additionalOptions.idempotencyKey) requestHeaders["Idempotency-Key"] = additionalOptions.idempotencyKey;
459
461
  let response;
@@ -19,7 +19,7 @@ const description = [require_nodes_Resend_actions_inboxThread_shared.createInbox
19
19
  operation: ["create"]
20
20
  } },
21
21
  options: [
22
- require_nodes_Resend_actions_inboxThread_shared.draftAttachmentsField("Files to store on the draft, from binary data. Each one needs a file name and a content type. The files of a draft can total at most 25 MB. An empty file or a blocked file type returns an error."),
22
+ require_nodes_Resend_actions_inboxThread_shared.draftAttachmentsField("Files to store on the draft, from binary data or a URL. Each one needs a file name. Binary data also needs a content type. A URL file is downloaded when the request is made. The files of a draft, downloaded ones included, can total at most 25 MB. An empty file, a blocked file type, or a URL that is not http or https or cannot be downloaded returns an error, and so do downloads that take more than 20 seconds together."),
23
23
  require_nodes_Resend_actions_inboxThread_shared.bccField,
24
24
  require_nodes_Resend_actions_inboxThread_shared.ccField,
25
25
  require_nodes_Resend_actions_inboxThread_shared.htmlField,
@@ -22,7 +22,7 @@ const description = [
22
22
  operation: ["update"]
23
23
  } },
24
24
  options: [
25
- require_nodes_Resend_actions_inboxThread_shared.draftAttachmentsField("Files to store on the draft, from binary data. They replace every attachment on the draft. Each one needs a file name and a content type. The files of a draft can total at most 25 MB. An empty file or a blocked file type returns an error."),
25
+ require_nodes_Resend_actions_inboxThread_shared.draftAttachmentsField("Files to store on the draft, from binary data or a URL. They replace every attachment on the draft. Each one needs a file name. Binary data also needs a content type. A URL file is downloaded when the request is made. The files of a draft, downloaded ones included, can total at most 25 MB. An empty file, a blocked file type, or a URL that is not http or https or cannot be downloaded returns an error, and so do downloads that take more than 20 seconds together."),
26
26
  require_nodes_Resend_actions_inboxThread_shared.bccField,
27
27
  require_nodes_Resend_actions_inboxThread_shared.ccField,
28
28
  {
@@ -335,13 +335,29 @@ const draftAttachmentsField = (description) => ({
335
335
  name: "attachments",
336
336
  displayName: "Attachment",
337
337
  values: [
338
+ {
339
+ displayName: "Attachment Type",
340
+ name: "attachmentType",
341
+ type: "options",
342
+ default: "binaryData",
343
+ options: [{
344
+ name: "Binary Data",
345
+ value: "binaryData",
346
+ description: "Use binary file data from a previous node in the workflow"
347
+ }, {
348
+ name: "Remote URL",
349
+ value: "url",
350
+ description: "Resend downloads the file from a public URL when the draft is saved, not when it is sent"
351
+ }]
352
+ },
338
353
  {
339
354
  displayName: "Binary Property",
340
355
  name: "binaryPropertyName",
341
356
  type: "string",
342
357
  default: "data",
343
358
  placeholder: "data",
344
- description: "The name of the binary property that holds the file data"
359
+ description: "The name of the binary property that holds the file data",
360
+ displayOptions: { show: { attachmentType: ["binaryData"] } }
345
361
  },
346
362
  {
347
363
  displayName: "Content Type",
@@ -349,7 +365,7 @@ const draftAttachmentsField = (description) => ({
349
365
  type: "string",
350
366
  default: "",
351
367
  placeholder: "application/pdf",
352
- description: "The MIME type of the file. Defaults to the MIME type of the binary data."
368
+ description: "The MIME type of the file. Defaults to the MIME type of the binary data, or of the downloaded file for a URL."
353
369
  },
354
370
  {
355
371
  displayName: "File Name",
@@ -357,7 +373,16 @@ const draftAttachmentsField = (description) => ({
357
373
  type: "string",
358
374
  default: "",
359
375
  placeholder: "document.pdf",
360
- description: "The name of the attached file. Defaults to the binary file name."
376
+ description: "The name of the attached file. Defaults to the binary file name. Required for a URL."
377
+ },
378
+ {
379
+ displayName: "File URL",
380
+ name: "fileUrl",
381
+ type: "string",
382
+ default: "",
383
+ placeholder: "https://example.com/file.pdf",
384
+ description: "The public http or https URL of the file. It is downloaded when the request is made.",
385
+ displayOptions: { show: { attachmentType: ["url"] } }
361
386
  }
362
387
  ]
363
388
  }]
@@ -368,6 +393,19 @@ async function buildDraftAttachments(context, value, index) {
368
393
  const attachments = [];
369
394
  for (const input of inputs) {
370
395
  var _context$getInputData2;
396
+ if (input.attachmentType === "url") {
397
+ var _input$fileUrl2;
398
+ const fileUrl = String((_input$fileUrl2 = input.fileUrl) !== null && _input$fileUrl2 !== void 0 ? _input$fileUrl2 : "").trim();
399
+ if (!fileUrl) throw new n8n_workflow.NodeOperationError(context.getNode(), "File URL is required for URL attachments", { itemIndex: index });
400
+ if (!input.filename) throw new n8n_workflow.NodeOperationError(context.getNode(), "Draft attachments from a URL need a File Name", { itemIndex: index });
401
+ const entry = {
402
+ path: fileUrl,
403
+ filename: input.filename
404
+ };
405
+ if (input.content_type) entry.content_type = input.content_type;
406
+ attachments.push(entry);
407
+ continue;
408
+ }
371
409
  const propertyName = input.binaryPropertyName || "data";
372
410
  const binary = (_context$getInputData2 = context.getInputData()[index]) === null || _context$getInputData2 === void 0 || (_context$getInputData2 = _context$getInputData2.binary) === null || _context$getInputData2 === void 0 ? void 0 : _context$getInputData2[propertyName];
373
411
  if (!binary) throw new n8n_workflow.NodeOperationError(context.getNode(), `Binary property "${propertyName}" not found in item ${index}`, { itemIndex: index });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n8n-nodes-resend",
3
- "version": "3.1.1",
3
+ "version": "3.2.1",
4
4
  "description": "Resend integration for n8n: Email, Broadcasts, Templates, Domains, Contacts, Segments, Topics, Webhooks, Automations, Events, and more",
5
5
  "keywords": [
6
6
  "n8n-community-node-package",