prunelle 0.7.7 → 0.9.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/llms.txt +63 -46
- package/package.json +7 -2
- package/src/a11y/declaration.ts +6 -10
- package/src/a11y/index.ts +69 -125
- package/src/animate.ts +127 -0
- package/src/build/asides.ts +51 -0
- package/src/build/bundle.ts +88 -134
- package/src/build/client-entries.ts +6 -6
- package/src/build/client-outputs.ts +75 -0
- package/src/build/client-plugin.ts +9 -4
- package/src/build/ecoindex.ts +4 -2
- package/src/build/files.ts +18 -0
- package/src/build/graph.ts +15 -7
- package/src/build/index.ts +20 -10
- package/src/build/island-promote.ts +1 -1
- package/src/build/islands.ts +4 -1
- package/src/build/key-types.ts +31 -0
- package/src/build/manifest.ts +19 -1
- package/src/build/plugin-host.ts +2 -0
- package/src/build/prerender.ts +2 -2
- package/src/build/reach.ts +14 -1
- package/src/build/report.ts +1 -1
- package/src/build/route-types.ts +16 -0
- package/src/build/routes.ts +24 -15
- package/src/build/seed-ids.ts +65 -0
- package/src/build/seed-writes.ts +111 -0
- package/src/build/static-headers.ts +2 -2
- package/src/build/static.ts +1 -1
- package/src/cli/check-cache.ts +51 -0
- package/src/cli/check-consent.ts +95 -0
- package/src/cli/check-forms.ts +2 -2
- package/src/cli/check-links-patterns.ts +101 -0
- package/src/cli/check-links.ts +16 -100
- package/src/cli/check-regions.ts +185 -0
- package/src/cli/check-security.ts +57 -6
- package/src/cli/check.ts +40 -17
- package/src/cli/commands.ts +134 -14
- package/src/cli/docs.ts +21 -2
- package/src/cli/index.ts +1 -1
- package/src/cli/inspect.ts +2 -0
- package/src/cli/mcp-tools.ts +2 -2
- package/src/cli/new.ts +9 -5
- package/src/cli/upgrade-names.ts +14 -2
- package/src/cli/upgrade.ts +3 -0
- package/src/compiler/analyze.ts +18 -4
- package/src/compiler/cacheability.ts +24 -2
- package/src/compiler/compliance-contrast.ts +284 -0
- package/src/compiler/compliance-empty.ts +24 -0
- package/src/compiler/compliance-rgaa-content.ts +95 -0
- package/src/compiler/compliance-rgaa-criteria.ts +45 -0
- package/src/compiler/compliance-rgaa-pages.ts +140 -0
- package/src/compiler/compliance-rgaa.ts +19 -0
- package/src/compiler/compliance-third-party.ts +59 -0
- package/src/compiler/compliance-urls.ts +52 -0
- package/src/compiler/compliance.ts +72 -42
- package/src/compiler/cookie-inventory.ts +119 -0
- package/src/compiler/dom-attrs.ts +4 -1
- package/src/compiler/emit.ts +1 -1
- package/src/compiler/foreign-imports.ts +5 -3
- package/src/compiler/mistakes.ts +18 -9
- package/src/compiler/props-pattern.ts +211 -0
- package/src/compiler/props.ts +177 -346
- package/src/compiler/shared.ts +9 -16
- package/src/compiler/ssr-emit.ts +510 -0
- package/src/compiler/ssr-helpers.ts +170 -121
- package/src/compiler/ssr.ts +25 -440
- package/src/context.ts +14 -1
- package/src/dev/child.ts +1 -1
- package/src/dev/hot-islands.ts +71 -0
- package/src/dev/index.ts +31 -18
- package/src/dev/protocol.ts +1 -1
- package/src/dev/queue.ts +3 -2
- package/src/dev/reload.ts +1 -1
- package/src/dev/supervisor.ts +3 -1
- package/src/dev/watchers.ts +6 -2
- package/src/dom/action.ts +97 -14
- package/src/dom/attrs.ts +8 -0
- package/src/dom/extras.ts +2 -1
- package/src/dom/field-marks.ts +24 -0
- package/src/dom/hot.ts +9 -0
- package/src/dom/index.ts +25 -5
- package/src/dom/island-hot.ts +29 -0
- package/src/dom/island.ts +13 -2
- package/src/dom/prefetch.ts +132 -0
- package/src/dom/regions.ts +498 -0
- package/src/dom/swap.ts +245 -0
- package/src/dom/trusted.ts +22 -0
- package/src/dom/upload.ts +44 -0
- package/src/eco/declaration.ts +39 -40
- package/src/eco/index.ts +5 -5
- package/src/href.ts +31 -0
- package/src/index.ts +9 -3
- package/src/plugins/config.ts +1 -1
- package/src/plugins/context.ts +7 -1
- package/src/plugins/daily.ts +27 -0
- package/src/plugins/index.ts +3 -3
- package/src/plugins/order.ts +1 -1
- package/src/plugins/public.ts +8 -5
- package/src/plugins/services.ts +88 -14
- package/src/plugins/types.ts +121 -10
- package/src/reactivity/hmr.ts +90 -0
- package/src/reactivity/index.ts +38 -18
- package/src/reactivity/resource.ts +115 -0
- package/src/reactivity/seed.ts +39 -0
- package/src/reactivity/server-seed.ts +194 -0
- package/src/reactivity/store.ts +55 -1
- package/src/rgpd/draft.ts +171 -0
- package/src/rgpd/forms.ts +85 -0
- package/src/rgpd/index.ts +57 -0
- package/src/server/action-flash.ts +1 -0
- package/src/server/action-registry.ts +6 -8
- package/src/server/action.ts +51 -19
- package/src/server/app-secret.ts +22 -17
- package/src/server/cache-invalidation.ts +96 -0
- package/src/server/compress.ts +3 -1
- package/src/server/consent.ts +16 -2
- package/src/server/cookie-inventory.ts +78 -0
- package/src/server/cookies.ts +50 -0
- package/src/server/csp-report.ts +86 -0
- package/src/server/discard.ts +13 -0
- package/src/server/document.ts +7 -4
- package/src/server/env.ts +1 -1
- package/src/server/errors.ts +9 -2
- package/src/server/field-errors.ts +91 -0
- package/src/server/form-schema.ts +16 -11
- package/src/server/health.ts +35 -14
- package/src/server/http.ts +25 -10
- package/src/server/index.ts +102 -299
- package/src/server/loader.ts +1 -0
- package/src/server/page.ts +11 -24
- package/src/server/plugin-host.ts +26 -8
- package/src/server/public.ts +14 -3
- package/src/server/rate-limit.ts +39 -10
- package/src/server/region.ts +3 -0
- package/src/server/request-handler.ts +370 -0
- package/src/server/request-log.ts +94 -0
- package/src/server/route-cache.ts +41 -6
- package/src/server/route-input.ts +54 -0
- package/src/server/route-table.ts +35 -19
- package/src/server/routing.ts +12 -11
- package/src/server/sanitize-html.ts +1 -1
- package/src/server/security.ts +81 -20
- package/src/server/serve-handlers.ts +9 -5
- package/src/server/shared-store.ts +314 -0
- package/src/server/start.ts +12 -5
- package/src/server/static-dir.ts +14 -10
- package/src/server/stream.ts +2 -1
- package/src/server/surface.ts +39 -0
- package/src/server/webhook.ts +48 -0
- package/src/server/workers.ts +168 -0
- package/src/ssr/consent-banner.ts +20 -16
- package/src/ssr/consent-texts.ts +40 -0
- package/src/ssr/context.ts +26 -3
- package/src/ssr/cookie-table.ts +75 -0
- package/src/ssr/index.ts +23 -13
- package/src/ssr/navigation.ts +161 -14
- package/src/test/browser.ts +50 -22
- package/src/test/build-reuse.ts +70 -0
- package/src/test/index.ts +45 -6
- package/src/test/mount.ts +53 -0
- package/src/test/outside.ts +94 -0
- package/templates/_shared/AGENTS.md +1 -1
- package/templates/_shared/Dockerfile +22 -0
- package/templates/_shared/dockerignore +9 -0
- package/templates/_shared/gitignore +2 -0
- package/templates/app/.env.example +3 -1
- package/templates/app/compose.yaml +32 -0
- package/templates/app/db/migrations/001_notes.sql +7 -0
- package/templates/app/db/schema.ts +11 -0
- package/templates/app/package.json +1 -0
- package/templates/app/prunelle.config.ts +6 -0
- package/templates/app/src/actions/notes.ts +26 -0
- package/templates/app/src/auth.ts +4 -2
- package/templates/app/src/db.ts +5 -0
- package/templates/app/src/routes/dashboard/index.tsx +26 -1
- package/templates/app/src/routes/privacy.tsx +6 -2
- package/templates/app/tests/app.test.ts +14 -3
- package/templates/plugin/AGENTS.md +11 -0
- package/templates/plugin/CLAUDE.md +1 -0
- package/templates/plugin/README.md +27 -0
- package/templates/plugin/gitignore +2 -0
- package/templates/plugin/llms.txt +19 -0
- package/templates/plugin/package.json +33 -0
- package/templates/plugin/src/index.ts +40 -0
- package/templates/plugin/tests/fixture/prunelle.config.ts +4 -0
- package/templates/plugin/tests/fixture/src/routes/index.tsx +11 -0
- package/templates/plugin/tests/plugin.test.ts +42 -0
- package/templates/plugin/tsconfig.json +19 -0
- package/ts-plugin.cjs +3674 -2196
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// What a `testApp` controls outside the app: the clock it reads, and the answers to the requests it sends out.
|
|
2
|
+
|
|
3
|
+
import { setSystemTime } from 'bun:test'
|
|
4
|
+
|
|
5
|
+
export interface TestClock {
|
|
6
|
+
/** Sets the time `Date.now()` and `new Date()` give the app, its plugins and the test, until `dispose()`. */
|
|
7
|
+
set: (time: Date | number | string) => void
|
|
8
|
+
/** Moves the clock `ms` forward from where it stands. */
|
|
9
|
+
advance: (ms: number) => void
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function testClock(): { clock: TestClock, restore: () => void } {
|
|
13
|
+
let moved = false
|
|
14
|
+
const set = (time: Date | number | string): void => {
|
|
15
|
+
moved = true
|
|
16
|
+
setSystemTime(new Date(time))
|
|
17
|
+
}
|
|
18
|
+
return {
|
|
19
|
+
clock: { set, advance: ms => set(Date.now() + ms) },
|
|
20
|
+
restore() {
|
|
21
|
+
if (moved)
|
|
22
|
+
setSystemTime()
|
|
23
|
+
moved = false
|
|
24
|
+
},
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export type StubAnswer = Response | ((request: Request) => Response | Promise<Response>)
|
|
29
|
+
|
|
30
|
+
interface Guard {
|
|
31
|
+
stubs: Array<{ matches: (url: URL) => boolean, answer: StubAnswer }>
|
|
32
|
+
unanswered: string[]
|
|
33
|
+
errors: string[]
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const LOOPBACK = new Set(['localhost', '127.0.0.1', '[::1]'])
|
|
37
|
+
const nativeFetch = globalThis.fetch
|
|
38
|
+
const guards = new Set<Guard>()
|
|
39
|
+
const patched = Object.assign(guardedFetch, { preconnect: nativeFetch.preconnect }) as typeof fetch
|
|
40
|
+
|
|
41
|
+
function stubFor(url: URL): StubAnswer | undefined {
|
|
42
|
+
for (const guard of [...guards].reverse()) {
|
|
43
|
+
const stub = guard.stubs.findLast(s => s.matches(url))
|
|
44
|
+
if (stub !== undefined)
|
|
45
|
+
return stub.answer
|
|
46
|
+
}
|
|
47
|
+
return undefined
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async function guardedFetch(input: string | URL | Request, init?: RequestInit): Promise<Response> {
|
|
51
|
+
const url = guards.size === 0 ? null : URL.parse(input instanceof Request ? input.url : input)
|
|
52
|
+
if (url === null)
|
|
53
|
+
return nativeFetch(input, init)
|
|
54
|
+
const answer = stubFor(url)
|
|
55
|
+
if (answer !== undefined)
|
|
56
|
+
return answer instanceof Response ? answer.clone() : await answer(new Request(input, init))
|
|
57
|
+
if (LOOPBACK.has(url.hostname) || !url.protocol.startsWith('http'))
|
|
58
|
+
return nativeFetch(input, init)
|
|
59
|
+
const sent = `${init?.method ?? (input instanceof Request ? input.method : 'GET')} ${url.href}`
|
|
60
|
+
for (const guard of guards) {
|
|
61
|
+
guard.unanswered.push(sent)
|
|
62
|
+
guard.errors.push(`fetch ${sent}: no app.stub() answers it`)
|
|
63
|
+
}
|
|
64
|
+
throw new Error(`prunelle: testApp: the app sent ${sent}, which no app.stub() answers: stub it, or send it to a loopback server of the test.`)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Refuses the requests the app sends outside the machine while the testApp lives, unless a stub answers them; a test that replaced `fetch` with its own mock keeps it. */
|
|
68
|
+
export function guardOutgoing(errors: string[]): { stub: (url: string | RegExp, answer: StubAnswer) => void, release: () => void } {
|
|
69
|
+
const guard: Guard = { stubs: [], unanswered: [], errors }
|
|
70
|
+
// Only the process's own fetch is wrapped: wrapping a mock that calls the fetch it replaced would call itself.
|
|
71
|
+
if (globalThis.fetch === nativeFetch)
|
|
72
|
+
globalThis.fetch = patched
|
|
73
|
+
const guarding = globalThis.fetch === patched
|
|
74
|
+
if (guarding)
|
|
75
|
+
guards.add(guard)
|
|
76
|
+
return {
|
|
77
|
+
stub(url, answer) {
|
|
78
|
+
if (!guarding)
|
|
79
|
+
throw new Error('prunelle: testApp: app.stub() cannot answer while the test has replaced globalThis.fetch with its own mock, which receives every request: answer from that mock, or drop it and stub here.')
|
|
80
|
+
const target = typeof url === 'string' ? new URL(url) : undefined
|
|
81
|
+
const matches = target !== undefined
|
|
82
|
+
? (sent: URL) => sent.origin === target.origin && sent.pathname === target.pathname
|
|
83
|
+
: (sent: URL) => (url as RegExp).test(sent.href)
|
|
84
|
+
guard.stubs.push({ matches, answer })
|
|
85
|
+
},
|
|
86
|
+
release() {
|
|
87
|
+
guards.delete(guard)
|
|
88
|
+
if (guards.size === 0 && globalThis.fetch === patched)
|
|
89
|
+
globalThis.fetch = nativeFetch
|
|
90
|
+
if (guard.unanswered.length > 0)
|
|
91
|
+
throw new Error(`prunelle: testApp: the app sent requests no app.stub() answered: ${guard.unanswered.join(', ')}.`)
|
|
92
|
+
},
|
|
93
|
+
}
|
|
94
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# __APP_NAME__
|
|
2
2
|
|
|
3
|
-
A prunelle app. Read `node_modules/prunelle/llms.txt` before writing code: it holds prunelle's whole API for the version installed here, on one page. When using
|
|
3
|
+
A prunelle app. Read `node_modules/prunelle/llms.txt` before writing code: it holds prunelle's whole API for the version installed here, on one page. When using plugins, also read each installed plugin's `llms.txt` if it ships one (`node_modules/@prunellejs/<plugin>/llms.txt` for first-party ones).
|
|
4
4
|
|
|
5
5
|
## Workflow
|
|
6
6
|
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# The app as one binary on an image holding only glibc and certificates, run by a user without root.
|
|
2
|
+
# docker build -t __APP_NAME__ . && docker run -p 127.0.0.1:3000:3000 __APP_NAME__
|
|
3
|
+
|
|
4
|
+
FROM oven/bun:__BUN_VERSION__ AS build
|
|
5
|
+
WORKDIR /app
|
|
6
|
+
COPY package.json bun.lock ./
|
|
7
|
+
RUN bun install --frozen-lockfile
|
|
8
|
+
COPY . .
|
|
9
|
+
# The image ships the data folder empty, whatever the build opened in it.
|
|
10
|
+
RUN bunx prunelle build --compile server && rm -rf data && mkdir data
|
|
11
|
+
|
|
12
|
+
FROM gcr.io/distroless/base-debian12
|
|
13
|
+
WORKDIR /app
|
|
14
|
+
COPY --from=build /app/server ./server
|
|
15
|
+
# SQLite files go here; a mounted folder must be writable by uid 1000.
|
|
16
|
+
COPY --from=build --chown=1000:1000 /app/data ./data
|
|
17
|
+
USER 1000:1000
|
|
18
|
+
# Inside the container the server listens on every interface; publish its port on 127.0.0.1 and put a proxy in front.
|
|
19
|
+
ENV HOST=0.0.0.0 PORT=3000
|
|
20
|
+
EXPOSE 3000
|
|
21
|
+
HEALTHCHECK --interval=30s --timeout=3s CMD ["./server", "--health"]
|
|
22
|
+
CMD ["./server"]
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
# Generate a 32+ byte secret for production, e.g.:
|
|
2
2
|
# openssl rand -base64 32
|
|
3
3
|
AUTH_SECRET=
|
|
4
|
-
|
|
4
|
+
DATABASE=./data/app.db
|
|
5
|
+
# The address the app is served at, e.g. https://example.com
|
|
6
|
+
SITE=
|
|
5
7
|
|
|
6
8
|
# The SMTP server and the sender of sign-up confirmations and sign-in links, e.g. smtp://user:pass@smtp.example.com:587 and hello@example.com
|
|
7
9
|
MAIL_URL=
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# docker compose up -d --build, after `mkdir data-prod && sudo chown 1000:1000 data-prod` and the four settings in .env.
|
|
2
|
+
# Expected server layout:
|
|
3
|
+
# compose.yaml
|
|
4
|
+
# .env AUTH_SECRET, MAIL_URL, MAIL_FROM, SITE
|
|
5
|
+
# data-prod/ the SQLite database, owned by uid 1000
|
|
6
|
+
|
|
7
|
+
services:
|
|
8
|
+
app:
|
|
9
|
+
build: .
|
|
10
|
+
image: __APP_NAME__
|
|
11
|
+
restart: unless-stopped
|
|
12
|
+
environment:
|
|
13
|
+
AUTH_SECRET: ${AUTH_SECRET:?set AUTH_SECRET in .env (openssl rand -base64 32)}
|
|
14
|
+
MAIL_URL: ${MAIL_URL:?set MAIL_URL in .env}
|
|
15
|
+
MAIL_FROM: ${MAIL_FROM:?set MAIL_FROM in .env}
|
|
16
|
+
SITE: ${SITE:?set SITE in .env to the address the app is served at, e.g. https://example.com}
|
|
17
|
+
DATABASE: data/app.db
|
|
18
|
+
ports:
|
|
19
|
+
# Loopback only: the proxy in front ends TLS and is the one thing on a public interface.
|
|
20
|
+
- '127.0.0.1:${PORT:-3000}:3000'
|
|
21
|
+
volumes:
|
|
22
|
+
- type: bind
|
|
23
|
+
source: ./data-prod
|
|
24
|
+
target: /app/data
|
|
25
|
+
bind: { create_host_path: false }
|
|
26
|
+
read_only: true
|
|
27
|
+
tmpfs: [/tmp]
|
|
28
|
+
cap_drop: [ALL]
|
|
29
|
+
security_opt: [no-new-privileges:true]
|
|
30
|
+
logging:
|
|
31
|
+
driver: json-file
|
|
32
|
+
options: { max-size: 10m, max-file: '3' }
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { defineSchema } from '@prunellejs/db'
|
|
2
|
+
|
|
3
|
+
// What SQL cannot say: which columns are personal and why, and whose rows they are. Auth exports and erases a user's notes with their account, and `prunelle rgpd --draft` lists them.
|
|
4
|
+
export default defineSchema({
|
|
5
|
+
notes: {
|
|
6
|
+
owner: 'user_id',
|
|
7
|
+
personal: { body: 'le texte des notes' },
|
|
8
|
+
purpose: 'Garder les notes que vous écrivez.',
|
|
9
|
+
legalBasis: 'Exécution du contrat (RGPD art. 6.1.b).',
|
|
10
|
+
},
|
|
11
|
+
})
|
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
import { ui } from '@prunellejs/ui/plugin'
|
|
2
2
|
import { defineConfig } from 'prunelle/config'
|
|
3
3
|
import { auth } from './src/auth'
|
|
4
|
+
import { db } from './src/db'
|
|
4
5
|
import { mail } from './src/mail'
|
|
5
6
|
|
|
6
7
|
export default defineConfig({
|
|
7
8
|
lang: 'en',
|
|
9
|
+
// The address the app is served at, for the links of mails sent outside a request, such as the warning before an inactive account is deleted.
|
|
10
|
+
site: process.env.SITE || undefined,
|
|
11
|
+
// The database of every process: accounts, notes and rate limits. A relative path lands under the app's folder, out of dist/.
|
|
12
|
+
store: process.env.DATABASE || 'data/app.db',
|
|
8
13
|
plugins: [
|
|
9
14
|
ui({ grammar: 'editorial' }),
|
|
10
15
|
mail,
|
|
11
16
|
auth,
|
|
17
|
+
db,
|
|
12
18
|
],
|
|
13
19
|
})
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { StandardSchemaV1 } from 'prunelle/server'
|
|
2
|
+
import { action } from 'prunelle/server'
|
|
3
|
+
import { db } from '../db'
|
|
4
|
+
|
|
5
|
+
const noteSchema: StandardSchemaV1<{ body: string }> = {
|
|
6
|
+
'~standard': {
|
|
7
|
+
version: 1,
|
|
8
|
+
vendor: 'prunelle',
|
|
9
|
+
// Read by prunelle check, and by the page, which gets `required` and `maxlength` on the field from it.
|
|
10
|
+
jsonSchema: { input: () => ({ type: 'object', properties: { body: { type: 'string', minLength: 1, maxLength: 2000 } }, required: ['body'] }) },
|
|
11
|
+
validate(raw: unknown) {
|
|
12
|
+
const body = String((raw as { body?: unknown })?.body ?? '').trim()
|
|
13
|
+
if (body === '' || body.length > 2000)
|
|
14
|
+
return { issues: [{ message: 'Write a note of 1 to 2000 characters', path: ['body'] }] }
|
|
15
|
+
return { value: { body } }
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const addNote = action(noteSchema, async ({ body }, ctx) => {
|
|
21
|
+
const user = ctx.locals.user
|
|
22
|
+
if (!user)
|
|
23
|
+
return ctx.deny(401, 'Sign in to write a note')
|
|
24
|
+
await db.sql`insert into notes (user_id, body, created_at) values (${user.id}, ${body}, ${Date.now()})`
|
|
25
|
+
return ctx.redirect('/dashboard')
|
|
26
|
+
})
|
|
@@ -4,9 +4,11 @@ import { mail } from './mail'
|
|
|
4
4
|
|
|
5
5
|
// Set AUTH_SECRET (at least 32 bytes) in production — see .env.example.
|
|
6
6
|
export const auth = createAuth({
|
|
7
|
-
//
|
|
8
|
-
store: sqliteAuthStore(process.env.
|
|
7
|
+
// The `store` of prunelle.config.ts, opened here too so a test or a script reaches the accounts.
|
|
8
|
+
store: sqliteAuthStore(process.env.DATABASE || 'data/app.db'),
|
|
9
9
|
secret: process.env.AUTH_SECRET || undefined,
|
|
10
10
|
defaultRedirect: '/dashboard',
|
|
11
11
|
mailer: mail,
|
|
12
|
+
// An account nobody signs in to for 2 years is deleted, its owner mailed 30 days before.
|
|
13
|
+
inactivity: true,
|
|
12
14
|
})
|
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
import type { PageProps } from 'prunelle'
|
|
2
|
-
import { Button, Card, CardBody, CardHeader, Checkbox, Cluster, Notice, Stack } from '@prunellejs/ui'
|
|
2
|
+
import { Button, Card, CardBody, CardHeader, Checkbox, Cluster, Field, Notice, Stack } from '@prunellejs/ui'
|
|
3
3
|
import { Head } from 'prunelle'
|
|
4
|
+
import { getActionError } from 'prunelle/server'
|
|
5
|
+
import { addNote } from '../../actions/notes'
|
|
4
6
|
import { auth } from '../../auth'
|
|
7
|
+
import { db } from '../../db'
|
|
8
|
+
|
|
9
|
+
interface Note { id: number, body: string }
|
|
5
10
|
|
|
6
11
|
export default async function DashboardPage({ locals, url }: PageProps) {
|
|
7
12
|
// A refused export or deletion comes back here with a code naming why.
|
|
8
13
|
const message = auth.formMessage(url)
|
|
9
14
|
const refusal = message?.form === 'account' ? message : undefined
|
|
15
|
+
const notes: Note[] = await db.sql`select id, body from notes where user_id = ${locals.user!.id} order by created_at desc, id desc`
|
|
16
|
+
const noteError = getActionError(locals)?.fieldErrors?.body
|
|
10
17
|
|
|
11
18
|
return (
|
|
12
19
|
<Stack gap="lg">
|
|
@@ -17,6 +24,24 @@ export default async function DashboardPage({ locals, url }: PageProps) {
|
|
|
17
24
|
<p class="m-0">Signed in as <strong>{locals.user?.email}</strong>.</p>
|
|
18
25
|
</CardBody>
|
|
19
26
|
</Card>
|
|
27
|
+
<Card>
|
|
28
|
+
<CardHeader><h2 class="card-title">Your notes</h2></CardHeader>
|
|
29
|
+
<CardBody>
|
|
30
|
+
<Stack gap="md">
|
|
31
|
+
<form action={addNote} method="post">
|
|
32
|
+
<Stack gap="sm">
|
|
33
|
+
<Field id="note-body" label="New note" error={noteError} required><textarea id="note-body" name="body" rows="3" /></Field>
|
|
34
|
+
<Cluster>
|
|
35
|
+
<Button type="submit">Add the note</Button>
|
|
36
|
+
</Cluster>
|
|
37
|
+
</Stack>
|
|
38
|
+
</form>
|
|
39
|
+
{notes.length === 0
|
|
40
|
+
? <p class="m-0">No notes yet.</p>
|
|
41
|
+
: <ul>{notes.map(note => <li>{note.body}</li>)}</ul>}
|
|
42
|
+
</Stack>
|
|
43
|
+
</CardBody>
|
|
44
|
+
</Card>
|
|
20
45
|
<Card>
|
|
21
46
|
<CardHeader><h2 class="card-title">Your data</h2></CardHeader>
|
|
22
47
|
<CardBody>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Head } from 'prunelle'
|
|
1
|
+
import { CookieTable, Head } from 'prunelle'
|
|
2
2
|
|
|
3
3
|
// What the RGPD (art. 13) asks to tell people when their data is collected, written for what @prunellejs/auth stores by default; `prunelle check` warns until every placeholder below is replaced.
|
|
4
4
|
// Change it when the app collects more, or when you change the auth plugin's storeIp, storeUserAgent or sessionTtlSeconds.
|
|
@@ -13,9 +13,13 @@ export default function Privacy() {
|
|
|
13
13
|
<p>__APP_NAME__ is run by [to fill in: your name or your company's, as on the legal notice]. For any question about your data, write to [to fill in: a contact email].</p>
|
|
14
14
|
<h2>What we collect and why</h2>
|
|
15
15
|
<p>To create your account and sign you in: your email address and a hash of your password, never the password itself. This is needed to provide the service you sign up for (RGPD art. 6.1.b).</p>
|
|
16
|
+
<p>To keep the notes you write: their text, for the same reason.</p>
|
|
16
17
|
<p>To keep you signed in and protect your account: a session cookie, which the site cannot work without and which therefore needs no consent, and for each session the name of your browser and a shortened IP address with its last part removed.</p>
|
|
17
18
|
<h2>How long we keep it</h2>
|
|
18
|
-
<p>A session ends 30 days after your last visit, or when you sign out, and is then deleted. An account whose email address is not confirmed within 7 days is deleted. Your account
|
|
19
|
+
<p>A session ends 30 days after your last visit, or when you sign out, and is then deleted. An account whose email address is not confirmed within 7 days is deleted. Your account and your notes are kept until you delete the account from your dashboard.</p>
|
|
20
|
+
<h2>Cookies</h2>
|
|
21
|
+
<p>Every cookie this site sets is essential to it, so none waits for your consent:</p>
|
|
22
|
+
<CookieTable />
|
|
19
23
|
<h2>Who receives it</h2>
|
|
20
24
|
<p>Nobody else: the data stays with our host, [to fill in: the host's name], and is not shared or sold.</p>
|
|
21
25
|
<h2>Your rights</h2>
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { TestApp } from 'prunelle/test'
|
|
2
2
|
import { beforeAll, describe, expect, it } from 'bun:test'
|
|
3
|
+
import { Database } from 'bun:sqlite'
|
|
3
4
|
import { mkdtempSync } from 'node:fs'
|
|
4
5
|
import { tmpdir } from 'node:os'
|
|
5
6
|
import { join, resolve } from 'node:path'
|
|
@@ -7,7 +8,7 @@ import { testApp } from 'prunelle/test'
|
|
|
7
8
|
|
|
8
9
|
const root = resolve(import.meta.dir, '..')
|
|
9
10
|
// A file the app and this test both open, so a user the test creates can sign in to the app.
|
|
10
|
-
process.env.
|
|
11
|
+
process.env.DATABASE ??= join(mkdtempSync(join(tmpdir(), '__APP_NAME__-')), 'app.db')
|
|
11
12
|
const { auth } = await import('../src/auth')
|
|
12
13
|
|
|
13
14
|
describe('__APP_NAME__', () => {
|
|
@@ -30,6 +31,7 @@ describe('__APP_NAME__', () => {
|
|
|
30
31
|
|
|
31
32
|
const privacy = await app.get('/privacy')
|
|
32
33
|
expect(privacy.status).toBe(200)
|
|
34
|
+
expect(await privacy.text()).toContain('<td><code>pru_session</code></td><td>Keeps you signed in.</td><td>Essential</td><td>30 days</td>')
|
|
33
35
|
expect(app.errors).toEqual([])
|
|
34
36
|
})
|
|
35
37
|
|
|
@@ -41,7 +43,7 @@ describe('__APP_NAME__', () => {
|
|
|
41
43
|
expect(page).toContain('Invalid email or password')
|
|
42
44
|
})
|
|
43
45
|
|
|
44
|
-
it('lets a signed-in user download their data and delete their account
|
|
46
|
+
it('lets a signed-in user write notes, download them with their data and delete them with their account', async () => {
|
|
45
47
|
const credentials = { email: 'ada@example.com', password: 'correct-horse-battery' }
|
|
46
48
|
await auth.createUser({ ...credentials, emailVerified: true })
|
|
47
49
|
const fromLogin = { referer: 'http://localhost/login' }
|
|
@@ -55,12 +57,21 @@ describe('__APP_NAME__', () => {
|
|
|
55
57
|
expect(refused).toContain('Sign in again to confirm it is you')
|
|
56
58
|
expect(refused).toContain('<a href="/login">Sign in</a>')
|
|
57
59
|
|
|
60
|
+
const { addNote } = await app.import('src/actions/notes.ts') as typeof import('../src/actions/notes')
|
|
61
|
+
expect((await app.submit(addNote, { body: 'Buy milk' }, fromDashboard)).headers.get('location')).toBe('/dashboard')
|
|
62
|
+
expect(await (await app.get('/dashboard')).text()).toContain('<li>Buy milk</li>')
|
|
63
|
+
|
|
58
64
|
const dump = await app.get('/auth/me/export', fromDashboard)
|
|
59
65
|
expect(dump.status).toBe(200)
|
|
60
|
-
|
|
66
|
+
const exported = await dump.json() as { user: { email: string }, data: { notes: { body: string }[] } }
|
|
67
|
+
expect(exported.user.email).toBe('ada@example.com')
|
|
68
|
+
expect(exported.data.notes.map(note => note.body)).toEqual(['Buy milk'])
|
|
61
69
|
|
|
62
70
|
const deleted = await app.submit('/auth/me/delete', { confirm: 'on', redirect: '/' }, fromDashboard)
|
|
63
71
|
expect(deleted.headers.get('location')).toBe('/')
|
|
72
|
+
const database = new Database(process.env.DATABASE)
|
|
73
|
+
expect(database.query('select count(*) as n from notes').get()).toEqual({ n: 0 })
|
|
74
|
+
database.close()
|
|
64
75
|
expect((await app.get('/dashboard')).status).toBe(302)
|
|
65
76
|
expect((await app.submit('/auth/signin', credentials, fromLogin)).headers.get('location')).toBe('/login?error=signin.invalid-credentials')
|
|
66
77
|
})
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# __APP_NAME__
|
|
2
|
+
|
|
3
|
+
A prunelle plugin. Read `node_modules/prunelle/llms.txt` before writing code: it holds prunelle's whole API, the `PrunellePlugin` hooks included, for the version installed here.
|
|
4
|
+
|
|
5
|
+
## Workflow
|
|
6
|
+
|
|
7
|
+
- **Verify changes**: `bun test` (the plugin mounted on `tests/fixture` with `testApp` from `prunelle/test`) and `bun run check` (TypeScript).
|
|
8
|
+
- **Keep `llms.txt` current**: it is what an agent working on an app reads to use this plugin, and `prunelle docs` searches it. A change to an option or an export updates it in the same commit.
|
|
9
|
+
- **Report mistakes early**: a misused option throws from the factory, what may be intended is a `ctx.warn()` in `check()`, and what production cannot run without is a message from `requires()`. Each names the option and its fix.
|
|
10
|
+
|
|
11
|
+
@node_modules/prunelle/llms.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@AGENTS.md
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# __APP_NAME__
|
|
2
|
+
|
|
3
|
+
A [prunelle](https://prunelle.kaynooo.fr) plugin serving `/.well-known/security.txt`.
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
bun add __APP_NAME__
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
// prunelle.config.ts
|
|
11
|
+
import { defineConfig } from 'prunelle/config'
|
|
12
|
+
import { securityTxt } from '__APP_NAME__'
|
|
13
|
+
|
|
14
|
+
export default defineConfig({ plugins: [securityTxt({ contact: 'mailto:security@example.com', expires: '2027-06-30' })] })
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
`llms.txt` documents the options for coding agents, and `prunelle docs` searches it in any app that installs the plugin.
|
|
18
|
+
|
|
19
|
+
## Developing
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
bun install
|
|
23
|
+
bun test
|
|
24
|
+
bun run check
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
The tests mount the plugin on the app in `tests/fixture` with `testApp` from `prunelle/test`, in-process and with no port bound. [Writing a plugin](https://prunelle.kaynooo.fr/docs/production/writing-a-plugin) covers each hook and how to publish.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# __APP_NAME__ Reference
|
|
2
|
+
|
|
3
|
+
> A prunelle plugin serving `/.well-known/security.txt` (RFC 9116): where to report a vulnerability, and until when that address holds.
|
|
4
|
+
|
|
5
|
+
## Imports
|
|
6
|
+
|
|
7
|
+
- `__APP_NAME__`: `securityTxt`; type `SecurityTxtOptions`.
|
|
8
|
+
|
|
9
|
+
## Setup (`securityTxt(options)`)
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import { defineConfig } from 'prunelle/config'
|
|
13
|
+
import { securityTxt } from '__APP_NAME__'
|
|
14
|
+
|
|
15
|
+
export default defineConfig({ plugins: [securityTxt({ contact: 'mailto:security@example.com', expires: '2027-06-30' })] })
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
- `contact`: a `mailto:` or `https://` URL; anything else throws as the config loads.
|
|
19
|
+
- `expires`: an ISO 8601 date, served in full (`2027-06-30T00:00:00.000Z`). One that is not a date throws; one more than a year ahead is a `prunelle check` warning; once it has passed, a production start refuses through `requires()`.
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "__APP_NAME__",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A prunelle plugin serving /.well-known/security.txt",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"files": [
|
|
8
|
+
"src",
|
|
9
|
+
"llms.txt"
|
|
10
|
+
],
|
|
11
|
+
"exports": {
|
|
12
|
+
".": "./src/index.ts"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"prunelle",
|
|
16
|
+
"prunelle-plugin"
|
|
17
|
+
],
|
|
18
|
+
"engines": {
|
|
19
|
+
"bun": ">=1.4.0"
|
|
20
|
+
},
|
|
21
|
+
"scripts": {
|
|
22
|
+
"check": "tsc",
|
|
23
|
+
"test": "bun test"
|
|
24
|
+
},
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"prunelle": "__PRUNELLE_VERSION__"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@types/bun": "^1.4.4",
|
|
30
|
+
"prunelle": "__PRUNELLE_VERSION__",
|
|
31
|
+
"typescript": "^6.0.3"
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// A prunelle plugin serving /.well-known/security.txt (RFC 9116): where to report a vulnerability, and until when that address holds.
|
|
2
|
+
|
|
3
|
+
import type { PrunellePlugin } from 'prunelle/config'
|
|
4
|
+
import { definePlugin } from 'prunelle/config'
|
|
5
|
+
|
|
6
|
+
export interface SecurityTxtOptions {
|
|
7
|
+
/** Where to report a vulnerability: a `mailto:` or `https://` URL. */
|
|
8
|
+
contact: string
|
|
9
|
+
/** When the file goes stale, as an ISO 8601 date such as `2027-06-30`: RFC 9116 asks for less than a year ahead. */
|
|
10
|
+
expires: string
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const CONTACT_RE = /^(?:mailto:|https:\/\/)\S+$/
|
|
14
|
+
const YEAR_MS = 365 * 24 * 60 * 60 * 1000
|
|
15
|
+
|
|
16
|
+
export function securityTxt(options: SecurityTxtOptions): PrunellePlugin {
|
|
17
|
+
// A misuse throws as the config loads, the earliest a plugin can report it, naming the option and its fix.
|
|
18
|
+
if (!CONTACT_RE.test(options.contact))
|
|
19
|
+
throw new Error(`__APP_NAME__: contact "${options.contact}" is neither a mailto: nor an https:// URL: give the address reports go to, such as mailto:security@example.com.`)
|
|
20
|
+
const expires = Date.parse(options.expires)
|
|
21
|
+
if (Number.isNaN(expires))
|
|
22
|
+
throw new Error(`__APP_NAME__: expires "${options.expires}" is not a date: give one such as 2027-06-30.`)
|
|
23
|
+
const body = `Contact: ${options.contact}\nExpires: ${new Date(expires).toISOString()}\n`
|
|
24
|
+
|
|
25
|
+
return definePlugin({
|
|
26
|
+
name: '__APP_NAME__',
|
|
27
|
+
server(api) {
|
|
28
|
+
api.route('GET', '/.well-known/security.txt', () => new Response(body, { headers: { 'content-type': 'text/plain; charset=utf-8' } }))
|
|
29
|
+
},
|
|
30
|
+
// What may be intended: `prunelle check` warns, and fails only under --strict.
|
|
31
|
+
check(ctx) {
|
|
32
|
+
if (expires - Date.now() > YEAR_MS)
|
|
33
|
+
ctx.warn(`__APP_NAME__: expires ${options.expires} is more than a year ahead, and RFC 9116 asks for less so a stale contact does not linger: set an earlier date.`)
|
|
34
|
+
},
|
|
35
|
+
// What production cannot run without: a production start refuses while any message is returned, and dev, tests and check warn, each after the plugin's name.
|
|
36
|
+
requires() {
|
|
37
|
+
return expires <= Date.now() ? [`security.txt expired on ${options.expires}, so reporters are told not to trust it: set \`expires\` to a date less than a year ahead.`] : []
|
|
38
|
+
},
|
|
39
|
+
})
|
|
40
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { describe, expect, it } from 'bun:test'
|
|
2
|
+
import { join } from 'node:path'
|
|
3
|
+
import { testApp } from 'prunelle/test'
|
|
4
|
+
import { securityTxt } from '../src/index'
|
|
5
|
+
|
|
6
|
+
// The app the plugin is mounted on: `testApp` builds it in-process, with no port bound.
|
|
7
|
+
const root = join(import.meta.dir, 'fixture')
|
|
8
|
+
const DAY_MS = 24 * 60 * 60 * 1000
|
|
9
|
+
const daysFromNow = (days: number): string => new Date(Date.now() + days * DAY_MS).toISOString()
|
|
10
|
+
|
|
11
|
+
function checkWarnings(plugin: ReturnType<typeof securityTxt>): string[] {
|
|
12
|
+
const warnings: string[] = []
|
|
13
|
+
plugin.check?.({ root, routesDir: join(root, 'src/routes'), error: message => warnings.push(`error: ${message}`), warn: message => warnings.push(message) })
|
|
14
|
+
return warnings
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
describe('__APP_NAME__', () => {
|
|
18
|
+
it('serves the contact and the expiry date, written in full as RFC 9116 asks, at /.well-known/security.txt', async () => {
|
|
19
|
+
const day = daysFromNow(30).slice(0, 10)
|
|
20
|
+
await using app = await testApp({ root, plugins: [securityTxt({ contact: 'mailto:security@example.com', expires: day })] })
|
|
21
|
+
const res = await app.get('/.well-known/security.txt')
|
|
22
|
+
expect(res.status).toBe(200)
|
|
23
|
+
expect(res.headers.get('content-type')).toBe('text/plain; charset=utf-8')
|
|
24
|
+
expect(await res.text()).toBe(`Contact: mailto:security@example.com\nExpires: ${day}T00:00:00.000Z\n`)
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
it('refuses a contact that is not a mailto: or https:// URL, and an expiry that is not a date', () => {
|
|
28
|
+
expect(() => securityTxt({ contact: 'security@example.com', expires: '2027-06-30' })).toThrow('is neither a mailto: nor an https:// URL')
|
|
29
|
+
expect(() => securityTxt({ contact: 'https://example.com/report', expires: 'next year' })).toThrow('is not a date')
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
it('warns in prunelle check when the expiry is more than a year ahead', () => {
|
|
33
|
+
expect(checkWarnings(securityTxt({ contact: 'mailto:security@example.com', expires: daysFromNow(400) }))).toEqual([expect.stringContaining('is more than a year ahead')])
|
|
34
|
+
expect(checkWarnings(securityTxt({ contact: 'mailto:security@example.com', expires: daysFromNow(300) }))).toEqual([])
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
it('stops a production start once the file has expired', async () => {
|
|
38
|
+
const context = { root, site: undefined, consentCategories: [] }
|
|
39
|
+
expect(await securityTxt({ contact: 'mailto:security@example.com', expires: daysFromNow(-1) }).requires?.(context)).toEqual([expect.stringContaining('security.txt expired on')])
|
|
40
|
+
expect(await securityTxt({ contact: 'mailto:security@example.com', expires: daysFromNow(1) }).requires?.(context)).toEqual([])
|
|
41
|
+
})
|
|
42
|
+
})
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ESNext",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "bundler",
|
|
6
|
+
"jsx": "react-jsx",
|
|
7
|
+
"jsxImportSource": "prunelle",
|
|
8
|
+
"strict": true,
|
|
9
|
+
"noEmit": true,
|
|
10
|
+
"skipLibCheck": true,
|
|
11
|
+
"types": [
|
|
12
|
+
"bun"
|
|
13
|
+
]
|
|
14
|
+
},
|
|
15
|
+
"include": [
|
|
16
|
+
"src",
|
|
17
|
+
"tests"
|
|
18
|
+
]
|
|
19
|
+
}
|