@vendure-io/docs-provider 0.1.0

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.
@@ -0,0 +1,520 @@
1
+ # Manifest Reference
2
+
3
+ This document provides complete API documentation for all manifest types and utility functions in `@vendure-io/docs-provider`.
4
+
5
+ ## DocsPackageManifest
6
+
7
+ The main manifest type that describes a documentation package.
8
+
9
+ ```typescript
10
+ interface DocsPackageManifest {
11
+ id: string
12
+ name: string
13
+ version: string
14
+ vendureVersion: VendureVersion
15
+ navigation: NavigationNode[]
16
+ search?: SearchConfig
17
+ github?: GitHubConfig
18
+ }
19
+ ```
20
+
21
+ ### Properties
22
+
23
+ | Property | Type | Required | Description |
24
+ | ---------------- | ------------------ | -------- | -------------------------------------------------- |
25
+ | `id` | `string` | Yes | Unique identifier used in URLs (e.g., `"core"`) |
26
+ | `name` | `string` | Yes | Human-readable display name |
27
+ | `version` | `string` | Yes | Semantic version (e.g., `"3.0.0"`) |
28
+ | `vendureVersion` | `VendureVersion` | Yes | Target Vendure version (`"v1"`, `"v2"`, or `"v3"`) |
29
+ | `navigation` | `NavigationNode[]` | Yes | Array of top-level navigation nodes |
30
+ | `search` | `SearchConfig` | No | Search indexing configuration |
31
+ | `github` | `GitHubConfig` | No | GitHub repository configuration for edit links |
32
+
33
+ ### Example
34
+
35
+ ```typescript
36
+ const manifest: DocsPackageManifest = {
37
+ id: 'my-plugin',
38
+ name: 'My Plugin Documentation',
39
+ version: '1.0.0',
40
+ vendureVersion: 'v3',
41
+ navigation: [
42
+ {
43
+ title: 'Getting Started',
44
+ slug: 'getting-started',
45
+ file: file('docs/getting-started.mdx'),
46
+ },
47
+ ],
48
+ search: {
49
+ indexFields: ['title', 'description', 'content'],
50
+ boosts: { title: 2 },
51
+ },
52
+ github: {
53
+ repository: 'vendure-ecommerce/my-plugin',
54
+ branch: 'main',
55
+ docsPath: 'docs',
56
+ },
57
+ }
58
+ ```
59
+
60
+ ---
61
+
62
+ ## NavigationNode
63
+
64
+ Represents a node in the navigation tree.
65
+
66
+ ```typescript
67
+ interface NavigationNode {
68
+ title: string
69
+ slug: string
70
+ file?: string
71
+ children?: NavigationNode[]
72
+ badge?: string
73
+ }
74
+ ```
75
+
76
+ ### Properties
77
+
78
+ | Property | Type | Required | Description |
79
+ | ---------- | ------------------ | -------- | ---------------------------------------------------- |
80
+ | `title` | `string` | Yes | Display title shown in navigation |
81
+ | `slug` | `string` | Yes | URL slug for this node |
82
+ | `file` | `string` | No | Absolute path to MDX file (leaf nodes only) |
83
+ | `children` | `NavigationNode[]` | No | Nested child navigation nodes |
84
+ | `badge` | `string` | No | Optional badge label (e.g., `"New"`, `"Deprecated"`) |
85
+
86
+ ### Node Types
87
+
88
+ **Section Node** (has children, no file):
89
+
90
+ ```typescript
91
+ {
92
+ title: 'Guides',
93
+ slug: 'guides',
94
+ children: [
95
+ // child nodes...
96
+ ],
97
+ }
98
+ ```
99
+
100
+ **Page Node** (has file, no children):
101
+
102
+ ```typescript
103
+ {
104
+ title: 'Installation',
105
+ slug: 'installation',
106
+ file: file('docs/installation.mdx'),
107
+ }
108
+ ```
109
+
110
+ **Section with Index Page** (has both file and children):
111
+
112
+ ```typescript
113
+ {
114
+ title: 'Reference',
115
+ slug: 'reference',
116
+ file: file('docs/reference/index.mdx'),
117
+ children: [
118
+ { title: 'API', slug: 'api', file: file('docs/reference/api.mdx') },
119
+ ],
120
+ }
121
+ ```
122
+
123
+ ---
124
+
125
+ ## VendureVersion
126
+
127
+ Supported Vendure versions.
128
+
129
+ ```typescript
130
+ type VendureVersion = 'v1' | 'v2' | 'v3'
131
+ ```
132
+
133
+ Use this to indicate which version of Vendure your documentation targets.
134
+
135
+ ---
136
+
137
+ ## SearchConfig
138
+
139
+ Configuration for search indexing.
140
+
141
+ ```typescript
142
+ interface SearchConfig {
143
+ indexFields: ('title' | 'description' | 'content' | 'keywords')[]
144
+ boosts?: Record<string, number>
145
+ }
146
+ ```
147
+
148
+ ### Properties
149
+
150
+ | Property | Type | Required | Description |
151
+ | ------------- | ------------------------ | -------- | --------------------------------------- |
152
+ | `indexFields` | `Array` | Yes | Fields to include in search index |
153
+ | `boosts` | `Record<string, number>` | No | Custom boost weights for search ranking |
154
+
155
+ ### Available Index Fields
156
+
157
+ - `title` - Page title from frontmatter
158
+ - `description` - Page description from frontmatter
159
+ - `content` - Full page content
160
+ - `keywords` - Keywords array from frontmatter
161
+
162
+ ### Example
163
+
164
+ ```typescript
165
+ search: {
166
+ indexFields: ['title', 'description', 'content', 'keywords'],
167
+ boosts: {
168
+ title: 3, // Title matches are 3x more important
169
+ keywords: 2, // Keyword matches are 2x more important
170
+ description: 1.5,
171
+ content: 1,
172
+ },
173
+ }
174
+ ```
175
+
176
+ ---
177
+
178
+ ## GitHubConfig
179
+
180
+ Configuration for GitHub integration (edit links, issue reporting).
181
+
182
+ ```typescript
183
+ interface GitHubConfig {
184
+ repository: string
185
+ branch?: string
186
+ docsPath?: string
187
+ }
188
+ ```
189
+
190
+ ### Properties
191
+
192
+ | Property | Type | Required | Default | Description |
193
+ | ------------ | -------- | -------- | -------- | ----------------------------------------------- |
194
+ | `repository` | `string` | Yes | - | GitHub repository in `"owner/repo"` format |
195
+ | `branch` | `string` | No | `"main"` | Branch to use for edit links |
196
+ | `docsPath` | `string` | No | `""` | Path prefix within repo for documentation files |
197
+
198
+ ### Example
199
+
200
+ ```typescript
201
+ github: {
202
+ repository: 'vendure-ecommerce/my-plugin',
203
+ branch: 'main',
204
+ docsPath: 'packages/my-plugin/docs',
205
+ }
206
+ ```
207
+
208
+ This generates edit links like:
209
+ `https://github.com/vendure-ecommerce/my-plugin/edit/main/packages/my-plugin/docs/getting-started.mdx`
210
+
211
+ ---
212
+
213
+ ## Utility Functions
214
+
215
+ ### validateManifest
216
+
217
+ Validates raw data against the manifest schema.
218
+
219
+ ```typescript
220
+ function validateManifest(manifest: unknown): DocsPackageManifest
221
+ ```
222
+
223
+ **Parameters:**
224
+
225
+ - `manifest` - Raw manifest data to validate
226
+
227
+ **Returns:** Validated `DocsPackageManifest`
228
+
229
+ **Throws:** `ManifestValidationError` if validation fails
230
+
231
+ **Example:**
232
+
233
+ ```typescript
234
+ import { validateManifest, ManifestValidationError } from '@vendure-io/docs-provider'
235
+
236
+ try {
237
+ const manifest = validateManifest(rawData)
238
+ console.log('Valid:', manifest.name)
239
+ } catch (error) {
240
+ if (error instanceof ManifestValidationError) {
241
+ console.error('Validation errors:', error.issues)
242
+ }
243
+ }
244
+ ```
245
+
246
+ ---
247
+
248
+ ### findNavigationNode
249
+
250
+ Find a navigation node by its slug path.
251
+
252
+ ```typescript
253
+ function findNavigationNode(
254
+ manifest: DocsPackageManifest,
255
+ slugPath: string,
256
+ ): NavigationNode | undefined
257
+ ```
258
+
259
+ **Parameters:**
260
+
261
+ - `manifest` - The docs package manifest
262
+ - `slugPath` - Slash-separated path (e.g., `"getting-started/installation"`)
263
+
264
+ **Returns:** Found `NavigationNode` or `undefined`
265
+
266
+ **Example:**
267
+
268
+ ```typescript
269
+ const node = findNavigationNode(manifest, 'guides/custom-plugins')
270
+ if (node) {
271
+ console.log(node.title) // "Custom Plugins"
272
+ console.log(node.file) // "/path/to/docs/guides/custom-plugins.mdx"
273
+ }
274
+ ```
275
+
276
+ ---
277
+
278
+ ### flattenNavigation
279
+
280
+ Flatten the navigation tree into a flat array.
281
+
282
+ ```typescript
283
+ function flattenNavigation(manifest: DocsPackageManifest): FlatNavigationNode[]
284
+ ```
285
+
286
+ **Returns:** Array of `FlatNavigationNode` with full path information
287
+
288
+ ```typescript
289
+ interface FlatNavigationNode extends NavigationNode {
290
+ path: string // Full path from root (e.g., "getting-started/installation")
291
+ depth: number // Depth level (0 = root)
292
+ parentPath?: string // Parent node's path, if any
293
+ }
294
+ ```
295
+
296
+ **Example:**
297
+
298
+ ```typescript
299
+ const flatNodes = flattenNavigation(manifest)
300
+ flatNodes.forEach((node) => {
301
+ console.log(`${' '.repeat(node.depth)}${node.title} (${node.path})`)
302
+ })
303
+
304
+ // Output:
305
+ // Getting Started (getting-started)
306
+ // Installation (getting-started/installation)
307
+ // Configuration (getting-started/configuration)
308
+ // Guides (guides)
309
+ // Custom Plugins (guides/custom-plugins)
310
+ ```
311
+
312
+ ---
313
+
314
+ ### buildBreadcrumbs
315
+
316
+ Build a breadcrumb trail for a given path.
317
+
318
+ ```typescript
319
+ function buildBreadcrumbs(manifest: DocsPackageManifest, slugPath: string): BreadcrumbItem[]
320
+ ```
321
+
322
+ **Returns:** Array of `BreadcrumbItem`
323
+
324
+ ```typescript
325
+ interface BreadcrumbItem {
326
+ title: string // Display title
327
+ slug: string // URL slug
328
+ path: string // Full path from root
329
+ }
330
+ ```
331
+
332
+ **Example:**
333
+
334
+ ```typescript
335
+ const breadcrumbs = buildBreadcrumbs(manifest, 'guides/custom-plugins')
336
+ // [
337
+ // { title: 'Guides', slug: 'guides', path: 'guides' },
338
+ // { title: 'Custom Plugins', slug: 'custom-plugins', path: 'guides/custom-plugins' }
339
+ // ]
340
+ ```
341
+
342
+ ---
343
+
344
+ ### getLeafNodes
345
+
346
+ Get all nodes that have files (actual pages).
347
+
348
+ ```typescript
349
+ function getLeafNodes(manifest: DocsPackageManifest): FlatNavigationNode[]
350
+ ```
351
+
352
+ **Returns:** Array of `FlatNavigationNode` with `file` property
353
+
354
+ **Example:**
355
+
356
+ ```typescript
357
+ const pages = getLeafNodes(manifest)
358
+ console.log(`Found ${pages.length} pages`)
359
+ pages.forEach((page) => {
360
+ console.log(`${page.title}: ${page.file}`)
361
+ })
362
+ ```
363
+
364
+ ---
365
+
366
+ ### getPrevNextNodes
367
+
368
+ Get the previous and next navigation nodes relative to a path.
369
+
370
+ ```typescript
371
+ function getPrevNextNodes(
372
+ manifest: DocsPackageManifest,
373
+ slugPath: string,
374
+ ): { prev?: FlatNavigationNode; next?: FlatNavigationNode }
375
+ ```
376
+
377
+ **Returns:** Object with optional `prev` and `next` nodes
378
+
379
+ **Example:**
380
+
381
+ ```typescript
382
+ const { prev, next } = getPrevNextNodes(manifest, 'getting-started/configuration')
383
+
384
+ if (prev) {
385
+ console.log(`Previous: ${prev.title}`) // "Installation"
386
+ }
387
+ if (next) {
388
+ console.log(`Next: ${next.title}`) // "Custom Plugins"
389
+ }
390
+ ```
391
+
392
+ ---
393
+
394
+ ### isNodeActive
395
+
396
+ Check if a navigation node or any of its children matches a path.
397
+
398
+ ```typescript
399
+ function isNodeActive(node: NavigationNode, currentPath: string): boolean
400
+ ```
401
+
402
+ Useful for determining if a nav section should be expanded.
403
+
404
+ **Example:**
405
+
406
+ ```typescript
407
+ const gettingStarted = manifest.navigation[0]
408
+ const isActive = isNodeActive(gettingStarted, 'getting-started/installation')
409
+ // true - because "installation" is a child of "getting-started"
410
+ ```
411
+
412
+ ---
413
+
414
+ ### getNodesAtDepth
415
+
416
+ Get all navigation nodes at a specific depth level.
417
+
418
+ ```typescript
419
+ function getNodesAtDepth(manifest: DocsPackageManifest, depth: number): FlatNavigationNode[]
420
+ ```
421
+
422
+ **Parameters:**
423
+
424
+ - `manifest` - The docs package manifest
425
+ - `depth` - Depth level (0 = root level)
426
+
427
+ **Example:**
428
+
429
+ ```typescript
430
+ const topLevel = getNodesAtDepth(manifest, 0)
431
+ // Returns: Getting Started, Guides, Reference
432
+
433
+ const secondLevel = getNodesAtDepth(manifest, 1)
434
+ // Returns: Installation, Configuration, Custom Plugins, etc.
435
+ ```
436
+
437
+ ---
438
+
439
+ ### getAllFilePaths
440
+
441
+ Extract all file paths from the manifest navigation.
442
+
443
+ ```typescript
444
+ function getAllFilePaths(manifest: DocsPackageManifest): string[]
445
+ ```
446
+
447
+ **Returns:** Array of all file paths in the navigation
448
+
449
+ **Example:**
450
+
451
+ ```typescript
452
+ const files = getAllFilePaths(manifest)
453
+ // [
454
+ // '/path/to/docs/getting-started/installation.mdx',
455
+ // '/path/to/docs/getting-started/configuration.mdx',
456
+ // '/path/to/docs/guides/custom-plugins.mdx',
457
+ // ...
458
+ // ]
459
+ ```
460
+
461
+ ---
462
+
463
+ ## Error Classes
464
+
465
+ ### ManifestValidationError
466
+
467
+ Thrown when manifest validation fails.
468
+
469
+ ```typescript
470
+ class ManifestValidationError extends Error {
471
+ readonly issues: string[]
472
+ }
473
+ ```
474
+
475
+ **Properties:**
476
+
477
+ - `issues` - Array of human-readable validation error messages
478
+
479
+ **Example:**
480
+
481
+ ```typescript
482
+ try {
483
+ validateManifest({ id: 'test' }) // Missing required fields
484
+ } catch (error) {
485
+ if (error instanceof ManifestValidationError) {
486
+ error.issues.forEach((issue) => console.error(issue))
487
+ // "name: Package name is required"
488
+ // "version: Version must be valid semver"
489
+ // etc.
490
+ }
491
+ }
492
+ ```
493
+
494
+ ---
495
+
496
+ ## Zod Schemas
497
+
498
+ All types have corresponding Zod schemas for runtime validation:
499
+
500
+ ```typescript
501
+ import {
502
+ DocsPackageManifestSchema,
503
+ NavigationNodeSchema,
504
+ SearchConfigSchema,
505
+ GitHubConfigSchema,
506
+ VendureVersionSchema,
507
+ FlatNavigationNodeSchema,
508
+ BreadcrumbItemSchema,
509
+ } from '@vendure-io/docs-provider'
510
+
511
+ // Use with Zod's parse method
512
+ const result = DocsPackageManifestSchema.safeParse(rawData)
513
+ if (result.success) {
514
+ const manifest = result.data
515
+ } else {
516
+ console.error(result.error.issues)
517
+ }
518
+ ```
519
+
520
+ These schemas are useful when you need fine-grained control over validation or want to integrate with other Zod-based validation workflows.