corebasic 1.0.258 → 1.0.260

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.
@@ -92,7 +92,7 @@ export const send = async (meta, feature, data, params) => {
92
92
  let url = getFeatureUrl(api);
93
93
  if (params || url.includes(':')) {
94
94
  for (let key in params)
95
- url = url.replace(`:${key}`, params[key]);
95
+ url = url.replace(`:${key}`, encodeURIComponent(params[key]));
96
96
  if (url.includes(':'))
97
97
  throw new Error(`Error: Internal feature call send on feature: ${feature} when api/params/substitution`);
98
98
  }
@@ -103,7 +103,7 @@ export const send = async (meta, feature, data, params) => {
103
103
  // return (await axios[method](`${service}${url}`, payload, {headers: {jwt: SERVICE_ACCESS_TOKEN, service: true}, timeout: 1000 })).data // Worked Earlier, but issue spotted
104
104
  if (baseFeature) { // Local call
105
105
  let response;
106
- let req = { body: payload, params: params ?? {}, method, path: url, url: '', headers: {}, query: {}, on: (_event, _callback) => { } };
106
+ let req = { body: payload, params: params ?? {}, method, path: decodeURIComponent(url), url: '', headers: {}, query: {}, on: (_event, _callback) => { } };
107
107
  req = JSON.parse(JSON.stringify(req));
108
108
  const callback = (payload) => { response = payload; };
109
109
  const res = {
@@ -182,10 +182,29 @@ 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(".$.");
188
+ const last_path = array_paths.pop();
189
+ const query = {};
190
+ let obj = query;
191
+ for (const path of array_paths) {
192
+ obj[path] = { $elemMatch: {} };
193
+ obj = obj[path].$elemMatch;
194
+ }
195
+ if (last_path?.endsWith(".$"))
196
+ obj[last_path.split(".$")[0]] = { $elemMatch: { $eq: id } };
197
+ else if (last_path)
198
+ obj[last_path] = id;
199
+ else
200
+ return undefined;
201
+ return query;
202
+ }
185
203
  const message = {
186
204
  meta,
187
205
  data: req.body.data,
188
206
  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
189
208
  };
190
209
  const appReq = {
191
210
  meta: message.meta,
package/libs/features.ts CHANGED
@@ -63,6 +63,7 @@ type FeatureMessage<I = unknown, T extends keyof Schema = keyof Schema> = {
63
63
  meta: FeatureMeta & { topic: T }
64
64
  data: I
65
65
  params: FeatureParams
66
+ query?: unknown // This is the buildQuery not the express query
66
67
 
67
68
  // feature // Only used as req.body.feature in features.ts, session.ts
68
69
  // client // Only used as req.body.client in auth.ts, session.ts and messaging.ts
@@ -143,7 +144,7 @@ type RemoteFeatureEntry = {
143
144
  headers?: {JWT?: string, service?: boolean, NDCURVE_DEVELOPER_LICENSE_ACCESS_TOKEN?: string}
144
145
  }
145
146
 
146
- type FeatureEntry = { api: string, topic: string, bypass: boolean, featureless: boolean, subscribe: string, handler: Handler<unknown, unknown, keyof Schema> }
147
+ type FeatureEntry = { api: string, topic: string, bypass: boolean, featureless: boolean, subscribe: string, handler: Handler<unknown, unknown, keyof Schema>, key?: string[] }
147
148
 
148
149
 
149
150
  let features: Record<string, FeatureEntry> = {}
@@ -203,7 +204,7 @@ export const send = async <K extends keyof FeatureTypes> (meta: Partial<FeatureM
203
204
 
204
205
  if (params || url.includes(':')) {
205
206
  for (let key in params)
206
- url = url.replace(`:${key}`, params[key]!)
207
+ url = url.replace(`:${key}`, encodeURIComponent(params[key]!))
207
208
  if (url.includes(':'))
208
209
  throw new Error(`Error: Internal feature call send on feature: ${feature} when api/params/substitution`)
209
210
  }
@@ -217,7 +218,7 @@ export const send = async <K extends keyof FeatureTypes> (meta: Partial<FeatureM
217
218
  // return (await axios[method](`${service}${url}`, payload, {headers: {jwt: SERVICE_ACCESS_TOKEN, service: true}, timeout: 1000 })).data // Worked Earlier, but issue spotted
218
219
  if (baseFeature) { // Local call
219
220
  let response;
220
- let req: ExpressRequest = { body: payload, params: params ?? {}, method, path: url, url: '', headers: {}, query: {}, on: (_event: string, _callback:()=>void) => {} }
221
+ let req: ExpressRequest = { body: payload, params: params ?? {}, method, path: decodeURIComponent(url), url: '', headers: {}, query: {}, on: (_event: string, _callback:()=>void) => {} }
221
222
  req = JSON.parse(JSON.stringify(req))
222
223
  const callback = (payload: unknown): void => { response = payload }
223
224
  const res: ExpressResponse = {
@@ -309,10 +310,32 @@ const apiHandler = async (req: ExpressRequest, res: ExpressResponse) => {
309
310
 
310
311
  meta.txn = meta.txn ?? Utils.uid()
311
312
 
313
+
314
+ function buildQuery(key: string, id: unknown): unknown {
315
+ key = key ? key : "_id"
316
+ const array_paths = key.split(".$.")
317
+ const last_path = array_paths.pop()
318
+ const query: Record<string, unknown> = {}
319
+ let obj = query
320
+ for (const path of array_paths) {
321
+ obj[path] = { $elemMatch: { } }
322
+ obj = (obj[path] as { $elemMatch: Record<string, unknown> }).$elemMatch
323
+ }
324
+
325
+ if (last_path?.endsWith(".$"))
326
+ obj[last_path.split(".$")[0]!] = { $elemMatch: {$eq: id} }
327
+ else if (last_path)
328
+ obj[last_path] = id
329
+ else
330
+ return undefined
331
+ return query
332
+ }
333
+
312
334
  const message: FeatureMessage = {
313
335
  meta,
314
336
  data: req.body.data,
315
337
  params: featureless ? req.params : req.body.params!,
338
+ 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
316
339
  }
317
340
 
318
341
  const appReq: Req = {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "corebasic",
3
3
  "type": "module",
4
- "version": "1.0.258",
4
+ "version": "1.0.260",
5
5
  "description": "",
6
6
  "main": "dist/index.js",
7
7
  "types": "./index.ts",