@intlayer/design-system 5.6.0 → 5.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (394) hide show
  1. package/dist/.vite/manifest.json +88 -560
  2. package/dist/components/Command/index.d.ts +5 -5
  3. package/dist/components/ContentEditor/ContentEditorTextArea.cjs +2 -27
  4. package/dist/components/ContentEditor/ContentEditorTextArea.cjs.map +1 -1
  5. package/dist/components/ContentEditor/ContentEditorTextArea.d.ts +1 -1
  6. package/dist/components/ContentEditor/ContentEditorTextArea.d.ts.map +1 -1
  7. package/dist/components/ContentEditor/ContentEditorTextArea.mjs +1 -26
  8. package/dist/components/ContentEditor/ContentEditorTextArea.mjs.map +1 -1
  9. package/dist/components/DictionaryFieldEditor/ContentEditorView/TextEditor.cjs +2 -0
  10. package/dist/components/DictionaryFieldEditor/ContentEditorView/TextEditor.cjs.map +1 -1
  11. package/dist/components/DictionaryFieldEditor/ContentEditorView/TextEditor.mjs +2 -0
  12. package/dist/components/DictionaryFieldEditor/ContentEditorView/TextEditor.mjs.map +1 -1
  13. package/dist/components/DictionaryFieldEditor/DictionaryCreationForm/DictionaryCreationForm.cjs +9 -28
  14. package/dist/components/DictionaryFieldEditor/DictionaryCreationForm/DictionaryCreationForm.cjs.map +1 -1
  15. package/dist/components/DictionaryFieldEditor/DictionaryCreationForm/DictionaryCreationForm.mjs +8 -27
  16. package/dist/components/DictionaryFieldEditor/DictionaryCreationForm/DictionaryCreationForm.mjs.map +1 -1
  17. package/dist/components/DictionaryFieldEditor/DictionaryCreationForm/useDictionaryFormSchema.cjs +1 -1
  18. package/dist/components/DictionaryFieldEditor/DictionaryCreationForm/useDictionaryFormSchema.mjs +1 -1
  19. package/dist/components/DictionaryFieldEditor/DictionaryDetails/DictionaryDetailsForm.cjs +10 -26
  20. package/dist/components/DictionaryFieldEditor/DictionaryDetails/DictionaryDetailsForm.cjs.map +1 -1
  21. package/dist/components/DictionaryFieldEditor/DictionaryDetails/DictionaryDetailsForm.mjs +9 -25
  22. package/dist/components/DictionaryFieldEditor/DictionaryDetails/DictionaryDetailsForm.mjs.map +1 -1
  23. package/dist/components/DictionaryFieldEditor/DictionaryDetails/useDictionaryDetailsSchema.cjs +1 -1
  24. package/dist/components/DictionaryFieldEditor/DictionaryDetails/useDictionaryDetailsSchema.mjs +1 -1
  25. package/dist/components/DictionaryFieldEditor/DictionaryFieldEditor.cjs +2 -2
  26. package/dist/components/DictionaryFieldEditor/DictionaryFieldEditor.mjs +2 -2
  27. package/dist/components/DictionaryFieldEditor/SaveForm/SaveForm.cjs +7 -20
  28. package/dist/components/DictionaryFieldEditor/SaveForm/SaveForm.cjs.map +1 -1
  29. package/dist/components/DictionaryFieldEditor/SaveForm/SaveForm.mjs +6 -19
  30. package/dist/components/DictionaryFieldEditor/SaveForm/SaveForm.mjs.map +1 -1
  31. package/dist/components/DictionaryFieldEditor/StructureView/StructureView.cjs +2 -2
  32. package/dist/components/DictionaryFieldEditor/StructureView/StructureView.mjs +2 -2
  33. package/dist/components/DictionaryFieldEditor/VersionSwitcherDropDown/VersionSwitcherContext.cjs +2 -2
  34. package/dist/components/DictionaryFieldEditor/VersionSwitcherDropDown/VersionSwitcherContext.mjs +2 -2
  35. package/dist/components/EditableField/EditableFieldTextArea.cjs +2 -2
  36. package/dist/components/EditableField/EditableFieldTextArea.mjs +2 -2
  37. package/dist/components/Form/elements/FormElementWrapper.cjs +1 -1
  38. package/dist/components/Form/elements/FormElementWrapper.mjs +1 -1
  39. package/dist/components/IDE/CodeContext.cjs +2 -2
  40. package/dist/components/IDE/CodeContext.mjs +2 -2
  41. package/dist/components/LocaleSwitcherContentDropDown/LocaleSwitcherContent.cjs +2 -2
  42. package/dist/components/LocaleSwitcherContentDropDown/LocaleSwitcherContent.mjs +2 -2
  43. package/dist/components/LocaleSwitcherContentDropDown/LocaleSwitcherContentContext.cjs +2 -2
  44. package/dist/components/LocaleSwitcherContentDropDown/LocaleSwitcherContentContext.mjs +2 -2
  45. package/dist/components/Modal/Modal.cjs +3 -3
  46. package/dist/components/Modal/Modal.mjs +3 -3
  47. package/dist/components/Navbar/MobileNavbar.cjs +2 -2
  48. package/dist/components/Navbar/MobileNavbar.mjs +2 -2
  49. package/dist/components/Navbar/index.cjs +3 -3
  50. package/dist/components/Navbar/index.mjs +3 -3
  51. package/dist/components/Pattern/GridPattern.cjs +45 -48
  52. package/dist/components/Pattern/GridPattern.cjs.map +1 -1
  53. package/dist/components/Pattern/GridPattern.d.ts.map +1 -1
  54. package/dist/components/Pattern/GridPattern.mjs +45 -48
  55. package/dist/components/Pattern/GridPattern.mjs.map +1 -1
  56. package/dist/components/SwitchSelector/index.cjs +2 -2
  57. package/dist/components/SwitchSelector/index.mjs +2 -2
  58. package/dist/components/TabSelector/TabSelector.cjs +2 -2
  59. package/dist/components/TabSelector/TabSelector.mjs +2 -2
  60. package/dist/components/TextArea/AutocompleteTextArea.cjs +90 -13
  61. package/dist/components/TextArea/AutocompleteTextArea.cjs.map +1 -1
  62. package/dist/components/TextArea/AutocompleteTextArea.d.ts.map +1 -1
  63. package/dist/components/TextArea/AutocompleteTextArea.mjs +92 -15
  64. package/dist/components/TextArea/AutocompleteTextArea.mjs.map +1 -1
  65. package/dist/components/index.cjs +0 -38
  66. package/dist/components/index.cjs.map +1 -1
  67. package/dist/components/index.d.ts +0 -2
  68. package/dist/components/index.d.ts.map +1 -1
  69. package/dist/components/index.mjs +0 -38
  70. package/dist/components/index.mjs.map +1 -1
  71. package/dist/hooks/index.cjs +8 -1
  72. package/dist/hooks/index.cjs.map +1 -1
  73. package/dist/hooks/index.d.ts +2 -0
  74. package/dist/hooks/index.d.ts.map +1 -1
  75. package/dist/hooks/index.mjs +9 -2
  76. package/dist/hooks/index.mjs.map +1 -1
  77. package/dist/hooks/intlayerAPIHooks.cjs +29 -31
  78. package/dist/hooks/intlayerAPIHooks.cjs.map +1 -1
  79. package/dist/hooks/intlayerAPIHooks.d.ts +678 -10
  80. package/dist/hooks/intlayerAPIHooks.d.ts.map +1 -1
  81. package/dist/hooks/intlayerAPIHooks.mjs +29 -31
  82. package/dist/hooks/intlayerAPIHooks.mjs.map +1 -1
  83. package/dist/hooks/useAsync/useAsync.cjs +0 -1
  84. package/dist/hooks/useAsync/useAsync.cjs.map +1 -1
  85. package/dist/hooks/useAsync/useAsync.d.ts.map +1 -1
  86. package/dist/hooks/useAsync/useAsync.mjs +0 -1
  87. package/dist/hooks/useAsync/useAsync.mjs.map +1 -1
  88. package/dist/hooks/useAuth/index.cjs +9 -0
  89. package/dist/{components/Auth/AuthenticationBarrier → hooks/useAuth}/index.cjs.map +1 -1
  90. package/dist/hooks/useAuth/index.d.ts +4 -0
  91. package/dist/hooks/useAuth/index.d.ts.map +1 -0
  92. package/dist/hooks/useAuth/index.mjs +9 -0
  93. package/dist/{components/Auth/ExternalsLoginButtons → hooks/useAuth}/index.mjs.map +1 -1
  94. package/dist/hooks/useAuth/useAuth.cjs +25 -0
  95. package/dist/hooks/useAuth/useAuth.cjs.map +1 -0
  96. package/dist/{components/Auth/useAuth/index.d.ts → hooks/useAuth/useAuth.d.ts} +3 -13
  97. package/dist/hooks/useAuth/useAuth.d.ts.map +1 -0
  98. package/dist/{components/Auth/useAuth/index.mjs → hooks/useAuth/useAuth.mjs} +2 -8
  99. package/dist/hooks/useAuth/useAuth.mjs.map +1 -0
  100. package/dist/{components/Auth → hooks}/useAuth/useOAuth2.cjs +3 -3
  101. package/dist/hooks/useAuth/useOAuth2.cjs.map +1 -0
  102. package/dist/{components/Auth → hooks}/useAuth/useOAuth2.d.ts +1 -1
  103. package/dist/hooks/useAuth/useOAuth2.d.ts.map +1 -0
  104. package/dist/{components/Auth → hooks}/useAuth/useOAuth2.mjs +4 -4
  105. package/dist/hooks/useAuth/useOAuth2.mjs.map +1 -0
  106. package/dist/{components/Auth → hooks}/useAuth/useSession.cjs +6 -25
  107. package/dist/hooks/useAuth/useSession.cjs.map +1 -0
  108. package/dist/{components/Auth → hooks}/useAuth/useSession.d.ts +3 -3
  109. package/dist/hooks/useAuth/useSession.d.ts.map +1 -0
  110. package/dist/hooks/useAuth/useSession.mjs +47 -0
  111. package/dist/hooks/useAuth/useSession.mjs.map +1 -0
  112. package/dist/hooks/useIntlayerAPI.cjs +5 -4
  113. package/dist/hooks/useIntlayerAPI.cjs.map +1 -1
  114. package/dist/hooks/useIntlayerAPI.mjs +5 -4
  115. package/dist/hooks/useIntlayerAPI.mjs.map +1 -1
  116. package/dist/{components/Auth → hooks}/useUser/index.cjs +7 -5
  117. package/dist/hooks/useUser/index.cjs.map +1 -0
  118. package/dist/hooks/useUser/index.d.ts +8 -0
  119. package/dist/hooks/useUser/index.d.ts.map +1 -0
  120. package/dist/{components/Auth → hooks}/useUser/index.mjs +6 -4
  121. package/dist/hooks/useUser/index.mjs.map +1 -0
  122. package/dist/{schemas-itjzX6bG.js → schemas-BIuxHDyZ.js} +3 -7
  123. package/dist/{schemas-itjzX6bG.js.map → schemas-BIuxHDyZ.js.map} +1 -1
  124. package/dist/{schemas-DlCjM5d_.cjs → schemas-Q6C7ZNs3.cjs} +3 -7
  125. package/dist/{schemas-DlCjM5d_.cjs.map → schemas-Q6C7ZNs3.cjs.map} +1 -1
  126. package/dist/tailwind.css +1 -1
  127. package/package.json +17 -17
  128. package/dist/components/Auth/AuthModal/index.cjs +0 -106
  129. package/dist/components/Auth/AuthModal/index.cjs.map +0 -1
  130. package/dist/components/Auth/AuthModal/index.d.ts +0 -20
  131. package/dist/components/Auth/AuthModal/index.d.ts.map +0 -1
  132. package/dist/components/Auth/AuthModal/index.mjs +0 -106
  133. package/dist/components/Auth/AuthModal/index.mjs.map +0 -1
  134. package/dist/components/Auth/AuthenticationBarrier/AuthenticationBarrierClient.cjs +0 -36
  135. package/dist/components/Auth/AuthenticationBarrier/AuthenticationBarrierClient.cjs.map +0 -1
  136. package/dist/components/Auth/AuthenticationBarrier/AuthenticationBarrierClient.d.ts +0 -5
  137. package/dist/components/Auth/AuthenticationBarrier/AuthenticationBarrierClient.d.ts.map +0 -1
  138. package/dist/components/Auth/AuthenticationBarrier/AuthenticationBarrierClient.mjs +0 -36
  139. package/dist/components/Auth/AuthenticationBarrier/AuthenticationBarrierClient.mjs.map +0 -1
  140. package/dist/components/Auth/AuthenticationBarrier/AuthenticationBarrierServer.cjs +0 -22
  141. package/dist/components/Auth/AuthenticationBarrier/AuthenticationBarrierServer.cjs.map +0 -1
  142. package/dist/components/Auth/AuthenticationBarrier/AuthenticationBarrierServer.d.ts +0 -8
  143. package/dist/components/Auth/AuthenticationBarrier/AuthenticationBarrierServer.d.ts.map +0 -1
  144. package/dist/components/Auth/AuthenticationBarrier/AuthenticationBarrierServer.mjs +0 -22
  145. package/dist/components/Auth/AuthenticationBarrier/AuthenticationBarrierServer.mjs.map +0 -1
  146. package/dist/components/Auth/AuthenticationBarrier/accessValidation.cjs +0 -15
  147. package/dist/components/Auth/AuthenticationBarrier/accessValidation.cjs.map +0 -1
  148. package/dist/components/Auth/AuthenticationBarrier/accessValidation.d.ts +0 -4
  149. package/dist/components/Auth/AuthenticationBarrier/accessValidation.d.ts.map +0 -1
  150. package/dist/components/Auth/AuthenticationBarrier/accessValidation.mjs +0 -15
  151. package/dist/components/Auth/AuthenticationBarrier/accessValidation.mjs.map +0 -1
  152. package/dist/components/Auth/AuthenticationBarrier/index.cjs +0 -7
  153. package/dist/components/Auth/AuthenticationBarrier/index.d.ts +0 -23
  154. package/dist/components/Auth/AuthenticationBarrier/index.d.ts.map +0 -1
  155. package/dist/components/Auth/AuthenticationBarrier/index.mjs +0 -7
  156. package/dist/components/Auth/AuthenticationBarrier/index.mjs.map +0 -1
  157. package/dist/components/Auth/ChangePasswordForm/ChangePasswordForm.cjs +0 -95
  158. package/dist/components/Auth/ChangePasswordForm/ChangePasswordForm.cjs.map +0 -1
  159. package/dist/components/Auth/ChangePasswordForm/ChangePasswordForm.d.ts +0 -9
  160. package/dist/components/Auth/ChangePasswordForm/ChangePasswordForm.d.ts.map +0 -1
  161. package/dist/components/Auth/ChangePasswordForm/ChangePasswordForm.mjs +0 -95
  162. package/dist/components/Auth/ChangePasswordForm/ChangePasswordForm.mjs.map +0 -1
  163. package/dist/components/Auth/ChangePasswordForm/changePasswordForm.content.cjs +0 -138
  164. package/dist/components/Auth/ChangePasswordForm/changePasswordForm.content.cjs.map +0 -1
  165. package/dist/components/Auth/ChangePasswordForm/changePasswordForm.content.d.ts +0 -278
  166. package/dist/components/Auth/ChangePasswordForm/changePasswordForm.content.d.ts.map +0 -1
  167. package/dist/components/Auth/ChangePasswordForm/changePasswordForm.content.mjs +0 -138
  168. package/dist/components/Auth/ChangePasswordForm/changePasswordForm.content.mjs.map +0 -1
  169. package/dist/components/Auth/ChangePasswordForm/index.cjs +0 -7
  170. package/dist/components/Auth/ChangePasswordForm/index.cjs.map +0 -1
  171. package/dist/components/Auth/ChangePasswordForm/index.d.ts +0 -3
  172. package/dist/components/Auth/ChangePasswordForm/index.d.ts.map +0 -1
  173. package/dist/components/Auth/ChangePasswordForm/index.mjs +0 -7
  174. package/dist/components/Auth/ChangePasswordForm/index.mjs.map +0 -1
  175. package/dist/components/Auth/ChangePasswordForm/useChangePasswordSchema.cjs +0 -34
  176. package/dist/components/Auth/ChangePasswordForm/useChangePasswordSchema.cjs.map +0 -1
  177. package/dist/components/Auth/ChangePasswordForm/useChangePasswordSchema.content.cjs +0 -131
  178. package/dist/components/Auth/ChangePasswordForm/useChangePasswordSchema.content.cjs.map +0 -1
  179. package/dist/components/Auth/ChangePasswordForm/useChangePasswordSchema.content.d.ts +0 -271
  180. package/dist/components/Auth/ChangePasswordForm/useChangePasswordSchema.content.d.ts.map +0 -1
  181. package/dist/components/Auth/ChangePasswordForm/useChangePasswordSchema.content.mjs +0 -131
  182. package/dist/components/Auth/ChangePasswordForm/useChangePasswordSchema.content.mjs.map +0 -1
  183. package/dist/components/Auth/ChangePasswordForm/useChangePasswordSchema.d.ts +0 -8
  184. package/dist/components/Auth/ChangePasswordForm/useChangePasswordSchema.d.ts.map +0 -1
  185. package/dist/components/Auth/ChangePasswordForm/useChangePasswordSchema.mjs +0 -34
  186. package/dist/components/Auth/ChangePasswordForm/useChangePasswordSchema.mjs.map +0 -1
  187. package/dist/components/Auth/DefineNewPasswordForm/DefineNewPasswordForm.cjs +0 -81
  188. package/dist/components/Auth/DefineNewPasswordForm/DefineNewPasswordForm.cjs.map +0 -1
  189. package/dist/components/Auth/DefineNewPasswordForm/DefineNewPasswordForm.d.ts +0 -9
  190. package/dist/components/Auth/DefineNewPasswordForm/DefineNewPasswordForm.d.ts.map +0 -1
  191. package/dist/components/Auth/DefineNewPasswordForm/DefineNewPasswordForm.mjs +0 -81
  192. package/dist/components/Auth/DefineNewPasswordForm/DefineNewPasswordForm.mjs.map +0 -1
  193. package/dist/components/Auth/DefineNewPasswordForm/defineNewPasswordForm.content.cjs +0 -106
  194. package/dist/components/Auth/DefineNewPasswordForm/defineNewPasswordForm.content.cjs.map +0 -1
  195. package/dist/components/Auth/DefineNewPasswordForm/defineNewPasswordForm.content.d.ts +0 -210
  196. package/dist/components/Auth/DefineNewPasswordForm/defineNewPasswordForm.content.d.ts.map +0 -1
  197. package/dist/components/Auth/DefineNewPasswordForm/defineNewPasswordForm.content.mjs +0 -106
  198. package/dist/components/Auth/DefineNewPasswordForm/defineNewPasswordForm.content.mjs.map +0 -1
  199. package/dist/components/Auth/DefineNewPasswordForm/index.cjs +0 -7
  200. package/dist/components/Auth/DefineNewPasswordForm/index.cjs.map +0 -1
  201. package/dist/components/Auth/DefineNewPasswordForm/index.d.ts +0 -3
  202. package/dist/components/Auth/DefineNewPasswordForm/index.d.ts.map +0 -1
  203. package/dist/components/Auth/DefineNewPasswordForm/index.mjs +0 -7
  204. package/dist/components/Auth/DefineNewPasswordForm/index.mjs.map +0 -1
  205. package/dist/components/Auth/DefineNewPasswordForm/useDefineNewPasswordSchema.cjs +0 -29
  206. package/dist/components/Auth/DefineNewPasswordForm/useDefineNewPasswordSchema.cjs.map +0 -1
  207. package/dist/components/Auth/DefineNewPasswordForm/useDefineNewPasswordSchema.content.cjs +0 -101
  208. package/dist/components/Auth/DefineNewPasswordForm/useDefineNewPasswordSchema.content.cjs.map +0 -1
  209. package/dist/components/Auth/DefineNewPasswordForm/useDefineNewPasswordSchema.content.d.ts +0 -205
  210. package/dist/components/Auth/DefineNewPasswordForm/useDefineNewPasswordSchema.content.d.ts.map +0 -1
  211. package/dist/components/Auth/DefineNewPasswordForm/useDefineNewPasswordSchema.content.mjs +0 -101
  212. package/dist/components/Auth/DefineNewPasswordForm/useDefineNewPasswordSchema.content.mjs.map +0 -1
  213. package/dist/components/Auth/DefineNewPasswordForm/useDefineNewPasswordSchema.d.ts +0 -7
  214. package/dist/components/Auth/DefineNewPasswordForm/useDefineNewPasswordSchema.d.ts.map +0 -1
  215. package/dist/components/Auth/DefineNewPasswordForm/useDefineNewPasswordSchema.mjs +0 -29
  216. package/dist/components/Auth/DefineNewPasswordForm/useDefineNewPasswordSchema.mjs.map +0 -1
  217. package/dist/components/Auth/ExternalsLoginButtons/ExternalsLoginButtons.cjs +0 -81
  218. package/dist/components/Auth/ExternalsLoginButtons/ExternalsLoginButtons.cjs.map +0 -1
  219. package/dist/components/Auth/ExternalsLoginButtons/ExternalsLoginButtons.d.ts +0 -9
  220. package/dist/components/Auth/ExternalsLoginButtons/ExternalsLoginButtons.d.ts.map +0 -1
  221. package/dist/components/Auth/ExternalsLoginButtons/ExternalsLoginButtons.mjs +0 -81
  222. package/dist/components/Auth/ExternalsLoginButtons/ExternalsLoginButtons.mjs.map +0 -1
  223. package/dist/components/Auth/ExternalsLoginButtons/assets/GithubLogo.cjs +0 -15
  224. package/dist/components/Auth/ExternalsLoginButtons/assets/GithubLogo.cjs.map +0 -1
  225. package/dist/components/Auth/ExternalsLoginButtons/assets/GithubLogo.d.ts +0 -3
  226. package/dist/components/Auth/ExternalsLoginButtons/assets/GithubLogo.d.ts.map +0 -1
  227. package/dist/components/Auth/ExternalsLoginButtons/assets/GithubLogo.mjs +0 -15
  228. package/dist/components/Auth/ExternalsLoginButtons/assets/GithubLogo.mjs.map +0 -1
  229. package/dist/components/Auth/ExternalsLoginButtons/assets/GoogleLogo.cjs +0 -23
  230. package/dist/components/Auth/ExternalsLoginButtons/assets/GoogleLogo.cjs.map +0 -1
  231. package/dist/components/Auth/ExternalsLoginButtons/assets/GoogleLogo.d.ts +0 -3
  232. package/dist/components/Auth/ExternalsLoginButtons/assets/GoogleLogo.d.ts.map +0 -1
  233. package/dist/components/Auth/ExternalsLoginButtons/assets/GoogleLogo.mjs +0 -23
  234. package/dist/components/Auth/ExternalsLoginButtons/assets/GoogleLogo.mjs.map +0 -1
  235. package/dist/components/Auth/ExternalsLoginButtons/externalsLoginButtons.content.cjs +0 -90
  236. package/dist/components/Auth/ExternalsLoginButtons/externalsLoginButtons.content.cjs.map +0 -1
  237. package/dist/components/Auth/ExternalsLoginButtons/externalsLoginButtons.content.d.ts +0 -176
  238. package/dist/components/Auth/ExternalsLoginButtons/externalsLoginButtons.content.d.ts.map +0 -1
  239. package/dist/components/Auth/ExternalsLoginButtons/externalsLoginButtons.content.mjs +0 -90
  240. package/dist/components/Auth/ExternalsLoginButtons/externalsLoginButtons.content.mjs.map +0 -1
  241. package/dist/components/Auth/ExternalsLoginButtons/index.cjs +0 -7
  242. package/dist/components/Auth/ExternalsLoginButtons/index.cjs.map +0 -1
  243. package/dist/components/Auth/ExternalsLoginButtons/index.d.ts +0 -2
  244. package/dist/components/Auth/ExternalsLoginButtons/index.d.ts.map +0 -1
  245. package/dist/components/Auth/ExternalsLoginButtons/index.mjs +0 -7
  246. package/dist/components/Auth/ResetPasswordForm/ResetPasswordForm.cjs +0 -113
  247. package/dist/components/Auth/ResetPasswordForm/ResetPasswordForm.cjs.map +0 -1
  248. package/dist/components/Auth/ResetPasswordForm/ResetPasswordForm.d.ts +0 -11
  249. package/dist/components/Auth/ResetPasswordForm/ResetPasswordForm.d.ts.map +0 -1
  250. package/dist/components/Auth/ResetPasswordForm/ResetPasswordForm.mjs +0 -113
  251. package/dist/components/Auth/ResetPasswordForm/ResetPasswordForm.mjs.map +0 -1
  252. package/dist/components/Auth/ResetPasswordForm/index.cjs +0 -7
  253. package/dist/components/Auth/ResetPasswordForm/index.cjs.map +0 -1
  254. package/dist/components/Auth/ResetPasswordForm/index.d.ts +0 -3
  255. package/dist/components/Auth/ResetPasswordForm/index.d.ts.map +0 -1
  256. package/dist/components/Auth/ResetPasswordForm/index.mjs +0 -7
  257. package/dist/components/Auth/ResetPasswordForm/index.mjs.map +0 -1
  258. package/dist/components/Auth/ResetPasswordForm/resetPasswordContent.content.cjs +0 -123
  259. package/dist/components/Auth/ResetPasswordForm/resetPasswordContent.content.cjs.map +0 -1
  260. package/dist/components/Auth/ResetPasswordForm/resetPasswordContent.content.d.ts +0 -245
  261. package/dist/components/Auth/ResetPasswordForm/resetPasswordContent.content.d.ts.map +0 -1
  262. package/dist/components/Auth/ResetPasswordForm/resetPasswordContent.content.mjs +0 -123
  263. package/dist/components/Auth/ResetPasswordForm/resetPasswordContent.content.mjs.map +0 -1
  264. package/dist/components/Auth/ResetPasswordForm/useResetPasswordSchema.cjs +0 -15
  265. package/dist/components/Auth/ResetPasswordForm/useResetPasswordSchema.cjs.map +0 -1
  266. package/dist/components/Auth/ResetPasswordForm/useResetPasswordSchema.content.cjs +0 -56
  267. package/dist/components/Auth/ResetPasswordForm/useResetPasswordSchema.content.cjs.map +0 -1
  268. package/dist/components/Auth/ResetPasswordForm/useResetPasswordSchema.content.d.ts +0 -106
  269. package/dist/components/Auth/ResetPasswordForm/useResetPasswordSchema.content.d.ts.map +0 -1
  270. package/dist/components/Auth/ResetPasswordForm/useResetPasswordSchema.content.mjs +0 -56
  271. package/dist/components/Auth/ResetPasswordForm/useResetPasswordSchema.content.mjs.map +0 -1
  272. package/dist/components/Auth/ResetPasswordForm/useResetPasswordSchema.d.ts +0 -6
  273. package/dist/components/Auth/ResetPasswordForm/useResetPasswordSchema.d.ts.map +0 -1
  274. package/dist/components/Auth/ResetPasswordForm/useResetPasswordSchema.mjs +0 -15
  275. package/dist/components/Auth/ResetPasswordForm/useResetPasswordSchema.mjs.map +0 -1
  276. package/dist/components/Auth/SignInForm/SignInForm.cjs +0 -105
  277. package/dist/components/Auth/SignInForm/SignInForm.cjs.map +0 -1
  278. package/dist/components/Auth/SignInForm/SignInForm.d.ts +0 -11
  279. package/dist/components/Auth/SignInForm/SignInForm.d.ts.map +0 -1
  280. package/dist/components/Auth/SignInForm/SignInForm.mjs +0 -105
  281. package/dist/components/Auth/SignInForm/SignInForm.mjs.map +0 -1
  282. package/dist/components/Auth/SignInForm/index.cjs +0 -7
  283. package/dist/components/Auth/SignInForm/index.cjs.map +0 -1
  284. package/dist/components/Auth/SignInForm/index.d.ts +0 -3
  285. package/dist/components/Auth/SignInForm/index.d.ts.map +0 -1
  286. package/dist/components/Auth/SignInForm/index.mjs +0 -7
  287. package/dist/components/Auth/SignInForm/index.mjs.map +0 -1
  288. package/dist/components/Auth/SignInForm/signIn.content.cjs +0 -217
  289. package/dist/components/Auth/SignInForm/signIn.content.cjs.map +0 -1
  290. package/dist/components/Auth/SignInForm/signIn.content.d.ts +0 -447
  291. package/dist/components/Auth/SignInForm/signIn.content.d.ts.map +0 -1
  292. package/dist/components/Auth/SignInForm/signIn.content.mjs +0 -217
  293. package/dist/components/Auth/SignInForm/signIn.content.mjs.map +0 -1
  294. package/dist/components/Auth/SignInForm/useSignInSchema.cjs +0 -23
  295. package/dist/components/Auth/SignInForm/useSignInSchema.cjs.map +0 -1
  296. package/dist/components/Auth/SignInForm/useSignInSchema.content.cjs +0 -71
  297. package/dist/components/Auth/SignInForm/useSignInSchema.content.cjs.map +0 -1
  298. package/dist/components/Auth/SignInForm/useSignInSchema.content.d.ts +0 -139
  299. package/dist/components/Auth/SignInForm/useSignInSchema.content.d.ts.map +0 -1
  300. package/dist/components/Auth/SignInForm/useSignInSchema.content.mjs +0 -71
  301. package/dist/components/Auth/SignInForm/useSignInSchema.content.mjs.map +0 -1
  302. package/dist/components/Auth/SignInForm/useSignInSchema.d.ts +0 -7
  303. package/dist/components/Auth/SignInForm/useSignInSchema.d.ts.map +0 -1
  304. package/dist/components/Auth/SignInForm/useSignInSchema.mjs +0 -23
  305. package/dist/components/Auth/SignInForm/useSignInSchema.mjs.map +0 -1
  306. package/dist/components/Auth/SignUpForm/SignUpForm.cjs +0 -98
  307. package/dist/components/Auth/SignUpForm/SignUpForm.cjs.map +0 -1
  308. package/dist/components/Auth/SignUpForm/SignUpForm.d.ts +0 -10
  309. package/dist/components/Auth/SignUpForm/SignUpForm.d.ts.map +0 -1
  310. package/dist/components/Auth/SignUpForm/SignUpForm.mjs +0 -98
  311. package/dist/components/Auth/SignUpForm/SignUpForm.mjs.map +0 -1
  312. package/dist/components/Auth/SignUpForm/index.cjs +0 -7
  313. package/dist/components/Auth/SignUpForm/index.cjs.map +0 -1
  314. package/dist/components/Auth/SignUpForm/index.d.ts +0 -3
  315. package/dist/components/Auth/SignUpForm/index.d.ts.map +0 -1
  316. package/dist/components/Auth/SignUpForm/index.mjs +0 -7
  317. package/dist/components/Auth/SignUpForm/index.mjs.map +0 -1
  318. package/dist/components/Auth/SignUpForm/signUpForm.content.cjs +0 -184
  319. package/dist/components/Auth/SignUpForm/signUpForm.content.cjs.map +0 -1
  320. package/dist/components/Auth/SignUpForm/signUpForm.content.d.ts +0 -380
  321. package/dist/components/Auth/SignUpForm/signUpForm.content.d.ts.map +0 -1
  322. package/dist/components/Auth/SignUpForm/signUpForm.content.mjs +0 -185
  323. package/dist/components/Auth/SignUpForm/signUpForm.content.mjs.map +0 -1
  324. package/dist/components/Auth/SignUpForm/useSignUpSchema.cjs +0 -33
  325. package/dist/components/Auth/SignUpForm/useSignUpSchema.cjs.map +0 -1
  326. package/dist/components/Auth/SignUpForm/useSignUpSchema.content.cjs +0 -116
  327. package/dist/components/Auth/SignUpForm/useSignUpSchema.content.cjs.map +0 -1
  328. package/dist/components/Auth/SignUpForm/useSignUpSchema.content.d.ts +0 -238
  329. package/dist/components/Auth/SignUpForm/useSignUpSchema.content.d.ts.map +0 -1
  330. package/dist/components/Auth/SignUpForm/useSignUpSchema.content.mjs +0 -116
  331. package/dist/components/Auth/SignUpForm/useSignUpSchema.content.mjs.map +0 -1
  332. package/dist/components/Auth/SignUpForm/useSignUpSchema.d.ts +0 -8
  333. package/dist/components/Auth/SignUpForm/useSignUpSchema.d.ts.map +0 -1
  334. package/dist/components/Auth/SignUpForm/useSignUpSchema.mjs +0 -33
  335. package/dist/components/Auth/SignUpForm/useSignUpSchema.mjs.map +0 -1
  336. package/dist/components/Auth/VerifyEmailForm/VerifyEmailForm.cjs +0 -79
  337. package/dist/components/Auth/VerifyEmailForm/VerifyEmailForm.cjs.map +0 -1
  338. package/dist/components/Auth/VerifyEmailForm/VerifyEmailForm.d.ts +0 -10
  339. package/dist/components/Auth/VerifyEmailForm/VerifyEmailForm.d.ts.map +0 -1
  340. package/dist/components/Auth/VerifyEmailForm/VerifyEmailForm.mjs +0 -79
  341. package/dist/components/Auth/VerifyEmailForm/VerifyEmailForm.mjs.map +0 -1
  342. package/dist/components/Auth/VerifyEmailForm/VerifyEmailSchema.cjs +0 -8
  343. package/dist/components/Auth/VerifyEmailForm/VerifyEmailSchema.cjs.map +0 -1
  344. package/dist/components/Auth/VerifyEmailForm/VerifyEmailSchema.d.ts +0 -4
  345. package/dist/components/Auth/VerifyEmailForm/VerifyEmailSchema.d.ts.map +0 -1
  346. package/dist/components/Auth/VerifyEmailForm/VerifyEmailSchema.mjs +0 -8
  347. package/dist/components/Auth/VerifyEmailForm/VerifyEmailSchema.mjs.map +0 -1
  348. package/dist/components/Auth/VerifyEmailForm/index.cjs +0 -5
  349. package/dist/components/Auth/VerifyEmailForm/index.cjs.map +0 -1
  350. package/dist/components/Auth/VerifyEmailForm/index.content.cjs +0 -73
  351. package/dist/components/Auth/VerifyEmailForm/index.content.cjs.map +0 -1
  352. package/dist/components/Auth/VerifyEmailForm/index.content.d.ts +0 -143
  353. package/dist/components/Auth/VerifyEmailForm/index.content.d.ts.map +0 -1
  354. package/dist/components/Auth/VerifyEmailForm/index.content.mjs +0 -74
  355. package/dist/components/Auth/VerifyEmailForm/index.content.mjs.map +0 -1
  356. package/dist/components/Auth/VerifyEmailForm/index.d.ts +0 -2
  357. package/dist/components/Auth/VerifyEmailForm/index.d.ts.map +0 -1
  358. package/dist/components/Auth/VerifyEmailForm/index.mjs +0 -5
  359. package/dist/components/Auth/VerifyEmailForm/index.mjs.map +0 -1
  360. package/dist/components/Auth/index.cjs +0 -39
  361. package/dist/components/Auth/index.cjs.map +0 -1
  362. package/dist/components/Auth/index.d.ts +0 -12
  363. package/dist/components/Auth/index.d.ts.map +0 -1
  364. package/dist/components/Auth/index.mjs +0 -39
  365. package/dist/components/Auth/index.mjs.map +0 -1
  366. package/dist/components/Auth/useAuth/index.cjs +0 -31
  367. package/dist/components/Auth/useAuth/index.cjs.map +0 -1
  368. package/dist/components/Auth/useAuth/index.d.ts.map +0 -1
  369. package/dist/components/Auth/useAuth/index.mjs.map +0 -1
  370. package/dist/components/Auth/useAuth/useCSRF.cjs +0 -27
  371. package/dist/components/Auth/useAuth/useCSRF.cjs.map +0 -1
  372. package/dist/components/Auth/useAuth/useCSRF.d.ts +0 -6
  373. package/dist/components/Auth/useAuth/useCSRF.d.ts.map +0 -1
  374. package/dist/components/Auth/useAuth/useCSRF.mjs +0 -27
  375. package/dist/components/Auth/useAuth/useCSRF.mjs.map +0 -1
  376. package/dist/components/Auth/useAuth/useOAuth2.cjs.map +0 -1
  377. package/dist/components/Auth/useAuth/useOAuth2.d.ts.map +0 -1
  378. package/dist/components/Auth/useAuth/useOAuth2.mjs.map +0 -1
  379. package/dist/components/Auth/useAuth/useSession.cjs.map +0 -1
  380. package/dist/components/Auth/useAuth/useSession.d.ts.map +0 -1
  381. package/dist/components/Auth/useAuth/useSession.mjs +0 -66
  382. package/dist/components/Auth/useAuth/useSession.mjs.map +0 -1
  383. package/dist/components/Auth/useUser/index.cjs.map +0 -1
  384. package/dist/components/Auth/useUser/index.d.ts +0 -8
  385. package/dist/components/Auth/useUser/index.d.ts.map +0 -1
  386. package/dist/components/Auth/useUser/index.mjs.map +0 -1
  387. package/dist/components/ProfileDropDown/index.cjs +0 -25
  388. package/dist/components/ProfileDropDown/index.cjs.map +0 -1
  389. package/dist/components/ProfileDropDown/index.d.ts +0 -6
  390. package/dist/components/ProfileDropDown/index.d.ts.map +0 -1
  391. package/dist/components/ProfileDropDown/index.mjs +0 -25
  392. package/dist/components/ProfileDropDown/index.mjs.map +0 -1
  393. package/dist/hooks/useIntlayerAPI.d.ts +0 -103
  394. package/dist/hooks/useIntlayerAPI.d.ts.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"intlayerAPIHooks.d.ts","sourceRoot":"","sources":["../../src/hooks/intlayerAPIHooks.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAIjD,OAAO,EAAE,KAAK,eAAe,EAAY,MAAM,qBAAqB,CAAC;AA+IrE;;GAEG;AAEH,eAAO,MAAM,QAAQ,GACnB,OAAO,eAAe,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,2MAKlD,CAAC;AAEL,eAAO,MAAM,WAAW,GACtB,OAAO,eAAe,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,UAAU,CAAC,CAAC,uQAKrD,CAAC;AAEL,eAAO,MAAM,SAAS,GACpB,OAAO,eAAe,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAC,4HAKnD,CAAC;AAEL,eAAO,MAAM,iBAAiB,GAC5B,OAAO,eAAe,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,gBAAgB,CAAC,CAAC,sOACgB,CAAC;AAEhF,eAAO,MAAM,mBAAmB,GAC9B,OAAO,eAAe,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,kBAAkB,CAAC,CAAC,sPAM9D,CAAC;AA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e,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC,uBAAuB,CAAC,CAAC,6PAMzE,CAAC;AAEJ,eAAO,MAAM,4BAA4B,GACvC,OAAO,eAAe,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC,2BAA2B,CAAC,CAAC,mQAM7E,CAAC;AAEJ,eAAO,MAAM,sBAAsB,GACjC,OAAO,eAAe,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC,qBAAqB,CAAC,CAAC,6LAMvE,CAAC;AAEJ;;GAEG;AAEH,eAAO,MAAM,kBAAkB,GAC7B,OAAO,eAAe,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,iBAAiB,CAAC,CAAC,2PAM/D,CAAC;AAEJ,eAAO,MAAM,wBAAwB,GACnC,OAAO,eAAe,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,iBAAiB,CAAC,CAAC,oJAM9D,CAAC"}
