@kb-labs/studio-data-client 0.2.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/README.md +210 -0
- package/dist/index.d.ts +2755 -0
- package/dist/index.js +3961 -0
- package/dist/index.js.map +1 -0
- package/package.json +61 -0
package/README.md
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
# @kb-labs/data-client
|
|
2
|
+
|
|
3
|
+
KB Labs Studio data client — API SDK with versioned contracts, mocks, and TanStack Query hooks.
|
|
4
|
+
|
|
5
|
+
## Vision & Purpose
|
|
6
|
+
|
|
7
|
+
**@kb-labs/data-client** provides API SDK for KB Labs Studio. It includes versioned contracts, mocks, and TanStack Query hooks for data fetching and state management.
|
|
8
|
+
|
|
9
|
+
### Core Goals
|
|
10
|
+
|
|
11
|
+
- **API SDK**: Type-safe API client for Studio
|
|
12
|
+
- **Versioned Contracts**: Versioned API contracts
|
|
13
|
+
- **Mocks**: Mock data sources for development
|
|
14
|
+
- **TanStack Query Hooks**: React hooks for data fetching
|
|
15
|
+
|
|
16
|
+
## Package Status
|
|
17
|
+
|
|
18
|
+
- **Version**: 0.1.0
|
|
19
|
+
- **Stage**: Stable
|
|
20
|
+
- **Status**: Production Ready ✅
|
|
21
|
+
|
|
22
|
+
## Architecture
|
|
23
|
+
|
|
24
|
+
### High-Level Overview
|
|
25
|
+
|
|
26
|
+
```
|
|
27
|
+
Data Client
|
|
28
|
+
│
|
|
29
|
+
├──► HTTP Client
|
|
30
|
+
├──► Sources
|
|
31
|
+
├──► Hooks
|
|
32
|
+
├──► Contracts
|
|
33
|
+
├──► Schemas
|
|
34
|
+
└──► Mocks
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Key Components
|
|
38
|
+
|
|
39
|
+
1. **HTTP Client** (`client/`): HTTP client implementation
|
|
40
|
+
2. **Sources** (`sources/`): Data sources (audit, release, system, workflows)
|
|
41
|
+
3. **Hooks** (`hooks/`): TanStack Query hooks
|
|
42
|
+
4. **Contracts** (`contracts/`): API contracts
|
|
43
|
+
5. **Schemas** (`schemas/`): Zod schemas for validation
|
|
44
|
+
6. **Mocks** (`mocks/`): Mock data sources
|
|
45
|
+
|
|
46
|
+
## ✨ Features
|
|
47
|
+
|
|
48
|
+
- **API SDK**: Type-safe API client for Studio
|
|
49
|
+
- **Versioned Contracts**: Versioned API contracts
|
|
50
|
+
- **Mocks**: Mock data sources for development
|
|
51
|
+
- **TanStack Query Hooks**: React hooks for data fetching (useAudit, useRelease, useSystem, useWorkflows)
|
|
52
|
+
- **Error Handling**: Unified error handling
|
|
53
|
+
- **Envelope Interceptor**: Response envelope interceptor
|
|
54
|
+
|
|
55
|
+
## 📦 API Reference
|
|
56
|
+
|
|
57
|
+
### Main Exports
|
|
58
|
+
|
|
59
|
+
#### HTTP Client
|
|
60
|
+
|
|
61
|
+
- `createHttpClient`: Create HTTP client instance
|
|
62
|
+
- `HttpClient`: HTTP client class
|
|
63
|
+
|
|
64
|
+
#### Sources
|
|
65
|
+
|
|
66
|
+
- `AuditSource`: Audit data source
|
|
67
|
+
- `ReleaseSource`: Release data source
|
|
68
|
+
- `SystemSource`: System data source
|
|
69
|
+
- `WorkflowSource`: Workflow data source
|
|
70
|
+
|
|
71
|
+
#### Hooks
|
|
72
|
+
|
|
73
|
+
- `useAudit`: Audit data hook
|
|
74
|
+
- `useRelease`: Release data hook
|
|
75
|
+
- `useSystem`: System data hook
|
|
76
|
+
- `useWorkflows`: Workflows data hook
|
|
77
|
+
- `useJobEvents`: Job events hook
|
|
78
|
+
|
|
79
|
+
#### Contracts
|
|
80
|
+
|
|
81
|
+
- `AuditContract`: Audit contract
|
|
82
|
+
- `ReleaseContract`: Release contract
|
|
83
|
+
- `SystemContract`: System contract
|
|
84
|
+
- `WorkflowContract`: Workflow contract
|
|
85
|
+
|
|
86
|
+
## 🔧 Configuration
|
|
87
|
+
|
|
88
|
+
### Configuration Options
|
|
89
|
+
|
|
90
|
+
All configuration via HTTP client factory.
|
|
91
|
+
|
|
92
|
+
## 🔗 Dependencies
|
|
93
|
+
|
|
94
|
+
### Runtime Dependencies
|
|
95
|
+
|
|
96
|
+
- `@tanstack/react-query` (`^5.62.23`): React Query
|
|
97
|
+
- `@kb-labs/api-contracts` (`link:../../../kb-labs-rest-api/packages/api-contracts`): API contracts
|
|
98
|
+
- `zod` (`^3.24.1`): Schema validation
|
|
99
|
+
- `ulid` (`^2.3.0`): ULID generation
|
|
100
|
+
|
|
101
|
+
### Development Dependencies
|
|
102
|
+
|
|
103
|
+
- `@kb-labs/devkit` (`file:../../../kb-labs-devkit`): DevKit presets
|
|
104
|
+
- `@types/node` (`^22.10.0`): Node.js types
|
|
105
|
+
- `@types/react` (`^18.3.18`): React types
|
|
106
|
+
- `react` (`^18.3.1`): React
|
|
107
|
+
- `tsup` (`^8`): TypeScript bundler
|
|
108
|
+
- `typescript` (`^5`): TypeScript compiler
|
|
109
|
+
- `vitest` (`^3.2.4`): Test runner
|
|
110
|
+
|
|
111
|
+
## 🧪 Testing
|
|
112
|
+
|
|
113
|
+
### Test Structure
|
|
114
|
+
|
|
115
|
+
```
|
|
116
|
+
src/sources/__tests__/
|
|
117
|
+
└── http-workflow-source.spec.ts
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### Test Coverage
|
|
121
|
+
|
|
122
|
+
- **Current Coverage**: ~70%
|
|
123
|
+
- **Target Coverage**: 90%
|
|
124
|
+
|
|
125
|
+
## 📈 Performance
|
|
126
|
+
|
|
127
|
+
### Performance Characteristics
|
|
128
|
+
|
|
129
|
+
- **Time Complexity**: O(1) for client creation, O(n) for data fetching
|
|
130
|
+
- **Space Complexity**: O(1)
|
|
131
|
+
- **Bottlenecks**: Network requests
|
|
132
|
+
|
|
133
|
+
## 🔒 Security
|
|
134
|
+
|
|
135
|
+
### Security Considerations
|
|
136
|
+
|
|
137
|
+
- **API Authentication**: Secure API authentication
|
|
138
|
+
- **Request Validation**: Request validation via schemas
|
|
139
|
+
|
|
140
|
+
### Known Vulnerabilities
|
|
141
|
+
|
|
142
|
+
- None
|
|
143
|
+
|
|
144
|
+
## 🐛 Known Issues & Limitations
|
|
145
|
+
|
|
146
|
+
### Known Issues
|
|
147
|
+
|
|
148
|
+
- None currently
|
|
149
|
+
|
|
150
|
+
### Limitations
|
|
151
|
+
|
|
152
|
+
- **Source Types**: Fixed source types
|
|
153
|
+
- **API Types**: Fixed API types
|
|
154
|
+
|
|
155
|
+
### Future Improvements
|
|
156
|
+
|
|
157
|
+
- **More Source Types**: Additional source types
|
|
158
|
+
- **Caching**: Enhanced caching support
|
|
159
|
+
|
|
160
|
+
## 🔄 Migration & Breaking Changes
|
|
161
|
+
|
|
162
|
+
### Migration from Previous Versions
|
|
163
|
+
|
|
164
|
+
No breaking changes in current version (0.1.0).
|
|
165
|
+
|
|
166
|
+
### Breaking Changes in Future Versions
|
|
167
|
+
|
|
168
|
+
- None planned
|
|
169
|
+
|
|
170
|
+
## 📚 Examples
|
|
171
|
+
|
|
172
|
+
### Example 1: Use HTTP Client
|
|
173
|
+
|
|
174
|
+
```typescript
|
|
175
|
+
import { createHttpClient } from '@kb-labs/data-client';
|
|
176
|
+
|
|
177
|
+
const client = createHttpClient({
|
|
178
|
+
baseURL: 'https://api.example.com',
|
|
179
|
+
});
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
### Example 2: Use Hooks
|
|
183
|
+
|
|
184
|
+
```typescript
|
|
185
|
+
import { useAudit, useRelease } from '@kb-labs/data-client';
|
|
186
|
+
|
|
187
|
+
function MyComponent() {
|
|
188
|
+
const { data: audit } = useAudit();
|
|
189
|
+
const { data: release } = useRelease();
|
|
190
|
+
|
|
191
|
+
return <div>...</div>;
|
|
192
|
+
}
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
### Example 3: Use Mocks
|
|
196
|
+
|
|
197
|
+
```typescript
|
|
198
|
+
import { createMockAuditSource } from '@kb-labs/data-client';
|
|
199
|
+
|
|
200
|
+
const mockSource = createMockAuditSource();
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
## 🤝 Contributing
|
|
204
|
+
|
|
205
|
+
See [CONTRIBUTING.md](../../CONTRIBUTING.md) for development guidelines.
|
|
206
|
+
|
|
207
|
+
## 📄 License
|
|
208
|
+
|
|
209
|
+
MIT © KB Labs
|
|
210
|
+
|