import {z} from 'zod' export type GetApiApplicationsClientIdReactionSpaceCountsArgs = {reaction_space_id: string, target_group_id?: string | undefined, 'client-id': string}; export type GetApiApplicationsClientIdReactionSpaceCountsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApplicationsClientIdReactionSpaceCountsResponse = z.object({previous: z.unknown(), results: z.array(z.object({reactions: z.array(z.object({reaction_id: z.string().optional(), count: z.number().int().optional(), self_reacted_user_reaction_id: z.string().optional()})).optional(), target_id: z.string().optional()})).optional(), next: z.unknown(), count: z.number().int().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 user reaction count * * GET /applications/{client-id}/reaction-space-counts/ */ export const getApiApplicationsClientIdReactionSpaceCounts = async (args: GetApiApplicationsClientIdReactionSpaceCountsArgs, options?: GetApiApplicationsClientIdReactionSpaceCountsOptions) => { const {baseUrl = "https://cf-blast.livelikecdn.com/api/v1", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.reaction_space_id != null) query.append("reaction_space_id", String(args.reaction_space_id)) if (args.target_group_id != null) query.append("target_group_id", String(args.target_group_id)) const url = `${baseUrl.replace(/\/+$/, '')}/applications/${encodeURIComponent(String(args['client-id']))}/reaction-space-counts/${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(getApiApplicationsClientIdReactionSpaceCountsResponse, await res.json()) };