import {z} from 'zod' export type CreateApiV1AudiencesAudienceIdExportCompaniesArgs = {audienceId: string, body: {apiKey: string, format: 'PROSPECT_GENERIC_CSV' | 'PROSPECT_LI_ADS_CSV' | 'PROSPECT_GOOGLE_ADS_CSV' | 'PROSPECT_META_ADS_CSV' | 'COMPANY_GENERIC_CSV' | 'COMPANY_LI_ADS_CSV' | 'LI_PROFILE_URL_FIXUP' | 'LI_COMPANY_URL_FIXUP' | 'GOOGLE_MAPS_CSV' | 'DOMAIN_AGENT_CSV' | 'MOSAIC_CSV', maxRowsToExport?: (number | null) | undefined, excludeFields?: (Array<'fiber_id' | 'name' | 'all_names' | 'website' | 'domain' | 'linkedin_url' | 'linkedin_org_id' | 'logo_url' | 'headline' | 'description' | 'standard_industries' | 'linkedin_industries' | 'naics_codes' | 'hq_full_address' | 'hq_street_address' | 'hq_city' | 'hq_state' | 'hq_country' | 'hq_country_code' | 'hq_latitude' | 'hq_longitude' | 'num_offices' | 'all_office_addresses' | 'office_countries' | 'category' | 'employee_count_lower' | 'employee_count_upper' | 'founded_on' | 'num_followers' | 'office_locations' | 'office_locations_raw' | 'funding_stage' | 'last_funded_at' | 'last_funding_usd' | 'total_funding_usd' | 'market_cap_usd' | 'revenue_usd' | 'accelerators' | 'investors' | 'acquisitions' | 'funding_rounds' | 'stock_ticker' | 'num_exits' | 'tags' | 'job_posting_stats' | 'specialties' | 'phone_numbers' | 'facebook_urls' | 'x_urls' | 'github_usernames' | 'wellfound_urls' | 'blog_urls' | 'instagram_urls' | 'youtube_urls' | 'short_description' | 'long_description' | 'roles' | 'primary_role' | 'is_subsidiary' | 'parent' | 'matching_job_posting_urls' | 'matching_job_postings_json' | 'matching_job_postings_titles' | 'num_matching_job_postings' | 'num_role_matches' | 'custom'>) | undefined, userEmail?: (string | null) | undefined}}; export type CreateApiV1AudiencesAudienceIdExportCompaniesOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiV1AudiencesAudienceIdExportCompaniesResponse = z.object({output: z.object({message: z.string(), estimatedRows: z.number(), maxRowsAllowed: z.number()}), chargeInfo: z.union([z.object({method: z.literal("charged-now"), creditsCharged: z.number(), lowCreditAlert: z.object({getMoreCreditsUrl: z.string(), message: z.string(), availableCredits: z.number()}).nullable().optional()}), z.object({method: z.literal("charging-later"), message: z.string(), lowCreditAlert: z.object({getMoreCreditsUrl: z.string(), message: z.string(), availableCredits: z.number()}).nullable().optional()}), z.object({method: z.literal("charged-for-async-process"), creditsCharged: z.number(), message: z.string(), lowCreditAlert: z.object({getMoreCreditsUrl: z.string(), message: z.string(), availableCredits: z.number()}).nullable().optional()}), z.object({method: z.literal("free"), message: z.string(), lowCreditAlert: z.object({getMoreCreditsUrl: z.string(), message: z.string(), availableCredits: z.number()}).nullable().optional()}), z.object({method: z.literal("credits-refunded"), creditsRefunded: z.number(), message: z.string(), lowCreditAlert: z.object({getMoreCreditsUrl: z.string(), message: z.string(), availableCredits: z.number()}).nullable().optional()})]), warnings: z.array(z.object({field: z.string(), message: z.string()})).nullable().optional(), advice: z.array(z.string()).nullable().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 }; /** * Export audience companies to CSV * * POST /v1/audiences/{audienceId}/export/companies */ export const createApiV1AudiencesAudienceIdExportCompanies = async (args: CreateApiV1AudiencesAudienceIdExportCompaniesArgs, options?: CreateApiV1AudiencesAudienceIdExportCompaniesOptions) => { const {baseUrl = "https://api.fiber.ai", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/v1/audiences/${encodeURIComponent(String(args.audienceId))}/export/companies${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(createApiV1AudiencesAudienceIdExportCompaniesResponse, await res.json()) };