@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.
- package/changelog.md +13 -0
- package/dist/gateway-ent.cjs +17 -17
- package/dist/gateway-ent.cjs.map +2 -2
- package/dist/gateway-ent.js +17 -17
- package/dist/gateway-ent.js.map +2 -2
- package/dist/index.cjs +1346 -611
- package/dist/index.cjs.map +4 -4
- package/dist/index.js +1346 -611
- package/dist/index.js.map +4 -4
- package/dist/web/test.js +1386 -0
- package/dist/web/test.js.map +7 -0
- package/gateway-server.d.ts +2 -4
- package/license.md +5 -0
- package/package.json +7 -3
- package/readme.md +59 -26
- package/types/web/client.d.ts +12 -0
- package/types/web/http.d.ts +38 -26
- package/types/web/server.d.ts +34 -24
- package/types/web/{ws.d.ts → socket.d.ts} +8 -6
- package/types/web/test.d.ts +14 -0
package/types/web/server.d.ts
CHANGED
|
@@ -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 './
|
|
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
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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
|
-
|
|
90
|
-
|
|
91
|
-
readonly
|
|
92
|
-
|
|
93
|
-
readonly
|
|
94
|
-
|
|
95
|
-
|
|
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:
|
|
101
|
-
|
|
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
|
|
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
|
-
|
|
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
|
+
}
|