hightjs 0.4.0 → 0.5.1

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 (117) hide show
  1. package/README.md +42 -126
  2. package/dist/bin/hightjs.js +51 -23
  3. package/dist/builder.js +139 -4
  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 +39 -29
  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 +2 -2
  13. package/dist/index.js +16 -16
  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 -31
  19. package/src/bin/hightjs.js +59 -29
  20. package/src/builder.js +163 -4
  21. package/src/client/DefaultNotFound.tsx +88 -53
  22. package/src/{client.ts → client/client.ts} +4 -3
  23. package/src/client/entry.client.tsx +44 -29
  24. package/src/global/global.ts +171 -0
  25. package/src/helpers.ts +91 -2
  26. package/src/hotReload.ts +2 -2
  27. package/src/index.ts +2 -0
  28. package/src/loaders.js +53 -0
  29. package/src/renderer.tsx +162 -4
  30. package/src/types.ts +51 -0
  31. package/.idea/HightJS.iml +0 -9
  32. package/.idea/copilot.data.migration.agent.xml +0 -6
  33. package/.idea/copilot.data.migration.ask.xml +0 -6
  34. package/.idea/copilot.data.migration.ask2agent.xml +0 -6
  35. package/.idea/copilot.data.migration.edit.xml +0 -6
  36. package/.idea/copilotDiffState.xml +0 -67
  37. package/.idea/inspectionProfiles/Project_Default.xml +0 -13
  38. package/.idea/libraries/test_package.xml +0 -9
  39. package/.idea/libraries/ts_commonjs_default_export.xml +0 -9
  40. package/.idea/misc.xml +0 -7
  41. package/.idea/modules.xml +0 -8
  42. package/.idea/vcs.xml +0 -6
  43. package/dist/auth/client.d.ts +0 -24
  44. package/dist/auth/client.js +0 -146
  45. package/dist/auth/components.d.ts +0 -29
  46. package/dist/auth/components.js +0 -100
  47. package/dist/auth/core.d.ts +0 -55
  48. package/dist/auth/core.js +0 -189
  49. package/dist/auth/index.d.ts +0 -7
  50. package/dist/auth/index.js +0 -45
  51. package/dist/auth/jwt.d.ts +0 -41
  52. package/dist/auth/jwt.js +0 -185
  53. package/dist/auth/providers/credentials.d.ts +0 -60
  54. package/dist/auth/providers/credentials.js +0 -97
  55. package/dist/auth/providers/discord.d.ts +0 -63
  56. package/dist/auth/providers/discord.js +0 -190
  57. package/dist/auth/providers/google.d.ts +0 -63
  58. package/dist/auth/providers/google.js +0 -186
  59. package/dist/auth/providers/index.d.ts +0 -2
  60. package/dist/auth/providers/index.js +0 -35
  61. package/dist/auth/providers.d.ts +0 -3
  62. package/dist/auth/providers.js +0 -26
  63. package/dist/auth/react/index.d.ts +0 -6
  64. package/dist/auth/react/index.js +0 -48
  65. package/dist/auth/react.d.ts +0 -22
  66. package/dist/auth/react.js +0 -199
  67. package/dist/auth/routes.d.ts +0 -16
  68. package/dist/auth/routes.js +0 -152
  69. package/dist/auth/types.d.ts +0 -76
  70. package/dist/client.d.ts +0 -3
  71. package/docs/README.md +0 -58
  72. package/docs/arquivos-especiais.md +0 -10
  73. package/docs/autenticacao.md +0 -212
  74. package/docs/checklist.md +0 -9
  75. package/docs/cli.md +0 -72
  76. package/docs/config.md +0 -216
  77. package/docs/estrutura.md +0 -20
  78. package/docs/faq.md +0 -10
  79. package/docs/hot-reload.md +0 -5
  80. package/docs/integracoes.md +0 -240
  81. package/docs/middlewares.md +0 -73
  82. package/docs/rotas-backend.md +0 -45
  83. package/docs/rotas-frontend.md +0 -66
  84. package/docs/seguranca.md +0 -8
  85. package/docs/websocket.md +0 -45
  86. package/example/certs/cert.pem +0 -20
  87. package/example/certs/key.pem +0 -27
  88. package/example/hightjs.config.ts +0 -87
  89. package/example/package-lock.json +0 -1174
  90. package/example/package.json +0 -26
  91. package/example/postcss.config.js +0 -8
  92. package/example/src/backend/auth.ts +0 -42
  93. package/example/src/backend/routes/auth.ts +0 -3
  94. package/example/src/backend/routes/version.ts +0 -13
  95. package/example/src/web/components/Home.tsx +0 -140
  96. package/example/src/web/components/LoginPage.tsx +0 -149
  97. package/example/src/web/globals.css +0 -5
  98. package/example/src/web/layout.tsx +0 -100
  99. package/example/src/web/routes/index.tsx +0 -13
  100. package/example/src/web/routes/login.tsx +0 -30
  101. package/example/tailwind.config.js +0 -12
  102. package/example/tsconfig.json +0 -15
  103. package/src/auth/client.ts +0 -171
  104. package/src/auth/components.tsx +0 -125
  105. package/src/auth/core.ts +0 -215
  106. package/src/auth/index.ts +0 -25
  107. package/src/auth/jwt.ts +0 -210
  108. package/src/auth/providers/credentials.ts +0 -139
  109. package/src/auth/providers/discord.ts +0 -239
  110. package/src/auth/providers/google.ts +0 -234
  111. package/src/auth/providers/index.ts +0 -20
  112. package/src/auth/providers.ts +0 -20
  113. package/src/auth/react/index.ts +0 -25
  114. package/src/auth/react.tsx +0 -234
  115. package/src/auth/routes.ts +0 -183
  116. package/src/auth/types.ts +0 -108
  117. package/tsconfig.json +0 -17
