@quatronic/sdk 0.7.1-rc.7 → 0.7.1-test.167ddea

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 (101) hide show
  1. package/dist/chunk-5RAO3LPF.js +116 -0
  2. package/dist/chunk-5RAO3LPF.js.map +1 -0
  3. package/dist/{chunk-G7VPNC6M.js → chunk-IFESUTF2.js} +21 -100
  4. package/dist/chunk-IFESUTF2.js.map +1 -0
  5. package/dist/{chunk-2AYDFLKR.js → chunk-NMJOF3ZM.js} +6 -104
  6. package/dist/chunk-NMJOF3ZM.js.map +1 -0
  7. package/dist/chunk-P7HNHLW7.js +65 -0
  8. package/dist/chunk-P7HNHLW7.js.map +1 -0
  9. package/dist/chunk-POZI4OKJ.js +20 -0
  10. package/dist/chunk-POZI4OKJ.js.map +1 -0
  11. package/dist/chunk-TPBRMW5N.js +197 -0
  12. package/dist/chunk-TPBRMW5N.js.map +1 -0
  13. package/dist/chunk-YFZB5EW6.js +107 -0
  14. package/dist/chunk-YFZB5EW6.js.map +1 -0
  15. package/dist/cli/legacy/qdc-sourcemaps.js +16 -6
  16. package/dist/cli/skills-postinstall.js +4 -3
  17. package/dist/cli/skills.js +4 -3
  18. package/dist/cli/sourcemaps.js +16 -6
  19. package/dist/integrations/index.d.ts +3 -75
  20. package/dist/integrations/index.js +6 -4
  21. package/dist/mail/index.d.ts +9 -0
  22. package/dist/mail/index.js +26 -0
  23. package/dist/mail/index.js.map +1 -0
  24. package/dist/next/auth/index.js +2 -152
  25. package/dist/next/auth/index.js.map +1 -1
  26. package/dist/next/boot/index.d.ts +39 -0
  27. package/dist/next/boot/index.js +22 -0
  28. package/dist/next/boot/index.js.map +1 -0
  29. package/dist/next/db/index.d.ts +27 -1
  30. package/dist/next/db/index.js +45 -3
  31. package/dist/next/db/index.js.map +1 -1
  32. package/dist/next/global-error/index.d.ts +9 -0
  33. package/dist/next/global-error/index.js +17 -0
  34. package/dist/next/global-error/index.js.map +1 -0
  35. package/dist/next/integrations/index.d.ts +2 -1
  36. package/dist/next/integrations/index.js +6 -4
  37. package/dist/next/platform/index.d.ts +19 -0
  38. package/dist/next/platform/index.js +44 -0
  39. package/dist/next/platform/index.js.map +1 -0
  40. package/dist/next/security/index.d.ts +23 -1
  41. package/dist/next/security/index.js +40 -57
  42. package/dist/next/security/index.js.map +1 -1
  43. package/dist/next/security/testing.js +10 -1
  44. package/dist/next/security/testing.js.map +1 -1
  45. package/dist/next/sentry/client.js +2 -1
  46. package/dist/next/sentry/client.js.map +1 -1
  47. package/dist/next/sentry/index.d.ts +1 -0
  48. package/dist/next/sentry/index.js +5 -1
  49. package/dist/next/sentry/index.js.map +1 -1
  50. package/dist/next/sentry/register.js +6 -13
  51. package/dist/next/sentry/register.js.map +1 -1
  52. package/dist/node/boot/index.d.ts +9 -0
  53. package/dist/node/boot/index.js +13 -0
  54. package/dist/node/boot/index.js.map +1 -0
  55. package/dist/node/integrations/index.d.ts +2 -1
  56. package/dist/node/integrations/index.js +6 -4
  57. package/dist/node/sentry/index.d.ts +3 -0
  58. package/dist/node/sentry/index.js +7 -0
  59. package/dist/node/sentry/index.js.map +1 -0
  60. package/dist/node/sentry/register.js +2 -1
  61. package/dist/node/sentry/register.js.map +1 -1
  62. package/dist/node-YQDRNIYH.js +33 -0
  63. package/dist/node-YQDRNIYH.js.map +1 -0
  64. package/dist/types-Cl7g4ego.d.ts +80 -0
  65. package/migrations/bootstrap-qore-env/codemod.mjs +77 -0
  66. package/migrations/bootstrap-qore-env/instructions.md +28 -0
  67. package/migrations/bootstrap-qore-env/meta.json +7 -0
  68. package/migrations/global-error/codemod.mjs +28 -0
  69. package/migrations/global-error/instructions.md +26 -0
  70. package/migrations/global-error/meta.json +7 -0
  71. package/migrations/local-db-port/codemod.mjs +61 -0
  72. package/migrations/local-db-port/instructions.md +45 -0
  73. package/migrations/local-db-port/meta.json +7 -0
  74. package/migrations/mail-reexport/codemod.mjs +64 -0
  75. package/migrations/mail-reexport/instructions.md +27 -0
  76. package/migrations/mail-reexport/meta.json +7 -0
  77. package/migrations/no-raw-fetch/meta.json +1 -1
  78. package/migrations/platform-routes/codemod.mjs +45 -0
  79. package/migrations/platform-routes/instructions.md +30 -0
  80. package/migrations/platform-routes/meta.json +7 -0
  81. package/migrations/qore-boot/codemod.mjs +271 -0
  82. package/migrations/qore-boot/instructions.md +74 -0
  83. package/migrations/qore-boot/meta.json +7 -0
  84. package/migrations/qore-proxy/codemod.mjs +88 -0
  85. package/migrations/qore-proxy/instructions.md +56 -0
  86. package/migrations/qore-proxy/meta.json +7 -0
  87. package/migrations/run.mjs +334 -0
  88. package/migrations/sourcemaps-finalize/codemod.mjs +63 -0
  89. package/migrations/sourcemaps-finalize/instructions.md +56 -0
  90. package/migrations/sourcemaps-finalize/meta.json +7 -0
  91. package/package.json +27 -2
  92. package/skills/catalog.json +1 -0
  93. package/skills/qore-add-env-key/SKILL.md +57 -0
  94. package/skills/qore-add-integration/SKILL.next.md +13 -7
  95. package/skills/qore-add-integration/SKILL.node.md +13 -7
  96. package/skills/qore-author-skill/SKILL.md +1 -0
  97. package/workspace-requirements.json +4 -0
  98. package/dist/chunk-2AYDFLKR.js.map +0 -1
  99. package/dist/chunk-BJN7YE63.js +0 -46
  100. package/dist/chunk-BJN7YE63.js.map +0 -1
  101. package/dist/chunk-G7VPNC6M.js.map +0 -1
