digital-products 2.0.1
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/.turbo/turbo-build.log +5 -0
- package/CHANGELOG.md +9 -0
- package/README.md +535 -0
- package/dist/api.d.ts +99 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/api.js +129 -0
- package/dist/api.js.map +1 -0
- package/dist/app.d.ts +79 -0
- package/dist/app.d.ts.map +1 -0
- package/dist/app.js +107 -0
- package/dist/app.js.map +1 -0
- package/dist/content.d.ts +58 -0
- package/dist/content.d.ts.map +1 -0
- package/dist/content.js +78 -0
- package/dist/content.js.map +1 -0
- package/dist/data.d.ts +67 -0
- package/dist/data.d.ts.map +1 -0
- package/dist/data.js +107 -0
- package/dist/data.js.map +1 -0
- package/dist/dataset.d.ts +32 -0
- package/dist/dataset.d.ts.map +1 -0
- package/dist/dataset.js +50 -0
- package/dist/dataset.js.map +1 -0
- package/dist/entities/ai.d.ts +53 -0
- package/dist/entities/ai.d.ts.map +1 -0
- package/dist/entities/ai.js +859 -0
- package/dist/entities/ai.js.map +1 -0
- package/dist/entities/content.d.ts +52 -0
- package/dist/entities/content.d.ts.map +1 -0
- package/dist/entities/content.js +784 -0
- package/dist/entities/content.js.map +1 -0
- package/dist/entities/index.d.ts +112 -0
- package/dist/entities/index.d.ts.map +1 -0
- package/dist/entities/index.js +89 -0
- package/dist/entities/index.js.map +1 -0
- package/dist/entities/interfaces.d.ts +67 -0
- package/dist/entities/interfaces.d.ts.map +1 -0
- package/dist/entities/interfaces.js +930 -0
- package/dist/entities/interfaces.js.map +1 -0
- package/dist/entities/lifecycle.d.ts +51 -0
- package/dist/entities/lifecycle.d.ts.map +1 -0
- package/dist/entities/lifecycle.js +804 -0
- package/dist/entities/lifecycle.js.map +1 -0
- package/dist/entities/products.d.ts +53 -0
- package/dist/entities/products.d.ts.map +1 -0
- package/dist/entities/products.js +798 -0
- package/dist/entities/products.js.map +1 -0
- package/dist/entities/web.d.ts +44 -0
- package/dist/entities/web.d.ts.map +1 -0
- package/dist/entities/web.js +658 -0
- package/dist/entities/web.js.map +1 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +36 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp.d.ts +101 -0
- package/dist/mcp.d.ts.map +1 -0
- package/dist/mcp.js +140 -0
- package/dist/mcp.js.map +1 -0
- package/dist/product.d.ts +37 -0
- package/dist/product.d.ts.map +1 -0
- package/dist/product.js +54 -0
- package/dist/product.js.map +1 -0
- package/dist/registry.d.ts +9 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +32 -0
- package/dist/registry.js.map +1 -0
- package/dist/sdk.d.ts +99 -0
- package/dist/sdk.d.ts.map +1 -0
- package/dist/sdk.js +128 -0
- package/dist/sdk.js.map +1 -0
- package/dist/site.d.ts +85 -0
- package/dist/site.d.ts.map +1 -0
- package/dist/site.js +113 -0
- package/dist/site.js.map +1 -0
- package/dist/types.d.ts +528 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/example.ts +236 -0
- package/package.json +35 -0
- package/src/api.ts +140 -0
- package/src/app.ts +117 -0
- package/src/content.ts +82 -0
- package/src/data.ts +129 -0
- package/src/dataset.ts +53 -0
- package/src/entities/ai.ts +932 -0
- package/src/entities/content.ts +851 -0
- package/src/entities/index.ts +156 -0
- package/src/entities/interfaces.ts +1017 -0
- package/src/entities/lifecycle.ts +872 -0
- package/src/entities/products.ts +867 -0
- package/src/entities/web.ts +719 -0
- package/src/index.ts +55 -0
- package/src/mcp.ts +163 -0
- package/src/product.ts +59 -0
- package/src/registry.ts +41 -0
- package/src/sdk.ts +148 -0
- package/src/site.ts +127 -0
- package/src/types.ts +558 -0
- package/test/api.test.ts +247 -0
- package/test/app.test.ts +220 -0
- package/test/content.test.ts +171 -0
- package/test/data.test.ts +201 -0
- package/test/dataset.test.ts +181 -0
- package/test/mcp.test.ts +230 -0
- package/test/product.test.ts +200 -0
- package/test/sdk.test.ts +236 -0
- package/test/site.test.ts +245 -0
- package/tsconfig.json +9 -0
package/src/index.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* digital-products - Primitives for defining and building digital products
|
|
3
|
+
*
|
|
4
|
+
* This package provides primitives for defining digital products:
|
|
5
|
+
* - Apps: Interactive user-facing applications
|
|
6
|
+
* - APIs: Programmatic interfaces
|
|
7
|
+
* - Content: Text/media content with schemas
|
|
8
|
+
* - Data: Structured data definitions
|
|
9
|
+
* - Datasets: Curated data collections
|
|
10
|
+
* - Sites: Websites and documentation
|
|
11
|
+
* - MCPs: Model Context Protocol servers
|
|
12
|
+
* - SDKs: Software development kits
|
|
13
|
+
*
|
|
14
|
+
* @packageDocumentation
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
// Export all types
|
|
18
|
+
export * from './types.js'
|
|
19
|
+
|
|
20
|
+
// Export entity definitions (Nouns) as namespace to avoid conflicts with types
|
|
21
|
+
export * as Nouns from './entities/index.js'
|
|
22
|
+
|
|
23
|
+
// Also export individual entity collections for convenience
|
|
24
|
+
export {
|
|
25
|
+
AllDigitalProductEntities,
|
|
26
|
+
DigitalProductEntityCategories,
|
|
27
|
+
Entities,
|
|
28
|
+
// Category exports
|
|
29
|
+
ProductEntities,
|
|
30
|
+
ProductCategories,
|
|
31
|
+
InterfaceEntities,
|
|
32
|
+
InterfaceCategories,
|
|
33
|
+
ContentEntities,
|
|
34
|
+
ContentCategories,
|
|
35
|
+
WebEntities,
|
|
36
|
+
WebCategories,
|
|
37
|
+
AIEntities,
|
|
38
|
+
AICategories,
|
|
39
|
+
LifecycleEntities,
|
|
40
|
+
LifecycleCategories,
|
|
41
|
+
} from './entities/index.js'
|
|
42
|
+
|
|
43
|
+
// Export registry
|
|
44
|
+
export { registry } from './registry.js'
|
|
45
|
+
|
|
46
|
+
// Export product constructors
|
|
47
|
+
export { Product, createProduct, registerProduct } from './product.js'
|
|
48
|
+
export { App, Route, State, Auth } from './app.js'
|
|
49
|
+
export { API, Endpoint, APIAuth, RateLimit } from './api.js'
|
|
50
|
+
export { Content, Workflow } from './content.js'
|
|
51
|
+
export { Data, Index, Relationship, Validate } from './data.js'
|
|
52
|
+
export { Dataset } from './dataset.js'
|
|
53
|
+
export { Site, Nav, SEO, Analytics } from './site.js'
|
|
54
|
+
export { MCP, Tool, Resource, Prompt, MCPConfig } from './mcp.js'
|
|
55
|
+
export { SDK, Export, Example } from './sdk.js'
|
package/src/mcp.ts
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP() - Define a Model Context Protocol server
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { MCPDefinition, MCPTool, MCPResource, MCPPrompt, MCPConfig } from './types.js'
|
|
6
|
+
import type { SimpleSchema } from 'ai-functions'
|
|
7
|
+
import { registerProduct } from './product.js'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Create an MCP server definition
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* const mcpServer = MCP({
|
|
15
|
+
* id: 'my-mcp',
|
|
16
|
+
* name: 'My MCP Server',
|
|
17
|
+
* description: 'Custom MCP server for AI tools',
|
|
18
|
+
* version: '1.0.0',
|
|
19
|
+
* transport: 'stdio',
|
|
20
|
+
* tools: [
|
|
21
|
+
* Tool('searchFiles', 'Search for files in the project', {
|
|
22
|
+
* query: 'Search query',
|
|
23
|
+
* path: 'Directory to search in',
|
|
24
|
+
* }),
|
|
25
|
+
* Tool('readFile', 'Read file contents', {
|
|
26
|
+
* path: 'File path to read',
|
|
27
|
+
* }),
|
|
28
|
+
* ],
|
|
29
|
+
* resources: [
|
|
30
|
+
* Resource('file://', 'Project Files', 'Access to project files'),
|
|
31
|
+
* ],
|
|
32
|
+
* prompts: [
|
|
33
|
+
* Prompt('codeReview', 'Review code for best practices',
|
|
34
|
+
* 'Review the following code:\n\n{{code}}'),
|
|
35
|
+
* ],
|
|
36
|
+
* })
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export function MCP(config: Omit<MCPDefinition, 'type'>): MCPDefinition {
|
|
40
|
+
const mcp: MCPDefinition = {
|
|
41
|
+
type: 'mcp',
|
|
42
|
+
id: config.id,
|
|
43
|
+
name: config.name,
|
|
44
|
+
description: config.description,
|
|
45
|
+
version: config.version,
|
|
46
|
+
transport: config.transport,
|
|
47
|
+
tools: config.tools,
|
|
48
|
+
resources: config.resources,
|
|
49
|
+
prompts: config.prompts,
|
|
50
|
+
config: config.config,
|
|
51
|
+
metadata: config.metadata,
|
|
52
|
+
tags: config.tags,
|
|
53
|
+
status: config.status || 'active',
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return registerProduct(mcp)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Helper to create an MCP tool
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```ts
|
|
64
|
+
* const tool = Tool(
|
|
65
|
+
* 'searchCode',
|
|
66
|
+
* 'Search code using regex',
|
|
67
|
+
* {
|
|
68
|
+
* pattern: 'Regex pattern to search for',
|
|
69
|
+
* path: 'Directory to search in',
|
|
70
|
+
* },
|
|
71
|
+
* async (input) => {
|
|
72
|
+
* // Tool implementation
|
|
73
|
+
* return { matches: [] }
|
|
74
|
+
* }
|
|
75
|
+
* )
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
export function Tool(
|
|
79
|
+
name: string,
|
|
80
|
+
description: string,
|
|
81
|
+
inputSchema: SimpleSchema,
|
|
82
|
+
handler?: (input: unknown) => Promise<unknown>
|
|
83
|
+
): MCPTool {
|
|
84
|
+
return {
|
|
85
|
+
name,
|
|
86
|
+
description,
|
|
87
|
+
inputSchema,
|
|
88
|
+
handler,
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Helper to create an MCP resource
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```ts
|
|
97
|
+
* const resource = Resource(
|
|
98
|
+
* 'file://project',
|
|
99
|
+
* 'Project Files',
|
|
100
|
+
* 'Access to all project files',
|
|
101
|
+
* 'application/json'
|
|
102
|
+
* )
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
export function Resource(
|
|
106
|
+
uri: string,
|
|
107
|
+
name: string,
|
|
108
|
+
description: string,
|
|
109
|
+
mimeType?: string
|
|
110
|
+
): MCPResource {
|
|
111
|
+
return {
|
|
112
|
+
uri,
|
|
113
|
+
name,
|
|
114
|
+
description,
|
|
115
|
+
mimeType,
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Helper to create an MCP prompt
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```ts
|
|
124
|
+
* const prompt = Prompt(
|
|
125
|
+
* 'summarize',
|
|
126
|
+
* 'Summarize text',
|
|
127
|
+
* 'Summarize the following:\n\n{{text}}',
|
|
128
|
+
* { text: 'Text to summarize' }
|
|
129
|
+
* )
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
export function Prompt(
|
|
133
|
+
name: string,
|
|
134
|
+
description: string,
|
|
135
|
+
template: string,
|
|
136
|
+
args?: SimpleSchema
|
|
137
|
+
): MCPPrompt {
|
|
138
|
+
return {
|
|
139
|
+
name,
|
|
140
|
+
description,
|
|
141
|
+
template,
|
|
142
|
+
arguments: args,
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Helper to configure MCP server
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* ```ts
|
|
151
|
+
* const config = MCPConfig({
|
|
152
|
+
* port: 3000,
|
|
153
|
+
* host: 'localhost',
|
|
154
|
+
* auth: {
|
|
155
|
+
* type: 'bearer',
|
|
156
|
+
* token: process.env.MCP_TOKEN,
|
|
157
|
+
* },
|
|
158
|
+
* })
|
|
159
|
+
* ```
|
|
160
|
+
*/
|
|
161
|
+
export function MCPConfig(config: MCPConfig): MCPConfig {
|
|
162
|
+
return config
|
|
163
|
+
}
|
package/src/product.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic Product() constructor
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { DigitalProduct, ProductDefinition } from './types.js'
|
|
6
|
+
import { registry } from './registry.js'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Create a generic digital product definition
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* const product = Product({
|
|
14
|
+
* id: 'my-product',
|
|
15
|
+
* name: 'My Product',
|
|
16
|
+
* description: 'A digital product',
|
|
17
|
+
* version: '1.0.0',
|
|
18
|
+
* })
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export function Product(config: Omit<DigitalProduct, 'type'>): DigitalProduct {
|
|
22
|
+
const product: DigitalProduct = {
|
|
23
|
+
id: config.id,
|
|
24
|
+
name: config.name,
|
|
25
|
+
description: config.description,
|
|
26
|
+
version: config.version,
|
|
27
|
+
metadata: config.metadata,
|
|
28
|
+
tags: config.tags,
|
|
29
|
+
status: config.status || 'active',
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return product
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Create and register a product in one step
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* const product = createProduct({
|
|
41
|
+
* id: 'my-product',
|
|
42
|
+
* name: 'My Product',
|
|
43
|
+
* description: 'A digital product',
|
|
44
|
+
* version: '1.0.0',
|
|
45
|
+
* })
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export function createProduct(config: Omit<DigitalProduct, 'type'>): DigitalProduct {
|
|
49
|
+
const product = Product(config)
|
|
50
|
+
return product
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Create and register any product definition
|
|
55
|
+
*/
|
|
56
|
+
export function registerProduct<T extends ProductDefinition>(product: T): T {
|
|
57
|
+
registry.register(product)
|
|
58
|
+
return product
|
|
59
|
+
}
|
package/src/registry.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Product registry implementation
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { ProductDefinition, ProductRegistry } from './types.js'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* In-memory product registry
|
|
9
|
+
*/
|
|
10
|
+
class InMemoryProductRegistry implements ProductRegistry {
|
|
11
|
+
private products = new Map<string, ProductDefinition>()
|
|
12
|
+
|
|
13
|
+
register(product: ProductDefinition): void {
|
|
14
|
+
this.products.set(product.id, product)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
get(id: string): ProductDefinition | undefined {
|
|
18
|
+
return this.products.get(id)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
list(): ProductDefinition[] {
|
|
22
|
+
return Array.from(this.products.values())
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
listByType<T extends ProductDefinition['type']>(type: T): Extract<ProductDefinition, { type: T }>[] {
|
|
26
|
+
return this.list().filter((p) => p.type === type) as Extract<ProductDefinition, { type: T }>[]
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
remove(id: string): boolean {
|
|
30
|
+
return this.products.delete(id)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
clear(): void {
|
|
34
|
+
this.products.clear()
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Global product registry instance
|
|
40
|
+
*/
|
|
41
|
+
export const registry: ProductRegistry = new InMemoryProductRegistry()
|
package/src/sdk.ts
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SDK() - Define a software development kit
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { SDKDefinition, SDKExport, SDKExample } from './types.js'
|
|
6
|
+
import type { SimpleSchema } from 'ai-functions'
|
|
7
|
+
import { registerProduct } from './product.js'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Create an SDK definition
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* const mySDK = SDK({
|
|
15
|
+
* id: 'my-sdk',
|
|
16
|
+
* name: 'My SDK',
|
|
17
|
+
* description: 'JavaScript SDK for My API',
|
|
18
|
+
* version: '1.0.0',
|
|
19
|
+
* language: 'typescript',
|
|
20
|
+
* api: 'my-api',
|
|
21
|
+
* exports: [
|
|
22
|
+
* Export('function', 'createClient', 'Create an API client', {
|
|
23
|
+
* parameters: {
|
|
24
|
+
* apiKey: 'API key for authentication',
|
|
25
|
+
* baseUrl: 'Optional base URL',
|
|
26
|
+
* },
|
|
27
|
+
* returns: 'API client instance',
|
|
28
|
+
* }),
|
|
29
|
+
* Export('class', 'APIClient', 'Main API client', {
|
|
30
|
+
* methods: [
|
|
31
|
+
* Export('function', 'get', 'GET request', {
|
|
32
|
+
* parameters: { path: 'Request path' },
|
|
33
|
+
* returns: 'Response data',
|
|
34
|
+
* }),
|
|
35
|
+
* Export('function', 'post', 'POST request', {
|
|
36
|
+
* parameters: { path: 'Request path', data: 'Request body' },
|
|
37
|
+
* returns: 'Response data',
|
|
38
|
+
* }),
|
|
39
|
+
* ],
|
|
40
|
+
* }),
|
|
41
|
+
* ],
|
|
42
|
+
* install: 'npm install my-sdk',
|
|
43
|
+
* examples: [
|
|
44
|
+
* Example(
|
|
45
|
+
* 'Basic Usage',
|
|
46
|
+
* 'Create a client and make a request',
|
|
47
|
+
* `import { createClient } from 'my-sdk'
|
|
48
|
+
*
|
|
49
|
+
* const client = createClient({ apiKey: 'YOUR_API_KEY' })
|
|
50
|
+
* const users = await client.get('/users')
|
|
51
|
+
* console.log(users)`
|
|
52
|
+
* ),
|
|
53
|
+
* ],
|
|
54
|
+
* })
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export function SDK(config: Omit<SDKDefinition, 'type'>): SDKDefinition {
|
|
58
|
+
const sdk: SDKDefinition = {
|
|
59
|
+
type: 'sdk',
|
|
60
|
+
id: config.id,
|
|
61
|
+
name: config.name,
|
|
62
|
+
description: config.description,
|
|
63
|
+
version: config.version,
|
|
64
|
+
language: config.language,
|
|
65
|
+
api: config.api,
|
|
66
|
+
exports: config.exports,
|
|
67
|
+
install: config.install,
|
|
68
|
+
docs: config.docs,
|
|
69
|
+
examples: config.examples,
|
|
70
|
+
metadata: config.metadata,
|
|
71
|
+
tags: config.tags,
|
|
72
|
+
status: config.status || 'active',
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return registerProduct(sdk)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Helper to create an SDK export
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```ts
|
|
83
|
+
* const fn = Export('function', 'calculateTotal', 'Calculate order total', {
|
|
84
|
+
* parameters: {
|
|
85
|
+
* items: ['Array of order items'],
|
|
86
|
+
* taxRate: 'Tax rate (number)',
|
|
87
|
+
* },
|
|
88
|
+
* returns: 'Total amount (number)',
|
|
89
|
+
* })
|
|
90
|
+
*
|
|
91
|
+
* const cls = Export('class', 'OrderManager', 'Manage orders', {
|
|
92
|
+
* methods: [
|
|
93
|
+
* Export('function', 'create', 'Create order', {
|
|
94
|
+
* parameters: { order: 'Order data' },
|
|
95
|
+
* returns: 'Created order',
|
|
96
|
+
* }),
|
|
97
|
+
* ],
|
|
98
|
+
* })
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
export function Export(
|
|
102
|
+
type: SDKExport['type'],
|
|
103
|
+
name: string,
|
|
104
|
+
description: string,
|
|
105
|
+
options?: {
|
|
106
|
+
parameters?: SimpleSchema
|
|
107
|
+
returns?: SimpleSchema
|
|
108
|
+
methods?: SDKExport[]
|
|
109
|
+
}
|
|
110
|
+
): SDKExport {
|
|
111
|
+
return {
|
|
112
|
+
type,
|
|
113
|
+
name,
|
|
114
|
+
description,
|
|
115
|
+
parameters: options?.parameters,
|
|
116
|
+
returns: options?.returns,
|
|
117
|
+
methods: options?.methods,
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Helper to create an SDK example
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```ts
|
|
126
|
+
* const example = Example(
|
|
127
|
+
* 'Authentication',
|
|
128
|
+
* 'How to authenticate with the API',
|
|
129
|
+
* `const client = createClient({
|
|
130
|
+
* apiKey: process.env.API_KEY,
|
|
131
|
+
* })`,
|
|
132
|
+
* '{ authenticated: true }'
|
|
133
|
+
* )
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
export function Example(
|
|
137
|
+
title: string,
|
|
138
|
+
description: string,
|
|
139
|
+
code: string,
|
|
140
|
+
output?: string
|
|
141
|
+
): SDKExample {
|
|
142
|
+
return {
|
|
143
|
+
title,
|
|
144
|
+
description,
|
|
145
|
+
code,
|
|
146
|
+
output,
|
|
147
|
+
}
|
|
148
|
+
}
|
package/src/site.ts
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Site() - Define a website
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { SiteDefinition, NavigationDefinition, SEOConfig, AnalyticsConfig } from './types.js'
|
|
6
|
+
import { registerProduct } from './product.js'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Create a site definition
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* const docsSite = Site({
|
|
14
|
+
* id: 'docs',
|
|
15
|
+
* name: 'Documentation Site',
|
|
16
|
+
* description: 'Product documentation',
|
|
17
|
+
* version: '1.0.0',
|
|
18
|
+
* generator: 'fumadocs',
|
|
19
|
+
* structure: {
|
|
20
|
+
* home: '/docs/index.mdx',
|
|
21
|
+
* docs: [
|
|
22
|
+
* '/docs/getting-started.mdx',
|
|
23
|
+
* '/docs/api-reference.mdx',
|
|
24
|
+
* ],
|
|
25
|
+
* },
|
|
26
|
+
* navigation: [
|
|
27
|
+
* Nav('Home', '/'),
|
|
28
|
+
* Nav('Docs', '/docs', {
|
|
29
|
+
* children: [
|
|
30
|
+
* Nav('Getting Started', '/docs/getting-started'),
|
|
31
|
+
* Nav('API Reference', '/docs/api-reference'),
|
|
32
|
+
* ],
|
|
33
|
+
* }),
|
|
34
|
+
* ],
|
|
35
|
+
* seo: {
|
|
36
|
+
* titleTemplate: '%s | My Product',
|
|
37
|
+
* description: 'Official documentation for My Product',
|
|
38
|
+
* keywords: ['docs', 'api', 'reference'],
|
|
39
|
+
* },
|
|
40
|
+
* analytics: {
|
|
41
|
+
* provider: 'plausible',
|
|
42
|
+
* id: 'docs.example.com',
|
|
43
|
+
* },
|
|
44
|
+
* })
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export function Site(config: Omit<SiteDefinition, 'type'>): SiteDefinition {
|
|
48
|
+
const site: SiteDefinition = {
|
|
49
|
+
type: 'site',
|
|
50
|
+
id: config.id,
|
|
51
|
+
name: config.name,
|
|
52
|
+
description: config.description,
|
|
53
|
+
version: config.version,
|
|
54
|
+
generator: config.generator || 'next',
|
|
55
|
+
structure: config.structure,
|
|
56
|
+
navigation: config.navigation,
|
|
57
|
+
seo: config.seo,
|
|
58
|
+
analytics: config.analytics,
|
|
59
|
+
deployment: config.deployment,
|
|
60
|
+
metadata: config.metadata,
|
|
61
|
+
tags: config.tags,
|
|
62
|
+
status: config.status || 'active',
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return registerProduct(site)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Helper to create a navigation item
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```ts
|
|
73
|
+
* const nav = Nav('Documentation', '/docs', {
|
|
74
|
+
* icon: 'book',
|
|
75
|
+
* children: [
|
|
76
|
+
* Nav('Getting Started', '/docs/getting-started'),
|
|
77
|
+
* Nav('API Reference', '/docs/api'),
|
|
78
|
+
* ],
|
|
79
|
+
* })
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
export function Nav(
|
|
83
|
+
label: string,
|
|
84
|
+
href: string,
|
|
85
|
+
options?: Omit<NavigationDefinition, 'label' | 'href'>
|
|
86
|
+
): NavigationDefinition {
|
|
87
|
+
return {
|
|
88
|
+
label,
|
|
89
|
+
href,
|
|
90
|
+
...options,
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Helper to configure SEO
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```ts
|
|
99
|
+
* const seo = SEO({
|
|
100
|
+
* titleTemplate: '%s | My Site',
|
|
101
|
+
* description: 'My awesome site',
|
|
102
|
+
* keywords: ['keyword1', 'keyword2'],
|
|
103
|
+
* ogImage: '/og-image.png',
|
|
104
|
+
* twitterCard: 'summary_large_image',
|
|
105
|
+
* })
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
export function SEO(config: SEOConfig): SEOConfig {
|
|
109
|
+
return config
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Helper to configure analytics
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```ts
|
|
117
|
+
* const analytics = Analytics('google', 'G-XXXXXXXXXX')
|
|
118
|
+
* const analytics = Analytics('plausible', 'example.com')
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
export function Analytics(
|
|
122
|
+
provider: AnalyticsConfig['provider'],
|
|
123
|
+
id: string,
|
|
124
|
+
config?: Record<string, unknown>
|
|
125
|
+
): AnalyticsConfig {
|
|
126
|
+
return { provider, id, config }
|
|
127
|
+
}
|