import {z} from 'zod' export type GetApiDevrankLeaderboardArgs = {page?: string | undefined, limit?: string | undefined}; export type GetApiDevrankLeaderboardOptions = {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 publicUserWithDevrank = 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()}); export const leaderboardResponse = z.object({users: z.array(publicUserWithDevrank), page: z.number().int(), limit: 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 }; /** * Get devrank leaderboard with enriched user data * * GET /devrank/leaderboard */ export const getApiDevrankLeaderboard = async (args: GetApiDevrankLeaderboardArgs, options?: GetApiDevrankLeaderboardOptions) => { const {baseUrl = "https://api.bountylab.io/v3", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.page != null) query.append("page", String(args.page)) if (args.limit != null) query.append("limit", String(args.limit)) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/devrank/leaderboard${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(leaderboardResponse, await res.json()) };