@nettyapps/ntybase 21.0.23 → 21.0.25

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.
@@ -9,8 +9,6 @@ import * as i2$1 from '@nettyapps/ntycontract';
9
9
  import { EnvironmentProxy } from '@nettyapps/ntycontract';
10
10
  import { DatePipe, Location, DecimalPipe } from '@angular/common';
11
11
  import { toSignal } from '@angular/core/rxjs-interop';
12
- import * as i1$1 from '@ngx-translate/core';
13
- import { TranslateModule, TranslateService } from '@ngx-translate/core';
14
12
  import { Buffer } from 'buffer';
15
13
  import * as i1 from '@angular/material/dialog';
16
14
  import { MAT_DIALOG_DATA, MatDialogModule, MatDialog, MatDialogRef } from '@angular/material/dialog';
@@ -20,6 +18,8 @@ import * as i2 from '@angular/material/icon';
20
18
  import { MatIconModule } from '@angular/material/icon';
21
19
  import * as i1$2 from '@angular/material/snack-bar';
22
20
  import { MatSnackBarModule } from '@angular/material/snack-bar';
21
+ import * as i1$1 from '@ngx-translate/core';
22
+ import { TranslateModule, TranslateService } from '@ngx-translate/core';
23
23
  import { Mutex } from 'async-mutex';
24
24
  import { ModuleRegistry, AllCommunityModule, ClientSideRowModelModule, HighlightChangesModule, themeQuartz } from 'ag-grid-community';
25
25
  import { StatusBarModule, ClipboardModule, ExcelExportModule, ColumnMenuModule, ContextMenuModule, CellSelectionModule, RowSelectionModule } from 'ag-grid-enterprise';
@@ -1166,6 +1166,7 @@ class NettyAppsBase {
1166
1166
  // --- SERVICES ---
1167
1167
  // ---------------------------------
1168
1168
  alertService = inject(AlertService);
1169
+ translateService = inject(TranslateService);
1169
1170
  // ---------------------------------
1170
1171
  // --- DOWNLOAD METHODS ---
1171
1172
  // ---------------------------------
@@ -1365,7 +1366,6 @@ class NettyAgGridBase extends NettyAppsBase {
1365
1366
  openInPopup = signal(false, ...(ngDevMode ? [{ debugName: "openInPopup" }] : []));
1366
1367
  // Services
1367
1368
  nettyAgGridService = inject(NettyAgGridService);
1368
- translateService = inject(TranslateService);
1369
1369
  commonService = inject(CommonService);
1370
1370
  router = inject(Router);
1371
1371
  routerActive = inject(ActivatedRoute);
@@ -3053,6 +3053,96 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.6", ngImpor
3053
3053
  args: [{ providedIn: 'root' }]
3054
3054
  }] });
3055
3055
 
3056
+ /**
3057
+ * Nty Authentication Interceptor. This interceptor is used to intercept HTTP requests and add authentication headers.
3058
+ * It's coded as functional interceptor for better performance.
3059
+ * @param req
3060
+ * @param next
3061
+ * @returns
3062
+ */
3063
+ const ntyAuthenticationInterceptor = (req, next) => {
3064
+ const router = inject(Router);
3065
+ const credentialsService = inject(CredentialsService);
3066
+ const environmentProxy = inject(EnvironmentProxy);
3067
+ const urlHelperService = inject(UrlHelperService);
3068
+ if (req.headers.get('No-Auth') == 'True')
3069
+ return next(req.clone());
3070
+ let token = credentialsService.token;
3071
+ if (token != null) {
3072
+ let appName = environmentProxy.getApplicationName();
3073
+ const clonedreq = req.clone({
3074
+ headers: req.headers.set('Authorization', 'Bearer ' + token)
3075
+ // .set("NettyAppName",appName)
3076
+ });
3077
+ return next(clonedreq).pipe(catchError((error) => {
3078
+ if (error instanceof HttpErrorResponse && error.status === 401) {
3079
+ // Handle 401 error, e.g., navigate to the login page
3080
+ router.navigate(['/login'], {
3081
+ queryParams: {
3082
+ redirect: urlHelperService.cleanUrl(router.url),
3083
+ },
3084
+ replaceUrl: true,
3085
+ });
3086
+ // Return an observable with a successful response
3087
+ return of(new HttpResponse({ status: 200, body: { message: 'Success' } }));
3088
+ }
3089
+ if (error instanceof HttpErrorResponse && error.status === 403) {
3090
+ router.navigate(['/forbidden'], {
3091
+ state: { attemptedUrl: router.url }, // Orijinal URL'i state olarak geçme
3092
+ });
3093
+ return of(new HttpResponse({ status: 200, body: { message: 'Success' } }));
3094
+ }
3095
+ if (error instanceof HttpErrorResponse && error.status === 428) {
3096
+ // Handle 428 error, e.g., navigate to the login page
3097
+ router.navigate(['/mfalogin'], {
3098
+ queryParams: {
3099
+ redirect: urlHelperService.cleanUrl(router.url),
3100
+ },
3101
+ replaceUrl: true,
3102
+ });
3103
+ // Return an observable with a successful response
3104
+ return of(new HttpResponse({ status: 200, body: { message: 'Success' } }));
3105
+ }
3106
+ // For other errors, re-throw the error to propagate it further
3107
+ return throwError(() => error);
3108
+ }));
3109
+ }
3110
+ else {
3111
+ return next(req.clone()).pipe(catchError((error) => {
3112
+ if (error instanceof HttpErrorResponse && error.status === 401) {
3113
+ // Handle 401 error, e.g., navigate to the login page
3114
+ router.navigate(['/login'], {
3115
+ queryParams: {
3116
+ redirect: urlHelperService.cleanUrl(router.url),
3117
+ },
3118
+ replaceUrl: true,
3119
+ });
3120
+ // Return an observable with a successful response
3121
+ return of(new HttpResponse({ status: 200, body: { message: 'Success' } }));
3122
+ }
3123
+ if (error instanceof HttpErrorResponse && error.status === 403) {
3124
+ router.navigate(['/forbidden'], {
3125
+ state: { attemptedUrl: router.url }, // Orijinal URL'i state olarak geçme
3126
+ });
3127
+ return of(new HttpResponse({ status: 200, body: { message: 'Success' } }));
3128
+ }
3129
+ if (error instanceof HttpErrorResponse && error.status === 428) {
3130
+ // Handle 428 error, e.g., navigate to the login page
3131
+ router.navigate(['/mfalogin'], {
3132
+ queryParams: {
3133
+ redirect: urlHelperService.cleanUrl(router.url),
3134
+ },
3135
+ replaceUrl: true,
3136
+ });
3137
+ // Return an observable with a successful response
3138
+ return of(new HttpResponse({ status: 200, body: { message: 'Success' } }));
3139
+ }
3140
+ // For other errors, re-throw the error to propagate it further
3141
+ return throwError(() => error);
3142
+ }));
3143
+ }
3144
+ };
3145
+
3056
3146
  class LoginDto {
3057
3147
  userName = '';
3058
3148
  password = '';
@@ -3916,6 +4006,42 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.6", ngImpor
3916
4006
  type: Input
3917
4007
  }] } });
