import {z} from 'zod' export type Query = {query: string}; export type TeamsFilter = {organization_ids: Array, query?: (Query | null) | undefined, since?: (string | null) | undefined}; export type TeamRelatedPeopleSelection = {attributes?: (Array<'name' | 'email' | 'phone' | 'linkedin_url' | 'job_title' | 'job_function' | 'job_level' | 'location' | 'country' | 'current_employer' | 'technologies' | 'person_score' | 'confidence'> | 'all') | undefined, max_per_team?: number | undefined}; export type JobPostsSelection = {components?: (Array<'job_details' | 'technologies' | 'job_functions' | 'job_level'> | 'all') | undefined, max_per_team?: number | undefined, since?: (string | null) | undefined}; export type TeamsSelect = {attributes?: (Array<'organization' | 'breadcrumbs' | 'jobs_count' | 'technology_list' | 'job_function_list' | 'location_list' | 'first_activity' | 'last_activity' | 'score'> | 'all') | undefined, related_people?: (TeamRelatedPeopleSelection | null) | undefined, job_posts?: (JobPostsSelection | null) | undefined}; export type FindTeamsRequest = {teams?: (Array | null) | undefined, filter?: (TeamsFilter | null) | undefined, select: TeamsSelect, limit?: number | undefined, offset?: number | undefined, order_by_column?: ('jobs_count' | 'first_activity' | 'last_activity' | 'score' | null) | undefined, order_by_direction?: ('ASC' | 'DESC' | null) | undefined}; export type CreateApiV9TeamsArgs = {body: FindTeamsRequest}; export type CreateApiV9TeamsOptions = {baseUrl?: string | undefined, apiToken?: string | undefined, fetch?: typeof fetch | undefined}; export const teamOrganization = z.object({organization_id: z.number().int(), name: z.string().nullable().optional(), sumble_url: z.string().min(1).max(2083).nullable().optional()}); export const teamBreadcrumb = z.object({team_id: z.number().int().nullable().optional(), name: z.string(), slug: z.string().nullable().optional(), sumble_url: z.string().min(1).max(2083).nullable().optional()}); export const teamTechnology = z.object({name: z.string(), slug: z.string(), used: z.boolean().optional(), jobs_count: z.number().int().nullable().optional()}); export const teamJobFunction = z.object({name: z.string(), slug: z.string(), jobs_count: z.number().int().nullable().optional()}); export const teamLocation = z.object({name: z.string(), jobs_count: z.number().int().nullable().optional()}); export const teamScoreComponent = z.object({name: z.string().nullable().optional(), slug: z.string().nullable().optional(), match_type: z.string(), contribution: z.number()}); export const teamScore = z.object({value: z.number(), fit: z.string().nullable().optional(), components: z.array(teamScoreComponent).optional()}); export const teamAttributes = z.object({organization: teamOrganization.nullable().optional(), breadcrumbs: z.array(teamBreadcrumb).nullable().optional(), jobs_count: z.number().int().nullable().optional(), technology_list: z.array(teamTechnology).nullable().optional(), job_function_list: z.array(teamJobFunction).nullable().optional(), location_list: z.array(teamLocation).nullable().optional(), first_activity: z.string().nullable().optional(), last_activity: z.string().nullable().optional(), score: teamScore.nullable().optional()}); export const teamMembershipFeature = z.object({match_type: z.enum(["team", "job_function", "technology", "location", "embedding"]), name: z.string().nullable().optional(), slug: z.string().nullable().optional(), is_parent: z.boolean().optional(), score: z.number()}); export const teamMembershipConfidence = z.object({score: z.number(), matched_features: z.array(teamMembershipFeature).optional()}); export const currentEmployer = z.object({organization_id: z.number().int(), name: z.string().nullable().optional(), start_date: z.string().nullable().optional(), sumble_url: z.string().min(1).max(2083).nullable().optional()}); export const personTechnology = z.object({name: z.string(), slug: z.string()}); export const personScoreFeature = z.object({name: z.string(), slug: z.string(), match_type: z.enum(["technology", "job_function"]), contribution: z.number()}); export const personScore = z.object({value: z.number(), skill_contribution: z.number(), job_function_contribution: z.number(), seniority_contribution: z.number(), matched_features: z.array(personScoreFeature)}); export const personAttributes = z.object({name: z.string().nullable().optional(), email: z.string().nullable().optional(), phone: z.string().nullable().optional(), linkedin_url: z.string().min(1).max(2083).nullable().optional(), job_title: z.string().nullable().optional(), job_function: z.string().nullable().optional(), job_level: z.string().nullable().optional(), location: z.string().nullable().optional(), country: z.string().nullable().optional(), current_employer: currentEmployer.nullable().optional(), technologies: z.array(personTechnology).nullable().optional(), person_score: personScore.nullable().optional()}); export const teamRelatedPersonRow = z.object({person_id: z.number().int(), sumble_url: z.string().min(1).max(2083), confidence: teamMembershipConfidence.nullable().optional(), attributes: personAttributes.nullable().optional()}); export const jobOrganization = z.object({organization_id: z.number().int(), name: z.string().nullable().optional(), domain: z.string().nullable().optional(), sumble_url: z.string().min(1).max(2083).nullable().optional()}); export const jobTechnology = z.object({name: z.string(), slug: z.string(), used: z.boolean(), sumble_url: z.string().min(1).max(2083).nullable().optional()}); export const jobTeam = z.object({team_id: z.number().int(), name: z.string(), slug: z.string(), sumble_url: z.string().min(1).max(2083).nullable().optional()}); export const appSchemasPaidApiJobsUnifiedJobFunction = z.object({name: z.string(), slug: z.string(), sumble_url: z.string().min(1).max(2083).nullable().optional()}); export const appSchemasPaidApiJobsUnifiedJobLevel = z.object({name: z.string()}); export const jobProject = z.object({name: z.string(), slug: z.string(), goal: z.string().nullable().optional(), sumble_url: z.string().min(1).max(2083).nullable().optional()}); export const jobAttributes = z.object({title: z.string().nullable().optional(), description: z.string().nullable().optional(), location: z.string().nullable().optional(), posted_date: z.string().nullable().optional(), organization: jobOrganization.nullable().optional(), technologies: z.array(jobTechnology).nullable().optional(), teams: z.array(jobTeam).nullable().optional(), job_functions: z.array(appSchemasPaidApiJobsUnifiedJobFunction).nullable().optional(), job_levels: z.array(appSchemasPaidApiJobsUnifiedJobLevel).nullable().optional(), projects: z.array(jobProject).nullable().optional()}); export const teamJobPostRow = z.object({job_id: z.number().int(), sumble_url: z.string().min(1).max(2083).nullable().optional(), attributes: jobAttributes.nullable().optional()}); export const teamResultRow = z.object({input: z.number().int().nullable().optional(), team_id: z.number().int().nullable().optional(), name: z.string().nullable().optional(), sumble_url: z.string().min(1).max(2083).nullable().optional(), attributes: teamAttributes.nullable().optional(), related_people: z.array(teamRelatedPersonRow).nullable().optional(), job_posts: z.array(teamJobPostRow).nullable().optional()}); export const findTeamsResponse = z.object({id: z.string(), credits_used: z.number().int(), credits_remaining: z.number().int(), teams: z.array(teamResultRow), matched_count: z.number().int().nullable().optional(), total: z.number().int(), source_data_url: z.string().min(1).max(2083).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 }; /** * Unified teams endpoint * * POST /v9/teams */ export const createApiV9Teams = async (args: CreateApiV9TeamsArgs, options?: CreateApiV9TeamsOptions) => { const {baseUrl = "https://api.sumble.com", fetch: fetchFn = fetch, apiToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (apiToken !== undefined) headers.set('authorization', `Bearer ${apiToken}`) const url = `${baseUrl.replace(/\/+$/, '')}/v9/teams${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(findTeamsResponse, await res.json()) };