@contract-case/case-core
Version:
Core functionality for the ContractCase contract testing suite
56 lines • 1.96 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.configToRunContext = exports.configFromEnv = void 0;
const types_1 = require("./types");
const ENV_TO_CONFIG_KEY = {
CASE_BROKER_BASEURL: 'brokerBaseUrl',
CASE_BROKER_CI_TOKEN: 'brokerCiAccessToken',
...types_1.stringConfigArgs
.map((configKey) => ({
[`CASE_${configKey}`]: configKey,
}))
.reduce((acc, curr) => ({ ...acc, ...curr }), {}),
};
const value = (s) => {
if (s == null)
return s;
switch (s.toLowerCase()) {
case 'true':
return true;
case 'false':
return false;
default:
return s;
}
};
const configFromEnv = () => Object.entries(ENV_TO_CONFIG_KEY)
.filter(([envKey]) => process.env[envKey] !== undefined)
.map(([envKey, configKey]) => ({
[configKey]: value(process.env[envKey]),
}))
.reduce((acc, curr) => ({ ...acc, ...curr }), {});
exports.configFromEnv = configFromEnv;
/**
* This function takes a CaseConfig object and turns it into the appropriate
* RunContext values.
*
* Most of the time, this is a passthrough of the config property
* to a corresponding currentRun:config property.
*
* Occasionally you'll want to do explicit processing beyond this, however.
*
* @param config - the configuration object to map
* @returns a Partial RunContext object with anything that was set by the Config
*/
const configToRunContext = (config) => Object.entries(config)
.map(([k, v]) => ({
[`_case:currentRun:context:${k}`]: v,
}))
.reduce((acc, curr) => ({ ...acc, ...curr }), {
'_case:currentRun:context:connectorClient': process.env['CASE_CONNECTOR_CLIENT'] ?? 'No Connector Client Supplied',
'_case:currentRun:context:location': config.coreLogContextPrefix
? [config.coreLogContextPrefix]
: [],
});
exports.configToRunContext = configToRunContext;
//# sourceMappingURL=config.js.map