kimu-core 0.4.1 → 0.5.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/.editorconfig +116 -30
- package/.gitattributes +81 -11
- package/.github/FUNDING.yml +8 -8
- package/.github/kimu-copilot-instructions.md +3779 -3779
- package/.github/workflows/deploy-demo.yml +39 -39
- package/.nvmrc +1 -0
- package/.prettierignore +44 -0
- package/.prettierrc +16 -0
- package/FUNDING.md +31 -31
- package/icon.svg +10 -10
- package/kimu-core-0.5.0.tgz +0 -0
- package/package.json +10 -3
- package/scripts/minify-css-assets.js +82 -82
- package/src/core/index.ts +47 -47
- package/src/core/kimu-global-styles.ts +136 -136
- package/src/core/kimu-reactive.ts +196 -196
- package/src/extensions/{kimu-home → app-root}/component.ts +5 -5
- package/src/extensions/extensions-manifest.json +4 -4
- package/src/main.ts +3 -3
- package/src/modules-repository/api-axios/CHANGELOG.md +48 -48
- package/src/modules-repository/api-axios/QUICK-REFERENCE.md +178 -178
- package/src/modules-repository/api-axios/README.md +304 -304
- package/src/modules-repository/api-axios/api-axios-service.ts +355 -355
- package/src/modules-repository/api-axios/examples.ts +293 -293
- package/src/modules-repository/api-axios/index.ts +19 -19
- package/src/modules-repository/api-axios/interfaces.ts +71 -71
- package/src/modules-repository/api-axios/module.ts +41 -41
- package/src/modules-repository/api-core/CHANGELOG.md +42 -42
- package/src/modules-repository/api-core/QUICK-REFERENCE.md +192 -192
- package/src/modules-repository/api-core/README.md +435 -435
- package/src/modules-repository/api-core/api-core-service.ts +289 -289
- package/src/modules-repository/api-core/examples.ts +432 -432
- package/src/modules-repository/api-core/index.ts +8 -8
- package/src/modules-repository/api-core/interfaces.ts +83 -83
- package/src/modules-repository/api-core/module.ts +30 -30
- package/src/modules-repository/event-bus/README.md +273 -273
- package/src/modules-repository/event-bus/event-bus-service.ts +176 -176
- package/src/modules-repository/event-bus/module.ts +30 -30
- package/src/modules-repository/notification/README.md +423 -423
- package/src/modules-repository/notification/module.ts +30 -30
- package/src/modules-repository/notification/notification-service.ts +436 -436
- package/src/modules-repository/router/README.it.md +61 -10
- package/src/modules-repository/router/README.md +61 -10
- package/src/modules-repository/router/router-config.ts.example +61 -0
- package/src/modules-repository/router/router.ts +18 -0
- package/src/modules-repository/state/README.md +409 -409
- package/src/modules-repository/state/module.ts +30 -30
- package/src/modules-repository/state/state-service.ts +296 -296
- package/src/modules-repository/theme/README.md +311 -267
- package/src/modules-repository/theme/module.ts +30 -30
- package/src/modules-repository/theme/pre-build.js +40 -40
- package/src/modules-repository/theme/theme-service.ts +411 -389
- package/src/modules-repository/theme/themes/theme-cherry-blossom.css +78 -78
- package/src/modules-repository/theme/themes/theme-cozy.css +111 -111
- package/src/modules-repository/theme/themes/theme-cyberpunk.css +150 -150
- package/src/modules-repository/theme/themes/theme-dark.css +79 -79
- package/src/modules-repository/theme/themes/theme-forest.css +171 -171
- package/src/modules-repository/theme/themes/theme-gold.css +100 -100
- package/src/modules-repository/theme/themes/theme-high-contrast.css +126 -126
- package/src/modules-repository/theme/themes/theme-lava.css +101 -101
- package/src/modules-repository/theme/themes/theme-lavender.css +90 -90
- package/src/modules-repository/theme/themes/theme-light.css +79 -79
- package/src/modules-repository/theme/themes/theme-matrix.css +103 -103
- package/src/modules-repository/theme/themes/theme-midnight.css +81 -81
- package/src/modules-repository/theme/themes/theme-nord.css +94 -94
- package/src/modules-repository/theme/themes/theme-ocean.css +84 -84
- package/src/modules-repository/theme/themes/theme-retro80s.css +343 -343
- package/src/modules-repository/theme/themes/theme-sunset.css +62 -62
- package/src/modules-repository/theme/themes-config-default.json +19 -0
- package/src/modules-repository/theme/themes-config.d.ts +27 -27
- package/src/modules-repository/theme/{themes-config.json → themes-config.json.example} +223 -213
- /package/src/extensions/{kimu-home → app-root}/lang/en.json +0 -0
- /package/src/extensions/{kimu-home → app-root}/lang/it.json +0 -0
- /package/src/extensions/{kimu-home → app-root}/style.css +0 -0
- /package/src/extensions/{kimu-home → app-root}/view.html +0 -0
|
@@ -8,11 +8,11 @@ import { KimuComponentElement } from '../../core/kimu-component-element';
|
|
|
8
8
|
import { KimuGlobalLang, KimuI18nService } from '../../modules/i18n/module';
|
|
9
9
|
|
|
10
10
|
@KimuComponent({
|
|
11
|
-
tag: '
|
|
12
|
-
path: '
|
|
13
|
-
name: '
|
|
11
|
+
tag: 'app-root',
|
|
12
|
+
path: 'app-root',
|
|
13
|
+
name: 'Application Root',
|
|
14
14
|
version: '1.0.0',
|
|
15
|
-
description: 'Main
|
|
15
|
+
description: 'Main application root component',
|
|
16
16
|
icon: '🏠',
|
|
17
17
|
author: 'UnicòVerso',
|
|
18
18
|
kimuVersion: '1.0.0',
|
|
@@ -24,7 +24,7 @@ import { KimuGlobalLang, KimuI18nService } from '../../modules/i18n/module';
|
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
})
|
|
27
|
-
export class
|
|
27
|
+
export class AppRootComponent extends KimuComponentElement {
|
|
28
28
|
|
|
29
29
|
/** I18n service instance for translations */
|
|
30
30
|
private i18n = new KimuI18nService(
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
[
|
|
2
2
|
{
|
|
3
|
-
"tag": "
|
|
4
|
-
"path": "
|
|
3
|
+
"tag": "app-root",
|
|
4
|
+
"path": "app-root",
|
|
5
5
|
"internal": true,
|
|
6
|
-
"name": "
|
|
7
|
-
"description": "Main
|
|
6
|
+
"name": "Application Root",
|
|
7
|
+
"description": "Main application root component",
|
|
8
8
|
"version": "1.0.0",
|
|
9
9
|
"author": "UnicòVerso",
|
|
10
10
|
"icon": "🏠",
|
package/src/main.ts
CHANGED
|
@@ -41,9 +41,9 @@ async function main() {
|
|
|
41
41
|
|
|
42
42
|
// Mount the extensions
|
|
43
43
|
// Load the main component of the Kimu application
|
|
44
|
-
// The main component is the one that has the tag name '
|
|
45
|
-
console.log('[KIMU-MAIN] 🚀 Loading
|
|
46
|
-
const mainAppExtensions = '
|
|
44
|
+
// The main component is the one that has the tag name 'app-root'
|
|
45
|
+
console.log('[KIMU-MAIN] 🚀 Loading app-root extension...');
|
|
46
|
+
const mainAppExtensions = 'app-root';
|
|
47
47
|
|
|
48
48
|
try {
|
|
49
49
|
await kimuExtensionManager.load(mainAppExtensions);
|
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
# Changelog - API Axios Module
|
|
2
|
-
|
|
3
|
-
All notable changes to the api-axios module will be documented in this file.
|
|
4
|
-
|
|
5
|
-
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
-
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
-
|
|
8
|
-
## [1.0.0] - 2025-11-01
|
|
9
|
-
|
|
10
|
-
### Added
|
|
11
|
-
- Initial release of api-axios module
|
|
12
|
-
- Full Axios-based HTTP client implementation
|
|
13
|
-
- Request/response interceptors support
|
|
14
|
-
- Automatic retry logic with exponential backoff
|
|
15
|
-
- Request cancellation support via cancel tokens
|
|
16
|
-
- Upload/download progress tracking
|
|
17
|
-
- Response caching with configurable TTL
|
|
18
|
-
- Complete TypeScript type definitions
|
|
19
|
-
- Comprehensive documentation and examples
|
|
20
|
-
- Migration guide from api-core
|
|
21
|
-
- Error transformation and standardized error handling
|
|
22
|
-
- Support for all HTTP methods (GET, POST, PUT, PATCH, DELETE)
|
|
23
|
-
- Query parameters and custom headers support
|
|
24
|
-
- Timeout configuration per request
|
|
25
|
-
- Credentials (cookies) support
|
|
26
|
-
|
|
27
|
-
### Features Over api-core
|
|
28
|
-
- **Interceptors**: Add custom logic before/after requests
|
|
29
|
-
- **Retry Logic**: Automatic retry with exponential backoff
|
|
30
|
-
- **Cancellation**: Cancel pending requests when needed
|
|
31
|
-
- **Progress**: Track upload/download progress in real-time
|
|
32
|
-
- **Caching**: Cache GET responses to reduce network calls
|
|
33
|
-
- **Better Errors**: Enhanced error handling with original error preservation
|
|
34
|
-
|
|
35
|
-
### Dependencies
|
|
36
|
-
- axios: ^1.6.0 (external dependency)
|
|
37
|
-
|
|
38
|
-
## [Unreleased]
|
|
39
|
-
|
|
40
|
-
### Planned Features
|
|
41
|
-
- Request deduplication (prevent duplicate concurrent requests)
|
|
42
|
-
- Request queue management
|
|
43
|
-
- Offline request queueing
|
|
44
|
-
- Custom retry strategies
|
|
45
|
-
- Response schema validation
|
|
46
|
-
- Mock mode for testing
|
|
47
|
-
- Request/response logging
|
|
48
|
-
- Metrics and performance tracking
|
|
1
|
+
# Changelog - API Axios Module
|
|
2
|
+
|
|
3
|
+
All notable changes to the api-axios module will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [1.0.0] - 2025-11-01
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- Initial release of api-axios module
|
|
12
|
+
- Full Axios-based HTTP client implementation
|
|
13
|
+
- Request/response interceptors support
|
|
14
|
+
- Automatic retry logic with exponential backoff
|
|
15
|
+
- Request cancellation support via cancel tokens
|
|
16
|
+
- Upload/download progress tracking
|
|
17
|
+
- Response caching with configurable TTL
|
|
18
|
+
- Complete TypeScript type definitions
|
|
19
|
+
- Comprehensive documentation and examples
|
|
20
|
+
- Migration guide from api-core
|
|
21
|
+
- Error transformation and standardized error handling
|
|
22
|
+
- Support for all HTTP methods (GET, POST, PUT, PATCH, DELETE)
|
|
23
|
+
- Query parameters and custom headers support
|
|
24
|
+
- Timeout configuration per request
|
|
25
|
+
- Credentials (cookies) support
|
|
26
|
+
|
|
27
|
+
### Features Over api-core
|
|
28
|
+
- **Interceptors**: Add custom logic before/after requests
|
|
29
|
+
- **Retry Logic**: Automatic retry with exponential backoff
|
|
30
|
+
- **Cancellation**: Cancel pending requests when needed
|
|
31
|
+
- **Progress**: Track upload/download progress in real-time
|
|
32
|
+
- **Caching**: Cache GET responses to reduce network calls
|
|
33
|
+
- **Better Errors**: Enhanced error handling with original error preservation
|
|
34
|
+
|
|
35
|
+
### Dependencies
|
|
36
|
+
- axios: ^1.6.0 (external dependency)
|
|
37
|
+
|
|
38
|
+
## [Unreleased]
|
|
39
|
+
|
|
40
|
+
### Planned Features
|
|
41
|
+
- Request deduplication (prevent duplicate concurrent requests)
|
|
42
|
+
- Request queue management
|
|
43
|
+
- Offline request queueing
|
|
44
|
+
- Custom retry strategies
|
|
45
|
+
- Response schema validation
|
|
46
|
+
- Mock mode for testing
|
|
47
|
+
- Request/response logging
|
|
48
|
+
- Metrics and performance tracking
|
|
@@ -1,178 +1,178 @@
|
|
|
1
|
-
# API Axios - Quick Reference
|
|
2
|
-
|
|
3
|
-
## Import
|
|
4
|
-
|
|
5
|
-
```typescript
|
|
6
|
-
import { apiAxiosService } from '../../modules/api-axios/api-axios-service';
|
|
7
|
-
```
|
|
8
|
-
|
|
9
|
-
## Basic Methods
|
|
10
|
-
|
|
11
|
-
```typescript
|
|
12
|
-
// GET request
|
|
13
|
-
const response = await apiAxiosService.get(url, config);
|
|
14
|
-
|
|
15
|
-
// POST request
|
|
16
|
-
const response = await apiAxiosService.post(url, data, config);
|
|
17
|
-
|
|
18
|
-
// PUT request
|
|
19
|
-
const response = await apiAxiosService.put(url, data, config);
|
|
20
|
-
|
|
21
|
-
// PATCH request
|
|
22
|
-
const response = await apiAxiosService.patch(url, data, config);
|
|
23
|
-
|
|
24
|
-
// DELETE request
|
|
25
|
-
const response = await apiAxiosService.delete(url, config);
|
|
26
|
-
|
|
27
|
-
// Generic request with method
|
|
28
|
-
const response = await apiAxiosService.request(method, url, data, config);
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
## Common Use Cases
|
|
32
|
-
|
|
33
|
-
### With Query Parameters
|
|
34
|
-
```typescript
|
|
35
|
-
const response = await apiAxiosService.get('https://api.example.com/users', {
|
|
36
|
-
params: { page: 1, limit: 10 }
|
|
37
|
-
});
|
|
38
|
-
// Calls: https://api.example.com/users?page=1&limit=10
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
### With Custom Headers
|
|
42
|
-
```typescript
|
|
43
|
-
const response = await apiAxiosService.get('https://api.example.com/data', {
|
|
44
|
-
headers: {
|
|
45
|
-
'Authorization': 'Bearer token123',
|
|
46
|
-
'X-Custom-Header': 'value'
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
### With Timeout
|
|
52
|
-
```typescript
|
|
53
|
-
const response = await apiAxiosService.get('https://api.example.com/data', {
|
|
54
|
-
timeout: 5000 // 5 seconds
|
|
55
|
-
});
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
### With Retry
|
|
59
|
-
```typescript
|
|
60
|
-
const response = await apiAxiosService.request('GET', 'https://api.example.com/data', null, {
|
|
61
|
-
retries: 3,
|
|
62
|
-
retryDelay: 1000
|
|
63
|
-
});
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
### With Cache
|
|
67
|
-
```typescript
|
|
68
|
-
const response = await apiAxiosService.get('https://api.example.com/data', {
|
|
69
|
-
useCache: true
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
// Configure cache TTL
|
|
73
|
-
apiAxiosService.setCacheTTL(10 * 60 * 1000); // 10 minutes
|
|
74
|
-
|
|
75
|
-
// Clear cache
|
|
76
|
-
apiAxiosService.clearCache();
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
### With Progress Tracking
|
|
80
|
-
```typescript
|
|
81
|
-
const response = await apiAxiosService.post('https://api.example.com/upload', formData, {
|
|
82
|
-
onUploadProgress: (event) => {
|
|
83
|
-
const percent = Math.round((event.loaded * 100) / event.total);
|
|
84
|
-
console.log(`Upload: ${percent}%`);
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
### With Cancellation
|
|
90
|
-
```typescript
|
|
91
|
-
const cancelToken = apiAxiosService.createCancelToken();
|
|
92
|
-
|
|
93
|
-
const promise = apiAxiosService.get('https://api.example.com/data', {
|
|
94
|
-
axiosConfig: { cancelToken: cancelToken.token }
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
// Cancel if needed
|
|
98
|
-
cancelToken.cancel('User cancelled');
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
## Interceptors
|
|
102
|
-
|
|
103
|
-
### Request Interceptor
|
|
104
|
-
```typescript
|
|
105
|
-
apiAxiosService.addRequestInterceptor(async (config) => {
|
|
106
|
-
config.headers = config.headers || {};
|
|
107
|
-
config.headers['Authorization'] = 'Bearer token';
|
|
108
|
-
return config;
|
|
109
|
-
});
|
|
110
|
-
```
|
|
111
|
-
|
|
112
|
-
### Response Interceptor
|
|
113
|
-
```typescript
|
|
114
|
-
apiAxiosService.addResponseInterceptor(async (response) => {
|
|
115
|
-
console.log('Response:', response.status);
|
|
116
|
-
return response;
|
|
117
|
-
});
|
|
118
|
-
```
|
|
119
|
-
|
|
120
|
-
### Error Interceptor
|
|
121
|
-
```typescript
|
|
122
|
-
apiAxiosService.addErrorInterceptor(async (error) => {
|
|
123
|
-
if (error.status === 401) {
|
|
124
|
-
// Handle unauthorized
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
```
|
|
128
|
-
|
|
129
|
-
## TypeScript Types
|
|
130
|
-
|
|
131
|
-
```typescript
|
|
132
|
-
import type { ApiResponse, ApiError, ApiRequestConfig } from '../../modules/api-axios';
|
|
133
|
-
|
|
134
|
-
interface User {
|
|
135
|
-
id: number;
|
|
136
|
-
name: string;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
const response = await apiAxiosService.get<User>('https://api.example.com/user/1');
|
|
140
|
-
// response.data is typed as User
|
|
141
|
-
```
|
|
142
|
-
|
|
143
|
-
## Error Handling
|
|
144
|
-
|
|
145
|
-
```typescript
|
|
146
|
-
try {
|
|
147
|
-
const response = await apiAxiosService.get('https://api.example.com/data');
|
|
148
|
-
console.log(response.data);
|
|
149
|
-
} catch (error: any) {
|
|
150
|
-
console.error('Status:', error.status);
|
|
151
|
-
console.error('Message:', error.message);
|
|
152
|
-
console.error('Data:', error.data);
|
|
153
|
-
}
|
|
154
|
-
```
|
|
155
|
-
|
|
156
|
-
## Response Format
|
|
157
|
-
|
|
158
|
-
```typescript
|
|
159
|
-
{
|
|
160
|
-
data: any, // Response data
|
|
161
|
-
status: number, // HTTP status code
|
|
162
|
-
statusText: string, // HTTP status text
|
|
163
|
-
headers: {}, // Response headers
|
|
164
|
-
config: {} // Original request config
|
|
165
|
-
}
|
|
166
|
-
```
|
|
167
|
-
|
|
168
|
-
## Migration from api-core
|
|
169
|
-
|
|
170
|
-
```typescript
|
|
171
|
-
// Simply replace the import
|
|
172
|
-
// From:
|
|
173
|
-
import { apiCoreService } from '../../modules/api-core/api-core-service';
|
|
174
|
-
// To:
|
|
175
|
-
import { apiAxiosService } from '../../modules/api-axios/api-axios-service';
|
|
176
|
-
|
|
177
|
-
// All basic methods work the same!
|
|
178
|
-
```
|
|
1
|
+
# API Axios - Quick Reference
|
|
2
|
+
|
|
3
|
+
## Import
|
|
4
|
+
|
|
5
|
+
```typescript
|
|
6
|
+
import { apiAxiosService } from '../../modules/api-axios/api-axios-service';
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## Basic Methods
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
// GET request
|
|
13
|
+
const response = await apiAxiosService.get(url, config);
|
|
14
|
+
|
|
15
|
+
// POST request
|
|
16
|
+
const response = await apiAxiosService.post(url, data, config);
|
|
17
|
+
|
|
18
|
+
// PUT request
|
|
19
|
+
const response = await apiAxiosService.put(url, data, config);
|
|
20
|
+
|
|
21
|
+
// PATCH request
|
|
22
|
+
const response = await apiAxiosService.patch(url, data, config);
|
|
23
|
+
|
|
24
|
+
// DELETE request
|
|
25
|
+
const response = await apiAxiosService.delete(url, config);
|
|
26
|
+
|
|
27
|
+
// Generic request with method
|
|
28
|
+
const response = await apiAxiosService.request(method, url, data, config);
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Common Use Cases
|
|
32
|
+
|
|
33
|
+
### With Query Parameters
|
|
34
|
+
```typescript
|
|
35
|
+
const response = await apiAxiosService.get('https://api.example.com/users', {
|
|
36
|
+
params: { page: 1, limit: 10 }
|
|
37
|
+
});
|
|
38
|
+
// Calls: https://api.example.com/users?page=1&limit=10
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### With Custom Headers
|
|
42
|
+
```typescript
|
|
43
|
+
const response = await apiAxiosService.get('https://api.example.com/data', {
|
|
44
|
+
headers: {
|
|
45
|
+
'Authorization': 'Bearer token123',
|
|
46
|
+
'X-Custom-Header': 'value'
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### With Timeout
|
|
52
|
+
```typescript
|
|
53
|
+
const response = await apiAxiosService.get('https://api.example.com/data', {
|
|
54
|
+
timeout: 5000 // 5 seconds
|
|
55
|
+
});
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### With Retry
|
|
59
|
+
```typescript
|
|
60
|
+
const response = await apiAxiosService.request('GET', 'https://api.example.com/data', null, {
|
|
61
|
+
retries: 3,
|
|
62
|
+
retryDelay: 1000
|
|
63
|
+
});
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### With Cache
|
|
67
|
+
```typescript
|
|
68
|
+
const response = await apiAxiosService.get('https://api.example.com/data', {
|
|
69
|
+
useCache: true
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
// Configure cache TTL
|
|
73
|
+
apiAxiosService.setCacheTTL(10 * 60 * 1000); // 10 minutes
|
|
74
|
+
|
|
75
|
+
// Clear cache
|
|
76
|
+
apiAxiosService.clearCache();
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### With Progress Tracking
|
|
80
|
+
```typescript
|
|
81
|
+
const response = await apiAxiosService.post('https://api.example.com/upload', formData, {
|
|
82
|
+
onUploadProgress: (event) => {
|
|
83
|
+
const percent = Math.round((event.loaded * 100) / event.total);
|
|
84
|
+
console.log(`Upload: ${percent}%`);
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### With Cancellation
|
|
90
|
+
```typescript
|
|
91
|
+
const cancelToken = apiAxiosService.createCancelToken();
|
|
92
|
+
|
|
93
|
+
const promise = apiAxiosService.get('https://api.example.com/data', {
|
|
94
|
+
axiosConfig: { cancelToken: cancelToken.token }
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
// Cancel if needed
|
|
98
|
+
cancelToken.cancel('User cancelled');
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Interceptors
|
|
102
|
+
|
|
103
|
+
### Request Interceptor
|
|
104
|
+
```typescript
|
|
105
|
+
apiAxiosService.addRequestInterceptor(async (config) => {
|
|
106
|
+
config.headers = config.headers || {};
|
|
107
|
+
config.headers['Authorization'] = 'Bearer token';
|
|
108
|
+
return config;
|
|
109
|
+
});
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### Response Interceptor
|
|
113
|
+
```typescript
|
|
114
|
+
apiAxiosService.addResponseInterceptor(async (response) => {
|
|
115
|
+
console.log('Response:', response.status);
|
|
116
|
+
return response;
|
|
117
|
+
});
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### Error Interceptor
|
|
121
|
+
```typescript
|
|
122
|
+
apiAxiosService.addErrorInterceptor(async (error) => {
|
|
123
|
+
if (error.status === 401) {
|
|
124
|
+
// Handle unauthorized
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## TypeScript Types
|
|
130
|
+
|
|
131
|
+
```typescript
|
|
132
|
+
import type { ApiResponse, ApiError, ApiRequestConfig } from '../../modules/api-axios';
|
|
133
|
+
|
|
134
|
+
interface User {
|
|
135
|
+
id: number;
|
|
136
|
+
name: string;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const response = await apiAxiosService.get<User>('https://api.example.com/user/1');
|
|
140
|
+
// response.data is typed as User
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## Error Handling
|
|
144
|
+
|
|
145
|
+
```typescript
|
|
146
|
+
try {
|
|
147
|
+
const response = await apiAxiosService.get('https://api.example.com/data');
|
|
148
|
+
console.log(response.data);
|
|
149
|
+
} catch (error: any) {
|
|
150
|
+
console.error('Status:', error.status);
|
|
151
|
+
console.error('Message:', error.message);
|
|
152
|
+
console.error('Data:', error.data);
|
|
153
|
+
}
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
## Response Format
|
|
157
|
+
|
|
158
|
+
```typescript
|
|
159
|
+
{
|
|
160
|
+
data: any, // Response data
|
|
161
|
+
status: number, // HTTP status code
|
|
162
|
+
statusText: string, // HTTP status text
|
|
163
|
+
headers: {}, // Response headers
|
|
164
|
+
config: {} // Original request config
|
|
165
|
+
}
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
## Migration from api-core
|
|
169
|
+
|
|
170
|
+
```typescript
|
|
171
|
+
// Simply replace the import
|
|
172
|
+
// From:
|
|
173
|
+
import { apiCoreService } from '../../modules/api-core/api-core-service';
|
|
174
|
+
// To:
|
|
175
|
+
import { apiAxiosService } from '../../modules/api-axios/api-axios-service';
|
|
176
|
+
|
|
177
|
+
// All basic methods work the same!
|
|
178
|
+
```
|