Changes & sync
There are three ways to keep a system current. Pick the one that fits:
| Need | Use |
|---|---|
| A local copy, refreshed now and then | product -C <clone> fetch / pull (see CLI) |
| Apply only the changes, idempotently, from a service | the change feed (below) |
| Be told when something happens | webhooks (maintainers set them up) or Follow on the web |
The change feed
curl -s "https://api-staging.product.cloud/v1/repos/acme/power-tools-eu/changes?limit=1000"{"events": [{"eventId": "sha256:…", "commit": "sha256:…", "sequence": 0, "entity": "product", "op": "add",
"key": {"gtin": "04012345678901"}, "after": {"brand": "ACME", "mpn": "GSR-18", "name": "…"}}],
"fromRevision": null, "toRevision": "sha256:…", "nextCursor": "eyJ…", "hasMore": true, "pending": false}What it covers: the semantic changes along the
mainbranch's first-parent history, oldest first.opisadd,replace, orremove.entityis the table's record type (product,attribute,class, …). Changes carrybeforeandafteras applicable.Paging: pass
nextCursorback asafteruntilhasMoreisfalse.limitdefaults to 1000, at most 5000. Store the last cursor and continue from it next time.Delivery: at least once. Deduplicate on
eventId; a retried or re-derived event keeps its id.pending: true: the newest commit is still being analyzed. Read again shortly.410 PRODUCT-CURSOR-GONE: your cursor's commit is no longer inmain's history. Read a snapshot again (clone or dataset), then continue from the feed's current cursor.Restricted repositories: the feed needs the same access as the data.
The normative description is the consumer protocol (spec 0.2), and conformance/run.sh in the repository checks a consumer against it.
Synchronizing with the CLI
product sync reads the feed of a clone and applies it to a target, keeping a checkpoint so a crash or a re-run never applies a change twice:
product get acme/power-tools-eu
product -C power-tools-eu sync plan --target dir:./mirror --checkpoint .product/checkpoints/mirror.json
product -C power-tools-eu sync run --target dir:./mirror --checkpoint .product/checkpoints/mirror.jsonThe dir: target writes one JSON document per product (mirror/products/<key>.json) and per record of other tables. Run product -C power-tools-eu pull (or fetch) and then sync run again to apply new changes.
Webhooks
Repository maintainers can register webhooks; consumers can ask a maintainer to add one for them.
curl -s -X POST "https://api-staging.product.cloud/v1/repos/<ns>/<repo>/webhooks" \
-H "Authorization: Bearer $PRODUCT_TOKEN" -H 'content-type: application/json' \
-d '{"url": "https://hooks.example.com/product-cloud", "events": ["release.published", "repo.ref.updated"]}'Events:
repo.ref.updated,release.published,access.requested,access.decided,proposal.submitted,proposal.accepted,proposal.changes-requested,proposal.rejected,proposal.withdrawn,proposal.merged,proposal.released,proposal.commented(subscriptions to the earlierproposal.openedandproposal.closedreceiveproposal.submittedandproposal.rejected/proposal.withdrawn), and the identity events (identity.decision.recorded,identity.entity.merged,identity.entity.split,identity.dispute.opened).*subscribes to all of them.The secret is returned once, when the webhook is created.
Headers:
product-event-id,product-event-type,product-delivery-id, andproduct-signature: t=<unix>,v1=<hex>, wherev1is HMAC-SHA256 of"<t>.<body>"with the secret.Retries: up to 8 attempts per delivery. A webhook is disabled after 20 consecutive failed deliveries. Maintainers can list deliveries and replay them.
Verify a delivery:
import hmac, hashlib, time
def verify(secret: str, header: str, body: bytes) -> bool:
parts = dict(p.split("=", 1) for p in header.split(","))
t = int(parts["t"])
if abs(time.time() - t) > 300:
return False
expected = hmac.new(secret.encode(), f"{t}.".encode() + body, hashlib.sha256).hexdigest()
return hmac.compare_digest(expected, parts["v1"])Follow
On the web, Follow on a repository puts its releases and discussions into your dashboard and notifications. It sends no external calls.