@arcis/node 1.0.0 → 1.1.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.
@@ -1,129 +0,0 @@
1
- import { RequestHandler } from 'express';
2
- import { n as ValidationSchema } from './types-BOdL3ZWo.js';
3
-
4
- /**
5
- * @module @arcis/node/validation/schema
6
- * Request validation middleware
7
- */
8
-
9
- /**
10
- * Create Express middleware for request validation.
11
- * Prevents mass assignment by only allowing fields defined in the schema.
12
- *
13
- * @param schema - Validation schema defining expected fields
14
- * @param source - Request property to validate ('body', 'query', or 'params')
15
- * @returns Express middleware
16
- *
17
- * @example
18
- * app.post('/users', validate({
19
- * email: { type: 'email', required: true },
20
- * name: { type: 'string', min: 2, max: 50 },
21
- * age: { type: 'number', min: 0, max: 150 },
22
- * role: { type: 'string', enum: ['user', 'admin'] }
23
- * }), handler);
24
- *
25
- * @example
26
- * // Validate query params
27
- * app.get('/search', validate({
28
- * q: { type: 'string', required: true, min: 1 },
29
- * page: { type: 'number', min: 1 }
30
- * }, 'query'), handler);
31
- */
32
- declare function validate(schema: ValidationSchema, source?: 'body' | 'query' | 'params'): RequestHandler;
33
- /**
34
- * Alias for validate
35
- * @see validate
36
- */
37
- declare const createValidator: typeof validate;
38
-
39
- /**
40
- * @module @arcis/node/validation/file
41
- * File upload validation and filename sanitization
42
- */
43
- /** File upload validation options */
44
- interface ValidateFileOptions {
45
- /** Maximum file size in bytes. Default: 5MB */
46
- maxSize?: number;
47
- /** Allowed MIME types (e.g., ['image/jpeg', 'image/png']) */
48
- allowedTypes?: string[];
49
- /** Allowed file extensions (e.g., ['.jpg', '.png']). Includes dot. */
50
- allowedExtensions?: string[];
51
- /** Block dangerous/executable extensions. Default: true */
52
- blockExecutables?: boolean;
53
- /** Validate magic bytes match the claimed MIME type. Default: true */
54
- validateMagicBytes?: boolean;
55
- /** Block files with no extension. Default: true */
56
- blockNoExtension?: boolean;
57
- /** Block double extensions (e.g., file.php.jpg). Default: true */
58
- blockDoubleExtensions?: boolean;
59
- }
60
- /** File metadata for validation */
61
- interface FileInput {
62
- /** Original filename */
63
- filename: string;
64
- /** MIME type (as claimed by client) */
65
- mimetype: string;
66
- /** File size in bytes */
67
- size: number;
68
- /** File content buffer (for magic byte validation) */
69
- buffer?: Buffer;
70
- }
71
- /** File validation result */
72
- interface ValidateFileResult {
73
- /** Whether the file passed validation */
74
- valid: boolean;
75
- /** Validation errors (empty if valid) */
76
- errors: string[];
77
- /** Sanitized filename (safe for storage) */
78
- sanitizedFilename: string;
79
- }
80
- /**
81
- * Sanitize a filename for safe storage.
82
- *
83
- * Strips path traversal, null bytes, control characters, and special characters.
84
- * Preserves the extension and converts to a filesystem-safe name.
85
- *
86
- * @param filename - The original filename
87
- * @returns A sanitized filename safe for storage
88
- *
89
- * @example
90
- * sanitizeFilename('../../etc/passwd') // 'etc_passwd'
91
- * sanitizeFilename('file<name>.jpg') // 'filename.jpg'
92
- * sanitizeFilename('photo (1).jpg') // 'photo_1.jpg'
93
- * sanitizeFilename('.htaccess') // 'htaccess'
94
- */
95
- declare function sanitizeFilename(filename: string): string;
96
- /**
97
- * Validate a file upload for security.
98
- *
99
- * Checks file size, MIME type, extension, magic bytes, and dangerous patterns.
100
- * Returns a result with validation errors and a sanitized filename.
101
- *
102
- * @param file - File metadata and optional content
103
- * @param options - Validation options
104
- * @returns Validation result
105
- *
106
- * @example
107
- * const result = validateFile(
108
- * { filename: 'photo.jpg', mimetype: 'image/jpeg', size: 1024, buffer },
109
- * { allowedTypes: ['image/jpeg', 'image/png'], maxSize: 2 * 1024 * 1024 }
110
- * );
111
- * if (!result.valid) {
112
- * return res.status(400).json({ errors: result.errors });
113
- * }
114
- * // Use result.sanitizedFilename for storage
115
- *
116
- * @example
117
- * // Block executables only (no whitelist)
118
- * const result = validateFile(file, { blockExecutables: true });
119
- */
120
- declare function validateFile(file: FileInput, options?: ValidateFileOptions): ValidateFileResult;
121
- /**
122
- * Check if a file extension is considered dangerous/executable.
123
- *
124
- * @param filename - Filename or extension to check
125
- * @returns true if the extension is dangerous
126
- */
127
- declare function isDangerousExtension(filename: string): boolean;
128
-
129
- export { type FileInput as F, type ValidateFileOptions as V, type ValidateFileResult as a, validateFile as b, createValidator as c, isDangerousExtension as i, sanitizeFilename as s, validate as v };
@@ -1,129 +0,0 @@
1
- import { RequestHandler } from 'express';
2
- import { n as ValidationSchema } from './types-BOdL3ZWo.mjs';
3
-
4
- /**
5
- * @module @arcis/node/validation/schema
6
- * Request validation middleware
7
- */
8
-
9
- /**
10
- * Create Express middleware for request validation.
11
- * Prevents mass assignment by only allowing fields defined in the schema.
12
- *
13
- * @param schema - Validation schema defining expected fields
14
- * @param source - Request property to validate ('body', 'query', or 'params')
15
- * @returns Express middleware
16
- *
17
- * @example
18
- * app.post('/users', validate({
19
- * email: { type: 'email', required: true },
20
- * name: { type: 'string', min: 2, max: 50 },
21
- * age: { type: 'number', min: 0, max: 150 },
22
- * role: { type: 'string', enum: ['user', 'admin'] }
23
- * }), handler);
24
- *
25
- * @example
26
- * // Validate query params
27
- * app.get('/search', validate({
28
- * q: { type: 'string', required: true, min: 1 },
29
- * page: { type: 'number', min: 1 }
30
- * }, 'query'), handler);
31
- */
32
- declare function validate(schema: ValidationSchema, source?: 'body' | 'query' | 'params'): RequestHandler;
33
- /**
34
- * Alias for validate
35
- * @see validate
36
- */
37
- declare const createValidator: typeof validate;
38
-
39
- /**
40
- * @module @arcis/node/validation/file
41
- * File upload validation and filename sanitization
42
- */
43
- /** File upload validation options */
44
- interface ValidateFileOptions {
45
- /** Maximum file size in bytes. Default: 5MB */
46
- maxSize?: number;
47
- /** Allowed MIME types (e.g., ['image/jpeg', 'image/png']) */
48
- allowedTypes?: string[];
49
- /** Allowed file extensions (e.g., ['.jpg', '.png']). Includes dot. */
50
- allowedExtensions?: string[];
51
- /** Block dangerous/executable extensions. Default: true */
52
- blockExecutables?: boolean;
53
- /** Validate magic bytes match the claimed MIME type. Default: true */
54
- validateMagicBytes?: boolean;
55
- /** Block files with no extension. Default: true */
56
- blockNoExtension?: boolean;
57
- /** Block double extensions (e.g., file.php.jpg). Default: true */
58
- blockDoubleExtensions?: boolean;
59
- }
60
- /** File metadata for validation */
61
- interface FileInput {
62
- /** Original filename */
63
- filename: string;
64
- /** MIME type (as claimed by client) */
65
- mimetype: string;
66
- /** File size in bytes */
67
- size: number;
68
- /** File content buffer (for magic byte validation) */
69
- buffer?: Buffer;
70
- }
71
- /** File validation result */
72
- interface ValidateFileResult {
73
- /** Whether the file passed validation */
74
- valid: boolean;
75
- /** Validation errors (empty if valid) */
76
- errors: string[];
77
- /** Sanitized filename (safe for storage) */
78
- sanitizedFilename: string;
79
- }
80
- /**
81
- * Sanitize a filename for safe storage.
82
- *
83
- * Strips path traversal, null bytes, control characters, and special characters.
84
- * Preserves the extension and converts to a filesystem-safe name.
85
- *
86
- * @param filename - The original filename
87
- * @returns A sanitized filename safe for storage
88
- *
89
- * @example
90
- * sanitizeFilename('../../etc/passwd') // 'etc_passwd'
91
- * sanitizeFilename('file<name>.jpg') // 'filename.jpg'
92
- * sanitizeFilename('photo (1).jpg') // 'photo_1.jpg'
93
- * sanitizeFilename('.htaccess') // 'htaccess'
94
- */
95
- declare function sanitizeFilename(filename: string): string;
96
- /**
97
- * Validate a file upload for security.
98
- *
99
- * Checks file size, MIME type, extension, magic bytes, and dangerous patterns.
100
- * Returns a result with validation errors and a sanitized filename.
101
- *
102
- * @param file - File metadata and optional content
103
- * @param options - Validation options
104
- * @returns Validation result
105
- *
106
- * @example
107
- * const result = validateFile(
108
- * { filename: 'photo.jpg', mimetype: 'image/jpeg', size: 1024, buffer },
109
- * { allowedTypes: ['image/jpeg', 'image/png'], maxSize: 2 * 1024 * 1024 }
110
- * );
111
- * if (!result.valid) {
112
- * return res.status(400).json({ errors: result.errors });
113
- * }
114
- * // Use result.sanitizedFilename for storage
115
- *
116
- * @example
117
- * // Block executables only (no whitelist)
118
- * const result = validateFile(file, { blockExecutables: true });
119
- */
120
- declare function validateFile(file: FileInput, options?: ValidateFileOptions): ValidateFileResult;
121
- /**
122
- * Check if a file extension is considered dangerous/executable.
123
- *
124
- * @param filename - Filename or extension to check
125
- * @returns true if the extension is dangerous
126
- */
127
- declare function isDangerousExtension(filename: string): boolean;
128
-
129
- export { type FileInput as F, type ValidateFileOptions as V, type ValidateFileResult as a, validateFile as b, createValidator as c, isDangerousExtension as i, sanitizeFilename as s, validate as v };