-
Notifications
You must be signed in to change notification settings - Fork 8
feat(config): add configuration versioning and harden scope/config flows #283
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
larsroettig
wants to merge
7
commits into
adobe:main
Choose a base branch
from
larsroettig:audit
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ce661de
feat(config): add configuration versioning and harden scope/config flows
larsroettig b7d6721
Merge remote-tracking branch 'upstream/main' into audit
larsroettig 83c5caa
Audit
larsroettig 239914e
Resolve merge conflict and merge main
larsroettig b5546e3
refactor(app-config): migrate audit endpoints to REST config routes
larsroettig 3d66b71
fix(config): harden config action/versioning validation and typing
larsroettig 1b85241
Remove feedtuere flag simplify branch
larsroettig File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
...urce/commands/generate/actions/templates/business-configuration/audit-enabled.js.template
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| /* | ||
| * Copyright 2026 Adobe. All rights reserved. | ||
| * This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. You may obtain a copy | ||
| * of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software distributed under | ||
| * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
| * OF ANY KIND, either express or implied. See the License for the specific language | ||
| * governing permissions and limitations under the License. | ||
| */ | ||
|
|
||
| export function parseAuditEnabled(value) { | ||
| if (typeof value === "boolean") { | ||
| return value; | ||
| } | ||
| if (typeof value === "string") { | ||
| const normalized = value.trim().toLowerCase(); | ||
| if (normalized === "true") { | ||
| return true; | ||
| } | ||
| if (normalized === "false") { | ||
| return false; | ||
| } | ||
| } | ||
| return true; | ||
| } |
128 changes: 128 additions & 0 deletions
128
.../generate/actions/templates/business-configuration/get-configuration-versions.js.template
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| /* | ||
| * Copyright 2026 Adobe. All rights reserved. | ||
| * This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. You may obtain a copy | ||
| * of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software distributed under | ||
| * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
| * OF ANY KIND, either express or implied. See the License for the specific language | ||
| * governing permissions and limitations under the License. | ||
| */ | ||
|
|
||
| // This file has been auto-generated by `@adobe/aio-commerce-lib-config` | ||
| // Do not modify this file directly | ||
|
|
||
| import util from "node:util"; | ||
|
|
||
| import { | ||
| byCode, | ||
| byCodeAndLevel, | ||
| byScopeId, | ||
| getConfigurationVersions, | ||
| setGlobalLibConfigOptions, | ||
| } from "@adobe/aio-commerce-lib-config"; | ||
| import { parseAuditEnabled } from "./audit-enabled.js"; | ||
| import { | ||
| badRequest, | ||
| internalServerError, | ||
| ok, | ||
| } from "@adobe/aio-commerce-sdk/core/responses"; | ||
| import AioLogger from "@adobe/aio-lib-core-logging"; | ||
|
|
||
| const inspect = (obj) => util.inspect(obj, { depth: null }); | ||
|
|
||
| function parsePositiveInteger(value) { | ||
| if (value === undefined || value === null || value === "") { | ||
| return undefined; | ||
| } | ||
|
|
||
| const parsed = Number(value); | ||
| if (!Number.isInteger(parsed) || parsed < 0) { | ||
| return null; | ||
| } | ||
| return parsed; | ||
| } | ||
|
|
||
| /** | ||
| * Get configuration version history. | ||
| * @param params - The input parameters. | ||
| * @returns The response object containing version history. | ||
| */ | ||
| export async function main(params) { | ||
| const logger = AioLogger("get-configuration-versions", { | ||
| level: params.LOG_LEVEL || "info", | ||
| }); | ||
|
|
||
| try { | ||
| const auditEnabled = parseAuditEnabled(params.AIO_COMMERCE_CONFIG_AUDIT_ENABLED); | ||
| setGlobalLibConfigOptions({ auditEnabled }); | ||
| if (!auditEnabled) { | ||
| return badRequest({ | ||
| body: { | ||
| code: "AUDIT_DISABLED", | ||
| message: "Audit feature is disabled", | ||
| }, | ||
| }); | ||
| } | ||
|
|
||
| const id = params.id; | ||
| const code = params.code; | ||
| const level = params.level; | ||
| const limit = parsePositiveInteger(params.limit); | ||
| const offset = parsePositiveInteger(params.offset); | ||
|
|
||
| if (limit === null || offset === null) { | ||
| return badRequest({ | ||
| body: { | ||
| code: "INVALID_PARAMS", | ||
| message: "limit and offset must be positive integers", | ||
| }, | ||
| }); | ||
| } | ||
|
|
||
| if (!(id || code)) { | ||
| return badRequest({ | ||
| body: { | ||
| code: "INVALID_PARAMS", | ||
| message: "Either id or code query param is required", | ||
| }, | ||
| }); | ||
| } | ||
|
|
||
| const selector = id | ||
| ? byScopeId(id) | ||
| : level | ||
| ? byCodeAndLevel(code, level) | ||
| : byCode(code); | ||
| const result = await getConfigurationVersions(selector, { limit, offset }); | ||
|
|
||
| return ok({ | ||
| body: result, | ||
| headers: { | ||
| "Cache-Control": "no-store", | ||
| }, | ||
| }); | ||
| } catch (error) { | ||
| logger.error( | ||
| `Something went wrong while retrieving configuration versions: ${inspect(error)}`, | ||
| ); | ||
|
|
||
| if (error instanceof Error && error.message.includes("AUDIT_DISABLED")) { | ||
| return badRequest({ | ||
| body: { | ||
| code: "AUDIT_DISABLED", | ||
| message: "Audit feature is disabled", | ||
| }, | ||
| }); | ||
| } | ||
|
|
||
| return internalServerError({ | ||
| body: { | ||
| code: "INTERNAL_ERROR", | ||
| details: error instanceof Error ? error.message : "Unknown error", | ||
| message: "An internal server error occurred", | ||
| }, | ||
| }); | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
parsePositiveIntegercurrently accepts0(it only rejects values< 0), but the error message says "limit and offset must be positive integers". Either reject0or change the message to "non-negative integers" to match the validation.