import {z} from 'zod' export type GetApiCustomerWatchlistProfilesArgs = {limit?: number | undefined, cursor?: string | undefined, entityType?: ('PERSON' | 'COMPANY') | undefined, profileType?: ('TEAMMATE' | 'COMPETITOR' | 'INFLUENCER' | 'INVESTOR' | 'CUSTOM' | 'TARGET_ACCOUNT' | 'CUSTOMER' | 'PARTNER') | undefined, profileTypes?: string | undefined, source?: ('MEMBER_ONBOARDING' | 'MANUAL_WATCHLIST') | undefined, slotKind?: ('SELF' | 'STANDARD' | 'COMPETITOR') | undefined, relationshipLabel?: string | undefined, state?: ('ACTIVE' | 'PAUSED') | undefined, query?: string | undefined, sort?: ('createdAt' | 'followers' | 'lastEngagementSyncAt' | 'displayName' | 'qualifiedLeads') | undefined, sortDirection?: ('asc' | 'desc') | undefined}; export type GetApiCustomerWatchlistProfilesOptions = {baseUrl?: string | undefined, CustomerApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiCustomerWatchlistProfilesResponse = z.object({data: z.array(z.record(z.string(), z.unknown())), page: z.object({limit: z.number().int(), cursor: z.string().nullable().optional(), nextCursor: z.string().nullable()}), total: z.number().int(), totalByEntityType: z.object({PERSON: z.number().int(), COMPANY: z.number().int()})}); 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 watchlist profiles. * * GET /customer/watchlist/profiles */ export const getApiCustomerWatchlistProfiles = async (args: GetApiCustomerWatchlistProfilesArgs, options?: GetApiCustomerWatchlistProfilesOptions) => { const {baseUrl = "https://api.traxy.ai/api/v1", fetch: fetchFn = fetch, CustomerApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.limit != null) query.append("limit", String(args.limit)) if (args.cursor != null) query.append("cursor", String(args.cursor)) if (args.entityType != null) query.append("entityType", String(args.entityType)) if (args.profileType != null) query.append("profileType", String(args.profileType)) if (args.profileTypes != null) query.append("profileTypes", String(args.profileTypes)) if (args.source != null) query.append("source", String(args.source)) if (args.slotKind != null) query.append("slotKind", String(args.slotKind)) if (args.relationshipLabel != null) query.append("relationshipLabel", String(args.relationshipLabel)) if (args.state != null) query.append("state", String(args.state)) if (args.query != null) query.append("query", String(args.query)) if (args.sort != null) query.append("sort", String(args.sort)) if (args.sortDirection != null) query.append("sortDirection", String(args.sortDirection)) if (CustomerApiKey !== undefined) headers.set('authorization', `Bearer ${CustomerApiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/customer/watchlist/profiles${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(getApiCustomerWatchlistProfilesResponse, await res.json()) };