@adobe/aio-commerce-lib-admin-ui 1.2.0 → 1.3.0-beta-20261105172845
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 +14 -0
- package/README.md +1 -1
- package/dist/cjs/credit-memo-view-buttons/index.cjs +90 -0
- package/dist/cjs/credit-memo-view-buttons/index.d.cts +70 -0
- package/dist/cjs/invoice-view-buttons/index.cjs +90 -0
- package/dist/cjs/invoice-view-buttons/index.d.cts +70 -0
- package/dist/cjs/order-view-buttons/index.cjs +3 -2
- package/dist/cjs/order-view-buttons/index.d.cts +1 -1
- package/dist/cjs/view-button-request-DdtipbWD.cjs +46 -0
- package/dist/cjs/web/index.cjs +94 -2
- package/dist/cjs/web/index.d.cts +58 -2
- package/dist/es/credit-memo-view-buttons/index.d.mts +70 -0
- package/dist/es/credit-memo-view-buttons/index.mjs +83 -0
- package/dist/es/invoice-view-buttons/index.d.mts +70 -0
- package/dist/es/invoice-view-buttons/index.mjs +83 -0
- package/dist/es/order-view-buttons/index.d.mts +1 -1
- package/dist/es/order-view-buttons/index.mjs +3 -2
- package/dist/es/view-button-request-Cu7Qz7jY.mjs +39 -0
- package/dist/es/web/index.d.mts +58 -2
- package/dist/es/web/index.mjs +90 -2
- package/package.json +21 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @adobe/aio-commerce-lib-admin-ui
|
|
2
2
|
|
|
3
|
+
## 1.3.0-beta-20261105172845
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#776](https://github.com/adobe/aio-commerce-sdk/pull/776) [`32988bb`](https://github.com/adobe/aio-commerce-sdk/commit/32988bbda397d9a34f788aee721f4dca9abc362a) Thanks [@aminakhyat](https://github.com/aminakhyat)! - Add the `credit-memo-view-buttons` entrypoint with worker request/response and ACL helpers, and the `useCreditMemoViewButtonContext` hook in `./web`.
|
|
8
|
+
|
|
9
|
+
- [#732](https://github.com/adobe/aio-commerce-sdk/pull/732) [`f124cf4`](https://github.com/adobe/aio-commerce-sdk/commit/f124cf49208d930ca0f151e948a7597317365697) Thanks [@asalloum5](https://github.com/asalloum5)! - Add invoice view-button runtime request/response and ACL helpers, plus a React hook for invoice iframe context.
|
|
10
|
+
|
|
11
|
+
- [#746](https://github.com/adobe/aio-commerce-sdk/pull/746) [`ca065be`](https://github.com/adobe/aio-commerce-sdk/commit/ca065bec387cf90ce21309420851bef408ca194e) Thanks [@asalloum5](https://github.com/asalloum5)! - Add the `useCustomerContext` and `useStoreContext` React hooks to independently read customer and store identifiers from Commerce shared context in native UI replacement pages, with guaranteed string identifiers on success, preserved leading zeros in string IDs, and errors for missing or invalid values.
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- [#776](https://github.com/adobe/aio-commerce-sdk/pull/776) [`32988bb`](https://github.com/adobe/aio-commerce-sdk/commit/32988bbda397d9a34f788aee721f4dca9abc362a) Thanks [@aminakhyat](https://github.com/aminakhyat)! - Fix the order, invoice and credit memo view button request parsers rejecting real Commerce requests: map the `buttonId` body field to `id` and the `X-Request-ID` header to `requestId`.
|
|
16
|
+
|
|
3
17
|
## 1.2.0
|
|
4
18
|
|
|
5
19
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# `@adobe/aio-commerce-lib-admin-ui`
|
|
2
2
|
|
|
3
|
-
This package provides utilities for interacting with the Adobe Commerce Admin UI SDK API, the extension points (grid columns, mass actions, menu, order view buttons), and browser-side helpers for Admin UI iframe extensions.
|
|
3
|
+
This package provides utilities for interacting with the Adobe Commerce Admin UI SDK API, the extension points (grid columns, mass actions, menu, order, invoice, and credit memo view buttons), and browser-side helpers for Admin UI iframe extensions.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -0,0 +1,90 @@
|
|
|
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
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
16
|
+
const require_rolldown_runtime = require("../rolldown-runtime-DREAZOkv.cjs");
|
|
17
|
+
const require_acl_resource_id = require("../acl-resource-id-Bjpse1tR.cjs");
|
|
18
|
+
const require_utils = require("../utils-D5meZ8l8.cjs");
|
|
19
|
+
const require_view_button_request = require("../view-button-request-DdtipbWD.cjs");
|
|
20
|
+
const require_schemas = require("../schemas-C-tIBLog.cjs");
|
|
21
|
+
let valibot = require("valibot");
|
|
22
|
+
valibot = require_rolldown_runtime.__toESM(valibot, 1);
|
|
23
|
+
let _adobe_aio_commerce_lib_core_responses = require("@adobe/aio-commerce-lib-core/responses");
|
|
24
|
+
|
|
25
|
+
// source/credit-memo-view-buttons/acl-resource-id.ts
|
|
26
|
+
/**
|
|
27
|
+
* Derives the Commerce ACL resource ID for a credit memo view button.
|
|
28
|
+
* App and button IDs are trimmed, lowercased, and sanitized independently.
|
|
29
|
+
*
|
|
30
|
+
* @param metadataId - The application's `metadata.id` value.
|
|
31
|
+
* @param buttonId - The button's `adminUi.creditMemo.viewButtons[].id` value.
|
|
32
|
+
* @returns The credit memo view-button leaf ID, or an empty string when `metadataId` is blank.
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* getCreditMemoViewButtonAclResourceId("refund-app", "refund-offline");
|
|
36
|
+
* // "Magento_CommerceBackendUix::adminuisdk_app_refund_app_creditmemo_viewbuttons_refund_offline"
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
function getCreditMemoViewButtonAclResourceId(metadataId, buttonId) {
|
|
40
|
+
const appRoot = require_acl_resource_id.getAclResourceId(metadataId);
|
|
41
|
+
if (appRoot === "") return "";
|
|
42
|
+
return `${appRoot}_creditmemo_viewbuttons_${require_acl_resource_id.sanitizeSegment(buttonId)}`;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// source/credit-memo-view-buttons/schema.ts
|
|
46
|
+
/**
|
|
47
|
+
* Schema for a credit memo view-button worker request.
|
|
48
|
+
* `id` identifies the clicked button; `creditMemoId` identifies the credit memo being viewed.
|
|
49
|
+
* All three fields must be non-empty strings.
|
|
50
|
+
*/
|
|
51
|
+
const CreditMemoViewButtonRequestSchema = valibot.object({
|
|
52
|
+
creditMemoId: require_schemas.nonEmptyStringValueSchema("creditMemoId"),
|
|
53
|
+
id: require_schemas.nonEmptyStringValueSchema("id"),
|
|
54
|
+
requestId: require_schemas.nonEmptyStringValueSchema("requestId")
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
// source/credit-memo-view-buttons/presets.ts
|
|
58
|
+
/**
|
|
59
|
+
* Parses a credit memo view-button worker request.
|
|
60
|
+
* Throws `CommerceSdkValidationError` when the input is malformed.
|
|
61
|
+
* @example
|
|
62
|
+
* ```ts
|
|
63
|
+
* const { requestId, id, creditMemoId } = parseCreditMemoViewButtonRequest(params);
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
function parseCreditMemoViewButtonRequest(input) {
|
|
67
|
+
return require_utils.parseOrThrow(CreditMemoViewButtonRequestSchema, require_view_button_request.normalizeViewButtonWorkerParams(input), "Invalid credit memo view button request");
|
|
68
|
+
}
|
|
69
|
+
/** Builds an HTTP 200 response with an empty body for a credit memo view-button worker. */
|
|
70
|
+
function okCreditMemoViewButtonResponse() {
|
|
71
|
+
return (0, _adobe_aio_commerce_lib_core_responses.ok)({ body: {} });
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Builds an error response for a credit memo view-button worker.
|
|
75
|
+
* @param statusCode - The HTTP status code to return.
|
|
76
|
+
* @param errorMessage - The message included in the response body.
|
|
77
|
+
* @example
|
|
78
|
+
* ```ts
|
|
79
|
+
* return creditMemoViewButtonErrorResponse(500, "Could not refund the credit memo");
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
function creditMemoViewButtonErrorResponse(statusCode, errorMessage) {
|
|
83
|
+
return (0, _adobe_aio_commerce_lib_core_responses.buildErrorResponse)(statusCode, { body: { message: errorMessage } });
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
exports.CreditMemoViewButtonRequestSchema = CreditMemoViewButtonRequestSchema;
|
|
87
|
+
exports.creditMemoViewButtonErrorResponse = creditMemoViewButtonErrorResponse;
|
|
88
|
+
exports.getCreditMemoViewButtonAclResourceId = getCreditMemoViewButtonAclResourceId;
|
|
89
|
+
exports.okCreditMemoViewButtonResponse = okCreditMemoViewButtonResponse;
|
|
90
|
+
exports.parseCreditMemoViewButtonRequest = parseCreditMemoViewButtonRequest;
|
|
@@ -0,0 +1,70 @@
|
|
|
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 { ErrorResponse, SuccessResponse } from "@adobe/aio-commerce-lib-core/responses";
|
|
17
|
+
/**
|
|
18
|
+
* Derives the Commerce ACL resource ID for a credit memo view button.
|
|
19
|
+
* App and button IDs are trimmed, lowercased, and sanitized independently.
|
|
20
|
+
*
|
|
21
|
+
* @param metadataId - The application's `metadata.id` value.
|
|
22
|
+
* @param buttonId - The button's `adminUi.creditMemo.viewButtons[].id` value.
|
|
23
|
+
* @returns The credit memo view-button leaf ID, or an empty string when `metadataId` is blank.
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* getCreditMemoViewButtonAclResourceId("refund-app", "refund-offline");
|
|
27
|
+
* // "Magento_CommerceBackendUix::adminuisdk_app_refund_app_creditmemo_viewbuttons_refund_offline"
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export declare function getCreditMemoViewButtonAclResourceId(metadataId: string, buttonId: string): string;
|
|
31
|
+
/**
|
|
32
|
+
* Schema for a credit memo view-button worker request.
|
|
33
|
+
* `id` identifies the clicked button; `creditMemoId` identifies the credit memo being viewed.
|
|
34
|
+
* All three fields must be non-empty strings.
|
|
35
|
+
*/
|
|
36
|
+
export declare const CreditMemoViewButtonRequestSchema: v.ObjectSchema<{
|
|
37
|
+
readonly creditMemoId: v.SchemaWithPipe<readonly [v.StringSchema<`Expected a string value for '${string}'`>, v.NonEmptyAction<string, `The value of "${string}" must not be empty`>]>;
|
|
38
|
+
readonly id: v.SchemaWithPipe<readonly [v.StringSchema<`Expected a string value for '${string}'`>, v.NonEmptyAction<string, `The value of "${string}" must not be empty`>]>;
|
|
39
|
+
readonly requestId: v.SchemaWithPipe<readonly [v.StringSchema<`Expected a string value for '${string}'`>, v.NonEmptyAction<string, `The value of "${string}" must not be empty`>]>;
|
|
40
|
+
}, undefined>;
|
|
41
|
+
/** Parsed request body for a credit memo view-button worker. */
|
|
42
|
+
type CreditMemoViewButtonRequest = v.InferOutput<typeof CreditMemoViewButtonRequestSchema>;
|
|
43
|
+
/** Empty success body returned by a credit memo view-button worker. */
|
|
44
|
+
type CreditMemoViewButtonSuccessBody = Record<string, never>;
|
|
45
|
+
/** Error body returned by a credit memo view-button worker. */
|
|
46
|
+
type CreditMemoViewButtonErrorBody = {
|
|
47
|
+
message: string;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Parses a credit memo view-button worker request.
|
|
51
|
+
* Throws `CommerceSdkValidationError` when the input is malformed.
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* const { requestId, id, creditMemoId } = parseCreditMemoViewButtonRequest(params);
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export declare function parseCreditMemoViewButtonRequest(input: unknown): CreditMemoViewButtonRequest;
|
|
58
|
+
/** Builds an HTTP 200 response with an empty body for a credit memo view-button worker. */
|
|
59
|
+
export declare function okCreditMemoViewButtonResponse(): SuccessResponse<CreditMemoViewButtonSuccessBody>;
|
|
60
|
+
/**
|
|
61
|
+
* Builds an error response for a credit memo view-button worker.
|
|
62
|
+
* @param statusCode - The HTTP status code to return.
|
|
63
|
+
* @param errorMessage - The message included in the response body.
|
|
64
|
+
* @example
|
|
65
|
+
* ```ts
|
|
66
|
+
* return creditMemoViewButtonErrorResponse(500, "Could not refund the credit memo");
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
export declare function creditMemoViewButtonErrorResponse(statusCode: number, errorMessage: string): ErrorResponse<CreditMemoViewButtonErrorBody>;
|
|
70
|
+
export type { CreditMemoViewButtonErrorBody, CreditMemoViewButtonRequest, CreditMemoViewButtonSuccessBody };
|
|
@@ -0,0 +1,90 @@
|
|
|
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
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
16
|
+
const require_rolldown_runtime = require("../rolldown-runtime-DREAZOkv.cjs");
|
|
17
|
+
const require_acl_resource_id = require("../acl-resource-id-Bjpse1tR.cjs");
|
|
18
|
+
const require_utils = require("../utils-D5meZ8l8.cjs");
|
|
19
|
+
const require_view_button_request = require("../view-button-request-DdtipbWD.cjs");
|
|
20
|
+
const require_schemas = require("../schemas-C-tIBLog.cjs");
|
|
21
|
+
let valibot = require("valibot");
|
|
22
|
+
valibot = require_rolldown_runtime.__toESM(valibot, 1);
|
|
23
|
+
let _adobe_aio_commerce_lib_core_responses = require("@adobe/aio-commerce-lib-core/responses");
|
|
24
|
+
|
|
25
|
+
// source/invoice-view-buttons/acl-resource-id.ts
|
|
26
|
+
/**
|
|
27
|
+
* Derives the Commerce ACL resource ID for an invoice view button.
|
|
28
|
+
* App and button IDs are trimmed, lowercased, and sanitized independently.
|
|
29
|
+
*
|
|
30
|
+
* @param metadataId - The application's `metadata.id` value.
|
|
31
|
+
* @param buttonId - The button's `adminUi.invoice.viewButtons[].id` value.
|
|
32
|
+
* @returns The invoice view-button leaf ID, or an empty string when `metadataId` is blank.
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* getInvoiceViewButtonAclResourceId("billing-app", "export-invoice");
|
|
36
|
+
* // "Magento_CommerceBackendUix::adminuisdk_app_billing_app_invoice_viewbuttons_export_invoice"
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
function getInvoiceViewButtonAclResourceId(metadataId, buttonId) {
|
|
40
|
+
const appRoot = require_acl_resource_id.getAclResourceId(metadataId);
|
|
41
|
+
if (appRoot === "") return "";
|
|
42
|
+
return `${appRoot}_invoice_viewbuttons_${require_acl_resource_id.sanitizeSegment(buttonId)}`;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// source/invoice-view-buttons/schema.ts
|
|
46
|
+
/**
|
|
47
|
+
* Schema for an invoice view-button worker request.
|
|
48
|
+
* `id` identifies the clicked button; `invoiceId` identifies the invoice being viewed.
|
|
49
|
+
* All three fields must be non-empty strings.
|
|
50
|
+
*/
|
|
51
|
+
const InvoiceViewButtonRequestSchema = valibot.object({
|
|
52
|
+
id: require_schemas.nonEmptyStringValueSchema("id"),
|
|
53
|
+
invoiceId: require_schemas.nonEmptyStringValueSchema("invoiceId"),
|
|
54
|
+
requestId: require_schemas.nonEmptyStringValueSchema("requestId")
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
// source/invoice-view-buttons/presets.ts
|
|
58
|
+
/**
|
|
59
|
+
* Parses an invoice view-button worker request.
|
|
60
|
+
* Throws `CommerceSdkValidationError` when the input is malformed.
|
|
61
|
+
* @example
|
|
62
|
+
* ```ts
|
|
63
|
+
* const { requestId, id, invoiceId } = parseInvoiceViewButtonRequest(params);
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
function parseInvoiceViewButtonRequest(input) {
|
|
67
|
+
return require_utils.parseOrThrow(InvoiceViewButtonRequestSchema, require_view_button_request.normalizeViewButtonWorkerParams(input), "Invalid invoice view button request");
|
|
68
|
+
}
|
|
69
|
+
/** Builds an HTTP 200 response with an empty body for an invoice view-button worker. */
|
|
70
|
+
function okInvoiceViewButtonResponse() {
|
|
71
|
+
return (0, _adobe_aio_commerce_lib_core_responses.ok)({ body: {} });
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Builds an error response for an invoice view-button worker.
|
|
75
|
+
* @param statusCode - The HTTP status code to return.
|
|
76
|
+
* @param errorMessage - The message included in the response body.
|
|
77
|
+
* @example
|
|
78
|
+
* ```ts
|
|
79
|
+
* return invoiceViewButtonErrorResponse(500, "Could not export the invoice");
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
function invoiceViewButtonErrorResponse(statusCode, errorMessage) {
|
|
83
|
+
return (0, _adobe_aio_commerce_lib_core_responses.buildErrorResponse)(statusCode, { body: { message: errorMessage } });
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
exports.InvoiceViewButtonRequestSchema = InvoiceViewButtonRequestSchema;
|
|
87
|
+
exports.getInvoiceViewButtonAclResourceId = getInvoiceViewButtonAclResourceId;
|
|
88
|
+
exports.invoiceViewButtonErrorResponse = invoiceViewButtonErrorResponse;
|
|
89
|
+
exports.okInvoiceViewButtonResponse = okInvoiceViewButtonResponse;
|
|
90
|
+
exports.parseInvoiceViewButtonRequest = parseInvoiceViewButtonRequest;
|
|
@@ -0,0 +1,70 @@
|
|
|
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 { ErrorResponse, SuccessResponse } from "@adobe/aio-commerce-lib-core/responses";
|
|
17
|
+
/**
|
|
18
|
+
* Derives the Commerce ACL resource ID for an invoice view button.
|
|
19
|
+
* App and button IDs are trimmed, lowercased, and sanitized independently.
|
|
20
|
+
*
|
|
21
|
+
* @param metadataId - The application's `metadata.id` value.
|
|
22
|
+
* @param buttonId - The button's `adminUi.invoice.viewButtons[].id` value.
|
|
23
|
+
* @returns The invoice view-button leaf ID, or an empty string when `metadataId` is blank.
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* getInvoiceViewButtonAclResourceId("billing-app", "export-invoice");
|
|
27
|
+
* // "Magento_CommerceBackendUix::adminuisdk_app_billing_app_invoice_viewbuttons_export_invoice"
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export declare function getInvoiceViewButtonAclResourceId(metadataId: string, buttonId: string): string;
|
|
31
|
+
/**
|
|
32
|
+
* Schema for an invoice view-button worker request.
|
|
33
|
+
* `id` identifies the clicked button; `invoiceId` identifies the invoice being viewed.
|
|
34
|
+
* All three fields must be non-empty strings.
|
|
35
|
+
*/
|
|
36
|
+
export declare const InvoiceViewButtonRequestSchema: v.ObjectSchema<{
|
|
37
|
+
readonly id: v.SchemaWithPipe<readonly [v.StringSchema<`Expected a string value for '${string}'`>, v.NonEmptyAction<string, `The value of "${string}" must not be empty`>]>;
|
|
38
|
+
readonly invoiceId: v.SchemaWithPipe<readonly [v.StringSchema<`Expected a string value for '${string}'`>, v.NonEmptyAction<string, `The value of "${string}" must not be empty`>]>;
|
|
39
|
+
readonly requestId: v.SchemaWithPipe<readonly [v.StringSchema<`Expected a string value for '${string}'`>, v.NonEmptyAction<string, `The value of "${string}" must not be empty`>]>;
|
|
40
|
+
}, undefined>;
|
|
41
|
+
/** Parsed request body for an invoice view-button worker. */
|
|
42
|
+
type InvoiceViewButtonRequest = v.InferOutput<typeof InvoiceViewButtonRequestSchema>;
|
|
43
|
+
/** Empty success body returned by an invoice view-button worker. */
|
|
44
|
+
type InvoiceViewButtonSuccessBody = Record<string, never>;
|
|
45
|
+
/** Error body returned by an invoice view-button worker. */
|
|
46
|
+
type InvoiceViewButtonErrorBody = {
|
|
47
|
+
message: string;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Parses an invoice view-button worker request.
|
|
51
|
+
* Throws `CommerceSdkValidationError` when the input is malformed.
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* const { requestId, id, invoiceId } = parseInvoiceViewButtonRequest(params);
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export declare function parseInvoiceViewButtonRequest(input: unknown): InvoiceViewButtonRequest;
|
|
58
|
+
/** Builds an HTTP 200 response with an empty body for an invoice view-button worker. */
|
|
59
|
+
export declare function okInvoiceViewButtonResponse(): SuccessResponse<InvoiceViewButtonSuccessBody>;
|
|
60
|
+
/**
|
|
61
|
+
* Builds an error response for an invoice view-button worker.
|
|
62
|
+
* @param statusCode - The HTTP status code to return.
|
|
63
|
+
* @param errorMessage - The message included in the response body.
|
|
64
|
+
* @example
|
|
65
|
+
* ```ts
|
|
66
|
+
* return invoiceViewButtonErrorResponse(500, "Could not export the invoice");
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
export declare function invoiceViewButtonErrorResponse(statusCode: number, errorMessage: string): ErrorResponse<InvoiceViewButtonErrorBody>;
|
|
70
|
+
export type { InvoiceViewButtonErrorBody, InvoiceViewButtonRequest, InvoiceViewButtonSuccessBody };
|
|
@@ -16,6 +16,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
16
16
|
const require_rolldown_runtime = require("../rolldown-runtime-DREAZOkv.cjs");
|
|
17
17
|
const require_acl_resource_id = require("../acl-resource-id-Bjpse1tR.cjs");
|
|
18
18
|
const require_utils = require("../utils-D5meZ8l8.cjs");
|
|
19
|
+
const require_view_button_request = require("../view-button-request-DdtipbWD.cjs");
|
|
19
20
|
const require_schemas = require("../schemas-C-tIBLog.cjs");
|
|
20
21
|
let valibot = require("valibot");
|
|
21
22
|
valibot = require_rolldown_runtime.__toESM(valibot, 1);
|
|
@@ -25,7 +26,7 @@ let _adobe_aio_commerce_lib_core_responses = require("@adobe/aio-commerce-lib-co
|
|
|
25
26
|
/**
|
|
26
27
|
* Derives the deterministic Commerce ACL resource id for an order view button.
|
|
27
28
|
*
|
|
28
|
-
*
|
|
29
|
+
* This helper is scoped to the order entity, so no entity discriminator is needed.
|
|
29
30
|
* The id is assembled as: `getAclResourceId(metadataId)` + `"_order_viewbuttons_"` +
|
|
30
31
|
* sanitized `buttonId`. The `buttonId` is sanitized (trimmed, lowercased, non-`[a-z0-9_]` → `_`).
|
|
31
32
|
* `"Magento_CommerceBackendUix::adminuisdk_app_"` in the example is the fixed constant prefix
|
|
@@ -83,7 +84,7 @@ const OrderViewButtonRequestSchema = valibot.object({
|
|
|
83
84
|
* ```
|
|
84
85
|
*/
|
|
85
86
|
function parseOrderViewButtonRequest(input) {
|
|
86
|
-
return require_utils.parseOrThrow(OrderViewButtonRequestSchema, input, "Invalid order view button request");
|
|
87
|
+
return require_utils.parseOrThrow(OrderViewButtonRequestSchema, require_view_button_request.normalizeViewButtonWorkerParams(input), "Invalid order view button request");
|
|
87
88
|
}
|
|
88
89
|
/**
|
|
89
90
|
* Builds an HTTP 200 success response for an order view button handler.
|
|
@@ -17,7 +17,7 @@ import { ErrorResponse, SuccessResponse } from "@adobe/aio-commerce-lib-core/res
|
|
|
17
17
|
/**
|
|
18
18
|
* Derives the deterministic Commerce ACL resource id for an order view button.
|
|
19
19
|
*
|
|
20
|
-
*
|
|
20
|
+
* This helper is scoped to the order entity, so no entity discriminator is needed.
|
|
21
21
|
* The id is assembled as: `getAclResourceId(metadataId)` + `"_order_viewbuttons_"` +
|
|
22
22
|
* sanitized `buttonId`. The `buttonId` is sanitized (trimmed, lowercased, non-`[a-z0-9_]` → `_`).
|
|
23
23
|
* `"Magento_CommerceBackendUix::adminuisdk_app_"` in the example is the fixed constant prefix
|
|
@@ -0,0 +1,46 @@
|
|
|
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
|
+
const require_rolldown_runtime = require("./rolldown-runtime-DREAZOkv.cjs");
|
|
16
|
+
let valibot = require("valibot");
|
|
17
|
+
valibot = require_rolldown_runtime.__toESM(valibot, 1);
|
|
18
|
+
let _adobe_aio_commerce_lib_core_headers = require("@adobe/aio-commerce-lib-core/headers");
|
|
19
|
+
|
|
20
|
+
// source/lib/view-button-request.ts
|
|
21
|
+
const REQUEST_ID_HEADER = "x-request-id";
|
|
22
|
+
const RuntimeParamsSchema = valibot.record(valibot.string(), valibot.unknown());
|
|
23
|
+
/**
|
|
24
|
+
* Maps the params Commerce sends to a view-button worker onto the documented request shape.
|
|
25
|
+
*
|
|
26
|
+
* Commerce POSTs `{ <entityId>, buttonId }` and sends the request ID in the `X-Request-ID`
|
|
27
|
+
* header, which App Builder exposes in `__ow_headers`. Explicit `id` and `requestId` params
|
|
28
|
+
* take precedence so direct calls with the documented shape keep working. Inputs that are not
|
|
29
|
+
* runtime params are returned as-is so the entity schema reports the validation error.
|
|
30
|
+
*/
|
|
31
|
+
function normalizeViewButtonWorkerParams(input) {
|
|
32
|
+
if (!valibot.is(RuntimeParamsSchema, input)) return input;
|
|
33
|
+
const headers = input.__ow_headers === void 0 ? {} : (0, _adobe_aio_commerce_lib_core_headers.getHeadersFromParams)(input);
|
|
34
|
+
return {
|
|
35
|
+
...input,
|
|
36
|
+
id: input.id ?? input.buttonId,
|
|
37
|
+
requestId: input.requestId ?? (0, _adobe_aio_commerce_lib_core_headers.getHeader)(headers, REQUEST_ID_HEADER)
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
Object.defineProperty(exports, "normalizeViewButtonWorkerParams", {
|
|
42
|
+
enumerable: true,
|
|
43
|
+
get: function () {
|
|
44
|
+
return normalizeViewButtonWorkerParams;
|
|
45
|
+
}
|
|
46
|
+
});
|
package/dist/cjs/web/index.cjs
CHANGED
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
|
|
15
15
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
16
16
|
const require_rolldown_runtime = require("../rolldown-runtime-DREAZOkv.cjs");
|
|
17
|
+
let valibot = require("valibot");
|
|
17
18
|
let react = require("react");
|
|
18
19
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
19
20
|
let _adobe_exc_app = require("@adobe/exc-app");
|
|
@@ -37,8 +38,26 @@ let react_error_boundary = require("react-error-boundary");
|
|
|
37
38
|
* @param href - The URL to read the order ID from (typically `window.location.href`).
|
|
38
39
|
*/
|
|
39
40
|
function parseOrderId(href) {
|
|
41
|
+
return parseViewButtonId(href, "orderId");
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Extracts the invoice ID from the given absolute URL.
|
|
45
|
+
* @param href - The URL to read the invoice ID from (typically `window.location.href`).
|
|
46
|
+
*/
|
|
47
|
+
function parseInvoiceId(href) {
|
|
48
|
+
return parseViewButtonId(href, "invoiceId");
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Extracts the credit memo ID from the given absolute URL.
|
|
52
|
+
* @param href - The URL to read the credit memo ID from (typically `window.location.href`).
|
|
53
|
+
*/
|
|
54
|
+
function parseCreditMemoId(href) {
|
|
55
|
+
return parseViewButtonId(href, "creditMemoId");
|
|
56
|
+
}
|
|
57
|
+
/** Reads a view-button identifier from the URL search parameters or hash-route query. */
|
|
58
|
+
function parseViewButtonId(href, key) {
|
|
40
59
|
const urlObj = new URL(href);
|
|
41
|
-
return urlObj.searchParams.get(
|
|
60
|
+
return urlObj.searchParams.get(key) ?? new URLSearchParams(urlObj.hash.split("?").at(1)).get(key);
|
|
42
61
|
}
|
|
43
62
|
/** Whether the app is embedded in a host frame (the Commerce Admin or the Experience Cloud shell). */
|
|
44
63
|
function isEmbeddedInHost() {
|
|
@@ -258,6 +277,7 @@ function useCommerce() {
|
|
|
258
277
|
}
|
|
259
278
|
|
|
260
279
|
// source/web/react/commerce/hooks/use-extension-context.ts
|
|
280
|
+
const ContextIdSchema = (0, valibot.union)([(0, valibot.string)(), (0, valibot.pipe)((0, valibot.number)(), (0, valibot.finite)())]);
|
|
261
281
|
/**
|
|
262
282
|
* Returns the context for a mass-action extension point: the selected row IDs the action was
|
|
263
283
|
* triggered with. The value is read from the host-provided Commerce context.
|
|
@@ -289,6 +309,74 @@ function useOrderViewButtonContext() {
|
|
|
289
309
|
return ok({ orderId });
|
|
290
310
|
}, []);
|
|
291
311
|
}
|
|
312
|
+
/**
|
|
313
|
+
* Returns the customer identifier from the Commerce shared context as a string.
|
|
314
|
+
* Numeric identifiers are converted to strings; existing strings retain leading zeros.
|
|
315
|
+
*
|
|
316
|
+
* Returns an error outside the Commerce shared context or when the customer identifier is
|
|
317
|
+
* missing, null, or not a string or finite number. The store identifier is not required.
|
|
318
|
+
*/
|
|
319
|
+
function useCustomerContext() {
|
|
320
|
+
const { data, error: contextError } = useSharedContext();
|
|
321
|
+
return (0, react.useMemo)(() => {
|
|
322
|
+
if (contextError) return error(contextError.message, { cause: contextError });
|
|
323
|
+
const customerId = data.sharedContext.get("customerId");
|
|
324
|
+
if (!(0, valibot.is)(ContextIdSchema, customerId)) return error("The Commerce shared context value \"customerId\" must be a string or finite number.");
|
|
325
|
+
return ok({ customerId: String(customerId) });
|
|
326
|
+
}, [data, contextError]);
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Returns the store identifier from the Commerce shared context as a string.
|
|
330
|
+
* Numeric identifiers are converted to strings; existing strings retain leading zeros.
|
|
331
|
+
*
|
|
332
|
+
* Returns an error outside the Commerce shared context or when the store identifier is
|
|
333
|
+
* missing, null, or not a string or finite number. The customer identifier is not required.
|
|
334
|
+
*/
|
|
335
|
+
function useStoreContext() {
|
|
336
|
+
const { data, error: contextError } = useSharedContext();
|
|
337
|
+
return (0, react.useMemo)(() => {
|
|
338
|
+
if (contextError) return error(contextError.message, { cause: contextError });
|
|
339
|
+
const storeId = data.sharedContext.get("storeId");
|
|
340
|
+
if (!(0, valibot.is)(ContextIdSchema, storeId)) return error("The Commerce shared context value \"storeId\" must be a string or finite number.");
|
|
341
|
+
return ok({ storeId: String(storeId) });
|
|
342
|
+
}, [data, contextError]);
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Returns the invoice ID for an invoice view-button extension point.
|
|
346
|
+
* Reads `invoiceId` from the page URL search parameters or hash-route query.
|
|
347
|
+
* Returns an error when the invoice ID is missing or blank.
|
|
348
|
+
* @example
|
|
349
|
+
* ```tsx
|
|
350
|
+
* const { data, error } = useInvoiceViewButtonContext();
|
|
351
|
+
* if (error) throw error;
|
|
352
|
+
* return <span>{data.invoiceId}</span>;
|
|
353
|
+
* ```
|
|
354
|
+
*/
|
|
355
|
+
function useInvoiceViewButtonContext() {
|
|
356
|
+
return (0, react.useMemo)(() => {
|
|
357
|
+
const invoiceId = parseInvoiceId(globalThis.location.href);
|
|
358
|
+
if (invoiceId === null || invoiceId.trim() === "") return error("Could not find an invoice ID. Is this frame running as an invoice view-button extension point?");
|
|
359
|
+
return ok({ invoiceId });
|
|
360
|
+
}, []);
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* Returns the credit memo ID for a credit memo view-button extension point.
|
|
364
|
+
* Reads `creditMemoId` from the page URL search parameters or hash-route query.
|
|
365
|
+
* Returns an error when the credit memo ID is missing or blank.
|
|
366
|
+
* @example
|
|
367
|
+
* ```tsx
|
|
368
|
+
* const { data, error } = useCreditMemoViewButtonContext();
|
|
369
|
+
* if (error) throw error;
|
|
370
|
+
* return <span>{data.creditMemoId}</span>;
|
|
371
|
+
* ```
|
|
372
|
+
*/
|
|
373
|
+
function useCreditMemoViewButtonContext() {
|
|
374
|
+
return (0, react.useMemo)(() => {
|
|
375
|
+
const creditMemoId = parseCreditMemoId(globalThis.location.href);
|
|
376
|
+
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?");
|
|
377
|
+
return ok({ creditMemoId });
|
|
378
|
+
}, []);
|
|
379
|
+
}
|
|
292
380
|
|
|
293
381
|
// source/web/react/commerce/hooks/use-host-connection.ts
|
|
294
382
|
/**
|
|
@@ -854,8 +942,12 @@ function createExtensionApp({ menu, metadata, routes = [], root: customRoot }) {
|
|
|
854
942
|
|
|
855
943
|
exports.createExtensionApp = createExtensionApp;
|
|
856
944
|
exports.useCommerce = useCommerce;
|
|
945
|
+
exports.useCreditMemoViewButtonContext = useCreditMemoViewButtonContext;
|
|
946
|
+
exports.useCustomerContext = useCustomerContext;
|
|
857
947
|
exports.useHostConnection = useHostConnection;
|
|
858
948
|
exports.useIms = useIms;
|
|
949
|
+
exports.useInvoiceViewButtonContext = useInvoiceViewButtonContext;
|
|
859
950
|
exports.useMassActionContext = useMassActionContext;
|
|
860
951
|
exports.useOrderViewButtonContext = useOrderViewButtonContext;
|
|
861
|
-
exports.useSharedContext = useSharedContext;
|
|
952
|
+
exports.useSharedContext = useSharedContext;
|
|
953
|
+
exports.useStoreContext = useStoreContext;
|
package/dist/cjs/web/index.d.cts
CHANGED
|
@@ -65,7 +65,7 @@ type SharedContext = {
|
|
|
65
65
|
};
|
|
66
66
|
/** Actions for closing the extension iframe and returning control to the Commerce Admin. */
|
|
67
67
|
type HostConnection = {
|
|
68
|
-
/** Closes the iframe and navigates back to the originating grid or
|
|
68
|
+
/** Closes the iframe and navigates back to the originating grid or detail page. */
|
|
69
69
|
close: () => Promise<void>;
|
|
70
70
|
/** Closes the iframe and navigates back, flagging the originating page that an error occurred. */
|
|
71
71
|
closeWithError: () => Promise<void>;
|
|
@@ -78,6 +78,22 @@ type MassActionContext = {
|
|
|
78
78
|
type OrderViewButtonContext = {
|
|
79
79
|
orderId: string;
|
|
80
80
|
};
|
|
81
|
+
/** The customer identifier provided by the Commerce shared context. */
|
|
82
|
+
type CustomerContext = {
|
|
83
|
+
customerId: string;
|
|
84
|
+
};
|
|
85
|
+
/** The store identifier provided by the Commerce shared context. */
|
|
86
|
+
type StoreContext = {
|
|
87
|
+
storeId: string;
|
|
88
|
+
};
|
|
89
|
+
/** The context shared with invoice view-button extension points. */
|
|
90
|
+
type InvoiceViewButtonContext = {
|
|
91
|
+
invoiceId: string;
|
|
92
|
+
};
|
|
93
|
+
/** The context shared with credit memo view-button extension points. */
|
|
94
|
+
type CreditMemoViewButtonContext = {
|
|
95
|
+
creditMemoId: string;
|
|
96
|
+
};
|
|
81
97
|
/**
|
|
82
98
|
* Returns the current Commerce shared context. The guest connection is already established by
|
|
83
99
|
* the time this can be called (see {@link SharedContextProvider}).
|
|
@@ -124,6 +140,46 @@ export declare function useMassActionContext(): Result<MassActionContext>;
|
|
|
124
140
|
* Returns an error when no order ID is present in the page URL.
|
|
125
141
|
*/
|
|
126
142
|
export declare function useOrderViewButtonContext(): Result<OrderViewButtonContext>;
|
|
143
|
+
/**
|
|
144
|
+
* Returns the customer identifier from the Commerce shared context as a string.
|
|
145
|
+
* Numeric identifiers are converted to strings; existing strings retain leading zeros.
|
|
146
|
+
*
|
|
147
|
+
* Returns an error outside the Commerce shared context or when the customer identifier is
|
|
148
|
+
* missing, null, or not a string or finite number. The store identifier is not required.
|
|
149
|
+
*/
|
|
150
|
+
export declare function useCustomerContext(): Result<CustomerContext>;
|
|
151
|
+
/**
|
|
152
|
+
* Returns the store identifier from the Commerce shared context as a string.
|
|
153
|
+
* Numeric identifiers are converted to strings; existing strings retain leading zeros.
|
|
154
|
+
*
|
|
155
|
+
* Returns an error outside the Commerce shared context or when the store identifier is
|
|
156
|
+
* missing, null, or not a string or finite number. The customer identifier is not required.
|
|
157
|
+
*/
|
|
158
|
+
export declare function useStoreContext(): Result<StoreContext>;
|
|
159
|
+
/**
|
|
160
|
+
* Returns the invoice ID for an invoice view-button extension point.
|
|
161
|
+
* Reads `invoiceId` from the page URL search parameters or hash-route query.
|
|
162
|
+
* Returns an error when the invoice ID is missing or blank.
|
|
163
|
+
* @example
|
|
164
|
+
* ```tsx
|
|
165
|
+
* const { data, error } = useInvoiceViewButtonContext();
|
|
166
|
+
* if (error) throw error;
|
|
167
|
+
* return <span>{data.invoiceId}</span>;
|
|
168
|
+
* ```
|
|
169
|
+
*/
|
|
170
|
+
export declare function useInvoiceViewButtonContext(): Result<InvoiceViewButtonContext>;
|
|
171
|
+
/**
|
|
172
|
+
* Returns the credit memo ID for a credit memo view-button extension point.
|
|
173
|
+
* Reads `creditMemoId` from the page URL search parameters or hash-route query.
|
|
174
|
+
* Returns an error when the credit memo ID is missing or blank.
|
|
175
|
+
* @example
|
|
176
|
+
* ```tsx
|
|
177
|
+
* const { data, error } = useCreditMemoViewButtonContext();
|
|
178
|
+
* if (error) throw error;
|
|
179
|
+
* return <span>{data.creditMemoId}</span>;
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
182
|
+
export declare function useCreditMemoViewButtonContext(): Result<CreditMemoViewButtonContext>;
|
|
127
183
|
/**
|
|
128
184
|
* Returns typed helpers for interacting with the Commerce Admin host.
|
|
129
185
|
*
|
|
@@ -190,4 +246,4 @@ type CreateExtensionAppOptions = {
|
|
|
190
246
|
* ```
|
|
191
247
|
*/
|
|
192
248
|
export declare function createExtensionApp({ menu, metadata, routes, root: customRoot }: CreateExtensionAppOptions): void;
|
|
193
|
-
export type { CreateExtensionAppOptions, ExtensionRoute, HostConnection, ImsContext, MassActionContext, OrderViewButtonContext, SharedContext };
|
|
249
|
+
export type { CreateExtensionAppOptions, CreditMemoViewButtonContext, CustomerContext, ExtensionRoute, HostConnection, ImsContext, InvoiceViewButtonContext, MassActionContext, OrderViewButtonContext, SharedContext, StoreContext };
|
|
@@ -0,0 +1,70 @@
|
|
|
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 { ErrorResponse, SuccessResponse } from "@adobe/aio-commerce-lib-core/responses";
|
|
17
|
+
/**
|
|
18
|
+
* Derives the Commerce ACL resource ID for a credit memo view button.
|
|
19
|
+
* App and button IDs are trimmed, lowercased, and sanitized independently.
|
|
20
|
+
*
|
|
21
|
+
* @param metadataId - The application's `metadata.id` value.
|
|
22
|
+
* @param buttonId - The button's `adminUi.creditMemo.viewButtons[].id` value.
|
|
23
|
+
* @returns The credit memo view-button leaf ID, or an empty string when `metadataId` is blank.
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* getCreditMemoViewButtonAclResourceId("refund-app", "refund-offline");
|
|
27
|
+
* // "Magento_CommerceBackendUix::adminuisdk_app_refund_app_creditmemo_viewbuttons_refund_offline"
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export declare function getCreditMemoViewButtonAclResourceId(metadataId: string, buttonId: string): string;
|
|
31
|
+
/**
|
|
32
|
+
* Schema for a credit memo view-button worker request.
|
|
33
|
+
* `id` identifies the clicked button; `creditMemoId` identifies the credit memo being viewed.
|
|
34
|
+
* All three fields must be non-empty strings.
|
|
35
|
+
*/
|
|
36
|
+
export declare const CreditMemoViewButtonRequestSchema: v.ObjectSchema<{
|
|
37
|
+
readonly creditMemoId: v.SchemaWithPipe<readonly [v.StringSchema<`Expected a string value for '${string}'`>, v.NonEmptyAction<string, `The value of "${string}" must not be empty`>]>;
|
|
38
|
+
readonly id: v.SchemaWithPipe<readonly [v.StringSchema<`Expected a string value for '${string}'`>, v.NonEmptyAction<string, `The value of "${string}" must not be empty`>]>;
|
|
39
|
+
readonly requestId: v.SchemaWithPipe<readonly [v.StringSchema<`Expected a string value for '${string}'`>, v.NonEmptyAction<string, `The value of "${string}" must not be empty`>]>;
|
|
40
|
+
}, undefined>;
|
|
41
|
+
/** Parsed request body for a credit memo view-button worker. */
|
|
42
|
+
type CreditMemoViewButtonRequest = v.InferOutput<typeof CreditMemoViewButtonRequestSchema>;
|
|
43
|
+
/** Empty success body returned by a credit memo view-button worker. */
|
|
44
|
+
type CreditMemoViewButtonSuccessBody = Record<string, never>;
|
|
45
|
+
/** Error body returned by a credit memo view-button worker. */
|
|
46
|
+
type CreditMemoViewButtonErrorBody = {
|
|
47
|
+
message: string;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Parses a credit memo view-button worker request.
|
|
51
|
+
* Throws `CommerceSdkValidationError` when the input is malformed.
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* const { requestId, id, creditMemoId } = parseCreditMemoViewButtonRequest(params);
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export declare function parseCreditMemoViewButtonRequest(input: unknown): CreditMemoViewButtonRequest;
|
|
58
|
+
/** Builds an HTTP 200 response with an empty body for a credit memo view-button worker. */
|
|
59
|
+
export declare function okCreditMemoViewButtonResponse(): SuccessResponse<CreditMemoViewButtonSuccessBody>;
|
|
60
|
+
/**
|
|
61
|
+
* Builds an error response for a credit memo view-button worker.
|
|
62
|
+
* @param statusCode - The HTTP status code to return.
|
|
63
|
+
* @param errorMessage - The message included in the response body.
|
|
64
|
+
* @example
|
|
65
|
+
* ```ts
|
|
66
|
+
* return creditMemoViewButtonErrorResponse(500, "Could not refund the credit memo");
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
export declare function creditMemoViewButtonErrorResponse(statusCode: number, errorMessage: string): ErrorResponse<CreditMemoViewButtonErrorBody>;
|
|
70
|
+
export type { CreditMemoViewButtonErrorBody, CreditMemoViewButtonRequest, CreditMemoViewButtonSuccessBody };
|
|
@@ -0,0 +1,83 @@
|
|
|
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 { a as sanitizeSegment, r as getAclResourceId } from "../acl-resource-id-C4Is2i_h.mjs";
|
|
16
|
+
import { t as parseOrThrow } from "../utils-G-EDWmew.mjs";
|
|
17
|
+
import { t as normalizeViewButtonWorkerParams } from "../view-button-request-Cu7Qz7jY.mjs";
|
|
18
|
+
import { t as nonEmptyStringValueSchema } from "../schemas-Dftlsf98.mjs";
|
|
19
|
+
import * as v from "valibot";
|
|
20
|
+
import { buildErrorResponse, ok } from "@adobe/aio-commerce-lib-core/responses";
|
|
21
|
+
|
|
22
|
+
// source/credit-memo-view-buttons/acl-resource-id.ts
|
|
23
|
+
/**
|
|
24
|
+
* Derives the Commerce ACL resource ID for a credit memo view button.
|
|
25
|
+
* App and button IDs are trimmed, lowercased, and sanitized independently.
|
|
26
|
+
*
|
|
27
|
+
* @param metadataId - The application's `metadata.id` value.
|
|
28
|
+
* @param buttonId - The button's `adminUi.creditMemo.viewButtons[].id` value.
|
|
29
|
+
* @returns The credit memo view-button leaf ID, or an empty string when `metadataId` is blank.
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* getCreditMemoViewButtonAclResourceId("refund-app", "refund-offline");
|
|
33
|
+
* // "Magento_CommerceBackendUix::adminuisdk_app_refund_app_creditmemo_viewbuttons_refund_offline"
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
function getCreditMemoViewButtonAclResourceId(metadataId, buttonId) {
|
|
37
|
+
const appRoot = getAclResourceId(metadataId);
|
|
38
|
+
if (appRoot === "") return "";
|
|
39
|
+
return `${appRoot}_creditmemo_viewbuttons_${sanitizeSegment(buttonId)}`;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// source/credit-memo-view-buttons/schema.ts
|
|
43
|
+
/**
|
|
44
|
+
* Schema for a credit memo view-button worker request.
|
|
45
|
+
* `id` identifies the clicked button; `creditMemoId` identifies the credit memo being viewed.
|
|
46
|
+
* All three fields must be non-empty strings.
|
|
47
|
+
*/
|
|
48
|
+
const CreditMemoViewButtonRequestSchema = v.object({
|
|
49
|
+
creditMemoId: nonEmptyStringValueSchema("creditMemoId"),
|
|
50
|
+
id: nonEmptyStringValueSchema("id"),
|
|
51
|
+
requestId: nonEmptyStringValueSchema("requestId")
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// source/credit-memo-view-buttons/presets.ts
|
|
55
|
+
/**
|
|
56
|
+
* Parses a credit memo view-button worker request.
|
|
57
|
+
* Throws `CommerceSdkValidationError` when the input is malformed.
|
|
58
|
+
* @example
|
|
59
|
+
* ```ts
|
|
60
|
+
* const { requestId, id, creditMemoId } = parseCreditMemoViewButtonRequest(params);
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
function parseCreditMemoViewButtonRequest(input) {
|
|
64
|
+
return parseOrThrow(CreditMemoViewButtonRequestSchema, normalizeViewButtonWorkerParams(input), "Invalid credit memo view button request");
|
|
65
|
+
}
|
|
66
|
+
/** Builds an HTTP 200 response with an empty body for a credit memo view-button worker. */
|
|
67
|
+
function okCreditMemoViewButtonResponse() {
|
|
68
|
+
return ok({ body: {} });
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Builds an error response for a credit memo view-button worker.
|
|
72
|
+
* @param statusCode - The HTTP status code to return.
|
|
73
|
+
* @param errorMessage - The message included in the response body.
|
|
74
|
+
* @example
|
|
75
|
+
* ```ts
|
|
76
|
+
* return creditMemoViewButtonErrorResponse(500, "Could not refund the credit memo");
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
function creditMemoViewButtonErrorResponse(statusCode, errorMessage) {
|
|
80
|
+
return buildErrorResponse(statusCode, { body: { message: errorMessage } });
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export { CreditMemoViewButtonRequestSchema, creditMemoViewButtonErrorResponse, getCreditMemoViewButtonAclResourceId, okCreditMemoViewButtonResponse, parseCreditMemoViewButtonRequest };
|
|
@@ -0,0 +1,70 @@
|
|
|
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 { ErrorResponse, SuccessResponse } from "@adobe/aio-commerce-lib-core/responses";
|
|
17
|
+
/**
|
|
18
|
+
* Derives the Commerce ACL resource ID for an invoice view button.
|
|
19
|
+
* App and button IDs are trimmed, lowercased, and sanitized independently.
|
|
20
|
+
*
|
|
21
|
+
* @param metadataId - The application's `metadata.id` value.
|
|
22
|
+
* @param buttonId - The button's `adminUi.invoice.viewButtons[].id` value.
|
|
23
|
+
* @returns The invoice view-button leaf ID, or an empty string when `metadataId` is blank.
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* getInvoiceViewButtonAclResourceId("billing-app", "export-invoice");
|
|
27
|
+
* // "Magento_CommerceBackendUix::adminuisdk_app_billing_app_invoice_viewbuttons_export_invoice"
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export declare function getInvoiceViewButtonAclResourceId(metadataId: string, buttonId: string): string;
|
|
31
|
+
/**
|
|
32
|
+
* Schema for an invoice view-button worker request.
|
|
33
|
+
* `id` identifies the clicked button; `invoiceId` identifies the invoice being viewed.
|
|
34
|
+
* All three fields must be non-empty strings.
|
|
35
|
+
*/
|
|
36
|
+
export declare const InvoiceViewButtonRequestSchema: v.ObjectSchema<{
|
|
37
|
+
readonly id: v.SchemaWithPipe<readonly [v.StringSchema<`Expected a string value for '${string}'`>, v.NonEmptyAction<string, `The value of "${string}" must not be empty`>]>;
|
|
38
|
+
readonly invoiceId: v.SchemaWithPipe<readonly [v.StringSchema<`Expected a string value for '${string}'`>, v.NonEmptyAction<string, `The value of "${string}" must not be empty`>]>;
|
|
39
|
+
readonly requestId: v.SchemaWithPipe<readonly [v.StringSchema<`Expected a string value for '${string}'`>, v.NonEmptyAction<string, `The value of "${string}" must not be empty`>]>;
|
|
40
|
+
}, undefined>;
|
|
41
|
+
/** Parsed request body for an invoice view-button worker. */
|
|
42
|
+
type InvoiceViewButtonRequest = v.InferOutput<typeof InvoiceViewButtonRequestSchema>;
|
|
43
|
+
/** Empty success body returned by an invoice view-button worker. */
|
|
44
|
+
type InvoiceViewButtonSuccessBody = Record<string, never>;
|
|
45
|
+
/** Error body returned by an invoice view-button worker. */
|
|
46
|
+
type InvoiceViewButtonErrorBody = {
|
|
47
|
+
message: string;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Parses an invoice view-button worker request.
|
|
51
|
+
* Throws `CommerceSdkValidationError` when the input is malformed.
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* const { requestId, id, invoiceId } = parseInvoiceViewButtonRequest(params);
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export declare function parseInvoiceViewButtonRequest(input: unknown): InvoiceViewButtonRequest;
|
|
58
|
+
/** Builds an HTTP 200 response with an empty body for an invoice view-button worker. */
|
|
59
|
+
export declare function okInvoiceViewButtonResponse(): SuccessResponse<InvoiceViewButtonSuccessBody>;
|
|
60
|
+
/**
|
|
61
|
+
* Builds an error response for an invoice view-button worker.
|
|
62
|
+
* @param statusCode - The HTTP status code to return.
|
|
63
|
+
* @param errorMessage - The message included in the response body.
|
|
64
|
+
* @example
|
|
65
|
+
* ```ts
|
|
66
|
+
* return invoiceViewButtonErrorResponse(500, "Could not export the invoice");
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
export declare function invoiceViewButtonErrorResponse(statusCode: number, errorMessage: string): ErrorResponse<InvoiceViewButtonErrorBody>;
|
|
70
|
+
export type { InvoiceViewButtonErrorBody, InvoiceViewButtonRequest, InvoiceViewButtonSuccessBody };
|
|
@@ -0,0 +1,83 @@
|
|
|
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 { a as sanitizeSegment, r as getAclResourceId } from "../acl-resource-id-C4Is2i_h.mjs";
|
|
16
|
+
import { t as parseOrThrow } from "../utils-G-EDWmew.mjs";
|
|
17
|
+
import { t as normalizeViewButtonWorkerParams } from "../view-button-request-Cu7Qz7jY.mjs";
|
|
18
|
+
import { t as nonEmptyStringValueSchema } from "../schemas-Dftlsf98.mjs";
|
|
19
|
+
import * as v from "valibot";
|
|
20
|
+
import { buildErrorResponse, ok } from "@adobe/aio-commerce-lib-core/responses";
|
|
21
|
+
|
|
22
|
+
// source/invoice-view-buttons/acl-resource-id.ts
|
|
23
|
+
/**
|
|
24
|
+
* Derives the Commerce ACL resource ID for an invoice view button.
|
|
25
|
+
* App and button IDs are trimmed, lowercased, and sanitized independently.
|
|
26
|
+
*
|
|
27
|
+
* @param metadataId - The application's `metadata.id` value.
|
|
28
|
+
* @param buttonId - The button's `adminUi.invoice.viewButtons[].id` value.
|
|
29
|
+
* @returns The invoice view-button leaf ID, or an empty string when `metadataId` is blank.
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* getInvoiceViewButtonAclResourceId("billing-app", "export-invoice");
|
|
33
|
+
* // "Magento_CommerceBackendUix::adminuisdk_app_billing_app_invoice_viewbuttons_export_invoice"
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
function getInvoiceViewButtonAclResourceId(metadataId, buttonId) {
|
|
37
|
+
const appRoot = getAclResourceId(metadataId);
|
|
38
|
+
if (appRoot === "") return "";
|
|
39
|
+
return `${appRoot}_invoice_viewbuttons_${sanitizeSegment(buttonId)}`;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// source/invoice-view-buttons/schema.ts
|
|
43
|
+
/**
|
|
44
|
+
* Schema for an invoice view-button worker request.
|
|
45
|
+
* `id` identifies the clicked button; `invoiceId` identifies the invoice being viewed.
|
|
46
|
+
* All three fields must be non-empty strings.
|
|
47
|
+
*/
|
|
48
|
+
const InvoiceViewButtonRequestSchema = v.object({
|
|
49
|
+
id: nonEmptyStringValueSchema("id"),
|
|
50
|
+
invoiceId: nonEmptyStringValueSchema("invoiceId"),
|
|
51
|
+
requestId: nonEmptyStringValueSchema("requestId")
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// source/invoice-view-buttons/presets.ts
|
|
55
|
+
/**
|
|
56
|
+
* Parses an invoice view-button worker request.
|
|
57
|
+
* Throws `CommerceSdkValidationError` when the input is malformed.
|
|
58
|
+
* @example
|
|
59
|
+
* ```ts
|
|
60
|
+
* const { requestId, id, invoiceId } = parseInvoiceViewButtonRequest(params);
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
function parseInvoiceViewButtonRequest(input) {
|
|
64
|
+
return parseOrThrow(InvoiceViewButtonRequestSchema, normalizeViewButtonWorkerParams(input), "Invalid invoice view button request");
|
|
65
|
+
}
|
|
66
|
+
/** Builds an HTTP 200 response with an empty body for an invoice view-button worker. */
|
|
67
|
+
function okInvoiceViewButtonResponse() {
|
|
68
|
+
return ok({ body: {} });
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Builds an error response for an invoice view-button worker.
|
|
72
|
+
* @param statusCode - The HTTP status code to return.
|
|
73
|
+
* @param errorMessage - The message included in the response body.
|
|
74
|
+
* @example
|
|
75
|
+
* ```ts
|
|
76
|
+
* return invoiceViewButtonErrorResponse(500, "Could not export the invoice");
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
function invoiceViewButtonErrorResponse(statusCode, errorMessage) {
|
|
80
|
+
return buildErrorResponse(statusCode, { body: { message: errorMessage } });
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export { InvoiceViewButtonRequestSchema, getInvoiceViewButtonAclResourceId, invoiceViewButtonErrorResponse, okInvoiceViewButtonResponse, parseInvoiceViewButtonRequest };
|
|
@@ -17,7 +17,7 @@ import { ErrorResponse, SuccessResponse } from "@adobe/aio-commerce-lib-core/res
|
|
|
17
17
|
/**
|
|
18
18
|
* Derives the deterministic Commerce ACL resource id for an order view button.
|
|
19
19
|
*
|
|
20
|
-
*
|
|
20
|
+
* This helper is scoped to the order entity, so no entity discriminator is needed.
|
|
21
21
|
* The id is assembled as: `getAclResourceId(metadataId)` + `"_order_viewbuttons_"` +
|
|
22
22
|
* sanitized `buttonId`. The `buttonId` is sanitized (trimmed, lowercased, non-`[a-z0-9_]` → `_`).
|
|
23
23
|
* `"Magento_CommerceBackendUix::adminuisdk_app_"` in the example is the fixed constant prefix
|
|
@@ -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
|
-
*
|
|
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 };
|
package/dist/es/web/index.d.mts
CHANGED
|
@@ -65,7 +65,7 @@ type SharedContext = {
|
|
|
65
65
|
};
|
|
66
66
|
/** Actions for closing the extension iframe and returning control to the Commerce Admin. */
|
|
67
67
|
type HostConnection = {
|
|
68
|
-
/** Closes the iframe and navigates back to the originating grid or
|
|
68
|
+
/** Closes the iframe and navigates back to the originating grid or detail page. */
|
|
69
69
|
close: () => Promise<void>;
|
|
70
70
|
/** Closes the iframe and navigates back, flagging the originating page that an error occurred. */
|
|
71
71
|
closeWithError: () => Promise<void>;
|
|
@@ -78,6 +78,22 @@ type MassActionContext = {
|
|
|
78
78
|
type OrderViewButtonContext = {
|
|
79
79
|
orderId: string;
|
|
80
80
|
};
|
|
81
|
+
/** The customer identifier provided by the Commerce shared context. */
|
|
82
|
+
type CustomerContext = {
|
|
83
|
+
customerId: string;
|
|
84
|
+
};
|
|
85
|
+
/** The store identifier provided by the Commerce shared context. */
|
|
86
|
+
type StoreContext = {
|
|
87
|
+
storeId: string;
|
|
88
|
+
};
|
|
89
|
+
/** The context shared with invoice view-button extension points. */
|
|
90
|
+
type InvoiceViewButtonContext = {
|
|
91
|
+
invoiceId: string;
|
|
92
|
+
};
|
|
93
|
+
/** The context shared with credit memo view-button extension points. */
|
|
94
|
+
type CreditMemoViewButtonContext = {
|
|
95
|
+
creditMemoId: string;
|
|
96
|
+
};
|
|
81
97
|
/**
|
|
82
98
|
* Returns the current Commerce shared context. The guest connection is already established by
|
|
83
99
|
* the time this can be called (see {@link SharedContextProvider}).
|
|
@@ -124,6 +140,46 @@ export declare function useMassActionContext(): Result<MassActionContext>;
|
|
|
124
140
|
* Returns an error when no order ID is present in the page URL.
|
|
125
141
|
*/
|
|
126
142
|
export declare function useOrderViewButtonContext(): Result<OrderViewButtonContext>;
|
|
143
|
+
/**
|
|
144
|
+
* Returns the customer identifier from the Commerce shared context as a string.
|
|
145
|
+
* Numeric identifiers are converted to strings; existing strings retain leading zeros.
|
|
146
|
+
*
|
|
147
|
+
* Returns an error outside the Commerce shared context or when the customer identifier is
|
|
148
|
+
* missing, null, or not a string or finite number. The store identifier is not required.
|
|
149
|
+
*/
|
|
150
|
+
export declare function useCustomerContext(): Result<CustomerContext>;
|
|
151
|
+
/**
|
|
152
|
+
* Returns the store identifier from the Commerce shared context as a string.
|
|
153
|
+
* Numeric identifiers are converted to strings; existing strings retain leading zeros.
|
|
154
|
+
*
|
|
155
|
+
* Returns an error outside the Commerce shared context or when the store identifier is
|
|
156
|
+
* missing, null, or not a string or finite number. The customer identifier is not required.
|
|
157
|
+
*/
|
|
158
|
+
export declare function useStoreContext(): Result<StoreContext>;
|
|
159
|
+
/**
|
|
160
|
+
* Returns the invoice ID for an invoice view-button extension point.
|
|
161
|
+
* Reads `invoiceId` from the page URL search parameters or hash-route query.
|
|
162
|
+
* Returns an error when the invoice ID is missing or blank.
|
|
163
|
+
* @example
|
|
164
|
+
* ```tsx
|
|
165
|
+
* const { data, error } = useInvoiceViewButtonContext();
|
|
166
|
+
* if (error) throw error;
|
|
167
|
+
* return <span>{data.invoiceId}</span>;
|
|
168
|
+
* ```
|
|
169
|
+
*/
|
|
170
|
+
export declare function useInvoiceViewButtonContext(): Result<InvoiceViewButtonContext>;
|
|
171
|
+
/**
|
|
172
|
+
* Returns the credit memo ID for a credit memo view-button extension point.
|
|
173
|
+
* Reads `creditMemoId` from the page URL search parameters or hash-route query.
|
|
174
|
+
* Returns an error when the credit memo ID is missing or blank.
|
|
175
|
+
* @example
|
|
176
|
+
* ```tsx
|
|
177
|
+
* const { data, error } = useCreditMemoViewButtonContext();
|
|
178
|
+
* if (error) throw error;
|
|
179
|
+
* return <span>{data.creditMemoId}</span>;
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
182
|
+
export declare function useCreditMemoViewButtonContext(): Result<CreditMemoViewButtonContext>;
|
|
127
183
|
/**
|
|
128
184
|
* Returns typed helpers for interacting with the Commerce Admin host.
|
|
129
185
|
*
|
|
@@ -190,4 +246,4 @@ type CreateExtensionAppOptions = {
|
|
|
190
246
|
* ```
|
|
191
247
|
*/
|
|
192
248
|
export declare function createExtensionApp({ menu, metadata, routes, root: customRoot }: CreateExtensionAppOptions): void;
|
|
193
|
-
export type { CreateExtensionAppOptions, ExtensionRoute, HostConnection, ImsContext, MassActionContext, OrderViewButtonContext, SharedContext };
|
|
249
|
+
export type { CreateExtensionAppOptions, CreditMemoViewButtonContext, CustomerContext, ExtensionRoute, HostConnection, ImsContext, InvoiceViewButtonContext, MassActionContext, OrderViewButtonContext, SharedContext, StoreContext };
|
package/dist/es/web/index.mjs
CHANGED
|
@@ -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(
|
|
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.
|
|
3
|
+
"version": "1.3.0-beta-20261105172845",
|
|
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",
|