digital-products 2.1.1 → 2.3.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.
Files changed (80) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/README.md +2 -0
  3. package/dist/api.js +7 -7
  4. package/dist/api.js.map +1 -1
  5. package/dist/app.js +6 -6
  6. package/dist/app.js.map +1 -1
  7. package/dist/client.d.ts +157 -0
  8. package/dist/client.d.ts.map +1 -0
  9. package/dist/client.js +69 -0
  10. package/dist/client.js.map +1 -0
  11. package/dist/content.js +7 -7
  12. package/dist/content.js.map +1 -1
  13. package/dist/data.d.ts.map +1 -1
  14. package/dist/data.js +6 -6
  15. package/dist/data.js.map +1 -1
  16. package/dist/dataset.js +5 -5
  17. package/dist/dataset.js.map +1 -1
  18. package/dist/index.d.ts +92 -13
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/index.js +139 -15
  21. package/dist/index.js.map +1 -1
  22. package/dist/mcp.d.ts +1 -1
  23. package/dist/mcp.d.ts.map +1 -1
  24. package/dist/mcp.js +17 -10
  25. package/dist/mcp.js.map +1 -1
  26. package/dist/product.js +2 -2
  27. package/dist/product.js.map +1 -1
  28. package/dist/sdk.d.ts.map +1 -1
  29. package/dist/sdk.js +52 -16
  30. package/dist/sdk.js.map +1 -1
  31. package/dist/site.d.ts.map +1 -1
  32. package/dist/site.js +12 -8
  33. package/dist/site.js.map +1 -1
  34. package/dist/types.d.ts +830 -12
  35. package/dist/types.d.ts.map +1 -1
  36. package/dist/types.js +495 -2
  37. package/dist/types.js.map +1 -1
  38. package/dist/worker.d.ts +205 -0
  39. package/dist/worker.d.ts.map +1 -0
  40. package/dist/worker.js +356 -0
  41. package/dist/worker.js.map +1 -0
  42. package/package.json +20 -4
  43. package/src/api.ts +7 -7
  44. package/src/app.ts +6 -6
  45. package/src/client.ts +192 -0
  46. package/src/content.ts +7 -7
  47. package/src/data.ts +12 -7
  48. package/src/dataset.ts +5 -5
  49. package/src/index.ts +151 -15
  50. package/src/mcp.ts +18 -11
  51. package/src/product.ts +2 -2
  52. package/src/sdk.ts +54 -15
  53. package/src/site.ts +12 -8
  54. package/src/types.ts +821 -12
  55. package/src/worker.ts +525 -0
  56. package/test/product.test.ts +53 -198
  57. package/test/unified-types.test.ts +589 -0
  58. package/test/worker.test.ts +912 -0
  59. package/vitest.config.ts +42 -0
  60. package/wrangler.jsonc +36 -0
  61. package/.turbo/turbo-build.log +0 -5
  62. package/src/api.js +0 -128
  63. package/src/app.js +0 -106
  64. package/src/content.js +0 -77
  65. package/src/data.js +0 -106
  66. package/src/dataset.js +0 -49
  67. package/src/entities/ai.js +0 -858
  68. package/src/entities/content.js +0 -783
  69. package/src/entities/index.js +0 -88
  70. package/src/entities/interfaces.js +0 -929
  71. package/src/entities/lifecycle.js +0 -803
  72. package/src/entities/products.js +0 -797
  73. package/src/entities/web.js +0 -657
  74. package/src/index.js +0 -35
  75. package/src/mcp.js +0 -139
  76. package/src/product.js +0 -53
  77. package/src/registry.js +0 -31
  78. package/src/sdk.js +0 -127
  79. package/src/site.js +0 -112
  80. package/src/types.js +0 -4
