corebasic 1.0.81 → 1.0.83

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.
Files changed (2) hide show
  1. package/libs/features.js +24 -3
  2. package/package.json +1 -1
package/libs/features.js CHANGED
@@ -2,11 +2,32 @@ import * as Dip from './dip.js'
2
2
  import * as Kafka from './kafka.js'
3
3
  import * as Utils from './utils.js'
4
4
  import * as Messaging from './messaging.js'
5
+ import axios from 'axios'
5
6
 
6
7
 
7
8
  let features = {}
8
9
  let apis = {}
9
10
 
11
+ const getFeatureMethod = api => api.split(' ')[0].toLowerCase()
12
+ const getFeatureUrl = api => api.split(' ')[1]
13
+ const getFeature = name => features[name]
14
+
15
+ export const send = async (feature, params, payload) => {
16
+ let {api} = getFeature(feature)
17
+ let method = getFeatureMethod(api)
18
+ let url = getFeatureUrl(api)
19
+
20
+ if (params || url.includes(':')) {
21
+ for (let key in params)
22
+ url = url.replace(`:${key}`, params[key])
23
+ if (url.includes(':'))
24
+ throw {feature, when: 'api/params/substitution', message: "Internal Feature Call" }
25
+ }
26
+
27
+ return await (axios[method](`http://127.0.0.1${url}`,payload).timeout(1000))
28
+ }
29
+
30
+
10
31
  export const start = async (app, url, file) => {
11
32
  features = await Utils.fileToJson(url, file)
12
33
 
@@ -29,13 +50,13 @@ export const start = async (app, url, file) => {
29
50
 
30
51
  // Registering apis
31
52
  for (let api in apis) {
32
- let method = api.split(' ')[0].toLowerCase()
53
+ let method = getFeatureMethod(api)
33
54
  let url = api.split(' ')[1]
34
55
  if (api === 'GET /transactions/:id')
35
56
  continue
36
57
 
37
58
  app[method](url, async (req, res) => {
38
- let feature = features[req.body.feature]
59
+ let feature = getFeature(req.body.feature)
39
60
  let topic = feature.topic
40
61
  try {
41
62
  if (method === "get") {
@@ -127,6 +148,6 @@ const commandAction = async (req, res, topic) => {
127
148
  } catch {
128
149
  throw {status: 500, message: "Failed to queue the transaction"}
129
150
  }
130
- res.json({ data: { txn: message.txn, success: true, status: "Queued" } })
151
+ res.json({ data: { txn: message.txn, success: true, status: "Queued", featureQueued: true } })
131
152
  }
132
153
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "corebasic",
3
3
  "type": "module",
4
- "version": "1.0.81",
4
+ "version": "1.0.83",
5
5
  "description": "",
6
6
  "main": "index.js",
7
7
  "scripts": {