@quatronic/sdk 0.7.0-test.bdf2e31 → 0.7.0-test.d0401ae
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-TOBGX4CZ.js → chunk-5RAO3LPF.js} +9 -2
- package/dist/chunk-5RAO3LPF.js.map +1 -0
- package/dist/{chunk-F3NHTHFO.js → chunk-NMJOF3ZM.js} +2 -2
- package/dist/cli/skills-postinstall.js +4 -3
- package/dist/cli/skills.js +4 -3
- package/dist/integrations/index.d.ts +2 -2
- package/dist/integrations/index.js +2 -2
- package/dist/next/boot/index.d.ts +1 -1
- package/dist/next/boot/index.js +1 -1
- package/dist/next/integrations/index.d.ts +1 -1
- package/dist/next/integrations/index.js +2 -2
- package/dist/next/security/index.js +3 -3
- package/dist/next/security/testing.js +10 -1
- package/dist/next/security/testing.js.map +1 -1
- package/dist/node/boot/index.d.ts +1 -1
- package/dist/node/boot/index.js +1 -1
- package/dist/node/integrations/index.d.ts +1 -1
- package/dist/node/integrations/index.js +2 -2
- package/dist/{node-Z7ERWJDZ.js → node-HH3ZZD2R.js} +2 -2
- package/dist/{types-CAwj03sM.d.ts → types-Cl7g4ego.d.ts} +7 -2
- package/migrations/qore-boot/codemod.mjs +3 -1
- package/migrations/run.mjs +14 -2
- package/package.json +1 -1
- 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/dist/chunk-TOBGX4CZ.js.map +0 -1
- /package/dist/{chunk-F3NHTHFO.js.map → chunk-NMJOF3ZM.js.map} +0 -0
- /package/dist/{node-Z7ERWJDZ.js.map → node-HH3ZZD2R.js.map} +0 -0
|
@@ -14,7 +14,14 @@ var AUTH_ENV_FIELDS = {
|
|
|
14
14
|
basic: ["username", "password"],
|
|
15
15
|
oauth2_client_credentials: ["tokenUrl", "clientId", "clientSecret", "scope", "audience"]
|
|
16
16
|
};
|
|
17
|
-
var AUTH_SECRET_FIELDS = [
|
|
17
|
+
var AUTH_SECRET_FIELDS = [
|
|
18
|
+
"apiKey",
|
|
19
|
+
"token",
|
|
20
|
+
"username",
|
|
21
|
+
"password",
|
|
22
|
+
"clientId",
|
|
23
|
+
"clientSecret"
|
|
24
|
+
];
|
|
18
25
|
var RESERVED_KEY_PREFIX = "QORE_INTEGRATION_";
|
|
19
26
|
|
|
20
27
|
// src/integrations-core/env.ts
|
|
@@ -106,4 +113,4 @@ export {
|
|
|
106
113
|
loggingEnabled,
|
|
107
114
|
assertIntegrations
|
|
108
115
|
};
|
|
109
|
-
//# sourceMappingURL=chunk-
|
|
116
|
+
//# sourceMappingURL=chunk-5RAO3LPF.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/integrations-core/types.ts","../src/integrations-core/env.ts","../src/integrations-core/assertIntegrations.ts"],"sourcesContent":["/**\n * How an integration authenticates. Every field except `header` and\n * `credentialsIn` names an **env key** — the SDK reads the value from the\n * environment at call time, never from the declaration — so a declaration can\n * sit in source control and carry no secret.\n */\nexport type AuthKind =\n | \"none\"\n | \"api_key_header\"\n | \"bearer_static\"\n | \"basic\"\n | \"oauth2_client_credentials\"\n\n/** What the API speaks. Informational for the portal; the client sends bytes either way. */\nexport type Protocol = \"rest\" | \"odata\" | \"soap\" | \"graphql\"\n\n/** The name of an env var, e.g. `SAP_BASE_URL`. */\nexport type EnvKey = string\n\n/**\n * A reference to an env var. The short form is required; the object form can\n * be optional and carry a default the app falls back on when the key is unset.\n */\nexport type EnvRef =\n | EnvKey\n | { key: EnvKey; optional?: boolean; default?: string | number | boolean }\n\nexport type IntegrationAuth =\n | { kind: \"none\" }\n | { kind: \"api_key_header\"; header: string; apiKey: EnvKey }\n | { kind: \"bearer_static\"; token: EnvKey }\n | { kind: \"basic\"; username: EnvKey; password: EnvKey }\n | {\n kind: \"oauth2_client_credentials\"\n tokenUrl: EnvKey\n clientId: EnvKey\n clientSecret: EnvKey\n scope?: EnvKey\n audience?: EnvKey\n /** Where the client credentials go on the token request. Default `\"header\"`. */\n credentialsIn?: \"header\" | \"body\"\n }\n\nexport interface IntegrationDefinition {\n /** Human name shown in the portal, e.g. \"SAP S/4HANA Cloud\". */\n label: string\n protocol: Protocol\n /** Env key holding the base URL for this environment. */\n baseUrl: EnvKey\n auth: IntegrationAuth\n /** Further env the app reads for this integration, by logical name. */\n config?: Record<string, EnvRef>\n}\n\nexport type IntegrationMap = Record<string, IntegrationDefinition>\n\n/**\n * Identity function that pins the literal types of the map, so an alias typo\n * at a call site is a compile error (`keyof M`) rather than a runtime\n * `not_declared`. Same shape as `definePermissions` in `auth-core`.\n */\nexport function defineIntegrations<const M extends IntegrationMap>(map: M): M {\n return map\n}\n\n/**\n * Which fields of each auth kind name an env key. Shared with the manifest\n * extractor and the portal, which derive the required-env list from a\n * declaration without evaluating app code.\n */\nexport const AUTH_ENV_FIELDS: Record<AuthKind, readonly string[]> = {\n none: [],\n api_key_header: [\"apiKey\"],\n bearer_static: [\"token\"],\n basic: [\"username\", \"password\"],\n oauth2_client_credentials: [\"tokenUrl\", \"clientId\", \"clientSecret\", \"scope\", \"audience\"],\n}\n\n/**\n * Auth fields whose env value is a secret, so the portal locks it whatever\n * `env.ts` labels it. The identifier of a login counts with its secret:\n * `username` sits with `password` and `clientId` with `clientSecret`, because\n * that is where a person looks for them and they are replaced together.\n */\nexport const AUTH_SECRET_FIELDS = [\n \"apiKey\",\n \"token\",\n \"username\",\n \"password\",\n \"clientId\",\n \"clientSecret\",\n] as const\n\n/**\n * Env keys under this prefix belong to the platform\n * (`QORE_INTEGRATION_<ALIAS>_LOGGING` today). A declaration may not claim one.\n */\nexport const RESERVED_KEY_PREFIX = \"QORE_INTEGRATION_\"\n","import { normalizeAlias, type Env } from \"../connections-core/env\"\nimport {\n AUTH_ENV_FIELDS,\n RESERVED_KEY_PREFIX,\n type EnvRef,\n type IntegrationDefinition,\n} from \"./types\"\n\nexport type { Env }\n\nexport function refKey(ref: EnvRef): string {\n return typeof ref === \"string\" ? ref : ref.key\n}\n\nfunction refOptional(ref: EnvRef): boolean {\n return typeof ref !== \"string\" && (ref.optional === true || ref.default !== undefined)\n}\n\n/** The auth fields of `def` that are set, as env keys. */\nfunction authKeys(def: IntegrationDefinition): string[] {\n const auth = def.auth as unknown as Record<string, unknown>\n return AUTH_ENV_FIELDS[def.auth.kind]\n .map((field) => auth[field])\n .filter((key): key is string => typeof key === \"string\" && key !== \"\")\n}\n\n/**\n * Every env key the integration cannot run without: the base URL, every auth\n * field that is set, and every config ref that is neither optional nor\n * defaulted. Order is stable so an error message reads the same twice.\n */\nexport function requiredKeys(def: IntegrationDefinition): string[] {\n const keys = [def.baseUrl, ...authKeys(def)]\n for (const ref of Object.values(def.config ?? {})) {\n if (!refOptional(ref)) keys.push(refKey(ref))\n }\n return [...new Set(keys)]\n}\n\n/** Every env key the declaration names, required or not. */\nexport function allKeys(def: IntegrationDefinition): string[] {\n const keys = [def.baseUrl, ...authKeys(def)]\n for (const ref of Object.values(def.config ?? {})) keys.push(refKey(ref))\n return [...new Set(keys)]\n}\n\n/**\n * Read one ref from `env`, applying its default when the key is unset or\n * empty. A default comes back as declared (a number or boolean stays typed);\n * an env value is always a string.\n */\nexport function readRef(env: Env, ref: EnvRef): string | number | boolean | undefined {\n const value = env[refKey(ref)]\n if (value !== undefined && value !== \"\") return value\n return typeof ref === \"string\" ? undefined : ref.default\n}\n\n/** `QORE_INTEGRATION_<ALIAS>_LOGGING` — the one reserved key v1 reads. */\nexport function loggingKey(alias: string): string {\n return `${RESERVED_KEY_PREFIX}${normalizeAlias(alias)}_LOGGING`\n}\n\n/** Whether the per-call JSON log line is switched on for this alias (\"1\" or \"true\"). */\nexport function loggingEnabled(env: Env, alias: string): boolean {\n const value = env[loggingKey(alias)]\n return value === \"1\" || value?.toLowerCase() === \"true\"\n}\n","import { defaultEnv, type Env } from \"../connections-core/env\"\nimport { allKeys, requiredKeys } from \"./env\"\nimport { RESERVED_KEY_PREFIX, type IntegrationMap } from \"./types\"\n\nconst ENV_KEY_RE = /^[A-Z][A-Z0-9_]*$/\n\nexport interface IntegrationProblem {\n alias: string\n key: string\n /** `missing_env`: a required key is unset or empty. `reserved_key`: the declaration claims a key it may not. */\n code: \"missing_env\" | \"reserved_key\"\n message: string\n}\n\n/**\n * Report, at app startup, what is wrong with the declared integrations: a\n * required env key that is unset, or a key the declaration may not claim.\n * **It never throws.** Integrations are a visibility tool: an API key that is\n * not set (an obsolete integration, a vendor not contracted in this\n * environment) must cost the calls to that one integration — they fail with\n * `missing_env` — never the boot of the whole app. Each problem is logged as\n * one warning and returned, so a caller may act on them if it chooses.\n */\nexport function assertIntegrations(\n map: IntegrationMap,\n opts: { env?: Env; warn?: (message: string) => void } = {},\n): IntegrationProblem[] {\n const env = opts.env ?? defaultEnv()\n const warn = opts.warn ?? ((message: string) => console.warn(message))\n const problems: IntegrationProblem[] = []\n\n for (const [alias, def] of Object.entries(map)) {\n for (const key of allKeys(def)) {\n let why: string | undefined\n if (key.startsWith(RESERVED_KEY_PREFIX)) {\n why = `${RESERVED_KEY_PREFIX}* keys are reserved by the platform`\n } else if (key.startsWith(\"CONN_\")) {\n why = \"CONN_* keys belong to module connections, not integrations\"\n } else if (!ENV_KEY_RE.test(key)) {\n why = \"an env key is uppercase letters, digits and underscores\"\n }\n if (why) {\n problems.push({\n alias,\n key,\n code: \"reserved_key\",\n message: `Integration \"${alias}\" declares env key \"${key}\": ${why}`,\n })\n }\n }\n for (const key of requiredKeys(def)) {\n const value = env[key]\n if (value === undefined || value === \"\") {\n problems.push({\n alias,\n key,\n code: \"missing_env\",\n message: `Integration \"${alias}\" is missing env key \"${key}\"; calls to it will fail until it is set`,\n })\n }\n }\n }\n\n for (const p of problems) warn(`[integrations] ${p.message}`)\n return problems\n}\n"],"mappings":";;;;;;AA6DO,SAAS,mBAAmD,KAAW;AAC5E,SAAO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A,QAC5D,CAAC;AAAA,MACH;AAAA,IACF;AAAA,EACF;AAEA,aAAW,KAAK,SAAU,MAAK,kBAAkB,EAAE,OAAO,EAAE;AAC5D,SAAO;AACT;","names":[]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
loggingEnabled,
|
|
3
3
|
readRef
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-5RAO3LPF.js";
|
|
5
5
|
import {
|
|
6
6
|
defaultEnv
|
|
7
7
|
} from "./chunk-5XMTUPIY.js";
|
|
@@ -346,4 +346,4 @@ export {
|
|
|
346
346
|
IntegrationError,
|
|
347
347
|
createIntegrationClient
|
|
348
348
|
};
|
|
349
|
-
//# sourceMappingURL=chunk-
|
|
349
|
+
//# sourceMappingURL=chunk-NMJOF3ZM.js.map
|
|
@@ -163,9 +163,10 @@ extension file.
|
|
|
163
163
|
|
|
164
164
|
## Contract skills
|
|
165
165
|
|
|
166
|
-
\`qore-add-
|
|
167
|
-
\`qore-observability\` and \`qore-use-database\`
|
|
168
|
-
the
|
|
166
|
+
\`qore-add-env-key\`, \`qore-add-integration\`, \`qore-add-connection\`,
|
|
167
|
+
\`qore-use-permissions\`, \`qore-observability\` and \`qore-use-database\`
|
|
168
|
+
produce code the portal reads: the Secrets tab, the Integrations tab,
|
|
169
|
+
connections, roles, Monitoring, the local database. An
|
|
169
170
|
extension may add to them but not relax them, and turning one off does not turn
|
|
170
171
|
off the SDK's lint rules that check the same things.
|
|
171
172
|
|
package/dist/cli/skills.js
CHANGED
|
@@ -162,9 +162,10 @@ extension file.
|
|
|
162
162
|
|
|
163
163
|
## Contract skills
|
|
164
164
|
|
|
165
|
-
\`qore-add-
|
|
166
|
-
\`qore-observability\` and \`qore-use-database\`
|
|
167
|
-
the
|
|
165
|
+
\`qore-add-env-key\`, \`qore-add-integration\`, \`qore-add-connection\`,
|
|
166
|
+
\`qore-use-permissions\`, \`qore-observability\` and \`qore-use-database\`
|
|
167
|
+
produce code the portal reads: the Secrets tab, the Integrations tab,
|
|
168
|
+
connections, roles, Monitoring, the local database. An
|
|
168
169
|
extension may add to them but not relax them, and turning one off does not turn
|
|
169
170
|
off the SDK's lint rules that check the same things.
|
|
170
171
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { I as IntegrationMap, a as IntegrationDefinition, E as EnvRef } from '../types-
|
|
2
|
-
export { A as AUTH_ENV_FIELDS, b as AUTH_SECRET_FIELDS, c as AuthKind, d as EnvKey, e as IntegrationAuth, P as Protocol, R as RESERVED_KEY_PREFIX, f as defineIntegrations } from '../types-
|
|
1
|
+
import { I as IntegrationMap, a as IntegrationDefinition, E as EnvRef } from '../types-Cl7g4ego.js';
|
|
2
|
+
export { A as AUTH_ENV_FIELDS, b as AUTH_SECRET_FIELDS, c as AuthKind, d as EnvKey, e as IntegrationAuth, P as Protocol, R as RESERVED_KEY_PREFIX, f as defineIntegrations } from '../types-Cl7g4ego.js';
|
|
3
3
|
import { E as Env } from '../env-R-bci5RU.js';
|
|
4
4
|
|
|
5
5
|
interface IntegrationProblem {
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
IntegrationError,
|
|
7
7
|
OAUTH_REFRESH_SKEW_MS,
|
|
8
8
|
createIntegrationClient
|
|
9
|
-
} from "../chunk-
|
|
9
|
+
} from "../chunk-NMJOF3ZM.js";
|
|
10
10
|
import {
|
|
11
11
|
AUTH_ENV_FIELDS,
|
|
12
12
|
AUTH_SECRET_FIELDS,
|
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
loggingKey,
|
|
19
19
|
readRef,
|
|
20
20
|
requiredKeys
|
|
21
|
-
} from "../chunk-
|
|
21
|
+
} from "../chunk-5RAO3LPF.js";
|
|
22
22
|
import {
|
|
23
23
|
PLATFORM_MANAGED_HOSTS,
|
|
24
24
|
isPlatformManagedHost
|
package/dist/next/boot/index.js
CHANGED
|
@@ -10,7 +10,7 @@ import "../../chunk-7ASQHY7O.js";
|
|
|
10
10
|
async function qoreRegister(node) {
|
|
11
11
|
await register();
|
|
12
12
|
if (process.env.NEXT_RUNTIME === "nodejs" && node) {
|
|
13
|
-
const { bootNode } = await import("../../node-
|
|
13
|
+
const { bootNode } = await import("../../node-HH3ZZD2R.js");
|
|
14
14
|
await bootNode(node);
|
|
15
15
|
}
|
|
16
16
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { A as AUTH_ENV_FIELDS, b as AUTH_SECRET_FIELDS, c as AuthKind, d as EnvKey, E as EnvRef, e as IntegrationAuth, a as IntegrationDefinition, I as IntegrationMap, P as Protocol, R as RESERVED_KEY_PREFIX, f as defineIntegrations } from '../../types-
|
|
1
|
+
export { A as AUTH_ENV_FIELDS, b as AUTH_SECRET_FIELDS, c as AuthKind, d as EnvKey, E as EnvRef, e as IntegrationAuth, a as IntegrationDefinition, I as IntegrationMap, P as Protocol, R as RESERVED_KEY_PREFIX, f as defineIntegrations } from '../../types-Cl7g4ego.js';
|
|
2
2
|
export { DEFAULT_INTEGRATION_TIMEOUT_MS, INTEGRATION_ALIAS_ATTR, INTEGRATION_SPAN_TYPE, INTEGRATION_SPAN_TYPE_ATTR, IntegrationClient, IntegrationConfig, IntegrationError, IntegrationErrorCode, IntegrationHandle, IntegrationProblem, IntegrationRequest, OAUTH_REFRESH_SKEW_MS, PLATFORM_MANAGED_HOSTS, ParamValue, allKeys, assertIntegrations, createIntegrationClient, isPlatformManagedHost, loggingEnabled, loggingKey, readRef, requiredKeys } from '../../integrations/index.js';
|
|
3
3
|
import '../../env-R-bci5RU.js';
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
IntegrationError,
|
|
7
7
|
OAUTH_REFRESH_SKEW_MS,
|
|
8
8
|
createIntegrationClient
|
|
9
|
-
} from "../../chunk-
|
|
9
|
+
} from "../../chunk-NMJOF3ZM.js";
|
|
10
10
|
import {
|
|
11
11
|
AUTH_ENV_FIELDS,
|
|
12
12
|
AUTH_SECRET_FIELDS,
|
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
loggingKey,
|
|
19
19
|
readRef,
|
|
20
20
|
requiredKeys
|
|
21
|
-
} from "../../chunk-
|
|
21
|
+
} from "../../chunk-5RAO3LPF.js";
|
|
22
22
|
import {
|
|
23
23
|
PLATFORM_MANAGED_HOSTS,
|
|
24
24
|
isPlatformManagedHost
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
+
import {
|
|
2
|
+
proxyMatcher
|
|
3
|
+
} from "../../chunk-X6D3TBNS.js";
|
|
1
4
|
import {
|
|
2
5
|
QORE_CSP_REPORT_URI,
|
|
3
6
|
createCspReportRoute,
|
|
4
7
|
readCspReport
|
|
5
8
|
} from "../../chunk-P7HNHLW7.js";
|
|
6
9
|
import "../../chunk-FUPTRHT7.js";
|
|
7
|
-
import {
|
|
8
|
-
proxyMatcher
|
|
9
|
-
} from "../../chunk-X6D3TBNS.js";
|
|
10
10
|
import {
|
|
11
11
|
STATIC_SECURITY_HEADERS
|
|
12
12
|
} from "../../chunk-2HE2D4SY.js";
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ALWAYS_EXCLUDED
|
|
3
3
|
} from "../../chunk-X6D3TBNS.js";
|
|
4
|
+
import {
|
|
5
|
+
QORE_CSP_REPORT_URI
|
|
6
|
+
} from "../../chunk-P7HNHLW7.js";
|
|
7
|
+
import "../../chunk-FUPTRHT7.js";
|
|
4
8
|
|
|
5
9
|
// src/next/security/testing.ts
|
|
6
10
|
var DEFAULT_SESSION_COOKIES = [
|
|
@@ -36,6 +40,7 @@ function expectHeader(response, name, value) {
|
|
|
36
40
|
);
|
|
37
41
|
}
|
|
38
42
|
}
|
|
43
|
+
var REPORT_URIS = ["/api/csp-report", QORE_CSP_REPORT_URI];
|
|
39
44
|
function expectContains(actual, needle, what) {
|
|
40
45
|
if (!actual.includes(needle)) {
|
|
41
46
|
throw new Error(`${what}: expected it to contain ${JSON.stringify(needle)}, got ${JSON.stringify(actual)}`);
|
|
@@ -82,7 +87,11 @@ function securityHeaderChecks(target) {
|
|
|
82
87
|
expectContains(first, "'strict-dynamic'", "content-security-policy");
|
|
83
88
|
expectContains(first, "frame-ancestors 'none'", "content-security-policy");
|
|
84
89
|
expectContains(first, "object-src 'none'", "content-security-policy");
|
|
85
|
-
|
|
90
|
+
if (!REPORT_URIS.some((uri) => first.includes(`report-uri ${uri}`))) {
|
|
91
|
+
throw new Error(
|
|
92
|
+
`content-security-policy: expected a report-uri of ${REPORT_URIS.join(" or ")}, got ${JSON.stringify(first)}`
|
|
93
|
+
);
|
|
94
|
+
}
|
|
86
95
|
const nonce = nonceOf(first);
|
|
87
96
|
if (!nonce) throw new Error(`content-security-policy carries no nonce: ${first}`);
|
|
88
97
|
if (nonce === nonceOf(second)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/next/security/testing.ts"],"sourcesContent":["import { ALWAYS_EXCLUDED } from \"../../security-core/proxy\"\nimport type { SecuredProxy } from \"./index\"\n\n/**\n * The security-header contract, as a list of checks an app runs against its own\n * proxy.\n *\n * These are not tests of `@quatronic/sdk` — this package has its own. They are\n * for the generated app, so that removing `withSecurityHeaders` from\n * `src/proxy.ts`, or matching so few routes that it stops running, fails that\n * app's build rather than being noticed in a penetration test.\n *\n * It returns checks rather than declaring them, so this module needs no test\n * runner of its own and works under whichever one the app uses:\n *\n * import { describe, it } from \"vitest\"\n * import { securityHeaderChecks } from \"@quatronic/sdk/next/security/testing\"\n * import { config, proxy } from \"@/proxy\"\n *\n * describe(\"security headers\", () => {\n * for (const check of securityHeaderChecks({ proxy, config })) it(check.name, check.run)\n * })\n *\n * A failing check throws with the header it wanted and the value it got, which\n * every runner reports as the test failure.\n */\n\nexport interface SecurityContractCookie {\n name: string\n value: string\n}\n\nexport interface SecurityContractTarget {\n /** The app's `proxy` export — the value `withSecurityHeaders` returned. */\n proxy: SecuredProxy\n /** The app's `config` export. Its matcher is checked too. */\n config: { matcher: readonly string[] }\n /**\n * Cookies that make a request look signed-in, so an auth module's proxy\n * passes it through instead of redirecting.\n *\n * Defaults to both QDC session cookies at once, which is what lets one\n * shipped test file cover every recipe: an app generated from `next-auth`\n * reads `qdc_session`, one from `next-betterauth` reads\n * `better-auth.session_token`, and a `next-base` app reads neither.\n */\n sessionCookies?: readonly SecurityContractCookie[]\n /** The URL the stub request carries. Must be a route the matcher covers. */\n url?: string\n}\n\nexport interface SecurityCheck {\n name: string\n run: () => Promise<void>\n}\n\nconst DEFAULT_SESSION_COOKIES: SecurityContractCookie[] = [\n { name: \"qdc_session\", value: \"test\" },\n { name: \"better-auth.session_token\", value: \"test\" },\n]\n\nconst DEFAULT_URL = \"https://app.example.test/dashboard\"\n\nfunction nextUrlStub(href: string): URL {\n return Object.assign(new URL(href), { clone: () => nextUrlStub(href) })\n}\n\n/**\n * Enough of a `NextRequest` for a proxy: the URL it can clone and the cookie\n * jar it reads. Casting through `unknown` keeps the stub honest about being one\n * — a partial `NextRequest` is exactly what this is.\n */\nfunction makeRequest(url: string, cookies: readonly SecurityContractCookie[]): NextRequestStub {\n return Object.assign(new Request(url), {\n nextUrl: nextUrlStub(url),\n cookies: {\n has: (name: string) => cookies.some((cookie) => cookie.name === name),\n get: (name: string) => cookies.find((cookie) => cookie.name === name),\n getAll: () => [...cookies],\n },\n }) as unknown as NextRequestStub\n}\n\ntype NextRequestStub = Parameters<SecuredProxy>[0]\n\n/** No runtime reads the fetch event, and jsdom has no `NextFetchEvent`. */\nconst NO_EVENT = {} as unknown as Parameters<SecuredProxy>[1]\n\nfunction cspOf(response: Response): string {\n return (\n response.headers.get(\"content-security-policy\") ??\n response.headers.get(\"content-security-policy-report-only\") ??\n \"\"\n )\n}\n\nfunction nonceOf(csp: string): string | undefined {\n return /'nonce-([^']+)'/.exec(csp)?.[1]\n}\n\nfunction expectHeader(response: Response, name: string, value: string): void {\n const actual = response.headers.get(name)\n if (actual !== value) {\n throw new Error(\n `${name}: expected ${JSON.stringify(value)}, got ${actual === null ? \"no header\" : JSON.stringify(actual)}`,\n )\n }\n}\n\nfunction expectContains(actual: string, needle: string, what: string): void {\n if (!actual.includes(needle)) {\n throw new Error(`${what}: expected it to contain ${JSON.stringify(needle)}, got ${JSON.stringify(actual)}`)\n }\n}\n\nexport function securityHeaderChecks(target: SecurityContractTarget): SecurityCheck[] {\n const url = target.url ?? DEFAULT_URL\n const signedIn = target.sessionCookies ?? DEFAULT_SESSION_COOKIES\n const run = (cookies: readonly SecurityContractCookie[]): Promise<Response> =>\n Promise.resolve(target.proxy(makeRequest(url, cookies), NO_EVENT))\n\n return [\n {\n name: \"sends the static headers on a signed-in request\",\n async run() {\n const response = await run(signedIn)\n expectHeader(response, \"x-content-type-options\", \"nosniff\")\n expectHeader(response, \"x-frame-options\", \"DENY\")\n expectHeader(response, \"referrer-policy\", \"strict-origin-when-cross-origin\")\n expectHeader(response, \"cross-origin-resource-policy\", \"same-origin\")\n expectContains(\n response.headers.get(\"strict-transport-security\") ?? \"\",\n \"max-age=\",\n \"strict-transport-security\",\n )\n expectContains(\n response.headers.get(\"permissions-policy\") ?? \"\",\n \"camera=()\",\n \"permissions-policy\",\n )\n },\n },\n {\n name: \"sends them on a request with no session too\",\n async run() {\n // Whatever this app does with an anonymous request — pass it through or\n // redirect it to a login — the response is still one the browser hardens.\n const response = await run([])\n expectHeader(response, \"x-content-type-options\", \"nosniff\")\n expectContains(cspOf(response), \"default-src 'self'\", \"content-security-policy\")\n },\n },\n {\n name: \"builds a CSP with a fresh nonce per response\",\n async run() {\n const first = cspOf(await run(signedIn))\n const second = cspOf(await run(signedIn))\n\n expectContains(first, \"'strict-dynamic'\", \"content-security-policy\")\n expectContains(first, \"frame-ancestors 'none'\", \"content-security-policy\")\n expectContains(first, \"object-src 'none'\", \"content-security-policy\")\n expectContains(first, \"report-uri /api/csp-report\", \"content-security-policy\")\n\n const nonce = nonceOf(first)\n if (!nonce) throw new Error(`content-security-policy carries no nonce: ${first}`)\n if (nonce === nonceOf(second)) {\n throw new Error(`two responses shared one nonce (${nonce}); a reused nonce protects nothing`)\n }\n },\n },\n {\n name: \"hands the nonce to the renderer on the forwarded request\",\n async run() {\n // A nonce only protects anything if the page carrying it is the page the\n // nonce was minted for. Next reads it off the request's CSP header.\n const response = await run(signedIn)\n const nonce = nonceOf(cspOf(response))\n if (!nonce) throw new Error(\"content-security-policy carries no nonce\")\n\n expectHeader(response, \"x-middleware-request-x-qdc-nonce\", nonce)\n expectContains(\n response.headers.get(\"x-middleware-request-content-security-policy\") ?? \"\",\n `'nonce-${nonce}'`,\n \"the forwarded request's content-security-policy\",\n )\n },\n },\n {\n name: \"matches every route that serves HTML\",\n run() {\n if (target.config.matcher.length === 0) {\n throw new Error(\"config.matcher is empty, so the proxy never runs\")\n }\n // Next extracts `config` statically, so the app writes this as a\n // literal rather than calling `proxyMatcher`. That makes the literal\n // the thing that can drift, and this the check that catches it: the\n // build output and the image optimizer are the only sanctioned holes,\n // and nonce-ing them would be pointless work on every asset request.\n for (const pattern of target.config.matcher) {\n for (const excluded of ALWAYS_EXCLUDED) {\n expectContains(pattern, excluded, \"config.matcher entry\")\n }\n }\n return Promise.resolve()\n },\n },\n ]\n}\n"],"mappings":";;;;;AAwDA,IAAM,0BAAoD;AAAA,EACxD,EAAE,MAAM,eAAe,OAAO,OAAO;AAAA,EACrC,EAAE,MAAM,6BAA6B,OAAO,OAAO;AACrD;AAEA,IAAM,cAAc;AAEpB,SAAS,YAAY,MAAmB;AACtC,SAAO,OAAO,OAAO,IAAI,IAAI,IAAI,GAAG,EAAE,OAAO,MAAM,YAAY,IAAI,EAAE,CAAC;AACxE;AAOA,SAAS,YAAY,KAAa,SAA6D;AAC7F,SAAO,OAAO,OAAO,IAAI,QAAQ,GAAG,GAAG;AAAA,IACrC,SAAS,YAAY,GAAG;AAAA,IACxB,SAAS;AAAA,MACP,KAAK,CAAC,SAAiB,QAAQ,KAAK,CAAC,WAAW,OAAO,SAAS,IAAI;AAAA,MACpE,KAAK,CAAC,SAAiB,QAAQ,KAAK,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A,MACE,MAAM;AAAA,MACN,MAAM;AACJ,YAAI,OAAO,OAAO,QAAQ,WAAW,GAAG;AACtC,gBAAM,IAAI,MAAM,kDAAkD;AAAA,QACpE;AAMA,mBAAW,WAAW,OAAO,OAAO,SAAS;AAC3C,qBAAW,YAAY,iBAAiB;AACtC,2BAAe,SAAS,UAAU,sBAAsB;AAAA,UAC1D;AAAA,QACF;AACA,eAAO,QAAQ,QAAQ;AAAA,MACzB;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../src/next/security/testing.ts"],"sourcesContent":["import { ALWAYS_EXCLUDED } from \"../../security-core/proxy\"\nimport { QORE_CSP_REPORT_URI } from \"../../security-core/cspReport\"\nimport type { SecuredProxy } from \"./index\"\n\n/**\n * The security-header contract, as a list of checks an app runs against its own\n * proxy.\n *\n * These are not tests of `@quatronic/sdk` — this package has its own. They are\n * for the generated app, so that removing `withSecurityHeaders` from\n * `src/proxy.ts`, or matching so few routes that it stops running, fails that\n * app's build rather than being noticed in a penetration test.\n *\n * It returns checks rather than declaring them, so this module needs no test\n * runner of its own and works under whichever one the app uses:\n *\n * import { describe, it } from \"vitest\"\n * import { securityHeaderChecks } from \"@quatronic/sdk/next/security/testing\"\n * import { config, proxy } from \"@/proxy\"\n *\n * describe(\"security headers\", () => {\n * for (const check of securityHeaderChecks({ proxy, config })) it(check.name, check.run)\n * })\n *\n * A failing check throws with the header it wanted and the value it got, which\n * every runner reports as the test failure.\n */\n\nexport interface SecurityContractCookie {\n name: string\n value: string\n}\n\nexport interface SecurityContractTarget {\n /** The app's `proxy` export — the value `withSecurityHeaders` returned. */\n proxy: SecuredProxy\n /** The app's `config` export. Its matcher is checked too. */\n config: { matcher: readonly string[] }\n /**\n * Cookies that make a request look signed-in, so an auth module's proxy\n * passes it through instead of redirecting.\n *\n * Defaults to both QDC session cookies at once, which is what lets one\n * shipped test file cover every recipe: an app generated from `next-auth`\n * reads `qdc_session`, one from `next-betterauth` reads\n * `better-auth.session_token`, and a `next-base` app reads neither.\n */\n sessionCookies?: readonly SecurityContractCookie[]\n /** The URL the stub request carries. Must be a route the matcher covers. */\n url?: string\n}\n\nexport interface SecurityCheck {\n name: string\n run: () => Promise<void>\n}\n\nconst DEFAULT_SESSION_COOKIES: SecurityContractCookie[] = [\n { name: \"qdc_session\", value: \"test\" },\n { name: \"better-auth.session_token\", value: \"test\" },\n]\n\nconst DEFAULT_URL = \"https://app.example.test/dashboard\"\n\nfunction nextUrlStub(href: string): URL {\n return Object.assign(new URL(href), { clone: () => nextUrlStub(href) })\n}\n\n/**\n * Enough of a `NextRequest` for a proxy: the URL it can clone and the cookie\n * jar it reads. Casting through `unknown` keeps the stub honest about being one\n * — a partial `NextRequest` is exactly what this is.\n */\nfunction makeRequest(url: string, cookies: readonly SecurityContractCookie[]): NextRequestStub {\n return Object.assign(new Request(url), {\n nextUrl: nextUrlStub(url),\n cookies: {\n has: (name: string) => cookies.some((cookie) => cookie.name === name),\n get: (name: string) => cookies.find((cookie) => cookie.name === name),\n getAll: () => [...cookies],\n },\n }) as unknown as NextRequestStub\n}\n\ntype NextRequestStub = Parameters<SecuredProxy>[0]\n\n/** No runtime reads the fetch event, and jsdom has no `NextFetchEvent`. */\nconst NO_EVENT = {} as unknown as Parameters<SecuredProxy>[1]\n\nfunction cspOf(response: Response): string {\n return (\n response.headers.get(\"content-security-policy\") ??\n response.headers.get(\"content-security-policy-report-only\") ??\n \"\"\n )\n}\n\nfunction nonceOf(csp: string): string | undefined {\n return /'nonce-([^']+)'/.exec(csp)?.[1]\n}\n\nfunction expectHeader(response: Response, name: string, value: string): void {\n const actual = response.headers.get(name)\n if (actual !== value) {\n throw new Error(\n `${name}: expected ${JSON.stringify(value)}, got ${actual === null ? \"no header\" : JSON.stringify(actual)}`,\n )\n }\n}\n\nconst REPORT_URIS = [\"/api/csp-report\", QORE_CSP_REPORT_URI]\n\nfunction expectContains(actual: string, needle: string, what: string): void {\n if (!actual.includes(needle)) {\n throw new Error(`${what}: expected it to contain ${JSON.stringify(needle)}, got ${JSON.stringify(actual)}`)\n }\n}\n\nexport function securityHeaderChecks(target: SecurityContractTarget): SecurityCheck[] {\n const url = target.url ?? DEFAULT_URL\n const signedIn = target.sessionCookies ?? DEFAULT_SESSION_COOKIES\n const run = (cookies: readonly SecurityContractCookie[]): Promise<Response> =>\n Promise.resolve(target.proxy(makeRequest(url, cookies), NO_EVENT))\n\n return [\n {\n name: \"sends the static headers on a signed-in request\",\n async run() {\n const response = await run(signedIn)\n expectHeader(response, \"x-content-type-options\", \"nosniff\")\n expectHeader(response, \"x-frame-options\", \"DENY\")\n expectHeader(response, \"referrer-policy\", \"strict-origin-when-cross-origin\")\n expectHeader(response, \"cross-origin-resource-policy\", \"same-origin\")\n expectContains(\n response.headers.get(\"strict-transport-security\") ?? \"\",\n \"max-age=\",\n \"strict-transport-security\",\n )\n expectContains(\n response.headers.get(\"permissions-policy\") ?? \"\",\n \"camera=()\",\n \"permissions-policy\",\n )\n },\n },\n {\n name: \"sends them on a request with no session too\",\n async run() {\n // Whatever this app does with an anonymous request — pass it through or\n // redirect it to a login — the response is still one the browser hardens.\n const response = await run([])\n expectHeader(response, \"x-content-type-options\", \"nosniff\")\n expectContains(cspOf(response), \"default-src 'self'\", \"content-security-policy\")\n },\n },\n {\n name: \"builds a CSP with a fresh nonce per response\",\n async run() {\n const first = cspOf(await run(signedIn))\n const second = cspOf(await run(signedIn))\n\n expectContains(first, \"'strict-dynamic'\", \"content-security-policy\")\n expectContains(first, \"frame-ancestors 'none'\", \"content-security-policy\")\n expectContains(first, \"object-src 'none'\", \"content-security-policy\")\n // `withSecurityHeaders` reports to the app's own route, `qoreProxy` to the\n // platform's; either one collects the evidence.\n if (!REPORT_URIS.some((uri) => first.includes(`report-uri ${uri}`))) {\n throw new Error(\n `content-security-policy: expected a report-uri of ${REPORT_URIS.join(\" or \")}, got ${JSON.stringify(first)}`,\n )\n }\n\n const nonce = nonceOf(first)\n if (!nonce) throw new Error(`content-security-policy carries no nonce: ${first}`)\n if (nonce === nonceOf(second)) {\n throw new Error(`two responses shared one nonce (${nonce}); a reused nonce protects nothing`)\n }\n },\n },\n {\n name: \"hands the nonce to the renderer on the forwarded request\",\n async run() {\n // A nonce only protects anything if the page carrying it is the page the\n // nonce was minted for. Next reads it off the request's CSP header.\n const response = await run(signedIn)\n const nonce = nonceOf(cspOf(response))\n if (!nonce) throw new Error(\"content-security-policy carries no nonce\")\n\n expectHeader(response, \"x-middleware-request-x-qdc-nonce\", nonce)\n expectContains(\n response.headers.get(\"x-middleware-request-content-security-policy\") ?? \"\",\n `'nonce-${nonce}'`,\n \"the forwarded request's content-security-policy\",\n )\n },\n },\n {\n name: \"matches every route that serves HTML\",\n run() {\n if (target.config.matcher.length === 0) {\n throw new Error(\"config.matcher is empty, so the proxy never runs\")\n }\n // Next extracts `config` statically, so the app writes this as a\n // literal rather than calling `proxyMatcher`. That makes the literal\n // the thing that can drift, and this the check that catches it: the\n // build output and the image optimizer are the only sanctioned holes,\n // and nonce-ing them would be pointless work on every asset request.\n for (const pattern of target.config.matcher) {\n for (const excluded of ALWAYS_EXCLUDED) {\n expectContains(pattern, excluded, \"config.matcher entry\")\n }\n }\n return Promise.resolve()\n },\n },\n ]\n}\n"],"mappings":";;;;;;;;;AAyDA,IAAM,0BAAoD;AAAA,EACxD,EAAE,MAAM,eAAe,OAAO,OAAO;AAAA,EACrC,EAAE,MAAM,6BAA6B,OAAO,OAAO;AACrD;AAEA,IAAM,cAAc;AAEpB,SAAS,YAAY,MAAmB;AACtC,SAAO,OAAO,OAAO,IAAI,IAAI,IAAI,GAAG,EAAE,OAAO,MAAM,YAAY,IAAI,EAAE,CAAC;AACxE;AAOA,SAAS,YAAY,KAAa,SAA6D;AAC7F,SAAO,OAAO,OAAO,IAAI,QAAQ,GAAG,GAAG;AAAA,IACrC,SAAS,YAAY,GAAG;AAAA,IACxB,SAAS;AAAA,MACP,KAAK,CAAC,SAAiB,QAAQ,KAAK,CAAC,WAA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I,QAAQ;AACnC,cAAM,QAAQ,QAAQ,MAAM,QAAQ,CAAC;AACrC,YAAI,CAAC,MAAO,OAAM,IAAI,MAAM,0CAA0C;AAEtE,qBAAa,UAAU,oCAAoC,KAAK;AAChE;AAAA,UACE,SAAS,QAAQ,IAAI,8CAA8C,KAAK;AAAA,UACxE,UAAU,KAAK;AAAA,UACf;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,IACA;AAAA,MACE,MAAM;AAAA,MACN,MAAM;AACJ,YAAI,OAAO,OAAO,QAAQ,WAAW,GAAG;AACtC,gBAAM,IAAI,MAAM,kDAAkD;AAAA,QACpE;AAMA,mBAAW,WAAW,OAAO,OAAO,SAAS;AAC3C,qBAAW,YAAY,iBAAiB;AACtC,2BAAe,SAAS,UAAU,sBAAsB;AAAA,UAC1D;AAAA,QACF;AACA,eAAO,QAAQ,QAAQ;AAAA,MACzB;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
package/dist/node/boot/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { A as AUTH_ENV_FIELDS, b as AUTH_SECRET_FIELDS, c as AuthKind, d as EnvKey, E as EnvRef, e as IntegrationAuth, a as IntegrationDefinition, I as IntegrationMap, P as Protocol, R as RESERVED_KEY_PREFIX, f as defineIntegrations } from '../../types-
|
|
1
|
+
export { A as AUTH_ENV_FIELDS, b as AUTH_SECRET_FIELDS, c as AuthKind, d as EnvKey, E as EnvRef, e as IntegrationAuth, a as IntegrationDefinition, I as IntegrationMap, P as Protocol, R as RESERVED_KEY_PREFIX, f as defineIntegrations } from '../../types-Cl7g4ego.js';
|
|
2
2
|
export { DEFAULT_INTEGRATION_TIMEOUT_MS, INTEGRATION_ALIAS_ATTR, INTEGRATION_SPAN_TYPE, INTEGRATION_SPAN_TYPE_ATTR, IntegrationClient, IntegrationConfig, IntegrationError, IntegrationErrorCode, IntegrationHandle, IntegrationProblem, IntegrationRequest, OAUTH_REFRESH_SKEW_MS, PLATFORM_MANAGED_HOSTS, ParamValue, allKeys, assertIntegrations, createIntegrationClient, isPlatformManagedHost, loggingEnabled, loggingKey, readRef, requiredKeys } from '../../integrations/index.js';
|
|
3
3
|
import '../../env-R-bci5RU.js';
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
IntegrationError,
|
|
7
7
|
OAUTH_REFRESH_SKEW_MS,
|
|
8
8
|
createIntegrationClient
|
|
9
|
-
} from "../../chunk-
|
|
9
|
+
} from "../../chunk-NMJOF3ZM.js";
|
|
10
10
|
import {
|
|
11
11
|
AUTH_ENV_FIELDS,
|
|
12
12
|
AUTH_SECRET_FIELDS,
|
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
loggingKey,
|
|
19
19
|
readRef,
|
|
20
20
|
requiredKeys
|
|
21
|
-
} from "../../chunk-
|
|
21
|
+
} from "../../chunk-5RAO3LPF.js";
|
|
22
22
|
import {
|
|
23
23
|
PLATFORM_MANAGED_HOSTS,
|
|
24
24
|
isPlatformManagedHost
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
assertIntegrations
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-5RAO3LPF.js";
|
|
4
4
|
import "./chunk-5XMTUPIY.js";
|
|
5
5
|
import {
|
|
6
6
|
runAuthMigrations
|
|
@@ -43,4 +43,4 @@ async function bootNode(boot) {
|
|
|
43
43
|
export {
|
|
44
44
|
bootNode
|
|
45
45
|
};
|
|
46
|
-
//# sourceMappingURL=node-
|
|
46
|
+
//# sourceMappingURL=node-HH3ZZD2R.js.map
|
|
@@ -64,8 +64,13 @@ declare function defineIntegrations<const M extends IntegrationMap>(map: M): M;
|
|
|
64
64
|
* declaration without evaluating app code.
|
|
65
65
|
*/
|
|
66
66
|
declare const AUTH_ENV_FIELDS: Record<AuthKind, readonly string[]>;
|
|
67
|
-
/**
|
|
68
|
-
|
|
67
|
+
/**
|
|
68
|
+
* Auth fields whose env value is a secret, so the portal locks it whatever
|
|
69
|
+
* `env.ts` labels it. The identifier of a login counts with its secret:
|
|
70
|
+
* `username` sits with `password` and `clientId` with `clientSecret`, because
|
|
71
|
+
* that is where a person looks for them and they are replaced together.
|
|
72
|
+
*/
|
|
73
|
+
declare const AUTH_SECRET_FIELDS: readonly ["apiKey", "token", "username", "password", "clientId", "clientSecret"];
|
|
69
74
|
/**
|
|
70
75
|
* Env keys under this prefix belong to the platform
|
|
71
76
|
* (`QORE_INTEGRATION_<ALIAS>_LOGGING` today). A declaration may not claim one.
|
|
@@ -179,7 +179,9 @@ async function ensureAdminSeed(db: NodePgDatabase): Promise<void> {
|
|
|
179
179
|
const password = process.env.ADMIN_PASSWORD
|
|
180
180
|
if (!email && !password) return
|
|
181
181
|
if (!email || !password || password.length < 8) {
|
|
182
|
-
Sentry.logger.warn(
|
|
182
|
+
Sentry.logger.warn(
|
|
183
|
+
"admin seed skipped: ADMIN_EMAIL and ADMIN_PASSWORD (min 8 chars) must both be set",
|
|
184
|
+
)
|
|
183
185
|
return
|
|
184
186
|
}
|
|
185
187
|
const existing = await db.select().from(user).where(eq(user.email, email)).limit(1)
|
package/migrations/run.mjs
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
// (`--jscodeshift <dir it is installed in>`), and only a migration whose
|
|
16
16
|
// codemod parses code needs it; `parser = "text"` codemods get the raw text.
|
|
17
17
|
import { createHash } from "node:crypto"
|
|
18
|
-
import { existsSync, mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync } from "node:fs"
|
|
18
|
+
import { existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, rmSync, writeFileSync } from "node:fs"
|
|
19
19
|
import { createRequire } from "node:module"
|
|
20
20
|
import { dirname, join, resolve } from "node:path"
|
|
21
21
|
import { fileURLToPath, pathToFileURL } from "node:url"
|
|
@@ -299,9 +299,21 @@ function loadJscodeshift(dir) {
|
|
|
299
299
|
}
|
|
300
300
|
}
|
|
301
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
|
+
|
|
302
311
|
// CLI: node run.mjs --app <dir> [--from <version>] [--to <version>]
|
|
303
312
|
// [--only id,id] [--test-only] [--jscodeshift <dir>] [--report <file>]
|
|
304
|
-
|
|
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])) {
|
|
305
317
|
const arg = (/** @type {string} */ name) => {
|
|
306
318
|
const i = process.argv.indexOf(name)
|
|
307
319
|
return i > 0 ? process.argv[i + 1] : undefined
|
package/package.json
CHANGED
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"]},
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: qore-add-env-key
|
|
3
|
+
description: Add an env key to src/config/env.ts and decide whether it is a secret or configuration (`.meta({ kind: "config" })`). Use whenever this app reads a new environment variable, or when a key shows up under the wrong heading in the portal.
|
|
4
|
+
allowed-tools: Edit, Read
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Add an env key
|
|
8
|
+
|
|
9
|
+
`src/config/env.ts` is the one list of env this app reads. The manifest
|
|
10
|
+
extractor reads it on every deploy and sends the portal each key's **name**
|
|
11
|
+
(never its value), whether it is optional, and whether it is labelled
|
|
12
|
+
configuration. Values are set per environment in the portal's Secrets tab.
|
|
13
|
+
|
|
14
|
+
## 1. Declare it
|
|
15
|
+
|
|
16
|
+
Add the key to the zod server schema, and to `.env.example` with a blank value
|
|
17
|
+
(never a real one). A required key that is unset fails the env parse, so make a
|
|
18
|
+
key required only when the app cannot work without it; otherwise add
|
|
19
|
+
`.optional()`.
|
|
20
|
+
|
|
21
|
+
## 2. Secret or configuration?
|
|
22
|
+
|
|
23
|
+
Every key is a **secret** unless you label it configuration:
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
SAP_BASE_URL: z.string().url().meta({ kind: "config" }),
|
|
27
|
+
SAP_CLIENT_ID: z.string().min(1),
|
|
28
|
+
SAP_CLIENT_SECRET: z.string().min(1),
|
|
29
|
+
SAP_COMPANY_CODE: z.string().min(1).meta({ kind: "config" }),
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
The label decides two things in the portal: where a person looks for the key
|
|
33
|
+
(Secrets or Configuration), and whether it is governed as a secret (age,
|
|
34
|
+
rotation reminders, findings). So judge a key by what it belongs to, not only
|
|
35
|
+
by what leaking it would cost.
|
|
36
|
+
|
|
37
|
+
- **Secret:** everything that belongs to a login. That is the secret itself
|
|
38
|
+
**and** the identifier paired with it: client id + client secret, username +
|
|
39
|
+
password, key id + key. It also covers any value with a credential embedded in
|
|
40
|
+
it (a database URL with a password, a webhook URL carrying a token). These are
|
|
41
|
+
looked up together, aged together and replaced together, so a client id
|
|
42
|
+
labelled config ends up on a different screen from its secret.
|
|
43
|
+
- **Configuration** (`.meta({ kind: "config" })`): everything that says *where*
|
|
44
|
+
or *how* to call something. That includes URLs, hosts, ports, paths, realm /
|
|
45
|
+
tenant / company codes, timeouts, retries, feature flags, public keys and
|
|
46
|
+
certificates, and anything shipped to the browser.
|
|
47
|
+
- **In doubt:** ask the user. Do not pick a side yourself.
|
|
48
|
+
|
|
49
|
+
A key with more than one environment counts as configuration only when every
|
|
50
|
+
environment's `env.ts` labels it so. An integration's credential fields
|
|
51
|
+
(`apiKey`, `token`, `username`, `password`, `clientId`, `clientSecret`; see
|
|
52
|
+
/qore-add-integration) are always shown as secrets on the Integrations tab,
|
|
53
|
+
whatever the label says, so never label one of them config.
|
|
54
|
+
|
|
55
|
+
## Don't
|
|
56
|
+
|
|
57
|
+
- **Don't** put a real value in `.env.example`, in code, or in a log line.
|
|
@@ -90,14 +90,19 @@ the app cannot do its job without that integration; otherwise mark it
|
|
|
90
90
|
|
|
91
91
|
```ts
|
|
92
92
|
// inside serverSchema = z.object({ ... })
|
|
93
|
-
SAP_BASE_URL: z.string().url(),
|
|
94
|
-
SAP_TOKEN_URL: z.string().url(),
|
|
93
|
+
SAP_BASE_URL: z.string().url().meta({ kind: "config" }),
|
|
94
|
+
SAP_TOKEN_URL: z.string().url().meta({ kind: "config" }),
|
|
95
95
|
SAP_CLIENT_ID: z.string().min(1),
|
|
96
96
|
SAP_CLIENT_SECRET: z.string().min(1),
|
|
97
|
-
SAP_COMPANY_CODE: z.string().min(1),
|
|
98
|
-
SAP_TIMEOUT_MS: z.coerce.number().optional(),
|
|
97
|
+
SAP_COMPANY_CODE: z.string().min(1).meta({ kind: "config" }),
|
|
98
|
+
SAP_TIMEOUT_MS: z.coerce.number().optional().meta({ kind: "config" }),
|
|
99
99
|
```
|
|
100
100
|
|
|
101
|
+
URLs, codes and timeouts are configuration, so they carry
|
|
102
|
+
`.meta({ kind: "config" })`. The client id stays unlabelled, a secret beside
|
|
103
|
+
the client secret, because it belongs to the same login. /qore-add-env-key has
|
|
104
|
+
the rule; in doubt, ask the user.
|
|
105
|
+
|
|
101
106
|
Add the same keys to `.env.example` with a blank value (never a real one), so
|
|
102
107
|
a colleague's `pnpm bootstrap` knows what to ask the portal for. Then set the
|
|
103
108
|
values per environment in the portal's Secrets tab; the Integrations tab shows
|
|
@@ -197,9 +202,10 @@ per call (`qore.integration.call`: alias, method, template, status, duration).
|
|
|
197
202
|
declaration; the client refuses `http(s)://…` paths (`absolute_url`), which is
|
|
198
203
|
what keeps a path parameter from redirecting a call to another host.
|
|
199
204
|
- **Don't put a credential in `config`, in `.env.example`, or in a log line.**
|
|
200
|
-
`apiKey` / `token` / `
|
|
201
|
-
SDK never logs them and neither should you. A
|
|
202
|
-
error carry no secret, so reporting one is safe;
|
|
205
|
+
`apiKey` / `token` / `username` / `password` / `clientId` / `clientSecret`
|
|
206
|
+
are the secret fields; the SDK never logs them and neither should you. A
|
|
207
|
+
failed call's span and error carry no secret, so reporting one is safe;
|
|
208
|
+
whether to report it at all
|
|
203
209
|
follows /qore-observability (unexpected: let it throw; expected: no capture).
|
|
204
210
|
- **Don't bypass `env.ts`.** Reading `process.env.SAP_BASE_URL` directly skips
|
|
205
211
|
validation and leaves `qore env pull` unaware of the key.
|
|
@@ -90,14 +90,19 @@ the service cannot do its job without that integration; otherwise mark it
|
|
|
90
90
|
|
|
91
91
|
```ts
|
|
92
92
|
// inside `const schema = z.object({ ... })`
|
|
93
|
-
SAP_BASE_URL: z.string().url(),
|
|
94
|
-
SAP_TOKEN_URL: z.string().url(),
|
|
93
|
+
SAP_BASE_URL: z.string().url().meta({ kind: "config" }),
|
|
94
|
+
SAP_TOKEN_URL: z.string().url().meta({ kind: "config" }),
|
|
95
95
|
SAP_CLIENT_ID: z.string().min(1),
|
|
96
96
|
SAP_CLIENT_SECRET: z.string().min(1),
|
|
97
|
-
SAP_COMPANY_CODE: z.string().min(1),
|
|
98
|
-
SAP_TIMEOUT_MS: z.coerce.number().optional(),
|
|
97
|
+
SAP_COMPANY_CODE: z.string().min(1).meta({ kind: "config" }),
|
|
98
|
+
SAP_TIMEOUT_MS: z.coerce.number().optional().meta({ kind: "config" }),
|
|
99
99
|
```
|
|
100
100
|
|
|
101
|
+
URLs, codes and timeouts are configuration, so they carry
|
|
102
|
+
`.meta({ kind: "config" })`. The client id stays unlabelled, a secret beside
|
|
103
|
+
the client secret, because it belongs to the same login. /qore-add-env-key has
|
|
104
|
+
the rule; in doubt, ask the user.
|
|
105
|
+
|
|
101
106
|
Add the same keys to `.env.example` with a blank value (never a real one), so
|
|
102
107
|
a colleague's `pnpm bootstrap` knows what to ask the portal for. Then set the
|
|
103
108
|
values per environment in the portal's Secrets tab; the Integrations tab shows
|
|
@@ -197,9 +202,10 @@ per call (`qore.integration.call`: alias, method, template, status, duration).
|
|
|
197
202
|
declaration; the client refuses `http(s)://…` paths (`absolute_url`), which is
|
|
198
203
|
what keeps a path parameter from redirecting a call to another host.
|
|
199
204
|
- **Don't put a credential in `config`, in `.env.example`, or in a log line.**
|
|
200
|
-
`apiKey` / `token` / `
|
|
201
|
-
SDK never logs them and neither should you. A
|
|
202
|
-
error carry no secret, so reporting one is safe;
|
|
205
|
+
`apiKey` / `token` / `username` / `password` / `clientId` / `clientSecret`
|
|
206
|
+
are the secret fields; the SDK never logs them and neither should you. A
|
|
207
|
+
failed call's span and error carry no secret, so reporting one is safe;
|
|
208
|
+
whether to report it at all
|
|
203
209
|
follows /qore-observability (unexpected: let it throw; expected: no capture).
|
|
204
210
|
- **Don't bypass `env.ts`.** Reading `process.env.SAP_BASE_URL` directly skips
|
|
205
211
|
validation and leaves `qore env pull` unaware of the key.
|
|
@@ -40,6 +40,7 @@ Code written with these skills is read by the portal:
|
|
|
40
40
|
|
|
41
41
|
| Skill | What the portal reads |
|
|
42
42
|
|---|---|
|
|
43
|
+
| `qore-add-env-key` | The Secrets tab: which keys are secrets, which configuration |
|
|
43
44
|
| `qore-add-integration` | The Integrations tab |
|
|
44
45
|
| `qore-add-connection` | Connection wiring |
|
|
45
46
|
| `qore-use-permissions` | Roles on the Access page |
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/integrations-core/types.ts","../src/integrations-core/env.ts","../src/integrations-core/assertIntegrations.ts"],"sourcesContent":["/**\n * How an integration authenticates. Every field except `header` and\n * `credentialsIn` names an **env key** — the SDK reads the value from the\n * environment at call time, never from the declaration — so a declaration can\n * sit in source control and carry no secret.\n */\nexport type AuthKind =\n | \"none\"\n | \"api_key_header\"\n | \"bearer_static\"\n | \"basic\"\n | \"oauth2_client_credentials\"\n\n/** What the API speaks. Informational for the portal; the client sends bytes either way. */\nexport type Protocol = \"rest\" | \"odata\" | \"soap\" | \"graphql\"\n\n/** The name of an env var, e.g. `SAP_BASE_URL`. */\nexport type EnvKey = string\n\n/**\n * A reference to an env var. The short form is required; the object form can\n * be optional and carry a default the app falls back on when the key is unset.\n */\nexport type EnvRef =\n | EnvKey\n | { key: EnvKey; optional?: boolean; default?: string | number | boolean }\n\nexport type IntegrationAuth =\n | { kind: \"none\" }\n | { kind: \"api_key_header\"; header: string; apiKey: EnvKey }\n | { kind: \"bearer_static\"; token: EnvKey }\n | { kind: \"basic\"; username: EnvKey; password: EnvKey }\n | {\n kind: \"oauth2_client_credentials\"\n tokenUrl: EnvKey\n clientId: EnvKey\n clientSecret: EnvKey\n scope?: EnvKey\n audience?: EnvKey\n /** Where the client credentials go on the token request. Default `\"header\"`. */\n credentialsIn?: \"header\" | \"body\"\n }\n\nexport interface IntegrationDefinition {\n /** Human name shown in the portal, e.g. \"SAP S/4HANA Cloud\". */\n label: string\n protocol: Protocol\n /** Env key holding the base URL for this environment. */\n baseUrl: EnvKey\n auth: IntegrationAuth\n /** Further env the app reads for this integration, by logical name. */\n config?: Record<string, EnvRef>\n}\n\nexport type IntegrationMap = Record<string, IntegrationDefinition>\n\n/**\n * Identity function that pins the literal types of the map, so an alias typo\n * at a call site is a compile error (`keyof M`) rather than a runtime\n * `not_declared`. Same shape as `definePermissions` in `auth-core`.\n */\nexport function defineIntegrations<const M extends IntegrationMap>(map: M): M {\n return map\n}\n\n/**\n * Which fields of each auth kind name an env key. Shared with the manifest\n * extractor and the portal, which derive the required-env list from a\n * declaration without evaluating app code.\n */\nexport const AUTH_ENV_FIELDS: Record<AuthKind, readonly string[]> = {\n none: [],\n api_key_header: [\"apiKey\"],\n bearer_static: [\"token\"],\n basic: [\"username\", \"password\"],\n oauth2_client_credentials: [\"tokenUrl\", \"clientId\", \"clientSecret\", \"scope\", \"audience\"],\n}\n\n/** Auth fields whose env value is a secret, so the portal masks it. */\nexport const AUTH_SECRET_FIELDS = [\"apiKey\", \"token\", \"password\", \"clientSecret\"] as const\n\n/**\n * Env keys under this prefix belong to the platform\n * (`QORE_INTEGRATION_<ALIAS>_LOGGING` today). A declaration may not claim one.\n */\nexport const RESERVED_KEY_PREFIX = \"QORE_INTEGRATION_\"\n","import { normalizeAlias, type Env } from \"../connections-core/env\"\nimport {\n AUTH_ENV_FIELDS,\n RESERVED_KEY_PREFIX,\n type EnvRef,\n type IntegrationDefinition,\n} from \"./types\"\n\nexport type { Env }\n\nexport function refKey(ref: EnvRef): string {\n return typeof ref === \"string\" ? ref : ref.key\n}\n\nfunction refOptional(ref: EnvRef): boolean {\n return typeof ref !== \"string\" && (ref.optional === true || ref.default !== undefined)\n}\n\n/** The auth fields of `def` that are set, as env keys. */\nfunction authKeys(def: IntegrationDefinition): string[] {\n const auth = def.auth as unknown as Record<string, unknown>\n return AUTH_ENV_FIELDS[def.auth.kind]\n .map((field) => auth[field])\n .filter((key): key is string => typeof key === \"string\" && key !== \"\")\n}\n\n/**\n * Every env key the integration cannot run without: the base URL, every auth\n * field that is set, and every config ref that is neither optional nor\n * defaulted. Order is stable so an error message reads the same twice.\n */\nexport function requiredKeys(def: IntegrationDefinition): string[] {\n const keys = [def.baseUrl, ...authKeys(def)]\n for (const ref of Object.values(def.config ?? {})) {\n if (!refOptional(ref)) keys.push(refKey(ref))\n }\n return [...new Set(keys)]\n}\n\n/** Every env key the declaration names, required or not. */\nexport function allKeys(def: IntegrationDefinition): string[] {\n const keys = [def.baseUrl, ...authKeys(def)]\n for (const ref of Object.values(def.config ?? {})) keys.push(refKey(ref))\n return [...new Set(keys)]\n}\n\n/**\n * Read one ref from `env`, applying its default when the key is unset or\n * empty. A default comes back as declared (a number or boolean stays typed);\n * an env value is always a string.\n */\nexport function readRef(env: Env, ref: EnvRef): string | number | boolean | undefined {\n const value = env[refKey(ref)]\n if (value !== undefined && value !== \"\") return value\n return typeof ref === \"string\" ? undefined : ref.default\n}\n\n/** `QORE_INTEGRATION_<ALIAS>_LOGGING` — the one reserved key v1 reads. */\nexport function loggingKey(alias: string): string {\n return `${RESERVED_KEY_PREFIX}${normalizeAlias(alias)}_LOGGING`\n}\n\n/** Whether the per-call JSON log line is switched on for this alias (\"1\" or \"true\"). */\nexport function loggingEnabled(env: Env, alias: string): boolean {\n const value = env[loggingKey(alias)]\n return value === \"1\" || value?.toLowerCase() === \"true\"\n}\n","import { defaultEnv, type Env } from \"../connections-core/env\"\nimport { allKeys, requiredKeys } from \"./env\"\nimport { RESERVED_KEY_PREFIX, type IntegrationMap } from \"./types\"\n\nconst ENV_KEY_RE = /^[A-Z][A-Z0-9_]*$/\n\nexport interface IntegrationProblem {\n alias: string\n key: string\n /** `missing_env`: a required key is unset or empty. `reserved_key`: the declaration claims a key it may not. */\n code: \"missing_env\" | \"reserved_key\"\n message: string\n}\n\n/**\n * Report, at app startup, what is wrong with the declared integrations: a\n * required env key that is unset, or a key the declaration may not claim.\n * **It never throws.** Integrations are a visibility tool: an API key that is\n * not set (an obsolete integration, a vendor not contracted in this\n * environment) must cost the calls to that one integration — they fail with\n * `missing_env` — never the boot of the whole app. Each problem is logged as\n * one warning and returned, so a caller may act on them if it chooses.\n */\nexport function assertIntegrations(\n map: IntegrationMap,\n opts: { env?: Env; warn?: (message: string) => void } = {},\n): IntegrationProblem[] {\n const env = opts.env ?? defaultEnv()\n const warn = opts.warn ?? ((message: string) => console.warn(message))\n const problems: IntegrationProblem[] = []\n\n for (const [alias, def] of Object.entries(map)) {\n for (const key of allKeys(def)) {\n let why: string | undefined\n if (key.startsWith(RESERVED_KEY_PREFIX)) {\n why = `${RESERVED_KEY_PREFIX}* keys are reserved by the platform`\n } else if (key.startsWith(\"CONN_\")) {\n why = \"CONN_* keys belong to module connections, not integrations\"\n } else if (!ENV_KEY_RE.test(key)) {\n why = \"an env key is uppercase letters, digits and underscores\"\n }\n if (why) {\n problems.push({\n alias,\n key,\n code: \"reserved_key\",\n message: `Integration \"${alias}\" declares env key \"${key}\": ${why}`,\n })\n }\n }\n for (const key of requiredKeys(def)) {\n const value = env[key]\n if (value === undefined || value === \"\") {\n problems.push({\n alias,\n key,\n code: \"missing_env\",\n message: `Integration \"${alias}\" is missing env key \"${key}\"; calls to it will fail until it is set`,\n })\n }\n }\n }\n\n for (const p of problems) warn(`[integrations] ${p.message}`)\n return problems\n}\n"],"mappings":";;;;;;AA6DO,SAAS,mBAAmD,KAAW;AAC5E,SAAO;AACT;AAOO,IAAM,kBAAuD;AAAA,EAClE,MAAM,CAAC;AAAA,EACP,gBAAgB,CAAC,QAAQ;AAAA,EACzB,eAAe,CAAC,OAAO;AAAA,EACvB,OAAO,CAAC,YAAY,UAAU;AAAA,EAC9B,2BAA2B,CAAC,YAAY,YAAY,gBAAgB,SAAS,UAAU;AACzF;AAGO,IAAM,qBAAqB,CAAC,UAAU,SAAS,YAAY,cAAc;AAMzE,IAAM,sBAAsB;;;AC3E5B,SAAS,OAAO,KAAqB;AAC1C,SAAO,OAAO,QAAQ,WAAW,MAAM,IAAI;AAC7C;AAEA,SAAS,YAAY,KAAsB;AACzC,SAAO,OAAO,QAAQ,aAAa,IAAI,aAAa,QAAQ,IAAI,YAAY;AAC9E;AAGA,SAAS,SAAS,KAAsC;AACtD,QAAM,OAAO,IAAI;AACjB,SAAO,gBAAgB,IAAI,KAAK,IAAI,EACjC,IAAI,CAAC,UAAU,KAAK,KAAK,CAAC,EAC1B,OAAO,CAA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