ServerDecideOptions
ServerDecideOptions =
object
Per-call options for decide().
Properties
Section titled “Properties”asUser?
Section titled “asUser?”
optionalasUser?: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.
castleRequestToken?
Section titled “castleRequestToken?”
optionalcastleRequestToken?: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.
context?
Section titled “context?”
optionalcontext?:Record<string,unknown>
Facts sent as given. The engine reads them at the unverified tier.
giftLink?
Section titled “giftLink?”
optionalgiftLink?: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.
newsletterLink?
Section titled “newsletterLink?”
optionalnewsletterLink?: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.
preview?
Section titled “preview?”
optionalpreview?: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.
request?
Section titled “request?”
optionalrequest?: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-forandcf-connecting-ipheaders; - the
utm_parameters ofurl; - on Cloudflare, the request’s
cfregion 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.
signal?
Section titled “signal?”
optionalsignal?:AbortSignal
Aborts the request early. The timeout still applies.
waitUntil?
Section titled “waitUntil?”
optionalwaitUntil?: (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.
Parameters
Section titled “Parameters”Promise<boolean>
Returns
Section titled “Returns”void