corebasic 1.0.43 → 1.0.45
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 +4 -4
- package/libs/features.js +7 -7
- package/package.json +1 -1
package/libs/auth.js
CHANGED
|
@@ -53,7 +53,7 @@ async function attemptLogin(req, res) {
|
|
|
53
53
|
throw {...errMessage, mode: 'verify', info: "Invalid/Expired OTP"}
|
|
54
54
|
} else { // generate login
|
|
55
55
|
let otp = phone === '0123456789' ? '1234' : otpGenerator.generate(4, { upperCaseAlphabets: false, specialChars: false, digital: true, lowerCaseAlphabets: false });
|
|
56
|
-
if (phone === '0123456789' || await sendOtp(phone, otp)) {
|
|
56
|
+
if (phone === '0123456789' || await sendOtp(phone, otp, req.body.app)) {
|
|
57
57
|
let userId = req.body.userId ?? Utils.uid()
|
|
58
58
|
let now = Utils.now().toISOString()
|
|
59
59
|
let data = req.body.data ?? {}
|
|
@@ -66,10 +66,10 @@ async function attemptLogin(req, res) {
|
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
|
|
69
|
-
async function sendOtp(phone, otp) {
|
|
69
|
+
async function sendOtp(phone, otp, app) {
|
|
70
70
|
try {
|
|
71
|
-
let
|
|
72
|
-
await axios.get(
|
|
71
|
+
let api = process.env.SMS_API.replace(':phone', phone).replace(':otp', otp).replace(':app', app ?? 'app')
|
|
72
|
+
await axios.get(api)
|
|
73
73
|
return true
|
|
74
74
|
} catch {
|
|
75
75
|
return false
|
package/libs/features.js
CHANGED
|
@@ -28,14 +28,14 @@ export function start(app, url) {
|
|
|
28
28
|
|
|
29
29
|
if (feature.api.split(' ')[0].toLowerCase() !== "get") {
|
|
30
30
|
let topic = feature.topic
|
|
31
|
-
Kafka.receive(`
|
|
31
|
+
Kafka.receive(`Features.${topic}`, `${featureName}.${topic}`, async (topic, message) => {
|
|
32
32
|
|
|
33
33
|
const timer = ms => new Promise(res => setTimeout(res, ms)) // A promise that resolves after "ms" Milliseconds
|
|
34
|
-
topic = topic.replace('
|
|
34
|
+
topic = topic.replace('Features.','')
|
|
35
35
|
while (true) {
|
|
36
36
|
try {
|
|
37
37
|
await features[message.feature].handler(topic, message)
|
|
38
|
-
await Elabase.insert("txns", {_id: message.txn, status: "Processed"})
|
|
38
|
+
await Elabase.insert("Features.txns", {_id: message.txn, status: "Processed"})
|
|
39
39
|
break
|
|
40
40
|
} catch {
|
|
41
41
|
console.warn(`Feature: ${featureName}, error in executing handler during Kafka.receive(topic: ${topic})`)
|
|
@@ -62,7 +62,7 @@ export function start(app, url) {
|
|
|
62
62
|
throw {status: 500, message: "Failed to retreive data", ...err}
|
|
63
63
|
}
|
|
64
64
|
} else
|
|
65
|
-
await commandAction(req, res, feature
|
|
65
|
+
await commandAction(req, res, feature)
|
|
66
66
|
} catch (err) {
|
|
67
67
|
res.status(err.status ?? 500).json(err)
|
|
68
68
|
}
|
|
@@ -72,7 +72,7 @@ export function start(app, url) {
|
|
|
72
72
|
|
|
73
73
|
app.get('/transactions/:id', async (req, res) => {
|
|
74
74
|
try {
|
|
75
|
-
let items = await Elabase.query("txns", {_id: req.params.id})
|
|
75
|
+
let items = await Elabase.query("Features.txns", {_id: req.params.id})
|
|
76
76
|
if (items.length)
|
|
77
77
|
res.json({ data: { ...items[0], txn: items._id } })
|
|
78
78
|
else
|
|
@@ -83,11 +83,11 @@ export function start(app, url) {
|
|
|
83
83
|
})
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
-
const commandAction = async (req, res, feature
|
|
86
|
+
const commandAction = async (req, res, feature) => {
|
|
87
87
|
let txn = req.body.txn ?? Util.uid()
|
|
88
88
|
req.body.data._id = req.body.data._id ?? txn
|
|
89
89
|
try {
|
|
90
|
-
await Kafka.send(`
|
|
90
|
+
await Kafka.send(`Features.${feature.topic}`, { data: req.body.data, feature: req.body.feature, txn, id: _id, date: new Date().getTime() }, _id)
|
|
91
91
|
|
|
92
92
|
} catch {
|
|
93
93
|
throw {status: 500, message: "Failed to queue the transaction"}
|