@adobe/aio-commerce-lib-admin-ui 0.1.0 → 0.2.0-beta-20260714082406

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/README.md +1 -1
  3. package/dist/cjs/acl-resource-id-DBlYU0DE.d.cts +39 -0
  4. package/dist/cjs/acl-resource-id-D_hCU1Qg.cjs +69 -0
  5. package/dist/cjs/api/index.cjs +252 -0
  6. package/dist/cjs/api/index.d.cts +126 -0
  7. package/dist/cjs/grid-columns/index.cjs +151 -0
  8. package/dist/cjs/grid-columns/index.d.cts +146 -0
  9. package/dist/cjs/mass-actions/index.cjs +188 -0
  10. package/dist/cjs/mass-actions/index.d.cts +160 -0
  11. package/dist/cjs/menu/index.cjs +91 -0
  12. package/dist/cjs/menu/index.d.cts +63 -0
  13. package/dist/cjs/order-view-buttons/index.cjs +126 -0
  14. package/dist/cjs/order-view-buttons/index.d.cts +113 -0
  15. package/dist/cjs/rolldown-runtime-Cx6hovH8.cjs +67 -0
  16. package/dist/cjs/schemas-Ce10uBzN.cjs +41 -0
  17. package/dist/cjs/utils-B59fjd_w.cjs +39 -0
  18. package/dist/cjs/web/index.cjs +830 -0
  19. package/dist/cjs/web/index.d.cts +192 -0
  20. package/dist/es/acl-resource-id-DBlYU0DE.d.mts +39 -0
  21. package/dist/es/acl-resource-id-pryVxI_c.mjs +57 -0
  22. package/dist/es/api/index.d.mts +126 -0
  23. package/dist/es/api/index.mjs +262 -0
  24. package/dist/es/grid-columns/index.d.mts +146 -0
  25. package/dist/es/grid-columns/index.mjs +143 -0
  26. package/dist/es/mass-actions/index.d.mts +160 -0
  27. package/dist/es/mass-actions/index.mjs +178 -0
  28. package/dist/es/menu/index.d.mts +63 -0
  29. package/dist/es/menu/index.mjs +80 -0
  30. package/dist/es/order-view-buttons/index.d.mts +113 -0
  31. package/dist/es/order-view-buttons/index.mjs +119 -0
  32. package/dist/es/schemas-BFT8ys8P.mjs +34 -0
  33. package/dist/es/utils-COPGW1HO.mjs +32 -0
  34. package/dist/es/web/index.d.mts +192 -0
  35. package/dist/es/web/index.mjs +819 -0
  36. package/package.json +87 -10
  37. package/dist/cjs/index.cjs +0 -139
  38. package/dist/cjs/index.d.cts +0 -56
  39. package/dist/es/index.d.mts +0 -56
  40. package/dist/es/index.mjs +0 -114
package/CHANGELOG.md CHANGED
@@ -1,5 +1,51 @@
1
1
  # @adobe/aio-commerce-lib-admin-ui
2
2
 
