API Reference
Autogenerated API reference for BTST
Backend (@btst/stack/api)
createBackendStack
Prop
Type
BackendPlugin
Prop
Type
BackendStackConfig
Prop
Type
BackendStack
Prop
Type
toNodeHandler
Re-exported from better-call/node. Converts a BTST handler to a Node.js compatible request handler.
Payments (@btst/stack/payments)
Core owns the shared PaymentAdapter, PaymentCheckout, and
PaymentWebhookResult contracts, stripeAdapter, lemonSqueezyAdapter, their
options types, and the verifyHmac SHA-256 helper. These exports are also
available from @btst/stack and @btst/stack/api. Provider credentials and
signature verification belong on the server.
import {
stripeAdapter,
paymentCheckoutSchema,
paymentWebhookResultSchema,
type PaymentAdapter,
} from "@btst/stack/payments"
const payments: PaymentAdapter = stripeAdapter(secretKey, webhookSecret)
const checkout = paymentCheckoutSchema.parse(await payments.createPayment({
amount: 1800,
currency: "USD",
orderId: "order-1",
}))createPayment returns a client secret, an HTTP(S) redirect URL, or both.
paymentCheckoutSchema rejects missing destinations, empty or whitespace-only
secrets, and URLs with other protocols. It preserves valid secret values.
handleWebhook verifies the original request signature before returning a
normalized event, or null for unrelated events. Validate non-null events with
paymentWebhookResultSchema: order and payment references must be nonempty,
status must be paid, failed, or refunded, amount must be a nonnegative safe
integer in minor units, and currency must contain exactly three ASCII letters.
The caller must match amount and currency to its stored pending payment and
handle duplicate delivery before changing business state.
Adapters may implement validatePayment as a pure preflight check. Use the
local order ID for provider idempotency and forward the unmodified webhook
Request. Stripe checks timestamp freshness and event mode; Lemon Squeezy
checks the configured store, variant when supplied by the event, and test mode.
See E-commerce payment setup
for provider configuration and checkout limitations.
PaymentAdapter
Prop
Type
PaymentCheckout
Prop
Type
PaymentWebhookResult
Prop
Type
Client (@btst/stack/client)
createClientStack
Configure the shared API location, site location, React Query client, and optional server request headers once. Runtime-independent client plugin definitions receive the resolved values when the stack is created.
const clientStack = createClientStack({
api: {
baseURL: "https://app.example.com",
basePath: "/api/data",
headers: requestHeaders, // server/request stacks only
},
site: {
baseURL: "https://app.example.com",
basePath: "/pages",
},
queryClient,
plugins: {
example: exampleClientPlugin(),
},
})Use endpoints.<plugin>.api or endpoints.<plugin>.site only when one plugin implements its BTST contract at another endpoint. A path-only API replacement inherits the top-level origin and server request headers. Supplying another origin requires its own basePath and does not inherit request headers. An empty plugin endpoint block inherits both top-level locations unchanged.
Headers deliberately exposed to browser code use the explicit browserHeaders field and appear under the same name in the provider projection. Cookie, authorization, proxy-authorization, and set-cookie values are rejected there; keep request credentials in server-only api.headers. Cross-origin browser credentials must also be explicit.
The returned provider value contains API/site/query information for browser consumers, but never top-level server request headers. Browser-created stacks reject api.headers rather than silently serializing them.
ResolvedClientStackConfig
Prop
Type
ResolvedClientPluginRuntime
Prop
Type
ClientPluginDefinition
Prop
Type
A definition may declare providerConfig when its browser components need a
small subset of plugin factory values. The resolved provider projection exposes
the exact inferred shape as plugins.<id>.config. These values must be safe to
expose in the browser: do not include secrets, request headers, server-only
objects, or the shared API/site/QueryClient runtime.
ClientProviderPluginRuntime
Prop
Type
config is present only for definitions that project browser-safe factory
values through providerConfig; it is not a provider override and applications
do not configure it on StackProvider.
ClientPlugin
Prop
Type
ClientStack
Prop
Type
ResolvedClientStack
Prop
Type
SitemapEntry
Prop
Type
Sitemap
An array of SitemapEntry objects.
type Sitemap = Array<SitemapEntry>;sitemapEntryToXmlString
Prop
Type
metaElementsToObject
Prop
Type
normalizePath
Prop
Type
Client Components (@btst/stack/client/components)
RouteWithComponents
Prop
Type
RouteRenderer
Prop
Type
ComposedRoute
Prop
Type
FallbackProps
Prop
Type
ErrorBoundary
Prop
Type
Context (@btst/stack/context)
StackProvider
Prop
Type
useStack
Prop
Type
usePluginOverrides
Prop
Type
usePluginSiteNavigation
Prop
Type
Use this client hook for links and programmatic navigation owned by a plugin. Pass the
same literal plugin ID used in createClientStack({ plugins }); the hook reads that
plugin's resolved site endpoint, including any endpoints.<pluginId>.site override.
resolve(...segments) returns the canonical path, the rendered href, and whether
the destination is cross-origin. Same-origin links use the configured router and a
path-only href. Cross-origin links use an absolute href that is stable during SSR
and hydration, and navigate() performs a full-page browser navigation. Without a
router adapter, navigate() also falls back to full-page navigation. Root-mounted
sites are normalized to one leading slash.
"use client"
import { usePluginSiteNavigation } from "@btst/stack/context"
const TODOS_PLUGIN_ID = "todos" as const
export function AddTodoLink() {
const { Link, resolve } = usePluginSiteNavigation(TODOS_PLUGIN_ID)
return <Link href={resolve("todos", "add").href}>Add Todo</Link>
}useBasePath
Prop
Type
joinBasePath
Prop
Type
Join the resolved site base path to a plugin route before passing it to a link or router navigation function. This produces one path separator even when the configured base path is /.
Prefer usePluginSiteNavigation(pluginId) inside plugin browser components so
per-plugin site endpoint overrides are honored. Keep joinBasePath for non-hook or
server-side path composition when you already have the correct resolved base path.
useNotify
Prop
Type
Notifications are configured via the notify prop on StackProvider. Without an override, useNotify() routes to sonner toasts.
useTranslate
Prop
Type
Without an i18n provider, useTranslate() returns the English default with {{param}} interpolation.
useListState
URL-synced list state (filters, tabs, pagination) via the router's getSearchParams / setSearchParams contract. Import useListState from the client-only @btst/stack/client/hooks entry. Server-safe parsing and serialization helpers remain available from @btst/stack/client.
The Next.js preset writes search-only updates with the native History API. The URL is committed before list-state subscribers read it, so changing a filter updates the active query immediately. Push and replace history behavior still follow the field configuration.
For SSR loaders, read initial state with parseListStateFromSearchParams(namespace, schema, requestSearchParams).
Prop
Type