@selfcommunity/react-core 0.1.7-alpha.1 → 0.1.8-alpha.1
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/lib/{types → cjs}/components/provider/SCAlertMessagesProvider/index.d.ts +0 -0
- package/lib/{types → cjs}/components/provider/SCAlertMessagesProvider/index.d.ts.map +0 -0
- package/lib/cjs/components/provider/SCAlertMessagesProvider/index.js +37 -35
- package/lib/cjs/components/provider/SCAlertMessagesProvider/index.js.map +1 -0
- package/lib/{types → cjs}/components/provider/SCContextProvider/index.d.ts +0 -0
- package/lib/{types → cjs}/components/provider/SCContextProvider/index.d.ts.map +0 -0
- package/lib/cjs/components/provider/SCContextProvider/index.js +74 -81
- package/lib/cjs/components/provider/SCContextProvider/index.js.map +1 -0
- package/lib/{types → cjs}/components/provider/SCLocaleProvider/index.d.ts +0 -0
- package/lib/{types → cjs}/components/provider/SCLocaleProvider/index.d.ts.map +0 -0
- package/lib/cjs/components/provider/SCLocaleProvider/index.js +86 -121
- package/lib/cjs/components/provider/SCLocaleProvider/index.js.map +1 -0
- package/lib/{types → cjs}/components/provider/SCNotificationProvider/index.d.ts +0 -0
- package/lib/{types → cjs}/components/provider/SCNotificationProvider/index.d.ts.map +0 -0
- package/lib/cjs/components/provider/SCNotificationProvider/index.js +41 -41
- package/lib/cjs/components/provider/SCNotificationProvider/index.js.map +1 -0
- package/lib/{types → cjs}/components/provider/SCPreferencesProvider/index.d.ts +0 -0
- package/lib/{types → cjs}/components/provider/SCPreferencesProvider/index.d.ts.map +0 -0
- package/lib/cjs/components/provider/SCPreferencesProvider/index.js +61 -62
- package/lib/cjs/components/provider/SCPreferencesProvider/index.js.map +1 -0
- package/lib/{types → cjs}/components/provider/SCRoutingProvider/index.d.ts +0 -0
- package/lib/{types → cjs}/components/provider/SCRoutingProvider/index.d.ts.map +1 -1
- package/lib/cjs/components/provider/SCRoutingProvider/index.js +104 -111
- package/lib/cjs/components/provider/SCRoutingProvider/index.js.map +1 -0
- package/lib/{types → cjs}/components/provider/SCThemeProvider/index.d.ts +0 -0
- package/lib/{types → cjs}/components/provider/SCThemeProvider/index.d.ts.map +0 -0
- package/lib/cjs/components/provider/SCThemeProvider/index.js +66 -79
- package/lib/cjs/components/provider/SCThemeProvider/index.js.map +1 -0
- package/lib/{types → cjs}/components/provider/SCUserProvider/index.d.ts +0 -0
- package/lib/{types → cjs}/components/provider/SCUserProvider/index.d.ts.map +0 -0
- package/lib/cjs/components/provider/SCUserProvider/index.js +215 -270
- package/lib/cjs/components/provider/SCUserProvider/index.js.map +1 -0
- package/lib/{types → cjs}/components/router/index.d.ts +0 -0
- package/lib/{types → cjs}/components/router/index.d.ts.map +0 -0
- package/lib/cjs/components/router/index.js +48 -49
- package/lib/cjs/components/router/index.js.map +1 -0
- package/lib/{types → cjs}/constants/Actions.d.ts +0 -0
- package/lib/{types → cjs}/constants/Actions.d.ts.map +0 -0
- package/lib/cjs/constants/Actions.js +3 -4
- package/lib/cjs/constants/Actions.js.map +1 -0
- package/lib/{types → cjs}/constants/ContextProviders.d.ts +0 -0
- package/lib/{types → cjs}/constants/ContextProviders.d.ts.map +0 -0
- package/lib/cjs/constants/ContextProviders.js +22 -24
- package/lib/cjs/constants/ContextProviders.js.map +1 -0
- package/lib/{types → cjs}/constants/Device.d.ts +0 -0
- package/lib/{types → cjs}/constants/Device.d.ts.map +0 -0
- package/lib/cjs/constants/Device.js +3 -5
- package/lib/cjs/constants/Device.js.map +1 -0
- package/lib/{types → cjs}/constants/Errors.d.ts +0 -0
- package/lib/{types → cjs}/constants/Errors.d.ts.map +0 -0
- package/lib/cjs/constants/Errors.js +3 -5
- package/lib/cjs/constants/Errors.js.map +1 -0
- package/lib/{types → cjs}/constants/Features.d.ts +0 -0
- package/lib/{types → cjs}/constants/Features.d.ts.map +0 -0
- package/lib/cjs/constants/Features.js +43 -83
- package/lib/cjs/constants/Features.js.map +1 -0
- package/lib/{types → cjs}/constants/Locale.d.ts +0 -0
- package/lib/{types → cjs}/constants/Locale.d.ts.map +0 -0
- package/lib/cjs/constants/Locale.js +10 -17
- package/lib/cjs/constants/Locale.js.map +1 -0
- package/lib/{types → cjs}/constants/Notification.d.ts +0 -0
- package/lib/{types → cjs}/constants/Notification.d.ts.map +0 -0
- package/lib/cjs/constants/Notification.js +44 -53
- package/lib/cjs/constants/Notification.js.map +1 -0
- package/lib/{types → cjs}/constants/Notifications.d.ts +0 -0
- package/lib/{types → cjs}/constants/Notifications.d.ts.map +0 -0
- package/lib/cjs/constants/Notifications.js +11 -25
- package/lib/cjs/constants/Notifications.js.map +1 -0
- package/lib/cjs/constants/Preferences.d.ts +201 -0
- package/lib/cjs/constants/Preferences.d.ts.map +1 -0
- package/lib/cjs/constants/Preferences.js +184 -292
- package/lib/cjs/constants/Preferences.js.map +1 -0
- package/lib/{types → cjs}/constants/Routes.d.ts +0 -0
- package/lib/{types → cjs}/constants/Routes.d.ts.map +0 -0
- package/lib/cjs/constants/Routes.js +38 -59
- package/lib/cjs/constants/Routes.js.map +1 -0
- package/lib/{types → cjs}/constants/Session.d.ts +0 -0
- package/lib/{types → cjs}/constants/Session.d.ts.map +0 -0
- package/lib/cjs/constants/Session.js +12 -21
- package/lib/cjs/constants/Session.js.map +1 -0
- package/lib/{types → cjs}/constants/Theme.d.ts +0 -0
- package/lib/{types → cjs}/constants/Theme.d.ts.map +0 -0
- package/lib/cjs/constants/Theme.js +3 -4
- package/lib/cjs/constants/Theme.js.map +1 -0
- package/lib/cjs/constants/WebSocket.d.ts +4 -0
- package/lib/cjs/constants/WebSocket.d.ts.map +1 -0
- package/lib/cjs/constants/WebSocket.js +6 -9
- package/lib/cjs/constants/WebSocket.js.map +1 -0
- package/lib/{types → cjs}/hooks/useSCAuth.d.ts +0 -0
- package/lib/{types → cjs}/hooks/useSCAuth.d.ts.map +0 -0
- package/lib/cjs/hooks/useSCAuth.js +212 -282
- package/lib/cjs/hooks/useSCAuth.js.map +1 -0
- package/lib/{types → cjs}/hooks/useSCCachingManager.d.ts +0 -0
- package/lib/{types → cjs}/hooks/useSCCachingManager.d.ts.map +0 -0
- package/lib/cjs/hooks/useSCCachingManager.js +37 -51
- package/lib/cjs/hooks/useSCCachingManager.js.map +1 -0
- package/lib/{types → cjs}/hooks/useSCConnectionsManager.d.ts +0 -0
- package/lib/{types → cjs}/hooks/useSCConnectionsManager.d.ts.map +0 -0
- package/lib/cjs/hooks/useSCConnectionsManager.js +190 -254
- package/lib/cjs/hooks/useSCConnectionsManager.js.map +1 -0
- package/lib/{types → cjs}/hooks/useSCFetchAddressingTagList.d.ts +0 -0
- package/lib/{types → cjs}/hooks/useSCFetchAddressingTagList.d.ts.map +0 -0
- package/lib/cjs/hooks/useSCFetchAddressingTagList.js +64 -55
- package/lib/cjs/hooks/useSCFetchAddressingTagList.js.map +1 -0
- package/lib/{types → cjs}/hooks/useSCFetchCategories.d.ts +0 -0
- package/lib/{types → cjs}/hooks/useSCFetchCategories.d.ts.map +0 -0
- package/lib/cjs/hooks/useSCFetchCategories.js +46 -56
- package/lib/cjs/hooks/useSCFetchCategories.js.map +1 -0
- package/lib/{types → cjs}/hooks/useSCFetchCategory.d.ts +0 -0
- package/lib/{types → cjs}/hooks/useSCFetchCategory.d.ts.map +0 -0
- package/lib/cjs/hooks/useSCFetchCategory.js +44 -59
- package/lib/cjs/hooks/useSCFetchCategory.js.map +1 -0
- package/lib/{types → cjs}/hooks/useSCFetchCommentObject.d.ts +0 -0
- package/lib/{types → cjs}/hooks/useSCFetchCommentObject.d.ts.map +0 -0
- package/lib/cjs/hooks/useSCFetchCommentObject.js +44 -59
- package/lib/cjs/hooks/useSCFetchCommentObject.js.map +1 -0
- package/lib/{types → cjs}/hooks/useSCFetchCommentObjects.d.ts +0 -0
- package/lib/{types → cjs}/hooks/useSCFetchCommentObjects.d.ts.map +0 -0
- package/lib/cjs/hooks/useSCFetchCommentObjects.js +157 -254
- package/lib/cjs/hooks/useSCFetchCommentObjects.js.map +1 -0
- package/lib/{types → cjs}/hooks/useSCFetchCustomAdv.d.ts +0 -0
- package/lib/{types → cjs}/hooks/useSCFetchCustomAdv.d.ts.map +0 -0
- package/lib/cjs/hooks/useSCFetchCustomAdv.js +57 -75
- package/lib/cjs/hooks/useSCFetchCustomAdv.js.map +1 -0
- package/lib/{types → cjs}/hooks/useSCFetchFeedObject.d.ts +0 -0
- package/lib/{types → cjs}/hooks/useSCFetchFeedObject.d.ts.map +0 -0
- package/lib/cjs/hooks/useSCFetchFeedObject.js +49 -69
- package/lib/cjs/hooks/useSCFetchFeedObject.js.map +1 -0
- package/lib/{types → cjs}/hooks/useSCFetchIncubator.d.ts +0 -0
- package/lib/{types → cjs}/hooks/useSCFetchIncubator.d.ts.map +0 -0
- package/lib/cjs/hooks/useSCFetchIncubator.js +44 -59
- package/lib/cjs/hooks/useSCFetchIncubator.js.map +1 -0
- package/lib/{types → cjs}/hooks/useSCFetchTag.d.ts +0 -0
- package/lib/{types → cjs}/hooks/useSCFetchTag.d.ts.map +0 -0
- package/lib/cjs/hooks/useSCFetchTag.js +44 -59
- package/lib/cjs/hooks/useSCFetchTag.js.map +1 -0
- package/lib/{types → cjs}/hooks/useSCFetchUser.d.ts +0 -0
- package/lib/{types → cjs}/hooks/useSCFetchUser.d.ts.map +1 -1
- package/lib/cjs/hooks/useSCFetchUser.js +47 -59
- package/lib/cjs/hooks/useSCFetchUser.js.map +1 -0
- package/lib/{types → cjs}/hooks/useSCFollowedCategoriesManager.d.ts +0 -0
- package/lib/{types → cjs}/hooks/useSCFollowedCategoriesManager.d.ts.map +0 -0
- package/lib/cjs/hooks/useSCFollowedCategoriesManager.js +105 -147
- package/lib/cjs/hooks/useSCFollowedCategoriesManager.js.map +1 -0
- package/lib/{types → cjs}/hooks/useSCFollowersManager.d.ts +0 -0
- package/lib/{types → cjs}/hooks/useSCFollowersManager.d.ts.map +0 -0
- package/lib/cjs/hooks/useSCFollowersManager.js +154 -204
- package/lib/cjs/hooks/useSCFollowersManager.js.map +1 -0
- package/lib/{types → cjs}/hooks/useSCMediaClick.d.ts +0 -0
- package/lib/{types → cjs}/hooks/useSCMediaClick.d.ts.map +0 -0
- package/lib/cjs/hooks/useSCMediaClick.js +18 -25
- package/lib/cjs/hooks/useSCMediaClick.js.map +1 -0
- package/lib/{types → cjs}/hooks/useSCSubscribedIncubatorsManager.d.ts +0 -0
- package/lib/{types → cjs}/hooks/useSCSubscribedIncubatorsManager.d.ts.map +0 -0
- package/lib/cjs/hooks/useSCSubscribedIncubatorsManager.js +118 -148
- package/lib/cjs/hooks/useSCSubscribedIncubatorsManager.js.map +1 -0
- package/lib/{types → cjs}/hooks/useSCWebPushMessaging.d.ts +0 -0
- package/lib/{types → cjs}/hooks/useSCWebPushMessaging.d.ts.map +0 -0
- package/lib/cjs/hooks/useSCWebPushMessaging.js +268 -268
- package/lib/cjs/hooks/useSCWebPushMessaging.js.map +1 -0
- package/lib/{types → cjs}/hooks/useSCWebSocket.d.ts +0 -0
- package/lib/{types → cjs}/hooks/useSCWebSocket.d.ts.map +0 -0
- package/lib/cjs/hooks/useSCWebSocket.js +103 -125
- package/lib/cjs/hooks/useSCWebSocket.js.map +1 -0
- package/lib/{types → cjs}/index.d.ts +0 -0
- package/lib/{types → cjs}/index.d.ts.map +0 -0
- package/lib/cjs/index.js +131 -144
- package/lib/cjs/index.js.map +1 -0
- package/lib/cjs/themes/theme.d.ts +9 -0
- package/lib/cjs/themes/theme.d.ts.map +1 -0
- package/lib/cjs/themes/theme.js +132 -143
- package/lib/cjs/themes/theme.js.map +1 -0
- package/lib/{types → cjs}/types/context.d.ts +0 -0
- package/lib/{types → cjs}/types/context.d.ts.map +0 -0
- package/lib/cjs/types/context.js +2 -2
- package/lib/cjs/types/context.js.map +1 -0
- package/lib/{types → cjs}/types/index.d.ts +0 -0
- package/lib/{types → cjs}/types/index.d.ts.map +0 -0
- package/lib/cjs/types/index.js +2 -21
- package/lib/cjs/types/index.js.map +1 -0
- package/lib/{types → cjs}/utils/errors.d.ts +0 -0
- package/lib/{types → cjs}/utils/errors.d.ts.map +0 -0
- package/lib/cjs/utils/errors.js +138 -149
- package/lib/cjs/utils/errors.js.map +1 -0
- package/lib/{types → cjs}/utils/locale.d.ts +0 -0
- package/lib/{types → cjs}/utils/locale.d.ts.map +0 -0
- package/lib/cjs/utils/locale.js +32 -48
- package/lib/cjs/utils/locale.js.map +1 -0
- package/lib/{types → cjs}/utils/user.d.ts +0 -0
- package/lib/{types → cjs}/utils/user.d.ts.map +0 -0
- package/lib/cjs/utils/user.js +25 -40
- package/lib/cjs/utils/user.js.map +1 -0
- package/lib/{types → cjs}/utils/validator.d.ts +0 -0
- package/lib/{types → cjs}/utils/validator.d.ts.map +0 -0
- package/lib/cjs/utils/validator.js +386 -576
- package/lib/cjs/utils/validator.js.map +1 -0
- package/lib/esm/components/provider/SCAlertMessagesProvider/index.d.ts +37 -0
- package/lib/esm/components/provider/SCAlertMessagesProvider/index.d.ts.map +1 -0
- package/lib/esm/components/provider/SCAlertMessagesProvider/index.js +11 -37
- package/lib/esm/components/provider/SCAlertMessagesProvider/index.js.map +1 -0
- package/lib/esm/components/provider/SCContextProvider/index.d.ts +35 -0
- package/lib/esm/components/provider/SCContextProvider/index.d.ts.map +1 -0
- package/lib/esm/components/provider/SCContextProvider/index.js +48 -83
- package/lib/esm/components/provider/SCContextProvider/index.js.map +1 -0
- package/lib/esm/components/provider/SCLocaleProvider/index.d.ts +42 -0
- package/lib/esm/components/provider/SCLocaleProvider/index.d.ts.map +1 -0
- package/lib/esm/components/provider/SCLocaleProvider/index.js +59 -123
- package/lib/esm/components/provider/SCLocaleProvider/index.js.map +1 -0
- package/lib/esm/components/provider/SCNotificationProvider/index.d.ts +37 -0
- package/lib/esm/components/provider/SCNotificationProvider/index.d.ts.map +1 -0
- package/lib/esm/components/provider/SCNotificationProvider/index.js +12 -43
- package/lib/esm/components/provider/SCNotificationProvider/index.js.map +1 -0
- package/lib/esm/components/provider/SCPreferencesProvider/index.d.ts +38 -0
- package/lib/esm/components/provider/SCPreferencesProvider/index.d.ts.map +1 -0
- package/lib/esm/components/provider/SCPreferencesProvider/index.js +35 -64
- package/lib/esm/components/provider/SCPreferencesProvider/index.js.map +1 -0
- package/lib/esm/components/provider/SCRoutingProvider/index.d.ts +39 -0
- package/lib/esm/components/provider/SCRoutingProvider/index.d.ts.map +1 -0
- package/lib/esm/components/provider/SCRoutingProvider/index.js +78 -113
- package/lib/esm/components/provider/SCRoutingProvider/index.js.map +1 -0
- package/lib/esm/components/provider/SCThemeProvider/index.d.ts +49 -0
- package/lib/esm/components/provider/SCThemeProvider/index.d.ts.map +1 -0
- package/lib/esm/components/provider/SCThemeProvider/index.js +36 -81
- package/lib/esm/components/provider/SCThemeProvider/index.js.map +1 -0
- package/lib/esm/components/provider/SCUserProvider/index.d.ts +38 -0
- package/lib/esm/components/provider/SCUserProvider/index.d.ts.map +1 -0
- package/lib/esm/components/provider/SCUserProvider/index.js +186 -272
- package/lib/esm/components/provider/SCUserProvider/index.js.map +1 -0
- package/lib/esm/components/router/index.d.ts +34 -0
- package/lib/esm/components/router/index.d.ts.map +1 -0
- package/lib/esm/components/router/index.js +24 -50
- package/lib/esm/components/router/index.js.map +1 -0
- package/lib/esm/constants/Actions.d.ts +2 -0
- package/lib/esm/constants/Actions.d.ts.map +1 -0
- package/lib/esm/constants/Actions.js +2 -6
- package/lib/esm/constants/Actions.js.map +1 -0
- package/lib/esm/constants/ContextProviders.d.ts +6 -0
- package/lib/esm/constants/ContextProviders.d.ts.map +1 -0
- package/lib/esm/constants/ContextProviders.js +18 -26
- package/lib/esm/constants/ContextProviders.js.map +1 -0
- package/lib/esm/constants/Device.d.ts +6 -0
- package/lib/esm/constants/Device.d.ts.map +1 -0
- package/lib/esm/constants/Device.js +2 -7
- package/lib/esm/constants/Device.js.map +1 -0
- package/lib/esm/constants/Errors.d.ts +5 -0
- package/lib/esm/constants/Errors.d.ts.map +1 -0
- package/lib/esm/constants/Errors.js +2 -7
- package/lib/esm/constants/Errors.js.map +1 -0
- package/lib/esm/constants/Features.d.ts +41 -0
- package/lib/esm/constants/Features.d.ts.map +1 -0
- package/lib/esm/constants/Features.js +41 -84
- package/lib/esm/constants/Features.js.map +1 -0
- package/lib/esm/constants/Locale.d.ts +8 -0
- package/lib/esm/constants/Locale.d.ts.map +1 -0
- package/lib/esm/constants/Locale.js +8 -18
- package/lib/esm/constants/Locale.js.map +1 -0
- package/lib/esm/constants/Notification.d.ts +55 -0
- package/lib/esm/constants/Notification.d.ts.map +1 -0
- package/lib/esm/constants/Notification.js +42 -54
- package/lib/esm/constants/Notification.js.map +1 -0
- package/lib/esm/constants/Notifications.d.ts +11 -0
- package/lib/esm/constants/Notifications.d.ts.map +1 -0
- package/lib/esm/constants/Notifications.js +9 -26
- package/lib/esm/constants/Notifications.js.map +1 -0
- package/lib/esm/constants/Preferences.d.ts +201 -0
- package/lib/esm/constants/Preferences.d.ts.map +1 -0
- package/lib/esm/constants/Preferences.js +181 -296
- package/lib/esm/constants/Preferences.js.map +1 -0
- package/lib/esm/constants/Routes.d.ts +29 -0
- package/lib/esm/constants/Routes.d.ts.map +1 -0
- package/lib/esm/constants/Routes.js +36 -60
- package/lib/esm/constants/Routes.js.map +1 -0
- package/lib/esm/constants/Session.d.ts +10 -0
- package/lib/esm/constants/Session.d.ts.map +1 -0
- package/lib/esm/constants/Session.js +10 -22
- package/lib/esm/constants/Session.js.map +1 -0
- package/lib/esm/constants/Theme.d.ts +2 -0
- package/lib/esm/constants/Theme.d.ts.map +1 -0
- package/lib/esm/constants/Theme.js +2 -6
- package/lib/esm/constants/Theme.js.map +1 -0
- package/lib/esm/constants/WebSocket.d.ts +4 -0
- package/lib/esm/constants/WebSocket.d.ts.map +1 -0
- package/lib/esm/constants/WebSocket.js +4 -10
- package/lib/esm/constants/WebSocket.js.map +1 -0
- package/lib/esm/hooks/useSCAuth.d.ts +56 -0
- package/lib/esm/hooks/useSCAuth.d.ts.map +1 -0
- package/lib/esm/hooks/useSCAuth.js +185 -285
- package/lib/esm/hooks/useSCAuth.js.map +1 -0
- package/lib/esm/hooks/useSCCachingManager.d.ts +19 -0
- package/lib/esm/hooks/useSCCachingManager.d.ts.map +1 -0
- package/lib/esm/hooks/useSCCachingManager.js +36 -53
- package/lib/esm/hooks/useSCCachingManager.js.map +1 -0
- package/lib/esm/hooks/useSCConnectionsManager.d.ts +40 -0
- package/lib/esm/hooks/useSCConnectionsManager.d.ts.map +1 -0
- package/lib/esm/hooks/useSCConnectionsManager.js +186 -256
- package/lib/esm/hooks/useSCConnectionsManager.js.map +1 -0
- package/lib/esm/hooks/useSCFetchAddressingTagList.d.ts +14 -0
- package/lib/esm/hooks/useSCFetchAddressingTagList.d.ts.map +1 -0
- package/lib/esm/hooks/useSCFetchAddressingTagList.js +39 -56
- package/lib/esm/hooks/useSCFetchAddressingTagList.js.map +1 -0
- package/lib/esm/hooks/useSCFetchCategories.d.ts +17 -0
- package/lib/esm/hooks/useSCFetchCategories.d.ts.map +1 -0
- package/lib/esm/hooks/useSCFetchCategories.js +45 -57
- package/lib/esm/hooks/useSCFetchCategories.js.map +1 -0
- package/lib/esm/hooks/useSCFetchCategory.d.ts +19 -0
- package/lib/esm/hooks/useSCFetchCategory.d.ts.map +1 -0
- package/lib/esm/hooks/useSCFetchCategory.js +42 -60
- package/lib/esm/hooks/useSCFetchCategory.js.map +1 -0
- package/lib/esm/hooks/useSCFetchCommentObject.d.ts +19 -0
- package/lib/esm/hooks/useSCFetchCommentObject.d.ts.map +1 -0
- package/lib/esm/hooks/useSCFetchCommentObject.js +42 -60
- package/lib/esm/hooks/useSCFetchCommentObject.js.map +1 -0
- package/lib/esm/hooks/useSCFetchCommentObjects.d.ts +53 -0
- package/lib/esm/hooks/useSCFetchCommentObjects.d.ts.map +1 -0
- package/lib/esm/hooks/useSCFetchCommentObjects.js +153 -257
- package/lib/esm/hooks/useSCFetchCommentObjects.js.map +1 -0
- package/lib/esm/hooks/useSCFetchCustomAdv.d.ts +19 -0
- package/lib/esm/hooks/useSCFetchCustomAdv.d.ts.map +1 -0
- package/lib/esm/hooks/useSCFetchCustomAdv.js +55 -76
- package/lib/esm/hooks/useSCFetchCustomAdv.js.map +1 -0
- package/lib/esm/hooks/useSCFetchFeedObject.d.ts +21 -0
- package/lib/esm/hooks/useSCFetchFeedObject.d.ts.map +1 -0
- package/lib/esm/hooks/useSCFetchFeedObject.js +47 -70
- package/lib/esm/hooks/useSCFetchFeedObject.js.map +1 -0
- package/lib/esm/hooks/useSCFetchIncubator.d.ts +19 -0
- package/lib/esm/hooks/useSCFetchIncubator.d.ts.map +1 -0
- package/lib/esm/hooks/useSCFetchIncubator.js +42 -60
- package/lib/esm/hooks/useSCFetchIncubator.js.map +1 -0
- package/lib/esm/hooks/useSCFetchTag.d.ts +19 -0
- package/lib/esm/hooks/useSCFetchTag.d.ts.map +1 -0
- package/lib/esm/hooks/useSCFetchTag.js +42 -60
- package/lib/esm/hooks/useSCFetchTag.js.map +1 -0
- package/lib/esm/hooks/useSCFetchUser.d.ts +19 -0
- package/lib/esm/hooks/useSCFetchUser.d.ts.map +1 -0
- package/lib/esm/hooks/useSCFetchUser.js +45 -60
- package/lib/esm/hooks/useSCFetchUser.js.map +1 -0
- package/lib/esm/hooks/useSCFollowedCategoriesManager.d.ts +37 -0
- package/lib/esm/hooks/useSCFollowedCategoriesManager.d.ts.map +1 -0
- package/lib/esm/hooks/useSCFollowedCategoriesManager.js +101 -149
- package/lib/esm/hooks/useSCFollowedCategoriesManager.js.map +1 -0
- package/lib/esm/hooks/useSCFollowersManager.d.ts +37 -0
- package/lib/esm/hooks/useSCFollowersManager.d.ts.map +1 -0
- package/lib/esm/hooks/useSCFollowersManager.js +150 -206
- package/lib/esm/hooks/useSCFollowersManager.js.map +1 -0
- package/lib/esm/hooks/useSCMediaClick.d.ts +4 -0
- package/lib/esm/hooks/useSCMediaClick.d.ts.map +1 -0
- package/lib/esm/hooks/useSCMediaClick.js +17 -27
- package/lib/esm/hooks/useSCMediaClick.js.map +1 -0
- package/lib/esm/hooks/useSCSubscribedIncubatorsManager.d.ts +27 -0
- package/lib/esm/hooks/useSCSubscribedIncubatorsManager.d.ts.map +1 -0
- package/lib/esm/hooks/useSCSubscribedIncubatorsManager.js +114 -150
- package/lib/esm/hooks/useSCSubscribedIncubatorsManager.js.map +1 -0
- package/lib/esm/hooks/useSCWebPushMessaging.d.ts +9 -0
- package/lib/esm/hooks/useSCWebPushMessaging.d.ts.map +1 -0
- package/lib/esm/hooks/useSCWebPushMessaging.js +244 -270
- package/lib/esm/hooks/useSCWebPushMessaging.js.map +1 -0
- package/lib/esm/hooks/useSCWebSocket.d.ts +12 -0
- package/lib/esm/hooks/useSCWebSocket.d.ts.map +1 -0
- package/lib/esm/hooks/useSCWebSocket.js +99 -127
- package/lib/esm/hooks/useSCWebSocket.js.map +1 -0
- package/lib/esm/index.d.ts +73 -0
- package/lib/esm/index.d.ts.map +1 -0
- package/lib/esm/index.js +69 -151
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/themes/theme.d.ts +9 -0
- package/lib/esm/themes/theme.d.ts.map +1 -0
- package/lib/esm/themes/theme.js +128 -144
- package/lib/esm/themes/theme.js.map +1 -0
- package/lib/esm/types/context.d.ts +428 -0
- package/lib/esm/types/context.d.ts.map +1 -0
- package/lib/esm/types/context.js +2 -3
- package/lib/esm/types/context.js.map +1 -0
- package/lib/esm/types/index.d.ts +3 -0
- package/lib/esm/types/index.d.ts.map +1 -0
- package/lib/esm/types/index.js +2 -22
- package/lib/esm/types/index.js.map +1 -0
- package/lib/esm/utils/errors.d.ts +98 -0
- package/lib/esm/utils/errors.d.ts.map +1 -0
- package/lib/esm/utils/errors.js +114 -155
- package/lib/esm/utils/errors.js.map +1 -0
- package/lib/esm/utils/locale.d.ts +10 -0
- package/lib/esm/utils/locale.d.ts.map +1 -0
- package/lib/esm/utils/locale.js +27 -50
- package/lib/esm/utils/locale.js.map +1 -0
- package/lib/esm/utils/user.d.ts +41 -0
- package/lib/esm/utils/user.d.ts.map +1 -0
- package/lib/esm/utils/user.js +23 -46
- package/lib/esm/utils/user.js.map +1 -0
- package/lib/esm/utils/validator.d.ts +239 -0
- package/lib/esm/utils/validator.d.ts.map +1 -0
- package/lib/esm/utils/validator.js +352 -588
- package/lib/esm/utils/validator.js.map +1 -0
- package/lib/umd/react-core.js +1 -1
- package/package.json +9 -11
- package/lib/types/tsconfig.build.tsbuildinfo +0 -1
|
@@ -1,27 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
var _Errors = require("../constants/Errors");
|
|
18
|
-
|
|
19
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
20
|
-
|
|
21
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
22
|
-
|
|
23
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
24
|
-
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { http } from '@selfcommunity/api-services';
|
|
11
|
+
import { useEffect, useMemo, useReducer, useRef } from 'react';
|
|
12
|
+
import * as Session from '../constants/Session';
|
|
13
|
+
import useDeepCompareEffect from 'use-deep-compare-effect';
|
|
14
|
+
import { Logger } from '@selfcommunity/utils';
|
|
15
|
+
import { SCOPE_SC_CORE } from '../constants/Errors';
|
|
25
16
|
/**
|
|
26
17
|
* @hidden
|
|
27
18
|
* We have complex state logic that involves multiple sub-values,
|
|
@@ -29,15 +20,15 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
|
|
|
29
20
|
* Define all possible auth action types label
|
|
30
21
|
* Use this to export actions and dispatch an action
|
|
31
22
|
*/
|
|
32
|
-
const userActionTypes = {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
23
|
+
export const userActionTypes = {
|
|
24
|
+
LOGIN_LOADING: '_login_loading',
|
|
25
|
+
LOGIN_SUCCESS: '_login_success',
|
|
26
|
+
LOGIN_FAILURE: '_login_failure',
|
|
27
|
+
LOGOUT: '_logout',
|
|
28
|
+
REFRESH_TOKEN_SUCCESS: '_refresh_token_success',
|
|
29
|
+
REFRESH_TOKEN_FAILURE: '_invalid_token_failure',
|
|
30
|
+
REFRESH_SESSION: '_refresh_token',
|
|
31
|
+
UPDATE_USER: '_change_user',
|
|
41
32
|
};
|
|
42
33
|
/**
|
|
43
34
|
* userReducer:
|
|
@@ -46,114 +37,51 @@ const userActionTypes = {
|
|
|
46
37
|
* @param state
|
|
47
38
|
* @param action
|
|
48
39
|
*/
|
|
49
|
-
|
|
50
|
-
exports.userActionTypes = userActionTypes;
|
|
51
|
-
|
|
52
40
|
function userReducer(state, action) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
const newAuthToken = Object.assign({}, state.session.authToken, Object.assign({}, state.session.authToken, {
|
|
80
|
-
accessToken: action.payload.token.accessToken
|
|
81
|
-
}, action.payload.token.refreshToken ? {
|
|
82
|
-
refreshToken: action.payload.token.refreshToken
|
|
83
|
-
} : {}, action.payload.token.expiresIn ? {
|
|
84
|
-
expiresIn: action.payload.token.expiresIn
|
|
85
|
-
} : {}));
|
|
86
|
-
const newSession = Object.assign({}, state.session, {
|
|
87
|
-
authToken: newAuthToken
|
|
88
|
-
}); // Update current client config
|
|
89
|
-
|
|
90
|
-
_apiServices.http.setAuthorizeToken(newAuthToken.accessToken);
|
|
91
|
-
|
|
92
|
-
return Object.assign({}, state, {
|
|
93
|
-
session: newSession,
|
|
94
|
-
error: null,
|
|
95
|
-
loading: false
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
case userActionTypes.REFRESH_TOKEN_FAILURE:
|
|
99
|
-
return {
|
|
100
|
-
user: null,
|
|
101
|
-
session: Object.assign({}, state.session),
|
|
102
|
-
loading: null,
|
|
103
|
-
error: action.payload.error
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
case userActionTypes.LOGOUT:
|
|
107
|
-
return {
|
|
108
|
-
user: null,
|
|
109
|
-
session: null,
|
|
110
|
-
error: null,
|
|
111
|
-
loading: null
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
case userActionTypes.UPDATE_USER:
|
|
115
|
-
return Object.assign({}, state, {
|
|
116
|
-
user: Object.assign({}, state.user, action.payload)
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
case userActionTypes.REFRESH_SESSION:
|
|
120
|
-
return Object.assign({}, state, action.payload.conf);
|
|
121
|
-
|
|
122
|
-
default:
|
|
123
|
-
throw new Error(`Unhandled type: ${action.type}`);
|
|
124
|
-
}
|
|
41
|
+
switch (action.type) {
|
|
42
|
+
case userActionTypes.LOGIN_LOADING:
|
|
43
|
+
return { user: null, session: Object.assign({}, state.session), error: null, loading: true };
|
|
44
|
+
case userActionTypes.LOGIN_SUCCESS:
|
|
45
|
+
return { user: action.payload.user, error: null, session: Object.assign({}, state.session), loading: false };
|
|
46
|
+
case userActionTypes.LOGIN_FAILURE:
|
|
47
|
+
return { user: null, session: Object.assign({}, state.session), error: action.payload.error, loading: false };
|
|
48
|
+
case userActionTypes.REFRESH_TOKEN_SUCCESS:
|
|
49
|
+
const newAuthToken = Object.assign({}, state.session.authToken, Object.assign(Object.assign(Object.assign(Object.assign({}, state.session.authToken), { accessToken: action.payload.token.accessToken }), (action.payload.token.refreshToken ? { refreshToken: action.payload.token.refreshToken } : {})), (action.payload.token.expiresIn ? { expiresIn: action.payload.token.expiresIn } : {})));
|
|
50
|
+
const newSession = Object.assign({}, state.session, {
|
|
51
|
+
authToken: newAuthToken,
|
|
52
|
+
});
|
|
53
|
+
// Update current client config
|
|
54
|
+
http.setAuthorizeToken(newAuthToken.accessToken);
|
|
55
|
+
return Object.assign(Object.assign({}, state), { session: newSession, error: null, loading: false });
|
|
56
|
+
case userActionTypes.REFRESH_TOKEN_FAILURE:
|
|
57
|
+
return { user: null, session: Object.assign({}, state.session), loading: null, error: action.payload.error };
|
|
58
|
+
case userActionTypes.LOGOUT:
|
|
59
|
+
return { user: null, session: null, error: null, loading: null };
|
|
60
|
+
case userActionTypes.UPDATE_USER:
|
|
61
|
+
return Object.assign(Object.assign({}, state), { user: Object.assign(Object.assign({}, state.user), action.payload) });
|
|
62
|
+
case userActionTypes.REFRESH_SESSION:
|
|
63
|
+
return Object.assign(Object.assign({}, state), action.payload.conf);
|
|
64
|
+
default:
|
|
65
|
+
throw new Error(`Unhandled type: ${action.type}`);
|
|
66
|
+
}
|
|
125
67
|
}
|
|
126
68
|
/**
|
|
127
69
|
* Define initial context auth session
|
|
128
70
|
* @param session
|
|
129
71
|
*/
|
|
130
|
-
|
|
131
|
-
|
|
132
72
|
function stateInitializer(session) {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
_isLoading
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
_apiServices.http.setSupportWithCredentials(_session.type === Session.COOKIE_SESSION);
|
|
148
|
-
|
|
149
|
-
return {
|
|
150
|
-
user: null,
|
|
151
|
-
session: _session,
|
|
152
|
-
error: null,
|
|
153
|
-
loading: _isLoading,
|
|
154
|
-
isSessionRefreshing: false,
|
|
155
|
-
refreshSession: false
|
|
156
|
-
};
|
|
73
|
+
let _session = Object.assign({}, session);
|
|
74
|
+
let _isLoading = false;
|
|
75
|
+
/**
|
|
76
|
+
* Set http authorization if session type is OAuth or JWT
|
|
77
|
+
* Configure http object (Authorization, etc...)
|
|
78
|
+
*/
|
|
79
|
+
if ([Session.OAUTH_SESSION, Session.JWT_SESSION].includes(_session.type) && _session.authToken && _session.authToken.accessToken) {
|
|
80
|
+
http.setAuthorizeToken(_session.authToken.accessToken);
|
|
81
|
+
_isLoading = true;
|
|
82
|
+
}
|
|
83
|
+
http.setSupportWithCredentials(_session.type === Session.COOKIE_SESSION);
|
|
84
|
+
return { user: null, session: _session, error: null, loading: _isLoading, isSessionRefreshing: false, refreshSession: false };
|
|
157
85
|
}
|
|
158
86
|
/**
|
|
159
87
|
:::info
|
|
@@ -183,158 +111,130 @@ const scRoutingContext: SCRoutingContextType = useSCRouting();
|
|
|
183
111
|
:::
|
|
184
112
|
* @param initialSession
|
|
185
113
|
*/
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
_utils.Logger.error(_Errors.SCOPE_SC_CORE, 'Unable to refresh user session.');
|
|
216
|
-
|
|
217
|
-
if (error.response && error.response.data) {
|
|
218
|
-
dispatch({
|
|
219
|
-
type: userActionTypes.REFRESH_TOKEN_FAILURE,
|
|
220
|
-
payload: {
|
|
221
|
-
error: error.response.toString()
|
|
222
|
-
}
|
|
223
|
-
});
|
|
114
|
+
export default function useAuth(initialSession) {
|
|
115
|
+
const [state, dispatch] = useReducer(userReducer, {}, () => stateInitializer(initialSession));
|
|
116
|
+
let authInterceptor = useRef(null);
|
|
117
|
+
let isSessionRefreshing = useRef(false);
|
|
118
|
+
let failedQueue = useRef([]);
|
|
119
|
+
// CONST
|
|
120
|
+
const userId = state.user ? state.user.id : null;
|
|
121
|
+
const accessToken = state.session.authToken && state.session.authToken.accessToken ? state.session.authToken.accessToken : null;
|
|
122
|
+
/**
|
|
123
|
+
* Refresh session
|
|
124
|
+
*/
|
|
125
|
+
const refreshSession = useMemo(() => () => {
|
|
126
|
+
const session = state.session;
|
|
127
|
+
if (!isSessionRefreshing.current && session.handleRefreshToken) {
|
|
128
|
+
isSessionRefreshing.current = true;
|
|
129
|
+
return session
|
|
130
|
+
.handleRefreshToken(state.session)
|
|
131
|
+
.then((res) => {
|
|
132
|
+
isSessionRefreshing.current = false;
|
|
133
|
+
dispatch({ type: userActionTypes.REFRESH_TOKEN_SUCCESS, payload: { token: res } });
|
|
134
|
+
return Promise.resolve(res);
|
|
135
|
+
})
|
|
136
|
+
.catch((error) => {
|
|
137
|
+
Logger.error(SCOPE_SC_CORE, 'Unable to refresh user session.');
|
|
138
|
+
if (error.response && error.response.data) {
|
|
139
|
+
dispatch({ type: userActionTypes.REFRESH_TOKEN_FAILURE, payload: { error: error.response.toString() } });
|
|
140
|
+
}
|
|
141
|
+
return Promise.reject(error);
|
|
142
|
+
});
|
|
224
143
|
}
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
*/
|
|
237
|
-
|
|
238
|
-
const processQueue = (0, _react.useMemo)(() => (error, token = null) => {
|
|
239
|
-
failedQueue.current.forEach(prom => {
|
|
240
|
-
if (error) {
|
|
241
|
-
prom.reject(error);
|
|
242
|
-
} else {
|
|
243
|
-
prom.resolve(token);
|
|
244
|
-
}
|
|
245
|
-
});
|
|
246
|
-
failedQueue.current = [];
|
|
247
|
-
}, [failedQueue.current]);
|
|
248
|
-
/**
|
|
249
|
-
* Add/remove an http request interceptor.
|
|
250
|
-
* When the component unmounted the interceptor will be detached
|
|
251
|
-
* The interceptor check if the token is expiring
|
|
252
|
-
*/
|
|
253
|
-
|
|
254
|
-
(0, _react.useEffect)(() => {
|
|
255
|
-
if (userId !== null) {
|
|
256
|
-
authInterceptor.current = _apiServices.http.getClientInstance().interceptors.response.use(response => {
|
|
257
|
-
return response;
|
|
258
|
-
}, async error => {
|
|
259
|
-
let originalConfig = error.config;
|
|
260
|
-
|
|
261
|
-
if (error.response) {
|
|
262
|
-
if (error.response.status === 401) {
|
|
263
|
-
/**
|
|
264
|
-
* if other requests arrive at the same time
|
|
265
|
-
* as the token refresh, we save them for later
|
|
266
|
-
*/
|
|
267
|
-
if (isSessionRefreshing.current) {
|
|
268
|
-
return new Promise(function (resolve, reject) {
|
|
269
|
-
failedQueue.current.push({
|
|
270
|
-
resolve,
|
|
271
|
-
reject
|
|
272
|
-
});
|
|
273
|
-
}).then(token => {
|
|
274
|
-
originalConfig.headers['Authorization'] = 'Bearer ' + token;
|
|
275
|
-
return _apiServices.http.request(originalConfig);
|
|
276
|
-
}).catch(err => {
|
|
277
|
-
_utils.Logger.error(_Errors.SCOPE_SC_CORE, 'Unable to resolve promises in failedQueue.');
|
|
278
|
-
|
|
279
|
-
return Promise.reject(err);
|
|
280
|
-
});
|
|
144
|
+
return Promise.reject(new Error('Unable to refresh session. Unauthenticated user.'));
|
|
145
|
+
}, [accessToken]);
|
|
146
|
+
/**
|
|
147
|
+
* Manages multiple request during refresh session
|
|
148
|
+
* Save concurrent requests and retry them again
|
|
149
|
+
* at the end of refreshing session
|
|
150
|
+
*/
|
|
151
|
+
const processQueue = useMemo(() => (error, token = null) => {
|
|
152
|
+
failedQueue.current.forEach((prom) => {
|
|
153
|
+
if (error) {
|
|
154
|
+
prom.reject(error);
|
|
281
155
|
}
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
* we avoid doing it again
|
|
285
|
-
*/
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
const session = state.session;
|
|
289
|
-
const authToken = session && 'authToken' in session ? session.authToken : null;
|
|
290
|
-
|
|
291
|
-
if (session.type !== Session.COOKIE_SESSION && !isSessionRefreshing.current && state.user && session && session.handleRefreshToken && Boolean(authToken && authToken.refreshToken)) {
|
|
292
|
-
/**
|
|
293
|
-
* set refreshing mode,
|
|
294
|
-
* save all concurrent request in the meantime
|
|
295
|
-
*/
|
|
296
|
-
try {
|
|
297
|
-
const res = await refreshSession();
|
|
298
|
-
originalConfig.headers.Authorization = `Bearer ${res['accessToken']}`;
|
|
299
|
-
processQueue(null, res['accessToken']);
|
|
300
|
-
return Promise.resolve(_apiServices.http.request(originalConfig));
|
|
301
|
-
} catch (_error) {
|
|
302
|
-
if (_error.response && _error.response.data) {
|
|
303
|
-
processQueue(_error, null);
|
|
304
|
-
return Promise.reject(_error.response.data);
|
|
305
|
-
}
|
|
306
|
-
}
|
|
156
|
+
else {
|
|
157
|
+
prom.resolve(token);
|
|
307
158
|
}
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
159
|
+
});
|
|
160
|
+
failedQueue.current = [];
|
|
161
|
+
}, [failedQueue.current]);
|
|
162
|
+
/**
|
|
163
|
+
* Add/remove an http request interceptor.
|
|
164
|
+
* When the component unmounted the interceptor will be detached
|
|
165
|
+
* The interceptor check if the token is expiring
|
|
166
|
+
*/
|
|
167
|
+
useEffect(() => {
|
|
168
|
+
if (userId !== null) {
|
|
169
|
+
authInterceptor.current = http.getClientInstance().interceptors.response.use((response) => {
|
|
170
|
+
return response;
|
|
171
|
+
}, (error) => __awaiter(this, void 0, void 0, function* () {
|
|
172
|
+
let originalConfig = error.config;
|
|
173
|
+
if (error.response) {
|
|
174
|
+
if (error.response.status === 401) {
|
|
175
|
+
/**
|
|
176
|
+
* if other requests arrive at the same time
|
|
177
|
+
* as the token refresh, we save them for later
|
|
178
|
+
*/
|
|
179
|
+
if (isSessionRefreshing.current) {
|
|
180
|
+
return new Promise(function (resolve, reject) {
|
|
181
|
+
failedQueue.current.push({ resolve, reject });
|
|
182
|
+
})
|
|
183
|
+
.then((token) => {
|
|
184
|
+
originalConfig.headers['Authorization'] = 'Bearer ' + token;
|
|
185
|
+
return http.request(originalConfig);
|
|
186
|
+
})
|
|
187
|
+
.catch((err) => {
|
|
188
|
+
Logger.error(SCOPE_SC_CORE, 'Unable to resolve promises in failedQueue.');
|
|
189
|
+
return Promise.reject(err);
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* we mark the request as retried,
|
|
194
|
+
* we avoid doing it again
|
|
195
|
+
*/
|
|
196
|
+
const session = state.session;
|
|
197
|
+
const authToken = session && 'authToken' in session ? session.authToken : null;
|
|
198
|
+
if (session.type !== Session.COOKIE_SESSION &&
|
|
199
|
+
!isSessionRefreshing.current &&
|
|
200
|
+
state.user &&
|
|
201
|
+
session &&
|
|
202
|
+
session.handleRefreshToken &&
|
|
203
|
+
Boolean(authToken && authToken.refreshToken)) {
|
|
204
|
+
/**
|
|
205
|
+
* set refreshing mode,
|
|
206
|
+
* save all concurrent request in the meantime
|
|
207
|
+
*/
|
|
208
|
+
try {
|
|
209
|
+
const res = yield refreshSession();
|
|
210
|
+
originalConfig.headers.Authorization = `Bearer ${res['accessToken']}`;
|
|
211
|
+
processQueue(null, res['accessToken']);
|
|
212
|
+
return Promise.resolve(http.request(originalConfig));
|
|
213
|
+
}
|
|
214
|
+
catch (_error) {
|
|
215
|
+
if (_error.response && _error.response.data) {
|
|
216
|
+
processQueue(_error, null);
|
|
217
|
+
return Promise.reject(_error.response.data);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
return Promise.reject(error);
|
|
223
|
+
}
|
|
224
|
+
}));
|
|
311
225
|
}
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
type: userActionTypes.REFRESH_SESSION,
|
|
328
|
-
payload: {
|
|
329
|
-
conf: stateInitializer(initialSession)
|
|
330
|
-
}
|
|
331
|
-
});
|
|
332
|
-
}, [initialSession]);
|
|
333
|
-
return {
|
|
334
|
-
state,
|
|
335
|
-
dispatch,
|
|
336
|
-
helpers: {
|
|
337
|
-
refreshSession
|
|
338
|
-
}
|
|
339
|
-
};
|
|
340
|
-
}
|
|
226
|
+
return () => {
|
|
227
|
+
if (authInterceptor.current !== null) {
|
|
228
|
+
http.getClientInstance().interceptors.response.eject(authInterceptor.current);
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
}, [userId, accessToken]);
|
|
232
|
+
/**
|
|
233
|
+
* Reset session if initial conf changed
|
|
234
|
+
*/
|
|
235
|
+
useDeepCompareEffect(() => {
|
|
236
|
+
dispatch({ type: userActionTypes.REFRESH_SESSION, payload: { conf: stateInitializer(initialSession) } });
|
|
237
|
+
}, [initialSession]);
|
|
238
|
+
return { state, dispatch, helpers: { refreshSession } };
|
|
239
|
+
}
|
|
240
|
+
//# sourceMappingURL=useSCAuth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSCAuth.js","sourceRoot":"","sources":["../../../src/hooks/useSCAuth.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAC,IAAI,EAAC,MAAM,6BAA6B,CAAC;AACjD,OAAO,EAAC,SAAS,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,EAAC,MAAM,OAAO,CAAC;AAG7D,OAAO,KAAK,OAAO,MAAM,sBAAsB,CAAC;AAChD,OAAO,oBAAoB,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAC,MAAM,EAAC,MAAM,sBAAsB,CAAC;AAC5C,OAAO,EAAC,aAAa,EAAC,MAAM,qBAAqB,CAAC;AAElD;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,aAAa,EAAE,gBAAgB;IAC/B,aAAa,EAAE,gBAAgB;IAC/B,aAAa,EAAE,gBAAgB;IAC/B,MAAM,EAAE,SAAS;IACjB,qBAAqB,EAAE,wBAAwB;IAC/C,qBAAqB,EAAE,wBAAwB;IAC/C,eAAe,EAAE,gBAA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QAAQ,CAAC,IAAI,CAAC,CAAC;iCAC7C;6BACF;yBACF;qBACF;oBACD,OAAO,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;iBAC9B;YACH,CAAC,CAAA,CACF,CAAC;SACH;QACD,OAAO,GAAS,EAAE;YAChB,IAAI,eAAe,CAAC,OAAO,KAAK,IAAI,EAAE;gBACpC,IAAI,CAAC,iBAAiB,EAAE,CAAC,YAAY,CAAC,QAAQ,CAAC,KAAK,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;aAC/E;QACH,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC;IAE1B;;OAEG;IACH,oBAAoB,CAAC,GAAG,EAAE;QACxB,QAAQ,CAAC,EAAC,IAAI,EAAE,eAAe,CAAC,eAAe,EAAE,OAAO,EAAE,EAAC,IAAI,EAAE,gBAAgB,CAAC,cAAc,CAAC,EAAC,EAAC,CAAC,CAAC;IACvG,CAAC,EAAE,CAAC,cAAc,CAAC,CAAC,CAAC;IAErB,OAAO,EAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,EAAC,cAAc,EAAC,EAAC,CAAC;AACtD,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
/**
|
|
3
|
+
:::info
|
|
4
|
+
This custom hook manages cached data and the loading state.
|
|
5
|
+
:::
|
|
6
|
+
*/
|
|
7
|
+
export default function useSCCachingManager(): {
|
|
8
|
+
cache: number[];
|
|
9
|
+
updateCache: (ids: number[]) => void;
|
|
10
|
+
emptyCache: () => void;
|
|
11
|
+
data: any[];
|
|
12
|
+
setData: import("react").Dispatch<import("react").SetStateAction<any[]>>;
|
|
13
|
+
loading: number[];
|
|
14
|
+
setLoading: import("react").Dispatch<import("react").SetStateAction<number[]>>;
|
|
15
|
+
isLoading: (obj: {
|
|
16
|
+
id: number;
|
|
17
|
+
}) => boolean;
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=useSCCachingManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSCCachingManager.d.ts","sourceRoot":"","sources":["../../../src/hooks/useSCCachingManager.ts"],"names":[],"mappings":";AAEA;;;;GAIG;AACH,MAAM,CAAC,OAAO,UAAU,mBAAmB;;uBAW/B,MAAM,EAAE,KAAG,IAAI;sBAgBb,IAAI;;;;;qBAcN;QAAC,EAAE,EAAE,MAAM,CAAA;KAAC,KAAG,OAAO;EAOjC"}
|
|
@@ -1,58 +1,41 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.__esModule = true;
|
|
4
|
-
exports.default = useSCCachingManager;
|
|
5
|
-
|
|
6
|
-
var _react = require("react");
|
|
7
|
-
|
|
1
|
+
import { useMemo, useRef, useState } from 'react';
|
|
8
2
|
/**
|
|
9
3
|
:::info
|
|
10
4
|
This custom hook manages cached data and the loading state.
|
|
11
5
|
:::
|
|
12
6
|
*/
|
|
13
|
-
function useSCCachingManager() {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
return {
|
|
49
|
-
cache: cache.current,
|
|
50
|
-
updateCache,
|
|
51
|
-
emptyCache,
|
|
52
|
-
data,
|
|
53
|
-
setData,
|
|
54
|
-
loading,
|
|
55
|
-
setLoading,
|
|
56
|
-
isLoading
|
|
57
|
-
};
|
|
58
|
-
}
|
|
7
|
+
export default function useSCCachingManager() {
|
|
8
|
+
const cache = useRef([]);
|
|
9
|
+
const [loading, setLoading] = useState([]);
|
|
10
|
+
const [data, setData] = useState([]);
|
|
11
|
+
/**
|
|
12
|
+
* Update cache
|
|
13
|
+
* @param ids
|
|
14
|
+
*/
|
|
15
|
+
const updateCache = useMemo(() => (ids) => {
|
|
16
|
+
ids.map((c) => {
|
|
17
|
+
if (!cache.current.includes(c)) {
|
|
18
|
+
cache.current.push(c);
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}, [cache]);
|
|
22
|
+
/**
|
|
23
|
+
* Empty cache
|
|
24
|
+
* emptying the cache each isFollow request
|
|
25
|
+
* results in a request to the server
|
|
26
|
+
*/
|
|
27
|
+
const emptyCache = useMemo(() => () => {
|
|
28
|
+
cache.current = [];
|
|
29
|
+
}, [cache]);
|
|
30
|
+
/**
|
|
31
|
+
* Category is checking
|
|
32
|
+
* Return true if the manager is checking
|
|
33
|
+
* the follow status of the obj
|
|
34
|
+
* @param category
|
|
35
|
+
*/
|
|
36
|
+
const isLoading = useMemo(() => (obj) => {
|
|
37
|
+
return loading.includes(obj.id);
|
|
38
|
+
}, [loading]);
|
|
39
|
+
return { cache: cache.current, updateCache, emptyCache, data, setData, loading, setLoading, isLoading };
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=useSCCachingManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSCCachingManager.js","sourceRoot":"","sources":["../../../src/hooks/useSCCachingManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAC,MAAM,OAAO,CAAC;AAEhD;;;;GAIG;AACH,MAAM,CAAC,OAAO,UAAU,mBAAmB;IACzC,MAAM,KAAK,GAAG,MAAM,CAAW,EAAE,CAAC,CAAC;IACnC,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAW,EAA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