@oxog/vld 2.1.0 → 2.2.5
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/CHANGELOG.md +87 -0
- package/README.md +1296 -1235
- package/dist/chunks/errors-core-Cqi4-9ew.js +1 -0
- package/dist/chunks/index-CkbfQQ4n.js +1 -0
- package/dist/chunks/index-yjpbvFgw.js +1 -0
- package/dist/chunks/ip-validation-g5LWgy9t.js +1 -0
- package/dist/chunks/security-Dy24T8N7.js +1 -0
- package/dist/cjs/chunks/errors-core-DKPohm9I.cjs +1 -0
- package/dist/cjs/chunks/index-BEV9nG0N.cjs +1 -0
- package/dist/cjs/chunks/index-ZjHAxYdA.cjs +1 -0
- package/dist/cjs/chunks/ip-validation-BZqPamPC.cjs +1 -0
- package/dist/cjs/chunks/security-aXZVI7qW.cjs +1 -0
- package/dist/cjs/cli/bin.cjs +1 -505
- package/dist/cjs/cli/index.cjs +1 -209
- package/dist/cjs/codecs/index.cjs +1 -45
- package/dist/cjs/coercion/index.cjs +1 -588
- package/dist/cjs/compat/emitter.cjs +1 -184
- package/dist/cjs/compat/result.cjs +1 -189
- package/dist/cjs/errors.cjs +1 -180
- package/dist/cjs/index.cjs +1 -1894
- package/dist/cjs/kernel.cjs +1 -415
- package/dist/cjs/locales/af.cjs +1 -108
- package/dist/cjs/locales/ar.cjs +1 -108
- package/dist/cjs/locales/bn.cjs +1 -108
- package/dist/cjs/locales/da.cjs +1 -108
- package/dist/cjs/locales/de.cjs +1 -108
- package/dist/cjs/locales/en.cjs +1 -108
- package/dist/cjs/locales/es-MX.cjs +1 -107
- package/dist/cjs/locales/es.cjs +1 -96
- package/dist/cjs/locales/fi.cjs +1 -108
- package/dist/cjs/locales/fr.cjs +1 -96
- package/dist/cjs/locales/hi.cjs +1 -108
- package/dist/cjs/locales/id.cjs +1 -108
- package/dist/cjs/locales/index.cjs +1 -43
- package/dist/cjs/locales/it.cjs +1 -108
- package/dist/cjs/locales/ja.cjs +1 -108
- package/dist/cjs/locales/ko.cjs +1 -108
- package/dist/cjs/locales/lazy.cjs +1 -188
- package/dist/cjs/locales/nl.cjs +1 -108
- package/dist/cjs/locales/no.cjs +1 -108
- package/dist/cjs/locales/pl.cjs +1 -108
- package/dist/cjs/locales/pt-BR.cjs +1 -108
- package/dist/cjs/locales/pt.cjs +1 -108
- package/dist/cjs/locales/ru.cjs +1 -108
- package/dist/cjs/locales/runtime.cjs +1 -51
- package/dist/cjs/locales/sv.cjs +1 -108
- package/dist/cjs/locales/sw.cjs +1 -108
- package/dist/cjs/locales/th.cjs +1 -108
- package/dist/cjs/locales/tr.cjs +1 -108
- package/dist/cjs/locales/vi.cjs +1 -108
- package/dist/cjs/locales/zh.cjs +1 -108
- package/dist/cjs/mini.cjs +1 -242
- package/dist/cjs/pigment.cjs +1 -207
- package/dist/cjs/plugins/index.cjs +1 -12
- package/dist/cjs/registry.cjs +1 -37
- package/dist/cjs/v3/index.cjs +1 -425
- package/dist/cjs/v4/core/index.cjs +1 -894
- package/dist/cjs/v4/index.cjs +1 -425
- package/dist/cjs/v4/locales/index.cjs +1 -130
- package/dist/cjs/v4/mini/index.cjs +1 -509
- package/dist/cjs/v4-mini/index.cjs +1 -532
- package/dist/cjs/validators/any.cjs +1 -40
- package/dist/cjs/validators/array.cjs +1 -283
- package/dist/cjs/validators/base.cjs +1 -887
- package/dist/cjs/validators/base64.cjs +1 -73
- package/dist/cjs/validators/bigint.cjs +1 -232
- package/dist/cjs/validators/boolean.cjs +1 -146
- package/dist/cjs/validators/codec.cjs +1 -205
- package/dist/cjs/validators/custom.cjs +1 -71
- package/dist/cjs/validators/date.cjs +1 -278
- package/dist/cjs/validators/discriminated-union.cjs +1 -130
- package/dist/cjs/validators/enum.cjs +1 -154
- package/dist/cjs/validators/file.cjs +1 -130
- package/dist/cjs/validators/function.cjs +1 -63
- package/dist/cjs/validators/hex.cjs +1 -70
- package/dist/cjs/validators/index.cjs +1 -123
- package/dist/cjs/validators/intersection.cjs +1 -120
- package/dist/cjs/validators/json.cjs +1 -70
- package/dist/cjs/validators/lazy.cjs +1 -53
- package/dist/cjs/validators/literal.cjs +1 -64
- package/dist/cjs/validators/map.cjs +1 -218
- package/dist/cjs/validators/nan.cjs +1 -41
- package/dist/cjs/validators/never.cjs +1 -36
- package/dist/cjs/validators/null.cjs +1 -43
- package/dist/cjs/validators/number.cjs +1 -427
- package/dist/cjs/validators/object.cjs +1 -868
- package/dist/cjs/validators/promise.cjs +1 -115
- package/dist/cjs/validators/record.cjs +1 -262
- package/dist/cjs/validators/set.cjs +1 -203
- package/dist/cjs/validators/string-bool.cjs +1 -124
- package/dist/cjs/validators/string-formats.cjs +1 -168
- package/dist/cjs/validators/string.cjs +1 -12
- package/dist/cjs/validators/symbol.cjs +1 -62
- package/dist/cjs/validators/template-literal.cjs +1 -108
- package/dist/cjs/validators/tuple.cjs +1 -187
- package/dist/cjs/validators/uint8array.cjs +1 -106
- package/dist/cjs/validators/undefined.cjs +1 -43
- package/dist/cjs/validators/union.cjs +1 -191
- package/dist/cjs/validators/unknown.cjs +1 -40
- package/dist/cjs/validators/void.cjs +1 -48
- package/dist/cjs/validators/xor.cjs +1 -69
- package/dist/cli/bin.js +1 -406
- package/dist/cli/index.js +1 -205
- package/dist/codecs/index.js +1 -11
- package/dist/coercion/index.js +1 -579
- package/dist/compat/emitter.js +1 -180
- package/dist/compat/result.js +1 -170
- package/dist/errors-core.d.ts +20 -1
- package/dist/errors.js +1 -171
- package/dist/index.d.ts +248 -357
- package/dist/index.js +1 -1534
- package/dist/kernel.js +1 -409
- package/dist/locales/af.js +1 -106
- package/dist/locales/ar.js +1 -106
- package/dist/locales/bn.js +1 -106
- package/dist/locales/da.js +1 -106
- package/dist/locales/de.js +1 -106
- package/dist/locales/en.js +1 -106
- package/dist/locales/es-MX.js +1 -105
- package/dist/locales/es.js +1 -94
- package/dist/locales/fi.js +1 -106
- package/dist/locales/fr.js +1 -94
- package/dist/locales/hi.js +1 -106
- package/dist/locales/id.js +1 -106
- package/dist/locales/index.js +1 -29
- package/dist/locales/it.js +1 -106
- package/dist/locales/ja.js +1 -106
- package/dist/locales/ko.js +1 -106
- package/dist/locales/lazy.js +1 -177
- package/dist/locales/nl.js +1 -106
- package/dist/locales/no.js +1 -106
- package/dist/locales/pl.js +1 -106
- package/dist/locales/pt-BR.js +1 -106
- package/dist/locales/pt.js +1 -106
- package/dist/locales/ru.js +1 -106
- package/dist/locales/runtime.js +1 -41
- package/dist/locales/sv.js +1 -106
- package/dist/locales/sw.js +1 -106
- package/dist/locales/th.js +1 -106
- package/dist/locales/tr.js +1 -106
- package/dist/locales/vi.js +1 -106
- package/dist/locales/zh.js +1 -106
- package/dist/mini.d.ts +3 -3
- package/dist/mini.js +1 -156
- package/dist/pigment.js +1 -180
- package/dist/plugins/index.js +1 -1
- package/dist/registry.js +1 -34
- package/dist/utils/json-schema.d.ts +10 -1
- package/dist/v3/index.js +1 -46
- package/dist/v4/core/index.d.ts +28 -16
- package/dist/v4/core/index.js +1 -277
- package/dist/v4/index.js +1 -50
- package/dist/v4/locales/index.d.ts +4 -0
- package/dist/v4/locales/index.js +1 -77
- package/dist/v4/mini/index.js +1 -47
- package/dist/v4-mini/index.d.ts +1 -1
- package/dist/v4-mini/index.js +1 -75
- package/dist/validators/any.js +1 -37
- package/dist/validators/array.d.ts +7 -0
- package/dist/validators/array.js +1 -279
- package/dist/validators/base.d.ts +63 -8
- package/dist/validators/base.js +1 -868
- package/dist/validators/base64.js +1 -68
- package/dist/validators/bigint.js +1 -228
- package/dist/validators/boolean.js +1 -142
- package/dist/validators/codec.js +1 -200
- package/dist/validators/custom.js +1 -67
- package/dist/validators/date.js +1 -274
- package/dist/validators/discriminated-union.d.ts +2 -2
- package/dist/validators/discriminated-union.js +1 -123
- package/dist/validators/enum.js +1 -150
- package/dist/validators/file.js +1 -125
- package/dist/validators/function.js +1 -58
- package/dist/validators/hex.js +1 -65
- package/dist/validators/index.d.ts +1 -1
- package/dist/validators/index.js +1 -35
- package/dist/validators/intersection.js +1 -116
- package/dist/validators/json.js +1 -66
- package/dist/validators/lazy.js +1 -50
- package/dist/validators/literal.d.ts +7 -3
- package/dist/validators/literal.js +1 -60
- package/dist/validators/map.js +1 -214
- package/dist/validators/nan.js +1 -38
- package/dist/validators/never.js +1 -32
- package/dist/validators/null.js +1 -40
- package/dist/validators/number.d.ts +20 -1
- package/dist/validators/number.js +1 -423
- package/dist/validators/object.d.ts +12 -2
- package/dist/validators/object.js +1 -864
- package/dist/validators/promise.js +1 -111
- package/dist/validators/record.d.ts +11 -8
- package/dist/validators/record.js +1 -258
- package/dist/validators/set.js +1 -199
- package/dist/validators/string-bool.js +1 -120
- package/dist/validators/string-formats.d.ts +58 -62
- package/dist/validators/string-formats.js +1 -135
- package/dist/validators/string.d.ts +47 -10
- package/dist/validators/string.js +1 -4
- package/dist/validators/symbol.js +1 -58
- package/dist/validators/template-literal.js +1 -103
- package/dist/validators/tuple.d.ts +17 -13
- package/dist/validators/tuple.js +1 -183
- package/dist/validators/uint8array.js +1 -101
- package/dist/validators/undefined.js +1 -40
- package/dist/validators/union.js +1 -187
- package/dist/validators/unknown.js +1 -37
- package/dist/validators/void.js +1 -44
- package/dist/validators/xor.d.ts +2 -2
- package/dist/validators/xor.js +1 -66
- package/package.json +239 -238
- package/dist/chunks/errors-core-BeiFUtZM.js +0 -81
- package/dist/chunks/index-0R2ntSud.js +0 -508
- package/dist/chunks/index-BvH403Yy.js +0 -88
- package/dist/chunks/security-B0Pd_vSY.js +0 -35
- package/dist/chunks/string-BJRQod3t.js +0 -530
- package/dist/cjs/chunks/errors-core-DWxLFs2f.cjs +0 -83
- package/dist/cjs/chunks/index-BkI37108.cjs +0 -538
- package/dist/cjs/chunks/index-Cc3bjUMX.cjs +0 -91
- package/dist/cjs/chunks/security-Dc3Jh13T.cjs +0 -37
- package/dist/cjs/chunks/string-BKZrc4hs.cjs +0 -533
|
@@ -1,508 +0,0 @@
|
|
|
1
|
-
import { VldCodec } from '../validators/codec.js';
|
|
2
|
-
import { VldBase64 } from '../validators/base64.js';
|
|
3
|
-
import { VldHex } from '../validators/hex.js';
|
|
4
|
-
import { VldUint8Array } from '../validators/uint8array.js';
|
|
5
|
-
import { V as VldString } from './string-BJRQod3t.js';
|
|
6
|
-
import { VldNumber } from '../validators/number.js';
|
|
7
|
-
import { VldBigInt } from '../validators/bigint.js';
|
|
8
|
-
import { VldBoolean } from '../validators/boolean.js';
|
|
9
|
-
import { VldDate } from '../validators/date.js';
|
|
10
|
-
import { VldUnknown } from '../validators/unknown.js';
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Utility functions for codec transformations
|
|
14
|
-
*/
|
|
15
|
-
/**
|
|
16
|
-
* Convert a base64 string to Uint8Array
|
|
17
|
-
*/
|
|
18
|
-
function base64ToUint8Array(base64) {
|
|
19
|
-
// Handle URL-safe base64
|
|
20
|
-
const base64Clean = base64.replace(/-/g, '+').replace(/_/g, '/');
|
|
21
|
-
// Add padding if necessary
|
|
22
|
-
const padded = base64Clean.padEnd(base64Clean.length + (4 - base64Clean.length % 4) % 4, '=');
|
|
23
|
-
// Decode base64 to binary string
|
|
24
|
-
const binaryString = safeAtob(padded);
|
|
25
|
-
// Convert binary string to Uint8Array
|
|
26
|
-
const bytes = new Uint8Array(binaryString.length);
|
|
27
|
-
for (let i = 0; i < binaryString.length; i++) {
|
|
28
|
-
bytes[i] = binaryString.charCodeAt(i);
|
|
29
|
-
}
|
|
30
|
-
return bytes;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Convert Uint8Array to base64 string
|
|
34
|
-
*/
|
|
35
|
-
function uint8ArrayToBase64(bytes) {
|
|
36
|
-
// Convert Uint8Array to binary string
|
|
37
|
-
let binaryString = '';
|
|
38
|
-
for (let i = 0; i < bytes.length; i++) {
|
|
39
|
-
binaryString += String.fromCharCode(bytes[i]);
|
|
40
|
-
}
|
|
41
|
-
// Encode to base64
|
|
42
|
-
return safeBtoa(binaryString);
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Convert Uint8Array to URL-safe base64 string
|
|
46
|
-
*/
|
|
47
|
-
function uint8ArrayToBase64Url(bytes) {
|
|
48
|
-
const base64 = uint8ArrayToBase64(bytes);
|
|
49
|
-
// Make URL-safe and remove padding
|
|
50
|
-
return base64
|
|
51
|
-
.replace(/\+/g, '-')
|
|
52
|
-
.replace(/\//g, '_')
|
|
53
|
-
.replace(/=/g, '');
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Convert hex string to Uint8Array
|
|
57
|
-
*/
|
|
58
|
-
function hexToUint8Array(hex) {
|
|
59
|
-
// BUG-010 FIX: Add length validation to prevent memory exhaustion
|
|
60
|
-
// 20 million characters = 10MB of data (consistent with base64 limits)
|
|
61
|
-
if (hex.length > 20000000) {
|
|
62
|
-
throw new Error('Hex string is too large (max 10MB)');
|
|
63
|
-
}
|
|
64
|
-
// Remove any 0x prefix if present
|
|
65
|
-
const cleanHex = hex.startsWith('0x') ? hex.slice(2) : hex;
|
|
66
|
-
// BUG-NPM-006 FIX: Validate hex characters to prevent silent data corruption
|
|
67
|
-
// parseInt silently returns NaN for invalid hex, which becomes 0 in Uint8Array
|
|
68
|
-
const hexPattern = /^[0-9a-fA-F]*$/;
|
|
69
|
-
if (!hexPattern.test(cleanHex)) {
|
|
70
|
-
throw new Error('Invalid hex string: contains non-hexadecimal characters');
|
|
71
|
-
}
|
|
72
|
-
// Ensure even length
|
|
73
|
-
const paddedHex = cleanHex.length % 2 === 0 ? cleanHex : '0' + cleanHex;
|
|
74
|
-
const bytes = new Uint8Array(paddedHex.length / 2);
|
|
75
|
-
for (let i = 0; i < paddedHex.length; i += 2) {
|
|
76
|
-
bytes[i / 2] = parseInt(paddedHex.substring(i, i + 2), 16);
|
|
77
|
-
}
|
|
78
|
-
return bytes;
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Convert Uint8Array to hex string
|
|
82
|
-
*/
|
|
83
|
-
function uint8ArrayToHex(bytes) {
|
|
84
|
-
let hex = '';
|
|
85
|
-
for (let i = 0; i < bytes.length; i++) {
|
|
86
|
-
const byte = bytes[i].toString(16);
|
|
87
|
-
hex += byte.length === 1 ? '0' + byte : byte;
|
|
88
|
-
}
|
|
89
|
-
return hex;
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Convert string to Uint8Array using UTF-8 encoding
|
|
93
|
-
* BUG-NEW-011 FIX: Add DoS protection with 10MB limit
|
|
94
|
-
*/
|
|
95
|
-
function stringToUint8Array(str) {
|
|
96
|
-
// Add DoS protection - limit to 10MB (consistent with base64 limit)
|
|
97
|
-
const MAX_STRING_LENGTH = 10000000; // 10 million characters (~10MB)
|
|
98
|
-
if (str.length > MAX_STRING_LENGTH) {
|
|
99
|
-
throw new Error(`String is too large for UTF-8 encoding (max ${MAX_STRING_LENGTH} characters)`);
|
|
100
|
-
}
|
|
101
|
-
const encoder = new TextEncoder();
|
|
102
|
-
return encoder.encode(str);
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Convert Uint8Array to string using UTF-8 decoding
|
|
106
|
-
* BUG-NEW-012 FIX: Add DoS protection with 10MB limit
|
|
107
|
-
*/
|
|
108
|
-
function uint8ArrayToString(bytes) {
|
|
109
|
-
// Add DoS protection - limit to 10MB
|
|
110
|
-
const MAX_BYTES_LENGTH = 10000000; // 10 million bytes
|
|
111
|
-
if (bytes.length > MAX_BYTES_LENGTH) {
|
|
112
|
-
throw new Error(`Byte array is too large for UTF-8 decoding (max ${MAX_BYTES_LENGTH} bytes)`);
|
|
113
|
-
}
|
|
114
|
-
const decoder = new TextDecoder();
|
|
115
|
-
return decoder.decode(bytes);
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* Check if running in Node.js environment
|
|
119
|
-
*/
|
|
120
|
-
function isNodeEnvironment() {
|
|
121
|
-
return typeof globalThis !== 'undefined' &&
|
|
122
|
-
typeof globalThis.process !== 'undefined' &&
|
|
123
|
-
globalThis.process.versions != null &&
|
|
124
|
-
globalThis.process.versions.node != null;
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* Validate and sanitize base64 input to prevent prototype pollution
|
|
128
|
-
*/
|
|
129
|
-
function validateBase64Input(encoded) {
|
|
130
|
-
// Check for null/undefined
|
|
131
|
-
if (encoded == null) {
|
|
132
|
-
throw new Error('Base64 input cannot be null or undefined');
|
|
133
|
-
}
|
|
134
|
-
// Ensure it's a string
|
|
135
|
-
if (typeof encoded !== 'string') {
|
|
136
|
-
throw new Error('Base64 input must be a string');
|
|
137
|
-
}
|
|
138
|
-
// Length validation - base64 strings should be reasonable length
|
|
139
|
-
if (encoded.length > 10000000) { // 10MB limit
|
|
140
|
-
throw new Error('Base64 input is too large');
|
|
141
|
-
}
|
|
142
|
-
// Base64 character validation - only allow valid base64 characters
|
|
143
|
-
const base64Regex = /^[A-Za-z0-9+/]*={0,2}$/;
|
|
144
|
-
if (!base64Regex.test(encoded)) {
|
|
145
|
-
throw new Error('Invalid base64 format');
|
|
146
|
-
}
|
|
147
|
-
// BUG-NEW-004 FIX: Correct base64 padding validation per RFC 4648
|
|
148
|
-
// Base64 only uses '=' or '==' as padding, never '==='
|
|
149
|
-
const paddingIndex = encoded.indexOf('=');
|
|
150
|
-
if (paddingIndex !== -1) {
|
|
151
|
-
const padding = encoded.substring(paddingIndex);
|
|
152
|
-
// Only allow '=' or '==' as valid padding (RFC 4648 compliant)
|
|
153
|
-
if (!/^={1,2}$/.test(padding)) {
|
|
154
|
-
throw new Error('Invalid base64 padding');
|
|
155
|
-
}
|
|
156
|
-
// Padding should only be at the end
|
|
157
|
-
if (paddingIndex < encoded.length - 2) {
|
|
158
|
-
throw new Error('Base64 padding must be at the end');
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
// Additional security check: prevent potential encoded JavaScript
|
|
162
|
-
// by looking for suspicious patterns that might indicate malicious content
|
|
163
|
-
const suspiciousPatterns = [
|
|
164
|
-
/eval/i,
|
|
165
|
-
/function/i,
|
|
166
|
-
/javascript:/i,
|
|
167
|
-
/<script/i,
|
|
168
|
-
/on\w+\s*=/i,
|
|
169
|
-
/__proto__/i,
|
|
170
|
-
/constructor/i,
|
|
171
|
-
/prototype/i
|
|
172
|
-
];
|
|
173
|
-
// Decode a small portion to check for suspicious content
|
|
174
|
-
try {
|
|
175
|
-
const sampleSize = Math.min(100, encoded.length);
|
|
176
|
-
const sample = encoded.substring(0, sampleSize);
|
|
177
|
-
const sampleDecoded = typeof atob !== 'undefined'
|
|
178
|
-
? atob(sample)
|
|
179
|
-
: Buffer.from(sample, 'base64').toString('utf8', 0, 50); // Only decode first 50 chars
|
|
180
|
-
for (const pattern of suspiciousPatterns) {
|
|
181
|
-
if (pattern.test(sampleDecoded)) {
|
|
182
|
-
throw new Error('Suspicious content detected in base64 input');
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
catch (error) {
|
|
187
|
-
if (error instanceof Error && error.message.includes('Suspicious content')) {
|
|
188
|
-
throw error;
|
|
189
|
-
}
|
|
190
|
-
// If decoding fails, continue - it might be invalid base64 which will be caught later
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
/**
|
|
194
|
-
* Polyfill for atob in Node.js with proper input validation
|
|
195
|
-
*/
|
|
196
|
-
function safeAtob(encoded) {
|
|
197
|
-
// Input validation and sanitization
|
|
198
|
-
validateBase64Input(encoded);
|
|
199
|
-
if (typeof atob !== 'undefined') {
|
|
200
|
-
try {
|
|
201
|
-
return atob(encoded);
|
|
202
|
-
}
|
|
203
|
-
catch {
|
|
204
|
-
throw new Error('Failed to decode base64 data');
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
// Node.js fallback with additional validation
|
|
208
|
-
if (isNodeEnvironment()) {
|
|
209
|
-
try {
|
|
210
|
-
// Use Buffer with explicit error handling
|
|
211
|
-
const buffer = Buffer.from(encoded, 'base64');
|
|
212
|
-
// Additional validation: ensure the decoded data is reasonable size
|
|
213
|
-
if (buffer.length > 5000000) { // 5MB limit for decoded data
|
|
214
|
-
throw new Error('Decoded base64 data is too large');
|
|
215
|
-
}
|
|
216
|
-
return buffer.toString('binary');
|
|
217
|
-
}
|
|
218
|
-
catch (error) {
|
|
219
|
-
if (error instanceof Error && error.message.includes('Invalid base64')) {
|
|
220
|
-
throw new Error('Invalid base64 format');
|
|
221
|
-
}
|
|
222
|
-
throw new Error('Failed to decode base64 data in Node.js environment');
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
throw new Error('Base64 decoding not supported in this environment');
|
|
226
|
-
}
|
|
227
|
-
/**
|
|
228
|
-
* Polyfill for btoa in Node.js
|
|
229
|
-
*/
|
|
230
|
-
function safeBtoa(str) {
|
|
231
|
-
if (typeof btoa !== 'undefined') {
|
|
232
|
-
return btoa(str);
|
|
233
|
-
}
|
|
234
|
-
// Node.js fallback
|
|
235
|
-
if (isNodeEnvironment()) {
|
|
236
|
-
return Buffer.from(str, 'binary').toString('base64');
|
|
237
|
-
}
|
|
238
|
-
throw new Error('Base64 encoding not supported in this environment');
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
/**
|
|
242
|
-
* Invert a codec, swapping encode and decode directions.
|
|
243
|
-
*/
|
|
244
|
-
function invertCodec(codec) {
|
|
245
|
-
return codec.invert();
|
|
246
|
-
}
|
|
247
|
-
// ===== STRING TO NUMBER CODECS =====
|
|
248
|
-
/**
|
|
249
|
-
* String to number codec
|
|
250
|
-
*/
|
|
251
|
-
const stringToNumber = VldCodec.create(VldString.create(), VldNumber.create(), {
|
|
252
|
-
decode: (str) => {
|
|
253
|
-
const num = Number(str);
|
|
254
|
-
if (isNaN(num))
|
|
255
|
-
throw new Error('Invalid number');
|
|
256
|
-
return num;
|
|
257
|
-
},
|
|
258
|
-
encode: (num) => num.toString()
|
|
259
|
-
});
|
|
260
|
-
/**
|
|
261
|
-
* String to integer codec
|
|
262
|
-
*/
|
|
263
|
-
const stringToInt = VldCodec.create(VldString.create(), VldNumber.create().int(), {
|
|
264
|
-
decode: (str) => {
|
|
265
|
-
const num = parseInt(str, 10);
|
|
266
|
-
if (isNaN(num))
|
|
267
|
-
throw new Error('Invalid integer');
|
|
268
|
-
return num;
|
|
269
|
-
},
|
|
270
|
-
encode: (num) => Math.floor(num).toString()
|
|
271
|
-
});
|
|
272
|
-
/**
|
|
273
|
-
* String to BigInt codec
|
|
274
|
-
*/
|
|
275
|
-
const stringToBigInt = VldCodec.create(VldString.create(), VldBigInt.create(), {
|
|
276
|
-
decode: (str) => {
|
|
277
|
-
try {
|
|
278
|
-
return BigInt(str);
|
|
279
|
-
}
|
|
280
|
-
catch {
|
|
281
|
-
throw new Error('Invalid BigInt');
|
|
282
|
-
}
|
|
283
|
-
},
|
|
284
|
-
encode: (bigint) => bigint.toString()
|
|
285
|
-
});
|
|
286
|
-
/**
|
|
287
|
-
* Number to BigInt codec
|
|
288
|
-
*/
|
|
289
|
-
const numberToBigInt = VldCodec.create(VldNumber.create().int(), VldBigInt.create(), {
|
|
290
|
-
decode: (num) => BigInt(Math.floor(num)),
|
|
291
|
-
encode: (bigint) => Number(bigint)
|
|
292
|
-
});
|
|
293
|
-
// ===== DATE CODECS =====
|
|
294
|
-
/**
|
|
295
|
-
* ISO datetime string to Date codec
|
|
296
|
-
*/
|
|
297
|
-
const isoDatetimeToDate = VldCodec.create(VldString.create().regex(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{3})?Z?$/, 'Invalid ISO datetime format'), VldDate.create(), {
|
|
298
|
-
decode: (isoString) => {
|
|
299
|
-
const date = new Date(isoString);
|
|
300
|
-
if (isNaN(date.getTime()))
|
|
301
|
-
throw new Error('Invalid date');
|
|
302
|
-
return date;
|
|
303
|
-
},
|
|
304
|
-
encode: (date) => date.toISOString()
|
|
305
|
-
});
|
|
306
|
-
/**
|
|
307
|
-
* Epoch seconds to Date codec
|
|
308
|
-
*/
|
|
309
|
-
const epochSecondsToDate = VldCodec.create(VldNumber.create(), VldDate.create(), {
|
|
310
|
-
decode: (seconds) => new Date(seconds * 1000),
|
|
311
|
-
encode: (date) => Math.floor(date.getTime() / 1000)
|
|
312
|
-
});
|
|
313
|
-
/**
|
|
314
|
-
* Epoch milliseconds to Date codec
|
|
315
|
-
*/
|
|
316
|
-
const epochMillisToDate = VldCodec.create(VldNumber.create(), VldDate.create(), {
|
|
317
|
-
decode: (millis) => new Date(millis),
|
|
318
|
-
encode: (date) => date.getTime()
|
|
319
|
-
});
|
|
320
|
-
// ===== JSON CODEC =====
|
|
321
|
-
/**
|
|
322
|
-
* JSON string codec for any type
|
|
323
|
-
*/
|
|
324
|
-
const jsonCodec = (schema) => {
|
|
325
|
-
const outputSchema = schema || VldUnknown.create();
|
|
326
|
-
return VldCodec.create(VldString.create(), outputSchema, {
|
|
327
|
-
decode: (jsonString) => {
|
|
328
|
-
try {
|
|
329
|
-
return JSON.parse(jsonString);
|
|
330
|
-
}
|
|
331
|
-
catch {
|
|
332
|
-
throw new Error('Invalid JSON');
|
|
333
|
-
}
|
|
334
|
-
},
|
|
335
|
-
encode: (data) => JSON.stringify(data)
|
|
336
|
-
});
|
|
337
|
-
};
|
|
338
|
-
// ===== URL CODECS =====
|
|
339
|
-
/**
|
|
340
|
-
* String to URL codec
|
|
341
|
-
*/
|
|
342
|
-
const stringToURL = VldCodec.create(VldString.create().url(), VldUnknown.create(), // URL object
|
|
343
|
-
{
|
|
344
|
-
decode: (urlString) => {
|
|
345
|
-
try {
|
|
346
|
-
return new URL(urlString);
|
|
347
|
-
}
|
|
348
|
-
catch {
|
|
349
|
-
throw new Error('Invalid URL');
|
|
350
|
-
}
|
|
351
|
-
},
|
|
352
|
-
encode: (url) => url.toString()
|
|
353
|
-
});
|
|
354
|
-
/**
|
|
355
|
-
* String to HTTP/HTTPS URL codec
|
|
356
|
-
*/
|
|
357
|
-
const stringToHttpURL = VldCodec.create(VldString.create().regex(/^https?:\/\//, 'Must be HTTP or HTTPS URL'), VldUnknown.create(), // URL object
|
|
358
|
-
{
|
|
359
|
-
decode: (urlString) => {
|
|
360
|
-
try {
|
|
361
|
-
const url = new URL(urlString);
|
|
362
|
-
if (!['http:', 'https:'].includes(url.protocol)) {
|
|
363
|
-
throw new Error('Must be HTTP or HTTPS');
|
|
364
|
-
}
|
|
365
|
-
return url;
|
|
366
|
-
}
|
|
367
|
-
catch {
|
|
368
|
-
throw new Error('Invalid HTTP URL');
|
|
369
|
-
}
|
|
370
|
-
},
|
|
371
|
-
encode: (url) => url.toString()
|
|
372
|
-
});
|
|
373
|
-
/**
|
|
374
|
-
* URI component encode/decode codec
|
|
375
|
-
*/
|
|
376
|
-
const uriComponent = VldCodec.create(VldString.create(), VldString.create(), {
|
|
377
|
-
decode: (encoded) => {
|
|
378
|
-
try {
|
|
379
|
-
return decodeURIComponent(encoded);
|
|
380
|
-
}
|
|
381
|
-
catch {
|
|
382
|
-
throw new Error('Invalid URI component');
|
|
383
|
-
}
|
|
384
|
-
},
|
|
385
|
-
encode: (decoded) => encodeURIComponent(decoded)
|
|
386
|
-
});
|
|
387
|
-
/**
|
|
388
|
-
* String to boolean codec
|
|
389
|
-
*/
|
|
390
|
-
const stringToBoolean = VldCodec.create(VldString.create(), VldBoolean.create(), {
|
|
391
|
-
decode: (str) => {
|
|
392
|
-
const lower = str.toLowerCase();
|
|
393
|
-
if (lower === 'true' || lower === '1' || lower === 'yes' || lower === 'on')
|
|
394
|
-
return true;
|
|
395
|
-
if (lower === 'false' || lower === '0' || lower === 'no' || lower === 'off')
|
|
396
|
-
return false;
|
|
397
|
-
throw new Error('Invalid boolean string');
|
|
398
|
-
},
|
|
399
|
-
encode: (bool) => bool.toString()
|
|
400
|
-
});
|
|
401
|
-
// ===== EXISTING BYTE CODECS (updated) =====
|
|
402
|
-
/**
|
|
403
|
-
* Base64 to Uint8Array codec
|
|
404
|
-
*/
|
|
405
|
-
const base64ToBytes = VldCodec.create(VldBase64.create(), VldUint8Array.create(), {
|
|
406
|
-
decode: base64ToUint8Array,
|
|
407
|
-
encode: uint8ArrayToBase64
|
|
408
|
-
});
|
|
409
|
-
/**
|
|
410
|
-
* URL-safe Base64 to Uint8Array codec
|
|
411
|
-
*/
|
|
412
|
-
const base64UrlToBytes = VldCodec.create(VldBase64.create().urlSafeMode(), VldUint8Array.create(), {
|
|
413
|
-
decode: base64ToUint8Array,
|
|
414
|
-
encode: uint8ArrayToBase64Url
|
|
415
|
-
});
|
|
416
|
-
/**
|
|
417
|
-
* Hexadecimal to Uint8Array codec
|
|
418
|
-
*/
|
|
419
|
-
const hexToBytes = VldCodec.create(VldHex.create(), VldUint8Array.create(), {
|
|
420
|
-
decode: hexToUint8Array,
|
|
421
|
-
encode: uint8ArrayToHex
|
|
422
|
-
});
|
|
423
|
-
/**
|
|
424
|
-
* Lowercase hexadecimal to Uint8Array codec
|
|
425
|
-
*/
|
|
426
|
-
const hexLowerToBytes = VldCodec.create(VldHex.create().lowercaseMode(), VldUint8Array.create(), {
|
|
427
|
-
decode: hexToUint8Array,
|
|
428
|
-
encode: (bytes) => uint8ArrayToHex(bytes).toLowerCase()
|
|
429
|
-
});
|
|
430
|
-
/**
|
|
431
|
-
* UTF-8 string to Uint8Array codec
|
|
432
|
-
*/
|
|
433
|
-
const utf8ToBytes = VldCodec.create(VldString.create(), VldUint8Array.create(), {
|
|
434
|
-
decode: stringToUint8Array,
|
|
435
|
-
encode: uint8ArrayToString
|
|
436
|
-
});
|
|
437
|
-
/**
|
|
438
|
-
* Uint8Array to UTF-8 string codec (reverse of utf8ToBytes)
|
|
439
|
-
*/
|
|
440
|
-
const bytesToUtf8 = VldCodec.create(VldUint8Array.create(), VldString.create(), {
|
|
441
|
-
decode: uint8ArrayToString,
|
|
442
|
-
encode: stringToUint8Array
|
|
443
|
-
});
|
|
444
|
-
/**
|
|
445
|
-
* Base64URL to Uint8Array codec (updated)
|
|
446
|
-
*/
|
|
447
|
-
const base64urlToBytes = VldCodec.create(VldBase64.create().urlSafeMode(), VldUint8Array.create(), {
|
|
448
|
-
decode: base64ToUint8Array,
|
|
449
|
-
encode: uint8ArrayToBase64Url
|
|
450
|
-
});
|
|
451
|
-
/**
|
|
452
|
-
* Base64 encoded JSON codec (updated)
|
|
453
|
-
*/
|
|
454
|
-
const base64Json = (schema) => {
|
|
455
|
-
const outputSchema = schema || VldUnknown.create();
|
|
456
|
-
return VldCodec.create(VldBase64.create(), outputSchema, {
|
|
457
|
-
decode: (base64) => {
|
|
458
|
-
// BUG-NPM-005 FIX: Add error handling for JSON parsing
|
|
459
|
-
try {
|
|
460
|
-
const jsonString = uint8ArrayToString(base64ToUint8Array(base64));
|
|
461
|
-
return JSON.parse(jsonString);
|
|
462
|
-
}
|
|
463
|
-
catch (error) {
|
|
464
|
-
throw new Error(`Failed to parse base64 JSON: ${error.message}`);
|
|
465
|
-
}
|
|
466
|
-
},
|
|
467
|
-
encode: (data) => {
|
|
468
|
-
const jsonString = JSON.stringify(data);
|
|
469
|
-
return uint8ArrayToBase64(stringToUint8Array(jsonString));
|
|
470
|
-
}
|
|
471
|
-
});
|
|
472
|
-
};
|
|
473
|
-
/**
|
|
474
|
-
* JWT payload decoder (base64url encoded JSON) - updated
|
|
475
|
-
*/
|
|
476
|
-
const jwtPayload = (schema) => {
|
|
477
|
-
const outputSchema = schema || VldUnknown.create();
|
|
478
|
-
return VldCodec.create(VldString.create().refine(s => s.split('.').length === 3, 'Invalid JWT format'), outputSchema, {
|
|
479
|
-
decode: (jwt) => {
|
|
480
|
-
// BUG-NPM-004 FIX: Add comprehensive error handling for JWT parsing
|
|
481
|
-
try {
|
|
482
|
-
const parts = jwt.split('.');
|
|
483
|
-
if (parts.length !== 3) {
|
|
484
|
-
throw new Error('JWT must have exactly 3 parts');
|
|
485
|
-
}
|
|
486
|
-
const payloadBase64 = parts[1];
|
|
487
|
-
if (!payloadBase64) {
|
|
488
|
-
throw new Error('JWT payload is empty');
|
|
489
|
-
}
|
|
490
|
-
// Convert base64url to base64
|
|
491
|
-
const base64 = payloadBase64
|
|
492
|
-
.replace(/-/g, '+')
|
|
493
|
-
.replace(/_/g, '/')
|
|
494
|
-
.padEnd(payloadBase64.length + (4 - payloadBase64.length % 4) % 4, '=');
|
|
495
|
-
const jsonString = uint8ArrayToString(base64ToUint8Array(base64));
|
|
496
|
-
return JSON.parse(jsonString);
|
|
497
|
-
}
|
|
498
|
-
catch (error) {
|
|
499
|
-
throw new Error(`Failed to decode JWT payload: ${error.message}`);
|
|
500
|
-
}
|
|
501
|
-
},
|
|
502
|
-
encode: () => {
|
|
503
|
-
throw new Error('JWT encoding not supported - use a proper JWT library');
|
|
504
|
-
}
|
|
505
|
-
});
|
|
506
|
-
};
|
|
507
|
-
|
|
508
|
-
export { uint8ArrayToString as A, uriComponent as B, utf8ToBytes as C, base64ToBytes as a, base64Json as b, base64ToUint8Array as c, base64UrlToBytes as d, base64urlToBytes as e, bytesToUtf8 as f, epochMillisToDate as g, epochSecondsToDate as h, hexLowerToBytes as i, hexToBytes as j, hexToUint8Array as k, invertCodec as l, isoDatetimeToDate as m, jsonCodec as n, jwtPayload as o, numberToBigInt as p, stringToBoolean as q, stringToHttpURL as r, stringToBigInt as s, stringToInt as t, stringToNumber as u, stringToURL as v, stringToUint8Array as w, uint8ArrayToBase64 as x, uint8ArrayToBase64Url as y, uint8ArrayToHex as z };
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { registerLocale, registerFallbackLocale, setLocale, getLocale, getMessages, getMessagesForLocale, getSupportedLocales, isLocaleLoaded, isLocaleSupported } from '../locales/runtime.js';
|
|
2
|
-
import { en } from '../locales/en.js';
|
|
3
|
-
import { tr } from '../locales/tr.js';
|
|
4
|
-
import { es } from '../locales/es.js';
|
|
5
|
-
import { fr } from '../locales/fr.js';
|
|
6
|
-
import { de } from '../locales/de.js';
|
|
7
|
-
import { it } from '../locales/it.js';
|
|
8
|
-
import { pt } from '../locales/pt.js';
|
|
9
|
-
import { ru } from '../locales/ru.js';
|
|
10
|
-
import { ja } from '../locales/ja.js';
|
|
11
|
-
import { ko } from '../locales/ko.js';
|
|
12
|
-
import { zh } from '../locales/zh.js';
|
|
13
|
-
import { ar } from '../locales/ar.js';
|
|
14
|
-
import { hi } from '../locales/hi.js';
|
|
15
|
-
import { nl } from '../locales/nl.js';
|
|
16
|
-
import { pl } from '../locales/pl.js';
|
|
17
|
-
import { da } from '../locales/da.js';
|
|
18
|
-
import { sv } from '../locales/sv.js';
|
|
19
|
-
import { no } from '../locales/no.js';
|
|
20
|
-
import { fi } from '../locales/fi.js';
|
|
21
|
-
import { th } from '../locales/th.js';
|
|
22
|
-
import { vi } from '../locales/vi.js';
|
|
23
|
-
import { id } from '../locales/id.js';
|
|
24
|
-
import { bn } from '../locales/bn.js';
|
|
25
|
-
import { sw } from '../locales/sw.js';
|
|
26
|
-
import { af } from '../locales/af.js';
|
|
27
|
-
import { ptBR } from '../locales/pt-BR.js';
|
|
28
|
-
import { esMX } from '../locales/es-MX.js';
|
|
29
|
-
|
|
30
|
-
const translatedLocaleCodes = [
|
|
31
|
-
'en', 'tr', 'es', 'fr', 'de', 'it', 'pt', 'ru', 'ja', 'ko', 'zh', 'ar', 'hi', 'nl', 'pl',
|
|
32
|
-
'da', 'sv', 'no', 'fi',
|
|
33
|
-
'th', 'vi', 'id', 'bn',
|
|
34
|
-
'sw', 'af',
|
|
35
|
-
'pt-BR', 'es-MX'
|
|
36
|
-
];
|
|
37
|
-
const fallbackLocaleCodes = [
|
|
38
|
-
'is', 'cs', 'sk', 'hu', 'ro', 'bg', 'hr', 'sl', 'lv', 'lt', 'et',
|
|
39
|
-
'el', 'mk', 'sq', 'sr', 'bs', 'me', 'mt', 'ga', 'cy', 'eu', 'ca',
|
|
40
|
-
'ms', 'tl', 'ur', 'fa', 'he', 'ka', 'am', 'hy', 'az', 'kk', 'ky',
|
|
41
|
-
'uz', 'tg', 'mn', 'my', 'km', 'lo', 'si', 'ta', 'te', 'ml', 'kn',
|
|
42
|
-
'gu', 'pa', 'or', 'as', 'ne', 'mr', 'sd', 'dv',
|
|
43
|
-
'ha', 'yo', 'ig', 'zu', 'xh', 'st', 'tn', 'ts', 've', 'nr', 'ss',
|
|
44
|
-
'es-AR', 'fr-CA', 'qu', 'gn', 'ay'
|
|
45
|
-
];
|
|
46
|
-
const translatedLocales = {
|
|
47
|
-
// Base languages
|
|
48
|
-
en, tr, es, fr, de, it, pt, ru, ja, ko, zh, ar, hi, nl, pl,
|
|
49
|
-
// Major European Languages
|
|
50
|
-
da, sv, no, fi,
|
|
51
|
-
// Major Asian Languages
|
|
52
|
-
th, vi, id, bn,
|
|
53
|
-
// African Languages
|
|
54
|
-
sw, af,
|
|
55
|
-
// American Languages
|
|
56
|
-
'pt-BR': ptBR,
|
|
57
|
-
'es-MX': esMX,
|
|
58
|
-
};
|
|
59
|
-
for (const locale of translatedLocaleCodes) {
|
|
60
|
-
registerLocale(locale, translatedLocales[locale]);
|
|
61
|
-
}
|
|
62
|
-
for (const locale of fallbackLocaleCodes) {
|
|
63
|
-
registerFallbackLocale(locale);
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Set the current locale asynchronously.
|
|
67
|
-
*
|
|
68
|
-
* The eager locale entrypoint already bundles translated locales and English
|
|
69
|
-
* fallbacks, so this mirrors setLocale() while preserving async API parity.
|
|
70
|
-
*/
|
|
71
|
-
async function setLocaleAsync(locale) {
|
|
72
|
-
setLocale(locale);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
var localeNamespace = /*#__PURE__*/Object.freeze({
|
|
76
|
-
__proto__: null,
|
|
77
|
-
getLocale: getLocale,
|
|
78
|
-
getMessages: getMessages,
|
|
79
|
-
getMessagesForLocale: getMessagesForLocale,
|
|
80
|
-
getSupportedLocales: getSupportedLocales,
|
|
81
|
-
isLocaleLoaded: isLocaleLoaded,
|
|
82
|
-
isLocaleSupported: isLocaleSupported,
|
|
83
|
-
registerLocale: registerLocale,
|
|
84
|
-
setLocale: setLocale,
|
|
85
|
-
setLocaleAsync: setLocaleAsync
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
export { localeNamespace as l, setLocaleAsync as s };
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Security utilities for prototype pollution protection
|
|
3
|
-
*/
|
|
4
|
-
/**
|
|
5
|
-
* Keys that, when written via `obj[key] = ...`, can mutate Object.prototype
|
|
6
|
-
* or alter property accessor behavior across the program.
|
|
7
|
-
*
|
|
8
|
-
* `__proto__`, `constructor`, `prototype` are the canonical prototype-pollution
|
|
9
|
-
* sinks. The `__define*Getter__` / `__lookup*Getter__` family installs accessors
|
|
10
|
-
* on the prototype chain in legacy engines.
|
|
11
|
-
*
|
|
12
|
-
* Note: keys such as `toString`, `valueOf`, or `hasOwnProperty` are NOT
|
|
13
|
-
* blocked. Those are legitimate property names that appear in real payloads
|
|
14
|
-
* (localization tables, custom widget config, generic key/value stores).
|
|
15
|
-
* Silently dropping them causes data loss; a validation library must not do
|
|
16
|
-
* that.
|
|
17
|
-
*/
|
|
18
|
-
const DANGEROUS_KEYS = new Set([
|
|
19
|
-
'__proto__',
|
|
20
|
-
'constructor',
|
|
21
|
-
'prototype',
|
|
22
|
-
'__defineGetter__',
|
|
23
|
-
'__defineSetter__',
|
|
24
|
-
'__lookupGetter__',
|
|
25
|
-
'__lookupSetter__',
|
|
26
|
-
]);
|
|
27
|
-
/**
|
|
28
|
-
* Return true if a property key would, if assigned, mutate the prototype
|
|
29
|
-
* chain or accessor behavior of the target object.
|
|
30
|
-
*/
|
|
31
|
-
function isDangerousKey(key) {
|
|
32
|
-
return DANGEROUS_KEYS.has(key);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export { isDangerousKey as i };
|