@auth-craft/worker-d1-stack 0.0.0-stage → 0.1.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/README.md +99 -2
- package/assets/check/config.mjs +1826 -0
- package/assets/manifest.json +96 -0
- package/assets/migrations/0001_baseline.sql +234 -0
- package/assets/migrations/0002_email.sql +31 -0
- package/assets/migrations/0003_email_provider_index.sql +7 -0
- package/assets/migrations/0004_audit.sql +27 -0
- package/assets/migrations/0005_allowed_origins.sql +14 -0
- package/assets/sbom/worker.cdx.json +629 -0
- package/assets/worker/worker.js +158 -0
- package/bin/auth-craft-worker.mjs +4 -0
- package/dist/check.d.ts +9 -0
- package/dist/check.d.ts.map +1 -0
- package/dist/check.js +122 -0
- package/dist/check.js.map +1 -0
- package/dist/cli.d.ts +9 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +175 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands.d.ts +27 -0
- package/dist/commands.d.ts.map +1 -0
- package/dist/commands.js +76 -0
- package/dist/commands.js.map +1 -0
- package/dist/init.d.ts +18 -0
- package/dist/init.d.ts.map +1 -0
- package/dist/init.js +68 -0
- package/dist/init.js.map +1 -0
- package/dist/paths.d.ts +17 -0
- package/dist/paths.d.ts.map +1 -0
- package/dist/paths.js +13 -0
- package/dist/paths.js.map +1 -0
- package/dist/secrets-file.d.ts +5 -0
- package/dist/secrets-file.d.ts.map +1 -0
- package/dist/secrets-file.js +56 -0
- package/dist/secrets-file.js.map +1 -0
- package/dist/smoke.d.ts +34 -0
- package/dist/smoke.d.ts.map +1 -0
- package/dist/smoke.js +144 -0
- package/dist/smoke.js.map +1 -0
- package/dist/wrangler-config.d.ts +52 -0
- package/dist/wrangler-config.d.ts.map +1 -0
- package/dist/wrangler-config.js +23 -0
- package/dist/wrangler-config.js.map +1 -0
- package/dist/wrangler-runner.d.ts +5 -0
- package/dist/wrangler-runner.d.ts.map +1 -0
- package/dist/wrangler-runner.js +35 -0
- package/dist/wrangler-runner.js.map +1 -0
- package/package.json +34 -3
package/README.md
CHANGED
|
@@ -1,3 +1,100 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @auth-craft/worker-d1-stack
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The Auth Craft backend on Cloudflare Workers + D1, ready to deploy: the prebuilt Worker,
|
|
4
|
+
its D1 migrations, and `auth-craft-worker`, a CLI that writes the Wrangler config, checks
|
|
5
|
+
it, uploads secrets, applies migrations and deploys. No clone or build of auth-craft.
|
|
6
|
+
|
|
7
|
+
The package version is the auth-craft version you deploy. `main` in the generated
|
|
8
|
+
config points into the installed package and the Worker ships as built (`no_bundle`), so
|
|
9
|
+
upgrading is `npm i @auth-craft/worker-d1-stack@<version>` followed by `deploy`.
|
|
10
|
+
|
|
11
|
+
Clients call this Worker directly (no gateway in front): see the URL and app model in
|
|
12
|
+
the auth-craft docs (`docs/CLOUDFLARE_WORKERS_PLAN.md` §6.5).
|
|
13
|
+
|
|
14
|
+
## Requirements
|
|
15
|
+
|
|
16
|
+
- Node.js 20+, `wrangler` 4 (`npm i -D wrangler`), `wrangler login` for real deploys.
|
|
17
|
+
- A D1 database: `npx wrangler d1 create auth` (note its id).
|
|
18
|
+
- Workers Paid for `--password-engine local` (scrypt needs more than the Free 10 ms CPU),
|
|
19
|
+
or Workers Free with `--password-engine remote` and a password engine (deploy one with
|
|
20
|
+
`auth-craft-stack password-engine` from `@auth-craft/aws-cf-stack`).
|
|
21
|
+
|
|
22
|
+
## Use
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
npm i -D @auth-craft/worker-d1-stack wrangler
|
|
26
|
+
|
|
27
|
+
npx auth-craft-worker init --name auth-prod --database-name auth --database-id <uuid> \
|
|
28
|
+
--password-engine local --domain auth.example.com --cors-origins https://app.example.com
|
|
29
|
+
# → wrangler.json (edit vars as needed; never put secrets there)
|
|
30
|
+
|
|
31
|
+
cat > .secrets <<'SECRETS'
|
|
32
|
+
JWT_PRIVATE_KEY=...
|
|
33
|
+
JWT_PUBLIC_KEY=...
|
|
34
|
+
SECRETS
|
|
35
|
+
chmod 600 .secrets
|
|
36
|
+
|
|
37
|
+
npx auth-craft-worker check --secrets-file .secrets # no account needed
|
|
38
|
+
npx auth-craft-worker deploy --secrets-file .secrets --dry-run
|
|
39
|
+
npx auth-craft-worker secrets --secrets-file .secrets # wrangler secret bulk
|
|
40
|
+
npx auth-craft-worker deploy --secrets-file .secrets # check → D1 migrations → deploy
|
|
41
|
+
AUTH_CRAFT_SMOKE_PASSWORD=... npx auth-craft-worker smoke \
|
|
42
|
+
--url https://auth.example.com --password-engine local --email smoke@example.com
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
| Command | Does |
|
|
46
|
+
| --- | --- |
|
|
47
|
+
| `init` | Writes `wrangler.json`: D1 as `DB`, the `RATE_LIMITER` Durable Object, the cleanup cron, optional custom domain and email queue, `workers_dev`/`preview_urls` off. Refuses to overwrite without `--force`. |
|
|
48
|
+
| `check` | Without an account: the config deploys this package's Worker unmodified (path, `no_bundle`, SHA-256); bindings the settings need (D1, the rate limiter in production, the email queue, `send_email`); the Worker's own config rules over `vars` + the secrets file (the refusals it would answer with 503); no secret in `vars`; unknown variables (typos) as warnings. Prints names, never values. |
|
|
49
|
+
| `secrets` | After `check`, uploads every key of the secrets file with one `wrangler secret bulk`; the JSON file exists (mode 600) only during the call. |
|
|
50
|
+
| `migrate` | `wrangler d1 migrations apply DB --remote` (or `--local`). |
|
|
51
|
+
| `deploy` | `check`, then migrations, then `wrangler deploy`. `--dry-run` builds and validates, uploads nothing; `--skip-migrations` leaves D1 alone. |
|
|
52
|
+
| `smoke` | Black-box checks of a running Worker over HTTP (below). Exit 1 if any fails. |
|
|
53
|
+
| `version` | The packaged version and Worker hash. |
|
|
54
|
+
|
|
55
|
+
The secrets file is `NAME=value` lines (`#` comments, optional quotes) and must not be
|
|
56
|
+
readable by other users. Secret variables: `JWT_PRIVATE_KEY`, `GATEWAY_SECRET`,
|
|
57
|
+
`PASSWORD_ENGINE_SIGNING_KEY`, `MFA_SECRET_KEY`, `MFA_SECRET_PREVIOUS_KEYS`,
|
|
58
|
+
`RESEND_API_KEY`, `RESEND_WEBHOOK_SECRET`, `GOOGLE_CLIENT_SECRET`, `FACEBOOK_CLIENT_SECRET`.
|
|
59
|
+
|
|
60
|
+
## Email delivery events (Cloudflare Email Service)
|
|
61
|
+
|
|
62
|
+
With `--email-queue` and `EMAIL_PROVIDER=cloudflare`, subscribe the Worker's email queue
|
|
63
|
+
(`<name>-email`) to the sending domain's Email Sending events `message.delivered`,
|
|
64
|
+
`message.bounced` and `message.complained` (dashboard: Queues → the queue →
|
|
65
|
+
Subscriptions). The Worker records them on the message it sent; a hard bounce or a
|
|
66
|
+
complaint suppresses that recipient, so no further sign-in codes go to a dead or
|
|
67
|
+
complaining mailbox. Soft bounces and deferrals change nothing.
|
|
68
|
+
|
|
69
|
+
## Smoke after a deploy
|
|
70
|
+
|
|
71
|
+
`smoke` needs a verified account without MFA on that deployment (create it once and keep
|
|
72
|
+
it for smoke runs) and `REFRESH_TOKEN_STRATEGY=body` or `both`. The password comes from
|
|
73
|
+
`AUTH_CRAFT_SMOKE_PASSWORD`, never the command line; `AUTH_CRAFT_SMOKE_GATEWAY_SECRET`
|
|
74
|
+
is sent as `X-Gateway-Secret` if something sits in front of the Worker. It checks, in
|
|
75
|
+
order: `/health` answers with the `PASSWORD_ENGINE` you name (anything else stops the
|
|
76
|
+
run); an undeclared app is refused; a wrong password is `INVALID_CREDENTIALS`, not 503
|
|
77
|
+
(the hasher or the engine is reachable); login; `/auth/me` with and without the token;
|
|
78
|
+
refresh rotates; logout ends the session; a foreign origin is not allowed by CORS. A run
|
|
79
|
+
leaves one logged-out session and no failed attempt. It prints check names, never
|
|
80
|
+
tokens, passwords or bodies.
|
|
81
|
+
|
|
82
|
+
## Release gate (auth-craft maintainers)
|
|
83
|
+
|
|
84
|
+
`pnpm verify:release:worker-d1-stack` (run by `publish:worker-d1-stack`) runs
|
|
85
|
+
`pnpm --filter @auth-craft/worker-d1-stack smoke:local` (`scripts/smoke-local.mjs`): for
|
|
86
|
+
each engine mode, `init` → `check` → `migrate --local` → the real `wrangler dev` → `smoke`,
|
|
87
|
+
with a real password engine on localhost for `remote`; a smoke naming the other mode must
|
|
88
|
+
fail. No Cloudflare account is used: releases are not verified against a real deployment.
|
|
89
|
+
|
|
90
|
+
## What is inside
|
|
91
|
+
|
|
92
|
+
- `assets/worker/worker.js` — the Worker, built by the auth-craft app's own build.
|
|
93
|
+
- `assets/migrations/` — D1 migrations, applied in order, additive.
|
|
94
|
+
- `assets/check/config.mjs` — the Worker's config loader, used by `check`.
|
|
95
|
+
- `assets/sbom/worker.cdx.json` — CycloneDX SBOM of the Worker bundle.
|
|
96
|
+
- `assets/manifest.json` — version, Worker SHA-256, migrations, known variables.
|
|
97
|
+
|
|
98
|
+
Verified locally only, by design: `wrangler deploy --dry-run` with the real wrangler, and
|
|
99
|
+
`smoke` against the packaged Worker under `wrangler dev` in both modes. Run `smoke`
|
|
100
|
+
against your own deployment after each deploy.
|