import {z} from 'zod' export type UpdateTokenConfigDto = {chatEnabled?: boolean | undefined, commentsEnabled?: boolean | undefined, facebookUrl?: (string | null) | undefined, instagramUrl?: (string | null) | undefined, nextLiveStreamAt?: (string | null) | undefined, redditUrl?: (string | null) | undefined, streamingEnabled?: boolean | undefined, streamLanguage?: string | undefined, telegramUrl?: (string | null) | undefined, tiktokUrl?: (string | null) | undefined, twitterUrl?: (string | null) | undefined, websiteUrl?: (string | null) | undefined}; export type PatchApiV1TokensTokenNameArgs = {tokenName: string, body: UpdateTokenConfigDto}; export type PatchApiV1TokensTokenNameOptions = {baseUrl?: string | undefined, apiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const tokenPoolRecordResponseDto = z.object({additionalKey: z.string().nullable(), blockNumber: z.number(), bondingCurvePercentage: z.number(), category: z.string().nullable(), chatStatus: z.string(), collection: z.string().nullable(), creatorAddress: z.string(), currentViewerCount: z.number(), description: z.string(), dexSynced: z.boolean(), engagementBadge: z.string().nullable().optional(), facebookUrl: z.string(), image: z.string(), initialBuyAmount: z.number(), instagramUrl: z.string(), isFinalized: z.number(), lastStreamedAt: z.string().nullable(), muxPlaybackId: z.string().nullable(), muxStreamAspectRatio: z.string().nullable(), muxStreamId: z.string().nullable(), muxStreamStatus: z.string().nullable(), nextLiveStreamAt: z.string().nullable(), peakViewerCount: z.number(), poolHash: z.string().optional(), recordingsCount: z.number(), redditUrl: z.string(), reverseBondingCurveMaxFeePortion: z.string().nullable(), reverseBondingCurveMinFeePortion: z.string().nullable(), saleStartTime: z.number().nullable().optional(), slowModeSeconds: z.number(), streamControlStatus: z.string(), streamLanguage: z.string(), streamStartedAt: z.string().nullable(), symbol: z.string(), telegramUrl: z.string(), tiktokUrl: z.string(), tokenName: z.string(), totalSecondsStreamed: z.number(), twitterUrl: z.string(), type: z.string().nullable(), vaultAddress: z.string(), volume: z.number(), volume1h: z.number(), volumeBadge: z.string().nullable().optional(), volumeSum: z.number(), websiteUrl: z.string()}); export const patchApiV1TokensTokenNameResponse = z.object({error: z.literal(false), message: z.string(), status: z.number(), data: tokenPoolRecordResponseDto}); 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 }; /** * Update token configuration * * PATCH /v1/tokens/{tokenName} * * Also accepts auth: bearer */ export const patchApiV1TokensTokenName = async (args: PatchApiV1TokensTokenNameArgs, options?: PatchApiV1TokensTokenNameOptions) => { const {baseUrl = "https://lpad-backend.stage.defi.ovh.gala.com", fetch: fetchFn = fetch, apiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (apiKeyAuth !== undefined) headers.set("x-api-key", apiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/v1/tokens/${encodeURIComponent(String(args.tokenName))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(patchApiV1TokensTokenNameResponse, await res.json()) };