alepha 0.7.5 → 0.7.7
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/cache/redis.cjs +4 -8
- package/cache/redis.d.ts +28 -89
- package/cache/redis.js +1 -1
- package/cache.cjs +4 -8
- package/cache.d.ts +189 -265
- package/cache.js +1 -1
- package/core.cjs +4 -8
- package/core.d.ts +951 -929
- package/core.js +1 -1
- package/datetime.cjs +4 -8
- package/datetime.d.ts +151 -146
- package/datetime.js +1 -1
- package/lock/redis.cjs +7 -49
- package/lock/redis.d.ts +15 -12
- package/lock/redis.js +1 -47
- package/lock.cjs +4 -8
- package/lock.d.ts +117 -170
- package/lock.js +1 -1
- package/package.json +105 -39
- package/postgres.cjs +4 -8
- package/postgres.d.ts +1410 -4433
- package/postgres.js +1 -1
- package/queue/redis.cjs +8 -0
- package/queue/redis.d.ts +31 -0
- package/queue/redis.js +1 -0
- package/queue.cjs +4 -8
- package/queue.d.ts +162 -205
- package/queue.js +1 -1
- package/react/auth.cjs +4 -8
- package/react/auth.d.ts +161 -282
- package/react/auth.js +1 -1
- package/react/head.cjs +8 -0
- package/react/head.d.ts +86 -0
- package/react/head.js +1 -0
- package/react.cjs +4 -8
- package/react.d.ts +468 -559
- package/react.js +1 -1
- package/redis.cjs +4 -8
- package/redis.d.ts +59 -132
- package/redis.js +1 -1
- package/retry.cjs +4 -8
- package/retry.d.ts +34 -31
- package/retry.js +1 -1
- package/scheduler.cjs +4 -8
- package/scheduler.d.ts +124 -182
- package/scheduler.js +1 -1
- package/security.cjs +4 -8
- package/security.d.ts +459 -595
- package/security.js +1 -1
- package/server/cache.cjs +4 -8
- package/server/cache.d.ts +43 -40
- package/server/cache.js +1 -1
- package/server/cookies.cjs +4 -8
- package/server/cookies.d.ts +49 -41
- package/server/cookies.js +1 -1
- package/server/cors.cjs +8 -0
- package/server/cors.d.ts +25 -0
- package/server/cors.js +1 -0
- package/server/health.cjs +8 -0
- package/server/health.d.ts +42 -0
- package/server/health.js +1 -0
- package/server/links.cjs +8 -0
- package/server/links.d.ts +188 -0
- package/server/links.js +1 -0
- package/server/proxy.cjs +8 -0
- package/server/proxy.d.ts +41 -0
- package/server/proxy.js +1 -0
- package/server/static.cjs +4 -8
- package/server/static.d.ts +98 -95
- package/server/static.js +1 -1
- package/server/swagger.cjs +4 -8
- package/server/swagger.d.ts +96 -92
- package/server/swagger.js +1 -1
- package/server.cjs +4 -8
- package/server.d.ts +602 -1087
- package/server.js +1 -1
- package/testing.cjs +8 -0
- package/testing.d.ts +1 -0
- package/testing.js +1 -0
- package/topic/redis.cjs +8 -0
- package/topic/redis.d.ts +45 -0
- package/topic/redis.js +1 -0
- package/topic.cjs +4 -8
- package/topic.d.ts +161 -169
- package/topic.js +1 -1
- package/vite.cjs +4 -8
- package/vite.d.ts +89 -82
- package/vite.js +1 -1
- package/src/cache/redis.ts +0 -1
- package/src/cache.ts +0 -1
- package/src/core.ts +0 -1
- package/src/datetime.ts +0 -1
- package/src/lock/redis.ts +0 -1
- package/src/lock.ts +0 -1
- package/src/postgres.ts +0 -1
- package/src/queue/redis.ts +0 -1
- package/src/queue.ts +0 -1
- package/src/react/auth.ts +0 -1
- package/src/react.ts +0 -1
- package/src/redis.ts +0 -1
- package/src/retry.ts +0 -1
- package/src/scheduler.ts +0 -1
- package/src/security.ts +0 -1
- package/src/server/cache.ts +0 -1
- package/src/server/cookies.ts +0 -1
- package/src/server/static.ts +0 -1
- package/src/server/swagger.ts +0 -1
- package/src/server.ts +0 -1
- package/src/topic/redis.ts +0 -1
- package/src/topic.ts +0 -1
- package/src/vite.ts +0 -1
package/server.d.ts
CHANGED
|
@@ -1,1042 +1,433 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import {
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
static: any;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
type TReadonly<T extends TSchema$1> = T & {
|
|
30
|
-
[ReadonlyKind$1]: 'Readonly';
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
type UnionStatic<T extends TSchema$1[], P extends unknown[]> = {
|
|
34
|
-
[K in keyof T]: T[K] extends TSchema$1 ? Static<T[K], P> : never;
|
|
35
|
-
}[number];
|
|
36
|
-
interface TUnion<T extends TSchema$1[] = TSchema$1[]> extends TSchema$1 {
|
|
37
|
-
[Kind$1]: 'Union';
|
|
38
|
-
static: UnionStatic<T, this['params']>;
|
|
39
|
-
anyOf: T;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
type StringFormatOption$1 = 'date-time' | 'time' | 'date' | 'email' | 'idn-email' | 'hostname' | 'idn-hostname' | 'ipv4' | 'ipv6' | 'uri' | 'uri-reference' | 'iri' | 'uuid' | 'iri-reference' | 'uri-template' | 'json-pointer' | 'relative-json-pointer' | 'regex' | ({} & string);
|
|
43
|
-
type StringContentEncodingOption$1 = '7bit' | '8bit' | 'binary' | 'quoted-printable' | 'base64' | ({} & string);
|
|
44
|
-
interface StringOptions$1 extends SchemaOptions$1 {
|
|
45
|
-
/** The maximum string length */
|
|
46
|
-
maxLength?: number;
|
|
47
|
-
/** The minimum string length */
|
|
48
|
-
minLength?: number;
|
|
49
|
-
/** A regular expression pattern this string should match */
|
|
50
|
-
pattern?: string;
|
|
51
|
-
/** A format this string should match */
|
|
52
|
-
format?: StringFormatOption$1;
|
|
53
|
-
/** The content encoding for this string */
|
|
54
|
-
contentEncoding?: StringContentEncodingOption$1;
|
|
55
|
-
/** The content media type for this string */
|
|
56
|
-
contentMediaType?: string;
|
|
57
|
-
}
|
|
58
|
-
interface TString$1 extends TSchema$1, StringOptions$1 {
|
|
59
|
-
[Kind$1]: 'String';
|
|
60
|
-
static: string;
|
|
61
|
-
type: 'string';
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
interface TBoolean extends TSchema$1 {
|
|
65
|
-
[Kind$1]: 'Boolean';
|
|
66
|
-
static: boolean;
|
|
67
|
-
type: 'boolean';
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
interface NumberOptions extends SchemaOptions$1 {
|
|
71
|
-
exclusiveMaximum?: number;
|
|
72
|
-
exclusiveMinimum?: number;
|
|
73
|
-
maximum?: number;
|
|
74
|
-
minimum?: number;
|
|
75
|
-
multipleOf?: number;
|
|
76
|
-
}
|
|
77
|
-
interface TNumber extends TSchema$1, NumberOptions {
|
|
78
|
-
[Kind$1]: 'Number';
|
|
79
|
-
static: number;
|
|
80
|
-
type: 'number';
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
interface IntegerOptions extends SchemaOptions$1 {
|
|
84
|
-
exclusiveMaximum?: number;
|
|
85
|
-
exclusiveMinimum?: number;
|
|
86
|
-
maximum?: number;
|
|
87
|
-
minimum?: number;
|
|
88
|
-
multipleOf?: number;
|
|
89
|
-
}
|
|
90
|
-
interface TInteger extends TSchema$1, IntegerOptions {
|
|
91
|
-
[Kind$1]: 'Integer';
|
|
92
|
-
static: number;
|
|
93
|
-
type: 'integer';
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
type TOptional<T extends TSchema$1> = T & {
|
|
97
|
-
[OptionalKind$1]: 'Optional';
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
type RecordStatic<Key extends TSchema$1, Type extends TSchema$1, P extends unknown[]> = (Evaluate<{
|
|
101
|
-
[_ in Assert<Static<Key>, PropertyKey>]: Static<Type, P>;
|
|
102
|
-
}>);
|
|
103
|
-
interface TRecord<Key extends TSchema$1 = TSchema$1, Type extends TSchema$1 = TSchema$1> extends TSchema$1 {
|
|
104
|
-
[Kind$1]: 'Record';
|
|
105
|
-
static: RecordStatic<Key, Type, this['params']>;
|
|
106
|
-
type: 'object';
|
|
107
|
-
patternProperties: {
|
|
108
|
-
[pattern: string]: Type;
|
|
109
|
-
};
|
|
110
|
-
additionalProperties: TAdditionalProperties;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/** Creates a static type from a TypeBox type */
|
|
114
|
-
type Static<Type extends TSchema$1, Params extends unknown[] = [], Result = (Type & {
|
|
115
|
-
params: Params;
|
|
116
|
-
})['static']> = Result;
|
|
117
|
-
|
|
118
|
-
type ReadonlyOptionalPropertyKeys<T extends TProperties> = {
|
|
119
|
-
[K in keyof T]: T[K] extends TReadonly<TSchema$1> ? (T[K] extends TOptional<T[K]> ? K : never) : never;
|
|
120
|
-
}[keyof T];
|
|
121
|
-
type ReadonlyPropertyKeys<T extends TProperties> = {
|
|
122
|
-
[K in keyof T]: T[K] extends TReadonly<TSchema$1> ? (T[K] extends TOptional<T[K]> ? never : K) : never;
|
|
123
|
-
}[keyof T];
|
|
124
|
-
type OptionalPropertyKeys<T extends TProperties> = {
|
|
125
|
-
[K in keyof T]: T[K] extends TOptional<TSchema$1> ? (T[K] extends TReadonly<T[K]> ? never : K) : never;
|
|
126
|
-
}[keyof T];
|
|
127
|
-
type RequiredPropertyKeys<T extends TProperties> = keyof Omit<T, ReadonlyOptionalPropertyKeys<T> | ReadonlyPropertyKeys<T> | OptionalPropertyKeys<T>>;
|
|
128
|
-
type ObjectStaticProperties<T extends TProperties, R extends Record<keyof any, unknown>> = Evaluate<(Readonly<Partial<Pick<R, ReadonlyOptionalPropertyKeys<T>>>> & Readonly<Pick<R, ReadonlyPropertyKeys<T>>> & Partial<Pick<R, OptionalPropertyKeys<T>>> & Required<Pick<R, RequiredPropertyKeys<T>>>)>;
|
|
129
|
-
type ObjectStatic<T extends TProperties, P extends unknown[]> = ObjectStaticProperties<T, {
|
|
130
|
-
[K in keyof T]: Static<T[K], P>;
|
|
131
|
-
}>;
|
|
132
|
-
type TPropertyKey = string | number;
|
|
133
|
-
type TProperties = Record<TPropertyKey, TSchema$1>;
|
|
134
|
-
type TAdditionalProperties = undefined | TSchema$1 | boolean;
|
|
135
|
-
interface ObjectOptions extends SchemaOptions$1 {
|
|
136
|
-
/** Additional property constraints for this object */
|
|
137
|
-
additionalProperties?: TAdditionalProperties;
|
|
138
|
-
/** The minimum number of properties allowed on this object */
|
|
139
|
-
minProperties?: number;
|
|
140
|
-
/** The maximum number of properties allowed on this object */
|
|
141
|
-
maxProperties?: number;
|
|
142
|
-
}
|
|
143
|
-
interface TObject<T extends TProperties = TProperties> extends TSchema$1, ObjectOptions {
|
|
144
|
-
[Kind$1]: 'Object';
|
|
145
|
-
static: ObjectStatic<T, this['params']>;
|
|
146
|
-
additionalProperties?: TAdditionalProperties;
|
|
147
|
-
type: 'object';
|
|
148
|
-
properties: T;
|
|
149
|
-
required?: string[];
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
type Assert<T, E> = T extends E ? T : never;
|
|
153
|
-
type Evaluate<T> = T extends infer O ? {
|
|
154
|
-
[K in keyof O]: O[K];
|
|
155
|
-
} : never;
|
|
156
|
-
type Ensure<T> = T extends infer U ? U : never;
|
|
157
|
-
|
|
158
|
-
interface ArrayOptions extends SchemaOptions$1 {
|
|
159
|
-
/** The minimum number of items in this array */
|
|
160
|
-
minItems?: number;
|
|
161
|
-
/** The maximum number of items in this array */
|
|
162
|
-
maxItems?: number;
|
|
163
|
-
/** Should this schema contain unique items */
|
|
164
|
-
uniqueItems?: boolean;
|
|
165
|
-
/** A schema for which some elements should match */
|
|
166
|
-
contains?: TSchema$1;
|
|
167
|
-
/** A minimum number of contains schema matches */
|
|
168
|
-
minContains?: number;
|
|
169
|
-
/** A maximum number of contains schema matches */
|
|
170
|
-
maxContains?: number;
|
|
171
|
-
}
|
|
172
|
-
type ArrayStatic<T extends TSchema$1, P extends unknown[]> = Ensure<Static<T, P>[]>;
|
|
173
|
-
interface TArray<T extends TSchema$1 = TSchema$1> extends TSchema$1, ArrayOptions {
|
|
174
|
-
[Kind$1]: 'Array';
|
|
175
|
-
static: ArrayStatic<T, this['params']>;
|
|
176
|
-
type: 'array';
|
|
177
|
-
items: T;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
interface SchemaOptions$1 {
|
|
181
|
-
$schema?: string;
|
|
182
|
-
/** Id for this schema */
|
|
183
|
-
$id?: string;
|
|
184
|
-
/** Title of this schema */
|
|
185
|
-
title?: string;
|
|
186
|
-
/** Description of this schema */
|
|
187
|
-
description?: string;
|
|
188
|
-
/** Default value for this schema */
|
|
189
|
-
default?: any;
|
|
190
|
-
/** Example values matching this schema */
|
|
191
|
-
examples?: any;
|
|
192
|
-
/** Optional annotation for readOnly */
|
|
193
|
-
readOnly?: boolean;
|
|
194
|
-
/** Optional annotation for writeOnly */
|
|
195
|
-
writeOnly?: boolean;
|
|
196
|
-
[prop: string]: any;
|
|
197
|
-
}
|
|
198
|
-
interface TKind$1 {
|
|
199
|
-
[Kind$1]: string;
|
|
200
|
-
}
|
|
201
|
-
interface TSchema$1 extends TKind$1, SchemaOptions$1 {
|
|
202
|
-
[ReadonlyKind$1]?: string;
|
|
203
|
-
[OptionalKind$1]?: string;
|
|
204
|
-
[Hint$1]?: string;
|
|
205
|
-
params: unknown[];
|
|
206
|
-
static: unknown;
|
|
207
|
-
}
|
|
208
|
-
|
|
1
|
+
import * as _alepha_core1 from "@alepha/core";
|
|
2
|
+
import * as _alepha_core3 from "@alepha/core";
|
|
3
|
+
import * as _alepha_core7 from "@alepha/core";
|
|
4
|
+
import * as _alepha_core9 from "@alepha/core";
|
|
5
|
+
import * as _alepha_core71 from "@alepha/core";
|
|
6
|
+
import * as _alepha_core10 from "@alepha/core";
|
|
7
|
+
import * as _alepha_core15 from "@alepha/core";
|
|
8
|
+
import * as _alepha_core23 from "@alepha/core";
|
|
9
|
+
import { Alepha, Async, FileLike, KIND, KIND as KIND$1, Module, OPTIONS, Static, StreamLike, TObject, TSchema } from "@alepha/core";
|
|
10
|
+
import { JwtProvider, Permission, SecurityProvider, ServiceAccountDescriptor, UserAccountToken } from "@alepha/security";
|
|
11
|
+
import { BusboyConfig } from "@fastify/busboy";
|
|
12
|
+
import * as _alepha_cache2 from "@alepha/cache";
|
|
13
|
+
import { Readable } from "node:stream";
|
|
14
|
+
import { ReadableStream } from "node:stream/web";
|
|
15
|
+
import { Route, RouterProvider } from "@alepha/router";
|
|
16
|
+
import { IncomingMessage, ServerResponse as ServerResponse$1 } from "node:http";
|
|
17
|
+
import { DurationLike } from "@alepha/datetime";
|
|
18
|
+
import * as _sinclair_typebox13 from "@sinclair/typebox";
|
|
19
|
+
import * as _sinclair_typebox37 from "@sinclair/typebox";
|
|
20
|
+
import * as _sinclair_typebox21 from "@sinclair/typebox";
|
|
21
|
+
import * as _sinclair_typebox27 from "@sinclair/typebox";
|
|
22
|
+
import * as _sinclair_typebox63 from "@sinclair/typebox";
|
|
23
|
+
import * as http18 from "http";
|
|
24
|
+
|
|
25
|
+
//#region src/constants/routeMethods.d.ts
|
|
209
26
|
declare const routeMethods: readonly ["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS", "CONNECT", "TRACE"];
|
|
210
27
|
type RouteMethod = (typeof routeMethods)[number];
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
* - $page => React route (for SSR)
|
|
226
|
-
*/
|
|
227
|
-
declare class ServerRouterProvider extends RouterProvider<ServerRouteWithHandler> {
|
|
228
|
-
protected readonly alepha: Alepha;
|
|
229
|
-
protected readonly env: {
|
|
230
|
-
SERVER_ALS_ENABLED: boolean;
|
|
231
|
-
};
|
|
232
|
-
createRequestId(): string;
|
|
233
|
-
route<TConfig extends RequestConfigSchema = RequestConfigSchema>(route: ServerRoute<TConfig>): Promise<void>;
|
|
234
|
-
onRequest(route: ServerRoute, rawRequest: ServerRawRequest, responseType: ResponseType, withAls: boolean): Promise<ServerResponse>;
|
|
235
|
-
protected processRequest(request: ServerRequest, route: ServerRoute, responseType: ResponseType, withAls: boolean): Promise<{
|
|
236
|
-
status: number;
|
|
237
|
-
headers: Record<string, string> & {
|
|
238
|
-
"set-cookie"?: string[];
|
|
239
|
-
};
|
|
240
|
-
body: any;
|
|
241
|
-
}>;
|
|
242
|
-
protected runRouteHandler(route: ServerRoute, request: ServerRequest, responseType: ResponseType, withAls: boolean): Promise<void>;
|
|
243
|
-
protected getResponseType(schema?: RequestConfigSchema): ResponseType;
|
|
244
|
-
protected errorHandler(route: ServerRoute, request: ServerRequest, error: Error): Promise<void>;
|
|
245
|
-
validateRequest(route: {
|
|
246
|
-
schema?: RequestConfigSchema;
|
|
247
|
-
}, request: ServerRequestConfig): void;
|
|
248
|
-
serializeResponse(route: ServerRoute, reply: ServerReply, responseType: ResponseType): void;
|
|
249
|
-
}
|
|
28
|
+
//#endregion
|
|
29
|
+
//#region src/helpers/ServerReply.d.ts
|
|
30
|
+
declare class ServerReply {
|
|
31
|
+
headers: Record<string, string> & {
|
|
32
|
+
"set-cookie"?: string[];
|
|
33
|
+
};
|
|
34
|
+
status?: number;
|
|
35
|
+
body?: any;
|
|
36
|
+
redirect(url: string, status?: number): void;
|
|
37
|
+
setStatus(status: number): void;
|
|
38
|
+
setHeader(name: string, value: string): void;
|
|
39
|
+
}
|
|
40
|
+
//#endregion
|
|
41
|
+
//#region src/interfaces/index.d.ts
|
|
250
42
|
interface RequestConfigSchema {
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
43
|
+
body?: TSchema;
|
|
44
|
+
params?: TObject;
|
|
45
|
+
query?: TObject;
|
|
46
|
+
headers?: TObject;
|
|
47
|
+
response?: TSchema;
|
|
256
48
|
}
|
|
257
49
|
interface ServerRequestConfig<TConfig extends RequestConfigSchema = RequestConfigSchema> {
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
50
|
+
body: TConfig["body"] extends TSchema ? Static<TConfig["body"]> : any;
|
|
51
|
+
headers: TConfig["headers"] extends TObject ? Static<TConfig["headers"]> : Record<string, string>;
|
|
52
|
+
params: TConfig["params"] extends TObject ? Static<TConfig["params"]> : Record<string, string>;
|
|
53
|
+
query: TConfig["query"] extends TObject ? Static<TConfig["query"]> : Record<string, string>;
|
|
262
54
|
}
|
|
263
55
|
type ServerRequestConfigEntry<TConfig extends RequestConfigSchema = RequestConfigSchema> = Partial<ServerRequestConfig<TConfig>>;
|
|
264
56
|
interface ServerRequest<TConfig extends RequestConfigSchema = RequestConfigSchema> extends ServerRequestConfig<TConfig> {
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
};
|
|
57
|
+
method: RouteMethod;
|
|
58
|
+
url: URL;
|
|
59
|
+
metadata: Record<string, any>;
|
|
60
|
+
reply: ServerReply;
|
|
61
|
+
raw: {
|
|
62
|
+
node?: {
|
|
63
|
+
req: IncomingMessage;
|
|
64
|
+
res: ServerResponse$1;
|
|
274
65
|
};
|
|
275
|
-
|
|
66
|
+
};
|
|
67
|
+
user: UserAccountToken;
|
|
276
68
|
}
|
|
277
69
|
interface ServerRoute<TConfig extends RequestConfigSchema = RequestConfigSchema> extends Route {
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
}
|
|
290
|
-
type ServerResponseBody<TConfig extends RequestConfigSchema = RequestConfigSchema> = TConfig["response"] extends TSchema
|
|
291
|
-
type
|
|
70
|
+
method?: RouteMethod;
|
|
71
|
+
handler: ServerHandler<TConfig>;
|
|
72
|
+
schema?: TConfig;
|
|
73
|
+
/**
|
|
74
|
+
* @see ServerLoggerProvider
|
|
75
|
+
*/
|
|
76
|
+
silent?: boolean;
|
|
77
|
+
/**
|
|
78
|
+
* @see ServerSecurityProvider
|
|
79
|
+
*/
|
|
80
|
+
secure?: ServerRouteSecure;
|
|
81
|
+
}
|
|
82
|
+
type ServerResponseBody<TConfig extends RequestConfigSchema = RequestConfigSchema> = TConfig["response"] extends TSchema ? Static<TConfig["response"]> : ResponseBodyType;
|
|
83
|
+
type ResponseKind = "json" | "text" | "void" | "file" | "any";
|
|
292
84
|
type ResponseBodyType = string | Buffer | StreamLike | undefined | null | void;
|
|
293
85
|
type ServerHandler<TConfig extends RequestConfigSchema = RequestConfigSchema> = (request: ServerRequest<TConfig>) => Async<ServerResponseBody<TConfig>>;
|
|
294
86
|
type ServerMiddlewareHandler<TConfig extends RequestConfigSchema = RequestConfigSchema> = (request: ServerRequest<TConfig>) => Async<ServerResponseBody<TConfig> | undefined>;
|
|
295
|
-
interface ServerReply {
|
|
296
|
-
headers: Record<string, string> & {
|
|
297
|
-
"set-cookie"?: string[];
|
|
298
|
-
};
|
|
299
|
-
status?: number;
|
|
300
|
-
body?: any;
|
|
301
|
-
redirect(url: string): void;
|
|
302
|
-
}
|
|
303
87
|
interface ServerResponse {
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
88
|
+
body: string | Buffer | ArrayBuffer | Readable | ReadableStream;
|
|
89
|
+
headers: Record<string, string>;
|
|
90
|
+
status: number;
|
|
307
91
|
}
|
|
308
92
|
interface ServerRouteWithHandler extends Route {
|
|
309
|
-
|
|
93
|
+
handler: (request: ServerRawRequest) => Promise<ServerResponse>;
|
|
310
94
|
}
|
|
311
95
|
interface ServerRawRequest {
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
};
|
|
96
|
+
method: RouteMethod;
|
|
97
|
+
url: URL;
|
|
98
|
+
headers: Record<string, string>;
|
|
99
|
+
query: Record<string, string>;
|
|
100
|
+
params: Record<string, string>;
|
|
101
|
+
raw: {
|
|
102
|
+
node?: {
|
|
103
|
+
req: IncomingMessage;
|
|
104
|
+
res: ServerResponse$1;
|
|
322
105
|
};
|
|
106
|
+
};
|
|
323
107
|
}
|
|
324
108
|
type ServerRouteSecure = boolean | {
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
109
|
+
permissions?: string[];
|
|
110
|
+
roles?: string[];
|
|
111
|
+
realms?: string[];
|
|
112
|
+
organizations?: string[];
|
|
329
113
|
};
|
|
330
|
-
|
|
114
|
+
//#endregion
|
|
115
|
+
//#region src/helpers/ActionDescriptorHelper.d.ts
|
|
331
116
|
declare class ActionDescriptorHelper {
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
method
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
isMultipart(options: {
|
|
342
|
-
schema?: RequestConfigSchema;
|
|
343
|
-
}): boolean;
|
|
344
|
-
bodyContentType(options: ActionDescriptorOptions): string | undefined;
|
|
345
|
-
protected short(name: string): string;
|
|
346
|
-
fetchLinks(_url: string): void;
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
declare const apiLinkSchema: TObject<{
|
|
350
|
-
name: TString$1;
|
|
351
|
-
path: TString$1;
|
|
352
|
-
method: TOptional<TString$1>;
|
|
353
|
-
group: TOptional<TString$1>;
|
|
354
|
-
requestBodyType: TOptional<TString$1>;
|
|
355
|
-
service: TOptional<TString$1>;
|
|
356
|
-
}>;
|
|
357
|
-
declare const apiLinksResponseSchema: TObject<{
|
|
358
|
-
prefix: TOptional<TString$1>;
|
|
359
|
-
links: TArray<TObject<{
|
|
360
|
-
name: TString$1;
|
|
361
|
-
path: TString$1;
|
|
362
|
-
method: TOptional<TString$1>;
|
|
363
|
-
group: TOptional<TString$1>;
|
|
364
|
-
requestBodyType: TOptional<TString$1>;
|
|
365
|
-
service: TOptional<TString$1>;
|
|
366
|
-
}>>;
|
|
367
|
-
}>;
|
|
368
|
-
type ApiLinksResponse = Static$1<typeof apiLinksResponseSchema>;
|
|
369
|
-
type ApiLink = Static$1<typeof apiLinkSchema>;
|
|
370
|
-
|
|
371
|
-
declare class HttpClient {
|
|
372
|
-
protected readonly log: _alepha_core.Logger;
|
|
373
|
-
protected readonly alepha: Alepha;
|
|
374
|
-
protected readonly helper: ActionDescriptorHelper;
|
|
375
|
-
readonly cache: _alepha_cache.CacheDescriptor<HttpClientCache, any[]>;
|
|
376
|
-
protected readonly pendingRequests: HttpClientPendingRequests;
|
|
377
|
-
readonly URL_LINKS = "/api/_links";
|
|
378
|
-
links?: Array<HttpClientLink>;
|
|
379
|
-
pushLink(link: HttpClientLink): void;
|
|
380
|
-
clear(): Promise<void>;
|
|
381
|
-
fetch<T>(url: string, request?: RequestInit, options?: FetchRunOptions): Promise<FetchResponse<T>>;
|
|
382
|
-
json<T = any>(url: string, options?: RequestInit): Promise<T>;
|
|
383
|
-
protected url(host: string, link: HttpClientLink, args: ServerRequestConfigEntry): string;
|
|
384
|
-
protected body(init: RequestInit, headers: Record<string, string>, link: HttpClientLink, args?: ServerRequestConfigEntry): Promise<void>;
|
|
385
|
-
protected responseData(response: Response, options: FetchRunOptions): Promise<any>;
|
|
386
|
-
protected isMaybeFile(response: Response): boolean;
|
|
387
|
-
protected createFileLike(response: Response, defaultFileName?: string): FileLike;
|
|
388
|
-
protected pathVariables(url: string, action: HttpClientLink, args?: ServerRequestConfigEntry): string;
|
|
389
|
-
protected queryParams(url: string, action: {
|
|
390
|
-
schema?: {
|
|
391
|
-
query?: TObject$1;
|
|
392
|
-
};
|
|
393
|
-
}, args?: ServerRequestConfigEntry): string;
|
|
394
|
-
/**
|
|
395
|
-
* Transform a link into a fetch-request then call fetch().
|
|
396
|
-
*/
|
|
397
|
-
fetchLink(args: FetchLinkArgs): Promise<FetchResponse>;
|
|
398
|
-
/**
|
|
399
|
-
* Create a proxy client.
|
|
400
|
-
* This allows to call actions as methods, e.g. `client.actionName()`.
|
|
401
|
-
*/
|
|
402
|
-
of<T extends object>(scope?: ClientScope): HttpVirtualClient<T>;
|
|
403
|
-
protected getLinkByName(name: string, options?: ClientScope): Promise<HttpClientLink>;
|
|
404
|
-
/**
|
|
405
|
-
* Resolve a link by its name and call it.
|
|
406
|
-
* - If link is local, it will call the local handler.
|
|
407
|
-
* - If link is remote, it will make a fetch request to the remote server.
|
|
408
|
-
*/
|
|
409
|
-
follow(name: string, config?: Partial<ServerRequestConfigEntry>, options?: ClientRequestOptions & ClientScope): Promise<any>;
|
|
410
|
-
protected followRemote(link: HttpClientLink, config?: Partial<ServerRequestConfigEntry>, options?: ClientRequestOptions): Promise<FetchResponse>;
|
|
411
|
-
can(name: string): boolean;
|
|
412
|
-
getLinks(force?: boolean): Promise<HttpClientLink[]>;
|
|
413
|
-
}
|
|
414
|
-
type HttpClientPendingRequests = Record<string, Promise<any> | undefined>;
|
|
415
|
-
interface FetchFactoryAdditionalOptions {
|
|
416
|
-
host?: string | (() => string);
|
|
417
|
-
}
|
|
418
|
-
interface FetchRunOptions {
|
|
419
|
-
/**
|
|
420
|
-
* Key to identify the request in the pending requests.
|
|
421
|
-
*/
|
|
422
|
-
key?: string;
|
|
423
|
-
/**
|
|
424
|
-
* The schema to validate the response against.
|
|
425
|
-
*/
|
|
426
|
-
schema?: TSchema$2;
|
|
427
|
-
/**
|
|
428
|
-
* Built-in cache options.
|
|
429
|
-
*/
|
|
430
|
-
cache?: boolean | number | DurationLike;
|
|
431
|
-
}
|
|
432
|
-
interface HttpClientLink extends ApiLink {
|
|
433
|
-
secured?: boolean;
|
|
434
|
-
prefix?: string;
|
|
435
|
-
host?: string;
|
|
436
|
-
service?: string;
|
|
117
|
+
name(options: ActionDescriptorOptions, instance: any, key: string): string;
|
|
118
|
+
path(options: ActionDescriptorOptions, _instance: any, key: string): string;
|
|
119
|
+
method(options: {
|
|
120
|
+
method?: string;
|
|
121
|
+
schema?: any;
|
|
122
|
+
}): RouteMethod;
|
|
123
|
+
permission(options: ActionDescriptorOptions, instance: any, key: string): Permission;
|
|
124
|
+
group(options: ActionDescriptorOptions, instance: any): string;
|
|
125
|
+
isMultipart(options: {
|
|
437
126
|
schema?: RequestConfigSchema;
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
service?: string;
|
|
127
|
+
}): boolean;
|
|
128
|
+
bodyContentType(options: ActionDescriptorOptions): string | undefined;
|
|
129
|
+
protected short(name: string): string;
|
|
130
|
+
fetchLinks(_url: string): void;
|
|
443
131
|
}
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
132
|
+
//#endregion
|
|
133
|
+
//#region src/services/HttpClient.d.ts
|
|
134
|
+
declare class HttpClient {
|
|
135
|
+
protected readonly log: _alepha_core1.Logger;
|
|
136
|
+
protected readonly alepha: Alepha;
|
|
137
|
+
protected readonly helper: ActionDescriptorHelper;
|
|
138
|
+
readonly cache: _alepha_cache2.CacheDescriptor<HttpClientCache, any[]>;
|
|
139
|
+
protected readonly pendingRequests: HttpClientPendingRequests;
|
|
140
|
+
clear(): Promise<void>;
|
|
141
|
+
fetchAction(args: FetchActionArgs): Promise<FetchResponse>;
|
|
142
|
+
fetch<T>(url: string, request?: RequestInit,
|
|
143
|
+
// standard options
|
|
144
|
+
options?: FetchOptions): Promise<FetchResponse<T>>;
|
|
145
|
+
json<T = any>(url: string, options?: RequestInit): Promise<T>;
|
|
146
|
+
protected url(host: string, action: HttpAction, args: ServerRequestConfigEntry): string;
|
|
147
|
+
protected body(init: RequestInit, headers: Record<string, string>, action: HttpAction, args?: ServerRequestConfigEntry): Promise<void>;
|
|
148
|
+
protected responseData(response: Response, options: FetchOptions): Promise<any>;
|
|
149
|
+
protected isMaybeFile(response: Response): boolean;
|
|
150
|
+
protected createFileLike(response: Response, defaultFileName?: string): FileLike;
|
|
151
|
+
pathVariables(url: string, action: {
|
|
152
|
+
schema?: {
|
|
153
|
+
params?: TObject;
|
|
154
|
+
};
|
|
155
|
+
}, args?: ServerRequestConfigEntry): string;
|
|
156
|
+
queryParams(url: string, action: {
|
|
157
|
+
schema?: {
|
|
158
|
+
query?: TObject;
|
|
159
|
+
};
|
|
160
|
+
}, args?: ServerRequestConfigEntry): string;
|
|
161
|
+
}
|
|
162
|
+
interface FetchOptions {
|
|
163
|
+
/**
|
|
164
|
+
* Key to identify the request in the pending requests.
|
|
165
|
+
*/
|
|
166
|
+
key?: string;
|
|
167
|
+
/**
|
|
168
|
+
* The schema to validate the response against.
|
|
169
|
+
*/
|
|
170
|
+
schema?: TSchema;
|
|
171
|
+
/**
|
|
172
|
+
* Built-in cache options.
|
|
173
|
+
*/
|
|
174
|
+
cache?: boolean | number | DurationLike;
|
|
453
175
|
}
|
|
454
176
|
interface FetchResponse<T = any> {
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
}
|
|
461
|
-
interface FetchLinkArgs {
|
|
462
|
-
link: HttpClientLink;
|
|
463
|
-
host?: string;
|
|
464
|
-
config?: ServerRequestConfigEntry;
|
|
465
|
-
options?: ClientRequestOptions;
|
|
177
|
+
data: T;
|
|
178
|
+
status: number;
|
|
179
|
+
statusText: string;
|
|
180
|
+
headers: Headers;
|
|
181
|
+
raw?: Response;
|
|
466
182
|
}
|
|
467
|
-
|
|
468
|
-
|
|
183
|
+
type HttpClientPendingRequests = Record<string, Promise<any> | undefined>;
|
|
184
|
+
interface HttpClientCache {
|
|
185
|
+
data: any;
|
|
186
|
+
etag?: string;
|
|
187
|
+
}
|
|
188
|
+
interface FetchActionArgs {
|
|
189
|
+
action: HttpAction;
|
|
190
|
+
host?: string;
|
|
191
|
+
config?: ServerRequestConfigEntry;
|
|
192
|
+
options?: ClientRequestOptions;
|
|
193
|
+
}
|
|
194
|
+
interface HttpAction {
|
|
195
|
+
method?: string;
|
|
196
|
+
prefix?: string;
|
|
197
|
+
path: string;
|
|
198
|
+
schema?: {
|
|
199
|
+
params?: TObject;
|
|
200
|
+
query?: TObject;
|
|
201
|
+
body?: TSchema;
|
|
202
|
+
response?: TSchema;
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
//#endregion
|
|
206
|
+
//#region src/descriptors/$action.d.ts
|
|
207
|
+
declare const KEY$1 = "ACTION";
|
|
469
208
|
interface ActionDescriptorOptions<TConfig extends RequestConfigSchema = RequestConfigSchema> extends Omit<ServerRoute, "handler" | "path" | "schema"> {
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
209
|
+
/**
|
|
210
|
+
* Name the route.
|
|
211
|
+
*/
|
|
212
|
+
name?: string;
|
|
213
|
+
/**
|
|
214
|
+
* Namespace of the route, used for grouping.
|
|
215
|
+
*
|
|
216
|
+
* @default Class name containing the route.
|
|
217
|
+
*/
|
|
218
|
+
group?: string;
|
|
219
|
+
/**
|
|
220
|
+
* If false, disabled the security check for this route.
|
|
221
|
+
*
|
|
222
|
+
* @default true when SecurityModule is enabled, false otherwise.
|
|
223
|
+
* @deprecated
|
|
224
|
+
*/
|
|
225
|
+
security?: boolean;
|
|
226
|
+
/**
|
|
227
|
+
* Pathname of the route.
|
|
228
|
+
*/
|
|
229
|
+
path?: string;
|
|
230
|
+
/**
|
|
231
|
+
* Inherit options from another route.
|
|
232
|
+
*/
|
|
233
|
+
use?: {
|
|
234
|
+
[OPTIONS]: ActionDescriptorOptions<TConfig>;
|
|
235
|
+
};
|
|
236
|
+
/**
|
|
237
|
+
* The route method.
|
|
238
|
+
*
|
|
239
|
+
* @default "GET" or "POST" when schema body is defined.
|
|
240
|
+
*/
|
|
241
|
+
method?: RouteMethod;
|
|
242
|
+
/**
|
|
243
|
+
* The config schema of the route.
|
|
244
|
+
* - body: The request body schema.
|
|
245
|
+
* - params: Path variables schema.
|
|
246
|
+
* - query: The request query-params schema.
|
|
247
|
+
* - response: The response schema.
|
|
248
|
+
*/
|
|
249
|
+
schema?: TConfig;
|
|
250
|
+
/**
|
|
251
|
+
* Short description of the route.
|
|
252
|
+
*/
|
|
253
|
+
summary?: string;
|
|
254
|
+
/**
|
|
255
|
+
* Long description of the route.
|
|
256
|
+
*/
|
|
257
|
+
description?: string;
|
|
258
|
+
/**
|
|
259
|
+
* Disable the route. Useful with env variables do disable one specific route.
|
|
260
|
+
*/
|
|
261
|
+
disabled?: boolean;
|
|
262
|
+
/**
|
|
263
|
+
* Mark the route as private.
|
|
264
|
+
* - It won't be exposed in the API documentation.
|
|
265
|
+
* - It won't be exposed in _links.
|
|
266
|
+
*/
|
|
267
|
+
internal?: boolean;
|
|
268
|
+
/**
|
|
269
|
+
* Main route handler. This is where the route logic is implemented.
|
|
270
|
+
*/
|
|
271
|
+
handler?: ServerHandler<TConfig>;
|
|
533
272
|
}
|
|
534
273
|
interface ActionDescriptor<TConfig extends RequestConfigSchema = RequestConfigSchema> {
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
274
|
+
[KIND$1]: typeof KEY$1;
|
|
275
|
+
[OPTIONS]: ActionDescriptorOptions<TConfig>;
|
|
276
|
+
/**
|
|
277
|
+
* Fetch or just call local route when available.
|
|
278
|
+
*/
|
|
279
|
+
(config?: ClientRequestEntry<TConfig>, opts?: ClientRequestOptions): Promise<ClientRequestResponse<TConfig>>;
|
|
280
|
+
/**
|
|
281
|
+
* Just fetch the route. Skip any local route.
|
|
282
|
+
*/
|
|
283
|
+
fetch: (config?: ClientRequestEntry<TConfig>, opts?: ClientRequestOptions) => Promise<FetchResponse<ClientRequestResponse<TConfig>>>;
|
|
284
|
+
/**
|
|
285
|
+
* Name of the permission required to access this route.
|
|
286
|
+
*/
|
|
287
|
+
permission: () => string;
|
|
549
288
|
}
|
|
550
289
|
declare const $action: {
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
};
|
|
554
|
-
type ClientRequestEntry<TConfig extends RequestConfigSchema = RequestConfigSchema, T = ClientRequestEntryContainer<TConfig>> = {
|
|
555
|
-
[K in keyof T as T[K] extends undefined ? never : K]: T[K];
|
|
290
|
+
<TConfig extends RequestConfigSchema>(options: ActionDescriptorOptions<TConfig>): ActionDescriptor<TConfig>;
|
|
291
|
+
[KIND$1]: string;
|
|
556
292
|
};
|
|
293
|
+
type ClientRequestEntry<TConfig extends RequestConfigSchema = RequestConfigSchema, T = ClientRequestEntryContainer<TConfig>> = { [K in keyof T as T[K] extends undefined ? never : K]: T[K] };
|
|
557
294
|
type ClientRequestEntryContainer<TConfig extends RequestConfigSchema = RequestConfigSchema> = {
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
295
|
+
body: TConfig["body"] extends TSchema ? Static<TConfig["body"]> : undefined;
|
|
296
|
+
params: TConfig["params"] extends TSchema ? Static<TConfig["params"]> : undefined;
|
|
297
|
+
headers?: TConfig["headers"] extends TSchema ? Static<TConfig["headers"]> : undefined;
|
|
298
|
+
query?: TConfig["query"] extends TSchema ? Partial<Static<TConfig["query"]>> : undefined;
|
|
562
299
|
};
|
|
563
|
-
interface ClientRequestOptions extends
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
}
|
|
577
|
-
type ClientRequestResponse<TConfig extends RequestConfigSchema> = TConfig["response"] extends TSchema
|
|
578
|
-
|
|
300
|
+
interface ClientRequestOptions extends FetchOptions {
|
|
301
|
+
/**
|
|
302
|
+
* Forward user from the previous request.
|
|
303
|
+
* If "system", use system user. @see {ServerSecurityProvider.localSystemUser}
|
|
304
|
+
* If "context", use the user from the current context (e.g. request).
|
|
305
|
+
*
|
|
306
|
+
* @default "system" is provided, else "context" is used.
|
|
307
|
+
*/
|
|
308
|
+
user?: UserAccountToken | "system" | "context";
|
|
309
|
+
/**
|
|
310
|
+
* Standard request fetch options.
|
|
311
|
+
*/
|
|
312
|
+
request?: RequestInit;
|
|
313
|
+
}
|
|
314
|
+
type ClientRequestResponse<TConfig extends RequestConfigSchema> = TConfig["response"] extends TSchema ? Static<TConfig["response"]> : any;
|
|
315
|
+
//#endregion
|
|
316
|
+
//#region src/errors/HttpError.d.ts
|
|
579
317
|
declare class HttpError extends Error {
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
};
|
|
588
|
-
} | {
|
|
589
|
-
status: number;
|
|
590
|
-
error: string | undefined;
|
|
591
|
-
message: string;
|
|
592
|
-
cause?: undefined;
|
|
593
|
-
};
|
|
594
|
-
readonly status: number;
|
|
595
|
-
readonly error?: string;
|
|
596
|
-
readonly reason?: {
|
|
597
|
-
name: string;
|
|
598
|
-
message: string;
|
|
318
|
+
static toJSON(error: HttpError): {
|
|
319
|
+
status: number;
|
|
320
|
+
error: string | undefined;
|
|
321
|
+
message: string;
|
|
322
|
+
cause: {
|
|
323
|
+
name: string;
|
|
324
|
+
message: string;
|
|
599
325
|
};
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
326
|
+
} | {
|
|
327
|
+
status: number;
|
|
328
|
+
error: string | undefined;
|
|
329
|
+
message: string;
|
|
330
|
+
cause?: undefined;
|
|
331
|
+
};
|
|
332
|
+
readonly status: number;
|
|
333
|
+
readonly error?: string;
|
|
334
|
+
readonly reason?: {
|
|
335
|
+
name: string;
|
|
336
|
+
message: string;
|
|
337
|
+
};
|
|
338
|
+
constructor(options: {
|
|
339
|
+
error?: string;
|
|
340
|
+
message: string;
|
|
341
|
+
status: number;
|
|
342
|
+
cause?: {
|
|
343
|
+
name: string;
|
|
344
|
+
message: string;
|
|
345
|
+
} | unknown;
|
|
346
|
+
}, cause?: unknown);
|
|
609
347
|
}
|
|
610
348
|
declare const errorNameByStatus: Record<number, string>;
|
|
611
349
|
declare const isHttpError: (error: unknown) => error is HttpErrorLike;
|
|
612
350
|
interface HttpErrorLike extends Error {
|
|
613
|
-
|
|
614
|
-
}
|
|
615
|
-
|
|
616
|
-
declare const $client: <T extends object>(scope?: ClientScope) => HttpVirtualClient<T>;
|
|
617
|
-
|
|
618
|
-
type ProxyDescriptorOptions = {
|
|
619
|
-
path: string;
|
|
620
|
-
target: string;
|
|
621
|
-
disabled?: boolean;
|
|
622
|
-
beforeRequest?: (request: ServerRequest, proxyRequest: RequestInit) => Async<void>;
|
|
623
|
-
afterResponse?: (request: ServerRequest, proxyResponse: Response) => Async<void>;
|
|
624
|
-
rewrite?: (url: URL) => void;
|
|
625
|
-
};
|
|
626
|
-
interface ProxyDescriptor {
|
|
627
|
-
[KIND]: "PROXY";
|
|
628
|
-
[OPTIONS]: ProxyDescriptorOptions;
|
|
351
|
+
status: number;
|
|
629
352
|
}
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
[KIND]: string;
|
|
633
|
-
};
|
|
634
|
-
|
|
635
|
-
/**
|
|
636
|
-
* Represents a User Account extracted from JWT.
|
|
637
|
-
*/
|
|
638
|
-
interface UserAccountInfo {
|
|
639
|
-
/**
|
|
640
|
-
* ID of user account. Based on JWT.sub.
|
|
641
|
-
*/
|
|
642
|
-
id: string;
|
|
643
|
-
/**
|
|
644
|
-
* Represents the roles assigned to a user.
|
|
645
|
-
*/
|
|
646
|
-
roles?: string[];
|
|
647
|
-
/**
|
|
648
|
-
* User full name, if available.
|
|
649
|
-
*/
|
|
650
|
-
name?: string;
|
|
651
|
-
/**
|
|
652
|
-
* User email, if available.
|
|
653
|
-
*/
|
|
654
|
-
email?: string;
|
|
655
|
-
/**
|
|
656
|
-
* User profile picture URL, if available.
|
|
657
|
-
*/
|
|
658
|
-
picture?: string;
|
|
659
|
-
/**
|
|
660
|
-
* Organization ID, if available.
|
|
661
|
-
*/
|
|
662
|
-
organization?: string;
|
|
663
|
-
}
|
|
664
|
-
|
|
665
|
-
/** Symbol key applied to readonly types */
|
|
666
|
-
declare const ReadonlyKind: unique symbol;
|
|
667
|
-
/** Symbol key applied to optional types */
|
|
668
|
-
declare const OptionalKind: unique symbol;
|
|
669
|
-
/** Symbol key applied to types */
|
|
670
|
-
declare const Hint: unique symbol;
|
|
671
|
-
/** Symbol key applied to types */
|
|
672
|
-
declare const Kind: unique symbol;
|
|
673
|
-
|
|
674
|
-
type StringFormatOption = 'date-time' | 'time' | 'date' | 'email' | 'idn-email' | 'hostname' | 'idn-hostname' | 'ipv4' | 'ipv6' | 'uri' | 'uri-reference' | 'iri' | 'uuid' | 'iri-reference' | 'uri-template' | 'json-pointer' | 'relative-json-pointer' | 'regex' | ({} & string);
|
|
675
|
-
type StringContentEncodingOption = '7bit' | '8bit' | 'binary' | 'quoted-printable' | 'base64' | ({} & string);
|
|
676
|
-
interface StringOptions extends SchemaOptions {
|
|
677
|
-
/** The maximum string length */
|
|
678
|
-
maxLength?: number;
|
|
679
|
-
/** The minimum string length */
|
|
680
|
-
minLength?: number;
|
|
681
|
-
/** A regular expression pattern this string should match */
|
|
682
|
-
pattern?: string;
|
|
683
|
-
/** A format this string should match */
|
|
684
|
-
format?: StringFormatOption;
|
|
685
|
-
/** The content encoding for this string */
|
|
686
|
-
contentEncoding?: StringContentEncodingOption;
|
|
687
|
-
/** The content media type for this string */
|
|
688
|
-
contentMediaType?: string;
|
|
689
|
-
}
|
|
690
|
-
interface TString extends TSchema, StringOptions {
|
|
691
|
-
[Kind]: 'String';
|
|
692
|
-
static: string;
|
|
693
|
-
type: 'string';
|
|
694
|
-
}
|
|
695
|
-
|
|
696
|
-
interface SchemaOptions {
|
|
697
|
-
$schema?: string;
|
|
698
|
-
/** Id for this schema */
|
|
699
|
-
$id?: string;
|
|
700
|
-
/** Title of this schema */
|
|
701
|
-
title?: string;
|
|
702
|
-
/** Description of this schema */
|
|
703
|
-
description?: string;
|
|
704
|
-
/** Default value for this schema */
|
|
705
|
-
default?: any;
|
|
706
|
-
/** Example values matching this schema */
|
|
707
|
-
examples?: any;
|
|
708
|
-
/** Optional annotation for readOnly */
|
|
709
|
-
readOnly?: boolean;
|
|
710
|
-
/** Optional annotation for writeOnly */
|
|
711
|
-
writeOnly?: boolean;
|
|
712
|
-
[prop: string]: any;
|
|
713
|
-
}
|
|
714
|
-
interface TKind {
|
|
715
|
-
[Kind]: string;
|
|
716
|
-
}
|
|
717
|
-
interface TSchema extends TKind, SchemaOptions {
|
|
718
|
-
[ReadonlyKind]?: string;
|
|
719
|
-
[OptionalKind]?: string;
|
|
720
|
-
[Hint]?: string;
|
|
721
|
-
params: unknown[];
|
|
722
|
-
static: unknown;
|
|
723
|
-
}
|
|
724
|
-
|
|
725
|
-
declare const envSchema$3: _alepha_core.TObject<{
|
|
726
|
-
SECURITY_SECRET_KEY: TString;
|
|
727
|
-
}>;
|
|
728
|
-
interface ServiceAccountDescriptor {
|
|
729
|
-
token: () => Promise<string>;
|
|
730
|
-
}
|
|
731
|
-
declare module "alepha/core" {
|
|
732
|
-
interface Env extends Partial<Static$1<typeof envSchema$3>> {
|
|
733
|
-
}
|
|
734
|
-
}
|
|
735
|
-
|
|
736
|
-
declare module "@alepha/core" {
|
|
737
|
-
interface Hooks {
|
|
738
|
-
"security:user:created": {
|
|
739
|
-
realm: string;
|
|
740
|
-
user: UserAccountInfo;
|
|
741
|
-
};
|
|
742
|
-
}
|
|
743
|
-
}
|
|
744
|
-
|
|
745
|
-
declare const KEY$1 = "REMOTE";
|
|
746
|
-
interface RemoteDescriptorOptions {
|
|
747
|
-
/**
|
|
748
|
-
* The URL of the remote service.
|
|
749
|
-
* You can use a function to generate the URL dynamically.
|
|
750
|
-
* You probably should use $inject(env) to get the URL from the environment.
|
|
751
|
-
*
|
|
752
|
-
* @example
|
|
753
|
-
* ```ts
|
|
754
|
-
* import { $remote } from "@alepha/server";
|
|
755
|
-
* import { $inject, t } from "@alepha/core";
|
|
756
|
-
*
|
|
757
|
-
* class App {
|
|
758
|
-
* env = $inject(t.object({
|
|
759
|
-
* REMOTE_URL: t.string({default: "http://localhost:3000"}),
|
|
760
|
-
* }));
|
|
761
|
-
* remote = $remote({
|
|
762
|
-
* url: this.env.REMOTE_URL,
|
|
763
|
-
* });
|
|
764
|
-
* }
|
|
765
|
-
* ```
|
|
766
|
-
*/
|
|
767
|
-
url: string | (() => string);
|
|
768
|
-
/**
|
|
769
|
-
* The name of the remote service.
|
|
770
|
-
*
|
|
771
|
-
* @default Member of the class containing the remote service.
|
|
772
|
-
*/
|
|
773
|
-
name?: string;
|
|
774
|
-
/**
|
|
775
|
-
* If true, all methods of the remote service will be exposed as actions in this context.
|
|
776
|
-
* > Note: Proxy will never use the service account, it just... proxies the request.
|
|
777
|
-
*/
|
|
778
|
-
proxy?: boolean | Partial<ProxyDescriptorOptions & {
|
|
779
|
-
/**
|
|
780
|
-
* If true, the remote service won't be available internally, only through the proxy.
|
|
781
|
-
*/
|
|
782
|
-
noInternal: boolean;
|
|
783
|
-
}>;
|
|
784
|
-
/**
|
|
785
|
-
* For communication between the server and the remote service with a security layer.
|
|
786
|
-
* This will be used for internal communication and will not be exposed to the client.
|
|
787
|
-
*/
|
|
788
|
-
serviceAccount?: ServiceAccountDescriptor;
|
|
789
|
-
}
|
|
790
|
-
interface RemoteDescriptor {
|
|
791
|
-
[KIND]: typeof KEY$1;
|
|
792
|
-
[OPTIONS]: RemoteDescriptorOptions;
|
|
793
|
-
}
|
|
794
|
-
/**
|
|
795
|
-
* $remote is a descriptor that allows you to define a remote service access.
|
|
796
|
-
*
|
|
797
|
-
* Use it only when you have 2 or more services that need to communicate with each other.
|
|
798
|
-
*
|
|
799
|
-
* All remote services can be exposed as actions, ... or not.
|
|
800
|
-
*
|
|
801
|
-
* You can add a service account if you want to use a security layer.
|
|
802
|
-
*/
|
|
803
|
-
declare const $remote: {
|
|
804
|
-
(options: RemoteDescriptorOptions): RemoteDescriptor;
|
|
805
|
-
[KIND]: string;
|
|
806
|
-
};
|
|
807
|
-
|
|
353
|
+
//#endregion
|
|
354
|
+
//#region src/descriptors/$route.d.ts
|
|
808
355
|
declare const KEY = "ROUTE";
|
|
809
|
-
interface RouteDescriptorOptions<TConfig extends RequestConfigSchema = RequestConfigSchema> extends ServerRoute<TConfig> {
|
|
810
|
-
}
|
|
356
|
+
interface RouteDescriptorOptions<TConfig extends RequestConfigSchema = RequestConfigSchema> extends ServerRoute<TConfig> {}
|
|
811
357
|
type RouteDescriptor<TConfig extends RequestConfigSchema = RequestConfigSchema> = {
|
|
812
|
-
|
|
813
|
-
|
|
358
|
+
[KIND$1]: typeof KEY;
|
|
359
|
+
[OPTIONS]: RouteDescriptorOptions<TConfig>;
|
|
814
360
|
};
|
|
815
361
|
declare const $route: {
|
|
816
|
-
|
|
817
|
-
|
|
362
|
+
<TConfig extends RequestConfigSchema = RequestConfigSchema>(options: RouteDescriptorOptions<TConfig>): RouteDescriptor<TConfig>;
|
|
363
|
+
[KIND$1]: string;
|
|
818
364
|
};
|
|
819
|
-
|
|
365
|
+
//#endregion
|
|
366
|
+
//#region src/errors/BadRequestError.d.ts
|
|
820
367
|
declare class BadRequestError extends HttpError {
|
|
821
|
-
|
|
368
|
+
constructor(message?: string, cause?: unknown);
|
|
822
369
|
}
|
|
823
|
-
|
|
370
|
+
//#endregion
|
|
371
|
+
//#region src/errors/ConflictError.d.ts
|
|
824
372
|
declare class ConflictError extends HttpError {
|
|
825
|
-
|
|
373
|
+
constructor(message?: string, cause?: unknown);
|
|
826
374
|
}
|
|
827
|
-
|
|
375
|
+
//#endregion
|
|
376
|
+
//#region src/errors/ForbiddenError.d.ts
|
|
828
377
|
declare class ForbiddenError extends HttpError {
|
|
829
|
-
|
|
378
|
+
constructor(message?: string, cause?: unknown);
|
|
830
379
|
}
|
|
831
|
-
|
|
380
|
+
//#endregion
|
|
381
|
+
//#region src/errors/NotFoundError.d.ts
|
|
832
382
|
declare class NotFoundError extends HttpError {
|
|
833
|
-
|
|
383
|
+
constructor(message?: string, cause?: unknown);
|
|
834
384
|
}
|
|
835
|
-
|
|
385
|
+
//#endregion
|
|
386
|
+
//#region src/errors/UnauthorizedError.d.ts
|
|
836
387
|
declare class UnauthorizedError extends HttpError {
|
|
837
|
-
|
|
388
|
+
constructor(message?: string, cause?: unknown);
|
|
838
389
|
}
|
|
839
|
-
|
|
390
|
+
//#endregion
|
|
391
|
+
//#region src/errors/ValidationError.d.ts
|
|
840
392
|
declare class ValidationError extends HttpError {
|
|
841
|
-
|
|
842
|
-
}
|
|
843
|
-
|
|
844
|
-
/**
|
|
845
|
-
* Register `/health` endpoint.
|
|
846
|
-
*
|
|
847
|
-
* - Provides basic health information about the server.
|
|
848
|
-
*/
|
|
849
|
-
declare class ServerHealthProvider {
|
|
850
|
-
protected readonly dateTimeProvider: DateTimeProvider;
|
|
851
|
-
protected readonly alepha: Alepha;
|
|
852
|
-
readonly health: RouteDescriptor<{
|
|
853
|
-
response: TObject<{
|
|
854
|
-
message: TString$1;
|
|
855
|
-
uptime: TNumber;
|
|
856
|
-
date: TString$1;
|
|
857
|
-
ready: TBoolean;
|
|
858
|
-
}>;
|
|
859
|
-
}>;
|
|
860
|
-
}
|
|
861
|
-
|
|
862
|
-
declare class ProxyDescriptorProvider {
|
|
863
|
-
protected readonly log: _alepha_core.Logger;
|
|
864
|
-
protected readonly routerProvider: ServerRouterProvider;
|
|
865
|
-
protected readonly alepha: Alepha;
|
|
866
|
-
readonly configure: _alepha_core.HookDescriptor<"configure">;
|
|
867
|
-
createProxyHandler(options: Omit<ProxyDescriptorOptions, "path">): ServerHandler;
|
|
868
|
-
proxy(options: ProxyDescriptorOptions): Promise<void>;
|
|
869
|
-
private getRawRequestBody;
|
|
393
|
+
constructor(message?: string, cause?: unknown);
|
|
870
394
|
}
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
constructor();
|
|
874
|
-
get hostname(): string;
|
|
875
|
-
}
|
|
876
|
-
|
|
877
|
-
declare const envSchema$2: _alepha_core.TObject<{
|
|
878
|
-
SERVER_API_PREFIX: TString$1;
|
|
879
|
-
SERVER_SECURITY_ENABLED: TBoolean;
|
|
880
|
-
}>;
|
|
881
|
-
declare module "@alepha/core" {
|
|
882
|
-
interface Env extends Partial<Static$1<typeof envSchema$2>> {
|
|
883
|
-
}
|
|
884
|
-
interface State {
|
|
885
|
-
/**
|
|
886
|
-
* Real (or fake) user account, used for internal actions.
|
|
887
|
-
* If you define this, you assume that all actions are executed by this user by default.
|
|
888
|
-
* And to force a different user, you need to pass it explicitly in the options.
|
|
889
|
-
*/
|
|
890
|
-
"ServerSecurityProvider.localSystemUser"?: UserAccountToken;
|
|
891
|
-
}
|
|
892
|
-
}
|
|
893
|
-
declare class ServerActionDescriptorProvider {
|
|
894
|
-
protected readonly log: _alepha_core.Logger;
|
|
895
|
-
protected readonly alepha: Alepha;
|
|
896
|
-
protected readonly env: {
|
|
897
|
-
SERVER_API_PREFIX: string;
|
|
898
|
-
SERVER_SECURITY_ENABLED: boolean;
|
|
899
|
-
};
|
|
900
|
-
protected readonly client: HttpClient;
|
|
901
|
-
protected readonly serverProvider: ServerProvider;
|
|
902
|
-
protected readonly helper: ActionDescriptorHelper;
|
|
903
|
-
protected readonly routerProvider: ServerRouterProvider;
|
|
904
|
-
protected readonly actions: ServerRouteAction[];
|
|
905
|
-
getActions(): ServerRouteAction<RequestConfigSchema>[];
|
|
906
|
-
getPrefix(): string;
|
|
907
|
-
readonly configure: _alepha_core.HookDescriptor<"configure">;
|
|
908
|
-
registerAction(value: ActionDescriptor, key: string, instance: any, prefix?: string): Promise<void>;
|
|
909
|
-
/**
|
|
910
|
-
* Check a mock function for the specified route.
|
|
911
|
-
*
|
|
912
|
-
* This is mostly used for testing purposes.
|
|
913
|
-
*/
|
|
914
|
-
protected createLocalFunction(action: ActionDescriptorOptions, permission: Permission): (config?: ServerRequestConfigEntry, options?: ClientRequestOptions) => Promise<any>;
|
|
915
|
-
/**
|
|
916
|
-
* Get the user account token for a local action call.
|
|
917
|
-
* It will check the options, context, and system user.
|
|
918
|
-
*/
|
|
919
|
-
protected getUserFromLocalFunctionContext(options: {
|
|
920
|
-
user?: UserAccountToken | "system" | "context";
|
|
921
|
-
}, permission: Permission, isRouteSecure: boolean): UserAccountToken | undefined;
|
|
922
|
-
}
|
|
923
|
-
declare const isServerAction: (value: any) => value is ServerRouteAction;
|
|
924
|
-
interface ServerRemote {
|
|
925
|
-
url: string;
|
|
926
|
-
name: string;
|
|
927
|
-
proxy: boolean;
|
|
928
|
-
internal: boolean;
|
|
929
|
-
links: (args: {
|
|
930
|
-
authorization?: string;
|
|
931
|
-
}) => Promise<ApiLinksResponse>;
|
|
932
|
-
schema: (args: {
|
|
933
|
-
name: string;
|
|
934
|
-
authorization?: string;
|
|
935
|
-
}) => Promise<any>;
|
|
936
|
-
serviceAccount?: ServiceAccountDescriptor$1;
|
|
937
|
-
prefix: string;
|
|
938
|
-
}
|
|
939
|
-
interface ServerRouteAction<TConfig extends RequestConfigSchema = RequestConfigSchema> extends ServerRoute<TConfig> {
|
|
940
|
-
prefix: string;
|
|
941
|
-
method: RouteMethod;
|
|
942
|
-
name: string;
|
|
943
|
-
group: string;
|
|
944
|
-
permission: Permission;
|
|
945
|
-
options: ActionDescriptorOptions;
|
|
946
|
-
}
|
|
947
|
-
|
|
948
|
-
declare class RemoteDescriptorProvider {
|
|
949
|
-
static path: {
|
|
950
|
-
apiLinks: string;
|
|
951
|
-
};
|
|
952
|
-
protected readonly alepha: Alepha;
|
|
953
|
-
protected readonly client: HttpClient;
|
|
954
|
-
protected readonly proxyProvider: ProxyDescriptorProvider;
|
|
955
|
-
protected readonly remotes: Array<ServerRemote>;
|
|
956
|
-
protected readonly log: _alepha_core.Logger;
|
|
957
|
-
getRemotes(): ServerRemote[];
|
|
958
|
-
readonly configure: _alepha_core.HookDescriptor<"configure">;
|
|
959
|
-
readonly start: _alepha_core.HookDescriptor<"start">;
|
|
960
|
-
registerRemote(value: RemoteDescriptor, key: string): Promise<void>;
|
|
961
|
-
protected readonly fetchLinks: _alepha_retry.RetryDescriptor<(opts: {
|
|
962
|
-
service: string;
|
|
963
|
-
url: string;
|
|
964
|
-
authorization?: string;
|
|
965
|
-
}) => Promise<{
|
|
966
|
-
prefix?: string | undefined;
|
|
967
|
-
links: {
|
|
968
|
-
method?: string | undefined;
|
|
969
|
-
group?: string | undefined;
|
|
970
|
-
requestBodyType?: string | undefined;
|
|
971
|
-
service?: string | undefined;
|
|
972
|
-
path: string;
|
|
973
|
-
name: string;
|
|
974
|
-
}[];
|
|
975
|
-
}>>;
|
|
976
|
-
}
|
|
977
|
-
|
|
978
|
-
declare class ServerLinksProvider {
|
|
979
|
-
protected readonly alepha: Alepha;
|
|
980
|
-
protected readonly client: HttpClient;
|
|
981
|
-
protected readonly remoteProvider: RemoteDescriptorProvider;
|
|
982
|
-
protected readonly serverActionDescriptorProvider: ServerActionDescriptorProvider;
|
|
983
|
-
readonly links: RouteDescriptor<{
|
|
984
|
-
response: TObject<{
|
|
985
|
-
prefix: TOptional<TString$1>;
|
|
986
|
-
links: TArray<TObject<{
|
|
987
|
-
name: TString$1;
|
|
988
|
-
path: TString$1;
|
|
989
|
-
method: TOptional<TString$1>;
|
|
990
|
-
group: TOptional<TString$1>;
|
|
991
|
-
requestBodyType: TOptional<TString$1>;
|
|
992
|
-
service: TOptional<TString$1>;
|
|
993
|
-
}>>;
|
|
994
|
-
}>;
|
|
995
|
-
}>;
|
|
996
|
-
readonly schema: RouteDescriptor<{
|
|
997
|
-
params: TObject<{
|
|
998
|
-
name: TString$1;
|
|
999
|
-
}>;
|
|
1000
|
-
response: TRecord<TString$1, TAny>;
|
|
1001
|
-
}>;
|
|
1002
|
-
getLinks(options: {
|
|
1003
|
-
user?: UserAccountToken;
|
|
1004
|
-
authorization?: string;
|
|
1005
|
-
}): Promise<ApiLinksResponse>;
|
|
1006
|
-
}
|
|
1007
|
-
|
|
395
|
+
//#endregion
|
|
396
|
+
//#region src/providers/features/ServerLoggerProvider.d.ts
|
|
1008
397
|
declare class ServerLoggerProvider {
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
}
|
|
1015
|
-
|
|
398
|
+
protected readonly log: _alepha_core3.Logger;
|
|
399
|
+
protected readonly alepha: Alepha;
|
|
400
|
+
readonly onRequest: _alepha_core3.HookDescriptor<"server:onRequest">;
|
|
401
|
+
readonly onError: _alepha_core3.HookDescriptor<"server:onError">;
|
|
402
|
+
readonly onResponse: _alepha_core3.HookDescriptor<"server:onResponse">;
|
|
403
|
+
}
|
|
404
|
+
//#endregion
|
|
405
|
+
//#region src/providers/features/ServerMultipartProvider.d.ts
|
|
1016
406
|
declare class ServerMultipartProvider {
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
407
|
+
protected readonly helper: ActionDescriptorHelper;
|
|
408
|
+
protected readonly alepha: Alepha;
|
|
409
|
+
readonly onRequest: _alepha_core7.HookDescriptor<"server:onRequest">;
|
|
410
|
+
readonly onSend: _alepha_core7.HookDescriptor<"server:onResponse">;
|
|
411
|
+
handleMultipartBodyFromNode(route: ServerRoute, stream: IncomingMessage): Promise<{
|
|
412
|
+
body: Record<string, any>;
|
|
413
|
+
cleanup: () => Promise<void>;
|
|
414
|
+
}>;
|
|
415
|
+
parseMultipart(req: IncomingMessage, config?: Omit<BusboyConfig, "headers">): Promise<MultipartResult>;
|
|
1026
416
|
}
|
|
1027
417
|
interface MultipartResult {
|
|
1028
|
-
|
|
1029
|
-
|
|
418
|
+
fields: Record<string, string | string[]>;
|
|
419
|
+
files: Record<string, HybridFile>;
|
|
1030
420
|
}
|
|
1031
421
|
interface HybridFile extends FileLike {
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
}
|
|
1039
|
-
|
|
422
|
+
cleanup(): Promise<void>;
|
|
423
|
+
_state: {
|
|
424
|
+
cleanup: boolean;
|
|
425
|
+
size: number;
|
|
426
|
+
tmpPath: string;
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
//#endregion
|
|
430
|
+
//#region src/providers/features/ServerNotReadyProvider.d.ts
|
|
1040
431
|
/**
|
|
1041
432
|
* On every request, this provider checks if the server is ready.
|
|
1042
433
|
*
|
|
@@ -1045,134 +436,258 @@ interface HybridFile extends FileLike {
|
|
|
1045
436
|
* The response also includes a `Retry-After` header indicating that the client should retry after 5 seconds.
|
|
1046
437
|
*/
|
|
1047
438
|
declare class ServerNotReadyProvider {
|
|
1048
|
-
|
|
1049
|
-
|
|
439
|
+
protected readonly alepha: Alepha;
|
|
440
|
+
readonly onRequest: _alepha_core9.HookDescriptor<"server:onRequest">;
|
|
1050
441
|
}
|
|
1051
|
-
|
|
442
|
+
//#endregion
|
|
443
|
+
//#region src/providers/features/ServerSecurityProvider.d.ts
|
|
1052
444
|
declare class ServerSecurityProvider {
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
}
|
|
1061
|
-
|
|
445
|
+
protected readonly log: _alepha_core71.Logger;
|
|
446
|
+
protected readonly securityProvider: SecurityProvider;
|
|
447
|
+
protected readonly jwtProvider: JwtProvider;
|
|
448
|
+
protected readonly alepha: Alepha;
|
|
449
|
+
readonly onClientRequest: _alepha_core71.HookDescriptor<"client:onRequest">;
|
|
450
|
+
protected readonly onRequest: _alepha_core71.HookDescriptor<"server:onRequest">;
|
|
451
|
+
protected readonly onRoute: _alepha_core71.HookDescriptor<"server:onRoute">;
|
|
452
|
+
}
|
|
453
|
+
//#endregion
|
|
454
|
+
//#region src/providers/features/ServerTimingProvider.d.ts
|
|
1062
455
|
type TimingMap = Record<string, [number, number]>;
|
|
1063
456
|
declare class ServerTimingProvider {
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
457
|
+
protected readonly log: _alepha_core10.Logger;
|
|
458
|
+
protected readonly alepha: Alepha;
|
|
459
|
+
readonly onRequest: _alepha_core10.HookDescriptor<"server:onRequest">;
|
|
460
|
+
readonly onResponse: _alepha_core10.HookDescriptor<"server:onResponse">;
|
|
461
|
+
protected get handlerName(): string;
|
|
462
|
+
beginTiming(name: string): void;
|
|
463
|
+
endTiming(name: string): void;
|
|
464
|
+
protected setDuration(name: string, timing: TimingMap): void;
|
|
465
|
+
}
|
|
466
|
+
//#endregion
|
|
467
|
+
//#region src/providers/ServerRouterProvider.d.ts
|
|
468
|
+
/**
|
|
469
|
+
* Main router for all routes on the server side.
|
|
470
|
+
*
|
|
471
|
+
* - $route => generic route
|
|
472
|
+
* - $action => action route (for API calls)
|
|
473
|
+
* - $page => React route (for SSR)
|
|
474
|
+
*/
|
|
475
|
+
declare class ServerRouterProvider extends RouterProvider<ServerRouteWithHandler> {
|
|
476
|
+
protected readonly alepha: Alepha;
|
|
477
|
+
route<TConfig extends RequestConfigSchema = RequestConfigSchema>(route: ServerRoute<TConfig>): Promise<void>;
|
|
478
|
+
onRequest(route: ServerRoute, rawRequest: ServerRawRequest, responseKind: ResponseKind): Promise<ServerResponse>;
|
|
479
|
+
protected processRequest(request: ServerRequest, route: ServerRoute, responseKind: ResponseKind): Promise<{
|
|
480
|
+
status: number;
|
|
481
|
+
headers: Record<string, string> & {
|
|
482
|
+
"set-cookie"?: string[];
|
|
483
|
+
};
|
|
484
|
+
body: any;
|
|
485
|
+
}>;
|
|
486
|
+
protected runRouteHandler(route: ServerRoute, request: ServerRequest, responseKind: ResponseKind): Promise<void>;
|
|
487
|
+
protected getResponseType(schema?: RequestConfigSchema): ResponseKind;
|
|
488
|
+
protected errorHandler(route: ServerRoute, request: ServerRequest, error: Error): Promise<void>;
|
|
489
|
+
validateRequest(route: {
|
|
490
|
+
schema?: RequestConfigSchema;
|
|
491
|
+
}, request: ServerRequestConfig): void;
|
|
492
|
+
serializeResponse(route: ServerRoute, reply: ServerReply, responseKind: ResponseKind): void;
|
|
1072
493
|
}
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
494
|
+
//#endregion
|
|
495
|
+
//#region src/providers/platforms/ServerProvider.d.ts
|
|
496
|
+
declare class ServerProvider {
|
|
497
|
+
constructor();
|
|
498
|
+
get hostname(): string;
|
|
499
|
+
}
|
|
500
|
+
//#endregion
|
|
501
|
+
//#region src/providers/platforms/NodeHttpServerProvider.d.ts
|
|
502
|
+
declare const envSchema$1: _alepha_core15.TObject<{
|
|
503
|
+
SERVER_PORT: _sinclair_typebox13.TNumber;
|
|
504
|
+
SERVER_HOST: _sinclair_typebox13.TString;
|
|
1077
505
|
}>;
|
|
1078
|
-
declare module "
|
|
1079
|
-
|
|
1080
|
-
}
|
|
506
|
+
declare module "alepha" {
|
|
507
|
+
interface Env extends Partial<Static<typeof envSchema$1>> {}
|
|
1081
508
|
}
|
|
1082
509
|
declare class NodeHttpServerProvider implements ServerProvider {
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
}
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
}>>;
|
|
510
|
+
protected readonly alepha: Alepha;
|
|
511
|
+
protected readonly log: _alepha_core15.Logger;
|
|
512
|
+
protected readonly env: {
|
|
513
|
+
SERVER_PORT: number;
|
|
514
|
+
SERVER_HOST: string;
|
|
515
|
+
};
|
|
516
|
+
protected readonly router: ServerRouterProvider;
|
|
517
|
+
protected readonly server: http18.Server<typeof IncomingMessage, typeof ServerResponse$1>;
|
|
518
|
+
handle(req: IncomingMessage, res: ServerResponse$1): Promise<number | void>;
|
|
519
|
+
createRouterRequest(req: IncomingMessage, res: ServerResponse$1, params?: Record<string, string>): ServerRawRequest;
|
|
520
|
+
getProtocol(req: IncomingMessage): "http" | "https";
|
|
521
|
+
shouldHaveBody(method: string): boolean;
|
|
522
|
+
get hostname(): string;
|
|
523
|
+
readonly start: _alepha_core15.HookDescriptor<"start">;
|
|
524
|
+
protected readonly stop: _alepha_core15.HookDescriptor<"stop">;
|
|
525
|
+
protected listen(): Promise<void>;
|
|
526
|
+
protected close(): Promise<void>;
|
|
527
|
+
}
|
|
528
|
+
//#endregion
|
|
529
|
+
//#region src/schemas/apiLinksResponseSchema.d.ts
|
|
530
|
+
declare const apiLinkSchema: _sinclair_typebox37.TObject<{
|
|
531
|
+
name: _sinclair_typebox37.TString;
|
|
532
|
+
path: _sinclair_typebox37.TString;
|
|
533
|
+
method: _sinclair_typebox37.TOptional<_sinclair_typebox37.TString>;
|
|
534
|
+
group: _sinclair_typebox37.TOptional<_sinclair_typebox37.TString>;
|
|
535
|
+
requestBodyType: _sinclair_typebox37.TOptional<_sinclair_typebox37.TString>;
|
|
536
|
+
service: _sinclair_typebox37.TOptional<_sinclair_typebox37.TString>;
|
|
1111
537
|
}>;
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
538
|
+
declare const apiLinksResponseSchema: _sinclair_typebox37.TObject<{
|
|
539
|
+
prefix: _sinclair_typebox37.TOptional<_sinclair_typebox37.TString>;
|
|
540
|
+
links: _sinclair_typebox37.TArray<_sinclair_typebox37.TObject<{
|
|
541
|
+
name: _sinclair_typebox37.TString;
|
|
542
|
+
path: _sinclair_typebox37.TString;
|
|
543
|
+
method: _sinclair_typebox37.TOptional<_sinclair_typebox37.TString>;
|
|
544
|
+
group: _sinclair_typebox37.TOptional<_sinclair_typebox37.TString>;
|
|
545
|
+
requestBodyType: _sinclair_typebox37.TOptional<_sinclair_typebox37.TString>;
|
|
546
|
+
service: _sinclair_typebox37.TOptional<_sinclair_typebox37.TString>;
|
|
547
|
+
}>>;
|
|
1117
548
|
}>;
|
|
1118
|
-
type
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
549
|
+
type ApiLinksResponse = Static<typeof apiLinksResponseSchema>;
|
|
550
|
+
type ApiLink = Static<typeof apiLinkSchema>;
|
|
551
|
+
//#endregion
|
|
552
|
+
//#region src/providers/ServerActionDescriptorProvider.d.ts
|
|
553
|
+
declare const envSchema: _alepha_core23.TObject<{
|
|
554
|
+
SERVER_API_PREFIX: _sinclair_typebox21.TString;
|
|
555
|
+
SERVER_SECURITY_ENABLED: _sinclair_typebox21.TBoolean;
|
|
1123
556
|
}>;
|
|
1124
|
-
declare module "
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
557
|
+
declare module "alepha/core" {
|
|
558
|
+
interface Env extends Partial<Static<typeof envSchema>> {}
|
|
559
|
+
interface State {
|
|
560
|
+
/**
|
|
561
|
+
* Real (or fake) user account, used for internal actions.
|
|
562
|
+
* If you define this, you assume that all actions are executed by this user by default.
|
|
563
|
+
* And to force a different user, you need to pass it explicitly in the options.
|
|
564
|
+
*/
|
|
565
|
+
"ServerSecurityProvider.localSystemUser"?: UserAccountToken;
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
declare class ServerActionDescriptorProvider {
|
|
569
|
+
protected readonly log: _alepha_core23.Logger;
|
|
570
|
+
protected readonly alepha: Alepha;
|
|
571
|
+
protected readonly env: {
|
|
572
|
+
SERVER_API_PREFIX: string;
|
|
573
|
+
SERVER_SECURITY_ENABLED: boolean;
|
|
574
|
+
};
|
|
575
|
+
protected readonly client: HttpClient;
|
|
576
|
+
protected readonly serverProvider: ServerProvider;
|
|
577
|
+
protected readonly helper: ActionDescriptorHelper;
|
|
578
|
+
protected readonly routerProvider: ServerRouterProvider;
|
|
579
|
+
protected readonly actions: ServerRouteAction[];
|
|
580
|
+
getActions(): ServerRouteAction<RequestConfigSchema>[];
|
|
581
|
+
getPrefix(): string;
|
|
582
|
+
readonly configure: _alepha_core23.HookDescriptor<"configure">;
|
|
583
|
+
registerAction(value: ActionDescriptor, key: string, instance: any, prefix?: string): Promise<void>;
|
|
584
|
+
/**
|
|
585
|
+
* Check a mock function for the specified route.
|
|
586
|
+
*
|
|
587
|
+
* This is mostly used for testing purposes.
|
|
588
|
+
*/
|
|
589
|
+
protected createLocalHandler(action: ActionDescriptorOptions, permission: Permission): (config?: ServerRequestConfigEntry, options?: ClientRequestOptions) => Promise<any>;
|
|
590
|
+
/**
|
|
591
|
+
* Get the user account token for a local action call.
|
|
592
|
+
* It will check the options, context, and system user.
|
|
593
|
+
*/
|
|
594
|
+
protected getUserFromLocalFunctionContext(options: {
|
|
595
|
+
user?: UserAccountToken | "system" | "context";
|
|
596
|
+
}, permission: Permission, isRouteSecure: boolean): UserAccountToken | undefined;
|
|
597
|
+
}
|
|
598
|
+
declare const isServerAction: (value: any) => value is ServerRouteAction;
|
|
599
|
+
interface ServerRemote {
|
|
600
|
+
url: string;
|
|
601
|
+
name: string;
|
|
602
|
+
proxy: boolean;
|
|
603
|
+
internal: boolean;
|
|
604
|
+
links: (args: {
|
|
605
|
+
authorization?: string;
|
|
606
|
+
}) => Promise<ApiLinksResponse>;
|
|
607
|
+
schema: (args: {
|
|
608
|
+
name: string;
|
|
609
|
+
authorization?: string;
|
|
610
|
+
}) => Promise<any>;
|
|
611
|
+
serviceAccount?: ServiceAccountDescriptor;
|
|
612
|
+
prefix: string;
|
|
1164
613
|
}
|
|
614
|
+
interface ServerRouteAction<TConfig extends RequestConfigSchema = RequestConfigSchema> extends ServerRoute<TConfig> {
|
|
615
|
+
prefix: string;
|
|
616
|
+
method: RouteMethod;
|
|
617
|
+
name: string;
|
|
618
|
+
group: string;
|
|
619
|
+
permission: Permission;
|
|
620
|
+
options: ActionDescriptorOptions;
|
|
621
|
+
localHandler: LocalHandler;
|
|
622
|
+
}
|
|
623
|
+
type LocalHandler<TConfig extends RequestConfigSchema = RequestConfigSchema> = (config?: ServerRequestConfigEntry<TConfig>, options?: ClientRequestOptions) => Promise<any>;
|
|
624
|
+
//#endregion
|
|
625
|
+
//#region src/schemas/errorSchema.d.ts
|
|
626
|
+
declare const errorSchema: _sinclair_typebox27.TObject<{
|
|
627
|
+
error: _sinclair_typebox27.TString;
|
|
628
|
+
status: _sinclair_typebox27.TNumber;
|
|
629
|
+
message: _sinclair_typebox27.TString;
|
|
630
|
+
details: _sinclair_typebox27.TOptional<_sinclair_typebox27.TString>;
|
|
631
|
+
cause: _sinclair_typebox27.TOptional<_sinclair_typebox27.TObject<{
|
|
632
|
+
name: _sinclair_typebox27.TString;
|
|
633
|
+
message: _sinclair_typebox27.TString;
|
|
634
|
+
}>>;
|
|
635
|
+
}>;
|
|
636
|
+
//#endregion
|
|
637
|
+
//#region src/schemas/okSchema.d.ts
|
|
638
|
+
declare const okSchema: _sinclair_typebox63.TObject<{
|
|
639
|
+
ok: _sinclair_typebox63.TBoolean;
|
|
640
|
+
id: _sinclair_typebox63.TOptional<_sinclair_typebox63.TUnion<[_sinclair_typebox63.TString, _sinclair_typebox63.TInteger]>>;
|
|
641
|
+
count: _sinclair_typebox63.TOptional<_sinclair_typebox63.TNumber>;
|
|
642
|
+
}>;
|
|
643
|
+
type Ok = Static<typeof okSchema>;
|
|
644
|
+
//#endregion
|
|
645
|
+
//#region src/index.d.ts
|
|
1165
646
|
declare module "@alepha/core" {
|
|
1166
|
-
|
|
1167
|
-
|
|
647
|
+
interface Hooks {
|
|
648
|
+
"server:onRoute": {
|
|
649
|
+
route: ServerRoute;
|
|
650
|
+
};
|
|
651
|
+
"server:onRequest": {
|
|
652
|
+
route: ServerRoute;
|
|
653
|
+
request: ServerRequest;
|
|
654
|
+
};
|
|
655
|
+
"server:onError": {
|
|
656
|
+
route: ServerRoute;
|
|
657
|
+
request: ServerRequest;
|
|
658
|
+
error: Error;
|
|
659
|
+
};
|
|
660
|
+
"server:onSend": {
|
|
661
|
+
route: ServerRoute;
|
|
662
|
+
request: ServerRequest;
|
|
663
|
+
};
|
|
664
|
+
"server:onResponse": {
|
|
665
|
+
route: ServerRoute;
|
|
666
|
+
request: ServerRequest;
|
|
667
|
+
response: ServerResponse;
|
|
668
|
+
};
|
|
669
|
+
"client:onRequest": {
|
|
670
|
+
route: HttpAction;
|
|
671
|
+
config: ServerRequestConfigEntry;
|
|
672
|
+
options: ClientRequestOptions;
|
|
673
|
+
headers: Record<string, string>;
|
|
674
|
+
request: RequestInit;
|
|
675
|
+
};
|
|
676
|
+
"client:beforeFetch": {
|
|
677
|
+
url: string;
|
|
678
|
+
options: FetchOptions;
|
|
679
|
+
request: RequestInit;
|
|
680
|
+
};
|
|
681
|
+
"client:onError": {
|
|
682
|
+
route?: HttpAction;
|
|
683
|
+
error: HttpError;
|
|
684
|
+
};
|
|
685
|
+
}
|
|
1168
686
|
}
|
|
1169
687
|
declare class AlephaServer implements Module {
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
SERVER_HEALTH_ENABLED: boolean;
|
|
1173
|
-
};
|
|
1174
|
-
readonly name = "alepha.server";
|
|
1175
|
-
readonly $services: (alepha: Alepha) => void;
|
|
688
|
+
readonly name = "alepha.server";
|
|
689
|
+
readonly $services: (alepha: Alepha) => void;
|
|
1176
690
|
}
|
|
1177
|
-
|
|
1178
|
-
export { $action, $
|
|
691
|
+
//#endregion
|
|
692
|
+
export { $action, $route, ActionDescriptor, ActionDescriptorHelper, ActionDescriptorOptions, AlephaServer, ApiLink, ApiLinksResponse, BadRequestError, ClientRequestEntry, ClientRequestEntryContainer, ClientRequestOptions, ClientRequestResponse, ConflictError, FetchActionArgs, FetchOptions, FetchResponse, ForbiddenError, HttpAction, HttpClient, HttpClientPendingRequests, HttpError, HttpErrorLike, KIND, LocalHandler, NodeHttpServerProvider, NotFoundError, Ok, RequestConfigSchema, ResponseBodyType, ResponseKind, RouteDescriptor, RouteDescriptorOptions, RouteMethod, ServerActionDescriptorProvider, ServerHandler, ServerLoggerProvider, ServerMiddlewareHandler, ServerMultipartProvider, ServerNotReadyProvider, ServerProvider, ServerRawRequest, ServerRemote, ServerReply, ServerRequest, ServerRequestConfig, ServerRequestConfigEntry, ServerResponse, ServerResponseBody, ServerRoute, ServerRouteAction, ServerRouteSecure, ServerRouteWithHandler, ServerRouterProvider, ServerSecurityProvider, ServerTimingProvider, UnauthorizedError, ValidationError, apiLinkSchema, apiLinksResponseSchema, errorNameByStatus, errorSchema, isHttpError, isServerAction, okSchema, routeMethods };
|
|
693
|
+
//# sourceMappingURL=index.d.ts.map
|