@@ -1,183 +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 { HightJSRequest, HightJSResponse } from '../api/http';
18
- import type { AuthConfig } from './types';
19
- import { HWebAuth } from './core';
20
- import Console from "../api/console";
21
-
22
- /**
23
- * Cria o handler catch-all para /api/auth/[...value]
24
- */
25
- export function createAuthRoutes(config: AuthConfig) {
26
- const auth = new HWebAuth(config);
27
-
28
- /**
29
- * Handler principal que gerencia todas as rotas de auth
30
- * Uso: /api/auth/[...value].ts
31
- */
32
- return {
33
- pattern: '/api/auth/[...value]',
34
-
35
- async GET(req: HightJSRequest, params: { [key: string]: string }) {
36
-
37
- const path = params["value"];
38
- const route = Array.isArray(path) ? path.join('/') : path || '';
39
-
40
- // Verifica rotas adicionais dos providers primeiro
41
- const additionalRoutes = auth.getAllAdditionalRoutes();
42
- for (const { provider, route: additionalRoute } of additionalRoutes) {
43
-
44
- if (additionalRoute.method === 'GET' && additionalRoute.path.includes(route)) {
45
- try {
46
- return await additionalRoute.handler(req, params);
47
- } catch (error) {
48
- console.error(`[${provider} Provider] Error in additional route:`, error);
49
- return HightJSResponse.json({ error: 'Provider route error' }, { status: 500 });
50
- }
51
- }
52
- }
53
-
54
- // Rotas padrão do sistema
55
- switch (route) {
56
- case 'session':
57
- return await handleSession(req, auth);
58
-
59
- case 'csrf':
60
- return await handleCsrf(req);
61
-
62
- case 'providers':
63
- return await handleProviders(auth);
64
-
65
- default:
66
- return HightJSResponse.json({ error: 'Route not found' }, { status: 404 });
67
- }
68
- },
69
-
70
- async POST(req: HightJSRequest, params: { [key: string]: string }) {
71
- const path = params["value"];
72
- const route = Array.isArray(path) ? path.join('/') : path || '';
73
-
74
- // Verifica rotas adicionais dos providers primeiro
75
- const additionalRoutes = auth.getAllAdditionalRoutes();
76
- for (const { provider, route: additionalRoute } of additionalRoutes) {
77
- if (additionalRoute.method === 'POST' && additionalRoute.path.includes(route)) {
78
- try {
79
- return await additionalRoute.handler(req, params);
80
- } catch (error) {
81
- console.error(`[${provider} Provider] Error in additional route:`, error);
82
- return HightJSResponse.json({ error: 'Provider route error' }, { status: 500 });
83
- }
84
- }
85
- }
86
-
87
- // Rotas padrão do sistema
88
- switch (route) {
89
- case 'signin':
90
- return await handleSignIn(req, auth);
91
-
92
- case 'signout':
93
- return await handleSignOut(req, auth);
94
-
95
- default:
96
- return HightJSResponse.json({ error: 'Route not found' }, { status: 404 });
97
- }
98
- },
99
-
100
- // Instância do auth para uso manual
101
- auth
102
- };
103
- }
104
-
105
- /**
106
- * Handler para GET /api/auth/session
107
- */
108
- async function handleSession(req: HightJSRequest, auth: HWebAuth) {
109
- const session = await auth.getSession(req);
110
-
111
- if (!session) {
112
- return HightJSResponse.json({ session: null });
113
- }
114
-
115
- return HightJSResponse.json({ session });
116
- }
117
-
118
- /**
119
- * Handler para GET /api/auth/csrf
120
- */
121
- async function handleCsrf(req: HightJSRequest) {
122
- // Token CSRF simples para proteção
123
- const csrfToken = Math.random().toString(36).substring(2, 15) +
124
- Math.random().toString(36).substring(2, 15);
125
-
126
- return HightJSResponse.json({ csrfToken });
127
- }
128
-
129
- /**
130
- * Handler para GET /api/auth/providers
131
- */
132
- async function handleProviders(auth: HWebAuth) {
133
- const providers = auth.getProviders();
134
-
135
- return HightJSResponse.json({ providers });
136
- }
137
-
138
- /**
139
- * Handler para POST /api/auth/signin
140
- */
141
- async function handleSignIn(req: HightJSRequest, auth: HWebAuth) {
142
- try {
143
- const { provider = 'credentials', ...credentials } = await req.json();
144
-
145
- const result = await auth.signIn(provider, credentials);
146
-
147
- if (!result) {
148
- return HightJSResponse.json(
149
- { error: 'Invalid credentials' },
150
- { status: 401 }
151
- );
152
- }
153
-
154
- // Se tem redirectUrl, é OAuth - retorna URL para redirecionamento
155
- if ('redirectUrl' in result) {
156
- return HightJSResponse.json({
157
- success: true,
158
- redirectUrl: result.redirectUrl,
159
- type: 'oauth'
160
- });
161
- }
162
-
163
- // Se tem session, é credentials - retorna sessão
164
- return auth.createAuthResponse(result.token, {
165
- success: true,
166
- user: result.session.user,
167
- type: 'session'
168
- });
169
- } catch (error) {
170
- console.error('[hweb-auth] Error on handleSignIn:', error);
171
- return HightJSResponse.json(
172
- { error: 'Authentication failed' },
173
- { status: 500 }
174
- );
175
- }
176
- }
177
-
178
- /**
179
- * Handler para POST /api/auth/signout
180
- */
181
- async function handleSignOut(req: HightJSRequest, auth: HWebAuth) {
182
- return await auth.signOut(req);
183
- }
package/src/auth/types.ts DELETED
@@ -1,108 +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
-
18
- // Tipos para o sistema de autenticação
19
- export type User = Record<string, any>;
20
-
21
- export interface Session {
22
- user: User;
23
- expires: string;
24
- accessToken?: string;
25
- }
26
-
27
- // Client-side types
28
- export interface SignInOptions {
29
- redirect?: boolean;
30
- callbackUrl?: string;
31
- [key: string]: any;
32
- }
33
-
34
- export interface SignInResult {
35
- error?: string;
36
- status?: number;
37
- ok?: boolean;
38
- url?: string;
39
- }
40
-
41
- export interface SessionContextType {
42
- data: Session | null;
43
- status: 'loading' | 'authenticated' | 'unauthenticated';
44
- signIn: (provider?: string, options?: SignInOptions) => Promise<SignInResult | undefined>;
45
- signOut: (options?: { callbackUrl?: string }) => Promise<void>;
46
- update: () => Promise<Session | null>;
47
- }
48
-
49
- export interface AuthRoute {
50
- method: 'GET' | 'POST' | 'PUT' | 'DELETE';
51
- path: string;
52
- handler: (req: any, params: any) => Promise<any>;
53
- }
54
-
55
- export interface AuthProviderClass {
56
- id: string;
57
- name: string;
58
- type: string;
59
-
60
- // Para providers OAuth - retorna URL de redirecionamento
61
- handleOauth?(credentials: Record<string, string>): Promise<string> | string;
62
-
63
- // Métodos principais
64
- handleSignIn(credentials: Record<string, string>): Promise<User | string | null>;
65
- handleSignOut?(): Promise<void>;
66
-
67
- // Rotas adicionais que o provider pode ter
68
- additionalRoutes?: AuthRoute[];
69
-
70
- // Configurações específicas do provider
71
- getConfig?(): any;
72
- }
73
-
74
- export interface AuthConfig {
75
- providers: AuthProviderClass[];
76
- pages?: {
77
- signIn?: string;
78
- signOut?: string;
79
- error?: string;
80
- };
81
- callbacks?: {
82
- signIn?: (user: User, account: any, profile: any) => boolean | Promise<boolean>;
83
- session?: ({session, user, provider}: {session: Session, user: User, provider: string}) => Session | Promise<Session>;
84
- jwt?: (token: any, user: User, account: any, profile: any) => any | Promise<any>;
85
- };
86
- session?: {
87
- strategy?: 'jwt' | 'database';
88
- maxAge?: number;
89
- updateAge?: number;
90
- };
91
- secret?: string;
92
- debug?: boolean;
93
- secureCookies?: boolean;
94
- }
95
-
96
-
97
-
98
- // Provider para credenciais
99
- export interface CredentialsConfig {
100
- id?: string;
101
- name?: string;
102
- credentials: Record<string, {
103
- label: string;
104
- type: string;
105
- placeholder?: string;
106
- }>;
107
- authorize: (credentials: Record<string, string>) => Promise<User | null> | User | null;
108
- }
package/tsconfig.json DELETED
@@ -1,17 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2020",
4
- "module": "CommonJS",
5
- "rootDir": "./src",
6
- "outDir": "./dist",
7
- "declaration": true,
8
- "strict": true,
9
- "esModuleInterop": true,
10
- "skipLibCheck": true,
11
- "jsx": "react-jsx",
12
- "moduleResolution": "node",
13
- "allowJs": true,
14
- },
15
- "include": ["src"],
16
- "exclude": ["node_modules"]
17
- }