2020-08-25 11:57:35 +00:00
|
|
|
// @flow
|
|
|
|
|
2021-01-15 12:44:24 +00:00
|
|
|
import { SET_ENDPOINT_COUNTED } from './actionTypes';
|
2020-08-25 11:57:35 +00:00
|
|
|
import { extractVpaasTenantFromPath, getBillingId, sendCountRequest } from './functions';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sends a billing count request when needed.
|
|
|
|
*
|
|
|
|
* @returns {Function}
|
|
|
|
*/
|
|
|
|
export function countEndpoint() {
|
|
|
|
return function(dispatch: Function, getState: Function) {
|
|
|
|
const state = getState();
|
|
|
|
const baseUrl = state['features/base/config'].billingCounterUrl;
|
|
|
|
const jwt = state['features/base/jwt'].jwt;
|
|
|
|
const tenant = extractVpaasTenantFromPath(state['features/base/connection'].locationURL.pathname);
|
|
|
|
const shouldSendRequest = Boolean(baseUrl && jwt && tenant);
|
|
|
|
|
|
|
|
if (shouldSendRequest) {
|
2021-01-15 12:44:24 +00:00
|
|
|
const billingId = getBillingId();
|
2020-08-25 11:57:35 +00:00
|
|
|
|
|
|
|
sendCountRequest({
|
|
|
|
baseUrl,
|
|
|
|
billingId,
|
|
|
|
jwt,
|
|
|
|
tenant
|
|
|
|
});
|
2020-09-17 09:21:01 +00:00
|
|
|
dispatch(setEndpointCounted());
|
2020-08-25 11:57:35 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-09-17 09:21:01 +00:00
|
|
|
/**
|
|
|
|
* Action used to mark the endpoint as counted.
|
|
|
|
*
|
|
|
|
* @returns {Object}
|
|
|
|
*/
|
|
|
|
function setEndpointCounted() {
|
|
|
|
return {
|
|
|
|
type: SET_ENDPOINT_COUNTED
|
|
|
|
};
|
|
|
|
}
|