/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import { MutationKey, useMutation, UseMutationResult, } from "@tanstack/react-query"; import { GustoEmbeddedCore } from "../core.js"; import { contractorsCreate } from "../funcs/contractorsCreate.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 { NotFoundErrorObject } from "../models/errors/notfounderrorobject.js"; import { ResponseValidationError } from "../models/errors/responsevalidationerror.js"; import { SDKValidationError } from "../models/errors/sdkvalidationerror.js"; import { UnprocessableEntityError } from "../models/errors/unprocessableentityerror.js"; import { PostV1CompaniesCompanyUuidContractorsRequest, PostV1CompaniesCompanyUuidContractorsResponse, } from "../models/operations/postv1companiescompanyuuidcontractors.js"; import { unwrapAsync } from "../types/fp.js"; import { useGustoEmbeddedContext } from "./_context.js"; import { MutationHookOptions } from "./_types.js"; export type ContractorsCreateMutationVariables = { request: PostV1CompaniesCompanyUuidContractorsRequest; options?: RequestOptions; }; export type ContractorsCreateMutationData = PostV1CompaniesCompanyUuidContractorsResponse; export type ContractorsCreateMutationError = | NotFoundErrorObject | UnprocessableEntityError | GustoEmbeddedError | ResponseValidationError | ConnectionError | RequestAbortedError | RequestTimeoutError | InvalidRequestError | UnexpectedClientError | SDKValidationError; /** * Create a contractor * * @remarks * Create an individual or business contractor. * * scope: `contractors:manage` */ export function useContractorsCreateMutation( options?: MutationHookOptions< ContractorsCreateMutationData, ContractorsCreateMutationError, ContractorsCreateMutationVariables >, ): UseMutationResult< ContractorsCreateMutationData, ContractorsCreateMutationError, ContractorsCreateMutationVariables > { const client = useGustoEmbeddedContext(); return useMutation({ ...buildContractorsCreateMutation(client, options), ...options, }); } export function mutationKeyContractorsCreate(): MutationKey { return ["@gusto/embedded-api", "Contractors", "create"]; } export function buildContractorsCreateMutation( client$: GustoEmbeddedCore, hookOptions?: RequestOptions, ): { mutationKey: MutationKey; mutationFn: ( variables: ContractorsCreateMutationVariables, ) => Promise; } { return { mutationKey: mutationKeyContractorsCreate(), mutationFn: function contractorsCreateMutationFn({ request, options, }): Promise { const mergedOptions = { ...hookOptions, ...options, fetchOptions: { ...hookOptions?.fetchOptions, ...options?.fetchOptions, signal: combineSignals( hookOptions?.fetchOptions?.signal, options?.fetchOptions?.signal, ), }, }; return unwrapAsync(contractorsCreate( client$, request, mergedOptions, )); }, }; }