@unireq/config 0.0.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Olivier Orabona
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,215 @@
1
+ /**
2
+ * @unireq/config - Centralized configuration for unireq
3
+ * Externalizes hardcoded defaults for security and maintainability
4
+ * Values can be overridden via environment variables (UNIREQ_* prefix)
5
+ */
6
+ /**
7
+ * HTTP configuration defaults
8
+ * Can be overridden with UNIREQ_HTTP_TIMEOUT environment variable
9
+ */
10
+ declare const HTTP_CONFIG: {
11
+ /** Default timeout for requests (ms) */
12
+ readonly DEFAULT_TIMEOUT: number;
13
+ /** Default redirect policy */
14
+ readonly REDIRECT: {
15
+ /** Allowed redirect status codes (307/308 only for safety) */
16
+ readonly ALLOWED_STATUS_CODES: readonly [307, 308];
17
+ /** Maximum number of redirects to follow */
18
+ readonly MAX_REDIRECTS: 5;
19
+ /** Follow 303 See Other redirects (opt-in) */
20
+ readonly FOLLOW_303: false;
21
+ };
22
+ /** Retry policy defaults */
23
+ readonly RETRY: {
24
+ /** Number of retry attempts */
25
+ readonly MAX_TRIES: 3;
26
+ /** Initial backoff delay (ms) */
27
+ readonly INITIAL_BACKOFF: 1000;
28
+ /** Maximum backoff delay (ms) */
29
+ readonly MAX_BACKOFF: 30000;
30
+ /** Enable jitter for backoff */
31
+ readonly JITTER: true;
32
+ /** HTTP methods eligible for retry */
33
+ readonly RETRY_METHODS: readonly ["GET", "PUT", "DELETE", "HEAD", "OPTIONS"];
34
+ /** Status codes that trigger retry */
35
+ readonly RETRY_STATUS_CODES: readonly [408, 429, 500, 502, 503, 504];
36
+ };
37
+ /** Rate limit handling */
38
+ readonly RATE_LIMIT: {
39
+ /** Automatically retry on rate limit (429/503) */
40
+ readonly AUTO_RETRY: true;
41
+ /** Maximum wait time for rate limit (ms) */
42
+ readonly MAX_WAIT: 60000;
43
+ };
44
+ };
45
+ /**
46
+ * Multipart upload security defaults
47
+ * Can be overridden with UNIREQ_MULTIPART_MAX_FILE_SIZE and UNIREQ_MULTIPART_SANITIZE_FILENAMES
48
+ */
49
+ declare const MULTIPART_CONFIG: {
50
+ /** Maximum file size (bytes) - 100 MB */
51
+ readonly MAX_FILE_SIZE: number;
52
+ /** Enable filename sanitization by default */
53
+ readonly SANITIZE_FILENAMES: boolean;
54
+ /** Common allowed MIME types by category */
55
+ readonly MIME_TYPES: {
56
+ readonly IMAGES: readonly ["image/jpeg", "image/png", "image/gif", "image/webp", "image/svg+xml"];
57
+ readonly DOCUMENTS: readonly ["application/pdf", "application/msword", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "application/vnd.ms-excel", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"];
58
+ readonly ARCHIVES: readonly ["application/zip", "application/x-tar", "application/gzip"];
59
+ };
60
+ /**
61
+ * Default secure whitelist for multipart uploads (OWASP A01:2021 - Broken Access Control)
62
+ * Includes common safe file types: images, documents, text, and binary data
63
+ * @security This whitelist prevents unrestricted file upload attacks
64
+ */
65
+ readonly DEFAULT_ALLOWED_MIME_TYPES: readonly ["image/jpeg", "image/png", "image/gif", "image/webp", "image/svg+xml", "application/pdf", "application/msword", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "application/vnd.ms-excel", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "application/vnd.ms-powerpoint", "application/vnd.openxmlformats-officedocument.presentationml.presentation", "text/plain", "text/csv", "text/html", "text/markdown", "application/json", "application/xml", "text/xml", "application/octet-stream"];
66
+ };
67
+ /**
68
+ * OAuth/JWT security defaults
69
+ * Can be overridden with UNIREQ_JWT_CLOCK_SKEW and UNIREQ_OAUTH_AUTO_REFRESH
70
+ */
71
+ declare const OAUTH_CONFIG: {
72
+ /** Clock skew tolerance for JWT expiration (seconds) */
73
+ readonly JWT_CLOCK_SKEW: number;
74
+ /** Automatically refresh tokens on 401 */
75
+ readonly AUTO_REFRESH: boolean;
76
+ };
77
+ /**
78
+ * Security configuration
79
+ */
80
+ declare const SECURITY_CONFIG: {
81
+ /** CRLF injection validation (always enabled, cannot be disabled) */
82
+ readonly CRLF_VALIDATION: {
83
+ readonly ENABLED: true;
84
+ /** Pattern to detect CRLF characters */
85
+ readonly PATTERN: RegExp;
86
+ };
87
+ /** Path traversal prevention patterns */
88
+ readonly PATH_TRAVERSAL: {
89
+ /** Patterns to sanitize in filenames */
90
+ readonly UNSAFE_PATTERNS: readonly [RegExp, RegExp, RegExp];
91
+ };
92
+ };
93
+ /**
94
+ * Content negotiation defaults
95
+ */
96
+ declare const CONTENT_CONFIG: {
97
+ /** Default Accept header for JSON APIs */
98
+ readonly JSON_ACCEPT: readonly ["application/json", "application/xml"];
99
+ /** Default content types */
100
+ readonly DEFAULT_CONTENT_TYPES: {
101
+ readonly JSON: "application/json";
102
+ readonly TEXT: "text/plain";
103
+ readonly FORM: "application/x-www-form-urlencoded";
104
+ readonly MULTIPART: "multipart/form-data";
105
+ };
106
+ };
107
+ /**
108
+ * Range request configuration
109
+ */
110
+ declare const RANGE_CONFIG: {
111
+ /** Default unit for range requests */
112
+ readonly DEFAULT_UNIT: "bytes";
113
+ /** Default chunk size for range requests (1 MB) */
114
+ readonly DEFAULT_CHUNK_SIZE: 1000000;
115
+ };
116
+ /**
117
+ * Complete configuration object
118
+ */
119
+ declare const CONFIG: {
120
+ readonly HTTP: {
121
+ /** Default timeout for requests (ms) */
122
+ readonly DEFAULT_TIMEOUT: number;
123
+ /** Default redirect policy */
124
+ readonly REDIRECT: {
125
+ /** Allowed redirect status codes (307/308 only for safety) */
126
+ readonly ALLOWED_STATUS_CODES: readonly [307, 308];
127
+ /** Maximum number of redirects to follow */
128
+ readonly MAX_REDIRECTS: 5;
129
+ /** Follow 303 See Other redirects (opt-in) */
130
+ readonly FOLLOW_303: false;
131
+ };
132
+ /** Retry policy defaults */
133
+ readonly RETRY: {
134
+ /** Number of retry attempts */
135
+ readonly MAX_TRIES: 3;
136
+ /** Initial backoff delay (ms) */
137
+ readonly INITIAL_BACKOFF: 1000;
138
+ /** Maximum backoff delay (ms) */
139
+ readonly MAX_BACKOFF: 30000;
140
+ /** Enable jitter for backoff */
141
+ readonly JITTER: true;
142
+ /** HTTP methods eligible for retry */
143
+ readonly RETRY_METHODS: readonly ["GET", "PUT", "DELETE", "HEAD", "OPTIONS"];
144
+ /** Status codes that trigger retry */
145
+ readonly RETRY_STATUS_CODES: readonly [408, 429, 500, 502, 503, 504];
146
+ };
147
+ /** Rate limit handling */
148
+ readonly RATE_LIMIT: {
149
+ /** Automatically retry on rate limit (429/503) */
150
+ readonly AUTO_RETRY: true;
151
+ /** Maximum wait time for rate limit (ms) */
152
+ readonly MAX_WAIT: 60000;
153
+ };
154
+ };
155
+ readonly MULTIPART: {
156
+ /** Maximum file size (bytes) - 100 MB */
157
+ readonly MAX_FILE_SIZE: number;
158
+ /** Enable filename sanitization by default */
159
+ readonly SANITIZE_FILENAMES: boolean;
160
+ /** Common allowed MIME types by category */
161
+ readonly MIME_TYPES: {
162
+ readonly IMAGES: readonly ["image/jpeg", "image/png", "image/gif", "image/webp", "image/svg+xml"];
163
+ readonly DOCUMENTS: readonly ["application/pdf", "application/msword", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "application/vnd.ms-excel", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"];
164
+ readonly ARCHIVES: readonly ["application/zip", "application/x-tar", "application/gzip"];
165
+ };
166
+ /**
167
+ * Default secure whitelist for multipart uploads (OWASP A01:2021 - Broken Access Control)
168
+ * Includes common safe file types: images, documents, text, and binary data
169
+ * @security This whitelist prevents unrestricted file upload attacks
170
+ */
171
+ readonly DEFAULT_ALLOWED_MIME_TYPES: readonly ["image/jpeg", "image/png", "image/gif", "image/webp", "image/svg+xml", "application/pdf", "application/msword", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "application/vnd.ms-excel", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "application/vnd.ms-powerpoint", "application/vnd.openxmlformats-officedocument.presentationml.presentation", "text/plain", "text/csv", "text/html", "text/markdown", "application/json", "application/xml", "text/xml", "application/octet-stream"];
172
+ };
173
+ readonly OAUTH: {
174
+ /** Clock skew tolerance for JWT expiration (seconds) */
175
+ readonly JWT_CLOCK_SKEW: number;
176
+ /** Automatically refresh tokens on 401 */
177
+ readonly AUTO_REFRESH: boolean;
178
+ };
179
+ readonly SECURITY: {
180
+ /** CRLF injection validation (always enabled, cannot be disabled) */
181
+ readonly CRLF_VALIDATION: {
182
+ readonly ENABLED: true;
183
+ /** Pattern to detect CRLF characters */
184
+ readonly PATTERN: RegExp;
185
+ };
186
+ /** Path traversal prevention patterns */
187
+ readonly PATH_TRAVERSAL: {
188
+ /** Patterns to sanitize in filenames */
189
+ readonly UNSAFE_PATTERNS: readonly [RegExp, RegExp, RegExp];
190
+ };
191
+ };
192
+ readonly CONTENT: {
193
+ /** Default Accept header for JSON APIs */
194
+ readonly JSON_ACCEPT: readonly ["application/json", "application/xml"];
195
+ /** Default content types */
196
+ readonly DEFAULT_CONTENT_TYPES: {
197
+ readonly JSON: "application/json";
198
+ readonly TEXT: "text/plain";
199
+ readonly FORM: "application/x-www-form-urlencoded";
200
+ readonly MULTIPART: "multipart/form-data";
201
+ };
202
+ };
203
+ readonly RANGE: {
204
+ /** Default unit for range requests */
205
+ readonly DEFAULT_UNIT: "bytes";
206
+ /** Default chunk size for range requests (1 MB) */
207
+ readonly DEFAULT_CHUNK_SIZE: 1000000;
208
+ };
209
+ };
210
+ /**
211
+ * Type-safe configuration access
212
+ */
213
+ type UnireqConfig = typeof CONFIG;
214
+
215
+ export { CONFIG, CONTENT_CONFIG, HTTP_CONFIG, MULTIPART_CONFIG, OAUTH_CONFIG, RANGE_CONFIG, SECURITY_CONFIG, type UnireqConfig, CONFIG as default };
package/dist/index.js ADDED
@@ -0,0 +1,159 @@
1
+ // src/index.ts
2
+ function getEnvNumber(key, fallback) {
3
+ const value = typeof process !== "undefined" && process.env ? process.env[key] : void 0;
4
+ const parsed = value ? Number.parseInt(value, 10) : Number.NaN;
5
+ return Number.isNaN(parsed) ? fallback : parsed;
6
+ }
7
+ function getEnvBoolean(key, fallback) {
8
+ const value = typeof process !== "undefined" && process.env ? process.env[key] : void 0;
9
+ if (value === void 0) return fallback;
10
+ return value.toLowerCase() === "true" || value === "1";
11
+ }
12
+ var HTTP_CONFIG = {
13
+ /** Default timeout for requests (ms) */
14
+ DEFAULT_TIMEOUT: getEnvNumber("UNIREQ_HTTP_TIMEOUT", 3e4),
15
+ /** Default redirect policy */
16
+ REDIRECT: {
17
+ /** Allowed redirect status codes (307/308 only for safety) */
18
+ ALLOWED_STATUS_CODES: [307, 308],
19
+ /** Maximum number of redirects to follow */
20
+ MAX_REDIRECTS: 5,
21
+ /** Follow 303 See Other redirects (opt-in) */
22
+ FOLLOW_303: false
23
+ },
24
+ /** Retry policy defaults */
25
+ RETRY: {
26
+ /** Number of retry attempts */
27
+ MAX_TRIES: 3,
28
+ /** Initial backoff delay (ms) */
29
+ INITIAL_BACKOFF: 1e3,
30
+ /** Maximum backoff delay (ms) */
31
+ MAX_BACKOFF: 3e4,
32
+ /** Enable jitter for backoff */
33
+ JITTER: true,
34
+ /** HTTP methods eligible for retry */
35
+ RETRY_METHODS: ["GET", "PUT", "DELETE", "HEAD", "OPTIONS"],
36
+ /** Status codes that trigger retry */
37
+ RETRY_STATUS_CODES: [408, 429, 500, 502, 503, 504]
38
+ },
39
+ /** Rate limit handling */
40
+ RATE_LIMIT: {
41
+ /** Automatically retry on rate limit (429/503) */
42
+ AUTO_RETRY: true,
43
+ /** Maximum wait time for rate limit (ms) */
44
+ MAX_WAIT: 6e4
45
+ }
46
+ };
47
+ var MULTIPART_CONFIG = {
48
+ /** Maximum file size (bytes) - 100 MB */
49
+ MAX_FILE_SIZE: getEnvNumber("UNIREQ_MULTIPART_MAX_FILE_SIZE", 1e8),
50
+ /** Enable filename sanitization by default */
51
+ SANITIZE_FILENAMES: getEnvBoolean("UNIREQ_MULTIPART_SANITIZE_FILENAMES", true),
52
+ /** Common allowed MIME types by category */
53
+ MIME_TYPES: {
54
+ IMAGES: ["image/jpeg", "image/png", "image/gif", "image/webp", "image/svg+xml"],
55
+ DOCUMENTS: [
56
+ "application/pdf",
57
+ "application/msword",
58
+ "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
59
+ "application/vnd.ms-excel",
60
+ "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
61
+ ],
62
+ ARCHIVES: ["application/zip", "application/x-tar", "application/gzip"]
63
+ },
64
+ /**
65
+ * Default secure whitelist for multipart uploads (OWASP A01:2021 - Broken Access Control)
66
+ * Includes common safe file types: images, documents, text, and binary data
67
+ * @security This whitelist prevents unrestricted file upload attacks
68
+ */
69
+ DEFAULT_ALLOWED_MIME_TYPES: [
70
+ // Images
71
+ "image/jpeg",
72
+ "image/png",
73
+ "image/gif",
74
+ "image/webp",
75
+ "image/svg+xml",
76
+ // Documents
77
+ "application/pdf",
78
+ "application/msword",
79
+ "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
80
+ "application/vnd.ms-excel",
81
+ "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
82
+ "application/vnd.ms-powerpoint",
83
+ "application/vnd.openxmlformats-officedocument.presentationml.presentation",
84
+ // Text
85
+ "text/plain",
86
+ "text/csv",
87
+ "text/html",
88
+ "text/markdown",
89
+ // JSON/XML
90
+ "application/json",
91
+ "application/xml",
92
+ "text/xml",
93
+ // Binary (safe generic types)
94
+ "application/octet-stream"
95
+ ]
96
+ };
97
+ var OAUTH_CONFIG = {
98
+ /** Clock skew tolerance for JWT expiration (seconds) */
99
+ JWT_CLOCK_SKEW: getEnvNumber("UNIREQ_JWT_CLOCK_SKEW", 60),
100
+ /** Automatically refresh tokens on 401 */
101
+ AUTO_REFRESH: getEnvBoolean("UNIREQ_OAUTH_AUTO_REFRESH", true)
102
+ };
103
+ var SECURITY_CONFIG = {
104
+ /** CRLF injection validation (always enabled, cannot be disabled) */
105
+ CRLF_VALIDATION: {
106
+ ENABLED: true,
107
+ /** Pattern to detect CRLF characters */
108
+ PATTERN: /[\r\n]/
109
+ },
110
+ /** Path traversal prevention patterns */
111
+ PATH_TRAVERSAL: {
112
+ /** Patterns to sanitize in filenames */
113
+ UNSAFE_PATTERNS: [
114
+ /[/\\]/g,
115
+ // Path separators
116
+ /\0/g,
117
+ // Null bytes
118
+ /\.\./g
119
+ // Directory traversal
120
+ ]
121
+ }
122
+ };
123
+ var CONTENT_CONFIG = {
124
+ /** Default Accept header for JSON APIs */
125
+ JSON_ACCEPT: ["application/json", "application/xml"],
126
+ /** Default content types */
127
+ DEFAULT_CONTENT_TYPES: {
128
+ JSON: "application/json",
129
+ TEXT: "text/plain",
130
+ FORM: "application/x-www-form-urlencoded",
131
+ MULTIPART: "multipart/form-data"
132
+ }
133
+ };
134
+ var RANGE_CONFIG = {
135
+ /** Default unit for range requests */
136
+ DEFAULT_UNIT: "bytes",
137
+ /** Default chunk size for range requests (1 MB) */
138
+ DEFAULT_CHUNK_SIZE: 1e6
139
+ };
140
+ var CONFIG = {
141
+ HTTP: HTTP_CONFIG,
142
+ MULTIPART: MULTIPART_CONFIG,
143
+ OAUTH: OAUTH_CONFIG,
144
+ SECURITY: SECURITY_CONFIG,
145
+ CONTENT: CONTENT_CONFIG,
146
+ RANGE: RANGE_CONFIG
147
+ };
148
+ var index_default = CONFIG;
149
+ export {
150
+ CONFIG,
151
+ CONTENT_CONFIG,
152
+ HTTP_CONFIG,
153
+ MULTIPART_CONFIG,
154
+ OAUTH_CONFIG,
155
+ RANGE_CONFIG,
156
+ SECURITY_CONFIG,
157
+ index_default as default
158
+ };
159
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * @unireq/config - Centralized configuration for unireq\n * Externalizes hardcoded defaults for security and maintainability\n * Values can be overridden via environment variables (UNIREQ_* prefix)\n */\n\n/**\n * Gets environment variable as number with fallback\n */\nfunction getEnvNumber(key: string, fallback: number): number {\n const value = typeof process !== 'undefined' && process.env ? process.env[key] : undefined;\n const parsed = value ? Number.parseInt(value, 10) : Number.NaN;\n return Number.isNaN(parsed) ? fallback : parsed;\n}\n\n/**\n * Gets environment variable as boolean with fallback\n */\nfunction getEnvBoolean(key: string, fallback: boolean): boolean {\n const value = typeof process !== 'undefined' && process.env ? process.env[key] : undefined;\n if (value === undefined) return fallback;\n return value.toLowerCase() === 'true' || value === '1';\n}\n\n/**\n * HTTP configuration defaults\n * Can be overridden with UNIREQ_HTTP_TIMEOUT environment variable\n */\nexport const HTTP_CONFIG = {\n /** Default timeout for requests (ms) */\n DEFAULT_TIMEOUT: getEnvNumber('UNIREQ_HTTP_TIMEOUT', 30000),\n\n /** Default redirect policy */\n REDIRECT: {\n /** Allowed redirect status codes (307/308 only for safety) */\n ALLOWED_STATUS_CODES: [307, 308] as const,\n /** Maximum number of redirects to follow */\n MAX_REDIRECTS: 5,\n /** Follow 303 See Other redirects (opt-in) */\n FOLLOW_303: false,\n },\n\n /** Retry policy defaults */\n RETRY: {\n /** Number of retry attempts */\n MAX_TRIES: 3,\n /** Initial backoff delay (ms) */\n INITIAL_BACKOFF: 1000,\n /** Maximum backoff delay (ms) */\n MAX_BACKOFF: 30000,\n /** Enable jitter for backoff */\n JITTER: true,\n /** HTTP methods eligible for retry */\n RETRY_METHODS: ['GET', 'PUT', 'DELETE', 'HEAD', 'OPTIONS'] as const,\n /** Status codes that trigger retry */\n RETRY_STATUS_CODES: [408, 429, 500, 502, 503, 504] as const,\n },\n\n /** Rate limit handling */\n RATE_LIMIT: {\n /** Automatically retry on rate limit (429/503) */\n AUTO_RETRY: true,\n /** Maximum wait time for rate limit (ms) */\n MAX_WAIT: 60000,\n },\n} as const;\n\n/**\n * Multipart upload security defaults\n * Can be overridden with UNIREQ_MULTIPART_MAX_FILE_SIZE and UNIREQ_MULTIPART_SANITIZE_FILENAMES\n */\nexport const MULTIPART_CONFIG = {\n /** Maximum file size (bytes) - 100 MB */\n MAX_FILE_SIZE: getEnvNumber('UNIREQ_MULTIPART_MAX_FILE_SIZE', 100_000_000),\n\n /** Enable filename sanitization by default */\n SANITIZE_FILENAMES: getEnvBoolean('UNIREQ_MULTIPART_SANITIZE_FILENAMES', true),\n\n /** Common allowed MIME types by category */\n MIME_TYPES: {\n IMAGES: ['image/jpeg', 'image/png', 'image/gif', 'image/webp', 'image/svg+xml'] as const,\n DOCUMENTS: [\n 'application/pdf',\n 'application/msword',\n 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',\n 'application/vnd.ms-excel',\n 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',\n ] as const,\n ARCHIVES: ['application/zip', 'application/x-tar', 'application/gzip'] as const,\n },\n\n /**\n * Default secure whitelist for multipart uploads (OWASP A01:2021 - Broken Access Control)\n * Includes common safe file types: images, documents, text, and binary data\n * @security This whitelist prevents unrestricted file upload attacks\n */\n DEFAULT_ALLOWED_MIME_TYPES: [\n // Images\n 'image/jpeg',\n 'image/png',\n 'image/gif',\n 'image/webp',\n 'image/svg+xml',\n // Documents\n 'application/pdf',\n 'application/msword',\n 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',\n 'application/vnd.ms-excel',\n 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',\n 'application/vnd.ms-powerpoint',\n 'application/vnd.openxmlformats-officedocument.presentationml.presentation',\n // Text\n 'text/plain',\n 'text/csv',\n 'text/html',\n 'text/markdown',\n // JSON/XML\n 'application/json',\n 'application/xml',\n 'text/xml',\n // Binary (safe generic types)\n 'application/octet-stream',\n ] as const,\n} as const;\n\n/**\n * OAuth/JWT security defaults\n * Can be overridden with UNIREQ_JWT_CLOCK_SKEW and UNIREQ_OAUTH_AUTO_REFRESH\n */\nexport const OAUTH_CONFIG = {\n /** Clock skew tolerance for JWT expiration (seconds) */\n JWT_CLOCK_SKEW: getEnvNumber('UNIREQ_JWT_CLOCK_SKEW', 60),\n\n /** Automatically refresh tokens on 401 */\n AUTO_REFRESH: getEnvBoolean('UNIREQ_OAUTH_AUTO_REFRESH', true),\n} as const;\n\n/**\n * Security configuration\n */\nexport const SECURITY_CONFIG = {\n /** CRLF injection validation (always enabled, cannot be disabled) */\n CRLF_VALIDATION: {\n ENABLED: true,\n /** Pattern to detect CRLF characters */\n PATTERN: /[\\r\\n]/,\n } as const,\n\n /** Path traversal prevention patterns */\n PATH_TRAVERSAL: {\n /** Patterns to sanitize in filenames */\n UNSAFE_PATTERNS: [\n /[/\\\\]/g, // Path separators\n /\\0/g, // Null bytes\n /\\.\\./g, // Directory traversal\n ] as const,\n } as const,\n} as const;\n\n/**\n * Content negotiation defaults\n */\nexport const CONTENT_CONFIG = {\n /** Default Accept header for JSON APIs */\n JSON_ACCEPT: ['application/json', 'application/xml'] as const,\n\n /** Default content types */\n DEFAULT_CONTENT_TYPES: {\n JSON: 'application/json',\n TEXT: 'text/plain',\n FORM: 'application/x-www-form-urlencoded',\n MULTIPART: 'multipart/form-data',\n } as const,\n} as const;\n\n/**\n * Range request configuration\n */\nexport const RANGE_CONFIG = {\n /** Default unit for range requests */\n DEFAULT_UNIT: 'bytes' as const,\n\n /** Default chunk size for range requests (1 MB) */\n DEFAULT_CHUNK_SIZE: 1_000_000,\n} as const;\n\n/**\n * Complete configuration object\n */\nexport const CONFIG = {\n HTTP: HTTP_CONFIG,\n MULTIPART: MULTIPART_CONFIG,\n OAUTH: OAUTH_CONFIG,\n SECURITY: SECURITY_CONFIG,\n CONTENT: CONTENT_CONFIG,\n RANGE: RANGE_CONFIG,\n} as const;\n\n/**\n * Type-safe configuration access\n */\nexport type UnireqConfig = typeof CONFIG;\n\n/**\n * Export individual configs for tree-shaking\n */\nexport default CONFIG;\n"],"mappings":"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","names":[]}
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@unireq/config",
3
+ "version": "0.0.1",
4
+ "description": "Configuration module for unireq - externalizes defaults and security settings",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "keywords": [
19
+ "config",
20
+ "defaults",
21
+ "security"
22
+ ],
23
+ "author": "Olivier Orabona",
24
+ "license": "MIT",
25
+ "devDependencies": {
26
+ "typescript": "^5.9.3",
27
+ "tsup": "^8.5.1",
28
+ "vitest": "^4.0.16"
29
+ },
30
+ "engines": {
31
+ "node": ">=18.0.0"
32
+ },
33
+ "repository": {
34
+ "type": "git",
35
+ "url": "https://github.com/oorabona/unireq",
36
+ "directory": "packages/config"
37
+ },
38
+ "bugs": {
39
+ "url": "https://github.com/oorabona/unireq/issues"
40
+ },
41
+ "homepage": "https://github.com/oorabona/unireq/tree/main/packages/config",
42
+ "scripts": {
43
+ "build": "tsup",
44
+ "type-check": "tsc --noEmit",
45
+ "test": "vitest run",
46
+ "test:watch": "vitest",
47
+ "clean": "rm -rf dist *.tsbuildinfo"
48
+ }
49
+ }