@grest-ts/http 0.0.48 → 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.
Files changed (127) hide show
  1. package/README.md +243 -175
  2. package/dist/src/_dedupCheck.js +1 -1
  3. package/dist/src/client/GGContextKeySynchronizer.d.ts +11 -0
  4. package/dist/src/client/GGContextKeySynchronizer.d.ts.map +1 -0
  5. package/dist/src/client/GGContextKeySynchronizer.js +26 -0
  6. package/dist/src/client/GGContextKeySynchronizer.js.map +1 -0
  7. package/dist/src/index-browser.d.ts +4 -2
  8. package/dist/src/index-browser.d.ts.map +1 -1
  9. package/dist/src/index-browser.js +4 -2
  10. package/dist/src/index-browser.js.map +1 -1
  11. package/dist/src/index-node.d.ts +8 -3
  12. package/dist/src/index-node.d.ts.map +1 -1
  13. package/dist/src/index-node.js +16 -7
  14. package/dist/src/index-node.js.map +1 -1
  15. package/dist/src/rpc/RpcRequest/GGRpcRequestBuilder.d.ts +4 -3
  16. package/dist/src/rpc/RpcRequest/GGRpcRequestBuilder.d.ts.map +1 -1
  17. package/dist/src/rpc/RpcRequest/GGRpcRequestBuilder.js +9 -2
  18. package/dist/src/rpc/RpcRequest/GGRpcRequestBuilder.js.map +1 -1
  19. package/dist/src/rpc/RpcRequest/GGRpcRequestParser.d.ts +3 -3
  20. package/dist/src/rpc/RpcRequest/GGRpcRequestParser.d.ts.map +1 -1
  21. package/dist/src/rpc/RpcRequest/GGRpcRequestParser.js +13 -16
  22. package/dist/src/rpc/RpcRequest/GGRpcRequestParser.js.map +1 -1
  23. package/dist/src/rpc/RpcResponse/GGRpcResponseBuilder.d.ts +1 -1
  24. package/dist/src/rpc/RpcResponse/GGRpcResponseBuilder.d.ts.map +1 -1
  25. package/dist/src/rpc/RpcResponse/GGRpcResponseBuilder.js +3 -3
  26. package/dist/src/rpc/RpcResponse/GGRpcResponseBuilder.js.map +1 -1
  27. package/dist/src/schema/GGCookie.d.ts +50 -0
  28. package/dist/src/schema/GGCookie.d.ts.map +1 -0
  29. package/dist/src/schema/GGCookie.js +130 -0
  30. package/dist/src/schema/GGCookie.js.map +1 -0
  31. package/dist/src/schema/GGHeader.d.ts +23 -0
  32. package/dist/src/schema/GGHeader.d.ts.map +1 -0
  33. package/dist/src/schema/GGHeader.js +41 -0
  34. package/dist/src/schema/GGHeader.js.map +1 -0
  35. package/dist/src/schema/GGHttpPermissionsChecker.d.ts +9 -0
  36. package/dist/src/schema/GGHttpPermissionsChecker.d.ts.map +1 -0
  37. package/dist/src/schema/GGHttpPermissionsChecker.js +29 -0
  38. package/dist/src/schema/GGHttpPermissionsChecker.js.map +1 -0
  39. package/dist/src/schema/GGHttpSchema.d.ts +8 -59
  40. package/dist/src/schema/GGHttpSchema.d.ts.map +1 -1
  41. package/dist/src/schema/GGHttpSchema.js.map +1 -1
  42. package/dist/src/schema/GGWireContextKey.d.ts +30 -0
  43. package/dist/src/schema/GGWireContextKey.d.ts.map +1 -0
  44. package/dist/src/schema/GGWireContextKey.js +36 -0
  45. package/dist/src/schema/GGWireContextKey.js.map +1 -0
  46. package/dist/src/schema/GGWireContextKey.node.d.ts +36 -0
  47. package/dist/src/schema/GGWireContextKey.node.d.ts.map +1 -0
  48. package/dist/src/schema/GGWireContextKey.node.js +83 -0
  49. package/dist/src/schema/GGWireContextKey.node.js.map +1 -0
  50. package/dist/src/schema/httpSchema.d.ts +2 -2
  51. package/dist/src/schema/httpSchema.d.ts.map +1 -1
  52. package/dist/src/schema/httpSchema.js.map +1 -1
  53. package/dist/src/server/GGHttp.d.ts +2 -26
  54. package/dist/src/server/GGHttp.d.ts.map +1 -1
  55. package/dist/src/server/GGHttp.js +0 -15
  56. package/dist/src/server/GGHttp.js.map +1 -1
  57. package/dist/src/server/GGHttpSchema.startServer.d.ts +2 -11
  58. package/dist/src/server/GGHttpSchema.startServer.d.ts.map +1 -1
  59. package/dist/src/server/GGHttpSchema.startServer.js +11 -28
  60. package/dist/src/server/GGHttpSchema.startServer.js.map +1 -1
  61. package/dist/src/server/GGHttpServer.d.ts +16 -14
  62. package/dist/src/server/GGHttpServer.d.ts.map +1 -1
  63. package/dist/src/server/GGHttpServer.js +26 -79
  64. package/dist/src/server/GGHttpServer.js.map +1 -1
  65. package/dist/src/server/applyRequestMiddleware.d.ts +11 -0
  66. package/dist/src/server/applyRequestMiddleware.d.ts.map +1 -0
  67. package/dist/src/server/applyRequestMiddleware.js +38 -0
  68. package/dist/src/server/applyRequestMiddleware.js.map +1 -0
  69. package/dist/src/server/applyResponseMiddleware.d.ts +2 -2
  70. package/dist/src/server/applyResponseMiddleware.d.ts.map +1 -1
  71. package/dist/src/server/applyResponseMiddleware.js +2 -2
  72. package/dist/src/server/applyResponseMiddleware.js.map +1 -1
  73. package/dist/src/server/checkers/checkPermissionsAtStart.d.ts +39 -0
  74. package/dist/src/server/checkers/checkPermissionsAtStart.d.ts.map +1 -0
  75. package/dist/src/server/checkers/checkPermissionsAtStart.js +82 -0
  76. package/dist/src/server/checkers/checkPermissionsAtStart.js.map +1 -0
  77. package/dist/src/server/checkers/checkWireConflicts.d.ts +18 -0
  78. package/dist/src/server/checkers/checkWireConflicts.d.ts.map +1 -0
  79. package/dist/src/server/checkers/checkWireConflicts.js +43 -0
  80. package/dist/src/server/checkers/checkWireConflicts.js.map +1 -0
  81. package/dist/src/server/checkers/checkWiresImplemented.d.ts +11 -0
  82. package/dist/src/server/checkers/checkWiresImplemented.d.ts.map +1 -0
  83. package/dist/src/server/checkers/checkWiresImplemented.js +27 -0
  84. package/dist/src/server/checkers/checkWiresImplemented.js.map +1 -0
  85. package/dist/src/tsconfig.json +2 -1
  86. package/dist/tsconfig.publish.tsbuildinfo +1 -1
  87. package/package.json +14 -11
  88. package/src/_dedupCheck.ts +1 -1
  89. package/src/client/GGContextKeySynchronizer.test.ts +106 -0
  90. package/src/client/GGContextKeySynchronizer.ts +42 -0
  91. package/src/index-browser.ts +4 -2
  92. package/src/index-node.ts +17 -7
  93. package/src/rpc/RpcRequest/GGRpcRequestBuilder.ts +11 -4
  94. package/src/rpc/RpcRequest/GGRpcRequestParser.ts +16 -17
  95. package/src/rpc/RpcResponse/GGRpcResponseBuilder.ts +5 -4
  96. package/src/schema/GGCookie.ts +151 -0
  97. package/src/schema/GGHeader.ts +48 -0
  98. package/src/schema/GGHttpPermissionsChecker.test.ts +125 -0
  99. package/src/schema/GGHttpPermissionsChecker.ts +35 -0
  100. package/src/schema/GGHttpSchema.ts +8 -71
  101. package/src/schema/GGWireContextKey.node.ts +119 -0
  102. package/src/schema/GGWireContextKey.ts +46 -0
  103. package/src/schema/httpSchema.ts +3 -3
  104. package/src/server/GGHttp.ts +3 -34
  105. package/src/server/GGHttpSchema.startServer.ts +13 -38
  106. package/src/server/GGHttpServer.ts +33 -89
  107. package/src/server/applyRequestMiddleware.ts +40 -0
  108. package/src/server/applyResponseMiddleware.ts +5 -5
  109. package/src/server/checkers/checkPermissionsAtStart.ts +112 -0
  110. package/src/server/checkers/checkWireConflicts.ts +65 -0
  111. package/src/server/checkers/checkWiresImplemented.ts +42 -0
  112. package/src/tsconfig.json +2 -1
  113. package/dist/src/schema/cookieMiddleware.d.ts +0 -71
  114. package/dist/src/schema/cookieMiddleware.d.ts.map +0 -1
  115. package/dist/src/schema/cookieMiddleware.js +0 -126
  116. package/dist/src/schema/cookieMiddleware.js.map +0 -1
  117. package/dist/src/schema/headerBinding.d.ts +0 -35
  118. package/dist/src/schema/headerBinding.d.ts.map +0 -1
  119. package/dist/src/schema/headerBinding.js +0 -49
  120. package/dist/src/schema/headerBinding.js.map +0 -1
  121. package/dist/src/server/GG_PERMISSIONS.d.ts +0 -15
  122. package/dist/src/server/GG_PERMISSIONS.d.ts.map +0 -1
  123. package/dist/src/server/GG_PERMISSIONS.js +0 -15
  124. package/dist/src/server/GG_PERMISSIONS.js.map +0 -1
  125. package/src/schema/cookieMiddleware.ts +0 -164
  126. package/src/schema/headerBinding.ts +0 -65
  127. package/src/server/GG_PERMISSIONS.ts +0 -15
