create-strata 2.2.0 → 2.2.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/dist/cli.js +114 -8
- package/dist/templates/package.json +3 -3
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -2927,9 +2927,11 @@ function renderEnvExample(projectName, layers) {
|
|
|
2927
2927
|
lines.push("# Scheduler coordination defaults to Redis in production, one process in development.");
|
|
2928
2928
|
lines.push("# SCHEDULER_COORDINATION=redis");
|
|
2929
2929
|
lines.push("APP_DEBUG=false");
|
|
2930
|
+
lines.push("TENANT_DEV_HEADERS=false");
|
|
2931
|
+
lines.push("# Development-only anonymous x-tenant-id selection; never enable in production.");
|
|
2930
2932
|
lines.push("FEATURE_PUBLIC_READS=false");
|
|
2931
2933
|
lines.push("# wrapWebPublicRead / wrapPublicRead require login when false (production-safe default).");
|
|
2932
|
-
lines.push("#
|
|
2934
|
+
lines.push("# Public reads do not enable tenant headers. Production guest tenancy requires CORE_PUBLIC_TENANCY_TOKEN.");
|
|
2933
2935
|
lines.push("FEATURE_SIEM_EXPORT=false");
|
|
2934
2936
|
lines.push("# SIEM_EXPORT_URL=");
|
|
2935
2937
|
lines.push("# SIEM_EXPORT_TOKEN=");
|
|
@@ -3195,9 +3197,9 @@ function renderPackageJson(projectName, options = {}) {
|
|
|
3195
3197
|
"@getstrata/cli": "workspace:*",
|
|
3196
3198
|
"@getstrata/core": "workspace:*"
|
|
3197
3199
|
} : {
|
|
3198
|
-
"@getstrata/bootstrap": "^2.2.
|
|
3199
|
-
"@getstrata/cli": "^2.2.
|
|
3200
|
-
"@getstrata/core": "^2.2.
|
|
3200
|
+
"@getstrata/bootstrap": "^2.2.1",
|
|
3201
|
+
"@getstrata/cli": "^2.2.1",
|
|
3202
|
+
"@getstrata/core": "^2.2.1"
|
|
3201
3203
|
};
|
|
3202
3204
|
coreDeps.eta = "^4.6.0";
|
|
3203
3205
|
if (options.layers?.database === "mysql") {
|
|
@@ -3477,6 +3479,8 @@ ${next.join(`
|
|
|
3477
3479
|
Open http://localhost:3000. Health check: \`GET /health\`. Redis worker: \`bun run queue:work\` (requires \`REDIS_URL\`).
|
|
3478
3480
|
|
|
3479
3481
|
${renderSupportingToolsReadme(layers)}${layers.auth !== "headers" ? `
|
|
3482
|
+
For the first production admin, apply migrations and run \`bunx strata auth:provision-admin --email operator@example.test --name "Initial Operator" --password-stdin${layers.tenancy !== "none" ? " --tenant 1" : ""} < /run/secrets/initial_admin_password\` before admitting traffic. Supply your own private secret-manager-mounted file, not a demo password. Passwords require at least 16 characters and at most 72 UTF-8 bytes. Tenant-enabled applications require an existing tenant ID; this command does not create tenants. It refuses existing admins/accounts, records a transactional one-time claim, and does not mark email verified or enroll MFA. Additional admins and recovery remain explicit application administration. The command does not migrate or seed automatically.
|
|
3483
|
+
|
|
3480
3484
|
Optional development demo accounts: run \`bun run db:seed:demo\` explicitly after migrations. This command refuses production and staging. It creates these accounts with password \`StrataDemo!ChangeMe\`:
|
|
3481
3485
|
|
|
3482
3486
|
- \`demo@example.com\` (member)
|
|
@@ -3535,7 +3539,7 @@ The image sets \`APP_ENV=production\` and \`AUTH_DEV_HEADERS=false\`; everything
|
|
|
3535
3539
|
- Replace every \`change-me\` placeholder in \`.env\`. The guard rejects the values this generator wrote, not just empty ones.
|
|
3536
3540
|
- Set \`APP_URL\` to the public origin (for example \`https://app.example.com\`). Signed links and redirects are built from it; localhost is rejected.
|
|
3537
3541
|
- Set \`AUTH_DEV_HEADERS=false\`.
|
|
3538
|
-
-
|
|
3542
|
+
- Generated \`FEATURE_PUBLIC_READS=false\` makes \`wrapWebPublicRead\` / \`wrapPublicRead\` require login by default. Opt in per route with \`{ allowAnonymous: true }\`, or set \`FEATURE_PUBLIC_READS=true\` as their default policy. With tenancy enabled, production guests require an application-approved host resolver bound to \`CORE_PUBLIC_TENANCY_TOKEN\`; unknown hosts fail closed. Keep \`TENANT_DEV_HEADERS=false\` in production. See the framework TENANCY guide for proxy trust and rollout.
|
|
3539
3543
|
- Add explicitly approved application headers with \`CORS_ADDITIONAL_ALLOWED_HEADERS=Idempotency-Key,X-Correlation-Id\`; this extends the defaults, validates header names and never reflects requested headers. OpenAPI metadata does not grant CORS access.
|
|
3540
3544
|
- Cross-origin browser calls are off in production until you set \`CORS_ALLOWED_ORIGINS\` to explicit origins. A \`*\` entry is rejected. Non-browser clients are unaffected.
|
|
3541
3545
|
- Behind a reverse proxy or load balancer, set \`TRUST_FORWARDED_FOR=true\` so throttles and session records see the client address instead of the proxy. Only the rightmost public hop of \`X-Forwarded-For\` is trusted.
|
|
@@ -3545,6 +3549,87 @@ ${authUsesCookie(layers.auth) ? "- Set `SESSION_SECRET` to 32+ characters.\n" :
|
|
|
3545
3549
|
`;
|
|
3546
3550
|
}
|
|
3547
3551
|
|
|
3552
|
+
// ../strata-starter/src/renderInitialAdmin.ts
|
|
3553
|
+
function renderInitialAdminMigration(layers) {
|
|
3554
|
+
if (!authNeedsUsers(layers.auth))
|
|
3555
|
+
return null;
|
|
3556
|
+
const driver = layers.database === "postgres" ? "pgsql" : layers.database;
|
|
3557
|
+
return `import { Schema } from "@getstrata/core/database/schema";
|
|
3558
|
+
import type { Migration } from "@getstrata/core/database/migrations/types";
|
|
3559
|
+
|
|
3560
|
+
const migration: Migration = {
|
|
3561
|
+
name: "0004_initial_admin_provisioning",
|
|
3562
|
+
async up(db) {
|
|
3563
|
+
await Schema.run(db, "${driver}", schema => {
|
|
3564
|
+
schema.create("initial_admin_provisioning", table => {
|
|
3565
|
+
table.integer("id").primary();
|
|
3566
|
+
table.text("email");
|
|
3567
|
+
table.timestamp("provisioned_at").defaultRaw("CURRENT_TIMESTAMP");
|
|
3568
|
+
});
|
|
3569
|
+
});
|
|
3570
|
+
},
|
|
3571
|
+
async down(db) {
|
|
3572
|
+
if ((await db.unsafe("SELECT id FROM initial_admin_provisioning")).length) {
|
|
3573
|
+
throw new Error("Cannot discard a completed initial-admin provisioning claim.");
|
|
3574
|
+
}
|
|
3575
|
+
await Schema.run(db, "${driver}", schema => { schema.drop("initial_admin_provisioning"); });
|
|
3576
|
+
},
|
|
3577
|
+
};
|
|
3578
|
+
export default migration;
|
|
3579
|
+
`;
|
|
3580
|
+
}
|
|
3581
|
+
function renderInitialAdminCommand(layers) {
|
|
3582
|
+
if (!authNeedsUsers(layers.auth))
|
|
3583
|
+
return null;
|
|
3584
|
+
const tenant = usesTenantTable(layers.tenancy);
|
|
3585
|
+
const rls = layers.tenancy === "rls";
|
|
3586
|
+
const placeholder = layers.database === "postgres" ? "$1" : "?";
|
|
3587
|
+
const fields = ["name", "email", "password", "is_admin", ...tenant ? ["tenant_id"] : []];
|
|
3588
|
+
const placeholders = fields.map((_, index) => layers.database === "postgres" ? `$${index + 1}` : "?");
|
|
3589
|
+
return `import { runInitialAdminCommand } from "@getstrata/cli/initialAdmin";
|
|
3590
|
+
import { hashPassword } from "@getstrata/core/auth/password";
|
|
3591
|
+
import { runInTransaction } from "@getstrata/core/database/transaction";
|
|
3592
|
+
${rls ? `import { runWithMigrationBypass } from "@getstrata/core/tenant/databaseTenantContext";
|
|
3593
|
+
import { isRlsTenancy } from "@getstrata/core/tenant/tenancyConfig";
|
|
3594
|
+
import { assertRlsLiveDatabaseRole } from "@getstrata/bootstrap/secretsGuard";
|
|
3595
|
+
` : ""}import { getSql, closeDatabase } from "../bootstrap/database.ts";
|
|
3596
|
+
|
|
3597
|
+
export async function initialAdminCommand(...args: string[]): Promise<void> {
|
|
3598
|
+
await runInitialAdminCommand(args, {
|
|
3599
|
+
tenantRequired: ${tenant},
|
|
3600
|
+
async provision(input) {
|
|
3601
|
+
// Hash before acquiring the database claim; only the official auth helper owns crypto.
|
|
3602
|
+
const passwordHash = await hashPassword(input.password);
|
|
3603
|
+
try {
|
|
3604
|
+
getSql();
|
|
3605
|
+
${rls ? ` if (!isRlsTenancy()) throw new Error("RLS configuration is required.");
|
|
3606
|
+
await assertRlsLiveDatabaseRole();
|
|
3607
|
+
` : ""} const provision = () => runInTransaction(async db => {
|
|
3608
|
+
// The singleton primary key serializes bootstrap commands across all tenants/processes.
|
|
3609
|
+
await db.unsafe("INSERT INTO initial_admin_provisioning (id, email) VALUES (1, ${placeholder})", [input.email]);
|
|
3610
|
+
if ((await db.unsafe("SELECT id FROM users WHERE is_admin = ${layers.database === "postgres" ? "TRUE" : "1"} LIMIT 1")).length) {
|
|
3611
|
+
throw new Error("An admin already exists.");
|
|
3612
|
+
}
|
|
3613
|
+
if ((await db.unsafe("SELECT id FROM users WHERE LOWER(email) = ${placeholder}", [input.email])).length) {
|
|
3614
|
+
throw new Error("The account already exists; provisioning never promotes accounts.");
|
|
3615
|
+
}
|
|
3616
|
+
${tenant ? ` if (!(await db.unsafe("SELECT id FROM tenant WHERE id = ${placeholder}", [input.tenantId])).length) {
|
|
3617
|
+
throw new Error("The tenant does not exist.");
|
|
3618
|
+
}
|
|
3619
|
+
` : ""} await db.unsafe("INSERT INTO users (${fields.join(", ")}) VALUES (${placeholders.join(", ")})", [input.name, input.email, passwordHash, ${layers.database === "postgres" ? "true" : "1"}${tenant ? ", input.tenantId" : ""}]);
|
|
3620
|
+
// Verification and MFA stay unenrolled; normal application flows remain authoritative.
|
|
3621
|
+
});
|
|
3622
|
+
await ${rls ? "runWithMigrationBypass(provision)" : "provision()"};
|
|
3623
|
+
} finally {
|
|
3624
|
+
await closeDatabase();
|
|
3625
|
+
}
|
|
3626
|
+
},
|
|
3627
|
+
});
|
|
3628
|
+
console.log("Initial admin provisioned. Complete email verification and MFA through the application.");
|
|
3629
|
+
}
|
|
3630
|
+
`;
|
|
3631
|
+
}
|
|
3632
|
+
|
|
3548
3633
|
// ../strata-starter/src/renderRuntime.ts
|
|
3549
3634
|
function needsEnsure(layers) {
|
|
3550
3635
|
return layers.database !== "sqlite";
|
|
@@ -3777,6 +3862,7 @@ function starterSchemaStatements(layers) {
|
|
|
3777
3862
|
statements.push(`CREATE TABLE IF NOT EXISTS failed_job (
|
|
3778
3863
|
id ${d.id},
|
|
3779
3864
|
job_name ${d.keyText} NOT NULL,
|
|
3865
|
+
job_id ${d.text},
|
|
3780
3866
|
payload ${payloadType},
|
|
3781
3867
|
exception ${d.text} NOT NULL,
|
|
3782
3868
|
failed_at ${d.timestamp}
|
|
@@ -4351,9 +4437,12 @@ function renderConfigProvider(layers) {
|
|
|
4351
4437
|
return `import {
|
|
4352
4438
|
APP_PORT_CONFIG_KEY,
|
|
4353
4439
|
CORE_CONFIG_TOKEN,
|
|
4440
|
+
CORE_PUBLIC_TENANCY_TOKEN,
|
|
4354
4441
|
DATABASE_URL_CONFIG_KEY,
|
|
4355
4442
|
REDIS_URL_CONFIG_KEY,
|
|
4356
4443
|
} from "@getstrata/bootstrap/config";
|
|
4444
|
+
import { isProductionEnv } from "@getstrata/core/runtime/appEnv";
|
|
4445
|
+
import { normalizeTenantHostname } from "@getstrata/core/tenant/tenantMiddleware";
|
|
4357
4446
|
import type { ServiceProvider } from "@getstrata/core/contracts/di";
|
|
4358
4447
|
import { loadConfig } from "../config.ts";
|
|
4359
4448
|
|
|
@@ -4363,6 +4452,13 @@ const configProvider: ServiceProvider = {
|
|
|
4363
4452
|
const appConfig = loadConfig();
|
|
4364
4453
|
|
|
4365
4454
|
container.set(CORE_CONFIG_TOKEN, config);
|
|
4455
|
+
// One approved origin for the starter tenant. Multi-tenant apps replace this lookup.
|
|
4456
|
+
if (isProductionEnv()) {
|
|
4457
|
+
const publicHost = normalizeTenantHostname(new URL(appConfig.appUrl).host);
|
|
4458
|
+
container.set(CORE_PUBLIC_TENANCY_TOKEN, {
|
|
4459
|
+
resolveTenantId: async (hostname) => hostname === publicHost ? 1 : null,
|
|
4460
|
+
});
|
|
4461
|
+
}
|
|
4366
4462
|
config.set(DATABASE_URL_CONFIG_KEY, appConfig.databaseUrl);
|
|
4367
4463
|
config.set(APP_PORT_CONFIG_KEY, appConfig.port);
|
|
4368
4464
|
config.set(REDIS_URL_CONFIG_KEY, process.env.REDIS_URL ?? "");
|
|
@@ -4658,10 +4754,11 @@ export function buildRoutes(dependencies: AppDependencies): AppRouteMap {
|
|
|
4658
4754
|
}
|
|
4659
4755
|
`;
|
|
4660
4756
|
}
|
|
4661
|
-
function renderCliRegisterTs() {
|
|
4757
|
+
function renderCliRegisterTs(layers) {
|
|
4662
4758
|
return `import type { StrataCommandMap } from "@getstrata/cli";
|
|
4663
4759
|
|
|
4664
|
-
const commands: StrataCommandMap = {
|
|
4760
|
+
const commands: StrataCommandMap = {${layers && authNeedsUsers(layers.auth) ? `
|
|
4761
|
+
"auth:provision-admin": async () => (await import("./initialAdmin.ts")).initialAdminCommand,` : ""}
|
|
4665
4762
|
"make:module": async () => (await import("@getstrata/cli/scaffold")).makeModuleCommand,
|
|
4666
4763
|
"make:policy": async () => (await import("@getstrata/cli/scaffold")).makePolicyCommand,
|
|
4667
4764
|
"make:job": async () => (await import("@getstrata/cli/scaffold")).makeJobCommand,
|
|
@@ -5546,7 +5643,16 @@ function writeGeneratedFiles(options) {
|
|
|
5546
5643
|
}
|
|
5547
5644
|
writeText(join2(src, "bootstrap/createApp.ts"), renderCreateAppTs(layers));
|
|
5548
5645
|
writeText(join2(src, "bootstrap/schedule.ts"), renderScheduleTs());
|
|
5549
|
-
writeText(join2(src, "cli/register.ts"), renderCliRegisterTs());
|
|
5646
|
+
writeText(join2(src, "cli/register.ts"), renderCliRegisterTs(layers));
|
|
5647
|
+
const initialAdminCommand = renderInitialAdminCommand(layers);
|
|
5648
|
+
const initialAdminMigration = renderInitialAdminMigration(layers);
|
|
5649
|
+
if (initialAdminCommand && initialAdminMigration) {
|
|
5650
|
+
writeText(join2(src, "cli/initialAdmin.ts"), initialAdminCommand);
|
|
5651
|
+
writeText(join2(src, "db/migrations/0004_initial_admin_provisioning.ts"), initialAdminMigration);
|
|
5652
|
+
} else {
|
|
5653
|
+
removeIfExists(join2(src, "cli/initialAdmin.ts"));
|
|
5654
|
+
removeIfExists(join2(src, "db/migrations/0004_initial_admin_provisioning.ts"));
|
|
5655
|
+
}
|
|
5550
5656
|
writeText(join2(src, "cli/queueWork.ts"), renderCliQueueWorkTs());
|
|
5551
5657
|
writeText(join2(src, "cli/queueFailed.ts"), renderCliQueueFailedTs());
|
|
5552
5658
|
writeText(join2(src, "cli/openapi.ts"), renderCliOpenApiTs());
|
|
@@ -12,9 +12,9 @@
|
|
|
12
12
|
"check": "tsc --noEmit"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@getstrata/bootstrap": "^2.2.
|
|
16
|
-
"@getstrata/cli": "^2.2.
|
|
17
|
-
"@getstrata/core": "^2.2.
|
|
15
|
+
"@getstrata/bootstrap": "^2.2.1",
|
|
16
|
+
"@getstrata/cli": "^2.2.1",
|
|
17
|
+
"@getstrata/core": "^2.2.1",
|
|
18
18
|
"eta": "^4.6.0"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|