hightjs 0.3.5 → 0.5.0

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 (123) hide show
  1. package/README.md +48 -116
  2. package/dist/bin/hightjs.js +51 -23
  3. package/dist/builder.js +198 -8
  4. package/dist/client/DefaultNotFound.d.ts +1 -1
  5. package/dist/client/DefaultNotFound.js +72 -46
  6. package/dist/client/client.d.ts +3 -0
  7. package/dist/{client.js → client/client.js} +4 -4
  8. package/dist/client/entry.client.js +77 -9
  9. package/dist/global/global.d.ts +117 -0
  10. package/dist/{auth/types.js → global/global.js} +0 -1
  11. package/dist/helpers.js +80 -2
  12. package/dist/hotReload.js +84 -4
  13. package/dist/index.js +72 -61
  14. package/dist/loaders.d.ts +1 -0
  15. package/dist/loaders.js +46 -0
  16. package/dist/renderer.js +158 -4
  17. package/dist/types.d.ts +44 -0
  18. package/package.json +37 -30
  19. package/.idea/HightJS.iml +0 -9
  20. package/.idea/copilot.data.migration.agent.xml +0 -6
  21. package/.idea/copilot.data.migration.ask.xml +0 -6
  22. package/.idea/copilot.data.migration.ask2agent.xml +0 -6
  23. package/.idea/copilot.data.migration.edit.xml +0 -6
  24. package/.idea/copilotDiffState.xml +0 -67
  25. package/.idea/inspectionProfiles/Project_Default.xml +0 -13
  26. package/.idea/libraries/test_package.xml +0 -9
  27. package/.idea/libraries/ts_commonjs_default_export.xml +0 -9
  28. package/.idea/misc.xml +0 -7
  29. package/.idea/modules.xml +0 -8
  30. package/.idea/vcs.xml +0 -6
  31. package/dist/auth/client.d.ts +0 -24
  32. package/dist/auth/client.js +0 -146
  33. package/dist/auth/components.d.ts +0 -29
  34. package/dist/auth/components.js +0 -100
  35. package/dist/auth/core.d.ts +0 -55
  36. package/dist/auth/core.js +0 -189
  37. package/dist/auth/index.d.ts +0 -7
  38. package/dist/auth/index.js +0 -45
  39. package/dist/auth/jwt.d.ts +0 -41
  40. package/dist/auth/jwt.js +0 -185
  41. package/dist/auth/providers/credentials.d.ts +0 -60
  42. package/dist/auth/providers/credentials.js +0 -97
  43. package/dist/auth/providers/discord.d.ts +0 -63
  44. package/dist/auth/providers/discord.js +0 -190
  45. package/dist/auth/providers/google.d.ts +0 -63
  46. package/dist/auth/providers/google.js +0 -186
  47. package/dist/auth/providers/index.d.ts +0 -2
  48. package/dist/auth/providers/index.js +0 -35
  49. package/dist/auth/providers.d.ts +0 -3
  50. package/dist/auth/providers.js +0 -26
  51. package/dist/auth/react/index.d.ts +0 -6
  52. package/dist/auth/react/index.js +0 -48
  53. package/dist/auth/react.d.ts +0 -22
  54. package/dist/auth/react.js +0 -199
  55. package/dist/auth/routes.d.ts +0 -16
  56. package/dist/auth/routes.js +0 -152
  57. package/dist/auth/types.d.ts +0 -76
  58. package/dist/client.d.ts +0 -3
  59. package/docs/README.md +0 -58
  60. package/docs/arquivos-especiais.md +0 -10
  61. package/docs/autenticacao.md +0 -212
  62. package/docs/checklist.md +0 -9
  63. package/docs/cli.md +0 -72
  64. package/docs/config.md +0 -216
  65. package/docs/estrutura.md +0 -20
  66. package/docs/faq.md +0 -10
  67. package/docs/hot-reload.md +0 -5
  68. package/docs/integracoes.md +0 -240
  69. package/docs/middlewares.md +0 -73
  70. package/docs/rotas-backend.md +0 -45
  71. package/docs/rotas-frontend.md +0 -66
  72. package/docs/seguranca.md +0 -8
  73. package/docs/websocket.md +0 -45
  74. package/example/certs/cert.pem +0 -20
  75. package/example/certs/key.pem +0 -27
  76. package/example/hightjs.config.ts +0 -87
  77. package/example/package-lock.json +0 -1174
  78. package/example/package.json +0 -26
  79. package/example/postcss.config.js +0 -8
  80. package/example/src/auth.ts +0 -42
  81. package/example/src/web/backend/routes/auth.ts +0 -3
  82. package/example/src/web/backend/routes/version.ts +0 -13
  83. package/example/src/web/globals.css +0 -5
  84. package/example/src/web/layout.tsx +0 -100
  85. package/example/src/web/routes/index.tsx +0 -153
  86. package/example/src/web/routes/login.tsx +0 -175
  87. package/example/tailwind.config.js +0 -12
  88. package/example/tsconfig.json +0 -15
  89. package/src/adapters/express.ts +0 -87
  90. package/src/adapters/factory.ts +0 -112
  91. package/src/adapters/fastify.ts +0 -104
  92. package/src/adapters/native.ts +0 -234
  93. package/src/api/console.ts +0 -305
  94. package/src/api/http.ts +0 -535
  95. package/src/auth/client.ts +0 -171
  96. package/src/auth/components.tsx +0 -125
  97. package/src/auth/core.ts +0 -215
  98. package/src/auth/index.ts +0 -25
  99. package/src/auth/jwt.ts +0 -210
  100. package/src/auth/providers/credentials.ts +0 -139
  101. package/src/auth/providers/discord.ts +0 -239
  102. package/src/auth/providers/google.ts +0 -234
  103. package/src/auth/providers/index.ts +0 -20
  104. package/src/auth/providers.ts +0 -20
  105. package/src/auth/react/index.ts +0 -25
  106. package/src/auth/react.tsx +0 -234
  107. package/src/auth/routes.ts +0 -183
  108. package/src/auth/types.ts +0 -108
  109. package/src/bin/hightjs.js +0 -222
  110. package/src/builder.js +0 -411
  111. package/src/client/DefaultNotFound.tsx +0 -84
  112. package/src/client/clientRouter.ts +0 -153
  113. package/src/client/entry.client.tsx +0 -444
  114. package/src/client.ts +0 -24
  115. package/src/components/Link.tsx +0 -38
  116. package/src/helpers.ts +0 -542
  117. package/src/hotReload.ts +0 -489
  118. package/src/index.ts +0 -546
  119. package/src/renderer.tsx +0 -263
  120. package/src/router.ts +0 -730
  121. package/src/types/framework.ts +0 -58
  122. package/src/types.ts +0 -207
  123. package/tsconfig.json +0 -17
