Publish approved cuts to social platforms through Zernio#146
What
Let an editor publish an approved, locked cut from Relay to the client's social accounts (YouTube, Instagram, TikTok, LinkedIn, Facebook, X and others) through the Zernio API, without Relay building and getting approval for its own OAuth app on each platform.
This is deferred. Fixing the current app issues comes first. Do not start until the blockers below are closed.
Zernio is Late (getlate.dev) under a new name, with the same API and the same sk_ keys (rebrand notice). Research notes with all sources are kept locally in .scratch/social-publishing/research.md.
Blocked by
- #128 Frame-accurate player for uploaded cuts. Today
projectMediaVersions.source(mediaSourceValidatorinapps/web/convex/domainValidators.ts) can only be a YouTube, Vimeo or plain link. Relay has no hosted file for an approved version to send to a platform. Publishing needs the approved version to point at an uploaded file (Convex storagestorageIdor R2r2Key, asprojectFileVersionsalready does). - The current app fixes take priority over this issue.
Related: #129 (YouTube publish with title/thumbnail A/B tests). This issue replaces the "connect and publish" half of #129. The A/B half stays in #129 because no aggregator offers it (see YouTube below).
Decisions already made
- Provider: Zernio. Alternatives are listed at the end in case we need to switch.
- Key model: one Relay-held Zernio API key in the Convex environment (
ZERNIO_API_KEY), and one Zernio profile per workspace (externalId= workspace id). This is the multi-tenant setup Zernio documents (multi-tenant guide). A workspace pasting its own Zernio key is a later option for agencies, stored likeaiProviderKeys(ciphertext + IV). It is not part of this issue. - Tokens: Relay never stores platform OAuth tokens. Zernio holds them. Relay stores only Zernio profile, account and post ids.
- Video transfer: the video never passes through a Convex action. Zernio either fetches it from a short-lived public HTTPS URL, or the browser PUTs it to a Zernio presigned URL (up to 5 GB, valid 1 hour). Reason: Node actions have 512 MB of memory and HTTP action responses are capped at 100 MB (Convex limits).
- Status: webhook first, polling only as a fallback.
- Gate: only an approved (
approvedAtset) andlockedmedia version can be published. Approval is the editor's go-ahead to upload.
How Zernio works (verified 2026-10-28)
- Auth:
Authorization: Bearer sk_.... The key belongs to the Zernio team and can see every profile. Base URLhttps://zernio.com/api/v1. - Connect:
POST /v1/profiles(name,externalId), thenGET /v1/connect/{platform}?profileId=...&redirect_url=...returnsauthUrl. The browser goes there, then returns toredirect_urlwithconnected,profileId,accountId,username. Anaccount.connectedwebhook also fires. Optionalscopes=posting,analytics. Adding scopes later means connecting again. - YouTube connect: there is no channel picker. The channel is whichever Google identity (personal or Brand Account) the user picks. One profile holds one YouTube channel.
- Facebook, LinkedIn, Pinterest, Google Business, Instagram via Facebook: need a second selection (Page, org, board). Zernio hosts that screen by default.
- X: connecting returns
402until the Zernio team has a card on file. X calls are passed through at X's prices. - Publish:
POST /v1/postswithcontent,platforms: [{ platform, accountId, platformSpecificData }],mediaItems, and eitherpublishNow: trueorscheduledFor+timezone. Send anIdempotency-Keyheader. Statuses arescheduled,publishing,published, with per-platform status onpost.platforms[]. - Media:
mediaItems[].urlmust return the raw file (Drive, Dropbox and iCloud share links fail), or usePOST /v1/media/presignand PUT the bytes with no auth header. - Webhooks: register with
POST /v1/webhooks/settings(url, events, a secret we generate). The signature is lowercase hex HMAC-SHA256 of the raw body inX-Zernio-Signature, withX-Zernio-Event-Idfor dedupe. Delivery is at least once and needs a 2xx within 5 seconds, with up to 7 retries. Events:post.scheduled,post.published,post.partial,post.failed,post.platform.published,post.platform.failed,post.cancelled,account.connected,account.disconnected. - Rate limits: per team, not per workspace. 60 requests/min with 0-2 accounts, 600 with 3-2,000. A separate posting cap of 25 posts per hour per account, plus daily caps per platform.
- Pricing (source): per connected account across the whole team. 1-2 free, 3-10 at $6, 11-100 at $3, 101+ at $1 per month. Profiles and posts are free. Example: 50 workspaces each with YouTube and Instagram is 100 accounts, about $318 a month.
- SDK:
@zernio/node(Apache-2.0) publishes several times a day. Pin a version at least 7 days old, or call the REST API withfetch.
YouTube specifics (source)
- One video per post. Up to 256 GB. 15 minutes on unverified channels, 12 hours on verified ones.
platformSpecificData:title(100 chars),visibility(public, private, unlisted),madeForKids,containsSyntheticMedia,categoryId,playlistId. Description up to 5,000 chars. Tags up to 500 chars combined.- Custom thumbnail via
mediaItems[].thumbnail: JPEG, PNG or GIF, 2 MB. Not available for Shorts. - A scheduled public video is uploaded early as private and released by YouTube at the scheduled time.
- After publishing, the description can be edited. Title and tags use a separate endpoint.
- Not supported: title/thumbnail A/B tests ("Test & compare"). That is a YouTube Studio feature with no aggregator API. It stays in #129.
Plan
Data model (new tables in apps/web/convex/schema.ts)
socialProfiles:workspaceId,provider("zernio"),profileId. Index onworkspaceId.socialAccounts:workspaceId,profileId,accountId,platform,username,needsReconnect,connectedByUserId,connectedAt. Indexes onworkspaceIdandaccountId.socialPublications: one row per publish attempt.workspaceId,projectId,outputId,mediaVersionId,providerPostId,idempotencyKey,status(queued,scheduled,publishing,published,partial,failed,cancelled),scheduledFor,requestedByUserId,createdAt. Indexes onmediaVersionIdandproviderPostId.socialPublicationTargets:publicationId,accountId,platform,status,platformPostUrl,errorCode. Index onpublicationId.socialWebhookEvents:eventId(unique index),receivedAt.
Use typed validators for every status and platform union. No v.any().
Convex functions
| Function | Type | Job |
|---|---|---|
ensureProfile | internal action | Create the workspace's Zernio profile once. On 409, store the existing profile id. |
startConnect | action | Owner/admin only. Returns authUrl for one platform. redirect_url is a Relay settings page. |
completeConnect | mutation | Called by the return page with accountId and username. Checks that the profile belongs to the caller's workspace. |
listAccounts | query | Reads socialAccounts for the active workspace. |
refreshAccounts | action | GET /v1/accounts?profileId= and account health, to update needsReconnect. |
disconnectAccount | action | Owner/admin only. Removes the account in Zernio and marks it removed. |
requestPublish | mutation | Checks membership, that the version is approved and locked, and that every target account belongs to this workspace. Inserts a queued publication and schedules publish. |
publish | internal action | Gets a short-lived file URL, calls POST /v1/posts with Idempotency-Key, stores providerPostId. Failures set failed with an error code. |
zernioWebhook | httpAction in convex/http.ts | Reads the raw body, checks the HMAC against ZERNIO_WEBHOOK_SECRET in constant time, ignores duplicate event ids, schedules applyWebhookEvent, returns 200 right away. |
applyWebhookEvent | internal mutation | Updates publication and target status, and account connect/disconnect state. |
pollPublication | internal action, scheduled | Calls GET /v1/posts/{id} if no final webhook has arrived by a deadline. |
UI
- Settings, Social accounts: connect, reconnect and disconnect per platform for the workspace. Owner/admin only. Uses existing
components/uiandworkspace-pageparts. One primary action in the top bar. - Approved output, Publish: pick accounts, then fill title, description, tags, visibility, thumbnail (YouTube) and publish now or schedule. A confirm step shows everything that will be sent, plus one plain line saying the video is sent to Zernio and the selected platforms.
- Status: each target shows a word status (Scheduled, Publishing, Published, Failed) and a link to the live post. Failed targets show a retry button.
Acceptance criteria
- A workspace owner connects at least YouTube and one Meta platform through Zernio's hosted flow, and the account appears in Settings without a page reload.
- Closing the tab during connect still records the account through the
account.connectedwebhook. - No Zernio key, webhook secret or file URL appears in a query response, a log line or a client-visible error.
- Publishing is only possible for an approved, locked media version that has a hosted file. The server rejects every other case, not just the UI.
- Target accounts must belong to the publishing workspace. This is enforced in the mutation.
- Retrying a publish reuses the idempotency key, so a retry never creates a duplicate post.
- The video never passes through a Convex action's memory.
- The webhook rejects a bad signature with 401, ignores duplicate event ids and returns 2xx within 5 seconds.
- A publication is never marked
publishedwithout aproviderPostId. Partial and failed targets are shown with a retry. - YouTube posts send title, description, tags, visibility, thumbnail and an optional schedule time.
- Disconnecting an account in Settings removes it from Zernio and from the publish picker.
- Privacy policy and the trust page name Zernio as a processor for published videos before release.
- Tests (convex-test): approved/locked gate, cross-workspace refusal, webhook signature and dedupe, status mapping for each event, idempotent retry.
- Manual check: publish an approved cut to a private YouTube test channel and one other platform, then confirm both statuses update from webhooks.
pnpm check:designpasses for the new screens.
Risks
- Privacy: the approved cut leaves Relay. Zernio stores a copy (temp for 7 days, permanent once a post uses it) and the platform fetches it. Some client contracts may forbid that. The confirm step and the privacy policy must say so.
- Shared limits and bans: every workspace shares one Zernio team's rate limit and Zernio's platform apps. An enforcement action against Zernio's app on a platform breaks publishing for everyone at once.
- Lock-in: account and post ids are Zernio ids. Switching providers means users reconnect every account.
- Cost: grows with connected accounts across all workspaces. Decide whether this is gated to a paid plan before release.
- File URL exposure: a Convex
storage.getUrlURL works for anyone who has it until the file is deleted. Prefer presigned R2 URLs with a short expiry.
Open questions
- Which plan includes publishing, and is there a per-workspace account limit?
- Is the file URL Zernio fetches an R2 presigned GET URL (with expiry) or a Convex storage URL? R2 is preferred.
- Does Zernio's YouTube analytics work on every account, or does it need the analytics add-on that one endpoint mentions? The pricing page says it is included.
Alternatives considered
| Provider | Fit | Notes |
|---|---|---|
| Upload-Post | Cheaper, publish only | One key, many users, white-label connect link. From $24/mo for 5 profiles. |
| Ayrshare | Same one-key, many-profiles setup | Higher price (Business from about $499-599/mo). X needs our own X app keys. |
| Postiz | Self-host | Keeps files off a vendor's storage. More to operate. |
| Buffer | Poor fit | An API key is one Buffer account. The API lists text and image posts only. |