///
import {
ApiPayload,
CompassCatalogBootstrap,
GetCatalogBootstrapStatus,
SdkError,
} from '@atlassian/forge-graphql-types';
import { CompassRequests } from '../../compass-requests';
import {
mapGqlErrors,
mapQueryErrors,
parsingResponseError,
} from '../../helpers';
declare module '../../compass-requests' {
interface CompassRequests {
/**
* Retrieves catalog bootstrap status.
*
* **Required Oauth Scopes:** `read:component:compass`
*/
getCatalogBootstrapStatus(
cloudId: string,
): Promise>;
}
}
CompassRequests.prototype.getCatalogBootstrapStatus =
async function getCatalogBootstrapStatus(
this: CompassRequests,
cloudId: string,
) {
let catalogBootstrap: CompassCatalogBootstrap = null;
let errorsResp: SdkError[] = [];
try {
const resp = await this.api.requestGraph(
GetCatalogBootstrapStatus,
{ cloudId },
'getCatalogBootstrapStatus',
);
const { data, errors: gqlErrors } = await resp.json();
errorsResp = mapGqlErrors(gqlErrors);
errorsResp = errorsResp.concat(
mapQueryErrors(data.compass, ['catalogBootstrap']),
);
if (errorsResp.length === 0) {
catalogBootstrap = data?.compass?.catalogBootstrap;
}
} catch (e) {
if (errorsResp.length === 0) {
errorsResp.push(parsingResponseError(e));
}
}
return {
errors: errorsResp,
success: errorsResp.length === 0,
data: catalogBootstrap,
};
};