aa-geuthur-react 1.6.0 → 1.8.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 +12 -0
- package/dist/Api/Api.d.ts +3 -0
- package/dist/Api/errors.d.ts +12 -0
- package/dist/Api/query.d.ts +18 -0
- package/dist/index.js +650 -617
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -71,6 +71,18 @@ import { AaReactProvider, AuthBase, ErrorPage } from "aa-geuthur-react";
|
|
|
71
71
|
- `menuRefetchInterval` (optional, milliseconds) lets `useMenu` reload the menu in that interval, so badges stay live. Off by default.
|
|
72
72
|
- `useAaReact()` returns both inside the provider and throws outside of it.
|
|
73
73
|
|
|
74
|
+
Create the `QueryClient` with `createQueryClient()` instead of `new QueryClient()`:
|
|
75
|
+
|
|
76
|
+
```tsx
|
|
77
|
+
import { createQueryClient } from "aa-geuthur-react";
|
|
78
|
+
|
|
79
|
+
const queryClient = createQueryClient();
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
- Queries are retried only after a network error (`TypeError` of `fetch`) or a short outage of the server (502, 503 or 504, thrown by the client of `createApiClient` as `ServiceUnavailableError`), at most three times. Every other answer of the server (4xx and 500) is shown at once; the rule is exported as `shouldRetryQuery(failureCount, error)`.
|
|
83
|
+
- For 502, 503 and 504 queries and mutations show the fixed message of `ServiceUnavailableError` instead of `apiErrorMessage`.
|
|
84
|
+
- Own options are merged and win: `createQueryClient({ defaultOptions: { queries: { staleTime: 60000 } } })`. Mutations keep the defaults of react-query.
|
|
85
|
+
|
|
74
86
|
### Styles<a name="styles"></a>
|
|
75
87
|
|
|
76
88
|
The components use Bootstrap utilities and a few global classes (`aa-table-*`, `aa-react.container`, `aa-shake`, `aa-menu-badge-pulse`, `aa-nav-danger`, `aa-tooltip`). Import the stylesheet once, before the stylesheet of the app so the app can override it:
|
package/dist/Api/Api.d.ts
CHANGED
|
@@ -3,6 +3,9 @@ import { ClientOptions } from 'openapi-fetch';
|
|
|
3
3
|
* Creates an `openapi-fetch` client for the API of the app that sends the Django CSRF token
|
|
4
4
|
* (`csrftoken` cookie) as `X-CSRFToken` header with every request.
|
|
5
5
|
*
|
|
6
|
+
* An answer with status 502, 503 or 504 rejects the request with a `ServiceUnavailableError`
|
|
7
|
+
* instead of resolving with `error`, so `shouldRetryQuery` retries the query.
|
|
8
|
+
*
|
|
6
9
|
* The app passes the `paths` type generated from its OpenAPI schema:
|
|
7
10
|
* `export const apiClient = createApiClient<paths>();`
|
|
8
11
|
*/
|
package/dist/Api/errors.d.ts
CHANGED
|
@@ -12,3 +12,15 @@
|
|
|
12
12
|
* ```
|
|
13
13
|
*/
|
|
14
14
|
export declare function apiErrorMessage(error: unknown, fallback: string): string;
|
|
15
|
+
/** Status codes of a short outage of the server, e.g. while Django restarts behind nginx. */
|
|
16
|
+
export declare const SERVICE_UNAVAILABLE_STATUSES: readonly [502, 503, 504];
|
|
17
|
+
/**
|
|
18
|
+
* Thrown by the client of `createApiClient` for an answer with status 502, 503 or 504.
|
|
19
|
+
*
|
|
20
|
+
* The request does not resolve with `error` but is rejected, so `shouldRetryQuery` can retry
|
|
21
|
+
* the query like a network error. Queries and mutations show the fixed message of this error.
|
|
22
|
+
*/
|
|
23
|
+
export declare class ServiceUnavailableError extends Error {
|
|
24
|
+
readonly status: number;
|
|
25
|
+
constructor(status: number);
|
|
26
|
+
}
|
package/dist/Api/query.d.ts
CHANGED
|
@@ -1,6 +1,24 @@
|
|
|
1
|
+
import { QueryClient, QueryClientConfig } from '@tanstack/react-query';
|
|
1
2
|
/** Query keys of the endpoints every app provides. Apps add their own keys next to them. */
|
|
2
3
|
export declare const queryKeys: {
|
|
3
4
|
Menu: readonly ["Menu"];
|
|
4
5
|
User: readonly ["User"];
|
|
5
6
|
UserSettings: readonly ["UserSettings"];
|
|
6
7
|
};
|
|
8
|
+
/** How often a query is retried after a network error or a short outage of the server. */
|
|
9
|
+
export declare const QUERY_NETWORK_RETRIES = 3;
|
|
10
|
+
/**
|
|
11
|
+
* Retry rule for queries: only network errors and short outages of the server are retried.
|
|
12
|
+
*
|
|
13
|
+
* `fetch` throws a `TypeError` when the server cannot be reached, the client of
|
|
14
|
+
* `createApiClient` throws a `ServiceUnavailableError` for 502, 503 and 504 (e.g. while
|
|
15
|
+
* Django restarts behind nginx). Every other answer of the server (4xx and 500) becomes a
|
|
16
|
+
* normal `Error` in the query functions of the apps and is shown at once, so a missing
|
|
17
|
+
* permission or an unknown ID does not wait for three retries.
|
|
18
|
+
*/
|
|
19
|
+
export declare function shouldRetryQuery(failureCount: number, error: unknown): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Creates the `QueryClient` of an app with the retry rule `shouldRetryQuery` for queries.
|
|
22
|
+
* The given `defaultOptions` are merged, values of the app win.
|
|
23
|
+
*/
|
|
24
|
+
export declare function createQueryClient(config?: QueryClientConfig): QueryClient;
|