/** * @license * * Copyright 2026 Adobe. All rights reserved. * This file is licensed to you under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. You may obtain a copy * of the License at http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software distributed under * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS * OF ANY KIND, either express or implied. See the License for the specific language * governing permissions and limitations under the License. */ import * as v from "valibot"; import { ErrorResponse, SuccessResponse } from "@adobe/aio-commerce-lib-core/responses"; //#region source/order-view-buttons/acl-resource-id.d.ts /** * Derives the deterministic Commerce ACL resource id for an order view button. * * View buttons exist only on the order entity, so no entity discriminator is needed. * The id is assembled as: `getAclResourceId(metadataId)` + `"_order_viewbuttons_"` + * sanitized `buttonId`. The `buttonId` is sanitized (trimmed, lowercased, non-`[a-z0-9_]` → `_`). * `"Magento_CommerceBackendUix::adminuisdk_app_"` in the example is the fixed constant prefix * (not a placeholder), and `"_order_viewbuttons_"` is the literal keyword separator for this component: * * @example * ``` * getOrderViewButtonAclResourceId("approval-dashboard-app", "approve-order") * // getAclResourceId("approval-dashboard-app") + "_order_viewbuttons_" + sanitize("approve-order") * // "Magento_CommerceBackendUix::adminuisdk_app_approval_dashboard_app" + "_order_viewbuttons_" + "approve_order" * // → "Magento_CommerceBackendUix::adminuisdk_app_approval_dashboard_app_order_viewbuttons_approve_order" * ``` * * @param metadataId - The application's `metadata.id` value (e.g. `"approval-dashboard-app"`). * @param buttonId - The button's `id` value from `adminUi.order.viewButtons[].id`. * @returns The full Commerce ACL resource id for the view-button leaf node, or an empty string * when `metadataId` is blank. */ declare function getOrderViewButtonAclResourceId(metadataId: string, buttonId: string): string; //#endregion //#region source/order-view-buttons/schema.d.ts /** * Schema for the JSON body Commerce POSTs to an order view button handler. * * `id` identifies the specific button that was clicked, letting a single * handler serve multiple buttons by branching on it. `orderId` is the * single order currently being viewed. */ declare const OrderViewButtonRequestSchema: v.ObjectSchema<{ readonly id: v.SchemaWithPipe, v.NonEmptyAction]>; readonly orderId: v.SchemaWithPipe, v.NonEmptyAction]>; readonly requestId: v.SchemaWithPipe, v.NonEmptyAction]>; }, undefined>; //#endregion //#region source/order-view-buttons/types.d.ts /** Parsed request body sent by Commerce to an order view button handler. */ type OrderViewButtonRequest = v.InferOutput; /** Success body returned to Commerce — an empty object signals success. */ type OrderViewButtonSuccessBody = Record; /** Failure body returned to Commerce when a worker order view button handler fails. */ type OrderViewButtonErrorBody = { message: string; }; //#endregion //#region source/order-view-buttons/presets.d.ts /** * Parses and validates the JSON body Commerce POSTs to an order view button handler. * * Throws a `CommerceSdkValidationError` if the input is malformed. * * @example * ```ts * import { parseOrderViewButtonRequest } from "@adobe/aio-commerce-lib-admin-ui/order-view-buttons"; * * export async function main(params: unknown) { * const { requestId, id, orderId } = parseOrderViewButtonRequest(params); * // id identifies which button was clicked * // orderId is the order currently being viewed * // ... * } * ``` */ declare function parseOrderViewButtonRequest(input: unknown): OrderViewButtonRequest; /** * Builds an HTTP 200 success response for an order view button handler. * * Commerce renders `notifications.success` from the registration as the * toast body when present, and a default success toast otherwise. * * @example * ```ts * return okOrderViewButtonResponse(); * ``` */ declare function okOrderViewButtonResponse(): SuccessResponse; /** * Builds an error response for a worker order view button handler with the given HTTP status code. * * Commerce uses the HTTP status code to distinguish success from failure. * * @param statusCode - The HTTP status code to return. * @param errorMessage - Error message included in the response body as `{ message }`. * * @example * ```ts * return orderViewButtonErrorResponse(500, "Could not reach inventory service"); * ``` */ declare function orderViewButtonErrorResponse(statusCode: number, errorMessage: string): ErrorResponse; //#endregion export { type OrderViewButtonErrorBody, type OrderViewButtonRequest, OrderViewButtonRequestSchema, type OrderViewButtonSuccessBody, getOrderViewButtonAclResourceId, okOrderViewButtonResponse, orderViewButtonErrorResponse, parseOrderViewButtonRequest };