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/CHANGELOG.md
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,535 @@
|
|
|
1
|
+
# digital-products
|
|
2
|
+
|
|
3
|
+
Primitives for defining and building digital products.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This package provides a declarative API for defining digital products - apps, APIs, content, data structures, datasets, websites, MCP servers, and SDKs. Each product type has a specialized constructor with a clean, chainable API.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install digital-products ai-functions
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## API
|
|
16
|
+
|
|
17
|
+
### Core Functions
|
|
18
|
+
|
|
19
|
+
- **`Product()`** - Define a generic digital product
|
|
20
|
+
- **`App()`** - Define an application
|
|
21
|
+
- **`API()`** - Define an API
|
|
22
|
+
- **`Content()`** - Define content
|
|
23
|
+
- **`Data()`** - Define data structures
|
|
24
|
+
- **`Dataset()`** - Define datasets
|
|
25
|
+
- **`Site()`** - Define a website
|
|
26
|
+
- **`MCP()`** - Define Model Context Protocol servers
|
|
27
|
+
- **`SDK()`** - Define software development kits
|
|
28
|
+
|
|
29
|
+
### Registry
|
|
30
|
+
|
|
31
|
+
- **`registry`** - Global product registry for storing and retrieving products
|
|
32
|
+
|
|
33
|
+
## Usage Examples
|
|
34
|
+
|
|
35
|
+
### Define an App
|
|
36
|
+
|
|
37
|
+
```typescript
|
|
38
|
+
import { App, Route, State, Auth } from 'digital-products'
|
|
39
|
+
|
|
40
|
+
const myApp = App({
|
|
41
|
+
id: 'my-app',
|
|
42
|
+
name: 'My App',
|
|
43
|
+
description: 'A web application',
|
|
44
|
+
version: '1.0.0',
|
|
45
|
+
framework: 'react',
|
|
46
|
+
routes: [
|
|
47
|
+
Route('/', 'Home'),
|
|
48
|
+
Route('/about', 'About'),
|
|
49
|
+
Route('/users/:id', 'UserDetail', {
|
|
50
|
+
meta: { title: 'User Profile' },
|
|
51
|
+
}),
|
|
52
|
+
],
|
|
53
|
+
state: State({
|
|
54
|
+
library: 'zustand',
|
|
55
|
+
schema: {
|
|
56
|
+
user: 'Current user object',
|
|
57
|
+
settings: 'App settings object',
|
|
58
|
+
},
|
|
59
|
+
persistence: {
|
|
60
|
+
type: 'local',
|
|
61
|
+
key: 'app-state',
|
|
62
|
+
},
|
|
63
|
+
}),
|
|
64
|
+
auth: Auth({
|
|
65
|
+
provider: 'clerk',
|
|
66
|
+
protectedRoutes: ['/dashboard', '/profile'],
|
|
67
|
+
}),
|
|
68
|
+
})
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Define an API
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
import { API, Endpoint, APIAuth, RateLimit } from 'digital-products'
|
|
75
|
+
|
|
76
|
+
const myAPI = API({
|
|
77
|
+
id: 'my-api',
|
|
78
|
+
name: 'My API',
|
|
79
|
+
description: 'A RESTful API',
|
|
80
|
+
version: '1.0.0',
|
|
81
|
+
style: 'rest',
|
|
82
|
+
baseUrl: 'https://api.example.com',
|
|
83
|
+
endpoints: [
|
|
84
|
+
Endpoint('GET', '/users', 'List all users', {
|
|
85
|
+
response: {
|
|
86
|
+
users: ['Array of user objects'],
|
|
87
|
+
total: 'Total count (number)',
|
|
88
|
+
},
|
|
89
|
+
}),
|
|
90
|
+
Endpoint('POST', '/users', 'Create a user', {
|
|
91
|
+
request: {
|
|
92
|
+
name: 'User name',
|
|
93
|
+
email: 'User email',
|
|
94
|
+
},
|
|
95
|
+
response: {
|
|
96
|
+
id: 'User ID',
|
|
97
|
+
name: 'User name',
|
|
98
|
+
email: 'User email',
|
|
99
|
+
},
|
|
100
|
+
auth: true,
|
|
101
|
+
}),
|
|
102
|
+
],
|
|
103
|
+
auth: APIAuth({
|
|
104
|
+
type: 'bearer',
|
|
105
|
+
header: 'Authorization',
|
|
106
|
+
}),
|
|
107
|
+
rateLimit: RateLimit({
|
|
108
|
+
requests: 100,
|
|
109
|
+
window: 60, // 60 seconds
|
|
110
|
+
onExceeded: 'reject',
|
|
111
|
+
}),
|
|
112
|
+
})
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### Define Content
|
|
116
|
+
|
|
117
|
+
```typescript
|
|
118
|
+
import { Content, Workflow } from 'digital-products'
|
|
119
|
+
|
|
120
|
+
const blogContent = Content({
|
|
121
|
+
id: 'blog',
|
|
122
|
+
name: 'Blog Posts',
|
|
123
|
+
description: 'Blog content for the website',
|
|
124
|
+
version: '1.0.0',
|
|
125
|
+
format: 'mdx',
|
|
126
|
+
source: './content/blog',
|
|
127
|
+
frontmatter: {
|
|
128
|
+
title: 'Post title',
|
|
129
|
+
author: 'Author name',
|
|
130
|
+
date: 'Publication date (date)',
|
|
131
|
+
tags: ['Array of tags'],
|
|
132
|
+
},
|
|
133
|
+
categories: ['Technology', 'Business', 'Design'],
|
|
134
|
+
workflow: Workflow({
|
|
135
|
+
states: ['draft', 'review', 'published'],
|
|
136
|
+
initialState: 'draft',
|
|
137
|
+
transitions: [
|
|
138
|
+
{ from: 'draft', to: 'review', action: 'submit' },
|
|
139
|
+
{ from: 'review', to: 'published', action: 'approve' },
|
|
140
|
+
{ from: 'review', to: 'draft', action: 'reject' },
|
|
141
|
+
],
|
|
142
|
+
approvals: [
|
|
143
|
+
{ state: 'review', roles: ['editor', 'admin'] },
|
|
144
|
+
],
|
|
145
|
+
}),
|
|
146
|
+
})
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### Define Data
|
|
150
|
+
|
|
151
|
+
```typescript
|
|
152
|
+
import { Data, Index, Relationship, Validate } from 'digital-products'
|
|
153
|
+
|
|
154
|
+
const userData = Data({
|
|
155
|
+
id: 'users',
|
|
156
|
+
name: 'Users',
|
|
157
|
+
description: 'User data store',
|
|
158
|
+
version: '1.0.0',
|
|
159
|
+
schema: {
|
|
160
|
+
id: 'User ID',
|
|
161
|
+
name: 'User name',
|
|
162
|
+
email: 'User email',
|
|
163
|
+
createdAt: 'Creation timestamp (date)',
|
|
164
|
+
role: 'admin | user | guest',
|
|
165
|
+
},
|
|
166
|
+
provider: 'postgres',
|
|
167
|
+
indexes: [
|
|
168
|
+
Index('email_idx', ['email'], { unique: true }),
|
|
169
|
+
Index('role_idx', ['role']),
|
|
170
|
+
],
|
|
171
|
+
relationships: [
|
|
172
|
+
Relationship('one-to-many', 'userId', 'posts', 'author'),
|
|
173
|
+
],
|
|
174
|
+
validation: [
|
|
175
|
+
Validate('email', 'email', 'Must be a valid email'),
|
|
176
|
+
Validate('name', 'required', 'Name is required'),
|
|
177
|
+
],
|
|
178
|
+
})
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### Define a Dataset
|
|
182
|
+
|
|
183
|
+
```typescript
|
|
184
|
+
import { Dataset } from 'digital-products'
|
|
185
|
+
|
|
186
|
+
const movieDataset = Dataset({
|
|
187
|
+
id: 'movies',
|
|
188
|
+
name: 'Movie Database',
|
|
189
|
+
description: 'Comprehensive movie information dataset',
|
|
190
|
+
version: '2024.1',
|
|
191
|
+
format: 'parquet',
|
|
192
|
+
schema: {
|
|
193
|
+
id: 'Movie ID',
|
|
194
|
+
title: 'Movie title',
|
|
195
|
+
year: 'Release year (number)',
|
|
196
|
+
genres: ['Array of genre names'],
|
|
197
|
+
rating: 'Average rating (number)',
|
|
198
|
+
votes: 'Number of votes (number)',
|
|
199
|
+
},
|
|
200
|
+
source: 's3://datasets/movies.parquet',
|
|
201
|
+
size: 1000000,
|
|
202
|
+
license: 'CC-BY-4.0',
|
|
203
|
+
updateFrequency: 'daily',
|
|
204
|
+
})
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
### Define a Site
|
|
208
|
+
|
|
209
|
+
```typescript
|
|
210
|
+
import { Site, Nav, SEO, Analytics } from 'digital-products'
|
|
211
|
+
|
|
212
|
+
const docsSite = Site({
|
|
213
|
+
id: 'docs',
|
|
214
|
+
name: 'Documentation Site',
|
|
215
|
+
description: 'Product documentation',
|
|
216
|
+
version: '1.0.0',
|
|
217
|
+
generator: 'fumadocs',
|
|
218
|
+
structure: {
|
|
219
|
+
home: '/docs/index.mdx',
|
|
220
|
+
docs: [
|
|
221
|
+
'/docs/getting-started.mdx',
|
|
222
|
+
'/docs/api-reference.mdx',
|
|
223
|
+
],
|
|
224
|
+
},
|
|
225
|
+
navigation: [
|
|
226
|
+
Nav('Home', '/'),
|
|
227
|
+
Nav('Docs', '/docs', {
|
|
228
|
+
children: [
|
|
229
|
+
Nav('Getting Started', '/docs/getting-started'),
|
|
230
|
+
Nav('API Reference', '/docs/api-reference'),
|
|
231
|
+
],
|
|
232
|
+
}),
|
|
233
|
+
],
|
|
234
|
+
seo: SEO({
|
|
235
|
+
titleTemplate: '%s | My Product',
|
|
236
|
+
description: 'Official documentation for My Product',
|
|
237
|
+
keywords: ['docs', 'api', 'reference'],
|
|
238
|
+
ogImage: '/og-image.png',
|
|
239
|
+
twitterCard: 'summary_large_image',
|
|
240
|
+
}),
|
|
241
|
+
analytics: Analytics('plausible', 'docs.example.com'),
|
|
242
|
+
})
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
### Define an MCP Server
|
|
246
|
+
|
|
247
|
+
```typescript
|
|
248
|
+
import { MCP, Tool, Resource, Prompt } from 'digital-products'
|
|
249
|
+
|
|
250
|
+
const mcpServer = MCP({
|
|
251
|
+
id: 'my-mcp',
|
|
252
|
+
name: 'My MCP Server',
|
|
253
|
+
description: 'Custom MCP server for AI tools',
|
|
254
|
+
version: '1.0.0',
|
|
255
|
+
transport: 'stdio',
|
|
256
|
+
tools: [
|
|
257
|
+
Tool('searchFiles', 'Search for files in the project', {
|
|
258
|
+
query: 'Search query',
|
|
259
|
+
path: 'Directory to search in',
|
|
260
|
+
}),
|
|
261
|
+
Tool('readFile', 'Read file contents', {
|
|
262
|
+
path: 'File path to read',
|
|
263
|
+
}),
|
|
264
|
+
],
|
|
265
|
+
resources: [
|
|
266
|
+
Resource('file://project', 'Project Files', 'Access to all project files'),
|
|
267
|
+
],
|
|
268
|
+
prompts: [
|
|
269
|
+
Prompt(
|
|
270
|
+
'codeReview',
|
|
271
|
+
'Review code for best practices',
|
|
272
|
+
'Review the following code:\n\n{{code}}',
|
|
273
|
+
{ code: 'Code to review' }
|
|
274
|
+
),
|
|
275
|
+
],
|
|
276
|
+
})
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
### Define an SDK
|
|
280
|
+
|
|
281
|
+
```typescript
|
|
282
|
+
import { SDK, Export, Example } from 'digital-products'
|
|
283
|
+
|
|
284
|
+
const mySDK = SDK({
|
|
285
|
+
id: 'my-sdk',
|
|
286
|
+
name: 'My SDK',
|
|
287
|
+
description: 'JavaScript SDK for My API',
|
|
288
|
+
version: '1.0.0',
|
|
289
|
+
language: 'typescript',
|
|
290
|
+
api: 'my-api',
|
|
291
|
+
exports: [
|
|
292
|
+
Export('function', 'createClient', 'Create an API client', {
|
|
293
|
+
parameters: {
|
|
294
|
+
apiKey: 'API key for authentication',
|
|
295
|
+
baseUrl: 'Optional base URL',
|
|
296
|
+
},
|
|
297
|
+
returns: 'API client instance',
|
|
298
|
+
}),
|
|
299
|
+
Export('class', 'APIClient', 'Main API client', {
|
|
300
|
+
methods: [
|
|
301
|
+
Export('function', 'get', 'GET request', {
|
|
302
|
+
parameters: { path: 'Request path' },
|
|
303
|
+
returns: 'Response data',
|
|
304
|
+
}),
|
|
305
|
+
Export('function', 'post', 'POST request', {
|
|
306
|
+
parameters: { path: 'Request path', data: 'Request body' },
|
|
307
|
+
returns: 'Response data',
|
|
308
|
+
}),
|
|
309
|
+
],
|
|
310
|
+
}),
|
|
311
|
+
],
|
|
312
|
+
install: 'npm install my-sdk',
|
|
313
|
+
examples: [
|
|
314
|
+
Example(
|
|
315
|
+
'Basic Usage',
|
|
316
|
+
'Create a client and make a request',
|
|
317
|
+
`import { createClient } from 'my-sdk'
|
|
318
|
+
|
|
319
|
+
const client = createClient({ apiKey: 'YOUR_API_KEY' })
|
|
320
|
+
const users = await client.get('/users')
|
|
321
|
+
console.log(users)`,
|
|
322
|
+
'{ users: [...] }'
|
|
323
|
+
),
|
|
324
|
+
],
|
|
325
|
+
})
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
### Using the Registry
|
|
329
|
+
|
|
330
|
+
```typescript
|
|
331
|
+
import { registry } from 'digital-products'
|
|
332
|
+
|
|
333
|
+
// List all registered products
|
|
334
|
+
const allProducts = registry.list()
|
|
335
|
+
console.log('All products:', allProducts.map(p => p.name))
|
|
336
|
+
|
|
337
|
+
// Get a specific product
|
|
338
|
+
const myApp = registry.get('my-app')
|
|
339
|
+
|
|
340
|
+
// List products by type
|
|
341
|
+
const apps = registry.listByType('app')
|
|
342
|
+
const apis = registry.listByType('api')
|
|
343
|
+
const sites = registry.listByType('site')
|
|
344
|
+
|
|
345
|
+
// Remove a product
|
|
346
|
+
registry.remove('my-app')
|
|
347
|
+
|
|
348
|
+
// Clear all products
|
|
349
|
+
registry.clear()
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
## Product Types
|
|
353
|
+
|
|
354
|
+
### App
|
|
355
|
+
|
|
356
|
+
Interactive user-facing applications with:
|
|
357
|
+
- Routes and navigation
|
|
358
|
+
- State management
|
|
359
|
+
- Authentication
|
|
360
|
+
- Deployment configuration
|
|
361
|
+
|
|
362
|
+
### API
|
|
363
|
+
|
|
364
|
+
Programmatic interfaces with:
|
|
365
|
+
- Endpoints (REST, GraphQL, RPC, gRPC, WebSocket)
|
|
366
|
+
- Request/response schemas
|
|
367
|
+
- Authentication
|
|
368
|
+
- Rate limiting
|
|
369
|
+
- OpenAPI/Swagger specs
|
|
370
|
+
|
|
371
|
+
### Content
|
|
372
|
+
|
|
373
|
+
Text and media content with:
|
|
374
|
+
- Multiple formats (Markdown, MDX, HTML, JSON, YAML)
|
|
375
|
+
- Structured schemas and frontmatter
|
|
376
|
+
- Categories and taxonomy
|
|
377
|
+
- Publishing workflows with approvals
|
|
378
|
+
|
|
379
|
+
### Data
|
|
380
|
+
|
|
381
|
+
Structured data definitions with:
|
|
382
|
+
- Schema definitions
|
|
383
|
+
- Database provider configuration
|
|
384
|
+
- Indexes and relationships
|
|
385
|
+
- Validation rules
|
|
386
|
+
|
|
387
|
+
### Dataset
|
|
388
|
+
|
|
389
|
+
Curated data collections with:
|
|
390
|
+
- Multiple formats (JSON, CSV, Parquet, Arrow, Avro)
|
|
391
|
+
- Schema definitions
|
|
392
|
+
- License information
|
|
393
|
+
- Update frequency
|
|
394
|
+
|
|
395
|
+
### Site
|
|
396
|
+
|
|
397
|
+
Websites and documentation with:
|
|
398
|
+
- Site structure and navigation
|
|
399
|
+
- SEO configuration
|
|
400
|
+
- Analytics integration
|
|
401
|
+
- Deployment configuration
|
|
402
|
+
|
|
403
|
+
### MCP
|
|
404
|
+
|
|
405
|
+
Model Context Protocol servers with:
|
|
406
|
+
- Transport configuration (stdio, HTTP, WebSocket)
|
|
407
|
+
- Tools for AI agents
|
|
408
|
+
- Resources and prompts
|
|
409
|
+
- Authentication
|
|
410
|
+
|
|
411
|
+
### SDK
|
|
412
|
+
|
|
413
|
+
Software development kits with:
|
|
414
|
+
- Target language/platform
|
|
415
|
+
- Exported functions, classes, and types
|
|
416
|
+
- Installation instructions
|
|
417
|
+
- Documentation and examples
|
|
418
|
+
|
|
419
|
+
## Entity Definitions (Nouns)
|
|
420
|
+
|
|
421
|
+
This package also provides comprehensive entity definitions following the Noun pattern from `ai-database`. Each entity includes properties, relationships, actions, and events.
|
|
422
|
+
|
|
423
|
+
### Entity Categories
|
|
424
|
+
|
|
425
|
+
| Category | Entities |
|
|
426
|
+
|----------|----------|
|
|
427
|
+
| **Products** | DigitalProduct, SaaSProduct, App, Platform, Marketplace |
|
|
428
|
+
| **Interfaces** | API, Endpoint, SDK, MCP, Plugin, Integration, Webhook |
|
|
429
|
+
| **Content** | ContentProduct, DataProduct, Dataset, Documentation, Template |
|
|
430
|
+
| **Web** | Site, Component, Widget, Theme |
|
|
431
|
+
| **AI** | AIProduct, Model, Agent, Prompt, Tool |
|
|
432
|
+
| **Lifecycle** | Version, Release, Deployment, Environment, Feature |
|
|
433
|
+
|
|
434
|
+
### Using Entity Definitions
|
|
435
|
+
|
|
436
|
+
```typescript
|
|
437
|
+
import { Nouns, ProductEntities, AIEntities } from 'digital-products'
|
|
438
|
+
|
|
439
|
+
// Access entities through the Nouns namespace
|
|
440
|
+
const appEntity = Nouns.App
|
|
441
|
+
console.log(appEntity.singular) // 'app'
|
|
442
|
+
console.log(appEntity.actions) // ['create', 'update', 'deploy', ...]
|
|
443
|
+
console.log(appEntity.events) // ['created', 'updated', 'deployed', ...]
|
|
444
|
+
|
|
445
|
+
// Or access category collections directly
|
|
446
|
+
const allProducts = ProductEntities
|
|
447
|
+
const allAI = AIEntities
|
|
448
|
+
```
|
|
449
|
+
|
|
450
|
+
### Entity Structure
|
|
451
|
+
|
|
452
|
+
Each entity follows the Noun pattern:
|
|
453
|
+
|
|
454
|
+
```typescript
|
|
455
|
+
const App: Noun = {
|
|
456
|
+
singular: 'app',
|
|
457
|
+
plural: 'apps',
|
|
458
|
+
description: 'An interactive user-facing application',
|
|
459
|
+
|
|
460
|
+
properties: {
|
|
461
|
+
name: { type: 'string', description: 'App name' },
|
|
462
|
+
type: { type: 'string', examples: ['web', 'mobile', 'desktop', 'cli', 'pwa'] },
|
|
463
|
+
framework: { type: 'string', examples: ['react', 'vue', 'svelte', 'solid'] },
|
|
464
|
+
status: { type: 'string', examples: ['draft', 'development', 'beta', 'production'] },
|
|
465
|
+
// ... more properties
|
|
466
|
+
},
|
|
467
|
+
|
|
468
|
+
relationships: {
|
|
469
|
+
product: { type: 'DigitalProduct', description: 'Parent product' },
|
|
470
|
+
features: { type: 'Feature[]', description: 'App features' },
|
|
471
|
+
deployments: { type: 'Deployment[]', description: 'Active deployments' },
|
|
472
|
+
},
|
|
473
|
+
|
|
474
|
+
actions: ['create', 'update', 'build', 'test', 'deploy', 'release', 'rollback', 'pause', 'deprecate'],
|
|
475
|
+
events: ['created', 'updated', 'built', 'tested', 'deployed', 'released', 'rolledBack', 'paused', 'deprecated'],
|
|
476
|
+
}
|
|
477
|
+
```
|
|
478
|
+
|
|
479
|
+
## TypeScript Support
|
|
480
|
+
|
|
481
|
+
All product definitions are fully typed with TypeScript. The package exports comprehensive type definitions for all product types and their configurations.
|
|
482
|
+
|
|
483
|
+
```typescript
|
|
484
|
+
import type {
|
|
485
|
+
AppDefinition,
|
|
486
|
+
APIDefinition,
|
|
487
|
+
ContentDefinition,
|
|
488
|
+
DataDefinition,
|
|
489
|
+
DatasetDefinition,
|
|
490
|
+
SiteDefinition,
|
|
491
|
+
MCPDefinition,
|
|
492
|
+
SDKDefinition,
|
|
493
|
+
ProductDefinition,
|
|
494
|
+
} from 'digital-products'
|
|
495
|
+
```
|
|
496
|
+
|
|
497
|
+
## Design Principles
|
|
498
|
+
|
|
499
|
+
1. **Declarative**: Define products using simple configuration objects
|
|
500
|
+
2. **Type-safe**: Full TypeScript support with comprehensive types
|
|
501
|
+
3. **Composable**: Helper functions for building complex configurations
|
|
502
|
+
4. **Extensible**: Easy to add custom metadata and configurations
|
|
503
|
+
5. **Registry-based**: Central registry for managing products
|
|
504
|
+
|
|
505
|
+
## Integration with ai-functions
|
|
506
|
+
|
|
507
|
+
This package uses `SimpleSchema` from `ai-functions` for defining schemas in a human-readable format:
|
|
508
|
+
|
|
509
|
+
```typescript
|
|
510
|
+
// Simple string description
|
|
511
|
+
schema: {
|
|
512
|
+
name: 'User name',
|
|
513
|
+
age: 'User age (number)',
|
|
514
|
+
active: 'Is user active (boolean)',
|
|
515
|
+
role: 'admin | user | guest',
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
// Arrays
|
|
519
|
+
schema: {
|
|
520
|
+
tags: ['List of tags'],
|
|
521
|
+
scores: ['List of scores (number)'],
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
// Nested objects
|
|
525
|
+
schema: {
|
|
526
|
+
user: {
|
|
527
|
+
name: 'Name',
|
|
528
|
+
email: 'Email address',
|
|
529
|
+
},
|
|
530
|
+
}
|
|
531
|
+
```
|
|
532
|
+
|
|
533
|
+
## License
|
|
534
|
+
|
|
535
|
+
MIT
|
package/dist/api.d.ts
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* API() - Define an API
|
|
3
|
+
*/
|
|
4
|
+
import type { APIDefinition, EndpointDefinition, APIAuthConfig, RateLimitConfig } from './types.js';
|
|
5
|
+
/**
|
|
6
|
+
* Create an API definition
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* const myAPI = API({
|
|
11
|
+
* id: 'my-api',
|
|
12
|
+
* name: 'My API',
|
|
13
|
+
* description: 'A RESTful API',
|
|
14
|
+
* version: '1.0.0',
|
|
15
|
+
* style: 'rest',
|
|
16
|
+
* baseUrl: 'https://api.example.com',
|
|
17
|
+
* endpoints: [
|
|
18
|
+
* Endpoint('GET', '/users', 'List all users', {
|
|
19
|
+
* response: {
|
|
20
|
+
* users: ['Array of user objects'],
|
|
21
|
+
* total: 'Total count (number)',
|
|
22
|
+
* },
|
|
23
|
+
* }),
|
|
24
|
+
* Endpoint('POST', '/users', 'Create a user', {
|
|
25
|
+
* request: {
|
|
26
|
+
* name: 'User name',
|
|
27
|
+
* email: 'User email',
|
|
28
|
+
* },
|
|
29
|
+
* response: {
|
|
30
|
+
* id: 'User ID',
|
|
31
|
+
* name: 'User name',
|
|
32
|
+
* email: 'User email',
|
|
33
|
+
* },
|
|
34
|
+
* }),
|
|
35
|
+
* ],
|
|
36
|
+
* auth: {
|
|
37
|
+
* type: 'bearer',
|
|
38
|
+
* header: 'Authorization',
|
|
39
|
+
* },
|
|
40
|
+
* rateLimit: {
|
|
41
|
+
* requests: 100,
|
|
42
|
+
* window: 60,
|
|
43
|
+
* },
|
|
44
|
+
* })
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export declare function API(config: Omit<APIDefinition, 'type'>): APIDefinition;
|
|
48
|
+
/**
|
|
49
|
+
* Helper to create an endpoint definition
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```ts
|
|
53
|
+
* const endpoint = Endpoint('GET', '/users/:id', 'Get user by ID', {
|
|
54
|
+
* params: { id: 'User ID' },
|
|
55
|
+
* response: {
|
|
56
|
+
* id: 'User ID',
|
|
57
|
+
* name: 'User name',
|
|
58
|
+
* email: 'User email',
|
|
59
|
+
* },
|
|
60
|
+
* auth: true,
|
|
61
|
+
* })
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
export declare function Endpoint(method: EndpointDefinition['method'], path: string, description: string, options?: Omit<EndpointDefinition, 'method' | 'path' | 'description'>): EndpointDefinition;
|
|
65
|
+
/**
|
|
66
|
+
* Helper to configure API authentication
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```ts
|
|
70
|
+
* const auth = APIAuth({
|
|
71
|
+
* type: 'bearer',
|
|
72
|
+
* header: 'Authorization',
|
|
73
|
+
* })
|
|
74
|
+
*
|
|
75
|
+
* const oauth = APIAuth({
|
|
76
|
+
* type: 'oauth2',
|
|
77
|
+
* oauth2: {
|
|
78
|
+
* authUrl: 'https://auth.example.com/authorize',
|
|
79
|
+
* tokenUrl: 'https://auth.example.com/token',
|
|
80
|
+
* scopes: ['read', 'write'],
|
|
81
|
+
* },
|
|
82
|
+
* })
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
export declare function APIAuth(config: APIAuthConfig): APIAuthConfig;
|
|
86
|
+
/**
|
|
87
|
+
* Helper to configure rate limiting
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```ts
|
|
91
|
+
* const rateLimit = RateLimit({
|
|
92
|
+
* requests: 100,
|
|
93
|
+
* window: 60, // 60 seconds
|
|
94
|
+
* onExceeded: 'reject',
|
|
95
|
+
* })
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
export declare function RateLimit(config: RateLimitConfig): RateLimitConfig;
|
|
99
|
+
//# sourceMappingURL=api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,kBAAkB,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAGnG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,wBAAgB,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,aAAa,EAAE,MAAM,CAAC,GAAG,aAAa,CAoBtE;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,QAAQ,CACtB,MAAM,EAAE,kBAAkB,CAAC,QAAQ,CAAC,EACpC,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,MAAM,EACnB,OAAO,CAAC,EAAE,IAAI,CAAC,kBAAkB,EAAE,QAAQ,GAAG,MAAM,GAAG,aAAa,CAAC,GACpE,kBAAkB,CAOpB;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,OAAO,CAAC,MAAM,EAAE,aAAa,GAAG,aAAa,CAE5D;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,eAAe,GAAG,eAAe,CAElE"}
|