@adobe/aio-commerce-lib-admin-ui 1.2.0 → 1.3.0-alpha-20261110171457

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 (36) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/README.md +1 -1
  3. package/dist/cjs/api/index.cjs +2 -2
  4. package/dist/cjs/api/index.d.cts +1 -0
  5. package/dist/cjs/credit-memo-view-buttons/index.cjs +90 -0
  6. package/dist/cjs/credit-memo-view-buttons/index.d.cts +76 -0
  7. package/dist/cjs/grid-columns/index.cjs +3 -3
  8. package/dist/cjs/grid-columns/index.d.cts +9 -0
  9. package/dist/cjs/invoice-view-buttons/index.cjs +90 -0
  10. package/dist/cjs/invoice-view-buttons/index.d.cts +76 -0
  11. package/dist/cjs/mass-actions/index.cjs +3 -3
  12. package/dist/cjs/mass-actions/index.d.cts +10 -0
  13. package/dist/cjs/menu/index.d.cts +9 -0
  14. package/dist/cjs/order-view-buttons/index.cjs +6 -5
  15. package/dist/cjs/order-view-buttons/index.d.cts +10 -1
  16. package/dist/cjs/{rolldown-runtime-DREAZOkv.cjs → rolldown-runtime-DdowHpbl.cjs} +4 -4
  17. package/dist/cjs/{schemas-C-tIBLog.cjs → schemas-CkbEkj5k.cjs} +1 -1
  18. package/dist/cjs/{utils-D5meZ8l8.cjs → utils-Dz_BZgfW.cjs} +1 -1
  19. package/dist/cjs/view-button-request-BymT_z5j.cjs +46 -0
  20. package/dist/cjs/web/index.cjs +95 -3
  21. package/dist/cjs/web/index.d.cts +63 -2
  22. package/dist/es/api/index.d.mts +1 -0
  23. package/dist/es/api/index.mjs +4 -4
  24. package/dist/es/credit-memo-view-buttons/index.d.mts +76 -0
  25. package/dist/es/credit-memo-view-buttons/index.mjs +83 -0
  26. package/dist/es/grid-columns/index.d.mts +9 -0
  27. package/dist/es/invoice-view-buttons/index.d.mts +76 -0
  28. package/dist/es/invoice-view-buttons/index.mjs +83 -0
  29. package/dist/es/mass-actions/index.d.mts +10 -0
  30. package/dist/es/menu/index.d.mts +9 -0
  31. package/dist/es/order-view-buttons/index.d.mts +10 -1
  32. package/dist/es/order-view-buttons/index.mjs +3 -2
  33. package/dist/es/view-button-request-Cu7Qz7jY.mjs +39 -0
  34. package/dist/es/web/index.d.mts +63 -2
  35. package/dist/es/web/index.mjs +90 -2
  36. package/package.json +21 -1
@@ -14,6 +14,7 @@
14
14
 
15
15
  import { a as sanitizeSegment, r as getAclResourceId } from "../acl-resource-id-C4Is2i_h.mjs";
16
16
  import { t as parseOrThrow } from "../utils-G-EDWmew.mjs";
17
+ import { t as normalizeViewButtonWorkerParams } from "../view-button-request-Cu7Qz7jY.mjs";
17
18
  import { t as nonEmptyStringValueSchema } from "../schemas-Dftlsf98.mjs";
18
19
  import * as v from "valibot";
19
20
  import { buildErrorResponse, ok } from "@adobe/aio-commerce-lib-core/responses";
@@ -22,7 +23,7 @@ import { buildErrorResponse, ok } from "@adobe/aio-commerce-lib-core/responses";
22
23
  /**
23
24
  * Derives the deterministic Commerce ACL resource id for an order view button.
24
25
  *
25
- * View buttons exist only on the order entity, so no entity discriminator is needed.
26
+ * This helper is scoped to the order entity, so no entity discriminator is needed.
26
27
  * The id is assembled as: `getAclResourceId(metadataId)` + `"_order_viewbuttons_"` +
27
28
  * sanitized `buttonId`. The `buttonId` is sanitized (trimmed, lowercased, non-`[a-z0-9_]` → `_`).
28
29
  * `"Magento_CommerceBackendUix::adminuisdk_app_"` in the example is the fixed constant prefix
@@ -80,7 +81,7 @@ const OrderViewButtonRequestSchema = v.object({
80
81
  * ```
81
82
  */
