import {z} from 'zod' export type Apiv2jobrolesaddskillsDataAttributesMeta = {'target-level'?: number | undefined, priority?: number | undefined}; export type Apiv2jobrolesaddskillsDataAttributesSkills = {type: string, id: string, meta?: Apiv2jobrolesaddskillsDataAttributesMeta | undefined}; export type Apiv2jobrolesaddskillsDataAttributes = {'role-id': string, skills?: Array | undefined}; export type Apiv2jobrolesaddskillsData = {type?: string | undefined, attributes?: Apiv2jobrolesaddskillsDataAttributes | undefined}; export type JobrolesAddskillsBody = {data?: Apiv2jobrolesaddskillsData | undefined}; export type CreateApiApiV2JobRolesAddSkillsArgs = {body: JobrolesAddskillsBody}; export type CreateApiApiV2JobRolesAddSkillsOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const apiv2jobrolesaddskillsDataAttributesMeta = z.object({"target-level": z.number().int().optional(), priority: z.number().int().optional()}); export const inlineResponse20027DataAttributesSkills = z.object({type: z.string().optional(), id: z.string().optional(), meta: apiv2jobrolesaddskillsDataAttributesMeta.optional()}); export const inlineResponse20027DataAttributes = z.object({"role-id": z.string().optional(), skills: z.array(inlineResponse20027DataAttributesSkills).optional()}); export const inlineResponse20027Data = z.object({type: z.string().optional(), id: z.string().nullable().optional(), attributes: inlineResponse20027DataAttributes.optional()}); export const inlineResponse20027 = z.object({data: inlineResponse20027Data.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 }; /** * Add a Skill to a Job Role * * POST /api/v2/job-roles/add-skills */ export const createApiApiV2JobRolesAddSkills = async (args: CreateApiApiV2JobRolesAddSkillsArgs, options?: CreateApiApiV2JobRolesAddSkillsOptions) => { const {baseUrl = "https://api.betatest.degreed.com", 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(/\/+$/, '')}/api/v2/job-roles/add-skills${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(inlineResponse20027, await res.json()) };