@@ -1,15 +1,16 @@
1
1
  "use client";
2
2
  import { useConfiguration } from "@intlayer/editor-react";
3
- import { useAuth } from "../components/Auth/useAuth/index.mjs";
4
3
  import "../components/Toaster/Toast.mjs";
5
4
  import { useToast } from "../components/Toaster/useToast.mjs";
6
5
  import "react/jsx-runtime";
7
6
  import { useAsync } from "./useAsync/useAsync.mjs";
7
+ import { useAuth } from "./useAuth/useAuth.mjs";
8
+ import "@intlayer/api";
9
+ import "@intlayer/config/built";
10
+ import "./useAsync/useAsyncStateStore.mjs";
8
11
  import { useIntlayerAuth } from "./useIntlayerAPI.mjs";
9
12
  var define_process_env_default = {};
10
- const formatErrorCode = (errorCode) => {
11
- return errorCode.split("_").join(" ");
12
- };
13
+ const formatErrorCode = (errorCode) => errorCode.split("_").join(" ");
13
14
  const useErrorHandling = (options) => {
14
15
  const { toast } = useToast();
15
16
  return {
@@ -34,6 +35,15 @@ const useErrorHandling = (options) => {
34
35
  options.onError?.(errorMessage);
35
36
  },
36
37
  onSuccess: (data) => {
38
+ if (data?.error) {
39
+ toast({
40
+ title: formatErrorCode(
41
+ data.error.title ?? data.error.code ?? "Error"
42
+ ),
43
+ description: data.error.message ?? data.error.code ?? "An error occurred",
44
+ variant: "error"
45
+ });
46
+ }
37
47
  if (data?.message)
38
48
  toast({
39
49
  title: data.message,
@@ -46,7 +56,7 @@ const useErrorHandling = (options) => {
46
56
  };
47
57
  const useAuthEnable = (options, { requireUser, requireProject, requireOrganization } = {}) => {
48
58
  const configuration = useConfiguration();
49
- const { csrfToken, oAuth2AccessToken, session } = useAuth({
59
+ const { oAuth2AccessToken, session } = useAuth({
50
60
  intlayerConfiguration: configuration
51
61
  });
52
62
  const isEnabledOption = options?.enable ?? true;
@@ -56,9 +66,7 @@ const useAuthEnable = (options, { requireUser, requireProject, requireOrganizati
56
66
  const isUserEnabled = requireUser ? Boolean(user) : true;
57
67
  const isProjectEnabled = requireProject ? Boolean(project) : true;
58
68
  const isOrganizationEnabled = requireOrganization ? Boolean(organization) : true;
59
- const isCSRFEnabled = Boolean(csrfToken) || // If auth using session, csrf token is not required
60
- !session && Boolean(oAuth2AccessToken);
61
- const isEnabled = isEnabledOption && isUserEnabled && isProjectEnabled && isOrganizationEnabled && isCSRFEnabled;
69
+ const isEnabled = isEnabledOption && isUserEnabled && isProjectEnabled && isOrganizationEnabled;
62
70
  return {
63
71
  ...options,
64
72
  enable: isEnabled
@@ -73,43 +81,34 @@ const useEditorAsync = (key, asyncFunction, options) => {
73
81
  const optionsWithErrorHandling = useErrorHandling(options ?? {});
74
82
  return useAsync(key, asyncFunction, optionsWithErrorHandling);
75
83
  };
76
- const useLogin = (args) => useAppAsync("login", useIntlayerAuth().auth.login, {
84
+ const useLogin = (args) => useAppAsync("login", useIntlayerAuth().auth.signInEmail, {
77
85
  invalidateQueries: ["getSession"],
78
86
  ...args
79
87
  });
80
- const useRegister = (args) => useAppAsync("register", useIntlayerAuth().auth.register, {
88
+ const useRegister = (args) => useAppAsync("register", useIntlayerAuth().auth.signUpEmail, {
81
89
  invalidateQueries: ["getSession"],
82
90
  ...args
83
91
  });
84
- const useLogout = (args) => useAppAsync("logout", useIntlayerAuth().auth.logout, {
85
- invalidateQueries: ["getSession"],
92
+ const useLogout = (args) => useAppAsync("logout", useIntlayerAuth().auth.signOut, {
86
93
  ...args
87
94
  });
88
- const useChangePassword = (args) => useAppAsync("changePassword", useIntlayerAuth().auth.changePassword, args);
95
+ const useChangePassword = (args) => useAppAsync(
96
+ "changePassword",
97
+ useIntlayerAuth().auth.changePasswordSession,
98
+ args
99
+ );
89
100
  const useAskResetPassword = (args) => useAppAsync(
90
101
  "askResetPassword",
91
- useIntlayerAuth().auth.askResetPassword,
102
+ useIntlayerAuth().auth.requestPasswordResetSession,
92
103
  args
93
104
  );
94
105
  const useDefineNewPassword = (args) => useAppAsync(
95
106
  "defineNewPassword",
96
- useIntlayerAuth().auth.defineNewPassword,
97
- args
98
- );
99
- const useCheckIfUserHasPassword = (args) => useAppAsync(
100
- "checkIfUserHasPassword",
101
- useIntlayerAuth().auth.checkIfUserHasPassword,
102
- args,
103
- {
104
- requireUser: true
105
- }
106
- );
107
- const useVerifyEmail = (args) => useAppAsync("verifyEmail", useIntlayerAuth().auth.verifyEmail, args);
108
- const useGetUserByAccount = (args) => useAppAsync(
109
- "getUserByAccount",
110
- useIntlayerAuth().user.getUserByAccount,
107
+ useIntlayerAuth().auth.changePasswordSession,
111
108
  args
112
109
  );
110
+ const useVerifyEmail = (args) => useAppAsync("verifyEmail", useIntlayerAuth().auth.verifyEmailSession, args);
111
+ const useGetUserByAccount = (args) => useAppAsync("getUserByAccount", useIntlayerAuth().auth.accountInfo, args);
113
112
  const useGetUsers = (args) => useAppAsync(
114
113
  "getUsers",
115
114
  useIntlayerAuth().user.getUsers,
@@ -126,7 +125,7 @@ const useGetUsers = (args) => useAppAsync(
126
125
  requireUser: true
127
126
  }
128
127
  );
129
- const useCreateUser = (args) => useAppAsync("createUser", useIntlayerAuth().user.createUser, {
128
+ const useCreateUser = (args) => useAppAsync("createUser", useIntlayerAuth().auth.updateUser, {
130
129
  invalidateQueries: ["getUsers"],
131
130
  ...args
132
131
  });
@@ -498,7 +497,6 @@ export {
498
497
  useAutocomplete,
499
498
  useCancelSubscription,
500
499
  useChangePassword,
501
- useCheckIfUserHasPassword,
502
500
  useCreateUser,
503
501
  useDefineNewPassword,
504
502
  useDeleteAccessKey,
@@ -1 +1 @@
1
- {"version":3,"file":"intlayerAPIHooks.mjs","sources":["../../src/hooks/intlayerAPIHooks.ts"],"sourcesContent":["'use client';\n\nimport type { IntlayerAPI } from '@intlayer/api';\nimport { useConfiguration } from '@intlayer/editor-react';\nimport { useAuth } from '../components/Auth/useAuth/index';\nimport { useToast } from '../components/Toaster';\nimport { type UseAsyncOptions, useAsync } from './useAsync/useAsync';\nimport { useIntlayerAuth } from './useIntlayerAPI';\n\nconst formatErrorCode = (errorCode: string) => {\n return errorCode.split('_').join(' ');\n};\n\n/**\n * Hook to handle error logging and toast notifications\n */\nconst useErrorHandling = <T extends UseAsyncOptions<any>>(options: T): T => {\n const { toast } = useToast();\n\n return {\n ...options,\n onError: (errorMessage) => {\n let error;\n\n // If json is valid, parse it\n try {\n if (typeof errorMessage === 'undefined') return;\n\n error = JSON.parse(errorMessage);\n } catch (e) {\n // If json is not valid, set error to the original errorMessage\n\n error = errorMessage;\n }\n\n // render toast for each error if there is more than one\n // otherwise render the toast with the error message\n [error]\n .flatMap((error) => error)\n .forEach((error) =>\n toast({\n title: formatErrorCode(\n (process.env.NODE_ENV === 'production'\n ? error.title\n : error.code) ?? 'Error'\n ),\n description: error.message ?? errorMessage ?? 'An error occurred',\n variant: 'error',\n })\n );\n options.onError?.(errorMessage);\n },\n onSuccess: (data) => {\n if (data?.message)\n toast({\n title: data.message,\n description: data.description,\n variant: 'success',\n });\n options.onSuccess?.(data);\n },\n };\n};\n\ntype AuthEnableOptions = {\n requireUser?: boolean;\n requireProject?: boolean;\n requireOrganization?: boolean;\n};\n\n/**\n * Hook to enable authentication\n */\nconst useAuthEnable = <T extends UseAsyncOptions<any>>(\n options: T,\n { requireUser, requireProject, requireOrganization }: AuthEnableOptions = {}\n): T => {\n const configuration = useConfiguration();\n const { csrfToken, oAuth2AccessToken, session } = useAuth({\n intlayerConfiguration: configuration,\n });\n\n const isEnabledOption = options?.enable ?? true;\n const user = session ? session.user : oAuth2AccessToken?.user;\n\n const organization = session\n ? session.organization\n : oAuth2AccessToken?.organization;\n\n const project = session ? session.project : oAuth2AccessToken?.project;\n\n const isUserEnabled = requireUser ? Boolean(user) : true;\n\n const isProjectEnabled = requireProject ? Boolean(project) : true;\n\n const isOrganizationEnabled = requireOrganization\n ? Boolean(organization)\n : true;\n\n const isCSRFEnabled =\n Boolean(csrfToken) ||\n // If auth using session, csrf token is not required\n (!session && Boolean(oAuth2AccessToken));\n\n const isEnabled =\n isEnabledOption &&\n isUserEnabled &&\n isProjectEnabled &&\n isOrganizationEnabled &&\n isCSRFEnabled;\n\n return {\n ...options,\n enable: isEnabled,\n };\n};\n\nconst useAppAsync = <\n U extends string,\n T extends (...args: any[]) => Promise<any>,\n>(\n key: U,\n asyncFunction: T,\n options?: UseAsyncOptions<T>,\n authOptions?: AuthEnableOptions\n) => {\n // Enhance options using custom hooks\n const optionsWithAuth = useAuthEnable(options ?? {}, authOptions);\n\n const optionsWithErrorHandling = useErrorHandling(optionsWithAuth);\n\n // Call the main useAsync hook with enhanced options\n return useAsync(key, asyncFunction, optionsWithErrorHandling);\n};\n\nconst useEditorAsync = <\n U extends string,\n T extends (...args: any[]) => Promise<any>,\n>(\n key: U,\n asyncFunction: T,\n options?: UseAsyncOptions<T>\n) => {\n const optionsWithErrorHandling = useErrorHandling(options ?? {});\n\n // Call the main useAsync hook with enhanced options\n return useAsync(key, asyncFunction, optionsWithErrorHandling);\n};\n\n/**\n * Auth\n */\n\nexport const useLogin = (\n args?: UseAsyncOptions<IntlayerAPI['auth']['login']>\n) =>\n useAppAsync('login', useIntlayerAuth().auth.login, {\n invalidateQueries: ['getSession'],\n ...args,\n });\n\nexport const useRegister = (\n args?: UseAsyncOptions<IntlayerAPI['auth']['register']>\n) =>\n useAppAsync('register', useIntlayerAuth().auth.register, {\n invalidateQueries: ['getSession'],\n ...args,\n });\n\nexport const useLogout = (\n args?: UseAsyncOptions<IntlayerAPI['auth']['logout']>\n) =>\n useAppAsync('logout', useIntlayerAuth().auth.logout, {\n invalidateQueries: ['getSession'],\n ...args,\n });\n\nexport const useChangePassword = (\n args?: UseAsyncOptions<IntlayerAPI['auth']['changePassword']>\n) => useAppAsync('changePassword', useIntlayerAuth().auth.changePassword, args);\n\nexport const useAskResetPassword = (\n args?: UseAsyncOptions<IntlayerAPI['auth']['askResetPassword']>\n) =>\n useAppAsync(\n 'askResetPassword',\n useIntlayerAuth().auth.askResetPassword,\n args\n );\n\nexport const useDefineNewPassword = (\n args?: UseAsyncOptions<IntlayerAPI['auth']['defineNewPassword']>\n) =>\n useAppAsync(\n 'defineNewPassword',\n useIntlayerAuth().auth.defineNewPassword,\n args\n );\n\nexport const useCheckIfUserHasPassword = (\n args?: UseAsyncOptions<IntlayerAPI['auth']['checkIfUserHasPassword']>\n) =>\n useAppAsync(\n 'checkIfUserHasPassword',\n useIntlayerAuth().auth.checkIfUserHasPassword,\n args,\n {\n requireUser: true,\n }\n );\n\nexport const useVerifyEmail = (\n args?: UseAsyncOptions<IntlayerAPI['auth']['verifyEmail']>\n) => useAppAsync('verifyEmail', useIntlayerAuth().auth.verifyEmail, args);\n\nexport const useGetUserByAccount = (\n args?: UseAsyncOptions<IntlayerAPI['user']['getUserByAccount']>\n) =>\n useAppAsync(\n 'getUserByAccount',\n useIntlayerAuth().user.getUserByAccount,\n args\n );\n\n/**\n * User\n */\n\nexport const useGetUsers = (\n args?: UseAsyncOptions<IntlayerAPI['user']['getUsers']>\n) =>\n useAppAsync(\n 'getUsers',\n useIntlayerAuth().user.getUsers,\n {\n cache: true,\n store: true,\n retryLimit: 3,\n autoFetch: true,\n revalidateTime: 5 * 60 * 1000, // 5 minutes\n ...args,\n },\n {\n requireUser: true,\n }\n );\n\nexport const useCreateUser = (\n args?: UseAsyncOptions<IntlayerAPI['user']['createUser']>\n) =>\n useAppAsync('createUser', useIntlayerAuth().user.createUser, {\n invalidateQueries: ['getUsers'],\n ...args,\n });\n\nexport const useUpdateUser = (\n args?: UseAsyncOptions<IntlayerAPI['user']['updateUser']>\n) =>\n useAppAsync('updateUser', useIntlayerAuth().user.updateUser, {\n invalidateQueries: ['getSession'],\n ...args,\n });\n\nexport const useDeleteUser = (\n args?: UseAsyncOptions<IntlayerAPI['user']['deleteUser']>\n) =>\n useAppAsync('deleteUser', useIntlayerAuth().user.deleteUser, {\n invalidateQueries: ['getUsers'],\n ...args,\n });\n\n/**\n * Organization\n */\n\nexport const useGetOrganizations = (\n args?: UseAsyncOptions<IntlayerAPI['organization']['getOrganizations']>\n) =>\n useAppAsync(\n 'getOrganizations',\n useIntlayerAuth().organization.getOrganizations,\n {\n cache: true,\n store: true,\n retryLimit: 3,\n autoFetch: true,\n revalidation: true,\n revalidateTime: 5 * 60 * 1000, // 5 minutes\n ...args,\n },\n {\n requireUser: true,\n }\n );\n\nexport const useAddOrganization = (\n args?: UseAsyncOptions<IntlayerAPI['organization']['addOrganization']>\n) =>\n useAppAsync(\n 'addOrganization',\n useIntlayerAuth().organization.addOrganization,\n {\n invalidateQueries: ['getOrganizations'],\n ...args,\n }\n );\n\nexport const useUpdateOrganization = (\n args?: UseAsyncOptions<IntlayerAPI['organization']['updateOrganization']>\n) =>\n useAppAsync(\n 'updateOrganization',\n useIntlayerAuth().organization.updateOrganization,\n {\n invalidateQueries: ['getSession'],\n ...args,\n }\n );\n\nexport const useUpdateOrganizationMembers = (\n args?: UseAsyncOptions<\n IntlayerAPI['organization']['updateOrganizationMembers']\n >\n) =>\n useAppAsync(\n 'updateOrganizationMembers',\n useIntlayerAuth().organization.updateOrganizationMembers,\n {\n invalidateQueries: ['getOrganizations', 'getSession'],\n ...args,\n }\n );\n\nexport const useAddOrganizationMember = (\n args?: UseAsyncOptions<IntlayerAPI['organization']['addOrganizationMember']>\n) =>\n useAppAsync(\n 'addOrganizationMember',\n useIntlayerAuth().organization.addOrganizationMember,\n {\n invalidateQueries: ['getOrganizations', 'getSession'],\n ...args,\n }\n );\n\nexport const useDeleteOrganization = (\n args?: UseAsyncOptions<IntlayerAPI['organization']['deleteOrganization']>\n) =>\n useAppAsync(\n 'deleteOrganization',\n useIntlayerAuth().organization.deleteOrganization,\n {\n invalidateQueries: ['getOrganizations', 'getSession'],\n ...args,\n }\n );\n\nexport const useSelectOrganization = (\n args?: UseAsyncOptions<IntlayerAPI['organization']['selectOrganization']>\n) =>\n useAppAsync(\n 'selectOrganization',\n useIntlayerAuth().organization.selectOrganization,\n {\n invalidateQueries: ['getSession'],\n ...args,\n }\n );\n\nexport const useUnselectOrganization = (\n args?: UseAsyncOptions<IntlayerAPI['organization']['unselectOrganization']>\n) =>\n useAppAsync(\n 'unselectOrganization',\n useIntlayerAuth().organization.unselectOrganization,\n {\n invalidateQueries: ['getSession'],\n ...args,\n }\n );\n\n/**\n * Project\n */\n\nexport const useGetProjects = (\n args?: UseAsyncOptions<IntlayerAPI['project']['getProjects']>\n) =>\n useAppAsync(\n 'getProjects',\n useIntlayerAuth().project.getProjects,\n {\n cache: true,\n store: true,\n retryLimit: 3,\n autoFetch: true,\n revalidation: true,\n revalidateTime: 5 * 60 * 1000, // 5 minutes\n ...args,\n },\n {\n requireUser: true,\n requireOrganization: true,\n }\n );\n\nexport const useAddProject = (\n args?: UseAsyncOptions<IntlayerAPI['project']['addProject']>\n) =>\n useAppAsync('addProject', useIntlayerAuth().project.addProject, {\n invalidateQueries: ['getProjects'],\n ...args,\n });\n\nexport const useUpdateProject = (\n args?: UseAsyncOptions<IntlayerAPI['project']['updateProject']>\n) =>\n useAppAsync('updateProject', useIntlayerAuth().project.updateProject, {\n invalidateQueries: ['getSession'],\n ...args,\n });\n\nexport const useUpdateProjectMembers = (\n args?: UseAsyncOptions<IntlayerAPI['project']['updateProjectMembers']>\n) =>\n useAppAsync(\n 'updateProjectMembers',\n useIntlayerAuth().project.updateProjectMembers,\n {\n invalidateQueries: ['getSession'],\n ...args,\n }\n );\n\nexport const useDeleteProject = (\n args?: UseAsyncOptions<IntlayerAPI['project']['deleteProject']>\n) =>\n useAppAsync('deleteProject', useIntlayerAuth().project.deleteProject, {\n invalidateQueries: ['getProjects', 'getSession'],\n ...args,\n });\n\nexport const useSelectProject = (\n args?: UseAsyncOptions<IntlayerAPI['project']['selectProject']>\n) =>\n useAppAsync('selectProject', useIntlayerAuth().project.selectProject, {\n invalidateQueries: ['getSession'],\n ...args,\n });\n\nexport const useUnselectProject = (\n args?: UseAsyncOptions<IntlayerAPI['project']['unselectProject']>\n) =>\n useAppAsync('unselectProject', useIntlayerAuth().project.unselectProject, {\n invalidateQueries: ['getSession'],\n ...args,\n });\n\nexport const useAddNewAccessKey = (\n args?: UseAsyncOptions<IntlayerAPI['project']['addNewAccessKey']>\n) =>\n useAppAsync('addNewAccessKey', useIntlayerAuth().project.addNewAccessKey, {\n invalidateQueries: ['getSession'],\n ...args,\n });\n\nexport const useDeleteAccessKey = (\n args?: UseAsyncOptions<IntlayerAPI['project']['deleteAccessKey']>\n) =>\n useAppAsync('deleteAccessKey', useIntlayerAuth().project.deleteAccessKey, {\n invalidateQueries: ['getSession'],\n ...args,\n });\n\nexport const useRefreshAccessKey = (\n args?: UseAsyncOptions<IntlayerAPI['project']['refreshAccessKey']>\n) =>\n useAppAsync('refreshAccessKey', useIntlayerAuth().project.refreshAccessKey, {\n invalidateQueries: ['getSession'],\n ...args,\n });\n\n/**\n * Dictionary\n */\n\nexport const useGetDictionaries = (\n args?: UseAsyncOptions<IntlayerAPI['dictionary']['getDictionaries']>\n) =>\n useAppAsync(\n 'getDictionaries',\n useIntlayerAuth().dictionary.getDictionaries,\n {\n cache: true,\n store: true,\n retryLimit: 3,\n autoFetch: true,\n revalidation: true,\n revalidateTime: 5 * 60 * 1000, // 5 minutes\n ...args,\n },\n {\n requireUser: true,\n requireOrganization: true,\n requireProject: true,\n }\n );\n\nexport const useGetDictionariesKeys = (\n args?: UseAsyncOptions<IntlayerAPI['dictionary']['getDictionariesKeys']>\n) =>\n useAppAsync(\n 'getDictionariesKeys',\n useIntlayerAuth().dictionary.getDictionariesKeys,\n {\n cache: true,\n store: true,\n retryLimit: 3,\n autoFetch: true,\n revalidation: true,\n revalidateTime: 5 * 60 * 1000, // 5 minutes\n ...args,\n },\n {\n requireUser: true,\n requireOrganization: true,\n requireProject: true,\n }\n );\n\nexport const useGetDictionary = (\n args?: UseAsyncOptions<IntlayerAPI['dictionary']['getDictionary']>\n) =>\n useAppAsync(\n 'getDictionary',\n useIntlayerAuth().dictionary.getDictionary,\n {\n cache: true,\n store: true,\n retryLimit: 3,\n revalidation: true,\n revalidateTime: 5 * 60 * 1000, // 5 minutes\n ...args,\n },\n {\n requireUser: true,\n requireOrganization: true,\n requireProject: true,\n }\n );\n\nexport const useAddDictionary = (\n args?: UseAsyncOptions<IntlayerAPI['dictionary']['addDictionary']>\n) =>\n useAppAsync('addDictionary', useIntlayerAuth().dictionary.addDictionary, {\n invalidateQueries: ['getDictionaries', 'getDictionariesKeys'],\n ...args,\n });\n\nexport const usePushDictionaries = (\n args?: UseAsyncOptions<IntlayerAPI['dictionary']['pushDictionaries']>\n) =>\n useAppAsync(\n 'pushDictionaries',\n useIntlayerAuth().dictionary.pushDictionaries,\n {\n invalidateQueries: [\n 'getDictionaries',\n 'getDictionary',\n 'getDictionariesKeys',\n ],\n ...args,\n }\n );\n\nexport const useUpdateDictionary = (\n args?: UseAsyncOptions<IntlayerAPI['dictionary']['updateDictionary']>\n) =>\n useAppAsync(\n 'updateDictionary',\n useIntlayerAuth().dictionary.updateDictionary,\n {\n invalidateQueries: ['getDictionaries', 'getDictionary'],\n ...args,\n }\n );\n\nexport const useDeleteDictionary = (\n args?: UseAsyncOptions<IntlayerAPI['dictionary']['deleteDictionary']>\n) =>\n useAppAsync(\n 'deleteDictionary',\n useIntlayerAuth().dictionary.deleteDictionary,\n {\n invalidateQueries: [\n 'getDictionaries',\n 'getDictionary',\n 'getDictionariesKeys',\n ],\n ...args,\n }\n );\n\n/**\n * Tag\n */\n\nexport const useGetTags = (\n args?: UseAsyncOptions<IntlayerAPI['tag']['getTags']>\n) =>\n useAppAsync(\n 'getTags',\n useIntlayerAuth().tag.getTags,\n {\n cache: true,\n store: true,\n retryLimit: 3,\n autoFetch: true,\n revalidation: true,\n revalidateTime: 5 * 60 * 1000, // 5 minutes\n ...args,\n },\n {\n requireUser: true,\n requireOrganization: true,\n }\n );\n\nexport const useAddTag = (\n args?: UseAsyncOptions<IntlayerAPI['tag']['addTag']>\n) =>\n useAppAsync('addTag', useIntlayerAuth().tag.addTag, {\n invalidateQueries: ['getTags'],\n ...args,\n });\n\nexport const useUpdateTag = (\n args?: UseAsyncOptions<IntlayerAPI['tag']['updateTag']>\n) =>\n useAppAsync('updateTag', useIntlayerAuth().tag.updateTag, {\n invalidateQueries: ['getTags'],\n ...args,\n });\n\nexport const useDeleteTag = (\n args?: UseAsyncOptions<IntlayerAPI['tag']['deleteTag']>\n) =>\n useAppAsync('deleteTag', useIntlayerAuth().tag.deleteTag, {\n invalidateQueries: ['getTags'],\n ...args,\n });\n\n/**\n * Stripe\n */\n\nexport const useGetPricing = (\n args?: UseAsyncOptions<IntlayerAPI['stripe']['getPricing']>\n) =>\n useAppAsync('getPricing', useIntlayerAuth().stripe.getPricing, {\n store: true,\n cache: true,\n ...args,\n });\n\nexport const useGetSubscription = (\n args?: UseAsyncOptions<IntlayerAPI['stripe']['getSubscription']>\n) =>\n useAppAsync(\n 'getSubscription',\n useIntlayerAuth().stripe.getSubscription,\n args,\n {\n requireUser: true,\n requireOrganization: true,\n }\n );\n\nexport const useCancelSubscription = (\n args?: UseAsyncOptions<IntlayerAPI['stripe']['cancelSubscription']>\n) =>\n useAppAsync(\n 'cancelSubscription',\n useIntlayerAuth().stripe.cancelSubscription,\n { invalidateQueries: ['getSession'], ...args },\n {\n requireUser: true,\n requireOrganization: true,\n }\n );\n\n/**\n * AI\n */\n\nexport const useTranslateJSONDeclaration = (\n args?: UseAsyncOptions<IntlayerAPI['ai']['translateJSON']>\n) =>\n useAppAsync('translateJSON', useIntlayerAuth().ai.translateJSON, args, {\n requireUser: true,\n requireOrganization: true,\n requireProject: true,\n });\n\nexport const useAuditContentDeclaration = (\n args?: UseAsyncOptions<IntlayerAPI['ai']['auditContentDeclaration']>\n) =>\n useAppAsync(\n 'auditContentDeclaration',\n useIntlayerAuth().ai.auditContentDeclaration,\n args,\n {\n requireUser: true,\n requireOrganization: true,\n requireProject: true,\n }\n );\n\nexport const useAuditContentDeclarationMetadata = (\n args?: UseAsyncOptions<IntlayerAPI['ai']['auditContentDeclarationMetadata']>\n) =>\n useAppAsync(\n 'auditContentDeclaration',\n useIntlayerAuth().ai.auditContentDeclarationMetadata,\n args,\n {\n requireUser: true,\n requireOrganization: true,\n requireProject: true,\n }\n );\n\nexport const useAuditContentDeclarationField = (\n args?: UseAsyncOptions<IntlayerAPI['ai']['auditContentDeclarationField']>\n) =>\n useAppAsync(\n 'auditContentDeclarationField',\n useIntlayerAuth().ai.auditContentDeclarationField,\n args,\n {\n requireUser: true,\n requireOrganization: true,\n requireProject: true,\n }\n );\n\nexport const useAuditTag = (\n args?: UseAsyncOptions<IntlayerAPI['ai']['auditTag']>\n) =>\n useAppAsync('auditTag', useIntlayerAuth().ai.auditTag, args, {\n requireUser: true,\n requireOrganization: true,\n requireProject: true,\n });\n\nexport const useAskDocQuestion = (\n args?: UseAsyncOptions<IntlayerAPI['ai']['askDocQuestion']>\n) => useAppAsync('askDocQuestion', useIntlayerAuth().ai.askDocQuestion, args);\n\nexport const useAutocomplete = (\n args?: UseAsyncOptions<IntlayerAPI['ai']['autocomplete']>\n) => useAppAsync('autocomplete', useIntlayerAuth().ai.autocomplete, args);\n\n/**\n * Search\n */\n\nexport const useSearchDoc = (\n args?: UseAsyncOptions<IntlayerAPI['search']['searchDoc']>\n) => useAppAsync('searchDoc', useIntlayerAuth().search.searchDoc, args);\n\n/**\n * Newsletter\n */\n\nexport const useSubscribeToNewsletter = (\n args?: UseAsyncOptions<IntlayerAPI['newsletter']['subscribeToNewsletter']>\n) =>\n useAppAsync(\n 'subscribeToNewsletter',\n useIntlayerAuth().newsletter.subscribeToNewsletter,\n args\n );\n\nexport const useUnsubscribeFromNewsletter = (\n args?: UseAsyncOptions<IntlayerAPI['newsletter']['unsubscribeFromNewsletter']>\n) =>\n useAppAsync(\n 'unsubscribeFromNewsletter',\n useIntlayerAuth().newsletter.unsubscribeFromNewsletter,\n args\n );\n\nexport const useGetNewsletterStatus = (\n args?: UseAsyncOptions<IntlayerAPI['newsletter']['getNewsletterStatus']>\n) =>\n useAppAsync(\n 'getNewsletterStatus',\n useIntlayerAuth().newsletter.getNewsletterStatus,\n args\n );\n\n/**\n * Editor\n */\n\nexport const useWriteDictionary = (\n args?: UseAsyncOptions<IntlayerAPI['editor']['writeDictionary']>\n) =>\n useEditorAsync(\n 'writeDictionary',\n useIntlayerAuth().editor.writeDictionary,\n args\n );\n\nexport const useGetEditorDictionaries = (\n args?: UseAsyncOptions<IntlayerAPI['editor']['getDictionaries']>\n) =>\n useEditorAsync('getDictionaries', useIntlayerAuth().editor.getDictionaries, {\n store: true,\n cache: true,\n ...args,\n });\n"],"names":["error"],"mappings":";;;;;;;;;AASA,MAAM,kBAAkB,CAAC,cAAsB;AAC7C,SAAO,UAAU,MAAM,GAAG,EAAE,KAAK,GAAG;AACtC;AAKA,MAAM,mBAAmB,CAAiC,YAAkB;AACpE,QAAA,EAAE,MAAM,IAAI,SAAS;AAEpB,SAAA;AAAA,IACL,GAAG;AAAA,IACH,SAAS,CAAC,iBAAiB;AACrB,UAAA;AAGA,UAAA;AACE,YAAA,OAAO,iBAAiB,YAAa;AAEjC,gBAAA,KAAK,MAAM,YAAY;AAAA,eACxB,GAAG;AAGF,gBAAA;AAAA,MAAA;AAKV,OAAC,KAAK,EACH,QAAQ,CAACA,WAAUA,MAAK,E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Aa,kBAAkB,OAAO,WAAW,IAAI;AAMzD,MAAA,2BAA2B,CACtC,SAEA;AAAA,EACE;AAAA,EACA,gBAAA,EAAkB,WAAW;AAAA,EAC7B;AACF;AAEW,MAAA,+BAA+B,CAC1C,SAEA;AAAA,EACE;AAAA,EACA,gBAAA,EAAkB,WAAW;AAAA,EAC7B;AACF;AAEW,MAAA,yBAAyB,CACpC,SAEA;AAAA,EACE;AAAA,EACA,gBAAA,EAAkB,WAAW;AAAA,EAC7B;AACF;AAMW,MAAA,qBAAqB,CAChC,SAEA;AAAA,EACE;AAAA,EACA,gBAAA,EAAkB,OAAO;AAAA,EACzB;AACF;AAEW,MAAA,2BAA2B,CACtC,SAEA,eAAe,mBAAmB,gBAAgB,EAAE,OAAO,iBAAiB;AAAA,EAC1E,OAAO;AAAA,EACP,OAAO;AAAA,EACP,GAAG;AACL,CAAC;"}
1
+ {"version":3,"file":"intlayerAPIHooks.mjs","sources":["../../src/hooks/intlayerAPIHooks.ts"],"sourcesContent":["'use client';\n\nimport type { IntlayerAPI } from '@intlayer/api';\nimport { useConfiguration } from '@intlayer/editor-react';\nimport { useToast } from '../components/Toaster';\nimport { type UseAsyncOptions, useAsync } from './useAsync/useAsync';\nimport { useAuth } from './useAuth';\nimport { useIntlayerAuth } from './useIntlayerAPI';\n\nconst formatErrorCode = (errorCode: string) => errorCode.split('_').join(' ');\n\n/**\n * Hook to handle error logging and toast notifications\n */\nconst useErrorHandling = <T extends UseAsyncOptions<any>>(options: T): T => {\n const { toast } = useToast();\n\n return {\n ...options,\n onError: (errorMessage) => {\n let error;\n\n // If json is valid, parse it\n try {\n if (typeof errorMessage === 'undefined') return;\n\n error = JSON.parse(errorMessage);\n } catch (e) {\n // If json is not valid, set error to the original errorMessage\n\n error = errorMessage;\n }\n\n // render toast for each error if there is more than one\n // otherwise render the toast with the error message\n [error]\n .flatMap((error) => error)\n .forEach((error) =>\n toast({\n title: formatErrorCode(\n (process.env.NODE_ENV === 'production'\n ? error.title\n : error.code) ?? 'Error'\n ),\n description: error.message ?? errorMessage ?? 'An error occurred',\n variant: 'error',\n })\n );\n options.onError?.(errorMessage);\n },\n onSuccess: (data) => {\n if (data?.error) {\n toast({\n title: formatErrorCode(\n data.error.title ?? data.error.code ?? 'Error'\n ),\n description:\n data.error.message ?? data.error.code ?? 'An error occurred',\n variant: 'error',\n });\n }\n\n if (data?.message)\n toast({\n title: data.message,\n description: data.description,\n variant: 'success',\n });\n options.onSuccess?.(data);\n },\n };\n};\n\ntype AuthEnableOptions = {\n requireUser?: boolean;\n requireProject?: boolean;\n requireOrganization?: boolean;\n};\n\n/**\n * Hook to enable authentication\n */\nconst useAuthEnable = <T extends UseAsyncOptions<any>>(\n options: T,\n { requireUser, requireProject, requireOrganization }: AuthEnableOptions = {}\n): T => {\n const configuration = useConfiguration();\n const { oAuth2AccessToken, session } = useAuth({\n intlayerConfiguration: configuration,\n });\n\n const isEnabledOption = options?.enable ?? true;\n const user = session ? session.user : oAuth2AccessToken?.user;\n\n const organization = session\n ? session.organization\n : oAuth2AccessToken?.organization;\n\n const project = session ? session.project : oAuth2AccessToken?.project;\n\n const isUserEnabled = requireUser ? Boolean(user) : true;\n\n const isProjectEnabled = requireProject ? Boolean(project) : true;\n\n const isOrganizationEnabled = requireOrganization\n ? Boolean(organization)\n : true;\n\n const isEnabled =\n isEnabledOption &&\n isUserEnabled &&\n isProjectEnabled &&\n isOrganizationEnabled;\n\n return {\n ...options,\n enable: isEnabled,\n };\n};\n\nconst useAppAsync = <\n U extends string,\n T extends (...args: any[]) => Promise<any>,\n>(\n key: U,\n asyncFunction: T,\n options?: UseAsyncOptions<T>,\n authOptions?: AuthEnableOptions\n) => {\n // Enhance options using custom hooks\n const optionsWithAuth = useAuthEnable(options ?? {}, authOptions);\n\n const optionsWithErrorHandling = useErrorHandling(optionsWithAuth);\n\n // Call the main useAsync hook with enhanced options\n return useAsync(key, asyncFunction, optionsWithErrorHandling);\n};\n\nconst useEditorAsync = <\n U extends string,\n T extends (...args: any[]) => Promise<any>,\n>(\n key: U,\n asyncFunction: T,\n options?: UseAsyncOptions<T>\n) => {\n const optionsWithErrorHandling = useErrorHandling(options ?? {});\n\n // Call the main useAsync hook with enhanced options\n return useAsync(key, asyncFunction, optionsWithErrorHandling);\n};\n\n/**\n * Auth\n */\n\nexport const useLogin = (\n args?: UseAsyncOptions<IntlayerAPI['auth']['signInEmail']>\n) =>\n useAppAsync('login', useIntlayerAuth().auth.signInEmail, {\n invalidateQueries: ['getSession'],\n ...args,\n });\n\nexport const useRegister = (\n args?: UseAsyncOptions<IntlayerAPI['auth']['signUpEmail']>\n) =>\n useAppAsync('register', useIntlayerAuth().auth.signUpEmail, {\n invalidateQueries: ['getSession'],\n ...args,\n });\n\nexport const useLogout = (\n args?: UseAsyncOptions<IntlayerAPI['auth']['signOut']>\n) =>\n useAppAsync('logout', useIntlayerAuth().auth.signOut, {\n ...args,\n });\n\nexport const useChangePassword = (\n args?: UseAsyncOptions<IntlayerAPI['auth']['changePasswordSession']>\n) =>\n useAppAsync(\n 'changePassword',\n useIntlayerAuth().auth.changePasswordSession,\n args\n );\n\nexport const useAskResetPassword = (\n args?: UseAsyncOptions<IntlayerAPI['auth']['requestPasswordResetSession']>\n) =>\n useAppAsync(\n 'askResetPassword',\n useIntlayerAuth().auth.requestPasswordResetSession,\n args\n );\n\nexport const useDefineNewPassword = (\n args?: UseAsyncOptions<IntlayerAPI['auth']['changePasswordSession']>\n) =>\n useAppAsync(\n 'defineNewPassword',\n useIntlayerAuth().auth.changePasswordSession,\n args\n );\n\nexport const useVerifyEmail = (\n args?: UseAsyncOptions<IntlayerAPI['auth']['verifyEmailSession']>\n) =>\n useAppAsync('verifyEmail', useIntlayerAuth().auth.verifyEmailSession, args);\n\nexport const useGetUserByAccount = (\n args?: UseAsyncOptions<IntlayerAPI['auth']['accountInfo']>\n) => useAppAsync('getUserByAccount', useIntlayerAuth().auth.accountInfo, args);\n\n/**\n * User\n */\n\nexport const useGetUsers = (\n args?: UseAsyncOptions<IntlayerAPI['user']['getUsers']>\n) =>\n useAppAsync(\n 'getUsers',\n useIntlayerAuth().user.getUsers,\n {\n cache: true,\n store: true,\n retryLimit: 3,\n autoFetch: true,\n revalidateTime: 5 * 60 * 1000, // 5 minutes\n ...args,\n },\n {\n requireUser: true,\n }\n );\n\nexport const useCreateUser = (\n args?: UseAsyncOptions<IntlayerAPI['auth']['updateUser']>\n) =>\n useAppAsync('createUser', useIntlayerAuth().auth.updateUser, {\n invalidateQueries: ['getUsers'],\n ...args,\n });\n\nexport const useUpdateUser = (\n args?: UseAsyncOptions<IntlayerAPI['user']['updateUser']>\n) =>\n useAppAsync('updateUser', useIntlayerAuth().user.updateUser, {\n invalidateQueries: ['getSession'],\n ...args,\n });\n\nexport const useDeleteUser = (\n args?: UseAsyncOptions<IntlayerAPI['user']['deleteUser']>\n) =>\n useAppAsync('deleteUser', useIntlayerAuth().user.deleteUser, {\n invalidateQueries: ['getUsers'],\n ...args,\n });\n\n/**\n * Organization\n */\n\nexport const useGetOrganizations = (\n args?: UseAsyncOptions<IntlayerAPI['organization']['getOrganizations']>\n) =>\n useAppAsync(\n 'getOrganizations',\n useIntlayerAuth().organization.getOrganizations,\n {\n cache: true,\n store: true,\n retryLimit: 3,\n autoFetch: true,\n revalidation: true,\n revalidateTime: 5 * 60 * 1000, // 5 minutes\n ...args,\n },\n {\n requireUser: true,\n }\n );\n\nexport const useAddOrganization = (\n args?: UseAsyncOptions<IntlayerAPI['organization']['addOrganization']>\n) =>\n useAppAsync(\n 'addOrganization',\n useIntlayerAuth().organization.addOrganization,\n {\n invalidateQueries: ['getOrganizations'],\n ...args,\n }\n );\n\nexport const useUpdateOrganization = (\n args?: UseAsyncOptions<IntlayerAPI['organization']['updateOrganization']>\n) =>\n useAppAsync(\n 'updateOrganization',\n useIntlayerAuth().organization.updateOrganization,\n {\n invalidateQueries: ['getSession'],\n ...args,\n }\n );\n\nexport const useUpdateOrganizationMembers = (\n args?: UseAsyncOptions<\n IntlayerAPI['organization']['updateOrganizationMembers']\n >\n) =>\n useAppAsync(\n 'updateOrganizationMembers',\n useIntlayerAuth().organization.updateOrganizationMembers,\n {\n invalidateQueries: ['getOrganizations', 'getSession'],\n ...args,\n }\n );\n\nexport const useAddOrganizationMember = (\n args?: UseAsyncOptions<IntlayerAPI['organization']['addOrganizationMember']>\n) =>\n useAppAsync(\n 'addOrganizationMember',\n useIntlayerAuth().organization.addOrganizationMember,\n {\n invalidateQueries: ['getOrganizations', 'getSession'],\n ...args,\n }\n );\n\nexport const useDeleteOrganization = (\n args?: UseAsyncOptions<IntlayerAPI['organization']['deleteOrganization']>\n) =>\n useAppAsync(\n 'deleteOrganization',\n useIntlayerAuth().organization.deleteOrganization,\n {\n invalidateQueries: ['getOrganizations', 'getSession'],\n ...args,\n }\n );\n\nexport const useSelectOrganization = (\n args?: UseAsyncOptions<IntlayerAPI['organization']['selectOrganization']>\n) =>\n useAppAsync(\n 'selectOrganization',\n useIntlayerAuth().organization.selectOrganization,\n {\n invalidateQueries: ['getSession'],\n ...args,\n }\n );\n\nexport const useUnselectOrganization = (\n args?: UseAsyncOptions<IntlayerAPI['organization']['unselectOrganization']>\n) =>\n useAppAsync(\n 'unselectOrganization',\n useIntlayerAuth().organization.unselectOrganization,\n {\n invalidateQueries: ['getSession'],\n ...args,\n }\n );\n\n/**\n * Project\n */\n\nexport const useGetProjects = (\n args?: UseAsyncOptions<IntlayerAPI['project']['getProjects']>\n) =>\n useAppAsync(\n 'getProjects',\n useIntlayerAuth().project.getProjects,\n {\n cache: true,\n store: true,\n retryLimit: 3,\n autoFetch: true,\n revalidation: true,\n revalidateTime: 5 * 60 * 1000, // 5 minutes\n ...args,\n },\n {\n requireUser: true,\n requireOrganization: true,\n }\n );\n\nexport const useAddProject = (\n args?: UseAsyncOptions<IntlayerAPI['project']['addProject']>\n) =>\n useAppAsync('addProject', useIntlayerAuth().project.addProject, {\n invalidateQueries: ['getProjects'],\n ...args,\n });\n\nexport const useUpdateProject = (\n args?: UseAsyncOptions<IntlayerAPI['project']['updateProject']>\n) =>\n useAppAsync('updateProject', useIntlayerAuth().project.updateProject, {\n invalidateQueries: ['getSession'],\n ...args,\n });\n\nexport const useUpdateProjectMembers = (\n args?: UseAsyncOptions<IntlayerAPI['project']['updateProjectMembers']>\n) =>\n useAppAsync(\n 'updateProjectMembers',\n useIntlayerAuth().project.updateProjectMembers,\n {\n invalidateQueries: ['getSession'],\n ...args,\n }\n );\n\nexport const useDeleteProject = (\n args?: UseAsyncOptions<IntlayerAPI['project']['deleteProject']>\n) =>\n useAppAsync('deleteProject', useIntlayerAuth().project.deleteProject, {\n invalidateQueries: ['getProjects', 'getSession'],\n ...args,\n });\n\nexport const useSelectProject = (\n args?: UseAsyncOptions<IntlayerAPI['project']['selectProject']>\n) =>\n useAppAsync('selectProject', useIntlayerAuth().project.selectProject, {\n invalidateQueries: ['getSession'],\n ...args,\n });\n\nexport const useUnselectProject = (\n args?: UseAsyncOptions<IntlayerAPI['project']['unselectProject']>\n) =>\n useAppAsync('unselectProject', useIntlayerAuth().project.unselectProject, {\n invalidateQueries: ['getSession'],\n ...args,\n });\n\nexport const useAddNewAccessKey = (\n args?: UseAsyncOptions<IntlayerAPI['project']['addNewAccessKey']>\n) =>\n useAppAsync('addNewAccessKey', useIntlayerAuth().project.addNewAccessKey, {\n invalidateQueries: ['getSession'],\n ...args,\n });\n\nexport const useDeleteAccessKey = (\n args?: UseAsyncOptions<IntlayerAPI['project']['deleteAccessKey']>\n) =>\n useAppAsync('deleteAccessKey', useIntlayerAuth().project.deleteAccessKey, {\n invalidateQueries: ['getSession'],\n ...args,\n });\n\nexport const useRefreshAccessKey = (\n args?: UseAsyncOptions<IntlayerAPI['project']['refreshAccessKey']>\n) =>\n useAppAsync('refreshAccessKey', useIntlayerAuth().project.refreshAccessKey, {\n invalidateQueries: ['getSession'],\n ...args,\n });\n\n/**\n * Dictionary\n */\n\nexport const useGetDictionaries = (\n args?: UseAsyncOptions<IntlayerAPI['dictionary']['getDictionaries']>\n) =>\n useAppAsync(\n 'getDictionaries',\n useIntlayerAuth().dictionary.getDictionaries,\n {\n cache: true,\n store: true,\n retryLimit: 3,\n autoFetch: true,\n revalidation: true,\n revalidateTime: 5 * 60 * 1000, // 5 minutes\n ...args,\n },\n {\n requireUser: true,\n requireOrganization: true,\n requireProject: true,\n }\n );\n\nexport const useGetDictionariesKeys = (\n args?: UseAsyncOptions<IntlayerAPI['dictionary']['getDictionariesKeys']>\n) =>\n useAppAsync(\n 'getDictionariesKeys',\n useIntlayerAuth().dictionary.getDictionariesKeys,\n {\n cache: true,\n store: true,\n retryLimit: 3,\n autoFetch: true,\n revalidation: true,\n revalidateTime: 5 * 60 * 1000, // 5 minutes\n ...args,\n },\n {\n requireUser: true,\n requireOrganization: true,\n requireProject: true,\n }\n );\n\nexport const useGetDictionary = (\n args?: UseAsyncOptions<IntlayerAPI['dictionary']['getDictionary']>\n) =>\n useAppAsync(\n 'getDictionary',\n useIntlayerAuth().dictionary.getDictionary,\n {\n cache: true,\n store: true,\n retryLimit: 3,\n revalidation: true,\n revalidateTime: 5 * 60 * 1000, // 5 minutes\n ...args,\n },\n {\n requireUser: true,\n requireOrganization: true,\n requireProject: true,\n }\n );\n\nexport const useAddDictionary = (\n args?: UseAsyncOptions<IntlayerAPI['dictionary']['addDictionary']>\n) =>\n useAppAsync('addDictionary', useIntlayerAuth().dictionary.addDictionary, {\n invalidateQueries: ['getDictionaries', 'getDictionariesKeys'],\n ...args,\n });\n\nexport const usePushDictionaries = (\n args?: UseAsyncOptions<IntlayerAPI['dictionary']['pushDictionaries']>\n) =>\n useAppAsync(\n 'pushDictionaries',\n useIntlayerAuth().dictionary.pushDictionaries,\n {\n invalidateQueries: [\n 'getDictionaries',\n 'getDictionary',\n 'getDictionariesKeys',\n ],\n ...args,\n }\n );\n\nexport const useUpdateDictionary = (\n args?: UseAsyncOptions<IntlayerAPI['dictionary']['updateDictionary']>\n) =>\n useAppAsync(\n 'updateDictionary',\n useIntlayerAuth().dictionary.updateDictionary,\n {\n invalidateQueries: ['getDictionaries', 'getDictionary'],\n ...args,\n }\n );\n\nexport const useDeleteDictionary = (\n args?: UseAsyncOptions<IntlayerAPI['dictionary']['deleteDictionary']>\n) =>\n useAppAsync(\n 'deleteDictionary',\n useIntlayerAuth().dictionary.deleteDictionary,\n {\n invalidateQueries: [\n 'getDictionaries',\n 'getDictionary',\n 'getDictionariesKeys',\n ],\n ...args,\n }\n );\n\n/**\n * Tag\n */\n\nexport const useGetTags = (\n args?: UseAsyncOptions<IntlayerAPI['tag']['getTags']>\n) =>\n useAppAsync(\n 'getTags',\n useIntlayerAuth().tag.getTags,\n {\n cache: true,\n store: true,\n retryLimit: 3,\n autoFetch: true,\n revalidation: true,\n revalidateTime: 5 * 60 * 1000, // 5 minutes\n ...args,\n },\n {\n requireUser: true,\n requireOrganization: true,\n }\n );\n\nexport const useAddTag = (\n args?: UseAsyncOptions<IntlayerAPI['tag']['addTag']>\n) =>\n useAppAsync('addTag', useIntlayerAuth().tag.addTag, {\n invalidateQueries: ['getTags'],\n ...args,\n });\n\nexport const useUpdateTag = (\n args?: UseAsyncOptions<IntlayerAPI['tag']['updateTag']>\n) =>\n useAppAsync('updateTag', useIntlayerAuth().tag.updateTag, {\n invalidateQueries: ['getTags'],\n ...args,\n });\n\nexport const useDeleteTag = (\n args?: UseAsyncOptions<IntlayerAPI['tag']['deleteTag']>\n) =>\n useAppAsync('deleteTag', useIntlayerAuth().tag.deleteTag, {\n invalidateQueries: ['getTags'],\n ...args,\n });\n\n/**\n * Stripe\n */\n\nexport const useGetPricing = (\n args?: UseAsyncOptions<IntlayerAPI['stripe']['getPricing']>\n) =>\n useAppAsync('getPricing', useIntlayerAuth().stripe.getPricing, {\n store: true,\n cache: true,\n ...args,\n });\n\nexport const useGetSubscription = (\n args?: UseAsyncOptions<IntlayerAPI['stripe']['getSubscription']>\n) =>\n useAppAsync(\n 'getSubscription',\n useIntlayerAuth().stripe.getSubscription,\n args,\n {\n requireUser: true,\n requireOrganization: true,\n }\n );\n\nexport const useCancelSubscription = (\n args?: UseAsyncOptions<IntlayerAPI['stripe']['cancelSubscription']>\n) =>\n useAppAsync(\n 'cancelSubscription',\n useIntlayerAuth().stripe.cancelSubscription,\n { invalidateQueries: ['getSession'], ...args },\n {\n requireUser: true,\n requireOrganization: true,\n }\n );\n\n/**\n * AI\n */\n\nexport const useTranslateJSONDeclaration = (\n args?: UseAsyncOptions<IntlayerAPI['ai']['translateJSON']>\n) =>\n useAppAsync('translateJSON', useIntlayerAuth().ai.translateJSON, args, {\n requireUser: true,\n requireOrganization: true,\n requireProject: true,\n });\n\nexport const useAuditContentDeclaration = (\n args?: UseAsyncOptions<IntlayerAPI['ai']['auditContentDeclaration']>\n) =>\n useAppAsync(\n 'auditContentDeclaration',\n useIntlayerAuth().ai.auditContentDeclaration,\n args,\n {\n requireUser: true,\n requireOrganization: true,\n requireProject: true,\n }\n );\n\nexport const useAuditContentDeclarationMetadata = (\n args?: UseAsyncOptions<IntlayerAPI['ai']['auditContentDeclarationMetadata']>\n) =>\n useAppAsync(\n 'auditContentDeclaration',\n useIntlayerAuth().ai.auditContentDeclarationMetadata,\n args,\n {\n requireUser: true,\n requireOrganization: true,\n requireProject: true,\n }\n );\n\nexport const useAuditContentDeclarationField = (\n args?: UseAsyncOptions<IntlayerAPI['ai']['auditContentDeclarationField']>\n) =>\n useAppAsync(\n 'auditContentDeclarationField',\n useIntlayerAuth().ai.auditContentDeclarationField,\n args,\n {\n requireUser: true,\n requireOrganization: true,\n requireProject: true,\n }\n );\n\nexport const useAuditTag = (\n args?: UseAsyncOptions<IntlayerAPI['ai']['auditTag']>\n) =>\n useAppAsync('auditTag', useIntlayerAuth().ai.auditTag, args, {\n requireUser: true,\n requireOrganization: true,\n requireProject: true,\n });\n\nexport const useAskDocQuestion = (\n args?: UseAsyncOptions<IntlayerAPI['ai']['askDocQuestion']>\n) => useAppAsync('askDocQuestion', useIntlayerAuth().ai.askDocQuestion, args);\n\nexport const useAutocomplete = (\n args?: UseAsyncOptions<IntlayerAPI['ai']['autocomplete']>\n) => useAppAsync('autocomplete', useIntlayerAuth().ai.autocomplete, args);\n\n/**\n * Search\n */\n\nexport const useSearchDoc = (\n args?: UseAsyncOptions<IntlayerAPI['search']['searchDoc']>\n) => useAppAsync('searchDoc', useIntlayerAuth().search.searchDoc, args);\n\n/**\n * Newsletter\n */\n\nexport const useSubscribeToNewsletter = (\n args?: UseAsyncOptions<IntlayerAPI['newsletter']['subscribeToNewsletter']>\n) =>\n useAppAsync(\n 'subscribeToNewsletter',\n useIntlayerAuth().newsletter.subscribeToNewsletter,\n args\n );\n\nexport const useUnsubscribeFromNewsletter = (\n args?: UseAsyncOptions<IntlayerAPI['newsletter']['unsubscribeFromNewsletter']>\n) =>\n useAppAsync(\n 'unsubscribeFromNewsletter',\n useIntlayerAuth().newsletter.unsubscribeFromNewsletter,\n args\n );\n\nexport const useGetNewsletterStatus = (\n args?: UseAsyncOptions<IntlayerAPI['newsletter']['getNewsletterStatus']>\n) =>\n useAppAsync(\n 'getNewsletterStatus',\n useIntlayerAuth().newsletter.getNewsletterStatus,\n args\n );\n\n/**\n * Editor\n */\n\nexport const useWriteDictionary = (\n args?: UseAsyncOptions<IntlayerAPI['editor']['writeDictionary']>\n) =>\n useEditorAsync(\n 'writeDictionary',\n useIntlayerAuth().editor.writeDictionary,\n args\n );\n\nexport const useGetEditorDictionaries = (\n args?: UseAsyncOptions<IntlayerAPI['editor']['getDictionaries']>\n) =>\n useEditorAsync('getDictionaries', useIntlayerAuth().editor.getDictionaries, {\n store: true,\n cache: true,\n ...args,\n });\n"],"names":["error"],"mappings":";;;;;;;;;;;;AASA,MAAM,kBAAkB,CAAC,cAAsB,UAAU,MAAM,GAAG,EAAE,KAAK,GAAG;AAK5E,MAAM,mBAAmB,CAAiC,YAAkB;AACpE,QAAA,EAAE,MAAM,IAAI,SAAS;AAEpB,SAAA;AAAA,IACL,GAAG;AAAA,IACH,SAAS,CAAC,iBAAiB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AAkB,kBAAkB,GAAG,gBAAgB,IAAI;AAE/D,MAAA,kBAAkB,CAC7B,SACG,YAAY,gBAAgB,kBAAkB,GAAG,cAAc,IAAI;AAM3D,MAAA,eAAe,CAC1B,SACG,YAAY,aAAa,kBAAkB,OAAO,WAAW,IAAI;AAMzD,MAAA,2BAA2B,CACtC,SAEA;AAAA,EACE;AAAA,EACA,gBAAA,EAAkB,WAAW;AAAA,EAC7B;AACF;AAEW,MAAA,+BAA+B,CAC1C,SAEA;AAAA,EACE;AAAA,EACA,gBAAA,EAAkB,WAAW;AAAA,EAC7B;AACF;AAEW,MAAA,yBAAyB,CACpC,SAEA;AAAA,EACE;AAAA,EACA,gBAAA,EAAkB,WAAW;AAAA,EAC7B;AACF;AAMW,MAAA,qBAAqB,CAChC,SAEA;AAAA,EACE;AAAA,EACA,gBAAA,EAAkB,OAAO;AAAA,EACzB;AACF;AAEW,MAAA,2BAA2B,CACtC,SAEA,eAAe,mBAAmB,gBAAgB,EAAE,OAAO,iBAAiB;AAAA,EAC1E,OAAO;AAAA,EACP,OAAO;AAAA,EACP,GAAG;AACL,CAAC;"}
@@ -88,7 +88,6 @@ const useAsync = (key, asyncFunction, options) => {
88
88
  localStorage.setItem(keyWithArgs2, JSON.stringify(result));
89
89
  }
90
90
  } catch (error2) {
91
- console.error({ error: error2 });
92
91
  const msg = error2 instanceof Error ? error2.message : String(error2);
93
92
  makeQueryInError(keyWithArgs2, msg);
94
93
  onError?.(msg);
@@ -1 +1 @@
1
- {"version":3,"file":"useAsync.cjs","sources":["../../../src/hooks/useAsync/useAsync.ts"],"sourcesContent":["'use client';\n\nimport { useEffect, useRef } from 'react';\nimport { useAsyncState } from './useAsyncStateStore';\n\n// Pending promises cache to prevent parallel requests when multiple components use the hook\nconst pendingPromises = new Map();\n\n// Defines the base structure for the result of the custom hook.\ntype UseAsyncResultBase<T extends (...args: any[]) => Promise<any>> = {\n isFetched: boolean;\n isLoading: boolean;\n isInvalidated: boolean;\n isSuccess: boolean;\n isDisabled: boolean;\n isWaitingData: boolean;\n isRevalidating: boolean;\n error: string | null;\n data: Awaited<ReturnType<T>> | null;\n errorCount: number;\n revalidate: T;\n setData: (data: Awaited<ReturnType<T> | null>) => void;\n abort: () => void;\n};\n\n// Options type for the hook, allowing customization of behavior.\nexport type UseAsyncOptions<T extends (...args: any[]) => Promise<any>> = {\n retryLimit?: number; // The number of times the hook should retry the function on failure before giving up\n retryTime?: number; // Time in milliseconds for retrying the data\n cache?: boolean; // Cache the result of the function\n store?: boolean; // Store the result of the function in local storage\n enable?: boolean; // Enable the hook\n autoFetch?: boolean; // Automatically fetch the data when the hook is mounted\n revalidation?: boolean; // Enable revalidation\n revalidateTime?: number; // Time in milliseconds for revalidating the data\n invalidateQueries?: string[]; // Invalidate other queries when the data is updated\n updateQueries?: string[]; // Update other queries when the data is updated\n onSuccess?: (data: Awaited<ReturnType<T>>) => void; // Callback function that is called when the asynchronous function resolves successfully\n onError?: (error: string) => void; // Callback function that is called when the asynchronous function rejects or encounters an error\n abort?: () => void; // Abort the request\n args?: Parameters<T>; // Arguments to pass to the asynchronous function\n};\n\n// Default values for the hook's options\nconst DEFAULT_CACHE_ENABLED = false;\nconst DEFAULT_STORE_ENABLED = false;\nconst DEFAULT_ENABLED = true;\nconst DEFAULT_AUTO_FETCH = false;\nconst DEFAULT_RETRY_LIMIT = 1;\nconst DEFAULT_REVALIDATION_ENABLED = false;\nconst DEFAULT_REVALIDATE_TIME = 5 * 60 * 1000; // 5 minutes\nconst DEFAULT_RETRY_TIME = 5 * 60 * 1000; // 5 minutes\n\n// The main hook type that includes the async function along with its additional properties.\nexport type UseAsyncResult<\n U extends string,\n T extends (...args: any[]) => Promise<any>,\n> = UseAsyncResultBase<T> & Record<U, T>;\n\nconst getArgs = (args?: any[]): any[] =>\n args ? (Array.isArray(args) ? args : [args]) : [];\n\nconst getKeyWithArgs = (key: string, args: any[]) =>\n getArgs(args).length > 0 ? `${key}/${JSON.stringify(args)}` : key;\n\n/**\n * A custom React hook that manages asynchronous operations, providing easy-to-use states and controls over fetching, caching, and retry mechanisms.\n * This hook abstracts away the complexity of handling loading, error, and success states for any asynchronous function.\n *\n *\n * ```tsx\n * // Example of using useAsync to manage fetching user data from an API.\n * const fetchUserData = async (userId) => {\n * const response = await fetch(`/api/users/${userId}`);\n * if (!response.ok) throw new Error('Failed to fetch');\n * return await response.json();\n * };\n *\n * const UserDetails = ({ userId }) => {\n * const {\n * isLoading,\n * data,\n * error,\n * revalidate,\n * } = useAsync('userDetails', fetchUserData, {\n * cache: true,\n * revalidateTime: 60000, // 1 minute\n * autoFetch: true,\n * onSuccess: (data) => console.log('User data fetched successfully:', data),\n * onError: (error) => console.error('Error fetching user data:', error),\n * });\n *\n * if (isLoading) return <div>Loading...</div>;\n * if (error) return <div>Error: {error}</div>;\n * return (\n * <div>\n * <h1>{data.name}</h1>\n * <button onClick={() => revalidate()}>Refresh</button>\n * </div>\n * );\n * };\n * ```\n */\nexport const useAsync = <\n U extends string,\n T extends (...args: any[]) => Promise<any>,\n>(\n key: U,\n asyncFunction: T,\n options?: UseAsyncOptions<T>\n): UseAsyncResult<U, T> => {\n // Resolving optional parameters with default values\n const retryLimit = options?.retryLimit ?? DEFAULT_RETRY_LIMIT;\n const autoFetch = options?.autoFetch ?? DEFAULT_AUTO_FETCH;\n const retryTime = options?.retryTime ?? DEFAULT_RETRY_TIME;\n const cacheEnabled = options?.cache ?? DEFAULT_CACHE_ENABLED;\n const storeEnabled = options?.store ?? DEFAULT_STORE_ENABLED;\n const enabled = options?.enable ?? DEFAULT_ENABLED;\n const revalidationEnabled =\n options?.revalidation ?? DEFAULT_REVALIDATION_ENABLED;\n const revalidateTime = options?.revalidateTime ?? DEFAULT_REVALIDATE_TIME;\n const updateQueries = options?.updateQueries ?? [];\n const invalidateQueries = options?.invalidateQueries ?? [];\n const onSuccess = options?.onSuccess;\n const onError = options?.onError;\n const args = getArgs(options?.args ?? []);\n\n // Using a custom hook to manage state specific to asynchronous operations\n const { getStates, setQueryState, setQueriesState, makeQueryInError } =\n useAsyncState();\n\n // Storing the last arguments used to call the async function\n const storedArgsRef = useRef<any[]>(args);\n\n const controllerRef = useRef<AbortController | null>(null);\n\n // Apply different key for different requests\n const keyWithArgs = getKeyWithArgs(key, storedArgsRef.current);\n\n // Retrieving the current state of async operations using the same custom hook\n const {\n isFetched,\n fetchedDateTime,\n isLoading,\n isEnabled,\n error,\n isSuccess,\n isInvalidated,\n data,\n errorCount,\n } = getStates(keyWithArgs);\n\n /**\n * FETCH FUNCTION\n *\n * Manage parallel fetching across multiple instances of the hook\n * Manage state updates on success and error\n * Manage eventual invalidation of other queries\n */\n const fetch: T = (async (...args) => {\n const keyWithArgs = getKeyWithArgs(key, args);\n\n /**\n * ABORT CONTROLLER\n *\n * cancel an unnecessary request.\n * For example, if a user navigates away from a page or triggers a new request that makes the previous one obsolete, you can abort the previous fetch\n */\n if (controllerRef.current) {\n // Abort the previous request\n controllerRef.current.abort();\n }\n\n // Create a new AbortController\n const controller = new AbortController();\n controllerRef.current = controller;\n\n /**\n * PENDING PROMISES\n *\n * This logic ensures that if two parts of your application trigger the same request simultaneously,\n * only one network call is made, and both receive the same result.\n */\n if (pendingPromises.has(keyWithArgs)) {\n // Return the existing pending promise\n return pendingPromises.get(keyWithArgs);\n }\n\n const promise = (async () => {\n setQueryState(keyWithArgs, { isLoading: true });\n let response = null;\n\n try {\n // Ensure asyncFunction returns a Promise\n const asyncResult = asyncFunction(...args);\n\n // Check if the result is a Promise-like object\n if (!asyncResult || typeof asyncResult.then !== 'function') {\n throw new Error('asyncFunction must return a Promise');\n }\n\n const result = await asyncResult;\n response = result;\n\n setQueryState(keyWithArgs, {\n data: result,\n errorCount: 0,\n isLoading: false,\n isFetched: true,\n fetchedDateTime: new Date(),\n isSuccess: true,\n isInvalidated: false,\n error: null,\n });\n\n onSuccess?.(result);\n\n // Invalidate other queries if necessary\n if (invalidateQueries.length > 0) {\n setQueriesState(invalidateQueries, {\n isInvalidated: true,\n });\n }\n\n // Update other queries if necessary\n if (updateQueries.length > 0) {\n setQueriesState(updateQueries, {\n data: result,\n });\n }\n\n // Store the result in local storage\n if (storeEnabled) {\n localStorage.setItem(keyWithArgs, JSON.stringify(result));\n }\n } catch (error) {\n console.error({ error });\n const msg = error instanceof Error ? error.message : String(error);\n\n makeQueryInError(keyWithArgs, msg);\n onError?.(msg);\n } finally {\n // Remove the pending promise from the cache\n pendingPromises.delete(keyWithArgs);\n }\n\n return response;\n })();\n\n // Store the pending promise in the cache\n pendingPromises.set(keyWithArgs, promise);\n\n return await promise;\n }) as T;\n\n /**\n * REVALIDATE FUNCTION\n *\n * Wrap core function to handle revalidation\n * Handle arguments caching\n *\n */\n const revalidate: T = (async (...args) => {\n if (!isEnabled || !enabled) return; // Hook is disabled\n\n if (args) {\n // Revalidation arguments can be different from the initial fetch arguments\n // If arguments are provided, store/update them for future periodic revalidation\n\n storedArgsRef.current = getArgs(args);\n }\n\n return await fetch(...storedArgsRef.current);\n }) as T;\n\n /**\n * EXECUTION FUNCTION\n *\n * Wrap revalidation function\n * If data is valid return it directly to avoid fetching again\n */\n const execute: T = (async (...args) => {\n if (!isEnabled || !enabled) return; // Hook is disabled\n if (isLoading) return; // Fetch is already in progress\n\n const shouldReturnData =\n !isInvalidated && // If data are invalidated, we should refetch to revalidate the data\n isSuccess &&\n cacheEnabled &&\n data;\n\n if (shouldReturnData) return data; // Data are already fetched and should be returned directly. Avoid fetching again.\n\n return await revalidate(...args);\n }) as T;\n\n /**\n * HANDLE SYNCHRONIZATION HOOKS DISACTIVATION\n *\n * If one instance of the hook is disabled, the other instances should be disabled too.\n * This is to prevent inconsistencies in the state of the hook.\n */\n useEffect(() => {\n if (enabled !== isEnabled) {\n setQueryState(keyWithArgs, {\n isEnabled,\n });\n }\n }, [enabled, isEnabled, keyWithArgs]);\n\n /**\n * HANDLE LOCAL STORAGE LOADING\n *\n * If store is enabled, load data from local storage\n */\n useEffect(() => {\n if (!isEnabled || !enabled) return; // Hook is disabled\n if (!storeEnabled) return; // Hook should not use local storage\n if (isInvalidated || isFetched || data) return; // Hook have been already mounted and fetched or invalidated\n\n const storedData = localStorage.getItem(keyWithArgs);\n\n // Wrap parsing in a try-catch block to handle invalid JSON data\n try {\n if (storedData) {\n setQueryState(keyWithArgs, {\n data: JSON.parse(storedData),\n });\n }\n } catch (error) {\n console.error(error);\n }\n }, [\n storeEnabled,\n keyWithArgs,\n isFetched,\n isInvalidated,\n isEnabled,\n enabled,\n data,\n ]);\n\n /**\n * HANDLE AUTO-FETCH ON HOOK MOUNT\n *\n * If autoFetch is enabled, fetch the data when the hook is mounted\n */\n useEffect(() => {\n if (!autoFetch) return; // Auto-fetch is disabled\n if (!isEnabled || !enabled) return; // Hook is disabled\n if (isFetched && !isInvalidated) return; // Hook have already fetched or invalidated\n if (isLoading) return; // Fetch is already in progress\n\n fetch(...storedArgsRef.current);\n }, [\n autoFetch,\n isEnabled,\n enabled,\n isFetched,\n isInvalidated,\n isLoading,\n fetch,\n ]);\n\n /**\n * HANDLE RETRY\n *\n * If fetching fails, retry the fetch after a certain time\n */\n useEffect(() => {\n const isRetryEnabled = errorCount > 0 && retryLimit > 0;\n const isRetryLimitReached = errorCount > retryLimit;\n\n if (!isEnabled || !enabled) return; // Hook is disabled\n if (!isRetryEnabled) return; // Retry is disabled\n if (isRetryLimitReached) return; // Retry limit has been reached\n if (isLoading) return; // Fetch is already in progress\n if (isSuccess) return; // Hook has already fetched successfully\n\n const timeout = setTimeout(() => {\n fetch(...storedArgsRef.current);\n }, retryTime);\n\n return () => clearTimeout(timeout);\n }, [\n isEnabled,\n errorCount,\n retryLimit,\n enabled,\n retryTime,\n isSuccess,\n isLoading,\n fetch,\n ]);\n\n /**\n * HANDLE PERIODIC REVALIDATION\n *\n * If revalidation is enabled, revalidate the data periodically\n */\n useEffect(() => {\n if (!revalidationEnabled || revalidateTime <= 0) return; // Revalidation is disabled\n if (!isEnabled || !enabled) return; // Hook is disabled\n if (isLoading) return; // Fetch is already in progress\n if (!isSuccess || !fetchedDateTime) return; // Should retry either of revalidate\n\n const timeout = setTimeout(() => {\n fetch(...storedArgsRef.current);\n }, revalidateTime);\n\n return () => clearTimeout(timeout);\n }, [\n revalidationEnabled,\n revalidateTime,\n isSuccess,\n fetchedDateTime,\n isLoading,\n isEnabled,\n enabled,\n fetch,\n ]);\n\n // Memoization of the setData function to prevent unnecessary re-renders\n const setDataMemo = (data: Awaited<ReturnType<T> | null>) => {\n setQueryState(keyWithArgs, {\n data,\n });\n };\n\n const abort = () => {\n if (controllerRef.current) {\n controllerRef.current.abort();\n }\n };\n\n // Memoization to prevent unnecessary re-renders\n const memoResult = {\n isFetched,\n isInvalidated,\n error,\n data,\n errorCount,\n isSuccess,\n isEnabled,\n isDisabled: !isEnabled,\n isLoading,\n isWaitingData: isLoading && !isFetched && !data, // Check if the data is still being fetched. Stay at true during revalidation or if data are stored in local storage\n isRevalidating: isLoading && isFetched, // Check if the data is valid and is being revalidated\n [key]: execute, // Name the execute function as the given key to avoid conflicts with other hooks (e.g. `const { fetchUser } = useAsync('fetchUser', () => fetchUserFunction());`)\n revalidate,\n setData: setDataMemo,\n abort,\n };\n\n useEffect(\n () => () => {\n // Clean up the controller on unmount\n if (controllerRef.current) {\n controllerRef.current.abort();\n }\n },\n []\n );\n\n // Return the hook's result, including all state and control functions\n return memoResult as UseAsyncResultBase<T> & Record<U, T>;\n};\n"],"names":["useAsyncState","useRef","args","keyWithArgs","error","useEffect","data"],"mappings":";;;;;AAMA,MAAM,sCAAsB,IAAI;AAsChC,MAAM,wBAAwB;AAC9B,MAAM,wBAAwB;AAC9B,MAAM,kBAAkB;AACxB,MAAM,qBAAqB;AAC3B,MAAM,sBAAsB;AAC5B,MAAM,+BAA+B;AACrC,MAAM,0BAA0B,IAAI,KAAK;AACzC,MAAM,qBAAqB,IAAI,KAAK;AAQpC,MAAM,UAAU,CAAC,SACf,OAAQ,MAAM,QAAQ,IAAI,IAAI,OAAO,CAAC,IAAI,IAAK,CAAC;A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S;AACzB,sBAAc,QAAQ,MAAM;AAAA,MAAA;AAAA,IAEhC;AAAA,IACA,CAAA;AAAA,EACF;AAGO,SAAA;AACT;;"}
1
+ {"version":3,"file":"useAsync.cjs","sources":["../../../src/hooks/useAsync/useAsync.ts"],"sourcesContent":["'use client';\n\nimport { useEffect, useRef } from 'react';\nimport { useAsyncState } from './useAsyncStateStore';\n\n// Pending promises cache to prevent parallel requests when multiple components use the hook\nconst pendingPromises = new Map();\n\n// Defines the base structure for the result of the custom hook.\ntype UseAsyncResultBase<T extends (...args: any[]) => Promise<any>> = {\n isFetched: boolean;\n isLoading: boolean;\n isInvalidated: boolean;\n isSuccess: boolean;\n isDisabled: boolean;\n isWaitingData: boolean;\n isRevalidating: boolean;\n error: string | null;\n data: Awaited<ReturnType<T>> | null;\n errorCount: number;\n revalidate: T;\n setData: (data: Awaited<ReturnType<T> | null>) => void;\n abort: () => void;\n};\n\n// Options type for the hook, allowing customization of behavior.\nexport type UseAsyncOptions<T extends (...args: any[]) => Promise<any>> = {\n retryLimit?: number; // The number of times the hook should retry the function on failure before giving up\n retryTime?: number; // Time in milliseconds for retrying the data\n cache?: boolean; // Cache the result of the function\n store?: boolean; // Store the result of the function in local storage\n enable?: boolean; // Enable the hook\n autoFetch?: boolean; // Automatically fetch the data when the hook is mounted\n revalidation?: boolean; // Enable revalidation\n revalidateTime?: number; // Time in milliseconds for revalidating the data\n invalidateQueries?: string[]; // Invalidate other queries when the data is updated\n updateQueries?: string[]; // Update other queries when the data is updated\n onSuccess?: (data: Awaited<ReturnType<T>>) => void; // Callback function that is called when the asynchronous function resolves successfully\n onError?: (error: string) => void; // Callback function that is called when the asynchronous function rejects or encounters an error\n abort?: () => void; // Abort the request\n args?: Parameters<T>; // Arguments to pass to the asynchronous function\n};\n\n// Default values for the hook's options\nconst DEFAULT_CACHE_ENABLED = false;\nconst DEFAULT_STORE_ENABLED = false;\nconst DEFAULT_ENABLED = true;\nconst DEFAULT_AUTO_FETCH = false;\nconst DEFAULT_RETRY_LIMIT = 1;\nconst DEFAULT_REVALIDATION_ENABLED = false;\nconst DEFAULT_REVALIDATE_TIME = 5 * 60 * 1000; // 5 minutes\nconst DEFAULT_RETRY_TIME = 5 * 60 * 1000; // 5 minutes\n\n// The main hook type that includes the async function along with its additional properties.\nexport type UseAsyncResult<\n U extends string,\n T extends (...args: any[]) => Promise<any>,\n> = UseAsyncResultBase<T> & Record<U, T>;\n\nconst getArgs = (args?: any[]): any[] =>\n args ? (Array.isArray(args) ? args : [args]) : [];\n\nconst getKeyWithArgs = (key: string, args: any[]) =>\n getArgs(args).length > 0 ? `${key}/${JSON.stringify(args)}` : key;\n\n/**\n * A custom React hook that manages asynchronous operations, providing easy-to-use states and controls over fetching, caching, and retry mechanisms.\n * This hook abstracts away the complexity of handling loading, error, and success states for any asynchronous function.\n *\n *\n * ```tsx\n * // Example of using useAsync to manage fetching user data from an API.\n * const fetchUserData = async (userId) => {\n * const response = await fetch(`/api/users/${userId}`);\n * if (!response.ok) throw new Error('Failed to fetch');\n * return await response.json();\n * };\n *\n * const UserDetails = ({ userId }) => {\n * const {\n * isLoading,\n * data,\n * error,\n * revalidate,\n * } = useAsync('userDetails', fetchUserData, {\n * cache: true,\n * revalidateTime: 60000, // 1 minute\n * autoFetch: true,\n * onSuccess: (data) => console.log('User data fetched successfully:', data),\n * onError: (error) => console.error('Error fetching user data:', error),\n * });\n *\n * if (isLoading) return <div>Loading...</div>;\n * if (error) return <div>Error: {error}</div>;\n * return (\n * <div>\n * <h1>{data.name}</h1>\n * <button onClick={() => revalidate()}>Refresh</button>\n * </div>\n * );\n * };\n * ```\n */\nexport const useAsync = <\n U extends string,\n T extends (...args: any[]) => Promise<any>,\n>(\n key: U,\n asyncFunction: T,\n options?: UseAsyncOptions<T>\n): UseAsyncResult<U, T> => {\n // Resolving optional parameters with default values\n const retryLimit = options?.retryLimit ?? DEFAULT_RETRY_LIMIT;\n const autoFetch = options?.autoFetch ?? DEFAULT_AUTO_FETCH;\n const retryTime = options?.retryTime ?? DEFAULT_RETRY_TIME;\n const cacheEnabled = options?.cache ?? DEFAULT_CACHE_ENABLED;\n const storeEnabled = options?.store ?? DEFAULT_STORE_ENABLED;\n const enabled = options?.enable ?? DEFAULT_ENABLED;\n const revalidationEnabled =\n options?.revalidation ?? DEFAULT_REVALIDATION_ENABLED;\n const revalidateTime = options?.revalidateTime ?? DEFAULT_REVALIDATE_TIME;\n const updateQueries = options?.updateQueries ?? [];\n const invalidateQueries = options?.invalidateQueries ?? [];\n const onSuccess = options?.onSuccess;\n const onError = options?.onError;\n const args = getArgs(options?.args ?? []);\n\n // Using a custom hook to manage state specific to asynchronous operations\n const { getStates, setQueryState, setQueriesState, makeQueryInError } =\n useAsyncState();\n\n // Storing the last arguments used to call the async function\n const storedArgsRef = useRef<any[]>(args);\n\n const controllerRef = useRef<AbortController | null>(null);\n\n // Apply different key for different requests\n const keyWithArgs = getKeyWithArgs(key, storedArgsRef.current);\n\n // Retrieving the current state of async operations using the same custom hook\n const {\n isFetched,\n fetchedDateTime,\n isLoading,\n isEnabled,\n error,\n isSuccess,\n isInvalidated,\n data,\n errorCount,\n } = getStates(keyWithArgs);\n\n /**\n * FETCH FUNCTION\n *\n * Manage parallel fetching across multiple instances of the hook\n * Manage state updates on success and error\n * Manage eventual invalidation of other queries\n */\n const fetch: T = (async (...args) => {\n const keyWithArgs = getKeyWithArgs(key, args);\n\n /**\n * ABORT CONTROLLER\n *\n * cancel an unnecessary request.\n * For example, if a user navigates away from a page or triggers a new request that makes the previous one obsolete, you can abort the previous fetch\n */\n if (controllerRef.current) {\n // Abort the previous request\n controllerRef.current.abort();\n }\n\n // Create a new AbortController\n const controller = new AbortController();\n controllerRef.current = controller;\n\n /**\n * PENDING PROMISES\n *\n * This logic ensures that if two parts of your application trigger the same request simultaneously,\n * only one network call is made, and both receive the same result.\n */\n if (pendingPromises.has(keyWithArgs)) {\n // Return the existing pending promise\n return pendingPromises.get(keyWithArgs);\n }\n\n const promise = (async () => {\n setQueryState(keyWithArgs, { isLoading: true });\n let response = null;\n\n try {\n // Ensure asyncFunction returns a Promise\n const asyncResult = asyncFunction(...args);\n\n // Check if the result is a Promise-like object\n if (!asyncResult || typeof asyncResult.then !== 'function') {\n throw new Error('asyncFunction must return a Promise');\n }\n\n const result = await asyncResult;\n response = result;\n\n setQueryState(keyWithArgs, {\n data: result,\n errorCount: 0,\n isLoading: false,\n isFetched: true,\n fetchedDateTime: new Date(),\n isSuccess: true,\n isInvalidated: false,\n error: null,\n });\n\n onSuccess?.(result);\n\n // Invalidate other queries if necessary\n if (invalidateQueries.length > 0) {\n setQueriesState(invalidateQueries, {\n isInvalidated: true,\n });\n }\n\n // Update other queries if necessary\n if (updateQueries.length > 0) {\n setQueriesState(updateQueries, {\n data: result,\n });\n }\n\n // Store the result in local storage\n if (storeEnabled) {\n localStorage.setItem(keyWithArgs, JSON.stringify(result));\n }\n } catch (error) {\n const msg = error instanceof Error ? error.message : String(error);\n\n makeQueryInError(keyWithArgs, msg);\n onError?.(msg);\n } finally {\n // Remove the pending promise from the cache\n pendingPromises.delete(keyWithArgs);\n }\n\n return response;\n })();\n\n // Store the pending promise in the cache\n pendingPromises.set(keyWithArgs, promise);\n\n return await promise;\n }) as T;\n\n /**\n * REVALIDATE FUNCTION\n *\n * Wrap core function to handle revalidation\n * Handle arguments caching\n *\n */\n const revalidate: T = (async (...args) => {\n if (!isEnabled || !enabled) return; // Hook is disabled\n\n if (args) {\n // Revalidation arguments can be different from the initial fetch arguments\n // If arguments are provided, store/update them for future periodic revalidation\n\n storedArgsRef.current = getArgs(args);\n }\n\n return await fetch(...storedArgsRef.current);\n }) as T;\n\n /**\n * EXECUTION FUNCTION\n *\n * Wrap revalidation function\n * If data is valid return it directly to avoid fetching again\n */\n const execute: T = (async (...args) => {\n if (!isEnabled || !enabled) return; // Hook is disabled\n if (isLoading) return; // Fetch is already in progress\n\n const shouldReturnData =\n !isInvalidated && // If data are invalidated, we should refetch to revalidate the data\n isSuccess &&\n cacheEnabled &&\n data;\n\n if (shouldReturnData) return data; // Data are already fetched and should be returned directly. Avoid fetching again.\n\n return await revalidate(...args);\n }) as T;\n\n /**\n * HANDLE SYNCHRONIZATION HOOKS DISACTIVATION\n *\n * If one instance of the hook is disabled, the other instances should be disabled too.\n * This is to prevent inconsistencies in the state of the hook.\n */\n useEffect(() => {\n if (enabled !== isEnabled) {\n setQueryState(keyWithArgs, {\n isEnabled,\n });\n }\n }, [enabled, isEnabled, keyWithArgs]);\n\n /**\n * HANDLE LOCAL STORAGE LOADING\n *\n * If store is enabled, load data from local storage\n */\n useEffect(() => {\n if (!isEnabled || !enabled) return; // Hook is disabled\n if (!storeEnabled) return; // Hook should not use local storage\n if (isInvalidated || isFetched || data) return; // Hook have been already mounted and fetched or invalidated\n\n const storedData = localStorage.getItem(keyWithArgs);\n\n // Wrap parsing in a try-catch block to handle invalid JSON data\n try {\n if (storedData) {\n setQueryState(keyWithArgs, {\n data: JSON.parse(storedData),\n });\n }\n } catch (error) {\n console.error(error);\n }\n }, [\n storeEnabled,\n keyWithArgs,\n isFetched,\n isInvalidated,\n isEnabled,\n enabled,\n data,\n ]);\n\n /**\n * HANDLE AUTO-FETCH ON HOOK MOUNT\n *\n * If autoFetch is enabled, fetch the data when the hook is mounted\n */\n useEffect(() => {\n if (!autoFetch) return; // Auto-fetch is disabled\n if (!isEnabled || !enabled) return; // Hook is disabled\n if (isFetched && !isInvalidated) return; // Hook have already fetched or invalidated\n if (isLoading) return; // Fetch is already in progress\n\n fetch(...storedArgsRef.current);\n }, [\n autoFetch,\n isEnabled,\n enabled,\n isFetched,\n isInvalidated,\n isLoading,\n fetch,\n ]);\n\n /**\n * HANDLE RETRY\n *\n * If fetching fails, retry the fetch after a certain time\n */\n useEffect(() => {\n const isRetryEnabled = errorCount > 0 && retryLimit > 0;\n const isRetryLimitReached = errorCount > retryLimit;\n\n if (!isEnabled || !enabled) return; // Hook is disabled\n if (!isRetryEnabled) return; // Retry is disabled\n if (isRetryLimitReached) return; // Retry limit has been reached\n if (isLoading) return; // Fetch is already in progress\n if (isSuccess) return; // Hook has already fetched successfully\n\n const timeout = setTimeout(() => {\n fetch(...storedArgsRef.current);\n }, retryTime);\n\n return () => clearTimeout(timeout);\n }, [\n isEnabled,\n errorCount,\n retryLimit,\n enabled,\n retryTime,\n isSuccess,\n isLoading,\n fetch,\n ]);\n\n /**\n * HANDLE PERIODIC REVALIDATION\n *\n * If revalidation is enabled, revalidate the data periodically\n */\n useEffect(() => {\n if (!revalidationEnabled || revalidateTime <= 0) return; // Revalidation is disabled\n if (!isEnabled || !enabled) return; // Hook is disabled\n if (isLoading) return; // Fetch is already in progress\n if (!isSuccess || !fetchedDateTime) return; // Should retry either of revalidate\n\n const timeout = setTimeout(() => {\n fetch(...storedArgsRef.current);\n }, revalidateTime);\n\n return () => clearTimeout(timeout);\n }, [\n revalidationEnabled,\n revalidateTime,\n isSuccess,\n fetchedDateTime,\n isLoading,\n isEnabled,\n enabled,\n fetch,\n ]);\n\n // Memoization of the setData function to prevent unnecessary re-renders\n const setDataMemo = (data: Awaited<ReturnType<T> | null>) => {\n setQueryState(keyWithArgs, {\n data,\n });\n };\n\n const abort = () => {\n if (controllerRef.current) {\n controllerRef.current.abort();\n }\n };\n\n // Memoization to prevent unnecessary re-renders\n const memoResult = {\n isFetched,\n isInvalidated,\n error,\n data,\n errorCount,\n isSuccess,\n isEnabled,\n isDisabled: !isEnabled,\n isLoading,\n isWaitingData: isLoading && !isFetched && !data, // Check if the data is still being fetched. Stay at true during revalidation or if data are stored in local storage\n isRevalidating: isLoading && isFetched, // Check if the data is valid and is being revalidated\n [key]: execute, // Name the execute function as the given key to avoid conflicts with other hooks (e.g. `const { fetchUser } = useAsync('fetchUser', () => fetchUserFunction());`)\n revalidate,\n setData: setDataMemo,\n abort,\n };\n\n useEffect(\n () => () => {\n // Clean up the controller on unmount\n if (controllerRef.current) {\n controllerRef.current.abort();\n }\n },\n []\n );\n\n // Return the hook's result, including all state and control functions\n return memoResult as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AC;IAC7B,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;IACnD,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,KAAK,CAAC,EAAE,MAAM,IAAI,CAAC;IACnB,IAAI,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC;CACtB,CAAC;AAaF,MAAM,MAAM,cAAc,CACxB,CAAC,SAAS,MAAM,EAChB,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,GAAG,CAAC,IACxC,kBAAkB,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAQzC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,eAAO,MAAM,QAAQ,GACnB,CAAC,SAAS,MAAM,EAChB,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,GAAG,CAAC,EAE1C,KAAK,CAAC,EACN,eAAe,CAAC,EAChB,UAAU,eAAe,CAAC,CAAC,CAAC,KAC3B,cAAc,CAAC,CAAC,EAAE,CAAC,CAmWrB,CAAC"}
@@ -86,7 +86,6 @@ const useAsync = (key, asyncFunction, options) => {
86
86
  localStorage.setItem(keyWithArgs2, JSON.stringify(result));
87
87
  }
88
88
  } catch (error2) {
89
- console.error({ error: error2 });
90
89
  const msg = error2 instanceof Error ? error2.message : String(error2);
91
90
  makeQueryInError(keyWithArgs2, msg);
92
91
  onError?.(msg);
@@ -1 +1 @@
1
- {"version":3,"file":"useAsync.mjs","sources":["../../../src/hooks/useAsync/useAsync.ts"],"sourcesContent":["'use client';\n\nimport { useEffect, useRef } from 'react';\nimport { useAsyncState } from './useAsyncStateStore';\n\n// Pending promises cache to prevent parallel requests when multiple components use the hook\nconst pendingPromises = new Map();\n\n// Defines the base structure for the result of the custom hook.\ntype UseAsyncResultBase<T extends (...args: any[]) => Promise<any>> = {\n isFetched: boolean;\n isLoading: boolean;\n isInvalidated: boolean;\n isSuccess: boolean;\n isDisabled: boolean;\n isWaitingData: boolean;\n isRevalidating: boolean;\n error: string | null;\n data: Awaited<ReturnType<T>> | null;\n errorCount: number;\n revalidate: T;\n setData: (data: Awaited<ReturnType<T> | null>) => void;\n abort: () => void;\n};\n\n// Options type for the hook, allowing customization of behavior.\nexport type UseAsyncOptions<T extends (...args: any[]) => Promise<any>> = {\n retryLimit?: number; // The number of times the hook should retry the function on failure before giving up\n retryTime?: number; // Time in milliseconds for retrying the data\n cache?: boolean; // Cache the result of the function\n store?: boolean; // Store the result of the function in local storage\n enable?: boolean; // Enable the hook\n autoFetch?: boolean; // Automatically fetch the data when the hook is mounted\n revalidation?: boolean; // Enable revalidation\n revalidateTime?: number; // Time in milliseconds for revalidating the data\n invalidateQueries?: string[]; // Invalidate other queries when the data is updated\n updateQueries?: string[]; // Update other queries when the data is updated\n onSuccess?: (data: Awaited<ReturnType<T>>) => void; // Callback function that is called when the asynchronous function resolves successfully\n onError?: (error: string) => void; // Callback function that is called when the asynchronous function rejects or encounters an error\n abort?: () => void; // Abort the request\n args?: Parameters<T>; // Arguments to pass to the asynchronous function\n};\n\n// Default values for the hook's options\nconst DEFAULT_CACHE_ENABLED = false;\nconst DEFAULT_STORE_ENABLED = false;\nconst DEFAULT_ENABLED = true;\nconst DEFAULT_AUTO_FETCH = false;\nconst DEFAULT_RETRY_LIMIT = 1;\nconst DEFAULT_REVALIDATION_ENABLED = false;\nconst DEFAULT_REVALIDATE_TIME = 5 * 60 * 1000; // 5 minutes\nconst DEFAULT_RETRY_TIME = 5 * 60 * 1000; // 5 minutes\n\n// The main hook type that includes the async function along with its additional properties.\nexport type UseAsyncResult<\n U extends string,\n T extends (...args: any[]) => Promise<any>,\n> = UseAsyncResultBase<T> & Record<U, T>;\n\nconst getArgs = (args?: any[]): any[] =>\n args ? (Array.isArray(args) ? args : [args]) : [];\n\nconst getKeyWithArgs = (key: string, args: any[]) =>\n getArgs(args).length > 0 ? `${key}/${JSON.stringify(args)}` : key;\n\n/**\n * A custom React hook that manages asynchronous operations, providing easy-to-use states and controls over fetching, caching, and retry mechanisms.\n * This hook abstracts away the complexity of handling loading, error, and success states for any asynchronous function.\n *\n *\n * ```tsx\n * // Example of using useAsync to manage fetching user data from an API.\n * const fetchUserData = async (userId) => {\n * const response = await fetch(`/api/users/${userId}`);\n * if (!response.ok) throw new Error('Failed to fetch');\n * return await response.json();\n * };\n *\n * const UserDetails = ({ userId }) => {\n * const {\n * isLoading,\n * data,\n * error,\n * revalidate,\n * } = useAsync('userDetails', fetchUserData, {\n * cache: true,\n * revalidateTime: 60000, // 1 minute\n * autoFetch: true,\n * onSuccess: (data) => console.log('User data fetched successfully:', data),\n * onError: (error) => console.error('Error fetching user data:', error),\n * });\n *\n * if (isLoading) return <div>Loading...</div>;\n * if (error) return <div>Error: {error}</div>;\n * return (\n * <div>\n * <h1>{data.name}</h1>\n * <button onClick={() => revalidate()}>Refresh</button>\n * </div>\n * );\n * };\n * ```\n */\nexport const useAsync = <\n U extends string,\n T extends (...args: any[]) => Promise<any>,\n>(\n key: U,\n asyncFunction: T,\n options?: UseAsyncOptions<T>\n): UseAsyncResult<U, T> => {\n // Resolving optional parameters with default values\n const retryLimit = options?.retryLimit ?? DEFAULT_RETRY_LIMIT;\n const autoFetch = options?.autoFetch ?? DEFAULT_AUTO_FETCH;\n const retryTime = options?.retryTime ?? DEFAULT_RETRY_TIME;\n const cacheEnabled = options?.cache ?? DEFAULT_CACHE_ENABLED;\n const storeEnabled = options?.store ?? DEFAULT_STORE_ENABLED;\n const enabled = options?.enable ?? DEFAULT_ENABLED;\n const revalidationEnabled =\n options?.revalidation ?? DEFAULT_REVALIDATION_ENABLED;\n const revalidateTime = options?.revalidateTime ?? DEFAULT_REVALIDATE_TIME;\n const updateQueries = options?.updateQueries ?? [];\n const invalidateQueries = options?.invalidateQueries ?? [];\n const onSuccess = options?.onSuccess;\n const onError = options?.onError;\n const args = getArgs(options?.args ?? []);\n\n // Using a custom hook to manage state specific to asynchronous operations\n const { getStates, setQueryState, setQueriesState, makeQueryInError } =\n useAsyncState();\n\n // Storing the last arguments used to call the async function\n const storedArgsRef = useRef<any[]>(args);\n\n const controllerRef = useRef<AbortController | null>(null);\n\n // Apply different key for different requests\n const keyWithArgs = getKeyWithArgs(key, storedArgsRef.current);\n\n // Retrieving the current state of async operations using the same custom hook\n const {\n isFetched,\n fetchedDateTime,\n isLoading,\n isEnabled,\n error,\n isSuccess,\n isInvalidated,\n data,\n errorCount,\n } = getStates(keyWithArgs);\n\n /**\n * FETCH FUNCTION\n *\n * Manage parallel fetching across multiple instances of the hook\n * Manage state updates on success and error\n * Manage eventual invalidation of other queries\n */\n const fetch: T = (async (...args) => {\n const keyWithArgs = getKeyWithArgs(key, args);\n\n /**\n * ABORT CONTROLLER\n *\n * cancel an unnecessary request.\n * For example, if a user navigates away from a page or triggers a new request that makes the previous one obsolete, you can abort the previous fetch\n */\n if (controllerRef.current) {\n // Abort the previous request\n controllerRef.current.abort();\n }\n\n // Create a new AbortController\n const controller = new AbortController();\n controllerRef.current = controller;\n\n /**\n * PENDING PROMISES\n *\n * This logic ensures that if two parts of your application trigger the same request simultaneously,\n * only one network call is made, and both receive the same result.\n */\n if (pendingPromises.has(keyWithArgs)) {\n // Return the existing pending promise\n return pendingPromises.get(keyWithArgs);\n }\n\n const promise = (async () => {\n setQueryState(keyWithArgs, { isLoading: true });\n let response = null;\n\n try {\n // Ensure asyncFunction returns a Promise\n const asyncResult = asyncFunction(...args);\n\n // Check if the result is a Promise-like object\n if (!asyncResult || typeof asyncResult.then !== 'function') {\n throw new Error('asyncFunction must return a Promise');\n }\n\n const result = await asyncResult;\n response = result;\n\n setQueryState(keyWithArgs, {\n data: result,\n errorCount: 0,\n isLoading: false,\n isFetched: true,\n fetchedDateTime: new Date(),\n isSuccess: true,\n isInvalidated: false,\n error: null,\n });\n\n onSuccess?.(result);\n\n // Invalidate other queries if necessary\n if (invalidateQueries.length > 0) {\n setQueriesState(invalidateQueries, {\n isInvalidated: true,\n });\n }\n\n // Update other queries if necessary\n if (updateQueries.length > 0) {\n setQueriesState(updateQueries, {\n data: result,\n });\n }\n\n // Store the result in local storage\n if (storeEnabled) {\n localStorage.setItem(keyWithArgs, JSON.stringify(result));\n }\n } catch (error) {\n console.error({ error });\n const msg = error instanceof Error ? error.message : String(error);\n\n makeQueryInError(keyWithArgs, msg);\n onError?.(msg);\n } finally {\n // Remove the pending promise from the cache\n pendingPromises.delete(keyWithArgs);\n }\n\n return response;\n })();\n\n // Store the pending promise in the cache\n pendingPromises.set(keyWithArgs, promise);\n\n return await promise;\n }) as T;\n\n /**\n * REVALIDATE FUNCTION\n *\n * Wrap core function to handle revalidation\n * Handle arguments caching\n *\n */\n const revalidate: T = (async (...args) => {\n if (!isEnabled || !enabled) return; // Hook is disabled\n\n if (args) {\n // Revalidation arguments can be different from the initial fetch arguments\n // If arguments are provided, store/update them for future periodic revalidation\n\n storedArgsRef.current = getArgs(args);\n }\n\n return await fetch(...storedArgsRef.current);\n }) as T;\n\n /**\n * EXECUTION FUNCTION\n *\n * Wrap revalidation function\n * If data is valid return it directly to avoid fetching again\n */\n const execute: T = (async (...args) => {\n if (!isEnabled || !enabled) return; // Hook is disabled\n if (isLoading) return; // Fetch is already in progress\n\n const shouldReturnData =\n !isInvalidated && // If data are invalidated, we should refetch to revalidate the data\n isSuccess &&\n cacheEnabled &&\n data;\n\n if (shouldReturnData) return data; // Data are already fetched and should be returned directly. Avoid fetching again.\n\n return await revalidate(...args);\n }) as T;\n\n /**\n * HANDLE SYNCHRONIZATION HOOKS DISACTIVATION\n *\n * If one instance of the hook is disabled, the other instances should be disabled too.\n * This is to prevent inconsistencies in the state of the hook.\n */\n useEffect(() => {\n if (enabled !== isEnabled) {\n setQueryState(keyWithArgs, {\n isEnabled,\n });\n }\n }, [enabled, isEnabled, keyWithArgs]);\n\n /**\n * HANDLE LOCAL STORAGE LOADING\n *\n * If store is enabled, load data from local storage\n */\n useEffect(() => {\n if (!isEnabled || !enabled) return; // Hook is disabled\n if (!storeEnabled) return; // Hook should not use local storage\n if (isInvalidated || isFetched || data) return; // Hook have been already mounted and fetched or invalidated\n\n const storedData = localStorage.getItem(keyWithArgs);\n\n // Wrap parsing in a try-catch block to handle invalid JSON data\n try {\n if (storedData) {\n setQueryState(keyWithArgs, {\n data: JSON.parse(storedData),\n });\n }\n } catch (error) {\n console.error(error);\n }\n }, [\n storeEnabled,\n keyWithArgs,\n isFetched,\n isInvalidated,\n isEnabled,\n enabled,\n data,\n ]);\n\n /**\n * HANDLE AUTO-FETCH ON HOOK MOUNT\n *\n * If autoFetch is enabled, fetch the data when the hook is mounted\n */\n useEffect(() => {\n if (!autoFetch) return; // Auto-fetch is disabled\n if (!isEnabled || !enabled) return; // Hook is disabled\n if (isFetched && !isInvalidated) return; // Hook have already fetched or invalidated\n if (isLoading) return; // Fetch is already in progress\n\n fetch(...storedArgsRef.current);\n }, [\n autoFetch,\n isEnabled,\n enabled,\n isFetched,\n isInvalidated,\n isLoading,\n fetch,\n ]);\n\n /**\n * HANDLE RETRY\n *\n * If fetching fails, retry the fetch after a certain time\n */\n useEffect(() => {\n const isRetryEnabled = errorCount > 0 && retryLimit > 0;\n const isRetryLimitReached = errorCount > retryLimit;\n\n if (!isEnabled || !enabled) return; // Hook is disabled\n if (!isRetryEnabled) return; // Retry is disabled\n if (isRetryLimitReached) return; // Retry limit has been reached\n if (isLoading) return; // Fetch is already in progress\n if (isSuccess) return; // Hook has already fetched successfully\n\n const timeout = setTimeout(() => {\n fetch(...storedArgsRef.current);\n }, retryTime);\n\n return () => clearTimeout(timeout);\n }, [\n isEnabled,\n errorCount,\n retryLimit,\n enabled,\n retryTime,\n isSuccess,\n isLoading,\n fetch,\n ]);\n\n /**\n * HANDLE PERIODIC REVALIDATION\n *\n * If revalidation is enabled, revalidate the data periodically\n */\n useEffect(() => {\n if (!revalidationEnabled || revalidateTime <= 0) return; // Revalidation is disabled\n if (!isEnabled || !enabled) return; // Hook is disabled\n if (isLoading) return; // Fetch is already in progress\n if (!isSuccess || !fetchedDateTime) return; // Should retry either of revalidate\n\n const timeout = setTimeout(() => {\n fetch(...storedArgsRef.current);\n }, revalidateTime);\n\n return () => clearTimeout(timeout);\n }, [\n revalidationEnabled,\n revalidateTime,\n isSuccess,\n fetchedDateTime,\n isLoading,\n isEnabled,\n enabled,\n fetch,\n ]);\n\n // Memoization of the setData function to prevent unnecessary re-renders\n const setDataMemo = (data: Awaited<ReturnType<T> | null>) => {\n setQueryState(keyWithArgs, {\n data,\n });\n };\n\n const abort = () => {\n if (controllerRef.current) {\n controllerRef.current.abort();\n }\n };\n\n // Memoization to prevent unnecessary re-renders\n const memoResult = {\n isFetched,\n isInvalidated,\n error,\n data,\n errorCount,\n isSuccess,\n isEnabled,\n isDisabled: !isEnabled,\n isLoading,\n isWaitingData: isLoading && !isFetched && !data, // Check if the data is still being fetched. Stay at true during revalidation or if data are stored in local storage\n isRevalidating: isLoading && isFetched, // Check if the data is valid and is being revalidated\n [key]: execute, // Name the execute function as the given key to avoid conflicts with other hooks (e.g. `const { fetchUser } = useAsync('fetchUser', () => fetchUserFunction());`)\n revalidate,\n setData: setDataMemo,\n abort,\n };\n\n useEffect(\n () => () => {\n // Clean up the controller on unmount\n if (controllerRef.current) {\n controllerRef.current.abort();\n }\n },\n []\n );\n\n // Return the hook's result, including all state and control functions\n return memoResult as UseAsyncResultBase<T> & Record<U, T>;\n};\n"],"names":["args","keyWithArgs","error","data"],"mappings":";;;AAMA,MAAM,sCAAsB,IAAI;AAsChC,MAAM,wBAAwB;AAC9B,MAAM,wBAAwB;AAC9B,MAAM,kBAAkB;AACxB,MAAM,qBAAqB;AAC3B,MAAM,sBAAsB;AAC5B,MAAM,+BAA+B;AACrC,MAAM,0BAA0B,I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SAAS;AAAA,IACT;AAAA,EACF;AAEA;AAAA,IACE,MAAM,MAAM;AAEV,UAAI,cAAc,SAAS;AACzB,sBAAc,QAAQ,MAAM;AAAA,MAAA;AAAA,IAEhC;AAAA,IACA,CAAA;AAAA,EACF;AAGO,SAAA;AACT;"}
1
+ {"version":3,"file":"useAsync.mjs","sources":["../../../src/hooks/useAsync/useAsync.ts"],"sourcesContent":["'use client';\n\nimport { useEffect, useRef } from 'react';\nimport { useAsyncState } from './useAsyncStateStore';\n\n// Pending promises cache to prevent parallel requests when multiple components use the hook\nconst pendingPromises = new Map();\n\n// Defines the base structure for the result of the custom hook.\ntype UseAsyncResultBase<T extends (...args: any[]) => Promise<any>> = {\n isFetched: boolean;\n isLoading: boolean;\n isInvalidated: boolean;\n isSuccess: boolean;\n isDisabled: boolean;\n isWaitingData: boolean;\n isRevalidating: boolean;\n error: string | null;\n data: Awaited<ReturnType<T>> | null;\n errorCount: number;\n revalidate: T;\n setData: (data: Awaited<ReturnType<T> | null>) => void;\n abort: () => void;\n};\n\n// Options type for the hook, allowing customization of behavior.\nexport type UseAsyncOptions<T extends (...args: any[]) => Promise<any>> = {\n retryLimit?: number; // The number of times the hook should retry the function on failure before giving up\n retryTime?: number; // Time in milliseconds for retrying the data\n cache?: boolean; // Cache the result of the function\n store?: boolean; // Store the result of the function in local storage\n enable?: boolean; // Enable the hook\n autoFetch?: boolean; // Automatically fetch the data when the hook is mounted\n revalidation?: boolean; // Enable revalidation\n revalidateTime?: number; // Time in milliseconds for revalidating the data\n invalidateQueries?: string[]; // Invalidate other queries when the data is updated\n updateQueries?: string[]; // Update other queries when the data is updated\n onSuccess?: (data: Awaited<ReturnType<T>>) => void; // Callback function that is called when the asynchronous function resolves successfully\n onError?: (error: string) => void; // Callback function that is called when the asynchronous function rejects or encounters an error\n abort?: () => void; // Abort the request\n args?: Parameters<T>; // Arguments to pass to the asynchronous function\n};\n\n// Default values for the hook's options\nconst DEFAULT_CACHE_ENABLED = false;\nconst DEFAULT_STORE_ENABLED = false;\nconst DEFAULT_ENABLED = true;\nconst DEFAULT_AUTO_FETCH = false;\nconst DEFAULT_RETRY_LIMIT = 1;\nconst DEFAULT_REVALIDATION_ENABLED = false;\nconst DEFAULT_REVALIDATE_TIME = 5 * 60 * 1000; // 5 minutes\nconst DEFAULT_RETRY_TIME = 5 * 60 * 1000; // 5 minutes\n\n// The main hook type that includes the async function along with its additional properties.\nexport type UseAsyncResult<\n U extends string,\n T extends (...args: any[]) => Promise<any>,\n> = UseAsyncResultBase<T> & Record<U, T>;\n\nconst getArgs = (args?: any[]): any[] =>\n args ? (Array.isArray(args) ? args : [args]) : [];\n\nconst getKeyWithArgs = (key: string, args: any[]) =>\n getArgs(args).length > 0 ? `${key}/${JSON.stringify(args)}` : key;\n\n/**\n * A custom React hook that manages asynchronous operations, providing easy-to-use states and controls over fetching, caching, and retry mechanisms.\n * This hook abstracts away the complexity of handling loading, error, and success states for any asynchronous function.\n *\n *\n * ```tsx\n * // Example of using useAsync to manage fetching user data from an API.\n * const fetchUserData = async (userId) => {\n * const response = await fetch(`/api/users/${userId}`);\n * if (!response.ok) throw new Error('Failed to fetch');\n * return await response.json();\n * };\n *\n * const UserDetails = ({ userId }) => {\n * const {\n * isLoading,\n * data,\n * error,\n * revalidate,\n * } = useAsync('userDetails', fetchUserData, {\n * cache: true,\n * revalidateTime: 60000, // 1 minute\n * autoFetch: true,\n * onSuccess: (data) => console.log('User data fetched successfully:', data),\n * onError: (error) => console.error('Error fetching user data:', error),\n * });\n *\n * if (isLoading) return <div>Loading...</div>;\n * if (error) return <div>Error: {error}</div>;\n * return (\n * <div>\n * <h1>{data.name}</h1>\n * <button onClick={() => revalidate()}>Refresh</button>\n * </div>\n * );\n * };\n * ```\n */\nexport const useAsync = <\n U extends string,\n T extends (...args: any[]) => Promise<any>,\n>(\n key: U,\n asyncFunction: T,\n options?: UseAsyncOptions<T>\n): UseAsyncResult<U, T> => {\n // Resolving optional parameters with default values\n const retryLimit = options?.retryLimit ?? DEFAULT_RETRY_LIMIT;\n const autoFetch = options?.autoFetch ?? DEFAULT_AUTO_FETCH;\n const retryTime = options?.retryTime ?? DEFAULT_RETRY_TIME;\n const cacheEnabled = options?.cache ?? DEFAULT_CACHE_ENABLED;\n const storeEnabled = options?.store ?? DEFAULT_STORE_ENABLED;\n const enabled = options?.enable ?? DEFAULT_ENABLED;\n const revalidationEnabled =\n options?.revalidation ?? DEFAULT_REVALIDATION_ENABLED;\n const revalidateTime = options?.revalidateTime ?? DEFAULT_REVALIDATE_TIME;\n const updateQueries = options?.updateQueries ?? [];\n const invalidateQueries = options?.invalidateQueries ?? [];\n const onSuccess = options?.onSuccess;\n const onError = options?.onError;\n const args = getArgs(options?.args ?? []);\n\n // Using a custom hook to manage state specific to asynchronous operations\n const { getStates, setQueryState, setQueriesState, makeQueryInError } =\n useAsyncState();\n\n // Storing the last arguments used to call the async function\n const storedArgsRef = useRef<any[]>(args);\n\n const controllerRef = useRef<AbortController | null>(null);\n\n // Apply different key for different requests\n const keyWithArgs = getKeyWithArgs(key, storedArgsRef.current);\n\n // Retrieving the current state of async operations using the same custom hook\n const {\n isFetched,\n fetchedDateTime,\n isLoading,\n isEnabled,\n error,\n isSuccess,\n isInvalidated,\n data,\n errorCount,\n } = getStates(keyWithArgs);\n\n /**\n * FETCH FUNCTION\n *\n * Manage parallel fetching across multiple instances of the hook\n * Manage state updates on success and error\n * Manage eventual invalidation of other queries\n */\n const fetch: T = (async (...args) => {\n const keyWithArgs = getKeyWithArgs(key, args);\n\n /**\n * ABORT CONTROLLER\n *\n * cancel an unnecessary request.\n * For example, if a user navigates away from a page or triggers a new request that makes the previous one obsolete, you can abort the previous fetch\n */\n if (controllerRef.current) {\n // Abort the previous request\n controllerRef.current.abort();\n }\n\n // Create a new AbortController\n const controller = new AbortController();\n controllerRef.current = controller;\n\n /**\n * PENDING PROMISES\n *\n * This logic ensures that if two parts of your application trigger the same request simultaneously,\n * only one network call is made, and both receive the same result.\n */\n if (pendingPromises.has(keyWithArgs)) {\n // Return the existing pending promise\n return pendingPromises.get(keyWithArgs);\n }\n\n const promise = (async () => {\n setQueryState(keyWithArgs, { isLoading: true });\n let response = null;\n\n try {\n // Ensure asyncFunction returns a Promise\n const asyncResult = asyncFunction(...args);\n\n // Check if the result is a Promise-like object\n if (!asyncResult || typeof asyncResult.then !== 'function') {\n throw new Error('asyncFunction must return a Promise');\n }\n\n const result = await asyncResult;\n response = result;\n\n setQueryState(keyWithArgs, {\n data: result,\n errorCount: 0,\n isLoading: false,\n isFetched: true,\n fetchedDateTime: new Date(),\n isSuccess: true,\n isInvalidated: false,\n error: null,\n });\n\n onSuccess?.(result);\n\n // Invalidate other queries if necessary\n if (invalidateQueries.length > 0) {\n setQueriesState(invalidateQueries, {\n isInvalidated: true,\n });\n }\n\n // Update other queries if necessary\n if (updateQueries.length > 0) {\n setQueriesState(updateQueries, {\n data: result,\n });\n }\n\n // Store the result in local storage\n if (storeEnabled) {\n localStorage.setItem(keyWithArgs, JSON.stringify(result));\n }\n } catch (error) {\n const msg = error instanceof Error ? error.message : String(error);\n\n makeQueryInError(keyWithArgs, msg);\n onError?.(msg);\n } finally {\n // Remove the pending promise from the cache\n pendingPromises.delete(keyWithArgs);\n }\n\n return response;\n })();\n\n // Store the pending promise in the cache\n pendingPromises.set(keyWithArgs, promise);\n\n return await promise;\n }) as T;\n\n /**\n * REVALIDATE FUNCTION\n *\n * Wrap core function to handle revalidation\n * Handle arguments caching\n *\n */\n const revalidate: T = (async (...args) => {\n if (!isEnabled || !enabled) return; // Hook is disabled\n\n if (args) {\n // Revalidation arguments can be different from the initial fetch arguments\n // If arguments are provided, store/update them for future periodic revalidation\n\n storedArgsRef.current = getArgs(args);\n }\n\n return await fetch(...storedArgsRef.current);\n }) as T;\n\n /**\n * EXECUTION FUNCTION\n *\n * Wrap revalidation function\n * If data is valid return it directly to avoid fetching again\n */\n const execute: T = (async (...args) => {\n if (!isEnabled || !enabled) return; // Hook is disabled\n if (isLoading) return; // Fetch is already in progress\n\n const shouldReturnData =\n !isInvalidated && // If data are invalidated, we should refetch to revalidate the data\n isSuccess &&\n cacheEnabled &&\n data;\n\n if (shouldReturnData) return data; // Data are already fetched and should be returned directly. Avoid fetching again.\n\n return await revalidate(...args);\n }) as T;\n\n /**\n * HANDLE SYNCHRONIZATION HOOKS DISACTIVATION\n *\n * If one instance of the hook is disabled, the other instances should be disabled too.\n * This is to prevent inconsistencies in the state of the hook.\n */\n useEffect(() => {\n if (enabled !== isEnabled) {\n setQueryState(keyWithArgs, {\n isEnabled,\n });\n }\n }, [enabled, isEnabled, keyWithArgs]);\n\n /**\n * HANDLE LOCAL STORAGE LOADING\n *\n * If store is enabled, load data from local storage\n */\n useEffect(() => {\n if (!isEnabled || !enabled) return; // Hook is disabled\n if (!storeEnabled) return; // Hook should not use local storage\n if (isInvalidated || isFetched || data) return; // Hook have been already mounted and fetched or invalidated\n\n const storedData = localStorage.getItem(keyWithArgs);\n\n // Wrap parsing in a try-catch block to handle invalid JSON data\n try {\n if (storedData) {\n setQueryState(keyWithArgs, {\n data: JSON.parse(storedData),\n });\n }\n } catch (error) {\n console.error(error);\n }\n }, [\n storeEnabled,\n keyWithArgs,\n isFetched,\n isInvalidated,\n isEnabled,\n enabled,\n data,\n ]);\n\n /**\n * HANDLE AUTO-FETCH ON HOOK MOUNT\n *\n * If autoFetch is enabled, fetch the data when the hook is mounted\n */\n useEffect(() => {\n if (!autoFetch) return; // Auto-fetch is disabled\n if (!isEnabled || !enabled) return; // Hook is disabled\n if (isFetched && !isInvalidated) return; // Hook have already fetched or invalidated\n if (isLoading) return; // Fetch is already in progress\n\n fetch(...storedArgsRef.current);\n }, [\n autoFetch,\n isEnabled,\n enabled,\n isFetched,\n isInvalidated,\n isLoading,\n fetch,\n ]);\n\n /**\n * HANDLE RETRY\n *\n * If fetching fails, retry the fetch after a certain time\n */\n useEffect(() => {\n const isRetryEnabled = errorCount > 0 && retryLimit > 0;\n const isRetryLimitReached = errorCount > retryLimit;\n\n if (!isEnabled || !enabled) return; // Hook is disabled\n if (!isRetryEnabled) return; // Retry is disabled\n if (isRetryLimitReached) return; // Retry limit has been reached\n if (isLoading) return; // Fetch is already in progress\n if (isSuccess) return; // Hook has already fetched successfully\n\n const timeout = setTimeout(() => {\n fetch(...storedArgsRef.current);\n }, retryTime);\n\n return () => clearTimeout(timeout);\n }, [\n isEnabled,\n errorCount,\n retryLimit,\n enabled,\n retryTime,\n isSuccess,\n isLoading,\n fetch,\n ]);\n\n /**\n * HANDLE PERIODIC REVALIDATION\n *\n * If revalidation is enabled, revalidate the data periodically\n */\n useEffect(() => {\n if (!revalidationEnabled || revalidateTime <= 0) return; // Revalidation is disabled\n if (!isEnabled || !enabled) return; // Hook is disabled\n if (isLoading) return; // Fetch is already in progress\n if (!isSuccess || !fetchedDateTime) return; // Should retry either of revalidate\n\n const timeout = setTimeout(() => {\n fetch(...storedArgsRef.current);\n }, revalidateTime);\n\n return () => clearTimeout(timeout);\n }, [\n revalidationEnabled,\n revalidateTime,\n isSuccess,\n fetchedDateTime,\n isLoading,\n isEnabled,\n enabled,\n fetch,\n ]);\n\n // Memoization of the setData function to prevent unnecessary re-renders\n const setDataMemo = (data: Awaited<ReturnType<T> | null>) => {\n setQueryState(keyWithArgs, {\n data,\n });\n };\n\n const abort = () => {\n if (controllerRef.current) {\n controllerRef.current.abort();\n }\n };\n\n // Memoization to prevent unnecessary re-renders\n const memoResult = {\n isFetched,\n isInvalidated,\n error,\n data,\n errorCount,\n isSuccess,\n isEnabled,\n isDisabled: !isEnabled,\n isLoading,\n isWaitingData: isLoading && !isFetched && !data, // Check if the data is still being fetched. Stay at true during revalidation or if data are stored in local storage\n isRevalidating: isLoading && isFetched, // Check if the data is valid and is being revalidated\n [key]: execute, // Name the execute function as the given key to avoid conflicts with other hooks (e.g. `const { fetchUser } = useAsync('fetchUser', () => fetchUserFunction());`)\n revalidate,\n setData: setDataMemo,\n abort,\n };\n\n useEffect(\n () => () => {\n // Clean up the controller on unmount\n if (controllerRef.current) {\n controllerRef.current.abort();\n }\n },\n []\n );\n\n // Return the hook's result, including all state and control functions\n return memoResult as UseAsyncResultBase<T> & Record<U, T>;\n};\n"],"names":["args","keyWithArgs","error","data"],"mappings":";;;AAMA,MAAM,sCAAsB,IAAI;AAsChC,MAAM,wBAAwB;AAC9B,MAAM,wBAAwB;AAC9B,MAAM,kBAAkB;AACxB,MAAM,qBAAqB;AAC3B,MAAM,sBAAsB;AAC5B,MAAM,+BAA+B;AACrC,MAAM,0BAA0B,IAAI,KAAK;AACzC,MAAM,qBAAqB,IAAI,KAAK;AAQpC,MAAM,UAAU,CAAC,SACf,OAAQ,MAAM,QAAQ,IAAI,IAAI,OAAO,CAAC,IAAI,IAAK,CAAC;AAElD,MAAM,iBAAiB,CAAC,KAAa,SACnC,QAAQ,IAAI,EAAE,SAAS,IAAI,GAAG,GAAG,IAAI,KAAK,UAAU,IAAI,CAAC,KAAK;AAwCzD,MAAM,WAAW,CAItB,KACA,eACA,YACyB;AAEnB,QAAA,aAAa,SAAS,cAAc;AACpC,QAAA,YAAY,SAAS,aAAa;AAClC,QAAA,YAAY,SAAS,aAAa;AAClC,QAAA,eAAe,SAAS,SAAS;AACjC,QAAA,eAAe,SAAS,SAAS;AACjC,QAAA,UAAU,SAAS,UAAU;AAC7B,QAAA,sBACJ,SAAS,gBAAgB;AACrB,QAAA,iBAAiB,SAAS,kBAAkB;AAC5C,QAAA,gBAAgB,SAAS,iBAAiB,CAAC;AAC3C,QAAA,oBAAoB,SAAS,qBAAqB,CAAC;AACzD,QAAM,YAAY,SAAS;AAC3B,QAAM,UAAU,SAAS;AACzB,QAAM,OAAO,QAAQ,SAAS,QAAQ,CAAA,CAAE;AAGxC,QAAM,EAAE,WAAW,eAAe,iBAAiB,iBAAA,IACjD,cAAc;AAGV,QAAA,gBAAgB,OAAc,IAAI;AAElC,QAAA,gBAAgB,OAA+B,IAAI;AAGzD,QAAM,cAAc,eAAe,KAAK,cAAc,OAAO;AAGvD,QAA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AEhC;AAGA,QAAM,aAAa;AAAA,IACjB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,YAAY,CAAC;AAAA,IACb;AAAA,IACA,eAAe,aAAa,CAAC,aAAa,CAAC;AAAA;AAAA,IAC3C,gBAAgB,aAAa;AAAA;AAAA,IAC7B,CAAC,GAAG,GAAG;AAAA;AAAA,IACP;AAAA,IACA,SAAS;AAAA,IACT;AAAA,EACF;AAEA;AAAA,IACE,MAAM,MAAM;AAEV,UAAI,cAAc,SAAS;AACzB,sBAAc,QAAQ,MAAM;AAAA,MAAA;AAAA,IAEhC;AAAA,IACA,CAAA;AAAA,EACF;AAGO,SAAA;AACT;"}
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const hooks_useAuth_useAuth = require("./useAuth.cjs");
4
+ const hooks_useAuth_useOAuth2 = require("./useOAuth2.cjs");
5
+ const hooks_useAuth_useSession = require("./useSession.cjs");
6
+ exports.useAuth = hooks_useAuth_useAuth.useAuth;
7
+ exports.useOAuth2 = hooks_useAuth_useOAuth2.useOAuth2;
8
+ exports.useSession = hooks_useAuth_useSession.useSession;
9
+ //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;"}
1
+ {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;"}
@@ -0,0 +1,4 @@
1
+ export * from './useAuth';
2
+ export * from './useOAuth2';
3
+ export * from './useSession';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/useAuth/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { useAuth } from "./useAuth.mjs";
2
+ import { useOAuth2 } from "./useOAuth2.mjs";
3
+ import { useSession } from "./useSession.mjs";
4
+ export {
5
+ useAuth,
6
+ useOAuth2,
7
+ useSession
8
+ };
9
+ //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
1
+ {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;"}