@openneuro/server 4.4.2 → 4.4.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openneuro/server",
3
- "version": "4.4.2",
3
+ "version": "4.4.3",
4
4
  "description": "Core service for the OpenNeuro platform.",
5
5
  "license": "MIT",
6
6
  "main": "src/server.js",
@@ -50,8 +50,7 @@
50
50
  "mongoose": "5.12.3",
51
51
  "morgan": "^1.6.1",
52
52
  "node-fetch": "^2.6.0",
53
- "nodemailer": "^6.7.2",
54
- "nodemailer-mailjet-transport": "^1.0.4",
53
+ "node-mailjet": "^3.3.5",
55
54
  "object-hash": "2.1.1",
56
55
  "passport": "^0.4.0",
57
56
  "passport-globus": "^0.0.1",
@@ -83,7 +82,7 @@
83
82
  "@types/draft-js": "^0.10.43",
84
83
  "@types/ioredis": "^4.17.1",
85
84
  "@types/jest": "^26.0.23",
86
- "@types/nodemailer": "^6.4.1",
85
+ "@types/node-mailjet": "^3",
87
86
  "@types/semver": "^5",
88
87
  "apollo-link-schema": "^1.2.5",
89
88
  "babel-eslint": "^10.1.0",
@@ -105,5 +104,5 @@
105
104
  "publishConfig": {
106
105
  "access": "public"
107
106
  },
108
- "gitHead": "453eb4503d1f98b9fa13f86ee810ad376a8391bc"
107
+ "gitHead": "1f7523d0925047a02597242f68efd9c1c42cc695"
109
108
  }
@@ -4,5 +4,6 @@ config.auth.jwt.secret = '123456'
4
4
  config.datalad.uri = 'datalad'
5
5
  config.datalad.workers = 4
6
6
  config.mongo.url = 'mongodb://'
7
+ config.notifications.email.from = 'notifications@example.com'
7
8
 
8
9
  export default config
@@ -0,0 +1,24 @@
1
+ import { mailjetFormat } from '../index'
2
+
3
+ jest.mock('../../../config.js')
4
+
5
+ describe('Mailjet formatter', () => {
6
+ it('formats a message', () => {
7
+ const testMessage = {
8
+ to: 'test@example.com',
9
+ name: 'Test User',
10
+ html: 'email content goes here',
11
+ subject: 'subject line',
12
+ }
13
+ expect(mailjetFormat(testMessage)).toEqual({
14
+ Messages: [
15
+ {
16
+ From: { Email: 'notifications@example.com', Name: 'OpenNeuro' },
17
+ HTMLPart: 'email content goes here',
18
+ Subject: 'subject line',
19
+ To: [{ Email: 'test@example.com', Name: 'Test User' }],
20
+ },
21
+ ],
22
+ })
23
+ })
24
+ })
@@ -1,41 +1,46 @@
1
- import nodemailer from 'nodemailer'
2
-
3
1
  import config from '../../config'
4
2
 
