@go-mailer/jarvis 6.0.0 → 7.0.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.
@@ -1,12 +1,23 @@
1
1
  const axios = require("axios").default;
2
2
  const Env = require("../env");
3
+ const { fetchTenants } = require("./iam");
3
4
  const USERS_URI = Env.fetch("USERS_SERVICE_URI", true);
4
5
  const GM_API_KEY = Env.fetch("GM_API_KEY", true);
5
6
 
6
- const updateContact = async (email, data = {}) => {
7
+ const updateContact = async (tenant_id, data = {}) => {
8
+ const {
9
+ tenants: [tenant]
10
+ } = await fetchTenants(`id=${tenant_id}`)
11
+
12
+ if (!tenant) throw new Error('Cannot trigger event for tenant')
13
+ const {
14
+ emails: [email],
15
+ name
16
+ } = tenant
17
+
7
18
  await axios.post(
8
19
  `${USERS_URI}/api/contacts`,
9
- { email, ...data },
20
+ { email, name, ...data },
10
21
  { headers: { Authorization: `Bearer ${GM_API_KEY}` } }
11
22
  );
12
23
  };
@@ -52,8 +52,8 @@ const extractToken = (headers) => {
52
52
  // main
53
53
 
54
54
  const authenticateAdmin = async (request, response, next) => {
55
- const { is_admin } = request
56
- if (!is_admin) return response.status(403).json(Errors.UNAUTHORIZED)
55
+ const { is_admin, is_service_request } = request
56
+ if (!is_admin && !is_service_request) return response.status(403).json(Errors.UNAUTHORIZED)
57
57
 
58
58
  next()
59
59
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@go-mailer/jarvis",
3
- "version": "6.0.0",
3
+ "version": "7.0.1",
4
4
  "main": "index.js",
5
5
  "repository": "git@github.com:go-mailer-ltd/jarvis-node.git",
6
6
  "author": "Nathan Oguntuberu <nateoguns.work@gmail.com>",