@intlayer/design-system 3.5.3 → 3.5.5
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.
- package/README.md +1 -1
- package/dist/.vite/manifest.json +274 -125
- package/dist/CopyButton-Cxu3goRg.cjs +59 -0
- package/dist/CopyButton-Cxu3goRg.cjs.map +1 -0
- package/dist/CopyButton-DlcDlf6U.js +60 -0
- package/dist/CopyButton-DlcDlf6U.js.map +1 -0
- package/dist/components/Auth/AuthModal/index.cjs +4 -0
- package/dist/components/Auth/AuthModal/index.cjs.map +1 -1
- package/dist/components/Auth/AuthModal/index.mjs +4 -0
- package/dist/components/Auth/AuthModal/index.mjs.map +1 -1
- package/dist/components/Auth/ChangePasswordForm/ChangePasswordForm.cjs +5 -4
- package/dist/components/Auth/ChangePasswordForm/ChangePasswordForm.cjs.map +1 -1
- package/dist/components/Auth/ChangePasswordForm/ChangePasswordForm.d.ts +1 -1
- package/dist/components/Auth/ChangePasswordForm/ChangePasswordForm.d.ts.map +1 -1
- package/dist/components/Auth/ChangePasswordForm/ChangePasswordForm.mjs +5 -4
- package/dist/components/Auth/ChangePasswordForm/ChangePasswordForm.mjs.map +1 -1
- package/dist/components/Auth/ChangePasswordForm/changePasswordForm.content.cjs +170 -0
- package/dist/components/Auth/ChangePasswordForm/changePasswordForm.content.cjs.map +1 -0
- package/dist/components/Auth/ChangePasswordForm/changePasswordForm.content.d.ts +26 -0
- package/dist/components/Auth/ChangePasswordForm/changePasswordForm.content.d.ts.map +1 -0
- package/dist/components/Auth/ChangePasswordForm/changePasswordForm.content.mjs +170 -0
- package/dist/components/Auth/ChangePasswordForm/changePasswordForm.content.mjs.map +1 -0
- package/dist/components/Auth/ChangePasswordForm/index.cjs +2 -2
- package/dist/components/Auth/ChangePasswordForm/index.d.ts +1 -1
- package/dist/components/Auth/ChangePasswordForm/index.d.ts.map +1 -1
- package/dist/components/Auth/ChangePasswordForm/index.mjs +2 -2
- package/dist/components/Auth/ChangePasswordForm/useChangePasswordSchema.cjs +37 -0
- package/dist/components/Auth/ChangePasswordForm/useChangePasswordSchema.cjs.map +1 -0
- package/dist/components/Auth/ChangePasswordForm/useChangePasswordSchema.content.cjs +131 -0
- package/dist/components/Auth/ChangePasswordForm/useChangePasswordSchema.content.cjs.map +1 -0
- package/dist/components/Auth/ChangePasswordForm/useChangePasswordSchema.content.d.ts +15 -0
- package/dist/components/Auth/ChangePasswordForm/useChangePasswordSchema.content.d.ts.map +1 -0
- package/dist/components/Auth/ChangePasswordForm/useChangePasswordSchema.content.mjs +131 -0
- package/dist/components/Auth/ChangePasswordForm/useChangePasswordSchema.content.mjs.map +1 -0
- package/dist/components/Auth/ChangePasswordForm/{ChangePasswordSchema.d.ts → useChangePasswordSchema.d.ts} +3 -3
- package/dist/components/Auth/ChangePasswordForm/useChangePasswordSchema.d.ts.map +1 -0
- package/dist/components/Auth/ChangePasswordForm/useChangePasswordSchema.mjs +37 -0
- package/dist/components/Auth/ChangePasswordForm/useChangePasswordSchema.mjs.map +1 -0
- package/dist/components/Auth/ExternalsLoginButtons/ExternalsLoginButtons.cjs +11 -10
- package/dist/components/Auth/ExternalsLoginButtons/ExternalsLoginButtons.cjs.map +1 -1
- package/dist/components/Auth/ExternalsLoginButtons/ExternalsLoginButtons.d.ts.map +1 -1
- package/dist/components/Auth/ExternalsLoginButtons/ExternalsLoginButtons.mjs +12 -11
- package/dist/components/Auth/ExternalsLoginButtons/ExternalsLoginButtons.mjs.map +1 -1
- package/dist/components/Auth/ExternalsLoginButtons/externalsLoginButtons.content.cjs +86 -32
- package/dist/components/Auth/ExternalsLoginButtons/externalsLoginButtons.content.cjs.map +1 -1
- package/dist/components/Auth/ExternalsLoginButtons/externalsLoginButtons.content.d.ts +13 -9
- package/dist/components/Auth/ExternalsLoginButtons/externalsLoginButtons.content.d.ts.map +1 -1
- package/dist/components/Auth/ExternalsLoginButtons/externalsLoginButtons.content.mjs +85 -31
- package/dist/components/Auth/ExternalsLoginButtons/externalsLoginButtons.content.mjs.map +1 -1
- package/dist/components/Auth/ResetPasswordForm/ResetPasswordForm.cjs +5 -4
- package/dist/components/Auth/ResetPasswordForm/ResetPasswordForm.cjs.map +1 -1
- package/dist/components/Auth/ResetPasswordForm/ResetPasswordForm.d.ts +1 -1
- package/dist/components/Auth/ResetPasswordForm/ResetPasswordForm.d.ts.map +1 -1
- package/dist/components/Auth/ResetPasswordForm/ResetPasswordForm.mjs +5 -4
- package/dist/components/Auth/ResetPasswordForm/ResetPasswordForm.mjs.map +1 -1
- package/dist/components/Auth/ResetPasswordForm/index.cjs +2 -2
- package/dist/components/Auth/ResetPasswordForm/index.d.ts +1 -1
- package/dist/components/Auth/ResetPasswordForm/index.d.ts.map +1 -1
- package/dist/components/Auth/ResetPasswordForm/index.mjs +2 -2
- package/dist/components/Auth/ResetPasswordForm/resetPasswordContent.content.cjs +123 -0
- package/dist/components/Auth/ResetPasswordForm/resetPasswordContent.content.cjs.map +1 -0
- package/dist/components/Auth/ResetPasswordForm/resetPasswordContent.content.d.ts +21 -0
- package/dist/components/Auth/ResetPasswordForm/resetPasswordContent.content.d.ts.map +1 -0
- package/dist/components/Auth/ResetPasswordForm/resetPasswordContent.content.mjs +123 -0
- package/dist/components/Auth/ResetPasswordForm/resetPasswordContent.content.mjs.map +1 -0
- package/dist/components/Auth/ResetPasswordForm/useResetPasswordSchema.cjs +16 -0
- package/dist/components/Auth/ResetPasswordForm/useResetPasswordSchema.cjs.map +1 -0
- package/dist/components/Auth/ResetPasswordForm/useResetPasswordSchema.content.cjs +56 -0
- package/dist/components/Auth/ResetPasswordForm/useResetPasswordSchema.content.cjs.map +1 -0
- package/dist/components/Auth/ResetPasswordForm/useResetPasswordSchema.content.d.ts +10 -0
- package/dist/components/Auth/ResetPasswordForm/useResetPasswordSchema.content.d.ts.map +1 -0
- package/dist/components/Auth/ResetPasswordForm/useResetPasswordSchema.content.mjs +56 -0
- package/dist/components/Auth/ResetPasswordForm/useResetPasswordSchema.content.mjs.map +1 -0
- package/dist/components/Auth/ResetPasswordForm/useResetPasswordSchema.d.ts +10 -0
- package/dist/components/Auth/ResetPasswordForm/useResetPasswordSchema.d.ts.map +1 -0
- package/dist/components/Auth/ResetPasswordForm/useResetPasswordSchema.mjs +16 -0
- package/dist/components/Auth/ResetPasswordForm/useResetPasswordSchema.mjs.map +1 -0
- package/dist/components/Auth/SignInForm/SignInForm.cjs +22 -15
- package/dist/components/Auth/SignInForm/SignInForm.cjs.map +1 -1
- package/dist/components/Auth/SignInForm/SignInForm.d.ts +1 -1
- package/dist/components/Auth/SignInForm/SignInForm.d.ts.map +1 -1
- package/dist/components/Auth/SignInForm/SignInForm.mjs +22 -15
- package/dist/components/Auth/SignInForm/SignInForm.mjs.map +1 -1
- package/dist/components/Auth/SignInForm/index.cjs +2 -2
- package/dist/components/Auth/SignInForm/index.d.ts +1 -1
- package/dist/components/Auth/SignInForm/index.d.ts.map +1 -1
- package/dist/components/Auth/SignInForm/index.mjs +2 -2
- package/dist/components/Auth/SignInForm/signIn.content.cjs +217 -0
- package/dist/components/Auth/SignInForm/signIn.content.cjs.map +1 -0
- package/dist/components/Auth/SignInForm/signIn.content.d.ts +31 -0
- package/dist/components/Auth/SignInForm/signIn.content.d.ts.map +1 -0
- package/dist/components/Auth/SignInForm/signIn.content.mjs +217 -0
- package/dist/components/Auth/SignInForm/signIn.content.mjs.map +1 -0
- package/dist/components/Auth/SignInForm/useSignInSchema.cjs +25 -0
- package/dist/components/Auth/SignInForm/useSignInSchema.cjs.map +1 -0
- package/dist/components/Auth/SignInForm/useSignInSchema.content.cjs +71 -0
- package/dist/components/Auth/SignInForm/useSignInSchema.content.cjs.map +1 -0
- package/dist/components/Auth/SignInForm/useSignInSchema.content.d.ts +11 -0
- package/dist/components/Auth/SignInForm/useSignInSchema.content.d.ts.map +1 -0
- package/dist/components/Auth/SignInForm/useSignInSchema.content.mjs +71 -0
- package/dist/components/Auth/SignInForm/useSignInSchema.content.mjs.map +1 -0
- package/dist/components/Auth/SignInForm/{SignInSchema.d.ts → useSignInSchema.d.ts} +3 -3
- package/dist/components/Auth/SignInForm/useSignInSchema.d.ts.map +1 -0
- package/dist/components/Auth/SignInForm/useSignInSchema.mjs +25 -0
- package/dist/components/Auth/SignInForm/useSignInSchema.mjs.map +1 -0
- package/dist/components/Auth/SignUpForm/SignUpForm.cjs +4 -4
- package/dist/components/Auth/SignUpForm/SignUpForm.cjs.map +1 -1
- package/dist/components/Auth/SignUpForm/SignUpForm.d.ts +1 -1
- package/dist/components/Auth/SignUpForm/SignUpForm.d.ts.map +1 -1
- package/dist/components/Auth/SignUpForm/SignUpForm.mjs +3 -3
- package/dist/components/Auth/SignUpForm/SignUpForm.mjs.map +1 -1
- package/dist/components/Auth/SignUpForm/index.cjs +2 -2
- package/dist/components/Auth/SignUpForm/index.d.ts +1 -1
- package/dist/components/Auth/SignUpForm/index.d.ts.map +1 -1
- package/dist/components/Auth/SignUpForm/index.mjs +2 -2
- package/dist/components/Auth/SignUpForm/signUpForm.content.cjs +182 -0
- package/dist/components/Auth/SignUpForm/signUpForm.content.cjs.map +1 -0
- package/dist/components/Auth/SignUpForm/signUpForm.content.d.ts +24 -0
- package/dist/components/Auth/SignUpForm/signUpForm.content.d.ts.map +1 -0
- package/dist/components/Auth/SignUpForm/signUpForm.content.mjs +182 -0
- package/dist/components/Auth/SignUpForm/signUpForm.content.mjs.map +1 -0
- package/dist/components/Auth/SignUpForm/useSignUpSchema.cjs +36 -0
- package/dist/components/Auth/SignUpForm/useSignUpSchema.cjs.map +1 -0
- package/dist/components/Auth/SignUpForm/useSignUpSchema.content.cjs +116 -0
- package/dist/components/Auth/SignUpForm/useSignUpSchema.content.cjs.map +1 -0
- package/dist/components/Auth/SignUpForm/useSignUpSchema.content.d.ts +14 -0
- package/dist/components/Auth/SignUpForm/useSignUpSchema.content.d.ts.map +1 -0
- package/dist/components/Auth/SignUpForm/useSignUpSchema.content.mjs +116 -0
- package/dist/components/Auth/SignUpForm/useSignUpSchema.content.mjs.map +1 -0
- package/dist/components/Auth/SignUpForm/{SignUpSchema.d.ts → useSignUpSchema.d.ts} +3 -3
- package/dist/components/Auth/SignUpForm/useSignUpSchema.d.ts.map +1 -0
- package/dist/components/Auth/SignUpForm/useSignUpSchema.mjs +36 -0
- package/dist/components/Auth/SignUpForm/useSignUpSchema.mjs.map +1 -0
- package/dist/components/Auth/index.cjs +8 -8
- package/dist/components/Auth/index.mjs +8 -8
- package/dist/components/Auth/useAuth/useSession.cjs +1 -0
- package/dist/components/Auth/useAuth/useSession.cjs.map +1 -1
- package/dist/components/Auth/useAuth/useSession.mjs +1 -0
- package/dist/components/Auth/useAuth/useSession.mjs.map +1 -1
- package/dist/components/Breadcrumb/breadcrumb.content.cjs +26 -0
- package/dist/components/Breadcrumb/breadcrumb.content.cjs.map +1 -0
- package/dist/components/Breadcrumb/breadcrumb.content.d.ts +8 -0
- package/dist/components/Breadcrumb/breadcrumb.content.d.ts.map +1 -0
- package/dist/components/Breadcrumb/breadcrumb.content.mjs +26 -0
- package/dist/components/Breadcrumb/breadcrumb.content.mjs.map +1 -0
- package/dist/components/Breadcrumb/index.cjs +103 -34
- package/dist/components/Breadcrumb/index.cjs.map +1 -1
- package/dist/components/Breadcrumb/index.d.ts +6 -2
- package/dist/components/Breadcrumb/index.d.ts.map +1 -1
- package/dist/components/Breadcrumb/index.mjs +103 -34
- package/dist/components/Breadcrumb/index.mjs.map +1 -1
- package/dist/components/Button/Button.cjs +7 -8
- package/dist/components/Button/Button.cjs.map +1 -1
- package/dist/components/Button/Button.d.ts.map +1 -1
- package/dist/components/Button/Button.mjs +7 -8
- package/dist/components/Button/Button.mjs.map +1 -1
- package/dist/components/Container/index.cjs +2 -2
- package/dist/components/Container/index.cjs.map +1 -1
- package/dist/components/Container/index.mjs +2 -2
- package/dist/components/Container/index.mjs.map +1 -1
- package/dist/components/DictionaryEditor/ValidDictionaryChangeButtons.cjs.map +1 -1
- package/dist/components/DictionaryEditor/ValidDictionaryChangeButtons.d.ts.map +1 -1
- package/dist/components/DictionaryEditor/ValidDictionaryChangeButtons.mjs.map +1 -1
- package/dist/components/DictionaryEditor/index.cjs +4 -0
- package/dist/components/DictionaryEditor/index.cjs.map +1 -1
- package/dist/components/DictionaryEditor/index.mjs +4 -0
- package/dist/components/DictionaryEditor/index.mjs.map +1 -1
- package/dist/components/DictionaryEditor/useEditedContentStore.cjs +3 -0
- package/dist/components/DictionaryEditor/useEditedContentStore.cjs.map +1 -1
- package/dist/components/DictionaryEditor/useEditedContentStore.d.ts +2 -2
- package/dist/components/DictionaryEditor/useEditedContentStore.d.ts.map +1 -1
- package/dist/components/DictionaryEditor/useEditedContentStore.mjs +3 -0
- package/dist/components/DictionaryEditor/useEditedContentStore.mjs.map +1 -1
- package/dist/components/DictionaryEditor/useEditionPanelStore.cjs.map +1 -1
- package/dist/components/DictionaryEditor/useEditionPanelStore.d.ts +1 -1
- package/dist/components/DictionaryEditor/useEditionPanelStore.d.ts.map +1 -1
- package/dist/components/DictionaryEditor/useEditionPanelStore.mjs.map +1 -1
- package/dist/components/DictionaryEditor/validDictionaryChangeButtons.content.cjs +60 -6
- package/dist/components/DictionaryEditor/validDictionaryChangeButtons.content.cjs.map +1 -1
- package/dist/components/DictionaryEditor/validDictionaryChangeButtons.content.d.ts.map +1 -1
- package/dist/components/DictionaryEditor/validDictionaryChangeButtons.content.mjs +60 -6
- package/dist/components/DictionaryEditor/validDictionaryChangeButtons.content.mjs.map +1 -1
- package/dist/components/DictionaryFieldEditor/DictionariesSelector/DictionariesSelector.cjs +7 -5
- package/dist/components/DictionaryFieldEditor/DictionariesSelector/DictionariesSelector.cjs.map +1 -1
- package/dist/components/DictionaryFieldEditor/DictionariesSelector/DictionariesSelector.d.ts +1 -0
- package/dist/components/DictionaryFieldEditor/DictionariesSelector/DictionariesSelector.d.ts.map +1 -1
- package/dist/components/DictionaryFieldEditor/DictionariesSelector/DictionariesSelector.mjs +7 -5
- package/dist/components/DictionaryFieldEditor/DictionariesSelector/DictionariesSelector.mjs.map +1 -1
- package/dist/components/DictionaryFieldEditor/DictionariesSelector/dictionariesSelector.content.cjs +22 -2
- package/dist/components/DictionaryFieldEditor/DictionariesSelector/dictionariesSelector.content.cjs.map +1 -1
- package/dist/components/DictionaryFieldEditor/DictionariesSelector/dictionariesSelector.content.d.ts.map +1 -1
- package/dist/components/DictionaryFieldEditor/DictionariesSelector/dictionariesSelector.content.mjs +22 -2
- package/dist/components/DictionaryFieldEditor/DictionariesSelector/dictionariesSelector.content.mjs.map +1 -1
- package/dist/components/DictionaryFieldEditor/DictionaryCreationForm/DictionaryCreationForm.cjs +14 -6
- package/dist/components/DictionaryFieldEditor/DictionaryCreationForm/DictionaryCreationForm.cjs.map +1 -1
- package/dist/components/DictionaryFieldEditor/DictionaryCreationForm/DictionaryCreationForm.mjs +14 -6
- package/dist/components/DictionaryFieldEditor/DictionaryCreationForm/DictionaryCreationForm.mjs.map +1 -1
- package/dist/components/DictionaryFieldEditor/DictionaryCreationForm/dictionaryCreationForm.content.cjs +151 -21
- package/dist/components/DictionaryFieldEditor/DictionaryCreationForm/dictionaryCreationForm.content.cjs.map +1 -1
- package/dist/components/DictionaryFieldEditor/DictionaryCreationForm/dictionaryCreationForm.content.d.ts.map +1 -1
- package/dist/components/DictionaryFieldEditor/DictionaryCreationForm/dictionaryCreationForm.content.mjs +151 -21
- package/dist/components/DictionaryFieldEditor/DictionaryCreationForm/dictionaryCreationForm.content.mjs.map +1 -1
- package/dist/components/DictionaryFieldEditor/DictionaryCreationForm/useDictionaryFormSchema.cjs +27 -0
- package/dist/components/DictionaryFieldEditor/DictionaryCreationForm/useDictionaryFormSchema.cjs.map +1 -0
- package/dist/components/DictionaryFieldEditor/DictionaryCreationForm/useDictionaryFormSchema.content.cjs +71 -0
- package/dist/components/DictionaryFieldEditor/DictionaryCreationForm/useDictionaryFormSchema.content.cjs.map +1 -0
- package/dist/components/DictionaryFieldEditor/DictionaryCreationForm/useDictionaryFormSchema.content.d.ts +11 -0
- package/dist/components/DictionaryFieldEditor/DictionaryCreationForm/useDictionaryFormSchema.content.d.ts.map +1 -0
- package/dist/components/DictionaryFieldEditor/DictionaryCreationForm/useDictionaryFormSchema.content.mjs +71 -0
- package/dist/components/DictionaryFieldEditor/DictionaryCreationForm/useDictionaryFormSchema.content.mjs.map +1 -0
- package/dist/components/DictionaryFieldEditor/DictionaryCreationForm/{dictionaryFormSchema.d.ts → useDictionaryFormSchema.d.ts} +3 -3
- package/dist/components/DictionaryFieldEditor/DictionaryCreationForm/useDictionaryFormSchema.d.ts.map +1 -0
- package/dist/components/DictionaryFieldEditor/DictionaryCreationForm/useDictionaryFormSchema.mjs +27 -0
- package/dist/components/DictionaryFieldEditor/DictionaryCreationForm/useDictionaryFormSchema.mjs.map +1 -0
- package/dist/components/DictionaryFieldEditor/DictionaryDetails/DictionaryDetailsForm.cjs +24 -16
- package/dist/components/DictionaryFieldEditor/DictionaryDetails/DictionaryDetailsForm.cjs.map +1 -1
- package/dist/components/DictionaryFieldEditor/DictionaryDetails/DictionaryDetailsForm.mjs +24 -16
- package/dist/components/DictionaryFieldEditor/DictionaryDetails/DictionaryDetailsForm.mjs.map +1 -1
- package/dist/components/DictionaryFieldEditor/DictionaryDetails/dictionaryDetails.content.cjs +176 -16
- package/dist/components/DictionaryFieldEditor/DictionaryDetails/dictionaryDetails.content.cjs.map +1 -1
- package/dist/components/DictionaryFieldEditor/DictionaryDetails/dictionaryDetails.content.d.ts.map +1 -1
- package/dist/components/DictionaryFieldEditor/DictionaryDetails/dictionaryDetails.content.mjs +176 -16
- package/dist/components/DictionaryFieldEditor/DictionaryDetails/dictionaryDetails.content.mjs.map +1 -1
- package/dist/components/DictionaryFieldEditor/DictionaryDetails/useDictionaryDetailsSchema.cjs +44 -0
- package/dist/components/DictionaryFieldEditor/DictionaryDetails/useDictionaryDetailsSchema.cjs.map +1 -0
- package/dist/components/DictionaryFieldEditor/DictionaryDetails/useDictionaryDetailsSchema.content.cjs +176 -0
- package/dist/components/DictionaryFieldEditor/DictionaryDetails/useDictionaryDetailsSchema.content.cjs.map +1 -0
- package/dist/components/DictionaryFieldEditor/DictionaryDetails/useDictionaryDetailsSchema.content.d.ts +17 -0
- package/dist/components/DictionaryFieldEditor/DictionaryDetails/useDictionaryDetailsSchema.content.d.ts.map +1 -0
- package/dist/components/DictionaryFieldEditor/DictionaryDetails/useDictionaryDetailsSchema.content.mjs +176 -0
- package/dist/components/DictionaryFieldEditor/DictionaryDetails/useDictionaryDetailsSchema.content.mjs.map +1 -0
- package/dist/components/DictionaryFieldEditor/DictionaryDetails/{DictionaryDetailsSchema.d.ts → useDictionaryDetailsSchema.d.ts} +3 -3
- package/dist/components/DictionaryFieldEditor/DictionaryDetails/useDictionaryDetailsSchema.d.ts.map +1 -0
- package/dist/components/DictionaryFieldEditor/DictionaryDetails/useDictionaryDetailsSchema.mjs +44 -0
- package/dist/components/DictionaryFieldEditor/DictionaryDetails/useDictionaryDetailsSchema.mjs.map +1 -0
- package/dist/components/DictionaryFieldEditor/DictionaryFieldEditor.cjs +6 -3
- package/dist/components/DictionaryFieldEditor/DictionaryFieldEditor.cjs.map +1 -1
- package/dist/components/DictionaryFieldEditor/DictionaryFieldEditor.d.ts +1 -0
- package/dist/components/DictionaryFieldEditor/DictionaryFieldEditor.d.ts.map +1 -1
- package/dist/components/DictionaryFieldEditor/DictionaryFieldEditor.mjs +6 -3
- package/dist/components/DictionaryFieldEditor/DictionaryFieldEditor.mjs.map +1 -1
- package/dist/components/DictionaryFieldEditor/EditorView/TextEditor.cjs +2 -2
- package/dist/components/DictionaryFieldEditor/EditorView/TextEditor.cjs.map +1 -1
- package/dist/components/DictionaryFieldEditor/EditorView/TextEditor.mjs +2 -2
- package/dist/components/DictionaryFieldEditor/EditorView/TextEditor.mjs.map +1 -1
- package/dist/components/DictionaryFieldEditor/JSONEditor.cjs +20 -18
- package/dist/components/DictionaryFieldEditor/JSONEditor.cjs.map +1 -1
- package/dist/components/DictionaryFieldEditor/JSONEditor.d.ts +1 -0
- package/dist/components/DictionaryFieldEditor/JSONEditor.d.ts.map +1 -1
- package/dist/components/DictionaryFieldEditor/JSONEditor.mjs +20 -18
- package/dist/components/DictionaryFieldEditor/JSONEditor.mjs.map +1 -1
- package/dist/components/DictionaryFieldEditor/KeyPathBreadcrumb.cjs +10 -2
- package/dist/components/DictionaryFieldEditor/KeyPathBreadcrumb.cjs.map +1 -1
- package/dist/components/DictionaryFieldEditor/KeyPathBreadcrumb.d.ts +2 -0
- package/dist/components/DictionaryFieldEditor/KeyPathBreadcrumb.d.ts.map +1 -1
- package/dist/components/DictionaryFieldEditor/KeyPathBreadcrumb.mjs +10 -2
- package/dist/components/DictionaryFieldEditor/KeyPathBreadcrumb.mjs.map +1 -1
- package/dist/components/DictionaryFieldEditor/NavigationView/navigationViewNode.content.cjs +121 -11
- package/dist/components/DictionaryFieldEditor/NavigationView/navigationViewNode.content.cjs.map +1 -1
- package/dist/components/DictionaryFieldEditor/NavigationView/navigationViewNode.content.d.ts.map +1 -1
- package/dist/components/DictionaryFieldEditor/NavigationView/navigationViewNode.content.mjs +121 -11
- package/dist/components/DictionaryFieldEditor/NavigationView/navigationViewNode.content.mjs.map +1 -1
- package/dist/components/DictionaryFieldEditor/NodeEditor.cjs +10 -14
- package/dist/components/DictionaryFieldEditor/NodeEditor.cjs.map +1 -1
- package/dist/components/DictionaryFieldEditor/NodeEditor.d.ts.map +1 -1
- package/dist/components/DictionaryFieldEditor/NodeEditor.mjs +10 -14
- package/dist/components/DictionaryFieldEditor/NodeEditor.mjs.map +1 -1
- package/dist/components/DictionaryFieldEditor/SaveForm/SaveForm.cjs +63 -20
- package/dist/components/DictionaryFieldEditor/SaveForm/SaveForm.cjs.map +1 -1
- package/dist/components/DictionaryFieldEditor/SaveForm/SaveForm.d.ts.map +1 -1
- package/dist/components/DictionaryFieldEditor/SaveForm/SaveForm.mjs +66 -23
- package/dist/components/DictionaryFieldEditor/SaveForm/SaveForm.mjs.map +1 -1
- package/dist/components/DictionaryFieldEditor/SaveForm/saveForm.content.cjs +98 -6
- package/dist/components/DictionaryFieldEditor/SaveForm/saveForm.content.cjs.map +1 -1
- package/dist/components/DictionaryFieldEditor/SaveForm/saveForm.content.d.ts +4 -0
- package/dist/components/DictionaryFieldEditor/SaveForm/saveForm.content.d.ts.map +1 -1
- package/dist/components/DictionaryFieldEditor/SaveForm/saveForm.content.mjs +98 -6
- package/dist/components/DictionaryFieldEditor/SaveForm/saveForm.content.mjs.map +1 -1
- package/dist/components/DictionaryFieldEditor/dictionaryFieldEditor.content.cjs +44 -4
- package/dist/components/DictionaryFieldEditor/dictionaryFieldEditor.content.cjs.map +1 -1
- package/dist/components/DictionaryFieldEditor/dictionaryFieldEditor.content.d.ts.map +1 -1
- package/dist/components/DictionaryFieldEditor/dictionaryFieldEditor.content.mjs +44 -4
- package/dist/components/DictionaryFieldEditor/dictionaryFieldEditor.content.mjs.map +1 -1
- package/dist/components/DictionaryFieldEditor/editorView.content.cjs +77 -7
- package/dist/components/DictionaryFieldEditor/editorView.content.cjs.map +1 -1
- package/dist/components/DictionaryFieldEditor/editorView.content.d.ts.map +1 -1
- package/dist/components/DictionaryFieldEditor/editorView.content.mjs +77 -7
- package/dist/components/DictionaryFieldEditor/editorView.content.mjs.map +1 -1
- package/dist/components/DictionaryFieldEditor/nodeTypeSelector.content.cjs +66 -6
- package/dist/components/DictionaryFieldEditor/nodeTypeSelector.content.cjs.map +1 -1
- package/dist/components/DictionaryFieldEditor/nodeTypeSelector.content.d.ts.map +1 -1
- package/dist/components/DictionaryFieldEditor/nodeTypeSelector.content.mjs +66 -6
- package/dist/components/DictionaryFieldEditor/nodeTypeSelector.content.mjs.map +1 -1
- package/dist/components/DropDown/index.cjs.map +1 -1
- package/dist/components/DropDown/index.d.ts +18 -1
- package/dist/components/DropDown/index.d.ts.map +1 -1
- package/dist/components/DropDown/index.mjs.map +1 -1
- package/dist/components/Headers/index.cjs +1 -1
- package/dist/components/Headers/index.cjs.map +1 -1
- package/dist/components/Headers/index.mjs +1 -1
- package/dist/components/Headers/index.mjs.map +1 -1
- package/dist/components/IDE/CodeRender copy.cjs +141 -0
- package/dist/components/IDE/CodeRender copy.cjs.map +1 -0
- package/dist/components/IDE/CodeRender copy.d.ts +14 -0
- package/dist/components/IDE/CodeRender copy.d.ts.map +1 -0
- package/dist/components/IDE/CodeRender copy.mjs +141 -0
- package/dist/components/IDE/CodeRender copy.mjs.map +1 -0
- package/dist/components/IDE/CodeRender.cjs +39 -625
- package/dist/components/IDE/CodeRender.cjs.map +1 -1
- package/dist/components/IDE/CodeRender.d.ts +4 -5
- package/dist/components/IDE/CodeRender.d.ts.map +1 -1
- package/dist/components/IDE/CodeRender.mjs +40 -604
- package/dist/components/IDE/CodeRender.mjs.map +1 -1
- package/dist/components/IDE/CopyButton.cjs +40 -0
- package/dist/components/IDE/CopyButton.cjs.map +1 -0
- package/dist/components/IDE/CopyButton.content.cjs +26 -0
- package/dist/components/IDE/CopyButton.content.cjs.map +1 -0
- package/dist/components/IDE/CopyButton.content.d.ts +8 -0
- package/dist/components/IDE/CopyButton.content.d.ts.map +1 -0
- package/dist/components/IDE/CopyButton.content.mjs +26 -0
- package/dist/components/IDE/CopyButton.content.mjs.map +1 -0
- package/dist/components/IDE/CopyButton.d.ts +7 -0
- package/dist/components/IDE/CopyButton.d.ts.map +1 -0
- package/dist/components/IDE/CopyButton.mjs +40 -0
- package/dist/components/IDE/CopyButton.mjs.map +1 -0
- package/dist/components/IDE/IDE.cjs +1 -1
- package/dist/components/IDE/IDE.cjs.map +1 -1
- package/dist/components/IDE/IDE.mjs +1 -1
- package/dist/components/IDE/IDE.mjs.map +1 -1
- package/dist/components/IDE/MarkDownRender.cjs +10 -2
- package/dist/components/IDE/MarkDownRender.cjs.map +1 -1
- package/dist/components/IDE/MarkDownRender.d.ts.map +1 -1
- package/dist/components/IDE/MarkDownRender.mjs +10 -2
- package/dist/components/IDE/MarkDownRender.mjs.map +1 -1
- package/dist/components/IDE/MonacoCode.cjs +129 -0
- package/dist/components/IDE/MonacoCode.cjs.map +1 -0
- package/dist/components/IDE/MonacoCode.d.ts +14 -0
- package/dist/components/IDE/MonacoCode.d.ts.map +1 -0
- package/dist/components/IDE/MonacoCode.mjs +129 -0
- package/dist/components/IDE/MonacoCode.mjs.map +1 -0
- package/dist/components/Link/Link.cjs +50 -31
- package/dist/components/Link/Link.cjs.map +1 -1
- package/dist/components/Link/Link.d.ts +3 -0
- package/dist/components/Link/Link.d.ts.map +1 -1
- package/dist/components/Link/Link.mjs +51 -32
- package/dist/components/Link/Link.mjs.map +1 -1
- package/dist/components/Link/index.cjs +1 -0
- package/dist/components/Link/index.cjs.map +1 -1
- package/dist/components/Link/index.mjs +3 -2
- package/dist/components/LocaleSwitcherDropDown/LocaleSwitcher.cjs +122 -42
- package/dist/components/LocaleSwitcherDropDown/LocaleSwitcher.cjs.map +1 -1
- package/dist/components/LocaleSwitcherDropDown/LocaleSwitcher.d.ts +2 -0
- package/dist/components/LocaleSwitcherDropDown/LocaleSwitcher.d.ts.map +1 -1
- package/dist/components/LocaleSwitcherDropDown/LocaleSwitcher.mjs +123 -43
- package/dist/components/LocaleSwitcherDropDown/LocaleSwitcher.mjs.map +1 -1
- package/dist/components/LocaleSwitcherDropDown/localeSwitcher.content.cjs +86 -0
- package/dist/components/LocaleSwitcherDropDown/localeSwitcher.content.cjs.map +1 -0
- package/dist/components/LocaleSwitcherDropDown/localeSwitcher.content.d.ts +14 -0
- package/dist/components/LocaleSwitcherDropDown/localeSwitcher.content.d.ts.map +1 -0
- package/dist/components/LocaleSwitcherDropDown/localeSwitcher.content.mjs +87 -0
- package/dist/components/LocaleSwitcherDropDown/localeSwitcher.content.mjs.map +1 -0
- package/dist/components/MarkDownRender/index.cjs +4 -2
- package/dist/components/MarkDownRender/index.cjs.map +1 -1
- package/dist/components/MarkDownRender/index.d.ts +3 -1
- package/dist/components/MarkDownRender/index.d.ts.map +1 -1
- package/dist/components/MarkDownRender/index.mjs +4 -2
- package/dist/components/MarkDownRender/index.mjs.map +1 -1
- package/dist/components/Modal/Modal.cjs +8 -10
- package/dist/components/Modal/Modal.cjs.map +1 -1
- package/dist/components/Modal/Modal.d.ts.map +1 -1
- package/dist/components/Modal/Modal.mjs +8 -10
- package/dist/components/Modal/Modal.mjs.map +1 -1
- package/dist/components/Navbar/DesktopNavbar.cjs +1 -1
- package/dist/components/Navbar/DesktopNavbar.cjs.map +1 -1
- package/dist/components/Navbar/DesktopNavbar.mjs +1 -1
- package/dist/components/Navbar/DesktopNavbar.mjs.map +1 -1
- package/dist/components/index.cjs +13 -8
- package/dist/components/index.cjs.map +1 -1
- package/dist/components/index.mjs +14 -9
- package/dist/components/index.mjs.map +1 -1
- package/dist/design-system.css +235 -0
- package/dist/hooks/index.cjs +6 -0
- package/dist/hooks/index.cjs.map +1 -1
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.mjs +7 -1
- package/dist/hooks/index.mjs.map +1 -1
- package/dist/hooks/intlayerAPIHooks.cjs +8 -2
- package/dist/hooks/intlayerAPIHooks.cjs.map +1 -1
- package/dist/hooks/intlayerAPIHooks.d.ts +4 -0
- package/dist/hooks/intlayerAPIHooks.d.ts.map +1 -1
- package/dist/hooks/intlayerAPIHooks.mjs +8 -2
- package/dist/hooks/intlayerAPIHooks.mjs.map +1 -1
- package/dist/hooks/useAsync/index.cjs +3 -0
- package/dist/hooks/useAsync/index.cjs.map +1 -1
- package/dist/hooks/useAsync/index.d.ts +1 -0
- package/dist/hooks/useAsync/index.d.ts.map +1 -1
- package/dist/hooks/useAsync/index.mjs +4 -1
- package/dist/hooks/useAsync/index.mjs.map +1 -1
- package/dist/hooks/useAsync/useAsync.cjs +2 -9
- package/dist/hooks/useAsync/useAsync.cjs.map +1 -1
- package/dist/hooks/useAsync/useAsync.d.ts.map +1 -1
- package/dist/hooks/useAsync/useAsync.mjs +3 -10
- package/dist/hooks/useAsync/useAsync.mjs.map +1 -1
- package/dist/hooks/useAsync/useAsyncStateStore.cjs +123 -69
- package/dist/hooks/useAsync/useAsyncStateStore.cjs.map +1 -1
- package/dist/hooks/useAsync/useAsyncStateStore.d.ts +35 -11
- package/dist/hooks/useAsync/useAsyncStateStore.d.ts.map +1 -1
- package/dist/hooks/useAsync/useAsyncStateStore.mjs +123 -69
- package/dist/hooks/useAsync/useAsyncStateStore.mjs.map +1 -1
- package/dist/hooks/useIntlayerAPI.d.ts +3 -0
- package/dist/hooks/useIntlayerAPI.d.ts.map +1 -1
- package/dist/hooks/useIsDarkMode.cjs +15 -0
- package/dist/hooks/useIsDarkMode.cjs.map +1 -0
- package/dist/hooks/useIsDarkMode.d.ts +2 -0
- package/dist/hooks/useIsDarkMode.d.ts.map +1 -0
- package/dist/hooks/useIsDarkMode.mjs +15 -0
- package/dist/hooks/useIsDarkMode.mjs.map +1 -0
- package/dist/libs/intlayer-api/ai.cjs +24 -0
- package/dist/libs/intlayer-api/ai.cjs.map +1 -0
- package/dist/libs/intlayer-api/ai.d.ts +10 -0
- package/dist/libs/intlayer-api/ai.d.ts.map +1 -0
- package/dist/libs/intlayer-api/ai.mjs +24 -0
- package/dist/libs/intlayer-api/ai.mjs.map +1 -0
- package/dist/libs/intlayer-api/index.cjs +3 -1
- package/dist/libs/intlayer-api/index.cjs.map +1 -1
- package/dist/libs/intlayer-api/index.d.ts +6 -0
- package/dist/libs/intlayer-api/index.d.ts.map +1 -1
- package/dist/libs/intlayer-api/index.mjs +3 -1
- package/dist/libs/intlayer-api/index.mjs.map +1 -1
- package/dist/tailwind.css +1 -1
- package/package.json +19 -16
- package/dist/__vite-browser-external-SDi5tJh6.cjs +0 -4
- package/dist/__vite-browser-external-SDi5tJh6.cjs.map +0 -1
- package/dist/__vite-browser-external-r74dyCO2.js +0 -5
- package/dist/__vite-browser-external-r74dyCO2.js.map +0 -1
- package/dist/components/Auth/ChangePasswordForm/ChangePasswordSchema.cjs +0 -66
- package/dist/components/Auth/ChangePasswordForm/ChangePasswordSchema.cjs.map +0 -1
- package/dist/components/Auth/ChangePasswordForm/ChangePasswordSchema.d.ts.map +0 -1
- package/dist/components/Auth/ChangePasswordForm/ChangePasswordSchema.mjs +0 -66
- package/dist/components/Auth/ChangePasswordForm/ChangePasswordSchema.mjs.map +0 -1
- package/dist/components/Auth/ChangePasswordForm/index.content.cjs +0 -67
- package/dist/components/Auth/ChangePasswordForm/index.content.cjs.map +0 -1
- package/dist/components/Auth/ChangePasswordForm/index.content.d.ts +0 -23
- package/dist/components/Auth/ChangePasswordForm/index.content.d.ts.map +0 -1
- package/dist/components/Auth/ChangePasswordForm/index.content.mjs +0 -67
- package/dist/components/Auth/ChangePasswordForm/index.content.mjs.map +0 -1
- package/dist/components/Auth/ResetPasswordForm/ResetPasswordSchema.cjs +0 -29
- package/dist/components/Auth/ResetPasswordForm/ResetPasswordSchema.cjs.map +0 -1
- package/dist/components/Auth/ResetPasswordForm/ResetPasswordSchema.d.ts +0 -10
- package/dist/components/Auth/ResetPasswordForm/ResetPasswordSchema.d.ts.map +0 -1
- package/dist/components/Auth/ResetPasswordForm/ResetPasswordSchema.mjs +0 -29
- package/dist/components/Auth/ResetPasswordForm/ResetPasswordSchema.mjs.map +0 -1
- package/dist/components/Auth/ResetPasswordForm/index.content.cjs +0 -50
- package/dist/components/Auth/ResetPasswordForm/index.content.cjs.map +0 -1
- package/dist/components/Auth/ResetPasswordForm/index.content.d.ts +0 -18
- package/dist/components/Auth/ResetPasswordForm/index.content.d.ts.map +0 -1
- package/dist/components/Auth/ResetPasswordForm/index.content.mjs +0 -50
- package/dist/components/Auth/ResetPasswordForm/index.content.mjs.map +0 -1
- package/dist/components/Auth/SignInForm/SignInSchema.cjs +0 -38
- package/dist/components/Auth/SignInForm/SignInSchema.cjs.map +0 -1
- package/dist/components/Auth/SignInForm/SignInSchema.d.ts.map +0 -1
- package/dist/components/Auth/SignInForm/SignInSchema.mjs +0 -38
- package/dist/components/Auth/SignInForm/SignInSchema.mjs.map +0 -1
- package/dist/components/Auth/SignInForm/index.content.cjs +0 -84
- package/dist/components/Auth/SignInForm/index.content.cjs.map +0 -1
- package/dist/components/Auth/SignInForm/index.content.d.ts +0 -28
- package/dist/components/Auth/SignInForm/index.content.d.ts.map +0 -1
- package/dist/components/Auth/SignInForm/index.content.mjs +0 -84
- package/dist/components/Auth/SignInForm/index.content.mjs.map +0 -1
- package/dist/components/Auth/SignUpForm/SignUpSchema.cjs +0 -61
- package/dist/components/Auth/SignUpForm/SignUpSchema.cjs.map +0 -1
- package/dist/components/Auth/SignUpForm/SignUpSchema.d.ts.map +0 -1
- package/dist/components/Auth/SignUpForm/SignUpSchema.mjs +0 -61
- package/dist/components/Auth/SignUpForm/SignUpSchema.mjs.map +0 -1
- package/dist/components/Auth/SignUpForm/index.content.cjs +0 -72
- package/dist/components/Auth/SignUpForm/index.content.cjs.map +0 -1
- package/dist/components/Auth/SignUpForm/index.content.d.ts +0 -24
- package/dist/components/Auth/SignUpForm/index.content.d.ts.map +0 -1
- package/dist/components/Auth/SignUpForm/index.content.mjs +0 -72
- package/dist/components/Auth/SignUpForm/index.content.mjs.map +0 -1
- package/dist/components/DictionaryFieldEditor/DictionaryCreationForm/dictionaryFormSchema.cjs +0 -40
- package/dist/components/DictionaryFieldEditor/DictionaryCreationForm/dictionaryFormSchema.cjs.map +0 -1
- package/dist/components/DictionaryFieldEditor/DictionaryCreationForm/dictionaryFormSchema.d.ts.map +0 -1
- package/dist/components/DictionaryFieldEditor/DictionaryCreationForm/dictionaryFormSchema.mjs +0 -40
- package/dist/components/DictionaryFieldEditor/DictionaryCreationForm/dictionaryFormSchema.mjs.map +0 -1
- package/dist/components/DictionaryFieldEditor/DictionaryDetails/DictionaryDetailsSchema.cjs +0 -85
- package/dist/components/DictionaryFieldEditor/DictionaryDetails/DictionaryDetailsSchema.cjs.map +0 -1
- package/dist/components/DictionaryFieldEditor/DictionaryDetails/DictionaryDetailsSchema.d.ts.map +0 -1
- package/dist/components/DictionaryFieldEditor/DictionaryDetails/DictionaryDetailsSchema.mjs +0 -85
- package/dist/components/DictionaryFieldEditor/DictionaryDetails/DictionaryDetailsSchema.mjs.map +0 -1
- package/dist/tailwind.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intlayerAPIHooks.mjs","sources":["../../__vite-browser-external","../../src/hooks/intlayerAPIHooks.ts"],"sourcesContent":["export default {}","/* eslint-disable @typescript-eslint/no-explicit-any */\n'use client';\n\nimport process from 'process';\nimport { intlayerAPI } from 'src/libs';\nimport { useAuth } from '../components/Auth/useAuth/index';\nimport { useToast } from '../components/Toaster';\nimport { useAsync, UseAsyncOptions } from './useAsync/useAsync';\nimport { useIntlayerAuth } from './useIntlayerAPI';\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 error = JSON.parse(errorMessage);\n } catch (e) {\n console.error(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:\n (process.env.NODE_ENV === 'production'\n ? error.title\n : error.code) ?? 'Error',\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 { csrfToken, oAuth2AccessToken, session } = useAuth();\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\n/**\n * Auth\n */\n\nexport const useLogin = (\n args?: UseAsyncOptions<typeof intlayerAPI.auth.login>\n) =>\n useAppAsync('login', useIntlayerAuth().auth.login, {\n invalidateQueries: ['getSession'],\n ...args,\n });\nexport const useRegister = (\n args?: UseAsyncOptions<typeof intlayerAPI.auth.register>\n) =>\n useAppAsync('register', useIntlayerAuth().auth.register, {\n invalidateQueries: ['getSession'],\n ...args,\n });\nexport const useLogout = (\n args?: UseAsyncOptions<typeof intlayerAPI.auth.logout>\n) =>\n useAppAsync('logout', useIntlayerAuth().auth.logout, {\n invalidateQueries: ['getSession'],\n ...args,\n });\nexport const useChangePassword = (\n args?: UseAsyncOptions<typeof intlayerAPI.auth.changePassword>\n) => useAppAsync('changePassword', useIntlayerAuth().auth.changePassword, args);\nexport const useAskResetPassword = (\n args?: UseAsyncOptions<typeof intlayerAPI.auth.askResetPassword>\n) =>\n useAppAsync(\n 'askResetPassword',\n useIntlayerAuth().auth.askResetPassword,\n args\n );\nexport const useResetPassword = (\n args?: UseAsyncOptions<typeof intlayerAPI.auth.resetPassword>\n) => useAppAsync('resetPassword', useIntlayerAuth().auth.resetPassword, args);\nexport const useCheckIfUserHasPassword = (\n args?: UseAsyncOptions<typeof intlayerAPI.auth.checkIfUserHasPassword>\n) =>\n useAppAsync(\n 'checkIfUserHasPassword',\n useIntlayerAuth().auth.checkIfUserHasPassword,\n args,\n {\n requireUser: true,\n }\n );\nexport const useVerifyEmail = (\n args?: UseAsyncOptions<typeof intlayerAPI.auth.verifyEmail>\n) => useAppAsync('verifyEmail', useIntlayerAuth().auth.verifyEmail, args);\n\nexport const useGetUserByAccount = (\n args?: UseAsyncOptions<typeof 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<typeof 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 );\nexport const useCreateUser = (\n args?: UseAsyncOptions<typeof intlayerAPI.user.createUser>\n) =>\n useAppAsync('createUser', useIntlayerAuth().user.createUser, {\n invalidateQueries: ['getUsers'],\n ...args,\n });\nexport const useUpdateUser = (\n args?: UseAsyncOptions<typeof intlayerAPI.user.updateUser>\n) =>\n useAppAsync('updateUser', useIntlayerAuth().user.updateUser, {\n invalidateQueries: ['getSession'],\n ...args,\n });\nexport const useDeleteUser = (\n args?: UseAsyncOptions<typeof 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<typeof 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<typeof intlayerAPI.organization.addOrganization>\n) =>\n useAppAsync(\n 'addOrganization',\n useIntlayerAuth().organization.addOrganization,\n {\n invalidateQueries: ['getOrganizations'],\n ...args,\n }\n );\nexport const useUpdateOrganization = (\n args?: UseAsyncOptions<typeof intlayerAPI.organization.updateOrganization>\n) =>\n useAppAsync(\n 'updateOrganization',\n useIntlayerAuth().organization.updateOrganization,\n {\n invalidateQueries: ['getSession'],\n ...args,\n }\n );\nexport const useUpdateOrganizationMembers = (\n args?: UseAsyncOptions<\n typeof intlayerAPI.organization.updateOrganizationMembers\n >\n) =>\n useAppAsync(\n 'updateOrganizationMembers',\n useIntlayerAuth().organization.updateOrganizationMembers,\n {\n invalidateQueries: ['getOrganizations'],\n ...args,\n }\n );\nexport const useAddOrganizationMember = (\n args?: UseAsyncOptions<typeof intlayerAPI.organization.addOrganizationMember>\n) =>\n useAppAsync(\n 'addOrganizationMember',\n useIntlayerAuth().organization.addOrganizationMember,\n {\n invalidateQueries: ['getOrganizations'],\n ...args,\n }\n );\nexport const useDeleteOrganization = (\n args?: UseAsyncOptions<typeof intlayerAPI.organization.deleteOrganization>\n) =>\n useAppAsync(\n 'deleteOrganization',\n useIntlayerAuth().organization.deleteOrganization,\n {\n invalidateQueries: ['getOrganizations'],\n ...args,\n }\n );\nexport const useSelectOrganization = (\n args?: UseAsyncOptions<typeof intlayerAPI.organization.selectOrganization>\n) =>\n useAppAsync(\n 'selectOrganization',\n useIntlayerAuth().organization.selectOrganization,\n {\n invalidateQueries: ['getSession'],\n ...args,\n }\n );\nexport const useUnselectOrganization = (\n args?: UseAsyncOptions<typeof 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<typeof 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 );\nexport const useAddProject = (\n args?: UseAsyncOptions<typeof intlayerAPI.project.addProject>\n) =>\n useAppAsync('addProject', useIntlayerAuth().project.addProject, {\n invalidateQueries: ['getProjects'],\n ...args,\n });\nexport const useUpdateProject = (\n args?: UseAsyncOptions<typeof intlayerAPI.project.updateProject>\n) =>\n useAppAsync('updateProject', useIntlayerAuth().project.updateProject, {\n invalidateQueries: ['getSession'],\n ...args,\n });\nexport const useUpdateProjectMembers = (\n args?: UseAsyncOptions<typeof intlayerAPI.project.updateProjectMembers>\n) =>\n useAppAsync(\n 'updateProjectMembers',\n useIntlayerAuth().project.updateProjectMembers,\n {\n invalidateQueries: ['getSession'],\n ...args,\n }\n );\nexport const useDeleteProject = (\n args?: UseAsyncOptions<typeof intlayerAPI.project.deleteProject>\n) =>\n useAppAsync('deleteProject', useIntlayerAuth().project.deleteProject, {\n invalidateQueries: ['getProjects'],\n ...args,\n });\nexport const useSelectProject = (\n args?: UseAsyncOptions<typeof intlayerAPI.project.selectProject>\n) =>\n useAppAsync('selectProject', useIntlayerAuth().project.selectProject, {\n invalidateQueries: ['getSession'],\n ...args,\n });\nexport const useUnselectProject = (\n args?: UseAsyncOptions<typeof intlayerAPI.project.unselectProject>\n) =>\n useAppAsync('unselectProject', useIntlayerAuth().project.unselectProject, {\n invalidateQueries: ['getSession'],\n ...args,\n });\nexport const useAddNewAccessKey = (\n args?: UseAsyncOptions<typeof intlayerAPI.project.addNewAccessKey>\n) =>\n useAppAsync('addNewAccessKey', useIntlayerAuth().project.addNewAccessKey, {\n invalidateQueries: ['getSession'],\n ...args,\n });\nexport const useDeleteAccessKey = (\n args?: UseAsyncOptions<typeof intlayerAPI.project.deleteAccessKey>\n) =>\n useAppAsync('deleteAccessKey', useIntlayerAuth().project.deleteAccessKey, {\n invalidateQueries: ['getSession'],\n ...args,\n });\nexport const useRefreshAccessKey = (\n args?: UseAsyncOptions<typeof 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<typeof 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<typeof 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<typeof 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 );\nexport const useAddDictionary = (\n args?: UseAsyncOptions<typeof intlayerAPI.dictionary.addDictionary>\n) =>\n useAppAsync('addDictionary', useIntlayerAuth().dictionary.addDictionary, {\n invalidateQueries: ['getDictionaries', 'getDictionariesKeys'],\n ...args,\n });\n\nexport const usePushDictionaries = (\n args?: UseAsyncOptions<typeof intlayerAPI.dictionary.pushDictionaries>\n) =>\n useAppAsync(\n 'pushDictionaries',\n useIntlayerAuth().dictionary.pushDictionaries,\n {\n invalidateQueries: ['getDictionaries', 'getDictionariesKeys'],\n ...args,\n }\n );\nexport const useUpdateDictionary = (\n args?: UseAsyncOptions<typeof intlayerAPI.dictionary.updateDictionary>\n) =>\n useAppAsync(\n 'updateDictionary',\n useIntlayerAuth().dictionary.updateDictionary,\n {\n invalidateQueries: ['getDictionaries'],\n ...args,\n }\n );\nexport const useDeleteDictionary = (\n args?: UseAsyncOptions<typeof intlayerAPI.dictionary.deleteDictionary>\n) =>\n useAppAsync(\n 'deleteDictionary',\n useIntlayerAuth().dictionary.deleteDictionary,\n {\n invalidateQueries: ['getDictionaries', 'getDictionariesKeys'],\n ...args,\n }\n );\n\n/**\n * Stripe\n */\n\nexport const useGetSubscription = (\n args?: UseAsyncOptions<typeof 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<typeof intlayerAPI.stripe.cancelSubscription>\n) =>\n useAppAsync(\n 'cancelSubscription',\n useIntlayerAuth().stripe.cancelSubscription,\n { ...args, invalidateQueries: ['getSession'] },\n {\n requireUser: true,\n requireOrganization: true,\n }\n );\n"],"names":["error"],"mappings":";;;;;;;AAAA,MAAe,UAAA,CAAA;ACaf,MAAM,mBAAmB,CAAiC,YAAkB;AACpE,QAAA,EAAE,MA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AAA,IACrC,GAAG;AAAA,EAAA;AAEP;AACW,MAAA,sBAAsB,CACjC,SAEA;AAAA,EACE;AAAA,EACA,gBAAA,EAAkB,WAAW;AAAA,EAC7B;AAAA,IACE,mBAAmB,CAAC,mBAAmB,qBAAqB;AAAA,IAC5D,GAAG;AAAA,EAAA;AAEP;AAMW,MAAA,qBAAqB,CAChC,SAEA;AAAA,EACE;AAAA,EACA,gBAAA,EAAkB,OAAO;AAAA,EACzB,EAAE,GAAG,KAAK;AAAA,EACV;AAAA,IACE,aAAa;AAAA,IACb,qBAAqB;AAAA,EAAA;AAEzB;AAEW,MAAA,wBAAwB,CACnC,SAEA;AAAA,EACE;AAAA,EACA,gBAAA,EAAkB,OAAO;AAAA,EACzB,EAAE,GAAG,MAAM,mBAAmB,CAAC,YAAY,EAAE;AAAA,EAC7C;AAAA,IACE,aAAa;AAAA,IACb,qBAAqB;AAAA,EAAA;AAEzB;"}
|
|
1
|
+
{"version":3,"file":"intlayerAPIHooks.mjs","sources":["../../__vite-browser-external","../../src/hooks/intlayerAPIHooks.ts"],"sourcesContent":["export default {}","/* eslint-disable @typescript-eslint/no-explicit-any */\n'use client';\n\nimport process from 'process';\nimport { intlayerAPI } from 'src/libs';\nimport { useAuth } from '../components/Auth/useAuth/index';\nimport { useToast } from '../components/Toaster';\nimport { useAsync, UseAsyncOptions } from './useAsync/useAsync';\nimport { useIntlayerAuth } from './useIntlayerAPI';\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 error = JSON.parse(errorMessage);\n } catch (e) {\n console.error(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:\n (process.env.NODE_ENV === 'production'\n ? error.title\n : error.code) ?? 'Error',\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 { csrfToken, oAuth2AccessToken, session } = useAuth();\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\n/**\n * Auth\n */\n\nexport const useLogin = (\n args?: UseAsyncOptions<typeof intlayerAPI.auth.login>\n) =>\n useAppAsync('login', useIntlayerAuth().auth.login, {\n invalidateQueries: ['getSession'],\n ...args,\n });\nexport const useRegister = (\n args?: UseAsyncOptions<typeof intlayerAPI.auth.register>\n) =>\n useAppAsync('register', useIntlayerAuth().auth.register, {\n invalidateQueries: ['getSession'],\n ...args,\n });\nexport const useLogout = (\n args?: UseAsyncOptions<typeof intlayerAPI.auth.logout>\n) =>\n useAppAsync('logout', useIntlayerAuth().auth.logout, {\n invalidateQueries: ['getSession'],\n ...args,\n });\nexport const useChangePassword = (\n args?: UseAsyncOptions<typeof intlayerAPI.auth.changePassword>\n) => useAppAsync('changePassword', useIntlayerAuth().auth.changePassword, args);\nexport const useAskResetPassword = (\n args?: UseAsyncOptions<typeof intlayerAPI.auth.askResetPassword>\n) =>\n useAppAsync(\n 'askResetPassword',\n useIntlayerAuth().auth.askResetPassword,\n args\n );\nexport const useResetPassword = (\n args?: UseAsyncOptions<typeof intlayerAPI.auth.resetPassword>\n) => useAppAsync('resetPassword', useIntlayerAuth().auth.resetPassword, args);\nexport const useCheckIfUserHasPassword = (\n args?: UseAsyncOptions<typeof intlayerAPI.auth.checkIfUserHasPassword>\n) =>\n useAppAsync(\n 'checkIfUserHasPassword',\n useIntlayerAuth().auth.checkIfUserHasPassword,\n args,\n {\n requireUser: true,\n }\n );\nexport const useVerifyEmail = (\n args?: UseAsyncOptions<typeof intlayerAPI.auth.verifyEmail>\n) => useAppAsync('verifyEmail', useIntlayerAuth().auth.verifyEmail, args);\n\nexport const useGetUserByAccount = (\n args?: UseAsyncOptions<typeof 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<typeof 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 );\nexport const useCreateUser = (\n args?: UseAsyncOptions<typeof intlayerAPI.user.createUser>\n) =>\n useAppAsync('createUser', useIntlayerAuth().user.createUser, {\n invalidateQueries: ['getUsers'],\n ...args,\n });\nexport const useUpdateUser = (\n args?: UseAsyncOptions<typeof intlayerAPI.user.updateUser>\n) =>\n useAppAsync('updateUser', useIntlayerAuth().user.updateUser, {\n invalidateQueries: ['getSession'],\n ...args,\n });\nexport const useDeleteUser = (\n args?: UseAsyncOptions<typeof 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<typeof 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<typeof intlayerAPI.organization.addOrganization>\n) =>\n useAppAsync(\n 'addOrganization',\n useIntlayerAuth().organization.addOrganization,\n {\n invalidateQueries: ['getOrganizations'],\n ...args,\n }\n );\nexport const useUpdateOrganization = (\n args?: UseAsyncOptions<typeof intlayerAPI.organization.updateOrganization>\n) =>\n useAppAsync(\n 'updateOrganization',\n useIntlayerAuth().organization.updateOrganization,\n {\n invalidateQueries: ['getSession'],\n ...args,\n }\n );\nexport const useUpdateOrganizationMembers = (\n args?: UseAsyncOptions<\n typeof intlayerAPI.organization.updateOrganizationMembers\n >\n) =>\n useAppAsync(\n 'updateOrganizationMembers',\n useIntlayerAuth().organization.updateOrganizationMembers,\n {\n invalidateQueries: ['getOrganizations'],\n ...args,\n }\n );\nexport const useAddOrganizationMember = (\n args?: UseAsyncOptions<typeof intlayerAPI.organization.addOrganizationMember>\n) =>\n useAppAsync(\n 'addOrganizationMember',\n useIntlayerAuth().organization.addOrganizationMember,\n {\n invalidateQueries: ['getOrganizations'],\n ...args,\n }\n );\nexport const useDeleteOrganization = (\n args?: UseAsyncOptions<typeof intlayerAPI.organization.deleteOrganization>\n) =>\n useAppAsync(\n 'deleteOrganization',\n useIntlayerAuth().organization.deleteOrganization,\n {\n invalidateQueries: ['getOrganizations'],\n ...args,\n }\n );\nexport const useSelectOrganization = (\n args?: UseAsyncOptions<typeof intlayerAPI.organization.selectOrganization>\n) =>\n useAppAsync(\n 'selectOrganization',\n useIntlayerAuth().organization.selectOrganization,\n {\n invalidateQueries: ['getSession'],\n ...args,\n }\n );\nexport const useUnselectOrganization = (\n args?: UseAsyncOptions<typeof 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<typeof 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 );\nexport const useAddProject = (\n args?: UseAsyncOptions<typeof intlayerAPI.project.addProject>\n) =>\n useAppAsync('addProject', useIntlayerAuth().project.addProject, {\n invalidateQueries: ['getProjects'],\n ...args,\n });\nexport const useUpdateProject = (\n args?: UseAsyncOptions<typeof intlayerAPI.project.updateProject>\n) =>\n useAppAsync('updateProject', useIntlayerAuth().project.updateProject, {\n invalidateQueries: ['getSession'],\n ...args,\n });\nexport const useUpdateProjectMembers = (\n args?: UseAsyncOptions<typeof intlayerAPI.project.updateProjectMembers>\n) =>\n useAppAsync(\n 'updateProjectMembers',\n useIntlayerAuth().project.updateProjectMembers,\n {\n invalidateQueries: ['getSession'],\n ...args,\n }\n );\nexport const useDeleteProject = (\n args?: UseAsyncOptions<typeof intlayerAPI.project.deleteProject>\n) =>\n useAppAsync('deleteProject', useIntlayerAuth().project.deleteProject, {\n invalidateQueries: ['getProjects'],\n ...args,\n });\nexport const useSelectProject = (\n args?: UseAsyncOptions<typeof intlayerAPI.project.selectProject>\n) =>\n useAppAsync('selectProject', useIntlayerAuth().project.selectProject, {\n invalidateQueries: ['getSession'],\n ...args,\n });\nexport const useUnselectProject = (\n args?: UseAsyncOptions<typeof intlayerAPI.project.unselectProject>\n) =>\n useAppAsync('unselectProject', useIntlayerAuth().project.unselectProject, {\n invalidateQueries: ['getSession'],\n ...args,\n });\nexport const useAddNewAccessKey = (\n args?: UseAsyncOptions<typeof intlayerAPI.project.addNewAccessKey>\n) =>\n useAppAsync('addNewAccessKey', useIntlayerAuth().project.addNewAccessKey, {\n invalidateQueries: ['getSession'],\n ...args,\n });\nexport const useDeleteAccessKey = (\n args?: UseAsyncOptions<typeof intlayerAPI.project.deleteAccessKey>\n) =>\n useAppAsync('deleteAccessKey', useIntlayerAuth().project.deleteAccessKey, {\n invalidateQueries: ['getSession'],\n ...args,\n });\nexport const useRefreshAccessKey = (\n args?: UseAsyncOptions<typeof 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<typeof 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<typeof 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<typeof 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 );\nexport const useAddDictionary = (\n args?: UseAsyncOptions<typeof intlayerAPI.dictionary.addDictionary>\n) =>\n useAppAsync('addDictionary', useIntlayerAuth().dictionary.addDictionary, {\n invalidateQueries: ['getDictionaries', 'getDictionariesKeys'],\n ...args,\n });\n\nexport const usePushDictionaries = (\n args?: UseAsyncOptions<typeof intlayerAPI.dictionary.pushDictionaries>\n) =>\n useAppAsync(\n 'pushDictionaries',\n useIntlayerAuth().dictionary.pushDictionaries,\n {\n invalidateQueries: ['getDictionaries', 'getDictionariesKeys'],\n ...args,\n }\n );\nexport const useUpdateDictionary = (\n args?: UseAsyncOptions<typeof intlayerAPI.dictionary.updateDictionary>\n) =>\n useAppAsync(\n 'updateDictionary',\n useIntlayerAuth().dictionary.updateDictionary,\n {\n invalidateQueries: ['getDictionaries'],\n ...args,\n }\n );\nexport const useDeleteDictionary = (\n args?: UseAsyncOptions<typeof intlayerAPI.dictionary.deleteDictionary>\n) =>\n useAppAsync(\n 'deleteDictionary',\n useIntlayerAuth().dictionary.deleteDictionary,\n {\n invalidateQueries: ['getDictionaries', 'getDictionariesKeys'],\n ...args,\n }\n );\n\n/**\n * Stripe\n */\n\nexport const useGetSubscription = (\n args?: UseAsyncOptions<typeof 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<typeof 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 useAuditFile = (\n args?: UseAsyncOptions<typeof intlayerAPI.ai.auditFile>\n) =>\n useAppAsync('auditFile', useIntlayerAuth().ai.auditFile, args, {\n requireUser: true,\n requireOrganization: true,\n requireProject: true,\n });\n"],"names":["error"],"mappings":";;;;;;;AAAA,MAAe,UAAA,CAAA;ACaf,MAAM,mBAAmB,CAAiC,YAAkB;AACpE,QAAA,EAAE,MAAM,IAAI,SAAS;AAEpB,SAAA;AAAA,IACL,GAAG;AAAA,IACH,SAAS,CAAC,iBAAiB;AACrB,UAAA;AAGA,UAAA;AACM,gBAAA,KAAK,MAAM,YAAY;AAAA,eACxB,GAAG;AACV,gBAAQ,MAAM,CAAC;AAGP,gBAAA;AAAA,MAAA;AAKV,OAAC,KAAK,EACH,QAAQ,CAACA,WAAUA,MAAK,EACxB;AAAA,QAAQ,CAACA,WACR,MAAM;AAAA,UACJ,QACG,QAAQ,IAAI,aAAa,eACtBA,OAAM,QACNA,OAAM,SAAS;AAAA,UACrB,aAAaA,OAAM,WAAW,gBAAgB;AAAA,UAC9C,SAAS;AAAA,QACV,CAAA;AAAA,MACH;AACF,cAAQ,UAAU,YAAY;AAAA,IAChC;AAAA,IACA,WAAW,CAAC,SAAS;AACnB,UAAI,KAAK;AACD,cAAA;AAAA,UACJ,OAAO,KAAK;AAAA,UACZ,aAAa,KAAK;AAAA,UAClB,SAAS;AAAA,QAAA,CACV;A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MAAM;AAAA,EAC7D,aAAa;AAAA,EACb,qBAAqB;AAAA,EACrB,gBAAgB;AAClB,CAAC;"}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const hooks_useAsync_useAsync = require("./useAsync.cjs");
|
|
4
|
+
const hooks_useAsync_useAsyncStateStore = require("./useAsyncStateStore.cjs");
|
|
4
5
|
exports.useAsync = hooks_useAsync_useAsync.useAsync;
|
|
6
|
+
exports.AsyncStateProvider = hooks_useAsync_useAsyncStateStore.AsyncStateProvider;
|
|
7
|
+
exports.useAsyncState = hooks_useAsync_useAsyncStateStore.useAsyncState;
|
|
5
8
|
//# 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":";;;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/useAsync/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/useAsync/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,sBAAsB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
"use strict";
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
4
4
|
const require$$0 = require("react");
|
|
5
|
-
const shallow = require("../../shallow-lhDIFtEp.cjs");
|
|
6
5
|
const hooks_useAsync_useAsyncStateStore = require("./useAsyncStateStore.cjs");
|
|
7
6
|
const pendingPromises = /* @__PURE__ */ new Map();
|
|
8
7
|
const DEFAULT_CACHE_ENABLED = false;
|
|
@@ -29,13 +28,7 @@ const useAsync = (key, asyncFunction, options) => {
|
|
|
29
28
|
const onSuccess = options?.onSuccess;
|
|
30
29
|
const onError = options?.onError;
|
|
31
30
|
const args = getArgs(options?.args ?? []);
|
|
32
|
-
const { setQueryState, setQueriesState, makeQueryInError } = hooks_useAsync_useAsyncStateStore.
|
|
33
|
-
shallow.useShallow((state) => ({
|
|
34
|
-
setQueryState: state.setQueryState,
|
|
35
|
-
setQueriesState: state.setQueriesState,
|
|
36
|
-
makeQueryInError: state.makeQueryInError
|
|
37
|
-
}))
|
|
38
|
-
);
|
|
31
|
+
const { getStates, setQueryState, setQueriesState, makeQueryInError } = hooks_useAsync_useAsyncStateStore.useAsyncState();
|
|
39
32
|
const storedArgsRef = require$$0.useRef(args);
|
|
40
33
|
const keyWithArgs = getKeyWithArgs(key, storedArgsRef.current);
|
|
41
34
|
const {
|
|
@@ -48,7 +41,7 @@ const useAsync = (key, asyncFunction, options) => {
|
|
|
48
41
|
isInvalidated,
|
|
49
42
|
data,
|
|
50
43
|
retryCount: errorCount
|
|
51
|
-
} =
|
|
44
|
+
} = getStates(keyWithArgs);
|
|
52
45
|
const fetch = require$$0.useCallback(
|
|
53
46
|
async (...args2) => {
|
|
54
47
|
const keyWithArgs2 = getKeyWithArgs(key, args2);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAsync.cjs","sources":["../../../src/hooks/useAsync/useAsync.ts"],"sourcesContent":["'use client';\n\n// This is an ESLint directive to disable specific rules.\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport { useCallback, useEffect, useMemo, useRef } from 'react';\nimport { useShallow } from 'zustand/react/shallow';\nimport { useAsyncStateStore } 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 error: string | null;\n data: Awaited<ReturnType<T>> | null;\n retryCount: number;\n revalidate: T;\n setData: (data: Awaited<ReturnType<T> | null>) => 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 using zustand\n store?: boolean; // Store the result of the function in session 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 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 * @template U - A string type that extends the keys of the async function, used as a key to store and retrieve state.\n * @template T - A function type that must return a Promise, representing the asynchronous operation to be managed.\n *\n * @param {U} key - A unique identifier for the async operation, used to handle state internally and avoid conflicts.\n * @param {T} asyncFunction - The asynchronous function that will be managed by this hook. This function should return a Promise.\n * @param {UseAsyncOptions<T>} [options] - Optional configuration options to customize the behavior of the hook.\n * @returns {UseAsyncResult<U, T>} The states and controls related to the managed async function. Includes states like isLoading, isSuccess, and provides control methods like revalidate and setData.\n *\n * @typedef {Object} UseAsyncOptions\n * @property {number} [retryTime=300000] - Time in milliseconds for retrying the data after an error occurs.\n * @property {number} [retryLimit=1] - The number of times the hook should retry the asynchronous function on failure before giving up.\n * @property {boolean} [revalidation=false] - Enable revalidation.\n * @property {number} [revalidateTime=300000] - Time in milliseconds after which the cached data is considered stale and the async function is re-invoked, if caching is enabled.\n * @property {boolean} [cache=false] - Whether to cache the result of the async function. When enabled, revalidation is controlled by `revalidateTime`.\n * @property {boolean} [store=false] - Store the result of the function in session storage.\n * @property {boolean} [autoFetch=false] - Whether the hook should automatically invoke the asynchronous function on mount.\n * @property {number} [revalidateTime=300000] - Time in milliseconds after which the cached data is considered stale and the async function is re-invoked, if caching is enabled.\n * @property {string[]} [updateQueries=[]] - Update other queries when the data is updated.\n * @property {string[]} [invalidateQueries=[]] - Invalidate other queries when the data is updated.\n * @property {(data: Awaited<ReturnType<T>>) => void} [onSuccess] - Callback function that is called when the asynchronous function resolves successfully.\n * @property {(error: string) => void} [onError] - Callback function that is called when the asynchronous function rejects or encounters an error.\n * @property {Parameters<T>} [args=[]] - Arguments to pass to the asynchronous function.\n *\n *\n * @example\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 */\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 { setQueryState, setQueriesState, makeQueryInError } =\n useAsyncStateStore(\n useShallow((state) => ({\n setQueryState: state.setQueryState,\n setQueriesState: state.setQueriesState,\n makeQueryInError: state.makeQueryInError,\n }))\n );\n\n // Storing the last arguments used to call the async function\n const storedArgsRef = useRef<any[]>(args);\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 retryCount: errorCount,\n } = useAsyncStateStore(useShallow((state) => state.getStates(keyWithArgs)));\n\n // The core fetching function, designed to be called directly or automatically based on configuration\n const fetch: T = useCallback<T>(\n (async (...args) => {\n const keyWithArgs = getKeyWithArgs(key, args);\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 await asyncFunction(...args)\n .then((result) => {\n response = result;\n\n setQueryState(keyWithArgs, {\n data: result,\n retryCount: 0,\n isLoading: false,\n isFetched: true,\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 session storage\n if (storeEnabled) {\n sessionStorage.setItem(keyWithArgs, JSON.stringify(result));\n }\n })\n .catch((error) => {\n makeQueryInError(keyWithArgs, error.message);\n onError?.(error.message);\n })\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 [asyncFunction, keyWithArgs, storeEnabled, cacheEnabled, onSuccess, onError]\n );\n\n // Wrapped execution function to handle disabled state and check for success before re-fetching\n const execute: T = useCallback<T>(\n (async (...args) => {\n if (!isEnabled || !enabled) return;\n if (isLoading) return;\n if (!isInvalidated && isSuccess && cacheEnabled && data) return data;\n\n if (args) {\n storedArgsRef.current = getArgs(...args);\n }\n\n return await fetch(...args);\n }) as T,\n [\n isEnabled,\n enabled,\n isInvalidated,\n cacheEnabled,\n isSuccess,\n data,\n isLoading,\n fetch,\n ]\n );\n\n // Function to revalidate the data when necessary\n const revalidate: T = useCallback<T>(\n (async (...args) => {\n if (!isEnabled || !enabled) return;\n\n if (args) {\n storedArgsRef.current = getArgs(...args);\n }\n\n const result = await fetch(...storedArgsRef.current);\n\n return result;\n }) as T,\n [isEnabled, enabled, storedArgsRef, fetch]\n );\n\n const autoRevalidate = useCallback(async () => {\n if (!isEnabled || !enabled) return;\n if (isLoading) return;\n if (!(cacheEnabled || storeEnabled)) return;\n if (!isSuccess) return;\n if (!revalidationEnabled || revalidateTime <= 0) return;\n if (!fetchedDateTime) return;\n\n const now = new Date().getTime();\n const lastFetchedTime = new Date(fetchedDateTime).getTime();\n const shouldRevalidate = now - lastFetchedTime >= revalidateTime;\n if (shouldRevalidate) {\n return await fetch(...storedArgsRef.current);\n }\n }, [\n cacheEnabled,\n revalidationEnabled,\n revalidateTime,\n isSuccess,\n fetchedDateTime,\n isLoading,\n isEnabled,\n enabled,\n ]);\n\n useEffect(() => {\n if (enabled !== isEnabled) {\n setQueryState(keyWithArgs, {\n isEnabled,\n });\n }\n }, [enabled, isEnabled, keyWithArgs]);\n\n // Auto-fetch data on hook mount if autoFetch is true\n useEffect(() => {\n if (!autoFetch) return;\n if (!isEnabled || !enabled) return;\n if (isFetched && !isInvalidated) return;\n if (isLoading) return;\n\n fetch(...storedArgsRef.current);\n }, [\n autoFetch,\n isFetched,\n isInvalidated,\n isEnabled,\n enabled,\n isLoading,\n fetch,\n ]);\n\n // Handle retry based on conditions set in options\n useEffect(() => {\n const isRetryEnabled = errorCount > 0 && retryLimit > 0;\n const isRetryLimitReached = errorCount >= retryLimit;\n if (!isEnabled || !enabled) return;\n if (!(cacheEnabled || storeEnabled)) return;\n if (!isRetryEnabled || isRetryLimitReached) return;\n if (isSuccess) return;\n if (isLoading) return;\n\n const timeOut = setTimeout(() => {\n fetch(...storedArgsRef.current);\n }, retryTime);\n\n return () => clearTimeout(timeOut);\n }, [\n fetch,\n errorCount,\n retryLimit,\n retryTime,\n isSuccess,\n isEnabled,\n enabled,\n isLoading,\n cacheEnabled,\n storeEnabled,\n ]);\n\n // Handle periodic revalidation if caching is enabled\n useEffect(() => {\n const interval = setInterval(autoRevalidate, revalidateTime);\n\n return () => clearInterval(interval);\n }, [autoRevalidate, revalidateTime]);\n\n // Load data from session storage if storeEnabled is true\n useEffect(() => {\n if (!isEnabled || !enabled) return;\n if (!storeEnabled) return;\n if (isInvalidated) return;\n if (isFetched) return;\n if (data) return;\n\n const storedData = sessionStorage.getItem(keyWithArgs);\n\n if (storedData && JSON.stringify(storedData) !== JSON.stringify(data)) {\n setQueryState(keyWithArgs, {\n data: JSON.parse(storedData),\n });\n }\n }, [\n storeEnabled,\n keyWithArgs,\n isFetched,\n isInvalidated,\n isEnabled,\n enabled,\n data,\n ]);\n\n // Memoization of the setData function to prevent unnecessary re-renders\n const setDataMemo = useCallback(\n (data: Awaited<ReturnType<T> | null>) => {\n setQueryState(keyWithArgs, {\n data,\n });\n },\n [keyWithArgs]\n );\n\n const memoResult = useMemo(\n () => ({\n isFetched,\n isLoading,\n isInvalidated,\n error,\n isSuccess,\n data,\n retryCount: errorCount,\n isDisabled: !isEnabled,\n isEnabled,\n [key]: execute,\n revalidate,\n setData: setDataMemo,\n }),\n [\n isFetched,\n isLoading,\n isInvalidated,\n error,\n isSuccess,\n data,\n errorCount,\n isEnabled,\n key,\n execute,\n revalidate,\n setDataMemo,\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":["useAsyncStateStore","useShallow","useRef","useCallback","args","keyWithArgs","error","useEffect","data","useMemo"],"mappings":";;;;;;AAUA,MAAM,sCAAsB,IAAI;AAkChC,MAAM,wBAAwB;AAC9B,MAAM,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,WAAW;AAEjD,QAAA,cAAc,KAAK,UAAU,UAAU,MAAM,KAAK,UAAU,IAAI,GAAG;AACrE,oBAAc,aAAa;AAAA,QACzB,MAAM,KAAK,MAAM,UAAU;AAAA,MAAA,CAC5B;AAAA,IAAA;AAAA,EACH,GACC;AAAA,IACD;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA,CACD;AAGD,QAAM,cAAcJ,WAAA;AAAA,IAClB,CAACK,UAAwC;AACvC,oBAAc,aAAa;AAAA,QACzB,MAAAA;AAAAA,MAAA,CACD;AAAA,IACH;AAAA,IACA,CAAC,WAAW;AAAA,EACd;AAEA,QAAM,aAAaC,WAAA;AAAA,IACjB,OAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,YAAY;AAAA,MACZ,YAAY,CAAC;AAAA,MACb;AAAA,MACA,CAAC,GAAG,GAAG;AAAA,MACP;AAAA,MACA,SAAS;AAAA,IAAA;AAAA,IAEX;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IAAA;AAAA,EAEJ;AAGO,SAAA;AACT;;"}
|
|
1
|
+
{"version":3,"file":"useAsync.cjs","sources":["../../../src/hooks/useAsync/useAsync.ts"],"sourcesContent":["'use client';\n\n// This is an ESLint directive to disable specific rules.\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport { useCallback, useEffect, useMemo, 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 error: string | null;\n data: Awaited<ReturnType<T>> | null;\n retryCount: number;\n revalidate: T;\n setData: (data: Awaited<ReturnType<T> | null>) => 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 using zustand\n store?: boolean; // Store the result of the function in session 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 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 * @template U - A string type that extends the keys of the async function, used as a key to store and retrieve state.\n * @template T - A function type that must return a Promise, representing the asynchronous operation to be managed.\n *\n * @param {U} key - A unique identifier for the async operation, used to handle state internally and avoid conflicts.\n * @param {T} asyncFunction - The asynchronous function that will be managed by this hook. This function should return a Promise.\n * @param {UseAsyncOptions<T>} [options] - Optional configuration options to customize the behavior of the hook.\n * @returns {UseAsyncResult<U, T>} The states and controls related to the managed async function. Includes states like isLoading, isSuccess, and provides control methods like revalidate and setData.\n *\n * @typedef {Object} UseAsyncOptions\n * @property {number} [retryTime=300000] - Time in milliseconds for retrying the data after an error occurs.\n * @property {number} [retryLimit=1] - The number of times the hook should retry the asynchronous function on failure before giving up.\n * @property {boolean} [revalidation=false] - Enable revalidation.\n * @property {number} [revalidateTime=300000] - Time in milliseconds after which the cached data is considered stale and the async function is re-invoked, if caching is enabled.\n * @property {boolean} [cache=false] - Whether to cache the result of the async function. When enabled, revalidation is controlled by `revalidateTime`.\n * @property {boolean} [store=false] - Store the result of the function in session storage.\n * @property {boolean} [autoFetch=false] - Whether the hook should automatically invoke the asynchronous function on mount.\n * @property {number} [revalidateTime=300000] - Time in milliseconds after which the cached data is considered stale and the async function is re-invoked, if caching is enabled.\n * @property {string[]} [updateQueries=[]] - Update other queries when the data is updated.\n * @property {string[]} [invalidateQueries=[]] - Invalidate other queries when the data is updated.\n * @property {(data: Awaited<ReturnType<T>>) => void} [onSuccess] - Callback function that is called when the asynchronous function resolves successfully.\n * @property {(error: string) => void} [onError] - Callback function that is called when the asynchronous function rejects or encounters an error.\n * @property {Parameters<T>} [args=[]] - Arguments to pass to the asynchronous function.\n *\n *\n * @example\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 */\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 // 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 retryCount: errorCount,\n } = getStates(keyWithArgs);\n\n // The core fetching function, designed to be called directly or automatically based on configuration\n const fetch: T = useCallback<T>(\n (async (...args) => {\n const keyWithArgs = getKeyWithArgs(key, args);\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 await asyncFunction(...args)\n .then((result) => {\n response = result;\n\n setQueryState(keyWithArgs, {\n data: result,\n retryCount: 0,\n isLoading: false,\n isFetched: true,\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 session storage\n if (storeEnabled) {\n sessionStorage.setItem(keyWithArgs, JSON.stringify(result));\n }\n })\n .catch((error) => {\n makeQueryInError(keyWithArgs, error.message);\n onError?.(error.message);\n })\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 [asyncFunction, keyWithArgs, storeEnabled, cacheEnabled, onSuccess, onError]\n );\n\n // Wrapped execution function to handle disabled state and check for success before re-fetching\n const execute: T = useCallback<T>(\n (async (...args) => {\n if (!isEnabled || !enabled) return;\n if (isLoading) return;\n if (!isInvalidated && isSuccess && cacheEnabled && data) return data;\n\n if (args) {\n storedArgsRef.current = getArgs(...args);\n }\n\n return await fetch(...args);\n }) as T,\n [\n isEnabled,\n enabled,\n isInvalidated,\n cacheEnabled,\n isSuccess,\n data,\n isLoading,\n fetch,\n ]\n );\n\n // Function to revalidate the data when necessary\n const revalidate: T = useCallback<T>(\n (async (...args) => {\n if (!isEnabled || !enabled) return;\n\n if (args) {\n storedArgsRef.current = getArgs(...args);\n }\n\n const result = await fetch(...storedArgsRef.current);\n\n return result;\n }) as T,\n [isEnabled, enabled, storedArgsRef, fetch]\n );\n\n const autoRevalidate = useCallback(async () => {\n if (!isEnabled || !enabled) return;\n if (isLoading) return;\n if (!(cacheEnabled || storeEnabled)) return;\n if (!isSuccess) return;\n if (!revalidationEnabled || revalidateTime <= 0) return;\n if (!fetchedDateTime) return;\n\n const now = new Date().getTime();\n const lastFetchedTime = new Date(fetchedDateTime).getTime();\n const shouldRevalidate = now - lastFetchedTime >= revalidateTime;\n if (shouldRevalidate) {\n return await fetch(...storedArgsRef.current);\n }\n }, [\n cacheEnabled,\n revalidationEnabled,\n revalidateTime,\n isSuccess,\n fetchedDateTime,\n isLoading,\n isEnabled,\n enabled,\n ]);\n\n useEffect(() => {\n if (enabled !== isEnabled) {\n setQueryState(keyWithArgs, {\n isEnabled,\n });\n }\n }, [enabled, isEnabled, keyWithArgs]);\n\n // Auto-fetch data on hook mount if autoFetch is true\n useEffect(() => {\n if (!autoFetch) return;\n if (!isEnabled || !enabled) return;\n if (isFetched && !isInvalidated) return;\n if (isLoading) return;\n\n fetch(...storedArgsRef.current);\n }, [\n autoFetch,\n isFetched,\n isInvalidated,\n isEnabled,\n enabled,\n isLoading,\n fetch,\n ]);\n\n // Handle retry based on conditions set in options\n useEffect(() => {\n const isRetryEnabled = errorCount > 0 && retryLimit > 0;\n const isRetryLimitReached = errorCount >= retryLimit;\n if (!isEnabled || !enabled) return;\n if (!(cacheEnabled || storeEnabled)) return;\n if (!isRetryEnabled || isRetryLimitReached) return;\n if (isSuccess) return;\n if (isLoading) return;\n\n const timeOut = setTimeout(() => {\n fetch(...storedArgsRef.current);\n }, retryTime);\n\n return () => clearTimeout(timeOut);\n }, [\n fetch,\n errorCount,\n retryLimit,\n retryTime,\n isSuccess,\n isEnabled,\n enabled,\n isLoading,\n cacheEnabled,\n storeEnabled,\n ]);\n\n // Handle periodic revalidation if caching is enabled\n useEffect(() => {\n const interval = setInterval(autoRevalidate, revalidateTime);\n\n return () => clearInterval(interval);\n }, [autoRevalidate, revalidateTime]);\n\n // Load data from session storage if storeEnabled is true\n useEffect(() => {\n if (!isEnabled || !enabled) return;\n if (!storeEnabled) return;\n if (isInvalidated) return;\n if (isFetched) return;\n if (data) return;\n\n const storedData = sessionStorage.getItem(keyWithArgs);\n\n if (storedData && JSON.stringify(storedData) !== JSON.stringify(data)) {\n setQueryState(keyWithArgs, {\n data: JSON.parse(storedData),\n });\n }\n }, [\n storeEnabled,\n keyWithArgs,\n isFetched,\n isInvalidated,\n isEnabled,\n enabled,\n data,\n ]);\n\n // Memoization of the setData function to prevent unnecessary re-renders\n const setDataMemo = useCallback(\n (data: Awaited<ReturnType<T> | null>) => {\n setQueryState(keyWithArgs, {\n data,\n });\n },\n [keyWithArgs]\n );\n\n const memoResult = useMemo(\n () => ({\n isFetched,\n isLoading,\n isInvalidated,\n error,\n isSuccess,\n data,\n retryCount: errorCount,\n isDisabled: !isEnabled,\n isEnabled,\n [key]: execute,\n revalidate,\n setData: setDataMemo,\n }),\n [\n isFetched,\n isLoading,\n isInvalidated,\n error,\n isSuccess,\n data,\n errorCount,\n isEnabled,\n key,\n execute,\n revalidate,\n setDataMemo,\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","useCallback","args","keyWithArgs","error","useEffect","data","useMemo"],"mappings":";;;;;AASA,MAAM,sCAAsB,IAAI;AAkChC,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,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A,MACL;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,YAAY;AAAA,MACZ,YAAY,CAAC;AAAA,MACb;AAAA,MACA,CAAC,GAAG,GAAG;AAAA,MACP;AAAA,MACA,SAAS;AAAA,IAAA;AAAA,IAEX;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IAAA;AAAA,EAEJ;AAGO,SAAA;AACT;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAsync.d.ts","sourceRoot":"","sources":["../../../src/hooks/useAsync/useAsync.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useAsync.d.ts","sourceRoot":"","sources":["../../../src/hooks/useAsync/useAsync.ts"],"names":[],"mappings":"AAYA,KAAK,kBAAkB,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,GAAG,CAAC,IAAI;IACpE,SAAS,EAAE,OAAO,CAAC;IACnB,SAAS,EAAE,OAAO,CAAC;IACnB,aAAa,EAAE,OAAO,CAAC;IACvB,SAAS,EAAE,OAAO,CAAC;IACnB,UAAU,EAAE,OAAO,CAAC;IACpB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,IAAI,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IACpC,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,CAAC,CAAC;IACd,OAAO,EAAE,CAAC,IAAI,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,IAAI,CAAC;CACxD,CAAC;AAGF,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CA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, useCallback, useEffect, useMemo } from "react";
|
|
3
|
-
import {
|
|
4
|
-
import { useAsyncStateStore } from "./useAsyncStateStore.mjs";
|
|
3
|
+
import { useAsyncState } from "./useAsyncStateStore.mjs";
|
|
5
4
|
const pendingPromises = /* @__PURE__ */ new Map();
|
|
6
5
|
const DEFAULT_CACHE_ENABLED = false;
|
|
7
6
|
const DEFAULT_STORE_ENABLED = false;
|
|
@@ -27,13 +26,7 @@ const useAsync = (key, asyncFunction, options) => {
|
|
|
27
26
|
const onSuccess = options?.onSuccess;
|
|
28
27
|
const onError = options?.onError;
|
|
29
28
|
const args = getArgs(options?.args ?? []);
|
|
30
|
-
const { setQueryState, setQueriesState, makeQueryInError } =
|
|
31
|
-
useShallow((state) => ({
|
|
32
|
-
setQueryState: state.setQueryState,
|
|
33
|
-
setQueriesState: state.setQueriesState,
|
|
34
|
-
makeQueryInError: state.makeQueryInError
|
|
35
|
-
}))
|
|
36
|
-
);
|
|
29
|
+
const { getStates, setQueryState, setQueriesState, makeQueryInError } = useAsyncState();
|
|
37
30
|
const storedArgsRef = useRef(args);
|
|
38
31
|
const keyWithArgs = getKeyWithArgs(key, storedArgsRef.current);
|
|
39
32
|
const {
|
|
@@ -46,7 +39,7 @@ const useAsync = (key, asyncFunction, options) => {
|
|
|
46
39
|
isInvalidated,
|
|
47
40
|
data,
|
|
48
41
|
retryCount: errorCount
|
|
49
|
-
} =
|
|
42
|
+
} = getStates(keyWithArgs);
|
|
50
43
|
const fetch = useCallback(
|
|
51
44
|
async (...args2) => {
|
|
52
45
|
const keyWithArgs2 = getKeyWithArgs(key, args2);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAsync.mjs","sources":["../../../src/hooks/useAsync/useAsync.ts"],"sourcesContent":["'use client';\n\n// This is an ESLint directive to disable specific rules.\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport { useCallback, useEffect, useMemo, useRef } from 'react';\nimport { useShallow } from 'zustand/react/shallow';\nimport { useAsyncStateStore } 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 error: string | null;\n data: Awaited<ReturnType<T>> | null;\n retryCount: number;\n revalidate: T;\n setData: (data: Awaited<ReturnType<T> | null>) => 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 using zustand\n store?: boolean; // Store the result of the function in session 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 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 * @template U - A string type that extends the keys of the async function, used as a key to store and retrieve state.\n * @template T - A function type that must return a Promise, representing the asynchronous operation to be managed.\n *\n * @param {U} key - A unique identifier for the async operation, used to handle state internally and avoid conflicts.\n * @param {T} asyncFunction - The asynchronous function that will be managed by this hook. This function should return a Promise.\n * @param {UseAsyncOptions<T>} [options] - Optional configuration options to customize the behavior of the hook.\n * @returns {UseAsyncResult<U, T>} The states and controls related to the managed async function. Includes states like isLoading, isSuccess, and provides control methods like revalidate and setData.\n *\n * @typedef {Object} UseAsyncOptions\n * @property {number} [retryTime=300000] - Time in milliseconds for retrying the data after an error occurs.\n * @property {number} [retryLimit=1] - The number of times the hook should retry the asynchronous function on failure before giving up.\n * @property {boolean} [revalidation=false] - Enable revalidation.\n * @property {number} [revalidateTime=300000] - Time in milliseconds after which the cached data is considered stale and the async function is re-invoked, if caching is enabled.\n * @property {boolean} [cache=false] - Whether to cache the result of the async function. When enabled, revalidation is controlled by `revalidateTime`.\n * @property {boolean} [store=false] - Store the result of the function in session storage.\n * @property {boolean} [autoFetch=false] - Whether the hook should automatically invoke the asynchronous function on mount.\n * @property {number} [revalidateTime=300000] - Time in milliseconds after which the cached data is considered stale and the async function is re-invoked, if caching is enabled.\n * @property {string[]} [updateQueries=[]] - Update other queries when the data is updated.\n * @property {string[]} [invalidateQueries=[]] - Invalidate other queries when the data is updated.\n * @property {(data: Awaited<ReturnType<T>>) => void} [onSuccess] - Callback function that is called when the asynchronous function resolves successfully.\n * @property {(error: string) => void} [onError] - Callback function that is called when the asynchronous function rejects or encounters an error.\n * @property {Parameters<T>} [args=[]] - Arguments to pass to the asynchronous function.\n *\n *\n * @example\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 */\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 { setQueryState, setQueriesState, makeQueryInError } =\n useAsyncStateStore(\n useShallow((state) => ({\n setQueryState: state.setQueryState,\n setQueriesState: state.setQueriesState,\n makeQueryInError: state.makeQueryInError,\n }))\n );\n\n // Storing the last arguments used to call the async function\n const storedArgsRef = useRef<any[]>(args);\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 retryCount: errorCount,\n } = useAsyncStateStore(useShallow((state) => state.getStates(keyWithArgs)));\n\n // The core fetching function, designed to be called directly or automatically based on configuration\n const fetch: T = useCallback<T>(\n (async (...args) => {\n const keyWithArgs = getKeyWithArgs(key, args);\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 await asyncFunction(...args)\n .then((result) => {\n response = result;\n\n setQueryState(keyWithArgs, {\n data: result,\n retryCount: 0,\n isLoading: false,\n isFetched: true,\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 session storage\n if (storeEnabled) {\n sessionStorage.setItem(keyWithArgs, JSON.stringify(result));\n }\n })\n .catch((error) => {\n makeQueryInError(keyWithArgs, error.message);\n onError?.(error.message);\n })\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 [asyncFunction, keyWithArgs, storeEnabled, cacheEnabled, onSuccess, onError]\n );\n\n // Wrapped execution function to handle disabled state and check for success before re-fetching\n const execute: T = useCallback<T>(\n (async (...args) => {\n if (!isEnabled || !enabled) return;\n if (isLoading) return;\n if (!isInvalidated && isSuccess && cacheEnabled && data) return data;\n\n if (args) {\n storedArgsRef.current = getArgs(...args);\n }\n\n return await fetch(...args);\n }) as T,\n [\n isEnabled,\n enabled,\n isInvalidated,\n cacheEnabled,\n isSuccess,\n data,\n isLoading,\n fetch,\n ]\n );\n\n // Function to revalidate the data when necessary\n const revalidate: T = useCallback<T>(\n (async (...args) => {\n if (!isEnabled || !enabled) return;\n\n if (args) {\n storedArgsRef.current = getArgs(...args);\n }\n\n const result = await fetch(...storedArgsRef.current);\n\n return result;\n }) as T,\n [isEnabled, enabled, storedArgsRef, fetch]\n );\n\n const autoRevalidate = useCallback(async () => {\n if (!isEnabled || !enabled) return;\n if (isLoading) return;\n if (!(cacheEnabled || storeEnabled)) return;\n if (!isSuccess) return;\n if (!revalidationEnabled || revalidateTime <= 0) return;\n if (!fetchedDateTime) return;\n\n const now = new Date().getTime();\n const lastFetchedTime = new Date(fetchedDateTime).getTime();\n const shouldRevalidate = now - lastFetchedTime >= revalidateTime;\n if (shouldRevalidate) {\n return await fetch(...storedArgsRef.current);\n }\n }, [\n cacheEnabled,\n revalidationEnabled,\n revalidateTime,\n isSuccess,\n fetchedDateTime,\n isLoading,\n isEnabled,\n enabled,\n ]);\n\n useEffect(() => {\n if (enabled !== isEnabled) {\n setQueryState(keyWithArgs, {\n isEnabled,\n });\n }\n }, [enabled, isEnabled, keyWithArgs]);\n\n // Auto-fetch data on hook mount if autoFetch is true\n useEffect(() => {\n if (!autoFetch) return;\n if (!isEnabled || !enabled) return;\n if (isFetched && !isInvalidated) return;\n if (isLoading) return;\n\n fetch(...storedArgsRef.current);\n }, [\n autoFetch,\n isFetched,\n isInvalidated,\n isEnabled,\n enabled,\n isLoading,\n fetch,\n ]);\n\n // Handle retry based on conditions set in options\n useEffect(() => {\n const isRetryEnabled = errorCount > 0 && retryLimit > 0;\n const isRetryLimitReached = errorCount >= retryLimit;\n if (!isEnabled || !enabled) return;\n if (!(cacheEnabled || storeEnabled)) return;\n if (!isRetryEnabled || isRetryLimitReached) return;\n if (isSuccess) return;\n if (isLoading) return;\n\n const timeOut = setTimeout(() => {\n fetch(...storedArgsRef.current);\n }, retryTime);\n\n return () => clearTimeout(timeOut);\n }, [\n fetch,\n errorCount,\n retryLimit,\n retryTime,\n isSuccess,\n isEnabled,\n enabled,\n isLoading,\n cacheEnabled,\n storeEnabled,\n ]);\n\n // Handle periodic revalidation if caching is enabled\n useEffect(() => {\n const interval = setInterval(autoRevalidate, revalidateTime);\n\n return () => clearInterval(interval);\n }, [autoRevalidate, revalidateTime]);\n\n // Load data from session storage if storeEnabled is true\n useEffect(() => {\n if (!isEnabled || !enabled) return;\n if (!storeEnabled) return;\n if (isInvalidated) return;\n if (isFetched) return;\n if (data) return;\n\n const storedData = sessionStorage.getItem(keyWithArgs);\n\n if (storedData && JSON.stringify(storedData) !== JSON.stringify(data)) {\n setQueryState(keyWithArgs, {\n data: JSON.parse(storedData),\n });\n }\n }, [\n storeEnabled,\n keyWithArgs,\n isFetched,\n isInvalidated,\n isEnabled,\n enabled,\n data,\n ]);\n\n // Memoization of the setData function to prevent unnecessary re-renders\n const setDataMemo = useCallback(\n (data: Awaited<ReturnType<T> | null>) => {\n setQueryState(keyWithArgs, {\n data,\n });\n },\n [keyWithArgs]\n );\n\n const memoResult = useMemo(\n () => ({\n isFetched,\n isLoading,\n isInvalidated,\n error,\n isSuccess,\n data,\n retryCount: errorCount,\n isDisabled: !isEnabled,\n isEnabled,\n [key]: execute,\n revalidate,\n setData: setDataMemo,\n }),\n [\n isFetched,\n isLoading,\n isInvalidated,\n error,\n isSuccess,\n data,\n errorCount,\n isEnabled,\n key,\n execute,\n revalidate,\n setDataMemo,\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":";;;;AAUA,MAAM,sCAAsB,IAAI;AAkChC,MAAM,wBAAwB;AAC9B,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zB,MAAM,KAAK,MAAM,UAAU;AAAA,MAAA,CAC5B;AAAA,IAAA;AAAA,EACH,GACC;AAAA,IACD;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA,CACD;AAGD,QAAM,cAAc;AAAA,IAClB,CAACG,UAAwC;AACvC,oBAAc,aAAa;AAAA,QACzB,MAAAA;AAAAA,MAAA,CACD;AAAA,IACH;AAAA,IACA,CAAC,WAAW;AAAA,EACd;AAEA,QAAM,aAAa;AAAA,IACjB,OAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,YAAY;AAAA,MACZ,YAAY,CAAC;AAAA,MACb;AAAA,MACA,CAAC,GAAG,GAAG;AAAA,MACP;AAAA,MACA,SAAS;AAAA,IAAA;AAAA,IAEX;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IAAA;AAAA,EAEJ;AAGO,SAAA;AACT;"}
|
|
1
|
+
{"version":3,"file":"useAsync.mjs","sources":["../../../src/hooks/useAsync/useAsync.ts"],"sourcesContent":["'use client';\n\n// This is an ESLint directive to disable specific rules.\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport { useCallback, useEffect, useMemo, 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 error: string | null;\n data: Awaited<ReturnType<T>> | null;\n retryCount: number;\n revalidate: T;\n setData: (data: Awaited<ReturnType<T> | null>) => 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 using zustand\n store?: boolean; // Store the result of the function in session 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 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 * @template U - A string type that extends the keys of the async function, used as a key to store and retrieve state.\n * @template T - A function type that must return a Promise, representing the asynchronous operation to be managed.\n *\n * @param {U} key - A unique identifier for the async operation, used to handle state internally and avoid conflicts.\n * @param {T} asyncFunction - The asynchronous function that will be managed by this hook. This function should return a Promise.\n * @param {UseAsyncOptions<T>} [options] - Optional configuration options to customize the behavior of the hook.\n * @returns {UseAsyncResult<U, T>} The states and controls related to the managed async function. Includes states like isLoading, isSuccess, and provides control methods like revalidate and setData.\n *\n * @typedef {Object} UseAsyncOptions\n * @property {number} [retryTime=300000] - Time in milliseconds for retrying the data after an error occurs.\n * @property {number} [retryLimit=1] - The number of times the hook should retry the asynchronous function on failure before giving up.\n * @property {boolean} [revalidation=false] - Enable revalidation.\n * @property {number} [revalidateTime=300000] - Time in milliseconds after which the cached data is considered stale and the async function is re-invoked, if caching is enabled.\n * @property {boolean} [cache=false] - Whether to cache the result of the async function. When enabled, revalidation is controlled by `revalidateTime`.\n * @property {boolean} [store=false] - Store the result of the function in session storage.\n * @property {boolean} [autoFetch=false] - Whether the hook should automatically invoke the asynchronous function on mount.\n * @property {number} [revalidateTime=300000] - Time in milliseconds after which the cached data is considered stale and the async function is re-invoked, if caching is enabled.\n * @property {string[]} [updateQueries=[]] - Update other queries when the data is updated.\n * @property {string[]} [invalidateQueries=[]] - Invalidate other queries when the data is updated.\n * @property {(data: Awaited<ReturnType<T>>) => void} [onSuccess] - Callback function that is called when the asynchronous function resolves successfully.\n * @property {(error: string) => void} [onError] - Callback function that is called when the asynchronous function rejects or encounters an error.\n * @property {Parameters<T>} [args=[]] - Arguments to pass to the asynchronous function.\n *\n *\n * @example\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 */\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 // 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 retryCount: errorCount,\n } = getStates(keyWithArgs);\n\n // The core fetching function, designed to be called directly or automatically based on configuration\n const fetch: T = useCallback<T>(\n (async (...args) => {\n const keyWithArgs = getKeyWithArgs(key, args);\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 await asyncFunction(...args)\n .then((result) => {\n response = result;\n\n setQueryState(keyWithArgs, {\n data: result,\n retryCount: 0,\n isLoading: false,\n isFetched: true,\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 session storage\n if (storeEnabled) {\n sessionStorage.setItem(keyWithArgs, JSON.stringify(result));\n }\n })\n .catch((error) => {\n makeQueryInError(keyWithArgs, error.message);\n onError?.(error.message);\n })\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 [asyncFunction, keyWithArgs, storeEnabled, cacheEnabled, onSuccess, onError]\n );\n\n // Wrapped execution function to handle disabled state and check for success before re-fetching\n const execute: T = useCallback<T>(\n (async (...args) => {\n if (!isEnabled || !enabled) return;\n if (isLoading) return;\n if (!isInvalidated && isSuccess && cacheEnabled && data) return data;\n\n if (args) {\n storedArgsRef.current = getArgs(...args);\n }\n\n return await fetch(...args);\n }) as T,\n [\n isEnabled,\n enabled,\n isInvalidated,\n cacheEnabled,\n isSuccess,\n data,\n isLoading,\n fetch,\n ]\n );\n\n // Function to revalidate the data when necessary\n const revalidate: T = useCallback<T>(\n (async (...args) => {\n if (!isEnabled || !enabled) return;\n\n if (args) {\n storedArgsRef.current = getArgs(...args);\n }\n\n const result = await fetch(...storedArgsRef.current);\n\n return result;\n }) as T,\n [isEnabled, enabled, storedArgsRef, fetch]\n );\n\n const autoRevalidate = useCallback(async () => {\n if (!isEnabled || !enabled) return;\n if (isLoading) return;\n if (!(cacheEnabled || storeEnabled)) return;\n if (!isSuccess) return;\n if (!revalidationEnabled || revalidateTime <= 0) return;\n if (!fetchedDateTime) return;\n\n const now = new Date().getTime();\n const lastFetchedTime = new Date(fetchedDateTime).getTime();\n const shouldRevalidate = now - lastFetchedTime >= revalidateTime;\n if (shouldRevalidate) {\n return await fetch(...storedArgsRef.current);\n }\n }, [\n cacheEnabled,\n revalidationEnabled,\n revalidateTime,\n isSuccess,\n fetchedDateTime,\n isLoading,\n isEnabled,\n enabled,\n ]);\n\n useEffect(() => {\n if (enabled !== isEnabled) {\n setQueryState(keyWithArgs, {\n isEnabled,\n });\n }\n }, [enabled, isEnabled, keyWithArgs]);\n\n // Auto-fetch data on hook mount if autoFetch is true\n useEffect(() => {\n if (!autoFetch) return;\n if (!isEnabled || !enabled) return;\n if (isFetched && !isInvalidated) return;\n if (isLoading) return;\n\n fetch(...storedArgsRef.current);\n }, [\n autoFetch,\n isFetched,\n isInvalidated,\n isEnabled,\n enabled,\n isLoading,\n fetch,\n ]);\n\n // Handle retry based on conditions set in options\n useEffect(() => {\n const isRetryEnabled = errorCount > 0 && retryLimit > 0;\n const isRetryLimitReached = errorCount >= retryLimit;\n if (!isEnabled || !enabled) return;\n if (!(cacheEnabled || storeEnabled)) return;\n if (!isRetryEnabled || isRetryLimitReached) return;\n if (isSuccess) return;\n if (isLoading) return;\n\n const timeOut = setTimeout(() => {\n fetch(...storedArgsRef.current);\n }, retryTime);\n\n return () => clearTimeout(timeOut);\n }, [\n fetch,\n errorCount,\n retryLimit,\n retryTime,\n isSuccess,\n isEnabled,\n enabled,\n isLoading,\n cacheEnabled,\n storeEnabled,\n ]);\n\n // Handle periodic revalidation if caching is enabled\n useEffect(() => {\n const interval = setInterval(autoRevalidate, revalidateTime);\n\n return () => clearInterval(interval);\n }, [autoRevalidate, revalidateTime]);\n\n // Load data from session storage if storeEnabled is true\n useEffect(() => {\n if (!isEnabled || !enabled) return;\n if (!storeEnabled) return;\n if (isInvalidated) return;\n if (isFetched) return;\n if (data) return;\n\n const storedData = sessionStorage.getItem(keyWithArgs);\n\n if (storedData && JSON.stringify(storedData) !== JSON.stringify(data)) {\n setQueryState(keyWithArgs, {\n data: JSON.parse(storedData),\n });\n }\n }, [\n storeEnabled,\n keyWithArgs,\n isFetched,\n isInvalidated,\n isEnabled,\n enabled,\n data,\n ]);\n\n // Memoization of the setData function to prevent unnecessary re-renders\n const setDataMemo = useCallback(\n (data: Awaited<ReturnType<T> | null>) => {\n setQueryState(keyWithArgs, {\n data,\n });\n },\n [keyWithArgs]\n );\n\n const memoResult = useMemo(\n () => ({\n isFetched,\n isLoading,\n isInvalidated,\n error,\n isSuccess,\n data,\n retryCount: errorCount,\n isDisabled: !isEnabled,\n isEnabled,\n [key]: execute,\n revalidate,\n setData: setDataMemo,\n }),\n [\n isFetched,\n isLoading,\n isInvalidated,\n error,\n isSuccess,\n data,\n errorCount,\n isEnabled,\n key,\n execute,\n revalidate,\n setDataMemo,\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":";;;AASA,MAAM,sCAAsB,IAAI;AAkChC,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;AA8DzD,MAAM,WAAW,CAItB,KACA,eACA,YACyB;AAEnB,QAAA,aAAa,S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