create-strata 2.2.0 → 2.2.2
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 +116 -13
- 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.2",
|
|
3201
|
+
"@getstrata/cli": "^2.2.2",
|
|
3202
|
+
"@getstrata/core": "^2.2.2"
|
|
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";
|
|
@@ -3726,10 +3811,7 @@ import {
|
|
|
3726
3811
|
} from "@getstrata/core/database/defaultConnection";
|
|
3727
3812
|
import { useSqlDialect } from "@getstrata/core/database/dialect";
|
|
3728
3813
|
|
|
3729
|
-
export type SqlClient =
|
|
3730
|
-
unsafe<T>(query: string, params?: readonly unknown[]): Promise<T[]>;
|
|
3731
|
-
close?: () => Promise<void> | void;
|
|
3732
|
-
};
|
|
3814
|
+
export type SqlClient = SqlDatabaseConnection;
|
|
3733
3815
|
|
|
3734
3816
|
let sql: SqlClient | null = null;
|
|
3735
3817
|
|
|
@@ -3747,7 +3829,7 @@ export function getSql(): SqlClient {
|
|
|
3747
3829
|
const pool = createBunSqlPool({ url, max: 5 }) as SqlDatabaseConnection;
|
|
3748
3830
|
registerDefaultDatabasePool(pool);
|
|
3749
3831
|
bindDatabaseConnection(getDefaultDatabaseQuery());
|
|
3750
|
-
sql = getDefaultDatabaseQuery()
|
|
3832
|
+
sql = getDefaultDatabaseQuery();
|
|
3751
3833
|
return sql;
|
|
3752
3834
|
}
|
|
3753
3835
|
|
|
@@ -3777,6 +3859,7 @@ function starterSchemaStatements(layers) {
|
|
|
3777
3859
|
statements.push(`CREATE TABLE IF NOT EXISTS failed_job (
|
|
3778
3860
|
id ${d.id},
|
|
3779
3861
|
job_name ${d.keyText} NOT NULL,
|
|
3862
|
+
job_id ${d.text},
|
|
3780
3863
|
payload ${payloadType},
|
|
3781
3864
|
exception ${d.text} NOT NULL,
|
|
3782
3865
|
failed_at ${d.timestamp}
|
|
@@ -4351,9 +4434,12 @@ function renderConfigProvider(layers) {
|
|
|
4351
4434
|
return `import {
|
|
4352
4435
|
APP_PORT_CONFIG_KEY,
|
|
4353
4436
|
CORE_CONFIG_TOKEN,
|
|
4437
|
+
CORE_PUBLIC_TENANCY_TOKEN,
|
|
4354
4438
|
DATABASE_URL_CONFIG_KEY,
|
|
4355
4439
|
REDIS_URL_CONFIG_KEY,
|
|
4356
4440
|
} from "@getstrata/bootstrap/config";
|
|
4441
|
+
import { isProductionEnv } from "@getstrata/core/runtime/appEnv";
|
|
4442
|
+
import { normalizeTenantHostname } from "@getstrata/core/tenant/tenantMiddleware";
|
|
4357
4443
|
import type { ServiceProvider } from "@getstrata/core/contracts/di";
|
|
4358
4444
|
import { loadConfig } from "../config.ts";
|
|
4359
4445
|
|
|
@@ -4363,6 +4449,13 @@ const configProvider: ServiceProvider = {
|
|
|
4363
4449
|
const appConfig = loadConfig();
|
|
4364
4450
|
|
|
4365
4451
|
container.set(CORE_CONFIG_TOKEN, config);
|
|
4452
|
+
// One approved origin for the starter tenant. Multi-tenant apps replace this lookup.
|
|
4453
|
+
if (isProductionEnv()) {
|
|
4454
|
+
const publicHost = normalizeTenantHostname(new URL(appConfig.appUrl).host);
|
|
4455
|
+
container.set(CORE_PUBLIC_TENANCY_TOKEN, {
|
|
4456
|
+
resolveTenantId: async (hostname) => hostname === publicHost ? 1 : null,
|
|
4457
|
+
});
|
|
4458
|
+
}
|
|
4366
4459
|
config.set(DATABASE_URL_CONFIG_KEY, appConfig.databaseUrl);
|
|
4367
4460
|
config.set(APP_PORT_CONFIG_KEY, appConfig.port);
|
|
4368
4461
|
config.set(REDIS_URL_CONFIG_KEY, process.env.REDIS_URL ?? "");
|
|
@@ -4658,10 +4751,11 @@ export function buildRoutes(dependencies: AppDependencies): AppRouteMap {
|
|
|
4658
4751
|
}
|
|
4659
4752
|
`;
|
|
4660
4753
|
}
|
|
4661
|
-
function renderCliRegisterTs() {
|
|
4754
|
+
function renderCliRegisterTs(layers) {
|
|
4662
4755
|
return `import type { StrataCommandMap } from "@getstrata/cli";
|
|
4663
4756
|
|
|
4664
|
-
const commands: StrataCommandMap = {
|
|
4757
|
+
const commands: StrataCommandMap = {${layers && authNeedsUsers(layers.auth) ? `
|
|
4758
|
+
"auth:provision-admin": async () => (await import("./initialAdmin.ts")).initialAdminCommand,` : ""}
|
|
4665
4759
|
"make:module": async () => (await import("@getstrata/cli/scaffold")).makeModuleCommand,
|
|
4666
4760
|
"make:policy": async () => (await import("@getstrata/cli/scaffold")).makePolicyCommand,
|
|
4667
4761
|
"make:job": async () => (await import("@getstrata/cli/scaffold")).makeJobCommand,
|
|
@@ -5546,7 +5640,16 @@ function writeGeneratedFiles(options) {
|
|
|
5546
5640
|
}
|
|
5547
5641
|
writeText(join2(src, "bootstrap/createApp.ts"), renderCreateAppTs(layers));
|
|
5548
5642
|
writeText(join2(src, "bootstrap/schedule.ts"), renderScheduleTs());
|
|
5549
|
-
writeText(join2(src, "cli/register.ts"), renderCliRegisterTs());
|
|
5643
|
+
writeText(join2(src, "cli/register.ts"), renderCliRegisterTs(layers));
|
|
5644
|
+
const initialAdminCommand = renderInitialAdminCommand(layers);
|
|
5645
|
+
const initialAdminMigration = renderInitialAdminMigration(layers);
|
|
5646
|
+
if (initialAdminCommand && initialAdminMigration) {
|
|
5647
|
+
writeText(join2(src, "cli/initialAdmin.ts"), initialAdminCommand);
|
|
5648
|
+
writeText(join2(src, "db/migrations/0004_initial_admin_provisioning.ts"), initialAdminMigration);
|
|
5649
|
+
} else {
|
|
5650
|
+
removeIfExists(join2(src, "cli/initialAdmin.ts"));
|
|
5651
|
+
removeIfExists(join2(src, "db/migrations/0004_initial_admin_provisioning.ts"));
|
|
5652
|
+
}
|
|
5550
5653
|
writeText(join2(src, "cli/queueWork.ts"), renderCliQueueWorkTs());
|
|
5551
5654
|
writeText(join2(src, "cli/queueFailed.ts"), renderCliQueueFailedTs());
|
|
5552
5655
|
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.2",
|
|
16
|
+
"@getstrata/cli": "^2.2.2",
|
|
17
|
+
"@getstrata/core": "^2.2.2",
|
|
18
18
|
"eta": "^4.6.0"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|