kimu-core 0.4.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.
- package/.editorconfig +30 -0
- package/.gitattributes +11 -0
- package/.github/FUNDING.yml +8 -0
- package/.github/copilot-instructions.md +103 -0
- package/.github/kimu-copilot-instructions.md +3779 -0
- package/.github/workflows/deploy-demo.yml +39 -0
- package/AUTHORS.md +20 -0
- package/CHANGELOG.md +20 -0
- package/CODE_GUIDELINES.md +165 -0
- package/CODE_OF_CONDUCT.md +47 -0
- package/CONTRIBUTING.md +62 -0
- package/FUNDING.md +31 -0
- package/ISSUE_GUIDELINES.md +74 -0
- package/LICENSE +17 -0
- package/LICENSE.it.md +17 -0
- package/MPL-2.0.txt +373 -0
- package/NOTICE +65 -0
- package/README-KIMU.md +40 -0
- package/README.it.md +208 -0
- package/README.md +266 -0
- package/SECURITY.md +64 -0
- package/docs/get-started-en.md +207 -0
- package/docs/images/icon.svg +64 -0
- package/docs/images/logo_kimu.png +0 -0
- package/docs/index.md +29 -0
- package/env/dev.config.json +6 -0
- package/env/local.config.json +6 -0
- package/env/prod.config.json +6 -0
- package/env/staging.config.json +6 -0
- package/env/test.config.json +4 -0
- package/icon.svg +10 -0
- package/logo_kimu.png +0 -0
- package/package.json +79 -0
- package/public/favicon.svg +64 -0
- package/public/logo_kimu.svg +1 -0
- package/scripts/build-all-config.js +59 -0
- package/scripts/build-all-core.js +65 -0
- package/scripts/build-all-extensions.js +64 -0
- package/scripts/build-all-modules.js +99 -0
- package/scripts/build-extension.js +60 -0
- package/scripts/clear-kimu-build.js +31 -0
- package/scripts/generate-kimu-build-config.js +79 -0
- package/scripts/install-module.js +162 -0
- package/scripts/list-modules.js +109 -0
- package/scripts/minify-css-assets.js +82 -0
- package/scripts/remove-module.js +122 -0
- package/scripts/utils/fix-imports.js +85 -0
- package/src/assets/index.css +43 -0
- package/src/assets/kimu-style.css +84 -0
- package/src/assets/style.css +116 -0
- package/src/config/kimu-base-config.json +5 -0
- package/src/core/index.ts +47 -0
- package/src/core/kimu-app.ts +76 -0
- package/src/core/kimu-asset-manager.ts +167 -0
- package/src/core/kimu-component-element.ts +325 -0
- package/src/core/kimu-component.ts +33 -0
- package/src/core/kimu-engine.ts +188 -0
- package/src/core/kimu-extension-manager.ts +281 -0
- package/src/core/kimu-global-styles.ts +136 -0
- package/src/core/kimu-module-manager.ts +69 -0
- package/src/core/kimu-module.ts +21 -0
- package/src/core/kimu-path-config.ts +127 -0
- package/src/core/kimu-reactive.ts +196 -0
- package/src/core/kimu-render.ts +91 -0
- package/src/core/kimu-store.ts +147 -0
- package/src/core/kimu-types.ts +65 -0
- package/src/extensions/.gitkeep +0 -0
- package/src/extensions/extensions-manifest.json +13 -0
- package/src/extensions/kimu-home/component.ts +80 -0
- package/src/extensions/kimu-home/lang/en.json +5 -0
- package/src/extensions/kimu-home/lang/it.json +5 -0
- package/src/extensions/kimu-home/style.css +61 -0
- package/src/extensions/kimu-home/view.html +51 -0
- package/src/index.html +26 -0
- package/src/main.ts +68 -0
- package/src/modules/.gitkeep +0 -0
- package/src/modules/README.md +79 -0
- package/src/modules/i18n/README.it.md +63 -0
- package/src/modules/i18n/README.md +63 -0
- package/src/modules/i18n/kimu-global-lang.ts +26 -0
- package/src/modules/i18n/kimu-i18n-service.ts +108 -0
- package/src/modules/i18n/manifest.json +22 -0
- package/src/modules/i18n/module.ts +39 -0
- package/src/modules/modules-manifest.json +12 -0
- package/src/modules-repository/README.md +108 -0
- package/src/modules-repository/api-axios/CHANGELOG.md +48 -0
- package/src/modules-repository/api-axios/QUICK-REFERENCE.md +178 -0
- package/src/modules-repository/api-axios/README.md +304 -0
- package/src/modules-repository/api-axios/api-axios-service.ts +355 -0
- package/src/modules-repository/api-axios/examples.ts +293 -0
- package/src/modules-repository/api-axios/index.ts +19 -0
- package/src/modules-repository/api-axios/interfaces.ts +71 -0
- package/src/modules-repository/api-axios/module.ts +41 -0
- package/src/modules-repository/api-core/CHANGELOG.md +42 -0
- package/src/modules-repository/api-core/QUICK-REFERENCE.md +192 -0
- package/src/modules-repository/api-core/README.md +435 -0
- package/src/modules-repository/api-core/api-core-service.ts +289 -0
- package/src/modules-repository/api-core/examples.ts +432 -0
- package/src/modules-repository/api-core/index.ts +8 -0
- package/src/modules-repository/api-core/interfaces.ts +83 -0
- package/src/modules-repository/api-core/module.ts +30 -0
- package/src/modules-repository/event-bus/README.md +273 -0
- package/src/modules-repository/event-bus/event-bus-service.ts +176 -0
- package/src/modules-repository/event-bus/module.ts +30 -0
- package/src/modules-repository/i18n/README.it.md +63 -0
- package/src/modules-repository/i18n/README.md +63 -0
- package/src/modules-repository/i18n/kimu-global-lang.ts +26 -0
- package/src/modules-repository/i18n/kimu-i18n-service.ts +108 -0
- package/src/modules-repository/i18n/manifest.json +22 -0
- package/src/modules-repository/i18n/module.ts +39 -0
- package/src/modules-repository/notification/README.md +423 -0
- package/src/modules-repository/notification/module.ts +30 -0
- package/src/modules-repository/notification/notification-service.ts +436 -0
- package/src/modules-repository/router/README.it.md +39 -0
- package/src/modules-repository/router/README.md +39 -0
- package/src/modules-repository/router/manifest.json +21 -0
- package/src/modules-repository/router/module.ts +23 -0
- package/src/modules-repository/router/router.ts +144 -0
- package/src/modules-repository/state/README.md +409 -0
- package/src/modules-repository/state/module.ts +30 -0
- package/src/modules-repository/state/state-service.ts +296 -0
- package/src/modules-repository/theme/README.md +267 -0
- package/src/modules-repository/theme/module.ts +30 -0
- package/src/modules-repository/theme/pre-build.js +40 -0
- package/src/modules-repository/theme/theme-service.ts +389 -0
- package/src/modules-repository/theme/themes/theme-cherry-blossom.css +78 -0
- package/src/modules-repository/theme/themes/theme-cozy.css +111 -0
- package/src/modules-repository/theme/themes/theme-cyberpunk.css +150 -0
- package/src/modules-repository/theme/themes/theme-dark.css +79 -0
- package/src/modules-repository/theme/themes/theme-forest.css +171 -0
- package/src/modules-repository/theme/themes/theme-gold.css +100 -0
- package/src/modules-repository/theme/themes/theme-high-contrast.css +126 -0
- package/src/modules-repository/theme/themes/theme-lava.css +101 -0
- package/src/modules-repository/theme/themes/theme-lavender.css +90 -0
- package/src/modules-repository/theme/themes/theme-light.css +79 -0
- package/src/modules-repository/theme/themes/theme-matrix.css +103 -0
- package/src/modules-repository/theme/themes/theme-midnight.css +81 -0
- package/src/modules-repository/theme/themes/theme-nord.css +94 -0
- package/src/modules-repository/theme/themes/theme-ocean.css +84 -0
- package/src/modules-repository/theme/themes/theme-retro80s.css +343 -0
- package/src/modules-repository/theme/themes/theme-sunset.css +62 -0
- package/src/modules-repository/theme/themes-config.d.ts +27 -0
- package/src/modules-repository/theme/themes-config.json +213 -0
- package/src/vite-env.d.ts +1 -0
- package/tsconfig.json +33 -0
- package/vite.config.ts +99 -0
|
@@ -0,0 +1,432 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* KIMU API Core Module - Usage Examples
|
|
3
|
+
* Demonstrates common use cases and patterns
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { apiCoreService } from './api-core-service';
|
|
7
|
+
|
|
8
|
+
// ============================================
|
|
9
|
+
// 1. BASIC CONFIGURATION
|
|
10
|
+
// ============================================
|
|
11
|
+
|
|
12
|
+
export function configureApiService() {
|
|
13
|
+
apiCoreService.configure({
|
|
14
|
+
baseURL: 'https://jsonplaceholder.typicode.com',
|
|
15
|
+
timeout: 10000,
|
|
16
|
+
headers: {
|
|
17
|
+
'Content-Type': 'application/json',
|
|
18
|
+
'Accept': 'application/json'
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// ============================================
|
|
24
|
+
// 2. SIMPLE GET REQUEST
|
|
25
|
+
// ============================================
|
|
26
|
+
|
|
27
|
+
export async function getUsersExample() {
|
|
28
|
+
try {
|
|
29
|
+
const response = await apiCoreService.get('/users');
|
|
30
|
+
console.log('Users:', response.data);
|
|
31
|
+
return response.data;
|
|
32
|
+
} catch (error) {
|
|
33
|
+
console.error('Error fetching users:', error);
|
|
34
|
+
throw error;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// ============================================
|
|
39
|
+
// 3. GET WITH QUERY PARAMETERS
|
|
40
|
+
// ============================================
|
|
41
|
+
|
|
42
|
+
export async function getPostsWithFiltersExample() {
|
|
43
|
+
try {
|
|
44
|
+
const response = await apiCoreService.get('/posts', {
|
|
45
|
+
params: {
|
|
46
|
+
userId: 1,
|
|
47
|
+
_limit: 10
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
console.log('Filtered posts:', response.data);
|
|
51
|
+
return response.data;
|
|
52
|
+
} catch (error) {
|
|
53
|
+
console.error('Error fetching posts:', error);
|
|
54
|
+
throw error;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// ============================================
|
|
59
|
+
// 4. POST REQUEST WITH DATA
|
|
60
|
+
// ============================================
|
|
61
|
+
|
|
62
|
+
export async function createPostExample() {
|
|
63
|
+
try {
|
|
64
|
+
const newPost = {
|
|
65
|
+
title: 'My New Post',
|
|
66
|
+
body: 'This is the content of my post',
|
|
67
|
+
userId: 1
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const response = await apiCoreService.post('/posts', newPost);
|
|
71
|
+
console.log('Created post:', response.data);
|
|
72
|
+
return response.data;
|
|
73
|
+
} catch (error) {
|
|
74
|
+
console.error('Error creating post:', error);
|
|
75
|
+
throw error;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// ============================================
|
|
80
|
+
// 5. PUT REQUEST (UPDATE)
|
|
81
|
+
// ============================================
|
|
82
|
+
|
|
83
|
+
export async function updatePostExample(postId: number) {
|
|
84
|
+
try {
|
|
85
|
+
const updatedPost = {
|
|
86
|
+
id: postId,
|
|
87
|
+
title: 'Updated Post Title',
|
|
88
|
+
body: 'Updated content',
|
|
89
|
+
userId: 1
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const response = await apiCoreService.put(`/posts/${postId}`, updatedPost);
|
|
93
|
+
console.log('Updated post:', response.data);
|
|
94
|
+
return response.data;
|
|
95
|
+
} catch (error) {
|
|
96
|
+
console.error('Error updating post:', error);
|
|
97
|
+
throw error;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// ============================================
|
|
102
|
+
// 6. PATCH REQUEST (PARTIAL UPDATE)
|
|
103
|
+
// ============================================
|
|
104
|
+
|
|
105
|
+
export async function patchPostExample(postId: number) {
|
|
106
|
+
try {
|
|
107
|
+
const response = await apiCoreService.patch(`/posts/${postId}`, {
|
|
108
|
+
title: 'Partially Updated Title'
|
|
109
|
+
});
|
|
110
|
+
console.log('Patched post:', response.data);
|
|
111
|
+
return response.data;
|
|
112
|
+
} catch (error) {
|
|
113
|
+
console.error('Error patching post:', error);
|
|
114
|
+
throw error;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// ============================================
|
|
119
|
+
// 7. DELETE REQUEST
|
|
120
|
+
// ============================================
|
|
121
|
+
|
|
122
|
+
export async function deletePostExample(postId: number) {
|
|
123
|
+
try {
|
|
124
|
+
const response = await apiCoreService.delete(`/posts/${postId}`);
|
|
125
|
+
console.log('Deleted post:', response.status);
|
|
126
|
+
return response;
|
|
127
|
+
} catch (error) {
|
|
128
|
+
console.error('Error deleting post:', error);
|
|
129
|
+
throw error;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// ============================================
|
|
134
|
+
// 8. REQUEST WITH CUSTOM HEADERS
|
|
135
|
+
// ============================================
|
|
136
|
+
|
|
137
|
+
export async function requestWithCustomHeadersExample() {
|
|
138
|
+
try {
|
|
139
|
+
const response = await apiCoreService.get('/users/1', {
|
|
140
|
+
headers: {
|
|
141
|
+
'X-Custom-Header': 'custom-value',
|
|
142
|
+
'Accept-Language': 'it-IT'
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
console.log('User with custom headers:', response.data);
|
|
146
|
+
return response.data;
|
|
147
|
+
} catch (error) {
|
|
148
|
+
console.error('Error with custom headers:', error);
|
|
149
|
+
throw error;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// ============================================
|
|
154
|
+
// 9. REQUEST WITH TIMEOUT
|
|
155
|
+
// ============================================
|
|
156
|
+
|
|
157
|
+
export async function requestWithTimeoutExample() {
|
|
158
|
+
try {
|
|
159
|
+
const response = await apiCoreService.get('/users', {
|
|
160
|
+
timeout: 3000 // 3 seconds
|
|
161
|
+
});
|
|
162
|
+
console.log('Users with timeout:', response.data);
|
|
163
|
+
return response.data;
|
|
164
|
+
} catch (error) {
|
|
165
|
+
console.error('Timeout or error:', error);
|
|
166
|
+
throw error;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// ============================================
|
|
171
|
+
// 10. REQUEST WITH ABORT CONTROLLER
|
|
172
|
+
// ============================================
|
|
173
|
+
|
|
174
|
+
export async function requestWithAbortExample() {
|
|
175
|
+
const controller = new AbortController();
|
|
176
|
+
|
|
177
|
+
// Abort after 2 seconds
|
|
178
|
+
setTimeout(() => {
|
|
179
|
+
console.log('Aborting request...');
|
|
180
|
+
controller.abort();
|
|
181
|
+
}, 2000);
|
|
182
|
+
|
|
183
|
+
try {
|
|
184
|
+
const response = await apiCoreService.get('/users', {
|
|
185
|
+
signal: controller.signal
|
|
186
|
+
});
|
|
187
|
+
console.log('Users:', response.data);
|
|
188
|
+
return response.data;
|
|
189
|
+
} catch (error) {
|
|
190
|
+
console.error('Request aborted or error:', error);
|
|
191
|
+
throw error;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// ============================================
|
|
196
|
+
// 11. USING REQUEST INTERCEPTOR
|
|
197
|
+
// ============================================
|
|
198
|
+
|
|
199
|
+
export function setupRequestInterceptorExample() {
|
|
200
|
+
apiCoreService.configure({
|
|
201
|
+
requestInterceptor: (config) => {
|
|
202
|
+
// Add authentication token
|
|
203
|
+
const token = localStorage.getItem('authToken');
|
|
204
|
+
if (token) {
|
|
205
|
+
config.headers = {
|
|
206
|
+
...config.headers,
|
|
207
|
+
'Authorization': `Bearer ${token}`
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// Log request
|
|
212
|
+
console.log(`[Request] ${config.method} ${config.params}`);
|
|
213
|
+
|
|
214
|
+
return config;
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// ============================================
|
|
220
|
+
// 12. USING RESPONSE INTERCEPTOR
|
|
221
|
+
// ============================================
|
|
222
|
+
|
|
223
|
+
export function setupResponseInterceptorExample() {
|
|
224
|
+
apiCoreService.configure({
|
|
225
|
+
responseInterceptor: (response) => {
|
|
226
|
+
// Log response
|
|
227
|
+
console.log(`[Response] ${response.status} - ${response.statusText}`);
|
|
228
|
+
|
|
229
|
+
// Add metadata
|
|
230
|
+
response.data = {
|
|
231
|
+
...response.data,
|
|
232
|
+
_metadata: {
|
|
233
|
+
receivedAt: new Date().toISOString(),
|
|
234
|
+
status: response.status
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
return response;
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// ============================================
|
|
244
|
+
// 13. USING ERROR INTERCEPTOR
|
|
245
|
+
// ============================================
|
|
246
|
+
|
|
247
|
+
export function setupErrorInterceptorExample() {
|
|
248
|
+
apiCoreService.configure({
|
|
249
|
+
errorInterceptor: async (error) => {
|
|
250
|
+
// Log error
|
|
251
|
+
console.error(`[Error] ${error.status} - ${error.message}`);
|
|
252
|
+
|
|
253
|
+
// Handle 401 Unauthorized
|
|
254
|
+
if (error.status === 401) {
|
|
255
|
+
console.log('Unauthorized, redirecting to login...');
|
|
256
|
+
// window.location.href = '/login';
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// Handle 500 Server Error
|
|
260
|
+
if (error.status && error.status >= 500) {
|
|
261
|
+
console.log('Server error, please try again later');
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
return error;
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
// ============================================
|
|
270
|
+
// 14. TYPED REQUESTS (TypeScript)
|
|
271
|
+
// ============================================
|
|
272
|
+
|
|
273
|
+
interface User {
|
|
274
|
+
id: number;
|
|
275
|
+
name: string;
|
|
276
|
+
email: string;
|
|
277
|
+
username: string;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
interface Post {
|
|
281
|
+
id: number;
|
|
282
|
+
userId: number;
|
|
283
|
+
title: string;
|
|
284
|
+
body: string;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
export async function typedRequestsExample() {
|
|
288
|
+
// Type-safe GET
|
|
289
|
+
const usersResponse = await apiCoreService.get<User[]>('/users');
|
|
290
|
+
usersResponse.data.forEach(user => {
|
|
291
|
+
console.log(user.name); // Type-safe access
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
// Type-safe POST
|
|
295
|
+
const newPost: Omit<Post, 'id'> = {
|
|
296
|
+
userId: 1,
|
|
297
|
+
title: 'New Post',
|
|
298
|
+
body: 'Content'
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
const postResponse = await apiCoreService.post<Post>('/posts', newPost);
|
|
302
|
+
console.log(postResponse.data.id); // Type-safe
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
// ============================================
|
|
306
|
+
// 15. ERROR HANDLING EXAMPLE
|
|
307
|
+
// ============================================
|
|
308
|
+
|
|
309
|
+
export async function errorHandlingExample() {
|
|
310
|
+
try {
|
|
311
|
+
const response = await apiCoreService.get('/invalid-endpoint');
|
|
312
|
+
console.log(response.data);
|
|
313
|
+
} catch (error: any) {
|
|
314
|
+
// Access ApiError properties
|
|
315
|
+
console.error('Error message:', error.message);
|
|
316
|
+
console.error('HTTP status:', error.status);
|
|
317
|
+
console.error('Status text:', error.statusText);
|
|
318
|
+
console.error('Response data:', error.data);
|
|
319
|
+
console.error('Original error:', error.originalError);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
// ============================================
|
|
324
|
+
// 16. COMPLETE EXAMPLE: USER SERVICE
|
|
325
|
+
// ============================================
|
|
326
|
+
|
|
327
|
+
export class UserService {
|
|
328
|
+
private api = apiCoreService;
|
|
329
|
+
|
|
330
|
+
constructor() {
|
|
331
|
+
// Configure service
|
|
332
|
+
this.api.configure({
|
|
333
|
+
baseURL: 'https://jsonplaceholder.typicode.com'
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
async getAll(): Promise<User[]> {
|
|
338
|
+
const response = await this.api.get<User[]>('/users');
|
|
339
|
+
return response.data;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
async getById(id: number): Promise<User> {
|
|
343
|
+
const response = await this.api.get<User>(`/users/${id}`);
|
|
344
|
+
return response.data;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
async create(user: Omit<User, 'id'>): Promise<User> {
|
|
348
|
+
const response = await this.api.post<User>('/users', user);
|
|
349
|
+
return response.data;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
async update(id: number, user: Partial<User>): Promise<User> {
|
|
353
|
+
const response = await this.api.patch<User>(`/users/${id}`, user);
|
|
354
|
+
return response.data;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
async delete(id: number): Promise<void> {
|
|
358
|
+
await this.api.delete(`/users/${id}`);
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
async search(query: string): Promise<User[]> {
|
|
362
|
+
const response = await this.api.get<User[]>('/users', {
|
|
363
|
+
params: { q: query }
|
|
364
|
+
});
|
|
365
|
+
return response.data;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
// ============================================
|
|
370
|
+
// 17. USAGE IN KIMU COMPONENT
|
|
371
|
+
// ============================================
|
|
372
|
+
|
|
373
|
+
/*
|
|
374
|
+
import { KimuComponentElement } from '@kimu/core';
|
|
375
|
+
import { KimuModuleManager } from '@kimu/core';
|
|
376
|
+
|
|
377
|
+
export class UserListComponent extends KimuComponentElement {
|
|
378
|
+
private api: any;
|
|
379
|
+
private users: User[] = [];
|
|
380
|
+
private loading = false;
|
|
381
|
+
private error: string | null = null;
|
|
382
|
+
|
|
383
|
+
async onInit() {
|
|
384
|
+
// Get API service
|
|
385
|
+
this.api = KimuModuleManager.getInstance().getService('api-core');
|
|
386
|
+
|
|
387
|
+
// Configure
|
|
388
|
+
this.api.configure({
|
|
389
|
+
baseURL: 'https://jsonplaceholder.typicode.com'
|
|
390
|
+
});
|
|
391
|
+
|
|
392
|
+
// Load data
|
|
393
|
+
await this.loadUsers();
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
async loadUsers() {
|
|
397
|
+
this.loading = true;
|
|
398
|
+
this.error = null;
|
|
399
|
+
this.onRender();
|
|
400
|
+
|
|
401
|
+
try {
|
|
402
|
+
const response = await this.api.get<User[]>('/users');
|
|
403
|
+
this.users = response.data;
|
|
404
|
+
} catch (error: any) {
|
|
405
|
+
this.error = error.message;
|
|
406
|
+
} finally {
|
|
407
|
+
this.loading = false;
|
|
408
|
+
this.onRender();
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
async createUser(userData: Omit<User, 'id'>) {
|
|
413
|
+
try {
|
|
414
|
+
const response = await this.api.post<User>('/users', userData);
|
|
415
|
+
this.users.push(response.data);
|
|
416
|
+
this.onRender();
|
|
417
|
+
} catch (error: any) {
|
|
418
|
+
console.error('Failed to create user:', error);
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
async deleteUser(id: number) {
|
|
423
|
+
try {
|
|
424
|
+
await this.api.delete(`/users/${id}`);
|
|
425
|
+
this.users = this.users.filter(u => u.id !== id);
|
|
426
|
+
this.onRender();
|
|
427
|
+
} catch (error: any) {
|
|
428
|
+
console.error('Failed to delete user:', error);
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
*/
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* KIMU API Core Module - Type Definitions
|
|
3
|
+
* Provides interfaces for HTTP API interactions
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* HTTP methods supported by the API service
|
|
8
|
+
*/
|
|
9
|
+
export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Configuration options for API requests
|
|
13
|
+
*/
|
|
14
|
+
export interface ApiRequestOptions {
|
|
15
|
+
/** HTTP method (default: GET) */
|
|
16
|
+
method?: HttpMethod;
|
|
17
|
+
/** Request headers */
|
|
18
|
+
headers?: Record<string, string>;
|
|
19
|
+
/** Request body (will be JSON stringified if object) */
|
|
20
|
+
body?: any;
|
|
21
|
+
/** Query parameters to append to URL */
|
|
22
|
+
params?: Record<string, string | number | boolean>;
|
|
23
|
+
/** Request timeout in milliseconds */
|
|
24
|
+
timeout?: number;
|
|
25
|
+
/** Response type expected */
|
|
26
|
+
responseType?: 'json' | 'text' | 'blob' | 'arraybuffer';
|
|
27
|
+
/** Credentials mode for fetch */
|
|
28
|
+
credentials?: RequestCredentials;
|
|
29
|
+
/** Cache mode for fetch */
|
|
30
|
+
cache?: RequestCache;
|
|
31
|
+
/** Abort signal for cancellation */
|
|
32
|
+
signal?: AbortSignal;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Response structure returned by API calls
|
|
37
|
+
*/
|
|
38
|
+
export interface ApiResponse<T = any> {
|
|
39
|
+
/** Response data */
|
|
40
|
+
data: T;
|
|
41
|
+
/** HTTP status code */
|
|
42
|
+
status: number;
|
|
43
|
+
/** HTTP status text */
|
|
44
|
+
statusText: string;
|
|
45
|
+
/** Response headers */
|
|
46
|
+
headers: Headers;
|
|
47
|
+
/** Original fetch Response object */
|
|
48
|
+
raw: Response;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Error structure for failed API calls
|
|
53
|
+
*/
|
|
54
|
+
export interface ApiError {
|
|
55
|
+
/** Error message */
|
|
56
|
+
message: string;
|
|
57
|
+
/** HTTP status code (if available) */
|
|
58
|
+
status?: number;
|
|
59
|
+
/** HTTP status text (if available) */
|
|
60
|
+
statusText?: string;
|
|
61
|
+
/** Response data (if available) */
|
|
62
|
+
data?: any;
|
|
63
|
+
/** Original error object */
|
|
64
|
+
originalError: Error;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Global configuration for API service
|
|
69
|
+
*/
|
|
70
|
+
export interface ApiConfig {
|
|
71
|
+
/** Base URL for all requests */
|
|
72
|
+
baseURL?: string;
|
|
73
|
+
/** Default timeout in milliseconds */
|
|
74
|
+
timeout?: number;
|
|
75
|
+
/** Default headers for all requests */
|
|
76
|
+
headers?: Record<string, string>;
|
|
77
|
+
/** Request interceptor function */
|
|
78
|
+
requestInterceptor?: (config: ApiRequestOptions) => ApiRequestOptions | Promise<ApiRequestOptions>;
|
|
79
|
+
/** Response interceptor function */
|
|
80
|
+
responseInterceptor?: <T>(response: ApiResponse<T>) => ApiResponse<T> | Promise<ApiResponse<T>>;
|
|
81
|
+
/** Error interceptor function */
|
|
82
|
+
errorInterceptor?: (error: ApiError) => ApiError | Promise<ApiError>;
|
|
83
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* KIMU API Core Module
|
|
3
|
+
* Entry point for the API Core module
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { KimuModule } from '../../core/kimu-module';
|
|
7
|
+
import { apiCoreService } from './api-core-service';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* API Core Module Class
|
|
11
|
+
* Provides HTTP client functionality based on native fetch API
|
|
12
|
+
*/
|
|
13
|
+
export default class ApiCoreModule extends KimuModule {
|
|
14
|
+
constructor(name = 'api-core', version = '1.0.0', options?: any) {
|
|
15
|
+
super(name, version, options);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Get the API Core service instance
|
|
20
|
+
* @returns ApiCoreService singleton instance
|
|
21
|
+
*/
|
|
22
|
+
getService() {
|
|
23
|
+
return apiCoreService;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Re-export for convenience
|
|
28
|
+
export { apiCoreService } from './api-core-service';
|
|
29
|
+
export { ApiCoreService } from './api-core-service';
|
|
30
|
+
export * from './interfaces';
|