@ez4/gateway 0.34.0 → 0.35.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.
@@ -1,9 +1,16 @@
1
1
  import type { Service as CommonService } from '@ez4/common';
2
2
  import type { LinkedVariables } from '@ez4/project/library';
3
- import type { HttpPath } from '../types/common';
4
3
  import type { HttpSuccessStatuses, HttpSuccessEmptyResponse, HttpSuccessResponse } from './utils';
4
+ import type { HttpAuthorization } from './authorization';
5
+ import type { HttpPreferences } from './preferences';
6
+ import type { HttpDefaults } from './defaults';
7
+ import type { HttpProvider } from './provider';
8
+ import type { HttpAccess } from './access';
9
+ import type { HttpRoute } from './route';
10
+ import type { HttpCache } from './cache';
11
+ import type { HttpCors } from './cors';
5
12
  import type { Client } from './client';
6
- import type { HttpHeaders, HttpIdentity, HttpPathParameters, HttpQueryStrings, HttpJsonBody, HttpRawBody, HttpPreferences, HttpAuthRequest, HttpAuthResponse, HttpRequest, HttpResponse, HttpErrors, HttpProvider, HttpIncoming, HttpListener, HttpAuthorizer, HttpHandler, HttpCache, HttpAccess, HttpCors } from './common';
13
+ import type { HttpHeaders, HttpIdentity, HttpPathParameters, HttpQueryStrings, HttpJsonBody, HttpRawBody, HttpAuthRequest, HttpAuthResponse, HttpRequest, HttpResponse, HttpErrors, HttpIncoming, HttpListener, HttpAuthorizer, HttpHandler } from './common';
7
14
  /**
8
15
  * Provide all contracts for a self-managed HTTP service.
9
16
  */
