db-model-router 1.0.9 → 1.0.11

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 (99) hide show
  1. package/.codegraph/config.json +143 -0
  2. package/CLAUDE.md +150 -0
  3. package/dbmr.schema.json +3 -0
  4. package/docs/dbmr-schema-spec.md +597 -393
  5. package/package.json +1 -1
  6. package/skill/SKILL.md +1 -1
  7. package/skill/references/dbmr-schema-spec.md +597 -0
  8. package/src/cli/commands/generate.js +6 -6
  9. package/src/cli/diff-engine.js +4 -4
  10. package/src/cli/generate-migration.js +4 -0
  11. package/src/cli/generate-route.js +3 -3
  12. package/src/schema/schema-validator.js +1 -1
  13. package/.env +0 -7
  14. package/db-manager/.dbmanager.sqlite +0 -0
  15. package/db-manager/.dbmanager.sqlite-shm +0 -0
  16. package/db-manager/.dbmanager.sqlite-wal +0 -0
  17. package/db-manager/demo/cockroachdb.env +0 -6
  18. package/db-manager/demo/demo.sqlite +0 -0
  19. package/db-manager/demo/dynamodb.env +0 -7
  20. package/db-manager/demo/mongodb.env +0 -4
  21. package/db-manager/demo/mssql.env +0 -6
  22. package/db-manager/demo/mysql.env +0 -6
  23. package/db-manager/demo/oracle.env +0 -6
  24. package/db-manager/demo/postgres.env +0 -6
  25. package/db-manager/demo/redis.env +0 -4
  26. package/db-manager/demo/seeds/cockroachdb.sql +0 -32
  27. package/db-manager/demo/seeds/mssql.sql +0 -32
  28. package/db-manager/demo/seeds/mysql.sql +0 -32
  29. package/db-manager/demo/seeds/oracle.sql +0 -43
  30. package/db-manager/demo/seeds/postgres.sql +0 -32
  31. package/db-manager/demo/seeds/sqlite3.sql +0 -32
  32. package/db-manager/demo/sqlite3.env +0 -2
  33. package/demo/.dockerignore +0 -7
  34. package/demo/.env.example +0 -15
  35. package/demo/Dockerfile +0 -20
  36. package/demo/app.js +0 -39
  37. package/demo/commons/add_migration.js +0 -43
  38. package/demo/commons/db.js +0 -17
  39. package/demo/commons/migrate.js +0 -68
  40. package/demo/commons/modules.js +0 -18
  41. package/demo/commons/password.js +0 -36
  42. package/demo/commons/security.js +0 -30
  43. package/demo/commons/session.js +0 -13
  44. package/demo/commons/webhook.js +0 -81
  45. package/demo/dbmr.schema.json +0 -338
  46. package/demo/middleware/authenticate.js +0 -14
  47. package/demo/middleware/hasPermission.js +0 -30
  48. package/demo/middleware/logger.js +0 -67
  49. package/demo/middleware/tenantIsolation.js +0 -19
  50. package/demo/migrations/20260510193736_create_migrations_table.sql +0 -6
  51. package/demo/migrations/20260510193737_create_saas_tables.sql +0 -69
  52. package/demo/migrations/20260510193737_create_tables.sql +0 -193
  53. package/demo/models/addresses.js +0 -24
  54. package/demo/models/cart_items.js +0 -20
  55. package/demo/models/carts.js +0 -18
  56. package/demo/models/categories.js +0 -22
  57. package/demo/models/coupons.js +0 -25
  58. package/demo/models/index.js +0 -43
  59. package/demo/models/order_items.js +0 -23
  60. package/demo/models/orders.js +0 -27
  61. package/demo/models/payments.js +0 -23
  62. package/demo/models/product_images.js +0 -20
  63. package/demo/models/product_reviews.js +0 -22
  64. package/demo/models/product_variants.js +0 -22
  65. package/demo/models/products.js +0 -32
  66. package/demo/models/role_permissions.js +0 -17
  67. package/demo/models/roles.js +0 -17
  68. package/demo/models/shipments.js +0 -21
  69. package/demo/models/tenants.js +0 -18
  70. package/demo/models/users.js +0 -23
  71. package/demo/models/webhook_logs.js +0 -22
  72. package/demo/models/webhooks.js +0 -19
  73. package/demo/models/wishlists.js +0 -17
  74. package/demo/openapi.json +0 -7000
  75. package/demo/package-lock.json +0 -3972
  76. package/demo/package.json +0 -46
  77. package/demo/routes/addresses/index.js +0 -10
  78. package/demo/routes/auth/index.js +0 -55
  79. package/demo/routes/carts/cart_items/index.js +0 -11
  80. package/demo/routes/carts/index.js +0 -14
  81. package/demo/routes/categories/index.js +0 -10
  82. package/demo/routes/coupons/index.js +0 -10
  83. package/demo/routes/docs.js +0 -18
  84. package/demo/routes/health.js +0 -35
  85. package/demo/routes/index.js +0 -40
  86. package/demo/routes/orders/index.js +0 -18
  87. package/demo/routes/orders/order_items/index.js +0 -11
  88. package/demo/routes/orders/payments/index.js +0 -11
  89. package/demo/routes/orders/shipments/index.js +0 -11
  90. package/demo/routes/products/index.js +0 -18
  91. package/demo/routes/products/product_images/index.js +0 -11
  92. package/demo/routes/products/product_reviews/index.js +0 -11
  93. package/demo/routes/products/product_variants/index.js +0 -11
  94. package/demo/routes/roles/index.js +0 -75
  95. package/demo/routes/roles/permissions/index.js +0 -47
  96. package/demo/routes/tenants/index.js +0 -45
  97. package/demo/routes/users/index.js +0 -45
  98. package/demo/routes/wishlists/index.js +0 -10
  99. package/demo/seeds/saas-seed.js +0 -329
