corebasic 1.0.96 → 1.0.98
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 +24 -4
- package/libs/utils.js +12 -1
- package/package.json +1 -1
package/libs/features.js
CHANGED
|
@@ -12,12 +12,32 @@ const getFeatureMethod = api => api.split(' ')[0].toLowerCase()
|
|
|
12
12
|
const getFeatureUrl = api => api.split(' ')[1]
|
|
13
13
|
const getFeature = name => features[name]
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
const DEPLOY_TOKEN_SECRET = process.env.DEPLOY_TOKEN_SECRET || "MY_SECRET_DEPLOY_TOKEN"
|
|
16
|
+
const SERVICE_ACCESS_TOKEN = jwt.sign({app: process.env.APP_DEPLOYMENT_NAME}, DEPLOY_TOKEN_SECRET, { expiresIn: '365d' });
|
|
17
|
+
|
|
18
|
+
async function loadLocalFeatures() { // For Local Testing
|
|
19
|
+
let data = {}
|
|
20
|
+
if (process.env.LOAD_LOCAL_FEATURES) {
|
|
21
|
+
try {
|
|
22
|
+
let url = 'https://slyp.app/slyp-main-dev/api/v1/features'
|
|
23
|
+
let result = (await axios.get(url, { data: {}, headers: {jwt: SERVICE_ACCESS_TOKEN, service: true}, timeout: 1000 })).data
|
|
24
|
+
await Utils.stringToFile('/slyp.local.features.json', JSON.stringify(result.data, null, '\t'))
|
|
25
|
+
} catch {
|
|
26
|
+
console.log('Error Fetching Remote Features')
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
data = JSON.parse(await Utils.fileToString('/slyp.local.features.json'))
|
|
30
|
+
} catch {
|
|
31
|
+
console.log('Error Loading Remote Features')
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return data
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
let SLYP_FEATURES_LIST = await loadLocalFeatures()
|
|
16
38
|
let appId = Utils.uid()
|
|
17
39
|
let SERVICE_ADDRESS = process.env.APP_ENDPOINT || 'http://127.0.0.1:3000'
|
|
18
40
|
|
|
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' });
|
|
21
41
|
|
|
22
42
|
export const send = async (feature, params, payload, headers) => {
|
|
23
43
|
const throwError = () => {throw {message: `Feature ${feature} not found in internal or external list during inter feature call`}}
|
|
@@ -64,7 +84,7 @@ export const start = async (app, url, file) => {
|
|
|
64
84
|
let exp_features = {}
|
|
65
85
|
for (let [key, {api}] of Object.entries(features))
|
|
66
86
|
exp_features[key] = {api, service: `${SERVICE_ADDRESS}`}
|
|
67
|
-
if (process.env.
|
|
87
|
+
if (process.env.LOAD_LOCAL_FEATURES) {
|
|
68
88
|
for (let key in SLYP_FEATURES_LIST)
|
|
69
89
|
SLYP_FEATURES_LIST[key].headers = {JWT: SERVICE_ACCESS_TOKEN, service: true}
|
|
70
90
|
}
|
package/libs/utils.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as ObjectId from './ObjectId.js'
|
|
2
2
|
|
|
3
3
|
// Parse JSON file: fileToJson
|
|
4
|
-
import {readFile} from 'fs/promises';
|
|
4
|
+
import {readFile,writeFile} from 'fs/promises';
|
|
5
5
|
import 'jsonminify'
|
|
6
6
|
|
|
7
7
|
// S3 Object Storage
|
|
@@ -157,6 +157,17 @@ export async function fileToJson(path, file) {
|
|
|
157
157
|
return JSON.parse(JSON.minify(data))
|
|
158
158
|
}
|
|
159
159
|
|
|
160
|
+
// ----------------
|
|
161
|
+
// File
|
|
162
|
+
// ----------------
|
|
163
|
+
|
|
164
|
+
export async function fileToString(file) {
|
|
165
|
+
return await readFile(file, 'utf8')
|
|
166
|
+
}
|
|
167
|
+
export async function stringToFile(file, data) {
|
|
168
|
+
return await writeFile(file, data)
|
|
169
|
+
}
|
|
170
|
+
|
|
160
171
|
// ----------------
|
|
161
172
|
// Pipeline Execute
|
|
162
173
|
// ----------------
|