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.
@@ -1,5 +1,5 @@
1
- import { T as TSchema, P as ProtoService } from '../../internals/index-rcLPSrw6.js';
2
- import { F as FileStorageBase, a as FileStorageOptions } from '../../internals/index-D1h-5NmA.js';
1
+ import { T as TSchema, P as ProtoService } from '../../internals/index-BabXTvEZ.js';
2
+ import { F as FileStorageBase, a as FileStorageOptions } from '../../internals/index-DCjn9EDu.js';
3
3
  import '@o2ter/utils-js';
4
4
  import 'jsonwebtoken';
5
5
  import '@o2ter/server-js';
@@ -1,5 +1,5 @@
1
- import { P as ProtoService } from '../../internals/index-rcLPSrw6.js';
2
- import { F as FileStorageBase, a as FileStorageOptions } from '../../internals/index-D1h-5NmA.js';
1
+ import { P as ProtoService } from '../../internals/index-BabXTvEZ.js';
2
+ import { F as FileStorageBase, a as FileStorageOptions } from '../../internals/index-DCjn9EDu.js';
3
3
  import '@o2ter/utils-js';
4
4
  import 'jsonwebtoken';
5
5
  import '@o2ter/server-js';
@@ -1,7 +1,7 @@
1
1
  import * as _google_cloud_storage from '@google-cloud/storage';
2
2
  import { Storage } from '@google-cloud/storage';
3
- import { P as ProtoService } from '../../internals/index-rcLPSrw6.js';
4
- import { F as FileStorageBase, a as FileStorageOptions } from '../../internals/index-D1h-5NmA.js';
3
+ import { P as ProtoService } from '../../internals/index-BabXTvEZ.js';
4
+ import { F as FileStorageBase, a as FileStorageOptions } from '../../internals/index-DCjn9EDu.js';
5
5
  import '@o2ter/utils-js';
6
6
  import 'jsonwebtoken';
7
7
  import '@o2ter/server-js';
@@ -1,5 +1,5 @@
1
1
  import { Pool, PoolClient, PoolConfig } from 'pg';
2
- import { _ as _TValue, o as EventData, T as TSchema, q as DecodedQuery, F as FindOptions, Q as QuerySelector, r as DecodedSortOption, I as InsertOptions, t as TValue, u as FindOneOptions, v as TUpdateOp, w as FieldSelectorExpression, x as QueryExpression, y as TStorage, z as TransactionOptions, h as TObject, A as TQueryRandomOptions, B as TPubSub } from '../../internals/index-rcLPSrw6.js';
2
+ import { _ as _TValue, o as EventData, T as TSchema, q as DecodedQuery, F as FindOptions, Q as QuerySelector, r as DecodedSortOption, I as InsertOptions, t as TValue, u as FindOneOptions, v as TUpdateOp, w as FieldSelectorExpression, x as QueryExpression, y as TStorage, z as TransactionOptions, h as TObject, A as TQueryRandomOptions, B as TPubSub } from '../../internals/index-BabXTvEZ.js';
3
3
  import * as _o2ter_utils_js from '@o2ter/utils-js';
4
4
  import { asyncStream } from '@o2ter/utils-js';
5
5
  import 'jsonwebtoken';
package/dist/client.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { P as ProtoClient } from './internals/index-DRgmWum4.js';
2
- export { c as classExtends, e as isFile, a as isObject, i as isQuery, d as isRole, b as isUser } from './internals/index-DRgmWum4.js';
1
+ import { P as ProtoClient } from './internals/index-BtnEuEVn.js';
2
+ export { c as classExtends, e as isFile, a as isObject, i as isQuery, d as isRole, b as isUser } from './internals/index-BtnEuEVn.js';
3
3
  export { Decimal } from 'decimal.js';
4
- export { D as DeserializeOptions, S as SerializeOptions, d as TSerializable, e as deserialize, s as serialize } from './internals/index-rcLPSrw6.js';
4
+ export { D as DeserializeOptions, S as SerializeOptions, d as TSerializable, e as deserialize, s as serialize } from './internals/index-BabXTvEZ.js';
5
5
  import '@o2ter/utils-js';
6
6
  import 'socket.io-client';
7
7
  import '@socket.io/component-emitter';
package/dist/client.js CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var index = require('./internals/index-CTyYPai3.js');
5
+ var index = require('./internals/index-D5nf79vF.js');
6
6
  var Decimal = require('decimal.js');
7
7
  require('./internals/index-C6zdNpc_.js');
8
8
  require('lodash');
package/dist/client.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { c as ProtoClient } from './internals/index-C8hhBfuh.mjs';
2
- export { e as classExtends, d as deserialize, j as isFile, f as isObject, i as isQuery, h as isRole, g as isUser, s as serialize } from './internals/index-C8hhBfuh.mjs';
1
+ import { c as ProtoClient } from './internals/index-ZIegYNKT.mjs';
2
+ export { e as classExtends, d as deserialize, j as isFile, f as isObject, i as isQuery, h as isRole, g as isUser, s as serialize } from './internals/index-ZIegYNKT.mjs';
3
3
  export { Decimal } from 'decimal.js';
4
4
  import './internals/index-EOtjV6U_.mjs';
5
5
  import 'lodash';
package/dist/index.d.ts CHANGED
@@ -2,11 +2,11 @@ import * as socket_io from 'socket.io';
2
2
  import * as socket_io_dist_typed_events from 'socket.io/dist/typed-events';
3
3
  import * as express_serve_static_core from 'express-serve-static-core';
4
4
  import { Server, RequestHandler } from '@o2ter/server-js';
