import {z} from 'zod' export type ImportGeo = {countryCode?: string | undefined, country?: string | undefined, city?: string | undefined}; export type ImportProfile = {profileId?: string | undefined, name?: string | undefined, nickname?: string | undefined, description?: string | undefined, url?: string | undefined, avatarUrl?: string | undefined, subscribers?: number | undefined, gender?: ('M' | 'F' | 'Community') | undefined, isVerified?: boolean | undefined, geo?: ImportGeo | undefined}; export type ImportEngagement = {likes?: number | undefined, comments?: number | undefined, shares?: number | undefined, views?: number | undefined, reactions?: number | undefined, reach?: number | undefined, impressions?: number | undefined, saves?: number | undefined}; export type ImportMention = {url: string, published: string, text?: string | undefined, title?: string | undefined, postId?: string | undefined, parentPostId?: string | undefined, discussionId?: string | undefined, originId?: string | undefined, source?: string | undefined, postType?: ('Post' | 'Comment' | 'Repost') | undefined, sourceType?: ('Social' | 'News' | 'Blog' | 'Forum' | 'Reviews') | undefined, contentTypes?: (Array<'Text' | 'Link' | 'Image' | 'Video' | 'Album' | 'Location' | 'Poll' | 'Subtitles' | 'Sticker'>) | undefined, tagIds?: Array | undefined, subcategoryIds?: Array | undefined, sourceSpecificFormat?: ('InstagramReels' | 'InstagramStories' | 'PinterestStoryPins' | 'YouTubeShorts' | 'FacebookReels' | 'FacebookStories' | 'TikTokPhoto' | 'TwitterNote' | 'YouTubeLive' | 'FacebookLive' | 'TwitchLive' | 'TwitterCommunityNote') | undefined, author?: ImportProfile | undefined, channel?: ImportProfile | undefined, engagement?: ImportEngagement | undefined, mentionGeo?: ImportGeo | undefined, imageUrl?: string | undefined, rating?: number | undefined, language?: string | undefined}; export type CreateApiTopicsTopicIdImportsArgs = {topicId: number, body: {name?: string | undefined, mentions: Array}}; export type CreateApiTopicsTopicIdImportsOptions = {baseUrl?: string | undefined, ApiKeyHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiTopicsTopicIdImportsResponse = z.object({importId: z.number().int().optional(), name: z.string().nullable().optional(), totalReceived: z.number().int().optional(), status: z.string().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 }; /** * Create import * * POST /topics/{topicId}/imports * * Also accepts auth: ApiKeyQuery */ export const createApiTopicsTopicIdImports = async (args: CreateApiTopicsTopicIdImportsArgs, options?: CreateApiTopicsTopicIdImportsOptions) => { const {baseUrl = "https://api.youscan.io/api/external", fetch: fetchFn = fetch, ApiKeyHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (ApiKeyHeader !== undefined) headers.set("X-API-KEY", ApiKeyHeader) const url = `${baseUrl.replace(/\/+$/, '')}/topics/${encodeURIComponent(String(args.topicId))}/imports${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(createApiTopicsTopicIdImportsResponse, await res.json()) };