bytekit 0.1.12
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 +21 -0
- package/README.md +2241 -0
- package/bin/sutils.js +9 -0
- package/dist/api-client.d.ts +2 -0
- package/dist/api-client.d.ts.map +1 -0
- package/dist/api-client.js +2 -0
- package/dist/api-client.js.map +1 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +401 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/type-generator.d.ts +12 -0
- package/dist/cli/type-generator.d.ts.map +1 -0
- package/dist/cli/type-generator.js +152 -0
- package/dist/cli/type-generator.js.map +1 -0
- package/dist/date-utils.d.ts +2 -0
- package/dist/date-utils.d.ts.map +1 -0
- package/dist/date-utils.js +2 -0
- package/dist/date-utils.js.map +1 -0
- package/dist/debug.d.ts +2 -0
- package/dist/debug.d.ts.map +1 -0
- package/dist/debug.js +2 -0
- package/dist/debug.js.map +1 -0
- package/dist/env-manager.d.ts +2 -0
- package/dist/env-manager.d.ts.map +1 -0
- package/dist/env-manager.js +2 -0
- package/dist/env-manager.js.map +1 -0
- package/dist/file-upload.d.ts +2 -0
- package/dist/file-upload.d.ts.map +1 -0
- package/dist/file-upload.js +2 -0
- package/dist/file-upload.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/logger.d.ts +2 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +2 -0
- package/dist/logger.js.map +1 -0
- package/dist/profiler.d.ts +2 -0
- package/dist/profiler.d.ts.map +1 -0
- package/dist/profiler.js +2 -0
- package/dist/profiler.js.map +1 -0
- package/dist/response-validator.d.ts +2 -0
- package/dist/response-validator.d.ts.map +1 -0
- package/dist/response-validator.js +2 -0
- package/dist/response-validator.js.map +1 -0
- package/dist/retry-policy.d.ts +2 -0
- package/dist/retry-policy.d.ts.map +1 -0
- package/dist/retry-policy.js +2 -0
- package/dist/retry-policy.js.map +1 -0
- package/dist/storage-utils.d.ts +2 -0
- package/dist/storage-utils.d.ts.map +1 -0
- package/dist/storage-utils.js +2 -0
- package/dist/storage-utils.js.map +1 -0
- package/dist/streaming.d.ts +2 -0
- package/dist/streaming.d.ts.map +1 -0
- package/dist/streaming.js +2 -0
- package/dist/streaming.js.map +1 -0
- package/dist/string-utils.d.ts +2 -0
- package/dist/string-utils.d.ts.map +1 -0
- package/dist/string-utils.js +2 -0
- package/dist/string-utils.js.map +1 -0
- package/dist/utils/core/ApiClient.d.ts +94 -0
- package/dist/utils/core/ApiClient.d.ts.map +1 -0
- package/dist/utils/core/ApiClient.js +291 -0
- package/dist/utils/core/ApiClient.js.map +1 -0
- package/dist/utils/core/ErrorBoundary.d.ts +141 -0
- package/dist/utils/core/ErrorBoundary.d.ts.map +1 -0
- package/dist/utils/core/ErrorBoundary.js +322 -0
- package/dist/utils/core/ErrorBoundary.js.map +1 -0
- package/dist/utils/core/Logger.d.ts +39 -0
- package/dist/utils/core/Logger.d.ts.map +1 -0
- package/dist/utils/core/Logger.js +154 -0
- package/dist/utils/core/Logger.js.map +1 -0
- package/dist/utils/core/Profiler.d.ts +8 -0
- package/dist/utils/core/Profiler.d.ts.map +1 -0
- package/dist/utils/core/Profiler.js +18 -0
- package/dist/utils/core/Profiler.js.map +1 -0
- package/dist/utils/core/RateLimiter.d.ts +74 -0
- package/dist/utils/core/RateLimiter.d.ts.map +1 -0
- package/dist/utils/core/RateLimiter.js +170 -0
- package/dist/utils/core/RateLimiter.js.map +1 -0
- package/dist/utils/core/RequestCache.d.ts +64 -0
- package/dist/utils/core/RequestCache.d.ts.map +1 -0
- package/dist/utils/core/RequestCache.js +139 -0
- package/dist/utils/core/RequestCache.js.map +1 -0
- package/dist/utils/core/RequestDeduplicator.d.ts +41 -0
- package/dist/utils/core/RequestDeduplicator.d.ts.map +1 -0
- package/dist/utils/core/RequestDeduplicator.js +83 -0
- package/dist/utils/core/RequestDeduplicator.js.map +1 -0
- package/dist/utils/core/ResponseValidator.d.ts +26 -0
- package/dist/utils/core/ResponseValidator.d.ts.map +1 -0
- package/dist/utils/core/ResponseValidator.js +140 -0
- package/dist/utils/core/ResponseValidator.js.map +1 -0
- package/dist/utils/core/RetryPolicy.d.ts +43 -0
- package/dist/utils/core/RetryPolicy.d.ts.map +1 -0
- package/dist/utils/core/RetryPolicy.js +119 -0
- package/dist/utils/core/RetryPolicy.js.map +1 -0
- package/dist/utils/core/debug.d.ts +46 -0
- package/dist/utils/core/debug.d.ts.map +1 -0
- package/dist/utils/core/debug.js +83 -0
- package/dist/utils/core/debug.js.map +1 -0
- package/dist/utils/core/index.d.ts +11 -0
- package/dist/utils/core/index.d.ts.map +1 -0
- package/dist/utils/core/index.js +11 -0
- package/dist/utils/core/index.js.map +1 -0
- package/dist/utils/helpers/ArrayUtils.d.ts +134 -0
- package/dist/utils/helpers/ArrayUtils.d.ts.map +1 -0
- package/dist/utils/helpers/ArrayUtils.js +301 -0
- package/dist/utils/helpers/ArrayUtils.js.map +1 -0
- package/dist/utils/helpers/CacheManager.d.ts +67 -0
- package/dist/utils/helpers/CacheManager.d.ts.map +1 -0
- package/dist/utils/helpers/CacheManager.js +222 -0
- package/dist/utils/helpers/CacheManager.js.map +1 -0
- package/dist/utils/helpers/CompressionUtils.d.ts +80 -0
- package/dist/utils/helpers/CompressionUtils.d.ts.map +1 -0
- package/dist/utils/helpers/CompressionUtils.js +224 -0
- package/dist/utils/helpers/CompressionUtils.js.map +1 -0
- package/dist/utils/helpers/CryptoUtils.d.ts +70 -0
- package/dist/utils/helpers/CryptoUtils.d.ts.map +1 -0
- package/dist/utils/helpers/CryptoUtils.js +215 -0
- package/dist/utils/helpers/CryptoUtils.js.map +1 -0
- package/dist/utils/helpers/DateUtils.d.ts +31 -0
- package/dist/utils/helpers/DateUtils.d.ts.map +1 -0
- package/dist/utils/helpers/DateUtils.js +104 -0
- package/dist/utils/helpers/DateUtils.js.map +1 -0
- package/dist/utils/helpers/DiffUtils.d.ts +61 -0
- package/dist/utils/helpers/DiffUtils.d.ts.map +1 -0
- package/dist/utils/helpers/DiffUtils.js +249 -0
- package/dist/utils/helpers/DiffUtils.js.map +1 -0
- package/dist/utils/helpers/EnvManager.d.ts +7 -0
- package/dist/utils/helpers/EnvManager.d.ts.map +1 -0
- package/dist/utils/helpers/EnvManager.js +19 -0
- package/dist/utils/helpers/EnvManager.js.map +1 -0
- package/dist/utils/helpers/EventEmitter.d.ts +78 -0
- package/dist/utils/helpers/EventEmitter.d.ts.map +1 -0
- package/dist/utils/helpers/EventEmitter.js +208 -0
- package/dist/utils/helpers/EventEmitter.js.map +1 -0
- package/dist/utils/helpers/FileUploadHelper.d.ts +44 -0
- package/dist/utils/helpers/FileUploadHelper.d.ts.map +1 -0
- package/dist/utils/helpers/FileUploadHelper.js +127 -0
- package/dist/utils/helpers/FileUploadHelper.js.map +1 -0
- package/dist/utils/helpers/FormUtils.d.ts +162 -0
- package/dist/utils/helpers/FormUtils.d.ts.map +1 -0
- package/dist/utils/helpers/FormUtils.js +378 -0
- package/dist/utils/helpers/FormUtils.js.map +1 -0
- package/dist/utils/helpers/ObjectUtils.d.ts +102 -0
- package/dist/utils/helpers/ObjectUtils.d.ts.map +1 -0
- package/dist/utils/helpers/ObjectUtils.js +297 -0
- package/dist/utils/helpers/ObjectUtils.js.map +1 -0
- package/dist/utils/helpers/PaginationHelper.d.ts +127 -0
- package/dist/utils/helpers/PaginationHelper.d.ts.map +1 -0
- package/dist/utils/helpers/PaginationHelper.js +259 -0
- package/dist/utils/helpers/PaginationHelper.js.map +1 -0
- package/dist/utils/helpers/PollingHelper.d.ts +64 -0
- package/dist/utils/helpers/PollingHelper.d.ts.map +1 -0
- package/dist/utils/helpers/PollingHelper.js +131 -0
- package/dist/utils/helpers/PollingHelper.js.map +1 -0
- package/dist/utils/helpers/StorageUtils.d.ts +9 -0
- package/dist/utils/helpers/StorageUtils.d.ts.map +1 -0
- package/dist/utils/helpers/StorageUtils.js +33 -0
- package/dist/utils/helpers/StorageUtils.js.map +1 -0
- package/dist/utils/helpers/StreamingHelper.d.ts +35 -0
- package/dist/utils/helpers/StreamingHelper.d.ts.map +1 -0
- package/dist/utils/helpers/StreamingHelper.js +167 -0
- package/dist/utils/helpers/StreamingHelper.js.map +1 -0
- package/dist/utils/helpers/StringUtils.d.ts +42 -0
- package/dist/utils/helpers/StringUtils.d.ts.map +1 -0
- package/dist/utils/helpers/StringUtils.js +173 -0
- package/dist/utils/helpers/StringUtils.js.map +1 -0
- package/dist/utils/helpers/TimeUtils.d.ts +87 -0
- package/dist/utils/helpers/TimeUtils.d.ts.map +1 -0
- package/dist/utils/helpers/TimeUtils.js +234 -0
- package/dist/utils/helpers/TimeUtils.js.map +1 -0
- package/dist/utils/helpers/Validator.d.ts +31 -0
- package/dist/utils/helpers/Validator.d.ts.map +1 -0
- package/dist/utils/helpers/Validator.js +156 -0
- package/dist/utils/helpers/Validator.js.map +1 -0
- package/dist/utils/helpers/WebSocketHelper.d.ts +63 -0
- package/dist/utils/helpers/WebSocketHelper.d.ts.map +1 -0
- package/dist/utils/helpers/WebSocketHelper.js +200 -0
- package/dist/utils/helpers/WebSocketHelper.js.map +1 -0
- package/dist/utils/helpers/index.d.ts +20 -0
- package/dist/utils/helpers/index.d.ts.map +1 -0
- package/dist/utils/helpers/index.js +20 -0
- package/dist/utils/helpers/index.js.map +1 -0
- package/dist/utils/index.d.ts +21 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +21 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/validator.d.ts +2 -0
- package/dist/validator.d.ts.map +1 -0
- package/dist/validator.js +2 -0
- package/dist/validator.js.map +1 -0
- package/dist/websocket.d.ts +2 -0
- package/dist/websocket.d.ts.map +1 -0
- package/dist/websocket.js +2 -0
- package/dist/websocket.js.map +1 -0
- package/package.json +189 -0
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compression utilities for data compression and encoding
|
|
3
|
+
* Isomorphic compression for Node.js and browsers
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Compression utilities
|
|
7
|
+
*/
|
|
8
|
+
export declare class CompressionUtils {
|
|
9
|
+
/**
|
|
10
|
+
* Compress string using LZ-like algorithm (simple)
|
|
11
|
+
* For production, use proper compression libraries
|
|
12
|
+
*/
|
|
13
|
+
static compress(str: string): string;
|
|
14
|
+
/**
|
|
15
|
+
* Decompress string
|
|
16
|
+
*/
|
|
17
|
+
static decompress(compressed: string): string;
|
|
18
|
+
/**
|
|
19
|
+
* Base64 encode
|
|
20
|
+
*/
|
|
21
|
+
static base64Encode(str: string): string;
|
|
22
|
+
/**
|
|
23
|
+
* Base64 decode
|
|
24
|
+
*/
|
|
25
|
+
static base64Decode(str: string): string;
|
|
26
|
+
/**
|
|
27
|
+
* URL-safe base64 encode
|
|
28
|
+
*/
|
|
29
|
+
static base64UrlEncode(str: string): string;
|
|
30
|
+
/**
|
|
31
|
+
* URL-safe base64 decode
|
|
32
|
+
*/
|
|
33
|
+
static base64UrlDecode(str: string): string;
|
|
34
|
+
/**
|
|
35
|
+
* Serialize object to compressed JSON
|
|
36
|
+
*/
|
|
37
|
+
static serializeCompressed(obj: unknown): string;
|
|
38
|
+
/**
|
|
39
|
+
* Deserialize compressed JSON
|
|
40
|
+
*/
|
|
41
|
+
static deserializeCompressed(compressed: string): unknown;
|
|
42
|
+
/**
|
|
43
|
+
* Calculate compression ratio (0-100, where 100 is best compression)
|
|
44
|
+
* Returns 0 if compressed is larger than original
|
|
45
|
+
*/
|
|
46
|
+
static getCompressionRatio(original: string, compressed: string): number;
|
|
47
|
+
/**
|
|
48
|
+
* Minify JSON (remove whitespace)
|
|
49
|
+
*/
|
|
50
|
+
static minifyJSON(json: string): string;
|
|
51
|
+
/**
|
|
52
|
+
* Pretty print JSON
|
|
53
|
+
*/
|
|
54
|
+
static prettyJSON(json: string, indent?: number): string;
|
|
55
|
+
/**
|
|
56
|
+
* Gzip compress (Node.js only)
|
|
57
|
+
*/
|
|
58
|
+
static gzip(str: string): Promise<Buffer | string>;
|
|
59
|
+
/**
|
|
60
|
+
* Gzip decompress (Node.js only)
|
|
61
|
+
*/
|
|
62
|
+
static gunzip(data: Buffer | string): Promise<string>;
|
|
63
|
+
/**
|
|
64
|
+
* Deflate compress (Node.js only)
|
|
65
|
+
*/
|
|
66
|
+
static deflate(str: string): Promise<Buffer | string>;
|
|
67
|
+
/**
|
|
68
|
+
* Inflate decompress (Node.js only)
|
|
69
|
+
*/
|
|
70
|
+
static inflate(data: Buffer | string): Promise<string>;
|
|
71
|
+
/**
|
|
72
|
+
* Get size in bytes
|
|
73
|
+
*/
|
|
74
|
+
static getSize(str: string): number;
|
|
75
|
+
/**
|
|
76
|
+
* Format bytes to human readable
|
|
77
|
+
*/
|
|
78
|
+
static formatBytes(bytes: number, decimals?: number): string;
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=CompressionUtils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CompressionUtils.d.ts","sourceRoot":"","sources":["../../../src/utils/helpers/CompressionUtils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,qBAAa,gBAAgB;IACzB;;;OAGG;IACH,MAAM,CAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IAoBpC;;OAEG;IACH,MAAM,CAAC,UAAU,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM;IA0B7C;;OAEG;IACH,MAAM,CAAC,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IAQxC;;OAEG;IACH,MAAM,CAAC,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IAQxC;;OAEG;IACH,MAAM,CAAC,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IAO3C;;OAEG;IACH,MAAM,CAAC,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IAK3C;;OAEG;IACH,MAAM,CAAC,mBAAmB,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM;IAKhD;;OAEG;IACH,MAAM,CAAC,qBAAqB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO;IAKzD;;;OAGG;IACH,MAAM,CAAC,mBAAmB,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM;IAKxE;;OAEG;IACH,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAIvC;;OAEG;IACH,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,GAAE,MAAU,GAAG,MAAM;IAS3D;;OAEG;WACU,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC;IAYxD;;OAEG;WACU,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAgB3D;;OAEG;WACU,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC;IAW3D;;OAEG;WACU,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAe5D;;OAEG;IACH,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IAQnC;;OAEG;IACH,MAAM,CAAC,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,GAAE,MAAU,GAAG,MAAM;CAYlE"}
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compression utilities for data compression and encoding
|
|
3
|
+
* Isomorphic compression for Node.js and browsers
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Compression utilities
|
|
7
|
+
*/
|
|
8
|
+
export class CompressionUtils {
|
|
9
|
+
/**
|
|
10
|
+
* Compress string using LZ-like algorithm (simple)
|
|
11
|
+
* For production, use proper compression libraries
|
|
12
|
+
*/
|
|
13
|
+
static compress(str) {
|
|
14
|
+
let compressed = "";
|
|
15
|
+
let count = 1;
|
|
16
|
+
for (let i = 0; i < str.length; i++) {
|
|
17
|
+
if (str[i] === str[i + 1]) {
|
|
18
|
+
count++;
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
if (count > 1) {
|
|
22
|
+
compressed += count + str[i];
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
compressed += str[i];
|
|
26
|
+
}
|
|
27
|
+
count = 1;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return this.base64Encode(compressed);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Decompress string
|
|
34
|
+
*/
|
|
35
|
+
static decompress(compressed) {
|
|
36
|
+
const str = this.base64Decode(compressed);
|
|
37
|
+
let decompressed = "";
|
|
38
|
+
let i = 0;
|
|
39
|
+
while (i < str.length) {
|
|
40
|
+
const char = str[i];
|
|
41
|
+
if (/\d/.test(char)) {
|
|
42
|
+
let num = "";
|
|
43
|
+
while (i < str.length && /\d/.test(str[i])) {
|
|
44
|
+
num += str[i];
|
|
45
|
+
i++;
|
|
46
|
+
}
|
|
47
|
+
const count = parseInt(num, 10);
|
|
48
|
+
const char = str[i];
|
|
49
|
+
decompressed += char.repeat(count);
|
|
50
|
+
i++;
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
decompressed += char;
|
|
54
|
+
i++;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return decompressed;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Base64 encode
|
|
61
|
+
*/
|
|
62
|
+
static base64Encode(str) {
|
|
63
|
+
if (typeof globalThis !== "undefined" && globalThis.btoa) {
|
|
64
|
+
return globalThis.btoa(str);
|
|
65
|
+
}
|
|
66
|
+
// Node.js fallback
|
|
67
|
+
return Buffer.from(str, "utf-8").toString("base64");
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Base64 decode
|
|
71
|
+
*/
|
|
72
|
+
static base64Decode(str) {
|
|
73
|
+
if (typeof globalThis !== "undefined" && globalThis.atob) {
|
|
74
|
+
return globalThis.atob(str);
|
|
75
|
+
}
|
|
76
|
+
// Node.js fallback
|
|
77
|
+
return Buffer.from(str, "base64").toString("utf-8");
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* URL-safe base64 encode
|
|
81
|
+
*/
|
|
82
|
+
static base64UrlEncode(str) {
|
|
83
|
+
return this.base64Encode(str)
|
|
84
|
+
.replace(/\+/g, "-")
|
|
85
|
+
.replace(/\//g, "_")
|
|
86
|
+
.replace(/=/g, "");
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* URL-safe base64 decode
|
|
90
|
+
*/
|
|
91
|
+
static base64UrlDecode(str) {
|
|
92
|
+
const padded = str + "=".repeat((4 - (str.length % 4)) % 4);
|
|
93
|
+
return this.base64Decode(padded.replace(/-/g, "+").replace(/_/g, "/"));
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Serialize object to compressed JSON
|
|
97
|
+
*/
|
|
98
|
+
static serializeCompressed(obj) {
|
|
99
|
+
const json = JSON.stringify(obj);
|
|
100
|
+
return this.compress(json);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Deserialize compressed JSON
|
|
104
|
+
*/
|
|
105
|
+
static deserializeCompressed(compressed) {
|
|
106
|
+
const json = this.decompress(compressed);
|
|
107
|
+
return JSON.parse(json);
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Calculate compression ratio (0-100, where 100 is best compression)
|
|
111
|
+
* Returns 0 if compressed is larger than original
|
|
112
|
+
*/
|
|
113
|
+
static getCompressionRatio(original, compressed) {
|
|
114
|
+
const ratio = (1 - compressed.length / original.length) * 100;
|
|
115
|
+
return Math.max(0, ratio);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Minify JSON (remove whitespace)
|
|
119
|
+
*/
|
|
120
|
+
static minifyJSON(json) {
|
|
121
|
+
return json.replace(/\s+/g, " ").trim();
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Pretty print JSON
|
|
125
|
+
*/
|
|
126
|
+
static prettyJSON(json, indent = 2) {
|
|
127
|
+
try {
|
|
128
|
+
const obj = typeof json === "string" ? JSON.parse(json) : json;
|
|
129
|
+
return JSON.stringify(obj, null, indent);
|
|
130
|
+
}
|
|
131
|
+
catch {
|
|
132
|
+
return json;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Gzip compress (Node.js only)
|
|
137
|
+
*/
|
|
138
|
+
static async gzip(str) {
|
|
139
|
+
try {
|
|
140
|
+
const zlib = await import("zlib");
|
|
141
|
+
const util = await import("util");
|
|
142
|
+
const gzip = util.promisify(zlib.gzip);
|
|
143
|
+
return await gzip(str);
|
|
144
|
+
}
|
|
145
|
+
catch {
|
|
146
|
+
// Fallback to simple compression
|
|
147
|
+
return this.compress(str);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Gzip decompress (Node.js only)
|
|
152
|
+
*/
|
|
153
|
+
static async gunzip(data) {
|
|
154
|
+
try {
|
|
155
|
+
const zlib = await import("zlib");
|
|
156
|
+
const util = await import("util");
|
|
157
|
+
const gunzip = util.promisify(zlib.gunzip);
|
|
158
|
+
const result = await gunzip(data);
|
|
159
|
+
return result.toString();
|
|
160
|
+
}
|
|
161
|
+
catch {
|
|
162
|
+
// Fallback to simple decompression
|
|
163
|
+
if (typeof data === "string") {
|
|
164
|
+
return this.decompress(data);
|
|
165
|
+
}
|
|
166
|
+
return data.toString();
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Deflate compress (Node.js only)
|
|
171
|
+
*/
|
|
172
|
+
static async deflate(str) {
|
|
173
|
+
try {
|
|
174
|
+
const zlib = await import("zlib");
|
|
175
|
+
const util = await import("util");
|
|
176
|
+
const deflate = util.promisify(zlib.deflate);
|
|
177
|
+
return await deflate(str);
|
|
178
|
+
}
|
|
179
|
+
catch {
|
|
180
|
+
return this.compress(str);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Inflate decompress (Node.js only)
|
|
185
|
+
*/
|
|
186
|
+
static async inflate(data) {
|
|
187
|
+
try {
|
|
188
|
+
const zlib = await import("zlib");
|
|
189
|
+
const util = await import("util");
|
|
190
|
+
const inflate = util.promisify(zlib.inflate);
|
|
191
|
+
const result = await inflate(data);
|
|
192
|
+
return result.toString();
|
|
193
|
+
}
|
|
194
|
+
catch {
|
|
195
|
+
if (typeof data === "string") {
|
|
196
|
+
return this.decompress(data);
|
|
197
|
+
}
|
|
198
|
+
return data.toString();
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Get size in bytes
|
|
203
|
+
*/
|
|
204
|
+
static getSize(str) {
|
|
205
|
+
if (typeof globalThis !== "undefined" && globalThis.Blob) {
|
|
206
|
+
return new Blob([str]).size;
|
|
207
|
+
}
|
|
208
|
+
// Node.js fallback
|
|
209
|
+
return Buffer.byteLength(str, "utf-8");
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Format bytes to human readable
|
|
213
|
+
*/
|
|
214
|
+
static formatBytes(bytes, decimals = 2) {
|
|
215
|
+
if (bytes === 0)
|
|
216
|
+
return "0 Bytes";
|
|
217
|
+
const k = 1024;
|
|
218
|
+
const dm = decimals < 0 ? 0 : decimals;
|
|
219
|
+
const sizes = ["Bytes", "KB", "MB", "GB"];
|
|
220
|
+
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
221
|
+
return (parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + " " + sizes[i]);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
//# sourceMappingURL=CompressionUtils.js.map
|
|
@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D,OAAO,IAAI,CAAC,QAAQ,EAAE,CAAC;QAC3B,CAAC;IACL,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,OAAO,CAAC,GAAW;QACtB,IAAI,OAAO,UAAU,KAAK,WAAW,IAAI,UAAU,CAAC,IAAI,EAAE,CAAC;YACvD,OAAO,IAAI,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC;QAChC,CAAC;QACD,mBAAmB;QACnB,OAAO,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IAC3C,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,WAAW,CAAC,KAAa,EAAE,WAAmB,CAAC;QAClD,IAAI,KAAK,KAAK,CAAC;YAAE,OAAO,SAAS,CAAC;QAElC,MAAM,CAAC,GAAG,IAAI,CAAC;QACf,MAAM,EAAE,GAAG,QAAQ,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;QACvC,MAAM,KAAK,GAAG,CAAC,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;QAC1C,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QAEpD,OAAO,CACH,UAAU,CAAC,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,GAAG,GAAG,GAAG,KAAK,CAAC,CAAC,CAAC,CACpE,CAAC;IACN,CAAC;CACJ"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cryptographic utilities for hashing, encoding, and token generation
|
|
3
|
+
* Isomorphic crypto operations for Node.js and browsers
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Crypto utilities
|
|
7
|
+
*/
|
|
8
|
+
export declare class CryptoUtils {
|
|
9
|
+
/**
|
|
10
|
+
* Generate random token (hex string)
|
|
11
|
+
*/
|
|
12
|
+
static generateToken(length?: number): string;
|
|
13
|
+
/**
|
|
14
|
+
* Generate random UUID v4
|
|
15
|
+
*/
|
|
16
|
+
static generateUUID(): string;
|
|
17
|
+
/**
|
|
18
|
+
* Base64 encode
|
|
19
|
+
*/
|
|
20
|
+
static base64Encode(str: string): string;
|
|
21
|
+
/**
|
|
22
|
+
* Base64 decode
|
|
23
|
+
*/
|
|
24
|
+
static base64Decode(str: string): string;
|
|
25
|
+
/**
|
|
26
|
+
* URL-safe base64 encode
|
|
27
|
+
*/
|
|
28
|
+
static base64UrlEncode(str: string): string;
|
|
29
|
+
/**
|
|
30
|
+
* URL-safe base64 decode
|
|
31
|
+
*/
|
|
32
|
+
static base64UrlDecode(str: string): string;
|
|
33
|
+
/**
|
|
34
|
+
* Simple hash using string manipulation (not cryptographic)
|
|
35
|
+
* For actual hashing, use SubtleCrypto or Node.js crypto
|
|
36
|
+
*/
|
|
37
|
+
static simpleHash(str: string): string;
|
|
38
|
+
/**
|
|
39
|
+
* Hash string using SubtleCrypto (browser) or crypto (Node.js)
|
|
40
|
+
*/
|
|
41
|
+
static hash(str: string, algorithm?: "SHA-1" | "SHA-256" | "SHA-384" | "SHA-512"): Promise<string>;
|
|
42
|
+
/**
|
|
43
|
+
* Create HMAC signature
|
|
44
|
+
*/
|
|
45
|
+
static hmac(message: string, secret: string, algorithm?: "SHA-256" | "SHA-512"): Promise<string>;
|
|
46
|
+
/**
|
|
47
|
+
* Check if string matches hash
|
|
48
|
+
*/
|
|
49
|
+
static verifyHash(str: string, hash: string, algorithm?: "SHA-1" | "SHA-256" | "SHA-384" | "SHA-512"): Promise<boolean>;
|
|
50
|
+
/**
|
|
51
|
+
* Encrypt string (simple XOR - NOT for production)
|
|
52
|
+
* For production, use proper encryption libraries like TweetNaCl or libsodium
|
|
53
|
+
* @deprecated XOR encryption is NOT cryptographically secure. Use proper encryption libraries.
|
|
54
|
+
*/
|
|
55
|
+
static xorEncrypt(str: string, key: string): string;
|
|
56
|
+
/**
|
|
57
|
+
* Decrypt string (simple XOR - NOT for production)
|
|
58
|
+
* @deprecated XOR encryption is NOT cryptographically secure. Use proper encryption libraries.
|
|
59
|
+
*/
|
|
60
|
+
static xorDecrypt(encrypted: string, key: string): string;
|
|
61
|
+
/**
|
|
62
|
+
* Generate random bytes
|
|
63
|
+
*/
|
|
64
|
+
static randomBytes(length: number): Uint8Array;
|
|
65
|
+
/**
|
|
66
|
+
* Constant-time string comparison (prevents timing attacks)
|
|
67
|
+
*/
|
|
68
|
+
static constantTimeCompare(a: string, b: string): boolean;
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=CryptoUtils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CryptoUtils.d.ts","sourceRoot":"","sources":["../../../src/utils/helpers/CryptoUtils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,qBAAa,WAAW;IACpB;;OAEG;IACH,MAAM,CAAC,aAAa,CAAC,MAAM,GAAE,MAAW,GAAG,MAAM;IAejD;;OAEG;IACH,MAAM,CAAC,YAAY,IAAI,MAAM;IAyB7B;;OAEG;IACH,MAAM,CAAC,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IAQxC;;OAEG;IACH,MAAM,CAAC,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IAQxC;;OAEG;IACH,MAAM,CAAC,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IAO3C;;OAEG;IACH,MAAM,CAAC,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IAK3C;;;OAGG;IACH,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IAUtC;;OAEG;WACU,IAAI,CACb,GAAG,EAAE,MAAM,EACX,SAAS,GAAE,OAAO,GAAG,SAAS,GAAG,SAAS,GAAG,SAAqB,GACnE,OAAO,CAAC,MAAM,CAAC;IA6BlB;;OAEG;WACU,IAAI,CACb,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,SAAS,GAAE,SAAS,GAAG,SAAqB,GAC7C,OAAO,CAAC,MAAM,CAAC;IAoClB;;OAEG;WACU,UAAU,CACnB,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,EACZ,SAAS,GAAE,OAAO,GAAG,SAAS,GAAG,SAAS,GAAG,SAAqB,GACnE,OAAO,CAAC,OAAO,CAAC;IAKnB;;;;OAIG;IACH,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM;IAanD;;;OAGG;IACH,MAAM,CAAC,UAAU,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM;IAczD;;OAEG;IACH,MAAM,CAAC,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU;IAY9C;;OAEG;IACH,MAAM,CAAC,mBAAmB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO;CAQ5D"}
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cryptographic utilities for hashing, encoding, and token generation
|
|
3
|
+
* Isomorphic crypto operations for Node.js and browsers
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Crypto utilities
|
|
7
|
+
*/
|
|
8
|
+
export class CryptoUtils {
|
|
9
|
+
/**
|
|
10
|
+
* Generate random token (hex string)
|
|
11
|
+
*/
|
|
12
|
+
static generateToken(length = 32) {
|
|
13
|
+
const bytes = new Uint8Array(length);
|
|
14
|
+
if (typeof globalThis !== "undefined" && globalThis.crypto) {
|
|
15
|
+
globalThis.crypto.getRandomValues(bytes);
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
// Fallback for environments without crypto
|
|
19
|
+
for (let i = 0; i < length; i++) {
|
|
20
|
+
bytes[i] = Math.floor(Math.random() * 256);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return Array.from(bytes)
|
|
24
|
+
.map((b) => b.toString(16).padStart(2, "0"))
|
|
25
|
+
.join("");
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Generate random UUID v4
|
|
29
|
+
*/
|
|
30
|
+
static generateUUID() {
|
|
31
|
+
if (typeof globalThis !== "undefined" &&
|
|
32
|
+
globalThis.crypto?.randomUUID) {
|
|
33
|
+
return globalThis.crypto.randomUUID();
|
|
34
|
+
}
|
|
35
|
+
// Fallback implementation
|
|
36
|
+
const chars = "0123456789abcdef";
|
|
37
|
+
let uuid = "";
|
|
38
|
+
for (let i = 0; i < 36; i++) {
|
|
39
|
+
if (i === 8 || i === 13 || i === 18 || i === 23) {
|
|
40
|
+
uuid += "-";
|
|
41
|
+
}
|
|
42
|
+
else if (i === 14) {
|
|
43
|
+
uuid += "4";
|
|
44
|
+
}
|
|
45
|
+
else if (i === 19) {
|
|
46
|
+
uuid += chars[(Math.random() * 4) | 8];
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
uuid += chars[Math.floor(Math.random() * 16)];
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return uuid;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Base64 encode
|
|
56
|
+
*/
|
|
57
|
+
static base64Encode(str) {
|
|
58
|
+
if (typeof globalThis !== "undefined" && globalThis.btoa) {
|
|
59
|
+
return globalThis.btoa(str);
|
|
60
|
+
}
|
|
61
|
+
// Node.js fallback
|
|
62
|
+
return Buffer.from(str, "utf-8").toString("base64");
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Base64 decode
|
|
66
|
+
*/
|
|
67
|
+
static base64Decode(str) {
|
|
68
|
+
if (typeof globalThis !== "undefined" && globalThis.atob) {
|
|
69
|
+
return globalThis.atob(str);
|
|
70
|
+
}
|
|
71
|
+
// Node.js fallback
|
|
72
|
+
return Buffer.from(str, "base64").toString("utf-8");
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* URL-safe base64 encode
|
|
76
|
+
*/
|
|
77
|
+
static base64UrlEncode(str) {
|
|
78
|
+
return this.base64Encode(str)
|
|
79
|
+
.replace(/\+/g, "-")
|
|
80
|
+
.replace(/\//g, "_")
|
|
81
|
+
.replace(/=/g, "");
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* URL-safe base64 decode
|
|
85
|
+
*/
|
|
86
|
+
static base64UrlDecode(str) {
|
|
87
|
+
const padded = str + "=".repeat((4 - (str.length % 4)) % 4);
|
|
88
|
+
return this.base64Decode(padded.replace(/-/g, "+").replace(/_/g, "/"));
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Simple hash using string manipulation (not cryptographic)
|
|
92
|
+
* For actual hashing, use SubtleCrypto or Node.js crypto
|
|
93
|
+
*/
|
|
94
|
+
static simpleHash(str) {
|
|
95
|
+
let hash = 0;
|
|
96
|
+
for (let i = 0; i < str.length; i++) {
|
|
97
|
+
const char = str.charCodeAt(i);
|
|
98
|
+
hash = (hash << 5) - hash + char;
|
|
99
|
+
hash = hash & hash; // Convert to 32bit integer
|
|
100
|
+
}
|
|
101
|
+
return Math.abs(hash).toString(16);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Hash string using SubtleCrypto (browser) or crypto (Node.js)
|
|
105
|
+
*/
|
|
106
|
+
static async hash(str, algorithm = "SHA-256") {
|
|
107
|
+
if (typeof globalThis !== "undefined" && globalThis.crypto?.subtle) {
|
|
108
|
+
// Browser
|
|
109
|
+
const encoder = new TextEncoder();
|
|
110
|
+
const data = encoder.encode(str);
|
|
111
|
+
const hashBuffer = await globalThis.crypto.subtle.digest(algorithm, data);
|
|
112
|
+
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
113
|
+
return hashArray
|
|
114
|
+
.map((b) => b.toString(16).padStart(2, "0"))
|
|
115
|
+
.join("");
|
|
116
|
+
}
|
|
117
|
+
// Node.js fallback
|
|
118
|
+
try {
|
|
119
|
+
const crypto = await import("crypto");
|
|
120
|
+
const hash = crypto.createHash(algorithm.toLowerCase().replace("-", ""));
|
|
121
|
+
hash.update(str);
|
|
122
|
+
return hash.digest("hex");
|
|
123
|
+
}
|
|
124
|
+
catch {
|
|
125
|
+
// Fallback to simple hash
|
|
126
|
+
return this.simpleHash(str);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Create HMAC signature
|
|
131
|
+
*/
|
|
132
|
+
static async hmac(message, secret, algorithm = "SHA-256") {
|
|
133
|
+
if (typeof globalThis !== "undefined" && globalThis.crypto?.subtle) {
|
|
134
|
+
// Browser
|
|
135
|
+
const encoder = new TextEncoder();
|
|
136
|
+
const key = await globalThis.crypto.subtle.importKey("raw", encoder.encode(secret), { name: "HMAC", hash: algorithm }, false, ["sign"]);
|
|
137
|
+
const signature = await globalThis.crypto.subtle.sign("HMAC", key, encoder.encode(message));
|
|
138
|
+
const signatureArray = Array.from(new Uint8Array(signature));
|
|
139
|
+
return signatureArray
|
|
140
|
+
.map((b) => b.toString(16).padStart(2, "0"))
|
|
141
|
+
.join("");
|
|
142
|
+
}
|
|
143
|
+
// Node.js fallback
|
|
144
|
+
try {
|
|
145
|
+
const crypto = await import("crypto");
|
|
146
|
+
const hmac = crypto.createHmac(algorithm.toLowerCase().replace("-", ""), secret);
|
|
147
|
+
hmac.update(message);
|
|
148
|
+
return hmac.digest("hex");
|
|
149
|
+
}
|
|
150
|
+
catch {
|
|
151
|
+
return "";
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Check if string matches hash
|
|
156
|
+
*/
|
|
157
|
+
static async verifyHash(str, hash, algorithm = "SHA-256") {
|
|
158
|
+
const computed = await this.hash(str, algorithm);
|
|
159
|
+
return computed === hash;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Encrypt string (simple XOR - NOT for production)
|
|
163
|
+
* For production, use proper encryption libraries like TweetNaCl or libsodium
|
|
164
|
+
* @deprecated XOR encryption is NOT cryptographically secure. Use proper encryption libraries.
|
|
165
|
+
*/
|
|
166
|
+
static xorEncrypt(str, key) {
|
|
167
|
+
console.warn("WARNING: XOR encryption is not cryptographically secure. Use proper encryption libraries like TweetNaCl or libsodium.");
|
|
168
|
+
let result = "";
|
|
169
|
+
for (let i = 0; i < str.length; i++) {
|
|
170
|
+
result += String.fromCharCode(str.charCodeAt(i) ^ key.charCodeAt(i % key.length));
|
|
171
|
+
}
|
|
172
|
+
return this.base64Encode(result);
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Decrypt string (simple XOR - NOT for production)
|
|
176
|
+
* @deprecated XOR encryption is NOT cryptographically secure. Use proper encryption libraries.
|
|
177
|
+
*/
|
|
178
|
+
static xorDecrypt(encrypted, key) {
|
|
179
|
+
console.warn("WARNING: XOR encryption is not cryptographically secure. Use proper encryption libraries like TweetNaCl or libsodium.");
|
|
180
|
+
const str = this.base64Decode(encrypted);
|
|
181
|
+
let result = "";
|
|
182
|
+
for (let i = 0; i < str.length; i++) {
|
|
183
|
+
result += String.fromCharCode(str.charCodeAt(i) ^ key.charCodeAt(i % key.length));
|
|
184
|
+
}
|
|
185
|
+
return result;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Generate random bytes
|
|
189
|
+
*/
|
|
190
|
+
static randomBytes(length) {
|
|
191
|
+
const bytes = new Uint8Array(length);
|
|
192
|
+
if (typeof globalThis !== "undefined" && globalThis.crypto) {
|
|
193
|
+
globalThis.crypto.getRandomValues(bytes);
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
for (let i = 0; i < length; i++) {
|
|
197
|
+
bytes[i] = Math.floor(Math.random() * 256);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return bytes;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Constant-time string comparison (prevents timing attacks)
|
|
204
|
+
*/
|
|
205
|
+
static constantTimeCompare(a, b) {
|
|
206
|
+
if (a.length !== b.length)
|
|
207
|
+
return false;
|
|
208
|
+
let result = 0;
|
|
209
|
+
for (let i = 0; i < a.length; i++) {
|
|
210
|
+
result |= a.charCodeAt(i) ^ b.charCodeAt(i);
|
|
211
|
+
}
|
|
212
|
+
return result === 0;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
//# sourceMappingURL=CryptoUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CryptoUtils.js","sourceRoot":"","sources":["../../../src/utils/helpers/CryptoUtils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,MAAM,OAAO,WAAW;IACpB;;OAEG;IACH,MAAM,CAAC,aAAa,CAAC,SAAiB,EAAE;QACpC,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC;QACrC,IAAI,OAAO,UAAU,KAAK,WAAW,IAAI,UAAU,CAAC,MAAM,EAAE,CAAC;YACzD,UAAU,CAAC,MAAM,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;QAC7C,CAAC;aAAM,CAAC;YACJ,2CAA2C;YAC3C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;gBAC9B,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,GAAG,CAAC,CAAC;YAC/C,CAAC;QACL,CAAC;QACD,OAAO,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC;aACnB,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;aAC3C,IAAI,CAAC,EAAE,CAAC,CAA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nit = "milliseconds" | "seconds" | "minutes" | "hours" | "days";
|
|
3
|
+
export type RoundingMode = "floor" | "ceil" | "round" | "trunc";
|
|
4
|
+
export interface DiffOptions {
|
|
5
|
+
unit?: DiffUnit;
|
|
6
|
+
absolute?: boolean;
|
|
7
|
+
rounding?: RoundingMode;
|
|
8
|
+
}
|
|
9
|
+
export interface AddDurationOptions {
|
|
10
|
+
days?: number;
|
|
11
|
+
hours?: number;
|
|
12
|
+
minutes?: number;
|
|
13
|
+
seconds?: number;
|
|
14
|
+
milliseconds?: number;
|
|
15
|
+
}
|
|
16
|
+
export declare const DateUtils: {
|
|
17
|
+
parse(value: DateInput): Date | null;
|
|
18
|
+
isValid(value: DateInput): boolean;
|
|
19
|
+
toISODate(value: DateInput): string;
|
|
20
|
+
startOfDay(value: DateInput): Date;
|
|
21
|
+
endOfDay(value: DateInput): Date;
|
|
22
|
+
add(value: DateInput, duration?: AddDurationOptions): Date;
|
|
23
|
+
diff(a: DateInput, b: DateInput, options?: DiffOptions): number;
|
|
24
|
+
diffInDays(a: DateInput, b: DateInput, options?: Omit<DiffOptions, "unit">): number;
|
|
25
|
+
isSameDay(a: DateInput, b: DateInput): boolean;
|
|
26
|
+
isBefore(a: DateInput, b: DateInput): boolean;
|
|
27
|
+
isAfter(a: DateInput, b: DateInput): boolean;
|
|
28
|
+
format(date: Date, locale?: string): string;
|
|
29
|
+
};
|
|
30
|
+
export {};
|
|
31
|
+
//# sourceMappingURL=DateUtils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DateUtils.d.ts","sourceRoot":"","sources":["../../../src/utils/helpers/DateUtils.ts"],"names":[],"mappings":"AAAA,KAAK,SAAS,GAAG,IAAI,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;AAE3D,MAAM,MAAM,QAAQ,GACd,cAAc,GACd,SAAS,GACT,SAAS,GACT,OAAO,GACP,MAAM,CAAC;AAEb,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,CAAC;AAEhE,MAAM,WAAW,WAAW;IACxB,IAAI,CAAC,EAAE,QAAQ,CAAC;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,YAAY,CAAC;CAC3B;AAED,MAAM,WAAW,kBAAkB;IAC/B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;CACzB;AAmDD,eAAO,MAAM,SAAS;iBACL,SAAS;mBAIP,SAAS;qBAIP,SAAS;sBAOR,SAAS;oBAMX,SAAS;eAMd,SAAS,aAAY,kBAAkB;YAO1C,SAAS,KAAK,SAAS,YAAW,WAAW;kBAY9C,SAAS,KACT,SAAS,YACH,IAAI,CAAC,WAAW,EAAE,MAAM,CAAC;iBAUzB,SAAS,KAAK,SAAS;gBAUxB,SAAS,KAAK,SAAS;eAIxB,SAAS,KAAK,SAAS;iBAIrB,IAAI,oBAAqB,MAAM;CAO/C,CAAC"}
|