{ "version": 3, "sources": ["src/app/enums/view-type.enum.ts", "src/app/shared/services/checkout-core/checkout-core-registerer.service.ts"], "sourcesContent": ["export enum ViewTypeEnum {\n EMBEDDED = 'embedded',\n}", "import {inject, Injectable, OnDestroy} from '@angular/core';\nimport {NavigationExtras, Router} from '@angular/router';\nimport {MsalBroadcastService, MsalService} from '@azure/msal-angular';\nimport {InteractionStatus, SilentRequest} from '@azure/msal-browser';\nimport {\n asapScheduler,\n BehaviorSubject,\n combineLatest,\n combineLatestWith,\n filter,\n fromEvent,\n map,\n Observable,\n observeOn,\n ReplaySubject,\n shareReplay,\n Subject,\n takeUntil,\n} from 'rxjs';\nimport {AppInsightsService} from 'src/app/core/app-insights/app-insights.service';\nimport {AuthenticationService} from 'src/app/core/auth/authentication.service';\nimport {ConfigurationService} from 'src/app/core/config/configuration.service';\nimport {LanguageService} from 'src/app/core/i18n/language.service';\nimport {ViewTypeEnum} from 'src/app/enums/view-type.enum';\nimport {DS_VIEW_TYPE_INJECTION_TOKEN} from 'src/app/shared/injection-token/injection-tokens';\nimport {CheckoutAppService} from 'src/app/shared/services/checkout-core/checkout-app.service';\n\nexport interface ICheckoutCoreComponentInitPayload {\n authToken: string | null;\n config: Record | null;\n language: string;\n visible: boolean;\n}\n\n@Injectable({\n providedIn: 'root',\n})\nexport class CheckoutCoreRegistererService implements OnDestroy {\n private readonly msalService = inject(MsalService);\n private readonly msalBroadcastService = inject(MsalBroadcastService);\n private readonly configService = inject(ConfigurationService);\n private readonly authService = inject(AuthenticationService);\n private readonly lang = inject(LanguageService);\n private readonly router = inject(Router);\n private readonly checkoutApp = inject(CheckoutAppService);\n private readonly appInsightsService = inject(AppInsightsService);\n private readonly viewType = inject(DS_VIEW_TYPE_INJECTION_TOKEN);\n\n private readonly _authToken$ = new BehaviorSubject(null);\n public readonly authToken$ = this._authToken$.asObservable();\n get authToken(): string | null {\n return this._authToken$.value;\n }\n\n private readonly _triedGetAuthToken$ = new BehaviorSubject(false);\n public readonly triedGetAuthToken$ = this._triedGetAuthToken$.asObservable();\n get triedGetAuthToken(): boolean {\n return this._triedGetAuthToken$.value;\n }\n set triedGetAuthToken(value: boolean) {\n this._triedGetAuthToken$.next(value);\n }\n\n private readonly isWebView = this.viewType === ViewTypeEnum.EMBEDDED;\n\n private readonly configPatch$ = new ReplaySubject | null>(1);\n public readonly checkoutConfig$ = this.configPatch$.pipe(\n map((patch) => {\n patch = patch ?? {};\n return {\n ...this.checkoutConfig(this.isWebView),\n ...patch,\n };\n }),\n );\n\n private readonly checkoutCoreVisibilitySrc$ = new BehaviorSubject(false);\n private readonly checkoutCoreVisibility$ = this.checkoutCoreVisibilitySrc$.asObservable();\n\n public readonly coreWebComponentPayload$: Observable =\n combineLatest([\n this.checkoutCoreVisibility$,\n this.authToken$.pipe(\n combineLatestWith(this.triedGetAuthToken$),\n filter(([, triedGetAuthToken]) => triedGetAuthToken),\n map(([authToken]) => authToken),\n ),\n this.checkoutConfig$,\n this.lang.languageChange$,\n ]).pipe(\n observeOn(asapScheduler),\n map(([visible, authToken, config, language]) => {\n return {\n visible: visible,\n authToken,\n config,\n language,\n };\n }),\n shareReplay({refCount: true, bufferSize: 1}),\n );\n\n private readonly _destroying$ = new Subject();\n\n constructor() {\n this.msalBroadcastService.inProgress$\n .pipe(\n // Filtering for all interactions to be completed\n filter((status: InteractionStatus) => status === InteractionStatus.None),\n takeUntil(this._destroying$),\n )\n .subscribe(() => {\n if (\n this.msalService.instance.getAllAccounts().length > 0 ||\n this.msalService.instance.getActiveAccount()\n ) {\n // this.store.dispatch(new SetAuthenticationState(AuthenticationStateEnum.Authorized));\n\n // TODO: Check that we always request the access token twice with that. If I'm correct we do not support guest users\n // anymore in ths portal. So why do we don't just rely on the token retrievel of the parent app and pass the new token on\n // success message in the msal service to the checkout component?\n this.getAuthToken();\n // this.optionalLinkGuestToProfile();\n } else {\n this.triedGetAuthToken = true;\n }\n });\n\n fromEvent(window, 'dsRefreshAuthTokenReq')\n .pipe(takeUntil(this._destroying$))\n .subscribe(() => {\n console.log('request refresh token from parent app');\n this.refreshAuthToken();\n });\n\n fromEvent(window, 'dsForceAuthReq')\n .pipe(\n map((event) => event.detail),\n takeUntil(this._destroying$),\n )\n .subscribe((payload) => this.forceAuthHandler(payload));\n }\n\n public ngOnDestroy(): void {\n this._destroying$.next();\n this._destroying$.complete();\n this._triedGetAuthToken$.complete();\n this.checkoutCoreVisibilitySrc$.complete();\n this._authToken$.complete();\n }\n\n public checkoutConfig(isWebView: boolean = false): Record {\n let checkoutStyle = this.configService.get('checkoutStyle');\n if (isWebView) {\n const lightStyle = this.configService.get('checkoutStyle')?.light;\n const darkStyle = this.configService.get('checkoutStyle')?.dark;\n const patchedLightStyle = {\n ...lightStyle,\n '--host-app-padding-top': '0px',\n '--mobile-host-app-padding-top': '0px',\n };\n const patchedDarkStyle = {\n ...darkStyle,\n '--host-app-padding-top': '0px',\n '--mobile-host-app-padding-top': '0px',\n };\n checkoutStyle = {light: patchedLightStyle, dark: patchedDarkStyle};\n }\n\n return {\n showTotalPriceInFooter: this.configService.webComponent.checkout.showTotalPriceInFooter, // check if present in config\n showGlobalHeader: this.configService.webComponent.checkout.showGlobalHeader,\n dateTimeInputType: this.configService.webComponent.checkout.dateTimeInputType, // check if present in config\n subscriptionKey: this.configService.webComponent.checkout.subscriptionKey,\n profileUrl: this.configService.get('sjhApi'),\n sjhUrl: this.configService.get('sjhApi'),\n infoUrl: this.configService.get('infocenterApi'),\n marketplaceUrl: this.configService.get('marketplaceApi'),\n orderFulfillmentUrl: this.configService.webComponent.checkout.orderFulfillmentUrl,\n refreshTokenExpirationTimeInDays: 10,\n forceToAuth: this.configService.webComponent.checkout.forceToAuth,\n assetsPrefix: this.configService.webComponent.checkout.assetsPrefix,\n translationsUrl: this.configService.webComponent.checkout.translationsUrl,\n stylesUrl: this.configService.webComponent.checkout.stylesUrl,\n stripeInteractionStrategy: this.configService.get('environment') ?? 'prod',\n additionalHeaders: this.configService.get('localBackend')\n ? this.configService.webComponent.checkout.additionalHeaders\n : undefined,\n showSavePaymentMethod:\n this.configService.webComponent.checkout.showSavePaymentMethod ?? false,\n directCheckout: this.configService.webComponent.checkout.directCheckout ?? true,\n useCase: this.configService.webComponent.checkout.useCase,\n style: checkoutStyle,\n project: this.configService.webComponent.checkout.project,\n bookingEngineProject: this.configService.webComponent.checkout.bookingEngineProject,\n successPaymentPageUrl: this.configService.webComponent.checkout.successPaymentPageUrl,\n errorPaymentPageUrl: this.configService.webComponent.checkout.errorPaymentPageUrl,\n colorScheme: this.configService.webComponent.checkout.colorScheme, // check if present in config\n actionFooter: this.configService.webComponent.checkout.actionFooter, // check if present in config\n featureFlags: this.configService.webComponent.checkout.featureFlags,\n };\n }\n\n public patchConfig(patch: Record): void {\n this.configPatch$.next(patch);\n }\n\n public activateCheckoutCore(configPatch?: Record): void {\n this.configPatch$.next(configPatch!);\n this.checkoutCoreVisibilitySrc$.next(true);\n }\n\n public deactivateCheckoutCore(): void {\n this.configPatch$.next(null);\n this.checkoutCoreVisibilitySrc$.next(false);\n }\n\n public forceAuthHandler(payload?: Record): void {\n this.checkoutApp.forceCheckoutInProgress(true);\n this.checkoutApp.closeCheckout();\n const prefillEmail = payload?.email;\n const extras: NavigationExtras = {\n queryParams: prefillEmail ? {email: prefillEmail} : {},\n };\n this.router.navigate(['/'], extras);\n }\n\n private refreshAuthToken(): void {\n this.appInsightsService.trackTrace({\n message: `CheckoutCoreRegistererService.refreshAuthToken()`,\n });\n // due to MSAL handle the token refresh, we don't need to do anything here\n // the wrapper is added only for the proper logging\n this.getAuthToken();\n }\n\n private getAuthToken() {\n let account;\n account = !!this.msalService.instance.getActiveAccount()\n ? this.msalService.instance.getActiveAccount()\n : this.msalService.instance.getAllAccounts()[0];\n\n const accessTokenRequest: SilentRequest = {\n scopes: [this.configService.get('clientID')],\n account: account ?? undefined,\n };\n this.msalService.acquireTokenSilent(accessTokenRequest).subscribe({\n next: (tokenResponse) => {\n if (tokenResponse?.accessToken) {\n // The tokenType included the schema e.g. Bearer\n this._authToken$.next(\n `${tokenResponse?.tokenType} ${tokenResponse?.accessToken}`,\n );\n }\n this.triedGetAuthToken = true;\n },\n error: (error) => {\n this.appInsightsService.trackTrace({\n message: `CheckoutCoreRegistererService.getAuthToken().error`,\n properties: {error},\n });\n console.log('Error during acquiring auth token for checkout component');\n console.error(error);\n // logout user when we can't get tokens anymore\n this.authService.logout();\n this.triedGetAuthToken = true;\n },\n });\n }\n}\n"], "mappings": "+XAAA,IAAYA,EAAZ,SAAYA,EAAY,CACpBA,OAAAA,EAAA,SAAA,WADQA,CAEZ,EAFYA,GAAY,CAAA,CAAA,ECqCxB,IAAaC,GAA6B,IAAA,CAApC,IAAOA,EAAP,MAAOA,CAA6B,CAatC,IAAIC,WAAS,CACT,OAAO,KAAKC,YAAYC,KAC5B,CAIA,IAAIC,mBAAiB,CACjB,OAAO,KAAKC,oBAAoBF,KACpC,CACA,IAAIC,kBAAkBD,EAAc,CAChC,KAAKE,oBAAoBC,KAAKH,CAAK,CACvC,CA2CAI,aAAA,CAlEiB,KAAAC,YAAcC,EAAOC,CAAW,EAChC,KAAAC,qBAAuBF,EAAOG,CAAoB,EAClD,KAAAC,cAAgBJ,EAAOK,CAAoB,EAC3C,KAAAC,YAAcN,EAAOO,CAAqB,EAC1C,KAAAC,KAAOR,EAAOS,CAAe,EAC7B,KAAAC,OAASV,EAAOW,CAAM,EACtB,KAAAC,YAAcZ,EAAOa,CAAkB,EACvC,KAAAC,mBAAqBd,EAAOe,CAAkB,EAC9C,KAAAC,SAAWhB,EAAOiB,CAA4B,EAE9C,KAAAxB,YAAc,IAAIyB,EAA+B,IAAI,EACtD,KAAAC,WAAa,KAAK1B,YAAY2B,aAAY,EAKzC,KAAAxB,oBAAsB,IAAIsB,EAAyB,EAAK,EACzD,KAAAG,mBAAqB,KAAKzB,oBAAoBwB,aAAY,EAQzD,KAAAE,UAAY,KAAKN,WAAaO,EAAaC,SAE3C,KAAAC,aAAe,IAAIC,EAA0C,CAAC,E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,kBAAgB,CACpB,KAAKnD,mBAAmB4G,WAAW,CAC/BC,QAAS,mDACZ,EAGD,KAAK/D,aAAY,CACrB,CAEQA,cAAY,CAChB,IAAIgE,EACJA,EAAY,KAAK7H,YAAYyD,SAASG,iBAAgB,EAChD,KAAK5D,YAAYyD,SAASG,iBAAgB,EAC1C,KAAK5D,YAAYyD,SAASC,eAAc,EAAG,CAAC,EAElD,IAAMoE,EAAoC,CACtCC,OAAQ,CAAC,KAAK1H,cAAcqE,IAAI,UAAU,CAAC,EAC3CmD,QAASA,GAAWzB,QAExB,KAAKpG,YAAYgI,mBAAmBF,CAAkB,EAAEtE,UAAU,CAC9D1D,KAAOmI,GAAiB,CAChBA,GAAeC,aAEf,KAAKxI,YAAYI,KACb,GAAGmI,GAAeE,SAAS,IAAIF,GAAeC,WAAW,EAAE,EAGnE,KAAKtI,kBAAoB,EAC7B,EACAwI,MAAQA,GAAS,CACb,KAAKrH,mBAAmB4G,WAAW,CAC/BC,QAAS,qDACTS,WAAY,CAACD,MAAAA,CAAK,EACrB,EACDpE,QAAQC,IAAI,0DAA0D,EACtED,QAAQoE,MAAMA,CAAK,EAEnB,KAAK7H,YAAY+H,OAAM,EACvB,KAAK1I,kBAAoB,EAC7B,EACH,CACL,yCAvOSJ,EAA6B,wBAA7BA,EAA6B+I,QAA7B/I,EAA6BgJ,UAAAC,WAF1B,MAAM,CAAA,EAEhB,IAAOjJ,EAAPkJ,SAAOlJ,CAA6B,GAAA", "names": ["ViewTypeEnum", "CheckoutCoreRegistererService", "authToken", "_authToken$", "value", "triedGetAuthToken", "_triedGetAuthToken$", "next", "constructor", "msalService", "inject", "MsalService", "msalBroadcastService", "MsalBroadcastService", "configService", "ConfigurationService", "authService", "AuthenticationService", "lang", "LanguageService", "router", "Router", "checkoutApp", "CheckoutAppService", "appInsightsService", "AppInsightsService", "viewType", "DS_VIEW_TYPE_INJECTION_TOKEN", "BehaviorSubject", "authToken$", "asObservable", "triedGetAuthToken$", "isWebView", "ViewTypeEnum", "EMBEDDED", "configPatch$", "ReplaySubject", "checkoutConfig$", "pipe", "map", "patch", "__spreadValues", "checkoutConfig", "checkoutCoreVisibilitySrc$", "checkoutCoreVisibility$", "coreWebComponentPayload$", "combineLatest", "combineLatestWith", "filter", "languageChange$", "observeOn", "asapScheduler", "visible", "config", "language", "shareReplay", "refCount", "bufferSize", "_destroying$", "Subject", "inProgress$", "status", "InteractionStatus", "None", "takeUntil", "subscribe", "instance", "getAllAccounts", "length", "getActiveAccount", "getAuthToken", "fromEvent", "window", "console", "log", "refreshAuthToken", "event", "detail", "payload", "forceAuthHandler", "ngOnDestroy", "complete", "checkoutStyle", "get", "lightStyle", "light", "darkStyle", "dark", "patchedLightStyle", "__spreadProps", "patchedDarkStyle", "showTotalPriceInFooter", "webComponent", "checkout", "showGlobalHeader", "dateTimeInputType", "subscriptionKey", "profileUrl", "sjhUrl", "infoUrl", "marketplaceUrl", "orderFulfillmentUrl", "refreshTokenExpirationTimeInDays", "forceToAuth", "assetsPrefix", "translationsUrl", "stylesUrl", "stripeInteractionStrategy", "additionalHeaders", "undefined", "showSavePaymentMethod", "directCheckout", "useCase", "style", "project", "bookingEngineProject", "successPaymentPageUrl", "errorPaymentPageUrl", "colorScheme", "actionFooter", "featureFlags", "patchConfig", "activateCheckoutCore", "configPatch", "deactivateCheckoutCore", "forceCheckoutInProgress", "closeCheckout", "prefillEmail", "email", "extras", "queryParams", "navigate", "trackTrace", "message", "account", "accessTokenRequest", "scopes", "acquireTokenSilent", "tokenResponse", "accessToken", "tokenType", "error", "properties", "logout", "factory", "\u0275fac", "providedIn", "_CheckoutCoreRegistererService"] }