5
- import { T as TSchema, _ as _TValue, P as ProtoService, a as ProtoServiceOptions, b as ProtoServiceKeyOptions } from './internals/index-rcLPSrw6.js';
6
- export { D as DeserializeOptions, S as SerializeOptions, c as TFileStorage, d as TSerializable, e as deserialize, s as serialize } from './internals/index-rcLPSrw6.js';
5
+ import { T as TSchema, _ as _TValue, P as ProtoService, a as ProtoServiceOptions, b as ProtoServiceKeyOptions } from './internals/index-BabXTvEZ.js';
6
+ export { D as DeserializeOptions, S as SerializeOptions, c as TFileStorage, d as TSerializable, e as deserialize, s as serialize } from './internals/index-BabXTvEZ.js';
7
7
  import Decimal from 'decimal.js';
8
8
  export { Decimal } from 'decimal.js';
9
- export { P as ProtoClient, c as classExtends, e as isFile, a as isObject, i as isQuery, d as isRole, b as isUser } from './internals/index-DRgmWum4.js';
9
+ export { P as ProtoClient, c as classExtends, e as isFile, a as isObject, i as isQuery, d as isRole, b as isUser } from './internals/index-BtnEuEVn.js';
10
10
  import '@o2ter/utils-js';
11
11
  import 'jsonwebtoken';
12
12
  import 'lodash';
package/dist/index.js CHANGED
@@ -7,7 +7,7 @@ var serverJs = require('@o2ter/server-js');
7
7
  var random = require('./internals/random-CiJ8I0Cd.js');
8
8
  var _private = require('./internals/private-CSB1Ep4g.js');
9
9
  var utilsJs = require('@o2ter/utils-js');
10
- var index = require('./internals/index-CTyYPai3.js');
10
+ var index = require('./internals/index-D5nf79vF.js');
11
11
  var index$1 = require('./internals/index-C6zdNpc_.js');
12
12
  var jwt = require('jsonwebtoken');
13
13
  var node_buffer = require('node:buffer');
@@ -1083,7 +1083,7 @@ const _sessionWithToken = (proto, token) => {
1083
1083
  const _session = (proto, request) => {
1084
1084
  const cached = sessionMap.get(request);
1085
1085
  if (cached)
1086
- return cached?.payload;
1086
+ return cached;
1087
1087
  sessionMap.set(request, { sessionId: cryptoJs.randomUUID() });
1088
1088
  const jwtToken = proto[_private.PVK].options.jwtToken;
1089
1089
  if (_.isEmpty(jwtToken))
@@ -1102,11 +1102,12 @@ const _session = (proto, request) => {
1102
1102
  const payload = proto[_private.PVK].jwtVarify(authorization, 'login');
1103
1103
  if (!_.isObject(payload))
1104
1104
  return;
1105
- sessionMap.set(request, {
1105
+ const session = {
1106
1106
  sessionId: payload.sessionId ?? cryptoJs.randomUUID(),
1107
- payload,
1108
- });
1109
- return payload;
1107
+ ...payload,
1108
+ };
1109
+ sessionMap.set(request, session);
1110
+ return session;
1110
1111
  };
1111
1112
  const sessionId = (proto, request) => {
1112
1113
  const session = _session(proto, request);
@@ -1129,13 +1130,12 @@ const sessionWithToken = async (proto, token) => {
1129
1130
  };
1130
1131
  const session = async (proto, request) => {
1131
1132
  const session = _session(proto, request);
1132
- const sessionId = sessionMap.get(request)?.sessionId ?? session?.sessionId;
1133
1133
  const cached = sessionInfoMap.get(request);
1134
1134
  if (cached)
1135
- return { sessionId, ...cached };
1135
+ return { ...session ?? {}, ...cached };
1136
1136
  const info = await fetchSessionInfo(proto, session?.user);
1137
1137
  sessionInfoMap.set(request, info);
1138
- return { sessionId, ...info };
1138
+ return { ...session ?? {}, ...info };
1139
1139
  };
1140
1140
  const sessionIsMaster = (proto, request) => {
1141
1141
  const user = request.header(index.MASTER_USER_HEADER_NAME);
@@ -1305,17 +1305,18 @@ class ProtoService extends index.ProtoType {
1305
1305
  return this.session.sessionId;
1306
1306
  return this.req ? sessionId(this, this.req) : undefined;
1307
1307
  }
1308
- async currentUser() {
1308
+ async sessionInfo() {
1309
1309
  if (this.session)
1310
- return this.session.user;
1311
- const _session = this.req ? await session(this, this.req) : undefined;
1312
- return _session?.user;
1310
+ return this.session;
1311
+ return this.req ? session(this, this.req) : undefined;
1312
+ }
1313
+ async currentUser() {
1314
+ const session = await this.sessionInfo();
1315
+ return session?.user;
1313
1316
  }
1314
1317
  async currentRoles() {
1315
- if (this.session)
1316
- return this.session.roles ?? [];
1317
- const _session = this.req ? await session(this, this.req) : undefined;
1318
- return _session?.roles ?? [];
1318
+ const session = await this.sessionInfo();
1319
+ return session?.roles ?? [];
1319
1320
  }
1320
1321
  get isMaster() {
1321
1322
  return this.req ? sessionIsMaster(this, this.req) === 'valid' : false;
@@ -2098,6 +2099,9 @@ const ProtoRoute = async (options) => {
2098
2099
  res.status(400).json({ message: 'Invalid token' });
2099
2100
  });
2100
2101
  router.get('/health', (req, res) => { res.sendStatus(200); });
2102
+ router.get('/sessionInfo', async (req, res) => {
2103
+ await response(res, () => proto.connect(req).sessionInfo());
2104
+ });
2101
2105
  classesRoute(router, proto);
2102
2106
  functionRoute(router, proto);
2103
2107
  filesRoute(router, proto);