corebasic 1.0.96 → 1.0.97
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 +21 -2
- package/libs/utils.js +12 -1
- package/package.json +1 -1
package/libs/features.js
CHANGED
|
@@ -12,7 +12,26 @@ 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
|
+
async function loadLocalFeatures() { // For Local Testing
|
|
16
|
+
let data = {}
|
|
17
|
+
if (process.env.LOAD_LOCAL_FEATURES) {
|
|
18
|
+
try {
|
|
19
|
+
let url = 'https://slyp.app/slyp-main-dev/api/v1/features'
|
|
20
|
+
let result = (await axios.get(url, { data: {}, headers: {jwt: SERVICE_ACCESS_TOKEN, service: true}, timeout: 1000 })).data
|
|
21
|
+
await Utils.stringToFile('/.slyp/features.json', JSON.stringify(result.data, null, '\t'))
|
|
22
|
+
} catch {
|
|
23
|
+
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
data = JSON.parse(await Utils.fileToString('/.slyp/features.json'))
|
|
27
|
+
} catch {
|
|
28
|
+
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return data
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
let SLYP_FEATURES_LIST = await loadLocalFeatures()
|
|
16
35
|
let appId = Utils.uid()
|
|
17
36
|
let SERVICE_ADDRESS = process.env.APP_ENDPOINT || 'http://127.0.0.1:3000'
|
|
18
37
|
|
|
@@ -64,7 +83,7 @@ export const start = async (app, url, file) => {
|
|
|
64
83
|
let exp_features = {}
|
|
65
84
|
for (let [key, {api}] of Object.entries(features))
|
|
66
85
|
exp_features[key] = {api, service: `${SERVICE_ADDRESS}`}
|
|
67
|
-
if (process.env.
|
|
86
|
+
if (process.env.LOAD_LOCAL_FEATURES) {
|
|
68
87
|
for (let key in SLYP_FEATURES_LIST)
|
|
69
88
|
SLYP_FEATURES_LIST[key].headers = {JWT: SERVICE_ACCESS_TOKEN, service: true}
|
|
70
89
|
}
|
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
|
// ----------------
|