@ez4/gateway 0.36.0 → 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 +3 -4
- package/dist/library.cjs +409 -404
- package/dist/library.d.ts +10 -10
- package/dist/library.mjs +416 -407
- package/dist/main.cjs +19 -18
- package/dist/main.mjs +8 -6
- package/dist/metadata/auth/handler.d.ts +2 -2
- package/dist/metadata/auth/identity.d.ts +3 -3
- package/dist/metadata/auth/request.d.ts +2 -2
- package/dist/metadata/auth/response.d.ts +2 -2
- package/dist/metadata/auth/types.d.ts +8 -5
- package/dist/metadata/body.d.ts +6 -0
- package/dist/metadata/headers.d.ts +5 -0
- package/dist/metadata/http/access.d.ts +2 -2
- package/dist/metadata/http/authorization.d.ts +2 -2
- package/dist/metadata/http/cache.d.ts +2 -2
- package/dist/metadata/http/cors.d.ts +2 -2
- package/dist/metadata/http/defaults.d.ts +2 -2
- package/dist/metadata/http/errors.d.ts +3 -3
- package/dist/metadata/http/handler.d.ts +2 -2
- package/dist/metadata/http/import.d.ts +2 -2
- package/dist/metadata/http/request.d.ts +2 -2
- package/dist/metadata/http/response.d.ts +2 -2
- package/dist/metadata/http/routes.d.ts +3 -3
- package/dist/metadata/http/service.d.ts +2 -2
- package/dist/metadata/http/types.d.ts +22 -11
- package/dist/metadata/parameters.d.ts +5 -0
- package/dist/metadata/{web/preferences.d.ts → preferences.d.ts} +2 -2
- package/dist/metadata/provider.d.ts +4 -0
- package/dist/metadata/query.d.ts +5 -0
- package/dist/metadata/utils/{type.d.ts → name.d.ts} +1 -0
- package/dist/metadata/utils/provider.d.ts +4 -0
- package/dist/metadata/utils/schema.d.ts +3 -3
- package/dist/metadata/utils/validator.d.ts +5 -0
- package/dist/metadata/ws/connection.d.ts +2 -2
- package/dist/metadata/ws/defaults.d.ts +2 -2
- package/dist/metadata/ws/event.d.ts +2 -2
- package/dist/metadata/ws/handlers.d.ts +3 -4
- package/dist/metadata/ws/message.d.ts +2 -2
- package/dist/metadata/ws/request.d.ts +2 -2
- package/dist/metadata/ws/response.d.ts +2 -2
- package/dist/metadata/ws/service.d.ts +2 -2
- package/dist/metadata/ws/types.d.ts +19 -8
- package/dist/services/auth/request.d.ts +3 -3
- package/dist/services/errors.d.ts +6 -0
- package/dist/services/http/contract.d.ts +8 -6
- package/dist/services/http/defaults.d.ts +1 -1
- package/dist/services/http/request.d.ts +4 -4
- package/dist/services/http/response.d.ts +2 -2
- package/dist/services/http/route.d.ts +1 -1
- package/dist/services/ws/connect.d.ts +1 -1
- package/dist/services/ws/contract.d.ts +6 -4
- package/dist/services/ws/defaults.d.ts +1 -1
- package/dist/services/ws/disconnect.d.ts +1 -1
- package/dist/services/ws/event.d.ts +2 -2
- package/dist/services/ws/message.d.ts +1 -1
- package/dist/services/ws/request.d.ts +1 -1
- package/dist/services/ws/response.d.ts +1 -1
- package/dist/utils/body.d.ts +3 -2
- package/dist/utils/headers.d.ts +2 -1
- package/dist/utils/identity.d.ts +2 -1
- package/dist/utils/parameters.d.ts +2 -1
- package/dist/utils/query.d.ts +2 -1
- 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/http/provider.d.ts +0 -4
- package/dist/metadata/web/body.d.ts +0 -6
- package/dist/metadata/web/headers.d.ts +0 -5
- package/dist/metadata/web/parameters.d.ts +0 -5
- package/dist/metadata/web/query.d.ts +0 -5
- /package/dist/errors/{web/body.d.ts → body.d.ts} +0 -0
- /package/dist/errors/{web/defaults.d.ts → defaults.d.ts} +0 -0
- /package/dist/errors/{web/handler.d.ts → handler.d.ts} +0 -0
- /package/dist/errors/{web/headers.d.ts → headers.d.ts} +0 -0
- /package/dist/errors/{web/parameters.d.ts → parameters.d.ts} +0 -0
- /package/dist/errors/{web/preferences.d.ts → preferences.d.ts} +0 -0
- /package/dist/errors/{web/query.d.ts → query.d.ts} +0 -0
- /package/dist/errors/{web/request.d.ts → request.d.ts} +0 -0
- /package/dist/errors/{web/response.d.ts → response.d.ts} +0 -0
- /package/dist/errors/{web/service.d.ts → service.d.ts} +0 -0
- /package/dist/metadata/{web/types.d.ts → types.d.ts} +0 -0
- /package/dist/services/{web/body.d.ts → body.d.ts} +0 -0
- /package/dist/services/{web/defaults.d.ts → defaults.d.ts} +0 -0
- /package/dist/services/{web/headers.d.ts → headers.d.ts} +0 -0
- /package/dist/services/{web/parameters.d.ts → parameters.d.ts} +0 -0
- /package/dist/services/{web/preferences.d.ts → preferences.d.ts} +0 -0
- /package/dist/services/{web/query.d.ts → query.d.ts} +0 -0
- /package/dist/services/{web/target.d.ts → target.d.ts} +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { AuthHandler } from '../auth/handler';
|
|
2
2
|
import type { AuthRequest } from '../auth/request';
|
|
3
|
-
import type { WebTarget } from '../
|
|
3
|
+
import type { WebTarget } from '../target';
|
|
4
4
|
import type { WsListener } from './listener';
|
|
5
5
|
import type { WsHandler } from './handler';
|
|
6
6
|
import type { WsEvent } from './event';
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import type { Service as CommonService } from '@ez4/common';
|
|
2
2
|
import type { LinkedVariables } from '@ez4/project/library';
|
|
3
|
+
import type { AuthProvider as WsAuthProvider } from '../auth/provider';
|
|
3
4
|
import type { AuthResponse as WsAuthResponse } from '../auth/response';
|
|
4
5
|
import type { AuthRequest as WsAuthRequest } from '../auth/request';
|
|
5
|
-
import type { WebJsonBody, WebRawBody } from '../web/body';
|
|
6
|
-
import type { WebPreferences } from '../web/preferences';
|
|
7
6
|
import type { AuthIdentity } from '../auth/identity';
|
|
8
|
-
import type {
|
|
9
|
-
import type {
|
|
7
|
+
import type { WebHeaders } from '../headers';
|
|
8
|
+
import type { WebQueryStrings } from '../query';
|
|
9
|
+
import type { WebPreferences } from '../preferences';
|
|
10
|
+
import type { WebJsonBody, WebRawBody } from '../body';
|
|
10
11
|
import type { WsEmptyEvent, WsEmptyRequest } from './utils';
|
|
11
12
|
import type { WsDisconnect } from './disconnect';
|
|
12
13
|
import type { WsDefaults } from './defaults';
|
|
@@ -34,6 +35,7 @@ export declare namespace Ws {
|
|
|
34
35
|
type Event = WsEvent;
|
|
35
36
|
type AuthRequest = WsAuthRequest;
|
|
36
37
|
type AuthResponse = WsAuthResponse;
|
|
38
|
+
type AuthProvider = WsAuthProvider;
|
|
37
39
|
type Incoming<T extends Request | Event> = WsIncoming<T>;
|
|
38
40
|
type Listener<T extends Request | Event> = WsListener<T>;
|
|
39
41
|
type Handler<T extends Request | Event> = WsHandler<T>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { AuthIdentity } from '../auth/identity';
|
|
2
|
-
import type { WebQueryStrings } from '../
|
|
3
|
-
import type { WebHeaders } from '../
|
|
2
|
+
import type { WebQueryStrings } from '../query';
|
|
3
|
+
import type { WebHeaders } from '../headers';
|
|
4
4
|
/**
|
|
5
5
|
* WS event.
|
|
6
6
|
*/
|
package/dist/utils/body.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import type { ValidationCustomHandler } from '@ez4/validator';
|
|
1
2
|
import type { AnySchema } from '@ez4/schema';
|
|
2
3
|
import type { Http } from '../services/http/contract';
|
|
3
4
|
export declare const prepareRequestBody: <T extends Http.JsonBody | Http.RawBody>(input: T, schema?: AnySchema, preferences?: Http.Preferences) => {
|
|
4
5
|
body: string;
|
|
5
6
|
json: boolean;
|
|
6
7
|
};
|
|
7
|
-
export declare const
|
|
8
|
+
export declare const resolveRequestBody: <T extends Http.JsonBody | Http.RawBody>(input: T | undefined, schema: AnySchema, preferences?: Http.Preferences, onCustomValidation?: ValidationCustomHandler) => Promise<T>;
|
|
8
9
|
export declare const prepareResponseBody: (body: string, schema?: AnySchema, preferences?: Http.Preferences) => unknown;
|
|
9
|
-
export declare const
|
|
10
|
+
export declare const resolveResponseBody: (body: unknown, schema: AnySchema, preferences?: Http.Preferences) => unknown;
|
package/dist/utils/headers.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ValidationCustomHandler } from '@ez4/validator';
|
|
1
2
|
import type { ObjectSchema } from '@ez4/schema';
|
|
2
3
|
import type { Http } from '../services/http/contract';
|
|
3
|
-
export declare const
|
|
4
|
+
export declare const resolveHeaders: <T extends Http.Headers>(input: T, schema: ObjectSchema, onCustomValidation?: ValidationCustomHandler) => Promise<T>;
|
package/dist/utils/identity.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ValidationCustomHandler } from '@ez4/validator';
|
|
1
2
|
import type { ObjectSchema, UnionSchema } from '@ez4/schema';
|
|
2
3
|
import type { Http } from '../services/http/contract';
|
|
3
|
-
export declare const
|
|
4
|
+
export declare const resolveIdentity: <T extends Http.Identity>(input: T, schema: ObjectSchema | UnionSchema, onCustomValidation?: ValidationCustomHandler) => Promise<T>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
+
import type { ValidationCustomHandler } from '@ez4/validator';
|
|
1
2
|
import type { ObjectSchema } from '@ez4/schema';
|
|
2
3
|
import type { Http } from '../services/http/contract';
|
|
3
4
|
export declare const preparePathParameters: (path: string, parameters: Record<string, string>) => string;
|
|
4
|
-
export declare const
|
|
5
|
+
export declare const resolvePathParameters: <T extends Http.PathParameters>(input: T, schema: ObjectSchema, onCustomValidation?: ValidationCustomHandler) => Promise<T>;
|
package/dist/utils/query.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
+
import type { ValidationCustomHandler } from '@ez4/validator';
|
|
1
2
|
import type { ObjectSchema } from '@ez4/schema';
|
|
2
3
|
import type { Http } from '../services/http/contract';
|
|
3
4
|
export declare const prepareQueryStrings: <T extends Http.QueryStrings>(input: T, schema?: ObjectSchema, preferences?: Http.Preferences) => string | undefined;
|
|
4
|
-
export declare const
|
|
5
|
+
export declare const resolveQueryStrings: <T extends Http.QueryStrings>(input: T, schema: ObjectSchema, preferences?: Http.Preferences, onCustomValidation?: ValidationCustomHandler) => Promise<T>;
|
package/dist/utils.cjs
CHANGED
|
@@ -1,56 +1,63 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
typeof t=="object"||typeof t=="function")for(let n of
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
exports=
|
|
8
|
-
|
|
9
|
-
namingStyle,convert:!1}),n=(0,
|
|
10
|
-
rings"),
|
|
11
|
-
convert:!0,inputStyle:
|
|
12
|
-
{property:"$query",pathStyle:o}),
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
t,o),
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
"
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
t,
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
o
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
1
|
+
"use strict";var T=Object.defineProperty;var D=Object.getOwnPropertyDescriptor;var _=Object.getOwnPropertyNames;var G=Object.prototype.hasOwnProperty;var a=(e,t)=>T(e,"name",{value:t,configurable:!0});var K=(e,t)=>{for(var r in t)T(e,r,{get:t[r],enumerable:!0})},L=(e,t,r,o)=>{if(t&&
|
|
2
|
+
typeof t=="object"||typeof t=="function")for(let n of _(t))!G.call(e,n)&&n!==r&&
|
|
3
|
+
T(e,n,{get:()=>t[n],enumerable:!(o=D(t,n))||o.enumerable});return e};var W=e=>L(T({},"__esModule",{value:!0}),e);var it={};K(it,{getClientRequestUrl:()=>rt,getHttpException:()=>O,getJsonError:()=>et,
|
|
4
|
+
preparePathParameters:()=>z,prepareQueryStrings:()=>j,prepareRequestBody:()=>P,prepareResponseBody:()=>V,
|
|
5
|
+
resolveHeaders:()=>nt,resolveIdentity:()=>at,resolvePathParameters:()=>tt,resolveQueryStrings:()=>X,
|
|
6
|
+
resolveRequestBody:()=>Y,resolveResponseBody:()=>Z,resolveValidation:()=>st,sendClientRequest:()=>ot});
|
|
7
|
+
module.exports=W(it);var f=require("@ez4/transform"),S=require("@ez4/validator"),h=require("@ez4/utils"),
|
|
8
|
+
b=require("@ez4/schema"),N=require("@ez4/gateway");var j=a((e,t,r)=>{if(!t)return B(e);let o=(0,f.createTransformContext)({inputStyle:r?.
|
|
9
|
+
namingStyle,convert:!1}),n=(0,f.transform)(e,t,o);return B(n,t)},"prepareQuerySt\
|
|
10
|
+
rings"),X=a(async(e,t,r,o)=>{let n=r?.namingStyle,s=(0,f.createTransformContext)(
|
|
11
|
+
{convert:!0,inputStyle:n}),p=(0,f.transform)(e,t,s),d=(0,S.createValidatorContext)(
|
|
12
|
+
{property:"$query",pathStyle:n,onCustomValidation:o}),c=await(0,S.validate)(p,t,
|
|
13
|
+
d);if(c.length){let u=(0,S.getUniqueErrorMessages)(c);throw new N.HttpBadRequestError(
|
|
14
|
+
"Malformed query strings.",u)}return p},"resolveQueryStrings"),B=a((e,t)=>{let r=[];
|
|
15
|
+
for(let o in e){let n=t&&(0,b.getSchemaProperty)(t,o),s=$(e[o],n);s&&r.push(`${o}\
|
|
16
|
+
=${encodeURIComponent(s)}`)}if(r.length)return r.join("&")},"serializeQueryStrin\
|
|
17
|
+
gs"),$=a((e,t)=>{if(!(0,h.isNullish)(e))return e instanceof Date?e.toISOString():
|
|
18
|
+
e instanceof Array&&(!t||!(0,b.isArraySchema)(t)||!t.definitions?.encoded)?e.map(
|
|
19
|
+
n=>$(n,t)).filter(n=>(0,h.isNotNullish)(n)).join(","):e instanceof Object?(0,h.base64Encode)(
|
|
20
|
+
JSON.stringify(e)):`${e}`},"serializeQueryStringValue");var m=require("@ez4/transform"),g=require("@ez4/validator"),w=require("@ez4/schema"),
|
|
21
|
+
q=require("@ez4/utils"),M=require("@ez4/gateway");var P=a((e,t,r)=>{if(!t||(0,w.isScalarSchema)(t))return{body:e.toString(),json:!1};
|
|
22
|
+
let o=(0,m.createTransformContext)({outputStyle:r?.namingStyle,convert:!1}),n=(0,m.transform)(
|
|
23
|
+
e,t,o);return{body:JSON.stringify(n),json:!0}},"prepareRequestBody"),Y=a(async(e,t,r,o)=>{
|
|
24
|
+
let n=r?.namingStyle,s=(0,m.createTransformContext)({convert:!1,inputStyle:n}),d=(0,g.createValidatorContext)(
|
|
25
|
+
{onCustomValidation:a((l,y)=>(0,q.isAnyObject)(l)||(0,q.isAnyArray)(l)?o?.((0,m.transform)(
|
|
26
|
+
l,y.schema,s),y):o?.(l,y),"useCustomValidation"),property:"$body",inputStyle:n}),
|
|
27
|
+
c=await(0,g.validate)(e,t,d);if(c.length){let l=(0,g.getUniqueErrorMessages)(c);
|
|
28
|
+
throw new M.HttpBadRequestError("Malformed body payload.",l)}return(0,m.transform)(
|
|
29
|
+
e,t,s)},"resolveRequestBody"),V=a((e,t,r)=>{if(!t||(0,w.isScalarSchema)(t))return e;
|
|
30
|
+
let o=JSON.parse(e),n=(0,m.createTransformContext)({outputStyle:w.NamingStyle.Preserve,
|
|
31
|
+
inputStyle:r?.namingStyle,convert:!1});return(0,m.transform)(o,t,n)},"prepareRes\
|
|
32
|
+
ponseBody"),Z=a((e,t,r)=>{let o=r?.namingStyle,n=(0,m.createTransformContext)({convert:!1,
|
|
33
|
+
outputStyle:o});return(0,m.transform)(e,t,n)},"resolveResponseBody");var R=require("@ez4/transform"),x=require("@ez4/validator"),Q=require("@ez4/gateway");var z=a((e,t)=>e.replaceAll(/\{(\w+)\}/g,(r,o)=>o in t?`${t[o]}`:`{${o}}`),"prep\
|
|
34
|
+
arePathParameters"),tt=a(async(e,t,r)=>{let o=(0,R.transform)(e,t,(0,R.createTransformContext)(
|
|
35
|
+
{convert:!1})),n=(0,x.createValidatorContext)({property:"$path",onCustomValidation:r}),
|
|
36
|
+
s=await(0,x.validate)(o,t,n);if(s.length){let p=(0,x.getUniqueErrorMessages)(s);
|
|
37
|
+
throw new Q.HttpBadRequestError("Malformed path parameters.",p)}return o},"resol\
|
|
38
|
+
vePathParameters");var i=require("@ez4/gateway");var et=a(({status:e,message:t,details:r})=>({status:e,body:{type:"error",message:t,
|
|
39
|
+
details:r}}),"getJsonError"),O=a((e,t,r)=>{switch(e){case 400:return new i.HttpBadRequestError(
|
|
40
|
+
t,r);case 401:return new i.HttpUnauthorizedError(t,r);case 403:return new i.HttpForbiddenError(
|
|
41
|
+
t,r);case 404:return new i.HttpNotFoundError(t,r);case 415:return new i.HttpUnsupportedMediaTypeError(
|
|
42
|
+
t,r);case 422:return new i.HttpUnprocessableEntityError(t,r);default:return new i.HttpError(
|
|
43
|
+
e,t,r)}},"getHttpException");var rt=a((e,t,r)=>{let{parameters:o,query:n,querySchema:s,namingStyle:p}=r,d=o?z(
|
|
44
|
+
t,o):t,c=n&&j(n,s,{namingStyle:p}),u=[e];return d&&u.push(d),c&&u.push("?",c),u.
|
|
45
|
+
join("")},"getClientRequestUrl"),ot=a(async(e,t,r)=>{let{authorization:o,headers:n,
|
|
46
|
+
body:s,bodySchema:p,responseSchema:d,namingStyle:c,timeout:u=20}=r,l=s?P(s,p,{namingStyle:c}):
|
|
47
|
+
void 0,y=new AbortController,F=setTimeout(()=>y?.abort("Request timed out"),u*1e3),
|
|
48
|
+
v=await fetch(e,{signal:y?.signal,body:l?.body,method:t,headers:{...n,...o&&{[o.
|
|
49
|
+
header]:o.value},...l?.json&&{"content-type":"application/json"}}});if(clearTimeout(
|
|
50
|
+
F),!v.ok){let U=await v.json();throw O(v.status,U.message,U.details)}let A=await v.
|
|
51
|
+
text();return{status:v.status,...A&&{body:V(A,d,{namingStyle:c})}}},"sendClientR\
|
|
52
|
+
equest");var E=require("@ez4/transform"),H=require("@ez4/validator"),I=require("@ez4/gateway");var nt=a(async(e,t,r)=>{let o=(0,E.transform)(e,t,(0,E.createTransformContext)({
|
|
53
|
+
convert:!1})),n=(0,H.createValidatorContext)({property:"$header",onCustomValidation:r}),
|
|
54
|
+
s=await(0,H.validate)(o,t,n);if(s.length){let p=(0,H.getUniqueErrorMessages)(s);
|
|
55
|
+
throw new I.HttpBadRequestError("Malformed request headers.",p)}return o},"resol\
|
|
56
|
+
veHeaders");var C=require("@ez4/validator"),J=require("@ez4/gateway");var at=a(async(e,t,r)=>{let o=(0,C.createValidatorContext)({property:"$identity",
|
|
57
|
+
onCustomValidation:r}),n=await(0,C.validate)(e,t,o);if(n.length){let s=(0,C.getUniqueErrorMessages)(
|
|
58
|
+
n);throw new J.HttpBadRequestError("Malformed authorizer identity.",s)}return e},
|
|
59
|
+
"resolveIdentity");var k=a(e=>`@${e}`,"getValidatorName");var st=a(async(e,t,r)=>{let o=t[k(r)];o&&await o.validate(e)},"resolveValidation");0&&(module.exports={getClientRequestUrl,getHttpException,getJsonError,preparePathParameters,
|
|
60
|
+
prepareQueryStrings,prepareRequestBody,prepareResponseBody,resolveHeaders,resolveIdentity,
|
|
61
|
+
resolvePathParameters,resolveQueryStrings,resolveRequestBody,resolveResponseBody,
|
|
62
|
+
resolveValidation,sendClientRequest});
|
|
56
63
|
//# sourceMappingURL=utils.cjs.map
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export * from './utils/client';
|
|
2
|
+
export * from './utils/headers';
|
|
2
3
|
export * from './utils/parameters';
|
|
3
4
|
export * from './utils/query';
|
|
4
|
-
export * from './utils/headers';
|
|
5
5
|
export * from './utils/identity';
|
|
6
6
|
export * from './utils/body';
|
|
7
|
+
export * from './utils/validation';
|
|
7
8
|
export * from './utils/errors';
|
package/dist/utils.mjs
CHANGED
|
@@ -1,54 +1,56 @@
|
|
|
1
|
-
var P=Object.defineProperty;var
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
n=H(e,t,o);return g(n,t)},"prepareQueryStrings"),
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
"
|
|
9
|
-
n);
|
|
10
|
-
|
|
11
|
-
e instanceof Array&&(!t||!$(t)||!t.definitions?.
|
|
12
|
-
n=>
|
|
13
|
-
|
|
1
|
+
var P=Object.defineProperty;var a=(e,t)=>P(e,"name",{value:t,configurable:!0});import{createTransformContext as x,transform as H}from"@ez4/transform";import{validate as V,
|
|
2
|
+
createValidatorContext as z,getUniqueErrorMessages as O}from"@ez4/validator";import{
|
|
3
|
+
base64Encode as A,isNotNullish as U,isNullish as B}from"@ez4/utils";import{getSchemaProperty as N,
|
|
4
|
+
isArraySchema as $}from"@ez4/schema";import{HttpBadRequestError as M}from"@ez4/gateway";var C=a((e,t,r)=>{if(!t)return g(e);let o=x({inputStyle:r?.namingStyle,convert:!1}),
|
|
5
|
+
n=H(e,t,o);return g(n,t)},"prepareQueryStrings"),vt=a(async(e,t,r,o)=>{let n=r?.
|
|
6
|
+
namingStyle,s=x({convert:!0,inputStyle:n}),i=H(e,t,s),m=z({property:"$query",pathStyle:n,
|
|
7
|
+
onCustomValidation:o}),p=await V(i,t,m);if(p.length){let l=O(p);throw new M("Mal\
|
|
8
|
+
formed query strings.",l)}return i},"resolveQueryStrings"),g=a((e,t)=>{let r=[];
|
|
9
|
+
for(let o in e){let n=t&&N(t,o),s=v(e[o],n);s&&r.push(`${o}=${encodeURIComponent(
|
|
10
|
+
s)}`)}if(r.length)return r.join("&")},"serializeQueryStrings"),v=a((e,t)=>{if(!B(
|
|
11
|
+
e))return e instanceof Date?e.toISOString():e instanceof Array&&(!t||!$(t)||!t.definitions?.
|
|
12
|
+
encoded)?e.map(n=>v(n,t)).filter(n=>U(n)).join(","):e instanceof Object?A(JSON.stringify(
|
|
13
|
+
e)):`${e}`},"serializeQueryStringValue");import{createTransformContext as f,transform as y}from"@ez4/transform";import{validate as Q,
|
|
14
14
|
createValidatorContext as I,getUniqueErrorMessages as J}from"@ez4/validator";import{
|
|
15
|
-
isScalarSchema as
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
t,
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
import{
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
15
|
+
isScalarSchema as w,NamingStyle as k}from"@ez4/schema";import{isAnyArray as F,isAnyObject as D}from"@ez4/utils";
|
|
16
|
+
import{HttpBadRequestError as _}from"@ez4/gateway";var T=a((e,t,r)=>{if(!t||w(t))return{body:e.toString(),json:!1};let o=f({outputStyle:r?.
|
|
17
|
+
namingStyle,convert:!1}),n=y(e,t,o);return{body:JSON.stringify(n),json:!0}},"pre\
|
|
18
|
+
pareRequestBody"),Pt=a(async(e,t,r,o)=>{let n=r?.namingStyle,s=f({convert:!1,inputStyle:n}),
|
|
19
|
+
m=I({onCustomValidation:a((c,d)=>D(c)||F(c)?o?.(y(c,d.schema,s),d):o?.(c,d),"use\
|
|
20
|
+
CustomValidation"),property:"$body",inputStyle:n}),p=await Q(e,t,m);if(p.length){
|
|
21
|
+
let c=J(p);throw new _("Malformed body payload.",c)}return y(e,t,s)},"resolveReq\
|
|
22
|
+
uestBody"),b=a((e,t,r)=>{if(!t||w(t))return e;let o=JSON.parse(e),n=f({outputStyle:k.
|
|
23
|
+
Preserve,inputStyle:r?.namingStyle,convert:!1});return y(o,t,n)},"prepareRespons\
|
|
24
|
+
eBody"),Vt=a((e,t,r)=>{let o=r?.namingStyle,n=f({convert:!1,outputStyle:o});return y(
|
|
25
|
+
e,t,n)},"resolveResponseBody");import{createTransformContext as G,transform as K}from"@ez4/transform";import{validate as L,
|
|
26
|
+
getUniqueErrorMessages as W,createValidatorContext as X}from"@ez4/validator";import{
|
|
27
|
+
HttpBadRequestError as Y}from"@ez4/gateway";var q=a((e,t)=>e.replaceAll(/\{(\w+)\}/g,(r,o)=>o in t?`${t[o]}`:`{${o}}`),"prep\
|
|
28
|
+
arePathParameters"),Nt=a(async(e,t,r)=>{let o=K(e,t,G({convert:!1})),n=X({property:"\
|
|
29
|
+
$path",onCustomValidation:r}),s=await L(o,t,n);if(s.length){let i=W(s);throw new Y(
|
|
30
|
+
"Malformed path parameters.",i)}return o},"resolvePathParameters");import{HttpBadRequestError as Z,HttpUnauthorizedError as tt,HttpForbiddenError as et,
|
|
31
|
+
HttpNotFoundError as rt,HttpUnsupportedMediaTypeError as ot,HttpUnprocessableEntityError as nt,
|
|
32
|
+
HttpError as at}from"@ez4/gateway";var It=a(({status:e,message:t,details:r})=>({status:e,body:{type:"error",message:t,
|
|
33
|
+
details:r}}),"getJsonError"),R=a((e,t,r)=>{switch(e){case 400:return new Z(t,r);case 401:
|
|
34
|
+
return new tt(t,r);case 403:return new et(t,r);case 404:return new rt(t,r);case 415:
|
|
35
|
+
return new ot(t,r);case 422:return new nt(t,r);default:return new at(e,t,r)}},"g\
|
|
36
|
+
etHttpException");var Kt=a((e,t,r)=>{let{parameters:o,query:n,querySchema:s,namingStyle:i}=r,m=o?q(
|
|
37
|
+
t,o):t,p=n&&C(n,s,{namingStyle:i}),l=[e];return m&&l.push(m),p&&l.push("?",p),l.
|
|
38
|
+
join("")},"getClientRequestUrl"),Lt=a(async(e,t,r)=>{let{authorization:o,headers:n,
|
|
39
|
+
body:s,bodySchema:i,responseSchema:m,namingStyle:p,timeout:l=20}=r,c=s?T(s,i,{namingStyle:p}):
|
|
40
|
+
void 0,d=new AbortController,j=setTimeout(()=>d?.abort("Request timed out"),l*1e3),
|
|
41
|
+
u=await fetch(e,{signal:d?.signal,body:c?.body,method:t,headers:{...n,...o&&{[o.
|
|
42
|
+
header]:o.value},...c?.json&&{"content-type":"application/json"}}});if(clearTimeout(
|
|
43
|
+
j),!u.ok){let h=await u.json();throw R(u.status,h.message,h.details)}let S=await u.
|
|
44
|
+
text();return{status:u.status,...S&&{body:b(S,m,{namingStyle:p})}}},"sendClientR\
|
|
45
|
+
equest");import{createTransformContext as st,transform as it}from"@ez4/transform";import{
|
|
46
|
+
validate as pt,createValidatorContext as ct,getUniqueErrorMessages as mt}from"@ez4/validator";
|
|
47
|
+
import{HttpBadRequestError as lt}from"@ez4/gateway";var ee=a(async(e,t,r)=>{let o=it(e,t,st({convert:!1})),n=ct({property:"$header",
|
|
48
|
+
onCustomValidation:r}),s=await pt(o,t,n);if(s.length){let i=mt(s);throw new lt("\
|
|
49
|
+
Malformed request headers.",i)}return o},"resolveHeaders");import{validate as dt,createValidatorContext as ut,getUniqueErrorMessages as yt}from"@ez4/validator";
|
|
50
|
+
import{HttpBadRequestError as ft}from"@ez4/gateway";var se=a(async(e,t,r)=>{let o=ut({property:"$identity",onCustomValidation:r}),n=await dt(
|
|
51
|
+
e,t,o);if(n.length){let s=yt(n);throw new ft("Malformed authorizer identity.",s)}
|
|
52
|
+
return e},"resolveIdentity");var E=a(e=>`@${e}`,"getValidatorName");var de=a(async(e,t,r)=>{let o=t[E(r)];o&&await o.validate(e)},"resolveValidation");export{Kt as getClientRequestUrl,R as getHttpException,It as getJsonError,q as preparePathParameters,
|
|
53
|
+
C as prepareQueryStrings,T as prepareRequestBody,b as prepareResponseBody,ee as resolveHeaders,
|
|
54
|
+
se as resolveIdentity,Nt as resolvePathParameters,vt as resolveQueryStrings,Pt as resolveRequestBody,
|
|
55
|
+
Vt as resolveResponseBody,de as resolveValidation,Lt as sendClientRequest};
|
|
54
56
|
//# sourceMappingURL=utils.mjs.map
|
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.37.0",
|
|
5
5
|
"author": "Silas B.",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"type": "module",
|
|
@@ -51,12 +51,12 @@
|
|
|
51
51
|
"live:publish": "npm run build && npm publish --access public"
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"@ez4/common": "^0.
|
|
55
|
-
"@ez4/project": "^0.
|
|
56
|
-
"@ez4/reflection": "^0.
|
|
57
|
-
"@ez4/schema": "^0.
|
|
58
|
-
"@ez4/transform": "^0.
|
|
59
|
-
"@ez4/utils": "^0.
|
|
60
|
-
"@ez4/validator": "^0.
|
|
54
|
+
"@ez4/common": "^0.37.0",
|
|
55
|
+
"@ez4/project": "^0.37.0",
|
|
56
|
+
"@ez4/reflection": "^0.37.0",
|
|
57
|
+
"@ez4/schema": "^0.37.0",
|
|
58
|
+
"@ez4/transform": "^0.37.0",
|
|
59
|
+
"@ez4/utils": "^0.37.0",
|
|
60
|
+
"@ez4/validator": "^0.37.0"
|
|
61
61
|
}
|
|
62
62
|
}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { AllType, SourceMap, TypeModel } from '@ez4/reflection';
|
|
2
|
-
import type { HttpProvider } from './types';
|
|
3
|
-
export declare const isHttpProviderDeclaration: (type: AllType) => type is TypeModel;
|
|
4
|
-
export declare const getHttpProviderMetadata: (type: AllType, parent: TypeModel, reflection: SourceMap, errorList: Error[]) => HttpProvider | undefined;
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { AllType, SourceMap, TypeIntersection, TypeModel, TypeObject } from '@ez4/reflection';
|
|
2
|
-
import type { ArraySchema, ObjectSchema, UnionSchema } from '@ez4/schema/library';
|
|
3
|
-
type TypeParent = TypeObject | TypeModel | TypeIntersection;
|
|
4
|
-
export declare const isWebBodyDeclaration: (type: TypeModel, namespace: string) => boolean;
|
|
5
|
-
export declare const getWebBodyMetadata: (type: AllType, parent: TypeParent, reflection: SourceMap, errorList: Error[], namespace: string) => import("@ez4/schema").BooleanSchema | import("@ez4/schema").NumberSchema | import("@ez4/schema").StringSchema | ObjectSchema | UnionSchema | ArraySchema | undefined;
|
|
6
|
-
export {};
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { AllType, SourceMap, TypeIntersection, TypeModel, TypeObject } from '@ez4/reflection';
|
|
2
|
-
type TypeParent = TypeObject | TypeModel | TypeIntersection;
|
|
3
|
-
export declare const isWebHeadersDeclaration: (type: TypeModel, namespace: string) => boolean;
|
|
4
|
-
export declare const getWebHeadersMetadata: (type: AllType, parent: TypeParent, reflection: SourceMap, errorList: Error[], namespace: string) => import("@ez4/schema").ObjectSchema | undefined;
|
|
5
|
-
export {};
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { AllType, SourceMap, TypeIntersection, TypeModel, TypeObject } from '@ez4/reflection';
|
|
2
|
-
type TypeParent = TypeObject | TypeModel | TypeIntersection;
|
|
3
|
-
export declare const isWebParametersDeclaration: (type: TypeModel, namespace: string) => boolean;
|
|
4
|
-
export declare const getWebParametersMetadata: (type: AllType, parent: TypeParent, reflection: SourceMap, errorList: Error[], namespace: string) => import("@ez4/schema").ObjectSchema | undefined;
|
|
5
|
-
export {};
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { AllType, SourceMap, TypeIntersection, TypeModel, TypeObject } from '@ez4/reflection';
|
|
2
|
-
type TypeParent = TypeObject | TypeModel | TypeIntersection;
|
|
3
|
-
export declare const isWebQueryDeclaration: (type: TypeModel, namespace: string) => boolean;
|
|
4
|
-
export declare const getWebQueryMetadata: (type: AllType, parent: TypeParent, reflection: SourceMap, errorList: Error[], namespace: string) => import("@ez4/schema").ObjectSchema | undefined;
|
|
5
|
-
export {};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|