/*! * SAPUI5 * Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved. */ import { isCentralFioriLaunchpad } from "./SearchShellHelperCentralFioriLaunchpad"; import { FederationType } from "./sinaNexTS/providers/multi/FederationType"; import { AvailableProviders, SinaConfiguration } from "./sinaNexTS/sina/SinaConfiguration"; import Container from "sap/ushell/Container"; interface ClientSideTargetResolutionService { getSystemContext(id: string): Promise<{ getProperty(name: string): string; getFullyQualifiedXhrUrl(url: string): string; }>; } async function createContentProviderSinaConfiguration( contentProviderId: string ): Promise { const service = (await Container.getServiceAsync( "ClientSideTargetResolution" )) as ClientSideTargetResolutionService; const oSystemContext = await service.getSystemContext(contentProviderId); // uncoment for cflp jade dev env: /*const fixProtocol = { enable: async function () { this.ctr = await (function () { return new Promise((resolve) => { sap.ui.require( ["sap/ushell/services/ClientSideTargetResolution/SystemContext"], function (ctr) { resolve(ctr); } ); }); })(); this._getProtocol = this.ctr._getProtocol; this.ctr._getProtocol = () => "https"; }, disable: function () { this.ctr._getProtocol = this._getProtocol; }, }; await fixProtocol.enable();*/ const sRequestUrlForAppRouter = oSystemContext.getFullyQualifiedXhrUrl( "sap/opu/odata/sap/ESH_SEARCH_SRV" ); const sinaProviderType = oSystemContext.getProperty("esearch.provider"); if (!sinaProviderType) { // destination of this content provider has no launchpad.esearch.provider property // -> not relevant for search return; } return { contentProviderId, provider: sinaProviderType.toLowerCase() as AvailableProviders, label: contentProviderId, url: sRequestUrlForAppRouter, }; } export async function readCFlpConfiguration( sinaConfigurations: Array ): Promise> { if (!isCentralFioriLaunchpad()) { return Promise.resolve(sinaConfigurations); // -> not active -> do nothing } // read content providers from cflp configuration const service = (await Container.getServiceAsync("CommonDataModel")) as any; const oApplications = await service.getApplications(); // extract content provider ids const oContentProviders = Object.keys(oApplications).reduce(function (o, sApplicationKey) { const oApplication = oApplications[sApplicationKey]; const sContentProviderId = oApplication["sap.app"] && oApplication["sap.app"].contentProviderId; if (sContentProviderId) { o[sContentProviderId] = true; } return o; }, {}); const contentProviderIds = Object.keys(oContentProviders); // create sina provider configuration const promises = []; for (let i = 0; i < contentProviderIds.length; ++i) { const contentProviderId = contentProviderIds[i]; promises.push(createContentProviderSinaConfiguration(contentProviderId)); } let subSinaProviderConfigurations: Array = await Promise.all(promises); if (!subSinaProviderConfigurations || subSinaProviderConfigurations.length === 0) { // fallback if configuration is empty return sinaConfigurations; } else { // assemble multi provider configuration subSinaProviderConfigurations = subSinaProviderConfigurations.filter(function (elem) { if (typeof elem !== "undefined") { return elem; } }); return [ { provider: AvailableProviders.MULTI, subProviders: subSinaProviderConfigurations, federationType: FederationType.advanced_round_robin, url: "", // not relevant for multi provider }, AvailableProviders.DUMMY, ]; } }