create-fluxstack 1.0.22 → 1.4.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 (82) hide show
  1. package/app/server/backend-only.ts +5 -5
  2. package/app/server/index.ts +63 -54
  3. package/app/server/live/FluxStackConfig.ts +43 -39
  4. package/app/server/live/SystemMonitorIntegration.ts +2 -2
  5. package/app/server/live/register-components.ts +6 -26
  6. package/app/server/middleware/errorHandling.ts +6 -4
  7. package/app/server/routes/config.ts +145 -0
  8. package/app/server/routes/index.ts +5 -3
  9. package/config/app.config.ts +113 -0
  10. package/config/build.config.ts +24 -0
  11. package/config/database.config.ts +99 -0
  12. package/config/index.ts +68 -0
  13. package/config/logger.config.ts +27 -0
  14. package/config/runtime.config.ts +92 -0
  15. package/config/server.config.ts +46 -0
  16. package/config/services.config.ts +130 -0
  17. package/config/system.config.ts +105 -0
  18. package/core/build/bundler.ts +53 -5
  19. package/core/build/flux-plugins-generator.ts +315 -0
  20. package/core/build/index.ts +11 -7
  21. package/core/build/live-components-generator.ts +231 -0
  22. package/core/build/optimizer.ts +2 -54
  23. package/core/cli/index.ts +31 -13
  24. package/core/config/env.ts +38 -94
  25. package/core/config/runtime-config.ts +61 -58
  26. package/core/config/schema.ts +1 -0
  27. package/core/framework/server.ts +55 -11
  28. package/core/plugins/built-in/index.ts +7 -17
  29. package/core/plugins/built-in/static/index.ts +24 -10
  30. package/core/plugins/built-in/swagger/index.ts +228 -228
  31. package/core/plugins/built-in/vite/index.ts +374 -358
  32. package/core/plugins/dependency-manager.ts +5 -5
  33. package/core/plugins/manager.ts +57 -14
  34. package/core/plugins/registry.ts +3 -3
  35. package/core/server/index.ts +0 -1
  36. package/core/server/live/ComponentRegistry.ts +34 -8
  37. package/core/server/live/LiveComponentPerformanceMonitor.ts +1 -1
  38. package/core/server/live/websocket-plugin.ts +434 -434
  39. package/core/server/middleware/README.md +488 -0
  40. package/core/server/middleware/elysia-helpers.ts +227 -0
  41. package/core/server/middleware/index.ts +25 -9
  42. package/core/server/plugins/static-files-plugin.ts +231 -231
  43. package/core/utils/config-schema.ts +484 -0
  44. package/core/utils/env.ts +306 -0
  45. package/core/utils/helpers.ts +9 -3
  46. package/core/utils/logger/colors.ts +114 -0
  47. package/core/utils/logger/config.ts +35 -0
  48. package/core/utils/logger/formatter.ts +82 -0
  49. package/core/utils/logger/group-logger.ts +101 -0
  50. package/core/utils/logger/index.ts +199 -250
  51. package/core/utils/logger/stack-trace.ts +92 -0
  52. package/core/utils/logger/startup-banner.ts +92 -0
  53. package/core/utils/logger/winston-logger.ts +152 -0
  54. package/core/utils/version.ts +5 -0
  55. package/create-fluxstack.ts +1 -0
  56. package/fluxstack.config.ts +6 -12
  57. package/package.json +117 -114
  58. package/plugins/crypto-auth/README.md +238 -0
  59. package/plugins/crypto-auth/client/CryptoAuthClient.ts +325 -0
  60. package/plugins/crypto-auth/client/components/AuthProvider.tsx +190 -0
  61. package/plugins/crypto-auth/client/components/LoginButton.tsx +155 -0
  62. package/plugins/crypto-auth/client/components/ProtectedRoute.tsx +109 -0
  63. package/plugins/crypto-auth/client/components/SessionInfo.tsx +242 -0
  64. package/plugins/crypto-auth/client/components/index.ts +15 -0
  65. package/plugins/crypto-auth/client/index.ts +12 -0
  66. package/plugins/crypto-auth/index.ts +230 -0
  67. package/plugins/crypto-auth/package.json +65 -0
  68. package/plugins/crypto-auth/plugin.json +29 -0
  69. package/plugins/crypto-auth/server/AuthMiddleware.ts +237 -0
  70. package/plugins/crypto-auth/server/CryptoAuthService.ts +293 -0
  71. package/plugins/crypto-auth/server/index.ts +9 -0
  72. package/vite.config.ts +16 -0
  73. package/core/config/env-dynamic.ts +0 -326
  74. package/core/plugins/built-in/logger/index.ts +0 -180
  75. package/core/server/plugins/logger.ts +0 -47
  76. package/core/utils/env-runtime-v2.ts +0 -232
  77. package/core/utils/env-runtime.ts +0 -259
  78. package/core/utils/logger/formatters.ts +0 -222
  79. package/core/utils/logger/middleware.ts +0 -253
  80. package/core/utils/logger/performance.ts +0 -384
  81. package/core/utils/logger/transports.ts +0 -365
  82. package/core/utils/logger.ts +0 -106
