millas 0.2.12-beta-1 → 0.2.13

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 (120) hide show
  1. package/package.json +3 -2
  2. package/src/admin/ActivityLog.js +153 -52
  3. package/src/admin/Admin.js +516 -199
  4. package/src/admin/AdminAuth.js +213 -98
  5. package/src/admin/FormGenerator.js +372 -0
  6. package/src/admin/HookRegistry.js +256 -0
  7. package/src/admin/QueryEngine.js +263 -0
  8. package/src/admin/ViewContext.js +318 -0
  9. package/src/admin/WidgetRegistry.js +406 -0
  10. package/src/admin/index.js +17 -0
  11. package/src/admin/resources/AdminResource.js +393 -97
  12. package/src/admin/static/admin.css +1422 -0
  13. package/src/admin/static/date-picker.css +157 -0
  14. package/src/admin/static/date-picker.js +316 -0
  15. package/src/admin/static/json-editor.css +649 -0
  16. package/src/admin/static/json-editor.js +1429 -0
  17. package/src/admin/static/ui.js +1044 -0
  18. package/src/admin/views/layouts/base.njk +87 -1046
  19. package/src/admin/views/pages/detail.njk +56 -21
  20. package/src/admin/views/pages/error.njk +65 -0
  21. package/src/admin/views/pages/form.njk +47 -599
  22. package/src/admin/views/pages/list.njk +270 -62
  23. package/src/admin/views/partials/form-field.njk +53 -0
  24. package/src/admin/views/partials/form-footer.njk +28 -0
  25. package/src/admin/views/partials/form-readonly.njk +114 -0
  26. package/src/admin/views/partials/form-scripts.njk +480 -0
  27. package/src/admin/views/partials/form-widget.njk +297 -0
  28. package/src/admin/views/partials/icons.njk +64 -0
  29. package/src/admin/views/partials/json-dialog.njk +80 -0
  30. package/src/admin/views/partials/json-editor.njk +37 -0
  31. package/src/ai/AIManager.js +954 -0
  32. package/src/ai/AITokenBudget.js +250 -0
  33. package/src/ai/PromptGuard.js +216 -0
  34. package/src/ai/agents.js +218 -0
  35. package/src/ai/conversation.js +213 -0
  36. package/src/ai/drivers.js +734 -0
  37. package/src/ai/files.js +249 -0
  38. package/src/ai/media.js +303 -0
  39. package/src/ai/pricing.js +152 -0
  40. package/src/ai/provider_tools.js +114 -0
  41. package/src/ai/types.js +356 -0
  42. package/src/auth/Auth.js +18 -2
  43. package/src/auth/AuthUser.js +65 -44
  44. package/src/cli.js +3 -1
  45. package/src/commands/createsuperuser.js +267 -0
  46. package/src/commands/lang.js +589 -0
  47. package/src/commands/migrate.js +154 -81
  48. package/src/commands/serve.js +3 -4
  49. package/src/container/AppInitializer.js +101 -20
  50. package/src/container/Application.js +31 -1
  51. package/src/container/MillasApp.js +10 -3
  52. package/src/container/MillasConfig.js +35 -6
  53. package/src/core/admin.js +5 -0
  54. package/src/core/db.js +2 -1
  55. package/src/core/foundation.js +2 -10
  56. package/src/core/lang.js +1 -0
  57. package/src/errors/HttpError.js +32 -16
  58. package/src/facades/AI.js +411 -0
  59. package/src/facades/Hash.js +67 -0
  60. package/src/facades/Process.js +144 -0
  61. package/src/hashing/Hash.js +262 -0
  62. package/src/http/HtmlEscape.js +162 -0
  63. package/src/http/MillasRequest.js +63 -7
  64. package/src/http/MillasResponse.js +70 -4
  65. package/src/http/ResponseDispatcher.js +21 -27
  66. package/src/http/SafeFilePath.js +195 -0
  67. package/src/http/SafeRedirect.js +62 -0
  68. package/src/http/SecurityBootstrap.js +70 -0
  69. package/src/http/helpers.js +40 -125
  70. package/src/http/index.js +10 -1
  71. package/src/http/middleware/CsrfMiddleware.js +258 -0
  72. package/src/http/middleware/RateLimiter.js +314 -0
  73. package/src/http/middleware/SecurityHeaders.js +281 -0
  74. package/src/i18n/I18nServiceProvider.js +91 -0
  75. package/src/i18n/Translator.js +643 -0
  76. package/src/i18n/defaults.js +122 -0
  77. package/src/i18n/index.js +164 -0
  78. package/src/i18n/locales/en.js +55 -0
  79. package/src/i18n/locales/sw.js +48 -0
  80. package/src/logger/LogRedactor.js +247 -0
  81. package/src/logger/Logger.js +1 -1
  82. package/src/logger/formatters/JsonFormatter.js +11 -4
  83. package/src/logger/formatters/PrettyFormatter.js +103 -65
  84. package/src/logger/formatters/SimpleFormatter.js +14 -3
  85. package/src/middleware/ThrottleMiddleware.js +27 -4
  86. package/src/migrations/system/0001_users.js +21 -0
  87. package/src/migrations/system/0002_admin_log.js +25 -0
  88. package/src/migrations/system/0003_sessions.js +23 -0
  89. package/src/orm/fields/index.js +210 -188
  90. package/src/orm/migration/DefaultValueParser.js +325 -0
  91. package/src/orm/migration/InteractiveResolver.js +191 -0
  92. package/src/orm/migration/Makemigrations.js +312 -0
  93. package/src/orm/migration/MigrationGraph.js +227 -0
  94. package/src/orm/migration/MigrationRunner.js +202 -108
  95. package/src/orm/migration/MigrationWriter.js +463 -0
  96. package/src/orm/migration/ModelInspector.js +143 -74
  97. package/src/orm/migration/ModelScanner.js +225 -0
  98. package/src/orm/migration/ProjectState.js +213 -0
  99. package/src/orm/migration/RenameDetector.js +175 -0
  100. package/src/orm/migration/SchemaBuilder.js +8 -81
  101. package/src/orm/migration/operations/base.js +57 -0
  102. package/src/orm/migration/operations/column.js +191 -0
  103. package/src/orm/migration/operations/fields.js +252 -0
  104. package/src/orm/migration/operations/index.js +55 -0
  105. package/src/orm/migration/operations/models.js +152 -0
  106. package/src/orm/migration/operations/registry.js +131 -0
  107. package/src/orm/migration/operations/special.js +51 -0
  108. package/src/orm/migration/utils.js +208 -0
  109. package/src/orm/model/Model.js +81 -13
  110. package/src/process/Process.js +333 -0
  111. package/src/providers/AdminServiceProvider.js +66 -9
  112. package/src/providers/AuthServiceProvider.js +40 -5
  113. package/src/providers/CacheStorageServiceProvider.js +2 -2
  114. package/src/providers/DatabaseServiceProvider.js +3 -2
  115. package/src/providers/LogServiceProvider.js +4 -1
  116. package/src/providers/MailServiceProvider.js +1 -1
  117. package/src/providers/QueueServiceProvider.js +1 -1
  118. package/src/router/MiddlewareRegistry.js +27 -2
  119. package/src/scaffold/templates.js +80 -21
  120. package/src/validation/Validator.js +348 -607
