Skip to content

add package.json config source with numeric priority system#60

Merged
clavery merged 2 commits intomainfrom
feature/package-json-config-source
Jan 21, 2026
Merged

add package.json config source with numeric priority system#60
clavery merged 2 commits intomainfrom
feature/package-json-config-source

Conversation

@clavery
Copy link
Copy Markdown
Collaborator

@clavery clavery commented Jan 20, 2026

Summary

This PR introduces a new PackageJsonSource configuration source that reads project-level defaults from the b2c key in package.json, along with a numeric priority system for fine-grained control over config source ordering.

Features

Package.json Configuration Source

  • Reads configuration from the b2c key in package.json
  • Has the lowest priority (1000) of all config sources - won't override dw.json or CLI flags
  • Only allows non-sensitive, project-level fields:
    • shortCode - SCAPI short code
    • clientId - OAuth client ID (for implicit login discovery)
    • mrtProject - MRT project slug
    • mrtOrigin - MRT API origin URL
    • accountManagerHost - Account Manager hostname
  • Sensitive fields (passwords, secrets, hostname) are intentionally excluded for security

Example package.json:

{
  "name": "my-storefront",
  "b2c": {
    "shortCode": "abc123",
    "clientId": "your-client-id",
    "mrtProject": "my-project"
  }
}

Numeric Priority System

Config sources now support numeric priorities for fine-grained ordering:

Priority Description Example
< 0 Override built-in sources Plugin 'before' → -1
0 Built-in sources DwJsonSource, MobifySource
1-999 After built-in Plugin 'after' → 10
1000 Lowest priority PackageJsonSource
  • Existing 'before'/'after' string values continue to work (mapped to -1 and 10)
  • Plugin hooks can now return numeric priority values
  • Custom ConfigSource implementations can set priority property directly

Files Changed

Implementation

  • packages/b2c-tooling-sdk/src/config/types.ts - Added priority?: number to ConfigSource
  • packages/b2c-tooling-sdk/src/config/sources/package-json-source.ts - New source
  • packages/b2c-tooling-sdk/src/config/sources/dw-json-source.ts - Added priority = 0
  • packages/b2c-tooling-sdk/src/config/sources/mobify-source.ts - Added priority = 0
  • packages/b2c-tooling-sdk/src/config/resolver.ts - Sort by priority, add PackageJsonSource
  • packages/b2c-tooling-sdk/src/cli/hooks.ts - Updated type for numeric priority
  • packages/b2c-tooling-sdk/src/cli/base-command.ts - Map string priorities to numeric

Tests

  • packages/b2c-tooling-sdk/test/config/sources.test.ts - PackageJsonSource tests
  • packages/b2c-tooling-sdk/test/config/resolver.test.ts - Priority sorting tests

Documentation

  • docs/guide/configuration.md - Added package.json section, updated priority list
  • docs/guide/extending.md - Added numeric priority documentation

- Add "Project Configuration (package.json)" section to configuration.md
- Document allowed fields: shortCode, clientId, mrtProject, mrtOrigin, accountManagerHost
- Explain security rationale for excluding sensitive fields
- Update resolution priority list to include package.json as lowest priority
- Document numeric priority system in extending.md
- Add priority table showing ranges (< 0, 0, 1-999, 1000)
- Add example showing how to set priority on custom ConfigSource
@clavery clavery changed the title feat: add package.json config source with numeric priority system add package.json config source with numeric priority system Jan 20, 2026
@clavery
Copy link
Copy Markdown
Collaborator Author

clavery commented Jan 21, 2026

bypassing as we want this in for plugin priority

@clavery clavery merged commit 42c0d04 into main Jan 21, 2026
3 checks passed
amit-kumar8-sf pushed a commit that referenced this pull request Jan 21, 2026
* package json config sourcce

* docs: add package.json config source and priority system documentation

- Add "Project Configuration (package.json)" section to configuration.md
- Document allowed fields: shortCode, clientId, mrtProject, mrtOrigin, accountManagerHost
- Explain security rationale for excluding sensitive fields
- Update resolution priority list to include package.json as lowest priority
- Document numeric priority system in extending.md
- Add priority table showing ranges (< 0, 0, 1-999, 1000)
- Add example showing how to set priority on custom ConfigSource
@clavery clavery deleted the feature/package-json-config-source branch January 27, 2026 01:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant