Mock Review Connector Tutorial
Purpose
Learn the connector adapter lifecycle without deploying an HTTP service or using real service tokens.
Concepts Covered
Connector, connector adapter, service token verification, scopes, event dispatch, error handling.
What You Will Build
You will run examples/connectors/mock-review-connector, a dependency-free adapter shaped like ConnectorAdapterV1.
Prerequisites
- Node 22.
File Structure
text
examples/connectors/mock-review-connector/
src/
index.mjs
demo.mjs
README.mdStep-by-Step Walkthrough
- Open
src/index.mjs. - Inspect
metadata(): slug, kind, scopes, and active status. - Inspect
verify(token): missing and revoked tokens resolve took: false. - Inspect
dispatch(event): events are stored in memory and return a status-like result. - Run the demo.
How to Run the Example
bash
node examples/connectors/mock-review-connector/src/demo.mjsExpected Output
The script prints:
- adapter ID
mock-review - metadata with connector scopes
verifyresult withok: truedispatchresult withok: true- the received
lens.publishedevent
How the Example Works Internally
The adapter uses the same method names and result shapes as the repository connector contract. It avoids network I/O so you can test event flow and failure handling locally.
Common Errors and Troubleshooting
token_revoked: use the demo token fromVALID_TOKEN.- Empty
received: calldispatchbefore reading the in-memory queue. - Real HTTP adapters should use the SDK
HttpConnectorAdapter; this example keeps the tutorial local.
Suggested Modifications
- Set
failNext: trueto inspect anok: falsedispatch result. - Add
agents:writeto scopes and document why it is needed. - Replace in-memory storage with a test double for your own service.