@@ -28,6 +28,7 @@ function getProjectFiles(projectName) {
28
28
  APP_ENV=development
29
29
  APP_PORT=3000
30
30
  APP_KEY=
31
+ APP_URL=http://localhost:3000
31
32
 
32
33
  DB_CONNECTION=sqlite
33
34
  DB_HOST=127.0.0.1
@@ -68,38 +69,38 @@ storage/logs/*.log
68
69
  storage/uploads/*
69
70
  !storage/uploads/.gitkeep
70
71
  database/database.sqlite
71
- `,
72
-
73
- // ─── millas.config.js ─────────────────────────────────────────
74
- 'millas.config.js': `'use strict';
75
-
76
- module.exports = {
77
- /*
78
- |--------------------------------------------------------------------------
79
- | Millas Framework Configuration
80
- |--------------------------------------------------------------------------
81
- */
82
- providers: [
83
- './providers/AppServiceProvider',
84
- ],
85
- };
86
72
  `,
87
73
 
88
74
  // ─── bootstrap/app.js ─────────────────────────────────────────
75
+
89
76
  'bootstrap/app.js': `'use strict';
90
77
 
91
78
  require('dotenv').config();
92
79
 
80
+ const path = require('path');
93
81
  const { Millas } = require('millas');
94
82
  const AppServiceProvider = require('../providers/AppServiceProvider');
95
83
 
