@aakash58/chatbot 1.1.0 → 1.1.2

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.
@@ -1,12 +1,11 @@
1
1
  import * as i1$2 from '@angular/common';
2
2
  import { CommonModule } from '@angular/common';
3
- import * as i1 from '@angular/common/http';
4
- import { HttpHeaders, HttpErrorResponse, HttpEventType, HttpClient, provideHttpClient, HTTP_INTERCEPTORS, withInterceptorsFromDi } from '@angular/common/http';
5
3
  import * as i0 from '@angular/core';
6
- import { isDevMode, Injectable, signal, inject, effect, EventEmitter, Output, Input, Component, Pipe, ViewChild, Inject, HostListener, Directive, InjectionToken, computed, ChangeDetectionStrategy, ChangeDetectorRef, ElementRef, ViewEncapsulation, provideAppInitializer, ContentChildren } from '@angular/core';
7
- import { DomSanitizer, bootstrapApplication } from '@angular/platform-browser';
8
- import { ReplaySubject, delay, retry, map, catchError, of, BehaviorSubject, firstValueFrom, throwError, tap, switchMap, filter, take, Observable, Subject, lastValueFrom } from 'rxjs';
4
+ import { isDevMode, Injectable, signal, inject, effect, EventEmitter, Output, Input, Component, Pipe, ViewChild, Inject, HostListener, Directive, InjectionToken, computed, ChangeDetectionStrategy, ChangeDetectorRef, ElementRef, ViewEncapsulation, ContentChildren, makeEnvironmentProviders, APP_INITIALIZER } from '@angular/core';
5
+ import { ReplaySubject, delay, retry, map, catchError, of, BehaviorSubject, firstValueFrom, throwError, tap, Observable, Subject, lastValueFrom, switchMap, filter, take } from 'rxjs';
9
6
  import { JwtHelperService } from '@auth0/angular-jwt';
7
+ import * as i1 from '@angular/common/http';
8
+ import { HttpHeaders, HttpEventType, HttpClient, HttpErrorResponse, provideHttpClient, HTTP_INTERCEPTORS, withInterceptorsFromDi } from '@angular/common/http';
10
9
  import * as CryptoJS from 'crypto-js';
11
10
  import * as i4 from '@angular/router';
12
11
  import * as i1$1 from '@angular/cdk/overlay';
@@ -17,6 +16,7 @@ import * as i4$1 from '@angular/material/menu';
17
16
  import { MatMenuModule } from '@angular/material/menu';
18
17
  import * as i1$4 from '@angular/material/dialog';
19
18
  import { MAT_DIALOG_DATA, MatDialogModule, MatDialogRef, MatDialog } from '@angular/material/dialog';
19
+ import { DomSanitizer } from '@angular/platform-browser';
20
20
  import * as i2 from '@angular/material/button';
21
21
  import { MatButtonModule } from '@angular/material/button';
22
22
  import * as i1$5 from '@angular/forms';
@@ -824,97 +824,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.14", ngImpo
824
824
  }]
825
825
  }], ctorParameters: () => [{ type: AccountService }, { type: CryptoHelperService }, { type: StorageService }, { type: i4.Router }] });
826
826
 
