@adobe/aio-commerce-lib-admin-ui 0.1.0 → 0.2.0-alpha-20260722091448

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 (40) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/README.md +1 -1
  3. package/dist/cjs/acl-resource-id-DBlYU0DE.d.cts +39 -0
  4. package/dist/cjs/acl-resource-id-D_hCU1Qg.cjs +69 -0
  5. package/dist/cjs/api/index.cjs +252 -0
  6. package/dist/cjs/api/index.d.cts +126 -0
  7. package/dist/cjs/grid-columns/index.cjs +151 -0
  8. package/dist/cjs/grid-columns/index.d.cts +146 -0
  9. package/dist/cjs/mass-actions/index.cjs +188 -0
  10. package/dist/cjs/mass-actions/index.d.cts +160 -0
  11. package/dist/cjs/menu/index.cjs +91 -0
  12. package/dist/cjs/menu/index.d.cts +63 -0
  13. package/dist/cjs/order-view-buttons/index.cjs +126 -0
  14. package/dist/cjs/order-view-buttons/index.d.cts +113 -0
  15. package/dist/cjs/rolldown-runtime-Cx6hovH8.cjs +67 -0
  16. package/dist/cjs/schemas-Ce10uBzN.cjs +41 -0
  17. package/dist/cjs/utils-B59fjd_w.cjs +39 -0
  18. package/dist/cjs/web/index.cjs +872 -0
  19. package/dist/cjs/web/index.d.cts +206 -0
  20. package/dist/es/acl-resource-id-DBlYU0DE.d.mts +39 -0
  21. package/dist/es/acl-resource-id-pryVxI_c.mjs +57 -0
  22. package/dist/es/api/index.d.mts +126 -0
  23. package/dist/es/api/index.mjs +262 -0
  24. package/dist/es/grid-columns/index.d.mts +146 -0
  25. package/dist/es/grid-columns/index.mjs +143 -0
  26. package/dist/es/mass-actions/index.d.mts +160 -0
  27. package/dist/es/mass-actions/index.mjs +178 -0
  28. package/dist/es/menu/index.d.mts +63 -0
  29. package/dist/es/menu/index.mjs +80 -0
  30. package/dist/es/order-view-buttons/index.d.mts +113 -0
  31. package/dist/es/order-view-buttons/index.mjs +119 -0
  32. package/dist/es/schemas-BFT8ys8P.mjs +34 -0
  33. package/dist/es/utils-COPGW1HO.mjs +32 -0
  34. package/dist/es/web/index.d.mts +206 -0
  35. package/dist/es/web/index.mjs +861 -0
  36. package/package.json +87 -10
  37. package/dist/cjs/index.cjs +0 -139
  38. package/dist/cjs/index.d.cts +0 -56
  39. package/dist/es/index.d.mts +0 -56
  40. package/dist/es/index.mjs +0 -114
