Write a connector without the kit
Follow a connector's run on the API, and retry after a refusal, from registration through the vendor, changes, webhooks, the hold and the report.
The connector kit makes this run for you. On the API, keep the steps in this order so a stop loses nothing. The TypeScript SDK makes the same calls. Errors lists refusals, and Write safely covers versions and idempotency keys.
A Marfa plugin's connector registers when a host starts it with the key the host minted. A connector outside a plugin registers itself. One key holds one registration.
Register the connector
Send read_only_types, the types you do not carry back, on every registration. A later list replaces it. Omitting the field clears it. An item reads read_only: true only while every live connector of its source lists that type and may write it. Marfa still accepts a write.
Read the vendor
A record left off a page is not a deletion.
Write what you read
Upsert in bulk by the key's source and source_id, so a second read updates the item. Put an account in source_id. The source names the system. tier feed is the feed, and text is Markdown. atomic false keeps the rows that passed. Otherwise one refusal undoes the page.
What a repeat write does
Send the vendor's page whole. Unchanged comes back skipped as unchanged. A binned item comes back skipped as trashed and stays binned. After a purge, look the record up and write again only past settled_at.
Connect items
A pointer is an edge. edges on the bulk write replaces that one type. Omit a type to leave its edges. Marfa's own types are in the Catalog.
Set aside what the vendor deleted
Archive only when the vendor dropped the record. People use the bin. A bulk write leaves state alone, so set active when the record returns.
Name the source
Each start, read the source and set the name and mark only while they are empty, so a name the owner set stays.
Declare the types you don't carry back
List them when you register. The next run puts back an edit to them.
Carry changes back
Link items to the vendor
Register the type with link_field, the vendor's id, unique in every state. A duplicate is 409 link_taken. No value means the vendor has not heard of the item.
Watch for changes made in Marfa
Keep Last-Event-ID from the event stream in state. Keep a copy in sync covers that stream, including your own writes. Write the agreement under the hold, then look it up per event. An item that matches its record is already agreed. On a person's edit, write waiting true and that record before the cursor moves. The other order drops the edit if you stop.
Carry a change back
List agreements with waiting true, send the change, and on acceptance store waiting false and the shared record. A refusal stays waiting. Clearing waiting early drops the change.
Send a new item to the vendor
No link: create the vendor's record, using the item's id where the vendor dedupes. Then set the link at the read version and write the agreement immediately, or the next run creates it again.
Rare cases
One rule for a field both sides changed. If the vendor cannot delete, edit the record and settle the tombstone then, or the next read creates the item again.
Take a vendor's webhooks
Create an endpoint
Create the endpoint once and keep path. Later reads hide it. The vendor posts to the public address plus path, with no credential. The signing secret is a connector setting. duplicate_header marks a repeat.
Read the deliveries
List unhandled deliveries, oldest first and without bodies, until next_cursor is absent. Only this connector's key can read them.
Check the signature
Check the webhook signature, in constant time, over the raw bytes the body returns. A stored delivery does not prove the sender. Mark a bad one rejected and skip it.
Act on a delivery
Read the vendor. A delivery only names the change, and it can arrive twice, late, or never, so keep the scheduled read. duplicate_of on a processed delivery is already done.
Mark it handled
Mark them handled after a successful run: processed, duplicate, or rejected. The first mark stands. A failure leaves them listed. Retire after the vendor switches. Ten endpoints may be live, and retired deliveries still count. Marfa answers the vendor first and stores nothing it refuses. Past the rate limit: 429 rate_limited; a full backlog: 503 inbound_unavailable; both with Retry-After. Handling one frees a place. Windows are instance settings.
One process, one place
- Take the hold and keep renewing it.
- Read state and the agreements.
- Read the vendor and write the items.
- Write the agreements for this run.
- Replace the state document.
- Report the run and release the hold.
Take the hold
Take the hold under this process's name before writing state or agreements. One name is one process. Another holder gets 409 connector_held and details.expires_at. Renew before expires_at. On a renewal, renewed false means it lapsed: read state and agreements again first. Without a renewal, write nothing, in Marfa or at the vendor. Release at the end. A heartbeat does not renew the hold.
Keep your place
Read state first. Replace it under the hold after its writes have landed, or the next run repeats them. You send the whole document. problems replaces the messages apps show, {} clears them, and leaving it out keeps them. Both stay on the source for the next key. Delete it and the agreements and the problems go too.
Retry after
409 connector_held wrote nothing. On 429 rate_limited, wait for Retry-After (error.details.retry_after_seconds), then resend. 503 write_contention changed nothing: resend. After 500 internal_error, read first. Replacing state or agreements under the hold is safe twice. A bulk write by natural key hits the same items. With no natural key, send an Idempotency-Key, or a retry creates a second item. Give the vendor an idempotency key too.
Report the run
Report the run at the end, succeeded or failed.
The contract is connectors, items and inbound webhooks.