@openneuro/server 4.4.0-alpha.3 → 4.4.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openneuro/server",
3
- "version": "4.4.0-alpha.3",
3
+ "version": "4.4.1",
4
4
  "description": "Core service for the OpenNeuro platform.",
5
5
  "license": "MIT",
6
6
  "main": "src/server.js",
@@ -105,5 +105,5 @@
105
105
  "publishConfig": {
106
106
  "access": "public"
107
107
  },
108
- "gitHead": "cb9355079436f8cda06e05fa6e53d9bac97420e1"
108
+ "gitHead": "440518fe50a68319f9b26c387d8a8b2adee5344c"
109
109
  }
package/src/config.js CHANGED
@@ -42,10 +42,8 @@ const config = {
42
42
  },
43
43
  notifications: {
44
44
  email: {
45
- service: process.env.CRN_SERVER_MAIL_SERVICE,
46
- user: process.env.CRN_SERVER_MAIL_USER,
47
- url: process.env.CRN_SERVER_MAIL_URL,
48
- pass: process.env.CRN_SERVER_MAIL_PASS,
45
+ apiKey: process.env.CRN_SERVER_MAIL_API_KEY,
46
+ secret: process.env.CRN_SERVER_MAIL_API_SECRET,
49
47
  from: process.env.CRN_SERVER_MAIL_FROM,
50
48
  },
51
49
  },
@@ -1,33 +1,36 @@
1
1
  import nodemailer from 'nodemailer'
2
+
2
3
  import config from '../../config'
3
4
 
4
5
  // setup email transporter
5
- const transporter = nodemailer.createTransport({
6
- service: config.notifications.email.service,
7
- auth: {
8
- user:
9
- config.notifications.email.user + '@' + config.notifications.email.url,
10
- pass: config.notifications.email.pass,
11
- },
12
- })
6
+ let transporter
7
+ try {
8
+ const mailjetTransport = require('nodemailer-mailjet-transport')
9
+ transporter = nodemailer.createTransport(
10
+ mailjetTransport({
11
+ auth: {
12
+ apiKey: config.notifications.email.apiKey,
13
+ secret: config.notifications.email.secret,
14
+ },
15
+ }),
16
+ )
17
+ } catch (err) {
18
+ // Mailjet is not configured, instead log emails
19
+ transporter = {
20
+ sendMail: (mail, cb) => {
21
+ console.dir(mail)
22
+ },
23
+ }
24
+ }
13
25
 
14
26
  export const send = (
15
27
  email: Record<string, string>,
16
28
  callback: (err, response) => void,
17
29
  ): void => {
18
- // inline styles
19
- //html = juice(html)
20
-
21
- // determine if the main is from a specific sender
22
- // or the generic email address
23
- const user: string =
24
- email && email.from ? email.from : config.notifications.email.user
25
- const from = user + '@' + config.notifications.email.url
26
-
27
30
  // configure mail options
28
31
  const mailOptions = {
29
- from: '"OpenNeuro" <notifications@openneuro.org>',
30
- replyTo: from,
32
+ from: `"OpenNeuro" <${config.notifications.email.from}>`,
33
+ replyTo: config.notifications.email.from,
31
34
  to: email.to,
32
35
  subject: email.subject,
33
36
  html: email.html,
@@ -1,13 +1,9 @@
1
1
  /*eslint no-console: ["error", { allow: ["log"] }] */
2
- import toDate from 'date-fns/toDate'
3
- import subHours from 'date-fns/subHours'
4
2
  import config from '../config'
5
3
  import { send as emailSend } from './email'
6
4
  import request from 'superagent'
7
- import Notification from '../models/notification'
8
5
  import User from '../models/user'
9
6
  import Subscription from '../models/subscription'
10
- import MailgunIdentifier from '../models/mailgunIdentifier'
11
7
  import moment from 'moment'
12
8
  import url from 'url'
13
9
  import bidsId from './bidsId'
@@ -29,20 +25,6 @@ function noop() {
29
25
  // public api ---------------------------------------------
30
26
 
31
27
  const notifications = {
32
- /**
33
- * Add
34
- *
35
- * Takes a notification object and
36
- * adds it to the database to be processed by
37
- * the cron.
38
- */
39
- add(notification, callback) {
40
- Notification.updateOne({ _id: notification._id }, notification, {
41
- upsert: true,
42
- new: true,
43
- }).then(callback)
44
- },
45
-
46
28
  /**
47
29
  * Send
48
30
  */
@@ -106,8 +88,8 @@ const notifications = {
106
88
  }),
107
89
  },
108
90
  }
109
- // send the email to the notifications database for distribution
110
- notifications.add(emailContent, noop)
91
+ // send the email
92
+ notifications.send(emailContent, noop)
111
93
  }
