import {z} from 'zod' export type GetApiSocialIntelligenceCreatorsHandleVideosArgs = {handle: string, page?: number | undefined, page_size?: number | undefined, sort_by?: (string | null) | undefined, sort_order?: string | undefined, days?: (number | null) | undefined, seller_id?: (string | null) | undefined}; export type GetApiSocialIntelligenceCreatorsHandleVideosOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, ShopId?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiSocialIntelligenceCreatorsHandleVideosResponse = z.unknown(); 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 }; /** * A creator's shop videos * * GET /social-intelligence/creators/{handle}/videos */ export const getApiSocialIntelligenceCreatorsHandleVideos = async (args: GetApiSocialIntelligenceCreatorsHandleVideosArgs, options?: GetApiSocialIntelligenceCreatorsHandleVideosOptions) => { const {baseUrl = "https://api.reacherapp.com/public/v1", fetch: fetchFn = fetch, ApiKeyAuth, ShopId} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.page != null) query.append("page", String(args.page)) if (args.page_size != null) query.append("page_size", String(args.page_size)) if (args.sort_by != null) query.append("sort_by", String(args.sort_by)) if (args.sort_order != null) query.append("sort_order", String(args.sort_order)) if (args.days != null) query.append("days", String(args.days)) if (args.seller_id != null) query.append("seller_id", String(args.seller_id)) if (ApiKeyAuth !== undefined) headers.set("x-api-key", ApiKeyAuth) if (ShopId !== undefined) headers.set("x-shop-id", ShopId) const url = `${baseUrl.replace(/\/+$/, '')}/social-intelligence/creators/${encodeURIComponent(String(args.handle))}/videos${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(getApiSocialIntelligenceCreatorsHandleVideosResponse, await res.json()) };