827
- class AuthInterceptor {
828
- tokenStorage;
829
- injector;
830
- isRefreshing = false;
831
- clearingAuth = false; // Prevent multiple clearAuth calls
832
- refreshTokenSubject = new BehaviorSubject(null);
833
- constructor(tokenStorage, injector) {
834
- this.tokenStorage = tokenStorage;
835
- this.injector = injector;
836
- }
837
- intercept(req, next) {
838
- const authReq = this.getRequestWithHeaders(req);
839
- return next.handle(authReq).pipe(catchError((error) => {
840
- // Handle 401 Unauthorized errors
841
- if (error instanceof HttpErrorResponse &&
842
- error.status === 401 &&
843
- !authReq.url.includes('auth/login') && // Don't retry login
844
- !authReq.url.includes('auth/federated/login') && // Don't retry federated login
845
- !authReq.url.includes('auth/logout') && // Don't retry logout
846
- !authReq.url.includes('auth/refresh') // Don't retry refresh itself
847
- ) {
848
- Logger.error('[AuthInterceptor] 401 Unauthorized:', {
849
- url: authReq.url,
850
- userId: this.tokenStorage.get('user_id'),
851
- });
852
- return this.handle401Error(authReq, next);
853
- }
854
- return throwError(() => error);
855
- }));
856
- }
857
- handle401Error(request, next) {
858
- // If already clearing, don't retry
859
- if (this.clearingAuth) {
860
- Logger.log('[AuthInterceptor] Already clearing auth, rejecting request');
861
- return throwError(() => new Error('Authentication cleared'));
862
- }
863
- if (!this.isRefreshing) {
864
- this.isRefreshing = true;
865
- this.refreshTokenSubject.next(null);
866
- const authService = this.injector.get(AuthService);
867
- return authService.refreshToken().pipe(switchMap((token) => {
868
- this.isRefreshing = false;
869
- this.refreshTokenSubject.next(token.access_token);
870
- // Retry the original request with the new token
871
- return next.handle(this.getRequestWithHeaders(request));
872
- }), catchError((err) => {
873
- this.isRefreshing = false;
874
- // Refresh failed - logout user (only once)
875
- if (!this.clearingAuth) {
876
- this.clearingAuth = true;
877
- const authService = this.injector.get(AuthService);
878
- authService.clearAuth();
879
- this.clearingAuth = false;
880
- }
881
- return throwError(() => err);
882
- }));
883
- }
884
- else {
885
- // Wait while getting new token
886
- return this.refreshTokenSubject.pipe(filter((token) => token != null), take(1), switchMap((jwt) => {
887
- // Rewrite with new token and retry
888
- return next.handle(this.getRequestWithHeaders(request));
889
- }));
890
- }
891
- }
892
- getRequestWithHeaders(req) {
893
- // Skip adding token for login/refresh/logout endpoints
894
- if (req.url.includes('auth/login') ||
895
- req.url.includes('auth/federated/login') ||
896
- req.url.includes('auth/refresh') ||
897
- req.url.includes('auth/logout')) {
898
- return req;
899
- }
900
- let headers = req.headers;
901
- // Get fresh token from new storage service
902
- const token = this.tokenStorage.get('access_token') ?? '';
903
- if (token != '') {
904
- headers = headers.set('authorization', `Bearer ${token}`);
905
- }
906
- return req.clone({ headers });
907
- }
908
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.14", ngImport: i0, type: AuthInterceptor, deps: [{ token: StorageService }, { token: i0.Injector }], target: i0.ɵɵFactoryTarget.Injectable });
909
- static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.14", ngImport: i0, type: AuthInterceptor, providedIn: 'root' });
910
- }
911
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.14", ngImport: i0, type: AuthInterceptor, decorators: [{
912
- type: Injectable,
913
- args: [{
914
- providedIn: 'root',
915
- }]
916
- }], ctorParameters: () => [{ type: StorageService }, { type: i0.Injector }] });
917
-
918
827
  const BASE_STORAGE_KEY = 'app.personalization.v1';
919
828
  const DEFAULT_SETTINGS = {
920
829
  customInstructions: {
@@ -4408,49 +4317,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.14", ngImpo
4408
4317
  }]
4409
4318
  }] });
4410
4319
 
