@sd-angular/core 19.0.0-beta.8 → 19.0.0-beta.80
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 +686 -33
- package/assets/scss/ckeditor5.scss +61 -4
- package/assets/scss/core/bootstrap.scss +17 -0
- package/assets/scss/core/form.scss +32 -6
- package/assets/scss/core/grid.scss +40 -0
- package/assets/scss/sd-core.scss +5 -0
- package/assets/scss/themes/material-theme.scss +82 -40
- package/components/anchor-v2/src/components/anchor-item-v2/anchor-item-v2.component.d.ts +5 -5
- package/components/anchor-v2/src/components/anchor-v2/anchor-v2.component.d.ts +12 -18
- package/components/anchor-v2/src/components/anchor-vertical-v2/anchor-vertical-list-v2.component.d.ts +9 -10
- package/components/anchor-v2/src/models/sd-anchor-v2.model.d.ts +3 -3
- package/components/avatar/index.d.ts +1 -0
- package/components/avatar/src/avatar.component.d.ts +19 -0
- package/components/badge/src/badge.component.d.ts +77 -19
- package/components/button/src/button.component.d.ts +30 -28
- package/components/chart/index.d.ts +4 -0
- package/components/chart/src/bar-chart.component.d.ts +18 -0
- package/components/chart/src/doughnut-chart.component.d.ts +16 -0
- package/components/chart/src/line-chart.component.d.ts +18 -0
- package/components/chart/src/pie-chart.component.d.ts +16 -0
- package/components/code-editor/index.d.ts +1 -0
- package/components/code-editor/src/code-editor.component.d.ts +25 -0
- package/components/document-builder/index.d.ts +1 -0
- package/components/document-builder/src/document-builder.component.d.ts +12 -41
- package/components/document-builder/src/document-builder.model.d.ts +14 -11
- package/components/document-builder/src/plugins/block-space/block-space.plugin.d.ts +9 -0
- package/components/document-builder/src/plugins/ck-comment/ck-comment.plugin.d.ts +44 -0
- package/components/document-builder/src/plugins/ck-comment/ck-comment.plugin.model.d.ts +57 -0
- package/components/document-builder/src/plugins/heading/heading.plugin.d.ts +1 -0
- package/components/document-builder/src/plugins/highlight-range/highlight-range.plugin.d.ts +4 -0
- package/components/document-builder/src/plugins/image-custom/image-custom.plugin.d.ts +31 -0
- package/components/document-builder/src/plugins/index.d.ts +7 -2
- package/components/document-builder/src/plugins/page-orientation/page-orientation.plugin.d.ts +2 -2
- package/components/document-builder/src/plugins/paste-handler/filters/bookmark.d.ts +14 -0
- package/components/document-builder/src/plugins/paste-handler/filters/br.d.ts +15 -0
- package/components/document-builder/src/plugins/paste-handler/filters/image.d.ts +25 -0
- package/components/document-builder/src/plugins/paste-handler/filters/list.d.ts +29 -0
- package/components/document-builder/src/plugins/paste-handler/filters/parse.d.ts +35 -0
- package/components/document-builder/src/plugins/paste-handler/filters/removeboldwrapper.d.ts +15 -0
- package/components/document-builder/src/plugins/paste-handler/filters/removegooglesheetstag.d.ts +15 -0
- package/components/document-builder/src/plugins/paste-handler/filters/removeinvalidtablewidth.d.ts +15 -0
- package/components/document-builder/src/plugins/paste-handler/filters/removemsattributes.d.ts +15 -0
- package/components/document-builder/src/plugins/paste-handler/filters/removestyleblock.d.ts +15 -0
- package/components/document-builder/src/plugins/paste-handler/filters/removexmlns.d.ts +15 -0
- package/components/document-builder/src/plugins/paste-handler/filters/replacemsfootnotes.d.ts +54 -0
- package/components/document-builder/src/plugins/paste-handler/filters/replacetabswithinprewithspaces.d.ts +24 -0
- package/components/document-builder/src/plugins/paste-handler/filters/space.d.ts +27 -0
- package/components/document-builder/src/plugins/paste-handler/filters/table.d.ts +16 -0
- package/components/document-builder/src/plugins/paste-handler/filters/utils.d.ts +25 -0
- package/components/document-builder/src/plugins/paste-handler/index.d.ts +35 -0
- package/components/document-builder/src/plugins/paste-handler/normalizers/googledocsnormalizer.d.ts +31 -0
- package/components/document-builder/src/plugins/paste-handler/normalizers/googlesheetsnormalizer.d.ts +31 -0
- package/components/document-builder/src/plugins/paste-handler/normalizers/mswordnormalizer.d.ts +29 -0
- package/components/document-builder/src/plugins/paste-handler/types.d.ts +30 -0
- package/components/document-builder/src/plugins/table-custom/index.d.ts +34 -0
- package/components/document-builder/src/plugins/variable/variable.plugin.d.ts +39 -0
- package/components/index.d.ts +5 -0
- package/components/mini-editor/index.d.ts +2 -0
- package/components/mini-editor/src/mini-editor.component.d.ts +91 -0
- package/components/mini-editor/src/mini-editor.model.d.ts +44 -0
- package/components/modal/index.d.ts +1 -1
- package/components/modal/src/modal.component.d.ts +26 -0
- package/components/section/index.d.ts +1 -0
- package/components/section/src/section-item/section-item.component.d.ts +7 -0
- package/components/section/src/section.component.d.ts +11 -11
- package/components/side-drawer/src/side-drawer.component.d.ts +11 -24
- package/components/tab-router/src/components/tab-router-item/tab-router-item.component.d.ts +4 -1
- package/components/tab-router/src/components/tab-router-outlet/tab-router-outlet.component.d.ts +3 -15
- package/components/table/index.d.ts +2 -0
- package/components/table/src/components/column-filter/column-filter.component.d.ts +3 -3
- package/components/table/src/components/column-title/column-title.component.d.ts +10 -0
- package/components/table/src/components/desktop-cell/desktop-cell.component.d.ts +18 -11
- package/components/table/src/components/desktop-cell/view/view.component.d.ts +24 -0
- package/components/table/src/components/external-filter/external-filter.component.d.ts +1 -1
- package/components/table/src/components/index.d.ts +1 -0
- package/components/table/src/components/selector-action/action-filter.pipe.d.ts +11 -10
- package/components/table/src/components/selector-action/selector-action.component.d.ts +5 -3
- package/components/table/src/directives/index.d.ts +4 -0
- package/components/table/src/directives/sd-table-cell-def.directive.d.ts +2 -3
- package/components/table/src/directives/sd-table-column-filter-def.directive.d.ts +8 -0
- package/components/table/src/directives/sd-table-expand-def.directive.d.ts +0 -1
- package/components/table/src/directives/sd-table-filter-def.directive.d.ts +4 -6
- package/components/table/src/directives/sd-table-footer-def.directive.d.ts +2 -3
- package/components/table/src/directives/sd-table-title-def.directive.d.ts +8 -0
- package/components/table/src/directives/sticky-shadow.directive.d.ts +17 -0
- package/components/table/src/models/table-column.model.d.ts +49 -40
- package/components/table/src/models/table-command.model.d.ts +7 -3
- package/components/table/src/models/table-item.model.d.ts +5 -4
- package/components/table/src/models/table-option-config.model.d.ts +3 -0
- package/components/table/src/models/table-option-export.model.d.ts +3 -2
- package/components/table/src/models/table-option-selector.model.d.ts +17 -10
- package/components/table/src/models/table-option.model.d.ts +15 -8
- package/components/table/src/services/index.d.ts +3 -0
- package/components/table/src/services/table-export/table-export.service.d.ts +26 -0
- package/components/table/src/services/table-filter/table-filter.model.d.ts +6 -5
- package/components/table/src/services/table-format/table-format.service.d.ts +16 -0
- package/components/table/src/table.component.d.ts +46 -53
- package/components/upload-file/src/configurations/upload-file.configuration.d.ts +34 -1
- package/components/upload-file/src/services/upload-file.service.d.ts +0 -1
- package/components/upload-file/src/upload-file.component.d.ts +52 -54
- package/components/view/index.d.ts +1 -0
- package/components/view/src/view.component.d.ts +16 -0
- package/components/workflow/src/models/form-generic-component.model.d.ts +5 -4
- package/components/workflow/src/models/form-generic-expression.model.d.ts +1 -0
- package/components/workflow/src/models/index.d.ts +1 -0
- package/components/workflow/src/pipes/html.pipe.d.ts +4 -4
- package/directives/index.d.ts +2 -0
- package/directives/src/sd-href.directive.d.ts +9 -0
- package/directives/src/sd-tooltip.directive.d.ts +26 -0
- package/fesm2022/sd-angular-core-components-anchor-v2.mjs +79 -154
- package/fesm2022/sd-angular-core-components-anchor-v2.mjs.map +1 -1
- package/fesm2022/sd-angular-core-components-avatar.mjs +103 -0
- package/fesm2022/sd-angular-core-components-avatar.mjs.map +1 -0
- package/fesm2022/sd-angular-core-components-badge.mjs +101 -91
- package/fesm2022/sd-angular-core-components-badge.mjs.map +1 -1
- package/fesm2022/sd-angular-core-components-button.mjs +70 -96
- package/fesm2022/sd-angular-core-components-button.mjs.map +1 -1
- package/fesm2022/sd-angular-core-components-chart.mjs +290 -0
- package/fesm2022/sd-angular-core-components-chart.mjs.map +1 -0
- package/fesm2022/sd-angular-core-components-code-editor.mjs +127 -0
- package/fesm2022/sd-angular-core-components-code-editor.mjs.map +1 -0
- package/fesm2022/sd-angular-core-components-document-builder.mjs +4006 -611
- package/fesm2022/sd-angular-core-components-document-builder.mjs.map +1 -1
- package/fesm2022/sd-angular-core-components-history.mjs +1 -1
- package/fesm2022/sd-angular-core-components-history.mjs.map +1 -1
- package/fesm2022/sd-angular-core-components-import-excel.mjs +1 -1
- package/fesm2022/sd-angular-core-components-import-excel.mjs.map +1 -1
- package/fesm2022/sd-angular-core-components-mini-editor.mjs +332 -0
- package/fesm2022/sd-angular-core-components-mini-editor.mjs.map +1 -0
- package/fesm2022/sd-angular-core-components-modal.mjs +63 -92
- package/fesm2022/sd-angular-core-components-modal.mjs.map +1 -1
- package/fesm2022/sd-angular-core-components-preview.mjs +1 -1
- package/fesm2022/sd-angular-core-components-preview.mjs.map +1 -1
- package/fesm2022/sd-angular-core-components-quick-action.mjs +2 -2
- package/fesm2022/sd-angular-core-components-quick-action.mjs.map +1 -1
- package/fesm2022/sd-angular-core-components-section.mjs +41 -43
- package/fesm2022/sd-angular-core-components-section.mjs.map +1 -1
- package/fesm2022/sd-angular-core-components-side-drawer.mjs +78 -84
- package/fesm2022/sd-angular-core-components-side-drawer.mjs.map +1 -1
- package/fesm2022/sd-angular-core-components-tab-router.mjs +151 -241
- package/fesm2022/sd-angular-core-components-tab-router.mjs.map +1 -1
- package/fesm2022/sd-angular-core-components-table.mjs +1394 -1254
- package/fesm2022/sd-angular-core-components-table.mjs.map +1 -1
- package/fesm2022/sd-angular-core-components-upload-file.mjs +390 -443
- package/fesm2022/sd-angular-core-components-upload-file.mjs.map +1 -1
- package/fesm2022/sd-angular-core-components-view.mjs +45 -0
- package/fesm2022/sd-angular-core-components-view.mjs.map +1 -0
- package/fesm2022/sd-angular-core-components-workflow.mjs +165 -168
- package/fesm2022/sd-angular-core-components-workflow.mjs.map +1 -1
- package/fesm2022/sd-angular-core-components.mjs +5 -0
- package/fesm2022/sd-angular-core-components.mjs.map +1 -1
- package/fesm2022/sd-angular-core-directives.mjs +286 -27
- package/fesm2022/sd-angular-core-directives.mjs.map +1 -1
- package/fesm2022/sd-angular-core-forms-autocomplete.mjs +289 -363
- package/fesm2022/sd-angular-core-forms-autocomplete.mjs.map +1 -1
- package/fesm2022/sd-angular-core-forms-chip-calendar.mjs +170 -189
- package/fesm2022/sd-angular-core-forms-chip-calendar.mjs.map +1 -1
- package/fesm2022/sd-angular-core-forms-chip.mjs +184 -194
- package/fesm2022/sd-angular-core-forms-chip.mjs.map +1 -1
- package/fesm2022/sd-angular-core-forms-date-range.mjs +180 -242
- package/fesm2022/sd-angular-core-forms-date-range.mjs.map +1 -1
- package/fesm2022/sd-angular-core-forms-date.mjs +178 -270
- package/fesm2022/sd-angular-core-forms-date.mjs.map +1 -1
- package/fesm2022/sd-angular-core-forms-datetime.mjs +177 -285
- package/fesm2022/sd-angular-core-forms-datetime.mjs.map +1 -1
- package/fesm2022/sd-angular-core-forms-input-number.mjs +210 -337
- package/fesm2022/sd-angular-core-forms-input-number.mjs.map +1 -1
- package/fesm2022/sd-angular-core-forms-input.mjs +169 -286
- package/fesm2022/sd-angular-core-forms-input.mjs.map +1 -1
- package/fesm2022/sd-angular-core-forms-radio.mjs +3 -2
- package/fesm2022/sd-angular-core-forms-radio.mjs.map +1 -1
- package/fesm2022/sd-angular-core-forms-select.mjs +390 -447
- package/fesm2022/sd-angular-core-forms-select.mjs.map +1 -1
- package/fesm2022/sd-angular-core-forms-textarea.mjs +167 -226
- package/fesm2022/sd-angular-core-forms-textarea.mjs.map +1 -1
- package/fesm2022/sd-angular-core-modules-authom.mjs +359 -0
- package/fesm2022/sd-angular-core-modules-authom.mjs.map +1 -0
- package/fesm2022/sd-angular-core-modules-keycloak.mjs +126 -0
- package/fesm2022/sd-angular-core-modules-keycloak.mjs.map +1 -0
- package/fesm2022/sd-angular-core-modules-layout.mjs +709 -456
- package/fesm2022/sd-angular-core-modules-layout.mjs.map +1 -1
- package/fesm2022/sd-angular-core-modules-permission.mjs +160 -74
- package/fesm2022/sd-angular-core-modules-permission.mjs.map +1 -1
- package/fesm2022/sd-angular-core-modules.mjs +2 -1
- package/fesm2022/sd-angular-core-modules.mjs.map +1 -1
- package/fesm2022/sd-angular-core-services-api.mjs +5 -10
- package/fesm2022/sd-angular-core-services-api.mjs.map +1 -1
- package/fesm2022/sd-angular-core-services-confirm.mjs +9 -7
- package/fesm2022/sd-angular-core-services-confirm.mjs.map +1 -1
- package/fesm2022/sd-angular-core-services-docx.mjs +173 -0
- package/fesm2022/sd-angular-core-services-docx.mjs.map +1 -0
- package/fesm2022/sd-angular-core-services-notify.mjs +2 -2
- package/fesm2022/sd-angular-core-services-notify.mjs.map +1 -1
- package/fesm2022/sd-angular-core-services.mjs +1 -0
- package/fesm2022/sd-angular-core-services.mjs.map +1 -1
- package/fesm2022/sd-angular-core-utilities-extensions.mjs +58 -80
- package/fesm2022/sd-angular-core-utilities-extensions.mjs.map +1 -1
- package/fesm2022/sd-angular-core-utilities-models.mjs +15 -1
- package/fesm2022/sd-angular-core-utilities-models.mjs.map +1 -1
- package/fesm2022/sd-angular-core.mjs +0 -1
- package/fesm2022/sd-angular-core.mjs.map +1 -1
- package/forms/autocomplete/src/autocomplete.component.d.ts +55 -55
- package/forms/chip/src/chip.component.d.ts +37 -40
- package/forms/chip-calendar/src/chip-calendar.component.d.ts +37 -38
- package/forms/date/src/date.component.d.ts +48 -46
- package/forms/date-range/src/date-range.component.d.ts +35 -34
- package/forms/datetime/src/datetime.component.d.ts +48 -49
- package/forms/input/src/input.component.d.ts +54 -57
- package/forms/input-number/src/input-number.component.d.ts +53 -54
- package/forms/select/src/select.component.d.ts +67 -64
- package/forms/textarea/src/textarea.component.d.ts +40 -43
- package/modules/authom/authom.configuration.d.ts +17 -0
- package/modules/authom/authom.interceptor.d.ts +3 -0
- package/modules/authom/authom.module.d.ts +16 -0
- package/modules/authom/authom.service.d.ts +32 -0
- package/modules/authom/index.d.ts +35 -0
- package/modules/index.d.ts +2 -1
- package/modules/keycloak/index.d.ts +4 -0
- package/modules/keycloak/keycloak.configuration.d.ts +11 -0
- package/modules/keycloak/keycloak.interceptor.d.ts +2 -0
- package/modules/keycloak/keycloak.module.d.ts +18 -0
- package/modules/keycloak/keycloak.service.d.ts +14 -0
- package/modules/layout/components/index.d.ts +2 -0
- package/modules/layout/components/layout-main/layout-main.component.d.ts +8 -12
- package/modules/layout/components/page/page.component.d.ts +5 -7
- package/modules/layout/components/sidebar-mobile-v1/components/sidebar/sidebar.component.d.ts +35 -0
- package/modules/layout/components/sidebar-mobile-v1/components/user/user.component.d.ts +24 -0
- package/modules/layout/components/sidebar-mobile-v1/main.component.d.ts +21 -0
- package/modules/layout/components/sidebar-v1/components/sidebar/sidebar.component.d.ts +22 -29
- package/modules/layout/components/sidebar-v1/components/user/user.component.d.ts +11 -17
- package/modules/layout/components/sidebar-v1/main.component.d.ts +14 -14
- package/modules/layout/configurations/layout.configuration.d.ts +46 -3
- package/modules/layout/modules/forbidden/pages/root/root.component.d.ts +3 -8
- package/modules/layout/modules/home/components/home-page/home-page.component.d.ts +2 -5
- package/modules/layout/modules/not-found/pages/root/root.component.d.ts +3 -8
- package/modules/layout/pipes/high-light-search.pipe.d.ts +1 -1
- package/modules/layout/services/index.d.ts +1 -0
- package/modules/layout/services/layout.service.d.ts +10 -0
- package/modules/layout/services/menu/menu.model.d.ts +4 -1
- package/modules/layout/services/storage/storage.service.d.ts +0 -3
- package/modules/permission/src/configurations/permission.configuration.d.ts +56 -2
- package/modules/permission/src/directives/permission.directive.d.ts +5 -8
- package/modules/permission/src/guards/permission.guard.d.ts +2 -1
- package/modules/permission/src/services/permission.service.d.ts +6 -9
- package/package.json +93 -69
- package/public-api.d.ts +0 -1
- package/sd-angular-core-19.0.0-beta.80.tgz +0 -0
- package/services/api/src/api.model.d.ts +6 -1
- package/services/confirm/src/lib/confirm.service.d.ts +5 -0
- package/services/docx/index.d.ts +1 -0
- package/services/docx/src/lib/docx.model.d.ts +9 -0
- package/services/docx/src/lib/docx.service.d.ts +13 -0
- package/services/docx/src/public-api.d.ts +2 -0
- package/services/index.d.ts +1 -0
- package/services/notify/index.d.ts +1 -0
- package/services/notify/src/notify.model.d.ts +1 -1
- package/services/notify/src/notify.service.d.ts +5 -5
- package/utilities/extensions/src/string.extension.d.ts +3 -0
- package/utilities/extensions/src/utility.extension.d.ts +1 -0
- package/utilities/models/index.d.ts +3 -0
- package/utilities/models/src/filter.model.d.ts +17 -4
- package/utilities/models/src/icon.model.d.ts +2 -0
- package/utilities/models/src/nested-key-of.model.d.ts +5 -0
- package/utilities/models/src/order.model.d.ts +2 -1
- package/utilities/models/src/paging.model.d.ts +2 -1
- package/utilities/models/src/pattern.model.d.ts +1 -1
- package/utilities/models/src/unwrap-signal.model.d.ts +6 -0
- package/components/document-builder/src/plugins/comment/comment.plugin.d.ts +0 -4
- package/components/document-builder/src/plugins/table-fit/table-fit.plugin.d.ts +0 -4
- package/components/modal/src/modal/modal.component.d.ts +0 -31
- package/components/table/src/components/desktop-cell-view/desktop-cell-view.component.d.ts +0 -14
- package/fesm2022/sd-angular-core-guards-permission.mjs +0 -155
- package/fesm2022/sd-angular-core-guards-permission.mjs.map +0 -1
- package/fesm2022/sd-angular-core-guards.mjs +0 -6
- package/fesm2022/sd-angular-core-guards.mjs.map +0 -1
- package/fesm2022/sd-angular-core-modules-oidc.mjs +0 -127
- package/fesm2022/sd-angular-core-modules-oidc.mjs.map +0 -1
- package/guards/index.d.ts +0 -1
- package/guards/permission/index.d.ts +0 -4
- package/guards/permission/src/configurations/index.d.ts +0 -1
- package/guards/permission/src/configurations/permission.configuration.d.ts +0 -8
- package/guards/permission/src/directives/index.d.ts +0 -1
- package/guards/permission/src/directives/permission.directive.d.ts +0 -12
- package/guards/permission/src/guards/index.d.ts +0 -1
- package/guards/permission/src/guards/permission.guard.d.ts +0 -13
- package/guards/permission/src/services/index.d.ts +0 -1
- package/guards/permission/src/services/permission.service.d.ts +0 -15
- package/modules/oidc/dynamic-sts.loader.d.ts +0 -11
- package/modules/oidc/index.d.ts +0 -2
- package/modules/oidc/oidc.configuration.d.ts +0 -11
- package/modules/oidc/oidc.module.d.ts +0 -14
- package/sd-angular-core-19.0.0-beta.8.tgz +0 -0
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { InjectionToken, Injectable, inject, provideAppInitializer, makeEnvironmentProviders, APP_INITIALIZER, NgModule } from '@angular/core';
|
|
3
|
+
import Keycloak from 'keycloak-js';
|
|
4
|
+
import { from, switchMap } from 'rxjs';
|
|
5
|
+
|
|
6
|
+
const SD_KEYCLOAK_CONFIGURATION = new InjectionToken('sd-keycloak.configuration');
|
|
7
|
+
|
|
8
|
+
class SdKeycloakService {
|
|
9
|
+
keycloak;
|
|
10
|
+
config;
|
|
11
|
+
async init(config) {
|
|
12
|
+
this.config = config;
|
|
13
|
+
// 1. Khởi tạo instance
|
|
14
|
+
this.keycloak = new Keycloak({
|
|
15
|
+
url: config.url,
|
|
16
|
+
realm: config.realm,
|
|
17
|
+
clientId: config.clientId,
|
|
18
|
+
});
|
|
19
|
+
// 2. Lắng nghe sự kiện hết hạn token để tự động làm mới ngầm
|
|
20
|
+
this.keycloak.onTokenExpired = () => {
|
|
21
|
+
this.keycloak.updateToken(30).catch(() => {
|
|
22
|
+
console.warn('Không thể làm mới token. Yêu cầu đăng nhập lại.');
|
|
23
|
+
this.keycloak.login();
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
// 3. Thực thi quá trình boot Keycloak
|
|
27
|
+
return this.keycloak.init({
|
|
28
|
+
onLoad: 'check-sso',
|
|
29
|
+
silentCheckSsoRedirectUri: window.location.origin + '/silent-renew.html',
|
|
30
|
+
checkLoginIframe: false, // Tắt check Iframe để chống lỗi vòng lặp
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
// Tiện ích nhanh cho Dev sử dụng
|
|
34
|
+
login() { return this.keycloak.login(); }
|
|
35
|
+
logout() { return this.keycloak.logout({ redirectUri: window.location.origin }); }
|
|
36
|
+
getToken() { return this.keycloak.token; }
|
|
37
|
+
getIsAuthenticated() { return this.keycloak.authenticated; }
|
|
38
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.17", ngImport: i0, type: SdKeycloakService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
39
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.17", ngImport: i0, type: SdKeycloakService, providedIn: 'root' });
|
|
40
|
+
}
|
|
41
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.17", ngImport: i0, type: SdKeycloakService, decorators: [{
|
|
42
|
+
type: Injectable,
|
|
43
|
+
args: [{ providedIn: 'root' }]
|
|
44
|
+
}] });
|
|
45
|
+
|
|
46
|
+
const SdKeycloakInterceptor = (req, next) => {
|
|
47
|
+
const keycloakService = inject(SdKeycloakService);
|
|
48
|
+
const { keycloak, config } = keycloakService;
|
|
49
|
+
// Nếu chưa init xong hoặc chưa đăng nhập -> cho request đi qua bình thường
|
|
50
|
+
if (!keycloak || !keycloak.authenticated || !config) {
|
|
51
|
+
return next(req);
|
|
52
|
+
}
|
|
53
|
+
// Kiểm tra xem URL của request có nằm trong mảng secureRoutes không
|
|
54
|
+
const isSecure = config.secureRoutes?.some(route => req.url.includes(route));
|
|
55
|
+
if (!isSecure) {
|
|
56
|
+
return next(req);
|
|
57
|
+
}
|
|
58
|
+
// Đảm bảo token luôn hợp lệ (cập nhật nếu token sẽ hết hạn trong 30s tới)
|
|
59
|
+
return from(keycloak.updateToken(30)).pipe(switchMap(() => {
|
|
60
|
+
const authReq = req.clone({
|
|
61
|
+
headers: req.headers.set('Authorization', `Bearer ${keycloak.token}`)
|
|
62
|
+
});
|
|
63
|
+
return next(authReq);
|
|
64
|
+
}));
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
// =======================================================================
|
|
68
|
+
// CÁCH 1: Dùng cho Angular 19 Standalone (Gọi trong app.config.ts)
|
|
69
|
+
// =======================================================================
|
|
70
|
+
function provideSdKeycloak(options) {
|
|
71
|
+
// FIX 1: Khai báo mảng nhận cả Provider (cho Service/Token) lẫn EnvironmentProviders (cho AppInitializer)
|
|
72
|
+
const providers = [SdKeycloakService];
|
|
73
|
+
if (options.useFactory) {
|
|
74
|
+
providers.push({ provide: SD_KEYCLOAK_CONFIGURATION, useFactory: options.useFactory, deps: options.deps || [] });
|
|
75
|
+
}
|
|
76
|
+
else if (options.useClass) {
|
|
77
|
+
providers.push({ provide: SD_KEYCLOAK_CONFIGURATION, useClass: options.useClass });
|
|
78
|
+
}
|
|
79
|
+
// Standalone dùng được provideAppInitializer ngon lành
|
|
80
|
+
providers.push(provideAppInitializer(() => {
|
|
81
|
+
const configLoader = inject(SD_KEYCLOAK_CONFIGURATION);
|
|
82
|
+
const keycloakService = inject(SdKeycloakService);
|
|
83
|
+
return configLoader.loadTenantConfig().then((config) => keycloakService.init(config));
|
|
84
|
+
}));
|
|
85
|
+
return makeEnvironmentProviders(providers);
|
|
86
|
+
}
|
|
87
|
+
// =======================================================================
|
|
88
|
+
// CÁCH 2: Dùng cho kiến trúc NgModule cũ (Backward Compatibility)
|
|
89
|
+
// =======================================================================
|
|
90
|
+
class SdKeycloakModule {
|
|
91
|
+
static forRoot(options) {
|
|
92
|
+
return {
|
|
93
|
+
ngModule: SdKeycloakModule,
|
|
94
|
+
providers: [
|
|
95
|
+
SdKeycloakService,
|
|
96
|
+
...(options.useFactory
|
|
97
|
+
? [{ provide: SD_KEYCLOAK_CONFIGURATION, useFactory: options.useFactory, deps: options.deps || [] }]
|
|
98
|
+
: [{ provide: SD_KEYCLOAK_CONFIGURATION, useClass: options.useClass }]),
|
|
99
|
+
// FIX 2: NgModule bắt buộc phải dùng APP_INITIALIZER (nhưng viết kiểu xịn của Angular 14+, dùng inject)
|
|
100
|
+
{
|
|
101
|
+
provide: APP_INITIALIZER,
|
|
102
|
+
multi: true,
|
|
103
|
+
useFactory: () => {
|
|
104
|
+
const configLoader = inject(SD_KEYCLOAK_CONFIGURATION);
|
|
105
|
+
const keycloakService = inject(SdKeycloakService);
|
|
106
|
+
return () => configLoader.loadTenantConfig().then((config) => keycloakService.init(config));
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
]
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.17", ngImport: i0, type: SdKeycloakModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
113
|
+
static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "19.2.17", ngImport: i0, type: SdKeycloakModule });
|
|
114
|
+
static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "19.2.17", ngImport: i0, type: SdKeycloakModule });
|
|
115
|
+
}
|
|
116
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.17", ngImport: i0, type: SdKeycloakModule, decorators: [{
|
|
117
|
+
type: NgModule,
|
|
118
|
+
args: [{}]
|
|
119
|
+
}] });
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Generated bundle index. Do not edit.
|
|
123
|
+
*/
|
|
124
|
+
|
|
125
|
+
export { SD_KEYCLOAK_CONFIGURATION, SdKeycloakInterceptor, SdKeycloakModule, SdKeycloakService, provideSdKeycloak };
|
|
126
|
+
//# sourceMappingURL=sd-angular-core-modules-keycloak.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sd-angular-core-modules-keycloak.mjs","sources":["../../../projects/sd-angular/modules/keycloak/keycloak.configuration.ts","../../../projects/sd-angular/modules/keycloak/keycloak.service.ts","../../../projects/sd-angular/modules/keycloak/keycloak.interceptor.ts","../../../projects/sd-angular/modules/keycloak/keycloak.module.ts","../../../projects/sd-angular/modules/keycloak/sd-angular-core-modules-keycloak.ts"],"sourcesContent":["import { InjectionToken } from '@angular/core';\r\n\r\nexport interface SdKeycloakTenantConfig {\r\n url: string;\r\n realm: string;\r\n clientId: string;\r\n secureRoutes?: string[]; // Các API cần đính token (vd: ['/api/v1'])\r\n}\r\n\r\nexport interface ISdKeycloakConfiguration {\r\n loadTenantConfig: () => Promise<SdKeycloakTenantConfig>;\r\n}\r\n\r\nexport const SD_KEYCLOAK_CONFIGURATION = new InjectionToken<ISdKeycloakConfiguration>('sd-keycloak.configuration');","import { Injectable } from '@angular/core';\r\nimport Keycloak from 'keycloak-js'; // Import trực tiếp SDK gốc của Keycloak\r\nimport { SdKeycloakTenantConfig } from './keycloak.configuration';\r\n\r\n@Injectable({ providedIn: 'root' })\r\nexport class SdKeycloakService {\r\n public keycloak!: Keycloak;\r\n public config!: SdKeycloakTenantConfig;\r\n\r\n async init(config: SdKeycloakTenantConfig): Promise<boolean> {\r\n this.config = config;\r\n \r\n // 1. Khởi tạo instance\r\n this.keycloak = new Keycloak({\r\n url: config.url,\r\n realm: config.realm,\r\n clientId: config.clientId,\r\n });\r\n\r\n // 2. Lắng nghe sự kiện hết hạn token để tự động làm mới ngầm\r\n this.keycloak.onTokenExpired = () => {\r\n this.keycloak.updateToken(30).catch(() => {\r\n console.warn('Không thể làm mới token. Yêu cầu đăng nhập lại.');\r\n this.keycloak.login();\r\n });\r\n };\r\n\r\n // 3. Thực thi quá trình boot Keycloak\r\n return this.keycloak.init({\r\n onLoad: 'check-sso',\r\n silentCheckSsoRedirectUri: window.location.origin + '/silent-renew.html',\r\n checkLoginIframe: false, // Tắt check Iframe để chống lỗi vòng lặp\r\n });\r\n }\r\n\r\n // Tiện ích nhanh cho Dev sử dụng\r\n login() { return this.keycloak.login(); }\r\n logout() { return this.keycloak.logout({ redirectUri: window.location.origin }); }\r\n getToken() { return this.keycloak.token; }\r\n getIsAuthenticated() { return this.keycloak.authenticated; }\r\n}","import { HttpInterceptorFn } from '@angular/common/http';\r\nimport { inject } from '@angular/core';\r\nimport { from, switchMap } from 'rxjs';\r\nimport { SdKeycloakService } from './keycloak.service';\r\n\r\nexport const SdKeycloakInterceptor: HttpInterceptorFn = (req, next) => {\r\n const keycloakService = inject(SdKeycloakService);\r\n const { keycloak, config } = keycloakService;\r\n\r\n // Nếu chưa init xong hoặc chưa đăng nhập -> cho request đi qua bình thường\r\n if (!keycloak || !keycloak.authenticated || !config) {\r\n return next(req);\r\n }\r\n\r\n // Kiểm tra xem URL của request có nằm trong mảng secureRoutes không\r\n const isSecure = config.secureRoutes?.some(route => req.url.includes(route));\r\n if (!isSecure) {\r\n return next(req);\r\n }\r\n\r\n // Đảm bảo token luôn hợp lệ (cập nhật nếu token sẽ hết hạn trong 30s tới)\r\n return from(keycloak.updateToken(30)).pipe(\r\n switchMap(() => {\r\n const authReq = req.clone({\r\n headers: req.headers.set('Authorization', `Bearer ${keycloak.token}`)\r\n });\r\n return next(authReq);\r\n })\r\n );\r\n};","import { \r\n ModuleWithProviders, \r\n NgModule, \r\n Provider, \r\n Type, \r\n EnvironmentProviders, \r\n makeEnvironmentProviders, \r\n provideAppInitializer, \r\n inject,\r\n APP_INITIALIZER\r\n} from '@angular/core';\r\nimport { ISdKeycloakConfiguration, SD_KEYCLOAK_CONFIGURATION } from './keycloak.configuration';\r\nimport { SdKeycloakService } from './keycloak.service';\r\n\r\n// =======================================================================\r\n// CÁCH 1: Dùng cho Angular 19 Standalone (Gọi trong app.config.ts)\r\n// =======================================================================\r\nexport function provideSdKeycloak(options: {\r\n useClass?: Type<ISdKeycloakConfiguration>;\r\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\r\n useFactory?: (...args: any[]) => ISdKeycloakConfiguration;\r\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\r\n deps?: any[];\r\n}): EnvironmentProviders {\r\n \r\n // FIX 1: Khai báo mảng nhận cả Provider (cho Service/Token) lẫn EnvironmentProviders (cho AppInitializer)\r\n const providers: Array<Provider | EnvironmentProviders> = [SdKeycloakService];\r\n\r\n if (options.useFactory) {\r\n providers.push({ provide: SD_KEYCLOAK_CONFIGURATION, useFactory: options.useFactory, deps: options.deps || [] });\r\n } else if (options.useClass) {\r\n providers.push({ provide: SD_KEYCLOAK_CONFIGURATION, useClass: options.useClass });\r\n }\r\n\r\n // Standalone dùng được provideAppInitializer ngon lành\r\n providers.push(\r\n provideAppInitializer(() => {\r\n const configLoader = inject(SD_KEYCLOAK_CONFIGURATION);\r\n const keycloakService = inject(SdKeycloakService);\r\n return configLoader.loadTenantConfig().then((config) => keycloakService.init(config));\r\n })\r\n );\r\n\r\n return makeEnvironmentProviders(providers);\r\n}\r\n\r\n// =======================================================================\r\n// CÁCH 2: Dùng cho kiến trúc NgModule cũ (Backward Compatibility)\r\n// =======================================================================\r\n@NgModule({})\r\nexport class SdKeycloakModule {\r\n static forRoot(options: {\r\n useClass?: Type<ISdKeycloakConfiguration>;\r\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\r\n useFactory?: (...args: any[]) => ISdKeycloakConfiguration;\r\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\r\n deps?: any[];\r\n }): ModuleWithProviders<SdKeycloakModule> {\r\n \r\n return {\r\n ngModule: SdKeycloakModule,\r\n providers: [\r\n SdKeycloakService,\r\n ...(options.useFactory \r\n ? [{ provide: SD_KEYCLOAK_CONFIGURATION, useFactory: options.useFactory, deps: options.deps || [] }]\r\n : [{ provide: SD_KEYCLOAK_CONFIGURATION, useClass: options.useClass! }]\r\n ),\r\n \r\n // FIX 2: NgModule bắt buộc phải dùng APP_INITIALIZER (nhưng viết kiểu xịn của Angular 14+, dùng inject)\r\n {\r\n provide: APP_INITIALIZER,\r\n multi: true,\r\n useFactory: () => {\r\n const configLoader = inject(SD_KEYCLOAK_CONFIGURATION);\r\n const keycloakService = inject(SdKeycloakService);\r\n return () => configLoader.loadTenantConfig().then((config) => keycloakService.init(config));\r\n }\r\n }\r\n ]\r\n };\r\n }\r\n}","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;MAaa,yBAAyB,GAAG,IAAI,cAAc,CAA2B,2BAA2B;;MCRpG,iBAAiB,CAAA;AACrB,IAAA,QAAQ;AACR,IAAA,MAAM;IAEb,MAAM,IAAI,CAAC,MAA8B,EAAA;AACvC,QAAA,IAAI,CAAC,MAAM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