82
83
  function parseOrderViewButtonRequest(input) {
83
- return parseOrThrow(OrderViewButtonRequestSchema, input, "Invalid order view button request");
84
+ return parseOrThrow(OrderViewButtonRequestSchema, normalizeViewButtonWorkerParams(input), "Invalid order view button request");
84
85
  }
85
86
  /**
86
87
  * Builds an HTTP 200 success response for an order view button handler.
@@ -0,0 +1,39 @@
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
+ import { getHeader, getHeadersFromParams } from "@adobe/aio-commerce-lib-core/headers";
17
+
18
+ // source/lib/view-button-request.ts
19
+ const REQUEST_ID_HEADER = "x-request-id";
20
+ const RuntimeParamsSchema = v.record(v.string(), v.unknown());
21
+ /**
22
+ * Maps the params Commerce sends to a view-button worker onto the documented request shape.
23
+ *
24
+ * Commerce POSTs `{ <entityId>, buttonId }` and sends the request ID in the `X-Request-ID`
25
+ * header, which App Builder exposes in `__ow_headers`. Explicit `id` and `requestId` params
26
+ * take precedence so direct calls with the documented shape keep working. Inputs that are not
27
+ * runtime params are returned as-is so the entity schema reports the validation error.
28
+ */
29
+ function normalizeViewButtonWorkerParams(input) {
30
+ if (!v.is(RuntimeParamsSchema, input)) return input;
31
+ const headers = input.__ow_headers === void 0 ? {} : getHeadersFromParams(input);
32
+ return {
33
+ ...input,
34
+ id: input.id ?? input.buttonId,
35
+ requestId: input.requestId ?? getHeader(headers, REQUEST_ID_HEADER)
36
+ };
37
+ }
38
+
39
+ export { normalizeViewButtonWorkerParams as t };
@@ -12,6 +12,11 @@
12
12
  * governing permissions and limitations under the License.
13
13
  */
14
14
 
15
+ /** biome-ignore-all lint/performance/noBarrelFile: This is the public API for the web entrypoint. */
16
+ /**
17
+ * Browser helpers for mounting `commerce/backend-ui/2` iframe apps.
18
+ * @packageDocumentation
19
+ */
15
20
  import { ReactNode } from "react";
16
21
  import { NavigateOptions, ToOptions } from "@tanstack/react-router";
17
22
  import { attach } from "@adobe/uix-guest";
@@ -65,7 +70,7 @@ type SharedContext = {
65
70
  };
66
71
  /** Actions for closing the extension iframe and returning control to the Commerce Admin. */
