Skip to content
Sign in

Changes & sync

There are three ways to keep a system current. Pick the one that fits:

NeedUse
A local copy, refreshed now and thenproduct -C <clone> fetch / pull (see CLI)
Apply only the changes, idempotently, from a servicethe change feed (below)
Be told when something happenswebhooks (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 main branch's first-parent history, oldest first. op is add, replace, or remove. entity is the table's record type (product, attribute, class, …). Changes carry before and after as applicable.

  • Paging: pass nextCursor back as after until hasMore is false. limit defaults 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 in main'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.json

The 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 earlier proposal.opened and proposal.closed receive proposal.submitted and proposal.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, and product-signature: t=<unix>,v1=<hex>, where v1 is 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.