import {z} from 'zod' export type GetApiProductsNotifyReceiptsArgs = {limit?: number | undefined, cursor?: string | undefined, interaction?: ('view' | 'acknowledge' | 'sign' | 'approve' | 'reply') | undefined}; export type GetApiProductsNotifyReceiptsOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const notifyReceipt = 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()}); 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 getApiProductsNotifyReceiptsResponse = z.object({data: z.object({receipts: z.array(notifyReceipt), 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 interaction receipts * * GET /products/notify/receipts * * Also accepts auth: BearerAuth */ export const getApiProductsNotifyReceipts = async (args: GetApiProductsNotifyReceiptsArgs, options?: GetApiProductsNotifyReceiptsOptions) => { 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.limit != null) query.append("limit", String(args.limit)) if (args.cursor != null) query.append("cursor", String(args.cursor)) if (args.interaction != null) query.append("interaction", String(args.interaction)) if (ApiKeyAuth !== undefined) headers.set("X-API-Key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/products/notify/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(getApiProductsNotifyReceiptsResponse, await res.json()) };