corebasic 1.0.261 → 1.0.263

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/dist/libs/auth.js CHANGED
@@ -42,7 +42,7 @@ const Apps = {
42
42
  Portal: "Portal"
43
43
  };
44
44
  async function attemptLogin(req) {
45
- let meta = { company: "GLOBAL", outlet: "GLOBAL" };
45
+ const globalMeta = Dip.globalMeta({ suffix: req.body.app });
46
46
  let errMessage = { success: false, message: "Login Server Error" };
47
47
  if (!req.body?.app || !Apps[req.body.app])
48
48
  throw { ...errMessage, mode: 'verify', info: "Invalid app" };
@@ -51,16 +51,15 @@ async function attemptLogin(req) {
51
51
  const code = req.body.code ?? '';
52
52
  let mob = userMob.endsWith('123456789') ? '0123456789' : Utils.parseMob(userMob, code);
53
53
  let time = new Date().getTime();
54
- const collection = `${req.body.app}.auth.login`;
55
54
  let otpValid = Utils.isEmpty(req.body.otp) ? false : true;
56
55
  let clientId = req.body.clientId;
57
56
  if (Utils.isEmpty(clientId))
58
57
  throw { ...errMessage, mode: otpValid ? 'verify' : 'login', info: "Invalid Client ID" };
59
58
  if (otpValid) { // verify login
60
- let res = await Dip.query(meta, collection, { _id: mob, otp: req.body.otp, clientId, time: { $gt: time - expiry } });
59
+ let res = await Dip.query(globalMeta, "auths", { _id: mob, otp: req.body.otp, clientId, time: { $gt: time - expiry } });
61
60
  if (res.length) {
62
61
  try {
63
- await Dip.update(meta, collection, { _id: mob }, { $set: { otp: '', clientId: '', loggedIn: true } });
62
+ await Dip.update(globalMeta, "auths", { _id: mob }, { $set: { otp: '', clientId: '', loggedIn: true } });
64
63
  }
65
64
  catch (err) {
66
65
  throw { ...errMessage, mode: 'verify', info: 'Cleanup Failed' };
@@ -76,7 +75,7 @@ async function attemptLogin(req) {
76
75
  let now = Utils.now().getTime();
77
76
  let data = req.body.data ?? {};
78
77
  let info = { clientId, created: now, updated: now, ...data };
79
- await Dip.update(meta, collection, { _id: mob }, { $set: { otp, clientId, time, updated: now, attemptLogin: true }, $setOnInsert: { _id: mob, otp, time, userId, ...info } }, { upsert: true });
78
+ await Dip.update(globalMeta, "auths", { _id: mob }, { $set: { otp, clientId, time, updated: now, attemptLogin: true }, $setOnInsert: { _id: mob, otp, time, userId, ...info } }, { upsert: true });
80
79
  return { mode: 'login', success: true, userId, expiry, phone: mob, mob, code };
81
80
  }
82
81
  throw { ...errMessage, mode: 'login', info: 'Generating Info Failed' };
@@ -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;
@@ -204,7 +204,7 @@ const apiHandler = async (req, res) => {
204
204
  meta,
205
205
  data: req.body.data,
206
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,
207
+ 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
208
  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
209
  };
210
210
  const appReq = {
package/libs/auth.ts CHANGED
@@ -97,32 +97,30 @@ type Auth = {
97
97
  loggedIn?: boolean
98
98
  }
99
99
  declare global {
100
- interface Schema extends Record<`${keyof typeof Apps}.auth.login`, Auth> {}
100
+ interface Schema extends Record<"auths", Auth> {}
101
101
  }
102
102
 
103
103
  async function attemptLogin(req: AuthRequest) {
104
- let meta = {company: "GLOBAL", outlet: "GLOBAL"}
104
+ const globalMeta = Dip.globalMeta({suffix: req.body.app})
105
105
  let errMessage = {success: false, message: "Login Server Error"}
106
106
 
107
107
  if (!req.body?.app || !Apps[req.body.app as keyof typeof Apps])
108
108
  throw {...errMessage, mode: 'verify', info: "Invalid app"}
109
109
 
110
-
111
110
  let expiry = 300000
112
111
  let userMob = req.body.mob ?? req.body.phone ?? ''
113
112
  const code = req.body.code ?? ''
114
113
  let mob = userMob.endsWith('123456789') ? '0123456789' : Utils.parseMob(userMob, code)
115
114
  let time = new Date().getTime()
116
- const collection = `${req.body.app}.auth.login` as `${keyof typeof Apps}.auth.login`;
117
115
  let otpValid = Utils.isEmpty(req.body.otp) ? false : true
118
116
  let clientId = req.body.clientId
119
117
  if (Utils.isEmpty(clientId))
120
118
  throw { ...errMessage, mode: otpValid ? 'verify' : 'login', info: "Invalid Client ID" }
121
119
 
122
120
  if (otpValid) { // verify login
123
- let res = await Dip.query(meta, collection, { _id: mob, otp: req.body.otp, clientId, time: { $gt: time - expiry } })
121
+ let res = await Dip.query(globalMeta, "auths", { _id: mob, otp: req.body.otp, clientId, time: { $gt: time - expiry } })
124
122
  if (res.length) {
125
- try {await Dip.update(meta, collection, { _id: mob }, { $set: { otp: '', clientId: '', loggedIn: true } }) } catch (err) { throw {...errMessage, mode: 'verify', info: 'Cleanup Failed'} }
123
+ try {await Dip.update(globalMeta, "auths", { _id: mob }, { $set: { otp: '', clientId: '', loggedIn: true } }) } catch (err) { throw {...errMessage, mode: 'verify', info: 'Cleanup Failed'} }
126
124
  return {...res[0], mode: 'verify', success: true, userId: res[0]!.userId!, phone: res[0]!._id, mob: res[0]!._id, code}
127
125
  }
128
126
  throw {...errMessage, mode: 'verify', info: "Invalid/Expired OTP"}
@@ -133,7 +131,7 @@ async function attemptLogin(req: AuthRequest) {
133
131
  let now = Utils.now().getTime()
134
132
  let data = req.body.data ?? {}
135
133
  let info = { clientId, created: now, updated: now, ...data}
136
- await Dip.update(meta, collection, { _id: mob }, { $set: { otp, clientId, time, updated: now, attemptLogin: true }, $setOnInsert: { _id: mob, otp, time, userId, ...info } }, { upsert: true })
134
+ await Dip.update(globalMeta, "auths", { _id: mob }, { $set: { otp, clientId, time, updated: now, attemptLogin: true }, $setOnInsert: { _id: mob, otp, time, userId, ...info } }, { upsert: true })
137
135
 
138
136
  return {mode: 'login', success: true, userId, expiry, phone: mob, mob, code}
139
137
  }
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
@@ -336,7 +336,7 @@ const apiHandler = async (req: ExpressRequest, res: ExpressResponse) => {
336
336
  meta,
337
337
  data: req.body.data,
338
338
  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,
339
+ 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
340
  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
341
 
342
342
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "corebasic",
3
3
  "type": "module",
4
- "version": "1.0.261",
4
+ "version": "1.0.263",
5
5
  "description": "",
6
6
  "main": "dist/index.js",
7
7
  "types": "./index.ts",