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
Empty file removed apps/.gitkeep
Empty file.
10 changes: 10 additions & 0 deletions apps/web/.dev.vars.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copy to .dev.vars for `pnpm preview` (wrangler dev reads it as the Worker's
# secrets; `vite dev` reads it too, through the platform proxy). Never commit
# .dev.vars. On stage and prod these come from Orun secrets (README → Stripe,
# Email); the service-role key from the environment's Supabase project.
PRIVATE_SUPABASE_SERVICE_ROLE="your project's service_role key"
# Optional — Stripe (billing) and Resend (email)
# PRIVATE_STRIPE_API_KEY="sk_test_…"
# PRIVATE_RESEND_API_KEY="re_…"
# PRIVATE_ADMIN_EMAIL="you@example.com"
# PRIVATE_FROM_ADMIN_EMAIL="no-reply@your-verified-domain.example"
8 changes: 8 additions & 0 deletions apps/web/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# For `vite dev`: the Supabase project the dev server talks to. A build reads
# these from wrangler.jsonc instead (tooling/wire/with-vars.mjs), and the
# deploy renders that file from the environment's own project — so this file
# is for local work only. Secrets go in .dev.vars (see .dev.vars.example).
PUBLIC_SUPABASE_URL='https://REPLACE_ME.supabase.co'
PUBLIC_SUPABASE_ANON_KEY='REPLACE_ME'
# The site's public origin (sitemap, RSS, emails). Empty: http://localhost:5173
PUBLIC_SITE_URL=''
13 changes: 13 additions & 0 deletions apps/web/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.DS_Store
node_modules
/build
/.svelte-kit
/package
.env
.env.*
!.env.example

# Ignore files for PNPM, NPM and YARN
pnpm-lock.yaml
package-lock.json
yarn.lock
48 changes: 48 additions & 0 deletions apps/web/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
module.exports = {
root: true,
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:svelte/recommended",
"prettier",
],
parser: "@typescript-eslint/parser",
plugins: ["@typescript-eslint"],
parserOptions: {
sourceType: "module",
ecmaVersion: 2020,
extraFileExtensions: [".svelte"],
},
overrides: [
{
files: ["*.svelte"],
parser: "svelte-eslint-parser",
parserOptions: {
parser: {
// Specify a parser for each lang.
ts: "@typescript-eslint/parser",
js: "espree",
typescript: "@typescript-eslint/parser",
},
},
},
{
// Apply to all test files. Proper type checking in tests with mocks can be tedious and counterproductive.
files: ["**/*.test.ts", "**/*.spec.ts"],
rules: {
"@typescript-eslint/no-explicit-any": "off",
},
},
],
env: {
browser: true,
es2017: true,
node: true,
},
rules: {
"no-undef": "off",
// no-undef has been turned off because of this:
// basically, it causes issues and TS does those checks so it's redundant
// https://typescript-eslint.io/linting/troubleshooting#i-get-errors-from-the-no-undef-rule-about-global-variables-not-being-defined-even-though-there-are-no-typescript-errors
},
}
10 changes: 10 additions & 0 deletions apps/web/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.DS_Store
node_modules
/build
/.svelte-kit
/package
.env
.env.*
!.env.example
vite.config.js.timestamp-*
vite.config.ts.timestamp-*
2 changes: 2 additions & 0 deletions apps/web/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
engine-strict=true
resolution-mode=highest
13 changes: 13 additions & 0 deletions apps/web/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
**/.svelte-kit/
**/node_modules/
**/package-lock.json

