@quatronic/sdk 0.8.0-rc.11 → 0.8.0-rc.13

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.
Files changed (77) hide show
  1. package/dist/{chunk-2AYDFLKR.js → chunk-F3NHTHFO.js} +6 -104
  2. package/dist/chunk-F3NHTHFO.js.map +1 -0
  3. package/dist/chunk-P7HNHLW7.js +65 -0
  4. package/dist/chunk-P7HNHLW7.js.map +1 -0
  5. package/dist/chunk-QMOZDE3U.js +158 -0
  6. package/dist/chunk-QMOZDE3U.js.map +1 -0
  7. package/dist/chunk-TOBGX4CZ.js +109 -0
  8. package/dist/chunk-TOBGX4CZ.js.map +1 -0
  9. package/dist/chunk-WU7N4PET.js +20 -0
  10. package/dist/chunk-WU7N4PET.js.map +1 -0
  11. package/dist/cli/legacy/qdc-sourcemaps.js +16 -6
  12. package/dist/cli/sourcemaps.js +16 -6
  13. package/dist/integrations/index.d.ts +3 -75
  14. package/dist/integrations/index.js +6 -4
  15. package/dist/mail/index.d.ts +9 -0
  16. package/dist/mail/index.js +26 -0
  17. package/dist/mail/index.js.map +1 -0
  18. package/dist/next/auth/index.js +3 -152
  19. package/dist/next/auth/index.js.map +1 -1
  20. package/dist/next/boot/index.d.ts +33 -0
  21. package/dist/next/boot/index.js +21 -0
  22. package/dist/next/boot/index.js.map +1 -0
  23. package/dist/next/db/index.d.ts +18 -1
  24. package/dist/next/db/index.js +25 -0
  25. package/dist/next/db/index.js.map +1 -1
  26. package/dist/next/global-error/index.d.ts +9 -0
  27. package/dist/next/global-error/index.js +17 -0
  28. package/dist/next/global-error/index.js.map +1 -0
  29. package/dist/next/integrations/index.d.ts +2 -1
  30. package/dist/next/integrations/index.js +6 -4
  31. package/dist/next/platform/index.d.ts +19 -0
  32. package/dist/next/platform/index.js +44 -0
  33. package/dist/next/platform/index.js.map +1 -0
  34. package/dist/next/security/index.d.ts +23 -1
  35. package/dist/next/security/index.js +39 -56
  36. package/dist/next/security/index.js.map +1 -1
  37. package/dist/next/security/testing.js +10 -1
  38. package/dist/next/security/testing.js.map +1 -1
  39. package/dist/next/sentry/register.js +5 -13
  40. package/dist/next/sentry/register.js.map +1 -1
  41. package/dist/node/boot/index.d.ts +9 -0
  42. package/dist/node/boot/index.js +13 -0
  43. package/dist/node/boot/index.js.map +1 -0
  44. package/dist/node/integrations/index.d.ts +2 -1
  45. package/dist/node/integrations/index.js +6 -4
  46. package/dist/node-Z7ERWJDZ.js +46 -0
  47. package/dist/node-Z7ERWJDZ.js.map +1 -0
  48. package/dist/types-CAwj03sM.d.ts +75 -0
  49. package/migrations/bootstrap-qore-env/codemod.mjs +77 -0
  50. package/migrations/bootstrap-qore-env/instructions.md +28 -0
  51. package/migrations/bootstrap-qore-env/meta.json +7 -0
  52. package/migrations/global-error/codemod.mjs +28 -0
  53. package/migrations/global-error/instructions.md +26 -0
  54. package/migrations/global-error/meta.json +7 -0
  55. package/migrations/local-db-port/codemod.mjs +61 -0
  56. package/migrations/local-db-port/instructions.md +45 -0
  57. package/migrations/local-db-port/meta.json +7 -0
  58. package/migrations/mail-reexport/codemod.mjs +64 -0
  59. package/migrations/mail-reexport/instructions.md +27 -0
  60. package/migrations/mail-reexport/meta.json +7 -0
  61. package/migrations/no-raw-fetch/meta.json +1 -1
  62. package/migrations/platform-routes/codemod.mjs +45 -0
  63. package/migrations/platform-routes/instructions.md +30 -0
  64. package/migrations/platform-routes/meta.json +7 -0
  65. package/migrations/qore-boot/codemod.mjs +263 -0
  66. package/migrations/qore-boot/instructions.md +74 -0
  67. package/migrations/qore-boot/meta.json +7 -0
  68. package/migrations/qore-proxy/codemod.mjs +88 -0
  69. package/migrations/qore-proxy/instructions.md +56 -0
  70. package/migrations/qore-proxy/meta.json +7 -0
  71. package/migrations/run.mjs +334 -0
  72. package/migrations/sourcemaps-finalize/codemod.mjs +63 -0
  73. package/migrations/sourcemaps-finalize/instructions.md +56 -0
  74. package/migrations/sourcemaps-finalize/meta.json +7 -0
  75. package/package.json +23 -2
  76. package/workspace-requirements.json +4 -0
  77. package/dist/chunk-2AYDFLKR.js.map +0 -1
