corebasic 1.0.134 → 1.0.136
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/dip.js +8 -0
- package/libs/features.js +6 -0
- package/libs/session.js +4 -1
- package/package.json +1 -1
package/libs/dip.js
CHANGED
|
@@ -15,6 +15,14 @@ export const transactionCommit = Elabase.transactionCommit
|
|
|
15
15
|
export const shard_stats = Elabase.shard_stats
|
|
16
16
|
export let config = Elabase.config
|
|
17
17
|
|
|
18
|
+
export async function insertSync(meta, feature, date, uid, ref, type) {
|
|
19
|
+
let stamp = new Date(date).toISOString()
|
|
20
|
+
let _id = `${meta.outlet}_${stamp}_${uid}`
|
|
21
|
+
let data = { _id, ref, type: type === "REMOVE" ? type : "UPSERT" }
|
|
22
|
+
let collection = 'syncs.' + feature
|
|
23
|
+
await Elabase.insert(meta, collection, data)
|
|
24
|
+
}
|
|
25
|
+
|
|
18
26
|
export const IdempotentDip = () => {
|
|
19
27
|
return {
|
|
20
28
|
txn: '',
|
package/libs/features.js
CHANGED
|
@@ -163,17 +163,23 @@ export const start = async (app, url, file) => {
|
|
|
163
163
|
try {
|
|
164
164
|
await feature.handler({...req, headers: req.headers, body: {...req.body, topic} }, res)
|
|
165
165
|
} catch (err) {
|
|
166
|
+
if (process.env.DEBUG_MODE)
|
|
167
|
+
console.log(err)
|
|
166
168
|
throw {status: 500, message: "Failed to GET feature", ...err}
|
|
167
169
|
}
|
|
168
170
|
} else if (method !== "get" && feature.bypass) {
|
|
169
171
|
try {
|
|
170
172
|
await feature.handler(topic, prepareMessage(req), req, res)
|
|
171
173
|
} catch (err) {
|
|
174
|
+
if (process.env.DEBUG_MODE)
|
|
175
|
+
console.log(err)
|
|
172
176
|
throw {status: 500, message: "Failed to POST feature", ...err}
|
|
173
177
|
}
|
|
174
178
|
} else
|
|
175
179
|
await commandAction(req, res, topic)
|
|
176
180
|
} catch (err) {
|
|
181
|
+
if (process.env.DEBUG_MODE)
|
|
182
|
+
console.log(err)
|
|
177
183
|
try { // Sometimes error occurs when disconnecting stream from front end
|
|
178
184
|
res.status(err.status ?? 500).json(err)
|
|
179
185
|
} catch (_) { }
|
package/libs/session.js
CHANGED
|
@@ -45,9 +45,12 @@ export const start = (expressApp, allowedUrls) => {
|
|
|
45
45
|
let { userId, clientId, refreshToken } = req.body
|
|
46
46
|
const decoded = jwt.verify(refreshToken, REFRESH_TOKEN_SECRET)
|
|
47
47
|
if (decoded.userId === userId && decoded.clientId === clientId) {
|
|
48
|
+
let now = Utils.now()
|
|
49
|
+
let accessTokenExpiry = new Date(now); accessTokenExpiry.setDate(accessTokenExpiry.getDate() + 1); accessTokenExpiry = accessTokenExpiry.getTime()
|
|
50
|
+
let refreshTokenExpiry = new Date(now); refreshTokenExpiry.setDate(refreshTokenExpiry.getDate() + 30); refreshTokenExpiry = refreshTokenExpiry.getTime()
|
|
48
51
|
const accessToken = jwt.sign({ userId, clientId }, ACCESS_TOKEN_SECRET, { expiresIn: '1d' });
|
|
49
52
|
const refreshToken = jwt.sign({ userId, clientId }, REFRESH_TOKEN_SECRET, { expiresIn: '30d' });
|
|
50
|
-
return res.json({ tokens: { accessToken, refreshToken } });
|
|
53
|
+
return res.json({ tokens: { accessToken, refreshToken, accessTokenExpiry, refreshTokenExpiry} });
|
|
51
54
|
}
|
|
52
55
|
// Access Denied
|
|
53
56
|
throw null;
|