import {z} from 'zod' export type UpdateApiV1TrackerPersonListsListIdPeopleArgs = {listId: string, body: {apiKey: string, people: Array<{linkedinUrl?: (string | null) | undefined, linkedinUserId?: (string | null) | undefined, linkedinSlug?: (string | null) | undefined}>, initialSignals?: ({lookbackPeriodDays?: (number | null) | undefined} | null) | undefined}}; export type UpdateApiV1TrackerPersonListsListIdPeopleOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const updateApiV1TrackerPersonListsListIdPeopleResponse = z.object({output: z.object({added: z.number().int().gte(0), pending: z.number().int().gte(0), skipped: z.number().int().gte(0), invalidPeople: z.array(z.object({index: z.number().int().gte(0), reason: z.string()})), initialSignals: z.union([z.object({triggered: z.literal(true), peopleQueued: z.number().int().gte(0)}), z.object({triggered: z.literal(false)})]), nextRefreshAt: 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 }; /** * Add people to tracker list * * PUT /v1/tracker/person-lists/{listId}/people */ export const updateApiV1TrackerPersonListsListIdPeople = async (args: UpdateApiV1TrackerPersonListsListIdPeopleArgs, options?: UpdateApiV1TrackerPersonListsListIdPeopleOptions) => { 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/tracker/person-lists/${encodeURIComponent(String(args.listId))}/people${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(updateApiV1TrackerPersonListsListIdPeopleResponse, await res.json()) };