{ "version": 3, "sources": ["apps/partner-center-client/src/app/app-config.service.ts"], "sourcesContent": ["import { HttpClient } from '@angular/common/http';\nimport { Injectable } from '@angular/core';\nimport { BehaviorSubject, firstValueFrom, Observable } from 'rxjs';\nimport { filter, map } from 'rxjs/operators';\n\nexport interface Product {\n link: string;\n title: string;\n icon: string;\n tab_id: string;\n pop_out?: boolean;\n ng_route: boolean;\n svg_icon: boolean;\n right_icon?: string;\n nested_tabs: Product[];\n locked: boolean;\n subsection_header?: string;\n badge?: string;\n}\n\nexport class AppConfig {\n customizeWhitelabelUrl: string;\n userOptions: { label: string; url: string; menuId: string }[];\n products: Product[];\n partnerId: string;\n partnerName: string;\n userIsAdmin: boolean;\n userCanAccessAccounts: boolean;\n userCanAccessAutomations: boolean;\n userCanAccessBilling: boolean;\n userCanAccessCompanyProfile: boolean;\n userCanAccessDashboard: boolean;\n userCanAccessMarketing: boolean;\n userCanAccessRetailBilling: boolean;\n userCanAccessSnapshotWidget: boolean;\n userCanCustomizeWhitelabel: boolean;\n userCanAccessOrders: boolean;\n userCanAccessSales: boolean;\n canEnableApps: boolean;\n googleAnalyticsDimensions: string[];\n googleAnalyticsCode: string;\n // @deprecated: this can be an email, use unifiedUserId instead\n userId?: string;\n unifiedUserId?: string;\n userEmail?: string;\n userFirstName?: string;\n userLastName?: string;\n userMarket?: string;\n partnerCreated?: number;\n userCreated?: number;\n gtmAuth?: string;\n gtmPreview?: string;\n gtmContainer?: string;\n supportEnabled?: boolean;\n hotjarTrackingCode?: string;\n wootricEnabled?: boolean;\n accountExecutive?: string;\n accountExecutiveSlack?: string;\n acceptedTermsAndConditions?: boolean;\n isSuperAdmin?: boolean;\n isImpersonated?: boolean;\n sessionId?: string;\n isBeta?: boolean;\n accessibleMarketIds?: string[];\n environment?: 'test' | 'demo' | 'prod' | 'local';\n partnerOrigin?: string;\n selectedTab: string;\n hasFailedPurchase: boolean;\n affiliateApproved?: boolean;\n}\n\nexport interface AppConfigProvider {\n config$: Observable;\n}\n\nconst APP_CONFIG_URL = '/api/v1/app-config';\n\n@Injectable()\nexport class AppConfigService implements AccessibleMarketsProvider, AppConfigProvider {\n private readonly config$$: BehaviorSubject = new BehaviorSubject(null);\n private readonly loading$$: BehaviorSubject = new BehaviorSubject(false);\n public readonly loading$ = this.loading$$.asObservable();\n\n public get config$(): Observable {\n return this.config$$.asObservable().pipe(\n filter((config) => {\n return !!config;\n }),\n );\n }\n\n public get userAccessibleMarkets$(): Observable {\n return this.config$.pipe(map((config) => config.accessibleMarketIds));\n }\n\n public get isImpersonated(): boolean {\n return this.config.isImpersonated;\n }\n\n public get config(): AppConfig {\n return this.config$$.getValue();\n }\n\n public set config(value: AppConfig) {\n this.config$$.next(value);\n }\n\n constructor(private http: HttpClient) {}\n\n public async load(partnerId?: string): Promise {\n try {\n this.loading$$.next(true);\n if (partnerId) {\n // To get the app config, the backend currently heavily relies on the session cookie for the partner ID, which\n // makes it difficult to switch the partner ID on the same request as wanting to use the new partner ID.\n // This post request will update the session cookie first so that the next call can use the session cookie with\n // the new partner ID in it.\n await firstValueFrom(\n this.http.post(`${APP_CONFIG_URL}?_pid=${partnerId.toUpperCase()}`, { withCredentials: true }),\n );\n }\n const result = await firstValueFrom(this.http.get(APP_CONFIG_URL, { withCredentials: true }));\n this.config$$.next({ ...result, affiliateApproved: false }); // TODO: replace static affiliate value with a call to backend\n } catch (error) {\n if (window.location.pathname !== '/login') {\n window.history.replaceState({}, 'Partner Login', '/login');\n }\n } finally {\n this.loading$$.next(false);\n }\n return true;\n }\n\n public excludeSpecificPIDForSSC(): boolean {\n const pid = this.config.partnerId;\n return pid === 'VMF' || pid === 'ABC';\n }\n}\n\n/**\n * @deprecated userAccessibleMarkets should be moved to MarketsServiceInterface.\n */\nexport interface AccessibleMarketsProvider {\n userAccessibleMarkets$: Observable;\n isImpersonated: boolean;\n}\n"], "mappings": "2KA2EA,IAAMA,EAAiB,qBAGVC,GAAgB,IAAA,CAAvB,IAAOA,EAAP,MAAOA,CAAgB,C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sC,EAAAC,CAAA,CAAA,CAAA,wBAAhBvC,EAAgBwC,QAAhBxC,EAAgByC,SAAA,CAAA,EAAvB,IAAOzC,EAAP0C,SAAO1C,CAAgB,GAAA", "names": ["APP_CONFIG_URL", "AppConfigService", "config$", "config$$", "asObservable", "pipe", "filter", "config", "userAccessibleMarkets$", "map", "accessibleMarketIds", "isImpersonated", "getValue", "value", "next", "constructor", "http", "BehaviorSubject", "loading$$", "loading$", "load", "partnerId", "__async", "firstValueFrom", "post", "toUpperCase", "withCredentials", "result", "get", "__spreadProps", "__spreadValues", "affiliateApproved", "window", "location", "pathname", "history", "replaceState", "excludeSpecificPIDForSSC", "pid", "\u0275\u0275inject", "HttpClient", "factory", "\u0275fac", "_AppConfigService"] }