corebasic 1.0.253 → 1.0.255
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 +11 -2
- package/dist/libs/elabase.js +2 -1
- package/dist/libs/features.js +1 -1
- package/libs/auth.ts +33 -3
- package/libs/dip.ts +6 -1
- package/libs/elabase.ts +3 -2
- package/libs/features.ts +5 -1
- package/libs/session.ts +1 -1
- package/package.json +1 -1
package/dist/libs/auth.js
CHANGED
|
@@ -34,15 +34,24 @@ export const start = (app, successCallback) => {
|
|
|
34
34
|
}
|
|
35
35
|
});
|
|
36
36
|
};
|
|
37
|
+
const Apps = {
|
|
38
|
+
SlypBusiness: "SlypBusiness",
|
|
39
|
+
Slyp: "Slyp",
|
|
40
|
+
DipDive: "DipDive",
|
|
41
|
+
Craft: "Craft",
|
|
42
|
+
Portal: "Portal"
|
|
43
|
+
};
|
|
37
44
|
async function attemptLogin(req) {
|
|
38
45
|
let meta = { company: "GLOBAL", outlet: "GLOBAL" };
|
|
46
|
+
let errMessage = { success: false, message: "Login Server Error" };
|
|
47
|
+
if (!req.body?.app || !Apps[req.body.app])
|
|
48
|
+
throw { ...errMessage, mode: 'verify', info: "Invalid app" };
|
|
39
49
|
let expiry = 300000;
|
|
40
50
|
let userMob = req.body.mob ?? req.body.phone ?? '';
|
|
41
51
|
const code = req.body.code ?? '';
|
|
42
52
|
let mob = userMob.endsWith('123456789') ? '0123456789' : Utils.parseMob(userMob, code);
|
|
43
53
|
let time = new Date().getTime();
|
|
44
|
-
|
|
45
|
-
let errMessage = { success: false, message: "Login Server Error" };
|
|
54
|
+
const collection = `${req.body.app}.auth.login`;
|
|
46
55
|
let otpValid = Utils.isEmpty(req.body.otp) ? false : true;
|
|
47
56
|
let clientId = req.body.clientId;
|
|
48
57
|
if (Utils.isEmpty(clientId))
|
package/dist/libs/elabase.js
CHANGED
|
@@ -301,6 +301,7 @@ export const insert = async (meta, collection, value, options, extras) => {
|
|
|
301
301
|
});
|
|
302
302
|
};
|
|
303
303
|
// Ported
|
|
304
|
+
// export const query = async (meta: DipMeta, collection: string | string[], query: any, options?: any, extras?: any) => {
|
|
304
305
|
export const query = async (meta, collection, query, options, extras) => {
|
|
305
306
|
if (!(meta instanceof DipMeta))
|
|
306
307
|
console.warn('Warn: Provided meta is not an instance of DipMeta in Dip.query()'); // TODO: throw error once review completes
|
|
@@ -328,7 +329,7 @@ export const query = async (meta, collection, query, options, extras) => {
|
|
|
328
329
|
if (!batches[meta.batch])
|
|
329
330
|
throw new Error('Error: Invalid batch in Dip.query()');
|
|
330
331
|
batches[meta.batch].push(arg);
|
|
331
|
-
return;
|
|
332
|
+
return [];
|
|
332
333
|
}
|
|
333
334
|
return new Promise((resolve, _reject) => resolve())
|
|
334
335
|
.then(() => execute(arg));
|
package/dist/libs/features.js
CHANGED
|
@@ -347,7 +347,7 @@ export const start = async (app, url, file) => {
|
|
|
347
347
|
try {
|
|
348
348
|
let items = await Dip.query(globalMeta, "Features.txns", { _id: req.params.id });
|
|
349
349
|
if (items.length)
|
|
350
|
-
res.json({ data: { ...items[0], txn: items._id } });
|
|
350
|
+
res.json({ data: { ...items[0], txn: items[0]._id } });
|
|
351
351
|
else
|
|
352
352
|
throw false;
|
|
353
353
|
}
|
package/libs/auth.ts
CHANGED
|
@@ -74,16 +74,46 @@ export const start = (app: AuthApp, successCallback?: SuccessCallback) => {
|
|
|
74
74
|
})
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
+
|
|
78
|
+
const Apps = {
|
|
79
|
+
SlypBusiness: "SlypBusiness",
|
|
80
|
+
Slyp: "Slyp",
|
|
81
|
+
DipDive: "DipDive",
|
|
82
|
+
Craft: "Craft",
|
|
83
|
+
Portal: "Portal"
|
|
84
|
+
} as const;
|
|
85
|
+
type Auth = {
|
|
86
|
+
app: string
|
|
87
|
+
// mob: string
|
|
88
|
+
// phone: string
|
|
89
|
+
// code: string
|
|
90
|
+
// otp: string
|
|
91
|
+
// clientId: string
|
|
92
|
+
_id: string
|
|
93
|
+
otp: string
|
|
94
|
+
clientId: string
|
|
95
|
+
time: number
|
|
96
|
+
userId?: string
|
|
97
|
+
loggedIn?: boolean
|
|
98
|
+
}
|
|
99
|
+
declare global {
|
|
100
|
+
interface Schema extends Record<`${keyof typeof Apps}.auth.login`, Auth> {}
|
|
101
|
+
}
|
|
102
|
+
|
|
77
103
|
async function attemptLogin(req: AuthRequest) {
|
|
78
104
|
let meta = {company: "GLOBAL", outlet: "GLOBAL"}
|
|
105
|
+
let errMessage = {success: false, message: "Login Server Error"}
|
|
106
|
+
|
|
107
|
+
if (!req.body?.app || !Apps[req.body.app as keyof typeof Apps])
|
|
108
|
+
throw {...errMessage, mode: 'verify', info: "Invalid app"}
|
|
109
|
+
|
|
79
110
|
|
|
80
111
|
let expiry = 300000
|
|
81
112
|
let userMob = req.body.mob ?? req.body.phone ?? ''
|
|
82
113
|
const code = req.body.code ?? ''
|
|
83
114
|
let mob = userMob.endsWith('123456789') ? '0123456789' : Utils.parseMob(userMob, code)
|
|
84
115
|
let time = new Date().getTime()
|
|
85
|
-
|
|
86
|
-
let errMessage = {success: false, message: "Login Server Error"}
|
|
116
|
+
const collection = `${req.body.app}.auth.login` as `${keyof typeof Apps}.auth.login`;
|
|
87
117
|
let otpValid = Utils.isEmpty(req.body.otp) ? false : true
|
|
88
118
|
let clientId = req.body.clientId
|
|
89
119
|
if (Utils.isEmpty(clientId))
|
|
@@ -93,7 +123,7 @@ async function attemptLogin(req: AuthRequest) {
|
|
|
93
123
|
let res = await Dip.query(meta, collection, { _id: mob, otp: req.body.otp, clientId, time: { $gt: time - expiry } })
|
|
94
124
|
if (res.length) {
|
|
95
125
|
try {await Dip.update(meta, collection, { _id: mob }, { $set: { otp: '', clientId: '', loggedIn: true } }) } catch (err) { throw {...errMessage, mode: 'verify', info: 'Cleanup Failed'} }
|
|
96
|
-
return {...res[0], mode: 'verify', success: true, userId: res[0]
|
|
126
|
+
return {...res[0], mode: 'verify', success: true, userId: res[0]!.userId!, phone: res[0]!._id, mob: res[0]!._id, code}
|
|
97
127
|
}
|
|
98
128
|
throw {...errMessage, mode: 'verify', info: "Invalid/Expired OTP"}
|
|
99
129
|
} else { // generate login
|
package/libs/dip.ts
CHANGED
|
@@ -40,6 +40,11 @@ type IdempotentDip = {
|
|
|
40
40
|
finish: () => Promise<unknown>
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
+
declare global {
|
|
44
|
+
interface Schema {
|
|
45
|
+
"txns": {_id: string}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
43
48
|
|
|
44
49
|
export async function insertSync(meta: Elabase.DipMeta, feature: string, date: number, uid: string, ref: unknown, type: "REMOVE" | "UPSERT") {
|
|
45
50
|
let stamp = new Date(date).toISOString()
|
|
@@ -71,7 +76,7 @@ export const IdempotentDip = (): IdempotentDip => {
|
|
|
71
76
|
let token = { [state.txn]: true }
|
|
72
77
|
let idempotent = { [state.txn]: { $exists: rollback ?? false } }
|
|
73
78
|
let result = await Elabase.update(state.meta!, collection, {...query, ...idempotent}, {...data, $setOnInsert: undefined, $set: {...(data.$set ?? {}), ...token} })
|
|
74
|
-
return result.count ? true : (await Elabase.query(state.meta!, collection, {...query, ...idempotent})).length
|
|
79
|
+
return result.count ? true : (await Elabase.query(state.meta!, collection as keyof Schema, {...query, ...idempotent})).length
|
|
75
80
|
}
|
|
76
81
|
|
|
77
82
|
idip.upsert = async function (collection, query, data, rollback) {
|
package/libs/elabase.ts
CHANGED
|
@@ -437,7 +437,8 @@ export const insert = async (meta: DipMeta, collection: string | string[], value
|
|
|
437
437
|
}
|
|
438
438
|
|
|
439
439
|
// Ported
|
|
440
|
-
export const query = async (meta: DipMeta, collection: string | string[], query: any, options?: any, extras?: any) => {
|
|
440
|
+
// export const query = async (meta: DipMeta, collection: string | string[], query: any, options?: any, extras?: any) => {
|
|
441
|
+
export const query = async<K extends keyof Schema> (meta: DipMeta, collection: K | K[], query: any, options?: any, extras?: any): Promise<Schema[K][]> => {
|
|
441
442
|
|
|
442
443
|
if (!(meta instanceof DipMeta)) console.warn('Warn: Provided meta is not an instance of DipMeta in Dip.query()') // TODO: throw error once review completes
|
|
443
444
|
|
|
@@ -468,7 +469,7 @@ export const query = async (meta: DipMeta, collection: string | string[], query:
|
|
|
468
469
|
if (!batches[meta.batch])
|
|
469
470
|
throw new Error('Error: Invalid batch in Dip.query()')
|
|
470
471
|
batches[meta.batch]!.push(arg)
|
|
471
|
-
return
|
|
472
|
+
return []
|
|
472
473
|
}
|
|
473
474
|
return new Promise<void>((resolve, _reject) => resolve())
|
|
474
475
|
.then(() => execute(arg))
|
package/libs/features.ts
CHANGED
|
@@ -127,6 +127,10 @@ declare global {
|
|
|
127
127
|
// "products.query.get": typeof import("./src/products/query.ts").get;
|
|
128
128
|
// "products.brands.query.get": typeof import("./src/products/brands/query.ts").get;
|
|
129
129
|
}
|
|
130
|
+
|
|
131
|
+
interface Schema {
|
|
132
|
+
"Features.txns": {_id: string, status: "Queued" | "Processed"}
|
|
133
|
+
}
|
|
130
134
|
}
|
|
131
135
|
|
|
132
136
|
|
|
@@ -478,7 +482,7 @@ export const start = async (app: ExpressApplication, url: URL, file: string) =>
|
|
|
478
482
|
try {
|
|
479
483
|
let items = await Dip.query(globalMeta, "Features.txns", {_id: req.params!.id})
|
|
480
484
|
if (items.length)
|
|
481
|
-
res.json({ data: { ...items[0], txn: items
|
|
485
|
+
res.json({ data: { ...items[0], txn: items[0]!._id } })
|
|
482
486
|
else
|
|
483
487
|
throw false
|
|
484
488
|
} catch {
|
package/libs/session.ts
CHANGED
|
@@ -45,7 +45,7 @@ export const start = (expressApp: ExpressApp, allowedUrls: string[]) => {
|
|
|
45
45
|
const checkPrivilege = async (req: Req) => {
|
|
46
46
|
const staff = Utils.isEmpty(req.body.staff) ? 'BLANK_STAFF' : req.body.staff
|
|
47
47
|
type PrivilegeResponse = {data: {granted: boolean}}
|
|
48
|
-
const response = (await Features.send({company: req.body.company, outlet: req.body.outlet, app: req.body.app}, "privileges.query.check" as keyof FeatureTypes, {feature: req.body.feature } as any as never, {id: staff} as Features.FeatureParams)) as PrivilegeResponse
|
|
48
|
+
const response = (await Features.send({company: req.body.company, outlet: req.body.outlet, app: req.body.app}, "privileges.query.check" as keyof FeatureTypes, {feature: req.body.feature } as any as never, {id: staff} as Features.FeatureParams)) as unknown as PrivilegeResponse
|
|
49
49
|
const granted = response.data.granted
|
|
50
50
|
if (!granted)
|
|
51
51
|
throw {message: "Access Denied"}
|