ServerClientOptions
ServerClientOptions<
S> =object
Options for createServerClient. S is one site’s schema, indexed
out of the types edgekit types pull generates:
createServerClient<EdgeKitDecisions['site_example']>({ siteId: 'site_example', … }).
Pass the site, not all of EdgeKitDecisions. TypeScript has no partial
type-argument inference, so createServerClient<EdgeKitDecisions>(…) drops
the 'site_example' literal and leaves only the feature names every site
shares, which is often none. With the site as the type argument, siteId: S['id']
makes calling a feature on a site that does not run it a compile error.
Type Parameters
Section titled “Type Parameters”S extends SiteSchema
Properties
Section titled “Properties”apiKey
Section titled “apiKey”apiKey:
string
A site-pinned tenant API key from the console. Keep it on your server.
baseUrl
Section titled “baseUrl”baseUrl:
string
Your tenant host, as an absolute URL, e.g. https://edgekit.example.com.
Required: there is no default, and the client does not discover it.
collectorFetch?
Section titled “collectorFetch?”
optionalcollectorFetch?: typeoffetch
Sends the request that records experiment exposures, to /edgekit/a/t
on baseUrl, instead of fetch. Pass it whenever fetch is a service
binding to the decide Worker, which does not reach the collector: bind
the collector Worker too, as
collectorFetch: (input, init) => env.EDGEKIT_COLLECTOR.fetch(input, init).
Without it there, no exposure is recorded.
fetch?
Section titled “fetch?”
optionalfetch?: typeoffetch
Sends the request instead of the global fetch. Needed in a Cloudflare
Worker on the same zone as your tenant host, where a global fetch to
that host never reaches EdgeKit: pass a service binding to the decide
Worker, as a closure so the binding keeps its this:
fetch: (input, init) => env.EDGEKIT_DECIDE.fetch(input, init).
baseUrl stays required and still names the tenant host. A binding
skips the zone’s WAF and rate limiting rules.
The request that records experiment exposures goes through it too,
unless you pass collectorFetch.
siteId
Section titled “siteId”siteId:
S["id"]
The site this client serves. It must be S’s id and the site the API
key is pinned to; the route answers 403 on a mismatch. One client serves
one site: three sites need three keys and three clients.
timeoutMs?
Section titled “timeoutMs?”
optionaltimeoutMs?:number
Request timeout in milliseconds. Defaults to 5000.