@@ -0,0 +1,42 @@
1
+ import { defineWorkersConfig } from '@cloudflare/vitest-pool-workers/config'
2
+
3
+ export default defineWorkersConfig({
4
+ test: {
5
+ // CRITICAL: Limit concurrency to prevent resource exhaustion
6
+ maxConcurrency: 1,
7
+ maxWorkers: 1,
8
+ minWorkers: 1,
9
+ fileParallelism: false,
10
+
11
+ poolOptions: {
12
+ workers: {
13
+ wrangler: { configPath: './wrangler.jsonc' },
14
+ miniflare: {
15
+ compatibilityDate: '2025-01-20',
16
+ compatibilityFlags: ['nodejs_compat_v2'],
17
+ durableObjects: {
18
+ PRODUCT_CATALOG: 'ProductCatalog',
19
+ },
20
+ },
21
+ },
22
+ },
23
+
24
+ include: ['src/**/*.test.ts', 'test/**/*.test.ts'],
25
+ testTimeout: 60000, // AI calls can take time
26
+ hookTimeout: 30000,
27
+
28
+ // Coverage configuration
29
+ coverage: {
30
+ provider: 'v8',
31
+ reporter: ['text', 'json', 'html'],
32
+ include: ['src/**/*.ts'],
33
+ exclude: ['**/*.test.ts', '**/__tests__/**', '**/node_modules/**'],
34
+ thresholds: {
35
+ statements: 65,
36
+ branches: 60,
37
+ functions: 60,
38
+ lines: 65,
39
+ },
40
+ },
41
+ },
42
+ })
package/wrangler.jsonc ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ // Wrangler configuration for digital-products worker tests
3
+ // Used by @cloudflare/vitest-pool-workers for testing
4
+
5
+ "name": "digital-products",
6
+ "main": "src/worker.ts",
7
+ "compatibility_date": "2025-01-20",
8
+ "compatibility_flags": ["nodejs_compat_v2"],
9
+
10
+ // AI binding for Cloudflare Workers AI
11
+ // Enables real AI Gateway access in tests (cache: true for deterministic tests)
12
+ "ai": {
13
+ "binding": "AI"
14
+ },
15
+
16
+ // Durable Objects for product catalog persistence
17
+ "durable_objects": {
18
+ "bindings": [
19
+ { "name": "PRODUCT_CATALOG", "class_name": "ProductCatalog" }
20
+ ]
21
+ },
22
+
23
+ // Migrations for Durable Objects
24
+ "migrations": [
25
+ { "tag": "v1", "new_classes": ["ProductCatalog"] }
26
+ ],
27
+
28
+ // The default export (ProductService) extends WorkerEntrypoint
29
+ // All public methods are automatically exposed via RPC
30
+
31
+ // Environment variables for AI Gateway
32
+ // These are loaded from .dev.vars or .env in local development
33
+ "vars": {
34
+ // Placeholder - actual values come from .dev.vars
35
+ }
36
+ }
@@ -1,5 +0,0 @@
1
-
2
- 
3
- > digital-products@2.0.1 build /Users/nathanclevenger/projects/primitives.org.ai/packages/digital-products
4
- > tsc
5
-
package/src/api.js DELETED
@@ -1,128 +0,0 @@
1
- /**
2
- * API() - Define an API
3
- */
4
- import { registerProduct } from './product.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 function API(config) {
48
- const api = {
49
- type: 'api',
50
- id: config.id,
51
- name: config.name,
52
- description: config.description,
53
- version: config.version,
54
- style: config.style || 'rest',
55
- baseUrl: config.baseUrl,
56
- endpoints: config.endpoints || [],
57
- auth: config.auth,
58
- rateLimit: config.rateLimit,
59
- docsUrl: config.docsUrl,
60
- openapi: config.openapi,
61
- metadata: config.metadata,
62
- tags: config.tags,
63
- status: config.status || 'active',
64
- };
65
- return registerProduct(api);
66
- }
67
- /**
68
- * Helper to create an endpoint definition
69
- *
70
- * @example
71
- * ```ts
72
- * const endpoint = Endpoint('GET', '/users/:id', 'Get user by ID', {
73
- * params: { id: 'User ID' },
74
- * response: {
75
- * id: 'User ID',
76
- * name: 'User name',
77
- * email: 'User email',
78
- * },
79
- * auth: true,
80
- * })
81
- * ```
82
- */
83
- export function Endpoint(method, path, description, options) {
84
- return {
85
- method,
86
- path,
87
- description,
88
- ...options,
89
- };
90
- }
91
- /**
92
- * Helper to configure API authentication
93
- *
94
- * @example
95
- * ```ts
96
- * const auth = APIAuth({
97
- * type: 'bearer',
98
- * header: 'Authorization',
99
- * })
100
- *
101
- * const oauth = APIAuth({
102
- * type: 'oauth2',
103
- * oauth2: {
104
- * authUrl: 'https://auth.example.com/authorize',
105
- * tokenUrl: 'https://auth.example.com/token',
106
- * scopes: ['read', 'write'],
107
- * },
108
- * })
109
- * ```
110
- */
111
- export function APIAuth(config) {
112
- return config;
113
- }
114
- /**
115
- * Helper to configure rate limiting
116
- *
117
- * @example
118
- * ```ts
119
- * const rateLimit = RateLimit({
120
- * requests: 100,
121
- * window: 60, // 60 seconds
122
- * onExceeded: 'reject',
123
- * })
124
- * ```
125
- */
126
- export function RateLimit(config) {
127
- return config;
128
- }
package/src/app.js DELETED
@@ -1,106 +0,0 @@
1
- /**
2
- * App() - Define an application
3
- */
4
- import { registerProduct } from './product.js';
5
- /**
6
- * Create an application definition
7
- *
8
- * @example
9
- * ```ts
10
- * const myApp = App({
11
- * id: 'my-app',
12
- * name: 'My App',
13
- * description: 'A web application',
14
- * version: '1.0.0',
15
- * framework: 'react',
16
- * routes: [
17
- * { path: '/', component: 'Home' },
18
- * { path: '/about', component: 'About' },
19
- * { path: '/users/:id', component: 'UserDetail' },
20
- * ],
21
- * state: {
22
- * library: 'zustand',
23
- * schema: {
24
- * user: 'Current user object',
25
- * settings: 'App settings object',
26
- * },
27
- * },
28
- * auth: {
29
- * provider: 'clerk',
30
- * protectedRoutes: ['/dashboard', '/profile'],
31
- * },
32
- * })
33
- * ```
34
- */
35
- export function App(config) {
36
- const app = {
37
- type: 'app',
38
- id: config.id,
39
- name: config.name,
40
- description: config.description,
41
- version: config.version,
42
- framework: config.framework || 'react',
43
- routes: config.routes || [],
44
- config: config.config,
45
- state: config.state,
46
- auth: config.auth,
47
- deployments: config.deployments,
48
- metadata: config.metadata,
49
- tags: config.tags,
50
- status: config.status || 'active',
51
- };
52
- return registerProduct(app);
53
- }
54
- /**
55
- * Helper to create a route definition
56
- *
57
- * @example
58
- * ```ts
59
- * const userRoute = Route('/users/:id', 'UserDetail', {
60
- * meta: { title: 'User Profile' },
61
- * })
62
- * ```
63
- */
64
- export function Route(path, component, options) {
65
- return {
66
- path,
67
- component,
68
- ...options,
69
- };
70
- }
71
- /**
72
- * Helper to configure state management
73
- *
74
- * @example
75
- * ```ts
76
- * const state = State({
77
- * library: 'zustand',
78
- * schema: {
79
- * user: 'Current user',
80
- * settings: 'User settings',
81
- * },
82
- * persistence: {
83
- * type: 'local',
84
- * key: 'app-state',
85
- * },
86
- * })
87
- * ```
88
- */
89
- export function State(config) {
90
- return config;
91
- }
92
- /**
93
- * Helper to configure authentication
94
- *
95
- * @example
96
- * ```ts
97
- * const auth = Auth({
98
- * provider: 'clerk',
99
- * protectedRoutes: ['/dashboard', '/profile'],
100
- * roles: ['admin', 'user'],
101
- * })
102
- * ```
103
- */
104
- export function Auth(config) {
105
- return config;
106
- }
package/src/content.js DELETED
@@ -1,77 +0,0 @@
1
- /**
2
- * Content() - Define content
3
- */
4
- import { registerProduct } from './product.js';
5
- /**
6
- * Create a content definition
7
- *
8
- * @example
9
- * ```ts
10
- * const blogContent = Content({
11
- * id: 'blog',
12
- * name: 'Blog Posts',
13
- * description: 'Blog content for the website',
14
- * version: '1.0.0',
15
- * format: 'mdx',
16
- * source: './content/blog',
17
- * frontmatter: {
18
- * title: 'Post title',
19
- * author: 'Author name',
20
- * date: 'Publication date (date)',
21
- * tags: ['Array of tags'],
22
- * },
23
- * categories: ['Technology', 'Business', 'Design'],
24
- * workflow: Workflow({
25
- * states: ['draft', 'review', 'published'],
26
- * initialState: 'draft',
27
- * transitions: [
28
- * { from: 'draft', to: 'review', action: 'submit' },
29
- * { from: 'review', to: 'published', action: 'approve' },
30
- * { from: 'review', to: 'draft', action: 'reject' },
31
- * ],
32
- * }),
33
- * })
34
- * ```
35
- */
36
- export function Content(config) {
37
- const content = {
38
- type: 'content',
39
- id: config.id,
40
- name: config.name,
41
- description: config.description,
42
- version: config.version,
43
- format: config.format || 'markdown',
44
- source: config.source,
45
- schema: config.schema,
46
- frontmatter: config.frontmatter,
47
- categories: config.categories,
48
- workflow: config.workflow,
49
- metadata: config.metadata,
50
- tags: config.tags,
51
- status: config.status || 'active',
52
- };
53
- return registerProduct(content);
54
- }
55
- /**
56
- * Helper to create a workflow definition
57
- *
58
- * @example
59
- * ```ts
60
- * const workflow = Workflow({
61
- * states: ['draft', 'review', 'published', 'archived'],
62
- * initialState: 'draft',
63
- * transitions: [
64
- * { from: 'draft', to: 'review', action: 'submit' },
65
- * { from: 'review', to: 'published', action: 'approve' },
66
- * { from: 'review', to: 'draft', action: 'reject' },
67
- * { from: 'published', to: 'archived', action: 'archive' },
68
- * ],
69
- * approvals: [
70
- * { state: 'review', roles: ['editor', 'admin'] },
71
- * ],
72
- * })
73
- * ```
74
- */
75
- export function Workflow(config) {
76
- return config;
77
- }
package/src/data.js DELETED
@@ -1,106 +0,0 @@
1
- /**
2
- * Data() - Define structured data
3
- */
4
- import { registerProduct } from './product.js';
5
- /**
6
- * Create a data definition
7
- *
8
- * @example
9
- * ```ts
10
- * const userData = Data({
11
- * id: 'users',
12
- * name: 'Users',
13
- * description: 'User data store',
14
- * version: '1.0.0',
15
- * schema: {
16
- * id: 'User ID',
17
- * name: 'User name',
18
- * email: 'User email',
19
- * createdAt: 'Creation timestamp (date)',
20
- * role: 'admin | user | guest',
21
- * },
22
- * provider: 'postgres',
23
- * indexes: [
24
- * Index('email_idx', ['email'], { unique: true }),
25
- * Index('role_idx', ['role']),
26
- * ],
27
- * validation: [
28
- * Validate('email', 'email', 'Must be a valid email'),
29
- * Validate('name', 'required', 'Name is required'),
30
- * ],
31
- * })
32
- * ```
33
- */
34
- export function Data(config) {
35
- const data = {
36
- type: 'data',
37
- id: config.id,
38
- name: config.name,
39
- description: config.description,
40
- version: config.version,
41
- schema: config.schema,
42
- provider: config.provider || 'fs',
43
- indexes: config.indexes,
44
- relationships: config.relationships,
45
- validation: config.validation,
46
- metadata: config.metadata,
47
- tags: config.tags,
48
- status: config.status || 'active',
49
- };
50
- return registerProduct(data);
51
- }
52
- /**
53
- * Helper to create an index definition
54
- *
55
- * @example
56
- * ```ts
57
- * const emailIndex = Index('email_idx', ['email'], { unique: true })
58
- * const nameIndex = Index('name_idx', ['firstName', 'lastName'])
59
- * const vectorIndex = Index('embedding_idx', ['embedding'], { type: 'vector' })
60
- * ```
61
- */
62
- export function Index(name, fields, options) {
63
- return {
64
- name,
65
- fields,
66
- ...options,
67
- };
68
- }
69
- /**
70
- * Helper to create a relationship definition
71
- *
72
- * @example
73
- * ```ts
74
- * const userPosts = Relationship('one-to-many', 'userId', 'posts', 'author')
75
- * const postTags = Relationship('many-to-many', 'postId', 'tags', 'posts')
76
- * ```
77
- */
78
- export function Relationship(type, from, to, field) {
79
- return {
80
- type,
81
- from,
82
- to,
83
- field,
84
- };
85
- }
86
- /**
87
- * Helper to create a validation rule
88
- *
89
- * @example
90
- * ```ts
91
- * const emailRule = Validate('email', 'email', 'Must be a valid email')
92
- * const ageRule = Validate('age', 'min', { value: 18 }, 'Must be 18 or older')
93
- * const uniqueRule = Validate('username', 'unique', 'Username already taken')
94
- * ```
95
- */
96
- export function Validate(field, rule, paramsOrMessage, message) {
97
- if (typeof paramsOrMessage === 'string') {
98
- return { field, rule, message: paramsOrMessage };
99
- }
100
- return {
101
- field,
102
- rule,
103
- params: paramsOrMessage,
104
- message,
105
- };
106
- }
package/src/dataset.js DELETED
@@ -1,49 +0,0 @@
1
- /**
2
- * Dataset() - Define a dataset
3
- */
4
- import { registerProduct } from './product.js';
5
- /**
6
- * Create a dataset definition
7
- *
8
- * @example
9
- * ```ts
10
- * const movieDataset = Dataset({
11
- * id: 'movies',
12
- * name: 'Movie Database',
13
- * description: 'Comprehensive movie information dataset',
14
- * version: '2024.1',
15
- * format: 'parquet',
16
- * schema: {
17
- * id: 'Movie ID',
18
- * title: 'Movie title',
19
- * year: 'Release year (number)',
20
- * genres: ['Array of genre names'],
21
- * rating: 'Average rating (number)',
22
- * votes: 'Number of votes (number)',
23
- * },
24
- * source: 's3://datasets/movies.parquet',
25
- * size: 1000000,
26
- * license: 'CC-BY-4.0',
27
- * updateFrequency: 'daily',
28
- * })
29
- * ```
30
- */
31
- export function Dataset(config) {
32
- const dataset = {
33
- type: 'dataset',
34
- id: config.id,
35
- name: config.name,
36
- description: config.description,
37
- version: config.version,
38
- format: config.format || 'json',
39
- schema: config.schema,
40
- source: config.source,
41
- size: config.size,
42
- license: config.license,
43
- updateFrequency: config.updateFrequency || 'static',
44
- metadata: config.metadata,
45
- tags: config.tags,
46
- status: config.status || 'active',
47
- };
48
- return registerProduct(dataset);
49
- }