@codex-ts/core-lib 1.1.3 → 1.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -5,11 +5,10 @@ import { isPlatformBrowser, CommonModule, formatDate } from '@angular/common';
|
|
|
5
5
|
import Keycloak from 'keycloak-js';
|
|
6
6
|
import * as i1 from '@angular/common/http';
|
|
7
7
|
import { HTTP_INTERCEPTORS, HttpClientModule, HttpParams } from '@angular/common/http';
|
|
8
|
-
import { from, mergeMap, catchError, throwError,
|
|
8
|
+
import { from, mergeMap, catchError, throwError, Observable, BehaviorSubject, finalize, forkJoin, of, isObservable, Subject, take as take$1, tap as tap$1, map as map$1, takeUntil as takeUntil$1, ReplaySubject, distinctUntilChanged as distinctUntilChanged$1 } from 'rxjs';
|
|
9
9
|
import * as i1$3 from '@angular/router';
|
|
10
10
|
import { Router } from '@angular/router';
|
|
11
|
-
import {
|
|
12
|
-
import { retry, timeout, catchError as catchError$1, take, map as map$1, finalize as finalize$1, switchMap, takeUntil, mergeMap as mergeMap$1, tap, debounceTime, distinctUntilChanged } from 'rxjs/operators';
|
|
11
|
+
import { retry, timeout, catchError as catchError$1, take, map, finalize as finalize$1, switchMap, takeUntil, mergeMap as mergeMap$1, tap, debounceTime, distinctUntilChanged } from 'rxjs/operators';
|
|
13
12
|
import * as i4 from 'primeng/api';
|
|
14
13
|
import * as i1$1 from '@angular/forms';
|
|
15
14
|
import { FormGroup, ReactiveFormsModule } from '@angular/forms';
|
|
@@ -323,21 +322,36 @@ class KeycloakAuthGuard {
|
|
|
323
322
|
keycloakService = inject(KeycloakService);
|
|
324
323
|
config = inject(KEYCLOAK_CONFIG);
|
|
325
324
|
router = inject(Router);
|
|
325
|
+
platformId = inject(PLATFORM_ID);
|
|
326
326
|
canActivate(route, state) {
|
|
327
|
-
return
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
const routeRoles = route.data['roles'];
|
|
334
|
-
const defaultRoles = this.config.options?.roles;
|
|
335
|
-
const requiredRoles = routeRoles || defaultRoles;
|
|
336
|
-
if (requiredRoles?.length && !this.hasRequiredRoles(requiredRoles)) {
|
|
337
|
-
return this.router.createUrlTree(['/unauthorized']);
|
|
327
|
+
return new Observable(subscriber => {
|
|
328
|
+
// In SSR, default to not authenticated
|
|
329
|
+
if (!isPlatformBrowser(this.platformId)) {
|
|
330
|
+
subscriber.next(false);
|
|
331
|
+
subscriber.complete();
|
|
332
|
+
return;
|
|
338
333
|
}
|
|
339
|
-
|
|
340
|
-
|
|
334
|
+
const authenticated = this.keycloakService.isAuthenticated$();
|
|
335
|
+
subscriber.next(this.processAuthentication(authenticated, route, state));
|
|
336
|
+
subscriber.complete();
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
processAuthentication(authenticated, route, state) {
|
|
340
|
+
if (!authenticated) {
|
|
341
|
+
const redirectUri = isPlatformBrowser(this.platformId)
|
|
342
|
+
? window.location.origin + state.url
|
|
343
|
+
: state.url;
|
|
344
|
+
this.keycloakService.login({ redirectUri });
|
|
345
|
+
return false;
|
|
346
|
+
}
|
|
347
|
+
// Check for route-specific roles first, then fallback to default roles
|
|
348
|
+
const routeRoles = route.data['roles'];
|
|
349
|
+
const defaultRoles = this.config.options?.roles;
|
|
350
|
+
const requiredRoles = routeRoles || defaultRoles;
|
|
351
|
+
if (requiredRoles?.length && !this.hasRequiredRoles(requiredRoles)) {
|
|
352
|
+
return this.router.createUrlTree(['/unauthorized']);
|
|
353
|
+
}
|
|
354
|
+
return true;
|
|
341
355
|
}
|
|
342
356
|
hasRequiredRoles(roles) {
|
|
343
357
|
return roles.every(role => this.keycloakService.hasRole(role));
|
|
@@ -1102,7 +1116,7 @@ class FormService {
|
|
|
1102
1116
|
return of(void 0);
|
|
1103
1117
|
}
|
|
1104
1118
|
this.formState.loading = true;
|
|
1105
|
-
return this.entityService.getById(uuid).pipe(take(1), map
|
|
1119
|
+
return this.entityService.getById(uuid).pipe(take(1), map(data => {
|
|
1106
1120
|
this.updateFormState(data);
|
|
1107
1121
|
}), finalize$1(() => this.formState.loading = false));
|
|
1108
1122
|
}
|
|
@@ -1122,7 +1136,7 @@ class FormService {
|
|
|
1122
1136
|
}
|
|
1123
1137
|
this.formState.loading = true;
|
|
1124
1138
|
const operation$ = this.getSubmitOperation();
|
|
1125
|
-
return operation$.pipe(finalize$1(() => this.formState.loading = false), map
|
|
1139
|
+
return operation$.pipe(finalize$1(() => this.formState.loading = false), map(result => {
|
|
1126
1140
|
this.notificationService.showSuccess(`${this.entityName} ${AppMessages.FORM.SUCCESS.SAVE}`);
|
|
1127
1141
|
return result;
|
|
1128
1142
|
}));
|
|
@@ -1861,7 +1875,7 @@ class BaseFormComponent extends BasePageComponent {
|
|
|
1861
1875
|
});
|
|
1862
1876
|
}
|
|
1863
1877
|
initializeForm() {
|
|
1864
|
-
return this.route.queryParams.pipe(take(1), map
|
|
1878
|
+
return this.route.queryParams.pipe(take(1), map(params => {
|
|
1865
1879
|
this.initializeFormMode(params[AppConstants.FORM.MODE]);
|
|
1866
1880
|
this.setupFormState();
|
|
1867
1881
|
this.initializeFormSubscriptions();
|
|
@@ -1882,7 +1896,7 @@ class BaseFormComponent extends BasePageComponent {
|
|
|
1882
1896
|
throw new Error(`UUID is required for ${this.state.mode} mode`);
|
|
1883
1897
|
}
|
|
1884
1898
|
return this.getEntityOperations().getById(uuid)
|
|
1885
|
-
.pipe(tap(data => this.updateFormState(data)), map
|
|
1899
|
+
.pipe(tap(data => this.updateFormState(data)), map(() => void 0));
|
|
1886
1900
|
}));
|
|
1887
1901
|
}
|
|
1888
1902
|
getRouterState() {
|
|
@@ -2461,7 +2475,7 @@ class BaseTabbedFormComponent extends BasePageComponent {
|
|
|
2461
2475
|
activeTab: tabs[0]?.value || ''
|
|
2462
2476
|
};
|
|
2463
2477
|
// Then initialize form
|
|
2464
|
-
this.route.queryParams.pipe(take$1(1), tap$1(() => this.state = { ...this.state, loading: true }), tap$1(params => this.initializeForm(params)), map(() => void 0), catchError(error => {
|
|
2478
|
+
this.route.queryParams.pipe(take$1(1), tap$1(() => this.state = { ...this.state, loading: true }), tap$1(params => this.initializeForm(params)), map$1(() => void 0), catchError(error => {
|
|
2465
2479
|
console.error('Error initializing form:', error);
|
|
2466
2480
|
this.showError(AppMessages.FORM.ERROR.INIT);
|
|
2467
2481
|
return of(void 0);
|
|
@@ -2517,7 +2531,7 @@ class BaseTabbedFormComponent extends BasePageComponent {
|
|
|
2517
2531
|
}
|
|
2518
2532
|
}
|
|
2519
2533
|
loadFromUuid() {
|
|
2520
|
-
this.route.queryParams.pipe(take$1(1), map((params) => {
|
|
2534
|
+
this.route.queryParams.pipe(take$1(1), map$1((params) => {
|
|
2521
2535
|
const uuid = params[AppConstants.FORM.UUID];
|
|
2522
2536
|
if (!uuid) {
|
|
2523
2537
|
throw new Error(`UUID is required for ${this.state.mode} mode when no formData is provided`);
|
|
@@ -2905,7 +2919,7 @@ class BaseTaskDetailsComponent extends BasePageComponent {
|
|
|
2905
2919
|
this.formlyConfigService = formlyConfigService;
|
|
2906
2920
|
}
|
|
2907
2921
|
initializeServices() {
|
|
2908
|
-
return of(void 0).pipe(map
|
|
2922
|
+
return of(void 0).pipe(map(() => {
|
|
2909
2923
|
this.formService = new FormService(this.getEntityService(), this.formlyConfigService, this.notificationService, this.getEntityName(), this.getJsonFields(), this.getDropdownOptions());
|
|
2910
2924
|
this.state = this.formService.getState();
|
|
2911
2925
|
this.loading = this.state.loading;
|
|
@@ -2920,7 +2934,7 @@ class BaseTaskDetailsComponent extends BasePageComponent {
|
|
|
2920
2934
|
});
|
|
2921
2935
|
}
|
|
2922
2936
|
initializeFromRoute() {
|
|
2923
|
-
return this.route.queryParams.pipe(map
|
|
2937
|
+
return this.route.queryParams.pipe(map(params => {
|
|
2924
2938
|
const mode = params[AppConstants.FORM.MODE];
|
|
2925
2939
|
if (mode) {
|
|
2926
2940
|
this.formService.setMode(mode);
|