# Don't format plaintext email templates, the new lines are important
src/lib/emails/*_text.svelte
src/lib/emails/*_text.hbs
# The Worker's config: the committed render is byte for byte what
# tooling/wire writes (tests/web holds it to that), and the template keeps
# the comments the render carries over.
wrangler.jsonc
wrangler.template.jsonc
component.yaml
7 changes: 7 additions & 0 deletions apps/web/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"plugins": ["prettier-plugin-svelte"],
"useTabs": false,
"tabWidth": 2,
"semi": false,
"overrides": [{ "files": "*.svelte", "options": { "parser": "svelte" } }]
}
21 changes: 21 additions & 0 deletions apps/web/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Steve Cosman

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
20 changes: 20 additions & 0 deletions apps/web/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# apps/web

[CMSaasStarter](https://github.com/scosman/CMSaasStarter) (MIT, © 2023 Steve
Cosman — see [LICENSE](LICENSE)) on Cloudflare Workers + Static Assets through
`@sveltejs/adapter-cloudflare`.

```bash
pnpm install # from the repository root
pnpm --filter @app/web wire:fixture # render wrangler.jsonc from the fixture
cp apps/web/.env.example apps/web/.env # your project's URL and anon key, for `vite dev`
cp apps/web/.dev.vars.example apps/web/.dev.vars # its service-role key (and Stripe / Resend, optional)
pnpm --filter @app/web dev # http://localhost:5173
pnpm --filter @app/web build # vite build → .svelte-kit/cloudflare (the Worker and its assets)
pnpm --filter @app/web preview # wrangler dev over the build
```

`pnpm build` reads the Supabase project's URL and anon key from
`wrangler.jsonc` (`tooling/wire/with-vars.mjs`), so the build always inlines
the project the Worker is configured for. Secrets are never inlined: the
Worker reads them at request time (`$env/dynamic/private`).
107 changes: 107 additions & 0 deletions apps/web/component.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
apiVersion: sourceplane.io/v1
kind: Component
metadata:
name: web
description: The SaaS site (SvelteKit on Cloudflare Workers + Static Assets via @sveltejs/adapter-cloudflare, per environment)
spec:
type: cloudflare-workers-assets-turbo
lifecycle: production
owner: platform
# `app`, not `web`: a domain and a component share one name space in the
# catalog, and a domain called `web` hid this component from it.
domain: app
path: apps/web
# Its own lane per environment: the framework build is the longest job in
# the plan, and a shared lane would wait on it.
lane: isolated
# The project this environment talks to: its URL and anon key, in the wiring
# document the `supabase` Terraform root lease-publishes after its apply.
# Rendered into wrangler.jsonc by the build (and inlined into the bundle),
# so a job resolves it when it STARTS.
secretEnv:
WIRING_SUPABASE_STAGE: "secret://sveltekit-saas/sveltekit-saas/stage/WIRING_SUPABASE"
WIRING_SUPABASE_PROD: "secret://sveltekit-saas/sveltekit-saas/prod/WIRING_SUPABASE"
# The Worker's SECRETS, each read at request time ($env/dynamic/private),
# never inlined: the project's service-role key, which the `supabase` root
# publishes beside the wiring, and the owner's Stripe and Resend settings
# (README → Stripe, Email). The build hands each one that is set to the
# Worker as a secret (tooling/wire/worker-secrets.mjs, the value over
# stdin). BEST-EFFORT, wire-now-seed-later: a key nobody has stored is
# skipped when the job resolves its secrets (no env var, no failure), and
# the site without it says what to connect — so a fresh product deploys and
# serves before its owner has a Stripe or Resend account at all.
optionalSecretEnv:
PRIVATE_SUPABASE_SERVICE_ROLE: "secret://sveltekit-saas/sveltekit-saas/{{ .environment }}/SUPABASE_SERVICE_ROLE_KEY"
PRIVATE_STRIPE_API_KEY: "secret://sveltekit-saas/sveltekit-saas/{{ .environment }}/STRIPE_API_KEY"
PRIVATE_RESEND_API_KEY: "secret://sveltekit-saas/sveltekit-saas/{{ .environment }}/RESEND_API_KEY"
PRIVATE_ADMIN_EMAIL: "secret://sveltekit-saas/sveltekit-saas/{{ .environment }}/ADMIN_EMAIL"
PRIVATE_FROM_ADMIN_EMAIL: "secret://sveltekit-saas/sveltekit-saas/{{ .environment }}/FROM_ADMIN_EMAIL"
subscribe:
environments:
- name: dev
profile: verify
- name: stage
profile: verify
profileRules:
- profile: deploy
when:
triggerRef: github-push-main
- name: prod
profile: verify
profileRules:
- profile: deploy
when:
triggerRef: github-push-main
parameters:
nodeVersion: "22"
pnpmVersion: "10.12.1"

workspaceDir: ../..
appDir: .

turboFilter: "@app/web"
wranglerConfig: wrangler.jsonc

# @sveltejs/adapter-cloudflare emits the Worker as
# .svelte-kit/cloudflare/_worker.js and the static output (pre-rendered
# pages, _app/* hashed assets, static/) beside it — both deploy in one
# `wrangler deploy`.
workerEntrypoint: .svelte-kit/cloudflare/_worker.js
assetsDir: .svelte-kit/cloudflare

# Per-env worker name: sveltekit-saas-web-{dev,stage,prod}.
workerName: sveltekit-saas-web
environmentAwareWorkerName: true

# The account's workers.dev subdomain; exported to the smoke step as
# ${WORKERS_DEV_SUBDOMAIN} and used to build ${DEPLOYED_URL}.
workersDevSubdomain: your-workers-subdomain

installCommand: pnpm install --frozen-lockfile
# Render this environment's wrangler config, then build, then hand the
# Worker its secrets. stage and prod render from the wiring document their
# supabase apply published (secretEnv above, resolved before the job's
# first step); dev, which no root applies to and which only verifies,
# renders from the committed fixture. The build inlines the rendered
# project's URL and anon key (tooling/wire/with-vars.mjs) and the site's
# public origin, PUBLIC_SITE_URL — the environment's SITE_URL
# (intent.yaml), or its workers.dev URL — into the sitemap, the feed and
# the emails. No secret reaches the build (`env -u`): the Worker reads each
# at request time. Then every secret the environment has goes to the
# Worker (`wrangler secret bulk`, the value over stdin) before the
# composition deploys it; only the deploy lane holds a Cloudflare
# credential, so a verify lane builds the same and pushes nothing.
buildCommand: node ../../tooling/wire/live.mjs --template wrangler.template.jsonc --out wrangler.jsonc --components supabase --env "${ORUN_ENVIRONMENT}" --fixture wiring.fixture.json --fixture-envs dev && env -u PRIVATE_SUPABASE_SERVICE_ROLE -u PRIVATE_STRIPE_API_KEY -u PRIVATE_RESEND_API_KEY -u PRIVATE_ADMIN_EMAIL -u PRIVATE_FROM_ADMIN_EMAIL PUBLIC_SITE_URL="${SITE_URL:-https://sveltekit-saas-web-${ORUN_ENVIRONMENT}.your-workers-subdomain.workers.dev}" pnpm exec turbo run build --filter=@app/web && node ../../tooling/wire/worker-secrets.mjs --worker "sveltekit-saas-web-${ORUN_ENVIRONMENT}" --config wrangler.jsonc --secret PRIVATE_SUPABASE_SERVICE_ROLE --secret PRIVATE_STRIPE_API_KEY --secret PRIVATE_RESEND_API_KEY --secret PRIVATE_ADMIN_EMAIL --secret PRIVATE_FROM_ADMIN_EMAIL

# Smoke: the home page renders to its end (`</html>`), and /api/health
# answers ok — which only the Worker can, by counting the profiles table
# in its project with the service-role key, so it proves the project's
# wiring and key reached the Worker, the migrations ran and the Worker is
# serving, whether or not Stripe and email are connected. Read-only. Each
# response is buffered before grep so an early match cannot SIGPIPE curl.
smokeCommand: "html=$(curl -sfL \"${DEPLOYED_URL}/\") && echo \"${html}\" | grep -q '</html>' && health=$(curl -sf \"${DEPLOYED_URL}/api/health\") && echo \"${health}\" | grep -q '\"ok\":true'"
labels:
team: platform
layer: delivery
surface: web
runtime: cloudflare
57 changes: 57 additions & 0 deletions apps/web/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"name": "@app/web",
"version": "0.0.0",
"private": true,
"scripts": {
"dev": "vite dev",
"build": "node ../../tooling/wire/with-vars.mjs --config wrangler.jsonc -- vite build",
"preview": "wrangler dev --config wrangler.jsonc",
"check": "node ../../tooling/wire/with-vars.mjs --config wrangler.jsonc -- svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"typecheck": "node ../../tooling/wire/with-vars.mjs --config wrangler.jsonc -- svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"test:unit": "node ../../tooling/wire/with-vars.mjs --config wrangler.jsonc -- svelte-kit sync && node ../../tooling/wire/with-vars.mjs --config wrangler.jsonc -- vitest run",
"lint": "eslint . && prettier --check --plugin prettier-plugin-svelte .",
"format": "prettier --write --plugin prettier-plugin-svelte .",
"wire:fixture": "node ../../tooling/wire/render.mjs --template wrangler.template.jsonc --out wrangler.jsonc --map wiring.fixture.json --env stage"
},
"devDependencies": {
"@sveltejs/adapter-cloudflare": "^7.2.9",
"@sveltejs/kit": "^2.21.1",
"@sveltejs/vite-plugin-svelte": "^5.0.3",
"@tailwindcss/postcss": "^4.0.9",
"@tailwindcss/typography": "^0.5.13",
"@types/glob": "^8.1.0",
"@types/html-to-text": "^9.0.4",
"@types/jsdom": "^21.1.7",
"@typescript-eslint/eslint-plugin": "^8.57.1",
"@typescript-eslint/parser": "^8.57.1",
"daisyui": "^5.0.0",
"eslint": "^8.28.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-svelte": "^2.45.1",
"fuse.js": "~7.0.0",
"glob": "^10.4.5",
"html-to-text": "^9.0.5",
"jsdom": "^24.1.1",
"postcss": "^8.4.31",
"prettier": "~3.4.2",
"prettier-plugin-svelte": "~3.3.2",
"super-sitemap": "^1.0.7",
"svelte": "^5.0.0",
"svelte-check": "^4.0.0",
"tailwindcss": "^4.0.9",
"typescript": "^5.5.0",
"vite": "^6.3.5",
"vitest": "^3.0.7",
"wrangler": "^4.151.0"
},
"type": "module",
"dependencies": {
"@supabase/auth-ui-shared": "^0.1.8",
"@supabase/auth-ui-svelte": "^0.2.9",
"@supabase/ssr": "^0.5.2",
"@supabase/supabase-js": "^2.45.2",
"handlebars": "^4.7.8",
"resend": "^3.5.0",
"stripe": "^13.3.0"
}
}
5 changes: 5 additions & 0 deletions apps/web/postcss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default {
plugins: {
"@tailwindcss/postcss": {},
},
}
Loading
Loading