/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import { ApideckCore } from "../core.js"; import { encodeDeepObjectQuery, encodeFormQuery, encodeSimple, queryJoin, } from "../lib/encodings.js"; import { matchStatusCode } from "../lib/http.js"; import * as M from "../lib/matchers.js"; import { compactMap } from "../lib/primitives.js"; import { safeParse } from "../lib/schemas.js"; import { RequestOptions } from "../lib/sdks.js"; import { extractSecurity, resolveGlobalSecurity } from "../lib/security.js"; import { pathToFunc } from "../lib/url.js"; import { ApideckError } from "../models/errors/apideckerror.js"; import { ConnectionError, InvalidRequestError, RequestAbortedError, RequestTimeoutError, UnexpectedClientError, } from "../models/errors/httpclienterrors.js"; import * as errors from "../models/errors/index.js"; import { ResponseValidationError } from "../models/errors/responsevalidationerror.js"; import { SDKValidationError } from "../models/errors/sdkvalidationerror.js"; import * as operations from "../models/operations/index.js"; import { APICall, APIPromise } from "../types/async.js"; import { Result } from "../types/fp.js"; import { createPageIterator, haltIterator, PageIterator, Paginator, } from "../types/operations.js"; /** * List Employees * * @remarks * Apideck operates as a stateless Unified API, which means that the list endpoint only provides a portion of the employee model. This is due to the fact that most HRIS systems do not readily provide all data in every call. However, you can access the complete employee model through an employee detail call. */ export function hrisEmployeesList( client: ApideckCore, request: operations.HrisEmployeesAllRequest, options?: RequestOptions, ): APIPromise< PageIterator< Result< operations.HrisEmployeesAllResponse, | errors.BadRequestResponse | errors.UnauthorizedResponse | errors.PaymentRequiredResponse | errors.NotFoundResponse | errors.MethodNotAllowedResponse | errors.UnprocessableResponse | ApideckError | ResponseValidationError | ConnectionError | RequestAbortedError | RequestTimeoutError | InvalidRequestError | UnexpectedClientError | SDKValidationError >, { cursor: string } > > { return new APIPromise($do( client, request, options, )); } async function $do( client: ApideckCore, request: operations.HrisEmployeesAllRequest, options?: RequestOptions, ): Promise< [ PageIterator< Result< operations.HrisEmployeesAllResponse, | errors.BadRequestResponse | errors.UnauthorizedResponse | errors.PaymentRequiredResponse | errors.NotFoundResponse | errors.MethodNotAllowedResponse | errors.UnprocessableResponse | ApideckError | ResponseValidationError | ConnectionError | RequestAbortedError | RequestTimeoutError | InvalidRequestError | UnexpectedClientError | SDKValidationError >, { cursor: string } >, APICall, ] > { const parsed = safeParse( request, (value) => operations.HrisEmployeesAllRequest$outboundSchema.parse(value), "Input validation failed", ); if (!parsed.ok) { return [haltIterator(parsed), { status: "invalid" }]; } const payload = parsed.value; const body = null; const path = pathToFunc("/hris/employees")(); const query = queryJoin( encodeDeepObjectQuery({ "filter": payload.filter, "pass_through": payload.pass_through, "sort": payload.sort, }), encodeFormQuery({ "cursor": payload.cursor, "fields": payload.fields, "limit": payload.limit, "raw": payload.raw, }), ); const headers = new Headers(compactMap({ Accept: "application/json", "x-apideck-app-id": encodeSimple( "x-apideck-app-id", payload.appId ?? client._options.appId, { explode: false, charEncoding: "none" }, ), "x-apideck-consumer-id": encodeSimple( "x-apideck-consumer-id", payload.consumerId ?? client._options.consumerId, { explode: false, charEncoding: "none" }, ), "x-apideck-service-id": encodeSimple( "x-apideck-service-id", payload.serviceId, { explode: false, charEncoding: "none" }, ), })); const secConfig = await extractSecurity(client._options.apiKey); const securityInput = secConfig == null ? {} : { apiKey: secConfig }; const requestSecurity = resolveGlobalSecurity(securityInput); const context = { options: client._options, baseURL: options?.serverURL ?? client._baseURL ?? "", operationID: "hris.employeesAll", oAuth2Scopes: null, resolvedSecurity: requestSecurity, securitySource: client._options.apiKey, retryConfig: options?.retries || client._options.retryConfig || { strategy: "backoff", backoff: { initialInterval: 500, maxInterval: 60000, exponent: 1.5, maxElapsedTime: 900000, }, retryConnectionErrors: true, } || { strategy: "none" }, retryCodes: options?.retryCodes || ["408", "500", "502", "503", "504"], }; const requestRes = client._createRequest(context, { security: requestSecurity, method: "GET", baseURL: options?.serverURL, path: path, headers: headers, query: query, body: body, userAgent: client._options.userAgent, timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, }, options); if (!requestRes.ok) { return [haltIterator(requestRes), { status: "invalid" }]; } const req = requestRes.value; const doResult = await client._do(req, { context, isErrorStatusCode: (statusCode: number) => matchStatusCode({ status: statusCode } as Response, ["4XX", "5XX"]), retryConfig: context.retryConfig, retryCodes: context.retryCodes, }); if (!doResult.ok) { return [haltIterator(doResult), { status: "request-error", request: req }]; } const response = doResult.value; const responseFields = { HttpMeta: { Response: response, Request: req }, }; const [result, raw] = await M.match< operations.HrisEmployeesAllResponse, | errors.BadRequestResponse | errors.UnauthorizedResponse | errors.PaymentRequiredResponse | errors.NotFoundResponse | errors.MethodNotAllowedResponse | errors.UnprocessableResponse | ApideckError | ResponseValidationError | ConnectionError | RequestAbortedError | RequestTimeoutError | InvalidRequestError | UnexpectedClientError | SDKValidationError >( M.json(200, operations.HrisEmployeesAllResponse$inboundSchema, { hdrs: true, key: "GetEmployeesResponse", }), M.jsonErr(400, errors.BadRequestResponse$inboundSchema, { hdrs: true }), M.jsonErr(401, errors.UnauthorizedResponse$inboundSchema, { hdrs: true }), M.jsonErr(402, errors.PaymentRequiredResponse$inboundSchema, { hdrs: true, }), M.jsonErr(404, errors.NotFoundResponse$inboundSchema, { hdrs: true }), M.jsonErr(405, errors.MethodNotAllowedResponse$inboundSchema, { hdrs: true, }), M.jsonErr(422, errors.UnprocessableResponse$inboundSchema, { hdrs: true }), M.fail("4XX"), M.fail("5XX"), M.json("default", operations.HrisEmployeesAllResponse$inboundSchema, { hdrs: true, key: "UnexpectedErrorResponse", }), )(response, req, { extraFields: responseFields }); if (!result.ok) { return [haltIterator(result), { status: "complete", request: req, response, }]; } const nextFunc = ( responseData: unknown, ): { next: Paginator< Result< operations.HrisEmployeesAllResponse, | errors.BadRequestResponse | errors.UnauthorizedResponse | errors.PaymentRequiredResponse | errors.NotFoundResponse | errors.MethodNotAllowedResponse | errors.UnprocessableResponse | ApideckError | ResponseValidationError | ConnectionError | RequestAbortedError | RequestTimeoutError | InvalidRequestError | UnexpectedClientError | SDKValidationError > >; "~next"?: { cursor: string }; } => { const nextCursor = (responseData as | { meta?: { cursors?: { next?: unknown } } } | null | undefined)?.meta?.cursors?.next; if (typeof nextCursor !== "string") { return { next: () => null }; } if (nextCursor.trim() === "") { return { next: () => null }; } const nextVal = () => hrisEmployeesList( client, { ...request, cursor: nextCursor, }, options, ); return { next: nextVal, "~next": { cursor: nextCursor } }; }; const page = { ...result, ...nextFunc(raw) }; return [{ ...page, ...createPageIterator(page, (v) => !v.ok) }, { status: "complete", request: req, response, }]; }