- TypeScript Cloudflare Worker for authorization holds.
- Source lives in
src/:index.tsentry.handlers/request handlers (*.handler.ts).services/external integrations (*.service.ts).middleware/cross-cutting concerns (cors.ts,auth.ts,rate-limit.ts).lib/errors, utils, router.config/env validation and constants.types/shared interfaces.
- Tests in
tests/unitandtests/integration. - Key config:
wrangler.toml,.env.example,vitest.config.ts.
npm run dev— run locally with Wrangler.npm test— run Vitest test suite.npm test -- --coverage— generate coverage report (coverage/).npm run typecheck— strict TypeScript type checks.npm run lint/lint:fix— ESLint checks and autofix.npm run format/format:check— Prettier formatting.npm run deploy— deploy to default environment.npm run deploy:production— deploy to production.npm run tail— stream Cloudflare Worker logs.- First-time setup:
npm ci(then hooks enabled vianpm run prepare).
- TypeScript (strict); 2-space indent, double quotes, semicolons.
- Formatting: Prettier enforced (
.prettierrc). Usenpm run format. - Linting: ESLint with
@typescript-eslintandeslint-config-prettier. Usenpm run lint. - Filenames: lower-kebab with role suffix when applicable, e.g.,
holds.handler.ts,stripe.service.ts,rate-limit.ts. - Identifiers: functions
camelCase; classesPascalCase; constantsUPPER_SNAKE_CASE. - EditorConfig is provided for editor defaults.
- Vitest (globals enabled, Node env). Place unit tests under
tests/unit, integration undertests/integration. - Name files
*.test.ts(e.g.,tests/unit/utils.test.ts). - Coverage thresholds: 80% statements/branches/functions/lines. Use
npm test -- --coverage. - Keep tests deterministic; do not hit real Stripe/ChittyID—mock services.
- Conventional Commits enforced via commitlint/husky:
feat: add capture idempotency keyfix: correct CORS wildcard handlingchore: update wrangler config
- Pre-commit runs format and lint. Run before push:
npm run typecheck && npm test. - PRs include: description, linked issue(s), test updates, screenshots/logs when relevant, and notes on env/config changes.
- Never commit secrets. Copy
.env.exampleto.envfor local dev; usewrangler secret put STRIPE_SECRET_KEY(and related secrets) for Cloudflare. - Never mint ChittyID locally; always call the ChittyID service (
src/services/chittyid.service.ts). - Validate env at startup; update CORS allowlist carefully; avoid logging PII or raw tokens.