Document Search
Since v5.0.0, this module has been added. Accessed via app.docs, it provides search and retrieval capabilities for the CloudBase official documentation site.
DocsService directly requests the public network documentation site, does not rely on the TCB environment ID, and can be invoked in any environment.
listModules
1. API Description
API feature: List all top-level and second-level documentation module names of the documentation site.
API declaration: app.docs.listModules(): Promise<string[]>
2. Input Parameters
N/A
3. Return Results
Returns a string array, each element being a module name (sorted alphabetically).
4. Sample Code
import CloudBase from '@cloudbase/manager-node'
const app = CloudBase.init({
secretId: 'Your SecretId',
secretKey: 'Your SecretKey',
envId: 'Your envId'
})
const modules = await app.docs.listModules()
console.log(modules)
// ['SCF', 'cloud database', 'Cloud storage', 'Cloud Run', ...]
listModuleDocs
1. API Description
API feature: Obtain the document directory structure under the specified module (a nested object with leaf nodes being document paths).
API declaration: app.docs.listModuleDocs(moduleName): Promise<ModuleDocs>
2. Input Parameters
| Field | Required | Type | Description |
|---|---|---|---|
| moduleName | Required | String | Module name, can be obtained via listModules() |
3. Return Results
Returns a nested object ModuleDocs, where key is the document/submodule name, and value is the document path string (leaf) or the submodule object (non-leaf).
4. Sample Code
const moduleDocs = await app.docs.listModuleDocs('SCF')
console.log(JSON.stringify(moduleDocs, null, 2))
// {
// "Quick Start": "cloud-function/quick-start/index",
// "Node.js Development Guide": { ... },
// ...
// }
findByName
1. API Description
API feature: Unified search entry, automatically identifying input formats, returning the corresponding module structure or document path.
Supports the following input formats:
- URL path (including
/): Directly returned as the document path, such ascloud-function/quick-start/create-function - Dot-separated hierarchical path: such as
Cloud Run.Quick Start.Node.js Quick Start - Top-level/nested module name: such as
SCF,WeChat ecosystem - Document title exact match: such as
Mini Program Quick Start - Prefix fuzzy matching (handling cases where titles with spaces are truncated): such as
PHPmatchesPHP Quick Start
API declaration: app.docs.findByName(input): Promise<{ type: 'module' | 'doc', data: ModuleDocs | string }>
2. Input Parameters
| Field | Required | Type | Description |
|---|---|---|---|
| input | Required | String | Query input (see formats above) |
3. Return Results
| Field | Type | Description |
|---|---|---|
| type | String | 'module' (module hit) or 'doc' (document path hit) |
| data | Any | ModuleDocs object when type='module'; document path string when type='doc' |
4. Sample Code
// Find document path
const result = await app.docs.findByName('Mini Program Quick Start')
if (result.type === 'doc') {
const content = await app.docs.readDoc(result.data)
console.log(content)
}
// Navigate using dot-separated path
const nodeResult = await app.docs.findByName('Cloud Run.Quick Start')
if (nodeResult.type === 'module') {
console.log(Object.keys(nodeResult.data))
}
readDoc
1. API Description
API feature: Read the raw Markdown content of the document page
API declaration: app.docs.readDoc(docPath): Promise<string>
2. Input Parameters
| Field | Required | Type | Description |
|---|---|---|---|
| docPath | Required | String | Document path (relative path or full URL). Relative paths are automatically concatenated with the documentation site's base URL; if the path does not include the .md suffix, it will be automatically appended. |
3. Return Results
Returns the Markdown string content of the document.
4. Sample Code
// Using relative paths (recommended to use findByName to obtain the path)
const content = await app.docs.readDoc('cloud-function/quick-start/create-function')
console.log(content)
// Use the full URL
const content2 = await app.docs.readDoc('https://docs.cloudbase.net/cloud-function/quick-start/index.md')
searchDocs
1. API Description
API feature: Use Algolia to perform full-text search on the documentation site content and return a list of matching documents.
API declaration: app.docs.searchDocs(query): Promise<SearchResult[]>
2. Input Parameters
| Field | Required | Type | Description |
|---|---|---|---|
| query | Required | String | Search keywords |
3. Return Results
Returns SearchResult[], and the structure of each element is as follows:
| Field | Type | Description |
|---|---|---|
| url | String | Full document URL |
| title | String | Document title (deepest-level heading) |
| content | String | null | Matched content fragment (may be null) |
4. Sample Code
const results = await app.docs.searchDocs('SCF timeout')
results.forEach(r => {
console.log(`[${r.title}] ${r.url}`)
if (r.content) console.log(' Summary:', r.content)
})