import { HTTPAuthIntegrationType } from '@baserow/modules/integrations/core/integrationTypes' /** * The HTTP authentication integrations an HTTP request in the application can * use: its own and the workspace ones. * * @param {object} store The Vuex store. * @param {object} application The application the request belongs to. * @returns {Array} The integrations. */ export function getHTTPAuthIntegrations(store, application) { if (!application) { return [] } return store.getters['integration/getUsableIntegrations'](application).filter( ({ type }) => type === HTTPAuthIntegrationType.getType() ) } /** * The locked rows an HTTP authentication adds to a request, for the request * forms to show where the key goes without showing it. * * @param {object} context Anything with `$store` and `$registry`, like a * component. * @param {object} application The application the request belongs to. * @param {number|null} integrationId The integration the request uses. * @returns {{integration: object|null, header: object|null, query: object|null}} * The integration, and the locked header row or query parameter row. */ export function getHTTPAuthRows( { $store, $registry }, application, integrationId ) { const empty = { integration: null, header: null, query: null } if (!application || !integrationId) { return empty } const integration = $store.getters['integration/getIntegrationById']( application, integrationId ) if (!integration || integration.type !== HTTPAuthIntegrationType.getType()) { return empty } const placement = $registry .get('integration', HTTPAuthIntegrationType.getType()) .getPlacement(integration) const row = { name: placement.name, prefix: placement.prefix, source: integration.name, label: placement.label, } return { integration, header: placement.in === 'header' ? row : null, query: placement.in === 'query' ? row : null, } }