import {z} from 'zod' export type UpdateApiWebhooksIdArgs = {'X-Steward-Request-Timestamp'?: string | undefined, 'X-Steward-Request-Expires-At'?: string | undefined, 'X-Steward-Signature'?: string | undefined, 'X-Steward-Signing-Key-Id'?: string | undefined, 'Idempotency-Key'?: string | undefined, body: {url?: string | undefined, events?: (Array<'tx.pending' | 'tx.approved' | 'tx.denied' | 'tx.signed' | 'spend.threshold' | 'policy.violation' | 'wallet_action.transfer.failed' | 'wallet_action.transfer.succeeded' | 'wallet_action.send_calls.failed' | 'wallet_action.send_calls.succeeded' | 'wallet.raw_signature.created' | 'wallet.private_key_exported' | 'user.wallet.created' | 'intent.created' | 'intent.authorized' | 'intent.executed' | 'intent.failed' | 'intent.rejected' | 'intent.canceled' | 'intent.expired'>) | undefined, enabled?: boolean | undefined, description?: string | undefined, maxRetries?: number | undefined, retryBackoffMs?: number | undefined}}; export type UpdateApiWebhooksIdOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const updateApiWebhooksIdResponse = z.object({ok: z.literal(true), data: z.object({id: z.string(), tenantId: z.string(), url: z.string(), events: z.array(z.enum(["tx.pending", "tx.approved", "tx.denied", "tx.signed", "spend.threshold", "policy.violation", "wallet_action.transfer.failed", "wallet_action.transfer.succeeded", "wallet_action.send_calls.failed", "wallet_action.send_calls.succeeded", "wallet.raw_signature.created", "wallet.private_key_exported", "user.wallet.created", "intent.created", "intent.authorized", "intent.executed", "intent.failed", "intent.rejected", "intent.canceled", "intent.expired"])), enabled: z.boolean(), maxRetries: z.number().int().gte(0).lte(10), retryBackoffMs: z.number().int().gte(1000).lte(3600000), description: z.string().nullable().optional(), createdAt: z.string(), updatedAt: z.string().optional()}).and(z.record(z.string(), z.unknown()))}); 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 }; /** * Update a webhook configuration * * PUT /webhooks/{id} */ export const updateApiWebhooksId = async (args: UpdateApiWebhooksIdArgs, options?: UpdateApiWebhooksIdOptions) => { const {baseUrl = "http://localhost:3200", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['X-Steward-Request-Timestamp'] != null) headers.set("X-Steward-Request-Timestamp", String(args['X-Steward-Request-Timestamp'])) if (args['X-Steward-Request-Expires-At'] != null) headers.set("X-Steward-Request-Expires-At", String(args['X-Steward-Request-Expires-At'])) if (args['X-Steward-Signature'] != null) headers.set("X-Steward-Signature", String(args['X-Steward-Signature'])) if (args['X-Steward-Signing-Key-Id'] != null) headers.set("X-Steward-Signing-Key-Id", String(args['X-Steward-Signing-Key-Id'])) if (args['Idempotency-Key'] != null) headers.set("Idempotency-Key", String(args['Idempotency-Key'])) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/webhooks/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(updateApiWebhooksIdResponse, await res.json()) };