corebasic 1.0.146 → 1.0.148

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/libs/auth.js CHANGED
@@ -58,7 +58,7 @@ async function attemptLogin(req, res) {
58
58
  let otp = mob === '0123456789' ? '1234' : otpGenerator.generate(4, { upperCaseAlphabets: false, specialChars: false, digital: true, lowerCaseAlphabets: false });
59
59
  if (mob === '0123456789' || await sendOtp(mob, otp, req.body.app)) {
60
60
  let userId = req.body.userId ?? Utils.uid()
61
- let now = Utils.now().toISOString()
61
+ let now = Utils.now().getTime()
62
62
  let data = req.body.data ?? {}
63
63
  let info = { clientId, created: now, updated: now, ...data}
64
64
  await Dip.update(meta, collection, { _id: mob }, { $set: { otp, clientId, time, updated: now, attemptLogin: true }, $setOnInsert: { _id: mob, otp, time, userId, ...info } }, { upsert: true })
package/libs/dip.js CHANGED
@@ -30,7 +30,7 @@ export const IdempotentDip = () => {
30
30
  new: (async function (meta, txn, blank) {
31
31
  this.txn = txn
32
32
  this.meta = meta
33
- return blank ? this : (await Elabase.query(this.meta, "txns",{_id: this.txn}).length ? false : this)
33
+ return blank ? this : ((await Elabase.query(this.meta, "txns",{_id: this.txn})).length ? false : this)
34
34
  }),
35
35
  insert: (async function (collection, query, data) {
36
36
  await Elabase.update(this.meta, collection, query, { $setOnInsert: data }, {upsert: true})
@@ -39,7 +39,7 @@ export const IdempotentDip = () => {
39
39
  let token = { [this.txn]: true }
40
40
  let idempotent = { [this.txn]: { $exists: rollback ?? false } }
41
41
  let result = await Elabase.update(this.meta, collection, {...query, ...idempotent}, {...data, $setOnInsert: undefined, $set: {...(data.$set ?? {}), ...token} })
42
- return result.count ? true : await Elabase.query(this.meta, collection, {...query, ...idempotent}).length
42
+ return result.count ? true : (await Elabase.query(this.meta, collection, {...query, ...idempotent})).length
43
43
  }),
44
44
  upsert: (async function (collection, query, data, rollback) {
45
45
  await this.insert(collection, query, data.$setOnInsert)
@@ -55,6 +55,19 @@ export const IdempotentDip = () => {
55
55
  }
56
56
 
57
57
 
58
+ export const idip = async (message, callback, cleanup) => {
59
+ let IDip = await IdempotentDip().new(message.meta, message.txn)
60
+ if (!IDip) {
61
+ IDip = IdempotentDip().new(message.meta, message.txn, {blank: true})
62
+ await cleanup(IDip)
63
+ return
64
+ }
65
+ await callback(IDip)
66
+ await IDip.finish()
67
+ await cleanup(IDip)
68
+ }
69
+
70
+
58
71
  export const insertKeys = message => {
59
72
  return {"created": message.date, "updated": message.date, "createdBy": message.user, "updatedBy": message.user}
60
73
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "corebasic",
3
3
  "type": "module",
4
- "version": "1.0.146",
4
+ "version": "1.0.148",
5
5
  "description": "",
6
6
  "main": "index.js",
7
7
  "scripts": {