import {z} from 'zod' export type GetApiV1AudiencesAudienceIdOperationsOperationIdStateDebugArgs = {audience_id: string, operation_id: string}; export type GetApiV1AudiencesAudienceIdOperationsOperationIdStateDebugOptions = {baseUrl?: string | undefined, HEADER?: string | undefined, fetch?: typeof fetch | undefined}; export const zonedDateTime = z.string(); export const audienceOperationResultResponse = z.object({anonymous_count: z.number().int().optional(), last_update: zonedDateTime.optional(), member_count: z.number().int().optional(), non_processed_count: z.number().int().optional()}); export const audienceOperationStateDebugResponse = z.discriminatedUnion("type", [z.object({created_date: zonedDateTime, debug_message: z.string(), error_code: z.enum(["COLUMN_CONFIGURATION_ERROR", "CONFIGURATION_ERROR", "EVENTS_EXECUTION_ERROR", "EXECUTION_ERROR", "INPUT_FILE_ERROR", "INTERRUPT", "MEMBERS_COUNT_VALIDATION_RETRIES_EXHAUSTED", "MEMORY_ERROR", "MISMATCH_EVENTS_EXECUTION_ERROR", "ROW_COUNT_VALIDATION_RETRIES_EXHAUSTED", "SOFTWARE_ERROR", "STORAGE_ERROR", "UNKNOWN"]), error_message: z.string(), input_rows_count: z.number().int(), state: z.enum(["BUILDING", "CANCELED", "EXPIRED", "FAILED", "PREPARING", "READY", "VALIDATING"]), state_reached_date: zonedDateTime, type: z.literal("ACTION"), updated_date: zonedDateTime}), z.object({created_date: zonedDateTime, debug_message: z.string(), error_code: z.enum(["COLUMN_CONFIGURATION_ERROR", "CONFIGURATION_ERROR", "EVENTS_EXECUTION_ERROR", "EXECUTION_ERROR", "INPUT_FILE_ERROR", "INTERRUPT", "MEMBERS_COUNT_VALIDATION_RETRIES_EXHAUSTED", "MEMORY_ERROR", "MISMATCH_EVENTS_EXECUTION_ERROR", "ROW_COUNT_VALIDATION_RETRIES_EXHAUSTED", "SOFTWARE_ERROR", "STORAGE_ERROR", "UNKNOWN"]), error_message: z.string(), input_rows_count: z.number().int(), state: z.enum(["BUILDING", "CANCELED", "EXPIRED", "FAILED", "PREPARING", "READY", "VALIDATING"]), state_reached_date: zonedDateTime, type: z.literal("ADD"), updated_date: zonedDateTime, result: audienceOperationResultResponse, retry_count: z.number().int()}), z.object({created_date: zonedDateTime, debug_message: z.string(), error_code: z.enum(["COLUMN_CONFIGURATION_ERROR", "CONFIGURATION_ERROR", "EVENTS_EXECUTION_ERROR", "EXECUTION_ERROR", "INPUT_FILE_ERROR", "INTERRUPT", "MEMBERS_COUNT_VALIDATION_RETRIES_EXHAUSTED", "MEMORY_ERROR", "MISMATCH_EVENTS_EXECUTION_ERROR", "ROW_COUNT_VALIDATION_RETRIES_EXHAUSTED", "SOFTWARE_ERROR", "STORAGE_ERROR", "UNKNOWN"]), error_message: z.string(), input_rows_count: z.number().int(), state: z.enum(["BUILDING", "CANCELED", "EXPIRED", "FAILED", "PREPARING", "READY", "VALIDATING"]), state_reached_date: zonedDateTime, type: z.literal("REMOVE"), updated_date: zonedDateTime, result: audienceOperationResultResponse, retry_count: z.number().int()}), z.object({created_date: zonedDateTime, debug_message: z.string(), error_code: z.enum(["COLUMN_CONFIGURATION_ERROR", "CONFIGURATION_ERROR", "EVENTS_EXECUTION_ERROR", "EXECUTION_ERROR", "INPUT_FILE_ERROR", "INTERRUPT", "MEMBERS_COUNT_VALIDATION_RETRIES_EXHAUSTED", "MEMORY_ERROR", "MISMATCH_EVENTS_EXECUTION_ERROR", "ROW_COUNT_VALIDATION_RETRIES_EXHAUSTED", "SOFTWARE_ERROR", "STORAGE_ERROR", "UNKNOWN"]), error_message: z.string(), input_rows_count: z.number().int(), state: z.enum(["BUILDING", "CANCELED", "EXPIRED", "FAILED", "PREPARING", "READY", "VALIDATING"]), state_reached_date: zonedDateTime, type: z.literal("REPLACE"), updated_date: zonedDateTime, result: audienceOperationResultResponse, retry_count: z.number().int()})]); 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 audience operation debug state * * GET /v1/audiences/{audience_id}/operations/{operation_id}/state/debug * * Also accepts auth: QUERY, COOKIE */ export const getApiV1AudiencesAudienceIdOperationsOperationIdStateDebug = async (args: GetApiV1AudiencesAudienceIdOperationsOperationIdStateDebugArgs, options?: GetApiV1AudiencesAudienceIdOperationsOperationIdStateDebugOptions) => { const {baseUrl = "https://api.extole.io", fetch: fetchFn = fetch, HEADER} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (HEADER !== undefined) headers.set("Authorization", HEADER) const url = `${baseUrl.replace(/\/+$/, '')}/v1/audiences/${encodeURIComponent(String(args.audience_id))}/operations/${encodeURIComponent(String(args.operation_id))}/state/debug${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(audienceOperationStateDebugResponse, await res.json()) };