@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
|
@@ -20,7 +20,7 @@ function sentryBuildOptions(env) {
|
|
|
20
20
|
if (qoreUploads(env)) {
|
|
21
21
|
return {
|
|
22
22
|
...common,
|
|
23
|
-
// Qore uploads the maps after the build (
|
|
23
|
+
// Qore uploads the maps after the build (qore-sourcemaps); the build holds no Sentry token.
|
|
24
24
|
// deleteSourcemapsAfterUpload must stay false: the plugin would otherwise delete the maps anyway.
|
|
25
25
|
sourcemaps: { disable: true, deleteSourcemapsAfterUpload: false },
|
|
26
26
|
release: { name: release, create: false }
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/next/config/index.ts"],"sourcesContent":["import { withSentryConfig } from \"@sentry/nextjs/config\"\nimport type { NextConfig } from \"next\"\n\nimport { STATIC_SECURITY_HEADERS } from \"../../security-core/headers\"\n\ntype Env = Record<string, string | undefined>\n\n/** Only the Qore build sets this; without it the build behaves as before (portal-web, older repos). */\nfunction qoreUploads(env: Env): boolean {\n return Boolean(env.QORE_BUILD_UPLOAD_URL)\n}\n\nexport function sentryBuildOptions(env: Env): Parameters<typeof withSentryConfig>[1] {\n const release = env.SENTRY_RELEASE || undefined\n const common = {\n org: env.SENTRY_ORG,\n project: env.SENTRY_PROJECT,\n sentryUrl: env.SENTRY_URL || \"https://de.sentry.io\",\n silent: true,\n telemetry: false,\n widenClientFileUpload: true,\n }\n if (qoreUploads(env)) {\n return {\n ...common,\n // Qore uploads the maps after the build (
|
|
1
|
+
{"version":3,"sources":["../../../src/next/config/index.ts"],"sourcesContent":["import { withSentryConfig } from \"@sentry/nextjs/config\"\nimport type { NextConfig } from \"next\"\n\nimport { STATIC_SECURITY_HEADERS } from \"../../security-core/headers\"\n\ntype Env = Record<string, string | undefined>\n\n/** Only the Qore build sets this; without it the build behaves as before (portal-web, older repos). */\nfunction qoreUploads(env: Env): boolean {\n return Boolean(env.QORE_BUILD_UPLOAD_URL)\n}\n\nexport function sentryBuildOptions(env: Env): Parameters<typeof withSentryConfig>[1] {\n const release = env.SENTRY_RELEASE || undefined\n const common = {\n org: env.SENTRY_ORG,\n project: env.SENTRY_PROJECT,\n sentryUrl: env.SENTRY_URL || \"https://de.sentry.io\",\n silent: true,\n telemetry: false,\n widenClientFileUpload: true,\n }\n if (qoreUploads(env)) {\n return {\n ...common,\n // Qore uploads the maps after the build (qore-sourcemaps); the build holds no Sentry token.\n // deleteSourcemapsAfterUpload must stay false: the plugin would otherwise delete the maps anyway.\n sourcemaps: { disable: true, deleteSourcemapsAfterUpload: false },\n release: { name: release, create: false },\n }\n }\n const authToken = env.SENTRY_AUTH_TOKEN || undefined\n return {\n ...common,\n authToken,\n sourcemaps: { disable: !authToken, deleteSourcemapsAfterUpload: true },\n release: {\n name: release,\n create: Boolean(authToken && release),\n setCommits: env.SENTRY_REPO && release ? { repo: env.SENTRY_REPO, commit: release } : undefined,\n },\n }\n}\n\nfunction turbopackDebugIds(config: NextConfig): boolean | undefined {\n return (config.turbopack as { debugIds?: boolean } | undefined)?.debugIds\n}\n\nfunction qoreMapOptions(config: NextConfig): NextConfig {\n return {\n productionBrowserSourceMaps: config.productionBrowserSourceMaps ?? true,\n // With sourcemaps disabled the Sentry plugin no longer turns debug ids on. Next 16 option, not in the Next 15 types.\n turbopack: { ...config.turbopack, debugIds: turbopackDebugIds(config) ?? true } as NextConfig[\"turbopack\"],\n }\n}\n\nexport function withQdcConfig(config: NextConfig = {}, env: Env = process.env): NextConfig {\n const base: NextConfig = {\n ...config,\n ...(qoreUploads(env) ? qoreMapOptions(config) : {}),\n serverExternalPackages: [...(config.serverExternalPackages ?? [])],\n // The static security headers, on every route Next serves. The CSP is\n // deliberately NOT here — it carries a per-response nonce, which a\n // build-time constant cannot have; that comes from `withSecurityHeaders`.\n headers: async () => [\n {\n source: \"/:path*\",\n headers: STATIC_SECURITY_HEADERS.map(([key, value]) => ({ key, value })),\n },\n ...((await config.headers?.()) ?? []),\n ],\n }\n return withSentryConfig(base, sentryBuildOptions(env))\n}\n"],"mappings":";;;;;AAAA,SAAS,wBAAwB;AAQjC,SAAS,YAAY,KAAmB;AACtC,SAAO,QAAQ,IAAI,qBAAqB;AAC1C;AAEO,SAAS,mBAAmB,KAAkD;AACnF,QAAM,UAAU,IAAI,kBAAkB;AACtC,QAAM,SAAS;AAAA,IACb,KAAK,IAAI;AAAA,IACT,SAAS,IAAI;AAAA,IACb,WAAW,IAAI,cAAc;AAAA,IAC7B,QAAQ;AAAA,IACR,WAAW;AAAA,IACX,uBAAuB;AAAA,EACzB;AACA,MAAI,YAAY,GAAG,GAAG;AACpB,WAAO;AAAA,MACL,GAAG;AAAA;AAAA;AAAA,MAGH,YAAY,EAAE,SAAS,MAAM,6BAA6B,MAAM;AAAA,MAChE,SAAS,EAAE,MAAM,SAAS,QAAQ,MAAM;AAAA,IAC1C;AAAA,EACF;AACA,QAAM,YAAY,IAAI,qBAAqB;AAC3C,SAAO;AAAA,IACL,GAAG;AAAA,IACH;AAAA,IACA,YAAY,EAAE,SAAS,CAAC,WAAW,6BAA6B,KAAK;AAAA,IACrE,SAAS;AAAA,MACP,MAAM;AAAA,MACN,QAAQ,QAAQ,aAAa,OAAO;AAAA,MACpC,YAAY,IAAI,eAAe,UAAU,EAAE,MAAM,IAAI,aAAa,QAAQ,QAAQ,IAAI;AAAA,IACxF;AAAA,EACF;AACF;AAEA,SAAS,kBAAkB,QAAyC;AAClE,SAAQ,OAAO,WAAkD;AACnE;AAEA,SAAS,eAAe,QAAgC;AACtD,SAAO;AAAA,IACL,6BAA6B,OAAO,+BAA+B;AAAA;AAAA,IAEnE,WAAW,EAAE,GAAG,OAAO,WAAW,UAAU,kBAAkB,MAAM,KAAK,KAAK;AAAA,EAChF;AACF;AAEO,SAAS,cAAc,SAAqB,CAAC,GAAG,MAAW,QAAQ,KAAiB;AACzF,QAAM,OAAmB;AAAA,IACvB,GAAG;AAAA,IACH,GAAI,YAAY,GAAG,IAAI,eAAe,MAAM,IAAI,CAAC;AAAA,IACjD,wBAAwB,CAAC,GAAI,OAAO,0BAA0B,CAAC,CAAE;AAAA;AAAA;AAAA;AAAA,IAIjE,SAAS,YAAY;AAAA,MACnB;AAAA,QACE,QAAQ;AAAA,QACR,SAAS,wBAAwB,IAAI,CAAC,CAAC,KAAK,KAAK,OAAO,EAAE,KAAK,MAAM,EAAE;AAAA,MACzE;AAAA,MACA,GAAK,MAAM,OAAO,UAAU,KAAM,CAAC;AAAA,IACrC;AAAA,EACF;AACA,SAAO,iBAAiB,MAAM,mBAAmB,GAAG,CAAC;AACvD;","names":[]}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// jscodeshift transform for migration no-raw-fetch. Moves the server-side
|
|
2
|
+
// fetch calls that QDC-NET-001 (safe-fetch) flags onto safeFetch, where the
|
|
3
|
+
// move cannot change behaviour beyond what safeFetch exists to change.
|
|
4
|
+
//
|
|
5
|
+
// npx jscodeshift@17.3.0 --parser=tsx \
|
|
6
|
+
// -t node_modules/@quatronic/sdk/migrations/no-raw-fetch/codemod.mjs src
|
|
7
|
+
//
|
|
8
|
+
// It rewrites a call only when it is the global `fetch`, in a server path, with
|
|
9
|
+
// a URL the server did not fix, and an init that SafeFetchInit can hold. Every
|
|
10
|
+
// other call is left exactly as it was; instructions.md covers those.
|
|
11
|
+
|
|
12
|
+
const SERVER_PATHS = ["src/app/api", "src/lib/server", "src/proxy.ts"]
|
|
13
|
+
const MODULE = "@quatronic/sdk/node/net"
|
|
14
|
+
// SafeFetchInit's keys. `cache`, `next`, `redirect`, `credentials` and the
|
|
15
|
+
// rest have no safeFetch equivalent, so a call carrying one needs a person.
|
|
16
|
+
const INIT_KEYS = new Set(["method", "headers", "body", "signal"])
|
|
17
|
+
|
|
18
|
+
function isServerFile(path) {
|
|
19
|
+
const file = path.replace(/\\/g, "/")
|
|
20
|
+
return SERVER_PATHS.some((p) => file.endsWith(`/${p}`) || file.includes(`/${p}/`) || file.startsWith(`${p}/`) || file === p)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Mirrors isFixedTarget in src/eslint/ast.ts: a URL the rule does not flag. */
|
|
24
|
+
function isFixed(node) {
|
|
25
|
+
if (!node) return false
|
|
26
|
+
if (node.type === "StringLiteral" || node.type === "Literal") return typeof node.value === "string"
|
|
27
|
+
if (node.type === "TemplateLiteral") return node.expressions.length === 0
|
|
28
|
+
if (node.type === "NewExpression") return node.callee.type === "Identifier" && node.callee.name === "URL" && isFixed(node.arguments[0])
|
|
29
|
+
return false
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function keyName(prop) {
|
|
33
|
+
if (prop.computed) return null
|
|
34
|
+
if (prop.key.type === "Identifier") return prop.key.name
|
|
35
|
+
return typeof prop.key.value === "string" ? prop.key.value : null
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** An init safeFetch accepts as is: absent, or a literal of SafeFetchInit keys. */
|
|
39
|
+
function isPortableInit(node) {
|
|
40
|
+
if (!node) return true
|
|
41
|
+
if (node.type !== "ObjectExpression") return false
|
|
42
|
+
return node.properties.every((p) => {
|
|
43
|
+
if (p.type !== "ObjectProperty" && p.type !== "Property") return false
|
|
44
|
+
const key = keyName(p)
|
|
45
|
+
if (!key || !INIT_KEYS.has(key)) return false
|
|
46
|
+
// `headers: new Headers(...)` or a variable may not be a plain record.
|
|
47
|
+
return key !== "headers" || p.value.type === "ObjectExpression"
|
|
48
|
+
})
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export default function transformer(file, api) {
|
|
52
|
+
if (!isServerFile(file.path)) return undefined
|
|
53
|
+
const j = api.jscodeshift
|
|
54
|
+
const root = j(file.source)
|
|
55
|
+
|
|
56
|
+
// A local or imported `fetch` is not the global one.
|
|
57
|
+
const shadowed =
|
|
58
|
+
root.find(j.Identifier, { name: "fetch" }).filter((p) => {
|
|
59
|
+
const parent = p.parent.node
|
|
60
|
+
return (
|
|
61
|
+
(parent.type === "VariableDeclarator" && parent.id === p.node) ||
|
|
62
|
+
(parent.type.startsWith("Function") && parent.id === p.node) ||
|
|
63
|
+
parent.type === "ImportSpecifier" ||
|
|
64
|
+
parent.type === "ImportDefaultSpecifier" ||
|
|
65
|
+
(parent.type.startsWith("Function") && parent.params.includes(p.node))
|
|
66
|
+
)
|
|
67
|
+
}).length > 0
|
|
68
|
+
if (shadowed) return undefined
|
|
69
|
+
|
|
70
|
+
const calls = root
|
|
71
|
+
.find(j.CallExpression, { callee: { type: "Identifier", name: "fetch" } })
|
|
72
|
+
.filter((p) => p.node.arguments.length >= 1 && p.node.arguments.length <= 2)
|
|
73
|
+
.filter((p) => !isFixed(p.node.arguments[0]) && p.node.arguments[0].type !== "SpreadElement")
|
|
74
|
+
.filter((p) => isPortableInit(p.node.arguments[1]))
|
|
75
|
+
if (calls.length === 0) return undefined
|
|
76
|
+
|
|
77
|
+
calls.forEach((p) => {
|
|
78
|
+
p.node.callee = j.identifier("safeFetch")
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
const existing = root.find(j.ImportDeclaration, { source: { value: MODULE } })
|
|
82
|
+
const has = existing.find(j.ImportSpecifier, { imported: { name: "safeFetch" } }).length > 0
|
|
83
|
+
if (!has) {
|
|
84
|
+
const spec = j.importSpecifier(j.identifier("safeFetch"))
|
|
85
|
+
const into = existing.filter((p) => p.node.importKind !== "type")
|
|
86
|
+
if (into.length > 0) into.get().node.specifiers.push(spec)
|
|
87
|
+
else {
|
|
88
|
+
const decl = j.importDeclaration([spec], j.literal(MODULE))
|
|
89
|
+
const imports = root.find(j.ImportDeclaration)
|
|
90
|
+
if (imports.length > 0) imports.at(imports.length - 1).insertAfter(decl)
|
|
91
|
+
else root.get().node.program.body.unshift(decl)
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return root.toSource({ quote: "double" })
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export const parser = "tsx"
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# no-raw-fetch
|
|
2
|
+
|
|
3
|
+
Server code that fetches a URL it did not fix itself uses `safeFetch` from
|
|
4
|
+
`@quatronic/sdk/node/net`, not the global `fetch`.
|
|
5
|
+
|
|
6
|
+
**Rule:** `qdc/safe-fetch` (QDC-NET-001), in `configs.recommended`. It covers
|
|
7
|
+
`src/app/api`, `src/lib/server` and `src/proxy.ts`.
|
|
8
|
+
|
|
9
|
+
## Why
|
|
10
|
+
|
|
11
|
+
A URL built from input can point at the private network: the metadata service,
|
|
12
|
+
another tenant's internal service, the database. `safeFetch` resolves the host,
|
|
13
|
+
refuses private, loopback and link-local addresses, and re-checks every
|
|
14
|
+
redirect. The global `fetch` does none of that.
|
|
15
|
+
|
|
16
|
+
## First, pick the right client
|
|
17
|
+
|
|
18
|
+
| The call goes to | Use |
|
|
19
|
+
|---|---|
|
|
20
|
+
| another module of this app | `connection(alias).fetch` from `@quatronic/sdk/node/connections` |
|
|
21
|
+
| a third-party API the app declares | `integration(alias)` from `@quatronic/sdk/node/integrations` |
|
|
22
|
+
| a URL that comes from input or data | `safeFetch` (this migration) |
|
|
23
|
+
|
|
24
|
+
The codemod only knows the last case. Move the other two by hand first.
|
|
25
|
+
|
|
26
|
+
## Run the codemod
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npx jscodeshift@17.3.0 --parser=tsx \
|
|
30
|
+
-t node_modules/@quatronic/sdk/migrations/no-raw-fetch/codemod.mjs src
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
It rewrites `fetch(url)` and `fetch(url, init)` to `safeFetch(...)` and adds the
|
|
34
|
+
import, when all of these hold:
|
|
35
|
+
|
|
36
|
+
- the file is in one of the paths above;
|
|
37
|
+
- `fetch` is the global one (not imported or declared in the file);
|
|
38
|
+
- the URL is not a fixed string, which the rule does not flag;
|
|
39
|
+
- `init` is absent or an object literal with only `method`, `headers` (an
|
|
40
|
+
object literal), `body` and `signal`.
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
const res = await fetch(target, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify(payload) })
|
|
44
|
+
// →
|
|
45
|
+
const res = await safeFetch(target, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify(payload) })
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
The printer may add semicolons to the lines it touched; run your formatter. Then
|
|
49
|
+
run `pnpm lint` to see the calls it left.
|
|
50
|
+
|
|
51
|
+
## Behaviour that changes
|
|
52
|
+
|
|
53
|
+
Check each rewritten call against these. The codemod cannot.
|
|
54
|
+
|
|
55
|
+
- **https only.** An `http:` URL is refused. Pass `{ protocols: ["https:", "http:"] }` as the third argument only if the target cannot do TLS.
|
|
56
|
+
- **No redirects.** Pass `{ maxRedirects: 3 }` if the call relied on following them. Each hop is checked again.
|
|
57
|
+
- **5 s timeout and 5 MiB response cap** for the whole request. Raise them with `timeoutMs` and `maxBytes`.
|
|
58
|
+
- **A refused target throws `SafeFetchError`** (`reason` says why). Catch it where the old code handled a network error, and answer the caller with a 4xx, not a 500.
|
|
59
|
+
|
|
60
|
+
## By hand
|
|
61
|
+
|
|
62
|
+
| The call has | Do this |
|
|
63
|
+
|---|---|
|
|
64
|
+
| `headers: new Headers(...)` or a variable | Pass a plain object: `Object.fromEntries(headers)`. |
|
|
65
|
+
| a `ReadableStream` or `FormData` body | Read it into a string or `Uint8Array` first. `safeFetch` replays the body on a redirect, so it cannot stream. |
|
|
66
|
+
| `cache`, `next: { revalidate }` | `safeFetch` does not use Next's data cache. Cache the result yourself, or keep `fetch` for a fixed URL (the rule allows that). |
|
|
67
|
+
| `redirect: "manual"` | That is the default. Drop the key. |
|
|
68
|
+
| `credentials`, `mode`, `keepalive` | Browser options. Server code does not need them. Drop the key. |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quatronic/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0-rc.10",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"private": false,
|
|
6
6
|
"publishConfig": {
|
|
@@ -9,12 +9,18 @@
|
|
|
9
9
|
},
|
|
10
10
|
"files": [
|
|
11
11
|
"dist",
|
|
12
|
-
"
|
|
12
|
+
"migrations",
|
|
13
|
+
"semgrep",
|
|
14
|
+
"skills",
|
|
15
|
+
"postinstall.mjs"
|
|
13
16
|
],
|
|
14
17
|
"bin": {
|
|
18
|
+
"qore-skills": "./dist/cli/skills.js",
|
|
19
|
+
"qore-sourcemaps": "./dist/cli/sourcemaps.js",
|
|
20
|
+
"qore-test-report": "./dist/cli/test-report.js",
|
|
15
21
|
"qdc-setup-env": "./dist/cli/setup-env.js",
|
|
16
|
-
"qdc-sourcemaps": "./dist/cli/sourcemaps.js",
|
|
17
|
-
"qdc-test-report": "./dist/cli/test-report.js"
|
|
22
|
+
"qdc-sourcemaps": "./dist/cli/legacy/qdc-sourcemaps.js",
|
|
23
|
+
"qdc-test-report": "./dist/cli/legacy/qdc-test-report.js"
|
|
18
24
|
},
|
|
19
25
|
"exports": {
|
|
20
26
|
"./auth": {
|
|
@@ -122,7 +128,10 @@
|
|
|
122
128
|
"build": "tsup",
|
|
123
129
|
"surface": "node scripts/api-surface.mjs",
|
|
124
130
|
"surface:check": "node scripts/api-surface.mjs --check",
|
|
131
|
+
"migration:lint": "node scripts/migration-lint.mjs",
|
|
132
|
+
"release:manifest": "node scripts/release-manifest.mjs",
|
|
125
133
|
"prepublishOnly": "pnpm build",
|
|
134
|
+
"postinstall": "node postinstall.mjs",
|
|
126
135
|
"test": "vitest run",
|
|
127
136
|
"test:watch": "vitest",
|
|
128
137
|
"typecheck": "tsc --noEmit && tsc -p tsconfig.test.json",
|
|
@@ -179,12 +188,13 @@
|
|
|
179
188
|
},
|
|
180
189
|
"devDependencies": {
|
|
181
190
|
"@better-auth/core": "^1.6.24",
|
|
182
|
-
"@sentry/nextjs": "10.75.2",
|
|
183
|
-
"@sentry/node": "10.75.2",
|
|
184
191
|
"@eslint/js": "^10.0.1",
|
|
185
192
|
"@opentelemetry/sdk-trace-base": "^2.7.0",
|
|
193
|
+
"@sentry/nextjs": "10.75.2",
|
|
194
|
+
"@sentry/node": "10.75.2",
|
|
186
195
|
"@testcontainers/postgresql": "^12.0.0",
|
|
187
196
|
"@testing-library/react": "^16.1.0",
|
|
197
|
+
"@types/jscodeshift": "17.3.0",
|
|
188
198
|
"@types/node": "^22.10.2",
|
|
189
199
|
"@types/pg": "^8.11.10",
|
|
190
200
|
"@types/react": "^18.3.17",
|
|
@@ -194,6 +204,7 @@
|
|
|
194
204
|
"drizzle-kit": "^0.30.1",
|
|
195
205
|
"drizzle-orm": "^0.38.2",
|
|
196
206
|
"eslint": "^10.5.0",
|
|
207
|
+
"jscodeshift": "17.3.0",
|
|
197
208
|
"jsdom": "^25.0.1",
|
|
198
209
|
"msw": "^2.7.0",
|
|
199
210
|
"next": "^15.1.0",
|
package/postinstall.mjs
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Syncs an app's managed skills when it installs or bumps this package; see
|
|
2
|
+
// src/cli/skills-postinstall.ts. It must never fail an install, so a missing
|
|
3
|
+
// build (the SDK's own workspace) or any error is swallowed here.
|
|
4
|
+
try {
|
|
5
|
+
const { main } = await import("./dist/cli/skills-postinstall.js")
|
|
6
|
+
main()
|
|
7
|
+
} catch {
|
|
8
|
+
// Nothing to do: the next `qore-skills check` reports skills that lag the SDK.
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
* text eol=lf
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"skills": [
|
|
3
|
+
{"name": "qore-add-api-route", "kind": "convenience", "requires": ["runtime=next"], "legacyNames": ["quatronic-add-api-route"]},
|
|
4
|
+
{"name": "qore-add-connection", "kind": "contract", "legacyNames": ["quatronic-add-connection"]},
|
|
5
|
+
{"name": "qore-add-db-table", "kind": "convenience", "requires": ["runtime=next", "db"], "legacyNames": ["quatronic-add-db-table"]},
|
|
6
|
+
{"name": "qore-add-feature", "kind": "convenience", "requires": ["runtime=next"], "legacyNames": ["quatronic-add-feature"]},
|
|
7
|
+
{"name": "qore-add-integration", "kind": "contract", "legacyNames": ["quatronic-add-integration"]},
|
|
8
|
+
{"name": "qore-add-page", "kind": "convenience", "requires": ["runtime=next"], "legacyNames": ["quatronic-add-page"]},
|
|
9
|
+
{"name": "qore-author-skill", "kind": "convenience", "legacyNames": ["quatronic-author-skill"]},
|
|
10
|
+
{"name": "qore-debug-issue", "kind": "convenience"},
|
|
11
|
+
{"name": "qore-enable-auth-method", "kind": "convenience", "requires": ["auth=betterauth"], "legacyNames": ["quatronic-enable-auth-method"]},
|
|
12
|
+
{"name": "qore-observability", "kind": "contract", "legacyNames": ["quatronic-observe"]},
|
|
13
|
+
{"name": "qore-recommended-tools", "kind": "convenience", "requires": ["runtime=next"], "legacyNames": ["quatronic-recommended-tools"]},
|
|
14
|
+
{"name": "qore-secure-io", "kind": "convenience", "requires": ["runtime=next"], "legacyNames": ["quatronic-secure-io"]},
|
|
15
|
+
{"name": "qore-ship-checklist", "kind": "convenience", "requires": ["runtime=next"], "legacyNames": ["quatronic-ship-checklist"]},
|
|
16
|
+
{"name": "qore-translate-strings", "kind": "convenience", "requires": ["runtime=next"], "legacyNames": ["quatronic-translate-strings"]},
|
|
17
|
+
{"name": "qore-use-addons", "kind": "convenience", "requires": ["runtime=next"], "legacyNames": ["quatronic-use-addons"]},
|
|
18
|
+
{"name": "qore-use-database", "kind": "contract", "requires": ["runtime=node", "db"], "legacyNames": ["quatronic-use-database"]},
|
|
19
|
+
{"name": "qore-use-design-system", "kind": "convenience", "requires": ["runtime=next"], "legacyNames": ["quatronic-use-design-system"]},
|
|
20
|
+
{"name": "qore-use-mail-domain", "kind": "convenience", "legacyNames": ["quatronic-use-mail-domain"]},
|
|
21
|
+
{"name": "qore-use-permissions", "kind": "contract", "requires": ["auth=keycloak"], "legacyNames": ["quatronic-use-permissions"]},
|
|
22
|
+
{"name": "qore-verify-user", "kind": "convenience", "requires": ["runtime=node"], "legacyNames": ["quatronic-verify-user"]}
|
|
23
|
+
]
|
|
24
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: qore-add-api-route
|
|
3
|
+
description: Add a business HTTP route under src/app/api/ for external callers{{#if auth}}, protected with the SDK{{/if}}. Use for API endpoints — internal mutations are Server Actions, not routes.
|
|
4
|
+
allowed-tools: Bash(pnpm:*), Edit, Read
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
{{#if auth}}> Gating access by role/permission? See /qore-use-permissions.{{#if auth=keycloak}} Added a role key? Run `qore roles sync` yourself, then ask before `qore roles use` (§3 there).{{/if}}
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
{{/if}}# Add an API route
|
|
11
|
+
|
|
12
|
+
Internal mutations use Server Actions (see /qore-add-feature). Use an API
|
|
13
|
+
route only for **external** callers.
|
|
14
|
+
|
|
15
|
+
1. Create `src/app/api/<name>/route.ts`, following the layout of the existing
|
|
16
|
+
routes — segment config first, then imports, then the handler:
|
|
17
|
+
{{#if auth}} ```ts
|
|
18
|
+
export const runtime = "nodejs"
|
|
19
|
+
export const dynamic = "force-dynamic" // set for any non-trivial handler (POST, reads request, must not be cached)
|
|
20
|
+
|
|
21
|
+
import { NextResponse } from "next/server"
|
|
22
|
+
import { getRequireAuth } from "@/lib/auth"
|
|
23
|
+
|
|
24
|
+
export async function GET() {
|
|
25
|
+
const requireAuth = await getRequireAuth()
|
|
26
|
+
const user = await requireAuth()
|
|
27
|
+
return NextResponse.json({ id: user.id })
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
{{else}} ```ts
|
|
31
|
+
export const runtime = "nodejs"
|
|
32
|
+
export const dynamic = "force-dynamic" // set for any non-trivial handler
|
|
33
|
+
|
|
34
|
+
import { NextResponse } from "next/server"
|
|
35
|
+
|
|
36
|
+
export async function GET() {
|
|
37
|
+
return NextResponse.json({ ok: true })
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
(No auth module is installed — protect external routes with your own token
|
|
41
|
+
check or add auth via the portal before exposing sensitive data.)
|
|
42
|
+
{{/if}}
|
|
43
|
+
2. Keep data access in a feature slice's `server/` dir, not inline in the route.
|
|
44
|
+
|
|
45
|
+
> API responses are data, not localized UI, so they generally need no
|
|
46
|
+
> translation. If a route returns human-readable text meant for end users,
|
|
47
|
+
> treat it like any UI string (see /qore-translate-strings).
|
|
48
|
+
|
|
49
|
+
3. Let unexpected failures throw — they are captured automatically. Use
|
|
50
|
+
`Sentry.captureException(err, { tags })` only for a failure you handle that
|
|
51
|
+
should never happen, never for expected ones (validation, not found, denied).
|
|
52
|
+
Add a `Sentry.logger.info` line for the business event (no PII); request
|
|
53
|
+
tracing is automatic. See /qore-observability.
|
|
54
|
+
4. Run the full local check loop — `pnpm lint && pnpm typecheck && pnpm test:run
|
|
55
|
+
&& pnpm build` — then /qore-ship-checklist before a PR.
|
|
56
|
+
|
|
57
|
+
{{#if auth}}> Never touch the auth catch-all (`src/app/api/auth/[...qdc]/route.ts`) — it is SDK-owned.
|
|
58
|
+
{{/if}}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: qore-add-connection
|
|
3
|
+
description: Wire a module-to-module connection — declare its env, guard an incoming route with requireConnection, call out with connection().fetch, and fail-fast at startup with assertConnection. Use when this app talks to another Quatronic module.
|
|
4
|
+
allowed-tools: Bash(pnpm:*), Edit, Read
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Add a connection
|
|
8
|
+
|
|
9
|
+
A connection links two Quatronic modules. The portal injects the env on both
|
|
10
|
+
sides when the connection is wired (`CONN_<ALIAS>_URL`, `CONN_<ALIAS>_TOKEN` for
|
|
11
|
+
a service; `CONN_<ALIAS>_URI`/`_HOST`/… for a resource). `<ALIAS>` is the
|
|
12
|
+
provider slug uppercased, non-alphanumerics collapsed to `_`. The SDK reads only
|
|
13
|
+
this env — it never calls the portal at runtime.
|
|
14
|
+
|
|
15
|
+
> A single-module app has no connections. Only follow this once the portal shows
|
|
16
|
+
> a wired connection for this module (its env keys exist in the Secrets tab).
|
|
17
|
+
|
|
18
|
+
## Kinds of connection
|
|
19
|
+
|
|
20
|
+
`connection(alias)` returns one handle with four methods — which one you call
|
|
21
|
+
depends on what the alias was wired to in the portal:
|
|
22
|
+
|
|
23
|
+
- **`.fetch(path, init?)`** — the alias is another **module** (a service
|
|
24
|
+
connection). This is module-to-module talking directly over the network via
|
|
25
|
+
its own API, authenticated with a shared-secret token in the
|
|
26
|
+
`X-QDC-Connection-Token` header. No addon involved.
|
|
27
|
+
- **`.postgres()` / `.redis()` / `.s3()`** — the alias is a **resource** (an
|
|
28
|
+
addon: Postgres, Redis, or object storage) this module was granted access
|
|
29
|
+
to. These return typed connection material (URI, host, credentials, …), not
|
|
30
|
+
an HTTP client — you pass it to your own DB/cache/S3 client.
|
|
31
|
+
|
|
32
|
+
`assertConnection(alias, kind)` takes the matching `kind` too: `"service"` for
|
|
33
|
+
`.fetch()`, `"postgres"`/`"redis"`/`"s3"` for the resource accessors.
|
|
34
|
+
`requireConnection` (step 4) is provider-side only — a resource connection has
|
|
35
|
+
no inbound side, so it's only ever used for service connections.
|
|
36
|
+
|
|
37
|
+
## 1. Declare the connection's env (consumer side only)
|
|
38
|
+
|
|
39
|
+
**Only do this when THIS module calls out** via `.fetch()`/`.postgres()`/
|
|
40
|
+
`.redis()`/`.s3()` (steps 2-3). If this module is only the **provider** guarding
|
|
41
|
+
an inbound route (step 4), skip this step entirely — see the note there.
|
|
42
|
+
|
|
43
|
+
Add the keys to the server schema in `src/config/env.ts` so a missing wire is a
|
|
44
|
+
clear startup error, not a mystery 500. For a service connection to `billing-api`
|
|
45
|
+
(alias `BILLING_API`):
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
// inside serverSchema = z.object({ ... })
|
|
49
|
+
CONN_BILLING_API_URL: z.string().url(),
|
|
50
|
+
CONN_BILLING_API_TOKEN: z.string().min(1),
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## 2. Fail-fast at startup
|
|
54
|
+
|
|
55
|
+
In a module-scoped init path (e.g. a server-only module imported by your feature
|
|
56
|
+
code), assert the wire once:
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
import { assertConnection } from "@quatronic/sdk/next/connections"
|
|
60
|
+
import { serverEnv } from "@/config/env"
|
|
61
|
+
|
|
62
|
+
assertConnection("billing-api", "service", { env: serverEnv() as Record<string, string> })
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## 3. Call out to the other module
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
import { connection } from "@quatronic/sdk/next/connections"
|
|
69
|
+
|
|
70
|
+
const res = await connection("billing-api").fetch("/invoices", { method: "GET" })
|
|
71
|
+
// connection() reads process.env; the X-QDC-Connection-Token header is added
|
|
72
|
+
// from CONN_BILLING_API_TOKEN automatically. Default 10s timeout.
|
|
73
|
+
const invoices = await res.json()
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
For a resource connection, use the typed accessor instead of `.fetch`:
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
const { uri } = connection("main-db").postgres() // { uri, host?, port?, user?, password?, db? }
|
|
80
|
+
const { url } = connection("cache").redis()
|
|
81
|
+
const { endpoint, bucket, accessKey, secretKey } = connection("media").s3()
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## 4. Guard an incoming connection route
|
|
85
|
+
|
|
86
|
+
When THIS module is the provider, protect the receiving route. The guard is
|
|
87
|
+
edge-safe, so it also works in `middleware.ts` to protect a whole route group.
|
|
88
|
+
|
|
89
|
+
**No `env.ts` schema entry needed for this** — unlike step 1, `requireConnection`
|
|
90
|
+
doesn't take or need an alias: it scans `process.env` for every `CONN_*_TOKEN`
|
|
91
|
+
key present and matches the incoming request's token against all of them, so
|
|
92
|
+
it works with whatever alias the portal happened to derive on the consumer's
|
|
93
|
+
side. Also note the portal never gives a provider its own `CONN_<ALIAS>_URL` —
|
|
94
|
+
only a consumer gets a `_URL` — so requiring `CONN_<ALIAS>_URL` in this
|
|
95
|
+
module's `env.ts` when it's provider-only will always fail (crash-loop) since
|
|
96
|
+
that key can never exist.
|
|
97
|
+
|
|
98
|
+
```ts
|
|
99
|
+
// src/app/api/internal/<name>/route.ts
|
|
100
|
+
export const runtime = "nodejs"
|
|
101
|
+
export const dynamic = "force-dynamic"
|
|
102
|
+
|
|
103
|
+
import { NextResponse } from "next/server"
|
|
104
|
+
import { requireConnection, ConnectionError } from "@quatronic/sdk/next/connections"
|
|
105
|
+
|
|
106
|
+
export async function POST(req: Request) {
|
|
107
|
+
try {
|
|
108
|
+
const alias = await requireConnection(req) // returns the matched <ALIAS>
|
|
109
|
+
// ... handle the trusted request; `alias` tells you which consumer wired in
|
|
110
|
+
return NextResponse.json({ ok: true })
|
|
111
|
+
} catch (e) {
|
|
112
|
+
if (e instanceof ConnectionError) {
|
|
113
|
+
return NextResponse.json({ error: e.code }, { status: e.status })
|
|
114
|
+
}
|
|
115
|
+
throw e
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
`requireConnection` is `async` (it uses Web Crypto for a constant-time token
|
|
121
|
+
compare) — always `await` it. It throws `ConnectionError` with code `not_wired`
|
|
122
|
+
/ `missing_token` / `invalid_token` (status 401).
|
|
123
|
+
|
|
124
|
+
### Fail-fast that an inbound connection is wired (optional)
|
|
125
|
+
|
|
126
|
+
To assert at startup that *some* connection is wired to this provider, use the
|
|
127
|
+
alias-agnostic `assertInboundConnection` (the provider doesn't know its callers'
|
|
128
|
+
aliases, so `assertConnection` from step 2 doesn't apply):
|
|
129
|
+
|
|
130
|
+
```ts
|
|
131
|
+
import { assertInboundConnection } from "@quatronic/sdk/next/connections"
|
|
132
|
+
|
|
133
|
+
assertInboundConnection()
|
|
134
|
+
// throws not_wired (500) if no CONN_*_TOKEN is present in process.env
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
Do **not** implement this by calling `requireConnection` with a tokenless
|
|
138
|
+
`Request`. `requireConnection` always logs a `qore.connection.rejected` /
|
|
139
|
+
`missing_token` warning before it throws, so a tokenless probe emits a
|
|
140
|
+
misleading rejection on **every healthy boot**. `assertInboundConnection` reads
|
|
141
|
+
the env directly and stays silent when a connection is wired.
|
|
142
|
+
|
|
143
|
+
## 5. Ship it
|
|
144
|
+
|
|
145
|
+
Run the full local check loop — `pnpm lint && pnpm typecheck && pnpm test:run &&
|
|
146
|
+
pnpm build` — then /qore-ship-checklist before a PR.
|
|
147
|
+
|
|
148
|
+
> A worked, non-wired reference lives at `src/examples/connection.example.ts`.
|
|
149
|
+
> Don't hand-edit the auth/SDK boundary (`src/lib/auth.ts`, `src/proxy.ts`).
|