3
+ ## 0.2.0-beta-20260714082406
4
+ ### Minor Changes
5
+
6
+
7
+
8
+ - [#528](https://github.com/adobe/aio-commerce-sdk/pull/528) [`0bb7d15`](https://github.com/adobe/aio-commerce-sdk/commit/0bb7d150961f631116b1ac421124960b5b857896) Thanks [@oshmyheliuk](https://github.com/oshmyheliuk)! - Add `getGridColumnAclResourceId`, `getMassActionAclResourceId`, and `getOrderViewButtonAclResourceId` helpers to derive the Commerce ACL resource id for protected grid columns, mass actions, and order view buttons, mirroring `getMenuAclResourceId`.
9
+
10
+
11
+
12
+ - [#522](https://github.com/adobe/aio-commerce-sdk/pull/522) [`4396a64`](https://github.com/adobe/aio-commerce-sdk/commit/4396a647ad22dba063cdf03a16e04aef9387212f) Thanks [@oshmyheliuk](https://github.com/oshmyheliuk)! - Add `getAdminUiPermissionClient` for checking ACL permissions at runtime (SPA bootstrap and runtime action entry). Includes in-process TTL cache, in-flight request deduplication, and deny-by-default on errors. Also exports `getAclResourceId` for deterministic ACL resource id derivation from `metadata.id`.
13
+
14
+
15
+
16
+ - [#542](https://github.com/adobe/aio-commerce-sdk/pull/542) [`c15b50f`](https://github.com/adobe/aio-commerce-sdk/commit/c15b50f667e6d1288270dbd4192c150db0ff0914) Thanks [@iivvaannxx](https://github.com/iivvaannxx)! - Add browser helpers for Admin UI iframe extensions.
17
+
18
+
19
+
20
+ - [#508](https://github.com/adobe/aio-commerce-sdk/pull/508) [`c36f825`](https://github.com/adobe/aio-commerce-sdk/commit/c36f825aff7329fc2831d8aaca032d17bbee373a) Thanks [@iivvaannxx](https://github.com/iivvaannxx)! - Add `@adobe/aio-commerce-lib-admin-ui/menu` entrypoint with named constants for Commerce Admin menu IDs (`MENU_SALES`, `MENU_CATALOG`, etc.), a `COMMERCE_MENUS` collection, a `CommerceMenu` type, and an `isCommerceMenu` type guard.
21
+
22
+
23
+
24
+ - [#516](https://github.com/adobe/aio-commerce-sdk/pull/516) [`bdcced9`](https://github.com/adobe/aio-commerce-sdk/commit/bdcced9297ae5e1b87ce86490a2b6fad76b2e341) Thanks [@obarcelonap](https://github.com/obarcelonap)! - Add `order-view-buttons` entrypoint with request parsing and response builders for `commerce/backend-ui/2` order view button handlers.
25
+
26
+
27
+
28
+ - [#551](https://github.com/adobe/aio-commerce-sdk/pull/551) [`a66f389`](https://github.com/adobe/aio-commerce-sdk/commit/a66f3892622584d27cd6b5d2fc633e15bf9942a8) Thanks [@asalloum5](https://github.com/asalloum5)! - Add `enableAdminUiSdk` to the Admin UI API client, which enables the Admin UI SDK in Commerce via `PUT /V1/adminuisdk/config`.
29
+
30
+
31
+
32
+ - [#486](https://github.com/adobe/aio-commerce-sdk/pull/486) [`413da36`](https://github.com/adobe/aio-commerce-sdk/commit/413da36dcd83e5a41c194f5af50611097659e725) Thanks [@obarcelonap](https://github.com/obarcelonap)! - Add request and response builders for the `commerce/backend-ui/2` grid column wire contract.
33
+
34
+
35
+
36
+ - [#546](https://github.com/adobe/aio-commerce-sdk/pull/546) [`ca2c4fe`](https://github.com/adobe/aio-commerce-sdk/commit/ca2c4febcdfbe52b933775f08e9a53765fc306ab) Thanks [@obarcelonap](https://github.com/obarcelonap)! - Remove `extensionUrl` from extension registration params. The Commerce backend now derives the view URL from the App Registry, so the field has no effect for v2 installed apps.
37
+
38
+
39
+
40
+ - [#492](https://github.com/adobe/aio-commerce-sdk/pull/492) [`ce63b2b`](https://github.com/adobe/aio-commerce-sdk/commit/ce63b2b46f7ef1f2f68780b13e52d1c13fd5fe6e) Thanks [@jcuerdo](https://github.com/jcuerdo)! - Add `mass-actions` entrypoint with wire contract helpers for `commerce/backend-ui/2` mass actions. Parse worker action requests with `parseMassActionRequest`, build success/error responses with `okMassActionResponse`/`errorMassActionResponse`, and parse iframe selection parameters with `parseMassActionSelection`.
41
+
42
+
43
+ ### Patch Changes
44
+
45
+ - Updated dependencies [[`19400fb`](https://github.com/adobe/aio-commerce-sdk/commit/19400fbdfc03c5bbfc30f995a2acdd4272c5e032), [`ce7768e`](https://github.com/adobe/aio-commerce-sdk/commit/ce7768e0ddc6ca35ad6ccec60f584c8bb5a743f0), [`4396a64`](https://github.com/adobe/aio-commerce-sdk/commit/4396a647ad22dba063cdf03a16e04aef9387212f), [`e85bec4`](https://github.com/adobe/aio-commerce-sdk/commit/e85bec40f1eaa91dd6bb7bc6954b2ecfc3ea4029), [`413da36`](https://github.com/adobe/aio-commerce-sdk/commit/413da36dcd83e5a41c194f5af50611097659e725)]:
46
+ - @adobe/aio-commerce-lib-core@1.2.0-beta-20260714082406
47
+ - @adobe/aio-commerce-lib-api@1.3.0-beta-20260714082406
48
+
3
49
  ## 0.1.0
4
50
 
5
51
  ### 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.
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.
4
4
 
5
5
  ## Installation
6
6
 
@@ -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
+ //#region source/api/lib/acl-resource-id.d.ts
16
+ /**
17
+ * Derives the deterministic Commerce ACL resource id for an app from its metadata id.
18
+ *
19
+ * The id is assembled as {@link PREFIX} + sanitized `metadataId`, where sanitization trims
20
+ * whitespace, lowercases, and replaces every character outside `[a-z0-9_]` with `_`.
21
+ * `"Magento_CommerceBackendUix::adminuisdk_app_"` is that fixed constant prefix — not a
22
+ * placeholder — so the example below is fully reproducible from the given argument:
23
+ *
24
+ * @example
25
+ * ```
26
+ * getAclResourceId("approval-dashboard-app")
27
+ * // PREFIX + sanitize("approval-dashboard-app")
28
+ * // "Magento_CommerceBackendUix::adminuisdk_app_" + "approval_dashboard_app"
29
+ * // → "Magento_CommerceBackendUix::adminuisdk_app_approval_dashboard_app"
30
+ * ```
31
+ *
32
+ * @param metadataId - The application's `metadata.id` value (e.g. `"approval-dashboard-app"`).
33
+ * @returns The full Commerce ACL resource id, or an empty string when `metadataId` is blank.
34
+ */
35
+ declare function getAclResourceId(metadataId: string): string;
36
+ /** Commerce entity an Admin UI component is attached to. */
37
+ type AdminUiEntity = "order" | "product" | "customer";
38
+ //#endregion
39
+ export { getAclResourceId as n, AdminUiEntity as t };
@@ -0,0 +1,69 @@
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
+
16
+ //#region source/api/lib/acl-resource-id.ts
17
+ /**
18
+ * Fixed, constant prefix that every Admin UI SDK ACL resource id starts with.
19
+ * It is owned by Commerce and is a stable part of the cross-repo id contract.
20
+ *
21
+ * @internal Exported for use by domain ACL helpers only — not part of the public API.
22
+ */
23
+ const PREFIX = "Magento_CommerceBackendUix::adminuisdk_app_";
24
+ /**
25
+ * Sanitizes a single ACL id segment: trims whitespace, lowercases, and replaces every
26
+ * character outside [a-z0-9_] with an underscore.
27
+ *
28
+ * @internal Exported for use by domain ACL helpers only — not part of the public API.
29
+ */
30
+ function sanitizeSegment(segment) {
31
+ return segment.trim().toLowerCase().replace(/[^a-z0-9_]/g, "_");
32
+ }
33
+ /**
34
+ * Derives the deterministic Commerce ACL resource id for an app from its metadata id.
35
+ *
36
+ * The id is assembled as {@link PREFIX} + sanitized `metadataId`, where sanitization trims
37
+ * whitespace, lowercases, and replaces every character outside `[a-z0-9_]` with `_`.
38
+ * `"Magento_CommerceBackendUix::adminuisdk_app_"` is that fixed constant prefix — not a
39
+ * placeholder — so the example below is fully reproducible from the given argument:
40
+ *
41
+ * @example
42
+ * ```
43
+ * getAclResourceId("approval-dashboard-app")
44
+ * // PREFIX + sanitize("approval-dashboard-app")
45
+ * // "Magento_CommerceBackendUix::adminuisdk_app_" + "approval_dashboard_app"
46
+ * // → "Magento_CommerceBackendUix::adminuisdk_app_approval_dashboard_app"
47
+ * ```
48
+ *
49
+ * @param metadataId - The application's `metadata.id` value (e.g. `"approval-dashboard-app"`).
50
+ * @returns The full Commerce ACL resource id, or an empty string when `metadataId` is blank.
51
+ */
52
+ function getAclResourceId(metadataId) {
53
+ if (metadataId.trim() === "") return "";
54
+ return `${PREFIX}${sanitizeSegment(metadataId)}`;
55
+ }
56
+
57
+ //#endregion
58
+ Object.defineProperty(exports, 'getAclResourceId', {
59
+ enumerable: true,
60
+ get: function () {
61
+ return getAclResourceId;
62
+ }
63
+ });
64
+ Object.defineProperty(exports, 'sanitizeSegment', {
65
+ enumerable: true,
66
+ get: function () {
67
+ return sanitizeSegment;
68
+ }
69
+ });
@@ -0,0 +1,252 @@
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-Cx6hovH8.cjs');
17
+ const require_acl_resource_id = require('../acl-resource-id-D_hCU1Qg.cjs');
18
+ const require_utils = require('../utils-B59fjd_w.cjs');
19
+ let _adobe_aio_commerce_lib_core_error = require("@adobe/aio-commerce-lib-core/error");
20
+ let _adobe_aio_commerce_lib_api = require("@adobe/aio-commerce-lib-api");
21
+ let valibot = require("valibot");
22
+ valibot = require_rolldown_runtime.__toESM(valibot, 1);
23
+ let ky = require("ky");
24
+
25
+ //#region source/errors.ts
26
+ /** Base error for Admin UI SDK permission helper failures. */
27
+ var AdminUiPermissionError = class extends _adobe_aio_commerce_lib_core_error.CommerceSdkErrorBase {};
28
+ /** Error thrown when the current user is denied access to an Admin UI SDK ACL resource. */
29
+ var AdminUiPermissionDeniedError = class extends AdminUiPermissionError {
30
+ resource;
31
+ constructor(resource, options) {
32
+ super(`Admin UI SDK permission denied for resource: ${resource}`, options);
33
+ this.resource = resource;
34
+ }
35
+ };
36
+
37
+ //#endregion
38
+ //#region source/api/config/endpoints.ts
39
+ var endpoints_exports$1 = /* @__PURE__ */ require_rolldown_runtime.__exportAll({ enableAdminUiSdk: () => enableAdminUiSdk });
40
+ /**
41
+ * Enables the Admin UI SDK in Commerce via PUT /V1/adminuisdk/config.
42
+ *
43
+ * This must be called before {@link registerExtension} so that Commerce accepts
44
+ * the extension registration; registering an extension while the SDK is disabled
45
+ * leaves the extension unavailable in the Admin UI.
46
+ *
47
+ * @param httpClient - The {@link AdobeCommerceHttpClient} to use to make the request.
48
+ * @param fetchOptions - Optional Ky fetch options.
49
+ *
50
+ * @throws An `HTTPError` if the status code is not 2XX.
51
+ */
52
+ async function enableAdminUiSdk(httpClient, fetchOptions) {
53
+ return httpClient.put("adminuisdk/config", {
54
+ ...fetchOptions,
55
+ json: { enableAdminUiSdk: true }
56
+ }).json();
57
+ }
58
+
59
+ //#endregion
60
+ //#region source/api/extensions/schema.ts
61
+ /** Parameters for POST /V1/adminuisdk/extension. */
62
+ const ExtensionRegistrationParamsSchema = valibot.object({
63
+ extensionName: valibot.pipe(valibot.string(), valibot.minLength(1)),
64
+ extensionTitle: valibot.pipe(valibot.string(), valibot.minLength(1)),
65
+ extensionWorkspace: valibot.pipe(valibot.string(), valibot.minLength(1))
66
+ });
67
+ /** Parameters for DELETE /V1/adminuisdk/extension/{workspaceName}/{extensionName}. */
68
+ const UnregisterExtensionParamsSchema = valibot.object({
69
+ extensionName: valibot.pipe(valibot.string(), valibot.minLength(1)),
70
+ workspaceName: valibot.pipe(valibot.string(), valibot.minLength(1))
71
+ });
72
+
73
+ //#endregion
74
+ //#region source/api/extensions/endpoints.ts
75
+ var endpoints_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({
76
+ registerExtension: () => registerExtension,
77
+ unregisterExtension: () => unregisterExtension
78
+ });
79
+ /**
80
+ * Registers an Admin UI extension with Commerce via POST /V1/adminuisdk/extension.
81
+ *
82
+ * @param httpClient - The {@link AdobeCommerceHttpClient} to use to make the request.
83
+ * @param params - The extension registration parameters.
84
+ * @param fetchOptions - Optional Ky fetch options.
85
+ *
86
+ * @throws A `CommerceSdkValidationError` if the parameters are invalid.
87
+ * @throws An `HTTPError` if the status code is not 2XX.
88
+ */
89
+ async function registerExtension(httpClient, params, fetchOptions) {
90
+ const extension = require_utils.parseOrThrow(ExtensionRegistrationParamsSchema, params);
91
+ return httpClient.post("adminuisdk/extension", {
92
+ ...fetchOptions,
93
+ json: { extension }
94
+ }).json();
95
+ }
96
+ /**
97
+ * Unregisters an Admin UI extension from Commerce via DELETE /V1/adminuisdk/extension/{workspaceName}/{extensionName}.
98
+ *
99
+ * @param httpClient - The {@link AdobeCommerceHttpClient} to use to make the request.
100
+ * @param params - The workspace and extension names.
101
+ * @param fetchOptions - Optional Ky fetch options.
102
+ *
103
+ * @throws A `CommerceSdkValidationError` if the parameters are invalid.
104
+ * @throws An `HTTPError` if the status code is not 2XX.
105
+ */
106
+ async function unregisterExtension(httpClient, params, fetchOptions) {
107
+ const { workspaceName, extensionName } = require_utils.parseOrThrow(UnregisterExtensionParamsSchema, params);
108
+ return httpClient.delete(`adminuisdk/extension/${workspaceName}/${extensionName}`, fetchOptions).then((_res) => {});
109
+ }
110
+
111
+ //#endregion
112
+ //#region source/api/lib/api-client.ts
113
+ /**
114
+ * Creates a new API client for the Admin UI API with all available operations.
115
+ *
116
+ * @param params - The parameters to build the Commerce HTTP client.
117
+ */
118
+ function createAdminUiApiClient(params) {
119
+ return _adobe_aio_commerce_lib_api.ApiClient.create(new _adobe_aio_commerce_lib_api.AdobeCommerceHttpClient(params), {
120
+ ...endpoints_exports$1,
121
+ ...endpoints_exports
122
+ });
123
+ }
124
+
125
+ //#endregion
126
+ //#region source/api/permissions/schema.ts
127
+ /** Response shape returned by the Admin UI SDK permission check endpoint. */
128
+ const permissionCheckResponseSchema = valibot.object({ allowed: valibot.boolean() });
129
+
130
+ //#endregion
131
+ //#region source/api/permissions/endpoints.ts
132
+ /**
133
+ * Checks whether the current user has the given ACL resource granted via POST /V1/adminuisdk/permission/check.
134
+ * This is the raw HTTP call — prefer {@link getAdminUiPermissionClient} for caching and deduplication.
135
+ *
136
+ * @param httpClient - The {@link AdobeCommerceHttpClient} to use to make the request.
137
+ * @param params - The resource to check.
138
+ *
139
+ * @throws {@link HTTPError} if the response status is not in the 2xx range.
140
+ */
141
+ async function checkPermission(httpClient, params) {
142
+ return require_utils.parseOrThrow(permissionCheckResponseSchema, await httpClient.post("adminuisdk/permission/check", { json: { resource: params.resource } }).json());
143
+ }
144
+
145
+ //#endregion
146
+ //#region source/api/lib/permission-client.ts
147
+ const DEFAULT_CACHE_TTL_MS = 3e5;
148
+ /** Returns true when the error is an HTTP 401 Unauthorized response from ky. */
149
+ function isUnauthorizedError(error) {
150
+ return error instanceof ky.HTTPError && error.response.status === 401;
151
+ }
152
+ /** Wraps an arbitrary thrown value in an `AdminUiPermissionError`, passing through instances that are already one. */
153
+ function toPermissionError(error) {
154
+ return error instanceof AdminUiPermissionError ? error : new AdminUiPermissionError("Permission check failed", { cause: error });
155
+ }
156
+ /**
157
+ * Creates a client for checking Admin UI SDK ACL resources.
158
+ *
159
+ * @param options - Client configuration; see {@link AdminUiPermissionClientOptions}.
160
+ * @returns An {@link AdminUiPermissionClient} for checking and requiring ACL resources.
161
+ */
162
+ function getAdminUiPermissionClient(options) {
163
+ const { httpClient, appId, cacheTtlMs = DEFAULT_CACHE_TTL_MS, denyOnError = true } = options;
164
+ const cache = /* @__PURE__ */ new Map();
165
+ const inFlight = /* @__PURE__ */ new Map();
166
+ /**
167
+ * Performs the network request for `resource` and maps the outcome to a `PermissionCheckResult`.
168
+ * Always throws `AdminUiPermissionError` on 401. On other errors, returns a non-cacheable error
169
+ * result when `denyOnError` is true, or re-throws otherwise.
170
+ */
171
+ async function fetchCheck(resource) {
172
+ try {
173
+ return {
174
+ allowed: (await checkPermission(httpClient, { resource })).allowed,
175
+ cacheable: true
176
+ };
177
+ } catch (error) {
178
+ if (isUnauthorizedError(error)) throw new AdminUiPermissionError("Unauthorized", { cause: error });
179
+ if (denyOnError) return {
180
+ cacheable: false,
181
+ error: toPermissionError(error)
182
+ };
183
+ throw toPermissionError(error);
184
+ }
185
+ }
186
+ /**
187
+ * Returns a permission check result for `resource`, serving from the TTL cache or an
188
+ * in-flight request when available, and falling back to a fresh `fetchCheck` call otherwise.
189
+ * Successful cacheable results are written to the TTL cache once the in-flight promise settles.
190
+ */
191
+ function resolveCheck(resource) {
192
+ if (cacheTtlMs > 0) {
193
+ const cached = cache.get(resource);
194
+ if (cached !== void 0 && cached.expiresAt > Date.now()) return {
195
+ allowed: cached.value,
196
+ cacheable: true
197
+ };
198
+ }
199
+ const existing = inFlight.get(resource);
200
+ if (existing !== void 0) return existing;
201
+ const trackedPromise = fetchCheck(resource).then((result) => {
202
+ if (cacheTtlMs > 0 && result.cacheable && inFlight.get(resource) === trackedPromise) cache.set(resource, {
203
+ expiresAt: Date.now() + cacheTtlMs,
204
+ value: result.allowed
205
+ });
206
+ return result;
207
+ }).finally(() => {
208
+ if (inFlight.get(resource) === trackedPromise) inFlight.delete(resource);
209
+ });
210
+ inFlight.set(resource, trackedPromise);
211
+ return trackedPromise;
212
+ }
213
+ /**
214
+ * Resolves the ACL resource id for a call: uses the explicit argument when provided,
215
+ * otherwise derives it from `appId`. Returns an empty string when neither source yields a
216
+ * valid id, which callers interpret as "no resource available."
217
+ */
218
+ function resolveResource(resource) {
219
+ return resource ?? require_acl_resource_id.getAclResourceId(appId ?? "");
220
+ }
221
+ return {
222
+ async check(resource) {
223
+ const resolved = resolveResource(resource);
224
+ if (resolved === "") return false;
225
+ const result = await resolveCheck(resolved);
226
+ return "error" in result ? false : result.allowed;
227
+ },
228
+ invalidate(resource) {
229
+ if (resource === void 0) {
230
+ cache.clear();
231
+ inFlight.clear();
232
+ return;
233
+ }
234
+ cache.delete(resource);
235
+ inFlight.delete(resource);
236
+ },
237
+ async require(resource) {
238
+ const resolved = resolveResource(resource);
239
+ if (resolved === "") throw new AdminUiPermissionError("No ACL resource ID could be resolved: provide a resource argument or set appId in options");
240
+ const result = await resolveCheck(resolved);
241
+ if ("error" in result) throw result.error;
242
+ if (!result.allowed) throw new AdminUiPermissionDeniedError(resolved);
243
+ }
244
+ };
245
+ }
246
+
247
+ //#endregion
248
+ exports.AdminUiPermissionDeniedError = AdminUiPermissionDeniedError;
249
+ exports.AdminUiPermissionError = AdminUiPermissionError;
250
+ exports.createAdminUiApiClient = createAdminUiApiClient;
251
+ exports.getAclResourceId = require_acl_resource_id.getAclResourceId;
252
+ exports.getAdminUiPermissionClient = getAdminUiPermissionClient;
@@ -0,0 +1,126 @@
1
+ /**
2
+ * @license
3
+ *
4
+ * Copyright 2026 Adobe. All rights reserved.
5
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License. You may obtain a copy
7
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software distributed under
10
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
11
+ * OF ANY KIND, either express or implied. See the License for the specific language
12
+ * governing permissions and limitations under the License.
13
+ */
14
+
15
+ import { n as getAclResourceId, t as AdminUiEntity } from "../acl-resource-id-DBlYU0DE.cjs";
16
+ import { CommerceSdkErrorBase, CommerceSdkErrorOptions } from "@adobe/aio-commerce-lib-core/error";
17
+ import { AdobeCommerceHttpClient, CommerceHttpClientParams } from "@adobe/aio-commerce-lib-api";
18
+ import * as v from "valibot";
19
+
20
+ //#region source/errors.d.ts
21
+ /** Base error for Admin UI SDK permission helper failures. */
22
+ declare class AdminUiPermissionError extends CommerceSdkErrorBase {}
23
+ /** Options for {@link AdminUiPermissionDeniedError}. */
24
+ type AdminUiPermissionDeniedErrorOptions = CommerceSdkErrorOptions;
25
+ /** Error thrown when the current user is denied access to an Admin UI SDK ACL resource. */
26
+ declare class AdminUiPermissionDeniedError extends AdminUiPermissionError {
27
+ readonly resource: string;
28
+ constructor(resource: string, options?: AdminUiPermissionDeniedErrorOptions);
29
+ }
30
+ //#endregion
31
+ //#region source/api/lib/api-client.d.ts
32
+ /**
33
+ * Creates a new API client for the Admin UI API with all available operations.
34
+ *
35
+ * @param params - The parameters to build the Commerce HTTP client.
36
+ */
37
+ declare function createAdminUiApiClient(params: CommerceHttpClientParams): import("@adobe/aio-commerce-lib-api").ApiClientRecord<AdobeCommerceHttpClient, {
38
+ registerExtension(httpClient: AdobeCommerceHttpClient, params: ExtensionRegistrationParams, fetchOptions?: import("ky").Options): Promise<RegisterExtensionResponse>;
39
+ unregisterExtension(httpClient: AdobeCommerceHttpClient, params: UnregisterExtensionParams, fetchOptions?: import("ky").Options): Promise<void>;
40
+ enableAdminUiSdk(httpClient: AdobeCommerceHttpClient, fetchOptions?: import("ky").Options): Promise<boolean>;
41
+ }>;
42
+ /**
43
+ * An API client for the Admin UI API with all operations.
44
+ * @see {@link createAdminUiApiClient}
45
+ */
46
+ type AdminUiApiClient = ReturnType<typeof createAdminUiApiClient>;
47
+ //#endregion
48
+ //#region source/api/lib/permission-client.d.ts
49
+ /** Options used to create an Admin UI SDK permission client. */
50
+ type AdminUiPermissionClientOptions = {
51
+ /** The application's `metadata.id` value. When provided, `check()` and `require()` can be called with no resource argument. */appId?: string;
52
+ /**
53
+ * Milliseconds to cache a permission result. Default: 300_000 (5 minutes).
54
+ * Set to 0 to disable result caching. Note: in-flight deduplication of concurrent identical
55
+ * requests is independent of this setting and remains active even when caching is disabled.
56
+ */
57
+ cacheTtlMs?: number; /** Return false instead of throwing when a network or parse error occurs. Default: true. */
58
+ denyOnError?: boolean; /** Commerce HTTP client used to call the Admin UI SDK permission endpoint. */
59
+ httpClient: AdobeCommerceHttpClient;
60
+ };
61
+ /** Client for checking the current user's Admin UI SDK resource permissions. */
62
+ type AdminUiPermissionClient = {
63
+ /**
64
+ * Checks whether the current user has the given ACL resource granted.
65
+ *
66
+ * @param resource - The ACL resource id to check. When omitted, defaults to the id derived from `appId`.
67
+ * @returns `true` when granted; `false` when denied, on network or parse errors while `denyOnError` is
68
+ * `true` (the default), or immediately when neither `resource` nor a valid `appId` is available.
69
+ * @throws {@link AdminUiPermissionError} on HTTP 401, regardless of `denyOnError`.
70
+ */
71
+ check: (resource?: string) => Promise<boolean>;
72
+ /**
73
+ * Clears cached permission results.
74
+ *
75
+ * @param resource - The ACL resource id whose cached result to clear. When omitted, clears all cached
76
+ * entries and in-flight tracking without aborting outstanding HTTP requests.
77
+ */
78
+ invalidate: (resource?: string) => void;
79
+ /**
80
+ * Resolves when the current user has the given ACL resource granted.
81
+ *
82
+ * @param resource - The ACL resource id to require. When omitted, defaults to the id derived from `appId`.
83
+ * @throws {@link AdminUiPermissionDeniedError} when the resource is explicitly denied.
84
+ * @throws {@link AdminUiPermissionError} on HTTP 401, on network or parse errors while `denyOnError` is
85
+ * `false`, or immediately when neither `resource` nor a valid `appId` is available.
86
+ */
87
+ require: (resource?: string) => Promise<void>;
88
+ };
89
+ /**
90
+ * Creates a client for checking Admin UI SDK ACL resources.
91
+ *
92
+ * @param options - Client configuration; see {@link AdminUiPermissionClientOptions}.
93
+ * @returns An {@link AdminUiPermissionClient} for checking and requiring ACL resources.
94
+ */
95
+ declare function getAdminUiPermissionClient(options: AdminUiPermissionClientOptions): AdminUiPermissionClient;
96
+ //#endregion
97
+ //#region source/api/extensions/schema.d.ts
98
+ /** Parameters for POST /V1/adminuisdk/extension. */
99
+ declare const ExtensionRegistrationParamsSchema: v.ObjectSchema<{
100
+ readonly extensionName: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
101
+ readonly extensionTitle: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
102
+ readonly extensionWorkspace: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
103
+ }, undefined>;
104
+ /** Parameters for DELETE /V1/adminuisdk/extension/{workspaceName}/{extensionName}. */
105
+ declare const UnregisterExtensionParamsSchema: v.ObjectSchema<{
106
+ readonly extensionName: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
107
+ readonly workspaceName: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
108
+ }, undefined>;
109
+ /** The parameters accepted by POST /V1/adminuisdk/extension. */
110
+ type ExtensionRegistrationParams = v.InferInput<typeof ExtensionRegistrationParamsSchema>;
111
+ /** The parameters accepted by DELETE /V1/adminuisdk/extension/{workspaceName}/{extensionName}. */
112
+ type UnregisterExtensionParams = v.InferInput<typeof UnregisterExtensionParamsSchema>;
113
+ /** The response returned by POST /V1/adminuisdk/extension. */
114
+ type RegisterExtensionResponse = {
115
+ extensionId: string;
116
+ };
117
+ //#endregion
118
+ //#region source/api/permissions/schema.d.ts
119
+ /** Response shape returned by the Admin UI SDK permission check endpoint. */
120
+ declare const permissionCheckResponseSchema: v.ObjectSchema<{
121
+ readonly allowed: v.BooleanSchema<undefined>;
122
+ }, undefined>;
123
+ /** Parsed Admin UI SDK permission check response. */
124
+ type PermissionCheckResponse = v.InferOutput<typeof permissionCheckResponseSchema>;
125
+ //#endregion
126
+ export { AdminUiApiClient, type AdminUiEntity, AdminUiPermissionClient, AdminUiPermissionClientOptions, AdminUiPermissionDeniedError, AdminUiPermissionDeniedErrorOptions, AdminUiPermissionError, type ExtensionRegistrationParams, type ExtensionRegistrationParamsSchema, type PermissionCheckResponse, type RegisterExtensionResponse, type UnregisterExtensionParams, type UnregisterExtensionParamsSchema, createAdminUiApiClient, getAclResourceId, getAdminUiPermissionClient, type permissionCheckResponseSchema };