corebasic 1.0.145 → 1.0.147
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 +1 -1
- package/libs/dip.js +10 -2
- package/libs/messaging.js +8 -0
- package/package.json +1 -1
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().
|
|
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)
|
|
@@ -53,3 +53,11 @@ export const IdempotentDip = () => {
|
|
|
53
53
|
})
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
export const insertKeys = message => {
|
|
59
|
+
return {"created": message.date, "updated": message.date, "createdBy": message.user, "updatedBy": message.user}
|
|
60
|
+
}
|
|
61
|
+
export const updateKeys = message => {
|
|
62
|
+
return {"updated": message.date, "updatedBy": message.user}
|
|
63
|
+
}
|
package/libs/messaging.js
CHANGED
|
@@ -114,4 +114,12 @@ export async function produce(channel, message) {
|
|
|
114
114
|
}
|
|
115
115
|
|
|
116
116
|
|
|
117
|
+
// Hydrate
|
|
118
|
+
|
|
119
|
+
export async function hydrate(callback) {
|
|
120
|
+
setTimeout(async _ => {
|
|
121
|
+
let {user,company,items} = await callback()
|
|
122
|
+
await publish(user, {event: "RPC_hydrate", data: { company, items }, txn: Utils.uid() })
|
|
123
|
+
}, 100)
|
|
124
|
+
}
|
|
117
125
|
|