@@ -0,0 +1,23 @@
1
+ import { type GGInbound, type GGOutbound } from "@grest-ts/context";
2
+ import { type GGSchema } from "@grest-ts/schema";
3
+ import { GGWireContextKey } from "./GGWireContextKey";
4
+ /**
5
+ * A request header that IS its own context key.
6
+ *
7
+ * // verified: requires .define() server-side; raw credential is ephemeral.
8
+ * const USER_TOKEN_WIRE = new GGHeader("authorization", {scheme: "bearer"})
9
+ *
10
+ * // ambient: parsed value lands in the wire and persists, no implementation needed.
11
+ * const CLIENT_VERSION_WIRE = new GGHeader("x-client-version")
12
+ */
13
+ export declare class GGHeader extends GGWireContextKey {
14
+ readonly headers: Record<string, GGSchema<string | undefined>>;
15
+ private readonly scheme?;
16
+ private readonly wireName;
17
+ constructor(name: string, options?: {
18
+ scheme?: "bearer";
19
+ });
20
+ parse(inbound: GGInbound): void;
21
+ update(outbound: GGOutbound): void;
22
+ }
23
+ //# sourceMappingURL=GGHeader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GGHeader.d.ts","sourceRoot":"","sources":["../../../src/schema/GGHeader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,SAAS,EAAE,KAAK,UAAU,EAAC,MAAM,mBAAmB,CAAA;AACjE,OAAO,EAAC,KAAK,QAAQ,EAAW,MAAM,kBAAkB,CAAA;AACxD,OAAO,EAAC,gBAAgB,EAAC,MAAM,oBAAoB,CAAA;AAKnD;;;;;;;;GAQG;AACH,qBAAa,QAAS,SAAQ,gBAAgB;IAE1C,SAAgB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC,CAAA;IACrE,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAU;IAClC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAQ;gBAErB,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,QAAQ,CAAA;KAAE;IAQlD,KAAK,CAAC,OAAO,EAAE,SAAS,GAAG,IAAI;IAW/B,MAAM,CAAC,QAAQ,EAAE,UAAU,GAAG,IAAI;CAM5C"}
@@ -0,0 +1,41 @@
1
+ import { IsString } from "@grest-ts/schema";
2
+ import { GGWireContextKey } from "./GGWireContextKey.js";
3
+ const BEARER = "Bearer ";
4
+ /**
5
+ * A request header that IS its own context key.
6
+ *
7
+ * // verified: requires .define() server-side; raw credential is ephemeral.
8
+ * const USER_TOKEN_WIRE = new GGHeader("authorization", {scheme: "bearer"})
9
+ *
10
+ * // ambient: parsed value lands in the wire and persists, no implementation needed.
11
+ * const CLIENT_VERSION_WIRE = new GGHeader("x-client-version")
12
+ */
13
+ export class GGHeader extends GGWireContextKey {
14
+ headers;
15
+ scheme;
16
+ wireName;
17
+ constructor(name, options) {
18
+ const WIRE_SCHEMA = IsString.orUndefined;
19
+ super(name, WIRE_SCHEMA);
20
+ this.scheme = options?.scheme;
21
+ this.wireName = name.toLowerCase();
22
+ this.headers = { [this.wireName]: WIRE_SCHEMA };
23
+ }
24
+ parse(inbound) {
25
+ const raw = inbound.headers[this.wireName];
26
+ if (raw === undefined) {
27
+ return undefined;
28
+ }
29
+ const value = this.scheme === "bearer" && raw.startsWith(BEARER) ? raw.slice(BEARER.length) : raw;
30
+ if (value !== undefined) {
31
+ this.set(value);
32
+ }
33
+ }
34
+ update(outbound) {
35
+ const value = this.get();
36
+ if (value !== undefined) {
37
+ outbound.headers[this.wireName] = (this.scheme === "bearer" ? `${BEARER}${value}` : value);
38
+ }
39
+ }
40
+ }
41
+ //# sourceMappingURL=GGHeader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GGHeader.js","sourceRoot":"","sources":["../../../src/schema/GGHeader.ts"],"names":[],"mappings":"AACA,OAAO,EAAgB,QAAQ,EAAC,MAAM,kBAAkB,CAAA;AACxD,OAAO,EAAC,gBAAgB,EAAC,MAAM,oBAAoB,CAAA;AAEnD,MAAM,MAAM,GAAG,SAAS,CAAA;AAGxB;;;;;;;;GAQG;AACH,MA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CAAA;QAC9F,CAAC;IACL,CAAC;CACJ"}
@@ -0,0 +1,9 @@
1
+ import type { GGTransportMiddleware } from "@grest-ts/context";
2
+ import { GGPermission } from "@grest-ts/schema";
3
+ export declare class GGHttpPermissionsChecker {
4
+ private readonly middlewaresWithPermissions;
5
+ constructor(apiMiddlewares: readonly GGTransportMiddleware[]);
6
+ assert(schema: string, method: string, required: GGPermission): Promise<ReadonlyArray<ReadonlyArray<string>>>;
7
+ assertGrants(schema: string, method: string, granted: undefined | ReadonlyArray<ReadonlyArray<string>>, required: GGPermission): void;
8
+ }
9
+ //# sourceMappingURL=GGHttpPermissionsChecker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GGHttpPermissionsChecker.d.ts","sourceRoot":"","sources":["../../../src/schema/GGHttpPermissionsChecker.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,qBAAqB,EAAC,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAY,YAAY,EAAsB,MAAM,kBAAkB,CAAC;AAE9E,qBAAa,wBAAwB;IAEjC,OAAO,CAAC,QAAQ,CAAC,0BAA0B,CAAyB;gBAExD,cAAc,EAAE,SAAS,qBAAqB,EAAE;IAS/C,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,YAAY,GAAG,OAAO,CAAC,aAAa,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC;IASnH,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,GAAG,aAAa,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,EAAE,QAAQ,EAAE,YAAY,GAAG,IAAI;CAQ/I"}
@@ -0,0 +1,29 @@
1
+ import { GGWireContextKey } from "./GGWireContextKey.js";
2
+ import { FORBIDDEN, GGPermissionChecker } from "@grest-ts/schema";
3
+ export class GGHttpPermissionsChecker {
4
+ middlewaresWithPermissions = [];
5
+ constructor(apiMiddlewares) {
6
+ for (const mw of apiMiddlewares) {
7
+ if (mw instanceof GGWireContextKey && mw.hasPermissions()) {
8
+ this.middlewaresWithPermissions.push(mw);
9
+ }
10
+ }
11
+ Object.freeze(this.middlewaresWithPermissions);
12
+ }
13
+ async assert(schema, method, required) {
14
+ const scopes = [];
15
+ for (let i = 0; i < this.middlewaresWithPermissions.length; i++) {
16
+ scopes.push(await this.middlewaresWithPermissions[i].getGrantedPermissions());
17
+ }
18
+ this.assertGrants(schema, method, scopes, required);
19
+ return Object.freeze(scopes);
20
+ }
21
+ assertGrants(schema, method, granted, required) {
22
+ if (!GGPermissionChecker.satisfies(required, granted)) {
23
+ throw new FORBIDDEN({
24
+ debugMessage: `${schema + (method ? "." + method : "")} requires ${GGPermissionChecker.describePermission(required)} — caller scopes did not satisfy`
25
+ });
26
+ }
27
+ }
28
+ }
29
+ //# sourceMappingURL=GGHttpPermissionsChecker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GGHttpPermissionsChecker.js","sourceRoot":"","sources":["../../../src/schema/GGHttpPermissionsChecker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,gBAAgB,EAAC,MAAM,oBAAoB,CAAC;AAEpD,OAAO,EAAC,SAAS,EAAgB,mBAAmB,EAAC,MAAM,kBAAkB,CAAC;AAE9E,MAAM,OAAO,wBAAwB;IAEhB,0BAA0B,GAAuB,EAAE,CAAA;IAEpE,YAAY,cAAgD;QACxD,KAAK,MAAM,EAAE,IAAI,cAAc,EAAE,CAAC;YAC9B,IAAI,EAAE,YAAY,gBAAgB,IAAI,EAAE,CAAC,cAAc,EAAE,EAAE,CAAC;gBACxD,IAAI,CAAC,0BAA0B,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YAC7C,CAAC;QACL,CAAC;QACD,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,0BAA0B,CAAC,CAAA;IAClD,CAAC;IAEM,KAAK,CAAC,MAAM,CAAC,MAAc,EAAE,MAAc,EAAE,QAAsB;QACtE,MAAM,MAAM,GAA6B,EAAE,CAAC;QAC5C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,0BAA0B,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YAC9D,MAAM,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC,0BAA0B,CAAC,CAAC,CAAC,CAAC,qBAAqB,EAAE,CAAC,CAAA;QACjF,CAAC;QACD,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAA;QACnD,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAwB,CAAA;IACvD,CAAC;IAEM,YAAY,CAAC,MAAc,EAAE,MAAc,EAAE,OAAyD,EAAE,QAAsB;QACjI,IAAI,CAAC,mBAAmB,CAAC,SAAS,CAAC,QAAQ,EAAE,OAAO,CAAC,EAAE,CAAC;YACpD,MAAM,IAAI,SAAS,CAAC;gBAChB,YAAY,EAAE,GAAG,MAAM,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,GAAG,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,aAAa,mBAAmB,CAAC,kBAAkB,CAAC,QAAQ,CAAC,kCAAkC;aACxJ,CAAC,CAAA;QACN,CAAC;IACL,CAAC;CAEJ"}
@@ -1,21 +1,20 @@
1
1
  import { ERROR, ERROR_JSON, GGContractApiDefinition, GGContractClass, GGContractMethod, GGSchema, GGSchemaDescription, OK } from "@grest-ts/schema";
