corebasic 1.0.262 → 1.0.264

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.
@@ -182,9 +182,9 @@ const apiHandler = async (req, res) => {
182
182
  meta.outlet = 'DEFAULT_OUTLET';
183
183
  }
184
184
  meta.txn = meta.txn ?? Utils.uid();
185
- function buildQuery(key, id) {
186
- key = key ? key : "_id";
187
- const array_paths = key.split(".$.");
185
+ function buildQuery(opt, id) {
186
+ opt = opt ? opt : "_id";
187
+ const array_paths = opt.split(".$.");
188
188
  const last_path = array_paths.pop();
189
189
  const query = {};
190
190
  let obj = query;
@@ -200,11 +200,19 @@ const apiHandler = async (req, res) => {
200
200
  return undefined;
201
201
  return query;
202
202
  }
203
+ if (feature.opt?.[0] === "*" && req.body.params?.opt === "*")
204
+ throw { status: 404, message: `Param opt: "*" not allowed when mandatory.` };
205
+ if (feature.opt?.[0] === "*" && !feature.opt?.includes(req.body.params?.opt))
206
+ throw { status: 404, message: `Param opt: "${req.body.params?.opt}" doesn't exist in the mandatory configuration.` };
207
+ if (feature.mut?.[0] === "*" && req.body.params?.mut === "*")
208
+ throw { status: 404, message: `Param mut: "*" not allowed when mandatory.` };
209
+ if (feature.mut?.[0] === "*" && !feature.mut?.includes(req.body.params?.mut))
210
+ throw { status: 404, message: `Param mut: "${req.body.params?.mut}" doesn't exist in the mandatory configuration.` };
203
211
  const message = {
204
212
  meta,
205
213
  data: req.body.data,
206
214
  params: featureless ? req.params : req.body.params,
207
- query: req.body.params?.key && (feature.key)?.includes(req.body.params?.key) ? buildQuery(req.body.params?.key ?? "_id", req.body.params?.id) : req.body.params?.id ? { _id: req.body.params?.id } : undefined,
215
+ query: req.body.params?.opt && (feature.opt)?.includes(req.body.params?.opt) ? buildQuery(req.body.params?.opt ?? "_id", req.body.params?.id) : req.body.params?.id ? { _id: req.body.params?.id } : undefined,
208
216
  update: req.body.params?.mut && (feature.mut)?.includes(req.body.params?.mut) ? { $set: { [req.body.params.mut]: req.body.data[req.body.params.mut], ...Dip.updateKeys({ meta }) } } : undefined,
209
217
  };
210
218
  const appReq = {
package/libs/features.ts CHANGED
@@ -145,7 +145,7 @@ type RemoteFeatureEntry = {
145
145
  headers?: {JWT?: string, service?: boolean, NDCURVE_DEVELOPER_LICENSE_ACCESS_TOKEN?: string}
146
146
  }
147
147
 
148
- type FeatureEntry = { api: string, topic: string, bypass: boolean, featureless: boolean, subscribe: string, handler: Handler<unknown, unknown, keyof Schema>, key?: string[], mut?: string[] }
148
+ type FeatureEntry = { api: string, topic: string, bypass: boolean, featureless: boolean, subscribe: string, handler: Handler<unknown, unknown, keyof Schema>, opt?: string[], mut?: string[] }
149
149
 
150
150
 
151
151
  let features: Record<string, FeatureEntry> = {}
@@ -312,9 +312,9 @@ const apiHandler = async (req: ExpressRequest, res: ExpressResponse) => {
312
312
  meta.txn = meta.txn ?? Utils.uid()
313
313
 
314
314
 
315
- function buildQuery(key: string, id: unknown): unknown {
316
- key = key ? key : "_id"
317
- const array_paths = key.split(".$.")
315
+ function buildQuery(opt: string, id: unknown): unknown {
316
+ opt = opt ? opt : "_id"
317
+ const array_paths = opt.split(".$.")
318
318
  const last_path = array_paths.pop()
319
319
  const query: Record<string, unknown> = {}
320
320
  let obj = query
@@ -332,11 +332,21 @@ const apiHandler = async (req: ExpressRequest, res: ExpressResponse) => {
332
332
  return query
333
333
  }
334
334
 
335
+ if (feature.opt?.[0] === "*" && req.body.params?.opt === "*")
336
+ throw { status: 404, message: `Param opt: "*" not allowed when mandatory.` }
337
+ if (feature.opt?.[0] === "*" && !feature.opt?.includes(req.body.params?.opt as string))
338
+ throw { status: 404, message: `Param opt: "${req.body.params?.opt}" doesn't exist in the mandatory configuration.` }
339
+ if (feature.mut?.[0] === "*" && req.body.params?.mut === "*")
340
+ throw { status: 404, message: `Param mut: "*" not allowed when mandatory.` }
341
+ if (feature.mut?.[0] === "*" && !feature.mut?.includes(req.body.params?.mut as string))
342
+ throw { status: 404, message: `Param mut: "${req.body.params?.mut}" doesn't exist in the mandatory configuration.` }
343
+
344
+
335
345
  const message: FeatureMessage = {
336
346
  meta,
337
347
  data: req.body.data,
338
348
  params: featureless ? req.params : req.body.params!,
339
- query: req.body.params?.key && (feature.key!)?.includes(req.body.params?.key as string) ? buildQuery(req.body.params?.key ?? "_id", req.body.params?.id) : req.body.params?.id ? {_id: req.body.params?.id} : undefined,
349
+ query: req.body.params?.opt && (feature.opt!)?.includes(req.body.params?.opt as string) ? buildQuery(req.body.params?.opt ?? "_id", req.body.params?.id) : req.body.params?.id ? {_id: req.body.params?.id} : undefined,
340
350
  update: req.body.params?.mut && (feature.mut!)?.includes(req.body.params?.mut as string) ? { $set: { [req.body.params!.mut]: (req.body.data as Record<string, unknown>)[req.body.params!.mut], ...Dip.updateKeys({meta}) } } : undefined,
341
351
 
342
352
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "corebasic",
3
3
  "type": "module",
4
- "version": "1.0.262",
4
+ "version": "1.0.264",
5
5
  "description": "",
6
6
  "main": "dist/index.js",
7
7
  "types": "./index.ts",