@unipin/angular-applet 18.9.7 → 21.0.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/README.md +49 -10
- package/common/assets/sprites/flagGlobal.png +0 -0
- package/common/assets/sprites/flagSprite42.webp +0 -0
- package/common/assets/styles/freakflags.scss +263 -0
- package/common/assets/styles/theme.css +69 -0
- package/fesm2022/unipin-angular-applet-accordion.mjs +242 -0
- package/fesm2022/unipin-angular-applet-accordion.mjs.map +1 -0
- package/fesm2022/unipin-angular-applet-alert-dialog.mjs +267 -0
- package/fesm2022/unipin-angular-applet-alert-dialog.mjs.map +1 -0
- package/fesm2022/unipin-angular-applet-alert.mjs +94 -0
- package/fesm2022/unipin-angular-applet-alert.mjs.map +1 -0
- package/fesm2022/unipin-angular-applet-auth.mjs +707 -0
- package/fesm2022/unipin-angular-applet-auth.mjs.map +1 -0
- package/fesm2022/unipin-angular-applet-avatar.mjs +41 -0
- package/fesm2022/unipin-angular-applet-avatar.mjs.map +1 -0
- package/fesm2022/unipin-angular-applet-badge.mjs +50 -0
- package/fesm2022/unipin-angular-applet-badge.mjs.map +1 -0
- package/fesm2022/unipin-angular-applet-buttons.mjs +263 -0
- package/fesm2022/unipin-angular-applet-buttons.mjs.map +1 -0
- package/fesm2022/unipin-angular-applet-calendar.mjs +492 -0
- package/fesm2022/unipin-angular-applet-calendar.mjs.map +1 -0
- package/fesm2022/unipin-angular-applet-collapsible.mjs +97 -0
- package/fesm2022/unipin-angular-applet-collapsible.mjs.map +1 -0
- package/fesm2022/unipin-angular-applet-common.mjs +342 -0
- package/fesm2022/unipin-angular-applet-common.mjs.map +1 -0
- package/fesm2022/unipin-angular-applet-containers.mjs +472 -0
- package/fesm2022/unipin-angular-applet-containers.mjs.map +1 -0
- package/fesm2022/unipin-angular-applet-dialog.mjs +535 -0
- package/fesm2022/unipin-angular-applet-dialog.mjs.map +1 -0
- package/fesm2022/unipin-angular-applet-forms.mjs +1699 -0
- package/fesm2022/unipin-angular-applet-forms.mjs.map +1 -0
- package/fesm2022/unipin-angular-applet-froala.mjs +298 -0
- package/fesm2022/unipin-angular-applet-froala.mjs.map +1 -0
- package/fesm2022/unipin-angular-applet-grids.mjs +105 -0
- package/fesm2022/unipin-angular-applet-grids.mjs.map +1 -0
- package/fesm2022/unipin-angular-applet-infinite-scroll.mjs +86 -0
- package/fesm2022/unipin-angular-applet-infinite-scroll.mjs.map +1 -0
- package/fesm2022/unipin-angular-applet-json-viewer.mjs +71 -0
- package/fesm2022/unipin-angular-applet-json-viewer.mjs.map +1 -0
- package/fesm2022/unipin-angular-applet-loading-dialog.mjs +252 -0
- package/fesm2022/unipin-angular-applet-loading-dialog.mjs.map +1 -0
- package/fesm2022/unipin-angular-applet-markdown.mjs +703 -0
- package/fesm2022/unipin-angular-applet-markdown.mjs.map +1 -0
- package/fesm2022/unipin-angular-applet-micro-frontend.mjs +75 -0
- package/fesm2022/unipin-angular-applet-micro-frontend.mjs.map +1 -0
- package/fesm2022/unipin-angular-applet-popover.mjs +333 -0
- package/fesm2022/unipin-angular-applet-popover.mjs.map +1 -0
- package/fesm2022/unipin-angular-applet-progress-bar.mjs +38 -0
- package/fesm2022/unipin-angular-applet-progress-bar.mjs.map +1 -0
- package/fesm2022/unipin-angular-applet-skeleton.mjs +32 -0
- package/fesm2022/unipin-angular-applet-skeleton.mjs.map +1 -0
- package/fesm2022/unipin-angular-applet-spinner.mjs +144 -0
- package/fesm2022/unipin-angular-applet-spinner.mjs.map +1 -0
- package/fesm2022/unipin-angular-applet-swipeable.mjs +270 -0
- package/fesm2022/unipin-angular-applet-swipeable.mjs.map +1 -0
- package/fesm2022/unipin-angular-applet-tabs.mjs +142 -0
- package/fesm2022/unipin-angular-applet-tabs.mjs.map +1 -0
- package/fesm2022/unipin-angular-applet-tooltip.mjs +118 -0
- package/fesm2022/unipin-angular-applet-tooltip.mjs.map +1 -0
- package/fesm2022/unipin-angular-applet.mjs +5 -4617
- package/fesm2022/unipin-angular-applet.mjs.map +1 -1
- package/package.json +132 -29
- package/types/unipin-angular-applet-accordion.d.ts +60 -0
- package/types/unipin-angular-applet-alert-dialog.d.ts +35 -0
- package/types/unipin-angular-applet-alert.d.ts +34 -0
- package/types/unipin-angular-applet-auth.d.ts +225 -0
- package/types/unipin-angular-applet-avatar.d.ts +16 -0
- package/types/unipin-angular-applet-badge.d.ts +20 -0
- package/types/unipin-angular-applet-buttons.d.ts +37 -0
- package/types/unipin-angular-applet-calendar.d.ts +44 -0
- package/types/unipin-angular-applet-collapsible.d.ts +35 -0
- package/types/unipin-angular-applet-common.d.ts +94 -0
- package/types/unipin-angular-applet-containers.d.ts +179 -0
- package/types/unipin-angular-applet-dialog.d.ts +180 -0
- package/types/unipin-angular-applet-forms.d.ts +412 -0
- package/types/unipin-angular-applet-froala.d.ts +85 -0
- package/types/unipin-angular-applet-grids.d.ts +22 -0
- package/types/unipin-angular-applet-infinite-scroll.d.ts +51 -0
- package/types/unipin-angular-applet-json-viewer.d.ts +30 -0
- package/types/unipin-angular-applet-loading-dialog.d.ts +19 -0
- package/types/unipin-angular-applet-markdown.d.ts +119 -0
- package/types/unipin-angular-applet-micro-frontend.d.ts +11 -0
- package/types/unipin-angular-applet-popover.d.ts +58 -0
- package/types/unipin-angular-applet-progress-bar.d.ts +14 -0
- package/types/unipin-angular-applet-skeleton.d.ts +11 -0
- package/types/unipin-angular-applet-spinner.d.ts +12 -0
- package/types/unipin-angular-applet-swipeable.d.ts +66 -0
- package/types/unipin-angular-applet-tabs.d.ts +40 -0
- package/types/unipin-angular-applet-tooltip.d.ts +32 -0
- package/types/unipin-angular-applet.d.ts +3 -0
- package/esm2022/graphql/generated.mjs +0 -938
- package/esm2022/lib/components/approval/detail/approval-detail.component.mjs +0 -78
- package/esm2022/lib/components/approval/form/approval-form.component.mjs +0 -128
- package/esm2022/lib/components/approval/index.mjs +0 -5
- package/esm2022/lib/components/approval/list/approval-list.component.mjs +0 -114
- package/esm2022/lib/components/approval/list/provide-approval-entities.util.mjs +0 -9
- package/esm2022/lib/components/approval/services/approval.service.mjs +0 -46
- package/esm2022/lib/components/audit/detail/audit-detail.component.mjs +0 -123
- package/esm2022/lib/components/audit/index.mjs +0 -3
- package/esm2022/lib/components/audit/list/audit-list.component.mjs +0 -81
- package/esm2022/lib/components/audit/service/audit.service.mjs +0 -49
- package/esm2022/lib/components/audit/types/audit-detail-form.type.mjs +0 -2
- package/esm2022/lib/components/buttons/group/btn-group.component.mjs +0 -43
- package/esm2022/lib/components/buttons/group/interfaces/btn-group-config.interface.mjs +0 -2
- package/esm2022/lib/components/buttons/index.mjs +0 -3
- package/esm2022/lib/components/buttons/loading/btn-loading.component.mjs +0 -48
- package/esm2022/lib/components/containers/applet-container/applet-container.component.mjs +0 -55
- package/esm2022/lib/components/containers/applet-container/provide-applet-config.util.mjs +0 -9
- package/esm2022/lib/components/containers/colum-header-container/column-header-container.component.mjs +0 -23
- package/esm2022/lib/components/containers/column-container/column-container.component.mjs +0 -79
- package/esm2022/lib/components/containers/column-container/directives/lazy-route.directive.mjs +0 -57
- package/esm2022/lib/components/containers/index.mjs +0 -7
- package/esm2022/lib/components/containers/list-container/index.mjs +0 -3
- package/esm2022/lib/components/containers/list-container/interfaces/list-container-config.interface.mjs +0 -2
- package/esm2022/lib/components/containers/list-container/list-pagination-container/list-pagination-container.component.mjs +0 -58
- package/esm2022/lib/components/containers/list-container/list-snapshot-container/list-snapshot-container.component.mjs +0 -57
- package/esm2022/lib/components/containers/modal-container/modal-container.component.mjs +0 -40
- package/esm2022/lib/components/filter/filter.component.mjs +0 -222
- package/esm2022/lib/components/filter/index.mjs +0 -2
- package/esm2022/lib/components/filter/interfaces/filter-config.interface.mjs +0 -2
- package/esm2022/lib/components/filter/interfaces/filter-field.interface.mjs +0 -2
- package/esm2022/lib/components/filter/interfaces/filter-search-event.interface.mjs +0 -2
- package/esm2022/lib/components/forms/country-input/form-country-input.component.mjs +0 -122
- package/esm2022/lib/components/forms/currency-input/form-currency-input.component.mjs +0 -157
- package/esm2022/lib/components/forms/date/form-date.component.mjs +0 -117
- package/esm2022/lib/components/forms/image-picker/directives/drag-n-drop.directive.mjs +0 -49
- package/esm2022/lib/components/forms/image-picker/form-image-picker.component.mjs +0 -68
- package/esm2022/lib/components/forms/index.mjs +0 -12
- package/esm2022/lib/components/forms/input/form-input.component.mjs +0 -98
- package/esm2022/lib/components/forms/number/form-number.component.mjs +0 -97
- package/esm2022/lib/components/forms/number/pipes/locale-number.pipe.mjs +0 -33
- package/esm2022/lib/components/forms/password/form-password.component.mjs +0 -100
- package/esm2022/lib/components/forms/rate-group-code-input/form-rate-group-code-input.component.mjs +0 -135
- package/esm2022/lib/components/forms/searchable-select/form-searchable-select.component.mjs +0 -138
- package/esm2022/lib/components/forms/select/form-select.component.mjs +0 -119
- package/esm2022/lib/components/forms/textarea/form-textarea.component.mjs +0 -88
- package/esm2022/lib/components/grids/grid-pagination/grid-pagination.component.mjs +0 -111
- package/esm2022/lib/components/grids/grid-snapshot/grid-snapshot.component.mjs +0 -109
- package/esm2022/lib/components/grids/index.mjs +0 -4
- package/esm2022/lib/components/grids/interfaces/grid-config.interface.mjs +0 -2
- package/esm2022/lib/components/grids/services/grid.service.mjs +0 -25
- package/esm2022/lib/components/index.mjs +0 -9
- package/esm2022/lib/components/infinite-scroll/directive/infinite-scroll.directive.mjs +0 -43
- package/esm2022/lib/components/infinite-scroll/index.mjs +0 -3
- package/esm2022/lib/components/infinite-scroll/infinite-scroll.component.mjs +0 -36
- package/esm2022/lib/components/tabs/index.mjs +0 -3
- package/esm2022/lib/components/tabs/tab-content/tab-content.component.mjs +0 -37
- package/esm2022/lib/components/tabs/tab-group/tab-group.component.mjs +0 -47
- package/esm2022/lib/guards/auth/auth.guard.mjs +0 -10
- package/esm2022/lib/guards/index.mjs +0 -2
- package/esm2022/lib/interceptors/header/header.interceptor.mjs +0 -29
- package/esm2022/lib/interceptors/index.mjs +0 -3
- package/esm2022/lib/interceptors/refresh-token/refresh-token.interceptor.mjs +0 -83
- package/esm2022/lib/interfaces/index.mjs +0 -2
- package/esm2022/lib/interfaces/user/user.interface.mjs +0 -2
- package/esm2022/lib/modules/index.mjs +0 -3
- package/esm2022/lib/modules/micro-frontend/index.mjs +0 -2
- package/esm2022/lib/modules/micro-frontend/utils/mf-bootstrap.util.mjs +0 -55
- package/esm2022/lib/modules/micro-frontend/utils/mf-global-state.util.mjs +0 -14
- package/esm2022/lib/modules/permission/directive/permission.directive.mjs +0 -41
- package/esm2022/lib/modules/permission/guards/permission.guard.mjs +0 -26
- package/esm2022/lib/modules/permission/index.mjs +0 -7
- package/esm2022/lib/modules/permission/pages/401/unauthorized.page.mjs +0 -15
- package/esm2022/lib/modules/permission/pages/loading/loading.page.mjs +0 -65
- package/esm2022/lib/modules/permission/pages/loading/provide-loading-config.util.mjs +0 -9
- package/esm2022/lib/modules/permission/services/permission.service.mjs +0 -50
- package/esm2022/lib/resolvers/auth/auth.resolver.mjs +0 -87
- package/esm2022/lib/resolvers/index.mjs +0 -2
- package/esm2022/lib/services/auth/auth.service.mjs +0 -171
- package/esm2022/lib/services/country/country.service.mjs +0 -43
- package/esm2022/lib/services/currency/currency.service.mjs +0 -40
- package/esm2022/lib/services/index.mjs +0 -6
- package/esm2022/lib/services/profile/profile.service.mjs +0 -82
- package/esm2022/lib/services/rate-group-code/rate-group-code.service.mjs +0 -31
- package/esm2022/lib/utils/contrast-color-generator/contrast-color-generator.util.mjs +0 -16
- package/esm2022/lib/utils/form-error-message/form-error-message.util.mjs +0 -21
- package/esm2022/lib/utils/format-capitalize/format-capitalize.util.mjs +0 -18
- package/esm2022/lib/utils/index.mjs +0 -5
- package/esm2022/lib/utils/redirect-to-first-menu/redirect-to-first-menu.util.mjs +0 -9
- package/esm2022/public-api.mjs +0 -10
- package/esm2022/unipin-angular-applet.mjs +0 -2
- package/graphql/generated.d.ts +0 -16225
- package/index.d.ts +0 -2
- package/lib/components/approval/detail/approval-detail.component.d.ts +0 -26
- package/lib/components/approval/form/approval-form.component.d.ts +0 -33
- package/lib/components/approval/index.d.ts +0 -4
- package/lib/components/approval/list/approval-list.component.d.ts +0 -33
- package/lib/components/approval/list/provide-approval-entities.util.d.ts +0 -3
- package/lib/components/approval/services/approval.service.d.ts +0 -18
- package/lib/components/audit/detail/audit-detail.component.d.ts +0 -33
- package/lib/components/audit/index.d.ts +0 -2
- package/lib/components/audit/list/audit-list.component.d.ts +0 -31
- package/lib/components/audit/service/audit.service.d.ts +0 -15
- package/lib/components/audit/types/audit-detail-form.type.d.ts +0 -12
- package/lib/components/buttons/group/btn-group.component.d.ts +0 -18
- package/lib/components/buttons/group/interfaces/btn-group-config.interface.d.ts +0 -11
- package/lib/components/buttons/index.d.ts +0 -3
- package/lib/components/buttons/loading/btn-loading.component.d.ts +0 -19
- package/lib/components/containers/applet-container/applet-container.component.d.ts +0 -22
- package/lib/components/containers/applet-container/provide-applet-config.util.d.ts +0 -15
- package/lib/components/containers/colum-header-container/column-header-container.component.d.ts +0 -7
- package/lib/components/containers/column-container/column-container.component.d.ts +0 -26
- package/lib/components/containers/column-container/directives/lazy-route.directive.d.ts +0 -17
- package/lib/components/containers/index.d.ts +0 -6
- package/lib/components/containers/list-container/index.d.ts +0 -3
- package/lib/components/containers/list-container/interfaces/list-container-config.interface.d.ts +0 -9
- package/lib/components/containers/list-container/list-pagination-container/list-pagination-container.component.d.ts +0 -23
- package/lib/components/containers/list-container/list-snapshot-container/list-snapshot-container.component.d.ts +0 -23
- package/lib/components/containers/modal-container/modal-container.component.d.ts +0 -16
- package/lib/components/filter/filter.component.d.ts +0 -44
- package/lib/components/filter/index.d.ts +0 -4
- package/lib/components/filter/interfaces/filter-config.interface.d.ts +0 -5
- package/lib/components/filter/interfaces/filter-field.interface.d.ts +0 -24
- package/lib/components/filter/interfaces/filter-search-event.interface.d.ts +0 -4
- package/lib/components/forms/country-input/form-country-input.component.d.ts +0 -41
- package/lib/components/forms/currency-input/form-currency-input.component.d.ts +0 -52
- package/lib/components/forms/date/form-date.component.d.ts +0 -33
- package/lib/components/forms/image-picker/directives/drag-n-drop.directive.d.ts +0 -10
- package/lib/components/forms/image-picker/form-image-picker.component.d.ts +0 -21
- package/lib/components/forms/index.d.ts +0 -11
- package/lib/components/forms/input/form-input.component.d.ts +0 -31
- package/lib/components/forms/number/form-number.component.d.ts +0 -27
- package/lib/components/forms/number/pipes/locale-number.pipe.d.ts +0 -8
- package/lib/components/forms/password/form-password.component.d.ts +0 -27
- package/lib/components/forms/rate-group-code-input/form-rate-group-code-input.component.d.ts +0 -41
- package/lib/components/forms/searchable-select/form-searchable-select.component.d.ts +0 -42
- package/lib/components/forms/select/form-select.component.d.ts +0 -34
- package/lib/components/forms/textarea/form-textarea.component.d.ts +0 -26
- package/lib/components/grids/grid-pagination/grid-pagination.component.d.ts +0 -33
- package/lib/components/grids/grid-snapshot/grid-snapshot.component.d.ts +0 -36
- package/lib/components/grids/index.d.ts +0 -4
- package/lib/components/grids/interfaces/grid-config.interface.d.ts +0 -16
- package/lib/components/grids/services/grid.service.d.ts +0 -12
- package/lib/components/index.d.ts +0 -8
- package/lib/components/infinite-scroll/directive/infinite-scroll.directive.d.ts +0 -15
- package/lib/components/infinite-scroll/index.d.ts +0 -2
- package/lib/components/infinite-scroll/infinite-scroll.component.d.ts +0 -12
- package/lib/components/tabs/index.d.ts +0 -6
- package/lib/components/tabs/tab-content/tab-content.component.d.ts +0 -14
- package/lib/components/tabs/tab-group/tab-group.component.d.ts +0 -18
- package/lib/guards/auth/auth.guard.d.ts +0 -1
- package/lib/guards/index.d.ts +0 -1
- package/lib/interceptors/header/header.interceptor.d.ts +0 -9
- package/lib/interceptors/index.d.ts +0 -2
- package/lib/interceptors/refresh-token/refresh-token.interceptor.d.ts +0 -14
- package/lib/interfaces/index.d.ts +0 -1
- package/lib/interfaces/user/user.interface.d.ts +0 -27
- package/lib/modules/index.d.ts +0 -2
- package/lib/modules/micro-frontend/index.d.ts +0 -1
- package/lib/modules/micro-frontend/utils/mf-bootstrap.util.d.ts +0 -9
- package/lib/modules/micro-frontend/utils/mf-global-state.util.d.ts +0 -4
- package/lib/modules/permission/directive/permission.directive.d.ts +0 -16
- package/lib/modules/permission/guards/permission.guard.d.ts +0 -2
- package/lib/modules/permission/index.d.ts +0 -6
- package/lib/modules/permission/pages/401/unauthorized.page.d.ts +0 -5
- package/lib/modules/permission/pages/loading/loading.page.d.ts +0 -18
- package/lib/modules/permission/pages/loading/provide-loading-config.util.d.ts +0 -10
- package/lib/modules/permission/services/permission.service.d.ts +0 -21
- package/lib/resolvers/auth/auth.resolver.d.ts +0 -14
- package/lib/resolvers/index.d.ts +0 -1
- package/lib/services/auth/auth.service.d.ts +0 -39
- package/lib/services/country/country.service.d.ts +0 -16
- package/lib/services/currency/currency.service.d.ts +0 -16
- package/lib/services/index.d.ts +0 -5
- package/lib/services/profile/profile.service.d.ts +0 -12
- package/lib/services/rate-group-code/rate-group-code.service.d.ts +0 -14
- package/lib/utils/contrast-color-generator/contrast-color-generator.util.d.ts +0 -4
- package/lib/utils/form-error-message/form-error-message.util.d.ts +0 -2
- package/lib/utils/format-capitalize/format-capitalize.util.d.ts +0 -1
- package/lib/utils/index.d.ts +0 -4
- package/lib/utils/redirect-to-first-menu/redirect-to-first-menu.util.d.ts +0 -2
- package/public-api.d.ts +0 -11
- package/src/assets/scss/forms.scss +0 -65
- package/src/assets/scss/grid.scss +0 -7505
- package/src/assets/scss/select.scss +0 -328
|
@@ -0,0 +1,707 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { InjectionToken, Injectable, signal, inject, Input, Directive, ChangeDetectionStrategy, Component, Inject } from '@angular/core';
|
|
3
|
+
import * as i1$1 from '@angular/router';
|
|
4
|
+
import { Router } from '@angular/router';
|
|
5
|
+
import { tap, catchError, throwError, switchMap } from 'rxjs';
|
|
6
|
+
import * as i1 from '@unipin/angular-gql';
|
|
7
|
+
import { Location } from '@angular/common';
|
|
8
|
+
import { NgIcon, provideIcons } from '@ng-icons/core';
|
|
9
|
+
import { matLockRound } from '@ng-icons/material-icons/round';
|
|
10
|
+
import { UpSpinnerComponent } from '@unipin/angular-applet/spinner';
|
|
11
|
+
|
|
12
|
+
const LOADING_CONFIG = new InjectionToken('LOADING_CONFIG');
|
|
13
|
+
function provideLoadingConfig(config) {
|
|
14
|
+
return {
|
|
15
|
+
provide: LOADING_CONFIG,
|
|
16
|
+
useValue: config
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
class ProfileService {
|
|
21
|
+
constructor(gql) {
|
|
22
|
+
this.gql = gql;
|
|
23
|
+
}
|
|
24
|
+
transformSubjetToUser(subject) {
|
|
25
|
+
const user = {
|
|
26
|
+
...subject,
|
|
27
|
+
email: '',
|
|
28
|
+
photo: '/assets/imgs/profile.svg'
|
|
29
|
+
};
|
|
30
|
+
subject.appLoginExt?.forEach(({ paramCode, file: { publicUrl } }) => {
|
|
31
|
+
if (paramCode === 'USER_PROFILE_PHOTO') {
|
|
32
|
+
user.photo = publicUrl;
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
subject.appLoginPrincipal?.forEach(({ principalId, principalType }) => {
|
|
36
|
+
if (principalType === 'EMAIL_USERNAME') {
|
|
37
|
+
user.email = principalId;
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
return user;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* A method to get the user profile information.
|
|
44
|
+
* @param {string} extraAttr - Contain extra attribute to get the user profile information.
|
|
45
|
+
* @param {CacheStrategy | undefined} cacheStrategy - Specifies how Apollo Client should handle data retrieval, determining whether it should make a network request to fetch fresh data from the server or use data from the local cache.
|
|
46
|
+
*
|
|
47
|
+
* @returns {Observable<QueryResult<{ authMsMyProfile: Maybe<AppLoginSubject> }>>} Contain user profile information.
|
|
48
|
+
*/
|
|
49
|
+
getMyProfile(extraAttr = '', cacheStrategy) {
|
|
50
|
+
return this.gql.query({
|
|
51
|
+
cacheStrategy,
|
|
52
|
+
operationName: 'getMyProfile',
|
|
53
|
+
query: `
|
|
54
|
+
query getMyProfile {
|
|
55
|
+
authMsMyProfile {
|
|
56
|
+
guid
|
|
57
|
+
name
|
|
58
|
+
status
|
|
59
|
+
gender
|
|
60
|
+
birthday
|
|
61
|
+
category
|
|
62
|
+
totpSecretGuid
|
|
63
|
+
appLoginPrincipal {
|
|
64
|
+
guid
|
|
65
|
+
principalId
|
|
66
|
+
principalType
|
|
67
|
+
}
|
|
68
|
+
appLoginExt {
|
|
69
|
+
guid
|
|
70
|
+
paramCode
|
|
71
|
+
paramType
|
|
72
|
+
file {
|
|
73
|
+
publicUrl
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
company {
|
|
77
|
+
code
|
|
78
|
+
guid
|
|
79
|
+
isInternal
|
|
80
|
+
name
|
|
81
|
+
status
|
|
82
|
+
}
|
|
83
|
+
merchants {
|
|
84
|
+
guid
|
|
85
|
+
name
|
|
86
|
+
status
|
|
87
|
+
}
|
|
88
|
+
roles {
|
|
89
|
+
guid
|
|
90
|
+
code
|
|
91
|
+
name
|
|
92
|
+
status
|
|
93
|
+
isInternal
|
|
94
|
+
}
|
|
95
|
+
departments {
|
|
96
|
+
isLead
|
|
97
|
+
department {
|
|
98
|
+
hierarchyCode
|
|
99
|
+
hierarchyPath
|
|
100
|
+
name
|
|
101
|
+
guid
|
|
102
|
+
status
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
${extraAttr}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
`,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.0", ngImport: i0, type: ProfileService, deps: [{ token: i1.GqlParser }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
112
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.0.0", ngImport: i0, type: ProfileService, providedIn: 'root' }); }
|
|
113
|
+
}
|
|
114
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.0", ngImport: i0, type: ProfileService, decorators: [{
|
|
115
|
+
type: Injectable,
|
|
116
|
+
args: [{
|
|
117
|
+
providedIn: 'root'
|
|
118
|
+
}]
|
|
119
|
+
}], ctorParameters: () => [{ type: i1.GqlParser }] });
|
|
120
|
+
|
|
121
|
+
class AuthService {
|
|
122
|
+
/**
|
|
123
|
+
* Both `authToken` and `refreshToken` are public static variable to store the auth token and refresh token obtained form the login API.
|
|
124
|
+
* They will be set as header param inside API calls.
|
|
125
|
+
* @type {string}
|
|
126
|
+
*
|
|
127
|
+
* @default ''
|
|
128
|
+
*/
|
|
129
|
+
static { this.authToken = ''; }
|
|
130
|
+
static { this.refreshToken = ''; }
|
|
131
|
+
constructor(gql, profileService) {
|
|
132
|
+
this.gql = gql;
|
|
133
|
+
this.profileService = profileService;
|
|
134
|
+
/**
|
|
135
|
+
* A public variable to store the logined user information.
|
|
136
|
+
* @type {User} An interface contain user information.
|
|
137
|
+
* @default {} as User
|
|
138
|
+
*/
|
|
139
|
+
this.user = signal({}, ...(ngDevMode ? [{ debugName: "user" }] : []));
|
|
140
|
+
}
|
|
141
|
+
static logout() {
|
|
142
|
+
AuthService.authToken = '';
|
|
143
|
+
AuthService.refreshToken = '';
|
|
144
|
+
localStorage.removeItem('authToken');
|
|
145
|
+
localStorage.removeItem('refreshToken');
|
|
146
|
+
}
|
|
147
|
+
logout() {
|
|
148
|
+
this.user.set({});
|
|
149
|
+
AuthService.logout();
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* This method is used by the `refreshTokenInterceptor`, to get the new token shortly before the auth token is expired.
|
|
153
|
+
* @param {MutationAuthMsRefreshAccessTokenArgs} variables - Contain `refreshToken` attribute which is the current refresh token.
|
|
154
|
+
* @returns {Observable<MutationResult<{ authMsRefreshAccessToken: Token }>>} Contain new `authToken` and `refreshToken`.
|
|
155
|
+
*/
|
|
156
|
+
refreshToken(variables) {
|
|
157
|
+
return this.gql.mutate({
|
|
158
|
+
variables,
|
|
159
|
+
operationName: 'RefreshToken',
|
|
160
|
+
headers: {
|
|
161
|
+
'operation-type': 'Mutation',
|
|
162
|
+
'operation-name': 'RefreshToken'
|
|
163
|
+
},
|
|
164
|
+
mutation: `
|
|
165
|
+
mutation RefreshToken($refreshToken: String!) {
|
|
166
|
+
authMsRefreshAccessToken(refreshToken: $refreshToken) {
|
|
167
|
+
accessToken
|
|
168
|
+
refreshToken
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
`
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* A method to authenticate the user to get the session for applet or platform.
|
|
176
|
+
* When successful it will set the user information to the `user` variable, `authToken` and `refreshToken`.
|
|
177
|
+
* It will set the `authToken`, `refreshToken`, `userGuid` and `roles` to the localStorage also for API calls.
|
|
178
|
+
*
|
|
179
|
+
* @param {{ email: string, password: string, sourcePlatform: string }} input - Contain `email` which is registered user email, `password` which is registered user password and `sourcePlatform` it's value can be `ADMIN` to get the applet session or `CP_COMMERCE` to get the platform session.
|
|
180
|
+
*
|
|
181
|
+
* @returns {Observable<MutationResult<{ authMsLogin: LoginResponse }>>} Contain logined user information.
|
|
182
|
+
*/
|
|
183
|
+
login(input) {
|
|
184
|
+
return this.gql.mutate({
|
|
185
|
+
operationName: 'Login',
|
|
186
|
+
variables: {
|
|
187
|
+
input
|
|
188
|
+
},
|
|
189
|
+
mutation: `
|
|
190
|
+
mutation Login($input: LoginRq!) {
|
|
191
|
+
authMsLogin(input: $input) {
|
|
192
|
+
accessToken
|
|
193
|
+
refreshToken
|
|
194
|
+
suggestedAction
|
|
195
|
+
user {
|
|
196
|
+
birthday
|
|
197
|
+
category
|
|
198
|
+
email
|
|
199
|
+
gender
|
|
200
|
+
guid
|
|
201
|
+
mobileNumber
|
|
202
|
+
name
|
|
203
|
+
status
|
|
204
|
+
departments {
|
|
205
|
+
department {
|
|
206
|
+
hierarchyCode
|
|
207
|
+
hierarchyPath
|
|
208
|
+
name
|
|
209
|
+
guid
|
|
210
|
+
status
|
|
211
|
+
}
|
|
212
|
+
isLead
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
roles {
|
|
216
|
+
guid
|
|
217
|
+
code
|
|
218
|
+
name
|
|
219
|
+
isInternal
|
|
220
|
+
status
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
`
|
|
225
|
+
}).pipe(tap(({ data }) => {
|
|
226
|
+
if (!data?.authMsLogin) {
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
const { accessToken, user, refreshToken, suggestedAction, roles } = data.authMsLogin;
|
|
230
|
+
this.user.set({
|
|
231
|
+
...user,
|
|
232
|
+
roles: roles,
|
|
233
|
+
photo: '/assets/imgs/profile.svg'
|
|
234
|
+
});
|
|
235
|
+
AuthService.authToken = accessToken ?? '';
|
|
236
|
+
AuthService.refreshToken = refreshToken ?? '';
|
|
237
|
+
if (suggestedAction !== 'CHANGE_PASSWORD') {
|
|
238
|
+
localStorage.setItem('authToken', AuthService.authToken);
|
|
239
|
+
}
|
|
240
|
+
localStorage.setItem('roles', JSON.stringify(roles));
|
|
241
|
+
localStorage.setItem('userGuid', this.user().guid ?? '');
|
|
242
|
+
localStorage.setItem('refreshToken', AuthService.refreshToken);
|
|
243
|
+
}));
|
|
244
|
+
}
|
|
245
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.0", ngImport: i0, type: AuthService, deps: [{ token: i1.GqlParser }, { token: ProfileService }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
246
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.0.0", ngImport: i0, type: AuthService, providedIn: 'root' }); }
|
|
247
|
+
}
|
|
248
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.0", ngImport: i0, type: AuthService, decorators: [{
|
|
249
|
+
type: Injectable,
|
|
250
|
+
args: [{
|
|
251
|
+
providedIn: 'root'
|
|
252
|
+
}]
|
|
253
|
+
}], ctorParameters: () => [{ type: i1.GqlParser }, { type: ProfileService }] });
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* The `AuthResolver` service provides methods for handling authentication-related tasks,
|
|
257
|
+
* such as checking user login status, retrieving authentication tokens, and managing token expiration.
|
|
258
|
+
*/
|
|
259
|
+
class AuthResolver {
|
|
260
|
+
/**
|
|
261
|
+
* Checks if the user is logged in by verifying the presence of an authentication token.
|
|
262
|
+
* @returns {boolean} - True if the user is logged in; otherwise, false.
|
|
263
|
+
*/
|
|
264
|
+
isUserLoggedIn() {
|
|
265
|
+
return AuthService.authToken !== '';
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Retrieves the authentication token, resolving it if needed.
|
|
269
|
+
* @returns {string | null} - The authentication token if the user is logged in; otherwise, null.
|
|
270
|
+
*/
|
|
271
|
+
getAuthToken() {
|
|
272
|
+
this.resolveUserAuthToken();
|
|
273
|
+
if (this.isUserLoggedIn()) {
|
|
274
|
+
return AuthService.authToken;
|
|
275
|
+
}
|
|
276
|
+
return null;
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Resolves the user's authentication token by checking expiration and whether the user still logged in or not.
|
|
280
|
+
*/
|
|
281
|
+
resolveUserAuthToken() {
|
|
282
|
+
if (!this.isUserLoggedIn() ||
|
|
283
|
+
!this.isTokenExpired(AuthService.authToken)) {
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
AuthService.logout();
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Checks if a given token is expired or not yet.
|
|
290
|
+
* @param {string | null} token - The token to be checked for expiration.
|
|
291
|
+
* @returns {boolean} - True if the token is expired; otherwise, false.
|
|
292
|
+
*/
|
|
293
|
+
isTokenExpired(token) {
|
|
294
|
+
if (!token || token === '') {
|
|
295
|
+
return true;
|
|
296
|
+
}
|
|
297
|
+
const date = this.getTokenExpirationDate(token);
|
|
298
|
+
if (date === null) {
|
|
299
|
+
return false;
|
|
300
|
+
}
|
|
301
|
+
return !(date.valueOf() > new Date().valueOf() + 0 * 1000);
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Retrieves the expiration date of a token.
|
|
305
|
+
* @param {string | null} token - The token for which to retrieve the expiration date.
|
|
306
|
+
* @returns {Date | null} - The expiration date of the token if available; otherwise, null.
|
|
307
|
+
*/
|
|
308
|
+
getTokenExpirationDate(token) {
|
|
309
|
+
const decoded = this.decodeToken(token);
|
|
310
|
+
if (!decoded || !decoded.hasOwnProperty('exp')) {
|
|
311
|
+
return null;
|
|
312
|
+
}
|
|
313
|
+
const date = new Date(0);
|
|
314
|
+
date.setUTCSeconds(decoded.exp);
|
|
315
|
+
return date;
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Decodes a JWT token to extract payload information.
|
|
319
|
+
* @param {string | null} token - The JWT token to be decoded.
|
|
320
|
+
* @returns {string | null} - The decoded payload as a string if successful; otherwise, null.
|
|
321
|
+
*/
|
|
322
|
+
decodeToken(token) {
|
|
323
|
+
if (!token || token === '') {
|
|
324
|
+
return null;
|
|
325
|
+
}
|
|
326
|
+
const parts = token.split('.');
|
|
327
|
+
if (parts.length !== 3) {
|
|
328
|
+
throw new Error(`The inspected token doesn't appear to be a JWT. Check to make sure it has three parts and see https://jwt.io for more.`);
|
|
329
|
+
}
|
|
330
|
+
const decoded = this.urlBase64Decode(parts[1]);
|
|
331
|
+
if (!decoded) {
|
|
332
|
+
throw new Error('Cannot decode the token.');
|
|
333
|
+
}
|
|
334
|
+
return JSON.parse(decoded);
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Decodes a base64url-encoded string.
|
|
338
|
+
* @param {string} str - The base64url-encoded string to be decoded.
|
|
339
|
+
* @returns {string} - The decoded string.
|
|
340
|
+
*/
|
|
341
|
+
urlBase64Decode(str) {
|
|
342
|
+
let output = str.replace(/-/g, '+').replace(/_/g, '/');
|
|
343
|
+
switch (output.length % 4) {
|
|
344
|
+
case 0:
|
|
345
|
+
break;
|
|
346
|
+
case 2:
|
|
347
|
+
output += '==';
|
|
348
|
+
break;
|
|
349
|
+
case 3:
|
|
350
|
+
output += '=';
|
|
351
|
+
break;
|
|
352
|
+
default:
|
|
353
|
+
throw new Error('Illegal base64url string!');
|
|
354
|
+
}
|
|
355
|
+
return this.b64DecodeUnicode(output);
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* Decodes a Unicode string from a base64-encoded string.
|
|
359
|
+
* @param {string} str - The base64-encoded string to be decoded.
|
|
360
|
+
* @returns {string} - The decoded Unicode string.
|
|
361
|
+
*/
|
|
362
|
+
b64DecodeUnicode(str) {
|
|
363
|
+
return decodeURIComponent(Array.prototype.map.call(this.b64decode(str), (c) => '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2)).join(''));
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Decodes a base64-encoded string.
|
|
367
|
+
* @param {string} str - The base64-encoded string to be decoded.
|
|
368
|
+
* @returns {string} - The decoded string.
|
|
369
|
+
*/
|
|
370
|
+
b64decode(str) {
|
|
371
|
+
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
|
|
372
|
+
let output = '';
|
|
373
|
+
str = String(str).replace(/=+$/, '');
|
|
374
|
+
if (str.length % 4 === 1) {
|
|
375
|
+
throw new Error(`'atob' failed: The string to be decoded is not correctly encoded.`);
|
|
376
|
+
}
|
|
377
|
+
for (let bc = 0, bs, buffer, idx = 0; (buffer = str.charAt(idx++)); ~buffer && ((bs = bc % 4 ? bs * 64 + buffer : buffer), bc++ % 4) ? (output += String.fromCharCode(255 & (bs >> ((-2 * bc) & 6)))) : 0)
|
|
378
|
+
buffer = chars.indexOf(buffer);
|
|
379
|
+
return output;
|
|
380
|
+
}
|
|
381
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.0", ngImport: i0, type: AuthResolver, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
382
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.0.0", ngImport: i0, type: AuthResolver, providedIn: 'root' }); }
|
|
383
|
+
}
|
|
384
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.0", ngImport: i0, type: AuthResolver, decorators: [{
|
|
385
|
+
type: Injectable,
|
|
386
|
+
args: [{
|
|
387
|
+
providedIn: 'root'
|
|
388
|
+
}]
|
|
389
|
+
}] });
|
|
390
|
+
|
|
391
|
+
const authGuard = () => {
|
|
392
|
+
const router = inject(Router);
|
|
393
|
+
const resolver = inject(AuthResolver);
|
|
394
|
+
if (!resolver.isUserLoggedIn()) {
|
|
395
|
+
router.navigateByUrl('/auth/login');
|
|
396
|
+
return false;
|
|
397
|
+
}
|
|
398
|
+
return true;
|
|
399
|
+
};
|
|
400
|
+
|
|
401
|
+
class PermissionService {
|
|
402
|
+
constructor(gql) {
|
|
403
|
+
this.gql = gql;
|
|
404
|
+
this.permissions = signal(new Map(), ...(ngDevMode ? [{ debugName: "permissions" }] : []));
|
|
405
|
+
/**
|
|
406
|
+
* A boolean value that tells the permission service is initiated (permissions list is retrieved from Backend) or not.
|
|
407
|
+
* @default false
|
|
408
|
+
*/
|
|
409
|
+
this.isInitiated = false;
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
412
|
+
* A method that checking if the user has the permission or not based on the params value.
|
|
413
|
+
* @param {string} permission - Permission code that wanted to be checked
|
|
414
|
+
*
|
|
415
|
+
* @returns {boolean} Contain boolean value that tells the user has the permission or not.
|
|
416
|
+
*/
|
|
417
|
+
has(permission) {
|
|
418
|
+
const permissions = this.permissions();
|
|
419
|
+
const [scope, module, type] = permission.split('.');
|
|
420
|
+
return (permissions.has(`${scope}.${module}.ADMIN`) ||
|
|
421
|
+
permissions.has(`${scope}.${module}.${type}`));
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* A method that set the permissions and permission modules.
|
|
425
|
+
* @param {string[]} permCodes - Contain list of permission codes.
|
|
426
|
+
*/
|
|
427
|
+
setPermission(permCodes) {
|
|
428
|
+
this.permissions.update((map) => {
|
|
429
|
+
const newMap = new Map(map);
|
|
430
|
+
for (const code of permCodes) {
|
|
431
|
+
newMap.set(code, true);
|
|
432
|
+
}
|
|
433
|
+
return newMap;
|
|
434
|
+
});
|
|
435
|
+
}
|
|
436
|
+
/**
|
|
437
|
+
* A method that get the query value with authMsPermission as the object.
|
|
438
|
+
* @param {PermissionFilter} filter - Contain filter as a conditions for the query.
|
|
439
|
+
* @returns {Observable<ApolloQueryResult<{ authMsPermission: { data: AppPermDfn[] }}>>} Contain query value.
|
|
440
|
+
*/
|
|
441
|
+
getPermissions(filter, cacheStrategy) {
|
|
442
|
+
return this.gql.query({
|
|
443
|
+
cacheStrategy,
|
|
444
|
+
operationName: 'QueryPermission',
|
|
445
|
+
variables: {
|
|
446
|
+
filter
|
|
447
|
+
},
|
|
448
|
+
query: `
|
|
449
|
+
query QueryPermission($filter: PermissionFilter!) {
|
|
450
|
+
authMsPermission(filter: $filter) {
|
|
451
|
+
data {
|
|
452
|
+
permCode
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
`
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.0", ngImport: i0, type: PermissionService, deps: [{ token: i1.GqlParser }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
460
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.0.0", ngImport: i0, type: PermissionService, providedIn: 'root' }); }
|
|
461
|
+
}
|
|
462
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.0", ngImport: i0, type: PermissionService, decorators: [{
|
|
463
|
+
type: Injectable,
|
|
464
|
+
args: [{
|
|
465
|
+
providedIn: 'root'
|
|
466
|
+
}]
|
|
467
|
+
}], ctorParameters: () => [{ type: i1.GqlParser }] });
|
|
468
|
+
|
|
469
|
+
const permissionGuard = (route) => {
|
|
470
|
+
const router = inject(Router);
|
|
471
|
+
const location = inject(Location);
|
|
472
|
+
const permissionService = inject(PermissionService);
|
|
473
|
+
const permissions = route.data['permissions'];
|
|
474
|
+
const aggregator = route.data['aggregator'] ?? 'OR';
|
|
475
|
+
if (!permissions ||
|
|
476
|
+
!permissions.length) {
|
|
477
|
+
console.error('Invalid config: permissions is a required parameter in route data for PermissionGuard');
|
|
478
|
+
return false;
|
|
479
|
+
}
|
|
480
|
+
if (!permissionService.isInitiated) {
|
|
481
|
+
router.navigate(['loading'], {
|
|
482
|
+
queryParams: {
|
|
483
|
+
url: `${location.path() + window.location.hash}`
|
|
484
|
+
}
|
|
485
|
+
});
|
|
486
|
+
return false;
|
|
487
|
+
}
|
|
488
|
+
if (aggregator === 'OR') {
|
|
489
|
+
for (let i = 0; i < permissions.length; i++) {
|
|
490
|
+
if (permissionService.has(permissions[i])) {
|
|
491
|
+
return true;
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
let hasPermission = true;
|
|
496
|
+
for (let i = 0; i < permissions.length; i++) {
|
|
497
|
+
if (!permissionService.has(permissions[i])) {
|
|
498
|
+
hasPermission = false;
|
|
499
|
+
break;
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
if (hasPermission) {
|
|
503
|
+
return true;
|
|
504
|
+
}
|
|
505
|
+
router.navigateByUrl('/401');
|
|
506
|
+
return false;
|
|
507
|
+
};
|
|
508
|
+
|
|
509
|
+
const authorizationInterceptor = (request, next) => {
|
|
510
|
+
return next(request.clone({
|
|
511
|
+
headers: request.headers,
|
|
512
|
+
setHeaders: {
|
|
513
|
+
authorization: AuthService.authToken,
|
|
514
|
+
}
|
|
515
|
+
}));
|
|
516
|
+
};
|
|
517
|
+
|
|
518
|
+
const refreshTokenInterceptor = (request, next) => {
|
|
519
|
+
const router = inject(Router);
|
|
520
|
+
const authService = inject(AuthService);
|
|
521
|
+
return next(request).pipe(catchError(({ error: { errors } }) => {
|
|
522
|
+
if (errors[0].extensions.code !== 'USER_INVALID_TOKEN') {
|
|
523
|
+
return throwError(() => errors[0]);
|
|
524
|
+
}
|
|
525
|
+
return authService.refreshToken({ refreshToken: AuthService.refreshToken }).pipe(switchMap(({ data }) => {
|
|
526
|
+
const { accessToken, refreshToken } = data.authMsRefreshAccessToken;
|
|
527
|
+
AuthService.authToken = accessToken;
|
|
528
|
+
AuthService.refreshToken = refreshToken;
|
|
529
|
+
localStorage.setItem('authToken', accessToken);
|
|
530
|
+
localStorage.setItem('refreshToken', refreshToken);
|
|
531
|
+
return next(request.clone({
|
|
532
|
+
setHeaders: {
|
|
533
|
+
authorization: accessToken,
|
|
534
|
+
},
|
|
535
|
+
}));
|
|
536
|
+
}), catchError(() => {
|
|
537
|
+
authService.logout();
|
|
538
|
+
location.href = `/auth/login?url=${encodeURIComponent(router.url + location.hash)}`;
|
|
539
|
+
return throwError(() => errors[0]);
|
|
540
|
+
}));
|
|
541
|
+
}));
|
|
542
|
+
};
|
|
543
|
+
|
|
544
|
+
/**
|
|
545
|
+
* The `PermissionDirective` is a directive that conditionally renders content based on user permissions.
|
|
546
|
+
* @selector '[hasPermission]'
|
|
547
|
+
*
|
|
548
|
+
* @example
|
|
549
|
+
* ```html
|
|
550
|
+
* <div *hasPermission="'MERCHANT.CONTRACT.READ'"></div>
|
|
551
|
+
* ```
|
|
552
|
+
*/
|
|
553
|
+
class PermissionDirective {
|
|
554
|
+
constructor(service, templateRef, viewContainer) {
|
|
555
|
+
this.service = service;
|
|
556
|
+
this.templateRef = templateRef;
|
|
557
|
+
this.viewContainer = viewContainer;
|
|
558
|
+
}
|
|
559
|
+
set hasPermission(permission) {
|
|
560
|
+
if (this.service.has(permission)) {
|
|
561
|
+
this.viewContainer.createEmbeddedView(this.templateRef);
|
|
562
|
+
return;
|
|
563
|
+
}
|
|
564
|
+
this.viewContainer.clear();
|
|
565
|
+
}
|
|
566
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.0", ngImport: i0, type: PermissionDirective, deps: [{ token: PermissionService }, { token: i0.TemplateRef }, { token: i0.ViewContainerRef }], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
567
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.0.0", type: PermissionDirective, isStandalone: true, selector: "[hasPermission]", inputs: { hasPermission: "hasPermission" }, exportAs: ["hasPermission"], ngImport: i0 }); }
|
|
568
|
+
}
|
|
569
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.0", ngImport: i0, type: PermissionDirective, decorators: [{
|
|
570
|
+
type: Directive,
|
|
571
|
+
args: [{
|
|
572
|
+
standalone: true,
|
|
573
|
+
exportAs: 'hasPermission',
|
|
574
|
+
selector: '[hasPermission]'
|
|
575
|
+
}]
|
|
576
|
+
}], ctorParameters: () => [{ type: PermissionService }, { type: i0.TemplateRef }, { type: i0.ViewContainerRef }], propDecorators: { hasPermission: [{
|
|
577
|
+
type: Input
|
|
578
|
+
}] } });
|
|
579
|
+
|
|
580
|
+
class UnauthorizedPage {
|
|
581
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.0", ngImport: i0, type: UnauthorizedPage, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
|
|
582
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "21.0.0", type: UnauthorizedPage, isStandalone: true, selector: "up-unauthorized", host: { classAttribute: "flex flex-col items-center justify-center size-full gap-4 p-5 select-none" }, providers: [
|
|
583
|
+
provideIcons({
|
|
584
|
+
matLockRound
|
|
585
|
+
})
|
|
586
|
+
], ngImport: i0, template: `
|
|
587
|
+
<ng-icon
|
|
588
|
+
name="matLockRound"
|
|
589
|
+
class="text-3xl lg:text-5xl"
|
|
590
|
+
/>
|
|
591
|
+
|
|
592
|
+
<h3 class="text-center text-lg lg:text-2xl font-bold">
|
|
593
|
+
Oops! You're not authorized to access this page.
|
|
594
|
+
</h3>
|
|
595
|
+
<p class="text-center">Please log in or re-check your permissions.</p>
|
|
596
|
+
`, isInline: true, dependencies: [{ kind: "component", type: NgIcon, selector: "ng-icon", inputs: ["name", "svg", "size", "strokeWidth", "color"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
|
|
597
|
+
}
|
|
598
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.0", ngImport: i0, type: UnauthorizedPage, decorators: [{
|
|
599
|
+
type: Component,
|
|
600
|
+
args: [{
|
|
601
|
+
standalone: true,
|
|
602
|
+
selector: 'up-unauthorized',
|
|
603
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
604
|
+
host: {
|
|
605
|
+
class: 'flex flex-col items-center justify-center size-full gap-4 p-5 select-none'
|
|
606
|
+
},
|
|
607
|
+
providers: [
|
|
608
|
+
provideIcons({
|
|
609
|
+
matLockRound
|
|
610
|
+
})
|
|
611
|
+
],
|
|
612
|
+
imports: [
|
|
613
|
+
NgIcon
|
|
614
|
+
],
|
|
615
|
+
template: `
|
|
616
|
+
<ng-icon
|
|
617
|
+
name="matLockRound"
|
|
618
|
+
class="text-3xl lg:text-5xl"
|
|
619
|
+
/>
|
|
620
|
+
|
|
621
|
+
<h3 class="text-center text-lg lg:text-2xl font-bold">
|
|
622
|
+
Oops! You're not authorized to access this page.
|
|
623
|
+
</h3>
|
|
624
|
+
<p class="text-center">Please log in or re-check your permissions.</p>
|
|
625
|
+
`,
|
|
626
|
+
}]
|
|
627
|
+
}] });
|
|
628
|
+
|
|
629
|
+
class LoadingPage {
|
|
630
|
+
constructor(config, router, route, permissionService) {
|
|
631
|
+
this.config = config;
|
|
632
|
+
this.router = router;
|
|
633
|
+
this.route = route;
|
|
634
|
+
this.permissionService = permissionService;
|
|
635
|
+
}
|
|
636
|
+
ngOnInit() {
|
|
637
|
+
const subjectGuid = localStorage.getItem(this.config.subjectGuidStorageKey || 'userGuid');
|
|
638
|
+
if (!subjectGuid) {
|
|
639
|
+
this.router.navigate(['401']);
|
|
640
|
+
return;
|
|
641
|
+
}
|
|
642
|
+
const permCodeList = [];
|
|
643
|
+
this.sub = this.permissionService.getPermissions({
|
|
644
|
+
subjectGuid,
|
|
645
|
+
pageSize: 1000,
|
|
646
|
+
permType: this.config.permTypes,
|
|
647
|
+
permModule: this.config.permModules,
|
|
648
|
+
}, 'no-cache').subscribe({
|
|
649
|
+
error: () => {
|
|
650
|
+
this.router.navigate(['401']);
|
|
651
|
+
},
|
|
652
|
+
next: ({ data: { authMsPermission: { data } } }) => {
|
|
653
|
+
data.forEach(({ permCode }) => {
|
|
654
|
+
if (!permCode) {
|
|
655
|
+
return;
|
|
656
|
+
}
|
|
657
|
+
permCodeList.push(permCode);
|
|
658
|
+
});
|
|
659
|
+
this.permissionService.isInitiated = true;
|
|
660
|
+
this.permissionService.setPermission(permCodeList);
|
|
661
|
+
this.router.navigateByUrl(this.route.snapshot.queryParamMap.get('url') ?? '');
|
|
662
|
+
}
|
|
663
|
+
});
|
|
664
|
+
}
|
|
665
|
+
ngOnDestroy() {
|
|
666
|
+
this.sub?.unsubscribe();
|
|
667
|
+
}
|
|
668
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.0", ngImport: i0, type: LoadingPage, deps: [{ token: LOADING_CONFIG }, { token: i1$1.Router }, { token: i1$1.ActivatedRoute }, { token: PermissionService }], target: i0.ɵɵFactoryTarget.Component }); }
|
|
669
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "21.0.0", type: LoadingPage, isStandalone: true, selector: "up-loading", host: { classAttribute: "flex flex-col items-center gap-6 p-5 justify-center size-full select-none" }, ngImport: i0, template: `
|
|
670
|
+
<up-spinner class="size-10" />
|
|
671
|
+
|
|
672
|
+
<h3 class="text-center text-lg lg:text-2xl font-bold">
|
|
673
|
+
Please wait, we're preparing the applet. Drink water or coffee while waiting.
|
|
674
|
+
</h3>
|
|
675
|
+
`, isInline: true, dependencies: [{ kind: "component", type: UpSpinnerComponent, selector: "up-spinner", inputs: ["stokeWidth", "inlineClass"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
|
|
676
|
+
}
|
|
677
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.0", ngImport: i0, type: LoadingPage, decorators: [{
|
|
678
|
+
type: Component,
|
|
679
|
+
args: [{
|
|
680
|
+
standalone: true,
|
|
681
|
+
selector: 'up-loading',
|
|
682
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
683
|
+
host: {
|
|
684
|
+
class: 'flex flex-col items-center gap-6 p-5 justify-center size-full select-none'
|
|
685
|
+
},
|
|
686
|
+
imports: [
|
|
687
|
+
UpSpinnerComponent
|
|
688
|
+
],
|
|
689
|
+
template: `
|
|
690
|
+
<up-spinner class="size-10" />
|
|
691
|
+
|
|
692
|
+
<h3 class="text-center text-lg lg:text-2xl font-bold">
|
|
693
|
+
Please wait, we're preparing the applet. Drink water or coffee while waiting.
|
|
694
|
+
</h3>
|
|
695
|
+
`,
|
|
696
|
+
}]
|
|
697
|
+
}], ctorParameters: () => [{ type: undefined, decorators: [{
|
|
698
|
+
type: Inject,
|
|
699
|
+
args: [LOADING_CONFIG]
|
|
700
|
+
}] }, { type: i1$1.Router }, { type: i1$1.ActivatedRoute }, { type: PermissionService }] });
|
|
701
|
+
|
|
702
|
+
/**
|
|
703
|
+
* Generated bundle index. Do not edit.
|
|
704
|
+
*/
|
|
705
|
+
|
|
706
|
+
export { AuthResolver, AuthService, LoadingPage, PermissionDirective, PermissionService, ProfileService, UnauthorizedPage, authGuard, authorizationInterceptor, permissionGuard, provideLoadingConfig, refreshTokenInterceptor };
|
|
707
|
+
//# sourceMappingURL=unipin-angular-applet-auth.mjs.map
|