@redocly/framework 1.0.0-next.8 → 1.0.0-next.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundler/build/output-metadata.js +1 -1
- package/dist/bundler/build/run.js +1 -1
- package/dist/bundler/dev/run.js +1 -1
- package/dist/bundler/dev/runtime-app.js +1 -1
- package/dist/bundler/dev/vite-config.js +1 -1
- package/dist/bundler/user-markdoc-schema.js +1 -1
- package/dist/bundler/vite-config.base.js +8 -8
- package/dist/cli/args.js +1 -1
- package/dist/cli/commands/translate.js +1 -1
- package/dist/cli/dev-console/index.js +1 -1
- package/dist/cli/dev-console/tui.js +1 -1
- package/dist/cli/output.js +12 -12
- package/dist/cli/validate-react-pages.js +1 -1
- package/dist/client/app.js +1 -1
- package/dist/client/history-mount.js +1 -0
- package/dist/client/revisions-history.js +1 -1
- package/dist/content-layer/database/files.js +1 -1
- package/dist/content-layer/database/finalize.js +1 -1
- package/dist/content-layer/database/origins.js +1 -1
- package/dist/content-layer/ingest/finalize-phase.js +1 -1
- package/dist/content-layer/ingest/l10n-warnings.js +1 -1
- package/dist/content-layer/ingest/markdoc-schema-problem.js +1 -0
- package/dist/content-layer/ingest/run.js +1 -1
- package/dist/content-layer/ingest/search-sync.js +1 -1
- package/dist/content-layer/ingest/sync.js +1 -1
- package/dist/content-layer/link-checker/delta.js +1 -1
- package/dist/content-layer/link-checker/run-build.js +1 -1
- package/dist/content-layer/loaders/context.js +1 -1
- package/dist/content-layer/markdown/constants/markdown-text-tag-set.js +1 -1
- package/dist/content-layer/markdown/constants/tag-sets.d.ts +11 -2
- package/dist/content-layer/markdown/constants/tag-sets.js +1 -1
- package/dist/content-layer/markdown/resolve/markdoc-resolvers/file-reference.js +1 -1
- package/dist/content-layer/markdown/resolve/markdoc-resolvers/json-schema.js +1 -1
- package/dist/content-layer/markdown/resolve/markdoc-resolvers/operation-samples.js +1 -1
- package/dist/content-layer/markdown/resolve/markdoc-resolvers/partial.js +1 -1
- package/dist/content-layer/markdown/resolve/markdoc-resolvers/svg-content.js +1 -1
- package/dist/content-layer/markdown/resolve/markdoc.js +1 -1
- package/dist/content-layer/markdown/resolve/references.d.ts +3 -1
- package/dist/content-layer/markdown/resolve/references.js +1 -1
- package/dist/content-layer/markdown/search/to-sections.d.ts +7 -2
- package/dist/content-layer/markdown/search/to-sections.js +1 -1
- package/dist/content-layer/markdown/search/to-text.js +5 -5
- package/dist/content-layer/markdown/server/render.js +1 -1
- package/dist/content-layer/markdown/service.js +1 -1
- package/dist/content-layer/markdown/types/service.d.ts +2 -0
- package/dist/content-layer/markdown/utils/first-heading.js +1 -1
- package/dist/content-layer/markdown/utils/parse-cache.js +1 -1
- package/dist/content-layer/materialization/entity.js +1 -1
- package/dist/content-layer/materialization/static-files.js +1 -1
- package/dist/content-layer/plugins/internal/api-docs/index.js +1 -1
- package/dist/content-layer/plugins/internal/api-docs/server/build-definition.js +1 -1
- package/dist/content-layer/plugins/internal/api-docs/server/markdown-docs.js +11 -11
- package/dist/content-layer/plugins/internal/api-docs/server/options.js +1 -1
- package/dist/content-layer/plugins/internal/api-docs/server/search-documents.js +1 -1
- package/dist/content-layer/plugins/internal/api-functions/server/dispatch.js +1 -1
- package/dist/content-layer/plugins/internal/app-data/banner.js +1 -1
- package/dist/content-layer/plugins/internal/app-data/index.d.ts +1 -1
- package/dist/content-layer/plugins/internal/app-data/index.js +1 -1
- package/dist/content-layer/plugins/internal/catalog-classic/index.js +1 -1
- package/dist/content-layer/plugins/internal/catalog-classic/resolve-items.js +1 -1
- package/dist/content-layer/plugins/internal/l10n/translations-loader.js +1 -1
- package/dist/content-layer/plugins/internal/markdoc/index.js +1 -1
- package/dist/content-layer/plugins/internal/mcp/server/agent-card.js +1 -1
- package/dist/content-layer/plugins/internal/mcp/server/auth.js +1 -1
- package/dist/content-layer/plugins/internal/mcp/server/custom-tools.js +1 -1
- package/dist/content-layer/plugins/internal/mcp/server/handler.js +1 -1
- package/dist/content-layer/plugins/internal/mcp/server/mcp-telemetry.js +1 -1
- package/dist/content-layer/plugins/internal/mcp/server/oauth/authorize.js +1 -1
- package/dist/content-layer/plugins/internal/mcp/server/oauth/callback.js +1 -1
- package/dist/content-layer/plugins/internal/mcp/server/oauth/discovery.js +1 -1
- package/dist/content-layer/plugins/internal/mcp/server/oauth/token.js +1 -1
- package/dist/content-layer/plugins/internal/mcp/server/oauth/tokens.js +1 -1
- package/dist/content-layer/plugins/internal/mcp/server/server-card.js +1 -1
- package/dist/content-layer/plugins/internal/mcp/server/skills-resources.js +1 -1
- package/dist/content-layer/plugins/internal/sidebar/bundle.d.ts +15 -15
- package/dist/content-layer/plugins/internal/sidebar/bundle.js +1 -1
- package/dist/content-layer/plugins/internal/sidebar/index.d.ts +1 -1
- package/dist/content-layer/plugins/internal/sidebar/index.js +2 -2
- package/dist/content-layer/plugins/internal/skills/server/routes.js +1 -1
- package/dist/content-layer/plugins/internal/versions/index.js +1 -1
- package/dist/content-layer/plugins/project/load.js +2 -2
- package/dist/content-layer/plugins/utils/link-access.d.ts +2 -0
- package/dist/content-layer/plugins/utils/link-access.js +1 -1
- package/dist/content-layer/problems/codes.js +1 -1
- package/dist/content-layer/search/postings/postings-store.js +1 -1
- package/dist/content-layer/server/database.js +1 -1
- package/dist/content-layer/static/registry.js +1 -1
- package/dist/server/app.js +2 -2
- package/dist/server/ask-ai/route.js +1 -1
- package/dist/server/auth/middleware.js +1 -1
- package/dist/server/auth/routes.js +1 -1
- package/dist/server/content.js +9 -9
- package/dist/server/lambda-entry.js +1 -1
- package/dist/server/node-entry.js +1 -1
- package/dist/server/page-handlers.js +2 -2
- package/dist/server/search/route.js +1 -1
- package/dist/server/seo-tags.js +2 -2
- package/dist/server/static-files/serve.js +1 -1
- package/dist/server/subprocess/child-entry.js +1 -1
- package/dist/server/subprocess/host.js +1 -1
- package/dist/shared/constants/l10n/langs/ar.js +1 -1
- package/dist/shared/constants/l10n/langs/de.js +1 -1
- package/dist/shared/constants/l10n/langs/en.js +1 -1
- package/dist/shared/constants/l10n/langs/es.js +1 -1
- package/dist/shared/constants/l10n/langs/fr.js +1 -1
- package/dist/shared/constants/l10n/langs/hi.js +1 -1
- package/dist/shared/constants/l10n/langs/it.js +1 -1
- package/dist/shared/constants/l10n/langs/ja.js +1 -1
- package/dist/shared/constants/l10n/langs/ko.js +1 -1
- package/dist/shared/constants/l10n/langs/pl.js +1 -1
- package/dist/shared/constants/l10n/langs/pt-br.js +1 -1
- package/dist/shared/constants/l10n/langs/pt.js +1 -1
- package/dist/shared/constants/l10n/langs/ru.js +1 -1
- package/dist/shared/constants/l10n/langs/uk.js +1 -1
- package/dist/shared/constants/l10n/langs/zh.js +1 -1
- package/dist/shared/constants/versions.d.ts +2 -0
- package/dist/shared/constants/versions.js +1 -1
- package/dist/shared/rbac/api-docs.js +1 -1
- package/dist/shared/rbac/l10n-rules.js +1 -1
- package/dist/shared/rbac/team-templates.js +1 -1
- package/dist/shared/utils/l10n.js +1 -1
- package/package.json +8 -8
|
@@ -1 +1 @@
|
|
|
1
|
-
import{defineContentPlugin as e}from"../../define.js";import{toJsonObject as t,toJsonValue as n}from"../../../database/utils/json.js";import{createEntityLoader as r}from"../../../loaders/define.js";import{createPluginScopedId as i}from"../../utils/scoped-id.js";import{buildSearchAppData as a}from"../../../../shared/search/facets.js";import{isAttributionRemoved as o,isPlanFeatureGranted as s}from"../../../../shared/plan-gates.js";import{isObject as c}from"../../../../shared/utils/is-object.js";import{isAiHidden as l}from"../../../../shared/ask-ai/config-gate.js";import{APP_DATA_STATIC_DATA_SLUG as u}from"../../../../shared/constants/app-data.js";import{splitUrlSuffix as d}from"../../../../shared/utils/routes/split-url-suffix.js";import{toNavItemRbacAnnotation as f}from"../../../../shared/rbac/filter.js";import{resolvePageTarget as p}from"../../../../shared/utils/routes/resolve-page-target.js";import{listConfiguredProducts as m}from"../../../products.js";import{collectVersionGroups as h,findVersionedDirectories as g}from"../../../versions/version-groups.js";import{publicLink as _}from"../../../versions/public-link.js";import{linkedPageAccess as v}from"../../utils/link-access.js";import{loadSidebarSubtreeLabel as y}from"../../utils/sidebar-label.js";import{resolveBannerForAppData as ee}from"./banner.js";import{resolveLogoForAppData as te}from"./logo.js";import{resolveNavbarIconsForAppData as b}from"./navbar-icons.js";import{resolveHtmlForAppData as x}from"./html.js";import{resolveSeoForAppData as S}from"./seo.js";import{productConfigPath as C,productLandingLink as w,readProductConfig as T,resolveProductAssetsForAppData as E}from"./products.js";import{dirname as D,resolve as O}from"node:path";import{REDOCLY_TEAMS_RBAC as k}from"@redocly/config";const A=`internal.app-data`,j=`1.
|
|
1
|
+
import{defineContentPlugin as e}from"../../define.js";import{toJsonObject as t,toJsonValue as n}from"../../../database/utils/json.js";import{createEntityLoader as r}from"../../../loaders/define.js";import{createPluginScopedId as i}from"../../utils/scoped-id.js";import{buildSearchAppData as a}from"../../../../shared/search/facets.js";import{isAttributionRemoved as o,isPlanFeatureGranted as s}from"../../../../shared/plan-gates.js";import{isObject as c}from"../../../../shared/utils/is-object.js";import{isAiHidden as l}from"../../../../shared/ask-ai/config-gate.js";import{APP_DATA_STATIC_DATA_SLUG as u}from"../../../../shared/constants/app-data.js";import{splitUrlSuffix as d}from"../../../../shared/utils/routes/split-url-suffix.js";import{toNavItemRbacAnnotation as f}from"../../../../shared/rbac/filter.js";import{resolvePageTarget as p}from"../../../../shared/utils/routes/resolve-page-target.js";import{listConfiguredProducts as m}from"../../../products.js";import{collectVersionGroups as h,findVersionedDirectories as g}from"../../../versions/version-groups.js";import{publicLink as _}from"../../../versions/public-link.js";import{linkedPageAccess as v}from"../../utils/link-access.js";import{loadSidebarSubtreeLabel as y}from"../../utils/sidebar-label.js";import{resolveBannerForAppData as ee}from"./banner.js";import{resolveLogoForAppData as te}from"./logo.js";import{resolveNavbarIconsForAppData as b}from"./navbar-icons.js";import{resolveHtmlForAppData as x}from"./html.js";import{resolveSeoForAppData as S}from"./seo.js";import{productConfigPath as C,productLandingLink as w,readProductConfig as T,resolveProductAssetsForAppData as E}from"./products.js";import{dirname as D,resolve as O}from"node:path";import{REDOCLY_TEAMS_RBAC as k}from"@redocly/config";const A=`internal.app-data`,j=`1.34.0`,M=i(A,`app-data`);function N(e){return c(e)&&typeof e.owner==`string`&&`value`in e}const P=r(M,async e=>{let n=new Set(e.pluginRegistry.listFinalizePlugins().map(e=>e.id)),r={};for(let[t,i]of Object.entries(e.args.fragments??{}))N(i)&&n.has(i.owner)&&(r[t]=i.value);let i=await te(e.config.logo,e.markdown,e.file.path);if(Object.keys(i.logo).length>0){let e=c(r.theme)?r.theme:{};r.theme=t({...e,logo:i.logo})}let a=await ee(e.config.banner,e);if(a){let e=c(r.theme)?r.theme:{};r.theme=t({...e,banner:a.banner})}let o=await b(c(r.theme)?r.theme.navbar:void 0,e.markdown,e.file.path);if(o){let e=c(r.theme)?r.theme:{};r.theme=t({...e,navbar:o.navbar})}let s=await b(c(r.theme)?r.theme.footer:void 0,e.markdown,e.file.path);if(s){let e=c(r.theme)?r.theme:{};r.theme=t({...e,footer:s.navbar})}let l=await E(c(r.theme)?r.theme.products:void 0,e.markdown,e.file.path);if(l){let e=c(r.theme)?r.theme:{};r.theme=t({...e,products:l.products})}let u=await x(e.config,e.markdown,e.file.path,t=>e.io.readFile(O(D(e.file.absolutePath),t)),e.logger);u&&(r.html=t(u.html));let d=await S(r.seo,e.markdown,e.file.path);d&&(r.seo=d.seo);let f=[i,a,o,s,l,u,d];return{value:r,entityDeps:f.flatMap(e=>e?.deps??[]),assetUsages:f.flatMap(e=>e?.assetUsages??[])}});function F(e){return{isSystem:!0,key:u,kind:`loader`,type:null,metadata:null,loaderArgs:{pluginVersion:j},loaderId:M,pluginId:A,shouldInvalidateValue:!1,value:null,version:null,fragmentUpdates:e.fragmentUpdates}}const I=e({id:A,version:j,async finalize(e){let r=await h({io:e.io,routes:e.routes,versionedDirectories:g(e.routes.all())}),i=e=>e&&_(e,r),a=t=>t&&{slug:_(t,r),loadLabel:()=>y(e.entities,t)},o=t=>a(e.routes.byFilePath(t)),s=t=>a(e.routes.bySlug(t)),l=t=>v(t,e.routes,r),u=await V(e.config,o,s,e.logger,l),d=await R(e,o,s,i,l);if(Object.keys(d).length>0){let e=c(u.theme)?u.theme:{};u.theme=t({...e,products:d}),u.pageProducts=n(Object.values(d).map(L))}return{appData:u}},loaders:[P]});function L(e){let{name:t,slug:n,configOverride:r}=e,i={name:t,slug:n},a=r?.analytics?.ga;return a&&(i.ga=a),i}async function R(e,n,r,i,o){let s={};for(let t of m(e.config)){let c=await w(t,e.routes,e.io,i);if(c===void 0){e.logger.warn(`Product "${t.id}" is left out of the product picker: "${t.folder}" has no page.`);continue}let l={name:t.name,folder:t.folder,slug:t.slug,link:c,[k]:o(c)??void 0};t.icon!==void 0&&(l.icon=t.icon);let u=C(t.folder),d=await e.io.exists(u)?await z(T(await e.io.readFile(u),u),{page:Q(n,r,u,e.logger),access:o},a(e.config),e.config):{};Object.keys(d).length>0&&(l.configOverride=d),s[t.id]=l}return t(s)}async function z(e,t,n,r){let i={},a=await K(e.navbar,t),o=await G(e.footer,t),c=W(e.breadcrumbs,t);return e.logo&&(i.logo=e.logo),a&&(i.navbar=a),o&&(i.footer=o),c&&s(r,`breadcrumbs`)&&(i.breadcrumbs=c),e.feedback&&(i.feedback=e.feedback),e.sidebar&&(i.sidebar=e.sidebar),e.codeSnippet&&(i.codeSnippet=e.codeSnippet),e.palette&&(i.palette=e.palette),e.search&&(i.search=await B(e.search,n,t)),e.analytics?.ga&&s(r,`analytics`)&&(i.analytics={ga:e.analytics.ga}),i}async function B(e,n,r){let i={...n},a=await q(e?.suggestedPages,r);return e?.hide!==void 0&&(i.hide=e.hide),e?.placement!==void 0&&(i.placement=e.placement),e?.shortcuts!==void 0&&(i.shortcuts=e.shortcuts),a.length>0&&(i.suggestedPages=a),t(i)}async function V(e,n,r,i,s=()=>void 0){let c={},l={page:Q(n,r,ie,i),access:s},u=await K(e.navbar,l),d=await G(e.footer,l),f=e.seo?.projectTitle,p=W(e.breadcrumbs,l),m={...u?{navbar:u}:{},...d?{footer:d}:{},...p?{breadcrumbs:p}:{},markdown:e.markdown,navigation:e.navigation,userMenu:await X(e.userMenu,l),feedback:e.feedback,consent:e.consent,...f?{seo:{projectTitle:f}}:{},aiAssistant:H(e),mcp:U(e),search:await B(e.search,a(e),l),sidebar:e.sidebar,versionPicker:e.versionPicker,codeSnippet:e.codeSnippet,palette:e.palette};if(e.colorMode&&(m.colorMode=e.colorMode),Object.keys(m).length>0&&(c.theme=m),e.analytics&&(c.analytics=e.analytics),e.planGates&&(c.removeAttribution=o(e)),e.removeAttribution===!0&&(c.removeConsoleAttribution=!0),e.seo){let{projectTitle:t,llmstxt:n,...r}=e.seo;Object.keys(r).length>0&&(c.seo=r)}return t(c)}function H(e){let t=l(e),n=e.aiAssistant?.trigger;return{...e.aiAssistant,hide:t,trigger:{...n,hide:n?.hide??t}}}function U(e){let t=e.mcp?.hide===!0;return{hide:t,docs:{hide:t}}}function W(e,n){if(!e)return null;let r={};e.hide!==void 0&&(r.hide=e.hide);let i=(e.prefixItems??[]).map(e=>{let t=e.page?n.page(e.page)?.link:void 0;return{icon:$(e.icon),label:$(e.label)??``,labelTranslationKey:$(e.labelTranslationKey),link:t,[k]:Y(n,t)}});return i.length>0&&(r.prefixItems=i),Object.keys(r).length>0?t(r):null}async function G(e,n){if(!e)return null;let r={hide:e.hide===!0},i=await q(e.items,n);return e.copyrightText!==void 0&&(r.copyrightText=e.copyrightText),e.logo&&(r.logo=e.logo),i.length>0&&(r.items=i),t(r)}async function K(e,n){if(!e)return null;let r={},i=await q(e.items,n);return e.hide!==void 0&&(r.hide=e.hide),i.length>0&&(r.items=i),Object.keys(r).length>0?t(r):null}async function q(e,t){return Array.isArray(e)?(await Promise.all(e.map(e=>J(e,t)))).filter(e=>e!==null):[]}async function J(e,n){if(typeof e==`string`)return J({page:e},n);if(!c(e))return null;if(typeof e.separator==`string`)return t({...Z(e),label:e.separator,type:`separator`});let r=await q(e.items,n),i=re(e,n.page),a=i?.link,o=e.rbac===void 0?Y(n,a):void 0,s=$(e.label)??$(e.group)??(i?i.anchor??await i.loadLabel?.()??i.link:``);return typeof e.group==`string`||r.length>0?t({...Z(e),...a?{link:a}:{},...r.length>0?{items:r}:{},label:s,labelTranslationKey:$(e.groupTranslationKey)??$(e.labelTranslationKey),type:`group`,[k]:o}):a?t({...Z(e),external:oe(e.external),label:s,link:a,type:`link`,[k]:o}):null}function Y(e,t){return t===void 0?void 0:e.access(t)??void 0}async function X(e,n){if(!e)return;let r=[];for(let t of e.items??[])r.push({...t,href:t.link});let i=await q(r,n);return t({...e,menu:i.length>0?i:void 0})}function Z(e){let t=ae(e,[`additionalProps`,`expanded`,`labelTranslationKey`,`languageInsensitive`,`linePosition`,`linkedSidebars`,`menuStyle`,`selectFirstItemOnExpand`,`separatorLine`,`target`,`version`]),n=ne(e.icon);return n.icon&&(t.icon=n.icon),n.srcSet&&(t.srcSet=n.srcSet),{...t,...f(e.rbac)}}function ne(e){return typeof e==`string`?{icon:e}:c(e)&&typeof e.srcSet==`string`?{srcSet:e.srcSet}:{}}function re(e,t){return typeof e.href==`string`&&e.href.trim()!==``?{link:e.href.trim()}:typeof e.page==`string`&&e.page.trim()!==``?t(e.page):null}const ie=`redocly.yaml`;function Q(e,t,n,r){let i={bySlug:e=>t?.(e),byFilePath:t=>e?.(t)};return e=>{let{path:t,suffix:a,anchor:o}=d(e.trim()),s=p(t,n,i);return s.kind===`escaped`?(r?.warn(`Config page reference escapes the content root`,{page:e}),null):s.kind===`missing`?(r?.warn(`Config page has no matching route`,{page:e}),{link:e.trim()}):{link:`${s.value.slug}${a}`,anchor:o,loadLabel:s.value.loadLabel}}}function ae(e,t){let n={};for(let r of t)e[r]!==void 0&&(n[r]=e[r]);return n}function $(e){return typeof e==`string`&&e.trim()!==``?e:void 0}function oe(e){return typeof e==`boolean`?e:void 0}export{A as APP_DATA_PLUGIN_ID,j as APP_DATA_PLUGIN_VERSION,M as APP_DATA_STATIC_DATA_LOADER_ID,u as APP_DATA_STATIC_DATA_SLUG,I as appDataContentPlugin,F as appDataSystemEntityDescriptor,V as buildConfigAppData,N as isAppDataFragment};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{defineContentPlugin as e}from"../../define.js";import{createEntityLoader as t}from"../../../loaders/define.js";import{runtimeFile as n}from"../../utils/runtime-file.js";import{createServerFn as r}from"../../server-fn.js";import{createPluginScopedId as i}from"../../utils/scoped-id.js";import{runtimeTemplate as a}from"../../templates.js";import{normalizeRouteSlug as o}from"../../../../shared/utils/routes/normalize-route-slug.js";import{SIDEBAR_CONTRIBUTIONS_ENTITY_TYPE as s}from"../sidebar/contributions.js";import{CATALOG_CLASSIC_DEP_KEY as c}from"./client/contract.js";import{catalogEntityKey as l}from"./entity-key.js";import{buildCatalogCards as u,loadVersionGroups as d,pickDefaultVersions as f,resolveCatalogMembers as p}from"./resolve-items.js";import{catalogSidebarContributions as m}from"./sidebars.js";const h=`internal.catalog-classic`,g=`catalog-classic`,_=i(h,`catalog`),v=i(h,`sidebars`),y=i(h,`deliver`),b=t(_,async e=>{let t=p(e.args.items,e),{versionGroups:n,entityDeps:r}=await d(t,e),i=e.args.config.separateVersions?t:f(t,n),a=await u(i,n,e);return{value:{catalogId:e.args.catalogId,config:e.args.config,items:a},entityDeps:r}}),x=t(v,async e=>{let t=p(e.args.items,{routes:e.routes}),{versionGroups:n,entityDeps:r}=await d(t,e);return{value:await m(t,n,{label:e.args.title,link:e.args.slug},e),entityDeps:r}}),S=r(y,{filePath:`./server/deliver.ts`,importer:import.meta.url,exportName:`deliver`,cacheable:!0});function C(e){return Object.entries(e.catalogClassic??e.catalog??{})}const w=e({id:h,version:`1.
|
|
1
|
+
import{defineContentPlugin as e}from"../../define.js";import{createEntityLoader as t}from"../../../loaders/define.js";import{runtimeFile as n}from"../../utils/runtime-file.js";import{createServerFn as r}from"../../server-fn.js";import{createPluginScopedId as i}from"../../utils/scoped-id.js";import{runtimeTemplate as a}from"../../templates.js";import{normalizeRouteSlug as o}from"../../../../shared/utils/routes/normalize-route-slug.js";import{SIDEBAR_CONTRIBUTIONS_ENTITY_TYPE as s}from"../sidebar/contributions.js";import{CATALOG_CLASSIC_DEP_KEY as c}from"./client/contract.js";import{catalogEntityKey as l}from"./entity-key.js";import{buildCatalogCards as u,loadVersionGroups as d,pickDefaultVersions as f,resolveCatalogMembers as p}from"./resolve-items.js";import{catalogSidebarContributions as m}from"./sidebars.js";const h=`internal.catalog-classic`,g=`catalog-classic`,_=i(h,`catalog`),v=i(h,`sidebars`),y=i(h,`deliver`),b=t(_,async e=>{let t=p(e.args.items,e),{versionGroups:n,entityDeps:r}=await d(t,e),i=e.args.config.separateVersions?t:f(t,n),a=await u(i,n,e);return{value:{catalogId:e.args.catalogId,config:e.args.config,items:a},entityDeps:r}}),x=t(v,async e=>{let t=p(e.args.items,{routes:e.routes}),{versionGroups:n,entityDeps:r}=await d(t,e);return{value:await m(t,n,{label:e.args.title,link:e.args.slug},e),entityDeps:r}}),S=r(y,{filePath:`./server/deliver.ts`,importer:import.meta.url,exportName:`deliver`,cacheable:!0});function C(e){return Object.entries(e.catalogClassic??e.catalog??{})}const w=e({id:h,version:`1.8.0`,content:{extractAll(e){let t=[],n=[];for(let[r,i]of C(e.config)){let{items:e,...a}=i,u=o(String(i.slug)),d=typeof i.title==`string`?i.title:`API Catalog`;t.push(b.withArgs({catalogId:r,config:a,items:e},{stableKey:l(r),metadata:{sourcePath:u}}),x.withArgs({items:e,slug:u,title:d},{stableKey:`${l(r)}:sidebars`,type:s})),n.push({deps:{[c]:S.withArgs({catalogId:r})},metadata:{title:d},routeId:r,slug:u,template:g})}return{entities:t,routes:n}}},loaders:[b,x],server:{functions:[S]},templates:{[g]:a(n(`./client/template.tsx`,import.meta.url))}});export{_ as CATALOG_CLASSIC_LOADER_ID,h as CATALOG_CLASSIC_PLUGIN_ID,y as CATALOG_CLASSIC_SERVER_FN_ID,v as CATALOG_CLASSIC_SIDEBARS_LOADER_ID,g as CATALOG_CLASSIC_TEMPLATE_ID,w as catalogClassicContentPlugin};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{toStableJsonString as e}from"../../../database/utils/json.js";import{
|
|
1
|
+
import{toStableJsonString as e}from"../../../database/utils/json.js";import{isObject as t}from"../../../../shared/utils/is-object.js";import{L10N_DIR as n}from"../../../../shared/constants/l10n/defaults.js";import{normalizeRouteSlug as r}from"../../../../shared/utils/routes/normalize-route-slug.js";import"../../../../shared/utils/l10n.js";import{resolveContentPath as i}from"../../../../shared/utils/resolve-content-path.js";import{collectVersionGroups as a,findVersionedDirectories as o,versionsYamlPath as s}from"../../../versions/version-groups.js";import{publicLink as c}from"../../../versions/public-link.js";import{parseMarkdown as l}from"../../../markdown/utils/parse-cache.js";import{markdocAstToText as u}from"../../../markdown/search/to-text.js";import{createApiEntityKey as d}from"../../utils/api-entity-key.js";import{sidebarStartEntityKey as f}from"../sidebar/contributions.js";import{CATALOG_CARD_METADATA_ENTITY_TYPE as p}from"./card-metadata.js";import{resolve as m}from"node:path";import{REDOCLY_TEAMS_RBAC as h}from"@redocly/config";const g=`redocly.yaml`;function _(e,t){let n=[],r=e=>{if(typeof e.directory==`string`)n.push(...C(e,e.directory,t));else if(typeof e.page==`string`){let r=w(e,e.page,t);r&&n.push(r)}else typeof e.href==`string`&&n.push(T(e,e.href,t));for(let t of e.items??[])r(t)};for(let t of e??[])r(t);return n}async function v(e,t){let n=e.flatMap(e=>`route`in e?[e.route]:[]),r=o(n);return{versionGroups:await a({io:{exists:e=>t.io.exists(m(t.contentDir,e)),readFile:e=>t.io.readFile(m(t.contentDir,e))},routes:t.routes,versionedDirectories:r}),entityDeps:r.map(e=>({kind:`file`,path:s(e)}))}}function y(e,t){let n=/* @__PURE__ */ new Map;for(let[r,i]of e.entries()){let e=`route`in i?c(i.route,t,!0):`${r}`,a=`route`in i&&i.route.versionGroup!==null&&t.get(i.route.versionGroup)?.defaultVersion===i.route.version;(!n.has(e)||a)&&n.set(e,i)}return[...n.values()]}async function b(e,t){return P(e.route.metadata.title)??P(e.entry.label)??await A(e.route,t)??N(e.route.slug)}async function x(e,t,n){let r=await S(n.entities),i=[];for(let a of e)i.push(`route`in a?await E(a,t,r,n):{link:a.link,title:a.title});return i}async function S(e){let t=/* @__PURE__ */ new Map;for(let n of await e.list({type:p}))for(let{route:r,metadata:i}of await e.load(n.key))t.set(r,{...t.get(r),...i});return t}function C(e,r,a){let o=i(r,g);if(o===null)return a.logger?.warn(`Catalog directory reference escapes the content root`,{directory:r}),[];let s=a.routes.inDirectory(o);if(s.length===0)return a.logger?.warn(`Catalog directory matched no routes`,{directory:r}),[];let c=t(e.includeByMetadata)?e.includeByMetadata:void 0,l=o.startsWith(`${n}/`),u=[];for(let t of s){if(!l&&t.locale!==``)continue;let n=a.routes.get(t.slug);n&&M(j(n.metadata),c)&&u.push({route:n,entry:e})}return u}function w(e,t,n){let r=i(t,g);if(r===null){n.logger?.warn(`Catalog page reference escapes the content root`,{page:t});return}let a=n.routes.byFilePath(r),o=a&&n.routes.get(a.slug);if(!o){n.logger?.warn(`Catalog page has no matching route`,{page:t});return}return{route:o,entry:e}}function T(e,t,n){let i=t.startsWith(`/`)?n.routes.bySlug(r(t)):void 0,a=i&&n.routes.get(i.slug);return a?{route:a,entry:e}:{link:t,title:P(e.label)??t}}async function E(e,t,n,r){let{route:i}=e,a={...j(i.metadata),...n.get(i.slug)};delete a.rbac;let o=await b(e,r),s=k(a.description)??P(a.summary)??await O(i,r),l=F(a.tags),u=await D(i,t,r),d={link:c(i,t),title:o,metadata:a};return s!==void 0&&(d.description=s),l!==void 0&&(d.tags=l),u!==void 0&&(d.docsLink=u),i.version!==null&&(d.version=i.version),i.access!==null&&(d[h]=i.access),d}async function D(t,n,r){let i=f(t.slug);if(await r.entities.get(i)===null)return;let a=r.routes.get(await r.entities.load(i));if(a!==void 0&&a.slug!==t.slug&&e(a.access)===e(t.access))return c(a,n)}async function O(e,n){if(e.originFilePath===null)return;let r=d(e.originFilePath);if((await n.entities.get(r))?.type!==`api`)return;let i=await n.entities.load(r),a=t(i)&&t(i.info)?i.info:{};return P(a.summary)??k(a.description)}function k(e){let t=P(e);if(t!==void 0)return P(u(l(t)))}async function A(e,n){if(!e.sidebarSubtreeEntityKey)return;let r=await n.entities.load(e.sidebarSubtreeEntityKey);return t(r)?P(r.label):void 0}function j(e){let{metadata:n,...r}=e;return t(n)?{...r,...n}:r}function M(e,t){return!t||Object.entries(t).every(([t,n])=>{let r=e?.[t];return Array.isArray(n)?n.includes(r):r===n})}function N(e){return e.split(`/`).filter(Boolean).at(-1)??e}function P(e){return typeof e==`string`&&e.trim()!==``?e:void 0}function F(e){return Array.isArray(e)&&e.every(e=>typeof e==`string`)?e:void 0}export{x as buildCatalogCards,v as loadVersionGroups,y as pickDefaultVersions,_ as resolveCatalogMembers,b as resolveMemberTitle};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createEntityLoader as e}from"../../../loaders/define.js";import{createPluginScopedId as t}from"../../utils/scoped-id.js";import{
|
|
1
|
+
import{createEntityLoader as e}from"../../../loaders/define.js";import{createPluginScopedId as t}from"../../utils/scoped-id.js";import{isObject as n}from"../../../../shared/utils/is-object.js";import{L10N_DIR as r,TRANSLATIONS_FILE_NAMES as i}from"../../../../shared/constants/l10n/defaults.js";import a from"js-yaml";const o=`internal.l10n`,s=`l10n-translations`,c=t(o,`translations`),l=RegExp(`^${r}/([^/]+)/(translations\\.ya?ml)$`,`i`),u=e(c,async e=>{let t=e.file.path,r=d(t);if(r===null)return{value:{dir:null,translation:{}},type:s,problems:[p(t,"Not loaded as UI-string translations: place the file at the project root or in `@l10n/<locale>/`.")]};let i;try{i=await e.io.readFile(e.file.absolutePath)}catch(e){return f(r,t,`reading failed`,e)}let o;try{o=a.load(i)}catch(e){return f(r,t,`invalid YAML`,e)}return o!=null&&!n(o)?f(r,t,`expected a key-value map`):{value:{dir:r,translation:o??{}},type:s}});function d(e){let t=e.toLowerCase();return i.some(e=>t===e)?``:l.exec(e)?.[1]??null}function f(e,t,n,r){let i=r instanceof Error?`: ${r.message}`:``;return{value:{dir:e,translation:{}},type:s,problems:[p(t,`Ignoring translations file: ${n}${i}.`)]}}function p(e,t){return{code:`configuration/l10n-translations-invalid`,message:t,location:{filePath:e}}}export{o as L10N_PLUGIN_ID,s as L10N_TRANSLATIONS_ENTITY_TYPE,c as L10N_TRANSLATIONS_LOADER_ID,u as l10nTranslationsLoader,d as translationsFileDir};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{defineContentPlugin as e}from"../../define.js";import{createEntityLoader as t}from"../../../loaders/define.js";import{runtimeFile as n}from"../../utils/runtime-file.js";import{createPluginScopedId as r}from"../../utils/scoped-id.js";import{runtimeTemplate as i}from"../../templates.js";import{SEARCH_GROUP_FACET_FIELD as a}from"../../../../shared/search/facets.js";import{configuredFacetFields as o,extractFacetsFromFrontmatter as s,invalidFacetValueProblems as c,searchCategoryOf as l}from"../../../search/facet-values.js";import{isPlanFeatureGranted as u}from"../../../../shared/plan-gates.js";import{SOURCE_TEMPLATE_PREFIX as d}from"../../../../shared/constants/template-ids.js";import{isObject as f}from"../../../../shared/utils/is-object.js";import{normalizeRouteSlug as p}from"../../../../shared/utils/routes/normalize-route-slug.js";import{resolveContentPath as m}from"../../../../shared/utils/resolve-content-path.js";import{PAGE_BANNER_SCHEMA as h,sanitizeConfig as g}from"../../../config-schema.js";import{notInPlanProblem as _}from"../../../plan-gates.js";import{matchPathMap as v}from"../../utils/glob.js";import{filePathToRouteSlug as y}from"../../../../shared/utils/routes/file-path-to-route-slug.js";import{splitUrlSuffix as b}from"../../../../shared/utils/routes/split-url-suffix.js";import{packMarkdocAst as ee,unpackMarkdocAst as x}from"../../../../shared/utils/packed-ast.js";import{isRouteSlugTarget as S}from"../../../../shared/utils/routes/is-route-slug-target.js";import{loadSidebarSubtreeLabel as C}from"../../utils/sidebar-label.js";import{markdocNodeRange as w}from"../../../markdown/utils/node-source-range.js";import{replaceWithMarkdocError as T}from"../../../markdown/tags/markdoc-error.js";import{getPartialTwins as te}from"../../../markdown/tags/partial.js";import{CODE_WALKTHROUGH_TAG_NAMES as ne,builtInMarkdocTags as re}from"../../../markdown/constants/builtin-tags.js";import{walkMarkdocAst as E}from"../../../markdown/utils/walk-markdoc-ast.js";import{markdocFirstHeading as ie}from"../../../markdown/search/to-text.js";import{safeDecodeURI as ae}from"../../../../shared/utils/safe-decode-uri.js";import{shiftRange as oe}from"../../../../shared/utils/shift-range.js";import{classifyLinkTarget as se}from"../../../link-checker/classify.js";import{onDiskLinkRefs as ce}from"../../../link-checker/node-ref.js";import{isPartialPath as le}from"../../../markdown/utils/partials.js";import{FRONTMATTER_BLOCK_RE as ue,computeFrontmatterLineOffset as de}from"../../../markdown/utils/frontmatter-offset.js";import{inlineRawPartials as D}from"../../../markdown/resolve/raw-partials.js";import{resolveMarkdownAst as O}from"../../../markdown/resolve/ast.js";import{resolveBannerForAppData as k}from"../app-data/banner.js";import{MARKDOC_DOCUMENT_LOADER_KEY as A}from"../../../../shared/constants/route-deps.js";import{isMarkdocValidationEnabled as j,resolveMarkdocTagSet as M,resolveMarkdownPageValidationSet as N,userMarkdocSchemaFiles as P,userMarkdocTagNames as F}from"../../../markdown/constants/tag-sets.js";import{pageLocale as I}from"../../utils/page-locale.js";import{captureSnippet as L,splitSourceLines as R}from"../../../../shared/utils/capture-snippet.js";import{markdocAstToMarkdownDoc as z}from"../../../markdown/search/to-markdown.js";import{collectAnchors as B}from"../../../markdown/utils/collect-anchors.js";import{frontmatterVariable as V}from"../../../markdown/utils/frontmatter-variable.js";import{markdownFirstHeading as H}from"../../../markdown/utils/first-heading.js";import{markdocAstToSearchSections as fe}from"../../../markdown/search/to-sections.js";import{isInternalPagePath as pe}from"../../utils/internal-page-path.js";import{parseExplicitSlugs as me}from"../../utils/explicit-slugs.js";import{isSkillContentPath as he}from"../../utils/skill-paths.js";import{curationKeywordsOf as ge}from"../../../search/keywords.js";import _e from"js-yaml";const U=`markdoc-page`,W=r(`internal.markdoc`,`document`),G=r(`internal.markdoc`,`sidebar-item`),ve=`Documentation`,K=t(W,async e=>{let t=await e.io.readFile(e.file.absolutePath),{content:n,frontmatter:r,frontmatterError:i}=Y(t),a=J(e),{ast:o,entityDeps:s,assetUsages:c,tagList:l,problems:d,linkRefs:f}=await O(n,e.file.path,{resolverContext:a,tags:(await M()).tags,variables:{get env(){return e.config.publicEnv??{}}},transform:t=>De(t,e.file.path,Ee(e.config)),validation:j()?await N():void 0}),p=de(t);Me(o);let m=await Te(r.seo,e),h=u(e.config,`banner`)?await k(Ne(r,e.file.path,e.logger),a):void 0,g=await ke(r,e),_=await Ae(r.navigation,e),v={...g.frontmatter,navigation:_.value,seo:m.seo,banner:h?.banner},y=Pe(r,o);return{value:{ast:ee(o),frontmatter:v,tagList:l,title:y,editPage:we(e.config,r,e.file.path),lastModified:e.file.lastModifiedAt},entityDeps:[...s,...be(),...m.entityDeps,...h?.deps??[],...g.entityDeps,..._.entityDeps],assetUsages:[...c,...m.assetUsages,...h?.assetUsages??[],...g.assetUsages],problems:xe(t,e.file.path,p,d,i),linkRefs:[...ce(f,p),..._.linkRefs],targetInventories:[Se(o,{frontmatter:V(v,y)})]}},{usesProjectMarkdocSchema:!0,async markdown(e,t){let{tags:n}=await M(),{chunks:r,headings:i}=z(x(e.ast),{tags:n,locale:I(t),variables:{frontmatter:V(e.frontmatter,e.title),env:t.config.publicEnv??{}}});return[{chunks:r,headings:i,...e.title?{title:e.title}:{}}]},searchable(e,t){if(t.route===void 0||t.route.metadata.excludeFromSearch===!0)return{docs:[]};let n=t.route.slug,r=e.title??Q(t.route.originFilePath??n),{category:i,isInvalid:u}=l(t.route.metadata),{facets:d,invalidFields:f}=s(t.route.metadata,o(t.config)),p=ge(e.frontmatter.keywords);return{docs:fe(x(e.ast),r,{frontmatter:V(e.frontmatter,e.title)}).map((e,t)=>{let r={docKey:e.docKey,routeSlug:n,title:e.title,text:e.text,groupKey:i??`Documentation`,facets:d};e.anchor!==void 0&&(r.anchor=e.anchor),e.path!==void 0&&(r.path=e.path);let a=t===0?p:{excludes:p?.excludes};return(a?.includes||a?.excludes)&&(r.keywords=a),e.rbacTeams!==void 0&&(r.rbacScope=Object.fromEntries(e.rbacTeams.map(e=>[e,`read`]))),r}),problems:c([...f,...u?[a]:[]],t.route.originFilePath)}}}),q=t(G,async e=>{let{content:t,frontmatter:n}=Y(await e.io.readFile(e.file.absolutePath)),r=await D(t,e.file.path,J(e));return{value:{label:Z(n)??H(r.source)??Q(e.args.filePath)},entityDeps:r.entityDeps}});function J(e){return{config:e.config,contentDir:e.contentDir,entities:e.entities,file:e.file,io:e.io,logger:e.logger,markdown:e.markdown,plugin:e.plugin}}const ye=e({id:`internal.markdoc`,version:`3.48.0`,content:{filter:{match:e=>e.toLowerCase().endsWith(`.md`)&&!he(e)},extractFile(e,t){if(pe(e.path)||le(e.path,t.config))return{routes:[]};if(!u(t.config,`markdown`))return{routes:[],problems:[_(`Markdown pages`)]};let{banner:n,...r}=e.manifest,i=Fe(e,t),a=me(r.slug),o=K.withArgs({filePath:e.path}),s=q.withArgs({filePath:e.path});return{routes:a.length>0?a.map(e=>({deps:{[A]:o},metadata:r,routeId:`page`,sidebarSubtree:s,slug:e,slugHint:null,template:i})):[{deps:{[A]:o},metadata:r,routeId:`page`,sidebarSubtree:s,slug:null,slugHint:y(e.path),template:i}],entities:[o]}}},loaders:[K,q],templates:{[U]:i(n(`./client/template.tsx`,import.meta.url))}});function Y(e){let t=e.match(ue);if(!t)return{content:e,frontmatter:{}};let n=t[1]??``;try{let r=_e.load(n);return{content:e.slice(t[0].length),frontmatter:f(r)?r:{}}}catch(n){let r=n instanceof Error?n.message:String(n);return{content:e.slice(t[0].length),frontmatter:{},frontmatterError:r}}}function be(){return(P()??[]).map(e=>({kind:`file`,path:e}))}function xe(e,t,n,r,i){if(r.length===0&&i===void 0)return[];let a=R(e),o=r.map(e=>Ce(e,a,n,t));if(i!==void 0){let e={start:{line:1},end:{line:n}};o.push({code:`markdown/frontmatter-parse`,message:i,location:{filePath:t,range:e,snippet:L(a,e)}})}return o}function Se(e,t){let{ids:n,exhaustive:r}=B(e,t);return{kind:`anchor`,exhaustive:r,targets:n}}function Ce(e,t,n,r){let i=e.location?.range;if(!i)return e;let a=oe(i,n);return{...e,location:{filePath:r,range:a,snippet:L(t,a)}}}function we(e,t,n){let r=f(t.markdown)?t.markdown:{},i={...e.markdown?.editPage,...f(r.editPage)?r.editPage:{}};if(i.hide!==!0&&typeof i.baseUrl==`string`&&i.baseUrl!==``)return{to:`${i.baseUrl.replace(/(?<!\/)\/+$/,``)}/${n}`}}async function Te(e,t){if(!f(e)||typeof e.image!=`string`)return{seo:e,entityDeps:[],assetUsages:[]};let n=await t.markdown.resolveImageReference(e.image,t.file.path);return n.result.kind===`assetRef`?{seo:{...e,image:n.result.url},entityDeps:n.entityDeps,assetUsages:n.assetUsages}:{seo:e,entityDeps:n.entityDeps,assetUsages:[]}}function Ee(e){let t=/* @__PURE__ */ new Map;if(!u(e,`customMarkdocTags`))for(let e of F())t.set(e,`Custom Markdoc tags are not in this project's plan, so \`${e}\` is ignored.`);if(!u(e,`codeWalkthrough`))for(let e of ne)t.set(e,`\`${e}\` is not in this project's plan and is ignored.`);return t}function De(e,t,n){let r=[];if(n.size===0)return r;for(let i of E(e,{getExtraNodes:te})){let e=i.type===`tag`&&i.tag!==void 0?n.get(i.tag):void 0;e!==void 0&&(r.push({code:`configuration/ignored`,message:e,location:{filePath:t,range:w(i)??{start:{line:1},end:{line:1}}}}),T(i,e))}return r}const Oe=[`image`,`links`];async function ke(e,t){let n=t.config.markdown?.frontMatterKeysToResolve??Oe,r={...e},i=[],a=[];for(let o of n){let n=e[o];if(typeof n!=`string`)continue;let s=await t.markdown.resolveLocalReference(n,t.file.path);i.push(...s.entityDeps),a.push(...s.assetUsages),s.result.kind!==`passthrough`&&(r[o]=s.result.url)}return{frontmatter:r,entityDeps:i,assetUsages:a}}async function Ae(e,t){let n=[],r=[];if(!f(e))return{value:e,entityDeps:n,linkRefs:r};let i={...e};for(let a of[`nextButton`,`previousButton`]){let o=e[a];if(!f(o)||typeof o.page!=`string`)continue;let{page:s,...c}=o,l=se(ae(s),t.file.path);l!==null&&r.push({kind:`link`,raw:s,...l});let u=await je(s,t);n.push(...u.entityDeps),i[a]={...c,label:typeof c.label==`string`?c.label:u.route&&await X(u.route,t),link:u.link}}return{value:i,entityDeps:n,linkRefs:r}}async function X(e,t){let n=await C(t.entities,e);if(n!==void 0)return n;let r=t.routes.get(e.slug)?.metadata.seo;return f(r)&&typeof r.title==`string`&&r.title.trim()!==``?r.title:e.slug}async function je(e,t){let n=e.trim(),{path:r,suffix:i}=b(n);if(S(r)){let e=t.routes.bySlug(p(r));return{link:e&&`${e.slug}${i}`,route:e,entityDeps:[]}}let a=await t.markdown.resolveLocalReference(n,t.file.path);if(a.result.kind!==`pageUrl`)return{entityDeps:a.entityDeps};let o=a.result.url;return{link:o,route:t.routes.bySlug(b(o).path)??a.entityDeps.map(e=>e.kind===`file`?t.routes.byFilePath(e.path):void 0).reverse().find(e=>e!==void 0),entityDeps:a.entityDeps}}function Me(e){let t=/* @__PURE__ */ new Map;for(let n of E(e)){if(n.type!==`tag`||n.tag===void 0||re[n.tag]?.attributes?.__idx===void 0)continue;let e=(t.get(n.tag)??0)+1;t.set(n.tag,e),n.attributes.__idx=e}}function Ne(e,t,n){if(e.banner===void 0)return;let{value:r,problems:i}=g(h,{banner:e.banner});for(let e of i)n?.warn(`${t}: ${e.message}`);return r.banner}function Pe(e,t){return Z(e)??ie(t)??void 0}function Z(e){let t=f(e.seo)?e.seo.title:void 0;return typeof t==`string`&&t.trim()!==``?t:void 0}function Q(e){let t=(e.split(`/`).pop()??e).replace(/\.[^.]+$/,``);return t===``?e:t}function Fe(e,t){let n=e.manifest.template;if(typeof n==`string`&&n.trim()!==``)return $(n,e.path,t.logger);let r=v(e.path,t.config.markdown?.template);return typeof r==`string`&&r.trim()!==``?$(r,`redocly.yaml`,t.logger):U}function $(e,t,n){if(!e.startsWith(`./`)&&!e.startsWith(`../`)&&!e.startsWith(`/`))return e;let r=m(e,t);return r===null?(n.warn(`Template reference "${e}" in ${t} escapes the content root; falling back to ${U}.`),U):`${d}${r}`}export{W as MARKDOC_DOCUMENT_LOADER_ID,ve as MARKDOC_SEARCH_GROUP,G as MARKDOC_SIDEBAR_ITEM_LOADER_ID,U as MARKDOC_TEMPLATE_ID,ye as markdocContentPlugin};
|
|
1
|
+
import{defineContentPlugin as e}from"../../define.js";import{createEntityLoader as t}from"../../../loaders/define.js";import{runtimeFile as n}from"../../utils/runtime-file.js";import{createPluginScopedId as r}from"../../utils/scoped-id.js";import{runtimeTemplate as i}from"../../templates.js";import{SEARCH_GROUP_FACET_FIELD as a}from"../../../../shared/search/facets.js";import{configuredFacetFields as o,extractFacetsFromFrontmatter as s,invalidFacetValueProblems as c,searchCategoryOf as l}from"../../../search/facet-values.js";import{isPlanFeatureGranted as u}from"../../../../shared/plan-gates.js";import{SOURCE_TEMPLATE_PREFIX as d}from"../../../../shared/constants/template-ids.js";import{isObject as f}from"../../../../shared/utils/is-object.js";import{markdocNodeRange as p}from"../../../markdown/utils/node-source-range.js";import{replaceWithMarkdocError as m}from"../../../markdown/tags/markdoc-error.js";import{getPartialTwins as h}from"../../../markdown/tags/partial.js";import{CODE_WALKTHROUGH_TAG_NAMES as g,builtInMarkdocTags as _}from"../../../markdown/constants/builtin-tags.js";import{isMarkdocValidationEnabled as ee,resolveMarkdocTagSet as v,resolveMarkdownPageValidationSet as te,userMarkdocSchemaFiles as y,userMarkdocTagNames as b}from"../../../markdown/constants/tag-sets.js";import{normalizeRouteSlug as ne}from"../../../../shared/utils/routes/normalize-route-slug.js";import{resolveContentPath as x}from"../../../../shared/utils/resolve-content-path.js";import{PAGE_BANNER_SCHEMA as S,sanitizeConfig as C}from"../../../config-schema.js";import{notInPlanProblem as re}from"../../../plan-gates.js";import{matchPathMap as ie}from"../../utils/glob.js";import{filePathToRouteSlug as ae}from"../../../../shared/utils/routes/file-path-to-route-slug.js";import{splitUrlSuffix as w}from"../../../../shared/utils/routes/split-url-suffix.js";import{packMarkdocAst as oe,unpackMarkdocAst as T}from"../../../../shared/utils/packed-ast.js";import{isRouteSlugTarget as se}from"../../../../shared/utils/routes/is-route-slug-target.js";import{loadSidebarSubtreeLabel as ce}from"../../utils/sidebar-label.js";import{walkMarkdocAst as E}from"../../../markdown/utils/walk-markdoc-ast.js";import{markdocFirstHeading as le}from"../../../markdown/search/to-text.js";import{safeDecodeURI as ue}from"../../../../shared/utils/safe-decode-uri.js";import{shiftRange as de}from"../../../../shared/utils/shift-range.js";import{classifyLinkTarget as D}from"../../../link-checker/classify.js";import{onDiskLinkRefs as O}from"../../../link-checker/node-ref.js";import{isPartialPath as k}from"../../../markdown/utils/partials.js";import{FRONTMATTER_BLOCK_RE as A,computeFrontmatterLineOffset as j}from"../../../markdown/utils/frontmatter-offset.js";import{inlineRawPartials as M}from"../../../markdown/resolve/raw-partials.js";import{resolveMarkdownAst as N}from"../../../markdown/resolve/ast.js";import{resolveBannerForAppData as P}from"../app-data/banner.js";import{MARKDOC_DOCUMENT_LOADER_KEY as F}from"../../../../shared/constants/route-deps.js";import{pageLocale as I}from"../../utils/page-locale.js";import{captureSnippet as L,splitSourceLines as R}from"../../../../shared/utils/capture-snippet.js";import{markdocAstToMarkdownDoc as z}from"../../../markdown/search/to-markdown.js";import{collectAnchors as B}from"../../../markdown/utils/collect-anchors.js";import{frontmatterVariable as V}from"../../../markdown/utils/frontmatter-variable.js";import{markdownFirstHeading as H}from"../../../markdown/utils/first-heading.js";import{markdocAstToSearchSections as fe}from"../../../markdown/search/to-sections.js";import{isInternalPagePath as pe}from"../../utils/internal-page-path.js";import{parseExplicitSlugs as me}from"../../utils/explicit-slugs.js";import{isSkillContentPath as he}from"../../utils/skill-paths.js";import{curationKeywordsOf as ge}from"../../../search/keywords.js";import _e from"js-yaml";const U=`markdoc-page`,W=r(`internal.markdoc`,`document`),G=r(`internal.markdoc`,`sidebar-item`),ve=`Documentation`,K=t(W,async e=>{let t=await e.io.readFile(e.file.absolutePath),{content:n,frontmatter:r,frontmatterError:i}=Y(t),a=J(e),{ast:o,entityDeps:s,assetUsages:c,tagList:l,problems:d,linkRefs:f}=await N(n,e.file.path,{resolverContext:a,tags:(await v()).tags,variables:{get env(){return e.config.publicEnv??{}}},transform:t=>De(t,e.file.path,Ee(e.config)),validation:ee()?await te():void 0}),p=j(t);Me(o);let m=await Te(r.seo,e),h=u(e.config,`banner`)?await P(Ne(r,e.file.path,e.logger),a):void 0,g=await ke(r,e),_=await Ae(r.navigation,e),y={...g.frontmatter,navigation:_.value,seo:m.seo,banner:h?.banner},b=Pe(r,o);return{value:{ast:oe(o),frontmatter:y,tagList:l,title:b,editPage:we(e.config,r,e.file.path),lastModified:e.file.lastModifiedAt},entityDeps:[...s,...be(),...m.entityDeps,...h?.deps??[],...g.entityDeps,..._.entityDeps],assetUsages:[...c,...m.assetUsages,...h?.assetUsages??[],...g.assetUsages],problems:xe(t,e.file.path,p,d,i),linkRefs:[...O(f,p),..._.linkRefs],targetInventories:[Se(o,{frontmatter:V(y,b)})]}},{usesProjectMarkdocSchema:!0,async markdown(e,t){let{tags:n}=await v(),{chunks:r,headings:i}=z(T(e.ast),{tags:n,locale:I(t),variables:{frontmatter:V(e.frontmatter,e.title),env:t.config.publicEnv??{}}});return[{chunks:r,headings:i,...e.title?{title:e.title}:{}}]},searchable(e,t){if(t.route===void 0||t.route.metadata.excludeFromSearch===!0)return{docs:[]};let n=t.route.slug,r=e.title??Q(t.route.originFilePath??n),{category:i,isInvalid:u}=l(t.route.metadata),{facets:d,invalidFields:f}=s(t.route.metadata,o(t.config)),p=ge(e.frontmatter.keywords);return{docs:fe(T(e.ast),r,{frontmatter:V(e.frontmatter,e.title)}).map((e,t)=>{let r={docKey:e.docKey,routeSlug:n,title:e.title,text:e.text,groupKey:i??`Documentation`,facets:d};e.anchor!==void 0&&(r.anchor=e.anchor),e.path!==void 0&&(r.path=e.path);let a=t===0?p:{excludes:p?.excludes};return(a?.includes||a?.excludes)&&(r.keywords=a),e.rbacTeams!==void 0&&(r.rbacScope=Object.fromEntries(e.rbacTeams.map(e=>[e,`read`]))),r}),problems:c([...f,...u?[a]:[]],t.route.originFilePath)}}}),q=t(G,async e=>{let{content:t,frontmatter:n}=Y(await e.io.readFile(e.file.absolutePath)),r=await M(t,e.file.path,J(e));return{value:{label:Z(n)??H(r.source)??Q(e.args.filePath)},entityDeps:r.entityDeps}});function J(e){return{config:e.config,contentDir:e.contentDir,entities:e.entities,file:e.file,io:e.io,logger:e.logger,markdown:e.markdown,plugin:e.plugin}}const ye=e({id:`internal.markdoc`,version:`3.51.0`,content:{filter:{match:e=>e.toLowerCase().endsWith(`.md`)&&!he(e)},extractFile(e,t){if(pe(e.path)||k(e.path,t.config))return{routes:[]};if(!u(t.config,`markdown`))return{routes:[],problems:[re(`Markdown pages`)]};let{banner:n,...r}=e.manifest,i=Fe(e,t),a=me(r.slug),o=K.withArgs({filePath:e.path}),s=q.withArgs({filePath:e.path});return{routes:a.length>0?a.map(e=>({deps:{[F]:o},metadata:r,routeId:`page`,sidebarSubtree:s,slug:e,slugHint:null,template:i})):[{deps:{[F]:o},metadata:r,routeId:`page`,sidebarSubtree:s,slug:null,slugHint:ae(e.path),template:i}],entities:[o]}}},loaders:[K,q],templates:{[U]:i(n(`./client/template.tsx`,import.meta.url))}});function Y(e){let t=e.match(A);if(!t)return{content:e,frontmatter:{}};let n=t[1]??``;try{let r=_e.load(n);return{content:e.slice(t[0].length),frontmatter:f(r)?r:{}}}catch(n){let r=n instanceof Error?n.message:String(n);return{content:e.slice(t[0].length),frontmatter:{},frontmatterError:r}}}function be(){return(y()??[]).map(e=>({kind:`file`,path:e}))}function xe(e,t,n,r,i){if(r.length===0&&i===void 0)return[];let a=R(e),o=r.map(e=>Ce(e,a,n,t));if(i!==void 0){let e={start:{line:1},end:{line:n}};o.push({code:`markdown/frontmatter-parse`,message:i,location:{filePath:t,range:e,snippet:L(a,e)}})}return o}function Se(e,t){let{ids:n,exhaustive:r}=B(e,t);return{kind:`anchor`,exhaustive:r,targets:n}}function Ce(e,t,n,r){let i=e.location?.range;if(!i)return e;let a=de(i,n);return{...e,location:{filePath:r,range:a,snippet:L(t,a)}}}function we(e,t,n){let r=f(t.markdown)?t.markdown:{},i={...e.markdown?.editPage,...f(r.editPage)?r.editPage:{}};if(i.hide!==!0&&typeof i.baseUrl==`string`&&i.baseUrl!==``)return{to:`${i.baseUrl.replace(/(?<!\/)\/+$/,``)}/${n}`}}async function Te(e,t){if(!f(e)||typeof e.image!=`string`)return{seo:e,entityDeps:[],assetUsages:[]};let n=await t.markdown.resolveImageReference(e.image,t.file.path);return n.result.kind===`assetRef`?{seo:{...e,image:n.result.url},entityDeps:n.entityDeps,assetUsages:n.assetUsages}:{seo:e,entityDeps:n.entityDeps,assetUsages:[]}}function Ee(e){let t=/* @__PURE__ */ new Map;if(!u(e,`customMarkdocTags`))for(let e of b())t.set(e,`Custom Markdoc tags are not in this project's plan, so \`${e}\` is ignored.`);if(!u(e,`codeWalkthrough`))for(let e of g)t.set(e,`\`${e}\` is not in this project's plan and is ignored.`);return t}function De(e,t,n){let r=[];if(n.size===0)return r;for(let i of E(e,{getExtraNodes:h})){let e=i.type===`tag`&&i.tag!==void 0?n.get(i.tag):void 0;e!==void 0&&(r.push({code:`configuration/ignored`,message:e,location:{filePath:t,range:p(i)??{start:{line:1},end:{line:1}}}}),m(i,e))}return r}const Oe=[`image`,`links`];async function ke(e,t){let n=t.config.markdown?.frontMatterKeysToResolve??Oe,r={...e},i=[],a=[];for(let o of n){let n=e[o];if(typeof n!=`string`)continue;let s=await t.markdown.resolveLocalReference(n,t.file.path);i.push(...s.entityDeps),a.push(...s.assetUsages),s.result.kind!==`passthrough`&&(r[o]=s.result.url)}return{frontmatter:r,entityDeps:i,assetUsages:a}}async function Ae(e,t){let n=[],r=[];if(!f(e))return{value:e,entityDeps:n,linkRefs:r};let i={...e};for(let a of[`nextButton`,`previousButton`]){let o=e[a];if(!f(o)||typeof o.page!=`string`)continue;let{page:s,...c}=o,l=D(ue(s),t.file.path);l!==null&&r.push({kind:`link`,raw:s,...l});let u=await je(s,t);n.push(...u.entityDeps),i[a]={...c,label:typeof c.label==`string`?c.label:u.route&&await X(u.route,t),link:u.link}}return{value:i,entityDeps:n,linkRefs:r}}async function X(e,t){let n=await ce(t.entities,e);if(n!==void 0)return n;let r=t.routes.get(e.slug)?.metadata.seo;return f(r)&&typeof r.title==`string`&&r.title.trim()!==``?r.title:e.slug}async function je(e,t){let n=e.trim(),{path:r,suffix:i}=w(n);if(se(r)){let e=t.routes.bySlug(ne(r));return{link:e&&`${e.slug}${i}`,route:e,entityDeps:[]}}let a=await t.markdown.resolveLocalReference(n,t.file.path);if(a.result.kind!==`pageUrl`)return{entityDeps:a.entityDeps};let o=a.result.url;return{link:o,route:t.routes.bySlug(w(o).path)??a.entityDeps.map(e=>e.kind===`file`?t.routes.byFilePath(e.path):void 0).reverse().find(e=>e!==void 0),entityDeps:a.entityDeps}}function Me(e){let t=/* @__PURE__ */ new Map;for(let n of E(e)){if(n.type!==`tag`||n.tag===void 0||_[n.tag]?.attributes?.__idx===void 0)continue;let e=(t.get(n.tag)??0)+1;t.set(n.tag,e),n.attributes.__idx=e}}function Ne(e,t,n){if(e.banner===void 0)return;let{value:r,problems:i}=C(S,{banner:e.banner});for(let e of i)n?.warn(`${t}: ${e.message}`);return r.banner}function Pe(e,t){return Z(e)??le(t)??void 0}function Z(e){let t=f(e.seo)?e.seo.title:void 0;return typeof t==`string`&&t.trim()!==``?t:void 0}function Q(e){let t=(e.split(`/`).pop()??e).replace(/\.[^.]+$/,``);return t===``?e:t}function Fe(e,t){let n=e.manifest.template;if(typeof n==`string`&&n.trim()!==``)return $(n,e.path,t.logger);let r=ie(e.path,t.config.markdown?.template);return typeof r==`string`&&r.trim()!==``?$(r,`redocly.yaml`,t.logger):U}function $(e,t,n){if(!e.startsWith(`./`)&&!e.startsWith(`../`)&&!e.startsWith(`/`))return e;let r=x(e,t);return r===null?(n.warn(`Template reference "${e}" in ${t} escapes the content root; falling back to ${U}.`),U):`${d}${r}`}export{W as MARKDOC_DOCUMENT_LOADER_ID,ve as MARKDOC_SEARCH_GROUP,G as MARKDOC_SIDEBAR_ITEM_LOADER_ID,U as MARKDOC_TEMPLATE_ID,ye as markdocContentPlugin};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{A2A_ROUTE as e,MCP_ROUTE as t,MCP_SERVER_CARD_ROUTE as n}from"../constants.js";import{withPathPrefix as r}from"../../../../../shared/path-prefix.js";import{SKILLS_INDEX_SLUG as i,skillMarkdownPath as a}from"../../../utils/skill-paths.js";import{isMcpContentProtected as o,isMcpHidden as s,resolveMcpAccess as c}from"./config-gate.js";import{SKILL_ENTITY_TYPE as l}from"../../../types/skill-entity.js";import{
|
|
1
|
+
import{A2A_ROUTE as e,MCP_ROUTE as t,MCP_SERVER_CARD_ROUTE as n}from"../constants.js";import{withPathPrefix as r}from"../../../../../shared/path-prefix.js";import{SKILLS_INDEX_SLUG as i,skillMarkdownPath as a}from"../../../utils/skill-paths.js";import{isMcpContentProtected as o,isMcpHidden as s,resolveMcpAccess as c}from"./config-gate.js";import{SKILL_ENTITY_TYPE as l}from"../../../types/skill-entity.js";import{isEntityScopeVisible as u}from"../../../../../shared/rbac/entity-scope.js";import{notFoundResponse as d}from"../../../../../server/plugin-context.js";import{publicBaseUrl as f}from"../../../utils/request-origin.js";import{CORS_ANY_ORIGIN as p,MCP_AUTH_SCHEMES as m}from"./oauth/constants.js";import"./auth.js";const h=[`text/plain`],g=[`text/plain`],_={streaming:!1,pushNotifications:!1},v={"Cache-Control":`no-store`};async function y(e,t){let n=!!e.request.viewer?.isAuthenticated;return o(c(e.config))&&!n?[]:(await e.entities.list({type:l})).flatMap(n=>{let{slug:i,title:o,description:s}=n.metadata??{};return typeof i!=`string`||!u(n,e.request.teams,t=>e.logger?.warn(t))?[]:[{id:i,name:o??i,description:s??``,tags:[],url:`${t}${r(a(i))}`}]})}async function b(n,i){if(s(i.config)||i.config.skills?.hide===!0)return d();n.set(`realmCacheControlOwned`,!0);let a=f(i.config,i.request),l=o(c(i.config)),u=i.config.seo;return n.json({name:u?.title||u?.projectTitle||`Developer Documentation`,description:u?.description||`Documentation agent card announcing this site's agent skills and MCP server.`,url:`${a}${r(e)}`,documentationUrl:`${a}${r(`/`)}`,version:`0.0.1`,protocolVersion:`0.3.0`,preferredTransport:`HTTP+JSON`,capabilities:{..._,extensions:[{uri:`https://modelcontextprotocol.io`,description:`Model Context Protocol server exposing the documentation tools and skills.`,params:{url:`${a}${r(t)}`,...l?{authentication:{required:!0,schemes:[...m]}}:{}}}]},defaultInputModes:h,defaultOutputModes:g,skills:await y(i,a)},200,{...v,...p})}function x(e,t){if(s(t.config))return d();let a=[`<${r(n)}>; rel="mcp-server-card"`];return t.config.skills?.hide!==!0&&a.push(`<${r(i)}>; rel="agent-skills"`),e.json({error:{code:`405`,message:`Method not allowed`}},405,{Link:a.join(`, `),...p,"Access-Control-Expose-Headers":`Link`})}export{x as a2a,b as agentCard};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{MCP_AUTHORIZATION_SERVER_ROUTE as e,MCP_PROTECTED_RESOURCE_ROUTE as t,PUBLIC_MCP_ROUTE as n}from"../constants.js";import{withPathPrefix as r}from"../../../../../shared/path-prefix.js";import{ANONYMOUS_VIEWER as i}from"../../../../../shared/types/auth.js";import{canAccessMcpFeature as a,isMcpContentProtected as o,isPublicEndpointServed as s,resolveMcpAccess as c}from"./config-gate.js";import{
|
|
1
|
+
import{MCP_AUTHORIZATION_SERVER_ROUTE as e,MCP_PROTECTED_RESOURCE_ROUTE as t,PUBLIC_MCP_ROUTE as n}from"../constants.js";import{withPathPrefix as r}from"../../../../../shared/path-prefix.js";import{ANONYMOUS_VIEWER as i}from"../../../../../shared/types/auth.js";import{canAccessMcpFeature as a,isMcpContentProtected as o,isPublicEndpointServed as s,resolveMcpAccess as c}from"./config-gate.js";import{getBearerVerifier as l,getSessionIssuer as u}from"../../../../../server/auth/middleware.js";import{publicOrigin as d}from"../../../utils/request-origin.js";import{isAssistantAnonymousToken as f}from"../../../../../server/ask-ai/assistant-anonymous-token.js";import{CORS_ANY_ORIGIN as p,CORS_EXPOSE_CHALLENGE as m,SUPPORTED_MCP_SCOPES as h}from"./oauth/constants.js";function g(e){let t=/^Bearer\s+(\S+)$/i.exec((e??``).trim());return t?t[1]:null}function _(n,i){let a=i?[`error="${i.code}"`,`error_description="${i.description}"`]:[];return a.push(`resource_metadata="${n}${r(t)}"`,`scope="${h.join(` `)}"`,`authorization_uri="${n}${r(e)}"`),`Bearer ${a.join(`, `)}`}function v(e,t){return t?`${e}. A public endpoint that serves anonymous-accessible content is available at ${t}.`:e}function y(e,t,n){return new Response(JSON.stringify(t),{status:e,headers:{"Content-Type":`application/json`,"Cache-Control":`no-store`,...n}})}function b(e,t){return y(401,{error:`unauthorized`,message:v(`Authentication required`,t)},{"WWW-Authenticate":_(e),...m})}function x(e,t){return y(401,{error:`invalid_token`,message:v(`Invalid or expired token`,t)},{"WWW-Authenticate":_(e,{code:`invalid_token`,description:`Invalid or expired token`}),...m})}function S(){return y(403,{error:`forbidden`,message:`You do not have access to this MCP server`},{...p})}async function C(e){let{c:t,ctx:p}=e,m=e=>p.logger?.warn(e),h=c(p.config),_=o(h);if(e.forceAnonymous){let e=await p.withViewer(i);return a(h,e.request.teams,!1,m)?{kind:`allow`,ctx:e,isProtected:_}:{kind:`deny`,response:S()}}let v=e=>{let t=d(p.request);return{kind:`deny`,response:e(t,s(p.config,h)?`${t}${r(n)}`:void 0)}},y=p.request.viewer??i,C,w,T=p,E=g(t.req.header(`authorization`)),D=u(t)?.artifactSecret,O=E!==null&&D!==void 0&&await f(E,D);if(!_)w=O||E===null?void 0:E;else if(O)y=i,T=await p.withViewer(i);else if(E!==null){let e=await l(t)?.(E);if(!e)return v(x);y=e.viewer,C=e.claims,w=E,T=await p.withViewer(y)}else if(!y.isAuthenticated)return v(b);return a(h,T.request.teams,y.isAuthenticated,m)?{kind:`allow`,ctx:T,isProtected:_,accessToken:w,claims:C}:{kind:`deny`,response:S()}}export{C as authorizeMcpRequest,o as isMcpContentProtected,s as isPublicEndpointServed,g as readBearerToken,c as resolveMcpAccess};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{MCP_TOOLS_ENTITY_TYPE as e}from"../constants.js";import{publicOrigin as t}from"../../../utils/request-origin.js";import{
|
|
1
|
+
import{MCP_TOOLS_ENTITY_TYPE as e}from"../constants.js";import{publicOrigin as t}from"../../../utils/request-origin.js";import{errorMessage as n}from"../../../../../shared/utils/error-message.js";import{isSubprocessError as r}from"../../../../../server/subprocess/runner.js";import{ToolHandlerError as i}from"./tool-errors.js";import{fileURLToPath as a}from"node:url";import{parse as o}from"hono/utils/cookie";const s=a(import.meta.url);function c(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function l(e){return`MCP tool "${e}" is not registered or its module does not export a handler for "${e}". Expected \`export default { '${e}': handler }\` or a single tool definition with \`description\` and \`execute\` as the default export.`}function u(e,t){if(c(e))return typeof e.execute==`function`&&typeof e.description==`string`?e:e[t]}const d=/* @__PURE__ */ new Set([`text`,`image`,`audio`,`resource`,`resource_link`]);function f(e){return c(e)&&Array.isArray(e.content)&&e.content.every(e=>c(e)&&d.has(e.type))}function p(e,t){if(f(t))return t;if(typeof t==`string`)return{content:[{type:`text`,text:t}]};let n;try{n=JSON.stringify(t)}catch(t){throw Error(`MCP tool "${e}" returned a value that cannot be serialized to JSON: ${S(t)}`)}if(n===void 0)throw Error(`MCP tool "${e}" returned an invalid result.`);return{content:[{type:`text`,text:n}]}}const m={readFile:async()=>{throw Error(`Project files are not available in this environment.`)}};async function h(e,t){let r=u((await t.loadModule(e.handlerModulePath)).default,e.toolName),i=typeof r==`function`?r:r?.execute;if(typeof i!=`function`)return{ok:!1,code:`no-handler-export`,message:l(e.toolName)};let a={...e.context,fs:m};try{if(e.mode===`isAvailable`){let e=typeof r==`function`?void 0:r?.isAvailable;return{ok:!0,output:!e||await e(a)}}let t=await i(e.args,a,e.extra);return{ok:!0,output:p(e.toolName,t)}}catch(e){return{ok:!1,code:`handler-error`,message:n(e),stack:e instanceof Error?e.stack:void 0}}}function g(e){let n=e.request.viewer;return{user:{teams:e.request.teams,claims:e.claims??{...n},email:n?.email,idpAccessToken:void 0,idpId:void 0,isAuthenticated:n?.isAuthenticated??!1},config:e.config,baseUrl:t(e.request),params:{},query:Object.fromEntries(new URL(e.request.url).searchParams),cookies:o(e.request.headers.cookie??``),products:Object.values(e.config.products??{}).map(e=>e.name),accessToken:e.accessToken,metadata:e.metadata}}function _(e,t,n){if(!c(e)||e.type!==`object`)return null;let r=`Invalid arguments for tool "${n}":`;if(!c(t))return`${r} expected an object.`;let i=Array.isArray(e.required)?e.required:[];for(let e of i)if(typeof e==`string`&&!(e in t))return`${r} missing required field "${e}".`;let a=c(e.properties)?e.properties:{};for(let[e,n]of Object.entries(t)){let t=a[e];if(c(t)){if(typeof t.type==`string`&&!v(n,t.type))return`${r} field "${e}" must be ${t.type}.`;if(Array.isArray(t.enum)&&!t.enum.includes(n))return`${r} field "${e}" must be one of ${JSON.stringify(t.enum)}.`}}return null}function v(e,t){switch(t){case`string`:return typeof e==`string`;case`number`:return typeof e==`number`&&Number.isFinite(e);case`integer`:return typeof e==`number`&&Number.isInteger(e);case`boolean`:return typeof e==`boolean`;case`object`:return c(e);case`array`:return Array.isArray(e);case`null`:return e===null;default:return!0}}function y(e,t,n,r,i){if(!t.subprocess)throw Error(`MCP tool "${e.toolName}" cannot run on this host: no subprocess.`);return t.subprocess.run({modulePath:s,exportName:`invokeCustomTool`,input:{handlerModulePath:t.subprocess.resolveContentModule(e.handlerFilePath),toolName:e.toolName,mode:n,args:r,context:g(t),extra:{sessionId:i?.sessionId,requestId:i?.mcpReq.id??t.requestId,_meta:i?.mcpReq._meta}},reuse:!import.meta.env.DEV,timeoutMs:3e4})}function b(e,t){return{schema:e,isAvailable:t.hasAvailabilityGate?async n=>{if(!n.subprocess)return!1;let r=n.isAvailableMemo?.get(e.name);if(r)return r;let i=(async()=>{try{let e=await y(t,n,`isAvailable`);return e.ok&&e.output===!0}catch(t){return n.logger?.warn(`MCP tool "${e.name}" isAvailable failed: ${S(t)}`),!1}})();return n.isAvailableMemo?.set(e.name,i),i}:void 0,async execute(n,r,a){let o=_(t.argsSchema,n,e.name);if(o)throw Error(o);let s=await y(t,r,`execute`,n,a);if(!s.ok){let e=new i(s.message);throw e.stack=s.stack??e.stack,e}return s.output}}}function x(e){let{declaration:t}=e;return b({name:t.name,title:t.title,description:t.description,schema:t.schema,outputSchema:t.outputSchema,annotations:t.annotations},{toolName:t.name,handlerFilePath:e.handler.filePath,argsSchema:t.schema,hasAvailabilityGate:!0})}function S(e){return r(e)?`${e.code}: ${e.message}`:n(e)}function C(e,t){if(!c(t))return{ok:!1,errors:["the default export must be an object with `description` and `execute` properties. Move shared helper code outside the `@mcp` folder."]};let{description:n,inputSchema:r,outputSchema:i,annotations:a,isAvailable:o,execute:s}=t,l=[];return(typeof n!=`string`||n.trim()===``)&&l.push("`description` must be a non-empty string."),typeof s!=`function`&&l.push("`execute` must be a function."),r!==void 0&&(c(r)?r.type!==void 0&&r.type!==`object`&&l.push('`inputSchema.type` must be "object" because MCP tool arguments are named.'):l.push("`inputSchema` must be a JSON Schema object.")),i!==void 0&&!c(i)&&l.push("`outputSchema` must be a JSON Schema object."),a!==void 0&&!c(a)&&l.push("`annotations` must be an object."),o!==void 0&&typeof o!=`function`&&l.push("`isAvailable` must be a function."),l.length>0||typeof n!=`string`?{ok:!1,errors:l}:{ok:!0,schema:{name:e,description:n,schema:Object.assign({type:`object`},r??{properties:{}}),outputSchema:i,annotations:a},hasAvailabilityGate:typeof o==`function`}}async function w(t){let n=[],r=[];for(let i of await t.entities.list({type:e})){let{name:e,sourcePath:a}=i.metadata,o=e=>r.push(`Invalid MCP tool file "${a}": ${e}`);if(t.reservedNames.has(e)){o(`the tool name "${e}" is already used by a built-in MCP tool. Rename the file.`);continue}let s;try{s=(await t.loadContentModule(a)).default}catch(e){o(`the file failed to load: ${S(e)}. Tool files must not have module-level side effects.`);continue}let c=C(e,s);if(!c.ok){o(c.errors.join(` `));continue}n.push({schema:c.schema,sourcePath:a,hasAvailabilityGate:c.hasAvailabilityGate})}return{tools:n,errors:r}}function T(e){return`MCP tool "${e.schema.name}" in ${e.sourcePath} declares no \`outputSchema\`. Add one that describes the returned value.`}const E=/* @__PURE__ */ new Set;function D(e,t){e&&!E.has(t)&&(E.add(t),e.warn(t))}async function O(e){let{loadContentModule:t,logger:n}=e;if(!t)return[];let{tools:r,errors:i}=await w({entities:e.entities,loadContentModule:t,reservedNames:e.reservedNames});for(let e of i)D(n,e);for(let e of r)e.schema.outputSchema===void 0&&D(n,T(e));return r.map(e=>b(e.schema,{toolName:e.schema.name,handlerFilePath:e.sourcePath,argsSchema:e.schema.schema,hasAvailabilityGate:e.hasAvailabilityGate}))}export{O as buildMcpFileTools,x as createCustomTool,h as invokeCustomTool,w as loadMcpFileTools,T as missingOutputSchemaWarning,C as validateToolDefinition};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{AI_METADATA_HEADER as e}from"../constants.js";import{isMcpHidden as t,isPublicEndpointServed as n,resolveMcpAccess as r}from"./config-gate.js";import{
|
|
1
|
+
import{AI_METADATA_HEADER as e}from"../constants.js";import{isMcpHidden as t,isPublicEndpointServed as n,resolveMcpAccess as r}from"./config-gate.js";import{notFoundResponse as i}from"../../../../../server/plugin-context.js";import{publicOrigin as a}from"../../../utils/request-origin.js";import{formatError as o,jsonRpcErrorResponse as s}from"./tool-errors.js";import{buildMcpFileTools as c,createCustomTool as l,invokeCustomTool as u}from"./custom-tools.js";import{authorizeMcpRequest as d}from"./auth.js";import{EXECUTE_DEADLINE_MS as f}from"./codemode/constants.js";import{resolveMcpMode as p,resolveRequestInstructionsStyle as m,resolveRequestMcpMode as h}from"./mode.js";import{narrowMcpConfigForCaller as g}from"./gateway/caller-api-calls.js";import{isGatewayEnabled as _}from"./gateway/env.js";import{userSubject as v}from"./gateway/subject.js";import{parseUserAgent as y}from"./mcp-client.js";import{createMcpTelemetry as b}from"./mcp-telemetry.js";import{applyMcpRateLimit as x}from"./rate-limit.js";import{createToolRegistry as S}from"./tool-registry.js";import{mcpToolRegistry as C}from"./registry-instance.js";const w=`POST`;function T(e){return(e??``).split(`,`).some(e=>{let[t,...n]=e.split(`;`).map(e=>e.trim().toLowerCase());if(t!==`text/html`)return!1;let r=n.find(e=>e.startsWith(`q=`));return r===void 0||Number(r.slice(2))>0})}function E(){return s(405,`Method not allowed`,{Allow:w})}function D(e){let t={error:`Method Not Allowed`,message:`In order to use this MCP server, you need to register it in your MCP client (VS Code, Cursor, Claude Code, etc.) using this URL: ${e}`};return new Response(JSON.stringify(t),{status:405,headers:{"Content-Type":`application/json`,"Cache-Control":`no-store`,Allow:w}})}function O(){return s(501,`MCP transport is not available in this environment`)}function k(e){if(!e)return{};try{let t=JSON.parse(e);return typeof t==`object`&&t&&!Array.isArray(t)?t:{}}catch{return{}}}function A(t,n,r,i){let a=k(t.headers.get(e)),{userAgent:o}=n.request,{client:s,clientVersion:c}=y(o),l=h(t.url,p()),u=crypto.randomUUID(),d=v(n.request.viewer),f=n.request.ip??void 0;return{config:{...n.config,mcp:g(n.config.mcp,a)},entities:n.entities,hasRoute:e=>n.hasRoute(e),isSlugVisible:(e,t)=>n.isSlugVisible(e,t),kv:n.kv,gatewaySecretSeed:n.gatewaySecretSeed,logger:n.logger,pageMarkdown:n.pageMarkdown,search:n.search,request:n.request,metadata:a,mcpMode:l,instructionsStyle:m(t.url),requestId:u,executeDeadline:i,messageId:typeof a.messageId==`string`?a.messageId:void 0,callerSubject:d,client:s,clientVersion:c,accessToken:r.accessToken,isProtected:r.isProtected??!1,isAvailableMemo:/* @__PURE__ */ new Map,subprocess:n.subprocess,claims:r.claims,telemetry:b({userAgent:o,request:t,metadata:a,mode:l,requestId:u,callerSubject:d,clientIp:f,logger:n.logger})}}async function j(e){let t=_(e.config)?(await import(`./gateway/tool-list.js`)).gatewayTools():[],n=e.subprocess?e.mcpToolEntries??[]:[],r=C.list(),i=/* @__PURE__ */ new Set([...r.map(e=>e.schema.name),...t.map(e=>e.schema.name),...n.map(e=>e.declaration.name)]),a=e.subprocess?await c({entities:e.entities,loadContentModule:e.loadContentModule,reservedNames:i,logger:e.logger}):[];if(t.length===0&&n.length===0&&a.length===0)return C;let o=S();for(let e of r)o.register(e);for(let e of t)o.register(e);for(let e of n)o.register(l(e));for(let e of a)o.register(e);return o}async function M(e,t,n,r={}){let i=await j(e),a;try{a=await import(`./mcp-server.js`)}catch(t){return e.logger?.error(`MCP transport failed to load: ${o(t)}`),async()=>O()}let s;return a.createMcpRequestHandler({registry:i,logger:e.logger,buildToolContext:r=>s??=A(r,e,t,n),onError:r.onError})}function N(e={}){return async(o,s,c)=>{let l=Date.now()+f;if(t(c.config)||e.publicEndpoint&&!n(c.config,r(c.config)))return i();if(o.req.method===`GET`&&T(o.req.header(`accept`)))return s();let u=await x({kv:c.kv,ip:c.request.ip,bucket:`mcp`,logger:c.logger});if(u)return u;let p=await d({c:o,ctx:c,forceAnonymous:e.forceAnonymous});return p.kind===`deny`?p.response:o.req.method===`GET`?D(`${a(c.request)}${new URL(c.request.url).pathname}`):o.req.method===`POST`?(await M(p.ctx,{isProtected:p.isProtected,accessToken:p.accessToken,claims:p.claims},l))(o.req.raw):E()}}const P=N(),F=N({forceAnonymous:!0,publicEndpoint:!0});export{A as buildToolContext,N as createMcpHandler,M as createServedMcpRequestHandler,u as invokeCustomTool,P as mcp,F as mcpPublic};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import"../constants.js";import{errorMessage as e}from"../../../../../shared/utils/error-message.js";import{
|
|
1
|
+
import"../constants.js";import{errorMessage as e}from"../../../../../shared/utils/error-message.js";import{isServerTelemetryEnabled as t}from"../../../../../server/telemetry/collector.js";import{sendServerEvent as n,sendServerEvents as r}from"../../../../../server/telemetry/sender.js";import{innerToolErrorClass as i,thrownErrorClass as a}from"./tool-errors.js";import{auditCode as o,auditInput as s,auditSha256 as c,auditStack as l,isCallToolResult as u,toolOutputText as d,toolResultText as f}from"./audit.js";import{SANDBOX_FAILURE as p}from"./codemode/constants.js";import{parseUserAgent as m,readListingSource as h}from"./mcp-client.js";import{randomUUID as g}from"node:crypto";import{ulid as _}from"ulid";const v={id:`docs`,object:`mcpServer`,uri:`urn:redocly:realm:mcp:server:docs`};function y(e){if(e===void 0)return;let t=c(e);return{id:t,object:`user`,uri:`urn:redocly:realm:mcp:subject:${t}`}}function b(n){let{mode:c,requestId:g,callerSubject:_,clientIp:b,logger:x}=n,S=n.env??process.env,C=t(S),w=y(_),{client:T,clientVersion:E}=m(n.userAgent),D=n.metadata.messageId,O={client:T,client_version:E,message_id:typeof D==`string`?D:void 0,listing_source:h(n.request)},j=[],M=/* @__PURE__ */ new Set,N=/* @__PURE__ */ new WeakSet,P=(e,t)=>{j.push({type:e,data:[t],requestId:g,time:/* @__PURE__ */ new Date,actor:w,clientIp:b})},F=t=>{try{t()}catch(t){x?.warn(`MCP telemetry failed: ${e(t)}`)}},I=(e,t,n)=>P(`com.redocly.mcpServer.toolCalled`,{...v,tool:e,mode:c,output_length:n,duration_ms:t,...O}),L=(e,t,n)=>{n.stack&&x?.error(`MCP tool ${e} failed (${n.error_class})`,{request_id:g,stack:n.stack}),P(`com.redocly.mcpServer.error`,{...v,tool:e,mode:c,duration_ms:t,message:s(n.message),stack:l(n.stack),error_class:n.error_class,...O})},R=async(t,n,r)=>{let a=Date.now(),o;try{o=await n()}catch(n){let o=i(n),s=o===`server_error`;throw r.set(e(n),{tool:t,reason:s?`server_error`:`inner_tool_error`}),F(()=>L(t,Date.now()-a,{message:e(n),stack:s&&n instanceof Error?n.stack??``:``,error_class:o})),n}return F(()=>I(t,Date.now()-a,d(o).length)),o};return{toolReturned(e,t,n){F(()=>{if(!u(n)||n.isError!==!0){I(e,t,d(n).length);return}N.has(n)||L(e,t,{message:f(n,` `),stack:``,error_class:e===`execute`?`sandbox_error`:`tool_error`})})},toolThrew(t,n,r){F(()=>{let i=a(r);L(t,n,{message:e(r),stack:i===`server_error`&&r instanceof Error?r.stack??``:``,error_class:i})})},trackCodeExecution(t,n){let r=Date.now(),i=o(t),a=/* @__PURE__ */ new Map,s=0;return{hostFetch:n&&(t=>(s+=1,n(t).catch(t=>{throw a.set(e(t),{reason:`runtime_error`}),t}))),innerToolCall(e,t){let n=R(e,t,a),r=n.then(()=>void 0,()=>void 0);return M.add(r),r.then(()=>M.delete(r)),n},finish(e,t,n){let o=e.failure===p.HostError&&e.error!==void 0?a.get(e.error):void 0;o?.tool&&N.add(t);let c=e.error===void 0?`ok`:`error`,l=Date.now()-r,u=k(e.failure,o,n),d=o?.tool;F(()=>P(`com.redocly.mcpServer.codeExecuted`,{...v,code_sha256:i.sha256,code_length:i.length,fetch_count:s,outcome:c,flags:i.flags,duration_ms:l,failure_reason:u,failed_tool:d,...O})),x?.info(`Gateway MCP code executed [${i.sha256.slice(0,12)}] outcome=${c} codeLength=${i.length} fetchCount=${s}`+(i.flags?` flags=${i.flags}`:``)+` durationMs=${l}`+(u?` failureReason=${u}`:``)+(d?` failedTool=${d}`:``))}}},gatewayFetchPerformed({host:e,method:t,outcome:n,durationMs:r,path:i,api:a,status:o,bytes:s,injectedScheme:c}){F(()=>P(`com.redocly.mcpServer.gatewayFetchPerformed`,{...v,host:e,method:t,outcome:n,path:i,api:a,status:o,injected_scheme:c,bytes:s,duration_ms:r})),x?.info(`Gateway MCP fetch [${t} ${e}] outcome=${n}`+(i===void 0?``:` path=${i}`)+(a===void 0?``:` api=${a}`)+(o===void 0?``:` status=${o}`)+(c===void 0?``:` injectedScheme=${c}`)+(s===void 0?``:` bytes=${s}`)+` durationMs=${r}`)},gatewayFetchRateLimited({scope:e,limit:t,retryAfterSeconds:n}){F(()=>P(`com.redocly.mcpServer.gatewayFetchRateLimited`,{...v,scope:e,retry_after_seconds:n,limit:t}))},async flush(){if(!C){j=[];return}await A(M,300);let e=j;j=[],await r(e,{env:S,fetcher:n.fetcher,logger:x})}}}function x(e,t){let{requestId:r=g(),callerSubject:i,clientIp:a}=t.caller??{};return n({...e,requestId:r,actor:y(i),clientIp:a},t)}function S(e,t,n={}){return x({type:`com.redocly.mcpServer.error`,data:[{...v,message:s(e instanceof Error?e.message:``),stack:l(e instanceof Error?e.stack??``:``),error_class:`server_error`,mode:t}]},n)}function C({scope:e,retryAfterSeconds:t,limit:n},r={}){return x({type:`com.redocly.mcpServer.rateLimited`,data:[{...v,scope:e,retry_after_seconds:t,limit:n}]},r)}function w(e){let t=e||_(),n=t.startsWith(`mcp_`)?t:`mcp_${t}`;return{id:n,object:`mcpSession`,uri:`urn:redocly:realm:mcp:session:${n}`}}function T(e,t,n={}){return x({type:`com.redocly.mcpServerAuthorization.started`,data:[{...w(e),redirect_uri:t}]},n)}function E(e,t,n={}){return x({type:`com.redocly.mcpServerAuthorization.completed`,data:[{...w(e),redirect_uri:t}]},n)}function D(e,t,n,r,i={}){return x({type:`com.redocly.mcpServerAuthorization.failed`,data:[{...w(e),error:n,error_details:r,error_class:t}]},i)}function O(e={}){return x({type:`com.redocly.mcpServerCard.served`,data:{id:`mcpServerCardId`,object:`mcpServerCard`,uri:`urn:redocly:realm:api:mcpServerCard:mcpServerCardId`},signal:`trace`},e)}function k(e,t,n){return e===p.HostError?t?.reason??p.RuntimeError:e===p.RuntimeError&&n!==void 0?`unknown_tool`:e}async function A(e,t){if(e.size===0)return;let n;await Promise.race([Promise.allSettled(e),new Promise(e=>{n=setTimeout(e,t)})]),clearTimeout(n)}export{b as createMcpTelemetry,E as sendMcpAuthorizationCompleted,D as sendMcpAuthorizationFailed,T as sendMcpAuthorizationStarted,C as sendMcpRateLimited,S as sendMcpRequestError,O as sendMcpServerCardServed};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{MCP_CALLBACK_ROUTE as e}from"../../constants.js";import{SystemRoute as t}from"../../../../../../shared/constants/system-routes.js";import{withPathPrefix as n}from"../../../../../../shared/path-prefix.js";import{isMcpContentProtected as r,isMcpHidden as i,resolveMcpAccess as a}from"../config-gate.js";import{
|
|
1
|
+
import{MCP_CALLBACK_ROUTE as e}from"../../constants.js";import{SystemRoute as t}from"../../../../../../shared/constants/system-routes.js";import{withPathPrefix as n}from"../../../../../../shared/path-prefix.js";import{isMcpContentProtected as r,isMcpHidden as i,resolveMcpAccess as a}from"../config-gate.js";import{getSessionIssuer as o}from"../../../../../../server/auth/middleware.js";import{notFoundResponse as s}from"../../../../../../server/plugin-context.js";import{SUPPORTED_CODE_CHALLENGE_METHODS as c}from"./constants.js";import"../auth.js";import{sendMcpAuthorizationStarted as l}from"../mcp-telemetry.js";import{applyMcpRateLimit as u}from"../rate-limit.js";import{parseRedirectUri as d}from"./redirect-uri.js";import{fetchClientMetadataDocument as f,isClientMetadataDocumentUrl as p,isRedirectUriRegistered as m}from"./client-metadata.js";import{readMcpClient as h}from"./client-registry.js";import{reportMcpAuthorizationFailure as g,withMcpFailureReporting as _}from"./error-reporting.js";import{isSupportedCodeChallengeMethod as v,signMcpArtifact as y}from"./tokens.js";import{ulid as b}from"ulid";function x(e,t){return e.json({error:`invalid_request`,error_description:t},400)}async function S(e,t,n){if(p(t)){let r;try{r=await f(t)}catch(t){let n=`Unable to resolve client metadata document: ${t instanceof Error?t.message:String(t)}`;return await g(e,n),{ok:!1,error:n}}return{ok:!0,allowed:m(n,r.redirect_uris),clientName:r.client_name??null}}let r=(await h(e.kv,t))?.redirect_uris??[];return{ok:!0,allowed:r.length===0||m(n,r),clientName:null}}const C=_(w,e=>e.json({error:`server_error`,error_description:`The server could not complete the request`},500));async function w(f,p){if(i(p.config)||!r(a(p.config)))return s();let m=o(f);if(!m)return s();let h=await u({kv:p.kv,ip:p.request.ip,bucket:`oauth`,logger:p.logger});if(h)return h;let g=new URL(f.req.url).searchParams,_=g.get(`redirect_uri`),C=g.get(`client_id`),w=g.get(`code_challenge`),T=g.get(`code_challenge_method`);if(!_||!d(_))return x(f,`redirect_uri must be an https URL, a loopback http URL, or a private-use scheme`);if(!C)return x(f,`client_id is required`);if(!w)return x(f,`code_challenge is required`);if(!T||!v(T))return x(f,`Unsupported code_challenge_method. Supported: ${c.join(`, `)}`);let E=await S(p,C,_);if(!E.ok)return f.json({error:`invalid_client`,error_description:E.error},400);if(!E.allowed)return x(f,`redirect_uri is not registered for this client`);let D=b(),O=await y({type:`mcp_context`,sessionId:D,redirectUri:_,clientId:C,clientName:E.clientName,state:g.get(`state`),codeChallenge:w,codeChallengeMethod:T},m.artifactSecret,Math.floor(Date.now()/1e3)+600);await l(D,_,{logger:p.logger});let k=new URLSearchParams({redirectTo:`${e}/${O}`});return f.redirect(`${n(t.AuthIdpLogin)}?${k.toString()}`,302)}export{C as mcpAuthorize};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isMcpHidden as e}from"../config-gate.js";import{REALM_SESSION_COOKIE as t}from"../../../../../../server/auth/constants.js";import{
|
|
1
|
+
import{isMcpHidden as e}from"../config-gate.js";import{REALM_SESSION_COOKIE as t}from"../../../../../../server/auth/constants.js";import{getBearerVerifier as n,getSessionIssuer as r}from"../../../../../../server/auth/middleware.js";import{notFoundResponse as i}from"../../../../../../server/plugin-context.js";import{MCP_REFRESH_SESSION_LIFETIME_SEC as a,SUPPORTED_MCP_SCOPES as o}from"./constants.js";import{auditInput as s}from"../audit.js";import{sendMcpAuthorizationCompleted as c}from"../mcp-telemetry.js";import{loadPageSite as l}from"../gateway/credentials-page/site-branding.js";import{isLoopbackRedirect as u,parseRedirectUri as d}from"./redirect-uri.js";import{isClientMetadataDocumentUrl as f}from"./client-metadata.js";import{reportMcpAuthorizationFailure as p,withMcpFailureReporting as m}from"./error-reporting.js";import{sessionClaimsFromSession as h,sha256Base64Url as g,signMcpArtifact as _,verifyMcpArtifact as v}from"./tokens.js";import{CONSENT_PAGE_HEADERS as y,consentInvalidPage as b,consentPage as x}from"./consent-page.js";import{hasConsent as S,saveConsent as C}from"./store.js";import{getCookie as w}from"hono/cookie";const T={"Cache-Control":`no-store`},E=`Missing context token`;function D(e){let t=e.searchParams.get(`context`);if(t)return t;let n=e.pathname.split(`/`).filter(Boolean).pop();return n&&n!==`callback`?n:null}async function O(e,r){let i=new URL(e.req.url),a=w(e,t),o=a?await n(e)?.(a):null;return{method:e.req.method,path:`${i.pathname}${i.search}`,referer:e.req.header(`referer`)??null,user_agent:r.request.userAgent,has_session_cookie:a!==void 0,has_user_session:!!o&&o?.claims.tokenUse!==`mcp_access_token`}}function k(a){return async(o,c)=>{if(e(c.config))return i();let l=r(o);if(!l)return i();let u=D(new URL(o.req.url));if(!u){let e=await O(o,c);return await p(c,E,{details:s(JSON.stringify(e)),logFields:e}),o.text(E,400,T)}let f,m,h;try{if(f=await v(u,l.artifactSecret,`mcp_context`),h=f.sessionId,o.set(`realmMcpSessionId`,h),m=d(f.redirectUri),!m)throw Error(`Invalid MCP context`)}catch(e){let t=await p(c,e,{sessionId:h,errorClass:`client_error`,logMessage:`MCP callback failed`});return o.text(`Invalid MCP callback: ${t}`,400,T)}let g=w(o,t),_=g?await n(o)?.(g):null;return!g||!_||_.claims.tokenUse===`mcp_access_token`?(await p(c,`Authentication required`,{sessionId:h}),o.text(`Authentication required`,401,T)):a(o,c,{issuer:l,contextToken:u,mcpContext:f,redirectUrl:m,sessionToken:g,session:_})}}async function A(e,t,{issuer:n,mcpContext:r,redirectUrl:i,session:o}){let s=Math.floor(Date.now()/1e3),l=await _({type:`mcp_auth_code`,sessionId:r.sessionId,clientId:r.clientId,redirectUri:r.redirectUri,claims:h(o),sessionExp:s+a,codeChallenge:r.codeChallenge,codeChallengeMethod:r.codeChallengeMethod},n.artifactSecret,s+600),u=new URL(i);return u.searchParams.set(`code`,l),r.state&&u.searchParams.set(`state`,r.state),await c(r.sessionId,r.redirectUri,{logger:t.logger}),e.header(`Cache-Control`,`no-store`),e.redirect(u.toString(),302)}async function j(e,t,{mcpContext:n,redirectUrl:r}){let i=new URL(r);return i.searchParams.set(`error`,`access_denied`),n.state&&i.searchParams.set(`state`,n.state),await p(t,`access_denied`,{sessionId:n.sessionId}),e.header(`Cache-Control`,`no-store`),e.redirect(i.toString(),302)}function M({mcpContext:e,session:t}){return{idpId:t.claims.idpId,subject:t.viewer.sub,clientId:e.clientId,redirectUri:e.redirectUri}}function N({issuer:e,sessionToken:t,contextToken:n}){return _({type:`mcp_consent`,sessionHash:g(t),contextHash:g(n)},e.artifactSecret,Math.floor(Date.now()/1e3)+300)}async function P(e,{issuer:t,sessionToken:n,contextToken:r}){try{let i=await v(e,t.artifactSecret,`mcp_consent`);return i.sessionHash===g(n)&&i.contextHash===g(r)}catch{return!1}}const F=e=>e.text(`MCP authorization could not be completed`,500,T),I=m(k(async(e,t,n)=>{if(u(n.redirectUrl)||await S(t.kv,M(n)))return A(e,t,n);let{clientId:r,clientName:i}=n.mcpContext,{viewer:s}=n.session,c=x({site:await l(t),user:s.email||s.name||s.sub,clientName:i??void 0,clientIdHost:f(r)?new URL(r).host:void 0,redirectUrl:n.redirectUrl,scopes:o,accessLifetimeHours:a/3600,rememberDays:30,consentToken:await N(n)});return e.set(`realmCacheControlOwned`,!0),new Response(c,{status:200,headers:y})}),F),L=m(k(async(e,t,n)=>{let r=await e.req.formData().catch(()=>null),i=r?.get(`consent`);return typeof i!=`string`||!await P(i,n)?new Response(b(await l(t)),{status:403,headers:y}):r?.get(`decision`)===`allow`?(await C(t.kv,M(n)),A(e,t,n)):j(e,t,n)}),F);export{I as mcpCallback,L as mcpConsent};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{MCP_AUTHORIZATION_SERVER_ROUTE as e,MCP_AUTHORIZE_ROUTE as t,MCP_REGISTER_ROUTE as n,MCP_ROUTE as r,MCP_TOKEN_ROUTE as i}from"../../constants.js";import{withPathPrefix as a}from"../../../../../../shared/path-prefix.js";import{isMcpContentProtected as o,isMcpHidden as s,resolveMcpAccess as c}from"../config-gate.js";import{
|
|
1
|
+
import{MCP_AUTHORIZATION_SERVER_ROUTE as e,MCP_AUTHORIZE_ROUTE as t,MCP_REGISTER_ROUTE as n,MCP_ROUTE as r,MCP_TOKEN_ROUTE as i}from"../../constants.js";import{withPathPrefix as a}from"../../../../../../shared/path-prefix.js";import{isMcpContentProtected as o,isMcpHidden as s,resolveMcpAccess as c}from"../config-gate.js";import{notFoundResponse as l}from"../../../../../../server/plugin-context.js";import{publicOrigin as u}from"../../../../utils/request-origin.js";import{CORS_ANY_ORIGIN as d,SUPPORTED_MCP_GRANT_TYPES as f,SUPPORTED_MCP_SCOPES as p}from"./constants.js";import"../auth.js";function m(e){return!s(e.config)&&o(c(e.config))}function h(t,n){if(!m(n))return l();let i=u(n.request);return t.json({resource:`${i}${a(r)}`,authorization_servers:[i],bearer_methods_supported:[`header`],resource_documentation:`${i}${a(e)}`,scopes_supported:[...p],bearer_token_types_supported:[`Bearer`]},200,{...d})}function g(e,r){if(!m(r))return l();let o=u(r.request);return e.json({issuer:o,authorization_endpoint:`${o}${a(t)}`,token_endpoint:`${o}${a(i)}`,scopes_supported:[...p],registration_endpoint:`${o}${a(n)}`,response_types_supported:[`code`],grant_types_supported:[...f],subject_types_supported:[`public`],id_token_signing_alg_values_supported:[`RS256`],code_challenge_methods_supported:[`S256`],token_endpoint_auth_methods_supported:[`none`],client_id_metadata_document_supported:!0},200,{...d})}export{g as oauthAuthorizationServer,h as oauthProtectedResource};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isMcpHidden as e}from"../config-gate.js";import{MCP_ACCESS_TOKEN_USE as t}from"../../../../../../server/auth/constants.js";import{
|
|
1
|
+
import{isMcpHidden as e}from"../config-gate.js";import{MCP_ACCESS_TOKEN_USE as t}from"../../../../../../server/auth/constants.js";import{getSessionIssuer as n}from"../../../../../../server/auth/middleware.js";import{notFoundResponse as r}from"../../../../../../server/plugin-context.js";import{MCP_ACCESS_TOKEN_TTL_SEC as i,SUPPORTED_MCP_GRANT_TYPES as a,SUPPORTED_MCP_SCOPES as o,TOKEN_RESPONSE_HEADERS as s}from"./constants.js";import{refuseMcpOAuth as c,withMcpFailureReporting as l}from"./error-reporting.js";import{signMcpArtifact as u,verifyMcpArtifact as d,verifyPkce as f}from"./tokens.js";import{redeemAuthorizationCode as p,redeemRefreshToken as m}from"./store.js";async function h(e,n,r,a){e.set(`realmCacheControlOwned`,!0);let l=Math.floor(Date.now()/1e3);if(l>=a.sessionExp)return c(e,n,`invalid_grant`,`Session has expired`);let d=Math.min(i,a.sessionExp-l),[f,p]=await Promise.all([r.mint({...a.claims,tokenUse:t},l+d),u({type:`mcp_refresh_token`,sessionId:a.sessionId,clientId:a.clientId,claims:a.claims,sessionExp:a.sessionExp},r.artifactSecret,a.sessionExp)]);return e.json({access_token:f,token_type:`Bearer`,expires_in:d,refresh_token:p,scope:o.join(` `)},200,{...s})}const g=l(_,e=>e.json({error:`server_error`,error_description:`The server could not complete the request`},500,{...s}));async function _(t,i){if(e(i.config))return r();let o=n(t);if(!o)return r();let s;try{s=await t.req.formData()}catch{return c(t,i,`invalid_request`,`Expected an application/x-www-form-urlencoded body`)}let l=s.get(`grant_type`);return typeof l!=`string`||!a.includes(l)?c(t,i,`invalid_request`,`Invalid grant type`):l===`refresh_token`?y(t,i,o,s):v(t,i,o,s)}async function v(e,t,n,r){let i=r.get(`code`);if(typeof i!=`string`||i===``)return c(e,t,`invalid_request`,`Missing authorization code`);let a;try{a=await d(i,n.artifactSecret,`mcp_auth_code`),e.set(`realmMcpSessionId`,a.sessionId)}catch{return c(e,t,`invalid_grant`,`Invalid authorization code`,`MCP token exchange failed`)}let o=r.get(`redirect_uri`);if(typeof o!=`string`||o!==a.redirectUri)return c(e,t,`invalid_grant`,`redirect_uri mismatch`);let s=r.get(`client_id`);if(typeof s!=`string`||s!==a.clientId)return c(e,t,`invalid_grant`,`Client mismatch`);let l=r.get(`code_verifier`);return typeof l!=`string`||l===``?c(e,t,`invalid_grant`,`code_verifier required`):f(a.codeChallenge,a.codeChallengeMethod,l)?await p(t.kv,i,a.exp)?h(e,t,n,{sessionId:a.sessionId,clientId:a.clientId,claims:a.claims,sessionExp:a.sessionExp}):c(e,t,`invalid_grant`,`Authorization code already used`):c(e,t,`invalid_grant`,`code_verifier mismatch`)}async function y(e,t,n,r){let i=r.get(`refresh_token`);if(typeof i!=`string`||i===``)return c(e,t,`invalid_request`,`refresh_token is required`);let a;try{a=await d(i,n.artifactSecret,`mcp_refresh_token`),e.set(`realmMcpSessionId`,a.sessionId)}catch{return c(e,t,`invalid_grant`,`Invalid refresh token`,`MCP refresh token rejected`)}let o=r.get(`client_id`);return typeof o!=`string`||o!==a.clientId?c(e,t,`invalid_grant`,`Client mismatch`):await m(t.kv,i,a.exp)?h(e,t,n,{sessionId:a.sessionId,clientId:a.clientId,claims:a.claims,sessionExp:a.sessionExp}):c(e,t,`invalid_grant`,`Refresh token already used`,`MCP refresh rejected: the refresh token was already used`)}export{g as mcpToken};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{SUPPORTED_CODE_CHALLENGE_METHODS as e}from"./constants.js";import{createHash as t,timingSafeEqual as n}from"node:crypto";import{
|
|
1
|
+
import{SUPPORTED_CODE_CHALLENGE_METHODS as e}from"./constants.js";import{createHash as t,timingSafeEqual as n}from"node:crypto";import{ulid as r}from"ulid";import{sign as i,verify as a}from"hono/jwt";const o=`HS256`;async function s(e,t,n){let a=Math.floor(Date.now()/1e3);return i({...e,jti:r(),iat:a,exp:n},t,o)}async function c(e,t,n){let r=await a(e,t,o);if(r.type!==n)throw Error(`Expected a ${n} token.`);return r}function l(e,r,i){if(!e||!u(r))return!1;let a=Buffer.from(t(`sha256`).update(i).digest(`base64url`)),o=Buffer.from(e);return a.length===o.length&&n(a,o)}function u(t){return e.includes(t??``)}function d(e){return t(`sha256`).update(e).digest(`base64url`)}function f({viewer:e,claims:t}){return{sub:e.sub,email:e.email,name:e.name,picture:e.picture,teams:[...e.teams],idpId:t.idpId}}export{u as isSupportedCodeChallengeMethod,f as sessionClaimsFromSession,d as sha256Base64Url,s as signMcpArtifact,c as verifyMcpArtifact,l as verifyPkce};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{MCP_ROUTE as e}from"../constants.js";import{withPathPrefix as t}from"../../../../../shared/path-prefix.js";import{ANONYMOUS_VIEWER as n}from"../../../../../shared/types/auth.js";import{isMcpContentProtected as r,isMcpHidden as i,resolveMcpAccess as a}from"./config-gate.js";import{
|
|
1
|
+
import{MCP_ROUTE as e}from"../constants.js";import{withPathPrefix as t}from"../../../../../shared/path-prefix.js";import{ANONYMOUS_VIEWER as n}from"../../../../../shared/types/auth.js";import{isMcpContentProtected as r,isMcpHidden as i,resolveMcpAccess as a}from"./config-gate.js";import{notFoundResponse as o}from"../../../../../server/plugin-context.js";import{publicBaseUrl as s,publicOrigin as c}from"../../../utils/request-origin.js";import{formatError as l}from"./tool-errors.js";import{CORS_ANY_ORIGIN as u,MCP_AUTH_SCHEMES as d}from"./oauth/constants.js";import"./auth.js";import{EXECUTE_DEADLINE_MS as f}from"./codemode/constants.js";import{sendMcpServerCardServed as p}from"./mcp-telemetry.js";import{applyMcpRateLimit as m}from"./rate-limit.js";import{createServedMcpRequestHandler as h}from"./handler.js";import{docsServerInfo as g}from"./server-info.js";import{CLIENT_CAPABILITIES_META_KEY as _,CLIENT_INFO_META_KEY as v,LATEST_PROTOCOL_VERSION as y,PROTOCOL_VERSION_META_KEY as b}from"@modelcontextprotocol/server";const x=`2026-07-28`,S=[`dynamic`],C={capabilities:{},tools:S};async function w(e,t,n){let r=await e(new Request(t,{method:`POST`,headers:{"content-type":`application/json`,accept:`application/json, text/event-stream`,"mcp-protocol-version":x,"mcp-method":n},body:JSON.stringify({jsonrpc:`2.0`,id:1,method:n,params:{_meta:{[b]:x,[v]:{name:`server-card`,version:`1.0`},[_]:{}}}})}));if(r.ok)return(await r.json()).result}function T(e,t){e.logger?.warn(`MCP server card lists dynamic tools: ${l(t)}`)}async function E(r,i){let a=await r.withViewer(n),o=await h(a,{isProtected:i},Date.now()+f,{onError:e=>T(r,e)}),s=new URL(t(e),c(r.request)).href,[l,u]=await Promise.all([w(o,s,`server/discover`),i?void 0:w(o,s,`tools/list`)]);if(!l)return;if(i)return{capabilities:l.capabilities,tools:S};if(!u)return;let d=u.tools.map(({name:e,title:t,description:n,inputSchema:r,annotations:i,_meta:a})=>({name:e,title:t,description:n,inputSchema:r,annotations:i,_meta:a}));return{capabilities:l.capabilities,instructions:l.instructions,tools:d.length>0?d:S}}async function D(n,c){if(i(c.config))return o();n.set(`realmCacheControlOwned`,!0);let l=await m({kv:c.kv,ip:c.request.ip,bucket:`card`,headers:u,logger:c.logger});if(l)return l;let f=g(c.config,c.request),h=r(a(c.config)),_=await E(c,h).catch(e=>{T(c,e)}),{capabilities:v,instructions:b,tools:x}=_??C;return await p({logger:c.logger}),n.json({$schema:`https://static.modelcontextprotocol.io/schemas/mcp-server-card/v1.json`,version:`1.0`,protocolVersion:y,serverInfo:{...f,title:f.name},description:f.description,documentationUrl:s(c.config,c.request),transport:{type:`streamable-http`,endpoint:t(e)},capabilities:v,authentication:h?{required:!0,schemes:[...d]}:void 0,instructions:b,tools:x},200,{...u,"Cache-Control":_?`public, max-age=3600`:`no-store`})}export{D as mcpServerCard};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{withPathPrefix as e}from"../../../../../shared/path-prefix.js";import{skillMarkdownPath as t}from"../../../utils/skill-paths.js";import{SKILL_ENTITY_TYPE as n}from"../../../types/skill-entity.js";import{
|
|
1
|
+
import{withPathPrefix as e}from"../../../../../shared/path-prefix.js";import{skillMarkdownPath as t}from"../../../utils/skill-paths.js";import{SKILL_ENTITY_TYPE as n}from"../../../types/skill-entity.js";import{isEntityScopeVisible as r}from"../../../../../shared/rbac/entity-scope.js";import{publicOrigin as i}from"../../../utils/request-origin.js";async function a(a){if(a.config.skills?.hide===!0)return[];let o=await a.entities.list({type:n}),s=i(a.request),c=e=>r(e,a.request.teams,e=>a.logger?.warn(e));return o.flatMap(n=>{let{slug:r,title:i,description:o}=n.metadata??{};return typeof r!=`string`||!c(n)?[]:[{slug:r,title:i??r,description:o??``,uri:`${s}${e(t(r))}`,read:async()=>(await a.entities.load(n.key)).content}]})}export{a as loadSkillResources};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { REDOCLY_TEAMS_RBAC } from '@redocly/config';
|
|
2
2
|
import type { NAV_ITEM_RBAC, RbacScope } from '../../../../shared/rbac/types.js';
|
|
3
|
-
import type { Logger } from '../../../../shared/logger.js';
|
|
4
3
|
import type { SidebarItemType } from '../../../../shared/types/sidebar.js';
|
|
5
4
|
import type { ProblemDraft } from '../../../problems/types.js';
|
|
6
5
|
import { type LinkRefDraft } from '../../../link-checker/classify.js';
|
|
7
6
|
import type { RouteIndex } from '../../utils/route-index.js';
|
|
7
|
+
import { type VersionGroups } from '../../../versions/version-groups.js';
|
|
8
8
|
export type SidebarBadge = {
|
|
9
9
|
name: string;
|
|
10
10
|
color?: string;
|
|
@@ -52,6 +52,15 @@ export type BundledSidebarNode = {
|
|
|
52
52
|
httpVerb?: string;
|
|
53
53
|
deprecated?: boolean;
|
|
54
54
|
badges?: SidebarBadge[];
|
|
55
|
+
/**
|
|
56
|
+
* A page that is an item of another route's sidebar, such as an API operation under its API
|
|
57
|
+
* route: that route's slug and the page's stored slug. The item gives the label and access, and
|
|
58
|
+
* a page the route does not list loses the link.
|
|
59
|
+
*/
|
|
60
|
+
subtreeItem?: {
|
|
61
|
+
route: string;
|
|
62
|
+
link: string;
|
|
63
|
+
};
|
|
55
64
|
/** Server-only RBAC scope. */
|
|
56
65
|
[REDOCLY_TEAMS_RBAC]?: Record<string, string>;
|
|
57
66
|
/** Server-only scope from the entry's `rbac`. */
|
|
@@ -89,6 +98,8 @@ type BundleSidebarOptions = {
|
|
|
89
98
|
sidebarByDirectory?: ReadonlyMap<string, string>;
|
|
90
99
|
/** Route slugs a `directory` entry leaves out. */
|
|
91
100
|
skipRoutes?: ReadonlySet<string>;
|
|
101
|
+
/** The site's version groups; a `page:` path under a default version's route links through them. */
|
|
102
|
+
versionGroups?: VersionGroups;
|
|
92
103
|
};
|
|
93
104
|
export declare function bundleSidebar(options: BundleSidebarOptions & {
|
|
94
105
|
source: string;
|
|
@@ -99,19 +110,8 @@ export declare function bundleSidebarEntries(options: BundleSidebarOptions & {
|
|
|
99
110
|
}): Promise<BundleSidebarResult>;
|
|
100
111
|
/**
|
|
101
112
|
* Stamp `isDefaultVersion` and `versionLabel` on versioned leaves, from
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
* later. Reads go through tracked io, so a change re-runs this finalize.
|
|
105
|
-
* Mutates `nodes`.
|
|
113
|
+
* `versionGroups`. Links keep their stored form here; `resolveSidebarNodes`
|
|
114
|
+
* rewrites default-version links later. Mutates `nodes`.
|
|
106
115
|
*/
|
|
107
|
-
export declare function stampDefaultVersions(
|
|
108
|
-
io: {
|
|
109
|
-
exists: (path: string) => Promise<boolean>;
|
|
110
|
-
readFile: (path: string) => Promise<string>;
|
|
111
|
-
};
|
|
112
|
-
routes: RouteIndex;
|
|
113
|
-
nodes: BundledSidebarNode[];
|
|
114
|
-
versionedDirectories: readonly string[];
|
|
115
|
-
logger?: Logger;
|
|
116
|
-
}): Promise<void>;
|
|
116
|
+
export declare function stampDefaultVersions(nodes: BundledSidebarNode[], versionGroups: VersionGroups): void;
|
|
117
117
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{L10N_DIR as e}from"../../../../shared/constants/l10n/defaults.js";import{isObject as t}from"../../../../shared/utils/is-object.js";import"../../../../shared/utils/l10n.js";import{resolveContentPath as n}from"../../../../shared/utils/resolve-content-path.js";import{isLocalImagePath as r}from"../assets/extensions.js";import{splitUrlSuffix as i}from"../../../../shared/utils/routes/split-url-suffix.js";import{toNavItemRbacAnnotation as a}from"../../../../shared/rbac/filter.js";import{resolvePageTarget as o}from"../../../../shared/utils/routes/resolve-page-target.js";import{collectVersionGroups as s,findVersionedDirectories as c}from"../../../versions/version-groups.js";import{joinSrcSet as l,parseSrcSet as u}from"../assets/srcset.js";import{classifyLinkTarget as d}from"../../../link-checker/classify.js";import{posix as f}from"node:path";import p from"js-yaml";function m(e){return typeof e.tab==`string`}function h(e,t,n){e.report?.({code:t,message:n,location:{filePath:e.file.path}})}function g(e,r){let i=p.load(e);if(!Array.isArray(i))return[];let a=[],o=e=>{if(t(e)){if(typeof e.$ref==`string`){let t=n(e.$ref,r);t!==null&&a.push(t)}if(Array.isArray(e.items))for(let t of e.items)o(t);if(m(e)&&Array.isArray(e.menu))for(let t of e.menu)o(t)}};for(let e of i)o(e);return a}async function _(e){let t=p.load(e.source);if(!Array.isArray(t))return[];let n=[];return await v({entries:t,ownerFilePath:e.filePath,currentFilePath:e.filePath,readFile:e.readFile,visitedRefs:/* @__PURE__ */ new Set([e.filePath]),refs:n}),n}async function v(e){let{ownerFilePath:t,currentFilePath:r,readFile:i,refs:a}=e;for(let o of e.entries){let s=K(o);if(s===void 0)continue;if(typeof s.$ref==`string`){let o=n(s.$ref,r);if(o===null||i===void 0||e.visitedRefs.has(o))continue;let c;try{c=await i(o)}catch{continue}let l=p.load(c);if(!Array.isArray(l))continue;let u=new Set(e.visitedRefs);u.add(o),await v({entries:l,ownerFilePath:t,currentFilePath:o,readFile:i,visitedRefs:u,refs:a});continue}let c=typeof s.page==`string`?s.page:s.href;typeof c==`string`&&y(a,c,r,t),Array.isArray(s.items)&&await v({...e,entries:s.items}),m(s)&&Array.isArray(s.menu)&&await v({...e,entries:s.menu})}}function y(e,t,n,r){let i=d(t,n);i!==null&&e.push({kind:`link`,raw:t,...i,...n===r?{}:{filePath:n}})}async function b(e){let t=p.load(e.source);if(!Array.isArray(t))throw Error(`Sidebar "${e.file.path}" must be a YAML sequence at the top level.`);return x({...e,entries:t})}async function x(e){let n=e.entries,r=n.filter(e=>t(e)&&m(e));if(r.length>0&&r.length!==n.length)throw Error(`Sidebar "${e.file.path}": when a sidebar uses navigation tabs, every top-level entry must be a tab (found ${n.length-r.length} other entries).`);let i={file:e.file,routes:e.routes,assignedRouteSlugs:/* @__PURE__ */ new Set,versionedDirectories:/* @__PURE__ */ new Set,report:e.report,readFile:e.readFile,skipRoutes:e.skipRoutes,exists:e.exists,sidebarByDirectory:e.sidebarByDirectory??/* @__PURE__ */ new Map,visitedRefs:/* @__PURE__ */ new Set([e.file.path])},a=[];if(r.length>0){for(let[e,t]of r.entries())a.push(await P({...i,entry:t,tabIndex:e}));L({file:e.file,tabs:a,routes:e.routes})}else for(let e of n)a.push(...await S({...i,entry:e}));return{assignedRouteSlugs:[...i.assignedRouteSlugs].sort(),versionedDirectories:[...i.versionedDirectories].sort(),nodes:a}}async function S(e){let n=await C(e),r=t(e.entry)?e.entry.rbac:void 0;if(r===void 0)return n;let i=I({...e,rbac:r});for(let e of n)Object.assign(e,i);return n}async function C(e){let t=K(e.entry);if(t===void 0)return h(e,`sidebar/invalid-entry`,`Sidebar entry ${G(e.entry)} is not a page reference or a group.`),[];if(m(t))throw Error(`Sidebar "${e.file.path}": "tab" is only allowed at the top level (found nested tab "${t.tab}").`);if(t.menu!==void 0)throw Error(`Sidebar "${e.file.path}": "menu" is only allowed directly on a tab.`);if(typeof t.$ref==`string`)return D({...e,ref:t.$ref});if(typeof t.directory==`string`&&E(t)&&t.items===void 0)return C({...e,entry:{...t,directory:void 0,items:[{directory:t.directory,flatten:t.flatten}]}});if(typeof t.directory==`string`){let r=n(t.directory,e.file.path);if(r===null)return h(e,`sidebar/invalid-entry`,`Sidebar directory "${t.directory}" is outside the content root.`),[];let i=e.routes.inDirectory(r);i.length===0&&h(e,`sidebar/missing-target`,`Sidebar directory "${t.directory}" has no pages.`);let a=await z({...e,directoryPath:r,flatten:t.flatten===!0,pages:i.filter(t=>!e.skipRoutes?.has(t.slug))}),o=J(t.group)??J(t.label);return o===void 0?a:[{type:`group`,...X(t,e),menuStyle:Z(t),items:a.length>0?a:void 0,label:o,labelTranslationKey:T(t)}]}if(typeof t.separator==`string`)return[{type:`separator`,...X(t,e),label:t.separator,labelTranslationKey:J(t.separatorTranslationKey)}];let r=await V(t,e),i=r.route;if(i)for(let t of c([i]))e.versionedDirectories.add(t);let a;if(Array.isArray(t.items)){a=[];for(let n of t.items)a.push(...await S({...e,entry:n}))}let o=J(t.group)??J(t.label)??(i===void 0?J(t.href):void 0)??r.anchor,s=E(t);return[{type:w(t,i,r.linksConnectedHeading===!0),...X(t,e),menuStyle:s?Z(t):void 0,external:t.external===!0||void 0,languageInsensitive:r.languageInsensitive?!0:void 0,items:a&&a.length>0?a:void 0,label:o,labelTranslationKey:T(t),link:r.link,isGroup:s?!0:void 0,version:J(t.version)??i?.version??void 0,versionGroup:i?.versionGroup??void 0}]}function w(e,t,n){if(E(e)&&!n)return`group`;if(t!==void 0||e.href||e.label)return`link`}function T(e){return J(E(e)?e.groupTranslationKey:e.labelTranslationKey)}function E(e){return J(e.group)!==void 0}async function D(e){let{ref:t}=e,r=n(t,e.file.path);if(r===null)return h(e,`sidebar/invalid-entry`,`Sidebar $ref "${t}" is outside the content root.`),[];if(e.readFile===void 0)return h(e,`sidebar/invalid-entry`,`Sidebar $ref "${t}" is not supported here.`),[];if(e.visitedRefs.has(r))return h(e,`sidebar/invalid-entry`,`Sidebar $ref "${r}" includes itself.`),[];let i;try{i=await e.readFile(r)}catch{return h(e,`sidebar/missing-target`,`Sidebar $ref "${r}" could not be read.`),[]}let a=p.load(i);return Array.isArray(a)?O(e,r,a):(h(e,`sidebar/invalid-entry`,`Sidebar $ref "${r}" must be a YAML sequence.`),[])}async function O(e,t,n){let r=/* @__PURE__ */ new Set([...e.visitedRefs,t]),i=[];for(let a of n)i.push(...await S({...e,entry:a,file:{path:t},visitedRefs:r}));return i}async function k(e,t){if(e.readFile===void 0)return[];let n=p.load(await e.readFile(t));return Array.isArray(n)?O({...e,assignedRouteSlugs:/* @__PURE__ */ new Set,report:void 0},t,n.map(A)):[]}function A(e){if(!t(e)||!m(e))return e;let{tab:n,menu:r,...i}=e;return{...i,group:n,items:i.items??r}}function j(e,t){return`${e}-${t.normalize(`NFKD`).replace(/[\u0300-\u036f]/g,``).toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|(?<!-)-+$/g,``)||`tab`}`}function M(e){return/* @__PURE__ */ Error(`Sidebar "${e.file.path}": tab "${e.label}" ${e.message}.`)}function N(e){let{file:t,entry:n}=e,r=n.tab,i=n.menu!==void 0;if(i&&n.items!==void 0)throw M({file:t,label:r,message:`cannot have both "menu" and "items"`});if(i&&n.page!==void 0)throw M({file:t,label:r,message:`has "menu" and cannot also have "page"`});if(!i&&n.page===void 0)throw M({file:t,label:r,message:`needs "page" or "menu"`});if(typeof n.page==`string`&&n.page.includes(`#`))throw M({file:t,label:r,message:`page must not contain a heading anchor`});if(i&&!Array.isArray(n.menu))throw M({file:t,label:r,message:`"menu" must be a list of entries`});if(i&&Array.isArray(n.menu)&&n.menu.length===0)throw M({file:t,label:r,message:`has an empty "menu"`});if(n.$ref!==void 0||n.directory!==void 0||n.group!==void 0||n.href!==void 0)throw M({file:t,label:r,message:`accepts only "page", "items", "menu" and "icon"; move "$ref"/"directory"/"group"/"href" into "items"`})}async function P(e){let{entry:t}=e,n=t.tab;N({file:e.file,entry:t});let r=j(e.tabIndex,n);if(t.menu!==void 0){let i=Array.isArray(t.menu)?t.menu:[],a=[];for(let[t,n]of i.entries()){let i=await F({...e,tabId:r,index:t,raw:n});i!==void 0&&a.push(i)}return{tab:!0,tabId:r,label:n,menu:a,...Q(t.icon,e),...I({...e,rbac:t.rbac})}}let[i]=await S({...e,entry:{page:t.page,label:n,items:t.items,rbac:t.rbac}}),a=i?.items??[];return{...i,tab:!0,tabId:r,...Q(t.icon,e),items:a}}async function F(e){let{file:t,entry:n,tabId:r,index:i,raw:a}=e,o=n.tab,s=K(a);if(s===void 0||typeof s.page!=`string`)throw Error(`Sidebar "${t.path}": menu entry ${i+1} of tab "${o}" needs "page".`);if(s.page.includes(`#`))throw Error(`Sidebar "${t.path}": menu entry ${i+1} of tab "${o}" page must not contain a heading anchor.`);let c=`${r}/${i}`,[l]=await S({...e,entry:s});return l?.link===void 0?void 0:{...l,tabId:c,items:l.items??[]}}function I(e){return a(e.rbac,()=>h(e,`sidebar/invalid-entry`,`Sidebar entry has an invalid "rbac" value, so it is hidden.`))}function L(e){let t=/* @__PURE__ */ new Map,n=(n,r)=>{for(let i of r){let r=t.get(i);if(r!==void 0&&r.tabId!==n.tabId)throw Error(`Sidebar "${e.file.path}": route "${i}" is claimed by two navigation tabs, "${r.label}" and "${n.label}". A route can belong to one tab only.`);t.set(i,n)}};for(let t of e.tabs){if(t.menu!==void 0){for(let r of t.menu)r.tabId!==void 0&&n({tabId:r.tabId,label:`${t.label} > ${r.label??r.link}`},R({routes:e.routes,link:r.link,items:r.items}));continue}t.tabId!==void 0&&n({tabId:t.tabId,label:t.label??t.link??``},R({routes:e.routes,link:t.link,items:t.items}))}}function R(e){let t=[],n=n=>{if(n.link===void 0||n.languageInsensitive===!0)return;let r=e.routes.bySlug(n.link);r!==void 0&&r.originFilePath!==null&&t.push(r.slug)};n({link:e.link});let r=e=>{if(e!==void 0)for(let t of e)n(t),r(t.items)};return r(e.items),t}async function z(t){let n=t.directoryPath===``?``:`${t.directoryPath}/`,r=[],i=/* @__PURE__ */ new Map,a=/* @__PURE__ */ new Set,o=t.directoryPath.startsWith(`${e}/`),s=t.pages.filter(e=>o||e.locale===``).map(e=>({route:e,relativePath:e.originFilePath?.startsWith(n)?e.originFilePath.slice(n.length):null})).sort((e,t)=>B(e.relativePath??e.route.slug,t.relativePath??t.route.slug));for(let e of s){let n=e.relativePath?.split(`/`).slice(0,-1)??[],r=c(n);if(r!==void 0){if(!a.has(r.path)){a.add(r.path);let e=await k(t,r.path);e.length>0&&u(l(n,r.depth)).push(...e)}continue}U(e.route,t),e.route.version&&t.versionedDirectories.add(t.directoryPath),u(l(n,n.length)).push({type:`link`,link:e.route.slug,version:e.route.version??void 0,versionGroup:e.route.versionGroup??void 0})}return r;function c(e){for(let n=0;n<=e.length;n++){let r=f.join(t.directoryPath,...e.slice(0,n)),i=t.sidebarByDirectory.get(r);if(i!==void 0&&!t.visitedRefs.has(i))return{depth:n,path:i}}}function l(e,n){return t.flatten?[]:e.slice(0,n).filter(e=>!e.startsWith(`@`))}function u(e){let t=r,n=``;for(let r of e){n=n===``?r:`${n}/${r}`;let e=i.get(n);if(e){t=e;continue}let a=[];t.push({type:`group`,items:a,label:r}),i.set(n,a),t=a}return t}}function B(e,t){return e.startsWith(`index.`)?-1:t.startsWith(`index.`)?1:e.localeCompare(t,void 0,{numeric:!0})}async function V(e,t){if(typeof e.page==`string`){let{path:n,suffix:r,anchor:a}=i(e.page.trim()),o=await H(n,t);if(!o)return{};let s=e.disconnect!==!0;return s&&U(o,t),{link:`${o.slug}${r}`,anchor:a,linksConnectedHeading:s&&a!==void 0,route:o}}if(typeof e.href==`string`){let n=e.href;if(n.startsWith(`/`)){let e=t.routes.bySlug(n);return e?{link:e.slug,route:e}:{link:n,languageInsensitive:!0}}return{link:n,languageInsensitive:!0}}return{}}async function H(e,t){let r=o(e,t.file.path,t.routes);if(r.kind===`escaped`){h(t,`sidebar/invalid-entry`,`Sidebar page "${e}" is outside the content root.`);return}if(r.kind===`missing`){let r=n(e,t.file.path);r!==null&&await t.exists?.(r)&&h(t,`sidebar/missing-target`,`Sidebar page "${e}" is a file that makes no page.`);return}return r.value}function U(e,t){t.assignedRouteSlugs.add(e.slug)}async function W(e){if(e.versionedDirectories.length===0)return;let t=await s({io:e.io,routes:e.routes,versionedDirectories:e.versionedDirectories}),n=e=>{for(let r of e){if(r.version!==void 0&&r.versionGroup!==void 0){let e=t.get(r.versionGroup),n=e?.labels.get(r.version);n&&(r.versionLabel=n),e?.defaultVersion===r.version&&(r.isDefaultVersion=!0)}r.items&&n(r.items),r.menu&&n(r.menu)}};n(e.nodes)}function G(e){let t=JSON.stringify(e)??String(e);return t.length>80?`${t.slice(0,79)}…`:t}function K(e){return typeof e==`string`?e.trim()===``?void 0:{page:e}:t(e)?e:void 0}function q(e){if(!Array.isArray(e))return;let n=[];for(let r of e){if(!t(r))continue;let e=J(r.name),i=J(r.icon);(e!==void 0||i!==void 0)&&n.push({name:e??``,color:J(r.color),icon:i,position:r.position===`before`||r.position===`after`?r.position:void 0})}return n.length>0?n:void 0}function J(e){return typeof e==`string`&&e.trim()!==``?e:void 0}function Y(e,t){return t.find(t=>t===e)}function X(e,t){return{badges:q(e.badges),...Q(e.icon,t),expanded:e.expanded===!0?`true`:Y(e.expanded,[`always`]),selectFirstItemOnExpand:e.selectFirstItemOnExpand===!0||void 0,separatorLine:e.separatorLine===!0||void 0,linePosition:Y(e.linePosition,[`top`,`bottom`]),target:J(e.target),sublabel:J(e.sublabel)}}function Z(e){return Y(e.menuStyle,[`drilldown`,`drilldown-header`])}function Q(e,n){let r=t(e)?J(e.srcSet):void 0;if(r!==void 0){let e=u(r);if(e===null)return{srcSet:r};for(let t of e)t.src=$(t.src,n);return{srcSet:l(e)}}let i=J(e);return i===void 0?{}:{icon:$(i,n)}}function $(e,t){if(!r(e))return e;let i=n(e,t.file.path);return i===null?(h(t,`sidebar/invalid-entry`,`Sidebar icon "${e}" is outside the content root.`),e):`/${i}`}export{b as bundleSidebar,x as bundleSidebarEntries,_ as collectSidebarLinkRefs,g as collectSidebarRefTargets,W as stampDefaultVersions};
|
|
1
|
+
import{isObject as e}from"../../../../shared/utils/is-object.js";import{L10N_DIR as t}from"../../../../shared/constants/l10n/defaults.js";import{normalizeRouteSlug as n}from"../../../../shared/utils/routes/normalize-route-slug.js";import"../../../../shared/utils/l10n.js";import{resolveContentPath as r}from"../../../../shared/utils/resolve-content-path.js";import{computePathPrefixes as i}from"../../../../shared/utils/routes/compute-path-prefixes.js";import{isLocalImagePath as a}from"../assets/extensions.js";import{splitUrlSuffix as o}from"../../../../shared/utils/routes/split-url-suffix.js";import{toNavItemRbacAnnotation as s}from"../../../../shared/rbac/filter.js";import{resolvePageTarget as c}from"../../../../shared/utils/routes/resolve-page-target.js";import{findVersionedDirectories as l}from"../../../versions/version-groups.js";import{physicalVersionedSlug as u}from"../../utils/link-access.js";import{joinSrcSet as d,parseSrcSet as f}from"../assets/srcset.js";import{classifyLinkTarget as p}from"../../../link-checker/classify.js";import{posix as m}from"node:path";import h from"js-yaml";function g(e){return typeof e.tab==`string`}function _(e,t,n){e.report?.({code:t,message:n,location:{filePath:e.file.path}})}function v(t,n){let i=h.load(t);if(!Array.isArray(i))return[];let a=[],o=t=>{if(e(t)){if(typeof t.$ref==`string`){let e=r(t.$ref,n);e!==null&&a.push(e)}if(Array.isArray(t.items))for(let e of t.items)o(e);if(g(t)&&Array.isArray(t.menu))for(let e of t.menu)o(e)}};for(let e of i)o(e);return a}async function y(e){let t=h.load(e.source);if(!Array.isArray(t))return[];let n=[];return await b({entries:t,ownerFilePath:e.filePath,currentFilePath:e.filePath,readFile:e.readFile,visitedRefs:/* @__PURE__ */ new Set([e.filePath]),refs:n}),n}async function b(e){let{ownerFilePath:t,currentFilePath:n,readFile:i,refs:a}=e;for(let o of e.entries){let s=K(o);if(s===void 0)continue;if(typeof s.$ref==`string`){let o=r(s.$ref,n);if(o===null||i===void 0||e.visitedRefs.has(o))continue;let c;try{c=await i(o)}catch{continue}let l=h.load(c);if(!Array.isArray(l))continue;let u=new Set(e.visitedRefs);u.add(o),await b({entries:l,ownerFilePath:t,currentFilePath:o,readFile:i,visitedRefs:u,refs:a});continue}let c=typeof s.page==`string`?s.page:s.href;typeof c==`string`&&x(a,c,n,t),Array.isArray(s.items)&&await b({...e,entries:s.items}),g(s)&&Array.isArray(s.menu)&&await b({...e,entries:s.menu})}}function x(e,t,n,r){let i=p(t,n);i!==null&&e.push({kind:`link`,raw:t,...i,...n===r?{}:{filePath:n}})}async function S(e){let t=h.load(e.source);if(!Array.isArray(t))throw Error(`Sidebar "${e.file.path}" must be a YAML sequence at the top level.`);return C({...e,entries:t})}async function C(t){let n=t.entries,r=n.filter(t=>e(t)&&g(t));if(r.length>0&&r.length!==n.length)throw Error(`Sidebar "${t.file.path}": when a sidebar uses navigation tabs, every top-level entry must be a tab (found ${n.length-r.length} other entries).`);let i={file:t.file,routes:t.routes,versionGroups:t.versionGroups??/* @__PURE__ */ new Map,assignedRouteSlugs:/* @__PURE__ */ new Set,versionedDirectories:/* @__PURE__ */ new Set,report:t.report,readFile:t.readFile,skipRoutes:t.skipRoutes,exists:t.exists,sidebarByDirectory:t.sidebarByDirectory??/* @__PURE__ */ new Map,visitedRefs:/* @__PURE__ */ new Set([t.file.path])},a=[];if(r.length>0){for(let[e,t]of r.entries())a.push(await N({...i,entry:t,tabIndex:e}));I({file:t.file,tabs:a,routes:t.routes})}else for(let e of n)a.push(...await w({...i,entry:e}));return{assignedRouteSlugs:[...i.assignedRouteSlugs].sort(),versionedDirectories:[...i.versionedDirectories].sort(),nodes:a}}async function w(t){let n=await T(t),r=e(t.entry)?t.entry.rbac:void 0;if(r===void 0)return n;let i=F({...t,rbac:r});for(let e of n)Object.assign(e,i);return n}async function T(e){let t=K(e.entry);if(t===void 0)return _(e,`sidebar/invalid-entry`,`Sidebar entry ${G(e.entry)} is not a page reference or a group.`),[];if(g(t))throw Error(`Sidebar "${e.file.path}": "tab" is only allowed at the top level (found nested tab "${t.tab}").`);if(t.menu!==void 0)throw Error(`Sidebar "${e.file.path}": "menu" is only allowed directly on a tab.`);if(typeof t.$ref==`string`)return k({...e,ref:t.$ref});if(typeof t.directory==`string`&&O(t)&&t.items===void 0)return T({...e,entry:{...t,directory:void 0,items:[{directory:t.directory,flatten:t.flatten}]}});if(typeof t.directory==`string`){let n=r(t.directory,e.file.path);if(n===null)return _(e,`sidebar/invalid-entry`,`Sidebar directory "${t.directory}" is outside the content root.`),[];let i=e.routes.inDirectory(n);i.length===0&&_(e,`sidebar/missing-target`,`Sidebar directory "${t.directory}" has no pages.`);let a=await R({...e,directoryPath:n,flatten:t.flatten===!0,pages:i.filter(t=>!e.skipRoutes?.has(t.slug))}),o=J(t.group)??J(t.label);return o===void 0?a:[{type:`group`,...X(t,e),menuStyle:Z(t),items:a.length>0?a:void 0,label:o,labelTranslationKey:D(t)}]}if(typeof t.separator==`string`)return[{type:`separator`,...X(t,e),label:t.separator,labelTranslationKey:J(t.separatorTranslationKey)}];let n=await B(t,e),i=n.route;if(i)for(let t of l([i]))e.versionedDirectories.add(t);let a;if(Array.isArray(t.items)){a=[];for(let n of t.items)a.push(...await w({...e,entry:n}))}let o=J(t.group)??J(t.label)??(i===void 0?J(t.href):void 0)??n.anchor,s=O(t);return[{type:E(t,!!n.link,n.linksConnectedHeading===!0),...X(t,e),menuStyle:s?Z(t):void 0,external:t.external===!0||void 0,languageInsensitive:n.languageInsensitive?!0:void 0,items:a&&a.length>0?a:void 0,label:o,labelTranslationKey:D(t),link:n.link,isGroup:s?!0:void 0,version:J(t.version)??i?.version??void 0,versionGroup:i?.versionGroup??void 0,subtreeItem:n.subtreeItem}]}function E(e,t,n){if(O(e)&&!n)return`group`;if(t||e.label)return`link`}function D(e){return J(O(e)?e.groupTranslationKey:e.labelTranslationKey)}function O(e){return J(e.group)!==void 0}async function k(e){let{ref:t}=e,n=r(t,e.file.path);if(n===null)return _(e,`sidebar/invalid-entry`,`Sidebar $ref "${t}" is outside the content root.`),[];if(e.readFile===void 0)return _(e,`sidebar/invalid-entry`,`Sidebar $ref "${t}" is not supported here.`),[];if(e.visitedRefs.has(n))return _(e,`sidebar/invalid-entry`,`Sidebar $ref "${n}" includes itself.`),[];let i;try{i=await e.readFile(n)}catch{return _(e,`sidebar/missing-target`,`Sidebar $ref "${n}" could not be read.`),[]}let a=h.load(i);return Array.isArray(a)?A(e,n,a):(_(e,`sidebar/invalid-entry`,`Sidebar $ref "${n}" must be a YAML sequence.`),[])}async function A(e,t,n){let r=/* @__PURE__ */ new Set([...e.visitedRefs,t]),i=[];for(let a of n)i.push(...await w({...e,entry:a,file:{path:t},visitedRefs:r}));return i}async function ee(e,t){if(e.readFile===void 0)return[];let n=h.load(await e.readFile(t));return Array.isArray(n)?A({...e,assignedRouteSlugs:/* @__PURE__ */ new Set,report:void 0},t,n.map(te)):[]}function te(t){if(!e(t)||!g(t))return t;let{tab:n,menu:r,...i}=t;return{...i,group:n,items:i.items??r}}function ne(e,t){return`${e}-${t.normalize(`NFKD`).replace(/[\u0300-\u036f]/g,``).toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|(?<!-)-+$/g,``)||`tab`}`}function j(e){return/* @__PURE__ */ Error(`Sidebar "${e.file.path}": tab "${e.label}" ${e.message}.`)}function M(e){let{file:t,entry:n}=e,r=n.tab,i=n.menu!==void 0;if(i&&n.items!==void 0)throw j({file:t,label:r,message:`cannot have both "menu" and "items"`});if(i&&n.page!==void 0)throw j({file:t,label:r,message:`has "menu" and cannot also have "page"`});if(!i&&n.page===void 0)throw j({file:t,label:r,message:`needs "page" or "menu"`});if(typeof n.page==`string`&&n.page.includes(`#`))throw j({file:t,label:r,message:`page must not contain a heading anchor`});if(i&&!Array.isArray(n.menu))throw j({file:t,label:r,message:`"menu" must be a list of entries`});if(i&&Array.isArray(n.menu)&&n.menu.length===0)throw j({file:t,label:r,message:`has an empty "menu"`});if(n.$ref!==void 0||n.directory!==void 0||n.group!==void 0||n.href!==void 0)throw j({file:t,label:r,message:`accepts only "page", "items", "menu" and "icon"; move "$ref"/"directory"/"group"/"href" into "items"`})}async function N(e){let{entry:t}=e,n=t.tab;M({file:e.file,entry:t});let r=ne(e.tabIndex,n);if(t.menu!==void 0){let i=Array.isArray(t.menu)?t.menu:[],a=[];for(let[t,n]of i.entries()){let i=await P({...e,tabId:r,index:t,raw:n});i!==void 0&&a.push(i)}return{tab:!0,tabId:r,label:n,menu:a,...Q(t.icon,e),...F({...e,rbac:t.rbac})}}let[i]=await w({...e,entry:{page:t.page,label:n,items:t.items,rbac:t.rbac}}),a=i?.items??[];return{...i,tab:!0,tabId:r,...Q(t.icon,e),items:a}}async function P(e){let{file:t,entry:n,tabId:r,index:i,raw:a}=e,o=n.tab,s=K(a);if(s===void 0||typeof s.page!=`string`)throw Error(`Sidebar "${t.path}": menu entry ${i+1} of tab "${o}" needs "page".`);if(s.page.includes(`#`))throw Error(`Sidebar "${t.path}": menu entry ${i+1} of tab "${o}" page must not contain a heading anchor.`);let c=`${r}/${i}`,[l]=await w({...e,entry:s});return l?.link===void 0?void 0:{...l,tabId:c,items:l.items??[]}}function F(e){return s(e.rbac,()=>_(e,`sidebar/invalid-entry`,`Sidebar entry has an invalid "rbac" value, so it is hidden.`))}function I(e){let t=/* @__PURE__ */ new Map,n=(n,r)=>{for(let i of r){let r=t.get(i);if(r!==void 0&&r.tabId!==n.tabId)throw Error(`Sidebar "${e.file.path}": route "${i}" is claimed by two navigation tabs, "${r.label}" and "${n.label}". A route can belong to one tab only.`);t.set(i,n)}};for(let t of e.tabs){if(t.menu!==void 0){for(let r of t.menu)r.tabId!==void 0&&n({tabId:r.tabId,label:`${t.label} > ${r.label??r.link}`},L({routes:e.routes,link:r.link,items:r.items}));continue}t.tabId!==void 0&&n({tabId:t.tabId,label:t.label??t.link??``},L({routes:e.routes,link:t.link,items:t.items}))}}function L(e){let t=[],n=n=>{if(n.link===void 0||n.languageInsensitive===!0)return;let r=e.routes.bySlug(n.link);r!==void 0&&r.originFilePath!==null&&t.push(r.slug)};n({link:e.link});let r=e=>{if(e!==void 0)for(let t of e)n(t),r(t.items)};return r(e.items),t}async function R(e){let n=e.directoryPath===``?``:`${e.directoryPath}/`,r=[],i=/* @__PURE__ */ new Map,a=/* @__PURE__ */ new Set,o=e.directoryPath.startsWith(`${t}/`),s=e.pages.filter(e=>o||e.locale===``).map(e=>({route:e,relativePath:e.originFilePath?.startsWith(n)?e.originFilePath.slice(n.length):null})).sort((e,t)=>z(e.relativePath??e.route.slug,t.relativePath??t.route.slug));for(let t of s){let n=t.relativePath?.split(`/`).slice(0,-1)??[],r=c(n);if(r!==void 0){if(!a.has(r.path)){a.add(r.path);let t=await ee(e,r.path);t.length>0&&u(l(n,r.depth)).push(...t)}continue}U(t.route,e),t.route.version&&e.versionedDirectories.add(e.directoryPath),u(l(n,n.length)).push({type:`link`,link:t.route.slug,version:t.route.version??void 0,versionGroup:t.route.versionGroup??void 0})}return r;function c(t){for(let n=0;n<=t.length;n++){let r=m.join(e.directoryPath,...t.slice(0,n)),i=e.sidebarByDirectory.get(r);if(i!==void 0&&!e.visitedRefs.has(i))return{depth:n,path:i}}}function l(t,n){return e.flatten?[]:t.slice(0,n).filter(e=>!e.startsWith(`@`))}function u(e){let t=r,n=``;for(let r of e){n=n===``?r:`${n}/${r}`;let e=i.get(n);if(e){t=e;continue}let a=[];t.push({type:`group`,items:a,label:r}),i.set(n,a),t=a}return t}}function z(e,t){return e.startsWith(`index.`)?-1:t.startsWith(`index.`)?1:e.localeCompare(t,void 0,{numeric:!0})}async function B(e,t){if(typeof e.page==`string`){let{path:r,suffix:i,anchor:a}=o(e.page.trim()),s=await V(r,t);if(!s){let e=H(r,t);return e===void 0?{}:{link:`${n(r)}${i}`,anchor:a,subtreeItem:e}}let c=e.disconnect!==!0;return c&&U(s,t),{link:`${s.slug}${i}`,anchor:a,linksConnectedHeading:c&&a!==void 0,route:s}}if(typeof e.href==`string`){let n=e.href;if(n.startsWith(`/`)){let e=t.routes.bySlug(n);return e?{link:e.slug,route:e}:{link:n,languageInsensitive:!0}}return{link:n,languageInsensitive:!0}}return{}}async function V(e,t){let n=c(e,t.file.path,t.routes);if(n.kind===`escaped`){_(t,`sidebar/invalid-entry`,`Sidebar page "${e}" is outside the content root.`);return}if(n.kind===`missing`){let n=r(e,t.file.path);n!==null&&await t.exists?.(n)&&_(t,`sidebar/missing-target`,`Sidebar page "${e}" is a file that makes no page.`);return}return n.value}function H(e,t){if(!e.startsWith(`/`))return;let r=n(e),a=[r,u(r,t.versionGroups)].find(e=>e!==null&&t.routes.getAccess(e)!==void 0);if(a!=null)for(let e of i(a).slice(0,-1).reverse()){let n=t.routes.bySlug(e);if(n?.sidebarSubtreeEntityKey)return{route:n.slug,link:a}}}function U(e,t){t.assignedRouteSlugs.add(e.slug)}function W(e,t){let n=e=>{for(let r of e){if(r.version!==void 0&&r.versionGroup!==void 0){let e=t.get(r.versionGroup),n=e?.labels.get(r.version);n&&(r.versionLabel=n),e?.defaultVersion===r.version&&(r.isDefaultVersion=!0)}r.items&&n(r.items),r.menu&&n(r.menu)}};n(e)}function G(e){let t=JSON.stringify(e)??String(e);return t.length>80?`${t.slice(0,79)}…`:t}function K(t){return typeof t==`string`?t.trim()===``?void 0:{page:t}:e(t)?t:void 0}function q(t){if(!Array.isArray(t))return;let n=[];for(let r of t){if(!e(r))continue;let t=J(r.name),i=J(r.icon);(t!==void 0||i!==void 0)&&n.push({name:t??``,color:J(r.color),icon:i,position:r.position===`before`||r.position===`after`?r.position:void 0})}return n.length>0?n:void 0}function J(e){return typeof e==`string`&&e.trim()!==``?e:void 0}function Y(e,t){return t.find(t=>t===e)}function X(e,t){return{badges:q(e.badges),...Q(e.icon,t),expanded:e.expanded===!0?`true`:Y(e.expanded,[`always`]),selectFirstItemOnExpand:e.selectFirstItemOnExpand===!0||void 0,separatorLine:e.separatorLine===!0||void 0,linePosition:Y(e.linePosition,[`top`,`bottom`]),target:J(e.target),sublabel:J(e.sublabel)}}function Z(e){return Y(e.menuStyle,[`drilldown`,`drilldown-header`])}function Q(t,n){let r=e(t)?J(t.srcSet):void 0;if(r!==void 0){let e=f(r);if(e===null)return{srcSet:r};for(let t of e)t.src=$(t.src,n);return{srcSet:d(e)}}let i=J(t);return i===void 0?{}:{icon:$(i,n)}}function $(e,t){if(!a(e))return e;let n=r(e,t.file.path);return n===null?(_(t,`sidebar/invalid-entry`,`Sidebar icon "${e}" is outside the content root.`),e):`/${n}`}export{S as bundleSidebar,C as bundleSidebarEntries,y as collectSidebarLinkRefs,v as collectSidebarRefTargets,W as stampDefaultVersions};
|
|
@@ -7,7 +7,7 @@ import { SIDEBAR_ROUTE_DEP_KEY } from '../../../../shared/constants/route-deps.j
|
|
|
7
7
|
export declare const SIDEBAR_PLUGIN_ID = "internal.sidebar";
|
|
8
8
|
export declare const SIDEBAR_AGGREGATOR_LOADER_ID: "internal.sidebar:aggregate";
|
|
9
9
|
export { SIDEBAR_ROUTE_DEP_KEY };
|
|
10
|
-
/**
|
|
10
|
+
/** `sidebars.yaml`, or a file name that ends in `.sidebars.yaml`, `_sidebars.yaml` or `-sidebars.yaml`. */
|
|
11
11
|
export declare const SIDEBAR_FILENAME_REGEX: RegExp;
|
|
12
12
|
/** A folder's own sidebar; a named `*sidebars.yaml` is not one. */
|
|
13
13
|
export declare const FOLDER_SIDEBAR_FILENAME_REGEX: RegExp;
|