/* * 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 { GetV1EmployeesEmployeeIdOnboardingStatusRequest, GetV1EmployeesEmployeeIdOnboardingStatusRequest$outboundSchema, GetV1EmployeesEmployeeIdOnboardingStatusResponse, GetV1EmployeesEmployeeIdOnboardingStatusResponse$inboundSchema, } from "../models/operations/getv1employeesemployeeidonboardingstatus.js"; import { APICall, APIPromise } from "../types/async.js"; import { Result } from "../types/fp.js"; /** * Get the employee's onboarding status * * @remarks * # Description * Retrieves an employee's onboarding status. The data returned helps inform the required onboarding steps and respective completion status. * * ## onboarding_status * * ### Admin-facilitated onboarding * | onboarding_status | Description | * |:------------------|------------:| * | `admin_onboarding_incomplete` | Admin needs to complete the full employee-onboarding. | * | `onboarding_completed` | Employee has been fully onboarded and verified. | * * ### Employee self-onboarding * | onboarding_status | Description | * |:------------------|------------:| * | `admin_onboarding_incomplete` | Admin needs to enter basic information about the employee. | * | `self_onboarding_pending_invite` | Admin has the intention to invite the employee to self-onboard (e.g., marking a checkbox), but the system has not yet sent the invitation. | * | `self_onboarding_invited` | Employee has been sent an invitation to self-onboard. | * | `self_onboarding_invited_started` | Employee has started the self-onboarding process. | * | `self_onboarding_invited_overdue` | Employee's start date has passed, and employee has still not completed self-onboarding. | * | `self_onboarding_completed_by_employee` | Employee has completed entering in their information. The status should be updated via API to "self_onboarding_awaiting_admin_review" from here, once the Admin has started reviewing. | * | `self_onboarding_awaiting_admin_review` | Admin has started to verify the employee's information. | * | `onboarding_completed` | Employee has been fully onboarded and verified. | * * ## onboarding_steps * * | onboarding_steps | Requirement(s) to be completed | * |:-----------------|-------------------------------:| * | `personal_details` | Add employee's first name, last name, email, date of birth, social security number | * | `compensation_details` | Associate employee to a job & compensation. | * | `add_work_address` | Add employee work address. | * | `add_home_address` | Add employee home address. | * | `federal_tax_setup` | Set up federal tax withholdings. | * | `state_tax_setup` | Set up state tax withholdings. | * | `direct_deposit_setup` | (optional) Set up employee's direct deposit. | * | `employee_form_signing` | Employee forms (e.g., W4, direct deposit authorization) are generated & signed. | * | `file_new_hire_report` | File a new hire report for this employee. | * | `admin_review` | Admin reviews & confirms employee details (only required for Employee self-onboarding) | * * scope: `employees:read` * * If set, this operation will use {@link Security.companyAccessAuth} from the global security. */ export function employeesGetOnboardingStatus( client: GustoEmbeddedCore, request: GetV1EmployeesEmployeeIdOnboardingStatusRequest, options?: RequestOptions, ): APIPromise< Result< GetV1EmployeesEmployeeIdOnboardingStatusResponse, | NotFoundErrorObject | GustoEmbeddedError | ResponseValidationError | ConnectionError | RequestAbortedError | RequestTimeoutError | InvalidRequestError | UnexpectedClientError | SDKValidationError > > { return new APIPromise($do( client, request, options, )); } async function $do( client: GustoEmbeddedCore, request: GetV1EmployeesEmployeeIdOnboardingStatusRequest, options?: RequestOptions, ): Promise< [ Result< GetV1EmployeesEmployeeIdOnboardingStatusResponse, | NotFoundErrorObject | GustoEmbeddedError | ResponseValidationError | ConnectionError | RequestAbortedError | RequestTimeoutError | InvalidRequestError | UnexpectedClientError | SDKValidationError >, APICall, ] > { const parsed = safeParse( request, (value) => GetV1EmployeesEmployeeIdOnboardingStatusRequest$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}/onboarding_status")( 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-onboarding_status", 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< GetV1EmployeesEmployeeIdOnboardingStatusResponse, | NotFoundErrorObject | GustoEmbeddedError | ResponseValidationError | ConnectionError | RequestAbortedError | RequestTimeoutError | InvalidRequestError | UnexpectedClientError | SDKValidationError >( M.json( 200, GetV1EmployeesEmployeeIdOnboardingStatusResponse$inboundSchema, { key: "Employee-Onboarding-Status" }, ), 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 }]; }