import {z} from 'zod' export type GetApiPublicV2NotaryNotarizationRequestsArgs = {status?: (Array<'DRAFT' | 'SENT' | 'WAITING_FOR_NOTARY' | 'ACCEPTED' | 'LIVE' | 'COMPLETED' | 'INCOMPLETE' | 'CANCELLED'>) | undefined, created_by_user_id?: Array | undefined, document_id?: Array | undefined, offset?: number | undefined, limit?: number | undefined, order_by?: ('status' | '-status' | 'date_created' | '-date_created' | 'date_completed' | '-date_completed') | undefined}; export type GetApiPublicV2NotaryNotarizationRequestsOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const listNotarizationRequestsResponse = z.object({results: z.array(z.object({id: z.string().optional(), status: z.enum(["DRAFT", "SENT", "WAITING_FOR_NOTARY", "ACCEPTED", "LIVE", "COMPLETED", "INCOMPLETE", "CANCELLED"]).optional(), name: z.string().optional(), document_id: z.string().optional(), date_created: z.string().optional(), date_started: z.string().nullable().optional(), date_completed: z.string().nullable().optional(), created_by_user_id: z.string().optional()})).optional(), count: z.number().int().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 Notarization Requests * * GET /public/v2/notary/notarization-requests * * Also accepts auth: oauth2 */ export const getApiPublicV2NotaryNotarizationRequests = async (args: GetApiPublicV2NotaryNotarizationRequestsArgs, options?: GetApiPublicV2NotaryNotarizationRequestsOptions) => { const {baseUrl = "https://api.pandadoc.com", fetch: fetchFn = fetch, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.status != null) query.append("status", args.status.join(',')) if (args.created_by_user_id != null) query.append("created_by_user_id", args.created_by_user_id.join(',')) if (args.document_id != null) query.append("document_id", args.document_id.join(',')) if (args.offset != null) query.append("offset", String(args.offset)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.order_by != null) query.append("order_by", String(args.order_by)) if (apiKey !== undefined) headers.set("Authorization", apiKey) const url = `${baseUrl.replace(/\/+$/, '')}/public/v2/notary/notarization-requests${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(listNotarizationRequestsResponse, await res.json()) };