import {z} from 'zod' export type CreateNotarizationRequest = {document_id: string, disable_invitees_notifications?: (boolean | null) | undefined, invitation: {message?: string | undefined, invitees?: (Array<{email: string, first_name?: (string | null) | undefined, last_name?: (string | null) | undefined}>) | undefined}, notary?: ({id: string, scheduled_at: string, message?: string | undefined}) | undefined}; export type CreateApiPublicV2NotaryNotarizationRequestsArgs = {body: CreateNotarizationRequest}; export type CreateApiPublicV2NotaryNotarizationRequestsOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const createNotarizationResponse = z.object({id: z.string().optional(), name: z.string().optional(), status: z.enum(["DRAFT", "SENT", "WAITING_FOR_NOTARY", "ACCEPTED", "LIVE", "COMPLETED", "INCOMPLETE", "CANCELLED"]).optional(), date_created: z.string().optional(), date_accepted: z.string().nullable().optional(), created_by: z.object({user_id: z.string().optional(), email: z.string().optional(), first_name: z.string().optional(), last_name: z.string().optional()}).optional(), invitees: z.array(z.object({id: z.string().optional(), email: z.string().max(255).optional(), first_name: z.string().max(50).optional(), last_name: z.string().max(50).optional(), notarization_link: z.string().optional()})).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 Notarization Request * * POST /public/v2/notary/notarization-requests * * Also accepts auth: oauth2 */ export const createApiPublicV2NotaryNotarizationRequests = async (args: CreateApiPublicV2NotaryNotarizationRequestsArgs, options?: CreateApiPublicV2NotaryNotarizationRequestsOptions) => { 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 (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: "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(createNotarizationResponse, await res.json()) };