96
- module.exports = Millas.config()
97
- .providers([AppServiceProvider])
84
+ /**
85
+ * Application configuration and bootstrap.
86
+ *
87
+ * Millas.configure(__dirname/..) sets the project root so the framework
88
+ * locates config files, models, and routes without guessing.
89
+ *
90
+ * Core providers (Database, Auth, Admin, Cache, Mail, Queue, Events)
91
+ * are wired automatically — only add your own app providers below.
92
+ *
93
+ * First-time setup:
94
+ * millas migrate # creates system tables (users, admin_log, sessions)
95
+ * millas createsuperuser # creates your first admin panel user
96
+ */
97
+ module.exports = Millas.configure(path.join(__dirname, '..'))
98
+ .withAdmin()
98
99
  .routes(Route => {
99
100
  require('../routes/web')(Route);
100
101
  require('../routes/api')(Route);
101
102
  })
102
- .withAdmin()
103
+ .providers([AppServiceProvider])
103
104
  .create();
104
105
  `,
105
106
 
@@ -151,9 +152,15 @@ module.exports = {
151
152
  env: process.env.APP_ENV || 'development',
152
153
  port: parseInt(process.env.APP_PORT, 10) || 3000,
153
154
  key: process.env.APP_KEY || '',
155
+ url: process.env.APP_URL || 'http://localhost:3000',
154
156
  debug: process.env.APP_ENV !== 'production',
155
157
  timezone: 'UTC',
156
- locale: 'en',
158
+ locale: 'en',
159
+ fallback: 'en',
160
+
161
+ // Set use_i18n: true to enable the translation system.
162
+ // Then run: millas lang:publish <locale>
163
+ use_i18n: false,
157
164
  };
158
165
  `,
159
166
 
@@ -215,6 +222,50 @@ module.exports = {
215
222
  expiresIn: '1h',
216
223
  },
217
224
  };
225
+ `,
226
+
227
+ // ─── config/admin.js ──────────────────────────────────────────
228
+ 'config/admin.js': `'use strict';
229
+
230
+ /**
231
+ * Admin Panel Configuration
232
+ *
233
+ * Credentials are read from environment variables by default.
234
+ * Set ADMIN_EMAIL and ADMIN_PASSWORD in your .env file, or define
235
+ * static users / a model here.
236
+ */
237
+ module.exports = {
238
+ // URL prefix for the admin panel
239
+ prefix: '/admin',
240
+
241
+ // Title shown in the browser tab and sidebar
242
+ title: process.env.APP_NAME ? \`\${process.env.APP_NAME} Admin\` : 'Millas Admin',
243
+
244
+ auth: {
245
+ // ── Option 1: static user list (simple setups / local dev) ────
246
+ users: [
247
+ {
248
+ email: process.env.ADMIN_EMAIL || 'admin@example.com',
249
+ // Use a bcrypt hash in production; plain text is fine for local dev.
250
+ password: process.env.ADMIN_PASSWORD || 'change-me',
251
+ name: process.env.ADMIN_NAME || 'Admin',
252
+ },
253
+ ],
254
+
255
+ // ── Option 2: model-based lookup ──────────────────────────────
256
+ // Uncomment and set to any Millas Model that has email + password fields.
257
+ // model: require('../app/models/User'),
258
+
259
+ // ── Session cookie settings ───────────────────────────────────
260
+ cookieName: 'millas_admin',
261
+ cookieMaxAge: 60 * 60 * 8, // 8 hours
262
+ rememberAge: 60 * 60 * 24 * 30, // 30 days ("remember me")
263
+
264
+ // ── Brute-force protection ────────────────────────────────────
265
+ maxAttempts: 5,
266
+ lockoutMinutes: 15,
267
+ },
268
+ };
218
269
  `,
219
270
 
220
271
  // ─── config/mail.js ───────────────────────────────────────────
@@ -264,10 +315,18 @@ class AppServiceProvider extends ServiceProvider {
264
315
  }
265
316
 
266
317
  async boot(container, app) {
267
- // Register Admin resources:
318
+ // Register Admin resources — Admin panel is auto-mounted via .withAdmin()
268
319
  // const { Admin } = require('millas');
320
+ // const { AdminResource, AdminField } = require('millas');
269
321
  // const Post = require('../app/models/Post');
270
- // Admin.register(Post);
322
+ //
323
+ // class PostResource extends AdminResource {
324
+ // static model = Post;
325
+ // static label = 'Posts';
326
+ // static searchable = ['title', 'body'];
327
+ // }
328
+ //
329
+ // Admin.register(PostResource);
271
330
  }
272
331
  }
273
332