@@ -0,0 +1,119 @@
1
+ /**
2
+ * @license
3
+ *
4
+ * Copyright 2026 Adobe. All rights reserved.
5
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License. You may obtain a copy
7
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software distributed under
10
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
11
+ * OF ANY KIND, either express or implied. See the License for the specific language
12
+ * governing permissions and limitations under the License.
13
+ */
14
+
15
+ import { n as sanitizeSegment, t as getAclResourceId } from "../acl-resource-id-pryVxI_c.mjs";
16
+ import { t as nonEmptyStringValueSchema } from "../schemas-BFT8ys8P.mjs";
17
+ import { t as parseOrThrow } from "../utils-COPGW1HO.mjs";
18
+ import * as v from "valibot";
19
+ import { buildErrorResponse, ok } from "@adobe/aio-commerce-lib-core/responses";
20
+
21
+ //#region source/order-view-buttons/acl-resource-id.ts
22
+ /**
23
+ * Derives the deterministic Commerce ACL resource id for an order view button.
24
+ *
25
+ * View buttons exist only on the order entity, so no entity discriminator is needed.
26
+ * The id is assembled as: `getAclResourceId(metadataId)` + `"_order_viewbuttons_"` +
27
+ * sanitized `buttonId`. The `buttonId` is sanitized (trimmed, lowercased, non-`[a-z0-9_]` → `_`).
28
+ * `"Magento_CommerceBackendUix::adminuisdk_app_"` in the example is the fixed constant prefix
29
+ * (not a placeholder), and `"_order_viewbuttons_"` is the literal keyword separator for this component:
30
+ *
31
+ * @example
32
+ * ```
33
+ * getOrderViewButtonAclResourceId("approval-dashboard-app", "approve-order")
34
+ * // getAclResourceId("approval-dashboard-app") + "_order_viewbuttons_" + sanitize("approve-order")
35
+ * // "Magento_CommerceBackendUix::adminuisdk_app_approval_dashboard_app" + "_order_viewbuttons_" + "approve_order"
36
+ * // → "Magento_CommerceBackendUix::adminuisdk_app_approval_dashboard_app_order_viewbuttons_approve_order"
37
+ * ```
38
+ *
39
+ * @param metadataId - The application's `metadata.id` value (e.g. `"approval-dashboard-app"`).
40
+ * @param buttonId - The button's `id` value from `adminUi.order.viewButtons[].id`.
41
+ * @returns The full Commerce ACL resource id for the view-button leaf node, or an empty string
42
+ * when `metadataId` is blank.
43
+ */
44
+ function getOrderViewButtonAclResourceId(metadataId, buttonId) {
45
+ const appRoot = getAclResourceId(metadataId);
46
+ if (appRoot === "") return "";
47
+ return `${appRoot}_order_viewbuttons_${sanitizeSegment(buttonId)}`;
48
+ }
49
+
50
+ //#endregion
51
+ //#region source/order-view-buttons/schema.ts
52
+ /**
53
+ * Schema for the JSON body Commerce POSTs to an order view button handler.
54
+ *
55
+ * `id` identifies the specific button that was clicked, letting a single
56
+ * handler serve multiple buttons by branching on it. `orderId` is the
57
+ * single order currently being viewed.
58
+ */
59
+ const OrderViewButtonRequestSchema = v.object({
60
+ id: nonEmptyStringValueSchema("id"),
61
+ orderId: nonEmptyStringValueSchema("orderId"),
62
+ requestId: nonEmptyStringValueSchema("requestId")
63
+ });
64
+
65
+ //#endregion
66
+ //#region source/order-view-buttons/presets.ts
67
+ /**
68
+ * Parses and validates the JSON body Commerce POSTs to an order view button handler.
69
+ *
70
+ * Throws a `CommerceSdkValidationError` if the input is malformed.
71
+ *
72
+ * @example
73
+ * ```ts
74
+ * import { parseOrderViewButtonRequest } from "@adobe/aio-commerce-lib-admin-ui/order-view-buttons";
75
+ *
76
+ * export async function main(params: unknown) {
77
+ * const { requestId, id, orderId } = parseOrderViewButtonRequest(params);
78
+ * // id identifies which button was clicked
79
+ * // orderId is the order currently being viewed
80
+ * // ...
81
+ * }
82
+ * ```
83
+ */
84
+ function parseOrderViewButtonRequest(input) {
85
+ return parseOrThrow(OrderViewButtonRequestSchema, input, "Invalid order view button request");
86
+ }
87
+ /**
88
+ * Builds an HTTP 200 success response for an order view button handler.
89
+ *
90
+ * Commerce renders `notifications.success` from the registration as the
91
+ * toast body when present, and a default success toast otherwise.
92
+ *
93
+ * @example
94
+ * ```ts
95
+ * return okOrderViewButtonResponse();
96
+ * ```
97
+ */
98
+ function okOrderViewButtonResponse() {
99
+ return ok({ body: {} });
100
+ }
101
+ /**
102
+ * Builds an error response for a worker order view button handler with the given HTTP status code.
103
+ *
104
+ * Commerce uses the HTTP status code to distinguish success from failure.
105
+ *
106
+ * @param statusCode - The HTTP status code to return.
107
+ * @param errorMessage - Error message included in the response body as `{ message }`.
108
+ *
109
+ * @example
110
+ * ```ts
111
+ * return orderViewButtonErrorResponse(500, "Could not reach inventory service");
112
+ * ```
113
+ */
114
+ function orderViewButtonErrorResponse(statusCode, errorMessage) {
115
+ return buildErrorResponse(statusCode, { body: { message: errorMessage } });
116
+ }
117
+
118
+ //#endregion
119
+ export { OrderViewButtonRequestSchema, getOrderViewButtonAclResourceId, okOrderViewButtonResponse, orderViewButtonErrorResponse, parseOrderViewButtonRequest };
@@ -0,0 +1,34 @@
1
+ /**
2
+ * @license
3
+ *
4
+ * Copyright 2026 Adobe. All rights reserved.
5
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License. You may obtain a copy
7
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software distributed under
10
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
11
+ * OF ANY KIND, either express or implied. See the License for the specific language
12
+ * governing permissions and limitations under the License.
13
+ */
14
+
15
+ import * as v from "valibot";
16
+
17
+ //#region ../../packages-private/common-utils/source/valibot/schemas.ts
18
+ /**
19
+ * A schema for a string value.
20
+ * @param name The name of the field this schema refers to.
21
+ */
22
+ function stringValueSchema(name) {
23
+ return v.string(`Expected a string value for '${name}'`);
24
+ }
25
+ /**
26
+ * A schema for a non-empty string value.
27
+ * @param name The name of the field this schema refers to.
28
+ */
29
+ function nonEmptyStringValueSchema(name) {
30
+ return v.pipe(stringValueSchema(name), v.nonEmpty(`The value of "${name}" must not be empty`));
31
+ }
32
+
33
+ //#endregion
34
+ export { nonEmptyStringValueSchema as t };
@@ -0,0 +1,32 @@
1
+ /**
2
+ * @license
3
+ *
4
+ * Copyright 2026 Adobe. All rights reserved.
5
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License. You may obtain a copy
7
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software distributed under
10
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
11
+ * OF ANY KIND, either express or implied. See the License for the specific language
12
+ * governing permissions and limitations under the License.
13
+ */
14
+
15
+ import { CommerceSdkValidationError } from "@adobe/aio-commerce-lib-core/error";
16
+ import * as v from "valibot";
17
+
18
+ //#region ../../packages-private/common-utils/source/valibot/utils.ts
19
+ /**
20
+ * Parses the input using the provided schema and throws a {@link CommerceSdkValidationError} error if the input is invalid.
21
+ * @param schema - The schema to use for parsing.
22
+ * @param input - The input to parse.
23
+ * @param message - Optional custom error message for the validation error.
24
+ */
25
+ function parseOrThrow(schema, input, message) {
26
+ const result = v.safeParse(schema, input);
27
+ if (!result.success) throw new CommerceSdkValidationError(message ?? "Invalid input", { issues: result.issues });
28
+ return result.output;
29
+ }
30
+
31
+ //#endregion
32
+ export { parseOrThrow as t };
@@ -0,0 +1,206 @@
1
+ /**
2
+ * @license
3
+ *
4
+ * Copyright 2026 Adobe. All rights reserved.
5
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License. You may obtain a copy
7
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software distributed under
10
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
11
+ * OF ANY KIND, either express or implied. See the License for the specific language
12
+ * governing permissions and limitations under the License.
13
+ */
14
+
15
+ import { ReactNode } from "react";
16
+ import { NavigateOptions, ToOptions } from "@tanstack/react-router";
17
+ import { attach } from "@adobe/uix-guest";
18
+
19
+ //#region source/web/react/auth/types.d.ts
20
+ /** The IMS credentials provided by the host (Commerce Admin or Experience Cloud shell). */
21
+ type ImsContext = {
22
+ imsToken: string;
23
+ imsOrgId: string;
24
+ };
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
47
+ //#region source/web/react/auth/context/ims-context.d.ts
48
+ /**
49
+ * Returns the IMS credentials provided by the host. Works inside the Commerce Admin and the
50
+ * Experience Cloud shell.
51
+ *
52
+ * Returns an error when no host provides credentials.
53
+ */
54
+ declare function useIms(): Result<ImsContext>;
55
+ //#endregion
56
+ //#region source/web/react/commerce/types.d.ts
57
+ /** The guest connection that shares the context between the extension and the Admin UI host. */
58
+ type GuestConnection = Awaited<ReturnType<typeof attach>>;
59
+ /**
60
+ * The Commerce shared context for a mounted Admin UI iframe app.
61
+ *
62
+ * This only exists when the app runs inside the Commerce Admin: it is provided by the Commerce UIX
63
+ * host over the guest connection. It is distinct from the IMS credentials ({@link ImsContext}),
64
+ * which are also available in the Experience Cloud shell.
65
+ */
66
+ type SharedContext = {
67
+ /** The extension ID of the app. */extensionId: string; /** The live `sharedContext` object provided by the host. */
68
+ sharedContext: NonNullable<GuestConnection["sharedContext"]>; /** The host proxy, used by `useHostConnection` to invoke host-frame actions (close/onError). */
69
+ host: NonNullable<GuestConnection["host"]>;
70
+ };
71
+ /** Actions for closing the extension iframe and returning control to the Commerce Admin. */
72
+ type HostConnection = {
73
+ /** Closes the iframe and navigates back to the originating grid or order. */close: () => Promise<void>; /** Closes the iframe and navigates back, flagging the originating page that an error occurred. */
74
+ closeWithError: () => Promise<void>;
75
+ };
76
+ /** The context shared with mass-action extension points. */
77
+ type MassActionContext = {
78
+ selectedIds: string[];
79
+ };
80
+ /** The context shared with order view-button extension points. */
81
+ type OrderViewButtonContext = {
82
+ orderId: string;
83
+ };
84
+ //#endregion
85
+ //#region source/web/react/commerce/context/shared-context.d.ts
86
+ /**
87
+ * Returns the current Commerce shared context. The guest connection is already established by
88
+ * the time this can be called (see {@link SharedContextProvider}).
89
+ *
90
+ * This is a low-level escape hatch that exposes the raw `sharedContext` and `host` objects.
91
+ * Prefer a purpose-built hook ({@link useCommerce}, {@link useMassActionContext},
92
+ * {@link useOrderViewButtonContext}) when one covers what you need.
93
+ *
94
+ * @example
95
+ * ```tsx
96
+ * import { useSharedContext } from "@adobe/aio-commerce-lib-admin-ui/web";
97
+ *
98
+ * function ImsTokenLabel() {
99
+ * const { data, error } = useSharedContext();
100
+ * if (error) return null;
101
+ * return <span>{data.sharedContext.get("imsToken")}</span>;
102
+ * }
103
+ * ```
104
+ */
105
+ declare function useSharedContext(): Result<SharedContext>;
106
+ //#endregion
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. */
112
+ /**
113
+ * Returns the host (domain) of the Commerce Admin the extension is embedded in, resolving it over
114
+ * the guest connection.
115
+ *
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.
118
+ */
119
+ declare function useCommerce(): Result<CommerceData>;
120
+ //#endregion
121
+ //#region source/web/react/commerce/hooks/use-extension-context.d.ts
122
+ /**
123
+ * Returns the context for a mass-action extension point: the selected row IDs the action was
124
+ * triggered with. The value is read from the host-provided Commerce context.
125
+ *
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.
128
+ */
129
+ declare function useMassActionContext(): Result<MassActionContext>;
130
+ /**
131
+ * Returns the context for an order view-button extension point: the order ID the button was
132
+ * triggered from.
133
+ *
134
+ * Returns an error when no order ID is present in the page URL.
135
+ */
136
+ declare function useOrderViewButtonContext(): Result<OrderViewButtonContext>;
137
+ //#endregion
138
+ //#region source/web/react/commerce/hooks/use-host-connection.d.ts
139
+ /**
140
+ * Returns typed helpers for interacting with the Commerce Admin host.
141
+ *
142
+ * @example
143
+ * ```tsx
144
+ * import { useHostConnection } from "@adobe/aio-commerce-lib-admin-ui/web";
145
+ *
146
+ * function DoneButton() {
147
+ * const { actions, error } = useHostConnection();
148
+ * if (error) return null;
149
+ * return <button onClick={actions.close}>Done</button>;
150
+ * }
151
+ * ```
152
+ */
153
+ declare function useHostConnection(): ActionsResult<HostConnection>;
154
+ //#endregion
155
+ //#region source/web/react/routing/types.d.ts
156
+ declare module "@react-spectrum/s2/Provider" {
157
+ interface RouterConfig {
158
+ href: ToOptions;
159
+ routerOptions: Omit<NavigateOptions, keyof ToOptions>;
160
+ }
161
+ }
162
+ /** Defines a route that exists at a given path. */
163
+ type ExtensionRoute = {
164
+ /** The path for the route. */path: string; /** The React element to render for the route. */
165
+ element: ReactNode;
166
+ };
167
+ //#endregion
168
+ //#region source/web/react/extension/create-app.d.ts
169
+ /** Configuration options when instantiating an extension app. */
170
+ type CreateExtensionAppOptions = {
171
+ /** General metadata about the extension app. */metadata: {
172
+ /** The unique identifier for the extension app. */extensionId: string;
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[];
177
+ };
178
+ /**
179
+ * Mounts a Commerce Admin UI iframe app and handles Experience Cloud Shell, UIX
180
+ * registration, shared-context attachment, routing, and Spectrum setup.
181
+ *
182
+ * The app is wrapped in React's `<StrictMode>`, so in development builds (e.g. when
183
+ * served via `aio app dev` or `aio app run`) components render twice and effects run
184
+ * an extra setup + cleanup cycle on mount. Production builds are unaffected.
185
+ *
186
+ * @param options - App bootstrap options.
187
+ *
188
+ * @example
189
+ * ```tsx
190
+ * import { createExtensionApp } from "@adobe/aio-commerce-lib-admin-ui/web";
191
+ * import { MainPage } from "./pages/main-page.jsx";
192
+ *
193
+ * createExtensionApp({
194
+ * metadata: { extensionId: "my-extension-id" },
195
+ * menu: <MainPage />,
196
+ * });
197
+ * ```
198
+ */
199
+ declare function createExtensionApp({
200
+ menu,
201
+ metadata,
202
+ routes,
203
+ root: customRoot
204
+ }: CreateExtensionAppOptions): void;
205
+ //#endregion
206
+ export { type CreateExtensionAppOptions, type ExtensionRoute, type HostConnection, type ImsContext, type MassActionContext, type OrderViewButtonContext, type SharedContext, createExtensionApp, useCommerce, useHostConnection, useIms, useMassActionContext, useOrderViewButtonContext, useSharedContext };