@@ -0,0 +1,45 @@
1
+ # local-db-port: the local database on the assigned port, loopback only
2
+
3
+ The portal assigns every module with a database its own local port (`DB_PORT`),
4
+ so two modules never fight over 5432, and `DATABASE_URL` from `qore env pull`
5
+ points at that port. Two things in older apps get in the way:
6
+
7
+ - `docker-compose.yml` binds the port on every network interface, so the
8
+ database, with its well-known `postgres`/`postgres` login, is reachable from
9
+ your whole network.
10
+ - In a Next app, `pnpm db:up` does not read `.env.local`, where `DB_PORT` is. The
11
+ database then starts on 5432 while the app connects to the assigned port.
12
+
13
+ The upgrade bot runs this for you:
14
+
15
+ ```bash
16
+ node node_modules/@quatronic/sdk/migrations/run.mjs --only local-db-port
17
+ ```
18
+
19
+ ```diff
20
+ # docker-compose.yml
21
+ ports:
22
+ - - "${DB_PORT:-5432}:5432"
23
+ + - "127.0.0.1:${DB_PORT:-5432}:5432"
24
+ ```
25
+
26
+ ```diff
27
+ # package.json (Next apps)
28
+ - "db:up": "docker compose up -d --wait",
29
+ + "db:up": "docker compose --env-file .env.local up -d --wait",
30
+ ```
31
+
32
+ A backend needs no `--env-file`: docker compose reads `.env` by itself.
33
+
34
+ ## Did you put `DB_PORT` in `.env`?
35
+
36
+ Apps generated before August 2026 have a README tip: "Create a `.env` file next
37
+ to `docker-compose.yml` with `DB_PORT=5433`". After this migration a Next app's
38
+ `db:up` reads `.env.local` only, so that `.env` is ignored and the database
39
+ starts on 5432 again. Move the line to `.env.local` (or run `qore env pull`,
40
+ which writes the assigned `DB_PORT` there) and delete the `.env` if nothing
41
+ else is in it. `.env` is not committed, so the upgrade bot cannot see or move
42
+ it for you.
43
+
44
+ If your database was already running, restart it once with
45
+ `pnpm db:down && pnpm db:up`. It comes back on the assigned port with its data.
@@ -0,0 +1,7 @@
1
+ {
2
+ "id": "local-db-port",
3
+ "rule": null,
4
+ "introducedIn": "0.8.0",
5
+ "targets": ["docker-compose.yml", "package.json"],
6
+ "order": 10
7
+ }
@@ -0,0 +1,64 @@
1
+ // Code migration mail-reexport. An app's src/lib/mail.ts becomes a re-export
2
+ // of @quatronic/sdk/mail, so how mail is sent (and logged) reaches it as SDK
3
+ // releases. Every rendering the templates produced has the SDK's signature,
4
+ // `sendMail(mail: Mail)`, so callers do not change.
5
+ //
6
+ // Tier 1 only: a mail.ts the team changed is kept as it is. The template's
7
+ // mail.test.ts (src/lib/ in Next apps, tests/ in backends) tests the old body
8
+ // (it mocks fetch and the logger), so it is
9
+ // deleted together with a replaced mail.ts; one the team changed is left for a
10
+ // person, since it will fail against the re-export.
11
+ export const parser = "text"
12
+
13
+ // node scripts/tier1-fingerprints.mjs --templates <QDC-app-templates> src/lib/mail.ts src/lib/mail.test.ts tests/mail.test.ts
14
+ const MAIL = new Set([
15
+ "865b9881e187cf73", // node-backend@30fdec5 2026-08-04
16
+ "6cb0fa829d99cf77", // node-backend@2fd295e 2026-09-07
17
+ "11fde4240bd6d7f7", // node-backend@8292521 2026-09-29
18
+ "94120fb267e75af8", // node-backend@a691748 2026-10-08
19
+ "f3d629f9d27883d6", // react-betterauth-next@30fdec5 2026-08-04
20
+ "39030a91919715e8", // react-betterauth-next@2fd295e 2026-09-07
21
+ "67c5fad8bf33b463", // react-betterauth-next@a691748 2026-10-08
22
+ ])
23
+
24
+ const MAIL_TEST = new Set([
25
+ "e9225a45d7032231", // react-betterauth-next@30fdec5 2026-08-04
26
+ "a5491c7c345292b0", // react-betterauth-next@a691748 2026-10-08
27
+ "0e14f2ab2f8524dc", // node-backend@28d9400 2026-09-21 tests/mail.test.ts
28
+ "9737c403a50268e4", // node-backend@a691748 2026-10-08 tests/mail.test.ts
29
+ ])
30
+
31
+ const MAIL_TESTS = new Set(["src/lib/mail.test.ts", "tests/mail.test.ts"])
32
+
33
+ const MAIL_TS = "src/lib/mail.ts"
34
+ const REEXPORT = "@quatronic/sdk/mail"
35
+
36
+ export const MAIL_SOURCE = `// Mail transport: Resend when MAIL_API_KEY is set, otherwise a logged skip.
37
+ // It lives in the SDK, so a fix to how mail is sent reaches this app with a
38
+ // version bump.
39
+ export { sendMail, type Mail } from "${REEXPORT}"
40
+ `
41
+
42
+ /** Whether mail.ts is, or is about to become, the re-export. */
43
+ function mailMoves(api) {
44
+ const source = api.read(MAIL_TS)
45
+ if (source === null) return false
46
+ return source.includes(REEXPORT) || MAIL.has(api.fingerprint(source))
47
+ }
48
+
49
+ export default function transformer(file, api) {
50
+ if (file.path === MAIL_TS) {
51
+ if (file.source.includes(REEXPORT)) return undefined
52
+ if (MAIL.has(api.fingerprint(file.source))) return MAIL_SOURCE
53
+ return void api.report({ status: "kept", reason: `changed by the team; it can re-export sendMail from ${REEXPORT}` })
54
+ }
55
+ if (MAIL_TESTS.has(file.path)) {
56
+ if (!mailMoves(api)) return undefined
57
+ if (MAIL_TEST.has(api.fingerprint(file.source))) return null
58
+ return void api.report({
59
+ status: "manual",
60
+ reason: "tests the mail.ts body that moved to the SDK; delete it or test your callers instead",
61
+ })
62
+ }
63
+ return undefined
64
+ }
@@ -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,271 @@
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
+ const AUTH_LOADER = `() => import("@quatronic/sdk/next/db")`
96
+
97
+ function instrumentation(file, api) {
98
+ if (file.source.includes("qoreRegister")) {
99
+ // 0.8.0 candidates took `authMigrations: true`; the loader keeps pg and
100
+ // drizzle out of the boot module.
101
+ return file.source.includes("authMigrations: true")
102
+ ? file.source.replace(/authMigrations: true,?/, `authMigrations: ${AUTH_LOADER},`)
103
+ : undefined
104
+ }
105
+ const fp = api.fingerprint(file.source)
106
+ if (BEFORE_SENTRY.has(fp)) return manual(api, "generated before Sentry (2026-09-29)")
107
+ if (!INSTRUMENTATION.has(fp)) return manual(api, "changed by the team")
108
+ const state = migrateState(api)
109
+ if (!["new", "template", "absent"].includes(state)) return manual(api, state)
110
+
111
+ const migrateSource = api.read(MIGRATE_TS) ?? ""
112
+ const loaders = []
113
+ if (api.exists("src/config/integrations.ts")) loaders.push(`integrations: () => import("@/config/integrations"),`)
114
+ if (/\bserverEnv\b/.test(file.source + migrateSource) && api.exists("src/config/env.ts")) {
115
+ loaders.push(`env: () => import("@/config/env"),`)
116
+ }
117
+ if (file.source.includes("runAuthMigrations")) loaders.push(`authMigrations: ${AUTH_LOADER},`)
118
+ if (file.source.includes("runAppMigrations") && state !== "absent") loaders.push(`migrations: () => import("./lib/migrate"),`)
119
+ // QDC_RUN_SEED before 2026-09-30; the platform has set QORE_RUN_SEED since.
120
+ if (/\b(QDC|QORE)_RUN_SEED\b/.test(file.source) && api.exists("src/scripts/seed.ts")) {
121
+ loaders.push(`seed: () => import("./scripts/seed"),`)
122
+ }
123
+ return nextInstrumentation(loaders)
124
+ }
125
+
126
+ /** The thin instrumentation.ts; the templates render the same text. */
127
+ export function nextInstrumentation(loaders) {
128
+ const node =
129
+ loaders.length === 0
130
+ ? "undefined"
131
+ : `process.env.NEXT_RUNTIME === "nodejs"
132
+ ? {
133
+ ${loaders.join("\n ")}
134
+ }
135
+ : undefined`
136
+ return `import { qoreRegister } from "@quatronic/sdk/next/boot"
137
+
138
+ export { onRequestError } from "@quatronic/sdk/next/boot"
139
+
140
+ // The platform's boot steps (Sentry, the integrations check, migrations, the
141
+ // preview seed) live in the SDK and arrive with its releases. Pass what only
142
+ // this app can name; put the app's own boot code after the call.
143
+ export async function register() {
144
+ await qoreRegister(
145
+ ${node},
146
+ )
147
+ }
148
+ `
149
+ }
150
+
151
+ function migrate(file, api) {
152
+ if (file.source.includes("migrateApp(")) return undefined
153
+ const fp = api.fingerprint(file.source)
154
+ if (BEFORE_ROLES.has(fp)) return manual(api, "generated before the migration role (2026-08)")
155
+ if (!MIGRATE.has(fp)) return manual(api, "changed by the team")
156
+ // instrumentation.ts runs first and decides whether the pair moves.
157
+ if (!(api.read(INSTR) ?? "").includes("qoreRegister")) return manual(api, "moves together with src/instrumentation.ts")
158
+ return file.source.includes("ensureAdminSeed") ? BETTERAUTH_MIGRATE : DRIZZLE_MIGRATE
159
+ }
160
+
161
+ export const DRIZZLE_MIGRATE = `// Applies this app's drizzle-kit migrations at boot. Add one with \`pnpm db:generate\`.
162
+ import { migrateApp } from "@quatronic/sdk/next/db"
163
+ import { appSchema } from "@/db/schema"
164
+
165
+ export async function runAppMigrations(): Promise<void> {
166
+ await migrateApp({ schema: appSchema.schemaName })
167
+ }
168
+ `
169
+
170
+ export const BETTERAUTH_MIGRATE = `import { eq } from "drizzle-orm"
171
+ import type { NodePgDatabase } from "drizzle-orm/node-postgres"
172
+ import * as Sentry from "@sentry/nextjs"
173
+ import { migrateApp } from "@quatronic/sdk/next/db"
174
+ import { getDb } from "@/lib/db"
175
+ import { user } from "@/db/schema"
176
+ import { getAuth } from "@/lib/auth"
177
+
178
+ // Applies Better Auth's migrations at boot, then seeds the first admin.
179
+ export async function runAppMigrations(): Promise<void> {
180
+ await migrateApp({ schema: "public" })
181
+ await ensureAdminSeed(getDb())
182
+ }
183
+
184
+ // Creates the admin from ADMIN_EMAIL + ADMIN_PASSWORD, once, if it is absent.
185
+ async function ensureAdminSeed(db: NodePgDatabase): Promise<void> {
186
+ const email = process.env.ADMIN_EMAIL?.toLowerCase()
187
+ const password = process.env.ADMIN_PASSWORD
188
+ if (!email && !password) return
189
+ if (!email || !password || password.length < 8) {
190
+ Sentry.logger.warn(
191
+ "admin seed skipped: ADMIN_EMAIL and ADMIN_PASSWORD (min 8 chars) must both be set",
192
+ )
193
+ return
194
+ }
195
+ const existing = await db.select().from(user).where(eq(user.email, email)).limit(1)
196
+ if (existing.length > 0) return
197
+ try {
198
+ await getAuth().api.signUpEmail({ body: { email, password, name: "Admin" } })
199
+ await db.update(user).set({ role: "admin" }).where(eq(user.email, email))
200
+ Sentry.logger.info("admin seeded", { "qore.audit.event": "admin.seeded" })
201
+ } catch (err) {
202
+ // A concurrent boot may have created the row already; anything else is real.
203
+ const raced = await db.select().from(user).where(eq(user.email, email)).limit(1)
204
+ if (raced.length > 0) return
205
+ Sentry.captureException(err, { tags: { "qore.seed.step": "admin" } })
206
+ }
207
+ }
208
+ `
209
+
210
+ function index(file, api) {
211
+ if (file.source.includes("qoreBoot")) return undefined
212
+ const fp = api.fingerprint(file.source)
213
+ if (BEFORE_SENTRY.has(fp)) return manual(api, "generated before Sentry (2026-09-29)")
214
+ // A backend's index.ts is where its routes go, so most are changed by the
215
+ // team. Their Sentry calls stay as they are, and assertIntegrations keeps
216
+ // working.
217
+ if (!INDEX.has(fp)) {
218
+ if (!file.source.includes("@quatronic/sdk/node/integrations")) return undefined
219
+ return void api.report({ status: "kept", reason: "changed by the team; qoreBoot({ integrations }) can replace assertIntegrations" })
220
+ }
221
+ return nodeIndex(api.exists("src/config/integrations.ts"))
222
+ }
223
+
224
+ /** The thin Node index.ts; the templates render the same text. */
225
+ export function nodeIndex(integrations) {
226
+ return `// HTTP entry point. Add routes inside the handler below.
227
+ import { createServer } from "node:http"
228
+ import * as Sentry from "@sentry/node"
229
+ import { qoreBoot } from "@quatronic/sdk/node/boot"
230
+ import { env } from "./config/env.js"
231
+ ${integrations ? `import { integrations } from "./config/integrations.js"\n` : ""}
232
+ // The platform's boot steps live in the SDK and arrive with its releases.
233
+ qoreBoot(${integrations ? "{ integrations }" : ""})
234
+
235
+ const server = createServer(async (req, res) => {
236
+ if (req.url === "/healthz") {
237
+ res.writeHead(200, { "content-type": "text/plain" })
238
+ res.end("ok")
239
+ return
240
+ }
241
+
242
+ try {
243
+ res.writeHead(404, { "content-type": "text/plain" })
244
+ res.end("not found")
245
+ } catch (err) {
246
+ Sentry.captureException(err)
247
+ if (!res.headersSent) {
248
+ res.writeHead(500, { "content-type": "text/plain" })
249
+ res.end("internal error")
250
+ }
251
+ }
252
+ })
253
+
254
+ server.listen(env.PORT, () => {
255
+ Sentry.logger.info("backend listening", { "qore.server.port": env.PORT })
256
+ })
257
+ `
258
+ }
259
+
260
+ const isNext = (api) => ["next.config.mjs", "next.config.ts", "next.config.js"].some((p) => api.exists(p))
261
+
262
+ export default function transformer(file, api) {
263
+ if (file.path === INSTR) {
264
+ if (isNext(api)) return instrumentation(file, api)
265
+ // A backend's instrumentation.ts is the OTel preload that Sentry replaced.
266
+ return BEFORE_SENTRY.has(api.fingerprint(file.source)) ? manual(api, "generated before Sentry (2026-09-29)") : undefined
267
+ }
268
+ if (file.path === MIGRATE_TS) return migrate(file, api)
269
+ if (file.path === "src/index.ts" && !isNext(api)) return index(file, api)
270
+ return undefined
271
+ }
@@ -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: () => import("@quatronic/sdk/next/db"), // 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
+ }