@adobe/aio-commerce-lib-app 0.3.2 → 1.0.0

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 (78) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/README.md +1 -4
  3. package/bin/cli.mjs +24 -0
  4. package/dist/cjs/actions/app-config.cjs +27 -0
  5. package/dist/cjs/actions/app-config.d.cts +15 -0
  6. package/dist/cjs/actions/config.cjs +79 -0
  7. package/dist/cjs/actions/config.d.cts +15 -0
  8. package/dist/cjs/actions/installation.cjs +424 -0
  9. package/dist/cjs/actions/{index.d.cts → installation.d.cts} +4 -3
  10. package/dist/cjs/actions/scope-tree.cjs +97 -0
  11. package/dist/cjs/actions/scope-tree.d.cts +8 -0
  12. package/dist/cjs/{app-Dx0ca6oL.d.cts → app-PTKvEBea.d.cts} +6 -6
  13. package/dist/cjs/commands/generate/actions/templates/app-management/app-config.js.template +22 -0
  14. package/dist/cjs/commands/generate/actions/templates/app-management/installation.js.template +1 -1
  15. package/dist/cjs/commands/generate/actions/templates/business-configuration/config.js.template +22 -0
  16. package/dist/cjs/commands/generate/actions/templates/business-configuration/scope-tree.js.template +18 -0
  17. package/dist/cjs/commands/index.cjs +91 -106
  18. package/dist/cjs/config/index.cjs +21 -19
  19. package/dist/cjs/config/index.d.cts +32 -332
  20. package/dist/cjs/error-DJ2UAPH2.cjs +24 -0
  21. package/dist/cjs/installation-nwF2RC7F.cjs +241 -0
  22. package/dist/cjs/{logging-DYwr5WQk.cjs → logging-IDRQG0as.cjs} +2 -2
  23. package/dist/cjs/management/index.cjs +9 -8
  24. package/dist/cjs/management/index.d.cts +2 -2
  25. package/dist/cjs/parser-DIchX9SL.cjs +267 -0
  26. package/dist/cjs/router-DCw7oEQ9.cjs +417 -0
  27. package/dist/cjs/{management-Dm5h0E6l.cjs → runner-CUJ8RHzY.cjs} +24 -30
  28. package/dist/{es/index-Bxr3zvCT.d.mts → cjs/runner-Ds2m27Q4.d.cts} +49 -95
  29. package/dist/cjs/schemas-CZ6c8Id9.cjs +98 -0
  30. package/dist/cjs/validate-BegMfe-i.cjs +235 -0
  31. package/dist/es/actions/app-config.d.mts +15 -0
  32. package/dist/es/actions/app-config.mjs +25 -0
  33. package/dist/es/actions/config.d.mts +15 -0
  34. package/dist/es/actions/config.mjs +77 -0
  35. package/dist/es/actions/{index.d.mts → installation.d.mts} +4 -3
  36. package/dist/es/actions/{index.mjs → installation.mjs} +27 -427
  37. package/dist/es/actions/scope-tree.d.mts +8 -0
  38. package/dist/es/actions/scope-tree.mjs +95 -0
  39. package/dist/es/{app-Cx1-6dn0.d.mts → app-vKXaAr6f.d.mts} +6 -6
  40. package/dist/es/commands/generate/actions/templates/app-management/app-config.js.template +22 -0
  41. package/dist/es/commands/generate/actions/templates/app-management/installation.js.template +1 -1
  42. package/dist/es/commands/generate/actions/templates/business-configuration/config.js.template +22 -0
  43. package/dist/es/commands/generate/actions/templates/business-configuration/scope-tree.js.template +18 -0
  44. package/dist/es/commands/index.mjs +68 -84
  45. package/dist/es/config/index.d.mts +32 -332
  46. package/dist/es/config/index.mjs +3 -2
  47. package/dist/es/error-CMV3IjBz.mjs +18 -0
  48. package/dist/es/{error-P7JgUTds.mjs → installation-SWIwhpKT.mjs} +72 -124
  49. package/dist/es/management/index.d.mts +2 -3
  50. package/dist/es/management/index.mjs +1 -1
  51. package/dist/es/parser-CKQyrTB7.mjs +201 -0
  52. package/dist/es/router-CJ4VWoCt.mjs +404 -0
  53. package/dist/es/{management-Y7pwEbNI.mjs → runner-DB2tDBQS.mjs} +17 -24
  54. package/dist/{cjs/index-C5SutkJQ.d.cts → es/runner-Uk7263hG.d.mts} +49 -95
  55. package/dist/es/schemas-B8yIv0_b.mjs +41 -0
  56. package/dist/es/validate-DXI6gwZ2.mjs +187 -0
  57. package/package.json +38 -24
  58. package/dist/cjs/actions/index.cjs +0 -824
  59. package/dist/cjs/commands/generate/actions/templates/app-management/get-app-config.js.template +0 -62
  60. package/dist/cjs/commands/generate/actions/templates/business-configuration/get-config-schema.js.template +0 -63
  61. package/dist/cjs/commands/generate/actions/templates/business-configuration/get-configuration.js.template +0 -104
  62. package/dist/cjs/commands/generate/actions/templates/business-configuration/get-scope-tree.js.template +0 -69
  63. package/dist/cjs/commands/generate/actions/templates/business-configuration/set-configuration.js.template +0 -125
  64. package/dist/cjs/commands/generate/actions/templates/business-configuration/set-custom-scope-tree.js.template +0 -83
  65. package/dist/cjs/commands/generate/actions/templates/business-configuration/sync-commerce-scopes.js.template +0 -113
  66. package/dist/cjs/commands/generate/actions/templates/business-configuration/unsync-commerce-scopes.js.template +0 -56
  67. package/dist/cjs/config-JQ_n-5Nk.cjs +0 -565
  68. package/dist/cjs/error-Byj1DVHZ.cjs +0 -344
  69. package/dist/es/commands/generate/actions/templates/app-management/get-app-config.js.template +0 -62
  70. package/dist/es/commands/generate/actions/templates/business-configuration/get-config-schema.js.template +0 -63
  71. package/dist/es/commands/generate/actions/templates/business-configuration/get-configuration.js.template +0 -104
  72. package/dist/es/commands/generate/actions/templates/business-configuration/get-scope-tree.js.template +0 -69
  73. package/dist/es/commands/generate/actions/templates/business-configuration/set-configuration.js.template +0 -125
  74. package/dist/es/commands/generate/actions/templates/business-configuration/set-custom-scope-tree.js.template +0 -83
  75. package/dist/es/commands/generate/actions/templates/business-configuration/sync-commerce-scopes.js.template +0 -113
  76. package/dist/es/commands/generate/actions/templates/business-configuration/unsync-commerce-scopes.js.template +0 -56
  77. package/dist/es/config-BSGerqCG.mjs +0 -457
  78. /package/dist/es/{logging-VgerMhp6.mjs → logging-CzmXDzxI.mjs} +0 -0
