hi-secure 1.0.4 → 1.0.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/package.json +1 -1
- package/src/core/useSecure.ts +82 -82
- package/src/index.ts +24 -24
package/package.json
CHANGED
package/src/core/useSecure.ts
CHANGED
|
@@ -62,105 +62,105 @@
|
|
|
62
62
|
// This is now optional since HiSecure class has fluent API
|
|
63
63
|
|
|
64
64
|
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
import { HiSecure } from "./HiSecure.js";
|
|
66
|
+
import { SecureOptions } from "./types/SecureOptions.js";
|
|
67
67
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
68
|
+
/**
|
|
69
|
+
* @deprecated Use HiSecure.middleware() or fluent API instead
|
|
70
|
+
*/
|
|
71
|
+
export function useSecure(options?: SecureOptions | "api" | "strict" | "public") {
|
|
72
|
+
console.warn("⚠ useSecure() is deprecated. Use HiSecure.middleware() or fluent API methods.");
|
|
73
|
+
return HiSecure.middleware(options);
|
|
74
|
+
}
|
|
75
75
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
76
|
+
/**
|
|
77
|
+
* Legacy support - route-level security
|
|
78
|
+
*/
|
|
79
|
+
export function secureRoute(options?: SecureOptions) {
|
|
80
|
+
const chain: any[] = [];
|
|
81
81
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
82
|
+
if (options?.cors) {
|
|
83
|
+
chain.push(HiSecure.cors(
|
|
84
|
+
typeof options.cors === 'object' ? options.cors : undefined
|
|
85
|
+
));
|
|
86
|
+
}
|
|
87
87
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
88
|
+
if (options?.rateLimit) {
|
|
89
|
+
chain.push(HiSecure.rateLimit(
|
|
90
|
+
typeof options.rateLimit === 'object' ? options.rateLimit :
|
|
91
|
+
options.rateLimit === "strict" ? "strict" : "relaxed"
|
|
92
|
+
));
|
|
93
|
+
}
|
|
94
94
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
95
|
+
if (options?.sanitize) {
|
|
96
|
+
chain.push(HiSecure.sanitize(
|
|
97
|
+
typeof options.sanitize === 'object' ? options.sanitize : undefined
|
|
98
|
+
));
|
|
99
|
+
}
|
|
100
100
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
101
|
+
if (options?.validate) {
|
|
102
|
+
chain.push(HiSecure.validate(options.validate));
|
|
103
|
+
}
|
|
104
104
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
105
|
+
if (options?.auth) {
|
|
106
|
+
chain.push(HiSecure.auth(
|
|
107
|
+
typeof options.auth === 'object' ? options.auth : undefined
|
|
108
|
+
));
|
|
109
|
+
}
|
|
110
110
|
|
|
111
|
-
|
|
112
|
-
|
|
111
|
+
return chain;
|
|
112
|
+
}
|
|
113
113
|
|
|
114
114
|
|
|
115
115
|
|
|
116
116
|
|
|
117
|
-
import { HiSecure } from "./HiSecure.js";
|
|
118
|
-
import { SecureOptions } from "./types/SecureOptions.js";
|
|
117
|
+
// import { HiSecure } from "./HiSecure.js";
|
|
118
|
+
// import { SecureOptions } from "./types/SecureOptions.js";
|
|
119
119
|
|
|
120
|
-
export function secureRoute(options?: SecureOptions) {
|
|
121
|
-
|
|
120
|
+
// export function secureRoute(options?: SecureOptions) {
|
|
121
|
+
// if (!options) return [];
|
|
122
122
|
|
|
123
|
-
|
|
123
|
+
// const chain: any[] = [];
|
|
124
124
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
125
|
+
// // 🔥 1. CORS
|
|
126
|
+
// if (options.cors !== undefined) {
|
|
127
|
+
// chain.push(
|
|
128
|
+
// HiSecure.cors(typeof options.cors === "object" ? options.cors : undefined)
|
|
129
|
+
// );
|
|
130
|
+
// }
|
|
131
131
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
132
|
+
// // 🔥 2. Rate Limiting (auto strict / relaxed detection)
|
|
133
|
+
// if (options.rateLimit !== undefined) {
|
|
134
|
+
// const rl = options.rateLimit;
|
|
135
|
+
// if (rl === "strict" || rl === "relaxed") {
|
|
136
|
+
// chain.push(HiSecure.rateLimit(rl));
|
|
137
|
+
// } else if (typeof rl === "object") {
|
|
138
|
+
// chain.push(HiSecure.rateLimit(rl));
|
|
139
|
+
// } else {
|
|
140
|
+
// chain.push(HiSecure.rateLimit("relaxed"));
|
|
141
|
+
// }
|
|
142
|
+
// }
|
|
143
143
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
144
|
+
// // 🔥 3. Sanitization
|
|
145
|
+
// if (options.sanitize !== undefined) {
|
|
146
|
+
// chain.push(
|
|
147
|
+
// HiSecure.sanitize(typeof options.sanitize === "object" ? options.sanitize : undefined)
|
|
148
|
+
// );
|
|
149
|
+
// }
|
|
150
150
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
151
|
+
// // 🔥 4. Validation — smart auto-detection
|
|
152
|
+
// if (options.validate) {
|
|
153
|
+
// chain.push(HiSecure.validate(options.validate));
|
|
154
|
+
// }
|
|
155
155
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
156
|
+
// // 🔥 5. Auth (roles included)
|
|
157
|
+
// if (options.auth) {
|
|
158
|
+
// chain.push(
|
|
159
|
+
// HiSecure.auth(
|
|
160
|
+
// typeof options.auth === "object" ? options.auth : undefined
|
|
161
|
+
// )
|
|
162
|
+
// );
|
|
163
|
+
// }
|
|
164
164
|
|
|
165
|
-
|
|
166
|
-
}
|
|
165
|
+
// return chain;
|
|
166
|
+
// }
|
package/src/index.ts
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
// src/index.ts - MAIN ENTRY POINT
|
|
2
|
+
import { HiSecure } from "./core/HiSecure.js";
|
|
3
|
+
import { useSecure, secureRoute } from "./core/useSecure.js";
|
|
4
4
|
|
|
5
|
-
//
|
|
6
|
-
|
|
5
|
+
// Export the singleton instance for quick usage
|
|
6
|
+
const hiSecure = HiSecure.getInstance();
|
|
7
7
|
|
|
8
|
-
//
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
// Export everything
|
|
9
|
+
export {
|
|
10
|
+
HiSecure, // Class for advanced usage
|
|
11
|
+
hiSecure, // Singleton instance
|
|
12
|
+
useSecure, // Legacy function (deprecated)
|
|
13
|
+
secureRoute // Route-level security helper
|
|
14
|
+
};
|
|
15
15
|
|
|
16
|
-
//
|
|
17
|
-
|
|
16
|
+
// Default export is the singleton instance
|
|
17
|
+
export default hiSecure;
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
|
|
22
|
-
// src/index.ts
|
|
23
|
-
import { HiSecure } from "./core/HiSecure.js";
|
|
24
|
-
import { secureRoute } from "./core/useSecure.js"; // Only if kept
|
|
22
|
+
// // src/index.ts
|
|
23
|
+
// import { HiSecure } from "./core/HiSecure.js";
|
|
24
|
+
// import { secureRoute } from "./core/useSecure.js"; // Only if kept
|
|
25
25
|
|
|
26
|
-
// DON'T auto-init here
|
|
27
|
-
export {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
};
|
|
26
|
+
// // DON'T auto-init here
|
|
27
|
+
// export {
|
|
28
|
+
// HiSecure, // Class
|
|
29
|
+
// secureRoute // Optional sugar API
|
|
30
|
+
// };
|
|
31
31
|
|
|
32
|
-
// Default export: class itself (NOT instance)
|
|
33
|
-
export default HiSecure;
|
|
32
|
+
// // Default export: class itself (NOT instance)
|
|
33
|
+
// export default HiSecure;
|