@grest-ts/http 0.0.47 → 0.0.49
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 +321 -128
- 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/client/GGHttpSchema.createClient.d.ts +8 -0
- package/dist/src/client/GGHttpSchema.createClient.d.ts.map +1 -1
- package/dist/src/client/GGHttpSchema.createClient.js +2 -1
- package/dist/src/client/GGHttpSchema.createClient.js.map +1 -1
- package/dist/src/index-browser.d.ts +4 -0
- package/dist/src/index-browser.d.ts.map +1 -1
- package/dist/src/index-browser.js +4 -0
- package/dist/src/index-browser.js.map +1 -1
- package/dist/src/index-node.d.ts +9 -1
- package/dist/src/index-node.d.ts.map +1 -1
- package/dist/src/index-node.js +17 -5
- package/dist/src/index-node.js.map +1 -1
- package/dist/src/rpc/GGHttpRouteRPC.d.ts +4 -0
- package/dist/src/rpc/GGHttpRouteRPC.d.ts.map +1 -1
- package/dist/src/rpc/GGHttpRouteRPC.js +6 -0
- package/dist/src/rpc/GGHttpRouteRPC.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 -0
- package/dist/src/rpc/RpcResponse/GGRpcResponseBuilder.d.ts.map +1 -1
- package/dist/src/rpc/RpcResponse/GGRpcResponseBuilder.js +4 -0
- 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 +14 -52
- 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 -4
- package/dist/src/schema/httpSchema.d.ts.map +1 -1
- package/dist/src/schema/httpSchema.js +0 -48
- 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 +14 -28
- package/dist/src/server/GGHttpSchema.startServer.js.map +1 -1
- package/dist/src/server/GGHttpServer.d.ts +45 -14
- package/dist/src/server/GGHttpServer.d.ts.map +1 -1
- package/dist/src/server/GGHttpServer.js +61 -87
- 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 +12 -0
- package/dist/src/server/applyResponseMiddleware.d.ts.map +1 -0
- package/dist/src/server/applyResponseMiddleware.js +25 -0
- package/dist/src/server/applyResponseMiddleware.js.map +1 -0
- 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/client/GGHttpSchema.createClient.ts +10 -1
- package/src/index-browser.ts +4 -0
- package/src/index-node.ts +18 -5
- package/src/rpc/GGHttpRouteRPC.ts +8 -0
- package/src/rpc/RpcRequest/GGRpcRequestBuilder.ts +11 -4
- package/src/rpc/RpcRequest/GGRpcRequestParser.ts +16 -17
- package/src/rpc/RpcResponse/GGRpcResponseBuilder.ts +5 -0
- 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 +15 -63
- package/src/schema/GGWireContextKey.node.ts +119 -0
- package/src/schema/GGWireContextKey.ts +46 -0
- package/src/schema/httpSchema.ts +4 -57
- package/src/server/GGHttp.ts +3 -34
- package/src/server/GGHttpSchema.startServer.ts +16 -38
- package/src/server/GGHttpServer.ts +90 -97
- package/src/server/applyRequestMiddleware.ts +40 -0
- package/src/server/applyResponseMiddleware.ts +27 -0
- 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/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/server/GG_PERMISSIONS.ts +0 -15
|
@@ -41,54 +41,6 @@ class GGHttpSchemaBuilder {
|
|
|
41
41
|
this._middlewares.push(middleware);
|
|
42
42
|
return this;
|
|
43
43
|
}
|
|
44
|
-
useHeader(contextKey) {
|
|
45
|
-
const codec = contextKey.getCodec("http");
|
|
46
|
-
if (!codec) {
|
|
47
|
-
throw new Error(`Context key '${contextKey.name}' does not have an 'http-header' codec registered.`);
|
|
48
|
-
}
|
|
49
|
-
// Build the typed header map from codec.inputSchema — the IsObject({headerName: schema})
|
|
50
|
-
// that describes which headers this codec reads and what format each value has.
|
|
51
|
-
const inputSchema = codec.inputSchema;
|
|
52
|
-
const headers = {};
|
|
53
|
-
if (inputSchema) {
|
|
54
|
-
const desc = inputSchema.toSchemaDescription();
|
|
55
|
-
if (desc.node.kind === 'object') {
|
|
56
|
-
for (const [k, fieldDesc] of Object.entries(desc.node.properties)) {
|
|
57
|
-
headers[k] = fieldDesc.schema;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
const middleware = {
|
|
62
|
-
headers,
|
|
63
|
-
responseHeaders: {},
|
|
64
|
-
updateRequest(req) {
|
|
65
|
-
const contextValue = contextKey.get();
|
|
66
|
-
if (contextValue !== undefined) {
|
|
67
|
-
const result = codec.decode(contextValue);
|
|
68
|
-
if (result.success) {
|
|
69
|
-
Object.assign(req.headers, result.value);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
const emptyResult = codec.decode({});
|
|
74
|
-
if (emptyResult.success) {
|
|
75
|
-
for (const key of Object.keys(emptyResult.value)) {
|
|
76
|
-
delete req.headers[key];
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
},
|
|
81
|
-
parseRequest(req) {
|
|
82
|
-
const headers = req.headers;
|
|
83
|
-
const result = codec.encode(headers);
|
|
84
|
-
if (result.success) {
|
|
85
|
-
contextKey.set(result.value);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
this._middlewares.push(middleware);
|
|
90
|
-
return this;
|
|
91
|
-
}
|
|
92
44
|
routes(mapping) {
|
|
93
45
|
return new GGHttpSchema(this._pathPrefix, this._contract, mapping, this._middlewares);
|
|
94
46
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"httpSchema.js","sourceRoot":"","sources":["../../../src/schema/httpSchema.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"httpSchema.js","sourceRoot":"","sources":["../../../src/schema/httpSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAIzD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,UAAU,UAAU,CACtB,QAAoC;IAEpC,OAAO,IAAI,mBAAmB,CAAC,QAAQ,CAAC,CAAA;AAC5C,CAAC;AAED,MAAM,mBAAmB;IAEJ,SAAS,CAA4B;IAC9C,WAAW,GAAW,EAAE,CAAA;IACxB,YAAY,GAA4B,EAAE,CAAA;IAElD,YAAY,QAAoC;QAC5C,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;IAC9B,CAAC;IAED,UAAU,CAAC,MAAc;QACrB,IAAI,CAAC,WAAW,GAAG,MAAM,CAAA;QACzB,OAAO,IAAI,CAAA;IACf,CAAC;IAED,GAAG,CAAkC,UAAa;QAC9C,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;QAClC,OAAO,IAA+D,CAAA;IAC1E,CAAC;IAED,MAAM,CAAC,OAAgD;QACnD,OAAO,IAAI,YAAY,CAAC,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,SAAS,EAAE,OAAO,EAAE,IAAI,CAAC,YAAY,CAAC,CAAA;IACzF,CAAC;CACJ"}
|
|
@@ -1,20 +1,7 @@
|
|
|
1
1
|
import { GGHttpSchema } from "../schema/GGHttpSchema";
|
|
2
2
|
import { GGContractApiDefinition, GGContractImplementation } from "@grest-ts/schema";
|
|
3
|
-
import {
|
|
3
|
+
import type { GGTransportMiddleware } from "@grest-ts/context";
|
|
4
4
|
import { GGHttpServer } from "./GGHttpServer";
|
|
5
|
-
/**
|
|
6
|
-
* Resolves the caller's permission scopes for the current request. The function
|
|
7
|
-
* is called once between transport middleware and the handler. Sync or async —
|
|
8
|
-
* both supported (the gate awaits).
|
|
9
|
-
*
|
|
10
|
-
* Return `null` when no caller identity is available (the gate will throw
|
|
11
|
-
* NOT_AUTHORIZED for non-public methods). Return a (possibly empty) set
|
|
12
|
-
* otherwise; the gate will call satisfies() against the method's permission.
|
|
13
|
-
*
|
|
14
|
-
* The resolver should read whatever app-defined context the upstream auth
|
|
15
|
-
* middleware populated — it should NOT parse the token itself.
|
|
16
|
-
*/
|
|
17
|
-
export type GGScopeResolver = () => ReadonlySet<string> | null | Promise<ReadonlySet<string> | null>;
|
|
18
5
|
export declare class GGHttp<TContext = undefined> {
|
|
19
6
|
/**
|
|
20
7
|
* Protected (not private) so that plugin modules can access the underlying server
|
|
@@ -23,19 +10,8 @@ export declare class GGHttp<TContext = undefined> {
|
|
|
23
10
|
*/
|
|
24
11
|
protected readonly httpServer: GGHttpServer;
|
|
25
12
|
private readonly middlewares;
|
|
26
|
-
private permissionResolver?;
|
|
27
13
|
constructor(httpServer: GGHttpServer);
|
|
28
|
-
use<M extends
|
|
29
|
-
/**
|
|
30
|
-
* Register a scope resolver. Subsequent .http(...) calls capture this
|
|
31
|
-
* resolver and use it to gate every request against the contract's
|
|
32
|
-
* declared `permission`.
|
|
33
|
-
*
|
|
34
|
-
* Calling order matters: .use(auth) → .usePermissions(getScopes) → .http(api).
|
|
35
|
-
* If .http() runs before .usePermissions(), the call sees no resolver — and
|
|
36
|
-
* the startup check will hard-fail if its schema has any non-public method.
|
|
37
|
-
*/
|
|
38
|
-
usePermissions(resolver: GGScopeResolver): this;
|
|
14
|
+
use<M extends GGTransportMiddleware>(middleware: M): GGHttp<TContext | M>;
|
|
39
15
|
http<TContract extends GGContractApiDefinition, TSchemaContext>(schema: GGHttpSchema<TContract, TSchemaContext>, implementation: GGContractImplementation<TContract>): this;
|
|
40
16
|
}
|
|
41
17
|
//# sourceMappingURL=GGHttp.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GGHttp.d.ts","sourceRoot":"","sources":["../../../src/server/GGHttp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAC,uBAAuB,EAAE,wBAAwB,EAAC,MAAM,kBAAkB,CAAC;AACnF,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"GGHttp.d.ts","sourceRoot":"","sources":["../../../src/server/GGHttp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAC,uBAAuB,EAAE,wBAAwB,EAAC,MAAM,kBAAkB,CAAC;AACnF,OAAO,KAAK,EAAC,qBAAqB,EAAC,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAE5C,qBAAa,MAAM,CAAC,QAAQ,GAAG,SAAS;IAEpC;;;;OAIG;IACH,SAAS,CAAC,QAAQ,CAAC,UAAU,EAAE,YAAY,CAAA;IAC3C,OAAO,CAAC,QAAQ,CAAC,WAAW,CAA+B;gBAE/C,UAAU,EAAE,YAAY;IAI7B,GAAG,CAAC,CAAC,SAAS,qBAAqB,EAAE,UAAU,EAAE,CAAC,GAAG,MAAM,CAAC,QAAQ,GAAG,CAAC,CAAC;IAKzE,IAAI,CAAC,SAAS,SAAS,uBAAuB,EAAE,cAAc,EACjE,MAAM,EAAE,YAAY,CAAC,SAAS,EAAE,cAAc,CAAC,EAC/C,cAAc,EAAE,wBAAwB,CAAC,SAAS,CAAC,GACpD,IAAI;CAOV"}
|
|
@@ -6,7 +6,6 @@ export class GGHttp {
|
|
|
6
6
|
*/
|
|
7
7
|
httpServer;
|
|
8
8
|
middlewares = [];
|
|
9
|
-
permissionResolver;
|
|
10
9
|
constructor(httpServer) {
|
|
11
10
|
this.httpServer = httpServer;
|
|
12
11
|
}
|
|
@@ -14,24 +13,10 @@ export class GGHttp {
|
|
|
14
13
|
this.middlewares.push(middleware);
|
|
15
14
|
return this;
|
|
16
15
|
}
|
|
17
|
-
/**
|
|
18
|
-
* Register a scope resolver. Subsequent .http(...) calls capture this
|
|
19
|
-
* resolver and use it to gate every request against the contract's
|
|
20
|
-
* declared `permission`.
|
|
21
|
-
*
|
|
22
|
-
* Calling order matters: .use(auth) → .usePermissions(getScopes) → .http(api).
|
|
23
|
-
* If .http() runs before .usePermissions(), the call sees no resolver — and
|
|
24
|
-
* the startup check will hard-fail if its schema has any non-public method.
|
|
25
|
-
*/
|
|
26
|
-
usePermissions(resolver) {
|
|
27
|
-
this.permissionResolver = resolver;
|
|
28
|
-
return this;
|
|
29
|
-
}
|
|
30
16
|
http(schema, implementation) {
|
|
31
17
|
schema.register(implementation, {
|
|
32
18
|
http: this.httpServer,
|
|
33
19
|
middlewares: this.middlewares,
|
|
34
|
-
permissionResolver: this.permissionResolver,
|
|
35
20
|
});
|
|
36
21
|
return this;
|
|
37
22
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GGHttp.js","sourceRoot":"","sources":["../../../src/server/GGHttp.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"GGHttp.js","sourceRoot":"","sources":["../../../src/server/GGHttp.ts"],"names":[],"mappings":"AAKA,MAAM,OAAO,MAAM;IAEf;;;;OAIG;IACgB,UAAU,CAAc;IAC1B,WAAW,GAA4B,EAAE,CAAC;IAE3D,YAAY,UAAwB;QAChC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IACjC,CAAC;IAEM,GAAG,CAAkC,UAAa;QACrD,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAClC,OAAO,IAAW,CAAC;IACvB,CAAC;IAEM,IAAI,CACP,MAA+C,EAC/C,cAAmD;QAEnD,MAAM,CAAC,QAAQ,CAAC,cAAc,EAAE;YAC5B,IAAI,EAAE,IAAI,CAAC,UAAU;YACrB,WAAW,EAAE,IAAI,CAAC,WAAW;SAChC,CAAC,CAAC;QACH,OAAO,IAAW,CAAC;IACvB,CAAC;CACJ"}
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
* This file should only be imported in server (Node.js) context.
|
|
4
4
|
*/
|
|
5
5
|
import { GGContractApiDefinition, GGContractImplementation } from "@grest-ts/schema";
|
|
6
|
+
import { type GGTransportMiddleware } from "@grest-ts/context";
|
|
6
7
|
import { GGHttpServer } from "./GGHttpServer";
|
|
7
|
-
import type { GGScopeResolver } from "./GGHttp";
|
|
8
8
|
export interface GGHttpSchemaConfig {
|
|
9
9
|
/**
|
|
10
10
|
* The HTTP request handler to register with.
|
|
@@ -13,16 +13,7 @@ export interface GGHttpSchemaConfig {
|
|
|
13
13
|
/**
|
|
14
14
|
* Additional middlewares to apply to all routes.
|
|
15
15
|
*/
|
|
16
|
-
middlewares?:
|
|
17
|
-
/**
|
|
18
|
-
* Optional scope resolver. When set, the gate calls it once per request,
|
|
19
|
-
* populates GG_PERMISSIONS, and rejects requests whose contract permission
|
|
20
|
-
* is not satisfied by the resolved scopes.
|
|
21
|
-
*/
|
|
22
|
-
permissionResolver?: GGScopeResolver;
|
|
23
|
-
}
|
|
24
|
-
export interface GGHttpServerMiddleware {
|
|
25
|
-
process?(): Promise<void>;
|
|
16
|
+
middlewares?: GGTransportMiddleware[];
|
|
26
17
|
}
|
|
27
18
|
declare module "../schema/GGHttpSchema" {
|
|
28
19
|
interface GGHttpSchema<TContract extends GGContractApiDefinition> {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GGHttpSchema.startServer.d.ts","sourceRoot":"","sources":["../../../src/server/GGHttpSchema.startServer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,
|
|
1
|
+
{"version":3,"file":"GGHttpSchema.startServer.d.ts","sourceRoot":"","sources":["../../../src/server/GGHttpSchema.startServer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EAAQ,uBAAuB,EAAE,wBAAwB,EAAqC,MAAM,kBAAkB,CAAC;AAG9H,OAAO,EAA4B,KAAK,qBAAqB,EAAC,MAAM,mBAAmB,CAAC;AAOxF,OAAO,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAI5C,MAAM,WAAW,kBAAkB;IAC/B;;OAEG;IACH,IAAI,CAAC,EAAE,YAAY,CAAC;IACpB;;OAEG;IACH,WAAW,CAAC,EAAE,qBAAqB,EAAE,CAAC;CACzC;AAED,OAAO,QAAQ,wBAAwB,CAAC;IACpC,UAAU,YAAY,CAAC,SAAS,SAAS,uBAAuB;QAC5D;;;;WAIG;QACH,QAAQ,CAAC,cAAc,EAAE,wBAAwB,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC,EAAE,kBAAkB,GAAG,IAAI,CAAA;KACnG;CACJ"}
|
|
@@ -4,16 +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/GGCookie.js";
|
|
12
13
|
import { GG_METRICS } from "@grest-ts/metrics";
|
|
13
14
|
import { GGHttpMetrics } from "./GGHttpMetrics.js";
|
|
14
15
|
import { GG_HTTP_SERVER } from "./GG_HTTP_SERVER.js";
|
|
15
16
|
import { GGLog } from "@grest-ts/logger";
|
|
16
|
-
import {
|
|
17
|
+
import { GGHttpPermissionsChecker } from "../schema/GGHttpPermissionsChecker.js";
|
|
17
18
|
GGHttpSchema.prototype.register = function (implementation, config) {
|
|
18
19
|
return setupRoutes(this, implementation, config);
|
|
19
20
|
};
|
|
@@ -30,9 +31,10 @@ function setupRoutes(httpSchema, implementation, config) {
|
|
|
30
31
|
const apiMiddlewares = httpSchema.apiMiddlewares;
|
|
31
32
|
const scope = GGLocator.getScope();
|
|
32
33
|
const parentContext = GGContextStore.tryGetContext();
|
|
34
|
+
const permissionsChecker = new GGHttpPermissionsChecker(apiMiddlewares);
|
|
33
35
|
for (const mw of apiMiddlewares) {
|
|
34
|
-
const hKeys = Object.keys(mw.headers);
|
|
35
|
-
const rhKeys = Object.keys(mw.responseHeaders);
|
|
36
|
+
const hKeys = Object.keys(mw.headers ?? {});
|
|
37
|
+
const rhKeys = Object.keys(mw.responseHeaders ?? {});
|
|
36
38
|
if (hKeys.length)
|
|
37
39
|
server.registerCorsHeaders(hKeys);
|
|
38
40
|
if (rhKeys.length)
|
|
@@ -56,8 +58,6 @@ function setupRoutes(httpSchema, implementation, config) {
|
|
|
56
58
|
// Info: Contract instance is auto-registered in GGLocator via patched implement()
|
|
57
59
|
// @TODO This is not really used and only for testkit so it would register implementation of the contract... Not cool
|
|
58
60
|
httpSchema.contract.implement(implementation);
|
|
59
|
-
if (config.permissionResolver)
|
|
60
|
-
server._markResolverWired(httpSchema);
|
|
61
61
|
for (const methodName in httpSchema.codec) {
|
|
62
62
|
// Wire format.
|
|
63
63
|
const codec = httpSchema.codec[methodName];
|
|
@@ -74,36 +74,22 @@ function setupRoutes(httpSchema, implementation, config) {
|
|
|
74
74
|
// build request mapping
|
|
75
75
|
const requestParser = codec.createForServer({
|
|
76
76
|
contract: contractFunctionSchema,
|
|
77
|
-
|
|
78
|
-
serverMiddlewares: config.middlewares
|
|
77
|
+
middlewares: [...apiMiddlewares, ...(config.middlewares ?? [])]
|
|
79
78
|
});
|
|
79
|
+
const cookieWriteNames = new Set((codec.updatesCookies ?? []).map(k => k.name));
|
|
80
80
|
server.registerRoute(codec.method, pathPrefix + codec.path, async (req, res) => {
|
|
81
81
|
scope.ensureEntered();
|
|
82
|
-
return new GGContext("REQ", parentContext).run(async () => {
|
|
82
|
+
return new GGContext("REQ", parentContext, true).run(async () => {
|
|
83
83
|
GG_TRACE.init();
|
|
84
84
|
GG_HTTP_REQUEST.set({ port: server.port, method: req.method, path: req.url });
|
|
85
|
+
GG_COOKIE_WRITES.set(cookieWriteNames);
|
|
85
86
|
const startTime = performance.now();
|
|
86
87
|
let rpcResult;
|
|
87
88
|
try {
|
|
88
|
-
const
|
|
89
|
+
const rawInput = await requestParser.readRequest(req);
|
|
90
|
+
await permissionsChecker.assert(httpSchema.name, methodName, contractFunctionSchema.permission);
|
|
89
91
|
try {
|
|
90
|
-
|
|
91
|
-
const scopes = await config.permissionResolver();
|
|
92
|
-
if (scopes != null)
|
|
93
|
-
GG_PERMISSIONS.set(new GGPermissionChecker(scopes));
|
|
94
|
-
const required = contractFunctionSchema.permission;
|
|
95
|
-
if (required !== undefined && required !== GG_NO_PERMISSIONS) {
|
|
96
|
-
if (scopes == null)
|
|
97
|
-
throw new NOT_AUTHORIZED({
|
|
98
|
-
debugMessage: `${httpSchema.name}.${methodName} requires ${describePermission(required)} but no caller identity was resolved`
|
|
99
|
-
});
|
|
100
|
-
if (!satisfies(required, scopes))
|
|
101
|
-
throw new FORBIDDEN({
|
|
102
|
-
debugMessage: `${httpSchema.name}.${methodName} requires ${describePermission(required)} — caller scopes did not satisfy`
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
rpcResult = { success: true, type: "OK", data: await implFn(rpcInput) };
|
|
92
|
+
rpcResult = { success: true, type: "OK", data: await implFn(requestParser.validateInput(rawInput)) };
|
|
107
93
|
// GGLog.debug(httpSchema, "Response", rpcResult) // This is very slow to log this (like 3x performance loss)
|
|
108
94
|
}
|
|
109
95
|
catch (error) {
|
|
@@ -123,7 +109,7 @@ function setupRoutes(httpSchema, implementation, config) {
|
|
|
123
109
|
metrics(rpcResult?.type, httpSchema.name, codec.method, pathPrefix, codec.path, startTime);
|
|
124
110
|
}
|
|
125
111
|
});
|
|
126
|
-
});
|
|
112
|
+
}, `${httpSchema.name}.${methodName}`);
|
|
127
113
|
}
|
|
128
114
|
}
|
|
129
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;AACpD,OAAO,EAAC,UAAU,EAAC,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAC,aAAa,EAAC,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAEhD,OAAO,EAAC,KAAK,EAAC,MAAM,kBAAkB,CAAC;AACvC,OAAO,EAAC,wBAAwB,EAAC,MAAM,oCAAoC,CAAC;AAwB5E,YAAY,CAAC,SAAS,CAAC,QAAQ,GAAG,UAE9B,cAAmD,EACnD,MAA2B;IAE3B,OAAO,WAAW,CAAC,IAAI,EAAE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AAe,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,13 +12,37 @@ 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
|
};
|
|
22
|
+
export interface GGCorsConfig {
|
|
23
|
+
/**
|
|
24
|
+
* Allowed cross-origin origins. Either an exact-match list or a predicate.
|
|
25
|
+
* Only a matching Origin is echoed back — an arbitrary origin is never
|
|
26
|
+
* reflected (that would be a credential-leak / CSRF hole with credentials on).
|
|
27
|
+
*/
|
|
28
|
+
origins: string[] | ((origin: string) => boolean);
|
|
29
|
+
/**
|
|
30
|
+
* When true, adds Access-Control-Allow-Credentials: true so the browser will
|
|
31
|
+
* send/store cross-origin cookies. Requires an exact-origin echo (never `*`),
|
|
32
|
+
* which this enforces by construction.
|
|
33
|
+
*/
|
|
34
|
+
credentials?: boolean;
|
|
35
|
+
}
|
|
17
36
|
export interface GGHttpServerAdapterConfig {
|
|
18
37
|
key?: GGLocatorKey<GGHttpServer>;
|
|
19
38
|
port?: number;
|
|
39
|
+
/**
|
|
40
|
+
* Cross-origin policy. Omitted (default) keeps the permissive
|
|
41
|
+
* `Access-Control-Allow-Origin: *` with no credentials — backward compatible.
|
|
42
|
+
* When set, switches to allowlisted mode: only an Origin in `origins` is echoed
|
|
43
|
+
* (never `*`), and `credentials: true` enables cross-origin cookies.
|
|
44
|
+
*/
|
|
45
|
+
cors?: GGCorsConfig;
|
|
20
46
|
/**
|
|
21
47
|
* If provided, the server listens over HTTPS using this cert+key. Both
|
|
22
48
|
* must be PEM-encoded strings or Buffers. Leaving undefined keeps the
|
|
@@ -36,6 +62,7 @@ export declare class GGHttpServer {
|
|
|
36
62
|
protected readonly scope: GGLocatorScope;
|
|
37
63
|
protected readonly runtimeName: string;
|
|
38
64
|
private readonly configuredPort;
|
|
65
|
+
private readonly cors?;
|
|
39
66
|
private readonly _onStart;
|
|
40
67
|
private readonly _onTeardown;
|
|
41
68
|
/**
|
|
@@ -43,12 +70,9 @@ export declare class GGHttpServer {
|
|
|
43
70
|
* Framework-internal — only setupRoutes() (in GGHttpSchema.startServer.ts) should push here.
|
|
44
71
|
*/
|
|
45
72
|
private readonly _registeredSchemas;
|
|
46
|
-
|
|
47
|
-
* All GGHttpSchema instances registered on this server, in registration order.
|
|
48
|
-
* Available from the moment compose() begins; frozen (no further push allowed) once start() is called.
|
|
49
|
-
*/
|
|
50
|
-
get registeredSchemas(): ReadonlyArray<GGHttpSchema<any, any>>;
|
|
73
|
+
private readonly _registeredWebSocketSchemas;
|
|
51
74
|
readonly httpServer: http.Server;
|
|
75
|
+
private readonly _routeOwners;
|
|
52
76
|
private activeRequests;
|
|
53
77
|
private router;
|
|
54
78
|
private static readonly DEFAULT_CORS_HEADERS;
|
|
@@ -74,24 +98,31 @@ export declare class GGHttpServer {
|
|
|
74
98
|
get port(): number | undefined;
|
|
75
99
|
/** @internal Called by setupRoutes() during compose(). Do not call directly. */
|
|
76
100
|
_registerSchema(schema: GGHttpSchema<any, any>): void;
|
|
77
|
-
|
|
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;
|
|
78
108
|
/**
|
|
79
109
|
* All GGWebSocketSchema instances registered on this server, in registration order.
|
|
80
110
|
* Populated automatically by GGWebSocketSchema.startServer() / .register().
|
|
81
111
|
*/
|
|
82
112
|
get registeredWebSocketSchemas(): ReadonlyArray<AnyWebSocketSchema>;
|
|
83
|
-
|
|
84
|
-
_registerWebSocketSchema(schema: AnyWebSocketSchema): void;
|
|
85
|
-
private readonly _schemasWithResolver;
|
|
86
|
-
/** @internal Called by HTTP / WS register paths when a scope resolver is wired. */
|
|
87
|
-
_markResolverWired(schema: object): void;
|
|
88
|
-
private _checkPermissionsAtStart;
|
|
89
|
-
registerRoute(method: HttpMethod, path: string, handler: GGHttpRequestCallback): void;
|
|
113
|
+
registerRoute(method: HttpMethod, path: string, handler: GGHttpRequestCallback, owner?: string): void;
|
|
90
114
|
start(): Promise<void>;
|
|
91
115
|
teardown(): Promise<void>;
|
|
92
116
|
onStart(callback: () => Promise<void> | void): this;
|
|
93
117
|
onTeardown(callback: () => Promise<void> | void): this;
|
|
94
118
|
}
|
|
95
119
|
export type GGHttpRequestCallback = (req: http.IncomingMessage, res: http.ServerResponse) => Promise<void>;
|
|
120
|
+
/**
|
|
121
|
+
* Computes CORS response headers for a request Origin. Pure (no req/res) so it is
|
|
122
|
+
* unit-testable. Default (no config) = permissive `*`, no credentials. With config =
|
|
123
|
+
* allowlisted: only a matching Origin is echoed (never `*`), `credentials` adds
|
|
124
|
+
* Allow-Credentials, and Vary: Origin is always set so caches key on the origin.
|
|
125
|
+
*/
|
|
126
|
+
export declare function corsResponseHeaders(origin: string | undefined, cors: GGCorsConfig | undefined, allowHeaders: string, exposeHeaders: string): Record<string, string>;
|
|
96
127
|
export {};
|
|
97
128
|
//# sourceMappingURL=GGHttpServer.d.ts.map
|
|
@@ -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;AAIhG,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,wBA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