@@ -139,7 +139,7 @@ export class PluginDependencyManager {
139
139
  */
140
140
  async installPluginDependencies(resolutions: DependencyResolution[]): Promise<void> {
141
141
  if (!this.config.autoInstall) {
142
- this.logger?.info('Auto-instalação desabilitada, pulando instalação de dependências')
142
+ this.logger?.debug('Auto-instalação desabilitada, pulando instalação de dependências')
143
143
  return
144
144
  }
145
145
 
@@ -164,17 +164,17 @@ export class PluginDependencyManager {
164
164
  })
165
165
 
166
166
  if (needsInstallation.length === 0) {
167
- this.logger?.info('Todas as dependências de plugins já estão instaladas')
167
+ this.logger?.debug('Todas as dependências de plugins já estão instaladas')
168
168
  return
169
169
  }
170
170
 
171
- this.logger?.info(`Instalando ${needsInstallation.length} dependências de plugins`, {
171
+ this.logger?.debug(`Instalando ${needsInstallation.length} dependências de plugins`, {
172
172
  dependencies: needsInstallation.map(d => `${d.name}@${d.version}`)
173
173
  })
174
174
 
175
175
  try {
176
176
  await this.installDependencies(needsInstallation)
177
- this.logger?.info('Dependências de plugins instaladas com sucesso')
177
+ this.logger?.debug('Dependências de plugins instaladas com sucesso')
178
178
  } catch (error) {
179
179
  this.logger?.error('Erro ao instalar dependências de plugins', { error })
180
180
  throw error
@@ -239,7 +239,7 @@ export class PluginDependencyManager {
239
239
  const resolution = sortedVersions[0].version
240
240
  conflict.resolution = resolution
241
241
 
242
- this.logger?.info(`Conflito resolvido para '${conflict.package}': usando versão ${resolution}`, {
242
+ this.logger?.debug(`Conflito resolvido para '${conflict.package}': usando versão ${resolution}`, {
243
243
  package: conflict.package,
244
244
  resolution,
245
245
  conflictingVersions: conflict.versions
@@ -60,24 +60,39 @@ export class PluginManager extends EventEmitter {
60
60
  return
61
61
  }
62
62
 
63
- this.logger.info('Initializing plugin manager')
63
+ this.logger.debug('Initializing plugin manager')
64
64
 
65
65
  try {
66
66
  // Discover and load plugins
67
+ this.logger.debug('Starting plugin discovery...')
67
68
  await this.discoverPlugins()
68
-
69
+ this.logger.debug('Plugin discovery completed')
70
+
69
71
  // Setup plugin contexts
72
+ this.logger.debug('Setting up plugin contexts...')
70
73
  this.setupPluginContexts()
71
-
74
+ this.logger.debug('Plugin contexts setup completed')
75
+
72
76
  // Execute setup hooks
77
+ this.logger.debug('Executing setup hooks...')
73
78
  await this.executeHook('setup')
74
-
79
+ this.logger.debug('Setup hooks execution completed')
80
+
75
81
  this.initialized = true
76
- this.logger.info('Plugin manager initialized successfully', {
77
- totalPlugins: this.registry.getStats().totalPlugins
82
+ const stats = this.registry.getStats()
83
+ this.logger.debug('Plugin manager initialized successfully', {
84
+ totalPlugins: stats.totalPlugins,
85
+ enabledPlugins: stats.enabledPlugins,
86
+ loadOrder: stats.loadOrder
78
87
  })
79
88
  } catch (error) {
80
- this.logger.error('Failed to initialize plugin manager', { error })
89
+ this.logger.error('Failed to initialize plugin manager', {
90
+ error: error instanceof Error ? {
91
+ message: error.message,
92
+ stack: error.stack,
93
+ name: error.name
94
+ } : error
95
+ })
81
96
  throw error
82
97
  }
83
98
  }
@@ -396,13 +411,41 @@ export class PluginManager extends EventEmitter {
396
411
  */
397
412
  private async discoverPlugins(): Promise<void> {
398
413
  try {
399
- this.logger.info('Discovering external plugins in directory: plugins')
400
- const results = await this.registry.discoverPlugins({
401
- directories: ['plugins'],
402
- includeBuiltIn: false,
403
- includeExternal: true
414
+ // Load built-in plugins first (handled by core system)
415
+ this.logger.debug('Loading built-in plugins...')
416
+ const builtInResults = await this.registry.discoverPlugins({
417
+ directories: [],
418
+ includeBuiltIn: true,
419
+ includeExternal: false
404
420
  })
405
421
 
422
+ // Try to use auto-generated registry for external plugins (if available from build)
423
+ let externalResults: any[] = []
424
+ try {
425
+ const autoRegistryModule = await import('./auto-registry')
426
+ if (autoRegistryModule.discoveredPlugins && autoRegistryModule.registerDiscoveredPlugins) {
427
+ this.logger.debug('🚀 Using auto-generated external plugins registry')
428
+ await autoRegistryModule.registerDiscoveredPlugins(this.registry)
429
+ externalResults = autoRegistryModule.discoveredPlugins.map((plugin: any) => ({
430
+ success: true,
431
+ plugin
432
+ }))
433
+ }
434
+ } catch (error) {
435
+ this.logger.debug('Auto-generated external plugins registry not found, falling back to discovery', { error: error.message })
436
+
437
+ // Fallback to runtime discovery for external plugins
438
+ this.logger.debug('Discovering external plugins in directory: plugins')
439
+ externalResults = await this.registry.discoverPlugins({
440
+ directories: ['plugins'],
441
+ includeBuiltIn: false,
442
+ includeExternal: true
443
+ })
444
+ }
445
+
446
+ // Combine results
447
+ const results = [...builtInResults, ...externalResults]
448
+
406
449
  let loaded = 0
407
450
  let failed = 0
408
451
 
@@ -420,7 +463,7 @@ export class PluginManager extends EventEmitter {
420
463
  }
421
464
  }
422
465
 
423
- this.logger.info('Plugin discovery completed', { loaded, failed })
466
+ this.logger.debug('Plugin discovery completed', { loaded, failed })
424
467
  } catch (error) {
425
468
  this.logger.error('Plugin discovery failed', { error })
426
469
  throw error
@@ -448,7 +491,7 @@ export class PluginManager extends EventEmitter {
448
491
 
449
492
  const context: PluginContext = {
450
493
  config: this.config,
451
- logger: this.logger,
494
+ logger: this.logger.child ? this.logger.child({ plugin: plugin.name }) : this.logger,
452
495
  app: this.app,
453
496
  utils: createPluginUtils(this.logger),
454
497
  registry: this.registry
@@ -225,7 +225,7 @@ export class PluginRegistry {
225
225
 
226
226
  // Descobrir plugins
227
227
  for (const directory of directories) {
228
- this.logger?.info(`Scanning directory: ${directory}`)
228
+ this.logger?.debug(`Scanning directory: ${directory}`)
229
229
  if (!existsSync(directory)) {
230
230
  this.logger?.warn(`Directory does not exist: ${directory}`)
231
231
  continue
@@ -233,7 +233,7 @@ export class PluginRegistry {
233
233
 
234
234
  try {
235
235
  const pluginResults = await this.discoverPluginsInDirectory(directory, _patterns)
236
- this.logger?.info(`Found ${pluginResults.length} plugins in ${directory}`)
236
+ this.logger?.debug(`Found ${pluginResults.length} plugins in ${directory}`)
237
237
  results.push(...pluginResults)
238
238
  } catch (error) {
239
239
  this.logger?.warn(`Failed to discover plugins in directory '${directory}'`, { error })
@@ -487,7 +487,7 @@ export class PluginRegistry {
487
487
  existsSync(join(pluginDir, 'plugin.js'))
488
488
 
489
489
  if (hasPluginFile) {
490
- this.logger?.info(`Loading plugin from: ${pluginDir}`)
490
+ this.logger?.debug(`Loading plugin from: ${pluginDir}`)
491
491
  const result = await this.loadPlugin(pluginDir)
492
492
  results.push(result)
493
493
  }
@@ -1,6 +1,5 @@
1
1
  // FluxStack framework exports
2
2
  export { FluxStackFramework } from "../framework/server"
3
- export { loggerPlugin } from "../plugins/built-in/logger"
4
3
  export { vitePlugin } from "../plugins/built-in/vite"
5
4
  export { staticPlugin } from "../plugins/built-in/static"
6
5
  export { swaggerPlugin } from "../plugins/built-in/swagger"
@@ -143,7 +143,7 @@ export class ComponentRegistry {
143
143
  // Register component class dynamically
144
144
  registerComponentClass(name: string, componentClass: any) {
145
145
  this.autoDiscoveredComponents.set(name, componentClass)
146
- console.log(`🔍 Auto-discovered component: ${name}`)
146
+ // Logging is handled by autoDiscoverComponents
147
147
  }
148
148
 
149
149
  // Auto-discover components from directory
@@ -151,36 +151,62 @@ export class ComponentRegistry {
151
151
  try {
152
152
  const fs = await import('fs')
153
153
  const path = await import('path')
154
-
154
+ const { startGroup, endGroup, logInGroup, groupSummary } = await import('../../utils/logger/group-logger')
155
+
155
156
  if (!fs.existsSync(componentsPath)) {
156
157
  console.log(`⚠️ Components path not found: ${componentsPath}`)
157
158
  return
158
159
  }
159
160
 
160
161
  const files = fs.readdirSync(componentsPath)
161
-
162
+ let discoveredCount = 0
163
+
164
+ startGroup({
165
+ title: 'Live Components Auto-Discovery',
166
+ icon: '🔍',
167
+ color: 'blue',
168
+ collapsed: true
169
+ })
170
+
162
171
  for (const file of files) {
163
172
  if (file.endsWith('.ts') || file.endsWith('.js')) {
164
173
  try {
165
174
  const fullPath = path.join(componentsPath, file)
166
175
  const module = await import(/* @vite-ignore */ fullPath)
167
-
176
+
168
177
  // Look for exported classes that extend LiveComponent
169
178
  Object.keys(module).forEach(exportName => {
170
179
  const exportedItem = module[exportName]
171
- if (typeof exportedItem === 'function' &&
172
- exportedItem.prototype &&
180
+ if (typeof exportedItem === 'function' &&
181
+ exportedItem.prototype &&
173
182
  this.isLiveComponentClass(exportedItem)) {
174
-
183
+
175
184
  const componentName = exportName.replace(/Component$/, '')
176
185
  this.registerComponentClass(componentName, exportedItem)
186
+ logInGroup(`${componentName} (from ${file})`, '📦')
187
+ discoveredCount++
177
188
  }
178
189
  })
190
+
191
+ // Check for integration hooks (like SystemMonitorIntegration)
192
+ if (module.default && typeof module.default === 'object' && module.default.setupIntegration) {
193
+ logInGroup('Integration hooks found', '🔗')
194
+ }
179
195
  } catch (error) {
180
- console.warn(`⚠️ Failed to load component from ${file}:`, error)
196
+ logInGroup(`Failed to load ${file}`, '⚠️')
181
197
  }
182
198
  }
183
199
  }
200
+
201
+ if (discoveredCount > 0) {
202
+ const label = discoveredCount === 1 ? 'component discovered' : 'components discovered'
203
+ groupSummary(discoveredCount, label, '✓')
204
+ } else {
205
+ logInGroup('No components found', '⚠️')
206
+ }
207
+
208
+ endGroup()
209
+ console.log('') // Separator line
184
210
  } catch (error) {
185
211
  console.error('❌ Auto-discovery failed:', error)
186
212
  }
@@ -180,7 +180,7 @@ export class LiveComponentPerformanceMonitor extends EventEmitter {
180
180
  })
181
181
 
182
182
  this.performanceObserver.observe({ entryTypes: ['measure', 'mark'] })
183
- console.log('📊 Performance observer initialized')
183
+ // Performance observer ready (logged at DEBUG level to keep startup clean)
184
184
  } catch (error) {
185
185
  console.warn('⚠️ Performance observer not available:', error)
186
186
  }