hightjs 0.3.2 → 0.3.4
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/adapters/factory.js +8 -8
- package/dist/adapters/native.js +3 -3
- package/dist/auth/client.js +5 -5
- package/dist/auth/components.js +2 -2
- package/dist/auth/core.js +2 -2
- package/dist/auth/react.js +4 -4
- package/dist/auth/routes.js +1 -1
- package/dist/bin/hightjs.js +29 -328
- package/dist/builder.js +47 -21
- package/dist/client/DefaultNotFound.js +1 -1
- package/dist/client/entry.client.js +3 -3
- package/dist/helpers.d.ts +1 -0
- package/dist/helpers.js +90 -28
- package/dist/hotReload.d.ts +3 -1
- package/dist/hotReload.js +43 -51
- package/dist/index.d.ts +1 -1
- package/dist/index.js +16 -30
- package/dist/router.js +133 -62
- package/dist/types.d.ts +42 -0
- package/docs/config.md +201 -0
- package/example/hightjs.config.ts +81 -0
- package/example/package-lock.json +633 -3054
- package/example/package.json +1 -1
- package/package.json +1 -1
- package/src/adapters/factory.ts +8 -8
- package/src/adapters/native.ts +3 -3
- package/src/auth/client.ts +5 -5
- package/src/auth/components.tsx +2 -2
- package/src/auth/core.ts +2 -2
- package/src/auth/react.tsx +4 -4
- package/src/auth/routes.ts +1 -1
- package/src/bin/hightjs.js +30 -391
- package/src/builder.js +47 -22
- package/src/client/DefaultNotFound.tsx +1 -1
- package/src/client/entry.client.tsx +3 -3
- package/src/helpers.ts +105 -29
- package/src/hotReload.ts +45 -55
- package/src/index.ts +20 -33
- package/src/router.ts +140 -63
- package/src/types.ts +52 -0
- package/example/.hweb/entry.client.js +0 -24
- package/example/hweb-dist/main-5KKAYNUU.js +0 -1137
package/example/package.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hightjs",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.4",
|
|
4
4
|
"description": "HightJS is a high-level framework for building web applications with ease and speed. It provides a robust set of tools and features to streamline development and enhance productivity.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
package/src/adapters/factory.ts
CHANGED
|
@@ -33,18 +33,18 @@ export class FrameworkAdapterFactory {
|
|
|
33
33
|
if (this.adapter) {
|
|
34
34
|
return this.adapter;
|
|
35
35
|
}
|
|
36
|
-
const msg = Console.dynamicLine(` ${Colors.FgYellow}● ${Colors.Reset}
|
|
36
|
+
const msg = Console.dynamicLine(` ${Colors.FgYellow}● ${Colors.Reset}Detecting web framework...`);
|
|
37
37
|
|
|
38
38
|
// Detecta Express
|
|
39
39
|
if (req.app && req.route && res.locals !== undefined) {
|
|
40
|
-
msg.end(` ${Colors.FgGreen}● ${Colors.Reset}Framework
|
|
40
|
+
msg.end(` ${Colors.FgGreen}● ${Colors.Reset}Framework detected: Express`);
|
|
41
41
|
this.adapter = new ExpressAdapter();
|
|
42
42
|
return this.adapter;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
// Detecta Fastify
|
|
46
46
|
if (req.server && req.routerPath !== undefined && res.request) {
|
|
47
|
-
msg.end(` ${Colors.FgGreen}● ${Colors.Reset}Framework
|
|
47
|
+
msg.end(` ${Colors.FgGreen}● ${Colors.Reset}Framework detected: Fastify`);
|
|
48
48
|
this.adapter = new FastifyAdapter();
|
|
49
49
|
return this.adapter;
|
|
50
50
|
}
|
|
@@ -52,27 +52,27 @@ export class FrameworkAdapterFactory {
|
|
|
52
52
|
// Detecta HTTP nativo do Node.js
|
|
53
53
|
if (req.method !== undefined && req.url !== undefined && req.headers !== undefined &&
|
|
54
54
|
res.statusCode !== undefined && res.setHeader !== undefined && res.end !== undefined) {
|
|
55
|
-
msg.end(` ${Colors.FgGreen}● ${Colors.Reset}Framework
|
|
55
|
+
msg.end(` ${Colors.FgGreen}● ${Colors.Reset}Framework detected: HightJS Native (HTTP)`);
|
|
56
56
|
this.adapter = new NativeAdapter();
|
|
57
57
|
return this.adapter;
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
// Fallback mais específico para Express
|
|
61
61
|
if (res.status && res.send && res.json && res.cookie) {
|
|
62
|
-
msg.end(` ${Colors.FgGreen}● ${Colors.Reset}Framework
|
|
62
|
+
msg.end(` ${Colors.FgGreen}● ${Colors.Reset}Framework detected: Express (fallback)`);
|
|
63
63
|
this.adapter = new ExpressAdapter();
|
|
64
64
|
return this.adapter;
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
// Fallback mais específico para Fastify
|
|
68
68
|
if (res.code && res.send && res.type && res.setCookie) {
|
|
69
|
-
msg.end(` ${Colors.FgGreen}● ${Colors.Reset}Framework
|
|
69
|
+
msg.end(` ${Colors.FgGreen}● ${Colors.Reset}Framework detected: Fastify (fallback)`);
|
|
70
70
|
this.adapter = new FastifyAdapter();
|
|
71
71
|
return this.adapter;
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
// Default para HightJS Native se não conseguir detectar
|
|
75
|
-
msg.end(` ${Colors.FgYellow}● ${Colors.Reset}
|
|
75
|
+
msg.end(` ${Colors.FgYellow}● ${Colors.Reset}Unable to detect framework. Using HightJS Native as default.`);
|
|
76
76
|
this.adapter = new NativeAdapter();
|
|
77
77
|
return this.adapter;
|
|
78
78
|
}
|
|
@@ -92,7 +92,7 @@ export class FrameworkAdapterFactory {
|
|
|
92
92
|
this.adapter = new NativeAdapter();
|
|
93
93
|
break;
|
|
94
94
|
default:
|
|
95
|
-
throw new Error(`
|
|
95
|
+
throw new Error(`Unsupported framework: ${framework}`);
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
98
|
|
package/src/adapters/native.ts
CHANGED
|
@@ -81,7 +81,7 @@ export class NativeAdapter implements FrameworkAdapter {
|
|
|
81
81
|
cookies[name] = decodeURIComponent(rest.join('='));
|
|
82
82
|
} catch (e) {
|
|
83
83
|
// Prevenção de crash: Ignora cookies com valores malformados (e.g., URI inválida).
|
|
84
|
-
console.error(`
|
|
84
|
+
console.error(`Warning: Malformed cookie with name "${name}" was ignored.`);
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
87
|
});
|
|
@@ -114,7 +114,7 @@ class NativeResponseWrapper implements GenericResponse {
|
|
|
114
114
|
const sanitizedValue = sanitizeHeaderValue(value);
|
|
115
115
|
|
|
116
116
|
if (name !== sanitizedName || String(value) !== sanitizedValue) {
|
|
117
|
-
console.warn(`
|
|
117
|
+
console.warn(`Warning: Potential HTTP Header Injection attempt detected and sanitized. Original header: "${name}"`);
|
|
118
118
|
}
|
|
119
119
|
|
|
120
120
|
|
|
@@ -125,7 +125,7 @@ class NativeResponseWrapper implements GenericResponse {
|
|
|
125
125
|
cookie(name: string, value: string, options?: CookieOptions): GenericResponse {
|
|
126
126
|
// Medida de segurança: Valida o nome do cookie.
|
|
127
127
|
if (!isValidCookieName(name)) {
|
|
128
|
-
console.error(`
|
|
128
|
+
console.error(`Error: Invalid cookie name "${name}". The cookie will not be set.`);
|
|
129
129
|
return this;
|
|
130
130
|
}
|
|
131
131
|
|
package/src/auth/client.ts
CHANGED
|
@@ -38,7 +38,7 @@ export async function getSession(): Promise<Session | null> {
|
|
|
38
38
|
const data = await response.json();
|
|
39
39
|
return data.session || null;
|
|
40
40
|
} catch (error) {
|
|
41
|
-
console.error('[hweb-auth]
|
|
41
|
+
console.error('[hweb-auth] Error fetching session:', error);
|
|
42
42
|
return null;
|
|
43
43
|
}
|
|
44
44
|
}
|
|
@@ -59,7 +59,7 @@ export async function getCsrfToken(): Promise<string | null> {
|
|
|
59
59
|
const data = await response.json();
|
|
60
60
|
return data.csrfToken || null;
|
|
61
61
|
} catch (error) {
|
|
62
|
-
console.error('[hweb-auth]
|
|
62
|
+
console.error('[hweb-auth] Error fetching CSRF token:', error);
|
|
63
63
|
return null;
|
|
64
64
|
}
|
|
65
65
|
}
|
|
@@ -80,7 +80,7 @@ export async function getProviders(): Promise<any[] | null> {
|
|
|
80
80
|
const data = await response.json();
|
|
81
81
|
return data.providers || [];
|
|
82
82
|
} catch (error) {
|
|
83
|
-
console.error('[hweb-auth]
|
|
83
|
+
console.error('[hweb-auth] Error searching for providers:', error);
|
|
84
84
|
return null;
|
|
85
85
|
}
|
|
86
86
|
}
|
|
@@ -143,7 +143,7 @@ export async function signIn(
|
|
|
143
143
|
};
|
|
144
144
|
}
|
|
145
145
|
} catch (error) {
|
|
146
|
-
console.error('[hweb-auth]
|
|
146
|
+
console.error('[hweb-auth] Error on signIn:', error);
|
|
147
147
|
return {
|
|
148
148
|
error: 'Network error',
|
|
149
149
|
status: 500,
|
|
@@ -166,6 +166,6 @@ export async function signOut(options: { callbackUrl?: string } = {}): Promise<v
|
|
|
166
166
|
window.location.href = options.callbackUrl || '/';
|
|
167
167
|
}
|
|
168
168
|
} catch (error) {
|
|
169
|
-
console.error('[hweb-auth]
|
|
169
|
+
console.error('[hweb-auth] Error on signOut:', error);
|
|
170
170
|
}
|
|
171
171
|
}
|
package/src/auth/components.tsx
CHANGED
|
@@ -37,7 +37,7 @@ export function ProtectedRoute({
|
|
|
37
37
|
|
|
38
38
|
// Ainda carregando
|
|
39
39
|
if (isLoading) {
|
|
40
|
-
return fallback || <div>
|
|
40
|
+
return fallback || <div>Loading...</div>;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
// Requer auth mas não está autenticado
|
|
@@ -46,7 +46,7 @@ export function ProtectedRoute({
|
|
|
46
46
|
window.location.href = redirectTo;
|
|
47
47
|
return null;
|
|
48
48
|
}
|
|
49
|
-
return fallback || <div>
|
|
49
|
+
return fallback || <div>Unauthorized</div>;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
// Não requer auth mas está autenticado (ex: página de login)
|
package/src/auth/core.ts
CHANGED
|
@@ -91,7 +91,7 @@ export class HWebAuth {
|
|
|
91
91
|
|
|
92
92
|
return sessionResult;
|
|
93
93
|
} catch (error) {
|
|
94
|
-
console.error(`[hweb-auth]
|
|
94
|
+
console.error(`[hweb-auth] Error signing in with provider ${providerId}:`, error);
|
|
95
95
|
return null;
|
|
96
96
|
}
|
|
97
97
|
}
|
|
@@ -109,7 +109,7 @@ export class HWebAuth {
|
|
|
109
109
|
try {
|
|
110
110
|
await provider.handleSignOut();
|
|
111
111
|
} catch (error) {
|
|
112
|
-
console.error(`[hweb-auth]
|
|
112
|
+
console.error(`[hweb-auth] Signout error on provider ${provider.id}:`, error);
|
|
113
113
|
}
|
|
114
114
|
}
|
|
115
115
|
}
|
package/src/auth/react.tsx
CHANGED
|
@@ -61,7 +61,7 @@ export function SessionProvider({
|
|
|
61
61
|
return null;
|
|
62
62
|
}
|
|
63
63
|
} catch (error) {
|
|
64
|
-
console.error('[hweb-auth]
|
|
64
|
+
console.error('[hweb-auth] Error fetching session:', error);
|
|
65
65
|
setSession(null);
|
|
66
66
|
setStatus('unauthenticated');
|
|
67
67
|
return null;
|
|
@@ -125,7 +125,7 @@ export function SessionProvider({
|
|
|
125
125
|
};
|
|
126
126
|
}
|
|
127
127
|
} catch (error) {
|
|
128
|
-
console.error('[hweb-auth]
|
|
128
|
+
console.error('[hweb-auth] Error on signIn:', error);
|
|
129
129
|
return {
|
|
130
130
|
error: 'Network error',
|
|
131
131
|
status: 500,
|
|
@@ -153,7 +153,7 @@ export function SessionProvider({
|
|
|
153
153
|
}
|
|
154
154
|
}
|
|
155
155
|
} catch (error) {
|
|
156
|
-
console.error('[hweb-auth]
|
|
156
|
+
console.error('[hweb-auth] Error on signOut:', error);
|
|
157
157
|
}
|
|
158
158
|
}, [basePath]);
|
|
159
159
|
|
|
@@ -215,7 +215,7 @@ export function SessionProvider({
|
|
|
215
215
|
export function useSession(): SessionContextType {
|
|
216
216
|
const context = useContext(SessionContext);
|
|
217
217
|
if (context === undefined) {
|
|
218
|
-
throw new Error('useSession
|
|
218
|
+
throw new Error('useSession must be used inside a SessionProvider');
|
|
219
219
|
}
|
|
220
220
|
return context;
|
|
221
221
|
}
|
package/src/auth/routes.ts
CHANGED
|
@@ -167,7 +167,7 @@ async function handleSignIn(req: HightJSRequest, auth: HWebAuth) {
|
|
|
167
167
|
type: 'session'
|
|
168
168
|
});
|
|
169
169
|
} catch (error) {
|
|
170
|
-
console.error('[hweb-auth]
|
|
170
|
+
console.error('[hweb-auth] Error on handleSignIn:', error);
|
|
171
171
|
return HightJSResponse.json(
|
|
172
172
|
{ error: 'Authentication failed' },
|
|
173
173
|
{ status: 500 }
|