{ "version": 3, "sources": ["apps/business-center-client/src/app/core/access/access.service.ts", "apps/business-center-client/src/app/core/access/index.ts"], "sourcesContent": ["import { Injectable } from '@angular/core';\nimport { Observable, of } from 'rxjs';\nimport { distinctUntilChanged, map, shareReplay, switchMap } from 'rxjs/operators';\nimport { HasViewAccessRequestInterface, ViewAccessApiService } from '@vendasta/platform-users';\nimport { Views } from './constants';\nimport { AccountGroupService } from '../../account-group';\nimport { Feature } from 'marketplace-ui';\nimport { WhitelabelService } from '@galaxy/partner';\nimport { AccountGroupApiService } from '@vendasta/account-group';\n\n@Injectable({ providedIn: 'root' })\nexport class AccessService {\n features$: Observable;\n\n constructor(\n private readonly viewAccessService: ViewAccessApiService,\n private readonly accountGroupService: AccountGroupService,\n private readonly accountGroupApiService: AccountGroupApiService,\n private readonly whitelabelService: WhitelabelService,\n ) {\n const parentNamespace$ = accountGroupService.currentAccountGroupId$.pipe(\n switchMap((accountGroupId) =>\n this.accountGroupApiService.getMulti({\n accountGroupIds: [accountGroupId],\n projectionFilter: { accountGroupExternalIdentifiers: true },\n }),\n ),\n map((response) => response.accountGroups[0]?.accountGroup?.accountGroupExternalIdentifiers?.partnerId),\n );\n this.features$ = parentNamespace$.pipe(\n switchMap((pid) => this.whitelabelService.getConfiguration(pid)),\n map((config) => config.enabledFeatures),\n shareReplay(1),\n );\n }\n\n // note: this should not to be confused with `vconfig/vconfig.service.ts`\n // this is for value based pricing feature access checks\n hasAccessToFeature(feature: Feature): Observable {\n return this.features$.pipe(\n map((features) => {\n return Boolean(features && features.indexOf(feature) >= 0);\n }),\n distinctUntilChanged(),\n );\n }\n\n // note: this should not to be confused with `vconfig/vconfig.service.ts`\n // this is for value based pricing feature access checks\n hasAccessToFeatures(features: Feature[]): Observable {\n if (!features) {\n return of(true);\n }\n return this.features$.pipe(\n map((partnerFeatures) => {\n return features.every((feature) => Boolean(partnerFeatures && partnerFeatures.indexOf(feature) >= 0));\n }),\n distinctUntilChanged(),\n );\n }\n\n hasAccessToViews(views: Views[]): Observable> {\n return this.accountGroupService.currentAccountGroupId$.pipe(\n switchMap((agid) =>\n this.viewAccessService.hasViewAccess({\n partnerId: agid,\n viewIds: views,\n } as HasViewAccessRequestInterface),\n ),\n map((response) => {\n const hasAccess = new Map();\n response.access.forEach((view) => {\n const viewId = view.viewId as Views;\n hasAccess.set(viewId, view.hasAccess ?? false);\n });\n return hasAccess;\n }),\n );\n }\n}\n", "export { AccessService } from './access.service';\nexport { Views, Feature } from './constants';\n"], "mappings": "8UAAA,IAWaA,EAXbC,EAAAC,EAAA,KACAC,IACAC,wBASaJ,GAAa,IAAA,CAApB,MAAOA,CAAa,CAGxBK,YACmBC,EACAC,EACAC,EACAC,EAAoC,CAHpC,KAAAH,kBAAAA,EACA,KAAAC,oBAAAA,EACA,KAAAC,uBAAAA,EACA,KAAAC,kBAAAA,EAEjB,IAAMC,EAAmBH,EAAoBI,uBAAuBC,KAClEC,EAAWC,GACT,KAAKN,uBAAuBO,SAAS,CACnCC,gBAAiB,CAACF,CAAc,EAChCG,iBAAkB,CAAEC,gCAAiC,EAAI,EAC1D,CAAC,EAEJC,EAAKC,GAAaA,EAASC,cAAc,CAAC,GAAGC,cAAcJ,iCAAiCK,SAAS,CAAC,EAExG,KAAKC,UAAYd,EAAiBE,KAChCC,EAAWY,GAAQ,KAAKhB,kBAAkBiB,iBAAiBD,CAAG,CAAC,EAC/DN,EAAKQ,GAAWA,EAAOC,eAAe,EACtCC,EAAY,CAAC,CAAC,CAElB,CAIAC,mBAAmBC,EAAgB,CACjC,OAAO,KAAKP,UAAUZ,KACpBO,EAAKa,GACIC,GAAQD,GAAYA,EAASE,QAAQH,CAAO,GAAK,EACzD,EACDI,EAAoB,CAAE,CAE1B,CAIAC,oBAAoBJ,EAAmB,CACrC,OAAKA,EAGE,KAAKR,UAAUZ,KACpBO,EAAKkB,GACIL,EAASM,MAAOP,GAAYE,GAAQI,GAAmBA,EAAgBH,QAAQH,CAAO,GAAK,EAAE,CACrG,EACDI,EAAoB,CAAE,EANfI,EAAG,EAAI,CAQlB,CAEAC,iBAAiBC,EAAc,CAC7B,OAAO,KAAKlC,oBAAoBI,uBAAuBC,KACrDC,EAAW6B,GACT,KAAKpC,kBAAkBqC,cAAc,CACnCpB,UAAWmB,EACXE,QAASH,EACuB,CAAC,EAErCtB,EAAKC,GAAY,CACf,IAAMyB,EAAY,IAAIC,IACtB1B,OAAAA,EAAS2B,OAAOC,QAASC,GAAQ,CAC/B,IAAMC,EAASD,EAAKC,OACpBL,EAAUM,IAAID,EAAQD,EAAKJ,WAAa,EAAK,CAC/C,CAAC,EACMA,CACT,CAAC,CAAC,CAEN,iDAnEW7C,GAAaoD,EAAAC,CAAA,EAAAD,EAAAE,CAAA,EAAAF,EAAAG,CAAA,EAAAH,EAAAI,CAAA,CAAA,CAAA,CAAA,iCAAbxD,EAAayD,QAAbzD,EAAa0D,UAAAC,WADA,MAAM,CAAA,CAAA,SACnB3D,CAAa,GAAA,ICX1B,IAAA4D,EAAAC,EAAA,KAAAC", "names": ["AccessService", "init_access_service", "__esmMin", "init_esm", "init_operators", "constructor", "viewAccessService", "accountGroupService", "accountGroupApiService", "whitelabelService", "parentNamespace$", "currentAccountGroupId$", "pipe", "switchMap", "accountGroupId", "getMulti", "accountGroupIds", "projectionFilter", "accountGroupExternalIdentifiers", "map", "response", "accountGroups", "accountGroup", "partnerId", "features$", "pid", "getConfiguration", "config", "enabledFeatures", "shareReplay", "hasAccessToFeature", "feature", "features", "Boolean", "indexOf", "distinctUntilChanged", "hasAccessToFeatures", "partnerFeatures", "every", "of", "hasAccessToViews", "views", "agid", "hasViewAccess", "viewIds", "hasAccess", "Map", "access", "forEach", "view", "viewId", "set", "\u0275\u0275inject", "ViewAccessApiService", "AccountGroupService", "AccountGroupApiService", "WhitelabelService", "factory", "\u0275fac", "providedIn", "init_access", "__esmMin", "init_access_service"] }