2
2
  import type { HttpMethod } from "@grest-ts/common";
3
3
  import type http from "http";
4
- import type { GGHttpServerMiddleware } from "../server/GGHttpSchema.startServer";
5
- import type { GGContextKey } from "@grest-ts/context";
4
+ import type { GGContextKey, GGTransportMiddleware } from "@grest-ts/context";
6
5
  import type { OpenAPIV3_1 } from "openapi-types";
7
6
  export declare class GGHttpSchema<TContract extends GGContractApiDefinition, TContext> {
8
7
  readonly name: string;
9
8
  readonly pathPrefix: string;
10
- readonly apiMiddlewares: readonly GGHttpTransportMiddleware[];
9
+ readonly apiMiddlewares: readonly GGTransportMiddleware[];
11
10
  readonly codec: Record<keyof TContract, GGHttpCodec>;
12
11
  readonly contract: GGContractClass<TContract> | null;
13
- constructor(pathPrefix: string, contract: GGContractClass<TContract>, wireCodec: Record<keyof TContract, GGHttpCodec>, middlewares?: readonly GGHttpTransportMiddleware[]);
12
+ constructor(pathPrefix: string, contract: GGContractClass<TContract>, wireCodec: Record<keyof TContract, GGHttpCodec>, middlewares?: readonly GGTransportMiddleware[]);
14
13
  }
