@decohere/create 0.0.1-dev.97 → 0.0.1-dev.99

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.
Files changed (2) hide show
  1. package/README.md +253 -0
  2. package/package.json +1 -1
package/README.md ADDED
@@ -0,0 +1,253 @@
1
+ # @decohere/create
2
+
3
+ Scaffold a new Decohere project — built with Forge, served with Flux.
4
+
5
+ Docker is required on the host. `@decohere/create` only pulls `ghcr.io/typesmiths/decohere/create` and runs `@decohere/scaffold` inside it (including the Auth0 CLI). It does not install the scaffolder libraries on the host.
6
+
7
+ ## Usage
8
+
9
+ `npm create` already says “create”, so the first token is the kind (`webapi`), not `create` again. The launcher forwards `decohere create webapi …` into the builder image.
10
+
11
+ This run prompts for database, auth, Postman, and whether to install:
12
+
13
+ ```bash
14
+ npm create @decohere@dev webapi -d my-app
15
+ # or
16
+ npx @decohere/create@dev webapi -d my-app
17
+ # or, once `@decohere/cli` is installed:
18
+ decohere create webapi -d my-app
19
+ ```
20
+
21
+ To skip prompts, pass every answer up front (`-y` means “install deps, don’t ask”):
22
+
23
+ ```bash
24
+ npm create @decohere@dev -- webapi -d my-app --database postgres/typeorm --auth none --postman local -y
25
+ ```
26
+
27
+ Target directory is `webapi`'s optional argument or `-d` (default `.`). `npm create` treats `-d` as its own loglevel flag and forwards `my-app` as a positional — that form is supported. Extra create flags still need `--` after `npm create`.
28
+
29
+ The first token after the package must be a command (`webapi`); a bare directory name is an unknown command.
30
+
31
+ The scaffolded Dev Container asks **y/N** (TTY only) before npm auth and optional codebase RAG MCP (semantic search). Decline or run without a TTY to skip. Credentials are written under the project `.cursor/` directory (gitignored).
32
+
33
+ ## Commands
34
+
35
+ ### `webapi`
36
+
37
+ Scaffolds a full web API using Cortex (DI), Protocol (HTTP), and Scribe (logging), plus a Dev Container workspace.
38
+
39
+ ```bash
40
+ npx @decohere/create webapi -d my-app
41
+ npx @decohere/create webapi -d my-app --name billing
42
+ npx @decohere/create webapi -d my-app --name api --name billing
43
+ ```
44
+
45
+ Generated structure (default `--name api`):
46
+
47
+ ```
48
+ my-app/
49
+ package.json # build / start / start:<name> / dev
50
+ Dockerfile # first API (PaaS default: docker build .)
51
+ Dockerfile.billing # extra APIs: docker build -f Dockerfile.billing .
52
+ .dockerignore
53
+ .github/
54
+ actions/setup-node-pnpm/
55
+ workflows/
56
+ ci.yml # lint ∥ test (+ build on default branch)
57
+ publish.yml # forge publish (skips private); no docker push by default
58
+ tsconfig.json
59
+ biome.json
60
+ .env
61
+ config/
62
+ config.yaml
63
+ config.dev.yaml
64
+ .devcontainer/
65
+ projects/
66
+ api/ # or projects/<name> when --name is set
67
+ package.json # private: true (app, not an npm package)
68
+ src/
69
+ main.ts
70
+ sample.config.ts
71
+ sample.service.ts
72
+ controllers/
73
+ hello.controller.ts
74
+ ```
75
+
76
+ `Dockerfile.<name>` is only written for extra APIs or a custom `--name` (a single default `api` still uses root `Dockerfile` only).
77
+
78
+ The app Dev Container is a thin `FROM ghcr.io/typesmiths/decohere/devcontainer:<version>` (pinned to the scaffolder version). Shared layers (bash history, pnpm, `gh`, js-debug bootloader fix) update via `docker pull` / Dev Container rebuild — Compose mounts and lifecycle scripts stay in the app repo. Rebuild with pull after upgrading `@decohere/create`.
79
+
80
+ #### Scripts
81
+
82
+ | Script | Command | When |
83
+ |---|---|---|
84
+ | `build` | `forge build --configuration release` | CI, Docker, Nixpacks |
85
+ | `start` | `node dist/release/projects/<first>/es6/src/main.js` | Production default API (`pnpm start` / root Dockerfile) |
86
+ | `start:<name>` | same path for that API | Deploy that API (`pnpm run start:billing`) |
87
+ | `dev` | `flux serve --env-file-if-exists .env` (plus `--project @<app>/<first>` when named) | Local HMR for the first API; loads `.env` if present |
88
+ | `dev:<name>` | `PORT=<3000+n> flux serve --env-file-if-exists .env --project @<app>/<name>` | Local HMR for that API |
89
+ | `lint:check` / `typecheck` / `test` | biome / forge typecheck / vitest | CI |
90
+
91
+ #### Multiple APIs / add later
92
+
93
+ ```bash
94
+ decohere add api billing
95
+ # empty machine / npm create still maps `webapi add`:
96
+ npx @decohere/create webapi add billing -d my-app
97
+ ```
98
+
99
+ Adds `projects/billing`, `start:billing` / `dev:billing`, and `Dockerfile.billing`. Does not rewrite the first API, root `Dockerfile`, or workspace files like `biome.json`.
100
+
101
+ Each API is a separate deploy: point a PaaS service at `Dockerfile.<name>` with **repo-root** build context (`docker build -f Dockerfile.billing .`), or set the start command to `pnpm run start:billing`. Workspace `config/` is shared; each API still has its own named datasource and `{PREFIX}_DB_*` env (host/port default to the Compose Postgres).
102
+
103
+ ### `auth0`
104
+
105
+ The Auth0 CLI lives in the create image. Host tokens are stored in `~/.config/auth0` (always bind-mounted). Use this after a project exists, when a token expires, or when the Postman SPA needs to be created/updated.
106
+
107
+ ```bash
108
+ # Device/URL login — open the printed URL in your browser
109
+ npx @decohere/create auth0 login
110
+
111
+ # Update the Auth0 API + Postman SPA for this workspace (run from the project, or pass -d)
112
+ npx @decohere/create auth0 configure
113
+ npx @decohere/create auth0 configure -d my-app
114
+
115
+ # Same commands once `@decohere/cli` is installed:
116
+ decohere auth0 login
117
+ decohere auth0 configure
118
+ ```
119
+
120
+ `configure` does **not** rewrite application source. It scans `projects/*/src` for `@Authorize("action", "Subject")`, adds those permissions to the Auth0 API (keeping any already on the API), assigns them to `AUTH0_ADMIN_USER_SUB` when set, and updates Postman token `scope`.
121
+
122
+ #### Keep Auth0 in sync with controllers
123
+
124
+ `@Authorize("read", "Invoice")` becomes Auth0 API permission `read:Invoice`. After adding a controller:
125
+
126
+ ```bash
127
+ npx @decohere/create auth0 configure
128
+ ```
129
+
130
+ Then in Postman, Authorization → Get New Access Token so the token includes the new permissions.
131
+
132
+ #### Deploy (Railway / Fly / Nixpacks)
133
+
134
+ Hosts clone git and build themselves — they do **not** receive GitHub Actions `dist/` artifacts.
135
+
136
+ 1. **Dockerfile (preferred):** connect the repo; the host runs `docker build`. The scaffolded Dockerfile compiles with a full `pnpm install` + `pnpm run build`, then installs **production-only** `node_modules` (`pnpm install --prod`) into the runtime image so Forge, TypeScript, Biome, and Vitest are not shipped. `pnpm start` runs the compiled API.
137
+ 2. **Nixpacks (no Dockerfile):** same conventional `build` / `start` scripts — install → build → start.
138
+
139
+ Private `@decohere/*` packages need npm auth during image build (`NODE_AUTH_TOKEN` build-arg or BuildKit secret `npm_token`). Commit `pnpm-lock.yaml` after the first install.
140
+
141
+ **Registry push (optional):** CI does not run `forge docker --push` by default. For Cloud Run / K8s, add that step to `publish.yml` after configuring GHCR.
142
+
143
+ **Conventions:** `"private": true` → skip npm publish; presence of a Dockerfile → dockerizable; non-private packages under `projects/` → `forge publish`.
144
+
145
+ #### Database (`--database`)
146
+
147
+ | Value | Effect |
148
+ |---|---|
149
+ | `none` | No database |
150
+ | `postgres/typeorm` | One Compose Postgres **instance**; each API owns a named database + `{PREFIX}_DB_*` env |
151
+
152
+ ```bash
153
+ npx @decohere/create webapi -d my-app --database postgres/typeorm
154
+ npx @decohere/create webapi -d my-app --name api --name billing --database postgres/typeorm
155
+ ```
156
+
157
+ `config.yaml` lists one datasource per API (`name: billing` → `withTypeOrm({ name: "billing" })`). Locally they share host `postgres` port `5432`. Point `BILLING_DB_HOST` / `BILLING_DB_PORT` at another server to split later. `webapi add billing --database postgres/typeorm` appends a datasource; TypeORM bootstrap `CREATE DATABASE`s it on first run.
158
+
159
+ #### Health probes
160
+
161
+ Scaffolded APIs call `.withHealth()` so these routes are available **without auth**:
162
+
163
+ | Route | Purpose | Status |
164
+ |---|---|---|
165
+ | `GET /health` | Liveness — process is up | Always `200` `{ "status": "ok" }` |
166
+ | `GET /ready` | Readiness — dependencies OK | `200` when checks pass; `503` when a check fails |
167
+
168
+ With `--database postgres/typeorm`, readiness runs `SELECT 1` against each TypeORM datasource. Use `/ready` for load balancers and orchestrators.
169
+
170
+ #### Auth (`--auth`)
171
+
172
+ | Value | Effect |
173
+ |---|---|
174
+ | `none` | No auth |
175
+ | `auth0` | Auth0 JWT protection; with Postgres also scaffolds a local User profile |
176
+
177
+ ```bash
178
+ npx @decohere/create webapi -d my-app --auth auth0
179
+ ```
180
+
181
+ With Auth0 + Postgres, customize authorization in `projects/<api>/src/auth/ability.factory.ts`:
182
+ override `defineAbilitiesFor` for product CASL rules, and `mapPrincipal` for IdP claim mapping
183
+ (including the `AUTH0_ADMIN_USER_SUB` admin bootstrap). Cortex’s default already maps
184
+ `admin` → `manage`/`all` and `action:Subject` scopes.
185
+
186
+ #### Postman (`--postman`)
187
+
188
+ | Value | Effect |
189
+ |---|---|
190
+ | `none` | Skip Postman |
191
+ | `local` | Local View collection + environment under `postman/` |
192
+ | `api` | Create collection/environment in a Postman cloud workspace |
193
+
194
+ ```bash
195
+ npx @decohere/create webapi -d my-app --postman local
196
+ ```
197
+
198
+ ## Options
199
+
200
+ | Option | Scope | Description |
201
+ |---|---|---|
202
+ | `[directory]` / `-d <directory>` | `webapi` / global | Target directory (positional wins; default `.`) |
203
+ | `--name <slug>` | `webapi` | API directory under `projects/` (repeatable; default `api`) |
204
+ | `add api <name>` | `decohere add api` / `npx @decohere/create webapi add` | Add an API to an existing Decohere workspace |
205
+ | `auth0 login` | `decohere auth0` / `npx @decohere/create auth0` | Device/URL login; persist tokens in `~/.config/auth0` |
206
+ | `auth0 configure` | `decohere auth0` / `npx @decohere/create auth0` | Update Auth0 API + Postman SPA for an existing workspace |
207
+ | `--database <provider>` | `webapi` / `add` | `none` \| `postgres/typeorm` |
208
+ | `--auth <provider>` | `webapi` / `add` | `none` \| `auth0` |
209
+ | `--postman <provider>` | `webapi` / `add` | `none` \| `local` \| `api` |
210
+ | `-y, --yes` | `webapi` / `add` | Install dependencies without prompting |
211
+ | `--install <mode>` | `webapi` / `add` | `ask` (default) \| `yes` \| `no` |
212
+
213
+ ## Next steps
214
+
215
+ After scaffolding:
216
+
217
+ ```bash
218
+ cd my-app
219
+ code . # open in VS Code / Dev Container
220
+ pnpm build # forge release build
221
+ pnpm start # run compiled API (production)
222
+ pnpm dev # Flux HMR (development)
223
+ ```
224
+
225
+ ## Troubleshooting
226
+
227
+ ### GHCR pull fails with `403 Forbidden`
228
+
229
+ If scaffolding fails with an error like:
230
+
231
+ ```text
232
+ failed to resolve reference "ghcr.io/typesmiths/decohere/create:<version>": ... 403 Forbidden
233
+ ```
234
+
235
+ your GitHub token likely does not include the `read:packages` scope.
236
+
237
+ 1. Create or use a token with at least `read:packages`.
238
+ 2. If the package is private/internal, also include `repo`.
239
+ 3. Re-login to GHCR and retry.
240
+
241
+ ```bash
242
+ export GH_TOKEN=YOUR_PAT_WITH_READ_PACKAGES
243
+ echo "$GH_TOKEN" | docker login ghcr.io -u YOUR_GITHUB_USERNAME --password-stdin
244
+ docker pull ghcr.io/typesmiths/decohere/create:<version>
245
+ ```
246
+
247
+ You can verify scopes with:
248
+
249
+ ```bash
250
+ gh auth status -t
251
+ ```
252
+
253
+ If you still get `403` after adding `read:packages`, ask an org admin to grant your user/team access to the `typesmiths/decohere/create` package.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decohere/create",
3
- "version": "0.0.1-dev.97",
3
+ "version": "0.0.1-dev.99",
4
4
  "description": "Download the Decohere scaffolder image and run it (npm create @decohere)",
5
5
  "keywords": [
6
6
  "decohere",