|
| 1 | +import { authenticatedFetch } from "../auth-helpers"; |
| 2 | + |
| 3 | +const API_BASE_URL = process.env.NEXT_PUBLIC_API_URL || "http://localhost:8000"; |
| 4 | + |
| 5 | +export interface CreatorBasic { |
| 6 | + id: string; |
| 7 | + display_name: string; |
| 8 | + tagline: string | null; |
| 9 | + bio: string | null; |
| 10 | + profile_picture_url: string | null; |
| 11 | + primary_niche: string; |
| 12 | + secondary_niches: string[] | null; |
| 13 | + total_followers: number; |
| 14 | + engagement_rate: number | null; |
| 15 | + is_verified_creator: boolean; |
| 16 | + profile_completion_percentage: number; |
| 17 | +} |
| 18 | + |
| 19 | +export interface CreatorFull extends CreatorBasic { |
| 20 | + user_id: string; |
| 21 | + cover_image_url: string | null; |
| 22 | + website_url: string | null; |
| 23 | + youtube_url: string | null; |
| 24 | + youtube_handle: string | null; |
| 25 | + youtube_subscribers: number | null; |
| 26 | + instagram_url: string | null; |
| 27 | + instagram_handle: string | null; |
| 28 | + instagram_followers: number | null; |
| 29 | + tiktok_url: string | null; |
| 30 | + tiktok_handle: string | null; |
| 31 | + tiktok_followers: number | null; |
| 32 | + twitter_url: string | null; |
| 33 | + twitter_handle: string | null; |
| 34 | + twitter_followers: number | null; |
| 35 | + twitch_url: string | null; |
| 36 | + twitch_handle: string | null; |
| 37 | + twitch_followers: number | null; |
| 38 | + linkedin_url: string | null; |
| 39 | + facebook_url: string | null; |
| 40 | + content_types: string[] | null; |
| 41 | + content_language: string[] | null; |
| 42 | + total_reach: number | null; |
| 43 | + average_views: number | null; |
| 44 | + audience_age_primary: string | null; |
| 45 | + audience_gender_split: Record<string, any> | null; |
| 46 | + audience_locations: Record<string, any> | null; |
| 47 | + audience_interests: string[] | null; |
| 48 | + average_engagement_per_post: number | null; |
| 49 | + posting_frequency: string | null; |
| 50 | + best_performing_content_type: string | null; |
| 51 | + years_of_experience: number | null; |
| 52 | + content_creation_full_time: boolean; |
| 53 | + team_size: number; |
| 54 | + equipment_quality: string | null; |
| 55 | + editing_software: string[] | null; |
| 56 | + collaboration_types: string[] | null; |
| 57 | + preferred_brands_style: string[] | null; |
| 58 | + rate_per_post: number | null; |
| 59 | + rate_per_video: number | null; |
| 60 | + rate_per_story: number | null; |
| 61 | + rate_per_reel: number | null; |
| 62 | + rate_negotiable: boolean; |
| 63 | + accepts_product_only_deals: boolean; |
| 64 | + minimum_deal_value: number | null; |
| 65 | + preferred_payment_terms: string | null; |
| 66 | + portfolio_links: string[] | null; |
| 67 | + past_brand_collaborations: string[] | null; |
| 68 | + case_study_links: string[] | null; |
| 69 | + media_kit_url: string | null; |
| 70 | + created_at: string | null; |
| 71 | + last_active_at: string | null; |
| 72 | +} |
| 73 | + |
| 74 | +export interface ListCreatorsParams { |
| 75 | + search?: string; |
| 76 | + niche?: string; |
| 77 | + limit?: number; |
| 78 | + offset?: number; |
| 79 | +} |
| 80 | + |
| 81 | +/** |
| 82 | + * List all creators with optional search and filters |
| 83 | + */ |
| 84 | +export async function listCreators( |
| 85 | + params: ListCreatorsParams = {} |
| 86 | +): Promise<CreatorBasic[]> { |
| 87 | + const queryParams = new URLSearchParams(); |
| 88 | + if (params.search) queryParams.append("search", params.search); |
| 89 | + if (params.niche) queryParams.append("niche", params.niche); |
| 90 | + if (params.limit) queryParams.append("limit", params.limit.toString()); |
| 91 | + if (params.offset) queryParams.append("offset", params.offset.toString()); |
| 92 | + |
| 93 | + const url = `${API_BASE_URL}/creators?${queryParams.toString()}`; |
| 94 | + const response = await authenticatedFetch(url); |
| 95 | + |
| 96 | + if (!response.ok) { |
| 97 | + // Try to get error details from response |
| 98 | + let errorMessage = `Failed to fetch creators: ${response.statusText}`; |
| 99 | + try { |
| 100 | + const errorData = await response.json(); |
| 101 | + if (errorData.detail) { |
| 102 | + errorMessage = errorData.detail; |
| 103 | + } |
| 104 | + } catch { |
| 105 | + // If response is not JSON, use status text |
| 106 | + } |
| 107 | + |
| 108 | + const error = new Error(errorMessage); |
| 109 | + (error as any).status = response.status; |
| 110 | + throw error; |
| 111 | + } |
| 112 | + |
| 113 | + return response.json(); |
| 114 | +} |
| 115 | + |
| 116 | +/** |
| 117 | + * Get full details of a specific creator |
| 118 | + */ |
| 119 | +export async function getCreatorDetails(creatorId: string): Promise<CreatorFull> { |
| 120 | + const url = `${API_BASE_URL}/creators/${creatorId}`; |
| 121 | + const response = await authenticatedFetch(url); |
| 122 | + |
| 123 | + if (!response.ok) { |
| 124 | + throw new Error(`Failed to fetch creator details: ${response.statusText}`); |
| 125 | + } |
| 126 | + |
| 127 | + return response.json(); |
| 128 | +} |
| 129 | + |
| 130 | +export interface CreatorRecommendation { |
| 131 | + id: string; |
| 132 | + display_name: string; |
| 133 | + profile_picture_url: string | null; |
| 134 | + primary_niche: string | null; |
| 135 | + total_followers: number | null; |
| 136 | + engagement_rate: number | null; |
| 137 | + top_platforms?: string[] | null; |
| 138 | + match_score: number; |
| 139 | + reason: string; |
| 140 | +} |
| 141 | + |
| 142 | +export async function getCreatorRecommendations(limit = 4): Promise<CreatorRecommendation[]> { |
| 143 | + const url = `${API_BASE_URL}/creators/recommendations?limit=${limit}`; |
| 144 | + const response = await authenticatedFetch(url); |
| 145 | + |
| 146 | + if (!response.ok) { |
| 147 | + const errText = await response.text().catch(() => ""); |
| 148 | + throw new Error(`Failed to fetch recommendations: ${response.status} ${errText}`); |
| 149 | + } |
| 150 | + return response.json(); |
| 151 | +} |
| 152 | + |
| 153 | +/** |
| 154 | + * Get list of all unique niches |
| 155 | + */ |
| 156 | +export async function listNiches(): Promise<string[]> { |
| 157 | + const url = `${API_BASE_URL}/creators/niches/list`; |
| 158 | + const response = await authenticatedFetch(url); |
| 159 | + |
| 160 | + if (!response.ok) { |
| 161 | + throw new Error(`Failed to fetch niches: ${response.statusText}`); |
| 162 | + } |
| 163 | + |
| 164 | + const data = await response.json(); |
| 165 | + return data.niches || []; |
| 166 | +} |
| 167 | + |
0 commit comments