@soleil-se/app-util 5.4.0 → 5.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/CHANGELOG.md +8 -0
- package/README.md +13 -2
- package/client/fetch-json/index.js +2 -6
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [5.5.0] - 2023-08-25
|
|
9
|
+
|
|
10
|
+
- Remove abort controllers in `fetchJson` since it's better to handle this seperatly case by case.
|
|
11
|
+
|
|
12
|
+
## [5.4.1] - 2023-08-22
|
|
13
|
+
|
|
14
|
+
- Add `/edit-app-config` to ignored URI:s in `fetchJson`.
|
|
15
|
+
|
|
8
16
|
## [5.4.0] - 2023-08-09
|
|
9
17
|
|
|
10
18
|
- Add `fetchJson` function to make requests to app routes or other resources.
|
package/README.md
CHANGED
|
@@ -230,6 +230,9 @@ Fetch wrapper for calling app routes, rest-api or external resources.
|
|
|
230
230
|
**Returns**: `Promise<Object>` - Promise containing parsed JSON-data.
|
|
231
231
|
**Throws** `Error` - Extended error object with custom properties for `status`, `aborted` and other JSON-data returned by the request.
|
|
232
232
|
|
|
233
|
+
URI:s starting with `/rest-api`, `/appresource`, `/edit-app-config` or a protocol, for example `https://` will be left as is.
|
|
234
|
+
Other URI:s will be converted to match a route in the current app with `getRouteUri`.
|
|
235
|
+
|
|
233
236
|
Most common usage is getting data from a route in the current app.
|
|
234
237
|
|
|
235
238
|
```js
|
|
@@ -269,15 +272,23 @@ async function getItems() {
|
|
|
269
272
|
}
|
|
270
273
|
```
|
|
271
274
|
|
|
272
|
-
|
|
275
|
+
When searching on input you probably want to abort the ongoing request to avoid weird bugs when
|
|
276
|
+
the first request might be completed after the subsequent one.
|
|
277
|
+
Pass an [AbortController](https://developer.mozilla.org/en-US/docs/Web/API/AbortController) signal
|
|
278
|
+
in options and abort the ongoing call.
|
|
273
279
|
|
|
274
280
|
```js
|
|
275
281
|
import { fetchJson } from '@soleil-se/webapp-util/client';
|
|
276
282
|
|
|
283
|
+
let controller;
|
|
284
|
+
|
|
277
285
|
async function onInput() {
|
|
286
|
+
if(controller) controller.abort();
|
|
287
|
+
controller = new AbortController();
|
|
288
|
+
|
|
278
289
|
const params = { query: 'foo' };
|
|
279
290
|
try {
|
|
280
|
-
const result = await fetchJson('/search', { params });
|
|
291
|
+
const result = await fetchJson('/search', { params, signal: controller.signal });
|
|
281
292
|
console.log(result);
|
|
282
293
|
} catch(e) {
|
|
283
294
|
// Ignore aborts due to new search.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getRouteUri, stringifyParams } from '../../common';
|
|
2
2
|
|
|
3
3
|
function getUrl(uri, params) {
|
|
4
|
-
if (uri.startsWith('/rest-api') || uri.startsWith('/appresource') || !uri.startsWith('/')) {
|
|
4
|
+
if (uri.startsWith('/rest-api') || uri.startsWith('/appresource') || uri.startsWith('/edit-app-config') || !uri.startsWith('/')) {
|
|
5
5
|
return uri + stringifyParams(params, { addQueryPrefix: true });
|
|
6
6
|
}
|
|
7
7
|
return getRouteUri(uri, params);
|
|
@@ -29,12 +29,8 @@ async function handleResponse(response) {
|
|
|
29
29
|
return json;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
const controllers = {};
|
|
33
|
-
|
|
34
32
|
export default function fetchJson(uri, { params = {}, retries = 0, ...options } = {}) {
|
|
35
|
-
|
|
36
|
-
controllers[uri] = new AbortController();
|
|
37
|
-
return fetch(getUrl(uri, params), { signal: controllers[uri].signal, ...options })
|
|
33
|
+
return fetch(getUrl(uri, params), options)
|
|
38
34
|
.then(handleResponse)
|
|
39
35
|
.catch((error) => {
|
|
40
36
|
const isTimeout = error.status === 504 || error.status === 408 || error.message.includes('SocketTimeoutException');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@soleil-se/app-util",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.5.0",
|
|
4
4
|
"description": "Utility and rendering functions for WebApps.",
|
|
5
5
|
"main": "./common/index.js",
|
|
6
6
|
"author": "Soleil AB",
|
|
@@ -14,6 +14,6 @@
|
|
|
14
14
|
"peerDependencies": {
|
|
15
15
|
"@sitevision/api": "*"
|
|
16
16
|
},
|
|
17
|
-
"gitHead": "
|
|
17
|
+
"gitHead": "b70a56edccc70b2af2da994e9fd4a99a7a908003",
|
|
18
18
|
"dependencies": {}
|
|
19
19
|
}
|