tom-microservice 3.8.0 → 3.9.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/README.md CHANGED
@@ -466,7 +466,7 @@ See [cors](https://github.com/expressjs/cors#configuration-options) for more inf
466
466
  Type: `string` </br>
467
467
  Default: `undefined`
468
468
 
469
- When you provide it, all request to **tom** 🐶 needs to be authenticated using `x-api-key` header and the value provided.
469
+ When you provide it, all request to **tom** 🐶 needs to be authenticated using `req.headers[`x-api-key`] or `req.query.apiKey` and the value provided.
470
470
 
471
471
  You can use [randomkeygen.com](https://randomkeygen.com) for that.
472
472
 
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.8.0",
5
+ "version": "3.9.1",
6
6
  "main": "src",
7
7
  "bin": {
8
8
  "tom": "bin/index.js"
package/src/routes.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict'
2
2
 
3
- const { get, eq, forEach, noop } = require('lodash')
3
+ const { eq, forEach, noop } = require('lodash')
4
4
  const { buffer, text } = require('http-body')
5
5
  const requestIp = require('request-ip')
6
6
  const toQuery = require('to-query')()
@@ -78,7 +78,8 @@ const createRouter = () => {
78
78
  if (TOM_API_KEY) {
79
79
  router.use((req, res, next) => {
80
80
  if (UNAUTHENTICATED_PATHS.includes(req.path)) return next()
81
- const apiKey = get(req, 'headers.x-api-key')
81
+ const apiKey = req.headers['x-api-key'] ?? req.query.apiKey
82
+
82
83
  return eq(apiKey, TOM_API_KEY)
83
84
  ? next()
84
85
  : send.fail(