@venturekit/cli 0.0.0-dev.20260429204013 → 0.0.0-dev.20260430161503
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/commands/dev.d.ts.map +1 -1
- package/dist/commands/dev.js +68 -1
- package/dist/commands/dev.js.map +1 -1
- package/dist/utils/cognito-local.d.ts +86 -0
- package/dist/utils/cognito-local.d.ts.map +1 -0
- package/dist/utils/cognito-local.js +284 -0
- package/dist/utils/cognito-local.js.map +1 -0
- package/dist/utils/docker-compose.d.ts +5 -0
- package/dist/utils/docker-compose.d.ts.map +1 -1
- package/dist/utils/docker-compose.js +72 -1
- package/dist/utils/docker-compose.js.map +1 -1
- package/dist/utils/local-server.d.ts +68 -0
- package/dist/utils/local-server.d.ts.map +1 -1
- package/dist/utils/local-server.js +135 -27
- package/dist/utils/local-server.js.map +1 -1
- package/package.json +5 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dev.d.ts","sourceRoot":"","sources":["../../src/commands/dev.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"dev.d.ts","sourceRoot":"","sources":["../../src/commands/dev.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AA0DpC,wBAAgB,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CA8IjD"}
|
package/dist/commands/dev.js
CHANGED
|
@@ -9,11 +9,34 @@ import chalk from 'chalk';
|
|
|
9
9
|
import { execSync } from 'child_process';
|
|
10
10
|
import { existsSync, mkdirSync } from 'fs';
|
|
11
11
|
import { join, resolve } from 'path';
|
|
12
|
+
import { config as loadDotenv } from 'dotenv';
|
|
13
|
+
import { resolveEnvConfig } from '@venturekit/core';
|
|
12
14
|
import { startLocalServer } from '../utils/local-server.js';
|
|
13
15
|
import { ensureDockerCompose } from '../utils/docker-compose.js';
|
|
14
16
|
import { ensureDockerServicesRunning } from '../utils/docker.js';
|
|
15
17
|
import { loadVentureConfig } from '../utils/config-loader.js';
|
|
16
18
|
import { ensureDependencies } from '../utils/auto-deps.js';
|
|
19
|
+
import { provisionCognitoLocal } from '../utils/cognito-local.js';
|
|
20
|
+
/**
|
|
21
|
+
* Load `.env` then `.env.local` from `cwd` (later wins). Both files are
|
|
22
|
+
* optional — missing files are silently ignored. Matches `vk migrate`'s
|
|
23
|
+
* behavior and the convention used by Next.js / Vite.
|
|
24
|
+
*
|
|
25
|
+
* Loading happens BEFORE `loadVentureConfig` so vk.config.ts can read
|
|
26
|
+
* `process.env.*` at evaluation time, and BEFORE `startLocalServer` so
|
|
27
|
+
* route handlers see the same environment a deployed Lambda would (e.g.
|
|
28
|
+
* `COGNITO_USER_POOL_ID` for `@venturekit/auth/server`).
|
|
29
|
+
*/
|
|
30
|
+
function loadEnvFiles(cwd) {
|
|
31
|
+
const envPath = join(cwd, '.env');
|
|
32
|
+
const localPath = join(cwd, '.env.local');
|
|
33
|
+
if (existsSync(envPath)) {
|
|
34
|
+
loadDotenv({ path: envPath });
|
|
35
|
+
}
|
|
36
|
+
if (existsSync(localPath)) {
|
|
37
|
+
loadDotenv({ path: localPath, override: true });
|
|
38
|
+
}
|
|
39
|
+
}
|
|
17
40
|
/**
|
|
18
41
|
* Detect package manager and run install.
|
|
19
42
|
*/
|
|
@@ -48,6 +71,11 @@ export function devCommand(program) {
|
|
|
48
71
|
console.error(chalk.gray(' Run `vk init <name>` to create a new project\n'));
|
|
49
72
|
process.exit(1);
|
|
50
73
|
}
|
|
74
|
+
// Load `.env` then `.env.local` (later wins) BEFORE config loads —
|
|
75
|
+
// mirrors `vk migrate`. This lets vk.config.ts read process.env at
|
|
76
|
+
// evaluation time, and ensures route handlers see env vars they
|
|
77
|
+
// would normally get from the deployed Lambda (`COGNITO_*` etc.).
|
|
78
|
+
loadEnvFiles(projectDir);
|
|
51
79
|
// Ensure dependencies are installed before loading config
|
|
52
80
|
if (!existsSync(join(projectDir, 'node_modules'))) {
|
|
53
81
|
console.log(chalk.blue('\n📦 Installing dependencies...\n'));
|
|
@@ -80,11 +108,39 @@ export function devCommand(program) {
|
|
|
80
108
|
if (docker.hasServices && docker.composePath) {
|
|
81
109
|
ensureDockerServicesRunning();
|
|
82
110
|
}
|
|
111
|
+
// Provision the cognito-local user pool + app client (or reuse a
|
|
112
|
+
// cached one) when an `auth` intent is declared. Skipped when the
|
|
113
|
+
// user has already set both COGNITO_USER_POOL_ID + COGNITO_APP_CLIENT_ID
|
|
114
|
+
// in their shell env (e.g. via .env.local pointing at a real pool).
|
|
115
|
+
const authIntents = (config.infrastructure?.auth ?? []);
|
|
116
|
+
const cognitoLocal = await provisionCognitoLocal(config.name, authIntents, stage);
|
|
117
|
+
if (!cognitoLocal.skipped && Object.keys(cognitoLocal.envVars).length > 0) {
|
|
118
|
+
const intentIds = Object.keys(cognitoLocal.pools).join(', ');
|
|
119
|
+
console.log(chalk.gray(' ✓ cognito-local provisioned: ') +
|
|
120
|
+
chalk.cyan(intentIds) +
|
|
121
|
+
chalk.gray(' (state: ~/.vk/cognito-local-state.json)\n'));
|
|
122
|
+
}
|
|
83
123
|
// Resolve directories
|
|
84
124
|
const routesDir = resolve(projectDir, config.routesDir);
|
|
85
125
|
const functionsDir = resolve(projectDir, config.functionsDir);
|
|
86
126
|
const queuesDir = resolve(projectDir, config.queuesDir);
|
|
87
127
|
const cronsDir = resolve(projectDir, config.cronsDir);
|
|
128
|
+
// Resolve env config for the current stage so the local dev server
|
|
129
|
+
// can honor `api.cors` (allowOrigins, allowCredentials, etc.). Stage
|
|
130
|
+
// mapping mirrors cdk-bridge.ts: anything other than 'prod' or 'stage'
|
|
131
|
+
// (e.g. the default 'local') resolves the 'dev' env block.
|
|
132
|
+
const envKey = (stage === 'prod' ? 'prod' : stage === 'stage' ? 'stage' : 'dev');
|
|
133
|
+
const envInput = config.definition?.envs?.[envKey] ?? config.definition?.envs?.[stage] ?? { preset: config.preset };
|
|
134
|
+
const resolvedEnvConfig = resolveEnvConfig(envKey, envInput ?? { preset: config.preset ?? 'micro' });
|
|
135
|
+
const corsConfig = resolvedEnvConfig.api?.cors
|
|
136
|
+
? {
|
|
137
|
+
allowOrigins: resolvedEnvConfig.api.cors.allowOrigins,
|
|
138
|
+
allowMethods: resolvedEnvConfig.api.cors.allowMethods,
|
|
139
|
+
allowHeaders: resolvedEnvConfig.api.cors.allowHeaders,
|
|
140
|
+
allowCredentials: resolvedEnvConfig.api.cors.allowCredentials,
|
|
141
|
+
maxAgeSec: resolvedEnvConfig.api.cors.maxAgeSec,
|
|
142
|
+
}
|
|
143
|
+
: undefined;
|
|
88
144
|
// Start the local HTTP server
|
|
89
145
|
try {
|
|
90
146
|
await startLocalServer({
|
|
@@ -95,8 +151,19 @@ export function devCommand(program) {
|
|
|
95
151
|
port,
|
|
96
152
|
projectName: config.name,
|
|
97
153
|
stage,
|
|
98
|
-
|
|
154
|
+
// Layering (later wins on collision):
|
|
155
|
+
// 1. docker.envVars — DB / S3 / Redis / cognito endpoint+region
|
|
156
|
+
// 2. cognitoLocal.envVars — auto-provisioned pool + client IDs
|
|
157
|
+
// 3. VENTURE_* — runtime markers
|
|
158
|
+
env: {
|
|
159
|
+
...docker.envVars,
|
|
160
|
+
...cognitoLocal.envVars,
|
|
161
|
+
VENTURE_PROJECT_NAME: config.name,
|
|
162
|
+
VENTURE_LOCAL: 'true',
|
|
163
|
+
VENTURE_LOCAL_PORT: String(port),
|
|
164
|
+
},
|
|
99
165
|
watch: options.watch !== false,
|
|
166
|
+
cors: corsConfig,
|
|
100
167
|
});
|
|
101
168
|
}
|
|
102
169
|
catch (err) {
|
package/dist/commands/dev.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dev.js","sourceRoot":"","sources":["../../src/commands/dev.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KA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` is a Docker image that emulates the Cognito
|
|
5
|
+
* User-Pool API on the standard Cognito SDK over plain HTTP. We start
|
|
6
|
+
* the container from `~/.vk/docker-compose.yml` (see
|
|
7
|
+
* `docker-compose.ts:needsCognito`); this file handles the runtime
|
|
8
|
+
* provisioning step that creates the user pool + app client inside the
|
|
9
|
+
* running mock and writes the resulting IDs into the local dev server's
|
|
10
|
+
* env.
|
|
11
|
+
*
|
|
12
|
+
* Provisioned IDs are cached in `~/.vk/cognito-local-state.json`, keyed
|
|
13
|
+
* by `(projectName, intent.id)`, so subsequent `vk dev` runs reuse the
|
|
14
|
+
* same pool. If `docker compose down -v` wipes the cognito-local volume,
|
|
15
|
+
* the cached IDs become stale — the next call detects "pool not found"
|
|
16
|
+
* and recreates a fresh pool transparently.
|
|
17
|
+
*
|
|
18
|
+
* Honors a user-provided override: when both `COGNITO_USER_POOL_ID` and
|
|
19
|
+
* `COGNITO_APP_CLIENT_ID` are present in the shell env (typically via
|
|
20
|
+
* `.env.local`), provisioning is SKIPPED and the user-supplied values
|
|
21
|
+
* win — letting consumers point local dev at a real Cognito pool when
|
|
22
|
+
* they prefer that over the in-docker mock.
|
|
23
|
+
*/
|
|
24
|
+
/** Default cognito-local URL, matches docker-compose.ts. */
|
|
25
|
+
export declare const COGNITO_LOCAL_ENDPOINT = "http://localhost:9229";
|
|
26
|
+
/** Region label used everywhere local — cognito-local doesn't care. */
|
|
27
|
+
export declare const COGNITO_LOCAL_REGION = "local";
|
|
28
|
+
/**
|
|
29
|
+
* The subset of `AuthIntent` fields this module reads. Kept minimal so
|
|
30
|
+
* the `vk.config.ts` definition can change without forcing a CLI bump.
|
|
31
|
+
*/
|
|
32
|
+
export interface ProvisionAuthIntent {
|
|
33
|
+
id: string;
|
|
34
|
+
signInWith?: Array<'email' | 'phone' | 'username'>;
|
|
35
|
+
allowSignUp?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Custom user attribute names (without the `custom:` prefix) to
|
|
38
|
+
* declare on the local pool's Schema, mirroring the production CDK
|
|
39
|
+
* stack. Required if your app code reads claims like
|
|
40
|
+
* `custom:tenantId` — without this, cognito-local rejects every
|
|
41
|
+
* `admin-update-user-attributes` with `InvalidParameterException:
|
|
42
|
+
* Attribute does not exist in the schema`.
|
|
43
|
+
*/
|
|
44
|
+
customAttributes?: string[];
|
|
45
|
+
}
|
|
46
|
+
interface PoolState {
|
|
47
|
+
userPoolId: string;
|
|
48
|
+
clientId: string;
|
|
49
|
+
}
|
|
50
|
+
export interface ProvisionResult {
|
|
51
|
+
/** Env vars to merge into the local dev server's process.env. */
|
|
52
|
+
envVars: Record<string, string>;
|
|
53
|
+
/** Whether provisioning was skipped (user provided their own COGNITO_*). */
|
|
54
|
+
skipped: boolean;
|
|
55
|
+
/** Pool/client IDs per intent.id, for downstream tooling (seed scripts, etc.). */
|
|
56
|
+
pools: Record<string, PoolState>;
|
|
57
|
+
}
|
|
58
|
+
export interface ProvisionOptions {
|
|
59
|
+
endpoint?: string;
|
|
60
|
+
/** Max time (ms) to wait for cognito-local to start. Default 30s. */
|
|
61
|
+
waitTimeoutMs?: number;
|
|
62
|
+
/** Process env to read user-provided overrides from. Defaults to process.env. */
|
|
63
|
+
env?: NodeJS.ProcessEnv | Record<string, string | undefined>;
|
|
64
|
+
/**
|
|
65
|
+
* Path to the JSON file that caches `(projectName, intent.id) → pool/client
|
|
66
|
+
* IDs` across `vk dev` runs. Defaults to `~/.vk/cognito-local-state.json`.
|
|
67
|
+
* Tests override this to an isolated tmpdir.
|
|
68
|
+
*/
|
|
69
|
+
stateFile?: string;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Provision (or reuse) cognito-local user pools for every `auth` intent
|
|
73
|
+
* declared in `vk.config.ts`, and return env vars to inject into the
|
|
74
|
+
* local dev server. The FIRST intent's IDs are exposed as the canonical
|
|
75
|
+
* `COGNITO_USER_POOL_ID` / `COGNITO_APP_CLIENT_ID` (matching the CDK
|
|
76
|
+
* stack's behavior in `createAuth`).
|
|
77
|
+
*/
|
|
78
|
+
export declare function provisionCognitoLocal(projectName: string, authIntents: ProvisionAuthIntent[], stage: string, options?: ProvisionOptions): Promise<ProvisionResult>;
|
|
79
|
+
/**
|
|
80
|
+
* Test-only — clear cached state between vitest runs. Accepts an
|
|
81
|
+
* optional `stateFile` path (defaulting to the real user-level one) so
|
|
82
|
+
* tests that use their own tmpdir can clean up explicitly.
|
|
83
|
+
*/
|
|
84
|
+
export declare function _clearCognitoLocalStateForTesting(stateFile?: string): void;
|
|
85
|
+
export {};
|
|
86
|
+
//# sourceMappingURL=cognito-local.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cognito-local.d.ts","sourceRoot":"","sources":["../../src/utils/cognito-local.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAUH,4DAA4D;AAC5D,eAAO,MAAM,sBAAsB,0BAA0B,CAAC;AAC9D,uEAAuE;AACvE,eAAO,MAAM,oBAAoB,UAAU,CAAC;AAiC5C;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IAClC,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,CAAC,EAAE,KAAK,CAAC,OAAO,GAAG,OAAO,GAAG,UAAU,CAAC,CAAC;IACnD,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;;;;;;;OAOG;IACH,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;CAC7B;AAED,UAAU,SAAS;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;CAClB;AA0KD,MAAM,WAAW,eAAe;IAC9B,iEAAiE;IACjE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,4EAA4E;IAC5E,OAAO,EAAE,OAAO,CAAC;IACjB,kFAAkF;IAClF,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;CAClC;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,qEAAqE;IACrE,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,iFAAiF;IACjF,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;IAC7D;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;GAMG;AACH,wBAAsB,qBAAqB,CACzC,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,mBAAmB,EAAE,EAClC,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,gBAAqB,GAC7B,OAAO,CAAC,eAAe,CAAC,CAmF1B;AAED;;;;GAIG;AACH,wBAAgB,iCAAiC,CAC/C,SAAS,GAAE,MAA2B,GACrC,IAAI,CAIN"}
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* cognito-local provisioning for `vk dev`.
|
|
3
|
+
*
|
|
4
|
+
* `jagregory/cognito-local` is a Docker image that emulates the Cognito
|
|
5
|
+
* User-Pool API on the standard Cognito SDK over plain HTTP. We start
|
|
6
|
+
* the container from `~/.vk/docker-compose.yml` (see
|
|
7
|
+
* `docker-compose.ts:needsCognito`); this file handles the runtime
|
|
8
|
+
* provisioning step that creates the user pool + app client inside the
|
|
9
|
+
* running mock and writes the resulting IDs into the local dev server's
|
|
10
|
+
* env.
|
|
11
|
+
*
|
|
12
|
+
* Provisioned IDs are cached in `~/.vk/cognito-local-state.json`, keyed
|
|
13
|
+
* by `(projectName, intent.id)`, so subsequent `vk dev` runs reuse the
|
|
14
|
+
* same pool. If `docker compose down -v` wipes the cognito-local volume,
|
|
15
|
+
* the cached IDs become stale — the next call detects "pool not found"
|
|
16
|
+
* and recreates a fresh pool transparently.
|
|
17
|
+
*
|
|
18
|
+
* Honors a user-provided override: when both `COGNITO_USER_POOL_ID` and
|
|
19
|
+
* `COGNITO_APP_CLIENT_ID` are present in the shell env (typically via
|
|
20
|
+
* `.env.local`), provisioning is SKIPPED and the user-supplied values
|
|
21
|
+
* win — letting consumers point local dev at a real Cognito pool when
|
|
22
|
+
* they prefer that over the in-docker mock.
|
|
23
|
+
*/
|
|
24
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs';
|
|
25
|
+
import { dirname, join } from 'path';
|
|
26
|
+
import { homedir } from 'os';
|
|
27
|
+
import chalk from 'chalk';
|
|
28
|
+
const VK_HOME = join(homedir(), '.vk');
|
|
29
|
+
const DEFAULT_STATE_FILE = join(VK_HOME, 'cognito-local-state.json');
|
|
30
|
+
/** Default cognito-local URL, matches docker-compose.ts. */
|
|
31
|
+
export const COGNITO_LOCAL_ENDPOINT = 'http://localhost:9229';
|
|
32
|
+
/** Region label used everywhere local — cognito-local doesn't care. */
|
|
33
|
+
export const COGNITO_LOCAL_REGION = 'local';
|
|
34
|
+
/**
|
|
35
|
+
* Recognises placeholder values that look like a `.env.example` user
|
|
36
|
+
* forgot to fill in (e.g. `us-east-1_XXXXXXXXX`,
|
|
37
|
+
* `XXXXXXXXXXXXXXXXXXXXXXXXXX`, `your-pool-id-here`). Treating these as
|
|
38
|
+
* "unset" means a copy-pasted `.env.example` doesn't silently disable
|
|
39
|
+
* cognito-local provisioning — the trap that bit us when the CMS's
|
|
40
|
+
* `apps/api/.env.local` carried over template placeholders and `vk dev`
|
|
41
|
+
* skipped, leaving `/auth/login` to 500 against a fictitious pool.
|
|
42
|
+
*
|
|
43
|
+
* Conservative heuristics: a value is a placeholder iff it (a) consists
|
|
44
|
+
* of 6+ consecutive `X`s/`x`s, OR (b) literally equals one of the
|
|
45
|
+
* obvious template tokens. We do NOT pattern-match real Cognito IDs to
|
|
46
|
+
* avoid false positives on legitimate (but unusual-looking) IDs.
|
|
47
|
+
*/
|
|
48
|
+
function isPlaceholder(value) {
|
|
49
|
+
if (!value)
|
|
50
|
+
return true;
|
|
51
|
+
const v = value.trim();
|
|
52
|
+
if (v.length === 0)
|
|
53
|
+
return true;
|
|
54
|
+
if (/X{6,}/i.test(v))
|
|
55
|
+
return true;
|
|
56
|
+
if (v === 'your-user-pool-id' ||
|
|
57
|
+
v === 'your-pool-id' ||
|
|
58
|
+
v === 'your-client-id' ||
|
|
59
|
+
v === 'your-app-client-id' ||
|
|
60
|
+
v === 'replace-me') {
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
function loadState(stateFile) {
|
|
66
|
+
if (!existsSync(stateFile))
|
|
67
|
+
return {};
|
|
68
|
+
try {
|
|
69
|
+
return JSON.parse(readFileSync(stateFile, 'utf-8'));
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
return {};
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function saveState(stateFile, state) {
|
|
76
|
+
// `dirname` is safer than hardcoding `VK_HOME` — when tests override
|
|
77
|
+
// `stateFile` we still want to ensure the containing dir exists.
|
|
78
|
+
mkdirSync(dirname(stateFile), { recursive: true });
|
|
79
|
+
writeFileSync(stateFile, JSON.stringify(state, null, 2), 'utf-8');
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Poll cognito-local until it answers an HTTP request. The container's
|
|
83
|
+
* own healthcheck (in docker-compose.ts) is the authoritative readiness
|
|
84
|
+
* signal — this is a belt-and-braces guard so the very first SDK call
|
|
85
|
+
* doesn't race the container's startup.
|
|
86
|
+
*
|
|
87
|
+
* Treats any HTTP response (even 4xx / 5xx) as "up" — we just need TCP
|
|
88
|
+
* + an HTTP server listening, not a successful operation.
|
|
89
|
+
*/
|
|
90
|
+
async function waitForCognitoLocal(endpoint, timeoutMs) {
|
|
91
|
+
const deadline = Date.now() + timeoutMs;
|
|
92
|
+
while (Date.now() < deadline) {
|
|
93
|
+
try {
|
|
94
|
+
// AbortSignal.timeout is Node 18+. Keep the per-request timeout
|
|
95
|
+
// short so a misbehaving container doesn't burn the whole budget.
|
|
96
|
+
const res = await fetch(endpoint + '/health', {
|
|
97
|
+
signal: AbortSignal.timeout(2000),
|
|
98
|
+
});
|
|
99
|
+
// Any response means there's an HTTP server on the other end.
|
|
100
|
+
if (res.status > 0)
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
// ECONNREFUSED, AbortError, etc. — keep polling.
|
|
105
|
+
}
|
|
106
|
+
await new Promise((r) => setTimeout(r, 500));
|
|
107
|
+
}
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Build a Cognito SDK client pointed at cognito-local. Dynamic-imported
|
|
112
|
+
* so the SDK isn't pulled in for users who don't have an `auth` intent.
|
|
113
|
+
*
|
|
114
|
+
* cognito-local doesn't validate AWS credentials — it just needs the
|
|
115
|
+
* SDK to send requests — so we hand it stub credentials that are
|
|
116
|
+
* obviously not real.
|
|
117
|
+
*/
|
|
118
|
+
async function loadCognitoSdk(endpoint) {
|
|
119
|
+
const sdk = await import('@aws-sdk/client-cognito-identity-provider');
|
|
120
|
+
const client = new sdk.CognitoIdentityProviderClient({
|
|
121
|
+
region: COGNITO_LOCAL_REGION,
|
|
122
|
+
endpoint,
|
|
123
|
+
credentials: {
|
|
124
|
+
accessKeyId: 'local-dev',
|
|
125
|
+
secretAccessKey: 'local-dev',
|
|
126
|
+
},
|
|
127
|
+
});
|
|
128
|
+
return { sdk, client };
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Look up a user pool by ID against cognito-local; returns true when it
|
|
132
|
+
* still exists, false when the volume's been wiped (e.g. `docker compose
|
|
133
|
+
* down -v`) and our cached ID is stale.
|
|
134
|
+
*/
|
|
135
|
+
async function poolExists(client, sdk, userPoolId) {
|
|
136
|
+
try {
|
|
137
|
+
await client.send(new sdk.DescribeUserPoolCommand({ UserPoolId: userPoolId }));
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
140
|
+
catch (err) {
|
|
141
|
+
// ResourceNotFoundException is the SDK error when the pool is gone.
|
|
142
|
+
if (err?.name === 'ResourceNotFoundException')
|
|
143
|
+
return false;
|
|
144
|
+
// Any other error (network, etc.) — assume the pool is fine and let
|
|
145
|
+
// the next real call surface the error.
|
|
146
|
+
return true;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
async function createPool(client, sdk, intent, projectName, stage) {
|
|
150
|
+
// Mirror the CDK naming convention so prod + local pools are visually
|
|
151
|
+
// identifiable as the same "logical" pool.
|
|
152
|
+
const poolName = `${projectName}-${intent.id}-${stage}`;
|
|
153
|
+
const usernameAttributes = [];
|
|
154
|
+
if (!intent.signInWith || intent.signInWith.includes('email')) {
|
|
155
|
+
usernameAttributes.push('email');
|
|
156
|
+
}
|
|
157
|
+
if (intent.signInWith?.includes('phone')) {
|
|
158
|
+
usernameAttributes.push('phone_number');
|
|
159
|
+
}
|
|
160
|
+
// Declare each custom attribute as a mutable string with the same
|
|
161
|
+
// shape the prod CDK stack uses. Without this, cognito-local rejects
|
|
162
|
+
// every later `admin-update-user-attributes` call (and indeed every
|
|
163
|
+
// `--user-attributes Name=custom:...` on `admin-create-user`) with
|
|
164
|
+
// `InvalidParameterException: Attribute does not exist in the schema`,
|
|
165
|
+
// and the resulting JWTs carry no custom claims — which silently
|
|
166
|
+
// breaks any role/scope mapping your app code does on `custom:role`.
|
|
167
|
+
const customSchema = (intent.customAttributes ?? []).map((name) => ({
|
|
168
|
+
Name: name,
|
|
169
|
+
AttributeDataType: 'String',
|
|
170
|
+
Mutable: true,
|
|
171
|
+
StringAttributeConstraints: { MinLength: '1', MaxLength: '2048' },
|
|
172
|
+
}));
|
|
173
|
+
const createPoolRes = await client.send(new sdk.CreateUserPoolCommand({
|
|
174
|
+
PoolName: poolName,
|
|
175
|
+
AutoVerifiedAttributes: ['email'],
|
|
176
|
+
UsernameAttributes: usernameAttributes.length > 0 ? usernameAttributes : undefined,
|
|
177
|
+
AdminCreateUserConfig: {
|
|
178
|
+
// Mirror CDK's `selfSignUpEnabled: intent.allowSignUp ?? false`
|
|
179
|
+
AllowAdminCreateUserOnly: !(intent.allowSignUp ?? false),
|
|
180
|
+
},
|
|
181
|
+
Schema: customSchema.length > 0 ? customSchema : undefined,
|
|
182
|
+
}));
|
|
183
|
+
const userPoolId = createPoolRes.UserPool?.Id;
|
|
184
|
+
if (!userPoolId) {
|
|
185
|
+
throw new Error(`cognito-local CreateUserPool returned no Id for ${poolName}`);
|
|
186
|
+
}
|
|
187
|
+
// Match the CDK app client config: USER_PASSWORD_AUTH is what
|
|
188
|
+
// `@venturekit/auth/server`'s signInWithPassword needs.
|
|
189
|
+
const createClientRes = await client.send(new sdk.CreateUserPoolClientCommand({
|
|
190
|
+
UserPoolId: userPoolId,
|
|
191
|
+
ClientName: 'default',
|
|
192
|
+
ExplicitAuthFlows: [
|
|
193
|
+
'ALLOW_USER_PASSWORD_AUTH',
|
|
194
|
+
'ALLOW_REFRESH_TOKEN_AUTH',
|
|
195
|
+
],
|
|
196
|
+
GenerateSecret: false,
|
|
197
|
+
PreventUserExistenceErrors: 'ENABLED',
|
|
198
|
+
}));
|
|
199
|
+
const clientId = createClientRes.UserPoolClient?.ClientId;
|
|
200
|
+
if (!clientId) {
|
|
201
|
+
throw new Error(`cognito-local CreateUserPoolClient returned no ClientId for ${poolName}`);
|
|
202
|
+
}
|
|
203
|
+
return { userPoolId, clientId };
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Provision (or reuse) cognito-local user pools for every `auth` intent
|
|
207
|
+
* declared in `vk.config.ts`, and return env vars to inject into the
|
|
208
|
+
* local dev server. The FIRST intent's IDs are exposed as the canonical
|
|
209
|
+
* `COGNITO_USER_POOL_ID` / `COGNITO_APP_CLIENT_ID` (matching the CDK
|
|
210
|
+
* stack's behavior in `createAuth`).
|
|
211
|
+
*/
|
|
212
|
+
export async function provisionCognitoLocal(projectName, authIntents, stage, options = {}) {
|
|
213
|
+
const env = options.env ?? process.env;
|
|
214
|
+
if (authIntents.length === 0) {
|
|
215
|
+
return { envVars: {}, skipped: true, pools: {} };
|
|
216
|
+
}
|
|
217
|
+
// User opt-out: an externally configured pool wins. We require BOTH
|
|
218
|
+
// values to be present AND non-placeholder — half-set means the user
|
|
219
|
+
// forgot one, and `XXXXX...` placeholders mean they copy-pasted
|
|
220
|
+
// `.env.example` without filling it in. In either case a working
|
|
221
|
+
// cognito-local is more helpful than a stale 401 / 500.
|
|
222
|
+
const userPoolId = env['COGNITO_USER_POOL_ID'];
|
|
223
|
+
const clientId = env['COGNITO_APP_CLIENT_ID'];
|
|
224
|
+
if (!isPlaceholder(userPoolId) &&
|
|
225
|
+
!isPlaceholder(clientId)) {
|
|
226
|
+
// Log so users can see why cognito-local provisioning didn't run —
|
|
227
|
+
// this is the most common source of confusion when /auth/login 500s.
|
|
228
|
+
console.log(chalk.gray(' ✓ cognito: using external pool from env ') +
|
|
229
|
+
chalk.cyan(userPoolId) +
|
|
230
|
+
chalk.gray(' (cognito-local provisioning skipped)\n'));
|
|
231
|
+
return { envVars: {}, skipped: true, pools: {} };
|
|
232
|
+
}
|
|
233
|
+
const endpoint = options.endpoint ?? COGNITO_LOCAL_ENDPOINT;
|
|
234
|
+
const waitTimeoutMs = options.waitTimeoutMs ?? 30000;
|
|
235
|
+
const stateFile = options.stateFile ?? DEFAULT_STATE_FILE;
|
|
236
|
+
const ready = await waitForCognitoLocal(endpoint, waitTimeoutMs);
|
|
237
|
+
if (!ready) {
|
|
238
|
+
console.warn(chalk.yellow(` ⚠ cognito-local at ${endpoint} did not become ready in ${waitTimeoutMs / 1000}s — auth-protected routes will 500 until it's up.`));
|
|
239
|
+
return { envVars: {}, skipped: true, pools: {} };
|
|
240
|
+
}
|
|
241
|
+
const { sdk, client } = await loadCognitoSdk(endpoint);
|
|
242
|
+
const state = loadState(stateFile);
|
|
243
|
+
state[projectName] = state[projectName] ?? {};
|
|
244
|
+
let stateChanged = false;
|
|
245
|
+
const pools = {};
|
|
246
|
+
for (const intent of authIntents) {
|
|
247
|
+
let pool = state[projectName][intent.id];
|
|
248
|
+
// Cache hit but the volume's been wiped → recreate.
|
|
249
|
+
if (pool && !(await poolExists(client, sdk, pool.userPoolId))) {
|
|
250
|
+
pool = undefined;
|
|
251
|
+
stateChanged = true;
|
|
252
|
+
}
|
|
253
|
+
if (!pool) {
|
|
254
|
+
pool = await createPool(client, sdk, intent, projectName, stage);
|
|
255
|
+
state[projectName][intent.id] = pool;
|
|
256
|
+
stateChanged = true;
|
|
257
|
+
}
|
|
258
|
+
pools[intent.id] = pool;
|
|
259
|
+
}
|
|
260
|
+
if (stateChanged)
|
|
261
|
+
saveState(stateFile, state);
|
|
262
|
+
// Canonical pool = first declared intent. Matches CDK's
|
|
263
|
+
// `createAuth(intent[0])` flow.
|
|
264
|
+
const primary = pools[authIntents[0].id];
|
|
265
|
+
return {
|
|
266
|
+
envVars: {
|
|
267
|
+
COGNITO_USER_POOL_ID: primary.userPoolId,
|
|
268
|
+
COGNITO_APP_CLIENT_ID: primary.clientId,
|
|
269
|
+
},
|
|
270
|
+
skipped: false,
|
|
271
|
+
pools,
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Test-only — clear cached state between vitest runs. Accepts an
|
|
276
|
+
* optional `stateFile` path (defaulting to the real user-level one) so
|
|
277
|
+
* tests that use their own tmpdir can clean up explicitly.
|
|
278
|
+
*/
|
|
279
|
+
export function _clearCognitoLocalStateForTesting(stateFile = DEFAULT_STATE_FILE) {
|
|
280
|
+
if (existsSync(stateFile)) {
|
|
281
|
+
writeFileSync(stateFile, JSON.stringify({}, null, 2), 'utf-8');
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
//# sourceMappingURL=cognito-local.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cognito-local.js","sourceRoot":"","sources":["../../src/utils/cognito-local.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,E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CAAC,MAAM,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC;YACtC,YAAY,GAAG,IAAI,CAAC;QACtB,CAAC;QAED,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC;IAC1B,CAAC;IAED,IAAI,YAAY;QAAE,SAAS,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;IAE9C,wDAAwD;IACxD,gCAAgC;IAChC,MAAM,OAAO,GAAG,KAAK,CAAC,WAAW,CAAC,CAAC,CAAE,CAAC,EAAE,CAAE,CAAC;IAE3C,OAAO;QACL,OAAO,EAAE;YACP,oBAAoB,EAAE,OAAO,CAAC,UAAU;YACxC,qBAAqB,EAAE,OAAO,CAAC,QAAQ;SACxC;QACD,OAAO,EAAE,KAAK;QACd,KAAK;KACN,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,iCAAiC,CAC/C,YAAoB,kBAAkB;IAEtC,IAAI,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;QAC1B,aAAa,CAAC,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;IACjE,CAAC;AACH,CAAC"}
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
* MinIO → localhost:9000 / 9001 (buckets per project)
|
|
10
10
|
* pgweb → localhost:8081 (DB viewer, auto-added with Postgres)
|
|
11
11
|
* Redis Insight → localhost:5540 (queue/cache viewer, auto-added with Redis)
|
|
12
|
+
* cognito-local → localhost:9229 (Cognito mock, auto-added with auth intent)
|
|
12
13
|
*/
|
|
13
14
|
interface DatabaseIntent {
|
|
14
15
|
id: string;
|
|
@@ -25,11 +26,15 @@ interface StorageIntent {
|
|
|
25
26
|
interface QueueIntent {
|
|
26
27
|
id: string;
|
|
27
28
|
}
|
|
29
|
+
interface AuthIntent {
|
|
30
|
+
id: string;
|
|
31
|
+
}
|
|
28
32
|
interface InfraIntents {
|
|
29
33
|
databases?: DatabaseIntent[];
|
|
30
34
|
caches?: CacheIntent[];
|
|
31
35
|
storage?: StorageIntent[];
|
|
32
36
|
queues?: QueueIntent[];
|
|
37
|
+
auth?: AuthIntent[];
|
|
33
38
|
}
|
|
34
39
|
/**
|
|
35
40
|
* Build the local Postgres database name for a single declared database
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"docker-compose.d.ts","sourceRoot":"","sources":["../../src/utils/docker-compose.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"docker-compose.d.ts","sourceRoot":"","sources":["../../src/utils/docker-compose.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AASH,UAAU,cAAc;IAAG,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC;CAAE;AACrE,UAAU,WAAW;IAAG,EAAE,EAAE,MAAM,CAAC;CAAE;AACrC,UAAU,aAAa;IAAG,EAAE,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAC;CAAE;AACzD,UAAU,WAAW;IAAG,EAAE,EAAE,MAAM,CAAC;CAAE;AACrC,UAAU,UAAU;IAAG,EAAE,EAAE,MAAM,CAAC;CAAE;AAEpC,UAAU,YAAY;IACpB,SAAS,CAAC,EAAE,cAAc,EAAE,CAAC;IAC7B,MAAM,CAAC,EAAE,WAAW,EAAE,CAAC;IACvB,OAAO,CAAC,EAAE,aAAa,EAAE,CAAC;IAC1B,MAAM,CAAC,EAAE,WAAW,EAAE,CAAC;IACvB,IAAI,CAAC,EAAE,UAAU,EAAE,CAAC;CACrB;AA+BD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAE5D;AA2OD,MAAM,WAAW,mBAAmB;IAClC,yEAAyE;IACzE,WAAW,EAAE,MAAM,GAAG,IAAI,CAA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