/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import { MutationKey, useMutation, UseMutationResult, } from "@tanstack/react-query"; import { GustoEmbeddedCore } from "../core.js"; import { payrollCancellationsPostV1PayrollBatches } from "../funcs/payrollCancellationsPostV1PayrollBatches.js"; import { combineSignals } from "../lib/primitives.js"; import { RequestOptions } from "../lib/sdks.js"; import { GustoEmbeddedError } from "../models/errors/gustoembeddederror.js"; import { ConnectionError, InvalidRequestError, RequestAbortedError, RequestTimeoutError, UnexpectedClientError, } from "../models/errors/httpclienterrors.js"; import { PayrollBatchConflictError } from "../models/errors/payrollbatchconflicterror.js"; import { ResponseValidationError } from "../models/errors/responsevalidationerror.js"; import { SDKValidationError } from "../models/errors/sdkvalidationerror.js"; import { UnprocessableEntityError } from "../models/errors/unprocessableentityerror.js"; import { PostV1PayrollBatchesRequest, PostV1PayrollBatchesResponse, PostV1PayrollBatchesSecurity, } from "../models/operations/postv1payrollbatches.js"; import { unwrapAsync } from "../types/fp.js"; import { useGustoEmbeddedContext } from "./_context.js"; import { MutationHookOptions } from "./_types.js"; export type PayrollCancellationsPostV1PayrollBatchesMutationVariables = { security: PostV1PayrollBatchesSecurity; request: PostV1PayrollBatchesRequest; options?: RequestOptions; }; export type PayrollCancellationsPostV1PayrollBatchesMutationData = PostV1PayrollBatchesResponse; export type PayrollCancellationsPostV1PayrollBatchesMutationError = | PayrollBatchConflictError | UnprocessableEntityError | GustoEmbeddedError | ResponseValidationError | ConnectionError | RequestAbortedError | RequestTimeoutError | InvalidRequestError | UnexpectedClientError | SDKValidationError; /** * Create a payroll cancellation batch * * @remarks * Cancels up to 100 payrolls across one or more companies the partner is mapped to, asynchronously. * * The batch is processed asynchronously. Use the returned batch UUID to poll `GET /v1/payroll_batches/{payroll_batch_uuid}` for status and per-payroll results. * * Each item carries the payroll `uuid` and the `company_uuid` that owns it. A payroll whose company is not mapped to the partner — or that doesn't exist — is recorded as a `not_found` exclusion rather than a hard error, so every requested UUID lands in either `results` or `exclusions`. * * Idempotency is scoped per `(partner, idempotency_key)`. A duplicate POST with the same `idempotency_key` returns a 409 Conflict referencing the existing batch UUID — no duplicate processing occurs. * * 📘 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:write` */ export function usePayrollCancellationsPostV1PayrollBatchesMutation( options?: MutationHookOptions< PayrollCancellationsPostV1PayrollBatchesMutationData, PayrollCancellationsPostV1PayrollBatchesMutationError, PayrollCancellationsPostV1PayrollBatchesMutationVariables >, ): UseMutationResult< PayrollCancellationsPostV1PayrollBatchesMutationData, PayrollCancellationsPostV1PayrollBatchesMutationError, PayrollCancellationsPostV1PayrollBatchesMutationVariables > { const client = useGustoEmbeddedContext(); return useMutation({ ...buildPayrollCancellationsPostV1PayrollBatchesMutation(client, options), ...options, }); } export function mutationKeyPayrollCancellationsPostV1PayrollBatches(): MutationKey { return [ "@gusto/embedded-api", "Payroll Cancellations", "postV1PayrollBatches", ]; } export function buildPayrollCancellationsPostV1PayrollBatchesMutation( client$: GustoEmbeddedCore, hookOptions?: RequestOptions, ): { mutationKey: MutationKey; mutationFn: ( variables: PayrollCancellationsPostV1PayrollBatchesMutationVariables, ) => Promise; } { return { mutationKey: mutationKeyPayrollCancellationsPostV1PayrollBatches(), mutationFn: function payrollCancellationsPostV1PayrollBatchesMutationFn({ security, request, options, }): Promise { const mergedOptions = { ...hookOptions, ...options, fetchOptions: { ...hookOptions?.fetchOptions, ...options?.fetchOptions, signal: combineSignals( hookOptions?.fetchOptions?.signal, options?.fetchOptions?.signal, ), }, }; return unwrapAsync(payrollCancellationsPostV1PayrollBatches( client$, security, request, mergedOptions, )); }, }; }