import {z} from 'zod' export type GetApiRollupInteractionsArgs = {tag: string, first: string, ratingFilters: string, categories: string, responseStatus: string, siteUrls: string, sortOrder: string, searchString: string, startDate: string, endDate: string, before: string, after: string, last: string, Authorization: string, 'Content-Type': string, body: BodyInit}; export type GetApiRollupInteractionsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiRollupInteractionsResponse = z.object({}); 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 }; /** * Rollup Review API * * GET /rollup_interactions */ export const getApiRollupInteractions = async (args: GetApiRollupInteractionsArgs, options?: GetApiRollupInteractionsOptions) => { const {baseUrl = "https://api.synup.com/api/v4", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "text/plain") headers.set('accept', "application/json") if (args.tag != null) query.append("tag", String(args.tag)) if (args.first != null) query.append("first", String(args.first)) if (args.ratingFilters != null) query.append("ratingFilters", String(args.ratingFilters)) if (args.categories != null) query.append("categories", String(args.categories)) if (args.responseStatus != null) query.append("responseStatus", String(args.responseStatus)) if (args.siteUrls != null) query.append("siteUrls", String(args.siteUrls)) if (args.sortOrder != null) query.append("sortOrder", String(args.sortOrder)) if (args.searchString != null) query.append("searchString", String(args.searchString)) if (args.startDate != null) query.append("startDate", String(args.startDate)) if (args.endDate != null) query.append("endDate", String(args.endDate)) if (args.before != null) query.append("before", String(args.before)) if (args.after != null) query.append("after", String(args.after)) if (args.last != null) query.append("last", String(args.last)) if (args.Authorization != null) headers.set("Authorization", String(args.Authorization)) if (args['Content-Type'] != null) headers.set("Content-Type", String(args['Content-Type'])) const url = `${baseUrl.replace(/\/+$/, '')}/rollup_interactions${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers, body: args.body}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiRollupInteractionsResponse, await res.json()) };