import{redocConfigSchema as m,rootRedoclyConfigSchema as c}from"@redocly/config";import p from"is-glob";import{CONFIG_FILE_NAME as d}from"../../../../constants/index.js";import{I18N_DIR_NAME as u,L10N_DIR_NAME as f}from"../../../constants/common.js";import{EntitlementsProvider as A}from"../../../entitlements/entitlements-provider.js";import{readAndValidateConfig as F}from"./utils/read-and-validate-config.js";import{resolvePlugins as b}from"../../../config/external-plugins.js";import{deepMerge as C}from"../../../../shared/jsUtils.js";import{getPathForAllLocales as l}from"../../../fs/utils/get-path-for-all-locales.js";import{parseRbacConfig as g}from"../../../utils/rbac.js";import{logger as h}from"../../../utils/index.js";import{RbacConfigLocation as v,validateRbacConfig as y}from"../../validate-rbac-config.js";import{DEFAULT_SEARCH_ENGINE as S}from"../../search/constants.js";const z=async(e,{fs:r},i)=>{const n=await F(e,r,i,async s=>e===d?E(r.cwd,s?.plugins||[]):void 0);n?.rbac&&(n.rbac=g(n.rbac),y(n.rbac,e===d?v.RootRedoclyYaml:void 0)),(n?.l10n||n?.i18n)&&(n.l10n=L(n),n.i18n=void 0);const t=C(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 b(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=A.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=S),e}function I(e=[],r){return["static",...e].flatMap(i=>p(i)&&(i.startsWith("*")||i.startsWith(f)||i.startsWith("/"+f)||i.startsWith(u)||i.startsWith("/"+u))?i:l(i,r))}function L(e){return e.i18n&&h.warn("The `i18n` configuration is deprecated. Please use `l10n` instead."),e.l10n||e.i18n||{}}export{z as redoclyConfigLoader};
