WFDASH-WEBAPP/scripts/smoke/_env.ts
SJCoetz 63048e51c9 feat: add AI quote processing pipeline and admin settings UI
Add complete end-to-end AI-powered quote extraction workflow:
- Disable PB SDK auto-cancellation to support parallel batch requests
- Add required runtime dependencies for AI processing and document parsing
- Implement AI settings backend, operator UI, and REST API routes
- Add quote ingestion, insight population, and manual re-run AI endpoints
- Build service layers for quote items, AI settings, and structured item insights
- Fix attachment upload handling and quote item history blob parsing
- Add supporting migrations, smoke tests, and shared utility functions
- Export previously private helper functions for cross-service reuse
2026-08-09 16:17:29 +02:00

39 lines
1.4 KiB
TypeScript

/**
* Loads .env / .env.local into process.env BEFORE any other import runs.
*
* ES module imports are hoisted — so any `import { x } from "./y"`
* at the top of a script runs BEFORE the body. If `./y` reads
* process.env at module-init or call time, the env vars need to be
* set during the import phase itself, which means this file has to
* be the FIRST import in any smoke script that needs PB / Anthropic
* credentials.
*
* Import order matters:
* import "./_env"; // ← FIRST, side-effect only
* import { … } from "../../src/…"; // ← can now safely read env
*
* No exports — this file's only purpose is the side effect of reading
* .env / .env.local into process.env.
*/
import { readFileSync } from "node:fs";
import { resolve } from "node:path";
function loadEnvFile(name: string): void {
try {
const raw = readFileSync(resolve(process.cwd(), name), "utf8");
for (const line of raw.split("\n")) {
const trimmed = line.trim();
if (!trimmed || trimmed.startsWith("#")) continue;
const m = trimmed.match(/^([A-Z0-9_]+)\s*=\s*(.+)$/i);
if (m && !process.env[m[1]]) {
// Strip surrounding quotes if the .env used them.
process.env[m[1]] = m[2].replace(/^["']|["']$/g, "").trim();
}
}
} catch {
// missing file — fine, rely on shell env
}
}
loadEnvFile(".env");
loadEnvFile(".env.local");