import {z} from 'zod' export type GetApiV2TicketFeedbackArgs = {teamId?: string | undefined, pageSize?: number | undefined, pageToken?: string | undefined, 'requestedAfter.seconds'?: (number | unknown) | undefined, includeUnansweredRequests?: boolean | undefined}; export type GetApiV2TicketFeedbackOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const svhelpPubapimodelsDetailedFeedback = z.object({starRating: z.number().int().optional(), textFeedback: z.string().nullable().optional()}); export const svhelpPubapimodelsFeedbackSubjectType = z.enum(["FEEDBACK_SUBJECT_TYPE_UNSPECIFIED", "FEEDBACK_SUBJECT_TYPE_SERVAL", "FEEDBACK_SUBJECT_TYPE_AGENT"]); export const googleProtobufTimestamp = z.string(); export const svhelpPubapimodelsThumbsFeedback = z.object({isPositive: z.boolean().optional()}); export const svhelpPubapimodelsTicketFeedback = z.union([z.object({detailed: svhelpPubapimodelsDetailedFeedback, id: z.string().optional(), ticketId: z.string().optional(), targetUserId: z.string().optional(), feedbackSubjectType: svhelpPubapimodelsFeedbackSubjectType.optional(), feedbackAboutUserId: z.string().optional(), requestedAt: googleProtobufTimestamp.optional(), respondedAt: googleProtobufTimestamp.optional()}), z.object({thumbs: svhelpPubapimodelsThumbsFeedback, id: z.string().optional(), ticketId: z.string().optional(), targetUserId: z.string().optional(), feedbackSubjectType: svhelpPubapimodelsFeedbackSubjectType.optional(), feedbackAboutUserId: z.string().optional(), requestedAt: googleProtobufTimestamp.optional(), respondedAt: googleProtobufTimestamp.optional()})]); export const svhelpPublicapiListTicketFeedbackResponse = z.object({data: z.array(svhelpPubapimodelsTicketFeedback).optional(), nextPageToken: z.string().nullable().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 Feedback * * GET /v2/ticket-feedback */ export const getApiV2TicketFeedback = async (args: GetApiV2TicketFeedbackArgs, options?: GetApiV2TicketFeedbackOptions) => { const {baseUrl = "https://public.api.serval.com", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.teamId != null) query.append("teamId", String(args.teamId)) if (args.pageSize != null) query.append("pageSize", String(args.pageSize)) if (args.pageToken != null) query.append("pageToken", String(args.pageToken)) if (args['requestedAfter.seconds'] != null) query.append("requestedAfter.seconds", String(args['requestedAfter.seconds'])) if (args.includeUnansweredRequests != null) query.append("includeUnansweredRequests", String(args.includeUnansweredRequests)) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v2/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(svhelpPublicapiListTicketFeedbackResponse, await res.json()) };