@ez4/gateway 0.18.0 → 0.20.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 +182 -171
- package/dist/library.mjs +182 -175
- package/dist/main.cjs +13 -13
- package/dist/main.mjs +9 -9
- package/dist/metadata/body.d.ts +5 -5
- 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 +15 -3
- package/dist/services/contract.d.ts +14 -4
- package/dist/types/common.d.ts +19 -14
- package/package.json +6 -6
|
@@ -131,6 +131,12 @@ export interface HttpResponse {
|
|
|
131
131
|
*/
|
|
132
132
|
body?: HttpJsonBody;
|
|
133
133
|
}
|
|
134
|
+
export interface HttpProvider {
|
|
135
|
+
/**
|
|
136
|
+
* All services associated to the provider.
|
|
137
|
+
*/
|
|
138
|
+
services: Record<string, unknown>;
|
|
139
|
+
}
|
|
134
140
|
/**
|
|
135
141
|
* Incoming request.
|
|
136
142
|
*/
|
|
@@ -155,12 +161,18 @@ export type HttpIncoming<T extends HttpRequest | HttpAuthRequest> = T & {
|
|
|
155
161
|
/**
|
|
156
162
|
* Request listener.
|
|
157
163
|
*/
|
|
158
|
-
export type HttpListener<T extends HttpRequest | HttpAuthRequest> = (event: Service.Event<HttpIncoming<T>>, context: Service.Context<Http.Service>) => Promise<void> | void;
|
|
164
|
+
export type HttpListener<T extends HttpRequest | HttpAuthRequest> = (event: Service.Event<HttpIncoming<T>>, context: Service.Context<Http.Service | HttpProvider>) => Promise<void> | void;
|
|
159
165
|
/**
|
|
160
166
|
* Request authorizer.
|
|
161
167
|
*/
|
|
162
|
-
export type HttpAuthorizer<T extends HttpAuthRequest> = (request: HttpIncoming<T> | T, context: Service.Context<Http.Service>) => Promise<HttpAuthResponse> | HttpAuthResponse;
|
|
168
|
+
export type HttpAuthorizer<T extends HttpAuthRequest> = (request: HttpIncoming<T> | T, context: Service.Context<Http.Service | HttpProvider>) => Promise<HttpAuthResponse> | HttpAuthResponse;
|
|
163
169
|
/**
|
|
164
170
|
* Request handler.
|
|
165
171
|
*/
|
|
166
|
-
export type HttpHandler<T extends HttpRequest> = (request: HttpIncoming<T> | T, context: Service.Context<Http.Service>) => Promise<HttpResponse> | HttpResponse;
|
|
172
|
+
export type HttpHandler<T extends HttpRequest> = (request: HttpIncoming<T> | T, context: Service.Context<Http.Service | HttpProvider>) => Promise<HttpResponse> | HttpResponse;
|
|
173
|
+
/**
|
|
174
|
+
* HTTP errors.
|
|
175
|
+
*/
|
|
176
|
+
export type HttpErrors = {
|
|
177
|
+
[code: number]: Error[];
|
|
178
|
+
};
|
|
@@ -1,13 +1,11 @@
|
|
|
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 { HttpHeaders, HttpIdentity, HttpPathParameters, HttpQueryStrings, HttpJsonBody, HttpAuthRequest, HttpAuthResponse, HttpRequest, HttpResponse, HttpErrors, HttpProvider, HttpIncoming, HttpListener, HttpAuthorizer, HttpHandler, HttpCache, HttpCors } from './common.js';
|
|
5
5
|
/**
|
|
6
6
|
* Provide all contracts for a self-managed HTTP service.
|
|
7
7
|
*/
|
|
8
8
|
export declare namespace Http {
|
|
9
|
-
type Cors = HttpCors;
|
|
10
|
-
type Cache = HttpCache;
|
|
11
9
|
type Headers = HttpHeaders;
|
|
12
10
|
type Identity = HttpIdentity;
|
|
13
11
|
type PathParameters = HttpPathParameters;
|
|
@@ -17,6 +15,10 @@ export declare namespace Http {
|
|
|
17
15
|
type Request = HttpRequest;
|
|
18
16
|
type AuthResponse = HttpAuthResponse;
|
|
19
17
|
type Response = HttpResponse;
|
|
18
|
+
type Errors = HttpErrors;
|
|
19
|
+
type Provider = HttpProvider;
|
|
20
|
+
type Cache = HttpCache;
|
|
21
|
+
type Cors = HttpCors;
|
|
20
22
|
type Incoming<T extends Request | AuthRequest> = HttpIncoming<T>;
|
|
21
23
|
type Listener<T extends Request | AuthRequest> = HttpListener<T>;
|
|
22
24
|
type Authorizer<T extends AuthRequest> = HttpAuthorizer<T>;
|
|
@@ -42,6 +44,10 @@ export declare namespace Http {
|
|
|
42
44
|
* Route handler.
|
|
43
45
|
*/
|
|
44
46
|
handler: Handler<T>;
|
|
47
|
+
/**
|
|
48
|
+
* Map status codes and errors for all known exceptions.
|
|
49
|
+
*/
|
|
50
|
+
httpErrors?: Errors;
|
|
45
51
|
/**
|
|
46
52
|
* Variables associated to the route.
|
|
47
53
|
*/
|
|
@@ -67,10 +73,14 @@ export declare namespace Http {
|
|
|
67
73
|
* Default route listener.
|
|
68
74
|
*/
|
|
69
75
|
listener?: Listener<T>;
|
|
76
|
+
/**
|
|
77
|
+
* Status codes for all known exceptions.
|
|
78
|
+
*/
|
|
79
|
+
httpErrors?: Errors;
|
|
70
80
|
/**
|
|
71
81
|
* Default log retention (in days) for the handlers.
|
|
72
82
|
*/
|
|
73
|
-
|
|
83
|
+
logRetention?: number;
|
|
74
84
|
/**
|
|
75
85
|
* Default execution time (in seconds) for handlers and routes.
|
|
76
86
|
*/
|
package/dist/types/common.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import type { ArraySchema, ObjectSchema, ScalarSchema, UnionSchema } from '@ez4/schema';
|
|
1
2
|
import type { LinkedVariables } from '@ez4/project/library';
|
|
2
3
|
import type { ServiceListener } from '@ez4/common/library';
|
|
3
|
-
import type { BooleanSchema, NumberSchema, ObjectSchema, StringSchema, UnionSchema } from '@ez4/schema';
|
|
4
4
|
export type HttpVerb = 'ANY' | 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS';
|
|
5
5
|
export type HttpPath = `${HttpVerb} /${string}`;
|
|
6
6
|
export type HttpAuthRequest = {
|
|
@@ -16,19 +16,19 @@ export type HttpRequest = {
|
|
|
16
16
|
identity?: ObjectSchema | UnionSchema | null;
|
|
17
17
|
parameters?: ObjectSchema | null;
|
|
18
18
|
query?: ObjectSchema | null;
|
|
19
|
-
body?: ObjectSchema | UnionSchema | null;
|
|
19
|
+
body?: ObjectSchema | UnionSchema | ArraySchema | null;
|
|
20
20
|
};
|
|
21
21
|
export type HttpResponse = {
|
|
22
22
|
status: number;
|
|
23
23
|
headers?: ObjectSchema | null;
|
|
24
|
-
body?: ObjectSchema | UnionSchema |
|
|
24
|
+
body?: ObjectSchema | UnionSchema | ArraySchema | ScalarSchema | null;
|
|
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.20.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.20.0",
|
|
46
|
+
"@ez4/project": "^0.20.0",
|
|
47
|
+
"@ez4/reflection": "^0.20.0",
|
|
48
|
+
"@ez4/schema": "^0.20.0",
|
|
49
|
+
"@ez4/utils": "^0.20.0"
|
|
50
50
|
}
|
|
51
51
|
}
|