import {z} from 'zod' export type GetApiInboundV2FeedfilesIdDetailedResultsOptions = {baseUrl?: string | undefined, mecOauth?: string | undefined, fetch?: typeof fetch | undefined}; export const fieldValue = z.object({modified_content: z.string().optional(), current_content: z.string(), value_modified: z.boolean(), dup_checking: z.boolean()}); export const successfulProcessedEntryResult = z.object({input_position: z.number().int(), result: z.string(), has_duplicate_record_info: z.boolean(), field_values: z.record(z.string(), fieldValue)}); export const discardedResultIssue = z.object({consequence: z.string(), explanation: z.string(), detail: z.string(), cause: z.string()}); export const discardedResult = z.object({input_position: z.number().int(), input_values: z.record(z.string(), z.string()), issues: z.array(discardedResultIssue)}); export const processingResult = z.object({entity_name: z.string(), successful_results: z.array(successfulProcessedEntryResult).optional(), discarded_results: z.array(discardedResult).optional()}); export const detailedResults = z.object({processing_results: z.array(processingResult).optional(), input_to_field_mappings: z.record(z.string(), z.array(z.string())).optional(), processing_error_description: z.string().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 }; /** * Provides the detailed processing results of a Feed File. This endpoint is only available in Medallia Experience Cloud 2023 Summer Release as an opt-in feature. Reach out to your Medallia contact to enable this API feature as part of the Early Adopter Program. * * GET /inbound/v2/feedfiles/{id}/detailed-results */ export const getApiInboundV2FeedfilesIdDetailedResults = async (options?: GetApiInboundV2FeedfilesIdDetailedResultsOptions) => { const {baseUrl = "https://instance-tenant.apis.medallia.com", fetch: fetchFn = fetch, mecOauth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (mecOauth !== undefined) headers.set('authorization', `Bearer ${mecOauth}`) const url = `${baseUrl.replace(/\/+$/, '')}/inbound/v2/feedfiles/${encodeURIComponent(String(args.id))}/detailed-results${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(detailedResults, await res.json()) };