import {z} from 'zod' export type GetApiV1InviteAccountAccountArgs = {account: string}; export type GetApiV1InviteAccountAccountOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const apiGetInviteAccountResponse = z.object({has_access: z.boolean().optional(), status: z.string().optional(), invited_by: z.string().optional(), activated_at: z.string().optional(), terms_accepted: z.boolean().optional(), volume: z.string().optional(), invitees_volume: z.string().optional(), cumulative_volume: z.string().optional(), total_codes_earned: z.number().int().optional(), next_code_threshold: z.string().optional(), next_code_drop_time: z.string().optional(), deposit_deadline: z.string().optional(), volume_maker: z.string().optional(), volume_taker: z.string().optional(), invitees_volume_maker: z.string().optional(), invitees_volume_taker: z.string().optional(), invitees_volume_all_time_maker: z.string().optional(), invitees_volume_all_time_taker: z.string().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 }; /** * Get invite account * * GET /v1/invite/account/{account} */ export const getApiV1InviteAccountAccount = async (args: GetApiV1InviteAccountAccountArgs, options?: GetApiV1InviteAccountAccountOptions) => { const {baseUrl = "https://api.testnet.rise.trade", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/v1/invite/account/${encodeURIComponent(String(args.account))}${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(apiGetInviteAccountResponse, await res.json()) };