112
94
  })
113
95
  },
@@ -179,7 +161,7 @@ const notifications = {
179
161
  },
180
162
  }
181
163
  // send each email to the notification database for distribution
182
- notifications.add(emailContent, noop)
164
+ notifications.send(emailContent, noop)
183
165
  }
184
166
  })
185
167
  })
@@ -224,8 +206,7 @@ const notifications = {
224
206
  }),
225
207
  },
226
208
  }
227
- // send each email to the notification database for distribution
228
- notifications.add(emailContent, noop)
209
+ notifications.send(emailContent, noop)
229
210
  }
230
211
  })
231
212
  })
@@ -274,8 +255,7 @@ const notifications = {
274
255
  }),
275
256
  },
276
257
  }
277
- // send each email to the notification database for distribution
278
- notifications.add(emailContent, noop)
258
+ notifications.send(emailContent, noop)
279
259
  }
280
260
  })
281
261
  })
@@ -327,7 +307,7 @@ const notifications = {
327
307
  },
328
308
  }
329
309
  // send each email to the notification database for distribution
330
- notifications.add(emailContent, noop)
310
+ notifications.send(emailContent, noop)
331
311
  }
332
312
  })
333
313
  })
@@ -371,49 +351,12 @@ const notifications = {
371
351
  type: 'email',
372
352
  email: {
373
353
  to: user.email,
374
- from: config.notifications.email.from,
375
354
  subject: `Dataset Import ${success ? 'Success' : 'Failed'}`,
376
355
  html: html,
377
356
  },
378
357
  }
379
358
  // send the email to the notifications database for distribution
380
- notifications.add(emailContent, noop)
381
- },
382
-
383
- initCron() {
384
- setInterval(() => {
385
- // After one hour, retry a notification even if we have a lock
386
- Notification.findOneAndUpdate(
387
- { notificationLock: { $lte: toDate(subHours(Date.now(), 1)) } },
388
- { $set: { notificationLock: new Date(Date.now()) } },
389
- ).exec((err, notification) => {
390
- if (err) {
391
- console.log(
392
- 'NOTIFICATION ERROR - Could not find notifications collection',
393
- )
394
- } else {
395
- if (notification) {
396
- notifications.send(notification, (err, response) => {
397
- if (!err) {
398
- notification.remove()
399
- if (response && response.messageId) {
400
- new MailgunIdentifier({
401
- messageId: response.messageId,
402
- }).save(err => {
403
- if (err) {
404
- throw `failed to save mailgunIdentifier ${response.messageId}`
405
- }
406
- })
407
- }
408
- } else {
409
- console.log('NOTIFICATION ERROR ----------')
410
- console.log(err)
411
- }
412
- })
413
- }
414
- }
415
- })
416
- }, 3600000)
359
+ notifications.send(emailContent, noop)
417
360
  },
418
361
  }
419
362
 
@@ -9,6 +9,7 @@ export interface NotificationDocument extends Document {
9
9
  from: string
10
10
  subject: string
11
11
  template: string
12
+ html: string
12
13
  data: {
13
14
  name: string
14
15
  appName: string
@@ -43,6 +44,7 @@ const notificationSchema = new Schema({
43
44
  from: String,
44
45
  subject: String,
45
46
  template: String,
47
+ html: String,
46
48
  data: {
47
49
  name: String,
48
50
  appName: String,
package/src/server.js CHANGED
@@ -8,7 +8,6 @@ import { createServer } from 'http'
8
8
  import mongoose from 'mongoose'
9
9
  import subscriptionServerFactory from './libs/subscription-server.js'
10
10
  import { connect as redisConnect } from './libs/redis'
11
- import notifications from './libs/notifications'
12
11
  import config from './config'
13
12
  import createApp from './app'
14
13
  import { version } from './lerna.json'
@@ -16,8 +15,6 @@ import { version } from './lerna.json'
16
15
  const redisConnectionSetup = async () => {
17
16
  try {
18
17
  await redisConnect(config.redis)
19
- // start background tasks
20
- notifications.initCron()
21
18
  } catch (err) {
22
19
  // eslint-disable-next-line no-console
23
20
  console.error(err)