@salesforce/b2c-tooling-sdk / config / InstanceManager
Class: InstanceManager
Defined in: packages/b2c-tooling-sdk/src/config/instance-manager.ts:57
Service for managing B2C instances across multiple config sources.
This class aggregates instance management operations from all sources that implement the optional instance management methods. Sources are used in priority order (lower number first), the same order configuration resolution uses.
Example
import { createInstanceManager } from '@salesforce/b2c-tooling-sdk/config';
// dw.json plus any globally registered (plugin) sources
const manager = createInstanceManager();
// List all instances
const instances = await manager.listAllInstances();
// Create a new instance
await manager.createInstance({
name: 'staging',
config: { hostname: 'staging.example.com' },
setActive: true,
});Constructors
Constructor
new InstanceManager(
sources):InstanceManager
Defined in: packages/b2c-tooling-sdk/src/config/instance-manager.ts:60
Parameters
sources
Returns
InstanceManager
Methods
createInstance()
createInstance(
options,targetSource?):Promise<InstanceCreateResult>
Defined in: packages/b2c-tooling-sdk/src/config/instance-manager.ts:78
Create an instance in the specified source (or the highest-priority source that can create instances).
Credentials go to a credential store (a source declaring ConfigSource.credentialFields) when the store declares every field given for a credential pair, such as both clientId and clientSecret. Pairs always stay together, because configuration resolution reads a pair from one source only. Otherwise the credentials stay with the instance.
Parameters
options
CreateInstanceOptions & ResolveConfigOptions
Instance creation options
targetSource?
string
Source name to use (optional, defaults to first available)
Returns
Promise<InstanceCreateResult>
Where the instance and any routed credentials were stored
Throws
Error if no instance sources available or specified source not found
findInstance()
findInstance(
name,options?):Promise<InstanceInfo|undefined>
Defined in: packages/b2c-tooling-sdk/src/config/instance-manager.ts:130
Find an instance by name in the highest-priority source that lists it.
Parameters
name
string
Instance name
options?
Resolution options
Returns
Promise<InstanceInfo | undefined>
The instance, or undefined if no source lists it
getCredentialSources()
getCredentialSources(
field):ConfigSource[]
Defined in: packages/b2c-tooling-sdk/src/config/instance-manager.ts:140
Get sources that can store a specific credential field.
Parameters
field
keyof NormalizedConfig
The credential field to check
Returns
Array of sources that can store the field
getInstanceSources()
getInstanceSources():
ConfigSource[]
Defined in: packages/b2c-tooling-sdk/src/config/instance-manager.ts:149
Get sources that can create instances.
Returns
Array of sources with createInstance() method
listAllInstances()
listAllInstances(
options?):Promise<InstanceInfo[]>
Defined in: packages/b2c-tooling-sdk/src/config/instance-manager.ts:163
List instances from all sources that implement listInstances(), in source priority order.
Each instance's source is the name of the source that lists it. A source whose listing fails is skipped with a warning, so one broken plugin doesn't hide every other instance.
Parameters
options?
Resolution options
Returns
Promise<InstanceInfo[]>
Array of all instances from all sources
removeInstance()
removeInstance(
name,options?,sourceName?):Promise<InstanceInfo>
Defined in: packages/b2c-tooling-sdk/src/config/instance-manager.ts:193
Remove an instance from the source that contains it.
Also asks every credential store to remove that instance's credentials, so no secrets are left behind. A store that fails to remove them is skipped with a warning.
Parameters
name
string
Instance name to remove
options?
Resolution options
sourceName?
string
Source to remove it from (default: the highest-priority source that lists it)
Returns
Promise<InstanceInfo>
The removed instance
Throws
Error if instance not found in any source
setActiveInstance()
setActiveInstance(
name,options?,sourceName?):Promise<InstanceInfo>
Defined in: packages/b2c-tooling-sdk/src/config/instance-manager.ts:224
Set an instance as active in the source that contains it.
Parameters
name
string
Instance name to set as active
options?
Resolution options
sourceName?
string
Source that holds it (default: the highest-priority source that lists it)
Returns
Promise<InstanceInfo>
The activated instance
Throws
Error if instance not found in any source
storeCredential()
storeCredential(
instanceName,field,value,targetSource?,options?):Promise<void>
Defined in: packages/b2c-tooling-sdk/src/config/instance-manager.ts:240
Store a credential for an instance in the specified source.
Parameters
instanceName
string
Instance name
field
keyof NormalizedConfig
Config field to store
value
string
Value to store
targetSource?
string
Source name to use (optional)
options?
Resolution options
Returns
Promise<void>
Throws
Error if no credential sources support the field