@@ -9,6 +9,8 @@ API clients and endpoint wrappers for Mixcore SDK. Provides typed HTTP clients f
99- Built-in error handling
1010- Support for authentication headers
1111- Promise-based async operations
12+ - Secure configuration injection
13+ - Framework-agnostic implementation
1214
1315## Installation
1416
@@ -27,50 +29,56 @@ import { ApiService } from '@mixcore/api';
2729
2830const api = new ApiService ({
2931 apiBaseUrl: ' https://api.mixcore.net' ,
30- apiKey: ' your-api-key ' // optional
32+ apiKey: process . env . MIXCORE_API_KEY // Never hardcode secrets!
3133});
3234
3335// Make API requests
3436const response = await api .get (' /some-endpoint' );
3537```
3638
39+ ### SDK Entrypoint
40+
41+ ``` typescript
42+ import { createMixcoreSdk } from ' @mixcore/api' ;
43+
44+ const sdk = createMixcoreSdk (
45+ { apiBaseUrl: ' https://api.mixcore.net' },
46+ {
47+ api: new ApiService ({ apiBaseUrl: ' https://api.mixcore.net' })
48+ }
49+ );
50+ ```
51+
3752### Configuration Options
3853
39- | Option | Type | Description |
40- | --------| ------| -------------|
41- | apiBaseUrl | string | Base URL for API requests |
42- | apiKey? | string | API key for authentication |
43- | timeout? | number | Request timeout in ms |
54+ | Option | Type | Required | Description |
55+ | --------| ------| ----------| ---------- ---|
56+ | apiBaseUrl | string | Yes | Base URL for API requests |
57+ | apiKey? | string | No | API key for authentication |
58+ | timeout? | number | No | Request timeout in ms |
4459
45- ### Authentication
60+ ### Security Note
4661
47- ``` typescript
48- // With API key
49- const api = new ApiService ({
50- apiBaseUrl: ' https://api.mixcore.net' ,
51- apiKey: ' your-api-key-here'
52- });
62+ - Never hardcode API keys or secrets in your code
63+ - Always inject configuration at runtime
64+ - Use environment variables for sensitive values
5365
54- // Requests will include Authorization: Bearer header
55- ```
66+ ## API Reference
5667
57- ## Error Handling
68+ ### ApiService Methods
5869
59- The API client throws structured errors for:
70+ | Method | Parameters | Returns | Description |
71+ | --------| ------------| ---------| -------------|
72+ | get | ` endpoint: string ` , ` params?: Record<string, any> ` | ` Promise<ApiResult> ` | Makes GET request |
73+ | post | ` endpoint: string ` , ` data: any ` , ` options?: { isFormData?: boolean } ` | ` Promise<ApiResult> ` | Makes POST request |
74+ | delete | ` endpoint: string ` | ` Promise<ApiResult> ` | Makes DELETE request |
6075
61- - Network failures
62- - Invalid responses (non-2xx status codes)
63- - Timeouts
76+ ## Testing
6477
65- ``` typescript
66- try {
67- await api .get (' /some-endpoint' );
68- } catch (error ) {
69- console .error (' API request failed:' , error .message );
70- if (error .response ) {
71- console .error (' Status:' , error .response .status );
72- }
73- }
78+ Test coverage reports are generated in ` coverage/ ` directory when running:
79+
80+ ``` bash
81+ pnpm test
7482```
7583
7684## Related Packages
0 commit comments