@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.
- package/CHANGELOG.md +46 -0
- package/README.md +1 -1
- package/dist/cjs/acl-resource-id-DBlYU0DE.d.cts +39 -0
- package/dist/cjs/acl-resource-id-D_hCU1Qg.cjs +69 -0
- package/dist/cjs/api/index.cjs +252 -0
- package/dist/cjs/api/index.d.cts +126 -0
- package/dist/cjs/grid-columns/index.cjs +151 -0
- package/dist/cjs/grid-columns/index.d.cts +146 -0
- package/dist/cjs/mass-actions/index.cjs +188 -0
- package/dist/cjs/mass-actions/index.d.cts +160 -0
- package/dist/cjs/menu/index.cjs +91 -0
- package/dist/cjs/menu/index.d.cts +63 -0
- package/dist/cjs/order-view-buttons/index.cjs +126 -0
- package/dist/cjs/order-view-buttons/index.d.cts +113 -0
- package/dist/cjs/rolldown-runtime-Cx6hovH8.cjs +67 -0
- package/dist/cjs/schemas-Ce10uBzN.cjs +41 -0
- package/dist/cjs/utils-B59fjd_w.cjs +39 -0
- package/dist/cjs/web/index.cjs +830 -0
- package/dist/cjs/web/index.d.cts +192 -0
- package/dist/es/acl-resource-id-DBlYU0DE.d.mts +39 -0
- package/dist/es/acl-resource-id-pryVxI_c.mjs +57 -0
- package/dist/es/api/index.d.mts +126 -0
- package/dist/es/api/index.mjs +262 -0
- package/dist/es/grid-columns/index.d.mts +146 -0
- package/dist/es/grid-columns/index.mjs +143 -0
- package/dist/es/mass-actions/index.d.mts +160 -0
- package/dist/es/mass-actions/index.mjs +178 -0
- package/dist/es/menu/index.d.mts +63 -0
- package/dist/es/menu/index.mjs +80 -0
- package/dist/es/order-view-buttons/index.d.mts +113 -0
- package/dist/es/order-view-buttons/index.mjs +119 -0
- package/dist/es/schemas-BFT8ys8P.mjs +34 -0
- package/dist/es/utils-COPGW1HO.mjs +32 -0
- package/dist/es/web/index.d.mts +192 -0
- package/dist/es/web/index.mjs +819 -0
- package/package.json +87 -10
- package/dist/cjs/index.cjs +0 -139
- package/dist/cjs/index.d.cts +0 -56
- package/dist/es/index.d.mts +0 -56
- package/dist/es/index.mjs +0 -114
|
@@ -0,0 +1,192 @@
|
|
|
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 { ReactNode } from "react";
|
|
16
|
+
import { attach } from "@adobe/uix-guest";
|
|
17
|
+
import { NavigateOptions, ToOptions } from "@tanstack/react-router";
|
|
18
|
+
|
|
19
|
+
//#region source/web/react/auth/types.d.ts
|
|
20
|
+
/** The IMS credentials provided by the host (Commerce Admin or Experience Cloud shell). */
|
|
21
|
+
type ImsContext = {
|
|
22
|
+
imsToken: string;
|
|
23
|
+
imsOrgId: string;
|
|
24
|
+
};
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region source/web/react/auth/context/ims-context.d.ts
|
|
27
|
+
/**
|
|
28
|
+
* Returns the IMS credentials provided by the host. Works inside the Commerce Admin and the
|
|
29
|
+
* Experience Cloud shell.
|
|
30
|
+
*
|
|
31
|
+
* @throws If no host provides credentials (e.g. the app is running standalone, outside both the
|
|
32
|
+
* Commerce Admin and the Experience Cloud shell).
|
|
33
|
+
*/
|
|
34
|
+
declare function useIms(): ImsContext;
|
|
35
|
+
//#endregion
|
|
36
|
+
//#region source/web/react/commerce/types.d.ts
|
|
37
|
+
/** The guest connection that shares the context between the extension and the Admin UI host. */
|
|
38
|
+
type GuestConnection = Awaited<ReturnType<typeof attach>>;
|
|
39
|
+
/**
|
|
40
|
+
* The Commerce shared context for a mounted Admin UI iframe app.
|
|
41
|
+
*
|
|
42
|
+
* This only exists when the app runs inside the Commerce Admin: it is provided by the Commerce UIX
|
|
43
|
+
* host over the guest connection. It is distinct from the IMS credentials ({@link ImsContext}),
|
|
44
|
+
* which are also available in the Experience Cloud shell.
|
|
45
|
+
*/
|
|
46
|
+
type SharedContext = {
|
|
47
|
+
/** The extension ID of the app. */extensionId: string; /** The live `sharedContext` object provided by the host. */
|
|
48
|
+
sharedContext: NonNullable<GuestConnection["sharedContext"]>; /** The host proxy, used by `useHostConnection` to invoke host-frame actions (close/onError). */
|
|
49
|
+
host: NonNullable<GuestConnection["host"]>;
|
|
50
|
+
};
|
|
51
|
+
/** Actions for closing the extension iframe and returning control to the Commerce Admin. */
|
|
52
|
+
type HostConnection = {
|
|
53
|
+
/** Closes the iframe and navigates back to the originating grid or order. */close: () => Promise<void>; /** Closes the iframe and navigates back, flagging the originating page that an error occurred. */
|
|
54
|
+
closeWithError: () => Promise<void>;
|
|
55
|
+
};
|
|
56
|
+
/** The context shared with mass-action extension points. */
|
|
57
|
+
type MassActionContext = {
|
|
58
|
+
selectedIds: string[];
|
|
59
|
+
};
|
|
60
|
+
/** The context shared with order view-button extension points. */
|
|
61
|
+
type OrderViewButtonContext = {
|
|
62
|
+
orderId: string;
|
|
63
|
+
};
|
|
64
|
+
//#endregion
|
|
65
|
+
//#region source/web/react/commerce/context/shared-context.d.ts
|
|
66
|
+
/**
|
|
67
|
+
* Returns the current Commerce shared context. The guest connection is already established by
|
|
68
|
+
* the time this can be called (see {@link SharedContextProvider}).
|
|
69
|
+
*
|
|
70
|
+
* This is a low-level escape hatch that exposes the raw `sharedContext` and `host` objects.
|
|
71
|
+
* Prefer a purpose-built hook ({@link useCommerce}, {@link useMassActionContext},
|
|
72
|
+
* {@link useOrderViewButtonContext}) when one covers what you need.
|
|
73
|
+
*
|
|
74
|
+
* @throws If used outside a {@link SharedContextProvider}.
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```tsx
|
|
78
|
+
* import { useSharedContext } from "@adobe/aio-commerce-lib-admin-ui/web";
|
|
79
|
+
*
|
|
80
|
+
* function ImsTokenLabel() {
|
|
81
|
+
* const { sharedContext } = useSharedContext();
|
|
82
|
+
* return <span>{sharedContext.get("imsToken")}</span>;
|
|
83
|
+
* }
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
declare function useSharedContext(): SharedContext;
|
|
87
|
+
//#endregion
|
|
88
|
+
//#region source/web/react/commerce/hooks/use-commerce.d.ts
|
|
89
|
+
/**
|
|
90
|
+
* Returns the host (domain) of the Commerce Admin the extension is embedded in, resolving it over
|
|
91
|
+
* the guest connection.
|
|
92
|
+
*
|
|
93
|
+
* @throws If used outside a Commerce Admin UI frame, or when the host does not expose the
|
|
94
|
+
* Commerce integration API.
|
|
95
|
+
*/
|
|
96
|
+
declare function useCommerce(): {
|
|
97
|
+
commerceHost: string;
|
|
98
|
+
};
|
|
99
|
+
//#endregion
|
|
100
|
+
//#region source/web/react/commerce/hooks/use-extension-context.d.ts
|
|
101
|
+
/**
|
|
102
|
+
* Returns the context for a mass-action extension point: the selected row IDs the action was
|
|
103
|
+
* triggered with. The value is read from the host-provided Commerce context.
|
|
104
|
+
*
|
|
105
|
+
* @throws If used outside the Commerce shared context, or when that context does not include a
|
|
106
|
+
* mass-action selection.
|
|
107
|
+
*/
|
|
108
|
+
declare function useMassActionContext(): MassActionContext;
|
|
109
|
+
/**
|
|
110
|
+
* Returns the context for an order view-button extension point: the order ID the button was
|
|
111
|
+
* triggered from.
|
|
112
|
+
*
|
|
113
|
+
* @throws If no order ID is present in the page URL.
|
|
114
|
+
*/
|
|
115
|
+
declare function useOrderViewButtonContext(): OrderViewButtonContext;
|
|
116
|
+
//#endregion
|
|
117
|
+
//#region source/web/react/commerce/hooks/use-host-connection.d.ts
|
|
118
|
+
/**
|
|
119
|
+
* Returns typed helpers for interacting with the Commerce Admin host.
|
|
120
|
+
*
|
|
121
|
+
* @throws If called before the guest connection is established, or when the host frame actions
|
|
122
|
+
* are unavailable.
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```tsx
|
|
126
|
+
* import { useHostConnection } from "@adobe/aio-commerce-lib-admin-ui/web";
|
|
127
|
+
*
|
|
128
|
+
* function DoneButton() {
|
|
129
|
+
* const { close } = useHostConnection();
|
|
130
|
+
* return <button onClick={() => void close()}>Done</button>;
|
|
131
|
+
* }
|
|
132
|
+
* ```
|
|
133
|
+
*/
|
|
134
|
+
declare function useHostConnection(): HostConnection;
|
|
135
|
+
//#endregion
|
|
136
|
+
//#region source/web/react/routing/types.d.ts
|
|
137
|
+
declare module "@react-spectrum/s2/Provider" {
|
|
138
|
+
interface RouterConfig {
|
|
139
|
+
href: ToOptions;
|
|
140
|
+
routerOptions: Omit<NavigateOptions, keyof ToOptions>;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
/** Defines a route that is marked as the index (entrypoint) */
|
|
144
|
+
type IndexRoute = {
|
|
145
|
+
index: true; /** The React element to render for the index route. */
|
|
146
|
+
element: ReactNode;
|
|
147
|
+
};
|
|
148
|
+
/** Defines a route that exists at a given path. */
|
|
149
|
+
type ExtensionRoute = {
|
|
150
|
+
/** The path for the route. */path: string; /** The React element to render for the route. */
|
|
151
|
+
element: ReactNode;
|
|
152
|
+
};
|
|
153
|
+
/** Defines the routes for an extension app, which must include at least one index route (first item). */
|
|
154
|
+
type ExtensionAppRoutes = [IndexRoute, ...ExtensionRoute[]];
|
|
155
|
+
//#endregion
|
|
156
|
+
//#region source/web/react/extension/create-app.d.ts
|
|
157
|
+
/** Configuration options when instantiating an extension app. */
|
|
158
|
+
type CreateExtensionAppOptions = {
|
|
159
|
+
/** General metadata about the extension app. */metadata: {
|
|
160
|
+
/** The unique identifier for the extension app. */extensionId: string;
|
|
161
|
+
}; /** Optional root element where the app will be mounted. */
|
|
162
|
+
root?: HTMLElement; /** A list of routes for the extension app, specifying an index route is mandatory. */
|
|
163
|
+
routes: ExtensionAppRoutes;
|
|
164
|
+
};
|
|
165
|
+
/**
|
|
166
|
+
* Mounts a Commerce Admin UI iframe app and handles Experience Cloud Shell, UIX
|
|
167
|
+
* registration, shared-context attachment, routing, and Spectrum setup.
|
|
168
|
+
*
|
|
169
|
+
* The app is wrapped in React's `<StrictMode>`, so in development builds (e.g. when
|
|
170
|
+
* served via `aio app dev` or `aio app run`) components render twice and effects run
|
|
171
|
+
* an extra setup + cleanup cycle on mount. Production builds are unaffected.
|
|
172
|
+
*
|
|
173
|
+
* @param options - App bootstrap options.
|
|
174
|
+
*
|
|
175
|
+
* @example
|
|
176
|
+
* ```tsx
|
|
177
|
+
* import { createExtensionApp } from "@adobe/aio-commerce-lib-admin-ui/web";
|
|
178
|
+
* import { MainPage } from "./pages/main-page.jsx";
|
|
179
|
+
*
|
|
180
|
+
* createExtensionApp({
|
|
181
|
+
* metadata: { extensionId: "my-extension-id" },
|
|
182
|
+
* routes: [{ index: true, element: <MainPage /> }],
|
|
183
|
+
* });
|
|
184
|
+
* ```
|
|
185
|
+
*/
|
|
186
|
+
declare function createExtensionApp({
|
|
187
|
+
metadata,
|
|
188
|
+
routes,
|
|
189
|
+
root: customRoot
|
|
190
|
+
}: CreateExtensionAppOptions): void;
|
|
191
|
+
//#endregion
|
|
192
|
+
export { type CreateExtensionAppOptions, type ExtensionAppRoutes, type ExtensionRoute, type HostConnection, type ImsContext, type IndexRoute, type MassActionContext, type OrderViewButtonContext, type SharedContext, createExtensionApp, useCommerce, useHostConnection, useIms, useMassActionContext, useOrderViewButtonContext, useSharedContext };
|
|
@@ -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,57 @@
|
|
|
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.ts
|
|
16
|
+
/**
|
|
17
|
+
* Fixed, constant prefix that every Admin UI SDK ACL resource id starts with.
|
|
18
|
+
* It is owned by Commerce and is a stable part of the cross-repo id contract.
|
|
19
|
+
*
|
|
20
|
+
* @internal Exported for use by domain ACL helpers only — not part of the public API.
|
|
21
|
+
*/
|
|
22
|
+
const PREFIX = "Magento_CommerceBackendUix::adminuisdk_app_";
|
|
23
|
+
/**
|
|
24
|
+
* Sanitizes a single ACL id segment: trims whitespace, lowercases, and replaces every
|
|
25
|
+
* character outside [a-z0-9_] with an underscore.
|
|
26
|
+
*
|
|
27
|
+
* @internal Exported for use by domain ACL helpers only — not part of the public API.
|
|
28
|
+
*/
|
|
29
|
+
function sanitizeSegment(segment) {
|
|
30
|
+
return segment.trim().toLowerCase().replace(/[^a-z0-9_]/g, "_");
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Derives the deterministic Commerce ACL resource id for an app from its metadata id.
|
|
34
|
+
*
|
|
35
|
+
* The id is assembled as {@link PREFIX} + sanitized `metadataId`, where sanitization trims
|
|
36
|
+
* whitespace, lowercases, and replaces every character outside `[a-z0-9_]` with `_`.
|
|
37
|
+
* `"Magento_CommerceBackendUix::adminuisdk_app_"` is that fixed constant prefix — not a
|
|
38
|
+
* placeholder — so the example below is fully reproducible from the given argument:
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```
|
|
42
|
+
* getAclResourceId("approval-dashboard-app")
|
|
43
|
+
* // PREFIX + sanitize("approval-dashboard-app")
|
|
44
|
+
* // "Magento_CommerceBackendUix::adminuisdk_app_" + "approval_dashboard_app"
|
|
45
|
+
* // → "Magento_CommerceBackendUix::adminuisdk_app_approval_dashboard_app"
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* @param metadataId - The application's `metadata.id` value (e.g. `"approval-dashboard-app"`).
|
|
49
|
+
* @returns The full Commerce ACL resource id, or an empty string when `metadataId` is blank.
|
|
50
|
+
*/
|
|
51
|
+
function getAclResourceId(metadataId) {
|
|
52
|
+
if (metadataId.trim() === "") return "";
|
|
53
|
+
return `${PREFIX}${sanitizeSegment(metadataId)}`;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
//#endregion
|
|
57
|
+
export { sanitizeSegment as n, getAclResourceId as t };
|
|
@@ -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.mjs";
|
|
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 };
|
|
@@ -0,0 +1,262 @@
|
|
|
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 { t as getAclResourceId } from "../acl-resource-id-pryVxI_c.mjs";
|
|
16
|
+
import { t as parseOrThrow } from "../utils-COPGW1HO.mjs";
|
|
17
|
+
import { CommerceSdkErrorBase } from "@adobe/aio-commerce-lib-core/error";
|
|
18
|
+
import { AdobeCommerceHttpClient, ApiClient } from "@adobe/aio-commerce-lib-api";
|
|
19
|
+
import * as v from "valibot";
|
|
20
|
+
import { HTTPError } from "ky";
|
|
21
|
+
|
|
22
|
+
//#region \0rolldown/runtime.js
|
|
23
|
+
var __defProp = Object.defineProperty;
|
|
24
|
+
var __exportAll = (all, no_symbols) => {
|
|
25
|
+
let target = {};
|
|
26
|
+
for (var name in all) {
|
|
27
|
+
__defProp(target, name, {
|
|
28
|
+
get: all[name],
|
|
29
|
+
enumerable: true
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
if (!no_symbols) {
|
|
33
|
+
__defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
34
|
+
}
|
|
35
|
+
return target;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
//#endregion
|
|
39
|
+
//#region source/errors.ts
|
|
40
|
+
/** Base error for Admin UI SDK permission helper failures. */
|
|
41
|
+
var AdminUiPermissionError = class extends CommerceSdkErrorBase {};
|
|
42
|
+
/** Error thrown when the current user is denied access to an Admin UI SDK ACL resource. */
|
|
43
|
+
var AdminUiPermissionDeniedError = class extends AdminUiPermissionError {
|
|
44
|
+
resource;
|
|
45
|
+
constructor(resource, options) {
|
|
46
|
+
super(`Admin UI SDK permission denied for resource: ${resource}`, options);
|
|
47
|
+
this.resource = resource;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
//#endregion
|
|
52
|
+
//#region source/api/config/endpoints.ts
|
|
53
|
+
var endpoints_exports$1 = /* @__PURE__ */ __exportAll({ enableAdminUiSdk: () => enableAdminUiSdk });
|
|
54
|
+
/**
|
|
55
|
+
* Enables the Admin UI SDK in Commerce via PUT /V1/adminuisdk/config.
|
|
56
|
+
*
|
|
57
|
+
* This must be called before {@link registerExtension} so that Commerce accepts
|
|
58
|
+
* the extension registration; registering an extension while the SDK is disabled
|
|
59
|
+
* leaves the extension unavailable in the Admin UI.
|
|
60
|
+
*
|
|
61
|
+
* @param httpClient - The {@link AdobeCommerceHttpClient} to use to make the request.
|
|
62
|
+
* @param fetchOptions - Optional Ky fetch options.
|
|
63
|
+
*
|
|
64
|
+
* @throws An `HTTPError` if the status code is not 2XX.
|
|
65
|
+
*/
|
|
66
|
+
async function enableAdminUiSdk(httpClient, fetchOptions) {
|
|
67
|
+
return httpClient.put("adminuisdk/config", {
|
|
68
|
+
...fetchOptions,
|
|
69
|
+
json: { enableAdminUiSdk: true }
|
|
70
|
+
}).json();
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
//#endregion
|
|
74
|
+
//#region source/api/extensions/schema.ts
|
|
75
|
+
/** Parameters for POST /V1/adminuisdk/extension. */
|
|
76
|
+
const ExtensionRegistrationParamsSchema = v.object({
|
|
77
|
+
extensionName: v.pipe(v.string(), v.minLength(1)),
|
|
78
|
+
extensionTitle: v.pipe(v.string(), v.minLength(1)),
|
|
79
|
+
extensionWorkspace: v.pipe(v.string(), v.minLength(1))
|
|
80
|
+
});
|
|
81
|
+
/** Parameters for DELETE /V1/adminuisdk/extension/{workspaceName}/{extensionName}. */
|
|
82
|
+
const UnregisterExtensionParamsSchema = v.object({
|
|
83
|
+
extensionName: v.pipe(v.string(), v.minLength(1)),
|
|
84
|
+
workspaceName: v.pipe(v.string(), v.minLength(1))
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
//#endregion
|
|
88
|
+
//#region source/api/extensions/endpoints.ts
|
|
89
|
+
var endpoints_exports = /* @__PURE__ */ __exportAll({
|
|
90
|
+
registerExtension: () => registerExtension,
|
|
91
|
+
unregisterExtension: () => unregisterExtension
|
|
92
|
+
});
|
|
93
|
+
/**
|
|
94
|
+
* Registers an Admin UI extension with Commerce via POST /V1/adminuisdk/extension.
|
|
95
|
+
*
|
|
96
|
+
* @param httpClient - The {@link AdobeCommerceHttpClient} to use to make the request.
|
|
97
|
+
* @param params - The extension registration parameters.
|
|
98
|
+
* @param fetchOptions - Optional Ky fetch options.
|
|
99
|
+
*
|
|
100
|
+
* @throws A `CommerceSdkValidationError` if the parameters are invalid.
|
|
101
|
+
* @throws An `HTTPError` if the status code is not 2XX.
|
|
102
|
+
*/
|
|
103
|
+
async function registerExtension(httpClient, params, fetchOptions) {
|
|
104
|
+
const extension = parseOrThrow(ExtensionRegistrationParamsSchema, params);
|
|
105
|
+
return httpClient.post("adminuisdk/extension", {
|
|
106
|
+
...fetchOptions,
|
|
107
|
+
json: { extension }
|
|
108
|
+
}).json();
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Unregisters an Admin UI extension from Commerce via DELETE /V1/adminuisdk/extension/{workspaceName}/{extensionName}.
|
|
112
|
+
*
|
|
113
|
+
* @param httpClient - The {@link AdobeCommerceHttpClient} to use to make the request.
|
|
114
|
+
* @param params - The workspace and extension names.
|
|
115
|
+
* @param fetchOptions - Optional Ky fetch options.
|
|
116
|
+
*
|
|
117
|
+
* @throws A `CommerceSdkValidationError` if the parameters are invalid.
|
|
118
|
+
* @throws An `HTTPError` if the status code is not 2XX.
|
|
119
|
+
*/
|
|
120
|
+
async function unregisterExtension(httpClient, params, fetchOptions) {
|
|
121
|
+
const { workspaceName, extensionName } = parseOrThrow(UnregisterExtensionParamsSchema, params);
|
|
122
|
+
return httpClient.delete(`adminuisdk/extension/${workspaceName}/${extensionName}`, fetchOptions).then((_res) => {});
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
//#endregion
|
|
126
|
+
//#region source/api/lib/api-client.ts
|
|
127
|
+
/**
|
|
128
|
+
* Creates a new API client for the Admin UI API with all available operations.
|
|
129
|
+
*
|
|
130
|
+
* @param params - The parameters to build the Commerce HTTP client.
|
|
131
|
+
*/
|
|
132
|
+
function createAdminUiApiClient(params) {
|
|
133
|
+
return ApiClient.create(new AdobeCommerceHttpClient(params), {
|
|
134
|
+
...endpoints_exports$1,
|
|
135
|
+
...endpoints_exports
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
//#endregion
|
|
140
|
+
//#region source/api/permissions/schema.ts
|
|
141
|
+
/** Response shape returned by the Admin UI SDK permission check endpoint. */
|
|
142
|
+
const permissionCheckResponseSchema = v.object({ allowed: v.boolean() });
|
|
143
|
+
|
|
144
|
+
//#endregion
|
|
145
|
+
//#region source/api/permissions/endpoints.ts
|
|
146
|
+
/**
|
|
147
|
+
* Checks whether the current user has the given ACL resource granted via POST /V1/adminuisdk/permission/check.
|
|
148
|
+
* This is the raw HTTP call — prefer {@link getAdminUiPermissionClient} for caching and deduplication.
|
|
149
|
+
*
|
|
150
|
+
* @param httpClient - The {@link AdobeCommerceHttpClient} to use to make the request.
|
|
151
|
+
* @param params - The resource to check.
|
|
152
|
+
*
|
|
153
|
+
* @throws {@link HTTPError} if the response status is not in the 2xx range.
|
|
154
|
+
*/
|
|
155
|
+
async function checkPermission(httpClient, params) {
|
|
156
|
+
return parseOrThrow(permissionCheckResponseSchema, await httpClient.post("adminuisdk/permission/check", { json: { resource: params.resource } }).json());
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
//#endregion
|
|
160
|
+
//#region source/api/lib/permission-client.ts
|
|
161
|
+
const DEFAULT_CACHE_TTL_MS = 3e5;
|
|
162
|
+
/** Returns true when the error is an HTTP 401 Unauthorized response from ky. */
|
|
163
|
+
function isUnauthorizedError(error) {
|
|
164
|
+
return error instanceof HTTPError && error.response.status === 401;
|
|
165
|
+
}
|
|
166
|
+
/** Wraps an arbitrary thrown value in an `AdminUiPermissionError`, passing through instances that are already one. */
|
|
167
|
+
function toPermissionError(error) {
|
|
168
|
+
return error instanceof AdminUiPermissionError ? error : new AdminUiPermissionError("Permission check failed", { cause: error });
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Creates a client for checking Admin UI SDK ACL resources.
|
|
172
|
+
*
|
|
173
|
+
* @param options - Client configuration; see {@link AdminUiPermissionClientOptions}.
|
|
174
|
+
* @returns An {@link AdminUiPermissionClient} for checking and requiring ACL resources.
|
|
175
|
+
*/
|
|
176
|
+
function getAdminUiPermissionClient(options) {
|
|
177
|
+
const { httpClient, appId, cacheTtlMs = DEFAULT_CACHE_TTL_MS, denyOnError = true } = options;
|
|
178
|
+
const cache = /* @__PURE__ */ new Map();
|
|
179
|
+
const inFlight = /* @__PURE__ */ new Map();
|
|
180
|
+
/**
|
|
181
|
+
* Performs the network request for `resource` and maps the outcome to a `PermissionCheckResult`.
|
|
182
|
+
* Always throws `AdminUiPermissionError` on 401. On other errors, returns a non-cacheable error
|
|
183
|
+
* result when `denyOnError` is true, or re-throws otherwise.
|
|
184
|
+
*/
|
|
185
|
+
async function fetchCheck(resource) {
|
|
186
|
+
try {
|
|
187
|
+
return {
|
|
188
|
+
allowed: (await checkPermission(httpClient, { resource })).allowed,
|
|
189
|
+
cacheable: true
|
|
190
|
+
};
|
|
191
|
+
} catch (error) {
|
|
192
|
+
if (isUnauthorizedError(error)) throw new AdminUiPermissionError("Unauthorized", { cause: error });
|
|
193
|
+
if (denyOnError) return {
|
|
194
|
+
cacheable: false,
|
|
195
|
+
error: toPermissionError(error)
|
|
196
|
+
};
|
|
197
|
+
throw toPermissionError(error);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Returns a permission check result for `resource`, serving from the TTL cache or an
|
|
202
|
+
* in-flight request when available, and falling back to a fresh `fetchCheck` call otherwise.
|
|
203
|
+
* Successful cacheable results are written to the TTL cache once the in-flight promise settles.
|
|
204
|
+
*/
|
|
205
|
+
function resolveCheck(resource) {
|
|
206
|
+
if (cacheTtlMs > 0) {
|
|
207
|
+
const cached = cache.get(resource);
|
|
208
|
+
if (cached !== void 0 && cached.expiresAt > Date.now()) return {
|
|
209
|
+
allowed: cached.value,
|
|
210
|
+
cacheable: true
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
const existing = inFlight.get(resource);
|
|
214
|
+
if (existing !== void 0) return existing;
|
|
215
|
+
const trackedPromise = fetchCheck(resource).then((result) => {
|
|
216
|
+
if (cacheTtlMs > 0 && result.cacheable && inFlight.get(resource) === trackedPromise) cache.set(resource, {
|
|
217
|
+
expiresAt: Date.now() + cacheTtlMs,
|
|
218
|
+
value: result.allowed
|
|
219
|
+
});
|
|
220
|
+
return result;
|
|
221
|
+
}).finally(() => {
|
|
222
|
+
if (inFlight.get(resource) === trackedPromise) inFlight.delete(resource);
|
|
223
|
+
});
|
|
224
|
+
inFlight.set(resource, trackedPromise);
|
|
225
|
+
return trackedPromise;
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Resolves the ACL resource id for a call: uses the explicit argument when provided,
|
|
229
|
+
* otherwise derives it from `appId`. Returns an empty string when neither source yields a
|
|
230
|
+
* valid id, which callers interpret as "no resource available."
|
|
231
|
+
*/
|
|
232
|
+
function resolveResource(resource) {
|
|
233
|
+
return resource ?? getAclResourceId(appId ?? "");
|
|
234
|
+
}
|
|
235
|
+
return {
|
|
236
|
+
async check(resource) {
|
|
237
|
+
const resolved = resolveResource(resource);
|
|
238
|
+
if (resolved === "") return false;
|
|
239
|
+
const result = await resolveCheck(resolved);
|
|
240
|
+
return "error" in result ? false : result.allowed;
|
|
241
|
+
},
|
|
242
|
+
invalidate(resource) {
|
|
243
|
+
if (resource === void 0) {
|
|
244
|
+
cache.clear();
|
|
245
|
+
inFlight.clear();
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
cache.delete(resource);
|
|
249
|
+
inFlight.delete(resource);
|
|
250
|
+
},
|
|
251
|
+
async require(resource) {
|
|
252
|
+
const resolved = resolveResource(resource);
|
|
253
|
+
if (resolved === "") throw new AdminUiPermissionError("No ACL resource ID could be resolved: provide a resource argument or set appId in options");
|
|
254
|
+
const result = await resolveCheck(resolved);
|
|
255
|
+
if ("error" in result) throw result.error;
|
|
256
|
+
if (!result.allowed) throw new AdminUiPermissionDeniedError(resolved);
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
//#endregion
|
|
262
|
+
export { AdminUiPermissionDeniedError, AdminUiPermissionError, createAdminUiApiClient, getAclResourceId, getAdminUiPermissionClient };
|