@dismissible/react-client 1.0.0 → 2.0.0-canary.5.88c27fb
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/CHANGELOG.md +30 -0
- package/README.md +298 -186
- package/dist/clients/defaultClient.d.ts +25 -0
- package/dist/config/api.config.d.ts +0 -14
- package/dist/contexts/DismissibleProvider.d.ts +22 -0
- package/dist/dismissible-client.es.js +522 -484
- package/dist/dismissible-client.umd.js +1 -1
- package/dist/hooks/useDismissibleItem.d.ts +17 -17
- package/dist/root.d.ts +1 -5
- package/dist/types/dismissible.types.d.ts +81 -7
- package/dist/utils/url.utils.d.ts +9 -0
- package/package.json +17 -16
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { DismissibleClient } from '../types/dismissible.types';
|
|
2
|
+
/**
|
|
3
|
+
* Creates the default HTTP client using openapi-fetch
|
|
4
|
+
*
|
|
5
|
+
* @param baseUrl - The base URL for the API
|
|
6
|
+
* @returns A DismissibleClient implementation
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* // Use the default client directly
|
|
11
|
+
* const client = createDefaultClient("https://api.dismissible.io");
|
|
12
|
+
*
|
|
13
|
+
* // Or wrap it with custom behavior
|
|
14
|
+
* const customClient: DismissibleClient = {
|
|
15
|
+
* getOrCreate: async (params) => {
|
|
16
|
+
* console.log("Fetching item:", params.itemId);
|
|
17
|
+
* const defaultClient = createDefaultClient(params.baseUrl);
|
|
18
|
+
* return defaultClient.getOrCreate(params);
|
|
19
|
+
* },
|
|
20
|
+
* dismiss: async (params) => { ... },
|
|
21
|
+
* restore: async (params) => { ... },
|
|
22
|
+
* };
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare const createDefaultClient: (baseUrl: string) => DismissibleClient;
|
|
@@ -1,21 +1,7 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* API configuration settings
|
|
3
|
-
*/
|
|
4
|
-
/**
|
|
5
|
-
* Configuration interface for API settings
|
|
6
|
-
*/
|
|
7
1
|
export interface ApiConfig {
|
|
8
2
|
/** Base URL for API requests */
|
|
9
3
|
baseUrl: string;
|
|
10
4
|
}
|
|
11
|
-
/**
|
|
12
|
-
* Returns the API configuration based on the current environment
|
|
13
|
-
* @returns The API configuration object
|
|
14
|
-
*/
|
|
15
5
|
export declare const getConfig: () => ApiConfig;
|
|
16
|
-
/**
|
|
17
|
-
* Gets the API base URL
|
|
18
|
-
* @returns The base URL for API requests
|
|
19
|
-
*/
|
|
20
6
|
export declare const getBaseUrl: () => string;
|
|
21
7
|
export default getConfig;
|
|
@@ -27,6 +27,28 @@ import { DismissibleProviderProps } from '../types/dismissible.types';
|
|
|
27
27
|
* >
|
|
28
28
|
* <App />
|
|
29
29
|
* </DismissibleProvider>
|
|
30
|
+
*
|
|
31
|
+
* // With custom HTTP client
|
|
32
|
+
* const myClient: DismissibleClient = {
|
|
33
|
+
* getOrCreate: async ({ resolvedPath, baseUrl, authHeaders, signal }) => {
|
|
34
|
+
* const res = await axios.get(`${baseUrl}${resolvedPath}`, {
|
|
35
|
+
* headers: { ...authHeaders, 'X-Correlation-ID': uuid() },
|
|
36
|
+
* signal
|
|
37
|
+
* });
|
|
38
|
+
* return res.data.data;
|
|
39
|
+
* },
|
|
40
|
+
* dismiss: async (params) => { ... },
|
|
41
|
+
* restore: async (params) => { ... },
|
|
42
|
+
* };
|
|
43
|
+
*
|
|
44
|
+
* <DismissibleProvider
|
|
45
|
+
* userId="user-123"
|
|
46
|
+
* jwt={token}
|
|
47
|
+
* baseUrl="https://api.dismissible.io"
|
|
48
|
+
* client={myClient}
|
|
49
|
+
* >
|
|
50
|
+
* <App />
|
|
51
|
+
* </DismissibleProvider>
|
|
30
52
|
* ```
|
|
31
53
|
*/
|
|
32
54
|
export declare const DismissibleProvider: React.FC<DismissibleProviderProps>;
|