67
72
  type HostConnection = {
68
- /** Closes the iframe and navigates back to the originating grid or order. */
73
+ /** Closes the iframe and navigates back to the originating grid or detail page. */
69
74
  close: () => Promise<void>;
70
75
  /** Closes the iframe and navigates back, flagging the originating page that an error occurred. */
71
76
  closeWithError: () => Promise<void>;
@@ -78,6 +83,22 @@ type MassActionContext = {
78
83
  type OrderViewButtonContext = {
79
84
  orderId: string;
80
85
  };
86
+ /** The customer identifier provided by the Commerce shared context. */
87
+ type CustomerContext = {
88
+ customerId: string;
89
+ };
90
+ /** The store identifier provided by the Commerce shared context. */
91
+ type StoreContext = {
92
+ storeId: string;
93
+ };
94
+ /** The context shared with invoice view-button extension points. */
95
+ type InvoiceViewButtonContext = {
96
+ invoiceId: string;
97
+ };
98
+ /** The context shared with credit memo view-button extension points. */
99
+ type CreditMemoViewButtonContext = {
100
+ creditMemoId: string;
101
+ };
81
102
  /**
82
103
  * Returns the current Commerce shared context. The guest connection is already established by
83
104
  * the time this can be called (see {@link SharedContextProvider}).
@@ -124,6 +145,46 @@ export declare function useMassActionContext(): Result<MassActionContext>;
124
145
  * Returns an error when no order ID is present in the page URL.
125
146
  */
126
147
  export declare function useOrderViewButtonContext(): Result<OrderViewButtonContext>;
148
+ /**
149
+ * Returns the customer identifier from the Commerce shared context as a string.
150
+ * Numeric identifiers are converted to strings; existing strings retain leading zeros.
151
+ *
152
+ * Returns an error outside the Commerce shared context or when the customer identifier is
153
+ * missing, null, or not a string or finite number. The store identifier is not required.
154
+ */
155
+ export declare function useCustomerContext(): Result<CustomerContext>;
156
+ /**
157
+ * Returns the store identifier from the Commerce shared context as a string.
158
+ * Numeric identifiers are converted to strings; existing strings retain leading zeros.
159
+ *
160
+ * Returns an error outside the Commerce shared context or when the store identifier is
161
+ * missing, null, or not a string or finite number. The customer identifier is not required.
162
+ */
163
+ export declare function useStoreContext(): Result<StoreContext>;
164
+ /**
165
+ * Returns the invoice ID for an invoice view-button extension point.
166
+ * Reads `invoiceId` from the page URL search parameters or hash-route query.
167
+ * Returns an error when the invoice ID is missing or blank.
168
+ * @example
169
+ * ```tsx
170
+ * const { data, error } = useInvoiceViewButtonContext();
171
+ * if (error) throw error;
172
+ * return <span>{data.invoiceId}</span>;
173
+ * ```
174
+ */
175
+ export declare function useInvoiceViewButtonContext(): Result<InvoiceViewButtonContext>;
176
+ /**
177
+ * Returns the credit memo ID for a credit memo view-button extension point.
178
+ * Reads `creditMemoId` from the page URL search parameters or hash-route query.
179
+ * Returns an error when the credit memo ID is missing or blank.
180
+ * @example
181
+ * ```tsx
182
+ * const { data, error } = useCreditMemoViewButtonContext();
183
+ * if (error) throw error;
184
+ * return <span>{data.creditMemoId}</span>;
185
+ * ```
186
+ */
187
+ export declare function useCreditMemoViewButtonContext(): Result<CreditMemoViewButtonContext>;
127
188
  /**
128
189
  * Returns typed helpers for interacting with the Commerce Admin host.
129
190
  *
@@ -190,4 +251,4 @@ type CreateExtensionAppOptions = {
190
251
  * ```
191
252
  */
192
253
  export declare function createExtensionApp({ menu, metadata, routes, root: customRoot }: CreateExtensionAppOptions): void;
193
- export type { CreateExtensionAppOptions, ExtensionRoute, HostConnection, ImsContext, MassActionContext, OrderViewButtonContext, SharedContext };
254
+ export type { CreateExtensionAppOptions, CreditMemoViewButtonContext, CustomerContext, ExtensionRoute, HostConnection, ImsContext, InvoiceViewButtonContext, MassActionContext, OrderViewButtonContext, SharedContext, StoreContext };
@@ -12,6 +12,7 @@
12
12
  * governing permissions and limitations under the License.
13
13
  */
14
14
 
15
+ import { finite, is, number, pipe, string, union } from "valibot";
15
16
  import { StrictMode, Suspense, createContext, use, useCallback, useEffect, useMemo, useState, useSyncExternalStore } from "react";
16
17
  import { jsx, jsxs } from "react/jsx-runtime";
17
18
  import Runtime, { init } from "@adobe/exc-app";
@@ -32,8 +33,26 @@ import { ErrorBoundary } from "react-error-boundary";
32
33
  * @param href - The URL to read the order ID from (typically `window.location.href`).
33
34
  */
34
35
  function parseOrderId(href) {
36
+ return parseViewButtonId(href, "orderId");
37
+ }
38
+ /**
39
+ * Extracts the invoice ID from the given absolute URL.
40
+ * @param href - The URL to read the invoice ID from (typically `window.location.href`).
41
+ */
42
+ function parseInvoiceId(href) {
43
+ return parseViewButtonId(href, "invoiceId");
44
+ }
45
+ /**
46
+ * Extracts the credit memo ID from the given absolute URL.
47
+ * @param href - The URL to read the credit memo ID from (typically `window.location.href`).
48
+ */
49
+ function parseCreditMemoId(href) {
50
+ return parseViewButtonId(href, "creditMemoId");
51
+ }
52
+ /** Reads a view-button identifier from the URL search parameters or hash-route query. */
53
+ function parseViewButtonId(href, key) {
35
54
  const urlObj = new URL(href);
36
- return urlObj.searchParams.get("orderId") ?? new URLSearchParams(urlObj.hash.split("?")[1]).get("orderId");
55
+ return urlObj.searchParams.get(key) ?? new URLSearchParams(urlObj.hash.split("?").at(1)).get(key);
37
56
  }
38
57
  /** Whether the app is embedded in a host frame (the Commerce Admin or the Experience Cloud shell). */
39
58
  function isEmbeddedInHost() {
@@ -253,6 +272,7 @@ function useCommerce() {
253
272
  }
254
273
 
255
274
  // source/web/react/commerce/hooks/use-extension-context.ts
275
+ const ContextIdSchema = union([string(), pipe(number(), finite())]);
256
276
  /**
257
277
  * Returns the context for a mass-action extension point: the selected row IDs the action was
258
278
  * triggered with. The value is read from the host-provided Commerce context.
@@ -284,6 +304,74 @@ function useOrderViewButtonContext() {
284
304
  return ok({ orderId });
285
305
  }, []);
286
306
  }
307
+ /**
308
+ * Returns the customer identifier from the Commerce shared context as a string.
309
+ * Numeric identifiers are converted to strings; existing strings retain leading zeros.
310
+ *
311
+ * Returns an error outside the Commerce shared context or when the customer identifier is
312
+ * missing, null, or not a string or finite number. The store identifier is not required.
313
+ */
314
+ function useCustomerContext() {
315
+ const { data, error: contextError } = useSharedContext();
316
+ return useMemo(() => {
317
+ if (contextError) return error(contextError.message, { cause: contextError });
318
+ const customerId = data.sharedContext.get("customerId");
319
+ if (!is(ContextIdSchema, customerId)) return error("The Commerce shared context value \"customerId\" must be a string or finite number.");
320
+ return ok({ customerId: String(customerId) });
321
+ }, [data, contextError]);
322
+ }
323
+ /**
324
+ * Returns the store identifier from the Commerce shared context as a string.
325
+ * Numeric identifiers are converted to strings; existing strings retain leading zeros.
326
+ *
327
+ * Returns an error outside the Commerce shared context or when the store identifier is
328
+ * missing, null, or not a string or finite number. The customer identifier is not required.
329
+ */
330
+ function useStoreContext() {
331
+ const { data, error: contextError } = useSharedContext();
332
+ return useMemo(() => {
333
+ if (contextError) return error(contextError.message, { cause: contextError });
334
+ const storeId = data.sharedContext.get("storeId");
335
+ if (!is(ContextIdSchema, storeId)) return error("The Commerce shared context value \"storeId\" must be a string or finite number.");
336
+ return ok({ storeId: String(storeId) });
337
+ }, [data, contextError]);
338
+ }
339
+ /**
340
+ * Returns the invoice ID for an invoice view-button extension point.
341
+ * Reads `invoiceId` from the page URL search parameters or hash-route query.
342
+ * Returns an error when the invoice ID is missing or blank.
343
+ * @example
344
+ * ```tsx
345
+ * const { data, error } = useInvoiceViewButtonContext();
346
+ * if (error) throw error;
347
+ * return <span>{data.invoiceId}</span>;
348
+ * ```
349
+ */
350
+ function useInvoiceViewButtonContext() {
351
+ return useMemo(() => {
352
+ const invoiceId = parseInvoiceId(globalThis.location.href);
353
+ if (invoiceId === null || invoiceId.trim() === "") return error("Could not find an invoice ID. Is this frame running as an invoice view-button extension point?");
354
+ return ok({ invoiceId });
355
+ }, []);
356
+ }
357
+ /**
358
+ * Returns the credit memo ID for a credit memo view-button extension point.
359
+ * Reads `creditMemoId` from the page URL search parameters or hash-route query.
360
+ * Returns an error when the credit memo ID is missing or blank.
361
+ * @example
362
+ * ```tsx
363
+ * const { data, error } = useCreditMemoViewButtonContext();
364
+ * if (error) throw error;
365
+ * return <span>{data.creditMemoId}</span>;
366
+ * ```
367
+ */
368
+ function useCreditMemoViewButtonContext() {
369
+ return useMemo(() => {
370
+ const creditMemoId = parseCreditMemoId(globalThis.location.href);
371
+ if (creditMemoId === null || creditMemoId.trim() === "") return error("Could not find a credit memo ID. Is this frame running as a credit memo view-button extension point?");
372
+ return ok({ creditMemoId });
373
+ }, []);
374
+ }
287
375
 
288
376
  // source/web/react/commerce/hooks/use-host-connection.ts
289
377
  /**
@@ -847,4 +935,4 @@ function createExtensionApp({ menu, metadata, routes = [], root: customRoot }) {
847
935
  }
848
936
  }
849
937
 
850
- export { createExtensionApp, useCommerce, useHostConnection, useIms, useMassActionContext, useOrderViewButtonContext, useSharedContext };
938
+ export { createExtensionApp, useCommerce, useCreditMemoViewButtonContext, useCustomerContext, useHostConnection, useIms, useInvoiceViewButtonContext, useMassActionContext, useOrderViewButtonContext, useSharedContext, useStoreContext };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/aio-commerce-lib-admin-ui",
3
- "version": "1.2.0",
3
+ "version": "1.3.0-alpha-20261110171457",
4
4
  "private": false,
5
5
  "description": "A library to interact with the Adobe Commerce Admin UI SDK API",
6
6
  "keywords": [
@@ -42,6 +42,16 @@
42
42
  "default": "./dist/cjs/api/index.cjs"
43
43
  }
44
44
  },
45
+ "./credit-memo-view-buttons": {
46
+ "import": {
47
+ "types": "./dist/es/credit-memo-view-buttons/index.d.mts",
48
+ "default": "./dist/es/credit-memo-view-buttons/index.mjs"
49
+ },
50
+ "require": {
51
+ "types": "./dist/cjs/credit-memo-view-buttons/index.d.cts",
52
+ "default": "./dist/cjs/credit-memo-view-buttons/index.cjs"
53
+ }
54
+ },
45
55
  "./grid-columns": {
46
56
  "import": {
47
57
  "types": "./dist/es/grid-columns/index.d.mts",
@@ -52,6 +62,16 @@
52
62
  "default": "./dist/cjs/grid-columns/index.cjs"
53
63
  }
54
64
  },
65
+ "./invoice-view-buttons": {
66
+ "import": {
67
+ "types": "./dist/es/invoice-view-buttons/index.d.mts",
68
+ "default": "./dist/es/invoice-view-buttons/index.mjs"
69
+ },
70
+ "require": {
71
+ "types": "./dist/cjs/invoice-view-buttons/index.d.cts",
72
+ "default": "./dist/cjs/invoice-view-buttons/index.cjs"
73
+ }
74
+ },
55
75
  "./mass-actions": {
56
76
  "import": {
57
77
  "types": "./dist/es/mass-actions/index.d.mts",