import {z} from 'zod' export type GetApiProductsHelpDeskReplyReviewsArgs = {view?: ('manager' | 'mine' | 'all') | undefined, status?: ('pending' | 'rejected' | 'approved' | 'discarded' | 'all') | undefined, ticket_id?: string | undefined, cursor?: string | undefined}; export type GetApiProductsHelpDeskReplyReviewsOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const helpDeskReplyReview = z.object({review_id: z.string(), ticket_id: z.string(), ticket_number: z.number().int(), operator_id: z.string(), manager_id: z.string(), status: z.enum(["pending", "rejected", "approved", "discarded"]), created_at: z.number().int(), submitted_at: z.number().int(), updated_at: z.number().int(), status_after: z.enum(["waiting_on_customer", "open"]), version: z.number().int().gte(1), body: z.object({}).nullable(), body_markup: z.string().nullable(), attachments: z.array(z.object({attachment_id: z.string().optional(), name: z.string().optional(), size: z.number().int().optional(), content_type: z.string().optional(), disposition: z.string().optional(), scan: z.string().optional()})), feedback: z.object({comment: z.string().optional(), reviewer_id: z.string().optional(), created_at: z.number().int().optional()}).nullable(), discard: z.object({reason: z.string().optional(), operator_id: z.string().optional(), created_at: z.number().int().optional()}).nullable()}); export const helpDeskReplyReviewsPage = z.object({reviews: z.array(helpDeskReplyReview), next_cursor: z.string().nullable(), count: z.number().int(), has_more: z.boolean()}); export const responseMeta = z.object({api_version: z.string().optional(), request_id: z.string().optional(), response_ms: z.number().int().optional(), timestamp: z.number().int().optional(), pools: z.object({}).optional(), billing: z.object({past_due: z.boolean().optional()}).optional(), quota: z.object({limit: z.number().int().optional(), used: z.number().int().optional(), remaining: z.number().int().optional(), resets_at: z.number().int().optional()}).optional()}); export const getApiProductsHelpDeskReplyReviewsResponse = z.object({data: helpDeskReplyReviewsPage, meta: responseMeta.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 }; /** * Read private reply reviews * * GET /products/help-desk/reply-reviews */ export const getApiProductsHelpDeskReplyReviews = async (args: GetApiProductsHelpDeskReplyReviewsArgs, options?: GetApiProductsHelpDeskReplyReviewsOptions) => { const {baseUrl = "https://api.sparkvault.com/v1", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.view != null) query.append("view", String(args.view)) if (args.status != null) query.append("status", String(args.status)) if (args.ticket_id != null) query.append("ticket_id", String(args.ticket_id)) if (args.cursor != null) query.append("cursor", String(args.cursor)) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/products/help-desk/reply-reviews${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(getApiProductsHelpDeskReplyReviewsResponse, await res.json()) };