15
14
  export interface ClientHttpRouteToRpcTransformClientConfig {
16
15
  pathPrefix: string;
17
16
  contract: GGContractMethod;
18
- middlewares: readonly GGHttpTransportMiddleware[];
17
+ middlewares: readonly GGTransportMiddleware[];
19
18
  }
20
19
  export interface ClientHttpRouteToRpcTransformClientCodec {
21
20
  createRequest: (data: unknown) => GGHttpFetchRequest | Promise<GGHttpFetchRequest>;
@@ -29,11 +28,12 @@ export interface GGHttpFetchRequest {
29
28
  }
30
29
  export interface ClientHttpRouteToRpcTransformServerConfig {
31
30
  contract: GGContractMethod;
32
- apiMiddlewares: readonly GGHttpTransportMiddleware[];
33
- serverMiddlewares: readonly GGHttpServerMiddleware[];
31
+ /** Schema bindings + server middlewares, already merged into one ordered server pipeline. */
32
+ middlewares: readonly GGTransportMiddleware[];
34
33
  }
35
34
  export interface ClientHttpRouteToRpcTransformServerCodec {
36
- parseRequest: (req: http.IncomingMessage) => Promise<unknown>;
35
+ readRequest: (req: http.IncomingMessage) => Promise<unknown>;
36
+ validateInput: (rawInput: unknown) => unknown;
37
37
  sendResponse: (res: http.ServerResponse, rpcResult: ERROR<string, unknown> | OK<unknown>) => Promise<void>;
38
38
  }
39
39
  /**
@@ -92,55 +92,4 @@ export interface GGHttpCodec {
92
92
  */
93
93
  toOpenApiOperation?(config: GGHttpCodecOpenApiConfig): Partial<OpenAPIV3_1.OperationObject>;
94
94
  }
95
- export interface GGHttpTransportMiddleware {
96
- /**
97
- * Request headers this middleware reads or writes, mapped to their value schemas.
98
- * Keys are header names; values describe the header value format for validation and docs.
99
- * Used for CORS Access-Control-Allow-Headers and OpenAPI parameter docs.
100
- * Use {} if the middleware touches no custom request headers.
101
- *
102
- * @example
103
- * headers: {
104
- * "authorization": IsString.nonEmpty.docs({title: "Bearer token", example: "Bearer ..."}),
105
- * "accept-language": IsLocale.orUndefined
106
- * }
107
- */
108
- readonly headers: Record<string, GGSchema<string | undefined>>;
109
- /**
110
- * Response headers this middleware sets, mapped to their value schemas.
111
- * Keys are header names; values describe the header value format for validation and docs.
112
- * Used for CORS Access-Control-Expose-Headers and OpenAPI response header docs.
113
- * Use {} if the middleware sets no custom response headers.
114
- */
115
- readonly responseHeaders: Record<string, GGSchema<string | undefined>>;
116
- /**
117
- * Cookies this middleware reads, mapped to their value schemas. Emitted as `in: cookie`
118
- * parameters in OpenAPI so cookie-bound inputs are documented. Absent for header/plain
119
- * middlewares.
120
- */
121
- readonly cookieParams?: Record<string, GGSchema<string | undefined>>;
122
- /**
123
- * Client-side: modify outgoing request (add headers, etc.)
124
- */
125
- updateRequest?(req: GGHttpRequest): void;
126
- /**
127
- * Server-side: parse incoming request (extract context from headers, etc.)
128
- */
129
- parseRequest?(req: GGHttpRequest): void;
130
- /**
131
- * Server-side: modify outgoing response
132
- */
133
- updateResponse?(res: GGHttpResponse): void;
134
- /**
135
- * Client-side: parse incoming response
136
- */
137
- parseResponse?(res: GGHttpResponse): void;
138
- }
139
- export interface GGHttpRequest {
140
- headers?: Record<string, string | string[]>;
141
- queryArgs?: Record<string, string | string[]>;
142
- }
143
- export interface GGHttpResponse {
144
- headers: Record<string, string | string[]>;
145
- }
146
95
  //# sourceMappingURL=GGHttpSchema.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"GGHttpSchema.d.ts","sourceRoot":"","sources":["../../../src/schema/GGHttpSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAE,UAAU,EAAE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AI,CAAC,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAA;QACzB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;QAC5B,IAAI,CAAC,cAAc,GAAG,WAAW,CAAA;QACjC,IAAI,CAAC,KAAK,GAAG,SAAS,CAAA;QACtB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;QACxB,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAA;QAClC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;QACzB,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IACvB,CAAC;CACJ"}
