@ez4/gateway 0.38.0 → 0.40.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/library.cjs +381 -381
- package/dist/library.mjs +353 -353
- package/dist/main.cjs +9 -9
- package/dist/main.mjs +9 -9
- package/dist/metadata/body.d.ts +1 -1
- package/dist/metadata/utils/name.d.ts +0 -1
- package/dist/services/errors.d.ts +10 -9
- package/dist/utils/errors.d.ts +5 -4
- package/dist/utils/validation.d.ts +1 -0
- package/dist/utils.cjs +56 -55
- package/dist/utils.mjs +53 -52
- package/package.json +12 -9
package/dist/main.cjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
"use strict";var a=Object.defineProperty;var
|
|
1
|
+
"use strict";var a=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var W=Object.getOwnPropertyNames;var A=Object.prototype.hasOwnProperty;var o=(r,e)=>a(r,"name",{value:e,configurable:!0});var H=(r,e)=>{for(var t in e)a(r,t,{get:e[t],enumerable:!0})},q=(r,e,t,n)=>{if(e&&
|
|
2
2
|
typeof e=="object"||typeof e=="function")for(let p of W(e))!A.call(r,p)&&p!==t&&
|
|
3
|
-
a(r,p,{get:()=>e[p],enumerable:!(n=
|
|
4
|
-
HttpError:()=>s,HttpForbiddenError:()=>
|
|
5
|
-
HttpUnauthorizedError:()=>
|
|
6
|
-
Ws:()=>R});module.exports=
|
|
7
|
-
o(this,"HttpError")}},
|
|
8
|
-
super(400,e||"Bad request",t)}},
|
|
9
|
-
dError")}constructor(e,t){super(401,e||"Unauthorized",t)}},
|
|
10
|
-
o(this,"HttpForbiddenError")}constructor(e,t){super(403,e||"Forbidden",t)}},
|
|
3
|
+
a(r,p,{get:()=>e[p],enumerable:!(n=T(e,p))||n.enumerable});return r};var S=r=>q(a({},"__esModule",{value:!0}),r);var b={};H(b,{AuthorizationType:()=>i,Http:()=>v,HttpBadRequestError:()=>y,HttpConflictError:()=>d,
|
|
4
|
+
HttpError:()=>s,HttpForbiddenError:()=>m,HttpInternalServerError:()=>f,HttpNotFoundError:()=>u,
|
|
5
|
+
HttpUnauthorizedError:()=>c,HttpUnprocessableEntityError:()=>l,HttpUnsupportedMediaTypeError:()=>x,
|
|
6
|
+
Ws:()=>R});module.exports=S(b);var i=(e=>(e.Bearer="bearer",e))(i||{});var R;(r=>{})(R||={});var v;(r=>{})(v||={});var h=require("@ez4/common");var s=class extends h.ServiceError{constructor(t,n,p){super(n,p);this.status=t}static{
|
|
7
|
+
o(this,"HttpError")}},y=class extends s{static{o(this,"HttpBadRequestError")}constructor(e,t){
|
|
8
|
+
super(400,e||"Bad request",t)}},c=class extends s{static{o(this,"HttpUnauthorize\
|
|
9
|
+
dError")}constructor(e,t){super(401,e||"Unauthorized",t)}},m=class extends s{static{
|
|
10
|
+
o(this,"HttpForbiddenError")}constructor(e,t){super(403,e||"Forbidden",t)}},u=class extends s{static{
|
|
11
11
|
o(this,"HttpNotFoundError")}constructor(e,t){super(404,e||"Not found",t)}},d=class extends s{static{
|
|
12
12
|
o(this,"HttpConflictError")}constructor(e,t){super(409,e||"Conflict",t)}},x=class extends s{static{
|
|
13
13
|
o(this,"HttpUnsupportedMediaTypeError")}constructor(e,t){super(415,e||"Unsupport\
|
package/dist/main.mjs
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
var f=Object.defineProperty;var s=(r,e)=>f(r,"name",{value:e,configurable:!0});var p=(e=>(e.Bearer="bearer",e))(p||{});var R;(r=>{})(R||={});var
|
|
1
|
+
var f=Object.defineProperty;var s=(r,e)=>f(r,"name",{value:e,configurable:!0});var p=(e=>(e.Bearer="bearer",e))(p||{});var R;(r=>{})(R||={});var v;(r=>{})(v||={});import{ServiceError as h}from"@ez4/common";var o=class extends h{constructor(t,x,l){super(x,l);this.status=t}static{s(this,
|
|
2
2
|
"HttpError")}},n=class extends o{static{s(this,"HttpBadRequestError")}constructor(e,t){
|
|
3
3
|
super(400,e||"Bad request",t)}},a=class extends o{static{s(this,"HttpUnauthorize\
|
|
4
|
-
dError")}constructor(e,t){super(401,e||"Unauthorized",t)}},
|
|
5
|
-
s(this,"HttpForbiddenError")}constructor(e,t){super(403,e||"Forbidden",t)}},
|
|
6
|
-
s(this,"HttpNotFoundError")}constructor(e,t){super(404,e||"Not found",t)}},
|
|
7
|
-
s(this,"HttpConflictError")}constructor(e,t){super(409,e||"Conflict",t)}},
|
|
4
|
+
dError")}constructor(e,t){super(401,e||"Unauthorized",t)}},i=class extends o{static{
|
|
5
|
+
s(this,"HttpForbiddenError")}constructor(e,t){super(403,e||"Forbidden",t)}},y=class extends o{static{
|
|
6
|
+
s(this,"HttpNotFoundError")}constructor(e,t){super(404,e||"Not found",t)}},c=class extends o{static{
|
|
7
|
+
s(this,"HttpConflictError")}constructor(e,t){super(409,e||"Conflict",t)}},m=class extends o{static{
|
|
8
8
|
s(this,"HttpUnsupportedMediaTypeError")}constructor(e,t){super(415,e||"Unsupport\
|
|
9
|
-
ed media type",t)}},
|
|
9
|
+
ed media type",t)}},u=class extends o{static{s(this,"HttpUnprocessableEntityErro\
|
|
10
10
|
r")}constructor(e,t){super(422,e||"Unprocessable entity",t)}},d=class extends o{static{
|
|
11
11
|
s(this,"HttpInternalServerError")}constructor(e,t){super(500,e||"Internal server\
|
|
12
|
-
error",t)}};export{p as AuthorizationType,
|
|
13
|
-
o as HttpError,
|
|
14
|
-
a as HttpUnauthorizedError,
|
|
12
|
+
error",t)}};export{p as AuthorizationType,v as Http,n as HttpBadRequestError,c as HttpConflictError,
|
|
13
|
+
o as HttpError,i as HttpForbiddenError,d as HttpInternalServerError,y as HttpNotFoundError,
|
|
14
|
+
a as HttpUnauthorizedError,u as HttpUnprocessableEntityError,m as HttpUnsupportedMediaTypeError,
|
|
15
15
|
R as Ws};
|
|
16
16
|
//# sourceMappingURL=main.mjs.map
|
package/dist/metadata/body.d.ts
CHANGED
|
@@ -2,5 +2,5 @@ import type { AllType, ReflectionTypes, TypeIntersection, TypeModel, TypeObject
|
|
|
2
2
|
import type { ArraySchema, ObjectSchema, UnionSchema } from '@ez4/schema';
|
|
3
3
|
type TypeParent = TypeObject | TypeModel | TypeIntersection;
|
|
4
4
|
export declare const isWebBodyDeclaration: (type: TypeModel, namespace: string) => boolean;
|
|
5
|
-
export declare const getWebBodyMetadata: (type: AllType, parent: TypeParent, reflection: ReflectionTypes, errorList: Error[], namespace: string) =>
|
|
5
|
+
export declare const getWebBodyMetadata: (type: AllType, parent: TypeParent, reflection: ReflectionTypes, errorList: Error[], namespace: string) => import("@ez4/schema").BooleanSchema | import("@ez4/schema").NumberSchema | import("@ez4/schema").StringSchema | ObjectSchema | UnionSchema | ArraySchema | undefined;
|
|
6
6
|
export {};
|
|
@@ -1,56 +1,57 @@
|
|
|
1
|
+
import type { ServiceErrorContext } from '@ez4/common';
|
|
1
2
|
import { ServiceError } from '@ez4/common';
|
|
2
3
|
/**
|
|
3
4
|
* Default HTTP error.
|
|
4
5
|
*/
|
|
5
6
|
export declare class HttpError extends ServiceError {
|
|
6
7
|
status: number;
|
|
7
|
-
constructor(status: number, message: string,
|
|
8
|
+
constructor(status: number, message: string, context?: ServiceErrorContext);
|
|
8
9
|
}
|
|
9
10
|
/**
|
|
10
11
|
* HTTP Bad Request error.
|
|
11
12
|
*/
|
|
12
13
|
export declare class HttpBadRequestError extends HttpError {
|
|
13
|
-
constructor(message?: string,
|
|
14
|
+
constructor(message?: string, context?: ServiceErrorContext);
|
|
14
15
|
}
|
|
15
16
|
/**
|
|
16
17
|
* HTTP Unauthorized error.
|
|
17
18
|
*/
|
|
18
19
|
export declare class HttpUnauthorizedError extends HttpError {
|
|
19
|
-
constructor(message?: string,
|
|
20
|
+
constructor(message?: string, context?: ServiceErrorContext);
|
|
20
21
|
}
|
|
21
22
|
/**
|
|
22
23
|
* HTTP Forbidden error.
|
|
23
24
|
*/
|
|
24
25
|
export declare class HttpForbiddenError extends HttpError {
|
|
25
|
-
constructor(message?: string,
|
|
26
|
+
constructor(message?: string, context?: ServiceErrorContext);
|
|
26
27
|
}
|
|
27
28
|
/**
|
|
28
29
|
* HTTP Not Found error.
|
|
29
30
|
*/
|
|
30
31
|
export declare class HttpNotFoundError extends HttpError {
|
|
31
|
-
constructor(message?: string,
|
|
32
|
+
constructor(message?: string, context?: ServiceErrorContext);
|
|
32
33
|
}
|
|
33
34
|
/**
|
|
34
35
|
* HTTP Conflict error.
|
|
35
36
|
*/
|
|
36
37
|
export declare class HttpConflictError extends HttpError {
|
|
37
|
-
constructor(message?: string,
|
|
38
|
+
constructor(message?: string, context?: ServiceErrorContext);
|
|
38
39
|
}
|
|
39
40
|
/**
|
|
40
41
|
* HTTP Unsupported Media Type error.
|
|
41
42
|
*/
|
|
42
43
|
export declare class HttpUnsupportedMediaTypeError extends HttpError {
|
|
43
|
-
constructor(message?: string,
|
|
44
|
+
constructor(message?: string, context?: ServiceErrorContext);
|
|
44
45
|
}
|
|
45
46
|
/**
|
|
46
47
|
* HTTP Unprocessable Entity error.
|
|
47
48
|
*/
|
|
48
49
|
export declare class HttpUnprocessableEntityError extends HttpError {
|
|
49
|
-
constructor(message?: string,
|
|
50
|
+
constructor(message?: string, context?: ServiceErrorContext);
|
|
50
51
|
}
|
|
51
52
|
/**
|
|
52
53
|
* HTTP Internal Server error.
|
|
53
54
|
*/
|
|
54
55
|
export declare class HttpInternalServerError extends HttpError {
|
|
55
|
-
constructor(message?: string,
|
|
56
|
+
constructor(message?: string, context?: ServiceErrorContext);
|
|
56
57
|
}
|
package/dist/utils/errors.d.ts
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
|
+
import type { ServiceErrorContext } from '@ez4/common';
|
|
1
2
|
import { HttpError } from '@ez4/gateway';
|
|
2
3
|
/**
|
|
3
4
|
* Get a JSON error response for the given HTTP error.
|
|
4
5
|
*
|
|
5
6
|
* @returns Returns an error response containing `status`, `message` and `details`.
|
|
6
7
|
*/
|
|
7
|
-
export declare const getJsonError: ({ status, message,
|
|
8
|
+
export declare const getJsonError: ({ status, message, context }: HttpError) => {
|
|
8
9
|
status: number;
|
|
9
10
|
body: {
|
|
10
11
|
type: string;
|
|
11
12
|
message: string;
|
|
12
|
-
|
|
13
|
+
context: ServiceErrorContext | undefined;
|
|
13
14
|
};
|
|
14
15
|
};
|
|
15
16
|
/**
|
|
@@ -17,7 +18,7 @@ export declare const getJsonError: ({ status, message, details }: HttpError) =>
|
|
|
17
18
|
*
|
|
18
19
|
* @param status HTTP status code.
|
|
19
20
|
* @param message Exception message.
|
|
20
|
-
* @param
|
|
21
|
+
* @param context Exception context.
|
|
21
22
|
* @returns Returns the corresponding exception.
|
|
22
23
|
*/
|
|
23
|
-
export declare const getHttpException: (status: number, message: string,
|
|
24
|
+
export declare const getHttpException: (status: number, message: string, context?: ServiceErrorContext) => HttpError;
|
package/dist/utils.cjs
CHANGED
|
@@ -1,63 +1,64 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var b=Object.defineProperty;var D=Object.getOwnPropertyDescriptor;var _=Object.getOwnPropertyNames;var G=Object.prototype.hasOwnProperty;var a=(e,t)=>b(e,"name",{value:t,configurable:!0});var K=(e,t)=>{for(var r in t)b(e,r,{get:t[r],enumerable:!0})},L=(e,t,r,o)=>{if(t&&
|
|
2
2
|
typeof t=="object"||typeof t=="function")for(let n of _(t))!G.call(e,n)&&n!==r&&
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
resolveHeaders:()=>nt,resolveIdentity:()=>at,resolvePathParameters:()=>tt,
|
|
6
|
-
resolveRequestBody:()=>Y,resolveResponseBody:()=>Z,resolveValidation:()=>
|
|
7
|
-
module.exports=W(
|
|
8
|
-
|
|
3
|
+
b(e,n,{get:()=>t[n],enumerable:!(o=D(t,n))||o.enumerable});return e};var W=e=>L(b({},"__esModule",{value:!0}),e);var st={};K(st,{getClientRequestUrl:()=>rt,getHttpException:()=>V,getJsonError:()=>et,
|
|
4
|
+
getValidatorName:()=>k,preparePathParameters:()=>O,prepareQueryStrings:()=>j,prepareRequestBody:()=>z,
|
|
5
|
+
prepareResponseBody:()=>P,resolveHeaders:()=>nt,resolveIdentity:()=>at,resolvePathParameters:()=>tt,
|
|
6
|
+
resolveQueryStrings:()=>X,resolveRequestBody:()=>Y,resolveResponseBody:()=>Z,resolveValidation:()=>it,
|
|
7
|
+
sendClientRequest:()=>ot});module.exports=W(st);var f=require("@ez4/transform"),S=require("@ez4/validator"),h=require("@ez4/utils"),
|
|
8
|
+
T=require("@ez4/schema"),M=require("@ez4/gateway");var j=a((e,t,r)=>{if(!t)return B(e);let o=(0,f.createTransformContext)({outputStyle:r?.
|
|
9
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,
|
|
11
|
-
{convert:!0,inputStyle:n}),
|
|
12
|
-
{property:"$query",pathStyle:n,onCustomValidation:o}),
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
q=require("@ez4/utils")
|
|
22
|
-
let o=(0,
|
|
10
|
+
rings"),X=a(async(e,t,r,o)=>{let n=r?.namingStyle,i=(0,f.createTransformContext)(
|
|
11
|
+
{convert:!0,inputStyle:n}),l=(0,f.transform)(e,t,i),m=(0,S.createValidatorContext)(
|
|
12
|
+
{property:"$query",pathStyle:n,onCustomValidation:o}),p=await(0,S.validate)(l,t,
|
|
13
|
+
m);if(p.length)throw new M.HttpBadRequestError("Malformed query strings.",{details:(0,S.getUniqueErrorMessages)(
|
|
14
|
+
p)});return l},"resolveQueryStrings"),B=a((e,t)=>{let r=[];for(let o in e){let n=t&&
|
|
15
|
+
(0,T.getSchemaProperty)(t,o),i=N(e[o],n);i&&r.push(`${o}=${encodeURIComponent(i)}`)}
|
|
16
|
+
if(r.length)return r.join("&")},"serializeQueryStrings"),N=a((e,t)=>{if(!(0,h.isNullish)(
|
|
17
|
+
e))return e instanceof Date?e.toISOString():e instanceof Array&&(!t||!(0,T.isArraySchema)(
|
|
18
|
+
t)||!t.definitions?.encoded)?e.map(n=>N(n,t)).filter(n=>(0,h.isNotNullish)(n)).join(
|
|
19
|
+
","):e instanceof Object?(0,h.base64Encode)(JSON.stringify(e)):`${e}`},"serializ\
|
|
20
|
+
eQueryStringValue");var c=require("@ez4/transform"),g=require("@ez4/validator"),w=require("@ez4/schema"),
|
|
21
|
+
q=require("@ez4/utils"),$=require("@ez4/gateway");var z=a((e,t,r)=>{if(!t||(0,w.isScalarSchema)(t))return{body:e.toString(),json:!1};
|
|
22
|
+
let o=(0,c.createTransformContext)({outputStyle:r?.namingStyle,convert:!1}),n=(0,c.transform)(
|
|
23
23
|
e,t,o);return{body:JSON.stringify(n),json:!0}},"prepareRequestBody"),Y=a(async(e,t,r,o)=>{
|
|
24
|
-
let n=r?.namingStyle,
|
|
25
|
-
{onCustomValidation:a((
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
e,t,
|
|
30
|
-
let o=JSON.parse(e),n=(0,
|
|
31
|
-
inputStyle:r?.namingStyle,convert:!1});return(0,
|
|
32
|
-
ponseBody"),Z=a((e,t,r)=>{let o=r?.namingStyle,n=(0,
|
|
33
|
-
outputStyle:o});return(0,
|
|
34
|
-
arePathParameters"),tt=a(async(e,t,r)=>{let o=(0,
|
|
24
|
+
let n=r?.namingStyle,i=(0,c.createTransformContext)({convert:!1,inputStyle:n}),m=(0,g.createValidatorContext)(
|
|
25
|
+
{onCustomValidation:a((d,y)=>(0,q.isAnyObject)(d)||(0,q.isAnyArray)(d)?o?.((0,c.transform)(
|
|
26
|
+
d,y.schema,i),y):o?.(d,y),"useCustomValidation"),property:"$body",inputStyle:n}),
|
|
27
|
+
p=await(0,g.validate)(e,t,m);if(p.length)throw new $.HttpBadRequestError("Malfor\
|
|
28
|
+
med body payload.",{details:(0,g.getUniqueErrorMessages)(p)});return(0,c.transform)(
|
|
29
|
+
e,t,i)},"resolveRequestBody"),P=a((e,t,r)=>{if(!t||(0,w.isScalarSchema)(t))return e;
|
|
30
|
+
let o=JSON.parse(e),n=(0,c.createTransformContext)({outputStyle:w.NamingStyle.Preserve,
|
|
31
|
+
inputStyle:r?.namingStyle,convert:!1});return(0,c.transform)(o,t,n)},"prepareRes\
|
|
32
|
+
ponseBody"),Z=a((e,t,r)=>{let o=r?.namingStyle,n=(0,c.createTransformContext)({convert:!1,
|
|
33
|
+
outputStyle:o});return(0,c.transform)(e,t,n)},"resolveResponseBody");var E=require("@ez4/transform"),x=require("@ez4/validator"),Q=require("@ez4/gateway");var O=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,E.transform)(e,t,(0,E.createTransformContext)(
|
|
35
35
|
{convert:!1})),n=(0,x.createValidatorContext)({property:"$path",onCustomValidation:r}),
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
t,r);case 401:return new
|
|
41
|
-
t,r);case 404:return new
|
|
42
|
-
t,r);case 415:return new
|
|
43
|
-
t,r);default:return new
|
|
44
|
-
t,o):t,
|
|
36
|
+
i=await(0,x.validate)(o,t,n);if(i.length)throw new Q.HttpBadRequestError("Malfor\
|
|
37
|
+
med path parameters.",{details:(0,x.getUniqueErrorMessages)(i)});return o},"reso\
|
|
38
|
+
lvePathParameters");var s=require("@ez4/gateway");var et=a(({status:e,message:t,context:r})=>({status:e,body:{type:"error",message:t,
|
|
39
|
+
context:r}}),"getJsonError"),V=a((e,t,r)=>{switch(e){case 400:return new s.HttpBadRequestError(
|
|
40
|
+
t,r);case 401:return new s.HttpUnauthorizedError(t,r);case 403:return new s.HttpForbiddenError(
|
|
41
|
+
t,r);case 404:return new s.HttpNotFoundError(t,r);case 409:return new s.HttpConflictError(
|
|
42
|
+
t,r);case 415:return new s.HttpUnsupportedMediaTypeError(t,r);case 422:return new s.HttpUnprocessableEntityError(
|
|
43
|
+
t,r);default:return new s.HttpError(e,t,r)}},"getHttpException");var rt=a((e,t,r)=>{let{parameters:o,query:n,querySchema:i,namingStyle:l}=r,m=o?O(
|
|
44
|
+
t,o):t,p=n&&j(n,i,{namingStyle:l}),u=[e];return m&&u.push(m),p&&u.push("?",p),u.
|
|
45
45
|
join("")},"getClientRequestUrl"),ot=a(async(e,t,r)=>{let{authorization:o,headers:n,
|
|
46
|
-
body:
|
|
46
|
+
body:i,bodySchema:l,responseSchema:m,namingStyle:p,timeout:u=20}=r,d=i?z(i,l,{namingStyle:p}):
|
|
47
47
|
void 0,y=new AbortController,F=setTimeout(()=>y?.abort("Request timed out"),u*1e3),
|
|
48
|
-
|
|
49
|
-
header]:o.value},...
|
|
50
|
-
F),!
|
|
51
|
-
text();return{status:
|
|
52
|
-
equest");var
|
|
48
|
+
v=await fetch(e,{signal:y?.signal,body:d?.body,method:t,headers:{...n,...o&&{[o.
|
|
49
|
+
header]:o.value},...d?.json&&{"content-type":"application/json"}}});if(clearTimeout(
|
|
50
|
+
F),!v.ok){let U=await v.json();throw V(v.status,U.message,U.context)}let A=await v.
|
|
51
|
+
text();return{status:v.status,...A&&{body:P(A,m,{namingStyle:p})}}},"sendClientR\
|
|
52
|
+
equest");var R=require("@ez4/transform"),H=require("@ez4/validator"),I=require("@ez4/gateway");var nt=a(async(e,t,r)=>{let o=(0,R.transform)(e,t,(0,R.createTransformContext)({
|
|
53
53
|
convert:!1})),n=(0,H.createValidatorContext)({property:"$header",onCustomValidation:r}),
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
onCustomValidation:r}),n=await(0,C.validate)(e,t,o);if(n.length)
|
|
58
|
-
|
|
59
|
-
"resolveIdentity");var k=a(e=>`@${e}`,"getValidatorName")
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
54
|
+
i=await(0,H.validate)(o,t,n);if(i.length)throw new I.HttpBadRequestError("Malfor\
|
|
55
|
+
med request headers.",{details:(0,H.getUniqueErrorMessages)(i)});return o},"reso\
|
|
56
|
+
lveHeaders");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)throw new J.HttpBadRequestError(
|
|
58
|
+
"Malformed authorizer identity.",{details:(0,C.getUniqueErrorMessages)(n)});return e},
|
|
59
|
+
"resolveIdentity");var k=a(e=>`@${e}`,"getValidatorName"),it=a(async(e,t,r)=>{let o=t[k(r)];o&&await o.
|
|
60
|
+
validate(e)},"resolveValidation");0&&(module.exports={getClientRequestUrl,getHttpException,getJsonError,getValidatorName,
|
|
61
|
+
preparePathParameters,prepareQueryStrings,prepareRequestBody,prepareResponseBody,
|
|
62
|
+
resolveHeaders,resolveIdentity,resolvePathParameters,resolveQueryStrings,resolveRequestBody,
|
|
63
|
+
resolveResponseBody,resolveValidation,sendClientRequest});
|
|
63
64
|
//# sourceMappingURL=utils.cjs.map
|
package/dist/utils.mjs
CHANGED
|
@@ -1,56 +1,57 @@
|
|
|
1
|
-
var
|
|
2
|
-
createValidatorContext as
|
|
3
|
-
base64Encode as
|
|
4
|
-
isArraySchema as
|
|
5
|
-
n=H(e,t,o);return g(n,t)},"prepareQueryStrings"),
|
|
6
|
-
namingStyle,
|
|
7
|
-
onCustomValidation:o}),
|
|
8
|
-
|
|
9
|
-
for(let o in e){let n=t&&
|
|
10
|
-
|
|
11
|
-
e))return e instanceof Date?e.toISOString():e instanceof Array&&(!t
|
|
12
|
-
encoded)?e.map(n=>
|
|
13
|
-
e)):`${e}`},"serializeQueryStringValue");import{createTransformContext as f,transform as y}from"@ez4/transform";import{validate as
|
|
14
|
-
createValidatorContext as
|
|
15
|
-
isScalarSchema as
|
|
16
|
-
import{HttpBadRequestError as
|
|
1
|
+
var j=Object.defineProperty;var a=(e,t)=>j(e,"name",{value:t,configurable:!0});import{createTransformContext as x,transform as H}from"@ez4/transform";import{validate as z,
|
|
2
|
+
createValidatorContext as P,getUniqueErrorMessages as O}from"@ez4/validator";import{
|
|
3
|
+
base64Encode as V,isNotNullish as A,isNullish as U}from"@ez4/utils";import{getSchemaProperty as B,
|
|
4
|
+
isArraySchema as M}from"@ez4/schema";import{HttpBadRequestError as N}from"@ez4/gateway";var C=a((e,t,r)=>{if(!t)return g(e);let o=x({outputStyle:r?.namingStyle,convert:!1}),
|
|
5
|
+
n=H(e,t,o);return g(n,t)},"prepareQueryStrings"),wt=a(async(e,t,r,o)=>{let n=r?.
|
|
6
|
+
namingStyle,i=x({convert:!0,inputStyle:n}),c=H(e,t,i),p=P({property:"$query",pathStyle:n,
|
|
7
|
+
onCustomValidation:o}),s=await z(c,t,p);if(s.length)throw new N("Malformed query\
|
|
8
|
+
strings.",{details:O(s)});return c},"resolveQueryStrings"),g=a((e,t)=>{let r=[];
|
|
9
|
+
for(let o in e){let n=t&&B(t,o),i=v(e[o],n);i&&r.push(`${o}=${encodeURIComponent(
|
|
10
|
+
i)}`)}if(r.length)return r.join("&")},"serializeQueryStrings"),v=a((e,t)=>{if(!U(
|
|
11
|
+
e))return e instanceof Date?e.toISOString():e instanceof Array&&(!t||!M(t)||!t.definitions?.
|
|
12
|
+
encoded)?e.map(n=>v(n,t)).filter(n=>A(n)).join(","):e instanceof Object?V(JSON.stringify(
|
|
13
|
+
e)):`${e}`},"serializeQueryStringValue");import{createTransformContext as f,transform as y}from"@ez4/transform";import{validate as $,
|
|
14
|
+
createValidatorContext as Q,getUniqueErrorMessages as I}from"@ez4/validator";import{
|
|
15
|
+
isScalarSchema as w,NamingStyle as J}from"@ez4/schema";import{isAnyArray as k,isAnyObject as F}from"@ez4/utils";
|
|
16
|
+
import{HttpBadRequestError as D}from"@ez4/gateway";var b=a((e,t,r)=>{if(!t||w(t))return{body:e.toString(),json:!1};let o=f({outputStyle:r?.
|
|
17
17
|
namingStyle,convert:!1}),n=y(e,t,o);return{body:JSON.stringify(n),json:!0}},"pre\
|
|
18
|
-
pareRequestBody"),
|
|
19
|
-
|
|
20
|
-
CustomValidation"),property:"$body",inputStyle:n}),
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
pareRequestBody"),Pt=a(async(e,t,r,o)=>{let n=r?.namingStyle,i=f({convert:!1,inputStyle:n}),
|
|
19
|
+
p=Q({onCustomValidation:a((m,d)=>F(m)||k(m)?o?.(y(m,d.schema,i),d):o?.(m,d),"use\
|
|
20
|
+
CustomValidation"),property:"$body",inputStyle:n}),s=await $(e,t,p);if(s.length)
|
|
21
|
+
throw new D("Malformed body payload.",{details:I(s)});return y(e,t,i)},"resolveR\
|
|
22
|
+
equestBody"),T=a((e,t,r)=>{if(!t||w(t))return e;let o=JSON.parse(e),n=f({outputStyle:J.
|
|
23
23
|
Preserve,inputStyle:r?.namingStyle,convert:!1});return y(o,t,n)},"prepareRespons\
|
|
24
|
-
eBody"),
|
|
25
|
-
e,t,n)},"resolveResponseBody");import{createTransformContext as
|
|
26
|
-
getUniqueErrorMessages as
|
|
27
|
-
HttpBadRequestError as
|
|
28
|
-
arePathParameters")
|
|
29
|
-
$path",onCustomValidation:r}),
|
|
30
|
-
|
|
31
|
-
HttpNotFoundError as
|
|
32
|
-
HttpUnprocessableEntityError as
|
|
33
|
-
|
|
34
|
-
return new
|
|
35
|
-
return new
|
|
36
|
-
return new
|
|
37
|
-
t,o):t,
|
|
24
|
+
eBody"),Ot=a((e,t,r)=>{let o=r?.namingStyle,n=f({convert:!1,outputStyle:o});return y(
|
|
25
|
+
e,t,n)},"resolveResponseBody");import{createTransformContext as _,transform as G}from"@ez4/transform";import{validate as K,
|
|
26
|
+
getUniqueErrorMessages as L,createValidatorContext as W}from"@ez4/validator";import{
|
|
27
|
+
HttpBadRequestError as X}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=G(e,t,_({convert:!1})),n=W({property:"\
|
|
29
|
+
$path",onCustomValidation:r}),i=await K(o,t,n);if(i.length)throw new X("Malforme\
|
|
30
|
+
d path parameters.",{details:L(i)});return o},"resolvePathParameters");import{HttpBadRequestError as Y,HttpUnauthorizedError as Z,HttpForbiddenError as tt,
|
|
31
|
+
HttpNotFoundError as et,HttpConflictError as rt,HttpUnsupportedMediaTypeError as ot,
|
|
32
|
+
HttpUnprocessableEntityError as nt,HttpError as at}from"@ez4/gateway";var Jt=a(({status:e,message:t,context:r})=>({status:e,body:{type:"error",message:t,
|
|
33
|
+
context:r}}),"getJsonError"),E=a((e,t,r)=>{switch(e){case 400:return new Y(t,r);case 401:
|
|
34
|
+
return new Z(t,r);case 403:return new tt(t,r);case 404:return new et(t,r);case 409:
|
|
35
|
+
return new rt(t,r);case 415:return new ot(t,r);case 422:return new nt(t,r);default:
|
|
36
|
+
return new at(e,t,r)}},"getHttpException");var Lt=a((e,t,r)=>{let{parameters:o,query:n,querySchema:i,namingStyle:c}=r,p=o?q(
|
|
37
|
+
t,o):t,s=n&&C(n,i,{namingStyle:c}),l=[e];return p&&l.push(p),s&&l.push("?",s),l.
|
|
38
38
|
join("")},"getClientRequestUrl"),Wt=a(async(e,t,r)=>{let{authorization:o,headers:n,
|
|
39
|
-
body:
|
|
40
|
-
void 0,d=new AbortController,
|
|
41
|
-
u=await fetch(e,{signal:d?.signal,body:
|
|
42
|
-
header]:o.value},...
|
|
43
|
-
|
|
44
|
-
text();return{status:u.status,...S&&{body:
|
|
45
|
-
equest");import{createTransformContext as it,transform as
|
|
46
|
-
validate as
|
|
47
|
-
import{HttpBadRequestError as
|
|
48
|
-
onCustomValidation:r}),
|
|
49
|
-
|
|
50
|
-
import{HttpBadRequestError as
|
|
51
|
-
e,t,o);if(n.length)
|
|
52
|
-
return e},"resolveIdentity");var
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
39
|
+
body:i,bodySchema:c,responseSchema:p,namingStyle:s,timeout:l=20}=r,m=i?b(i,c,{namingStyle:s}):
|
|
40
|
+
void 0,d=new AbortController,R=setTimeout(()=>d?.abort("Request timed out"),l*1e3),
|
|
41
|
+
u=await fetch(e,{signal:d?.signal,body:m?.body,method:t,headers:{...n,...o&&{[o.
|
|
42
|
+
header]:o.value},...m?.json&&{"content-type":"application/json"}}});if(clearTimeout(
|
|
43
|
+
R),!u.ok){let h=await u.json();throw E(u.status,h.message,h.context)}let S=await u.
|
|
44
|
+
text();return{status:u.status,...S&&{body:T(S,p,{namingStyle:s})}}},"sendClientR\
|
|
45
|
+
equest");import{createTransformContext as it,transform as st}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 re=a(async(e,t,r)=>{let o=st(e,t,it({convert:!1})),n=ct({property:"$header",
|
|
48
|
+
onCustomValidation:r}),i=await pt(o,t,n);if(i.length)throw new lt("Malformed req\
|
|
49
|
+
uest headers.",{details:mt(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)throw new ft("Malformed authorizer identity.",{details:yt(n)});
|
|
52
|
+
return e},"resolveIdentity");var St=a(e=>`@${e}`,"getValidatorName"),me=a(async(e,t,r)=>{let o=t[St(r)];o&&await o.
|
|
53
|
+
validate(e)},"resolveValidation");export{Lt as getClientRequestUrl,E as getHttpException,Jt as getJsonError,St as getValidatorName,
|
|
54
|
+
q as preparePathParameters,C as prepareQueryStrings,b as prepareRequestBody,T as prepareResponseBody,
|
|
55
|
+
re as resolveHeaders,se as resolveIdentity,Nt as resolvePathParameters,wt as resolveQueryStrings,
|
|
56
|
+
Pt as resolveRequestBody,Ot as resolveResponseBody,me as resolveValidation,Wt as sendClientRequest};
|
|
56
57
|
//# 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.40.0",
|
|
5
5
|
"author": "Silas B.",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"type": "module",
|
|
@@ -43,20 +43,23 @@
|
|
|
43
43
|
],
|
|
44
44
|
"scripts": {
|
|
45
45
|
"lint": "eslint --cache",
|
|
46
|
-
"clean": "rm -
|
|
46
|
+
"clean": "rm -rf dist/* *.tsbuildinfo .eslintcache",
|
|
47
47
|
"build": "tsc && node tools/bundler.mjs",
|
|
48
48
|
"test": "npm run build && tsc -p tsconfig.test.json && ez4 test",
|
|
49
49
|
"local:publish": "npm run build && npm run clean:registry && npm publish --registry http://localhost:4873",
|
|
50
50
|
"clean:registry": "rm -rf ../../.registry/@ez4/gateway",
|
|
51
51
|
"live:publish": "npm run build && npm publish --access public"
|
|
52
52
|
},
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"@ez4/validation": "^0.40.0"
|
|
55
|
+
},
|
|
53
56
|
"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.
|
|
57
|
+
"@ez4/common": "^0.40.0",
|
|
58
|
+
"@ez4/project": "^0.40.0",
|
|
59
|
+
"@ez4/reflection": "^0.40.0",
|
|
60
|
+
"@ez4/schema": "^0.40.0",
|
|
61
|
+
"@ez4/transform": "^0.40.0",
|
|
62
|
+
"@ez4/utils": "^0.40.0",
|
|
63
|
+
"@ez4/validator": "^0.40.0"
|
|
61
64
|
}
|
|
62
65
|
}
|