@@ -0,0 +1,95 @@
1
+ import { n as logger, t as HttpActionRouter } from "../router-CJ4VWoCt.mjs";
2
+ import { r as nonEmptyStringValueSchema } from "../schemas-B8yIv0_b.mjs";
3
+ import { t as inspect } from "../logging-CzmXDzxI.mjs";
4
+ import { internalServerError, nonAuthoritativeInformation, ok } from "@adobe/aio-commerce-lib-core/responses";
5
+ import * as v from "valibot";
6
+ import { getScopeTree, setCustomScopeTree, syncCommerceScopes, unsyncCommerceScopes } from "@adobe/aio-commerce-lib-config";
7
+ import { resolveCommerceHttpClientParams } from "@adobe/aio-commerce-lib-api";
8
+
9
+ //#region source/actions/scope-tree.ts
10
+ const router = new HttpActionRouter().use(logger());
11
+ /** GET / - Get scope tree */
12
+ router.get("/", { handler: async (_req, ctx) => {
13
+ const { logger } = ctx;
14
+ const result = await getScopeTree();
15
+ logger.debug(`Successfully retrieved scope tree (cached: ${result.isCachedData}): ${inspect(result.scopeTree)}`);
16
+ if (result.isCachedData) return nonAuthoritativeInformation({
17
+ headers: { "x-cache": "hit" },
18
+ body: { scopes: result.scopeTree }
19
+ });
20
+ return ok({ body: { scopes: result.scopeTree } });
21
+ } });
22
+ /** POST / - Set custom scope tree */
23
+ router.put("/", {
24
+ body: v.object({ scopes: v.array(v.any()) }),
25
+ handler: async (req, ctx) => {
26
+ const { logger } = ctx;
27
+ logger.debug(`Setting custom scope tree with ${req.body.scopes?.length || 0} scopes`);
28
+ const request = { scopes: req.body.scopes };
29
+ logger.debug(`Setting custom scope tree: ${inspect(request)}`);
30
+ const result = await setCustomScopeTree(request);
31
+ logger.debug(`Successfully set custom scope tree: ${inspect(result)}`);
32
+ return ok({
33
+ body: { result },
34
+ headers: { "Cache-Control": "no-store" }
35
+ });
36
+ }
37
+ });
38
+ /** POST /commerce - Sync commerce scopes */
39
+ router.post("/commerce", {
40
+ body: v.object({
41
+ commerceBaseUrl: nonEmptyStringValueSchema("commerceBaseUrl"),
42
+ commerceEnv: v.optional(nonEmptyStringValueSchema("commerceEnv"))
43
+ }),
44
+ handler: async (req, ctx) => {
45
+ const { logger } = ctx;
46
+ logger.debug("Syncing commerce scopes...");
47
+ const { commerceBaseUrl, commerceEnv } = req.body;
48
+ const result = await syncCommerceScopes(resolveCommerceHttpClientParams({
49
+ ...ctx.rawParams,
50
+ AIO_COMMERCE_API_BASE_URL: commerceBaseUrl,
51
+ ...commerceEnv && { AIO_COMMERCE_API_FLAVOR: commerceEnv }
52
+ }, { tryForwardAuthProvider: true }));
53
+ if (result.error) {
54
+ logger.error(`Error syncing commerce scopes: ${inspect(result.error)}`);
55
+ return internalServerError({ body: {
56
+ message: "An internal server error occurred",
57
+ error: result.error
58
+ } });
59
+ }
60
+ if (!result.synced) {
61
+ logger.debug(`Commerce scopes not synced (cached): ${inspect(result.scopeTree)}`);
62
+ return nonAuthoritativeInformation({
63
+ headers: { "x-cache": "hit" },
64
+ body: {
65
+ scopes: result.scopeTree,
66
+ synced: false
67
+ }
68
+ });
69
+ }
70
+ logger.debug(`Successfully synced commerce scopes: ${inspect(result.scopeTree)}`);
71
+ return ok({ body: {
72
+ scopes: result.scopeTree,
73
+ synced: true
74
+ } });
75
+ }
76
+ });
77
+ /** DELETE /commerce - Unsync commerce scopes */
78
+ router.delete("/commerce", { handler: async (_req, ctx) => {
79
+ const { logger } = ctx;
80
+ logger.debug("Unsyncing commerce scopes...");
81
+ const { unsynced } = await unsyncCommerceScopes();
82
+ if (unsynced) {
83
+ const message = "Commerce scopes unsynced successfully";
84
+ logger.debug(message);
85
+ return ok(message);
86
+ }
87
+ const message = "No commerce scopes to unsync";
88
+ logger.debug(message);
89
+ return ok(message);
90
+ } });
91
+ /** The handler method for the `scope-tree` action. */
92
+ const scopeTreeRuntimeAction = router.handler();
93
+
94
+ //#endregion
95
+ export { scopeTreeRuntimeAction };
@@ -40,7 +40,7 @@ declare const CommerceAppConfigSchema: v.LooseObjectSchema<{
40
40
  readonly description: v.OptionalSchema<v.StringSchema<"Expected a string for the field description">, undefined>;
41
41
  }, undefined>, v.ObjectSchema<{
42
42
  readonly type: v.LiteralSchema<"password", "Expected the type to be 'password'">;
43
- readonly default: v.OptionalSchema<v.StringSchema<"Expected a string for the default value">, undefined>;
43
+ readonly default: v.OptionalSchema<v.NeverSchema<"Password fields do not have a default value">, undefined>;
44
44
  readonly name: v.SchemaWithPipe<readonly [v.StringSchema<"Expected a string for the field name">, v.NonEmptyAction<string, "The field name must not be empty">]>;
45
45
  readonly label: v.OptionalSchema<v.StringSchema<"Expected a string for the field label">, undefined>;
46
46
  readonly description: v.OptionalSchema<v.StringSchema<"Expected a string for the field description">, undefined>;
@@ -92,7 +92,7 @@ declare const CommerceAppConfigSchema: v.LooseObjectSchema<{
92
92
  description?: string | undefined;
93
93
  } | {
94
94
  type: "password";
95
- default?: string | undefined;
95
+ default?: undefined;
96
96
  name: string;
97
97
  label?: string | undefined;
98
98
  description?: string | undefined;
@@ -124,7 +124,7 @@ declare const CommerceAppConfigSchema: v.LooseObjectSchema<{
124
124
  readonly key: v.OptionalSchema<v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.StringSchema<`Expected a string value for '${string}'`>, v.RegexAction<string, `Only alphanumeric characters and hyphens are allowed in string value of "${string}"${string}`>]>, v.MaxLengthAction<string, 50, "The provider key must not be longer than 50 characters">]>, undefined>;
125
125
  }, undefined>;
