import {z} from 'zod' export type GetApiMerchantAccountMerchantIdCostClustersArgs = {merchantId: string, limit?: number | undefined, connector?: string | undefined, account?: string | undefined, report_date?: string | undefined, ingestion_id?: string | undefined, order?: string | undefined}; export type GetApiMerchantAccountMerchantIdCostClustersOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const apiClusterSegment = z.object({seg_idx: z.number().int().optional(), lo: z.number().optional(), hi: z.number().optional(), pct_bps: z.number().nullable().optional(), fixed: z.number().nullable().optional(), bps_rmse: z.number().nullable().optional(), n: z.number().int().optional(), gross_sum: z.number().optional(), verdict: z.enum(["GOOD", "THIN", "NON_LINEAR"]).optional()}); export const clusterFee = z.object({key: z.string().optional(), connector: z.string().optional(), card_network: z.string().optional(), variant: z.string().optional(), funding: z.string().optional(), issuer_country: z.string().optional(), currency: z.string().optional(), ic_category: z.string().optional(), n: z.number().int().optional(), gross_sum: z.number().optional(), model_pct_bps: z.number().nullable().optional(), model_fixed: z.number().nullable().optional(), override_pct_bps: z.number().nullable().optional(), override_fixed: z.number().nullable().optional(), override_updated_at: z.string().nullable().optional(), effective_pct_bps: z.number().nullable().optional(), effective_fixed: z.number().nullable().optional(), source: z.enum(["override", "model", "segmented"]).optional(), verdict: z.string().optional(), card_product: z.string().optional(), segments: z.array(apiClusterSegment).optional()}); export const getApiMerchantAccountMerchantIdCostClustersResponse = z.array(clusterFee); 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 cost clusters * * GET /merchant-account/{merchantId}/cost-clusters * * Also accepts auth: ApiKeyAuth */ export const getApiMerchantAccountMerchantIdCostClusters = async (args: GetApiMerchantAccountMerchantIdCostClustersArgs, options?: GetApiMerchantAccountMerchantIdCostClustersOptions) => { const {baseUrl = "http://localhost:8080", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.limit != null) query.append("limit", String(args.limit)) if (args.connector != null) query.append("connector", String(args.connector)) if (args.account != null) query.append("account", String(args.account)) if (args.report_date != null) query.append("report_date", String(args.report_date)) if (args.ingestion_id != null) query.append("ingestion_id", String(args.ingestion_id)) if (args.order != null) query.append("order", String(args.order)) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/merchant-account/${encodeURIComponent(String(args.merchantId))}/cost-clusters${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(getApiMerchantAccountMerchantIdCostClustersResponse, await res.json()) };