proto.io 0.0.139 → 0.0.140
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/adapters/file/database.d.ts +2 -2
- package/dist/adapters/file/filesystem.d.ts +2 -2
- package/dist/adapters/file/google-cloud-storage.d.ts +2 -2
- package/dist/adapters/storage/progres.d.ts +1 -1
- package/dist/client.d.ts +3 -3
- package/dist/client.js +1 -1
- package/dist/client.mjs +2 -2
- package/dist/index.d.ts +3 -3
- package/dist/index.js +21 -17
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +22 -18
- package/dist/index.mjs.map +1 -1
- package/dist/internals/{index-rcLPSrw6.d.ts → index-BabXTvEZ.d.ts} +18 -9
- package/dist/internals/index-BabXTvEZ.d.ts.map +1 -0
- package/dist/internals/{index-DRgmWum4.d.ts → index-BtnEuEVn.d.ts} +4 -2
- package/dist/internals/index-BtnEuEVn.d.ts.map +1 -0
- package/dist/internals/{index-CTyYPai3.js → index-D5nf79vF.js} +15 -1
- package/dist/internals/{index-CTyYPai3.js.map → index-D5nf79vF.js.map} +1 -1
- package/dist/internals/{index-D1h-5NmA.d.ts → index-DCjn9EDu.d.ts} +2 -2
- package/dist/internals/index-DCjn9EDu.d.ts.map +1 -0
- package/dist/internals/{index-C8hhBfuh.mjs → index-ZIegYNKT.mjs} +15 -1
- package/dist/internals/{index-C8hhBfuh.mjs.map → index-ZIegYNKT.mjs.map} +1 -1
- package/package.json +1 -1
- package/dist/internals/index-D1h-5NmA.d.ts.map +0 -1
- package/dist/internals/index-DRgmWum4.d.ts.map +0 -1
- package/dist/internals/index-rcLPSrw6.d.ts.map +0 -1
package/dist/index.mjs
CHANGED
|
@@ -3,8 +3,8 @@ import { Server } from '@o2ter/server-js';
|
|
|
3
3
|
import { Q as QueryValidator, g as generateId } from './internals/random-Dn9rhwfh.mjs';
|
|
4
4
|
import { P as PVK } from './internals/private-BUpLAMZi.mjs';
|
|
5
5
|
import { asyncStream, asyncIterableToArray, isBinaryData, base64ToBuffer } from '@o2ter/utils-js';
|
|
6
|
-
import { T as TQuery, M as MASTER_USER_HEADER_NAME, a as MASTER_PASS_HEADER_NAME, A as AUTH_COOKIE_KEY, b as TUser, P as ProtoType, s as serialize, d as deserialize, U as UPLOAD_TOKEN_HEADER_NAME } from './internals/index-
|
|
7
|
-
export { c as ProtoClient, e as classExtends, j as isFile, f as isObject, i as isQuery, h as isRole, g as isUser } from './internals/index-
|
|
6
|
+
import { T as TQuery, M as MASTER_USER_HEADER_NAME, a as MASTER_PASS_HEADER_NAME, A as AUTH_COOKIE_KEY, b as TUser, P as ProtoType, s as serialize, d as deserialize, U as UPLOAD_TOKEN_HEADER_NAME } from './internals/index-ZIegYNKT.mjs';
|
|
7
|
+
export { c as ProtoClient, e as classExtends, j as isFile, f as isObject, i as isQuery, h as isRole, g as isUser } from './internals/index-ZIegYNKT.mjs';
|
|
8
8
|
import { d as decodeUpdateOp, T as TObject, i as isShape, a as isPointer, b as isRelation, c as defaultObjectKeyTypes, e as isPrimitive } from './internals/index-EOtjV6U_.mjs';
|
|
9
9
|
import jwt from 'jsonwebtoken';
|
|
10
10
|
import { Blob } from 'node:buffer';
|
|
@@ -1080,7 +1080,7 @@ const _sessionWithToken = (proto, token) => {
|
|
|
1080
1080
|
const _session = (proto, request) => {
|
|
1081
1081
|
const cached = sessionMap.get(request);
|
|
1082
1082
|
if (cached)
|
|
1083
|
-
return cached
|
|
1083
|
+
return cached;
|
|
1084
1084
|
sessionMap.set(request, { sessionId: randomUUID() });
|
|
1085
1085
|
const jwtToken = proto[PVK].options.jwtToken;
|
|
1086
1086
|
if (_.isEmpty(jwtToken))
|
|
@@ -1099,11 +1099,12 @@ const _session = (proto, request) => {
|
|
|
1099
1099
|
const payload = proto[PVK].jwtVarify(authorization, 'login');
|
|
1100
1100
|
if (!_.isObject(payload))
|
|
1101
1101
|
return;
|
|
1102
|
-
|
|
1102
|
+
const session = {
|
|
1103
1103
|
sessionId: payload.sessionId ?? randomUUID(),
|
|
1104
|
-
payload,
|
|
1105
|
-
}
|
|
1106
|
-
|
|
1104
|
+
...payload,
|
|
1105
|
+
};
|
|
1106
|
+
sessionMap.set(request, session);
|
|
1107
|
+
return session;
|
|
1107
1108
|
};
|
|
1108
1109
|
const sessionId = (proto, request) => {
|
|
1109
1110
|
const session = _session(proto, request);
|
|
@@ -1126,13 +1127,12 @@ const sessionWithToken = async (proto, token) => {
|
|
|
1126
1127
|
};
|
|
1127
1128
|
const session = async (proto, request) => {
|
|
1128
1129
|
const session = _session(proto, request);
|
|
1129
|
-
const sessionId = sessionMap.get(request)?.sessionId ?? session?.sessionId;
|
|
1130
1130
|
const cached = sessionInfoMap.get(request);
|
|
1131
1131
|
if (cached)
|
|
1132
|
-
return {
|
|
1132
|
+
return { ...session ?? {}, ...cached };
|
|
1133
1133
|
const info = await fetchSessionInfo(proto, session?.user);
|
|
1134
1134
|
sessionInfoMap.set(request, info);
|
|
1135
|
-
return {
|
|
1135
|
+
return { ...session ?? {}, ...info };
|
|
1136
1136
|
};
|
|
1137
1137
|
const sessionIsMaster = (proto, request) => {
|
|
1138
1138
|
const user = request.header(MASTER_USER_HEADER_NAME);
|
|
@@ -1302,17 +1302,18 @@ class ProtoService extends ProtoType {
|
|
|
1302
1302
|
return this.session.sessionId;
|
|
1303
1303
|
return this.req ? sessionId(this, this.req) : undefined;
|
|
1304
1304
|
}
|
|
1305
|
-
async
|
|
1305
|
+
async sessionInfo() {
|
|
1306
1306
|
if (this.session)
|
|
1307
|
-
return this.session
|
|
1308
|
-
|
|
1309
|
-
|
|
1307
|
+
return this.session;
|
|
1308
|
+
return this.req ? session(this, this.req) : undefined;
|
|
1309
|
+
}
|
|
1310
|
+
async currentUser() {
|
|
1311
|
+
const session = await this.sessionInfo();
|
|
1312
|
+
return session?.user;
|
|
1310
1313
|
}
|
|
1311
1314
|
async currentRoles() {
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
const _session = this.req ? await session(this, this.req) : undefined;
|
|
1315
|
-
return _session?.roles ?? [];
|
|
1315
|
+
const session = await this.sessionInfo();
|
|
1316
|
+
return session?.roles ?? [];
|
|
1316
1317
|
}
|
|
1317
1318
|
get isMaster() {
|
|
1318
1319
|
return this.req ? sessionIsMaster(this, this.req) === 'valid' : false;
|
|
@@ -2095,6 +2096,9 @@ const ProtoRoute = async (options) => {
|
|
|
2095
2096
|
res.status(400).json({ message: 'Invalid token' });
|
|
2096
2097
|
});
|
|
2097
2098
|
router.get('/health', (req, res) => { res.sendStatus(200); });
|
|
2099
|
+
router.get('/sessionInfo', async (req, res) => {
|
|
2100
|
+
await response(res, () => proto.connect(req).sessionInfo());
|
|
2101
|
+
});
|
|
2098
2102
|
classesRoute(router, proto);
|
|
2099
2103
|
functionRoute(router, proto);
|
|
2100
2104
|
filesRoute(router, proto);
|