import {z} from 'zod' export type GetApiApiPublicTicketFeedbackArgs = {'x-api-key': string, page?: number | undefined, page_size?: number | undefined, feedback_type?: ('csat' | 'nps') | undefined, scheduled_at_start?: string | undefined, scheduled_at_end?: string | undefined, pipeline_id?: Array | undefined, responded?: ('true' | 'false') | undefined}; export type GetApiApiPublicTicketFeedbackOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiPublicTicketFeedbackResponse = z.object({data: z.array(z.object({id: z.string().optional(), ticket_id: z.string().optional(), type: z.enum(["csat", "nps"]).optional(), value: z.number().nullable().optional(), comment: z.string().nullable().optional(), scheduled_at: z.string().optional(), responded_at: z.string().nullable().optional(), created_at: z.string().optional(), pipeline: z.object({id: z.string().optional(), name: z.string().optional()}).nullable().optional(), customer: z.object({id: z.string().optional(), name: z.string().optional(), phone: z.string().optional(), email: z.string().optional()}).nullable().optional()})).optional(), page: z.number().optional(), page_size: z.number().optional(), has_next_page: z.boolean().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 ticket feedbacks * * GET /api/public/ticket-feedback */ export const getApiApiPublicTicketFeedback = async (args: GetApiApiPublicTicketFeedbackArgs, options?: GetApiApiPublicTicketFeedbackOptions) => { const {baseUrl = "https://api.vambe.me", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['x-api-key'] != null) headers.set("x-api-key", String(args['x-api-key'])) 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.feedback_type != null) query.append("feedback_type", String(args.feedback_type)) if (args.scheduled_at_start != null) query.append("scheduled_at_start", String(args.scheduled_at_start)) if (args.scheduled_at_end != null) query.append("scheduled_at_end", String(args.scheduled_at_end)) for (const item of args.pipeline_id ?? []) query.append("pipeline_id", String(item)) if (args.responded != null) query.append("responded", String(args.responded)) const url = `${baseUrl.replace(/\/+$/, '')}/api/public/ticket-feedback${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(getApiApiPublicTicketFeedbackResponse, await res.json()) };