diff --git a/airbyte-webapp/src/services/connector/ConnectorService.ts b/airbyte-webapp/src/services/connector/ConnectorService.ts index 7b590dc40335..6e488830ca70 100644 --- a/airbyte-webapp/src/services/connector/ConnectorService.ts +++ b/airbyte-webapp/src/services/connector/ConnectorService.ts @@ -1,23 +1,46 @@ import { useConfig } from "config"; import { webBackendCheckUpdates, WebBackendCheckUpdatesRead } from "core/request/AirbyteClient"; import { AirbyteRequestService } from "core/request/AirbyteRequestService"; +import { RequestMiddleware } from "core/request/RequestMiddleware"; +import { FeatureItem, useFeature } from "hooks/services/Feature"; import { useDefaultRequestMiddlewares } from "services/useDefaultRequestMiddlewares"; import { useInitService } from "services/useInitService"; -import { isCloudApp } from "utils/app"; + +const NO_UPDATES: WebBackendCheckUpdatesRead = { + destinationDefinitions: 0, + sourceDefinitions: 0, +}; + +type EnabledFeatures = Partial>; class ConnectorService extends AirbyteRequestService { - checkUpdates(): Promise { - if (isCloudApp()) { - return Promise.resolve({ sourceDefinitions: 0, destinationDefinitions: 0 }); + constructor( + rootUrl: string, + middlewares: RequestMiddleware[] = [], + private readonly enabledFeatures: EnabledFeatures + ) { + super(rootUrl, middlewares); + this.enabledFeatures = enabledFeatures; + } + checkUpdates() { + if (this.enabledFeatures[FeatureItem.AllowUpdateConnectors]) { + return webBackendCheckUpdates(this.requestOptions); } - return webBackendCheckUpdates(this.requestOptions); + return Promise.resolve(NO_UPDATES); } } export function useConnectorService() { const { apiUrl } = useConfig(); + const enabledFeatures = { + [FeatureItem.AllowUpdateConnectors]: useFeature(FeatureItem.AllowUpdateConnectors), + }; + const requestAuthMiddleware = useDefaultRequestMiddlewares(); - return useInitService(() => new ConnectorService(apiUrl, requestAuthMiddleware), [apiUrl, requestAuthMiddleware]); + return useInitService( + () => new ConnectorService(apiUrl, requestAuthMiddleware, enabledFeatures), + [apiUrl, requestAuthMiddleware] + ); }