@usebruno/converters
Version:
The converters package is responsible for converting collections from one format to a Bruno collection. It can be used as a standalone package or as a part of the Bruno framework.
46 lines (37 loc) • 1.19 kB
JavaScript
import each from 'lodash/each';
import { invalidVariableCharacterRegex } from '../constants';
import { uuid } from '../common';
const isSecret = (type) => {
return type === 'secret';
};
const importPostmanEnvironmentVariables = (brunoEnvironment, values) => {
brunoEnvironment.variables = brunoEnvironment.variables || [];
each(values, (i) => {
const brunoEnvironmentVariable = {
uid: uuid(),
name: i.key.replace(invalidVariableCharacterRegex, '_'),
value: i.value,
enabled: i.enabled,
secret: isSecret(i.type)
};
brunoEnvironment.variables.push(brunoEnvironmentVariable);
});
};
const importPostmanEnvironment = (environment) => {
const brunoEnvironment = {
uid: uuid(),
name: environment.name,
variables: []
};
importPostmanEnvironmentVariables(brunoEnvironment, environment.values);
return brunoEnvironment;
};
export const postmanToBrunoEnvironment = (postmanEnvironment) => {
try {
return importPostmanEnvironment(postmanEnvironment);
} catch (err) {
console.log(err);
throw new Error('Unable to parse the postman environment json file');
}
};
export default postmanToBrunoEnvironment;