@stratum-hq/create 0.5.0 → 0.6.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 +22 -0
- package/README.md +31 -7
- package/dist/index.js +270 -191
- package/package.json +17 -3
- package/src/generators/db-setup.ts +43 -1
- package/src/generators/init-sql.ts +56 -11
- package/src/generators/middleware.ts +50 -18
- package/src/generators/package-json.ts +24 -13
- package/src/generators/readme.ts +11 -8
- package/src/generators/tsconfig.ts +12 -6
- package/src/index.ts +58 -102
- package/src/matrix.ts +1 -1
- package/src/preset-project.ts +10 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# @stratum-hq/create
|
|
2
2
|
|
|
3
|
+
## 0.6.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 99437c5: The Next.js template and every Next.js preset now write the tenant middleware to `src/middleware.ts`, next to the `src/app` directory, so Next.js runs it. Previously it was written to the project root, where Next.js ignores it when the app lives in `src/app`, so the tenant JWT was not verified and a client-supplied `x-tenant-id` header reached server code. The generated app also gets the root layout (`src/app/layout.tsx`) that `next build` requires, and the Next.js presets get a `tsconfig.json` that `next build` accepts (bundler module resolution, no `rootDir`). If you generated a Next.js project with an earlier version, move `middleware.ts` to `src/middleware.ts`. See GHSA-mg93-96h7-h9fq.
|
|
8
|
+
- 99437c5: Generated PostgreSQL projects follow the hardened role model (GHSA-mg93-96h7-h9fq): `init.sql` creates the control role and a separate login for Stratum (`STRATUM_ADMIN_DATABASE_URL`, the library's `adminPool`), gives the application role no `CREATE` on `public`, and limits its default privileges to the tables the bootstrap superuser creates. Run the Stratum migrations as the Stratum login.
|
|
9
|
+
- 99437c5: Generated PostgreSQL projects name the bootstrap superuser URL `DATABASE_SUPERUSER_URL` (was `DATABASE_ADMIN_URL`, which the library uses for its admin login), and schema-per-tenant projects keep the schemas the app creates off the search path of the Stratum login and the superuser (GHSA-mg93-96h7-h9fq).
|
|
10
|
+
- 99437c5: The `express` and `fastify` templates now generate the tenant middleware the docs describe: the tenant comes from the `tenant_id` claim of a bearer token verified with `JWT_SECRET` (HS256, using `jose`, now a dependency of every template), and `GET /tenants` answers 401 without one. The servers are the same as the express and fastify presets write. The generated README no longer points these templates at a `src/middleware.ts` that does not exist.
|
|
11
|
+
|
|
12
|
+
The Drizzle presets now pin `drizzle-orm ^0.45.3` and `drizzle-kit ^0.31.11`, override the esbuild that drizzle-kit pulls in through `@esbuild-kit/core-utils` to `^0.25.4`, and generate the `src/schema.ts` that `drizzle.config.ts` points at. On PostgreSQL, `drizzle.config.ts` connects with `DATABASE_ADMIN_URL` when it is set.
|
|
13
|
+
|
|
14
|
+
Generated dependency ranges now start past published advisories: `fastify ^5.12.5` (was `^4.26.0`, a major upgrade), `express ^4.22.3`, `hono ^4.13.7`, `@hono/node-server ^1.19.15`, `@nestjs/core`, `@nestjs/common` and `@nestjs/platform-express ^11.1.18`, `mongoose ^8.24.1`, `mysql2 ^3.23.1`, and `tsx ^4.19.3`.
|
|
15
|
+
|
|
16
|
+
An invalid `--preset` now exits before anything is written, so it no longer leaves an empty project directory, and with `--force` it no longer removes the existing one.
|
|
17
|
+
|
|
18
|
+
## 0.5.1
|
|
19
|
+
|
|
20
|
+
### Patch Changes
|
|
21
|
+
|
|
22
|
+
- b737034: Improve the npm metadata so that npm search finds the packages. Each `description` now starts with the problem the package solves. Each package carries the same multi-tenancy keywords, including `multitenancy`. The `homepage` field now points at the package's page on https://docs.stratum-hq.org instead of a GitHub folder. The first lines of each README link the documentation. No code changes.
|
|
23
|
+
- a1bd9aa: Replace em dashes in user-visible text with ordinary punctuation. This touches READMEs, package descriptions, CLI output, control plane startup log messages, the text that `@stratum-hq/create` writes into generated projects, and the assertion messages in `@stratum-hq/test-utils`. The CLI `health` and `migrate` tables now print `no` instead of a dash for an unset flag. No behavior changes.
|
|
24
|
+
|
|
3
25
|
## 0.5.0
|
|
4
26
|
|
|
5
27
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# @stratum-hq/create
|
|
2
2
|
|
|
3
|
-
Scaffold a complete [Stratum](https://github.com/stratum-hq/Stratum) multi-tenancy project with one command
|
|
3
|
+
Scaffold a complete [Stratum](https://github.com/stratum-hq/Stratum) multi-tenancy project with one command: package.json, Docker Compose, environment files, and framework-specific starter code.
|
|
4
|
+
|
|
5
|
+
Read the documentation at [docs.stratum-hq.org/packages/create](https://docs.stratum-hq.org/packages/create/).
|
|
4
6
|
|
|
5
7
|
## Usage
|
|
6
8
|
|
|
@@ -10,10 +12,10 @@ npx @stratum-hq/create my-app
|
|
|
10
12
|
|
|
11
13
|
This creates a `my-app/` directory containing:
|
|
12
14
|
|
|
13
|
-
- `package.json` with `@stratum-hq/lib`, `pg`, and your chosen framework
|
|
15
|
+
- `package.json` with `@stratum-hq/lib`, `pg`, `jose`, and your chosen framework
|
|
14
16
|
- `docker-compose.yml` with PostgreSQL 16 and the `ltree` + `uuid-ossp` extensions pre-loaded
|
|
15
17
|
- `.env.example` with `DATABASE_URL` and other defaults
|
|
16
|
-
- A starter server
|
|
18
|
+
- A starter server with tenant middleware that takes the tenant from a verified JWT
|
|
17
19
|
- `README.md` with getting-started instructions
|
|
18
20
|
|
|
19
21
|
## Options
|
|
@@ -22,15 +24,37 @@ This creates a `my-app/` directory containing:
|
|
|
22
24
|
npx @stratum-hq/create my-app [options]
|
|
23
25
|
|
|
24
26
|
--template <name> express (default), fastify, or nextjs
|
|
27
|
+
--preset <preset> a full stack, {database}-{strategy}-{orm}-{framework}
|
|
25
28
|
--skip-install skip npm install after scaffolding
|
|
26
29
|
--force overwrite an existing directory
|
|
27
30
|
```
|
|
28
31
|
|
|
32
|
+
`--template` and `--preset` cannot be used together.
|
|
33
|
+
|
|
29
34
|
## Templates
|
|
30
35
|
|
|
31
|
-
- **express** (default)
|
|
32
|
-
- **fastify
|
|
33
|
-
- **nextjs
|
|
36
|
+
- **express** (default): Express server in `src/index.ts` with tenant middleware that resolves the tenant from a verified JWT, a tenant-aware `/tenants` route, and TypeScript config.
|
|
37
|
+
- **fastify**: Fastify server in `src/index.ts` with an `onRequest` hook that resolves the tenant from a verified JWT, a tenant-aware `/tenants` route, and TypeScript config.
|
|
38
|
+
- **nextjs**: Next.js project with edge middleware that resolves the tenant from a verified JWT.
|
|
39
|
+
|
|
40
|
+
## Presets
|
|
41
|
+
|
|
42
|
+
A preset picks the database, isolation strategy, ORM, and framework in one string:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
npx @stratum-hq/create my-app --preset postgres-rls-prisma-express
|
|
46
|
+
npx @stratum-hq/create my-app --preset postgres-schema-drizzle-fastify
|
|
47
|
+
npx @stratum-hq/create my-app --preset mongodb-database-mongoose-hono
|
|
48
|
+
npx @stratum-hq/create my-app --preset mysql-table-prefix-sequelize-nestjs
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
| Database | Strategies | ORMs |
|
|
52
|
+
|---|---|---|
|
|
53
|
+
| `postgres` | `rls`, `schema`, `database` | `prisma`, `drizzle`, `sequelize`, `knex`, `pg` |
|
|
54
|
+
| `mongodb` | `database`, `collection` | `mongoose` |
|
|
55
|
+
| `mysql` | `database`, `table-prefix` | `sequelize`, `knex`, `pg` |
|
|
56
|
+
|
|
57
|
+
Every database works with every framework: `express`, `fastify`, `nextjs`, `hono`, `nestjs`, or `none`. An invalid preset exits with an error before anything is written. The Drizzle presets write their table definitions to `src/schema.ts`, which `drizzle.config.ts` points at.
|
|
34
58
|
|
|
35
59
|
## After Scaffolding
|
|
36
60
|
|
|
@@ -45,7 +69,7 @@ The generated starter code does not create a `Stratum` instance, so it does not
|
|
|
45
69
|
|
|
46
70
|
## Tenant resolution
|
|
47
71
|
|
|
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.
|
|
72
|
+
Generated servers (the Express and Fastify templates, and 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.
|
|
49
73
|
|
|
50
74
|
## Links
|
|
51
75
|
|