"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
function _export(target, all) {
    for(var name in all)Object.defineProperty(target, name, {
        enumerable: true,
        get: Object.getOwnPropertyDescriptor(all, name).get
    });
}
_export(exports, {
    get SECRET_PLACEHOLDER () {
        return SECRET_PLACEHOLDER;
    },
    get extractDefaults () {
        return extractDefaults;
    },
    get extractSecretPaths () {
        return extractSecretPaths;
    },
    get getSettingAtPath () {
        return getSettingAtPath;
    },
    get isSecretPath () {
        return isSecretPath;
    },
    get isSetting () {
        return isSetting;
    },
    get isSettingsSchema () {
        return isSettingsSchema;
    },
    get maskSecrets () {
        return maskSecrets;
    }
});
const _lodash = require("lodash");
const isSetting = (value)=>{
    return Boolean(value) && (0, _lodash.isObject)(value) && 'type' in value;
};
const isSettingsSchema = (value)=>{
    return value && (0, _lodash.isObject)(value) && 'properties' in value;
};
const extractDefaults = (settings)=>{
    const result = (0, _lodash.mapValues)(settings.properties, (value)=>isSetting(value) ? value.defaultValue : extractDefaults(value));
    return (0, _lodash.omitBy)(result, _lodash.isUndefined);
};
const extractSecretPaths = (schema, parentKey = '')=>{
    const paths = [];
    for (const [key, value] of Object.entries(schema.properties)){
        const fullKey = parentKey ? `${parentKey}.${key}` : key;
        if (isSetting(value)) {
            if (value.secret) {
                paths.push(fullKey);
            }
        } else if (isSettingsSchema(value)) {
            paths.push(...extractSecretPaths(value, fullKey));
        }
    }
    return paths;
};
const SECRET_PLACEHOLDER = '••••••••';
const maskSecrets = (settings, secretPaths)=>{
    const masked = (0, _lodash.cloneDeep)(settings);
    for (const path of secretPaths){
        const value = (0, _lodash.get)(masked, path);
        if (value !== undefined && value !== null && value !== '') {
            (0, _lodash.set)(masked, path, SECRET_PLACEHOLDER);
        }
    }
    return masked;
};
const getSettingAtPath = (schema, path)=>{
    const parts = path.split('.');
    let current = schema;
    for (const part of parts){
        if (!isSettingsSchema(current)) {
            return null;
        }
        const next = current.properties[part];
        if (!next) {
            return null;
        }
        current = next;
    }
    return isSetting(current) ? current : null;
};
const isSecretPath = (schema, path)=>{
    const setting = getSettingAtPath(schema, path);
    return setting?.secret === true;
};

//# sourceMappingURL=utils.js.map