@codex-ts/core-lib 1.1.2 → 1.1.4

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, map, BehaviorSubject, finalize, Observable, forkJoin, of, isObservable, Subject, take as take$1, tap as tap$1, takeUntil as takeUntil$1, ReplaySubject, distinctUntilChanged as distinctUntilChanged$1 } from 'rxjs';
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 { toObservable } from '@angular/core/rxjs-interop';
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';
@@ -324,20 +323,25 @@ class KeycloakAuthGuard {
324
323
  config = inject(KEYCLOAK_CONFIG);
325
324
  router = inject(Router);
326
325
  canActivate(route, state) {
327
- return toObservable(this.keycloakService.isAuthenticated$).pipe(map(authenticated => {
328
- if (!authenticated) {
329
- this.keycloakService.login({ redirectUri: window.location.origin + state.url });
330
- return false;
331
- }
332
- // Check for route-specific roles first, then fallback to default roles
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']);
338
- }
339
- return true;
340
- }));
326
+ return new Observable(subscriber => {
327
+ const authenticated = this.keycloakService.isAuthenticated$();
328
+ subscriber.next(this.processAuthentication(authenticated, route, state));
329
+ subscriber.complete();
330
+ });
331
+ }
332
+ processAuthentication(authenticated, route, state) {
333
+ if (!authenticated) {
334
+ this.keycloakService.login({ redirectUri: window.location.origin + state.url });
335
+ return false;
336
+ }
337
+ // Check for route-specific roles first, then fallback to default roles
338
+ const routeRoles = route.data['roles'];
339
+ const defaultRoles = this.config.options?.roles;
340
+ const requiredRoles = routeRoles || defaultRoles;
341
+ if (requiredRoles?.length && !this.hasRequiredRoles(requiredRoles)) {
342
+ return this.router.createUrlTree(['/unauthorized']);
343
+ }
344
+ return true;
341
345
  }
