import {z} from 'zod' export type SourceTypeFilter = 'blog' | 'forum' | 'news' | 'social' | 'reviews' | 'messenger'; export type PostType = 'post' | 'repost' | 'extendedRepost' | 'comment'; export type GetApiTopicsTopicIdMentionsArgs = {topicId: number, from?: string | undefined, to?: string | undefined, addedFrom?: string | undefined, addedTo?: string | undefined, sinceSeq?: number | undefined, sentiment?: (Array<'positive' | 'neutral' | 'negative'>) | undefined, excludeSentiment?: (Array<'positive' | 'neutral' | 'negative'>) | undefined, engagementFrom?: number | undefined, engagementTo?: number | undefined, engagementCollectedFrom?: string | undefined, engagementCollectedTo?: string | undefined, sources?: Array | undefined, excludeSources?: Array | undefined, sourceTypes?: Array | undefined, excludeSourceTypes?: Array | undefined, postTypes?: Array | undefined, excludePostTypes?: Array | undefined, tags?: Array | undefined, excludeTags?: Array | undefined, autoCategories?: (Array<'wom' | 'commercial' | 'news' | 'recipe'>) | undefined, excludeAutoCategories?: (Array<'wom' | 'commercial' | 'news' | 'recipe'>) | undefined, starred?: boolean | undefined, tagged?: boolean | undefined, processed?: boolean | undefined, deleted?: boolean | undefined, spam?: boolean | undefined, textQuery?: string | undefined, dedup?: boolean | undefined, htmlSanitize?: boolean | undefined, timeZone?: string | undefined, size?: number | undefined, skip?: number | undefined, orderBy?: ('published' | 'publishedAsc' | 'seqAsc' | 'engagement') | undefined}; export type GetApiTopicsTopicIdMentionsOptions = {baseUrl?: string | undefined, ApiKeyHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const mentionProfile = z.object({profileId: z.string().nullable().optional(), url: z.string().nullable().optional(), name: z.string().nullable().optional(), nickname: z.string().nullable().optional(), bio: z.string().nullable().optional(), avatarUrl: z.string().nullable().optional(), subscribers: z.number().int().nullable().optional(), gender: z.enum(["unknown", "community", "male", "female"]).optional(), age: z.number().int().nullable().optional(), jobs: z.array(z.string()).nullable().optional(), interests: z.array(z.string()).nullable().optional(), interestCategories: z.array(z.string()).nullable().optional()}); export const sentiment = z.enum(["positive", "neutral", "negative", "undefined"]); export const postType = z.enum(["post", "repost", "extendedRepost", "comment"]); export const sourceSpecificFormat = z.enum(["instagramReels", "instagramStories", "pinterestStoryPins", "youTubeShorts", "facebookReels", "facebookStories", "tikTokPhoto", "twitterNote", "youTubeLive", "facebookLive", "twitchLive", "twitterCommunityNote"]); export const reactions = z.object({total: z.number().int().optional(), angry: z.number().int().nullable().optional(), haha: z.number().int().nullable().optional(), love: z.number().int().nullable().optional(), sad: z.number().int().nullable().optional(), wow: z.number().int().nullable().optional(), care: z.number().int().nullable().optional()}); export const mentionEngagement = z.object({likes: z.number().int().nullable().optional(), dislikes: z.number().int().nullable().optional(), comments: z.number().int().nullable().optional(), reposts: z.number().int().nullable().optional(), views: z.number().int().nullable().optional(), reach: z.number().int().nullable().optional(), saves: z.number().int().nullable().optional(), impressions: z.number().int().nullable().optional(), engagement: z.number().int().nullable().optional(), reactions: reactions.nullable().optional(), dateCollected: z.string().nullable().optional()}); export const subCategory = z.object({id: z.number().int().optional(), name: z.string().optional()}); export const category = z.object({id: z.number().int().optional(), name: z.string().optional(), subCategories: z.array(subCategory).optional()}); export const mentionSpeechContentSegment = z.object({text: z.string().optional(), startTime: z.number().int().optional(), endTime: z.number().int().optional(), hasMatches: z.boolean().optional()}); export const mentionSpeechContent = z.object({language: z.string().optional(), segments: z.array(mentionSpeechContentSegment).optional(), timecodeUrlTemplate: z.string().nullable().optional()}); export const mention = z.object({id: z.string().optional(), seq: z.number().int().optional(), published: z.string().optional(), addedAt: z.string().optional(), url: z.string().nullable().optional(), title: z.string().nullable().optional(), text: z.string().nullable().optional(), fullText: z.string().nullable().optional(), imageUrl: z.string().nullable().optional(), images: z.array(z.string()).nullable().optional(), source: z.string().optional(), author: mentionProfile.nullable().optional(), publicationPlace: mentionProfile.nullable().optional(), sentiment: sentiment.optional(), sourceType: z.enum(["social", "blog", "forum", "messenger", "news", "reviews", "other"]).optional(), resourceType: z.string().nullable().optional(), language: z.string().nullable().optional(), imageActivities: z.array(z.string()).nullable().optional(), imageBrands: z.array(z.string()).nullable().optional(), imageColors: z.array(z.string()).nullable().optional(), imageObjects: z.array(z.string()).nullable().optional(), imagePeople: z.array(z.string()).nullable().optional(), imageScenes: z.array(z.string()).nullable().optional(), imageTexts: z.array(z.string()).nullable().optional(), postType: postType.optional(), contentTypes: z.array(z.enum(["text", "link", "image", "video", "poll", "subtitles", "sticker"])).nullable().optional(), collectionMethods: z.array(z.enum(["text", "ocrText", "imageLogo", "imageFeature", "imageSimilarity", "audio", "channel", "manual", "filter", "import"])).nullable().optional(), sourceFormat: sourceSpecificFormat.nullable().optional(), tags: z.array(z.string()).optional(), rating: z.number().gte(0).lte(5).nullable().optional(), autoCategories: z.array(z.string()).nullable().optional(), subjects: z.array(z.string()).nullable().optional(), starred: z.boolean().optional(), processed: z.boolean().optional(), engagement: mentionEngagement.nullable().optional(), postId: z.string().nullable().optional(), parentPostId: z.string().nullable().optional(), discussionId: z.string().nullable().optional(), country: z.string().nullable().optional(), region: z.string().nullable().optional(), city: z.string().nullable().optional(), note: z.string().nullable().optional(), aspects: z.array(z.string()).nullable().optional(), sentimentAspects: z.array(z.object({aspect: z.string().optional(), sentiment: sentiment.optional()})).nullable().optional(), potentialReach: z.number().int().nullable().optional(), authorJobs: z.array(z.string()).nullable().optional(), authorInterests: z.array(z.string()).nullable().optional(), authorInterestCategories: z.array(z.string()).nullable().optional(), customTags: z.array(z.string()).nullable().optional(), categories: z.array(category).optional(), speechContent: mentionSpeechContent.optional()}); export const getApiTopicsTopicIdMentionsResponse = z.object({total: z.number().int().optional(), lastSeq: z.number().int().optional(), mentions: z.array(mention).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 }; /** * List mentions * * GET /topics/{topicId}/mentions * * Also accepts auth: ApiKeyQuery */ export const getApiTopicsTopicIdMentions = async (args: GetApiTopicsTopicIdMentionsArgs, options?: GetApiTopicsTopicIdMentionsOptions) => { const {baseUrl = "https://api.youscan.io/api/external", fetch: fetchFn = fetch, ApiKeyHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.from != null) query.append("from", String(args.from)) if (args.to != null) query.append("to", String(args.to)) if (args.addedFrom != null) query.append("addedFrom", String(args.addedFrom)) if (args.addedTo != null) query.append("addedTo", String(args.addedTo)) if (args.sinceSeq != null) query.append("sinceSeq", String(args.sinceSeq)) for (const item of args.sentiment ?? []) query.append("sentiment", String(item)) for (const item of args.excludeSentiment ?? []) query.append("excludeSentiment", String(item)) if (args.engagementFrom != null) query.append("engagementFrom", String(args.engagementFrom)) if (args.engagementTo != null) query.append("engagementTo", String(args.engagementTo)) if (args.engagementCollectedFrom != null) query.append("engagementCollectedFrom", String(args.engagementCollectedFrom)) if (args.engagementCollectedTo != null) query.append("engagementCollectedTo", String(args.engagementCollectedTo)) for (const item of args.sources ?? []) query.append("sources", String(item)) for (const item of args.excludeSources ?? []) query.append("excludeSources", String(item)) for (const item of args.sourceTypes ?? []) query.append("sourceTypes", String(item)) for (const item of args.excludeSourceTypes ?? []) query.append("excludeSourceTypes", String(item)) for (const item of args.postTypes ?? []) query.append("postTypes", String(item)) for (const item of args.excludePostTypes ?? []) query.append("excludePostTypes", String(item)) for (const item of args.tags ?? []) query.append("tags", String(item)) for (const item of args.excludeTags ?? []) query.append("excludeTags", String(item)) for (const item of args.autoCategories ?? []) query.append("autoCategories", String(item)) for (const item of args.excludeAutoCategories ?? []) query.append("excludeAutoCategories", String(item)) if (args.starred != null) query.append("starred", String(args.starred)) if (args.tagged != null) query.append("tagged", String(args.tagged)) if (args.processed != null) query.append("processed", String(args.processed)) if (args.deleted != null) query.append("deleted", String(args.deleted)) if (args.spam != null) query.append("spam", String(args.spam)) if (args.textQuery != null) query.append("textQuery", String(args.textQuery)) if (args.dedup != null) query.append("dedup", String(args.dedup)) if (args.htmlSanitize != null) query.append("htmlSanitize", String(args.htmlSanitize)) if (args.timeZone != null) query.append("timeZone", String(args.timeZone)) if (args.size != null) query.append("size", String(args.size)) if (args.skip != null) query.append("skip", String(args.skip)) if (args.orderBy != null) query.append("orderBy", String(args.orderBy)) if (ApiKeyHeader !== undefined) headers.set("X-API-KEY", ApiKeyHeader) const url = `${baseUrl.replace(/\/+$/, '')}/topics/${encodeURIComponent(String(args.topicId))}/mentions${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(getApiTopicsTopicIdMentionsResponse, await res.json()) };