import {z} from 'zod' export type ResearchDataRequestDTO = {countries?: (Array | null) | undefined, ad_platforms?: (Array | null) | undefined, ad_display_format?: (Array | null) | undefined, category?: (Array | null) | undefined, impression?: (Array | null) | undefined, ad_stage?: (Array | null) | undefined, sort_type?: (string | null) | undefined, sort_direction?: (string | null) | undefined, ad_status?: (Array | null) | undefined, keyword_value?: (Array | null) | undefined, brand_value?: (Array | null) | undefined, title_value?: (Array | null) | undefined, tiktok_reach?: (string | null) | undefined, language?: (Array | null) | undefined, family?: (Array | null) | undefined, is_organic?: (boolean | null) | undefined, is_partnership?: (boolean | null) | undefined, focus_area?: (Array | null) | undefined, campaign_objective?: (Array | null) | undefined, hook_type?: (Array | null) | undefined, ad_concept?: (Array | null) | undefined, talent_presenter_type?: (Array | null) | undefined, cta_type?: (Array | null) | undefined, visual_style?: (Array | null) | undefined, emotional_tone?: (Array | null) | undefined, personas?: (Array | null) | undefined, hook_style?: (Array | null) | undefined, hook_category?: (Array | null) | undefined, ad_style?: (Array | null) | undefined, logo_placement?: (Array | null) | undefined, text_overlay_density?: (Array | null) | undefined, logo_timing?: (Array | null) | undefined, claim_type?: (Array | null) | undefined, proof_element?: (Array | null) | undefined, disclaimer_present?: (Array | null) | undefined, social_proof_element?: (Array | null) | undefined, offer_type?: (Array | null) | undefined, target_gender?: (Array | null) | undefined, talent_count?: (Array | null) | undefined, talent_delivery?: (Array | null) | undefined, talent_age_band?: (Array | null) | undefined, talent_gender?: (Array | null) | undefined, product_visibility?: (Array | null) | undefined, scene_setting?: (Array | null) | undefined, audio_style?: (Array | null) | undefined, pacing_style?: (Array | null) | undefined, creative_category?: (Array | null) | undefined, ai_generated?: (Array | null) | undefined, video_len?: (Array | null) | undefined, sub_industries?: (Array | null) | undefined, date?: (Array | null) | undefined, brand_page_id?: (string | null) | undefined, avatar_url?: (string | null) | undefined, linkedin?: (boolean | null) | undefined, linkedin_company_name?: (string | null) | undefined, linkedin_keyword?: (string | null) | undefined, pinterest?: (boolean | null) | undefined, pinterest_keyword?: (string | null) | undefined, tiktok?: (boolean | null) | undefined, tiktok_keyword?: (string | null) | undefined, tiktok_ads?: (boolean | null) | undefined, tiktok_shop?: (boolean | null) | undefined, advertiser_token?: (string | null) | undefined, meta?: (boolean | null) | undefined, facebook_profile?: (boolean | null) | undefined, google_ads?: (boolean | null) | undefined, instagram?: (boolean | null) | undefined, meta_keyword?: (string | null) | undefined, meta_brand_value?: (string | null) | undefined, meta_page_id?: (string | null) | undefined, youtube?: (boolean | null) | undefined, youtube_keyword?: (string | null) | undefined, live_scraping_on?: (boolean | null) | undefined, page?: number | undefined, page_size?: number | undefined, has_next?: boolean | undefined, fuzzyPageNum?: number | undefined, next_cursor?: (string | null) | undefined, has_next_page?: (boolean | null) | undefined, load_more?: (boolean | null) | undefined, scrapping_keywords?: (Array | null) | undefined}; export type CreateApiApiV1ResearchSmartSearchResearchArgs = {use_model?: boolean | undefined, plan?: boolean | undefined, body: ResearchDataRequestDTO}; export type CreateApiApiV1ResearchSmartSearchResearchOptions = {baseUrl: string, JWTBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiApiV1ResearchSmartSearchResearchResponse = 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 }; /** * Smart Search Research * * POST /api/v1/research/smart-search-research */ export const createApiApiV1ResearchSmartSearchResearch = async (args: CreateApiApiV1ResearchSmartSearchResearchArgs, options: CreateApiApiV1ResearchSmartSearchResearchOptions) => { const {baseUrl, fetch: fetchFn = fetch, JWTBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.use_model != null) query.append("use_model", String(args.use_model)) if (args.plan != null) query.append("plan", String(args.plan)) if (JWTBearer !== undefined) headers.set('authorization', `Bearer ${JWTBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/research/smart-search-research${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(createApiApiV1ResearchSmartSearchResearchResponse, await res.json()) };