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.
Files changed (47) hide show
  1. package/dist/adapters/factory.js +8 -8
  2. package/dist/adapters/native.js +3 -3
  3. package/dist/api/console.js +1 -1
  4. package/dist/auth/client.js +5 -5
  5. package/dist/auth/components.js +2 -2
  6. package/dist/auth/core.js +2 -2
  7. package/dist/auth/react.js +4 -4
  8. package/dist/auth/routes.js +1 -1
  9. package/dist/bin/hightjs.js +32 -331
  10. package/dist/builder.js +7 -19
  11. package/dist/client/DefaultNotFound.js +1 -1
  12. package/dist/client/entry.client.js +98 -8
  13. package/dist/helpers.d.ts +1 -0
  14. package/dist/helpers.js +130 -29
  15. package/dist/hotReload.js +25 -16
  16. package/dist/index.d.ts +1 -1
  17. package/dist/index.js +26 -36
  18. package/dist/renderer.js +137 -18
  19. package/dist/router.js +133 -62
  20. package/dist/types.d.ts +81 -0
  21. package/docs/config.md +216 -0
  22. package/example/hightjs.config.ts +87 -0
  23. package/example/package-lock.json +633 -3054
  24. package/example/package.json +3 -3
  25. package/example/src/web/layout.tsx +57 -3
  26. package/example/src/web/routes/index.tsx +1 -1
  27. package/package.json +1 -1
  28. package/src/adapters/factory.ts +8 -8
  29. package/src/adapters/native.ts +3 -3
  30. package/src/api/console.ts +3 -1
  31. package/src/auth/client.ts +5 -5
  32. package/src/auth/components.tsx +2 -2
  33. package/src/auth/core.ts +2 -2
  34. package/src/auth/react.tsx +4 -4
  35. package/src/auth/routes.ts +1 -1
  36. package/src/bin/hightjs.js +33 -394
  37. package/src/builder.js +7 -20
  38. package/src/client/DefaultNotFound.tsx +1 -1
  39. package/src/client/entry.client.tsx +125 -10
  40. package/src/helpers.ts +144 -30
  41. package/src/hotReload.ts +25 -16
  42. package/src/index.ts +33 -39
  43. package/src/renderer.tsx +142 -18
  44. package/src/router.ts +142 -63
  45. package/src/types.ts +108 -0
  46. package/example/.hweb/entry.client.js +0 -24
  47. package/example/hweb-dist/main-5KKAYNUU.js +0 -1137
@@ -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}Detectando framework web...`);
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 detectado: Express`);
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 detectado: Fastify`);
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 detectado: HightJS Native (HTTP)`);
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 detectado: Express (fallback)`);
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 detectado: Fastify (fallback)`);
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}Não foi possível detectar o framework. Usando HightJS Native como padrão.`);
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(`Framework não suportado: ${framework}`);
105
+ throw new Error(`Unsupported framework: ${framework}`);
106
106
  }
107
107
  }
108
108
  /**
@@ -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(`Aviso: Cookie malformado com nome "${name}" foi ignorado.`);
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(`Aviso: Tentativa potencial de HTTP Header Injection foi detectada e sanitizada. Header original: "${name}"`);
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(`Erro: Nome de cookie inválido "${name}". O cookie não será definido.`);
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)}`;
@@ -185,7 +185,7 @@ class Console {
185
185
  }
186
186
  }
187
187
  static logWithout(level, colors, ...args) {
188
- const color = colors || level === Levels.ERROR ? Colors.BgRed : level === Levels.WARN ? Colors.BgYellow : level === Levels.INFO ? Colors.BgMagenta : level === Levels.SUCCESS ? Colors.BgGreen : Colors.BgCyan;
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);
@@ -26,7 +26,7 @@ async function getSession() {
26
26
  return data.session || null;
27
27
  }
28
28
  catch (error) {
29
- console.error('[hweb-auth] Erro ao buscar sessão:', error);
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] Erro ao buscar CSRF token:', error);
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] Erro ao buscar providers:', error);
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] Erro no signIn:', error);
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] Erro no signOut:', error);
144
+ console.error('[hweb-auth] Error on signOut:', error);
145
145
  }
146
146
  }
@@ -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: "Carregando..." });
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: "N\u00E3o autorizado" });
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] Erro no signIn com provider ${providerId}:`, error);
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] Erro no signOut do provider ${provider.id}:`, error);
96
+ console.error(`[hweb-auth] Signout error on provider ${provider.id}:`, error);
97
97
  }
98
98
  }
99
99
  }
@@ -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] Erro ao buscar sessão:', error);
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] Erro no signIn:', error);
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] Erro no signOut:', error);
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 deve ser usado dentro de um SessionProvider');
185
+ throw new Error('useSession must be used inside a SessionProvider');
186
186
  }
187
187
  return context;
188
188
  }
@@ -140,7 +140,7 @@ async function handleSignIn(req, auth) {
140
140
  });
141
141
  }
142
142
  catch (error) {
143
- console.error('[hweb-auth] Erro no handleSignIn:', error);
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
  }