@catbee/utils 0.0.8-rc.2 → 0.0.8-rc.4
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/build/index.cjs +6591 -0
- package/build/index.d.ts +5131 -0
- package/build/index.mjs +6321 -0
- package/package.json +12 -36
- package/build/esm/config.d.ts +0 -121
- package/build/esm/config.js +0 -132
- package/build/esm/index.d.ts +0 -26
- package/build/esm/index.js +0 -49
- package/build/esm/servers/server.builder.d.ts +0 -507
- package/build/esm/servers/server.builder.js +0 -654
- package/build/esm/servers/server.d.ts +0 -255
- package/build/esm/servers/server.js +0 -963
- package/build/esm/types/api-response.d.ts +0 -151
- package/build/esm/types/api-response.js +0 -33
- package/build/esm/types/index.d.ts +0 -124
- package/build/esm/types/index.js +0 -24
- package/build/esm/types/server.d.ts +0 -267
- package/build/esm/types/server.js +0 -24
- package/build/esm/utils/array.utils.d.ts +0 -167
- package/build/esm/utils/array.utils.js +0 -344
- package/build/esm/utils/async.utils.d.ts +0 -264
- package/build/esm/utils/async.utils.js +0 -619
- package/build/esm/utils/cache.utils.d.ts +0 -152
- package/build/esm/utils/cache.utils.js +0 -294
- package/build/esm/utils/context-store.utils.d.ts +0 -188
- package/build/esm/utils/context-store.utils.js +0 -290
- package/build/esm/utils/crypto.utils.d.ts +0 -159
- package/build/esm/utils/crypto.utils.js +0 -278
- package/build/esm/utils/date.utils.d.ts +0 -158
- package/build/esm/utils/date.utils.js +0 -383
- package/build/esm/utils/decorators.utils.d.ts +0 -511
- package/build/esm/utils/decorators.utils.js +0 -1013
- package/build/esm/utils/dir.utils.d.ts +0 -195
- package/build/esm/utils/dir.utils.js +0 -476
- package/build/esm/utils/env.utils.d.ts +0 -376
- package/build/esm/utils/env.utils.js +0 -782
- package/build/esm/utils/exception.utils.d.ts +0 -229
- package/build/esm/utils/exception.utils.js +0 -382
- package/build/esm/utils/fs.utils.d.ts +0 -163
- package/build/esm/utils/fs.utils.js +0 -348
- package/build/esm/utils/http-status-codes.d.ts +0 -265
- package/build/esm/utils/http-status-codes.js +0 -294
- package/build/esm/utils/id.utils.d.ts +0 -35
- package/build/esm/utils/id.utils.js +0 -83
- package/build/esm/utils/logger.utils.d.ts +0 -159
- package/build/esm/utils/logger.utils.js +0 -304
- package/build/esm/utils/middleware.utils.d.ts +0 -99
- package/build/esm/utils/middleware.utils.js +0 -235
- package/build/esm/utils/obj.utils.d.ts +0 -123
- package/build/esm/utils/obj.utils.js +0 -412
- package/build/esm/utils/performance.utils.d.ts +0 -135
- package/build/esm/utils/performance.utils.js +0 -273
- package/build/esm/utils/request.utils.d.ts +0 -85
- package/build/esm/utils/request.utils.js +0 -190
- package/build/esm/utils/response.utils.d.ts +0 -162
- package/build/esm/utils/response.utils.js +0 -261
- package/build/esm/utils/stream.utils.d.ts +0 -87
- package/build/esm/utils/stream.utils.js +0 -209
- package/build/esm/utils/string.utils.d.ts +0 -92
- package/build/esm/utils/string.utils.js +0 -164
- package/build/esm/utils/type.utils.d.ts +0 -89
- package/build/esm/utils/type.utils.js +0 -186
- package/build/esm/utils/url.utils.d.ts +0 -140
- package/build/esm/utils/url.utils.js +0 -303
- package/build/esm/utils/validate.utils.d.ts +0 -176
- package/build/esm/utils/validate.utils.js +0 -319
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Generic API response format.
|
|
3
|
-
* Used to wrap any successful or failed response from the server.
|
|
4
|
-
*/
|
|
5
|
-
export interface ApiResponse<T = any> {
|
|
6
|
-
/** Payload returned from the API. Can be any shape depending on the endpoint. */
|
|
7
|
-
data: T | null;
|
|
8
|
-
/** Indicates whether an error occurred (true = error, false = success). */
|
|
9
|
-
error: boolean;
|
|
10
|
-
/** Success message describing the result of the operation. */
|
|
11
|
-
message: string;
|
|
12
|
-
/** Unique request ID for traceability in logs (e.g., from a middleware). */
|
|
13
|
-
requestId: string;
|
|
14
|
-
/** ISO timestamp when the response was generated. */
|
|
15
|
-
timestamp: string;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Generic pagination structure used for paged lists (e.g., /users?page=1).
|
|
19
|
-
*/
|
|
20
|
-
export interface Pagination<T = any> {
|
|
21
|
-
/** List of records for the current page. */
|
|
22
|
-
content: T[];
|
|
23
|
-
/** Metadata about the pagination state. */
|
|
24
|
-
pagination: {
|
|
25
|
-
/** Total number of records across all pages. */
|
|
26
|
-
totalRecords: number;
|
|
27
|
-
/** Total number of pages available. */
|
|
28
|
-
totalPages: number;
|
|
29
|
-
/** Current page number (1-based index). */
|
|
30
|
-
page: number;
|
|
31
|
-
/** Number of records per page. */
|
|
32
|
-
limit: number;
|
|
33
|
-
/** Field by which the data is sorted. */
|
|
34
|
-
sortBy: string;
|
|
35
|
-
/** Sort order: ascending or descending. */
|
|
36
|
-
sortOrder: 'asc' | 'desc';
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Alias for paginated API response.
|
|
41
|
-
* Allows semantic naming like `PaginationResponse<User>` or `PaginationResponse<Post>`.
|
|
42
|
-
*/
|
|
43
|
-
export type PaginationResponse<T = any> = Pagination<T>;
|
|
44
|
-
/**
|
|
45
|
-
* Error response structure with additional metadata.
|
|
46
|
-
* Used for providing richer error information to clients.
|
|
47
|
-
*/
|
|
48
|
-
export interface ApiErrorResponse extends Omit<ApiResponse<never>, 'data'> {
|
|
49
|
-
/** Error always true for error responses */
|
|
50
|
-
error: true;
|
|
51
|
-
/** HTTP status code */
|
|
52
|
-
status: number;
|
|
53
|
-
/** Path to the resource that caused the error */
|
|
54
|
-
path: string;
|
|
55
|
-
/** Stack trace of the error (if available) */
|
|
56
|
-
stack?: string[];
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Success response structure with strongly typed data.
|
|
60
|
-
* Used for providing successful responses to clients.
|
|
61
|
-
*/
|
|
62
|
-
export interface ApiSuccessResponse<T = any> extends ApiResponse<T> {
|
|
63
|
-
/** Error always false for success responses */
|
|
64
|
-
error: false;
|
|
65
|
-
/** HTTP status code (usually 200) */
|
|
66
|
-
status?: number;
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Response structure for batch operations.
|
|
70
|
-
* Used when multiple operations are performed in a single request.
|
|
71
|
-
*/
|
|
72
|
-
export interface BatchResponse<T = any> {
|
|
73
|
-
/** Overall success/failure indicator */
|
|
74
|
-
success: boolean;
|
|
75
|
-
/** Total number of operations */
|
|
76
|
-
total: number;
|
|
77
|
-
/** Number of successful operations */
|
|
78
|
-
successful: number;
|
|
79
|
-
/** Number of failed operations */
|
|
80
|
-
failed: number;
|
|
81
|
-
/** Results of individual operations */
|
|
82
|
-
results: Array<{
|
|
83
|
-
/** Identifier for this operation */
|
|
84
|
-
id: string | number;
|
|
85
|
-
/** Success/failure indicator for this operation */
|
|
86
|
-
success: boolean;
|
|
87
|
-
/** Response data for this operation */
|
|
88
|
-
data?: T;
|
|
89
|
-
/** Error information if this operation failed */
|
|
90
|
-
error?: {
|
|
91
|
-
message: string;
|
|
92
|
-
code?: string;
|
|
93
|
-
};
|
|
94
|
-
}>;
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Response structure for asynchronous operations.
|
|
98
|
-
* Used when the operation will complete in the future.
|
|
99
|
-
*/
|
|
100
|
-
export interface AsyncOperationResponse {
|
|
101
|
-
/** Always true for async operations */
|
|
102
|
-
async: true;
|
|
103
|
-
/** Job or task ID to check status later */
|
|
104
|
-
jobId: string;
|
|
105
|
-
/** Estimated completion time in seconds (if known) */
|
|
106
|
-
estimatedTime?: number;
|
|
107
|
-
/** URL to check status */
|
|
108
|
-
statusUrl: string;
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Response structure for streaming operations.
|
|
112
|
-
* Used when data is returned as a stream rather than all at once.
|
|
113
|
-
*/
|
|
114
|
-
export interface StreamResponse {
|
|
115
|
-
/** Stream identifier */
|
|
116
|
-
streamId: string;
|
|
117
|
-
/** Stream type (e.g., 'json', 'binary') */
|
|
118
|
-
streamType: string;
|
|
119
|
-
/** Total size in bytes (if known) */
|
|
120
|
-
totalSize?: number;
|
|
121
|
-
/** Chunk size in bytes */
|
|
122
|
-
chunkSize: number;
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Sort direction enumeration.
|
|
126
|
-
*/
|
|
127
|
-
export declare enum SortDirection {
|
|
128
|
-
/** Ascending sort order */
|
|
129
|
-
ASC = "asc",
|
|
130
|
-
/** Descending sort order */
|
|
131
|
-
DESC = "desc"
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* Pagination parameters for API requests.
|
|
135
|
-
*/
|
|
136
|
-
export interface PaginationParams {
|
|
137
|
-
/** Current page number (1-based index) */
|
|
138
|
-
page: number;
|
|
139
|
-
/** Number of records per page */
|
|
140
|
-
limit: number;
|
|
141
|
-
/** Field by which the data is sorted */
|
|
142
|
-
sortBy: string;
|
|
143
|
-
/** Sort order: ascending or descending */
|
|
144
|
-
sortOrder: SortDirection;
|
|
145
|
-
/** Optional search query */
|
|
146
|
-
search?: string;
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* Type that combines pagination parameters with additional data.
|
|
150
|
-
*/
|
|
151
|
-
export type WithPagination<T = {}> = PaginationParams & T;
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* The MIT License
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) 2025 Catbee Technologies. https://catbee-utils.npm.hprasath.com/license
|
|
5
|
-
*
|
|
6
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
-
* in the Software without restriction, including without limitation the rights
|
|
9
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
-
* furnished to do so, subject to the following conditions:
|
|
12
|
-
*
|
|
13
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
-
* copies or substantial portions of the Software.
|
|
15
|
-
*
|
|
16
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
* SOFTWARE.
|
|
23
|
-
*/
|
|
24
|
-
/**
|
|
25
|
-
* Sort direction enumeration.
|
|
26
|
-
*/
|
|
27
|
-
export var SortDirection;
|
|
28
|
-
(function (SortDirection) {
|
|
29
|
-
/** Ascending sort order */
|
|
30
|
-
SortDirection["ASC"] = "asc";
|
|
31
|
-
/** Descending sort order */
|
|
32
|
-
SortDirection["DESC"] = "desc";
|
|
33
|
-
})(SortDirection || (SortDirection = {}));
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A type that represents a configurable toggle.
|
|
3
|
-
* Can be `true`, `false`, or a custom configuration object `T`.
|
|
4
|
-
*/
|
|
5
|
-
export type ToggleConfig<T> = boolean | T;
|
|
6
|
-
/**
|
|
7
|
-
* A type representing a value that can be `null` or `undefined`.
|
|
8
|
-
*/
|
|
9
|
-
export type Nullable<T> = T | null | undefined;
|
|
10
|
-
/**
|
|
11
|
-
* A type representing a value that may or may not be present.
|
|
12
|
-
*/
|
|
13
|
-
export type Optional<T> = T | undefined;
|
|
14
|
-
/**
|
|
15
|
-
* A type that makes all properties of `T` deeply optional.
|
|
16
|
-
*/
|
|
17
|
-
export type DeepPartial<T> = {
|
|
18
|
-
[P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
|
|
19
|
-
};
|
|
20
|
-
/**
|
|
21
|
-
* A type that makes all properties of `T` readonly, recursively.
|
|
22
|
-
*/
|
|
23
|
-
export type DeepReadonly<T> = {
|
|
24
|
-
readonly [P in keyof T]: T[P] extends object ? DeepReadonly<T[P]> : T[P];
|
|
25
|
-
};
|
|
26
|
-
/**
|
|
27
|
-
* A type that converts a union of types into an intersection.
|
|
28
|
-
*/
|
|
29
|
-
export type UnionToIntersection<U> = (U extends any ? (x: U) => void : never) extends (x: infer I) => void ? I : never;
|
|
30
|
-
/**
|
|
31
|
-
* A type representing a promise or a plain value.
|
|
32
|
-
*/
|
|
33
|
-
export type MaybePromise<T> = T | Promise<T>;
|
|
34
|
-
/**
|
|
35
|
-
* A type representing a record with string keys and values of type `T`.
|
|
36
|
-
*/
|
|
37
|
-
export type StringKeyedRecord<T> = Record<string, T>;
|
|
38
|
-
/**
|
|
39
|
-
* A type representing a function that returns `R` and optionally receives arguments `A`.
|
|
40
|
-
*/
|
|
41
|
-
export type Func<A extends any[] = any[], R = any> = (...args: A) => R;
|
|
42
|
-
/**
|
|
43
|
-
* A type representing a partial pick from `T` (like Partial + Pick combined)
|
|
44
|
-
*/
|
|
45
|
-
export type PartialPick<T, K extends keyof T> = Partial<Pick<T, K>> & Omit<T, K>;
|
|
46
|
-
/**
|
|
47
|
-
* A type that deeply stringifies all properties of T or makes them null.
|
|
48
|
-
*/
|
|
49
|
-
export type DeepStringifyOrNull<T> = T extends string | number | boolean | bigint | boolean | symbol | null | undefined | null ? string | null : T extends Array<infer U> ? Array<DeepStringifyOrNull<U>> : T extends object ? {
|
|
50
|
-
[K in keyof T]: DeepStringifyOrNull<T[K]>;
|
|
51
|
-
} : string | null;
|
|
52
|
-
/**
|
|
53
|
-
* A type representing a non-empty array of T.
|
|
54
|
-
*/
|
|
55
|
-
export type NonEmptyArray<T> = [T, ...T[]];
|
|
56
|
-
/**
|
|
57
|
-
* A type representing the union of all property values of T.
|
|
58
|
-
*/
|
|
59
|
-
export type ValueOf<T> = T[keyof T];
|
|
60
|
-
/**
|
|
61
|
-
* A type that makes all properties of T mutable (removes readonly).
|
|
62
|
-
*/
|
|
63
|
-
export type Mutable<T> = {
|
|
64
|
-
-readonly [P in keyof T]: T[P];
|
|
65
|
-
};
|
|
66
|
-
/**
|
|
67
|
-
* A type that gets the keys of T whose values are assignable to U.
|
|
68
|
-
*/
|
|
69
|
-
export type KeysOfType<T, U> = {
|
|
70
|
-
[K in keyof T]: T[K] extends U ? K : never;
|
|
71
|
-
}[keyof T];
|
|
72
|
-
/**
|
|
73
|
-
* Require at least one of the keys in K to be present in T.
|
|
74
|
-
*/
|
|
75
|
-
export type RequireAtLeastOne<T, K extends keyof T = keyof T> = K extends keyof T ? {
|
|
76
|
-
[P in K]-?: T[P];
|
|
77
|
-
} & Omit<T, K> : never;
|
|
78
|
-
/**
|
|
79
|
-
* A record type with optional keys.
|
|
80
|
-
*/
|
|
81
|
-
export type RecordOptional<K extends string | number | symbol, T> = {
|
|
82
|
-
[P in K]?: T;
|
|
83
|
-
};
|
|
84
|
-
/**
|
|
85
|
-
* Primitive types in TypeScript.
|
|
86
|
-
*/
|
|
87
|
-
export type Primitive = string | number | boolean | bigint | symbol | undefined | null;
|
|
88
|
-
/**
|
|
89
|
-
* Recursively unwraps Promise types to get their resolved value type.
|
|
90
|
-
*/
|
|
91
|
-
export type Awaited<T> = T extends Promise<infer U> ? Awaited<U> : T;
|
|
92
|
-
/**
|
|
93
|
-
* Picks properties from T that are of type U.
|
|
94
|
-
*/
|
|
95
|
-
export type PickByType<T, U> = {
|
|
96
|
-
[P in keyof T as T[P] extends U ? P : never]: T[P];
|
|
97
|
-
};
|
|
98
|
-
/**
|
|
99
|
-
* Makes all properties of T required recursively.
|
|
100
|
-
*/
|
|
101
|
-
export type DeepRequired<T> = {
|
|
102
|
-
[P in keyof T]-?: T[P] extends object ? DeepRequired<T[P]> : T[P];
|
|
103
|
-
};
|
|
104
|
-
/**
|
|
105
|
-
* Checks if two types are exactly equal.
|
|
106
|
-
* Returns true or false as type.
|
|
107
|
-
*/
|
|
108
|
-
export type IsEqual<T, U> = (<G>() => G extends T ? 1 : 2) extends <G>() => G extends U ? 1 : 2 ? true : false;
|
|
109
|
-
/**
|
|
110
|
-
* Makes all properties of an object writable (removes readonly).
|
|
111
|
-
*/
|
|
112
|
-
export type Writable<T> = {
|
|
113
|
-
-readonly [P in keyof T]: T[P];
|
|
114
|
-
};
|
|
115
|
-
/**
|
|
116
|
-
* Makes specific keys K of type T optional.
|
|
117
|
-
*/
|
|
118
|
-
export type Optional2<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
119
|
-
/**
|
|
120
|
-
* Creates a type with all properties of T except those with types assignable to U.
|
|
121
|
-
*/
|
|
122
|
-
export type Without<T, U> = {
|
|
123
|
-
[P in keyof T as T[P] extends U ? never : P]: T[P];
|
|
124
|
-
};
|
package/build/esm/types/index.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* The MIT License
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) 2025 Catbee Technologies. https://catbee-utils.npm.hprasath.com/license
|
|
5
|
-
*
|
|
6
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
-
* in the Software without restriction, including without limitation the rights
|
|
9
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
-
* furnished to do so, subject to the following conditions:
|
|
12
|
-
*
|
|
13
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
-
* copies or substantial portions of the Software.
|
|
15
|
-
*
|
|
16
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
* SOFTWARE.
|
|
23
|
-
*/
|
|
24
|
-
export {};
|
|
@@ -1,267 +0,0 @@
|
|
|
1
|
-
import { Express, json, NextFunction, urlencoded, Request, Response } from 'express';
|
|
2
|
-
import { ExpressServer } from '../servers/server';
|
|
3
|
-
import { HelmetOptions } from 'helmet';
|
|
4
|
-
import { CompressionOptions } from 'compression';
|
|
5
|
-
import { CookieParseOptions } from 'cookie-parser';
|
|
6
|
-
import http from 'http';
|
|
7
|
-
import { CorsOptions } from 'cors';
|
|
8
|
-
import { ToggleConfig } from '.';
|
|
9
|
-
/**
|
|
10
|
-
* Server configuration interface with smart defaults and full customization.
|
|
11
|
-
* All options are designed with security and performance best practices.
|
|
12
|
-
* Most options can be overridden via environment variables.
|
|
13
|
-
*/
|
|
14
|
-
export interface ServerConfig {
|
|
15
|
-
/** Port the server should listen on (default: 3000, env: PORT)
|
|
16
|
-
* - default: 3000
|
|
17
|
-
*/
|
|
18
|
-
port: number;
|
|
19
|
-
/** Optional host address for binding (default: '0.0.0.0', env: HOST)
|
|
20
|
-
* - default: '0.0.0.0'
|
|
21
|
-
*/
|
|
22
|
-
host?: string;
|
|
23
|
-
/** CORS configuration (default: false disables CORS, or provide options object)
|
|
24
|
-
* - default: false
|
|
25
|
-
*/
|
|
26
|
-
cors?: ToggleConfig<CorsOptions>;
|
|
27
|
-
/** Enable Helmet security headers (default: false disables Helmet, or provide options object)
|
|
28
|
-
* - default: false
|
|
29
|
-
*/
|
|
30
|
-
helmet?: ToggleConfig<HelmetOptions>;
|
|
31
|
-
/** Enable gzip/deflate compression (default: false disables compression, or provide options object)
|
|
32
|
-
* - default: false
|
|
33
|
-
*/
|
|
34
|
-
compression?: ToggleConfig<CompressionOptions>;
|
|
35
|
-
/** Request body parsing with size limits
|
|
36
|
-
* - json: { limit: '1mb' }
|
|
37
|
-
* - urlencoded: { extended: true, limit: '1mb' }
|
|
38
|
-
*/
|
|
39
|
-
bodyParser?: {
|
|
40
|
-
/** JSON parser (default: { limit: '1mb' }) */
|
|
41
|
-
json?: Parameters<typeof json>[0];
|
|
42
|
-
/** URL-encoded parser (default: { extended: true, limit: '1mb' }) */
|
|
43
|
-
urlencoded?: Parameters<typeof urlencoded>[0];
|
|
44
|
-
};
|
|
45
|
-
/** Enable cookie parsing with options (default: false)
|
|
46
|
-
* - default: false
|
|
47
|
-
*/
|
|
48
|
-
cookieParser?: ToggleConfig<CookieParseOptions>;
|
|
49
|
-
/** Trust proxy headers (default: false)
|
|
50
|
-
* - default: false
|
|
51
|
-
*/
|
|
52
|
-
trustProxy?: boolean;
|
|
53
|
-
/** Static file serving configuration for assets, uploads, etc.
|
|
54
|
-
* - path: file system path to serve
|
|
55
|
-
* - route: URL route prefix (default: "/")
|
|
56
|
-
* - maxAge: cache max age (default: 0)
|
|
57
|
-
* - etag: enable ETag headers (default: true)
|
|
58
|
-
* - immutable: enable immutable caching (default: false)
|
|
59
|
-
* - lastModified: enable last-modified caching (default: true)
|
|
60
|
-
* - cacheControl: enable Cache-Control headers (default: true)
|
|
61
|
-
*/
|
|
62
|
-
staticFolders?: Array<{
|
|
63
|
-
/** URL route prefix (default: "/") */
|
|
64
|
-
path?: string;
|
|
65
|
-
/** File system path to serve */
|
|
66
|
-
directory: string;
|
|
67
|
-
/** Cache-Control: max-age=<duration> (default: 0) */
|
|
68
|
-
maxAge?: string;
|
|
69
|
-
/** Enable ETag headers (default: true) */
|
|
70
|
-
etag?: boolean;
|
|
71
|
-
/** Enable immutable caching (default: false) */
|
|
72
|
-
immutable?: boolean;
|
|
73
|
-
/** Enable last-modified caching (default: true) */
|
|
74
|
-
lastModified?: boolean;
|
|
75
|
-
/** Enable Cache-Control headers (default: true) */
|
|
76
|
-
cacheControl?: boolean;
|
|
77
|
-
}>;
|
|
78
|
-
/** Enable microservice mode (default: false)
|
|
79
|
-
* - default: false
|
|
80
|
-
*/
|
|
81
|
-
isMicroservice?: boolean;
|
|
82
|
-
/** Service name for headers/metrics (default: 'express_app', env: APP_NAME)
|
|
83
|
-
* - default: 'express_app'
|
|
84
|
-
*/
|
|
85
|
-
appName?: string;
|
|
86
|
-
/** Global response headers (default: {})
|
|
87
|
-
* - default: {}
|
|
88
|
-
*/
|
|
89
|
-
globalHeaders?: Record<string, string | (() => string)>;
|
|
90
|
-
/** Rate limiting settings
|
|
91
|
-
* - enable: false
|
|
92
|
-
* - windowMs: 15 * 60 * 1000
|
|
93
|
-
* - max: 100
|
|
94
|
-
* - message: 'Too many requests'
|
|
95
|
-
* - standardHeaders: true
|
|
96
|
-
* - legacyHeaders: false
|
|
97
|
-
*/
|
|
98
|
-
rateLimit?: {
|
|
99
|
-
/** Enable rate limiting (default: false) */
|
|
100
|
-
enable: boolean;
|
|
101
|
-
/** Time window in ms (default: 900000 - 15 minutes) */
|
|
102
|
-
windowMs?: number;
|
|
103
|
-
/** Max requests per window (default: 100) */
|
|
104
|
-
max?: number;
|
|
105
|
-
/** Rate limit message (default: 'Too many requests') */
|
|
106
|
-
message?: string;
|
|
107
|
-
/** Add standard headers (default: true) */
|
|
108
|
-
standardHeaders?: boolean;
|
|
109
|
-
/** Add legacy headers (default: false) */
|
|
110
|
-
legacyHeaders?: boolean;
|
|
111
|
-
};
|
|
112
|
-
/** Request logging configuration
|
|
113
|
-
* - enable: true in dev, false in prod
|
|
114
|
-
* - ignorePaths: skips /healthz, /favicon.ico, /metrics, /docs, /.well-known
|
|
115
|
-
* - skipNotFoundRoutes: false
|
|
116
|
-
*/
|
|
117
|
-
requestLogging?: {
|
|
118
|
-
/** Enable request logging (default: true in dev, false in prod) */
|
|
119
|
-
enable: boolean;
|
|
120
|
-
/** Ignore paths function or string[] (default: skips /healthz, /favicon.ico, /metrics, /docs, /.well-known) */
|
|
121
|
-
ignorePaths?: string[] | ((req: Request, res: Response) => boolean);
|
|
122
|
-
/** Skip logging for not found routes (default: false) */
|
|
123
|
-
skipNotFoundRoutes?: boolean;
|
|
124
|
-
};
|
|
125
|
-
/** Health check settings
|
|
126
|
-
* - path: '/healthz'
|
|
127
|
-
* - detailed: true
|
|
128
|
-
* - withGlobalPrefix: false
|
|
129
|
-
*/
|
|
130
|
-
healthCheck?: {
|
|
131
|
-
/** Health check path (default: '/healthz') */
|
|
132
|
-
path?: string;
|
|
133
|
-
/** Custom checks (default: []) */
|
|
134
|
-
checks?: Array<{
|
|
135
|
-
name: string;
|
|
136
|
-
check: () => Promise<boolean> | boolean;
|
|
137
|
-
}>;
|
|
138
|
-
/** Show detailed checks status in response (default: true) */
|
|
139
|
-
detailed?: boolean;
|
|
140
|
-
/** Include in global prefix (default: false) */
|
|
141
|
-
withGlobalPrefix?: boolean;
|
|
142
|
-
};
|
|
143
|
-
/** Request timeout in ms (default: 30000 - 30 seconds)
|
|
144
|
-
* - default: 30000
|
|
145
|
-
*/
|
|
146
|
-
requestTimeout?: number;
|
|
147
|
-
/** Response timing configuration
|
|
148
|
-
* - enable: false
|
|
149
|
-
* - addHeader: true
|
|
150
|
-
* - logOnComplete: false
|
|
151
|
-
*/
|
|
152
|
-
responseTime?: {
|
|
153
|
-
/** Enable timing (default: false) */
|
|
154
|
-
enable: boolean;
|
|
155
|
-
/** Add X-Response-Time header (default: true) */
|
|
156
|
-
addHeader?: boolean;
|
|
157
|
-
/** Log completion time (default: false) */
|
|
158
|
-
logOnComplete?: boolean;
|
|
159
|
-
};
|
|
160
|
-
/** Request ID configuration
|
|
161
|
-
* - headerName: 'x-request-id'
|
|
162
|
-
* - exposeHeader: true
|
|
163
|
-
* - generator: uuid()
|
|
164
|
-
*/
|
|
165
|
-
requestId?: {
|
|
166
|
-
/** Header name (default: 'x-request-id') */
|
|
167
|
-
headerName?: string;
|
|
168
|
-
/** Add to response headers (default: true) */
|
|
169
|
-
exposeHeader?: boolean;
|
|
170
|
-
/** ID generator (default: uuid()) */
|
|
171
|
-
generator?: () => string;
|
|
172
|
-
};
|
|
173
|
-
/** Global route prefix (default: '/')
|
|
174
|
-
* - default: '/'
|
|
175
|
-
*/
|
|
176
|
-
globalPrefix?: string;
|
|
177
|
-
/** OpenAPI documentation
|
|
178
|
-
* - enable: false
|
|
179
|
-
* - mountPath: '/docs'
|
|
180
|
-
* - verbose: false
|
|
181
|
-
* - withGlobalPrefix: false
|
|
182
|
-
*/
|
|
183
|
-
openApi?: {
|
|
184
|
-
/** Enable docs (default: false) */
|
|
185
|
-
enable: boolean;
|
|
186
|
-
/** UI path (default: '/docs') */
|
|
187
|
-
mountPath?: string;
|
|
188
|
-
/** Spec file path (required if enabled) */
|
|
189
|
-
filePath?: string;
|
|
190
|
-
/** Enable verbose logs (default: false) */
|
|
191
|
-
verbose?: boolean;
|
|
192
|
-
/** Include in global prefix (default: false) */
|
|
193
|
-
withGlobalPrefix?: boolean;
|
|
194
|
-
};
|
|
195
|
-
/** Prometheus metrics
|
|
196
|
-
* - enable: false
|
|
197
|
-
* - path: '/metrics'
|
|
198
|
-
* - withGlobalPrefix: false
|
|
199
|
-
*/
|
|
200
|
-
metrics?: {
|
|
201
|
-
/** Enable metrics (default: false) */
|
|
202
|
-
enable: boolean;
|
|
203
|
-
/** Metrics path (default: '/metrics') */
|
|
204
|
-
path?: string;
|
|
205
|
-
/** Include in global prefix (default: false) */
|
|
206
|
-
withGlobalPrefix?: boolean;
|
|
207
|
-
};
|
|
208
|
-
/** Service version header
|
|
209
|
-
* - enable: false
|
|
210
|
-
* - headerName: 'x-service-version'
|
|
211
|
-
* - version: '0.0.0'
|
|
212
|
-
*/
|
|
213
|
-
serviceVersion?: {
|
|
214
|
-
/** Enable version header (default: false) */
|
|
215
|
-
enable: boolean;
|
|
216
|
-
/** Header name (default: 'x-service-version') */
|
|
217
|
-
headerName?: string;
|
|
218
|
-
/** Version value (default: '0.0.0') */
|
|
219
|
-
version?: string | (() => string);
|
|
220
|
-
};
|
|
221
|
-
/**
|
|
222
|
-
* HTTPS configuration (if provided, server will use HTTPS)
|
|
223
|
-
* Requires 'key' and 'cert' at minimum.
|
|
224
|
-
* @command - to generate self-signed certificates
|
|
225
|
-
* ```bash
|
|
226
|
-
* choco install mkcert
|
|
227
|
-
* mkcert -key-file localhost-key.pem -cert-file localhost-cert.pem localhost 127.0.0.1 ::1
|
|
228
|
-
* ```
|
|
229
|
-
*/
|
|
230
|
-
https?: {
|
|
231
|
-
/** Path to SSL private key file (PEM) */
|
|
232
|
-
key: string;
|
|
233
|
-
/** Path to SSL certificate file (PEM) */
|
|
234
|
-
cert: string;
|
|
235
|
-
/** Optional path to CA bundle file (PEM) */
|
|
236
|
-
ca?: string;
|
|
237
|
-
/** Optional passphrase for the private key */
|
|
238
|
-
passphrase?: string;
|
|
239
|
-
/** Any other https.ServerOptions */
|
|
240
|
-
[key: string]: any;
|
|
241
|
-
};
|
|
242
|
-
}
|
|
243
|
-
/**
|
|
244
|
-
* Server lifecycle hooks for custom behavior injection.
|
|
245
|
-
* Allows extending server functionality without modifying core code.
|
|
246
|
-
* All hooks can be async and support error handling.
|
|
247
|
-
*/
|
|
248
|
-
export interface ServerHooks {
|
|
249
|
-
/** Called before any middleware or routes are initialized - good for early setup */
|
|
250
|
-
beforeInit?: (server: ExpressServer) => Promise<void> | void;
|
|
251
|
-
/** Called after middleware and routes are set up - good for final configuration */
|
|
252
|
-
afterInit?: (server: ExpressServer) => Promise<void> | void;
|
|
253
|
-
/** Called just before the server starts listening - good for last-minute checks */
|
|
254
|
-
beforeStart?: (app: Express) => Promise<void> | void;
|
|
255
|
-
/** Called after the server starts successfully - good for announcing readiness */
|
|
256
|
-
afterStart?: (server: http.Server) => Promise<void> | void;
|
|
257
|
-
/** Called before graceful shutdown begins - good for cleanup preparation */
|
|
258
|
-
beforeStop?: (server: http.Server) => Promise<void> | void;
|
|
259
|
-
/** Called after server has stopped - good for final cleanup */
|
|
260
|
-
afterStop?: () => Promise<void> | void;
|
|
261
|
-
/** Custom global error handler - overrides the default error handling */
|
|
262
|
-
onError?: (error: Error, req: Request, res: Response, next: NextFunction) => void;
|
|
263
|
-
/** Called at the start of each request - good for request preprocessing */
|
|
264
|
-
onRequest?: (req: Request, res: Response, next: NextFunction) => void;
|
|
265
|
-
/** Called before response is sent - good for response modification */
|
|
266
|
-
onResponse?: (req: Request, res: Response, next: NextFunction) => void;
|
|
267
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* The MIT License
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) 2025 Catbee Technologies. https://catbee-utils.npm.hprasath.com/license
|
|
5
|
-
*
|
|
6
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
-
* in the Software without restriction, including without limitation the rights
|
|
9
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
-
* furnished to do so, subject to the following conditions:
|
|
12
|
-
*
|
|
13
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
-
* copies or substantial portions of the Software.
|
|
15
|
-
*
|
|
16
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
* SOFTWARE.
|
|
23
|
-
*/
|
|
24
|
-
export {};
|