import {z} from 'zod' export type GetApiSupportingDocumentsSubmissionRequestsArgs = {'x-simple-workspace': string, 'x-piriod-test-mode'?: boolean | undefined, page?: number | undefined, page_size?: number | undefined, ordering?: string | undefined, customer?: string | undefined, status?: ('pending' | 'sent' | 'overdue' | 'fulfilled' | 'cancelled') | undefined, submission_type?: ('order' | 'hes') | undefined, is_automatic?: boolean | undefined, due_date?: string | undefined}; export type GetApiSupportingDocumentsSubmissionRequestsOptions = {baseUrl?: string | undefined, TokenAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const submissionRequest = z.object({id: z.number().int().optional(), customer: z.string(), submission_type: z.enum(["order", "hes"]), status: z.enum(["pending", "sent", "overdue", "fulfilled", "cancelled"]).optional(), recipients: z.array(z.string()).optional(), subscriptions: z.array(z.string()).optional(), due_date: z.string().nullable().optional(), is_automatic: z.boolean().optional(), billing_cycle: z.number().int().nullable().optional(), email_subject: z.string().max(255).optional(), email_message: z.string().optional(), sent_at: z.string().nullable().optional(), fulfilled_at: z.string().nullable().optional(), created: z.string().optional()}); export const getApiSupportingDocumentsSubmissionRequestsResponse = z.object({count: z.number().int(), next: z.string().nullable().optional(), previous: z.string().nullable().optional(), results: z.array(submissionRequest)}); 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 submission requests * * GET /supporting-documents/submission-requests/ */ export const getApiSupportingDocumentsSubmissionRequests = async (args: GetApiSupportingDocumentsSubmissionRequestsArgs, options?: GetApiSupportingDocumentsSubmissionRequestsOptions) => { const {baseUrl = "https://api.piriod.com", fetch: fetchFn = fetch, TokenAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['x-simple-workspace'] != null) headers.set("x-simple-workspace", String(args['x-simple-workspace'])) if (args['x-piriod-test-mode'] != null) headers.set("x-piriod-test-mode", String(args['x-piriod-test-mode'])) if (args.page != null) query.append("page", String(args.page)) if (args.page_size != null) query.append("page_size", String(args.page_size)) if (args.ordering != null) query.append("ordering", String(args.ordering)) if (args.customer != null) query.append("customer", String(args.customer)) if (args.status != null) query.append("status", String(args.status)) if (args.submission_type != null) query.append("submission_type", String(args.submission_type)) if (args.is_automatic != null) query.append("is_automatic", String(args.is_automatic)) if (args.due_date != null) query.append("due_date", String(args.due_date)) if (TokenAuth !== undefined) headers.set("Authorization", TokenAuth) const url = `${baseUrl.replace(/\/+$/, '')}/supporting-documents/submission-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(getApiSupportingDocumentsSubmissionRequestsResponse, await res.json()) };