import {z} from 'zod' export type PricingTableRequest = {name: string, data_merge?: boolean | undefined, options?: Record | undefined, sections: Array<{title: string, default: boolean, multichoice_enabled?: boolean | undefined, rows?: (Array<{options: {qty_editable?: boolean | undefined, optional_selected?: boolean | undefined, optional?: boolean | undefined}, data: {images?: Array<{src: string}> | undefined, pricing_method?: ('volume_based_price' | 'volume_based_discount_price') | undefined, tiers?: Array<{min_qty: number, value: number}> | undefined} | {[key: string]: unknown}, custom_fields?: Record | undefined}>) | undefined}>}; export type RecipientDeliveryMethods = {email?: boolean | undefined, sms?: boolean | undefined} | null; export type RecipientRedirect = {is_enabled: boolean, url: string | null}; export type RecipientVerificationPlaceEnum = 'before_open' | 'before_sign'; export type RecipientVerificationSettings = {verification_place?: RecipientVerificationPlaceEnum | undefined, passcode_verification?: ({passcode: string} | null) | undefined, phone_verification?: ({phone_number: string} | null) | undefined, kba_verification?: ({time_limit_sec?: number | undefined, score_threshold?: number | undefined, max_attempts_count?: number | undefined} | null) | undefined, id_verification?: ({enabled?: boolean | undefined} | null) | undefined, email_otp_verification?: ({email: string} | null) | undefined}; export type CreateDocumentRecipient = {role?: (string | null) | undefined, signing_order?: (number | null) | undefined, email?: (string | null) | undefined, phone?: (string | null) | undefined, first_name?: (string | null) | undefined, last_name?: (string | null) | undefined, delivery_methods?: RecipientDeliveryMethods | undefined, redirect?: RecipientRedirect | undefined, type?: 'recipient' | undefined, verification_settings?: RecipientVerificationSettings | undefined}; export type BaseIdentity = {email?: (string | null) | undefined, phone?: (string | null) | undefined, first_name?: (string | null) | undefined, last_name?: (string | null) | undefined}; export type CreateDocumentRecipientGroup = {role?: (string | null) | undefined, signing_order?: (number | null) | undefined, name: string, type: 'recipient_group', members?: Array | undefined}; export type CreateDocumentActor = CreateDocumentRecipient | CreateDocumentRecipientGroup; export type UploadSectionByTemplateRequest = {template_uuid: string, pricing_tables?: Array | undefined, content_placeholders?: (Array<{content_library_items?: (Array<{id: string, fields?: Record | undefined, pricing_tables?: Array | undefined, recipients?: (Array<{email?: (string | null) | undefined, phone?: (string | null) | undefined, delivery_methods?: RecipientDeliveryMethods | undefined, first_name?: string | undefined, last_name?: string | undefined, role?: string | undefined, signing_order?: (number | null) | undefined, redirect?: RecipientRedirect | undefined}>) | undefined}>) | undefined, block_id: string}>) | undefined, fields?: Record | undefined, name?: string | undefined, recipients: Array, tokens?: Array<{name: string, value: string}> | undefined, tags?: Array | undefined}; export type UploadSectionByFileRequest = {parse_form_fields?: boolean | undefined, parse_text_tags?: boolean | undefined, fields?: Record | undefined, name?: string | undefined, recipients: Array, tokens?: Array<{name: string, value: string}> | undefined, tags?: Array | undefined, url: string}; export type CreateApiPublicV1DocumentsDocumentIdSectionsUploadsArgs = {document_id: string, merge_field_scope?: ('document' | 'upload') | undefined, body: UploadSectionByTemplateRequest | UploadSectionByFileRequest}; export type CreateApiPublicV1DocumentsDocumentIdSectionsUploadsOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const uploadSectionStatusEnum = z.enum(["document_sections_upload.UPLOADED", "document_sections_upload.PROCESSED", "document_sections_upload.ERROR"]); export const uploadSectionResponse = z.object({uuid: z.string().optional(), name: z.string().optional(), document_uuid: z.string().optional(), status: uploadSectionStatusEnum.optional(), date_created: z.string().optional(), date_modified: z.string().optional(), date_completed: z.string().nullable().optional(), info_message: z.string().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 }; /** * Create Document Section * * POST /public/v1/documents/{document_id}/sections/uploads * * Also accepts auth: oauth2 */ export const createApiPublicV1DocumentsDocumentIdSectionsUploads = async (args: CreateApiPublicV1DocumentsDocumentIdSectionsUploadsArgs, options?: CreateApiPublicV1DocumentsDocumentIdSectionsUploadsOptions) => { const {baseUrl = "https://api.pandadoc.com", fetch: fetchFn = fetch, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.merge_field_scope != null) query.append("merge_field_scope", String(args.merge_field_scope)) if (apiKey !== undefined) headers.set("Authorization", apiKey) const url = `${baseUrl.replace(/\/+$/, '')}/public/v1/documents/${encodeURIComponent(String(args.document_id))}/sections/uploads${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(uploadSectionResponse, await res.json()) };