@ez4/gateway 0.28.0 → 0.30.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/main.mjs CHANGED
@@ -1,14 +1,14 @@
1
1
  var H=Object.defineProperty;var r=(s,e)=>H(s,"name",{value:e,configurable:!0});var d;(s=>{})(d||={});import{ServiceError as R}from"@ez4/common";var p=class extends R{constructor(t,m,y){super(m,y);this.status=t}static{r(this,
2
2
  "HttpError")}},o=class extends p{static{r(this,"HttpBadRequestError")}constructor(e,t){
3
3
  super(400,e||"Bad request",t)}},n=class extends p{static{r(this,"HttpUnauthorize\
4
- dError")}constructor(e,t){super(401,e||"Unauthorized",t)}},u=class extends p{static{
5
- r(this,"HttpForbiddenError")}constructor(e,t){super(403,e||"Forbidden",t)}},c=class extends p{static{
4
+ dError")}constructor(e,t){super(401,e||"Unauthorized",t)}},c=class extends p{static{
5
+ r(this,"HttpForbiddenError")}constructor(e,t){super(403,e||"Forbidden",t)}},u=class extends p{static{
6
6
  r(this,"HttpNotFoundError")}constructor(e,t){super(404,e||"Not found",t)}},i=class extends p{static{
7
7
  r(this,"HttpUnsupportedMediaTypeError")}constructor(e,t){super(415,e||"Unsupport\
8
8
  ed media type",t)}},a=class extends p{static{r(this,"HttpUnprocessableEntityErro\
9
9
  r")}constructor(e,t){super(422,e||"Unprocessable entity",t)}},x=class extends p{static{
10
10
  r(this,"HttpInternalServerError")}constructor(e,t){super(500,e||"Internal server\
11
- error",t)}};export{d as Http,o as HttpBadRequestError,p as HttpError,u as HttpForbiddenError,
12
- x as HttpInternalServerError,c as HttpNotFoundError,n as HttpUnauthorizedError,a as HttpUnprocessableEntityError,
11
+ error",t)}};export{d as Http,o as HttpBadRequestError,p as HttpError,c as HttpForbiddenError,
12
+ x as HttpInternalServerError,u as HttpNotFoundError,n as HttpUnauthorizedError,a as HttpUnprocessableEntityError,
13
13
  i as HttpUnsupportedMediaTypeError};
14
14
  //# sourceMappingURL=main.mjs.map
@@ -0,0 +1,3 @@
1
+ import type { AllType, SourceMap, TypeModel } from '@ez4/reflection';
2
+ import type { HttpAccess } from '../types/common';
3
+ export declare const getHttpAccess: (type: AllType, parent: TypeModel, reflection: SourceMap, errorList: Error[]) => HttpAccess | null;
@@ -1,5 +1,5 @@
1
1
  import type { AllType, SourceMap, TypeIntersection, TypeModel, TypeObject } from '@ez4/reflection';
2
2
  import type { ArraySchema, ObjectSchema, UnionSchema } from '@ez4/schema/library';
3
3
  type TypeParent = TypeObject | TypeModel | TypeIntersection;
4
- export declare const getHttpBody: (type: AllType, parent: TypeParent, reflection: SourceMap, errorList: Error[]) => import("@ez4/schema").BooleanSchema | import("@ez4/schema").NumberSchema | import("@ez4/schema").StringSchema | ObjectSchema | UnionSchema | ArraySchema | null;
4
+ export declare const getHttpBody: (type: AllType, parent: TypeParent, reflection: SourceMap, errorList: Error[]) => ObjectSchema | UnionSchema | ArraySchema | import("@ez4/schema").BooleanSchema | import("@ez4/schema").NumberSchema | import("@ez4/schema").StringSchema | null;
5
5
  export {};
@@ -0,0 +1,3 @@
1
+ import type { AllType, SourceMap, TypeModel } from '@ez4/reflection';
2
+ import type { HttpContext } from '../types/common';
3
+ export declare const getHttpContext: (type: AllType, parent: TypeModel, reflection: SourceMap, errorList: Error[]) => HttpContext | null;
@@ -0,0 +1,3 @@
1
+ import type { AllType, SourceMap, TypeModel } from '@ez4/reflection';
2
+ import type { HttpProvider } from '../types/common';
3
+ export declare const getHttpProvider: (type: AllType, parent: TypeModel, reflection: SourceMap, errorList: Error[]) => HttpProvider | null;
@@ -2,6 +2,7 @@ import type { AllType, TypeCallback, TypeClass, TypeFunction, TypeModel } from '
2
2
  import type { HttpPath } from '../types/common';
3
3
  export declare const isHttpPath: (path: string) => path is HttpPath;
4
4
  export declare const isHttpService: (type: AllType) => type is TypeClass;
5
+ export declare const isHttpProvider: (type: AllType) => type is TypeModel;
5
6
  export declare const isHttpRoute: (type: AllType) => type is TypeModel;
6
7
  export declare const isHttpAuthorizerRequest: (type: TypeModel) => boolean;
7
8
  export declare const isHttpHandlerRequest: (type: TypeModel) => boolean;
@@ -14,7 +15,8 @@ export declare const isHttpIdentity: (type: TypeModel) => boolean;
14
15
  export declare const isHttpQuery: (type: TypeModel) => boolean;
15
16
  export declare const isHttpParameters: (type: TypeModel) => boolean;
16
17
  export declare const isJsonBody: (type: TypeModel) => boolean;
17
- export declare const isHttpCors: (type: TypeModel) => boolean;
18
18
  export declare const isHttpCache: (type: TypeModel) => boolean;
19
+ export declare const isHttpAccess: (type: TypeModel) => boolean;
20
+ export declare const isHttpCors: (type: TypeModel) => boolean;
19
21
  export declare const isHttpAuthorizer: (type: AllType) => type is TypeCallback | TypeFunction;
20
22
  export declare const isHttpHandler: (type: AllType) => type is TypeCallback | TypeFunction;
@@ -40,7 +40,7 @@ export interface HttpCors {
40
40
  maxAge?: number;
41
41
  }
42
42
  /**
43
- * HTTP cache.
43
+ * HTTP cache configuration.
44
44
  */
45
45
  export interface HttpCache {
46
46
  /**
@@ -48,6 +48,15 @@ export interface HttpCache {
48
48
  */
49
49
  authorizerTTL: number;
50
50
  }
51
+ /**
52
+ * HTTP access configuration.
53
+ */
54
+ export interface HttpAccess {
55
+ /**
56
+ * Log retention (in days) for the access log.
57
+ */
58
+ logRetention: number;
59
+ }
51
60
  /**
52
61
  * Request headers.
53
62
  */
@@ -1,8 +1,8 @@
1
1
  import type { Service as CommonService } from '@ez4/common';
2
2
  import type { LinkedVariables } from '@ez4/project/library';
3
3
  import type { HttpPath } from '../types/common';
4
- import type { HttpSuccessStatuses, HttpEmptySuccessResponse, HttpSuccessResponse } from './utils';
5
- import type { HttpHeaders, HttpIdentity, HttpPathParameters, HttpQueryStrings, HttpJsonBody, HttpRawBody, HttpPreferences, HttpAuthRequest, HttpAuthResponse, HttpRequest, HttpResponse, HttpErrors, HttpProvider, HttpIncoming, HttpListener, HttpAuthorizer, HttpHandler, HttpCache, HttpCors } from './common';
4
+ import type { HttpSuccessStatuses, HttpSuccessEmptyResponse, HttpSuccessResponse } from './utils';
5
+ import type { HttpHeaders, HttpIdentity, HttpPathParameters, HttpQueryStrings, HttpJsonBody, HttpRawBody, HttpPreferences, HttpAuthRequest, HttpAuthResponse, HttpRequest, HttpResponse, HttpErrors, HttpProvider, HttpIncoming, HttpListener, HttpAuthorizer, HttpHandler, HttpCache, HttpAccess, HttpCors } from './common';
6
6
  /**
7
7
  * Provide all contracts for a self-managed HTTP service.
8
8
  */
@@ -21,13 +21,14 @@ export declare namespace Http {
21
21
  type Errors = HttpErrors;
22
22
  type Provider = HttpProvider;
23
23
  type Cache = HttpCache;
24
+ type Access = HttpAccess;
24
25
  type Cors = HttpCors;
25
26
  type Incoming<T extends Request | AuthRequest> = HttpIncoming<T>;
26
27
  type Listener<T extends Request | AuthRequest> = HttpListener<T>;
27
28
  type Authorizer<T extends AuthRequest> = HttpAuthorizer<T>;
28
29
  type Handler<T extends Request> = HttpHandler<T>;
29
30
  type ServiceEvent<T extends Request | AuthRequest = Request> = CommonService.AnyEvent<Incoming<T>>;
30
- type EmptySuccessResponse<S extends HttpSuccessStatuses = 204> = HttpEmptySuccessResponse<S>;
31
+ type SuccessEmptyResponse<S extends HttpSuccessStatuses = 204> = HttpSuccessEmptyResponse<S>;
31
32
  type SuccessResponse<S extends HttpSuccessStatuses, T extends HttpRawBody | HttpJsonBody> = HttpSuccessResponse<S, T>;
32
33
  /**
33
34
  * HTTP route.
@@ -127,6 +128,10 @@ export declare namespace Http {
127
128
  * Cache configuration.
128
129
  */
129
130
  cache?: Cache;
131
+ /**
132
+ * Access configuration.
133
+ */
134
+ access?: Access;
130
135
  /**
131
136
  * Variables associated to all routes.
132
137
  */
@@ -3,7 +3,7 @@ export type HttpSuccessStatuses = 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207
3
3
  /**
4
4
  * Common HTTP success response without a response body.
5
5
  */
6
- export declare class HttpEmptySuccessResponse<S extends HttpSuccessStatuses> implements HttpResponse {
6
+ export declare class HttpSuccessEmptyResponse<S extends HttpSuccessStatuses> implements HttpResponse {
7
7
  /**
8
8
  * HTTP status code.
9
9
  */
@@ -0,0 +1,2 @@
1
+ import type { TypeClass } from '@ez4/reflection';
2
+ export declare const getLinkedService: (declaration: TypeClass) => string | null;
@@ -1,5 +1,5 @@
1
1
  import type { ArraySchema, NamingStyle, ObjectSchema, ScalarSchema, UnionSchema } from '@ez4/schema';
2
- import type { LinkedVariables } from '@ez4/project/library';
2
+ import type { LinkedServices, LinkedVariables } from '@ez4/project/library';
3
3
  import type { ServiceListener } from '@ez4/common/library';
4
4
  export type HttpVerb = 'ANY' | 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS';
5
5
  export type HttpPath = `${HttpVerb} /${string}`;
@@ -22,17 +22,18 @@ export type HttpRequest = {
22
22
  body?: ObjectSchema | UnionSchema | ArraySchema | ScalarSchema | null;
23
23
  };
24
24
  export type HttpResponse = {
25
- status: number;
25
+ status: number | number[];
26
26
  headers?: ObjectSchema | null;
27
27
  body?: ObjectSchema | UnionSchema | ArraySchema | ScalarSchema | null;
28
28
  };
29
29
  export type HttpHandler = {
30
30
  name: string;
31
+ file: string;
32
+ module?: string;
31
33
  description?: string;
32
34
  response: HttpResponse;
33
35
  request?: HttpRequest;
34
- file: string;
35
- module?: string;
36
+ provider?: HttpProvider;
36
37
  };
37
38
  export type HttpAuthorizer = {
38
39
  name: string;
@@ -69,6 +70,9 @@ export type HttpDefaults = {
69
70
  export type HttpCache = {
70
71
  authorizerTTL?: number;
71
72
  };
73
+ export type HttpAccess = {
74
+ logRetention: number;
75
+ };
72
76
  export type HttpCors = {
73
77
  allowOrigins: string[];
74
78
  allowMethods?: string[];
@@ -77,3 +81,6 @@ export type HttpCors = {
77
81
  allowHeaders?: string[];
78
82
  maxAge?: number;
79
83
  };
84
+ export type HttpProvider = {
85
+ services?: LinkedServices;
86
+ };
@@ -1,5 +1,5 @@
1
1
  import type { ServiceMetadata } from '@ez4/project/library';
2
- import type { HttpRoute, HttpCors, HttpDefaults, HttpCache } from './common';
2
+ import type { HttpRoute, HttpCors, HttpDefaults, HttpCache, HttpAccess } from './common';
3
3
  export declare const ServiceType = "@ez4/http";
4
4
  export type HttpService = ServiceMetadata & {
5
5
  type: typeof ServiceType;
@@ -7,7 +7,8 @@ export type HttpService = ServiceMetadata & {
7
7
  description?: string;
8
8
  defaults?: HttpDefaults;
9
9
  routes: HttpRoute[];
10
- cors?: HttpCors;
11
10
  cache?: HttpCache;
11
+ access?: HttpAccess;
12
+ cors?: HttpCors;
12
13
  };
13
14
  export declare const isHttpService: (service: ServiceMetadata) => service is HttpService;
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.28.0",
4
+ "version": "0.30.0",
5
5
  "author": "Silas B.",
6
6
  "license": "MIT",
7
7
  "type": "module",
@@ -33,6 +33,10 @@
33
33
  "import": "./dist/utils.mjs"
34
34
  }
35
35
  },
36
+ "sideEffects": [
37
+ "./dist/library.cjs",
38
+ "./dist/library.mjs"
39
+ ],
36
40
  "workspaces": [
37
41
  "foundation/*",
38
42
  "contracts/*"
@@ -47,12 +51,12 @@
47
51
  "live:publish": "npm run build && npm publish --access public"
48
52
  },
49
53
  "dependencies": {
50
- "@ez4/common": "^0.28.0",
51
- "@ez4/project": "^0.28.0",
52
- "@ez4/reflection": "^0.28.0",
53
- "@ez4/schema": "^0.28.0",
54
- "@ez4/transform": "^0.28.0",
55
- "@ez4/utils": "^0.28.0",
56
- "@ez4/validator": "^0.28.0"
54
+ "@ez4/common": "^0.30.0",
55
+ "@ez4/project": "^0.30.0",
56
+ "@ez4/reflection": "^0.30.0",
57
+ "@ez4/schema": "^0.30.0",
58
+ "@ez4/transform": "^0.30.0",
59
+ "@ez4/utils": "^0.30.0",
60
+ "@ez4/validator": "^0.30.0"
57
61
  }
58
62
  }