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.
- package/.codegraph/config.json +143 -0
- package/CLAUDE.md +150 -0
- package/dbmr.schema.json +3 -0
- package/docs/dbmr-schema-spec.md +597 -393
- package/package.json +1 -1
- package/skill/SKILL.md +1 -1
- package/skill/references/dbmr-schema-spec.md +597 -0
- package/src/cli/commands/generate.js +6 -6
- package/src/cli/diff-engine.js +4 -4
- package/src/cli/generate-migration.js +4 -0
- package/src/cli/generate-route.js +3 -3
- package/src/schema/schema-validator.js +1 -1
- package/.env +0 -7
- package/db-manager/.dbmanager.sqlite +0 -0
- package/db-manager/.dbmanager.sqlite-shm +0 -0
- package/db-manager/.dbmanager.sqlite-wal +0 -0
- package/db-manager/demo/cockroachdb.env +0 -6
- package/db-manager/demo/demo.sqlite +0 -0
- package/db-manager/demo/dynamodb.env +0 -7
- package/db-manager/demo/mongodb.env +0 -4
- package/db-manager/demo/mssql.env +0 -6
- package/db-manager/demo/mysql.env +0 -6
- package/db-manager/demo/oracle.env +0 -6
- package/db-manager/demo/postgres.env +0 -6
- package/db-manager/demo/redis.env +0 -4
- package/db-manager/demo/seeds/cockroachdb.sql +0 -32
- package/db-manager/demo/seeds/mssql.sql +0 -32
- package/db-manager/demo/seeds/mysql.sql +0 -32
- package/db-manager/demo/seeds/oracle.sql +0 -43
- package/db-manager/demo/seeds/postgres.sql +0 -32
- package/db-manager/demo/seeds/sqlite3.sql +0 -32
- package/db-manager/demo/sqlite3.env +0 -2
- package/demo/.dockerignore +0 -7
- package/demo/.env.example +0 -15
- package/demo/Dockerfile +0 -20
- package/demo/app.js +0 -39
- package/demo/commons/add_migration.js +0 -43
- package/demo/commons/db.js +0 -17
- package/demo/commons/migrate.js +0 -68
- package/demo/commons/modules.js +0 -18
- package/demo/commons/password.js +0 -36
- package/demo/commons/security.js +0 -30
- package/demo/commons/session.js +0 -13
- package/demo/commons/webhook.js +0 -81
- package/demo/dbmr.schema.json +0 -338
- package/demo/middleware/authenticate.js +0 -14
- package/demo/middleware/hasPermission.js +0 -30
- package/demo/middleware/logger.js +0 -67
- package/demo/middleware/tenantIsolation.js +0 -19
- package/demo/migrations/20260510193736_create_migrations_table.sql +0 -6
- package/demo/migrations/20260510193737_create_saas_tables.sql +0 -69
- package/demo/migrations/20260510193737_create_tables.sql +0 -193
- package/demo/models/addresses.js +0 -24
- package/demo/models/cart_items.js +0 -20
- package/demo/models/carts.js +0 -18
- package/demo/models/categories.js +0 -22
- package/demo/models/coupons.js +0 -25
- package/demo/models/index.js +0 -43
- package/demo/models/order_items.js +0 -23
- package/demo/models/orders.js +0 -27
- package/demo/models/payments.js +0 -23
- package/demo/models/product_images.js +0 -20
- package/demo/models/product_reviews.js +0 -22
- package/demo/models/product_variants.js +0 -22
- package/demo/models/products.js +0 -32
- package/demo/models/role_permissions.js +0 -17
- package/demo/models/roles.js +0 -17
- package/demo/models/shipments.js +0 -21
- package/demo/models/tenants.js +0 -18
- package/demo/models/users.js +0 -23
- package/demo/models/webhook_logs.js +0 -22
- package/demo/models/webhooks.js +0 -19
- package/demo/models/wishlists.js +0 -17
- package/demo/openapi.json +0 -7000
- package/demo/package-lock.json +0 -3972
- package/demo/package.json +0 -46
- package/demo/routes/addresses/index.js +0 -10
- package/demo/routes/auth/index.js +0 -55
- package/demo/routes/carts/cart_items/index.js +0 -11
- package/demo/routes/carts/index.js +0 -14
- package/demo/routes/categories/index.js +0 -10
- package/demo/routes/coupons/index.js +0 -10
- package/demo/routes/docs.js +0 -18
- package/demo/routes/health.js +0 -35
- package/demo/routes/index.js +0 -40
- package/demo/routes/orders/index.js +0 -18
- package/demo/routes/orders/order_items/index.js +0 -11
- package/demo/routes/orders/payments/index.js +0 -11
- package/demo/routes/orders/shipments/index.js +0 -11
- package/demo/routes/products/index.js +0 -18
- package/demo/routes/products/product_images/index.js +0 -11
- package/demo/routes/products/product_reviews/index.js +0 -11
- package/demo/routes/products/product_variants/index.js +0 -11
- package/demo/routes/roles/index.js +0 -75
- package/demo/routes/roles/permissions/index.js +0 -47
- package/demo/routes/tenants/index.js +0 -45
- package/demo/routes/users/index.js +0 -45
- package/demo/routes/wishlists/index.js +0 -10
- package/demo/seeds/saas-seed.js +0 -329
package/demo/seeds/saas-seed.js
DELETED
|
@@ -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 };
|