import {z} from 'zod' export type GetApiCosmosFeegrantV1beta1AllowanceGranterGranteeArgs = {granter: string, grantee: string}; export type GetApiCosmosFeegrantV1beta1AllowanceGranterGranteeOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const getApiCosmosFeegrantV1beta1AllowanceGranterGranteeResponse = z.object({allowance: z.object({granter: z.string().optional(), grantee: z.string().optional(), allowance: z.object({"@type": z.string().optional()}).and(z.record(z.string(), z.unknown())).optional()}).optional()}); 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 }; /** * Allowance returns fee granted to the grantee by the granter. * * GET /cosmos/feegrant/v1beta1/allowance/{granter}/{grantee} */ export const getApiCosmosFeegrantV1beta1AllowanceGranterGrantee = async (args: GetApiCosmosFeegrantV1beta1AllowanceGranterGranteeArgs, options: GetApiCosmosFeegrantV1beta1AllowanceGranterGranteeOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/cosmos/feegrant/v1beta1/allowance/${encodeURIComponent(String(args.granter))}/${encodeURIComponent(String(args.grantee))}${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(getApiCosmosFeegrantV1beta1AllowanceGranterGranteeResponse, await res.json()) };