hi-secure 1.0.5 → 1.0.7
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/dist/core/HiSecure.d.ts +17 -2
- package/dist/core/HiSecure.d.ts.map +1 -1
- package/dist/core/HiSecure.js +135 -30
- package/dist/core/HiSecure.js.map +1 -1
- package/dist/core/useSecure.d.ts +7 -0
- package/dist/core/useSecure.d.ts.map +1 -1
- package/dist/core/useSecure.js +23 -114
- package/dist/core/useSecure.js.map +1 -1
- package/dist/index.d.ts +6 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -19
- package/dist/index.js.map +1 -1
- package/dist/utils/normalizeOptions.d.ts.map +1 -1
- package/dist/utils/normalizeOptions.js +8 -8
- package/dist/utils/normalizeOptions.js.map +1 -1
- package/package.json +1 -1
- package/src/core/HiSecure.ts +0 -837
- package/src/core/useSecure.ts +0 -112
- package/src/index.ts +0 -16
- package/src/utils/normalizeOptions.ts +13 -12
package/src/core/useSecure.ts
CHANGED
|
@@ -1,63 +1,3 @@
|
|
|
1
|
-
// import { normalizeOptions } from "../utils/normalizeOptions.js";
|
|
2
|
-
// import { HiSecure } from "./HiSecure.js";
|
|
3
|
-
|
|
4
|
-
// export function useSecure(engine: HiSecure, input?: any) {
|
|
5
|
-
// if (!engine.isInitialized()) {
|
|
6
|
-
// throw new Error("HiSecure must be initialized before using .use()");
|
|
7
|
-
// }
|
|
8
|
-
|
|
9
|
-
// const options = normalizeOptions(input);
|
|
10
|
-
// const chain: any[] = [];
|
|
11
|
-
|
|
12
|
-
// // JSON
|
|
13
|
-
// if (options.json.enabled) {
|
|
14
|
-
// chain.push(engine.jsonManager.middleware(options.json.options));
|
|
15
|
-
// chain.push(engine.jsonManager.urlencoded());
|
|
16
|
-
// }
|
|
17
|
-
|
|
18
|
-
// // CORS
|
|
19
|
-
// if (options.cors.enabled) {
|
|
20
|
-
// chain.push(engine.corsManager.middleware(options.cors.options));
|
|
21
|
-
// }
|
|
22
|
-
|
|
23
|
-
// // Sanitize
|
|
24
|
-
// if (options.sanitize.enabled) {
|
|
25
|
-
// chain.push(engine.sanitizerManager.middleware());
|
|
26
|
-
// }
|
|
27
|
-
|
|
28
|
-
// // Validate
|
|
29
|
-
// if (options.validate.enabled && options.validate.schema) {
|
|
30
|
-
// chain.push(engine.validatorManager.validate(options.validate.schema));
|
|
31
|
-
// }
|
|
32
|
-
|
|
33
|
-
// // Rate Limit
|
|
34
|
-
// if (options.rateLimit.enabled) {
|
|
35
|
-
// chain.push(
|
|
36
|
-
// engine.rateLimitManager.middleware({
|
|
37
|
-
// mode: options.rateLimit.mode ?? undefined,
|
|
38
|
-
// options: options.rateLimit.options ?? undefined
|
|
39
|
-
// })
|
|
40
|
-
// );
|
|
41
|
-
// }
|
|
42
|
-
|
|
43
|
-
// // AUTH
|
|
44
|
-
// if (options.auth.enabled) {
|
|
45
|
-
// if (!engine.authManager) {
|
|
46
|
-
// throw new Error("AuthManager not initialized. Enable auth in config.");
|
|
47
|
-
// }
|
|
48
|
-
|
|
49
|
-
// chain.push(
|
|
50
|
-
// engine.authManager.protect({
|
|
51
|
-
// required: options.auth.required
|
|
52
|
-
// })
|
|
53
|
-
// );
|
|
54
|
-
// }
|
|
55
|
-
|
|
56
|
-
// return chain;
|
|
57
|
-
// }
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
1
|
// src/core/useSecure.ts - SIMPLER VERSION
|
|
62
2
|
// This is now optional since HiSecure class has fluent API
|
|
63
3
|
|
|
@@ -112,55 +52,3 @@ export function secureRoute(options?: SecureOptions) {
|
|
|
112
52
|
}
|
|
113
53
|
|
|
114
54
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
// import { HiSecure } from "./HiSecure.js";
|
|
118
|
-
// import { SecureOptions } from "./types/SecureOptions.js";
|
|
119
|
-
|
|
120
|
-
// export function secureRoute(options?: SecureOptions) {
|
|
121
|
-
// if (!options) return [];
|
|
122
|
-
|
|
123
|
-
// const chain: any[] = [];
|
|
124
|
-
|
|
125
|
-
// // 🔥 1. CORS
|
|
126
|
-
// if (options.cors !== undefined) {
|
|
127
|
-
// chain.push(
|
|
128
|
-
// HiSecure.cors(typeof options.cors === "object" ? options.cors : undefined)
|
|
129
|
-
// );
|
|
130
|
-
// }
|
|
131
|
-
|
|
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
|
-
|
|
144
|
-
// // 🔥 3. Sanitization
|
|
145
|
-
// if (options.sanitize !== undefined) {
|
|
146
|
-
// chain.push(
|
|
147
|
-
// HiSecure.sanitize(typeof options.sanitize === "object" ? options.sanitize : undefined)
|
|
148
|
-
// );
|
|
149
|
-
// }
|
|
150
|
-
|
|
151
|
-
// // 🔥 4. Validation — smart auto-detection
|
|
152
|
-
// if (options.validate) {
|
|
153
|
-
// chain.push(HiSecure.validate(options.validate));
|
|
154
|
-
// }
|
|
155
|
-
|
|
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
|
-
|
|
165
|
-
// return chain;
|
|
166
|
-
// }
|
package/src/index.ts
CHANGED
|
@@ -2,10 +2,8 @@
|
|
|
2
2
|
import { HiSecure } from "./core/HiSecure.js";
|
|
3
3
|
import { useSecure, secureRoute } from "./core/useSecure.js";
|
|
4
4
|
|
|
5
|
-
// Export the singleton instance for quick usage
|
|
6
5
|
const hiSecure = HiSecure.getInstance();
|
|
7
6
|
|
|
8
|
-
// Export everything
|
|
9
7
|
export {
|
|
10
8
|
HiSecure, // Class for advanced usage
|
|
11
9
|
hiSecure, // Singleton instance
|
|
@@ -13,21 +11,7 @@ export {
|
|
|
13
11
|
secureRoute // Route-level security helper
|
|
14
12
|
};
|
|
15
13
|
|
|
16
|
-
// Default export is the singleton instance
|
|
17
14
|
export default hiSecure;
|
|
18
15
|
|
|
19
16
|
|
|
20
17
|
|
|
21
|
-
|
|
22
|
-
// // src/index.ts
|
|
23
|
-
// import { HiSecure } from "./core/HiSecure.js";
|
|
24
|
-
// import { secureRoute } from "./core/useSecure.js"; // Only if kept
|
|
25
|
-
|
|
26
|
-
// // DON'T auto-init here
|
|
27
|
-
// export {
|
|
28
|
-
// HiSecure, // Class
|
|
29
|
-
// secureRoute // Optional sugar API
|
|
30
|
-
// };
|
|
31
|
-
|
|
32
|
-
// // Default export: class itself (NOT instance)
|
|
33
|
-
// export default HiSecure;
|
|
@@ -218,21 +218,22 @@ function normalizeRateLimit(value: SecureOptions["rateLimit"]): NormalizedOption
|
|
|
218
218
|
}
|
|
219
219
|
|
|
220
220
|
function normalizeAuth(value: SecureOptions["auth"]): NormalizedOptions["auth"] {
|
|
221
|
-
// if (value === false) {
|
|
222
|
-
// return { enabled: false, required: false };
|
|
223
|
-
// }
|
|
224
221
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
222
|
+
if (value === false) {
|
|
223
|
+
return { enabled: false, required: false };
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
if (value === true || value === undefined) {
|
|
227
|
+
return { enabled: true, required: true };
|
|
228
|
+
}
|
|
228
229
|
|
|
229
230
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
}
|
|
233
|
-
if (value === true) {
|
|
234
|
-
|
|
235
|
-
}
|
|
231
|
+
// if (value === undefined) {
|
|
232
|
+
// return { enabled: false, required: false };
|
|
233
|
+
// }
|
|
234
|
+
// if (value === true) {
|
|
235
|
+
// return { enabled: true, required: true };
|
|
236
|
+
// }
|
|
236
237
|
|
|
237
238
|
|
|
238
239
|
const authOptions = value as AuthOptions;
|