3918
4008
 
4009
+ class NtyLoadingService {
4010
+ requestCount = 0;
4011
+ isLoading = signal(false, ...(ngDevMode ? [{ debugName: "isLoading" }] : []));
4012
+ show() {
4013
+ this.requestCount++;
4014
+ if (this.requestCount > 0) {
4015
+ this.isLoading.set(true);
4016
+ }
4017
+ }
4018
+ hide() {
4019
+ this.requestCount--;
4020
+ if (this.requestCount <= 0) {
4021
+ this.requestCount = 0;
4022
+ this.isLoading.set(false);
4023
+ }
4024
+ }
4025
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: NtyLoadingService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
4026
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: NtyLoadingService, providedIn: 'root' });
4027
+ }
4028
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.6", ngImport: i0, type: NtyLoadingService, decorators: [{
4029
+ type: Injectable,
4030
+ args: [{
4031
+ providedIn: 'root',
4032
+ }]
4033
+ }] });
4034
+
4035
+ const NtyLoadingInterceptor = (req, next) => {
4036
+ const loadingService = inject(NtyLoadingService);
4037
+ // Optional: Skip specific URLs if needed (e.g. background polling)
4038
+ // if (req.url.includes('/silent-api')) return next(req);
4039
+ loadingService.show();
4040
+ return next(req).pipe(finalize(() => {
4041
+ loadingService.hide();
4042
+ }));
4043
+ };
4044
+
3919
4045
  class NettyMenuService {
3920
4046
  http = inject(HttpClient);
3921
4047
  environmentProxy = inject(EnvironmentProxy);
@@ -3965,5 +4091,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.6", ngImpor
3965
4091
  * Generated bundle index. Do not edit.
3966
4092
  */
3967
4093
 
3968
- export { AlertService, AuthenticationGuard, AuthenticationInterceptor, AuthenticationService, ButtonRenderer, CanDeactivateGuard, CheckboxRenderer, CommonService, ConfirmDialog, CredentialsService, CurrentUserPreference, ENVIRONMENT_CONFIG, EnvironmentInfo, EnvironmentInfoService, ExcelImportBase, ForgotPassword, Login, LoginDto, MFACodeDto, MfaLogin, NettyAgGridBase, NettyAgGridSaveBase, NettyAgGridService, NettyAppsBase, NettyBaseApp, NettyHelper, NettyImageService, NettyMenuService, Ntybase, NtybaseModule, RangeDateTimeFilter, RangeNumberFilter, RangeStringFilter, UrlHelperService };
4094
+ export { AlertService, AuthenticationGuard, AuthenticationInterceptor, AuthenticationService, ButtonRenderer, CanDeactivateGuard, CheckboxRenderer, CommonService, ConfirmDialog, CredentialsService, CurrentUserPreference, ENVIRONMENT_CONFIG, EnvironmentInfo, EnvironmentInfoService, ExcelImportBase, ForgotPassword, Login, LoginDto, MFACodeDto, MfaLogin, NettyAgGridBase, NettyAgGridSaveBase, NettyAgGridService, NettyAppsBase, NettyBaseApp, NettyHelper, NettyImageService, NettyMenuService, NtyLoadingInterceptor, Ntybase, NtybaseModule, RangeDateTimeFilter, RangeNumberFilter, RangeStringFilter, UrlHelperService, ntyAuthenticationInterceptor };
3969
4095
  //# sourceMappingURL=nettyapps-ntybase.mjs.map