import {z} from 'zod' export type UserFilter = {field: string, op: 'Eq' | 'NotEq' | 'In' | 'NotIn' | 'Lt' | 'Lte' | 'Gt' | 'Gte' | 'Glob' | 'NotGlob' | 'IGlob' | 'NotIGlob' | 'Regex' | 'Contains' | 'NotContains' | 'ContainsAny' | 'NotContainsAny' | 'AnyLt' | 'AnyLte' | 'AnyGt' | 'AnyGte' | 'ContainsAllTokens', value: string | number | boolean | Array | Array} | {op: 'And' | 'Or', filters: Array<{field: string, op: 'Eq' | 'NotEq' | 'In' | 'NotIn' | 'Lt' | 'Lte' | 'Gt' | 'Gte' | 'Glob' | 'NotGlob' | 'IGlob' | 'NotIGlob' | 'Regex' | 'Contains' | 'NotContains' | 'ContainsAny' | 'NotContainsAny' | 'AnyLt' | 'AnyLte' | 'AnyGt' | 'AnyGte' | 'ContainsAllTokens', value: string | number | boolean | Array | Array}>} | {op: 'And' | 'Or', filters: Array<{field: string, op: 'Eq' | 'NotEq' | 'In' | 'NotIn' | 'Lt' | 'Lte' | 'Gt' | 'Gte' | 'Glob' | 'NotGlob' | 'IGlob' | 'NotIGlob' | 'Regex' | 'Contains' | 'NotContains' | 'ContainsAny' | 'NotContainsAny' | 'AnyLt' | 'AnyLte' | 'AnyGt' | 'AnyGte' | 'ContainsAllTokens', value: string | number | boolean | Array | Array} | {op: 'And' | 'Or', filters: Array<{field: string, op: 'Eq' | 'NotEq' | 'In' | 'NotIn' | 'Lt' | 'Lte' | 'Gt' | 'Gte' | 'Glob' | 'NotGlob' | 'IGlob' | 'NotIGlob' | 'Regex' | 'Contains' | 'NotContains' | 'ContainsAny' | 'NotContainsAny' | 'AnyLt' | 'AnyLte' | 'AnyGt' | 'AnyGte' | 'ContainsAllTokens', value: string | number | boolean | Array | Array}>}>}; export type UserIncludeAttributes = {followers?: ({first: number, after?: string | undefined, filters?: UserFilter | undefined}) | undefined, following?: ({first: number, after?: string | undefined, filters?: UserFilter | undefined}) | undefined, stars?: ({first: number, after?: string | undefined, filters?: UserFilter | undefined}) | undefined, owns?: ({first: number, after?: string | undefined, filters?: UserFilter | undefined}) | undefined, contributes?: ({first: number, after?: string | undefined, filters?: UserFilter | undefined}) | undefined, devrank?: boolean | undefined, professional?: boolean | undefined, aggregates?: boolean | undefined, bestEmail?: boolean | undefined, revealEmails?: boolean | undefined}; export type V3GetUsersByIdRequest = {githubIds: Array, includeAttributes?: UserIncludeAttributes | undefined}; export type CreateApiRawUsersArgs = {body: V3GetUsersByIdRequest}; export type CreateApiRawUsersOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const professionalEducation = z.object({campus: z.string().nullable(), major: z.string().nullable(), specialization: z.string().nullable(), startDate: z.string().nullable(), endDate: z.string().nullable()}); export const professionalExperience = z.object({company: z.string().nullable(), title: z.string().nullable(), summary: z.string().nullable(), location: z.string().nullable(), industry: z.string().nullable(), startDate: z.string().nullable(), endDate: z.string().nullable(), startDateConfidence: z.string().nullable(), isCurrent: z.boolean().nullable()}); export const professionalProfile = z.object({firstName: z.string().nullable(), lastName: z.string().nullable(), linkedinUrl: z.string(), title: z.string().nullable(), headline: z.string().nullable(), organization: z.string().nullable(), currentIndustry: z.string().nullable(), city: z.string().nullable(), state: z.string().nullable(), country: z.string().nullable(), location: z.string().nullable(), seniorityLevel: z.string().nullable(), seniority: z.string().nullable(), functionalArea: z.string().nullable(), expertise: z.array(z.string()).nullable(), certifications: z.array(z.string()).nullable(), awards: z.array(z.string()).nullable(), memberships: z.array(z.string()).nullable(), departments: z.array(z.string()).nullable(), patents: z.array(z.string()).nullable(), publications: z.array(z.string()).nullable(), priorIndustries: z.array(z.string()).nullable(), languages: z.array(z.string()).nullable(), connectionsCount: z.number().nullable(), followerCount: z.number().nullable(), hiring: z.boolean().nullable(), openToWork: z.boolean().nullable(), education: z.array(professionalEducation), experience: z.array(professionalExperience)}); export const userAggregates = z.object({totalStars: z.number()}); export const publicUser = z.object({id: z.string(), githubId: z.string(), login: z.string(), displayName: z.string().nullable().optional(), bio: z.string().nullable().optional(), company: z.string().nullable().optional(), location: z.string().nullable().optional(), websiteUrl: z.string().nullable().optional(), socialAccounts: z.array(z.object({provider: z.string(), url: z.string()})).nullable().optional(), emails: z.array(z.string()).nullable().optional(), resolvedCountry: z.string().nullable().optional(), resolvedState: z.string().nullable().optional(), resolvedCity: z.string().nullable().optional(), createdAt: z.string().nullable().optional(), updatedAt: z.string().nullable().optional(), embeddedAt: z.string().nullable().optional(), score: z.number().optional()}); export const pageInfo = z.object({hasNextPage: z.boolean(), endCursor: z.string().nullable()}); export const paginatedUsers = z.object({edges: z.array(publicUser), pageInfo: pageInfo}); export const developerProfile = z.object({login: z.string(), userId: z.string().optional(), githubId: z.string().optional(), displayName: z.string().optional(), company: z.string().optional(), location: z.string().optional(), bio: z.string().optional(), accountCreatedAt: z.string().optional(), topRepos: z.array(z.object({name: z.string(), stargazerCount: z.number()})), devrank: z.object({tier: z.string(), crackedScore: z.number(), followersIn: z.number(), followingOut: z.number()}).optional(), linkedin: z.object({url: z.string().optional(), currentTitle: z.string().optional(), currentCompany: z.string().optional(), seniorityLevel: z.string().optional(), totalExperienceYears: z.number().optional(), connectionsCount: z.number().optional()}).optional()}); export const publicRepositoryWithGraph = z.object({id: z.string(), githubId: z.string(), ownerLogin: z.string(), name: z.string(), description: z.string().nullable().optional(), stargazerCount: z.number(), language: z.string().nullable().optional(), totalIssuesCount: z.number(), totalIssuesOpen: z.number(), totalIssuesClosed: z.number(), readmePreview: z.string().nullable().optional(), lastContributorLocations: z.array(z.string()).nullable().optional(), createdAt: z.string().nullable().optional(), updatedAt: z.string().nullable().optional(), embeddedAt: z.string().nullable().optional(), score: z.number().optional(), owner: z.object({id: z.string(), githubId: z.string(), login: z.string(), displayName: z.string().nullable().optional(), bio: z.string().nullable().optional(), company: z.string().nullable().optional(), location: z.string().nullable().optional(), websiteUrl: z.string().nullable().optional(), socialAccounts: z.array(z.object({provider: z.string(), url: z.string()})).nullable().optional(), emails: z.array(z.string()).nullable().optional(), resolvedCountry: z.string().nullable().optional(), resolvedState: z.string().nullable().optional(), resolvedCity: z.string().nullable().optional(), createdAt: z.string().nullable().optional(), updatedAt: z.string().nullable().optional(), embeddedAt: z.string().nullable().optional(), score: z.number().optional()}).optional(), contributors: z.object({edges: z.array(publicUser), pageInfo: pageInfo}).optional(), contributorProfiles: z.array(developerProfile).optional(), starrers: z.object({edges: z.array(publicUser), pageInfo: pageInfo}).optional(), ownerDevrank: z.object({crackedScore: z.number(), tier: z.string(), rawScore: z.number(), trust: z.number(), pc: z.number(), followersIn: z.number(), followingOut: z.number(), community: z.number().int(), createdAt: z.string(), updatedAt: z.string()}).optional(), ownerProfessional: z.object({firstName: z.string().nullable(), lastName: z.string().nullable(), linkedinUrl: z.string(), title: z.string().nullable(), headline: z.string().nullable(), organization: z.string().nullable(), currentIndustry: z.string().nullable(), city: z.string().nullable(), state: z.string().nullable(), country: z.string().nullable(), location: z.string().nullable(), seniorityLevel: z.string().nullable(), seniority: z.string().nullable(), functionalArea: z.string().nullable(), expertise: z.array(z.string()).nullable(), certifications: z.array(z.string()).nullable(), awards: z.array(z.string()).nullable(), memberships: z.array(z.string()).nullable(), departments: z.array(z.string()).nullable(), patents: z.array(z.string()).nullable(), publications: z.array(z.string()).nullable(), priorIndustries: z.array(z.string()).nullable(), languages: z.array(z.string()).nullable(), connectionsCount: z.number().nullable(), followerCount: z.number().nullable(), hiring: z.boolean().nullable(), openToWork: z.boolean().nullable(), education: z.array(professionalEducation), experience: z.array(professionalExperience)}).optional()}); export const paginatedRepositories = z.object({edges: z.array(publicRepositoryWithGraph), pageInfo: pageInfo}); export const publicUserWithGraph = z.object({id: z.string(), githubId: z.string(), login: z.string(), displayName: z.string().nullable().optional(), bio: z.string().nullable().optional(), company: z.string().nullable().optional(), location: z.string().nullable().optional(), websiteUrl: z.string().nullable().optional(), socialAccounts: z.array(z.object({provider: z.string(), url: z.string()})).nullable().optional(), emails: z.array(z.string()).nullable().optional(), resolvedCountry: z.string().nullable().optional(), resolvedState: z.string().nullable().optional(), resolvedCity: z.string().nullable().optional(), createdAt: z.string().nullable().optional(), updatedAt: z.string().nullable().optional(), embeddedAt: z.string().nullable().optional(), score: z.number().optional(), devrank: z.object({crackedScore: z.number(), tier: z.string(), rawScore: z.number(), trust: z.number(), pc: z.number(), followersIn: z.number(), followingOut: z.number(), community: z.number().int(), createdAt: z.string(), updatedAt: z.string()}).optional(), professional: professionalProfile.optional(), aggregates: userAggregates.optional(), followers: paginatedUsers.optional(), following: z.object({edges: z.array(publicUser), pageInfo: pageInfo}).optional(), stars: paginatedRepositories.optional(), owns: z.object({edges: z.array(publicRepositoryWithGraph), pageInfo: pageInfo}).optional(), contributes: z.object({edges: z.array(publicRepositoryWithGraph), pageInfo: pageInfo}).optional(), bestEmail: z.string().nullable().optional()}).nullable(); export const v3UsersResponse = z.object({users: z.array(publicUserWithGraph), count: z.number()}); 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 }; /** * Get users by ID (GitHub node IDs or BountyLab IDs) * * POST /raw/users */ export const createApiRawUsers = async (args: CreateApiRawUsersArgs, options?: CreateApiRawUsersOptions) => { const {baseUrl = "https://api.bountylab.io/v3", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/raw/users${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(v3UsersResponse, await res.json()) };