adula 2.0.0 → 2.2.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 (214) hide show
  1. package/README.md +149 -18
  2. package/build/agent/AGENTS.template.md +4 -4
  3. package/build/agent/capabilities.md +22 -11
  4. package/build/agent/skills/adula-frontend-design/SKILL.md +1 -1
  5. package/build/agent/skills/idea-review/SKILL.md +2 -2
  6. package/build/commands/adula_outbox.d.ts +10 -0
  7. package/build/commands/adula_outbox.js +11 -0
  8. package/build/commands/adula_restore_reconcile.d.ts +10 -0
  9. package/build/commands/adula_restore_reconcile.js +34 -0
  10. package/build/commands/adula_runtime_health.d.ts +10 -0
  11. package/build/commands/adula_runtime_health.js +27 -0
  12. package/build/commands/adula_uploads_prune.d.ts +10 -0
  13. package/build/commands/adula_uploads_prune.js +16 -0
  14. package/build/commands/app.d.ts +10 -0
  15. package/build/commands/app.js +64 -0
  16. package/build/commands/backup_create.d.ts +11 -0
  17. package/build/commands/backup_create.js +99 -0
  18. package/build/commands/backup_restore_files.d.ts +11 -0
  19. package/build/commands/backup_restore_files.js +44 -0
  20. package/build/commands/backup_restore_test.d.ts +12 -0
  21. package/build/commands/backup_restore_test.js +185 -0
  22. package/build/commands/backup_services.d.ts +31 -0
  23. package/build/commands/backup_services.js +6 -0
  24. package/build/commands/backup_verify.d.ts +9 -0
  25. package/build/commands/backup_verify.js +59 -0
  26. package/build/commands/backup_verify_snapshot.d.ts +10 -0
  27. package/build/commands/backup_verify_snapshot.js +37 -0
  28. package/build/commands/client.d.ts +16 -0
  29. package/build/commands/client.js +71 -0
  30. package/build/commands/doctor.js +4 -1
  31. package/build/commands/install.d.ts +8 -0
  32. package/build/commands/install.js +63 -45
  33. package/build/commands/main.d.ts +3 -2
  34. package/build/commands/main.js +26 -0
  35. package/build/commands/module_add.js +4 -20
  36. package/build/commands/resource.d.ts +2 -0
  37. package/build/commands/resource.js +12 -3
  38. package/build/commands/resource_migration.d.ts +15 -0
  39. package/build/commands/resource_migration.js +72 -0
  40. package/build/commands/resource_snapshot.d.ts +2 -0
  41. package/build/commands/resource_snapshot.js +3 -0
  42. package/build/commands/sla_evaluate.d.ts +14 -0
  43. package/build/commands/sla_evaluate.js +16 -0
  44. package/build/commands/ui.js +5 -3
  45. package/build/commands/ui_css.d.ts +9 -0
  46. package/build/commands/ui_css.js +19 -0
  47. package/build/commands/upgrade.d.ts +1 -1
  48. package/build/commands/upgrade.js +1 -1
  49. package/build/configure.js +1 -1
  50. package/build/database/migrations/1770000000020_two_factor.d.ts +5 -0
  51. package/build/database/migrations/1770000000020_two_factor.js +10 -0
  52. package/build/database/migrations/1770000000041_import_modes.d.ts +5 -0
  53. package/build/database/migrations/1770000000041_import_modes.js +10 -0
  54. package/build/database/migrations/1770000000042_sync_jobs.d.ts +5 -0
  55. package/build/database/migrations/1770000000042_sync_jobs.js +10 -0
  56. package/build/database/migrations/1770000000043_notification_channels.d.ts +5 -0
  57. package/build/database/migrations/1770000000043_notification_channels.js +10 -0
  58. package/build/database/migrations/1770000000044_channel_confirmations.d.ts +5 -0
  59. package/build/database/migrations/1770000000044_channel_confirmations.js +10 -0
  60. package/build/database/migrations/1770000000045_import_leases.d.ts +5 -0
  61. package/build/database/migrations/1770000000045_import_leases.js +10 -0
  62. package/build/database/migrations/1770000000046_workflow_delegation_sla.d.ts +5 -0
  63. package/build/database/migrations/1770000000046_workflow_delegation_sla.js +10 -0
  64. package/build/database/migrations/1770000000049_print_templates.d.ts +5 -0
  65. package/build/database/migrations/1770000000049_print_templates.js +10 -0
  66. package/build/index.d.ts +56 -10
  67. package/build/index.js +34 -6
  68. package/build/providers/adula_provider.d.ts +2 -0
  69. package/build/providers/adula_provider.js +7 -0
  70. package/build/src/admin/contracts.js +1 -1
  71. package/build/src/admin/controller.d.ts +14 -1
  72. package/build/src/admin/controller.js +77 -13
  73. package/build/src/admin/errors.d.ts +32 -0
  74. package/build/src/admin/errors.js +63 -1
  75. package/build/src/admin/presentation.d.ts +21 -2
  76. package/build/src/admin/resource/editor.d.ts +59 -0
  77. package/build/src/admin/resource/editor.js +323 -0
  78. package/build/src/admin/resource/export.d.ts +37 -0
  79. package/build/src/admin/resource/export.js +181 -0
  80. package/build/src/admin/resource/lifecycle.d.ts +21 -0
  81. package/build/src/admin/resource/lifecycle.js +91 -0
  82. package/build/src/admin/resource/query.d.ts +100 -0
  83. package/build/src/admin/resource/query.js +508 -0
  84. package/build/src/admin/resource/read.d.ts +106 -0
  85. package/build/src/admin/resource/read.js +327 -0
  86. package/build/src/admin/resource/shared.d.ts +77 -0
  87. package/build/src/admin/resource/shared.js +222 -0
  88. package/build/src/admin/resource/trash.d.ts +10 -0
  89. package/build/src/admin/resource/trash.js +56 -0
  90. package/build/src/admin/resource/write.d.ts +57 -0
  91. package/build/src/admin/resource/write.js +574 -0
  92. package/build/src/admin/resource_service.d.ts +66 -193
  93. package/build/src/admin/resource_service.js +69 -1345
  94. package/build/src/attachments/attachment_service.d.ts +46 -2
  95. package/build/src/attachments/attachment_service.js +96 -4
  96. package/build/src/auth/conditions.d.ts +5 -0
  97. package/build/src/auth/conditions.js +26 -3
  98. package/build/src/auth/sql.js +17 -5
  99. package/build/src/auth/two_factor.d.ts +96 -0
  100. package/build/src/auth/two_factor.js +259 -0
  101. package/build/src/collaboration/assignments.d.ts +36 -1
  102. package/build/src/collaboration/assignments.js +132 -66
  103. package/build/src/collaboration/record_collaboration.d.ts +2 -3
  104. package/build/src/collaboration/record_collaboration.js +19 -16
  105. package/build/src/collaboration/shared.d.ts +16 -0
  106. package/build/src/collaboration/shared.js +21 -0
  107. package/build/src/commands/app_scaffold.d.ts +72 -0
  108. package/build/src/commands/app_scaffold.js +285 -0
  109. package/build/src/commands/capabilities.js +34 -8
  110. package/build/src/commands/doctor.d.ts +14 -2
  111. package/build/src/commands/doctor.js +50 -5
  112. package/build/src/commands/gap_report.d.ts +1 -1
  113. package/build/src/commands/gap_report.js +2 -2
  114. package/build/src/commands/generator.d.ts +37 -1
  115. package/build/src/commands/generator.js +61 -18
  116. package/build/src/commands/snapshot.d.ts +10 -13
  117. package/build/src/commands/snapshot.js +31 -14
  118. package/build/src/commands/source_markers.d.ts +10 -0
  119. package/build/src/commands/source_markers.js +29 -0
  120. package/build/src/core/activity.d.ts +2 -0
  121. package/build/src/core/activity.js +7 -1
  122. package/build/src/core/administrators.d.ts +38 -0
  123. package/build/src/core/administrators.js +129 -0
  124. package/build/src/core/html_sanitizer.d.ts +20 -0
  125. package/build/src/core/html_sanitizer.js +261 -0
  126. package/build/src/core/like.d.ts +5 -0
  127. package/build/src/core/like.js +5 -0
  128. package/build/src/core/lookups.d.ts +80 -0
  129. package/build/src/core/lookups.js +319 -0
  130. package/build/src/core/message_templates.d.ts +7 -2
  131. package/build/src/core/message_templates.js +72 -11
  132. package/build/src/core/module_seed.js +2 -1
  133. package/build/src/core/notification_channels.d.ts +235 -0
  134. package/build/src/core/notification_channels.js +660 -0
  135. package/build/src/core/roles.js +2 -2
  136. package/build/src/core/saved_views.d.ts +8 -1
  137. package/build/src/core/saved_views.js +36 -2
  138. package/build/src/core/sequences.d.ts +32 -0
  139. package/build/src/core/sequences.js +97 -0
  140. package/build/src/core/settings.d.ts +5 -0
  141. package/build/src/core/settings.js +19 -2
  142. package/build/src/core/template_language.d.ts +61 -0
  143. package/build/src/core/template_language.js +141 -0
  144. package/build/src/core/ui_preferences.d.ts +4 -0
  145. package/build/src/core/ui_preferences.js +4 -1
  146. package/build/src/core/user_invitations.d.ts +5 -1
  147. package/build/src/core/user_invitations.js +7 -1
  148. package/build/src/core/users.js +1 -1
  149. package/build/src/database/calendar_days.d.ts +19 -0
  150. package/build/src/database/calendar_days.js +36 -0
  151. package/build/src/database/schema.d.ts +155 -2
  152. package/build/src/database/schema.js +531 -59
  153. package/build/src/database/schema_diff.d.ts +56 -0
  154. package/build/src/database/schema_diff.js +157 -0
  155. package/build/src/events/record_mutation.d.ts +2 -1
  156. package/build/src/events/record_mutation.js +1 -0
  157. package/build/src/integrations/api_client.d.ts +37 -0
  158. package/build/src/integrations/api_client.js +552 -0
  159. package/build/src/integrations/import_adapters.d.ts +37 -0
  160. package/build/src/integrations/import_adapters.js +35 -0
  161. package/build/src/integrations/imports.d.ts +118 -16
  162. package/build/src/integrations/imports.js +406 -73
  163. package/build/src/integrations/openapi.d.ts +3 -1
  164. package/build/src/integrations/openapi.js +454 -31
  165. package/build/src/integrations/outbound.d.ts +51 -0
  166. package/build/src/integrations/outbound.js +195 -0
  167. package/build/src/integrations/print.d.ts +21 -1
  168. package/build/src/integrations/print.js +63 -21
  169. package/build/src/integrations/print_templates.d.ts +216 -0
  170. package/build/src/integrations/print_templates.js +1015 -0
  171. package/build/src/integrations/sync_jobs.d.ts +139 -0
  172. package/build/src/integrations/sync_jobs.js +416 -0
  173. package/build/src/integrations/webhooks.d.ts +12 -12
  174. package/build/src/integrations/webhooks.js +34 -43
  175. package/build/src/languages/ar.d.ts +11 -0
  176. package/build/src/languages/ar.js +336 -0
  177. package/build/src/languages/ar_ui.d.ts +332 -0
  178. package/build/src/languages/ar_ui.js +333 -0
  179. package/build/src/languages/catalog.d.ts +66 -0
  180. package/build/src/languages/catalog.js +152 -0
  181. package/build/src/languages/en.d.ts +7 -0
  182. package/build/src/languages/en.js +330 -0
  183. package/build/src/languages/en_ui.d.ts +3 -0
  184. package/build/src/languages/en_ui.js +328 -0
  185. package/build/src/languages/validation.d.ts +26 -0
  186. package/build/src/languages/validation.js +60 -0
  187. package/build/src/lists/bulk_actions.d.ts +89 -0
  188. package/build/src/lists/bulk_actions.js +268 -0
  189. package/build/src/lists/dashboards.d.ts +96 -0
  190. package/build/src/lists/dashboards.js +241 -0
  191. package/build/src/mcp/tools.js +1 -1
  192. package/build/src/resource/define_resource.d.ts +18 -1
  193. package/build/src/resource/define_resource.js +205 -18
  194. package/build/src/resource/definition.d.ts +44 -0
  195. package/build/src/resource/definition.js +171 -0
  196. package/build/src/resource/registry.js +15 -4
  197. package/build/src/resource/types.d.ts +304 -16
  198. package/build/src/resource/values.d.ts +56 -1
  199. package/build/src/resource/values.js +237 -5
  200. package/build/src/services/settings.d.ts +2 -0
  201. package/build/src/services/settings.js +5 -1
  202. package/build/src/upgrade/legacy.js +2 -2
  203. package/build/src/workflows/calendar.d.ts +9 -0
  204. package/build/src/workflows/calendar.js +44 -0
  205. package/build/src/workflows/define_workflow.d.ts +48 -3
  206. package/build/src/workflows/define_workflow.js +57 -13
  207. package/build/src/workflows/delegations.d.ts +93 -0
  208. package/build/src/workflows/delegations.js +287 -0
  209. package/build/src/workflows/engine.d.ts +69 -4
  210. package/build/src/workflows/engine.js +441 -83
  211. package/build/src/workflows/sla.d.ts +15 -0
  212. package/build/src/workflows/sla.js +8 -0
  213. package/build/stubs/resource_contract.txt +12 -1
  214. package/package.json +5 -2
