Skip to Content
Test

Demo

One switch that wires every fake and your seed data so the app runs offline.

Usage

import { createDemo, isDemo } from "@dapplelight/signet-test/demo"

const SEED = { users: [{ id: "user_1", name: "Test User" }], invoices: [] }

export async function setup(env: Record<string, string | undefined>) {
  const demo = isDemo(env)
    ? await createDemo({ seed: SEED, user: SEED.users[0], plan: "pro", appEnv: env.APP_ENV })
    : null

  // use the fakes when demo is on, the real thing otherwise
  // const payments = demo?.payments ?? createPayments({ ... })
  // const channels = demo?.senders ?? realSenders
  // in your router: (await demo?.handle(request)) ?? next()
  return demo
}

Nothing is read at import time: isDemo takes your env object. SIGNET_DEMO=1 (or true) turns it on.

API

ExportWhat it does
createDemo(options?)Build the fakes, clock and seed data; returns a Demo.
isDemo(env)true when SIGNET_DEMO is "1" or "true".
DemoOptions<D>Type: options for createDemo.
Demo<D>Type: what createDemo returns.
DevStateType: what the dev overlay shows.

createDemo(options?)

OptionTypeDefault
seedDnoneYour seed data. Deep-copied; demo.data is the live copy.
user{ id, email?, name? } | nullnullShown in the overlay.
planstringnoneShown in the overlay.
entitlementsstring[]noneShown in the overlay.
flagsRecord<string, boolean | string | number>noneShown in the overlay.
startnumber | string | DatenowStart time of the fake clock.
aireplies for fakeModelnoneGives you demo.model. Needs ai installed.
appEnvstringnonePass your APP_ENV. "production" throws unless allowProduction.
allowProductionbooleanfalseFor a public demo deployment that never touches real providers.
onSeed(data: D) => void | Promise<void>noneCalled after seed and reset, to load data into your store.

The Demo object

FieldWhat it is
clockThe fake clock.
outbox, sendersFake notification senders and their outbox.
notifyStoreIn-memory store for createNotifier.
gateways{ razorpay, stripe, payu } fake gateways.
payments, paymentsStorecreatePayments over the fakes, and its in-memory store.
modelFake AI model, when ai replies were given.
dataThe live seed data.
stateThe DevState the overlay reads.
reset()Back to the seed: outbox, notify store, gateways, payments store and clock all start over.
handle(request)Answers the routes below, or null for any other request.

Routes served by handle

RouteWhat it does
GET /__signet/devUser, plan, entitlements, flags and the last 20 outbox messages, as JSON.
POST /__signet/seedReplace the data with the request body.
POST /__signet/resetRestore the seed and start everything over.
POST /__signet/pay{ gateway, checkoutId, status? }: finish a fake checkout through its signed webhook.

Examples

Mount the routes in a router

import { createDemo } from "@dapplelight/signet-test/demo"

const demo = await createDemo({ seed: { orders: [] } })

export default {
  async fetch(request: Request) {
    return (await demo.handle(request)) ?? new Response("Not found", { status: 404 })
  },
}