@getstrata/starter 3.0.8 → 3.1.1
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/README.md +10 -36
- package/dist/cli.js +795 -501
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -388,14 +388,22 @@ function compileStarterFeatures(input, reference) {
|
|
|
388
388
|
browserTransport: cookie ? "cookie" : layers.auth
|
|
389
389
|
});
|
|
390
390
|
const artifacts = [
|
|
391
|
+
"AGENTS.md",
|
|
391
392
|
"package.json",
|
|
392
393
|
"src/bootstrap/createApp.ts",
|
|
394
|
+
"src/routes/api.ts",
|
|
395
|
+
"src/routes/web.ts",
|
|
396
|
+
"src/routes/index.ts",
|
|
393
397
|
"src/models/Note.ts",
|
|
394
398
|
"src/models/register.ts",
|
|
395
399
|
"src/db/migrations/0001_starter_schema.ts"
|
|
396
400
|
];
|
|
397
401
|
if (decisions.users)
|
|
398
|
-
artifacts.push("src/models/User.ts", "src/models/AuthOneTimeToken.ts", "src/db/migrations/0006_account_state.ts");
|
|
402
|
+
artifacts.push("src/http/controllers/AuthController.ts", "src/http/auth/account.ts", "src/models/User.ts", "src/models/AuthOneTimeToken.ts", "src/db/migrations/0006_account_state.ts");
|
|
403
|
+
if (decisions.cookie)
|
|
404
|
+
artifacts.push("src/http/controllers/AuthWebController.ts");
|
|
405
|
+
if (decisions.serverViews)
|
|
406
|
+
artifacts.push("src/http/controllers/HomeController.ts");
|
|
399
407
|
if (decisions.token)
|
|
400
408
|
artifacts.push("src/models/ApiToken.ts");
|
|
401
409
|
if (decisions.frontendBuild)
|
|
@@ -407,13 +415,13 @@ function compileStarterFeatures(input, reference) {
|
|
|
407
415
|
if (decisions.htmlAuth && layers.extras.emailVerification)
|
|
408
416
|
artifacts.push("views/auth/verify-email.eta");
|
|
409
417
|
if (layers.extras.scim)
|
|
410
|
-
artifacts.push("src/
|
|
418
|
+
artifacts.push("src/http/controllers/ScimController.ts");
|
|
411
419
|
if (layers.extras.billing)
|
|
412
|
-
artifacts.push("src/billing/applyStripeWebhook.ts", "src/
|
|
420
|
+
artifacts.push("src/billing/applyStripeWebhook.ts", "src/http/controllers/BillingController.ts");
|
|
413
421
|
if (layers.extras.webhooks)
|
|
414
422
|
artifacts.push("src/jobs/dispatchOutboundWebhookJob.ts", "src/listeners/noteCreatedWebhookListener.ts");
|
|
415
423
|
if (decisions.workTracker)
|
|
416
|
-
artifacts.push("docs/WORK_TRACKER.md", "src/domain/workTracker.ts", "src/models/workTracker.ts", "src/
|
|
424
|
+
artifacts.push("docs/WORK_TRACKER.md", "src/domain/workTracker.ts", "src/models/workTracker.ts", "src/http/controllers/WorkTrackerController.ts", "src/http/requests/WorkRequest.ts", "src/db/migrations/0007_work_tracker.ts");
|
|
417
425
|
return Object.freeze({
|
|
418
426
|
version: 1,
|
|
419
427
|
...reference ? { reference } : {},
|
|
@@ -1390,18 +1398,189 @@ async function resolveStarterPlan(flags, injected) {
|
|
|
1390
1398
|
}
|
|
1391
1399
|
}
|
|
1392
1400
|
|
|
1401
|
+
// src/renderAgentInstructions.ts
|
|
1402
|
+
function renderAgentInstructions(projectName, plan) {
|
|
1403
|
+
const { layers, decisions, services } = plan;
|
|
1404
|
+
const extras = Object.entries(layers.extras).filter(([, enabled]) => enabled).map(([name]) => name).sort();
|
|
1405
|
+
return `# Building ${projectName}
|
|
1406
|
+
|
|
1407
|
+
This is an application built with Strata, TypeScript and Bun. Build product features
|
|
1408
|
+
in this app using the installed public APIs; do not recreate framework internals or
|
|
1409
|
+
edit node_modules. Follow Laravel-style organization where it fits TypeScript.
|
|
1410
|
+
|
|
1411
|
+
## Start here
|
|
1412
|
+
|
|
1413
|
+
Read README.md, package.json and the files involved in the feature. Installed package
|
|
1414
|
+
versions and current application code take precedence over generic examples. Runtime
|
|
1415
|
+
choices live in src/config/app.ts and environment configuration. strata.layers.json
|
|
1416
|
+
records generation choices; editing it does not reconfigure the application.
|
|
1417
|
+
Update this guide when the app's structure or stack changes. Do not print secrets
|
|
1418
|
+
from .env or commit credentials.
|
|
1419
|
+
|
|
1420
|
+
Starting stack: frontend=${layers.frontend}; database=${layers.database}; auth=${layers.auth};
|
|
1421
|
+
tenancy=${layers.tenancy}; cache=${layers.cache}; queue=${layers.queue}; mail=${layers.mail}.
|
|
1422
|
+
Selected extras: ${extras.join(", ") || "none"}.
|
|
1423
|
+
|
|
1424
|
+
## Where features belong
|
|
1425
|
+
|
|
1426
|
+
- src/routes/api.ts and src/routes/web.ts: endpoints and their middleware.
|
|
1427
|
+
- src/http/controllers/: named actions; create a controller when needed.
|
|
1428
|
+
- src/http/requests/: input validation and request authorization when needed.
|
|
1429
|
+
- src/policies/: resource access rules when needed.
|
|
1430
|
+
- src/models/: model classes; add new classes to src/models/register.ts.
|
|
1431
|
+
- src/db/migrations/: explicit schema changes, separate from model declarations.
|
|
1432
|
+
- src/config/app.ts and src/bootstrap/: configuration and dependency composition.
|
|
1433
|
+
${decisions.serverViews || decisions.mfaViews ? `- views/: Eta templates; use the existing view rendering and escaping helpers.
|
|
1434
|
+
` : ""}${decisions.frontendBuild ? `- frontend/: React UI built by Bun; preserve the configured SPA prefix (${layers.spaPrefix}).
|
|
1435
|
+
` : ""}
|
|
1436
|
+
Optional folders need not exist until their first feature is added. Larger domains
|
|
1437
|
+
may use modules; ordinary CRUD needs no module, forwarding service or repository layer.
|
|
1438
|
+
|
|
1439
|
+
## Add a feature
|
|
1440
|
+
|
|
1441
|
+
Use the local CLI from this directory; inspect each command's help before guessing flags:
|
|
1442
|
+
|
|
1443
|
+
\`\`\`sh
|
|
1444
|
+
bunx strata make:model Product
|
|
1445
|
+
bunx strata make:migration create_products
|
|
1446
|
+
bunx strata make:controller ProductController
|
|
1447
|
+
bunx strata make:request StoreProductRequest
|
|
1448
|
+
bunx strata make:policy ProductPolicy
|
|
1449
|
+
\`\`\`
|
|
1450
|
+
|
|
1451
|
+
1. Declare model fields once with defineModel and field from
|
|
1452
|
+
@getstrata/core/database/model. Infer row types with ModelAttributes when needed.
|
|
1453
|
+
Put relationships on the model class, for example
|
|
1454
|
+
category() { return this.belongsTo(Category, "category_id"); }.
|
|
1455
|
+
Register both model classes. Ordinary models need no separate XxxRepository.
|
|
1456
|
+
2. Implement a new migration for the actual table/columns/indexes. Model declarations
|
|
1457
|
+
do not change the database. Keep applied migrations intact.
|
|
1458
|
+
3. Validate input in a request and authorize the operation/resource. A fillable list
|
|
1459
|
+
is not authorization. Derive identity/ownership values from trusted context.
|
|
1460
|
+
4. Put application behavior in the controller or a service that adds real domain
|
|
1461
|
+
behavior. Register routes through the existing kernel/middleware composition.
|
|
1462
|
+
5. Query through database.model(Product), or transaction.model(Product) inside its
|
|
1463
|
+
transaction. Never cache a request session, identity or bound model in a singleton.
|
|
1464
|
+
Keep after-commit effects inside the existing transaction-aware workflow.
|
|
1465
|
+
6. Add focused tests for successful, denied and invalid operations. Check persisted
|
|
1466
|
+
outcomes and rollback when a feature changes data.
|
|
1467
|
+
|
|
1468
|
+
Use @getstrata/core/... and @getstrata/bootstrap/... public subpaths. Inspect installed
|
|
1469
|
+
types and neighboring app code before inventing an API. Pass narrow dependencies to
|
|
1470
|
+
controllers; do not pass the whole container. Prefer native Bun HTTP, SQL, streaming
|
|
1471
|
+
and image capabilities through Strata's APIs instead of adding duplicate frameworks.
|
|
1472
|
+
|
|
1473
|
+
## Access and the selected stack
|
|
1474
|
+
|
|
1475
|
+
${layers.auth === "headers" ? `Development header auth is selected. It is not a production login mechanism; adopt an appropriate real guard before exposing private data.
|
|
1476
|
+
` : `Keep the generated authentication and account-state checks. Authentication, abilities and resource policies are separate checks; do not bypass them in a new endpoint.
|
|
1477
|
+
`}${decisions.cookie ? `Preserve the existing cookie/CSRF handshake and server-side session handling. Do not store session credentials in browser storage or mint cookies in controllers.
|
|
1478
|
+
` : ""}${decisions.token || decisions.jwt ? `Preserve bearer-token/JWT verification and expiry. Do not persist bearer credentials in localStorage or sessionStorage, or treat unverified claims as identity.
|
|
1479
|
+
` : ""}${decisions.rls ? `PostgreSQL RLS is selected. Keep runtime access on the restricted app role and tenant policy inside the owned transaction; administrative migration credentials never belong in request handlers.
|
|
1480
|
+
` : decisions.tenantTable ? `Column tenancy is selected. Explicitly filter tenant-owned reads and writes using the trusted current tenant; a tenant_id column alone does not isolate records.
|
|
1481
|
+
` : `No tenancy is selected. Do not invent tenant fields or middleware without adding the corresponding schema and application policy.
|
|
1482
|
+
`}${layers.database === "sqlite" ? `SQLite is selected. Use its configured file and portable schema/query APIs; do not assume PostgreSQL RLS or full-text operators are available.
|
|
1483
|
+
` : ""}${decisions.redisQueue ? `Redis queued work needs a separate bun run queue:work process. Make job effects idempotent and preserve retry/cancellation semantics.
|
|
1484
|
+
` : `The queue is synchronous; HTTP startup does not create a background queue worker.
|
|
1485
|
+
`}Only run bun run outbox:work when this application uses SQL durable listeners.
|
|
1486
|
+
${layers.mail === "log" ? `Mail is logged locally; configure an actual mail transport before relying on delivered account emails.
|
|
1487
|
+
` : `SMTP is selected; use the configured transport and preserve failure/retry handling without logging credentials.
|
|
1488
|
+
`}
|
|
1489
|
+
## Commands and validation
|
|
1490
|
+
|
|
1491
|
+
Use the Bun version in .bun-version. Follow README.md for environment setup and
|
|
1492
|
+
${services.docker.length ? `selected Docker services (${services.docker.join(", ")}).` : services.local.length ? `local services (${services.local.join(", ")}).` : "local startup; this selection needs no supporting service containers."}
|
|
1493
|
+
|
|
1494
|
+
\`\`\`sh
|
|
1495
|
+
bun install
|
|
1496
|
+
bun run check
|
|
1497
|
+
bun run db:migrate
|
|
1498
|
+
bun run dev
|
|
1499
|
+
${decisions.frontendBuild ? `bun run frontend:install
|
|
1500
|
+
bun run frontend:build
|
|
1501
|
+
` : ""}\`\`\`
|
|
1502
|
+
|
|
1503
|
+
Run migrations against the intended development database after reviewing the changes.
|
|
1504
|
+
db:fresh is destructive; never use it on shared or production data. Demo seeds are
|
|
1505
|
+
development-only. Use disposable test data. Run existing focused tests with bun test
|
|
1506
|
+
when present; do not assume this app defines test, lint or framework-monorepo scripts.
|
|
1507
|
+
Inspect package.json for additional commands and add application tests where needed.
|
|
1508
|
+
|
|
1509
|
+
Keep changes small and inspect the diff. Avoid reading unrelated files or repeatedly
|
|
1510
|
+
running full suites. Recheck affected behavior after edits; report what ran and what
|
|
1511
|
+
remains unverified. Do not replace a failed check with a weaker assertion. Keep new
|
|
1512
|
+
dependencies, public APIs and infrastructure proportional to the product requirement.
|
|
1513
|
+
|
|
1514
|
+
## Framework reference
|
|
1515
|
+
|
|
1516
|
+
- [Application workflow](https://github.com/EyK-26/strata/blob/main/docs/BUILDING-APPS.md)
|
|
1517
|
+
- [Models and migrations](https://github.com/EyK-26/strata/blob/main/docs/DATABASE.md)
|
|
1518
|
+
- [Authentication](https://github.com/EyK-26/strata/blob/main/docs/AUTH.md)
|
|
1519
|
+
- [Tenancy](https://github.com/EyK-26/strata/blob/main/docs/TENANCY.md)
|
|
1520
|
+
- [Uploads and images](https://github.com/EyK-26/strata/blob/main/docs/MEDIA.md)
|
|
1521
|
+
|
|
1522
|
+
Documentation on main may be newer than the installed release. Keep this app's
|
|
1523
|
+
versions and public type contracts authoritative. Adding a feature should not require
|
|
1524
|
+
studying Strata's contributor workspace or changing framework package versions.
|
|
1525
|
+
`;
|
|
1526
|
+
}
|
|
1527
|
+
|
|
1528
|
+
// src/controllerActions.ts
|
|
1529
|
+
class ControllerActions {
|
|
1530
|
+
className;
|
|
1531
|
+
methods = new Map;
|
|
1532
|
+
constructor(className) {
|
|
1533
|
+
this.className = className;
|
|
1534
|
+
}
|
|
1535
|
+
add(name, handler) {
|
|
1536
|
+
if (this.methods.has(name))
|
|
1537
|
+
throw new Error(`Duplicate ${this.className}.${name}`);
|
|
1538
|
+
this.methods.set(name, handler);
|
|
1539
|
+
return `controller.${name}`;
|
|
1540
|
+
}
|
|
1541
|
+
render(construction = "", scope = []) {
|
|
1542
|
+
const methods = [...this.methods].map(([name, handler]) => {
|
|
1543
|
+
const arrow = handler.indexOf("=>");
|
|
1544
|
+
if (arrow < 0)
|
|
1545
|
+
throw new Error(`Missing arrow for ${this.className}.${name}`);
|
|
1546
|
+
const signature = handler.slice(0, arrow).trim();
|
|
1547
|
+
const body = handler.slice(arrow + 2).trim();
|
|
1548
|
+
const statements = body.startsWith("{") ? body.slice(1, -1) : `return ${body};`;
|
|
1549
|
+
const lines = statements.replace(/^\n/, "").replace(/\s+$/, "").split(`
|
|
1550
|
+
`);
|
|
1551
|
+
const indentation = Math.min(...lines.filter((line) => line.trim()).map((line) => line.match(/^\s*/)?.[0].length ?? 0));
|
|
1552
|
+
const formatted = lines.map((line) => line.trim() ? ` ${line.slice(indentation)}` : "").join(`
|
|
1553
|
+
`);
|
|
1554
|
+
return ` ${name}: BusinessRouteHandler = ${signature} => {${scope.length ? `
|
|
1555
|
+
const { ${scope.join(", ")} } = this;` : ""}
|
|
1556
|
+
${formatted}
|
|
1557
|
+
};`;
|
|
1558
|
+
});
|
|
1559
|
+
return `export class ${this.className} {
|
|
1560
|
+
${construction}
|
|
1561
|
+
${methods.join(`
|
|
1562
|
+
|
|
1563
|
+
`)}
|
|
1564
|
+
}
|
|
1565
|
+
`;
|
|
1566
|
+
}
|
|
1567
|
+
}
|
|
1568
|
+
function renderAction(actions, name, handler) {
|
|
1569
|
+
return actions ? actions.add(name, handler) : handler;
|
|
1570
|
+
}
|
|
1571
|
+
|
|
1393
1572
|
// src/auth/renderBrowserRoutes.ts
|
|
1394
|
-
function renderMfaChallengeRoutes() {
|
|
1573
|
+
function renderMfaChallengeRoutes(actions) {
|
|
1395
1574
|
return ` "/login/mfa": {
|
|
1396
|
-
GET: kernel.wrapWebGuest(kernel.wrapIdentity(async (request, _ports) => {
|
|
1575
|
+
GET: kernel.wrapWebGuest(kernel.wrapIdentity(${renderAction(actions, "showMfaChallenge", `async (request, _ports) => {
|
|
1397
1576
|
const pending = authServices.pendingMfa.read(request);
|
|
1398
1577
|
const record = pending ? await authServices.directory(_ports).findByIdOrThrow(pending.userId).catch(() => null) : null;
|
|
1399
1578
|
if (!record?.is_active || record.auth_version !== pending?.authVersion) return redirectTo("/login");
|
|
1400
1579
|
return views.render("mfa-challenge.eta", { layout: { title: "MFA" }, errors: {}, code: "" }, { request });
|
|
1401
|
-
})),
|
|
1580
|
+
}`)})),
|
|
1402
1581
|
POST: wrapWebLogin(
|
|
1403
1582
|
kernel,
|
|
1404
|
-
kernel.wrapIdentity(async (request, _ports) => {
|
|
1583
|
+
kernel.wrapIdentity(${renderAction(actions, "completeMfaChallenge", `async (request, _ports) => {
|
|
1405
1584
|
const pending = authServices.pendingMfa.read(request);
|
|
1406
1585
|
if (!pending) {
|
|
1407
1586
|
return redirectTo("/login");
|
|
@@ -1423,18 +1602,14 @@ function renderMfaChallengeRoutes() {
|
|
|
1423
1602
|
signed.headers.append("set-cookie", authServices.pendingMfa.clearCookie());
|
|
1424
1603
|
return signed;
|
|
1425
1604
|
});
|
|
1426
|
-
}),
|
|
1427
|
-
async (request) =>
|
|
1428
|
-
views.render("mfa-challenge.eta", { layout: { title: "MFA" }, errors: { code: "Too many login attempts. Try again shortly." }, code: "" }, { request, status: 429 }),
|
|
1605
|
+
}`)}),
|
|
1606
|
+
${renderAction(actions, "mfaChallengeThrottled", `async (request) =>
|
|
1607
|
+
views.render("mfa-challenge.eta", { layout: { title: "MFA" }, errors: { code: "Too many login attempts. Try again shortly." }, code: "" }, { request, status: 429 })`)},
|
|
1429
1608
|
),
|
|
1430
1609
|
},
|
|
1431
1610
|
`;
|
|
1432
1611
|
}
|
|
1433
|
-
function renderBrowserAuthRoutes({
|
|
1434
|
-
cookie,
|
|
1435
|
-
mfa,
|
|
1436
|
-
verify
|
|
1437
|
-
}) {
|
|
1612
|
+
function renderBrowserAuthRoutes({ cookie, mfa, verify }, actions) {
|
|
1438
1613
|
const mfaLoginBranch = `if (!mfaResult.ok) {
|
|
1439
1614
|
${mfa ? `if (mfaResult.error === "mfa_required") {
|
|
1440
1615
|
const pending = redirectTo("/login/mfa");
|
|
@@ -1452,17 +1627,21 @@ function renderBrowserAuthRoutes({
|
|
|
1452
1627
|
{ level: "success", message: "If that email is available, continue from the sign-in page." }, authServices.flash,
|
|
1453
1628
|
);`;
|
|
1454
1629
|
const cookieRoutes = cookie ? `
|
|
1455
|
-
|
|
1630
|
+
${actions ? `export function authWebRoutes(context: ModuleRouteContext): AppRouteMap {
|
|
1631
|
+
const { kernel, dependencies } = context;
|
|
1456
1632
|
const authServices = dependencies.container.resolve(STARTER_AUTH_SERVICES);
|
|
1457
1633
|
const views = dependencies.container.resolve(CORE_VIEW_RENDERER_TOKEN).namespace("auth", { headers: { "Cache-Control": "private, no-store" } });
|
|
1634
|
+
const controller = new AuthWebController(authServices, views);` : ` webRoutes({ kernel, dependencies }) {
|
|
1635
|
+
const authServices = dependencies.container.resolve(STARTER_AUTH_SERVICES);
|
|
1636
|
+
const views = dependencies.container.resolve(CORE_VIEW_RENDERER_TOKEN).namespace("auth", { headers: { "Cache-Control": "private, no-store" } });`}
|
|
1458
1637
|
return {
|
|
1459
1638
|
"/login": {
|
|
1460
|
-
GET: kernel.wrapWebGuest(async (request) =>
|
|
1461
|
-
views.render("login.eta", { layout: { title: "Sign in" }, errors: {}, email: "", password: "" }, { request }),
|
|
1639
|
+
GET: kernel.wrapWebGuest(${renderAction(actions, "showLogin", `async (request) =>
|
|
1640
|
+
views.render("login.eta", { layout: { title: "Sign in" }, errors: {}, email: "", password: "" }, { request })`)},
|
|
1462
1641
|
),
|
|
1463
1642
|
POST: wrapWebLogin(
|
|
1464
1643
|
kernel,
|
|
1465
|
-
kernel.wrapIdentity(async (request, _ports) => {
|
|
1644
|
+
kernel.wrapIdentity(${renderAction(actions, "login", `async (request, _ports) => {
|
|
1466
1645
|
const { fields } = await parseFormBody(request);
|
|
1467
1646
|
const { email, password, mfa_code } = parseLoginCredentials(fields);
|
|
1468
1647
|
return runWithLoginUser(_ports, email, async (candidate, _ports) => {
|
|
@@ -1471,21 +1650,21 @@ function renderBrowserAuthRoutes({
|
|
|
1471
1650
|
const user = mfaResult.user;
|
|
1472
1651
|
return authServices.session(_ports).signInRedirect(sessionUser(user), "/");
|
|
1473
1652
|
});
|
|
1474
|
-
}),
|
|
1475
|
-
async (request) =>
|
|
1476
|
-
views.render("login.eta", { layout: { title: "Sign in" }, errors: { email: "Too many login attempts. Try again shortly." }, email: "", password: "" }, { request, status: 429 }),
|
|
1653
|
+
}`)}),
|
|
1654
|
+
${renderAction(actions, "loginThrottled", `async (request) =>
|
|
1655
|
+
views.render("login.eta", { layout: { title: "Sign in" }, errors: { email: "Too many login attempts. Try again shortly." }, email: "", password: "" }, { request, status: 429 })`)},
|
|
1477
1656
|
),
|
|
1478
1657
|
},
|
|
1479
1658
|
"/register": {
|
|
1480
|
-
GET: kernel.wrapWebGuest(async (request, _ports) => {
|
|
1659
|
+
GET: kernel.wrapWebGuest(${renderAction(actions, "showRegistration", `async (request, _ports) => {
|
|
1481
1660
|
if (!authServices.config.registrationEnabled) {
|
|
1482
1661
|
return new Response("Not found", { status: 404 });
|
|
1483
1662
|
}
|
|
1484
1663
|
return views.render("register.eta", { layout: { title: "Create account" }, errors: {}, name: "", email: "", password: "" }, { request });
|
|
1485
|
-
}),
|
|
1664
|
+
}`)}),
|
|
1486
1665
|
POST: wrapWebRegister(
|
|
1487
1666
|
kernel,
|
|
1488
|
-
kernel.wrapIdentity(async (request, _ports) => {
|
|
1667
|
+
kernel.wrapIdentity(${renderAction(actions, "register", `async (request, _ports) => {
|
|
1489
1668
|
if (!authServices.config.registrationEnabled) {
|
|
1490
1669
|
return new Response("Not found", { status: 404 });
|
|
1491
1670
|
}
|
|
@@ -1501,16 +1680,16 @@ function renderBrowserAuthRoutes({
|
|
|
1501
1680
|
${verify ? `// SMTP follows the outermost commit, including request RLS.
|
|
1502
1681
|
if (verificationMail) await deferAuthEffect(_ports, () => authServices.mail.send(verificationMail));` : ""}
|
|
1503
1682
|
${verifyRegisterBranch}
|
|
1504
|
-
}),
|
|
1505
|
-
async (request) =>
|
|
1506
|
-
views.render("register.eta", { layout: { title: "Create account" }, errors: { form: "Too many registration attempts. Try again shortly." }, name: "", email: "", password: "" }, { request, status: 429 }),
|
|
1683
|
+
}`)}),
|
|
1684
|
+
${renderAction(actions, "registrationThrottled", `async (request) =>
|
|
1685
|
+
views.render("register.eta", { layout: { title: "Create account" }, errors: { form: "Too many registration attempts. Try again shortly." }, name: "", email: "", password: "" }, { request, status: 429 })`)},
|
|
1507
1686
|
),
|
|
1508
1687
|
},
|
|
1509
1688
|
"/forgot-password": {
|
|
1510
|
-
GET: kernel.wrapWebGuest(async (request) =>
|
|
1511
|
-
views.render("forgot-password.eta", { layout: { title: "Forgot password" }, errors: {}, email: "" }, { request }),
|
|
1689
|
+
GET: kernel.wrapWebGuest(${renderAction(actions, "showForgotPassword", `async (request) =>
|
|
1690
|
+
views.render("forgot-password.eta", { layout: { title: "Forgot password" }, errors: {}, email: "" }, { request })`)},
|
|
1512
1691
|
),
|
|
1513
|
-
POST: kernel.wrapWeb(kernel.wrapIdentity(async (request, _ports) => {
|
|
1692
|
+
POST: kernel.wrapWeb(kernel.wrapIdentity(${renderAction(actions, "forgotPassword", `async (request, _ports) => {
|
|
1514
1693
|
const { fields } = await parseFormBody(request);
|
|
1515
1694
|
const email = parseForgotPasswordEmail(fields);
|
|
1516
1695
|
const user = await authServices.directory(_ports).findByEmail?.(email);
|
|
@@ -1521,14 +1700,14 @@ function renderBrowserAuthRoutes({
|
|
|
1521
1700
|
level: "success",
|
|
1522
1701
|
message: "If that account exists, a reset link is on its way.",
|
|
1523
1702
|
}, authServices.flash);
|
|
1524
|
-
})),
|
|
1703
|
+
}`)})),
|
|
1525
1704
|
},
|
|
1526
1705
|
"/reset-password": {
|
|
1527
|
-
GET: kernel.wrapWeb(kernel.wrapSigned(async (request, _ports) => {
|
|
1706
|
+
GET: kernel.wrapWeb(kernel.wrapSigned(${renderAction(actions, "showResetPassword", `async (request, _ports) => {
|
|
1528
1707
|
const email = new URL(request.url).searchParams.get("email") ?? "";
|
|
1529
1708
|
return views.render("reset-password.eta", { layout: { title: "Reset password" }, errors: {}, password: "", email, action: \`\${new URL(request.url).pathname}\${new URL(request.url).search}\` }, { request });
|
|
1530
|
-
})),
|
|
1531
|
-
POST: kernel.wrapWeb(kernel.wrapSigned(kernel.wrapIdentity(async (request, _ports) => {
|
|
1709
|
+
}`)})),
|
|
1710
|
+
POST: kernel.wrapWeb(kernel.wrapSigned(kernel.wrapIdentity(${renderAction(actions, "resetPassword", `async (request, _ports) => {
|
|
1532
1711
|
const { fields } = await parseFormBody(request);
|
|
1533
1712
|
const email = new URL(request.url).searchParams.get("email") ?? fields.email ?? "";
|
|
1534
1713
|
const password = fields.password ?? "";
|
|
@@ -1536,13 +1715,13 @@ function renderBrowserAuthRoutes({
|
|
|
1536
1715
|
return views.render("reset-password.eta", { layout: { title: "Reset password" }, errors: { password: "Invalid or expired reset link." }, password: "", email, action: \`\${new URL(request.url).pathname}\${new URL(request.url).search}\` }, { request });
|
|
1537
1716
|
}
|
|
1538
1717
|
return flashResponse(redirectTo("/login"), { level: "success", message: "Password updated. Sign in." }, authServices.flash);
|
|
1539
|
-
}))),
|
|
1718
|
+
}`)}))),
|
|
1540
1719
|
},
|
|
1541
1720
|
"/logout": {
|
|
1542
|
-
POST: kernel.wrapWebAuthenticatedAllowUnverified(kernel.wrapIdentity(async (request, _ports) => { return authServices.session(_ports).signOutRedirect(request, "/"); })),
|
|
1721
|
+
POST: kernel.wrapWebAuthenticatedAllowUnverified(kernel.wrapIdentity(${renderAction(actions, "logout", `async (request, _ports) => { return authServices.session(_ports).signOutRedirect(request, "/"); }`)})),
|
|
1543
1722
|
},${verify ? `
|
|
1544
1723
|
"/email/verify": {
|
|
1545
|
-
GET: kernel.wrapWeb(kernel.wrapIdentity(async (request, _ports) => {
|
|
1724
|
+
GET: kernel.wrapWeb(kernel.wrapIdentity(${renderAction(actions, "verifyEmail", `async (request, _ports) => {
|
|
1546
1725
|
const url = new URL(request.url);
|
|
1547
1726
|
if (url.searchParams.get("signature")) {
|
|
1548
1727
|
assertValidSignature(request, authServices.config.signatureSecret);
|
|
@@ -1558,23 +1737,23 @@ function renderBrowserAuthRoutes({
|
|
|
1558
1737
|
);
|
|
1559
1738
|
}
|
|
1560
1739
|
return views.render("verify-email.eta", { layout: { title: "Verify email" } }, { request });
|
|
1561
|
-
})),
|
|
1740
|
+
}`)})),
|
|
1562
1741
|
},
|
|
1563
1742
|
"/email/verification-notification": {
|
|
1564
|
-
POST: kernel.wrapWebAuthenticatedAllowUnverified(kernel.wrapIdentity(async (request, _ports) => {
|
|
1743
|
+
POST: kernel.wrapWebAuthenticatedAllowUnverified(kernel.wrapIdentity(${renderAction(actions, "sendVerification", `async (request, _ports) => {
|
|
1565
1744
|
const user = await _ports.auth.user(request);
|
|
1566
1745
|
if (user) {
|
|
1567
1746
|
const record = await authServices.directory(_ports).findByIdOrThrow(Number(user.id));
|
|
1568
1747
|
await issueSignedAuthMail(_ports, authServices, record.email ?? "", "Verify your email", "/email/verify", AUTH_ONE_TIME_PURPOSES.emailVerify, Number(record.id), { id: String(record.id) });
|
|
1569
1748
|
}
|
|
1570
1749
|
return flashResponse(redirectTo("/email/verify"), { level: "info", message: "Verification link sent." }, authServices.flash);
|
|
1571
|
-
})),
|
|
1750
|
+
}`)})),
|
|
1572
1751
|
},` : ""}${mfa ? `
|
|
1573
|
-
${renderMfaChallengeRoutes()} "/confirm-password": {
|
|
1574
|
-
GET: kernel.wrapWebAuthenticated(async (request) =>
|
|
1575
|
-
views.render("confirm-password.eta", { layout: { title: "Confirm password" }, errors: {}, password: "" }, { request }),
|
|
1752
|
+
${renderMfaChallengeRoutes(actions)} "/confirm-password": {
|
|
1753
|
+
GET: kernel.wrapWebAuthenticated(${renderAction(actions, "showPasswordConfirmation", `async (request) =>
|
|
1754
|
+
views.render("confirm-password.eta", { layout: { title: "Confirm password" }, errors: {}, password: "" }, { request })`)},
|
|
1576
1755
|
),
|
|
1577
|
-
POST: kernel.wrapWebAuthenticated(kernel.wrapIdentity(async (request, _ports) => {
|
|
1756
|
+
POST: kernel.wrapWebAuthenticated(kernel.wrapIdentity(${renderAction(actions, "confirmPassword", `async (request, _ports) => {
|
|
1578
1757
|
const user = await _ports.auth.user(request);
|
|
1579
1758
|
if (!user) {
|
|
1580
1759
|
return redirectTo("/login");
|
|
@@ -1591,10 +1770,10 @@ ${renderMfaChallengeRoutes()} "/confirm-password": {
|
|
|
1591
1770
|
confirmed.headers.append("set-cookie", createPasswordConfirmCookie(Number(user.id), record.auth_version, authServices.config.passwordConfirmation));
|
|
1592
1771
|
return confirmed;
|
|
1593
1772
|
});
|
|
1594
|
-
})),
|
|
1773
|
+
}`)})),
|
|
1595
1774
|
},
|
|
1596
1775
|
"/account/mfa": {
|
|
1597
|
-
GET: kernel.wrapWebAuthenticated(kernel.wrapIdentity(async (request, _ports) => {
|
|
1776
|
+
GET: kernel.wrapWebAuthenticated(kernel.wrapIdentity(${renderAction(actions, "showMfaSetup", `async (request, _ports) => {
|
|
1598
1777
|
const secret = generateTotpSecret();
|
|
1599
1778
|
const user = await _ports.auth.user(request);
|
|
1600
1779
|
const record = user ? await authServices.directory(_ports).findByIdOrThrow(Number(user.id)) : null;
|
|
@@ -1604,8 +1783,8 @@ ${renderMfaChallengeRoutes()} "/confirm-password": {
|
|
|
1604
1783
|
issuer: authServices.config.appName,
|
|
1605
1784
|
});
|
|
1606
1785
|
return views.render("mfa-setup.eta", { layout: { title: "MFA" }, errors: {}, code: "", secret, otpauth }, { request });
|
|
1607
|
-
})),
|
|
1608
|
-
POST: kernel.wrapWebPasswordConfirm(kernel.wrapIdentity(async (request, _ports) => {
|
|
1786
|
+
}`)})),
|
|
1787
|
+
POST: kernel.wrapWebPasswordConfirm(kernel.wrapIdentity(${renderAction(actions, "enrollMfa", `async (request, _ports) => {
|
|
1609
1788
|
const user = await _ports.auth.user(request);
|
|
1610
1789
|
if (!user) {
|
|
1611
1790
|
return redirectTo("/login");
|
|
@@ -1631,10 +1810,10 @@ ${renderMfaChallengeRoutes()} "/confirm-password": {
|
|
|
1631
1810
|
otpauth: buildOtpauthUrl({ secret, account: "user", issuer: authServices.config.appName }),
|
|
1632
1811
|
recoveryCodes,
|
|
1633
1812
|
}, { request });
|
|
1634
|
-
})),
|
|
1813
|
+
}`)})),
|
|
1635
1814
|
},` : ""}
|
|
1636
1815
|
};
|
|
1637
|
-
}
|
|
1816
|
+
}${actions ? "" : ","}` : "";
|
|
1638
1817
|
return cookieRoutes;
|
|
1639
1818
|
}
|
|
1640
1819
|
|
|
@@ -1649,15 +1828,15 @@ function renderApiAuthRoutes({
|
|
|
1649
1828
|
bearerApi,
|
|
1650
1829
|
jsonCookieAccounts,
|
|
1651
1830
|
jsonAccounts
|
|
1652
|
-
}) {
|
|
1831
|
+
}, actions) {
|
|
1653
1832
|
const browserMfa = plan.decisions.mfaViews;
|
|
1654
1833
|
const mfaContinuation = browserMfa ? `
|
|
1655
1834
|
...kernel.wrapRouteMap({
|
|
1656
|
-
${renderMfaChallengeRoutes()}
|
|
1835
|
+
${renderMfaChallengeRoutes(actions)}
|
|
1657
1836
|
}, kernel.group("api")),` : "";
|
|
1658
1837
|
const tokenLogin = plan.decisions.token ? `
|
|
1659
1838
|
"/api/v1/auth/login": {
|
|
1660
|
-
POST: kernel.wrap("api", kernel.wrapLogin(kernel.wrapIdentity(async (request, _ports) => {
|
|
1839
|
+
POST: kernel.wrap("api", kernel.wrapLogin(kernel.wrapIdentity(${renderAction(actions, "loginWithToken", `async (request, _ports) => {
|
|
1661
1840
|
const { email, password, mfa_code } = await parseJsonBody(request, parseLoginCredentials);
|
|
1662
1841
|
return runWithLoginUser(_ports, email, async (candidate, _ports) => {
|
|
1663
1842
|
const mfaResult = await authenticatePasswordUser(_ports, authServices, candidate, password, mfa_code);
|
|
@@ -1690,10 +1869,10 @@ ${renderMfaChallengeRoutes()}
|
|
|
1690
1869
|
payload.headers.append("set-cookie", setCookie);
|
|
1691
1870
|
` : ""}return payload;
|
|
1692
1871
|
});
|
|
1693
|
-
}))),
|
|
1872
|
+
}`)}))),
|
|
1694
1873
|
},
|
|
1695
1874
|
"/api/v1/auth/me": {
|
|
1696
|
-
GET: kernel.wrapApi(kernel.wrapIdentity(async (request, _ports) => {
|
|
1875
|
+
GET: kernel.wrapApi(kernel.wrapIdentity(${renderAction(actions, "showTokenUser", `async (request, _ports) => {
|
|
1697
1876
|
const user = await _ports.auth.requireUser(request);
|
|
1698
1877
|
const record = await authServices.directory(_ports).findByIdOrThrow(Number(user.id));
|
|
1699
1878
|
return privateJsonResponse({
|
|
@@ -1702,11 +1881,11 @@ ${renderMfaChallengeRoutes()}
|
|
|
1702
1881
|
email: record.email,
|
|
1703
1882
|
role: record.role,
|
|
1704
1883
|
});
|
|
1705
|
-
})),
|
|
1884
|
+
}`)})),
|
|
1706
1885
|
},` : "";
|
|
1707
1886
|
const jsonRegister = jsonAccounts ? `
|
|
1708
1887
|
"/api/v1/auth/register": {
|
|
1709
|
-
POST: kernel.wrap("api", kernel.wrapRegister(kernel.wrapIdentity(async (request, _ports) => {
|
|
1888
|
+
POST: kernel.wrap("api", kernel.wrapRegister(kernel.wrapIdentity(${renderAction(actions, "register", `async (request, _ports) => {
|
|
1710
1889
|
if (!authServices.config.registrationEnabled) {
|
|
1711
1890
|
return privateJsonResponse({ error: "Not found" }, { status: 404 });
|
|
1712
1891
|
}
|
|
@@ -1721,11 +1900,11 @@ ${renderMfaChallengeRoutes()}
|
|
|
1721
1900
|
${verify ? `// SMTP follows the outermost commit, including request RLS.
|
|
1722
1901
|
if (verificationMail) await deferAuthEffect(_ports, () => authServices.mail.send(verificationMail));` : ""}
|
|
1723
1902
|
return privateJsonResponse({ ok: true }, { status: 201 });
|
|
1724
|
-
}))),
|
|
1903
|
+
}`)}))),
|
|
1725
1904
|
},` : "";
|
|
1726
1905
|
const jwtLogin = plan.decisions.jwt ? `
|
|
1727
1906
|
"/api/auth/token": {
|
|
1728
|
-
POST: kernel.wrap("api", kernel.wrapLogin(kernel.wrapIdentity(async (request, _ports) => {
|
|
1907
|
+
POST: kernel.wrap("api", kernel.wrapLogin(kernel.wrapIdentity(${renderAction(actions, "loginWithJwt", `async (request, _ports) => {
|
|
1729
1908
|
const { email, password, mfa_code } = await parseJsonBody(request, parseLoginCredentials);
|
|
1730
1909
|
return runWithLoginUser(_ports, email, async (candidate, _ports) => {
|
|
1731
1910
|
const mfaResult = await authenticatePasswordUser(_ports, authServices, candidate, password, mfa_code);
|
|
@@ -1750,67 +1929,67 @@ ${renderMfaChallengeRoutes()}
|
|
|
1750
1929
|
expires_in: authServices.config.jwtTtlSeconds,
|
|
1751
1930
|
});
|
|
1752
1931
|
});
|
|
1753
|
-
}))),
|
|
1932
|
+
}`)}))),
|
|
1754
1933
|
},` : "";
|
|
1755
1934
|
const apiUser = bearerApi ? `
|
|
1756
1935
|
"/api/user": {
|
|
1757
|
-
GET: kernel.wrapApi(async (request, _ports) => {
|
|
1936
|
+
GET: kernel.wrapApi(${renderAction(actions, "showUser", `async (request, _ports) => {
|
|
1758
1937
|
const user = await _ports.auth.requireUser(request);
|
|
1759
1938
|
return privateJsonResponse({ id: user.id, role: user.role ?? "member" });
|
|
1760
|
-
}),
|
|
1939
|
+
}`)}),
|
|
1761
1940
|
},
|
|
1762
1941
|
"/api/v1/auth/logout": {
|
|
1763
|
-
POST: kernel.wrap("api", ${cookie ? "kernel.wrapIdentity(" : ""}async (request, _ports) => {
|
|
1942
|
+
POST: kernel.wrap("api", ${cookie ? "kernel.wrapIdentity(" : ""}${renderAction(actions, "logoutBearer", `async (request, _ports) => {
|
|
1764
1943
|
const payload = privateJsonResponse({ ok: true });
|
|
1765
1944
|
${cookie ? `const sessionAuth = authServices.session(_ports);
|
|
1766
1945
|
const { setCookie } = await sessionAuth.signOut(request);
|
|
1767
1946
|
payload.headers.append("set-cookie", setCookie);
|
|
1768
1947
|
` : ""}return payload;
|
|
1769
|
-
}${cookie ? ")" : ""}),
|
|
1948
|
+
}`)}${cookie ? ")" : ""}),
|
|
1770
1949
|
},` : "";
|
|
1771
1950
|
const jsonPassword = jsonAccounts ? `
|
|
1772
1951
|
"/api/v1/auth/forgot-password": {
|
|
1773
|
-
POST: kernel.wrap("api", kernel.wrapIdentity(async (request, _ports) => {
|
|
1952
|
+
POST: kernel.wrap("api", kernel.wrapIdentity(${renderAction(actions, "forgotPassword", `async (request, _ports) => {
|
|
1774
1953
|
const email = await parseJsonBody(request, parseForgotPasswordEmail);
|
|
1775
1954
|
const user = await authServices.directory(_ports).findByEmail?.(email);
|
|
1776
1955
|
if (user) {
|
|
1777
1956
|
await issueSignedAuthMail(_ports, authServices, email, "Reset your password", "/api/v1/auth/reset-password", AUTH_ONE_TIME_PURPOSES.passwordReset, user.id, { email });
|
|
1778
1957
|
}
|
|
1779
1958
|
return privateJsonResponse({ ok: true });
|
|
1780
|
-
})),
|
|
1959
|
+
}`)})),
|
|
1781
1960
|
},
|
|
1782
1961
|
"/api/v1/auth/reset-password": {
|
|
1783
|
-
POST: kernel.wrap("api", kernel.wrapSigned(kernel.wrapIdentity(async (request, _ports) => {
|
|
1962
|
+
POST: kernel.wrap("api", kernel.wrapSigned(kernel.wrapIdentity(${renderAction(actions, "resetPassword", `async (request, _ports) => {
|
|
1784
1963
|
const body = await parseJsonBody(request, (payload) => payload);
|
|
1785
1964
|
const password = typeof body === "object" && body !== null && "password" in body ? body.password : undefined;
|
|
1786
1965
|
if (!(await completeSignedPasswordReset(_ports, request, password))) {
|
|
1787
1966
|
return privateJsonResponse({ error: "Invalid or expired reset link." }, { status: 403 });
|
|
1788
1967
|
}
|
|
1789
1968
|
return privateJsonResponse({ ok: true });
|
|
1790
|
-
}))),
|
|
1969
|
+
}`)}))),
|
|
1791
1970
|
},` : "";
|
|
1792
1971
|
const jsonVerify = plan.decisions.jsonVerification ? `
|
|
1793
1972
|
"/api/v1/auth/verify-email": {
|
|
1794
|
-
POST: kernel.wrap("api", kernel.wrapSigned(kernel.wrapIdentity(async (request, _ports) => {
|
|
1973
|
+
POST: kernel.wrap("api", kernel.wrapSigned(kernel.wrapIdentity(${renderAction(actions, "verifyEmail", `async (request, _ports) => {
|
|
1795
1974
|
if (!(await completeSignedEmailVerification(_ports, request))) {
|
|
1796
1975
|
return privateJsonResponse({ error: "Invalid or expired verification link." }, { status: 403 });
|
|
1797
1976
|
}
|
|
1798
1977
|
return privateJsonResponse({ ok: true });
|
|
1799
|
-
}))),
|
|
1978
|
+
}`)}))),
|
|
1800
1979
|
},` : "";
|
|
1801
1980
|
const jsonAccountManagement = jsonCookieAccounts ? `
|
|
1802
1981
|
${verify ? `"/api/v1/auth/verification-notification": {
|
|
1803
|
-
POST: kernel.wrapApi(kernel.wrapIdentity(async (request, _ports) => {
|
|
1982
|
+
POST: kernel.wrapApi(kernel.wrapIdentity(${renderAction(actions, "sendVerification", `async (request, _ports) => {
|
|
1804
1983
|
const user = await _ports.auth.requireUser(request);
|
|
1805
1984
|
await runWithLockedAccount(_ports, Number(user.id), async (record, _ports) => {
|
|
1806
1985
|
if (!record?.is_active || record.auth_version !== user.authVersion) throw new ConflictError("Account changed. Sign in again.");
|
|
1807
1986
|
if (!record.email_verified_at) await issueSignedAuthMail(_ports, authServices, record.email ?? "", "Verify your email", "/api/v1/auth/verify-email", AUTH_ONE_TIME_PURPOSES.emailVerify, record.id, { id: String(record.id) });
|
|
1808
1987
|
});
|
|
1809
1988
|
return privateJsonResponse({ ok: true });
|
|
1810
|
-
})),
|
|
1989
|
+
}`)})),
|
|
1811
1990
|
},` : ""}
|
|
1812
1991
|
${mfa ? `"/api/v1/auth/confirm-password": {
|
|
1813
|
-
POST: kernel.wrap("api", kernel.wrapVerified(kernel.wrapIdentity(async (request, _ports) => {
|
|
1992
|
+
POST: kernel.wrap("api", kernel.wrapVerified(kernel.wrapIdentity(${renderAction(actions, "confirmPassword", `async (request, _ports) => {
|
|
1814
1993
|
const user = await _ports.auth.requireUser(request);
|
|
1815
1994
|
const { password } = await parseJsonBody(request, (payload) => validateObject(payload, { password: [required(), stringRule()] }));
|
|
1816
1995
|
return runWithLockedAccount(_ports, Number(user.id), async (record, _ports) => {
|
|
@@ -1820,33 +1999,33 @@ ${renderMfaChallengeRoutes()}
|
|
|
1820
1999
|
response.headers.append("set-cookie", createPasswordConfirmCookie(Number(user.id), record.auth_version, authServices.config.passwordConfirmation));
|
|
1821
2000
|
return response;
|
|
1822
2001
|
});
|
|
1823
|
-
}))),
|
|
2002
|
+
}`)}))),
|
|
1824
2003
|
},
|
|
1825
2004
|
"/api/v1/auth/mfa": {
|
|
1826
|
-
GET: kernel.wrap("api", kernel.wrapVerified(kernel.wrapIdentity(async (request, _ports) => {
|
|
2005
|
+
GET: kernel.wrap("api", kernel.wrapVerified(kernel.wrapIdentity(${renderAction(actions, "showMfaSetup", `async (request, _ports) => {
|
|
1827
2006
|
const user = await _ports.auth.requireUser(request);
|
|
1828
2007
|
const record = await authServices.directory(_ports).findByIdOrThrow(Number(user.id));
|
|
1829
2008
|
const secret = generateTotpSecret();
|
|
1830
2009
|
return privateJsonResponse({ secret, otpauth: buildOtpauthUrl({ secret, account: record.email ?? "user", issuer: authServices.config.appName }) });
|
|
1831
|
-
}))),
|
|
1832
|
-
POST: kernel.wrap("api", kernel.wrapVerified(kernel.wrapPasswordConfirm(kernel.wrapIdentity(async (request, _ports) => {
|
|
2010
|
+
}`)}))),
|
|
2011
|
+
POST: kernel.wrap("api", kernel.wrapVerified(kernel.wrapPasswordConfirm(kernel.wrapIdentity(${renderAction(actions, "enrollMfa", `async (request, _ports) => {
|
|
1833
2012
|
const user = await _ports.auth.requireUser(request);
|
|
1834
2013
|
const fields = await parseJsonBody(request, (payload) => validateObject(payload, { secret: [required(), stringRule()], code: [required(), stringRule()] }));
|
|
1835
2014
|
const secret = String(fields.secret).trim();
|
|
1836
2015
|
if (!verifyTotp(secret, String(fields.code).trim())) return privateJsonResponse({ error: "Could not confirm that code." }, { status: 422 });
|
|
1837
2016
|
const recoveryCodes = await enrollMfa(_ports, authServices, user, secret);
|
|
1838
2017
|
return privateJsonResponse({ recoveryCodes });
|
|
1839
|
-
})))),
|
|
2018
|
+
}`)})))),
|
|
1840
2019
|
},` : ""}` : "";
|
|
1841
2020
|
const csrfRoute = `
|
|
1842
2021
|
"/api/v1/auth/csrf": {
|
|
1843
|
-
GET: kernel.wrap("api", async (request, _ports) => {
|
|
2022
|
+
GET: kernel.wrap("api", ${renderAction(actions, "csrf", `async (request, _ports) => {
|
|
1844
2023
|
return privateJsonResponse({ token: resolveCsrfTokenForRequest(request, authServices.csrf) });
|
|
1845
|
-
}),
|
|
2024
|
+
}`)}),
|
|
1846
2025
|
},`;
|
|
1847
2026
|
const cookieJsonAuth = plan.decisions.cookieJsonLogin ? `
|
|
1848
2027
|
"/api/v1/auth/login": {
|
|
1849
|
-
POST: kernel.wrap("api", kernel.wrapLogin(kernel.wrapIdentity(async (request, _ports) => {
|
|
2028
|
+
POST: kernel.wrap("api", kernel.wrapLogin(kernel.wrapIdentity(${renderAction(actions, "loginWithCookie", `async (request, _ports) => {
|
|
1850
2029
|
const { email, password, mfa_code } = await parseJsonBody(request, parseLoginCredentials);
|
|
1851
2030
|
return runWithLoginUser(_ports, email, async (candidate, _ports) => {
|
|
1852
2031
|
const mfaResult = await authenticatePasswordUser(_ports, authServices, candidate, password, mfa_code);
|
|
@@ -1863,10 +2042,10 @@ ${renderMfaChallengeRoutes()}
|
|
|
1863
2042
|
payload.headers.append("set-cookie", setCookie);
|
|
1864
2043
|
return payload;
|
|
1865
2044
|
});
|
|
1866
|
-
}))),
|
|
2045
|
+
}`)}))),
|
|
1867
2046
|
},
|
|
1868
2047
|
"/api/v1/auth/me": {
|
|
1869
|
-
GET: kernel.wrapApi(kernel.wrapIdentity(async (request, _ports) => {
|
|
2048
|
+
GET: kernel.wrapApi(kernel.wrapIdentity(${renderAction(actions, "showCookieUser", `async (request, _ports) => {
|
|
1870
2049
|
const user = await _ports.auth.requireUser(request);
|
|
1871
2050
|
const record = await authServices.directory(_ports).findByIdOrThrow(Number(user.id));
|
|
1872
2051
|
return privateJsonResponse({
|
|
@@ -1875,30 +2054,30 @@ ${renderMfaChallengeRoutes()}
|
|
|
1875
2054
|
email: record.email,
|
|
1876
2055
|
role: record.role,
|
|
1877
2056
|
});
|
|
1878
|
-
})),
|
|
2057
|
+
}`)})),
|
|
1879
2058
|
},
|
|
1880
2059
|
"/api/v1/auth/logout": {
|
|
1881
|
-
POST: kernel.wrap("api", kernel.wrapIdentity(async (request, _ports) => {
|
|
2060
|
+
POST: kernel.wrap("api", kernel.wrapIdentity(${renderAction(actions, "logoutCookie", `async (request, _ports) => {
|
|
1882
2061
|
const sessionAuth = authServices.session(_ports);
|
|
1883
2062
|
const { setCookie } = await sessionAuth.signOut(request);
|
|
1884
2063
|
const payload = privateJsonResponse({ ok: true });
|
|
1885
2064
|
payload.headers.append("set-cookie", setCookie);
|
|
1886
2065
|
return payload;
|
|
1887
|
-
})),
|
|
2066
|
+
}`)})),
|
|
1888
2067
|
},` : "";
|
|
1889
2068
|
const samlRoutes = cookie ? `
|
|
1890
2069
|
"/auth/saml": {
|
|
1891
|
-
GET: kernel.wrap("api", async (_request, _ports) => {
|
|
2070
|
+
GET: kernel.wrap("api", ${renderAction(actions, "startSaml", `async (_request, _ports) => {
|
|
1892
2071
|
if (!authServices.config.samlEnabled) {
|
|
1893
2072
|
return new Response("Not found", { status: 404 });
|
|
1894
2073
|
}
|
|
1895
2074
|
const issued = createSamlStateCookie(authServices.config.oauth);
|
|
1896
2075
|
const url = await authServices.saml(_ports).authorizationUrl(issued.state);
|
|
1897
2076
|
return new Response(null, { status: 302, headers: { location: url, "set-cookie": issued.cookie } });
|
|
1898
|
-
}),
|
|
2077
|
+
}`)}),
|
|
1899
2078
|
},
|
|
1900
2079
|
"/auth/saml/acs": {
|
|
1901
|
-
POST: kernel.wrap("api", kernel.wrapIdentity(async (request, _ports) => {
|
|
2080
|
+
POST: kernel.wrap("api", kernel.wrapIdentity(${renderAction(actions, "completeSaml", `async (request, _ports) => {
|
|
1902
2081
|
if (!authServices.config.samlEnabled) {
|
|
1903
2082
|
return new Response("Not found", { status: 404 });
|
|
1904
2083
|
}
|
|
@@ -1921,11 +2100,11 @@ ${renderMfaChallengeRoutes()}
|
|
|
1921
2100
|
const login = await completeBrowserSsoLogin(_ports, authServices, profile, "SAML");
|
|
1922
2101
|
login.headers.append("set-cookie", clearSamlStateCookie());
|
|
1923
2102
|
return login;
|
|
1924
|
-
})),
|
|
2103
|
+
}`)})),
|
|
1925
2104
|
},` : "";
|
|
1926
2105
|
const githubRoutes = github ? `
|
|
1927
2106
|
"/auth/github": {
|
|
1928
|
-
GET: kernel.wrap("api", async (_request, _ports) => {
|
|
2107
|
+
GET: kernel.wrap("api", ${renderAction(actions, "startGitHub", `async (_request, _ports) => {
|
|
1929
2108
|
if (!authServices.config.oauthEnabled) {
|
|
1930
2109
|
return new Response("Not found", { status: 404 });
|
|
1931
2110
|
}
|
|
@@ -1938,10 +2117,10 @@ ${renderMfaChallengeRoutes()}
|
|
|
1938
2117
|
const issued = createOAuthStateCookie(authServices.config.oauth);
|
|
1939
2118
|
const url = new GitHubOAuthProvider({ clientId, clientSecret, redirectUri, production: authServices.config.github.production, userAgent: authServices.config.github.userAgent }).getAuthorizationUrl(issued.state);
|
|
1940
2119
|
return new Response(null, { status: 302, headers: { location: url, "set-cookie": issued.cookie } });
|
|
1941
|
-
}),
|
|
2120
|
+
}`)}),
|
|
1942
2121
|
},
|
|
1943
2122
|
"/auth/github/callback": {
|
|
1944
|
-
GET: kernel.wrap("api", kernel.wrapIdentity(async (request, _ports) => {
|
|
2123
|
+
GET: kernel.wrap("api", kernel.wrapIdentity(${renderAction(actions, "completeGitHub", `async (request, _ports) => {
|
|
1945
2124
|
if (!authServices.config.oauthEnabled) {
|
|
1946
2125
|
return new Response("Not found", { status: 404 });
|
|
1947
2126
|
}
|
|
@@ -1970,11 +2149,11 @@ ${renderMfaChallengeRoutes()}
|
|
|
1970
2149
|
const login = await completeBrowserSsoLogin(_ports, authServices, profile, "GitHub");
|
|
1971
2150
|
login.headers.append("set-cookie", clearOAuthStateCookie(authServices.config.oauth));
|
|
1972
2151
|
return login;
|
|
1973
|
-
})),
|
|
2152
|
+
}`)})),
|
|
1974
2153
|
},` : "";
|
|
1975
2154
|
const oidcRoutes = oidc ? `
|
|
1976
2155
|
"/auth/oidc": {
|
|
1977
|
-
GET: kernel.wrap("api", async (_request, _ports) => {
|
|
2156
|
+
GET: kernel.wrap("api", ${renderAction(actions, "startOidc", `async (_request, _ports) => {
|
|
1978
2157
|
if (!authServices.config.oauthEnabled) {
|
|
1979
2158
|
return new Response("Not found", { status: 404 });
|
|
1980
2159
|
}
|
|
@@ -1994,10 +2173,10 @@ ${renderMfaChallengeRoutes()}
|
|
|
1994
2173
|
sealOidcPkceCookie({ state: issued.state, nonce: handshake.nonce, codeVerifier: handshake.codeVerifier }, authServices.config.oauth),
|
|
1995
2174
|
);
|
|
1996
2175
|
return redirect;
|
|
1997
|
-
}),
|
|
2176
|
+
}`)}),
|
|
1998
2177
|
},
|
|
1999
2178
|
"/auth/oidc/callback": {
|
|
2000
|
-
GET: kernel.wrap("api", kernel.wrapIdentity(async (request, _ports) => {
|
|
2179
|
+
GET: kernel.wrap("api", kernel.wrapIdentity(${renderAction(actions, "completeOidc", `async (request, _ports) => {
|
|
2001
2180
|
if (!authServices.config.oauthEnabled) {
|
|
2002
2181
|
return new Response("Not found", { status: 404 });
|
|
2003
2182
|
}
|
|
@@ -2028,16 +2207,20 @@ ${renderMfaChallengeRoutes()}
|
|
|
2028
2207
|
const login = await completeBrowserSsoLogin(_ports, authServices, profile, "OIDC");
|
|
2029
2208
|
login.headers.append("set-cookie", clearOidcPkceCookie(authServices.config.oauth));
|
|
2030
2209
|
return login;
|
|
2031
|
-
})),
|
|
2210
|
+
}`)})),
|
|
2032
2211
|
},` : "";
|
|
2033
2212
|
const apiRoutes = plan.decisions.users ? `
|
|
2034
|
-
|
|
2213
|
+
${actions ? `export function authApiRoutes(context: ModuleRouteContext): AppRouteMap {
|
|
2214
|
+
const { kernel, dependencies } = context;
|
|
2035
2215
|
const authServices = dependencies.container.resolve(STARTER_AUTH_SERVICES);${browserMfa ? `
|
|
2216
|
+
const views = dependencies.container.resolve(CORE_VIEW_RENDERER_TOKEN).namespace("auth", { headers: { "Cache-Control": "private, no-store" } });` : ""}
|
|
2217
|
+
const controller = new AuthController(authServices${browserMfa ? ", views" : ""});` : ` routes({ kernel, dependencies }) {
|
|
2218
|
+
const authServices = dependencies.container.resolve(STARTER_AUTH_SERVICES);`}${browserMfa && !actions ? `
|
|
2036
2219
|
// Browser SSO requires only its continuation view, not general web routes.
|
|
2037
2220
|
const views = dependencies.container.resolve(CORE_VIEW_RENDERER_TOKEN).namespace("auth", { headers: { "Cache-Control": "private, no-store" } });` : ""}
|
|
2038
2221
|
return {${mfaContinuation}${csrfRoute}${samlRoutes}${githubRoutes}${oidcRoutes}${cookieJsonAuth}${tokenLogin}${jsonRegister}${jwtLogin}${apiUser}${jsonPassword}${jsonVerify}${jsonAccountManagement}
|
|
2039
2222
|
};
|
|
2040
|
-
}
|
|
2223
|
+
}${actions ? "" : ","}` : "";
|
|
2041
2224
|
return apiRoutes;
|
|
2042
2225
|
}
|
|
2043
2226
|
|
|
@@ -2375,47 +2558,82 @@ export function createPendingMfaHelpers(options: Readonly<{secret:string;product
|
|
|
2375
2558
|
}
|
|
2376
2559
|
`;
|
|
2377
2560
|
}
|
|
2378
|
-
function
|
|
2379
|
-
return `import type { AppModule } from "@getstrata/bootstrap/contracts";
|
|
2380
|
-
import { CORE_VIEW_RENDERER_TOKEN } from "@getstrata/core/view";
|
|
2381
|
-
|
|
2382
|
-
const siteModule: AppModule = {
|
|
2383
|
-
name: "site",
|
|
2384
|
-
order: 1,
|
|
2385
|
-
webRoutes({ kernel, dependencies }) {
|
|
2386
|
-
const views = dependencies.container.resolve(CORE_VIEW_RENDERER_TOKEN);
|
|
2387
|
-
return {
|
|
2388
|
-
"/": kernel.wrapWeb(async (request) =>
|
|
2389
|
-
views.renderHtmx("home.eta", { layout: { title: "Welcome", description: "Welcome to your Strata app. Restyle views/home.eta and public/assets/site.css." } }, { request }),
|
|
2390
|
-
),
|
|
2391
|
-
};
|
|
2392
|
-
},
|
|
2393
|
-
};
|
|
2394
|
-
|
|
2395
|
-
export default siteModule;
|
|
2396
|
-
`;
|
|
2397
|
-
}
|
|
2398
|
-
function renderAuthModule(plan) {
|
|
2561
|
+
function renderAuthHttp(plan) {
|
|
2399
2562
|
if (!plan.decisions.users)
|
|
2400
2563
|
return null;
|
|
2401
2564
|
const context = createAuthRenderingContext(plan);
|
|
2402
|
-
const imports = renderAuthImports(context)
|
|
2403
|
-
|
|
2404
|
-
const
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2565
|
+
const imports = renderAuthImports(context).join(`
|
|
2566
|
+
`);
|
|
2567
|
+
const helperNames = [
|
|
2568
|
+
"runWithLockedAccount",
|
|
2569
|
+
"authTimestamp",
|
|
2570
|
+
"deferAuthEffect",
|
|
2571
|
+
"authenticatePasswordUser",
|
|
2572
|
+
"runWithLoginUser",
|
|
2573
|
+
"runAuthWrite",
|
|
2574
|
+
"issueSignedAuthMail",
|
|
2575
|
+
"createRegistration",
|
|
2576
|
+
"completeSignedPasswordReset",
|
|
2577
|
+
"persistAuthRecovery",
|
|
2578
|
+
...context.verify ? ["completeSignedEmailVerification"] : [],
|
|
2579
|
+
...context.cookie ? ["redirectTo", "sessionUser", "completeBrowserSsoLogin"] : [],
|
|
2580
|
+
...context.mfa ? ["enrollMfa"] : []
|
|
2581
|
+
];
|
|
2582
|
+
const helpers = `${imports}
|
|
2583
|
+
${renderAuthHelpers(context)}
|
|
2410
2584
|
${renderMfaEnrollment(context.mfa)}
|
|
2585
|
+
export { ${helperNames.join(", ")} };
|
|
2586
|
+
`;
|
|
2587
|
+
const controllerDependencies = renderAuthImports(context).filter((line) => !line.includes("AppModule") && !line.includes("CORE_VIEW_RENDERER_TOKEN") && !line.includes("wrapWebLogin")).map((line) => line.includes("STARTER_AUTH_SERVICES") ? 'import type { StarterAuthServices } from "../../bootstrap/auth.ts";' : line).join(`
|
|
2588
|
+
`);
|
|
2589
|
+
const controllerImports = `${controllerDependencies}
|
|
2590
|
+
${context.cookie ? `import type { NamespacedViewRenderer } from "@getstrata/core/view";
|
|
2591
|
+
` : ""}
|
|
2592
|
+
import type { BusinessRouteHandler } from "@getstrata/bootstrap/persistenceContracts";
|
|
2593
|
+
import { ${helperNames.join(", ")} } from "../auth/account.ts";
|
|
2594
|
+
`;
|
|
2595
|
+
const apiActions = new ControllerActions("AuthController");
|
|
2596
|
+
const api = renderApiAuthRoutes(context, apiActions);
|
|
2597
|
+
const apiScope = ["authServices", ...plan.decisions.mfaViews ? ["views"] : []];
|
|
2598
|
+
const construction = (views) => ` constructor(private readonly authServices: StarterAuthServices${views ? ", private readonly views: NamespacedViewRenderer" : ""}) {}`;
|
|
2599
|
+
const files = {
|
|
2600
|
+
"http/auth/account.ts": helpers,
|
|
2601
|
+
"http/controllers/AuthController.ts": controllerImports + apiActions.render(construction(plan.decisions.mfaViews), apiScope)
|
|
2602
|
+
};
|
|
2603
|
+
const webActions = new ControllerActions("AuthWebController");
|
|
2604
|
+
const web = renderBrowserAuthRoutes(context, webActions);
|
|
2605
|
+
if (web)
|
|
2606
|
+
files["http/controllers/AuthWebController.ts"] = controllerImports + webActions.render(construction(true), ["authServices", "views"]);
|
|
2607
|
+
return {
|
|
2608
|
+
files,
|
|
2609
|
+
api: { name: "authApiRoutes", source: api },
|
|
2610
|
+
...web ? { web: { name: "authWebRoutes", source: web } } : {}
|
|
2611
|
+
};
|
|
2612
|
+
}
|
|
2613
|
+
function renderHomeHttp() {
|
|
2614
|
+
return {
|
|
2615
|
+
files: {
|
|
2616
|
+
"http/controllers/HomeController.ts": `import type { BusinessRouteHandler } from "@getstrata/bootstrap/persistenceContracts";
|
|
2617
|
+
import type { ViewRenderer } from "@getstrata/core/view";
|
|
2411
2618
|
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
order: 2,${apiRoutes}${cookieRoutes}
|
|
2415
|
-
};
|
|
2619
|
+
export class HomeController {
|
|
2620
|
+
constructor(private readonly views: ViewRenderer) {}
|
|
2416
2621
|
|
|
2417
|
-
|
|
2418
|
-
|
|
2622
|
+
index: BusinessRouteHandler = async (request) =>
|
|
2623
|
+
this.views.renderHtmx("home.eta", { layout: { title: "Welcome", description: "Welcome to your Strata app. Restyle views/home.eta and public/assets/site.css." } }, { request });
|
|
2624
|
+
}
|
|
2625
|
+
`
|
|
2626
|
+
},
|
|
2627
|
+
web: {
|
|
2628
|
+
name: "homeWebRoutes",
|
|
2629
|
+
source: `export function homeWebRoutes(context: ModuleRouteContext): AppRouteMap {
|
|
2630
|
+
const views = context.dependencies.container.resolve(CORE_VIEW_RENDERER_TOKEN);
|
|
2631
|
+
const controller = new HomeController(views);
|
|
2632
|
+
return { "/": context.kernel.wrapWeb(controller.index) };
|
|
2633
|
+
}
|
|
2634
|
+
`
|
|
2635
|
+
}
|
|
2636
|
+
};
|
|
2419
2637
|
}
|
|
2420
2638
|
// src/renderAuthViews.ts
|
|
2421
2639
|
function renderSiteCss() {
|
|
@@ -2986,7 +3204,8 @@ import config from "../config/app.ts";
|
|
|
2986
3204
|
import paths from "../../strata.config.ts";
|
|
2987
3205
|
import { databaseOptions } from "./database.ts";
|
|
2988
3206
|
import { createStarterAuthServices, STARTER_AUTH_SERVICES } from "./auth.ts";
|
|
2989
|
-
import { modelDefinitions, repositoryDefinitions } from "../models/register.ts";
|
|
3207
|
+
import { modelDefinitions${plan.decisions.workTracker ? ", repositoryDefinitions" : ""} } from "../models/register.ts";
|
|
3208
|
+
import { applicationRoutes } from "../routes/index.ts";
|
|
2990
3209
|
import { Note } from "../models/Note.ts";
|
|
2991
3210
|
import { migrate } from "../db/migrate.ts";
|
|
2992
3211
|
import { listeners } from "../outbox/registry.ts";
|
|
@@ -3000,7 +3219,8 @@ const { bootstrapApp, createApp, createAppServer } = defineApp({
|
|
|
3000
3219
|
database: databaseOptions,
|
|
3001
3220
|
auth: { create: createStarterAuthServices, token: STARTER_AUTH_SERVICES },
|
|
3002
3221
|
models: modelDefinitions,
|
|
3003
|
-
|
|
3222
|
+
routes: applicationRoutes,${plan.decisions.workTracker ? `
|
|
3223
|
+
repositories: repositoryDefinitions,` : ""}
|
|
3004
3224
|
migrate,${plan.decisions.ensureDatabase ? `
|
|
3005
3225
|
ensureDatabase: ensureAppDatabase,` : ""}
|
|
3006
3226
|
outbox: { listeners${plan.decisions.workTracker ? ", token: WORK_TRACKER_OUTBOX" : ""} },
|
|
@@ -3363,31 +3583,30 @@ ${authNote}
|
|
|
3363
3583
|
|
|
3364
3584
|
## Adding a route
|
|
3365
3585
|
|
|
3366
|
-
|
|
3586
|
+
Put HTTP actions in \`src/http/controllers/\` and register their paths and middleware in \`src/routes/api.ts\` or \`src/routes/web.ts\`. The bootstrap loads these route files once. Controller methods receive Bun's native \`Request\` and explicit request ports.
|
|
3367
3587
|
|
|
3368
3588
|
\`\`\`typescript
|
|
3369
|
-
// src/
|
|
3370
|
-
import type {
|
|
3371
|
-
import { jsonResponse } from "@getstrata/core/http/response";
|
|
3589
|
+
// src/http/controllers/NoteController.ts
|
|
3590
|
+
import type { BusinessRouteHandler } from "@getstrata/bootstrap/persistenceContracts";
|
|
3372
3591
|
import { Note } from "../../models/Note.ts";
|
|
3373
3592
|
|
|
3374
|
-
|
|
3375
|
-
|
|
3376
|
-
|
|
3377
|
-
|
|
3378
|
-
|
|
3379
|
-
|
|
3380
|
-
|
|
3381
|
-
|
|
3382
|
-
|
|
3383
|
-
};
|
|
3384
|
-
},
|
|
3385
|
-
};
|
|
3593
|
+
export class NoteController {
|
|
3594
|
+
index: BusinessRouteHandler = async (_request, { database }) => {
|
|
3595
|
+
const notes = await database.model(Note).query().orderBy({ id: "desc" }).get();
|
|
3596
|
+
return Response.json({ data: notes.map(note => note.toJSON()) });
|
|
3597
|
+
};
|
|
3598
|
+
}
|
|
3599
|
+
\`\`\`
|
|
3600
|
+
|
|
3601
|
+
In \`src/routes/api.ts\`, import \`NoteController\` from \`../http/controllers/NoteController.ts\`, construct it in \`apiRoutes(context)\`, and add this map to that function's \`composeRouteMaps(...)\` arguments:
|
|
3386
3602
|
|
|
3387
|
-
|
|
3603
|
+
\`\`\`typescript
|
|
3604
|
+
{ "/api/v1/notes": { GET: context.kernel.wrapApi(notes.index) } }
|
|
3388
3605
|
\`\`\`
|
|
3389
3606
|
|
|
3390
|
-
Use the handler
|
|
3607
|
+
Here \`notes\` is \`const notes = new NoteController();\`. Keep existing route maps and middleware. Use the handler's \`database\` port to bind the model class to the current application and execution. Use \`src/http/requests/\` for application request validation; account credential validation and account workflows are provided by the framework.
|
|
3608
|
+
|
|
3609
|
+
Optional modules in \`src/modules/\` remain available for feature composition. They use the same kernel and execution ports.
|
|
3391
3610
|
|
|
3392
3611
|
## Docs
|
|
3393
3612
|
|
|
@@ -3409,13 +3628,13 @@ function renderIntegrationsReadme(plan) {
|
|
|
3409
3628
|
"",
|
|
3410
3629
|
"OAuth, billing, outbound webhooks, SIEM, and SAML are **off by default**. Commented placeholders live in `.env.example`. Framework map: [INTEGRATIONS.md](https://github.com/EyK-26/strata/blob/main/docs/INTEGRATIONS.md).",
|
|
3411
3630
|
"",
|
|
3412
|
-
"Wizard flags (any stack unless noted): `--oauth-github` and `--oidc` (cookie HTML), `--billing`, `--webhooks`. They emit
|
|
3631
|
+
"Wizard flags (any stack unless noted): `--oauth-github` and `--oidc` (cookie HTML), `--billing`, `--webhooks`. They emit controllers, routes, migrations, jobs, or listeners. `createApp` still calls `await discoverListeners()` and `await discoverJobs()`.",
|
|
3413
3632
|
""
|
|
3414
3633
|
];
|
|
3415
3634
|
if (enabled.length > 0) {
|
|
3416
3635
|
lines.push("Enabled in this app:", "", ...enabled.map((row) => `- ${row}`), "");
|
|
3417
3636
|
} else {
|
|
3418
|
-
lines.push("This app did not pass those flags. Turn a flag on and re-run `create-strata`, or copy the commented env block and add
|
|
3637
|
+
lines.push("This app did not pass those flags. Turn a flag on and re-run `create-strata`, or copy the commented env block and add the integration controller and routes yourself.", "");
|
|
3419
3638
|
}
|
|
3420
3639
|
return `${lines.join(`
|
|
3421
3640
|
`)}
|
|
@@ -3471,6 +3690,9 @@ function renderReadme(projectName, plan, options = {}) {
|
|
|
3471
3690
|
const neededTools = plan.services.required;
|
|
3472
3691
|
const dockerLabel = neededTools.length === 0 ? "not needed" : dockerServices.length > 0 ? dockerServices.join(", ") : "off (local installs)";
|
|
3473
3692
|
return `${renderReadmeIntro(projectName, options)}
|
|
3693
|
+
AI coding agents: read [AGENTS.md](AGENTS.md) for this application's structure,
|
|
3694
|
+
selected stack, feature workflow and validation commands. Keep it current as the app evolves.
|
|
3695
|
+
|
|
3474
3696
|
## Layers
|
|
3475
3697
|
|
|
3476
3698
|
| Layer | Choice |
|
|
@@ -3488,6 +3710,18 @@ ${extras.length > 0 ? `| Extras | ${extras.join(", ")} |
|
|
|
3488
3710
|
` : ""}
|
|
3489
3711
|
This file is the map for this app. Framework guides: [Building apps](https://github.com/EyK-26/strata/blob/main/docs/BUILDING-APPS.md), [Auth](https://github.com/EyK-26/strata/blob/main/docs/AUTH.md), [Starter](https://github.com/EyK-26/strata/blob/main/docs/STARTER.md), [Integrations](https://github.com/EyK-26/strata/blob/main/docs/INTEGRATIONS.md).
|
|
3490
3712
|
|
|
3713
|
+
## Application files
|
|
3714
|
+
|
|
3715
|
+
- \`src/routes/web.ts\`: browser routes and middleware.
|
|
3716
|
+
- \`src/routes/api.ts\`: API and integration routes and middleware.
|
|
3717
|
+
- \`src/http/controllers/\`: named HTTP actions for the selected features.
|
|
3718
|
+
- \`src/http/requests/\`: application request validation when needed. Account parsers and workflows come from the framework.
|
|
3719
|
+
- \`src/models/\`: model classes extending \`defineModel(...)\`; register them in \`src/models/register.ts\`.
|
|
3720
|
+
- \`src/db/migrations/\`: explicit schema changes.
|
|
3721
|
+
- \`src/bootstrap/createApp.ts\`: application services and the route entry point. Optional \`src/modules/\` packages can add feature composition.
|
|
3722
|
+
|
|
3723
|
+
Start a feature with \`bunx strata make:model Task\`, \`bunx strata make:controller Task\`, and \`bunx strata make:request StoreTask\`. Register the model and route explicitly. Controller methods take Bun's native \`Request\` and execution ports; use \`database.model(Task)\` inside the action. Models declare fields, \`$fillable\`, and \`$timestamps\`; a normal model does not need a separate table, repository, or record declaration.
|
|
3724
|
+
|
|
3491
3725
|
${renderIntegrationsReadme(plan)}
|
|
3492
3726
|
## Run it
|
|
3493
3727
|
|
|
@@ -3987,9 +4221,9 @@ function renderPackageJson(projectName, options = {}) {
|
|
|
3987
4221
|
"@getstrata/cli": "workspace:*",
|
|
3988
4222
|
"@getstrata/core": "workspace:*"
|
|
3989
4223
|
} : {
|
|
3990
|
-
"@getstrata/bootstrap": "^3.
|
|
3991
|
-
"@getstrata/cli": "^3.
|
|
3992
|
-
"@getstrata/core": "^3.
|
|
4224
|
+
"@getstrata/bootstrap": "^3.1.1",
|
|
4225
|
+
"@getstrata/cli": "^3.1.1",
|
|
4226
|
+
"@getstrata/core": "^3.1.1"
|
|
3993
4227
|
};
|
|
3994
4228
|
if (!options.plan || options.plan.decisions.serverViews || options.plan.decisions.mfaViews)
|
|
3995
4229
|
coreDeps.eta = "^4.6.0";
|
|
@@ -4048,89 +4282,6 @@ function renderLayersManifest(projectName, plan) {
|
|
|
4048
4282
|
}, null, 2)}
|
|
4049
4283
|
`;
|
|
4050
4284
|
}
|
|
4051
|
-
// src/renderInitialAdmin.ts
|
|
4052
|
-
function renderInitialAdminMigration(plan) {
|
|
4053
|
-
if (!plan.decisions.users)
|
|
4054
|
-
return null;
|
|
4055
|
-
const driver = plan.decisions.sqlDriver;
|
|
4056
|
-
return `import { Schema } from "@getstrata/core/database/schema";
|
|
4057
|
-
import { guardMigrationRollback } from "@getstrata/core/database/migrations";
|
|
4058
|
-
import type { Migration } from "@getstrata/core/database/migrations/types";
|
|
4059
|
-
|
|
4060
|
-
const migration: Migration = {
|
|
4061
|
-
name: "0004_initial_admin_provisioning",
|
|
4062
|
-
async up(db) {
|
|
4063
|
-
await Schema.run(db, "${driver}", schema => {
|
|
4064
|
-
schema.create("initial_admin_provisioning", table => {
|
|
4065
|
-
table.integer("id").primary();
|
|
4066
|
-
table.text("email");
|
|
4067
|
-
table.timestamp("provisioned_at").defaultRaw("CURRENT_TIMESTAMP");
|
|
4068
|
-
});
|
|
4069
|
-
});
|
|
4070
|
-
},
|
|
4071
|
-
async down(db, context) {
|
|
4072
|
-
await guardMigrationRollback(context, {
|
|
4073
|
-
hasHistory: async () => (await db.unsafe("SELECT id FROM initial_admin_provisioning")).length > 0,
|
|
4074
|
-
message: "Cannot discard a completed initial-admin provisioning claim.",
|
|
4075
|
-
});
|
|
4076
|
-
await Schema.run(db, "${driver}", schema => { schema.drop("initial_admin_provisioning"); });
|
|
4077
|
-
},
|
|
4078
|
-
};
|
|
4079
|
-
export default migration;
|
|
4080
|
-
`;
|
|
4081
|
-
}
|
|
4082
|
-
function renderInitialAdminCommand(plan) {
|
|
4083
|
-
const layers = plan.layers;
|
|
4084
|
-
if (!plan.decisions.users)
|
|
4085
|
-
return null;
|
|
4086
|
-
const tenant = plan.decisions.tenantTable;
|
|
4087
|
-
const rls = plan.decisions.rls;
|
|
4088
|
-
const placeholder = layers.database === "postgres" ? "$1" : "?";
|
|
4089
|
-
const fields = ["name", "email", "password", "is_admin", ...tenant ? ["tenant_id"] : []];
|
|
4090
|
-
const placeholders = fields.map((_, index) => layers.database === "postgres" ? `$${index + 1}` : "?");
|
|
4091
|
-
return `import { runInitialAdminCommand } from "@getstrata/cli/initialAdmin";
|
|
4092
|
-
import { hashPassword } from "@getstrata/core/auth/password";
|
|
4093
|
-
import type { TransactionSession } from "@getstrata/core/database/session";
|
|
4094
|
-
${rls ? `import { assertRlsLiveDatabaseRole } from "@getstrata/bootstrap/secretsGuard";
|
|
4095
|
-
` : ""}import { bootstrapApp } from "../bootstrap/createApp.ts";
|
|
4096
|
-
|
|
4097
|
-
export async function initialAdminCommand(...args: string[]): Promise<void> {
|
|
4098
|
-
await runInitialAdminCommand(args, {
|
|
4099
|
-
tenantRequired: ${tenant},
|
|
4100
|
-
async provision(input) {
|
|
4101
|
-
// Hash before acquiring the database claim; only the official auth helper owns crypto.
|
|
4102
|
-
const passwordHash = await hashPassword(input.password);
|
|
4103
|
-
const app = await bootstrapApp({ migrate: false, mode: "command" });
|
|
4104
|
-
try {
|
|
4105
|
-
await app.invoke({ kind: "command", actor: { kind: "system", policy: "cli.initial-admin" } }, async ports => {
|
|
4106
|
-
${rls ? ` await assertRlsLiveDatabaseRole({ ...process.env }, async () => { const rows = await ports.database.execute<{rolname:string;rolsuper:boolean;rolbypassrls:boolean}>({text:"SELECT rolname, rolsuper, rolbypassrls FROM pg_roles WHERE rolname = current_user",params:[]});return rows[0] ?? null; });
|
|
4107
|
-
` : ""} const provision = async (db: TransactionSession) => {
|
|
4108
|
-
// The singleton primary key serializes bootstrap commands across all tenants/processes.
|
|
4109
|
-
await db.execute({text:"INSERT INTO initial_admin_provisioning (id, email) VALUES (1, ${placeholder})",params:[input.email]});
|
|
4110
|
-
if ((await db.execute({text:"SELECT id FROM users WHERE is_admin = ${layers.database === "postgres" ? "TRUE" : "1"} LIMIT 1",params:[]})).length) {
|
|
4111
|
-
throw new Error("An admin already exists.");
|
|
4112
|
-
}
|
|
4113
|
-
if ((await db.execute({text:"SELECT id FROM users WHERE LOWER(email) = ${placeholder}",params:[input.email]})).length) {
|
|
4114
|
-
throw new Error("The account already exists; provisioning never promotes accounts.");
|
|
4115
|
-
}
|
|
4116
|
-
${tenant ? ` if (!(await db.execute({text:"SELECT id FROM tenant WHERE id = ${placeholder}",params:[input.tenantId]})).length) {
|
|
4117
|
-
throw new Error("The tenant does not exist.");
|
|
4118
|
-
}
|
|
4119
|
-
` : ""} await db.execute({text:"INSERT INTO users (${fields.join(", ")}) VALUES (${placeholders.join(", ")})",params:[input.name, input.email, passwordHash, ${layers.database === "postgres" ? "true" : "1"}${tenant ? ", input.tenantId" : ""}]});
|
|
4120
|
-
// Verification and MFA stay unenrolled; normal application flows remain authoritative.
|
|
4121
|
-
};
|
|
4122
|
-
await ${rls ? 'ports.policy.run(ports.database, {kind:"bypass"}, provision)' : "ports.database.transaction(provision)"};
|
|
4123
|
-
});
|
|
4124
|
-
} finally {
|
|
4125
|
-
await app.context.dispose();
|
|
4126
|
-
}
|
|
4127
|
-
},
|
|
4128
|
-
});
|
|
4129
|
-
console.log("Initial admin provisioned. Complete email verification and MFA through the application.");
|
|
4130
|
-
}
|
|
4131
|
-
`;
|
|
4132
|
-
}
|
|
4133
|
-
|
|
4134
4285
|
// src/renderMigrations.ts
|
|
4135
4286
|
function ensureImport(plan) {
|
|
4136
4287
|
return plan.decisions.ensureDatabase ? `import { ensureAppDatabase } from "../bootstrap/ensureDatabase.ts";
|
|
@@ -4321,7 +4472,7 @@ function renderMigrateTs(plan) {
|
|
|
4321
4472
|
const verifyOn = plan.decisions.emailVerification;
|
|
4322
4473
|
const rlsOn = plan.decisions.rls;
|
|
4323
4474
|
const imports = usersOn ? `import { hashPassword } from "@getstrata/core/auth/password";
|
|
4324
|
-
import { User
|
|
4475
|
+
import { User } from "../models/User.ts";
|
|
4325
4476
|
` : "";
|
|
4326
4477
|
const tenant = plan.decisions.schemaTenants ? `
|
|
4327
4478
|
const [tenant] = await selected.execute<{count:string|number}>({text:"SELECT COUNT(*) AS count FROM tenant",params:[]});
|
|
@@ -4341,7 +4492,7 @@ import { createPersistenceInvocation } from "@getstrata/bootstrap/persistenceInv
|
|
|
4341
4492
|
import { migrateDatabase } from "@getstrata/core/database/migrations";
|
|
4342
4493
|
import { isProductionEnv } from "@getstrata/core/runtime/appEnv";
|
|
4343
4494
|
import { databaseOptions, databaseEnvironment } from "../bootstrap/database.ts";
|
|
4344
|
-
import { Note
|
|
4495
|
+
import { Note } from "../models/Note.ts";
|
|
4345
4496
|
import { loadStarterMigrations, withMigrationDatabase } from "./migrationRuntime.ts";
|
|
4346
4497
|
|
|
4347
4498
|
/** An explicit development-only command owns its own canonical Application. */
|
|
@@ -4349,7 +4500,7 @@ export async function seed(input: Readonly<Record<string, string | undefined>> =
|
|
|
4349
4500
|
const environment = databaseEnvironment(input);
|
|
4350
4501
|
if (isProductionEnv(environment)) throw new Error("Demo seeding is disabled in production and staging.");
|
|
4351
4502
|
${ensureCall(plan)} const connection = databaseOptions(environment);
|
|
4352
|
-
const application = createApplication({providers:[],services:createDatabaseBindings({default:"main",connections:{main:connection},
|
|
4503
|
+
const application = createApplication({providers:[],services:createDatabaseBindings({default:"main",connections:{main:connection},models:[Note${usersOn ? ",User" : ""}]})});
|
|
4353
4504
|
await application.start();
|
|
4354
4505
|
try {
|
|
4355
4506
|
const invoke = createPersistenceInvocation(application, "main");
|
|
@@ -4696,9 +4847,9 @@ function renderNoteCreatedWebhookListener() {
|
|
|
4696
4847
|
return `import type { ListenerDeclarations } from "@getstrata/bootstrap/discoverListeners";
|
|
4697
4848
|
import { service } from "@getstrata/core/contracts/services";
|
|
4698
4849
|
import { createServiceToken } from "@getstrata/core/contracts/token";
|
|
4699
|
-
import {
|
|
4850
|
+
import { modelEffects, type AfterCommitRepositoryListener } from "@getstrata/core/database/definitions";
|
|
4700
4851
|
import { APPLICATION_QUEUE as STARTER_QUEUE_TOKEN, APPLICATION_WEBHOOKS as STARTER_WEBHOOK_OPTIONS_TOKEN } from "@getstrata/bootstrap/application";
|
|
4701
|
-
import {
|
|
4852
|
+
import { Note, type NoteRecord } from "../models/Note.ts";
|
|
4702
4853
|
import DispatchOutboundWebhookJob from "../jobs/dispatchOutboundWebhookJob.ts";
|
|
4703
4854
|
|
|
4704
4855
|
const noteCreated = createServiceToken<AfterCommitRepositoryListener<NoteRecord>>("starter.webhooks.note-created");
|
|
@@ -4731,7 +4882,7 @@ const declarations: ListenerDeclarations = Object.freeze({
|
|
|
4731
4882
|
}
|
|
4732
4883
|
},
|
|
4733
4884
|
})]),
|
|
4734
|
-
repositoryEffects: Object.freeze([
|
|
4885
|
+
repositoryEffects: Object.freeze([modelEffects(Note, [
|
|
4735
4886
|
{action: "created", afterCommit: noteCreated},
|
|
4736
4887
|
])]),
|
|
4737
4888
|
});
|
|
@@ -4761,7 +4912,7 @@ export type { StripeWebhookEvent };
|
|
|
4761
4912
|
export { applyStripeWebhook };
|
|
4762
4913
|
`;
|
|
4763
4914
|
}
|
|
4764
|
-
function
|
|
4915
|
+
function renderBillingParts(plan, actions) {
|
|
4765
4916
|
const layers = plan.layers;
|
|
4766
4917
|
const tenancyOn = plan.decisions.tenantTable;
|
|
4767
4918
|
const tenantPlaceholder = layers.database === "postgres" ? "$1" : "?";
|
|
@@ -4776,20 +4927,24 @@ function renderBillingModule(plan) {
|
|
|
4776
4927
|
text: "SELECT plan, status, stripe_subscription_id, current_period_end FROM subscription LIMIT 1",
|
|
4777
4928
|
params: [],
|
|
4778
4929
|
});`;
|
|
4779
|
-
|
|
4930
|
+
const support = `import type { AppModule, ModuleRouteContext } from "@getstrata/bootstrap/contracts";
|
|
4780
4931
|
import { jsonResponse } from "@getstrata/core/http/response";
|
|
4781
4932
|
import { verifyStripeWebhookSignature } from "@getstrata/core/security/stripeWebhook";
|
|
4782
4933
|
import { applyStripeWebhook } from "../../billing/applyStripeWebhook.ts";
|
|
4783
4934
|
import { APPLICATION_BILLING as STARTER_BILLING_OPTIONS_TOKEN } from "@getstrata/bootstrap/application";
|
|
4784
4935
|
|
|
4785
|
-
|
|
4936
|
+
`;
|
|
4937
|
+
const routes = `${actions ? `export function billingApiRoutes(context: ModuleRouteContext): AppRouteMap {
|
|
4938
|
+
const { kernel, dependencies } = context;
|
|
4939
|
+
const { enabled, stripeSecret } = dependencies.container.get(STARTER_BILLING_OPTIONS_TOKEN);
|
|
4940
|
+
const controller = new BillingController(enabled, stripeSecret);` : `const billingModule: AppModule = {
|
|
4786
4941
|
name: "billing",
|
|
4787
4942
|
order: 40,
|
|
4788
4943
|
routes({ kernel, dependencies }) {
|
|
4789
|
-
const {enabled:billingEnabled,stripeSecret:secret} = dependencies.container.get(STARTER_BILLING_OPTIONS_TOKEN)
|
|
4944
|
+
const {enabled:billingEnabled,stripeSecret:secret} = dependencies.container.get(STARTER_BILLING_OPTIONS_TOKEN);`}
|
|
4790
4945
|
return {
|
|
4791
4946
|
"/billing/webhooks/stripe": {
|
|
4792
|
-
POST: kernel.wrap("api", kernel.wrapIdentity(async (request, ports) => {
|
|
4947
|
+
POST: kernel.wrap("api", kernel.wrapIdentity(${renderAction(actions, "stripeWebhook", `async (request, ports) => {
|
|
4793
4948
|
if (!billingEnabled) return new Response("Not found", { status: 404 });
|
|
4794
4949
|
if (!secret) {
|
|
4795
4950
|
return jsonResponse({ error: "STRIPE_WEBHOOK_SECRET is not set." }, { status: 503 });
|
|
@@ -4804,10 +4959,10 @@ const billingModule: AppModule = {
|
|
|
4804
4959
|
}
|
|
4805
4960
|
await applyStripeWebhook(event, ports);
|
|
4806
4961
|
return jsonResponse({ received: true, id: event.id ?? null, type: event.type ?? null });
|
|
4807
|
-
})),
|
|
4962
|
+
}`)})),
|
|
4808
4963
|
},
|
|
4809
4964
|
"/api/v1/billing/subscription": {
|
|
4810
|
-
GET: kernel.wrapApi(async (_request, ports) => {
|
|
4965
|
+
GET: kernel.wrapApi(${renderAction(actions, "subscription", `async (_request, ports) => {
|
|
4811
4966
|
if (!billingEnabled) return new Response("Not found", { status: 404 });
|
|
4812
4967
|
${subscriptionQuery}
|
|
4813
4968
|
const row = rows[0];
|
|
@@ -4818,210 +4973,40 @@ ${subscriptionQuery}
|
|
|
4818
4973
|
stripe_subscription_id: row.stripe_subscription_id ?? null,
|
|
4819
4974
|
current_period_end: row.current_period_end ?? null,
|
|
4820
4975
|
});
|
|
4821
|
-
}),
|
|
4976
|
+
}`)}),
|
|
4822
4977
|
},
|
|
4823
4978
|
};
|
|
4824
|
-
}
|
|
4979
|
+
}${actions ? "" : `,
|
|
4825
4980
|
};
|
|
4826
4981
|
|
|
4827
|
-
export default billingModule
|
|
4828
|
-
`;
|
|
4829
|
-
}
|
|
4830
|
-
|
|
4831
|
-
// src/renderModels.ts
|
|
4832
|
-
function renderNoteModel(plan) {
|
|
4833
|
-
const tenancyOn = plan.decisions.tenantTable;
|
|
4834
|
-
const tenantField = tenancyOn ? `
|
|
4835
|
-
tenant_id: number;` : "";
|
|
4836
|
-
const tenantColumn = tenancyOn ? ', "tenant_id"' : "";
|
|
4837
|
-
const fillable = tenancyOn ? '["body", "tenant_id"]' : '["body"]';
|
|
4838
|
-
return `import { createModel, type Model } from "@getstrata/core/database/model";
|
|
4839
|
-
import { defineTable } from "@getstrata/core/database/table";
|
|
4840
|
-
|
|
4841
|
-
interface NoteRecord {
|
|
4842
|
-
id: number;
|
|
4843
|
-
body: string;${tenantField}
|
|
4844
|
-
created_at: Date | string;
|
|
4845
|
-
}
|
|
4846
|
-
|
|
4847
|
-
const notesTable = defineTable<NoteRecord, "id">({
|
|
4848
|
-
name: "notes",
|
|
4849
|
-
primaryKey: "id",
|
|
4850
|
-
columns: ["id", "body"${tenantColumn}, "created_at"],
|
|
4851
|
-
defaultOrderBy: { column: "id", direction: "ASC" },
|
|
4852
|
-
});
|
|
4853
|
-
|
|
4854
|
-
type Note = Model<NoteRecord, "id">;
|
|
4855
|
-
|
|
4856
|
-
const Note = createModel({
|
|
4857
|
-
name: "Note", table: notesTable,
|
|
4858
|
-
// created_at uses the table default; no client timestamp is sent.
|
|
4859
|
-
attributes: { fillable: ${fillable}, timestamps: false },
|
|
4860
|
-
});
|
|
4861
|
-
const NoteRepository = Note.repository;
|
|
4862
|
-
|
|
4863
|
-
export type { NoteRecord };
|
|
4864
|
-
export { Note, NoteRepository };
|
|
4865
|
-
`;
|
|
4866
|
-
}
|
|
4867
|
-
function renderUserModel(plan) {
|
|
4868
|
-
const layers = plan.layers;
|
|
4869
|
-
const tenancyOn = plan.decisions.schemaTenants;
|
|
4870
|
-
const mfaOn = Boolean(layers.extras.mfa);
|
|
4871
|
-
const tenantField = tenancyOn ? `
|
|
4872
|
-
tenant_id: number;` : "";
|
|
4873
|
-
const mfaFields = mfaOn ? `
|
|
4874
|
-
mfa_secret: string | null;
|
|
4875
|
-
mfa_enabled: number | boolean;
|
|
4876
|
-
mfa_recovery_codes: string | null;` : "";
|
|
4877
|
-
const columns = ["id", "name", "email", "password", "is_admin", "is_active", "auth_version"];
|
|
4878
|
-
if (tenancyOn) {
|
|
4879
|
-
columns.push("tenant_id");
|
|
4880
|
-
}
|
|
4881
|
-
if (mfaOn) {
|
|
4882
|
-
columns.push("mfa_secret", "mfa_enabled", "mfa_recovery_codes");
|
|
4883
|
-
}
|
|
4884
|
-
columns.push("session_valid_after", "email_verified_at", "created_at");
|
|
4885
|
-
const fillable = ["name", "email", "password", "is_admin", "is_active"];
|
|
4886
|
-
if (tenancyOn) {
|
|
4887
|
-
fillable.push("tenant_id");
|
|
4888
|
-
}
|
|
4889
|
-
if (mfaOn) {
|
|
4890
|
-
fillable.push("mfa_secret", "mfa_enabled", "mfa_recovery_codes");
|
|
4891
|
-
}
|
|
4892
|
-
fillable.push("session_valid_after", "email_verified_at");
|
|
4893
|
-
const hidden = ["password"];
|
|
4894
|
-
if (mfaOn) {
|
|
4895
|
-
hidden.push("mfa_secret", "mfa_recovery_codes");
|
|
4896
|
-
}
|
|
4897
|
-
const fillableLiteral = `[${fillable.map((column) => `"${column}"`).join(", ")}]`;
|
|
4898
|
-
const hiddenLiteral = `[${hidden.map((column) => `"${column}"`).join(", ")}]`;
|
|
4899
|
-
const columnsLiteral = columns.map((column) => `"${column}"`).join(", ");
|
|
4900
|
-
return `import { createModel, type Model } from "@getstrata/core/database/model";
|
|
4901
|
-
import { defineTable } from "@getstrata/core/database/table";
|
|
4902
|
-
|
|
4903
|
-
interface UserRecord {
|
|
4904
|
-
id: number;
|
|
4905
|
-
name: string;
|
|
4906
|
-
email: string;
|
|
4907
|
-
password: string;
|
|
4908
|
-
is_active: number | boolean;
|
|
4909
|
-
auth_version: number;
|
|
4910
|
-
is_admin: number | boolean;${tenantField}${mfaFields}
|
|
4911
|
-
session_valid_after: Date | string | null;
|
|
4912
|
-
email_verified_at: Date | string | null;
|
|
4913
|
-
created_at: Date | string;
|
|
4914
|
-
}
|
|
4915
|
-
|
|
4916
|
-
const usersTable = defineTable<UserRecord, "id">({
|
|
4917
|
-
name: "users",
|
|
4918
|
-
primaryKey: "id",
|
|
4919
|
-
columns: [${columnsLiteral}],
|
|
4920
|
-
defaultOrderBy: { column: "id", direction: "ASC" },
|
|
4921
|
-
});
|
|
4922
|
-
|
|
4923
|
-
type User = Model<UserRecord, "id">;
|
|
4924
|
-
|
|
4925
|
-
const User = createModel({
|
|
4926
|
-
name: "User", table: usersTable,
|
|
4927
|
-
// created_at uses the table default; no client timestamp is sent.
|
|
4928
|
-
attributes: { fillable: ${fillableLiteral}, hidden: ${hiddenLiteral}, timestamps: false },
|
|
4929
|
-
});
|
|
4930
|
-
const UserRepository = User.repository;
|
|
4931
|
-
|
|
4932
|
-
export type { UserRecord };
|
|
4933
|
-
export { User, UserRepository };
|
|
4934
|
-
`;
|
|
4935
|
-
}
|
|
4936
|
-
function renderApiTokenModel() {
|
|
4937
|
-
return `import { createModel, type Model } from "@getstrata/core/database/model";
|
|
4938
|
-
import { defineTable } from "@getstrata/core/database/table";
|
|
4939
|
-
|
|
4940
|
-
interface ApiTokenRecord {
|
|
4941
|
-
id: number;
|
|
4942
|
-
user_id: number;
|
|
4943
|
-
name: string;
|
|
4944
|
-
token_hash: string;
|
|
4945
|
-
abilities: string;
|
|
4946
|
-
expires_at: Date | string | null;
|
|
4947
|
-
last_used_at: Date | string | null;
|
|
4948
|
-
created_at: Date | string;
|
|
4949
|
-
}
|
|
4950
|
-
|
|
4951
|
-
const apiTokensTable = defineTable<ApiTokenRecord, "id">({
|
|
4952
|
-
name: "api_tokens",
|
|
4953
|
-
primaryKey: "id",
|
|
4954
|
-
columns: ["id", "user_id", "name", "token_hash", "abilities", "expires_at", "last_used_at", "created_at"],
|
|
4955
|
-
defaultOrderBy: { column: "id", direction: "ASC" },
|
|
4956
|
-
});
|
|
4957
|
-
|
|
4958
|
-
type ApiToken = Model<ApiTokenRecord, "id">;
|
|
4959
|
-
|
|
4960
|
-
const ApiToken = createModel({
|
|
4961
|
-
name: "ApiToken", table: apiTokensTable,
|
|
4962
|
-
// created_at uses the table default; no client timestamp is sent.
|
|
4963
|
-
attributes: { fillable: ["user_id", "name", "token_hash", "abilities", "expires_at", "last_used_at"], timestamps: false },
|
|
4964
|
-
});
|
|
4965
|
-
const ApiTokenRepository = ApiToken.repository;
|
|
4966
|
-
|
|
4967
|
-
export type { ApiTokenRecord };
|
|
4968
|
-
export { ApiToken, ApiTokenRepository };
|
|
4969
|
-
`;
|
|
4970
|
-
}
|
|
4971
|
-
function renderAuthOneTimeTokenModel() {
|
|
4972
|
-
return `import { createModel, type Model } from "@getstrata/core/database/model";
|
|
4973
|
-
import { defineTable } from "@getstrata/core/database/table";
|
|
4974
|
-
|
|
4975
|
-
interface AuthOneTimeTokenRecord {
|
|
4976
|
-
id: number;
|
|
4977
|
-
purpose: string;
|
|
4978
|
-
user_id: number;
|
|
4979
|
-
token_hash: string;
|
|
4980
|
-
expires_at: Date | string;
|
|
4981
|
-
consumed_at: Date | string | null;
|
|
4982
|
-
}
|
|
4983
|
-
|
|
4984
|
-
const authOneTimeTokensTable = defineTable<AuthOneTimeTokenRecord, "id">({
|
|
4985
|
-
name: "auth_one_time_tokens",
|
|
4986
|
-
primaryKey: "id",
|
|
4987
|
-
columns: ["id", "purpose", "user_id", "token_hash", "expires_at", "consumed_at"],
|
|
4988
|
-
defaultOrderBy: { column: "id", direction: "ASC" },
|
|
4989
|
-
});
|
|
4990
|
-
|
|
4991
|
-
type AuthOneTimeToken = Model<AuthOneTimeTokenRecord, "id">;
|
|
4992
|
-
|
|
4993
|
-
const AuthOneTimeToken = createModel({
|
|
4994
|
-
name: "AuthOneTimeToken", table: authOneTimeTokensTable,
|
|
4995
|
-
attributes: { fillable: ["purpose", "user_id", "token_hash", "expires_at", "consumed_at"], timestamps: false },
|
|
4996
|
-
});
|
|
4997
|
-
const AuthOneTimeTokenRepository = AuthOneTimeToken.repository;
|
|
4998
|
-
|
|
4999
|
-
export type { AuthOneTimeTokenRecord };
|
|
5000
|
-
export { AuthOneTimeToken, AuthOneTimeTokenRepository };
|
|
4982
|
+
export default billingModule;`}
|
|
5001
4983
|
`;
|
|
4984
|
+
return { support, routes };
|
|
5002
4985
|
}
|
|
5003
|
-
function
|
|
5004
|
-
|
|
5005
|
-
|
|
5006
|
-
|
|
5007
|
-
|
|
5008
|
-
|
|
5009
|
-
|
|
5010
|
-
|
|
5011
|
-
|
|
5012
|
-
|
|
5013
|
-
|
|
5014
|
-
|
|
5015
|
-
|
|
5016
|
-
|
|
4986
|
+
function renderBillingHttp(plan) {
|
|
4987
|
+
if (!plan.layers.extras.billing)
|
|
4988
|
+
return null;
|
|
4989
|
+
const actions = new ControllerActions("BillingController");
|
|
4990
|
+
const parts = renderBillingParts(plan, actions);
|
|
4991
|
+
const construction = ` constructor(private readonly billingEnabled: boolean, private readonly secret: string | undefined) {}`;
|
|
4992
|
+
const support = parts.support.replace(`import type { AppModule, ModuleRouteContext } from "@getstrata/bootstrap/contracts";
|
|
4993
|
+
`, "").replace(`import { APPLICATION_BILLING as STARTER_BILLING_OPTIONS_TOKEN } from "@getstrata/bootstrap/application";
|
|
4994
|
+
`, "");
|
|
4995
|
+
return {
|
|
4996
|
+
files: {
|
|
4997
|
+
"http/controllers/BillingController.ts": support + `import type { BusinessRouteHandler } from "@getstrata/bootstrap/persistenceContracts";
|
|
4998
|
+
` + actions.render(construction, ["billingEnabled", "secret"])
|
|
4999
|
+
},
|
|
5000
|
+
api: { name: "billingApiRoutes", source: parts.routes }
|
|
5001
|
+
};
|
|
5017
5002
|
}
|
|
5018
5003
|
|
|
5019
5004
|
// src/renderScim.ts
|
|
5020
|
-
function
|
|
5005
|
+
function renderScimParts(plan, actions) {
|
|
5021
5006
|
if (!plan.decisions.scim) {
|
|
5022
5007
|
return null;
|
|
5023
5008
|
}
|
|
5024
|
-
|
|
5009
|
+
const support = `import { randomBytes } from "node:crypto";
|
|
5025
5010
|
import type { HttpKernel } from "@getstrata/bootstrap/httpKernel";
|
|
5026
5011
|
import type { AppModule } from "@getstrata/bootstrap/contracts";
|
|
5027
5012
|
import { routeParams } from "@getstrata/bootstrap/web/routing";
|
|
@@ -5177,7 +5162,7 @@ async function readScimBody(request: Request): Promise<Record<string, unknown> |
|
|
|
5177
5162
|
}
|
|
5178
5163
|
}
|
|
5179
5164
|
|
|
5180
|
-
function wrapScim(kernel: HttpKernel, services:StarterAuthServices, handler: BusinessRouteHandler) {
|
|
5165
|
+
${actions ? "export " : ""}function wrapScim(kernel: HttpKernel, services:StarterAuthServices, handler: BusinessRouteHandler) {
|
|
5181
5166
|
const enabled = services.config.scimEnabled;
|
|
5182
5167
|
const throttle = kernel.ownThrottle(createScimThrottleMiddleware({
|
|
5183
5168
|
redisUrl: services.config.redisUrl,
|
|
@@ -5195,16 +5180,19 @@ function wrapScim(kernel: HttpKernel, services:StarterAuthServices, handler: Bus
|
|
|
5195
5180
|
}, [throttle]);
|
|
5196
5181
|
}
|
|
5197
5182
|
|
|
5198
|
-
|
|
5183
|
+
`;
|
|
5184
|
+
const routes = `${actions ? `export function scimApiRoutes(context: ModuleRouteContext): AppRouteMap {
|
|
5185
|
+
const { kernel, dependencies } = context;
|
|
5186
|
+
const controller = new ScimController();` : `const scimModule: AppModule = {
|
|
5199
5187
|
name: "scim",
|
|
5200
5188
|
order: 8,
|
|
5201
|
-
routes({ kernel, dependencies }) {
|
|
5189
|
+
routes({ kernel, dependencies }) {`}
|
|
5202
5190
|
const services = dependencies.container.resolve(STARTER_AUTH_SERVICES);
|
|
5203
5191
|
return {
|
|
5204
5192
|
"/scim/v2/ServiceProviderConfig": {
|
|
5205
5193
|
GET: kernel.wrap(
|
|
5206
5194
|
"api",
|
|
5207
|
-
wrapScim(kernel, services, async () =>
|
|
5195
|
+
wrapScim(kernel, services, ${renderAction(actions, "configuration", `async () =>
|
|
5208
5196
|
scimJson({
|
|
5209
5197
|
schemas: [CONFIG_SCHEMA],
|
|
5210
5198
|
patch: { supported: true },
|
|
@@ -5222,14 +5210,14 @@ const scimModule: AppModule = {
|
|
|
5222
5210
|
primary: true,
|
|
5223
5211
|
},
|
|
5224
5212
|
],
|
|
5225
|
-
}),
|
|
5213
|
+
})`)},
|
|
5226
5214
|
),
|
|
5227
5215
|
),
|
|
5228
5216
|
},
|
|
5229
5217
|
"/scim/v2/Users": {
|
|
5230
5218
|
GET: kernel.wrap(
|
|
5231
5219
|
"api",
|
|
5232
|
-
wrapScim(kernel, services, async (request, ports) => {
|
|
5220
|
+
wrapScim(kernel, services, ${renderAction(actions, "index", `async (request, ports) => {
|
|
5233
5221
|
const url = new URL(request.url);
|
|
5234
5222
|
const filter = url.searchParams.get("filter") ?? "";
|
|
5235
5223
|
const match = /userName\\s+eq\\s+"([^"]+)"/i.exec(filter);
|
|
@@ -5257,11 +5245,11 @@ const scimModule: AppModule = {
|
|
|
5257
5245
|
itemsPerPage: page.length,
|
|
5258
5246
|
Resources: page.map(toScimUser),
|
|
5259
5247
|
});
|
|
5260
|
-
}),
|
|
5248
|
+
}`)}),
|
|
5261
5249
|
),
|
|
5262
5250
|
POST: kernel.wrap(
|
|
5263
5251
|
"api",
|
|
5264
|
-
wrapScim(kernel, services, async (request, ports) => {
|
|
5252
|
+
wrapScim(kernel, services, ${renderAction(actions, "store", `async (request, ports) => {
|
|
5265
5253
|
const body = await readScimBody(request);
|
|
5266
5254
|
if (body instanceof Response) return body;
|
|
5267
5255
|
const invalid = validateScimProfile(body);
|
|
@@ -5281,13 +5269,13 @@ const scimModule: AppModule = {
|
|
|
5281
5269
|
return scimError("Could not create user.", 500);
|
|
5282
5270
|
}
|
|
5283
5271
|
return scimJson(toScimUser(created), 201);
|
|
5284
|
-
}),
|
|
5272
|
+
}`)}),
|
|
5285
5273
|
),
|
|
5286
5274
|
},
|
|
5287
5275
|
"/scim/v2/Users/:id": {
|
|
5288
5276
|
GET: kernel.wrap(
|
|
5289
5277
|
"api",
|
|
5290
|
-
wrapScim(kernel, services, async (request, ports) => {
|
|
5278
|
+
wrapScim(kernel, services, ${renderAction(actions, "show", `async (request, ports) => {
|
|
5291
5279
|
const id = readScimUserId(request);
|
|
5292
5280
|
if (id instanceof Response) {
|
|
5293
5281
|
return id;
|
|
@@ -5297,11 +5285,11 @@ const scimModule: AppModule = {
|
|
|
5297
5285
|
return scimError("User not found.", 404);
|
|
5298
5286
|
}
|
|
5299
5287
|
return scimJson(toScimUser(user));
|
|
5300
|
-
}),
|
|
5288
|
+
}`)}),
|
|
5301
5289
|
),
|
|
5302
5290
|
PUT: kernel.wrap(
|
|
5303
5291
|
"api",
|
|
5304
|
-
wrapScim(kernel, services, async (request, ports) => {
|
|
5292
|
+
wrapScim(kernel, services, ${renderAction(actions, "update", `async (request, ports) => {
|
|
5305
5293
|
const id = readScimUserId(request);
|
|
5306
5294
|
if (id instanceof Response) {
|
|
5307
5295
|
return id;
|
|
@@ -5321,11 +5309,11 @@ const scimModule: AppModule = {
|
|
|
5321
5309
|
}
|
|
5322
5310
|
await applyAccountUpdate(ports, user, name, email, typeof body.active === "boolean" ? body.active : undefined);
|
|
5323
5311
|
return scimJson(toScimUser(user));
|
|
5324
|
-
}),
|
|
5312
|
+
}`)}),
|
|
5325
5313
|
),
|
|
5326
5314
|
PATCH: kernel.wrap(
|
|
5327
5315
|
"api",
|
|
5328
|
-
wrapScim(kernel, services, async (request, ports) => {
|
|
5316
|
+
wrapScim(kernel, services, ${renderAction(actions, "patch", `async (request, ports) => {
|
|
5329
5317
|
const id = readScimUserId(request);
|
|
5330
5318
|
if (id instanceof Response) {
|
|
5331
5319
|
return id;
|
|
@@ -5380,11 +5368,11 @@ const scimModule: AppModule = {
|
|
|
5380
5368
|
}
|
|
5381
5369
|
await applyAccountUpdate(ports, user, name, email, active);
|
|
5382
5370
|
return scimJson(toScimUser(user));
|
|
5383
|
-
}),
|
|
5371
|
+
}`)}),
|
|
5384
5372
|
),
|
|
5385
5373
|
DELETE: kernel.wrap(
|
|
5386
5374
|
"api",
|
|
5387
|
-
wrapScim(kernel, services, async (request, ports) => {
|
|
5375
|
+
wrapScim(kernel, services, ${renderAction(actions, "destroy", `async (request, ports) => {
|
|
5388
5376
|
const id = readScimUserId(request);
|
|
5389
5377
|
if (id instanceof Response) {
|
|
5390
5378
|
return id;
|
|
@@ -5394,15 +5382,29 @@ const scimModule: AppModule = {
|
|
|
5394
5382
|
await user.delete();
|
|
5395
5383
|
}
|
|
5396
5384
|
return new Response(null, { status: 204 });
|
|
5397
|
-
}),
|
|
5385
|
+
}`)}),
|
|
5398
5386
|
),
|
|
5399
5387
|
},
|
|
5400
5388
|
};
|
|
5401
|
-
}
|
|
5389
|
+
}${actions ? "" : `,
|
|
5402
5390
|
};
|
|
5403
5391
|
|
|
5404
|
-
export default scimModule
|
|
5392
|
+
export default scimModule;`}
|
|
5405
5393
|
`;
|
|
5394
|
+
return { support, routes };
|
|
5395
|
+
}
|
|
5396
|
+
function renderScimHttp(plan) {
|
|
5397
|
+
const actions = new ControllerActions("ScimController");
|
|
5398
|
+
const parts = renderScimParts(plan, actions);
|
|
5399
|
+
if (!parts)
|
|
5400
|
+
return null;
|
|
5401
|
+
return {
|
|
5402
|
+
files: {
|
|
5403
|
+
"http/controllers/ScimController.ts": parts.support.replace(`import type { AppModule } from "@getstrata/bootstrap/contracts";
|
|
5404
|
+
`, "").replace("import { STARTER_AUTH_SERVICES, type StarterAuthServices }", "import type { StarterAuthServices }") + actions.render()
|
|
5405
|
+
},
|
|
5406
|
+
api: { name: "scimApiRoutes", source: parts.routes }
|
|
5407
|
+
};
|
|
5406
5408
|
}
|
|
5407
5409
|
|
|
5408
5410
|
// src/renderWorkTracker.ts
|
|
@@ -5573,8 +5575,8 @@ ${tables.map((table) => `await db.unsafe("DROP TABLE ${table}");`).join(`
|
|
|
5573
5575
|
export default migration;
|
|
5574
5576
|
`;
|
|
5575
5577
|
}
|
|
5576
|
-
function
|
|
5577
|
-
|
|
5578
|
+
function renderWorkTrackerParts(actions) {
|
|
5579
|
+
const support = `import type { AppModule, ModuleRouteContext, BusinessRequestPorts } from "@getstrata/bootstrap/contracts";
|
|
5578
5580
|
import { BadRequestError, NotFoundError, UnauthorizedError } from "@getstrata/core/errors/http";
|
|
5579
5581
|
import { jsonResponse } from "@getstrata/core/http/response";
|
|
5580
5582
|
import { currentRequestMeta } from "@getstrata/core/http/requestMetaContext";
|
|
@@ -5584,7 +5586,8 @@ function identity(ports:BusinessRequestPorts){
|
|
|
5584
5586
|
if(!user)throw new UnauthorizedError();
|
|
5585
5587
|
return {tenantId:ports.established.tenant.id,userId:Number(user.id)};
|
|
5586
5588
|
}
|
|
5587
|
-
|
|
5589
|
+
${actions ? `import { readWorkFields as fields } from "../requests/WorkRequest.ts";
|
|
5590
|
+
` : `async function fields(request:Request):Promise<Record<string,unknown>>{
|
|
5588
5591
|
const content=request.headers.get("content-type")??"";
|
|
5589
5592
|
if(content.includes("application/json")){
|
|
5590
5593
|
const value:unknown=await request.json();
|
|
@@ -5593,6 +5596,7 @@ async function fields(request:Request):Promise<Record<string,unknown>>{
|
|
|
5593
5596
|
}
|
|
5594
5597
|
return Object.fromEntries(await request.formData());
|
|
5595
5598
|
}
|
|
5599
|
+
`}
|
|
5596
5600
|
async function mutate(input:Record<string,unknown>,ports:BusinessRequestPorts,publisher:WorkPublisher){
|
|
5597
5601
|
try {
|
|
5598
5602
|
const service=createWorkTracker(ports.database,publisher,identity(ports));
|
|
@@ -5612,22 +5616,30 @@ async function mutate(input:Record<string,unknown>,ports:BusinessRequestPorts,pu
|
|
|
5612
5616
|
}
|
|
5613
5617
|
}
|
|
5614
5618
|
function escape(value:string){return value.replace(/[&<>"']/g,char=>({"&":"&","<":"<",">":">",'"':""","'":"'"})[char]!);}
|
|
5615
|
-
|
|
5619
|
+
`;
|
|
5620
|
+
const api = `${actions ? `export function workTrackerApiRoutes(context: ModuleRouteContext): AppRouteMap {
|
|
5621
|
+
const { kernel, dependencies } = context;
|
|
5622
|
+
const publisher = dependencies.container.resolve(WORK_TRACKER_OUTBOX);
|
|
5623
|
+
const controller = new WorkTrackerController(publisher);` : `const module:AppModule={name:"work-tracker",order:5,
|
|
5616
5624
|
routes({kernel,dependencies}){
|
|
5617
|
-
const publisher=dependencies.container.resolve(WORK_TRACKER_OUTBOX)
|
|
5625
|
+
const publisher=dependencies.container.resolve(WORK_TRACKER_OUTBOX);`}
|
|
5618
5626
|
return {"/api/v1/work":{
|
|
5619
|
-
GET:kernel.wrapApi(async(request,ports)=>{
|
|
5627
|
+
GET:kernel.wrapApi(${renderAction(actions, "index", `async(request,ports)=>{
|
|
5620
5628
|
const service=createWorkTracker(ports.database,publisher,identity(ports));
|
|
5621
5629
|
const organization=new URL(request.url).searchParams.get("organization");
|
|
5622
5630
|
return jsonResponse(organization?await service.tasks(organization):await service.organizations());
|
|
5623
|
-
}),
|
|
5624
|
-
POST:kernel.wrapApi(async(request,ports)=>jsonResponse(await mutate(await fields(request),ports,publisher))),
|
|
5631
|
+
}`)}),
|
|
5632
|
+
POST:kernel.wrapApi(${renderAction(actions, "store", `async(request,ports)=>jsonResponse(await mutate(await fields(request),ports,publisher))`)}),
|
|
5625
5633
|
}};
|
|
5626
|
-
},
|
|
5627
|
-
|
|
5628
|
-
|
|
5634
|
+
}${actions ? "" : ","}
|
|
5635
|
+
`;
|
|
5636
|
+
const web = `${actions ? `export function workTrackerWebRoutes(context: ModuleRouteContext): AppRouteMap {
|
|
5637
|
+
const { kernel, dependencies } = context;
|
|
5638
|
+
const publisher = dependencies.container.resolve(WORK_TRACKER_OUTBOX);
|
|
5639
|
+
const controller = new WorkTrackerController(publisher);` : ` webRoutes({kernel,dependencies}){
|
|
5640
|
+
const publisher=dependencies.container.resolve(WORK_TRACKER_OUTBOX);`}
|
|
5629
5641
|
return {"/work":{
|
|
5630
|
-
GET:kernel.wrapWebAuthenticated(async(request,ports)=>{
|
|
5642
|
+
GET:kernel.wrapWebAuthenticated(${renderAction(actions, "showPage", `async(request,ports)=>{
|
|
5631
5643
|
const service=createWorkTracker(ports.database,publisher,identity(ports));
|
|
5632
5644
|
const organization=new URL(request.url).searchParams.get("organization")??"";
|
|
5633
5645
|
const organizations=await service.organizations();
|
|
@@ -5637,18 +5649,34 @@ const module:AppModule={name:"work-tracker",order:5,
|
|
|
5637
5649
|
const form=(content:string)=>'<form method="post" action="/work">'+hidden+content+'</form>';
|
|
5638
5650
|
const html='<!doctype html><title>Work tracker</title><h1>Work tracker</h1><nav>'+organizations.map(org=>'<a href="/work?organization='+encodeURIComponent(org.id)+'">'+escape(org.name)+'</a> ').join('')+'</nav>'+form('<input name="name" required maxlength="200" placeholder="Organization name"><button name="action" value="organization">Create organization</button>')+(organization?'<h2>Projects</h2>'+form('<input name="name" required maxlength="200" placeholder="Project name"><button name="action" value="project">Create project (owner)</button>')+projects.map(project=>'<h3>'+escape(project.name)+'</h3>'+form('<input type="hidden" name="project" value="'+escape(project.id)+'"><input name="title" required maxlength="200" placeholder="Task title"><button name="action" value="task">Create task</button>')).join('')+'<h2>Tasks</h2><ul>'+tasks.map(task=>'<li>'+escape(task.title)+' ('+escape(task.status)+')'+form('<input type="hidden" name="task" value="'+escape(task.id)+'"><button name="action" value="complete">Complete task</button>')+'</li>').join('')+'</ul>':'');
|
|
5639
5651
|
return new Response(html,{headers:{"content-type":"text/html; charset=utf-8","cache-control":"private, no-store"}});
|
|
5640
|
-
}),
|
|
5641
|
-
POST:kernel.wrapWebAuthenticated(async(request,ports)=>{
|
|
5652
|
+
}`)}),
|
|
5653
|
+
POST:kernel.wrapWebAuthenticated(${renderAction(actions, "storeFromPage", `async(request,ports)=>{
|
|
5642
5654
|
const input=await fields(request);
|
|
5643
5655
|
const result=await mutate(input,ports,publisher);
|
|
5644
5656
|
const organization=input.action==="organization"?(result as {id:string}).id:String(input.organization??"");
|
|
5645
5657
|
return new Response(null,{status:303,headers:{location:"/work?organization="+encodeURIComponent(organization)}});
|
|
5646
|
-
}),
|
|
5658
|
+
}`)}),
|
|
5647
5659
|
}};
|
|
5648
|
-
}
|
|
5660
|
+
}${actions ? "" : `,
|
|
5649
5661
|
};
|
|
5650
|
-
export default module
|
|
5662
|
+
export default module;`}
|
|
5651
5663
|
`;
|
|
5664
|
+
return { support, api, web };
|
|
5665
|
+
}
|
|
5666
|
+
function renderWorkTrackerHttp() {
|
|
5667
|
+
const actions = new ControllerActions("WorkTrackerController");
|
|
5668
|
+
const parts = renderWorkTrackerParts(actions);
|
|
5669
|
+
const construction = ` constructor(private readonly publisher: WorkPublisher) {}`;
|
|
5670
|
+
const support = parts.support.replace("AppModule, ModuleRouteContext, BusinessRequestPorts", "BusinessRequestPorts").replace("createWorkTracker, WORK_TRACKER_OUTBOX,", "createWorkTracker,");
|
|
5671
|
+
return {
|
|
5672
|
+
files: {
|
|
5673
|
+
"http/requests/WorkRequest.ts": renderWorkRequest(),
|
|
5674
|
+
"http/controllers/WorkTrackerController.ts": support + `import type { BusinessRouteHandler } from "@getstrata/bootstrap/persistenceContracts";
|
|
5675
|
+
` + actions.render(construction, ["publisher"])
|
|
5676
|
+
},
|
|
5677
|
+
api: { name: "workTrackerApiRoutes", source: parts.api },
|
|
5678
|
+
web: { name: "workTrackerWebRoutes", source: parts.web }
|
|
5679
|
+
};
|
|
5652
5680
|
}
|
|
5653
5681
|
function renderWorkTrackerGuide() {
|
|
5654
5682
|
return `# Work tracker reference
|
|
@@ -5687,6 +5715,283 @@ Column-tenancy drivers use explicit tenant/organization predicates and composite
|
|
|
5687
5715
|
Schema commands use the migration connection; keep privileged credentials out of the runtime.
|
|
5688
5716
|
`;
|
|
5689
5717
|
}
|
|
5718
|
+
function renderWorkRequest() {
|
|
5719
|
+
return `import { BadRequestError } from "@getstrata/core/errors/http";
|
|
5720
|
+
export async function readWorkFields(request:Request):Promise<Record<string,unknown>>{
|
|
5721
|
+
const content=request.headers.get("content-type")??"";
|
|
5722
|
+
if(content.includes("application/json")){
|
|
5723
|
+
const value:unknown=await request.json();
|
|
5724
|
+
if(!value||typeof value!=="object"||Array.isArray(value))throw new BadRequestError("Expected an object.");
|
|
5725
|
+
return value as Record<string,unknown>;
|
|
5726
|
+
}
|
|
5727
|
+
return Object.fromEntries(await request.formData());
|
|
5728
|
+
}
|
|
5729
|
+
`;
|
|
5730
|
+
}
|
|
5731
|
+
|
|
5732
|
+
// src/renderHttp.ts
|
|
5733
|
+
function renderHttpFiles(plan) {
|
|
5734
|
+
const features = [
|
|
5735
|
+
...plan.decisions.serverViews ? [renderHomeHttp()] : [],
|
|
5736
|
+
renderAuthHttp(plan),
|
|
5737
|
+
...plan.decisions.workTracker ? [renderWorkTrackerHttp()] : [],
|
|
5738
|
+
renderScimHttp(plan),
|
|
5739
|
+
renderBillingHttp(plan)
|
|
5740
|
+
].filter((feature) => feature !== null);
|
|
5741
|
+
const files = Object.assign({}, ...features.map((feature) => feature.files));
|
|
5742
|
+
const imports = {
|
|
5743
|
+
api: [
|
|
5744
|
+
...plan.decisions.users ? [
|
|
5745
|
+
'import { AuthController } from "../http/controllers/AuthController.ts";',
|
|
5746
|
+
'import { STARTER_AUTH_SERVICES } from "../bootstrap/auth.ts";'
|
|
5747
|
+
] : [],
|
|
5748
|
+
...plan.decisions.mfaViews ? [
|
|
5749
|
+
'import { wrapWebLogin } from "@getstrata/bootstrap/web/routing";',
|
|
5750
|
+
'import { CORE_VIEW_RENDERER_TOKEN } from "@getstrata/core/view";'
|
|
5751
|
+
] : [],
|
|
5752
|
+
...plan.decisions.workTracker ? [
|
|
5753
|
+
'import { WorkTrackerController } from "../http/controllers/WorkTrackerController.ts";',
|
|
5754
|
+
'import { WORK_TRACKER_OUTBOX } from "../domain/workTracker.ts";'
|
|
5755
|
+
] : [],
|
|
5756
|
+
...plan.decisions.scim ? ['import { ScimController, wrapScim } from "../http/controllers/ScimController.ts";'] : [],
|
|
5757
|
+
...plan.layers.extras.billing ? [
|
|
5758
|
+
'import { BillingController } from "../http/controllers/BillingController.ts";',
|
|
5759
|
+
'import { APPLICATION_BILLING as STARTER_BILLING_OPTIONS_TOKEN } from "@getstrata/bootstrap/application";'
|
|
5760
|
+
] : []
|
|
5761
|
+
],
|
|
5762
|
+
web: [
|
|
5763
|
+
...plan.decisions.serverViews || plan.decisions.cookie ? ['import { CORE_VIEW_RENDERER_TOKEN } from "@getstrata/core/view";'] : [],
|
|
5764
|
+
...plan.decisions.serverViews ? ['import { HomeController } from "../http/controllers/HomeController.ts";'] : [],
|
|
5765
|
+
...plan.decisions.cookie ? [
|
|
5766
|
+
'import { AuthWebController } from "../http/controllers/AuthWebController.ts";',
|
|
5767
|
+
'import { STARTER_AUTH_SERVICES } from "../bootstrap/auth.ts";',
|
|
5768
|
+
'import { wrapWebLogin, wrapWebRegister } from "@getstrata/bootstrap/web/routing";'
|
|
5769
|
+
] : [],
|
|
5770
|
+
...plan.decisions.workTracker ? [
|
|
5771
|
+
'import { WorkTrackerController } from "../http/controllers/WorkTrackerController.ts";',
|
|
5772
|
+
'import { WORK_TRACKER_OUTBOX } from "../domain/workTracker.ts";'
|
|
5773
|
+
] : []
|
|
5774
|
+
]
|
|
5775
|
+
};
|
|
5776
|
+
for (const kind of ["api", "web"]) {
|
|
5777
|
+
const routes = features.flatMap((feature) => {
|
|
5778
|
+
const route = feature[kind];
|
|
5779
|
+
return route ? [route] : [];
|
|
5780
|
+
});
|
|
5781
|
+
files[`routes/${kind}.ts`] = `import type { AppRouteMap, ModuleRouteContext } from "@getstrata/bootstrap/contracts";
|
|
5782
|
+
import { composeRouteMaps } from "@getstrata/bootstrap/routePlan";
|
|
5783
|
+
${imports[kind].join(`
|
|
5784
|
+
`)}
|
|
5785
|
+
|
|
5786
|
+
${routes.map((route) => route.source).join(`
|
|
5787
|
+
`)}
|
|
5788
|
+
/** Register ${kind === "api" ? "API" : "browser"} endpoints and their middleware here. */
|
|
5789
|
+
export function ${kind}Routes(context: ModuleRouteContext): AppRouteMap {
|
|
5790
|
+
return composeRouteMaps(${routes.map((route) => `${route.name}(context)`).join(", ")});
|
|
5791
|
+
}
|
|
5792
|
+
`;
|
|
5793
|
+
}
|
|
5794
|
+
files["routes/index.ts"] = `import { buildApplicationRoutes } from "@getstrata/bootstrap/application";
|
|
5795
|
+
import type { AppDependencies, AppModule } from "@getstrata/bootstrap/contracts";
|
|
5796
|
+
import type { FrontendMode } from "@getstrata/core/runtime/frontendMode";
|
|
5797
|
+
import { apiRoutes } from "./api.ts";
|
|
5798
|
+
import { webRoutes } from "./web.ts";
|
|
5799
|
+
|
|
5800
|
+
/** App routes use the same kernel and middleware boundaries as optional modules. */
|
|
5801
|
+
export function applicationRoutes(dependencies: AppDependencies, modules: readonly AppModule[], options: { frontend: FrontendMode }) {
|
|
5802
|
+
return buildApplicationRoutes(dependencies, [
|
|
5803
|
+
...modules,
|
|
5804
|
+
{ name: "application", routes: apiRoutes, webRoutes },
|
|
5805
|
+
], options);
|
|
5806
|
+
}
|
|
5807
|
+
`;
|
|
5808
|
+
return files;
|
|
5809
|
+
}
|
|
5810
|
+
|
|
5811
|
+
// src/renderInitialAdmin.ts
|
|
5812
|
+
function renderInitialAdminMigration(plan) {
|
|
5813
|
+
if (!plan.decisions.users)
|
|
5814
|
+
return null;
|
|
5815
|
+
const driver = plan.decisions.sqlDriver;
|
|
5816
|
+
return `import { Schema } from "@getstrata/core/database/schema";
|
|
5817
|
+
import { guardMigrationRollback } from "@getstrata/core/database/migrations";
|
|
5818
|
+
import type { Migration } from "@getstrata/core/database/migrations/types";
|
|
5819
|
+
|
|
5820
|
+
const migration: Migration = {
|
|
5821
|
+
name: "0004_initial_admin_provisioning",
|
|
5822
|
+
async up(db) {
|
|
5823
|
+
await Schema.run(db, "${driver}", schema => {
|
|
5824
|
+
schema.create("initial_admin_provisioning", table => {
|
|
5825
|
+
table.integer("id").primary();
|
|
5826
|
+
table.text("email");
|
|
5827
|
+
table.timestamp("provisioned_at").defaultRaw("CURRENT_TIMESTAMP");
|
|
5828
|
+
});
|
|
5829
|
+
});
|
|
5830
|
+
},
|
|
5831
|
+
async down(db, context) {
|
|
5832
|
+
await guardMigrationRollback(context, {
|
|
5833
|
+
hasHistory: async () => (await db.unsafe("SELECT id FROM initial_admin_provisioning")).length > 0,
|
|
5834
|
+
message: "Cannot discard a completed initial-admin provisioning claim.",
|
|
5835
|
+
});
|
|
5836
|
+
await Schema.run(db, "${driver}", schema => { schema.drop("initial_admin_provisioning"); });
|
|
5837
|
+
},
|
|
5838
|
+
};
|
|
5839
|
+
export default migration;
|
|
5840
|
+
`;
|
|
5841
|
+
}
|
|
5842
|
+
function renderInitialAdminCommand(plan) {
|
|
5843
|
+
const layers = plan.layers;
|
|
5844
|
+
if (!plan.decisions.users)
|
|
5845
|
+
return null;
|
|
5846
|
+
const tenant = plan.decisions.tenantTable;
|
|
5847
|
+
const rls = plan.decisions.rls;
|
|
5848
|
+
const placeholder = layers.database === "postgres" ? "$1" : "?";
|
|
5849
|
+
const fields = ["name", "email", "password", "is_admin", ...tenant ? ["tenant_id"] : []];
|
|
5850
|
+
const placeholders = fields.map((_, index) => layers.database === "postgres" ? `$${index + 1}` : "?");
|
|
5851
|
+
return `import { runInitialAdminCommand } from "@getstrata/cli/initialAdmin";
|
|
5852
|
+
import { hashPassword } from "@getstrata/core/auth/password";
|
|
5853
|
+
import type { TransactionSession } from "@getstrata/core/database/session";
|
|
5854
|
+
${rls ? `import { assertRlsLiveDatabaseRole } from "@getstrata/bootstrap/secretsGuard";
|
|
5855
|
+
` : ""}import { bootstrapApp } from "../bootstrap/createApp.ts";
|
|
5856
|
+
|
|
5857
|
+
export async function initialAdminCommand(...args: string[]): Promise<void> {
|
|
5858
|
+
await runInitialAdminCommand(args, {
|
|
5859
|
+
tenantRequired: ${tenant},
|
|
5860
|
+
async provision(input) {
|
|
5861
|
+
// Hash before acquiring the database claim; only the official auth helper owns crypto.
|
|
5862
|
+
const passwordHash = await hashPassword(input.password);
|
|
5863
|
+
const app = await bootstrapApp({ migrate: false, mode: "command" });
|
|
5864
|
+
try {
|
|
5865
|
+
await app.invoke({ kind: "command", actor: { kind: "system", policy: "cli.initial-admin" } }, async ports => {
|
|
5866
|
+
${rls ? ` await assertRlsLiveDatabaseRole({ ...process.env }, async () => { const rows = await ports.database.execute<{rolname:string;rolsuper:boolean;rolbypassrls:boolean}>({text:"SELECT rolname, rolsuper, rolbypassrls FROM pg_roles WHERE rolname = current_user",params:[]});return rows[0] ?? null; });
|
|
5867
|
+
` : ""} const provision = async (db: TransactionSession) => {
|
|
5868
|
+
// The singleton primary key serializes bootstrap commands across all tenants/processes.
|
|
5869
|
+
await db.execute({text:"INSERT INTO initial_admin_provisioning (id, email) VALUES (1, ${placeholder})",params:[input.email]});
|
|
5870
|
+
if ((await db.execute({text:"SELECT id FROM users WHERE is_admin = ${layers.database === "postgres" ? "TRUE" : "1"} LIMIT 1",params:[]})).length) {
|
|
5871
|
+
throw new Error("An admin already exists.");
|
|
5872
|
+
}
|
|
5873
|
+
if ((await db.execute({text:"SELECT id FROM users WHERE LOWER(email) = ${placeholder}",params:[input.email]})).length) {
|
|
5874
|
+
throw new Error("The account already exists; provisioning never promotes accounts.");
|
|
5875
|
+
}
|
|
5876
|
+
${tenant ? ` if (!(await db.execute({text:"SELECT id FROM tenant WHERE id = ${placeholder}",params:[input.tenantId]})).length) {
|
|
5877
|
+
throw new Error("The tenant does not exist.");
|
|
5878
|
+
}
|
|
5879
|
+
` : ""} await db.execute({text:"INSERT INTO users (${fields.join(", ")}) VALUES (${placeholders.join(", ")})",params:[input.name, input.email, passwordHash, ${layers.database === "postgres" ? "true" : "1"}${tenant ? ", input.tenantId" : ""}]});
|
|
5880
|
+
// Verification and MFA stay unenrolled; normal application flows remain authoritative.
|
|
5881
|
+
};
|
|
5882
|
+
await ${rls ? 'ports.policy.run(ports.database, {kind:"bypass"}, provision)' : "ports.database.transaction(provision)"};
|
|
5883
|
+
});
|
|
5884
|
+
} finally {
|
|
5885
|
+
await app.context.dispose();
|
|
5886
|
+
}
|
|
5887
|
+
},
|
|
5888
|
+
});
|
|
5889
|
+
console.log("Initial admin provisioned. Complete email verification and MFA through the application.");
|
|
5890
|
+
}
|
|
5891
|
+
`;
|
|
5892
|
+
}
|
|
5893
|
+
|
|
5894
|
+
// src/renderModels.ts
|
|
5895
|
+
function renderModel(name, table, fields, fillable, hidden = []) {
|
|
5896
|
+
return `import { defineModel, field, type ModelAttributes } from "@getstrata/core/database/model";
|
|
5897
|
+
|
|
5898
|
+
class ${name} extends defineModel({
|
|
5899
|
+
table: "${table}",
|
|
5900
|
+
fields: {
|
|
5901
|
+
${Object.entries(fields).map(([column, type]) => ` ${column}: ${type},`).join(`
|
|
5902
|
+
`)}
|
|
5903
|
+
},
|
|
5904
|
+
defaultOrderBy: { column: "id", direction: "ASC" },
|
|
5905
|
+
}) {
|
|
5906
|
+
static $fillable = ${JSON.stringify(fillable)} as const;
|
|
5907
|
+
${hidden.length ? ` static $hidden = ${JSON.stringify(hidden)} as const;
|
|
5908
|
+
` : ""} // Timestamp columns use database defaults; no client timestamp is sent.
|
|
5909
|
+
static $timestamps = false;
|
|
5910
|
+
}
|
|
5911
|
+
|
|
5912
|
+
type ${name}Record = ModelAttributes<${name}>;
|
|
5913
|
+
export type { ${name}Record };
|
|
5914
|
+
export { ${name} };
|
|
5915
|
+
`;
|
|
5916
|
+
}
|
|
5917
|
+
function renderNoteModel(plan) {
|
|
5918
|
+
const tenant = plan.decisions.tenantTable;
|
|
5919
|
+
return renderModel("Note", "notes", {
|
|
5920
|
+
id: "field.number()",
|
|
5921
|
+
body: "field.string()",
|
|
5922
|
+
...tenant ? { tenant_id: "field.number()" } : {},
|
|
5923
|
+
created_at: "field.timestamp()"
|
|
5924
|
+
}, ["body", ...tenant ? ["tenant_id"] : []]);
|
|
5925
|
+
}
|
|
5926
|
+
function renderUserModel(plan) {
|
|
5927
|
+
const tenant = plan.decisions.schemaTenants;
|
|
5928
|
+
const mfa = plan.layers.extras.mfa;
|
|
5929
|
+
return renderModel("User", "users", {
|
|
5930
|
+
id: "field.number()",
|
|
5931
|
+
name: "field.string()",
|
|
5932
|
+
email: "field.string()",
|
|
5933
|
+
password: "field.string()",
|
|
5934
|
+
is_admin: "field.boolean()",
|
|
5935
|
+
is_active: "field.boolean()",
|
|
5936
|
+
auth_version: "field.number()",
|
|
5937
|
+
...tenant ? { tenant_id: "field.number()" } : {},
|
|
5938
|
+
...mfa ? {
|
|
5939
|
+
mfa_secret: "field.nullable(field.string())",
|
|
5940
|
+
mfa_enabled: "field.boolean()",
|
|
5941
|
+
mfa_recovery_codes: "field.nullable(field.string())"
|
|
5942
|
+
} : {},
|
|
5943
|
+
session_valid_after: "field.nullable(field.timestamp())",
|
|
5944
|
+
email_verified_at: "field.nullable(field.timestamp())",
|
|
5945
|
+
created_at: "field.timestamp()"
|
|
5946
|
+
}, [
|
|
5947
|
+
"name",
|
|
5948
|
+
"email",
|
|
5949
|
+
"password",
|
|
5950
|
+
"is_admin",
|
|
5951
|
+
"is_active",
|
|
5952
|
+
...tenant ? ["tenant_id"] : [],
|
|
5953
|
+
...mfa ? ["mfa_secret", "mfa_enabled", "mfa_recovery_codes"] : [],
|
|
5954
|
+
"session_valid_after",
|
|
5955
|
+
"email_verified_at"
|
|
5956
|
+
], ["password", ...mfa ? ["mfa_secret", "mfa_recovery_codes"] : []]);
|
|
5957
|
+
}
|
|
5958
|
+
function renderApiTokenModel() {
|
|
5959
|
+
return renderModel("ApiToken", "api_tokens", {
|
|
5960
|
+
id: "field.number()",
|
|
5961
|
+
user_id: "field.number()",
|
|
5962
|
+
name: "field.string()",
|
|
5963
|
+
token_hash: "field.string()",
|
|
5964
|
+
abilities: "field.string()",
|
|
5965
|
+
expires_at: "field.nullable(field.timestamp())",
|
|
5966
|
+
last_used_at: "field.nullable(field.timestamp())",
|
|
5967
|
+
created_at: "field.timestamp()"
|
|
5968
|
+
}, ["user_id", "name", "token_hash", "abilities", "expires_at", "last_used_at"]);
|
|
5969
|
+
}
|
|
5970
|
+
function renderAuthOneTimeTokenModel() {
|
|
5971
|
+
return renderModel("AuthOneTimeToken", "auth_one_time_tokens", {
|
|
5972
|
+
id: "field.number()",
|
|
5973
|
+
purpose: "field.string()",
|
|
5974
|
+
user_id: "field.number()",
|
|
5975
|
+
token_hash: "field.string()",
|
|
5976
|
+
expires_at: "field.timestamp()",
|
|
5977
|
+
consumed_at: "field.nullable(field.timestamp())"
|
|
5978
|
+
}, ["purpose", "user_id", "token_hash", "expires_at", "consumed_at"]);
|
|
5979
|
+
}
|
|
5980
|
+
function renderModelsRegister(plan) {
|
|
5981
|
+
const names = ["Note"];
|
|
5982
|
+
if (plan.decisions.users)
|
|
5983
|
+
names.push("User", "AuthOneTimeToken");
|
|
5984
|
+
if (plan.decisions.token)
|
|
5985
|
+
names.push("ApiToken");
|
|
5986
|
+
return `${names.map((name) => `import { ${name} } from "./${name}";`).join(`
|
|
5987
|
+
`)}
|
|
5988
|
+
|
|
5989
|
+
export const modelDefinitions = Object.freeze([${names.join(", ")}]);
|
|
5990
|
+
${plan.decisions.workTracker ? `
|
|
5991
|
+
// This optional domain example supplies custom data-access repositories.
|
|
5992
|
+
export { workTrackerRepositories as repositoryDefinitions } from "./workTracker.ts";
|
|
5993
|
+
` : ""}`;
|
|
5994
|
+
}
|
|
5690
5995
|
|
|
5691
5996
|
// src/generate.ts
|
|
5692
5997
|
var PROJECT_NAME_PATTERN = /^[a-z0-9][a-z0-9-_]*$/i;
|
|
@@ -5760,6 +6065,7 @@ export const TENANCY_ENABLED = ${decisions.tenantTable};
|
|
|
5760
6065
|
}
|
|
5761
6066
|
writeText(join2(targetDir, ".bun-version"), `1.4.4
|
|
5762
6067
|
`);
|
|
6068
|
+
writeText(join2(targetDir, "AGENTS.md"), renderAgentInstructions(projectName, plan));
|
|
5763
6069
|
writeText(join2(targetDir, ".env.example"), renderEnvExample(projectName, plan));
|
|
5764
6070
|
writeText(join2(targetDir, ".gitignore"), renderGitignore());
|
|
5765
6071
|
writeText(join2(targetDir, "package.json"), renderPackageJson(projectName, { ...options, plan }));
|
|
@@ -5857,28 +6163,17 @@ export const TENANCY_ENABLED = ${decisions.tenantTable};
|
|
|
5857
6163
|
writeText(join2(src, "db/seed.ts"), renderSeedTs());
|
|
5858
6164
|
writeText(join2(src, "db/status.ts"), renderStatusTs(plan));
|
|
5859
6165
|
writeText(join2(src, "db/rollback.ts"), renderRollbackTs(plan));
|
|
5860
|
-
|
|
5861
|
-
writeText(join2(src,
|
|
6166
|
+
for (const [path, source] of Object.entries(renderHttpFiles(plan))) {
|
|
6167
|
+
writeText(join2(src, path), source);
|
|
6168
|
+
}
|
|
5862
6169
|
const directory = renderAuthDirectory(plan);
|
|
5863
6170
|
if (directory) {
|
|
5864
6171
|
writeText(join2(src, "bootstrap/authDirectory.ts"), directory);
|
|
5865
6172
|
}
|
|
5866
|
-
const authModule = renderAuthModule(plan);
|
|
5867
|
-
if (authModule) {
|
|
5868
|
-
writeText(join2(src, "modules/auth/index.ts"), authModule);
|
|
5869
|
-
}
|
|
5870
|
-
const scimModule = renderScimModule(plan);
|
|
5871
|
-
if (scimModule) {
|
|
5872
|
-
writeText(join2(src, "modules/scim/index.ts"), scimModule);
|
|
5873
|
-
} else {
|
|
5874
|
-
removeIfExists(join2(src, "modules/scim/index.ts"));
|
|
5875
|
-
}
|
|
5876
6173
|
if (layers.extras.billing) {
|
|
5877
6174
|
writeText(join2(src, "billing/applyStripeWebhook.ts"), renderApplyStripeWebhook());
|
|
5878
|
-
writeText(join2(src, "modules/billing/index.ts"), renderBillingModule(plan));
|
|
5879
6175
|
} else {
|
|
5880
6176
|
removeIfExists(join2(src, "billing/applyStripeWebhook.ts"));
|
|
5881
|
-
removeIfExists(join2(src, "modules/billing/index.ts"));
|
|
5882
6177
|
}
|
|
5883
6178
|
if (layers.extras.webhooks) {
|
|
5884
6179
|
writeText(join2(src, "jobs/dispatchOutboundWebhookJob.ts"), renderDispatchOutboundWebhookJob(plan));
|
|
@@ -5933,7 +6228,6 @@ Open \`/work\` after signing in to the server app. See [the reference workflow](
|
|
|
5933
6228
|
`);
|
|
5934
6229
|
writeText(join2(src, "domain/workTracker.ts"), renderWorkTrackerDomain());
|
|
5935
6230
|
writeText(join2(src, "models/workTracker.ts"), renderWorkTrackerModels());
|
|
5936
|
-
writeText(join2(src, "modules/workTracker/index.ts"), renderWorkTrackerModule());
|
|
5937
6231
|
writeText(join2(src, "db/migrations/0007_work_tracker.ts"), renderWorkTrackerMigration(plan));
|
|
5938
6232
|
}
|
|
5939
6233
|
mkdirSync2(join2(targetDir, "storage"), { recursive: true });
|