import {z} from 'zod' export type SupportV1CreateReplyRequest = {attachments?: string | undefined, content?: string | undefined, ticketId?: string | undefined}; export type CreateApiV1MeTicketsTicketIdRepliesArgs = {ticketId: string, body: SupportV1CreateReplyRequest}; export type CreateApiV1MeTicketsTicketIdRepliesOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const supportV1TicketReplyInfo = z.object({attachments: z.string().optional(), content: z.string().optional(), createdAt: z.string().optional(), id: z.string().optional(), isStaff: z.boolean().optional(), ticketId: z.string().optional(), userId: z.string().optional()}); export const supportV1CreateReplyReply = z.object({reply: supportV1TicketReplyInfo.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 }; /** * CreateReply 创建工单回复 * * POST /v1/me/tickets/{ticketId}/replies */ export const createApiV1MeTicketsTicketIdReplies = async (args: CreateApiV1MeTicketsTicketIdRepliesArgs, options: CreateApiV1MeTicketsTicketIdRepliesOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/v1/me/tickets/${encodeURIComponent(String(args.ticketId))}/replies${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(supportV1CreateReplyReply, await res.json()) };