import {z} from 'zod' export type GetApiGatewayV1MarketTgeArgs = {id?: string | undefined, q?: string | undefined}; export type GetApiGatewayV1MarketTgeOptions = {baseUrl?: string | undefined, AccessToken?: string | undefined, fetch?: typeof fetch | undefined}; export const tGEItem = z.object({current_status: z.string(), exchanges: z.array(z.string()).nullable().optional(), last_event_time: z.number().int().optional(), project_id: z.string(), project_name: z.string().optional()}); export const objectResponseMeta = z.object({cached: z.boolean(), credits_used: z.number().int(), empty_reason: z.string().optional()}); export const dataObjectResponseTGEItem = z.object({$schema: z.string().optional(), data: tGEItem, meta: objectResponseMeta}); 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 }; /** * Token Generation Event * * GET /gateway/v1/market/tge */ export const getApiGatewayV1MarketTge = async (args: GetApiGatewayV1MarketTgeArgs, options?: GetApiGatewayV1MarketTgeOptions) => { const {baseUrl = "https://api.asksurf.ai", fetch: fetchFn = fetch, AccessToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.id != null) query.append("id", String(args.id)) if (args.q != null) query.append("q", String(args.q)) if (AccessToken !== undefined) headers.set('authorization', `Bearer ${AccessToken}`) const url = `${baseUrl.replace(/\/+$/, '')}/gateway/v1/market/tge${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(dataObjectResponseTGEItem, await res.json()) };