import {z} from 'zod' export type GetApiAppAnalyzeGAuditAuditIdArgs = {auditId: number}; export type GetApiAppAnalyzeGAuditAuditIdOptions = {baseUrl: string, token?: string | undefined, fetch?: typeof fetch | undefined}; export const appAnalyzeGoogleAdsAuditResultSchema = z.object({id: z.number().int(), status: z.enum(["PASSED", "FAILED", "WARNING", "ERROR"]), title: z.string(), description: z.string().nullable(), scoreValue: z.number().int(), scoreMaxValue: z.number().int(), category: z.string().nullable(), summary: z.string().nullable().optional(), details: z.array(z.record(z.string(), z.unknown())).nullable()}); export const appAnalyzeGoogleAdsAuditSchema = z.object({id: z.number().int(), linkingId: z.number().int(), linkingCustomerId: z.number().int(), linkingName: z.string(), campaignId: z.number().int(), campaignName: z.string().nullable().optional(), status: z.enum(["QUEUED", "PROCESSING", "SUCCESSFUL"]), scope: z.enum(["CAMPAIGN", "SEARCH_ADS", "SEARCH_KEYWORDS", "SEARCH_TERMS", "P_MAX"]).optional(), auditedAt: z.string().nullable(), results: z.array(appAnalyzeGoogleAdsAuditResultSchema)}); export const getApiAppAnalyzeGAuditAuditIdResponse = z.object({data: appAnalyzeGoogleAdsAuditSchema}); 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 /app/analyze/g/audit/{auditId} */ export const getApiAppAnalyzeGAuditAuditId = async (args: GetApiAppAnalyzeGAuditAuditIdArgs, options: GetApiAppAnalyzeGAuditAuditIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, token} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (token !== undefined) headers.set("authorization", token) const url = `${baseUrl.replace(/\/+$/, '')}/app/analyze/g/audit/${encodeURIComponent(String(args.auditId))}${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(getApiAppAnalyzeGAuditAuditIdResponse, await res.json()) };