@quatronic/sdk 0.6.1-rc.4 → 0.7.0-rc.10
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 +26 -0
- package/dist/cli/legacy/qdc-sourcemaps.js +237 -0
- package/dist/cli/legacy/qdc-test-report.js +200 -0
- package/dist/cli/skills-postinstall.js +603 -0
- package/dist/cli/skills.js +499 -0
- package/dist/cli/sourcemaps.js +9 -9
- package/dist/cli/test-report.js +2 -2
- package/dist/next/auth/index.js.map +1 -1
- package/dist/next/config/index.js +1 -1
- package/dist/next/config/index.js.map +1 -1
- package/migrations/no-raw-fetch/codemod.mjs +97 -0
- package/migrations/no-raw-fetch/instructions.md +68 -0
- package/migrations/no-raw-fetch/meta.json +6 -0
- package/package.json +17 -6
- package/postinstall.mjs +9 -0
- package/skills/.gitattributes +1 -0
- package/skills/catalog.json +24 -0
- package/skills/qore-add-api-route/SKILL.md +58 -0
- package/skills/qore-add-connection/SKILL.next.md +149 -0
- package/skills/qore-add-connection/SKILL.node.md +160 -0
- package/skills/qore-add-db-table/SKILL.md +88 -0
- package/skills/qore-add-db-table/references/cross-module-reference.md +74 -0
- package/skills/qore-add-feature/SKILL.md +77 -0
- package/skills/qore-add-integration/SKILL.next.md +217 -0
- package/skills/qore-add-integration/SKILL.node.md +216 -0
- package/skills/qore-add-page/SKILL.md +53 -0
- package/skills/qore-author-skill/SKILL.md +136 -0
- package/skills/qore-debug-issue/SKILL.md +48 -0
- package/skills/qore-enable-auth-method/SKILL.md +91 -0
- package/skills/qore-observability/SKILL.md +89 -0
- package/skills/qore-observability/references/errors.md +87 -0
- package/skills/qore-observability/references/logs.md +69 -0
- package/skills/qore-observability/references/tracing.md +58 -0
- package/skills/qore-recommended-tools/SKILL.md +58 -0
- package/skills/qore-secure-io/SKILL.md +174 -0
- package/skills/qore-ship-checklist/SKILL.md +80 -0
- package/skills/qore-translate-strings/SKILL.md +36 -0
- package/skills/qore-use-addons/SKILL.md +175 -0
- package/skills/qore-use-database/SKILL.md +222 -0
- package/skills/qore-use-design-system/SKILL.md +76 -0
- package/skills/qore-use-mail-domain/SKILL.next.md +67 -0
- package/skills/qore-use-mail-domain/SKILL.node.md +62 -0
- package/skills/qore-use-permissions/SKILL.md +116 -0
- package/skills/qore-verify-user/SKILL.md +56 -0
- package/dist/next/auth/migrations/0001_init.sql +0 -31
- package/dist/next/auth/migrations/0002_id_token.sql +0 -1
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# Errors
|
|
2
|
+
|
|
3
|
+
## Let it throw
|
|
4
|
+
|
|
5
|
+
Unexpected errors are captured for you:
|
|
6
|
+
{{#if runtime=next}}
|
|
7
|
+
- Route handlers, server actions and server components, through Next's `onRequestError` hook,
|
|
8
|
+
which the SDK wires in `src/instrumentation.ts`.
|
|
9
|
+
- Client components: uncaught errors and unhandled rejections in the browser.
|
|
10
|
+
- Rendering errors that reach `src/app/error.tsx` or `src/app/global-error.tsx`: call
|
|
11
|
+
`Sentry.captureException(error)` in their `useEffect`, because Next handles them before Sentry
|
|
12
|
+
sees them.
|
|
13
|
+
{{else}}
|
|
14
|
+
- Request handlers: the catch-all in `src/index.ts` calls `Sentry.captureException` and answers
|
|
15
|
+
500. Let your route code throw into it.
|
|
16
|
+
- Everything else: uncaught exceptions and unhandled rejections.
|
|
17
|
+
{{/if}}
|
|
18
|
+
|
|
19
|
+
So the default is no error handling at all. Never catch, log and rethrow: that reports one
|
|
20
|
+
failure twice.
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
// Wrong: two reports for one failure, and the log has no stack.
|
|
24
|
+
try {
|
|
25
|
+
await chargeCard(order)
|
|
26
|
+
} catch (err) {
|
|
27
|
+
Sentry.logger.error("charge failed")
|
|
28
|
+
throw err
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Right: put the id on the trace, add context, let it propagate.
|
|
32
|
+
Sentry.getActiveSpan()?.setAttribute("qore.order.id", order.id)
|
|
33
|
+
try {
|
|
34
|
+
await chargeCard(order)
|
|
35
|
+
} catch (err) {
|
|
36
|
+
throw new Error("charge failed", { cause: err })
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Capture what you swallow
|
|
41
|
+
|
|
42
|
+
Call `Sentry.captureException` only where you catch an error **and do not rethrow it** (a
|
|
43
|
+
fallback, a retry that gave up, a loop that must keep running) and the error means a bug or an
|
|
44
|
+
outage:
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
try {
|
|
48
|
+
await syncLedger(ledgerId)
|
|
49
|
+
} catch (err) {
|
|
50
|
+
Sentry.captureException(err, { tags: { "qore.ledger.id": ledgerId } })
|
|
51
|
+
// the next tick retries
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Expected failures are not errors
|
|
56
|
+
|
|
57
|
+
Validation failures, "not found", "not allowed" and duplicate submits are outcomes, not bugs.
|
|
58
|
+
Never capture them.
|
|
59
|
+
{{#if runtime=next}}
|
|
60
|
+
In a server action or route handler, return them as a typed result and throw only for the
|
|
61
|
+
unexpected:
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
const parsed = schema.safeParse(Object.fromEntries(formData))
|
|
65
|
+
if (!parsed.success) return { status: "error", message: "invoice.invalid" }
|
|
66
|
+
await createInvoice(parsed.data) // throws on the unexpected; captured automatically
|
|
67
|
+
```
|
|
68
|
+
{{else}}
|
|
69
|
+
In a route, answer them with a 4xx and throw only for the unexpected.
|
|
70
|
+
{{/if}}
|
|
71
|
+
|
|
72
|
+
Log one as `warn` only when someone will ask about it later (see `logs.md`).
|
|
73
|
+
|
|
74
|
+
## Context
|
|
75
|
+
|
|
76
|
+
- Tags on a capture: `Sentry.captureException(err, { tags: { "qore.invoice.id": id } })`. Ids
|
|
77
|
+
only.
|
|
78
|
+
- Keep error messages stable: no ids in them. Sentry groups on type, message and stack, so a
|
|
79
|
+
per-id message splits one bug into many issues. Ids go in tags or span attributes.
|
|
80
|
+
- Use `fingerprint` only to merge or split a known noisy group, with a comment saying why.
|
|
81
|
+
{{#if runtime=next}}
|
|
82
|
+
|
|
83
|
+
## Isolating a widget
|
|
84
|
+
|
|
85
|
+
Wrap a part of the page that can fail on its own in `Sentry.ErrorBoundary` with a fallback, so
|
|
86
|
+
one broken widget does not blank the page. It reports what it catches.
|
|
87
|
+
{{/if}}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# Logs
|
|
2
|
+
|
|
3
|
+
## Is this log worth it?
|
|
4
|
+
|
|
5
|
+
Write a log only if all of these hold:
|
|
6
|
+
|
|
7
|
+
- It answers a concrete production question ("why was invoice 8f2 not sent?").
|
|
8
|
+
- It is still useful when it fires thousands of times a day.
|
|
9
|
+
- It is not better as a span (timing, flow) or an error (a bug).
|
|
10
|
+
- No exception, span or existing log already says it.
|
|
11
|
+
- It holds no personal data.
|
|
12
|
+
|
|
13
|
+
## Levels
|
|
14
|
+
|
|
15
|
+
| Level | For | Example |
|
|
16
|
+
|---|---|---|
|
|
17
|
+
| `debug` | Detail you need while developing | parsed config |
|
|
18
|
+
| `info` | A business event or a state change | `invoice.sent` |
|
|
19
|
+
| `warn` | An expected failure or anomaly someone may ask about | `invoice.send.rejected` |
|
|
20
|
+
| `error` | A failure you handled; usually next to `captureException` | `ledger.sync.gave_up` |
|
|
21
|
+
|
|
22
|
+
## Shape
|
|
23
|
+
|
|
24
|
+
Keep the message stable and put the data in attributes, so logs group and filter:
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
Sentry.logger.info("invoice sent", { "qore.invoice.id": invoice.id, "qore.invoice.lines": lines.length })
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
To keep values readable in the message as well, use `Sentry.logger.fmt`; the template stays
|
|
31
|
+
groupable and each value also becomes an attribute:
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
Sentry.logger.info(Sentry.logger.fmt`invoice ${invoice.id} sent`)
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Log fields, not whole objects. Log the outcome once, not every step towards it.
|
|
38
|
+
|
|
39
|
+
## Audit events
|
|
40
|
+
|
|
41
|
+
Sign-in and sign-out, permission denials, and changes someone may have to account for are audit
|
|
42
|
+
events. Log them at `info` with `qore.audit.event`:
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
Sentry.logger.info("role granted", {
|
|
46
|
+
"qore.audit.event": "role.granted",
|
|
47
|
+
"qore.role.name": role,
|
|
48
|
+
"qore.target.user": targetUserId,
|
|
49
|
+
})
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
The acting user is already on the scope as `user.id`. Never add their e-mail address or name.
|
|
53
|
+
|
|
54
|
+
## Breadcrumbs
|
|
55
|
+
|
|
56
|
+
Breadcrumbs (fetches, navigation, clicks) are recorded automatically and travel with the next
|
|
57
|
+
error. Add one by hand only for context that matters solely when an error follows; anything you
|
|
58
|
+
would search for on its own is a log.
|
|
59
|
+
|
|
60
|
+
## Replacing `console`{{#if runtime=next}} and `src/lib/log.ts`{{/if}}
|
|
61
|
+
|
|
62
|
+
| Before | After |
|
|
63
|
+
|---|---|
|
|
64
|
+
| `console.log(...)` / `console.info(...)` | `Sentry.logger.info("…", { "qore.<area>.<name>": id })` |
|
|
65
|
+
| `console.warn(...)` | `Sentry.logger.warn(...)` |
|
|
66
|
+
| `console.error("x failed", err)` | let it throw, or `Sentry.captureException(err)` if you swallow it |
|
|
67
|
+
{{#if runtime=next}}
|
|
68
|
+
| `log.info({ event: "auth.login", actor })` | `Sentry.logger.info("auth.login", { "qore.audit.event": "auth.login" })` |
|
|
69
|
+
{{/if}}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# Tracing
|
|
2
|
+
|
|
3
|
+
## Already traced
|
|
4
|
+
|
|
5
|
+
Incoming requests{{#if runtime=next}}, server actions{{/if}}, `fetch` (including calls to other modules via
|
|
6
|
+
`CONN_*_URL`, which carry the trace across) and Postgres queries are spans already. Never wrap
|
|
7
|
+
them in a span of your own.
|
|
8
|
+
|
|
9
|
+
## The span ladder
|
|
10
|
+
|
|
11
|
+
Stop at the first rung that fits:
|
|
12
|
+
|
|
13
|
+
1. **Nothing.** The step is fast, single, and already visible.
|
|
14
|
+
2. **Rely on the automatic span.** A fetch, a query, the request itself.
|
|
15
|
+
3. **Add attributes to the active span.** The cheapest way to make a trace findable:
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
Sentry.getActiveSpan()?.setAttribute("qore.invoice.id", invoice.id)
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
4. **Start a span.** Only for an operation of your own that has several steps or takes
|
|
22
|
+
measurable time, so you can see where the time went:
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
const pdf = await Sentry.startSpan(
|
|
26
|
+
{ name: "invoice.render", op: "function", attributes: { "qore.invoice.id": invoice.id } },
|
|
27
|
+
() => renderInvoicePdf(invoice),
|
|
28
|
+
)
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Never a span per function or per loop iteration, and never around a single query or fetch.
|
|
32
|
+
|
|
33
|
+
## Naming
|
|
34
|
+
|
|
35
|
+
- `name` is a domain verb-noun: `invoice.render`, `order.reconcile`, `ledger.sync`. Not
|
|
36
|
+
`handler`, `process`, `run` or an HTTP shape like `GET /invoices`. It is the first thing a
|
|
37
|
+
teammate reads in the trace.
|
|
38
|
+
- `op` is one of `function` (work inside a request), `task` (background or scheduled work),
|
|
39
|
+
`http.client` (an outbound call the SDK does not trace) or `queue.process` (handling a
|
|
40
|
+
message).
|
|
41
|
+
- Attributes you know up front go in `attributes`; results go on with `span.setAttribute` inside
|
|
42
|
+
the callback.
|
|
43
|
+
|
|
44
|
+
## Errors inside a span
|
|
45
|
+
|
|
46
|
+
A throw inside `startSpan` marks the span failed and propagates. Do not catch it to set a
|
|
47
|
+
status.
|
|
48
|
+
|
|
49
|
+
## Background work
|
|
50
|
+
|
|
51
|
+
Work that no request triggered, such as a timer or a queue consumer, starts its own trace, so it
|
|
52
|
+
does not hang off whichever request happened to be running:
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
await Sentry.startNewTrace(() =>
|
|
56
|
+
Sentry.startSpan({ name: "ledger.sync", op: "task" }, () => syncLedger()),
|
|
57
|
+
)
|
|
58
|
+
```
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: qore-recommended-tools
|
|
3
|
+
description: Optional public Claude Code skills and plugins that pair well with this app, and when to reach for each. Use when asking what tooling to install here, how to set up Claude Code for this app, or for first-time setup.
|
|
4
|
+
allowed-tools: Read
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Recommended tools for this app
|
|
8
|
+
|
|
9
|
+
Optional, public tools that pair well with this app. Nothing here is required —
|
|
10
|
+
the `/qore-*` skills already cover scaffolding. Install what helps.
|
|
11
|
+
|
|
12
|
+
## Plugins (public — `anthropics/claude-plugins-official`)
|
|
13
|
+
|
|
14
|
+
### `superpowers` — the disciplined dev workflow
|
|
15
|
+
|
|
16
|
+
```
|
|
17
|
+
/plugin marketplace add anthropics/claude-plugins-official
|
|
18
|
+
/plugin install superpowers@claude-plugins-official
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
What you get, and when to use it:
|
|
22
|
+
|
|
23
|
+
- **brainstorming** — before any non-trivial feature, to turn a vague idea into
|
|
24
|
+
a design. Then `/qore-add-feature` to scaffold it.
|
|
25
|
+
- **writing-plans** — turn a design into a step-by-step plan for a bigger change.
|
|
26
|
+
- **test-driven-development** — when writing logic; pairs with this app's Vitest
|
|
27
|
+
setup (`pnpm test`).
|
|
28
|
+
- **systematic-debugging** — on a failing test or unexpected behaviour, before
|
|
29
|
+
guessing at fixes.
|
|
30
|
+
- **requesting-code-review** / **receiving-code-review** — before opening or
|
|
31
|
+
merging a PR.
|
|
32
|
+
- **using-git-worktrees** — isolate feature work from your working tree.
|
|
33
|
+
|
|
34
|
+
### `frontend-design` — distinctive, production-grade UI
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
/plugin install frontend-design@claude-plugins-official
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
When: building or restyling pages and components in this app's shadcn/ui +
|
|
41
|
+
Tailwind kit (`src/components/ui`, tokens in `src/styles/theme.css` — the
|
|
42
|
+
single swap-point for tenant theming). Pair it with `/qore-add-page` for
|
|
43
|
+
the page shell.
|
|
44
|
+
|
|
45
|
+
## Built into Claude Code (no install — just run them)
|
|
46
|
+
|
|
47
|
+
- **`/deep-research`** — multi-source, fact-checked research. When: evaluating a
|
|
48
|
+
library, auth pattern, or approach before committing to it.
|
|
49
|
+
- **`/security-review`** — security review of pending changes. When: before
|
|
50
|
+
opening a PR, especially for anything touching auth or per-user data — this
|
|
51
|
+
app handles Keycloak sessions and user-scoped tables, so it is high-value here.
|
|
52
|
+
|
|
53
|
+
> Built-ins ship with Claude Code; if your version doesn't have one, skip it.
|
|
54
|
+
|
|
55
|
+
## The right way — a flow for this app
|
|
56
|
+
|
|
57
|
+
`brainstorming` → `writing-plans` (for big changes) → `/qore-add-*` to scaffold
|
|
58
|
+
→ TDD for logic (`pnpm test`) → `/security-review` → open a PR.
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: qore-secure-io
|
|
3
|
+
description: Use the @quatronic/sdk safe helpers whenever server code touches something a user supplied — a URL to fetch, a file path or upload, a redirect target, or a JSON body — instead of the raw method that looks correct but is the vulnerable one. Also covers wiring the SDK's CSP / security headers. Use when handling untrusted input on the server or setting response security headers.
|
|
4
|
+
allowed-tools: Bash(pnpm:*), Edit, Read
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Handle untrusted input with the SDK safe helpers
|
|
8
|
+
|
|
9
|
+
A handful of ordinary operations produce most web vulnerabilities: fetching a
|
|
10
|
+
URL someone named, opening a file someone named, redirecting somewhere someone
|
|
11
|
+
named, parsing a body someone sent. Each has a short "obvious" version that
|
|
12
|
+
looks correct and is the exploitable one.
|
|
13
|
+
|
|
14
|
+
`@quatronic/sdk` (already a dependency of this app) ships a safe helper for each.
|
|
15
|
+
**Reach for the helper the moment a value comes from a request** — `searchParams`,
|
|
16
|
+
route `params`, headers, cookies, or `await request.json() / .text() / .formData()`.
|
|
17
|
+
The helpers run on the Node server; import them in route handlers, server
|
|
18
|
+
actions and other server code, not in `"use client"` components.
|
|
19
|
+
|
|
20
|
+
> These are opt-in helpers, not magic. Nothing rewrites `fetch(url)` into
|
|
21
|
+
> `safeFetch(url)` for you — this skill is the reminder to pick the safe one.
|
|
22
|
+
|
|
23
|
+
## The traps, and what to use instead
|
|
24
|
+
|
|
25
|
+
| If you were about to write… | It's vulnerable to | Use instead |
|
|
26
|
+
|---|---|---|
|
|
27
|
+
| `fetch(userUrl)` | SSRF (metadata service, internal hosts) | `safeFetch` |
|
|
28
|
+
| `path.join(root, name)` / `path.resolve(...)` | path traversal | `safeJoin` |
|
|
29
|
+
| trusting `file.type` on an upload | content-type spoofing → stored XSS | `assertUpload` |
|
|
30
|
+
| `JSON.parse(await request.text())` | parser DoS (huge / deeply nested) | `parseJsonBounded` |
|
|
31
|
+
| `redirect(searchParams.get("next"))` | open redirect (phishing) | `safeRedirect` |
|
|
32
|
+
|
|
33
|
+
## `safeFetch` — a URL the user named
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
// Wrong. http://169.254.169.254/ is a valid URL; so is a hostname whose DNS
|
|
37
|
+
// points there. A blocklist does not close this.
|
|
38
|
+
const res = await fetch(userSuppliedUrl)
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
import { safeFetch, SafeFetchError } from "@quatronic/sdk/node/net"
|
|
43
|
+
|
|
44
|
+
try {
|
|
45
|
+
const res = await safeFetch(userUrl, {}, { allowHosts: ["api.partner.example"] })
|
|
46
|
+
} catch (err) {
|
|
47
|
+
if (err instanceof SafeFetchError) {
|
|
48
|
+
// err.reason — "blocked_link_local", "protocol", "too_many_redirects", …
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
`safeFetch` vets the hostname, resolves it, vets **every** resolved address, then
|
|
54
|
+
connects to the pinned address (keeping the hostname for SNI/cert/Host). Defaults:
|
|
55
|
+
`https:` only, no redirects, 5 s, 5 MiB. `allowHosts` only ever narrows, and a
|
|
56
|
+
listed host must still resolve to a public address.
|
|
57
|
+
|
|
58
|
+
**Use it for a URL a person supplied** — a webhook someone typed into a form, an
|
|
59
|
+
avatar URL, an RSS feed. To call another wired module use
|
|
60
|
+
`connection(alias).fetch(path)` (see `/qore-add-connection`), not `safeFetch`.
|
|
61
|
+
Need only the vetting (e.g. before opening a socket yourself)? `vetTarget` from the
|
|
62
|
+
same module returns the pinned address.
|
|
63
|
+
|
|
64
|
+
## `safeJoin` / `safeFilename` — a path or filename the user named
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
// Wrong. join(root, "../../etc/passwd") leaves the root; resolve() with an
|
|
68
|
+
// absolute segment is worse. Rejecting ".." misses encoded / absolute escapes.
|
|
69
|
+
const file = path.join(uploadsRoot, name)
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
import { safeJoin, safeFilename, PathEscapeError } from "@quatronic/sdk/node/fspath"
|
|
74
|
+
|
|
75
|
+
const file = safeJoin("/srv/uploads", tenantId, name) // throws PathEscapeError if it escapes
|
|
76
|
+
const stored = safeFilename(userName) // "../../etc/passwd" -> "passwd"
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
`safeJoin` joins, resolves, then checks the result is still under the root — a
|
|
80
|
+
lexical guarantee (it does not follow symlinks; pair with `fs.realpath` where
|
|
81
|
+
untrusted writers can create links). `safeFilename` always returns something
|
|
82
|
+
usable and is a sanitiser, not a validator: two inputs can collapse to the same
|
|
83
|
+
name, so pair it with an id you generated for uniqueness.
|
|
84
|
+
|
|
85
|
+
## `assertUpload` — a file that may not be what it claims
|
|
86
|
+
|
|
87
|
+
```ts
|
|
88
|
+
// Wrong. file.type is copied from the request; an HTML page can declare
|
|
89
|
+
// image/png for free, and serving it back is stored XSS.
|
|
90
|
+
if (!file.type.startsWith("image/")) throw new Error("images only")
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
import { assertUpload, UploadRejectedError } from "@quatronic/sdk/node/fspath"
|
|
95
|
+
|
|
96
|
+
const { filename, mediaType, bytes } = await assertUpload(file, {
|
|
97
|
+
allow: ["image/png", "image/jpeg"],
|
|
98
|
+
maxBytes: 2 * 1024 * 1024,
|
|
99
|
+
})
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Checks size, then the declared type against the allow-list, then the leading
|
|
103
|
+
**bytes** against that declared type. On refusal `UploadRejectedError.reason` is
|
|
104
|
+
`"empty" | "too_large" | "type_not_allowed" | "content_mismatch"`. The allow-list
|
|
105
|
+
may only name types the SDK can verify by content; `image/svg+xml` is deliberately
|
|
106
|
+
not verifiable (an SVG can carry script) — rasterise it or reject it.
|
|
107
|
+
|
|
108
|
+
## `parseJsonBounded` — a JSON body the user sent
|
|
109
|
+
|
|
110
|
+
```ts
|
|
111
|
+
// Wrong. A deeply nested array is small on the wire and expensive to walk.
|
|
112
|
+
const body = JSON.parse(await request.text())
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
```ts
|
|
116
|
+
import { parseJsonBounded, BoundedJsonError } from "@quatronic/sdk/node/parse"
|
|
117
|
+
|
|
118
|
+
const body = parseJsonBounded(await request.text(), { maxBytes: 64 * 1024, maxDepth: 16 })
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
Both bounds are applied **before** `JSON.parse`. Defaults are 1 MiB and depth 32.
|
|
122
|
+
`BoundedJsonError.reason` is `"too_large" | "too_deep" | "malformed"`. It returns
|
|
123
|
+
`unknown` on purpose — validate the result with your own zod schema.
|
|
124
|
+
|
|
125
|
+
## `safeRedirect` — a redirect target the user named
|
|
126
|
+
|
|
127
|
+
```ts
|
|
128
|
+
// Wrong. "https://evil.example" is a fine value for ?redirect=, and a prefix
|
|
129
|
+
// check misses "/\evil.example", which the URL parser normalises to "//evil…".
|
|
130
|
+
redirect(searchParams.get("redirect") ?? "/")
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
```ts
|
|
134
|
+
import { safeRedirect } from "@quatronic/sdk/next/auth"
|
|
135
|
+
|
|
136
|
+
redirect(safeRedirect(searchParams.get("redirect")))
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
`safeRedirect(candidate, fallback = "/")` keeps the candidate only if it resolves
|
|
140
|
+
to a path on the app's own origin; anything absolute, protocol-relative or
|
|
141
|
+
unparseable becomes `fallback` (itself validated the same way).
|
|
142
|
+
|
|
143
|
+
## Response security headers & CSP (`withSecurityHeaders`)
|
|
144
|
+
|
|
145
|
+
The SDK can also set a locked-down Content-Security-Policy (per-response nonce +
|
|
146
|
+
`'strict-dynamic'`) and the standard security headers. Wire it in `src/proxy.ts`
|
|
147
|
+
by wrapping the request handler — return `undefined` for the pass-through case so
|
|
148
|
+
the wrapper can attach the nonce to the forwarded request:
|
|
149
|
+
|
|
150
|
+
```ts
|
|
151
|
+
import { withSecurityHeaders } from "@quatronic/sdk/next/security"
|
|
152
|
+
|
|
153
|
+
export const proxy = withSecurityHeaders(async () => undefined)
|
|
154
|
+
export const config = { matcher: ["/((?!_next/static|_next/image|favicon.ico).*)"] }
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
Notes that are easy to get wrong:
|
|
158
|
+
|
|
159
|
+
- **`reportOnly` defaults to `true`** — the policy is reported, not enforced.
|
|
160
|
+
Collect violations first (add a `createCspReportRoute` handler at
|
|
161
|
+
`src/app/api/csp-report/route.ts`), read them, then pass `{ reportOnly: false }`.
|
|
162
|
+
- **A route carrying a nonce must render dynamically and must not be CDN-cached** —
|
|
163
|
+
a cached nonce is shared by every visitor, which is the same as having none.
|
|
164
|
+
- `matcher` must be a **static literal** — Next reads it from the AST at build
|
|
165
|
+
time, so it cannot be a function call.
|
|
166
|
+
- Widen `frameSrc` for an embedded iframe (`{ frameSrc: ["'self'", "https://js.stripe.com"] }`);
|
|
167
|
+
`frameAncestors` (who may embed *you*) defaults to `'none'`.
|
|
168
|
+
|
|
169
|
+
`buildCsp(nonce, options)` is exported if you assemble a header yourself.
|
|
170
|
+
|
|
171
|
+
## Ship it
|
|
172
|
+
|
|
173
|
+
Run the full local check loop — `pnpm lint && pnpm typecheck && pnpm test:run &&
|
|
174
|
+
pnpm build` — then `/qore-ship-checklist` before a PR.
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: qore-ship-checklist
|
|
3
|
+
description: The quality gate to run before opening a pull request — translate the requirement into acceptance criteria, cover it with tests, get all automated checks green, and run an independent review. Use before committing a finished change or opening a PR.
|
|
4
|
+
allowed-tools: Bash(pnpm:*), Bash(git add:*), Bash(git commit:*), Read, Edit
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Ship checklist
|
|
8
|
+
|
|
9
|
+
Run this before opening a PR. It encodes Quatronic's definition of done.
|
|
10
|
+
|
|
11
|
+
## 1. Acceptance criteria
|
|
12
|
+
|
|
13
|
+
Restate the requirement as concrete, checkable acceptance criteria — what must
|
|
14
|
+
be true for this to be "done". Keep them in the PR description.
|
|
15
|
+
|
|
16
|
+
## 2. Tests for those criteria
|
|
17
|
+
|
|
18
|
+
- **Unit** (`*.test.ts`) for pure logic and schemas — see /qore-add-feature.
|
|
19
|
+
{{#if db}}- **Integration** (`*.integration.test.ts`) for anything whose behaviour lives
|
|
20
|
+
in the database (constraints, upserts, joins).{{#if auth}} Mirror
|
|
21
|
+
`src/features/profile/server/queries.integration.test.ts`; run with
|
|
22
|
+
`pnpm db:up` then `pnpm test:integration`.
|
|
23
|
+
{{else}} Run with
|
|
24
|
+
`pnpm db:up` then `pnpm test:integration`.
|
|
25
|
+
{{/if}}{{else}}- (No database module: integration tests apply once the app gains stateful behaviour.)
|
|
26
|
+
{{/if}}- Write the test first where you can; watch it fail, then make it pass.
|
|
27
|
+
|
|
28
|
+
## 3. All automated checks green
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
{{#if db}}pnpm db:generate && {{/if}}pnpm lint && pnpm format:check && pnpm typecheck && pnpm test:run && pnpm build
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
These are exactly what CI runs — `.github/workflows/ci.yml` calls Quatronic's
|
|
35
|
+
shared pipeline, which invokes these same scripts. If any fail locally, the
|
|
36
|
+
PR will be red — fix before pushing.
|
|
37
|
+
|
|
38
|
+
{{#if db}}CI runs `pnpm db:generate` as a drift check and fails when it writes
|
|
39
|
+
anything, so commit every migration it produces under `src/db/migrations`.
|
|
40
|
+
|
|
41
|
+
{{/if}}Also check by hand (the automated gates don't catch everything): no
|
|
42
|
+
third-party UI library imports, no `style={{ ... }}`, no raw/arbitrary color classes
|
|
43
|
+
(`bg-blue-500`, `text-[#1234ff]`) — use semantic tokens
|
|
44
|
+
(`text-destructive`, `bg-muted`, `border-border`) from `src/styles/theme.css`
|
|
45
|
+
instead.
|
|
46
|
+
|
|
47
|
+
If the change calls an external API, check after it deploys that the portal's
|
|
48
|
+
Integrations tab lists every endpoint you call. One missing means its alias or
|
|
49
|
+
path is not written as a literal at the call site — see
|
|
50
|
+
/qore-add-integration step 4.
|
|
51
|
+
|
|
52
|
+
## 4. Independent review
|
|
53
|
+
|
|
54
|
+
- Run `/code-review` and resolve real findings.
|
|
55
|
+
- {{#if auth}}Run `/security-review` — this app handles Keycloak sessions and per-user
|
|
56
|
+
data, so treat anything touching auth, roles, or user-scoped tables as
|
|
57
|
+
high-value.{{else}}Run `/security-review` — treat anything touching external input or
|
|
58
|
+
stored data as high-value.{{/if}} Resolve all critical/high findings before merge.
|
|
59
|
+
{{#if auth=keycloak}}- Added or renamed a role? Say in the PR who should get it on staging and
|
|
60
|
+
production — nobody holds a new role there until someone grants it in the
|
|
61
|
+
portal's Access tab.
|
|
62
|
+
{{/if}}
|
|
63
|
+
|
|
64
|
+
## 5. Observability
|
|
65
|
+
|
|
66
|
+
Walk the new code against `/qore-observability`:
|
|
67
|
+
|
|
68
|
+
- Unexpected failures are left to throw (captured automatically, so no extra capture), no
|
|
69
|
+
error is swallowed without `Sentry.captureException`, and no capture of expected failures
|
|
70
|
+
(validation, not found, denied).
|
|
71
|
+
- Business and audit events logged once with `Sentry.logger`; audit events carry
|
|
72
|
+
`qore.audit.event`{{#if auth}} (login/logout, authorization denials, mutations){{/if}}.
|
|
73
|
+
- Custom attributes are `qore.*` and hold ids, never personal data or secrets.
|
|
74
|
+
- No `console` in runtime code. `pnpm lint` is green.
|
|
75
|
+
|
|
76
|
+
## 6. Commit & PR
|
|
77
|
+
|
|
78
|
+
Small, focused commits on a feature branch. Open a PR (never push to
|
|
79
|
+
`main`/`production` directly) so the change is reviewable, traceable, and
|
|
80
|
+
revertable.
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: qore-translate-strings
|
|
3
|
+
description: Add or change user-facing strings the bilingual (NL/EN) way — message keys in both catalogs, resolved with next-intl. Use whenever you write or edit visible copy.
|
|
4
|
+
allowed-tools: Bash(pnpm:*), Edit, Read
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Translate strings
|
|
8
|
+
|
|
9
|
+
This app is bilingual (Dutch + English) out of the box. Default locale is `nl`;
|
|
10
|
+
the locale lives in a `locale` cookie (no `[locale]` in the URL). Never hardcode
|
|
11
|
+
user-facing copy — every visible string is a key in `messages/nl.json` and
|
|
12
|
+
`messages/en.json`.
|
|
13
|
+
|
|
14
|
+
## Adding or changing a string
|
|
15
|
+
|
|
16
|
+
1. Pick a namespace + key (e.g. `profile.displayName`). Reuse generic keys in
|
|
17
|
+
`common` (`save`, `saved`, `cancel`) instead of duplicating.
|
|
18
|
+
2. Add the SAME key to BOTH `messages/nl.json` and `messages/en.json`. The
|
|
19
|
+
vitest parity test fails if the key sets differ.
|
|
20
|
+
3. Use it:
|
|
21
|
+
- **Client or server component:** `const t = useTranslations("profile")` then
|
|
22
|
+
`t("displayName")`. (`useTranslations` works in both in next-intl v4.)
|
|
23
|
+
- **Dynamic / full-path key** (e.g. a value coming from a server action):
|
|
24
|
+
`const tRoot = useTranslations()` then `tRoot(fullKey)`.
|
|
25
|
+
- **Metadata / outside the render tree:** `getTranslations` from
|
|
26
|
+
`next-intl/server`.
|
|
27
|
+
4. **Zod validation messages:** store the full message key as the zod message
|
|
28
|
+
(`.min(1, "profile.displayNameRequired")`) and resolve it where the form
|
|
29
|
+
shows `state.message` with a root translator. Mirror `src/features/profile/`.
|
|
30
|
+
|
|
31
|
+
## Verify
|
|
32
|
+
|
|
33
|
+
- `pnpm test:run` — runs the parity test (`src/i18n/messages.test.ts`).
|
|
34
|
+
- `pnpm typecheck` — typed messages (`global.d.ts`) catch mistyped keys.
|
|
35
|
+
|
|
36
|
+
Both run as part of /qore-ship-checklist.
|