---
editLink: false
lastUpdated: false
---

[@salesforce/b2c-tooling-sdk](../modules.md) / config

# config

Configuration loading utilities.

This module provides utilities for loading B2C Commerce configuration.
The preferred high-level API is [resolveConfig](functions/resolveConfig.md), which returns
a rich configuration object with factory methods.

## Quick Start

```typescript
import { resolveConfig } from '@salesforce/b2c-tooling-sdk/config';

const config = await resolveConfig({
  hostname: process.env.SFCC_SERVER,
  clientId: process.env.SFCC_CLIENT_ID,
  mrtApiKey: process.env.MRT_API_KEY,
});

// Check what's available and create objects
if (config.hasB2CInstanceConfig()) {
  const instance = config.createB2CInstance();
  await instance.webdav.propfind('Cartridges');
}

if (config.hasMrtConfig()) {
  const mrtAuth = config.createMrtAuth();
}
```

## Resolution Priority

Configuration is resolved with the following precedence (highest to lowest):

1. **Explicit overrides** - Values passed to `resolve()`, `createInstance()`, etc.
2. **Configuration sources** - dw.json, ~/.mobify (in order)

Later sources only fill in missing values—they do not override values from
higher-priority sources.

## Hostname Mismatch Protection

The configuration system includes safety protection against accidentally using
credentials from one instance with a different hostname. When you explicitly
specify a hostname that differs from the dw.json hostname:

- The entire base configuration from dw.json is ignored
- Only your explicit overrides are used
- A warning is included in the resolution result

This prevents credential leakage between different B2C instances.

## Default Configuration Sources

The default sources loaded by [createConfigResolver](functions/createConfigResolver.md) are:

- **dw.json** - Project configuration file, searched upward from cwd
- **~/.mobify** - Home directory file for MRT API key

## Custom Configuration Sources

Implement the [ConfigSource](interfaces/ConfigSource.md) interface to create custom sources:

```typescript
import { ConfigResolver, type ConfigSource, type ConfigLoadResult } from '@salesforce/b2c-tooling-sdk/config';

class MySource implements ConfigSource {
  name = 'my-source';
  load(options): ConfigLoadResult | undefined {
    return {
      config: { hostname: 'custom.example.com' },
      location: '/path/to/source',
    };
  }
}

const resolver = new ConfigResolver([new MySource()]);
```

## Lower-Level APIs

For advanced use cases, you can use the lower-level dw.json loading functions:

```typescript
import { loadDwJson, findDwJson } from '@salesforce/b2c-tooling-sdk/config';

const dwJsonPath = findDwJson();
const config = loadDwJson({ path: dwJsonPath, instance: 'staging' });
```

## Classes

- [ConfigResolver](classes/ConfigResolver.md)
- [ConfigSourceRegistry](classes/ConfigSourceRegistry.md)
- [InstanceManager](classes/InstanceManager.md)

## Interfaces

- [AddInstanceOptions](interfaces/AddInstanceOptions.md)
- [ConfigLoadResult](interfaces/ConfigLoadResult.md)
- [ConfigResolutionResult](interfaces/ConfigResolutionResult.md)
- [ConfigSource](interfaces/ConfigSource.md)
- [ConfigSourceInfo](interfaces/ConfigSourceInfo.md)
- [ConfigWarning](interfaces/ConfigWarning.md)
- [CreateInstanceOptions](interfaces/CreateInstanceOptions.md)
- [CreateOAuthOptions](interfaces/CreateOAuthOptions.md)
- [DwJsonConfig](interfaces/DwJsonConfig.md)
- [DwJsonMultiConfig](interfaces/DwJsonMultiConfig.md)
- [InstanceInfo](interfaces/InstanceInfo.md)
- [LoadDwJsonOptions](interfaces/LoadDwJsonOptions.md)
- [LoadDwJsonResult](interfaces/LoadDwJsonResult.md)
- [NormalizedConfig](interfaces/NormalizedConfig.md)
- [RemoveInstanceOptions](interfaces/RemoveInstanceOptions.md)
- [ResolveConfigOptions](interfaces/ResolveConfigOptions.md)
- [ResolvedB2CConfig](interfaces/ResolvedB2CConfig.md)
- [SetActiveInstanceOptions](interfaces/SetActiveInstanceOptions.md)

## Type Aliases

- [ConfigWarningCode](type-aliases/ConfigWarningCode.md)
- [MaybePromise](type-aliases/MaybePromise.md)

## Variables

- [globalConfigSourceRegistry](variables/globalConfigSourceRegistry.md)

## Functions

- [addInstance](functions/addInstance.md)
- [createConfigResolver](functions/createConfigResolver.md)
- [createInstanceFromConfig](functions/createInstanceFromConfig.md)
- [createInstanceManager](functions/createInstanceManager.md)
- [findDwJson](functions/findDwJson.md)
- [loadDwJson](functions/loadDwJson.md)
- [loadFullDwJson](functions/loadFullDwJson.md)
- [normalizeConfigKeys](functions/normalizeConfigKeys.md)
- [removeInstance](functions/removeInstance.md)
- [resolveConfig](functions/resolveConfig.md)
- [saveDwJson](functions/saveDwJson.md)
- [setActiveInstance](functions/setActiveInstance.md)
