import { Observable } from 'rxjs'; import jwt from 'jwt-decode'; import { PapiClient } from '@pepperi-addons/papi-sdk'; import { Injectable } from '@angular/core'; import { PepHttpService, PepSessionService } from '@pepperi-addons/ngx-lib'; @Injectable({ providedIn: 'root' }) export class AddonService { accessToken = ''; parsedToken: any papiBaseURL = '' addonUUID; get papiClient(): PapiClient { return new PapiClient({ baseURL: this.papiBaseURL, token: this.session.getIdpToken(), addonUUID: this.addonUUID, suppressLogging:true }) } constructor( public session: PepSessionService, private pepHttp: PepHttpService ) { const accessToken = this.session.getIdpToken(); this.parsedToken = jwt(accessToken); this.papiBaseURL = this.parsedToken["pepperi.baseurl"]; } async get(endpoint: string): Promise { return await this.papiClient.get(endpoint); } async post(endpoint: string, body: any): Promise { return await this.papiClient.post(endpoint, body); } pepGet(endpoint: string): Observable { return this.pepHttp.getPapiApiCall(endpoint); } pepPost(endpoint: string, body: any): Observable { return this.pepHttp.postPapiApiCall(endpoint, body); } }