@dukkan.one/app-sdk/testing
Sample envelopes, delivery signing and fetch stubs for your own test suites.
- الحزمة
@dukkan.one/app-sdk@0.3.0- مراجعة الواجهة
2026-09-10- الاستيراد
import { … } from "@dukkan.one/app-sdk/testing"
في هذه الصفحة
الدوال
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.
الواجهات
SampleEnvelopeOptions#
interface SampleEnvelopeOptions<Topic extends WebhookTopic>
Options of sampleEnvelope: the topic, the install and store ids, and any payload overrides.
| الاسم | النوع | الوصف |
|---|---|---|
topicمطلوب | Topic | |
storeIdمطلوب | string | |
installIdمطلوب | string | |
data | Partial<EventDataByTopic[Topic]> | undefined | |
id | string | undefined | |
sequence | number | undefined | |
occurredAt | string | undefined | |
test | boolean | 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.
| الاسم | النوع | الوصف |
|---|---|---|
bodyمطلوب | string | The body to POST, byte for byte what was signed. |
headersمطلوب | Record<string, string> | |
envelopeمطلوب | { [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; } |