342
346
  hasRequiredRoles(roles) {
343
347
  return roles.every(role => this.keycloakService.hasRole(role));
@@ -1102,7 +1106,7 @@ class FormService {
1102
1106
  return of(void 0);
1103
1107
  }
1104
1108
  this.formState.loading = true;
1105
- return this.entityService.getById(uuid).pipe(take(1), map$1(data => {
1109
+ return this.entityService.getById(uuid).pipe(take(1), map(data => {
1106
1110
  this.updateFormState(data);
1107
1111
  }), finalize$1(() => this.formState.loading = false));
1108
1112
  }
@@ -1122,7 +1126,7 @@ class FormService {
1122
1126
  }
1123
1127
  this.formState.loading = true;
1124
1128
  const operation$ = this.getSubmitOperation();
1125
- return operation$.pipe(finalize$1(() => this.formState.loading = false), map$1(result => {
1129
+ return operation$.pipe(finalize$1(() => this.formState.loading = false), map(result => {
1126
1130
  this.notificationService.showSuccess(`${this.entityName} ${AppMessages.FORM.SUCCESS.SAVE}`);
1127
1131
  return result;
1128
1132
  }));
@@ -1861,7 +1865,7 @@ class BaseFormComponent extends BasePageComponent {
1861
1865
  });
1862
1866
  }
1863
1867
  initializeForm() {
1864
- return this.route.queryParams.pipe(take(1), map$1(params => {
1868
+ return this.route.queryParams.pipe(take(1), map(params => {
1865
1869
  this.initializeFormMode(params[AppConstants.FORM.MODE]);
1866
1870
  this.setupFormState();
1867
1871
  this.initializeFormSubscriptions();
@@ -1882,7 +1886,7 @@ class BaseFormComponent extends BasePageComponent {
1882
1886
  throw new Error(`UUID is required for ${this.state.mode} mode`);
1883
1887
  }
1884
1888
  return this.getEntityOperations().getById(uuid)
1885
- .pipe(tap(data => this.updateFormState(data)), map$1(() => void 0));
1889
+ .pipe(tap(data => this.updateFormState(data)), map(() => void 0));
1886
1890
  }));
1887
1891
  }
1888
1892
  getRouterState() {
@@ -2461,7 +2465,7 @@ class BaseTabbedFormComponent extends BasePageComponent {
2461
2465
  activeTab: tabs[0]?.value || ''
2462
2466
  };
2463
2467
  // 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 => {
2468
+ 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
2469
  console.error('Error initializing form:', error);
2466
2470
  this.showError(AppMessages.FORM.ERROR.INIT);
2467
2471
  return of(void 0);
@@ -2517,7 +2521,7 @@ class BaseTabbedFormComponent extends BasePageComponent {
2517
2521
  }
2518
2522
  }
2519
2523
  loadFromUuid() {
2520
- this.route.queryParams.pipe(take$1(1), map((params) => {
2524
+ this.route.queryParams.pipe(take$1(1), map$1((params) => {
2521
2525
  const uuid = params[AppConstants.FORM.UUID];
2522
2526
  if (!uuid) {
2523
2527
  throw new Error(`UUID is required for ${this.state.mode} mode when no formData is provided`);
@@ -2905,7 +2909,7 @@ class BaseTaskDetailsComponent extends BasePageComponent {
2905
2909
  this.formlyConfigService = formlyConfigService;
2906
2910
  }
2907
2911
  initializeServices() {
2908
- return of(void 0).pipe(map$1(() => {
2912
+ return of(void 0).pipe(map(() => {
2909
2913
  this.formService = new FormService(this.getEntityService(), this.formlyConfigService, this.notificationService, this.getEntityName(), this.getJsonFields(), this.getDropdownOptions());
2910
2914
  this.state = this.formService.getState();
2911
2915
  this.loading = this.state.loading;
@@ -2920,7 +2924,7 @@ class BaseTaskDetailsComponent extends BasePageComponent {
2920
2924
  });
2921
2925
  }
2922
2926
  initializeFromRoute() {
2923
- return this.route.queryParams.pipe(map$1(params => {
2927
+ return this.route.queryParams.pipe(map(params => {
2924
2928
  const mode = params[AppConstants.FORM.MODE];
2925
2929
  if (mode) {
2926
2930
  this.formService.setMode(mode);
@@ -3120,6 +3124,36 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImpor
3120
3124
  type: Directive
3121
3125
  }], ctorParameters: () => [{ type: i1$3.Router }, { type: NotificationService }, { type: UtilsService }, { type: i4.ConfirmationService }] });
3122
3126
 
3127
+ class ReferenceDataProviderService {
3128
+ endpoints = {};
3129
+ // Method to set/update endpoints
3130
+ setEndpoints(endpoints) {
3131
+ this.endpoints = { ...this.endpoints, ...endpoints };
3132
+ }
3133
+ getReferenceEndpoint(entityName) {
3134
+ console.log('getReferenceEndpoint', entityName, this.endpoints);
3135
+ let endpoint = this.endpoints[entityName];
3136
+ if (endpoint != null && endpoint.length > 0) {
3137
+ if (endpoint.startsWith('http://') || endpoint.startsWith('https://')) {
3138
+ return endpoint; // Absolute URL
3139
+ }
3140
+ else {
3141
+ // Relative URL, assume it's within the application's base context
3142
+ return endpoint;
3143
+ }
3144
+ }
3145
+ return null;
3146
+ }
3147
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: ReferenceDataProviderService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
3148
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: ReferenceDataProviderService, providedIn: 'root' });
3149
+ }
3150
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImport: i0, type: ReferenceDataProviderService, decorators: [{
3151
+ type: Injectable,
3152
+ args: [{
3153
+ providedIn: 'root'
3154
+ }]
3155
+ }] });
3156
+
3123
3157
  class IndianDatePipe {
3124
3158
  datePipe;
3125
3159
  constructor(datePipe) {
@@ -3174,5 +3208,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.6", ngImpor
3174
3208
  * Generated bundle index. Do not edit.
3175
3209
  */
3176
3210
 
3177
- export { AppConstants, AppMessages, BaseCrudService, BaseFormComponent, BaseListPageComponent, BaseListTabbedFormComponent, BasePageComponent, BaseTabbedFormComponent, BaseTaskDashboardComponent, BaseTaskDetailsComponent, BaseTaskService, ComponentContext, CoreFormlyModule, FormService, FormlyConfigService, HttpUtilityService, IndianDatePipe, KEYCLOAK_CONFIG, KeycloakAuthGuard, KeycloakService, NotificationService, TabbedFormType, TaskRole, UtilsService, provideKeycloak };
3211
+ export { AppConstants, AppMessages, BaseCrudService, BaseFormComponent, BaseListPageComponent, BaseListTabbedFormComponent, BasePageComponent, BaseTabbedFormComponent, BaseTaskDashboardComponent, BaseTaskDetailsComponent, BaseTaskService, ComponentContext, CoreFormlyModule, FormService, FormlyConfigService, HttpUtilityService, IndianDatePipe, KEYCLOAK_CONFIG, KeycloakAuthGuard, KeycloakService, NotificationService, ReferenceDataProviderService, TabbedFormType, TaskRole, UtilsService, provideKeycloak };
3178
3212
  //# sourceMappingURL=codex-ts-core-lib.mjs.map