import {z} from 'zod' export type GetApiV1KrakenEmbedAssetsAssetIdArgs = {asset_id: string, quote?: string | undefined, lang?: string | undefined, 'privy-app-id': string}; export type GetApiV1KrakenEmbedAssetsAssetIdOptions = {baseUrl?: string | undefined, appSecretAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const getApiV1KrakenEmbedAssetsAssetIdResponse = z.object({data: z.object({errors: z.array(z.unknown()).optional(), error: z.array(z.unknown()).optional(), result: z.object({symbol: z.string().max(16), links: z.object({self: z.object({href: z.string(), type: z.string().nullable().optional()}), logo: z.object({href: z.string(), type: z.string().nullable().optional(), width: z.number().int().gte(0), height: z.number().int().gte(0)})}), english_name: z.string().nullable().optional(), description: z.string().nullable().optional(), bearish_insights: z.string().nullable().optional(), bullish_insights: z.string().nullable().optional(), circulating_supply: z.string().min(1).max(64).nullable().optional(), total_supply: z.string().min(1).max(64).nullable().optional(), max_supply: z.string().min(1).max(64).nullable().optional(), market_cap_value: z.string().min(1).max(64).nullable().optional(), change_value_24h: z.string().min(1).max(64).nullable().optional(), change_percent_24h: z.string().min(1).max(64).nullable().optional(), volume_value_24h: z.string().min(1).max(64).nullable().optional(), ath_value: z.string().min(1).max(64).nullable().optional(), ath_date: z.string().nullable().optional()}).nullable()})}); 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 Asset Details * * GET /v1/kraken_embed/assets/{asset_id} */ export const getApiV1KrakenEmbedAssetsAssetId = async (args: GetApiV1KrakenEmbedAssetsAssetIdArgs, options?: GetApiV1KrakenEmbedAssetsAssetIdOptions) => { const {baseUrl = "https://api.privy.io", fetch: fetchFn = fetch, appSecretAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.quote != null) query.append("quote", String(args.quote)) if (args.lang != null) query.append("lang", String(args.lang)) if (args['privy-app-id'] != null) headers.set("privy-app-id", String(args['privy-app-id'])) if (appSecretAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${appSecretAuth.username}:${appSecretAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/kraken_embed/assets/${encodeURIComponent(String(args.asset_id))}${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(getApiV1KrakenEmbedAssetsAssetIdResponse, await res.json()) };