@voltrix/security 0.3.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 (39) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +147 -0
  3. package/dist/decorators/index.d.ts +26 -0
  4. package/dist/decorators/index.js +37 -0
  5. package/dist/decorators/index.js.map +1 -0
  6. package/dist/index.d.ts +11 -0
  7. package/dist/index.js +86 -0
  8. package/dist/index.js.map +1 -0
  9. package/dist/modules/cors.d.ts +8 -0
  10. package/dist/modules/cors.js +71 -0
  11. package/dist/modules/cors.js.map +1 -0
  12. package/dist/modules/csrf.d.ts +20 -0
  13. package/dist/modules/csrf.js +98 -0
  14. package/dist/modules/csrf.js.map +1 -0
  15. package/dist/modules/helmet.d.ts +7 -0
  16. package/dist/modules/helmet.js +65 -0
  17. package/dist/modules/helmet.js.map +1 -0
  18. package/dist/modules/ip-filter.d.ts +21 -0
  19. package/dist/modules/ip-filter.js +99 -0
  20. package/dist/modules/ip-filter.js.map +1 -0
  21. package/dist/modules/rate-limit.d.ts +11 -0
  22. package/dist/modules/rate-limit.js +58 -0
  23. package/dist/modules/rate-limit.js.map +1 -0
  24. package/dist/modules/session.d.ts +16 -0
  25. package/dist/modules/session.js +157 -0
  26. package/dist/modules/session.js.map +1 -0
  27. package/dist/store/index.d.ts +3 -0
  28. package/dist/store/index.js +3 -0
  29. package/dist/store/index.js.map +1 -0
  30. package/dist/store/memory-store.d.ts +23 -0
  31. package/dist/store/memory-store.js +75 -0
  32. package/dist/store/memory-store.js.map +1 -0
  33. package/dist/store/redis-store.d.ts +20 -0
  34. package/dist/store/redis-store.js +55 -0
  35. package/dist/store/redis-store.js.map +1 -0
  36. package/dist/types/index.d.ts +98 -0
  37. package/dist/types/index.js +2 -0
  38. package/dist/types/index.js.map +1 -0
  39. package/package.json +60 -0
