@tmlmobilidade/utils 20260603.1838.59 → 20260604.1619.56
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/dist/http/swr.d.ts +13 -0
- package/dist/http/swr.js +6 -0
- package/package.json +1 -1
package/dist/http/swr.d.ts
CHANGED
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
export interface SwrFetcherOptions {
|
|
2
|
+
/**
|
|
3
|
+
* Whether to include credentials in the fetch operation.
|
|
4
|
+
* @default 'include'
|
|
5
|
+
*/
|
|
2
6
|
credentials?: RequestInit['credentials'];
|
|
7
|
+
/**
|
|
8
|
+
* The URL to fetch from.
|
|
9
|
+
*/
|
|
3
10
|
url: string;
|
|
11
|
+
/**
|
|
12
|
+
* Whether to use the proper API response, where the response is an object with a data property.
|
|
13
|
+
* If false, the response is assumed to be the data directly.
|
|
14
|
+
* @default true
|
|
15
|
+
*/
|
|
16
|
+
useProperApiResponse?: boolean;
|
|
4
17
|
}
|
|
5
18
|
/**
|
|
6
19
|
* Fetches data from a URL using the SWR fetcher function.
|
package/dist/http/swr.js
CHANGED
|
@@ -30,6 +30,12 @@ export async function swrFetcher(urlOrOptions) {
|
|
|
30
30
|
if (!res.ok) {
|
|
31
31
|
throw new HttpException(res.status, data.error ?? 'An error occurred');
|
|
32
32
|
}
|
|
33
|
+
//
|
|
34
|
+
// Return the data directly if the useProperApiResponse option is false
|
|
35
|
+
// or directly accessing the data property of the HttpResponse object.
|
|
36
|
+
if (typeof urlOrOptions === 'object' && urlOrOptions.useProperApiResponse === false) {
|
|
37
|
+
return data;
|
|
38
|
+
}
|
|
33
39
|
return data.data;
|
|
34
40
|
}
|
|
35
41
|
;
|