/// import { ApiPayload, Component, ComponentByExternalAlias, ComponentPayload, GetComponentByExternalAliasInput, SdkError, } from '@atlassian/forge-graphql-types'; import { CompassRequests } from '../../compass-requests'; import { mapGqlErrors, mapQueryErrors, parsingResponseError, transformGqlComponent, } from '../../helpers'; import { COMPONENT_BY_EXTERNAL_ALIAS_RETRIEVAL_OPTIONS } from '../../helpers/constants'; declare module '../../compass-requests' { interface CompassRequests { /** * Retrieves a single component by its external alias. * * **Required Oauth Scopes:** `read:component:compass` */ getComponentByExternalAlias( input: GetComponentByExternalAliasInput, ): Promise>; } } CompassRequests.prototype.getComponentByExternalAlias = async function getComponentByExternalAlias( this: CompassRequests, { options, ...getComponentInput }, ) { let component = null as Component; let errorsResp = [] as SdkError[]; try { const resp = await this.api.requestGraph( ComponentByExternalAlias, { ...getComponentInput, ...COMPONENT_BY_EXTERNAL_ALIAS_RETRIEVAL_OPTIONS, ...options, }, 'getComponentByExternalAlias', ); const { data, errors: gqlErrors } = await resp.json(); errorsResp = mapGqlErrors(gqlErrors); errorsResp = errorsResp.concat( mapQueryErrors(data.compass, [ 'componentByExternalAlias', 'componentByExternalAlias.relationships', 'componentByExternalAlias.metricSources', ]), ); if (errorsResp.length === 0) { component = transformGqlComponent( data.compass.componentByExternalAlias, ); } } catch (e) { if (errorsResp.length === 0) { errorsResp.push(parsingResponseError(e)); } } return { errors: errorsResp, success: errorsResp.length === 0, data: { component }, }; };