import {z} from 'zod' export type JobInput = {job_id: number}; export type Query = {query: string}; export type JobsFilter = {organization_ids?: (Array | null) | undefined, organization_list_id?: (number | null) | undefined, query?: (Query | null) | undefined}; export type JobRelatedPeopleSelection = {attributes?: (Array<'name' | 'email' | 'phone' | 'linkedin_url' | 'job_title' | 'job_function' | 'job_level' | 'location' | 'country' | 'current_employer' | 'technologies' | 'person_score' | 'confidence'> | 'all') | undefined, limit?: number | undefined, job_levels?: Array | undefined, job_functions?: Array | undefined, sort_order?: ('score' | 'level') | undefined, sort_direction?: ('desc' | 'asc') | undefined}; export type JobsSelect = {attributes?: (Array<'title' | 'description' | 'location' | 'posted_date' | 'organization' | 'technologies' | 'teams' | 'job_functions' | 'job_levels' | 'projects'> | 'all') | undefined, related_people?: (JobRelatedPeopleSelection | null) | undefined}; export type EnrichJobsRequest = {jobs?: (Array | null) | undefined, filter?: (JobsFilter | null) | undefined, select: JobsSelect, limit?: number | undefined, offset?: number | undefined}; export type CreateApiV9JobsArgs = {body: EnrichJobsRequest}; export type CreateApiV9JobsOptions = {baseUrl?: string | undefined, apiToken?: string | undefined, fetch?: typeof fetch | undefined}; export const jobInput = z.object({job_id: z.number().int().gte(1)}); 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 relatedPersonConfidenceFeature = z.object({match_type: z.enum(["technology", "job_function", "team", "location", "title_similarity"]), name: z.string(), slug: z.string().nullable().optional(), contribution: z.number()}); export const relatedPersonConfidence = z.object({score: z.number(), technology_contribution: z.number(), job_function_contribution: z.number(), team_contribution: z.number(), location_contribution: z.number(), title_similarity_contribution: z.number(), matched_features: z.array(relatedPersonConfidenceFeature)}); 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 relatedPersonRow = z.object({person_id: z.number().int(), sumble_url: z.string().min(1).max(2083), confidence: relatedPersonConfidence.nullable().optional(), attributes: personAttributes.nullable().optional()}); export const jobRow = z.object({input: jobInput.nullable().optional(), job_id: z.number().int().nullable().optional(), sumble_url: z.string().min(1).max(2083).nullable().optional(), attributes: jobAttributes.nullable().optional(), related_people: z.array(relatedPersonRow).nullable().optional()}); export const enrichJobsResponse = z.object({id: z.string(), credits_used: z.number().int(), credits_remaining: z.number().int(), jobs: z.array(jobRow), 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 jobs endpoint * * POST /v9/jobs */ export const createApiV9Jobs = async (args: CreateApiV9JobsArgs, options?: CreateApiV9JobsOptions) => { 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/jobs${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(enrichJobsResponse, await res.json()) };