import {z} from 'zod' export type GetApiProductsNotifySendsSendIdReceiptsArgs = {sendId: string, cursor?: string | undefined}; export type GetApiProductsNotifySendsSendIdReceiptsOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const responseMeta = z.object({api_version: z.string().optional(), request_id: z.string().optional(), response_ms: z.number().int().optional(), timestamp: z.number().int().optional(), pools: z.object({}).optional(), billing: z.object({past_due: z.boolean().optional()}).optional(), quota: z.object({limit: z.number().int().optional(), used: z.number().int().optional(), remaining: z.number().int().optional(), resets_at: z.number().int().optional()}).optional()}); export const getApiProductsNotifySendsSendIdReceiptsResponse = z.object({data: z.object({send_id: z.string(), receipts: z.array(z.object({event_type: z.enum(["sparklink_accessed", "sparklink_signed", "sparklink_approved", "sparklink_denied", "sparklink_replied"]), occurred_at: z.number().int().nullable(), interaction: z.enum(["view", "acknowledge", "sign", "approve", "reply", "null"]).nullable(), identity: z.string().nullable().optional(), asset_id: z.string().nullable().optional(), vault_id: z.string().nullable().optional(), link_code: z.string().nullable().optional(), link_code_hash: z.string().nullable().optional(), link_type: z.string().nullable().optional(), verification_level: z.enum(["none", "identifier", "passkey", "out_of_band", "dual_control", "null"]).nullable().optional(), action_hash: z.string().nullable().optional(), signed_token: z.string().nullable().optional(), decision: z.string().nullable().optional(), thread_id: z.string().nullable().optional(), reply_spark_id: z.string().nullable().optional(), send_id: z.string().nullable().optional(), title: z.string().nullable().optional(), receipt_id: z.string().nullable().optional(), recipient_id: z.string()})), truncated: z.boolean(), cursor: z.string().nullable()}), meta: responseMeta.optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * List receipts for one send * * GET /products/notify/sends/{sendId}/receipts * * Also accepts auth: BearerAuth */ export const getApiProductsNotifySendsSendIdReceipts = async (args: GetApiProductsNotifySendsSendIdReceiptsArgs, options?: GetApiProductsNotifySendsSendIdReceiptsOptions) => { const {baseUrl = "https://api.sparkvault.com/v1", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.cursor != null) query.append("cursor", String(args.cursor)) if (ApiKeyAuth !== undefined) headers.set("X-API-Key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/products/notify/sends/${encodeURIComponent(String(args.sendId))}/receipts${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiProductsNotifySendsSendIdReceiptsResponse, await res.json()) };