@quatronic/sdk 0.9.0-rc.1 → 0.9.0-test.0c53b6d

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/dist/{chunk-TOBGX4CZ.js → chunk-5RAO3LPF.js} +9 -2
  2. package/dist/chunk-5RAO3LPF.js.map +1 -0
  3. package/dist/{chunk-F3NHTHFO.js → chunk-NMJOF3ZM.js} +2 -2
  4. package/dist/cli/skills-postinstall.js +4 -3
  5. package/dist/cli/skills.js +4 -3
  6. package/dist/integrations/index.d.ts +2 -2
  7. package/dist/integrations/index.js +2 -2
  8. package/dist/next/boot/index.d.ts +1 -1
  9. package/dist/next/boot/index.js +1 -1
  10. package/dist/next/integrations/index.d.ts +1 -1
  11. package/dist/next/integrations/index.js +2 -2
  12. package/dist/node/boot/index.d.ts +1 -1
  13. package/dist/node/boot/index.js +1 -1
  14. package/dist/node/integrations/index.d.ts +1 -1
  15. package/dist/node/integrations/index.js +2 -2
  16. package/dist/{node-OVIG5ZYJ.js → node-YQDRNIYH.js} +2 -2
  17. package/dist/{types-CAwj03sM.d.ts → types-Cl7g4ego.d.ts} +7 -2
  18. package/package.json +1 -1
  19. package/skills/catalog.json +1 -0
  20. package/skills/qore-add-connection/SKILL.next.md +3 -1
  21. package/skills/qore-add-connection/SKILL.node.md +3 -1
  22. package/skills/qore-add-env-key/SKILL.md +222 -0
  23. package/skills/qore-add-integration/SKILL.next.md +17 -9
  24. package/skills/qore-add-integration/SKILL.node.md +19 -13
  25. package/skills/qore-author-skill/SKILL.md +1 -0
  26. package/skills/qore-use-addons/SKILL.md +2 -0
  27. package/skills/qore-use-database/SKILL.md +2 -0
  28. package/skills/qore-use-mail-domain/SKILL.next.md +1 -1
  29. package/skills/qore-use-mail-domain/SKILL.node.md +2 -2
  30. package/dist/chunk-TOBGX4CZ.js.map +0 -1
  31. /package/dist/{chunk-F3NHTHFO.js.map → chunk-NMJOF3ZM.js.map} +0 -0
  32. /package/dist/{node-OVIG5ZYJ.js.map → node-YQDRNIYH.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 = ["apiKey", "token", "password", "clientSecret"];
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-TOBGX4CZ.js.map
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":";;;;;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N,SAAS,gBAAgB,KAAK,yBAAyB,GAAG;AAAA,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-TOBGX4CZ.js";
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-F3NHTHFO.js.map
349
+ //# sourceMappingURL=chunk-NMJOF3ZM.js.map
@@ -163,9 +163,10 @@ extension file.
163
163
 
164
164
  ## Contract skills
165
165
 
166
- \`qore-add-integration\`, \`qore-add-connection\`, \`qore-use-permissions\`,
167
- \`qore-observability\` and \`qore-use-database\` produce code the portal reads:
168
- the Integrations tab, connections, roles, Monitoring, the local database. An
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 Variables 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
 
@@ -162,9 +162,10 @@ extension file.
162
162
 
163
163
  ## Contract skills
164
164
 
165
- \`qore-add-integration\`, \`qore-add-connection\`, \`qore-use-permissions\`,
166
- \`qore-observability\` and \`qore-use-database\` produce code the portal reads:
167
- the Integrations tab, connections, roles, Monitoring, the local database. An
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 Variables 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-CAwj03sM.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-CAwj03sM.js';
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-F3NHTHFO.js";
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-TOBGX4CZ.js";
21
+ } from "../chunk-5RAO3LPF.js";
22
22
  import {
23
23
  PLATFORM_MANAGED_HOSTS,
24
24
  isPlatformManagedHost
@@ -1,4 +1,4 @@
1
- import { I as IntegrationMap } from '../../types-CAwj03sM.js';
1
+ import { I as IntegrationMap } from '../../types-Cl7g4ego.js';
2
2
  export { onRequestError } from '../sentry/register.js';
3
3
  import '@sentry/nextjs';
4
4
 
@@ -11,7 +11,7 @@ import "../../chunk-IFESUTF2.js";
11
11
  async function qoreRegister(node) {
12
12
  await register();
13
13
  if (process.env.NEXT_RUNTIME === "nodejs" && node) {
14
- const { bootNode } = await import("../../node-OVIG5ZYJ.js");
14
+ const { bootNode } = await import("../../node-YQDRNIYH.js");
15
15
  await bootNode(node);
16
16
  }
17
17
  }
@@ -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-CAwj03sM.js';
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-F3NHTHFO.js";
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-TOBGX4CZ.js";
21
+ } from "../../chunk-5RAO3LPF.js";
22
22
  import {
23
23
  PLATFORM_MANAGED_HOSTS,
24
24
  isPlatformManagedHost
@@ -1,4 +1,4 @@
1
- import { I as IntegrationMap } from '../../types-CAwj03sM.js';
1
+ import { I as IntegrationMap } from '../../types-Cl7g4ego.js';
2
2
 
3
3
  interface QoreBootOptions {
4
4
  /** The backend's `integrations` from `./config/integrations.js`. */
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  assertIntegrations
3
- } from "../../chunk-TOBGX4CZ.js";
3
+ } from "../../chunk-5RAO3LPF.js";
4
4
  import "../../chunk-5XMTUPIY.js";
5
5
 
6
6
  // src/node/boot/index.ts
@@ -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-CAwj03sM.js';
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-F3NHTHFO.js";
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-TOBGX4CZ.js";
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-TOBGX4CZ.js";
3
+ } from "./chunk-5RAO3LPF.js";
4
4
  import "./chunk-5XMTUPIY.js";
5
5
 
6
6
  // src/next/boot/node.ts
@@ -30,4 +30,4 @@ async function bootNode(boot) {
30
30
  export {
31
31
  bootNode
32
32
  };
33
- //# sourceMappingURL=node-OVIG5ZYJ.js.map
33
+ //# sourceMappingURL=node-YQDRNIYH.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
- /** Auth fields whose env value is a secret, so the portal masks it. */
68
- declare const AUTH_SECRET_FIELDS: readonly ["apiKey", "token", "password", "clientSecret"];
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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quatronic/sdk",
3
- "version": "0.9.0-rc.1",
3
+ "version": "0.9.0-test.0c53b6d",
4
4
  "type": "module",
5
5
  "private": false,
6
6
  "publishConfig": {
@@ -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"]},
@@ -13,7 +13,7 @@ provider slug uppercased, non-alphanumerics collapsed to `_`. The SDK reads only
13
13
  this env — it never calls the portal at runtime.
14
14
 
15
15
  > A single-module app has no connections. Only follow this once the portal shows
16
- > a wired connection for this module (its env keys exist in the Secrets tab).
16
+ > the connection as Active in this module's Connections tab.
17
17
 
18
18
  ## Kinds of connection
19
19
 
@@ -50,6 +50,8 @@ clear startup error, not a mystery 500. For a service connection to `billing-api
50
50
  CONN_BILLING_API_TOKEN: z.string().min(1),
51
51
  ```
52
52
 
53
+ How to declare, mark and check a key: `/qore-add-env-key`.
54
+
53
55
  ## 2. Fail-fast at startup
54
56
 
55
57
  In a module-scoped init path (e.g. a server-only module imported by your feature
@@ -13,7 +13,7 @@ provider slug uppercased, non-alphanumerics collapsed to `_`. The SDK reads only
13
13
  this env — it never calls the portal at runtime.
14
14
 
15
15
  > A single-module app has no connections. Only follow this once the portal shows
16
- > a wired connection for this module (its env keys exist in the Secrets tab).
16
+ > the connection as Active in this module's Connections tab.
17
17
 
18
18
  This module is a plain `node:http` service (no framework), so the provider side
19
19
  needs one small adapter — step 4 covers it.
@@ -53,6 +53,8 @@ startup error, not a mystery failure. For a service connection to `billing-api`
53
53
  CONN_BILLING_API_TOKEN: z.string().min(1),
54
54
  ```
55
55
 
56
+ How to declare, mark and check a key: `/qore-add-env-key`.
57
+
56
58
  ## 2. Fail-fast at startup
57
59
 
58
60
  In `src/index.ts`, before `server.listen(...)`, assert every wire this module
@@ -0,0 +1,222 @@
1
+ ---
2
+ name: qore-add-env-key
3
+ description: Declare, read and protect this app's settings and secrets (env.ts, .env files, API keys, tokens, passwords, connection strings, feature flags and per-environment config). Use whenever a key is added, renamed or read, a value differs per environment, a third-party credential arrives, something must work locally, or a secret may end up in code, logs or errors, even if the word secret never comes up.
4
+ allowed-tools: Edit, Read, Write
5
+ ---
6
+
7
+ # Settings and secrets
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, whether it is labelled
12
+ configuration, and the value rules below. Values are set per environment in the
13
+ portal's Variables tab.
14
+
15
+ If you were about to...
16
+
17
+ | ...do this | do this instead |
18
+ |---|---|
19
+ | read `process.env.X` in a route | add `X` to `env.ts`, read it from there |
20
+ | paste a real key to make it work locally | `qore env pull`, or list it in `localSecrets` |
21
+ | add a Stripe key | `sk_` secret and `pk_` config, see section 1; the API itself is `/qore-add-integration` |
22
+ | add a feature flag that differs per environment | `z.enum([...])` or `z.stringbool()` marked config |
23
+ | log a failed call's response | log the status only, see section 5 |
24
+
25
+ ## 1. Declare it
26
+
27
+ Add the key to the zod server schema{{#if runtime=next}}, and to `.env.example` with a **blank** value
28
+ (never a real one){{/if}}. A required key that is unset fails the env parse, so make a
29
+ key required only when the app cannot work without it; otherwise add
30
+ `.optional()`.
31
+
32
+ Give a value the tightest rule you know. The portal checks the rules when
33
+ someone applies a value in the Variables tab, and in the Integrations tab's
34
+ value window. A stored value that breaks a rule you add later shows as invalid
35
+ and counts as missing.
36
+
37
+ | You write | The portal checks |
38
+ |---|---|
39
+ | `z.string().min(n)` / `.max(n)` | at least / at most `n` characters |
40
+ | `z.string().length(n)` | exactly `n` (sets both bounds) |
41
+ | `.startsWith("sk_")` / `.endsWith("...")` | that prefix / suffix |
42
+ | `z.hex()` / `z.base64()` / `z.base64url()` | that encoding |
43
+ | `z.coerce.number().int()` | a whole number |
44
+ | `.min(n)` / `.max(n)` / `.gte(n)` / `.lte(n)` on a number | that bound |
45
+
46
+ Only literal arguments count: `.min(32)` yes, `.min(MIN_LEN)` no. The portal
47
+ ignores everything not in this table (`.regex()`, `.refine()`, `.transform()`,
48
+ `.positive()`, `.gt()`, `z.uuid()`, `.nonempty()`); the app still checks those
49
+ at boot.
50
+
51
+ ```ts
52
+ STRIPE_SECRET_KEY: z.string().startsWith("sk_"),
53
+ STRIPE_PUBLISHABLE_KEY: z.string().startsWith("pk_").meta({ kind: "config" }),
54
+ ENCRYPTION_KEY: z.hex().length(64),
55
+ {{#if runtime=next}}
56
+ SESSION_COOKIE_SECRET: z.hex().min(32),
57
+ {{/if}}
58
+ NEW_CHECKOUT: z.stringbool().meta({ kind: "config" }),
59
+ EXPORT_MODE: z.enum(["off", "csv", "xlsx"]).meta({ kind: "config" }),
60
+ ```
61
+ {{#if runtime=next}}
62
+
63
+ A secret never gets the `NEXT_PUBLIC_` prefix. Neither does anything else:
64
+ Qore builds the Next image once and promotes it, so no value from the Variables
65
+ tab is a build arg, and a `NEXT_PUBLIC_` value is `undefined` after deploy.
66
+ Reading it in the browser is also a `process.env` read outside `env.ts`. A
67
+ config value the browser needs (the Stripe publishable key) is read on the
68
+ server with `serverEnv()` and passed down as a prop or in the server-rendered
69
+ page.
70
+ {{/if}}
71
+
72
+ ## 2. Secret or configuration?
73
+
74
+ Every key is a **secret** unless you label it configuration:
75
+
76
+ ```ts
77
+ SAP_BASE_URL: z.string().url().meta({ kind: "config" }),
78
+ SAP_CLIENT_ID: z.string().min(1),
79
+ SAP_CLIENT_SECRET: z.string().min(1),
80
+ SAP_COMPANY_CODE: z.string().min(1).meta({ kind: "config" }),
81
+ ```
82
+
83
+ The label decides two things in the portal: where a person looks for the key
84
+ (the secret or the configuration list), and whether it is governed as a secret (age,
85
+ rotation reminders, findings). So judge a key by what it belongs to, not only
86
+ by what leaking it would cost.
87
+
88
+ - **Secret:** everything that belongs to a login. That is the secret itself
89
+ **and** the identifier paired with it: client id + client secret, username +
90
+ password, key id + key. It also covers any value with a credential embedded in
91
+ it (a database URL with a password, a webhook URL carrying a token). These are
92
+ looked up together, aged together and replaced together, so a client id
93
+ labelled config ends up on a different screen from its secret.
94
+ - **Configuration** (`.meta({ kind: "config" })`): everything that says *where*
95
+ or *how* to call something. That includes URLs, hosts, ports, paths, realm /
96
+ tenant / company codes, timeouts, retries, feature flags, public keys and
97
+ certificates, and anything shipped to the browser.
98
+ - **In doubt:** ask the user. Do not pick a side yourself.
99
+
100
+ A key with more than one environment counts as configuration only when every
101
+ environment's `env.ts` labels it so. An integration's credential fields
102
+ (`apiKey`, `token`, `username`, `password`, `clientId`, `clientSecret`; see
103
+ /qore-add-integration) are always shown as secrets on the Integrations tab,
104
+ whatever the label says, so never label one of them config.
105
+
106
+ ## 3. Where values live
107
+
108
+ - **Per environment:** a value is set in the Variables tab, once per
109
+ environment. A flag that differs between staging and production is two values
110
+ there, not two code paths. Staging and production need their values there
111
+ whatever you set locally.
112
+ - **Platform keys:** the portal writes some keys itself (database and
113
+ connection URLs, auth settings). The app cannot set them; do not ask the user
114
+ for them.
115
+ - **Locally:** `qore env pull` writes the module's env file
116
+ (`{{#if runtime=next}}.env.local{{else}}.env{{/if}}`) from the portal.
117
+ `qore dev` syncs that file and starts the dev server. `qore run -- <command>`
118
+ does not use the file: it fetches the portal's values fresh and injects them
119
+ into the command.
120
+ - **Third-party keys** (Stripe, SAP): set a local or test value for the key in
121
+ the portal, then `qore env pull`. Do not invent one.
122
+ - **App-owned secrets:** a key the app can generate itself, such as an
123
+ encryption key, is listed in `.qore.json` under `localSecrets`. `qore env pull`
124
+ then generates a local value that passes the key's rules (`z.hex().length(64)`
125
+ gives 64 hex characters). A recent qore honours the rules; an older one always
126
+ writes 64 hex characters, so if a generated value fails a rule at boot, update
127
+ qore. Never copy a production value to a laptop.
128
+ {{#if runtime=next}}
129
+
130
+ A `.qore.json` `localSecrets` list replaces qore's default for a Next module,
131
+ which is `["SESSION_COOKIE_SECRET"]`, and generated apps ship no `.qore.json`.
132
+ So when you create the file, keep `SESSION_COOKIE_SECRET` in the list:
133
+ {{/if}}
134
+
135
+ ```json
136
+ {{#if runtime=next}}
137
+ { "localSecrets": ["SESSION_COOKIE_SECRET", "ENCRYPTION_KEY"] }
138
+ {{else}}
139
+ { "localSecrets": ["ENCRYPTION_KEY"] }
140
+ {{/if}}
141
+ ```
142
+
143
+ ## 4. Rotation
144
+
145
+ The portal reminds you when a secret is old; it does not rotate it for you
146
+ (it manages rotation for some platform keys itself).
147
+
148
+ - **API key:** create a new one at the provider, set it in the Variables tab,
149
+ apply, then revoke the old one.
150
+ {{#if runtime=next}}
151
+ - **`SESSION_COOKIE_SECRET`:** everyone is signed out.
152
+ {{/if}}
153
+ - **Encryption key:** data written with the old key must be re-encrypted with
154
+ the new one first. Changing the value alone makes it unreadable.
155
+
156
+ ## 5. Never
157
+
158
+ {{#if runtime=next}}
159
+ - Never put a secret in code, in `.env.example`, in a log line, an error
160
+ message, a span attribute, the client bundle or a URL.
161
+ {{else}}
162
+ - Never put a secret in code, in a log line, an error message, a span
163
+ attribute or a URL.
164
+ {{/if}}
165
+ - Never read `process.env` outside `env.ts`.
166
+ - Never commit an env file.
167
+ - When a call fails, log the status. Never the response body, a token or an
168
+ env value. How to log: `/qore-observability`.
169
+
170
+ ## 6. Older apps
171
+
172
+ An app generated before these rules needs a one-time pass:
173
+
174
+ 1. Tighten the known keys.
175
+ {{#if runtime=next}}
176
+ `SESSION_COOKIE_SECRET` is `z.hex().min(32)`.
177
+ {{else}}
178
+ `PORT` is `z.coerce.number().int().min(1).max(65535)` marked config, and
179
+ `DATABASE_URL`, when the module has a database, is `z.string().startsWith("postgres")`.
180
+ {{/if}}
181
+ 2. Mark config keys with `.meta({ kind: "config" })` (section 2).
182
+ 3. Make `.gitignore` cover the env files (`.env*`{{#if runtime=next}}, except `.env.example`{{/if}}).
183
+ 4. Register the secret values with the Sentry scrubber once, right after the
184
+ env parse, so a value that slips into an error is masked. Register every key
185
+ that is not marked config, so a key added later is covered too. Strings
186
+ shorter than 8 characters and non-strings are ignored.
187
+
188
+ {{#if runtime=next}}
189
+ ```ts
190
+ import { registerSecretValues } from "@quatronic/sdk/next/sentry"
191
+
192
+ export function serverEnv(): ServerEnv {
193
+ if (!_env) {
194
+ // ...parse as before, then:
195
+ _env = parsed.data
196
+ registerSecretValues(
197
+ (Object.keys(serverSchema.shape) as (keyof ServerEnv)[])
198
+ .filter((key) => serverSchema.shape[key].meta()?.kind !== "config")
199
+ .map((key) => parsed.data[key]),
200
+ )
201
+ }
202
+ return _env
203
+ }
204
+ ```
205
+ {{else}}
206
+ ```ts
207
+ import { registerSecretValues } from "@quatronic/sdk/node/sentry"
208
+
209
+ export const env = schema.parse(raw)
210
+
211
+ registerSecretValues(
212
+ (Object.keys(schema.shape) as (keyof typeof env)[])
213
+ .filter((key) => schema.shape[key].meta()?.kind !== "config")
214
+ .map((key) => env[key]),
215
+ )
216
+ ```
217
+ {{/if}}
218
+
219
+ ## Don't
220
+
221
+ - **Don't** put a real value{{#if runtime=next}} in `.env.example`,{{/if}} in code, or in a log line.
222
+ - **Don't** label a login's identifier config to "tidy" the portal.
@@ -11,7 +11,7 @@ REST or OData API, a SOAP endpoint, a partner's GraphQL. It is declared once in
11
11
  `src/config/integrations.ts`, and that declaration is what the portal reads to
12
12
  show the app's Integrations tab — which systems the app talks to, under which
13
13
  env keys, with a Probe button per environment. The values (base URL, credentials)
14
- are never in code: they live in the portal's Secrets tab and reach the app as
14
+ are never in code: they live in the portal's Variables tab and reach the app as
15
15
  env, exactly like every other secret.
16
16
 
17
17
  **Integration vs connection.** A *connection* (`/qore-add-connection`) is
@@ -90,17 +90,24 @@ 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
+
106
+ How to declare, mark and check a key: `/qore-add-env-key`.
107
+
101
108
  Add the same keys to `.env.example` with a blank value (never a real one), so
102
109
  a colleague's `pnpm bootstrap` knows what to ask the portal for. Then set the
103
- values per environment in the portal's Secrets tab; the Integrations tab shows
110
+ values per environment in the portal's Variables tab; the Integrations tab shows
104
111
  which keys are still unset.
105
112
 
106
113
  ## 3. Startup warnings (already wired)
@@ -197,9 +204,10 @@ per call (`qore.integration.call`: alias, method, template, status, duration).
197
204
  declaration; the client refuses `http(s)://…` paths (`absolute_url`), which is
198
205
  what keeps a path parameter from redirecting a call to another host.
199
206
  - **Don't put a credential in `config`, in `.env.example`, or in a log line.**
200
- `apiKey` / `token` / `password` / `clientSecret` are the secret fields; the
201
- SDK never logs them and neither should you. A failed call's span and
202
- error carry no secret, so reporting one is safe; whether to report it at all
207
+ `apiKey` / `token` / `username` / `password` / `clientId` / `clientSecret`
208
+ are the secret fields; the SDK never logs them and neither should you. A
209
+ failed call's span and error carry no secret, so reporting one is safe;
210
+ whether to report it at all
203
211
  follows /qore-observability (unexpected: let it throw; expected: no capture).
204
212
  - **Don't bypass `env.ts`.** Reading `process.env.SAP_BASE_URL` directly skips
205
213
  validation and leaves `qore env pull` unaware of the key.
@@ -11,7 +11,7 @@ vendor REST or OData API, a SOAP endpoint, a partner's GraphQL. It is declared
11
11
  once in `src/config/integrations.ts`, and that declaration is what the portal
12
12
  reads to show the app's Integrations tab — which systems the module talks to,
13
13
  under which env keys, with a Probe button per environment. The values (base
14
- URL, credentials) are never in code: they live in the portal's Secrets tab and
14
+ URL, credentials) are never in code: they live in the portal's Variables tab and
15
15
  reach the service as env, exactly like every other secret.
16
16
 
17
17
  **Integration vs connection.** A *connection* (`/qore-add-connection`) is
@@ -78,7 +78,7 @@ Rules for the keys:
78
78
  **and every call site** statically, and skips anything it cannot read as a
79
79
  literal (step 4 says what that means for a call).
80
80
 
81
- ## 2. Declare the env in `src/config/env.ts` and `.env.example`
81
+ ## 2. Declare the env in `src/config/env.ts`
82
82
 
83
83
  The zod schema is the one list of env this service reads — an integration key
84
84
  that is not in it is invisible to `env` and to `qore env pull`. Add every key
@@ -90,17 +90,22 @@ 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
- Add the same keys to `.env.example` with a blank value (never a real one), so
102
- a colleague's `pnpm bootstrap` knows what to ask the portal for. Then set the
103
- values per environment in the portal's Secrets tab; the Integrations tab shows
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
+
106
+ How to declare, mark and check a key: `/qore-add-env-key`.
107
+
108
+ Set the values per environment in the portal's Variables tab; the Integrations tab shows
104
109
  which keys are still unset.
105
110
 
106
111
  ## 3. Startup warnings (already wired)
@@ -196,10 +201,11 @@ per call (`qore.integration.call`: alias, method, template, status, duration).
196
201
  - **Don't pass an absolute URL to `.get`/`.post`.** The base URL belongs to the
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
- - **Don't put a credential in `config`, in `.env.example`, or in a log line.**
200
- `apiKey` / `token` / `password` / `clientSecret` are the secret fields; the
201
- SDK never logs them and neither should you. A failed call's span and
202
- error carry no secret, so reporting one is safe; whether to report it at all
204
+ - **Don't put a credential in `config` or in a log line.**
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 Variables 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 |
@@ -49,6 +49,8 @@ Add the keys for the addons you use to the server schema in
49
49
  `DATABASE_URL` is already declared when this app was generated with a database.
50
50
  Add the others only for the addons you actually provisioned.
51
51
 
52
+ How to declare, mark and check a key: `/qore-add-env-key`.
53
+
52
54
  ## 2. Postgres — use the existing client
53
55
 
54
56
  {{#if db}}The database client already reads `DATABASE_URL` for you. Don't build a new
@@ -15,6 +15,8 @@ skill is the whole contract.
15
15
  `src/config/env.ts` requires `DATABASE_URL` (`z.string().min(1)`), so the service
16
16
  refuses to boot without it.
17
17
 
18
+ How to declare, mark and check a key: `/qore-add-env-key`.
19
+
18
20
  | Where | How it arrives |
19
21
  |-------|----------------|
20
22
  | **Local** | `pnpm bootstrap` (or `qore env pull`) fetches it from the portal into `.env`. It points at the docker-compose database below on this module's own port: `postgresql://postgres:postgres@localhost:<DB_PORT>/app`, with `DB_PORT` written alongside it |
@@ -18,7 +18,7 @@ environments:
18
18
  | `MAIL_FROM` | the full from-header, e.g. `Acme Support <support@acme.nl>` |
19
19
 
20
20
  > These are system-managed: they never appear in `.env.example`, never show up
21
- > in this module's Secrets tab, and you cannot set them yourself. Until a
21
+ > in this module's Variables tab, and you cannot set them yourself. Until a
22
22
  > domain is linked they're simply absent.
23
23
 
24
24
  ## Hard rule: never present in `local` or preview
@@ -17,8 +17,8 @@ environments:
17
17
  | `MAIL_SENDING_DOMAIN` | the domain, e.g. `acme.nl` — informational only, already baked into `MAIL_FROM` |
18
18
  | `MAIL_FROM` | the full from-header, e.g. `Acme Support <support@acme.nl>` |
19
19
 
20
- > These are system-managed: they never appear in `.env.example`, never show up
21
- > in this module's Secrets tab, and you cannot set them yourself. Until a
20
+ > These are system-managed: they never show up
21
+ > in this module's Variables tab, and you cannot set them yourself. Until a
22
22
  > domain is linked they're simply absent.
23
23
 
24
24
  ## Hard rule: never present in `local` or preview
@@ -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,CAAC,QAAuB,OAAO,QAAQ,YAAY,QAAQ,EAAE;AACzE;AAOO,SAAS,aAAa,KAAsC;AACjE,QAAM,OAAO,CAAC,IAAI,SAAS,GAAG,SAAS,GAAG,CAAC;AAC3C,aAAW,OAAO,OAAO,OAAO,IAAI,UAAU,CAAC,CAAC,GAAG;AACjD,QAAI,CAAC,YAAY,GAAG,EAAG,MAAK,KAAK,OAAO,GAAG,CAAC;AAAA,EAC9C;AACA,SAAO,CAAC,GAAG,IAAI,IAAI,IAAI,CAAC;AAC1B;AA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