CodeVetter · Repo Unpack · Extension points
pact-foundation/pact-js
Extension points are primarily typed builder stages and caller-provided callback registries. Matching declarations and explicit Rules provide two paths into native matching, while plugins add content and transport support. Changes to public capabilities must account for exports, types, concrete builders, and cleanup behavior together.
- src/index.ts is the public export aggregation point; V4ConsumerPact factories in PactV4 create HTTP, synchronous, asynchronous, and GraphQL stages and supply their reset callbacks.
- HTTP builder callbacks are typed by V4RequestBuilderFunc/V4ResponseBuilderFunc and instantiated as RequestBuilder/ResponseBuilder, making those interfaces and classes the paired extension points for request/response options.
- Matcher helpers return declarative objects using pact:matcher:type, value, and optional generator properties; isMatcher and recursive reify define how declarations are recognized and reduced to examples.
- Advanced matching plugs in through validateRules/convertRulesToFFI, used by HTTP and message builders; adding a new rule part requires considering validateRules' fixed path/body/header/query/status list.
- StateHandlers is a string-keyed registry of promise-returning functions or setup/teardown objects; setupStates performs exact state-name lookup and passes state params to the selected lifecycle function.
- messageProviders dispatches by interaction description; providerWithMetadata adapts producers to metadata-bearing responses, while synchronousBodyHandler/asynchronousBodyHandler and their V4 counterparts adapt consumer body functions.
- requestFilter is an Express RequestHandler installed before state/message/catch-all dispatch; beforeEach/afterEach hooks are separate setup-path middleware with per-verification HooksState.
- usingPlugin calls native addPlugin and switches to plugin-capable stages; RequestWithPluginBuilder extends RequestBuilder with pluginContents, and synchronous plugin startTransport accepts transport/address/config while Verifier appends its message transport.