corebasic 1.0.89 → 1.0.91
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 +17 -9
- package/libs/messaging.js +5 -5
- package/package.json +1 -1
package/libs/features.js
CHANGED
|
@@ -13,10 +13,13 @@ const getFeatureUrl = api => api.split(' ')[1]
|
|
|
13
13
|
const getFeature = name => features[name]
|
|
14
14
|
|
|
15
15
|
let SLYP_FEATURES_LIST = {}
|
|
16
|
+
let appId = Utils.uid()
|
|
17
|
+
let SERVICE_ADDRESS = process.env.APP_ENDPOINT || 'http://127.0.0.1:3000'
|
|
18
|
+
|
|
16
19
|
|
|
17
20
|
export const send = async (feature, params, payload, headers) => {
|
|
18
21
|
const throwError = () => {throw {message: `Feature ${feature} not found in internal or external list during inter feature call`}}
|
|
19
|
-
let {api} = getFeature(feature) ?? SLYP_FEATURES_LIST[feature] ?? throwError()
|
|
22
|
+
let {api, service = SERVICE_ADDRESS} = getFeature(feature) ?? SLYP_FEATURES_LIST[feature] ?? throwError()
|
|
20
23
|
let method = getFeatureMethod(api)
|
|
21
24
|
let url = getFeatureUrl(api)
|
|
22
25
|
|
|
@@ -29,23 +32,28 @@ export const send = async (feature, params, payload, headers) => {
|
|
|
29
32
|
|
|
30
33
|
payload = { ...payload, feature, txn: Utils.uid() }
|
|
31
34
|
|
|
32
|
-
return (await axios[method](
|
|
35
|
+
return (await axios[method](`${service}${url}`, { data: payload, headers: {jwt: headers.jwt}, timeout: 1000 })).data
|
|
33
36
|
}
|
|
34
37
|
|
|
35
|
-
async function
|
|
38
|
+
async function announce() {
|
|
36
39
|
let exp_features = {}
|
|
37
40
|
for (let [key, {api}] of Object.entries(features))
|
|
38
|
-
exp_features[key] = {api}
|
|
39
|
-
|
|
40
|
-
await Messaging.subscribe("SLYP_FEATURES_LIST", (message, channel) => {
|
|
41
|
-
|
|
41
|
+
exp_features[key] = {api, service: SERVICE_ADDRESS}
|
|
42
|
+
|
|
43
|
+
await Messaging.subscribe("SLYP_FEATURES_LIST", async (message, channel) => {
|
|
44
|
+
let msg = JSON.parse(message)
|
|
45
|
+
if (msg.uid !== appId) {
|
|
46
|
+
SLYP_FEATURES_LIST = {...SLYP_FEATURES_LIST, ...msg}
|
|
47
|
+
delete SLYP_FEATURES_LIST.uid
|
|
48
|
+
await Messaging.produce("SLYP_FEATURES_LIST", JSON.stringify({...exp_features, uid: appId }))
|
|
49
|
+
}
|
|
42
50
|
})
|
|
43
|
-
await Messaging.produce("SLYP_FEATURES_LIST", JSON.stringify(exp_features))
|
|
51
|
+
await Messaging.produce("SLYP_FEATURES_LIST", JSON.stringify({...exp_features, uid: appId }))
|
|
44
52
|
}
|
|
45
53
|
|
|
46
54
|
export const start = async (app, url, file) => {
|
|
47
55
|
features = await Utils.fileToJson(url, file)
|
|
48
|
-
await
|
|
56
|
+
await announce()
|
|
49
57
|
|
|
50
58
|
|
|
51
59
|
// Registering handlers
|
package/libs/messaging.js
CHANGED
|
@@ -94,15 +94,15 @@ export async function newProducer() {
|
|
|
94
94
|
return publisher
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
+
let defaultConsumer = await newConsumer()
|
|
98
|
+
let defaultProducer = await newProducer()
|
|
99
|
+
|
|
97
100
|
export async function subscribe(channel, listener) {
|
|
98
|
-
|
|
99
|
-
await consumer.subscribe(channel, listener)
|
|
101
|
+
await defaultConsumer.subscribe(channel, listener)
|
|
100
102
|
}
|
|
101
103
|
|
|
102
|
-
|
|
103
104
|
export async function produce(channel, message) {
|
|
104
|
-
|
|
105
|
-
await producer.publish(channel, message)
|
|
105
|
+
await defaultProducer.publish(channel, message)
|
|
106
106
|
}
|
|
107
107
|
|
|
108
108
|
|