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.
Files changed (110) hide show
  1. package/.turbo/turbo-build.log +5 -0
  2. package/CHANGELOG.md +9 -0
  3. package/README.md +535 -0
  4. package/dist/api.d.ts +99 -0
  5. package/dist/api.d.ts.map +1 -0
  6. package/dist/api.js +129 -0
  7. package/dist/api.js.map +1 -0
  8. package/dist/app.d.ts +79 -0
  9. package/dist/app.d.ts.map +1 -0
  10. package/dist/app.js +107 -0
  11. package/dist/app.js.map +1 -0
  12. package/dist/content.d.ts +58 -0
  13. package/dist/content.d.ts.map +1 -0
  14. package/dist/content.js +78 -0
  15. package/dist/content.js.map +1 -0
  16. package/dist/data.d.ts +67 -0
  17. package/dist/data.d.ts.map +1 -0
  18. package/dist/data.js +107 -0
  19. package/dist/data.js.map +1 -0
  20. package/dist/dataset.d.ts +32 -0
  21. package/dist/dataset.d.ts.map +1 -0
  22. package/dist/dataset.js +50 -0
  23. package/dist/dataset.js.map +1 -0
  24. package/dist/entities/ai.d.ts +53 -0
  25. package/dist/entities/ai.d.ts.map +1 -0
  26. package/dist/entities/ai.js +859 -0
  27. package/dist/entities/ai.js.map +1 -0
  28. package/dist/entities/content.d.ts +52 -0
  29. package/dist/entities/content.d.ts.map +1 -0
  30. package/dist/entities/content.js +784 -0
  31. package/dist/entities/content.js.map +1 -0
  32. package/dist/entities/index.d.ts +112 -0
  33. package/dist/entities/index.d.ts.map +1 -0
  34. package/dist/entities/index.js +89 -0
  35. package/dist/entities/index.js.map +1 -0
  36. package/dist/entities/interfaces.d.ts +67 -0
  37. package/dist/entities/interfaces.d.ts.map +1 -0
  38. package/dist/entities/interfaces.js +930 -0
  39. package/dist/entities/interfaces.js.map +1 -0
  40. package/dist/entities/lifecycle.d.ts +51 -0
  41. package/dist/entities/lifecycle.d.ts.map +1 -0
  42. package/dist/entities/lifecycle.js +804 -0
  43. package/dist/entities/lifecycle.js.map +1 -0
  44. package/dist/entities/products.d.ts +53 -0
  45. package/dist/entities/products.d.ts.map +1 -0
  46. package/dist/entities/products.js +798 -0
  47. package/dist/entities/products.js.map +1 -0
  48. package/dist/entities/web.d.ts +44 -0
  49. package/dist/entities/web.d.ts.map +1 -0
  50. package/dist/entities/web.js +658 -0
  51. package/dist/entities/web.js.map +1 -0
  52. package/dist/index.d.ts +29 -0
  53. package/dist/index.d.ts.map +1 -0
  54. package/dist/index.js +36 -0
  55. package/dist/index.js.map +1 -0
  56. package/dist/mcp.d.ts +101 -0
  57. package/dist/mcp.d.ts.map +1 -0
  58. package/dist/mcp.js +140 -0
  59. package/dist/mcp.js.map +1 -0
  60. package/dist/product.d.ts +37 -0
  61. package/dist/product.d.ts.map +1 -0
  62. package/dist/product.js +54 -0
  63. package/dist/product.js.map +1 -0
  64. package/dist/registry.d.ts +9 -0
  65. package/dist/registry.d.ts.map +1 -0
  66. package/dist/registry.js +32 -0
  67. package/dist/registry.js.map +1 -0
  68. package/dist/sdk.d.ts +99 -0
  69. package/dist/sdk.d.ts.map +1 -0
  70. package/dist/sdk.js +128 -0
  71. package/dist/sdk.js.map +1 -0
  72. package/dist/site.d.ts +85 -0
  73. package/dist/site.d.ts.map +1 -0
  74. package/dist/site.js +113 -0
  75. package/dist/site.js.map +1 -0
  76. package/dist/types.d.ts +528 -0
  77. package/dist/types.d.ts.map +1 -0
  78. package/dist/types.js +5 -0
  79. package/dist/types.js.map +1 -0
  80. package/example.ts +236 -0
  81. package/package.json +35 -0
  82. package/src/api.ts +140 -0
  83. package/src/app.ts +117 -0
  84. package/src/content.ts +82 -0
  85. package/src/data.ts +129 -0
  86. package/src/dataset.ts +53 -0
  87. package/src/entities/ai.ts +932 -0
  88. package/src/entities/content.ts +851 -0
  89. package/src/entities/index.ts +156 -0
  90. package/src/entities/interfaces.ts +1017 -0
  91. package/src/entities/lifecycle.ts +872 -0
  92. package/src/entities/products.ts +867 -0
  93. package/src/entities/web.ts +719 -0
  94. package/src/index.ts +55 -0
  95. package/src/mcp.ts +163 -0
  96. package/src/product.ts +59 -0
  97. package/src/registry.ts +41 -0
  98. package/src/sdk.ts +148 -0
  99. package/src/site.ts +127 -0
  100. package/src/types.ts +558 -0
  101. package/test/api.test.ts +247 -0
  102. package/test/app.test.ts +220 -0
  103. package/test/content.test.ts +171 -0
  104. package/test/data.test.ts +201 -0
  105. package/test/dataset.test.ts +181 -0
  106. package/test/mcp.test.ts +230 -0
  107. package/test/product.test.ts +200 -0
  108. package/test/sdk.test.ts +236 -0
  109. package/test/site.test.ts +245 -0
  110. package/tsconfig.json +9 -0
