diff --git a/src/services/api/base.ts b/src/services/api/base.ts index 13d8e056f8..a222b04ed3 100644 --- a/src/services/api/base.ts +++ b/src/services/api/base.ts @@ -16,19 +16,19 @@ export type AxiosOptions = { }; export interface BaseAPIParams { - singleClusterMode?: boolean; - proxyMeta?: boolean; + singleClusterMode: undefined | boolean; + proxyMeta: undefined | boolean; } export class BaseYdbAPI extends AxiosWrapper { DEFAULT_RETRIES_COUNT = 0; - singleClusterMode?: boolean; + singleClusterMode: BaseAPIParams['singleClusterMode']; - constructor(axiosOptions?: AxiosWrapperOptions, {singleClusterMode}: BaseAPIParams = {}) { + constructor(axiosOptions: AxiosWrapperOptions, baseApiParams: BaseAPIParams) { super(axiosOptions); - this.singleClusterMode = singleClusterMode; + this.singleClusterMode = baseApiParams.singleClusterMode; axiosRetry(this._axios, { retries: this.DEFAULT_RETRIES_COUNT, diff --git a/src/services/api/index.ts b/src/services/api/index.ts index 890c11e125..2bd3b439ab 100644 --- a/src/services/api/index.ts +++ b/src/services/api/index.ts @@ -15,6 +15,18 @@ import {TabletsAPI} from './tablets'; import {VDiskAPI} from './vdisk'; import {ViewerAPI} from './viewer'; +// Require all fields to be explicitly passed +// It is needed to prevent forgotten params in installations +// Where ydb-embedded-ui is used as a package +interface YdbEmbeddedAPIProps { + webVersion: undefined | boolean; + withCredentials: undefined | boolean; + singleClusterMode: undefined | boolean; + proxyMeta: undefined | boolean; + csrfTokenGetter: undefined | (() => string | undefined); + defaults: undefined | AxiosRequestConfig; +} + export class YdbEmbeddedAPI { auth: AuthAPI; operation: OperationAPI; @@ -25,24 +37,18 @@ export class YdbEmbeddedAPI { tablets: TabletsAPI; vdisk: VDiskAPI; viewer: ViewerAPI; + meta?: MetaAPI; codeAssist?: CodeAssistAPI; constructor({ webVersion = false, withCredentials = false, - singleClusterMode, + singleClusterMode = true, + proxyMeta = false, csrfTokenGetter = () => undefined, defaults = {}, - proxyMeta = false, - }: { - webVersion?: boolean; - withCredentials?: boolean; - singleClusterMode?: boolean; - csrfTokenGetter?: () => string | undefined; - defaults?: AxiosRequestConfig; - proxyMeta?: boolean; - } = {}) { + }: YdbEmbeddedAPIProps) { const axiosParams: AxiosWrapperOptions = {config: {withCredentials, ...defaults}}; const baseApiParams = {singleClusterMode, proxyMeta}; diff --git a/src/services/api/meta.ts b/src/services/api/meta.ts index 877bc3f39d..dd2182bad2 100644 --- a/src/services/api/meta.ts +++ b/src/services/api/meta.ts @@ -14,11 +14,12 @@ import type {AxiosOptions, BaseAPIParams} from './base'; import {BaseYdbAPI} from './base'; export class MetaAPI extends BaseYdbAPI { - proxyMeta?: boolean; - constructor(axiosOptions?: AxiosWrapperOptions, {proxyMeta}: BaseAPIParams = {}) { - super(axiosOptions); + proxyMeta: BaseAPIParams['proxyMeta']; - this.proxyMeta = proxyMeta; + constructor(axiosOptions: AxiosWrapperOptions, baseApiParams: BaseAPIParams) { + super(axiosOptions, baseApiParams); + + this.proxyMeta = baseApiParams.proxyMeta; } getPath(path: string, clusterName?: string) { if (this.proxyMeta && clusterName) { diff --git a/src/store/configureStore.ts b/src/store/configureStore.ts index c649997276..b73cca461a 100644 --- a/src/store/configureStore.ts +++ b/src/store/configureStore.ts @@ -61,6 +61,9 @@ export function configureStore({ webVersion, singleClusterMode: isSingleClusterMode, withCredentials: !customBackend, + proxyMeta: false, + csrfTokenGetter: undefined, + defaults: undefined, }), } = {}) { const params = getUrlData({singleClusterMode, customBackend}); diff --git a/src/uiFactory/types.ts b/src/uiFactory/types.ts index 7785948275..c0e1ce11e3 100644 --- a/src/uiFactory/types.ts +++ b/src/uiFactory/types.ts @@ -32,12 +32,8 @@ export interface UIFactory { getDatabaseLinks?: GetDatabaseLinks; getClusterLinks?: GetClusterLinks; - renderBackups?: (props: { - database: string; - scrollContainerRef: React.RefObject; - }) => React.ReactNode; - - renderEvents?: () => React.ReactNode; + renderBackups?: RenderBackups; + renderEvents?: RenderEvents; healthcheck: { getHealthckechViewTitles: GetHealthcheckViewTitles; @@ -73,3 +69,10 @@ export type GetDatabaseLinks = (params: { }) => DatabaseLink[]; export type GetClusterLinks = (params: {clusterInfo: ClusterInfo}) => ClusterLink[]; + +export type RenderBackups = (props: { + database: string; + scrollContainerRef: React.RefObject; +}) => React.ReactNode; + +export type RenderEvents = () => React.ReactNode;