{"version":3,"file":"progress-chef-interact-http-interceptor.mjs","sources":["../../../projects/http-interceptor/src/lib/popup/popup.service.ts","../../../projects/http-interceptor/src/lib/http-interceptor.service.ts","../../../projects/http-interceptor/src/public-api.ts","../../../projects/http-interceptor/src/progress-chef-interact-http-interceptor.ts"],"sourcesContent":["import { Injectable } from '@angular/core';\nimport { BehaviorSubject } from 'rxjs/internal/BehaviorSubject';\n\n@Injectable({\n  providedIn: 'root'\n})\nexport class PopupService {\n  header: string = '';\n  message: string = '';\n  type: 'info' | 'error' = 'info';\n  showPopup = new BehaviorSubject<boolean>(false);\n  visible$ = this.showPopup.asObservable();\n\n  constructor() { }\n\n  // open popup\n  open(content: any): void {\n    this.header = content.header;\n    this.message = content.message;\n    this.type = content.type;\n    this.showPopup.next(true);\n  }\n\n  // close popup\n  close(): void {\n    this.showPopup.next(false);\n  }\n}\n","import {\n  HttpErrorResponse, HttpEvent, HttpHandler,\n  HttpInterceptor, HttpRequest\n} from '@angular/common/http';\nimport { Injectable, Injector } from '@angular/core';\nimport { Observable, throwError } from 'rxjs';\nimport { catchError, mergeMap, take } from 'rxjs/operators';\nimport { PopupService } from './popup/popup.service';\nimport { SessionService } from '@progress-chef/interact-session';\n\n\n@Injectable()\nexport class HttpClientInterceptor implements HttpInterceptor {\n\n  constructor(private injector: Injector) { }\n\n  intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {\n    const popupService = this.injector.get(PopupService);\n    let headers = req.headers;\n    const apiToken = localStorage.getItem(\"apiToken\") || \"\";\n    const token: string = '<TEST_TOKEN>';\n\n    if (localStorage.getItem('isNginx') === 'true') {\n      const sessionService = this.injector.get(SessionService);\n\n      return sessionService.tokenProvider.pipe(\n        take(1),\n        mergeMap((id_token) => {\n          headers = headers.set('Authorization', `Bearer ${id_token}`);\n          req = req.clone({ headers });\n\n          return next.handle(req).pipe(catchError((error: HttpErrorResponse) => {\n            return throwError(() => error);\n          }));\n        })\n      );\n    } else {\n      // We either need api-token or Authorization request header for Automate backend to authenticate and allow our request.\n      if (apiToken.length > 0) {\n        headers = headers.set('api-token', apiToken);\n      }\n      // headers = headers.set('Authorization', `Bearer ${token}`);\n      req = req.clone({ headers });\n\n      return next.handle(req).pipe(catchError((error: HttpErrorResponse) => {\n        return throwError(() => error);\n      }));\n    }\n  }\n}\n","/*\n * Public API Surface of http-interceptor\n */\n\nexport * from './lib/http-interceptor.service';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;;;MAMa,YAAY,CAAA;AAOvB,IAAA,WAAA,GAAA;QANA,IAAM,CAAA,MAAA,GAAW,EAAE,CAAC;QACpB,IAAO,CAAA,OAAA,GAAW,EAAE,CAAC;QACrB,IAAI,CAAA,IAAA,GAAqB,MAAM,CAAC;AAChC,QAAA,IAAA,CAAA,SAAS,GAAG,IAAI,eAAe,CAAU,KAAK,CAAC,CAAC;AAChD,QAAA,IAAA,CAAA,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,YAAY,EAAE,CAAC;KAExB;;AAGjB,IAAA,IAAI,CAAC,OAAY,EAAA;AACf,QAAA,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;AAC7B,QAAA,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;AAC/B,QAAA,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;AACzB,QAAA,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;KAC3B;;IAGD,KAAK,GAAA;AACH,QAAA,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;KAC5B;+GApBU,YAAY,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA,CAAA,EAAA;AAAZ,IAAA,SAAA,IAAA,CAAA,KAAA,GAAA,EAAA,CAAA,qBAAA,CAAA,EAAA,UAAA,EAAA,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