import {z} from 'zod' export type SigningRequestSettings = {allow_download?: boolean | undefined, attach_pdf_on_finish?: boolean | undefined, allow_editing_before_sending?: boolean | undefined, use_signing_order?: boolean | undefined, hand_drawn_only?: boolean | undefined, send_signing_email?: boolean | undefined, send_finish_email?: boolean | undefined, send_expiration_email?: boolean | undefined, send_cancellation_email?: boolean | undefined, require_otp_verification?: (boolean | null) | undefined, disable_guided_navigation?: (boolean | null) | undefined, allow_presigning_download?: (boolean | null) | undefined, show_qr_code?: (boolean | null) | undefined, allow_decline?: (boolean | null) | undefined, show_save_for_later?: (boolean | null) | undefined, identity_editable_fields?: (Array | null) | undefined, notify_identity_change_email?: boolean | undefined}; export type Recipient = {id?: string | undefined, _temp_id?: string | undefined, template_user_id?: string | undefined, first_name: string, last_name?: string | undefined, email: string, designation: 'Signer' | 'Approver' | 'CC', order?: number | undefined, phone_number?: (string | null) | undefined, street_address?: (string | null) | undefined, city?: (string | null) | undefined, state_province?: (string | null) | undefined, postal_code?: (string | null) | undefined, country?: (string | null) | undefined, title?: (string | null) | undefined, company?: (string | null) | undefined, custom_fields?: {[key: string]: unknown} | undefined}; export type PatchApiSigningRequestsIdArgs = {id: string, body: {name?: string | undefined, description?: string | undefined, document?: string | undefined, expiration_hours?: number | undefined, settings?: SigningRequestSettings | undefined, language?: ('en' | 'es' | 'it' | 'pt' | 'fr' | 'de' | 'el' | 'ru' | 'pl' | 'cs' | 'sv' | 'nl' | 'ro' | 'nb' | 'ca' | null) | undefined, completion_title?: (string | null) | undefined, completion_message?: (string | null) | undefined, completion_redirect_url?: (string | null) | undefined, completion_redirect_delay?: (number | null) | undefined} | {recipient: Recipient} | {field: {id?: string | undefined, type?: ('text' | 'signature' | 'date' | 'checkbox' | 'initial' | 'initials' | 'dropdown' | 'radio_buttons' | 'textarea' | 'text_area' | 'url' | 'file' | 'stamp' | 'approval_signature' | 'approval_checkmark' | 'approval_date') | undefined, position?: ({x?: number | undefined, y?: number | undefined, width?: number | undefined, height?: number | undefined}) | undefined, page_number?: number | undefined, required?: boolean | undefined, recipient_id?: (string | null) | undefined, variable_name?: string | undefined, variable_defined_name?: (string | null) | undefined, dropdown_options?: (Array | Record) | undefined, format_rules?: Record | undefined, validation_rules?: Record | undefined, multi_group_id?: string | undefined, date_default?: string | undefined, date_signing_default?: boolean | undefined, read_only?: boolean | undefined, read_only_value?: string | undefined, final_value?: string | undefined}, documents_layout_version?: number | undefined} | {seal_participant: {id?: string | undefined, seal_id?: string | undefined, order?: number | undefined, swap_to_seal_id?: string | undefined}}}; export type PatchApiSigningRequestsIdOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const sealParticipantApi = z.object({id: z.string(), order: z.number().int().gte(1), seal: z.object({id: z.string(), lineage_id: z.string(), name: z.string(), version: z.number().int(), display_name: z.string()}), status: z.enum(["pending", "paused", "applied"]), applied_at: z.string().nullable(), paused_at: z.string().nullable(), pause_reason: z.enum(["seal_revoked_stop_pending", "seal_integrity_mismatch", "null"]).nullable(), swapped_from_seal_id: z.string().nullable(), triggered_by_recipient_id: z.string().nullable(), sender_kind: z.enum(["dashboard", "api_key", "embedded", "null"]).nullable(), seal_out_of_scope: z.boolean()}); export const patchApiSigningRequestsIdResponse = z.union([z.object({id: z.string().optional(), name: z.string().optional(), template_description: z.string().nullable().optional(), document_url: z.string().optional(), expiration_hours: z.number().int().optional()}), z.object({}), z.object({}), z.object({seal_participant: sealParticipantApi})]); 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 }; /** * Partially Update Signing Request * * PATCH /signing-requests/{id} */ export const patchApiSigningRequestsId = async (args: PatchApiSigningRequestsIdArgs, options?: PatchApiSigningRequestsIdOptions) => { const {baseUrl = "https://api.firma.dev/functions/v1/signing-request-api", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (ApiKeyAuth !== undefined) headers.set("Authorization", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/signing-requests/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(patchApiSigningRequestsIdResponse, await res.json()) };