corebasic 1.0.260 → 1.0.262
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 +4 -5
- package/dist/libs/features.js +2 -1
- package/libs/auth.ts +5 -7
- package/libs/features.ts +5 -2
- package/package.json +1 -1
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
|
-
|
|
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(
|
|
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(
|
|
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(
|
|
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' };
|
package/dist/libs/features.js
CHANGED
|
@@ -204,7 +204,8 @@ 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?.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,
|
|
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,
|
|
208
209
|
};
|
|
209
210
|
const appReq = {
|
|
210
211
|
meta: message.meta,
|
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
|
|
100
|
+
interface Schema extends Record<"auths", Auth> {}
|
|
101
101
|
}
|
|
102
102
|
|
|
103
103
|
async function attemptLogin(req: AuthRequest) {
|
|
104
|
-
|
|
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(
|
|
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(
|
|
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(
|
|
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
|
@@ -64,6 +64,7 @@ type FeatureMessage<I = unknown, T extends keyof Schema = keyof Schema> = {
|
|
|
64
64
|
data: I
|
|
65
65
|
params: FeatureParams
|
|
66
66
|
query?: unknown // This is the buildQuery not the express query
|
|
67
|
+
update?: unknown // This is the buildUpdate
|
|
67
68
|
|
|
68
69
|
// feature // Only used as req.body.feature in features.ts, session.ts
|
|
69
70
|
// client // Only used as req.body.client in auth.ts, session.ts and messaging.ts
|
|
@@ -144,7 +145,7 @@ type RemoteFeatureEntry = {
|
|
|
144
145
|
headers?: {JWT?: string, service?: boolean, NDCURVE_DEVELOPER_LICENSE_ACCESS_TOKEN?: string}
|
|
145
146
|
}
|
|
146
147
|
|
|
147
|
-
type FeatureEntry = { api: string, topic: string, bypass: boolean, featureless: boolean, subscribe: string, handler: Handler<unknown, unknown, keyof Schema>, key?: string[] }
|
|
148
|
+
type FeatureEntry = { api: string, topic: string, bypass: boolean, featureless: boolean, subscribe: string, handler: Handler<unknown, unknown, keyof Schema>, key?: string[], mut?: string[] }
|
|
148
149
|
|
|
149
150
|
|
|
150
151
|
let features: Record<string, FeatureEntry> = {}
|
|
@@ -335,7 +336,9 @@ const apiHandler = async (req: ExpressRequest, res: ExpressResponse) => {
|
|
|
335
336
|
meta,
|
|
336
337
|
data: req.body.data,
|
|
337
338
|
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
|
|
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,
|
|
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
|
+
|
|
339
342
|
}
|
|
340
343
|
|
|
341
344
|
const appReq: Req = {
|