@quatronic/sdk 0.8.0-rc.9 → 0.8.0-test.1d67463
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/dist/chunk-5RAO3LPF.js +116 -0
- package/dist/chunk-5RAO3LPF.js.map +1 -0
- package/dist/{chunk-G7VPNC6M.js → chunk-IFESUTF2.js} +21 -100
- package/dist/chunk-IFESUTF2.js.map +1 -0
- package/dist/{chunk-2AYDFLKR.js → chunk-NMJOF3ZM.js} +6 -104
- package/dist/chunk-NMJOF3ZM.js.map +1 -0
- package/dist/chunk-P7HNHLW7.js +65 -0
- package/dist/chunk-P7HNHLW7.js.map +1 -0
- package/dist/chunk-POZI4OKJ.js +20 -0
- package/dist/chunk-POZI4OKJ.js.map +1 -0
- package/dist/chunk-TPBRMW5N.js +197 -0
- package/dist/chunk-TPBRMW5N.js.map +1 -0
- package/dist/chunk-YFZB5EW6.js +107 -0
- package/dist/chunk-YFZB5EW6.js.map +1 -0
- package/dist/cli/legacy/qdc-sourcemaps.js +16 -6
- package/dist/cli/skills-postinstall.js +4 -3
- package/dist/cli/skills.js +4 -3
- package/dist/cli/sourcemaps.js +16 -6
- package/dist/integrations/index.d.ts +3 -75
- package/dist/integrations/index.js +6 -4
- package/dist/mail/index.d.ts +9 -0
- package/dist/mail/index.js +26 -0
- package/dist/mail/index.js.map +1 -0
- package/dist/next/auth/index.js +2 -152
- package/dist/next/auth/index.js.map +1 -1
- package/dist/next/boot/index.d.ts +39 -0
- package/dist/next/boot/index.js +22 -0
- package/dist/next/boot/index.js.map +1 -0
- package/dist/next/db/index.d.ts +27 -1
- package/dist/next/db/index.js +45 -3
- package/dist/next/db/index.js.map +1 -1
- package/dist/next/global-error/index.d.ts +9 -0
- package/dist/next/global-error/index.js +17 -0
- package/dist/next/global-error/index.js.map +1 -0
- package/dist/next/integrations/index.d.ts +2 -1
- package/dist/next/integrations/index.js +6 -4
- package/dist/next/platform/index.d.ts +19 -0
- package/dist/next/platform/index.js +44 -0
- package/dist/next/platform/index.js.map +1 -0
- package/dist/next/security/index.d.ts +23 -1
- package/dist/next/security/index.js +40 -57
- package/dist/next/security/index.js.map +1 -1
- package/dist/next/security/testing.js +10 -1
- package/dist/next/security/testing.js.map +1 -1
- package/dist/next/sentry/client.js +2 -1
- package/dist/next/sentry/client.js.map +1 -1
- package/dist/next/sentry/index.d.ts +1 -0
- package/dist/next/sentry/index.js +5 -1
- package/dist/next/sentry/index.js.map +1 -1
- package/dist/next/sentry/register.js +6 -13
- package/dist/next/sentry/register.js.map +1 -1
- package/dist/node/boot/index.d.ts +9 -0
- package/dist/node/boot/index.js +13 -0
- package/dist/node/boot/index.js.map +1 -0
- package/dist/node/integrations/index.d.ts +2 -1
- package/dist/node/integrations/index.js +6 -4
- package/dist/node/sentry/index.d.ts +3 -0
- package/dist/node/sentry/index.js +7 -0
- package/dist/node/sentry/index.js.map +1 -0
- package/dist/node/sentry/register.js +2 -1
- package/dist/node/sentry/register.js.map +1 -1
- package/dist/node-YQDRNIYH.js +33 -0
- package/dist/node-YQDRNIYH.js.map +1 -0
- package/dist/types-Cl7g4ego.d.ts +80 -0
- package/migrations/bootstrap-qore-env/codemod.mjs +77 -0
- package/migrations/bootstrap-qore-env/instructions.md +28 -0
- package/migrations/bootstrap-qore-env/meta.json +7 -0
- package/migrations/global-error/codemod.mjs +28 -0
- package/migrations/global-error/instructions.md +26 -0
- package/migrations/global-error/meta.json +7 -0
- package/migrations/local-db-port/codemod.mjs +61 -0
- package/migrations/local-db-port/instructions.md +45 -0
- package/migrations/local-db-port/meta.json +7 -0
- package/migrations/mail-reexport/codemod.mjs +64 -0
- package/migrations/mail-reexport/instructions.md +27 -0
- package/migrations/mail-reexport/meta.json +7 -0
- package/migrations/no-raw-fetch/meta.json +1 -1
- package/migrations/platform-routes/codemod.mjs +45 -0
- package/migrations/platform-routes/instructions.md +30 -0
- package/migrations/platform-routes/meta.json +7 -0
- package/migrations/qore-boot/codemod.mjs +271 -0
- package/migrations/qore-boot/instructions.md +74 -0
- package/migrations/qore-boot/meta.json +7 -0
- package/migrations/qore-proxy/codemod.mjs +88 -0
- package/migrations/qore-proxy/instructions.md +56 -0
- package/migrations/qore-proxy/meta.json +7 -0
- package/migrations/run.mjs +334 -0
- package/migrations/sourcemaps-finalize/codemod.mjs +63 -0
- package/migrations/sourcemaps-finalize/instructions.md +56 -0
- package/migrations/sourcemaps-finalize/meta.json +7 -0
- package/package.json +27 -2
- package/skills/catalog.json +1 -0
- package/skills/qore-add-env-key/SKILL.md +57 -0
- package/skills/qore-add-integration/SKILL.next.md +13 -7
- package/skills/qore-add-integration/SKILL.node.md +13 -7
- package/skills/qore-author-skill/SKILL.md +1 -0
- package/workspace-requirements.json +4 -0
- package/dist/chunk-2AYDFLKR.js.map +0 -1
- package/dist/chunk-BJN7YE63.js +0 -46
- package/dist/chunk-BJN7YE63.js.map +0 -1
- package/dist/chunk-G7VPNC6M.js.map +0 -1
|
@@ -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,334 @@
|
|
|
1
|
+
// Runs the SDK's code migrations against an app checkout and reports, per
|
|
2
|
+
// file, what happened. The portal's upgrade bot calls it after bumping the
|
|
3
|
+
// SDK and puts the report in the pull request; a person can call it too:
|
|
4
|
+
//
|
|
5
|
+
// node node_modules/@quatronic/sdk/migrations/run.mjs --app . --from 0.6.0
|
|
6
|
+
//
|
|
7
|
+
// A migration is a folder next to this file (see the sdk-code-migration
|
|
8
|
+
// skill). Its codemod.mjs exports a `transformer(file, api)` that returns the
|
|
9
|
+
// new source, `undefined` to leave the file alone, or `null` to delete it, and
|
|
10
|
+
// optionally a `create(api)` that returns files to add. Every migration fails
|
|
11
|
+
// closed per file: it rewrites a file it fully recognises or leaves it
|
|
12
|
+
// byte-identical and says why through `api.report`.
|
|
13
|
+
//
|
|
14
|
+
// Imports nothing but node builtins. jscodeshift comes from the caller
|
|
15
|
+
// (`--jscodeshift <dir it is installed in>`), and only a migration whose
|
|
16
|
+
// codemod parses code needs it; `parser = "text"` codemods get the raw text.
|
|
17
|
+
import { createHash } from "node:crypto"
|
|
18
|
+
import { existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, rmSync, writeFileSync } from "node:fs"
|
|
19
|
+
import { createRequire } from "node:module"
|
|
20
|
+
import { dirname, join, resolve } from "node:path"
|
|
21
|
+
import { fileURLToPath, pathToFileURL } from "node:url"
|
|
22
|
+
|
|
23
|
+
const HERE = dirname(fileURLToPath(import.meta.url))
|
|
24
|
+
const DEFAULT_TARGETS = ["src/**/*.{ts,tsx,js,jsx,mjs,cjs}"]
|
|
25
|
+
const SKIP_DIRS = new Set(["node_modules", ".git", ".next", "dist", "build", "coverage", ".turbo"])
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @typedef {"migrated" | "removed" | "added" | "manual" | "kept"} Status
|
|
29
|
+
* @typedef {{ status: "manual" | "kept", reason: string }} Note
|
|
30
|
+
* @typedef {{ path: string, status: Status, reason?: string }} FileResult
|
|
31
|
+
* @typedef {{ id: string, files: FileResult[] }} MigrationResult
|
|
32
|
+
* @typedef {{
|
|
33
|
+
* id: string,
|
|
34
|
+
* rule: string | null,
|
|
35
|
+
* introducedIn: string,
|
|
36
|
+
* testOnly?: boolean,
|
|
37
|
+
* targets?: string[],
|
|
38
|
+
* order?: number,
|
|
39
|
+
* }} Meta
|
|
40
|
+
* @typedef {{ meta: Meta, dir: string }} Migration
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* What a historical template rendering is compared on: line endings, trailing
|
|
45
|
+
* whitespace, trailing semicolons and blank-line runs are what a formatter
|
|
46
|
+
* changes without changing the code. Used by the tier-1 tables, so a file a
|
|
47
|
+
* team only reformatted still counts as untouched.
|
|
48
|
+
*
|
|
49
|
+
* @param {string} source
|
|
50
|
+
*/
|
|
51
|
+
export function normalize(source) {
|
|
52
|
+
return source
|
|
53
|
+
.replace(/\r\n?/g, "\n")
|
|
54
|
+
.split("\n")
|
|
55
|
+
.map((l) => l.replace(/\s+$/, "").replace(/;+$/, ""))
|
|
56
|
+
.join("\n")
|
|
57
|
+
.replace(/\n{3,}/g, "\n\n")
|
|
58
|
+
.trim()
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* A parsing codemod's output in the file's own style: recast prints the lines
|
|
63
|
+
* it creates with the platform's line ending and a semicolon. The file's line
|
|
64
|
+
* ending wins, and in a file with no semicolon-terminated line the new lines
|
|
65
|
+
* lose theirs, so the formatter has nothing to do.
|
|
66
|
+
*
|
|
67
|
+
* @param {string} source @param {string} out
|
|
68
|
+
*/
|
|
69
|
+
export function keepStyle(source, out) {
|
|
70
|
+
const eol = source.includes("\r\n") ? "\r\n" : "\n"
|
|
71
|
+
const lines = out.split(/\r?\n/)
|
|
72
|
+
const had = source.split(/\r?\n/)
|
|
73
|
+
if (!had.some((l) => /;\s*$/.test(l))) {
|
|
74
|
+
const old = new Set(had)
|
|
75
|
+
for (let i = 0; i < lines.length; i++) {
|
|
76
|
+
const l = lines[i] ?? ""
|
|
77
|
+
if (!old.has(l)) lines[i] = l.replace(/;(\s*)$/, "$1")
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return lines.join(eol)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** sha256 of the normalized source, first 16 hex characters. */
|
|
84
|
+
export function fingerprint(/** @type {string} */ source) {
|
|
85
|
+
return createHash("sha256").update(normalize(source)).digest("hex").slice(0, 16)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** @param {string} v */
|
|
89
|
+
function semver(v) {
|
|
90
|
+
return v.split(".").map((n) => Number.parseInt(n, 10) || 0)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** @param {string} a @param {string} b */
|
|
94
|
+
export function compareVersions(a, b) {
|
|
95
|
+
const x = semver(a)
|
|
96
|
+
const y = semver(b)
|
|
97
|
+
for (let i = 0; i < 3; i++) {
|
|
98
|
+
const d = (x[i] ?? 0) - (y[i] ?? 0)
|
|
99
|
+
if (d !== 0) return d
|
|
100
|
+
}
|
|
101
|
+
return 0
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* A glob as a RegExp over `/`-separated relative paths: `**` spans
|
|
106
|
+
* directories, `*` and `?` stay inside one, `{a,b}` is an alternation.
|
|
107
|
+
*
|
|
108
|
+
* @param {string} glob
|
|
109
|
+
*/
|
|
110
|
+
export function globToRegExp(glob) {
|
|
111
|
+
let re = ""
|
|
112
|
+
for (let i = 0; i < glob.length; i++) {
|
|
113
|
+
const c = glob[i] ?? ""
|
|
114
|
+
if (c === "*" && glob[i + 1] === "*") {
|
|
115
|
+
i++
|
|
116
|
+
if (glob[i + 1] === "/") {
|
|
117
|
+
i++
|
|
118
|
+
re += "(?:.*/)?"
|
|
119
|
+
} else re += ".*"
|
|
120
|
+
} else if (c === "*") re += "[^/]*"
|
|
121
|
+
else if (c === "?") re += "[^/]"
|
|
122
|
+
else if (c === "{") {
|
|
123
|
+
const end = glob.indexOf("}", i)
|
|
124
|
+
re += `(?:${glob
|
|
125
|
+
.slice(i + 1, end)
|
|
126
|
+
.split(",")
|
|
127
|
+
.map((s) => s.replace(/[.+^$()|[\]\\]/g, "\\$&"))
|
|
128
|
+
.join("|")})`
|
|
129
|
+
i = end
|
|
130
|
+
} else re += c.replace(/[.+^$()|[\]\\]/g, "\\$&")
|
|
131
|
+
}
|
|
132
|
+
return new RegExp(`^${re}$`)
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** @param {string} root @returns {string[]} relative, `/`-separated */
|
|
136
|
+
function walk(root, rel = "") {
|
|
137
|
+
/** @type {string[]} */
|
|
138
|
+
const out = []
|
|
139
|
+
for (const e of readdirSync(join(root, rel), { withFileTypes: true })) {
|
|
140
|
+
const path = rel ? `${rel}/${e.name}` : e.name
|
|
141
|
+
if (e.isDirectory()) {
|
|
142
|
+
if (!SKIP_DIRS.has(e.name)) out.push(...walk(root, path))
|
|
143
|
+
} else if (e.isFile()) out.push(path)
|
|
144
|
+
}
|
|
145
|
+
return out.sort()
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** @param {string} dir */
|
|
149
|
+
export function readMeta(dir) {
|
|
150
|
+
return /** @type {Meta} */ (JSON.parse(readFileSync(join(dir, "meta.json"), "utf8")))
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* The migrations a bump from `from` (exclusive) to `to` (inclusive) carries,
|
|
155
|
+
* in the order they must run: `order`, then the version that introduced
|
|
156
|
+
* them, then id. `only` picks by id regardless of version.
|
|
157
|
+
*
|
|
158
|
+
* @param {{ dir?: string, from?: string, to?: string, only?: string[], includeTestOnly?: boolean }} opts
|
|
159
|
+
* @returns {Migration[]}
|
|
160
|
+
*/
|
|
161
|
+
export function selectMigrations(opts = {}) {
|
|
162
|
+
const dir = opts.dir ?? HERE
|
|
163
|
+
const all = readdirSync(dir, { withFileTypes: true })
|
|
164
|
+
.filter((e) => e.isDirectory())
|
|
165
|
+
.map((e) => ({ meta: readMeta(join(dir, e.name)), dir: join(dir, e.name) }))
|
|
166
|
+
const picked = all.filter(({ meta }) => {
|
|
167
|
+
if (opts.only) return opts.only.includes(meta.id)
|
|
168
|
+
if (meta.testOnly && !opts.includeTestOnly) return false
|
|
169
|
+
if (opts.from && compareVersions(meta.introducedIn, opts.from) <= 0) return false
|
|
170
|
+
if (opts.to && compareVersions(meta.introducedIn, opts.to) > 0) return false
|
|
171
|
+
return true
|
|
172
|
+
})
|
|
173
|
+
return picked.sort(
|
|
174
|
+
(a, b) =>
|
|
175
|
+
(a.meta.order ?? 0) - (b.meta.order ?? 0) ||
|
|
176
|
+
compareVersions(a.meta.introducedIn, b.meta.introducedIn) ||
|
|
177
|
+
a.meta.id.localeCompare(b.meta.id),
|
|
178
|
+
)
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Runs `migrations` in order on the checkout at `root`, writing the results
|
|
183
|
+
* in place. One migration sees what the ones before it wrote.
|
|
184
|
+
*
|
|
185
|
+
* @param {{ root: string, migrations: Migration[], jscodeshift?: any }} opts
|
|
186
|
+
* @returns {Promise<MigrationResult[]>}
|
|
187
|
+
*/
|
|
188
|
+
export async function runMigrations({ root, migrations, jscodeshift }) {
|
|
189
|
+
/** @type {MigrationResult[]} */
|
|
190
|
+
const results = []
|
|
191
|
+
for (const m of migrations) {
|
|
192
|
+
const mod = existsSync(join(m.dir, "codemod.mjs"))
|
|
193
|
+
? await import(pathToFileURL(join(m.dir, "codemod.mjs")).href)
|
|
194
|
+
: null
|
|
195
|
+
/** @type {FileResult[]} */
|
|
196
|
+
const files = []
|
|
197
|
+
results.push({ id: m.meta.id, files })
|
|
198
|
+
if (!mod) continue
|
|
199
|
+
|
|
200
|
+
const parser = mod.parser ?? "tsx"
|
|
201
|
+
if (parser !== "text" && !jscodeshift) {
|
|
202
|
+
throw new Error(`migration ${m.meta.id} parses ${parser} and needs jscodeshift (--jscodeshift <dir>)`)
|
|
203
|
+
}
|
|
204
|
+
const j = parser === "text" ? undefined : jscodeshift.withParser(parser)
|
|
205
|
+
const abs = (/** @type {string} */ p) => join(root, ...p.split("/"))
|
|
206
|
+
const base = {
|
|
207
|
+
jscodeshift: j,
|
|
208
|
+
j,
|
|
209
|
+
stats: () => {},
|
|
210
|
+
fingerprint,
|
|
211
|
+
normalize,
|
|
212
|
+
exists: (/** @type {string} */ p) => existsSync(abs(p)),
|
|
213
|
+
read: (/** @type {string} */ p) => (existsSync(abs(p)) ? readFileSync(abs(p), "utf8") : null),
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
const targets = (m.meta.targets ?? DEFAULT_TARGETS).map(globToRegExp)
|
|
217
|
+
const paths = typeof mod.default === "function" ? walk(root).filter((p) => targets.some((t) => t.test(p))) : []
|
|
218
|
+
for (const path of paths) {
|
|
219
|
+
const source = readFileSync(abs(path), "utf8")
|
|
220
|
+
/** @type {Note | null} */
|
|
221
|
+
let note = null
|
|
222
|
+
const api = { ...base, report: (/** @type {Note} */ n) => (note = n) }
|
|
223
|
+
let out
|
|
224
|
+
try {
|
|
225
|
+
out = mod.default({ path, source }, api)
|
|
226
|
+
if (parser !== "text" && typeof out === "string") out = keepStyle(source, out)
|
|
227
|
+
} catch (err) {
|
|
228
|
+
files.push({ path, status: "manual", reason: `the codemod failed: ${err instanceof Error ? err.message : String(err)}` })
|
|
229
|
+
continue
|
|
230
|
+
}
|
|
231
|
+
if (out === null) {
|
|
232
|
+
rmSync(abs(path))
|
|
233
|
+
files.push({ path, status: "removed" })
|
|
234
|
+
} else if (typeof out === "string" && out !== source) {
|
|
235
|
+
writeFileSync(abs(path), out)
|
|
236
|
+
files.push({ path, status: "migrated" })
|
|
237
|
+
} else if (note) {
|
|
238
|
+
const n = /** @type {Note} */ (note)
|
|
239
|
+
files.push({ path, status: n.status, reason: n.reason })
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
if (typeof mod.create === "function") {
|
|
244
|
+
/** @type {Note[]} */
|
|
245
|
+
const notes = []
|
|
246
|
+
const api = { ...base, report: (/** @type {Note & { path: string }} */ n) => notes.push(n) }
|
|
247
|
+
for (const f of mod.create(api) ?? []) {
|
|
248
|
+
if (existsSync(abs(f.path))) continue
|
|
249
|
+
mkdirSync(dirname(abs(f.path)), { recursive: true })
|
|
250
|
+
writeFileSync(abs(f.path), f.source)
|
|
251
|
+
files.push({ path: f.path, status: "added" })
|
|
252
|
+
}
|
|
253
|
+
for (const n of /** @type {(Note & { path: string })[]} */ (notes)) {
|
|
254
|
+
files.push({ path: n.path, status: n.status, reason: n.reason })
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
return results
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
const HEADINGS = /** @type {const} */ ([
|
|
262
|
+
["manual", "Needs a manual change"],
|
|
263
|
+
["kept", "Left as is (changed by the team)"],
|
|
264
|
+
["migrated", "Migrated"],
|
|
265
|
+
["added", "Added"],
|
|
266
|
+
["removed", "Removed"],
|
|
267
|
+
])
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* The report as Markdown for a pull request body. Manual work comes first:
|
|
271
|
+
* that is what a reviewer has to act on.
|
|
272
|
+
*
|
|
273
|
+
* @param {MigrationResult[]} results
|
|
274
|
+
*/
|
|
275
|
+
export function reportMarkdown(results) {
|
|
276
|
+
if (results.length === 0) return ""
|
|
277
|
+
const lines = ["## Code migrations", ""]
|
|
278
|
+
lines.push(`Ran: ${results.map((r) => `\`${r.id}\``).join(", ")}.`, "")
|
|
279
|
+
const all = results.flatMap((r) => r.files.map((f) => ({ ...f, id: r.id })))
|
|
280
|
+
if (all.length === 0) lines.push("Nothing in this app needed a change.")
|
|
281
|
+
for (const [status, heading] of HEADINGS) {
|
|
282
|
+
const rows = all.filter((f) => f.status === status)
|
|
283
|
+
if (rows.length === 0) continue
|
|
284
|
+
lines.push(`### ${heading}`, "")
|
|
285
|
+
for (const f of rows) lines.push(`- \`${f.path}\` (${f.id})${f.reason ? `: ${f.reason}` : ""}`)
|
|
286
|
+
lines.push("")
|
|
287
|
+
}
|
|
288
|
+
return `${lines.join("\n").trimEnd()}\n`
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/** @param {string | undefined} dir */
|
|
292
|
+
function loadJscodeshift(dir) {
|
|
293
|
+
// createRequire takes an absolute path only; `--jscodeshift deps` is relative.
|
|
294
|
+
const req = createRequire(dir ? join(resolve(dir), "noop.js") : import.meta.url)
|
|
295
|
+
try {
|
|
296
|
+
return req("jscodeshift")
|
|
297
|
+
} catch {
|
|
298
|
+
return undefined
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/** @param {string} argv1 */
|
|
303
|
+
function isEntry(argv1) {
|
|
304
|
+
try {
|
|
305
|
+
return realpathSync(argv1) === realpathSync(fileURLToPath(import.meta.url))
|
|
306
|
+
} catch {
|
|
307
|
+
return false
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
// CLI: node run.mjs --app <dir> [--from <version>] [--to <version>]
|
|
312
|
+
// [--only id,id] [--test-only] [--jscodeshift <dir>] [--report <file>]
|
|
313
|
+
// Compared as real paths: a pnpm app reaches this file through a node_modules
|
|
314
|
+
// symlink, and the documented `node node_modules/@quatronic/sdk/...` would
|
|
315
|
+
// otherwise skip the CLI and exit 0 having done nothing.
|
|
316
|
+
if (process.argv[1] && isEntry(process.argv[1])) {
|
|
317
|
+
const arg = (/** @type {string} */ name) => {
|
|
318
|
+
const i = process.argv.indexOf(name)
|
|
319
|
+
return i > 0 ? process.argv[i + 1] : undefined
|
|
320
|
+
}
|
|
321
|
+
const app = arg("--app") ?? "."
|
|
322
|
+
const to = arg("--to") ?? JSON.parse(readFileSync(join(HERE, "../package.json"), "utf8")).version
|
|
323
|
+
const only = arg("--only")?.split(",")
|
|
324
|
+
const migrations = selectMigrations({
|
|
325
|
+
from: arg("--from"),
|
|
326
|
+
to,
|
|
327
|
+
...(only ? { only } : {}),
|
|
328
|
+
includeTestOnly: process.argv.includes("--test-only"),
|
|
329
|
+
})
|
|
330
|
+
const results = await runMigrations({ root: app, migrations, jscodeshift: loadJscodeshift(arg("--jscodeshift")) })
|
|
331
|
+
const report = arg("--report")
|
|
332
|
+
if (report) writeFileSync(report, `${JSON.stringify(results, null, 2)}\n`)
|
|
333
|
+
process.stdout.write(reportMarkdown(results))
|
|
334
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// Code migration sourcemaps-finalize. The Dockerfile's source-map handling
|
|
2
|
+
// becomes one SDK step:
|
|
3
|
+
//
|
|
4
|
+
// RUN pnpm exec qore-sourcemaps finalize <dir>
|
|
5
|
+
//
|
|
6
|
+
// `finalize` is the build's platform step: a new one ships inside it with an
|
|
7
|
+
// SDK release instead of as a Dockerfile edit. It never fails the build.
|
|
8
|
+
//
|
|
9
|
+
// Two shapes migrate, both as line edits, so a Dockerfile the team changed
|
|
10
|
+
// elsewhere migrates too:
|
|
11
|
+
//
|
|
12
|
+
// - the pair "upload, then delete the maps" becomes the one step. The legacy
|
|
13
|
+
// `qdc-sourcemaps` name is replaced as well: it uploads nothing since the
|
|
14
|
+
// upload moved behind the portal.
|
|
15
|
+
// - a Dockerfile without any source-map step (Next apps that uploaded from
|
|
16
|
+
// inside `next build` until 2026-09-29, backends that never uploaded) gets
|
|
17
|
+
// the step after its one `RUN pnpm build` in the build stage, with the two
|
|
18
|
+
// build arguments it reads.
|
|
19
|
+
export const parser = "text"
|
|
20
|
+
|
|
21
|
+
const PAIR = /^RUN pnpm exec (?:qore|qdc)-sourcemaps upload (\S+) \|\| true\r?\nRUN find (\S+) -name '\*\.map' -delete[ \t]*$/m
|
|
22
|
+
const BUILD = /^RUN pnpm (?:run )?build[ \t]*$/gm
|
|
23
|
+
const SEE = "see the sourcemaps-finalize instructions"
|
|
24
|
+
|
|
25
|
+
const isNext = (api) => ["next.config.mjs", "next.config.ts", "next.config.js"].some((p) => api.exists(p))
|
|
26
|
+
|
|
27
|
+
/** Adds the step after the build stage's single `RUN pnpm build`, or null when that line is not unambiguous. */
|
|
28
|
+
function addStep(source, dir) {
|
|
29
|
+
const froms = [...source.matchAll(/^FROM /gm)]
|
|
30
|
+
if (froms.length === 0) return null
|
|
31
|
+
const stage = froms.length > 1 ? source.slice(0, froms[1].index) : source
|
|
32
|
+
const builds = [...stage.matchAll(BUILD)]
|
|
33
|
+
if (builds.length !== 1) return null
|
|
34
|
+
const at = builds[0].index
|
|
35
|
+
const line = builds[0][0]
|
|
36
|
+
const before = /^ARG QORE_BUILD_UPLOAD_URL\b/m.test(stage) ? "" : `ARG QORE_BUILD_UPLOAD_URL=""\n`
|
|
37
|
+
const after = /^ARG QORE_BUILD_UPLOAD_TOKEN\b/m.test(stage) ? "" : `ARG QORE_BUILD_UPLOAD_TOKEN=""\n`
|
|
38
|
+
const step =
|
|
39
|
+
`${before}${line}\n` +
|
|
40
|
+
`# Platform build step: hands the source maps to Qore, then strips them from\n` +
|
|
41
|
+
`# the image. Never fails the build.\n` +
|
|
42
|
+
`${after}RUN pnpm exec qore-sourcemaps finalize ${dir}`
|
|
43
|
+
return source.slice(0, at) + step + source.slice(at + line.length)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export default function transformer(file, api) {
|
|
47
|
+
if (file.path !== "Dockerfile") return undefined
|
|
48
|
+
if (/qore-sourcemaps finalize /.test(file.source)) return undefined
|
|
49
|
+
const m = PAIR.exec(file.source)
|
|
50
|
+
if (m && m[1] === m[2]) return file.source.replace(PAIR, `RUN pnpm exec qore-sourcemaps finalize ${m[1]}`)
|
|
51
|
+
if (file.source.includes("sentry-cli")) {
|
|
52
|
+
return void api.report({
|
|
53
|
+
status: "manual",
|
|
54
|
+
reason: `uploads source maps with a Sentry token in the build; replace that step with qore-sourcemaps finalize, ${SEE}`,
|
|
55
|
+
})
|
|
56
|
+
}
|
|
57
|
+
if (/(?:qore|qdc)-sourcemaps/.test(file.source)) {
|
|
58
|
+
return void api.report({ status: "manual", reason: `changed by the team; replace the source-map lines with qore-sourcemaps finalize, ${SEE}` })
|
|
59
|
+
}
|
|
60
|
+
const added = addStep(file.source, isNext(api) ? ".next" : "dist")
|
|
61
|
+
if (added !== null) return added
|
|
62
|
+
return void api.report({ status: "manual", reason: `has no source-map step and no single \`RUN pnpm build\` to add it after, ${SEE}` })
|
|
63
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# sourcemaps-finalize: one platform step in the Dockerfile
|
|
2
|
+
|
|
3
|
+
The Dockerfile used to carry two source-map lines: hand the maps to Qore, then
|
|
4
|
+
delete them so the image does not ship your source. Both are now one SDK step,
|
|
5
|
+
so a new platform build step arrives with an SDK release instead of a
|
|
6
|
+
Dockerfile edit:
|
|
7
|
+
|
|
8
|
+
```dockerfile
|
|
9
|
+
RUN pnpm exec qore-sourcemaps finalize .next # dist for a backend
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
It never fails the build: a refused or failed upload is a warning.
|
|
13
|
+
|
|
14
|
+
The upgrade bot runs this for you:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
node node_modules/@quatronic/sdk/migrations/run.mjs --only sourcemaps-finalize
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
It replaces the pair
|
|
21
|
+
|
|
22
|
+
```dockerfile
|
|
23
|
+
RUN pnpm exec qore-sourcemaps upload .next || true # or qdc-sourcemaps
|
|
24
|
+
RUN find .next -name '*.map' -delete
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
wherever it is, even in a Dockerfile your team changed elsewhere. The old
|
|
28
|
+
`qdc-sourcemaps` name uploads nothing any more, so those apps get their source
|
|
29
|
+
maps back with this change.
|
|
30
|
+
|
|
31
|
+
A Dockerfile without any source-map step gets the step after its `RUN pnpm
|
|
32
|
+
build`, with the two build arguments it reads (see below). That covers Next apps
|
|
33
|
+
generated until 2026-09-29, which uploaded from inside `next build`, and
|
|
34
|
+
backends, which did not upload at all.
|
|
35
|
+
|
|
36
|
+
## By hand
|
|
37
|
+
|
|
38
|
+
The step needs the upload settings as build arguments. In the build stage, put
|
|
39
|
+
the URL before the build (the SDK's Next config keeps the maps only when it is
|
|
40
|
+
set) and the token after it:
|
|
41
|
+
|
|
42
|
+
```dockerfile
|
|
43
|
+
ARG NF_GIT_SHA=""
|
|
44
|
+
ENV SENTRY_RELEASE=$NF_GIT_SHA
|
|
45
|
+
ARG QORE_BUILD_UPLOAD_URL=""
|
|
46
|
+
RUN pnpm build
|
|
47
|
+
ARG QORE_BUILD_UPLOAD_TOKEN=""
|
|
48
|
+
RUN pnpm exec qore-sourcemaps finalize .next
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
A Dockerfile that runs `sentry-cli` itself (generated 2026-09-29 to 2026-10-12)
|
|
52
|
+
uploads with a Sentry token inside the build. Delete that `RUN` block and its
|
|
53
|
+
`SENTRY_AUTH_TOKEN`/`SENTRY_ORG`/`SENTRY_PROJECT`/`SENTRY_URL`/`SENTRY_REPO`
|
|
54
|
+
arguments, and use the lines above. So does a Dockerfile that builds with `npm run build`
|
|
55
|
+
(backends generated before 2026-08-21): switch it to pnpm first, as the template
|
|
56
|
+
did.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quatronic/sdk",
|
|
3
|
-
"version": "0.8.0-
|
|
3
|
+
"version": "0.8.0-test.1d67463",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"private": false,
|
|
6
6
|
"publishConfig": {
|
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
"migrations",
|
|
13
13
|
"semgrep",
|
|
14
14
|
"skills",
|
|
15
|
-
"postinstall.mjs"
|
|
15
|
+
"postinstall.mjs",
|
|
16
|
+
"workspace-requirements.json"
|
|
16
17
|
],
|
|
17
18
|
"bin": {
|
|
18
19
|
"qore-skills": "./dist/cli/skills.js",
|
|
@@ -47,6 +48,10 @@
|
|
|
47
48
|
"types": "./dist/next/sentry/client.d.ts",
|
|
48
49
|
"import": "./dist/next/sentry/client.js"
|
|
49
50
|
},
|
|
51
|
+
"./node/sentry": {
|
|
52
|
+
"types": "./dist/node/sentry/index.d.ts",
|
|
53
|
+
"import": "./dist/node/sentry/index.js"
|
|
54
|
+
},
|
|
50
55
|
"./node/sentry/register": {
|
|
51
56
|
"types": "./dist/node/sentry/register.d.ts",
|
|
52
57
|
"import": "./dist/node/sentry/register.js"
|
|
@@ -122,6 +127,26 @@
|
|
|
122
127
|
"./next/db": {
|
|
123
128
|
"types": "./dist/next/db/index.d.ts",
|
|
124
129
|
"import": "./dist/next/db/index.js"
|
|
130
|
+
},
|
|
131
|
+
"./mail": {
|
|
132
|
+
"types": "./dist/mail/index.d.ts",
|
|
133
|
+
"import": "./dist/mail/index.js"
|
|
134
|
+
},
|
|
135
|
+
"./next/boot": {
|
|
136
|
+
"types": "./dist/next/boot/index.d.ts",
|
|
137
|
+
"import": "./dist/next/boot/index.js"
|
|
138
|
+
},
|
|
139
|
+
"./node/boot": {
|
|
140
|
+
"types": "./dist/node/boot/index.d.ts",
|
|
141
|
+
"import": "./dist/node/boot/index.js"
|
|
142
|
+
},
|
|
143
|
+
"./next/global-error": {
|
|
144
|
+
"types": "./dist/next/global-error/index.d.ts",
|
|
145
|
+
"import": "./dist/next/global-error/index.js"
|
|
146
|
+
},
|
|
147
|
+
"./next/platform": {
|
|
148
|
+
"types": "./dist/next/platform/index.d.ts",
|
|
149
|
+
"import": "./dist/next/platform/index.js"
|
|
125
150
|
}
|
|
126
151
|
},
|
|
127
152
|
"scripts": {
|
package/skills/catalog.json
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
{"name": "qore-add-api-route", "kind": "convenience", "requires": ["runtime=next"], "legacyNames": ["quatronic-add-api-route"]},
|
|
4
4
|
{"name": "qore-add-connection", "kind": "contract", "legacyNames": ["quatronic-add-connection"]},
|
|
5
5
|
{"name": "qore-add-db-table", "kind": "convenience", "requires": ["runtime=next", "db"], "legacyNames": ["quatronic-add-db-table"]},
|
|
6
|
+
{"name": "qore-add-env-key", "kind": "contract"},
|
|
6
7
|
{"name": "qore-add-feature", "kind": "convenience", "requires": ["runtime=next"], "legacyNames": ["quatronic-add-feature"]},
|
|
7
8
|
{"name": "qore-add-integration", "kind": "contract", "legacyNames": ["quatronic-add-integration"]},
|
|
8
9
|
{"name": "qore-add-page", "kind": "convenience", "requires": ["runtime=next"], "legacyNames": ["quatronic-add-page"]},
|