Skip to content

Draft: Add optionsSource support for dynamic list field options#280

Open
nuzil wants to merge 2 commits intoadobe:mainfrom
comwrap:dynamic-options
Open

Draft: Add optionsSource support for dynamic list field options#280
nuzil wants to merge 2 commits intoadobe:mainfrom
comwrap:dynamic-options

Conversation

@nuzil
Copy link

@nuzil nuzil commented Mar 2, 2026

Add Dynamic Options Support for List Fields (optionsSource)

Summary

This PR adds support for dynamically loading options for list type fields in the Adobe Commerce App Management configuration schema. Instead of requiring static options defined at build time, fields can now specify an optionsSource that references a runtime action or external URL to fetch options dynamically.

Configuration Example

// app.commerce.config.js
import { defineConfig } from "@adobe/aio-commerce-lib-app/config";

export default defineConfig({
  metadata: {
    id: "myApp",
    displayName: "My App",
  },
  businessConfig: {
    schema: [
      {
        name: "store-code",
        label: "Store",
        description: "Select a store (dynamically loaded)",
        type: "list",
        selectionMode: "single",
        optionsSource: {
          action: "extension/get-store-options"
        },
        default: "",
      },
    ],
  },
});

Action

// actions/get-store-options/index.js
import { ok, internalServerError } from "@adobe/aio-commerce-sdk/core/responses";

export async function main(params) {
  try {
    // Fetch from Commerce API, database, or any source
    const options = [
      { label: "Default Store", value: "default" },
      { label: "US Store", value: "us" },
      { label: "EU Store", value: "eu" },
    ];

    return ok({
      body: { options },
    });
  } catch (error) {
    return internalServerError({
      body: {
        code: "INTERNAL_ERROR",
        message: "Failed to fetch options",
      },
    });
  }
}

nuzil added 2 commits March 2, 2026 11:18
- Extended fields.ts schema to support optionsSource property with action/url
- Made options property optional when optionsSource is provided
- Updated get-config-schema template to resolve dynamic options at runtime
@changeset-bot
Copy link

changeset-bot bot commented Mar 2, 2026

⚠️ No Changeset found

Latest commit: b7a5842

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions github-actions bot added without-changeset The PR does not contain a Changeset file pkg: aio-commerce-lib-config Includes changes in `packages/aio-commerce-lib-config` pkg: aio-commerce-lib-app Includes changes in `packages/aio-commerce-lib-app` labels Mar 2, 2026
@larsroettig
Copy link
Member

Hi @nuzil, I really like the direction of this PR! The implementation is solid.

Just a couple of thoughts for future-proofing:

Stale Configs: What happens if a config option is saved but then removed from the action later? It might be worth considering how we handle those 'orphaned' values.

Template Logic: The template is getting quite large; moving some of the logic into a testable helper function could be a great next step to keep things maintainable.

Not blockers for now, but definitely worth a thought as we scale this out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg: aio-commerce-lib-app Includes changes in `packages/aio-commerce-lib-app` pkg: aio-commerce-lib-config Includes changes in `packages/aio-commerce-lib-config` without-changeset The PR does not contain a Changeset file

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants