@interopio/gateway-server 0.7.0-beta → 0.8.0-beta

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.
@@ -1,13 +1,18 @@
1
1
  import type {
2
- HttpCookie,
3
2
  HttpMethod,
3
+ HttpInputMessage,
4
4
  HttpRequest,
5
5
  HttpResponse,
6
+ HttpOutputMessage,
7
+ HttpStatusCode,
6
8
  MutableHttpHeaders,
7
- ReadonlyHttpHeaders
9
+ ReadonlyHttpHeaders,
10
+ ResponseCookie
8
11
  } from './http';
9
- import type {WebSocketHandler} from './ws';
12
+ import type {WebSocketHandler} from './socket';
10
13
  import type {Principal, AuthorizationRule} from '../auth';
14
+ import {AsyncLocalStorage} from 'node:async_hooks';
15
+ import type {AddressInfo} from 'node:net';
11
16
  import {IOGateway} from '@interopio/gateway';
12
17
 
13
18
  export type OriginFilters = {
@@ -60,7 +65,7 @@ export type ServerWebSocketHandler = WebSocketHandler & {
60
65
 
61
66
  export type ServerConfigurerSocketSpec = {
62
67
  path?: string, options?: ServerWebSocketOptions
63
- factory: (server: { endpoint: string }) => Promise<ServerWebSocketHandler>,
68
+ factory: (server: { endpoint: string, storage?: AsyncLocalStorage<{ }> }) => Promise<ServerWebSocketHandler>,
64
69
  }
65
70
 
66
71
  export interface ServerConfigurer {
@@ -74,35 +79,40 @@ export type Middleware<Request extends ServerHttpRequest = ServerHttpRequest, Re
74
79
  export type ServerWebExchange<Request extends ServerHttpRequest = ServerHttpRequest, Response extends ServerHttpResponse = ServerHttpResponse> = {
75
80
  readonly request: Request
76
81
  readonly response: Response;
82
+ attribute<T>(key: string): T | undefined;
77
83
  principal<P extends Principal>(): Promise<P | undefined>;
84
+ readonly logPrefix: string;
78
85
  }
79
86
 
80
- export type ResponseCookie = HttpCookie & {
81
- maxAge: number,
82
- domain?: string,
83
- path?: string,
84
- secure?: boolean,
85
- httpOnly?: boolean,
86
- sameSite?: 'strict' | 'lax' | 'none'
87
+ export interface ServerWebExchangeBuilder<Request extends ServerHttpRequest = ServerHttpRequest, Response extends ServerHttpResponse = ServerHttpResponse> {
88
+ request(request: Request): this
89
+ response(response: Response): this
90
+ principal(principal: () => Promise<Principal>): this
91
+ build(): ServerWebExchange<Request, Response>
87
92
  }
88
93
 
89
- export type ServerHttpRequest = HttpRequest<ReadonlyHttpHeaders> & {
90
- readonly cookies: HttpCookie[]
91
- readonly formData: Promise<URLSearchParams>
92
- // readonly text: Promise<string>
93
- readonly json: Promise<unknown>
94
- // readonly socket: http.IncomingMessage['socket']
95
- // readonly _req: http.IncomingMessage
94
+
95
+ export type ServerHttpRequest = HttpRequest<ReadonlyHttpHeaders> & HttpInputMessage<ReadonlyHttpHeaders> & {
96
+ readonly id: string
97
+ readonly path: string,
98
+ readonly protocol: string
99
+ /**
100
+ * hostname[:port]
101
+ */
102
+ readonly host?: string
103
+
104
+ formData(): Promise<URLSearchParams>
105
+ text(): Promise<string>
106
+ json(): Promise<unknown>
107
+
96
108
  readonly upgrade: boolean
109
+ readonly remoteAddress?: AddressInfo
97
110
  }
98
111
 
99
- export interface ServerHttpResponse extends HttpResponse<MutableHttpHeaders> {
100
- statusCode: number
101
- statusMessage?: string
102
-
103
- readonly cookies: ResponseCookie[]
112
+ export interface ServerHttpResponse extends HttpResponse<MutableHttpHeaders>, HttpOutputMessage<MutableHttpHeaders> {
113
+ readonly statusCode: HttpStatusCode
114
+ setStatusCode(statusCode: HttpStatusCode): boolean
104
115
 
105
116
  addCookie(cookie: ResponseCookie): this
106
117
 
107
- end(chunk?: unknown): Promise<boolean>
108
118
  }
@@ -1,19 +1,21 @@
1
1
  import type {WebSocket} from 'ws';
2
2
  import type {ReadonlyHttpHeaders, HttpCookie} from './http';
3
3
  import type {Principal} from '../auth';
4
+ import type {AddressInfo} from 'node:net';
4
5
 
5
6
  type WebSocketHandshakeInfo = {
6
7
  readonly url: URL;
8
+ readonly protocol?: string;
7
9
 
8
10
  // request headers for server and response headers for client
9
11
  readonly headers: ReadonlyHttpHeaders;
10
12
  readonly cookies: ReadonlyArray<HttpCookie>;
11
13
  principal<P extends Principal>(): Promise<P | undefined>;
12
- readonly protocol?: string;
13
- readonly remoteAddress?: string;
14
- readonly remoteFamily?: string;
15
- readonly remotePort?: number;
14
+ readonly remoteAddress?: AddressInfo;
16
15
  readonly logPrefix?: string;
17
16
  }
18
-
19
- type WebSocketHandler = (socket: WebSocket, handshake: WebSocketHandshakeInfo) => Promise<void>
17
+ type WebSocketSession = {
18
+ socket: WebSocket;
19
+ handshake: WebSocketHandshakeInfo;
20
+ };
21
+ type WebSocketHandler = (session: WebSocketSession) => Promise<void>
@@ -0,0 +1,14 @@
1
+ import {GatewayServer} from '../../gateway-server';
2
+
3
+ export interface TestClient {
4
+ readonly fetch: (input: string | URL, init?: RequestInit) => Promise<Response>;
5
+ }
6
+
7
+ export interface TestClientBuilder {
8
+ build(): Promise<TestClient>;
9
+ }
10
+
11
+
12
+ declare const TestClient: {
13
+ bindToApp(app: GatewayServer.ServerCustomizer): TestClientBuilder
14
+ }