Web API and domain services
The web API and domain services form Cap's shared backend boundary. They turn requests from the web app, desktop app, mobile app, developer products, agents, and connected services into checked product actions for recordings, transcripts, storage, sharing, organizations, and billing. See Web product and collaborative workspace for product context, Web application routes and components for the UI boundary, Developer infrastructure platform for infrastructure products, and Infrastructure MCP tooling for the MCP surface.
Service boundary
Shared domain model
The shared domain model gives clients and backend services common names for users, organizations, spaces, videos, storage, identity, policies, and errors. This common language keeps an action such as reading a video or changing access rules consistent across API families.
References: packages/…/README.md• L1-10 packages/…/index.ts• L1-27 packages/…/Video.ts• L13-56 packages/…/Organisation.ts• L16-30
Backend service layers
The backend service layer combines data access, access checks, storage, billing, analytics, and background work into product operations. API handlers use these operations so that the same rule applies to browser, desktop, mobile, developer, and agent requests.
References: packages/…/README.md• L3-36 packages/…/index.ts• L1-48 packages/…/index.ts• L97-111
Service environment
The web server creates one live environment for database, storage, policy, domain, and workflow services. Each transport adds its own request concerns, such as identity, CORS, tracing, and error mapping, before it calls a shared operation.
References: apps/…/server.ts• L108-190 packages/…/Live.ts• L1-11 apps/…/infra-mcp-server.ts• L23-73
API contracts
HTTP and RPC contracts
The HTTP and RPC contracts define request data, response data, identity needs, and domain errors before a request reaches a handler. The main web API is under /api, and shared RPC operations are under /api/erpc.
References: packages/…/Api.ts• L1-14 packages/…/Rpcs.ts• L1-13 apps/…/api-errors.ts• L1-63
Client transport families
Desktop, mobile, developer, agent, and selected web features use focused contracts in addition to the shared HTTP and RPC surfaces. These contracts are related but not interchangeable. A response or error change must follow the client family that consumes it.
References: packages/…/index.ts• L1-18 packages/…/desktop.ts• L96-145 packages/…/index.ts• L85-159
Developer API
The developer API lets an outside product host video and turn audio or video into text. A server uses a secret key for app-level operations. A browser receives a short-lived upload token for the file transfer only, so the server secret does not cross into browser code.
The REST contract covers videos, URL imports, uploads, transcripts, usage, credit transactions, and webhook endpoints. It also defines hosted playback and embed links, stable status values, paging, idempotency, rate-limit guidance, and machine-readable errors. The OpenAPI document is the public description of these contracts and is also used by agent discovery. URL imports report clear admission and download failures, while direct uploads remain the path for files that are local, large, or slow.
References: apps/…/developer-openapi.ts• L605-669 apps/…/developer-openapi.ts• L693-763 apps/…/developer-openapi.ts• L812-1013 apps/…/agent-discovery.ts• L17-83
Developer authentication
Developer credentials separate app administration from browser file transfer. Secret keys create resources and read app data. Upload tokens bind one browser transfer to one app and one video, with limits for time, origin, and bytes. Public keys cannot create or upload videos.
This split lets a product keep its secret on its server while still giving a browser a narrow upload capability. Idempotency keys make repeated create requests return the same resource instead of creating a second one.
References: apps/…/developer-upload-token.ts• L6-15 apps/…/developer-upload-token.ts• L49-111 apps/…/developer-ids.ts• L28-66 apps/…/developer-video-ids.ts• L9-17
Agent interfaces
Agent access exposes product data and Cap Infra actions through documented HTTP and MCP interfaces. Read-only Cap access reports its server card and Markdown content for tools that prefer machine-readable pages. Cap Infra MCP uses the same developer secret checks, rate limits, and REST handlers as direct API calls.
Agent authorization uses short-lived grants and proof of possession before it issues a bearer token. MCP clients register allowed redirect addresses, complete a PKCE-based authorization flow for the caps:read resource, and use short-lived access tokens with refresh-token rotation. Token revocation also covers the token family, so a reused or revoked refresh token cannot keep a client active.
References: apps/…/agent-discovery.ts• L19-109 apps/…/agent-markdown.ts• L15-46 apps/…/agent-token.ts• L45-134 apps/…/agent-token.ts• L137-170 apps/…/mcp-auth.ts• L23-87 apps/…/mcp-auth.ts• L172-198 apps/…/mcp-auth.ts• L206-238 apps/…/mcp-auth.ts• L292-388 apps/…/infra-mcp-endpoint.ts• L143-197 apps/…/infra-mcp-server.ts• L17-73 apps/…/infra-mcp-rest.ts• L27-47
Webhook contracts
Developer webhooks tell an outside product when a video becomes ready or fails. Each endpoint has a stored signing secret, a selected event set, a bounded retry window, and a failure state that can disable delivery. Event IDs stay stable across retries so receivers can ignore work they already applied.
References: apps/…/developer-webhooks.ts• L134-189 apps/…/developer-webhook-events.ts• L7-52 apps/…/developer-webhook-signature.ts• L19-73 apps/…/developer-webhook-delivery.ts• L110-197
Error contracts
API errors tell a caller what kind of action is safe next. Validation, authentication, access, payment, conflict, rate, not-found, and temporary service errors keep stable codes and useful hints across transport families. Console errors use a safe customer-facing fallback when an internal response is not an approved upload refusal.
References: apps/…/api-errors.ts• L5-63 apps/…/developer-transcript-errors.ts• L3-135 apps/…/infra-console-errors.ts• L53-97
Rate limits
Rate limits protect costly, sensitive, or abuse-prone operations. Production requests use shared firewall rules when available. A local fixed-window limit acts as a backstop when the shared rule cannot answer.
Developer secret-key, account-wide, upload-token, authentication-failure, import, passkey, and email-code limits use separate buckets because administration, file transfer, authentication, and resource intake have different risk and volume. Email-code buckets normalize addresses before hashing, so equivalent accented spellings use the same bucket as the verification records. Responses expose retry information so callers can wait instead of repeating a failing request.
The shared rule set also protects guest checkout, support messenger messages and polls, password attempts, media processing retries, and developer API traffic. Each operation can use a caller, account, resource, email, or network as its limit key. The firewall decision is final when available; the local limit is only a per-instance safety net.
References: apps/…/rate-limit.ts• L20-77 apps/…/rate-limit.ts• L164-247 apps/…/rate-limit.ts• L249-363 apps/…/email-code-rate-limit.ts• L4-34 apps/…/developer-rate-limits.ts• L1-19 apps/…/infra-video-import.ts• L472-547
Request lifecycle
The normal request path moves from a client contract to identity, policy, a domain operation, and a mapped result. The same shape applies to an authenticated API request, RPC call, server action, webhook, MCP call, or protected scheduled job.
This diagram shows how a request becomes a product result while storage, billing, and background work remain behind the service boundary.
flowchart LR
A[Client or external event] --> B[Contract and input checks]
B --> C[Identity and request context]
C --> D[Policy and entitlement checks]
D --> E[Domain operation]
E --> F[Database storage billing or workflow]
F --> G[Stable result or domain error]
Authentication context
Authentication turns a web session, user API key, developer secret, upload token, desktop handoff, mobile bearer token, passkey result, or agent grant into request context. Services receive the resulting identity and scope instead of handling raw credentials in every operation.
Passkey sign-in maps the authentication callback to a small result set that distinguishes success, an unlinked credential, a blocked account, rate limiting, and other failure. The web app offers a first passkey only after a fresh sign-in when the user has no passkeys and has not recently deferred the prompt. A cancelled browser ceremony is treated as a user cancellation rather than as a service fault.
References: apps/…/developer-upload-token.ts• L68-111 apps/…/agent-token.ts• L45-134 apps/…/mcp-auth.ts• L341-366 apps/…/passkey-prompt.ts• L8-35 apps/…/passkey-sign-in.ts• L3-40 apps/…/passkey-errors.ts• L1-9 apps/…/infra-mcp-endpoint.ts• L143-195 apps/…/developer-ids.ts• L44-49
Policy enforcement
Policies decide whether the current actor can see or change a resource. The model covers ownership, organization and space membership, public links, passwords, plan gates, developer app ownership, embed origins, and billing standing.
References: packages/…/Policy.ts• L8-24 apps/…/infra-standing.ts• L614-686 apps/…/developer-embed-origins.ts• L21-71 apps/…/infra-domain.ts• L21-72
Error mapping
Domain failures become transport errors at the API edge. The adapter keeps the meaning of not found, forbidden, invalid input, payment required, conflict, rate limit, and temporary failure while hiding internal service details.
References: apps/…/api-errors.ts• L13-63 apps/…/developer-transcript-store.ts• L70-174 apps/…/infra-console-errors.ts• L67-97
Domain operations
Video upload and publication
Video upload separates byte transfer from publication. The service creates a video record, checks storage standing, opens or reuses a multipart upload, validates the stored parts, and records the video only after the object is complete.
The same boundary supports direct uploads and imports from public URLs. Imports check the source before creating a video, reserve bounded app and key capacity, stream the file into storage, and use the upload path for final admission. Idempotent retries return the same video, while a bounded recovery pass closes downloads that stop reporting.
References: apps/…/infra-video-upload.ts• L453-517 apps/…/infra-video-upload.ts• L729-895 apps/…/infra-video-import-limits.ts• L3-26 apps/…/infra-video-import.ts• L210-255 apps/…/infra-video-import.ts• L715-863 apps/…/infra-video-import.ts• L1027-1197 apps/…/infra-video-import.ts• L1290-1346
Video processing
Video processing turns a stored source into a usable player result. It measures the source, checks the measured duration and resolution against the app's credit standing, and coordinates MP4, poster, and adaptive streaming outputs with the media service.
A video can become ready when one usable output exists. The service keeps enough state to retry a stalled job, reject late results from an old attempt, expose HLS while long videos are still being encoded, and stop work for deleted content.
References: apps/…/developer-video-processing.ts• L214-315 apps/…/developer-video-state.ts• L311-383 apps/…/developer-video-slices.ts• L242-265 apps/…/developer-video-cancel.ts• L56-98
Product media imports
Product media imports expose a small state model that separates waiting for work, active transfer, completion, and failure. The model lets the web application show progress without exposing worker-specific error text, and marks recoverable processing failures as retrying when raw media is still available.
References: apps/…/loom-import-status.ts• L3-29 apps/…/loom-import-status.ts• L52-81
Video editing
Video editing keeps a stable identity for the original source while processing a new result. This lets edit and processing flows distinguish the source object from other video files and avoid applying source-specific work to unrelated objects.
References: apps/…/video-edit-processing.ts• L1-19
Playback and embedding
Playback gives a ready video signed HLS, MP4, poster, caption, hosted-player, and embed results. It applies app standing and takedown state at the playback boundary, so a paused or removed resource does not continue to serve as normal.
Embed access can be open or limited to an app's allowed website origins. Web embeds keep one option model for title, owner, branding, autoplay, muting, and start time. Share presentation can also apply a custom thumbnail, a workspace or video call to action, and a plan-gated player brand with a readable control color.
The player and oEmbed responses use the same resource state, while short cache bounds and cache purge keep deletes and takedowns visible quickly. Poster generation falls back to a playable source when a processed screenshot is not ready yet.
References: apps/…/developer-video-playback.ts• L525-673 apps/…/developer-video-player.ts• L66-103 apps/…/developer-embed-origins.ts• L21-71 apps/…/developer-video-oembed.ts• L125-160 apps/…/developer-video-cache.ts• L1-39 apps/…/embed-options.ts• L1-68 apps/…/embed-code.ts• L9-45 apps/…/custom-thumbnail.ts• L1-74 apps/…/player-brand.ts• L4-19 apps/…/player-brand.ts• L56-73 apps/…/share-call-to-action.ts• L112-145 apps/…/poster-frame.ts• L95-126
Video takedown and deletion
Takedown hides a video from hosted playback without changing its normal processing state. Customer or staff deletion retires the resource, stops active encodes, removes cached playback, and purges stored objects after the late-write window.
This separates an immediate public safety result from the later storage cleanup needed to handle workers that finish after deletion.
References: apps/…/developer-video-takedown-store.ts• L51-90 apps/…/developer-video-delete.ts• L8-21 apps/…/developer-video-purge.ts• L60-131 apps/…/developer-video-takedown.ts• L23-69
Transcript creation
The transcript service accepts a public media URL, a file uploaded to a signed target, or a ready video owned by the app. It validates source rules, file size, language, metadata, and app capacity before it moves the transcript through uploading, queued, processing, complete, or error states.
An idempotency key identifies a repeat of the same request. A repeat returns the existing transcript and can renew an upload target. A different request with the same key is refused.
References: apps/…/developer-transcript-store.ts• L185-260 apps/…/developer-transcript-store.ts• L454-565 apps/…/developer-transcript-store.ts• L588-723 apps/…/developer-transcripts.ts• L51-104
Transcript processing and captions
Transcript processing measures or extracts audio, sends it to the speech service, stores text and timings, and settles the actual cost. A bounded credit hold protects concurrent work, and a failed or timed-out run releases the hold rather than charging it.
Completed transcripts for videos can produce WebVTT caption tracks. The newest completed transcript for a language controls the track, and the player exposes it through both direct captions and HLS subtitle playlists.
References: apps/…/developer-transcript-billing.ts• L127-199 apps/…/developer-transcript-billing.ts• L268-394 apps/…/developer-transcript-run.ts• L20-83 apps/…/developer-video-captions.ts• L102-147 apps/…/developer-transcript-vtt.ts• L119-185
Transcript cleanup
Cleanup protects storage and work capacity after a client or worker stops. It expires old upload and processing states, retries queued work that was not dispatched, removes stale objects, and reconciles caption files after transcript deletion.
References: apps/…/developer-transcript-store.ts• L1044-1104 apps/…/developer-transcript-store.ts• L1110-1269 apps/…/developer-transcript-storage.ts• L166-197
Credit account
Each developer app has a credit account that records additions, usage, holds, refunds, disputes, storage, delivery, and balance history. A balance change and its ledger entry form one product action, while stable payment or resource references make repeated events safe.
References: apps/…/developer-credits.ts• L16-103 apps/…/developer-credits.ts• L124-210 apps/…/infra-ledger.ts• L8-19 apps/…/infra-ledger-store.ts• L83-116
Storage standing
Storage standing describes whether an app is active, in a grace period, or paused. Daily storage and delivery charges compare retained or delivered usage with available credit and keep a shortfall until later credit resolves it.
Uploads are blocked when the app is out of credit or has a disputed payment. Playback continues during the grace period and pauses after it unless credit restores the account.
References: apps/…/infra-standing.ts• L27-64 apps/…/infra-standing.ts• L117-136 apps/…/infra-standing.ts• L552-686 apps/…/infra-storage-billing.ts• L86-264
Delivery metering
Delivery metering turns CDN log records into delivered video seconds by resolution tier. HLS ranges use playlist segments when available; MP4 transfers use a video rate estimate. Abandoned transfers remain separate from delivered seconds.
The billing layer settles final days once, writes delivery usage to the credit ledger, and feeds the same standing and auto top-up rules used by storage billing.
References: apps/…/infra-delivery-log.ts• L65-117 apps/…/infra-delivery-log.ts• L183-205 apps/…/infra-delivery-log.ts• L416-462 apps/…/infra-delivery-log.ts• L541-587 apps/…/infra-delivery-metering.ts• L186-337 apps/…/infra-delivery-billing.ts• L33-70 apps/…/infra-delivery-billing.ts• L103-206
Credit purchases and auto top-ups
The billing service supports manual credit checkout, saved cards, automatic top-ups, monthly Cap Pro credit, and credit codes. Payment metadata ties a payment to one app credit account before a webhook or reconciliation step adds balance.
Auto top-ups run only below the account threshold and within account and owner limits. Pending payments, declines, refunds, and disputes remain visible in ledger state so a retry cannot add credit twice.
References: apps/…/infra-credit-checkout.ts• L31-82 apps/…/developer-card-checkout.ts• L34-102 apps/…/infra-auto-top-up.ts• L641-878 apps/…/infra-pro-credit.ts• L153-289
Webhook operations
Stripe, media-server, and developer webhook flows turn signed external events into local billing, processing, or customer state. They use resource identity, payment metadata, event IDs, processing tokens, and bounded retry behavior so duplicate or late events do not apply to a different operation.
References: apps/…/developer-webhook-dispatch.ts• L69-123 apps/…/developer-webhook-delivery.ts• L199-305 apps/…/developer-webhook-events.ts• L67-112 apps/…/developer-webhook-input.ts• L22-36
AI generation
AI generation is a follow-on domain operation for a recording whose transcription is complete. The service accepts a safe retry request, marks one generation as queued, and starts background work without allowing two requests to generate the same result at once.
References: apps/…/generate-ai.ts• L18-46 apps/…/generate-ai.ts• L58-162
Checkout plans and discounts
Checkout services turn plan, seat, currency, promotion, and referral input into a Stripe-compatible purchase. They normalize the purchase choices first, then apply a campaign or partner discount without making a valid payment depend on an external discount record.
Signed-in buyers can receive a partner discount after an existing referral is found or a valid click is attached to the user. Guest buyers carry a safe referral reference into the purchase because they do not yet have a Cap user. If Stripe rejects a stale or ineligible discount, checkout retries without that discount or restores the normal promotion-code path.
References: apps/…/plans.ts• L4-22 apps/…/plans.ts• L24-67 apps/…/promotion.ts• L5-43 apps/…/referral.ts• L16-33 apps/…/referral.ts• L35-93
License purchase and redemption
License redemption connects gift links and completed purchases to the commercial license service. The web application accepts either a validated license key or checkout session and presents stable states for claimable, redeemed, missing, pending, rate-limited, and unavailable results.
The flow removes a key or session from the visible return URL before normal page work continues. Purchase results preserve each license position and distinguish an unclaimed key from a license already claimed by its recipient.
References: apps/…/license-redeem.ts• L1-59 apps/…/license-redeem.ts• L62-107 apps/…/license-redeem.ts• L133-243 apps/…/license-redeem.ts• L257-285
Share access and download access
Share services apply video, organization, space, password, link, quota, and processing rules before they expose metadata or playback. Download access is narrower than view access for outside viewers, and the RPC and object routes use the same result.
Public share eligibility also excludes active uploads, screenshots, incomplete processing, and inherited passwords. This keeps a link from becoming public only because one access check omitted a workspace rule.
References: apps/…/public-share-video.ts• L14-65 apps/…/public-share-video.ts• L67-148 apps/…/link-access.ts• L5-52 apps/…/video-download-access.ts• L29-100 apps/…/video-download-permissions.ts• L12-99
Organization and workspace operations
Organization services keep member access, spaces, seats, invites, and workspace limits aligned. Move operations keep videos and folders within valid personal, organization, or space locations and prevent a folder from moving into itself.
Folder queries present the same video with its shared spaces, inherited access rules, counts, and active-upload state. Workspace settings writes preserve keys owned by separate access and call-to-action flows instead of restoring stale values from an earlier read.
Directory sync extends these operations to an external identity directory. It provisions active users with approved domains, removes inactive members only after checking other directory links, and revokes credentials when a managed user no longer has access. Leases, time budgets, paging, and a hold for unusually large removals keep a slow or bad external snapshot from causing broad access loss.
References: apps/…/organization-member-removal.ts• L16-66 apps/…/move-items.ts• L1-92 apps/…/workspace-creation-limits.ts• L7-85 apps/…/folder.ts• L171-395 apps/…/organization-settings-write.ts• L4-20 apps/…/directory-sync.ts• L56-93 apps/…/directory-sync.ts• L120-252 apps/…/directory-sync.ts• L255-361 apps/…/directory-sync.ts• L364-541 apps/…/directory-sync.ts• L544-675
Media input policy
Media input policy records repeated rejected processing inputs for a user. When the threshold is reached, it suspends personal media processing and custom storage, then sends one operational notice so the account can be reviewed and restored safely.
The policy also keeps unsupported playlists and document-like inputs from entering video processing. It gives upload completion a safe content type for non-media objects so they remain downloads rather than playable media.
References: apps/…/media-processing-policy.ts• L6-12 apps/…/media-processing-policy.ts• L14-115 apps/…/media-processing-policy.ts• L118-201 apps/…/media-input-policy-strikes.ts• L18-47 apps/…/media-input-policy-strikes.ts• L50-115
Messenger conversations
Messenger provides a support conversation service for anonymous visitors, signed-in users, and an approved admin. An anonymous conversation can become attached to a user after sign-in, while reads remain limited to the matching user or anonymous cookie unless the admin view is explicitly allowed.
The web client requests only messages after its last confirmed message. It backs off when no change arrives, slows polling for hidden pages, and ignores results that are stale or overlap an active send. This keeps agent or human takeover updates visible without duplicating optimistic messages.
References: apps/…/data.ts• L23-109 apps/…/data.ts• L163-229 apps/…/data.ts• L232-329 apps/…/use-messenger-poll.ts• L28-45 apps/…/use-messenger-poll.ts• L69-151
Web application consumption
Server handler composition
Next.js handlers compose transport validation with shared authentication, policy, storage, database, billing, and workflow services. The handler owns the response shape, while the service boundary owns the product action.
References: apps/…/server.ts• L108-190 apps/…/infra-mcp-endpoint.ts• L143-197 apps/…/infra-mcp-rest.ts• L27-47
Browser RPC consumption
The browser uses typed RPC calls for shared operations such as thumbnails, analytics, and download access. Request resolvers batch repeated reads so a page can load many video cards through bounded backend calls.
References: apps/…/Rpcs.ts• L1-17 apps/…/ThumbnailRequest.ts• L16-54 apps/…/AnalyticsRequest.ts• L14-52
Server action consumption
Server actions provide a direct application boundary for operations that need Next.js behavior or a page-specific result. They still use shared identity and domain rules, then refresh affected pages so the browser sees the new server state.
References: apps/…/create-for-processing.ts• L21-128 apps/…/save-edits.ts• L11-23 apps/…/update-details.ts• L11-57
Authentication consumption
Authentication screens consume shared sign-in and account state through small result contracts. Passkey completion posts a CSRF-protected response to the auth boundary, then turns the returned redirect state into a safe browser result instead of exposing raw provider errors to the page.
References: apps/…/passkey-sign-in.ts• L10-40 apps/…/passkey-errors.ts• L1-9 apps/…/passkey-prompt.ts• L24-35
Commercial purchase consumption
Checkout and redemption pages consume shared commercial contracts rather than reading payment or license records directly. Checkout passes normalized plan and discount choices to the payment boundary, while redemption maps remote results to safe page states and preserves the intent across redirects.
References: apps/…/plans.ts• L41-75 apps/…/promotion.ts• L23-43 apps/…/referral.ts• L71-93 apps/…/license-redeem.ts• L62-107 apps/…/license-redeem.ts• L173-243
Dashboard and workspace consumption
Dashboard and workspace screens consume bounded lists and stable ordering rules for personal videos, archives, spaces, and organizations. Selection can span pages, bulk archive work is capped and chunked, and a space can use newest, oldest, or custom order without changing the meaning of “next” on its share page.
References: apps/…/dashboard-page-size.ts• L1-35 apps/…/cap-selection.ts• L1-79 apps/…/select-all-view.ts• L1-7 apps/…/video-archive.ts• L1-8 apps/…/space-video-order.ts• L1-93 apps/…/space-video-order-query.ts• L35-75 apps/…/space-up-next.ts• L20-69
Effect query consumption
Effect query helpers connect typed backend effects to browser query and mutation state. They preserve typed failures and support cancellation through the query lifecycle, so UI code can use shared service results without rebuilding error handling.
References: apps/…/effect-react-query.ts• L27-171 apps/…/effect-react-query.ts• L184-492
Storage and media clients
Storage clients hide provider differences behind upload, signed-read, multipart, copy, delete, and quota operations. The media client hides worker authentication, job status, and retry behavior. The product layer can therefore keep one recording model while storage or media providers change.
References: apps/…/developer-video-storage.ts• L51-209 apps/…/developer-transcript-storage.ts• L19-163 apps/…/media-client.ts• L56-103 apps/…/media-client.ts• L326-462 apps/…/share-playback.ts• L18-62
Public media intake
Public media intake protects URL-based transcript, import, webhook, and storage operations from private network access, unsafe redirects, unsupported sources, and oversized streams. Media sniffing distinguishes self-contained files from playlists before a worker or speech service accepts the source.
References: apps/…/public-media-fetch.ts• L97-197 apps/…/s3-endpoint-policy.ts• L75-169 apps/…/storage-fetch.ts• L116-141 apps/…/media-container.ts• L142-225
Share surface consumption
Share pages, embeds, metadata endpoints, and Slack unfurls consume one public-video result before they build their own response. This keeps title, owner, dimensions, duration, thumbnail version, canonical links, and playback eligibility aligned across browser and external surfaces.
References: apps/…/public-share-video.ts• L67-148 apps/…/share-video-metadata.ts• L31-95 apps/…/share-video-metadata.ts• L97-202 apps/…/oembed.ts• L64-154 apps/…/unfurl.ts• L49-86 apps/…/unfurl.ts• L168-237
Markdown and discovery consumption
The web application serves selected product and API pages as Markdown for agents. Content negotiation keeps normal browser pages unchanged, while explicit Markdown routes and public discovery responses point tools to the product overview, API docs, OpenAPI description, and MCP setup.
References: apps/…/agent-markdown.ts• L15-62 apps/…/agent-markdown.ts• L100-149 apps/…/docs-markdown.ts• L22-79 apps/…/infra-markdown.ts• L23-53
Search-facing page consumption
Search-facing pages use one slug to select both the page content and its search metadata. The registry supplies the rendered product page, while the metadata map supplies its title, description, keywords, and share image so public discovery surfaces describe the same product page.
References: apps/…/seo-pages.ts• L85-180 apps/…/seo-metadata.ts• L3-21 apps/…/seo-metadata.ts• L333-354
Change checklist
When these files or sections are changed, remember to consider these:
- Changes to developer video, import, or transcript states must stay aligned across REST responses, OpenAPI descriptions, console views, agent responses, webhooks, cleanup jobs, captions, and playback behavior.
- Changes to developer authentication must preserve the split between server secret keys, browser upload tokens, public keys, CORS origins, expiry, ownership, and rate-limit headers.
- Changes to agent or MCP authorization must preserve redirect URI checks, PKCE verification, resource binding, one-use grants, token expiry, refresh-token family revocation, and sign-out invalidation.
- Changes to passkey sign-in or prompts must preserve the distinction between a cancelled ceremony, an unlinked credential, a blocked account, a rate limit, and a service failure.
- Changes to authentication rate limits must keep email normalization aligned with verification lookup and keep passkey limits applied to both ceremony start and completion.
- Changes to credit admission, holds, storage charges, delivery charges, or transcript settlement must preserve the account lock, available balance, ledger reference, and retry idempotency together.
- Changes to upload measurement or processing output must update admission, status, playback URLs, storage billing, delivery metering, and public status together.
- Changes to playback, share links, embeds, thumbnails, or downloads must keep view policy, credit standing, signed URL scope, allowed origins, cache behavior, player options, and object identity aligned.
- Changes to share call-to-action or player branding settings must preserve video overrides, workspace defaults, plan gates, URL validation, and readable player controls across share and embed surfaces.
- Changes to webhook event states must preserve stable event IDs, signature inputs, endpoint subscriptions, retry behavior, and receiver guidance.
- Changes to public URL intake must preserve redirect checks, private-address checks, source format checks, size limits, concurrency limits, retry windows, and external-provider URL expiry rules.
- Changes to space ordering, page limits, selection, or bulk archive behavior must preserve stable tie-breakers, off-page selection, bounded work, and the meaning of the next video.
- Changes to MCP or Markdown discovery must keep server cards, OpenAPI links, docs links, authentication wording, and in-process REST behavior consistent.
- Changes to cleanup limits or continuation cursors must preserve bounded work, repeat safety, and the distinction between stale temporary data and user-visible records.
- Changes to user preference or organization settings writes must preserve JSON object defaults and keys owned by separate settings flows.
- Changes to directory sync must preserve organization identity checks, external directory pagination, sync leases, verified-domain admission, multi-directory retention, removal approval, and credential revocation.
- Changes to checkout plans, promotion codes, or referrals must preserve plan price mapping, seat bounds, currency compatibility, guest attribution, and the fallback path when Stripe rejects a discount.
- Changes to license redemption must preserve intent validation, URL cleanup, stable refused states, and the distinction between claimed and unclaimed licenses.
- Changes to messenger access or polling must preserve anonymous-to-user linking, admin-only reads, message cursors, optimistic-message filtering, and stale-response checks.
- Changes to SEO page slugs must keep the rendered page and its metadata entry aligned, including the Open Graph image for public sharing.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A developer secret key reaches browser code | Any page visitor can use the app's administration credential | Create the resource on the server and pass only its bound upload token to the browser |
| An upload token is used for another app or video | A caller can write bytes to a different product resource | Verify the signed app and video binding before every upload operation |
| Multipart completion trusts the request without checking stored parts | Incomplete or different bytes become the published video | Compare part numbers, ETags, sizes, and the assembled object before recording completion |
| A URL import follows a redirect into a private address | The service can reach an internal host or metadata endpoint | Recheck every redirect with scheme and public-address guards |
| An import has no active or rate limit | One app or key can consume all download and storage capacity | Reserve slots in a transaction and return retry information when a limit is reached |
| An import worker stops without closing its state | A video stays in uploading and a capacity slot remains occupied | Reap stalled rows with a bounded recovery pass and update the import and video together |
| A transcript starts without enough available credit | Concurrent work can spend more than the app balance | Hold credit while processing and subtract other active holds from admission |
| A repeated payment or webhook event lacks a stable reference | One payment or event can apply more than once | Use payment, resource, and event references inside the account transaction |
| A media callback accepts an old processing token | A late worker can publish output from a replaced attempt | Match the current video, encode, part, and job token before applying progress |
| Playback ignores paused standing, takedown, or inherited share rules | A removed, unpaid, or restricted video continues to serve | Apply standing, access, and takedown at the playback boundary |
| A share or embed surface skips public eligibility checks | A private, incomplete, or password-protected video appears in an external preview | Build external responses from the checked public-share result |
| A webhook receiver trusts the body without verifying the signature and event ID | An attacker or retry can cause an untrusted or repeated action | Verify the raw body, timestamp, signature, and event ID |
| A settings update writes a stale workspace-owned key | A separate access or call-to-action change is silently lost | Preserve row-owned keys in the database write |
| A cleanup job runs without a bounded page or time budget | A large backlog can time out and leave partial work unclear | Use pages, cursors, budgets, and safe continuation requests |
| A stale or restricted promotion or referral discount is treated as a required payment condition | A buyer cannot complete a valid checkout | Retry without the rejected discount and keep the ordinary promotion-code path available |
| A license key or checkout session remains in the return URL | Analytics, browser history, or a copied link can expose a redeem credential | Validate the intent early, move it to tab storage, and replace the visible URL |
| Messenger polling applies a result from an older message version | New or optimistic messages can be duplicated or overwritten | Use a message cursor and reject stale requests while sending or after a newer update |
| An unsupported raw upload is treated as processable video | A worker can spend resources on a playlist or non-media file | Apply the media input extension gate and preserve non-media content as a download |
| An agent or MCP grant is replayed or used for another client or resource | A credential can be minted outside the approved account and scope | Consume grants once and bind every exchange to the verifier, redirect, client, resource, and account |
| An MCP refresh token is reused after rotation | A stolen token can keep minting access tokens | Revoke the full token family when a revoked refresh token is presented |
| Equivalent email spellings use different verification buckets | Address-based OTP limits can be bypassed with accent variants | Normalize the email before hashing the rate-limit key |
| A directory snapshot reports many users as inactive | A valid organization can lose access at once | Hold unusually large removals and require recent approval before deprovisioning |
| A page slug exists in only the content or metadata registry | Search results or shared previews can point to an incomplete public page | Add and review the slug in both registries as one public contract |
Key files
| File | Why to read it |
|---|---|
| packages/…/Api.ts | Defines the main HTTP contract. |
| packages/…/Rpcs.ts | Defines shared RPC operation groups. |
| packages/…/README.md | Explains repository, policy, and service roles. |
| apps/…/server.ts | Builds the live service environment used by handlers. |
| apps/…/api-errors.ts | Defines common API error shape and docs links. |
| apps/…/developer-openapi.ts | Describes the public developer API and lifecycle. |
| apps/…/developer-upload-token.ts | Defines the browser upload credential boundary. |
| apps/…/agent-token.ts | Defines one-use agent authorization-code exchange and token revocation. |
| apps/…/mcp-auth.ts | Defines MCP client registration, authorization, token rotation, and revocation. |
| apps/…/passkey-sign-in.ts | Maps passkey callback results to the web sign-in flow. |
| apps/…/passkey-prompt.ts | Defines when the web app offers a first passkey. |
| apps/…/infra-video-upload.ts | Shows upload admission, multipart completion, and publication. |
| apps/…/infra-video-import.ts | Defines safe URL import admission, streaming, retry, and recovery. |
| apps/…/developer-video-processing.ts | Coordinates probing, encoding, output checks, and media callbacks. |
| apps/…/developer-video-playback.ts | Enforces playback, signing, captions, and paused-account behavior. |
| apps/…/developer-transcript-store.ts | Defines transcript admission, dispatch, state, result, and cleanup. |
| apps/…/developer-transcript-billing.ts | Defines transcript holds and final charges. |
| apps/…/developer-credits.ts | Applies credit additions and usage debits. |
| apps/…/infra-standing.ts | Defines app standing and upload admission. |
| apps/…/infra-delivery-log.ts | Converts delivery records into measured video usage. |
| apps/…/infra-auto-top-up.ts | Coordinates automatic payment, reconciliation, and credit grants. |
| apps/…/developer-webhook-delivery.ts | Defines safe webhook delivery and failure handling. |
| apps/…/plans.ts | Defines normalized plan, seat, promotion, currency, and checkout-session choices. |
| apps/…/promotion.ts | Applies campaign promotion codes without blocking valid checkout. |
| apps/…/referral.ts | Connects partner attribution and discounts to signed-in and guest checkout. |
| apps/…/license-redeem.ts | Defines commercial license lookup, claiming, purchase results, and URL intent handling. |
| apps/…/media-processing-policy.ts | Defines supported media input and account processing suspension checks. |
| apps/…/data.ts | Defines messenger identity, access, conversation reads, and incremental updates. |
| apps/…/use-messenger-poll.ts | Keeps browser messenger updates ordered and bounded while polling. |
| apps/…/rate-limit.ts | Connects API operations to shared firewall and local backstop limits. |
| apps/…/email-code-rate-limit.ts | Keeps email verification limits aligned with address lookup rules. |
| apps/…/directory-sync.ts | Reconciles external directory membership with organization access. |
| apps/…/public-share-video.ts | Defines the common public-share eligibility result. |
| apps/…/embed-options.ts | Defines shared embed options and query behavior. |
| apps/…/share-call-to-action.ts | Defines share call-to-action validation and precedence. |
| apps/…/infra-mcp-server.ts | Connects hosted MCP tools to shared REST capabilities. |
| apps/…/effect-react-query.ts | Connects typed backend effects to browser query state. |
| apps/…/public-media-fetch.ts | Defines safe intake for public media URLs. |
| apps/…/seo-pages.ts | Maps public discovery slugs to their rendered page content. |
| apps/…/seo-metadata.ts | Maps public discovery slugs to search and share metadata. |