5
- // setup email transporter
6
- let transporter
3
+ let transport
4
+ let perform_api_call = true
7
5
  try {
8
- const mailjetTransport = require('nodemailer-mailjet-transport')
9
- transporter = nodemailer.createTransport(
10
- mailjetTransport({
11
- auth: {
12
- apiKey: config.notifications.email.apiKey,
13
- apiSecret: config.notifications.email.secret,
14
- },
15
- }),
6
+ const mailjet = require('node-mailjet')
7
+ transport = mailjet.connect(
8
+ config.notifications.email.apiKey,
9
+ config.notifications.email.secret,
16
10
  )
17
11
  } catch (err) {
18
- // Mailjet is not configured, instead log emails
19
- transporter = {
20
- sendMail: (mail, cb) => {
21
- console.dir(mail)
22
- },
23
- }
12
+ perform_api_call = false
24
13
  }
25
14
 
26
- export const send = (
27
- email: Record<string, string>,
28
- callback: (err, response) => void,
29
- ): void => {
30
- // configure mail options
31
- const mailOptions = {
32
- from: `"OpenNeuro" <${config.notifications.email.from}>`,
33
- replyTo: config.notifications.email.from,
34
- to: email.to,
35
- subject: email.subject,
36
- html: email.html,
37
- }
15
+ export const mailjetFormat = (email: Record<string, string>) => ({
16
+ Messages: [
17
+ {
18
+ From: {
19
+ Email: config.notifications.email.from,
20
+ Name: 'OpenNeuro',
21
+ },
22
+ To: [
23
+ {
24
+ Email: email.to,
25
+ Name: email.name,
26
+ },
27
+ ],
28
+ Subject: email.subject,
29
+ HTMLPart: email.html,
30
+ },
31
+ ],
32
+ })
38
33
 
39
- // send email
40
- transporter.sendMail(mailOptions, callback)
34
+ /**
35
+ * Send via Mailjet
36
+ * @param email Nodemailer style email record
37
+ */
38
+ export const send = (email: Record<string, string>): Promise<Response> => {
39
+ // Mailjet is not configured, instead log emails
40
+ if (!perform_api_call) {
41
+ console.dir(email)
42
+ }
43
+ return transport
44
+ .post('send', { version: 'v3.1', perform_api_call })
45
+ .request(mailjetFormat(email))
41
46
  }
@@ -18,19 +18,15 @@ import { snapshotReminder } from '../libs/email/templates/snapshot-reminder'
18
18
  import { datasetImportEmail } from '../libs/email/templates/dataset-imported'
19
19
  import { datasetImportFailed } from '../libs/email/templates/dataset-import-failed'
20
20
 
21
- function noop() {
22
- // No callback helper
23
- }
24
-
25
21
  // public api ---------------------------------------------
26
22
 
27
23
  const notifications = {
28
24
  /**
29
25
  * Send
30
26
  */
31
- send(notification, callback) {
27
+ send(notification) {
32
28
  if (notification.type === 'email') {
33
- emailSend(notification.email, callback)
29
+ emailSend(notification.email)
34
30
  }
35
31
  },
36
32
 
@@ -74,6 +70,7 @@ const notifications = {
74
70
  type: 'email',
75
71
  email: {
76
72
  to: user.email,
73
+ name: user.name,
77
74
  subject: 'Snapshot Created',
78
75
  html: snapshotCreated({
79
76
  name: user.name,
@@ -89,7 +86,7 @@ const notifications = {
89
86
  },
90
87
  }
91
88
  // send the email
92
- notifications.send(emailContent, noop)
89
+ notifications.send(emailContent)
93
90
  }
94
91
  })
95
92
  },
@@ -138,6 +135,7 @@ const notifications = {
138
135
  type: 'email',
139
136
  email: {
140
137
  to: user.email,
138
+ name: user.name,
141
139
  from:
142
140
  'reply-' +
143
141
  encodeURIComponent(comment._id) +
@@ -161,7 +159,7 @@ const notifications = {
161
159
  },
162
160
  }
163
161
  // send each email to the notification database for distribution
164
- notifications.send(emailContent, noop)
162
+ notifications.send(emailContent)
165
163
  }
166
164
  })
167
165
  })
@@ -195,6 +193,7 @@ const notifications = {
195
193
  type: 'email',
196
194
  email: {
197
195
  to: user.email,
196
+ name: user.name,
198
197
  subject: 'Dataset Deleted',
199
198
  html: datasetDeleted({
200
199
  name: user.name,
@@ -206,7 +205,7 @@ const notifications = {
206
205
  }),
207
206
  },
208
207
  }
209
- notifications.send(emailContent, noop)
208
+ notifications.send(emailContent)
210
209
  }
211
210
  })
212
211
  })
@@ -244,6 +243,7 @@ const notifications = {
244
243
  type: 'email',
245
244
  email: {
246
245
  to: user.email,
246
+ name: user.name,
247
247
  subject: 'Owner Unsubscribed',
248
248
  html: ownerUnsubscribed({
249
249
  name: user.name,
@@ -255,7 +255,7 @@ const notifications = {
255
255
  }),
256
256
  },
257
257
  }
258
- notifications.send(emailContent, noop)
258
+ notifications.send(emailContent)
259
259
  }
260
260
  })
261
261
  })
@@ -294,6 +294,7 @@ const notifications = {
294
294
  type: 'email',
295
295
  email: {
296
296
  to: user.email,
297
+ name: user.name,
297
298
  subject: 'Snapshot Reminder',
298
299
  html: snapshotReminder({
299
300
  name: user.name,
@@ -307,7 +308,7 @@ const notifications = {
307
308
  },
308
309
  }
309
310
  // send each email to the notification database for distribution
310
- notifications.send(emailContent, noop)
311
+ notifications.send(emailContent)
311
312
  }
312
313
  })
313
314
  })
@@ -351,12 +352,13 @@ const notifications = {
351
352
  type: 'email',
352
353
  email: {
353
354
  to: user.email,
355
+ name: user.name,
354
356
  subject: `Dataset Import ${success ? 'Success' : 'Failed'}`,
355
357
  html: html,
356
358
  },
357
359
  }
358
360
  // send the email to the notifications database for distribution
359
- notifications.send(emailContent, noop)
361
+ notifications.send(emailContent)
360
362
  },
361
363
  }
362
364