@adobe/aio-commerce-lib-admin-ui 0.2.0-beta-20260714082406 → 0.2.0-beta-20260721105643

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
@@ -1,6 +1,6 @@
1
1
  # @adobe/aio-commerce-lib-admin-ui
2
2
 
3
- ## 0.2.0-beta-20260714082406
3
+ ## 0.2.0-beta-20260721105643
4
4
  ### Minor Changes
5
5
 
6
6
 
@@ -43,8 +43,8 @@
43
43
  ### Patch Changes
44
44
 
45
45
  - Updated dependencies [[`19400fb`](https://github.com/adobe/aio-commerce-sdk/commit/19400fbdfc03c5bbfc30f995a2acdd4272c5e032), [`ce7768e`](https://github.com/adobe/aio-commerce-sdk/commit/ce7768e0ddc6ca35ad6ccec60f584c8bb5a743f0), [`4396a64`](https://github.com/adobe/aio-commerce-sdk/commit/4396a647ad22dba063cdf03a16e04aef9387212f), [`e85bec4`](https://github.com/adobe/aio-commerce-sdk/commit/e85bec40f1eaa91dd6bb7bc6954b2ecfc3ea4029), [`413da36`](https://github.com/adobe/aio-commerce-sdk/commit/413da36dcd83e5a41c194f5af50611097659e725)]:
46
- - @adobe/aio-commerce-lib-core@1.2.0-beta-20260714082406
47
- - @adobe/aio-commerce-lib-api@1.3.0-beta-20260714082406
46
+ - @adobe/aio-commerce-lib-core@1.2.0-beta-20260721105643
47
+ - @adobe/aio-commerce-lib-api@1.3.0-beta-20260721105643
48
48
 
49
49
  ## 0.1.0
50
50
 
@@ -53,6 +53,37 @@ function isControlFrame() {
53
53
  return isEmbeddedInHost() && !window.name;
54
54
  }
55
55
 
56
+ //#endregion
57
+ //#region source/web/react/result.ts
58
+ /** Creates a successful data result. */
59
+ function ok(data) {
60
+ return {
61
+ data,
62
+ error: null
63
+ };
64
+ }
65
+ /** Creates a failed data result. */
66
+ function error(message, options) {
67
+ return {
68
+ data: null,
69
+ error: new Error(message, options)
70
+ };
71
+ }
72
+ /** Creates a successful actions result. */
73
+ function okActions(actions) {
74
+ return {
75
+ actions,
76
+ error: null
77
+ };
78
+ }
79
+ /** Creates a failed actions result. */
80
+ function actionsError(message, options) {
81
+ return {
82
+ actions: null,
83
+ error: new Error(message, options)
84
+ };
85
+ }
86
+
56
87
  //#endregion
57
88
  //#region source/web/react/auth/context/ims-context.tsx
58
89
  const ImsContextValue = (0, react.createContext)(void 0);
@@ -60,14 +91,13 @@ const ImsContextValue = (0, react.createContext)(void 0);
60
91
  * Returns the IMS credentials provided by the host. Works inside the Commerce Admin and the
61
92
  * Experience Cloud shell.
62
93
  *
63
- * @throws If no host provides credentials (e.g. the app is running standalone, outside both the
64
- * Commerce Admin and the Experience Cloud shell).
94
+ * Returns an error when no host provides credentials.
65
95
  */
66
96
  function useIms() {
67
97
  const credentials = (0, react.use)(ImsContextValue);
68
- if (credentials === void 0) throw new Error("useIms must be used inside an ImsContextProvider.");
69
- if (!credentials) throw new Error("useIms requires running inside the Commerce Admin or the Experience Cloud shell, which provide the IMS credentials.");
70
- return credentials;
98
+ if (credentials === void 0) return error("useIms must be used inside an ImsContextProvider.");
99
+ if (!credentials) return error("useIms requires running inside the Commerce Admin or the Experience Cloud shell, which provide the IMS credentials.");
100
+ return ok(credentials);
71
101
  }
72
102
  /**
73
103
  * Provides the IMS credentials for a mounted Admin UI iframe app.
@@ -89,9 +119,7 @@ const SharedContextValue = (0, react.createContext)(void 0);
89
119
  * Returns the current Commerce shared context provider state.
90
120
  */
91
121
  function useInternalSharedContext() {
92
- const context = (0, react.use)(SharedContextValue);
93
- if (context === void 0) throw new Error("useSharedContext must be used inside a SharedContextProvider, which is only available in the Commerce Admin.");
94
- return context;
122
+ return (0, react.use)(SharedContextValue);
95
123
  }
96
124
  /**
97
125
  * Returns the current Commerce shared context. The guest connection is already established by
@@ -101,26 +129,29 @@ function useInternalSharedContext() {
101
129
  * Prefer a purpose-built hook ({@link useCommerce}, {@link useMassActionContext},
102
130
  * {@link useOrderViewButtonContext}) when one covers what you need.
103
131
  *
104
- * @throws If used outside a {@link SharedContextProvider}.
105
- *
106
132
  * @example
107
133
  * ```tsx
108
134
  * import { useSharedContext } from "@adobe/aio-commerce-lib-admin-ui/web";
109
135
  *
110
136
  * function ImsTokenLabel() {
111
- * const { sharedContext } = useSharedContext();
112
- * return <span>{sharedContext.get("imsToken")}</span>;
137
+ * const { data, error } = useSharedContext();
138
+ * if (error) return null;
139
+ * return <span>{data.sharedContext.get("imsToken")}</span>;
113
140
  * }
114
141
  * ```
115
142
  */
116
143
  function useSharedContext() {
117
- const { extensionId, guestConnection } = useInternalSharedContext();
118
- const sharedContext = useLiveSharedContext(guestConnection);
119
- return {
120
- extensionId,
121
- host: guestConnection.host,
122
- sharedContext
123
- };
144
+ const context = useInternalSharedContext();
145
+ const sharedContext = useLiveSharedContext(context?.guestConnection);
146
+ return (0, react.useMemo)(() => {
147
+ if (!context) return error("useSharedContext must be used inside a SharedContextProvider, which is only available in the Commerce Admin.");
148
+ if (!sharedContext) return error("The Commerce host did not provide a shared context for this extension.");
149
+ return ok({
150
+ extensionId: context.extensionId,
151
+ host: context.guestConnection.host,
152
+ sharedContext
153
+ });
154
+ }, [context, sharedContext]);
124
155
  }
125
156
  /**
126
157
  * Tracks the live UIX `sharedContext` for a connection.
@@ -132,7 +163,10 @@ function useSharedContext() {
132
163
  * @param guestConnection - The established guest connection.
133
164
  */
134
165
  function useLiveSharedContext(guestConnection) {
135
- return (0, react.useSyncExternalStore)((0, react.useCallback)((onContextChange) => guestConnection.addEventListener("contextchange", onContextChange), [guestConnection]), () => guestConnection.sharedContext);
166
+ return (0, react.useSyncExternalStore)((0, react.useCallback)((onContextChange) => {
167
+ if (!guestConnection) return () => void 0;
168
+ return guestConnection.addEventListener("contextchange", onContextChange);
169
+ }, [guestConnection]), () => guestConnection?.sharedContext ?? null);
136
170
  }
137
171
  /**
138
172
  * Provides the Commerce shared context for a mounted Admin UI iframe app.
@@ -154,28 +188,33 @@ function SharedContextProvider(props) {
154
188
  //#endregion
155
189
  //#region source/web/react/promise-cache.ts
156
190
  /**
157
- * Creates a keyed cache that memoizes in-flight, resolved, and rejected promises, giving `use()`
191
+ * Creates a keyed cache that memoizes in-flight, successful, and failed promises, giving `use()`
158
192
  * the reference-stable promise it needs while suspended and single-flighting side-effecting
159
193
  * establishment calls across re-renders, remounts, and StrictMode double-invocation.
160
194
  *
161
- * Rejections are retained (not evicted) so `use()` replays them to an error boundary instead of
162
- * suspending forever on a fresh pending promise. Retry a failed key via {@link RetryablePromiseCache.evict}.
195
+ * Promise rejections are failures by default. Pass `isFailure` when a fulfilled value, such as an
196
+ * error result, must also be retryable. Failed entries remain cached until `evictIfFailed` is
197
+ * called, so retries never replace a stable promise during render.
198
+ *
199
+ * @param isFailure - Determines whether a fulfilled value represents a failure.
163
200
  */
164
- function createRetryablePromiseCache() {
201
+ function createRetryablePromiseCache(isFailure = () => false) {
165
202
  const cache = /* @__PURE__ */ new Map();
166
203
  return {
167
- evictIfRejected(key) {
168
- if (cache.get(key)?.rejected) cache.delete(key);
204
+ evictIfFailed(key) {
205
+ if (cache.get(key)?.failed) cache.delete(key);
169
206
  },
170
207
  get(key, create) {
171
208
  const cached = cache.get(key);
172
209
  if (cached) return cached.promise;
173
210
  const entry = {
174
- promise: create(),
175
- rejected: false
211
+ failed: false,
212
+ promise: create()
176
213
  };
177
- entry.promise.catch(() => {
178
- entry.rejected = true;
214
+ entry.promise.then((value) => {
215
+ entry.failed = isFailure(value);
216
+ }).catch(() => {
217
+ entry.failed = true;
179
218
  });
180
219
  cache.set(key, entry);
181
220
  return entry.promise;
@@ -185,7 +224,7 @@ function createRetryablePromiseCache() {
185
224
 
186
225
  //#endregion
187
226
  //#region source/web/react/commerce/hooks/use-commerce.ts
188
- const commerceHosts = createRetryablePromiseCache();
227
+ const commerceHosts = createRetryablePromiseCache((result) => result.error !== null);
189
228
  /**
190
229
  * Returns the cached Commerce Admin host promise for an extension, resolving it once over the
191
230
  * given guest connection. The value is static for the lifetime of the connection.
@@ -194,24 +233,31 @@ const commerceHosts = createRetryablePromiseCache();
194
233
  * @param connection - The established guest connection.
195
234
  */
196
235
  function getCommerceHostPromise(extensionId, connection) {
197
- const { integration } = connection.host;
198
- if (!integration) throw new Error("The host does not provide the integration API needed to resolve the Commerce host.");
199
- return commerceHosts.get(extensionId, () => integration.getCommerceHost());
236
+ return commerceHosts.get(extensionId, async () => {
237
+ const { integration } = connection.host;
238
+ if (!integration) return error("The host does not provide the integration API needed to resolve the Commerce host.");
239
+ try {
240
+ return ok({ commerceHost: await integration.getCommerceHost() });
241
+ } catch (cause) {
242
+ return error("Failed to resolve the Commerce host.", { cause });
243
+ }
244
+ });
200
245
  }
201
246
  /** Drops a failed Commerce host resolution for `extensionId`, so a later render retries it. */
202
247
  function retryCommerceHost(extensionId) {
203
- commerceHosts.evictIfRejected(extensionId);
248
+ commerceHosts.evictIfFailed(extensionId);
204
249
  }
205
250
  /**
206
251
  * Returns the host (domain) of the Commerce Admin the extension is embedded in, resolving it over
207
252
  * the guest connection.
208
253
  *
209
- * @throws If used outside a Commerce Admin UI frame, or when the host does not expose the
210
- * Commerce integration API.
254
+ * Returns an error when used outside a Commerce Admin UI frame, when the host does not expose the
255
+ * Commerce integration API, or when resolving the host fails.
211
256
  */
212
257
  function useCommerce() {
213
- const { extensionId, guestConnection } = useInternalSharedContext();
214
- return { commerceHost: (0, react.use)(getCommerceHostPromise(extensionId, guestConnection)) };
258
+ const context = useInternalSharedContext();
259
+ if (!context) return error("useCommerce requires running inside the Commerce Admin.");
260
+ return (0, react.use)(getCommerceHostPromise(context.extensionId, context.guestConnection));
215
261
  }
216
262
 
217
263
  //#endregion
@@ -220,28 +266,31 @@ function useCommerce() {
220
266
  * Returns the context for a mass-action extension point: the selected row IDs the action was
221
267
  * triggered with. The value is read from the host-provided Commerce context.
222
268
  *
223
- * @throws If used outside the Commerce shared context, or when that context does not include a
224
- * mass-action selection.
269
+ * Returns an error outside the Commerce shared context, or when the mass-action selection is
270
+ * missing, empty, or contains a non-string row ID.
225
271
  */
226
272
  function useMassActionContext() {
227
- const { sharedContext } = useSharedContext();
273
+ const { data, error: contextError } = useSharedContext();
228
274
  return (0, react.useMemo)(() => {
229
- const selectedIds = sharedContext.get("selectedIds");
230
- if (!Array.isArray(selectedIds)) throw new Error("Could not find `selectedIds` in the Commerce shared context. Is this frame running as a mass-action extension point?");
231
- return { selectedIds };
232
- }, [sharedContext]);
275
+ if (contextError) return error(contextError.message, { cause: contextError });
276
+ const selectedIds = data.sharedContext.get("selectedIds");
277
+ if (!Array.isArray(selectedIds)) return error("Could not find `selectedIds` in the Commerce shared context. Is this frame running as a mass-action extension point?");
278
+ if (selectedIds.length === 0) return error("No rows selected. A mass-action extension point must be triggered with at least one selected row.");
279
+ if (selectedIds.some((id) => typeof id !== "string")) return error("Some of the `selectedIds` in the Commerce shared context are not strings. All selected row IDs must be strings.");
280
+ return ok({ selectedIds });
281
+ }, [data, contextError]);
233
282
  }
234
283
  /**
235
284
  * Returns the context for an order view-button extension point: the order ID the button was
236
285
  * triggered from.
237
286
  *
238
- * @throws If no order ID is present in the page URL.
287
+ * Returns an error when no order ID is present in the page URL.
239
288
  */
240
289
  function useOrderViewButtonContext() {
241
290
  return (0, react.useMemo)(() => {
242
291
  const orderId = parseOrderId(globalThis.location.href);
243
- if (orderId === null) throw new Error("Could not find an order ID. Is this frame running as an order view-button extension point?");
244
- return { orderId };
292
+ if (orderId === null) return error("Could not find an order ID. Is this frame running as an order view-button extension point?");
293
+ return ok({ orderId });
245
294
  }, []);
246
295
  }
247
296
 
@@ -250,51 +299,39 @@ function useOrderViewButtonContext() {
250
299
  /**
251
300
  * Returns typed helpers for interacting with the Commerce Admin host.
252
301
  *
253
- * @throws If called before the guest connection is established, or when the host frame actions
254
- * are unavailable.
255
- *
256
302
  * @example
257
303
  * ```tsx
258
304
  * import { useHostConnection } from "@adobe/aio-commerce-lib-admin-ui/web";
259
305
  *
260
306
  * function DoneButton() {
261
- * const { close } = useHostConnection();
262
- * return <button onClick={() => void close()}>Done</button>;
307
+ * const { actions, error } = useHostConnection();
308
+ * if (error) return null;
309
+ * return <button onClick={actions.close}>Done</button>;
263
310
  * }
264
311
  * ```
265
312
  */
266
313
  function useHostConnection() {
267
- const { host } = useSharedContext();
314
+ const { data, error: contextError } = useSharedContext();
268
315
  return (0, react.useMemo)(() => {
269
- const { field } = host;
270
- const requireField = () => {
271
- if (!field) throw new Error("Host frame actions are unavailable. They require an established guest connection with a host that exposes frame actions.");
272
- return field;
273
- };
274
- return {
275
- close: () => requireField().close(),
276
- closeWithError: () => requireField().onError()
277
- };
278
- }, [host]);
316
+ if (contextError) return actionsError(contextError.message, { cause: contextError });
317
+ const { field } = data.host;
318
+ if (!field) return actionsError("Host frame actions are unavailable. They require an established guest connection with a host that exposes frame actions.");
319
+ return okActions({
320
+ close: () => field.close(),
321
+ closeWithError: () => field.onError()
322
+ });
323
+ }, [data, contextError]);
279
324
  }
280
325
 
281
326
  //#endregion
282
327
  //#region source/web/react/routing/lib.ts
283
328
  const HASH_ROUTE_PREFIX_PATTERN = /^[#/]+/u;
284
329
  /**
285
- * Determines if a given route is an index route.
286
- * @param route The route to check.
287
- */
288
- function isIndexRoute(route) {
289
- return "index" in route && route.index;
290
- }
291
- /**
292
330
  * Returns the path for a given route, removing any leading hash or slash characters.
293
331
  * @param route The route to get the path for.
294
332
  */
295
333
  function getRoutePath(route) {
296
- if (isIndexRoute(route)) return "/";
297
- return route.path.replace(HASH_ROUTE_PREFIX_PATTERN, "");
334
+ return route.path.replace(HASH_ROUTE_PREFIX_PATTERN, "") || "/";
298
335
  }
299
336
  /**
300
337
  * Returns the "to" path for a given route, removing any leading hash or slash characters.
@@ -436,7 +473,7 @@ function useGuestConnection(extensionId) {
436
473
  }
437
474
  /** Drops a failed connection for `extensionId`, so a later render re-attaches. */
438
475
  function retryGuestConnection(extensionId) {
439
- guestConnections.evictIfRejected(extensionId);
476
+ guestConnections.evictIfFailed(extensionId);
440
477
  }
441
478
 
442
479
  //#endregion
@@ -627,9 +664,10 @@ function CommerceGuestConnection(props) {
627
664
  }
628
665
  /** Renders IMS-gated route content for a Commerce Admin UI frame. */
629
666
  function CommerceExtensionContent() {
630
- const { sharedContext } = useSharedContext();
667
+ const { data, error } = useSharedContext();
668
+ if (error) throw error;
631
669
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ImsContextProvider, {
632
- credentials: resolveCommerceImsCredentials(sharedContext),
670
+ credentials: resolveCommerceImsCredentials(data.sharedContext),
633
671
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_tanstack_react_router.Outlet, {})
634
672
  });
635
673
  }
@@ -785,11 +823,12 @@ function Entrypoint(props) {
785
823
  *
786
824
  * createExtensionApp({
787
825
  * metadata: { extensionId: "my-extension-id" },
788
- * routes: [{ index: true, element: <MainPage /> }],
826
+ * menu: <MainPage />,
789
827
  * });
790
828
  * ```
791
829
  */
792
- function createExtensionApp({ metadata, routes, root: customRoot }) {
830
+ function createExtensionApp({ menu, metadata, routes = [], root: customRoot }) {
831
+ if (menu !== void 0 && routes.some((route) => getRouteTo(route.path) === "/")) throw new Error("The \"/\" route is reserved for the menu. Pass its element through the menu option instead.");
793
832
  const rootElement = customRoot ?? document.getElementById("root");
794
833
  if (!rootElement) throw new Error("Could not find an element with id \"root\".");
795
834
  const root = (0, react_dom_client.createRoot)(rootElement);
@@ -798,7 +837,10 @@ function createExtensionApp({ metadata, routes, root: customRoot }) {
798
837
  extensionId: metadata.extensionId,
799
838
  initialConfigurationPromise,
800
839
  runtime
801
- }), routes);
840
+ }), menu === void 0 ? routes : [{
841
+ element: menu,
842
+ path: "/"
843
+ }, ...routes]);
802
844
  root.render(/* @__PURE__ */ (0, react_jsx_runtime.jsx)(react.StrictMode, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_tanstack_react_router.RouterProvider, { router }) }));
803
845
  };
804
846
  try {
@@ -23,15 +23,35 @@ type ImsContext = {
23
23
  imsOrgId: string;
24
24
  };
25
25
  //#endregion
26
+ //#region source/web/react/result.d.ts
27
+ /** The result of reading data that might not be available in the current host context. */
28
+ type Result<T, E = Error> = {
29
+ data: T;
30
+ error: null;
31
+ } | {
32
+ data: null;
33
+ error: E;
34
+ };
35
+ type ActionMap = {
36
+ [key: string]: (...args: unknown[]) => PromiseLike<unknown>;
37
+ };
38
+ /** The result of exposing an API that might not be available in the current host context. */
39
+ type ActionsResult<T extends ActionMap, E = Error> = {
40
+ actions: T;
41
+ error: null;
42
+ } | {
43
+ actions: null;
44
+ error: E;
45
+ };
46
+ //#endregion
26
47
  //#region source/web/react/auth/context/ims-context.d.ts
27
48
  /**
28
49
  * Returns the IMS credentials provided by the host. Works inside the Commerce Admin and the
29
50
  * Experience Cloud shell.
30
51
  *
31
- * @throws If no host provides credentials (e.g. the app is running standalone, outside both the
32
- * Commerce Admin and the Experience Cloud shell).
52
+ * Returns an error when no host provides credentials.
33
53
  */
34
- declare function useIms(): ImsContext;
54
+ declare function useIms(): Result<ImsContext>;
35
55
  //#endregion
36
56
  //#region source/web/react/commerce/types.d.ts
37
57
  /** The guest connection that shares the context between the extension and the Admin UI host. */
@@ -71,67 +91,66 @@ type OrderViewButtonContext = {
71
91
  * Prefer a purpose-built hook ({@link useCommerce}, {@link useMassActionContext},
72
92
  * {@link useOrderViewButtonContext}) when one covers what you need.
73
93
  *
74
- * @throws If used outside a {@link SharedContextProvider}.
75
- *
76
94
  * @example
77
95
  * ```tsx
78
96
  * import { useSharedContext } from "@adobe/aio-commerce-lib-admin-ui/web";
79
97
  *
80
98
  * function ImsTokenLabel() {
81
- * const { sharedContext } = useSharedContext();
82
- * return <span>{sharedContext.get("imsToken")}</span>;
99
+ * const { data, error } = useSharedContext();
100
+ * if (error) return null;
101
+ * return <span>{data.sharedContext.get("imsToken")}</span>;
83
102
  * }
84
103
  * ```
85
104
  */
86
- declare function useSharedContext(): SharedContext;
105
+ declare function useSharedContext(): Result<SharedContext>;
87
106
  //#endregion
88
107
  //#region source/web/react/commerce/hooks/use-commerce.d.ts
108
+ type CommerceData = {
109
+ commerceHost: string;
110
+ };
111
+ /** Drops a failed Commerce host resolution for `extensionId`, so a later render retries it. */
89
112
  /**
90
113
  * Returns the host (domain) of the Commerce Admin the extension is embedded in, resolving it over
91
114
  * the guest connection.
92
115
  *
93
- * @throws If used outside a Commerce Admin UI frame, or when the host does not expose the
94
- * Commerce integration API.
116
+ * Returns an error when used outside a Commerce Admin UI frame, when the host does not expose the
117
+ * Commerce integration API, or when resolving the host fails.
95
118
  */
96
- declare function useCommerce(): {
97
- commerceHost: string;
98
- };
119
+ declare function useCommerce(): Result<CommerceData>;
99
120
  //#endregion
100
121
  //#region source/web/react/commerce/hooks/use-extension-context.d.ts
101
122
  /**
102
123
  * Returns the context for a mass-action extension point: the selected row IDs the action was
103
124
  * triggered with. The value is read from the host-provided Commerce context.
104
125
  *
105
- * @throws If used outside the Commerce shared context, or when that context does not include a
106
- * mass-action selection.
126
+ * Returns an error outside the Commerce shared context, or when the mass-action selection is
127
+ * missing, empty, or contains a non-string row ID.
107
128
  */
108
- declare function useMassActionContext(): MassActionContext;
129
+ declare function useMassActionContext(): Result<MassActionContext>;
109
130
  /**
110
131
  * Returns the context for an order view-button extension point: the order ID the button was
111
132
  * triggered from.
112
133
  *
113
- * @throws If no order ID is present in the page URL.
134
+ * Returns an error when no order ID is present in the page URL.
114
135
  */
115
- declare function useOrderViewButtonContext(): OrderViewButtonContext;
136
+ declare function useOrderViewButtonContext(): Result<OrderViewButtonContext>;
116
137
  //#endregion
117
138
  //#region source/web/react/commerce/hooks/use-host-connection.d.ts
118
139
  /**
119
140
  * Returns typed helpers for interacting with the Commerce Admin host.
120
141
  *
121
- * @throws If called before the guest connection is established, or when the host frame actions
122
- * are unavailable.
123
- *
124
142
  * @example
125
143
  * ```tsx
126
144
  * import { useHostConnection } from "@adobe/aio-commerce-lib-admin-ui/web";
127
145
  *
128
146
  * function DoneButton() {
129
- * const { close } = useHostConnection();
130
- * return <button onClick={() => void close()}>Done</button>;
147
+ * const { actions, error } = useHostConnection();
148
+ * if (error) return null;
149
+ * return <button onClick={actions.close}>Done</button>;
131
150
  * }
132
151
  * ```
133
152
  */
134
- declare function useHostConnection(): HostConnection;
153
+ declare function useHostConnection(): ActionsResult<HostConnection>;
135
154
  //#endregion
136
155
  //#region source/web/react/routing/types.d.ts
137
156
  declare module "@react-spectrum/s2/Provider" {
@@ -140,27 +159,21 @@ declare module "@react-spectrum/s2/Provider" {
140
159
  routerOptions: Omit<NavigateOptions, keyof ToOptions>;
141
160
  }
142
161
  }
143
- /** Defines a route that is marked as the index (entrypoint) */
144
- type IndexRoute = {
145
- index: true; /** The React element to render for the index route. */
146
- element: ReactNode;
147
- };
148
162
  /** Defines a route that exists at a given path. */
149
163
  type ExtensionRoute = {
150
164
  /** The path for the route. */path: string; /** The React element to render for the route. */
151
165
  element: ReactNode;
152
166
  };
153
- /** Defines the routes for an extension app, which must include at least one index route (first item). */
154
- type ExtensionAppRoutes = [IndexRoute, ...ExtensionRoute[]];
155
167
  //#endregion
156
168
  //#region source/web/react/extension/create-app.d.ts
157
169
  /** Configuration options when instantiating an extension app. */
158
170
  type CreateExtensionAppOptions = {
159
171
  /** General metadata about the extension app. */metadata: {
160
172
  /** The unique identifier for the extension app. */extensionId: string;
161
- }; /** Optional root element where the app will be mounted. */
162
- root?: HTMLElement; /** A list of routes for the extension app, specifying an index route is mandatory. */
163
- routes: ExtensionAppRoutes;
173
+ }; /** The optional app page opened from the Commerce Admin menu and by default in Experience Cloud Shell. */
174
+ menu?: ReactNode; /** Optional root element where the app will be mounted. */
175
+ root?: HTMLElement; /** Additional path-based routes for the extension app. */
176
+ routes?: ExtensionRoute[];
164
177
  };
165
178
  /**
166
179
  * Mounts a Commerce Admin UI iframe app and handles Experience Cloud Shell, UIX
@@ -179,14 +192,15 @@ type CreateExtensionAppOptions = {
179
192
  *
180
193
  * createExtensionApp({
181
194
  * metadata: { extensionId: "my-extension-id" },
182
- * routes: [{ index: true, element: <MainPage /> }],
195
+ * menu: <MainPage />,
183
196
  * });
184
197
  * ```
185
198
  */
186
199
  declare function createExtensionApp({
200
+ menu,
187
201
  metadata,
188
202
  routes,
189
203
  root: customRoot
190
204
  }: CreateExtensionAppOptions): void;
191
205
  //#endregion
192
- export { type CreateExtensionAppOptions, type ExtensionAppRoutes, type ExtensionRoute, type HostConnection, type ImsContext, type IndexRoute, type MassActionContext, type OrderViewButtonContext, type SharedContext, createExtensionApp, useCommerce, useHostConnection, useIms, useMassActionContext, useOrderViewButtonContext, useSharedContext };
206
+ export { type CreateExtensionAppOptions, type ExtensionRoute, type HostConnection, type ImsContext, type MassActionContext, type OrderViewButtonContext, type SharedContext, createExtensionApp, useCommerce, useHostConnection, useIms, useMassActionContext, useOrderViewButtonContext, useSharedContext };
@@ -23,15 +23,35 @@ type ImsContext = {
23
23
  imsOrgId: string;
24
24
  };
25
25
  //#endregion
26
+ //#region source/web/react/result.d.ts
27
+ /** The result of reading data that might not be available in the current host context. */
28
+ type Result<T, E = Error> = {
29
+ data: T;
30
+ error: null;
31
+ } | {
32
+ data: null;
33
+ error: E;
34
+ };
35
+ type ActionMap = {
36
+ [key: string]: (...args: unknown[]) => PromiseLike<unknown>;
37
+ };
38
+ /** The result of exposing an API that might not be available in the current host context. */
39
+ type ActionsResult<T extends ActionMap, E = Error> = {
40
+ actions: T;
41
+ error: null;
42
+ } | {
43
+ actions: null;
44
+ error: E;
45
+ };
46
+ //#endregion
26
47
  //#region source/web/react/auth/context/ims-context.d.ts
27
48
  /**
28
49
  * Returns the IMS credentials provided by the host. Works inside the Commerce Admin and the
29
50
  * Experience Cloud shell.
30
51
  *
31
- * @throws If no host provides credentials (e.g. the app is running standalone, outside both the
32
- * Commerce Admin and the Experience Cloud shell).
52
+ * Returns an error when no host provides credentials.
33
53
  */
34
- declare function useIms(): ImsContext;
54
+ declare function useIms(): Result<ImsContext>;
35
55
  //#endregion
36
56
  //#region source/web/react/commerce/types.d.ts
37
57
  /** The guest connection that shares the context between the extension and the Admin UI host. */
@@ -71,67 +91,66 @@ type OrderViewButtonContext = {
71
91
  * Prefer a purpose-built hook ({@link useCommerce}, {@link useMassActionContext},
72
92
  * {@link useOrderViewButtonContext}) when one covers what you need.
73
93
  *
74
- * @throws If used outside a {@link SharedContextProvider}.
75
- *
76
94
  * @example
77
95
  * ```tsx
78
96
  * import { useSharedContext } from "@adobe/aio-commerce-lib-admin-ui/web";
79
97
  *
80
98
  * function ImsTokenLabel() {
81
- * const { sharedContext } = useSharedContext();
82
- * return <span>{sharedContext.get("imsToken")}</span>;
99
+ * const { data, error } = useSharedContext();
100
+ * if (error) return null;
101
+ * return <span>{data.sharedContext.get("imsToken")}</span>;
83
102
  * }
84
103
  * ```
85
104
  */
86
- declare function useSharedContext(): SharedContext;
105
+ declare function useSharedContext(): Result<SharedContext>;
87
106
  //#endregion
88
107
  //#region source/web/react/commerce/hooks/use-commerce.d.ts
108
+ type CommerceData = {
109
+ commerceHost: string;
110
+ };
111
+ /** Drops a failed Commerce host resolution for `extensionId`, so a later render retries it. */
89
112
  /**
90
113
  * Returns the host (domain) of the Commerce Admin the extension is embedded in, resolving it over
91
114
  * the guest connection.
92
115
  *
93
- * @throws If used outside a Commerce Admin UI frame, or when the host does not expose the
94
- * Commerce integration API.
116
+ * Returns an error when used outside a Commerce Admin UI frame, when the host does not expose the
117
+ * Commerce integration API, or when resolving the host fails.
95
118
  */
96
- declare function useCommerce(): {
97
- commerceHost: string;
98
- };
119
+ declare function useCommerce(): Result<CommerceData>;
99
120
  //#endregion
100
121
  //#region source/web/react/commerce/hooks/use-extension-context.d.ts
101
122
  /**
102
123
  * Returns the context for a mass-action extension point: the selected row IDs the action was
103
124
  * triggered with. The value is read from the host-provided Commerce context.
104
125
  *
105
- * @throws If used outside the Commerce shared context, or when that context does not include a
106
- * mass-action selection.
126
+ * Returns an error outside the Commerce shared context, or when the mass-action selection is
127
+ * missing, empty, or contains a non-string row ID.
107
128
  */
108
- declare function useMassActionContext(): MassActionContext;
129
+ declare function useMassActionContext(): Result<MassActionContext>;
109
130
  /**
110
131
  * Returns the context for an order view-button extension point: the order ID the button was
111
132
  * triggered from.
112
133
  *
113
- * @throws If no order ID is present in the page URL.
134
+ * Returns an error when no order ID is present in the page URL.
114
135
  */
115
- declare function useOrderViewButtonContext(): OrderViewButtonContext;
136
+ declare function useOrderViewButtonContext(): Result<OrderViewButtonContext>;
116
137
  //#endregion
117
138
  //#region source/web/react/commerce/hooks/use-host-connection.d.ts
118
139
  /**
119
140
  * Returns typed helpers for interacting with the Commerce Admin host.
120
141
  *
121
- * @throws If called before the guest connection is established, or when the host frame actions
122
- * are unavailable.
123
- *
124
142
  * @example
125
143
  * ```tsx
126
144
  * import { useHostConnection } from "@adobe/aio-commerce-lib-admin-ui/web";
127
145
  *
128
146
  * function DoneButton() {
129
- * const { close } = useHostConnection();
130
- * return <button onClick={() => void close()}>Done</button>;
147
+ * const { actions, error } = useHostConnection();
148
+ * if (error) return null;
149
+ * return <button onClick={actions.close}>Done</button>;
131
150
  * }
132
151
  * ```
133
152
  */
134
- declare function useHostConnection(): HostConnection;
153
+ declare function useHostConnection(): ActionsResult<HostConnection>;
135
154
  //#endregion
136
155
  //#region source/web/react/routing/types.d.ts
137
156
  declare module "@react-spectrum/s2/Provider" {
@@ -140,27 +159,21 @@ declare module "@react-spectrum/s2/Provider" {
140
159
  routerOptions: Omit<NavigateOptions, keyof ToOptions>;
141
160
  }
142
161
  }
143
- /** Defines a route that is marked as the index (entrypoint) */
144
- type IndexRoute = {
145
- index: true; /** The React element to render for the index route. */
146
- element: ReactNode;
147
- };
148
162
  /** Defines a route that exists at a given path. */
149
163
  type ExtensionRoute = {
150
164
  /** The path for the route. */path: string; /** The React element to render for the route. */
151
165
  element: ReactNode;
152
166
  };
153
- /** Defines the routes for an extension app, which must include at least one index route (first item). */
154
- type ExtensionAppRoutes = [IndexRoute, ...ExtensionRoute[]];
155
167
  //#endregion
156
168
  //#region source/web/react/extension/create-app.d.ts
157
169
  /** Configuration options when instantiating an extension app. */
158
170
  type CreateExtensionAppOptions = {
159
171
  /** General metadata about the extension app. */metadata: {
160
172
  /** The unique identifier for the extension app. */extensionId: string;
161
- }; /** Optional root element where the app will be mounted. */
162
- root?: HTMLElement; /** A list of routes for the extension app, specifying an index route is mandatory. */
163
- routes: ExtensionAppRoutes;
173
+ }; /** The optional app page opened from the Commerce Admin menu and by default in Experience Cloud Shell. */
174
+ menu?: ReactNode; /** Optional root element where the app will be mounted. */
175
+ root?: HTMLElement; /** Additional path-based routes for the extension app. */
176
+ routes?: ExtensionRoute[];
164
177
  };
165
178
  /**
166
179
  * Mounts a Commerce Admin UI iframe app and handles Experience Cloud Shell, UIX
@@ -179,14 +192,15 @@ type CreateExtensionAppOptions = {
179
192
  *
180
193
  * createExtensionApp({
181
194
  * metadata: { extensionId: "my-extension-id" },
182
- * routes: [{ index: true, element: <MainPage /> }],
195
+ * menu: <MainPage />,
183
196
  * });
184
197
  * ```
185
198
  */
186
199
  declare function createExtensionApp({
200
+ menu,
187
201
  metadata,
188
202
  routes,
189
203
  root: customRoot
190
204
  }: CreateExtensionAppOptions): void;
191
205
  //#endregion
192
- export { type CreateExtensionAppOptions, type ExtensionAppRoutes, type ExtensionRoute, type HostConnection, type ImsContext, type IndexRoute, type MassActionContext, type OrderViewButtonContext, type SharedContext, createExtensionApp, useCommerce, useHostConnection, useIms, useMassActionContext, useOrderViewButtonContext, useSharedContext };
206
+ export { type CreateExtensionAppOptions, type ExtensionRoute, type HostConnection, type ImsContext, type MassActionContext, type OrderViewButtonContext, type SharedContext, createExtensionApp, useCommerce, useHostConnection, useIms, useMassActionContext, useOrderViewButtonContext, useSharedContext };
@@ -48,6 +48,37 @@ function isControlFrame() {
48
48
  return isEmbeddedInHost() && !window.name;
49
49
  }
50
50
 
51
+ //#endregion
52
+ //#region source/web/react/result.ts
53
+ /** Creates a successful data result. */
54
+ function ok(data) {
55
+ return {
56
+ data,
57
+ error: null
58
+ };
59
+ }
60
+ /** Creates a failed data result. */
61
+ function error(message, options) {
62
+ return {
63
+ data: null,
64
+ error: new Error(message, options)
65
+ };
66
+ }
67
+ /** Creates a successful actions result. */
68
+ function okActions(actions) {
69
+ return {
70
+ actions,
71
+ error: null
72
+ };
73
+ }
74
+ /** Creates a failed actions result. */
75
+ function actionsError(message, options) {
76
+ return {
77
+ actions: null,
78
+ error: new Error(message, options)
79
+ };
80
+ }
81
+
51
82
  //#endregion
52
83
  //#region source/web/react/auth/context/ims-context.tsx
53
84
  const ImsContextValue = createContext(void 0);
@@ -55,14 +86,13 @@ const ImsContextValue = createContext(void 0);
55
86
  * Returns the IMS credentials provided by the host. Works inside the Commerce Admin and the
56
87
  * Experience Cloud shell.
57
88
  *
58
- * @throws If no host provides credentials (e.g. the app is running standalone, outside both the
59
- * Commerce Admin and the Experience Cloud shell).
89
+ * Returns an error when no host provides credentials.
60
90
  */
61
91
  function useIms() {
62
92
  const credentials = use(ImsContextValue);
63
- if (credentials === void 0) throw new Error("useIms must be used inside an ImsContextProvider.");
64
- if (!credentials) throw new Error("useIms requires running inside the Commerce Admin or the Experience Cloud shell, which provide the IMS credentials.");
65
- return credentials;
93
+ if (credentials === void 0) return error("useIms must be used inside an ImsContextProvider.");
94
+ if (!credentials) return error("useIms requires running inside the Commerce Admin or the Experience Cloud shell, which provide the IMS credentials.");
95
+ return ok(credentials);
66
96
  }
67
97
  /**
68
98
  * Provides the IMS credentials for a mounted Admin UI iframe app.
@@ -84,9 +114,7 @@ const SharedContextValue = createContext(void 0);
84
114
  * Returns the current Commerce shared context provider state.
85
115
  */
86
116
  function useInternalSharedContext() {
87
- const context = use(SharedContextValue);
88
- if (context === void 0) throw new Error("useSharedContext must be used inside a SharedContextProvider, which is only available in the Commerce Admin.");
89
- return context;
117
+ return use(SharedContextValue);
90
118
  }
91
119
  /**
92
120
  * Returns the current Commerce shared context. The guest connection is already established by
@@ -96,26 +124,29 @@ function useInternalSharedContext() {
96
124
  * Prefer a purpose-built hook ({@link useCommerce}, {@link useMassActionContext},
97
125
  * {@link useOrderViewButtonContext}) when one covers what you need.
98
126
  *
99
- * @throws If used outside a {@link SharedContextProvider}.
100
- *
101
127
  * @example
102
128
  * ```tsx
103
129
  * import { useSharedContext } from "@adobe/aio-commerce-lib-admin-ui/web";
104
130
  *
105
131
  * function ImsTokenLabel() {
106
- * const { sharedContext } = useSharedContext();
107
- * return <span>{sharedContext.get("imsToken")}</span>;
132
+ * const { data, error } = useSharedContext();
133
+ * if (error) return null;
134
+ * return <span>{data.sharedContext.get("imsToken")}</span>;
108
135
  * }
109
136
  * ```
110
137
  */
111
138
  function useSharedContext() {
112
- const { extensionId, guestConnection } = useInternalSharedContext();
113
- const sharedContext = useLiveSharedContext(guestConnection);
114
- return {
115
- extensionId,
116
- host: guestConnection.host,
117
- sharedContext
118
- };
139
+ const context = useInternalSharedContext();
140
+ const sharedContext = useLiveSharedContext(context?.guestConnection);
141
+ return useMemo(() => {
142
+ if (!context) return error("useSharedContext must be used inside a SharedContextProvider, which is only available in the Commerce Admin.");
143
+ if (!sharedContext) return error("The Commerce host did not provide a shared context for this extension.");
144
+ return ok({
145
+ extensionId: context.extensionId,
146
+ host: context.guestConnection.host,
147
+ sharedContext
148
+ });
149
+ }, [context, sharedContext]);
119
150
  }
120
151
  /**
121
152
  * Tracks the live UIX `sharedContext` for a connection.
@@ -127,7 +158,10 @@ function useSharedContext() {
127
158
  * @param guestConnection - The established guest connection.
128
159
  */
129
160
  function useLiveSharedContext(guestConnection) {
130
- return useSyncExternalStore(useCallback((onContextChange) => guestConnection.addEventListener("contextchange", onContextChange), [guestConnection]), () => guestConnection.sharedContext);
161
+ return useSyncExternalStore(useCallback((onContextChange) => {
162
+ if (!guestConnection) return () => void 0;
163
+ return guestConnection.addEventListener("contextchange", onContextChange);
164
+ }, [guestConnection]), () => guestConnection?.sharedContext ?? null);
131
165
  }
132
166
  /**
133
167
  * Provides the Commerce shared context for a mounted Admin UI iframe app.
@@ -149,28 +183,33 @@ function SharedContextProvider(props) {
149
183
  //#endregion
150
184
  //#region source/web/react/promise-cache.ts
151
185
  /**
152
- * Creates a keyed cache that memoizes in-flight, resolved, and rejected promises, giving `use()`
186
+ * Creates a keyed cache that memoizes in-flight, successful, and failed promises, giving `use()`
153
187
  * the reference-stable promise it needs while suspended and single-flighting side-effecting
154
188
  * establishment calls across re-renders, remounts, and StrictMode double-invocation.
155
189
  *
156
- * Rejections are retained (not evicted) so `use()` replays them to an error boundary instead of
157
- * suspending forever on a fresh pending promise. Retry a failed key via {@link RetryablePromiseCache.evict}.
190
+ * Promise rejections are failures by default. Pass `isFailure` when a fulfilled value, such as an
191
+ * error result, must also be retryable. Failed entries remain cached until `evictIfFailed` is
192
+ * called, so retries never replace a stable promise during render.
193
+ *
194
+ * @param isFailure - Determines whether a fulfilled value represents a failure.
158
195
  */
159
- function createRetryablePromiseCache() {
196
+ function createRetryablePromiseCache(isFailure = () => false) {
160
197
  const cache = /* @__PURE__ */ new Map();
161
198
  return {
162
- evictIfRejected(key) {
163
- if (cache.get(key)?.rejected) cache.delete(key);
199
+ evictIfFailed(key) {
200
+ if (cache.get(key)?.failed) cache.delete(key);
164
201
  },
165
202
  get(key, create) {
166
203
  const cached = cache.get(key);
167
204
  if (cached) return cached.promise;
168
205
  const entry = {
169
- promise: create(),
170
- rejected: false
206
+ failed: false,
207
+ promise: create()
171
208
  };
172
- entry.promise.catch(() => {
173
- entry.rejected = true;
209
+ entry.promise.then((value) => {
210
+ entry.failed = isFailure(value);
211
+ }).catch(() => {
212
+ entry.failed = true;
174
213
  });
175
214
  cache.set(key, entry);
176
215
  return entry.promise;
@@ -180,7 +219,7 @@ function createRetryablePromiseCache() {
180
219
 
181
220
  //#endregion
182
221
  //#region source/web/react/commerce/hooks/use-commerce.ts
183
- const commerceHosts = createRetryablePromiseCache();
222
+ const commerceHosts = createRetryablePromiseCache((result) => result.error !== null);
184
223
  /**
185
224
  * Returns the cached Commerce Admin host promise for an extension, resolving it once over the
186
225
  * given guest connection. The value is static for the lifetime of the connection.
@@ -189,24 +228,31 @@ const commerceHosts = createRetryablePromiseCache();
189
228
  * @param connection - The established guest connection.
190
229
  */
191
230
  function getCommerceHostPromise(extensionId, connection) {
192
- const { integration } = connection.host;
193
- if (!integration) throw new Error("The host does not provide the integration API needed to resolve the Commerce host.");
194
- return commerceHosts.get(extensionId, () => integration.getCommerceHost());
231
+ return commerceHosts.get(extensionId, async () => {
232
+ const { integration } = connection.host;
233
+ if (!integration) return error("The host does not provide the integration API needed to resolve the Commerce host.");
234
+ try {
235
+ return ok({ commerceHost: await integration.getCommerceHost() });
236
+ } catch (cause) {
237
+ return error("Failed to resolve the Commerce host.", { cause });
238
+ }
239
+ });
195
240
  }
196
241
  /** Drops a failed Commerce host resolution for `extensionId`, so a later render retries it. */
197
242
  function retryCommerceHost(extensionId) {
198
- commerceHosts.evictIfRejected(extensionId);
243
+ commerceHosts.evictIfFailed(extensionId);
199
244
  }
200
245
  /**
201
246
  * Returns the host (domain) of the Commerce Admin the extension is embedded in, resolving it over
202
247
  * the guest connection.
203
248
  *
204
- * @throws If used outside a Commerce Admin UI frame, or when the host does not expose the
205
- * Commerce integration API.
249
+ * Returns an error when used outside a Commerce Admin UI frame, when the host does not expose the
250
+ * Commerce integration API, or when resolving the host fails.
206
251
  */
207
252
  function useCommerce() {
208
- const { extensionId, guestConnection } = useInternalSharedContext();
209
- return { commerceHost: use(getCommerceHostPromise(extensionId, guestConnection)) };
253
+ const context = useInternalSharedContext();
254
+ if (!context) return error("useCommerce requires running inside the Commerce Admin.");
255
+ return use(getCommerceHostPromise(context.extensionId, context.guestConnection));
210
256
  }
211
257
 
212
258
  //#endregion
@@ -215,28 +261,31 @@ function useCommerce() {
215
261
  * Returns the context for a mass-action extension point: the selected row IDs the action was
216
262
  * triggered with. The value is read from the host-provided Commerce context.
217
263
  *
218
- * @throws If used outside the Commerce shared context, or when that context does not include a
219
- * mass-action selection.
264
+ * Returns an error outside the Commerce shared context, or when the mass-action selection is
265
+ * missing, empty, or contains a non-string row ID.
220
266
  */
221
267
  function useMassActionContext() {
222
- const { sharedContext } = useSharedContext();
268
+ const { data, error: contextError } = useSharedContext();
223
269
  return useMemo(() => {
224
- const selectedIds = sharedContext.get("selectedIds");
225
- if (!Array.isArray(selectedIds)) throw new Error("Could not find `selectedIds` in the Commerce shared context. Is this frame running as a mass-action extension point?");
226
- return { selectedIds };
227
- }, [sharedContext]);
270
+ if (contextError) return error(contextError.message, { cause: contextError });
271
+ const selectedIds = data.sharedContext.get("selectedIds");
272
+ if (!Array.isArray(selectedIds)) return error("Could not find `selectedIds` in the Commerce shared context. Is this frame running as a mass-action extension point?");
273
+ if (selectedIds.length === 0) return error("No rows selected. A mass-action extension point must be triggered with at least one selected row.");
274
+ if (selectedIds.some((id) => typeof id !== "string")) return error("Some of the `selectedIds` in the Commerce shared context are not strings. All selected row IDs must be strings.");
275
+ return ok({ selectedIds });
276
+ }, [data, contextError]);
228
277
  }
229
278
  /**
230
279
  * Returns the context for an order view-button extension point: the order ID the button was
231
280
  * triggered from.
232
281
  *
233
- * @throws If no order ID is present in the page URL.
282
+ * Returns an error when no order ID is present in the page URL.
234
283
  */
235
284
  function useOrderViewButtonContext() {
236
285
  return useMemo(() => {
237
286
  const orderId = parseOrderId(globalThis.location.href);
238
- if (orderId === null) throw new Error("Could not find an order ID. Is this frame running as an order view-button extension point?");
239
- return { orderId };
287
+ if (orderId === null) return error("Could not find an order ID. Is this frame running as an order view-button extension point?");
288
+ return ok({ orderId });
240
289
  }, []);
241
290
  }
242
291
 
@@ -245,51 +294,39 @@ function useOrderViewButtonContext() {
245
294
  /**
246
295
  * Returns typed helpers for interacting with the Commerce Admin host.
247
296
  *
248
- * @throws If called before the guest connection is established, or when the host frame actions
249
- * are unavailable.
250
- *
251
297
  * @example
252
298
  * ```tsx
253
299
  * import { useHostConnection } from "@adobe/aio-commerce-lib-admin-ui/web";
254
300
  *
255
301
  * function DoneButton() {
256
- * const { close } = useHostConnection();
257
- * return <button onClick={() => void close()}>Done</button>;
302
+ * const { actions, error } = useHostConnection();
303
+ * if (error) return null;
304
+ * return <button onClick={actions.close}>Done</button>;
258
305
  * }
259
306
  * ```
260
307
  */
261
308
  function useHostConnection() {
262
- const { host } = useSharedContext();
309
+ const { data, error: contextError } = useSharedContext();
263
310
  return useMemo(() => {
264
- const { field } = host;
265
- const requireField = () => {
266
- if (!field) throw new Error("Host frame actions are unavailable. They require an established guest connection with a host that exposes frame actions.");
267
- return field;
268
- };
269
- return {
270
- close: () => requireField().close(),
271
- closeWithError: () => requireField().onError()
272
- };
273
- }, [host]);
311
+ if (contextError) return actionsError(contextError.message, { cause: contextError });
312
+ const { field } = data.host;
313
+ if (!field) return actionsError("Host frame actions are unavailable. They require an established guest connection with a host that exposes frame actions.");
314
+ return okActions({
315
+ close: () => field.close(),
316
+ closeWithError: () => field.onError()
317
+ });
318
+ }, [data, contextError]);
274
319
  }
275
320
 
276
321
  //#endregion
277
322
  //#region source/web/react/routing/lib.ts
278
323
  const HASH_ROUTE_PREFIX_PATTERN = /^[#/]+/u;
279
324
  /**
280
- * Determines if a given route is an index route.
281
- * @param route The route to check.
282
- */
283
- function isIndexRoute(route) {
284
- return "index" in route && route.index;
285
- }
286
- /**
287
325
  * Returns the path for a given route, removing any leading hash or slash characters.
288
326
  * @param route The route to get the path for.
289
327
  */
290
328
  function getRoutePath(route) {
291
- if (isIndexRoute(route)) return "/";
292
- return route.path.replace(HASH_ROUTE_PREFIX_PATTERN, "");
329
+ return route.path.replace(HASH_ROUTE_PREFIX_PATTERN, "") || "/";
293
330
  }
294
331
  /**
295
332
  * Returns the "to" path for a given route, removing any leading hash or slash characters.
@@ -431,7 +468,7 @@ function useGuestConnection(extensionId) {
431
468
  }
432
469
  /** Drops a failed connection for `extensionId`, so a later render re-attaches. */
433
470
  function retryGuestConnection(extensionId) {
434
- guestConnections.evictIfRejected(extensionId);
471
+ guestConnections.evictIfFailed(extensionId);
435
472
  }
436
473
 
437
474
  //#endregion
@@ -622,9 +659,10 @@ function CommerceGuestConnection(props) {
622
659
  }
623
660
  /** Renders IMS-gated route content for a Commerce Admin UI frame. */
624
661
  function CommerceExtensionContent() {
625
- const { sharedContext } = useSharedContext();
662
+ const { data, error } = useSharedContext();
663
+ if (error) throw error;
626
664
  return /* @__PURE__ */ jsx(ImsContextProvider, {
627
- credentials: resolveCommerceImsCredentials(sharedContext),
665
+ credentials: resolveCommerceImsCredentials(data.sharedContext),
628
666
  children: /* @__PURE__ */ jsx(Outlet, {})
629
667
  });
630
668
  }
@@ -780,11 +818,12 @@ function Entrypoint(props) {
780
818
  *
781
819
  * createExtensionApp({
782
820
  * metadata: { extensionId: "my-extension-id" },
783
- * routes: [{ index: true, element: <MainPage /> }],
821
+ * menu: <MainPage />,
784
822
  * });
785
823
  * ```
786
824
  */
787
- function createExtensionApp({ metadata, routes, root: customRoot }) {
825
+ function createExtensionApp({ menu, metadata, routes = [], root: customRoot }) {
826
+ if (menu !== void 0 && routes.some((route) => getRouteTo(route.path) === "/")) throw new Error("The \"/\" route is reserved for the menu. Pass its element through the menu option instead.");
788
827
  const rootElement = customRoot ?? document.getElementById("root");
789
828
  if (!rootElement) throw new Error("Could not find an element with id \"root\".");
790
829
  const root = createRoot(rootElement);
@@ -793,7 +832,10 @@ function createExtensionApp({ metadata, routes, root: customRoot }) {
793
832
  extensionId: metadata.extensionId,
794
833
  initialConfigurationPromise,
795
834
  runtime
796
- }), routes);
835
+ }), menu === void 0 ? routes : [{
836
+ element: menu,
837
+ path: "/"
838
+ }, ...routes]);
797
839
  root.render(/* @__PURE__ */ jsx(StrictMode, { children: /* @__PURE__ */ jsx(RouterProvider, { router }) }));
798
840
  };
799
841
  try {
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@adobe/aio-commerce-lib-admin-ui",
3
3
  "type": "module",
4
4
  "author": "Adobe Inc.",
5
- "version": "0.2.0-beta-20260714082406",
5
+ "version": "0.2.0-beta-20260721105643",
6
6
  "private": false,
7
7
  "engines": {
8
8
  "node": ">=22 <=24"
@@ -113,8 +113,8 @@
113
113
  "ky": "^1.9.0",
114
114
  "react-error-boundary": "^6.1.2",
115
115
  "valibot": "^1.1.0",
116
- "@adobe/aio-commerce-lib-api": "1.3.0-beta-20260714082406",
117
- "@adobe/aio-commerce-lib-core": "1.2.0-beta-20260714082406"
116
+ "@adobe/aio-commerce-lib-api": "1.3.0-beta-20260721105643",
117
+ "@adobe/aio-commerce-lib-core": "1.2.0-beta-20260721105643"
118
118
  },
119
119
  "peerDependencies": {
120
120
  "@react-spectrum/s2": "^1.5.1",
@@ -139,12 +139,12 @@
139
139
  "react": "^19.2.7",
140
140
  "react-dom": "^19.2.7",
141
141
  "typescript": "^6.0.0",
142
- "@aio-commerce-sdk/common-utils": "0.2.6-beta-20260714082406",
142
+ "@aio-commerce-sdk/common-utils": "0.2.6-beta-20260721105643",
143
143
  "@aio-commerce-sdk/config-tsdown": "1.0.1",
144
144
  "@aio-commerce-sdk/config-typedoc": "1.0.0",
145
145
  "@aio-commerce-sdk/config-typescript": "1.0.0",
146
146
  "@aio-commerce-sdk/config-vitest": "1.0.0",
147
- "@aio-commerce-sdk/scripting-utils": "0.3.4-beta-20260714082406",
147
+ "@aio-commerce-sdk/scripting-utils": "0.3.4-beta-20260721105643",
148
148
  "@aio-commerce-sdk/scripts": "0.1.0"
149
149
  },
150
150
  "sideEffects": false,