import{redocConfigSchema as m,rootRedoclyConfigSchema as c}from"@redocly/config";import p from"is-glob";import{I18N_DIR_NAME as d,L10N_DIR_NAME as u}from"../../../constants/common.js";import{CONFIG_FILE_NAME as f}from"../../../../constants/common.js";import{DEFAULT_SEARCH_ENGINE as A}from"../../../constants/plugins/search.js";import{deepMerge as F}from"../../../../utils/object/deep-merge.js";import{logger as b}from"../../../tools/notifiers/logger.js";import{EntitlementsProvider as C}from"../../../entitlements/entitlements-provider.js";import{readAndValidateConfig as g}from"./utils/read-and-validate-config.js";import{resolvePlugins as h}from"../../../config/external-plugins.js";import{getPathForAllLocales as l}from"../../../fs/utils/get-path-for-all-locales.js";import{parseRbacConfig as v}from"../../../utils/rbac.js";import{RbacConfigLocation as y,validateRbacConfig as S}from"../../validate-rbac-config.js";const z=async(e,{fs:r},i)=>{const n=await g(e,r,i,async s=>e===f?E(r.cwd,s?.plugins||[]):void 0);n?.rbac&&(n.rbac=v(n.rbac),S(n.rbac,e===f?y.RootRedoclyYaml:void 0)),(n?.l10n||n?.i18n)&&(n.l10n=L(n),n.i18n=void 0);const t=F(n||{},{markdown:{partialsFolders:(n?.markdown?.partialsFolders||[]).flatMap(s=>l(s,r))}});return R({...t,configPath:e,ignore:I(n?.ignore,r)})};async function E(e,r){const i=await h(e,r),n=i.map(a=>a.config.schema?a.lifecyclePlugin.id:""),t={};for(const a of i){const o=a.lifecyclePlugin?.id;a.config.schema&&o&&c.properties&&(t[o]=a.config.schema)}return{...c,properties:{...t,...c.properties,openapi:m},$id:c.$id+n.join("")}}function R(e){const r=C.instance();return r.canAccessFeature("apiFunctions")||(e.apiFunctions=void 0),r.canAccessFeature("products")||(e.products=void 0),r.canAccessFeature("breadcrumbs")||(e.breadcrumbs={hide:!0}),r.canAccessFeature("seo")||(e.seo=void 0),r.canAccessFeature("redirects")||(e.redirects={}),r.canAccessFeature("l10n")||(e.l10n=void 0),r.canAccessFeature("rbac")||(e.rbac=void 0),r.canAccessFeature("sso")||(e.sso=void 0),r.canAccessFeature("ssoDirect")||(e.ssoDirect=void 0),r.canAccessFeature("catalogClassic")||(e.catalog=void 0,e.catalogClassic=void 0),r.canAccessFeature("scorecard")||(e.scorecard=void 0),r.canAccessFeature("devOnboarding")||(e.developerOnboarding=void 0),r.canAccessFeature("analytics")||(e.analytics=void 0),r.canAccessFeature("removeAttribution")||(e.removeAttribution=void 0),r.canAccessFeature("mockServer")||(e.mockServer={off:!0}),r.canAccessFeature("advancedSearch")||e.search&&(e.search.engine=A),e}function I(e=[],r){return["static",...e].flatMap(i=>p(i)&&(i.startsWith("*")||i.startsWith(u)||i.startsWith("/"+u)||i.startsWith(d)||i.startsWith("/"+d))?i:l(i,r))}function L(e){return e.i18n&&b.warn("The `i18n` configuration is deprecated. Please use `l10n` instead."),e.l10n||e.i18n||{}}export{z as redoclyConfigLoader};
