@demokit-ai/core 0.2.0 → 0.4.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/dist/index.cjs +6463 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2392 -3
- package/dist/index.d.ts +2392 -3
- package/dist/index.js +6387 -4
- package/dist/index.js.map +1 -1
- package/package.json +36 -18
- package/README.md +0 -190
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@demokit-ai/core",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Framework-agnostic demo mode SDK with fetch interception",
|
|
3
|
+
"version": "0.4.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",
|
|
@@ -23,28 +23,46 @@
|
|
|
23
23
|
],
|
|
24
24
|
"scripts": {
|
|
25
25
|
"build": "tsup",
|
|
26
|
-
"dev": "tsup --watch",
|
|
26
|
+
"dev": "tsup --watch --no-dts",
|
|
27
27
|
"test": "vitest",
|
|
28
|
-
"
|
|
28
|
+
"test:coverage": "vitest run --coverage",
|
|
29
|
+
"typecheck": "tsc --noEmit",
|
|
30
|
+
"clean": "rm -rf dist"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@scalar/openapi-parser": "^0.10.0",
|
|
34
|
+
"@scalar/openapi-types": "^0.2.0",
|
|
35
|
+
"zod": "^4.2.1"
|
|
29
36
|
},
|
|
30
37
|
"devDependencies": {
|
|
38
|
+
"@types/node": "^22.10.2",
|
|
39
|
+
"@vitest/coverage-v8": "^2.1.9",
|
|
31
40
|
"tsup": "^8.3.5",
|
|
32
41
|
"typescript": "^5.7.2",
|
|
33
|
-
"vitest": "^2.1.
|
|
42
|
+
"vitest": "^2.1.9"
|
|
34
43
|
},
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
"
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
"
|
|
44
|
+
"peerDependencies": {
|
|
45
|
+
"@ai-sdk/anthropic": "3.0.63",
|
|
46
|
+
"@mastra/core": "1.15.0",
|
|
47
|
+
"@supabase/supabase-js": "2.100.0"
|
|
48
|
+
},
|
|
49
|
+
"peerDependenciesMeta": {
|
|
50
|
+
"@ai-sdk/anthropic": {
|
|
51
|
+
"optional": true
|
|
52
|
+
},
|
|
53
|
+
"@mastra/core": {
|
|
54
|
+
"optional": true
|
|
55
|
+
},
|
|
56
|
+
"@mastra/langfuse": {
|
|
57
|
+
"optional": true
|
|
58
|
+
},
|
|
59
|
+
"@supabase/supabase-js": {
|
|
60
|
+
"optional": true
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
"engines": {
|
|
64
|
+
"node": ">=18"
|
|
48
65
|
},
|
|
66
|
+
"license": "Apache-2.0",
|
|
49
67
|
"sideEffects": false
|
|
50
68
|
}
|
package/README.md
DELETED
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
# @demokit-ai/core
|
|
2
|
-
|
|
3
|
-

|
|
4
|
-

|
|
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
|