package/src/renderer.tsx DELETED
@@ -1,263 +0,0 @@
1
- /*
2
- * This file is part of the HightJS Project.
3
- * Copyright (c) 2025 itsmuzin
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- */
17
- import React from 'react';
18
- import { RouteConfig, Metadata } from './types';
19
- import { getLayout } from './router';
20
- import type { GenericRequest } from './types/framework';
21
- import fs from 'fs';
22
- import path from 'path';
23
-
24
- // Função para gerar todas as meta tags
25
- function generateMetaTags(metadata: Metadata): string {
26
- const tags: string[] = [];
27
-
28
- // Charset
29
- tags.push(`<meta charset="${metadata.charset || 'UTF-8'}">`);
30
-
31
- // Viewport
32
- tags.push(`<meta name="viewport" content="${metadata.viewport || 'width=device-width, initial-scale=1.0'}">`);
33
-
34
- // Description
35
- if (metadata.description) {
36
- tags.push(`<meta name="description" content="${metadata.description}">`);
37
- }
38
-
39
- // Keywords
40
- if (metadata.keywords) {
41
- const keywordsStr = Array.isArray(metadata.keywords)
42
- ? metadata.keywords.join(', ')
43
- : metadata.keywords;
44
- tags.push(`<meta name="keywords" content="${keywordsStr}">`);
45
- }
46
-
47
- // Author
48
- if (metadata.author) {
49
- tags.push(`<meta name="author" content="${metadata.author}">`);
50
- }
51
-
52
- // Theme color
53
- if (metadata.themeColor) {
54
- tags.push(`<meta name="theme-color" content="${metadata.themeColor}">`);
55
- }
56
-
57
- // Robots
58
- if (metadata.robots) {
59
- tags.push(`<meta name="robots" content="${metadata.robots}">`);
60
- }
61
-
62
- // Canonical
63
- if (metadata.canonical) {
64
- tags.push(`<link rel="canonical" href="${metadata.canonical}">`);
65
- }
66
-
67
- // Favicon
68
- if (metadata.favicon) {
69
- tags.push(`<link rel="icon" href="${metadata.favicon}">`);
70
- }
71
-
72
- // Apple Touch Icon
73
- if (metadata.appleTouchIcon) {
74
- tags.push(`<link rel="apple-touch-icon" href="${metadata.appleTouchIcon}">`);
75
- }
76
-
77
- // Manifest
78
- if (metadata.manifest) {
79
- tags.push(`<link rel="manifest" href="${metadata.manifest}">`);
80
- }
81
-
82
- // Open Graph
83
- if (metadata.openGraph) {
84
- const og = metadata.openGraph;
85
- if (og.title) tags.push(`<meta property="og:title" content="${og.title}">`);
86
- if (og.description) tags.push(`<meta property="og:description" content="${og.description}">`);
87
- if (og.type) tags.push(`<meta property="og:type" content="${og.type}">`);
88
- if (og.url) tags.push(`<meta property="og:url" content="${og.url}">`);
89
- if (og.siteName) tags.push(`<meta property="og:site_name" content="${og.siteName}">`);
90
- if (og.locale) tags.push(`<meta property="og:locale" content="${og.locale}">`);
91
-
92
- if (og.image) {
93
- if (typeof og.image === 'string') {
94
- tags.push(`<meta property="og:image" content="${og.image}">`);
95
- } else {
96
- tags.push(`<meta property="og:image" content="${og.image.url}">`);
97
- if (og.image.width) tags.push(`<meta property="og:image:width" content="${og.image.width}">`);
98
- if (og.image.height) tags.push(`<meta property="og:image:height" content="${og.image.height}">`);
99
- if (og.image.alt) tags.push(`<meta property="og:image:alt" content="${og.image.alt}">`);
100
- }
101
- }
102
- }
103
-
104
- // Twitter Card
105
- if (metadata.twitter) {
106
- const tw = metadata.twitter;
107
- if (tw.card) tags.push(`<meta name="twitter:card" content="${tw.card}">`);
108
- if (tw.site) tags.push(`<meta name="twitter:site" content="${tw.site}">`);
109
- if (tw.creator) tags.push(`<meta name="twitter:creator" content="${tw.creator}">`);
110
- if (tw.title) tags.push(`<meta name="twitter:title" content="${tw.title}">`);
111
- if (tw.description) tags.push(`<meta name="twitter:description" content="${tw.description}">`);
112
- if (tw.image) tags.push(`<meta name="twitter:image" content="${tw.image}">`);
113
- if (tw.imageAlt) tags.push(`<meta name="twitter:image:alt" content="${tw.imageAlt}">`);
114
- }
115
-
116
- // Custom meta tags
117
- if (metadata.other) {
118
- for (const [key, value] of Object.entries(metadata.other)) {
119
- tags.push(`<meta name="${key}" content="${value}">`);
120
- }
121
- }
122
-
123
- return tags.join('\n');
124
- }
125
-
126
- // Função para ofuscar dados (não é criptografia, apenas ofuscação)
127
- function obfuscateData(data: any): string {
128
- // 1. Serializa para JSON minificado
129
- const jsonStr = JSON.stringify(data);
130
-
131
- // 2. Converte para base64
132
- const base64 = Buffer.from(jsonStr).toString('base64');
133
-
134
- // 3. Adiciona um hash fake no início para parecer um token
135
- const hash = Buffer.from(Date.now().toString()).toString('base64').substring(0, 8);
136
-
137
- return `${hash}.${base64}`;
138
- }
139
-
140
- // Função para criar script ofuscado
141
- function createInitialDataScript(data: any): string {
142
- const obfuscated = obfuscateData(data);
143
-
144
- // Usa um atributo data-* ao invés de JSON visível
145
- return `<script id="__hight_data__" type="text/plain" data-h="${obfuscated}"></script>`;
146
- }
147
-
148
- // Interface para opções de renderização apenas do cliente
149
- interface RenderOptions {
150
- req: GenericRequest;
151
- route: RouteConfig & { componentPath: string };
152
- params: Record<string, string>;
153
- allRoutes: (RouteConfig & { componentPath: string })[];
154
- }
155
-
156
- export async function render({ req, route, params, allRoutes }: RenderOptions): Promise<string> {
157
- const { generateMetadata } = route;
158
-
159
- // Pega a opção dev e hot reload manager do req
160
- const isProduction = !(req as any).hwebDev;
161
- const hotReloadManager = (req as any).hotReloadManager;
162
-
163
- // Pega o layout se existir
164
- const layout = getLayout();
165
-
166
- let metadata: Metadata = { title: 'App hweb' };
167
-
168
- // Primeiro usa o metadata do layout se existir
169
- if (layout && layout.metadata) {
170
- metadata = { ...metadata, ...layout.metadata };
171
- }
172
-
173
- // Depois sobrescreve com metadata específico da rota se existir
174
- if (generateMetadata) {
175
- const routeMetadata = await Promise.resolve(generateMetadata(params, req));
176
- metadata = { ...metadata, ...routeMetadata };
177
- }
178
-
179
- // Prepara os dados para injetar na janela do navegador
180
- const initialData = {
181
- routes: allRoutes.map(r => ({ pattern: r.pattern, componentPath: r.componentPath })),
182
- initialComponentPath: route.componentPath,
183
- initialParams: params,
184
- };
185
-
186
- // Cria script JSON limpo
187
- const initialDataScript = createInitialDataScript(initialData);
188
-
189
- // Script de hot reload apenas em desenvolvimento
190
- const hotReloadScript = !isProduction && hotReloadManager
191
- ? hotReloadManager.getClientScript()
192
- : '';
193
-
194
- // Gera todas as meta tags
195
- const metaTags = generateMetaTags(metadata);
196
-
197
- // Determina quais arquivos JavaScript carregar
198
- const jsFiles = getJavaScriptFiles(req);
199
-
200
- const htmlLang = metadata.language || 'pt-BR';
201
-
202
- // HTML base sem SSR - apenas o container e scripts para client-side rendering
203
- return `<!DOCTYPE html>
204
- <html lang="${htmlLang}">
205
- <head>
206
- ${metaTags}
207
- <title>${metadata.title || 'App hweb'}</title>
208
- </head>
209
- <body>
210
- <div id="root"></div>
211
- ${initialDataScript}
212
- ${jsFiles}
213
- ${hotReloadScript}
214
- </body>
215
- </html>`;
216
- }
217
-
218
- // Função para determinar quais arquivos JavaScript carregar
219
- function getJavaScriptFiles(req: GenericRequest): string {
220
- const projectDir = process.cwd();
221
- const distDir = path.join(projectDir, '.hight');
222
-
223
- try {
224
- // Verifica se existe um manifesto de chunks (gerado pelo ESBuild com splitting)
225
- const manifestPath = path.join(distDir, 'manifest.json');
226
-
227
- if (fs.existsSync(manifestPath)) {
228
- // Modo chunks - carrega todos os arquivos necessários
229
- const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));
230
- const scripts = Object.values(manifest)
231
- .filter((file: any) => file.endsWith('.js'))
232
- .map((file: any) => `<script src="/_hight/${file}"></script>`)
233
- .join('');
234
- return scripts;
235
- } else {
236
- // Verifica se existem múltiplos arquivos JS (chunks sem manifesto)
237
- const jsFiles = fs.readdirSync(distDir)
238
- .filter(file => file.endsWith('.js') && !file.endsWith('.map'))
239
- .sort((a, b) => {
240
- // Ordena para carregar arquivos principais primeiro
241
- if (a.includes('main')) return -1;
242
- if (b.includes('main')) return 1;
243
- if (a.includes('vendor') || a.includes('react')) return -1;
244
- if (b.includes('vendor') || b.includes('react')) return 1;
245
- return a.localeCompare(b);
246
- });
247
-
248
- // @ts-ignore
249
- if (jsFiles.length >= 1) {
250
- // Modo chunks sem manifesto
251
- return jsFiles
252
- .map(file => `<script src="/_hight/${file}"></script>`)
253
- .join('');
254
- } else {
255
- // Modo tradicional - único arquivo
256
- return '<script src="/_hight/main.js"></script>';
257
- }
258
- }
259
- } catch (error) {
260
- // Fallback para o modo tradicional
261
- return '<script src="/_hight/main.js"></script>';
262
- }
263
- }