@gravity-ui/gateway 4.1.1-alpha.0 → 4.2.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/commonjs → build}/components/grpc.d.ts +4 -4
- package/{dist/commonjs → build}/components/grpc.js +78 -85
- package/{dist/esm → build}/components/mixed.d.ts +4 -4
- package/{dist/commonjs → build}/components/mixed.js +12 -11
- package/{dist/commonjs → build}/components/rest.d.ts +5 -5
- package/{dist/commonjs → build}/components/rest.js +32 -32
- package/{dist/esm → build}/constants.d.ts +2 -2
- package/{dist/commonjs → build}/constants.js +18 -25
- package/{dist/commonjs → build}/index.d.ts +7 -8
- package/{dist/commonjs → build}/index.js +46 -32
- package/{dist/esm → build}/models/common.d.ts +14 -12
- package/{dist/esm → build}/models/context.d.ts +1 -0
- package/build/utils/axios.d.ts +4 -0
- package/{dist/commonjs → build}/utils/axios.js +6 -4
- package/{dist/esm → build}/utils/common.d.ts +3 -3
- package/{dist/commonjs → build}/utils/common.js +8 -7
- package/{dist/commonjs → build}/utils/create-context-api.d.ts +2 -2
- package/{dist/commonjs → build}/utils/create-context-api.js +6 -5
- package/{dist/commonjs → build}/utils/grpc-reflection.js +12 -21
- package/{dist/commonjs → build}/utils/grpc.js +8 -7
- package/build/utils/overrideEndpoints/index.d.ts +2 -0
- package/build/utils/overrideEndpoints/index.js +4 -0
- package/{dist/commonjs → build}/utils/overrideEndpoints/overrideEndpoints.d.ts +1 -1
- package/{dist/commonjs → build}/utils/overrideEndpoints/overrideEndpoints.js +2 -1
- package/{dist/esm → build}/utils/parse-error.d.ts +4 -4
- package/{dist/commonjs → build}/utils/parse-error.js +18 -18
- package/{dist/commonjs → build}/utils/proto-path-resolver.js +17 -23
- package/{dist/commonjs → build}/utils/redact-sensitive-headers.d.ts +2 -1
- package/{dist/commonjs → build}/utils/redact-sensitive-headers.js +2 -1
- package/{dist/commonjs → build}/utils/typed-api.d.ts +1 -1
- package/{dist/commonjs → build}/utils/typed-api.js +2 -1
- package/{dist/commonjs → build}/utils/validate.js +10 -6
- package/package.json +16 -41
- package/dist/commonjs/components/mixed.d.ts +0 -11
- package/dist/commonjs/constants.d.ts +0 -53
- package/dist/commonjs/models/common.d.ts +0 -272
- package/dist/commonjs/models/context.d.ts +0 -22
- package/dist/commonjs/package.json +0 -3
- package/dist/commonjs/utils/axios.d.ts +0 -3
- package/dist/commonjs/utils/common.d.ts +0 -15
- package/dist/commonjs/utils/overrideEndpoints/index.d.ts +0 -2
- package/dist/commonjs/utils/overrideEndpoints/index.js +0 -4
- package/dist/commonjs/utils/parse-error.d.ts +0 -30
- package/dist/commonjs/utils/source-dir.d.ts +0 -1
- package/dist/commonjs/utils/source-dir.js +0 -41
- package/dist/esm/components/grpc.d.ts +0 -24
- package/dist/esm/components/grpc.js +0 -641
- package/dist/esm/components/mixed.js +0 -62
- package/dist/esm/components/rest.d.ts +0 -8
- package/dist/esm/components/rest.js +0 -349
- package/dist/esm/constants.js +0 -79
- package/dist/esm/index.d.ts +0 -12
- package/dist/esm/index.js +0 -264
- package/dist/esm/models/common.js +0 -5
- package/dist/esm/models/context.js +0 -1
- package/dist/esm/models/error.d.ts +0 -12
- package/dist/esm/models/error.js +0 -1
- package/dist/esm/package.json +0 -3
- package/dist/esm/utils/axios.d.ts +0 -3
- package/dist/esm/utils/axios.js +0 -23
- package/dist/esm/utils/common.js +0 -38
- package/dist/esm/utils/create-context-api.d.ts +0 -4
- package/dist/esm/utils/create-context-api.js +0 -38
- package/dist/esm/utils/grpc-reflection.d.ts +0 -28
- package/dist/esm/utils/grpc-reflection.js +0 -68
- package/dist/esm/utils/grpc.d.ts +0 -5
- package/dist/esm/utils/grpc.js +0 -39
- package/dist/esm/utils/overrideEndpoints/index.d.ts +0 -2
- package/dist/esm/utils/overrideEndpoints/index.js +0 -2
- package/dist/esm/utils/overrideEndpoints/overrideEndpoints.d.ts +0 -17
- package/dist/esm/utils/overrideEndpoints/overrideEndpoints.js +0 -96
- package/dist/esm/utils/parse-error.js +0 -210
- package/dist/esm/utils/proto-path-resolver.d.ts +0 -2
- package/dist/esm/utils/proto-path-resolver.js +0 -23
- package/dist/esm/utils/redact-sensitive-headers.d.ts +0 -3
- package/dist/esm/utils/redact-sensitive-headers.js +0 -12
- package/dist/esm/utils/source-dir.d.ts +0 -1
- package/dist/esm/utils/source-dir.js +0 -4
- package/dist/esm/utils/typed-api.d.ts +0 -2
- package/dist/esm/utils/typed-api.js +0 -3
- package/dist/esm/utils/validate.d.ts +0 -4
- package/dist/esm/utils/validate.js +0 -47
- /package/bin/{patch.cjs → patch.js} +0 -0
- /package/{dist/commonjs → build}/models/common.js +0 -0
- /package/{dist/commonjs → build}/models/context.js +0 -0
- /package/{dist/commonjs → build}/models/error.d.ts +0 -0
- /package/{dist/commonjs → build}/models/error.js +0 -0
- /package/{dist/commonjs → build}/utils/grpc-reflection.d.ts +0 -0
- /package/{dist/commonjs → build}/utils/grpc.d.ts +0 -0
- /package/{dist/commonjs → build}/utils/proto-path-resolver.d.ts +0 -0
- /package/{dist/commonjs → build}/utils/validate.d.ts +0 -0
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import * as http from 'http';
|
|
2
|
-
import * as https from 'https';
|
|
3
|
-
import * as grpc from '@grpc/grpc-js';
|
|
4
|
-
export declare const VERSION: any;
|
|
5
|
-
export declare enum Lang {
|
|
6
|
-
Ru = "ru",
|
|
7
|
-
En = "en"
|
|
8
|
-
}
|
|
9
|
-
export declare const DEFAULT_TIMEOUT: number;
|
|
10
|
-
export declare const DEFAULT_LANG_HEADER = "accept-language";
|
|
11
|
-
export declare const DEFAULT_PROXY_HEADERS: string[];
|
|
12
|
-
export declare const DEFAULT_AXIOS_OPTIONS: {
|
|
13
|
-
maxContentLength: number;
|
|
14
|
-
httpAgent: http.Agent;
|
|
15
|
-
httpsAgent: https.Agent;
|
|
16
|
-
};
|
|
17
|
-
export declare const DEFAULT_GRPC_OPTIONS: {
|
|
18
|
-
'grpc.max_receive_message_length': number;
|
|
19
|
-
'grpc.keepalive_time_ms': number;
|
|
20
|
-
'grpc.keepalive_timeout_ms': number;
|
|
21
|
-
'grpc.keepalive_permit_without_calls': number;
|
|
22
|
-
};
|
|
23
|
-
export declare const DEFAULT_PROTO_LOADER_OPTIONS: {
|
|
24
|
-
longs: StringConstructor;
|
|
25
|
-
enums: StringConstructor;
|
|
26
|
-
defaults: boolean;
|
|
27
|
-
oneofs: boolean;
|
|
28
|
-
};
|
|
29
|
-
/**
|
|
30
|
-
* Byte sizes are taken from ECMAScript Language Specification
|
|
31
|
-
* http://www.ecma-international.org/ecma-262/5.1/
|
|
32
|
-
*/
|
|
33
|
-
export declare const ECMA_STRING_SIZE = 2;
|
|
34
|
-
export declare const ANY_ACTION_SYMBOL = "*";
|
|
35
|
-
export declare const RETRYABLE_STATUS_CODES: Array<grpc.status | undefined>;
|
|
36
|
-
export declare const RECREATE_SERVICE_CODES: Array<grpc.status | undefined>;
|
|
37
|
-
/**
|
|
38
|
-
* Common validation schema for action's parameters. You can use it in GatewayConfig as validationSchema
|
|
39
|
-
* Validates the parameter type: only number, object, or string are allowed.
|
|
40
|
-
* For strings, disallows characters: ".", "?", "#", "/", "\"
|
|
41
|
-
*/
|
|
42
|
-
export declare const DEFAULT_VALIDATION_SCHEMA: {
|
|
43
|
-
additionalProperties: {
|
|
44
|
-
oneOf: ({
|
|
45
|
-
type: string;
|
|
46
|
-
pattern?: undefined;
|
|
47
|
-
} | {
|
|
48
|
-
type: string;
|
|
49
|
-
pattern: string;
|
|
50
|
-
})[];
|
|
51
|
-
};
|
|
52
|
-
};
|
|
53
|
-
export declare const AXIOS_RETRY_NAMESPACE = "axios-retry";
|
|
@@ -1,272 +0,0 @@
|
|
|
1
|
-
import { IncomingHttpHeaders } from 'http';
|
|
2
|
-
import { ClientDuplexStream, ClientReadableStream, ClientWritableStream } from '@grpc/grpc-js';
|
|
3
|
-
import type { HandlerType } from '@grpc/grpc-js/build/src/server-call.js';
|
|
4
|
-
import { AxiosInterceptorManager, AxiosRequestConfig, AxiosResponse, InternalAxiosRequestConfig } from 'axios';
|
|
5
|
-
import type { Request, Response } from 'express';
|
|
6
|
-
import * as protobufjs from 'protobufjs';
|
|
7
|
-
import type { GrpcContext } from '../components/grpc.js';
|
|
8
|
-
import { Lang } from '../constants.js';
|
|
9
|
-
import { GatewayContext } from './context.js';
|
|
10
|
-
import { AppErrorConstructor } from './error.js';
|
|
11
|
-
export interface GatewayRequest<Context extends GatewayContext> extends Request {
|
|
12
|
-
id: string;
|
|
13
|
-
ctx: Context;
|
|
14
|
-
}
|
|
15
|
-
export interface GatewayResponse extends Response {
|
|
16
|
-
}
|
|
17
|
-
export interface Headers {
|
|
18
|
-
[key: string]: any;
|
|
19
|
-
}
|
|
20
|
-
export interface EndpointsConfig {
|
|
21
|
-
[key: string]: ActionEndpoint;
|
|
22
|
-
}
|
|
23
|
-
export type AuthHeadersFunc = (serviceName: string) => Record<string, string> | undefined;
|
|
24
|
-
export interface ApiActionConfig<Context extends GatewayContext, TRequestData, TResponseData = any> {
|
|
25
|
-
requestId: string;
|
|
26
|
-
headers: Headers;
|
|
27
|
-
args: TRequestData;
|
|
28
|
-
ctx: Context;
|
|
29
|
-
timeout?: number;
|
|
30
|
-
callback?: (response: TResponseData) => void;
|
|
31
|
-
authArgs?: Record<string, unknown>;
|
|
32
|
-
userId?: string;
|
|
33
|
-
}
|
|
34
|
-
export interface GRPCActionData {
|
|
35
|
-
[key: string]: unknown;
|
|
36
|
-
}
|
|
37
|
-
export type SendStats<Context extends GatewayContext> = (stats: Stats, headers: IncomingHttpHeaders, ctx: Context, meta: {
|
|
38
|
-
debugHeaders: Headers;
|
|
39
|
-
}) => void;
|
|
40
|
-
export interface Stats {
|
|
41
|
-
service: string;
|
|
42
|
-
action: string;
|
|
43
|
-
restStatus: number;
|
|
44
|
-
grpcStatus?: number;
|
|
45
|
-
responseSize: number;
|
|
46
|
-
requestId: string;
|
|
47
|
-
requestTime: number;
|
|
48
|
-
requestMethod: string;
|
|
49
|
-
requestUrl: string;
|
|
50
|
-
timestamp: number;
|
|
51
|
-
userId?: string;
|
|
52
|
-
traceId: string;
|
|
53
|
-
}
|
|
54
|
-
export type ControllerType = 'rest' | 'grpc';
|
|
55
|
-
export interface GatewayError {
|
|
56
|
-
status: number;
|
|
57
|
-
message: string;
|
|
58
|
-
code: string;
|
|
59
|
-
details?: {
|
|
60
|
-
title?: string;
|
|
61
|
-
description?: string;
|
|
62
|
-
} & Record<string, unknown>;
|
|
63
|
-
debug?: any;
|
|
64
|
-
requestId?: string;
|
|
65
|
-
}
|
|
66
|
-
export type ProxyHeadersFunction = (headers: IncomingHttpHeaders, type: ControllerType) => IncomingHttpHeaders;
|
|
67
|
-
export type ProxyHeaders = string[] | ProxyHeadersFunction;
|
|
68
|
-
export type ProxyResponseHeadersFunction = (headers: Headers, type: ControllerType) => Headers;
|
|
69
|
-
export type ProxyResponseHeaders = string[] | ProxyResponseHeadersFunction;
|
|
70
|
-
export type GetAuthHeadersParams<AuthArgs = Record<string, unknown>> = {
|
|
71
|
-
actionType: ControllerType;
|
|
72
|
-
serviceName: string;
|
|
73
|
-
requestHeaders: Headers;
|
|
74
|
-
authArgs: AuthArgs | undefined;
|
|
75
|
-
};
|
|
76
|
-
export type GetAuthHeaders<AuthArgs = Record<string, unknown>> = (params: GetAuthHeadersParams<AuthArgs>) => Record<string, string> | undefined;
|
|
77
|
-
export type ResponseContentType = AxiosResponse['headers']['Content-Type'];
|
|
78
|
-
export interface GatewayApiOptions<Context extends GatewayContext> {
|
|
79
|
-
serviceName: string;
|
|
80
|
-
timeout?: number;
|
|
81
|
-
sendStats?: SendStats<Context>;
|
|
82
|
-
grpcOptions?: object;
|
|
83
|
-
grpcRecreateService?: boolean;
|
|
84
|
-
axiosConfig?: AxiosRequestConfig;
|
|
85
|
-
axiosInterceptors?: AxiosInterceptorsConfig;
|
|
86
|
-
proxyHeaders?: ProxyHeaders;
|
|
87
|
-
proxyDebugHeaders?: ProxyHeaders;
|
|
88
|
-
validationSchema?: object;
|
|
89
|
-
encodePathArgs?: boolean;
|
|
90
|
-
expectedResponseContentType?: ResponseContentType | ResponseContentType[];
|
|
91
|
-
getAuthHeaders: GetAuthHeaders;
|
|
92
|
-
}
|
|
93
|
-
export interface ParamsOutput {
|
|
94
|
-
body?: any;
|
|
95
|
-
query?: {
|
|
96
|
-
[key: string]: any;
|
|
97
|
-
};
|
|
98
|
-
headers?: Headers;
|
|
99
|
-
}
|
|
100
|
-
export interface ResponseError extends AxiosResponse<unknown> {
|
|
101
|
-
}
|
|
102
|
-
export interface ExtendedBaseActionEndpoint {
|
|
103
|
-
path: string;
|
|
104
|
-
}
|
|
105
|
-
export interface ExtendedGrpcActionEndpoint extends ExtendedBaseActionEndpoint {
|
|
106
|
-
insecure?: boolean;
|
|
107
|
-
secureWithoutRootCert?: boolean;
|
|
108
|
-
grpcOptions?: object;
|
|
109
|
-
}
|
|
110
|
-
export interface ExtendedRestActionEndpoint extends ExtendedBaseActionEndpoint {
|
|
111
|
-
axiosConfig?: AxiosRequestConfig;
|
|
112
|
-
}
|
|
113
|
-
export type ExtendedActionEndpoint = ExtendedGrpcActionEndpoint | ExtendedRestActionEndpoint;
|
|
114
|
-
export type ActionEndpoint = string | ExtendedActionEndpoint;
|
|
115
|
-
export interface ApiServiceBaseActionConfig<Context extends GatewayContext, TOutput, TParams = undefined, TTransformed = TOutput> {
|
|
116
|
-
getAuthHeaders?: GetAuthHeaders;
|
|
117
|
-
params?: (args: TParams, headers: Headers, config: ApiParamsConfig<Context>) => Promise<ParamsOutput> | ParamsOutput;
|
|
118
|
-
endpoint?: string | ((endpoints: EndpointsConfig | undefined, args: TParams) => string);
|
|
119
|
-
transformResponseData?: (data: TOutput, config: ApiTransformResponseDataConfig<TParams, Context>) => Promise<TTransformed> | TTransformed;
|
|
120
|
-
transformResponseError?: (error: ResponseError, config: ApiTransformResponseErrorConfig<TParams, Context>) => Promise<GatewayError> | GatewayError;
|
|
121
|
-
validationSchema?: object;
|
|
122
|
-
timeout?: number;
|
|
123
|
-
retries?: number;
|
|
124
|
-
idempotency?: boolean;
|
|
125
|
-
proxyHeaders?: ProxyHeaders;
|
|
126
|
-
proxyResponseHeaders?: ProxyResponseHeaders;
|
|
127
|
-
metadata?: Record<string, string | number | boolean>;
|
|
128
|
-
}
|
|
129
|
-
export interface ApiServiceRestActionConfig<Context extends GatewayContext, TOutput, TParams = undefined, TTransformed = TOutput> extends ApiServiceBaseActionConfig<Context, TOutput, TParams, TTransformed> {
|
|
130
|
-
method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS';
|
|
131
|
-
path: (args: TParams) => string;
|
|
132
|
-
paramsSerializer?: AxiosRequestConfig['paramsSerializer'];
|
|
133
|
-
responseType?: AxiosRequestConfig['responseType'];
|
|
134
|
-
expectedResponseContentType?: ResponseContentType | ResponseContentType[];
|
|
135
|
-
maxRedirects?: number;
|
|
136
|
-
}
|
|
137
|
-
export interface ApiServiceBaseGrpcActionConfig<Context extends GatewayContext, TOutput, TParams = undefined, TTransformed = TOutput> extends ApiServiceBaseActionConfig<Context, TOutput, TParams, TTransformed> {
|
|
138
|
-
action: string;
|
|
139
|
-
protoKey: string;
|
|
140
|
-
insecure?: boolean;
|
|
141
|
-
secureWithoutRootCert?: boolean;
|
|
142
|
-
encodedFields?: string[];
|
|
143
|
-
type?: HandlerType;
|
|
144
|
-
decodeAnyMessageProtoLoaderOptions?: protobufjs.IConversionOptions;
|
|
145
|
-
}
|
|
146
|
-
export interface ApiServiceFileGrpcActionConfig<Context extends GatewayContext, TOutput, TParams, TTransformed> extends ApiServiceBaseGrpcActionConfig<Context, TOutput, TParams, TTransformed> {
|
|
147
|
-
protoPath: string;
|
|
148
|
-
}
|
|
149
|
-
export declare enum GrpcReflection {
|
|
150
|
-
OnFirstRequest = 0,
|
|
151
|
-
OnEveryRequest = 1
|
|
152
|
-
}
|
|
153
|
-
export interface ApiServiceReflectGrpcActionConfig<Context extends GatewayContext, TOutput, TParams, TTransformed> extends ApiServiceBaseGrpcActionConfig<Context, TOutput, TParams, TTransformed> {
|
|
154
|
-
reflection: GrpcReflection;
|
|
155
|
-
reflectionRefreshSec?: number;
|
|
156
|
-
}
|
|
157
|
-
export type ApiServiceGrpcActionConfig<Context extends GatewayContext, TOutput, TParams = undefined, TTransformed = TOutput> = ApiServiceFileGrpcActionConfig<Context, TOutput, TParams, TTransformed> | ApiServiceReflectGrpcActionConfig<Context, TOutput, TParams, TTransformed>;
|
|
158
|
-
export interface ApiServiceMixedExtra<Context extends GatewayContext, Req extends GatewayRequest<Context>, Res extends GatewayResponse> {
|
|
159
|
-
headers: Headers;
|
|
160
|
-
lang: Lang;
|
|
161
|
-
ctx: Context;
|
|
162
|
-
config: GatewayConfig<Context, Req, Res>;
|
|
163
|
-
grpcContext: GrpcContext;
|
|
164
|
-
}
|
|
165
|
-
export type ApiServiceMixedActionConfig<Context extends GatewayContext, Req extends GatewayRequest<Context>, Res extends GatewayResponse, TOutput, TParams = undefined, TTransformed = TOutput> = (api: unknown, args: TParams, extra: ApiServiceMixedExtra<Context, Req, Res>) => Promise<TTransformed>;
|
|
166
|
-
export type ApiServiceActionConfig<Context extends GatewayContext, Req extends GatewayRequest<Context>, Res extends GatewayResponse, TOutput, TParams = undefined, TTransformed = TOutput> = ApiServiceRestActionConfig<Context, TOutput, TParams, TTransformed> | ApiServiceGrpcActionConfig<Context, TOutput, TParams, TTransformed> | ApiServiceMixedActionConfig<Context, Req, Res, TOutput, TParams, TTransformed>;
|
|
167
|
-
export type ApiActionResponseType<T> = T extends ApiServiceActionConfig<any, any, any, any, any, infer R> ? R : never;
|
|
168
|
-
export type ApiActionParams<T> = T extends ApiServiceActionConfig<any, any, any, any, infer R, any> ? R : never;
|
|
169
|
-
export interface ApiParamsConfig<Context extends GatewayContext> {
|
|
170
|
-
ctx: Context;
|
|
171
|
-
}
|
|
172
|
-
export interface ApiTransformResponseDataConfig<TParams, Context extends GatewayContext> {
|
|
173
|
-
args: TParams;
|
|
174
|
-
ctx: Context;
|
|
175
|
-
headers?: Headers;
|
|
176
|
-
}
|
|
177
|
-
export interface ApiTransformResponseErrorConfig<TParams, Context extends GatewayContext> {
|
|
178
|
-
args: TParams;
|
|
179
|
-
ctx: Context;
|
|
180
|
-
}
|
|
181
|
-
export interface BaseSchema {
|
|
182
|
-
[key: string]: {
|
|
183
|
-
actions: Record<string, ApiServiceActionConfig<any, any, any, any, any, any>>;
|
|
184
|
-
serviceName?: string;
|
|
185
|
-
endpoints?: Record<string, Record<string, EndpointsConfig>>;
|
|
186
|
-
};
|
|
187
|
-
}
|
|
188
|
-
export interface SchemasByScope {
|
|
189
|
-
[scope: string]: BaseSchema;
|
|
190
|
-
}
|
|
191
|
-
export type ApiByScope<R extends SchemasByScope, Context extends GatewayContext, Req extends GatewayRequest<Context>, Res extends GatewayResponse> = {
|
|
192
|
-
[scope in keyof R]: GatewayApi<R[scope], Context, Req, Res>;
|
|
193
|
-
};
|
|
194
|
-
export type ApiWithRoot<R extends SchemasByScope, Context extends GatewayContext, Req extends GatewayRequest<Context>, Res extends GatewayResponse> = ApiByScope<R, Context, Req, Res>['root'] & ApiByScope<R, Context, Req, Res>;
|
|
195
|
-
export interface GatewayActionHeaders {
|
|
196
|
-
debugHeaders: Headers;
|
|
197
|
-
}
|
|
198
|
-
export interface GatewayActionUnaryResponse<TAction> extends GatewayActionHeaders {
|
|
199
|
-
responseData: ApiActionResponseType<TAction>;
|
|
200
|
-
responseHeaders?: Headers;
|
|
201
|
-
}
|
|
202
|
-
export interface GatewayActionClientStreamResponse<TAction> extends GatewayActionHeaders {
|
|
203
|
-
stream: ClientWritableStream<ApiActionResponseType<TAction>>;
|
|
204
|
-
responseData?: never;
|
|
205
|
-
responseHeaders?: never;
|
|
206
|
-
}
|
|
207
|
-
export interface GatewayActionServerStreamResponse<TAction> extends GatewayActionHeaders {
|
|
208
|
-
stream: ClientReadableStream<ApiActionResponseType<TAction>>;
|
|
209
|
-
responseData?: never;
|
|
210
|
-
responseHeaders?: never;
|
|
211
|
-
}
|
|
212
|
-
export interface GatewayActionDuplexStreamResponse<TAction> extends GatewayActionHeaders {
|
|
213
|
-
stream: ClientDuplexStream<ApiActionParams<TAction>, ApiActionResponseType<TAction>>;
|
|
214
|
-
responseData?: never;
|
|
215
|
-
responseHeaders?: never;
|
|
216
|
-
}
|
|
217
|
-
export type GatewayActionResponseData<Context extends GatewayContext, Req extends GatewayRequest<Context>, Res extends GatewayResponse, TAction extends ApiServiceActionConfig<Context, Req, Res, unknown, unknown, unknown>> = TAction extends ApiServiceGrpcActionConfig<Context, unknown, unknown, unknown> ? TAction['type'] extends 'clientStream' ? GatewayActionClientStreamResponse<TAction> : TAction['type'] extends 'serverStream' ? GatewayActionServerStreamResponse<TAction> : TAction['type'] extends 'bidi' ? GatewayActionDuplexStreamResponse<TAction> : GatewayActionUnaryResponse<TAction> : GatewayActionUnaryResponse<TAction>;
|
|
218
|
-
type GatewayAction<Context extends GatewayContext, Req extends GatewayRequest<Context>, Res extends GatewayResponse, TAction extends ApiServiceActionConfig<Context, Req, Res, unknown, unknown, unknown>> = undefined extends ApiActionParams<TAction> ? (params?: ApiActionConfig<Context, ApiActionParams<TAction>, ApiActionResponseType<TAction>>) => Promise<GatewayActionResponseData<Context, Req, Res, TAction>> : (params: ApiActionConfig<Context, ApiActionParams<TAction>, ApiActionResponseType<TAction>>) => Promise<GatewayActionResponseData<Context, Req, Res, TAction>>;
|
|
219
|
-
export type GatewayApi<T extends BaseSchema, Context extends GatewayContext, Req extends GatewayRequest<Context>, Res extends GatewayResponse> = {
|
|
220
|
-
[S in keyof T]: {
|
|
221
|
-
[A in keyof T[S]['actions']]: GatewayAction<Context, Req, Res, T[S]['actions'][A]>;
|
|
222
|
-
};
|
|
223
|
-
};
|
|
224
|
-
type ContextAction<TAction> = undefined extends ApiActionParams<TAction> ? (params?: ApiActionParams<TAction>) => Promise<ApiActionResponseType<TAction>> : (params: ApiActionParams<TAction>) => Promise<ApiActionResponseType<TAction>>;
|
|
225
|
-
export type ContextApi<T extends BaseSchema> = {
|
|
226
|
-
[S in keyof T]: {
|
|
227
|
-
[A in keyof T[S]['actions']]: ContextAction<T[S]['actions'][A]>;
|
|
228
|
-
};
|
|
229
|
-
};
|
|
230
|
-
export type ContextApiByScope<R extends SchemasByScope> = {
|
|
231
|
-
[scope in keyof R]: ContextApi<R[scope]>;
|
|
232
|
-
};
|
|
233
|
-
export type ContextApiWithRoot<R extends SchemasByScope> = ContextApiByScope<R>['root'] & ContextApiByScope<R>;
|
|
234
|
-
interface OnUnknownActionData {
|
|
235
|
-
service?: string;
|
|
236
|
-
action?: string;
|
|
237
|
-
}
|
|
238
|
-
type AxiosInterceptorUseParams<T> = Parameters<AxiosInterceptorManager<T>['use']>;
|
|
239
|
-
interface AxiosInterceptorConfig<T> {
|
|
240
|
-
callback: AxiosInterceptorUseParams<T>[0];
|
|
241
|
-
errorCallback?: AxiosInterceptorUseParams<T>[1];
|
|
242
|
-
}
|
|
243
|
-
export interface AxiosInterceptorsConfig {
|
|
244
|
-
request?: AxiosInterceptorConfig<InternalAxiosRequestConfig<any>>[];
|
|
245
|
-
response?: AxiosInterceptorConfig<AxiosResponse<any>>[];
|
|
246
|
-
}
|
|
247
|
-
export interface GatewayConfig<Context extends GatewayContext, Req extends GatewayRequest<Context>, Res extends GatewayResponse> {
|
|
248
|
-
installation?: string;
|
|
249
|
-
env?: string;
|
|
250
|
-
actions?: string[];
|
|
251
|
-
timeout?: number;
|
|
252
|
-
grpcOptions?: object;
|
|
253
|
-
grpcRecreateService?: boolean;
|
|
254
|
-
axiosConfig?: AxiosRequestConfig;
|
|
255
|
-
axiosInterceptors?: AxiosInterceptorsConfig;
|
|
256
|
-
onUnknownAction?: (req: Req, res: Res, data: OnUnknownActionData) => any;
|
|
257
|
-
onBeforeAction?: (req: Req, res: Res, scope: string, service: string, action: string, config?: ApiServiceActionConfig<Context, Req, Res, unknown>) => any;
|
|
258
|
-
onRequestSuccess?: (req: Req, res: Res, data: any) => any;
|
|
259
|
-
onRequestFailed?: (req: Req, res: Res, error: any) => any;
|
|
260
|
-
sendStats?: SendStats<Context>;
|
|
261
|
-
includeProtoRoots?: string[];
|
|
262
|
-
caCertificatePath: string | null;
|
|
263
|
-
proxyHeaders: ProxyHeaders;
|
|
264
|
-
proxyDebugHeaders?: ProxyHeaders;
|
|
265
|
-
withDebugHeaders?: boolean | ((req: Req, res: Res) => boolean);
|
|
266
|
-
validationSchema?: object;
|
|
267
|
-
encodePathArgs?: boolean;
|
|
268
|
-
getAuthArgs: (req: Req, res: Res) => Record<string, unknown> | undefined;
|
|
269
|
-
getAuthHeaders: GetAuthHeaders;
|
|
270
|
-
ErrorConstructor: AppErrorConstructor;
|
|
271
|
-
}
|
|
272
|
-
export {};
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { IncomingHttpHeaders } from 'http';
|
|
2
|
-
export interface GatewayContextParams {
|
|
3
|
-
tags?: Record<string, string | number | boolean | undefined>;
|
|
4
|
-
}
|
|
5
|
-
export type Dict = {
|
|
6
|
-
[key: string]: unknown;
|
|
7
|
-
};
|
|
8
|
-
export interface GatewayContext {
|
|
9
|
-
create: (name: string, params?: GatewayContextParams) => this;
|
|
10
|
-
log: (message: string, extra?: Dict) => void;
|
|
11
|
-
logError: (message: string, error?: unknown, extra?: Dict) => void;
|
|
12
|
-
end: () => void;
|
|
13
|
-
stats: (data: {
|
|
14
|
-
[name: string]: string | number;
|
|
15
|
-
}) => void;
|
|
16
|
-
utils?: {
|
|
17
|
-
redactSensitiveHeaders?: (headers?: IncomingHttpHeaders) => IncomingHttpHeaders;
|
|
18
|
-
redactSensitiveKeys?: (headers: Dict) => Dict;
|
|
19
|
-
};
|
|
20
|
-
getMetadata: () => IncomingHttpHeaders;
|
|
21
|
-
getTraceId?: () => string | undefined;
|
|
22
|
-
}
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import axios, { AxiosRequestConfig } from 'axios';
|
|
2
|
-
import { AxiosInterceptorsConfig } from '../models/common.js';
|
|
3
|
-
export declare function getAxiosClient(timeout?: number, retries?: number, axiosConfig?: AxiosRequestConfig, { request: reqInterceptors, response: resInterceptors }?: AxiosInterceptorsConfig): axios.AxiosInstance;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import * as grpc from '@grpc/grpc-js';
|
|
2
|
-
import _ from 'lodash';
|
|
3
|
-
import { ActionEndpoint, ExtendedActionEndpoint, ExtendedGrpcActionEndpoint, ExtendedRestActionEndpoint, Headers } from '../models/common.js';
|
|
4
|
-
import { Dict, GatewayContext } from '../models/context.js';
|
|
5
|
-
import { AppErrorConstructor } from '../models/error.js';
|
|
6
|
-
export declare function isExtendedActionEndpoint(endpoint: ActionEndpoint): endpoint is ExtendedActionEndpoint;
|
|
7
|
-
export declare function isExtendedGrpcActionEndpoint(endpoint: ActionEndpoint): endpoint is ExtendedGrpcActionEndpoint;
|
|
8
|
-
export declare function isExtendedRestActionEndpoint(endpoint: ActionEndpoint): endpoint is ExtendedRestActionEndpoint;
|
|
9
|
-
export declare function getKeys<T extends object>(obj: T): (keyof T)[];
|
|
10
|
-
/**
|
|
11
|
-
* This function should only use to sanitize debugHeaders that are creating in our code
|
|
12
|
-
*/
|
|
13
|
-
export declare function sanitizeDebugHeaders(debugHeaders: Headers): _.Omit<Headers, "x-api-request-body">;
|
|
14
|
-
export declare function getHeadersFromMetadata(metadata: Record<string, grpc.MetadataValue[]>, prefix?: string): Record<string, string>;
|
|
15
|
-
export declare function handleError<Context extends GatewayContext>(ErrorConstructor: AppErrorConstructor, error: unknown, ctx: Context, message: string, extra?: Dict): void;
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import * as grpc from '@grpc/grpc-js';
|
|
2
|
-
import * as protobufjs from 'protobufjs';
|
|
3
|
-
import { Lang } from '../constants.js';
|
|
4
|
-
import { GatewayError } from '../models/common.js';
|
|
5
|
-
import { AppErrorConstructor } from '../models/error.js';
|
|
6
|
-
export declare function parseMixedError(e: Error & {
|
|
7
|
-
code?: string;
|
|
8
|
-
}): {
|
|
9
|
-
status: number;
|
|
10
|
-
message: string;
|
|
11
|
-
code: string;
|
|
12
|
-
debug: {
|
|
13
|
-
originalError: Error & {
|
|
14
|
-
code?: string;
|
|
15
|
-
};
|
|
16
|
-
stack: string | undefined;
|
|
17
|
-
};
|
|
18
|
-
};
|
|
19
|
-
export declare function parseRestError(error: any, lang?: string): GatewayError;
|
|
20
|
-
export declare function parseGrpcError(error: grpc.ServiceError, packageRoot: protobufjs.Root, lang?: Lang, decodeAnyMessageProtoLoaderOptions?: protobufjs.IConversionOptions): GatewayError;
|
|
21
|
-
export declare class GrpcError extends Error {
|
|
22
|
-
private parsedError;
|
|
23
|
-
private rawError;
|
|
24
|
-
constructor(message: string, parsedError: GatewayError, rawError?: grpc.ServiceError);
|
|
25
|
-
getGatewayError(): GatewayError;
|
|
26
|
-
getRawError(): grpc.ServiceError | undefined;
|
|
27
|
-
getAppError(ErrorConstructor: AppErrorConstructor): Error;
|
|
28
|
-
}
|
|
29
|
-
export declare function isGrpcError(error: Error | GrpcError): error is GrpcError;
|
|
30
|
-
export declare function grpcErrorFactory(error: Error): GrpcError;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const sourceDir: string;
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.sourceDir = void 0;
|
|
37
|
-
// this one has a -cjs.cts suffix, so it will override the
|
|
38
|
-
// module at src/utils/source-dir.ts in the CommonJS build,
|
|
39
|
-
// and be excluded from the esm build.
|
|
40
|
-
const path = __importStar(require("path"));
|
|
41
|
-
exports.sourceDir = path.resolve(__dirname, '..');
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import * as grpc from '@grpc/grpc-js';
|
|
2
|
-
import * as protobufjs from 'protobufjs';
|
|
3
|
-
import type * as descriptor from 'protobufjs/ext/descriptor';
|
|
4
|
-
import { ApiActionConfig, ApiServiceGrpcActionConfig, EndpointsConfig, GatewayApiOptions } from '../models/common.js';
|
|
5
|
-
import { GatewayContext } from '../models/context.js';
|
|
6
|
-
import { AppErrorConstructor } from '../models/error.js';
|
|
7
|
-
declare module 'protobufjs' {
|
|
8
|
-
interface Root {
|
|
9
|
-
toDescriptor(protoVersion: string): protobufjs.Message<descriptor.IFileDescriptorSet> & descriptor.IFileDescriptorSet;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
interface CredentialsMap {
|
|
13
|
-
insecure: grpc.ChannelCredentials;
|
|
14
|
-
secure: grpc.ChannelCredentials;
|
|
15
|
-
secureWithoutRootCert: grpc.ChannelCredentials;
|
|
16
|
-
}
|
|
17
|
-
export interface GrpcContext {
|
|
18
|
-
root: protobufjs.Root;
|
|
19
|
-
credentials: CredentialsMap;
|
|
20
|
-
}
|
|
21
|
-
export declare function createRoot(includeGrpcPaths?: string[]): protobufjs.Root;
|
|
22
|
-
export declare function getCredentialsMap(caCertificatePath?: string | null): CredentialsMap;
|
|
23
|
-
export declare function createGrpcAction<Context extends GatewayContext>({ root, credentials }: GrpcContext, endpoints: EndpointsConfig | undefined, config: ApiServiceGrpcActionConfig<Context, any, any>, serviceKey: string, actionName: string, options: GatewayApiOptions<Context>, ErrorConstructor: AppErrorConstructor): (actionConfig: ApiActionConfig<Context, any, any>) => Promise<import("../models/common.js").GatewayActionClientStreamResponse<any> | import("../models/common.js").GatewayActionServerStreamResponse<any> | import("../models/common.js").GatewayActionDuplexStreamResponse<any> | import("../models/common.js").GatewayActionUnaryResponse<any>>;
|
|
24
|
-
export {};
|