import {z} from 'zod' export type GetApiApiExternalV2DealsDealIdIndexMetricDefinitionsArgs = {deal_id: number, metric_label?: (string | null) | undefined, category_id?: (number | null) | undefined, page?: number | undefined, limit?: number | undefined}; export type GetApiApiExternalV2DealsDealIdIndexMetricDefinitionsOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const dealIndexMetricDefinitionResponse = z.object({id: z.number().int().nullable().optional(), metric_key: z.string().nullable().optional(), metric_label: z.string().nullable().optional(), value_type: z.string().nullable().optional(), category_id: z.number().int().nullable().optional(), is_temporal: z.boolean().nullable().optional(), formatting_rules: z.string().nullable().optional(), support_multiple_values: z.boolean().nullable().optional(), entity_type: z.string().nullable().optional(), editable_form: z.string().nullable().optional(), exclude_from_extraction: z.boolean().nullable().optional()}); export const dealIndexMetricDefinitionListResponse = z.object({request_id: z.string(), timestamp: z.string(), data: z.array(dealIndexMetricDefinitionResponse), pagination: z.unknown()}); 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 Deal Index Metric Definitions * * GET /api/external/v2/deals/{deal_id}/index/metric-definitions */ export const getApiApiExternalV2DealsDealIdIndexMetricDefinitions = async (args: GetApiApiExternalV2DealsDealIdIndexMetricDefinitionsArgs, options: GetApiApiExternalV2DealsDealIdIndexMetricDefinitionsOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.metric_label != null) query.append("metric_label", String(args.metric_label)) if (args.category_id != null) query.append("category_id", String(args.category_id)) if (args.page != null) query.append("page", String(args.page)) if (args.limit != null) query.append("limit", String(args.limit)) const url = `${baseUrl.replace(/\/+$/, '')}/api/external/v2/deals/${encodeURIComponent(String(args.deal_id))}/index/metric-definitions${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(dealIndexMetricDefinitionListResponse, await res.json()) };