corebasic 1.0.93 → 1.0.95
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/libs/features.js +11 -2
- package/libs/session.js +6 -1
- package/package.json +1 -1
package/libs/features.js
CHANGED
|
@@ -3,7 +3,7 @@ import * as Kafka from './kafka.js'
|
|
|
3
3
|
import * as Utils from './utils.js'
|
|
4
4
|
import * as Messaging from './messaging.js'
|
|
5
5
|
import axios from 'axios'
|
|
6
|
-
|
|
6
|
+
import jwt from 'jsonwebtoken'
|
|
7
7
|
|
|
8
8
|
let features = {}
|
|
9
9
|
let apis = {}
|
|
@@ -16,6 +16,8 @@ let SLYP_FEATURES_LIST = {}
|
|
|
16
16
|
let appId = Utils.uid()
|
|
17
17
|
let SERVICE_ADDRESS = process.env.APP_ENDPOINT || 'http://127.0.0.1:3000'
|
|
18
18
|
|
|
19
|
+
const DEPLOY_TOKEN_SECRET = process.env.DEPLOY_TOKEN_SECRET || "MY_SECRET_DEPLOY_TOKEN"
|
|
20
|
+
const SERVICE_ACCESS_TOKEN = jwt.sign({app: process.env.APP_DEPLOYMENT_NAME}, DEPLOY_TOKEN_SECRET, { expiresIn: '365d' });
|
|
19
21
|
|
|
20
22
|
export const send = async (feature, params, payload, headers) => {
|
|
21
23
|
const throwError = () => {throw {message: `Feature ${feature} not found in internal or external list during inter feature call`}}
|
|
@@ -32,7 +34,8 @@ export const send = async (feature, params, payload, headers) => {
|
|
|
32
34
|
|
|
33
35
|
payload = { ...payload, feature, txn: Utils.uid() }
|
|
34
36
|
|
|
35
|
-
return (await axios[method](`${service}${url}`, { data: payload, headers: {jwt: headers.jwt}, timeout: 1000 })).data
|
|
37
|
+
// return (await axios[method](`${service}${url}`, { data: payload, headers: {jwt: headers.jwt}, timeout: 1000 })).data
|
|
38
|
+
return (await axios[method](`${service}${url}`, { data: payload, headers: {jwt: SERVICE_ACCESS_TOKEN, service: true}, timeout: 1000 })).data
|
|
36
39
|
}
|
|
37
40
|
|
|
38
41
|
let appids = {}
|
|
@@ -57,6 +60,12 @@ export const start = async (app, url, file) => {
|
|
|
57
60
|
features = await Utils.fileToJson(url, file)
|
|
58
61
|
await announce()
|
|
59
62
|
|
|
63
|
+
app.get('/features', async (req, res) => {
|
|
64
|
+
let exp_features = {}
|
|
65
|
+
for (let [key, {api}] of Object.entries(features))
|
|
66
|
+
exp_features[key] = {api, service: `${SERVICE_ADDRESS}`}
|
|
67
|
+
res.json({ data: { ...SLYP_FEATURES_LIST, ...exp_features } })
|
|
68
|
+
})
|
|
60
69
|
|
|
61
70
|
// Registering handlers
|
|
62
71
|
for (let name in features) {
|
package/libs/session.js
CHANGED
|
@@ -7,6 +7,8 @@ let app
|
|
|
7
7
|
const ACCESS_TOKEN_SECRET = process.env.JWT_ACCESS_TOKEN_SECRET || "MY_SECRET_ACCESS_TOKEN";
|
|
8
8
|
const REFRESH_TOKEN_SECRET = process.env.JWT_REFRESH_TOKEN_SECRET || "MY_SECRET_REFRESH_TOKEN";
|
|
9
9
|
|
|
10
|
+
const DEPLOY_TOKEN_SECRET = process.env.DEPLOY_TOKEN_SECRET || "MY_SECRET_DEPLOY_TOKEN"
|
|
11
|
+
|
|
10
12
|
let urlsAllowed = []
|
|
11
13
|
|
|
12
14
|
export const start = (expressApp, allowedUrls) => {
|
|
@@ -23,7 +25,10 @@ export const start = (expressApp, allowedUrls) => {
|
|
|
23
25
|
|
|
24
26
|
try {
|
|
25
27
|
const token = req.header('JWT'); // 'Authorization' for Spring Boot, 'x-access-token' for Node.js Express back-end
|
|
26
|
-
|
|
28
|
+
const service = req.header('SERVICE'); // Case insensitive search
|
|
29
|
+
if (service && jwt.verify(token, DEPLOY_TOKEN_SECRET))
|
|
30
|
+
return next()
|
|
31
|
+
else if (jwt.verify(token, ACCESS_TOKEN_SECRET))
|
|
27
32
|
return next()
|
|
28
33
|
throw null;
|
|
29
34
|
} catch (error) {
|