yinzerflow 0.1.18 → 0.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/README.md +0 -296
- package/YinzerFlow.d.ts +565 -0
- package/YinzerFlow.js +24 -0
- package/YinzerFlow.js.map +42 -0
- package/docs/advanced-configuration-options.md +175 -0
- package/docs/body-parsing.md +294 -0
- package/docs/cors.md +187 -0
- package/docs/ip-security.md +232 -0
- package/docs/request.md +145 -0
- package/docs/response.md +251 -0
- package/docs/start-here.MD +116 -0
- package/example/index.ts +109 -53
- package/package.json +15 -17
- package/constants/index.d.ts +0 -86
- package/constants/index.js +0 -3
- package/constants/index.js.map +0 -13
- package/docs/README.md +0 -327
- package/docs/content-types.md +0 -390
- package/docs/error-handling.md +0 -266
- package/docs/file-parsers.md +0 -276
- package/docs/hooks.md +0 -289
- package/docs/routing.md +0 -204
- package/example/bun.lock +0 -866
- package/example/hooks/authentication.middleware.ts +0 -77
- package/example/package.json +0 -61
- package/example/routes/authentication.routes.ts +0 -243
- package/example/routes/content-types.ts +0 -116
- package/example/tsconfig.json +0 -32
- package/index.d.ts +0 -395
- package/index.js +0 -23
- package/index.js.map +0 -33
package/YinzerFlow.d.ts
ADDED
|
@@ -0,0 +1,565 @@
|
|
|
1
|
+
type CreateEnum<T> = T[keyof T];
|
|
2
|
+
type DeepPartial<T> = {
|
|
3
|
+
[P in keyof T]?: T[P] extends object ? T[P] extends Array<infer U> ? Array<U> // Keep arrays as-is, don't make array items partial
|
|
4
|
+
: DeepPartial<T[P]> : T[P];
|
|
5
|
+
};
|
|
6
|
+
interface InternalHandlerCallbackGenerics {
|
|
7
|
+
body: unknown;
|
|
8
|
+
response: unknown;
|
|
9
|
+
query: Record<string, string>;
|
|
10
|
+
params: Record<string, string>;
|
|
11
|
+
}
|
|
12
|
+
declare const httpStatusCode: {
|
|
13
|
+
readonly ok: 200;
|
|
14
|
+
readonly created: 201;
|
|
15
|
+
readonly accepted: 202;
|
|
16
|
+
readonly noContent: 204;
|
|
17
|
+
readonly movedPermanently: 301;
|
|
18
|
+
readonly found: 302;
|
|
19
|
+
readonly notModified: 304;
|
|
20
|
+
readonly badRequest: 400;
|
|
21
|
+
readonly unauthorized: 401;
|
|
22
|
+
readonly forbidden: 403;
|
|
23
|
+
readonly notFound: 404;
|
|
24
|
+
readonly methodNotAllowed: 405;
|
|
25
|
+
readonly conflict: 409;
|
|
26
|
+
readonly unsupportedMediaType: 415;
|
|
27
|
+
readonly tooManyRequests: 429;
|
|
28
|
+
readonly internalServerError: 500;
|
|
29
|
+
};
|
|
30
|
+
declare const httpMethod: {
|
|
31
|
+
readonly delete: "DELETE";
|
|
32
|
+
readonly get: "GET";
|
|
33
|
+
readonly head: "HEAD";
|
|
34
|
+
readonly post: "POST";
|
|
35
|
+
readonly put: "PUT";
|
|
36
|
+
readonly patch: "PATCH";
|
|
37
|
+
readonly options: "OPTIONS";
|
|
38
|
+
};
|
|
39
|
+
declare const httpHeaders: {
|
|
40
|
+
readonly authorization: "Authorization";
|
|
41
|
+
readonly proxyAuthorization: "Proxy-Authorization";
|
|
42
|
+
readonly wwwAuthenticate: "WWW-Authenticate";
|
|
43
|
+
readonly cacheControl: "Cache-Control";
|
|
44
|
+
readonly etag: "ETag";
|
|
45
|
+
readonly expires: "Expires";
|
|
46
|
+
readonly lastModified: "Last-Modified";
|
|
47
|
+
readonly ifMatch: "If-Match";
|
|
48
|
+
readonly ifNoneMatch: "If-None-Match";
|
|
49
|
+
readonly ifModifiedSince: "If-Modified-Since";
|
|
50
|
+
readonly ifUnmodifiedSince: "If-Unmodified-Since";
|
|
51
|
+
readonly ifRange: "If-Range";
|
|
52
|
+
readonly age: "Age";
|
|
53
|
+
readonly vary: "Vary";
|
|
54
|
+
readonly contentType: "Content-Type";
|
|
55
|
+
readonly contentLength: "Content-Length";
|
|
56
|
+
readonly contentEncoding: "Content-Encoding";
|
|
57
|
+
readonly contentLanguage: "Content-Language";
|
|
58
|
+
readonly contentDisposition: "Content-Disposition";
|
|
59
|
+
readonly contentLocation: "Content-Location";
|
|
60
|
+
readonly contentRange: "Content-Range";
|
|
61
|
+
readonly accessControlAllowCredentials: "Access-Control-Allow-Credentials";
|
|
62
|
+
readonly accessControlAllowHeaders: "Access-Control-Allow-Headers";
|
|
63
|
+
readonly accessControlAllowMethods: "Access-Control-Allow-Methods";
|
|
64
|
+
readonly accessControlAllowOrigin: "Access-Control-Allow-Origin";
|
|
65
|
+
readonly accessControlExposeHeaders: "Access-Control-Expose-Headers";
|
|
66
|
+
readonly accessControlMaxAge: "Access-Control-Max-Age";
|
|
67
|
+
readonly accessControlRequestHeaders: "Access-Control-Request-Headers";
|
|
68
|
+
readonly accessControlRequestMethod: "Access-Control-Request-Method";
|
|
69
|
+
readonly accept: "Accept";
|
|
70
|
+
readonly acceptEncoding: "Accept-Encoding";
|
|
71
|
+
readonly acceptLanguage: "Accept-Language";
|
|
72
|
+
readonly acceptRanges: "Accept-Ranges";
|
|
73
|
+
readonly host: "Host";
|
|
74
|
+
readonly userAgent: "User-Agent";
|
|
75
|
+
readonly referer: "Referer";
|
|
76
|
+
readonly origin: "Origin";
|
|
77
|
+
readonly from: "From";
|
|
78
|
+
readonly expect: "Expect";
|
|
79
|
+
readonly location: "Location";
|
|
80
|
+
readonly server: "Server";
|
|
81
|
+
readonly date: "Date";
|
|
82
|
+
readonly allow: "Allow";
|
|
83
|
+
readonly retryAfter: "Retry-After";
|
|
84
|
+
readonly range: "Range";
|
|
85
|
+
readonly contentSecurityPolicy: "Content-Security-Policy";
|
|
86
|
+
readonly contentSecurityPolicyReportOnly: "Content-Security-Policy-Report-Only";
|
|
87
|
+
readonly strictTransportSecurity: "Strict-Transport-Security";
|
|
88
|
+
readonly xContentTypeOptions: "X-Content-Type-Options";
|
|
89
|
+
readonly xFrameOptions: "X-Frame-Options";
|
|
90
|
+
readonly xXSSProtection: "X-XSS-Protection";
|
|
91
|
+
readonly referrerPolicy: "Referrer-Policy";
|
|
92
|
+
readonly permissionsPolicy: "Permissions-Policy";
|
|
93
|
+
readonly crossOriginEmbedderPolicy: "Cross-Origin-Embedder-Policy";
|
|
94
|
+
readonly crossOriginOpenerPolicy: "Cross-Origin-Opener-Policy";
|
|
95
|
+
readonly crossOriginResourcePolicy: "Cross-Origin-Resource-Policy";
|
|
96
|
+
readonly cookie: "Cookie";
|
|
97
|
+
readonly setCookie: "Set-Cookie";
|
|
98
|
+
readonly connection: "Connection";
|
|
99
|
+
readonly keepAlive: "Keep-Alive";
|
|
100
|
+
readonly upgrade: "Upgrade";
|
|
101
|
+
readonly upgradeInsecureRequests: "Upgrade-Insecure-Requests";
|
|
102
|
+
readonly transferEncoding: "Transfer-Encoding";
|
|
103
|
+
readonly te: "TE";
|
|
104
|
+
readonly trailer: "Trailer";
|
|
105
|
+
readonly forwarded: "Forwarded";
|
|
106
|
+
readonly xForwardedFor: "X-Forwarded-For";
|
|
107
|
+
readonly via: "Via";
|
|
108
|
+
readonly maxForwards: "Max-Forwards";
|
|
109
|
+
readonly altSvc: "Alt-Svc";
|
|
110
|
+
readonly altUsed: "Alt-Used";
|
|
111
|
+
readonly timingAllowOrigin: "Timing-Allow-Origin";
|
|
112
|
+
readonly serverTiming: "Server-Timing";
|
|
113
|
+
readonly refresh: "Refresh";
|
|
114
|
+
readonly link: "Link";
|
|
115
|
+
readonly xPoweredBy: "X-Powered-By";
|
|
116
|
+
readonly xPermittedCrossDomainPolicies: "X-Permitted-Cross-Domain-Policies";
|
|
117
|
+
readonly reportTo: "Report-To";
|
|
118
|
+
readonly serviceWorkerAllowed: "Service-Worker-Allowed";
|
|
119
|
+
readonly sourceMap: "SourceMap";
|
|
120
|
+
readonly priority: "Priority";
|
|
121
|
+
readonly secGPC: "Sec-GPC";
|
|
122
|
+
readonly clearSiteData: "Clear-Site-Data";
|
|
123
|
+
readonly noVarySearch: "No-Vary-Search";
|
|
124
|
+
};
|
|
125
|
+
type InternalHttpStatusCode = CreateEnum<typeof httpStatusCode>;
|
|
126
|
+
type InternalHttpMethod = CreateEnum<typeof httpMethod>;
|
|
127
|
+
type InternalHttpHeaders = Lowercase<CreateEnum<typeof httpHeaders>> | string;
|
|
128
|
+
interface Request$1<T = InternalHandlerCallbackGenerics> {
|
|
129
|
+
protocol: string;
|
|
130
|
+
method: InternalHttpMethod;
|
|
131
|
+
path: string;
|
|
132
|
+
headers: Partial<Record<InternalHttpHeaders, string>>;
|
|
133
|
+
body: T["body"];
|
|
134
|
+
query: T["query"];
|
|
135
|
+
params: T["params"];
|
|
136
|
+
ipAddress: string; // The ip address of the client (Configure proxy hops if behind a proxy, load balancer, etc.)
|
|
137
|
+
rawBody: Buffer | string; // The raw body of the request. Useful for parsing the body manually.
|
|
138
|
+
}
|
|
139
|
+
interface Response$1 {
|
|
140
|
+
setStatusCode: (statusCode: InternalHttpStatusCode) => void;
|
|
141
|
+
addHeaders: (headers: Partial<Record<InternalHttpHeaders, string>>) => void;
|
|
142
|
+
removeHeaders: (headerNames: Array<InternalHttpHeaders>) => void;
|
|
143
|
+
}
|
|
144
|
+
interface Context {
|
|
145
|
+
request: Request$1;
|
|
146
|
+
response: Response$1;
|
|
147
|
+
}
|
|
148
|
+
type HandlerCallback<T = InternalHandlerCallbackGenerics> = (ctx: Context) => Promise<T["response"] | void> | T["response"] | void;
|
|
149
|
+
type InternalGlobalHookOptions = {
|
|
150
|
+
routesToExclude: Array<string>;
|
|
151
|
+
} & {
|
|
152
|
+
routesToInclude: Array<string>;
|
|
153
|
+
};
|
|
154
|
+
interface InternalHookRegistryImpl {
|
|
155
|
+
readonly _beforeAll: Set<{
|
|
156
|
+
handler: HandlerCallback;
|
|
157
|
+
options?: InternalGlobalHookOptions;
|
|
158
|
+
}>;
|
|
159
|
+
readonly _afterAll: Set<{
|
|
160
|
+
handler: HandlerCallback;
|
|
161
|
+
options?: InternalGlobalHookOptions;
|
|
162
|
+
}>;
|
|
163
|
+
_onError: HandlerCallback;
|
|
164
|
+
_onNotFound: HandlerCallback;
|
|
165
|
+
_addBeforeHooks: (handlers: Array<HandlerCallback>, options?: InternalGlobalHookOptions) => void;
|
|
166
|
+
_addAfterHooks: (handlers: Array<HandlerCallback>, options?: InternalGlobalHookOptions) => void;
|
|
167
|
+
_addOnError: (handler: HandlerCallback) => void;
|
|
168
|
+
_addOnNotFound: (handler: HandlerCallback) => void;
|
|
169
|
+
}
|
|
170
|
+
interface InternalRouteRegistryImpl {
|
|
171
|
+
readonly _exactRoutes: Map<InternalHttpMethod, Map<string, InternalRouteRegistry>>;
|
|
172
|
+
readonly _parameterizedRoutes: Map<InternalHttpMethod, Array<InternalPreCompiledRoute>>;
|
|
173
|
+
_register: (route: InternalRouteRegistry) => void;
|
|
174
|
+
_findRoute: (method: InternalHttpMethod, path: string) => InternalRouteRegistry | undefined;
|
|
175
|
+
}
|
|
176
|
+
interface InternalRouteRegistryOptions {
|
|
177
|
+
beforeHooks: Array<HandlerCallback>;
|
|
178
|
+
afterHooks: Array<HandlerCallback>;
|
|
179
|
+
}
|
|
180
|
+
interface InternalRouteRegistry {
|
|
181
|
+
prefix?: string;
|
|
182
|
+
path: string;
|
|
183
|
+
method: InternalHttpMethod;
|
|
184
|
+
handler: HandlerCallback;
|
|
185
|
+
options: InternalRouteRegistryOptions;
|
|
186
|
+
params: Record<string, string>;
|
|
187
|
+
}
|
|
188
|
+
interface InternalPreCompiledRoute extends InternalRouteRegistry {
|
|
189
|
+
pattern: RegExp;
|
|
190
|
+
paramNames: Array<string>;
|
|
191
|
+
isParameterized: boolean;
|
|
192
|
+
}
|
|
193
|
+
declare const logLevels: {
|
|
194
|
+
readonly off: "off";
|
|
195
|
+
readonly verbose: "verbose";
|
|
196
|
+
readonly network: "network";
|
|
197
|
+
};
|
|
198
|
+
type InternalCorsConfiguration = InternalCorsDisabledConfiguration | InternalCorsEnabledConfiguration;
|
|
199
|
+
interface InternalCorsDisabledConfiguration {
|
|
200
|
+
/**
|
|
201
|
+
* Disable CORS handling
|
|
202
|
+
*/
|
|
203
|
+
enabled: false;
|
|
204
|
+
}
|
|
205
|
+
interface InternalCorsEnabledConfiguration {
|
|
206
|
+
/**
|
|
207
|
+
* Enable CORS handling
|
|
208
|
+
*/
|
|
209
|
+
enabled: true;
|
|
210
|
+
/**
|
|
211
|
+
* Allowed origins for CORS requests (REQUIRED when enabled)
|
|
212
|
+
* - string: Single origin (e.g., 'https://example.com')
|
|
213
|
+
* - string[]: Multiple specific origins
|
|
214
|
+
* - '*': Allow all origins (not recommended for production with credentials)
|
|
215
|
+
* - function: Dynamic origin validation
|
|
216
|
+
*/
|
|
217
|
+
origin: Array<string> | RegExp | string | ((origin: string | undefined, request: any) => boolean);
|
|
218
|
+
/**
|
|
219
|
+
* HTTP methods allowed for CORS requests
|
|
220
|
+
* @default ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS']
|
|
221
|
+
*/
|
|
222
|
+
methods: Array<string>;
|
|
223
|
+
/**
|
|
224
|
+
* Headers allowed in CORS requests
|
|
225
|
+
* - string[]: Specific headers
|
|
226
|
+
* - '*': Allow all headers
|
|
227
|
+
* @default ['*']
|
|
228
|
+
*/
|
|
229
|
+
allowedHeaders: Array<string> | string | "*";
|
|
230
|
+
/**
|
|
231
|
+
* Headers exposed to the client in CORS responses
|
|
232
|
+
* @default []
|
|
233
|
+
*/
|
|
234
|
+
exposedHeaders: Array<string>;
|
|
235
|
+
/**
|
|
236
|
+
* Allow credentials (cookies, authorization headers) in CORS requests
|
|
237
|
+
* Note: When true, origin cannot be '*'
|
|
238
|
+
* @default false
|
|
239
|
+
*/
|
|
240
|
+
credentials: boolean;
|
|
241
|
+
/**
|
|
242
|
+
* Maximum age (in seconds) for preflight cache
|
|
243
|
+
* Tells browser how long to cache preflight response (client-side only)
|
|
244
|
+
* @default 86400 (24 hours)
|
|
245
|
+
*/
|
|
246
|
+
maxAge: number;
|
|
247
|
+
/**
|
|
248
|
+
* Continue to route handler after preflight
|
|
249
|
+
* - false: Handle preflight completely in CORS system (recommended)
|
|
250
|
+
* - true: Pass preflight to route handlers (requires manual OPTIONS routes)
|
|
251
|
+
* @default false
|
|
252
|
+
*/
|
|
253
|
+
preflightContinue: boolean;
|
|
254
|
+
/**
|
|
255
|
+
* Status code for successful OPTIONS requests
|
|
256
|
+
* @default 204
|
|
257
|
+
*/
|
|
258
|
+
optionsSuccessStatus: InternalHttpStatusCode;
|
|
259
|
+
}
|
|
260
|
+
interface InternalConnectionOptions {
|
|
261
|
+
/**
|
|
262
|
+
* Default socket timeout in milliseconds (30 seconds)
|
|
263
|
+
*
|
|
264
|
+
* Standard timeout for most socket connections.
|
|
265
|
+
* It is long enough for slow clients but short enough to prevent idle connections from staying open indefinitely.
|
|
266
|
+
*/
|
|
267
|
+
socketTimeout: number;
|
|
268
|
+
/**
|
|
269
|
+
* Default graceful shutdown timeout in milliseconds (30 seconds)
|
|
270
|
+
*
|
|
271
|
+
* This is the maximum time to wait for a connection to complete before the server will close it.
|
|
272
|
+
*/
|
|
273
|
+
gracefulShutdownTimeout: number;
|
|
274
|
+
/**
|
|
275
|
+
* Default keep-alive timeout in milliseconds (65 seconds)
|
|
276
|
+
*
|
|
277
|
+
* This is the maximum time a connection can be idle before the server will close it.
|
|
278
|
+
* This is to allow for a connection to stay open for a period of time so subsequent requests can be handled without a new connection.
|
|
279
|
+
* This is also to prevent a connection from staying open indefinitely.
|
|
280
|
+
* This is also useful for load balancing and preventing a single server from being overwhelmed by a large number of connections.
|
|
281
|
+
* AWS recommends a keep-alive timeout of 65 seconds because there idle timeout is 60 seconds.
|
|
282
|
+
*/
|
|
283
|
+
keepAliveTimeout: number;
|
|
284
|
+
/**
|
|
285
|
+
* Default headers timeout in milliseconds (66 seconds)
|
|
286
|
+
*
|
|
287
|
+
* This is the maximum time to wait for a header from the client.
|
|
288
|
+
* This is to allow for a connection to stay open for a period of time so subsequent requests can be handled without a new connection.
|
|
289
|
+
* This is also to prevent a connection from staying open indefinitely.
|
|
290
|
+
* This is also useful for load balancing and preventing a single server from being overwhelmed by a large number of connections.
|
|
291
|
+
* It is recommended to set this value to be greater than the keep-alive timeout to prevent the server from closing the connection prematurely
|
|
292
|
+
* before the keep-alive timeout has expired.
|
|
293
|
+
*/
|
|
294
|
+
headersTimeout: number;
|
|
295
|
+
}
|
|
296
|
+
interface InternalBodyParserConfiguration {
|
|
297
|
+
/**
|
|
298
|
+
* JSON parsing security configuration
|
|
299
|
+
*/
|
|
300
|
+
json: InternalJsonParserConfiguration;
|
|
301
|
+
/**
|
|
302
|
+
* File upload security configuration
|
|
303
|
+
*/
|
|
304
|
+
fileUploads: InternalFileUploadConfiguration;
|
|
305
|
+
/**
|
|
306
|
+
* URL-encoded form data configuration
|
|
307
|
+
*/
|
|
308
|
+
urlEncoded: InternalUrlEncodedConfiguration;
|
|
309
|
+
}
|
|
310
|
+
interface InternalJsonParserConfiguration {
|
|
311
|
+
/**
|
|
312
|
+
* Maximum JSON request body size in bytes
|
|
313
|
+
* @default 262144 (256KB) - reasonable for API payloads
|
|
314
|
+
* @min 1024 (1KB)
|
|
315
|
+
*/
|
|
316
|
+
maxSize: number;
|
|
317
|
+
/**
|
|
318
|
+
* Maximum JSON nesting depth to prevent stack overflow attacks
|
|
319
|
+
* @default 10
|
|
320
|
+
* @min 1
|
|
321
|
+
*/
|
|
322
|
+
maxDepth: number;
|
|
323
|
+
/**
|
|
324
|
+
* Allow prototype properties (__proto__, constructor, prototype) in JSON
|
|
325
|
+
* SECURITY WARNING: Setting this to true enables prototype pollution attacks
|
|
326
|
+
* @default false
|
|
327
|
+
*/
|
|
328
|
+
allowPrototypeProperties: boolean;
|
|
329
|
+
/**
|
|
330
|
+
* Maximum number of keys in JSON objects to prevent memory exhaustion
|
|
331
|
+
* @default 1000
|
|
332
|
+
* @min 10
|
|
333
|
+
*/
|
|
334
|
+
maxKeys: number;
|
|
335
|
+
/**
|
|
336
|
+
* Maximum length of JSON string values to prevent memory exhaustion
|
|
337
|
+
* @default 1048576 (1MB)
|
|
338
|
+
* @min 100
|
|
339
|
+
*/
|
|
340
|
+
maxStringLength: number;
|
|
341
|
+
/**
|
|
342
|
+
* Maximum number of array elements to prevent memory exhaustion
|
|
343
|
+
* @default 10000
|
|
344
|
+
* @min 10
|
|
345
|
+
*/
|
|
346
|
+
maxArrayLength: number;
|
|
347
|
+
}
|
|
348
|
+
interface InternalFileUploadConfiguration {
|
|
349
|
+
/**
|
|
350
|
+
* Maximum size per file in bytes
|
|
351
|
+
* @default 10485760 (10MB) - reasonable for documents/images
|
|
352
|
+
* @min 1024 (1KB)
|
|
353
|
+
*/
|
|
354
|
+
maxFileSize: number;
|
|
355
|
+
/**
|
|
356
|
+
* Maximum total size of all files in a single request
|
|
357
|
+
* @default 52428800 (50MB)
|
|
358
|
+
* @min 1024 (1KB)
|
|
359
|
+
*/
|
|
360
|
+
maxTotalSize: number;
|
|
361
|
+
/**
|
|
362
|
+
* Maximum number of files per request
|
|
363
|
+
* @default 10
|
|
364
|
+
* @min 1
|
|
365
|
+
*/
|
|
366
|
+
maxFiles: number;
|
|
367
|
+
/**
|
|
368
|
+
* Allowed file extensions (empty array allows all)
|
|
369
|
+
* @default [] (all extensions allowed)
|
|
370
|
+
* @example ['.jpg', '.png', '.pdf', '.txt']
|
|
371
|
+
*/
|
|
372
|
+
allowedExtensions: Array<string>;
|
|
373
|
+
/**
|
|
374
|
+
* Blocked file extensions for security
|
|
375
|
+
* @default ['.exe', '.bat', '.cmd', '.scr', '.pif', '.com']
|
|
376
|
+
*/
|
|
377
|
+
blockedExtensions: Array<string>;
|
|
378
|
+
/**
|
|
379
|
+
* Maximum filename length to prevent path issues
|
|
380
|
+
* @default 255
|
|
381
|
+
* @min 10
|
|
382
|
+
*/
|
|
383
|
+
maxFilenameLength: number;
|
|
384
|
+
}
|
|
385
|
+
interface InternalUrlEncodedConfiguration {
|
|
386
|
+
/**
|
|
387
|
+
* Maximum URL-encoded form data size in bytes
|
|
388
|
+
* @default 1048576 (1MB)
|
|
389
|
+
* @min 1024 (1KB)
|
|
390
|
+
*/
|
|
391
|
+
maxSize: number;
|
|
392
|
+
/**
|
|
393
|
+
* Maximum number of form fields
|
|
394
|
+
* @default 1000
|
|
395
|
+
* @min 10
|
|
396
|
+
*/
|
|
397
|
+
maxFields: number;
|
|
398
|
+
/**
|
|
399
|
+
* Maximum field name length
|
|
400
|
+
* @default 100
|
|
401
|
+
* @min 5
|
|
402
|
+
*/
|
|
403
|
+
maxFieldNameLength: number;
|
|
404
|
+
/**
|
|
405
|
+
* Maximum field value length
|
|
406
|
+
* @default 1048576 (1MB)
|
|
407
|
+
* @min 100
|
|
408
|
+
*/
|
|
409
|
+
maxFieldLength: number;
|
|
410
|
+
}
|
|
411
|
+
interface InternalIpValidationConfig {
|
|
412
|
+
/**
|
|
413
|
+
* List of trusted proxy IP addresses that are allowed to set forwarded headers
|
|
414
|
+
* Only these IPs can provide X-Forwarded-For and similar headers
|
|
415
|
+
* Use '*' to trust any proxy (less secure but useful for complex/unknown infrastructure)
|
|
416
|
+
* @default ['127.0.0.1', '::1']
|
|
417
|
+
* @example ['127.0.0.1', '::1', '192.168.1.10'] // Specific proxies
|
|
418
|
+
* @example ['*'] // Trust any proxy (enables spoofing detection without proxy validation)
|
|
419
|
+
*/
|
|
420
|
+
trustedProxies: Array<string>;
|
|
421
|
+
/**
|
|
422
|
+
* Allow private IP addresses (RFC 1918, RFC 4193, RFC 3927) as client IPs
|
|
423
|
+
* Set to false for public-facing APIs that should only receive public IPs
|
|
424
|
+
* @default true
|
|
425
|
+
*/
|
|
426
|
+
allowPrivateIps: boolean;
|
|
427
|
+
/**
|
|
428
|
+
* Header preference order for IP extraction
|
|
429
|
+
* YinzerFlow will check headers in this order and use the first valid one
|
|
430
|
+
* @default ['x-forwarded-for', 'x-real-ip', 'cf-connecting-ip', 'x-client-ip', 'true-client-ip']
|
|
431
|
+
*/
|
|
432
|
+
headerPreference: Array<string>;
|
|
433
|
+
/**
|
|
434
|
+
* Maximum allowed length of IP chain in forwarded headers
|
|
435
|
+
* Prevents DoS attacks through extremely long proxy chains
|
|
436
|
+
* @default 10
|
|
437
|
+
* @min 1
|
|
438
|
+
* @max 50
|
|
439
|
+
*/
|
|
440
|
+
maxChainLength: number;
|
|
441
|
+
/**
|
|
442
|
+
* Enable spoofing pattern detection
|
|
443
|
+
* Detects suspicious patterns like duplicate IPs, mixed valid/invalid IPs
|
|
444
|
+
* @default true
|
|
445
|
+
*/
|
|
446
|
+
detectSpoofing: boolean;
|
|
447
|
+
}
|
|
448
|
+
interface InternalServerConfiguration {
|
|
449
|
+
/**
|
|
450
|
+
* Port number for the server to listen on
|
|
451
|
+
* @default 5000
|
|
452
|
+
*/
|
|
453
|
+
port: number;
|
|
454
|
+
/**
|
|
455
|
+
* Host address to bind the server to
|
|
456
|
+
* @default '0.0.0.0'
|
|
457
|
+
*/
|
|
458
|
+
host: string;
|
|
459
|
+
/**
|
|
460
|
+
* Logging level for YinzerFlow server
|
|
461
|
+
* - 'off': No logging (silent mode)
|
|
462
|
+
* - 'verbose': Application logging with Pittsburgh personality (level 1)
|
|
463
|
+
* - 'network': Network logging + application logging (level 2)
|
|
464
|
+
* @default 'off'
|
|
465
|
+
*/
|
|
466
|
+
logLevel: CreateEnum<typeof logLevels>;
|
|
467
|
+
/**
|
|
468
|
+
* Cross-Origin Resource Sharing configuration
|
|
469
|
+
*/
|
|
470
|
+
cors: InternalCorsConfiguration;
|
|
471
|
+
/**
|
|
472
|
+
* Body parsing configuration with security limits
|
|
473
|
+
*/
|
|
474
|
+
bodyParser: InternalBodyParserConfiguration;
|
|
475
|
+
/**
|
|
476
|
+
* IP address security and validation configuration
|
|
477
|
+
*/
|
|
478
|
+
ipSecurity: InternalIpValidationConfig;
|
|
479
|
+
/**
|
|
480
|
+
* Server connection options
|
|
481
|
+
*/
|
|
482
|
+
connectionOptions: InternalConnectionOptions;
|
|
483
|
+
}
|
|
484
|
+
interface Setup {
|
|
485
|
+
get: InternalSetupMethod;
|
|
486
|
+
post: InternalSetupMethod;
|
|
487
|
+
put: InternalSetupMethod;
|
|
488
|
+
patch: InternalSetupMethod;
|
|
489
|
+
delete: InternalSetupMethod;
|
|
490
|
+
options: InternalSetupMethod;
|
|
491
|
+
group: (prefix: string, callback: (group: Record<Lowercase<InternalHttpMethod>, InternalSetupMethod>) => void, options?: InternalRouteRegistryOptions) => void;
|
|
492
|
+
beforeAll: (handlers: Array<HandlerCallback>, options?: InternalGlobalHookOptions) => void;
|
|
493
|
+
afterAll: (handlers: Array<HandlerCallback>, options?: InternalGlobalHookOptions) => void;
|
|
494
|
+
onError: (handler: HandlerCallback) => void;
|
|
495
|
+
onNotFound: (handler: HandlerCallback) => void;
|
|
496
|
+
}
|
|
497
|
+
type InternalSetupMethod = (path: string, handler: HandlerCallback, options?: InternalRouteRegistryOptions) => void;
|
|
498
|
+
interface InternalSetupImpl extends Setup {
|
|
499
|
+
readonly _configuration: InternalServerConfiguration;
|
|
500
|
+
readonly _routeRegistry: InternalRouteRegistryImpl;
|
|
501
|
+
readonly _hooks: InternalHookRegistryImpl;
|
|
502
|
+
}
|
|
503
|
+
declare class HookRegistryImpl implements InternalHookRegistryImpl {
|
|
504
|
+
readonly _beforeAll: Set<{
|
|
505
|
+
handler: HandlerCallback;
|
|
506
|
+
options?: InternalGlobalHookOptions;
|
|
507
|
+
}>;
|
|
508
|
+
readonly _afterAll: Set<{
|
|
509
|
+
handler: HandlerCallback;
|
|
510
|
+
options?: InternalGlobalHookOptions;
|
|
511
|
+
}>;
|
|
512
|
+
_onError: HandlerCallback;
|
|
513
|
+
_onNotFound: HandlerCallback;
|
|
514
|
+
constructor();
|
|
515
|
+
_addBeforeHooks(handlers: Array<HandlerCallback>, options?: InternalGlobalHookOptions): void;
|
|
516
|
+
_addAfterHooks(handlers: Array<HandlerCallback>, options?: InternalGlobalHookOptions): void;
|
|
517
|
+
_addOnError(handler: HandlerCallback): void;
|
|
518
|
+
_addOnNotFound(handler: HandlerCallback): void;
|
|
519
|
+
}
|
|
520
|
+
type ServerConfiguration = DeepPartial<InternalServerConfiguration>;
|
|
521
|
+
declare class RouteRegistryImpl implements InternalRouteRegistryImpl {
|
|
522
|
+
readonly _exactRoutes: Map<InternalHttpMethod, Map<string, InternalRouteRegistry>>;
|
|
523
|
+
readonly _parameterizedRoutes: Map<InternalHttpMethod, InternalPreCompiledRoute[]>;
|
|
524
|
+
_register({ method, path, handler, options }: InternalRouteRegistry): void;
|
|
525
|
+
_findRoute(method: InternalHttpMethod, path: string): InternalRouteRegistry | undefined;
|
|
526
|
+
private _hasExactRoutePattern;
|
|
527
|
+
private _storeExactRoute;
|
|
528
|
+
private _storeParameterizedRoute;
|
|
529
|
+
private _findParameterizedRoute;
|
|
530
|
+
}
|
|
531
|
+
declare class SetupImpl implements InternalSetupImpl {
|
|
532
|
+
readonly _configuration: InternalServerConfiguration;
|
|
533
|
+
readonly _routeRegistry: RouteRegistryImpl;
|
|
534
|
+
readonly _hooks: HookRegistryImpl;
|
|
535
|
+
constructor(customConfiguration?: ServerConfiguration);
|
|
536
|
+
get(path: string, handler: HandlerCallback, options?: InternalRouteRegistryOptions): void;
|
|
537
|
+
head(path: string, handler: HandlerCallback, options?: InternalRouteRegistryOptions): void;
|
|
538
|
+
post(path: string, handler: HandlerCallback, options?: InternalRouteRegistryOptions): void;
|
|
539
|
+
put(path: string, handler: HandlerCallback, options?: InternalRouteRegistryOptions): void;
|
|
540
|
+
patch(path: string, handler: HandlerCallback, options?: InternalRouteRegistryOptions): void;
|
|
541
|
+
delete(path: string, handler: HandlerCallback, options?: InternalRouteRegistryOptions): void;
|
|
542
|
+
options(path: string, handler: HandlerCallback, options?: InternalRouteRegistryOptions): void;
|
|
543
|
+
group(prefix: string, callback: (group: Record<Lowercase<InternalHttpMethod>, InternalSetupMethod>) => void, options?: InternalRouteRegistryOptions): void;
|
|
544
|
+
beforeAll(handlers: Array<HandlerCallback>, options?: InternalGlobalHookOptions): void;
|
|
545
|
+
afterAll(handlers: Array<HandlerCallback>, options?: InternalGlobalHookOptions): void;
|
|
546
|
+
onError(handler: HandlerCallback): void;
|
|
547
|
+
onNotFound(handler: HandlerCallback): void;
|
|
548
|
+
}
|
|
549
|
+
export declare class YinzerFlow extends SetupImpl {
|
|
550
|
+
private _isListening;
|
|
551
|
+
private _server?;
|
|
552
|
+
constructor(configuration?: ServerConfiguration);
|
|
553
|
+
private _setupServer;
|
|
554
|
+
private _processRequest;
|
|
555
|
+
private _handleConnection;
|
|
556
|
+
listen(): Promise<void>;
|
|
557
|
+
close(): Promise<void>;
|
|
558
|
+
status(): {
|
|
559
|
+
isListening: boolean;
|
|
560
|
+
port: number | undefined;
|
|
561
|
+
host: string | undefined;
|
|
562
|
+
};
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
export {};
|