import {z} from 'zod' export type RecipientDeliveryMethods = {email?: boolean | undefined, sms?: boolean | undefined} | null; export type DocumentSendManualReminderRequest = {reminders?: (Array<{recipient_id?: string | undefined, delivery_methods?: RecipientDeliveryMethods | undefined, email_customization?: ({subject?: (string | null) | undefined, message?: (string | null) | undefined}) | undefined}>) | undefined}; export type CreateApiPublicV1DocumentsDocumentIdSendReminderArgs = {document_id: string, body: DocumentSendManualReminderRequest}; export type CreateApiPublicV1DocumentsDocumentIdSendReminderOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const documentSendManualReminder200Response = z.object({result: z.array(z.object({recipient_id: z.string().optional(), sms: z.object({status: z.enum(["sent", "error"]).optional(), sent_at: z.string().nullable().optional(), detail: z.enum(["Can't send reminder to CC recipient", "Can't send reminder to the Recipient who completed their part", "Can't send reminder. Signing order is enabled and this Recipient can't sign the document yet", "Can't send reminder. SMS delivery method is not selected for recipient", "Can't send SMS reminder to recipient group", "Can't send SMS reminder. Confirmation of recipient consent is required. Admin should access workspace settings to certify", "Can't send SMS reminder to the Recipient more than once every 24 hours", "Can't send SMS reminder to the Recipient with no phone number", "Can't send SMS reminder to the Recipient with invalid phone number", "Can't send reminder. The document does not contain a recipient with the specified recipient ID"]).nullable().optional()}).optional(), email: z.object({status: z.enum(["sent", "error"]).optional(), sent_at: z.string().nullable().optional(), detail: z.enum(["Can't send reminder to CC recipient", "Can't send reminder to the Recipient who completed their part", "Can't send reminder. Signing order is enabled and this Recipient can't sign the document yet", "Can't send reminder. Email delivery method is not selected for recipient", "Can't send email reminder. Recipient's mailbox is unreachable", "Can't send email reminder to the Recipient with no email", "Can't send email reminder to the Recipient more than once every 24 hours", "Can't send reminder. The document does not contain a recipient with the specified recipient ID", "Can’t send reminder. Email message contains potentially malicious links and could not be processed"]).nullable().optional()}).optional(), email_customization: z.object({subject: z.string().max(512).nullable().optional(), message: z.string().max(5000).nullable().optional()}).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 }; /** * Send Manual Reminder * * POST /public/v1/documents/{document_id}/send-reminder * * Also accepts auth: oauth2 */ export const createApiPublicV1DocumentsDocumentIdSendReminder = async (args: CreateApiPublicV1DocumentsDocumentIdSendReminderArgs, options?: CreateApiPublicV1DocumentsDocumentIdSendReminderOptions) => { 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/v1/documents/${encodeURIComponent(String(args.document_id))}/send-reminder${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(documentSendManualReminder200Response, await res.json()) };