import {z} from 'zod' export type GetHrisEmploymentsParameterCursor = string; export type GetHrisEmploymentsParameterPageSize = number; export type GetHrisEmploymentsParameterUpdatedAfter = string; export type GetHrisEmploymentsParameterIncludeDeleted = 'true' | 'false'; export type GetHrisEmploymentsParameterIgnoreUnsupportedFilters = 'true' | 'false'; export type GetHrisEmploymentsParameterIds = string; export type GetHrisEmploymentsParameterRemoteIds = string; export type GetApiHrisEmploymentsArgs = {'X-Integration-Id': string, cursor?: GetHrisEmploymentsParameterCursor | undefined, page_size?: GetHrisEmploymentsParameterPageSize | undefined, updated_after?: GetHrisEmploymentsParameterUpdatedAfter | undefined, include_deleted?: GetHrisEmploymentsParameterIncludeDeleted | undefined, ignore_unsupported_filters?: GetHrisEmploymentsParameterIgnoreUnsupportedFilters | undefined, ids?: GetHrisEmploymentsParameterIds | undefined, remote_ids?: GetHrisEmploymentsParameterRemoteIds | undefined}; export type GetApiHrisEmploymentsOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const getHrisEmploymentsPositiveResponse = z.object({status: z.literal("success"), data: z.object({next: z.string().nullable(), results: z.array(z.object({id: z.string(), remote_id: z.string().nullable(), employee_id: z.string(), job_title: z.string().nullable(), pay_rate: z.number().nullable(), pay_period: z.union([z.enum(["HOUR", "DAY", "WEEK", "TWO_WEEKS", "HALF_MONTH", "MONTH", "TWO_MONTHS", "QUARTER", "HALF_YEAR", "YEAR"]), z.string()]).nullable().optional(), pay_frequency: z.union([z.enum(["DAILY", "WEEKLY", "BIWEEKLY", "MONTHLY", "SEMIMONTHLY", "QUARTERLY", "SEMIANNUALLY", "ANNUALLY", "PRO_RATA"]), z.string()]).nullable().optional(), employment_type: z.union([z.enum(["FULL_TIME", "PART_TIME", "CONTRACT", "INTERNSHIP", "FREELANCE", "WORKING_STUDENT", "APPRENTICESHIP", "TRAINING"]), z.string()]).nullable().optional(), pay_currency: z.string().nullable(), effective_date: z.string().nullable(), changed_at: z.string(), remote_deleted_at: z.string().nullable(), remote_data: z.record(z.string(), z.unknown()).nullable(), custom_fields: z.record(z.string(), z.unknown()).nullable(), integration_fields: z.array(z.object({id: z.string(), key: z.string(), type: z.enum(["DEFAULT", "CUSTOM"]), value: z.unknown(), label: z.string().nullable()}))}))})}); 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 employments * * GET /hris/employments */ export const getApiHrisEmployments = async (args: GetApiHrisEmploymentsArgs, options?: GetApiHrisEmploymentsOptions) => { const {baseUrl = "https://api.kombo.dev/v1", fetch: fetchFn = fetch, ApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['X-Integration-Id'] != null) headers.set("X-Integration-Id", String(args['X-Integration-Id'])) if (args.cursor != null) query.append("cursor", String(args.cursor)) if (args.page_size != null) query.append("page_size", String(args.page_size)) if (args.updated_after != null) query.append("updated_after", String(args.updated_after)) if (args.include_deleted != null) query.append("include_deleted", String(args.include_deleted)) if (args.ignore_unsupported_filters != null) query.append("ignore_unsupported_filters", String(args.ignore_unsupported_filters)) if (args.ids != null) query.append("ids", String(args.ids)) if (args.remote_ids != null) query.append("remote_ids", String(args.remote_ids)) if (ApiKey !== undefined) headers.set('authorization', `Bearer ${ApiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/hris/employments${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(getHrisEmploymentsPositiveResponse, await res.json()) };