import {z} from 'zod' export type GetApiApiSocialScrapingSessionsArgs = {season: number, review_status: 'pending' | 'reviewed', grouped?: boolean | undefined, include_empty?: boolean | undefined, download?: boolean | undefined, league_id?: Array | undefined, property_list_id?: number | undefined, division_id?: Array | undefined, team_id?: Array | undefined, user_id?: Array | undefined, reviewer?: Array | undefined, type?: (Array<'twitter' | 'facebook' | 'instagram' | 'tiktok' | 'youtube' | 'twitch'>) | undefined, platform_handle?: Array | undefined, status_value?: Array | undefined, scouting_markets?: Array | undefined, order_by?: ('division_name' | 'followers_count' | 'team_name' | 'user_name' | 'reviewer_name' | 'start' | 'end' | 'brands_count' | 'items_count' | 'handle') | undefined, order_direction?: ('asc' | 'desc') | undefined, order?: ('asc' | 'desc') | undefined, page?: number | undefined, per_page?: number | undefined, infinite_scroll?: boolean | undefined}; export type GetApiApiSocialScrapingSessionsOptions = {baseUrl: string, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiSocialScrapingSessionsResponse = z.object({current_page: z.number().int().optional(), per_page: z.number().int().optional(), total: z.number().int().nullable().optional(), next_page_url: z.string().nullable().optional(), prev_page_url: z.string().nullable().optional(), data: z.array(z.object({id: z.number().int().optional(), type: z.string().optional(), handle: z.string().optional(), team_id: z.number().int().optional(), user_id: z.number().int().nullable().optional(), brands_count: z.number().int().optional(), items_count: z.number().int().optional(), statuses: z.string().nullable().optional(), start_date: z.string().nullable().optional(), end_date: z.string().nullable().optional(), scan_group: z.string().optional(), social_scraping_session_ids: z.string().nullable().optional(), has_unmatched_handles: z.boolean().optional(), has_rejected_companies: z.boolean().optional(), total_followers: z.number().int().nullable().optional(), platform_followers: z.number().int().nullable().optional(), latest_reviewed_at: z.string().nullable().optional()})).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 }; /** * List league social scraping sessions * * GET /api/social-scraping-sessions */ export const getApiApiSocialScrapingSessions = async (args: GetApiApiSocialScrapingSessionsArgs, options: GetApiApiSocialScrapingSessionsOptions) => { const {baseUrl, fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.season != null) query.append("season", String(args.season)) if (args.review_status != null) query.append("review_status", String(args.review_status)) if (args.grouped != null) query.append("grouped", String(args.grouped)) if (args.include_empty != null) query.append("include_empty", String(args.include_empty)) if (args.download != null) query.append("download", String(args.download)) for (const item of args.league_id ?? []) query.append("league_id", String(item)) if (args.property_list_id != null) query.append("property_list_id", String(args.property_list_id)) for (const item of args.division_id ?? []) query.append("division_id", String(item)) for (const item of args.team_id ?? []) query.append("team_id", String(item)) for (const item of args.user_id ?? []) query.append("user_id", String(item)) for (const item of args.reviewer ?? []) query.append("reviewer", String(item)) for (const item of args.type ?? []) query.append("type", String(item)) for (const item of args.platform_handle ?? []) query.append("platform_handle", String(item)) for (const item of args.status_value ?? []) query.append("status_value", String(item)) for (const item of args.scouting_markets ?? []) query.append("scouting_markets", String(item)) if (args.order_by != null) query.append("order_by", String(args.order_by)) if (args.order_direction != null) query.append("order_direction", String(args.order_direction)) if (args.order != null) query.append("order", String(args.order)) if (args.page != null) query.append("page", String(args.page)) if (args.per_page != null) query.append("per_page", String(args.per_page)) if (args.infinite_scroll != null) query.append("infinite_scroll", String(args.infinite_scroll)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/social-scraping-sessions${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(getApiApiSocialScrapingSessionsResponse, await res.json()) };