proto.io 0.0.139 → 0.0.141
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 +43 -31
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +44 -32
- 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
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { T as TSchema, P as ProtoService } from '../../internals/index-
|
|
2
|
-
import { F as FileStorageBase, a as FileStorageOptions } from '../../internals/index-
|
|
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-
|
|
2
|
-
import { F as FileStorageBase, a as FileStorageOptions } from '../../internals/index-
|
|
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-
|
|
4
|
-
import { F as FileStorageBase, a as FileStorageOptions } from '../../internals/index-
|
|
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-
|
|
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-
|
|
2
|
-
export { c as classExtends, e as isFile, a as isObject, i as isQuery, d as isRole, b as isUser } from './internals/index-
|
|
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-
|
|
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-
|
|
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-
|
|
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-
|
|
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-
|
|
6
|
-
export { D as DeserializeOptions, S as SerializeOptions, c as TFileStorage, d as TSerializable, e as deserialize, s as serialize } from './internals/index-
|
|
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-
|
|
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-
|
|
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');
|
|
@@ -695,15 +695,30 @@ const validateShapedObject = (schema, dataType) => {
|
|
|
695
695
|
}
|
|
696
696
|
}
|
|
697
697
|
};
|
|
698
|
-
const
|
|
698
|
+
const validateSchemaPermission = (schema) => {
|
|
699
699
|
if (!_.isNil(schema['_Schema']) || !_.isNil(schema['_Config']))
|
|
700
700
|
throw Error('Reserved name of class');
|
|
701
|
+
for (const [, _schema] of _.toPairs(schema)) {
|
|
702
|
+
for (const [key] of _.toPairs(_schema.fields)) {
|
|
703
|
+
if (_.includes(index$1.TObject.defaultKeys, key))
|
|
704
|
+
throw Error(`Reserved field name: ${key}`);
|
|
705
|
+
}
|
|
706
|
+
const fields = _.keys(_schema.fields);
|
|
707
|
+
for (const key of _.keys(_schema.fieldLevelPermissions)) {
|
|
708
|
+
if (!fields.includes(key))
|
|
709
|
+
throw Error(`Invalid field permission: ${key}`);
|
|
710
|
+
}
|
|
711
|
+
for (const key of _schema.secureFields ?? []) {
|
|
712
|
+
if (!fields.includes(key))
|
|
713
|
+
throw Error(`Invalid field permission: ${key}`);
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
};
|
|
717
|
+
const validateSchema = (schema) => {
|
|
701
718
|
for (const [className, _schema] of _.toPairs(schema)) {
|
|
702
719
|
if (!className.match(random.QueryValidator.patterns.name))
|
|
703
720
|
throw Error(`Invalid class name: ${className}`);
|
|
704
721
|
for (const [key, dataType] of _.toPairs(_schema.fields)) {
|
|
705
|
-
if (_.includes(index$1.TObject.defaultKeys, key))
|
|
706
|
-
throw Error(`Reserved field name: ${key}`);
|
|
707
722
|
if (!key.match(random.QueryValidator.patterns.name))
|
|
708
723
|
throw Error(`Invalid field name: ${key}`);
|
|
709
724
|
if (index$1.isShape(dataType)) {
|
|
@@ -719,15 +734,6 @@ const validateSchema = (schema) => {
|
|
|
719
734
|
validateForeignField(schema, key, dataType);
|
|
720
735
|
}
|
|
721
736
|
}
|
|
722
|
-
const fields = _.keys(_schema.fields);
|
|
723
|
-
for (const key of _.keys(_schema.fieldLevelPermissions)) {
|
|
724
|
-
if (!fields.includes(key))
|
|
725
|
-
throw Error(`Invalid field permission: ${key}`);
|
|
726
|
-
}
|
|
727
|
-
for (const key of _schema.secureFields ?? []) {
|
|
728
|
-
if (!fields.includes(key))
|
|
729
|
-
throw Error(`Invalid field permission: ${key}`);
|
|
730
|
-
}
|
|
731
737
|
}
|
|
732
738
|
};
|
|
733
739
|
const mergeSchema = (...schemas) => _.reduce(schemas, (acc, schema) => ({
|
|
@@ -759,10 +765,12 @@ class ProtoInternal {
|
|
|
759
765
|
functions = {};
|
|
760
766
|
triggers = {};
|
|
761
767
|
constructor(options) {
|
|
762
|
-
|
|
768
|
+
validateSchemaPermission(options.schema);
|
|
769
|
+
const schema = mergeSchema(defaultSchema, options.fileStorage.schema, options.schema);
|
|
770
|
+
validateSchema(schema);
|
|
763
771
|
this.options = {
|
|
764
772
|
...options,
|
|
765
|
-
schema
|
|
773
|
+
schema,
|
|
766
774
|
};
|
|
767
775
|
}
|
|
768
776
|
async prepare() {
|
|
@@ -1083,7 +1091,7 @@ const _sessionWithToken = (proto, token) => {
|
|
|
1083
1091
|
const _session = (proto, request) => {
|
|
1084
1092
|
const cached = sessionMap.get(request);
|
|
1085
1093
|
if (cached)
|
|
1086
|
-
return cached
|
|
1094
|
+
return cached;
|
|
1087
1095
|
sessionMap.set(request, { sessionId: cryptoJs.randomUUID() });
|
|
1088
1096
|
const jwtToken = proto[_private.PVK].options.jwtToken;
|
|
1089
1097
|
if (_.isEmpty(jwtToken))
|
|
@@ -1102,11 +1110,12 @@ const _session = (proto, request) => {
|
|
|
1102
1110
|
const payload = proto[_private.PVK].jwtVarify(authorization, 'login');
|
|
1103
1111
|
if (!_.isObject(payload))
|
|
1104
1112
|
return;
|
|
1105
|
-
|
|
1113
|
+
const session = {
|
|
1106
1114
|
sessionId: payload.sessionId ?? cryptoJs.randomUUID(),
|
|
1107
|
-
payload,
|
|
1108
|
-
}
|
|
1109
|
-
|
|
1115
|
+
...payload,
|
|
1116
|
+
};
|
|
1117
|
+
sessionMap.set(request, session);
|
|
1118
|
+
return session;
|
|
1110
1119
|
};
|
|
1111
1120
|
const sessionId = (proto, request) => {
|
|
1112
1121
|
const session = _session(proto, request);
|
|
@@ -1129,13 +1138,12 @@ const sessionWithToken = async (proto, token) => {
|
|
|
1129
1138
|
};
|
|
1130
1139
|
const session = async (proto, request) => {
|
|
1131
1140
|
const session = _session(proto, request);
|
|
1132
|
-
const sessionId = sessionMap.get(request)?.sessionId ?? session?.sessionId;
|
|
1133
1141
|
const cached = sessionInfoMap.get(request);
|
|
1134
1142
|
if (cached)
|
|
1135
|
-
return {
|
|
1143
|
+
return { ...session ?? {}, ...cached };
|
|
1136
1144
|
const info = await fetchSessionInfo(proto, session?.user);
|
|
1137
1145
|
sessionInfoMap.set(request, info);
|
|
1138
|
-
return {
|
|
1146
|
+
return { ...session ?? {}, ...info };
|
|
1139
1147
|
};
|
|
1140
1148
|
const sessionIsMaster = (proto, request) => {
|
|
1141
1149
|
const user = request.header(index.MASTER_USER_HEADER_NAME);
|
|
@@ -1305,17 +1313,18 @@ class ProtoService extends index.ProtoType {
|
|
|
1305
1313
|
return this.session.sessionId;
|
|
1306
1314
|
return this.req ? sessionId(this, this.req) : undefined;
|
|
1307
1315
|
}
|
|
1308
|
-
async
|
|
1316
|
+
async sessionInfo() {
|
|
1309
1317
|
if (this.session)
|
|
1310
|
-
return this.session
|
|
1311
|
-
|
|
1312
|
-
|
|
1318
|
+
return this.session;
|
|
1319
|
+
return this.req ? session(this, this.req) : undefined;
|
|
1320
|
+
}
|
|
1321
|
+
async currentUser() {
|
|
1322
|
+
const session = await this.sessionInfo();
|
|
1323
|
+
return session?.user;
|
|
1313
1324
|
}
|
|
1314
1325
|
async currentRoles() {
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
const _session = this.req ? await session(this, this.req) : undefined;
|
|
1318
|
-
return _session?.roles ?? [];
|
|
1326
|
+
const session = await this.sessionInfo();
|
|
1327
|
+
return session?.roles ?? [];
|
|
1319
1328
|
}
|
|
1320
1329
|
get isMaster() {
|
|
1321
1330
|
return this.req ? sessionIsMaster(this, this.req) === 'valid' : false;
|
|
@@ -2098,6 +2107,9 @@ const ProtoRoute = async (options) => {
|
|
|
2098
2107
|
res.status(400).json({ message: 'Invalid token' });
|
|
2099
2108
|
});
|
|
2100
2109
|
router.get('/health', (req, res) => { res.sendStatus(200); });
|
|
2110
|
+
router.get('/sessionInfo', async (req, res) => {
|
|
2111
|
+
await response(res, () => proto.connect(req).sessionInfo());
|
|
2112
|
+
});
|
|
2101
2113
|
classesRoute(router, proto);
|
|
2102
2114
|
functionRoute(router, proto);
|
|
2103
2115
|
filesRoute(router, proto);
|