@quatronic/sdk 0.11.0-rc.1 → 0.11.0-test.71f8765
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-BJN7YE63.js +46 -0
- package/dist/chunk-BJN7YE63.js.map +1 -0
- package/dist/{chunk-YCKDMG4B.js → chunk-GYUIIM5X.js} +6 -45
- package/dist/chunk-GYUIIM5X.js.map +1 -0
- package/dist/chunk-S7TJQVXV.js +34 -0
- package/dist/chunk-S7TJQVXV.js.map +1 -0
- package/dist/cli/skills-postinstall.js +1 -1
- package/dist/cli/skills.js +1 -1
- package/dist/next/auth/index.js +2 -1
- package/dist/next/auth/index.js.map +1 -1
- package/dist/next/db/index.d.ts +3 -27
- package/dist/next/db/index.js +11 -30
- package/dist/next/db/index.js.map +1 -1
- package/dist/node/db/migrate/index.d.ts +28 -0
- package/dist/node/db/migrate/index.js +16 -0
- package/dist/node/db/migrate/index.js.map +1 -0
- package/package.json +5 -1
- package/skills/catalog.json +1 -1
- package/skills/qore-add-connection/SKILL.next.md +3 -1
- package/skills/qore-add-connection/SKILL.node.md +3 -1
- package/skills/qore-add-env-key/SKILL.md +174 -9
- package/skills/qore-add-integration/SKILL.next.md +4 -2
- package/skills/qore-add-integration/SKILL.node.md +6 -6
- package/skills/qore-author-skill/SKILL.md +1 -1
- package/skills/qore-use-addons/SKILL.md +2 -0
- package/skills/qore-use-database/SKILL.md +164 -145
- package/skills/qore-use-mail-domain/SKILL.next.md +1 -1
- package/skills/qore-use-mail-domain/SKILL.node.md +2 -2
- package/dist/chunk-YCKDMG4B.js.map +0 -1
package/dist/next/db/index.d.ts
CHANGED
|
@@ -1,30 +1,6 @@
|
|
|
1
1
|
export { PostgresConnectionConfig, PostgresSslConfig, isNorthflankManagedPostgres, resolvePostgresConfig } from '../../node/db/index.js';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
interface MigrationDb {
|
|
5
|
-
readonly db: NodePgDatabase;
|
|
6
|
-
readonly close: () => Promise<void>;
|
|
7
|
-
}
|
|
8
|
-
declare function createMigrationDb(databaseUrl: string): MigrationDb;
|
|
9
|
-
declare function parseRoleFromUrl(databaseUrl: string): string;
|
|
10
|
-
declare function grantRuntimeDefaultPrivileges(db: NodePgDatabase, schema: string, runtimeRole: string): Promise<void>;
|
|
11
|
-
|
|
12
|
-
interface MigrateAppOptions {
|
|
13
|
-
/** The Postgres schema the app's tables live in (`appSchema.schemaName`, or `"public"`). */
|
|
14
|
-
schema: string;
|
|
15
|
-
/** Defaults to `<cwd>/src/db/migrations`, where `pnpm db:generate` writes. */
|
|
16
|
-
migrationsFolder?: string;
|
|
17
|
-
/** The runtime role's DSN. Defaults to `DATABASE_URL`. */
|
|
18
|
-
databaseUrl?: string;
|
|
19
|
-
/** The migrator role's DSN. Defaults to `MIGRATION_DATABASE_URL`. */
|
|
20
|
-
migrationDatabaseUrl?: string;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Applies the app's drizzle-kit migrations as the migrator role, then grants
|
|
24
|
-
* the runtime role access to what they created. Safe on every boot: drizzle
|
|
25
|
-
* skips applied migrations and the grant is a no-op when both roles are one.
|
|
26
|
-
*/
|
|
27
|
-
declare function migrateApp(options: MigrateAppOptions): Promise<void>;
|
|
2
|
+
export { MigrateAppOptions, MigrationDb, createMigrationDb, grantRuntimeDefaultPrivileges, migrateApp, parseRoleFromUrl } from '../../node/db/migrate/index.js';
|
|
3
|
+
import 'drizzle-orm/node-postgres';
|
|
28
4
|
|
|
29
5
|
/**
|
|
30
6
|
* The SDK's own auth-schema migrations (Keycloak apps), run as the migration
|
|
@@ -35,4 +11,4 @@ declare function migrateApp(options: MigrateAppOptions): Promise<void>;
|
|
|
35
11
|
*/
|
|
36
12
|
declare function runQoreAuthMigrations(): Promise<void>;
|
|
37
13
|
|
|
38
|
-
export {
|
|
14
|
+
export { runQoreAuthMigrations };
|
package/dist/next/db/index.js
CHANGED
|
@@ -1,48 +1,29 @@
|
|
|
1
|
+
import {
|
|
2
|
+
migrateApp
|
|
3
|
+
} from "../../chunk-S7TJQVXV.js";
|
|
4
|
+
import {
|
|
5
|
+
runAuthMigrations
|
|
6
|
+
} from "../../chunk-GYUIIM5X.js";
|
|
1
7
|
import {
|
|
2
8
|
createMigrationDb,
|
|
3
9
|
grantRuntimeDefaultPrivileges,
|
|
4
|
-
parseRoleFromUrl
|
|
5
|
-
|
|
6
|
-
} from "../../chunk-YCKDMG4B.js";
|
|
10
|
+
parseRoleFromUrl
|
|
11
|
+
} from "../../chunk-BJN7YE63.js";
|
|
7
12
|
import {
|
|
8
13
|
isNorthflankManagedPostgres,
|
|
9
14
|
resolvePostgresConfig
|
|
10
15
|
} from "../../chunk-4MBB2UQW.js";
|
|
11
16
|
|
|
12
|
-
// src/db-core/migrate-app.ts
|
|
13
|
-
import { join } from "path";
|
|
14
|
-
import { migrate } from "drizzle-orm/node-postgres/migrator";
|
|
15
|
-
function required(value, key) {
|
|
16
|
-
if (!value) throw new Error(`migrateApp: ${key} is required`);
|
|
17
|
-
return value;
|
|
18
|
-
}
|
|
19
|
-
async function migrateApp(options) {
|
|
20
|
-
const databaseUrl = required(options.databaseUrl ?? process.env.DATABASE_URL, "DATABASE_URL");
|
|
21
|
-
const migrationUrl = required(
|
|
22
|
-
options.migrationDatabaseUrl ?? process.env.MIGRATION_DATABASE_URL,
|
|
23
|
-
"MIGRATION_DATABASE_URL"
|
|
24
|
-
);
|
|
25
|
-
const { db, close } = createMigrationDb(migrationUrl);
|
|
26
|
-
try {
|
|
27
|
-
await migrate(db, {
|
|
28
|
-
migrationsFolder: options.migrationsFolder ?? join(process.cwd(), "src/db/migrations")
|
|
29
|
-
});
|
|
30
|
-
await grantRuntimeDefaultPrivileges(db, options.schema, parseRoleFromUrl(databaseUrl));
|
|
31
|
-
} finally {
|
|
32
|
-
await close();
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
17
|
// src/next/db/auth-migrations.ts
|
|
37
|
-
function
|
|
18
|
+
function required(key) {
|
|
38
19
|
const value = process.env[key];
|
|
39
20
|
if (!value) throw new Error(`qoreRegister: ${key} is required`);
|
|
40
21
|
return value;
|
|
41
22
|
}
|
|
42
23
|
async function runQoreAuthMigrations() {
|
|
43
|
-
const { db, close } = createMigrationDb(
|
|
24
|
+
const { db, close } = createMigrationDb(required("MIGRATION_DATABASE_URL"));
|
|
44
25
|
try {
|
|
45
|
-
await runAuthMigrations(db, { runtimeRole: parseRoleFromUrl(
|
|
26
|
+
await runAuthMigrations(db, { runtimeRole: parseRoleFromUrl(required("DATABASE_URL")) });
|
|
46
27
|
} finally {
|
|
47
28
|
await close();
|
|
48
29
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/
|
|
1
|
+
{"version":3,"sources":["../../../src/next/db/auth-migrations.ts"],"sourcesContent":["import { runAuthMigrations } from \"../../auth-core/migrate\"\nimport { createMigrationDb, parseRoleFromUrl } from \"../../db-core/migration-db\"\n\nfunction required(key: string): string {\n const value = process.env[key]\n if (!value) throw new Error(`qoreRegister: ${key} is required`)\n return value\n}\n\n/**\n * The SDK's own auth-schema migrations (Keycloak apps), run as the migration\n * role from `MIGRATION_DATABASE_URL`, granting the runtime role from\n * `DATABASE_URL`. `qoreRegister` calls it through\n * `authMigrations: () => import(\"@quatronic/sdk/next/db\")`, so an app without a\n * database never bundles pg or drizzle.\n */\nexport async function runQoreAuthMigrations(): Promise<void> {\n const { db, close } = createMigrationDb(required(\"MIGRATION_DATABASE_URL\"))\n try {\n await runAuthMigrations(db, { runtimeRole: parseRoleFromUrl(required(\"DATABASE_URL\")) })\n } finally {\n await close()\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAGA,SAAS,SAAS,KAAqB;AACrC,QAAM,QAAQ,QAAQ,IAAI,GAAG;AAC7B,MAAI,CAAC,MAAO,OAAM,IAAI,MAAM,iBAAiB,GAAG,cAAc;AAC9D,SAAO;AACT;AASA,eAAsB,wBAAuC;AAC3D,QAAM,EAAE,IAAI,MAAM,IAAI,kBAAkB,SAAS,wBAAwB,CAAC;AAC1E,MAAI;AACF,UAAM,kBAAkB,IAAI,EAAE,aAAa,iBAAiB,SAAS,cAAc,CAAC,EAAE,CAAC;AAAA,EACzF,UAAE;AACA,UAAM,MAAM;AAAA,EACd;AACF;","names":[]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { NodePgDatabase } from 'drizzle-orm/node-postgres';
|
|
2
|
+
|
|
3
|
+
interface MigrationDb {
|
|
4
|
+
readonly db: NodePgDatabase;
|
|
5
|
+
readonly close: () => Promise<void>;
|
|
6
|
+
}
|
|
7
|
+
declare function createMigrationDb(databaseUrl: string): MigrationDb;
|
|
8
|
+
declare function parseRoleFromUrl(databaseUrl: string): string;
|
|
9
|
+
declare function grantRuntimeDefaultPrivileges(db: NodePgDatabase, schema: string, runtimeRole: string): Promise<void>;
|
|
10
|
+
|
|
11
|
+
interface MigrateAppOptions {
|
|
12
|
+
/** The Postgres schema the app's tables live in (`appSchema.schemaName`, or `"public"`). */
|
|
13
|
+
schema: string;
|
|
14
|
+
/** Defaults to `<cwd>/src/db/migrations`, where `pnpm db:generate` writes. */
|
|
15
|
+
migrationsFolder?: string;
|
|
16
|
+
/** The runtime role's DSN. Defaults to `DATABASE_URL`. */
|
|
17
|
+
databaseUrl?: string;
|
|
18
|
+
/** The migrator role's DSN. Defaults to `MIGRATION_DATABASE_URL`. */
|
|
19
|
+
migrationDatabaseUrl?: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Applies the app's drizzle-kit migrations as the migrator role, then grants
|
|
23
|
+
* the runtime role access to what they created. Safe on every boot: drizzle
|
|
24
|
+
* skips applied migrations and the grant is a no-op when both roles are one.
|
|
25
|
+
*/
|
|
26
|
+
declare function migrateApp(options: MigrateAppOptions): Promise<void>;
|
|
27
|
+
|
|
28
|
+
export { type MigrateAppOptions, type MigrationDb, createMigrationDb, grantRuntimeDefaultPrivileges, migrateApp, parseRoleFromUrl };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import {
|
|
2
|
+
migrateApp
|
|
3
|
+
} from "../../../chunk-S7TJQVXV.js";
|
|
4
|
+
import {
|
|
5
|
+
createMigrationDb,
|
|
6
|
+
grantRuntimeDefaultPrivileges,
|
|
7
|
+
parseRoleFromUrl
|
|
8
|
+
} from "../../../chunk-BJN7YE63.js";
|
|
9
|
+
import "../../../chunk-4MBB2UQW.js";
|
|
10
|
+
export {
|
|
11
|
+
createMigrationDb,
|
|
12
|
+
grantRuntimeDefaultPrivileges,
|
|
13
|
+
migrateApp,
|
|
14
|
+
parseRoleFromUrl
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quatronic/sdk",
|
|
3
|
-
"version": "0.11.0-
|
|
3
|
+
"version": "0.11.0-test.71f8765",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"private": false,
|
|
6
6
|
"publishConfig": {
|
|
@@ -124,6 +124,10 @@
|
|
|
124
124
|
"types": "./dist/node/db/index.d.ts",
|
|
125
125
|
"import": "./dist/node/db/index.js"
|
|
126
126
|
},
|
|
127
|
+
"./node/db/migrate": {
|
|
128
|
+
"types": "./dist/node/db/migrate/index.d.ts",
|
|
129
|
+
"import": "./dist/node/db/migrate/index.js"
|
|
130
|
+
},
|
|
127
131
|
"./next/db": {
|
|
128
132
|
"types": "./dist/next/db/index.d.ts",
|
|
129
133
|
"import": "./dist/next/db/index.js"
|
package/skills/catalog.json
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
{"name": "qore-ship-checklist", "kind": "convenience", "requires": ["runtime=next"], "legacyNames": ["quatronic-ship-checklist"]},
|
|
20
20
|
{"name": "qore-translate-strings", "kind": "convenience", "requires": ["runtime=next"], "legacyNames": ["quatronic-translate-strings"]},
|
|
21
21
|
{"name": "qore-use-addons", "kind": "convenience", "requires": ["runtime=next"], "legacyNames": ["quatronic-use-addons"]},
|
|
22
|
-
{"name": "qore-use-database", "kind": "contract", "requires": ["runtime=node"
|
|
22
|
+
{"name": "qore-use-database", "kind": "contract", "requires": ["runtime=node"], "legacyNames": ["quatronic-use-database"]},
|
|
23
23
|
{"name": "qore-use-design-system", "kind": "convenience", "requires": ["runtime=next"], "legacyNames": ["quatronic-use-design-system"]},
|
|
24
24
|
{"name": "qore-use-mail-domain", "kind": "convenience", "legacyNames": ["quatronic-use-mail-domain"]},
|
|
25
25
|
{"name": "qore-use-permissions", "kind": "contract", "requires": ["auth=keycloak"], "legacyNames": ["quatronic-use-permissions"]},
|
|
@@ -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
|
-
>
|
|
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
|
-
>
|
|
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
|
|
@@ -1,23 +1,74 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: qore-add-env-key
|
|
3
|
-
description:
|
|
4
|
-
allowed-tools: Edit, Read
|
|
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
5
|
---
|
|
6
6
|
|
|
7
|
-
#
|
|
7
|
+
# Settings and secrets
|
|
8
8
|
|
|
9
9
|
`src/config/env.ts` is the one list of env this app reads. The manifest
|
|
10
10
|
extractor reads it on every deploy and sends the portal each key's **name**
|
|
11
|
-
(never its value), whether it is optional,
|
|
12
|
-
configuration. Values are set per environment in the
|
|
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 |
|
|
13
24
|
|
|
14
25
|
## 1. Declare it
|
|
15
26
|
|
|
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
|
|
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
|
|
18
29
|
key required only when the app cannot work without it; otherwise add
|
|
19
30
|
`.optional()`.
|
|
20
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
|
+
|
|
21
72
|
## 2. Secret or configuration?
|
|
22
73
|
|
|
23
74
|
Every key is a **secret** unless you label it configuration:
|
|
@@ -30,7 +81,7 @@ Every key is a **secret** unless you label it configuration:
|
|
|
30
81
|
```
|
|
31
82
|
|
|
32
83
|
The label decides two things in the portal: where a person looks for the key
|
|
33
|
-
(
|
|
84
|
+
(the secret or the configuration list), and whether it is governed as a secret (age,
|
|
34
85
|
rotation reminders, findings). So judge a key by what it belongs to, not only
|
|
35
86
|
by what leaking it would cost.
|
|
36
87
|
|
|
@@ -52,6 +103,120 @@ environment's `env.ts` labels it so. An integration's credential fields
|
|
|
52
103
|
/qore-add-integration) are always shown as secrets on the Integrations tab,
|
|
53
104
|
whatever the label says, so never label one of them config.
|
|
54
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
|
+
|
|
55
219
|
## Don't
|
|
56
220
|
|
|
57
|
-
- **Don't** put a real value in `.env.example`, in code, or in a log line.
|
|
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
|
|
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
|
|
@@ -103,9 +103,11 @@ URLs, codes and timeouts are configuration, so they carry
|
|
|
103
103
|
the client secret, because it belongs to the same login. /qore-add-env-key has
|
|
104
104
|
the rule; in doubt, ask the user.
|
|
105
105
|
|
|
106
|
+
How to declare, mark and check a key: `/qore-add-env-key`.
|
|
107
|
+
|
|
106
108
|
Add the same keys to `.env.example` with a blank value (never a real one), so
|
|
107
109
|
a colleague's `pnpm bootstrap` knows what to ask the portal for. Then set the
|
|
108
|
-
values per environment in the portal's
|
|
110
|
+
values per environment in the portal's Variables tab; the Integrations tab shows
|
|
109
111
|
which keys are still unset.
|
|
110
112
|
|
|
111
113
|
## 3. Startup warnings (already wired)
|
|
@@ -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
|
|
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`
|
|
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
|
|
@@ -103,9 +103,9 @@ URLs, codes and timeouts are configuration, so they carry
|
|
|
103
103
|
the client secret, because it belongs to the same login. /qore-add-env-key has
|
|
104
104
|
the rule; in doubt, ask the user.
|
|
105
105
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
values per environment in the portal's
|
|
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
|
|
109
109
|
which keys are still unset.
|
|
110
110
|
|
|
111
111
|
## 3. Startup warnings (already wired)
|
|
@@ -201,7 +201,7 @@ per call (`qore.integration.call`: alias, method, template, status, duration).
|
|
|
201
201
|
- **Don't pass an absolute URL to `.get`/`.post`.** The base URL belongs to the
|
|
202
202
|
declaration; the client refuses `http(s)://…` paths (`absolute_url`), which is
|
|
203
203
|
what keeps a path parameter from redirecting a call to another host.
|
|
204
|
-
- **Don't put a credential in `config
|
|
204
|
+
- **Don't put a credential in `config` or in a log line.**
|
|
205
205
|
`apiKey` / `token` / `username` / `password` / `clientId` / `clientSecret`
|
|
206
206
|
are the secret fields; the SDK never logs them and neither should you. A
|
|
207
207
|
failed call's span and error carry no secret, so reporting one is safe;
|
|
@@ -40,7 +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
|
|
43
|
+
| `qore-add-env-key` | The Variables tab: which keys are secrets, which configuration |
|
|
44
44
|
| `qore-add-integration` | The Integrations tab |
|
|
45
45
|
| `qore-add-connection` | Connection wiring |
|
|
46
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
|