Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .baseline/identity.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"_comment": "THIS TREE'S OWN IDENTITY — the FROM side of every rebrand. tooling/rebrand/rebrand.mjs reads it to know what to rename AWAY from; a product's identity is the --values file, which is the TO side. Change a value here only together with the tree: these strings must be what the tree actually contains, or the rename silently misses and the product ships carrying this baseline's name. `productName` is the SITE_NAME seam in apps/web/src/site.ts (upstream's own heading, 'SvelteKit Auth Example'); `pascal` is also the name of Auth.js's `SvelteKitAuth`, which the engine protects where the app imports and calls it (UPSTREAM in rebrand.mjs); `domain` and `subdomain` are placeholders, because this baseline has never deployed under a name of its own; `githubOwner` is the owner in the repository's source links.",
"slug": "sveltekit-auth",
"pascal": "SvelteKitAuth",
"productName": "SvelteKit Auth Example",
"domain": "sveltekit-auth.example.com",
"subdomain": "your-workers-subdomain",
"githubOwner": "sourceplane"
}
171 changes: 171 additions & 0 deletions .baseline/product/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
# sveltekit-auth

A SvelteKit site whose sign-in is [Auth.js](https://authjs.dev) — a home
page, a sign-in page, a page only a signed-in visitor can read, and a
sign-out — on **Cloudflare Workers + Static Assets** through SvelteKit's own
[`@sveltejs/adapter-cloudflare`](https://svelte.dev/docs/kit/adapter-cloudflare).
Sessions are Auth.js's encrypted JWT cookies: there is no database to run.

It is Auth.js's SvelteKit example, ported to Cloudflare.
Upstream: https://github.com/nextauthjs/sveltekit-auth-example (ISC,
© 2022-2024 Balázs Orbán; the licence is `apps/web/LICENSE`).

## Live deployment

<!-- 03-docs:begin -->
Not recorded yet. The bootstrap's last phase writes the live URLs, the
workspace and the secrets the site uses into
[ai/context/deployment.md](ai/context/deployment.md); how the site deploys
and how to operate it is in
[ai/context/operations.md](ai/context/operations.md).
<!-- 03-docs:end -->

## What is here

| Surface | Where |
|---|---|
| The site's name (the home page's heading, every page's `<title>`) | `apps/web/src/site.ts` |
| `/` (home), `/signin`, `/protected`, `/signout` | `apps/web/src/routes` |
| Auth.js: the configuration, built per request from the Worker's secrets | `apps/web/src/auth.ts`, `apps/web/src/hooks.server.ts` |
| The 26 sign-in providers and the keys each needs | `apps/web/src/server/providers.ts` |
| The header (who is signed in, sign in and out) and the footer | `apps/web/src/components` |
| The deploy step that gives each Worker its secrets | `tooling/wire/worker-secrets.mjs` |
| Workers build and deploy contract | `apps/web/svelte.config.js`, `apps/web/wrangler.jsonc`, `apps/web/component.yaml` |
| Tests (the providers and their keys, the site's name, the secrets step) | `apps/web/src/**/*.test.ts` (vitest) |

## Getting started

```bash
pnpm install # runs `svelte-kit sync`
pnpm typecheck # svelte-check
pnpm lint # prettier --check
pnpm test # vitest
pnpm build # vite build → apps/web/.svelte-kit/cloudflare (_worker.js + the static output)
```

```bash
pnpm --filter @app/web secret:dev # writes a generated AUTH_SECRET into apps/web/.env (git-ignored)
pnpm --filter @app/web dev # http://localhost:3000
pnpm --filter @app/web preview # wrangler dev over the built Worker, http://localhost:8787
```

Both read `apps/web/.env`: copy `apps/web/.env.example`, the example's
own, for every key the site can take. Without an
AUTH_SECRET Auth.js refuses every request with a server-configuration
error, so run `secret:dev` once; a second run keeps the secret it wrote.

Make the site yours in `apps/web/src/routes` (the pages) and
`apps/web/src/site.ts` (its name). A page reads the visitor's session from
`$page.data.session` (the root layout loads it with `event.locals.auth()`),
as `/protected` does.

## Sign-in providers

The site deploys with no provider connected, and `/signin` says so and
lists what each one needs. A provider is offered once **every** key it
takes is set; the others are never shown. For GitHub:

1. Create an OAuth app (GitHub → Settings → Developer settings → OAuth
Apps). Its callback URL is the site's `/auth/callback/github`:
`https://sveltekit-auth-web-prod.<subdomain>.workers.dev/auth/callback/github`
for prod (one app per environment, or one per origin you serve).
2. Store its client id and secret as this repository's Orun secrets for
that environment (or on the console's Secrets page):

```bash
orun secrets set AUTH_GITHUB_ID --env prod # prompts for the value
orun secrets set AUTH_GITHUB_SECRET --env prod
```

The build never sees them; the deploy hands them to the Worker as
Worker secrets (`wrangler secret bulk`, over stdin), so they are in no
bundle, no build cache and no log.
3. Redeploy (a merge, or **Deploy by hand** below). The deploy pushes the
keys to the Worker, and the GitHub button appears.

The deploy pushes the keys of the providers upstream's `.env.example`
names, when they are set:

| Provider | Keys |
|---|---|
| GitHub | `AUTH_GITHUB_ID`, `AUTH_GITHUB_SECRET` |
| Google | `AUTH_GOOGLE_ID`, `AUTH_GOOGLE_SECRET` |
| Discord | `AUTH_DISCORD_ID`, `AUTH_DISCORD_SECRET` |
| LinkedIn | `AUTH_LINKEDIN_ID`, `AUTH_LINKEDIN_SECRET` |
| Facebook | `AUTH_FACEBOOK_ID`, `AUTH_FACEBOOK_SECRET` |
| Twitter | `AUTH_TWITTER_ID`, `AUTH_TWITTER_SECRET` |
| Twitch | `AUTH_TWITCH_ID`, `AUTH_TWITCH_SECRET` |
| Pinterest | `AUTH_PINTEREST_ID`, `AUTH_PINTEREST_SECRET` |
| Auth0 | `AUTH_AUTH0_ID`, `AUTH_AUTH0_SECRET`, `AUTH_AUTH0_ISSUER` |

The other seventeen of the example's providers (Apple, Azure AD B2C, BoxyHQ
SAML, Cognito, Coinbase, Dropbox, GitLab, HubSpot, Keycloak, Netlify, Okta,
Passage, Reddit, Slack, Spotify, WorkOS, Zoom) work the same way; their keys
are in `apps/web/src/server/providers.ts`. Set them in `apps/web/.env` locally.
To deploy one, add its keys to `optionalSecretEnv` in
`apps/web/component.yaml` and to the `--secret` list in that file's
`buildCommand`, or set them on the Worker directly
(`pnpm --filter @app/web exec wrangler secret put AUTH_GITLAB_ID --name sveltekit-auth-web-prod`):
a Worker keeps its secrets from one deploy to the next.

## Sessions and AUTH_SECRET

A session is Auth.js's default: a JWT, encrypted with `AUTH_SECRET`, in an
httpOnly `authjs.session-token` cookie (`__Secure-` prefixed over HTTPS).
Nothing about a visitor is stored anywhere else. The upstream example has
no database adapter, and none is added.

Each environment's Worker gets its own AUTH_SECRET from its first deploy:
the deploy lane's build step (`tooling/wire/worker-secrets.mjs`) lists the
secrets the Worker carries, generates one only if it carries none, and
pushes it with `wrangler secret bulk` over stdin. Every later deploy keeps
it, so sessions survive deploys. It is never in the repository, a log or
the build. To set your own, store an Orun secret named `AUTH_SECRET` for
the environment (`orun secrets set AUTH_SECRET --env prod`); the next deploy
pushes it. Changing it signs everyone out,
since a session sealed with the old secret no longer opens.

## How it deploys

Merges to `main` converge through Orun: `.github/workflows/ci.yml` plans the
changed components and runs each lane against the workspace in
`intent.yaml`. The site deploys to `stage`, then to `prod` once stage has
converged on the same commit; `dev` only verifies. The Worker is
`sveltekit-auth-web-<env>` on your account's workers.dev subdomain. Each
deploy builds the site, gives the Worker its secrets, deploys it, and is
smoke-tested over HTTP: the home page must render and Auth.js's
`/auth/session` must answer `null`, which it does only once the Worker has
its AUTH_SECRET. A pull request runs the same pipeline's verify lanes: the
site built and dry-deployed for each environment, with nothing deployed and
no secret pushed. They do not lint or run the tests, so run
`pnpm typecheck`, `pnpm lint` and `pnpm test` before you push.

The pipeline holds one credential, GitHub's own `GITHUB_TOKEN`. The
Cloudflare token and account id are brokered per run from the workspace's
Cloudflare connection; the providers' keys are the site's own secrets in
the workspace. Nothing provider-shaped is stored in the repository or in
GitHub.

**Deploy by hand.** Orunbase's **Deploy** button on a component, or **Run
workflow** on the CI workflow in GitHub's Actions tab (on `main`), runs
`ci.yml` for the environment and components you pick, and each one deploys
exactly as a merge would deploy it. Leave the component blank to redeploy
every component in that environment, with nothing changed: after storing a
provider's keys, say. A component with nothing to run in that environment
(a test suite in `prod`) is left out with a notice.

## Custom domain

The site answers on workers.dev from its first deploy. To serve it on your
own domain, add the domain to the Cloudflare account the site deploys into
and attach it to the Worker (dashboard → Workers & Pages →
`sveltekit-auth-web-prod` → Settings → Domains & Routes → Add → Custom
domain). Do the same for stage with a subdomain if you want one.

Auth.js trusts the host a request arrives on (`trustHost: true`), so
sign-in works on the new origin with no change to the code: add the new
origin's `/auth/callback/<provider>` to each OAuth app. The repository
names the domain in one place, `BASE_DOMAIN` in `intent.yaml` (dev, stage
and prod), which the site was born with as the reserved placeholder
`sveltekit-auth.example.com`. Replace it with your domain in the same
change that records it.
25 changes: 25 additions & 0 deletions .baseline/tasks/01-product.TaskContract.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Task contract template for the 01-product landing.
# Unbound to a key on purpose: `orun.task/ensure@v1` seals and attaches it to
# the key the allocator issues. It lives under `.baseline/`, not `tasks/`,
# because `tasks/` is this repository's own work tree (`intent.yaml` `work:`),
# where an unkeyed contract is an error. gates: [] is a DECLARATION — merge
# alone finishes this task; the main convergence is the gate the bootstrap
# watches, not one the plane observes as a PR check.
#
# The whole site in one landing. `affects` names COMPONENTS, by
# metadata.name: the phase's retouch hook reads this list to decide which
# component.yaml files get the redeploy marker, so the deploy set and the task
# plane's statement of the work are one list. The site is one component — its
# test runs inside it (vitest in apps/web), so there is no separate test
# package to redeploy.
apiVersion: orun.io/v1
kind: TaskContract
spec:
goal: The site's repository is born and linked, the whole site lands in one pull request, and one convergence builds it with @sveltejs/adapter-cloudflare, gives each environment's Worker its AUTH_SECRET and deploys it to stage and prod, its tests green
affects:
- web
doneWhen:
- repo pushed, main pinned as default, workspace linked (orun cloud link)
- main convergence green (build, deploy and smoke on stage and prod)
- the home page answers on both workers.dev URLs, and Auth.js's /auth/session answers there
gates: []
13 changes: 13 additions & 0 deletions .baseline/tasks/03-docs.TaskContract.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Task contract template for the 03-docs landing. See 01-product's header.
apiVersion: orun.io/v1
kind: TaskContract
spec:
goal: The live deployment is recorded from verified facts as agent-readable state in the site's repo
affects:
- ai/context/deployment.md
- ai/context/operations.md
- README.md
doneWhen:
- committed deployment manifest matches probed reality
- prod waits on stage again, and dev verifies every merge to main again
gates: []
136 changes: 136 additions & 0 deletions .github/workflows/baseline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
name: Baseline CI

# THE FACTORY'S OWN LANES — this repository tested as a BASELINE: that its
# build document parses with the orun a bootstrap actually runs, that its card
# agrees with it, that every component is placed by exactly one phase, that a
# placed tree comes up branded and carrying nothing of the factory, and that
# the site it produces installs, builds, deploys (dry) and serves.
#
# ─── WHY THIS IS NOT IN ci.yml ────────────────────────────────────────────
#
# `repo-blueprint.yaml`'s `github-workflows` module copies the WHOLE `.github`
# directory into every site built from this repository. These jobs run
# `testing/*.sh`, and `testing/` is deliberately not placed — so in a site they
# would be steps that cannot pass, red on its very first pull request. This
# file is in the blueprint's `ignore` list, and `testing/coverage.test.sh`
# fails on any workflow that reads `testing/` and is not.

on:
push:
branches: [main]
pull_request:

concurrency:
group: baseline-ci-${{ github.event_name == 'pull_request' && github.ref || github.run_id }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

permissions:
contents: read

jobs:
# Tier 0. bash, python3 and git; node for the tools. No workspace install,
# no network, no credential — the job that most certainly fails a PR.
baseline-contract:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v5
with:
node-version: 22
# setup-node v5 turns on the pnpm cache by itself when package.json
# names a packageManager, and then fails on a runner with no pnpm.
# This job installs nothing.
package-manager-cache: false
- name: Contract tests (manifest, phases, coverage, rebrand, retouch, bootstrap-defer)
run: |
set -euo pipefail
python3 -c 'import yaml' 2>/dev/null || pip install --quiet pyyaml
for t in manifest phases coverage rebrand retouch bootstrap-defer; do
echo "── $t"
bash "testing/$t.test.sh"
done
# Every component's docs/{overview,architecture,runbook}.md is generated
# from what the component declares (its manifest, Worker config,
# Terraform, migrations, package scripts). A pull request that changes
# one of those facts without regenerating the pages fails here.
- name: Component docs match their manifests
run: python3 tooling/catalog/gen-component-docs.py --check

# Tier 1. THE BLUEPRINT, READ AND PLACED BY THE BINARY A BOOTSTRAP RUNS.
#
# Pinned at the bootstrap floor (BOOTSTRAP.md), not the site's lane pin:
# every test here reads YAML with PyYAML, which parses anything well-formed;
# only the pinned orun can say whether the document is one a bootstrap can
# run. `--status` parses it, validates every hook against the action
# registry, compiles every `when` and narration template, and writes
# nothing. Then the leak gate (what a site would carry) and the placement
# tier (the offline bootstrap: every phase placed and finished by the
# blueprint's own hooks, then the site's own `orun plan` for the 01-product
# merge).
blueprint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: sourceplane/orun-action@v1.2.0
with:
version: v2.88.0
- uses: pnpm/action-setup@v4
with:
version: 10.12.1
- uses: actions/setup-node@v5
with:
node-version: 22
# This job installs nothing either: with no lockfile hook the offline
# bootstrap never runs pnpm, so there is no store, and the pnpm cache
# setup-node v5 turns on by itself (package.json names a packageManager)
# fails the job saving a path that does not exist whenever no earlier
# cache exists for the lockfile.
package-manager-cache: false
- name: repo-blueprint.yaml, read by the pinned CLI
run: |
set -euo pipefail
orun --version
python3 -c 'import yaml' 2>/dev/null || pip install --quiet pyyaml
# Required inputs must be supplied for the document to resolve; the
# values are arbitrary and nothing is written.
orun new --blueprint repo-blueprint.yaml --status \
--out "$(mktemp -d)" \
--set reponame=acme-notes \
--set "productname=Acme Notes" \
--set githuborg=acme-inc
- name: the leak gate — what a site carries
run: bash testing/leak.test.sh
- name: placement — the offline bootstrap, and the site's own plan
run: |
git config --global user.email ci@example.invalid
git config --global user.name "baseline ci"
bash testing/placement.test.sh

# Tier 2. THE SITE IT PRODUCES WORKS: the finished site installed, its
# fixtures rendered, type-checked, linted, tested and built, the stage
# lane's own build, output check and dry deploy, and the built Worker served
# and smoke-tested with the component's own smoke command. Pinned at the
# bootstrap floor (v2.88.0): the offline bootstrap reads the blueprint (its
# one `secrets` reconcile, its background task set-up, its landings checked
# in the box), and the floor is newer than the site's lane pin (v2.78.4),
# which is all the lane steps need.
site:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: sourceplane/orun-action@v1.2.0
with:
version: v2.88.0
- uses: pnpm/action-setup@v4
with:
version: 10.12.1
- uses: actions/setup-node@v5
with:
node-version: 22
cache: pnpm
- name: e2e — the bootstrapped site builds, deploys (dry) and serves
run: |
python3 -c 'import yaml' 2>/dev/null || pip install --quiet pyyaml
git config --global user.email ci@example.invalid
git config --global user.name "baseline ci"
bash testing/e2e.test.sh
Loading
Loading