import {z} from 'zod' export type GetApiPostsPostIdInlineCommentsArgs = {postId: string, channel?: ('LinkedIn' | 'Twitter' | 'Instagram' | 'Facebook' | 'Threads' | 'TikTok' | 'Discord' | 'Slack' | 'Webflow' | 'YouTubeShorts') | undefined, resolved?: boolean | undefined}; export type GetApiPostsPostIdInlineCommentsOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const commentUser = z.object({id: z.string().optional(), firstName: z.string().nullable().optional(), lastName: z.string().nullable().optional(), email: z.string().optional()}); export const inlineCommentReaction = z.object({emoji: z.string().optional(), users: z.array(commentUser).optional()}); export const inlineCommentReply = z.object({id: z.string().optional(), user: commentUser.optional(), message: z.string().optional(), createdAt: z.string().optional(), reactions: z.array(inlineCommentReaction).optional()}); export const inlineComment = z.object({id: z.string().optional(), resolved: z.boolean().optional(), channel: z.string().optional(), highlightedText: z.string().optional(), replies: z.array(inlineCommentReply).optional(), createdAt: z.string().optional(), updatedAt: z.string().nullable().optional()}); export const getApiPostsPostIdInlineCommentsResponse = z.object({inlineComments: z.array(inlineComment).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 inline comments on a post * * GET /posts/{postId}/inline-comments */ export const getApiPostsPostIdInlineComments = async (args: GetApiPostsPostIdInlineCommentsArgs, options?: GetApiPostsPostIdInlineCommentsOptions) => { const {baseUrl = "https://app.tryordinal.com/api/v1", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.channel != null) query.append("channel", String(args.channel)) if (args.resolved != null) query.append("resolved", String(args.resolved)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/posts/${encodeURIComponent(String(args.postId))}/inline-comments${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(getApiPostsPostIdInlineCommentsResponse, await res.json()) };