Skip to main content

@flow-state-dev/vercel

Interfaces​

VercelScheduler​

A SchedulerAdapter with the route Vercel Cron calls.

Extends​

  • SchedulerAdapter

Methods​

route()​
route(req): Promise<Response>;

The cron route's handler: authenticate the call, run the tick once, and answer 200 with how many fires it sent. 401 for a missing or wrong secret, 500 when the tick rejects or the scheduler was never passed to createFlowState. Unbound: export it directly as the route's GET.

Parameters​
req​

Request

Returns​

Promise<Response>

start()​
start(ticker): object;

Run ticker.tick() when the schedules should be checked.

Parameters​
ticker​

ScheduleTicker

Returns​

object

stop()​
stop(): Promise<void>;
Returns​

Promise<void>

Inherited from​

SchedulerAdapter.start


VercelSchedulerOptions​

Options for vercelScheduler.

Properties​

secret?​
secret?: string;

The secret Vercel Cron sends as Authorization: Bearer <secret>. Default process.env.CRON_SECRET, read on each call. Each fire the tick sends carries the same secret to the dispatch endpoint.

Type Aliases​

FlowApiRouter​

type FlowApiRouter = object;

Returned by createFlowApiRouter. The four method properties are the canonical { GET, POST, PATCH, DELETE } dispatcher for the catch-all route. The shape matches what Next.js / Vercel / Hono catch-all routes expect; it is intentionally backward-compatible with the earlier router so consumers indexing by HTTP method (router[method], keyof typeof router) keep working.

For teardown of registered transport adapters, call disposeFlowApiRouter(router) — keeping it off the router shape avoids widening keyof for index-call consumers.

Properties​

DELETE​
DELETE: (req, ctx) => Promise<Response>;
Parameters​
req​

Request

ctx​

NextRouteContext

Returns​

Promise<Response>

GET​
GET: (req, ctx) => Promise<Response>;
Parameters​
req​

Request

ctx​

NextRouteContext

Returns​

Promise<Response>

PATCH​
PATCH: (req, ctx) => Promise<Response>;
Parameters​
req​

Request

ctx​

NextRouteContext

Returns​

Promise<Response>

POST​
POST: (req, ctx) => Promise<Response>;
Parameters​
req​

Request

ctx​

NextRouteContext

Returns​

Promise<Response>


VercelHandlerInput​

type VercelHandlerInput =
| FlowApiRouter
| (() =>
| FlowApiRouter
| Promise<FlowApiRouter>);

Accepted input for createVercelHandler. Either a pre-built router or a factory function that lazily creates one (useful when store initialization is async, e.g. Postgres pool creation).


VercelHandlerOptions​

type VercelHandlerOptions = object;

Configuration options for createVercelHandler.

Properties​

allowUnauthenticated?​
allowUnauthenticated?: boolean;

Explicitly permit flows that trust a caller-supplied userId.

onAbort?​
onAbort?: (req) => void;

Callback invoked when a client disconnects and the request signal aborts. Useful for logging or cleanup.

Parameters​
req​

Request

Returns​

void

waitUntil?​
waitUntil?: (promise) => void;

Vercel waitUntil function for keeping the serverless function alive after the response has been sent. Pass this when background .sideChain() tasks need to outlive the response stream.

Typically obtained from @vercel/functions or Next.js after().

Parameters​
promise​

Promise<unknown>

Returns​

void

Functions​

createVercelBareHandler()​

function createVercelBareHandler(app, options?): object;

Creates bare-path handlers for the /api/flows route (no path segments).

Next.js [...path] catch-all requires at least one segment, so the bare path needs a sibling route.ts that forwards to the router with an empty path array.

// app/api/flows/route.ts
import { createVercelBareHandler } from '@flow-state-dev/vercel';
import { getRouter } from '@/lib/server';

export const { GET, POST } = createVercelBareHandler(getRouter);

Parameters​

app​

VercelHandlerInput

options?​

VercelHandlerOptions

Returns​

object

GET​
GET: BareHandler;
POST​
POST: BareHandler;

createVercelHandler()​

function createVercelHandler(app, options?): object;

Creates Next.js App Router handlers for deploying a flow-state-dev app to Vercel.

Handles the Next.js 15 async params contract and injects Vercel-specific SSE headers to prevent proxy buffering. SSE heartbeats are emitted by @flow-state-dev/engine for every live and GET-attach stream.

// app/api/fsd/[...path]/route.ts
import { createVercelHandler } from '@flow-state-dev/vercel';
import { getRouter } from '@/lib/server';

export const { GET, POST, PATCH, DELETE } = createVercelHandler(getRouter);

export const runtime = "nodejs";
export const maxDuration = 300;
export const dynamic = "force-dynamic";

Parameters​

app​

VercelHandlerInput

options?​

VercelHandlerOptions

Returns​

object

DELETE​
DELETE: CatchAllHandler;
GET​
GET: CatchAllHandler;
PATCH​
PATCH: CatchAllHandler;
POST​
POST: CatchAllHandler;

vercelScheduler()​

function vercelScheduler(options?): VercelScheduler;

Build the Vercel scheduler adapter. See the module header.

Parameters​

options?​

VercelSchedulerOptions

Returns​

VercelScheduler