@@ -14,6 +21,7 @@ export declare namespace Http {
14
21
  type QueryStrings = HttpQueryStrings;
15
22
  type JsonBody = HttpJsonBody;
16
23
  type RawBody = HttpRawBody;
24
+ type Authorization = HttpAuthorization;
17
25
  type Preferences = HttpPreferences;
18
26
  type AuthRequest = HttpAuthRequest;
19
27
  type Request = HttpRequest;
@@ -28,87 +36,39 @@ export declare namespace Http {
28
36
  type Listener<T extends Request | AuthRequest> = HttpListener<T>;
29
37
  type Authorizer<T extends AuthRequest> = HttpAuthorizer<T>;
30
38
  type Handler<T extends Request> = HttpHandler<T>;
39
+ type Route<T extends Request = Request, U extends AuthRequest = AuthRequest> = HttpRoute<T, U>;
40
+ type Defaults<T extends HttpRequest | HttpAuthRequest = any> = HttpDefaults<T>;
31
41
  type ServiceEvent<T extends Request | AuthRequest = Request> = CommonService.AnyEvent<Incoming<T>>;
32
42
  type SuccessEmptyResponse<S extends HttpSuccessStatuses = 204> = HttpSuccessEmptyResponse<S>;
33
43
  type SuccessResponse<S extends HttpSuccessStatuses, T extends HttpRawBody | HttpJsonBody> = HttpSuccessResponse<S, T>;
34
44
  /**
35
- * HTTP route.
45
+ * HTTP Route definition.
36
46
  */
37
- interface Route<T extends Request = Request, U extends AuthRequest = AuthRequest> {
38
- /**
39
- * Route name.
40
- */
41
- name?: string;
42
- /**
43
- * Route path.
44
- */
45
- path: HttpPath;
46
- /**
47
- * Route listener.
48
- */
49
- listener?: Listener<T | U>;
50
- /**
51
- * Route authorizer.
52
- */
53
- authorizer?: Authorizer<U>;
54
- /**
55
- * Route handler.
56
- */
57
- handler: Handler<T>;
58
- /**
59
- * Map status codes and errors for all known exceptions.
60
- */
61
- httpErrors?: Errors;
62
- /**
63
- * Default log retention (in days) for the handlers.
64
- */
65
- logRetention?: number;
66
- /**
67
- * Variables associated to the route.
68
- */
69
- variables?: LinkedVariables;
70
- /**
71
- * Max execution time (in seconds) for the route.
72
- */
73
- timeout?: number;
74
- /**
75
- * Amount of memory available for the handler.
76
- */
77
- memory?: number;
78
- /**
79
- * Determines whether or not CORS is enabled for the route.
80
- */
81
- cors?: boolean;
82
- }
47
+ type UseRoute<T extends Route<any, any>> = T;
83
48
  /**
84
- * Default HTTP service parameters.
49
+ * HTTP Service definition.
85
50
  */
86
- type Defaults<T extends Request | AuthRequest = {}> = {
87
- /**
88
- * Default route listener.
89
- */
90
- listener?: Listener<T>;
91
- /**
92
- * Status codes for all known exceptions.
93
- */
94
- httpErrors?: Errors;
95
- /**
96
- * Default preferences for all handlers and routes.
97
- */
98
- preferences?: Preferences;
99
- /**
100
- * Default log retention (in days) for the handlers.
101
- */
102
- logRetention?: number;
103
- /**
104
- * Default execution time (in seconds) for handlers and routes.
105
- */
106
- timeout?: number;
107
- /**
108
- * Default amount of memory available for handlers.
109
- */
110
- memory?: number;
111
- };
51
+ type UseDefaults<T extends Defaults<any>> = T;
52
+ /**
53
+ * HTTP Preferences definition.
54
+ */
55
+ type UsePreferences<T extends Preferences> = T;
56
+ /**
57
+ * HTTP Authorization definition.
58
+ */
59
+ type UseAuthorization<T extends Authorization> = T;
60
+ /**
61
+ * HTTP Cache definition.
62
+ */
63
+ type UseCache<T extends Cache> = T;
64
+ /**
65
+ * HTTP Access definition.
66
+ */
67
+ type UseAccess<T extends Access> = T;
68
+ /**
69
+ * HTTP CORS definition.
70
+ */
71
+ type UseCors<T extends Cors> = T;
112
72
  /**
113
73
  * HTTP service.
114
74
  */
@@ -116,35 +76,35 @@ export declare namespace Http {
116
76
  /**
117
77
  * All expected routes.
118
78
  */
119
- abstract routes: Route<any, any>[];
79
+ abstract readonly routes: Route<any, any>[];
120
80
  /**
121
81
  * Display name for the service.
122
82
  */
123
- name?: string;
83
+ readonly name?: string;
124
84
  /**
125
85
  * Default parameters.
126
86
  */
127
- defaults?: Defaults;
87
+ readonly defaults?: Defaults<any>;
128
88
  /**
129
89
  * CORS configuration.
130
90
  */
131
- cors?: Cors;
91
+ readonly cors?: Cors;
132
92
  /**
133
93
  * Cache configuration.
134
94
  */
135
- cache?: Cache;
95
+ readonly cache?: Cache;
136
96
  /**
137
97
  * Access configuration.
138
98
  */
139
- access?: Access;
99
+ readonly access?: Access;
140
100
  /**
141
101
  * Variables associated to all routes.
142
102
  */
143
- variables?: LinkedVariables;
103
+ readonly variables?: LinkedVariables;
144
104
  /**
145
105
  * Service client.
146
106
  */
147
- client: Client<Service>;
107
+ readonly client: Client<Service>;
148
108
  }
149
109
  /**
150
110
  * Imported HTTP service.
@@ -153,34 +113,38 @@ export declare namespace Http {
153
113
  /**
154
114
  * Name of the imported project defined in the project options file.
155
115
  */
156
- abstract project: string;
116
+ abstract readonly project: string;
157
117
  /**
158
118
  * Imported service reference.
159
119
  */
160
- reference: T;
120
+ readonly reference: T;
121
+ /**
122
+ * Authorization configuration.
123
+ */
124
+ readonly authorization?: Authorization;
161
125
  /**
162
126
  * All routes attached to the imported service (do not replace).
163
127
  */
164
- routes: T['routes'];
128
+ readonly routes: T['routes'];
165
129
  /**
166
130
  * Display name for the service imported service (do not replace).
167
131
  */
168
- name: T['name'];
132
+ readonly name: T['name'];
169
133
  /**
170
134
  * All default configurations attached to the imported service (do not replace).
171
135
  */
172
- defaults: T['defaults'];
136
+ readonly defaults: T['defaults'];
173
137
  /**
174
138
  * Imported service client (do not replace).
175
139
  */
176
- client: Client<T>;
140
+ readonly client: Client<T>;
177
141
  /**
178
142
  * Variables are not allowed.
179
143
  */
180
- variables: never;
144
+ readonly variables: never;
181
145
  /**
182
146
  * Services are not allowed.
183
147
  */
184
- service: never;
148
+ readonly service: never;
185
149
  }
186
150
  }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * HTTP CORS configuration.
