corebasic 1.0.175 → 1.0.177

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 +39 -18
  2. package/package.json +1 -1
package/libs/features.js CHANGED
@@ -171,26 +171,24 @@ const apiHandler = async (req, res) => {
171
171
  } catch (_) { }
172
172
  }
173
173
  }
174
- export const start = async (app, url, file) => {
175
- features = await Utils.fileToJson(url, file)
176
- await announce()
177
-
178
- app.get('/features', async (req, res) => {
179
- let exp_features = {}
180
- for (let [key, {api}] of Object.entries(features))
181
- exp_features[key] = {api, service: `${SERVICE_ADDRESS}`}
182
- if (process.env.LOAD_LOCAL_FEATURES) {
183
- for (let key in SLYP_FEATURES_LIST)
184
- SLYP_FEATURES_LIST[key].headers = {JWT: SERVICE_ACCESS_TOKEN, service: true, NDCURVE_DEVELOPER_LICENSE_ACCESS_TOKEN}
185
- }
186
- res.json({ data: { ...SLYP_FEATURES_LIST, ...exp_features } })
187
- })
188
174
 
175
+ let ExpressApp
176
+ let PROJECT_ROOT_URL
177
+ export async function registerFeatures(newFeatures) {
189
178
  // Registering handlers
179
+ await registerHandler(newFeatures)
180
+
181
+ features = {...newFeatures, ...features}
182
+
183
+ // Registering apis
184
+ registerApi()
185
+ }
186
+ async function registerHandler(features) {
190
187
  for (let name in features) {
191
188
  let feature = features[name]
192
189
  apis[feature.api] = apis[feature.api] ?? {}
193
190
  apis[feature.api][name] = feature
191
+ const featureName = name
194
192
 
195
193
  name = name.split('.')
196
194
  let handler = name.pop()
@@ -199,19 +197,42 @@ export const start = async (app, url, file) => {
199
197
  if (name === 'src/transactions/query')
200
198
  continue
201
199
 
202
- feature.handler = (await import(`${new URL(`${name}.js`, url).toString().replace('file://', '')}`))[handler]
200
+ if (featureName.startsWith("flows.") && !featureName.startsWith("flows.query.") && !featureName.startsWith("flows.command.") && !featureName.startsWith("flows.designs."))
201
+ feature.handler = (await import(`${new URL(`src/flows/query.js`, PROJECT_ROOT_URL).toString().replace('file://', '')}`)).FEATURE_HANDLERS[handler]
202
+ else
203
+ feature.handler = (await import(`${new URL(`${name}.js`, PROJECT_ROOT_URL).toString().replace('file://', '')}`))[handler]
203
204
  }
204
-
205
- // Registering apis
205
+ }
206
+ function registerApi() {
206
207
  for (let api in apis) {
207
208
  let method = getFeatureMethod(api)
208
209
  let url = api.split(' ')[1]
209
210
  if (api === 'GET /transactions/:id')
210
211
  continue
211
212
 
212
- app[method](url, apiHandler)
213
+ ExpressApp[method](url, apiHandler)
213
214
  }
215
+ }
216
+
217
+ export const start = async (app, url, file) => {
218
+ ExpressApp = app
219
+ PROJECT_ROOT_URL = url
220
+ features = await Utils.fileToJson(url, file)
221
+ await announce()
222
+
223
+ app.get('/features', async (req, res) => {
224
+ let exp_features = {}
225
+ for (let [key, {api}] of Object.entries(features))
226
+ exp_features[key] = {api, service: `${SERVICE_ADDRESS}`}
227
+ if (process.env.LOAD_LOCAL_FEATURES) {
228
+ for (let key in SLYP_FEATURES_LIST)
229
+ SLYP_FEATURES_LIST[key].headers = {JWT: SERVICE_ACCESS_TOKEN, service: true, NDCURVE_DEVELOPER_LICENSE_ACCESS_TOKEN}
230
+ }
231
+ res.json({ data: { ...SLYP_FEATURES_LIST, ...exp_features } })
232
+ })
214
233
 
234
+ // Registering features
235
+ await registerFeatures(features)
215
236
 
216
237
  // Get unique kafka topics list from features
217
238
  let kafkaTopics = []
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "corebasic",
3
3
  "type": "module",
4
- "version": "1.0.175",
4
+ "version": "1.0.177",
5
5
  "description": "",
6
6
  "main": "index.js",
7
7
  "scripts": {