@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.
- package/CHANGELOG.md +33 -0
- package/README.md +1 -4
- package/bin/cli.mjs +24 -0
- package/dist/cjs/actions/app-config.cjs +27 -0
- package/dist/cjs/actions/app-config.d.cts +15 -0
- package/dist/cjs/actions/config.cjs +79 -0
- package/dist/cjs/actions/config.d.cts +15 -0
- package/dist/cjs/actions/installation.cjs +424 -0
- package/dist/cjs/actions/{index.d.cts → installation.d.cts} +4 -3
- package/dist/cjs/actions/scope-tree.cjs +97 -0
- package/dist/cjs/actions/scope-tree.d.cts +8 -0
- package/dist/cjs/{app-Dx0ca6oL.d.cts → app-PTKvEBea.d.cts} +6 -6
- package/dist/cjs/commands/generate/actions/templates/app-management/app-config.js.template +22 -0
- package/dist/cjs/commands/generate/actions/templates/app-management/installation.js.template +1 -1
- package/dist/cjs/commands/generate/actions/templates/business-configuration/config.js.template +22 -0
- package/dist/cjs/commands/generate/actions/templates/business-configuration/scope-tree.js.template +18 -0
- package/dist/cjs/commands/index.cjs +91 -106
- package/dist/cjs/config/index.cjs +21 -19
- package/dist/cjs/config/index.d.cts +32 -332
- package/dist/cjs/error-DJ2UAPH2.cjs +24 -0
- package/dist/cjs/installation-nwF2RC7F.cjs +241 -0
- package/dist/cjs/{logging-DYwr5WQk.cjs → logging-IDRQG0as.cjs} +2 -2
- package/dist/cjs/management/index.cjs +9 -8
- package/dist/cjs/management/index.d.cts +2 -2
- package/dist/cjs/parser-DIchX9SL.cjs +267 -0
- package/dist/cjs/router-DCw7oEQ9.cjs +417 -0
- package/dist/cjs/{management-Dm5h0E6l.cjs → runner-CUJ8RHzY.cjs} +24 -30
- package/dist/{es/index-Bxr3zvCT.d.mts → cjs/runner-Ds2m27Q4.d.cts} +49 -95
- package/dist/cjs/schemas-CZ6c8Id9.cjs +98 -0
- package/dist/cjs/validate-BegMfe-i.cjs +235 -0
- package/dist/es/actions/app-config.d.mts +15 -0
- package/dist/es/actions/app-config.mjs +25 -0
- package/dist/es/actions/config.d.mts +15 -0
- package/dist/es/actions/config.mjs +77 -0
- package/dist/es/actions/{index.d.mts → installation.d.mts} +4 -3
- package/dist/es/actions/{index.mjs → installation.mjs} +27 -427
- package/dist/es/actions/scope-tree.d.mts +8 -0
- package/dist/es/actions/scope-tree.mjs +95 -0
- package/dist/es/{app-Cx1-6dn0.d.mts → app-vKXaAr6f.d.mts} +6 -6
- package/dist/es/commands/generate/actions/templates/app-management/app-config.js.template +22 -0
- package/dist/es/commands/generate/actions/templates/app-management/installation.js.template +1 -1
- package/dist/es/commands/generate/actions/templates/business-configuration/config.js.template +22 -0
- package/dist/es/commands/generate/actions/templates/business-configuration/scope-tree.js.template +18 -0
- package/dist/es/commands/index.mjs +68 -84
- package/dist/es/config/index.d.mts +32 -332
- package/dist/es/config/index.mjs +3 -2
- package/dist/es/error-CMV3IjBz.mjs +18 -0
- package/dist/es/{error-P7JgUTds.mjs → installation-SWIwhpKT.mjs} +72 -124
- package/dist/es/management/index.d.mts +2 -3
- package/dist/es/management/index.mjs +1 -1
- package/dist/es/parser-CKQyrTB7.mjs +201 -0
- package/dist/es/router-CJ4VWoCt.mjs +404 -0
- package/dist/es/{management-Y7pwEbNI.mjs → runner-DB2tDBQS.mjs} +17 -24
- package/dist/{cjs/index-C5SutkJQ.d.cts → es/runner-Uk7263hG.d.mts} +49 -95
- package/dist/es/schemas-B8yIv0_b.mjs +41 -0
- package/dist/es/validate-DXI6gwZ2.mjs +187 -0
- package/package.json +38 -24
- package/dist/cjs/actions/index.cjs +0 -824
- package/dist/cjs/commands/generate/actions/templates/app-management/get-app-config.js.template +0 -62
- package/dist/cjs/commands/generate/actions/templates/business-configuration/get-config-schema.js.template +0 -63
- package/dist/cjs/commands/generate/actions/templates/business-configuration/get-configuration.js.template +0 -104
- package/dist/cjs/commands/generate/actions/templates/business-configuration/get-scope-tree.js.template +0 -69
- package/dist/cjs/commands/generate/actions/templates/business-configuration/set-configuration.js.template +0 -125
- package/dist/cjs/commands/generate/actions/templates/business-configuration/set-custom-scope-tree.js.template +0 -83
- package/dist/cjs/commands/generate/actions/templates/business-configuration/sync-commerce-scopes.js.template +0 -113
- package/dist/cjs/commands/generate/actions/templates/business-configuration/unsync-commerce-scopes.js.template +0 -56
- package/dist/cjs/config-JQ_n-5Nk.cjs +0 -565
- package/dist/cjs/error-Byj1DVHZ.cjs +0 -344
- package/dist/es/commands/generate/actions/templates/app-management/get-app-config.js.template +0 -62
- package/dist/es/commands/generate/actions/templates/business-configuration/get-config-schema.js.template +0 -63
- package/dist/es/commands/generate/actions/templates/business-configuration/get-configuration.js.template +0 -104
- package/dist/es/commands/generate/actions/templates/business-configuration/get-scope-tree.js.template +0 -69
- package/dist/es/commands/generate/actions/templates/business-configuration/set-configuration.js.template +0 -125
- package/dist/es/commands/generate/actions/templates/business-configuration/set-custom-scope-tree.js.template +0 -83
- package/dist/es/commands/generate/actions/templates/business-configuration/sync-commerce-scopes.js.template +0 -113
- package/dist/es/commands/generate/actions/templates/business-configuration/unsync-commerce-scopes.js.template +0 -56
- package/dist/es/config-BSGerqCG.mjs +0 -457
- /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.
|
|
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?:
|
|
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
|
|
139
|
-
readonly
|
|
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.
|
|
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);
|
package/dist/es/commands/generate/actions/templates/business-configuration/scope-tree.js.template
ADDED
|
@@ -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
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
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
|
|
27
|
+
async function readYamlFile(path) {
|
|
26
28
|
let doc = new Document();
|
|
27
|
-
if (existsSync(path
|
|
28
|
-
doc = parseDocument(await readFile(path
|
|
29
|
+
if (existsSync(path)) try {
|
|
30
|
+
doc = parseDocument(await readFile(path, "utf-8"), { keepSourceTokens: true });
|
|
29
31
|
} catch (_) {
|
|
30
|
-
const file = basename(path
|
|
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
|
|
45
|
-
const node = doc.getIn(path
|
|
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
|
|
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
|
|
51
|
-
const pair = doc.createPair(path
|
|
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
|
|
54
|
-
else doc.addIn(path
|
|
55
|
-
return doc.getIn(path
|
|
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
|
|
64
|
-
return getOrCreateNode(doc, path
|
|
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
|
|
77
|
-
return getOrCreateNode(doc, path
|
|
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
|
|
94
|
+
async function createOrUpdateExtConfig(path, config, doc) {
|
|
93
95
|
const extConfigDoc = doc ?? new Document({});
|
|
94
|
-
config
|
|
95
|
-
config
|
|
96
|
-
config
|
|
97
|
-
await buildHooks(extConfigDoc, config
|
|
98
|
-
buildOperations(extConfigDoc, config
|
|
99
|
-
buildRuntimeManifest(extConfigDoc, config
|
|
100
|
-
await writeExtConfig(path
|
|
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
|
|
197
|
-
const fullCommand = `${command
|
|
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
|
|
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
|
|
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(
|
|
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}/
|
|
319
|
+
impl: `${PACKAGE_NAME}/app-config`
|
|
317
320
|
}] },
|
|
318
321
|
runtimeManifest: { packages: { [PACKAGE_NAME]: {
|
|
319
322
|
license: "Apache-2.0",
|
|
320
|
-
actions: { "
|
|
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
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
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(
|
|
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
|
-
|
|
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
|
|
829
|
+
let config = null;
|
|
846
830
|
try {
|
|
847
|
-
config
|
|
831
|
+
config = await readCommerceAppConfig(cwd);
|
|
848
832
|
} catch (_) {}
|
|
849
|
-
if (config
|
|
850
|
-
const validatedConfig = validateCommerceAppConfig(config
|
|
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
|
|
870
|
-
await writeFile(path
|
|
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
|
|
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
|
|
978
|
+
const { config, domains } = await ensureCommerceAppConfig();
|
|
995
979
|
installDependencies(packageManager, domains);
|
|
996
|
-
execSync(`npm pkg set name="${config
|
|
997
|
-
execSync(`npm pkg set version="${config
|
|
998
|
-
execSync(`npm pkg set description="${config
|
|
999
|
-
await runGeneration(config
|
|
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!");
|