nodebb-plugin-calendar-onekite 11.1.77 → 11.1.79

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/lib/admin.js CHANGED
@@ -26,22 +26,18 @@ async function sendEmail(template, toEmail, subject, data) {
26
26
  // Same compatibility strategy as lib/api.js
27
27
  const attempts = [];
28
28
  if (typeof emailer.sendToEmail === 'function') {
29
- if (emailer.sendToEmail.length === 3) {
30
- attempts.push(() => emailer.sendToEmail(template, toEmail, dataWithSubject));
31
- } else {
29
+ if (subject) {
32
30
  attempts.push(() => emailer.sendToEmail(template, toEmail, subject, dataWithSubject));
33
31
  attempts.push(() => emailer.sendToEmail(template, toEmail, dataWithSubject, subject));
34
- attempts.push(() => emailer.sendToEmail(template, toEmail, dataWithSubject));
35
32
  }
33
+ attempts.push(() => emailer.sendToEmail(template, toEmail, dataWithSubject));
36
34
  }
37
35
  if (typeof emailer.send === 'function') {
38
- if (emailer.send.length === 3) {
39
- attempts.push(() => emailer.send(template, toEmail, dataWithSubject));
40
- } else {
36
+ if (subject) {
41
37
  attempts.push(() => emailer.send(template, toEmail, subject, dataWithSubject));
42
38
  attempts.push(() => emailer.send(template, toEmail, dataWithSubject, subject));
43
- attempts.push(() => emailer.send(template, toEmail, dataWithSubject));
44
39
  }
40
+ attempts.push(() => emailer.send(template, toEmail, dataWithSubject));
45
41
  }
46
42
 
47
43
  let lastErr = null;
package/lib/api.js CHANGED
@@ -23,23 +23,20 @@ async function sendEmail(template, toEmail, subject, data) {
23
23
  const attempts = [];
24
24
 
25
25
  if (typeof emailer.sendToEmail === 'function') {
26
- if (emailer.sendToEmail.length === 3) {
27
- attempts.push(() => emailer.sendToEmail(template, toEmail, dataWithSubject));
28
- } else {
29
- // Try the common forms that include subject
26
+ // Always try multiple signatures; some implementations ignore arity.
27
+ // Prefer subject-explicit signatures first, then fall back to data.subject.
28
+ if (subject) {
30
29
  attempts.push(() => emailer.sendToEmail(template, toEmail, subject, dataWithSubject));
31
30
  attempts.push(() => emailer.sendToEmail(template, toEmail, dataWithSubject, subject));
32
- attempts.push(() => emailer.sendToEmail(template, toEmail, dataWithSubject));
33
31
  }
32
+ attempts.push(() => emailer.sendToEmail(template, toEmail, dataWithSubject));
34
33
  }
35
34
  if (typeof emailer.send === 'function') {
36
- if (emailer.send.length === 3) {
37
- attempts.push(() => emailer.send(template, toEmail, dataWithSubject));
38
- } else {
35
+ if (subject) {
39
36
  attempts.push(() => emailer.send(template, toEmail, subject, dataWithSubject));
40
37
  attempts.push(() => emailer.send(template, toEmail, dataWithSubject, subject));
41
- attempts.push(() => emailer.send(template, toEmail, dataWithSubject));
42
38
  }
39
+ attempts.push(() => emailer.send(template, toEmail, dataWithSubject));
43
40
  }
44
41
 
45
42
  let lastErr = null;
@@ -26,31 +26,34 @@ const PROCESSED_KEY = 'calendar-onekite:helloasso:processedPayments';
26
26
  async function sendEmail(template, toEmail, subject, data) {
27
27
  if (!toEmail) return;
28
28
  const emailer = require.main.require('./src/emailer');
29
+ const dataWithSubject = Object.assign({}, data || {}, subject ? { subject, _subject: subject } : {});
29
30
  try {
31
+ const attempts = [];
30
32
  if (typeof emailer.sendToEmail === 'function') {
31
- // NodeBB versions differ:
32
- // - sendToEmail(template, email, subject, data)
33
- // - sendToEmail(template, email, data)
34
- if (emailer.sendToEmail.length >= 4) {
35
- await emailer.sendToEmail(template, toEmail, subject, data);
36
- } else {
37
- const dataWithSubject = Object.assign({}, data || {}, { subject });
38
- await emailer.sendToEmail(template, toEmail, dataWithSubject);
33
+ if (subject) {
34
+ attempts.push(() => emailer.sendToEmail(template, toEmail, subject, dataWithSubject));
35
+ attempts.push(() => emailer.sendToEmail(template, toEmail, dataWithSubject, subject));
39
36
  }
40
- return;
37
+ attempts.push(() => emailer.sendToEmail(template, toEmail, dataWithSubject));
41
38
  }
42
39
  if (typeof emailer.send === 'function') {
43
- if (emailer.send.length >= 4) {
44
- await emailer.send(template, toEmail, subject, data);
45
- return;
40
+ if (subject) {
41
+ attempts.push(() => emailer.send(template, toEmail, subject, dataWithSubject));
42
+ attempts.push(() => emailer.send(template, toEmail, dataWithSubject, subject));
46
43
  }
47
- if (emailer.send.length === 3) {
48
- const dataWithSubject = Object.assign({}, data || {}, { subject });
49
- await emailer.send(template, toEmail, dataWithSubject);
44
+ attempts.push(() => emailer.send(template, toEmail, dataWithSubject));
45
+ }
46
+
47
+ let lastErr = null;
48
+ for (const fn of attempts) {
49
+ try {
50
+ await fn();
50
51
  return;
52
+ } catch (e) {
53
+ lastErr = e;
51
54
  }
52
- await emailer.send(template, toEmail, subject, data);
53
55
  }
56
+ if (lastErr) throw lastErr;
54
57
  } catch (err) {
55
58
  // eslint-disable-next-line no-console
56
59
  console.warn('[calendar-onekite] Failed to send email (webhook)', { template, toEmail, err: String(err && err.message || err) });
package/lib/scheduler.js CHANGED
@@ -58,21 +58,34 @@ async function processAwaitingPayment() {
58
58
  async function sendEmail(template, toEmail, subject, data) {
59
59
  if (!toEmail) return;
60
60
  try {
61
- if (typeof emailer.sendToEmail === 'function') {
62
- await emailer.sendToEmail(template, toEmail, subject, data);
63
- return;
61
+ const dataWithSubject = Object.assign({}, data || {}, subject ? { subject, _subject: subject } : {});
62
+
63
+ const attempts = [];
64
+ if (typeof emailer.sendToEmail === 'function') {
65
+ if (subject) {
66
+ attempts.push(() => emailer.sendToEmail(template, toEmail, subject, dataWithSubject));
67
+ attempts.push(() => emailer.sendToEmail(template, toEmail, dataWithSubject, subject));
64
68
  }
65
- if (typeof emailer.send === 'function') {
66
- if (emailer.send.length >= 4) {
67
- await emailer.send(template, toEmail, subject, data);
68
- return;
69
- }
70
- if (emailer.send.length === 3) {
71
- await emailer.send(template, toEmail, data);
69
+ attempts.push(() => emailer.sendToEmail(template, toEmail, dataWithSubject));
70
+ }
71
+ if (typeof emailer.send === 'function') {
72
+ if (subject) {
73
+ attempts.push(() => emailer.send(template, toEmail, subject, dataWithSubject));
74
+ attempts.push(() => emailer.send(template, toEmail, dataWithSubject, subject));
75
+ }
76
+ attempts.push(() => emailer.send(template, toEmail, dataWithSubject));
77
+ }
78
+
79
+ let lastErr = null;
80
+ for (const fn of attempts) {
81
+ try {
82
+ await fn();
72
83
  return;
84
+ } catch (e) {
85
+ lastErr = e;
73
86
  }
74
- await emailer.send(template, toEmail, subject, data);
75
87
  }
88
+ if (lastErr) throw lastErr;
76
89
  } catch (err) {
77
90
  // eslint-disable-next-line no-console
78
91
  console.warn('[calendar-onekite] Failed to send email (scheduler)', { template, toEmail, err: String(err && err.message || err) });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-calendar-onekite",
3
- "version": "11.1.77",
3
+ "version": "11.1.79",
4
4
  "description": "FullCalendar-based equipment reservation workflow with admin approval & HelloAsso payment for NodeBB",
5
5
  "main": "library.js",
6
6
  "license": "MIT",
package/plugin.json CHANGED
@@ -27,14 +27,11 @@
27
27
  "public": "./public"
28
28
  },
29
29
  "templates": "./templates",
30
- "modules": {
31
- "admin/plugins/calendar-onekite": "./public/admin.js"
32
- },
33
30
  "scripts": [
34
31
  "public/client.js"
35
32
  ],
36
33
  "acpScripts": [
37
34
  "public/admin.js"
38
35
  ],
39
- "version": "1.0.54"
36
+ "version": "1.0.56"
40
37
  }