import {z} from 'zod' export type CreateApiV1LinkedinLiveFetchProfileReactionsArgs = {body: {apiKey: string, identifier: string, cursor?: (string | null) | undefined}}; export type CreateApiV1LinkedinLiveFetchProfileReactionsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiV1LinkedinLiveFetchProfileReactionsResponse = z.object({output: z.object({reactions: z.array(z.object({reactionId: z.string().nullable().optional(), type: z.enum(["LIKE", "LOVE", "INSIGHTFUL", "CELEBRATE", "SUPPORT", "FUNNY", "CURIOUS", "null"]).nullable().optional(), target: z.string().nullable().optional(), reactedAgo: z.string().nullable().optional(), reactedAt: z.string().nullable().optional(), reactor: z.object({linkedinUrl: z.string().nullable().optional(), profilePicture: z.string().nullable().optional(), linkedinSlug: z.string().nullable().optional(), entityUrn: z.string().nullable().optional(), linkedinId: z.number().nullable().optional()}).nullable().optional(), post: z.object({postUrn: z.string().nullable().optional(), postUrl: z.string().nullable().optional(), author: z.object({name: z.string().nullable().optional(), linkedinUrl: z.string().nullable().optional(), linkedinSlug: z.string().nullable().optional(), entityUrn: z.string().nullable().optional(), linkedinId: z.number().nullable().optional()}).nullable().optional(), content: z.string().nullable().optional()}).nullable().optional(), comment: z.object({content: z.string().nullable().optional(), author: z.object({name: z.string().nullable().optional(), linkedinUrl: z.string().nullable().optional(), linkedinSlug: z.string().nullable().optional(), entityUrn: z.string().nullable().optional(), linkedinId: z.number().nullable().optional()}).nullable().optional()}).nullable().optional()})).nullable().optional(), cursor: z.string().nullable().optional()}), 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 }; /** * Fetch LinkedIn profile reactions * * POST /v1/linkedin-live-fetch/profile-reactions */ export const createApiV1LinkedinLiveFetchProfileReactions = async (args: CreateApiV1LinkedinLiveFetchProfileReactionsArgs, options?: CreateApiV1LinkedinLiveFetchProfileReactionsOptions) => { 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/linkedin-live-fetch/profile-reactions${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(createApiV1LinkedinLiveFetchProfileReactionsResponse, await res.json()) };