@@ -1,64 +1,71 @@
1
- import { BaseCommand } from '@adonisjs/core/ace';
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { BaseCommand, flags } from '@adonisjs/core/ace';
8
+ import { randomBytes } from 'node:crypto';
2
9
  import { readFile, writeFile, access } from 'node:fs/promises';
3
- import { Settings } from '../src/services/settings.js';
10
+ import { grantInstallAdministrator, resolveInstallAdministrator, } from '../src/core/administrators.js';
4
11
  import { seedModules } from '../src/core/module_seed.js';
5
12
  import { syncAgentAssets } from '../src/commands/agent_assets.js';
6
13
  import { GAPS_TEMPLATE } from '../src/commands/gap_report.js';
7
14
  import { ADULA_VERSION } from '../src/version.js';
8
15
  import { fileURLToPath } from 'node:url';
16
+ /**
17
+ * Installs the core organization, administrator role and managed agent instructions.
18
+ * Creating or re-securing the first administrator requires the application's `#models/user`
19
+ * Lucid model (with `email`, `fullName` and a hashed `password`); it is loaded only then.
20
+ */
9
21
  export default class Install extends BaseCommand {
10
22
  static commandName = 'adula:install';
11
- static description = 'Install core organization, administrator role and managed agent instructions after migrations';
23
+ static description = 'Install core organization, administrator role (creating the first administrator when missing) and managed agent instructions after migrations';
12
24
  static options = { startApp: true };
13
25
  async run() {
14
26
  const { default: db } = await import('@adonisjs/lucid/services/db');
15
27
  const knex = db.connection().getWriteClient();
16
- const email = process.env.ADULA_ADMIN_EMAIL;
28
+ const email = (this.adminEmail ?? process.env.ADULA_ADMIN_EMAIL)?.trim().toLowerCase();
17
29
  if (!email)
18
- throw new Error('Set ADULA_ADMIN_EMAIL to an existing user email. Create the user through the official auth flow first.');
19
- const user = await knex('users').where({ email }).first('id');
20
- if (!user)
21
- throw new Error('Administrator user does not exist. Create it using the official signup flow first.');
22
- await knex.transaction(async (trx) => {
23
- await trx.raw('SELECT pg_advisory_xact_lock(717011)');
24
- let root = await trx('org_units').whereNull('parent_id').first();
25
- if (!root) {
26
- const [created] = await trx('org_units')
27
- .insert({ name: 'الجهة', type: 'root', path: 'root' })
28
- .returning('*');
29
- await trx('org_units')
30
- .where('id', created.id)
31
- .update({ path: String(created.id) });
32
- root = created;
30
+ throw new Error('Set ADULA_ADMIN_EMAIL (or pass --admin-email) to the administrator e-mail address.');
31
+ let password;
32
+ const userModel = async () => {
33
+ try {
34
+ const module = await this.app.import('#models/user');
35
+ return module.default;
33
36
  }
34
- let role = await trx('roles').where('name', 'administrator').first();
35
- if (!role) {
36
- const [created] = await trx('roles')
37
- .insert({ name: 'administrator', key: 'administrator', permission_level: 1 })
38
- .returning('*');
39
- role = created;
37
+ catch (error) {
38
+ throw new Error("adula:install creates the first administrator through the application's #models/user model; it was not found", { cause: error });
40
39
  }
41
- else if (!role.key && !(await trx('roles').where('key', 'administrator').first()))
42
- await trx('roles').where('id', role.id).update({ key: 'administrator' });
43
- // Repair a missing bootstrap grant even when the role already exists.
44
- // The transaction lock makes repeated/concurrent installation idempotent.
45
- if (!(await trx('role_rules')
46
- .where({ role_id: role.id, subject: 'all', action: 'manage', inverted: false })
47
- .whereNull('conditions')
48
- .whereNull('fields')
49
- .first()))
50
- await trx('role_rules').insert({ role_id: role.id, subject: 'all', action: 'manage' });
51
- if (!(await trx('user_roles')
52
- .where({ user_id: user.id, role_id: role.id })
53
- .whereNull('org_unit_id')
54
- .first()))
55
- await trx('user_roles').insert({ user_id: user.id, role_id: role.id });
56
- await trx('user_org_units')
57
- .insert({ user_id: user.id, org_unit_id: root.id })
58
- .onConflict(['user_id', 'org_unit_id'])
59
- .ignore();
60
- await new Settings(trx).set('adula.version', ADULA_VERSION);
40
+ };
41
+ const user = await resolveInstallAdministrator(knex, email, async () => {
42
+ // The first administrator is created here so self-signup is never the bootstrap path.
43
+ password = randomBytes(18).toString('base64url');
44
+ const User = await userModel();
45
+ const created = await User.create({
46
+ email,
47
+ fullName: this.adminName?.trim() || 'مدير النظام',
48
+ password,
49
+ });
50
+ return Number(created.id);
51
+ }, {
52
+ // Anyone may have self-registered this address before the first administrator existed.
53
+ rotatePassword: this.keepPassword
54
+ ? undefined
55
+ : async (id) => {
56
+ password = randomBytes(18).toString('base64url');
57
+ const User = await userModel();
58
+ const account = await User.findOrFail(id);
59
+ account.password = password;
60
+ await account.save();
61
+ },
61
62
  });
63
+ await grantInstallAdministrator(knex, user.id, ADULA_VERSION);
64
+ // Shown once on the terminal and never written to a file; change it after signing in.
65
+ if (user.created && password)
66
+ this.logger.warning(`First administrator ${email} created. One-time password (change it after signing in): ${password}`);
67
+ if (user.rotated && password)
68
+ this.logger.warning(`Existing account ${email} promoted to first administrator: its password was replaced and ${user.rotated.sessions} session(s), ${user.rotated.tokens} API token(s), ${user.rotated.resetTokens} recovery link(s) and ${user.rotated.invitations} invitation(s) were ended. One-time password (change it after signing in): ${password}. Pass --keep-password only for an account you created yourself.`);
62
69
  // Module lookups and default roles: added when missing, never overwritten.
63
70
  let registry;
64
71
  try {
@@ -103,3 +110,14 @@ export default class Install extends BaseCommand {
103
110
  this.logger.success('Core installation complete. Run adula:doctor.');
104
111
  }
105
112
  }
113
+ __decorate([
114
+ flags.string({ description: 'Administrator e-mail (defaults to ADULA_ADMIN_EMAIL)' })
115
+ ], Install.prototype, "adminEmail", void 0);
116
+ __decorate([
117
+ flags.string({ description: 'Full name used when the first administrator is created' })
118
+ ], Install.prototype, "adminName", void 0);
119
+ __decorate([
120
+ flags.boolean({
121
+ description: 'Keep the password of an existing account promoted as the first administrator (only when you created it yourself)',
122
+ })
123
+ ], Install.prototype, "keepPassword", void 0);
@@ -1,8 +1,9 @@
1
1
  import Resource from './resource.js';
2
- import Doctor from './doctor.js';
3
2
  import ModuleAdd from './module_add.js';
4
3
  import Ui from './ui.js';
4
+ import AdulaOutbox from './adula_outbox.js';
5
+ import App from './app.js';
5
6
  export declare function getMetaData(): Promise<import("@adonisjs/core/types/ace").CommandMetaData[]>;
6
7
  export declare function getCommand(meta: {
7
8
  commandName: string;
8
- }): Promise<typeof Resource | typeof Doctor | typeof ModuleAdd | typeof Ui | null>;
9
+ }): Promise<typeof AdulaOutbox | typeof App | typeof Resource | typeof ModuleAdd | typeof Ui | null>;
@@ -1,5 +1,6 @@
1
1
  import Resource from './resource.js';
2
2
  import ResourceSnapshot from './resource_snapshot.js';
3
+ import ResourceMigration from './resource_migration.js';
3
4
  import Doctor from './doctor.js';
4
5
  import Install from './install.js';
5
6
  import Capabilities from './capabilities.js';
@@ -9,9 +10,22 @@ import Ui from './ui.js';
9
10
  import StorageMigrate from './storage_migrate.js';
10
11
  import Gaps from './gaps.js';
11
12
  import Upgrade from './upgrade.js';
13
+ import AdulaOutbox from './adula_outbox.js';
14
+ import AdulaRuntimeHealth from './adula_runtime_health.js';
15
+ import AdulaUploadsPrune from './adula_uploads_prune.js';
16
+ import AdulaRestoreReconcile from './adula_restore_reconcile.js';
17
+ import BackupCreate from './backup_create.js';
18
+ import BackupRestoreFiles from './backup_restore_files.js';
19
+ import BackupRestoreTest from './backup_restore_test.js';
20
+ import BackupVerify from './backup_verify.js';
21
+ import BackupVerifySnapshot from './backup_verify_snapshot.js';
22
+ import App from './app.js';
23
+ import Client from './client.js';
24
+ import SlaEvaluate from './sla_evaluate.js';
12
25
  const commands = [
13
26
  Resource,
14
27
  ResourceSnapshot,
28
+ ResourceMigration,
15
29
  Doctor,
16
30
  Install,
17
31
  Capabilities,
@@ -21,6 +35,18 @@ const commands = [
21
35
  StorageMigrate,
22
36
  Gaps,
23
37
  Upgrade,
38
+ AdulaOutbox,
39
+ AdulaRuntimeHealth,
40
+ AdulaUploadsPrune,
41
+ AdulaRestoreReconcile,
42
+ BackupCreate,
43
+ BackupRestoreFiles,
44
+ BackupRestoreTest,
45
+ BackupVerify,
46
+ BackupVerifySnapshot,
47
+ App,
48
+ Client,
49
+ SlaEvaluate,
24
50
  ];
25
51
  export async function getMetaData() {
26
52
  return commands.map((command) => {
@@ -7,7 +7,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7
7
  import { BaseCommand, args, flags } from '@adonisjs/core/ace';
8
8
  import { mkdir, readFile, writeFile, access } from 'node:fs/promises';
9
9
  import { identifier } from '../src/resource/define_resource.js';
10
- import { appendMarkedItem, moduleSource } from '../src/commands/source_markers.js';
10
+ import { MODULE_DIRECTORIES, moduleSource, registerModuleSource, } from '../src/commands/source_markers.js';
11
11
  export default class ModuleAdd extends BaseCommand {
12
12
  static commandName = 'adula:module:add';
13
13
  static description = 'Create and register an application-owned module';
@@ -25,28 +25,12 @@ export default class ModuleAdd extends BaseCommand {
25
25
  throw error;
26
26
  }
27
27
  const indexPath = this.app.makePath('start/modules.ts');
28
- const source = await readFile(indexPath, 'utf8');
29
- if (!source.includes('// adula:imports'))
30
- throw new Error('Module index registration markers are missing');
31
- const alias = `module_${this.name}`;
32
- const next = appendMarkedItem(source.replace('// adula:imports', `import ${alias} from '#modules/${this.name}/module'\n// adula:imports`), '/* adula:modules */', alias);
33
- for (const directory of [
34
- 'models',
35
- 'resources',
36
- 'validators',
37
- 'migrations',
38
- 'factories',
39
- 'listeners',
40
- 'jobs',
41
- 'workflows',
42
- 'reports',
43
- 'pages',
44
- 'tests',
45
- ])
28
+ const next = registerModuleSource(await readFile(indexPath, 'utf8'), this.name);
29
+ for (const directory of MODULE_DIRECTORIES)
46
30
  await mkdir(this.app.makePath('app/modules', this.name, directory), { recursive: true });
47
31
  await writeFile(this.app.makePath('app/modules', this.name, 'module.ts'), moduleSource(this.name, { reference: Boolean(this.reference), typed: true }), { flag: 'wx' });
48
32
  await writeFile(indexPath, next);
49
- this.logger.success(`Created ${this.name}. Fill bilingual labels and declare dependencies before adding resources.`);
33
+ this.logger.success(`Created ${this.name}. Fill the Arabic labels (other languages are optional) and declare dependencies before adding resources.`);
50
34
  }
51
35
  }
52
36
  __decorate([
@@ -4,5 +4,7 @@ export default class Resource extends BaseCommand {
4
4
  static description: string;
5
5
  name: string;
6
6
  module: string;
7
+ validator: boolean;
8
+ model: boolean;
7
9
  run(): Promise<void>;
8
10
  }
@@ -9,16 +9,19 @@ import { generateResource } from '../src/commands/generator.js';
9
9
  import { fileURLToPath } from 'node:url';
10
10
  export default class Resource extends BaseCommand {
11
11
  static commandName = 'adula:resource';
12
- static description = 'Generate a scoped resource, migration, model, validator, factory and security contract';
12
+ static description = 'Generate a scoped resource, its create-migration and security contract (validator and model are derived; opt in with --validator / --model)';
13
13
  async run() {
14
14
  if (!this.module) {
15
15
  this.logger.error('--module is required');
16
16
  this.exitCode = 1;
17
17
  return;
18
18
  }
19
- const files = await generateResource(fileURLToPath(this.app.appRoot), this.name, this.module);
19
+ const files = await generateResource(fileURLToPath(this.app.appRoot), this.name, this.module, {
20
+ validator: Boolean(this.validator),
21
+ model: Boolean(this.model),
22
+ });
20
23
  files.forEach((file) => this.logger.success(file));
21
- this.logger.info('Set bilingual labels (label: the plural list heading; recordLabel: the singular record noun) and fill the resource definition. The generated migration embeds the definition as scaffolded: after filling the definition, run `node ace adula:resource:snapshot <name>` to refresh the pending migration, and update the model, factory and contract fixture, before migration:run. adula:doctor reports a pending migration that differs. Then run the generated security contract.');
24
+ this.logger.info('Set the Arabic labels (label: the plural list heading; recordLabel: the singular record noun; label.en and other languages are optional) and fill the resource definition: its fields decide validation, columns and forms. The generated migration embeds the definition as scaffolded: run migration:run, then after adding fields run `node ace adula:resource:migration <name>` for an additive migration of what the table lacks. adula:doctor reports tables that differ from their definitions. Then run the generated security contract.');
22
25
  }
23
26
  }
24
27
  __decorate([
@@ -27,3 +30,9 @@ __decorate([
27
30
  __decorate([
28
31
  flags.string()
29
32
  ], Resource.prototype, "module", void 0);
33
+ __decorate([
34
+ flags.boolean({ description: 'Also write a VineJS validator file instead of the derived one' })
35
+ ], Resource.prototype, "validator", void 0);
36
+ __decorate([
37
+ flags.boolean({ description: 'Also write a Lucid model and factory for your own code' })
38
+ ], Resource.prototype, "model", void 0);
@@ -0,0 +1,15 @@
1
+ import { BaseCommand } from '@adonisjs/core/ace';
2
+ /**
3
+ * Writes an additive migration with what the database lacks for a resource: new
4
+ * columns, join tables and unique indexes (see alterResourceTable). Only the new pieces
5
+ * are embedded, so migrations that already ran stay unchanged.
6
+ */
7
+ export default class ResourceMigration extends BaseCommand {
8
+ static commandName: string;
9
+ static description: string;
10
+ static options: {
11
+ startApp: boolean;
12
+ };
13
+ name: string;
14
+ run(): Promise<void>;
15
+ }
@@ -0,0 +1,72 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { BaseCommand, args } from '@adonisjs/core/ace';
8
+ import { mkdir, readFile, writeFile } from 'node:fs/promises';
9
+ import { dirname } from 'node:path';
10
+ import { MigrationRunner } from '@adonisjs/lucid/migration';
11
+ import { embeddedResource } from '../src/commands/snapshot.js';
12
+ import { additionMigrationSource, describeDrift, resourceAddition, schemaDrift, } from '../src/database/schema_diff.js';
13
+ /**
14
+ * Writes an additive migration with what the database lacks for a resource: new
15
+ * columns, join tables and unique indexes (see alterResourceTable). Only the new pieces
16
+ * are embedded, so migrations that already ran stay unchanged.
17
+ */
18
+ export default class ResourceMigration extends BaseCommand {
19
+ static commandName = 'adula:resource:migration';
20
+ static description = 'Write an additive migration for the columns, join tables and unique indexes a resource table lacks';
21
+ static options = { startApp: true };
22
+ async run() {
23
+ const { default: db } = await import('@adonisjs/lucid/services/db');
24
+ const { registry } = (await this.app.import('#start/modules'));
25
+ let resource;
26
+ try {
27
+ resource = registry.get(this.name);
28
+ }
29
+ catch {
30
+ this.logger.error(`Unknown resource: ${this.name}. Register it in its module first.`);
31
+ this.exitCode = 1;
32
+ return;
33
+ }
34
+ const drift = await schemaDrift(db.connection().getWriteClient(), resource);
35
+ if (drift.missingTable) {
36
+ this.logger.error(`${this.name} has no table yet: run its create-migration with migration:run first.`);
37
+ this.exitCode = 1;
38
+ return;
39
+ }
40
+ for (const entry of drift.wrongTypes)
41
+ this.logger.warning(`${this.name}.${entry.column} is ${entry.actual}, the definition expects ${entry.expected}; types are never changed automatically (write an expand/contract migration).`);
42
+ const addition = resourceAddition(resource, drift);
43
+ if (!Object.keys(addition).length) {
44
+ this.logger.info(`${this.name}: the database already has every column, join table and unique index.`);
45
+ return;
46
+ }
47
+ // Next to the resource's create-migration, or in its module's migrations folder.
48
+ let folder = `app/modules/${registry.owner(this.name)}/migrations`;
49
+ const migrations = await new MigrationRunner(db, this.app, { direction: 'up' }).getList();
50
+ for (const entry of migrations)
51
+ for (const extension of ['.ts', '.js'])
52
+ try {
53
+ const source = await readFile(this.app.makePath(`${entry.name}${extension}`), 'utf8');
54
+ if (embeddedResource(source) === this.name)
55
+ folder = dirname(entry.name);
56
+ break;
57
+ }
58
+ catch { }
59
+ const file = `${folder}/${Date.now()}_alter_${this.name}.ts`;
60
+ await mkdir(this.app.makePath(folder), { recursive: true });
61
+ await writeFile(this.app.makePath(file), additionMigrationSource(this.name, addition), {
62
+ flag: 'wx',
63
+ });
64
+ for (const line of describeDrift(drift))
65
+ this.logger.info(line);
66
+ this.logger.success(file);
67
+ this.logger.info('Review the migration, then run migration:run after the deployment backup.');
68
+ }
69
+ }
70
+ __decorate([
71
+ args.string({ description: 'Resource name' })
72
+ ], ResourceMigration.prototype, "name", void 0);
@@ -3,6 +3,8 @@ import { BaseCommand } from '@adonisjs/core/ace';
3
3
  * Rewrites the definition embedded in a resource's generated create-migration from the
4
4
  * current resource, while that migration has not run yet (#20). A migration that already
5
5
  * ran is never edited: change the table with a new expand migration instead.
6
+ *
7
+ * @deprecated Use adula:resource:migration after the create-migration ran (ADR 045).
6
8
  */
7
9
  export default class ResourceSnapshot extends BaseCommand {
8
10
  static commandName: string;
@@ -12,12 +12,15 @@ import { embeddedResource, resourceSnapshot, rewriteResourceSnapshot, } from '..
12
12
  * Rewrites the definition embedded in a resource's generated create-migration from the
13
13
  * current resource, while that migration has not run yet (#20). A migration that already
14
14
  * ran is never edited: change the table with a new expand migration instead.
15
+ *
16
+ * @deprecated Use adula:resource:migration after the create-migration ran (ADR 045).
15
17
  */
16
18
  export default class ResourceSnapshot extends BaseCommand {
17
19
  static commandName = 'adula:resource:snapshot';
18
20
  static description = "Refresh a pending generated create-migration from the resource's current definition";
19
21
  static options = { startApp: true };
20
22
  async run() {
23
+ this.logger.warning('adula:resource:snapshot is deprecated (ADR 045): run the create-migration as scaffolded, then add later fields with node ace adula:resource:migration <name>.');
21
24
  const { default: db } = await import('@adonisjs/lucid/services/db');
22
25
  const { registry } = (await this.app.import('#start/modules'));
23
26
  let resource;
@@ -0,0 +1,14 @@
1
+ import { BaseCommand } from '@adonisjs/core/ace';
2
+ /**
3
+ * The `sla:` job family (ADR 044): reminds approvers before their deadline and runs
4
+ * each overdue step's escalation policy once. The application owns the engine wiring in
5
+ * `#services/workflow_sla`; the scheduler runs this every minute without overlap.
6
+ */
7
+ export default class SlaEvaluate extends BaseCommand {
8
+ static commandName: string;
9
+ static description: string;
10
+ static options: {
11
+ startApp: boolean;
12
+ };
13
+ run(): Promise<void>;
14
+ }
@@ -0,0 +1,16 @@
1
+ import { BaseCommand } from '@adonisjs/core/ace';
2
+ /**
3
+ * The `sla:` job family (ADR 044): reminds approvers before their deadline and runs
4
+ * each overdue step's escalation policy once. The application owns the engine wiring in
5
+ * `#services/workflow_sla`; the scheduler runs this every minute without overlap.
6
+ */
7
+ export default class SlaEvaluate extends BaseCommand {
8
+ static commandName = 'sla:evaluate';
9
+ static description = 'Remind approvers before SLA deadlines and escalate overdue approvals';
10
+ static options = { startApp: true };
11
+ async run() {
12
+ const { evaluateWorkflowSla } = (await this.app.import('#services/workflow_sla'));
13
+ const { reminded, escalated } = await evaluateWorkflowSla();
14
+ this.logger.info(`SLA: ${reminded} reminders, ${escalated} escalations`);
15
+ }
16
+ }
@@ -10,6 +10,7 @@ import { readFile, writeFile, mkdir, access } from 'node:fs/promises';
10
10
  import { dirname, join, resolve, relative, isAbsolute } from 'node:path';
11
11
  import { spawn } from 'node:child_process';
12
12
  import { digest } from '../src/commands/agent_assets.js';
13
+ import { ensureAdulaCssEntry } from './ui_css.js';
13
14
  export default class Ui extends BaseCommand {
14
15
  static commandName = 'adula:ui';
15
16
  static description = 'Install reviewed RTL components through the project-owned shadcn registry';
@@ -88,7 +89,7 @@ export default class Ui extends BaseCommand {
88
89
  dependencies: [
89
90
  ...new Set([
90
91
  ...[...collected.values()].flatMap((item) => item.dependencies ?? []),
91
- ...['tw-animate-css', '@fontsource/noto-sans-arabic'].map((name) => `${name}@${manifest.dependencies[name]}`),
92
+ ...['tw-animate-css', '@fontsource/ibm-plex-sans-arabic'].map((name) => `${name}@${manifest.dependencies[name]}`),
92
93
  ]),
93
94
  ],
94
95
  files: [...collected.values()].flatMap((item) => item.files),
@@ -186,8 +187,9 @@ export default class Ui extends BaseCommand {
186
187
  // One CSS entry fixes layer ordering in development and production bundlers.
187
188
  const adulaCssPath = join(root, 'inertia/css/adula.css');
188
189
  const adulaCss = await readFile(adulaCssPath, 'utf8');
189
- if (!adulaCss.includes('@import "./app.css"'))
190
- await writeFile(adulaCssPath, `@layer theme, base, legacy, components, utilities;\n@import "./app.css";\n${adulaCss}`);
190
+ const entryCss = ensureAdulaCssEntry(adulaCss);
191
+ if (entryCss !== adulaCss)
192
+ await writeFile(adulaCssPath, entryCss);
191
193
  entry.getImportDeclaration('./css/app.css')?.remove();
192
194
  if (!entry.getImportDeclaration('./css/adula.css'))
193
195
  entry.addImportDeclaration({ moduleSpecifier: './css/adula.css' });
@@ -0,0 +1,9 @@
1
+ /**
2
+ * The CSS entry `adula:ui` keeps in `inertia/css/adula.css`: the layer order first, then the
3
+ * legacy application stylesheet. Formatters may rewrite quotes and spacing (prettier writes
4
+ * `@import './app.css';`), so detection is quote- and whitespace-agnostic and re-running the
5
+ * command never prepends the lines again.
6
+ */
7
+ export declare const ADULA_CSS_LAYERS = "@layer theme, base, legacy, components, utilities;";
8
+ export declare const ADULA_CSS_IMPORT = "@import \"./app.css\";";
9
+ export declare function ensureAdulaCssEntry(css: string): string;
@@ -0,0 +1,19 @@
1
+ /**
2
+ * The CSS entry `adula:ui` keeps in `inertia/css/adula.css`: the layer order first, then the
3
+ * legacy application stylesheet. Formatters may rewrite quotes and spacing (prettier writes
4
+ * `@import './app.css';`), so detection is quote- and whitespace-agnostic and re-running the
5
+ * command never prepends the lines again.
6
+ */
7
+ export const ADULA_CSS_LAYERS = '@layer theme, base, legacy, components, utilities;';
8
+ export const ADULA_CSS_IMPORT = '@import "./app.css";';
9
+ const LAYERS = /@layer\s+theme\s*,\s*base\s*,\s*legacy\s*,\s*components\s*,\s*utilities\s*;/;
10
+ const IMPORT = /@import\s+(["'])\.\/app\.css\1[^;]*;/;
11
+ export function ensureAdulaCssEntry(css) {
12
+ const layers = css.match(LAYERS);
13
+ if (IMPORT.test(css))
14
+ return layers ? css : `${ADULA_CSS_LAYERS}\n${css}`;
15
+ // A missing import goes right after the layer order, which must stay the first statement.
16
+ if (layers)
17
+ return css.replace(LAYERS, (statement) => `${statement}\n${ADULA_CSS_IMPORT}`);
18
+ return `${ADULA_CSS_LAYERS}\n${ADULA_CSS_IMPORT}\n${css}`;
19
+ }
@@ -1,6 +1,6 @@
1
1
  import { BaseCommand } from '@adonisjs/core/ace';
2
2
  /**
3
- * Second step of the 2.0 upgrade, after `npx create-adula-app@latest upgrade` has
3
+ * Second step of the 2.0 upgrade, after `npx create-adulajs@latest upgrade` has
4
4
  * moved the application to the `adula` package. Renames the migration history,
5
5
  * the gap log and the managed AGENTS.md block that 1.x wrote, then runs the
6
6
  * pending migrations. Safe to repeat.
@@ -3,7 +3,7 @@ import { fileURLToPath } from 'node:url';
3
3
  import { syncAgentAssets } from '../src/commands/agent_assets.js';
4
4
  import { renameLegacyFiles, renameRecordedMigrations } from '../src/upgrade/rename.js';
5
5
  /**
6
- * Second step of the 2.0 upgrade, after `npx create-adula-app@latest upgrade` has
6
+ * Second step of the 2.0 upgrade, after `npx create-adulajs@latest upgrade` has
7
7
  * moved the application to the `adula` package. Renames the migration history,
8
8
  * the gap log and the managed AGENTS.md block that 1.x wrote, then runs the
9
9
  * pending migrations. Safe to repeat.
@@ -75,5 +75,5 @@ export async function configure(command) {
75
75
  ['shieldApiClient', '@adonisjs/shield/plugins/api_client', ''],
76
76
  ])
77
77
  await codemods.registerJapaPlugin(`${name}(${args})`, [{ module: path, isNamed: true, identifier: name }]);
78
- command.logger.success('AdulaJS configured. Run migration:run, create your user using the official auth flow, then ADULA_ADMIN_EMAIL=<email> node ace adula:install.');
78
+ command.logger.success('AdulaJS configured. Run migration:run, then ADULA_ADMIN_EMAIL=<email> node ace adula:install (it creates the first administrator when that user does not exist).');
79
79
  }
@@ -0,0 +1,5 @@
1
+ import { BaseSchema } from '@adonisjs/lucid/schema';
2
+ export default class TwoFactor extends BaseSchema {
3
+ up(): Promise<void>;
4
+ down(): Promise<void>;
5
+ }
@@ -0,0 +1,10 @@
1
+ import { BaseSchema } from '@adonisjs/lucid/schema';
2
+ import { createTwoFactorSchema } from '../../src/database/schema.js';
3
+ export default class TwoFactor extends BaseSchema {
4
+ async up() {
5
+ await createTwoFactorSchema(this.db.getWriteClient());
6
+ }
7
+ async down() {
8
+ throw new Error('AdulaJS migrations are additive. Restore a tested backup instead of rolling back.');
9
+ }
10
+ }
@@ -0,0 +1,5 @@
1
+ import { BaseSchema } from '@adonisjs/lucid/schema';
2
+ export default class ImportModes extends BaseSchema {
3
+ up(): Promise<void>;
4
+ down(): Promise<void>;
5
+ }
@@ -0,0 +1,10 @@
1
+ import { BaseSchema } from '@adonisjs/lucid/schema';
2
+ import { createImportModesSchema } from '../../src/database/schema.js';
3
+ export default class ImportModes extends BaseSchema {
4
+ async up() {
5
+ await createImportModesSchema(this.db.getWriteClient());
6
+ }
7
+ async down() {
8
+ throw new Error('AdulaJS migrations are additive. Restore a tested backup instead of rolling back.');
9
+ }
10
+ }
@@ -0,0 +1,5 @@
1
+ import { BaseSchema } from '@adonisjs/lucid/schema';
2
+ export default class SyncJobs extends BaseSchema {
3
+ up(): Promise<void>;
4
+ down(): Promise<void>;
5
+ }
@@ -0,0 +1,10 @@
1
+ import { BaseSchema } from '@adonisjs/lucid/schema';
2
+ import { createSyncJobsSchema } from '../../src/database/schema.js';
3
+ export default class SyncJobs extends BaseSchema {
4
+ async up() {
5
+ await createSyncJobsSchema(this.db.getWriteClient());
6
+ }
7
+ async down() {
8
+ throw new Error('AdulaJS migrations are additive. Restore a tested backup instead of rolling back.');
9
+ }
10
+ }
@@ -0,0 +1,5 @@
1
+ import { BaseSchema } from '@adonisjs/lucid/schema';
2
+ export default class NotificationChannels extends BaseSchema {
3
+ up(): Promise<void>;
4
+ down(): Promise<void>;
5
+ }
@@ -0,0 +1,10 @@
1
+ import { BaseSchema } from '@adonisjs/lucid/schema';
2
+ import { createNotificationChannelsSchema } from '../../src/database/schema.js';
3
+ export default class NotificationChannels extends BaseSchema {
4
+ async up() {
5
+ await createNotificationChannelsSchema(this.db.getWriteClient());
6
+ }
7
+ async down() {
8
+ throw new Error('AdulaJS migrations are additive. Restore a tested backup instead of rolling back.');
9
+ }
10
+ }
@@ -0,0 +1,5 @@
1
+ import { BaseSchema } from '@adonisjs/lucid/schema';
2
+ export default class ChannelConfirmations extends BaseSchema {
3
+ up(): Promise<void>;
4
+ down(): Promise<void>;
5
+ }
@@ -0,0 +1,10 @@
1
+ import { BaseSchema } from '@adonisjs/lucid/schema';
2
+ import { createChannelConfirmationsSchema } from '../../src/database/schema.js';
3
+ export default class ChannelConfirmations extends BaseSchema {
4
+ async up() {
5
+ await createChannelConfirmationsSchema(this.db.getWriteClient());
6
+ }
7
+ async down() {
8
+ throw new Error('AdulaJS migrations are additive. Restore a tested backup instead of rolling back.');
9
+ }
10
+ }
@@ -0,0 +1,5 @@
1
+ import { BaseSchema } from '@adonisjs/lucid/schema';
2
+ export default class ImportLeases extends BaseSchema {
3
+ up(): Promise<void>;
4
+ down(): Promise<void>;
5
+ }