@ez4/gateway 0.35.1 → 0.37.0
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 +120 -2
- package/dist/client/authorization.d.ts +1 -1
- package/dist/client/operations.d.ts +1 -2
- package/dist/errors/auth/authorizer.d.ts +4 -0
- package/dist/errors/{identity.d.ts → auth/identity.d.ts} +4 -2
- package/dist/errors/body.d.ts +4 -2
- package/dist/errors/defaults.d.ts +4 -2
- package/dist/errors/headers.d.ts +4 -2
- package/dist/errors/{authorization.d.ts → http/authorization.d.ts} +4 -2
- package/dist/errors/{cache.d.ts → http/cache.d.ts} +4 -2
- package/dist/errors/{cors.d.ts → http/cors.d.ts} +5 -3
- package/dist/errors/parameters.d.ts +9 -3
- package/dist/errors/preferences.d.ts +4 -2
- package/dist/errors/query.d.ts +4 -2
- package/dist/errors/ws/event.d.ts +10 -0
- package/dist/errors/{authorizer.d.ts → ws/target.d.ts} +1 -1
- package/dist/library.cjs +464 -310
- package/dist/library.d.ts +17 -14
- package/dist/library.mjs +445 -293
- package/dist/main.cjs +15 -14
- package/dist/main.d.ts +5 -3
- package/dist/main.mjs +8 -6
- package/dist/metadata/auth/handler.d.ts +4 -0
- package/dist/metadata/auth/identity.d.ts +6 -0
- package/dist/metadata/auth/request.d.ts +4 -0
- package/dist/metadata/auth/response.d.ts +4 -0
- package/dist/metadata/auth/types.d.ts +20 -0
- package/dist/metadata/body.d.ts +4 -3
- package/dist/metadata/headers.d.ts +3 -2
- package/dist/metadata/http/access.d.ts +4 -0
- package/dist/metadata/http/authorization.d.ts +4 -0
- package/dist/metadata/http/cache.d.ts +4 -0
- package/dist/metadata/http/cors.d.ts +4 -0
- package/dist/metadata/http/defaults.d.ts +4 -0
- package/dist/metadata/http/errors.d.ts +4 -0
- package/dist/metadata/http/handler.d.ts +4 -0
- package/dist/metadata/http/import.d.ts +7 -0
- package/dist/metadata/http/request.d.ts +4 -0
- package/dist/metadata/http/response.d.ts +4 -0
- package/dist/metadata/http/routes.d.ts +5 -0
- package/dist/metadata/http/service.d.ts +7 -0
- package/dist/metadata/http/types.d.ts +117 -0
- package/dist/metadata/parameters.d.ts +3 -2
- package/dist/metadata/preferences.d.ts +4 -3
- package/dist/metadata/provider.d.ts +4 -3
- package/dist/metadata/query.d.ts +3 -2
- package/dist/metadata/types.d.ts +4 -0
- package/dist/metadata/utils/name.d.ts +2 -0
- package/dist/metadata/utils/path.d.ts +2 -0
- package/dist/metadata/utils/provider.d.ts +4 -0
- package/dist/metadata/utils/schema.d.ts +3 -0
- package/dist/metadata/utils/validator.d.ts +5 -0
- package/dist/metadata/ws/connection.d.ts +4 -0
- package/dist/metadata/ws/defaults.d.ts +5 -0
- package/dist/metadata/ws/event.d.ts +4 -0
- package/dist/metadata/ws/handlers.d.ts +4 -0
- package/dist/metadata/ws/message.d.ts +4 -0
- package/dist/metadata/ws/request.d.ts +4 -0
- package/dist/metadata/ws/response.d.ts +4 -0
- package/dist/metadata/ws/service.d.ts +7 -0
- package/dist/metadata/ws/types.d.ts +83 -0
- package/dist/services/auth/cache.d.ts +9 -0
- package/dist/services/auth/handler.d.ts +9 -0
- package/dist/services/auth/identity.d.ts +5 -0
- package/dist/services/auth/incoming.d.ts +22 -0
- package/dist/services/auth/provider.d.ts +11 -0
- package/dist/services/auth/request.d.ts +20 -0
- package/dist/services/auth/response.d.ts +10 -0
- package/dist/services/body.d.ts +13 -0
- package/dist/services/defaults.d.ts +7 -16
- package/dist/services/errors.d.ts +6 -0
- package/dist/services/headers.d.ts +10 -0
- package/dist/services/{client.d.ts → http/client.d.ts} +3 -3
- package/dist/services/{contract.d.ts → http/contract.d.ts} +45 -31
- package/dist/services/http/defaults.d.ts +17 -0
- package/dist/services/http/errors.d.ts +6 -0
- package/dist/services/http/handler.d.ts +10 -0
- package/dist/services/http/incoming.d.ts +30 -0
- package/dist/services/http/listener.d.ts +9 -0
- package/dist/services/http/path.d.ts +2 -0
- package/dist/services/http/request.d.ts +30 -0
- package/dist/services/http/response.d.ts +19 -0
- package/dist/services/http/route.d.ts +45 -0
- package/dist/services/{utils.d.ts → http/utils.d.ts} +13 -5
- package/dist/services/parameters.d.ts +5 -0
- package/dist/services/preferences.d.ts +2 -2
- package/dist/services/query.d.ts +5 -0
- package/dist/services/target.d.ts +27 -0
- package/dist/services/ws/client.d.ts +19 -0
- package/dist/services/ws/connect.d.ts +23 -0
- package/dist/services/ws/contract.d.ts +110 -0
- package/dist/services/ws/defaults.d.ts +13 -0
- package/dist/services/ws/disconnect.d.ts +17 -0
- package/dist/services/ws/event.d.ts +20 -0
- package/dist/services/ws/handler.d.ts +10 -0
- package/dist/services/ws/incoming.d.ts +19 -0
- package/dist/services/ws/listener.d.ts +9 -0
- package/dist/services/ws/message.d.ts +17 -0
- package/dist/services/ws/request.d.ts +15 -0
- package/dist/services/ws/response.d.ts +10 -0
- package/dist/services/ws/utils.d.ts +11 -0
- package/dist/utils/body.d.ts +4 -3
- package/dist/utils/client.d.ts +4 -4
- package/dist/utils/errors.d.ts +1 -0
- package/dist/utils/headers.d.ts +3 -2
- package/dist/utils/identity.d.ts +3 -2
- package/dist/utils/parameters.d.ts +3 -2
- package/dist/utils/query.d.ts +3 -2
- package/dist/utils/validation.d.ts +2 -0
- package/dist/utils.cjs +62 -55
- package/dist/utils.d.ts +2 -1
- package/dist/utils.mjs +54 -52
- package/package.json +8 -8
- package/dist/metadata/access.d.ts +0 -3
- package/dist/metadata/authorization.d.ts +0 -3
- package/dist/metadata/authorizer.d.ts +0 -3
- package/dist/metadata/cache.d.ts +0 -3
- package/dist/metadata/cors.d.ts +0 -3
- package/dist/metadata/defaults.d.ts +0 -3
- package/dist/metadata/errors.d.ts +0 -4
- package/dist/metadata/handler.d.ts +0 -3
- package/dist/metadata/identity.d.ts +0 -5
- package/dist/metadata/import.d.ts +0 -6
- package/dist/metadata/request.d.ts +0 -4
- package/dist/metadata/response.d.ts +0 -4
- package/dist/metadata/route.d.ts +0 -4
- package/dist/metadata/schema.d.ts +0 -3
- package/dist/metadata/service.d.ts +0 -6
- package/dist/metadata/utils.d.ts +0 -24
- package/dist/services/cache.d.ts +0 -9
- package/dist/services/common.d.ts +0 -147
- package/dist/services/route.d.ts +0 -56
- package/dist/types/common.d.ts +0 -95
- package/dist/types/import.d.ts +0 -14
- package/dist/types/service.d.ts +0 -14
- /package/dist/errors/{access.d.ts → http/access.d.ts} +0 -0
- /package/dist/errors/{provider.d.ts → http/provider.d.ts} +0 -0
- /package/dist/errors/{route.d.ts → http/route.d.ts} +0 -0
- /package/dist/services/{access.d.ts → http/access.d.ts} +0 -0
- /package/dist/services/{authorization.d.ts → http/authorization.d.ts} +0 -0
- /package/dist/services/{cors.d.ts → http/cors.d.ts} +0 -0
- /package/dist/services/{provider.d.ts → http/provider.d.ts} +0 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { WebPathParameters } from '../parameters';
|
|
2
|
+
import type { WebQueryStrings } from '../query';
|
|
3
|
+
import type { WebHeaders } from '../headers';
|
|
4
|
+
/**
|
|
5
|
+
* Authorization request.
|
|
6
|
+
*/
|
|
7
|
+
export interface AuthRequest {
|
|
8
|
+
/**
|
|
9
|
+
* Expected HTTP headers.
|
|
10
|
+
*/
|
|
11
|
+
readonly headers?: WebHeaders;
|
|
12
|
+
/**
|
|
13
|
+
* Expected HTTP path parameters.
|
|
14
|
+
*/
|
|
15
|
+
readonly parameters?: WebPathParameters;
|
|
16
|
+
/**
|
|
17
|
+
* Expected HTTP query strings.
|
|
18
|
+
*/
|
|
19
|
+
readonly query?: WebQueryStrings;
|
|
20
|
+
}
|
|
@@ -1,31 +1,22 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { HttpPreferences } from './preferences';
|
|
1
|
+
import type { WebPreferences } from './preferences';
|
|
3
2
|
/**
|
|
4
|
-
* Default
|
|
3
|
+
* Default service parameters.
|
|
5
4
|
*/
|
|
6
|
-
export interface
|
|
5
|
+
export interface WebDefaults {
|
|
7
6
|
/**
|
|
8
|
-
* Default
|
|
7
|
+
* Default preferences for all handlers.
|
|
9
8
|
*/
|
|
10
|
-
readonly
|
|
11
|
-
/**
|
|
12
|
-
* Status codes for all known exceptions.
|
|
13
|
-
*/
|
|
14
|
-
readonly httpErrors?: HttpErrors;
|
|
15
|
-
/**
|
|
16
|
-
* Default preferences for all handlers and routes.
|
|
17
|
-
*/
|
|
18
|
-
readonly preferences?: HttpPreferences;
|
|
9
|
+
readonly preferences?: WebPreferences;
|
|
19
10
|
/**
|
|
20
11
|
* Default log retention (in days) for the handlers.
|
|
21
12
|
*/
|
|
22
13
|
readonly logRetention?: number;
|
|
23
14
|
/**
|
|
24
|
-
* Default execution time (in seconds) for handlers
|
|
15
|
+
* Default execution time (in seconds) for handlers.
|
|
25
16
|
*/
|
|
26
17
|
readonly timeout?: number;
|
|
27
18
|
/**
|
|
28
|
-
* Default amount of memory available for handlers.
|
|
19
|
+
* Default amount of memory available (in megabytes) for handlers.
|
|
29
20
|
*/
|
|
30
21
|
readonly memory?: number;
|
|
31
22
|
}
|
|
@@ -30,6 +30,12 @@ export declare class HttpForbiddenError extends HttpError {
|
|
|
30
30
|
export declare class HttpNotFoundError extends HttpError {
|
|
31
31
|
constructor(message?: string, details?: string[]);
|
|
32
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* HTTP Conflict error.
|
|
35
|
+
*/
|
|
36
|
+
export declare class HttpConflictError extends HttpError {
|
|
37
|
+
constructor(message?: string, details?: string[]);
|
|
38
|
+
}
|
|
33
39
|
/**
|
|
34
40
|
* HTTP Unsupported Media Type error.
|
|
35
41
|
*/
|
|
@@ -3,7 +3,7 @@ import type { Http } from './contract';
|
|
|
3
3
|
/**
|
|
4
4
|
* HTTP client.
|
|
5
5
|
*/
|
|
6
|
-
export type
|
|
6
|
+
export type HttpClient<T extends Http.Service | Http.Import<any>> = {
|
|
7
7
|
[P in ClientRoutes<T> as P extends {
|
|
8
8
|
name: infer N;
|
|
9
9
|
} ? (N extends string ? N : never) : never]: P extends {
|
|
@@ -16,7 +16,7 @@ export type Client<T extends Http.Service | Http.Import<any>> = {
|
|
|
16
16
|
/**
|
|
17
17
|
* Default HTTP client request.
|
|
18
18
|
*/
|
|
19
|
-
export type
|
|
19
|
+
export type HttpClientRequest = RequestOptions & {
|
|
20
20
|
readonly headers?: Record<string, string>;
|
|
21
21
|
readonly parameters?: Record<string, string>;
|
|
22
22
|
readonly query?: Record<string, unknown>;
|
|
@@ -25,7 +25,7 @@ export type ClientRequest = RequestOptions & {
|
|
|
25
25
|
/**
|
|
26
26
|
* Default HTTP response.
|
|
27
27
|
*/
|
|
28
|
-
export type
|
|
28
|
+
export type HttpClientResponse = {
|
|
29
29
|
readonly status: number;
|
|
30
30
|
readonly headers?: Record<string, string | undefined>;
|
|
31
31
|
readonly body?: unknown;
|
|
@@ -1,52 +1,66 @@
|
|
|
1
1
|
import type { Service as CommonService } from '@ez4/common';
|
|
2
2
|
import type { LinkedVariables } from '@ez4/project/library';
|
|
3
|
-
import type {
|
|
3
|
+
import type { AuthProvider as HttpAuthProvider } from '../auth/provider';
|
|
4
|
+
import type { AuthResponse as HttpAuthResponse } from '../auth/response';
|
|
5
|
+
import type { AuthRequest as HttpAuthRequest } from '../auth/request';
|
|
6
|
+
import type { AuthIdentity } from '../auth/identity';
|
|
7
|
+
import type { AuthCache } from '../auth/cache';
|
|
8
|
+
import type { WebHeaders } from '../headers';
|
|
9
|
+
import type { WebQueryStrings } from '../query';
|
|
10
|
+
import type { WebPreferences } from '../preferences';
|
|
11
|
+
import type { WebPathParameters } from '../parameters';
|
|
12
|
+
import type { WebJsonBody, WebRawBody } from '../body';
|
|
13
|
+
import type { HttpSuccessStatuses, HttpSuccessEmptyResponse, HttpSuccessResponse, HttpEmptyRequest } from './utils';
|
|
4
14
|
import type { HttpAuthorization } from './authorization';
|
|
5
|
-
import type { HttpPreferences } from './preferences';
|
|
6
15
|
import type { HttpDefaults } from './defaults';
|
|
7
16
|
import type { HttpProvider } from './provider';
|
|
17
|
+
import type { HttpListener } from './listener';
|
|
18
|
+
import type { HttpIncoming } from './incoming';
|
|
19
|
+
import type { HttpResponse } from './response';
|
|
20
|
+
import type { HttpRequest } from './request';
|
|
21
|
+
import type { HttpHandler } from './handler';
|
|
22
|
+
import type { HttpClient } from './client';
|
|
8
23
|
import type { HttpAccess } from './access';
|
|
24
|
+
import type { HttpErrors } from './errors';
|
|
9
25
|
import type { HttpRoute } from './route';
|
|
10
|
-
import type { HttpCache } from './cache';
|
|
11
26
|
import type { HttpCors } from './cors';
|
|
12
|
-
import type { Client } from './client';
|
|
13
|
-
import type { HttpHeaders, HttpIdentity, HttpPathParameters, HttpQueryStrings, HttpJsonBody, HttpRawBody, HttpAuthRequest, HttpAuthResponse, HttpRequest, HttpResponse, HttpErrors, HttpIncoming, HttpListener, HttpAuthorizer, HttpHandler } from './common';
|
|
14
27
|
/**
|
|
15
28
|
* Provide all contracts for a self-managed HTTP service.
|
|
16
29
|
*/
|
|
17
30
|
export declare namespace Http {
|
|
18
|
-
type Headers =
|
|
19
|
-
type Identity =
|
|
20
|
-
type PathParameters =
|
|
21
|
-
type QueryStrings =
|
|
22
|
-
type JsonBody =
|
|
23
|
-
type RawBody =
|
|
31
|
+
type Headers = WebHeaders;
|
|
32
|
+
type Identity = AuthIdentity;
|
|
33
|
+
type PathParameters = WebPathParameters;
|
|
34
|
+
type QueryStrings = WebQueryStrings;
|
|
35
|
+
type JsonBody = WebJsonBody;
|
|
36
|
+
type RawBody = WebRawBody;
|
|
24
37
|
type Authorization = HttpAuthorization;
|
|
25
|
-
type
|
|
26
|
-
type
|
|
38
|
+
type Access = HttpAccess;
|
|
39
|
+
type Preferences = WebPreferences;
|
|
40
|
+
type Cache = AuthCache;
|
|
27
41
|
type Request = HttpRequest;
|
|
28
|
-
type AuthResponse = HttpAuthResponse;
|
|
29
42
|
type Response = HttpResponse;
|
|
30
|
-
type Errors = HttpErrors;
|
|
31
43
|
type Provider = HttpProvider;
|
|
32
|
-
type
|
|
33
|
-
type
|
|
44
|
+
type AuthRequest = HttpAuthRequest;
|
|
45
|
+
type AuthResponse = HttpAuthResponse;
|
|
46
|
+
type AuthProvider = HttpAuthProvider;
|
|
47
|
+
type Errors = HttpErrors;
|
|
34
48
|
type Cors = HttpCors;
|
|
35
|
-
type Incoming<T extends Request
|
|
36
|
-
type Listener<T extends Request
|
|
37
|
-
type Authorizer<T extends AuthRequest> = HttpAuthorizer<T>;
|
|
49
|
+
type Incoming<T extends Request> = HttpIncoming<T>;
|
|
50
|
+
type Listener<T extends Request> = HttpListener<T>;
|
|
38
51
|
type Handler<T extends Request> = HttpHandler<T>;
|
|
39
52
|
type Route<T extends Request = Request, U extends AuthRequest = AuthRequest> = HttpRoute<T, U>;
|
|
40
|
-
type Defaults<T extends
|
|
41
|
-
type ServiceEvent<T extends Request
|
|
53
|
+
type Defaults<T extends Request = Request> = HttpDefaults<T>;
|
|
54
|
+
type ServiceEvent<T extends Request = Request> = CommonService.AnyEvent<Incoming<T>>;
|
|
42
55
|
type SuccessEmptyResponse<S extends HttpSuccessStatuses = 204> = HttpSuccessEmptyResponse<S>;
|
|
43
|
-
type SuccessResponse<S extends HttpSuccessStatuses, T extends
|
|
56
|
+
type SuccessResponse<S extends HttpSuccessStatuses, T extends JsonBody | RawBody> = HttpSuccessResponse<S, T>;
|
|
57
|
+
type EmptyRequest = HttpEmptyRequest;
|
|
44
58
|
/**
|
|
45
59
|
* HTTP Route definition.
|
|
46
60
|
*/
|
|
47
61
|
type UseRoute<T extends Route<any, any>> = T;
|
|
48
62
|
/**
|
|
49
|
-
* HTTP
|
|
63
|
+
* HTTP Defaults definition.
|
|
50
64
|
*/
|
|
51
65
|
type UseDefaults<T extends Defaults<any>> = T;
|
|
52
66
|
/**
|
|
@@ -74,7 +88,7 @@ export declare namespace Http {
|
|
|
74
88
|
*/
|
|
75
89
|
abstract class Service implements CommonService.Provider {
|
|
76
90
|
/**
|
|
77
|
-
* All
|
|
91
|
+
* All routes associated to the gateway.
|
|
78
92
|
*/
|
|
79
93
|
abstract readonly routes: Route<any, any>[];
|
|
80
94
|
/**
|
|
@@ -82,19 +96,19 @@ export declare namespace Http {
|
|
|
82
96
|
*/
|
|
83
97
|
readonly name?: string;
|
|
84
98
|
/**
|
|
85
|
-
* Default parameters.
|
|
99
|
+
* Default gateway parameters.
|
|
86
100
|
*/
|
|
87
101
|
readonly defaults?: Defaults<any>;
|
|
88
102
|
/**
|
|
89
|
-
* CORS configuration.
|
|
103
|
+
* CORS configuration for all routes.
|
|
90
104
|
*/
|
|
91
105
|
readonly cors?: Cors;
|
|
92
106
|
/**
|
|
93
|
-
* Cache configuration.
|
|
107
|
+
* Cache configuration for authorizers.
|
|
94
108
|
*/
|
|
95
109
|
readonly cache?: Cache;
|
|
96
110
|
/**
|
|
97
|
-
* Access configuration.
|
|
111
|
+
* Access configuration for logs.
|
|
98
112
|
*/
|
|
99
113
|
readonly access?: Access;
|
|
100
114
|
/**
|
|
@@ -104,7 +118,7 @@ export declare namespace Http {
|
|
|
104
118
|
/**
|
|
105
119
|
* Service client.
|
|
106
120
|
*/
|
|
107
|
-
readonly client:
|
|
121
|
+
readonly client: HttpClient<Service>;
|
|
108
122
|
}
|
|
109
123
|
/**
|
|
110
124
|
* Imported HTTP service.
|
|
@@ -137,7 +151,7 @@ export declare namespace Http {
|
|
|
137
151
|
/**
|
|
138
152
|
* Imported service client (do not replace).
|
|
139
153
|
*/
|
|
140
|
-
readonly client:
|
|
154
|
+
readonly client: HttpClient<T>;
|
|
141
155
|
/**
|
|
142
156
|
* Variables are not allowed.
|
|
143
157
|
*/
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { WebDefaults } from '../defaults';
|
|
2
|
+
import type { HttpListener } from './listener';
|
|
3
|
+
import type { HttpRequest } from './request';
|
|
4
|
+
import type { HttpErrors } from './errors';
|
|
5
|
+
/**
|
|
6
|
+
* Default HTTP service parameters.
|
|
7
|
+
*/
|
|
8
|
+
export interface HttpDefaults<T extends HttpRequest> extends WebDefaults {
|
|
9
|
+
/**
|
|
10
|
+
* Default listener.
|
|
11
|
+
*/
|
|
12
|
+
readonly listener?: HttpListener<T>;
|
|
13
|
+
/**
|
|
14
|
+
* Status codes for all known exceptions.
|
|
15
|
+
*/
|
|
16
|
+
readonly httpErrors?: HttpErrors;
|
|
17
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Service } from '@ez4/common';
|
|
2
|
+
import type { HttpProvider } from './provider';
|
|
3
|
+
import type { HttpIncoming } from './incoming';
|
|
4
|
+
import type { HttpResponse } from './response';
|
|
5
|
+
import type { HttpRequest } from './request';
|
|
6
|
+
import type { Http } from './contract';
|
|
7
|
+
/**
|
|
8
|
+
* HTTP request handler.
|
|
9
|
+
*/
|
|
10
|
+
export type HttpHandler<T extends HttpRequest> = (request: HttpIncoming<T> | T, context: Service.Context<Http.Service | HttpProvider>) => Promise<HttpResponse> | HttpResponse;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { HttpRequest } from './request';
|
|
2
|
+
/**
|
|
3
|
+
* Incoming request.
|
|
4
|
+
*/
|
|
5
|
+
export type HttpIncoming<T extends HttpRequest> = T & {
|
|
6
|
+
/**
|
|
7
|
+
* Request tracking Id.
|
|
8
|
+
*/
|
|
9
|
+
readonly requestId: string;
|
|
10
|
+
/**
|
|
11
|
+
* Determines whether request is base64 encoded or not.
|
|
12
|
+
*/
|
|
13
|
+
readonly encoded?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Request timestamp.
|
|
16
|
+
*/
|
|
17
|
+
readonly timestamp: Date;
|
|
18
|
+
/**
|
|
19
|
+
* Request method.
|
|
20
|
+
*/
|
|
21
|
+
readonly method: string;
|
|
22
|
+
/**
|
|
23
|
+
* Request path.
|
|
24
|
+
*/
|
|
25
|
+
readonly path: string;
|
|
26
|
+
/**
|
|
27
|
+
* Raw body data (when provided in the request).
|
|
28
|
+
*/
|
|
29
|
+
readonly data?: string;
|
|
30
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Service } from '@ez4/common';
|
|
2
|
+
import type { HttpProvider } from './provider';
|
|
3
|
+
import type { HttpIncoming } from './incoming';
|
|
4
|
+
import type { HttpRequest } from './request';
|
|
5
|
+
import type { Http } from './contract';
|
|
6
|
+
/**
|
|
7
|
+
* HTTP request listener.
|
|
8
|
+
*/
|
|
9
|
+
export type HttpListener<T extends HttpRequest> = (event: Service.AnyEvent<HttpIncoming<T>>, context: Service.Context<Http.Service | HttpProvider>) => Promise<void> | void;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { AuthIdentity } from '../auth/identity';
|
|
2
|
+
import type { WebPathParameters } from '../parameters';
|
|
3
|
+
import type { WebQueryStrings } from '../query';
|
|
4
|
+
import type { WebHeaders } from '../headers';
|
|
5
|
+
import type { WebBody } from '../body';
|
|
6
|
+
/**
|
|
7
|
+
* HTTP request.
|
|
8
|
+
*/
|
|
9
|
+
export interface HttpRequest {
|
|
10
|
+
/**
|
|
11
|
+
* Expected identity.
|
|
12
|
+
*/
|
|
13
|
+
readonly identity?: AuthIdentity;
|
|
14
|
+
/**
|
|
15
|
+
* Expected HTTP headers.
|
|
16
|
+
*/
|
|
17
|
+
readonly headers?: WebHeaders;
|
|
18
|
+
/**
|
|
19
|
+
* Expected HTTP path parameters.
|
|
20
|
+
*/
|
|
21
|
+
readonly parameters?: WebPathParameters;
|
|
22
|
+
/**
|
|
23
|
+
* Expected HTTP query strings.
|
|
24
|
+
*/
|
|
25
|
+
readonly query?: WebQueryStrings;
|
|
26
|
+
/**
|
|
27
|
+
* Expected HTTP body payload.
|
|
28
|
+
*/
|
|
29
|
+
readonly body?: WebBody;
|
|
30
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { WebHeaders } from '../headers';
|
|
2
|
+
import type { WebBody } from '../body';
|
|
3
|
+
/**
|
|
4
|
+
* HTTP response.
|
|
5
|
+
*/
|
|
6
|
+
export interface HttpResponse {
|
|
7
|
+
/**
|
|
8
|
+
* HTTP status code.
|
|
9
|
+
*/
|
|
10
|
+
readonly status: number;
|
|
11
|
+
/**
|
|
12
|
+
* HTTP headers.
|
|
13
|
+
*/
|
|
14
|
+
readonly headers?: WebHeaders;
|
|
15
|
+
/**
|
|
16
|
+
* HTTP body payload.
|
|
17
|
+
*/
|
|
18
|
+
readonly body?: WebBody;
|
|
19
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { AuthHandler } from '../auth/handler';
|
|
2
|
+
import type { AuthRequest } from '../auth/request';
|
|
3
|
+
import type { WebTarget } from '../target';
|
|
4
|
+
import type { HttpListener } from './listener';
|
|
5
|
+
import type { HttpRequest } from './request';
|
|
6
|
+
import type { HttpHandler } from './handler';
|
|
7
|
+
import type { HttpErrors } from './errors';
|
|
8
|
+
import type { HttpPath } from './path';
|
|
9
|
+
/**
|
|
10
|
+
* HTTP route.
|
|
11
|
+
*/
|
|
12
|
+
export interface HttpRoute<T extends HttpRequest, U extends AuthRequest> extends WebTarget {
|
|
13
|
+
/**
|
|
14
|
+
* Route operation name.
|
|
15
|
+
*/
|
|
16
|
+
readonly name?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Route path including the HTTP verb.
|
|
19
|
+
*/
|
|
20
|
+
readonly path: HttpPath;
|
|
21
|
+
/**
|
|
22
|
+
* Life-cycle listener function for the route.
|
|
23
|
+
*/
|
|
24
|
+
readonly listener?: HttpListener<T>;
|
|
25
|
+
/**
|
|
26
|
+
* Entry-point authorizer handler function for the route.
|
|
27
|
+
*/
|
|
28
|
+
readonly authorizer?: AuthHandler<U>;
|
|
29
|
+
/**
|
|
30
|
+
* Entry-point handler function for the route.
|
|
31
|
+
*/
|
|
32
|
+
readonly handler: HttpHandler<T>;
|
|
33
|
+
/**
|
|
34
|
+
* Map status codes and errors for all known exceptions.
|
|
35
|
+
*/
|
|
36
|
+
readonly httpErrors?: HttpErrors;
|
|
37
|
+
/**
|
|
38
|
+
* Determines whether or not the route is disabled.
|
|
39
|
+
*/
|
|
40
|
+
readonly disabled?: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Determines whether or not CORS is enabled for the route.
|
|
43
|
+
*/
|
|
44
|
+
readonly cors?: boolean;
|
|
45
|
+
}
|
|
@@ -1,18 +1,26 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Http } from './contract';
|
|
2
|
+
/**
|
|
3
|
+
* HTTP success status codes.
|
|
4
|
+
*/
|
|
2
5
|
export type HttpSuccessStatuses = 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208;
|
|
3
6
|
/**
|
|
4
|
-
*
|
|
7
|
+
* HTTP empty request.
|
|
8
|
+
*/
|
|
9
|
+
export declare class HttpEmptyRequest implements Http.Request {
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* HTTP success response without a response body.
|
|
5
13
|
*/
|
|
6
|
-
export declare class HttpSuccessEmptyResponse<S extends HttpSuccessStatuses> implements
|
|
14
|
+
export declare class HttpSuccessEmptyResponse<S extends HttpSuccessStatuses> implements Http.Response {
|
|
7
15
|
/**
|
|
8
16
|
* HTTP status code.
|
|
9
17
|
*/
|
|
10
18
|
readonly status: S;
|
|
11
19
|
}
|
|
12
20
|
/**
|
|
13
|
-
*
|
|
21
|
+
* HTTP success response.
|
|
14
22
|
*/
|
|
15
|
-
export declare class HttpSuccessResponse<S extends HttpSuccessStatuses, T extends
|
|
23
|
+
export declare class HttpSuccessResponse<S extends HttpSuccessStatuses, T extends Http.JsonBody | Http.RawBody> implements Http.Response {
|
|
16
24
|
/**
|
|
17
25
|
* HTTP status code.
|
|
18
26
|
*/
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { NamingStyle } from '@ez4/schema';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Preferences configuration.
|
|
4
4
|
*/
|
|
5
|
-
export interface
|
|
5
|
+
export interface WebPreferences {
|
|
6
6
|
/**
|
|
7
7
|
* Determines the naming style for the query strings and body payloads.
|
|
8
8
|
*/
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { LinkedVariables } from '@ez4/project/library';
|
|
2
|
+
import type { WebPreferences } from './preferences';
|
|
3
|
+
/**
|
|
4
|
+
* Target configuration.
|
|
5
|
+
*/
|
|
6
|
+
export interface WebTarget {
|
|
7
|
+
/**
|
|
8
|
+
* Target preference options.
|
|
9
|
+
*/
|
|
10
|
+
readonly preferences?: WebPreferences;
|
|
11
|
+
/**
|
|
12
|
+
* Default log retention (in days) for the handlers.
|
|
13
|
+
*/
|
|
14
|
+
readonly logRetention?: number;
|
|
15
|
+
/**
|
|
16
|
+
* Variables associated to the event.
|
|
17
|
+
*/
|
|
18
|
+
readonly variables?: LinkedVariables;
|
|
19
|
+
/**
|
|
20
|
+
* Max execution time (in seconds) for the event.
|
|
21
|
+
*/
|
|
22
|
+
readonly timeout?: number;
|
|
23
|
+
/**
|
|
24
|
+
* Amount of memory available (in megabytes) for the handler.
|
|
25
|
+
*/
|
|
26
|
+
readonly memory?: number;
|
|
27
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Ws } from './contract';
|
|
2
|
+
/**
|
|
3
|
+
* WS client.
|
|
4
|
+
*/
|
|
5
|
+
export interface WsClient<T extends Ws.JsonBody> {
|
|
6
|
+
/**
|
|
7
|
+
* Send a new JSON message to the connection.
|
|
8
|
+
*
|
|
9
|
+
* @param connectionId Connection identifier.
|
|
10
|
+
* @param message Message object.
|
|
11
|
+
*/
|
|
12
|
+
sendMessage(connectionId: string, message: T): Promise<void>;
|
|
13
|
+
/**
|
|
14
|
+
* Terminate an active connection.
|
|
15
|
+
*
|
|
16
|
+
* @param connectionId Connection identifier.
|
|
17
|
+
*/
|
|
18
|
+
disconnect(connectionId: string): Promise<void>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { AuthHandler } from '../auth/handler';
|
|
2
|
+
import type { AuthRequest } from '../auth/request';
|
|
3
|
+
import type { WebTarget } from '../target';
|
|
4
|
+
import type { WsListener } from './listener';
|
|
5
|
+
import type { WsHandler } from './handler';
|
|
6
|
+
import type { WsEvent } from './event';
|
|
7
|
+
/**
|
|
8
|
+
* WS connect event.
|
|
9
|
+
*/
|
|
10
|
+
export interface WsConnect<T extends WsEvent, U extends AuthRequest> extends WebTarget {
|
|
11
|
+
/**
|
|
12
|
+
* Life-cycle listener function for the event.
|
|
13
|
+
*/
|
|
14
|
+
readonly listener?: WsListener<T>;
|
|
15
|
+
/**
|
|
16
|
+
* Entry-point authorizer handler function for the event.
|
|
17
|
+
*/
|
|
18
|
+
readonly authorizer?: AuthHandler<U>;
|
|
19
|
+
/**
|
|
20
|
+
* Entry-point handler function for the event.
|
|
21
|
+
*/
|
|
22
|
+
readonly handler: WsHandler<T>;
|
|
23
|
+
}
|