4411
- class LicenseInterceptor {
4412
- injector;
4413
- constructor(injector) {
4414
- this.injector = injector;
4415
- }
4416
- intercept(req, next) {
4417
- const authService = this.injector.get(AuthService);
4418
- const licenseService = this.injector.get(LicenseService);
4419
- // Skip if this is a login/auth request (AccountService handles it explicitly)
4420
- if (req.url.includes('auth/login') ||
4421
- req.url.includes('auth/federated/login') ||
4422
- req.url.includes('auth/refresh') ||
4423
- req.url.includes('auth/logout')) {
4424
- return next.handle(req);
4425
- }
4426
- // Determine if this is an internal API request
4427
- const apiBaseUrl = AppConst.data?.apiBaseUrl || '';
4428
- const apiSegment = AppConst.data?.apiSegment || '/api/';
4429
- const isInternalApi = req.url.includes(apiSegment) ||
4430
- (apiBaseUrl && req.url.startsWith(apiBaseUrl)) ||
4431
- (!req.url.startsWith('http') && !req.url.startsWith('assets/'));
4432
- if (!isInternalApi) {
4433
- return next.handle(req);
4434
- }
4435
- // Resolve License Key for Authenticated Request
4436
- const context = authService.getLicensingContext();
4437
- // Post-login, context.tenantId should be company_id
4438
- const licenseKey = licenseService.resolveLicenseKey(context, 'doohbot');
4439
- if (licenseKey) {
4440
- const clonedReq = req.clone({
4441
- headers: req.headers.set('x-license-key', licenseKey),
4442
- });
4443
- return next.handle(clonedReq);
4444
- }
4445
- return next.handle(req);
4446
- }
4447
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.14", ngImport: i0, type: LicenseInterceptor, deps: [{ token: i0.Injector }], target: i0.ɵɵFactoryTarget.Injectable });
4448
- static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.14", ngImport: i0, type: LicenseInterceptor });
4449
- }
4450
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.14", ngImport: i0, type: LicenseInterceptor, decorators: [{
4451
- type: Injectable
4452
- }], ctorParameters: () => [{ type: i0.Injector }] });
4453
-
4454
4320
  class Doohbot extends DoohbotInput {
4455
4321
  elementRef;
4456
4322
  renderer;
@@ -4785,25 +4651,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.14", ngImpo
4785
4651
  //! ================== INITIALIZATION =======================
4786
4652
  function initializeApp() {
4787
4653
  const appConst = inject(AppConst);
4788
- return appConst.load(); // Returns a Promise
4654
+ return () => appConst.load(); // Returns a function that returns a Promise
4789
4655
  }
4790
- bootstrapApplication(Doohbot, {
4791
- providers: [
4792
- provideHttpClient(withInterceptorsFromDi()),
4793
- AppConst,
4794
- provideAppInitializer(initializeApp),
4795
- {
4796
- provide: HTTP_INTERCEPTORS,
4797
- useClass: AuthInterceptor,
4798
- multi: true,
4799
- },
4800
- {
4801
- provide: HTTP_INTERCEPTORS,
4802
- useClass: LicenseInterceptor,
4803
- multi: true,
4804
- },
4805
- ],
4806
- });
4807
4656
 
4808
4657
  /**
4809
4658
  * Injection token for providing Doohbot API configuration
@@ -4870,11 +4719,172 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.14", ngImpo
4870
4719
  args: [MenuItem]
4871
4720
  }] } });
4872
4721
 
4722
+ class AuthInterceptor {
4723
+ tokenStorage;
4724
+ injector;
4725
+ isRefreshing = false;
4726
+ clearingAuth = false; // Prevent multiple clearAuth calls
4727
+ refreshTokenSubject = new BehaviorSubject(null);
4728
+ constructor(tokenStorage, injector) {
4729
+ this.tokenStorage = tokenStorage;
4730
+ this.injector = injector;
4731
+ }
4732
+ intercept(req, next) {
4733
+ const authReq = this.getRequestWithHeaders(req);
4734
+ return next.handle(authReq).pipe(catchError((error) => {
4735
+ // Handle 401 Unauthorized errors
4736
+ if (error instanceof HttpErrorResponse &&
4737
+ error.status === 401 &&
4738
+ !authReq.url.includes('auth/login') && // Don't retry login
4739
+ !authReq.url.includes('auth/federated/login') && // Don't retry federated login
4740
+ !authReq.url.includes('auth/logout') && // Don't retry logout
4741
+ !authReq.url.includes('auth/refresh') // Don't retry refresh itself
4742
+ ) {
4743
+ Logger.error('[AuthInterceptor] 401 Unauthorized:', {
4744
+ url: authReq.url,
4745
+ userId: this.tokenStorage.get('user_id'),
4746
+ });
4747
+ return this.handle401Error(authReq, next);
4748
+ }
4749
+ return throwError(() => error);
4750
+ }));
4751
+ }
4752
+ handle401Error(request, next) {
4753
+ // If already clearing, don't retry
4754
+ if (this.clearingAuth) {
4755
+ Logger.log('[AuthInterceptor] Already clearing auth, rejecting request');
4756
+ return throwError(() => new Error('Authentication cleared'));
4757
+ }
4758
+ if (!this.isRefreshing) {
4759
+ this.isRefreshing = true;
4760
+ this.refreshTokenSubject.next(null);
4761
+ const authService = this.injector.get(AuthService);
4762
+ return authService.refreshToken().pipe(switchMap((token) => {
4763
+ this.isRefreshing = false;
4764
+ this.refreshTokenSubject.next(token.access_token);
4765
+ // Retry the original request with the new token
4766
+ return next.handle(this.getRequestWithHeaders(request));
4767
+ }), catchError((err) => {
4768
+ this.isRefreshing = false;
4769
+ // Refresh failed - logout user (only once)
4770
+ if (!this.clearingAuth) {
4771
+ this.clearingAuth = true;
4772
+ const authService = this.injector.get(AuthService);
4773
+ authService.clearAuth();
4774
+ this.clearingAuth = false;
4775
+ }
4776
+ return throwError(() => err);
4777
+ }));
4778
+ }
4779
+ else {
4780
+ // Wait while getting new token
4781
+ return this.refreshTokenSubject.pipe(filter((token) => token != null), take(1), switchMap((jwt) => {
4782
+ // Rewrite with new token and retry
4783
+ return next.handle(this.getRequestWithHeaders(request));
4784
+ }));
4785
+ }
4786
+ }
4787
+ getRequestWithHeaders(req) {
4788
+ // Skip adding token for login/refresh/logout endpoints
4789
+ if (req.url.includes('auth/login') ||
4790
+ req.url.includes('auth/federated/login') ||
4791
+ req.url.includes('auth/refresh') ||
4792
+ req.url.includes('auth/logout')) {
4793
+ return req;
4794
+ }
4795
+ let headers = req.headers;
4796
+ // Get fresh token from new storage service
4797
+ const token = this.tokenStorage.get('access_token') ?? '';
4798
+ if (token != '') {
4799
+ headers = headers.set('authorization', `Bearer ${token}`);
4800
+ }
4801
+ return req.clone({ headers });
4802
+ }
4803
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.14", ngImport: i0, type: AuthInterceptor, deps: [{ token: StorageService }, { token: i0.Injector }], target: i0.ɵɵFactoryTarget.Injectable });
4804
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.14", ngImport: i0, type: AuthInterceptor, providedIn: 'root' });
4805
+ }
4806
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.14", ngImport: i0, type: AuthInterceptor, decorators: [{
4807
+ type: Injectable,
4808
+ args: [{
4809
+ providedIn: 'root',
4810
+ }]
4811
+ }], ctorParameters: () => [{ type: StorageService }, { type: i0.Injector }] });
4812
+
4813
+ class LicenseInterceptor {
4814
+ injector;
4815
+ constructor(injector) {
4816
+ this.injector = injector;
4817
+ }
4818
+ intercept(req, next) {
4819
+ const authService = this.injector.get(AuthService);
4820
+ const licenseService = this.injector.get(LicenseService);
4821
+ // Skip if this is a login/auth request (AccountService handles it explicitly)
4822
+ if (req.url.includes('auth/login') ||
4823
+ req.url.includes('auth/federated/login') ||
4824
+ req.url.includes('auth/refresh') ||
4825
+ req.url.includes('auth/logout')) {
4826
+ return next.handle(req);
4827
+ }
4828
+ // Determine if this is an internal API request
4829
+ const apiBaseUrl = AppConst.data?.apiBaseUrl || '';
4830
+ const apiSegment = AppConst.data?.apiSegment || '/api/';
4831
+ const isInternalApi = req.url.includes(apiSegment) ||
4832
+ (apiBaseUrl && req.url.startsWith(apiBaseUrl)) ||
4833
+ (!req.url.startsWith('http') && !req.url.startsWith('assets/'));
4834
+ if (!isInternalApi) {
4835
+ return next.handle(req);
4836
+ }
4837
+ // Resolve License Key for Authenticated Request
4838
+ const context = authService.getLicensingContext();
4839
+ // Post-login, context.tenantId should be company_id
4840
+ const licenseKey = licenseService.resolveLicenseKey(context, 'doohbot');
4841
+ if (licenseKey) {
4842
+ const clonedReq = req.clone({
4843
+ headers: req.headers.set('x-license-key', licenseKey),
4844
+ });
4845
+ return next.handle(clonedReq);
4846
+ }
4847
+ return next.handle(req);
4848
+ }
4849
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.14", ngImport: i0, type: LicenseInterceptor, deps: [{ token: i0.Injector }], target: i0.ɵɵFactoryTarget.Injectable });
4850
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.14", ngImport: i0, type: LicenseInterceptor });
4851
+ }
4852
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.14", ngImport: i0, type: LicenseInterceptor, decorators: [{
4853
+ type: Injectable
4854
+ }], ctorParameters: () => [{ type: i0.Injector }] });
4855
+
4856
+ function initializeDoohbotApp() {
4857
+ return () => {
4858
+ const appConst = inject(AppConst);
4859
+ return appConst.load();
4860
+ };
4861
+ }
4862
+ function provideDoohbot() {
4863
+ return makeEnvironmentProviders([
4864
+ AppConst,
4865
+ {
4866
+ provide: APP_INITIALIZER,
4867
+ useFactory: initializeDoohbotApp,
4868
+ multi: true,
4869
+ },
4870
+ provideHttpClient(withInterceptorsFromDi()),
4871
+ {
4872
+ provide: HTTP_INTERCEPTORS,
4873
+ useClass: AuthInterceptor,
4874
+ multi: true,
4875
+ },
4876
+ {
4877
+ provide: HTTP_INTERCEPTORS,
4878
+ useClass: LicenseInterceptor,
4879
+ multi: true,
4880
+ },
4881
+ ]);
4882
+ }
4883
+
4873
4884
  // /*
4874
4885
  // * Public API Surface of chatbot
4875
4886
  // */
4876
4887
  // // Main component
4877
- // // export * from './lib/doohbot-initializer';
4878
4888
  // // Services
4879
4889
  // export * from './lib/core/services/doohbot-api.service';
4880
4890
  // export * from './lib/core/auth/auth.service';
@@ -4901,5 +4911,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.14", ngImpo
4901
4911
  * Generated bundle index. Do not edit.
4902
4912
  */
4903
4913
 
4904
- export { Chips, DOOHBOT_API_CONFIG, DialogComponent, DialogService, Doohbot, DoohbotConst, DoohbotInput, DropdownMenu, MenuItem, SnackBar, initializeApp };
4914
+ export { Chips, DOOHBOT_API_CONFIG, DialogComponent, DialogService, Doohbot, DoohbotConst, DoohbotInput, DropdownMenu, MenuItem, SnackBar, initializeApp, initializeDoohbotApp, provideDoohbot };
4905
4915
  //# sourceMappingURL=aakash58-chatbot.mjs.map