@adobe/aio-commerce-lib-app 2.1.0 → 2.2.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.
Files changed (48) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/cjs/actions/app-config/index.cjs +5 -5
  3. package/dist/cjs/actions/app-config/index.d.cts +1 -1
  4. package/dist/cjs/actions/association/index.cjs +2 -2
  5. package/dist/cjs/actions/config/index.cjs +2 -2
  6. package/dist/cjs/actions/installation/index.cjs +5 -5
  7. package/dist/cjs/actions/installation/index.d.cts +2 -2
  8. package/dist/cjs/actions/scope-tree/index.cjs +2 -2
  9. package/dist/cjs/{app-Ch19CR6g.d.cts → app-CiZuhrsm.d.cts} +326 -0
  10. package/dist/cjs/commands/index.cjs +10 -9
  11. package/dist/cjs/config/index.browser.d.cts +1 -1
  12. package/dist/cjs/config/index.node.cjs +3 -3
  13. package/dist/cjs/config/index.node.d.cts +88 -4
  14. package/dist/{es/define-C95h_wa0.d.mts → cjs/define-CZRjG5N_.d.cts} +1 -1
  15. package/dist/cjs/{index-D-Qn-irL.d.cts → index-Bu2X-HUh.d.cts} +2 -2
  16. package/dist/cjs/{index.node-CxdwPrOg.cjs → index.node-Boszndri.cjs} +1 -1
  17. package/dist/cjs/management/index.cjs +1 -1
  18. package/dist/cjs/management/index.d.cts +1 -1
  19. package/dist/cjs/{management-C_JQpgVB.cjs → management-C_cVbr0s.cjs} +17 -5
  20. package/dist/cjs/{openapi-DFoMdZzI.cjs → openapi-c06taOv1.cjs} +412 -45
  21. package/dist/cjs/{validate-B0rOILvG.cjs → validate-CunJ4fUD.cjs} +1 -1
  22. package/dist/cjs/{router-DpB8wpR2.cjs → version-CUu8Ks59.cjs} +77 -19
  23. package/dist/cjs/{webhooks-TvDm57xt.cjs → webhooks-C5ONLbQ4.cjs} +53 -12
  24. package/dist/{es/webhooks-C9vMZZDZ.d.mts → cjs/webhooks-DX7km8wk.d.cts} +266 -10
  25. package/dist/es/actions/app-config/index.d.mts +1 -1
  26. package/dist/es/actions/app-config/index.mjs +5 -5
  27. package/dist/es/actions/association/index.mjs +2 -2
  28. package/dist/es/actions/config/index.mjs +2 -2
  29. package/dist/es/actions/installation/index.d.mts +2 -2
  30. package/dist/es/actions/installation/index.mjs +5 -5
  31. package/dist/es/actions/scope-tree/index.mjs +2 -2
  32. package/dist/es/{app-Ch19CR6g.d.mts → app-CiZuhrsm.d.mts} +326 -0
  33. package/dist/es/commands/index.mjs +10 -9
  34. package/dist/es/config/index.browser.d.mts +1 -1
  35. package/dist/es/config/index.node.d.mts +88 -4
  36. package/dist/es/config/index.node.mjs +3 -3
  37. package/dist/{cjs/define-C12IwNNN.d.cts → es/define-9bwRE_UG.d.mts} +1 -1
  38. package/dist/es/{index-VgCNSlLP.d.mts → index-Cho-eRFD.d.mts} +2 -2
  39. package/dist/es/{index.node-C8EXBW94.mjs → index.node-BVO6sC7z.mjs} +1 -1
  40. package/dist/es/management/index.d.mts +1 -1
  41. package/dist/es/management/index.mjs +1 -1
  42. package/dist/es/{management-DKDR7-fX.mjs → management-BYmbjhGb.mjs} +17 -5
  43. package/dist/es/{openapi-E_1RFhAr.mjs → openapi-C_TGWLou.mjs} +412 -45
  44. package/dist/es/{validate-CiJIjyOr.mjs → validate-D-Oh-sxE.mjs} +1 -1
  45. package/dist/es/{router-C23GIyGQ.mjs → version-C-Pkqohl.mjs} +71 -20
  46. package/dist/{cjs/webhooks-Buu1d7AB.d.cts → es/webhooks-B7UjO8dd.d.mts} +266 -10
  47. package/dist/es/{webhooks-CfrYeMy_.mjs → webhooks-CMb_05b6.mjs} +48 -13
  48. package/package.json +3 -3
