@jskit-ai/http-web 0.2.58 → 0.2.59

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 CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ - **Breaking:** `useList()`, `useView()` and `useAddEdit()` (and so `useCrudList()`, `useCrudView()`, `useCrudAddEdit()` and the three CRUD screens) leave shell-web's request recovery banner out of their read unless the caller passes `requestRecovery`: the default was on, and is now off (`meta.jskit.requestRecovery` is `false`). Fix: a read whose screen shows no `loadError` (a lookup feeding a select, a section that hides its read) passes `requestRecovery: true` (or a label, or an options object) to keep the banner; a screen that shows the read's `loadError` needs no change. Why: these reads show their failure where it happened, as `loadError` with Retry, and report it once as `resource-load`, while the banner reported the same network failure again with its own Retry, so the page showed it twice. Where the old shape shows, the read is refused: a `requestRecoveryLabel` given without `requestRecovery: true`, which named the banner before, is a `TypeError` at setup naming both fixes (pass `requestRecovery: true`, or drop the label where the screen shows `loadError`), and the CRUD screens no longer default a label of their own (the catalog's `jskit.http.crud.records`, which only that default used, is gone; no dependent project uses it). The rule lives in one helper, `resolveScreenReadRequestRecovery`. JSKIT's own reads that show no load error ask for the banner: the CRUD lookup fields' and list filters' options and `useCrudListParentTitle()`'s parent read; the crud-screen-set pattern's Book screens no longer pass a label. `useEndpointResource()` and `useListCore()` keep request recovery on by default, as before.
6
+ - `toUiErrorMessage` and `toQueryErrorMessage` no longer show the browser's "signal timed out" for a request past its deadline as if the server had said it: the caller's fallback copy shows, and without one "The server took too long to answer. Try again." (`jskit.http.feedback.timedOut`). Before, a read that took longer than 30 seconds showed "signal timed out" on the page.
5
7
  - The CRUD screens' command buttons keep keyboard focus while they run, through shell-web's `pending` and `v-pending`: the form's Save while it saves or the record reloads after it (`addEdit.isSubmitPending`, new on `useAddEdit()` and the runtimes built on it, alongside `isSubmitDisabled`, which still includes it), the list's Refresh and "Load more", the Retry of a list, record or form that failed to load, and the delete dialog's Delete. Each reads as unavailable and ignores a second press meanwhile, where it was `disabled` and dropped focus to the page body (the dialog's Delete kept focus but never read as unavailable). A save the server refuses with a field error moves focus to that field. When the last page of "Load more" takes the button away, focus moves to the first record that page added.
6
8
  - A `useCommand()` run refused because the person lacks its `runPermissions` (`canRun` false) is no longer silent: it shows, through the command's feedback (its `message` and `messageType`, and the shell's action feedback), the notice the server's 403 for the same request shows (`ACTION_PERMISSION_DENIED`, "Forbidden." in the person's language). It still sends nothing and resolves `null`, so callers are unchanged, and `onRunError` does not run, as nothing was sent. Before, `run()` answered null with no request and no notice, so a tap did nothing visible. A run while the command is already running still answers null without a notice.
7
9
  - A list's, a record's or a form's load notice offers Retry only when trying again can help: after a network failure (no status), a timeout (408), a rate limit (429) or a server error (5xx). Before, it offered Retry on every failed load, also when the server had refused it (401, 403, 404, 422 and the other 4xx), where Retry only failed again; such a notice now has no action. One helper decides it for `useView()`, `useList()` and `useAddEdit()` (whose notice still offers nothing while `readEnabled` is false, and whose `canRetryLoad` and `refresh()` are unchanged).
package/locales/en.json CHANGED
@@ -80,7 +80,6 @@
80
80
  },
81
81
  "record": "Record",
82
82
  "recordNotFound": "Record not found.",
83
- "records": "Records",
84
83
  "view": {
85
84
  "loadFailed": "Unable to load record.",
86
85
  "notFound": "This {resource} could not be found."
@@ -94,6 +93,7 @@
94
93
  "requestFailed": "Request failed.",
95
94
  "saveFailed": "Unable to save.",
96
95
  "saved": "Saved.",
96
+ "timedOut": "The server took too long to answer. Try again.",
97
97
  "validationFailed": "Validation failed."
98
98
  },
99
99
  "list": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jskit-ai/http-web",
3
- "version": "0.2.58",
3
+ "version": "0.2.59",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "test": "jskit test"
@@ -50,17 +50,17 @@
50
50
  "@jskit-ai/resource-crud-core": "0.1.226"
51
51
  },