@@ -0,0 +1,27 @@
1
+ # mail-reexport: send mail through the SDK
2
+
3
+ `src/lib/mail.ts` used to hold the Resend call. It now lives in
4
+ `@quatronic/sdk/mail`, with the same `sendMail(mail: Mail)` signature, so a fix
5
+ to how mail is sent reaches your app as an SDK release.
6
+
7
+ The upgrade bot runs this for you:
8
+
9
+ ```bash
10
+ node node_modules/@quatronic/sdk/migrations/run.mjs --only mail-reexport
11
+ ```
12
+
13
+ A `mail.ts` exactly as the templates generated it becomes:
14
+
15
+ ```ts
16
+ export { sendMail, type Mail } from "@quatronic/sdk/mail"
17
+ ```
18
+
19
+ and the template's `mail.test.ts` (`src/lib/` in a Next app, `tests/` in a backend), which tested the old body, is deleted.
20
+
21
+ A `mail.ts` your team changed is kept and listed in the pull request. Move it
22
+ when the SDK version does what you need: replace the body with the re-export
23
+ above, or call `sendMail` from the SDK inside your own function.
24
+
25
+ A `mail.test.ts` your team changed is listed as a manual change when `mail.ts`
26
+ moves. It mocks `fetch` and the logger of the old body and will fail against the
27
+ re-export. Delete it, or test your callers with `sendMail` mocked.
@@ -0,0 +1,7 @@
1
+ {
2
+ "id": "mail-reexport",
3
+ "rule": null,
4
+ "introducedIn": "0.8.0",
5
+ "targets": ["src/lib/mail.ts", "src/lib/mail.test.ts", "tests/mail.test.ts"],
6
+ "order": 10
7
+ }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "id": "no-raw-fetch",
3
3
  "rule": "safe-fetch",
4
- "introducedIn": "0.7.0",
4
+ "introducedIn": "0.8.0",
5
5
  "testOnly": true
6
6
  }