3
+ */
4
+ export interface HttpCors {
5
+ /**
6
+ * List of allowed origins.
7
+ */
8
+ readonly allowOrigins: string[];
9
+ /**
10
+ * List of allowed methods.
11
+ */
12
+ readonly allowMethods?: string[];
13
+ /**
14
+ * Determines whether or not requests can be made with credentials.
15
+ */
16
+ readonly allowCredentials?: boolean;
17
+ /**
18
+ * List of allowed headers.
19
+ */
20
+ readonly allowHeaders?: string[];
21
+ /**
22
+ * List of exposed headers.
23
+ */
24
+ readonly exposeHeaders?: string[];
25
+ /**
26
+ * Determines how long the preflight result can be cached.
27
+ */
28
+ readonly maxAge?: number;
29
+ }
@@ -0,0 +1,31 @@
1
+ import type { HttpAuthRequest, HttpErrors, HttpListener, HttpRequest } from './common';
2
+ import type { HttpPreferences } from './preferences';
3
+ /**
4
+ * Default HTTP service parameters.
5
+ */
6
+ export interface HttpDefaults<T extends HttpRequest | HttpAuthRequest> {
7
+ /**
8
+ * Default route listener.
9
+ */
10
+ readonly listener?: HttpListener<T>;
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;
19
+ /**
20
+ * Default log retention (in days) for the handlers.
21
+ */
22
+ readonly logRetention?: number;
23
+ /**
24
+ * Default execution time (in seconds) for handlers and routes.
25
+ */
26
+ readonly timeout?: number;
27
+ /**
28
+ * Default amount of memory available for handlers.
29
+ */
30
+ readonly memory?: number;
31
+ }
@@ -0,0 +1,10 @@
1
+ import type { NamingStyle } from '@ez4/schema';
2
+ /**
3
+ * HTTP preferences configuration.
4
+ */
5
+ export interface HttpPreferences {
6
+ /**
7
+ * Determines the naming style for the query strings and body payloads.
8
+ */
9
+ readonly namingStyle?: NamingStyle;
10
+ }
@@ -0,0 +1,11 @@
1
+ import type { LinkedVariables } from '@ez4/project/library';
2
+ export interface HttpProvider {
3
+ /**
4
+ * Variables associated to the provider.
5
+ */
6
+ readonly variables?: LinkedVariables;
7
+ /**
8
+ * All services associated to the provider.
9
+ */
10
+ readonly services: Record<string, unknown>;
11
+ }
@@ -0,0 +1,56 @@
1
+ import type { LinkedVariables } from '@ez4/project/library';
2
+ import type { HttpPath } from '../types/common';
3
+ import type { HttpAuthorizer, HttpAuthRequest, HttpErrors, HttpHandler, HttpListener, HttpRequest } from './common';
4
+ /**
5
+ * HTTP route.
6
+ */
7
+ export interface HttpRoute<T extends HttpRequest, U extends HttpAuthRequest> {
8
+ /**
9
+ * Route name.
10
+ */
11
+ readonly name?: string;
12
+ /**
13
+ * Route path.
14
+ */
15
+ readonly path: HttpPath;
16
+ /**
17
+ * Route listener.
18
+ */
19
+ readonly listener?: HttpListener<T | U>;
20
+ /**
21
+ * Route authorizer.
22
+ */
23
+ readonly authorizer?: HttpAuthorizer<U>;
24
+ /**
25
+ * Route handler.
26
+ */
27
+ readonly handler: HttpHandler<T>;
28
+ /**
29
+ * Map status codes and errors for all known exceptions.
30
+ */
31
+ readonly httpErrors?: HttpErrors;
32
+ /**
33
+ * Default log retention (in days) for the handlers.
34
+ */
35
+ readonly logRetention?: number;
36
+ /**
37
+ * Variables associated to the route.
38
+ */
39
+ readonly variables?: LinkedVariables;
40
+ /**
41
+ * Max execution time (in seconds) for the route.
42
+ */
43
+ readonly timeout?: number;
44
+ /**
45
+ * Amount of memory available for the handler.
46
+ */
47
+ readonly memory?: number;
48
+ /**
49
+ * Determines whether or not CORS is enabled for the route.
50
+ */
51
+ readonly cors?: boolean;
52
+ /**
53
+ * Determines whether or not the route is disabled.
54
+ */
55
+ readonly disabled?: boolean;
56
+ }
@@ -7,7 +7,7 @@ export declare class HttpSuccessEmptyResponse<S extends HttpSuccessStatuses> imp
7
7
  /**
8
8
  * HTTP status code.
9
9
  */
10
- status: S;
10
+ readonly status: S;
11
11
  }
