proto.io 0.0.150 → 0.0.152

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-013pxZ3P.js';
2
- import { F as FileStorageBase, a as FileStorageOptions } from '../../internals/index-CyX8Lu9K.js';
1
+ import { T as TSchema, P as ProtoService } from '../../internals/index-m4WmZoWj.js';
2
+ import { F as FileStorageBase, a as FileStorageOptions } from '../../internals/index-DeD3CiUK.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-013pxZ3P.js';
2
- import { F as FileStorageBase, a as FileStorageOptions } from '../../internals/index-CyX8Lu9K.js';
1
+ import { P as ProtoService } from '../../internals/index-m4WmZoWj.js';
2
+ import { F as FileStorageBase, a as FileStorageOptions } from '../../internals/index-DeD3CiUK.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-013pxZ3P.js';
4
- import { F as FileStorageBase, a as FileStorageOptions } from '../../internals/index-CyX8Lu9K.js';
3
+ import { P as ProtoService } from '../../internals/index-m4WmZoWj.js';
4
+ import { F as FileStorageBase, a as FileStorageOptions } from '../../internals/index-DeD3CiUK.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, n as EventData, T as TSchema, o as DecodedQuery, F as FindOptions, Q as QuerySelector, p as DecodedSortOption, I as InsertOptions, q as TValue, r as FindOneOptions, t as TUpdateOp, u as FieldSelectorExpression, v as QueryExpression, w as TStorage, x as TransactionOptions, h as TObject, y as TQueryRandomOptions, z as TPubSub } from '../../internals/index-013pxZ3P.js';
2
+ import { _ as _TValue, n as EventData, T as TSchema, o as DecodedQuery, F as FindOptions, Q as QuerySelector, p as DecodedSortOption, I as InsertOptions, q as TValue, r as FindOneOptions, t as TUpdateOp, u as FieldSelectorExpression, v as QueryExpression, w as TStorage, x as TransactionOptions, h as TObject, y as TQueryRandomOptions, z as TPubSub } from '../../internals/index-m4WmZoWj.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-CsRN32Jf.js';
2
- export { c as classExtends, e as isFile, a as isObject, i as isQuery, d as isRole, b as isUser } from './internals/index-CsRN32Jf.js';
1
+ import { P as ProtoClient } from './internals/index-DQm5Xz3Q.js';
2
+ export { c as classExtends, e as isFile, a as isObject, i as isQuery, d as isRole, b as isUser } from './internals/index-DQm5Xz3Q.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-013pxZ3P.js';
4
+ export { D as DeserializeOptions, S as SerializeOptions, d as TSerializable, e as deserialize, s as serialize } from './internals/index-m4WmZoWj.js';
5
5
  import '@o2ter/utils-js';
6
6
  import 'socket.io-client';
7
7
  import '@socket.io/component-emitter';
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-013pxZ3P.js';
6
- export { D as DeserializeOptions, S as SerializeOptions, c as TFileStorage, d as TSerializable, e as deserialize, s as serialize } from './internals/index-013pxZ3P.js';
5
+ import { T as TSchema, _ as _TValue, P as ProtoService, a as ProtoServiceOptions, b as ProtoServiceKeyOptions } from './internals/index-m4WmZoWj.js';
6
+ export { D as DeserializeOptions, S as SerializeOptions, c as TFileStorage, d as TSerializable, e as deserialize, s as serialize } from './internals/index-m4WmZoWj.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-CsRN32Jf.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-DQm5Xz3Q.js';
10
10
  import '@o2ter/utils-js';
11
11
  import 'jsonwebtoken';
12
12
  import 'lodash';
package/dist/index.js CHANGED
@@ -1115,7 +1115,10 @@ const _session = (proto, request) => {
1115
1115
  const cached = sessionMap.get(request);
1116
1116
  if (cached)
1117
1117
  return cached;
1118
- sessionMap.set(request, { sessionId: cryptoJs.randomUUID() });
1118
+ sessionMap.set(request, {
1119
+ sessionId: cryptoJs.randomUUID(),
1120
+ createdAt: new Date,
1121
+ });
1119
1122
  const jwtToken = proto[_private.PVK].options.jwtToken;
1120
1123
  if (_.isEmpty(jwtToken))
1121
1124
  throw Error('Invalid jwt token');
@@ -1134,8 +1137,9 @@ const _session = (proto, request) => {
1134
1137
  if (!_.isObject(payload))
1135
1138
  return;
1136
1139
  const session = {
1137
- sessionId: payload.sessionId ?? cryptoJs.randomUUID(),
1138
1140
  ...payload,
1141
+ sessionId: payload.sessionId ?? cryptoJs.randomUUID(),
1142
+ createdAt: new Date(payload.createdAt),
1139
1143
  };
1140
1144
  sessionMap.set(request, session);
1141
1145
  return session;
@@ -1147,9 +1151,9 @@ const sessionId = (proto, request) => {
1147
1151
  const sessionInfoMap = new WeakMap();
1148
1152
  const fetchSessionInfo = async (proto, userId) => {
1149
1153
  const user = _.isString(userId) ? await proto.Query('User').get(userId, { master: true }) : undefined;
1150
- const roles = user instanceof index.TUser ? _.compact(_.map(await proto.userRoles(user), x => x.name)) : [];
1154
+ const roles = user instanceof index.TUser ? _.filter(await proto.userRoles(user), x => !_.isEmpty(x.name)) : [];
1151
1155
  return {
1152
- roles: roles,
1156
+ _roles: roles,
1153
1157
  user: user instanceof index.TUser ? user : undefined,
1154
1158
  };
1155
1159
  };
@@ -1179,9 +1183,13 @@ const signUser = async (proto, res, user, options) => {
1179
1183
  if (_.isNil(proto[_private.PVK].options.jwtToken))
1180
1184
  return;
1181
1185
  const session = _session(proto, res.req);
1182
- const sessionId = sessionMap.get(res.req)?.sessionId ?? session?.sessionId ?? cryptoJs.randomUUID();
1183
1186
  const cookieOptions = options?.cookieOptions ?? session?.cookieOptions ?? proto[_private.PVK].options.cookieOptions;
1184
- const token = proto[_private.PVK].jwtSign({ sessionId, user: user?.objectId, cookieOptions }, options?.jwtSignOptions ?? 'login');
1187
+ const token = proto[_private.PVK].jwtSign({
1188
+ sessionId: session?.sessionId ?? cryptoJs.randomUUID(),
1189
+ createdAt: session?.createdAt?.getTime() ?? Date.now(),
1190
+ user: user?.objectId,
1191
+ cookieOptions,
1192
+ }, options?.jwtSignOptions ?? 'login');
1185
1193
  res.cookie(index.AUTH_COOKIE_KEY, token, cookieOptions);
1186
1194
  sessionInfoMap.set(res.req, user ? await fetchSessionInfo(proto, user.objectId) : {});
1187
1195
  };
@@ -1346,9 +1354,13 @@ class ProtoService extends index.ProtoType {
1346
1354
  const session = await this.sessionInfo();
1347
1355
  return session?.user;
1348
1356
  }
1349
- async currentRoles() {
1357
+ async _currentRoles() {
1350
1358
  const session = await this.sessionInfo();
1351
- return session?.roles ?? [];
1359
+ return session?._roles ?? [];
1360
+ }
1361
+ async currentRoles() {
1362
+ const roles = await this._currentRoles();
1363
+ return _.compact(_.map(roles, x => x.name));
1352
1364
  }
1353
1365
  get isMaster() {
1354
1366
  return this.req ? sessionIsMaster(this, this.req) === 'valid' : false;