@jskit-ai/shell-web 0.2.4 → 0.2.6

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.
Files changed (68) hide show
  1. package/package.json +10 -4
  2. package/src/client/asyncModuleRecovery/index.js +1 -0
  3. package/src/client/asyncModuleRecovery/inject.js +30 -18
  4. package/src/client/asyncModuleRecovery/runtime.js +14 -22
  5. package/src/client/bootstrap/bootstrapPayloadHandlerRegistry.js +13 -6
  6. package/src/client/browser.js +56 -0
  7. package/src/client/clientUpdate/runtime.js +28 -18
  8. package/src/client/components/ShellErrorHost.vue +19 -219
  9. package/src/client/components/ShellLayout.vue +19 -227
  10. package/src/client/components/ShellOutlet.vue +16 -53
  11. package/src/client/components/ShellRouteTransition.vue +2 -291
  12. package/src/client/composables/shellLayoutDrawerPreference.js +15 -8
  13. package/src/client/composables/useShellDrawer.js +194 -0
  14. package/src/client/composables/useShellErrorHost.js +171 -0
  15. package/src/client/composables/useShellLayoutState.js +10 -20
  16. package/src/client/composables/useShellNavigationLink.js +6 -6
  17. package/src/client/composables/useShellPullToRefresh.js +15 -19
  18. package/src/client/composables/useShellRouteTransition.js +218 -0
  19. package/src/client/error/index.js +1 -1
  20. package/src/client/error/inject.js +36 -48
  21. package/src/client/error/normalize.js +2 -3
  22. package/src/client/error/policy.js +9 -0
  23. package/src/client/error/presentation.js +67 -0
  24. package/src/client/error/presentationDefaults.js +2 -2
  25. package/src/client/error/presenters.js +44 -19
  26. package/src/client/error/runtime.js +20 -17
  27. package/src/client/error/store.js +4 -0
  28. package/src/client/navigation/linkResolver.js +6 -2
  29. package/src/client/navigation/usePaths.js +11 -8
  30. package/src/client/navigation/useSurfaceRouteContext.js +3 -3
  31. package/src/client/placement/debug.js +2 -2
  32. package/src/client/placement/index.js +1 -0
  33. package/src/client/placement/inject.js +49 -46
  34. package/src/client/placement/pathname.js +3 -9
  35. package/src/client/placement/runtime.js +4 -16
  36. package/src/client/placement/surfaceContext.js +14 -33
  37. package/src/client/placement/validators.js +6 -1
  38. package/src/client/providers/ShellWebClientProvider.js +14 -32
  39. package/src/client/providers/appModuleLoadFailure.js +1 -1
  40. package/src/client/requestRecovery/index.js +1 -0
  41. package/src/client/requestRecovery/inject.js +29 -17
  42. package/src/client/requestRecovery/runtime.js +33 -84
  43. package/src/client/runtime/bootstrapRuntime.js +10 -32
  44. package/src/client/runtime/refreshRuntime.js +24 -21
  45. package/src/client/stores/useShellErrorPresentationStore.js +5 -19
  46. package/src/client/support/drawerWidth.js +39 -0
  47. package/src/client/support/gestureTargets.js +4 -2
  48. package/src/client/support/menuLinkTarget.js +1 -1
  49. package/src/client/support/navigationLinkKeyboard.js +1 -1
  50. package/src/client/support/primaryNavigation.js +93 -0
  51. package/src/client/support/routeSwipeGesture.js +13 -3
  52. package/src/client/support/shellLayoutClass.js +4 -6
  53. package/src/client/types.js +38 -0
  54. package/test/asyncModuleRecoveryInject.test.js +13 -18
  55. package/test/browser.test.js +51 -0
  56. package/test/clientUpdate.test.js +12 -1
  57. package/test/drawerWidth.test.js +64 -0
  58. package/test/errorActions.test.js +7 -2
  59. package/test/errorPresentation.test.js +51 -0
  60. package/test/placementInject.test.js +60 -0
  61. package/test/primaryNavigation.test.js +75 -0
  62. package/test/provider.test.js +18 -4
  63. package/test/requestRecovery.test.js +13 -18
  64. package/test/settingsPlacementContract.test.js +12 -8
  65. package/test/support/mountComposable.js +90 -0
  66. package/test/useShellDrawer.test.js +213 -0
  67. package/test/useShellErrorHost.test.js +149 -0
  68. package/test/useShellRouteTransition.test.js +129 -0