1
+ {"version":3,"file":"GGHttpSchema.js","sourceRoot":"","sources":["../../../src/schema/GGHttpSchema.ts"],"names":[],"mappings":"AAMA,MAAM,OAAO,YAAY;IAEL,IAAI,CAAQ;IACZ,UAAU,CAAQ;IAClB,cAAc,CAAkC;IAChD,KAAK,CAAsC;IAC3C,QAAQ,GAAsC,IAAI,CAAA;IAElE,YACI,UAAkB,EAClB,QAAoC,EACpC,SAA+C,EAC/C,cAAgD,EAAE;QAElD,IAAI,CAAC,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAA;QACzB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;QAC5B,IAAI,CAAC,cAAc,GAAG,WAAW,CAAA;QACjC,IAAI,CAAC,KAAK,GAAG,SAAS,CAAA;QACtB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;QACxB,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAA;QAClC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;QACzB,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IACvB,CAAC;CACJ"}
@@ -0,0 +1,30 @@
1
+ import { GGContextKey, type GGTransportMiddleware } from "@grest-ts/context";
2
+ /** Outbound freshness gate for a smart wire. The outbound value is always the wire's own context value. */
3
+ export interface GGWireClientHandler {
4
+ /** Async — true when the wire value is stale and recover() should run before the next outbound read. */
5
+ isStale?: () => boolean;
6
+ /** Async — refresh the credential into the wire (via key.set); run by the synchronizer's waitFor before the outbound read. */
7
+ recover?: () => Promise<void>;
8
+ }
9
+ /**
10
+ * Base for credential wires (GGHeader, GGCookie). A wire IS a GGContextKey and a transport
11
+ * middleware at once. Verified vs ambient is decided by whether `.define()` was called:
12
+ * - verified (`.define()`d): the wire holds the raw inbound credential, which is verified
13
+ * during process(), then clear()d before the handler runs — handlers read the durable key
14
+ * minted by the handler, never the credential.
15
+ * - ambient (never `.define()`d): the parsed value lands in the wire and persists through the
16
+ * handler (read via WIRE.get()); no process, no clear, no implementation needed.
17
+ *
18
+ * The server/inbound half (define/create/process/permissions) is attached node-side via
19
+ * ./GGWireContextKey.node — the browser bundle never pulls @grest-ts/locator.
20
+ */
21
+ export declare abstract class GGWireContextKey extends GGContextKey<string | undefined> implements GGTransportMiddleware {
22
+ private _clientHandler?;
23
+ /**
24
+ * Attach the outbound freshness gate. Freeze-once. The outbound value is always the wire's
25
+ * context value; this only registers an isStale/recover gate that refreshes it before the read.
26
+ * GGAuthSession calls it internally on the wires it holds.
27
+ */
28
+ defineClient(handler: GGWireClientHandler): void;
29
+ }
30
+ //# sourceMappingURL=GGWireContextKey.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GGWireContextKey.d.ts","sourceRoot":"","sources":["../../../src/schema/GGWireContextKey.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAE,KAAK,qBAAqB,EAAC,MAAM,mBAAmB,CAAA;AAG1E,2GAA2G;AAC3G,MAAM,WAAW,mBAAmB;IAChC,wGAAwG;IACxG,OAAO,CAAC,EAAE,MAAM,OAAO,CAAA;IACvB,8HAA8H;IAC9H,OAAO,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CAChC;AAED;;;;;;;;;;;GAWG;AACH,8BAAsB,gBAAiB,SAAQ,YAAY,CAAC,MAAM,GAAG,SAAS,CAAE,YAAW,qBAAqB;IAE5G,OAAO,CAAC,cAAc,CAAC,CAAqB;IAE5C;;;;OAIG;IACI,YAAY,CAAC,OAAO,EAAE,mBAAmB,GAAG,IAAI;CAa1D"}
@@ -0,0 +1,36 @@
1
+ import { GGContextKey } from "@grest-ts/context";
2
+ import { GGContextKeySynchronizer } from "../client/GGContextKeySynchronizer.js";
3
+ /**
4
+ * Base for credential wires (GGHeader, GGCookie). A wire IS a GGContextKey and a transport
5
+ * middleware at once. Verified vs ambient is decided by whether `.define()` was called:
6
+ * - verified (`.define()`d): the wire holds the raw inbound credential, which is verified
7
+ * during process(), then clear()d before the handler runs — handlers read the durable key
8
+ * minted by the handler, never the credential.
9
+ * - ambient (never `.define()`d): the parsed value lands in the wire and persists through the
10
+ * handler (read via WIRE.get()); no process, no clear, no implementation needed.
11
+ *
12
+ * The server/inbound half (define/create/process/permissions) is attached node-side via
13
+ * ./GGWireContextKey.node — the browser bundle never pulls @grest-ts/locator.
14
+ */
15
+ export class GGWireContextKey extends GGContextKey {
16
+ _clientHandler;
17
+ /**
18
+ * Attach the outbound freshness gate. Freeze-once. The outbound value is always the wire's
19
+ * context value; this only registers an isStale/recover gate that refreshes it before the read.
20
+ * GGAuthSession calls it internally on the wires it holds.
21
+ */
22
+ defineClient(handler) {
23
+ if (this._clientHandler) {
24
+ throw new Error(`Wire "${this.name}" already has .defineClient() — it can only be defined once.`);
25
+ }
26
+ this._clientHandler = handler;
27
+ if (handler.isStale || handler.recover) {
28
+ GGContextKeySynchronizer.provide(this, {
29
+ isStale: handler.isStale ?? (() => false),
30
+ recover: handler.recover ?? (async () => {
31
+ }),
32
+ });
33
+ }
34
+ }
35
+ }
36
+ //# sourceMappingURL=GGWireContextKey.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GGWireContextKey.js","sourceRoot":"","sources":["../../../src/schema/GGWireContextKey.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAA6B,MAAM,mBAAmB,CAAA;AAC1E,OAAO,EAAC,wBAAwB,EAAC,MAAM,oCAAoC,CAAA;AAU3E;;;;;;;;;;;GAWG;AACH,MAAM,OAAgB,gBAAiB,SAAQ,YAAgC;IAEnE,cAAc,CAAsB;IAE5C;;;;OAIG;IACI,YAAY,CAAC,OAA4B;QAC5C,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;YACtB,MAAM,IAAI,KAAK,CAAC,SAAS,IAAI,CAAC,IAAI,8DAA8D,CAAC,CAAA;QACrG,CAAC;QACD,IAAI,CAAC,cAAc,GAAG,OAAO,CAAA;QAC7B,IAAI,OAAO,CAAC,OAAO,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;YACrC,wBAAwB,CAAC,OAAO,CAAC,IAAI,EAAE;gBACnC,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC;gBACzC,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,CAAC,KAAK,IAAI,EAAE;gBACxC,CAAC,CAAC;aACL,CAAC,CAAA;QACN,CAAC;IACL,CAAC;CACJ"}
@@ -0,0 +1,36 @@
1
+ import { GGWireContextKey } from "./GGWireContextKey";
2
+ export interface GGWireServerHandler {
3
+ /** Verify the raw credential and mint the durable principal. Throws to reject the request. */
4
+ process: () => Promise<void>;
5
+ /** The caller's grants from this wire — read off the durable principal minted in process(). */
6
+ permissions?: () => Promise<readonly string[]>;
7
+ }
8
+ /** True once .define() has run on this wire — distinguishes verified wires from ambient ones. */
9
+ export declare function wireIsDefined(wire: GGWireContextKey): boolean;
10
+ /**
11
+ * Binds the verification handler's deps into one runtime's locator scope. Returned by
12
+ * `.define()`; `.create(deps)` runs once per scope (a fresh worker / restart gets its own).
13
+ */
14
+ export declare class GGWireHandlerRegistration<Deps> {
15
+ private readonly wire;
16
+ private readonly factory;
17
+ constructor(wire: GGWireContextKey, factory: (deps: Deps) => GGWireServerHandler);
18
+ create(deps: Deps): void;
19
+ }
20
+ declare module "./GGWireContextKey" {
21
+ interface GGWireContextKey {
22
+ /** Attach the server-side verification handler. Process-global, frozen once — a second call throws. */
23
+ define<Deps>(factory: (deps: Deps) => GGWireServerHandler): GGWireHandlerRegistration<Deps>;
24
+ /** @internal server pipeline hook — verify the credential and mint the durable principal. */
25
+ process(): Promise<void>;
26
+ /** @internal If wire is handling permissions **/
27
+ hasPermissions(): boolean;
28
+ /** @internal permission-gate hook — the caller's grants from this wire. */
29
+ getGrantedPermissions(): Promise<readonly string[]>;
30
+ /** @internal startup validation — true once .create() has run on the current runtime scope. */
31
+ hasHandler(): boolean;
32
+ /** Drop the ephemeral raw credential after process(); ambient wires keep their value. */
33
+ clear(): void;
34
+ }
35
+ }
36
+ //# sourceMappingURL=GGWireContextKey.node.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GGWireContextKey.node.d.ts","sourceRoot":"","sources":["../../../src/schema/GGWireContextKey.node.ts"],"names":[],"mappings":"AAMA,OAAO,EAAC,gBAAgB,EAAC,MAAM,oBAAoB,CAAA;AAEnD,MAAM,WAAW,mBAAmB;IAChC,8FAA8F;IAC9F,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;IAC5B,+FAA+F;IAC/F,WAAW,CAAC,EAAE,MAAM,OAAO,CAAC,SAAS,MAAM,EAAE,CAAC,CAAA;CACjD;AAUD,iGAAiG;AACjG,wBAAgB,aAAa,CAAC,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAE7D;AAmBD;;;GAGG;AACH,qBAAa,yBAAyB,CAAC,IAAI;IAEnC,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,OAAO;gBADP,IAAI,EAAE,gBAAgB,EACtB,OAAO,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,mBAAmB;IAI1D,MAAM,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI;CAOlC;AAED,OAAO,QAAQ,oBAAoB,CAAC;IAChC,UAAU,gBAAgB;QACtB,uGAAuG;QACvG,MAAM,CAAC,IAAI,EAAE,OAAO,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,mBAAmB,GAAG,yBAAyB,CAAC,IAAI,CAAC,CAAA;QAE3F,6FAA6F;QAC7F,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;QAExB,iDAAiD;QACjD,cAAc,IAAI,OAAO,CAAC;QAE1B,2EAA2E;QAC3E,qBAAqB,IAAI,OAAO,CAAC,SAAS,MAAM,EAAE,CAAC,CAAA;QAEnD,+FAA+F;QAC/F,UAAU,IAAI,OAAO,CAAA;QAErB,yFAAyF;QACzF,KAAK,IAAI,IAAI,CAAA;KAChB;CACJ"}
@@ -0,0 +1,83 @@
1
+ /**
2
+ * Server/inbound half of the wire model: define/create the verification handler, run it during
3
+ * the request pipeline (process), and expose the caller's grants to the permission gate
4
+ * (permissions). Node-only — keeps @grest-ts/locator out of the browser bundle.
5
+ */
6
+ import { GGLocator, GGLocatorKey } from "@grest-ts/locator";
7
+ import { GGWireContextKey } from "./GGWireContextKey.js";
8
+ const HANDLER_KEYS = new WeakMap();
9
+ const FACTORIES = new WeakMap();
10
+ // Locator keys resolve by their string name, so the handler key must be unique per wire
11
+ // instance — two wires over the same name (e.g. a public ambient cookie and a gated one
12
+ // over the same cookie name) must not share a handler.
13
+ let nextWireHandlerId = 0;
14
+ /** True once .define() has run on this wire — distinguishes verified wires from ambient ones. */
15
+ export function wireIsDefined(wire) {
16
+ return FACTORIES.has(wire);
17
+ }
18
+ function handlerKeyFor(wire) {
19
+ let key = HANDLER_KEYS.get(wire);
20
+ if (!key) {
21
+ key = new GGLocatorKey(`wire:${wire.name}:${nextWireHandlerId++}`);
22
+ HANDLER_KEYS.set(wire, key);
23
+ }
24
+ return key;
25
+ }
26
+ function resolveHandler(wire) {
27
+ const handler = handlerKeyFor(wire).tryGet();
28
+ if (!handler) {
29
+ throw new Error(`Wire "${wire.name}" is used but not implemented — call ${wire.name}.define(...).create(deps) in compose().`);
30
+ }
31
+ return handler;
32
+ }
33
+ /**
34
+ * Binds the verification handler's deps into one runtime's locator scope. Returned by
35
+ * `.define()`; `.create(deps)` runs once per scope (a fresh worker / restart gets its own).
36
+ */
37
+ export class GGWireHandlerRegistration {
38
+ wire;
39
+ factory;
40
+ constructor(wire, factory) {
41
+ this.wire = wire;
42
+ this.factory = factory;
43
+ }
44
+ create(deps) {
45
+ const key = handlerKeyFor(this.wire);
46
+ if (GGLocator.getScope().has(key)) {
47
+ throw new Error(`Wire "${this.wire.name}" was already created in this runtime scope — .create() runs once per runtime.`);
48
+ }
49
+ GGLocator.getScope().set(key, this.factory(deps));
50
+ }
51
+ }
52
+ GGWireContextKey.prototype.define = function (factory) {
53
+ if (FACTORIES.has(this)) {
54
+ throw new Error(`Wire "${this.name}" already has .define() — it can only be defined once.`);
55
+ }
56
+ FACTORIES.set(this, factory);
57
+ return new GGWireHandlerRegistration(this, factory);
58
+ };
59
+ GGWireContextKey.prototype.process = async function () {
60
+ if (!this.hasHandler())
61
+ return;
62
+ await resolveHandler(this).process();
63
+ };
64
+ GGWireContextKey.prototype.hasPermissions = function () {
65
+ if (!this.hasHandler())
66
+ return false;
67
+ const handler = resolveHandler(this);
68
+ return !!handler.permissions;
69
+ };
70
+ GGWireContextKey.prototype.getGrantedPermissions = async function () {
71
+ if (!this.hasHandler())
72
+ return [];
73
+ const handler = resolveHandler(this);
74
+ return handler.permissions ? await handler.permissions() : [];
75
+ };
76
+ GGWireContextKey.prototype.hasHandler = function () {
77
+ return handlerKeyFor(this).has();
78
+ };
79
+ GGWireContextKey.prototype.clear = function () {
80
+ if (this.hasHandler() && this.has())
81
+ this.delete();
82
+ };
83
+ //# sourceMappingURL=GGWireContextKey.node.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GGWireContextKey.node.js","sourceRoot":"","sources":["../../../src/schema/GGWireContextKey.node.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAC,SAAS,EAAE,YAAY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AAG,cAAc,CAAC,IAAI,CAAC,CAAA;IACpC,OAAO,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,MAAM,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAA;AACjE,CAAC,CAAA;AAED,gBAAgB,CAAC,SAAS,CAAC,UAAU,GAAG;IACpC,OAAO,aAAa,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,CAAA;AACpC,CAAC,CAAA;AAED,gBAAgB,CAAC,SAAS,CAAC,KAAK,GAAG;IAC/B,IAAI,IAAI,CAAC,UAAU,EAAE,IAAI,IAAI,CAAC,GAAG,EAAE;QAAE,IAAI,CAAC,MAAM,EAAE,CAAA;AACtD,CAAC,CAAA"}
@@ -1,6 +1,6 @@
1
1
  import { GGHttpCodec, GGHttpSchema } from "./GGHttpSchema";
