hightjs 0.3.3 → 0.3.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/dist/adapters/factory.js +8 -8
- package/dist/adapters/native.js +3 -3
- package/dist/api/console.js +1 -1
- 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 +32 -331
- package/dist/builder.js +7 -19
- package/dist/client/DefaultNotFound.js +1 -1
- package/dist/client/entry.client.js +98 -8
- package/dist/helpers.d.ts +1 -0
- package/dist/helpers.js +130 -29
- package/dist/hotReload.js +25 -16
- package/dist/index.d.ts +1 -1
- package/dist/index.js +26 -36
- package/dist/renderer.js +137 -18
- package/dist/router.js +133 -62
- package/dist/types.d.ts +81 -0
- package/docs/config.md +216 -0
- package/example/hightjs.config.ts +87 -0
- package/example/package-lock.json +633 -3054
- package/example/package.json +3 -3
- package/example/src/web/layout.tsx +57 -3
- package/example/src/web/routes/index.tsx +1 -1
- package/package.json +1 -1
- package/src/adapters/factory.ts +8 -8
- package/src/adapters/native.ts +3 -3
- package/src/api/console.ts +3 -1
- 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 +33 -394
- package/src/builder.js +7 -20
- package/src/client/DefaultNotFound.tsx +1 -1
- package/src/client/entry.client.tsx +125 -10
- package/src/helpers.ts +144 -30
- package/src/hotReload.ts +25 -16
- package/src/index.ts +33 -39
- package/src/renderer.tsx +142 -18
- package/src/router.ts +142 -63
- package/src/types.ts +108 -0
- package/example/.hweb/entry.client.js +0 -24
- package/example/hweb-dist/main-5KKAYNUU.js +0 -1137
package/dist/adapters/factory.js
CHANGED
|
@@ -50,40 +50,40 @@ class FrameworkAdapterFactory {
|
|
|
50
50
|
if (this.adapter) {
|
|
51
51
|
return this.adapter;
|
|
52
52
|
}
|
|
53
|
-
const msg = console_1.default.dynamicLine(` ${console_1.Colors.FgYellow}● ${console_1.Colors.Reset}
|
|
53
|
+
const msg = console_1.default.dynamicLine(` ${console_1.Colors.FgYellow}● ${console_1.Colors.Reset}Detecting web framework...`);
|
|
54
54
|
// Detecta Express
|
|
55
55
|
if (req.app && req.route && res.locals !== undefined) {
|
|
56
|
-
msg.end(` ${console_1.Colors.FgGreen}● ${console_1.Colors.Reset}Framework
|
|
56
|
+
msg.end(` ${console_1.Colors.FgGreen}● ${console_1.Colors.Reset}Framework detected: Express`);
|
|
57
57
|
this.adapter = new express_1.ExpressAdapter();
|
|
58
58
|
return this.adapter;
|
|
59
59
|
}
|
|
60
60
|
// Detecta Fastify
|
|
61
61
|
if (req.server && req.routerPath !== undefined && res.request) {
|
|
62
|
-
msg.end(` ${console_1.Colors.FgGreen}● ${console_1.Colors.Reset}Framework
|
|
62
|
+
msg.end(` ${console_1.Colors.FgGreen}● ${console_1.Colors.Reset}Framework detected: Fastify`);
|
|
63
63
|
this.adapter = new fastify_1.FastifyAdapter();
|
|
64
64
|
return this.adapter;
|
|
65
65
|
}
|
|
66
66
|
// Detecta HTTP nativo do Node.js
|
|
67
67
|
if (req.method !== undefined && req.url !== undefined && req.headers !== undefined &&
|
|
68
68
|
res.statusCode !== undefined && res.setHeader !== undefined && res.end !== undefined) {
|
|
69
|
-
msg.end(` ${console_1.Colors.FgGreen}● ${console_1.Colors.Reset}Framework
|
|
69
|
+
msg.end(` ${console_1.Colors.FgGreen}● ${console_1.Colors.Reset}Framework detected: HightJS Native (HTTP)`);
|
|
70
70
|
this.adapter = new native_1.NativeAdapter();
|
|
71
71
|
return this.adapter;
|
|
72
72
|
}
|
|
73
73
|
// Fallback mais específico para Express
|
|
74
74
|
if (res.status && res.send && res.json && res.cookie) {
|
|
75
|
-
msg.end(` ${console_1.Colors.FgGreen}● ${console_1.Colors.Reset}Framework
|
|
75
|
+
msg.end(` ${console_1.Colors.FgGreen}● ${console_1.Colors.Reset}Framework detected: Express (fallback)`);
|
|
76
76
|
this.adapter = new express_1.ExpressAdapter();
|
|
77
77
|
return this.adapter;
|
|
78
78
|
}
|
|
79
79
|
// Fallback mais específico para Fastify
|
|
80
80
|
if (res.code && res.send && res.type && res.setCookie) {
|
|
81
|
-
msg.end(` ${console_1.Colors.FgGreen}● ${console_1.Colors.Reset}Framework
|
|
81
|
+
msg.end(` ${console_1.Colors.FgGreen}● ${console_1.Colors.Reset}Framework detected: Fastify (fallback)`);
|
|
82
82
|
this.adapter = new fastify_1.FastifyAdapter();
|
|
83
83
|
return this.adapter;
|
|
84
84
|
}
|
|
85
85
|
// Default para HightJS Native se não conseguir detectar
|
|
86
|
-
msg.end(` ${console_1.Colors.FgYellow}● ${console_1.Colors.Reset}
|
|
86
|
+
msg.end(` ${console_1.Colors.FgYellow}● ${console_1.Colors.Reset}Unable to detect framework. Using HightJS Native as default.`);
|
|
87
87
|
this.adapter = new native_1.NativeAdapter();
|
|
88
88
|
return this.adapter;
|
|
89
89
|
}
|
|
@@ -102,7 +102,7 @@ class FrameworkAdapterFactory {
|
|
|
102
102
|
this.adapter = new native_1.NativeAdapter();
|
|
103
103
|
break;
|
|
104
104
|
default:
|
|
105
|
-
throw new Error(`
|
|
105
|
+
throw new Error(`Unsupported framework: ${framework}`);
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
108
|
/**
|
package/dist/adapters/native.js
CHANGED
|
@@ -59,7 +59,7 @@ class NativeAdapter {
|
|
|
59
59
|
}
|
|
60
60
|
catch (e) {
|
|
61
61
|
// Prevenção de crash: Ignora cookies com valores malformados (e.g., URI inválida).
|
|
62
|
-
console.error(`
|
|
62
|
+
console.error(`Warning: Malformed cookie with name "${name}" was ignored.`);
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
});
|
|
@@ -88,7 +88,7 @@ class NativeResponseWrapper {
|
|
|
88
88
|
const sanitizedName = sanitizeHeaderValue(name);
|
|
89
89
|
const sanitizedValue = sanitizeHeaderValue(value);
|
|
90
90
|
if (name !== sanitizedName || String(value) !== sanitizedValue) {
|
|
91
|
-
console.warn(`
|
|
91
|
+
console.warn(`Warning: Potential HTTP Header Injection attempt detected and sanitized. Original header: "${name}"`);
|
|
92
92
|
}
|
|
93
93
|
this.headers[sanitizedName] = sanitizedValue;
|
|
94
94
|
return this;
|
|
@@ -96,7 +96,7 @@ class NativeResponseWrapper {
|
|
|
96
96
|
cookie(name, value, options) {
|
|
97
97
|
// Medida de segurança: Valida o nome do cookie.
|
|
98
98
|
if (!isValidCookieName(name)) {
|
|
99
|
-
console.error(`
|
|
99
|
+
console.error(`Error: Invalid cookie name "${name}". The cookie will not be set.`);
|
|
100
100
|
return this;
|
|
101
101
|
}
|
|
102
102
|
let cookieString = `${name}=${encodeURIComponent(value)}`;
|
package/dist/api/console.js
CHANGED
|
@@ -185,7 +185,7 @@ class Console {
|
|
|
185
185
|
}
|
|
186
186
|
}
|
|
187
187
|
static logWithout(level, colors, ...args) {
|
|
188
|
-
const color = colors
|
|
188
|
+
const color = colors ? colors : level === Levels.ERROR ? Colors.BgRed : level === Levels.WARN ? Colors.BgYellow : level === Levels.INFO ? Colors.BgMagenta : level === Levels.SUCCESS ? Colors.BgGreen : Colors.BgCyan;
|
|
189
189
|
let output = "";
|
|
190
190
|
for (const arg of args) {
|
|
191
191
|
let msg = (arg instanceof Error) ? arg.stack : (typeof arg === 'string') ? arg : JSON.stringify(arg, null, 2);
|
package/dist/auth/client.js
CHANGED
|
@@ -26,7 +26,7 @@ async function getSession() {
|
|
|
26
26
|
return data.session || null;
|
|
27
27
|
}
|
|
28
28
|
catch (error) {
|
|
29
|
-
console.error('[hweb-auth]
|
|
29
|
+
console.error('[hweb-auth] Error fetching session:', error);
|
|
30
30
|
return null;
|
|
31
31
|
}
|
|
32
32
|
}
|
|
@@ -45,7 +45,7 @@ async function getCsrfToken() {
|
|
|
45
45
|
return data.csrfToken || null;
|
|
46
46
|
}
|
|
47
47
|
catch (error) {
|
|
48
|
-
console.error('[hweb-auth]
|
|
48
|
+
console.error('[hweb-auth] Error fetching CSRF token:', error);
|
|
49
49
|
return null;
|
|
50
50
|
}
|
|
51
51
|
}
|
|
@@ -64,7 +64,7 @@ async function getProviders() {
|
|
|
64
64
|
return data.providers || [];
|
|
65
65
|
}
|
|
66
66
|
catch (error) {
|
|
67
|
-
console.error('[hweb-auth]
|
|
67
|
+
console.error('[hweb-auth] Error searching for providers:', error);
|
|
68
68
|
return null;
|
|
69
69
|
}
|
|
70
70
|
}
|
|
@@ -119,7 +119,7 @@ async function signIn(provider = 'credentials', options = {}) {
|
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
121
|
catch (error) {
|
|
122
|
-
console.error('[hweb-auth]
|
|
122
|
+
console.error('[hweb-auth] Error on signIn:', error);
|
|
123
123
|
return {
|
|
124
124
|
error: 'Network error',
|
|
125
125
|
status: 500,
|
|
@@ -141,6 +141,6 @@ async function signOut(options = {}) {
|
|
|
141
141
|
}
|
|
142
142
|
}
|
|
143
143
|
catch (error) {
|
|
144
|
-
console.error('[hweb-auth]
|
|
144
|
+
console.error('[hweb-auth] Error on signOut:', error);
|
|
145
145
|
}
|
|
146
146
|
}
|
package/dist/auth/components.js
CHANGED
|
@@ -34,7 +34,7 @@ function ProtectedRoute({ children, fallback, redirectTo = '/auth/signin', requi
|
|
|
34
34
|
const { isAuthenticated, isLoading } = (0, react_2.useAuth)();
|
|
35
35
|
// Ainda carregando
|
|
36
36
|
if (isLoading) {
|
|
37
|
-
return fallback || (0, jsx_runtime_1.jsx)("div", { children: "
|
|
37
|
+
return fallback || (0, jsx_runtime_1.jsx)("div", { children: "Loading..." });
|
|
38
38
|
}
|
|
39
39
|
// Requer auth mas não está autenticado
|
|
40
40
|
if (requireAuth && !isAuthenticated) {
|
|
@@ -42,7 +42,7 @@ function ProtectedRoute({ children, fallback, redirectTo = '/auth/signin', requi
|
|
|
42
42
|
window.location.href = redirectTo;
|
|
43
43
|
return null;
|
|
44
44
|
}
|
|
45
|
-
return fallback || (0, jsx_runtime_1.jsx)("div", { children: "
|
|
45
|
+
return fallback || (0, jsx_runtime_1.jsx)("div", { children: "Unauthorized" });
|
|
46
46
|
}
|
|
47
47
|
// Não requer auth mas está autenticado (ex: página de login)
|
|
48
48
|
if (!requireAuth && isAuthenticated && redirectTo) {
|
package/dist/auth/core.js
CHANGED
|
@@ -76,7 +76,7 @@ class HWebAuth {
|
|
|
76
76
|
return sessionResult;
|
|
77
77
|
}
|
|
78
78
|
catch (error) {
|
|
79
|
-
console.error(`[hweb-auth]
|
|
79
|
+
console.error(`[hweb-auth] Error signing in with provider ${providerId}:`, error);
|
|
80
80
|
return null;
|
|
81
81
|
}
|
|
82
82
|
}
|
|
@@ -93,7 +93,7 @@ class HWebAuth {
|
|
|
93
93
|
await provider.handleSignOut();
|
|
94
94
|
}
|
|
95
95
|
catch (error) {
|
|
96
|
-
console.error(`[hweb-auth]
|
|
96
|
+
console.error(`[hweb-auth] Signout error on provider ${provider.id}:`, error);
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
99
|
}
|
package/dist/auth/react.js
CHANGED
|
@@ -50,7 +50,7 @@ function SessionProvider({ children, basePath = '/api/auth', refetchInterval = 0
|
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
catch (error) {
|
|
53
|
-
console.error('[hweb-auth]
|
|
53
|
+
console.error('[hweb-auth] Error fetching session:', error);
|
|
54
54
|
setSession(null);
|
|
55
55
|
setStatus('unauthenticated');
|
|
56
56
|
return null;
|
|
@@ -106,7 +106,7 @@ function SessionProvider({ children, basePath = '/api/auth', refetchInterval = 0
|
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
108
|
catch (error) {
|
|
109
|
-
console.error('[hweb-auth]
|
|
109
|
+
console.error('[hweb-auth] Error on signIn:', error);
|
|
110
110
|
return {
|
|
111
111
|
error: 'Network error',
|
|
112
112
|
status: 500,
|
|
@@ -133,7 +133,7 @@ function SessionProvider({ children, basePath = '/api/auth', refetchInterval = 0
|
|
|
133
133
|
}
|
|
134
134
|
}
|
|
135
135
|
catch (error) {
|
|
136
|
-
console.error('[hweb-auth]
|
|
136
|
+
console.error('[hweb-auth] Error on signOut:', error);
|
|
137
137
|
}
|
|
138
138
|
}, [basePath]);
|
|
139
139
|
// Update session
|
|
@@ -182,7 +182,7 @@ function SessionProvider({ children, basePath = '/api/auth', refetchInterval = 0
|
|
|
182
182
|
function useSession() {
|
|
183
183
|
const context = (0, react_1.useContext)(SessionContext);
|
|
184
184
|
if (context === undefined) {
|
|
185
|
-
throw new Error('useSession
|
|
185
|
+
throw new Error('useSession must be used inside a SessionProvider');
|
|
186
186
|
}
|
|
187
187
|
return context;
|
|
188
188
|
}
|
package/dist/auth/routes.js
CHANGED
|
@@ -140,7 +140,7 @@ async function handleSignIn(req, auth) {
|
|
|
140
140
|
});
|
|
141
141
|
}
|
|
142
142
|
catch (error) {
|
|
143
|
-
console.error('[hweb-auth]
|
|
143
|
+
console.error('[hweb-auth] Error on handleSignIn:', error);
|
|
144
144
|
return http_1.HightJSResponse.json({ error: 'Authentication failed' }, { status: 500 });
|
|
145
145
|
}
|
|
146
146
|
}
|