import{redocConfigSchema as m,rootRedoclyConfigSchema as t}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 h}from"./utils/read-and-validate-config.js";import{resolveExternalPlugins as v}from"../../../external-plugins/resolve-external-plugins.js";import{getPathForAllLocales as l}from"../../../fs/utils/get-path-for-all-locales.js";import{parseRbacConfig as y}from"../../../utils/rbac.js";import{RbacConfigLocation as E,validateRbacConfig as S}from"../../validate-rbac-config.js";const z=async(e,{fs:r},s)=>{const a=await h(e,r,s,async c=>e===f?g(r.cwd,c?.plugins||[]):void 0);if(a?.access?.rbac){const c=await y(a.access.rbac);a.access.rbac=c,S(c,e===f?E.RootRedoclyYaml:void 0)}(a?.l10n||a?.i18n)&&(a.l10n=L(a),a.i18n=void 0);const i=F(a||{},{markdown:{partialsFolders:(a?.markdown?.partialsFolders||[]).flatMap(c=>l(c,r))}});return R({...i,configPath:e,ignore:I(a?.ignore,r)})};async function g(e,r){const s=await v(e,r),a=s.map(n=>n.config.schema?n.lifecyclePlugin.id:""),i={};for(const n of s){const o=n.lifecyclePlugin?.id;n.config.schema&&o&&t.properties&&(i[o]=n.config.schema)}return{...t,properties:{...i,...t.properties,openapi:m},$id:t.$id+a.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={llmstxt:{hide:!0}}),r.canAccessFeature("redirects")||(e.redirects={}),r.canAccessFeature("l10n")||(e.l10n=void 0),r.canAccessFeature("rbac")||e.access&&(e.access.rbac=void 0),r.canAccessFeature("sso")||e.access&&(e.access.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,e.scorecardClassic=void 0),r.canAccessFeature("scorecards")||(e.scorecards=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),r.canAccessFeature("banner")||(e.banner=void 0),e}function I(e=[],r){return["static",...e].flatMap(s=>p(s)&&(s.startsWith("*")||s.startsWith(u)||s.startsWith("/"+u)||s.startsWith(d)||s.startsWith("/"+d))?s:l(s,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};
