@grest-ts/http 0.0.33 → 0.0.35
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 +24 -0
- package/dist/src/_dedupCheck.js +1 -1
- package/dist/src/index-node.d.ts +1 -0
- package/dist/src/index-node.d.ts.map +1 -1
- package/dist/src/index-node.js +1 -0
- package/dist/src/index-node.js.map +1 -1
- package/dist/src/server/GGHttp.d.ts +24 -0
- package/dist/src/server/GGHttp.d.ts.map +1 -1
- package/dist/src/server/GGHttp.js +19 -1
- package/dist/src/server/GGHttp.js.map +1 -1
- package/dist/src/server/GGHttpSchema.startServer.d.ts +7 -0
- package/dist/src/server/GGHttpSchema.startServer.d.ts.map +1 -1
- package/dist/src/server/GGHttpSchema.startServer.js +20 -1
- package/dist/src/server/GGHttpSchema.startServer.js.map +1 -1
- package/dist/src/server/GGHttpServer.d.ts +11 -1
- package/dist/src/server/GGHttpServer.d.ts.map +1 -1
- package/dist/src/server/GGHttpServer.js +68 -0
- package/dist/src/server/GGHttpServer.js.map +1 -1
- package/dist/src/server/GG_PERMISSIONS.d.ts +15 -0
- package/dist/src/server/GG_PERMISSIONS.d.ts.map +1 -0
- package/dist/src/server/GG_PERMISSIONS.js +15 -0
- package/dist/src/server/GG_PERMISSIONS.js.map +1 -0
- package/dist/tsconfig.publish.tsbuildinfo +1 -1
- package/package.json +10 -10
- package/src/_dedupCheck.ts +1 -1
- package/src/index-node.ts +1 -0
- package/src/server/GGHttp.ts +35 -1
- package/src/server/GGHttpSchema.startServer.ts +24 -1
- package/src/server/GGHttpServer.ts +84 -1
- package/src/server/GG_PERMISSIONS.ts +15 -0
package/README.md
CHANGED
|
@@ -166,6 +166,30 @@ export const MyApiContract = new GGContractClass("MyApi", {
|
|
|
166
166
|
})
|
|
167
167
|
```
|
|
168
168
|
|
|
169
|
+
## Permissions
|
|
170
|
+
|
|
171
|
+
Contract methods may declare a `permission`. The framework gates every request against the declared permission **before the handler runs**, so missing or wrong scopes can never reach service code. Declarations are opt-in but *infectious*: once any route on the server declares one (or `.usePermissions(...)` is wired), every route on the server must declare — the runtime refuses to start otherwise (see "Hard guarantee" below).
|
|
172
|
+
|
|
173
|
+
The wiring chain is read top-to-bottom:
|
|
174
|
+
|
|
175
|
+
```typescript
|
|
176
|
+
new GGHttp(httpServer)
|
|
177
|
+
.use(new JwtAuthMiddleware(secret)) // parses the token → context
|
|
178
|
+
.usePermissions(getScopes) // reads context → scope set
|
|
179
|
+
.http(ItemApi, new ItemApiImpl())
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
Each step has one job: the auth middleware turns a token into identity in context; the scope resolver (a zero-arg `() => ReadonlySet<string> | null`, sync or async) extracts the caller's scopes from that context; the gate calls the resolver, checks `satisfies(method.permission, scopes)`, and throws `NOT_AUTHORIZED` (no identity) or `FORBIDDEN` (wrong scopes). Order matters — `.usePermissions(...)` must come before the `.http(...)` calls it should apply to.
|
|
183
|
+
|
|
184
|
+
**Hard guarantee.** At server start the framework walks every HTTP / WS route registered on the `GGHttpServer`. If any of them declared a permission, or any chain wired `.usePermissions(...)`, **strict mode** is on for the whole server. In strict mode:
|
|
185
|
+
|
|
186
|
+
- Every route must declare `permission` — use `GG_NO_PERMISSIONS` for intentionally public ones. Routes that omit it fail the start and are listed by name.
|
|
187
|
+
- A route declaring a non-public permission without a resolver on its registering chain also fails the start.
|
|
188
|
+
|
|
189
|
+
The check is per-server (HTTP routes + WS schemas on the same `GGHttpServer`), so a permission declared anywhere is infectious across sibling chains. The only way to opt out is to declare nothing — projects with no auth pay zero ceremony, but the moment one route opts in, the framework forces consistency.
|
|
190
|
+
|
|
191
|
+
**What this does not cover.** The permission gates *endpoint access* — "is this caller allowed to invoke this method at all?" It does not handle *resource access* — "can this caller edit *this specific* post?" That check still belongs in the handler. The same `GGPermissionChecker` the gate used is exposed via `GG_PERMISSIONS.get()`, so handler-side sub-decisions use identical logic with no drift between framework and app code.
|
|
192
|
+
|
|
169
193
|
## Authentication & Context
|
|
170
194
|
|
|
171
195
|
### Using Codec (Recommended for Header-Based Auth)
|
package/dist/src/_dedupCheck.js
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
const __KEY = Symbol.for("grest-ts:dedup:@grest-ts/http");
|
|
12
12
|
const __slot = globalThis;
|
|
13
13
|
const __existing = __slot[__KEY];
|
|
14
|
-
const __here = { path: import.meta.url, version: "0.0.
|
|
14
|
+
const __here = { path: import.meta.url, version: "0.0.35" };
|
|
15
15
|
// Same path + same version means the same physical package is being
|
|
16
16
|
// re-evaluated by a different ESM runner (e.g. vitest projects share one
|
|
17
17
|
// process but each project has its own module cache). That isn't a true
|
package/dist/src/index-node.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import "./_dedupCheck";
|
|
2
2
|
export * from "./server/GGHttpMetrics";
|
|
3
3
|
export * from "./server/GG_HTTP_REQUEST";
|
|
4
|
+
export * from "./server/GG_PERMISSIONS";
|
|
4
5
|
export * from "./schema/GGHttpSchema";
|
|
5
6
|
export * from "./schema/httpSchema";
|
|
6
7
|
export * from "./rpc/GGHttpRouteRPC";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-node.d.ts","sourceRoot":"","sources":["../../src/index-node.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,CAAC;AAWvB,cAAc,wBAAwB,CAAC;AAGvC,cAAc,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"index-node.d.ts","sourceRoot":"","sources":["../../src/index-node.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,CAAC;AAWvB,cAAc,wBAAwB,CAAC;AAGvC,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC;AAGxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,sBAAsB,CAAC;AACrC,cAAc,sCAAsC,CAAC;AACrD,cAAc,qCAAqC,CAAC;AACpD,cAAc,wCAAwC,CAAC;AACvD,cAAc,uCAAuC,CAAC;AAGtD,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AAGxC,cAAc,oCAAoC,CAAC;AACnD,cAAc,mCAAmC,CAAC;AAIlD,OAAO,oCAAoC,CAAC;AAC5C,OAAO,mCAAmC,CAAC"}
|
package/dist/src/index-node.js
CHANGED
|
@@ -11,6 +11,7 @@ _registerRpcServerCodecFactory((method, path, config) => ({
|
|
|
11
11
|
export * from "./server/GGHttpMetrics.js";
|
|
12
12
|
// Context
|
|
13
13
|
export * from "./server/GG_HTTP_REQUEST.js";
|
|
14
|
+
export * from "./server/GG_PERMISSIONS.js";
|
|
14
15
|
// API Schema
|
|
15
16
|
export * from "./schema/GGHttpSchema.js";
|
|
16
17
|
export * from "./schema/httpSchema.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-node.js","sourceRoot":"","sources":["../../src/index-node.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,CAAC;AACvB,+EAA+E;AAC/E,OAAO,EAAC,8BAA8B,EAAC,MAAM,sBAAsB,CAAC;AACpE,OAAO,EAAC,oBAAoB,EAAC,MAAM,wCAAwC,CAAC;AAC5E,OAAO,EAAC,kBAAkB,EAAC,MAAM,qCAAqC,CAAC;AACvE,8BAA8B,CAAC,CAAC,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC;IACtD,YAAY,EAAE,IAAI,kBAAkB,CAAC,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,YAAY;IACvE,YAAY,EAAE,IAAI,oBAAoB,CAAC,MAAM,CAAC,CAAC,YAAY;CAC9D,CAAC,CAAC,CAAC;AAEJ,UAAU;AACV,cAAc,wBAAwB,CAAC;AAEvC,UAAU;AACV,cAAc,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"index-node.js","sourceRoot":"","sources":["../../src/index-node.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,CAAC;AACvB,+EAA+E;AAC/E,OAAO,EAAC,8BAA8B,EAAC,MAAM,sBAAsB,CAAC;AACpE,OAAO,EAAC,oBAAoB,EAAC,MAAM,wCAAwC,CAAC;AAC5E,OAAO,EAAC,kBAAkB,EAAC,MAAM,qCAAqC,CAAC;AACvE,8BAA8B,CAAC,CAAC,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC;IACtD,YAAY,EAAE,IAAI,kBAAkB,CAAC,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,YAAY;IACvE,YAAY,EAAE,IAAI,oBAAoB,CAAC,MAAM,CAAC,CAAC,YAAY;CAC9D,CAAC,CAAC,CAAC;AAEJ,UAAU;AACV,cAAc,wBAAwB,CAAC;AAEvC,UAAU;AACV,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC;AAExC,aAAa;AACb,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,sBAAsB,CAAC;AACrC,cAAc,sCAAsC,CAAC;AACrD,cAAc,qCAAqC,CAAC;AACpD,cAAc,wCAAwC,CAAC;AACvD,cAAc,uCAAuC,CAAC;AAEtD,+BAA+B;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AAExC,SAAS;AACT,cAAc,oCAAoC,CAAC;AACnD,cAAc,mCAAmC,CAAC;AAGlD,aAAa;AACb,OAAO,oCAAoC,CAAC;AAC5C,OAAO,mCAAmC,CAAC"}
|
|
@@ -2,6 +2,19 @@ import { GGHttpSchema } from "../schema/GGHttpSchema";
|
|
|
2
2
|
import { GGContractApiDefinition, GGContractImplementation } from "@grest-ts/schema";
|
|
3
3
|
import { GGHttpServerMiddleware } from "./GGHttpSchema.startServer";
|
|
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>;
|
|
5
18
|
export declare class GGHttp<TContext = undefined> {
|
|
6
19
|
/**
|
|
7
20
|
* Protected (not private) so that plugin modules can access the underlying server
|
|
@@ -10,8 +23,19 @@ export declare class GGHttp<TContext = undefined> {
|
|
|
10
23
|
*/
|
|
11
24
|
protected readonly httpServer: GGHttpServer;
|
|
12
25
|
private readonly middlewares;
|
|
26
|
+
private permissionResolver?;
|
|
13
27
|
constructor(httpServer: GGHttpServer);
|
|
14
28
|
use<M extends GGHttpServerMiddleware>(middleware: M): GGHttp<TContext | M>;
|
|
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;
|
|
15
39
|
http<TContract extends GGContractApiDefinition, TSchemaContext>(schema: GGHttpSchema<TContract, TSchemaContext>, implementation: GGContractImplementation<TContract>): this;
|
|
16
40
|
}
|
|
17
41
|
//# 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,sBAAsB,EAAC,MAAM,4BAA4B,CAAC;AAClE,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,CAAgC;
|
|
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,sBAAsB,EAAC,MAAM,4BAA4B,CAAC;AAClE,OAAO,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAE5C;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,eAAe,GACvB,MAAM,WAAW,CAAC,MAAM,CAAC,GAAG,IAAI,GAAG,OAAO,CAAC,WAAW,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,CAAA;AAE1E,qBAAa,MAAM,CAAC,QAAQ,GAAG,SAAS;IAEpC;;;;OAIG;IACH,SAAS,CAAC,QAAQ,CAAC,UAAU,EAAE,YAAY,CAAA;IAC3C,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAgC;IAC5D,OAAO,CAAC,kBAAkB,CAAC,CAAkB;gBAEjC,UAAU,EAAE,YAAY;IAI7B,GAAG,CAAC,CAAC,SAAS,sBAAsB,EAAE,UAAU,EAAE,CAAC,GAAG,MAAM,CAAC,QAAQ,GAAG,CAAC,CAAC;IAKjF;;;;;;;;OAQG;IACI,cAAc,CAAC,QAAQ,EAAE,eAAe,GAAG,IAAI;IAK/C,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;CAQV"}
|
|
@@ -6,6 +6,7 @@ export class GGHttp {
|
|
|
6
6
|
*/
|
|
7
7
|
httpServer;
|
|
8
8
|
middlewares = [];
|
|
9
|
+
permissionResolver;
|
|
9
10
|
constructor(httpServer) {
|
|
10
11
|
this.httpServer = httpServer;
|
|
11
12
|
}
|
|
@@ -13,8 +14,25 @@ export class GGHttp {
|
|
|
13
14
|
this.middlewares.push(middleware);
|
|
14
15
|
return this;
|
|
15
16
|
}
|
|
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
|
+
}
|
|
16
30
|
http(schema, implementation) {
|
|
17
|
-
schema.register(implementation, {
|
|
31
|
+
schema.register(implementation, {
|
|
32
|
+
http: this.httpServer,
|
|
33
|
+
middlewares: this.middlewares,
|
|
34
|
+
permissionResolver: this.permissionResolver,
|
|
35
|
+
});
|
|
18
36
|
return this;
|
|
19
37
|
}
|
|
20
38
|
}
|
|
@@ -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":"AAoBA,MAAM,OAAO,MAAM;IAEf;;;;OAIG;IACgB,UAAU,CAAc;IAC1B,WAAW,GAA6B,EAAE,CAAC;IACpD,kBAAkB,CAAmB;IAE7C,YAAY,UAAwB;QAChC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IACjC,CAAC;IAEM,GAAG,CAAmC,UAAa;QACtD,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAClC,OAAO,IAAW,CAAC;IACvB,CAAC;IAED;;;;;;;;OAQG;IACI,cAAc,CAAC,QAAyB;QAC3C,IAAI,CAAC,kBAAkB,GAAG,QAAQ,CAAC;QACnC,OAAO,IAAI,CAAC;IAChB,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;YAC7B,kBAAkB,EAAE,IAAI,CAAC,kBAAkB;SAC9C,CAAC,CAAC;QACH,OAAO,IAAW,CAAC;IACvB,CAAC;CACJ"}
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { GGContractApiDefinition, GGContractImplementation } from "@grest-ts/schema";
|
|
6
6
|
import { GGHttpServer } from "./GGHttpServer";
|
|
7
|
+
import type { GGScopeResolver } from "./GGHttp";
|
|
7
8
|
export interface GGHttpSchemaConfig {
|
|
8
9
|
/**
|
|
9
10
|
* The HTTP request handler to register with.
|
|
@@ -13,6 +14,12 @@ export interface GGHttpSchemaConfig {
|
|
|
13
14
|
* Additional middlewares to apply to all routes.
|
|
14
15
|
*/
|
|
15
16
|
middlewares?: GGHttpServerMiddleware[];
|
|
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;
|
|
16
23
|
}
|
|
17
24
|
export interface GGHttpServerMiddleware {
|
|
18
25
|
process?(): Promise<void>;
|
|
@@ -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,EAA0D,uBAAuB,EAAE,wBAAwB,EAAqF,MAAM,kBAAkB,CAAC;AAShO,OAAO,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAG5C,OAAO,KAAK,EAAC,eAAe,EAAC,MAAM,UAAU,CAAC;AAE9C,MAAM,WAAW,kBAAkB;IAC/B;;OAEG;IACH,IAAI,CAAC,EAAE,YAAY,CAAC;IACpB;;OAEG;IACH,WAAW,CAAC,EAAE,sBAAsB,EAAE,CAAC;IACvC;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,eAAe,CAAC;CACxC;AAED,MAAM,WAAW,sBAAsB;IACnC,OAAO,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;CAC5B;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,7 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { GGLocator } from "@grest-ts/locator";
|
|
6
6
|
import { GGHttpSchema } from "../schema/GGHttpSchema.js";
|
|
7
|
-
import { ERROR, SERVER_ERROR } from "@grest-ts/schema";
|
|
7
|
+
import { describePermission, ERROR, FORBIDDEN, GG_NO_PERMISSIONS, GGPermissionChecker, NOT_AUTHORIZED, satisfies, 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";
|
|
@@ -13,6 +13,7 @@ import { GG_METRICS } from "@grest-ts/metrics";
|
|
|
13
13
|
import { GGHttpMetrics } from "./GGHttpMetrics.js";
|
|
14
14
|
import { GG_HTTP_SERVER } from "./GG_HTTP_SERVER.js";
|
|
15
15
|
import { GGLog } from "@grest-ts/logger";
|
|
16
|
+
import { GG_PERMISSIONS } from "./GG_PERMISSIONS.js";
|
|
16
17
|
GGHttpSchema.prototype.register = function (implementation, config) {
|
|
17
18
|
return setupRoutes(this, implementation, config);
|
|
18
19
|
};
|
|
@@ -55,6 +56,8 @@ function setupRoutes(httpSchema, implementation, config) {
|
|
|
55
56
|
// Info: Contract instance is auto-registered in GGLocator via patched implement()
|
|
56
57
|
// @TODO This is not really used and only for testkit so it would register implementation of the contract... Not cool
|
|
57
58
|
httpSchema.contract.implement(implementation);
|
|
59
|
+
if (config.permissionResolver)
|
|
60
|
+
server._markResolverWired(httpSchema);
|
|
58
61
|
for (const methodName in httpSchema.codec) {
|
|
59
62
|
// Wire format.
|
|
60
63
|
const codec = httpSchema.codec[methodName];
|
|
@@ -84,6 +87,22 @@ function setupRoutes(httpSchema, implementation, config) {
|
|
|
84
87
|
try {
|
|
85
88
|
const rpcInput = await requestParser.parseRequest(req);
|
|
86
89
|
try {
|
|
90
|
+
if (config.permissionResolver) {
|
|
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
|
+
}
|
|
87
106
|
rpcResult = { success: true, type: "OK", data: await implFn(rpcInput) };
|
|
88
107
|
// GGLog.debug(httpSchema, "Response", rpcResult) // This is very slow to log this (like 3x performance loss)
|
|
89
108
|
}
|
|
@@ -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,KAAK,
|
|
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,kBAAkB,EAAE,KAAK,EAAE,SAAS,EAAE,iBAAiB,EAAu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,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,11 +2,17 @@ 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 { GGContractMethod, GGPermission } from "@grest-ts/schema";
|
|
5
6
|
type AnyWebSocketSchema = {
|
|
6
7
|
name: string;
|
|
7
8
|
path: string;
|
|
8
|
-
contract:
|
|
9
|
+
contract: {
|
|
10
|
+
clientToServer: {
|
|
11
|
+
methods: Record<string, GGContractMethod>;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
9
14
|
middlewares: readonly unknown[];
|
|
15
|
+
connectPermission?: GGPermission;
|
|
10
16
|
};
|
|
11
17
|
export interface GGHttpServerAdapterConfig {
|
|
12
18
|
key?: GGLocatorKey<GGHttpServer>;
|
|
@@ -76,6 +82,10 @@ export declare class GGHttpServer {
|
|
|
76
82
|
get registeredWebSocketSchemas(): ReadonlyArray<AnyWebSocketSchema>;
|
|
77
83
|
/** @internal Called by GGWebSocketSchema.startServer(). Do not call directly. */
|
|
78
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;
|
|
79
89
|
registerRoute(method: HttpMethod, path: string, handler: GGHttpRequestCallback): void;
|
|
80
90
|
start(): Promise<void>;
|
|
81
91
|
teardown(): Promise<void>;
|
|
@@ -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,wBAAwB,CAAC;AACzD,OAAO,EAAwC,gBAAgB,EAAE,YAAY,EAAC,MAAM,kBAAkB,CAAC;AAGvG,KAAK,kBAAkB,GAAG;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE;QAAC,cAAc,EAAE;YAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAA;SAAC,CAAA;KAAC,CAAC;IACxE,WAAW,EAAE,SAAS,OAAO,EAAE,CAAC;IAChC,iBAAiB,CAAC,EAAE,YAAY,CAAC;CACpC,CAAC;AAEF,MAAM,WAAW,yBAAyB;IACtC,GAAG,CAAC,EAAE,YAAY,CAAC,YAAY,CAAC,CAAC;IACjC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;;;;;OAOG;IACH,GAAG,CAAC,EAAE;QACF,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;QACtB,GAAG,EAAE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GAAG,EAAE,GAAG,CAAC,GAAG,IAAI;IAI5D,OAAO,CAAC,QAAQ,CAAC,2BAA2B,CAA4B;IAExE;;;OAGG;IACH,IAAI,0BAA0B,IAAI,aAAa,CAAC,kBAAkB,CAAC,CAElE;IAED,iFAAiF;IAC1E,wBAAwB,CAAC,MAAM,EAAE,kBAAkB,GAAG,IAAI;IAIjE,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAAqB;IAE1D,mFAAmF;IAC5E,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAI/C,OAAO,CAAC,wBAAwB;IAoEzB,aAAa,CAAC,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,qBAAqB,GAAG,IAAI;IAI/E,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAgBtB,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"}
|
|
@@ -5,6 +5,7 @@ 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 { describePermission, GG_NO_PERMISSIONS } from "@grest-ts/schema";
|
|
8
9
|
export class GGHttpServer {
|
|
9
10
|
_port;
|
|
10
11
|
teardownPromise;
|
|
@@ -144,11 +145,78 @@ export class GGHttpServer {
|
|
|
144
145
|
_registerWebSocketSchema(schema) {
|
|
145
146
|
this._registeredWebSocketSchemas.push(schema);
|
|
146
147
|
}
|
|
148
|
+
_schemasWithResolver = new Set();
|
|
149
|
+
/** @internal Called by HTTP / WS register paths when a scope resolver is wired. */
|
|
150
|
+
_markResolverWired(schema) {
|
|
151
|
+
this._schemasWithResolver.add(schema);
|
|
152
|
+
}
|
|
153
|
+
_checkPermissionsAtStart() {
|
|
154
|
+
const surfaces = [];
|
|
155
|
+
for (const schema of this._registeredSchemas) {
|
|
156
|
+
const resolverWired = this._schemasWithResolver.has(schema);
|
|
157
|
+
const methods = schema.contract?.methods ?? {};
|
|
158
|
+
for (const name of Object.keys(methods)) {
|
|
159
|
+
surfaces.push({
|
|
160
|
+
label: `${schema.name}.${name}`,
|
|
161
|
+
permission: methods[name].permission,
|
|
162
|
+
resolverWired,
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
for (const ws of this._registeredWebSocketSchemas) {
|
|
167
|
+
const resolverWired = this._schemasWithResolver.has(ws);
|
|
168
|
+
const methods = ws.contract.clientToServer.methods;
|
|
169
|
+
for (const name of Object.keys(methods)) {
|
|
170
|
+
surfaces.push({
|
|
171
|
+
label: `${ws.name}.${name}`,
|
|
172
|
+
permission: methods[name].permission,
|
|
173
|
+
resolverWired,
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
if (ws.connectPermission !== undefined) {
|
|
177
|
+
surfaces.push({
|
|
178
|
+
label: `${ws.name} (connectPermission)`,
|
|
179
|
+
permission: ws.connectPermission,
|
|
180
|
+
resolverWired,
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
let strict = false;
|
|
185
|
+
const undeclared = [];
|
|
186
|
+
const orphaned = [];
|
|
187
|
+
for (const s of surfaces) {
|
|
188
|
+
if (s.permission !== undefined || s.resolverWired)
|
|
189
|
+
strict = true;
|
|
190
|
+
if (s.permission === undefined)
|
|
191
|
+
undeclared.push(s);
|
|
192
|
+
else if (s.permission !== GG_NO_PERMISSIONS && !s.resolverWired)
|
|
193
|
+
orphaned.push(s);
|
|
194
|
+
}
|
|
195
|
+
if (!strict)
|
|
196
|
+
return;
|
|
197
|
+
if (undeclared.length > 0) {
|
|
198
|
+
const lines = undeclared.map(s => ` ${s.label}`).join("\n");
|
|
199
|
+
throw new Error(`GGHttpServer: permission strict mode is active on this server ` +
|
|
200
|
+
`(at least one route declares a permission or has .usePermissions(...) wired), ` +
|
|
201
|
+
`but the following routes have no \`permission\` declared:\n\n` +
|
|
202
|
+
lines +
|
|
203
|
+
`\n\nFix: declare \`permission\` on every route — use \`GG_NO_PERMISSIONS\` for intentionally public ones.`);
|
|
204
|
+
}
|
|
205
|
+
if (orphaned.length > 0) {
|
|
206
|
+
const lines = orphaned.map(s => ` ${s.label} requires ${describePermission(s.permission)}`).join("\n");
|
|
207
|
+
throw new Error(`GGHttpServer: these routes declare non-public permissions but their schema was ` +
|
|
208
|
+
`registered without a scope resolver:\n\n` +
|
|
209
|
+
lines +
|
|
210
|
+
`\n\nFix: call \`.usePermissions(yourResolver)\` on the GGHttp chain (or pass ` +
|
|
211
|
+
`\`permissionResolver\` to the WS schema config) before registering these routes.`);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
147
214
|
registerRoute(method, path, handler) {
|
|
148
215
|
this.router.on(method, path, handler);
|
|
149
216
|
}
|
|
150
217
|
async start() {
|
|
151
218
|
Object.freeze(this._registeredSchemas);
|
|
219
|
+
this._checkPermissionsAtStart();
|
|
152
220
|
this._port = await new Promise((resolve) => {
|
|
153
221
|
this.httpServer.listen(this.configuredPort, '0.0.0.0', () => {
|
|
154
222
|
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,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AC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { GGContextKey } from "@grest-ts/context";
|
|
2
|
+
import { GGPermissionChecker } from "@grest-ts/schema";
|
|
3
|
+
/**
|
|
4
|
+
* Per-request permission context populated by the gate when a scope resolver
|
|
5
|
+
* is wired via GGHttp.usePermissions(...). Handler code can read it to make
|
|
6
|
+
* sub-decisions inside an authorized method:
|
|
7
|
+
*
|
|
8
|
+
* const perm = GG_PERMISSIONS.get();
|
|
9
|
+
* if (perm.has(AppPermission.Admin)) { ... }
|
|
10
|
+
*
|
|
11
|
+
* The checker uses the same satisfies() the framework gate uses — no parallel
|
|
12
|
+
* implementations.
|
|
13
|
+
*/
|
|
14
|
+
export declare const GG_PERMISSIONS: GGContextKey<GGPermissionChecker>;
|
|
15
|
+
//# sourceMappingURL=GG_PERMISSIONS.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GG_PERMISSIONS.d.ts","sourceRoot":"","sources":["../../../src/server/GG_PERMISSIONS.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAC,mBAAmB,EAAQ,MAAM,kBAAkB,CAAC;AAE5D;;;;;;;;;;GAUG;AACH,eAAO,MAAM,cAAc,mCAAqE,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { GGContextKey } from "@grest-ts/context";
|
|
2
|
+
import { IsAny } from "@grest-ts/schema";
|
|
3
|
+
/**
|
|
4
|
+
* Per-request permission context populated by the gate when a scope resolver
|
|
5
|
+
* is wired via GGHttp.usePermissions(...). Handler code can read it to make
|
|
6
|
+
* sub-decisions inside an authorized method:
|
|
7
|
+
*
|
|
8
|
+
* const perm = GG_PERMISSIONS.get();
|
|
9
|
+
* if (perm.has(AppPermission.Admin)) { ... }
|
|
10
|
+
*
|
|
11
|
+
* The checker uses the same satisfies() the framework gate uses — no parallel
|
|
12
|
+
* implementations.
|
|
13
|
+
*/
|
|
14
|
+
export const GG_PERMISSIONS = new GGContextKey("permissions", IsAny);
|
|
15
|
+
//# sourceMappingURL=GG_PERMISSIONS.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GG_PERMISSIONS.js","sourceRoot":"","sources":["../../../src/server/GG_PERMISSIONS.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAsB,KAAK,EAAC,MAAM,kBAAkB,CAAC;AAE5D;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,YAAY,CAAsB,aAAa,EAAE,KAAY,CAAC,CAAC"}
|