/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import { MutationKey, useMutation, UseMutationResult, } from "@tanstack/react-query"; import { GustoEmbeddedCore } from "../core.js"; import { webhooksCreateSubscription } from "../funcs/webhooksCreateSubscription.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 { ResponseValidationError } from "../models/errors/responsevalidationerror.js"; import { SDKValidationError } from "../models/errors/sdkvalidationerror.js"; import { UnprocessableEntityError } from "../models/errors/unprocessableentityerror.js"; import { PostV1WebhookSubscriptionRequest, PostV1WebhookSubscriptionResponse, PostV1WebhookSubscriptionSecurity, } from "../models/operations/postv1webhooksubscription.js"; import { unwrapAsync } from "../types/fp.js"; import { useGustoEmbeddedContext } from "./_context.js"; import { MutationHookOptions } from "./_types.js"; export type WebhooksCreateSubscriptionMutationVariables = { security: PostV1WebhookSubscriptionSecurity; request: PostV1WebhookSubscriptionRequest; options?: RequestOptions; }; export type WebhooksCreateSubscriptionMutationData = PostV1WebhookSubscriptionResponse; export type WebhooksCreateSubscriptionMutationError = | UnprocessableEntityError | GustoEmbeddedError | ResponseValidationError | ConnectionError | RequestAbortedError | RequestTimeoutError | InvalidRequestError | UnexpectedClientError | SDKValidationError; /** * Create a webhook subscription * * @remarks * Create a webhook subscription to receive events of the specified subscription_types whenever there is a state change. * * 📘 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: `webhook_subscriptions:write` */ export function useWebhooksCreateSubscriptionMutation( options?: MutationHookOptions< WebhooksCreateSubscriptionMutationData, WebhooksCreateSubscriptionMutationError, WebhooksCreateSubscriptionMutationVariables >, ): UseMutationResult< WebhooksCreateSubscriptionMutationData, WebhooksCreateSubscriptionMutationError, WebhooksCreateSubscriptionMutationVariables > { const client = useGustoEmbeddedContext(); return useMutation({ ...buildWebhooksCreateSubscriptionMutation(client, options), ...options, }); } export function mutationKeyWebhooksCreateSubscription(): MutationKey { return ["@gusto/embedded-api", "Webhooks", "createSubscription"]; } export function buildWebhooksCreateSubscriptionMutation( client$: GustoEmbeddedCore, hookOptions?: RequestOptions, ): { mutationKey: MutationKey; mutationFn: ( variables: WebhooksCreateSubscriptionMutationVariables, ) => Promise; } { return { mutationKey: mutationKeyWebhooksCreateSubscription(), mutationFn: function webhooksCreateSubscriptionMutationFn({ security, request, options, }): Promise { const mergedOptions = { ...hookOptions, ...options, fetchOptions: { ...hookOptions?.fetchOptions, ...options?.fetchOptions, signal: combineSignals( hookOptions?.fetchOptions?.signal, options?.fetchOptions?.signal, ), }, }; return unwrapAsync(webhooksCreateSubscription( client$, security, request, mergedOptions, )); }, }; }