126
126
  readonly events: v.ArraySchema<v.ObjectSchema<{
127
- readonly name: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.StringSchema<`Expected a string value for '${string}'`>, v.NonEmptyAction<string, `The value of "${string}" must not be empty`>]>, v.RegexAction<string, "Event name must start with \"plugin.\" or \"observer.\" followed by lowercase letters and underscores only (e.g., \"plugin.order_placed\")">]>;
127
+ readonly name: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.StringSchema<`Expected a string value for '${string}'`>, v.NonEmptyAction<string, `The value of "${string}" must not be empty`>]>, v.RegexAction<string, "Event name must start with \"plugin.\" or \"observer.\" followed by lowercase letters and underscores only (e.g., \"plugin.order_placed\")">, v.MaxLengthAction<string, 180, "The event name must not be longer than 180 characters">]>;
128
128
  readonly fields: v.ArraySchema<v.ObjectSchema<{
129
129
  readonly name: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.StringSchema<`Expected a string value for '${string}'`>, v.NonEmptyAction<string, `The value of "${string}" must not be empty`>]>, v.RegexAction<string, "Field name must contain only letters (a-z, A-Z), numbers (0-9), underscores (_), dashes (-), dots (.), and square brackets ([, ]), or be exactly \"*\"">]>;
130
130
  readonly source: v.OptionalSchema<v.StringSchema<`Expected a string value for '${string}'`>, undefined>;