@@ -1,329 +0,0 @@
1
- "use strict";
2
-
3
- const path = require("path");
4
- const fs = require("fs");
5
- const { hashPassword } = require("../commons/password");
6
-
7
- /**
8
- * Super Admin email address.
9
- */
10
- const SUPER_ADMIN_EMAIL = "admin@system.local";
11
-
12
- /**
13
- * Generated password for the Super Admin.
14
- * This is cryptographically random and unique per generation.
15
- */
16
- const SUPER_ADMIN_PASSWORD = "812fed18236314a46972a977b60c69a5";
17
-
18
- /**
19
- * Super Admin permissions: all actions for all modules with global scope.
20
- */
21
- const SUPER_ADMIN_PERMISSIONS = [
22
- {
23
- "module": "users",
24
- "action": "read",
25
- "scope": "global"
26
- },
27
- {
28
- "module": "users",
29
- "action": "write",
30
- "scope": "global"
31
- },
32
- {
33
- "module": "users",
34
- "action": "update",
35
- "scope": "global"
36
- },
37
- {
38
- "module": "users",
39
- "action": "delete",
40
- "scope": "global"
41
- },
42
- {
43
- "module": "users",
44
- "action": "export",
45
- "scope": "global"
46
- },
47
- {
48
- "module": "users",
49
- "action": "approve",
50
- "scope": "global"
51
- },
52
- {
53
- "module": "users",
54
- "action": "global",
55
- "scope": "global"
56
- },
57
- {
58
- "module": "tenants",
59
- "action": "read",
60
- "scope": "global"
61
- },
62
- {
63
- "module": "tenants",
64
- "action": "write",
65
- "scope": "global"
66
- },
67
- {
68
- "module": "tenants",
69
- "action": "update",
70
- "scope": "global"
71
- },
72
- {
73
- "module": "tenants",
74
- "action": "delete",
75
- "scope": "global"
76
- },
77
- {
78
- "module": "tenants",
79
- "action": "export",
80
- "scope": "global"
81
- },
82
- {
83
- "module": "tenants",
84
- "action": "approve",
85
- "scope": "global"
86
- },
87
- {
88
- "module": "tenants",
89
- "action": "global",
90
- "scope": "global"
91
- },
92
- {
93
- "module": "roles",
94
- "action": "read",
95
- "scope": "global"
96
- },
97
- {
98
- "module": "roles",
99
- "action": "write",
100
- "scope": "global"
101
- },
102
- {
103
- "module": "roles",
104
- "action": "update",
105
- "scope": "global"
106
- },
107
- {
108
- "module": "roles",
109
- "action": "delete",
110
- "scope": "global"
111
- },
112
- {
113
- "module": "roles",
114
- "action": "export",
115
- "scope": "global"
116
- },
117
- {
118
- "module": "roles",
119
- "action": "approve",
120
- "scope": "global"
121
- },
122
- {
123
- "module": "roles",
124
- "action": "global",
125
- "scope": "global"
126
- },
127
- {
128
- "module": "permissions",
129
- "action": "read",
130
- "scope": "global"
131
- },
132
- {
133
- "module": "permissions",
134
- "action": "write",
135
- "scope": "global"
136
- },
137
- {
138
- "module": "permissions",
139
- "action": "update",
140
- "scope": "global"
141
- },
142
- {
143
- "module": "permissions",
144
- "action": "delete",
145
- "scope": "global"
146
- },
147
- {
148
- "module": "permissions",
149
- "action": "export",
150
- "scope": "global"
151
- },
152
- {
153
- "module": "permissions",
154
- "action": "approve",
155
- "scope": "global"
156
- },
157
- {
158
- "module": "permissions",
159
- "action": "global",
160
- "scope": "global"
161
- },
162
- {
163
- "module": "webhooks",
164
- "action": "read",
165
- "scope": "global"
166
- },
167
- {
168
- "module": "webhooks",
169
- "action": "write",
170
- "scope": "global"
171
- },
172
- {
173
- "module": "webhooks",
174
- "action": "update",
175
- "scope": "global"
176
- },
177
- {
178
- "module": "webhooks",
179
- "action": "delete",
180
- "scope": "global"
181
- },
182
- {
183
- "module": "webhooks",
184
- "action": "export",
185
- "scope": "global"
186
- },
187
- {
188
- "module": "webhooks",
189
- "action": "approve",
190
- "scope": "global"
191
- },
192
- {
193
- "module": "webhooks",
194
- "action": "global",
195
- "scope": "global"
196
- }
197
- ];
198
-
199
- /**
200
- * Tenant Admin permissions: CRUD for users and roles with tenant scope.
201
- */
202
- const TENANT_ADMIN_PERMISSIONS = [
203
- {
204
- "module": "users",
205
- "action": "read",
206
- "scope": "tenant"
207
- },
208
- {
209
- "module": "users",
210
- "action": "write",
211
- "scope": "tenant"
212
- },
213
- {
214
- "module": "users",
215
- "action": "update",
216
- "scope": "tenant"
217
- },
218
- {
219
- "module": "users",
220
- "action": "delete",
221
- "scope": "tenant"
222
- },
223
- {
224
- "module": "roles",
225
- "action": "read",
226
- "scope": "tenant"
227
- },
228
- {
229
- "module": "roles",
230
- "action": "write",
231
- "scope": "tenant"
232
- },
233
- {
234
- "module": "roles",
235
- "action": "update",
236
- "scope": "tenant"
237
- },
238
- {
239
- "module": "roles",
240
- "action": "delete",
241
- "scope": "tenant"
242
- }
243
- ];
244
-
245
- /**
246
- * Write the credentials.md file with the super admin login details.
247
- */
248
- function writeCredentials() {
249
- const content = `# Super Admin Credentials
250
-
251
- **Email:** ${SUPER_ADMIN_EMAIL}
252
- **Password:** ${SUPER_ADMIN_PASSWORD}
253
-
254
- > ⚠️ **WARNING:** Change this password after first login. This file should not be committed to version control.
255
- `;
256
- fs.writeFileSync(path.join(process.cwd(), "credentials.md"), content, "utf8");
257
- }
258
-
259
- /**
260
- * Seed the database with Super Admin user and Tenant Admin Role.
261
- *
262
- * @param {object} db - Database connection/query interface
263
- * @returns {Promise<void>}
264
- */
265
- async function seed(db) {
266
- const passwordHash = await hashPassword(SUPER_ADMIN_PASSWORD);
267
-
268
- // Insert Super Admin role with all permissions
269
- const superAdminRoleResult = await db("roles").insert({
270
- tenant_id: null,
271
- name: "Super Admin",
272
- created_at: new Date(),
273
- modified_at: new Date(),
274
- });
275
- const superAdminRoleId = Array.isArray(superAdminRoleResult)
276
- ? superAdminRoleResult[0]
277
- : superAdminRoleResult;
278
-
279
- // Insert Super Admin permissions
280
- for (const perm of SUPER_ADMIN_PERMISSIONS) {
281
- await db("role_permissions").insert({
282
- role_id: superAdminRoleId,
283
- permission: JSON.stringify(perm),
284
- created_at: new Date(),
285
- modified_at: new Date(),
286
- });
287
- }
288
-
289
- // Insert Super Admin user
290
- await db("users").insert({
291
- email: SUPER_ADMIN_EMAIL,
292
- password_hash: passwordHash,
293
- name: "Super Admin",
294
- tenant_id: null,
295
- role_id: superAdminRoleId,
296
- created_at: new Date(),
297
- modified_at: new Date(),
298
- });
299
-
300
- // Insert Tenant Admin Role
301
- const tenantAdminRoleResult = await db("roles").insert({
302
- tenant_id: null,
303
- name: "Tenant Admin",
304
- created_at: new Date(),
305
- modified_at: new Date(),
306
- });
307
- const tenantAdminRoleId = Array.isArray(tenantAdminRoleResult)
308
- ? tenantAdminRoleResult[0]
309
- : tenantAdminRoleResult;
310
-
311
- // Insert Tenant Admin permissions
312
- for (const perm of TENANT_ADMIN_PERMISSIONS) {
313
- await db("role_permissions").insert({
314
- role_id: tenantAdminRoleId,
315
- permission: JSON.stringify(perm),
316
- created_at: new Date(),
317
- modified_at: new Date(),
318
- });
319
- }
320
-
321
- // Write credentials file
322
- writeCredentials();
323
-
324
- console.log("SaaS seed completed successfully.");
325
- console.log("Super Admin:", SUPER_ADMIN_EMAIL);
326
- console.log("Credentials written to credentials.md");
327
- }
328
-
329
- module.exports = { seed, SUPER_ADMIN_PERMISSIONS, TENANT_ADMIN_PERMISSIONS, SUPER_ADMIN_EMAIL, SUPER_ADMIN_PASSWORD };