import {z} from 'zod' export type GetApiTreasuryFeesArgs = {instrument?: string | undefined, from_month?: string | undefined, to_month?: string | undefined, cursor?: string | undefined, limit?: number | undefined, 'LMG-Data-Privacy-Access-Principal': string, 'LMG-Data-Privacy-Access-Justification': string}; export type GetApiTreasuryFeesOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const billingPeriod = z.object({start_date: z.string(), end_date: z.string(), billing_month: z.string()}); export const partnerTreasuryFeesResponse = z.object({id: z.string(), instrument: z.string(), total_fee_amount: z.string(), currency: z.string(), billing_period: billingPeriod}); export const encodedPaginationResponse = z.object({next_cursor: z.string().optional()}); export const encodedPaginatedCollectionResponsePartnerTreasuryFeesResponse = z.object({data: z.array(partnerTreasuryFeesResponse), pagination: encodedPaginationResponse}); 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 Treasury Fees * * GET /treasury_fees */ export const getApiTreasuryFees = async (args: GetApiTreasuryFeesArgs, options?: GetApiTreasuryFeesOptions) => { const {baseUrl = "https://sandbox.api.lemon.markets/v1", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.instrument != null) query.append("instrument", String(args.instrument)) if (args.from_month != null) query.append("from_month", String(args.from_month)) if (args.to_month != null) query.append("to_month", String(args.to_month)) if (args.cursor != null) query.append("cursor", String(args.cursor)) if (args.limit != null) query.append("limit", String(args.limit)) if (args['LMG-Data-Privacy-Access-Principal'] != null) headers.set("LMG-Data-Privacy-Access-Principal", String(args['LMG-Data-Privacy-Access-Principal'])) if (args['LMG-Data-Privacy-Access-Justification'] != null) headers.set("LMG-Data-Privacy-Access-Justification", String(args['LMG-Data-Privacy-Access-Justification'])) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/treasury_fees${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(encodedPaginatedCollectionResponsePartnerTreasuryFeesResponse, await res.json()) };