@@ -135,8 +135,8 @@ declare const CommerceAppConfigSchema: v.LooseObjectSchema<{
135
135
  readonly value: v.SchemaWithPipe<readonly [v.StringSchema<`Expected a string value for '${string}'`>, v.NonEmptyAction<string, `The value of "${string}" must not be empty`>]>;
136
136
  }, undefined>, "Expected an array of event rules with field, operator, and value">, undefined>;
137
137
  readonly destination: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<`Expected a string value for '${string}'`>, v.NonEmptyAction<string, `The value of "${string}" must not be empty`>]>, undefined>;
138
- readonly hipaaAuditRequired: v.OptionalSchema<v.BooleanSchema<`Expected a boolean value for '${string}'`>, undefined>;
139
- readonly prioritary: v.OptionalSchema<v.BooleanSchema<`Expected a boolean value for '${string}'`>, undefined>;
138
+ readonly hipaa_audit_required: v.OptionalSchema<v.BooleanSchema<`Expected a boolean value for '${string}'`>, undefined>;
139
+ readonly priority: v.OptionalSchema<v.BooleanSchema<`Expected a boolean value for '${string}'`>, undefined>;
140
140
  readonly force: v.OptionalSchema<v.BooleanSchema<`Expected a boolean value for '${string}'`>, undefined>;
141
141
  readonly label: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.StringSchema<`Expected a string value for '${string}'`>, v.NonEmptyAction<string, `The value of "${string}" must not be empty`>]>, v.MaxLengthAction<string, 100, "The event label must not be longer than 100 characters">]>;
142
142
  readonly description: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.StringSchema<`Expected a string value for '${string}'`>, v.NonEmptyAction<string, `The value of "${string}" must not be empty`>]>, v.MaxLengthAction<string, 255, "The event description must not be longer than 255 characters">]>;
@@ -150,7 +150,7 @@ declare const CommerceAppConfigSchema: v.LooseObjectSchema<{
150
150
  readonly key: v.OptionalSchema<v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.StringSchema<`Expected a string value for '${string}'`>, v.RegexAction<string, `Only alphanumeric characters and hyphens are allowed in string value of "${string}"${string}`>]>, v.MaxLengthAction<string, 50, "The provider key must not be longer than 50 characters">]>, undefined>;
151
151
  }, undefined>;
152
152
  readonly events: v.ArraySchema<v.ObjectSchema<{
153
- readonly name: v.SchemaWithPipe<readonly [v.StringSchema<`Expected a string value for '${string}'`>, v.RegexAction<string, `Only alphanumeric characters and underscores are allowed in string value of "${string}"${string}`>]>;
153
+ readonly name: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.StringSchema<`Expected a string value for '${string}'`>, v.NonEmptyAction<string, `The value of "${string}" must not be empty`>]>, v.RegexAction<string, "Event name must contain only letters, digits, underscores, hyphens, and dots (e.g., \"external_event\", \"webhook.received\", \"my-event_123\")">, v.MaxLengthAction<string, 180, "The event name must not be longer than 180 characters">]>;
154
154
  readonly label: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.StringSchema<`Expected a string value for '${string}'`>, v.NonEmptyAction<string, `The value of "${string}" must not be empty`>]>, v.MaxLengthAction<string, 100, "The event label must not be longer than 100 characters">]>;
155
155
  readonly description: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.StringSchema<`Expected a string value for '${string}'`>, v.NonEmptyAction<string, `The value of "${string}" must not be empty`>]>, v.MaxLengthAction<string, 255, "The event description must not be longer than 255 characters">]>;
156
156
  readonly runtimeActions: v.ArraySchema<v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.StringSchema<`Expected a string value for '${string}'`>, v.NonEmptyAction<string, `The value of "${string}" must not be empty`>]>, v.RegexAction<string, "Runtime action must be in the format \"<package>/<action>\" (e.g., \"my-package/my-action\")">]>, "Expected an array of runtime actions in the format <package>/<action>">;
@@ -0,0 +1,22 @@
1
+ /*
2
+ * Copyright 2026 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */
12
+
13
+ // This file has been auto-generated by `@adobe/aio-commerce-lib-app`
14
+ // Do not modify this file directly
15
+
16
+ import { appConfigRuntimeAction } from "@adobe/aio-commerce-lib-app/actions/app-config";
17
+
18
+ // The manifest is always at this relative constant path from the action.
19
+ import commerceAppManifest from "../../app.commerce.manifest.json" with { type: "json" };
20
+
21
+ const args = { appConfig: commerceAppManifest };
22
+ export const main = appConfigRuntimeAction(args);
@@ -13,7 +13,7 @@
13
13
  // This file has been auto-generated by `@adobe/aio-commerce-lib-app`