@@ -1,5 +1,5 @@
1
1
  import { computed, unref } from "vue";
2
- import { normalizeText } from "@jskit-ai/kernel/shared/support/normalize";
2
+ import { normalizeObject, normalizeText } from "@jskit-ai/kernel/shared/support/normalize";
3
3
  import { resolveScopedApiBasePath } from "@jskit-ai/kernel/shared/surface";
4
4
  import { resolveSurfaceDefinitionFromPlacementContext } from "../placement/index.js";
5
5
  import { useShellLinkResolver } from "./linkResolver.js";
@@ -40,13 +40,16 @@ function resolveRouteParams(baseParams = {}, overrideParams = null) {
40
40
  };
41
41
  }
42
42
 
43
- function usePaths({ routeContext: sourceRouteContext = null } = {}) {
44
- const routeContext = sourceRouteContext || useSurfaceRouteContext();
43
+ /**
44
+ * @param {object} [options]
45
+ * @param {import("../types.js").SurfaceRouteContext} [options.routeContext]
46
+ */
47
+ function usePaths({ routeContext = useSurfaceRouteContext() } = {}) {
45
48
  const shellLinkResolver = useShellLinkResolver();
46
- const routeParams = computed(() => normalizeRouteParams(routeContext.route?.params));
49
+ const routeParams = computed(() => normalizeRouteParams(routeContext.route.params));
47
50
 
48
51
  function page(relativePath = "/", options = {}) {
49
- const source = options && typeof options === "object" && !Array.isArray(options) ? options : {};
52
+ const source = normalizeObject(options);
50
53
  const surface =
51
54
  resolveSurfaceId(source.surface, routeContext.currentSurfaceId.value) ||
52
55
  resolveDefaultSurfaceIdFromPlacementContext(routeContext.placementContext.value);
@@ -63,7 +66,7 @@ function usePaths({ routeContext: sourceRouteContext = null } = {}) {
63
66
  }
64
67
 
65
68
  function api(relativePath = "", options = {}) {
66
- const source = options && typeof options === "object" && !Array.isArray(options) ? options : {};
69
+ const source = normalizeObject(options);
67
70
  const surface =
68
71
  resolveSurfaceId(source.surface, routeContext.currentSurfaceId.value) ||
69
72
  resolveDefaultSurfaceIdFromPlacementContext(routeContext.placementContext.value);
@@ -86,14 +89,14 @@ function usePaths({ routeContext: sourceRouteContext = null } = {}) {
86
89
  });
87
90
  }
88
91
 
89
- return Object.freeze({
92
+ return {
90
93
  route: routeContext.route,
91
94
  placementContext: routeContext.placementContext,
92
95
  currentSurfaceId: routeContext.currentSurfaceId,
93
96
  routeParams,
94
97
  page,
95
98
  api
96
- });
99
+ };
97
100
  }
98
101
 
99
102
  export { usePaths };
@@ -9,18 +9,18 @@ import {
9
9
  function useSurfaceRouteContext() {
10
10
  const route = useRoute();
11
11
  const { context: placementContext, mergeContext: mergePlacementContext } = useWebPlacementContext();
12
- const routePath = computed(() => resolveRuntimePathname(route?.path));
12
+ const routePath = computed(() => resolveRuntimePathname(route.path));
13
13
  const currentSurfaceId = computed(() =>
14
14
  resolveSurfaceIdFromPlacementPathname(placementContext.value, routePath.value)
15
15
  );
16
16
 
17
- return Object.freeze({
17
+ return {
18
18
  route,
19
19
  routePath,
20
20
  placementContext,
21
21
  mergePlacementContext,
22
22
  currentSurfaceId
23
- });
23
+ };
24
24
  }
25
25
 
26
26
  export { useSurfaceRouteContext };
@@ -1,11 +1,11 @@
1
1
  const DEFAULT_DEBUG_DEPTH = 4;
2
2
 
3
3
  function describeFunction(fn) {
4
- return `[Function ${fn?.name || "anonymous"}]`;
4
+ return `[Function ${fn.name || "anonymous"}]`;
5
5
  }
6
6
 
7
7
  function describeSymbol(value) {
8
- return value?.toString ? value.toString() : "[Symbol]";
8
+ return value.toString();
9
9
  }
10
10
 
11
11
  function explodePayload(value, depth = DEFAULT_DEBUG_DEPTH) {
@@ -8,6 +8,7 @@ export {
8
8
  } from "./validators.js";
9
9
 
10
10
  export {
11
+ NO_WEB_PLACEMENT_RUNTIME,
11
12
  SHELL_WEB_PLACEMENT_RUNTIME_KEY,
12
13
  useWebPlacementContext
13
14
  } from "./inject.js";
@@ -2,18 +2,25 @@ import {
2
2
  inject,
3
3
  onBeforeUnmount,
4
4
  onMounted,
5
+ ref,
5
6
  shallowRef
6
7
  } from "vue";
7
8
 
8
9
  const SHELL_WEB_PLACEMENT_RUNTIME_KEY = "jskit.shell-web.runtime.web-placement.client";
9
10
 
10
- const EMPTY_WEB_PLACEMENT_RUNTIME = Object.freeze({
11
- getContext() {
12
- return Object.freeze({});
13
- },
11
+ /**
12
+ * The placement runtime of an application without shell-web's provider: nothing is placed.
13
+ * @type {any}
14
+ */
15
+ const NO_WEB_PLACEMENT_RUNTIME = Object.freeze({
16
+ replacePlacements() {},
17
+ replacePlacementTopology() {},
14
18
  getPlacements() {
15
19
  return Object.freeze([]);
16
20
  },
21
+ getContext() {
22
+ return Object.freeze({});
23
+ },
17
24
  setContext() {
18
25
  return Object.freeze({});
19
26
  },
@@ -25,55 +32,37 @@ const EMPTY_WEB_PLACEMENT_RUNTIME = Object.freeze({
25
32
  }
26
33
  });
27
34
 
28
- const EMPTY_WEB_PLACEMENT_CONTEXT_REF = shallowRef(Object.freeze({}));
29
-
30
- const EMPTY_WEB_PLACEMENT_CONTEXT = Object.freeze({
31
- context: EMPTY_WEB_PLACEMENT_CONTEXT_REF,
32
- mergeContext() {
33
- return EMPTY_WEB_PLACEMENT_CONTEXT_REF.value;
34
- },
35
- replaceContext() {
36
- return EMPTY_WEB_PLACEMENT_CONTEXT_REF.value;
37
- }
38
- });
39
-
40
- function useWebPlacementRuntime({ required = false } = {}) {
41
- const runtime = inject(SHELL_WEB_PLACEMENT_RUNTIME_KEY, null);
42
- if (runtime && typeof runtime.getPlacements === "function") {
43
- return runtime;
44
- }
45
-
46
- if (required) {
47
- throw new Error("Web placement runtime is not available in Vue injection context.");
48
- }
49
-
50
- return EMPTY_WEB_PLACEMENT_RUNTIME;
35
+ /**
36
+ * The shell's placement runtime, or `NO_WEB_PLACEMENT_RUNTIME` in an application without shell-web's provider.
37
+ * @returns {import("../types.js").WebPlacementRuntime}
38
+ */
39
+ function useWebPlacementRuntime() {
40
+ return inject(SHELL_WEB_PLACEMENT_RUNTIME_KEY, NO_WEB_PLACEMENT_RUNTIME);
51
41
  }
52
42
 
53
- function useWebPlacementContext({ required = false } = {}) {
54
- const runtime = useWebPlacementRuntime({ required });
55
- if (runtime === EMPTY_WEB_PLACEMENT_RUNTIME) {
56
- return EMPTY_WEB_PLACEMENT_CONTEXT;
57
- }
58
-
59
- const context = shallowRef(runtime.getContext());
43
+ // Runs the listener on every placement change while the component is mounted.
44
+ function followWebPlacementRuntime(runtime, listener) {
60
45
  let unsubscribe = null;
61
46
 
62
47
  onMounted(() => {
63
- if (typeof runtime.subscribe !== "function") {
64
- return;
65
- }
66
- unsubscribe = runtime.subscribe(() => {
67
- context.value = runtime.getContext();
68
- });
48
+ unsubscribe = runtime.subscribe(listener);
69
49
  });
70
50
 
71
51
  onBeforeUnmount(() => {
72
- if (typeof unsubscribe === "function") {
52
+ if (unsubscribe) {
73
53
  unsubscribe();
74
54
  unsubscribe = null;
75
55
  }
76
56
  });
57
+ }
58
+
59
+ function useWebPlacementContext() {
60
+ const runtime = useWebPlacementRuntime();
61
+ const context = shallowRef(runtime.getContext());
62
+
63
+ followWebPlacementRuntime(runtime, () => {
64
+ context.value = runtime.getContext();
65
+ });
77
66
 
78
67
  function mergeContext(value = {}, source = "component") {
79
68
  context.value = runtime.setContext(value, {
@@ -90,17 +79,31 @@ function useWebPlacementContext({ required = false } = {}) {
90
79
  return context.value;
91
80
  }
92
81
 
93
- return Object.freeze({
82
+ return {
94
83
  context,
95
84
  mergeContext,
96
85
  replaceContext
86
+ };
87
+ }
88
+
89
+ /**
90
+ * The runtime's revision, for a computed that must read its placements again when they change.
91
+ * @param {import("../types.js").WebPlacementRuntime} runtime
92
+ */
93
+ function useWebPlacementRevision(runtime) {
94
+ const revision = ref(runtime.getRevision());
95
+
96
+ followWebPlacementRuntime(runtime, (event) => {
97
+ revision.value = event.revision;
97
98
  });
99
+
100
+ return revision;
98
101
  }
99
102
 
100
103
  export {
104
+ NO_WEB_PLACEMENT_RUNTIME,
101
105
  SHELL_WEB_PLACEMENT_RUNTIME_KEY,
102
- EMPTY_WEB_PLACEMENT_RUNTIME,
103
- EMPTY_WEB_PLACEMENT_CONTEXT,
104
- useWebPlacementRuntime,
105
- useWebPlacementContext
106
+ useWebPlacementContext,
107
+ useWebPlacementRevision,
108
+ useWebPlacementRuntime
106
109
  };
@@ -1,14 +1,8 @@
1
+ import { pagePathname } from "../browser.js";
2
+
1
3
  function resolveRuntimePathname(candidate = "") {
2
4
  const explicitPathname = String(candidate || "").trim();
3
- if (explicitPathname) {
4
- return explicitPathname;
5
- }
6
-
7
- if (typeof window === "object" && window?.location?.pathname) {
8
- return String(window.location.pathname || "").trim() || "/";
9
- }
10
-
11
- return "/";
5
+ return explicitPathname || pagePathname() || "/";
12
6
  }
13
7
 
14
8
  export { resolveRuntimePathname };
@@ -27,10 +27,6 @@ const PLACEMENT_DEBUG_PREFIX = "[placement-debug]";
27
27
  const PLACEMENT_DEBUG_FLAG = "__JSKIT_PLACEMENT_DEBUG__";
28
28
 
29
29
  function isPlacementDebugEnabled() {
30
- if (typeof globalThis !== "object" || !globalThis) {
31
- return false;
32
- }
33
-
34
30
  return globalThis[PLACEMENT_DEBUG_FLAG] === true;
35
31
  }
36
32
 
@@ -281,10 +277,6 @@ function resolvePlacementComponent(
281
277
  }
282
278
 
283
279
  function shouldIncludePlacement(placement, placementContext, logger) {
284
- if (typeof placement.when !== "function") {
285
- return true;
286
- }
287
-
288
280
  try {
289
281
  return placement.when(Object.freeze({ ...placementContext })) === true;
290
282
  } catch (error) {
@@ -301,15 +293,11 @@ function shouldIncludePlacement(placement, placementContext, logger) {
301
293
 
302
294
  /**
303
295
  * @param {object} options
304
- * @param {Map<string, any> | { has: Function, get: Function }} options.components
296
+ * @param {Pick<import("@jskit-ai/kernel/client/types").ClientComponents, "has" | "get">} options.components
305
297
  * @param {Function[]} [options.contextContributors]
306
- * @param {import("@jskit-ai/kernel/server/types").RuntimeLogger} options.logger
298
+ * @param {import("@jskit-ai/kernel/client/types").ClientLogger} options.logger
307
299
  */
308
300
  function createWebPlacementRuntime({ components, contextContributors = [], logger }) {
309
- if (!components || typeof components.has !== "function" || typeof components.get !== "function") {
310
- throw new Error("createWebPlacementRuntime requires a client component registry.");
311
- }
312
-
313
301
  const missingTokens = new Set();
314
302
  const invalidComponentTokens = new Set();
315
303
  const failedTokens = new Set();
@@ -418,10 +406,10 @@ function createWebPlacementRuntime({ components, contextContributors = [], logge
418
406
  const normalizedSurface = normalizeSurface(surface);
419
407
  const normalizedLayoutClass =
420
408
  normalizePlacementLayoutClass(layoutClass) ||
421
- normalizePlacementLayoutClass(sharedContext?.layoutClass) ||
409
+ normalizePlacementLayoutClass(sharedContext.layoutClass) ||
422
410
  "compact";
423
411
  const baseContext = isRecord(context) ? { ...context } : {};
424
- const contextFromRuntime = isRecord(sharedContext) ? sharedContext : {};
412
+ const contextFromRuntime = sharedContext;
425
413
  const contextFromContributors = resolveContextContributors(
426
414
  contextContributors,
427
415
  {
@@ -8,6 +8,7 @@ import { isRecord } from "@jskit-ai/kernel/shared/support/normalize";
8
8
  import { normalizePathname } from "@jskit-ai/kernel/shared/surface/paths";
9
9
  import { isExternalLinkTarget, splitPathQueryHash } from "@jskit-ai/kernel/shared/support/linkPath";
10
10
  import { resolveAllowedOriginsFromSurfaceDefinitions } from "@jskit-ai/kernel/shared/support/returnToPath";
11
+ import { pageOrigin } from "../browser.js";
11
12
 
12
13
  const EMPTY_SURFACE_CONFIG = Object.freeze({
13
14
  tenancyMode: "",
@@ -83,22 +84,14 @@ function normalizeSurfaceConfig(surfaceConfig = {}) {
83
84
  });
84
85
  }
85
86
 
86
- function buildSurfaceConfigContext(surfaceRuntime = null, { tenancyMode = "" } = {}) {
87
- const normalizedTenancyMode = String(tenancyMode || "").trim().toLowerCase();
88
- if (!isRecord(surfaceRuntime)) {
89
- return normalizeSurfaceConfig({
90
- tenancyMode: normalizedTenancyMode
91
- });
92
- }
93
-
94
- const surfaceDefinitions =
95
- typeof surfaceRuntime.listSurfaceDefinitions === "function" ? surfaceRuntime.listSurfaceDefinitions() : [];
87
+ /**
88
+ * @param {import("@jskit-ai/kernel/client/types").ClientSurfaceRuntime} surfaceRuntime
89
+ * @param {object} [options]
90
+ * @param {string} [options.tenancyMode]
91
+ */
92
+ function buildSurfaceConfigContext(surfaceRuntime, { tenancyMode = "" } = {}) {
96
93
  const surfacesById = {};
97
- for (const definition of Array.isArray(surfaceDefinitions) ? surfaceDefinitions : []) {
98
- if (!isRecord(definition)) {
99
- continue;
100
- }
101
-
94
+ for (const definition of surfaceRuntime.listSurfaceDefinitions()) {
102
95
  const surfaceId = normalizeSurfaceId(definition.id);
103
96
  if (!surfaceId) {
104
97
  continue;
@@ -107,10 +100,9 @@ function buildSurfaceConfigContext(surfaceRuntime = null, { tenancyMode = "" } =
107
100
  }
108
101
 
109
102
  return normalizeSurfaceConfig({
110
- tenancyMode: normalizedTenancyMode,
103
+ tenancyMode: String(tenancyMode || "").trim().toLowerCase(),
111
104
  defaultSurfaceId: surfaceRuntime.DEFAULT_SURFACE_ID,
112
- enabledSurfaceIds:
113
- typeof surfaceRuntime.listEnabledSurfaceIds === "function" ? surfaceRuntime.listEnabledSurfaceIds() : [],
105
+ enabledSurfaceIds: surfaceRuntime.listEnabledSurfaceIds(),
114
106
  surfacesById
115
107
  });
116
108
  }
@@ -122,9 +114,9 @@ function readPlacementSurfaceConfig(contextValue = null) {
122
114
 
123
115
  // Origins a return-to URL may point at: this page plus every surface origin.
124
116
  function resolveAllowedOriginsFromPlacementContext(contextValue = null) {
125
- const seedOrigins = typeof window === "object" && window?.location?.origin ? [window.location.origin] : [];
117
+ const origin = pageOrigin();
126
118
  return resolveAllowedOriginsFromSurfaceDefinitions(readPlacementSurfaceConfig(contextValue).surfacesById, {
127
- seedOrigins
119
+ seedOrigins: origin ? [origin] : []
128
120
  });
129
121
  }
130
122
 
@@ -182,16 +174,7 @@ function normalizeSurfaceOrigin(originValue = "") {
182
174
  }
183
175
 
184
176
  function resolveRuntimeOrigin(currentOrigin = "") {
185
- const normalizedCurrentOrigin = normalizeSurfaceOrigin(currentOrigin);
186
- if (normalizedCurrentOrigin) {
187
- return normalizedCurrentOrigin;
188
- }
189
-
190
- if (typeof window === "object" && window?.location?.origin) {
191
- return normalizeSurfaceOrigin(window.location.origin);
192
- }
193
-
194
- return "";
177
+ return normalizeSurfaceOrigin(currentOrigin) || normalizeSurfaceOrigin(pageOrigin());
195
178
  }
196
179
 
197
180
  function resolveSurfaceNavigationTargetFromPlacementContext(
@@ -268,9 +251,7 @@ function createPlacementSurfacePathHelpers(surfaceConfig = EMPTY_SURFACE_CONFIG)
268
251
 
269
252
  function resolveSurfaceIdFromPlacementPathname(contextValue = null, pathname = "") {
270
253
  const surfaceConfig = readPlacementSurfaceConfig(contextValue);
271
- const normalizedPathname =
272
- normalizePathname(pathname) ||
273
- (typeof window === "object" && window?.location?.pathname ? normalizePathname(window.location.pathname) : "/");
254
+ const normalizedPathname = normalizePathname(pathname);
274
255
  const pathHelpers = createPlacementSurfacePathHelpers(surfaceConfig);
275
256
  if (!pathHelpers) {
276
257
  return "";
@@ -8,6 +8,11 @@ import {
8
8
  resolvePlacementTargetReference
9
9
  } from "@jskit-ai/kernel/shared/support/shellLayoutTargets";
10
10
 
11
+ // A placement that appears only sometimes supplies its own when().
12
+ function placeAlways() {
13
+ return true;
14
+ }
15
+
11
16
  function isRenderableComponent(value) {
12
17
  if (typeof value === "function") {
13
18
  return true;
@@ -105,7 +110,7 @@ function normalizePlacementDefinition(value, { strict = false, source = "placeme
105
110
  }
106
111
 
107
112
  const props = isRecord(value.props) ? { ...value.props } : {};
108
- const when = typeof value.when === "function" ? value.when : null;
113
+ const when = value.when || placeAlways;
109
114
  const surfaces = normalizePlacementSurfaces(value.surfaces, {
110
115
  strict,
111
116
  source: `${source} "${id}"`
@@ -17,8 +17,9 @@ import {
17
17
  createShellRequestRecoveryRuntime
18
18
  } from "../requestRecovery/runtime.js";
19
19
  import {
20
- isRecord
21
- } from "@jskit-ai/kernel/shared/support";
20
+ isRecord,
21
+ normalizeObject
22
+ } from "@jskit-ai/kernel/shared/support/normalize";
22
23
  import {
23
24
  createDefaultErrorPolicy
24
25
  } from "../error/policy.js";
@@ -66,11 +67,11 @@ async function loadAppModule({
66
67
  loadFailureMessage,
67
68
  fallback,
68
69
  logger,
69
- asyncModuleRecoveryRuntime = null
70
+ asyncModuleRecoveryRuntime
70
71
  }) {
71
72
  try {
72
73
  const moduleNamespace = await importModule();
73
- const exported = moduleNamespace?.default;
74
+ const exported = moduleNamespace.default;
74
75
  const resolved = await resolve(exported);
75
76
  if (resolved !== undefined) {
76
77
  return resolved;
@@ -101,7 +102,7 @@ async function loadAppModule({
101
102
  return fallback;
102
103
  }
103
104
 
104
- function loadAppPlacementDefinitions(logger, asyncModuleRecoveryRuntime = null) {
105
+ function loadAppPlacementDefinitions(logger, asyncModuleRecoveryRuntime) {
105
106
  return loadAppModule({
106
107
  importModule: () => import("/src/placement.js"),
107
108
  specifier: APP_PLACEMENT_MODULE_SPECIFIER,
@@ -118,7 +119,7 @@ function loadAppPlacementDefinitions(logger, asyncModuleRecoveryRuntime = null)
118
119
  });
119
120
  }
120
121
 
121
- function loadAppPlacementTopology(logger, asyncModuleRecoveryRuntime = null) {
122
+ function loadAppPlacementTopology(logger, asyncModuleRecoveryRuntime) {
122
123
  return loadAppModule({
123
124
  importModule: () => import("/src/placementTopology.js"),
124
125
  specifier: APP_PLACEMENT_TOPOLOGY_MODULE_SPECIFIER,
@@ -163,7 +164,7 @@ function createErrorConfigToolkit(errorRuntime) {
163
164
  });
164
165
  }
165
166
 
166
- function loadAppErrorConfig(logger, errorRuntime, asyncModuleRecoveryRuntime = null) {
167
+ function loadAppErrorConfig(logger, errorRuntime, asyncModuleRecoveryRuntime) {
167
168
  return loadAppModule({
168
169
  importModule: () => import("/src/error.js"),
169
170
  specifier: APP_ERROR_MODULE_SPECIFIER,
@@ -182,11 +183,7 @@ function loadAppErrorConfig(logger, errorRuntime, asyncModuleRecoveryRuntime = n
182
183
  }
183
184
 
184
185
  function installVueErrorBridge(vueApp, errorRuntime, logger) {
185
- if (!vueApp || !isRecord(vueApp.config)) {
186
- return;
187
- }
188
-
189
- const previousHandler = typeof vueApp.config.errorHandler === "function" ? vueApp.config.errorHandler : null;
186
+ const previousHandler = vueApp.config.errorHandler;
190
187
 
191
188
  vueApp.config.errorHandler = (error, instance, info) => {
192
189
  try {
@@ -217,10 +214,6 @@ function installVueErrorBridge(vueApp, errorRuntime, logger) {
217
214
  }
218
215
 
219
216
  function installRouterErrorBridge(router, errorRuntime, logger) {
220
- if (!router || typeof router.onError !== "function") {
221
- return;
222
- }
223
-
224
217
  router.onError((error) => {
225
218
  if (isDynamicImportError(error)) {
226
219
  return;
@@ -271,16 +264,15 @@ const ShellWebClientProvider = defineProvider({
271
264
  Object.freeze({
272
265
  handlerId: "shell.web.bootstrap.surface-access",
273
266
  order: 0,
274
- applyBootstrapPayload({ payload = {}, placementRuntime, source } = {}) {
267
+ applyBootstrapPayload({ payload, placementRuntime, source }) {
275
268
  placementRuntime.setContext(
276
269
  {
277
- surfaceAccess:
278
- payload?.surfaceAccess && typeof payload.surfaceAccess === "object" ? payload.surfaceAccess : {}
270
+ surfaceAccess: normalizeObject(normalizeObject(payload).surfaceAccess)
279
271
  },
280
272
  { source }
281
273
  );
282
274
  },
283
- handleBootstrapError({ error, placementRuntime, source } = {}) {
275
+ handleBootstrapError({ error, placementRuntime, source }) {
284
276
  if (resolveBootstrapErrorStatusCode(error) !== 401) {
285
277
  return;
286
278
  }
@@ -358,16 +350,12 @@ const ShellWebClientProvider = defineProvider({
358
350
  placementRuntime.replacePlacements(placements, { source: APP_PLACEMENT_MODULE_SPECIFIER });
359
351
  const appConfig = getClientAppConfig();
360
352
  const surfaceConfig = buildSurfaceConfigContext(surfaceRuntime, {
361
- tenancyMode: appConfig?.tenancyMode
353
+ tenancyMode: appConfig.tenancyMode
362
354
  });
363
- const surfaceAccessPolicies =
364
- appConfig?.surfaceAccessPolicies && typeof appConfig.surfaceAccessPolicies === "object"
365
- ? appConfig.surfaceAccessPolicies
366
- : {};
367
355
  placementRuntime.setContext(
368
356
  {
369
357
  surfaceConfig,
370
- surfaceAccessPolicies
358
+ surfaceAccessPolicies: normalizeObject(appConfig.surfaceAccessPolicies)
371
359
  },
372
360
  {
373
361
  source: "shell-web.surface-config"
@@ -382,12 +370,6 @@ const ShellWebClientProvider = defineProvider({
382
370
 
383
371
  await bootstrapRuntime.initialize();
384
372
 
385
- if (!vueApp || typeof vueApp.provide !== "function" || typeof vueApp.use !== "function") {
386
- return;
387
- }
388
- if (!pinia) {
389
- throw new Error("ShellWebClientProvider requires Pinia installed in the client app.");
390
- }
391
373
  useShellErrorPresentationStore(pinia).attachRuntimeStore(errorPresentationStore);
392
374
 
393
375
  vueApp.provide(SHELL_WEB_PLACEMENT_RUNTIME_KEY, placementRuntime);
@@ -17,7 +17,7 @@ function isMissingDynamicModule(error, moduleSpecifier) {
17
17
  function notifyDynamicImportFailure(asyncModuleRecoveryRuntime, error, {
18
18
  label = t("jskit.shell.recovery.appModuleLabel")
19
19
  } = {}) {
20
- if (!isDynamicImportError(error) || typeof asyncModuleRecoveryRuntime?.notify !== "function") {
20
+ if (!isDynamicImportError(error)) {
21
21
  return;
22
22
  }
23
23
 
@@ -1,4 +1,5 @@
1
1
  export {
2
+ NO_SHELL_REQUEST_RECOVERY_RUNTIME,
2
3
  SHELL_REQUEST_RECOVERY_RUNTIME_KEY,
3
4
  useShellRequestRecoveryRuntime
4
5
  } from "./inject.js";
@@ -1,30 +1,42 @@
1
- import {
2
- hasInjectionContext,
3
- inject
4
- } from "vue";
1
+ import { inject } from "vue";
2
+ import { isRecoverableRequestError } from "./runtime.js";
5
3
 
6
4
  const SHELL_REQUEST_RECOVERY_RUNTIME_KEY =
7
5
  "jskit.shell-web.runtime.web-request-recovery.client";
8
6
 
9
- function isShellRequestRecoveryRuntime(value) {
10
- return Boolean(
11
- value &&
12
- typeof value.report === "function" &&
13
- typeof value.reload === "function"
14
- );
15
- }
16
-
17
- function useShellRequestRecoveryRuntime() {
18
- if (!hasInjectionContext()) {
7
+ /**
8
+ * The recovery of an application without shell-web's provider: nothing is reported and nothing reloads.
9
+ * @type {import("../types.js").ShellRequestRecoveryRuntime}
10
+ */
11
+ const NO_SHELL_REQUEST_RECOVERY_RUNTIME = Object.freeze({
12
+ dismiss() {
13
+ return 0;
14
+ },
15
+ dispose() {},
16
+ install() {
17
+ return Object.freeze({
18
+ dispose() {}
19
+ });
20
+ },
21
+ isRecoverableRequestError,
22
+ async reload() {
23
+ return false;
24
+ },
25
+ report() {
19
26
  return null;
20
27
  }
28
+ });
21
29
 
22
- const runtime = inject(SHELL_REQUEST_RECOVERY_RUNTIME_KEY, null);
23
- return isShellRequestRecoveryRuntime(runtime) ? runtime : null;
30
+ /**
31
+ * The shell's request recovery, or `NO_SHELL_REQUEST_RECOVERY_RUNTIME` in an application without shell-web's provider.
32
+ * @returns {import("../types.js").ShellRequestRecoveryRuntime}
33
+ */
34
+ function useShellRequestRecoveryRuntime() {
35
+ return inject(SHELL_REQUEST_RECOVERY_RUNTIME_KEY, NO_SHELL_REQUEST_RECOVERY_RUNTIME);
24
36
  }
25
37
 
26
38
  export {
39
+ NO_SHELL_REQUEST_RECOVERY_RUNTIME,
27
40
  SHELL_REQUEST_RECOVERY_RUNTIME_KEY,
28
- isShellRequestRecoveryRuntime,
29
41
  useShellRequestRecoveryRuntime
30
42
  };