Skip to content

Sync

An application owns a set of things on the platform: its roles, event types, dispatch pools, connections, subscriptions, processes, scheduled jobs, service users, OpenAPI document and documentation pages. The sync package lets you declare them in code and push them with one call, so that a deploy leaves the platform matching the code. The process is described in sync definitions; this page is the Go API.

Sync is declarative and repeatable. Running it twice with the same set changes nothing the second time.

sync.ForApplication(code) starts a *DefinitionSet for one application. Each category has a Make* constructor returning a value with chainable With* methods, and an Add* method on the set.

set := sync.ForApplication("orders").
AddRole(sync.MakeRole("admin").
WithDisplayName("Orders Admin").
WithPermissions("orders:sales:order:view", "orders:sales:order:manage")).
AddEventType(sync.MakeEventType("orders:sales:order:placed", "Order placed")).
AddDispatchPool(sync.MakeDispatchPool("orders-default", "Orders").
WithConcurrency(8).
WithRateLimit(600)). // messages per minute
AddConnection(sync.MakeConnection("orders-billing", "Billing webhooks")).
AddSubscription(sync.MakeSubscription("order-billing", "Billing", "https://billing.example.com/webhooks").
WithConnectionCode("orders-billing").
WithDispatchPool("orders-default").
WithMode("IMMEDIATE").
WithMaxRetries(5).
Bind("orders:sales:order:placed", "")).
AddProcess(sync.MakeProcess("orders:sales:place-order", "Place order").
WithBody("graph LR; Cart-->Checkout-->Placed")).
AddScheduledJob(sync.MakeScheduledJob("orders:nightly", "Nightly", "0 0 2 * * *").
WithTimezone("Europe/London").
WithTargetURL("https://orders.example.com/jobs")).
AddPrincipal(sync.MakePrincipal("ops@example.com").
WithName("Ops").
WithRoles("orders:admin")).
AddDoc(sync.MakeDoc("getting-started", "# Getting started\n"))
res := sync.NewSynchronizer(c).Sync(ctx, set, sync.DefaultOptions())
if res.HasErrors() {
for category, msg := range res.Errors() {
log.Printf("sync category %s failed: %s", category, msg)
}
}

c is a *client.FlowCatalystClient. examples/fc-sync is a complete program.

Category Definition Notes
Roles MakeRole(name): WithDisplayName, WithDescription, WithPermissions(...), ClientManagedEnabled() name is the short name; the platform adds the app: prefix. Permissions are four-segment {app}:{context}:{aggregate}:{action}. A client-managed role can be re-assigned by client admins.
Event types MakeEventType(code, name): WithDescription code is the full {app}:{domain}:{aggregate}:{event}. The sync carries a name and description only; attach JSON Schemas through the console or the API.
Dispatch pools MakeDispatchPool(code, name): WithConcurrency, WithRateLimit(perMinute), WithDescription Synced before the subscriptions that name them. Pools are platform-wide, matched by code across applications, and each sync sets every field: an omitted rate limit removes an existing limit, and an omitted concurrency becomes 10. RemoveUnlisted on pools archives every other pool and needs an anchor credential.
Connections MakeConnection(code, name): WithDescription, WithExternalID No credentials: the platform assigns the application’s own service account. See connections.
Subscriptions MakeSubscription(code, name, target) and the methods below Bind event types to a webhook target.
Processes MakeProcess(code, name): WithBody, WithDiagramType, WithTags, WithDescription Documentation only: a diagram (Mermaid by default). No runtime effect.
Scheduled jobs MakeScheduledJob(code, name, crons...) and the methods below Cron expressions are six fields, seconds first.
Principals MakePrincipal(email): WithName, WithRoles(...), WithPasswordHash, Inactive() Matched by email. Role names are full (orders:admin); a name that is not a role is skipped and reported.
OpenAPI set.WithOpenAPISpec(json.RawMessage) One document, published as the application’s current version. Unchanged content is reported as unchanged.
Docs MakeDoc(slug, markdown): WithTitle Shown to administrators under Platform, Documentation.
Method Meaning
WithConnectionCode(code) Deliver through one of this application’s connections, by code. Codes are stable across environments. Prefer it to an id.
WithSharedConnectionCode(code) Name a shared (application-less) connection. The two namespaces never fall back to each other.
WithConnection(id) By connection id. Ids differ per environment, so avoid it for anything synced to more than one.
WithDispatchPool(code) The pool, by code.
WithMode(m) IMMEDIATE, NEXT_ON_ERROR (the platform default) or BLOCK_ON_ERROR. See ordering. Sync applies a mode you set on create and on update, so it overwrites a console change; without WithMode the stored mode is kept (a new subscription gets the default). An unknown value is refused with INVALID_MODE.
WithMaxRetries(n), WithTimeout(secs) Delivery limits.
DataOnlyEnabled() Deliver the event data as the body, with no envelope.
Bind(eventTypeCode, filter) Subscribe to an event type, with an optional filter. Call once per event type.

