tom-microservice 3.5.2 → 3.5.4

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
@@ -2,7 +2,7 @@
2
2
  "name": "tom-microservice",
3
3
  "description": "Tom creates customers, subscriptions plans & send notifications.",
4
4
  "homepage": "https://tom.js.org",
5
- "version": "3.5.2",
5
+ "version": "3.5.4",
6
6
  "main": "src",
7
7
  "bin": {
8
8
  "tom": "bin/index.js"
@@ -43,7 +43,6 @@
43
43
  "beauty-error": "~1.2.15",
44
44
  "cors": "~2.8.5",
45
45
  "country-vat": "~1.0.8",
46
- "emittery": "~0.13.1",
47
46
  "got": "~11.8.6",
48
47
  "helmet": "~6.1.2",
49
48
  "http-body": "~1.0.4",
@@ -56,6 +55,7 @@
56
55
  "mailgen": "~2.0.27",
57
56
  "map-values-deep": "~1.0.2",
58
57
  "meow": "~9.0.0",
58
+ "mitt": "~3.0.0",
59
59
  "morgan": "~1.10.0",
60
60
  "nodemailer": "~6.9.1",
61
61
  "ow": "~0.28.2",
@@ -1,7 +1,20 @@
1
1
  'use strict'
2
2
 
3
3
  const { isFunction, get, set } = require('lodash')
4
- const Emittery = require('emittery')
4
+ const mitt = require('mitt')
5
+
6
+ const createEmitter = () => {
7
+ const emitter = mitt()
8
+ emitter.emitAsync = (type, data) =>
9
+ Promise.all(
10
+ []
11
+ .concat(emitter.all.get('*'))
12
+ .concat(emitter.all.get(type))
13
+ .filter(Boolean)
14
+ .map(fn => fn(data))
15
+ )
16
+ return emitter
17
+ }
5
18
 
6
19
  const setEnv = (config, configKey, globalEnvKey) => {
7
20
  const globalEnvValue = get(process.env, globalEnvKey)
@@ -11,9 +24,9 @@ const setEnv = (config, configKey, globalEnvKey) => {
11
24
 
12
25
  module.exports = fn => {
13
26
  let config
14
- const emitter = new Emittery()
27
+ const emitter = createEmitter()
15
28
  const on = (eventName, listener) => emitter.on(eventName, listener)
16
- const emit = (eventName, data) => emitter.emit(eventName, data)
29
+ const emit = (eventName, data) => emitter.emitAsync(eventName, data)
17
30
  const setConfig = obj => (config = obj)
18
31
 
19
32
  if (isFunction(fn)) fn({ setConfig, on })
package/src/routes.js CHANGED
@@ -1,8 +1,8 @@
1
1
  'use strict'
2
2
 
3
3
  const { get, eq, forEach } = require('lodash')
4
+ const { buffer, text } = require('http-body')
4
5
  const requestIp = require('request-ip')
5
- const { text } = require('http-body')
6
6
  const toQuery = require('to-query')()
7
7
  const Router = require('router-http')
8
8
  const send = require('./send')
@@ -21,11 +21,13 @@ const UNAUTHENTICATED_PATHS = [
21
21
  ]
22
22
 
23
23
  const getBody = async req => {
24
- const string = await text(req)
24
+ if (req.path === '/payment/webhook') return buffer(req)
25
+ const body = await text(req)
26
+ if (body === '') return body
25
27
  try {
26
- return JSON.parse(string)
28
+ return JSON.parse(body)
27
29
  } catch (_) {
28
- return string
30
+ return body
29
31
  }
30
32
  }
31
33