import {z} from 'zod' export type GetHrisLocationsParameterCursor = string; export type GetHrisLocationsParameterPageSize = number; export type GetHrisLocationsParameterUpdatedAfter = string; export type GetHrisLocationsParameterIncludeDeleted = 'true' | 'false'; export type GetHrisLocationsParameterIgnoreUnsupportedFilters = 'true' | 'false'; export type GetHrisLocationsParameterIds = string; export type GetHrisLocationsParameterRemoteIds = string; export type GetHrisLocationsParameterNameContains = string; export type GetApiHrisLocationsArgs = {'X-Integration-Id': string, cursor?: GetHrisLocationsParameterCursor | undefined, page_size?: GetHrisLocationsParameterPageSize | undefined, updated_after?: GetHrisLocationsParameterUpdatedAfter | undefined, include_deleted?: GetHrisLocationsParameterIncludeDeleted | undefined, ignore_unsupported_filters?: GetHrisLocationsParameterIgnoreUnsupportedFilters | undefined, ids?: GetHrisLocationsParameterIds | undefined, remote_ids?: GetHrisLocationsParameterRemoteIds | undefined, name_contains?: GetHrisLocationsParameterNameContains | undefined}; export type GetApiHrisLocationsOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const getHrisLocationsPositiveResponse = 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(), name: z.string().nullable(), address: z.object({city: z.string().nullable().optional(), country: z.string().nullable().optional(), raw: z.string().nullable().optional(), state: z.string().nullable().optional(), street_1: z.string().nullable().optional(), street_2: z.string().nullable().optional(), zip_code: z.string().nullable().optional()}).nullable().optional(), type: 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 work locations * * GET /hris/locations */ export const getApiHrisLocations = async (args: GetApiHrisLocationsArgs, options?: GetApiHrisLocationsOptions) => { 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 (args.name_contains != null) query.append("name_contains", String(args.name_contains)) if (ApiKey !== undefined) headers.set('authorization', `Bearer ${ApiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/hris/locations${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(getHrisLocationsPositiveResponse, await res.json()) };