@wavemaker/react-runtime 11.14.1-rc.236
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/actions/base-action.js +32 -0
- package/actions/login-action.js +53 -0
- package/actions/logout-action.js +41 -0
- package/actions/navigation-action.js +145 -0
- package/actions/notification-action.js +147 -0
- package/actions/timer-action.js +164 -0
- package/actions/toast-provider.js +111 -0
- package/actions/toast.js +115 -0
- package/actions/toast.service.js +94 -0
- package/actions/types/index.js +11 -0
- package/components/advanced/carousel/index.js +456 -0
- package/components/advanced/carousel/props.js +5 -0
- package/components/advanced/carousel/template.js +72 -0
- package/components/advanced/login/index.js +307 -0
- package/components/advanced/login/props.js +5 -0
- package/components/advanced/marquee/index.js +158 -0
- package/components/advanced/marquee/props.js +5 -0
- package/components/basic/anchor/index.js +239 -0
- package/components/basic/anchor/props.js +5 -0
- package/components/basic/audio/index.js +61 -0
- package/components/basic/html/index.js +158 -0
- package/components/basic/icon/index.js +85 -0
- package/components/basic/iframe/iframe.utils.js +10 -0
- package/components/basic/iframe/index.js +95 -0
- package/components/basic/label/index.js +139 -0
- package/components/basic/message/index.js +120 -0
- package/components/basic/message/props.js +5 -0
- package/components/basic/picture/index.js +117 -0
- package/components/basic/picture/props.js +5 -0
- package/components/basic/progress-bar/index.js +168 -0
- package/components/basic/progress-bar/props.js +18 -0
- package/components/basic/progress-circle/index.js +196 -0
- package/components/basic/progress-circle/props.js +16 -0
- package/components/basic/richtexteditor/index.js +533 -0
- package/components/basic/richtexteditor/props.js +5 -0
- package/components/basic/search/index.js +1023 -0
- package/components/basic/search/props.js +5 -0
- package/components/basic/search/providers.js +350 -0
- package/components/basic/spinner/index.js +202 -0
- package/components/basic/spinner/props.js +12 -0
- package/components/basic/tile/index.js +91 -0
- package/components/basic/tree/Components/TreeNodeComponent.js +142 -0
- package/components/basic/tree/index.js +503 -0
- package/components/basic/tree/props.js +5 -0
- package/components/basic/tree/utils.js +154 -0
- package/components/basic/video/index.js +85 -0
- package/components/basic/video/props.js +5 -0
- package/components/chart/components/barColumnChart/index.js +132 -0
- package/components/chart/components/barColumnChart/props.js +5 -0
- package/components/chart/components/bubbleChart/index.js +176 -0
- package/components/chart/components/bubbleChart/props.js +5 -0
- package/components/chart/components/chartLegend/components/ClassicLegendItem.js +39 -0
- package/components/chart/components/chartLegend/components/FuriousLegendItem.js +81 -0
- package/components/chart/components/chartLegend/index.js +69 -0
- package/components/chart/components/chartLegend/props.js +5 -0
- package/components/chart/components/chartLegend/utils.js +31 -0
- package/components/chart/components/chartTooltip/index.js +53 -0
- package/components/chart/components/chartTooltip/styles.js +37 -0
- package/components/chart/components/chartTooltip/utils.js +23 -0
- package/components/chart/components/cumulativeLineChart/index.js +113 -0
- package/components/chart/components/cumulativeLineChart/props.js +5 -0
- package/components/chart/components/cumulativeLineChart/utils.js +34 -0
- package/components/chart/components/index.js +40 -0
- package/components/chart/components/lineAreaChart/index.js +140 -0
- package/components/chart/components/lineAreaChart/props.js +5 -0
- package/components/chart/components/noDataMessage/index.js +27 -0
- package/components/chart/components/pieDonutChart/index.js +171 -0
- package/components/chart/components/pieDonutChart/props.js +5 -0
- package/components/chart/constant.js +72 -0
- package/components/chart/index.js +930 -0
- package/components/chart/props.js +5 -0
- package/components/chart/utils.js +691 -0
- package/components/common/AppSpinner.js +36 -0
- package/components/common/app-spinner.js +26 -0
- package/components/common/index.js +12 -0
- package/components/constants.js +1208 -0
- package/components/container/accordion/accordion-pane/index.js +108 -0
- package/components/container/accordion/accordion-pane/props.js +11 -0
- package/components/container/accordion/index.js +232 -0
- package/components/container/accordion/props.js +13 -0
- package/components/container/alignment-utils.js +183 -0
- package/components/container/index.js +188 -0
- package/components/container/layout-grid/grid-column/index.js +34 -0
- package/components/container/layout-grid/grid-row/index.js +24 -0
- package/components/container/layout-grid/index.js +33 -0
- package/components/container/linear-layout/index.js +72 -0
- package/components/container/linear-layout/linear-layout-item/index.js +43 -0
- package/components/container/panel/components/panel-header/index.js +144 -0
- package/components/container/panel/components/panel-header/props.js +5 -0
- package/components/container/panel/hooks.js +144 -0
- package/components/container/panel/index.js +286 -0
- package/components/container/panel/props.js +5 -0
- package/components/container/props.js +5 -0
- package/components/container/tabs/index.js +379 -0
- package/components/container/tabs/props.js +20 -0
- package/components/container/tabs/tab-pane/index.js +42 -0
- package/components/container/tabs/tab-pane/props.js +5 -0
- package/components/container/wizard/WizardContext.js +16 -0
- package/components/container/wizard/components/StepComponents.js +100 -0
- package/components/container/wizard/components/WizardStep.js +89 -0
- package/components/container/wizard/index.js +710 -0
- package/components/container/wizard/props.js +5 -0
- package/components/container/wizard/utils.js +133 -0
- package/components/container/wizard/wizard-action/index.js +22 -0
- package/components/container/wizard/wizard-step/index.js +94 -0
- package/components/data/card/card-actions/index.js +24 -0
- package/components/data/card/card-content/index.js +38 -0
- package/components/data/card/card-footer/index.js +24 -0
- package/components/data/card/index.js +246 -0
- package/components/data/card/props.js +5 -0
- package/components/data/form/base-form/constant.js +39 -0
- package/components/data/form/base-form/index.js +460 -0
- package/components/data/form/base-form/props.js +29 -0
- package/components/data/form/base-form/utils.js +42 -0
- package/components/data/form/dynamic-fields/index.js +196 -0
- package/components/data/form/dynamic-fields/props.js +5 -0
- package/components/data/form/dynamic-fields/utils.js +237 -0
- package/components/data/form/form-action/index.js +71 -0
- package/components/data/form/form-body/index.js +26 -0
- package/components/data/form/form-context.js +34 -0
- package/components/data/form/form-controller/props.js +19 -0
- package/components/data/form/form-controller/validation-contrustor.js +313 -0
- package/components/data/form/form-controller/withFormController.js +320 -0
- package/components/data/form/form-field/base-field.js +138 -0
- package/components/data/form/form-field/index.js +36 -0
- package/components/data/form/form-field/props.js +5 -0
- package/components/data/form/form-footer/index.js +26 -0
- package/components/data/form/form-header/index.js +56 -0
- package/components/data/form/index.js +39 -0
- package/components/data/form/props.js +5 -0
- package/components/data/list/components/GroupHeader.js +35 -0
- package/components/data/list/components/GroupedListItems.js +98 -0
- package/components/data/list/components/ListContainer.js +27 -0
- package/components/data/list/components/ListDND.js +241 -0
- package/components/data/list/components/ListHeader.js +59 -0
- package/components/data/list/components/ListItem.js +148 -0
- package/components/data/list/components/ListItemWithTemplate.js +59 -0
- package/components/data/list/components/ListItems.js +231 -0
- package/components/data/list/components/ListPagination.js +165 -0
- package/components/data/list/components/LoadMoreButton.js +39 -0
- package/components/data/list/components/NoDataMessage.js +22 -0
- package/components/data/list/components/StandardListItems.js +84 -0
- package/components/data/list/components/index.js +119 -0
- package/components/data/list/components/props.js +5 -0
- package/components/data/list/hooks/index.js +75 -0
- package/components/data/list/hooks/props.js +5 -0
- package/components/data/list/hooks/useCurrentPageItems.js +48 -0
- package/components/data/list/hooks/useGroupedData.js +37 -0
- package/components/data/list/hooks/useListData.js +60 -0
- package/components/data/list/hooks/useListEffects.js +285 -0
- package/components/data/list/hooks/useListEventHandlers.js +291 -0
- package/components/data/list/hooks/useListPagination.js +168 -0
- package/components/data/list/hooks/useListState.js +98 -0
- package/components/data/list/hooks/useListStateManager.js +195 -0
- package/components/data/list/hooks/usePaginatedGroupedData.js +121 -0
- package/components/data/list/index.js +611 -0
- package/components/data/list/props.js +5 -0
- package/components/data/list/templates/media-template.js +53 -0
- package/components/data/list/utils/constants.js +81 -0
- package/components/data/list/utils/list-helpers.js +173 -0
- package/components/data/list/utils/list-widget-methods.js +114 -0
- package/components/data/live-filter/index.js +279 -0
- package/components/data/live-filter/props.js +12 -0
- package/components/data/live-form/index.js +93 -0
- package/components/data/live-form/props.js +16 -0
- package/components/data/pagination/components/BasicPagination.js +77 -0
- package/components/data/pagination/components/ClassicPagination.js +191 -0
- package/components/data/pagination/components/InlinePagination.js +99 -0
- package/components/data/pagination/components/LoadingComponent.js +31 -0
- package/components/data/pagination/components/PageSizeSelector.js +175 -0
- package/components/data/pagination/components/PagerNavigation.js +105 -0
- package/components/data/pagination/components/TotalRecords.js +52 -0
- package/components/data/pagination/components/index.js +47 -0
- package/components/data/pagination/components/props.js +5 -0
- package/components/data/pagination/hooks/index.js +19 -0
- package/components/data/pagination/hooks/props.js +5 -0
- package/components/data/pagination/hooks/useNavigationSize.js +44 -0
- package/components/data/pagination/hooks/usePagination.js +796 -0
- package/components/data/pagination/index.js +322 -0
- package/components/data/table/components/AddNewRow.js +190 -0
- package/components/data/table/components/EditableCell.js +91 -0
- package/components/data/table/components/FieldValidationError.js +24 -0
- package/components/data/table/components/RowExpansionButton.js +74 -0
- package/components/data/table/components/TableBody.js +279 -0
- package/components/data/table/components/TableFilters.js +325 -0
- package/components/data/table/components/TableFooterActions.js +48 -0
- package/components/data/table/components/TableHeader.js +174 -0
- package/components/data/table/components/TablePanelHeading.js +68 -0
- package/components/data/table/components/index.js +74 -0
- package/components/data/table/hooks/index.js +219 -0
- package/components/data/table/hooks/useCellState.js +117 -0
- package/components/data/table/hooks/useDynamicColumns.js +85 -0
- package/components/data/table/hooks/useEditingState.js +47 -0
- package/components/data/table/hooks/useFormWidget.js +184 -0
- package/components/data/table/hooks/usePaginationState.js +60 -0
- package/components/data/table/hooks/usePanelStructure.js +40 -0
- package/components/data/table/hooks/useResponsiveColumns.js +34 -0
- package/components/data/table/hooks/useRowExpansion.js +110 -0
- package/components/data/table/hooks/useRowHandlers.js +38 -0
- package/components/data/table/hooks/useRowSelection.js +213 -0
- package/components/data/table/hooks/useServerSideSorting.js +165 -0
- package/components/data/table/hooks/useTableColumns.js +263 -0
- package/components/data/table/hooks/useTableData.js +154 -0
- package/components/data/table/hooks/useTableEdit.js +467 -0
- package/components/data/table/hooks/useTableEffects.js +139 -0
- package/components/data/table/hooks/useTableFilter.js +389 -0
- package/components/data/table/hooks/useTableInitialization.js +103 -0
- package/components/data/table/hooks/useTableState.js +69 -0
- package/components/data/table/hooks/useTableStateManager.js +558 -0
- package/components/data/table/index.js +1295 -0
- package/components/data/table/live-table/index.js +232 -0
- package/components/data/table/props.js +5 -0
- package/components/data/table/table-action/index.js +78 -0
- package/components/data/table/table-column/index.js +35 -0
- package/components/data/table/table-row/index.js +49 -0
- package/components/data/table/table-row-action/index.js +74 -0
- package/components/data/table/utils/buildSelectionColumns.js +173 -0
- package/components/data/table/utils/columnBuilder.js +209 -0
- package/components/data/table/utils/columnProxy.js +48 -0
- package/components/data/table/utils/columnWidthDistribution.js +98 -0
- package/components/data/table/utils/constants.js +80 -0
- package/components/data/table/utils/crud-handlers.js +518 -0
- package/components/data/table/utils/dynamic-columns.js +118 -0
- package/components/data/table/utils/index.js +607 -0
- package/components/data/table/utils/renderDisplayCell.js +183 -0
- package/components/data/table/utils/selectionUtils.js +166 -0
- package/components/data/table/utils/table-helpers.js +100 -0
- package/components/data/table/utils/validation.js +124 -0
- package/components/data/types.js +113 -0
- package/components/data/utils/field-data-utils.js +66 -0
- package/components/data/utils/filter-field-util.js +81 -0
- package/components/data/utils/index.js +216 -0
- package/components/dialogs/alert-dialog/index.js +80 -0
- package/components/dialogs/confirm-dialog/index.js +105 -0
- package/components/dialogs/dialog/index.js +56 -0
- package/components/dialogs/dialog-actions/index.js +18 -0
- package/components/dialogs/dialog-body/index.js +21 -0
- package/components/dialogs/dialog-content/index.js +30 -0
- package/components/dialogs/dialog-header/index.js +93 -0
- package/components/dialogs/iframe-dialog/index.js +114 -0
- package/components/dialogs/index.js +129 -0
- package/components/dialogs/login-dialog/index.js +369 -0
- package/components/dialogs/login-dialog/props.js +5 -0
- package/components/dialogs/page-dialog/index.js +96 -0
- package/components/dialogs/withDialogWrapper.js +108 -0
- package/components/form/button/index.js +216 -0
- package/components/form/button-group/index.js +60 -0
- package/components/input/calendar/index.js +546 -0
- package/components/input/calendar/props.js +5 -0
- package/components/input/calendar/utils.js +340 -0
- package/components/input/chips/SortableChip/index.js +115 -0
- package/components/input/chips/SortableChip/props.js +5 -0
- package/components/input/chips/index.js +488 -0
- package/components/input/chips/props.js +5 -0
- package/components/input/chips/utils.js +259 -0
- package/components/input/color-picker/index.js +678 -0
- package/components/input/color-picker/props.js +5 -0
- package/components/input/composite/index.js +137 -0
- package/components/input/currency/index.js +263 -0
- package/components/input/currency/props.js +5 -0
- package/components/input/default/checkbox/index.js +230 -0
- package/components/input/default/checkbox/props.js +5 -0
- package/components/input/default/checkboxset/index.js +476 -0
- package/components/input/default/checkboxset/props.js +5 -0
- package/components/input/default/radioset/index.js +379 -0
- package/components/input/default/radioset/props.js +5 -0
- package/components/input/default/switch/index.js +490 -0
- package/components/input/default/switch/prop.js +5 -0
- package/components/input/epoch/date/components/DatePickerPopover.js +220 -0
- package/components/input/epoch/date/index.js +520 -0
- package/components/input/epoch/date/props.js +5 -0
- package/components/input/epoch/date/styled.js +70 -0
- package/components/input/epoch/date/utils.js +108 -0
- package/components/input/epoch/datetime/index.js +656 -0
- package/components/input/epoch/datetime/props.js +5 -0
- package/components/input/epoch/datetime/styled.js +90 -0
- package/components/input/epoch/datetime/utils.js +244 -0
- package/components/input/epoch/time/index.js +412 -0
- package/components/input/epoch/time/props.js +5 -0
- package/components/input/epoch/time/utils.js +209 -0
- package/components/input/fileupload/Utils.js +134 -0
- package/components/input/fileupload/components/ListItems.js +140 -0
- package/components/input/fileupload/components/MultiUpload.js +85 -0
- package/components/input/fileupload/components/SingleUpload.js +65 -0
- package/components/input/fileupload/index.js +170 -0
- package/components/input/fileupload/props.js +5 -0
- package/components/input/fileupload/useFileUpload.js +400 -0
- package/components/input/number/index.js +295 -0
- package/components/input/number/props.js +5 -0
- package/components/input/rating/index.js +368 -0
- package/components/input/rating/props.js +5 -0
- package/components/input/select/index.js +344 -0
- package/components/input/select/props.js +5 -0
- package/components/input/slider/index.js +167 -0
- package/components/input/slider/props.js +5 -0
- package/components/input/text/index.js +434 -0
- package/components/input/text/props.js +5 -0
- package/components/input/text/util.js +179 -0
- package/components/input/textarea/index.js +347 -0
- package/components/input/textarea/props.js +5 -0
- package/components/layout/footer/index.js +30 -0
- package/components/layout/header/index.js +30 -0
- package/components/layout/leftnav/index.js +44 -0
- package/components/layout/rightnav/index.js +32 -0
- package/components/layout/topnav/index.js +34 -0
- package/components/navbar/index.js +41 -0
- package/components/navbar/nav/index.js +102 -0
- package/components/navbar/nav/props.js +5 -0
- package/components/navbar/nav-item/index.js +44 -0
- package/components/navigation/breadcrumb/index.js +56 -0
- package/components/navigation/breadcrumb/props.js +5 -0
- package/components/navigation/menu/components/ListItems.js +66 -0
- package/components/navigation/menu/constants.js +101 -0
- package/components/navigation/menu/index.js +807 -0
- package/components/navigation/menu/props.js +5 -0
- package/components/navigation/popover/index.js +209 -0
- package/components/navigation/popover/props.js +15 -0
- package/components/page/content/index.js +28 -0
- package/components/page/error-boundary/index.js +108 -0
- package/components/page/index.js +137 -0
- package/components/page/page-content/index.js +23 -0
- package/components/page/partial/index.js +36 -0
- package/components/page/partial-container/index.js +48 -0
- package/components/page/props.js +5 -0
- package/components/page/toast-container/index.js +33 -0
- package/components/prefab/container/index.js +46 -0
- package/components/prefab/index.js +67 -0
- package/context/AppContext.js +25 -0
- package/context/AppSpinnerProvider.js +43 -0
- package/context/LocalizationProvider.js +79 -0
- package/context/PrefabContext.js +66 -0
- package/context/WidgetProvider.js +187 -0
- package/core/app-config.js +1 -0
- package/core/app.service.js +357 -0
- package/core/appVariablesStore.js +20 -0
- package/core/appstore.js +88 -0
- package/core/constants/currency-constant.js +1071 -0
- package/core/constants/events.js +34 -0
- package/core/constants/index.js +27 -0
- package/core/dialog.service.js +76 -0
- package/core/event-notifier.js +151 -0
- package/core/formatter/date-formatters.js +222 -0
- package/core/formatter/index.js +131 -0
- package/core/formatter/number-formatters.js +142 -0
- package/core/formatter/security-formatters.js +323 -0
- package/core/formatter/string-formatters.js +52 -0
- package/core/formatter/types.js +18 -0
- package/core/formatters.js +24 -0
- package/core/proxy-service.js +412 -0
- package/core/script-registry.js +63 -0
- package/core/security.service.js +11 -0
- package/core/util/common.js +33 -0
- package/core/util/dom.js +107 -0
- package/core/util/index.js +136 -0
- package/core/util/security.js +184 -0
- package/core/util/utils.js +189 -0
- package/core/widget-observer.js +98 -0
- package/higherOrder/BaseApp.js +430 -0
- package/higherOrder/BaseAppProps.js +5 -0
- package/higherOrder/BaseDateTime.js +251 -0
- package/higherOrder/BasePage.js +715 -0
- package/higherOrder/BasePartial.js +124 -0
- package/higherOrder/BasePrefab.js +145 -0
- package/higherOrder/DataNav.js +377 -0
- package/higherOrder/helper.js +43 -0
- package/higherOrder/props.js +5 -0
- package/higherOrder/withBaseWrapper.js +183 -0
- package/hooks/useAccess.js +308 -0
- package/hooks/useAppConfig.js +42 -0
- package/hooks/useAuth.js +562 -0
- package/hooks/useDataSourceSubscription.js +125 -0
- package/hooks/useDebounce.js +76 -0
- package/hooks/useDeviceVisibility.js +49 -0
- package/hooks/useHttp.js +338 -0
- package/libs/index.js +20 -0
- package/mui-config/theme-provider.js +17 -0
- package/mui-config/theme.js +371 -0
- package/package-lock.json +10183 -0
- package/package.json +95 -0
- package/store/index.js +33 -0
- package/store/middleware/navigationMiddleware.js +48 -0
- package/store/slices/appConfigSlice.js +103 -0
- package/store/slices/authSlice.js +508 -0
- package/store/slices/i18nSlice.js +206 -0
- package/types/index.js +15 -0
- package/utils/dataset-util.js +174 -0
- package/utils/eval-expression.js +32 -0
- package/utils/form-state.util.js +140 -0
- package/utils/form-utils.js +187 -0
- package/utils/format-util.js +260 -0
- package/utils/page-params-util.js +24 -0
- package/utils/resource-url.js +27 -0
- package/utils/state-persistance.js +343 -0
- package/utils/style-utils.js +73 -0
- package/utils/transformedDataset-utils.js +633 -0
- package/utils/widget-cleanup-util.js +84 -0
- package/utils/widgets.js +99 -0
- package/variables/base-variable.js +173 -0
- package/variables/constants.js +27 -0
- package/variables/live-variable.js +166 -0
- package/variables/model-variable.js +77 -0
- package/variables/service-variable.js +307 -0
package/hooks/useAuth.js
ADDED
|
@@ -0,0 +1,562 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.useWidgetAccess = exports.usePageAccess = exports.useLogout = exports.useLogin = exports.useCurrentUser = exports.useAuth = exports.useAccess = exports.checkAccessSync = void 0;
|
|
8
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
9
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
10
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
11
|
+
var _react = require("react");
|
|
12
|
+
var _store = require("../store");
|
|
13
|
+
var _authSlice = require("@wavemaker/react-runtime/store/slices/authSlice");
|
|
14
|
+
var _includes = _interopRequireDefault(require("lodash-es/includes"));
|
|
15
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
16
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
17
|
+
var useAuth = exports.useAuth = function useAuth() {
|
|
18
|
+
var dispatch = (0, _store.useAppDispatch)();
|
|
19
|
+
var _useAppSelector = (0, _store.useAppSelector)(function (state) {
|
|
20
|
+
return state.auth;
|
|
21
|
+
}),
|
|
22
|
+
isLoggedIn = _useAppSelector.isLoggedIn,
|
|
23
|
+
loggedInUser = _useAppSelector.loggedInUser,
|
|
24
|
+
securityConfig = _useAppSelector.securityConfig,
|
|
25
|
+
isPageLoading = _useAppSelector.isPageLoading,
|
|
26
|
+
error = _useAppSelector.error;
|
|
27
|
+
var handleLogin = /*#__PURE__*/function () {
|
|
28
|
+
var _ref = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee(options) {
|
|
29
|
+
var loginResponse;
|
|
30
|
+
return _regenerator["default"].wrap(function _callee$(_context) {
|
|
31
|
+
while (1) switch (_context.prev = _context.next) {
|
|
32
|
+
case 0:
|
|
33
|
+
_context.prev = 0;
|
|
34
|
+
_context.next = 3;
|
|
35
|
+
return dispatch((0, _authSlice.login)(options)).unwrap();
|
|
36
|
+
case 3:
|
|
37
|
+
loginResponse = _context.sent;
|
|
38
|
+
return _context.abrupt("return", loginResponse);
|
|
39
|
+
case 7:
|
|
40
|
+
_context.prev = 7;
|
|
41
|
+
_context.t0 = _context["catch"](0);
|
|
42
|
+
throw _context.t0;
|
|
43
|
+
case 10:
|
|
44
|
+
case "end":
|
|
45
|
+
return _context.stop();
|
|
46
|
+
}
|
|
47
|
+
}, _callee, null, [[0, 7]]);
|
|
48
|
+
}));
|
|
49
|
+
return function handleLogin(_x) {
|
|
50
|
+
return _ref.apply(this, arguments);
|
|
51
|
+
};
|
|
52
|
+
}();
|
|
53
|
+
var handleLogout = /*#__PURE__*/function () {
|
|
54
|
+
var _ref2 = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee2(baseURL) {
|
|
55
|
+
var logoutResponse;
|
|
56
|
+
return _regenerator["default"].wrap(function _callee2$(_context2) {
|
|
57
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
58
|
+
case 0:
|
|
59
|
+
_context2.prev = 0;
|
|
60
|
+
_context2.next = 3;
|
|
61
|
+
return dispatch((0, _authSlice.logout)({
|
|
62
|
+
baseURL: baseURL
|
|
63
|
+
})).unwrap();
|
|
64
|
+
case 3:
|
|
65
|
+
logoutResponse = _context2.sent;
|
|
66
|
+
return _context2.abrupt("return", logoutResponse);
|
|
67
|
+
case 7:
|
|
68
|
+
_context2.prev = 7;
|
|
69
|
+
_context2.t0 = _context2["catch"](0);
|
|
70
|
+
return _context2.abrupt("return", _context2.t0);
|
|
71
|
+
case 10:
|
|
72
|
+
case "end":
|
|
73
|
+
return _context2.stop();
|
|
74
|
+
}
|
|
75
|
+
}, _callee2, null, [[0, 7]]);
|
|
76
|
+
}));
|
|
77
|
+
return function handleLogout(_x2) {
|
|
78
|
+
return _ref2.apply(this, arguments);
|
|
79
|
+
};
|
|
80
|
+
}();
|
|
81
|
+
var checkCanAccessPage = /*#__PURE__*/function () {
|
|
82
|
+
var _ref3 = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee3(pageName) {
|
|
83
|
+
var baseUrl;
|
|
84
|
+
return _regenerator["default"].wrap(function _callee3$(_context3) {
|
|
85
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
86
|
+
case 0:
|
|
87
|
+
baseUrl = (securityConfig === null || securityConfig === void 0 ? void 0 : securityConfig.baseUrl) || "";
|
|
88
|
+
_context3.next = 3;
|
|
89
|
+
return dispatch((0, _authSlice.canAccessPage)({
|
|
90
|
+
pageName: pageName
|
|
91
|
+
})).unwrap();
|
|
92
|
+
case 3:
|
|
93
|
+
return _context3.abrupt("return", _context3.sent);
|
|
94
|
+
case 4:
|
|
95
|
+
case "end":
|
|
96
|
+
return _context3.stop();
|
|
97
|
+
}
|
|
98
|
+
}, _callee3);
|
|
99
|
+
}));
|
|
100
|
+
return function checkCanAccessPage(_x3) {
|
|
101
|
+
return _ref3.apply(this, arguments);
|
|
102
|
+
};
|
|
103
|
+
}();
|
|
104
|
+
var hasAccessToWidget = function hasAccessToWidget(widgetRoles) {
|
|
105
|
+
var widgetRolesArr = widgetRoles.split(",");
|
|
106
|
+
|
|
107
|
+
// Access the widget when 'Everyone' is chosen
|
|
108
|
+
if ((0, _includes["default"])(widgetRolesArr, _authSlice.USER_ROLE.EVERYONE)) {
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Access the widget when 'Anonymous' is chosen and user is not authenticated
|
|
113
|
+
if ((0, _includes["default"])(widgetRolesArr, _authSlice.USER_ROLE.ANONYMOUS) && !(loggedInUser !== null && loggedInUser !== void 0 && loggedInUser.isAuthenticated)) {
|
|
114
|
+
return true;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Access the widget when 'Only Authenticated Users' is chosen and user is authenticated
|
|
118
|
+
if ((0, _includes["default"])(widgetRolesArr, _authSlice.USER_ROLE.AUTHENTICATED) && loggedInUser !== null && loggedInUser !== void 0 && loggedInUser.isAuthenticated) {
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Access the widget when widget role and logged in user role matches
|
|
123
|
+
return !!(loggedInUser !== null && loggedInUser !== void 0 && loggedInUser.isAuthenticated) && matchRoles(widgetRolesArr, (loggedInUser === null || loggedInUser === void 0 ? void 0 : loggedInUser.roles) || []);
|
|
124
|
+
};
|
|
125
|
+
var matchRoles = function matchRoles(widgetRoles, userRoles) {
|
|
126
|
+
return widgetRoles.some(function (role) {
|
|
127
|
+
return (0, _includes["default"])(userRoles, role);
|
|
128
|
+
});
|
|
129
|
+
};
|
|
130
|
+
var getLoggedInUserDetails = /*#__PURE__*/function () {
|
|
131
|
+
var _ref4 = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee4(baseURL) {
|
|
132
|
+
return _regenerator["default"].wrap(function _callee4$(_context4) {
|
|
133
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
134
|
+
case 0:
|
|
135
|
+
if (baseURL) {
|
|
136
|
+
_context4.next = 2;
|
|
137
|
+
break;
|
|
138
|
+
}
|
|
139
|
+
return _context4.abrupt("return", Promise.resolve({}));
|
|
140
|
+
case 2:
|
|
141
|
+
_context4.next = 4;
|
|
142
|
+
return dispatch((0, _authSlice.loadSecurityInfo)(baseURL)).unwrap();
|
|
143
|
+
case 4:
|
|
144
|
+
return _context4.abrupt("return", _context4.sent);
|
|
145
|
+
case 5:
|
|
146
|
+
case "end":
|
|
147
|
+
return _context4.stop();
|
|
148
|
+
}
|
|
149
|
+
}, _callee4);
|
|
150
|
+
}));
|
|
151
|
+
return function getLoggedInUserDetails(_x4) {
|
|
152
|
+
return _ref4.apply(this, arguments);
|
|
153
|
+
};
|
|
154
|
+
}();
|
|
155
|
+
var authNavigateToLandingPage = /*#__PURE__*/function () {
|
|
156
|
+
var _ref5 = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee5(options) {
|
|
157
|
+
return _regenerator["default"].wrap(function _callee5$(_context5) {
|
|
158
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
159
|
+
case 0:
|
|
160
|
+
_context5.prev = 0;
|
|
161
|
+
_context5.next = 3;
|
|
162
|
+
return dispatch((0, _authSlice.navigateToLandingPage)(options)).unwrap();
|
|
163
|
+
case 3:
|
|
164
|
+
return _context5.abrupt("return", true);
|
|
165
|
+
case 6:
|
|
166
|
+
_context5.prev = 6;
|
|
167
|
+
_context5.t0 = _context5["catch"](0);
|
|
168
|
+
return _context5.abrupt("return", _context5.t0 || false);
|
|
169
|
+
case 9:
|
|
170
|
+
case "end":
|
|
171
|
+
return _context5.stop();
|
|
172
|
+
}
|
|
173
|
+
}, _callee5, null, [[0, 6]]);
|
|
174
|
+
}));
|
|
175
|
+
return function authNavigateToLandingPage(_x5) {
|
|
176
|
+
return _ref5.apply(this, arguments);
|
|
177
|
+
};
|
|
178
|
+
}();
|
|
179
|
+
return {
|
|
180
|
+
isLoggedIn: isLoggedIn,
|
|
181
|
+
loggedInUser: loggedInUser,
|
|
182
|
+
securityConfig: securityConfig,
|
|
183
|
+
isPageLoading: isPageLoading,
|
|
184
|
+
error: error,
|
|
185
|
+
login: handleLogin,
|
|
186
|
+
logout: handleLogout,
|
|
187
|
+
canAccessPage: checkCanAccessPage,
|
|
188
|
+
hasAccessToWidget: hasAccessToWidget,
|
|
189
|
+
getLoggedInUserDetails: getLoggedInUserDetails,
|
|
190
|
+
navigateToLandingPage: authNavigateToLandingPage
|
|
191
|
+
};
|
|
192
|
+
};
|
|
193
|
+
var usePageAccess = exports.usePageAccess = function usePageAccess(pageName) {
|
|
194
|
+
var dispatch = (0, _store.useAppDispatch)();
|
|
195
|
+
var _useAppSelector2 = (0, _store.useAppSelector)(function (state) {
|
|
196
|
+
return state.auth;
|
|
197
|
+
}),
|
|
198
|
+
loggedInUser = _useAppSelector2.loggedInUser;
|
|
199
|
+
var _useState = (0, _react.useState)({
|
|
200
|
+
hasAccess: false,
|
|
201
|
+
loading: true,
|
|
202
|
+
currentPage: pageName
|
|
203
|
+
}),
|
|
204
|
+
state = _useState[0],
|
|
205
|
+
setState = _useState[1];
|
|
206
|
+
var hasAccess = pageName === state.currentPage ? state.hasAccess : false;
|
|
207
|
+
var loading = pageName !== state.currentPage || state.loading;
|
|
208
|
+
(0, _react.useEffect)(function () {
|
|
209
|
+
// Set loading to true and hasAccess to false immediately for new page
|
|
210
|
+
if (pageName !== state.currentPage) {
|
|
211
|
+
setState(function (prev) {
|
|
212
|
+
return _objectSpread(_objectSpread({}, prev), {}, {
|
|
213
|
+
currentPage: pageName,
|
|
214
|
+
hasAccess: false,
|
|
215
|
+
loading: true
|
|
216
|
+
});
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
var checkAccess = /*#__PURE__*/function () {
|
|
220
|
+
var _ref6 = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee6() {
|
|
221
|
+
var access;
|
|
222
|
+
return _regenerator["default"].wrap(function _callee6$(_context6) {
|
|
223
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
224
|
+
case 0:
|
|
225
|
+
_context6.prev = 0;
|
|
226
|
+
_context6.next = 3;
|
|
227
|
+
return dispatch((0, _authSlice.canAccessPage)({
|
|
228
|
+
pageName: pageName
|
|
229
|
+
})).unwrap();
|
|
230
|
+
case 3:
|
|
231
|
+
access = _context6.sent;
|
|
232
|
+
setState(function (prev) {
|
|
233
|
+
if (prev.currentPage !== pageName) return prev;
|
|
234
|
+
return _objectSpread(_objectSpread({}, prev), {}, {
|
|
235
|
+
hasAccess: access,
|
|
236
|
+
loading: false
|
|
237
|
+
});
|
|
238
|
+
});
|
|
239
|
+
_context6.next = 11;
|
|
240
|
+
break;
|
|
241
|
+
case 7:
|
|
242
|
+
_context6.prev = 7;
|
|
243
|
+
_context6.t0 = _context6["catch"](0);
|
|
244
|
+
console.error("Error checking page access:", _context6.t0);
|
|
245
|
+
setState(function (prev) {
|
|
246
|
+
if (prev.currentPage !== pageName) return prev;
|
|
247
|
+
return _objectSpread(_objectSpread({}, prev), {}, {
|
|
248
|
+
hasAccess: false,
|
|
249
|
+
loading: false
|
|
250
|
+
});
|
|
251
|
+
});
|
|
252
|
+
case 11:
|
|
253
|
+
case "end":
|
|
254
|
+
return _context6.stop();
|
|
255
|
+
}
|
|
256
|
+
}, _callee6, null, [[0, 7]]);
|
|
257
|
+
}));
|
|
258
|
+
return function checkAccess() {
|
|
259
|
+
return _ref6.apply(this, arguments);
|
|
260
|
+
};
|
|
261
|
+
}();
|
|
262
|
+
checkAccess();
|
|
263
|
+
}, [pageName, loggedInUser, dispatch]);
|
|
264
|
+
return {
|
|
265
|
+
hasAccess: hasAccess,
|
|
266
|
+
loading: loading
|
|
267
|
+
};
|
|
268
|
+
};
|
|
269
|
+
var useWidgetAccess = exports.useWidgetAccess = function useWidgetAccess(widgetRoles) {
|
|
270
|
+
var _useAuth = useAuth(),
|
|
271
|
+
hasAccessToWidget = _useAuth.hasAccessToWidget;
|
|
272
|
+
return hasAccessToWidget(widgetRoles);
|
|
273
|
+
};
|
|
274
|
+
var useAccess = exports.useAccess = function useAccess(name, type) {
|
|
275
|
+
var dispatch = (0, _store.useAppDispatch)();
|
|
276
|
+
var _useAppSelector3 = (0, _store.useAppSelector)(function (state) {
|
|
277
|
+
return state.auth;
|
|
278
|
+
}),
|
|
279
|
+
loggedInUser = _useAppSelector3.loggedInUser,
|
|
280
|
+
securityConfig = _useAppSelector3.securityConfig;
|
|
281
|
+
var _useState2 = (0, _react.useState)({
|
|
282
|
+
hasAccess: false,
|
|
283
|
+
loading: true,
|
|
284
|
+
currentItem: "".concat(type, "-").concat(name)
|
|
285
|
+
}),
|
|
286
|
+
state = _useState2[0],
|
|
287
|
+
setState = _useState2[1];
|
|
288
|
+
var hasAccess = "".concat(type, "-").concat(name) === state.currentItem ? state.hasAccess : false;
|
|
289
|
+
var loading = "".concat(type, "-").concat(name) !== state.currentItem || state.loading;
|
|
290
|
+
(0, _react.useEffect)(function () {
|
|
291
|
+
// If name is empty, skip access check and mark as not loading
|
|
292
|
+
if (!name) {
|
|
293
|
+
setState(function (prev) {
|
|
294
|
+
return _objectSpread(_objectSpread({}, prev), {}, {
|
|
295
|
+
currentItem: "".concat(type, "-").concat(name),
|
|
296
|
+
hasAccess: true,
|
|
297
|
+
// Allow access when no name specified
|
|
298
|
+
loading: false
|
|
299
|
+
});
|
|
300
|
+
});
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
// Set loading to true and hasAccess to false immediately for new item
|
|
305
|
+
var currentItemKey = "".concat(type, "-").concat(name);
|
|
306
|
+
if (currentItemKey !== state.currentItem) {
|
|
307
|
+
setState(function (prev) {
|
|
308
|
+
return _objectSpread(_objectSpread({}, prev), {}, {
|
|
309
|
+
currentItem: currentItemKey,
|
|
310
|
+
hasAccess: false,
|
|
311
|
+
loading: true
|
|
312
|
+
});
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
var checkItemAccess = /*#__PURE__*/function () {
|
|
316
|
+
var _ref7 = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee7() {
|
|
317
|
+
var access;
|
|
318
|
+
return _regenerator["default"].wrap(function _callee7$(_context7) {
|
|
319
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
320
|
+
case 0:
|
|
321
|
+
_context7.prev = 0;
|
|
322
|
+
_context7.next = 3;
|
|
323
|
+
return dispatch((0, _authSlice.checkAccess)({
|
|
324
|
+
name: name,
|
|
325
|
+
type: type
|
|
326
|
+
})).unwrap();
|
|
327
|
+
case 3:
|
|
328
|
+
access = _context7.sent;
|
|
329
|
+
setState(function (prev) {
|
|
330
|
+
if (prev.currentItem !== currentItemKey) return prev;
|
|
331
|
+
return _objectSpread(_objectSpread({}, prev), {}, {
|
|
332
|
+
hasAccess: access,
|
|
333
|
+
loading: false
|
|
334
|
+
});
|
|
335
|
+
});
|
|
336
|
+
_context7.next = 11;
|
|
337
|
+
break;
|
|
338
|
+
case 7:
|
|
339
|
+
_context7.prev = 7;
|
|
340
|
+
_context7.t0 = _context7["catch"](0);
|
|
341
|
+
console.error("Error checking ".concat(type.toLowerCase(), " access:"), _context7.t0);
|
|
342
|
+
setState(function (prev) {
|
|
343
|
+
if (prev.currentItem !== currentItemKey) return prev;
|
|
344
|
+
return _objectSpread(_objectSpread({}, prev), {}, {
|
|
345
|
+
hasAccess: false,
|
|
346
|
+
loading: false
|
|
347
|
+
});
|
|
348
|
+
});
|
|
349
|
+
case 11:
|
|
350
|
+
case "end":
|
|
351
|
+
return _context7.stop();
|
|
352
|
+
}
|
|
353
|
+
}, _callee7, null, [[0, 7]]);
|
|
354
|
+
}));
|
|
355
|
+
return function checkItemAccess() {
|
|
356
|
+
return _ref7.apply(this, arguments);
|
|
357
|
+
};
|
|
358
|
+
}();
|
|
359
|
+
checkItemAccess();
|
|
360
|
+
}, [name, type, loggedInUser, securityConfig, dispatch]);
|
|
361
|
+
return {
|
|
362
|
+
hasAccess: hasAccess,
|
|
363
|
+
loading: loading
|
|
364
|
+
};
|
|
365
|
+
};
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* Synchronous access checker for use outside of React components
|
|
369
|
+
* @param name - Name of the page or partial
|
|
370
|
+
* @param type - Type: 'PAGE' or 'PARTIAL'
|
|
371
|
+
* @param authState - Current auth state from Redux store
|
|
372
|
+
* @param appConfig - App configuration containing pages and partials
|
|
373
|
+
* @returns boolean indicating if access is granted
|
|
374
|
+
*/
|
|
375
|
+
var checkAccessSync = exports.checkAccessSync = function checkAccessSync(name, type, authState, appConfig) {
|
|
376
|
+
var _authState$loggedInUs, _authState$loggedInUs2, _authState$securityCo;
|
|
377
|
+
var userRoles = (authState === null || authState === void 0 || (_authState$loggedInUs = authState.loggedInUser) === null || _authState$loggedInUs === void 0 ? void 0 : _authState$loggedInUs.roles) || [];
|
|
378
|
+
var isAuthenticated = (authState === null || authState === void 0 || (_authState$loggedInUs2 = authState.loggedInUser) === null || _authState$loggedInUs2 === void 0 ? void 0 : _authState$loggedInUs2.isAuthenticated) || false;
|
|
379
|
+
var isSecurityEnabled = authState === null || authState === void 0 || (_authState$securityCo = authState.securityConfig) === null || _authState$securityCo === void 0 ? void 0 : _authState$securityCo.isSecurityEnabled;
|
|
380
|
+
|
|
381
|
+
// If security is not enabled, allow access to everything
|
|
382
|
+
if (!isSecurityEnabled) {
|
|
383
|
+
return true;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
// Get the appropriate config based on type
|
|
387
|
+
var configs = type === "PAGE" ? (appConfig === null || appConfig === void 0 ? void 0 : appConfig.pages) || [] : (appConfig === null || appConfig === void 0 ? void 0 : appConfig.partials) || [];
|
|
388
|
+
|
|
389
|
+
// Extract only serializable properties for access control (avoid components)
|
|
390
|
+
var serializableConfigs = configs.map(function (item) {
|
|
391
|
+
return {
|
|
392
|
+
name: item.name,
|
|
393
|
+
permission: item.permission,
|
|
394
|
+
allowedRoles: item.allowedRoles,
|
|
395
|
+
type: item.type
|
|
396
|
+
};
|
|
397
|
+
});
|
|
398
|
+
var config = serializableConfigs.find(function (item) {
|
|
399
|
+
return item.name.toLowerCase() === name.toLowerCase();
|
|
400
|
+
});
|
|
401
|
+
|
|
402
|
+
// If no config found, deny access for security
|
|
403
|
+
if (!config) {
|
|
404
|
+
return false;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
// Check permission type
|
|
408
|
+
switch (config.permission) {
|
|
409
|
+
case "PermitAll":
|
|
410
|
+
return true;
|
|
411
|
+
case "Authenticated":
|
|
412
|
+
return isAuthenticated;
|
|
413
|
+
case "Role":
|
|
414
|
+
if (!isAuthenticated) {
|
|
415
|
+
return false;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
// Check if user has any of the required roles
|
|
419
|
+
var allowedRoles = config.allowedRoles || [];
|
|
420
|
+
if (allowedRoles.length === 0) {
|
|
421
|
+
// If no roles specified but permission is Role, deny access
|
|
422
|
+
return false;
|
|
423
|
+
}
|
|
424
|
+
return allowedRoles.some(function (role) {
|
|
425
|
+
return userRoles.includes(role);
|
|
426
|
+
});
|
|
427
|
+
default:
|
|
428
|
+
// Unknown permission type, deny access for security
|
|
429
|
+
return false;
|
|
430
|
+
}
|
|
431
|
+
};
|
|
432
|
+
var useLogin = exports.useLogin = function useLogin() {
|
|
433
|
+
var dispatch = (0, _store.useAppDispatch)();
|
|
434
|
+
var _useAppSelector4 = (0, _store.useAppSelector)(function (state) {
|
|
435
|
+
return state.auth;
|
|
436
|
+
}),
|
|
437
|
+
isLoggedIn = _useAppSelector4.isLoggedIn,
|
|
438
|
+
error = _useAppSelector4.error;
|
|
439
|
+
var _useState3 = (0, _react.useState)(false),
|
|
440
|
+
loading = _useState3[0],
|
|
441
|
+
setLoading = _useState3[1];
|
|
442
|
+
var _useState4 = (0, _react.useState)(null),
|
|
443
|
+
loginError = _useState4[0],
|
|
444
|
+
setLoginError = _useState4[1];
|
|
445
|
+
var handleLogin = /*#__PURE__*/function () {
|
|
446
|
+
var _ref8 = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee8(options) {
|
|
447
|
+
return _regenerator["default"].wrap(function _callee8$(_context8) {
|
|
448
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
449
|
+
case 0:
|
|
450
|
+
setLoading(true);
|
|
451
|
+
setLoginError(null);
|
|
452
|
+
_context8.prev = 2;
|
|
453
|
+
_context8.next = 5;
|
|
454
|
+
return dispatch((0, _authSlice.login)(options)).unwrap();
|
|
455
|
+
case 5:
|
|
456
|
+
return _context8.abrupt("return", true);
|
|
457
|
+
case 8:
|
|
458
|
+
_context8.prev = 8;
|
|
459
|
+
_context8.t0 = _context8["catch"](2);
|
|
460
|
+
setLoginError(_context8.t0 instanceof Error ? _context8.t0.message : "Login failed");
|
|
461
|
+
return _context8.abrupt("return", false);
|
|
462
|
+
case 12:
|
|
463
|
+
_context8.prev = 12;
|
|
464
|
+
setLoading(false);
|
|
465
|
+
return _context8.finish(12);
|
|
466
|
+
case 15:
|
|
467
|
+
case "end":
|
|
468
|
+
return _context8.stop();
|
|
469
|
+
}
|
|
470
|
+
}, _callee8, null, [[2, 8, 12, 15]]);
|
|
471
|
+
}));
|
|
472
|
+
return function handleLogin(_x6) {
|
|
473
|
+
return _ref8.apply(this, arguments);
|
|
474
|
+
};
|
|
475
|
+
}();
|
|
476
|
+
return {
|
|
477
|
+
loading: loading,
|
|
478
|
+
error: loginError || error,
|
|
479
|
+
isLoggedIn: isLoggedIn,
|
|
480
|
+
handleLogin: handleLogin,
|
|
481
|
+
clearError: function clearError() {
|
|
482
|
+
return setLoginError(null);
|
|
483
|
+
}
|
|
484
|
+
};
|
|
485
|
+
};
|
|
486
|
+
var useLogout = exports.useLogout = function useLogout() {
|
|
487
|
+
var dispatch = (0, _store.useAppDispatch)();
|
|
488
|
+
var _useState5 = (0, _react.useState)(false),
|
|
489
|
+
loading = _useState5[0],
|
|
490
|
+
setLoading = _useState5[1];
|
|
491
|
+
var _useState6 = (0, _react.useState)(null),
|
|
492
|
+
logoutError = _useState6[0],
|
|
493
|
+
setLogoutError = _useState6[1];
|
|
494
|
+
var handleLogout = /*#__PURE__*/function () {
|
|
495
|
+
var _ref9 = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee9(baseURL) {
|
|
496
|
+
return _regenerator["default"].wrap(function _callee9$(_context9) {
|
|
497
|
+
while (1) switch (_context9.prev = _context9.next) {
|
|
498
|
+
case 0:
|
|
499
|
+
setLoading(true);
|
|
500
|
+
setLogoutError(null);
|
|
501
|
+
_context9.prev = 2;
|
|
502
|
+
_context9.next = 5;
|
|
503
|
+
return dispatch((0, _authSlice.logout)({
|
|
504
|
+
baseURL: baseURL
|
|
505
|
+
})).unwrap();
|
|
506
|
+
case 5:
|
|
507
|
+
return _context9.abrupt("return", true);
|
|
508
|
+
case 8:
|
|
509
|
+
_context9.prev = 8;
|
|
510
|
+
_context9.t0 = _context9["catch"](2);
|
|
511
|
+
setLogoutError(_context9.t0 instanceof Error ? _context9.t0.message : "Logout failed");
|
|
512
|
+
return _context9.abrupt("return", false);
|
|
513
|
+
case 12:
|
|
514
|
+
_context9.prev = 12;
|
|
515
|
+
setLoading(false);
|
|
516
|
+
return _context9.finish(12);
|
|
517
|
+
case 15:
|
|
518
|
+
case "end":
|
|
519
|
+
return _context9.stop();
|
|
520
|
+
}
|
|
521
|
+
}, _callee9, null, [[2, 8, 12, 15]]);
|
|
522
|
+
}));
|
|
523
|
+
return function handleLogout(_x7) {
|
|
524
|
+
return _ref9.apply(this, arguments);
|
|
525
|
+
};
|
|
526
|
+
}();
|
|
527
|
+
return {
|
|
528
|
+
loading: loading,
|
|
529
|
+
error: logoutError,
|
|
530
|
+
handleLogout: handleLogout,
|
|
531
|
+
clearError: function clearError() {
|
|
532
|
+
return setLogoutError(null);
|
|
533
|
+
}
|
|
534
|
+
};
|
|
535
|
+
};
|
|
536
|
+
var useCurrentUser = exports.useCurrentUser = function useCurrentUser() {
|
|
537
|
+
var _useAppSelector5 = (0, _store.useAppSelector)(function (state) {
|
|
538
|
+
return state.auth;
|
|
539
|
+
}),
|
|
540
|
+
loggedInUser = _useAppSelector5.loggedInUser,
|
|
541
|
+
isLoggedIn = _useAppSelector5.isLoggedIn;
|
|
542
|
+
return {
|
|
543
|
+
user: loggedInUser,
|
|
544
|
+
isLoggedIn: isLoggedIn,
|
|
545
|
+
hasRole: function hasRole(role) {
|
|
546
|
+
if (!loggedInUser || !loggedInUser.roles) return false;
|
|
547
|
+
return loggedInUser.roles.includes(role);
|
|
548
|
+
},
|
|
549
|
+
hasAnyRole: function hasAnyRole(roles) {
|
|
550
|
+
if (!loggedInUser || !loggedInUser.roles) return false;
|
|
551
|
+
return roles.some(function (role) {
|
|
552
|
+
return loggedInUser.roles.includes(role);
|
|
553
|
+
});
|
|
554
|
+
},
|
|
555
|
+
hasAllRoles: function hasAllRoles(roles) {
|
|
556
|
+
if (!loggedInUser || !loggedInUser.roles) return false;
|
|
557
|
+
return roles.every(function (role) {
|
|
558
|
+
return loggedInUser.roles.includes(role);
|
|
559
|
+
});
|
|
560
|
+
}
|
|
561
|
+
};
|
|
562
|
+
};
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.useDataSourceSubscription = void 0;
|
|
8
|
+
var _react = require("react");
|
|
9
|
+
var _listHelpers = require("../components/data/list/utils/list-helpers");
|
|
10
|
+
var _tableHelpers = require("../components/data/table/utils/table-helpers");
|
|
11
|
+
var _types = require("../components/data/types");
|
|
12
|
+
var _eventNotifier = _interopRequireDefault(require("@wavemaker/react-runtime/core/event-notifier"));
|
|
13
|
+
var _variables = require("@wavemaker/variables");
|
|
14
|
+
// @ts-ignore - Using yalc linked local package
|
|
15
|
+
|
|
16
|
+
// Create a singleton EventNotifier instance that all components will share
|
|
17
|
+
var sharedEventNotifier = null;
|
|
18
|
+
var getSharedEventNotifier = function getSharedEventNotifier() {
|
|
19
|
+
if (!sharedEventNotifier) {
|
|
20
|
+
// Create new EventNotifier only once
|
|
21
|
+
sharedEventNotifier = new _eventNotifier["default"]();
|
|
22
|
+
sharedEventNotifier.notify = sharedEventNotifier.notifyApp.bind(sharedEventNotifier);
|
|
23
|
+
// Set it in the external dependency store (from @wavemaker/variables)
|
|
24
|
+
(0, _variables.wmSetDependency)("appManager", sharedEventNotifier);
|
|
25
|
+
}
|
|
26
|
+
return sharedEventNotifier;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* This function accepts two data sources and will check if both are same by comparing the unique id and
|
|
31
|
+
* context in which datasources are present
|
|
32
|
+
* @returns {*} boolean true/ false
|
|
33
|
+
*/
|
|
34
|
+
var isDataSourceEqual = function isDataSourceEqual(d1, d2) {
|
|
35
|
+
return d1.execute(_types.DataSource.Operation.GET_UNIQUE_IDENTIFIER) === d2.execute(_types.DataSource.Operation.GET_UNIQUE_IDENTIFIER);
|
|
36
|
+
// && isEqual(d1.execute(DataSource.Operation.GET_CONTEXT_IDENTIFIER), d2.execute(DataSource.Operation.GET_CONTEXT_IDENTIFIER));
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Hook to subscribe to 'toggle-variable-state' event
|
|
41
|
+
* Handles state params for pagination when events are fired
|
|
42
|
+
* Subscription happens only once when datasource and EventNotifier are available
|
|
43
|
+
*/
|
|
44
|
+
var useDataSourceSubscription = exports.useDataSourceSubscription = function useDataSourceSubscription(_ref) {
|
|
45
|
+
var datasource = _ref.datasource,
|
|
46
|
+
statehandler = _ref.statehandler,
|
|
47
|
+
name = _ref.name,
|
|
48
|
+
onPageRestored = _ref.onPageRestored,
|
|
49
|
+
_ref$widgetType = _ref.widgetType,
|
|
50
|
+
widgetType = _ref$widgetType === void 0 ? "list" : _ref$widgetType;
|
|
51
|
+
var pageLoadRef = (0, _react.useRef)(true); // Track if this is the first page load
|
|
52
|
+
var unsubscribeRef = (0, _react.useRef)(null);
|
|
53
|
+
|
|
54
|
+
// Get the shared EventNotifier instance
|
|
55
|
+
var eventNotifier = getSharedEventNotifier();
|
|
56
|
+
|
|
57
|
+
// Subscribe only once when datasource and EventNotifier become available
|
|
58
|
+
(0, _react.useMemo)(function () {
|
|
59
|
+
// Skip if prerequisites not met
|
|
60
|
+
if (!datasource || !eventNotifier) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Clean up previous subscription if exists
|
|
65
|
+
if (unsubscribeRef.current) {
|
|
66
|
+
unsubscribeRef.current();
|
|
67
|
+
unsubscribeRef.current = null;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Handler for toggle-variable-state event
|
|
71
|
+
function handleLoading(data) {
|
|
72
|
+
if (!(data !== null && data !== void 0 && data.variable) && !data.active) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
if (datasource && datasource.execute && datasource.execute(_types.DataSource.Operation.IS_API_AWARE) && isDataSourceEqual(data.variable, datasource)) {
|
|
76
|
+
// Handle state params only on page load (first time)
|
|
77
|
+
if (pageLoadRef.current && statehandler.toLowerCase() !== "none") {
|
|
78
|
+
pageLoadRef.current = false; // Mark as handled
|
|
79
|
+
|
|
80
|
+
// Use appropriate state getter based on widget type
|
|
81
|
+
var widgetState = widgetType === "table" ? (0, _tableHelpers.getTableState)(name, statehandler) : (0, _listHelpers.getListState)(name, statehandler);
|
|
82
|
+
if (widgetState) {
|
|
83
|
+
// Ensure options object exists
|
|
84
|
+
data.options = data.options || {};
|
|
85
|
+
|
|
86
|
+
// Set page number for server-side pagination
|
|
87
|
+
data.options.page = widgetState.pagination;
|
|
88
|
+
|
|
89
|
+
// Set page size
|
|
90
|
+
if (widgetState.pagesize) {
|
|
91
|
+
datasource.maxResults = widgetState.pagesize;
|
|
92
|
+
data.options.pagesize = widgetState.pagesize;
|
|
93
|
+
}
|
|
94
|
+
if (widgetType === "table") {
|
|
95
|
+
var tableState = widgetState;
|
|
96
|
+
if (tableState.search && tableState.search.length > 0) {
|
|
97
|
+
data.options.filterFields = (0, _tableHelpers.convertFilterArrayToObject)(tableState.search);
|
|
98
|
+
}
|
|
99
|
+
if (tableState.sort && tableState.sort.field.length > 0) {
|
|
100
|
+
data.options.orderBy = "".concat(tableState.sort.field, " ").concat(tableState.sort.direction);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Notify parent component about the restored page
|
|
105
|
+
if (onPageRestored) {
|
|
106
|
+
onPageRestored(widgetState.pagination);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Subscribe to toggle-variable-state event
|
|
114
|
+
var unsubscribe = eventNotifier.subscribe("toggle-variable-state", handleLoading);
|
|
115
|
+
unsubscribeRef.current = unsubscribe;
|
|
116
|
+
|
|
117
|
+
// Return cleanup function
|
|
118
|
+
return function () {
|
|
119
|
+
if (unsubscribeRef.current) {
|
|
120
|
+
unsubscribeRef.current();
|
|
121
|
+
unsubscribeRef.current = null;
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
}, [datasource, statehandler, name, onPageRestored, widgetType, eventNotifier]);
|
|
125
|
+
};
|