import {z} from 'zod' export type GetApiFeedbackPortalPortalIdFeedbackItemsArgs = {portalId: string, workspaceId?: string | undefined, page?: number | undefined, limit?: number | undefined, keyword?: string | undefined, shortId?: string | undefined, fields?: string | undefined, ids?: string | undefined, status?: string | undefined, internalStatus?: string | undefined, importance?: string | undefined, category?: string | undefined, company?: string | undefined, labels?: string | undefined, hasLinkedItems?: boolean | undefined, postedBy?: string | undefined, created_from?: string | undefined, created_to?: string | undefined, customFields?: string | undefined}; export type GetApiFeedbackPortalPortalIdFeedbackItemsOptions = {baseUrl: string, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const category = z.object({id: z.string(), name: z.string()}); export const entity = z.object({id: z.string().optional(), name: z.string().nullable().optional()}); export const person = z.object({id: z.string().optional(), name: z.string().nullable().optional(), email: z.string().optional()}); export const nullableTypeStringOrNumber = z.union([z.string(), z.number()]).nullable(); export const nullableTypeStringArray = z.array(z.string()).nullable(); export const customFieldValue = z.object({id: z.string(), name: z.string().optional(), value: nullableTypeStringOrNumber.optional(), values: nullableTypeStringArray.optional(), label: z.string().optional()}); export const linkedItem = z.object({id: z.string().optional(), shortId: z.string().optional(), title: z.string().optional(), webUrl: z.string().optional()}); export const nullableTypeLinkedItemArray = z.array(linkedItem).nullable(); export const itemComment = z.object({id: z.string().optional(), author: entity.optional(), createdAt: z.string().nullable().optional(), body: z.string().optional(), parentId: z.string().nullable().optional()}); export const nullableTypeString = z.string().nullable(); export const feedbackItem = z.object({id: z.string(), portalId: z.string().optional(), shortId: z.string().optional(), title: z.string().optional(), description: z.string().optional(), creationTime: z.string().optional(), updateTime: z.string().optional(), category: category.optional(), company: entity.optional(), owner: person.optional(), createdBy: person.optional(), status: entity.optional(), internalStatus: entity.optional(), importance: entity.optional(), labels: z.array(z.string()).optional(), customFields: z.array(customFieldValue).optional(), linkedItems: nullableTypeLinkedItemArray.optional(), commentCount: z.number().optional(), comments: z.array(itemComment).optional(), internalNoteCount: z.number().optional(), internalNotes: z.array(itemComment).optional(), sourceUrl: nullableTypeString.optional(), webUrl: z.string().optional()}); export const paginationMetadata = z.object({currentPage: z.number(), perPage: z.number(), totalPages: z.number(), totalRecords: z.number()}); export const feedbackItemsPaginatedFeedbackItem = z.object({items: z.array(feedbackItem), metadata: paginationMetadata}); 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 }; /** * Get the list of your feedback portal's items * * GET /feedback_portal/{portalId}/feedback_items */ export const getApiFeedbackPortalPortalIdFeedbackItems = async (args: GetApiFeedbackPortalPortalIdFeedbackItemsArgs, options: GetApiFeedbackPortalPortalIdFeedbackItemsOptions) => { const {baseUrl, fetch: fetchFn = fetch, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.workspaceId != null) query.append("workspaceId", String(args.workspaceId)) if (args.page != null) query.append("page", String(args.page)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.keyword != null) query.append("keyword", String(args.keyword)) if (args.shortId != null) query.append("shortId", String(args.shortId)) if (args.fields != null) query.append("fields", String(args.fields)) if (args.ids != null) query.append("ids", String(args.ids)) if (args.status != null) query.append("status", String(args.status)) if (args.internalStatus != null) query.append("internalStatus", String(args.internalStatus)) if (args.importance != null) query.append("importance", String(args.importance)) if (args.category != null) query.append("category", String(args.category)) if (args.company != null) query.append("company", String(args.company)) if (args.labels != null) query.append("labels", String(args.labels)) if (args.hasLinkedItems != null) query.append("hasLinkedItems", String(args.hasLinkedItems)) if (args.postedBy != null) query.append("postedBy", String(args.postedBy)) if (args.created_from != null) query.append("created_from", String(args.created_from)) if (args.created_to != null) query.append("created_to", String(args.created_to)) if (args.customFields != null) query.append("customFields", String(args.customFields)) if (apiKey !== undefined) headers.set("x-api-key", apiKey) const url = `${baseUrl.replace(/\/+$/, '')}/feedback_portal/${encodeURIComponent(String(args.portalId))}/feedback_items${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(feedbackItemsPaginatedFeedbackItem, await res.json()) };