2
- import { GGHttpTransportMiddleware } from "./GGHttpSchema";
3
2
  import { GGContractApiDefinition, GGContractClass } from "@grest-ts/schema";
3
+ import type { GGTransportMiddleware } from "@grest-ts/context";
4
4
  /**
5
5
  * Create an HTTP API schema builder from a contract.
6
6
  *
@@ -32,7 +32,7 @@ declare class GGHttpSchemaBuilder<TContract extends GGContractApiDefinition, TCo
32
32
  private _middlewares;
33
33
  constructor(contract: GGContractClass<TContract>);
34
34
  pathPrefix(prefix: string): this;
35
- use<M extends GGHttpTransportMiddleware>(middleware: M): GGHttpSchemaBuilder<TContract, TContext | M>;
35
+ use<M extends GGTransportMiddleware>(middleware: M): GGHttpSchemaBuilder<TContract, TContext | M>;
36
36
  routes(mapping: {
37
37
  [K in keyof TContract]: GGHttpCodec;
38
38
  }): GGHttpSchema<TContract, TContext>;
@@ -1 +1 @@
1
- {"version":3,"file":"httpSchema.d.ts","sourceRoot":"","sources":["../../../src/schema/httpSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAE,YAAY,EAAC,MAAM,gBAAgB,CAAC;AACzD,OAAO,EAAC,yBAAyB,EAAC,MAAM,gBAAgB,CA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AAC,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,SAAS,EAAE,OAAO,EAAE,IAAI,CAAC,YAAY,CAAC,CAAA;IACzF,CAAC;CACJ"}
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 { GGHttpServerMiddleware } from "./GGHttpSchema.startServer";
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 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;
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,sBAAsB,EAAC,MAAM,4BAA4B,CAAC;AAClE,OAAO,EAAC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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":"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"}
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?: 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;
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,EAA0D,uBAAuB,EAAE,wBAAwB,EAAqF,MAAM,kBAAkB,CAAC;AAUhO,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,kBAA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