@ez4/gateway 0.19.0 → 0.21.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/dist/errors/route.d.ts +4 -1
- package/dist/library.cjs +180 -173
- package/dist/library.mjs +182 -176
- package/dist/main.cjs +13 -13
- package/dist/main.mjs +9 -9
- package/dist/metadata/body.d.ts +3 -4
- package/dist/metadata/errors.d.ts +4 -0
- package/dist/metadata/headers.d.ts +4 -2
- package/dist/metadata/identity.d.ts +4 -2
- package/dist/metadata/parameters.d.ts +4 -2
- package/dist/metadata/query.d.ts +4 -2
- package/dist/metadata/schema.d.ts +2 -0
- package/dist/services/common.d.ts +30 -16
- package/dist/services/contract.d.ts +21 -4
- package/dist/services/utils.d.ts +24 -0
- package/dist/types/common.d.ts +17 -12
- package/package.json +6 -6
|
@@ -59,24 +59,28 @@ export interface HttpPathParameters {
|
|
|
59
59
|
export interface HttpQueryStrings {
|
|
60
60
|
}
|
|
61
61
|
/**
|
|
62
|
-
*
|
|
62
|
+
* Json body payload.
|
|
63
63
|
*/
|
|
64
64
|
export interface HttpJsonBody {
|
|
65
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* Raw body payload.
|
|
68
|
+
*/
|
|
69
|
+
export type HttpRawBody = string;
|
|
66
70
|
/**
|
|
67
71
|
* Authorizer request.
|
|
68
72
|
*/
|
|
69
73
|
export interface HttpAuthRequest {
|
|
70
74
|
/**
|
|
71
|
-
* Expected headers.
|
|
75
|
+
* Expected HTTP headers.
|
|
72
76
|
*/
|
|
73
77
|
headers?: HttpHeaders;
|
|
74
78
|
/**
|
|
75
|
-
* Expected path parameters.
|
|
79
|
+
* Expected HTTP path parameters.
|
|
76
80
|
*/
|
|
77
81
|
parameters?: HttpPathParameters;
|
|
78
82
|
/**
|
|
79
|
-
* Expected query strings.
|
|
83
|
+
* Expected HTTP query strings.
|
|
80
84
|
*/
|
|
81
85
|
query?: HttpQueryStrings;
|
|
82
86
|
}
|
|
@@ -93,43 +97,43 @@ export interface HttpAuthResponse {
|
|
|
93
97
|
* HTTP request.
|
|
94
98
|
*/
|
|
95
99
|
export interface HttpRequest {
|
|
96
|
-
/**
|
|
97
|
-
* Expected headers.
|
|
98
|
-
*/
|
|
99
|
-
headers?: HttpHeaders;
|
|
100
100
|
/**
|
|
101
101
|
* Expected identity.
|
|
102
102
|
*/
|
|
103
103
|
identity?: HttpIdentity;
|
|
104
104
|
/**
|
|
105
|
-
* Expected
|
|
105
|
+
* Expected HTTP headers.
|
|
106
|
+
*/
|
|
107
|
+
headers?: HttpHeaders;
|
|
108
|
+
/**
|
|
109
|
+
* Expected HTTP path parameters.
|
|
106
110
|
*/
|
|
107
111
|
parameters?: HttpPathParameters;
|
|
108
112
|
/**
|
|
109
|
-
* Expected query strings.
|
|
113
|
+
* Expected HTTP query strings.
|
|
110
114
|
*/
|
|
111
115
|
query?: HttpQueryStrings;
|
|
112
116
|
/**
|
|
113
|
-
* Expected
|
|
117
|
+
* Expected HTTP body payload.
|
|
114
118
|
*/
|
|
115
|
-
body?: HttpJsonBody;
|
|
119
|
+
body?: HttpJsonBody | HttpRawBody;
|
|
116
120
|
}
|
|
117
121
|
/**
|
|
118
122
|
* HTTP response.
|
|
119
123
|
*/
|
|
120
124
|
export interface HttpResponse {
|
|
121
125
|
/**
|
|
122
|
-
*
|
|
126
|
+
* HTTP status code.
|
|
123
127
|
*/
|
|
124
128
|
status: number;
|
|
125
129
|
/**
|
|
126
|
-
*
|
|
130
|
+
* HTTP headers.
|
|
127
131
|
*/
|
|
128
132
|
headers?: HttpHeaders;
|
|
129
133
|
/**
|
|
130
|
-
*
|
|
134
|
+
* HTTP body payload.
|
|
131
135
|
*/
|
|
132
|
-
body?: HttpJsonBody;
|
|
136
|
+
body?: HttpJsonBody | HttpRawBody;
|
|
133
137
|
}
|
|
134
138
|
export interface HttpProvider {
|
|
135
139
|
/**
|
|
@@ -145,6 +149,10 @@ export type HttpIncoming<T extends HttpRequest | HttpAuthRequest> = T & {
|
|
|
145
149
|
* Request tracking Id.
|
|
146
150
|
*/
|
|
147
151
|
requestId: string;
|
|
152
|
+
/**
|
|
153
|
+
* Determines whether request is base64 encoded or not.
|
|
154
|
+
*/
|
|
155
|
+
encoded?: boolean;
|
|
148
156
|
/**
|
|
149
157
|
* Request timestamp.
|
|
150
158
|
*/
|
|
@@ -170,3 +178,9 @@ export type HttpAuthorizer<T extends HttpAuthRequest> = (request: HttpIncoming<T
|
|
|
170
178
|
* Request handler.
|
|
171
179
|
*/
|
|
172
180
|
export type HttpHandler<T extends HttpRequest> = (request: HttpIncoming<T> | T, context: Service.Context<Http.Service | HttpProvider>) => Promise<HttpResponse> | HttpResponse;
|
|
181
|
+
/**
|
|
182
|
+
* HTTP errors.
|
|
183
|
+
*/
|
|
184
|
+
export type HttpErrors = {
|
|
185
|
+
[code: number]: Error[];
|
|
186
|
+
};
|
|
@@ -1,28 +1,33 @@
|
|
|
1
1
|
import type { Service } from '@ez4/common';
|
|
2
2
|
import type { LinkedVariables } from '@ez4/project/library';
|
|
3
3
|
import type { HttpPath } from '../types/common.js';
|
|
4
|
-
import type {
|
|
4
|
+
import type { HttpSuccessStatuses, HttpEmptySuccessResponse, HttpSuccessResponse } from './utils.js';
|
|
5
|
+
import type { HttpHeaders, HttpIdentity, HttpPathParameters, HttpQueryStrings, HttpJsonBody, HttpRawBody, HttpAuthRequest, HttpAuthResponse, HttpRequest, HttpResponse, HttpErrors, HttpProvider, HttpIncoming, HttpListener, HttpAuthorizer, HttpHandler, HttpCache, HttpCors } from './common.js';
|
|
5
6
|
/**
|
|
6
7
|
* Provide all contracts for a self-managed HTTP service.
|
|
7
8
|
*/
|
|
8
9
|
export declare namespace Http {
|
|
9
|
-
type Cors = HttpCors;
|
|
10
|
-
type Cache = HttpCache;
|
|
11
10
|
type Headers = HttpHeaders;
|
|
12
11
|
type Identity = HttpIdentity;
|
|
13
12
|
type PathParameters = HttpPathParameters;
|
|
14
13
|
type QueryStrings = HttpQueryStrings;
|
|
15
14
|
type JsonBody = HttpJsonBody;
|
|
15
|
+
type RawBody = HttpRawBody;
|
|
16
16
|
type AuthRequest = HttpAuthRequest;
|
|
17
17
|
type Request = HttpRequest;
|
|
18
18
|
type AuthResponse = HttpAuthResponse;
|
|
19
19
|
type Response = HttpResponse;
|
|
20
|
+
type Errors = HttpErrors;
|
|
20
21
|
type Provider = HttpProvider;
|
|
22
|
+
type Cache = HttpCache;
|
|
23
|
+
type Cors = HttpCors;
|
|
21
24
|
type Incoming<T extends Request | AuthRequest> = HttpIncoming<T>;
|
|
22
25
|
type Listener<T extends Request | AuthRequest> = HttpListener<T>;
|
|
23
26
|
type Authorizer<T extends AuthRequest> = HttpAuthorizer<T>;
|
|
24
27
|
type Handler<T extends Request> = HttpHandler<T>;
|
|
25
28
|
type ServiceEvent<T extends Request | AuthRequest = Request> = Service.Event<Incoming<T>>;
|
|
29
|
+
type EmptySuccessResponse<S extends HttpSuccessStatuses = 204> = HttpEmptySuccessResponse<S>;
|
|
30
|
+
type SuccessResponse<S extends HttpSuccessStatuses, T extends HttpRawBody | HttpJsonBody> = HttpSuccessResponse<S, T>;
|
|
26
31
|
/**
|
|
27
32
|
* HTTP route.
|
|
28
33
|
*/
|
|
@@ -43,6 +48,14 @@ export declare namespace Http {
|
|
|
43
48
|
* Route handler.
|
|
44
49
|
*/
|
|
45
50
|
handler: Handler<T>;
|
|
51
|
+
/**
|
|
52
|
+
* Default log retention (in days) for the handlers.
|
|
53
|
+
*/
|
|
54
|
+
logRetention?: number;
|
|
55
|
+
/**
|
|
56
|
+
* Map status codes and errors for all known exceptions.
|
|
57
|
+
*/
|
|
58
|
+
httpErrors?: Errors;
|
|
46
59
|
/**
|
|
47
60
|
* Variables associated to the route.
|
|
48
61
|
*/
|
|
@@ -68,10 +81,14 @@ export declare namespace Http {
|
|
|
68
81
|
* Default route listener.
|
|
69
82
|
*/
|
|
70
83
|
listener?: Listener<T>;
|
|
84
|
+
/**
|
|
85
|
+
* Status codes for all known exceptions.
|
|
86
|
+
*/
|
|
87
|
+
httpErrors?: Errors;
|
|
71
88
|
/**
|
|
72
89
|
* Default log retention (in days) for the handlers.
|
|
73
90
|
*/
|
|
74
|
-
|
|
91
|
+
logRetention?: number;
|
|
75
92
|
/**
|
|
76
93
|
* Default execution time (in seconds) for handlers and routes.
|
|
77
94
|
*/
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { HttpResponse, HttpJsonBody, HttpRawBody } from './common.js';
|
|
2
|
+
export type HttpSuccessStatuses = 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208;
|
|
3
|
+
/**
|
|
4
|
+
* Common HTTP success response without a response body.
|
|
5
|
+
*/
|
|
6
|
+
export declare class HttpEmptySuccessResponse<S extends HttpSuccessStatuses> implements HttpResponse {
|
|
7
|
+
/**
|
|
8
|
+
* HTTP status code.
|
|
9
|
+
*/
|
|
10
|
+
status: S;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Common HTTP success response.
|
|
14
|
+
*/
|
|
15
|
+
export declare class HttpSuccessResponse<S extends HttpSuccessStatuses, T extends HttpJsonBody | HttpRawBody> implements HttpResponse {
|
|
16
|
+
/**
|
|
17
|
+
* HTTP status code.
|
|
18
|
+
*/
|
|
19
|
+
status: S;
|
|
20
|
+
/**
|
|
21
|
+
* HTTP response payload.
|
|
22
|
+
*/
|
|
23
|
+
body: T;
|
|
24
|
+
}
|
package/dist/types/common.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ export type HttpRequest = {
|
|
|
16
16
|
identity?: ObjectSchema | UnionSchema | null;
|
|
17
17
|
parameters?: ObjectSchema | null;
|
|
18
18
|
query?: ObjectSchema | null;
|
|
19
|
-
body?: ObjectSchema | UnionSchema | ArraySchema | null;
|
|
19
|
+
body?: ObjectSchema | UnionSchema | ArraySchema | ScalarSchema | null;
|
|
20
20
|
};
|
|
21
21
|
export type HttpResponse = {
|
|
22
22
|
status: number;
|
|
@@ -25,10 +25,10 @@ export type HttpResponse = {
|
|
|
25
25
|
};
|
|
26
26
|
export type HttpHandler = {
|
|
27
27
|
name: string;
|
|
28
|
-
file: string;
|
|
29
28
|
description?: string;
|
|
30
29
|
response: HttpResponse;
|
|
31
30
|
request?: HttpRequest;
|
|
31
|
+
file: string;
|
|
32
32
|
};
|
|
33
33
|
export type HttpAuthorizer = {
|
|
34
34
|
name: string;
|
|
@@ -37,23 +37,31 @@ export type HttpAuthorizer = {
|
|
|
37
37
|
response?: HttpAuthResponse;
|
|
38
38
|
request?: HttpAuthRequest;
|
|
39
39
|
};
|
|
40
|
+
export type HttpErrors = {
|
|
41
|
+
[name: string]: number;
|
|
42
|
+
};
|
|
40
43
|
export type HttpRoute = {
|
|
41
44
|
path: HttpPath;
|
|
42
|
-
listener?: ServiceListener;
|
|
43
|
-
authorizer?: HttpAuthorizer;
|
|
44
45
|
handler: HttpHandler;
|
|
46
|
+
listener?: ServiceListener | null;
|
|
47
|
+
authorizer?: HttpAuthorizer | null;
|
|
45
48
|
variables?: LinkedVariables | null;
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
49
|
+
logRetention?: number | null;
|
|
50
|
+
httpErrors?: HttpErrors | null;
|
|
51
|
+
timeout?: number | null;
|
|
52
|
+
memory?: number | null;
|
|
53
|
+
cors?: boolean | null;
|
|
50
54
|
};
|
|
51
55
|
export type HttpDefaults = {
|
|
52
|
-
|
|
56
|
+
logRetention?: number | null;
|
|
57
|
+
httpErrors?: HttpErrors | null;
|
|
53
58
|
listener?: ServiceListener | null;
|
|
54
59
|
timeout?: number | null;
|
|
55
60
|
memory?: number | null;
|
|
56
61
|
};
|
|
62
|
+
export type HttpCache = {
|
|
63
|
+
authorizerTTL?: number;
|
|
64
|
+
};
|
|
57
65
|
export type HttpCors = {
|
|
58
66
|
allowOrigins: string[];
|
|
59
67
|
allowMethods?: string[];
|
|
@@ -62,6 +70,3 @@ export type HttpCors = {
|
|
|
62
70
|
allowHeaders?: string[];
|
|
63
71
|
maxAge?: number;
|
|
64
72
|
};
|
|
65
|
-
export type HttpCache = {
|
|
66
|
-
authorizerTTL?: number;
|
|
67
|
-
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ez4/gateway",
|
|
3
3
|
"description": "EZ4: Components to build gateway services",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.21.0",
|
|
5
5
|
"author": "Silas B.",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"type": "module",
|
|
@@ -42,10 +42,10 @@
|
|
|
42
42
|
"live:publish": "npm run test && npm publish --access public"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@ez4/common": "^0.
|
|
46
|
-
"@ez4/project": "^0.
|
|
47
|
-
"@ez4/reflection": "^0.
|
|
48
|
-
"@ez4/schema": "^0.
|
|
49
|
-
"@ez4/utils": "^0.
|
|
45
|
+
"@ez4/common": "^0.21.0",
|
|
46
|
+
"@ez4/project": "^0.21.0",
|
|
47
|
+
"@ez4/reflection": "^0.21.0",
|
|
48
|
+
"@ez4/schema": "^0.21.0",
|
|
49
|
+
"@ez4/utils": "^0.21.0"
|
|
50
50
|
}
|
|
51
51
|
}
|