52
52
  "peerDependencies": {
53
- "@jskit-ai/http-runtime": "0.2.33",
53
+ "@jskit-ai/http-runtime": "0.2.34",
54
54
  "@jskit-ai/kernel": "0.2.33",
55
- "@jskit-ai/realtime": "0.2.52",
56
- "@jskit-ai/shell-web": "0.2.49",
55
+ "@jskit-ai/realtime": "0.2.53",
56
+ "@jskit-ai/shell-web": "0.2.50",
57
57
  "@tanstack/vue-query": "^5.90.5",
58
58
  "vue": "^3.5.13",
59
59
  "vue-router": "^5.0.4",
60
60
  "vuetify": "^4.3.0"
61
61
  },
62
62
  "devDependencies": {
63
- "@jskit-ai/material-web": "0.1.9"
63
+ "@jskit-ai/material-web": "0.1.10"
64
64
  },
65
65
  "description": "Neutral Vue request, command, resource, and CRUD UI runtime for JSKIT web applications.",
66
66
  "jskit": {
@@ -25,7 +25,6 @@ const screen = useCrudAddEditScreen({
25
25
  placementSource: "crud.books.edit",
26
26
  queryKeyFactory: (surfaceId = "", scope = "") => ["crud", "books", surfaceId, scope, routeRecordId.value],
27
27
  writeMethod: "PATCH",
28
- requestRecoveryLabel: "Book",
29
28
  fallbackLoadError: "Unable to load this book.",
30
29
  fallbackSaveError: "Unable to save this book.",
31
30
  recordIdParam: "bookId",
@@ -20,7 +20,6 @@ const screen = useCrudListScreen({
20
20
  listFilters,
21
21
  listBulkActions,
22
22
  listRowActions,
23
- requestRecoveryLabel: "Books",
24
23
  fallbackLoadError: "Unable to load books."
25
24
  });
26
25
  </script>
@@ -16,7 +16,6 @@ const screen = useCrudViewScreen({
16
16
  titleFallbackFieldKey: "title",
17
17
  listUrlTemplate: "/books",
18
18
  editUrlTemplate: "/books/:bookId/edit",
19
- requestRecoveryLabel: "Book",
20
19
  fallbackLoadError: "Unable to load this book."
21
20
  });
22
21
 
@@ -115,9 +115,12 @@ function createCrudLookupFieldRuntime({
115
115
  continue;
116
116
  }
117
117
 
118
+ // A lookup field shows no load error of its own, so a network failure of its options shows as the shell's
119
+ // request recovery banner.
118
120
  const runtime = useList({
119
121
  ...(relationSurfaceId ? { surfaceId: relationSurfaceId } : {}),
120
122
  apiSuffix: apiPath,
123
+ requestRecovery: true,
121
124
  ...(transport ? { transport } : {}),
122
125
  queryKeyFactory: (surfaceId = "", scopeParamValue = "") => [
123
126
  ...normalizedQueryKeyPrefix,
@@ -15,7 +15,7 @@ import {
15
15
  import {
16
16
  resolveResourceMessages
17
17
  } from "../support/scopeHelpers.js";
18
- import { resolveLoadErrorStatus } from "../support/resourceLoadStateHelpers.js";
18
+ import { resolveLoadErrorStatus, resolveScreenReadRequestRecovery } from "../support/resourceLoadStateHelpers.js";
19
19
  import { toLoadRefusalMessage } from "../support/errorMessageHelpers.js";
20
20
  import { createRequestQueryRuntime } from "../support/requestQueryRuntimeSupport.js";
21
21
  import { resolveRouteParamNamesInOrder } from "../support/routeTemplateHelpers.js";
@@ -39,7 +39,7 @@ function useAddEdit({
39
39
  client,
40
40
  transport,
41
41
  requestRecovery,
42
- requestRecoveryLabel = t("jskit.http.resource.label"),
42
+ requestRecoveryLabel,
43
43
  placementSource = "http-web.add-edit",
44
44
  fallbackLoadError = t("jskit.http.resource.loadFailed"),
45
45
  fallbackSaveError = "",
@@ -137,8 +137,8 @@ function useAddEdit({
137
137
  writeMethod,
138
138
  readQuery: requestQueryRuntime.requestQuery,
139
139
  transport,
140
- requestRecovery,
141
- requestRecoveryLabel,
140
+ requestRecovery: resolveScreenReadRequestRecovery(requestRecovery, { caller: "useAddEdit", requestRecoveryLabel }),
141
+ requestRecoveryLabel: requestRecoveryLabel ?? t("jskit.http.resource.label"),
142
142
  fallbackLoadError,
143
143
  fallbackSaveError: effectiveMessages.saveError
144
144
  });
@@ -14,7 +14,7 @@ import {
14
14
  } from "../runtime/operationUiHelpers.js";
15
15
  import { createListUiRuntime } from "../runtime/listUiRuntime.js";
16
16
  import { asPlainObject } from "../support/scopeHelpers.js";
17
- import { resolveLoadErrorStatus } from "../support/resourceLoadStateHelpers.js";
17
+ import { resolveLoadErrorStatus, resolveScreenReadRequestRecovery } from "../support/resourceLoadStateHelpers.js";
18
18
  import { toLoadRefusalMessage } from "../support/errorMessageHelpers.js";
19
19
  import {
20
20
  buildRequestQueryObject,
@@ -63,7 +63,7 @@ function useList({
63
63
  requestOptions,
64
64
  queryOptions,
65
65
  requestRecovery,
66
- requestRecoveryLabel = t("jskit.http.list.label"),
66
+ requestRecoveryLabel,
67
67
  realtime,
68
68
  recordIdParam = "recordId",
69
69
  recordIdSelector,
@@ -253,8 +253,8 @@ function useList({
253
253
  selectItems,
254
254
  requestOptions: listRequestOptions,
255
255
  queryOptions,
256
- requestRecovery,
257
- requestRecoveryLabel,
256
+ requestRecovery: resolveScreenReadRequestRecovery(requestRecovery, { caller: "useList", requestRecoveryLabel }),
257
+ requestRecoveryLabel: requestRecoveryLabel ?? t("jskit.http.list.label"),
258
258
  fallbackLoadError
259
259
  });
260
260
  const routeSyncApplying = ref(false);
@@ -16,6 +16,7 @@ import { createViewUiRuntime } from "../runtime/viewUiRuntime.js";
16
16
  import { createRequestQueryRuntime } from "../support/requestQueryRuntimeSupport.js";
17
17
  import { resolveRouteParamNamesInOrder } from "../support/routeTemplateHelpers.js";
18
18
  import { resolveOperationRealtimeOptions } from "../useRealtimeQueryInvalidation.js";
19
+ import { resolveScreenReadRequestRecovery } from "../support/resourceLoadStateHelpers.js";
19
20
  import { useJskitText } from "../../i18n.js";
20
21
 
21
22
  const { t } = useJskitText();
@@ -34,7 +35,7 @@ function useView({
34
35
  client,
35
36
  transport,
36
37
  requestRecovery,
37
- requestRecoveryLabel = t("jskit.http.resource.label"),
38
+ requestRecoveryLabel,
38
39
  placementSource = "http-web.view",
39
40
  fallbackLoadError = t("jskit.http.resource.loadFailed"),
40
41
  notFoundStatuses = [404],
@@ -116,8 +117,8 @@ function useView({
116
117
  readMethod,
117
118
  readQuery: requestQueryRuntime.requestQuery,
118
119
  transport,
119
- requestRecovery,
120
- requestRecoveryLabel,
120
+ requestRecovery: resolveScreenReadRequestRecovery(requestRecovery, { caller: "useView", requestRecoveryLabel }),
121
+ requestRecoveryLabel: requestRecoveryLabel ?? t("jskit.http.resource.label"),
121
122
  refreshOnPull: true,
122
123
  fallbackLoadError
123
124
  });
@@ -1,4 +1,4 @@
1
- import { isGenericHttpErrorMessage, resolveFieldErrors } from "@jskit-ai/http-runtime/client";
1
+ import { isGenericHttpErrorMessage, isRequestTimeoutError, resolveFieldErrors } from "@jskit-ai/http-runtime/client";
2
2
  import { isRetryableLoadStatus, resolveLoadErrorStatus } from "./resourceLoadStateHelpers.js";
3
3
  import { useJskitText } from "../../i18n.js";
4
4
 
@@ -6,8 +6,10 @@ const { t, text, serverMessage, fieldErrorMessages } = useJskitText();
6
6
 
7
7
  // An error's message in the user's language: its code or messageCode when the
8
8
  // English it carries is JSKIT's English for that code, otherwise as sent. A
9
- // caller's specific fallback copy still wins over generic transport wording.
10
- // Fallbacks may be message keys, rendered in the language active when shown.
9
+ // caller's specific fallback copy still wins over generic transport wording;
10
+ // without one, a request past its deadline says so in words, never the
11
+ // browser's own "signal timed out". Fallbacks may be message keys, rendered in
12
+ // the language active when shown.
11
13
  function toUiErrorMessage(error, fallbackMessage = "", defaultMessage = "") {
12
14
  const normalizedFallback = text(fallbackMessage).trim();
13
15
  const normalizedMessage = String(error?.message || "").trim();
@@ -17,6 +19,9 @@ function toUiErrorMessage(error, fallbackMessage = "", defaultMessage = "") {
17
19
  if (normalizedFallback) {
18
20
  return normalizedFallback;
19
21
  }
22
+ if (isRequestTimeoutError(error)) {
23
+ return t("jskit.http.feedback.timedOut");
24
+ }
20
25
  if (normalizedMessage) {
21
26
  return serverMessage(error).trim();
22
27
  }
@@ -125,11 +125,30 @@ function mergeRequestRecoveryQueryMeta(queryOptions = null, requestRecovery = nu
125
125
  return Object.keys(meta).length > 0 ? mergeQueryMeta(sourceOptions, meta) : sourceOptions;
126
126
  }
127
127
 
128
+ // useList(), useView() and useAddEdit() report their read's failure once, for their screen: `loadError` (shown where
129
+ // the read failed, with Retry when trying again can help) and the shell's one `resource-load` notice, whose channel the
130
+ // app's error policy picks. So shell-web's request recovery, which would report a network failure again as its own
131
+ // banner, leaves their reads out unless the caller asks for it with `requestRecovery`, for a read no screen shows the
132
+ // failure of (a lookup's options). The one rule for the three. A requestRecoveryLabel the caller gives while the banner
133
+ // stays out names nothing, so it is refused: such a read relied on the banner before this default, or its label is a
134
+ // leftover.
135
+ function resolveScreenReadRequestRecovery(requestRecovery = null, { caller, requestRecoveryLabel } = {}) {
136
+ const resolved = requestRecovery ?? false;
137
+ if (requestRecoveryLabel != null && (resolved === false || resolved?.enabled === false)) {
138
+ throw new TypeError(`${caller}() was given requestRecoveryLabel, which names the shell's request recovery banner, ` +
139
+ "but its read leaves the banner out unless requestRecovery is true: its screen shows the failure as loadError. " +
140
+ "Pass requestRecovery: true for a read whose screen shows no loadError (a lookup's options), or drop " +
141
+ "requestRecoveryLabel where the screen shows loadError (a CRUD screen always does).");
142
+ }
143
+ return resolved;
144
+ }
145
+
128
146
  export {
129
147
  buildRequestRecoveryMeta,
130
148
  hasResolvedQueryData,
131
149
  isRetryableLoadStatus,
132
150
  mergeQueryMeta,
133
151
  mergeRequestRecoveryQueryMeta,
134
- resolveLoadErrorStatus
152
+ resolveLoadErrorStatus,
153
+ resolveScreenReadRequestRecovery
135
154
  };
@@ -77,9 +77,12 @@ function useCrudListFilterLookups(
77
77
  }
78
78
  };
79
79
 
80
+ // A filter's options show no load error of their own, so a network failure of them shows as the shell's request
81
+ // recovery banner, as does the read of the selected values' labels below.
80
82
  const runtime = useList({
81
83
  apiSuffix: filter.lookup.apiSuffix,
82
84
  ...(transport ? { transport } : {}),
85
+ requestRecovery: true,
83
86
  readEnabled: optionsWanted,
84
87
  queryKeyFactory: queryKeyFactory(""),
85
88
  search: {
@@ -114,6 +117,7 @@ function useCrudListFilterLookups(
114
117
  ? useList({
115
118
  apiSuffix: filter.lookup.apiSuffix,
116
119
  ...(transport ? { transport } : {}),
120
+ requestRecovery: true,
117
121
  readEnabled: computed(() => unlabeledValues.value.length > 0),
118
122
  queryKeyFactory: queryKeyFactory("__selected__"),
119
123
  requestQueryParams: (context) => ({
@@ -95,8 +95,11 @@ function useCrudListParentTitle({
95
95
  return !listTitle;
96
96
  });
97
97
 
98
+ // The title falls back to the entity's label and shows no load error, so a network failure of the parent's read shows
99
+ // as the shell's request recovery banner.
98
100
  const parentView = viewRuntimeFactory({
99
101
  apiUrlTemplate: normalizeText(initialParentDescriptor.apiUrlTemplate),
102
+ requestRecovery: true,
100
103
  transport: parentTransport,
101
104
  readEnabled: shouldLoadParentRecord,
102
105
  recordIdParam: normalizeText(initialParentDescriptor.routeParamKey) || "recordId",
@@ -134,7 +134,7 @@ function useCrudListScreen({
134
134
  requestQueryParams,
135
135
  requestFieldsets,
136
136
  readEnabled = true,
137
- requestRecoveryLabel = t("jskit.http.crud.records"),
137
+ requestRecoveryLabel,
138
138
  fallbackLoadError = t("jskit.http.crud.list.loadFailed")
139
139
  }) {
140
140
  const crudHttpClient = resolveCrudHttpClient(resource, { client });
@@ -20,7 +20,7 @@ function useCrudViewScreen({
20
20
  requestFieldsets,
21
21
  readEnabled = true,
22
22
  queryKeyFactory = null,
23
- requestRecoveryLabel = t("jskit.http.crud.record"),
23
+ requestRecoveryLabel,
24
24
  fallbackLoadError = t("jskit.http.crud.view.loadFailed"),
25
25
  notFoundMessage = t("jskit.http.crud.recordNotFound")
26
26
  }) {
@@ -22,7 +22,13 @@
22
22
  /** @typedef {string | ((context: Record<string, any>) => string) | import("vue").Ref<string>} ApiSuffix */
23
23
  /** @typedef {boolean | import("vue").Ref<boolean> | ((context: Record<string, any>) => boolean)} ReadEnabled */
24
24
  /** @typedef {(surfaceId: string, scopeParamValue?: string, ownershipFilter?: string) => unknown[]} QueryKeyFactory */
25
- /** @typedef {false | string | { enabled?: boolean, label?: string, source?: string, dedupeKey?: string, method?: string, dedupeWindowMs?: number } | null} RequestRecovery */
25
+ /**
26
+ * Whether shell-web's request recovery reports a network failure of the read as its banner, with a Retry: `false` off,
27
+ * `true` on, a label string or an options object on with those hints. `null` takes the composable's default: on for
28
+ * useEndpointResource() and useListCore(); off for useList(), useView() and useAddEdit(), whose screen shows the failure
29
+ * as `loadError` with its own Retry, so a caller whose screen shows no load error passes `true`.
30
+ * @typedef {boolean | string | { enabled?: boolean, label?: string, source?: string, dedupeKey?: string, method?: string, dedupeWindowMs?: number } | null} RequestRecovery
31
+ */
26
32
  /** @typedef {Record<string, any> | import("vue").Ref<Record<string, any>> | ((context: Record<string, any>) => Record<string, any>) | null} RequestQueryParams */
27
33
  /** @typedef {(model: any, payload: any, context: Record<string, any>) => void} MapLoadedToModel */
28
34
 
@@ -278,7 +284,7 @@
278
284
  * @property {HttpClient} [client]
279
285
  * @property {Record<string, any> | null} [transport]
280
286
  * @property {RequestRecovery} [requestRecovery]
281
- * @property {string} [requestRecoveryLabel]
287
+ * @property {string} [requestRecoveryLabel] The request recovery banner's label: only with `requestRecovery: true`, refused (a TypeError) without it.
282
288
  * @property {string} [placementSource]
283
289
  * @property {string} [fallbackLoadError]
284
290
  * @property {string} [fallbackSaveError]
@@ -350,7 +356,7 @@
350
356
  * @property {HttpClient} [client]
351
357
  * @property {Record<string, any> | null} [transport]
352
358
  * @property {RequestRecovery} [requestRecovery]
353
- * @property {string} [requestRecoveryLabel]
359
+ * @property {string} [requestRecoveryLabel] The request recovery banner's label: only with `requestRecovery: true`, refused (a TypeError) without it.
354
360
  * @property {string} [placementSource]
355
361
  * @property {string} [fallbackLoadError]
356
362
  * @property {number[]} [notFoundStatuses]
@@ -397,7 +403,7 @@
397
403
  * @property {Record<string, any>} [requestOptions]
398
404
  * @property {Record<string, any>} [queryOptions]
399
405
  * @property {RequestRecovery} [requestRecovery]
400
- * @property {string} [requestRecoveryLabel]
406
+ * @property {string} [requestRecoveryLabel] The request recovery banner's label: only with `requestRecovery: true`, refused (a TypeError) without it.
401
407
  * @property {OperationRealtime | false | null} [realtime]
402
408
  * @property {string} [recordIdParam]
403
409
  * @property {(record: Record<string, any>) => unknown} [recordIdSelector]
@@ -561,7 +567,6 @@
561
567
  * @property {RequestQueryParams} [requestFieldsets]
562
568
  * @property {ReadEnabled} [readEnabled]
563
569
  * @property {QueryKeyFactory} [queryKeyFactory]
564
- * @property {string} [requestRecoveryLabel]
565
570
  * @property {string} [fallbackLoadError]
566
571
  * @property {string} [notFoundMessage]
567
572
  */
@@ -589,7 +594,6 @@
589
594
  * @property {RequestQueryParams} [requestQueryParams]
590
595
  * @property {RequestQueryParams} [requestFieldsets]
591
596
  * @property {ReadEnabled} [readEnabled]
592
- * @property {string} [requestRecoveryLabel]
593
597
  * @property {string} [fallbackLoadError]
594
598
  */
595
599
 
@@ -15,7 +15,8 @@ const hooks = registerHooks({
15
15
  return {
16
16
  format: "module",
17
17
  shortCircuit: true,
18
- source: "export const useList = () => ({ items: [{ id: 7, name: 'Bath' }] });"
18
+ source: "export const useList = (options) => { (globalThis.lookupUseListCalls ||= []).push(options); " +
19
+ "return { items: [{ id: 7, name: 'Bath' }] }; };"
19
20
  };
20
21
  }
21
22
  });
@@ -304,3 +305,13 @@ test("lookup items never title the selected value with its raw id", () => {
304
305
  [{ value: "53", label: "Daycare - One Day", record: { id: 53, name: "Daycare - One Day" } }, ...listed]
305
306
  );
306
307
  });
308
+
309
+ // A lookup field shows no load error of its own, so its options keep the shell's request recovery banner, which
310
+ // useList leaves out for a screen that shows its own.
311
+ test("a lookup field's options read asks for the shell's request recovery", () => {
312
+ globalThis.lookupUseListCalls = [];
313
+ createCrudLookupFieldRuntime({ formFields: serviceFormFields });
314
+
315
+ assert.equal(globalThis.lookupUseListCalls.length, 1);
316
+ assert.equal(globalThis.lookupUseListCalls[0].requestRecovery, true);
317
+ });
@@ -37,3 +37,10 @@ test("toUiErrorMessage uses fallback copy for generic transport errors", () => {
37
37
  );
38
38
  assert.equal(toUiErrorMessage({}, "Unable to save."), "Unable to save.");
39
39
  });
40
+
41
+ test("a request past its deadline reads as transport wording, never the browser's \"signal timed out\"", () => {
42
+ const timedOut = new DOMException("signal timed out", "TimeoutError");
43
+ assert.equal(toQueryErrorMessage(timedOut, "Unable to load list."), "Unable to load list.");
44
+ assert.equal(toUiErrorMessage(timedOut, "Unable to save."), "Unable to save.");
45
+ assert.equal(toUiErrorMessage(timedOut), "The server took too long to answer. Try again.");
46
+ });
@@ -4,6 +4,8 @@ import { QueryClient, VueQueryPlugin } from "@tanstack/vue-query";
4
4
  import { createRenderer, h, reactive } from "vue";
5
5
  import { createMemoryHistory, createRouter } from "vue-router";
6
6
  import { SHELL_WEB_ERROR_RUNTIME_KEY } from "@jskit-ai/shell-web/client/error";
7
+ import { silentLogger } from "@jskit-ai/kernel/shared/support/silentLogger";
8
+ import { createShellRequestRecoveryRuntime } from "../../shell-web/src/client/requestRecovery/runtime.js";
7
9
  import { useAddEdit } from "../src/client/composables/records/useAddEdit.js";
8
10
  import { useCrudList } from "../src/client/composables/records/useCrudList.js";
9
11
  import { useList } from "../src/client/composables/records/useList.js";
@@ -59,10 +61,12 @@ async function waitFor(check, message) {
59
61
  }
60
62
 
61
63
  // Mounts one runtime whose every read fails with `status` (and `message`, by default one of the server's own, and the
62
- // server's `code` when given), and records what it reports to the shell.
64
+ // server's `code` when given), and records what it reports to the shell. With `shellRequestRecovery`, shell-web's
65
+ // request recovery watches the same queries and reports to the same shell, as an app's shell has it.
63
66
  async function mountFailingLoad(t, status, useRuntime, {
64
67
  message = `Contacts refused the read (${describeStatus(status)}).`,
65
- code
68
+ code,
69
+ shellRequestRecovery = false
66
70
  } = {}) {
67
71
  const requests = [];
68
72
  const client = {
@@ -95,15 +99,21 @@ async function mountFailingLoad(t, status, useRuntime, {
95
99
  });
96
100
  app.use(router);
97
101
  app.use(VueQueryPlugin, { queryClient });
98
- app.provide(SHELL_WEB_ERROR_RUNTIME_KEY, {
102
+ const shell = {
99
103
  report(event) {
100
104
  reports.push(event);
101
105
  return { presentationId: `presentation-${reports.length}` };
102
106
  },
103
107
  dismiss() {}
104
- });
108
+ };
109
+ app.provide(SHELL_WEB_ERROR_RUNTIME_KEY, shell);
110
+ const requestRecovery = shellRequestRecovery
111
+ ? createShellRequestRecoveryRuntime({ queryClient, errorRuntime: shell, logger: silentLogger })
112
+ : null;
113
+ requestRecovery?.install();
105
114
  app.mount(node("root"));
106
115
  t.after(() => {
116
+ requestRecovery?.dispose();
107
117
  app.unmount();
108
118
  queryClient.clear();
109
119
  });
@@ -225,15 +235,9 @@ const LOAD_REFUSALS = Object.freeze([
225
235
  }
226
236
  ]);
227
237
 
228
- const REFUSAL_RUNTIMES = Object.freeze({
229
- useList: (client) => useList(listOptions(client)),
230
- useView: (client) => useView({
231
- apiSuffix: "/contacts/7",
232
- ownershipFilter: "public",
233
- client,
234
- queryKeyFactory: () => ["contacts", "7"]
235
- }),
236
- useAddEdit: (client) => useAddEdit({
238
+ const REFUSAL_RUNTIMES_OPTIONS = Object.freeze({
239
+ view: (client) => ({ apiSuffix: "/contacts/7", ownershipFilter: "public", client, queryKeyFactory: () => ["contacts", "7"] }),
240
+ addEdit: (client) => ({
237
241
  apiSuffix: "/contacts/7",
238
242
  ownershipFilter: "public",
239
243
  client,
@@ -241,6 +245,11 @@ const REFUSAL_RUNTIMES = Object.freeze({
241
245
  model: reactive({ name: "" })
242
246
  })
243
247
  });
248
+ const REFUSAL_RUNTIMES = Object.freeze({
249
+ useList: (client) => useList(listOptions(client)),
250
+ useView: (client) => useView(REFUSAL_RUNTIMES_OPTIONS.view(client)),
251
+ useAddEdit: (client) => useAddEdit(REFUSAL_RUNTIMES_OPTIONS.addEdit(client))
252
+ });
244
253
 
245
254
  for (const [name, useRuntime] of Object.entries(REFUSAL_RUNTIMES)) {
246
255
  for (const { label, status, message, refusal } of LOAD_REFUSALS) {
@@ -268,3 +277,94 @@ test("useCrudList: a 400 for a query key the list does not take says the server'
268
277
  assert.equal(mounted.runtime.errorStatus, 400);
269
278
  assert.equal(mounted.runtime.loadRefusalMessage, sentence);
270
279
  });
280
+
281
+ // A network failure of a screen's read shows once: the screen shows the runtime's `loadError` with Retry, and the shell
282
+ // gets its one load notice, whose channel the app's error policy picks. shell-web's request recovery, which reports a
283
+ // network failure of a read as its own banner with its own Retry, leaves these reads out.
284
+ const SCREEN_READS = Object.freeze({
285
+ ...REFUSAL_RUNTIMES,
286
+ useCrudList: (client) => useCrudList(listOptions(client))
287
+ });
288
+ const NETWORK_FAILURE = "Failed to fetch";
289
+
290
+ for (const [name, useRuntime] of Object.entries(SCREEN_READS)) {
291
+ test(`${name}: a network failure shows once, as its own load notice, not again as the shell's request recovery banner`, async (t) => {
292
+ const mounted = await mountFailingLoad(t, undefined, useRuntime, {
293
+ message: NETWORK_FAILURE,
294
+ shellRequestRecovery: true
295
+ });
296
+ // Long enough for the request recovery observer, which reports from the query cache's events, to have spoken.
297
+ await new Promise((resolve) => setTimeout(resolve, 50));
298
+
299
+ assert.deepEqual(mounted.reports.map((event) => event.intent), ["resource-load"]);
300
+ assertRetryOffer(mounted, { status: undefined, retry: true });
301
+ assert.ok(mounted.runtime.loadError);
302
+ });
303
+ }
304
+
305
+ // The errors a reader's setup throws, as the app's error handler receives them.
306
+ async function setupErrors(t, useRuntime) {
307
+ const router = createRouter({
308
+ history: createMemoryHistory(),
309
+ routes: [{ path: "/contacts/:recordId?", component: { render: () => h("div") } }]
310
+ });
311
+ await router.push("/contacts/7");
312
+ await router.isReady();
313
+ const errors = [];
314
+ const app = renderer.createApp({
315
+ setup() {
316
+ useRuntime({ async request() { return {}; } });
317
+ return () => h("div");
318
+ }
319
+ });
320
+ app.config.errorHandler = (error) => errors.push(error);
321
+ app.use(router);
322
+ app.use(VueQueryPlugin, { queryClient: new QueryClient() });
323
+ app.provide(SHELL_WEB_ERROR_RUNTIME_KEY, { report: () => ({}), dismiss() {} });
324
+ app.mount(node("root"));
325
+ t.after(() => app.unmount());
326
+ return errors;
327
+ }
328
+
329
+ // A label names the banner, which a screen read leaves out: given without requestRecovery: true it names nothing, as
330
+ // in an application written before this default, so the read is refused and the error says what to change.
331
+ const LABELLED_SCREEN_READS = Object.freeze([
332
+ ["useList", "useList", (client) => useList({ ...listOptions(client), requestRecoveryLabel: "Contacts" })],
333
+ ["useList with requestRecovery: false", "useList", (client) => useList({
334
+ ...listOptions(client),
335
+ requestRecovery: false,
336
+ requestRecoveryLabel: "Contacts"
337
+ })],
338
+ ["useView", "useView", (client) => useView({ ...REFUSAL_RUNTIMES_OPTIONS.view(client), requestRecoveryLabel: "Contact" })],
339
+ ["useAddEdit", "useAddEdit", (client) => useAddEdit({ ...REFUSAL_RUNTIMES_OPTIONS.addEdit(client), requestRecoveryLabel: "Contact" })],
340
+ ["useCrudList", "useList", (client) => useCrudList({ ...listOptions(client), requestRecoveryLabel: "Contacts" })]
341
+ ]);
342
+
343
+ for (const [name, caller, useRuntime] of LABELLED_SCREEN_READS) {
344
+ test(`${name}: a requestRecoveryLabel without requestRecovery: true is refused, naming the fix`, async (t) => {
345
+ const errors = await setupErrors(t, useRuntime);
346
+ assert.equal(errors.length, 1);
347
+ assert.ok(errors[0] instanceof TypeError);
348
+ assert.equal(errors[0].message, `${caller}() was given requestRecoveryLabel, which names the shell's request ` +
349
+ "recovery banner, but its read leaves the banner out unless requestRecovery is true: its screen shows the failure " +
350
+ "as loadError. Pass requestRecovery: true for a read whose screen shows no loadError (a lookup's options), or " +
351
+ "drop requestRecoveryLabel where the screen shows loadError (a CRUD screen always does).");
352
+ });
353
+ }
354
+
355
+ // A read whose screen shows no load error (a lookup's options) asks for the banner, and gets it with its Retry.
356
+ test("useList with requestRecovery: a network failure also shows as the shell's request recovery banner", async (t) => {
357
+ const mounted = await mountFailingLoad(t, undefined, (client) => useList({
358
+ ...listOptions(client),
359
+ requestRecovery: true,
360
+ requestRecoveryLabel: "Contacts"
361
+ }), { message: NETWORK_FAILURE, shellRequestRecovery: true });
362
+
363
+ await waitFor(
364
+ () => mounted.reports.some((event) => event.intent === "app-recoverable"),
365
+ "Expected the shell's request recovery banner."
366
+ );
367
+ const banner = mounted.reports.find((event) => event.intent === "app-recoverable");
368
+ assert.equal(banner.message, "Contacts could not reach the server or network. Check the connection and try again.");
369
+ assert.equal(banner.action.label, "Retry");
370
+ });
@@ -160,12 +160,12 @@ test("CRUD list chrome is English by default and follows the active language", a
160
160
  });
161
161
 
162
162
  test("date filters format with the app's active language", async () => {
163
- const filter = { type: "dateRange", label: "jskit.http.crud.records" };
163
+ const filter = { type: "dateRange", label: "jskit.http.crud.record" };
164
164
  await withTestLanguage(() => {
165
165
  assert.equal(formatDateOnlyDisplay("2026-04-18"), "18 Apr 2026");
166
166
  assert.equal(
167
167
  formatCrudListDateFilterChipLabel(filter, { from: "2026-05-04", to: "2026-05-10" }),
168
- "[xx] [xx] Records: 4 May 2026 to 10 May 2026"
168
+ "[xx] [xx] Record: 4 May 2026 to 10 May 2026"
169
169
  );
170
170
  }, "en-GB");
171
171
  });
@@ -232,3 +232,24 @@ test("a lookup filter reads nothing until its options are shown, and labels a se
232
232
  assert.equal(lookup.options[0].label, "Farm 01");
233
233
  assert.equal(lookup.options[44].label, "Farm 45");
234
234
  });
235
+
236
+ // A filter's options show no load error of their own, so both of its reads keep the shell's request recovery banner,
237
+ // which useList leaves out for a screen that shows its own: their queries carry the recovery hints, never `false`.
238
+ test("a lookup filter's reads ask for the shell's request recovery", async (t) => {
239
+ const values = reactive({ supplierContactId: ["44"] });
240
+ const { app, filterLookups, queryClient } = await mountSupplierLookup(values);
241
+ t.after(() => {
242
+ app.unmount();
243
+ queryClient.clear();
244
+ configureHttpWebClient({});
245
+ });
246
+ await settle(() => filterLookups.resolveLookupLabel("supplierContactId", "44", "Supplier") === "Farm 44");
247
+
248
+ // The options' query and the selected values' query, one per key they have had.
249
+ const recoveries = queryClient.getQueryCache().getAll().map((query) => query.meta?.jskit || {});
250
+ assert.ok(recoveries.length >= 2);
251
+ for (const recovery of recoveries) {
252
+ assert.notEqual(recovery.requestRecovery, false);
253
+ assert.equal(recovery.requestRecoveryMethod, "GET");
254
+ }
255
+ });
@@ -260,3 +260,24 @@ test("useCrudListParentTitle requests the parent through JSON:API record transpo
260
260
  responseKind: "record"
261
261
  });
262
262
  });
263
+
264
+ // The title falls back to the entity's label and shows no load error, so the parent's read keeps the shell's request
265
+ // recovery banner, which useView leaves out for a screen that shows its own.
266
+ test("useCrudListParentTitle's parent read asks for the shell's request recovery", () => {
267
+ let capturedOptions = null;
268
+ useCrudListParentTitle({
269
+ listRuntime: { items: [], isInitialLoading: false, loadError: "" },
270
+ resource: contactChildResource,
271
+ recordIdParam: "availabilityRuleId",
272
+ route: {
273
+ matched: [{ path: "/w/:workspaceSlug/admin/contacts/:contactId/availabilities" }],
274
+ params: { workspaceSlug: "harbor", contactId: "538779" }
275
+ },
276
+ viewRuntimeFactory: (options = {}) => {
277
+ capturedOptions = options;
278
+ return { record: null, isLoading: false, loadError: "" };
279
+ }
280
+ });
281
+
282
+ assert.equal(capturedOptions.requestRecovery, true);
283
+ });