n8n-nodes-posthawk 0.1.2 → 0.1.5

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.
@@ -28,14 +28,14 @@ class PosthawkApi {
28
28
  type: 'generic',
29
29
  properties: {
30
30
  headers: {
31
- Authorization: '=Bearer {{$credentials.apiKey}}',
31
+ 'x-api-key': '={{$credentials.apiKey}}',
32
32
  },
33
33
  },
34
34
  };
35
35
  this.test = {
36
36
  request: {
37
37
  baseURL: '={{$credentials.baseUrl}}',
38
- url: '/v1/queue/stats',
38
+ url: '/v1/webhooks',
39
39
  method: 'GET',
40
40
  },
41
41
  };
@@ -247,12 +247,12 @@ class Posthawk {
247
247
  },
248
248
  // Email Batch
249
249
  {
250
- displayName: 'Emails (JSON)',
250
+ displayName: 'Messages (JSON)',
251
251
  name: 'emails',
252
252
  type: 'json',
253
253
  default: '[]',
254
254
  required: true,
255
- description: 'Array of email objects to send in batch',
255
+ description: 'Array of email message objects to send in batch (1-100 messages). Each must include from, to (array), subject, and html or text.',
256
256
  displayOptions: { show: { resource: ['email'], operation: ['batch'] } },
257
257
  },
258
258
  // ════════════════════════════════════════════════
@@ -330,15 +330,11 @@ class Posthawk {
330
330
  displayOptions: { show: { resource: ['suppression'], operation: ['add'] } },
331
331
  },
332
332
  {
333
- displayName: 'Reason',
334
- name: 'reason',
335
- type: 'options',
336
- options: [
337
- { name: 'Bounce', value: 'bounce' },
338
- { name: 'Complaint', value: 'complaint' },
339
- { name: 'Manual', value: 'manual' },
340
- ],
341
- default: 'manual',
333
+ displayName: 'Notes',
334
+ name: 'notes',
335
+ type: 'string',
336
+ default: '',
337
+ description: 'Optional notes about why this email is suppressed',
342
338
  displayOptions: { show: { resource: ['suppression'], operation: ['add'] } },
343
339
  },
