Postman Automation
This section documents the code that keeps the Postman collection self-healing. Every helper lives under dapp/postman and ships with the repo, so there is no manual clicking inside the Postman UI—the CLI owns the entire lifecycle.
- env.schema.ts
- fetch-openapi.ts
- add-signing-to-collection.ts
- add-tests-to-collection.ts
- add-jwt-capture-test.ts
- add-jwt-requests.ts
- presign-requests.ts
Environment Validation (env.schema.ts)
dapp/postman/env.schema.ts is the gatekeeper for every script. It loads .env.postman, enforces mandatory keys, and normalizes values before exporting them to callers.
| Field | Validation | Notes |
|---|---|---|
PRIVATE_KEY | Required, auto-adds 0x prefix, fails fast if missing. | Use a throwaway key that maps to the Colored Key you plan to test. |
TOKEN_ID | Required, coerced to a non-negative number. | Shared across gate-access + form-submission requests. |
CHAIN_ID | Defaults to 1, must be positive. | Stored as a number so the signing helpers can embed it in envelopes. |
TEST_BASE_URL / BASE_URL | Must parse as a URL, strips trailing slashes. | Every script rewrites requests to avoid //api collisions. |
NEXT_PUBLIC_ENABLE_STATE_WORKER | Boolean-ish string, defaults to false. | Toggles SIWE behavior; still auto-enables when /api/nonce responds. |
Successful validation also exposes helpers for building the postman/collection directory, so all scripts share the same paths.
Script Responsibilities
fetch-openapi
fetch-openapi.ts
- Pulls the live spec from
env.OPENAPI_URL(/api/openapiby default). - Saves it to
postman/collection/openapi.jsonplus a timestamped snapshot for audits. - Refreshes
postman/collection/local.postman_environment.jsonwith baseline variables (baseUrl,tokenId,chainId,privateKey). Existing env files are merged to avoid losing overrides. - Warns when the fetched document is not OpenAPI 3.x so CI can catch stale endpoints.
Putting It Together
Run sequence (pnpm postman:all)
postman:all sequences the scripts plus Newman: fetch → convert → sign → tests → jwt-capture → jwt → presign → run.
Extend coverage
Add a new OpenAPI path + tag, run postman:all, and you automatically get a folder, generated assertions, signing helpers, and JWT coverage (when applicable).
Debug failures
postman/collection/report.html (from postman:report) preserves each request/response pair. Use it when CI surfaces a regression but you cannot reproduce it locally.
Coordinate with Supertest
Supertest remains the fast loop for handler logic; Postman proves that configuration, middleware, and the state worker still align with the public contract. Run both before cutting a release.
Tips
- Treat
.env.postmanlike code: commit the example, never the real file. The scripts refuse to run if the env is missing so CI jobs fail loudly. - Point
TEST_BASE_URLat isolates (local dev or staging) because Newman will consume rate-limit quota. - Flip
NEXT_PUBLIC_ENABLE_STATE_WORKERtotrueand confirm/api/nonceresponds if you want SIWE exercised; otherwise the presign script sticks to legacy envelopes so the same collection can test both worlds. - The automation lives entirely inside the repo, so onboarding a new engineer is as simple as
cp .env.postman.example .env.postman && pnpm postman:all.
Need the high-level justification and runbook? Head back to the Postman Contract Tests page.