kreftjs 0.0.0-stage → 0.0.2-beta

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 (184) hide show
  1. package/README.md +103 -2
  2. package/bin/add.js +1074 -0
  3. package/bin/artisan-more.js +994 -0
  4. package/bin/artisan.js +1877 -0
  5. package/bin/backend/app.js +161 -0
  6. package/bin/backend/cache.js +196 -0
  7. package/bin/backend/collection.js +117 -0
  8. package/bin/backend/command.js +45 -0
  9. package/bin/backend/config.js +234 -0
  10. package/bin/backend/error-page.js +773 -0
  11. package/bin/backend/events.js +49 -0
  12. package/bin/backend/factory.js +223 -0
  13. package/bin/backend/fake.js +180 -0
  14. package/bin/backend/form.js +102 -0
  15. package/bin/backend/gate.js +79 -0
  16. package/bin/backend/gc.js +69 -0
  17. package/bin/backend/html.js +322 -0
  18. package/bin/backend/http.js +652 -0
  19. package/bin/backend/index.js +452 -0
  20. package/bin/backend/mail.js +77 -0
  21. package/bin/backend/mcp.js +433 -0
  22. package/bin/backend/migrator.js +370 -0
  23. package/bin/backend/model.js +781 -0
  24. package/bin/backend/namespace.js +213 -0
  25. package/bin/backend/notifications.js +68 -0
  26. package/bin/backend/qr.js +164 -0
  27. package/bin/backend/query.js +387 -0
  28. package/bin/backend/queue.js +412 -0
  29. package/bin/backend/redis.js +479 -0
  30. package/bin/backend/schedule.js +112 -0
  31. package/bin/backend/schema.js +321 -0
  32. package/bin/backend/seo-pages.js +100 -0
  33. package/bin/backend/storage.js +153 -0
  34. package/bin/backend/support.js +567 -0
  35. package/bin/backend/typescript.js +166 -0
  36. package/bin/build.js +540 -0
  37. package/bin/db-api.js +249 -0
  38. package/bin/db.js +275 -0
  39. package/bin/deps.js +138 -0
  40. package/bin/electron.js +509 -0
  41. package/bin/env.js +97 -0
  42. package/bin/guard.js +80 -0
  43. package/bin/kreftjs-config.js +40 -0
  44. package/bin/kreftjs.js +1373 -0
  45. package/bin/lang.js +241 -0
  46. package/bin/layout.js +74 -0
  47. package/bin/no-auth.js +162 -0
  48. package/bin/prerender.js +258 -0
  49. package/bin/safe-json.js +24 -0
  50. package/bin/server-routes.js +154 -0
  51. package/bin/ssr.js +133 -0
  52. package/bin/terminal.js +195 -0
  53. package/bin/to-ts.js +36 -0
  54. package/bin/update.js +237 -0
  55. package/bin/urls-file.js +27 -0
  56. package/bin/vite.js +228 -0
  57. package/docs/Docs.kreftjs +557 -0
  58. package/docs/README.md +2302 -0
  59. package/docs/markdown.js +186 -0
  60. package/editors/vscode/README.md +13 -0
  61. package/editors/vscode/extension.js +183 -0
  62. package/editors/vscode/language-configuration.json +17 -0
  63. package/editors/vscode/package.json +57 -0
  64. package/editors/vscode/snippets/kreftjs.json +21 -0
  65. package/editors/vscode/syntaxes/kreftjs.tmLanguage.json +207 -0
  66. package/kreftjs.d.ts +579 -0
  67. package/kreftjs.js +5108 -0
  68. package/package.json +97 -4
  69. package/server.d.ts +1028 -0
  70. package/server.js +8 -0
  71. package/templates/app/README.md +127 -0
  72. package/templates/app/_env.example +64 -0
  73. package/templates/app/_gitignore +5 -0
  74. package/templates/app/_vscode/settings.json +9 -0
  75. package/templates/app/backend/app/Auth/Session.js +177 -0
  76. package/templates/app/backend/app/Auth/Throttle.js +29 -0
  77. package/templates/app/backend/app/Console/Commands/.gitkeep +0 -0
  78. package/templates/app/backend/app/Events/.gitkeep +0 -0
  79. package/templates/app/backend/app/Http/Controllers/Admin/DashboardController.js +34 -0
  80. package/templates/app/backend/app/Http/Controllers/Admin/UserController.js +53 -0
  81. package/templates/app/backend/app/Http/Controllers/Auth/ApiTokenController.js +47 -0
  82. package/templates/app/backend/app/Http/Controllers/Auth/AuthenticatedSessionController.js +41 -0
  83. package/templates/app/backend/app/Http/Controllers/Auth/ConfirmablePasswordController.js +14 -0
  84. package/templates/app/backend/app/Http/Controllers/Auth/EmailVerificationController.js +23 -0
  85. package/templates/app/backend/app/Http/Controllers/Auth/NewPasswordController.js +29 -0
  86. package/templates/app/backend/app/Http/Controllers/Auth/PasswordResetLinkController.js +20 -0
  87. package/templates/app/backend/app/Http/Controllers/Auth/RegisteredUserController.js +19 -0
  88. package/templates/app/backend/app/Http/Controllers/Auth/SessionController.js +36 -0
  89. package/templates/app/backend/app/Http/Controllers/Auth/TwoFactorChallengeController.js +41 -0
  90. package/templates/app/backend/app/Http/Controllers/Auth/TwoFactorController.js +63 -0
  91. package/templates/app/backend/app/Http/Controllers/ProfileController.js +66 -0
  92. package/templates/app/backend/app/Http/Kernel.js +8 -0
  93. package/templates/app/backend/app/Http/Middleware/Authenticate.js +84 -0
  94. package/templates/app/backend/app/Http/Middleware/CheckAbilities.js +17 -0
  95. package/templates/app/backend/app/Http/Middleware/CheckForAnyAbility.js +12 -0
  96. package/templates/app/backend/app/Http/Middleware/EnsureEmailIsVerified.js +11 -0
  97. package/templates/app/backend/app/Http/Middleware/EnsureHasRole.js +11 -0
  98. package/templates/app/backend/app/Http/Middleware/EnsureIsAdmin.js +11 -0
  99. package/templates/app/backend/app/Http/Middleware/RequirePassword.js +15 -0
  100. package/templates/app/backend/app/Http/Requests/Auth/LoginRequest.js +45 -0
  101. package/templates/app/backend/app/Http/Resources/.gitkeep +1 -0
  102. package/templates/app/backend/app/Jobs/.gitkeep +0 -0
  103. package/templates/app/backend/app/Listeners/.gitkeep +0 -0
  104. package/templates/app/backend/app/Mail/.gitkeep +0 -0
  105. package/templates/app/backend/app/Models/PersonalAccessToken.js +21 -0
  106. package/templates/app/backend/app/Models/User.js +64 -0
  107. package/templates/app/backend/app/Notifications/.gitkeep +0 -0
  108. package/templates/app/backend/app/Observers/.gitkeep +0 -0
  109. package/templates/app/backend/app/Policies/.gitkeep +0 -0
  110. package/templates/app/backend/app/Providers/AppServiceProvider.js +12 -0
  111. package/templates/app/backend/app/Rules/.gitkeep +1 -0
  112. package/templates/app/backend/config/app.js +16 -0
  113. package/templates/app/backend/config/auth.js +34 -0
  114. package/templates/app/backend/config/database.js +38 -0
  115. package/templates/app/backend/config/redis.js +28 -0
  116. package/templates/app/backend/config/session.js +36 -0
  117. package/templates/app/backend/database/migrations/0001_01_01_000000_create_users_table.js +49 -0
  118. package/templates/app/backend/database/migrations/0001_01_01_000001_create_cache_table.js +13 -0
  119. package/templates/app/backend/database/migrations/0001_01_01_000002_create_jobs_table.js +26 -0
  120. package/templates/app/backend/database/migrations/0001_01_01_000003_create_notifications_table.js +18 -0
  121. package/templates/app/backend/database/seeders/DatabaseSeeder.js +15 -0
  122. package/templates/app/backend/lang/ar/messages.json +10 -0
  123. package/templates/app/backend/lang/ar/validation.json +21 -0
  124. package/templates/app/backend/lang/en/messages.json +10 -0
  125. package/templates/app/backend/lang/en/validation.json +19 -0
  126. package/templates/app/backend/routes/api.js +25 -0
  127. package/templates/app/backend/routes/auth.js +52 -0
  128. package/templates/app/backend/routes/console.js +15 -0
  129. package/templates/app/frontend/App.kreftjs +4 -0
  130. package/templates/app/frontend/components/Field.kreftjs +19 -0
  131. package/templates/app/frontend/components/StatCard.kreftjs +47 -0
  132. package/templates/app/frontend/components/profile/ApiTokens.kreftjs +70 -0
  133. package/templates/app/frontend/components/profile/Sessions.kreftjs +42 -0
  134. package/templates/app/frontend/components/profile/TwoFactor.kreftjs +90 -0
  135. package/templates/app/frontend/errors/ErrorMonitor.kreftjs +264 -0
  136. package/templates/app/frontend/index.html +79 -0
  137. package/templates/app/frontend/kreftjs.d.ts +579 -0
  138. package/templates/app/frontend/kreftjs.js +5108 -0
  139. package/templates/app/frontend/layouts/app.kreftjs +718 -0
  140. package/templates/app/frontend/layouts/docs.kreftjs +37 -0
  141. package/templates/app/frontend/layouts/guest.kreftjs +18 -0
  142. package/templates/app/frontend/pages/Dashboard.kreftjs +273 -0
  143. package/templates/app/frontend/pages/ErrorMonitor.kreftjs +96 -0
  144. package/templates/app/frontend/pages/Home.kreftjs +617 -0
  145. package/templates/app/frontend/pages/Profile.kreftjs +104 -0
  146. package/templates/app/frontend/pages/Users.kreftjs +240 -0
  147. package/templates/app/frontend/pages/auth/ConfirmPassword.kreftjs +33 -0
  148. package/templates/app/frontend/pages/auth/ForgotPassword.kreftjs +36 -0
  149. package/templates/app/frontend/pages/auth/Login.kreftjs +89 -0
  150. package/templates/app/frontend/pages/auth/Register.kreftjs +48 -0
  151. package/templates/app/frontend/pages/auth/ResetPassword.kreftjs +45 -0
  152. package/templates/app/frontend/pages/auth/VerifyEmail.kreftjs +59 -0
  153. package/templates/app/frontend/routes/web.kreftjs +34 -0
  154. package/templates/app/frontend/tests/components/Counter.kreftjs +15 -0
  155. package/templates/app/frontend/tests/pages/About.kreftjs +12 -0
  156. package/templates/app/frontend/tests/pages/Test.kreftjs +31 -0
  157. package/templates/app/frontend/ui.css +517 -0
  158. package/templates/app/lang/ar/auth.json +6 -0
  159. package/templates/app/lang/ar/messages.json +6 -0
  160. package/templates/app/lang/ar/pagination.json +5 -0
  161. package/templates/app/lang/ar/passwords.json +8 -0
  162. package/templates/app/lang/ar/validation.json +22 -0
  163. package/templates/app/lang/ar.json +10 -0
  164. package/templates/app/lang/en/auth.json +6 -0
  165. package/templates/app/lang/en/messages.json +6 -0
  166. package/templates/app/lang/en/pagination.json +5 -0
  167. package/templates/app/lang/en/passwords.json +8 -0
  168. package/templates/app/lang/en/validation.json +22 -0
  169. package/templates/app/lang/en.json +10 -0
  170. package/templates/errors/401.kreftjs +11 -0
  171. package/templates/errors/402.kreftjs +11 -0
  172. package/templates/errors/403.kreftjs +11 -0
  173. package/templates/errors/404.kreftjs +11 -0
  174. package/templates/errors/419.kreftjs +11 -0
  175. package/templates/errors/429.kreftjs +11 -0
  176. package/templates/errors/500.kreftjs +11 -0
  177. package/templates/errors/503.kreftjs +11 -0
  178. package/templates/errors/ErrorMonitor.kreftjs +502 -0
  179. package/templates/errors/error.kreftjs +11 -0
  180. package/templates/errors/minimal.kreftjs +25 -0
  181. package/tools/dev-client.js +125 -0
  182. package/tools/devtools.js +172 -0
  183. package/tools/vite-plugin-kreftjs.d.ts +52 -0
  184. package/tools/vite-plugin-kreftjs.js +466 -0
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Authentication & Security Configuration
3
+ *
4
+ * Session lifetime, password hashing, and token guards.
5
+ * config('auth.defaults.guard')
6
+ * config('auth.session.lifetime')
7
+ */
8
+ module.exports = {
9
+ defaults: {
10
+ guard: 'web',
11
+ passwords: 'users',
12
+ },
13
+
14
+ guards: {
15
+ web: {
16
+ driver: 'session',
17
+ provider: 'users',
18
+ },
19
+ api: {
20
+ driver: 'token',
21
+ provider: 'users',
22
+ },
23
+ },
24
+
25
+ session: {
26
+ lifetime: Number(process.env.SESSION_LIFETIME) || 120, // minutes
27
+ expireOnClose: false,
28
+ encrypt: true,
29
+ cookie: 'kreft_session',
30
+ secure: process.env.APP_ENV === 'production',
31
+ httpOnly: true,
32
+ sameSite: 'lax',
33
+ },
34
+ };
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Database Configuration
3
+ *
4
+ * Connection settings for databases: SQLite, MySQL, and PostgreSQL.
5
+ * config('database.default')
6
+ * config('database.connections.sqlite.database')
7
+ */
8
+ module.exports = {
9
+ default: process.env.DB_CONNECTION || 'sqlite',
10
+
11
+ connections: {
12
+ sqlite: {
13
+ driver: 'sqlite',
14
+ database: process.env.DB_DATABASE || 'database/database.sqlite',
15
+ foreignKeyConstraints: true,
16
+ },
17
+
18
+ mysql: {
19
+ driver: 'mysql',
20
+ host: process.env.DB_HOST || '127.0.0.1',
21
+ port: Number(process.env.DB_PORT) || 3306,
22
+ database: process.env.DB_DATABASE || 'kreft',
23
+ username: process.env.DB_USERNAME || 'root',
24
+ password: process.env.DB_PASSWORD || '',
25
+ charset: 'utf8mb4',
26
+ },
27
+
28
+ pgsql: {
29
+ driver: 'pgsql',
30
+ host: process.env.DB_HOST || '127.0.0.1',
31
+ port: Number(process.env.DB_PORT) || 5432,
32
+ database: process.env.DB_DATABASE || 'kreft',
33
+ username: process.env.DB_USERNAME || 'postgres',
34
+ password: process.env.DB_PASSWORD || '',
35
+ ssl: process.env.DB_SSL === 'true',
36
+ },
37
+ },
38
+ };
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Redis & Cache Configuration
3
+ *
4
+ * Built-in native Redis client, cache stores, and background queue settings.
5
+ * config('redis.default.host')
6
+ * config('redis.cache.ttl')
7
+ */
8
+ module.exports = {
9
+ default: {
10
+ host: process.env.REDIS_HOST || '127.0.0.1',
11
+ port: Number(process.env.REDIS_PORT) || 6379,
12
+ password: process.env.REDIS_PASSWORD || null,
13
+ db: Number(process.env.REDIS_DB) || 0,
14
+ prefix: process.env.REDIS_PREFIX || 'kreft_database_',
15
+ },
16
+
17
+ cache: {
18
+ driver: process.env.CACHE_STORE || 'redis',
19
+ ttl: Number(process.env.CACHE_DEFAULT_TTL) || 3600,
20
+ prefix: 'kreft_cache_',
21
+ },
22
+
23
+ queue: {
24
+ driver: process.env.QUEUE_CONNECTION || 'redis',
25
+ prefix: 'kreft_jobs_',
26
+ defaultQueue: 'default',
27
+ },
28
+ };
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Session Configuration
3
+ *
4
+ * Controls server session storage, lifetimes, cookie attributes,
5
+ * and inactivity timeouts for both backend and frontend.
6
+ *
7
+ * config('session.lifetime')
8
+ * config('session.inactivity_timeout')
9
+ */
10
+ module.exports = {
11
+ // Session storage driver: 'file', 'cookie', 'database', 'redis'
12
+ driver: process.env.SESSION_DRIVER || 'file',
13
+
14
+ // Session lifetime in minutes on the server
15
+ lifetime: Number(process.env.SESSION_LIFETIME) || 120,
16
+
17
+ // Invalidate session immediately when browser window closes
18
+ expire_on_close: process.env.SESSION_EXPIRE_ON_CLOSE === 'true',
19
+
20
+ // Inactivity timeout in minutes before redirecting to login on the client
21
+ inactivity_timeout: Number(process.env.PUBLIC_SESSION_TIMEOUT || process.env.SESSION_INACTIVITY_TIMEOUT) || 15,
22
+
23
+ // Inactivity warning in minutes before session expires
24
+ warning_before: Number(process.env.PUBLIC_SESSION_WARNING) || 2,
25
+
26
+ // Redirect destination when session times out due to inactivity
27
+ redirect_url: '/login?reason=inactive',
28
+
29
+ // Cookie settings
30
+ cookie: process.env.SESSION_COOKIE || 'kreft_session',
31
+ path: '/',
32
+ domain: process.env.SESSION_DOMAIN || null,
33
+ secure: process.env.SESSION_SECURE_COOKIE ? process.env.SESSION_SECURE_COOKIE === 'true' : process.env.APP_ENV === 'production',
34
+ http_only: true,
35
+ same_site: 'lax',
36
+ };
@@ -0,0 +1,49 @@
1
+ // The tables for user authentication. kreftjs dev runs it by itself (or: kreftjs migrate).
2
+ module.exports = {
3
+ up(schema) {
4
+ schema.create('users', (table) => {
5
+ table.id()
6
+ table.string('name')
7
+ table.string('email').unique()
8
+ table.timestamp('email_verified_at').nullable()
9
+ table.string('password')
10
+ table.boolean('is_admin').default(false) // may open the admin panel (/admin)
11
+ table.string('role', 40).default('user') // 'role:editor' in the routes; user.hasRole('editor')
12
+ table.text('two_factor_secret').nullable() // encrypted (Crypt), for the authenticator app
13
+ table.text('two_factor_recovery_codes').nullable() // encrypted list of one-time codes
14
+ table.timestamp('two_factor_confirmed_at').nullable()
15
+ table.timestamps()
16
+ })
17
+
18
+ // the links sent by "Forgot your password?" (only a hash of each token is kept)
19
+ schema.create('password_reset_tokens', (table) => {
20
+ table.string('email').primary()
21
+ table.string('token')
22
+ table.timestamp('created_at').nullable()
23
+ })
24
+
25
+ // one row per signed-in browser (type 'session', in an HttpOnly cookie) or API token (type 'api').
26
+ // Only a hash of each token is kept.
27
+ schema.create('personal_access_tokens', (table) => {
28
+ table.id()
29
+ table.foreignId('user_id').constrained().cascadeOnDelete()
30
+ table.string('type', 20).default('session')
31
+ table.string('name')
32
+ table.string('token', 64).unique()
33
+ table.text('abilities').nullable() // ["posts:read", "posts:write"] or ["*"]
34
+ table.string('ip_address', 45).nullable()
35
+ table.string('user_agent', 255).nullable()
36
+ table.boolean('remember').default(false)
37
+ table.timestamp('last_used_at').nullable()
38
+ table.timestamp('password_confirmed_at').nullable()
39
+ table.timestamp('expires_at').nullable()
40
+ table.timestamps()
41
+ })
42
+ },
43
+
44
+ down(schema) {
45
+ schema.dropIfExists('personal_access_tokens')
46
+ schema.dropIfExists('password_reset_tokens')
47
+ schema.dropIfExists('users')
48
+ },
49
+ }
@@ -0,0 +1,13 @@
1
+ // The cache table (CACHE_STORE=database): Cache.put(), Cache.remember(), Cache.lock()
2
+ module.exports = {
3
+ up(schema) {
4
+ schema.create('cache', (table) => {
5
+ table.string('key').primary()
6
+ table.text('value')
7
+ table.integer('expiration').default(0)
8
+ })
9
+ },
10
+ down(schema) {
11
+ schema.dropIfExists('cache')
12
+ },
13
+ }
@@ -0,0 +1,26 @@
1
+ // The queue's tables: jobs waiting (kreftjs queue:work, or kreftjs dev, runs them) and jobs that failed
2
+ module.exports = {
3
+ up(schema) {
4
+ schema.create('jobs', (table) => {
5
+ table.id()
6
+ table.string('queue').index()
7
+ table.longText('payload')
8
+ table.integer('attempts').default(0)
9
+ table.integer('reserved_at').nullable()
10
+ table.integer('available_at')
11
+ table.integer('created_at')
12
+ })
13
+ schema.create('failed_jobs', (table) => {
14
+ table.id()
15
+ table.string('uuid').unique()
16
+ table.string('queue')
17
+ table.longText('payload')
18
+ table.longText('exception')
19
+ table.timestamp('failed_at').useCurrent()
20
+ })
21
+ },
22
+ down(schema) {
23
+ schema.dropIfExists('failed_jobs')
24
+ schema.dropIfExists('jobs')
25
+ },
26
+ }
@@ -0,0 +1,18 @@
1
+ // The notifications table: user.notify(…) with the 'database' channel, user.notifications()
2
+ module.exports = {
3
+ up(schema) {
4
+ schema.create('notifications', (table) => {
5
+ table.string('id', 36).primary()
6
+ table.string('type')
7
+ table.string('notifiable_type')
8
+ table.bigInteger('notifiable_id')
9
+ table.text('data')
10
+ table.timestamp('read_at').nullable()
11
+ table.timestamps()
12
+ table.index(['notifiable_type', 'notifiable_id'])
13
+ })
14
+ },
15
+ down(schema) {
16
+ schema.dropIfExists('notifications')
17
+ },
18
+ }
@@ -0,0 +1,15 @@
1
+ const { Seeder, Hash } = require('kreftjs/server')
2
+ const User = require('../../app/Models/User')
3
+
4
+ // kreftjs db:seed (kreftjs dev --seed fills a new database). Sign in as test@example.com / password;
5
+ // that user is an admin too, so /admin opens for it
6
+ class DatabaseSeeder extends Seeder {
7
+ async run() {
8
+ const user = await User.create({ name: 'Test User', email: 'test@example.com', password: Hash.make('password') })
9
+ user.email_verified_at = new Date()
10
+ user.is_admin = true // never fillable: only set like this, by your own code
11
+ await user.save()
12
+ }
13
+ }
14
+
15
+ module.exports = DatabaseSeeder
@@ -0,0 +1,10 @@
1
+ {
2
+ "welcome": "أهلاً بك في Kreft",
3
+ "hello": "مرحباً، :name",
4
+ "items": "{0} لا توجد عناصر|{1} عنصر واحد|{2} عنصران|[3,10] :count عناصر|[11,*] :count عنصراً",
5
+ "pagination": {
6
+ "previous": "« السابق",
7
+ "next": "التالي »"
8
+ }
9
+ }
10
+
@@ -0,0 +1,21 @@
1
+ {
2
+ "required": "حقل :attribute مطلوب.",
3
+ "email": "يجب أن يكون :attribute عنوان بريد إلكتروني صالح.",
4
+ "min": {
5
+ "string": "يجب أن يحتوي :attribute على :min أحرف على الأقل.",
6
+ "numeric": "يجب أن تكون قيمة :attribute على الأقل :min.",
7
+ "array": "يجب أن يحتوي :attribute على الأقل على :min عناصر."
8
+ },
9
+ "max": {
10
+ "string": "يجب ألا يتجاوز :attribute :max أحرف.",
11
+ "numeric": "يجب ألا تتجاوز قيمة :attribute :max.",
12
+ "array": "يجب ألا يحتوي :attribute على أكثر من :max عناصر."
13
+ },
14
+ "attributes": {
15
+ "email": "البريد الإلكتروني",
16
+ "password": "كلمة المرور",
17
+ "title": "العنوان",
18
+ "name": "الاسم"
19
+ }
20
+ }
21
+
@@ -0,0 +1,10 @@
1
+ {
2
+ "welcome": "Welcome to Kreft",
3
+ "hello": "Hello, :name",
4
+ "items": "{0} No items|{1} One item|[2,*] :count items",
5
+ "pagination": {
6
+ "previous": "« Previous",
7
+ "next": "Next »"
8
+ }
9
+ }
10
+
@@ -0,0 +1,19 @@
1
+ {
2
+ "required": "The :attribute field is required.",
3
+ "email": "The :attribute field must be a valid email address.",
4
+ "min": {
5
+ "string": "The :attribute field must be at least :min characters.",
6
+ "numeric": "The :attribute field must be at least :min.",
7
+ "array": "The :attribute field must have at least :min items."
8
+ },
9
+ "max": {
10
+ "string": "The :attribute field must not be greater than :max characters.",
11
+ "numeric": "The :attribute field must not be greater than :max.",
12
+ "array": "The :attribute field must not have more than :max items."
13
+ },
14
+ "attributes": {
15
+ "email": "email address",
16
+ "password": "password"
17
+ }
18
+ }
19
+
@@ -0,0 +1,25 @@
1
+ // Your API: every address here starts with /api.
2
+ // All API routes live directly in this file. Add your new routes here!
3
+ // See them all anytime with: kreftjs route:list
4
+ const { Route, use, namespace } = require('kreftjs/server')
5
+
6
+ // PHP-style namespace imports (e.g. use('App\Http\Controllers\Admin\UserController')):
7
+ const { DashboardController, UserController } = namespace('App\\Http\\Controllers\\Admin')
8
+
9
+ // Authentication routes (login, register, password reset, 2FA)
10
+ require('./auth')
11
+
12
+ // Dashboard telemetry & stats (protected)
13
+ Route.middleware('auth').group(() => {
14
+ Route.get('/stats', [DashboardController, 'index']).name('stats')
15
+ Route.get('/admin/stats', [DashboardController, 'index']).name('admin.stats')
16
+ Route.get('/admin/me', [DashboardController, 'me']).name('admin.me')
17
+ Route.get('/dashboard', (req) => ({ greeting: `Welcome back, ${req.user ? req.user.name : 'User'}.` }))
18
+ })
19
+
20
+ // User management endpoints (admin only)
21
+ Route.apiResource('admin/users', UserController, { only: ['index', 'update', 'destroy'] }).middleware(['auth', 'admin'])
22
+ Route.apiResource('users', UserController, { only: ['index', 'update', 'destroy'] }).middleware(['auth', 'admin'])
23
+
24
+ // Example public endpoint: GET /api/hello?name=World
25
+ Route.get('/hello', (req) => ({ hello: req.input('name', 'world'), app: process.env.APP_NAME }))
@@ -0,0 +1,52 @@
1
+ // Authentication routes (sign in, register, password reset, 2FA). routes/api.js loads this file.
2
+ const { Route } = require('kreftjs/server')
3
+ const RegisteredUserController = require('../app/Http/Controllers/Auth/RegisteredUserController')
4
+ const AuthenticatedSessionController = require('../app/Http/Controllers/Auth/AuthenticatedSessionController')
5
+ const PasswordResetLinkController = require('../app/Http/Controllers/Auth/PasswordResetLinkController')
6
+ const NewPasswordController = require('../app/Http/Controllers/Auth/NewPasswordController')
7
+ const EmailVerificationController = require('../app/Http/Controllers/Auth/EmailVerificationController')
8
+ const ConfirmablePasswordController = require('../app/Http/Controllers/Auth/ConfirmablePasswordController')
9
+ const TwoFactorController = require('../app/Http/Controllers/Auth/TwoFactorController')
10
+ const TwoFactorChallengeController = require('../app/Http/Controllers/Auth/TwoFactorChallengeController')
11
+ const SessionController = require('../app/Http/Controllers/Auth/SessionController')
12
+ const ApiTokenController = require('../app/Http/Controllers/Auth/ApiTokenController')
13
+ const ProfileController = require('../app/Http/Controllers/ProfileController')
14
+
15
+ // for visitors: 6 tries a minute, so passwords and codes can't be guessed quickly
16
+ Route.middleware('throttle:6,1').group(() => {
17
+ Route.post('/register', [RegisteredUserController, 'store']).name('register')
18
+ Route.post('/login', [AuthenticatedSessionController, 'store']).name('login')
19
+ Route.post('/two-factor-challenge', [TwoFactorChallengeController, 'store']).name('two-factor.login')
20
+ Route.post('/forgot-password', [PasswordResetLinkController, 'store']).name('password.email')
21
+ Route.post('/reset-password', [NewPasswordController, 'store']).name('password.store')
22
+ Route.post('/email/verify', [EmailVerificationController, 'verify']).name('verification.verify')
23
+ })
24
+
25
+ // for signed-in users ('auth': app/Http/Middleware/Authenticate.js)
26
+ Route.middleware('auth').group(() => {
27
+ Route.get('/user', [ProfileController, 'show']).name('user')
28
+ Route.post('/logout', [AuthenticatedSessionController, 'destroy']).name('logout')
29
+ Route.post('/email/verification-notification', [EmailVerificationController, 'send']).middleware('throttle:6,1').name('verification.send')
30
+ Route.post('/confirm-password', [ConfirmablePasswordController, 'store']).middleware('throttle:6,1').name('password.confirm')
31
+ Route.patch('/profile', [ProfileController, 'update']).name('profile.update')
32
+ Route.put('/password', [ProfileController, 'password']).name('password.update')
33
+ Route.delete('/profile', [ProfileController, 'destroy']).middleware('password.confirm').name('profile.destroy')
34
+
35
+ // two-factor authentication (an authenticator app)
36
+ Route.prefix('/user/two-factor').name('two-factor.').group(() => {
37
+ Route.post('/', [TwoFactorController, 'enable']).middleware('password.confirm').name('enable')
38
+ Route.post('/confirm', [TwoFactorController, 'confirm']).middleware('throttle:6,1').name('confirm')
39
+ Route.delete('/', [TwoFactorController, 'disable']).middleware('password.confirm').name('disable')
40
+ Route.get('/recovery-codes', [TwoFactorController, 'recoveryCodes']).middleware('password.confirm').name('recovery-codes')
41
+ Route.post('/recovery-codes', [TwoFactorController, 'regenerate']).middleware('password.confirm').name('regenerate')
42
+ })
43
+
44
+ // the devices signed in, and API tokens for scripts and apps
45
+ Route.get('/user/sessions', [SessionController, 'index']).name('sessions.index')
46
+ Route.delete('/user/sessions', [SessionController, 'destroyOthers']).middleware('password.confirm').name('sessions.others')
47
+ Route.delete('/user/sessions/{id}', [SessionController, 'destroy']).name('sessions.destroy')
48
+ Route.get('/user/tokens', [ApiTokenController, 'index']).name('tokens.index')
49
+ Route.post('/user/tokens', [ApiTokenController, 'store']).name('tokens.store')
50
+ Route.put('/user/tokens/{id}', [ApiTokenController, 'update']).name('tokens.update')
51
+ Route.delete('/user/tokens/{id}', [ApiTokenController, 'destroy']).name('tokens.destroy')
52
+ })
@@ -0,0 +1,15 @@
1
+ // What runs on a schedule. kreftjs dev runs it while it is on;
2
+ // on a server: kreftjs schedule:work (or `kreftjs schedule:run` from cron every minute). See them: kreftjs schedule:list
3
+ const { Schedule } = require('kreftjs/server')
4
+
5
+ // Schedule.call(async () => { … }).daily().name('clean-up')
6
+ // Schedule.job(new SendDailyReport()).weekdays().at('08:00')
7
+ // Schedule.command('cache:clear').hourly()
8
+
9
+ // remove login tokens nobody used for a long time
10
+ Schedule.call(async () => {
11
+ const PersonalAccessToken = require('../app/Models/PersonalAccessToken')
12
+ const days = Number(process.env.AUTH_TOKEN_DAYS || 30)
13
+ const before = new Date(Date.now() - days * 86400000).toISOString().slice(0, 19).replace('T', ' ')
14
+ await PersonalAccessToken.query().where('last_used_at', '<', before).delete()
15
+ }).daily().name('prune-old-tokens')
@@ -0,0 +1,4 @@
1
+ <!-- The app: the page for the current route, inside its layout (layouts/app.kreftjs) -->
2
+ <view>
3
+ <kreft-view k-animate.after="fade"></kreft-view>
4
+ </view>
@@ -0,0 +1,19 @@
1
+ <!-- A form field: its label, the input you put inside, and its error.
2
+ <field label="Email" error={form.$error('email')}><input type="email" k-model="form.email"></field> -->
3
+ prop label = ''
4
+ prop error = ''
5
+ prop hint = ''
6
+
7
+ <view>
8
+ <label class="field">
9
+ <span class="label">{label}</span>
10
+ <slot></slot>
11
+ <small k-if="error" class="err" role="alert">{error}</small>
12
+ <small k-elif="hint">{hint}</small>
13
+ </label>
14
+ </view>
15
+
16
+ <style scoped>
17
+ .label { margin: 0; }
18
+ .err { color: var(--destructive); }
19
+ </style>
@@ -0,0 +1,47 @@
1
+ <!-- A number with its label: <stat-card label="Users" value={stats.users} hint="new this week"></stat-card> -->
2
+ prop label = ''
3
+ prop value = 0
4
+ prop hint = ''
5
+
6
+ <view>
7
+ <div class="stat-card">
8
+ <p class="stat-label">{label}</p>
9
+ <p class="stat-value">{value}</p>
10
+ <p k-if="hint" class="stat-hint">{hint}</p>
11
+ </div>
12
+ </view>
13
+
14
+ <style scoped>
15
+ .stat-card {
16
+ border: 1px solid var(--border);
17
+ padding: 20px;
18
+ background: var(--card);
19
+ transition: border-color .15s ease;
20
+ }
21
+ .stat-card:hover {
22
+ border-color: var(--foreground);
23
+ }
24
+ .stat-label {
25
+ margin: 0;
26
+ font-size: 11px;
27
+ font-weight: 600;
28
+ font-family: var(--mono);
29
+ text-transform: uppercase;
30
+ letter-spacing: 0.05em;
31
+ color: var(--muted);
32
+ }
33
+ .stat-value {
34
+ margin: 8px 0 0;
35
+ font-size: 32px;
36
+ font-weight: 800;
37
+ letter-spacing: -0.04em;
38
+ font-variant-numeric: tabular-nums;
39
+ line-height: 1;
40
+ color: var(--foreground);
41
+ }
42
+ .stat-hint {
43
+ margin: 8px 0 0;
44
+ font-size: 12px;
45
+ color: var(--muted);
46
+ }
47
+ </style>
@@ -0,0 +1,70 @@
1
+ <!-- API tokens: for scripts and other apps (Authorization: Bearer …). pages/Profile.kreftjs, /api/user/tokens -->
2
+ load tokens = api.get('/api/user/tokens')
3
+ state name = ''
4
+ state chosen = ['read']
5
+ state created = null // the new token, shown once
6
+ state problem = ''
7
+
8
+ action create() {
9
+ problem = ''
10
+ try {
11
+ created = await api.post('/api/user/tokens', { name, abilities: chosen })
12
+ name = ''
13
+ tokens.reload()
14
+ } catch (e) { problem = e.message }
15
+ }
16
+ action toggle(a) { chosen = chosen.includes(a) ? chosen.filter((x) => x !== a) : [...chosen, a] }
17
+ action remove(t) {
18
+ problem = ''
19
+ try { await api.delete('/api/user/tokens/' + t.id); tokens.reload() }
20
+ catch (e) { problem = e.message }
21
+ }
22
+ action copy() { navigator.clipboard && navigator.clipboard.writeText(created.token) }
23
+
24
+ <view>
25
+ <div class="card">
26
+ <h2>API tokens</h2>
27
+ <p class="muted">Let a script or another app use your account through the API. Send the token as <code>Authorization: Bearer …</code>.</p>
28
+ <p k-if="problem" class="alert danger" role="alert">{problem}</p>
29
+
30
+ <form @submit.prevent={create}>
31
+ <input k-model="name" placeholder="Token name, like Reports script" aria-label="Token name">
32
+ <div class="abilities" k-if="tokens.data">
33
+ {for a in tokens.data.abilities}
34
+ <label><input type="checkbox" checked={chosen.includes(a)} @change="toggle(a)"> {a}</label>
35
+ {/for}
36
+ </div>
37
+ <button class="primary" disabled={!name.trim() || !chosen.length}>Create token</button>
38
+ </form>
39
+
40
+ <div k-if="created" class="alert success new">
41
+ <p><strong>{created.name}</strong>: copy it now. It is not shown again.</p>
42
+ <div class="row"><code>{created.token}</code><button class="sm" @click={copy}>Copy</button></div>
43
+ </div>
44
+
45
+ <ul k-if="tokens.data && tokens.data.tokens.length" class="list">
46
+ {for t in tokens.data.tokens key t.id}
47
+ <li>
48
+ <div>
49
+ <strong>{t.name}</strong>
50
+ <div class="muted small">{t.abilities.join(', ')} · {t.last_used_at ? 'last used ' + new Date(t.last_used_at).toLocaleDateString() : 'never used'}</div>
51
+ </div>
52
+ <button class="ghost sm" @click="remove(t)">Delete</button>
53
+ </li>
54
+ {/for}
55
+ </ul>
56
+ </div>
57
+ </view>
58
+
59
+ <style scoped>
60
+ form { display: grid; gap: 10px; max-width: 420px; margin: 12px 0; }
61
+ .abilities { display: flex; gap: 14px; flex-wrap: wrap; font-size: 14px; }
62
+ .abilities label { display: inline-flex; align-items: center; gap: 6px; }
63
+ form button { justify-self: start; }
64
+ .new code { word-break: break-all; }
65
+ .row { display: flex; align-items: center; gap: 8px; }
66
+ .list { list-style: none; padding: 0; margin: 12px 0 0; border: 1px solid var(--border); }
67
+ .list li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--border); }
68
+ .list li:last-child { border-bottom: 0; }
69
+ .small { font-size: 13px; }
70
+ </style>
@@ -0,0 +1,42 @@
1
+ <!-- Browser sessions: the devices signed in to this account (pages/Profile.kreftjs, /api/user/sessions) -->
2
+ load sessions = api.get('/api/user/sessions')
3
+ state problem = ''
4
+
5
+ action logout(s) {
6
+ problem = ''
7
+ try { await api.delete('/api/user/sessions/' + s.id); sessions.data = sessions.data.filter((x) => x.id !== s.id) }
8
+ catch (e) { problem = e.message }
9
+ }
10
+ action logoutOthers() {
11
+ problem = ''
12
+ try { await api.delete('/api/user/sessions'); sessions.reload() }
13
+ catch (e) { if (e.status !== 423) problem = e.message }
14
+ }
15
+
16
+ <view>
17
+ <div class="card">
18
+ <h2>Browser sessions</h2>
19
+ <p class="muted">The devices signed in to your account. Log out any you don't know, then change your password.</p>
20
+ <p k-if="problem" class="alert danger" role="alert">{problem}</p>
21
+ <p k-if="sessions.loading" class="muted">Loading…</p>
22
+ <ul k-elif="sessions.data" class="list">
23
+ {for s in sessions.data key s.id}
24
+ <li>
25
+ <div>
26
+ <strong>{s.name}</strong> <span k-if="s.current" class="badge solid">This device</span>
27
+ <div class="muted small">{s.ip_address || 'unknown address'} · last active {s.last_used_at ? new Date(s.last_used_at).toLocaleString() : ''}</div>
28
+ </div>
29
+ <button k-if="!s.current" class="ghost sm" @click="logout(s)">Log out</button>
30
+ </li>
31
+ {/for}
32
+ </ul>
33
+ <button k-if="sessions.data && sessions.data.length > 1" @click={logoutOthers}>Log out other devices</button>
34
+ </div>
35
+ </view>
36
+
37
+ <style scoped>
38
+ .list { list-style: none; padding: 0; margin: 12px 0; border: 1px solid var(--border); }
39
+ .list li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--border); }
40
+ .list li:last-child { border-bottom: 0; }
41
+ .small { font-size: 13px; }
42
+ </style>