strapkit
API Reference

Strapkit class

Construction, init, and the API key.

The default export of @strapkit/core. Each instance owns one Node runtime.

import Strapkit from "@strapkit/core";

const sk = new Strapkit({
  apiKey: "sk_live_…",
});

await sk.init();

apiKey (required)

A non-empty string. Strapkit attaches it to every connection the runtime opens to the network proxy. Missing or non-string values throw StrapkitConfigError.

You can change the key later with setApiKey() — Strapkit picks up the new value on the next connection without needing to be reconstructed.

Unknown options

Passing a key Strapkit doesn't know about throws StrapkitConfigError, with a hint for common typos (apikeyapiKey).

init()

init(): Promise<object>

Loads the Node runtime and returns it. Calling init() more than once is fine — concurrent and later calls all share the same in-flight load.

Errors

init() rejects with StrapkitRuntimeError if:

  • The page isn't running in a browser (no WebSocket available).
  • The runtime files can't be fetched from the server.
  • The runtime build is missing pieces Strapkit relies on.
  • The proxy rejects the API key.

When the underlying problem has its own error, it's attached as .cause. See the Errors page for the full table.

setApiKey(apiKey)

setApiKey(apiKey: string): void

Replaces the API key Strapkit attaches to proxy connections. Useful when the key isn't available at construction (e.g. you load it after the user signs in).

Throws StrapkitConfigError if the argument isn't a non-empty string. Connections that are already open keep the old key; new connections use the new one.

On this page