Adding a New Provider (e.g., ZR Express, Maystro Delivery, Ecotrack)
dz-sandbox separates deterministic simulation infrastructure (@dz-sandbox/core) from each provider adapter (packages/mock-<name>). Adding another Algerian payment or courier API takes ~4 small files.
1. Collect Honest Evidence First
Before coding endpoints:
- Read the provider's official documentation or record sanitized responses from their real sandbox/production account.
- Add a fixture file under
fixtures/<provider>/tagged:
"verified": true+ exact"source": "<url or capture note>"if confirmed from official docs/captures, or"verified": falseif still awaiting merchant confirmation.
- Add a section in
docs/SPEC_STATUS.mdlisting every endpoint/field and its status (Verified/Partial/Unverified).
2. Create packages/mock-<provider>
Scaffold an npm workspace package depending on @dz-sandbox/core, fastify, and zod:
src/<provider>.spec.ts: Keep all route paths, header names, status tables, and response code constants in one configurable file (explicitly annotateverified: true | false).src/server.ts: Exportcreate<Provider>Server({ ctx, webhooks }):
- Call
registerRequestAuditHook(app, ctx, '<provider>')so all requests appear in/__control/requestsand the dashboard. - Call
resolveScenario+applyNetworkScenario(ctx, '<provider>', request, reply, resolved)before route logic sotimeout,slow,gateway_500,network_drop,rate_limited, andauth_failedwork automatically. - Persist resources in
ctx.storenamespaces (e.g.<provider>:parcels) soGET /__control/export,POST /__control/import, andPOST /__control/resetsupport your provider for free. - Schedule lifecycle transitions or webhooks through
ctx.clock.schedule(...)andwebhooks.dispatch(...)soclock/advancemakes every async flow instant in tests.
src/<provider>.test.ts: Add contract replay tests againstfixtures/<provider>/*.json, validation tests, and scenario tests.
3. Wire into CLI & Control
- Update
packages/cli/src/runtime.tsanddoctor.tsto assign a default port (4004,DZ_<PROVIDER>_PORT) and expose URLs in.envsnippets. - Add built-in scenarios if provider-specific in
packages/core/src/scenarios.ts. - Update
Dockerfile,docker-compose.yml, andREADME*.md.
Experimental: Generate a Stateless Mock from OpenAPI 3.x
If you already have an OpenAPI 3.x specification (YAML or JSON), you can generate a starter experimental provider mock immediately:
npx dz-sandbox generate --openapi ./fixtures/openapi-demo/courier-demo.openapi.yaml --name courier-demo --out ./generated-providers/courier-demo
node ./generated-providers/courier-demo/server.mjs
Or boot it directly without writing files:
npx dz-sandbox serve-openapi --openapi ./fixtures/openapi-demo/courier-demo.openapi.yaml --name courier-demo --port 4200
[!WARNING]
Experimental Limitations: OpenAPI-generated mocks are stateless request/response validators (example/ schema synthesis) with scenario fault injection (gateway_500,slow,rate_limited,timeout,network_drop). They do not implement stateful payment/delivery state machines, external$refURLs, polymorphic discriminators, or automatic webhook dispatch. Generated providers must keep theirexperimentallabel until backed by hand-authored behavior and real fixtures.