import {z} from 'zod' export type GetApiApiReportsPartnershipArgs = {category?: Array | undefined, subcategory?: Array | undefined, agency?: Array | undefined, league?: Array | undefined, tag?: Array | undefined, publishedBefore?: string | undefined, publishedAfter?: string | undefined}; export type GetApiApiReportsPartnershipOptions = {baseUrl: string, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const fileUploadResource = z.object({id: z.number().int().optional(), original_name: z.string().optional(), stored_name: z.string().optional(), mime_type: z.string().optional(), file_size: z.number().int().optional(), file_hash: z.string().optional(), url: z.string().optional(), created_at: z.string().optional(), updated_at: z.string().optional(), user: z.object({id: z.number().int().optional(), name: z.string().optional()}).optional(), thumbnail: z.object({id: z.number().int().optional(), original_url: z.string().optional(), image_url: z.string().optional(), resized_image_url: z.string().optional(), extension: z.string().optional(), mime_type: z.string().optional(), file_size: z.number().int().optional(), width: z.number().int().optional(), height: z.number().int().optional()}).optional()}); export const partnershipReportResource = z.object({id: z.number().int().optional(), title: z.string().optional(), description: z.string().optional(), report_external_url: z.string().optional(), thumbnail_url: z.string().optional(), resized_url: z.string().optional(), original_url: z.string().optional(), published_at: z.string().optional(), tags: z.array(z.object({id: z.number().int().optional(), name: z.string().optional()})).optional(), brands: z.array(z.object({id: z.number().int().optional(), name: z.string().optional()})).optional(), properties: z.array(z.object({id: z.number().int().optional(), name: z.string().optional()})).optional(), agencies: z.array(z.object({id: z.number().int().optional(), name: z.string().optional()})).optional(), file: fileUploadResource.optional()}); export const partnershipReportCollection = z.array(partnershipReportResource); 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 partnership reports * * GET /api/reports/partnership */ export const getApiApiReportsPartnership = async (args: GetApiApiReportsPartnershipArgs, options: GetApiApiReportsPartnershipOptions) => { const {baseUrl, fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") for (const item of args.category ?? []) query.append("category", String(item)) for (const item of args.subcategory ?? []) query.append("subcategory", String(item)) for (const item of args.agency ?? []) query.append("agency", String(item)) for (const item of args.league ?? []) query.append("league", String(item)) for (const item of args.tag ?? []) query.append("tag", String(item)) if (args.publishedBefore != null) query.append("publishedBefore", String(args.publishedBefore)) if (args.publishedAfter != null) query.append("publishedAfter", String(args.publishedAfter)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/reports/partnership${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(partnershipReportCollection, await res.json()) };