@salesforce/b2c-tooling-sdk / cli / BackendDispatcher
Class: BackendDispatcher<S>
Defined in: packages/b2c-tooling-sdk/src/compat/dispatcher.ts:82
Stateful router that runs SCAPI optimistically and falls back to OCAPI once on a safe capability/auth/request rejection, caching the choice for the lifetime of the dispatcher. See the module-level docs for the full rationale.
Construct one per logical operation (e.g. one per CLI command run, or one per VSCode user-initiated action). Sharing a dispatcher across unrelated operations is fine but not required.
Type Parameters
S
S
The SCAPI ops bundle type (e.g., ScapiJobsOps).
Constructors
Constructor
new BackendDispatcher<
S>(preference,createScapi,domainName):BackendDispatcher<S>
Defined in: packages/b2c-tooling-sdk/src/compat/dispatcher.ts:96
Parameters
preference
User preference (auto | scapi | ocapi).
createScapi
() => S | undefined
Lazily builds the SCAPI ops bundle. Returns undefined when SCAPI is not configured (shortCode/tenantId/auth missing).
domainName
string
Used in fallback log messages (e.g. 'jobs').
Returns
BackendDispatcher<S>
Throws
Error if preference === 'scapi' but createScapi() returns undefined — explicit SCAPI without configuration is a hard error.
Accessors
active
Get Signature
get active():
ResolvedBackend|undefined
Defined in: packages/b2c-tooling-sdk/src/compat/dispatcher.ts:114
Backend that has handled requests so far, or undefined if none yet.
Returns
ResolvedBackend | undefined
Methods
run()
run<
T>(branches):Promise<T>
Defined in: packages/b2c-tooling-sdk/src/compat/dispatcher.ts:123
Runs the operation against the resolved backend. If unresolved (auto with SCAPI configured), tries SCAPI first; on a safe fallback trigger, falls back to OCAPI and caches the choice. Ambiguous failures propagate.
Type Parameters
T
T
Parameters
branches
DispatchBranches<S, T>
Returns
Promise<T>