@@ -0,0 +1,45 @@
1
+ // Code migration platform-routes. Adds src/app/api/qore/[...path]/route.ts,
2
+ // the one file through which the platform serves its routes inside a Next app
3
+ // (/api/qore/*), so a new platform route arrives with an SDK release. The first
4
+ // is the CSP report.
5
+ //
6
+ // The old src/app/api/csp-report/route.ts is deleted only when it is a
7
+ // rendering the templates produced and src/proxy.ts already calls qoreProxy,
8
+ // which reports to /api/qore/csp-report. Any other proxy still sends its
9
+ // reports to the old route, so the route stays.
10
+ export const parser = "text"
11
+
12
+ // node scripts/tier1-fingerprints.mjs --templates <QDC-app-templates> src/app/api/csp-report/route.ts
13
+ const CSP_REPORT = new Set([
14
+ "19389ea245971f8b", // react-betterauth-next@edc1939 2026-09-21
15
+ "076b4ffa19d27e91", // react-betterauth-next@a691748 2026-10-08
16
+ ])
17
+
18
+ export const CATCH_ALL = "src/app/api/qore/[...path]/route.ts"
19
+
20
+ export const CATCH_ALL_SOURCE = `// The routes the platform serves inside this app, under /api/qore/*. They live
21
+ // in the SDK, so a new one arrives with a version bump.
22
+ //
23
+ // Next reads \`runtime\` and \`dynamic\` statically off this module and does not
24
+ // follow them into a package, so they stay here as literals.
25
+ export const runtime = "nodejs"
26
+ export const dynamic = "force-dynamic"
27
+
28
+ export { GET, POST } from "@quatronic/sdk/next/platform"
29
+ `
30
+
31
+ const isNext = (api) => ["next.config.mjs", "next.config.ts", "next.config.js"].some((p) => api.exists(p))
32
+
33
+ export function create(api) {
34
+ return isNext(api) ? [{ path: CATCH_ALL, source: CATCH_ALL_SOURCE }] : []
35
+ }
36
+
37
+ export default function transformer(file, api) {
38
+ if (file.path !== "src/app/api/csp-report/route.ts") return undefined
39
+ if (!(api.read("src/proxy.ts") ?? "").includes("qoreProxy(")) return undefined
40
+ if (CSP_REPORT.has(api.fingerprint(file.source))) return null
41
+ return void api.report({
42
+ status: "manual",
43
+ reason: "changed by the team; the proxy now reports to /api/qore/csp-report, so move anything you added there and delete this route",
44
+ })
45
+ }
@@ -0,0 +1,30 @@
1
+ # platform-routes: one route file for the platform
2
+
3
+ The platform serves its own routes inside your app under `/api/qore/*` through
4
+ one file, so a new platform route arrives with an SDK release instead of a new
5
+ file in your repo:
6
+
7
+ ```ts
8
+ // src/app/api/qore/[...path]/route.ts
9
+ export const runtime = "nodejs"
10
+ export const dynamic = "force-dynamic"
11
+
12
+ export { GET, POST } from "@quatronic/sdk/next/platform"
13
+ ```
14
+
15
+ The upgrade bot adds it to every Next app:
16
+
17
+ ```bash
18
+ node node_modules/@quatronic/sdk/migrations/run.mjs --only platform-routes
19
+ ```
20
+
21
+ The first route is the CSP report, `/api/qore/csp-report`. The old
22
+ `src/app/api/csp-report/route.ts` is deleted once `src/proxy.ts` calls
23
+ `qoreProxy`, because that proxy reports to the new path. A proxy that does not
24
+ call `qoreProxy` yet still reports to the old route, so the route stays until
25
+ the proxy moves.
26
+
27
+ A `csp-report` route your team changed is listed in the pull request. Move what
28
+ you added and delete the file.
29
+
30
+ `/api/healthz` stays where it is: the portal's monitor calls that path.
@@ -0,0 +1,7 @@
1
+ {
2
+ "id": "platform-routes",
3
+ "rule": null,
4
+ "introducedIn": "0.8.0",
5
+ "targets": ["src/app/api/csp-report/route.ts"],
6
+ "order": 30
7
+ }
@@ -0,0 +1,263 @@
1
+ // Code migration qore-boot. Moves an app's boot onto the SDK, so the
2
+ // platform's boot steps (Sentry, the integrations check, auth and app
3
+ // migrations, the preview seed) reach it as SDK releases from now on:
4
+ //
5
+ // src/instrumentation.ts -> qoreRegister({ ...what only the app can name })
6
+ // src/lib/migrate.ts -> migrateApp({ schema })
7
+ // src/index.ts (Node) -> qoreBoot({ integrations }); its Sentry calls stay
8
+ //
9
+ // Tier 1 only: a file is replaced whole when it is a rendering the templates
10
+ // produced (its fingerprint is in a table below) and left byte-identical
11
+ // otherwise, with a note for a person. instrumentation.ts and migrate.ts move
12
+ // together, since the new instrumentation no longer hands migrate.ts its
13
+ // database; one of them changed by the team leaves both alone.
14
+ //
15
+ // Renderings from before Sentry (2026-09-29) are recognised but not replaced:
16
+ // the move to Sentry also changed next.config and the environment, which a
17
+ // file swap cannot do.
18
+ export const parser = "text"
19
+
20
+ // node scripts/tier1-fingerprints.mjs, renderings from 2026-09-29 on.
21
+ const INSTRUMENTATION = new Set([
22
+ "a7431df89a0b67b5", // react-betterauth-next@8292521 2026-09-29
23
+ "020918bc58e7ba6e", // react-betterauth-next@a08be54 2026-09-30
24
+ "293aa47ff009f7b6", // react-betterauth-next@bd01653 2026-10-07
25
+ "52b92e707b305eab", // react-betterauth-next@2520231 2026-10-08
26
+ "000a429e9eea52cd", // react-betterauth-next@a691748 2026-10-08
27
+ "740148fbd0f9c60a", // react-keycloak-next@8292521 2026-09-29
28
+ "0fafd9c871de3195", // react-keycloak-next@a08be54 2026-09-30
29
+ "a6c63c56aab200ac", // react-keycloak-next@bd01653 2026-10-07
30
+ "c065c569f6009222", // react-keycloak-next@2520231 2026-10-08
31
+ "6fa8caf03ea54ceb", // react-keycloak-next@a691748 2026-10-08
32
+ "f060078324bb1171", // react-next-minimal@8292521 2026-09-29
33
+ "2a604598ecee2da6", // react-next-minimal@bd01653 2026-10-07
34
+ "37877ccca36f92b5", // react-next-minimal@2520231 2026-10-08
35
+ ])
36
+
37
+ // Renderings with a separate migration role (MIGRATION_DATABASE_URL, 2026-08-07 on).
38
+ const MIGRATE = new Set([
39
+ "a20193090f5b9153", // react-betterauth-next@2256ea4 2026-08-07
40
+ "25b89335130d396d", // react-betterauth-next@0df3d74 2026-08-11
41
+ "533b5b7834735b90", // react-betterauth-next@2fd295e 2026-09-07
42
+ "9a1662ccd7891624", // react-betterauth-next@a691748 2026-10-08
43
+ "de99419c0047eee3", // react-keycloak-next@2256ea4 2026-08-07
44
+ "a4836b70150f667b", // react-keycloak-next@d8fbd59 2026-08-10
45
+ "fe6d3504e525cb47", // react-keycloak-next@0df3d74 2026-08-11
46
+ "0b3c02bf441162ea", // react-keycloak-next@2fd295e 2026-09-07
47
+ ])
48
+
49
+ const INDEX = new Set([
50
+ "e1ed6784713e8271", // node-backend@8292521 2026-09-29
51
+ "6dd930c7d884fa0b", // node-backend@bd01653 2026-10-07
52
+ "ca9dec2dec2e9e12", // node-backend@2520231 2026-10-08
53
+ "bd5544b0649d7bcc", // node-backend@a691748 2026-10-08
54
+ ])
55
+
56
+ // Recognised, too old to replace.
57
+ const BEFORE_SENTRY = new Set([
58
+ "cc58fc71a5a059ea", // node-backend@5225413 2026-07-10
59
+ "bb660121cf43aaf3", // node-backend@2fd295e 2026-09-07
60
+ "f56dfa2cae1b027b", // react-betterauth-next@f2c7a50 2026-07-22
61
+ "df6b33b45da5dc55", // react-betterauth-next@2256ea4 2026-08-07
62
+ "c305ef528ff9f74b", // react-betterauth-next@2fd295e 2026-09-07
63
+ "d8c743636927f8ca", // react-keycloak-next@5225413 2026-07-10
64
+ "5281265e84a755e0", // react-keycloak-next@d75718e 2026-07-17
65
+ "b7bcfde84adfcf89", // react-keycloak-next@2256ea4 2026-08-07
66
+ "fd7ef717a9ad087e", // react-keycloak-next@2fd295e 2026-09-07
67
+ "3c81f8c30f47875a", // react-next-db@5225413 2026-07-10
68
+ "6f246f0220ab84a4", // react-next-minimal@5225413 2026-07-10
69
+ "65af87340987e7b2", // react-next-minimal@2fd295e 2026-09-07
70
+ "f62c7be31c921fbe", // node-backend@5225413 2026-07-10 (src/index.ts)
71
+ "7f1ba1bdc3f92281", // node-backend@2fd295e 2026-09-07 (src/index.ts)
72
+ ])
73
+ const BEFORE_ROLES = new Set([
74
+ "b233596621f33ee6", // react-betterauth-next@f2c7a50 2026-07-22
75
+ "de1e472020510ed5", // react-keycloak-next@5225413 2026-07-10
76
+ ])
77
+
78
+ const INSTR = "src/instrumentation.ts"
79
+ const MIGRATE_TS = "src/lib/migrate.ts"
80
+ const SEE = "move it by hand, see the qore-boot instructions"
81
+
82
+ const manual = (api, reason) => void api.report({ status: "manual", reason: `${reason}; ${SEE}` })
83
+
84
+ /** Where migrate.ts stands: "new", "template", "absent", or why it is none of those. */
85
+ function migrateState(api) {
86
+ const source = api.read(MIGRATE_TS)
87
+ if (source === null) return "absent"
88
+ if (source.includes("migrateApp(")) return "new"
89
+ const fp = api.fingerprint(source)
90
+ if (MIGRATE.has(fp)) return "template"
91
+ if (BEFORE_ROLES.has(fp)) return "src/lib/migrate.ts was generated before the migration role (2026-08)"
92
+ return "src/lib/migrate.ts was changed by the team"
93
+ }
94
+
95
+ function instrumentation(file, api) {
96
+ if (file.source.includes("qoreRegister")) return undefined
97
+ const fp = api.fingerprint(file.source)
98
+ if (BEFORE_SENTRY.has(fp)) return manual(api, "generated before Sentry (2026-09-29)")
99
+ if (!INSTRUMENTATION.has(fp)) return manual(api, "changed by the team")
100
+ const state = migrateState(api)
101
+ if (!["new", "template", "absent"].includes(state)) return manual(api, state)
102
+
103
+ const migrateSource = api.read(MIGRATE_TS) ?? ""
104
+ const loaders = []
105
+ if (api.exists("src/config/integrations.ts")) loaders.push(`integrations: () => import("@/config/integrations"),`)
106
+ if (/\bserverEnv\b/.test(file.source + migrateSource) && api.exists("src/config/env.ts")) {
107
+ loaders.push(`env: () => import("@/config/env"),`)
108
+ }
109
+ if (file.source.includes("runAuthMigrations")) loaders.push("authMigrations: true,")
110
+ if (file.source.includes("runAppMigrations") && state !== "absent") loaders.push(`migrations: () => import("./lib/migrate"),`)
111
+ // QDC_RUN_SEED before 2026-09-30; the platform has set QORE_RUN_SEED since.
112
+ if (/\b(QDC|QORE)_RUN_SEED\b/.test(file.source) && api.exists("src/scripts/seed.ts")) {
113
+ loaders.push(`seed: () => import("./scripts/seed"),`)
114
+ }
115
+ return nextInstrumentation(loaders)
116
+ }
117
+
118
+ /** The thin instrumentation.ts; the templates render the same text. */
119
+ export function nextInstrumentation(loaders) {
120
+ const node =
121
+ loaders.length === 0
122
+ ? "undefined"
123
+ : `process.env.NEXT_RUNTIME === "nodejs"
124
+ ? {
125
+ ${loaders.join("\n ")}
126
+ }
127
+ : undefined`
128
+ return `import { qoreRegister } from "@quatronic/sdk/next/boot"
129
+
130
+ export { onRequestError } from "@quatronic/sdk/next/boot"
131
+
132
+ // The platform's boot steps (Sentry, the integrations check, migrations, the
133
+ // preview seed) live in the SDK and arrive with its releases. Pass what only
134
+ // this app can name; put the app's own boot code after the call.
135
+ export async function register() {
136
+ await qoreRegister(
137
+ ${node},
138
+ )
139
+ }
140
+ `
141
+ }
142
+
143
+ function migrate(file, api) {
144
+ if (file.source.includes("migrateApp(")) return undefined
145
+ const fp = api.fingerprint(file.source)
146
+ if (BEFORE_ROLES.has(fp)) return manual(api, "generated before the migration role (2026-08)")
147
+ if (!MIGRATE.has(fp)) return manual(api, "changed by the team")
148
+ // instrumentation.ts runs first and decides whether the pair moves.
149
+ if (!(api.read(INSTR) ?? "").includes("qoreRegister")) return manual(api, "moves together with src/instrumentation.ts")
150
+ return file.source.includes("ensureAdminSeed") ? BETTERAUTH_MIGRATE : DRIZZLE_MIGRATE
151
+ }
152
+
153
+ export const DRIZZLE_MIGRATE = `// Applies this app's drizzle-kit migrations at boot. Add one with \`pnpm db:generate\`.
154
+ import { migrateApp } from "@quatronic/sdk/next/db"
155
+ import { appSchema } from "@/db/schema"
156
+
157
+ export async function runAppMigrations(): Promise<void> {
158
+ await migrateApp({ schema: appSchema.schemaName })
159
+ }
160
+ `
161
+
162
+ export const BETTERAUTH_MIGRATE = `import { eq } from "drizzle-orm"
163
+ import type { NodePgDatabase } from "drizzle-orm/node-postgres"
164
+ import * as Sentry from "@sentry/nextjs"
165
+ import { migrateApp } from "@quatronic/sdk/next/db"
166
+ import { getDb } from "@/lib/db"
167
+ import { user } from "@/db/schema"
168
+ import { getAuth } from "@/lib/auth"
169
+
170
+ // Applies Better Auth's migrations at boot, then seeds the first admin.
171
+ export async function runAppMigrations(): Promise<void> {
172
+ await migrateApp({ schema: "public" })
173
+ await ensureAdminSeed(getDb())
174
+ }
175
+
176
+ // Creates the admin from ADMIN_EMAIL + ADMIN_PASSWORD, once, if it is absent.
177
+ async function ensureAdminSeed(db: NodePgDatabase): Promise<void> {
178
+ const email = process.env.ADMIN_EMAIL?.toLowerCase()
179
+ const password = process.env.ADMIN_PASSWORD
180
+ if (!email && !password) return
181
+ if (!email || !password || password.length < 8) {
182
+ Sentry.logger.warn(
183
+ "admin seed skipped: ADMIN_EMAIL and ADMIN_PASSWORD (min 8 chars) must both be set",
184
+ )
185
+ return
186
+ }
187
+ const existing = await db.select().from(user).where(eq(user.email, email)).limit(1)
188
+ if (existing.length > 0) return
189
+ try {
190
+ await getAuth().api.signUpEmail({ body: { email, password, name: "Admin" } })
191
+ await db.update(user).set({ role: "admin" }).where(eq(user.email, email))
192
+ Sentry.logger.info("admin seeded", { "qore.audit.event": "admin.seeded" })
193
+ } catch (err) {
194
+ // A concurrent boot may have created the row already; anything else is real.
195
+ const raced = await db.select().from(user).where(eq(user.email, email)).limit(1)
196
+ if (raced.length > 0) return
197
+ Sentry.captureException(err, { tags: { "qore.seed.step": "admin" } })
198
+ }
199
+ }
200
+ `
201
+
202
+ function index(file, api) {
203
+ if (file.source.includes("qoreBoot")) return undefined
204
+ const fp = api.fingerprint(file.source)
205
+ if (BEFORE_SENTRY.has(fp)) return manual(api, "generated before Sentry (2026-09-29)")
206
+ // A backend's index.ts is where its routes go, so most are changed by the
207
+ // team. Their Sentry calls stay as they are, and assertIntegrations keeps
208
+ // working.
209
+ if (!INDEX.has(fp)) {
210
+ if (!file.source.includes("@quatronic/sdk/node/integrations")) return undefined
211
+ return void api.report({ status: "kept", reason: "changed by the team; qoreBoot({ integrations }) can replace assertIntegrations" })
212
+ }
213
+ return nodeIndex(api.exists("src/config/integrations.ts"))
214
+ }
215
+
216
+ /** The thin Node index.ts; the templates render the same text. */
217
+ export function nodeIndex(integrations) {
218
+ return `// HTTP entry point. Add routes inside the handler below.
219
+ import { createServer } from "node:http"
220
+ import * as Sentry from "@sentry/node"
221
+ import { qoreBoot } from "@quatronic/sdk/node/boot"
222
+ import { env } from "./config/env.js"
223
+ ${integrations ? `import { integrations } from "./config/integrations.js"\n` : ""}
224
+ // The platform's boot steps live in the SDK and arrive with its releases.
225
+ qoreBoot(${integrations ? "{ integrations }" : ""})
226
+
227
+ const server = createServer(async (req, res) => {
228
+ if (req.url === "/healthz") {
229
+ res.writeHead(200, { "content-type": "text/plain" })
230
+ res.end("ok")
231
+ return
232
+ }
233
+
234
+ try {
235
+ res.writeHead(404, { "content-type": "text/plain" })
236
+ res.end("not found")
237
+ } catch (err) {
238
+ Sentry.captureException(err)
239
+ if (!res.headersSent) {
240
+ res.writeHead(500, { "content-type": "text/plain" })
241
+ res.end("internal error")
242
+ }
243
+ }
244
+ })
245
+
246
+ server.listen(env.PORT, () => {
247
+ Sentry.logger.info("backend listening", { "qore.server.port": env.PORT })
248
+ })
249
+ `
250
+ }
251
+
252
+ const isNext = (api) => ["next.config.mjs", "next.config.ts", "next.config.js"].some((p) => api.exists(p))
253
+
254
+ export default function transformer(file, api) {
255
+ if (file.path === INSTR) {
256
+ if (isNext(api)) return instrumentation(file, api)
257
+ // A backend's instrumentation.ts is the OTel preload that Sentry replaced.
258
+ return BEFORE_SENTRY.has(api.fingerprint(file.source)) ? manual(api, "generated before Sentry (2026-09-29)") : undefined
259
+ }
260
+ if (file.path === MIGRATE_TS) return migrate(file, api)
261
+ if (file.path === "src/index.ts" && !isNext(api)) return index(file, api)
262
+ return undefined
263
+ }
@@ -0,0 +1,74 @@
1
+ # qore-boot: boot through the SDK
2
+
3
+ The platform's boot steps (Sentry, the integrations check, auth and app
4
+ migrations, the preview seed) used to be written out in each app. They now live
5
+ in the SDK, so a new or fixed boot step reaches your app as an SDK release.
6
+
7
+ The upgrade bot runs this for you:
8
+
9
+ ```bash
10
+ node node_modules/@quatronic/sdk/migrations/run.mjs --only qore-boot
11
+ ```
12
+
13
+ It replaces a file only when it is exactly what the templates generated. A file
14
+ your team changed, or one generated before Sentry (2026-09-29), is left as it is
15
+ and listed in the pull request. Move it by hand as below.
16
+
17
+ ## Next apps: `src/instrumentation.ts`
18
+
19
+ Pass what only your app can name. Leave out a line your app does not have.
20
+
21
+ ```ts
22
+ import { qoreRegister } from "@quatronic/sdk/next/boot"
23
+
24
+ export { onRequestError } from "@quatronic/sdk/next/boot"
25
+
26
+ export async function register() {
27
+ await qoreRegister(
28
+ process.env.NEXT_RUNTIME === "nodejs"
29
+ ? {
30
+ integrations: () => import("@/config/integrations"),
31
+ env: () => import("@/config/env"),
32
+ authMigrations: true, // Keycloak apps only
33
+ migrations: () => import("./lib/migrate"),
34
+ seed: () => import("./scripts/seed"),
35
+ }
36
+ : undefined,
37
+ )
38
+ // your own boot code goes here, after migrations
39
+ }
40
+ ```
41
+
42
+ Keep the `NEXT_RUNTIME` ternary: it keeps the database code out of the edge
43
+ bundle. The seed runs only when `QORE_RUN_SEED=true` (previews); a failing seed
44
+ is reported, never thrown.
45
+
46
+ ## Next apps: `src/lib/migrate.ts`
47
+
48
+ `runAppMigrations` no longer gets a database: `migrateApp` connects as the
49
+ migration role (`MIGRATION_DATABASE_URL`) and grants the runtime role
50
+ (`DATABASE_URL`) access afterwards.
51
+
52
+ ```ts
53
+ import { migrateApp } from "@quatronic/sdk/next/db"
54
+ import { appSchema } from "@/db/schema"
55
+
56
+ export async function runAppMigrations(): Promise<void> {
57
+ await migrateApp({ schema: appSchema.schemaName }) // or "public"
58
+ // your own post-migration steps
59
+ }
60
+ ```
61
+
62
+ An app generated before 2026-08 has no `MIGRATION_DATABASE_URL`. Check that the
63
+ key is in its secrets in the portal before you move it; without it the app does
64
+ not boot.
65
+
66
+ ## Node backends: `src/index.ts`
67
+
68
+ Replace `assertIntegrations(integrations)` with `qoreBoot({ integrations })`
69
+ from `@quatronic/sdk/node/boot`. Leave the file's `Sentry` calls as they are.
70
+
71
+ An old `src/instrumentation.ts` in a backend is the OpenTelemetry preload from
72
+ before Sentry; Sentry starts through `node --import
73
+ @quatronic/sdk/node/sentry/register` now. Delete it once the start script uses
74
+ that.
@@ -0,0 +1,7 @@
1
+ {
2
+ "id": "qore-boot",
3
+ "rule": null,
4
+ "introducedIn": "0.8.0",
5
+ "targets": ["src/instrumentation.ts", "src/lib/migrate.ts", "src/index.ts"],
6
+ "order": 10
7
+ }
@@ -0,0 +1,88 @@
1
+ // Code migration qore-proxy. An app's src/proxy.ts becomes a call to
2
+ // qoreProxy from @quatronic/sdk/next/security, so the session pre-check, the
3
+ // security headers and the CSP reach it as SDK releases.
4
+ //
5
+ // Tier 1 only: a proxy the templates produced is replaced, keeping its
6
+ // `config` literal byte for byte (Next reads the matcher statically, and which
7
+ // routes stay public is the app's decision). A proxy the team changed is kept.
8
+ //
9
+ // Renderings from before the security headers (2026-09-21) are recognised but
10
+ // left for a person: qoreProxy would add enforced headers (X-Frame-Options
11
+ // DENY, a Permissions-Policy without camera, microphone or location, HSTS with
12
+ // preload) that can break an app embedded in an iframe or using those devices.
13
+ // The first Keycloak proxy (2026-07-10) also redirected to an app-side /login
14
+ // that later apps do not have.
15
+ export const parser = "text"
16
+
17
+ // node scripts/tier1-fingerprints.mjs --templates <QDC-app-templates> src/proxy.ts
18
+ const PROXY = new Map([
19
+ ["9808d3c1ef378788", "betterauth"], // react-betterauth-next@edc1939 2026-09-21
20
+ ["e94461517c0935dd", "keycloak"], // react-keycloak-next@edc1939 2026-09-21
21
+ ["abdce3416f505af0", "none"], // react-next-db@edc1939 2026-09-21
22
+ ])
23
+
24
+ // Recognised, not replaced: no security headers yet.
25
+ const BEFORE_HEADERS = new Set([
26
+ "1033f02ea39784a6", // react-betterauth-next@f2c7a50 2026-07-22
27
+ "e062b854d7f4dd17", // react-betterauth-next@2fd295e 2026-09-07
28
+ "1ab0e445ca3b456e", // react-keycloak-next@85719d3 2026-08-03
29
+ "45e1bb378d7caf54", // react-keycloak-next@2fd295e 2026-09-07
30
+ ])
31
+
32
+ // Recognised, not replaced: redirects to an app-side /login. The early
33
+ // next-db and minimal apps (2026-07) carried the same file.
34
+ const LOGIN_PAGE = new Set([
35
+ "4095d7970f158540", // react-keycloak-next@5225413 2026-07-10
36
+ ])
37
+
38
+ const SEE = "see the qore-proxy instructions"
39
+
40
+ /** The `export const config = {...}` block, verbatim, or null. */
41
+ function configBlock(source) {
42
+ const start = source.indexOf("export const config = {")
43
+ if (start < 0) return null
44
+ const end = source.indexOf("\n}", start)
45
+ return end < 0 ? null : source.slice(start, end + 2)
46
+ }
47
+
48
+ export function proxySource(auth, config) {
49
+ const arg = auth === "none" ? "" : `{ auth: "${auth}" }`
50
+ return `import { qoreProxy } from "@quatronic/sdk/next/security"
51
+
52
+ // The session pre-check (real validation stays server-side), the security
53
+ // headers and the per-response CSP nonce come from the SDK, so a fix reaches
54
+ // this app with a version bump. Put the app's own proxy logic in
55
+ // qoreProxy({ handler }).
56
+ export const proxy = qoreProxy(${arg})
57
+
58
+ // Next extracts \`config\` from this file statically, at build time, so the
59
+ // matcher has to be a literal. \`proxyMatcher\` in @quatronic/sdk/next/security
60
+ // builds one; the security test in tests/security/ asserts this literal still
61
+ // excludes the build output and the image optimizer.
62
+ ${config}
63
+ `
64
+ }
65
+
66
+ export default function transformer(file, api) {
67
+ if (file.path !== "src/proxy.ts") return undefined
68
+ if (file.source.includes("qoreProxy(")) return undefined
69
+ const fp = api.fingerprint(file.source)
70
+ if (LOGIN_PAGE.has(fp)) {
71
+ return void api.report({
72
+ status: "manual",
73
+ reason: `generated when the app had its own /login page (2026-07); move it to qoreProxy({ auth: "keycloak" }) by hand, ${SEE}`,
74
+ })
75
+ }
76
+ if (BEFORE_HEADERS.has(fp)) {
77
+ return void api.report({
78
+ status: "manual",
79
+ reason: `generated before the security headers (2026-09-21); qoreProxy adds X-Frame-Options DENY and turns off camera, microphone and location, so check the app is not embedded in an iframe and does not use them, then move it by hand, ${SEE}`,
80
+ })
81
+ }
82
+ const auth = PROXY.get(fp)
83
+ const config = configBlock(file.source)
84
+ if (!auth || !config) {
85
+ return void api.report({ status: "kept", reason: `changed by the team; qoreProxy({ handler }) can carry your logic, ${SEE}` })
86
+ }
87
+ return proxySource(auth, config)
88
+ }
@@ -0,0 +1,56 @@
1
+ # qore-proxy: the proxy from the SDK
2
+
3
+ `src/proxy.ts` used to hold the session-cookie check and the security-header
4
+ wrapper. Both now come from `qoreProxy` in `@quatronic/sdk/next/security`, so a
5
+ change to them reaches your app as an SDK release.
6
+
7
+ The upgrade bot runs this for you:
8
+
9
+ ```bash
10
+ node node_modules/@quatronic/sdk/migrations/run.mjs --only qore-proxy
11
+ ```
12
+
13
+ A proxy exactly as the templates generated it becomes:
14
+
15
+ ```ts
16
+ import { qoreProxy } from "@quatronic/sdk/next/security"
17
+
18
+ export const proxy = qoreProxy({ auth: "keycloak" }) // or "betterauth", or no argument
19
+
20
+ export const config = {
21
+ matcher: [/* your existing literal, unchanged */],
22
+ }
23
+ ```
24
+
25
+ The `config` literal is kept byte for byte: which routes are public is your
26
+ app's decision, and Next reads it statically.
27
+
28
+ A proxy generated before 2026-09-21 had no security headers, and the migration
29
+ leaves it for a person. `qoreProxy` sends them, and some are enforced:
30
+ `X-Frame-Options: DENY` stops the app loading in an iframe, the
31
+ `Permissions-Policy` turns off camera, microphone and location, and HSTS asks
32
+ browsers to use HTTPS for two years, subdomains included. Check that the app
33
+ needs none of these before you move it. The Content-Security-Policy is
34
+ report-only, so it blocks nothing. Reports go to `/api/qore/csp-report` (the
35
+ `platform-routes` migration adds that route).
36
+
37
+ ## By hand
38
+
39
+ A proxy your team changed is kept and listed in the pull request. Move your
40
+ logic into `handler`. It runs after the session check passes; return nothing to
41
+ pass through, or a `Response` to answer early:
42
+
43
+ ```ts
44
+ export const proxy = qoreProxy({
45
+ auth: "keycloak",
46
+ handler: async (req) => {
47
+ // your code
48
+ return undefined
49
+ },
50
+ })
51
+ ```
52
+
53
+ The first Keycloak proxy (generated in 2026-07) redirected to an app-side
54
+ `/login` page. `qoreProxy({ auth: "keycloak" })` redirects to `/api/auth/login`,
55
+ the SDK's Keycloak login route. Check that the app has that route before you
56
+ switch.
@@ -0,0 +1,7 @@
1
+ {
2
+ "id": "qore-proxy",
3
+ "rule": null,
4
+ "introducedIn": "0.8.0",
5
+ "targets": ["src/proxy.ts"],
6
+ "order": 20
7
+ }