Integrate the Social SDK
A mock-first integration path for authorized account connections, durable publishing, per-target outcomes, and verified webhook processing.
This guide turns the Social SDK’s core contracts into an application integration. Keep account ownership in your application, use a real provider callback exchange, and treat each delivery outcome independently.
Build in this order
- Start with
mockBackendandMemoryIdempotencyStorefrom@opencoredev/social-sdk/testing. Exercise success, partial, processing, unknown, and failed outcomes with mock scenarios. - Configure an
AuthorizationPolicyincreateSocial({ authorization })that checks your server-owned grants, and pass{ authorization: { tenantId, principalId } }from the authenticated session to publish and facade calls. The call option alone is not a grant; without a configured policy the client performs no access check. See authorization. - Add
ConnectionManagerfrom@opencoredev/social-sdk/server. Callbeginwith the authenticated tenant and principal and an exact HTTPS callback allowlist,discoverin the callback handler, andselectwith the accounts the user picked. Onlyselectwrites grants. Do not call a provider’scompletemethod directly; the manager checks the principal, state, redirect, expiry, and one-use code claim around it. See connect accounts. - Use the provider factories from
@opencoredev/social-sdk/server, such asxOAuthoryoutubeOAuth, or implementConnectionProviderwith the provider’s documented callback and token APIs. The SDK does not pretend to complete OAuth for a provider it cannot call. - Verify webhook signatures over the untouched request bytes. For managed backends, decode with
decodeWebhook({ provider: "zernio" | "post-for-me", ... }). For direct platform webhooks, decode withdecodePlatformWebhook({ platform, ... }). Resolve account IDs to tenant IDs and callacceptWebhookinto an application-owned inbox. Unmapped events are quarantined; duplicates are acknowledged without reprocessing. See process webhooks. - Replace in-memory stores with durable transactions for connection attempts, grants, credentials, idempotency, and inbox state before production.
Recipes
The repository skill includes TypeScript shapes in references/mock-server.ts, references/connection-callback.ts, references/render-outcomes.ts, references/webhook-handler.ts, and references/integration.test.ts. They are repository examples, not package exports.
Review checklist
- Provider secrets stay on the server.
createSocialhas anAuthorizationPolicy, and every call passes the authenticated tenant and principal.- Every publish result is rendered per target, including
unknownandnot-submitted. - Callback state, redirect URI, tenant, principal, expiry, and replay are checked by
ConnectionManager. - Webhooks are verified before parsing and accepted into a deduplicated inbox before processing.
- Tests cover unauthorized selection, callback replay, duplicate events, partial results, and quarantine.