Skip to content

ServerDecideOptions

ServerDecideOptions = object

Per-call options for decide().

optional asUser?: string

The user this decision is for, sent as the request’s userId. An unverified assertion: the route takes it at face value and reads that user’s grants, and nothing checks that the caller is that user. Take it from a session your backend has verified, never from a value on the incoming request, or the requester can claim any user’s grants.


optional castleRequestToken?: string

A Castle request token your page minted with castle.js and sent to your server, forwarded verbatim. Without one, the castle.* facts have no value and a rule reading them routes to the feature’s error outcome. A token is good for one request, so never reuse one.


optional context?: Record<string, unknown>

Facts sent as given. The engine reads them at the unverified tier.


optional giftLink?: string

The _gt query parameter from your own incoming request, verbatim. The client never reads a URL itself. An invalid, forged or expired token means no gift, never an error.


optional newsletterLink?: string

The ek_nl query parameter from your own incoming request, verbatim: a newsletter link. The client never reads a URL itself. It says who an edition’s link was sent to, not who is clicking, and is read only when the decision names no user: asUser wins. An invalid, forged or unknown one means none, never an error. The same value unsubscribes its user, so remove it from the URL your page shows.


optional preview?: string

An outcome preview token from your own incoming request, verbatim: its ?edgekitPreview= or its edgekit_preview cookie. The client never reads a URL or a cookie itself, so keeping a preview across pages is yours. A value that cannot be sent as a header is ignored; an invalid or expired token means no preview, never an error.


optional request?: IncomingRequest

The incoming request this decision is for: a Fetch Request, or anything with its url and headers.get. The client forwards what the engine reads about the user’s request and nothing else:

  • the cookie, user-agent, accept-language, referer, cf-ipcountry, x-forwarded-for and cf-connecting-ip headers;
  • the utm_ parameters of url;
  • on Cloudflare, the request’s cf region and, over a service binding, its bot verdict.

Without it, every user is decided as a desktop device with no referrer and no country, and every anonymous user shares one meter.

At a site whose users sign in only through your own identity provider, the route reads that provider’s credential from the cookies, decides for that user and refuses asUser. A credential that is missing or does not verify means an anonymous decision, never an error.


optional signal?: AbortSignal

Aborts the request early. The timeout still applies.


optional waitUntil?: (sent) => void

Receives the promise of the request that records this decision’s experiment exposures, so your runtime can keep it alive after you respond: on Cloudflare Workers, waitUntil: (sent) => ctx.waitUntil(sent). Called at most once per decide, and only when the answer assigned an experiment arm. The promise never rejects; it resolves false when the exposures were not recorded. decide never waits for it.

The client posts one experiment_exposure event per exposure to your collector, at /edgekit/a/t on baseUrl, with or without this option. It sends no cookie and nothing from request. Each event counts toward your billed events. A preview answer records none.

Promise<boolean>

void

edgekit.ai