@redocly/redoc-reef 0.141.0-next.13 → 0.141.0-next.15
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/CHANGELOG.md +43 -0
- package/dist/client/app/markdoc/custom-components/openapi/openapi-code-sample.d.ts +2 -1
- package/dist/client/app/markdoc/custom-components/openapi/openapi-code-sample.js +1 -1
- package/dist/client/app/markdoc/custom-components/openapi/openapi-example.d.ts +1 -1
- package/dist/client/app/markdoc/custom-components/openapi/openapi-example.js +1 -1
- package/dist/client/app/markdoc/custom-components/openapi/openapi-response-sample.d.ts +2 -1
- package/dist/client/app/markdoc/custom-components/openapi/openapi-response-sample.js +1 -1
- package/dist/client/app/markdoc/custom-components/openapi/replay-openapi.d.ts +2 -1
- package/dist/client/app/markdoc/custom-components/openapi/replay-openapi.js +1 -1
- package/dist/client/app/markdoc/hooks/use-store.d.ts +12 -0
- package/dist/client/app/markdoc/hooks/use-store.js +1 -1
- package/dist/client/runtime/loader.js +1 -1
- package/dist/constants/l10n/langs/ar.js +1 -1
- package/dist/constants/l10n/langs/de.js +1 -1
- package/dist/constants/l10n/langs/en.js +1 -1
- package/dist/constants/l10n/langs/es.js +1 -1
- package/dist/constants/l10n/langs/fr.js +1 -1
- package/dist/constants/l10n/langs/hi.js +1 -1
- package/dist/constants/l10n/langs/it.js +1 -1
- package/dist/constants/l10n/langs/ja.js +1 -1
- package/dist/constants/l10n/langs/ko.js +1 -1
- package/dist/constants/l10n/langs/pl.js +1 -1
- package/dist/constants/l10n/langs/pt-BR.js +1 -1
- package/dist/constants/l10n/langs/pt.js +1 -1
- package/dist/constants/l10n/langs/ru.js +1 -1
- package/dist/constants/l10n/langs/uk.js +1 -1
- package/dist/constants/l10n/langs/zh.js +1 -1
- package/dist/markdoc/helpers/get-resolved-sample-code-block.js +4 -4
- package/dist/markdoc/nodes/fence/index.js +1 -1
- package/dist/markdoc/tags/openapi-code-sample.js +1 -1
- package/dist/markdoc/tags/openapi-response-sample.js +1 -1
- package/dist/markdoc/tags/replay-openapi.js +1 -1
- package/dist/server/constants/plugins/search.d.ts +0 -1
- package/dist/server/constants/plugins/search.js +1 -1
- package/dist/server/esbuild/plugins/dependency-resolver.js +1 -1
- package/dist/server/plugins/api-docs/search/create-indexer.d.ts +1 -4
- package/dist/server/plugins/api-docs/search/create-indexer.js +1 -1
- package/dist/server/plugins/api-docs/search/get-ai-search-documents.js +23 -23
- package/dist/server/plugins/api-docs/search/search-resolver.js +1 -1
- package/dist/server/plugins/markdown/attribute-resolvers/helpers/load-openapi-bundle.d.ts +1 -0
- package/dist/server/plugins/markdown/attribute-resolvers/helpers/load-openapi-bundle.js +1 -1
- package/dist/server/plugins/markdown/attribute-resolvers/index.js +1 -1
- package/dist/server/plugins/markdown/attribute-resolvers/resolve-openapi-code-samples.js +1 -1
- package/dist/server/plugins/markdown/attribute-resolvers/resolve-openapi-operation.d.ts +10 -0
- package/dist/server/plugins/markdown/attribute-resolvers/resolve-openapi-operation.js +1 -0
- package/dist/server/plugins/markdown/runtime-transform.js +1 -1
- package/dist/server/plugins/markdown/utils/resolve-markdown-template.js +1 -1
- package/dist/server/plugins/mcp/handlers/docs-mcp-handler.js +1 -1
- package/dist/server/plugins/search/engines/flexsearch/search-index.js +1 -1
- package/dist/server/plugins/search/engines/typesense/index.js +1 -1
- package/dist/server/utils/crypto/sha-dir-path-short.js +1 -1
- package/package.json +3 -3
- package/dist/server/utils/search/highlight-text-for-search.d.ts +0 -3
- package/dist/server/utils/search/highlight-text-for-search.js +0 -1
- package/dist/server/utils/search/text-match.d.ts +0 -6
- package/dist/server/utils/search/text-match.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{logger as A}from"../../../tools/notifiers/logger.js";import{getFeedbackClientIp as v}from"../../../web-server/utils/feedback-ip.js";import{getForwardedOrigin as M,getInternalOrigin as N}from"../../../web-server/utils/get-request-origin.js";import{GATEWAY_FETCH_LIMIT_DEFAULTS as L,DEFAULT_ANONYMOUS_VISITOR_TEAM as B,RbacFeatures as H}from"../../../../constants/common.js";import{isObject as j}from"../../../../utils/guards/is-object.js";import{getAccessibleSkills as V}from"../../../utils/skills/get-accessible-skills.js";import{getSkillUrl as $}from"../../../utils/skills/get-skill-url.js";import{createMcpHandler as Y}from"@modelcontextprotocol/server";import{createDocsMcpServer as G}from"../servers/docs-server.js";import{filterApiDescriptionsByRbac as J,filterGraphqlDescriptionsByRbac as K}from"../utils.js";import{userSubject as z}from"../gateway-mcp/subject.js";import{ipRateLimitKey as X}from"../gateway-mcp/rate-limit/utils/ip-key.js";import{createMethodNotAllowedError as Q,withErrorHandling as W}from"./errors.js";import{constructForbiddenResponse as Z,constructInvalidTokenResponse as q,constructUnauthorizedResponse as x,handleMcpAuth as ee}from"../auth/auth-handlers.js";import{isAssistantAnonymousToken as oe}from"../auth/assistant-anonymous-token.js";import{shouldHandleMcpAuth as re}from"../../../utils/rbac/should-handle-mcp-auth.js";import{extractTokenFromAuthHeader as se}from"../utils/jwt.js";import{resolveMcpClient as ie}from"../utils/mcp-client.js";import{randomUUID as ne}from"../../../utils/crypto/random-uuid.js";import{getPublicMcpEndpointStatus as te}from"../utils/public-endpoint.js";import{narrowMcpConfigForCaller as ce}from"../gateway-mcp/caller-api-calls.js";import{DEFAULT_DOCS_MCP_SERVER_NAME as ae,SSE_KEEPALIVE_INTERVAL_MS as pe}from"../constants.js";import{withPathPrefix as de}from"@redocly/theme/core/utils";import{PUBLIC_MCP_ROUTE as le}from"@redocly/theme/core/constants/mcp";import{canAccessFeature as me}from"../../../utils/rbac/can-access-feature.js";import{ANONYMOUS_AUTH_DETAILS as fe}from"../../../constants/rbac.js";const E="X-Redocly-AI-Metadata",ue=1024*1024;function ge(o){if(o)try{const e=JSON.parse(o);if(j(e))return e;A.warn(`Ignoring ${E} header: not a JSON object.`)}catch{A.warn(`Ignoring ${E} header: invalid JSON.`)}}function he(o,e){return new URL(o).searchParams.get("mode")==="tools"?"tools":e}function b(){return{...fe,email:"",idpAccessToken:void 0,idpId:void 0}}const Ae=async(o,e,n)=>{const t=!!e?.config?.access?.requiresLogin,c=e?.config?.access?.rbac||{},I=n?.props?.config?.mcpMode??"tools",p=he(o.url,I),U=n?.props?.config?.gatewayFetchBudgetPerExec??L.budgetPerExec,R=n?.props?.config?.searchIgnoredRoutes??[],r=n,C=!!r?.props?.config?.isPublicEndpoint;let u;const T=o.headers.get("Authorization");if(C)e.user=b();else if(re(t,c)){const{isAuthenticated:i,isTokenValid:d,isFirstPartyAnonymous:g,currentUser:l,accessToken:h}=await ee(o,e);if(g)e.user=b();else if(i)l&&(e.user=l),u=h;else{const a=M(o),m=te(e.config)==="served"?`${a}${de(le)}`:void 0;return d===!1?q(a,m):x(a,m)}}else if(T){const i=se(T)??void 0;u=(i?await oe(i):!1)?void 0:i}const _={isAuthenticated:!!e.user?.isAuthenticated,teams:e.user?.teams||[B],claims:e.user?.claims??{}};return me(H.MCP,_,c,t)?await W(async()=>{const i=p==="code"&&(n?.props?.config?.elicitationEnabled??!1);if(o.method==="GET")return new Response(JSON.stringify({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: ${o.url}`}),{status:405,headers:{"Content-Type":"application/json"}});if(o.method!=="POST")return Q();const d=r?.props?.config?.apiDescriptionsMap||{},g=r?.props?.config?.graphqlDescriptions||[],l=r?.props?.config?.mcpDocsServerName||ae,{config:{mcp:h={}}}=e,a=J(d,e.user,c,t),m=K(g,e.user,c,t),y=e.config.products?Object.values(e.config.products).map(s=>s?.name):[],D=h.docs?.name||l,f=ge(o.headers.get(E)),P=r?.props?.tools||[],O=r?.props?.skillsBaseUrl||M(o),w=V(r?.props?.skills||[],e.user,c,t).map(s=>({slug:s.slug,name:s.name,description:s.description,content:s.content,uri:$(O,s.slug)})),S=r?.props?.fetchCountSecret,F={name:D,tools:P,skills:w,context:{...e,config:{...e.config,mcp:ce(e.config.mcp,f)},configFile:r?.props?.configFile,accessToken:u,outdir:e.outdir||"",baseUrl:e.baseUrl||M(o),internalBaseUrl:N(o),apiDescriptionsMap:a,graphqlDescriptions:m,products:y,metadata:f,mcpMode:p,elicitationEnabled:i,gatewayFetchBudgetPerExec:U,fetchCountRequest:p==="code"&&S?{caller:{subject:z(e.user),ip:X(o)},secret:S}:void 0,searchIgnoredRoutes:R,clientIp:v(o),...ie(o),requestId:ne(),messageId:typeof f?.messageId=="string"?f.messageId:void 0}},k=await G({...F,getKv:e.getKv});return await Y(async()=>k,{keepAliveMs:pe,maxRequestBodySize:ue,onerror:s=>A.warn(`MCP handler: ${s.message}`)}).fetch(o)},p):Z()};var Je=Ae;export{Je as default};
|
|
1
|
+
import{logger as A}from"../../../tools/notifiers/logger.js";import{getFeedbackClientIp as v}from"../../../web-server/utils/feedback-ip.js";import{getForwardedOrigin as M,getInternalOrigin as N}from"../../../web-server/utils/get-request-origin.js";import{GATEWAY_FETCH_LIMIT_DEFAULTS as L,DEFAULT_ANONYMOUS_VISITOR_TEAM as B,RbacFeatures as H}from"../../../../constants/common.js";import{isObject as j}from"../../../../utils/guards/is-object.js";import{getAccessibleSkills as V}from"../../../utils/skills/get-accessible-skills.js";import{getSkillUrl as $}from"../../../utils/skills/get-skill-url.js";import{createMcpHandler as Y}from"@modelcontextprotocol/server";import{createDocsMcpServer as G}from"../servers/docs-server.js";import{filterApiDescriptionsByRbac as J,filterGraphqlDescriptionsByRbac as K}from"../utils.js";import{userSubject as z}from"../gateway-mcp/subject.js";import{ipRateLimitKey as X}from"../gateway-mcp/rate-limit/utils/ip-key.js";import{createMethodNotAllowedError as Q,withErrorHandling as W}from"./errors.js";import{constructForbiddenResponse as Z,constructInvalidTokenResponse as q,constructUnauthorizedResponse as x,handleMcpAuth as ee}from"../auth/auth-handlers.js";import{isAssistantAnonymousToken as oe}from"../auth/assistant-anonymous-token.js";import{shouldHandleMcpAuth as re}from"../../../utils/rbac/should-handle-mcp-auth.js";import{extractTokenFromAuthHeader as se}from"../utils/jwt.js";import{resolveMcpClient as ie}from"../utils/mcp-client.js";import{randomUUID as ne}from"../../../utils/crypto/random-uuid.js";import{getPublicMcpEndpointStatus as te}from"../utils/public-endpoint.js";import{narrowMcpConfigForCaller as ce}from"../gateway-mcp/caller-api-calls.js";import{DEFAULT_DOCS_MCP_SERVER_NAME as ae,SSE_KEEPALIVE_INTERVAL_MS as pe}from"../constants.js";import{withPathPrefix as de}from"@redocly/theme/core/utils";import{PUBLIC_MCP_ROUTE as le}from"@redocly/theme/core/constants/mcp";import{canAccessFeature as me}from"../../../utils/rbac/can-access-feature.js";import{ANONYMOUS_AUTH_DETAILS as fe}from"../../../constants/rbac.js";const E="X-Redocly-AI-Metadata",ue=1024*1024;function ge(o){if(o)try{const e=JSON.parse(o);if(j(e))return e;A.warn(`Ignoring ${E} header: not a JSON object.`)}catch{A.warn(`Ignoring ${E} header: invalid JSON.`)}}function he(o,e){return new URL(o).searchParams.get("mode")==="tools"?"tools":e}function b(){return{...fe,email:"",idpAccessToken:void 0,idpId:void 0}}const Ae=async(o,e,n)=>{const t=!!e?.config?.access?.requiresLogin,c=e?.config?.access?.rbac||{},I=n?.props?.config?.mcpMode??"tools",p=he(o.url,I),U=n?.props?.config?.gatewayFetchBudgetPerExec??L.budgetPerExec,R=n?.props?.config?.searchIgnoredRoutes??[],r=n,C=!!r?.props?.config?.isPublicEndpoint;let u;const T=o.headers.get("Authorization");if(C)e.user=b();else if(re(t,c)){const{isAuthenticated:i,isTokenValid:d,isFirstPartyAnonymous:g,currentUser:l,accessToken:h}=await ee(o,e);if(g)e.user=b();else if(i)l&&(e.user=l),u=h;else{const a=M(o),m=te(e.config)==="served"?`${a}${de(le)}`:void 0;return d===!1?q(a,m):x(a,m)}}else if(T){const i=se(T)??void 0;u=(i?await oe(i):!1)?void 0:i}const _={isAuthenticated:!!e.user?.isAuthenticated,teams:e.user?.teams||[B],claims:e.user?.claims??{}};return me(H.MCP,_,c,t)?await W(async()=>{const i=p==="code"&&(n?.props?.config?.elicitationEnabled??!1);if(o.method==="GET")return new Response(JSON.stringify({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: ${o.url}`}),{status:405,headers:{"Content-Type":"application/json"}});if(o.method!=="POST")return Q();const d=r?.props?.config?.apiDescriptionsMap||{},g=r?.props?.config?.graphqlDescriptions||[],l=r?.props?.config?.mcpDocsServerName||ae,{config:{mcp:h={}}}=e,a=J(d,e.user,c,t),m=K(g,e.user,c,t),y=e.config.products?Object.values(e.config.products).map(s=>s?.name):[],D=h.docs?.name||l,f=ge(o.headers.get(E)),P=r?.props?.tools||[],O=r?.props?.skillsBaseUrl||M(o),w=V(r?.props?.skills||[],e.user,c,t).map(s=>({slug:s.slug,name:s.name,description:s.description,content:s.content,uri:$(O,s.slug)})),S=r?.props?.fetchCountSecret,F={name:D,tools:P,skills:w,context:{...e,config:{...e.config,mcp:ce(e.config.mcp,f)},configFile:r?.props?.configFile,accessToken:u,outdir:e.outdir||"",baseUrl:e.baseUrl||M(o),internalBaseUrl:N(o),apiDescriptionsMap:a,graphqlDescriptions:m,products:y,metadata:f,mcpMode:p,elicitationEnabled:i,gatewayFetchBudgetPerExec:U,fetchCountRequest:p==="code"&&S?{caller:{subject:z(e.user),ip:X(o)},secret:S}:void 0,searchIgnoredRoutes:R,clientIp:v(o),...ie(o),requestId:ne(),messageId:typeof f?.messageId=="string"?f.messageId:void 0}},k=await G({...F,getKv:e.getKv});return await Y(async()=>k,{responseMode:o.headers.get("mcp-method")==="tools/call"?"sse":"auto",keepAliveMs:pe,maxRequestBodySize:ue,onerror:s=>A.warn(`MCP handler: ${s.message}`)}).fetch(o)},p):Z()};var Je=Ae;export{Je as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import _ from"flexsearch";import{REDOCLY_TEAMS_RBAC as L}from"@redocly/config";import{DISABLE_DEEP_LINK_IF_FIELDS_EXIST as C,SEARCH_LIMIT as R}from"../../../../constants/plugins/search.js";import{telemetryTraceStep as b}from"../../../../telemetry/helpers/trace-step.js";import{highlightTextForSearch as m,markMatchedValue as D}from"
|
|
1
|
+
import _ from"flexsearch";import{REDOCLY_TEAMS_RBAC as L}from"@redocly/config";import{DISABLE_DEEP_LINK_IF_FIELDS_EXIST as C,SEARCH_LIMIT as R}from"../../../../constants/plugins/search.js";import{telemetryTraceStep as b}from"../../../../telemetry/helpers/trace-step.js";import{highlightTextForSearch as m,markMatchedValue as D}from"@redocly/theme/core/utils/search-highlight";import{MIN_QUERY_WORD_LENGTH as M,containsQueryWord as S,matchableQueryWords as j}from"@redocly/theme/core/utils/search-text-match";function k(I){const{name:e,description:t,place:s,path:i,deepLink:r,example:n,enum:a}=I,o=r?.indexOf("#")??-1;return{name:e,description:t,place:s,...i&&{path:i},...r&&{deepLink:o>=0?r.slice(o+1):r},example:n,enum:a}}class T{#t;#e=new Map;#s=1;id;constructor(e,t){this.id=e,this.#t=new _.Document(t)}get documents(){return this.#e.entries()}get documentsCount(){return this.#s}clearDocuments(){this.#e.clear()}async export(e){await this.#t.export(e)}async import(e){this.#e.clear();for await(const t of e)if("document"in t){const[s,i]=t.document;this.#e.set(s,i)}else{const[s,i]=t.index;await this.#t.import(s,i)}}add(e){const t={...e,tags:e.tags??[],[L]:e[L],...e.parameters&&{parameters:e.parameters.map(k)}};this.#e.set(this.#s,t),this.#t.add(this.#s,t),this.#s++}async search(e){return await b("com.redocly.search.performed",async t=>{t?.setAttribute("id","searchQueryId"),t?.setAttribute("object","searchQuery"),t?.setAttribute("uri","urn:redocly:realm:api:searchQuery:searchQueryId");const{query:s,offset:i,auth:r,product:n,versions:a}=e,o=[],l=r.teams,p={limit:R,offset:i},c=this.#r(s);if(!c.length&&s.trim())return{documents:{[this.id]:[]},facets:{},hasCoveringHit:!1};let d=new Map,g=await this.#t.searchAsync(s,{...p,tag:l});if(n){const h=await this.#t.searchAsync(s,{...p,tag:n});g=this.#a(g,h),t?.setAttribute("product",n)}if(a&&a.length){const h=await this.#t.searchAsync(s,{...p,tag:a});g=this.#a(g,h),t?.setAttribute("versions",a.join(","))}for(const h of g)for(const u of h.result){const f=d.get(u)?.fields||[];d.set(u,{fields:h.field?[...f,h.field]:[...f]})}!i&&c.length&&!d.size&&(d=this.#l(c,l,n,a));const x=[];for(const[h,u]of d.entries()){const f=this.#e.get(h);f&&!this.#d(f,a)&&x.push({document:f,fields:u.fields,score:this.#m(c,f)})}const y=x.filter(h=>h.score>=c.length),A=y.length?y:x;A.sort((h,u)=>u.score-h.score);for(const h of A.slice(0,R))o.push({document:this.#o(h.document,s,h.fields),highlight:this.#h(h.document,s,h.fields)});return{documents:{[this.id]:o},facets:{},hasCoveringHit:y.length>0}})}#o(e,t,s){return this.#g(e,t,s)}#h(e,t,s){const i={};let r=!1;for(const n of s)if(n==="path")i.path=e.path?e.path.map(a=>m(t,a)):[];else if(n.includes("parameters")){if(!r){const a=n.split(":")[1],o=this.#n(t,a,e.parameters);o&&(i.parameters=[{name:m(t,o.name),description:m(t,o.description),place:m(t,o.place),path:o.path?o.path.map(l=>m(t,l)):[],...this.#c(t,o)}],r=!0)}}else n!=="httpMethod"&&(i[n]=m(t,e[n]));return i}#c(e,t){return{enum:D(e,(t.enum??[]).join(", ")),example:D(e,t.example??"")}}#r(e){return j(e)}#l(e,t,s,i){const r=new Map;if(!e.length)return r;for(const[n,a]of this.#e)this.#p(a,t,s,i)&&this.#f(e,a)&&r.set(n,{fields:this.#u(e,a)});return r}#f(e,t){const s=i=>{if(i==null)return!1;const r=(Array.isArray(i)?i.join(" "):String(i)).toLowerCase();return!!r&&e.every(n=>S(r,n))};return s(t.title)||s(t.text)||s(t.httpPath)||s(t.path)?!0:(t.parameters??[]).some(i=>s(i.name)||s(i.description)||s(i.example)||s(i.enum))}#p(e,t,s,i){const r=new Set(e.tags??[]);return!(t.length&&!t.some(n=>r.has(n))||s&&!r.has(s)||i&&i.length&&!i.some(n=>r.has(n)))}#u(e,t){const s=r=>{if(r==null)return!1;const n=(Array.isArray(r)?r.join(" "):String(r)).toLowerCase();return e.some(a=>S(n,a))},i=[];s(t.title)&&i.push("title"),s(t.text)&&i.push("text"),s(t.path)&&i.push("path"),t.httpMethod&&e.some(r=>r.length>=M&&t.httpMethod?.toLowerCase().startsWith(r))&&i.push("httpMethod"),s(t.httpPath)&&i.push("httpPath");for(const r of["name","description","path","example","enum"])t.parameters?.some(n=>s(n[r]))&&i.push(`parameters[]:${r}`);return i}#i(e,t){const s=t.toLowerCase().replace(/\s+/g," "),i=e.filter(n=>S(s,n)).length;let r=0;for(let n=1;n<e.length;n++)s.includes(`${e[n-1]} ${e[n]}`)&&r++;return i+r/e.length}#m(e,t){let s=0;const i=r=>{if(r==null)return;const n=this.#i(e,String(r));n>s&&(s=n)};if(i(t.title),i(t.text),i(t.httpPath),i(t.path?.join(" ")),t.httpMethod){const r=t.httpMethod.toLowerCase(),n=e.filter(a=>a.length>=M&&r.startsWith(a)).length;n>s&&(s=n)}for(const r of t.parameters??[])i([r.name,r.description,r.place,r.example,r.enum?.join(" ")].filter(Boolean).join(" "));return s}#n(e,t,s){const i=this.#r(e);let r,n=0;for(const a of s??[]){const o=a[t],l=(Array.isArray(o)?o:[o]).filter(c=>c!=null).map(c=>String(c)).join(" "),p=this.#i(i,l);p>n&&(n=p,r=a)}return r}#a(e,t){const s=[];for(const i of e){const r=[];for(const n of t)for(const a of i.result){const o=n.result.find(l=>l===a);o&&r.push(o)}r.length&&s.push({result:r,field:i.field})}return s}#d(e,t){return!!(t&&t.length&&e.isDefaultVersion&&e.versionFolderId&&e.version&&t.some(s=>s.includes(e.versionFolderId??""))&&!t.some(s=>s.includes(e.version??"")))}#g(e,t,s){for(const r of C)if(s.some(n=>n===r))return e;let i;for(const r of s)if(r.includes("parameters")){const n=r.split(":")[1],a=this.#n(t,n,e.parameters);if(a){i=a.deepLink;break}}return i?{...e,url:`${e.url}#${i}`}:e}}export{T as FlexSearchIndex};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{appendFile as T}from"node:fs/promises";import{existsSync as P}from"node:fs";import b from"node:path";import{Client as q}from"typesense";import{SEARCH_GROUP_FACET_FIELD as F,SEARCH_PRODUCT_FIELD as L,SEARCH_RBAC_FIELD as d,SEARCH_VERSION_FIELD as h}from"../../../../../constants/common.js";import{DISABLE_DEEP_LINK_IF_FIELDS_EXIST as v,
|
|
1
|
+
import{appendFile as T}from"node:fs/promises";import{existsSync as P}from"node:fs";import b from"node:path";import{Client as q}from"typesense";import{SEARCH_GROUP_FACET_FIELD as F,SEARCH_PRODUCT_FIELD as L,SEARCH_RBAC_FIELD as d,SEARCH_VERSION_FIELD as h}from"../../../../../constants/common.js";import{DISABLE_DEEP_LINK_IF_FIELDS_EXIST as v,SEARCH_DATA_EXPORT_FOLDER as C,SEARCH_DOCUMENT_METADATA_KEY as j,SEARCH_GROUP_LIMIT as R,SEARCH_MAX_FACET_VALUES as y,SEARCH_MAX_INMEMORY_DOCUMENTS_COUNT as k}from"../../../../constants/plugins/search.js";import{telemetryTraceStep as O}from"../../../../telemetry/helpers/trace-step.js";import{envConfig as _}from"../../../../config/env-config.js";import{logger as I}from"../../../../tools/notifiers/logger.js";import{HIGHLIGHTED_TEXT_MAX_LENGTH as N}from"@redocly/theme/core/utils/search-highlight";import{ensureDir as E}from"../../../../utils/index.js";class J{#e=null;#i="";#t=[{name:"title",type:"string",facet:!1,optional:!0},{name:"text",type:"string",facet:!1,optional:!0},{name:"path",type:"string[]",facet:!1,optional:!0},{name:"isAdditionalOperation",type:"bool",facet:!1,optional:!0,queryable:!1},{name:"deprecated",type:"bool",facet:!1,optional:!0,queryable:!1},{name:"parameters",type:"object[]",facet:!1,optional:!0},{name:"parameters.name",type:"string[]",facet:!1,optional:!0,queryable:!1},{name:"parameters.description",type:"string[]",facet:!1,optional:!0,queryable:!1},{name:"parameters.place",type:"string[]",facet:!1,optional:!0,queryable:!1},{name:"parameters.path",type:"string[]",facet:!1,optional:!0,queryable:!1},{name:L,type:"string",facet:!0,optional:!0},{name:h,type:"object",facet:!0,optional:!0},{name:d,type:"string[]",facet:!0},{name:"metadata_curated",type:"bool",facet:!1,optional:!0,queryable:!1},{name:"metadata_keywords_excludes",type:"string[]",facet:!1,optional:!0,queryable:!1},{name:"metadata_keywords_includes",type:"string[]",facet:!1,optional:!0,queryable:!1}];#s=new Map;#r={ORGANIZATION_ID:_.ORGANIZATION_ID??"",PROJECT_ID:_.PROJECT_ID??"",TYPESENSE_API_URL:_.TYPESENSE_API_URL??"",TYPESENSE_API_KEY:_.TYPESENSE_API_KEY??""};constructor(){if(!_.isBuildMode){for(const[e,t]of Object.entries(this.#r))if(!t)throw new Error(`Cannot initialize search index. ${e} is not set`);this.#i=`${this.#r.ORGANIZATION_ID}_${this.#r.PROJECT_ID}_`,this.#e=new q({nodes:[{url:this.#r.TYPESENSE_API_URL}],apiKey:this.#r.TYPESENSE_API_KEY,connectionTimeoutSeconds:5})}}async initIndexSchema(e){this.#b(e)}async addDocuments(e,t){const{locale:s,outDir:a}=t,n=e.map(r=>{const i={...r},c=r[j];return c&&(c.curated&&(i.metadata_curated=c.curated),c.excludes&&(i.metadata_keywords_excludes=c.excludes),c.includes&&(i.metadata_keywords_includes=c.includes)),i}),o=this.#s.get(s)??[];this.#s.set(s,o.concat(n)),o.length+e.length>=k&&await this.exportDocuments(a)}async search(e,t){return await O("com.redocly.search.performed",async s=>{s?.setAttribute("id","searchQueryId"),s?.setAttribute("object","searchQuery"),s?.setAttribute("uri","urn:redocly:realm:api:searchQuery:searchQueryId");const{query:a,locale:n,filter:o,loadMore:r}=e,i=this.#f(n),c={collection:i,q:a||"*",query_by:this.#h(),max_facet_values:y};if(s?.setAttribute("collectionName",i),s?.setAttribute("locale",n),this.#e)if(r){const{groupKey:l,offset:u}=r,f={offset:u,filter_by:this.#n(t,o),facet_by:"*",per_page:R};return s?.setAttribute("isLoadMore",!0),s?.setAttribute("filter",f.filter_by),this.#d(await this.#e.collections(i).documents().search({...c,...f}),l)}else{const l=this.#n(t,o);s?.setAttribute("filter",l);const u=await this.#e.multiSearch.perform({searches:this.#F(t,o)},c),f=this.#c(u,this.#o());f&&I.warn("Search facet requests failed: %s",f);const p=this.#y(u),m=(p[F]??[]).map(A=>A.value);s?.setAttribute("groups",m.join(",")),m.length===y&&I.warn("Search category facet list reached the limit of %s; results for some categories may be missing",y);const D=[...new Set(this.#m(o))].slice(0,y),g=D.length?D:m;if(!g.length)return{facets:p,documents:{},groupCounts:{}};const S=await this.#e.multiSearch.perform({searches:g.map(A=>({filter_by:`${l} && (${F}:=${this.#a(A)})`,per_page:R}))},c),$=this.#c(S,g);return $&&I.warn("Search category requests failed: %s",$),this.#_(S,g,p,o)}else return{facets:{},documents:{}}})}#d(e,t){const s={facets:{},documents:{[t]:[]},groupCounts:typeof e.found=="number"?{[t]:e.found}:{}};if(e.hits&&e.hits.length)for(const a of e.hits)s.documents[t].push({document:this.#l(a),highlight:this.#u(a)});return s}#y(e){const t={};if("results"in e){for(const s of e.results)if(s.facet_counts&&s.facet_counts.length)for(const a of s.facet_counts)t[a.field_name]=a.counts.map(n=>({value:n.value,count:n.count}))}return t}#c(e,t){return"results"in e?e.results.map((s,a)=>({result:s,label:t[a]})).filter(({result:s})=>"error"in s).map(({result:s,label:a})=>`${a}: ${s.error}`).join("; "):""}#_(e,t,s,a){const n={},o={facets:s,documents:{},groupCounts:n};for(const r of this.#m(a))o.documents[r]=[];return"results"in e&&e.results.forEach((r,i)=>{const c=t[i];typeof r.found=="number"&&(n[c]=r.found);const l=r.hits??[];l.length&&(o.documents[c]=l.map(u=>({document:this.#l(u),highlight:this.#u(u)})))}),o}#l(e){return this.#g(e)}#u(e){const t={},s=[];for(const[a,n]of Object.entries(e.highlight??{}))if(Array.isArray(n)){if(a==="path"){const o=n,r=[];for(const i of o)r.push(i.snippet);t.path=r}else if(a==="parameters"){const o=n;for(const r of o){let i=!1;for(const[c,l]of Object.entries(r))if(c!=="deepLink")if(Array.isArray(l))for(const u of l)u.matched_tokens?.length&&(i=!0);else l.matched_tokens?.length&&(i=!0);if(i){const c={name:r.name?.snippet||"",description:r.description?.snippet||"",place:r.place?.snippet||"",path:r.path?.map(l=>l?.snippet)||[]};t.parameters=[c];break}}}}else t[a]=n.snippet,s.push(a);for(const[a,n]of Object.entries(e.document))!s.includes(a)&&typeof n=="string"&&(t[a]=n.length>N?`${n.substring(0,N)}...`:n);return t.parameters||(t.parameters=[]),t}#g(e){let t;const s=Object.keys(e.highlight??{});for(const n of v)if(s.some(o=>o===n))return e.document;const a=e.highlight?.parameters;if(a){for(const n of a)for(const[o,r]of Object.entries(n))if(o!=="deepLink"){if(Array.isArray(r)){for(const i of r)if(i.matched_tokens?.length){t=n.deepLink?.snippet??t;break}}else if(r.matched_tokens?.length){t=n.deepLink?.snippet??t;break}}}if(t){const n=t.split("#")[1];return{...e.document,url:`${e.document.url}#${n}`}}return e.document}async exportDocuments(e){const t='{"documents":[',s=E(b.join(e,C));for(const[a,n]of this.#s){if(n.length===0)continue;const o=E(b.join(s,`${a}.json`)),r=!P(o),i=JSON.stringify(n).substring(1).slice(0,-1),c=r?t+i:","+i;await T(o,c,{encoding:"utf8"}),this.#s.set(a,[])}}async exportIndexes(e){const t=E(b.join(e,C));for(const s of this.#s.keys()){const a=E(b.join(t,`${s}.json`)),n=`],"schemaFields":${JSON.stringify(this.#t)}}`;await T(a,n,{encoding:"utf8"})}}async import(e){}async countFacets(e,t){return await O("com.redocly.search.facets",async s=>{s?.setAttribute("id","searchFacetsId"),s?.setAttribute("object","searchFacets"),s?.setAttribute("uri","urn:redocly:realm:api:searchFacets:searchFacetsId");const{locale:a,query:n,facetQuery:o,filter:r,field:i}=e,c=this.#f(a),l={q:n||"*",query_by:this.#h(),facet_by:"*",facet_query:this.#A(o,i),filter_by:this.#n(t,r,i),max_facet_values:y,per_page:0};if(s?.setAttribute("collectionName",c),s?.setAttribute("query",l.q),s?.setAttribute("facetQuery",l.facet_query),s?.setAttribute("filter",l.filter_by),this.#e){const u={},f=await this.#e.collections(c).documents().search(l);if(f.facet_counts&&f.facet_counts.length)for(const p of f.facet_counts)u[p.field_name]=p.counts.map(m=>({value:m.value,count:m.count,isCounterVisible:!!n||(r?.length||0)>0}));return u}else return{}})}#f(e){return`${this.#i}${e}`}#b(e){for(const[t,{queryable:s}]of e)this.#t.find(a=>a.name===t)||this.#t.push({queryable:s,name:t,type:"string",facet:!0,optional:!0})}#h(){return this.#t.filter(e=>e.facet?e.queryable:e.queryable!==!1).map(e=>e.name).join(",")}#a(e){return`\`${e.replaceAll("`","")}\``}#n(e,t,s){const a=e.teams.filter(r=>!r.includes("`")&&!r.includes("*")).map(r=>this.#a(r)),n=a.length?`${d}:=[${a.join(", ")}]`:`${d}:=[\`anonymous\`] && ${d}:!=[\`anonymous\`]`,o=(t??[]).filter(r=>r.field!==s&&r.field!==h&&r.values.length&&this.#p(r.field)).map(r=>{const i=r.values.map(c=>this.#a(c));return`${r.field}:=[${i.join(", ")}]`});return[n,...o,this.#E(t)].map(r=>`(${r})`).join(" && ")}#p(e){return this.#o().includes(e)}#o(){return this.#t.filter(e=>e.facet&&e.name!==d&&e.name===e.name.trim()).map(e=>e.name)}#E(e){const t=e?.find(r=>r.field===h);if(t?.values.length!==2)return`${h}.isDefault:true`;const[s,a]=t.values.map(r=>this.#a(r)),n=`(${h}.folderId:! ${s} && ${h}.isDefault:true)`,o=`(${h}.folderId: ${s} && ${h}.version:=${a})`;return`${n} || ${o}`}#A(e,t){return e&&t&&this.#p(t)?`${t}:${e}`:""}#m(e){const t=[];if(e&&e.length)for(const s of e)s.field===F&&t.push(...s.values);return t}#F(e,t){const s=[];for(const a of this.#o()){const n={facet_by:a,filter_by:this.#n(e,t,a),per_page:0};s.push(n)}return s}cleanupFacetValues(e){const t=e.getSearchFacets();t.forEach(s=>{s.values=[]}),e.setSearchFacets(t)}}export{J as Typesense};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{addLeadingSlash as a,removeTrailingSlash as t}from"@redocly/theme/core/utils";import{shaHexShort as h}from"./sha-hex-short.js";function m(r){const o=r==="."?"/":a(t(r));return h(o)}export{m as shaDirPathShort};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@redocly/redoc-reef",
|
|
3
|
-
"version": "0.141.0-next.
|
|
3
|
+
"version": "0.141.0-next.15",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -33,14 +33,14 @@
|
|
|
33
33
|
"@opentelemetry/sdk-trace-web": "2.8.0",
|
|
34
34
|
"@opentelemetry/semantic-conventions": "1.40.0",
|
|
35
35
|
"@redocly/ajv": "8.18.0",
|
|
36
|
-
"@redocly/api-docs": "0.6.0-next.
|
|
36
|
+
"@redocly/api-docs": "0.6.0-next.15",
|
|
37
37
|
"@redocly/config": "0.75.0",
|
|
38
38
|
"@redocly/markdoc": "0.7.1",
|
|
39
39
|
"@redocly/openapi-core": "2.78.0",
|
|
40
40
|
"@redocly/portal-legacy-ui": "0.19.0",
|
|
41
41
|
"@redocly/portal-plugin-mock-server": "0.26.0-next.4",
|
|
42
42
|
"@redocly/realm-asyncapi-sdk": "0.18.0-next.1",
|
|
43
|
-
"@redocly/theme": "0.73.0-next.
|
|
43
|
+
"@redocly/theme": "0.73.0-next.11",
|
|
44
44
|
"@shikijs/transformers": "3.21.0",
|
|
45
45
|
"@tanstack/react-query": "5.62.3",
|
|
46
46
|
"@tanstack/react-table": "8.21.3",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{HIGHLIGHTED_TEXT_MAX_LENGTH as f}from"../../constants/plugins/search.js";import{MIN_INFIX_MATCH_LENGTH as h,MIN_QUERY_WORD_LENGTH as g,isWordChar as c,matchableQueryWords as m}from"./text-match.js";function w(t,e){if(!e)return"";const r=p(t);if(!r.length)return e;const n=f+t.length;if(e.length<=n)return u(r,e);const o=M(l(r,e),n)??{start:0,end:0},{start:s,end:d}=_(e,o,n),a=u(r,e.slice(s,d));return`${s>0?"...":""}${a}${d<e.length?"...":""}`}function I(t,e){if(!e)return;const r=w(t,e);return r.includes("<mark>")?r:void 0}function p(t){return m(t).sort((e,r)=>r.length-e.length)}function l(t,e){const r=e.toLowerCase(),n=[];for(const o of t)for(let s=r.indexOf(o);s!==-1;s=r.indexOf(o,s+1)){const d=!c(r[s-1]);if(!d&&o.length<h||o.length<g&&c(r[s+o.length]))continue;let a=s+o.length;if(d)for(;c(r[a]);)a++;n.push({start:s,end:a,word:o})}return n.sort((o,s)=>o.start-s.start||o.end-s.end)}function M(t,e){let r;for(let n=0;n<t.length;n++){const o=new Set;let s=t[n].end;for(let a=n;a<t.length&&t[a].end-t[n].start<=e;a++)o.has(t[a].word)||(o.add(t[a].word),s=t[a].end);const d=s-t[n].start;(!r||o.size>r.count||o.size===r.count&&d<r.end-r.start)&&(r={start:t[n].start,end:s,count:o.size})}return r&&{start:r.start,end:r.end}}function _(t,e,r){const n=Math.max(r,e.end-e.start),o=n-(e.end-e.start),s=Math.min(t.length,Math.max(0,Math.floor(e.start-o/2))+n),d=Math.max(0,s-n);return{start:H(t,d,e.start),end:T(t,s,e.end)}}function H(t,e,r){let n=e;if(n>0&&!i(t[n-1]))for(;n<r&&!i(t[n]);)n++;for(;n<r&&i(t[n]);)n++;return n}function T(t,e,r){let n=e;if(n<t.length&&!i(t[n]))for(;n>r&&!i(t[n]);)n--;for(;n>r&&i(t[n-1]);)n--;return n}function i(t){return t!==void 0&&/\s/.test(t)}function u(t,e){const r=l(t,e);if(!r.length)return e;const n=[];for(const d of r){const a=n[n.length-1];a&&(d.start<=a.end||!e.slice(a.end,d.start).trim())?a.end=Math.max(a.end,d.end):n.push({start:d.start,end:d.end})}let o="",s=0;for(const d of n)o+=`${e.slice(s,d.start)}<mark>${e.slice(d.start,d.end)}</mark>`,s=d.end;return o+e.slice(s)}export{w as highlightTextForSearch,I as markMatchedValue};
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export declare const MIN_QUERY_WORD_LENGTH = 2;
|
|
2
|
-
export declare const MIN_INFIX_MATCH_LENGTH = 3;
|
|
3
|
-
export declare function isWordChar(char: string | undefined): boolean;
|
|
4
|
-
export declare function matchableQueryWords(query: string): string[];
|
|
5
|
-
export declare function containsQueryWord(lowered: string, word: string): boolean;
|
|
6
|
-
//# sourceMappingURL=text-match.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
const i=2,o=3,r=/[\p{L}\p{N}_-]/u;function _(t){return t!==void 0&&r.test(t)}function s(t){const n=[...new Set(t.toLowerCase().split(/\s+/g).filter(Boolean))];return n.some(e=>e.length>=2)?n:[]}function u(t,n){if(n.length>=3)return t.includes(n);for(let e=t.indexOf(n);e!==-1;e=t.indexOf(n,e+1))if(!_(t[e-1])&&(n.length>=2||!_(t[e+n.length])))return!0;return!1}export{o as MIN_INFIX_MATCH_LENGTH,i as MIN_QUERY_WORD_LENGTH,u as containsQueryWord,_ as isWordChar,s as matchableQueryWords};
|