@ez4/gateway 0.35.1 → 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 +120 -2
- package/dist/client/authorization.d.ts +1 -1
- package/dist/client/operations.d.ts +1 -2
- package/dist/errors/auth/authorizer.d.ts +4 -0
- package/dist/errors/{identity.d.ts → auth/identity.d.ts} +4 -2
- package/dist/errors/body.d.ts +4 -2
- package/dist/errors/defaults.d.ts +4 -2
- package/dist/errors/headers.d.ts +4 -2
- package/dist/errors/{authorization.d.ts → http/authorization.d.ts} +4 -2
- package/dist/errors/{cache.d.ts → http/cache.d.ts} +4 -2
- package/dist/errors/{cors.d.ts → http/cors.d.ts} +5 -3
- package/dist/errors/parameters.d.ts +9 -3
- package/dist/errors/preferences.d.ts +4 -2
- package/dist/errors/query.d.ts +4 -2
- package/dist/errors/ws/event.d.ts +10 -0
- package/dist/errors/{authorizer.d.ts → ws/target.d.ts} +1 -1
- package/dist/library.cjs +464 -310
- package/dist/library.d.ts +17 -14
- package/dist/library.mjs +445 -293
- package/dist/main.cjs +15 -14
- package/dist/main.d.ts +5 -3
- package/dist/main.mjs +8 -6
- package/dist/metadata/auth/handler.d.ts +4 -0
- package/dist/metadata/auth/identity.d.ts +6 -0
- package/dist/metadata/auth/request.d.ts +4 -0
- package/dist/metadata/auth/response.d.ts +4 -0
- package/dist/metadata/auth/types.d.ts +20 -0
- package/dist/metadata/body.d.ts +4 -3
- package/dist/metadata/headers.d.ts +3 -2
- package/dist/metadata/http/access.d.ts +4 -0
- package/dist/metadata/http/authorization.d.ts +4 -0
- package/dist/metadata/http/cache.d.ts +4 -0
- package/dist/metadata/http/cors.d.ts +4 -0
- package/dist/metadata/http/defaults.d.ts +4 -0
- package/dist/metadata/http/errors.d.ts +4 -0
- package/dist/metadata/http/handler.d.ts +4 -0
- package/dist/metadata/http/import.d.ts +7 -0
- package/dist/metadata/http/request.d.ts +4 -0
- package/dist/metadata/http/response.d.ts +4 -0
- package/dist/metadata/http/routes.d.ts +5 -0
- package/dist/metadata/http/service.d.ts +7 -0
- package/dist/metadata/http/types.d.ts +117 -0
- package/dist/metadata/parameters.d.ts +3 -2
- package/dist/metadata/preferences.d.ts +4 -3
- package/dist/metadata/provider.d.ts +4 -3
- package/dist/metadata/query.d.ts +3 -2
- package/dist/metadata/types.d.ts +4 -0
- package/dist/metadata/utils/name.d.ts +2 -0
- package/dist/metadata/utils/path.d.ts +2 -0
- package/dist/metadata/utils/provider.d.ts +4 -0
- package/dist/metadata/utils/schema.d.ts +3 -0
- package/dist/metadata/utils/validator.d.ts +5 -0
- package/dist/metadata/ws/connection.d.ts +4 -0
- package/dist/metadata/ws/defaults.d.ts +5 -0
- package/dist/metadata/ws/event.d.ts +4 -0
- package/dist/metadata/ws/handlers.d.ts +4 -0
- package/dist/metadata/ws/message.d.ts +4 -0
- package/dist/metadata/ws/request.d.ts +4 -0
- package/dist/metadata/ws/response.d.ts +4 -0
- package/dist/metadata/ws/service.d.ts +7 -0
- package/dist/metadata/ws/types.d.ts +83 -0
- package/dist/services/auth/cache.d.ts +9 -0
- package/dist/services/auth/handler.d.ts +9 -0
- package/dist/services/auth/identity.d.ts +5 -0
- package/dist/services/auth/incoming.d.ts +22 -0
- package/dist/services/auth/provider.d.ts +11 -0
- package/dist/services/auth/request.d.ts +20 -0
- package/dist/services/auth/response.d.ts +10 -0
- package/dist/services/body.d.ts +13 -0
- package/dist/services/defaults.d.ts +7 -16
- package/dist/services/errors.d.ts +6 -0
- package/dist/services/headers.d.ts +10 -0
- package/dist/services/{client.d.ts → http/client.d.ts} +3 -3
- package/dist/services/{contract.d.ts → http/contract.d.ts} +45 -31
- package/dist/services/http/defaults.d.ts +17 -0
- package/dist/services/http/errors.d.ts +6 -0
- package/dist/services/http/handler.d.ts +10 -0
- package/dist/services/http/incoming.d.ts +30 -0
- package/dist/services/http/listener.d.ts +9 -0
- package/dist/services/http/path.d.ts +2 -0
- package/dist/services/http/request.d.ts +30 -0
- package/dist/services/http/response.d.ts +19 -0
- package/dist/services/http/route.d.ts +45 -0
- package/dist/services/{utils.d.ts → http/utils.d.ts} +13 -5
- package/dist/services/parameters.d.ts +5 -0
- package/dist/services/preferences.d.ts +2 -2
- package/dist/services/query.d.ts +5 -0
- package/dist/services/target.d.ts +27 -0
- package/dist/services/ws/client.d.ts +19 -0
- package/dist/services/ws/connect.d.ts +23 -0
- package/dist/services/ws/contract.d.ts +110 -0
- package/dist/services/ws/defaults.d.ts +13 -0
- package/dist/services/ws/disconnect.d.ts +17 -0
- package/dist/services/ws/event.d.ts +20 -0
- package/dist/services/ws/handler.d.ts +10 -0
- package/dist/services/ws/incoming.d.ts +19 -0
- package/dist/services/ws/listener.d.ts +9 -0
- package/dist/services/ws/message.d.ts +17 -0
- package/dist/services/ws/request.d.ts +15 -0
- package/dist/services/ws/response.d.ts +10 -0
- package/dist/services/ws/utils.d.ts +11 -0
- package/dist/utils/body.d.ts +4 -3
- package/dist/utils/client.d.ts +4 -4
- package/dist/utils/errors.d.ts +1 -0
- package/dist/utils/headers.d.ts +3 -2
- package/dist/utils/identity.d.ts +3 -2
- package/dist/utils/parameters.d.ts +3 -2
- package/dist/utils/query.d.ts +3 -2
- 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/access.d.ts +0 -3
- package/dist/metadata/authorization.d.ts +0 -3
- package/dist/metadata/authorizer.d.ts +0 -3
- package/dist/metadata/cache.d.ts +0 -3
- package/dist/metadata/cors.d.ts +0 -3
- package/dist/metadata/defaults.d.ts +0 -3
- package/dist/metadata/errors.d.ts +0 -4
- package/dist/metadata/handler.d.ts +0 -3
- package/dist/metadata/identity.d.ts +0 -5
- package/dist/metadata/import.d.ts +0 -6
- package/dist/metadata/request.d.ts +0 -4
- package/dist/metadata/response.d.ts +0 -4
- package/dist/metadata/route.d.ts +0 -4
- package/dist/metadata/schema.d.ts +0 -3
- package/dist/metadata/service.d.ts +0 -6
- package/dist/metadata/utils.d.ts +0 -24
- package/dist/services/cache.d.ts +0 -9
- package/dist/services/common.d.ts +0 -147
- package/dist/services/route.d.ts +0 -56
- package/dist/types/common.d.ts +0 -95
- package/dist/types/import.d.ts +0 -14
- package/dist/types/service.d.ts +0 -14
- /package/dist/errors/{access.d.ts → http/access.d.ts} +0 -0
- /package/dist/errors/{provider.d.ts → http/provider.d.ts} +0 -0
- /package/dist/errors/{route.d.ts → http/route.d.ts} +0 -0
- /package/dist/services/{access.d.ts → http/access.d.ts} +0 -0
- /package/dist/services/{authorization.d.ts → http/authorization.d.ts} +0 -0
- /package/dist/services/{cors.d.ts → http/cors.d.ts} +0 -0
- /package/dist/services/{provider.d.ts → http/provider.d.ts} +0 -0
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import type { Service as CommonService } from '@ez4/common';
|
|
2
|
+
import type { LinkedVariables } from '@ez4/project/library';
|
|
3
|
+
import type { AuthProvider as WsAuthProvider } from '../auth/provider';
|
|
4
|
+
import type { AuthResponse as WsAuthResponse } from '../auth/response';
|
|
5
|
+
import type { AuthRequest as WsAuthRequest } from '../auth/request';
|
|
6
|
+
import type { AuthIdentity } from '../auth/identity';
|
|
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';
|
|
11
|
+
import type { WsEmptyEvent, WsEmptyRequest } from './utils';
|
|
12
|
+
import type { WsDisconnect } from './disconnect';
|
|
13
|
+
import type { WsDefaults } from './defaults';
|
|
14
|
+
import type { WsIncoming } from './incoming';
|
|
15
|
+
import type { WsListener } from './listener';
|
|
16
|
+
import type { WsResponse } from './response';
|
|
17
|
+
import type { WsRequest } from './request';
|
|
18
|
+
import type { WsHandler } from './handler';
|
|
19
|
+
import type { WsMessage } from './message';
|
|
20
|
+
import type { WsConnect } from './connect';
|
|
21
|
+
import type { WsClient } from './client';
|
|
22
|
+
import type { WsEvent } from './event';
|
|
23
|
+
/**
|
|
24
|
+
* Provide all contracts for a self-managed WS service.
|
|
25
|
+
*/
|
|
26
|
+
export declare namespace Ws {
|
|
27
|
+
type Headers = WebHeaders;
|
|
28
|
+
type Identity = AuthIdentity;
|
|
29
|
+
type QueryStrings = WebQueryStrings;
|
|
30
|
+
type JsonBody = WebJsonBody;
|
|
31
|
+
type RawBody = WebRawBody;
|
|
32
|
+
type Preferences = WebPreferences;
|
|
33
|
+
type Request = WsRequest;
|
|
34
|
+
type Response = WsResponse;
|
|
35
|
+
type Event = WsEvent;
|
|
36
|
+
type AuthRequest = WsAuthRequest;
|
|
37
|
+
type AuthResponse = WsAuthResponse;
|
|
38
|
+
type AuthProvider = WsAuthProvider;
|
|
39
|
+
type Incoming<T extends Request | Event> = WsIncoming<T>;
|
|
40
|
+
type Listener<T extends Request | Event> = WsListener<T>;
|
|
41
|
+
type Handler<T extends Request | Event> = WsHandler<T>;
|
|
42
|
+
type Connect<T extends Event = Event, U extends AuthRequest = AuthRequest> = WsConnect<T, U>;
|
|
43
|
+
type Disconnect<T extends Event = Event> = WsDisconnect<T>;
|
|
44
|
+
type Message<T extends Request = Request> = WsMessage<T>;
|
|
45
|
+
type Defaults<T extends Request | Event = any> = WsDefaults<T>;
|
|
46
|
+
type ServiceEvent<T extends Request | Event = Event> = CommonService.AnyEvent<Incoming<T>>;
|
|
47
|
+
type EmptyRequest = WsEmptyRequest;
|
|
48
|
+
type EmptyEvent = WsEmptyEvent;
|
|
49
|
+
/**
|
|
50
|
+
* WS Defaults definition.
|
|
51
|
+
*/
|
|
52
|
+
type UseDefaults<T extends Defaults<any>> = T;
|
|
53
|
+
/**
|
|
54
|
+
* WS Preferences definition.
|
|
55
|
+
*/
|
|
56
|
+
type UsePreferences<T extends Preferences> = T;
|
|
57
|
+
/**
|
|
58
|
+
* WS Connect event definition.
|
|
59
|
+
*/
|
|
60
|
+
type UseConnect<T extends Connect<any, any>> = T;
|
|
61
|
+
/**
|
|
62
|
+
* WS Disconnect event definition.
|
|
63
|
+
*/
|
|
64
|
+
type UseDisconnect<T extends Disconnect<any>> = T;
|
|
65
|
+
/**
|
|
66
|
+
* WS Message event definition.
|
|
67
|
+
*/
|
|
68
|
+
type UseMessage<T extends Message<any>> = T;
|
|
69
|
+
/**
|
|
70
|
+
* WS service.
|
|
71
|
+
*/
|
|
72
|
+
abstract class Service<T extends JsonBody> implements CommonService.Provider {
|
|
73
|
+
/**
|
|
74
|
+
* All connection events.
|
|
75
|
+
*/
|
|
76
|
+
abstract readonly connect: Connect<any, any>;
|
|
77
|
+
/**
|
|
78
|
+
* All disconnection events.
|
|
79
|
+
*/
|
|
80
|
+
abstract readonly disconnect: Disconnect<any>;
|
|
81
|
+
/**
|
|
82
|
+
* All message events.
|
|
83
|
+
*/
|
|
84
|
+
abstract readonly message: Message<any>;
|
|
85
|
+
/**
|
|
86
|
+
* Default gateway parameters.
|
|
87
|
+
*/
|
|
88
|
+
readonly defaults?: Defaults<any>;
|
|
89
|
+
/**
|
|
90
|
+
* Display name for the service.
|
|
91
|
+
*/
|
|
92
|
+
readonly name?: string;
|
|
93
|
+
/**
|
|
94
|
+
* Service stage name.
|
|
95
|
+
*/
|
|
96
|
+
readonly stage?: string;
|
|
97
|
+
/**
|
|
98
|
+
* Service schema.
|
|
99
|
+
*/
|
|
100
|
+
readonly schema: T;
|
|
101
|
+
/**
|
|
102
|
+
* Variables associated to all routes.
|
|
103
|
+
*/
|
|
104
|
+
readonly variables?: LinkedVariables;
|
|
105
|
+
/**
|
|
106
|
+
* Service client.
|
|
107
|
+
*/
|
|
108
|
+
readonly client: WsClient<T>;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { WebDefaults } from '../defaults';
|
|
2
|
+
import type { WsRequest } from './request';
|
|
3
|
+
import type { WsListener } from './listener';
|
|
4
|
+
import type { WsEvent } from './event';
|
|
5
|
+
/**
|
|
6
|
+
* Default WS service parameters.
|
|
7
|
+
*/
|
|
8
|
+
export interface WsDefaults<T extends WsRequest | WsEvent> extends WebDefaults {
|
|
9
|
+
/**
|
|
10
|
+
* Default listener.
|
|
11
|
+
*/
|
|
12
|
+
readonly listener?: WsListener<T>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { WebTarget } from '../target';
|
|
2
|
+
import type { WsListener } from './listener';
|
|
3
|
+
import type { WsHandler } from './handler';
|
|
4
|
+
import type { WsEvent } from './event';
|
|
5
|
+
/**
|
|
6
|
+
* WS disconnect event.
|
|
7
|
+
*/
|
|
8
|
+
export interface WsDisconnect<T extends WsEvent> extends WebTarget {
|
|
9
|
+
/**
|
|
10
|
+
* Life-cycle listener function for the event.
|
|
11
|
+
*/
|
|
12
|
+
readonly listener?: WsListener<T>;
|
|
13
|
+
/**
|
|
14
|
+
* Entry-point handler function for the event.
|
|
15
|
+
*/
|
|
16
|
+
readonly handler: WsHandler<T>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { AuthIdentity } from '../auth/identity';
|
|
2
|
+
import type { WebQueryStrings } from '../query';
|
|
3
|
+
import type { WebHeaders } from '../headers';
|
|
4
|
+
/**
|
|
5
|
+
* WS event.
|
|
6
|
+
*/
|
|
7
|
+
export interface WsEvent {
|
|
8
|
+
/**
|
|
9
|
+
* Expected HTTP headers.
|
|
10
|
+
*/
|
|
11
|
+
readonly headers?: WebHeaders;
|
|
12
|
+
/**
|
|
13
|
+
* Expected HTTP query strings.
|
|
14
|
+
*/
|
|
15
|
+
readonly query?: WebQueryStrings;
|
|
16
|
+
/**
|
|
17
|
+
* Expected identity.
|
|
18
|
+
*/
|
|
19
|
+
readonly identity?: AuthIdentity;
|
|
20
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Service } from '@ez4/common';
|
|
2
|
+
import type { WsIncoming } from './incoming';
|
|
3
|
+
import type { WsResponse } from './response';
|
|
4
|
+
import type { WsRequest } from './request';
|
|
5
|
+
import type { WsEvent } from './event';
|
|
6
|
+
import type { Ws } from './contract';
|
|
7
|
+
/**
|
|
8
|
+
* WS request handler.
|
|
9
|
+
*/
|
|
10
|
+
export type WsHandler<T extends WsRequest | WsEvent> = (request: WsIncoming<T> | T, context: Service.Context<Ws.Service<any>>) => Promise<WsResponse | void> | WsResponse | void;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { WsRequest } from './request';
|
|
2
|
+
import type { WsEvent } from './event';
|
|
3
|
+
/**
|
|
4
|
+
* Incoming WS event.
|
|
5
|
+
*/
|
|
6
|
+
export type WsIncoming<T extends WsRequest | WsEvent> = T & {
|
|
7
|
+
/**
|
|
8
|
+
* Request tracking Id.
|
|
9
|
+
*/
|
|
10
|
+
readonly requestId: string;
|
|
11
|
+
/**
|
|
12
|
+
* Request connection Id.
|
|
13
|
+
*/
|
|
14
|
+
readonly connectionId: string;
|
|
15
|
+
/**
|
|
16
|
+
* Request timestamp.
|
|
17
|
+
*/
|
|
18
|
+
readonly timestamp: Date;
|
|
19
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Service } from '@ez4/common';
|
|
2
|
+
import type { WsIncoming } from './incoming';
|
|
3
|
+
import type { WsRequest } from './request';
|
|
4
|
+
import type { WsEvent } from './event';
|
|
5
|
+
import type { Ws } from './contract';
|
|
6
|
+
/**
|
|
7
|
+
* WS request listener.
|
|
8
|
+
*/
|
|
9
|
+
export type WsListener<T extends WsRequest | WsEvent> = (event: Service.AnyEvent<WsIncoming<T> | T>, context: Service.Context<Ws.Service<any>>) => Promise<void> | void;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { WebTarget } from '../target';
|
|
2
|
+
import type { WsListener } from './listener';
|
|
3
|
+
import type { WsHandler } from './handler';
|
|
4
|
+
import type { WsEvent } from './event';
|
|
5
|
+
/**
|
|
6
|
+
* WS message event.
|
|
7
|
+
*/
|
|
8
|
+
export interface WsMessage<T extends WsEvent> extends WebTarget {
|
|
9
|
+
/**
|
|
10
|
+
* Life-cycle listener function for the event.
|
|
11
|
+
*/
|
|
12
|
+
readonly listener?: WsListener<T>;
|
|
13
|
+
/**
|
|
14
|
+
* Entry-point handler function for the event.
|
|
15
|
+
*/
|
|
16
|
+
readonly handler: WsHandler<T>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { AuthIdentity } from '../auth/identity';
|
|
2
|
+
import type { WebBody } from '../body';
|
|
3
|
+
/**
|
|
4
|
+
* WS request.
|
|
5
|
+
*/
|
|
6
|
+
export interface WsRequest {
|
|
7
|
+
/**
|
|
8
|
+
* Expected identity.
|
|
9
|
+
*/
|
|
10
|
+
readonly identity?: AuthIdentity;
|
|
11
|
+
/**
|
|
12
|
+
* Expected event body.
|
|
13
|
+
*/
|
|
14
|
+
readonly body?: WebBody;
|
|
15
|
+
}
|
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
|
-
import type { Http } from '../services/contract';
|
|
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/client.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ArraySchema, ObjectSchema, ScalarSchema, UnionSchema, NamingStyle } from '@ez4/schema';
|
|
2
|
-
import type {
|
|
3
|
-
export type ClientRequestUrl =
|
|
2
|
+
import type { HttpClientRequest, HttpClientResponse } from '../services/http/client';
|
|
3
|
+
export type ClientRequestUrl = HttpClientRequest & {
|
|
4
4
|
querySchema?: ObjectSchema;
|
|
5
5
|
namingStyle?: NamingStyle;
|
|
6
6
|
};
|
|
@@ -9,10 +9,10 @@ export type RequestAuthorization = {
|
|
|
9
9
|
header: string;
|
|
10
10
|
value: string;
|
|
11
11
|
};
|
|
12
|
-
export type ClientRequestInput =
|
|
12
|
+
export type ClientRequestInput = HttpClientRequest & {
|
|
13
13
|
authorization?: RequestAuthorization;
|
|
14
14
|
responseSchema?: ObjectSchema | UnionSchema | ArraySchema | ScalarSchema;
|
|
15
15
|
bodySchema?: ObjectSchema | UnionSchema | ArraySchema | ScalarSchema;
|
|
16
16
|
namingStyle?: NamingStyle;
|
|
17
17
|
};
|
|
18
|
-
export declare const sendClientRequest: (url: string, method: string, request: ClientRequestInput) => Promise<
|
|
18
|
+
export declare const sendClientRequest: (url: string, method: string, request: ClientRequestInput) => Promise<HttpClientResponse>;
|
package/dist/utils/errors.d.ts
CHANGED
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
|
-
import type { Http } from '../services/contract';
|
|
3
|
-
export declare const
|
|
3
|
+
import type { Http } from '../services/http/contract';
|
|
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
|
-
import type { Http } from '../services/contract';
|
|
3
|
-
export declare const
|
|
3
|
+
import type { Http } from '../services/http/contract';
|
|
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
|
-
import type { Http } from '../services/contract';
|
|
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
|
-
import type { Http } from '../services/contract';
|
|
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';
|