@demokit-ai/core 0.2.0 → 0.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.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@demokit-ai/core",
3
- "version": "0.2.0",
4
- "description": "Framework-agnostic demo mode SDK with fetch interception",
3
+ "version": "0.3.0",
4
+ "description": "Framework-agnostic demo mode SDK with fetch interception and fixture generation",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
7
7
  "module": "./dist/index.js",
@@ -21,30 +21,49 @@
21
21
  "files": [
22
22
  "dist"
23
23
  ],
24
- "scripts": {
25
- "build": "tsup",
26
- "dev": "tsup --watch",
27
- "test": "vitest",
28
- "typecheck": "tsc --noEmit"
24
+ "dependencies": {
25
+ "@scalar/openapi-parser": "^0.10.0",
26
+ "@scalar/openapi-types": "^0.2.0",
27
+ "zod": "^3.24.0"
29
28
  },
30
29
  "devDependencies": {
30
+ "@types/node": "^22.10.2",
31
+ "@vitest/coverage-v8": "^2.1.9",
31
32
  "tsup": "^8.3.5",
32
33
  "typescript": "^5.7.2",
33
- "vitest": "^2.1.8"
34
+ "vitest": "^2.1.9"
34
35
  },
35
- "keywords": [
36
- "demo",
37
- "mock",
38
- "api",
39
- "fetch",
40
- "interceptor",
41
- "saas"
42
- ],
43
- "license": "MIT",
44
- "repository": {
45
- "type": "git",
46
- "url": "https://github.com/your-org/demokit",
47
- "directory": "packages/core"
36
+ "peerDependencies": {
37
+ "@ai-sdk/anthropic": ">=1.0.0",
38
+ "@mastra/core": ">=1.0.0-beta.0",
39
+ "@mastra/langfuse": ">=0.2.0",
40
+ "@supabase/supabase-js": ">=2.0.0"
41
+ },
42
+ "peerDependenciesMeta": {
43
+ "@ai-sdk/anthropic": {
44
+ "optional": true
45
+ },
46
+ "@mastra/core": {
47
+ "optional": true
48
+ },
49
+ "@mastra/langfuse": {
50
+ "optional": true
51
+ },
52
+ "@supabase/supabase-js": {
53
+ "optional": true
54
+ }
55
+ },
56
+ "engines": {
57
+ "node": ">=18"
48
58
  },
49
- "sideEffects": false
50
- }
59
+ "license": "Apache-2.0",
60
+ "sideEffects": false,
61
+ "scripts": {
62
+ "build": "tsup",
63
+ "dev": "tsup --watch --no-dts",
64
+ "test": "vitest",
65
+ "test:coverage": "vitest run --coverage",
66
+ "typecheck": "tsc --noEmit",
67
+ "clean": "rm -rf dist"
68
+ }
69
+ }
package/README.md DELETED
@@ -1,190 +0,0 @@
1
- # @demokit-ai/core
2
-
3
- ![Tests](https://img.shields.io/badge/tests-154%20passing-brightgreen)
4
- ![Coverage](https://img.shields.io/badge/coverage-36%25-red)
5
-
6
- Framework-agnostic demo mode SDK with fetch interception. The foundation for all DemoKit adapters.
7
-
8
- ## Installation
9
-
10
- ```bash
11
- npm install @demokit-ai/core
12
- ```
13
-
14
- ## Features
15
-
16
- - **Fetch Interception** - Intercept and mock API calls at the network level
17
- - **Session Management** - Manage demo mode state with storage adapters
18
- - **State Machine** - Declarative demo state management
19
- - **Scenario Support** - Define and switch between demo scenarios
20
- - **Framework Agnostic** - Works with any JavaScript framework
21
- - Full TypeScript support
22
-
23
- ## Usage
24
-
25
- ### Basic Fetch Interception
26
-
27
- ```ts
28
- import { createDemoInterceptor, enableDemoMode } from '@demokit-ai/core'
29
-
30
- const interceptor = createDemoInterceptor({
31
- fixtures: {
32
- '/api/users': [
33
- { id: '1', name: 'Demo User' },
34
- { id: '2', name: 'Another User' },
35
- ],
36
- '/api/users/:id': (req) => ({
37
- id: req.params.id,
38
- name: 'Demo User',
39
- email: 'demo@example.com',
40
- }),
41
- },
42
- })
43
-
44
- // Enable demo mode
45
- enableDemoMode()
46
-
47
- // All fetch calls to matched routes will return fixtures
48
- const response = await fetch('/api/users')
49
- const users = await response.json()
50
- // [{ id: '1', name: 'Demo User' }, ...]
51
- ```
52
-
53
- ### Session Management
54
-
55
- ```ts
56
- import { createDemoSession, DemoSession } from '@demokit-ai/core'
57
-
58
- const session = createDemoSession({
59
- storage: 'localStorage', // or 'sessionStorage', 'memory', custom adapter
60
- key: 'demo-mode',
61
- })
62
-
63
- // Check if demo mode is active
64
- if (session.isActive()) {
65
- console.log('Demo mode is enabled')
66
- }
67
-
68
- // Toggle demo mode
69
- session.toggle()
70
-
71
- // Set with expiry
72
- session.enable({ expiresIn: 3600000 }) // 1 hour
73
- ```
74
-
75
- ### State Management
76
-
77
- ```ts
78
- import { createDemoState } from '@demokit-ai/core'
79
-
80
- const state = createDemoState({
81
- initial: {
82
- user: null,
83
- features: ['basic'],
84
- },
85
- scenarios: {
86
- free: { user: { plan: 'free' }, features: ['basic'] },
87
- pro: { user: { plan: 'pro' }, features: ['basic', 'advanced'] },
88
- enterprise: { user: { plan: 'enterprise' }, features: ['basic', 'advanced', 'enterprise'] },
89
- },
90
- })
91
-
92
- // Switch scenarios
93
- state.setScenario('pro')
94
-
95
- // Get current state
96
- const { user, features } = state.get()
97
-
98
- // Subscribe to changes
99
- state.subscribe((newState) => {
100
- console.log('Demo state changed:', newState)
101
- })
102
- ```
103
-
104
- ### URL-based Activation
105
-
106
- ```ts
107
- import { createUrlActivator } from '@demokit-ai/core'
108
-
109
- const activator = createUrlActivator({
110
- param: 'demo', // ?demo=true or ?demo=enterprise
111
- scenarios: {
112
- true: 'default',
113
- enterprise: 'enterprise',
114
- },
115
- })
116
-
117
- // Check URL and activate if param present
118
- activator.check(window.location.href)
119
- ```
120
-
121
- ### Custom Storage Adapter
122
-
123
- ```ts
124
- import { createDemoSession, StorageAdapter } from '@demokit-ai/core'
125
-
126
- const customStorage: StorageAdapter = {
127
- get: (key) => myDatabase.get(key),
128
- set: (key, value) => myDatabase.set(key, value),
129
- remove: (key) => myDatabase.delete(key),
130
- }
131
-
132
- const session = createDemoSession({
133
- storage: customStorage,
134
- })
135
- ```
136
-
137
- ## API Reference
138
-
139
- ### Interceptor
140
-
141
- #### `createDemoInterceptor(options)`
142
-
143
- Creates a fetch interceptor for demo mode.
144
-
145
- Options:
146
- - `fixtures` - Route fixtures (static or function)
147
- - `delay` - Simulated network delay in ms
148
- - `onIntercept` - Callback when a request is intercepted
149
- - `shouldIntercept` - Custom function to determine if request should be intercepted
150
-
151
- ### Session
152
-
153
- #### `createDemoSession(options)`
154
-
155
- Creates a demo session manager.
156
-
157
- Options:
158
- - `storage` - Storage adapter ('localStorage', 'sessionStorage', 'memory', or custom)
159
- - `key` - Storage key name
160
- - `defaultScenario` - Default scenario name
161
-
162
- Returns:
163
- - `isActive()` - Check if demo mode is enabled
164
- - `enable(options?)` - Enable demo mode
165
- - `disable()` - Disable demo mode
166
- - `toggle()` - Toggle demo mode
167
- - `getScenario()` - Get current scenario
168
- - `setScenario(name)` - Set scenario
169
-
170
- ### State
171
-
172
- #### `createDemoState(options)`
173
-
174
- Creates a demo state manager.
175
-
176
- Options:
177
- - `initial` - Initial state object
178
- - `scenarios` - Named scenario configurations
179
- - `onChange` - Callback when state changes
180
-
181
- Returns:
182
- - `get()` - Get current state
183
- - `set(state)` - Set state
184
- - `setScenario(name)` - Switch to named scenario
185
- - `subscribe(callback)` - Subscribe to state changes
186
- - `reset()` - Reset to initial state
187
-
188
- ## License
189
-
190
- MIT