@go-mailer/jarvis 8.1.0 → 9.0.0
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/lib/clients/iam.js +35 -34
- package/package.json +1 -1
package/lib/clients/iam.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
const axios = require(
|
|
2
|
-
const Env = require(
|
|
3
|
-
const IAM_URI = Env.fetch(
|
|
4
|
-
const
|
|
1
|
+
const axios = require("axios").default;
|
|
2
|
+
const Env = require("../env");
|
|
3
|
+
const IAM_URI = Env.fetch("IAM_SERVICE_URI", true);
|
|
4
|
+
const API_SERVICE_URI = Env.fetch("API_SERVICE_URI", true);
|
|
5
|
+
const DEFAULT_TOKEN = Env.fetch("DEFAULT_TOKEN", true);
|
|
5
6
|
|
|
6
7
|
const checkAuthority = async ({ action, resource, user_id, tenant_id }) => {
|
|
7
8
|
const { error, payload } = (
|
|
@@ -9,41 +10,41 @@ const checkAuthority = async ({ action, resource, user_id, tenant_id }) => {
|
|
|
9
10
|
action,
|
|
10
11
|
resource,
|
|
11
12
|
tenant_id,
|
|
12
|
-
user_id
|
|
13
|
+
user_id,
|
|
13
14
|
})
|
|
14
|
-
).data
|
|
15
|
+
).data;
|
|
15
16
|
|
|
16
|
-
if (error || !payload.is_permitted) throw new Error(
|
|
17
|
-
return payload.is_permitted
|
|
18
|
-
}
|
|
17
|
+
if (error || !payload.is_permitted) throw new Error("Unauthorized");
|
|
18
|
+
return payload.is_permitted;
|
|
19
|
+
};
|
|
19
20
|
|
|
20
|
-
const fetchTenants = async (query =
|
|
21
|
+
const fetchTenants = async (query = "") => {
|
|
21
22
|
const { data: response } = await axios.get(`${IAM_URI}/tenants?${query}`, {
|
|
22
23
|
headers: {
|
|
23
|
-
authorization: `Bearer ${DEFAULT_TOKEN}
|
|
24
|
-
}
|
|
25
|
-
})
|
|
24
|
+
authorization: `Bearer ${DEFAULT_TOKEN}`,
|
|
25
|
+
},
|
|
26
|
+
});
|
|
26
27
|
|
|
27
|
-
const { error, payload } = response
|
|
28
|
-
if (error) throw new Error(error)
|
|
28
|
+
const { error, payload } = response;
|
|
29
|
+
if (error) throw new Error(error);
|
|
29
30
|
|
|
30
|
-
const { data: tenants, meta } = payload
|
|
31
|
-
return { tenants, size: meta?.size || 0 }
|
|
32
|
-
}
|
|
31
|
+
const { data: tenants, meta } = payload;
|
|
32
|
+
return { tenants, size: meta?.size || 0 };
|
|
33
|
+
};
|
|
33
34
|
|
|
34
35
|
const verifyAPIKey = async (key) => {
|
|
35
36
|
const { error, payload } = (
|
|
36
|
-
await axios.get(`${
|
|
37
|
+
await axios.get(`${API_SERVICE_URI}/keys/verify/${key}`, {
|
|
37
38
|
headers: {
|
|
38
|
-
authorization: `Bearer ${DEFAULT_TOKEN}
|
|
39
|
-
}
|
|
39
|
+
authorization: `Bearer ${DEFAULT_TOKEN}`,
|
|
40
|
+
},
|
|
40
41
|
})
|
|
41
|
-
).data
|
|
42
|
+
).data;
|
|
42
43
|
|
|
43
|
-
if (error) throw new Error(
|
|
44
|
+
if (error) throw new Error("Unauthorized");
|
|
44
45
|
|
|
45
|
-
return payload.org_id
|
|
46
|
-
}
|
|
46
|
+
return payload.org_id;
|
|
47
|
+
};
|
|
47
48
|
|
|
48
49
|
const verifyFeatureFlag = async (flag_name, criteria = {}) => {
|
|
49
50
|
const { error, payload } = (
|
|
@@ -51,20 +52,20 @@ const verifyFeatureFlag = async (flag_name, criteria = {}) => {
|
|
|
51
52
|
`${IAM_URI}/flags`,
|
|
52
53
|
{
|
|
53
54
|
criteria,
|
|
54
|
-
environment: Env.fetch(
|
|
55
|
-
name: flag_name
|
|
55
|
+
environment: Env.fetch("NODE_ENV"),
|
|
56
|
+
name: flag_name,
|
|
56
57
|
},
|
|
57
58
|
{
|
|
58
59
|
headers: {
|
|
59
|
-
authorization: `Bearer ${DEFAULT_TOKEN}
|
|
60
|
-
}
|
|
60
|
+
authorization: `Bearer ${DEFAULT_TOKEN}`,
|
|
61
|
+
},
|
|
61
62
|
}
|
|
62
63
|
)
|
|
63
|
-
).data
|
|
64
|
+
).data;
|
|
64
65
|
|
|
65
|
-
if (error) throw new Error(error)
|
|
66
|
+
if (error) throw new Error(error);
|
|
66
67
|
|
|
67
|
-
return payload.is_permitted
|
|
68
|
-
}
|
|
68
|
+
return payload.is_permitted;
|
|
69
|
+
};
|
|
69
70
|
|
|
70
|
-
module.exports = { checkAuthority, fetchTenants, verifyAPIKey, verifyFeatureFlag }
|
|
71
|
+
module.exports = { checkAuthority, fetchTenants, verifyAPIKey, verifyFeatureFlag };
|