/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import { GustoEmbeddedCore } from "../core.js"; import { encodeSimple } 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 { GustoEmbeddedError } from "../models/errors/gustoembeddederror.js"; import { ConnectionError, InvalidRequestError, RequestAbortedError, RequestTimeoutError, UnexpectedClientError, } from "../models/errors/httpclienterrors.js"; import { NotFoundErrorObject, NotFoundErrorObject$inboundSchema, } from "../models/errors/notfounderrorobject.js"; import { ResponseValidationError } from "../models/errors/responsevalidationerror.js"; import { SDKValidationError } from "../models/errors/sdkvalidationerror.js"; import { GetV1EmployeesEmployeeIdTerminationsRequest, GetV1EmployeesEmployeeIdTerminationsRequest$outboundSchema, GetV1EmployeesEmployeeIdTerminationsResponse, GetV1EmployeesEmployeeIdTerminationsResponse$inboundSchema, } from "../models/operations/getv1employeesemployeeidterminations.js"; import { APICall, APIPromise } from "../types/async.js"; import { Result } from "../types/fp.js"; /** * Get terminations for an employee * * @remarks * Terminations are created whenever an employee is scheduled to leave the company. The only things required are an effective date (their last day of work) and whether they should receive their wages in a one-off termination payroll or with the rest of the company. * * Note that some states require employees to receive their final wages within 24 hours (unless they consent otherwise,) in which case running a one-off payroll may be the only option. * * scope: `employments:read` * * If set, this operation will use {@link Security.companyAccessAuth} from the global security. */ export function employeeEmploymentsGetTerminations( client: GustoEmbeddedCore, request: GetV1EmployeesEmployeeIdTerminationsRequest, options?: RequestOptions, ): APIPromise< Result< GetV1EmployeesEmployeeIdTerminationsResponse, | NotFoundErrorObject | GustoEmbeddedError | ResponseValidationError | ConnectionError | RequestAbortedError | RequestTimeoutError | InvalidRequestError | UnexpectedClientError | SDKValidationError > > { return new APIPromise($do( client, request, options, )); } async function $do( client: GustoEmbeddedCore, request: GetV1EmployeesEmployeeIdTerminationsRequest, options?: RequestOptions, ): Promise< [ Result< GetV1EmployeesEmployeeIdTerminationsResponse, | NotFoundErrorObject | GustoEmbeddedError | ResponseValidationError | ConnectionError | RequestAbortedError | RequestTimeoutError | InvalidRequestError | UnexpectedClientError | SDKValidationError >, APICall, ] > { const parsed = safeParse( request, (value) => GetV1EmployeesEmployeeIdTerminationsRequest$outboundSchema.parse(value), "Input validation failed", ); if (!parsed.ok) { return [parsed, { status: "invalid" }]; } const payload = parsed.value; const body = null; const pathParams = { employee_id: encodeSimple("employee_id", payload.employee_id, { explode: false, charEncoding: "percent", }), }; const path = pathToFunc("/v1/employees/{employee_id}/terminations")( pathParams, ); const headers = new Headers(compactMap({ Accept: "application/json", "X-Gusto-API-Version": encodeSimple( "X-Gusto-API-Version", payload["X-Gusto-API-Version"], { explode: false, charEncoding: "none" }, ), })); const secConfig = await extractSecurity(client._options.companyAccessAuth); const securityInput = secConfig == null ? {} : { companyAccessAuth: secConfig }; const requestSecurity = resolveGlobalSecurity(securityInput, [0]); const context = { options: client._options, baseURL: options?.serverURL ?? client._baseURL ?? "", operationID: "get-v1-employees-employee_id-terminations", oAuth2Scopes: null, resolvedSecurity: requestSecurity, securitySource: client._options.companyAccessAuth, retryConfig: options?.retries || client._options.retryConfig || { strategy: "none" }, retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"], }; const requestRes = client._createRequest(context, { security: requestSecurity, method: "GET", baseURL: options?.serverURL, path: path, headers: headers, body: body, userAgent: client._options.userAgent, timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, }, options); if (!requestRes.ok) { return [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 [doResult, { status: "request-error", request: req }]; } const response = doResult.value; const responseFields = { HttpMeta: { Response: response, Request: req }, }; const [result] = await M.match< GetV1EmployeesEmployeeIdTerminationsResponse, | NotFoundErrorObject | GustoEmbeddedError | ResponseValidationError | ConnectionError | RequestAbortedError | RequestTimeoutError | InvalidRequestError | UnexpectedClientError | SDKValidationError >( M.json(200, GetV1EmployeesEmployeeIdTerminationsResponse$inboundSchema, { key: "Terminations", }), M.jsonErr(404, NotFoundErrorObject$inboundSchema), M.fail("4XX"), M.fail("5XX"), )(response, req, { extraFields: responseFields }); if (!result.ok) { return [result, { status: "complete", request: req, response }]; } return [result, { status: "complete", request: req, response }]; }