{ "version": 3, "sources": ["apps/partner-center-client/src/app/api-service/api.service.ts"], "sourcesContent": ["import { HttpClient, HttpErrorResponse } from '@angular/common/http';\nimport { Injectable } from '@angular/core';\nimport { Observable, throwError as observableThrowError } from 'rxjs';\nimport { catchError, map } from 'rxjs/operators';\n\nexport interface ApiServiceInterface {\n get(url: string, options?: Record): Observable;\n\n post(url: string, body: any, options?: Record): Observable;\n}\n\nexport class ApiError implements Error {\n name: string;\n message: string;\n code: number;\n data?: Record;\n\n constructor(message: string, code: number, data?: Record) {\n this.name = `ApiError${code}`;\n this.message = message;\n this.code = code;\n this.data = data;\n }\n}\n\n/**\n * @deprecated PLEASE USE HTTPCLIENT FROM '@angular/common/http'.\n */\n@Injectable({ providedIn: 'root' })\nexport class ApiService implements ApiServiceInterface {\n apiOptions = {\n withCredentials: true,\n responseType: 'json',\n };\n constructor(private http: HttpClient) {}\n\n public get(url: string, options?: any): Observable {\n return this.http\n .get(url, Object.assign({}, this.apiOptions, options))\n .pipe(map(this.extractData), catchError(this.handleError)); // TODO: ugly\n }\n\n public put(url: string, body: any, options?: any): Observable {\n return this.http\n .put(url, body, Object.assign({}, this.apiOptions, options))\n .pipe(map(this.extractData), catchError(this.handleError));\n }\n\n public post(url: string, body: any, options?: any): Observable {\n return this.http\n .post(url, body, Object.assign({}, this.apiOptions, options))\n .pipe(map(this.extractData), catchError(this.handleError));\n }\n\n public generateUrlWithParams(url: string, params: { [key: string]: string }): string {\n if (Object.keys(params).length === 0) {\n return url;\n }\n\n const finalUrl = url + '?';\n const finalParams = Object.keys(params)\n .map((param_key) => `${param_key}=${params[param_key]}`)\n .join('&');\n return finalUrl + finalParams;\n }\n\n public generateRepeatedUrlParams(paramName: string, params: string[]): string {\n let repeatedParams = '';\n params.forEach((id, index) => {\n if (index !== 0) {\n repeatedParams += '&';\n }\n repeatedParams += paramName + '=' + id;\n });\n return repeatedParams;\n }\n\n private extractData(res: any): any {\n try {\n return 'data' in res ? res.data : res;\n } catch (error) {\n return res;\n }\n }\n\n private handleError(error: HttpErrorResponse): Observable {\n try {\n const errorInfo = error;\n const err = new ApiError(errorInfo.message, errorInfo.status, errorInfo.error);\n return observableThrowError(err);\n } catch (error) {\n const err = new ApiError('Unknown Error', 500);\n return observableThrowError(err);\n }\n }\n}\n"], "mappings": "8GAWM,IAAOA,EAAP,KAAe,CAMnBC,YAAYC,EAAiBC,EAAcC,EAA8B,CACvE,KAAKC,KAAO,WAAWF,CAAI,GAC3B,KAAKD,QAAUA,EACf,KAAKC,KAAOA,EACZ,KAAKC,KAAOA,CACd,GAOWE,GAAU,IAAA,CAAjB,IAAOA,EAAP,MAAOA,CAAU,CAKrBL,YAAoBM,EAAgB,CAAhB,KAAAA,KAAAA,EAJpB,KAAAC,WAAa,CACXC,gBAAiB,GACjBC,aAAc,OAEuB,CAEhCC,IAAIC,EAAaC,EAAa,CACnC,OAAO,KAAKN,KACTI,IAAIC,EAAKE,OAAOC,OAAO,CAAA,EAAI,KAAKP,WAAYK,CAAO,CAAC,EACpDG,KAAKC,EAAI,KAAKC,WAAW,EAAGC,EAAW,KAAKC,WAAW,CAAC,CAC7D,CAEOC,IAAIT,EAAaU,EAAWT,EAAa,CAC9C,OAAO,KAAKN,KACTc,IAAIT,EAAKU,EAAMR,OAAOC,OAAO,CAAA,EAAI,KAAKP,WAAYK,CAAO,CAAC,EAC1DG,KAAKC,EAAI,KAAKC,WAAW,EAAGC,EAAW,KAAKC,WAAW,CAAC,CAC7D,CAEOG,KAAKX,EAAaU,EAAWT,EAAa,CAC/C,OAAO,KAAKN,KACTgB,KAAKX,EAAKU,EAAMR,OAAOC,OAAO,CAAA,EAAI,KAAKP,WAAYK,CAAO,CAAC,EAC3DG,KAAKC,EAAI,KAAKC,WAAW,EAAGC,EAAW,KAAKC,WAAW,CAAC,CAC7D,CAEOI,sBAAsBZ,EAAaa,EAAiC,CACzE,GAAIX,OAAOY,KAAKD,CAAM,EAAEE,SAAW,EACjC,OAAOf,EAGT,IAAMgB,EAAWhB,EAAM,IACjBiB,EAAcf,OAAOY,KAAKD,CAAM,EACnCR,IAAKa,GAAc,GAAGA,CAAS,IAAIL,EAAOK,CAAS,CAAC,EAAE,EACtDC,KAAK,GAAG,EACX,OAAOH,EAAWC,CACpB,CAEOG,0BAA0BC,EAAmBR,EAAgB,CAClE,IAAIS,EAAiB,GACrBT,OAAAA,EAAOU,QAAQ,CAACC,EAAIC,IAAS,CACvBA,IAAU,IACZH,GAAkB,KAEpBA,GAAkBD,EAAY,IAAMG,CACtC,CAAC,EACMF,CACT,CAEQhB,YAAYoB,EAAQ,CAC1B,GAAI,CACF,MAAO,SAAUA,EAAMA,EAAIlC,KAAOkC,CACpC,MAAgB,CACd,OAAOA,CACT,CACF,CAEQlB,YAAYmB,EAAwB,CAC1C,GAAI,CACF,IAAMC,EAAYD,EACZE,EAAM,IAAIzC,EAASwC,EAAUtC,QAASsC,EAAUE,OAAQF,EAAUD,KAAK,EAC7E,OAAOI,EAAqBF,CAAG,CACjC,MAAgB,CACd,IAAMA,EAAM,IAAIzC,EAAS,gBAAiB,GAAG,EAC7C,OAAO2C,EAAqBF,CAAG,CACjC,CACF,yCAjEWnC,GAAUsC,EAAAC,CAAA,CAAA,CAAA,wBAAVvC,EAAUwC,QAAVxC,EAAUyC,UAAAC,WADG,MAAM,CAAA,EAC1B,IAAO1C,EAAP2C,SAAO3C,CAAU,GAAA", "names": ["ApiError", "constructor", "message", "code", "data", "name", "ApiService", "http", "apiOptions", "withCredentials", "responseType", "get", "url", "options", "Object", "assign", "pipe", "map", "extractData", "catchError", "handleError", "put", "body", "post", "generateUrlWithParams", "params", "keys", "length", "finalUrl", "finalParams", "param_key", "join", "generateRepeatedUrlParams", "paramName", "repeatedParams", "forEach", "id", "index", "res", "error", "errorInfo", "err", "status", "observableThrowError", "\u0275\u0275inject", "HttpClient", "factory", "\u0275fac", "providedIn", "_ApiService"] }