create-strata 2.2.3 → 2.2.5
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 +60 -52
- package/dist/templates/package.json +3 -3
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -2096,42 +2096,17 @@ export default authModule;
|
|
|
2096
2096
|
}
|
|
2097
2097
|
function renderSiteModule(_layers) {
|
|
2098
2098
|
return `import type { AppModule } from "@getstrata/bootstrap/contracts";
|
|
2099
|
-
import {
|
|
2100
|
-
import { pingDatabase } from "../../bootstrap/database.ts";
|
|
2101
|
-
import { Note } from "../../models/Note.ts";
|
|
2102
|
-
import { plainText, renderPage } from "../../lib/view.ts";
|
|
2103
|
-
|
|
2104
|
-
async function schemaReady(): Promise<boolean> {
|
|
2105
|
-
try {
|
|
2106
|
-
await Note.query().limit(1).get();
|
|
2107
|
-
return true;
|
|
2108
|
-
} catch {
|
|
2109
|
-
return false;
|
|
2110
|
-
}
|
|
2111
|
-
}
|
|
2099
|
+
import { renderPage } from "../../lib/view.ts";
|
|
2112
2100
|
|
|
2113
2101
|
const siteModule: AppModule = {
|
|
2114
2102
|
name: "site",
|
|
2115
2103
|
order: 1,
|
|
2116
|
-
routes({ kernel }) {
|
|
2117
|
-
return {
|
|
2118
|
-
"/health": kernel.wrap("api", withErrorHandling(async () => {
|
|
2119
|
-
const ok = (await pingDatabase()) && (await schemaReady());
|
|
2120
|
-
return plainText(ok ? "ok" : "degraded", ok ? 200 : 503);
|
|
2121
|
-
})),
|
|
2122
|
-
};
|
|
2123
|
-
},
|
|
2124
2104
|
webRoutes({ kernel }) {
|
|
2125
2105
|
return {
|
|
2126
2106
|
"/": kernel.wrapWeb(async (request) =>
|
|
2127
2107
|
renderPage(
|
|
2128
2108
|
"home.eta",
|
|
2129
|
-
{
|
|
2130
|
-
layout: {
|
|
2131
|
-
title: "Welcome",
|
|
2132
|
-
description: "Welcome to your Strata app. Restyle views/home.eta and public/assets/site.css.",
|
|
2133
|
-
},
|
|
2134
|
-
},
|
|
2109
|
+
{ layout: { title: "Welcome", description: "Welcome to your Strata app. Restyle views/home.eta and public/assets/site.css." } },
|
|
2135
2110
|
request,
|
|
2136
2111
|
),
|
|
2137
2112
|
),
|
|
@@ -2882,7 +2857,9 @@ function postgresAppRoleEnvNotes(layers) {
|
|
|
2882
2857
|
}
|
|
2883
2858
|
return [
|
|
2884
2859
|
`# Runtime DATABASE_URL is ${GENERATED_POSTGRES_APP_ROLE} (NOSUPERUSER NOBYPASSRLS).`,
|
|
2885
|
-
"# MIGRATION_DATABASE_URL
|
|
2860
|
+
"# MIGRATION_DATABASE_URL belongs to the explicit migration/provisioning process, never HTTP/workers.",
|
|
2861
|
+
"# Production provisioning also requires STRATA_APP_PASSWORD matching the restricted role credential.",
|
|
2862
|
+
"# STRATA_APP_PASSWORD=",
|
|
2886
2863
|
"# db/ensure-postgres-app-role.sql is repeatable on an existing volume, not only docker-entrypoint-initdb.d.",
|
|
2887
2864
|
layers.tenancy === "rls" ? "# Production TENANCY_DRIVER=rls inspects pg_roles (rolsuper / rolbypassrls), not only the URL username." : "# This app is not TENANCY_DRIVER=rls; still do not point runtime traffic at the postgres superuser."
|
|
2888
2865
|
];
|
|
@@ -3165,7 +3142,7 @@ function renderDockerfile(layers) {
|
|
|
3165
3142
|
if (layers.database === "sqlite") {
|
|
3166
3143
|
lines.push("# SQLite lives in storage/; mount a volume there or the data dies with the container.", 'VOLUME ["/app/storage"]');
|
|
3167
3144
|
}
|
|
3168
|
-
lines.push(`HEALTHCHECK --interval=30s --timeout=3s --start-period=10s CMD ["bun", "-e", "fetch('http://127.0.0.1:' + process.env.PORT + '/health').then((r) => process.exit(r.ok ? 0 : 1), () => process.exit(1))"]`, 'CMD ["bun", "run", "start"]');
|
|
3145
|
+
lines.push("# Readiness: anonymous dependency/schema probe; use a separate process check for liveness.", `HEALTHCHECK --interval=30s --timeout=3s --start-period=10s CMD ["bun", "-e", "fetch('http://127.0.0.1:' + process.env.PORT + '/health').then((r) => process.exit(r.ok ? 0 : 1), () => process.exit(1))"]`, 'CMD ["bun", "run", "start"]');
|
|
3169
3146
|
return `${lines.join(`
|
|
3170
3147
|
`)}
|
|
3171
3148
|
`;
|
|
@@ -3197,9 +3174,9 @@ function renderPackageJson(projectName, options = {}) {
|
|
|
3197
3174
|
"@getstrata/cli": "workspace:*",
|
|
3198
3175
|
"@getstrata/core": "workspace:*"
|
|
3199
3176
|
} : {
|
|
3200
|
-
"@getstrata/bootstrap": "^2.2.
|
|
3201
|
-
"@getstrata/cli": "^2.2.
|
|
3202
|
-
"@getstrata/core": "^2.2.
|
|
3177
|
+
"@getstrata/bootstrap": "^2.2.5",
|
|
3178
|
+
"@getstrata/cli": "^2.2.5",
|
|
3179
|
+
"@getstrata/core": "^2.2.5"
|
|
3203
3180
|
};
|
|
3204
3181
|
coreDeps.eta = "^4.6.0";
|
|
3205
3182
|
if (options.layers?.database === "mysql") {
|
|
@@ -3301,7 +3278,7 @@ function renderSupportingToolsReadme(layers) {
|
|
|
3301
3278
|
}
|
|
3302
3279
|
function renderApiDocs(projectName, layers) {
|
|
3303
3280
|
const rows = ["| Method | Path | Notes |", "| --- | --- | --- |"];
|
|
3304
|
-
rows.push("| `GET` | `/health` | Plain text `ok` (200) when
|
|
3281
|
+
rows.push("| `GET` | `/health` | Plain text `ok` (200) when configured database/Redis checks succeed and `notes` is readable (zero rows is still 200). This infrastructure probe runs outside API auth/tenancy admission, never selects a tenant or bypasses RLS, and returns no rows. `degraded` (503) when a dependency or schema check fails. Docker HEALTHCHECK uses this path. |", '| `GET` | `/ready` | JSON from the framework: `{"status":"ready","checks":{"database":"ok","redis":"skipped"}}` (200) or `not_ready` (503). `redis` is `ok` or `error` when `REDIS_URL` is set and `skipped` otherwise. It does not check the schema, so use `/health` as the deploy gate. |');
|
|
3305
3282
|
rows.push("| `GET` | `/` | Welcome page. Restyle or replace it. |");
|
|
3306
3283
|
if (authUsesToken(layers.auth)) {
|
|
3307
3284
|
rows.push("| `POST` | `/api/v1/auth/login` | `{ email, password }` returns `{ token }`. Requires `GET /api/v1/auth/csrf` then `X-CSRF-Token`. |", "| `POST` | `/api/v1/auth/register` | Creates a user and returns a token. |", "| `GET` | `/api/v1/auth/me` | Requires `Authorization: Bearer <token>`. |");
|
|
@@ -3543,9 +3520,9 @@ The image sets \`APP_ENV=production\` and \`AUTH_DEV_HEADERS=false\`; everything
|
|
|
3543
3520
|
- 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.
|
|
3544
3521
|
- 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.
|
|
3545
3522
|
- 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.
|
|
3546
|
-
${authUsesCookie(layers.auth) ? "- Set `SESSION_SECRET` to 32+ characters.\n" : ""}${authUsesToken(layers.auth) ? "- Set `TOKEN_HASH_PEPPER`.\n" : ""}${layers.extras.scim ? "- Set `SCIM_BEARER_TOKEN`.\n" : ""}${layers.extras.metrics ? "- Set `METRICS_TOKEN`.\n" : ""}${layers.extras.oauthGithub ? "- Set `OAUTH_STATE_SECRET` and `GITHUB_CLIENT_ID` / `GITHUB_CLIENT_SECRET`.\n" : ""}${layers.extras.oidc ? "- Set `OAUTH_STATE_SECRET`, `OIDC_ISSUER`, `OIDC_CLIENT_ID`, and `OIDC_CLIENT_SECRET`. Loopback issuers work outside production; set `OIDC_ALLOW_PRIVATE=true` for other private IdPs.\n" : ""}${layers.extras.billing ? "- Set `STRIPE_WEBHOOK_SECRET` when `FEATURE_BILLING=true`.\n" : ""}${layers.tenancy === "rls" ? `- \`DATABASE_URL\` must be a \`NOBYPASSRLS\` role, not the \`postgres\` superuser. Generated apps create \`${GENERATED_POSTGRES_APP_ROLE}\` via \`db/ensure-postgres-app-role.sql\` (and Compose init on first empty volume). \`MIGRATION_DATABASE_URL\`
|
|
3523
|
+
${authUsesCookie(layers.auth) ? "- Set `SESSION_SECRET` to 32+ characters.\n" : ""}${authUsesToken(layers.auth) ? "- Set `TOKEN_HASH_PEPPER`.\n" : ""}${layers.extras.scim ? "- Set `SCIM_BEARER_TOKEN`.\n" : ""}${layers.extras.metrics ? "- Set `METRICS_TOKEN`.\n" : ""}${layers.extras.oauthGithub ? "- Set `OAUTH_STATE_SECRET` and `GITHUB_CLIENT_ID` / `GITHUB_CLIENT_SECRET`.\n" : ""}${layers.extras.oidc ? "- Set `OAUTH_STATE_SECRET`, `OIDC_ISSUER`, `OIDC_CLIENT_ID`, and `OIDC_CLIENT_SECRET`. Loopback issuers work outside production; set `OIDC_ALLOW_PRIVATE=true` for other private IdPs.\n" : ""}${layers.extras.billing ? "- Set `STRIPE_WEBHOOK_SECRET` when `FEATURE_BILLING=true`.\n" : ""}${layers.tenancy === "rls" ? `- \`DATABASE_URL\` must be a \`NOBYPASSRLS\` role, not the \`postgres\` superuser. Generated apps create \`${GENERATED_POSTGRES_APP_ROLE}\` via \`db/ensure-postgres-app-role.sql\` (and Compose init on first empty volume). \`MIGRATION_DATABASE_URL\` and an explicit non-development \`STRATA_APP_PASSWORD\` belong only to the migrate/provisioning process. HTTP/workers connect to the existing role without admin credentials or role/password writes. Production boot rejects username \`postgres\` or \`root\`, then inspects \`pg_roles\` for \`rolsuper\` / \`rolbypassrls\`.
|
|
3547
3524
|
` : ""}
|
|
3548
|
-
\`strata start\` does not migrate when \`APP_ENV=production\`. Run \`bun run db:migrate\` as a deploy step. \`GET /health\` is 200 when \`notes\` is readable (including zero rows) and 503 when
|
|
3525
|
+
\`strata start\` does not migrate when \`APP_ENV=production\`. Run \`bun run db:migrate\` as a deploy step. \`GET /health\` is 200 when \`notes\` is readable (including zero rows) and configured dependencies are available; it returns only \`ok\` or \`degraded\` without authentication or tenant selection, and 503 when a dependency or schema check fails. Use it for readiness, not process liveness. Redis jobs need a worker: \`bun run queue:work\` (requires \`REDIS_URL\`).
|
|
3549
3526
|
`;
|
|
3550
3527
|
}
|
|
3551
3528
|
|
|
@@ -3638,8 +3615,8 @@ function ensureImport(layers) {
|
|
|
3638
3615
|
return needsEnsure(layers) ? `import { ensureAppDatabase } from "../bootstrap/ensureDatabase.ts";
|
|
3639
3616
|
` : "";
|
|
3640
3617
|
}
|
|
3641
|
-
function ensureCall(layers) {
|
|
3642
|
-
return needsEnsure(layers) ? ` await ensureAppDatabase();
|
|
3618
|
+
function ensureCall(layers, provision = true) {
|
|
3619
|
+
return needsEnsure(layers) ? ` await ensureAppDatabase({ provision: ${provision} });
|
|
3643
3620
|
` : "";
|
|
3644
3621
|
}
|
|
3645
3622
|
function dialectFragments(database) {
|
|
@@ -4339,7 +4316,7 @@ function renderStatusTs(layers) {
|
|
|
4339
4316
|
import { loadStarterMigrations, withMigrationDatabase } from "./migrationRuntime.ts";
|
|
4340
4317
|
|
|
4341
4318
|
export async function status() {
|
|
4342
|
-
${ensureCall(layers)} const rows = await withMigrationDatabase(async (db) => {
|
|
4319
|
+
${ensureCall(layers, false)} const rows = await withMigrationDatabase(async (db) => {
|
|
4343
4320
|
return getMigrationStatus(db, await loadStarterMigrations());
|
|
4344
4321
|
});
|
|
4345
4322
|
console.log("Migrations:");
|
|
@@ -4360,7 +4337,7 @@ function renderRollbackTs(layers) {
|
|
|
4360
4337
|
import { loadStarterMigrations, withMigrationDatabase } from "./migrationRuntime.ts";
|
|
4361
4338
|
|
|
4362
4339
|
export async function rollback() {
|
|
4363
|
-
${ensureCall(layers)} const rolledBack = await withMigrationDatabase(async (db) => {
|
|
4340
|
+
${ensureCall(layers, false)} const rolledBack = await withMigrationDatabase(async (db) => {
|
|
4364
4341
|
return rollbackDatabase(db, await loadStarterMigrations(), {
|
|
4365
4342
|
onMigration: (name) => {
|
|
4366
4343
|
console.log(\`rolled back \${name}\`);
|
|
@@ -4384,12 +4361,18 @@ function renderPreloadTs(layers, projectName) {
|
|
|
4384
4361
|
const migrationFallback = defaultMigrationDatabaseUrl(layers, projectName);
|
|
4385
4362
|
const migrationLine = migrationFallback ? `process.env.MIGRATION_DATABASE_URL ??= ${JSON.stringify(migrationFallback)};
|
|
4386
4363
|
` : "";
|
|
4364
|
+
const databaseDefaults = needsEnsure(layers) ? `if (!isProductionEnv()) {
|
|
4365
|
+
process.env.DATABASE_URL ??= ${JSON.stringify(fallback)};
|
|
4366
|
+
${migrationLine.trim()}
|
|
4367
|
+
}
|
|
4368
|
+
` : `process.env.DATABASE_URL ??= ${JSON.stringify(fallback)};
|
|
4369
|
+
`;
|
|
4387
4370
|
return `import { join } from "node:path";
|
|
4388
4371
|
import { configureModulesDirectory } from "@getstrata/bootstrap/discoverModules";
|
|
4389
|
-
import "
|
|
4372
|
+
${needsEnsure(layers) ? `import { isProductionEnv } from "@getstrata/core/runtime/appEnv";
|
|
4373
|
+
` : ""}import "../models/register.ts";
|
|
4390
4374
|
|
|
4391
|
-
process.env.
|
|
4392
|
-
${migrationLine}process.env.FRONTEND_MODE ??= ${JSON.stringify(layers.frontend)};
|
|
4375
|
+
${databaseDefaults}process.env.FRONTEND_MODE ??= ${JSON.stringify(layers.frontend)};
|
|
4393
4376
|
process.env.SPA_PREFIX ??= ${JSON.stringify(layers.spaPrefix)};
|
|
4394
4377
|
process.env.CACHE_DRIVER ??= ${JSON.stringify(layers.cache)};
|
|
4395
4378
|
process.env.QUEUE_DRIVER ??= ${JSON.stringify(layers.queue)};
|
|
@@ -4512,7 +4495,10 @@ function resolveAppDatabaseUrl(): string {
|
|
|
4512
4495
|
if (explicit) {
|
|
4513
4496
|
return explicit;
|
|
4514
4497
|
}
|
|
4515
|
-
|
|
4498
|
+
const configured = process.env.DATABASE_URL?.trim();
|
|
4499
|
+
if (configured) return configured;
|
|
4500
|
+
if (isProductionEnv()) throw new Error("DATABASE_URL or APP_DATABASE_URL is required in production/staging.");
|
|
4501
|
+
return DEFAULT_DATABASE_URL;
|
|
4516
4502
|
}
|
|
4517
4503
|
`;
|
|
4518
4504
|
const safeName = `/** Reject anything we would have to quote before interpolating into DDL. */
|
|
@@ -4534,12 +4520,17 @@ function safeDatabaseName(url: string): string {
|
|
|
4534
4520
|
`;
|
|
4535
4521
|
if (layers.database === "mysql") {
|
|
4536
4522
|
return `import { createConnection } from "mysql2/promise";
|
|
4523
|
+
import { isProductionEnv } from "@getstrata/core/runtime/appEnv";
|
|
4537
4524
|
|
|
4538
4525
|
const DEFAULT_DATABASE_URL = ${JSON.stringify(fallback)};
|
|
4539
4526
|
|
|
4540
4527
|
${resolveUrl}${safeName}
|
|
4541
|
-
export async function ensureAppDatabase(): Promise<string> {
|
|
4528
|
+
export async function ensureAppDatabase(options: { provision?: boolean } = {}): Promise<string> {
|
|
4542
4529
|
const url = resolveAppDatabaseUrl();
|
|
4530
|
+
if (!(options.provision ?? !isProductionEnv())) {
|
|
4531
|
+
process.env.DATABASE_URL = url;
|
|
4532
|
+
return url;
|
|
4533
|
+
}
|
|
4543
4534
|
const name = safeDatabaseName(url);
|
|
4544
4535
|
|
|
4545
4536
|
const admin = new URL(url);
|
|
@@ -4560,17 +4551,25 @@ export async function ensureAppDatabase(): Promise<string> {
|
|
|
4560
4551
|
ensurePostgresDatabaseAndAppRole,
|
|
4561
4552
|
POSTGRES_APP_ROLE_PASSWORD,
|
|
4562
4553
|
} from "@getstrata/core/tenant/enableTenantRls";
|
|
4554
|
+
import { isProductionEnv } from "@getstrata/core/runtime/appEnv";
|
|
4563
4555
|
|
|
4564
4556
|
const DEFAULT_DATABASE_URL = ${JSON.stringify(fallback)};
|
|
4565
4557
|
|
|
4566
4558
|
${resolveUrl}
|
|
4567
|
-
export async function ensureAppDatabase(): Promise<string> {
|
|
4559
|
+
export async function ensureAppDatabase(options: { provision?: boolean } = {}): Promise<string> {
|
|
4568
4560
|
const url = resolveAppDatabaseUrl();
|
|
4569
|
-
|
|
4570
|
-
|
|
4571
|
-
|
|
4572
|
-
|
|
4573
|
-
|
|
4561
|
+
if (options.provision ?? !isProductionEnv()) {
|
|
4562
|
+
if (isProductionEnv()) {
|
|
4563
|
+
if (!process.env.MIGRATION_DATABASE_URL?.trim()) throw new Error("MIGRATION_DATABASE_URL is required for production/staging provisioning.");
|
|
4564
|
+
const password = process.env.STRATA_APP_PASSWORD?.trim();
|
|
4565
|
+
if (!password || password === POSTGRES_APP_ROLE_PASSWORD) throw new Error("Set an explicit non-development STRATA_APP_PASSWORD for production/staging provisioning.");
|
|
4566
|
+
}
|
|
4567
|
+
await ensurePostgresDatabaseAndAppRole({
|
|
4568
|
+
runtimeUrl: url,
|
|
4569
|
+
migrationUrl: process.env.MIGRATION_DATABASE_URL,
|
|
4570
|
+
password: process.env.STRATA_APP_PASSWORD ?? POSTGRES_APP_ROLE_PASSWORD,
|
|
4571
|
+
});
|
|
4572
|
+
}
|
|
4574
4573
|
process.env.DATABASE_URL = url;
|
|
4575
4574
|
return url;
|
|
4576
4575
|
}
|
|
@@ -4656,6 +4655,7 @@ import { isProductionEnv } from "@getstrata/core/runtime/appEnv";
|
|
|
4656
4655
|
import { isRlsTenancy } from "@getstrata/core/tenant/tenancyConfig";
|
|
4657
4656
|
import { migrate } from "../db/migrate.ts";
|
|
4658
4657
|
import { buildRoutes } from "../routes.ts";
|
|
4658
|
+
import { Note } from "../models/Note.ts";
|
|
4659
4659
|
import { loadConfig } from "./config.ts";
|
|
4660
4660
|
import { closeDatabase, getSql, pingDatabase } from "./database.ts";
|
|
4661
4661
|
${ensureLine}import { starterProviders } from "./providers/index.ts";
|
|
@@ -4688,7 +4688,7 @@ export async function bootstrapApp(options: BootstrapOptions = {}): Promise<Boot
|
|
|
4688
4688
|
assertProductionSecrets();
|
|
4689
4689
|
}
|
|
4690
4690
|
|
|
4691
|
-
${needsEnsure(layers) ? ` await ensureAppDatabase();
|
|
4691
|
+
${needsEnsure(layers) ? ` await ensureAppDatabase({ provision: !isProduction });
|
|
4692
4692
|
` : ""} const appConfig = loadConfig();
|
|
4693
4693
|
getSql();
|
|
4694
4694
|
if (!(await pingDatabase())) throw new Error("Database is not ready.");
|
|
@@ -4704,7 +4704,15 @@ ${needsEnsure(layers) ? ` await ensureAppDatabase();
|
|
|
4704
4704
|
}
|
|
4705
4705
|
|
|
4706
4706
|
const routes = mergeSpaRoutes(context.dependencies, {
|
|
4707
|
-
...createHealthRoutes(context.dependencies
|
|
4707
|
+
...createHealthRoutes(context.dependencies, {
|
|
4708
|
+
pingOnHealth: true,
|
|
4709
|
+
healthFormat: "text",
|
|
4710
|
+
schemaCheck: async () => {
|
|
4711
|
+
// Infrastructure probe: no tenant selection, bypass, user data or writes.
|
|
4712
|
+
try { await Note.query().limit(1).select("id").get(); return true; }
|
|
4713
|
+
catch { return false; }
|
|
4714
|
+
},
|
|
4715
|
+
}),
|
|
4708
4716
|
...buildRoutes(context.dependencies),${metricsSpread}
|
|
4709
4717
|
}, {
|
|
4710
4718
|
distDirectory: join(import.meta.dir, "../../frontend/dist"),
|
|
@@ -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.5",
|
|
16
|
+
"@getstrata/cli": "^2.2.5",
|
|
17
|
+
"@getstrata/core": "^2.2.5",
|
|
18
18
|
"eta": "^4.6.0"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|