import { getFeature, DEFAULT_FEATURES } from "../featureFlags";
import axios from "axios";
export const getAllFeatureFlags = (appLanguage, localOverrides) => {
    const res = {};
    Object.keys(DEFAULT_FEATURES).forEach(k => {
        const key = k;
        const value = getFeature({ key, appLanguage, localOverrides });
        if (value !== null)
            res[key] = value;
    });
    return res;
};
export const formatFlagsData = (data) => {
    let allureData = "";
    for (const [key, value] of Object.entries(data)) {
        if (!value)
            continue;
        if (!value.enabled)
            continue;
        allureData += `FF.${key} = ${value.enabled}\n`;
        const entries = {
            desktop_version: value.desktop_version,
            mobile_version: value.mobile_version,
            enabledOverriddenForCurrentVersion: value.enabledOverriddenForCurrentVersion,
            languages_whitelisted: value.languages_whitelisted?.join(", "),
            languages_blacklisted: value.languages_blacklisted?.join(", "),
            enabledOverriddenForCurrentLanguage: value.enabledOverriddenForCurrentLanguage,
            overridesRemote: value.overridesRemote,
            overriddenByEnv: value.overriddenByEnv,
            params: value.params ? JSON.stringify(value.params) : undefined,
        };
        for (const [field, fieldValue] of Object.entries(entries)) {
            if (fieldValue !== undefined) {
                allureData += `FF.${key}.${field} = ${fieldValue
                    .toString()
                    .replace(/^\{|\}$/g, "")
                    .replace(/"/g, " ")}\n`;
            }
        }
    }
    return allureData;
};
export const formatEnvData = (data) => {
    let allureData = "";
    for (const [key, value] of Object.entries(data)) {
        allureData += `ENV.${key} = ${value}\n`;
    }
    return allureData;
};
export const sanitizeError = (error) => {
    if (!axios.isAxiosError(error)) {
        return error instanceof Error ? error : new Error(String(error ?? "Unknown error"));
    }
    const err = error;
    const sanitized = new Error(err.message || "Axios request failed");
    Object.assign(sanitized, {
        name: err.name,
        code: err.code,
        url: err.config?.url,
        method: err.config?.method,
        status: err.response?.status,
    });
    return sanitized;
};
//# sourceMappingURL=index.js.map