UNPKG

@creditkarma/dynamic-config

Version:

Dynamic Config for Node.js backed by Consul and Vault

48 lines 1.44 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.consulTranslator = void 0; const utils_1 = require("../utils"); const CONSUL_PREFIX = 'consul!/'; function isPlaceholderKey(key) { if (key.startsWith(CONSUL_PREFIX)) { return key.replace(CONSUL_PREFIX, ''); } return undefined; } function isConsulPlaceholder(obj) { return utils_1.JSONUtils.objectMatchesSchema({ type: 'object', properties: { default: {}, key: { type: 'string', }, }, required: ['key'], }, obj); } exports.consulTranslator = { translate(configValue) { if (typeof configValue === 'string') { const placeholderKey = isPlaceholderKey(configValue); if (placeholderKey !== undefined) { return { _source: 'consul', _key: placeholderKey, }; } } else if (typeof configValue === 'object') { if (isConsulPlaceholder(configValue) && configValue.key.startsWith(CONSUL_PREFIX)) { return { _source: 'consul', _key: configValue.key.replace(CONSUL_PREFIX, ''), _default: configValue.default, }; } } return configValue; }, }; //# sourceMappingURL=consul.js.map