/** * @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 { t as AdminUiEntity } from "../acl-resource-id-DBlYU0DE.mjs"; import * as v from "valibot"; import { ErrorResponse, SuccessResponse } from "@adobe/aio-commerce-lib-core/responses"; //#region source/grid-columns/acl-resource-id.d.ts /** * Derives the deterministic Commerce ACL resource id for a grid column. * * The id is assembled as: `getAclResourceId(metadataId)` + `"__gridcolumns_"` + * sanitized `columnId`. The `entity` value is used verbatim (it is already `[a-z]`); the * `columnId` is sanitized (trimmed, lowercased, non-`[a-z0-9_]` → `_`). `"Magento_CommerceBackendUix::adminuisdk_app_"` * in the example is the fixed constant prefix (not a placeholder), and `"_gridcolumns_"` is the * literal keyword separator for this component: * * @example * ``` * getGridColumnAclResourceId("approval-dashboard-app", "order", "order_status") * // getAclResourceId("approval-dashboard-app") + "_order_gridcolumns_" + sanitize("order_status") * // "Magento_CommerceBackendUix::adminuisdk_app_approval_dashboard_app" + "_order_gridcolumns_" + "order_status" * // → "Magento_CommerceBackendUix::adminuisdk_app_approval_dashboard_app_order_gridcolumns_order_status" * ``` * * @param metadataId - The application's `metadata.id` value (e.g. `"approval-dashboard-app"`). * @param entity - The grid's Commerce entity (`"order"`, `"product"`, or `"customer"`). * @param columnId - The column's `id` value from `adminUi..gridColumns.columns[].id`. * @returns The full Commerce ACL resource id for the grid-column leaf node, or an empty string * when `metadataId` is blank. */ declare function getGridColumnAclResourceId(metadataId: string, entity: AdminUiEntity, columnId: string): string; //#endregion //#region source/grid-columns/requests/schema.d.ts /** * Grid identifier sent by Commerce on the `commerce/backend-ui/2` wire contract. * * @see {@link https://github.com/magento-commerce/adobe-commerce-backend-uix Magento module reference} */ declare const GridTypeSchema: v.PicklistSchema<["order", "product", "customer"], undefined>; /** * Schema for the JSON body Commerce POSTs to a grid column handler. * * Commerce sends one request per chunk of grid rows (currently up to 1000 IDs * per request). The upper bound is the Commerce side's contract and is not * enforced here. */ declare const GridRequestSchema: v.ObjectSchema<{ readonly gridType: v.PicklistSchema<["order", "product", "customer"], undefined>; readonly ids: v.SchemaWithPipe, v.NonEmptyAction]>, undefined>, v.MinLengthAction]>; readonly requestId: v.SchemaWithPipe, v.NonEmptyAction]>; }, undefined>; //#endregion //#region source/grid-columns/requests/types.d.ts /** Grid identifier sent on the wire. */ type GridType = v.InferOutput; /** Parsed request body sent by Commerce to a grid column handler. */ type GridRequest = v.InferOutput; //#endregion //#region source/grid-columns/requests/presets.d.ts /** * Parses and validates the JSON body Commerce POSTs to a grid column handler. * * Throws a `CommerceSdkValidationError` if the input is malformed. * * @example * ```ts * import { parseGridRequest } from "@adobe/aio-commerce-lib-admin-ui/grid-columns"; * * export async function main(params: unknown) { * const { requestId, gridType, ids } = parseGridRequest(params); * // ... * } * ``` */ declare function parseGridRequest(input: unknown): GridRequest; //#endregion //#region source/grid-columns/responses/types.d.ts /** Cell values returned for a single row, keyed by `id`. */ type GridRow = Record; /** * Success body returned to Commerce. * * The `"*"` entry supplies default cell values that Commerce applies to IDs * missing from `data` and to cells whose returned value does not satisfy the * declared `type` on the registration. */ type GridSuccessBody = { data: Record & { "*"?: GridRow; }; }; /** Failure body returned to Commerce. */ type GridErrorBody = { message: string; }; //#endregion //#region source/grid-columns/responses/presets.d.ts /** * Builds an HTTP 200 success response carrying the grid column data envelope * Commerce expects on the `commerce/backend-ui/2` wire contract. * * @param data - Per-row cell values, keyed by entity ID. * @param defaults - Default cell values applied by Commerce to IDs missing from * `data` and to cells whose value does not satisfy the declared `type` on the * registration. * * @example * ```ts * return okGridResponse( * { * "000000001": { fulfillment_status: "shipped", risk_score: 12 }, * "000000002": { fulfillment_status: "pending", risk_score: 47 }, * }, * { fulfillment_status: "unknown", risk_score: 0 }, * ); * ``` */ declare function okGridResponse(data: Record, defaults?: GridRow): SuccessResponse; /** * Builds an error response for a grid column 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 errorGridResponse(500, "Could not reach inventory service"); * ``` */ declare function errorGridResponse(statusCode: number, errorMessage: string): ErrorResponse; //#endregion export { type AdminUiEntity, type GridErrorBody, type GridRequest, GridRequestSchema, type GridRow, type GridSuccessBody, type GridType, GridTypeSchema, errorGridResponse, getGridColumnAclResourceId, okGridResponse, parseGridRequest };