344
340
  {
@@ -413,7 +409,7 @@ class Posthawk {
413
409
  const additional = this.getNodeParameter('additionalFields', i, {});
414
410
  const body = {
415
411
  from: this.getNodeParameter('from', i),
416
- to: to.length === 1 ? to[0] : to,
412
+ to,
417
413
  subject: this.getNodeParameter('subject', i),
418
414
  };
419
415
  const html = this.getNodeParameter('html', i, '');
@@ -430,16 +426,25 @@ class Posthawk {
430
426
  body.replyTo = additional.replyTo;
431
427
  if (additional.templateId)
432
428
  body.templateId = additional.templateId;
433
- if (additional.variables)
434
- body.variables = JSON.parse(additional.variables);
429
+ if (additional.variables) {
430
+ body.variables = typeof additional.variables === 'string'
431
+ ? JSON.parse(additional.variables)
432
+ : additional.variables;
433
+ }
435
434
  if (additional.scheduledFor)
436
435
  body.scheduledFor = additional.scheduledFor;
437
436
  if (additional.timezone)
438
437
  body.timezone = additional.timezone;
439
- if (additional.tags)
440
- body.tags = JSON.parse(additional.tags);
441
- if (additional.metadata)
442
- body.metadata = JSON.parse(additional.metadata);
438
+ if (additional.tags) {
439
+ body.tags = typeof additional.tags === 'string'
440
+ ? JSON.parse(additional.tags)
441
+ : additional.tags;
442
+ }
443
+ if (additional.metadata) {
444
+ body.metadata = typeof additional.metadata === 'string'
445
+ ? JSON.parse(additional.metadata)
446
+ : additional.metadata;
447
+ }
443
448
  responseData = await this.helpers.httpRequestWithAuthentication.call(this, 'posthawkApi', {
444
449
  method: 'POST',
445
450
  url: `${baseUrl}/v1/send`,
@@ -448,11 +453,12 @@ class Posthawk {
448
453
  });
449
454
  }
450
455
  else if (operation === 'batch') {
451
- const emails = JSON.parse(this.getNodeParameter('emails', i));
456
+ const rawEmails = this.getNodeParameter('emails', i);
457
+ const messages = typeof rawEmails === 'string' ? JSON.parse(rawEmails) : rawEmails;
452
458
  responseData = await this.helpers.httpRequestWithAuthentication.call(this, 'posthawkApi', {
453
459
  method: 'POST',
454
460
  url: `${baseUrl}/v1/batch`,
455
- body: { emails },
461
+ body: { messages },
456
462
  json: true,
457
463
  });
458
464
  }
@@ -526,8 +532,11 @@ class Posthawk {
526
532
  body.name = fields.name;
527
533
  if (fields.tags)
528
534
  body.tags = fields.tags.split(',').map(s => s.trim());
529
- if (fields.metadata)
530
- body.metadata = JSON.parse(fields.metadata);
535
+ if (fields.metadata) {
536
+ body.metadata = typeof fields.metadata === 'string'
537
+ ? JSON.parse(fields.metadata)
538
+ : fields.metadata;
539
+ }
531
540
  responseData = await this.helpers.httpRequestWithAuthentication.call(this, 'posthawkApi', {
532
541
  method: 'POST',
533
542
  url: `${baseUrl}/v1/contacts`,
@@ -543,8 +552,11 @@ class Posthawk {
543
552
  body.name = fields.name;
544
553
  if (fields.tags)
545
554
  body.tags = fields.tags.split(',').map(s => s.trim());
546
- if (fields.metadata)
547
- body.metadata = JSON.parse(fields.metadata);
555
+ if (fields.metadata) {
556
+ body.metadata = typeof fields.metadata === 'string'
557
+ ? JSON.parse(fields.metadata)
558
+ : fields.metadata;
559
+ }
548
560
  responseData = await this.helpers.httpRequestWithAuthentication.call(this, 'posthawkApi', {
549
561
  method: 'PATCH',
550
562
  url: `${baseUrl}/v1/contacts/${id}`,
@@ -571,13 +583,16 @@ class Posthawk {
571
583
  });
572
584
  }
573
585
  else if (operation === 'add') {
586
+ const suppressionBody = {
587
+ email: this.getNodeParameter('email', i),
588
+ };
589
+ const notes = this.getNodeParameter('notes', i, '');
590
+ if (notes)
591
+ suppressionBody.notes = notes;
574
592
  responseData = await this.helpers.httpRequestWithAuthentication.call(this, 'posthawkApi', {
575
593
  method: 'POST',
576
594
  url: `${baseUrl}/v1/suppressions`,
577
- body: {
578
- email: this.getNodeParameter('email', i),
579
- reason: this.getNodeParameter('reason', i),
580
- },
595
+ body: suppressionBody,
581
596
  json: true,
582
597
  });
583
598
  }
@@ -646,6 +661,12 @@ class Posthawk {
646
661
  if (Array.isArray(responseData)) {
647
662
  returnData.push(...responseData.map(d => ({ json: d })));
648
663
  }
664
+ else if (responseData && Array.isArray(responseData.data)) {
665
+ returnData.push(...responseData.data.map((d) => ({ json: d })));
666
+ }
667
+ else if (responseData && Array.isArray(responseData.entries)) {
668
+ returnData.push(...responseData.entries.map((d) => ({ json: d })));
669
+ }
649
670
  else {
650
671
  returnData.push({ json: responseData ?? { success: true } });
651
672
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n8n-nodes-posthawk",
3
- "version": "0.1.2",
3
+ "version": "0.1.5",
4
4
  "description": "n8n node for Posthawk — send, schedule, and manage emails via the Posthawk API",
5
5
  "keywords": [
6
6
  "n8n-community-node-package",