/* * 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 { resolveSecurity } 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 { GetV1PayrollBatchesPayrollBatchUuidRequest, GetV1PayrollBatchesPayrollBatchUuidRequest$outboundSchema, GetV1PayrollBatchesPayrollBatchUuidResponse, GetV1PayrollBatchesPayrollBatchUuidResponse$inboundSchema, GetV1PayrollBatchesPayrollBatchUuidSecurity, } from "../models/operations/getv1payrollbatchespayrollbatchuuid.js"; import { APICall, APIPromise } from "../types/async.js"; import { Result } from "../types/fp.js"; /** * Get a payroll cancellation batch * * @remarks * Returns the status and per-payroll results of a payroll cancellation batch. * * Poll this endpoint until the batch `status` reaches a terminal value (`completed` or `failed`). Once terminal, the response includes the `results` array (one entry per authorized payroll, each with its own per-payroll `status` — `success` or `failed`) and the `exclusions` array (one entry per payroll that could not be processed). A cancel is atomic, so a per-payroll result is only ever `success` or `failed` — never `partial_success`. * * Note that the top-level batch `status` (`pending` / `processing` / `completed` / `failed`) is the request lifecycle, distinct from the per-payroll `status` inside `results[]`. A `completed` batch does not imply every payroll was cancelled — inspect the array for per-payroll outcomes. * * Results are stored in Redis with a limited TTL after completion. If the partner polls after results have expired, this endpoint returns 410 Gone — partners should re-submit a new batch. * * 📘 System Access Authentication * * This endpoint uses the [Bearer Auth scheme with the system-level access token in the HTTP Authorization header](https://docs.gusto.com/embedded-payroll/docs/system-access) * * scope: `payroll_batches:read` */ export function payrollCancellationsGetV1PayrollBatchesPayrollBatchUuid( client: GustoEmbeddedCore, security: GetV1PayrollBatchesPayrollBatchUuidSecurity, request: GetV1PayrollBatchesPayrollBatchUuidRequest, options?: RequestOptions, ): APIPromise< Result< GetV1PayrollBatchesPayrollBatchUuidResponse, | NotFoundErrorObject | GustoEmbeddedError | ResponseValidationError | ConnectionError | RequestAbortedError | RequestTimeoutError | InvalidRequestError | UnexpectedClientError | SDKValidationError > > { return new APIPromise($do( client, security, request, options, )); } async function $do( client: GustoEmbeddedCore, security: GetV1PayrollBatchesPayrollBatchUuidSecurity, request: GetV1PayrollBatchesPayrollBatchUuidRequest, options?: RequestOptions, ): Promise< [ Result< GetV1PayrollBatchesPayrollBatchUuidResponse, | NotFoundErrorObject | GustoEmbeddedError | ResponseValidationError | ConnectionError | RequestAbortedError | RequestTimeoutError | InvalidRequestError | UnexpectedClientError | SDKValidationError >, APICall, ] > { const parsed = safeParse( request, (value) => GetV1PayrollBatchesPayrollBatchUuidRequest$outboundSchema.parse(value), "Input validation failed", ); if (!parsed.ok) { return [parsed, { status: "invalid" }]; } const payload = parsed.value; const body = null; const pathParams = { payroll_batch_uuid: encodeSimple( "payroll_batch_uuid", payload.payroll_batch_uuid, { explode: false, charEncoding: "percent" }, ), }; const path = pathToFunc("/v1/payroll_batches/{payroll_batch_uuid}")( 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 requestSecurity = resolveSecurity( [ { fieldName: "Authorization", type: "http:bearer", value: security?.systemAccessAuth, }, ], ); const context = { options: client._options, baseURL: options?.serverURL ?? client._baseURL ?? "", operationID: "get-v1-payroll_batches-payroll_batch_uuid", oAuth2Scopes: null, resolvedSecurity: requestSecurity, securitySource: security, 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< GetV1PayrollBatchesPayrollBatchUuidResponse, | NotFoundErrorObject | GustoEmbeddedError | ResponseValidationError | ConnectionError | RequestAbortedError | RequestTimeoutError | InvalidRequestError | UnexpectedClientError | SDKValidationError >( M.json(200, GetV1PayrollBatchesPayrollBatchUuidResponse$inboundSchema, { key: "Payroll-Batch-Results", }), M.jsonErr([404, 410], 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 }]; }