@arcis/node 1.3.0 → 1.4.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.
Files changed (118) hide show
  1. package/dist/core/{index.d.mts → constants.d.ts} +21 -70
  2. package/dist/core/constants.d.ts.map +1 -0
  3. package/dist/core/errors.d.ts +53 -0
  4. package/dist/core/errors.d.ts.map +1 -0
  5. package/dist/core/index.d.ts +6 -168
  6. package/dist/core/index.d.ts.map +1 -0
  7. package/dist/{types-BOkx5YJc.d.mts → core/types.d.ts} +27 -30
  8. package/dist/core/types.d.ts.map +1 -0
  9. package/dist/index.d.ts +71 -166
  10. package/dist/index.d.ts.map +1 -0
  11. package/dist/index.js +57 -2
  12. package/dist/index.js.map +1 -1
  13. package/dist/index.mjs +56 -3
  14. package/dist/index.mjs.map +1 -1
  15. package/dist/logging/index.d.ts +4 -36
  16. package/dist/logging/index.d.ts.map +1 -0
  17. package/dist/logging/{index.d.mts → redactor.d.ts} +5 -9
  18. package/dist/logging/redactor.d.ts.map +1 -0
  19. package/dist/middleware/bot-detection.d.ts +86 -0
  20. package/dist/middleware/bot-detection.d.ts.map +1 -0
  21. package/dist/middleware/cookies.d.ts +48 -0
  22. package/dist/middleware/cookies.d.ts.map +1 -0
  23. package/dist/middleware/cors.d.ts +65 -0
  24. package/dist/middleware/cors.d.ts.map +1 -0
  25. package/dist/middleware/csrf.d.ts +109 -0
  26. package/dist/middleware/csrf.d.ts.map +1 -0
  27. package/dist/middleware/error-handler.d.ts +43 -0
  28. package/dist/middleware/error-handler.d.ts.map +1 -0
  29. package/dist/middleware/headers.d.ts +29 -0
  30. package/dist/middleware/headers.d.ts.map +1 -0
  31. package/dist/middleware/hpp.d.ts +56 -0
  32. package/dist/middleware/hpp.d.ts.map +1 -0
  33. package/dist/middleware/index.d.ts +16 -3
  34. package/dist/middleware/index.d.ts.map +1 -0
  35. package/dist/middleware/index.js +6 -1
  36. package/dist/middleware/index.js.map +1 -1
  37. package/dist/middleware/index.mjs +6 -1
  38. package/dist/middleware/index.mjs.map +1 -1
  39. package/dist/middleware/main.d.ts +40 -0
  40. package/dist/middleware/main.d.ts.map +1 -0
  41. package/dist/middleware/rate-limit-sliding.d.ts +46 -0
  42. package/dist/middleware/rate-limit-sliding.d.ts.map +1 -0
  43. package/dist/middleware/rate-limit-token.d.ts +51 -0
  44. package/dist/middleware/rate-limit-token.d.ts.map +1 -0
  45. package/dist/middleware/rate-limit.d.ts +34 -0
  46. package/dist/middleware/rate-limit.d.ts.map +1 -0
  47. package/dist/sanitizers/command.d.ts +28 -0
  48. package/dist/sanitizers/command.d.ts.map +1 -0
  49. package/dist/sanitizers/encode.d.ts +46 -0
  50. package/dist/sanitizers/encode.d.ts.map +1 -0
  51. package/dist/sanitizers/headers.d.ts +46 -0
  52. package/dist/sanitizers/headers.d.ts.map +1 -0
  53. package/dist/sanitizers/index.d.ts +17 -22
  54. package/dist/sanitizers/index.d.ts.map +1 -0
  55. package/dist/sanitizers/jsonp.d.ts +34 -0
  56. package/dist/sanitizers/jsonp.d.ts.map +1 -0
  57. package/dist/sanitizers/nosql.d.ts +31 -0
  58. package/dist/sanitizers/nosql.d.ts.map +1 -0
  59. package/dist/sanitizers/path.d.ts +28 -0
  60. package/dist/sanitizers/path.d.ts.map +1 -0
  61. package/dist/sanitizers/pii.d.ts +80 -0
  62. package/dist/sanitizers/pii.d.ts.map +1 -0
  63. package/dist/sanitizers/prototype.d.ts +34 -0
  64. package/dist/sanitizers/prototype.d.ts.map +1 -0
  65. package/dist/sanitizers/sanitize.d.ts +51 -0
  66. package/dist/sanitizers/sanitize.d.ts.map +1 -0
  67. package/dist/sanitizers/sql.d.ts +28 -0
  68. package/dist/sanitizers/sql.d.ts.map +1 -0
  69. package/dist/sanitizers/ssti.d.ts +20 -0
  70. package/dist/sanitizers/ssti.d.ts.map +1 -0
  71. package/dist/sanitizers/utils.d.ts +19 -0
  72. package/dist/sanitizers/utils.d.ts.map +1 -0
  73. package/dist/sanitizers/xss.d.ts +35 -0
  74. package/dist/sanitizers/xss.d.ts.map +1 -0
  75. package/dist/sanitizers/xxe.d.ts +20 -0
  76. package/dist/sanitizers/xxe.d.ts.map +1 -0
  77. package/dist/stores/index.d.ts +6 -104
  78. package/dist/stores/index.d.ts.map +1 -0
  79. package/dist/stores/memory.d.ts +35 -0
  80. package/dist/stores/memory.d.ts.map +1 -0
  81. package/dist/stores/{index.d.mts → redis.d.ts} +6 -45
  82. package/dist/stores/redis.d.ts.map +1 -0
  83. package/dist/utils/duration.d.ts +34 -0
  84. package/dist/utils/duration.d.ts.map +1 -0
  85. package/dist/utils/fingerprint.d.ts +64 -0
  86. package/dist/utils/fingerprint.d.ts.map +1 -0
  87. package/dist/utils/index.d.ts +10 -0
  88. package/dist/utils/index.d.ts.map +1 -0
  89. package/dist/utils/index.js +188 -0
  90. package/dist/utils/index.js.map +1 -0
  91. package/dist/utils/index.mjs +182 -0
  92. package/dist/utils/index.mjs.map +1 -0
  93. package/dist/utils/ip.d.ts +70 -0
  94. package/dist/utils/ip.d.ts.map +1 -0
  95. package/dist/validation/email.d.ts +82 -0
  96. package/dist/validation/email.d.ts.map +1 -0
  97. package/dist/validation/file.d.ts +90 -0
  98. package/dist/validation/file.d.ts.map +1 -0
  99. package/dist/validation/index.d.ts +10 -3
  100. package/dist/validation/index.d.ts.map +1 -0
  101. package/dist/validation/redirect.d.ts +64 -0
  102. package/dist/validation/redirect.d.ts.map +1 -0
  103. package/dist/validation/schema.d.ts +36 -0
  104. package/dist/validation/schema.d.ts.map +1 -0
  105. package/dist/validation/url.d.ts +65 -0
  106. package/dist/validation/url.d.ts.map +1 -0
  107. package/package.json +8 -6
  108. package/dist/encode-CrQCGlBq.d.mts +0 -484
  109. package/dist/encode-jl9sOwmA.d.ts +0 -484
  110. package/dist/index-BAhgn9V2.d.ts +0 -532
  111. package/dist/index-BGNKspqH.d.ts +0 -340
  112. package/dist/index-Cd02z-0j.d.mts +0 -340
  113. package/dist/index-DgJtWMSj.d.mts +0 -532
  114. package/dist/index.d.mts +0 -175
  115. package/dist/middleware/index.d.mts +0 -3
  116. package/dist/sanitizers/index.d.mts +0 -24
  117. package/dist/types-BOkx5YJc.d.ts +0 -279
  118. package/dist/validation/index.d.mts +0 -3
