"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.serializeEnrichmentPolicies = exports.enrichPoliciesActions = void 0; /* * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one * or more contributor license agreements. Licensed under the Elastic License * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ const getPolicyType = policy => { if (policy.config.match) { return 'match'; } if (policy.config.geo_match) { return 'geo_match'; } if (policy.config.range) { return 'range'; } throw new Error('Unknown policy type'); }; const serializeEnrichmentPolicies = policies => { return policies.map(policy => { const policyType = getPolicyType(policy); return { name: policy.config[policyType].name, type: policyType, sourceIndices: policy.config[policyType].indices, matchField: policy.config[policyType].match_field, enrichFields: policy.config[policyType].enrich_fields }; }); }; exports.serializeEnrichmentPolicies = serializeEnrichmentPolicies; const fetchAll = async client => { const res = await client.asCurrentUser.enrich.getPolicy(); return serializeEnrichmentPolicies(res.policies); }; const enrichPoliciesActions = { fetchAll }; exports.enrichPoliciesActions = enrichPoliciesActions;