@stratum-hq/create 0.4.0 → 0.5.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,28 @@
1
1
  # @stratum-hq/create
2
2
 
3
+ ## 0.5.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 4c1686a: Generated servers and Next.js middleware take the tenant from a verified JWT instead of the hostname (GHSA-p4wg-j8hh-9wh8).
8
+
9
+ ## 0.4.1
10
+
11
+ ### Patch Changes
12
+
13
+ - 7ac4283: `npx @stratum-hq/create <name>` now runs the scaffolder. Before this fix, the command exited 0 and did nothing when npm ran the bin through its `node_modules/.bin` symlink. The `create-stratum` bin is now `dist/bin.js`, which always calls `main()`.
14
+ - 7ac4283: Generated projects now depend on the current `@stratum-hq/*` releases. The CLI took the dependency ranges from a hardcoded `^0.2.0`, which installs releases from before 1.0. The build now reads the ranges from the workspace package versions.
15
+ - 7ac4283: Fix the database setup that the pg, knex and mongoose presets generate, so that it compiles and runs against the published packages.
16
+
17
+ - The PostgreSQL `pg` preset passes a tenant function to `createTenantPool`, which expects `() => string`.
18
+ - The PostgreSQL `knex` preset sets `app.current_tenant_id` with `set_config(..., true)` inside `knex.transaction`. PostgreSQL does not accept a bind parameter in `SET`, and the RLS policies read `app.current_tenant_id`.
19
+ - The `mongoose` presets no longer import `createTenantConnection`, which `@stratum-hq/mongodb` does not export. They use Mongoose directly, with the database and collection names of the `@stratum-hq/mongodb` adapters.
20
+ - The MySQL `pg` preset types its query parameters so that `pool.execute` accepts them.
21
+ - The generated README names the `app.current_tenant_id` setting.
22
+ - The RLS policy example in the generated `init.sql` uses `NULLIF(current_setting('app.current_tenant_id', true), '')::uuid`. A pooled connection reads the setting as an empty string after a tenant transaction ends, and the old example raised an error there instead of returning no rows.
23
+
24
+ - 7ac4283: Generated projects now run with the scripts they ship. The express and fastify templates now write a `tsconfig.json`, so `npm run build` compiles `src/` to `dist/` and `npm start` runs `dist/index.js`. The `dev` script of the templates and of every preset except Next.js and NestJS is now `tsx watch --env-file=.env src/<entry>.ts`, because Node 20 cannot run a `.ts` file. The NestJS preset `dev` script is now `tsc-watch --onSuccess "node --env-file=.env dist/main.js"`, because NestJS injection needs the decorator metadata that `tsc` emits. Before this fix, `dev` pointed at `src/index.js`, which the scaffold never wrote. Knex presets now compile from the project root, because `src/stratum-knex.ts` imports `knexfile.ts` from there. Their `start` script runs `dist/src/<entry>.js`. The generated README and the success message now tell you to run `npm run dev`.
25
+
3
26
  ## 0.4.0
4
27
 
5
28
  ### Minor Changes
package/README.md CHANGED
@@ -30,17 +30,22 @@ npx @stratum-hq/create my-app [options]
30
30
 
31
31
  - **express** (default) — Express server with Stratum middleware, tenant-aware routes, and TypeScript config.
32
32
  - **fastify** — Fastify server with the Stratum plugin registered.
33
- - **nextjs** — Next.js project with edge middleware for tenant resolution and server-side helpers.
33
+ - **nextjs** — Next.js project with edge middleware that resolves the tenant from a verified JWT.
34
34
 
35
35
  ## After Scaffolding
36
36
 
37
37
  ```bash
38
38
  cd my-app
39
39
  docker compose up -d # start PostgreSQL
40
+ cp .env.example .env # npm run dev reads .env
40
41
  npm run dev # run the app
41
42
  ```
42
43
 
43
- The generated project uses `autoMigrate: true`, so Stratum creates its tables automatically on first run — no separate migration step.
44
+ The generated starter code does not create a `Stratum` instance, so it does not create Stratum's tables. To create them, construct `Stratum` with `autoMigrate: true` and call `initialize()` once at startup.
45
+
46
+ ## Tenant resolution
47
+
48
+ Generated servers (the Express, Fastify, Hono and NestJS presets) and the Next.js middleware take the tenant ID only from the `tenant_id` claim of a bearer token that verifies with `JWT_SECRET` (HS256, using `jose`, which the generated `package.json` lists). A token that does not verify, or has no `tenant_id` claim, is rejected with 401. The tenant is never taken from the hostname or from a client-supplied header such as `x-tenant-id`. In the Next.js middleware the subdomain is forwarded as `x-tenant-slug`, a display hint that does not identify the caller's tenant.
44
49
 
45
50
  ## Links
46
51
 
package/dist/bin.js ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ import { main } from "./index.js";
3
+ main(process.argv.slice(2));