import {z} from 'zod' export type GetApiV1CreatorsCreatorIdSocialAccountsArgs = {creator_id: string}; export type GetApiV1CreatorsCreatorIdSocialAccountsOptions = {baseUrl?: string | undefined, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const creatorSocialPlatform = z.enum(["tiktok", "youtube", "instagram", "threads", "x_twitter", "facebook", "reddit", "twitch", "kick", "other"]); export const syncStatus = z.enum(["pending", "ok", "error", "not_found"]); export const socialChannelRead = z.object({followers: z.number().int(), total_views: z.number().int(), total_content_count: z.number().int(), avg_views_per_video_in_window: z.number(), avg_views_per_video_window_days: z.number().int()}); export const socialContentItemRead = z.object({url: z.string(), title: z.string(), thumbnail_url: z.string(), published_at: z.string(), views: z.number().int(), likes: z.number().int(), comments: z.number().int(), is_short: z.boolean().optional()}); export const socialPerformanceMetricsRead = z.object({views: z.number().int(), likes: z.number().int(), comments: z.number().int()}); export const socialPerformanceSnapshotRead = z.object({content_url: z.string(), title: z.string(), thumbnail_url: z.string(), published_at: z.string(), taken_at: z.string(), window_days: z.number().int(), metrics: socialPerformanceMetricsRead}); export const creatorSocialAccountRead = z.object({platform: creatorSocialPlatform, handle: z.string(), sync_status: syncStatus, synced_at: z.number(), channel: socialChannelRead, content: z.array(socialContentItemRead), performance: z.array(socialPerformanceSnapshotRead)}); export const getApiV1CreatorsCreatorIdSocialAccountsResponse = z.array(creatorSocialAccountRead); 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 }; /** * Get Creator Social Accounts * * GET /v1/creators/{creator_id}/social-accounts */ export const getApiV1CreatorsCreatorIdSocialAccounts = async (args: GetApiV1CreatorsCreatorIdSocialAccountsArgs, options?: GetApiV1CreatorsCreatorIdSocialAccountsOptions) => { const {baseUrl = "https://api.aghanim.com/s2s", fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/creators/${encodeURIComponent(String(args.creator_id))}/social-accounts${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(getApiV1CreatorsCreatorIdSocialAccountsResponse, await res.json()) };