@softimist/api 1.0.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 +67 -0
- package/dist/index.cjs +665 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +298 -0
- package/dist/index.d.ts +298 -0
- package/dist/index.js +617 -0
- package/dist/index.js.map +1 -0
- package/package.json +37 -0
package/README.md
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# @softimist/api
|
|
2
|
+
|
|
3
|
+
Shared API types and base client for Edushade monorepo packages.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
### Extending BaseApiClient
|
|
8
|
+
|
|
9
|
+
The `BaseApiClient` class uses axios internally and provides a foundation for module-specific API clients. Simply extend it and add your module-specific methods:
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
import { BaseApiClient, type BaseApiClientConfig, type ServerResponse } from '@softimist/api';
|
|
13
|
+
|
|
14
|
+
interface WebsiteApiClientConfig extends BaseApiClientConfig {
|
|
15
|
+
// Add module-specific config if needed
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
class WebsiteApiClient extends BaseApiClient {
|
|
19
|
+
constructor(config: WebsiteApiClientConfig) {
|
|
20
|
+
super(config);
|
|
21
|
+
// BaseApiClient already handles axios setup, auth interceptors, and error handling
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Add module-specific methods
|
|
25
|
+
async getPages() {
|
|
26
|
+
return this.get<Page[]>('/api/v1/website/pages');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async getPageById(id: string) {
|
|
30
|
+
return this.get<Page>(`/api/v1/website/pages/${id}`);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async createPage(data: CreatePageDto) {
|
|
34
|
+
return this.post<Page>('/api/v1/website/pages', data);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async updatePage(id: string, data: UpdatePageDto) {
|
|
38
|
+
return this.patch<Page>(`/api/v1/website/pages/${id}`, data);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async deletePage(id: string) {
|
|
42
|
+
return this.delete<void>(`/api/v1/website/pages/${id}`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Usage
|
|
47
|
+
const client = new WebsiteApiClient({
|
|
48
|
+
baseURL: 'https://api.example.com',
|
|
49
|
+
getAuthToken: () => localStorage.getItem('token'),
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const pages = await client.getPages();
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Using Types
|
|
56
|
+
|
|
57
|
+
Import types for use in your modules:
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
import type {
|
|
61
|
+
HttpClient,
|
|
62
|
+
ServerResponse,
|
|
63
|
+
ServerPaginatedResponse,
|
|
64
|
+
UsePaginatedApiReturn,
|
|
65
|
+
PaginationMeta,
|
|
66
|
+
} from '@softimist/api';
|
|
67
|
+
```
|