{"version":3,"sources":["../../../src/hooks/useDeleteChannelConnection.ts"],"sourcesContent":["import type { NovuError } from '@novu/js';\nimport { useCallback, useRef, useState } from 'react';\nimport { useNovu } from './NovuProvider';\n\nexport type UseDeleteChannelConnectionProps = {\n  onSuccess?: () => void;\n  onError?: (error: NovuError) => void;\n};\n\nexport type UseDeleteChannelConnectionResult = {\n  isDeleting: boolean;\n  error?: NovuError;\n  remove: (identifier: string) => Promise<{\n    data?: undefined;\n    error?: NovuError | undefined;\n  }>;\n};\n\n/**\n * Delete a channel connection by identifier. Works for both subscriber-owned and\n * shared (workspace-level) connections the current subscriber can access.\n */\nexport const useDeleteChannelConnection = (\n  props: UseDeleteChannelConnectionProps = {}\n): UseDeleteChannelConnectionResult => {\n  const propsRef = useRef<UseDeleteChannelConnectionProps>(props);\n  propsRef.current = props;\n  const novu = useNovu();\n  const [isDeleting, setIsDeleting] = useState(false);\n  const [error, setError] = useState<NovuError>();\n\n  const remove = useCallback(\n    async (identifier: string) => {\n      setError(undefined);\n      setIsDeleting(true);\n\n      try {\n        const response = await novu.channelConnections.delete({ identifier });\n\n        if (response.error) {\n          setError(response.error as NovuError);\n          propsRef.current.onError?.(response.error as NovuError);\n        } else {\n          propsRef.current.onSuccess?.();\n        }\n\n        return response as { data?: undefined; error?: NovuError };\n      } catch (err) {\n        const novuError = err as NovuError;\n        setError(novuError);\n        propsRef.current.onError?.(novuError);\n\n        return { error: novuError };\n      } finally {\n        setIsDeleting(false);\n      }\n    },\n    [novu]\n  );\n\n  return {\n    remove,\n    isDeleting,\n    error,\n  };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAA8C;AAC9C,0BAAwB;AAoBjB,IAAM,6BAA6B,CACxC,QAAyC,CAAC,MACL;AACrC,QAAM,eAAW,qBAAwC,KAAK;AAC9D,WAAS,UAAU;AACnB,QAAM,WAAO,6BAAQ;AACrB,QAAM,CAAC,YAAY,aAAa,QAAI,uBAAS,KAAK;AAClD,QAAM,CAAC,OAAO,QAAQ,QAAI,uBAAoB;AAE9C,QAAM,aAAS;AAAA,IACb,OAAO,eAAuB;AAhClC;AAiCM,eAAS,MAAS;AAClB,oBAAc,IAAI;AAElB,UAAI;AACF,cAAM,WAAW,MAAM,KAAK,mBAAmB,OAAO,EAAE,WAAW,CAAC;AAEpE,YAAI,SAAS,OAAO;AAClB,mBAAS,SAAS,KAAkB;AACpC,+BAAS,SAAQ,YAAjB,4BAA2B,SAAS;AAAA,QACtC,OAAO;AACL,+BAAS,SAAQ,cAAjB;AAAA,QACF;AAEA,eAAO;AAAA,MACT,SAAS,KAAK;AACZ,cAAM,YAAY;AAClB,iBAAS,SAAS;AAClB,6BAAS,SAAQ,YAAjB,4BAA2B;AAE3B,eAAO,EAAE,OAAO,UAAU;AAAA,MAC5B,UAAE;AACA,sBAAc,KAAK;AAAA,MACrB;AAAA,IACF;AAAA,IACA,CAAC,IAAI;AAAA,EACP;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":[]}