Skip to content
MSO CloudDocumentation

Consume and publish platform events and API data

On this page

Another system reads MSO Cloud data through the Platform API, receives signed webhooks when something changes, and pushes events back. The table below says which "event" you want; the sections after it list what an engineer on either side touches.

When to use#

Use it when your system is not a connector (it does not get polled) and needs organizations, members, entitlements or the shared social trend feed, or needs to be told that a membership, app or trend changed. If your system also signs users in, add the satellite checklist. To pull data into MSO Cloud on a schedule, write a connector.

"Event" names five unrelated mechanisms in the code (Event contracts):

You want to Mechanism Contract
Receive changes as an external app Platform webhooks platformEventSchema in packages/platform-contract/src/webhooks.ts
Tell MSO Cloud something (content.published) POST /api/platform/v1/events contentPublishedEventSchema, scope platform:events.write
Send a marketplace order or stock change into MSO Cloud Marketplace webhook ingest POST /api/ingest/webhook/<tiktok-shop|shopee>/<connectorId>; connector-specific HMAC
React inside the platform Eventbus topics TOPICS in packages/eventbus/src/bus.ts (internal, not for apps)
Feed the ops screen Realtime ops feed packages/eventbus/src/realtime.ts (internal)

Only the first two are an external contract. Both the ingest envelope (packages/platform-contract/src/event-envelope.ts) and the bus entry (EventEnvelope in packages/eventbus/src/bus.ts) are called an envelope and have different shapes.

The contract#

  • The platform contract package (version 0.5.0, packages/platform-contract/package.json): api.ts response schemas, scopes.ts, webhooks.ts, signature.ts, claims.ts; prose in packages/platform-contract/CONTRACT.md. Endpoint, scope, signing and retry details: Platform API and events.
  • Events MSO to app: org.app.changed, membership.changed, user.disabled, trends.updated. App to MSO: content.published.
  • Every event is one envelope: id (idempotency key), type, org_id, occurred_at, data.
  • Scopes, one per data plane, are listed once in PLATFORM_SCOPES; the issuer derives its scope list from it (apps/idp/src/provider.ts).

How registration works#

Outbound delivery is subscription-driven. writePlatformEvent (apps/web/src/server/platform/outbox.ts) writes one pending platform_outbox row per active row of platform_webhook_subscriptions whose eventTypes match, inside the caller's tenant transaction, so a rolled-back change sends nothing. With no subscription it writes nothing. The worker queue scheduled runs platform-webhooks:sweep every minute and apps/worker/src/processors/platform-webhook-delivery.ts posts the signed body (X-MSO-Signature: sha256=<hex>, X-MSO-Event-Id).

Add one#

New event type, MSO to app:

  1. Add the Zod schema to packages/platform-contract/src/webhooks.ts, to platformEventSchema and to MSO_TO_APP_EVENT_TYPES.
  2. Call writePlatformEvent(orgId, '<type>', data) from the code that makes the change, inside its org transaction (web: apps/web/src/server/platform/, worker: apps/worker/src/lib/platform-outbox-write.ts).
  3. Raise the package version and update CONTRACT.md and Platform API and events; add a case to packages/platform-contract/src/contract.test.ts.

New endpoint or scope:

  1. Add the response schema to packages/platform-contract/src/api.ts; add the scope to PLATFORM_SCOPES only if no existing plane scope fits (a plane has one scope).
  2. Add the route under apps/web/src/app/api/platform/v1/, starting with requirePlatformScope('<scope>') (apps/web/src/server/platform/auth.ts), requiring the path organization to equal the token organization, and parsing the response with the schema.
  3. Add the scope to the manifests of the satellites that may request it and to the issuer client entries (Connected app).

Receiving side: verify the HMAC over the raw body in constant time before parsing, store seen X-MSO-Event-Id values, order by occurred_at, return 2xx quickly.

Guards#

packages/platform-contract/src/contract.test.ts, event-envelope.test.ts; scripts/audit/platform-scope-per-plane.py (one scope per route, in audit:all); scripts/audit/event-envelope-single-schema.py (one envelope schema; token audit-ok-event-envelope); rule pack .claude/rules/platform-family.md.

Operating it#

  • Retries: 2xx settles; 408, 425, 429 and 5xx retry at 30 s x 2^(n-1) capped at 6 h, at most 10 attempts; anything else is dead and stays in platform_outbox for inspection. Delivery is at-least-once and can arrive out of order.
  • The destination must be https on the satellite's launch host, with no credentials, no private or loopback address and no followed redirects. Secrets are envelope-encrypted.
  • Inbound POST /events: 600 requests a minute per organization and client, body at most 64 KiB, a repeated event id answers duplicate: true.
  • trends.updated is written by the worker when the shared feed revision moves (apps/worker/src/lib/trend-feed/announce.ts); a lost webhook delays an app by at most its own reconciliation.

Where it stops#

  • No screen or API creates platform_webhook_subscriptions rows, so every webhook receiver is wired by hand; creating that path touches schema and row-level security and needs operator review.
  • content.published is stored for lineage and has no consumer in apps/ or packages/.
  • The API exposes only the third-party market-intelligence plane and org structure; marketplace and marketing data have no endpoint.
  • Realtime type creator.hour_spike is declared and has no publisher; source_watermark columns have no writer (Event contracts).
  • GET /social/trends and /social/trends/counts are deprecated since 0.5.0 and removed in 1.0.