@interopio/gateway-server 0.6.2-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 +28 -0
- package/dist/gateway-ent.cjs +170 -6
- package/dist/gateway-ent.cjs.map +4 -4
- package/dist/gateway-ent.js +176 -6
- package/dist/gateway-ent.js.map +4 -4
- package/dist/index.cjs +2501 -2198
- package/dist/index.cjs.map +4 -4
- package/dist/index.js +2503 -2200
- 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 +7 -47
- package/license.md +5 -0
- package/package.json +15 -5
- package/readme.md +61 -5
- package/types/auth.d.ts +5 -0
- package/types/web/client.d.ts +12 -0
- package/types/web/http.d.ts +76 -0
- package/types/web/server.d.ts +118 -0
- package/types/web/socket.d.ts +21 -0
- package/types/web/test.d.ts +14 -0
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
HttpMethod,
|
|
3
|
+
HttpInputMessage,
|
|
4
|
+
HttpRequest,
|
|
5
|
+
HttpResponse,
|
|
6
|
+
HttpOutputMessage,
|
|
7
|
+
HttpStatusCode,
|
|
8
|
+
MutableHttpHeaders,
|
|
9
|
+
ReadonlyHttpHeaders,
|
|
10
|
+
ResponseCookie
|
|
11
|
+
} from './http';
|
|
12
|
+
import type {WebSocketHandler} from './socket';
|
|
13
|
+
import type {Principal, AuthorizationRule} from '../auth';
|
|
14
|
+
import {AsyncLocalStorage} from 'node:async_hooks';
|
|
15
|
+
import type {AddressInfo} from 'node:net';
|
|
16
|
+
import {IOGateway} from '@interopio/gateway';
|
|
17
|
+
|
|
18
|
+
export type OriginFilters = {
|
|
19
|
+
non_matched?: IOGateway.Filtering.Action
|
|
20
|
+
missing?: IOGateway.Filtering.Action
|
|
21
|
+
block?: IOGateway.Filtering.Matcher[]
|
|
22
|
+
allow?: IOGateway.Filtering.Matcher[]
|
|
23
|
+
/**
|
|
24
|
+
* @deprecated
|
|
25
|
+
* @see block
|
|
26
|
+
*/
|
|
27
|
+
blacklist?: IOGateway.Filtering.Matcher[]
|
|
28
|
+
/**
|
|
29
|
+
* @deprecated
|
|
30
|
+
* @see allow
|
|
31
|
+
*/
|
|
32
|
+
whitelist?: IOGateway.Filtering.Matcher[]
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export type ServerHttpRequestMatcher = { method?: HttpMethod, path: IOGateway.Filtering.Matcher };
|
|
36
|
+
|
|
37
|
+
export type ServerCorsConfig = Readonly<{
|
|
38
|
+
allowOrigin?: '*' | IOGateway.Filtering.Matcher[]
|
|
39
|
+
allowHeaders?: string[]
|
|
40
|
+
allowMethods?: HttpMethod[]
|
|
41
|
+
exposeHeaders?: string[]
|
|
42
|
+
allowCredentials?: boolean
|
|
43
|
+
allowPrivateNetwork?: boolean
|
|
44
|
+
maxAge?: number
|
|
45
|
+
}>;
|
|
46
|
+
|
|
47
|
+
export type ServerExchangeOptions = {
|
|
48
|
+
authorize?: AuthorizationRule,
|
|
49
|
+
cors?: boolean | ServerCorsConfig,
|
|
50
|
+
origins?: OriginFilters,
|
|
51
|
+
}
|
|
52
|
+
export type ServerWebSocketOptions = ServerExchangeOptions & {
|
|
53
|
+
ping?: number,
|
|
54
|
+
maxConnections?: number
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export type ServerConfigurerHandlerSpec<T extends string = string> = {
|
|
58
|
+
request: ServerHttpRequestMatcher, options?: ServerExchangeOptions
|
|
59
|
+
handler: (exchange: ServerWebExchange, variables: { [key in T]: string }) => Promise<void>,
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export type ServerWebSocketHandler = WebSocketHandler & {
|
|
63
|
+
close?: () => Promise<void>
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export type ServerConfigurerSocketSpec = {
|
|
67
|
+
path?: string, options?: ServerWebSocketOptions
|
|
68
|
+
factory: (server: { endpoint: string, storage?: AsyncLocalStorage<{ }> }) => Promise<ServerWebSocketHandler>,
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export interface ServerConfigurer {
|
|
72
|
+
handle(...handler: Array<ServerConfigurerHandlerSpec>): void;
|
|
73
|
+
|
|
74
|
+
socket(...socket: Array<ServerConfigurerSocketSpec>): void;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export type Middleware<Request extends ServerHttpRequest = ServerHttpRequest, Response extends ServerHttpResponse = ServerHttpResponse> = ((context: ServerWebExchange<Request, Response>, next: () => Promise<void>) => Promise<void>)[];
|
|
78
|
+
|
|
79
|
+
export type ServerWebExchange<Request extends ServerHttpRequest = ServerHttpRequest, Response extends ServerHttpResponse = ServerHttpResponse> = {
|
|
80
|
+
readonly request: Request
|
|
81
|
+
readonly response: Response;
|
|
82
|
+
attribute<T>(key: string): T | undefined;
|
|
83
|
+
principal<P extends Principal>(): Promise<P | undefined>;
|
|
84
|
+
readonly logPrefix: string;
|
|
85
|
+
}
|
|
86
|
+
|
|
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>
|
|
92
|
+
}
|
|
93
|
+
|
|
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
|
+
|
|
108
|
+
readonly upgrade: boolean
|
|
109
|
+
readonly remoteAddress?: AddressInfo
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export interface ServerHttpResponse extends HttpResponse<MutableHttpHeaders>, HttpOutputMessage<MutableHttpHeaders> {
|
|
113
|
+
readonly statusCode: HttpStatusCode
|
|
114
|
+
setStatusCode(statusCode: HttpStatusCode): boolean
|
|
115
|
+
|
|
116
|
+
addCookie(cookie: ResponseCookie): this
|
|
117
|
+
|
|
118
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type {WebSocket} from 'ws';
|
|
2
|
+
import type {ReadonlyHttpHeaders, HttpCookie} from './http';
|
|
3
|
+
import type {Principal} from '../auth';
|
|
4
|
+
import type {AddressInfo} from 'node:net';
|
|
5
|
+
|
|
6
|
+
type WebSocketHandshakeInfo = {
|
|
7
|
+
readonly url: URL;
|
|
8
|
+
readonly protocol?: string;
|
|
9
|
+
|
|
10
|
+
// request headers for server and response headers for client
|
|
11
|
+
readonly headers: ReadonlyHttpHeaders;
|
|
12
|
+
readonly cookies: ReadonlyArray<HttpCookie>;
|
|
13
|
+
principal<P extends Principal>(): Promise<P | undefined>;
|
|
14
|
+
readonly remoteAddress?: AddressInfo;
|
|
15
|
+
readonly logPrefix?: string;
|
|
16
|
+
}
|
|
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
|
+
}
|