Teardown

Server SDK

Self-host Teardown's identify, events, force-update, and version management runtime inside your own TypeScript backend, backed by your own database.

The Teardown Server SDK (@teardown/server) lets you run Teardown's device/user identify, event ingestion, force-update / version-status checks, and app version & build management runtime inside your own TypeScript backend, backed by your own database.

It pairs with the React Native SDK: point its ingestUrl at a server running @teardown/server and the existing client works unchanged.

Features

  • Self-hosted ingest - Run the POST /v1/identify and POST /v1/events wire contract the React Native SDK speaks, in your own service
  • Force updates from your backend - Version-status checks resolved against your data, plus version & build management (status cascade + change hooks)
  • Bring your own database - Implement a small storage interface for any database (Postgres, MongoDB, Firestore, …); you own the schema and migrations. An in-memory adapter ships for tests and prototyping
  • Two consumption modes - Mount a ready-made HTTP router, or call the domain services directly from your own routes and auth
  • Runtime-agnostic - Web-standard fetch adapter runs on Bun, Hono, Deno, Cloudflare Workers, and Next.js route handlers; a first-class Elysia plugin is also shipped
  • No singletons, full DI - Everything is wired through createTeardown; nothing reads a module-level db/cache/logger
  • Type Safety - Full TypeScript types for the storage ports, entities, configuration, and HTTP contract

Quick Start

Install the package:

bun add @teardown/server

Generate a SESSION_SECRET (openssl rand -base64 32), wire a storage layer into the runtime, then mount the ingest router:

import { createTeardown } from "@teardown/server";
import { createMemoryStorage } from "@teardown/server/adapters/memory";
import { toFetchHandler } from "@teardown/server/http/fetch";

const td = createTeardown({
  storage: createMemoryStorage(),                 // in-memory for tests; implement the repositories for production
  config: { sessionSecret: process.env.SESSION_SECRET! },
});

// Bun example — serve the ingest contract the RN SDK speaks:
Bun.serve({ port: 4501, fetch: toFetchHandler(td.router()) });

The Getting Started guide walks this end to end — generating the secret, seeding a project/environment, running single-tenant, and going to production by implementing the storage repositories.

Then point the React Native SDK at your server with the self-hosted config:

const teardown = new TeardownCore({
  config: { type: "self-hosted", ingestUrl: "https://ingest.your-app.com" }, // your @teardown/server endpoint
  environment_slug: "production",
  // ...storageAdapter, deviceAdapter
});

Runtime support

The primary fetch adapter has zero required peer dependencies and runs anywhere Web-standard Request/Response is available. An Elysia plugin is shipped for Elysia hosts.

RuntimeAdapterImport
Bun (Bun.serve)fetch@teardown/server/http/fetch
ElysiaElysia plugin@teardown/server/http/elysia
Honofetch@teardown/server/http/fetch
Cloudflare Workers / Deno / edgefetch@teardown/server/http/fetch
Next.js route handlersfetch@teardown/server/http/fetch
Node / Expressfetch (via a Web Request shim)@teardown/server/http/fetch

Documentation

  • Getting Started - Install, generate a session secret, run with in-memory storage, connect the client, then implement the repositories for production
  • Core Concepts - Ports & adapters architecture and the two consumption modes
  • Storage - The TeardownStorage port, the in-memory adapter, and bringing your own database
  • Mounting - The HTTP layer, adapters, CORS, and the request/response contract
  • Version Management - Managing versions/builds and force-update status from your backend
  • API Reference - createTeardown, the Teardown object, services, and ports
  • Advanced - Caching, logging, metrics, atomicity, and deployment