/* * 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 { GetV1EmployeesEmployeeIdStateTaxesRequest, GetV1EmployeesEmployeeIdStateTaxesRequest$outboundSchema, GetV1EmployeesEmployeeIdStateTaxesResponse, GetV1EmployeesEmployeeIdStateTaxesResponse$inboundSchema, } from "../models/operations/getv1employeesemployeeidstatetaxes.js"; import { APICall, APIPromise } from "../types/async.js"; import { Result } from "../types/fp.js"; /** * Get an employee's state taxes * * @remarks * Get attributes relevant for an employee's state taxes. * * The data required to correctly calculate an employee's state taxes varies by both home and work location. This API returns information about each question that must be answered grouped by state. Mostly commonly, an employee lives and works in the same state and will only have questions for a single state. The response contains metadata about each question, the type of answer expected, and the current answer stored in Gusto for that question. * * Answers are represented by an array. Today, this array can only be empty or contain exactly one element, but is designed to allow for forward compatibility with effective-dated fields. The `valid_from` and `valid_up_to` fields are optional and currently ignored. * * ## About filing new hire reports * Payroll Admins are responsible for filing a new hire report for each Employee. The `file_new_hire_report` question will only be listed if: * - the `employee.onboarding_status` is one of the following: * - `admin_onboarding_incomplete` * - `self_onboarding_awaiting_admin_review` * - that employee's work state requires filing a new hire report * * scope: `employee_state_taxes:read` * * If set, this operation will use {@link Security.companyAccessAuth} from the global security. */ export function employeeTaxSetupGetStateTaxes( client: GustoEmbeddedCore, request: GetV1EmployeesEmployeeIdStateTaxesRequest, options?: RequestOptions, ): APIPromise< Result< GetV1EmployeesEmployeeIdStateTaxesResponse, | NotFoundErrorObject | GustoEmbeddedError | ResponseValidationError | ConnectionError | RequestAbortedError | RequestTimeoutError | InvalidRequestError | UnexpectedClientError | SDKValidationError > > { return new APIPromise($do( client, request, options, )); } async function $do( client: GustoEmbeddedCore, request: GetV1EmployeesEmployeeIdStateTaxesRequest, options?: RequestOptions, ): Promise< [ Result< GetV1EmployeesEmployeeIdStateTaxesResponse, | NotFoundErrorObject | GustoEmbeddedError | ResponseValidationError | ConnectionError | RequestAbortedError | RequestTimeoutError | InvalidRequestError | UnexpectedClientError | SDKValidationError >, APICall, ] > { const parsed = safeParse( request, (value) => GetV1EmployeesEmployeeIdStateTaxesRequest$outboundSchema.parse(value), "Input validation failed", ); if (!parsed.ok) { return [parsed, { status: "invalid" }]; } const payload = parsed.value; const body = null; const pathParams = { employee_uuid: encodeSimple("employee_uuid", payload.employee_uuid, { explode: false, charEncoding: "percent", }), }; const path = pathToFunc("/v1/employees/{employee_uuid}/state_taxes")( 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-state_taxes", 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< GetV1EmployeesEmployeeIdStateTaxesResponse, | NotFoundErrorObject | GustoEmbeddedError | ResponseValidationError | ConnectionError | RequestAbortedError | RequestTimeoutError | InvalidRequestError | UnexpectedClientError | SDKValidationError >( M.json(200, GetV1EmployeesEmployeeIdStateTaxesResponse$inboundSchema, { key: "Employee-State-Taxes-List", }), 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 }]; }