@@ -13,7 +13,7 @@
13
13
  */
14
14
 
15
15
  const require_rolldown_runtime = require("./rolldown-runtime-CoOt0iuZ.cjs");
16
- const require_webhooks = require("./webhooks-TvDm57xt.cjs");
16
+ const require_webhooks = require("./webhooks-C5ONLbQ4.cjs");
17
17
  const require_schemas = require("./schemas-B6ITl1bG.cjs");
18
18
  let _adobe_aio_commerce_lib_config = require("@adobe/aio-commerce-lib-config");
19
19
  let _adobe_aio_commerce_lib_core_error = require("@adobe/aio-commerce-lib-core/error");
@@ -17,6 +17,8 @@ let _adobe_aio_commerce_lib_core_responses = require("@adobe/aio-commerce-lib-co
17
17
  let _adobe_aio_lib_core_logging = require("@adobe/aio-lib-core-logging");
18
18
  _adobe_aio_lib_core_logging = require_rolldown_runtime.__toESM(_adobe_aio_lib_core_logging, 1);
19
19
  let regexparam = require("regexparam");
20
+ let _adobe_aio_commerce_lib_config_package_json = require("@adobe/aio-commerce-lib-config/package.json");
21
+ _adobe_aio_commerce_lib_config_package_json = require_rolldown_runtime.__toESM(_adobe_aio_commerce_lib_config_package_json, 1);
20
22
 
21
23
  // ../../packages-private/common-utils/source/actions/http/middleware/logger.ts
22
24
  /**
@@ -159,6 +161,36 @@ function parseQueryParams(queryString, fallbackParams) {
159
161
  var HttpActionRouter = class HttpActionRouter {
160
162
  routes = [];
161
163
  contextBuilders = [];
164
+ defaultHeaders;
165
+ /**
166
+ * @param options - Router options.
167
+ *
168
+ * @example
169
+ * ```typescript
170
+ * const router = new HttpActionRouter({ headers: { "x-content-type-options": "nosniff" } });
171
+ * ```
172
+ */
173
+ constructor(options = {}) {
174
+ this.defaultHeaders = { ...options.headers };
175
+ }
176
+ /** Adds the default headers to a response. Headers already on the response win. */
177
+ withDefaultHeaders(response) {
178
+ const defaults = Object.entries(this.defaultHeaders);
179
+ if (defaults.length === 0) return response;
180
+ const headers = { ...(response.type === "error" ? response.error : response).headers };
181
+ const present = new Set(Object.keys(headers).map((k) => k.toLowerCase()));
182
+ for (const [name, value] of defaults) if (!present.has(name.toLowerCase())) headers[name] = value;
183
+ return response.type === "error" ? {
184
+ ...response,
185
+ error: {
186
+ ...response.error,
187
+ headers
188
+ }
189
+ } : {
190
+ ...response,
191
+ headers
192
+ };
193
+ }
162
194
  /**
163
195
  * Internal method to add a route to the router.
164
196
  */
@@ -390,34 +422,60 @@ var HttpActionRouter = class HttpActionRouter {
390
422
  * ```
391
423
  */
392
424
  handler() {
393
- return async (args) => {
394
- const method = (args.__ow_method ?? "get").toUpperCase();
395
- const rawPath = args.__ow_path ?? "/";
396
- const path = rawPath.startsWith("/") ? rawPath : `/${rawPath}`;
397
- const headers = args.__ow_headers ?? {};
398
- const body = parseRequestBody(args.__ow_body, args);
399
- const query = parseQueryParams(args.__ow_query, args);
400
- const context = await this.buildContext(args);
401
- const matchedMethods = [];
402
- for (const route of this.routes) {
403
- const match = route.pattern.exec(path);
404
- if (!match) continue;
405
- matchedMethods.push(route.method);
406
- if (route.method !== method) continue;
407
- return await HttpActionRouter.handleRoute(route, match, body, query, headers, method, path, context);
408
- }
409
- if (matchedMethods.length > 0) return (0, _adobe_aio_commerce_lib_core_responses.methodNotAllowed)(`Method ${method} not allowed`);
410
- return (0, _adobe_aio_commerce_lib_core_responses.notFound)(`No route matches ${path}`);
411
- };
425
+ return async (args) => this.withDefaultHeaders(await this.dispatch(args));
426
+ }
427
+ /** Matches the request to a route and runs it. */
428
+ async dispatch(args) {
429
+ const method = (args.__ow_method ?? "get").toUpperCase();
430
+ const rawPath = args.__ow_path ?? "/";
431
+ const path = rawPath.startsWith("/") ? rawPath : `/${rawPath}`;
432
+ const headers = args.__ow_headers ?? {};
433
+ const body = parseRequestBody(args.__ow_body, args);
434
+ const query = parseQueryParams(args.__ow_query, args);
435
+ const context = await this.buildContext(args);
436
+ const matchedMethods = [];
437
+ for (const route of this.routes) {
438
+ const match = route.pattern.exec(path);
439
+ if (!match) continue;
440
+ matchedMethods.push(route.method);
441
+ if (route.method !== method) continue;
442
+ return await HttpActionRouter.handleRoute(route, match, body, query, headers, method, path, context);
443
+ }
444
+ if (matchedMethods.length > 0) return (0, _adobe_aio_commerce_lib_core_responses.methodNotAllowed)(`Method ${method} not allowed`);
445
+ return (0, _adobe_aio_commerce_lib_core_responses.notFound)(`No route matches ${path}`);
412
446
  }
413
447
  };
414
448
 
449
+ // source/actions/version.ts
450
+ /**
451
+ * Name of the response header that carries the versions of the SDK libraries the app-management
452
+ * endpoints were built with. These are not the app's own version.
453
+ */
454
+ const SDK_LIB_VERSIONS_HEADER = "x-ac-sdk-lib-versions";
455
+ const UNKNOWN_VERSION = "unknown";
456
+ /**
457
+ * Value of {@link SDK_LIB_VERSIONS_HEADER}, an RFC 8941 dictionary with string values, e.g.
458
+ * `lib-app="2.2.0", lib-config="1.4.1"`. TSDown and Vitest replace `__PKG_VERSION__` for
459
+ * `lib-app`, which is "unknown" when the variable is not defined. `lib-config` is the version
460
+ * in the `package.json` of the copy of lib-config that lib-app loads, which the app's bundler
461
+ * resolves when it builds the action.
462
+ */
463
+ const SDK_LIB_VERSIONS = [["lib-app", "2.2.0-beta-20261105172845"], ["lib-config", _adobe_aio_commerce_lib_config_package_json.default.version ?? UNKNOWN_VERSION]].map(([name, version]) => `${name}="${version}"`).join(", ");
464
+ /** Headers every app-management router adds to its responses. */
465
+ const SDK_LIB_VERSIONS_HEADERS = { [SDK_LIB_VERSIONS_HEADER]: SDK_LIB_VERSIONS };
466
+
415
467
  Object.defineProperty(exports, "HttpActionRouter", {
416
468
  enumerable: true,
417
469
  get: function () {
418
470
  return HttpActionRouter;
419
471
  }
420
472
  });
473
+ Object.defineProperty(exports, "SDK_LIB_VERSIONS_HEADERS", {
474
+ enumerable: true,
475
+ get: function () {
476
+ return SDK_LIB_VERSIONS_HEADERS;
477
+ }
478
+ });
421
479
  Object.defineProperty(exports, "logger", {
422
480
  enumerable: true,
423
481
  get: function () {
@@ -107,7 +107,7 @@ const ViewButtonLevelSchema = valibot.picklist([
107
107
  0,
108
108
  1
109
109
  ]);
110
- const OrderViewButtonSchema = valibot.variant("type", [valibot.strictObject({
110
+ const ViewButtonViewSchema = valibot.strictObject({
111
111
  aclProtected: valibot.optional(valibot.boolean()),
112
112
  confirm: valibot.optional(ConfirmSchema),
113
113
  description: valibot.optional(require_schemas.nonEmptyStringValueSchema("view button description")),
@@ -119,7 +119,8 @@ const OrderViewButtonSchema = valibot.variant("type", [valibot.strictObject({
119
119
  sandboxPermissions: valibot.optional(SandboxPermissionsSchema),
120
120
  sortOrder: valibot.optional(require_schemas.positiveNumberValueSchema("sortOrder")),
121
121
  type: valibot.literal("view")
122
- }), valibot.strictObject({
122
+ });
123
+ const ViewButtonWorkerSchema = valibot.strictObject({
123
124
  aclProtected: valibot.optional(valibot.boolean()),
124
125
  confirm: valibot.optional(ConfirmSchema),
125
126
  description: valibot.optional(require_schemas.nonEmptyStringValueSchema("view button description")),
@@ -131,7 +132,16 @@ const OrderViewButtonSchema = valibot.variant("type", [valibot.strictObject({
131
132
  sortOrder: valibot.optional(require_schemas.positiveNumberValueSchema("sortOrder")),
132
133
  timeout: valibot.optional(require_schemas.positiveNumberValueSchema("timeout")),
133
134
  type: valibot.literal("worker")
134
- })]);
135
+ });
136
+ const OrderViewButtonSchema = valibot.variant("type", [ViewButtonViewSchema, ViewButtonWorkerSchema]);
137
+ const InvoiceViewButtonSchema = valibot.variant("type", [valibot.strictObject({
138
+ ...ViewButtonViewSchema.entries,
139
+ title: valibot.optional(require_schemas.nonEmptyStringValueSchema("view button page title"))
140
+ }), ViewButtonWorkerSchema]);
141
+ const CreditMemoViewButtonSchema = valibot.variant("type", [valibot.strictObject({
142
+ ...ViewButtonViewSchema.entries,
143
+ title: valibot.optional(require_schemas.nonEmptyStringValueSchema("view button page title"))
144
+ }), ViewButtonWorkerSchema]);
135
145
  const MassActionsSchema = valibot.pipe(valibot.array(MassActionSchema), valibot.check((items) => hasUniqueSanitizedIds(items), "Mass action ids must be unique after Commerce id sanitization."));
136
146
  const AdminUiOrderSchema = valibot.object({
137
147
  gridColumns: valibot.optional(GridColumnsSchema),
@@ -142,6 +152,14 @@ const AdminUiGridAndMassActionEntitySchema = valibot.object({
142
152
  gridColumns: valibot.optional(GridColumnsSchema),
143
153
  massActions: valibot.optional(MassActionsSchema)
144
154
  });
155
+ const AdminUiInvoiceSchema = valibot.object({
156
+ gridColumns: valibot.optional(GridColumnsSchema),
157
+ viewButtons: valibot.optional(valibot.pipe(valibot.array(InvoiceViewButtonSchema), valibot.check((items) => hasUniqueSanitizedIds(items), "Invoice view button ids must be unique after Commerce id sanitization.")))
158
+ });
159
+ const AdminUiCreditMemoSchema = valibot.object({
160
+ gridColumns: valibot.optional(GridColumnsSchema),
161
+ viewButtons: valibot.optional(valibot.pipe(valibot.array(CreditMemoViewButtonSchema), valibot.check((items) => hasUniqueSanitizedIds(items), "Credit memo view button ids must be unique after Commerce id sanitization.")))
162
+ });
145
163
  const AdminUiGridOnlyEntitySchema = valibot.object({ gridColumns: valibot.optional(GridColumnsSchema) });
146
164
  const MenuIdSchema = valibot.pipe(require_schemas.nonEmptyStringValueSchema("menu ID"), valibot.regex(/^[A-Za-z0-9_/:]+$/u, "Menu ID may contain only letters, digits, \"/\", \":\", and \"_\""));
147
165
  const MenuSchema = valibot.object({
@@ -158,6 +176,14 @@ const MenuSchema = valibot.object({
158
176
  parentMenu: valibot.optional(valibot.picklist(_adobe_aio_commerce_lib_admin_ui_menu.COMMERCE_MENUS, "parentMenu must be a known Commerce Admin menu ID")),
159
177
  sandboxPermissions: valibot.optional(SandboxPermissionsSchema)
160
178
  });
179
+ const NATIVE_UI_REPLACED_PAGE_TARGETS = ["order.create"];
180
+ const NativeUiReplacedPageSchema = valibot.strictObject({
181
+ path: require_schemas.nonEmptyStringValueSchema("replaced page path"),
182
+ sandboxPermissions: valibot.optional(SandboxPermissionsSchema),
183
+ target: valibot.picklist(NATIVE_UI_REPLACED_PAGE_TARGETS, `Invalid native UI replaced page target. Accepted values are: ${NATIVE_UI_REPLACED_PAGE_TARGETS.join(", ")}`),
184
+ title: require_schemas.nonEmptyStringValueSchema("replaced page title")
185
+ });
186
+ const NativeUiSchema = valibot.object({ replacedPages: valibot.pipe(valibot.array(NativeUiReplacedPageSchema), valibot.check((pages) => new Set(pages.map((page) => page.target)).size === pages.length, "Native UI replaced page targets must be unique.")) });
161
187
  const AclResourceIdSchema = valibot.pipe(require_schemas.nonEmptyStringValueSchema("acl resource ID"), valibot.regex(/^[a-z0-9_]+$/u, "ACL resource ID may contain only lowercase letters, digits, and \"_\""));
162
188
  const ACL_LABEL_MIN_LENGTH = 3;
163
189
  const ACL_LABEL_MAX_LENGTH = 50;
@@ -194,14 +220,15 @@ const AdminUiAclSchema = valibot.pipe(valibot.array(AclResourceEntrySchema), val
194
220
  }, "Custom ACL resource ids must stay unique after Commerce derivation: a top-level resource id must not equal a group's \"<group>_<child>\" combination."));
195
221
  /**
196
222
  * Schema for the `adminUi` config section.
197
- * Supports grid column extensions, mass actions, order view buttons, menu, and custom ACL resources on `commerce/backend-ui/2`.
223
+ * Supports grid column extensions, mass actions, order, invoice, and credit memo view buttons, menu, native UI replaced pages, and custom ACL resources on `commerce/backend-ui/2`.
198
224
  */
199
225
  const AdminUiSchema = valibot.object({
200
226
  acl: valibot.optional(AdminUiAclSchema),
201
- creditMemo: valibot.optional(AdminUiGridOnlyEntitySchema),
227
+ creditMemo: valibot.optional(AdminUiCreditMemoSchema),
202
228
  customer: valibot.optional(AdminUiGridAndMassActionEntitySchema),
203
- invoice: valibot.optional(AdminUiGridOnlyEntitySchema),
229
+ invoice: valibot.optional(AdminUiInvoiceSchema),
204
230
  menu: valibot.optional(MenuSchema),
231
+ nativeUi: valibot.optional(NativeUiSchema),
205
232
  newsletter: valibot.optional(AdminUiGridOnlyEntitySchema),
206
233
  order: valibot.optional(AdminUiOrderSchema),
207
234
  product: valibot.optional(AdminUiGridAndMassActionEntitySchema),
@@ -226,22 +253,30 @@ const ADMIN_UI_MASS_ACTION_ENTITIES = [
226
253
  "product",
227
254
  "customer"
228
255
  ];
256
+ /** Entities that support view buttons, in a stable order. */
257
+ const ADMIN_UI_VIEW_BUTTON_ENTITIES = [
258
+ "order",
259
+ "invoice",
260
+ "creditMemo"
261
+ ];
229
262
  /**
230
263
  * Check whether the config declares an Admin UI component that requires the
231
264
  * `commerce/backend-ui/2` extension point — a menu, grid columns, mass actions,
232
- * or view buttons. Custom ACL resources are deliberately excluded: they reach
233
- * Commerce through the `extensibility/1` app-config payload, not backend-ui/2,
234
- * so an acl-only config needs no backend-ui/2 registration.
265
+ * view buttons, or native UI replaced pages. Custom ACL resources are
266
+ * deliberately excluded: they reach Commerce through the `extensibility/1`
267
+ * app-config payload, not backend-ui/2, so an acl-only config needs no
268
+ * backend-ui/2 registration.
235
269
  */
236
270
  function hasBackendUiV2Components(config) {
237
271
  const { adminUi } = config;
238
272
  if (!adminUi) return false;
239
- return Boolean(adminUi.menu || adminUi.order?.gridColumns || adminUi.order?.massActions?.length || adminUi.order?.viewButtons?.length || adminUi.product?.gridColumns || adminUi.product?.massActions?.length || adminUi.customer?.gridColumns || adminUi.customer?.massActions?.length || adminUi.invoice?.gridColumns || adminUi.creditMemo?.gridColumns || adminUi.shipment?.gridColumns || adminUi.newsletter?.gridColumns);
273
+ return Boolean(adminUi.menu || adminUi.order?.gridColumns || adminUi.order?.massActions?.length || adminUi.order?.viewButtons?.length || adminUi.product?.gridColumns || adminUi.product?.massActions?.length || adminUi.customer?.gridColumns || adminUi.customer?.massActions?.length || adminUi.invoice?.gridColumns || adminUi.invoice?.viewButtons?.length || adminUi.creditMemo?.gridColumns || adminUi.creditMemo?.viewButtons?.length || adminUi.shipment?.gridColumns || adminUi.nativeUi?.replacedPages?.length || adminUi.newsletter?.gridColumns);
240
274
  }
241
275
  /**
242
276
  * Check whether the config declares at least one Admin UI component (menu, grid
243
- * columns, mass actions, view buttons, or custom ACL resources). A component-less `adminUi` block is
244
- * treated as absent — it registers nothing.
277
+ * columns, mass actions, view buttons, native UI replaced pages, or custom ACL
278
+ * resources). A component-less `adminUi` block is treated as absent — it
279
+ * registers nothing.
245
280
  */
246
281
  function hasAdminUi(config) {
247
282
  return hasBackendUiV2Components(config) || Boolean(config.adminUi?.acl?.length);
@@ -557,6 +592,12 @@ Object.defineProperty(exports, "ADMIN_UI_MASS_ACTION_ENTITIES", {
557
592
  return ADMIN_UI_MASS_ACTION_ENTITIES;
558
593
  }
559
594
  });
595
+ Object.defineProperty(exports, "ADMIN_UI_VIEW_BUTTON_ENTITIES", {
596
+ enumerable: true,
597
+ get: function () {
598
+ return ADMIN_UI_VIEW_BUTTON_ENTITIES;
599
+ }
600
+ });
560
601
  Object.defineProperty(exports, "AdminUiSchema", {
561
602
  enumerable: true,
562
603
  get: function () {