@entity-access/server-pages 1.0.42 → 1.1.2
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/Page.d.ts +6 -13
- package/dist/Page.d.ts.map +1 -1
- package/dist/Page.js +10 -41
- package/dist/Page.js.map +1 -1
- package/dist/ServerPages.d.ts.map +1 -1
- package/dist/ServerPages.js +14 -2
- package/dist/ServerPages.js.map +1 -1
- package/dist/core/CacheProperty.d.ts +5 -0
- package/dist/core/CacheProperty.d.ts.map +1 -0
- package/dist/core/CacheProperty.js +19 -0
- package/dist/core/CacheProperty.js.map +1 -0
- package/dist/core/Executor.d.ts +5 -0
- package/dist/core/Executor.d.ts.map +1 -0
- package/dist/core/Executor.js +13 -0
- package/dist/core/Executor.js.map +1 -0
- package/dist/core/RouteTree.d.ts.map +1 -1
- package/dist/core/RouteTree.js +15 -6
- package/dist/core/RouteTree.js.map +1 -1
- package/dist/core/SessionUser.d.ts +7 -5
- package/dist/core/SessionUser.d.ts.map +1 -1
- package/dist/core/SessionUser.js +36 -0
- package/dist/core/SessionUser.js.map +1 -1
- package/dist/core/Wrapped.d.ts +13 -16
- package/dist/core/Wrapped.d.ts.map +1 -1
- package/dist/core/Wrapped.js +151 -235
- package/dist/core/Wrapped.js.map +1 -1
- package/dist/decorators/Prepare.d.ts +14 -0
- package/dist/decorators/Prepare.d.ts.map +1 -0
- package/dist/decorators/Prepare.js +111 -0
- package/dist/decorators/Prepare.js.map +1 -0
- package/dist/routes/api/entity/index.d.ts.map +1 -1
- package/dist/routes/api/entity/index.js +9 -3
- package/dist/routes/api/entity/index.js.map +1 -1
- package/dist/routes/api/entity/model/get.d.ts.map +1 -1
- package/dist/routes/api/entity/model/get.js.map +1 -1
- package/dist/routes/api/entity/query/get.d.ts.map +1 -1
- package/dist/routes/api/entity/query/get.js +9 -3
- package/dist/routes/api/entity/query/get.js.map +1 -1
- package/dist/services/CookieService.d.ts.map +1 -1
- package/dist/services/CookieService.js +10 -2
- package/dist/services/CookieService.js.map +1 -1
- package/dist/socket/SocketService.d.ts.map +1 -1
- package/dist/socket/SocketService.js +1 -3
- package/dist/socket/SocketService.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/Page.tsx +11 -51
- package/src/ServerPages.ts +14 -2
- package/src/core/CacheProperty.ts +18 -0
- package/src/core/Executor.ts +16 -0
- package/src/core/RouteTree.ts +7 -3
- package/src/core/SessionUser.ts +21 -5
- package/src/core/Wrapped.ts +206 -270
- package/src/decorators/Prepare.ts +132 -0
- package/src/index.d.ts +10 -10
- package/src/routes/api/entity/index.tsx +4 -1
- package/src/routes/api/entity/model/get.tsx +1 -1
- package/src/routes/api/entity/query/get.ts +4 -1
- package/src/services/CookieService.ts +10 -2
- package/src/socket/SocketService.ts +1 -2
- package/dist/decorators/Authorize.d.ts +0 -2
- package/dist/decorators/Authorize.d.ts.map +0 -1
- package/dist/decorators/Authorize.js +0 -3
- package/dist/decorators/Authorize.js.map +0 -1
- package/src/decorators/Authorize.ts +0 -3
package/src/index.d.ts
CHANGED
|
@@ -3,14 +3,14 @@ import type SessionUser from "./core/SessionUser.ts";
|
|
|
3
3
|
export {};
|
|
4
4
|
|
|
5
5
|
declare global {
|
|
6
|
-
namespace Express {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
6
|
+
// namespace Express {
|
|
7
|
+
// // eslint-disable-next-line @typescript-eslint/naming-convention
|
|
8
|
+
// export interface Request {
|
|
9
|
+
// /**
|
|
10
|
+
// * user will always be set, even in case if it is an anonymous request.
|
|
11
|
+
// * This is to track actual views.
|
|
12
|
+
// */
|
|
13
|
+
// user: SessionUser;
|
|
14
|
+
// }
|
|
15
|
+
// }
|
|
16
16
|
}
|
|
@@ -5,9 +5,12 @@ import SchemaRegistry from "@entity-access/entity-access/dist/decorators/SchemaR
|
|
|
5
5
|
import EntityAccessError from "@entity-access/entity-access/dist/common/EntityAccessError.js";
|
|
6
6
|
import Page, { IRouteCheck } from "../../../Page.js";
|
|
7
7
|
import GraphService from "../../../services/GraphService.js";
|
|
8
|
+
import { Prepare } from "../../../decorators/Prepare.js";
|
|
8
9
|
|
|
9
10
|
const added = Symbol("added");
|
|
10
11
|
|
|
12
|
+
@Prepare.authorize
|
|
13
|
+
@Prepare.parseJsonBody
|
|
11
14
|
export default class extends Page {
|
|
12
15
|
|
|
13
16
|
static canHandle(pageContext: IRouteCheck): boolean {
|
|
@@ -22,7 +25,7 @@ export default class extends Page {
|
|
|
22
25
|
this.db.verifyFilters = true;
|
|
23
26
|
this.db.raiseEvents = true;
|
|
24
27
|
|
|
25
|
-
const body =
|
|
28
|
+
const body = this.body;
|
|
26
29
|
|
|
27
30
|
if (/delete/i.test(this.method)) {
|
|
28
31
|
return this.delete(body);
|
|
@@ -2,6 +2,7 @@ import Inject from "@entity-access/entity-access/dist/di/di.js";
|
|
|
2
2
|
import EntityContext from "@entity-access/entity-access/dist/model/EntityContext.js";
|
|
3
3
|
import Page from "../../../../Page.js";
|
|
4
4
|
import ModelService from "../../../../services/ModelService.js";
|
|
5
|
+
import { Prepare } from "../../../../decorators/Prepare.js";
|
|
5
6
|
|
|
6
7
|
export default class extends Page {
|
|
7
8
|
|
|
@@ -9,7 +10,6 @@ export default class extends Page {
|
|
|
9
10
|
db: EntityContext;
|
|
10
11
|
|
|
11
12
|
all() {
|
|
12
|
-
|
|
13
13
|
return this.json(ModelService.getModel(this.db), 4);
|
|
14
14
|
}
|
|
15
15
|
|
|
@@ -2,7 +2,10 @@ import Inject from "@entity-access/entity-access/dist/di/di.js";
|
|
|
2
2
|
import EntityContext from "@entity-access/entity-access/dist/model/EntityContext.js";
|
|
3
3
|
import Page from "../../../../Page.js";
|
|
4
4
|
import EntityAccessServer from "../../../../services/EntityAccessServer.js";
|
|
5
|
+
import { Prepare } from "../../../../decorators/Prepare.js";
|
|
5
6
|
|
|
7
|
+
@Prepare.authorize
|
|
8
|
+
@Prepare.parseJsonBody
|
|
6
9
|
export default class extends Page {
|
|
7
10
|
|
|
8
11
|
@Inject
|
|
@@ -13,7 +16,7 @@ export default class extends Page {
|
|
|
13
16
|
return this.json(await EntityAccessServer.query(this.db, {
|
|
14
17
|
entity,
|
|
15
18
|
... this.query,
|
|
16
|
-
...
|
|
19
|
+
... this.body
|
|
17
20
|
}));
|
|
18
21
|
}
|
|
19
22
|
|
|
@@ -66,13 +66,21 @@ export default class CookieService {
|
|
|
66
66
|
public clearCache = clearCache;
|
|
67
67
|
|
|
68
68
|
async createSessionUserFromCookie(cookie: string, ip: string) {
|
|
69
|
-
const user =
|
|
69
|
+
const user = ServiceProvider.resolve(this, SessionUser);
|
|
70
|
+
const ua = user as any;
|
|
71
|
+
ua.isAuthorized = true;
|
|
72
|
+
ua.authorize = () => null;
|
|
73
|
+
ua.sessionID = null;
|
|
74
|
+
ua.userID = null;
|
|
75
|
+
ua.userName = null;
|
|
76
|
+
ua.roles = [];
|
|
77
|
+
ua.expiry = null;
|
|
70
78
|
try {
|
|
71
79
|
user.ipAddress = ip;
|
|
72
80
|
if (cookie) {
|
|
73
81
|
const userInfo = await this.getVerifiedUser(cookie);
|
|
74
82
|
if (userInfo?.sessionID) {
|
|
75
|
-
user.sessionID = userInfo.sessionID;
|
|
83
|
+
(user as any).sessionID = userInfo.sessionID;
|
|
76
84
|
}
|
|
77
85
|
if (userInfo?.userID) {
|
|
78
86
|
user[tagForCache] = userInfo;
|
|
@@ -61,8 +61,7 @@ export default abstract class SocketService {
|
|
|
61
61
|
try {
|
|
62
62
|
const cookieService = scope.resolve(CookieService);
|
|
63
63
|
const cookie = cookies[tokenService.authCookieName];
|
|
64
|
-
|
|
65
|
-
scope.add(SessionUser, sessionUser);
|
|
64
|
+
await cookieService.createSessionUserFromCookie(cookie, socket.handshake.address);
|
|
66
65
|
scope.add(Socket, socket);
|
|
67
66
|
const method = sns[methodName];
|
|
68
67
|
const types = method[injectServiceKeysSymbol] as any[];
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Authorize.d.ts","sourceRoot":"","sources":["../../src/decorators/Authorize.ts"],"names":[],"mappings":"AAAA,wBAAgB,SAAS,SAExB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Authorize.js","sourceRoot":"","sources":["../../src/decorators/Authorize.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,SAAS;AAEzB,CAAC"}
|