Files
vin-decoder/scripts/seed.js
T
agent-company 67097cf976
CI — Build, Test, Push / test (pull_request) Failing after 6s
CI — Build, Test, Push / build-and-push (pull_request) Has been skipped
feat: scaffold vin-decoder repo — server, data layer, Flux manifests, CI
Closes leeworks-agents/api-company#122

- openapi.yaml: copied from leeworks-agents/api-company apis/vin-decoder/openapi.yaml (canonical spec)
- src/db.js: SQLite database init with vin_cache schema and indexes
- src/nhtsa.js: NHTSA vPIC fetch + field mapping
- src/cache.js: cache read/write with 90-day TTL, validateVin, getCacheStats, evictExpired
- src/server.js: Fastify server implementing GET /v1/decode, POST /v1/batch, GET /v1/health
  - X-RapidAPI-Proxy-Secret middleware on /decode and /batch
  - X-Request-Id, X-Cache, X-Data-Source response headers
  - Returns 403 for missing/wrong proxy secret
- scripts/seed.js: pre-warm cache with known VINs, runs eviction sweep
- src/tests/cache.test.js: unit tests for validateVin + cache integration (Honda Accord VIN)
- Dockerfile: Node 20 alpine, non-root, healthcheck on /v1/health
- .gitea/workflows/ci.yaml: test → build → push to registry.leeworks.dev/vin-decoder/api:<sha>
- flux/vin-decoder/: Namespace, Deployment (with RAPIDAPI_PROXY_SECRET from secret), Service, Ingress (vin.leeworks.dev + TLS), Kustomization
- .gitignore: node_modules, data/, .env
2026-05-30 20:08:47 +00:00

30 lines
902 B
JavaScript

#!/usr/bin/env node
/**
* Seed script — pre-warm the SQLite cache with a set of known VINs.
* Also used for the startup eviction sweep.
* Usage: node scripts/seed.js [VIN1 VIN2 ...]
*/
import { decodeVin, evictExpired } from '../src/cache.js';
const DEFAULT_VINS = [
'1HGCM82633A004352', // 2003 Honda Accord EX
'WBABW33486PX01612', // BMW
];
async function main() {
const vins = process.argv.slice(2).length > 0 ? process.argv.slice(2) : DEFAULT_VINS;
const evicted = evictExpired();
console.log(`Evicted ${evicted} expired cache entries.`);
for (const vin of vins) {
try {
const { result, fromCache } = await decodeVin(vin);
console.log(`${vin}: ${fromCache ? 'CACHE HIT' : 'FETCHED'}${result.make} ${result.model} ${result.model_year}`);
} catch (err) {
console.error(`${vin}: ERROR — ${err.message}`);
}
}
}
main().catch(console.error);