14
14
  // Do not modify this file directly
15
15
 
16
- import { installationRuntimeAction } from "@adobe/aio-commerce-lib-app/actions"
16
+ import { installationRuntimeAction } from "@adobe/aio-commerce-lib-app/actions/installation"
17
17
  import appConfig from "../../app.commerce.manifest.json" with { type: "json" };
18
18
 
19
19
  // {{CUSTOM_SCRIPTS_LOADER}}
@@ -0,0 +1,22 @@
1
+ /*
2
+ * Copyright 2026 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */
12
+
13
+ // This file has been auto-generated by `@adobe/aio-commerce-lib-app`
14
+ // Do not modify this file directly
15
+
16
+ import { configRuntimeAction } from "@adobe/aio-commerce-lib-app/actions/config";
17
+
18
+ // The config schema is always at this relative constant path from the action.
19
+ import configSchema from "../../configuration-schema.json" with { type: "json" };
20
+
21
+ const args = { configSchema };
22
+ export const main = configRuntimeAction(args);
@@ -0,0 +1,18 @@
1
+ /*
2
+ * Copyright 2026 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */
12
+
13
+ // This file has been auto-generated by `@adobe/aio-commerce-lib-app`
14
+ // Do not modify this file directly
15
+
16
+ import { scopeTreeRuntimeAction } from "@adobe/aio-commerce-lib-app/actions/scope-tree";
17
+
18
+ export const main = scopeTreeRuntimeAction;
@@ -1,7 +1,9 @@
1
1
  #!/usr/bin/env node
2
- import { c as hasCustomInstallationSteps, t as stringifyError } from "../error-P7JgUTds.mjs";
3
- import { t as inspect } from "../logging-VgerMhp6.mjs";
4
- import { _ as readPackageJson, d as hasBusinessConfigSchema, f as detectPackageManager, g as makeOutputDirFor, h as isESM, i as validateCommerceAppConfig, m as getProjectRootDirectory, n as readCommerceAppConfig, p as getExecCommand, s as getConfigDomains, t as parseCommerceAppConfig } from "../config-BSGerqCG.mjs";
2
+ import { c as hasBusinessConfigSchema, i as getConfigDomains, t as validateCommerceAppConfig } from "../validate-DXI6gwZ2.mjs";
3
+ import { r as hasCustomInstallationSteps } from "../installation-SWIwhpKT.mjs";
4
+ import { a as findNearestPackageJson, c as isESM, i as detectPackageManager, l as makeOutputDirFor, n as readCommerceAppConfig, o as getExecCommand, s as getProjectRootDirectory, t as parseCommerceAppConfig, u as readPackageJson } from "../parser-CKQyrTB7.mjs";
5
+ import { t as stringifyError } from "../error-CMV3IjBz.mjs";
6
+ import { t as inspect } from "../logging-CzmXDzxI.mjs";
5
7
  import { CommerceSdkValidationError } from "@adobe/aio-commerce-lib-core/error";
6
8
  import path, { basename, dirname, join, relative, resolve } from "path";
7
9
  import { existsSync, readFileSync, writeFileSync } from "fs";
@@ -22,12 +24,12 @@ import * as prettier from "prettier";
22
24
  * Read a YAML file and return a {@link Document}
23
25
  * @param path - The path to the YAML file
24
26
  */
