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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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 };
@@ -42,47 +42,6 @@ import { ErrorResponse, SuccessResponse } from "@adobe/aio-commerce-lib-core/res
42
42
  */
43
43
  declare function getMassActionAclResourceId(metadataId: string, entity: AdminUiEntity, actionId: string): string;
44
44
  //#endregion
45
- //#region source/mass-actions/view/schema.d.ts
46
- /**
47
- * Schema for the `selection` query parameter Commerce appends to the iframe URL
48
- * of a view mass action.
49
- *
50
- * Commerce serializes the selection as a JSON-encoded string:
51
- * `?selection={"ids":["000000001"],"gridType":"customer"}`
52
- */
53
- declare const MassActionSelectionSchema: v.ObjectSchema<{
54
- readonly gridType: v.PicklistSchema<["order", "product", "customer"], undefined>;
55
- readonly ids: v.SchemaWithPipe<readonly [v.ArraySchema<v.SchemaWithPipe<readonly [v.StringSchema<`Expected a string value for '${string}'`>, v.NonEmptyAction<string, `The value of "${string}" must not be empty`>]>, undefined>, v.MinLengthAction<string[], 1, "The value of \"ids\" must contain at least one entry">]>;
56
- }, undefined>;
57
- //#endregion
58
- //#region source/mass-actions/view/types.d.ts
59
- /** Parsed `selection` query parameter appended by Commerce to the iframe URL. */
60
- type MassActionSelection = v.InferOutput<typeof MassActionSelectionSchema>;
61
- //#endregion
62
- //#region source/mass-actions/view/presets.d.ts
63
- /**
64
- * Parses the `selection` query parameter Commerce appends to the iframe URL of
65
- * a view mass action.
66
- *
67
- * Commerce serializes the selection as a JSON string:
68
- * `?selection={"ids":["000000001","000000002"],"gridType":"customer"}`
69
- *
70
- * Throws a `CommerceSdkValidationError` if the input is missing, not valid
71
- * JSON, or does not match the expected shape.
72
- *
73
- * @param rawSelection - The raw string value of the `selection` query parameter.
74
- *
75
- * @example
76
- * ```ts
77
- * import { parseMassActionSelection } from "@adobe/aio-commerce-lib-admin-ui/mass-actions";
78
- *
79
- * // In your SPA route handler:
80
- * const raw = new URLSearchParams(window.location.search).get("selection");
81
- * const { ids, gridType } = parseMassActionSelection(raw);
82
- * ```
83
- */
84
- declare function parseMassActionSelection(rawSelection: unknown): MassActionSelection;
85
- //#endregion
86
45
  //#region source/mass-actions/worker/schema.d.ts
87
46
  /**
88
47
  * Grid identifier sent by Commerce on the `commerce/backend-ui/2` wire contract
@@ -157,4 +116,4 @@ declare function okMassActionResponse(body?: MassActionResponseBody): SuccessRes
157
116
  */
158
117
  declare function massActionErrorResponse(statusCode: number, errorMessage: string): ErrorResponse<MassActionErrorBody>;
159
118
  //#endregion
160
- export { type AdminUiEntity, type MassActionErrorBody, type MassActionGridType, MassActionGridTypeSchema, type MassActionRequest, MassActionRequestSchema, type MassActionResponseBody, type MassActionSelection, MassActionSelectionSchema, getMassActionAclResourceId, massActionErrorResponse, okMassActionResponse, parseMassActionRequest, parseMassActionSelection };
119
+ export { type AdminUiEntity, type MassActionErrorBody, type MassActionGridType, MassActionGridTypeSchema, type MassActionRequest, MassActionRequestSchema, type MassActionResponseBody, getMassActionAclResourceId, massActionErrorResponse, okMassActionResponse, parseMassActionRequest };
@@ -48,58 +48,6 @@ function getMassActionAclResourceId(metadataId, entity, actionId) {
48
48
  return `${appRoot}_${entity}_massactions_${sanitizeSegment(actionId)}`;
49
49
  }
50
50
 
51
- //#endregion
52
- //#region source/mass-actions/view/schema.ts
53
- /**
54
- * Schema for the `selection` query parameter Commerce appends to the iframe URL
55
- * of a view mass action.
56
- *
57
- * Commerce serializes the selection as a JSON-encoded string:
58
- * `?selection={"ids":["000000001"],"gridType":"customer"}`
59
- */
60
- const MassActionSelectionSchema = v.object({
61
- gridType: v.picklist([
62
- "order",
63
- "product",
64
- "customer"
65
- ]),
66
- ids: v.pipe(v.array(nonEmptyStringValueSchema("id")), v.minLength(1, "The value of \"ids\" must contain at least one entry"))
67
- });
68
-
69
- //#endregion
70
- //#region source/mass-actions/view/presets.ts
71
- /**
72
- * Parses the `selection` query parameter Commerce appends to the iframe URL of
73
- * a view mass action.
74
- *
75
- * Commerce serializes the selection as a JSON string:
76
- * `?selection={"ids":["000000001","000000002"],"gridType":"customer"}`
77
- *
78
- * Throws a `CommerceSdkValidationError` if the input is missing, not valid
79
- * JSON, or does not match the expected shape.
80
- *
81
- * @param rawSelection - The raw string value of the `selection` query parameter.
82
- *
83
- * @example
84
- * ```ts
85
- * import { parseMassActionSelection } from "@adobe/aio-commerce-lib-admin-ui/mass-actions";
86
- *
87
- * // In your SPA route handler:
88
- * const raw = new URLSearchParams(window.location.search).get("selection");
89
- * const { ids, gridType } = parseMassActionSelection(raw);
90
- * ```
91
- */
92
- function parseMassActionSelection(rawSelection) {
93
- if (rawSelection === null || rawSelection === void 0) throw new Error("Invalid mass action selection: the selection query parameter is missing.");
94
- let parsed;
95
- try {
96
- parsed = JSON.parse(String(rawSelection));
97
- } catch (error) {
98
- throw new Error(`Invalid mass action selection: expected a JSON string, got: ${String(rawSelection)}`, { cause: error });
99
- }
100
- return parseOrThrow(MassActionSelectionSchema, parsed, "Invalid mass action selection");
101
- }
102
-
103
51
  //#endregion
104
52
  //#region source/mass-actions/worker/schema.ts
105
53
  /**
@@ -175,4 +123,4 @@ function massActionErrorResponse(statusCode, errorMessage) {
175
123
  }
176
124
 
177
125
  //#endregion
178
- export { MassActionGridTypeSchema, MassActionRequestSchema, MassActionSelectionSchema, getMassActionAclResourceId, massActionErrorResponse, okMassActionResponse, parseMassActionRequest, parseMassActionSelection };
126
+ export { MassActionGridTypeSchema, MassActionRequestSchema, getMassActionAclResourceId, massActionErrorResponse, okMassActionResponse, parseMassActionRequest };
@@ -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 };