import {z} from 'zod' export type CrossChainRoutesConfigDTO = Record; export type CrossChainRoutesDTO = {useTokenEnums?: boolean | undefined, crossChainRoutesConfig: CrossChainRoutesConfigDTO}; export type UpdateRegisteredSolverDTO = {intentExecutionTypes?: (Array<'SELF_PUBLISH' | 'GASLESS'>) | undefined, crossChainRoutes?: CrossChainRoutesDTO | undefined, quotesUrl?: string | undefined, quotesV2Url?: string | undefined, reverseQuotesUrl?: string | undefined, receiveSignedIntentUrl?: string | undefined, useSolverDataFormat?: boolean | undefined}; export type PatchApiApiV1SolverRegistryUpdateSolverArgs = {'x-beam-sig'?: string | undefined, 'x-beam-sig-expire'?: string | undefined, 'x-beam-sig-address'?: string | undefined, body: UpdateRegisteredSolverDTO}; export type PatchApiApiV1SolverRegistryUpdateSolverOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const ecoAPIResponse = z.object({}); 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 }; /** * Update Solver * * PATCH /api/v1/solverRegistry/updateSolver */ export const patchApiApiV1SolverRegistryUpdateSolver = async (args: PatchApiApiV1SolverRegistryUpdateSolverArgs, options?: PatchApiApiV1SolverRegistryUpdateSolverOptions) => { const {baseUrl = "https://quotes.eco.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['x-beam-sig'] != null) headers.set("x-beam-sig", String(args['x-beam-sig'])) if (args['x-beam-sig-expire'] != null) headers.set("x-beam-sig-expire", String(args['x-beam-sig-expire'])) if (args['x-beam-sig-address'] != null) headers.set("x-beam-sig-address", String(args['x-beam-sig-address'])) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/solverRegistry/updateSolver${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(ecoAPIResponse, await res.json()) };