25
- async function readYamlFile(path$1) {
27
+ async function readYamlFile(path) {
26
28
  let doc = new Document();
27
- if (existsSync(path$1)) try {
28
- doc = parseDocument(await readFile(path$1, "utf-8"), { keepSourceTokens: true });
29
+ if (existsSync(path)) try {
30
+ doc = parseDocument(await readFile(path, "utf-8"), { keepSourceTokens: true });
29
31
  } catch (_) {
30
- const file = basename(path$1);
32
+ const file = basename(path);
31
33
  throw new Error(`Failed to parse ${file}`);
32
34
  }
33
35
  if (doc.contents === null) doc.contents = new YAMLMap();
@@ -41,18 +43,18 @@ async function readYamlFile(path$1) {
41
43
  * @param typeConfig - Configuration for the node type
42
44
  * @returns The existing or newly created node
43
45
  */
44
- function getOrCreateNode(doc, path$1, options, typeConfig) {
45
- const node = doc.getIn(path$1);
46
+ function getOrCreateNode(doc, path, options, typeConfig) {
47
+ const node = doc.getIn(path);
46
48
  if (node) {
47
- if (!typeConfig.typeGuard(node)) throw new Error(`Expected ${typeConfig.typeName} at path "${path$1.join(".")}".`);
49
+ if (!typeConfig.typeGuard(node)) throw new Error(`Expected ${typeConfig.typeName} at path "${path.join(".")}".`);
48
50
  return node;
49
51
  }
50
- if (doc.hasIn(path$1)) doc.deleteIn(path$1);
51
- const pair = doc.createPair(path$1.at(-1), typeConfig.createNode());
52
+ if (doc.hasIn(path)) doc.deleteIn(path);
53
+ const pair = doc.createPair(path.at(-1), typeConfig.createNode());
52
54
  options.onBeforeCreate?.(pair);
53
- if (path$1.length === 1) doc.add(pair);
54
- else doc.addIn(path$1.slice(0, -1), pair);
55
- return doc.getIn(path$1);
55
+ if (path.length === 1) doc.add(pair);
56
+ else doc.addIn(path.slice(0, -1), pair);
57
+ return doc.getIn(path);
56
58
  }
57
59
  /**
58
60
  * Get or create a sequence at the given path
@@ -60,8 +62,8 @@ function getOrCreateNode(doc, path$1, options, typeConfig) {
60
62
  * @param path - The path to the sequence
61
63
  * @param options - The options for the sequence
62
64
  */
63
- function getOrCreateSeq(doc, path$1, options) {
64
- return getOrCreateNode(doc, path$1, options ?? {}, {
65
+ function getOrCreateSeq(doc, path, options) {
66
+ return getOrCreateNode(doc, path, options ?? {}, {
65
67
  typeGuard: isSeq,
66
68
  createNode: () => new YAMLSeq(),
67
69
  typeName: "sequence"
@@ -73,8 +75,8 @@ function getOrCreateSeq(doc, path$1, options) {
73
75
  * @param path - The path to the map
74
76
  * @param options - The options for the map
75
77
  */
76
- function getOrCreateMap(doc, path$1, options) {
77
- return getOrCreateNode(doc, path$1, options ?? {}, {
78
+ function getOrCreateMap(doc, path, options) {
79
+ return getOrCreateNode(doc, path, options ?? {}, {
78
80
  typeGuard: isMap,
79
81
  createNode: () => new YAMLMap(),
80
82
  typeName: "map"
@@ -89,15 +91,15 @@ function getOrCreateMap(doc, path$1, options) {
89
91
  * @param config - The config to build
90
92
  * @param doc - The document to modify (a new one is created if not provided)
91
93
  */
92
- async function createOrUpdateExtConfig(path$1, config$1, doc) {
94
+ async function createOrUpdateExtConfig(path, config, doc) {
93
95
  const extConfigDoc = doc ?? new Document({});
94
- config$1.hooks ??= {};
95
- config$1.operations ??= { workerProcess: [] };
96
- config$1.runtimeManifest ??= { packages: {} };
97
- await buildHooks(extConfigDoc, config$1.hooks);
98
- buildOperations(extConfigDoc, config$1.operations);
99
- buildRuntimeManifest(extConfigDoc, config$1.runtimeManifest);
100
- await writeExtConfig(path$1, extConfigDoc);
96
+ config.hooks ??= {};
97
+ config.operations ??= { workerProcess: [] };
98
+ config.runtimeManifest ??= { packages: {} };
99
+ await buildHooks(extConfigDoc, config.hooks);
100
+ buildOperations(extConfigDoc, config.operations);
101
+ buildRuntimeManifest(extConfigDoc, config.runtimeManifest);
102
+ await writeExtConfig(path, extConfigDoc);
101
103
  return extConfigDoc;
102
104
  }
103
105
  /**
@@ -193,8 +195,8 @@ async function buildHooks(extConfig, hooks) {
193
195
  pair.key.commentBefore = ` The ${generatedHooks} hooks are auto-generated. Do not remove or manually edit.`;
194
196
  } });
195
197
  const execCommand = getExecCommand(await detectPackageManager());
196
- for (const [name, command$1] of Object.entries(hooks)) {
197
- const fullCommand = `${command$1.replaceAll("$packageExec", execCommand)}`;
198
+ for (const [name, command] of Object.entries(hooks)) {
199
+ const fullCommand = `${command.replaceAll("$packageExec", execCommand)}`;
198
200
  const prevValue = (hooksMap.get(name) ?? "").trim();
199
201
  if (prevValue.endsWith("js") || prevValue.endsWith("ts")) throw new Error(`Conflicting hook definition found. The "${name}" hook needs to be a command, not a script.`);
200
202
  if (prevValue !== "" && !prevValue.includes(fullCommand)) hooksMap.set(name, `${prevValue} && ${fullCommand}`);
@@ -276,7 +278,7 @@ const CUSTOM_SCRIPTS_LOADER_PLACEHOLDER = "// {{CUSTOM_SCRIPTS_LOADER}}";
276
278
  * @param actionName - The name of the action.
277
279
  * @param options - Optional configuration options.
278
280
  */
279
- function createActionDefinition(actionName, config$1 = {}, options = {}) {
281
+ function createActionDefinition(actionName, config = {}, options = {}) {
280
282
  const def = {
281
283
  ...options,
282
284
  function: `${GENERATED_ACTIONS_PATH}/${actionName}.js`,
@@ -287,8 +289,7 @@ function createActionDefinition(actionName, config$1 = {}, options = {}) {
287
289
  final: true
288
290
  }
289
291
  };
290
- if (config$1.requiresSchema) def.include = [[`${GENERATED_PATH}/${CONFIG_SCHEMA_FILE_NAME}`, `${PACKAGE_NAME}/`]];
291
- if (config$1.requiresEncryptionKey) def.inputs = {
292
+ if (config.requiresEncryptionKey) def.inputs = {
292
293
  ...def.inputs,
293
294
  AIO_COMMERCE_CONFIG_ENCRYPTION_KEY: "$AIO_COMMERCE_CONFIG_ENCRYPTION_KEY"
294
295
  };
@@ -308,16 +309,18 @@ function getRuntimeActions(extConfig, dir) {
308
309
  * Builds the ext.config.yaml configuration for the extensibility extension.
309
310
  * @param features - The features that are enabled for the app.
310
311
  */
311
- function buildAppManagementExtConfig(features) {
312
+ function buildAppManagementExtConfig(appConfig) {
313
+ const features = getConfigDomains(appConfig);
314
+ const hasPasswordFieldsInSchema = hasBusinessConfigSchema(appConfig) && appConfig.businessConfig.schema.some((field) => field.type === "password");
312
315
  const extConfig = {
313
316
  hooks: { "pre-app-build": "EXTENSION=extensibility/1 $packageExec aio-commerce-lib-app hooks pre-app-build" },
314
317
  operations: { workerProcess: [{
315
318
  type: "action",
316
- impl: `${PACKAGE_NAME}/get-app-config`
319
+ impl: `${PACKAGE_NAME}/app-config`
317
320
  }] },
318
321
  runtimeManifest: { packages: { [PACKAGE_NAME]: {
319
322
  license: "Apache-2.0",
320
- actions: { "get-app-config": createActionDefinition("get-app-config") }
323
+ actions: { "app-config": createActionDefinition("app-config") }
321
324
  } } }
322
325
  };
323
326
  if ([
@@ -329,7 +332,7 @@ function buildAppManagementExtConfig(features) {
329
332
  type: "action",
330
333
  impl: `${PACKAGE_NAME}/installation`
331
334
  });
332
- extConfig.runtimeManifest.packages[PACKAGE_NAME].actions.installation = createActionDefinition("installation", {}, {
335
+ extConfig.runtimeManifest.packages[PACKAGE_NAME].actions.installation = createActionDefinition("installation", { requiresEncryptionKey: hasPasswordFieldsInSchema }, {
333
336
  inputs: {
334
337
  ...COMMERCE_ACTION_INPUTS,
335
338
  LOG_LEVEL: "$LOG_LEVEL"
@@ -341,40 +344,14 @@ function buildAppManagementExtConfig(features) {
341
344
  }
342
345
  /** Builds the ext.config.yaml configuration for the business configuration extension. */
343
346
  function buildBusinessConfigurationExtConfig() {
344
- const actions = [
345
- {
346
- name: "get-scope-tree",
347
- templateFile: "get-scope-tree.js.template"
348
- },
349
- {
350
- name: "get-config-schema",
351
- templateFile: "get-config-schema.js.template",
352
- requiresSchema: true
353
- },
354
- {
355
- name: "get-configuration",
356
- templateFile: "get-configuration.js.template",
357
- requiresSchema: true,
358
- requiresEncryptionKey: true
359
- },
360
- {
361
- name: "set-configuration",
362
- templateFile: "set-configuration.js.template",
363
- requiresEncryptionKey: true
364
- },
365
- {
366
- name: "set-custom-scope-tree",
367
- templateFile: "set-custom-scope-tree.js.template"
368
- },
369
- {
370
- name: "sync-commerce-scopes",
371
- templateFile: "sync-commerce-scopes.js.template"
372
- },
373
- {
374
- name: "unsync-commerce-scopes",
375
- templateFile: "unsync-commerce-scopes.js.template"
376
- }
377
- ];
347
+ const actions = [{
348
+ name: "config",
349
+ templateFile: "config.js.template",
350
+ requiresEncryptionKey: true
351
+ }, {
352
+ name: "scope-tree",
353
+ templateFile: "scope-tree.js.template"
354
+ }];
378
355
  return {
379
356
  hooks: { "pre-app-build": "EXTENSION=configuration/1 $packageExec aio-commerce-lib-app hooks pre-app-build" },
380
357
  operations: { workerProcess: actions.map((action) => ({
@@ -413,7 +390,7 @@ async function updateExtConfig(appConfig, extensionPointId) {
413
390
  let extConfig;
414
391
  switch (extensionPointId) {
415
392
  case EXTENSIBILITY_EXTENSION_POINT_ID:
416
- extConfig = buildAppManagementExtConfig(getConfigDomains(appConfig));
393
+ extConfig = buildAppManagementExtConfig(appConfig);
417
394
  break;
418
395
  case CONFIGURATION_EXTENSION_POINT_ID:
419
396
  extConfig = buildBusinessConfigurationExtConfig();
@@ -500,7 +477,14 @@ async function run$2(appConfig) {
500
477
  consola$1.warn("Business configuration schema not found");
501
478
  return;
502
479
  }
503
- execSync("aio-commerce-lib-config validate schema");
480
+ const projectDir = dirname(await findNearestPackageJson() ?? process.cwd());
481
+ const envPath = join(projectDir, ".env");
482
+ process.loadEnvFile(envPath);
483
+ if (appConfig.businessConfig.schema.some((field) => field.type === "password")) {
484
+ const packageExec = getExecCommand(await detectPackageManager(projectDir));
485
+ if ("AIO_COMMERCE_CONFIG_ENCRYPTION_KEY" in process.env && String(process.env.AIO_COMMERCE_CONFIG_ENCRYPTION_KEY).trim().length > 0) execSync(`${packageExec} aio-commerce-lib-config encryption validate`);
486
+ else execSync(`${packageExec} aio-commerce-lib-config encryption setup`);
487
+ }
504
488
  const contents = stringify(appConfig.businessConfig.schema, null, 2);
505
489
  await writeFile(join(await makeOutputDirFor(`${getExtensionPointFolderPath(CONFIGURATION_EXTENSION_POINT_ID)}/.generated`), CONFIG_SCHEMA_FILE_NAME), contents, "utf-8");
506
490
  consola$1.success(`Generated ${CONFIG_SCHEMA_FILE_NAME}`);
@@ -842,12 +826,12 @@ async function addExtensionPointToInstallYaml(extensionPointId, rootDirectory, c
842
826
  //#region source/commands/init/lib.ts
843
827
  /** Ensure app.commerce.config file exists, allow creating if it doesn't */
844
828
  async function ensureCommerceAppConfig(cwd = process.cwd()) {
845
- let config$1 = null;
829
+ let config = null;
846
830
  try {
847
- config$1 = await readCommerceAppConfig(cwd);
831
+ config = await readCommerceAppConfig(cwd);
848
832
  } catch (_) {}
849
- if (config$1) try {
850
- const validatedConfig = validateCommerceAppConfig(config$1);
833
+ if (config) try {
834
+ const validatedConfig = validateCommerceAppConfig(config);
851
835
  consola$1.success(`${COMMERCE_APP_CONFIG_FILE} found and is valid. Continuing...`);
852
836
  return {
853
837
  config: validatedConfig,
@@ -866,8 +850,8 @@ async function ensureCommerceAppConfig(cwd = process.cwd()) {
866
850
  try {
867
851
  const configContent = await getDefaultCommerceAppConfig(cwd, answers);
868
852
  consola$1.info(`Creating ${answers.configFile}...`);
869
- const path$1 = join(await getProjectRootDirectory(cwd), answers.configFile);
870
- await writeFile(path$1, await prettier.format(configContent, {
853
+ const path = join(await getProjectRootDirectory(cwd), answers.configFile);
854
+ await writeFile(path, await prettier.format(configContent, {
871
855
  semi: true,
872
856
  quoteStyle: "double",
873
857
  arrowParens: "always",
@@ -877,7 +861,7 @@ async function ensureCommerceAppConfig(cwd = process.cwd()) {
877
861
  tabWidth: 2,
878
862
  useTabs: false,
879
863
  printWidth: 80,
880
- filepath: path$1
864
+ filepath: path
881
865
  }), "utf-8");
882
866
  consola$1.success(`Created ${answers.configFile}`);
883
867
  return {
@@ -991,12 +975,12 @@ async function exec() {
991
975
  consola$1.start("Initializing app...");
992
976
  const { execCommand, packageManager } = await ensurePackageJson();
993
977
  runInstall(packageManager, REQUIRED_DEPENDENCIES);
994
- const { config: config$1, domains } = await ensureCommerceAppConfig();
978
+ const { config, domains } = await ensureCommerceAppConfig();
995
979
  installDependencies(packageManager, domains);
996
- execSync(`npm pkg set name="${config$1.metadata.id}"`);
997
- execSync(`npm pkg set version="${config$1.metadata.version}"`);
998
- execSync(`npm pkg set description="${config$1.metadata.description}"`);
999
- await runGeneration(config$1, execCommand);
980
+ execSync(`npm pkg set name="${config.metadata.id}"`);
981
+ execSync(`npm pkg set version="${config.metadata.version}"`);
982
+ execSync(`npm pkg set description="${config.metadata.description}"`);
983
+ await runGeneration(config, execCommand);
1000
984
  await ensureAppConfig(domains);
1001
985
  await ensureInstallYaml(domains);
1002
986
  consola$1.success("Initialization complete!");