import {z} from 'zod' export type GetApiV1ListingsProcessingReportsArgs = {agencyId: number, providerAdId: string}; export type GetApiV1ListingsProcessingReportsOptions = {baseUrl?: string | undefined, apikey?: string | undefined, fetch?: typeof fetch | undefined}; export const domainListingAdminServiceV1ModelModelEvent = z.object({severity: z.enum(["Info", "Warning", "Error"]).optional(), issueType: z.enum(["Internal", "External"]).optional(), message: z.string().optional()}); export const domainListingAdminServiceV1ModelReportVersion = z.object({operations: z.array(z.string()).optional(), versionId: z.string().optional(), processedDate: z.string().optional(), dataUrl: z.string().optional(), processCount: z.number().int().optional()}); export const domainListingAdminServiceV1ModelListingReport = z.object({processStatus: z.enum(["queued", "processing", "processed", "searchable", "failed", "error"]).optional(), agencyId: z.number().int().optional(), providerId: z.string().optional(), providerAdId: z.string().optional(), adId: z.array(z.number().int()).optional(), qualityScore: z.number().int().optional(), events: z.array(domainListingAdminServiceV1ModelModelEvent).optional(), versions: z.array(domainListingAdminServiceV1ModelReportVersion).optional()}); export const getApiV1ListingsProcessingReportsResponse = z.array(domainListingAdminServiceV1ModelListingReport); 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 }; /** * Searches processing reports * * GET /v1/listings/processingReports * * Also accepts auth: oauth2 */ export const getApiV1ListingsProcessingReports = async (args: GetApiV1ListingsProcessingReportsArgs, options?: GetApiV1ListingsProcessingReportsOptions) => { const {baseUrl = "https://api.domain.com.au", fetch: fetchFn = fetch, apikey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.agencyId != null) query.append("agencyId", String(args.agencyId)) if (args.providerAdId != null) query.append("providerAdId", String(args.providerAdId)) if (apikey !== undefined) headers.set("x-api-key", apikey) const url = `${baseUrl.replace(/\/+$/, '')}/v1/listings/processingReports${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(getApiV1ListingsProcessingReportsResponse, await res.json()) };