@@ -0,0 +1,51 @@
1
+ /**
2
+ * @module @arcis/node/sanitizers/sanitize
3
+ * Main sanitization functions that combine all sanitizers
4
+ */
5
+ import type { RequestHandler } from 'express';
6
+ import type { SanitizeOptions } from '../core/types';
7
+ /**
8
+ * Sanitize a string value against multiple attack vectors.
9
+ *
10
+ * Order matters: We do XSS encoding LAST because:
11
+ * 1. Other sanitizers need to see the original patterns (e.g., SQL keywords)
12
+ * 2. HTML encoding is the final safe output transformation
13
+ * 3. Encoded entities like < shouldn't be treated as SQL/command threats
14
+ *
15
+ * @param value - The string to sanitize
16
+ * @param options - Sanitization options
17
+ * @returns The sanitized string
18
+ *
19
+ * @example
20
+ * sanitizeString("<script>alert('xss')</script>")
21
+ * // Returns: "&lt;script&gt;alert(&#x27;xss&#x27;)&lt;/script&gt;"
22
+ *
23
+ * @example
24
+ * sanitizeString("../../etc/passwd")
25
+ * // Returns: "etc/passwd"
26
+ */
27
+ export declare function sanitizeString(value: string, options?: SanitizeOptions): string;
28
+ /**
29
+ * Sanitize an object recursively, including nested objects and arrays.
30
+ * Also removes prototype pollution and NoSQL injection keys.
31
+ *
32
+ * @param obj - The object to sanitize
33
+ * @param options - Sanitization options
34
+ * @returns The sanitized object
35
+ */
36
+ export declare function sanitizeObject(obj: unknown, options?: SanitizeOptions): unknown;
37
+ /**
38
+ * Create Express middleware for request sanitization.
39
+ * Sanitizes req.body, req.query, and req.params.
40
+ *
41
+ * @param options - Sanitization options
42
+ * @returns Express middleware
43
+ *
44
+ * @example
45
+ * app.use(createSanitizer());
46
+ *
47
+ * @example
48
+ * app.use(createSanitizer({ xss: true, sql: true, nosql: true }));
49
+ */
50
+ export declare function createSanitizer(options?: SanitizeOptions): RequestHandler;
51
+ //# sourceMappingURL=sanitize.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sanitize.d.ts","sourceRoot":"","sources":["../../src/sanitizers/sanitize.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAmC,cAAc,EAAE,MAAM,SAAS,CAAC;AAG/E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAMrD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,GAAE,eAAoB,GAAG,MAAM,CA8CnF;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,GAAE,eAAoB,GAAG,OAAO,CAQnF;AA+CD;;;;;;;;;;;;GAYG;AACH,wBAAgB,eAAe,CAAC,OAAO,GAAE,eAAoB,GAAG,cAAc,CAoB7E"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * @module @arcis/node/sanitizers/sql
3
+ * SQL injection prevention
4
+ */
5
+ import type { SanitizeResult } from '../core/types';
6
+ /**
7
+ * Sanitizes a string to prevent SQL injection attacks.
8
+ * Replaces dangerous SQL patterns with [BLOCKED].
9
+ *
10
+ * @param input - The string to sanitize
11
+ * @param collectThreats - Whether to collect threat information (default: false for performance)
12
+ * @returns Sanitized string or SanitizeResult if collectThreats is true
13
+ *
14
+ * @example
15
+ * sanitizeSql("'; DROP TABLE users; --")
16
+ * // Returns: "'; TABLE users "
17
+ */
18
+ export declare function sanitizeSql(input: string, collectThreats?: false): string;
19
+ export declare function sanitizeSql(input: string, collectThreats: true): SanitizeResult;
20
+ /**
21
+ * Checks if a string contains potential SQL injection patterns.
22
+ * Does not sanitize — use sanitizeSql() for that.
23
+ *
24
+ * @param input - The string to check
25
+ * @returns True if SQL injection patterns detected
26
+ */
27
+ export declare function detectSql(input: string): boolean;
28
+ //# sourceMappingURL=sql.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sql.d.ts","sourceRoot":"","sources":["../../src/sanitizers/sql.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,cAAc,EAAc,MAAM,eAAe,CAAC;AAEhE;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,cAAc,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;AAC3E,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,cAAc,EAAE,IAAI,GAAG,cAAc,CAAC;AA8CjF;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAWhD"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * @module @arcis/node/sanitizers/ssti
3
+ * Server-Side Template Injection (SSTI) prevention
4
+ */
5
+ import type { SanitizeResult } from '../core/types';
6
+ /**
7
+ * Sanitizes a string to prevent SSTI attacks.
8
+ * Removes template expression syntax.
9
+ */
10
+ export declare function sanitizeSsti(input: string, collectThreats?: false): string;
11
+ export declare function sanitizeSsti(input: string, collectThreats: true): SanitizeResult;
12
+ /**
13
+ * Checks if a string contains SSTI patterns.
14
+ * Does not sanitize — use sanitizeSsti() for that.
15
+ *
16
+ * @param input - The string to check
17
+ * @returns True if SSTI patterns detected
18
+ */
19
+ export declare function detectSsti(input: string): boolean;
20
+ //# sourceMappingURL=ssti.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ssti.d.ts","sourceRoot":"","sources":["../../src/sanitizers/ssti.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAc,MAAM,eAAe,CAAC;AAkChE;;;GAGG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,cAAc,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;AAC5E,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,cAAc,EAAE,IAAI,GAAG,cAAc,CAAC;AA0ClF;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAWjD"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * @module @arcis/node/sanitizers/utils
3
+ * Shared utilities for sanitizers
4
+ */
5
+ /**
6
+ * Encodes HTML entities to prevent interpretation as markup.
7
+ *
8
+ * @param str - The string to encode
9
+ * @returns The encoded string
10
+ */
11
+ export declare function encodeHtmlEntities(str: string): string;
12
+ /**
13
+ * Checks if a value is a plain object (not null, array, Date, etc.)
14
+ *
15
+ * @param value - Value to check
16
+ * @returns True if plain object
17
+ */
18
+ export declare function isPlainObject(value: unknown): value is Record<string, unknown>;
19
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/sanitizers/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAOtD;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAS9E"}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * @module @arcis/node/sanitizers/xss
3
+ * XSS (Cross-Site Scripting) prevention
4
+ */
5
+ import type { SanitizeResult } from '../core/types';
6
+ /**
7
+ * Sanitizes a string to prevent XSS attacks.
8
+ *
9
+ * Strategy:
10
+ * 1. Remove dangerous patterns (script tags, event handlers, etc.)
11
+ * 2. HTML-encode the remaining content
12
+ *
13
+ * @param input - The string to sanitize
14
+ * @param collectThreats - Whether to collect threat information (default: false for performance)
15
+ * @returns Sanitized string or SanitizeResult if collectThreats is true
16
+ *
17
+ * @example
18
+ * sanitizeXss("<script>alert('xss')</script>")
19
+ * // Returns: "&lt;script&gt;alert(&#x27;xss&#x27;)&lt;/script&gt;"
20
+ *
21
+ * @example
22
+ * sanitizeXss("<img onerror='alert(1)'>")
23
+ * // Returns: "&lt;img&gt;" (event handler removed)
24
+ */
25
+ export declare function sanitizeXss(input: string, collectThreats?: false, htmlEncode?: boolean): string;
26
+ export declare function sanitizeXss(input: string, collectThreats: true, htmlEncode?: boolean): SanitizeResult;
27
+ /**
28
+ * Checks if a string contains potential XSS patterns.
29
+ * Does not sanitize — use sanitizeXss() for that.
30
+ *
31
+ * @param input - The string to check
32
+ * @returns True if XSS patterns detected
33
+ */
34
+ export declare function detectXss(input: string): boolean;
35
+ //# sourceMappingURL=xss.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"xss.d.ts","sourceRoot":"","sources":["../../src/sanitizers/xss.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,KAAK,EAAE,cAAc,EAAc,MAAM,eAAe,CAAC;AAEhE;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,cAAc,CAAC,EAAE,KAAK,EAAE,UAAU,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;AACjG,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,cAAc,EAAE,IAAI,EAAE,UAAU,CAAC,EAAE,OAAO,GAAG,cAAc,CAAC;AAwDvG;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAoBhD"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * @module @arcis/node/sanitizers/xxe
3
+ * XML External Entity (XXE) injection prevention
4
+ */
5
+ import type { SanitizeResult } from '../core/types';
6
+ /**
7
+ * Sanitizes a string to prevent XXE attacks.
8
+ * Removes DOCTYPE, ENTITY, and CDATA constructs.
9
+ */
10
+ export declare function sanitizeXxe(input: string, collectThreats?: false): string;
11
+ export declare function sanitizeXxe(input: string, collectThreats: true): SanitizeResult;
12
+ /**
13
+ * Checks if a string contains XXE patterns.
14
+ * Does not sanitize — use sanitizeXxe() for that.
15
+ *
16
+ * @param input - The string to check
17
+ * @returns True if XXE patterns detected
18
+ */
19
+ export declare function detectXxe(input: string): boolean;
20
+ //# sourceMappingURL=xxe.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"xxe.d.ts","sourceRoot":"","sources":["../../src/sanitizers/xxe.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAc,MAAM,eAAe,CAAC;AAiChE;;;GAGG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,cAAc,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;AAC3E,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,cAAc,EAAE,IAAI,GAAG,cAAc,CAAC;AA0CjF;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAWhD"}
@@ -1,106 +1,8 @@
1
- import { g as RateLimitStore, R as RateLimitEntry } from '../types-BOkx5YJc.js';
2
- import 'express';
3
-
4
1
  /**
5
- * @module @arcis/node/stores/memory
6
- * In-memory rate limit store
2
+ * @module @arcis/node/stores
3
+ * Rate limit stores for Arcis
7
4
  */
8
-
9
- /**
10
- * In-memory rate limit store.
11
- * Suitable for single-instance deployments.
12
- * For distributed systems, use RedisStore or a custom store.
13
- *
14
- * @example
15
- * const store = new MemoryStore(60000); // 1 minute window
16
- * const limiter = createRateLimiter({ store });
17
- */
18
- declare class MemoryStore implements RateLimitStore {
19
- private store;
20
- private cleanupInterval;
21
- private windowMs;
22
- constructor(windowMs?: number);
23
- /**
24
- * Start the cleanup interval to remove expired entries.
25
- */
26
- private startCleanup;
27
- get(key: string): Promise<RateLimitEntry | null>;
28
- set(key: string, entry: RateLimitEntry): Promise<void>;
29
- increment(key: string): Promise<number>;
30
- decrement(key: string): Promise<void>;
31
- reset(key: string): Promise<void>;
32
- close(): Promise<void>;
33
- /**
34
- * Get current store size (for monitoring).
35
- */
36
- get size(): number;
37
- }
38
-
39
- /**
40
- * @module @arcis/node/stores/redis
41
- * Redis rate limit store
42
- *
43
- * Note: This is a reference implementation. You'll need to install
44
- * the 'ioredis' or 'redis' package and pass your client instance.
45
- */
46
-
47
- /** Generic Redis client interface (works with ioredis, redis, etc.) */
48
- interface RedisClientLike {
49
- get(key: string): Promise<string | null>;
50
- set(key: string, value: string, mode?: string, duration?: number): Promise<unknown>;
51
- setex(key: string, seconds: number, value: string): Promise<unknown>;
52
- expire(key: string, seconds: number): Promise<unknown>;
53
- incr(key: string): Promise<number>;
54
- decr(key: string): Promise<number>;
55
- del(key: string): Promise<number>;
56
- ttl(key: string): Promise<number>;
57
- quit?(): Promise<unknown>;
58
- disconnect?(): Promise<unknown>;
59
- }
60
- interface RedisStoreOptions {
61
- /** Redis client instance */
62
- client: RedisClientLike;
63
- /** Key prefix. Default: 'arcis:rl:' */
64
- prefix?: string;
65
- /** Window size in milliseconds. Default: 60000 */
66
- windowMs?: number;
67
- }
68
- /**
69
- * Redis rate limit store for distributed deployments.
70
- *
71
- * @example
72
- * import Redis from 'ioredis';
73
- *
74
- * const redis = new Redis();
75
- * const store = new RedisStore({ client: redis });
76
- * const limiter = createRateLimiter({ store });
77
- *
78
- * // Cleanup on shutdown
79
- * process.on('SIGTERM', async () => {
80
- * await store.close();
81
- * });
82
- */
83
- declare class RedisStore implements RateLimitStore {
84
- private client;
85
- private prefix;
86
- private windowMs;
87
- private windowSec;
88
- constructor(options: RedisStoreOptions);
89
- private getKey;
90
- get(key: string): Promise<RateLimitEntry | null>;
91
- set(key: string, entry: RateLimitEntry): Promise<void>;
92
- increment(key: string): Promise<number>;
93
- decrement(key: string): Promise<void>;
94
- reset(key: string): Promise<void>;
95
- close(): Promise<void>;
96
- }
97
- /**
98
- * Create a Redis store with the given options.
99
- * Convenience function for functional programming style.
100
- *
101
- * @example
102
- * const store = createRedisStore({ client: redisClient });
103
- */
104
- declare function createRedisStore(options: RedisStoreOptions): RedisStore;
105
-
106
- export { MemoryStore, type RedisClientLike, RedisStore, type RedisStoreOptions, createRedisStore };
5
+ export { MemoryStore } from './memory';
6
+ export { RedisStore, createRedisStore } from './redis';
7
+ export type { RedisClientLike, RedisStoreOptions } from './redis';
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/stores/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AACvD,YAAY,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC"}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * @module @arcis/node/stores/memory
3
+ * In-memory rate limit store
4
+ */
5
+ import type { RateLimitStore, RateLimitEntry } from '../core/types';
6
+ /**
7
+ * In-memory rate limit store.
8
+ * Suitable for single-instance deployments.
9
+ * For distributed systems, use RedisStore or a custom store.
10
+ *
11
+ * @example
12
+ * const store = new MemoryStore(60000); // 1 minute window
13
+ * const limiter = createRateLimiter({ store });
14
+ */
15
+ export declare class MemoryStore implements RateLimitStore {
16
+ private store;
17
+ private cleanupInterval;
18
+ private windowMs;
19
+ constructor(windowMs?: number);
20
+ /**
21
+ * Start the cleanup interval to remove expired entries.
22
+ */
23
+ private startCleanup;
24
+ get(key: string): Promise<RateLimitEntry | null>;
25
+ set(key: string, entry: RateLimitEntry): Promise<void>;
26
+ increment(key: string): Promise<number>;
27
+ decrement(key: string): Promise<void>;
28
+ reset(key: string): Promise<void>;
29
+ close(): Promise<void>;
30
+ /**
31
+ * Get current store size (for monitoring).
32
+ */
33
+ get size(): number;
34
+ }
35
+ //# sourceMappingURL=memory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../../src/stores/memory.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAGpE;;;;;;;;GAQG;AACH,qBAAa,WAAY,YAAW,cAAc;IAChD,OAAO,CAAC,KAAK,CAA0C;IACvD,OAAO,CAAC,eAAe,CAA+C;IACtE,OAAO,CAAC,QAAQ,CAAS;gBAEb,QAAQ,GAAE,MAAqC;IAU3D;;OAEG;IACH,OAAO,CAAC,YAAY;IAuBd,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC;IAahD,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAItD,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAcvC,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAOrC,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIjC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAQ5B;;OAEG;IACH,IAAI,IAAI,IAAI,MAAM,CAEjB;CACF"}
@@ -1,41 +1,3 @@
1
- import { g as RateLimitStore, R as RateLimitEntry } from '../types-BOkx5YJc.mjs';
2
- import 'express';
3
-
4
- /**
5
- * @module @arcis/node/stores/memory
6
- * In-memory rate limit store
7
- */
8
-
9
- /**
10
- * In-memory rate limit store.
11
- * Suitable for single-instance deployments.
12
- * For distributed systems, use RedisStore or a custom store.
13
- *
14
- * @example
15
- * const store = new MemoryStore(60000); // 1 minute window
16
- * const limiter = createRateLimiter({ store });
17
- */
18
- declare class MemoryStore implements RateLimitStore {
19
- private store;
20
- private cleanupInterval;
21
- private windowMs;
22
- constructor(windowMs?: number);
23
- /**
24
- * Start the cleanup interval to remove expired entries.
25
- */
26
- private startCleanup;
27
- get(key: string): Promise<RateLimitEntry | null>;
28
- set(key: string, entry: RateLimitEntry): Promise<void>;
29
- increment(key: string): Promise<number>;
30
- decrement(key: string): Promise<void>;
31
- reset(key: string): Promise<void>;
32
- close(): Promise<void>;
33
- /**
34
- * Get current store size (for monitoring).
35
- */
36
- get size(): number;
37
- }
38
-
39
1
  /**
40
2
  * @module @arcis/node/stores/redis
41
3
  * Redis rate limit store
@@ -43,9 +5,9 @@ declare class MemoryStore implements RateLimitStore {
43
5
  * Note: This is a reference implementation. You'll need to install
44
6
  * the 'ioredis' or 'redis' package and pass your client instance.
45
7
  */
46
-
8
+ import type { RateLimitStore, RateLimitEntry } from '../core/types';
47
9
  /** Generic Redis client interface (works with ioredis, redis, etc.) */
48
- interface RedisClientLike {
10
+ export interface RedisClientLike {
49
11
  get(key: string): Promise<string | null>;
50
12
  set(key: string, value: string, mode?: string, duration?: number): Promise<unknown>;
51
13
  setex(key: string, seconds: number, value: string): Promise<unknown>;
@@ -57,7 +19,7 @@ interface RedisClientLike {
57
19
  quit?(): Promise<unknown>;
58
20
  disconnect?(): Promise<unknown>;
59
21
  }
60
- interface RedisStoreOptions {
22
+ export interface RedisStoreOptions {
61
23
  /** Redis client instance */
62
24
  client: RedisClientLike;
63
25
  /** Key prefix. Default: 'arcis:rl:' */
@@ -80,7 +42,7 @@ interface RedisStoreOptions {
80
42
  * await store.close();
81
43
  * });
82
44
  */
83
- declare class RedisStore implements RateLimitStore {
45
+ export declare class RedisStore implements RateLimitStore {
84
46
  private client;
85
47
  private prefix;
86
48
  private windowMs;
@@ -101,6 +63,5 @@ declare class RedisStore implements RateLimitStore {
101
63
  * @example
102
64
  * const store = createRedisStore({ client: redisClient });
103
65
  */
104
- declare function createRedisStore(options: RedisStoreOptions): RedisStore;
105
-
106
- export { MemoryStore, type RedisClientLike, RedisStore, type RedisStoreOptions, createRedisStore };
66
+ export declare function createRedisStore(options: RedisStoreOptions): RedisStore;
67
+ //# sourceMappingURL=redis.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"redis.d.ts","sourceRoot":"","sources":["../../src/stores/redis.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAGpE,uEAAuE;AACvE,MAAM,WAAW,eAAe;IAC9B,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IACzC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACpF,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACrE,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACvD,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACnC,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACnC,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAClC,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAClC,IAAI,CAAC,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IAC1B,UAAU,CAAC,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;CACjC;AAED,MAAM,WAAW,iBAAiB;IAChC,4BAA4B;IAC5B,MAAM,EAAE,eAAe,CAAC;IACxB,uCAAuC;IACvC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,kDAAkD;IAClD,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;;;;;;;;;;;;;GAcG;AACH,qBAAa,UAAW,YAAW,cAAc;IAC/C,OAAO,CAAC,MAAM,CAAkB;IAChC,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,SAAS,CAAS;gBAEd,OAAO,EAAE,iBAAiB;IAOtC,OAAO,CAAC,MAAM;IAIR,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC;IAwBhD,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAQtD,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAgBvC,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAKrC,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAKjC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAI7B;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,iBAAiB,GAAG,UAAU,CAEvE"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * @module @arcis/node/utils/duration
3
+ * Parse human-readable duration strings into milliseconds.
4
+ *
5
+ * Supports: ms, s, m, h, d
6
+ *
7
+ * @example
8
+ * parseDuration('5m') // 300000
9
+ * parseDuration('2h') // 7200000
10
+ * parseDuration(60000) // 60000 (passthrough)
11
+ * parseDuration('500ms') // 500
12
+ */
13
+ /**
14
+ * Parse a duration string or number into milliseconds.
15
+ *
16
+ * @param value - Duration string (e.g. "5m", "2h", "30s") or number (ms)
17
+ * @returns Duration in milliseconds
18
+ * @throws {Error} If the value is not a valid duration
19
+ *
20
+ * @example
21
+ * parseDuration('15m') // 900000
22
+ * parseDuration('1d') // 86400000
23
+ * parseDuration('500ms') // 500
24
+ * parseDuration(60000) // 60000
25
+ */
26
+ export declare function parseDuration(value: string | number): number;
27
+ /**
28
+ * Format milliseconds into a human-readable duration string.
29
+ *
30
+ * @param ms - Duration in milliseconds
31
+ * @returns Human-readable string (e.g. "5m", "2h 30m")
32
+ */
33
+ export declare function formatDuration(ms: number): string;
34
+ //# sourceMappingURL=duration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"duration.d.ts","sourceRoot":"","sources":["../../src/utils/duration.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAeH;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CA4B5D;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAiBjD"}
@@ -0,0 +1,64 @@
1
+ /**
2
+ * @module @arcis/node/utils/fingerprint
3
+ * Deterministic request fingerprinting via SHA-256.
4
+ *
5
+ * Generates a stable hash from request characteristics for
6
+ * rate limiting keys, abuse detection, and analytics.
7
+ *
8
+ * @example
9
+ * const fp = await fingerprint(req);
10
+ * // "a3f2b8c1d4e5..."
11
+ */
12
+ import type { DetectIpOptions } from './ip';
13
+ export interface FingerprintOptions {
14
+ /** Include IP address in fingerprint. Default: true */
15
+ ip?: boolean;
16
+ /** Include User-Agent header. Default: true */
17
+ userAgent?: boolean;
18
+ /** Include Accept header. Default: true */
19
+ accept?: boolean;
20
+ /** Include Accept-Language header. Default: true */
21
+ acceptLanguage?: boolean;
22
+ /** Include Accept-Encoding header. Default: true */
23
+ acceptEncoding?: boolean;
24
+ /** Additional custom components to include */
25
+ custom?: string[];
26
+ /** IP detection options */
27
+ ipOptions?: DetectIpOptions;
28
+ }
29
+ interface RequestLike {
30
+ headers: Record<string, string | string[] | undefined>;
31
+ socket?: {
32
+ remoteAddress?: string;
33
+ };
34
+ connection?: {
35
+ remoteAddress?: string;
36
+ };
37
+ ip?: string;
38
+ }
39
+ /**
40
+ * Generate a deterministic fingerprint for a request.
41
+ *
42
+ * Creates a SHA-256 hash from configurable request components.
43
+ * The fingerprint is stable across requests from the same client
44
+ * (same IP, browser, language settings).
45
+ *
46
+ * @param req - HTTP request object
47
+ * @param options - Fingerprint configuration
48
+ * @returns Hex-encoded SHA-256 hash (64 characters)
49
+ *
50
+ * @example
51
+ * // Default fingerprint (IP + UA + Accept headers)
52
+ * const fp = fingerprint(req);
53
+ *
54
+ * @example
55
+ * // IP-only fingerprint (for simple rate limiting)
56
+ * const fp = fingerprint(req, { userAgent: false, accept: false, acceptLanguage: false, acceptEncoding: false });
57
+ *
58
+ * @example
59
+ * // With custom components
60
+ * const fp = fingerprint(req, { custom: [req.body?.userId] });
61
+ */
62
+ export declare function fingerprint(req: RequestLike, options?: FingerprintOptions): string;
63
+ export {};
64
+ //# sourceMappingURL=fingerprint.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fingerprint.d.ts","sourceRoot":"","sources":["../../src/utils/fingerprint.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,MAAM,CAAC;AAE5C,MAAM,WAAW,kBAAkB;IACjC,uDAAuD;IACvD,EAAE,CAAC,EAAE,OAAO,CAAC;IACb,+CAA+C;IAC/C,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,2CAA2C;IAC3C,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,oDAAoD;IACpD,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,oDAAoD;IACpD,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,8CAA8C;IAC9C,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,2BAA2B;IAC3B,SAAS,CAAC,EAAE,eAAe,CAAC;CAC7B;AAED,UAAU,WAAW;IACnB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC,CAAC;IACvD,MAAM,CAAC,EAAE;QAAE,aAAa,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACpC,UAAU,CAAC,EAAE;QAAE,aAAa,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACxC,EAAE,CAAC,EAAE,MAAM,CAAC;CACb;AAQD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,WAAW,EAAE,OAAO,GAAE,kBAAuB,GAAG,MAAM,CAuCtF"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @module @arcis/node/utils
3
+ * Utility functions for Arcis
4
+ */
5
+ export { parseDuration, formatDuration } from './duration';
6
+ export { detectClientIp, isPrivateIp } from './ip';
7
+ export { fingerprint } from './fingerprint';
8
+ export type { Platform, DetectIpOptions } from './ip';
9
+ export type { FingerprintOptions } from './fingerprint';
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,MAAM,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,YAAY,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,MAAM,CAAC;AACtD,YAAY,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC"}