delaySeconds and maxAgeSeconds are not part of the sync item. Set them on a subscription through client.Subscriptions().Create or Update.

Method Meaning
WithTimezone(tz) The IANA zone the crons are evaluated in. Default UTC.
WithPayload(json.RawMessage) The payload sent with each firing.
ConcurrentEnabled() Passed to the receiver, which enforces it. The platform does not.
TracksCompletionEnabled() The platform waits for the application’s completion report.
WithTimeout(secs), WithDeliveryMaxAttempts(n) Delivery limits. The attempt default is 3.
WithTargetURL(url) Overrides the application’s default callback URL.
ForClient(id) Scope the job to one client. Omit it for a platform-wide job (anchor only).

Jobs are sent one request per client, in first-seen order. Receiving the firings is covered in Scheduled jobs. Cron syntax is in cron.

Synchronizer.Sync makes one platform call per category, in dependency order:

  1. roles
  2. event types
  3. dispatch pools
  4. connections
  5. subscriptions
  6. processes
  7. scheduled jobs
  8. principals
  9. OpenAPI
  10. docs

A failed category does not stop the others. The exception is that subscriptions are not sent when the connections category failed, because a subscription’s connectionCode may not resolve; the result says so. An empty category is skipped, so the corresponding field of the result stays nil.

Sync never returns an error. Failures are on the returned *sync.Result:

type CategoryResult struct {
Created, Updated, Deleted uint32 // Deleted counts archived rows for scheduled jobs
SyncedCodes []string
PasswordHashIgnored []string // principals: emails whose hash was not applied
SkippedRoles []string // principals: names that are not roles
Error string
}

Result has one *CategoryResult per category (Roles, EventTypes, DispatchPools, Connections, Subscriptions, Processes, ScheduledJobs, Principals, OpenAPI, Docs), plus HasErrors() and Errors() (a category to message map). SkippedRoles and PasswordHashIgnored are not errors: the sync applied, and those names or hashes were left out. A passwordHash is stored only for a user the sync creates.

SyncAll(ctx, sets, opts) syncs several sets in order; one set’s failures do not stop the next. SyncUsers(ctx, defs) syncs users without an application, keyed by email, and never strips roles from users it does not list.

sync.DefaultOptions() enables every category and leaves RemoveUnlisted false.

Constructor Effect
sync.WithRemoveUnlisted() The defaults, plus: the platform archives or removes SDK-sourced rows that the set no longer lists. Rows created in the console are never touched. For scheduled jobs this is archiveUnlisted.
sync.NoneOptions() Every category off. Switch on the ones you want.
sync.RolesOnly(), EventTypesOnly(), SubscriptionsOnly(), ConnectionsOnly(), DispatchPoolsOnly(), PrincipalsOnly(), ProcessesOnly(), ScheduledJobsOnly(), OpenAPIOnly(), DocsOnly() One category.

Options also has a Sync* boolean per category if you want to build a mix.

The docs sync is always a full replace: the set’s pages are the application’s pages. The OpenAPI sync publishes one document, so RemoveUnlisted does not apply to either.

set.ForClient("acme") scopes the set’s connections and subscriptions to one client. Use the client’s identifier slug; ids differ per environment. Scheduled jobs carry their own ForClient. A multi-tenant application builds one set per client and calls SyncAll. Do not mix sets that share an application and a client with RemoveUnlisted, or the second call can remove what the first created.