Skip to content

@dukkan.one/app-sdk/testing

Sample envelopes, delivery signing and fetch stubs for your own test suites.

Package
@dukkan.one/app-sdk@0.3.0
API revision
2026-09-10
Import
import { … } from "@dukkan.one/app-sdk/testing"
On this page

Functions

createFetchStub#

function createFetchStub(script: Array<Response | ((request: Request) => Response | Promise<Response>)>): { fetch: (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>; calls: Array<Request>; remaining: () => number; }

A fetch stub that answers from a script of responses, recording every request.

jsonResponse#

function jsonResponse(body: unknown, init?: { status?: number; headers?: Record<string, string>; }): Response

A Response with a JSON body, for fetch stubs.

sampleEnvelope#

function sampleEnvelope<Topic extends WebhookTopic>(options: SampleEnvelopeOptions<Topic>): WebhookEnvelope

A well-formed v1 envelope for a topic with a plausible data payload, ready to sign.

sampleEventData#

function sampleEventData<Topic extends WebhookTopic>(topic: Topic, installId?: string): EventDataByTopic[Topic]

Representative data per topic, shaped like the emitters documented in the contract.

signDelivery#

function signDelivery(input: { envelope: WebhookEnvelope; secret: string; timestamp?: string; deliveryId?: string; }): Promise<SignedDelivery>

Signs an envelope with a secret the way the delivery worker does.

Interfaces

SampleEnvelopeOptions#

interface SampleEnvelopeOptions<Topic extends WebhookTopic>

Options of sampleEnvelope: the topic, the install and store ids, and any payload overrides.

Members
NameTypeDescription
topicRequiredTopic
storeIdRequiredstring
installIdRequiredstring
dataPartial<EventDataByTopic[Topic]> | undefined
idstring | undefined
sequencenumber | undefined
occurredAtstring | undefined
testboolean | undefined

SignedDelivery#

interface SignedDelivery

Test helpers for apps: build and sign deliveries exactly like the platform does, so a receiver can be exercised offline with the same bytes and headers the real worker sends.

Members
NameTypeDescription
bodyRequiredstring

The body to POST, byte for byte what was signed.

headersRequiredRecord<string, string>
envelopeRequired{ [x: string]: unknown; id: string; api_version: "v1"; topic: string; store_id: string; install_id: string; sequence: number; occurred_at: string; data: Record<string, unknown>; test?: boolean | undefined; }