@grest-ts/http 0.0.48 → 0.0.50
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/README.md +243 -175
- package/dist/src/_dedupCheck.js +1 -1
- package/dist/src/client/GGContextKeySynchronizer.d.ts +11 -0
- package/dist/src/client/GGContextKeySynchronizer.d.ts.map +1 -0
- package/dist/src/client/GGContextKeySynchronizer.js +26 -0
- package/dist/src/client/GGContextKeySynchronizer.js.map +1 -0
- package/dist/src/index-browser.d.ts +4 -2
- package/dist/src/index-browser.d.ts.map +1 -1
- package/dist/src/index-browser.js +4 -2
- package/dist/src/index-browser.js.map +1 -1
- package/dist/src/index-node.d.ts +8 -3
- package/dist/src/index-node.d.ts.map +1 -1
- package/dist/src/index-node.js +16 -7
- package/dist/src/index-node.js.map +1 -1
- package/dist/src/rpc/RpcRequest/GGRpcRequestBuilder.d.ts +4 -3
- package/dist/src/rpc/RpcRequest/GGRpcRequestBuilder.d.ts.map +1 -1
- package/dist/src/rpc/RpcRequest/GGRpcRequestBuilder.js +9 -2
- package/dist/src/rpc/RpcRequest/GGRpcRequestBuilder.js.map +1 -1
- package/dist/src/rpc/RpcRequest/GGRpcRequestParser.d.ts +3 -3
- package/dist/src/rpc/RpcRequest/GGRpcRequestParser.d.ts.map +1 -1
- package/dist/src/rpc/RpcRequest/GGRpcRequestParser.js +13 -16
- package/dist/src/rpc/RpcRequest/GGRpcRequestParser.js.map +1 -1
- package/dist/src/rpc/RpcResponse/GGRpcResponseBuilder.d.ts +1 -1
- package/dist/src/rpc/RpcResponse/GGRpcResponseBuilder.d.ts.map +1 -1
- package/dist/src/rpc/RpcResponse/GGRpcResponseBuilder.js +3 -3
- package/dist/src/rpc/RpcResponse/GGRpcResponseBuilder.js.map +1 -1
- package/dist/src/schema/GGCookie.d.ts +50 -0
- package/dist/src/schema/GGCookie.d.ts.map +1 -0
- package/dist/src/schema/GGCookie.js +130 -0
- package/dist/src/schema/GGCookie.js.map +1 -0
- package/dist/src/schema/GGHeader.d.ts +23 -0
- package/dist/src/schema/GGHeader.d.ts.map +1 -0
- package/dist/src/schema/GGHeader.js +41 -0
- package/dist/src/schema/GGHeader.js.map +1 -0
- package/dist/src/schema/GGHttpPermissionsChecker.d.ts +9 -0
- package/dist/src/schema/GGHttpPermissionsChecker.d.ts.map +1 -0
- package/dist/src/schema/GGHttpPermissionsChecker.js +29 -0
- package/dist/src/schema/GGHttpPermissionsChecker.js.map +1 -0
- package/dist/src/schema/GGHttpSchema.d.ts +8 -59
- package/dist/src/schema/GGHttpSchema.d.ts.map +1 -1
- package/dist/src/schema/GGHttpSchema.js.map +1 -1
- package/dist/src/schema/GGWireContextKey.d.ts +30 -0
- package/dist/src/schema/GGWireContextKey.d.ts.map +1 -0
- package/dist/src/schema/GGWireContextKey.js +36 -0
- package/dist/src/schema/GGWireContextKey.js.map +1 -0
- package/dist/src/schema/GGWireContextKey.node.d.ts +36 -0
- package/dist/src/schema/GGWireContextKey.node.d.ts.map +1 -0
- package/dist/src/schema/GGWireContextKey.node.js +83 -0
- package/dist/src/schema/GGWireContextKey.node.js.map +1 -0
- package/dist/src/schema/httpSchema.d.ts +2 -2
- package/dist/src/schema/httpSchema.d.ts.map +1 -1
- package/dist/src/schema/httpSchema.js.map +1 -1
- package/dist/src/server/GGHttp.d.ts +2 -26
- package/dist/src/server/GGHttp.d.ts.map +1 -1
- package/dist/src/server/GGHttp.js +0 -15
- package/dist/src/server/GGHttp.js.map +1 -1
- package/dist/src/server/GGHttpSchema.startServer.d.ts +2 -11
- package/dist/src/server/GGHttpSchema.startServer.d.ts.map +1 -1
- package/dist/src/server/GGHttpSchema.startServer.js +11 -28
- package/dist/src/server/GGHttpSchema.startServer.js.map +1 -1
- package/dist/src/server/GGHttpServer.d.ts +16 -14
- package/dist/src/server/GGHttpServer.d.ts.map +1 -1
- package/dist/src/server/GGHttpServer.js +26 -79
- package/dist/src/server/GGHttpServer.js.map +1 -1
- package/dist/src/server/applyRequestMiddleware.d.ts +11 -0
- package/dist/src/server/applyRequestMiddleware.d.ts.map +1 -0
- package/dist/src/server/applyRequestMiddleware.js +38 -0
- package/dist/src/server/applyRequestMiddleware.js.map +1 -0
- package/dist/src/server/applyResponseMiddleware.d.ts +2 -2
- package/dist/src/server/applyResponseMiddleware.d.ts.map +1 -1
- package/dist/src/server/applyResponseMiddleware.js +2 -2
- package/dist/src/server/applyResponseMiddleware.js.map +1 -1
- package/dist/src/server/checkers/checkPermissionsAtStart.d.ts +39 -0
- package/dist/src/server/checkers/checkPermissionsAtStart.d.ts.map +1 -0
- package/dist/src/server/checkers/checkPermissionsAtStart.js +82 -0
- package/dist/src/server/checkers/checkPermissionsAtStart.js.map +1 -0
- package/dist/src/server/checkers/checkWireConflicts.d.ts +18 -0
- package/dist/src/server/checkers/checkWireConflicts.d.ts.map +1 -0
- package/dist/src/server/checkers/checkWireConflicts.js +43 -0
- package/dist/src/server/checkers/checkWireConflicts.js.map +1 -0
- package/dist/src/server/checkers/checkWiresImplemented.d.ts +11 -0
- package/dist/src/server/checkers/checkWiresImplemented.d.ts.map +1 -0
- package/dist/src/server/checkers/checkWiresImplemented.js +27 -0
- package/dist/src/server/checkers/checkWiresImplemented.js.map +1 -0
- package/dist/src/tsconfig.json +2 -1
- package/dist/tsconfig.publish.tsbuildinfo +1 -1
- package/package.json +14 -11
- package/src/_dedupCheck.ts +1 -1
- package/src/client/GGContextKeySynchronizer.test.ts +106 -0
- package/src/client/GGContextKeySynchronizer.ts +42 -0
- package/src/index-browser.ts +4 -2
- package/src/index-node.ts +17 -7
- package/src/rpc/RpcRequest/GGRpcRequestBuilder.ts +11 -4
- package/src/rpc/RpcRequest/GGRpcRequestParser.ts +16 -17
- package/src/rpc/RpcResponse/GGRpcResponseBuilder.ts +5 -4
- package/src/schema/GGCookie.ts +151 -0
- package/src/schema/GGHeader.ts +48 -0
- package/src/schema/GGHttpPermissionsChecker.test.ts +125 -0
- package/src/schema/GGHttpPermissionsChecker.ts +35 -0
- package/src/schema/GGHttpSchema.ts +8 -71
- package/src/schema/GGWireContextKey.node.ts +119 -0
- package/src/schema/GGWireContextKey.ts +46 -0
- package/src/schema/httpSchema.ts +3 -3
- package/src/server/GGHttp.ts +3 -34
- package/src/server/GGHttpSchema.startServer.ts +13 -38
- package/src/server/GGHttpServer.ts +33 -89
- package/src/server/applyRequestMiddleware.ts +40 -0
- package/src/server/applyResponseMiddleware.ts +5 -5
- package/src/server/checkers/checkPermissionsAtStart.ts +112 -0
- package/src/server/checkers/checkWireConflicts.ts +65 -0
- package/src/server/checkers/checkWiresImplemented.ts +42 -0
- package/src/tsconfig.json +2 -1
- package/dist/src/schema/cookieMiddleware.d.ts +0 -71
- package/dist/src/schema/cookieMiddleware.d.ts.map +0 -1
- package/dist/src/schema/cookieMiddleware.js +0 -126
- package/dist/src/schema/cookieMiddleware.js.map +0 -1
- package/dist/src/schema/headerBinding.d.ts +0 -35
- package/dist/src/schema/headerBinding.d.ts.map +0 -1
- package/dist/src/schema/headerBinding.js +0 -49
- package/dist/src/schema/headerBinding.js.map +0 -1
- package/dist/src/server/GG_PERMISSIONS.d.ts +0 -15
- package/dist/src/server/GG_PERMISSIONS.d.ts.map +0 -1
- package/dist/src/server/GG_PERMISSIONS.js +0 -15
- package/dist/src/server/GG_PERMISSIONS.js.map +0 -1
- package/src/schema/cookieMiddleware.ts +0 -164
- package/src/schema/headerBinding.ts +0 -65
- package/src/server/GG_PERMISSIONS.ts +0 -15
|
@@ -4,17 +4,17 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { GGLocator } from "@grest-ts/locator";
|
|
6
6
|
import { GGHttpSchema } from "../schema/GGHttpSchema.js";
|
|
7
|
-
import {
|
|
7
|
+
import { ERROR, SERVER_ERROR } from "@grest-ts/schema";
|
|
8
8
|
import { GG_DISCOVERY } from "@grest-ts/discovery";
|
|
9
9
|
import { GGContext, GGContextStore } from "@grest-ts/context";
|
|
10
10
|
import { GG_TRACE } from "@grest-ts/trace";
|
|
11
11
|
import { GG_HTTP_REQUEST } from "./GG_HTTP_REQUEST.js";
|
|
12
|
-
import { GG_COOKIE_WRITES } from "../schema/
|
|
12
|
+
import { GG_COOKIE_WRITES } from "../schema/GGCookie.js";
|
|
13
13
|
import { GG_METRICS } from "@grest-ts/metrics";
|
|
14
14
|
import { GGHttpMetrics } from "./GGHttpMetrics.js";
|
|
15
15
|
import { GG_HTTP_SERVER } from "./GG_HTTP_SERVER.js";
|
|
16
16
|
import { GGLog } from "@grest-ts/logger";
|
|
17
|
-
import {
|
|
17
|
+
import { GGHttpPermissionsChecker } from "../schema/GGHttpPermissionsChecker.js";
|
|
18
18
|
GGHttpSchema.prototype.register = function (implementation, config) {
|
|
19
19
|
return setupRoutes(this, implementation, config);
|
|
20
20
|
};
|
|
@@ -31,9 +31,10 @@ function setupRoutes(httpSchema, implementation, config) {
|
|
|
31
31
|
const apiMiddlewares = httpSchema.apiMiddlewares;
|
|
32
32
|
const scope = GGLocator.getScope();
|
|
33
33
|
const parentContext = GGContextStore.tryGetContext();
|
|
34
|
+
const permissionsChecker = new GGHttpPermissionsChecker(apiMiddlewares);
|
|
34
35
|
for (const mw of apiMiddlewares) {
|
|
35
|
-
const hKeys = Object.keys(mw.headers);
|
|
36
|
-
const rhKeys = Object.keys(mw.responseHeaders);
|
|
36
|
+
const hKeys = Object.keys(mw.headers ?? {});
|
|
37
|
+
const rhKeys = Object.keys(mw.responseHeaders ?? {});
|
|
37
38
|
if (hKeys.length)
|
|
38
39
|
server.registerCorsHeaders(hKeys);
|
|
39
40
|
if (rhKeys.length)
|
|
@@ -57,8 +58,6 @@ function setupRoutes(httpSchema, implementation, config) {
|
|
|
57
58
|
// Info: Contract instance is auto-registered in GGLocator via patched implement()
|
|
58
59
|
// @TODO This is not really used and only for testkit so it would register implementation of the contract... Not cool
|
|
59
60
|
httpSchema.contract.implement(implementation);
|
|
60
|
-
if (config.permissionResolver)
|
|
61
|
-
server._markResolverWired(httpSchema);
|
|
62
61
|
for (const methodName in httpSchema.codec) {
|
|
63
62
|
// Wire format.
|
|
64
63
|
const codec = httpSchema.codec[methodName];
|
|
@@ -75,8 +74,7 @@ function setupRoutes(httpSchema, implementation, config) {
|
|
|
75
74
|
// build request mapping
|
|
76
75
|
const requestParser = codec.createForServer({
|
|
77
76
|
contract: contractFunctionSchema,
|
|
78
|
-
|
|
79
|
-
serverMiddlewares: config.middlewares
|
|
77
|
+
middlewares: [...apiMiddlewares, ...(config.middlewares ?? [])]
|
|
80
78
|
});
|
|
81
79
|
const cookieWriteNames = new Set((codec.updatesCookies ?? []).map(k => k.name));
|
|
82
80
|
server.registerRoute(codec.method, pathPrefix + codec.path, async (req, res) => {
|
|
@@ -88,25 +86,10 @@ function setupRoutes(httpSchema, implementation, config) {
|
|
|
88
86
|
const startTime = performance.now();
|
|
89
87
|
let rpcResult;
|
|
90
88
|
try {
|
|
91
|
-
const
|
|
89
|
+
const rawInput = await requestParser.readRequest(req);
|
|
90
|
+
await permissionsChecker.assert(httpSchema.name, methodName, contractFunctionSchema.permission);
|
|
92
91
|
try {
|
|
93
|
-
|
|
94
|
-
const scopes = await config.permissionResolver();
|
|
95
|
-
if (scopes != null)
|
|
96
|
-
GG_PERMISSIONS.set(new GGPermissionChecker(scopes));
|
|
97
|
-
const required = contractFunctionSchema.permission;
|
|
98
|
-
if (required !== undefined && required !== GG_NO_PERMISSIONS) {
|
|
99
|
-
if (scopes == null)
|
|
100
|
-
throw new NOT_AUTHORIZED({
|
|
101
|
-
debugMessage: `${httpSchema.name}.${methodName} requires ${describePermission(required)} but no caller identity was resolved`
|
|
102
|
-
});
|
|
103
|
-
if (!satisfies(required, scopes))
|
|
104
|
-
throw new FORBIDDEN({
|
|
105
|
-
debugMessage: `${httpSchema.name}.${methodName} requires ${describePermission(required)} — caller scopes did not satisfy`
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
rpcResult = { success: true, type: "OK", data: await implFn(rpcInput) };
|
|
92
|
+
rpcResult = { success: true, type: "OK", data: await implFn(requestParser.validateInput(rawInput)) };
|
|
110
93
|
// GGLog.debug(httpSchema, "Response", rpcResult) // This is very slow to log this (like 3x performance loss)
|
|
111
94
|
}
|
|
112
95
|
catch (error) {
|
|
@@ -126,7 +109,7 @@ function setupRoutes(httpSchema, implementation, config) {
|
|
|
126
109
|
metrics(rpcResult?.type, httpSchema.name, codec.method, pathPrefix, codec.path, startTime);
|
|
127
110
|
}
|
|
128
111
|
});
|
|
129
|
-
});
|
|
112
|
+
}, `${httpSchema.name}.${methodName}`);
|
|
130
113
|
}
|
|
131
114
|
}
|
|
132
115
|
function metrics(resultType, apiName, method, pathPrefix, pathSuffix, startTime) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GGHttpSchema.startServer.js","sourceRoot":"","sources":["../../../src/server/GGHttpSchema.startServer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAC,SAAS,EAAC,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAwD,YAAY,EAAC,MAAM,wBAAwB,CAAC;AAC3G,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"GGHttpSchema.startServer.js","sourceRoot":"","sources":["../../../src/server/GGHttpSchema.startServer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAC,SAAS,EAAC,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAwD,YAAY,EAAC,MAAM,wBAAwB,CAAC;AAC3G,OAAO,EAAC,KAAK,EAA2E,YAAY,EAAC,MAAM,kBAAkB,CAAC;AAE9H,OAAO,EAAC,YAAY,EAAC,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAC,SAAS,EAAE,cAAc,EAA6B,MAAM,mBAAmB,CAAC;AACxF,OAAO,EAAC,QAAQ,EAAC,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAC,eAAe,EAAC,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAC,gBAAgB,EAAC,MAAM,oBAAoB,CAAC;A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U,EAAE,SAAS,CAAC,CAAA;gBACtC,CAAC;wBAAS,CAAC;oBACP,OAAO,CAAC,SAAS,EAAE,IAAI,EAAE,UAAU,CAAC,IAAI,EAAE,KAAK,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,CAAC,IAAI,EAAE,SAAS,CAAC,CAAA;gBAC9F,CAAC;YACL,CAAC,CAAC,CAAC;QACP,CAAC,EAAE,GAAG,UAAU,CAAC,IAAI,IAAI,UAAU,EAAE,CAAC,CAAA;IAC1C,CAAC;AACL,CAAC;AAED,SAAS,OAAO,CACZ,UAAkB,EAClB,OAAe,EACf,MAAkB,EAClB,UAAkB,EAClB,UAAkB,EAClB,SAAiB;IAEjB,IAAI,UAAU,CAAC,GAAG,EAAE,EAAE,CAAC;QACnB,MAAM,IAAI,GAAG,MAAM,GAAG,GAAG,GAAG,UAAU,GAAG,UAAU,CAAC;QACpD,aAAa,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,EAAE;YAC1B,GAAG,EAAE,OAAO;YACZ,MAAM,EAAE,UAAU;YAClB,IAAI,EAAE,IAAI;YACV,MAAM,EAAE,UAAU;SACrB,CAAC,CAAC;QACH,aAAa,CAAC,eAAe,CAAC,OAAO,CAAC,WAAW,CAAC,GAAG,EAAE,GAAG,SAAS,EAAE;YACjE,GAAG,EAAE,OAAO;YACZ,MAAM,EAAE,UAAU;YAClB,IAAI,EAAE,IAAI;SACb,CAAC,CAAC;IACP,CAAC;AACL,CAAC"}
|
|
@@ -2,7 +2,9 @@ import http from "http";
|
|
|
2
2
|
import { HttpMethod } from "@grest-ts/common";
|
|
3
3
|
import { GGLocatorKey, GGLocatorScope } from "@grest-ts/locator";
|
|
4
4
|
import type { GGHttpSchema } from "../schema/GGHttpSchema";
|
|
5
|
+
import "../schema/GGWireContextKey.node";
|
|
5
6
|
import { GGContractMethod, GGPermission } from "@grest-ts/schema";
|
|
7
|
+
import type { GGTransportMiddleware } from "@grest-ts/context";
|
|
6
8
|
type AnyWebSocketSchema = {
|
|
7
9
|
name: string;
|
|
8
10
|
path: string;
|
|
@@ -10,8 +12,11 @@ type AnyWebSocketSchema = {
|
|
|
10
12
|
clientToServer: {
|
|
11
13
|
methods: Record<string, GGContractMethod>;
|
|
12
14
|
};
|
|
15
|
+
serverToClient: {
|
|
16
|
+
methods: Record<string, GGContractMethod>;
|
|
17
|
+
};
|
|
13
18
|
};
|
|
14
|
-
middlewares: readonly
|
|
19
|
+
middlewares: readonly GGTransportMiddleware[];
|
|
15
20
|
connectPermission?: GGPermission;
|
|
16
21
|
};
|
|
17
22
|
export interface GGCorsConfig {
|
|
@@ -65,12 +70,9 @@ export declare class GGHttpServer {
|
|
|
65
70
|
* Framework-internal — only setupRoutes() (in GGHttpSchema.startServer.ts) should push here.
|
|
66
71
|
*/
|
|
67
72
|
private readonly _registeredSchemas;
|
|
68
|
-
|
|
69
|
-
* All GGHttpSchema instances registered on this server, in registration order.
|
|
70
|
-
* Available from the moment compose() begins; frozen (no further push allowed) once start() is called.
|
|
71
|
-
*/
|
|
72
|
-
get registeredSchemas(): ReadonlyArray<GGHttpSchema<any, any>>;
|
|
73
|
+
private readonly _registeredWebSocketSchemas;
|
|
73
74
|
readonly httpServer: http.Server;
|
|
75
|
+
private readonly _routeOwners;
|
|
74
76
|
private activeRequests;
|
|
75
77
|
private router;
|
|
76
78
|
private static readonly DEFAULT_CORS_HEADERS;
|
|
@@ -96,19 +98,19 @@ export declare class GGHttpServer {
|
|
|
96
98
|
get port(): number | undefined;
|
|
97
99
|
/** @internal Called by setupRoutes() during compose(). Do not call directly. */
|
|
98
100
|
_registerSchema(schema: GGHttpSchema<any, any>): void;
|
|
99
|
-
|
|
101
|
+
/**
|
|
102
|
+
* All GGHttpSchema instances registered on this server, in registration order.
|
|
103
|
+
* Available from the moment compose() begins; frozen (no further push allowed) once start() is called.
|
|
104
|
+
*/
|
|
105
|
+
get registeredSchemas(): ReadonlyArray<GGHttpSchema<any, any>>;
|
|
106
|
+
/** @internal Called by GGWebSocketSchema.startServer(). Do not call directly. */
|
|
107
|
+
_registerWebSocketSchema(schema: AnyWebSocketSchema): void;
|
|
100
108
|
/**
|
|
101
109
|
* All GGWebSocketSchema instances registered on this server, in registration order.
|
|
102
110
|
* Populated automatically by GGWebSocketSchema.startServer() / .register().
|
|
103
111
|
*/
|
|
104
112
|
get registeredWebSocketSchemas(): ReadonlyArray<AnyWebSocketSchema>;
|
|
105
|
-
|
|
106
|
-
_registerWebSocketSchema(schema: AnyWebSocketSchema): void;
|
|
107
|
-
private readonly _schemasWithResolver;
|
|
108
|
-
/** @internal Called by HTTP / WS register paths when a scope resolver is wired. */
|
|
109
|
-
_markResolverWired(schema: object): void;
|
|
110
|
-
private _checkPermissionsAtStart;
|
|
111
|
-
registerRoute(method: HttpMethod, path: string, handler: GGHttpRequestCallback): void;
|
|
113
|
+
registerRoute(method: HttpMethod, path: string, handler: GGHttpRequestCallback, owner?: string): void;
|
|
112
114
|
start(): Promise<void>;
|
|
113
115
|
teardown(): Promise<void>;
|
|
114
116
|
onStart(callback: () => Promise<void> | void): this;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GGHttpServer.d.ts","sourceRoot":"","sources":["../../../src/server/GGHttpServer.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAC,UAAU,EAAiB,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAY,YAAY,EAAE,cAAc,EAAuB,MAAM,mBAAmB,CAAC;AAIhG,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"GGHttpServer.d.ts","sourceRoot":"","sources":["../../../src/server/GGHttpServer.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAC,UAAU,EAAiB,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAY,YAAY,EAAE,cAAc,EAAuB,MAAM,mBAAmB,CAAC;AAIh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;IAED,iFAAiF;IAC1E,wBAAwB,CAAC,MAAM,EAAE,kBAAkB,GAAG,IAAI;IAIjE;;;OAGG;IACH,IAAI,0BAA0B,IAAI,aAAa,CAAC,kBAAkB,CAAC,CAElE;IAEM,aAAa,CAAC,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,qBAAqB,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI;IAa/F,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAkBtB,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAgB/B,OAAO,CAAC,QAAQ,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,IAAI;IAKnD,UAAU,CAAC,QAAQ,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,IAAI;CAIhE;AAED,MAAM,MAAM,qBAAqB,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,eAAe,EAAE,GAAG,EAAE,IAAI,CAAC,cAAc,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAE3G;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAC/B,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,IAAI,EAAE,YAAY,GAAG,SAAS,EAC9B,YAAY,EAAE,MAAM,EACpB,aAAa,EAAE,MAAM,GACtB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAkBxB"}
|
|
@@ -5,7 +5,10 @@ import { GGLocator, GGLocatorServiceType } from "@grest-ts/locator";
|
|
|
5
5
|
import { GG_HTTP_SERVER } from "./GG_HTTP_SERVER.js";
|
|
6
6
|
import { GGLog } from "@grest-ts/logger";
|
|
7
7
|
import findMyWay from "find-my-way";
|
|
8
|
-
import {
|
|
8
|
+
import { checkWiresImplemented } from "./checkers/checkWiresImplemented.js";
|
|
9
|
+
import { checkPermissionsAtStart } from "./checkers/checkPermissionsAtStart.js";
|
|
10
|
+
import { checkWireConflicts } from "./checkers/checkWireConflicts.js";
|
|
11
|
+
import "../schema/GGWireContextKey.node.js";
|
|
9
12
|
export class GGHttpServer {
|
|
10
13
|
_port;
|
|
11
14
|
teardownPromise;
|
|
@@ -20,14 +23,9 @@ export class GGHttpServer {
|
|
|
20
23
|
* Framework-internal — only setupRoutes() (in GGHttpSchema.startServer.ts) should push here.
|
|
21
24
|
*/
|
|
22
25
|
_registeredSchemas = [];
|
|
23
|
-
|
|
24
|
-
* All GGHttpSchema instances registered on this server, in registration order.
|
|
25
|
-
* Available from the moment compose() begins; frozen (no further push allowed) once start() is called.
|
|
26
|
-
*/
|
|
27
|
-
get registeredSchemas() {
|
|
28
|
-
return this._registeredSchemas;
|
|
29
|
-
}
|
|
26
|
+
_registeredWebSocketSchemas = [];
|
|
30
27
|
httpServer;
|
|
28
|
+
_routeOwners = new Map();
|
|
31
29
|
activeRequests = 0;
|
|
32
30
|
router = findMyWay();
|
|
33
31
|
static DEFAULT_CORS_HEADERS = ['Content-Type'];
|
|
@@ -130,90 +128,39 @@ export class GGHttpServer {
|
|
|
130
128
|
_registerSchema(schema) {
|
|
131
129
|
this._registeredSchemas.push(schema);
|
|
132
130
|
}
|
|
133
|
-
_registeredWebSocketSchemas = [];
|
|
134
131
|
/**
|
|
135
|
-
* All
|
|
136
|
-
*
|
|
132
|
+
* All GGHttpSchema instances registered on this server, in registration order.
|
|
133
|
+
* Available from the moment compose() begins; frozen (no further push allowed) once start() is called.
|
|
137
134
|
*/
|
|
138
|
-
get
|
|
139
|
-
return this.
|
|
135
|
+
get registeredSchemas() {
|
|
136
|
+
return this._registeredSchemas;
|
|
140
137
|
}
|
|
141
138
|
/** @internal Called by GGWebSocketSchema.startServer(). Do not call directly. */
|
|
142
139
|
_registerWebSocketSchema(schema) {
|
|
143
140
|
this._registeredWebSocketSchemas.push(schema);
|
|
144
141
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
142
|
+
/**
|
|
143
|
+
* All GGWebSocketSchema instances registered on this server, in registration order.
|
|
144
|
+
* Populated automatically by GGWebSocketSchema.startServer() / .register().
|
|
145
|
+
*/
|
|
146
|
+
get registeredWebSocketSchemas() {
|
|
147
|
+
return this._registeredWebSocketSchemas;
|
|
149
148
|
}
|
|
150
|
-
|
|
151
|
-
const
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
surfaces.push({
|
|
157
|
-
label: `${schema.name}.${name}`,
|
|
158
|
-
permission: methods[name].permission,
|
|
159
|
-
resolverWired,
|
|
160
|
-
});
|
|
161
|
-
}
|
|
149
|
+
registerRoute(method, path, handler, owner) {
|
|
150
|
+
const route = `${method} ${path}`;
|
|
151
|
+
const existing = this._routeOwners.get(route);
|
|
152
|
+
if (existing !== undefined) {
|
|
153
|
+
throw new Error(`GGHttpServer: route ${route} is declared by both ${existing} and ${owner ?? "another route"}. ` +
|
|
154
|
+
`Give each route a distinct path (change a pathPrefix or route path).`);
|
|
162
155
|
}
|
|
163
|
-
|
|
164
|
-
const resolverWired = this._schemasWithResolver.has(ws);
|
|
165
|
-
const methods = ws.contract.clientToServer.methods;
|
|
166
|
-
for (const name of Object.keys(methods)) {
|
|
167
|
-
surfaces.push({
|
|
168
|
-
label: `${ws.name}.${name}`,
|
|
169
|
-
permission: methods[name].permission,
|
|
170
|
-
resolverWired,
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
if (ws.connectPermission !== undefined) {
|
|
174
|
-
surfaces.push({
|
|
175
|
-
label: `${ws.name} (connectPermission)`,
|
|
176
|
-
permission: ws.connectPermission,
|
|
177
|
-
resolverWired,
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
let strict = false;
|
|
182
|
-
const undeclared = [];
|
|
183
|
-
const orphaned = [];
|
|
184
|
-
for (const s of surfaces) {
|
|
185
|
-
if (s.permission !== undefined || s.resolverWired)
|
|
186
|
-
strict = true;
|
|
187
|
-
if (s.permission === undefined)
|
|
188
|
-
undeclared.push(s);
|
|
189
|
-
else if (s.permission !== GG_NO_PERMISSIONS && !s.resolverWired)
|
|
190
|
-
orphaned.push(s);
|
|
191
|
-
}
|
|
192
|
-
if (!strict)
|
|
193
|
-
return;
|
|
194
|
-
if (undeclared.length > 0) {
|
|
195
|
-
const lines = undeclared.map(s => ` ${s.label}`).join("\n");
|
|
196
|
-
throw new Error(`GGHttpServer: permission strict mode is active on this server ` +
|
|
197
|
-
`(at least one route declares a permission or has .usePermissions(...) wired), ` +
|
|
198
|
-
`but the following routes have no \`permission\` declared:\n\n` +
|
|
199
|
-
lines +
|
|
200
|
-
`\n\nFix: declare \`permission\` on every route — use \`GG_NO_PERMISSIONS\` for intentionally public ones.`);
|
|
201
|
-
}
|
|
202
|
-
if (orphaned.length > 0) {
|
|
203
|
-
const lines = orphaned.map(s => ` ${s.label} requires ${describePermission(s.permission)}`).join("\n");
|
|
204
|
-
throw new Error(`GGHttpServer: these routes declare non-public permissions but their schema was ` +
|
|
205
|
-
`registered without a scope resolver:\n\n` +
|
|
206
|
-
lines +
|
|
207
|
-
`\n\nFix: call \`.usePermissions(yourResolver)\` on the GGHttp chain (or pass ` +
|
|
208
|
-
`\`permissionResolver\` to the WS schema config) before registering these routes.`);
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
registerRoute(method, path, handler) {
|
|
156
|
+
this._routeOwners.set(route, owner ?? path);
|
|
212
157
|
this.router.on(method, path, handler);
|
|
213
158
|
}
|
|
214
159
|
async start() {
|
|
215
160
|
Object.freeze(this._registeredSchemas);
|
|
216
|
-
this.
|
|
161
|
+
checkWireConflicts(this.registeredSchemas, this.registeredWebSocketSchemas);
|
|
162
|
+
checkWiresImplemented(this.registeredSchemas, this.registeredWebSocketSchemas);
|
|
163
|
+
checkPermissionsAtStart(this.registeredSchemas, this.registeredWebSocketSchemas);
|
|
217
164
|
this._port = await new Promise((resolve) => {
|
|
218
165
|
this.httpServer.listen(this.configuredPort, '0.0.0.0', () => {
|
|
219
166
|
const port = this.httpServer.address().port;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GGHttpServer.js","sourceRoot":"","sources":["../../../src/server/GGHttpServer.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAa,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAC,SAAS,EAAgC,oBAAoB,EAAC,MAAM,mBAAmB,CAAC;AAChG,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAC,KAAK,EAAC,MAAM,kBAAkB,CAAC;AACvC,OAAO,SAAuB,MAAM,aAAa,CAAC;AAElD,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"GGHttpServer.js","sourceRoot":"","sources":["../../../src/server/GGHttpServer.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAa,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAC,SAAS,EAAgC,oBAAoB,EAAC,MAAM,mBAAmB,CAAC;AAChG,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAC,KAAK,EAAC,MAAM,kBAAkB,CAAC;AACvC,OAAO,SAAuB,MAAM,aAAa,CAAC;AAElD,OAAO,EAAC,qBAAqB,EAAC,MAAM,kCAAkC,CAAC;AACvE,OAAO,EAAC,uBAAuB,EAAC,MAAM,oCAAoC,CAAC;AAC3E,OAAO,EAAC,kBAAkB,EAAC,MAAM,+BAA+B,CAAC;AACjE,OAAO,iCAAiC,CAAC;AAuDzC,MAAM,OAAO,YAAY;IAEX,KAAK,CAAqB;IAC1B,eAAe,CAA4B;IAClC,KAAK,CAAiB;IACtB,WAAW,CAAS;IACtB,cAAc,CAAS;IACvB,IAAI,CAAgB;IAEpB,QAAQ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AC,GAAG,QAAQ,CAAC;QAC3B,IAAI,CAAC,OAAO;YAAE,OAAO,OAAO,CAAC;QAC7B,OAAO,CAAC,6BAA6B,CAAC,GAAG,MAAM,CAAC;QAChD,IAAI,IAAI,CAAC,WAAW;YAAE,OAAO,CAAC,kCAAkC,CAAC,GAAG,MAAM,CAAC;IAC/E,CAAC;SAAM,CAAC;QACJ,OAAO,CAAC,6BAA6B,CAAC,GAAG,GAAG,CAAC;IACjD,CAAC;IACD,OAAO,CAAC,8BAA8B,CAAC,GAAG,wCAAwC,CAAC;IACnF,OAAO,CAAC,8BAA8B,CAAC,GAAG,YAAY,CAAC;IACvD,IAAI,aAAa;QAAE,OAAO,CAAC,+BAA+B,CAAC,GAAG,aAAa,CAAC;IAC5E,OAAO,OAAO,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type http from "http";
|
|
2
|
+
import type { GGTransportMiddleware } from "@grest-ts/context";
|
|
3
|
+
/**
|
|
4
|
+
* Normalizes a Node request + parsed query into a GGInbound and runs the server-side
|
|
5
|
+
* pipeline: every parse() (populating context keys) before any process() (async
|
|
6
|
+
* validation), so a middleware can validate against a key an earlier one parsed.
|
|
7
|
+
* The cookie is taken only from the real request header — never from anywhere a
|
|
8
|
+
* client could forge — preserving the anti-spoof guarantee on every transport.
|
|
9
|
+
*/
|
|
10
|
+
export declare function applyRequestMiddleware(req: http.IncomingMessage, queryArgs: Record<string, string | string[]>, middlewares: readonly GGTransportMiddleware[]): Promise<void>;
|
|
11
|
+
//# sourceMappingURL=applyRequestMiddleware.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"applyRequestMiddleware.d.ts","sourceRoot":"","sources":["../../../src/server/applyRequestMiddleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,KAAK,EAAY,qBAAqB,EAAC,MAAM,mBAAmB,CAAC;AAExE;;;;;;GAMG;AACH,wBAAsB,sBAAsB,CACxC,GAAG,EAAE,IAAI,CAAC,eAAe,EACzB,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,EAC5C,WAAW,EAAE,SAAS,qBAAqB,EAAE,GAC9C,OAAO,CAAC,IAAI,CAAC,CAgBf"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Normalizes a Node request + parsed query into a GGInbound and runs the server-side
|
|
3
|
+
* pipeline: every parse() (populating context keys) before any process() (async
|
|
4
|
+
* validation), so a middleware can validate against a key an earlier one parsed.
|
|
5
|
+
* The cookie is taken only from the real request header — never from anywhere a
|
|
6
|
+
* client could forge — preserving the anti-spoof guarantee on every transport.
|
|
7
|
+
*/
|
|
8
|
+
export async function applyRequestMiddleware(req, queryArgs, middlewares) {
|
|
9
|
+
if (middlewares.length === 0)
|
|
10
|
+
return;
|
|
11
|
+
const inbound = {
|
|
12
|
+
headers: flatten(req.headers),
|
|
13
|
+
cookie: typeof req.headers.cookie === "string" ? req.headers.cookie : undefined,
|
|
14
|
+
query: flatten(queryArgs)
|
|
15
|
+
};
|
|
16
|
+
for (const mw of middlewares)
|
|
17
|
+
mw.parse?.(inbound);
|
|
18
|
+
// finally: a rejecting process() (e.g. anonymous → NOT_AUTHORIZED) must still drop every
|
|
19
|
+
// ephemeral credential — including those an earlier wire already parsed — so no raw token
|
|
20
|
+
// outlives the failed request in context.
|
|
21
|
+
try {
|
|
22
|
+
for (const mw of middlewares)
|
|
23
|
+
await mw.process?.();
|
|
24
|
+
}
|
|
25
|
+
finally {
|
|
26
|
+
for (const mw of middlewares)
|
|
27
|
+
mw.clear?.();
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function flatten(src) {
|
|
31
|
+
const out = {};
|
|
32
|
+
for (const key in src) {
|
|
33
|
+
const value = src[key];
|
|
34
|
+
out[key] = Array.isArray(value) ? value[0] : value;
|
|
35
|
+
}
|
|
36
|
+
return out;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=applyRequestMiddleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"applyRequestMiddleware.js","sourceRoot":"","sources":["../../../src/server/applyRequestMiddleware.ts"],"names":[],"mappings":"AAGA;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CACxC,GAAyB,EACzB,SAA4C,EAC5C,WAA6C;IAE7C,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO;IACrC,MAAM,OAAO,GAAc;QACvB,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC;QAC7B,MAAM,EAAE,OAAO,GAAG,CAAC,OAAO,CAAC,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS;QAC/E,KAAK,EAAE,OAAO,CAAC,SAAS,CAAC;KAC5B,CAAC;IACF,KAAK,MAAM,EAAE,IAAI,WAAW;QAAE,EAAE,CAAC,KAAK,EAAE,CAAC,OAAO,CAAC,CAAC;IAClD,yFAAyF;IACzF,0FAA0F;IAC1F,0CAA0C;IAC1C,IAAI,CAAC;QACD,KAAK,MAAM,EAAE,IAAI,WAAW;YAAE,MAAM,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC;IACvD,CAAC;YAAS,CAAC;QACP,KAAK,MAAM,EAAE,IAAI,WAAW;YAAE,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC;IAC/C,CAAC;AACL,CAAC;AAED,SAAS,OAAO,CAAC,GAAkD;IAC/D,MAAM,GAAG,GAAuC,EAAE,CAAC;IACnD,KAAK,MAAM,GAAG,IAAI,GAAG,EAAE,CAAC;QACpB,MAAM,KAAK,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;QACvB,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IACvD,CAAC;IACD,OAAO,GAAG,CAAC;AACf,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type http from "http";
|
|
2
|
-
import type {
|
|
2
|
+
import type { GGTransportMiddleware } from "@grest-ts/context";
|
|
3
3
|
/**
|
|
4
4
|
* Runs the transport chain's server-side response hook and writes the collected
|
|
5
5
|
* headers onto the Node response. Applied via setHeader (not writeHead) so a
|
|
@@ -8,5 +8,5 @@ import type { GGHttpTransportMiddleware } from "../schema/GGHttpSchema";
|
|
|
8
8
|
* merges rather than clobbers. Must run inside the request GGContext so a
|
|
9
9
|
* middleware can read per-request staged state.
|
|
10
10
|
*/
|
|
11
|
-
export declare function applyResponseMiddleware(res: http.ServerResponse, middlewares: readonly
|
|
11
|
+
export declare function applyResponseMiddleware(res: http.ServerResponse, middlewares: readonly GGTransportMiddleware[] | undefined): void;
|
|
12
12
|
//# sourceMappingURL=applyResponseMiddleware.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"applyResponseMiddleware.d.ts","sourceRoot":"","sources":["../../../src/server/applyResponseMiddleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"applyResponseMiddleware.d.ts","sourceRoot":"","sources":["../../../src/server/applyResponseMiddleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,KAAK,EAAa,qBAAqB,EAAC,MAAM,mBAAmB,CAAC;AAEzE;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CACnC,GAAG,EAAE,IAAI,CAAC,cAAc,EACxB,WAAW,EAAE,SAAS,qBAAqB,EAAE,GAAG,SAAS,GAC1D,IAAI,CAYN"}
|
|
@@ -11,10 +11,10 @@ export function applyResponseMiddleware(res, middlewares) {
|
|
|
11
11
|
return;
|
|
12
12
|
let response;
|
|
13
13
|
for (const mw of middlewares) {
|
|
14
|
-
if (!mw.
|
|
14
|
+
if (!mw.respond)
|
|
15
15
|
continue;
|
|
16
16
|
response ??= { headers: {} };
|
|
17
|
-
mw.
|
|
17
|
+
mw.respond(response);
|
|
18
18
|
}
|
|
19
19
|
if (!response)
|
|
20
20
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"applyResponseMiddleware.js","sourceRoot":"","sources":["../../../src/server/applyResponseMiddleware.ts"],"names":[],"mappings":"AAGA;;;;;;;GAOG;AACH,MAAM,UAAU,uBAAuB,CACnC,GAAwB,EACxB,
|
|
1
|
+
{"version":3,"file":"applyResponseMiddleware.js","sourceRoot":"","sources":["../../../src/server/applyResponseMiddleware.ts"],"names":[],"mappings":"AAGA;;;;;;;GAOG;AACH,MAAM,UAAU,uBAAuB,CACnC,GAAwB,EACxB,WAAyD;IAEzD,IAAI,CAAC,WAAW,EAAE,MAAM,IAAI,GAAG,CAAC,WAAW;QAAE,OAAO;IACpD,IAAI,QAAgC,CAAC;IACrC,KAAK,MAAM,EAAE,IAAI,WAAW,EAAE,CAAC;QAC3B,IAAI,CAAC,EAAE,CAAC,OAAO;YAAE,SAAS;QAC1B,QAAQ,KAAK,EAAC,OAAO,EAAE,EAAE,EAAC,CAAC;QAC3B,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IACzB,CAAC;IACD,IAAI,CAAC,QAAQ;QAAE,OAAO;IACtB,KAAK,MAAM,IAAI,IAAI,QAAQ,CAAC,OAAO,EAAE,CAAC;QAClC,GAAG,CAAC,SAAS,CAAC,IAAI,EAAE,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;IAChD,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Run at GGHttpServer.start() over the frozen schema graph. Three permission-coherence checks:
|
|
3
|
+
*
|
|
4
|
+
* - strict-mode coverage: once any route declares a permission, every route on the server must
|
|
5
|
+
* declare one (use GG_NO_PERMISSIONS for intentionally public routes).
|
|
6
|
+
* - unsatisfiable route: a route requiring a non-public permission on a schema with no
|
|
7
|
+
* permission-resolving wire (a .define()d wire whose handler exposes permissions()) can never
|
|
8
|
+
* pass the gate — its pooled grants are always empty, so it is permanently FORBIDDEN.
|
|
9
|
+
* - dead serverToClient permission: the gate has no caller identity for server-pushed messages,
|
|
10
|
+
* so a non-public permission on a WS serverToClient method is silently ignored.
|
|
11
|
+
*
|
|
12
|
+
* Scopes come only from the schema's wires; there is no resolver wiring.
|
|
13
|
+
*/
|
|
14
|
+
import { GGContractMethod, GGPermission } from "@grest-ts/schema";
|
|
15
|
+
import type { GGTransportMiddleware } from "@grest-ts/context";
|
|
16
|
+
import "../../schema/GGWireContextKey.node";
|
|
17
|
+
interface HttpSchemaLike {
|
|
18
|
+
name: string;
|
|
19
|
+
apiMiddlewares: readonly GGTransportMiddleware[];
|
|
20
|
+
contract?: {
|
|
21
|
+
methods: Record<string, GGContractMethod>;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
interface WebSocketSchemaLike {
|
|
25
|
+
name: string;
|
|
26
|
+
middlewares: readonly GGTransportMiddleware[];
|
|
27
|
+
contract: {
|
|
28
|
+
clientToServer: {
|
|
29
|
+
methods: Record<string, GGContractMethod>;
|
|
30
|
+
};
|
|
31
|
+
serverToClient: {
|
|
32
|
+
methods: Record<string, GGContractMethod>;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
connectPermission?: GGPermission;
|
|
36
|
+
}
|
|
37
|
+
export declare function checkPermissionsAtStart(httpSchemas: readonly HttpSchemaLike[], webSocketSchemas: readonly WebSocketSchemaLike[]): void;
|
|
38
|
+
export {};
|
|
39
|
+
//# sourceMappingURL=checkPermissionsAtStart.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkPermissionsAtStart.d.ts","sourceRoot":"","sources":["../../../../src/server/checkers/checkPermissionsAtStart.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAoB,gBAAgB,EAAE,YAAY,EAAC,MAAM,kBAAkB,CAAA;AAClF,OAAO,KAAK,EAAC,qBAAqB,EAAC,MAAM,mBAAmB,CAAA;AAE5D,OAAO,oCAAoC,CAAA;AAE3C,UAAU,cAAc;IACpB,IAAI,EAAE,MAAM,CAAA;IACZ,cAAc,EAAE,SAAS,qBAAqB,EAAE,CAAA;IAChD,QAAQ,CAAC,EAAE;QAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAA;KAAC,CAAA;CACzD;AAED,UAAU,mBAAmB;IACzB,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,SAAS,qBAAqB,EAAE,CAAA;IAC7C,QAAQ,EAAE;QACN,cAAc,EAAE;YAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAA;SAAC,CAAA;QAC3D,cAAc,EAAE;YAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAA;SAAC,CAAA;KAC9D,CAAA;IACD,iBAAiB,CAAC,EAAE,YAAY,CAAA;CACnC;AAUD,wBAAgB,uBAAuB,CACnC,WAAW,EAAE,SAAS,cAAc,EAAE,EACtC,gBAAgB,EAAE,SAAS,mBAAmB,EAAE,GACjD,IAAI,CAkEN"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Run at GGHttpServer.start() over the frozen schema graph. Three permission-coherence checks:
|
|
3
|
+
*
|
|
4
|
+
* - strict-mode coverage: once any route declares a permission, every route on the server must
|
|
5
|
+
* declare one (use GG_NO_PERMISSIONS for intentionally public routes).
|
|
6
|
+
* - unsatisfiable route: a route requiring a non-public permission on a schema with no
|
|
7
|
+
* permission-resolving wire (a .define()d wire whose handler exposes permissions()) can never
|
|
8
|
+
* pass the gate — its pooled grants are always empty, so it is permanently FORBIDDEN.
|
|
9
|
+
* - dead serverToClient permission: the gate has no caller identity for server-pushed messages,
|
|
10
|
+
* so a non-public permission on a WS serverToClient method is silently ignored.
|
|
11
|
+
*
|
|
12
|
+
* Scopes come only from the schema's wires; there is no resolver wiring.
|
|
13
|
+
*/
|
|
14
|
+
import { GG_NO_PERMISSIONS } from "@grest-ts/schema";
|
|
15
|
+
import { GGWireContextKey } from "../../schema/GGWireContextKey.js";
|
|
16
|
+
import "../../schema/GGWireContextKey.node.js";
|
|
17
|
+
function isNonPublic(permission) {
|
|
18
|
+
return permission !== undefined && permission !== GG_NO_PERMISSIONS;
|
|
19
|
+
}
|
|
20
|
+
function hasPermissionWire(wires) {
|
|
21
|
+
return wires.some(mw => mw instanceof GGWireContextKey && mw.hasPermissions());
|
|
22
|
+
}
|
|
23
|
+
export function checkPermissionsAtStart(httpSchemas, webSocketSchemas) {
|
|
24
|
+
const surfaces = [];
|
|
25
|
+
const deadServerToClient = [];
|
|
26
|
+
for (const schema of httpSchemas) {
|
|
27
|
+
const hasWire = hasPermissionWire(schema.apiMiddlewares);
|
|
28
|
+
const methods = schema.contract?.methods ?? {};
|
|
29
|
+
for (const name of Object.keys(methods)) {
|
|
30
|
+
surfaces.push({ label: `${schema.name}.${name}`, permission: methods[name].permission, hasWire });
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
for (const ws of webSocketSchemas) {
|
|
34
|
+
const hasWire = hasPermissionWire(ws.middlewares);
|
|
35
|
+
const methods = ws.contract.clientToServer.methods;
|
|
36
|
+
for (const name of Object.keys(methods)) {
|
|
37
|
+
surfaces.push({ label: `${ws.name}.${name}`, permission: methods[name].permission, hasWire });
|
|
38
|
+
}
|
|
39
|
+
if (ws.connectPermission !== undefined) {
|
|
40
|
+
surfaces.push({ label: `${ws.name} (connectPermission)`, permission: ws.connectPermission, hasWire });
|
|
41
|
+
}
|
|
42
|
+
const pushed = ws.contract.serverToClient.methods;
|
|
43
|
+
for (const name of Object.keys(pushed)) {
|
|
44
|
+
if (isNonPublic(pushed[name].permission))
|
|
45
|
+
deadServerToClient.push(` ${ws.name}.${name}`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (deadServerToClient.length > 0) {
|
|
49
|
+
throw new Error(`GGHttpServer: these WebSocket serverToClient methods declare a non-public permission, ` +
|
|
50
|
+
`but server-pushed messages have no caller to gate — the permission is silently ignored:\n\n` +
|
|
51
|
+
deadServerToClient.join("\n") +
|
|
52
|
+
`\n\nFix: set \`permission: GG_NO_PERMISSIONS\` on serverToClient methods.`);
|
|
53
|
+
}
|
|
54
|
+
const unsatisfiable = surfaces.filter(s => isNonPublic(s.permission) && !s.hasWire);
|
|
55
|
+
if (unsatisfiable.length > 0) {
|
|
56
|
+
const lines = unsatisfiable.map(s => ` ${s.label}`).join("\n");
|
|
57
|
+
throw new Error(`GGHttpServer: these routes require a permission but their schema .use()s no wire that ` +
|
|
58
|
+
`resolves permissions — they can never pass the gate (permanently FORBIDDEN):\n\n` +
|
|
59
|
+
lines +
|
|
60
|
+
`\n\nFix: .use() an auth wire whose handler exposes permissions(), or set the route to ` +
|
|
61
|
+
`\`GG_NO_PERMISSIONS\` if it is meant to be public.`);
|
|
62
|
+
}
|
|
63
|
+
let strict = false;
|
|
64
|
+
const undeclared = [];
|
|
65
|
+
for (const s of surfaces) {
|
|
66
|
+
if (s.permission !== undefined)
|
|
67
|
+
strict = true;
|
|
68
|
+
if (s.permission === undefined)
|
|
69
|
+
undeclared.push(s);
|
|
70
|
+
}
|
|
71
|
+
if (!strict)
|
|
72
|
+
return;
|
|
73
|
+
if (undeclared.length > 0) {
|
|
74
|
+
const lines = undeclared.map(s => ` ${s.label}`).join("\n");
|
|
75
|
+
throw new Error(`GGHttpServer: permission strict mode is active on this server ` +
|
|
76
|
+
`(at least one route declares a permission), ` +
|
|
77
|
+
`but the following routes have no \`permission\` declared:\n\n` +
|
|
78
|
+
lines +
|
|
79
|
+
`\n\nFix: declare \`permission\` on every route — use \`GG_NO_PERMISSIONS\` for intentionally public ones.`);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=checkPermissionsAtStart.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkPermissionsAtStart.js","sourceRoot":"","sources":["../../../../src/server/checkers/checkPermissionsAtStart.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAC,iBAAiB,EAAiC,MAAM,kBAAkB,CAAA;AAElF,OAAO,EAAC,gBAAgB,EAAC,MAAM,+BAA+B,CAAA;AAC9D,OAAO,oCAAoC,CAAA;AAkB3C,SAAS,WAAW,CAAC,UAAoC;IACrD,OAAO,UAAU,KAAK,SAAS,IAAI,UAAU,KAAK,iBAAiB,CAAA;AACvE,CAAC;AAED,SAAS,iBAAiB,CAAC,KAAuC;IAC9D,OAAO,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,YAAY,gBAAgB,IAAI,EAAE,CAAC,cAAc,EAAE,CAAC,CAAA;AAClF,CAAC;AAED,MAAM,UAAU,uBAAuB,CACnC,WAAsC,EACtC,gBAAgD;IAGhD,MAAM,QAAQ,GAAc,EAAE,CAAA;IAC9B,MAAM,kBAAkB,GAAa,EAAE,CAAA;IAEvC,KAAK,MAAM,MAAM,IAAI,WAAW,EAAE,CAAC;QAC/B,MAAM,OAAO,GAAG,iBAAiB,CAAC,MAAM,CAAC,cAAc,CAAC,CAAA;QACxD,MAAM,OAAO,GAAG,MAAM,CAAC,QAAQ,EAAE,OAAO,IAAI,EAAE,CAAA;QAC9C,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;YACtC,QAAQ,CAAC,IAAI,CAAC,EAAC,KAAK,EAAE,GAAG,MAAM,CAAC,IAAI,IAAI,IAAI,EAAE,EAAE,UAAU,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,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