@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,364 @@
1
+ # Frontmatter Reference
2
+
3
+ Every MDX documentation file must include YAML frontmatter at the top of the file. This document describes all available frontmatter fields and how to use them.
4
+
5
+ ## Basic Structure
6
+
7
+ Frontmatter is enclosed between triple dashes (`---`) at the start of the file:
8
+
9
+ ```mdx
10
+ ---
11
+ title: Page Title
12
+ description: A brief description of the page
13
+ keywords:
14
+ - keyword1
15
+ - keyword2
16
+ ---
17
+
18
+ # Page Title
19
+
20
+ Your content here...
21
+ ```
22
+
23
+ ## DocPageMeta Schema
24
+
25
+ ```typescript
26
+ interface DocPageMeta {
27
+ title: string
28
+ description?: string
29
+ keywords?: string[]
30
+ sidebarLabel?: string
31
+ hidden?: boolean
32
+ }
33
+ ```
34
+
35
+ ## Required Fields
36
+
37
+ ### title
38
+
39
+ **Type:** `string` (required)
40
+
41
+ The page title. This is used for:
42
+
43
+ - The `<title>` HTML element
44
+ - Navigation display (unless overridden by `sidebarLabel`)
45
+ - Search indexing
46
+ - Open Graph metadata
47
+
48
+ ```yaml
49
+ ---
50
+ title: Getting Started with My Plugin
51
+ ---
52
+ ```
53
+
54
+ **Validation:** Must be a non-empty string.
55
+
56
+ ## Optional Fields
57
+
58
+ ### description
59
+
60
+ **Type:** `string` (optional)
61
+
62
+ A brief description of the page content. Used for:
63
+
64
+ - Meta description tag for SEO
65
+ - Search result snippets
66
+ - Social media previews (Open Graph)
67
+
68
+ ```yaml
69
+ ---
70
+ title: Installation Guide
71
+ description: Learn how to install and configure My Plugin in your Vendure project
72
+ ---
73
+ ```
74
+
75
+ **Best practices:**
76
+
77
+ - Keep descriptions between 120-160 characters
78
+ - Include relevant keywords naturally
79
+ - Make it compelling for search results
80
+
81
+ ### keywords
82
+
83
+ **Type:** `string[]` (optional)
84
+
85
+ An array of keywords for search indexing. These improve search relevance for specific terms.
86
+
87
+ ```yaml
88
+ ---
89
+ title: Custom Payment Integration
90
+ keywords:
91
+ - payment
92
+ - stripe
93
+ - checkout
94
+ - payment-provider
95
+ ---
96
+ ```
97
+
98
+ **Best practices:**
99
+
100
+ - Use 3-8 relevant keywords
101
+ - Include variations users might search for
102
+ - Don't duplicate words already in the title
103
+
104
+ ### sidebarLabel
105
+
106
+ **Type:** `string` (optional)
107
+
108
+ An alternative label to display in the sidebar navigation instead of the full title. Useful when the page title is long but you want a shorter navigation label.
109
+
110
+ ```yaml
111
+ ---
112
+ title: Comprehensive Guide to Payment Provider Integration
113
+ sidebarLabel: Payment Providers
114
+ ---
115
+ ```
116
+
117
+ ### hidden
118
+
119
+ **Type:** `boolean` (optional, default: `false`)
120
+
121
+ When set to `true`, the page will be excluded from:
122
+
123
+ - Sidebar navigation
124
+ - Search results
125
+ - Sitemap generation
126
+
127
+ The page is still accessible via direct URL.
128
+
129
+ ```yaml
130
+ ---
131
+ title: Internal Testing Page
132
+ hidden: true
133
+ ---
134
+ ```
135
+
136
+ **Use cases:**
137
+
138
+ - Draft content not ready for publication
139
+ - Internal documentation
140
+ - Legacy pages being phased out
141
+
142
+ ## Complete Example
143
+
144
+ ```yaml
145
+ ---
146
+ title: Building Custom Payment Providers
147
+ description: A comprehensive guide to creating custom payment integrations for your Vendure storefront
148
+ keywords:
149
+ - payment
150
+ - integration
151
+ - custom-provider
152
+ - stripe
153
+ - paypal
154
+ sidebarLabel: Custom Payments
155
+ hidden: false
156
+ ---
157
+ ```
158
+
159
+ ## Utility Functions
160
+
161
+ ### parseFrontmatter
162
+
163
+ Parse MDX content and extract validated frontmatter.
164
+
165
+ ```typescript
166
+ import { parseFrontmatter } from '@vendure-io/docs-provider'
167
+
168
+ const mdxContent = `---
169
+ title: My Page
170
+ description: Page description
171
+ ---
172
+
173
+ # Content here
174
+ `
175
+
176
+ const { meta, content } = parseFrontmatter(mdxContent)
177
+ console.log(meta.title) // "My Page"
178
+ console.log(meta.description) // "Page description"
179
+ console.log(content) // "# Content here"
180
+ ```
181
+
182
+ **Parameters:**
183
+
184
+ - `rawContent: string` - The raw MDX file content including frontmatter
185
+ - `filePath?: string` - Optional file path for better error messages
186
+
187
+ **Returns:** `ParsedFrontmatter`
188
+
189
+ ```typescript
190
+ interface ParsedFrontmatter {
191
+ meta: DocPageMeta
192
+ content: string
193
+ }
194
+ ```
195
+
196
+ **Throws:** `FrontmatterParseError` if parsing or validation fails
197
+
198
+ ---
199
+
200
+ ### validateFrontmatter
201
+
202
+ Validate frontmatter data against the schema.
203
+
204
+ ```typescript
205
+ import { validateFrontmatter } from '@vendure-io/docs-provider'
206
+
207
+ const meta = validateFrontmatter({
208
+ title: 'My Page',
209
+ description: 'Description',
210
+ keywords: ['test'],
211
+ })
212
+ ```
213
+
214
+ **Parameters:**
215
+
216
+ - `data: unknown` - Raw frontmatter data object
217
+ - `filePath?: string` - Optional file path for error messages
218
+
219
+ **Returns:** Validated `DocPageMeta`
220
+
221
+ **Throws:** `FrontmatterParseError` if validation fails
222
+
223
+ ---
224
+
225
+ ### hasFrontmatter
226
+
227
+ Check if content contains frontmatter.
228
+
229
+ ```typescript
230
+ import { hasFrontmatter } from '@vendure-io/docs-provider'
231
+
232
+ hasFrontmatter('---\ntitle: Test\n---\nContent') // true
233
+ hasFrontmatter('# Just a heading') // false
234
+ ```
235
+
236
+ Useful for quickly checking file content before attempting to parse.
237
+
238
+ ---
239
+
240
+ ### extractFrontmatterData
241
+
242
+ Extract raw frontmatter without validation. Useful for quick metadata access.
243
+
244
+ ```typescript
245
+ import { extractFrontmatterData } from '@vendure-io/docs-provider'
246
+
247
+ const data = extractFrontmatterData(mdxContent)
248
+ console.log(data.title) // Works even with custom fields
249
+ console.log(data.customField) // Preserves non-standard fields
250
+ ```
251
+
252
+ **Note:** This returns unvalidated data. Use `parseFrontmatter` or `validateFrontmatter` when you need type-safe access.
253
+
254
+ ---
255
+
256
+ ## Error Handling
257
+
258
+ ### FrontmatterParseError
259
+
260
+ Thrown when frontmatter parsing or validation fails.
261
+
262
+ ```typescript
263
+ import { FrontmatterParseError, parseFrontmatter } from '@vendure-io/docs-provider'
264
+
265
+ try {
266
+ parseFrontmatter(invalidContent, 'docs/page.mdx')
267
+ } catch (error) {
268
+ if (error instanceof FrontmatterParseError) {
269
+ console.error('Parse error:', error.message)
270
+ console.error('File:', error.filePath)
271
+ // Error message includes validation details:
272
+ // "Invalid frontmatter in docs/page.mdx:
273
+ // - title: Page title is required"
274
+ }
275
+ }
276
+ ```
277
+
278
+ **Properties:**
279
+
280
+ - `message: string` - Human-readable error message with details
281
+ - `filePath?: string` - The file path if provided
282
+ - `originalError?: unknown` - The underlying error (usually Zod validation error)
283
+
284
+ ## Common Validation Errors
285
+
286
+ ### Missing Title
287
+
288
+ ```
289
+ Invalid frontmatter in docs/page.mdx:
290
+ - title: Page title is required
291
+ ```
292
+
293
+ **Fix:** Add a non-empty `title` field.
294
+
295
+ ### Empty Title
296
+
297
+ ```
298
+ Invalid frontmatter in docs/page.mdx:
299
+ - title: String must contain at least 1 character(s)
300
+ ```
301
+
302
+ **Fix:** Provide a meaningful title string.
303
+
304
+ ### Invalid Keywords Type
305
+
306
+ ```
307
+ Invalid frontmatter in docs/page.mdx:
308
+ - keywords: Expected array, received string
309
+ ```
310
+
311
+ **Fix:** Use array syntax for keywords:
312
+
313
+ ```yaml
314
+ # Wrong
315
+ keywords: single-keyword
316
+
317
+ # Correct
318
+ keywords:
319
+ - single-keyword
320
+ ```
321
+
322
+ ### Invalid Hidden Type
323
+
324
+ ```
325
+ Invalid frontmatter in docs/page.mdx:
326
+ - hidden: Expected boolean, received string
327
+ ```
328
+
329
+ **Fix:** Use boolean values without quotes:
330
+
331
+ ```yaml
332
+ # Wrong
333
+ hidden: 'true'
334
+
335
+ # Correct
336
+ hidden: true
337
+ ```
338
+
339
+ ## Zod Schema
340
+
341
+ The frontmatter is validated using this Zod schema:
342
+
343
+ ```typescript
344
+ import { z } from 'zod'
345
+
346
+ const DocPageMetaSchema = z.object({
347
+ title: z.string().min(1, 'Page title is required'),
348
+ description: z.string().optional(),
349
+ keywords: z.array(z.string()).optional(),
350
+ sidebarLabel: z.string().optional(),
351
+ hidden: z.boolean().optional(),
352
+ })
353
+ ```
354
+
355
+ You can import and use this schema directly:
356
+
357
+ ```typescript
358
+ import { DocPageMetaSchema } from '@vendure-io/docs-provider'
359
+
360
+ const result = DocPageMetaSchema.safeParse(data)
361
+ if (!result.success) {
362
+ console.error(result.error.issues)
363
+ }
364
+ ```
@@ -0,0 +1,156 @@
1
+ # Getting Started
2
+
3
+ `@vendure-io/docs-provider` is a contract library that enables you to create documentation packages for the [Vendure documentation website](https://docs.vendure.io). It provides TypeScript types, Zod schemas for validation, and utility functions for building and navigating documentation structures.
4
+
5
+ ## Overview
6
+
7
+ The Vendure documentation system uses a **package-based architecture** where documentation content is distributed as separate npm packages. Each package contains:
8
+
9
+ - A **manifest** describing the package metadata and navigation structure
10
+ - **MDX files** containing the actual documentation content
11
+ - **Frontmatter** metadata for each page
12
+
13
+ This approach allows:
14
+
15
+ - Independent versioning of documentation per package
16
+ - Decentralized documentation authoring
17
+ - Type-safe contracts between docs packages and the docs application
18
+
19
+ ## Installation
20
+
21
+ ```bash
22
+ npm install @vendure-io/docs-provider
23
+ # or
24
+ bun add @vendure-io/docs-provider
25
+ # or
26
+ yarn add @vendure-io/docs-provider
27
+ # or
28
+ pnpm add @vendure-io/docs-provider
29
+ ```
30
+
31
+ ## Core Concepts
32
+
33
+ ### Manifest
34
+
35
+ The manifest is the central configuration file for your documentation package. It defines:
36
+
37
+ - Package identity (`id`, `name`, `version`)
38
+ - Target Vendure version (`vendureVersion`)
39
+ - Navigation tree structure
40
+ - Optional search and GitHub configuration
41
+
42
+ ```typescript
43
+ import type { DocsPackageManifest } from '@vendure-io/docs-provider'
44
+
45
+ export const manifest: DocsPackageManifest = {
46
+ id: 'my-plugin',
47
+ name: 'My Plugin Documentation',
48
+ version: '1.0.0',
49
+ vendureVersion: 'v3',
50
+ navigation: [
51
+ // ... navigation structure
52
+ ],
53
+ }
54
+ ```
55
+
56
+ ### Navigation Nodes
57
+
58
+ Navigation is defined as a tree of nodes. Each node has a `title` and `slug`. Leaf nodes (actual pages) have a `file` property pointing to the MDX content.
59
+
60
+ ```typescript
61
+ {
62
+ title: 'Getting Started',
63
+ slug: 'getting-started',
64
+ children: [
65
+ {
66
+ title: 'Installation',
67
+ slug: 'installation',
68
+ file: 'docs/getting-started/installation.mdx',
69
+ },
70
+ ],
71
+ }
72
+ ```
73
+
74
+ ### Frontmatter
75
+
76
+ Each MDX file must include YAML frontmatter with at least a `title`:
77
+
78
+ ```mdx
79
+ ---
80
+ title: Installation Guide
81
+ description: Learn how to install and configure the plugin
82
+ keywords:
83
+ - install
84
+ - setup
85
+ ---
86
+
87
+ # Installation Guide
88
+
89
+ Your content here...
90
+ ```
91
+
92
+ ## Quick Example
93
+
94
+ Here's a minimal docs package structure:
95
+
96
+ ```
97
+ my-docs-package/
98
+ ├── src/
99
+ │ ├── index.ts # Exports the manifest
100
+ │ └── manifest.ts # Manifest definition
101
+ ├── docs/
102
+ │ └── getting-started.mdx
103
+ ├── package.json
104
+ └── tsconfig.json
105
+ ```
106
+
107
+ **`src/manifest.ts`**:
108
+
109
+ ```typescript
110
+ import type { DocsPackageManifest } from '@vendure-io/docs-provider'
111
+ import { dirname, join } from 'path'
112
+ import { fileURLToPath } from 'url'
113
+
114
+ const packageRoot = dirname(dirname(fileURLToPath(import.meta.url)))
115
+ const file = (relativePath: string) => join(packageRoot, relativePath)
116
+
117
+ export const manifest: DocsPackageManifest = {
118
+ id: 'my-plugin',
119
+ name: 'My Plugin',
120
+ version: '1.0.0',
121
+ vendureVersion: 'v3',
122
+ navigation: [
123
+ {
124
+ title: 'Getting Started',
125
+ slug: 'getting-started',
126
+ file: file('docs/getting-started.mdx'),
127
+ },
128
+ ],
129
+ }
130
+ ```
131
+
132
+ **`src/index.ts`**:
133
+
134
+ ```typescript
135
+ export { manifest } from './manifest'
136
+ ```
137
+
138
+ **`docs/getting-started.mdx`**:
139
+
140
+ ```mdx
141
+ ---
142
+ title: Getting Started
143
+ description: Quick start guide for My Plugin
144
+ ---
145
+
146
+ # Getting Started
147
+
148
+ Welcome to My Plugin documentation!
149
+ ```
150
+
151
+ ## Next Steps
152
+
153
+ - [Creating a Docs Package](./creating-a-docs-package.md) - Complete guide to building a documentation package
154
+ - [Manifest Reference](./manifest-reference.md) - Full API documentation for manifest configuration
155
+ - [Frontmatter Reference](./frontmatter-reference.md) - All available frontmatter options
156
+ - [Publishing](./publishing.md) - How to publish and integrate with vendure.io