package/example.ts ADDED
@@ -0,0 +1,236 @@
1
+ /**
2
+ * Example usage of digital-products primitives
3
+ */
4
+
5
+ import {
6
+ App,
7
+ Route,
8
+ State,
9
+ Auth,
10
+ API,
11
+ Endpoint,
12
+ Content,
13
+ Workflow,
14
+ Data,
15
+ Index,
16
+ Validate,
17
+ Dataset,
18
+ Site,
19
+ Nav,
20
+ SEO,
21
+ MCP,
22
+ Tool,
23
+ SDK,
24
+ Export,
25
+ Example,
26
+ registry,
27
+ } from './src/index.js'
28
+
29
+ // Example 1: Define an App
30
+ const myApp = App({
31
+ id: 'my-app',
32
+ name: 'My App',
33
+ description: 'A web application',
34
+ version: '1.0.0',
35
+ framework: 'react',
36
+ routes: [
37
+ Route('/', 'Home'),
38
+ Route('/about', 'About'),
39
+ Route('/users/:id', 'UserDetail', {
40
+ meta: { title: 'User Profile' },
41
+ }),
42
+ ],
43
+ state: State({
44
+ library: 'zustand',
45
+ schema: {
46
+ user: 'Current user object',
47
+ settings: 'App settings object',
48
+ },
49
+ persistence: {
50
+ type: 'local',
51
+ key: 'app-state',
52
+ },
53
+ }),
54
+ auth: Auth({
55
+ provider: 'clerk',
56
+ protectedRoutes: ['/dashboard', '/profile'],
57
+ }),
58
+ })
59
+
60
+ // Example 2: Define an API
61
+ const myAPI = API({
62
+ id: 'my-api',
63
+ name: 'My API',
64
+ description: 'A RESTful API',
65
+ version: '1.0.0',
66
+ style: 'rest',
67
+ baseUrl: 'https://api.example.com',
68
+ endpoints: [
69
+ Endpoint('GET', '/users', 'List all users', {
70
+ response: {
71
+ users: ['Array of user objects'],
72
+ total: 'Total count (number)',
73
+ },
74
+ }),
75
+ Endpoint('POST', '/users', 'Create a user', {
76
+ request: {
77
+ name: 'User name',
78
+ email: 'User email',
79
+ },
80
+ response: {
81
+ id: 'User ID',
82
+ name: 'User name',
83
+ email: 'User email',
84
+ },
85
+ }),
86
+ ],
87
+ auth: {
88
+ type: 'bearer',
89
+ header: 'Authorization',
90
+ },
91
+ })
92
+
93
+ // Example 3: Define Content
94
+ const blogContent = Content({
95
+ id: 'blog',
96
+ name: 'Blog Posts',
97
+ description: 'Blog content for the website',
98
+ version: '1.0.0',
99
+ format: 'mdx',
100
+ source: './content/blog',
101
+ frontmatter: {
102
+ title: 'Post title',
103
+ author: 'Author name',
104
+ date: 'Publication date (date)',
105
+ tags: ['Array of tags'],
106
+ },
107
+ workflow: Workflow({
108
+ states: ['draft', 'review', 'published'],
109
+ initialState: 'draft',
110
+ transitions: [
111
+ { from: 'draft', to: 'review', action: 'submit' },
112
+ { from: 'review', to: 'published', action: 'approve' },
113
+ { from: 'review', to: 'draft', action: 'reject' },
114
+ ],
115
+ }),
116
+ })
117
+
118
+ // Example 4: Define Data
119
+ const userData = Data({
120
+ id: 'users',
121
+ name: 'Users',
122
+ description: 'User data store',
123
+ version: '1.0.0',
124
+ schema: {
125
+ id: 'User ID',
126
+ name: 'User name',
127
+ email: 'User email',
128
+ createdAt: 'Creation timestamp (date)',
129
+ role: 'admin | user | guest',
130
+ },
131
+ provider: 'postgres',
132
+ indexes: [
133
+ Index('email_idx', ['email'], { unique: true }),
134
+ Index('role_idx', ['role']),
135
+ ],
136
+ validation: [
137
+ Validate('email', 'email', 'Must be a valid email'),
138
+ Validate('name', 'required', 'Name is required'),
139
+ ],
140
+ })
141
+
142
+ // Example 5: Define a Dataset
143
+ const movieDataset = Dataset({
144
+ id: 'movies',
145
+ name: 'Movie Database',
146
+ description: 'Comprehensive movie information dataset',
147
+ version: '2024.1',
148
+ format: 'parquet',
149
+ schema: {
150
+ id: 'Movie ID',
151
+ title: 'Movie title',
152
+ year: 'Release year (number)',
153
+ genres: ['Array of genre names'],
154
+ rating: 'Average rating (number)',
155
+ },
156
+ size: 1000000,
157
+ license: 'CC-BY-4.0',
158
+ updateFrequency: 'daily',
159
+ })
160
+
161
+ // Example 6: Define a Site
162
+ const docsSite = Site({
163
+ id: 'docs',
164
+ name: 'Documentation Site',
165
+ description: 'Product documentation',
166
+ version: '1.0.0',
167
+ generator: 'fumadocs',
168
+ navigation: [
169
+ Nav('Home', '/'),
170
+ Nav('Docs', '/docs', {
171
+ children: [
172
+ Nav('Getting Started', '/docs/getting-started'),
173
+ Nav('API Reference', '/docs/api-reference'),
174
+ ],
175
+ }),
176
+ ],
177
+ seo: SEO({
178
+ titleTemplate: '%s | My Product',
179
+ description: 'Official documentation for My Product',
180
+ keywords: ['docs', 'api', 'reference'],
181
+ }),
182
+ })
183
+
184
+ // Example 7: Define an MCP Server
185
+ const mcpServer = MCP({
186
+ id: 'my-mcp',
187
+ name: 'My MCP Server',
188
+ description: 'Custom MCP server for AI tools',
189
+ version: '1.0.0',
190
+ transport: 'stdio',
191
+ tools: [
192
+ Tool('searchFiles', 'Search for files in the project', {
193
+ query: 'Search query',
194
+ path: 'Directory to search in',
195
+ }),
196
+ Tool('readFile', 'Read file contents', {
197
+ path: 'File path to read',
198
+ }),
199
+ ],
200
+ })
201
+
202
+ // Example 8: Define an SDK
203
+ const mySDK = SDK({
204
+ id: 'my-sdk',
205
+ name: 'My SDK',
206
+ description: 'JavaScript SDK for My API',
207
+ version: '1.0.0',
208
+ language: 'typescript',
209
+ api: 'my-api',
210
+ exports: [
211
+ Export('function', 'createClient', 'Create an API client', {
212
+ parameters: {
213
+ apiKey: 'API key for authentication',
214
+ baseUrl: 'Optional base URL',
215
+ },
216
+ returns: 'API client instance',
217
+ }),
218
+ ],
219
+ install: 'npm install my-sdk',
220
+ examples: [
221
+ Example(
222
+ 'Basic Usage',
223
+ 'Create a client and make a request',
224
+ `import { createClient } from 'my-sdk'
225
+
226
+ const client = createClient({ apiKey: 'YOUR_API_KEY' })
227
+ const users = await client.get('/users')
228
+ console.log(users)`
229
+ ),
230
+ ],
231
+ })
232
+
233
+ // Access the registry
234
+ console.log('Registered products:', registry.list().map((p) => p.name))
235
+ console.log('Apps:', registry.listByType('app').map((p) => p.name))
236
+ console.log('APIs:', registry.listByType('api').map((p) => p.name))
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "digital-products",
3
+ "version": "2.0.1",
4
+ "description": "Primitives for defining and building digital products",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.js",
11
+ "types": "./dist/index.d.ts"
12
+ }
13
+ },
14
+ "scripts": {
15
+ "build": "tsc",
16
+ "dev": "tsc --watch",
17
+ "test": "vitest",
18
+ "typecheck": "tsc --noEmit",
19
+ "lint": "eslint .",
20
+ "clean": "rm -rf dist"
21
+ },
22
+ "dependencies": {
23
+ "ai-database": "workspace:*",
24
+ "ai-functions": "workspace:*",
25
+ "rpc.do": "^0.1.0"
26
+ },
27
+ "keywords": [
28
+ "products",
29
+ "apps",
30
+ "api",
31
+ "digital",
32
+ "primitives"
33
+ ],
34
+ "license": "MIT"
35
+ }
package/src/api.ts ADDED
@@ -0,0 +1,140 @@
1
+ /**
2
+ * API() - Define an API
3
+ */
4
+
5
+ import type { APIDefinition, EndpointDefinition, APIAuthConfig, RateLimitConfig } from './types.js'
6
+ import { registerProduct } from './product.js'
7
+
8
+ /**
9
+ * Create an API definition
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * const myAPI = API({
14
+ * id: 'my-api',
15
+ * name: 'My API',
16
+ * description: 'A RESTful API',
17
+ * version: '1.0.0',
18
+ * style: 'rest',
19
+ * baseUrl: 'https://api.example.com',
20
+ * endpoints: [
21
+ * Endpoint('GET', '/users', 'List all users', {
22
+ * response: {
23
+ * users: ['Array of user objects'],
24
+ * total: 'Total count (number)',
25
+ * },
26
+ * }),
27
+ * Endpoint('POST', '/users', 'Create a user', {
28
+ * request: {
29
+ * name: 'User name',
30
+ * email: 'User email',
31
+ * },
32
+ * response: {
33
+ * id: 'User ID',
34
+ * name: 'User name',
35
+ * email: 'User email',
36
+ * },
37
+ * }),
38
+ * ],
39
+ * auth: {
40
+ * type: 'bearer',
41
+ * header: 'Authorization',
42
+ * },
43
+ * rateLimit: {
44
+ * requests: 100,
45
+ * window: 60,
46
+ * },
47
+ * })
48
+ * ```
49
+ */
50
+ export function API(config: Omit<APIDefinition, 'type'>): APIDefinition {
51
+ const api: APIDefinition = {
52
+ type: 'api',
53
+ id: config.id,
54
+ name: config.name,
55
+ description: config.description,
56
+ version: config.version,
57
+ style: config.style || 'rest',
58
+ baseUrl: config.baseUrl,
59
+ endpoints: config.endpoints || [],
60
+ auth: config.auth,
61
+ rateLimit: config.rateLimit,
62
+ docsUrl: config.docsUrl,
63
+ openapi: config.openapi,
64
+ metadata: config.metadata,
65
+ tags: config.tags,
66
+ status: config.status || 'active',
67
+ }
68
+
69
+ return registerProduct(api)
70
+ }
71
+
72
+ /**
73
+ * Helper to create an endpoint definition
74
+ *
75
+ * @example
76
+ * ```ts
77
+ * const endpoint = Endpoint('GET', '/users/:id', 'Get user by ID', {
78
+ * params: { id: 'User ID' },
79
+ * response: {
80
+ * id: 'User ID',
81
+ * name: 'User name',
82
+ * email: 'User email',
83
+ * },
84
+ * auth: true,
85
+ * })
86
+ * ```
87
+ */
88
+ export function Endpoint(
89
+ method: EndpointDefinition['method'],
90
+ path: string,
91
+ description: string,
92
+ options?: Omit<EndpointDefinition, 'method' | 'path' | 'description'>
93
+ ): EndpointDefinition {
94
+ return {
95
+ method,
96
+ path,
97
+ description,
98
+ ...options,
99
+ }
100
+ }
101
+
102
+ /**
103
+ * Helper to configure API authentication
104
+ *
105
+ * @example
106
+ * ```ts
107
+ * const auth = APIAuth({
108
+ * type: 'bearer',
109
+ * header: 'Authorization',
110
+ * })
111
+ *
112
+ * const oauth = APIAuth({
113
+ * type: 'oauth2',
114
+ * oauth2: {
115
+ * authUrl: 'https://auth.example.com/authorize',
116
+ * tokenUrl: 'https://auth.example.com/token',
117
+ * scopes: ['read', 'write'],
118
+ * },
119
+ * })
120
+ * ```
121
+ */
122
+ export function APIAuth(config: APIAuthConfig): APIAuthConfig {
123
+ return config
124
+ }
125
+
126
+ /**
127
+ * Helper to configure rate limiting
128
+ *
129
+ * @example
130
+ * ```ts
131
+ * const rateLimit = RateLimit({
132
+ * requests: 100,
133
+ * window: 60, // 60 seconds
134
+ * onExceeded: 'reject',
135
+ * })
136
+ * ```
137
+ */
138
+ export function RateLimit(config: RateLimitConfig): RateLimitConfig {
139
+ return config
140
+ }
package/src/app.ts ADDED
@@ -0,0 +1,117 @@
1
+ /**
2
+ * App() - Define an application
3
+ */
4
+
5
+ import type { AppDefinition, RouteDefinition, StateDefinition, AuthConfig } from './types.js'
6
+ import { registerProduct } from './product.js'
7
+
8
+ /**
9
+ * Create an application definition
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * const myApp = App({
14
+ * id: 'my-app',
15
+ * name: 'My App',
16
+ * description: 'A web application',
17
+ * version: '1.0.0',
18
+ * framework: 'react',
19
+ * routes: [
20
+ * { path: '/', component: 'Home' },
21
+ * { path: '/about', component: 'About' },
22
+ * { path: '/users/:id', component: 'UserDetail' },
23
+ * ],
24
+ * state: {
25
+ * library: 'zustand',
26
+ * schema: {
27
+ * user: 'Current user object',
28
+ * settings: 'App settings object',
29
+ * },
30
+ * },
31
+ * auth: {
32
+ * provider: 'clerk',
33
+ * protectedRoutes: ['/dashboard', '/profile'],
34
+ * },
35
+ * })
36
+ * ```
37
+ */
38
+ export function App(config: Omit<AppDefinition, 'type'>): AppDefinition {
39
+ const app: AppDefinition = {
40
+ type: 'app',
41
+ id: config.id,
42
+ name: config.name,
43
+ description: config.description,
44
+ version: config.version,
45
+ framework: config.framework || 'react',
46
+ routes: config.routes || [],
47
+ config: config.config,
48
+ state: config.state,
49
+ auth: config.auth,
50
+ deployments: config.deployments,
51
+ metadata: config.metadata,
52
+ tags: config.tags,
53
+ status: config.status || 'active',
54
+ }
55
+
56
+ return registerProduct(app)
57
+ }
58
+
59
+ /**
60
+ * Helper to create a route definition
61
+ *
62
+ * @example
63
+ * ```ts
64
+ * const userRoute = Route('/users/:id', 'UserDetail', {
65
+ * meta: { title: 'User Profile' },
66
+ * })
67
+ * ```
68
+ */
69
+ export function Route(
70
+ path: string,
71
+ component: string,
72
+ options?: Omit<RouteDefinition, 'path' | 'component'>
73
+ ): RouteDefinition {
74
+ return {
75
+ path,
76
+ component,
77
+ ...options,
78
+ }
79
+ }
80
+
81
+ /**
82
+ * Helper to configure state management
83
+ *
84
+ * @example
85
+ * ```ts
86
+ * const state = State({
87
+ * library: 'zustand',
88
+ * schema: {
89
+ * user: 'Current user',
90
+ * settings: 'User settings',
91
+ * },
92
+ * persistence: {
93
+ * type: 'local',
94
+ * key: 'app-state',
95
+ * },
96
+ * })
97
+ * ```
98
+ */
99
+ export function State(config: StateDefinition): StateDefinition {
100
+ return config
101
+ }
102
+
103
+ /**
104
+ * Helper to configure authentication
105
+ *
106
+ * @example
107
+ * ```ts
108
+ * const auth = Auth({
109
+ * provider: 'clerk',
110
+ * protectedRoutes: ['/dashboard', '/profile'],
111
+ * roles: ['admin', 'user'],
112
+ * })
113
+ * ```
114
+ */
115
+ export function Auth(config: AuthConfig): AuthConfig {
116
+ return config
117
+ }
package/src/content.ts ADDED
@@ -0,0 +1,82 @@
1
+ /**
2
+ * Content() - Define content
3
+ */
4
+
5
+ import type { ContentDefinition, WorkflowDefinition } from './types.js'
6
+ import { registerProduct } from './product.js'
7
+
8
+ /**
9
+ * Create a content definition
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * const blogContent = Content({
14
+ * id: 'blog',
15
+ * name: 'Blog Posts',
16
+ * description: 'Blog content for the website',
17
+ * version: '1.0.0',
18
+ * format: 'mdx',
19
+ * source: './content/blog',
20
+ * frontmatter: {
21
+ * title: 'Post title',
22
+ * author: 'Author name',
23
+ * date: 'Publication date (date)',
24
+ * tags: ['Array of tags'],
25
+ * },
26
+ * categories: ['Technology', 'Business', 'Design'],
27
+ * workflow: Workflow({
28
+ * states: ['draft', 'review', 'published'],
29
+ * initialState: 'draft',
30
+ * transitions: [
31
+ * { from: 'draft', to: 'review', action: 'submit' },
32
+ * { from: 'review', to: 'published', action: 'approve' },
33
+ * { from: 'review', to: 'draft', action: 'reject' },
34
+ * ],
35
+ * }),
36
+ * })
37
+ * ```
38
+ */
39
+ export function Content(config: Omit<ContentDefinition, 'type'>): ContentDefinition {
40
+ const content: ContentDefinition = {
41
+ type: 'content',
42
+ id: config.id,
43
+ name: config.name,
44
+ description: config.description,
45
+ version: config.version,
46
+ format: config.format || 'markdown',
47
+ source: config.source,
48
+ schema: config.schema,
49
+ frontmatter: config.frontmatter,
50
+ categories: config.categories,
51
+ workflow: config.workflow,
52
+ metadata: config.metadata,
53
+ tags: config.tags,
54
+ status: config.status || 'active',
55
+ }
56
+
57
+ return registerProduct(content)
58
+ }
59
+
60
+ /**
61
+ * Helper to create a workflow definition
62
+ *
63
+ * @example
64
+ * ```ts
65
+ * const workflow = Workflow({
66
+ * states: ['draft', 'review', 'published', 'archived'],
67
+ * initialState: 'draft',
68
+ * transitions: [
69
+ * { from: 'draft', to: 'review', action: 'submit' },
70
+ * { from: 'review', to: 'published', action: 'approve' },
71
+ * { from: 'review', to: 'draft', action: 'reject' },
72
+ * { from: 'published', to: 'archived', action: 'archive' },
73
+ * ],
74
+ * approvals: [
75
+ * { state: 'review', roles: ['editor', 'admin'] },
76
+ * ],
77
+ * })
78
+ * ```
79
+ */
80
+ export function Workflow(config: WorkflowDefinition): WorkflowDefinition {
81
+ return config
82
+ }