@@ -0,0 +1,98 @@
1
+ import type { IRequest, IResponse } from '@voltrix/core';
2
+ /**
3
+ * Interface representing a shared caching store for security modules.
4
+ * This abstracts local memory from clustered distributed instances like Redis.
5
+ */
6
+ export interface SecurityStore {
7
+ get(key: string): Promise<string | null>;
8
+ set(key: string, value: string, ttlMs: number): Promise<void>;
9
+ increment(key: string, ttlMs: number): Promise<number>;
10
+ decrement(key: string): Promise<void>;
11
+ delete(key: string): Promise<void>;
12
+ }
13
+ /**
14
+ * Helmet module configuration options.
15
+ */
16
+ export interface HelmetOptions {
17
+ csp?: boolean | Record<string, string[]>;
18
+ hsts?: boolean | {
19
+ maxAge?: number;
20
+ includeSubDomains?: boolean;
21
+ preload?: boolean;
22
+ };
23
+ xFrame?: boolean | 'DENY' | 'SAMEORIGIN';
24
+ xContentType?: boolean;
25
+ referrerPolicy?: boolean | string;
26
+ permissionsPolicy?: boolean | Record<string, string>;
27
+ }
28
+ /**
29
+ * CORS module configuration options.
30
+ */
31
+ export interface CorsOptions {
32
+ origin?: string | string[] | ((origin: string) => boolean | Promise<boolean>);
33
+ methods?: string | string[];
34
+ allowedHeaders?: string | string[];
35
+ exposedHeaders?: string | string[];
36
+ credentials?: boolean;
37
+ maxAge?: number;
38
+ }
39
+ /**
40
+ * Rate Limiting module configuration options.
41
+ */
42
+ export interface RateLimitOptions {
43
+ windowMs?: number;
44
+ limit?: number;
45
+ keyGenerator?: (req: IRequest) => string | Promise<string>;
46
+ store?: SecurityStore;
47
+ handler?: (req: IRequest, res: IResponse) => void | Promise<void>;
48
+ }
49
+ /**
50
+ * IP Filtering module configuration options.
51
+ */
52
+ export interface IpFilterOptions {
53
+ whitelist?: string[];
54
+ blacklist?: string[];
55
+ handler?: (req: IRequest, res: IResponse) => void | Promise<void>;
56
+ }
57
+ /**
58
+ * CSRF Protection module configuration options.
59
+ */
60
+ export interface CsrfOptions {
61
+ cookieName?: string;
62
+ headerName?: string;
63
+ cookieOptions?: {
64
+ path?: string;
65
+ domain?: string;
66
+ secure?: boolean;
67
+ httpOnly?: boolean;
68
+ sameSite?: 'Strict' | 'Lax' | 'None';
69
+ };
70
+ ignoreMethods?: string[];
71
+ }
72
+ /**
73
+ * Session Management module configuration options.
74
+ */
75
+ export interface SessionOptions {
76
+ secret: string;
77
+ cookieName?: string;
78
+ ttlMs?: number;
79
+ store?: SecurityStore;
80
+ cookieOptions?: {
81
+ path?: string;
82
+ domain?: string;
83
+ secure?: boolean;
84
+ httpOnly?: boolean;
85
+ sameSite?: 'Strict' | 'Lax' | 'None';
86
+ };
87
+ }
88
+ /**
89
+ * Complete security module options pack.
90
+ */
91
+ export interface SecurityOptions {
92
+ helmet?: boolean | HelmetOptions;
93
+ cors?: boolean | CorsOptions;
94
+ rateLimit?: boolean | RateLimitOptions;
95
+ ipFilter?: boolean | IpFilterOptions;
96
+ csrf?: boolean | CsrfOptions;
97
+ session?: boolean | SessionOptions;
98
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,60 @@
1
+ {
2
+ "name": "@voltrix/security",
3
+ "version": "0.3.0",
4
+ "description": "High-performance distributed security package (CORS, Rate Limiting, IP Firewall, CSRF, Helmet, Sessions) for Voltrix",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "module": "dist/index.js",
8
+ "types": "dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js",
13
+ "require": "./dist/index.js"
14
+ }
15
+ },
16
+ "keywords": [
17
+ "voltrix",
18
+ "security",
19
+ "cors",
20
+ "rate-limit",
21
+ "helmet",
22
+ "csrf",
23
+ "session",
24
+ "ip-filter",
25
+ "firewall"
26
+ ],
27
+ "author": "Voltrix Team",
28
+ "license": "MIT",
29
+ "dependencies": {
30
+ "ioredis": "^5.4.1",
31
+ "reflect-metadata": "^0.2.2",
32
+ "tslib": "^2.8.1",
33
+ "@voltrix/core": "0.3.0",
34
+ "@voltrix/injector": "0.2.2"
35
+ },
36
+ "devDependencies": {
37
+ "@types/node": "^20.0.0",
38
+ "typescript": "5.9.3",
39
+ "vitest": "^4.1.0",
40
+ "@voltrix/decorator": "0.2.2",
41
+ "@voltrix/server": "0.2.1"
42
+ },
43
+ "files": [
44
+ "dist",
45
+ "README.md",
46
+ "LICENSE"
47
+ ],
48
+ "engines": {
49
+ "node": ">=18.0.0"
50
+ },
51
+ "publishConfig": {
52
+ "access": "public"
53
+ },
54
+ "scripts": {
55
+ "build": "tsc -p tsconfig.json",
56
+ "dev": "tsc --watch",
57
+ "test": "vitest run",
58
+ "type-check": "tsc --noEmit"
59
+ }
60
+ }