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/src/types.ts ADDED
@@ -0,0 +1,558 @@
1
+ /**
2
+ * Core types for digital products
3
+ */
4
+
5
+ import type { SimpleSchema } from 'ai-functions'
6
+
7
+ /**
8
+ * Base digital product definition
9
+ */
10
+ export interface DigitalProduct {
11
+ /** Unique identifier for this product */
12
+ id: string
13
+ /** Human-readable name */
14
+ name: string
15
+ /** Description of what this product does */
16
+ description: string
17
+ /** Version string (e.g., "1.0.0") */
18
+ version: string
19
+ /** Product metadata */
20
+ metadata?: Record<string, unknown>
21
+ /** Tags for categorization */
22
+ tags?: string[]
23
+ /** Product status */
24
+ status?: 'draft' | 'active' | 'deprecated'
25
+ }
26
+
27
+ /**
28
+ * Application definition - interactive user-facing software
29
+ */
30
+ export interface AppDefinition extends DigitalProduct {
31
+ type: 'app'
32
+ /** UI framework/runtime */
33
+ framework?: 'react' | 'vue' | 'svelte' | 'solid' | 'ink' | 'custom'
34
+ /** Application routes/pages */
35
+ routes?: RouteDefinition[]
36
+ /** Application configuration */
37
+ config?: AppConfig
38
+ /** State management */
39
+ state?: StateDefinition
40
+ /** Authentication configuration */
41
+ auth?: AuthConfig
42
+ /** Deployment targets */
43
+ deployments?: DeploymentTarget[]
44
+ }
45
+
46
+ /**
47
+ * Route definition for an app
48
+ */
49
+ export interface RouteDefinition {
50
+ /** Route path (e.g., "/", "/about", "/users/:id") */
51
+ path: string
52
+ /** Component or page to render */
53
+ component: string
54
+ /** Route metadata */
55
+ meta?: Record<string, unknown>
56
+ /** Child routes */
57
+ children?: RouteDefinition[]
58
+ }
59
+
60
+ /**
61
+ * Application configuration
62
+ */
63
+ export interface AppConfig {
64
+ /** App title */
65
+ title?: string
66
+ /** Theme configuration */
67
+ theme?: Record<string, unknown>
68
+ /** Environment variables */
69
+ env?: Record<string, string>
70
+ /** Feature flags */
71
+ features?: Record<string, boolean>
72
+ }
73
+
74
+ /**
75
+ * State management definition
76
+ */
77
+ export interface StateDefinition {
78
+ /** State management library */
79
+ library?: 'react-context' | 'zustand' | 'redux' | 'mobx' | 'jotai' | 'custom'
80
+ /** Initial state schema */
81
+ schema?: SimpleSchema
82
+ /** State persistence */
83
+ persistence?: {
84
+ type: 'local' | 'session' | 'database'
85
+ key?: string
86
+ }
87
+ }
88
+
89
+ /**
90
+ * Authentication configuration
91
+ */
92
+ export interface AuthConfig {
93
+ /** Auth provider */
94
+ provider?: 'clerk' | 'auth0' | 'firebase' | 'supabase' | 'custom'
95
+ /** Required roles */
96
+ roles?: string[]
97
+ /** Protected routes */
98
+ protectedRoutes?: string[]
99
+ }
100
+
101
+ /**
102
+ * API definition - programmatic interface
103
+ */
104
+ export interface APIDefinition extends DigitalProduct {
105
+ type: 'api'
106
+ /** API style */
107
+ style?: 'rest' | 'graphql' | 'rpc' | 'grpc' | 'websocket'
108
+ /** Base URL or endpoint pattern */
109
+ baseUrl?: string
110
+ /** API endpoints */
111
+ endpoints?: EndpointDefinition[]
112
+ /** Authentication method */
113
+ auth?: APIAuthConfig
114
+ /** Rate limiting */
115
+ rateLimit?: RateLimitConfig
116
+ /** API documentation URL */
117
+ docsUrl?: string
118
+ /** OpenAPI/Swagger spec */
119
+ openapi?: Record<string, unknown>
120
+ }
121
+
122
+ /**
123
+ * API endpoint definition
124
+ */
125
+ export interface EndpointDefinition {
126
+ /** HTTP method */
127
+ method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS' | 'HEAD'
128
+ /** Endpoint path */
129
+ path: string
130
+ /** Description of what this endpoint does */
131
+ description: string
132
+ /** Request schema */
133
+ request?: SimpleSchema
134
+ /** Response schema */
135
+ response?: SimpleSchema
136
+ /** Query parameters */
137
+ query?: SimpleSchema
138
+ /** Path parameters */
139
+ params?: Record<string, string>
140
+ /** Headers */
141
+ headers?: Record<string, string>
142
+ /** Authentication required */
143
+ auth?: boolean
144
+ /** Rate limit override */
145
+ rateLimit?: RateLimitConfig
146
+ }
147
+
148
+ /**
149
+ * API authentication configuration
150
+ */
151
+ export interface APIAuthConfig {
152
+ /** Auth type */
153
+ type: 'apikey' | 'bearer' | 'basic' | 'oauth2' | 'custom'
154
+ /** Header name for API key/token */
155
+ header?: string
156
+ /** OAuth2 configuration */
157
+ oauth2?: {
158
+ authUrl: string
159
+ tokenUrl: string
160
+ scopes: string[]
161
+ }
162
+ }
163
+
164
+ /**
165
+ * Rate limiting configuration
166
+ */
167
+ export interface RateLimitConfig {
168
+ /** Requests per time window */
169
+ requests: number
170
+ /** Time window in seconds */
171
+ window: number
172
+ /** What to do when limit exceeded */
173
+ onExceeded?: 'reject' | 'queue' | 'custom'
174
+ }
175
+
176
+ /**
177
+ * Content definition - text/media content
178
+ */
179
+ export interface ContentDefinition extends DigitalProduct {
180
+ type: 'content'
181
+ /** Content format */
182
+ format?: 'markdown' | 'mdx' | 'html' | 'json' | 'yaml' | 'text'
183
+ /** Content source */
184
+ source?: string
185
+ /** Content schema (for structured content) */
186
+ schema?: SimpleSchema
187
+ /** Frontmatter schema */
188
+ frontmatter?: SimpleSchema
189
+ /** Content categories/taxonomy */
190
+ categories?: string[]
191
+ /** Publishing workflow */
192
+ workflow?: WorkflowDefinition
193
+ }
194
+
195
+ /**
196
+ * Publishing workflow
197
+ */
198
+ export interface WorkflowDefinition {
199
+ /** Workflow states */
200
+ states: string[]
201
+ /** Initial state */
202
+ initialState: string
203
+ /** Allowed transitions */
204
+ transitions: { from: string; to: string; action: string }[]
205
+ /** Approval requirements */
206
+ approvals?: { state: string; roles: string[] }[]
207
+ }
208
+
209
+ /**
210
+ * Data definition - structured data/database
211
+ */
212
+ export interface DataDefinition extends DigitalProduct {
213
+ type: 'data'
214
+ /** Data schema */
215
+ schema: SimpleSchema
216
+ /** Database provider */
217
+ provider?: 'postgres' | 'mysql' | 'sqlite' | 'mongo' | 'clickhouse' | 'fs'
218
+ /** Indexes */
219
+ indexes?: IndexDefinition[]
220
+ /** Relationships */
221
+ relationships?: RelationshipDefinition[]
222
+ /** Validation rules */
223
+ validation?: ValidationRule[]
224
+ }
225
+
226
+ /**
227
+ * Database index definition
228
+ */
229
+ export interface IndexDefinition {
230
+ /** Index name */
231
+ name: string
232
+ /** Fields to index */
233
+ fields: string[]
234
+ /** Index type */
235
+ type?: 'btree' | 'hash' | 'gin' | 'gist' | 'vector'
236
+ /** Unique constraint */
237
+ unique?: boolean
238
+ }
239
+
240
+ /**
241
+ * Relationship definition
242
+ */
243
+ export interface RelationshipDefinition {
244
+ /** Relationship type */
245
+ type: 'one-to-one' | 'one-to-many' | 'many-to-many'
246
+ /** Source field */
247
+ from: string
248
+ /** Target entity */
249
+ to: string
250
+ /** Target field */
251
+ field: string
252
+ }
253
+
254
+ /**
255
+ * Validation rule
256
+ */
257
+ export interface ValidationRule {
258
+ /** Field to validate */
259
+ field: string
260
+ /** Rule type */
261
+ rule: 'required' | 'unique' | 'email' | 'url' | 'min' | 'max' | 'regex' | 'custom'
262
+ /** Rule parameters */
263
+ params?: unknown
264
+ /** Error message */
265
+ message?: string
266
+ }
267
+
268
+ /**
269
+ * Dataset definition - curated data collection
270
+ */
271
+ export interface DatasetDefinition extends DigitalProduct {
272
+ type: 'dataset'
273
+ /** Data format */
274
+ format?: 'json' | 'csv' | 'parquet' | 'arrow' | 'avro'
275
+ /** Dataset schema */
276
+ schema: SimpleSchema
277
+ /** Data source */
278
+ source?: string
279
+ /** Number of records */
280
+ size?: number
281
+ /** License */
282
+ license?: string
283
+ /** Update frequency */
284
+ updateFrequency?: 'realtime' | 'hourly' | 'daily' | 'weekly' | 'monthly' | 'static'
285
+ }
286
+
287
+ /**
288
+ * Site definition - website/documentation
289
+ */
290
+ export interface SiteDefinition extends DigitalProduct {
291
+ type: 'site'
292
+ /** Site generator */
293
+ generator?: 'next' | 'fumadocs' | 'docusaurus' | 'vitepress' | 'astro' | 'custom'
294
+ /** Site structure */
295
+ structure?: SiteStructure
296
+ /** Navigation */
297
+ navigation?: NavigationDefinition[]
298
+ /** SEO configuration */
299
+ seo?: SEOConfig
300
+ /** Analytics */
301
+ analytics?: AnalyticsConfig
302
+ /** Deployment */
303
+ deployment?: DeploymentTarget
304
+ }
305
+
306
+ /**
307
+ * Site structure
308
+ */
309
+ export interface SiteStructure {
310
+ /** Homepage */
311
+ home?: string
312
+ /** Documentation pages */
313
+ docs?: string[]
314
+ /** Blog posts */
315
+ blog?: string[]
316
+ /** Custom pages */
317
+ pages?: { path: string; source: string }[]
318
+ }
319
+
320
+ /**
321
+ * Navigation definition
322
+ */
323
+ export interface NavigationDefinition {
324
+ /** Label */
325
+ label: string
326
+ /** URL or path */
327
+ href: string
328
+ /** Icon */
329
+ icon?: string
330
+ /** Child items */
331
+ children?: NavigationDefinition[]
332
+ /** External link */
333
+ external?: boolean
334
+ }
335
+
336
+ /**
337
+ * SEO configuration
338
+ */
339
+ export interface SEOConfig {
340
+ /** Site title template */
341
+ titleTemplate?: string
342
+ /** Default description */
343
+ description?: string
344
+ /** Keywords */
345
+ keywords?: string[]
346
+ /** Open Graph image */
347
+ ogImage?: string
348
+ /** Twitter card type */
349
+ twitterCard?: 'summary' | 'summary_large_image' | 'app' | 'player'
350
+ }
351
+
352
+ /**
353
+ * Analytics configuration
354
+ */
355
+ export interface AnalyticsConfig {
356
+ /** Analytics provider */
357
+ provider: 'google' | 'plausible' | 'fathom' | 'custom'
358
+ /** Tracking ID */
359
+ id: string
360
+ /** Additional config */
361
+ config?: Record<string, unknown>
362
+ }
363
+
364
+ /**
365
+ * MCP (Model Context Protocol) server definition
366
+ */
367
+ export interface MCPDefinition extends DigitalProduct {
368
+ type: 'mcp'
369
+ /** Transport type */
370
+ transport: 'stdio' | 'http' | 'websocket'
371
+ /** Tools provided by this MCP server */
372
+ tools?: MCPTool[]
373
+ /** Resources provided */
374
+ resources?: MCPResource[]
375
+ /** Prompts provided */
376
+ prompts?: MCPPrompt[]
377
+ /** Server configuration */
378
+ config?: MCPConfig
379
+ }
380
+
381
+ /**
382
+ * MCP tool definition
383
+ */
384
+ export interface MCPTool {
385
+ /** Tool name */
386
+ name: string
387
+ /** Description for AI */
388
+ description: string
389
+ /** Input schema */
390
+ inputSchema: SimpleSchema
391
+ /** Handler implementation */
392
+ handler?: (input: unknown) => Promise<unknown>
393
+ }
394
+
395
+ /**
396
+ * MCP resource definition
397
+ */
398
+ export interface MCPResource {
399
+ /** Resource URI */
400
+ uri: string
401
+ /** Resource name */
402
+ name: string
403
+ /** Description */
404
+ description: string
405
+ /** MIME type */
406
+ mimeType?: string
407
+ }
408
+
409
+ /**
410
+ * MCP prompt definition
411
+ */
412
+ export interface MCPPrompt {
413
+ /** Prompt name */
414
+ name: string
415
+ /** Description */
416
+ description: string
417
+ /** Prompt template */
418
+ template: string
419
+ /** Arguments schema */
420
+ arguments?: SimpleSchema
421
+ }
422
+
423
+ /**
424
+ * MCP server configuration
425
+ */
426
+ export interface MCPConfig {
427
+ /** Port (for HTTP/WebSocket) */
428
+ port?: number
429
+ /** Host */
430
+ host?: string
431
+ /** Authentication */
432
+ auth?: {
433
+ type: 'bearer' | 'apikey'
434
+ token?: string
435
+ }
436
+ }
437
+
438
+ /**
439
+ * SDK (Software Development Kit) definition
440
+ */
441
+ export interface SDKDefinition extends DigitalProduct {
442
+ type: 'sdk'
443
+ /** Target language/platform */
444
+ language: 'typescript' | 'javascript' | 'python' | 'go' | 'rust' | 'java' | 'csharp'
445
+ /** API it wraps */
446
+ api?: string
447
+ /** Exported functions/classes */
448
+ exports?: SDKExport[]
449
+ /** Installation instructions */
450
+ install?: string
451
+ /** Documentation */
452
+ docs?: string
453
+ /** Examples */
454
+ examples?: SDKExample[]
455
+ }
456
+
457
+ /**
458
+ * SDK export definition
459
+ */
460
+ export interface SDKExport {
461
+ /** Export name */
462
+ name: string
463
+ /** Export type */
464
+ type: 'function' | 'class' | 'constant' | 'type'
465
+ /** Description */
466
+ description: string
467
+ /** Parameters (for functions) */
468
+ parameters?: SimpleSchema
469
+ /** Return type */
470
+ returns?: SimpleSchema
471
+ /** Class methods (for classes) */
472
+ methods?: SDKExport[]
473
+ }
474
+
475
+ /**
476
+ * SDK example
477
+ */
478
+ export interface SDKExample {
479
+ /** Example title */
480
+ title: string
481
+ /** Description */
482
+ description: string
483
+ /** Code sample */
484
+ code: string
485
+ /** Expected output */
486
+ output?: string
487
+ }
488
+
489
+ /**
490
+ * Deployment target
491
+ */
492
+ export interface DeploymentTarget {
493
+ /** Platform */
494
+ platform: 'vercel' | 'netlify' | 'cloudflare' | 'aws' | 'gcp' | 'azure' | 'custom'
495
+ /** Environment */
496
+ environment?: 'production' | 'staging' | 'preview' | 'development'
497
+ /** URL */
498
+ url?: string
499
+ /** Build command */
500
+ buildCommand?: string
501
+ /** Output directory */
502
+ outputDir?: string
503
+ /** Environment variables */
504
+ env?: Record<string, string>
505
+ }
506
+
507
+ /**
508
+ * Union of all product types
509
+ */
510
+ export type ProductDefinition =
511
+ | AppDefinition
512
+ | APIDefinition
513
+ | ContentDefinition
514
+ | DataDefinition
515
+ | DatasetDefinition
516
+ | SiteDefinition
517
+ | MCPDefinition
518
+ | SDKDefinition
519
+
520
+ /**
521
+ * Product builder - chainable API for creating products
522
+ */
523
+ export interface ProductBuilder<T extends ProductDefinition> {
524
+ /** Set product ID */
525
+ id(id: string): ProductBuilder<T>
526
+ /** Set product name */
527
+ name(name: string): ProductBuilder<T>
528
+ /** Set description */
529
+ description(description: string): ProductBuilder<T>
530
+ /** Set version */
531
+ version(version: string): ProductBuilder<T>
532
+ /** Set metadata */
533
+ metadata(metadata: Record<string, unknown>): ProductBuilder<T>
534
+ /** Add tags */
535
+ tags(...tags: string[]): ProductBuilder<T>
536
+ /** Set status */
537
+ status(status: 'draft' | 'active' | 'deprecated'): ProductBuilder<T>
538
+ /** Build the product definition */
539
+ build(): T
540
+ }
541
+
542
+ /**
543
+ * Product registry for storing products
544
+ */
545
+ export interface ProductRegistry {
546
+ /** Register a product */
547
+ register(product: ProductDefinition): void
548
+ /** Get a product by ID */
549
+ get(id: string): ProductDefinition | undefined
550
+ /** List all products */
551
+ list(): ProductDefinition[]
552
+ /** List products by type */
553
+ listByType<T extends ProductDefinition['type']>(type: T): Extract<ProductDefinition, { type: T }>[]
554
+ /** Remove a product */
555
+ remove(id: string): boolean
556
+ /** Clear all products */
557
+ clear(): void
558
+ }