12
12
  /**
13
13
  * Common HTTP success response.
@@ -16,9 +16,9 @@ export declare class HttpSuccessResponse<S extends HttpSuccessStatuses, T extend
16
16
  /**
17
17
  * HTTP status code.
18
18
  */
19
- status: S;
19
+ readonly status: S;
20
20
  /**
21
21
  * HTTP response payload.
22
22
  */
23
- body: T;
23
+ readonly body: T;
24
24
  }
@@ -1,11 +1,17 @@
1
1
  import type { ArraySchema, NamingStyle, ObjectSchema, ScalarSchema, UnionSchema } from '@ez4/schema';
2
2
  import type { LinkedServices, LinkedVariables } from '@ez4/project/library';
3
3
  import type { ServiceListener } from '@ez4/common/library';
4
+ import type { AuthorizationType } from '../services/authorization';
4
5
  export type HttpVerb = 'ANY' | 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS';
5
6
  export type HttpPath = `${HttpVerb} /${string}`;
6
7
  export type HttpPreferences = {
7
8
  namingStyle?: NamingStyle;
8
9
  };
10
+ export type HttpAuthorization = {
11
+ type: AuthorizationType;
12
+ header: string;
13
+ value: string;
14
+ };
9
15
  export type HttpAuthRequest = {
10
16
  headers?: ObjectSchema;
11
17
  parameters?: ObjectSchema;
@@ -59,6 +65,7 @@ export type HttpRoute = {
59
65
  timeout?: number;
60
66
  memory?: number;
61
67
  cors?: boolean;
68
+ disabled?: boolean;
62
69
  };
63
70
  export type HttpDefaults = {
64
71
  listener?: ServiceListener;
@@ -1,5 +1,5 @@
1
1
  import type { ServiceMetadata } from '@ez4/project/library';
2
- import type { HttpRoute, HttpDefaults } from './common';
2
+ import type { HttpRoute, HttpDefaults, HttpAuthorization } from './common';
3
3
  export declare const ImportType = "@ez4/import:http";
4
4
  export type HttpImport = ServiceMetadata & {
5
5
  type: typeof ImportType;
@@ -8,6 +8,7 @@ export type HttpImport = ServiceMetadata & {
8
8
  displayName?: string;
9
9
  description?: string;
10
10
  defaults?: HttpDefaults;
11
+ authorization?: HttpAuthorization;
11
12
  routes: HttpRoute[];
12
13
  };
13
14
  export declare const isHttpImport: (service: ServiceMetadata) => service is HttpImport;
@@ -1,4 +1,9 @@
1
1
  import type { AnySchema } from '@ez4/schema';
2
2
  import type { Http } from '../services/contract';
3
- export declare const getRequestBody: <T extends Http.JsonBody | Http.RawBody>(input: T | undefined, schema: AnySchema, preferences?: Http.Preferences | null) => Promise<T>;
3
+ export declare const prepareRequestBody: <T extends Http.JsonBody | Http.RawBody>(input: T, schema?: AnySchema, preferences?: Http.Preferences) => {
4
+ body: string;
5
+ json: boolean;
6
+ };
7
+ export declare const getRequestBody: <T extends Http.JsonBody | Http.RawBody>(input: T | undefined, schema: AnySchema, preferences?: Http.Preferences) => Promise<T>;
8
+ export declare const prepareResponseBody: (body: string, schema?: AnySchema, preferences?: Http.Preferences) => unknown;
4
9
  export declare const getResponseBody: (body: unknown, schema: AnySchema, preferences?: Http.Preferences) => unknown;
@@ -1,14 +1,18 @@
1
- import type { ArraySchema, ObjectSchema, ScalarSchema, UnionSchema } from '@ez4/schema';
1
+ import type { ArraySchema, ObjectSchema, ScalarSchema, UnionSchema, NamingStyle } from '@ez4/schema';
2
2
  import type { ClientRequest, ClientResponse } from '../services/client';
3
- import { NamingStyle } from '@ez4/schema';
4
3
  export type ClientRequestUrl = ClientRequest & {
5
4
  querySchema?: ObjectSchema;
6
5
  namingStyle?: NamingStyle;
7
6
  };
8
7
  export declare const getClientRequestUrl: (host: string, path: string, request: ClientRequestUrl) => string;
9
- export type SendClientRequest = ClientRequest & {
10
- bodySchema?: ObjectSchema | UnionSchema | ArraySchema | ScalarSchema;
8
+ export type RequestAuthorization = {
9
+ header: string;
10
+ value: string;
11
+ };
12
+ export type ClientRequestInput = ClientRequest & {
13
+ authorization?: RequestAuthorization;
11
14
  responseSchema?: ObjectSchema | UnionSchema | ArraySchema | ScalarSchema;
15
+ bodySchema?: ObjectSchema | UnionSchema | ArraySchema | ScalarSchema;
12
16
  namingStyle?: NamingStyle;
13
17
  };
14
- export declare const sendClientRequest: (url: string, method: string, request: SendClientRequest) => Promise<ClientResponse>;
18
+ export declare const sendClientRequest: (url: string, method: string, request: ClientRequestInput) => Promise<ClientResponse>;
@@ -1,3 +1,4 @@
1
1
  import type { ObjectSchema } from '@ez4/schema';
2
2
  import type { Http } from '../services/contract';
3
+ export declare const preparePathParameters: (path: string, parameters: Record<string, string>) => string;
3
4
  export declare const getPathParameters: <T extends Http.PathParameters>(input: T, schema: ObjectSchema) => Promise<T>;
@@ -1,5 +1,4 @@
1
- import type { AnySchema, ObjectSchema } from '@ez4/schema';
1
+ import type { ObjectSchema } from '@ez4/schema';
2
2
  import type { Http } from '../services/contract';
3
- export declare const getQueryStrings: <T extends Http.QueryStrings>(input: T, schema: ObjectSchema, preferences?: Http.Preferences | null) => Promise<T>;
4
- export declare const serializeQueryStrings: <T extends Http.QueryStrings>(query: T, schema?: ObjectSchema) => string | undefined;
5
- export declare const serializeQueryStringValue: (value: unknown, schema?: AnySchema) => string | undefined;
3
+ export declare const prepareQueryStrings: <T extends Http.QueryStrings>(input: T, schema?: ObjectSchema, preferences?: Http.Preferences) => string | undefined;
4
+ export declare const getQueryStrings: <T extends Http.QueryStrings>(input: T, schema: ObjectSchema, preferences?: Http.Preferences) => Promise<T>;
package/dist/utils.cjs CHANGED
@@ -1,52 +1,56 @@
1
- "use strict";var T=Object.defineProperty;var Q=Object.getOwnPropertyDescriptor;var V=Object.getOwnPropertyNames;var I=Object.prototype.hasOwnProperty;var s=(e,t)=>T(e,"name",{value:t,configurable:!0});var J=(e,t)=>{for(var r in t)T(e,r,{get:t[r],enumerable:!0})},k=(e,t,r,o)=>{if(t&&
2
- typeof t=="object"||typeof t=="function")for(let n of V(t))!I.call(e,n)&&n!==r&&
3
- T(e,n,{get:()=>t[n],enumerable:!(o=Q(t,n))||o.enumerable});return e};var F=e=>k(T({},"__esModule",{value:!0}),e);var nt={};J(nt,{getClientRequestUrl:()=>G,getHeaders:()=>tt,getHttpException:()=>O,
4
- getIdentity:()=>et,getJsonError:()=>_,getPathParameters:()=>Z,getQueryStrings:()=>D,
5
- getRequestBody:()=>rt,getResponseBody:()=>ot,sendClientRequest:()=>K,serializeQueryStringValue:()=>q,
6
- serializeQueryStrings:()=>R});module.exports=F(nt);var p=require("@ez4/transform"),H=require("@ez4/schema");var U=require("@ez4/gateway"),w=require("@ez4/transform"),l=require("@ez4/validator"),
7
- d=require("@ez4/utils"),C=require("@ez4/schema");var D=s(async(e,t,r)=>{let o=r?.namingStyle,n=(0,w.createTransformContext)({convert:!0,
8
- inputStyle:o}),i=(0,w.transform)(e,t,n),f=(0,l.createValidatorContext)({property:"\
9
- $query",pathStyle:o}),c=await(0,l.validate)(i,t,f);if(c.length){let m=(0,l.getUniqueErrorMessages)(
10
- c);throw new U.HttpBadRequestError("Malformed query strings.",m)}return i},"getQ\
11
- ueryStrings"),R=s((e,t)=>{let r=[];for(let o in e){let n=t&&(0,C.getSchemaProperty)(
12
- t,o),i=q(e[o],n);i&&r.push(`${o}=${encodeURIComponent(i)}`)}if(r.length)return r.
13
- join("&")},"serializeQueryStrings"),q=s((e,t)=>{if(!(0,d.isNullish)(e))return e instanceof
14
- Date?e.toISOString():e instanceof Array&&(!t||!(0,C.isArraySchema)(t)||!t.definitions?.
15
- encoded)?e.map(n=>q(n,t)).filter(n=>(0,d.isNotNullish)(n)).join(","):e instanceof
16
- Object?(0,d.base64Encode)(JSON.stringify(e)):`${e}`},"serializeQueryStringValue");var a=require("@ez4/gateway");var _=s(({status:e,message:t,details:r})=>({status:e,body:{message:t,details:r}}),
17
- "getJsonError"),O=s((e,t,r)=>{switch(e){case 400:return new a.HttpBadRequestError(
1
+ "use strict";var w=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var F=Object.getOwnPropertyNames;var D=Object.prototype.hasOwnProperty;var s=(e,t)=>w(e,"name",{value:t,configurable:!0});var _=(e,t)=>{for(var r in t)w(e,r,{get:t[r],enumerable:!0})},G=(e,t,r,o)=>{if(t&&
2
+ typeof t=="object"||typeof t=="function")for(let n of F(t))!D.call(e,n)&&n!==r&&
3
+ w(e,n,{get:()=>t[n],enumerable:!(o=k(t,n))||o.enumerable});return e};var K=e=>G(w({},"__esModule",{value:!0}),e);var nt={};_(nt,{getClientRequestUrl:()=>tt,getHeaders:()=>rt,getHttpException:()=>v,
4
+ getIdentity:()=>ot,getJsonError:()=>Z,getPathParameters:()=>Y,getQueryStrings:()=>L,
5
+ getRequestBody:()=>W,getResponseBody:()=>X,preparePathParameters:()=>P,prepareQueryStrings:()=>C,
6
+ prepareRequestBody:()=>E,prepareResponseBody:()=>j,sendClientRequest:()=>et});module.
7
+ exports=K(nt);var M=require("@ez4/gateway"),u=require("@ez4/transform"),f=require("@ez4/validator"),
8
+ d=require("@ez4/utils"),q=require("@ez4/schema");var C=s((e,t,r)=>{if(!t)return B(e);let o=(0,u.createTransformContext)({inputStyle:r?.
9
+ namingStyle,convert:!1}),n=(0,u.transform)(e,t,o);return B(n,t)},"prepareQuerySt\
10
+ rings"),L=s(async(e,t,r)=>{let o=r?.namingStyle,n=(0,u.createTransformContext)({
11
+ convert:!0,inputStyle:o}),i=(0,u.transform)(e,t,n),y=(0,f.createValidatorContext)(
12
+ {property:"$query",pathStyle:o}),m=await(0,f.validate)(i,t,y);if(m.length){let p=(0,f.getUniqueErrorMessages)(
13
+ m);throw new M.HttpBadRequestError("Malformed query strings.",p)}return i},"getQ\
14
+ ueryStrings"),B=s((e,t)=>{let r=[];for(let o in e){let n=t&&(0,q.getSchemaProperty)(
15
+ t,o),i=N(e[o],n);i&&r.push(`${o}=${encodeURIComponent(i)}`)}if(r.length)return r.
16
+ join("&")},"serializeQueryStrings"),N=s((e,t)=>{if(!(0,d.isNullish)(e))return e instanceof
17
+ Date?e.toISOString():e instanceof Array&&(!t||!(0,q.isArraySchema)(t)||!t.definitions?.
18
+ encoded)?e.map(n=>N(n,t)).filter(n=>(0,d.isNotNullish)(n)).join(","):e instanceof
19
+ Object?(0,d.base64Encode)(JSON.stringify(e)):`${e}`},"serializeQueryStringValue");var c=require("@ez4/transform"),l=require("@ez4/validator"),T=require("@ez4/schema"),
20
+ $=require("@ez4/gateway");var E=s((e,t,r)=>{if(!t||(0,T.isScalarSchema)(t))return{body:e.toString(),json:!1};
21
+ let o=(0,c.createTransformContext)({outputStyle:r?.namingStyle,convert:!1}),n=(0,c.transform)(
22
+ e,t,o);return{body:JSON.stringify(n),json:!0}},"prepareRequestBody"),W=s(async(e,t,r)=>{
23
+ let o=r?.namingStyle,n=(0,l.createValidatorContext)({property:"$body",inputStyle:o}),
24
+ i=await(0,l.validate)(e,t,n);if(i.length){let p=(0,l.getUniqueErrorMessages)(i);
25
+ throw new $.HttpBadRequestError("Malformed body payload.",p)}let y=(0,c.createTransformContext)(
26
+ {convert:!1,inputStyle:o});return(0,c.transform)(e,t,y)},"getRequestBody"),j=s((e,t,r)=>{
27
+ if(!t||(0,T.isScalarSchema)(t))return e;let o=JSON.parse(e),n=(0,c.createTransformContext)(
28
+ {outputStyle:T.NamingStyle.Preserve,inputStyle:r?.namingStyle,convert:!1});return(0,c.transform)(
29
+ o,t,n)},"prepareResponseBody"),X=s((e,t,r)=>{let o=r?.namingStyle,n=(0,c.createTransformContext)(
30
+ {convert:!1,outputStyle:o});return(0,c.transform)(e,t,n)},"getResponseBody");var b=require("@ez4/transform"),S=require("@ez4/validator"),Q=require("@ez4/gateway");var P=s((e,t)=>e.replaceAll(/\{(\w+)\}/g,(r,o)=>o in t?`${t[o]}`:`{${o}}`),"prep\
31
+ arePathParameters"),Y=s(async(e,t)=>{let r=(0,b.transform)(e,t,(0,b.createTransformContext)(
32
+ {convert:!1})),o=await(0,S.validate)(r,t,(0,S.createValidatorContext)({property:"\
33
+ $path"}));if(o.length){let n=(0,S.getUniqueErrorMessages)(o);throw new Q.HttpBadRequestError(
34
+ "Malformed path parameters.",n)}return r},"getPathParameters");var a=require("@ez4/gateway");var Z=s(({status:e,message:t,details:r})=>({status:e,body:{message:t,details:r}}),
35
+ "getJsonError"),v=s((e,t,r)=>{switch(e){case 400:return new a.HttpBadRequestError(
18
36
  t,r);case 401:return new a.HttpUnauthorizedError(t,r);case 403:return new a.HttpForbiddenError(
19
37
  t,r);case 404:return new a.HttpNotFoundError(t,r);case 415:return new a.HttpUnsupportedMediaTypeError(
20
38
  t,r);case 422:return new a.HttpUnprocessableEntityError(t,r);default:return new a.HttpError(
21
- e,t,r)}},"getHttpException");var G=s((e,t,r)=>{let{parameters:o,query:n,querySchema:i,namingStyle:f}=r,c=o?L(
22
- t,o):t,m=n&&W(n,i,f),y=[e];return c&&y.push(c),m&&y.push("?",m),y.join("")},"get\
23
- ClientRequestUrl"),K=s(async(e,t,r)=>{let{headers:o,body:n,bodySchema:i,responseSchema:f,
24
- namingStyle:c,timeout:m=20}=r,y=n?X(n,i,c):void 0,v=new AbortController,$=setTimeout(
25
- ()=>v?.abort("Request timed out"),m*1e3),b=await fetch(e,{signal:v?.signal,body:y?.
26
- body,method:t,headers:{...o,...y?.json&&{"content-type":"application/json"}}});if(clearTimeout(
27
- $),!b.ok){let A=await b.json();throw O(b.status,A.message,A.details)}let P=await b.
28
- text();return{status:b.status,...P&&{body:Y(P,f,c)}}},"sendClientRequest"),L=s((e,t)=>e.
29
- replaceAll(/\{(\w+)\}/g,(r,o)=>o in t?`${t[o]}`:`{${o}}`),"getPathParameters"),W=s(
30
- (e,t,r)=>{if(!t)return R(e);let o=(0,p.createTransformContext)({inputStyle:r,convert:!1}),
31
- n=(0,p.transform)(e,t,o);return R(n,t)},"getQueryStrings"),X=s((e,t,r)=>{if(!t||
32
- (0,H.isScalarSchema)(t))return{body:e.toString(),json:!1};let o=(0,p.createTransformContext)(
33
- {outputStyle:r,convert:!1}),n=(0,p.transform)(e,t,o);return{body:JSON.stringify(
34
- n),json:!0}},"getRequestBody"),Y=s((e,t,r)=>{if(!t||(0,H.isScalarSchema)(t))return e;
35
- let o=JSON.parse(e),n=(0,p.createTransformContext)({outputStyle:H.NamingStyle.Preserve,
36
- inputStyle:r,convert:!1});return(0,p.transform)(o,t,n)},"getResponseBody");var j=require("@ez4/transform"),u=require("@ez4/validator"),z=require("@ez4/gateway");var Z=s(async(e,t)=>{let r=(0,j.transform)(e,t,(0,j.createTransformContext)({convert:!1})),
37
- o=await(0,u.validate)(r,t,(0,u.createValidatorContext)({property:"$path"}));if(o.
38
- length){let n=(0,u.getUniqueErrorMessages)(o);throw new z.HttpBadRequestError("M\
39
- alformed path parameters.",n)}return r},"getPathParameters");var E=require("@ez4/transform"),S=require("@ez4/validator"),B=require("@ez4/gateway");var tt=s(async(e,t)=>{let r=(0,E.transform)(e,t,(0,E.createTransformContext)({convert:!1})),
40
- o=await(0,S.validate)(r,t,(0,S.createValidatorContext)({property:"$header"}));if(o.
41
- length){let n=(0,S.getUniqueErrorMessages)(o);throw new B.HttpBadRequestError("M\
42
- alformed request headers.",n)}return r},"getHeaders");var g=require("@ez4/validator"),N=require("@ez4/gateway");var et=s(async(e,t)=>{let r=await(0,g.validate)(e,t,(0,g.createValidatorContext)(
43
- {property:"$identity"}));if(r.length){let o=(0,g.getUniqueErrorMessages)(r);throw new N.HttpBadRequestError(
44
- "Malformed authorizer identity.",o)}return e},"getIdentity");var h=require("@ez4/transform"),x=require("@ez4/validator"),M=require("@ez4/gateway");var rt=s(async(e,t,r)=>{let o=r?.namingStyle,n=(0,x.createValidatorContext)({property:"\
45
- $body",inputStyle:o}),i=await(0,x.validate)(e,t,n);if(i.length){let m=(0,x.getUniqueErrorMessages)(
46
- i);throw new M.HttpBadRequestError("Malformed body payload.",m)}let f=(0,h.createTransformContext)(
47
- {convert:!1,inputStyle:o});return(0,h.transform)(e,t,f)},"getRequestBody"),ot=s(
48
- (e,t,r)=>{let o=r?.namingStyle,n=(0,h.createTransformContext)({convert:!1,outputStyle:o});
49
- return(0,h.transform)(e,t,n)},"getResponseBody");0&&(module.exports={getClientRequestUrl,getHeaders,getHttpException,getIdentity,
50
- getJsonError,getPathParameters,getQueryStrings,getRequestBody,getResponseBody,sendClientRequest,
51
- serializeQueryStringValue,serializeQueryStrings});
39
+ e,t,r)}},"getHttpException");var tt=s((e,t,r)=>{let{parameters:o,query:n,querySchema:i,namingStyle:y}=r,m=o?P(
40
+ t,o):t,p=n&&C(n,i,{namingStyle:y}),x=[e];return m&&x.push(m),p&&x.push("?",p),x.
41
+ join("")},"getClientRequestUrl"),et=s(async(e,t,r)=>{let{authorization:o,headers:n,
42
+ body:i,bodySchema:y,responseSchema:m,namingStyle:p,timeout:x=20}=r,O=i?E(i,y,{namingStyle:p}):
43
+ void 0,U=new AbortController,V=setTimeout(()=>U?.abort("Request timed out"),x*1e3),
44
+ H=await fetch(e,{signal:U?.signal,body:O?.body,method:t,headers:{...n,...o&&{[o.
45
+ header]:o.value},...O?.json&&{"content-type":"application/json"}}});if(clearTimeout(
46
+ V),!H.ok){let A=await H.json();throw v(H.status,A.message,A.details)}let z=await H.
47
+ text();return{status:H.status,...z&&{body:j(z,m,{namingStyle:p})}}},"sendClientR\
48
+ equest");var R=require("@ez4/transform"),h=require("@ez4/validator"),I=require("@ez4/gateway");var rt=s(async(e,t)=>{let r=(0,R.transform)(e,t,(0,R.createTransformContext)({convert:!1})),
49
+ o=await(0,h.validate)(r,t,(0,h.createValidatorContext)({property:"$header"}));if(o.
50
+ length){let n=(0,h.getUniqueErrorMessages)(o);throw new I.HttpBadRequestError("M\
51
+ alformed request headers.",n)}return r},"getHeaders");var g=require("@ez4/validator"),J=require("@ez4/gateway");var ot=s(async(e,t)=>{let r=await(0,g.validate)(e,t,(0,g.createValidatorContext)(
52
+ {property:"$identity"}));if(r.length){let o=(0,g.getUniqueErrorMessages)(r);throw new J.HttpBadRequestError(
53
+ "Malformed authorizer identity.",o)}return e},"getIdentity");0&&(module.exports={getClientRequestUrl,getHeaders,getHttpException,getIdentity,
54
+ getJsonError,getPathParameters,getQueryStrings,getRequestBody,getResponseBody,preparePathParameters,
55
+ prepareQueryStrings,prepareRequestBody,prepareResponseBody,sendClientRequest});
52
56
  //# sourceMappingURL=utils.cjs.map