@salesforce/b2c-tooling-sdk / clients / createFallbackBackend
Function: createFallbackBackend()
createFallbackBackend<
T>(scapi,ocapi,domainName):T
Defined in: packages/b2c-tooling-sdk/src/clients/scapi-fallback-backend.ts:107
Creates a fallback wrapper over scapi and ocapi backends.
The returned object presents the same interface as T. Method calls are intercepted: the first call tries SCAPI; on a safe fallback trigger it falls back to OCAPI. The choice is cached for the wrapper's lifetime.
Contract:
- Both
scapiandocapimust implementT. TypeScript enforces this at the call site since both are typed asT. - Only methods of
Tare routed through the fallback logic. Thenamegetter is special-cased to reflect the resolved backend. - Non-method properties are returned from the SCAPI target only and are not switched on fallback. By convention, backends should be method bags — any state beyond
nameshould be encapsulated, not exposed. - Concurrency: if two calls race before resolution, both may attempt SCAPI. This is benign for read operations (idempotent retries) and acceptable for writes (both either succeed or fail with the same error). Each Proxy instance has its own state, so this concerns only shared use of a single wrapper.
Type Parameters
T
T extends BackendBase
Parameters
scapi
T
Primary (SCAPI) backend implementation
ocapi
T
Fallback (OCAPI) backend implementation
domainName
string
Used in fallback log messages, e.g. 'jobs'
Returns
T
A Proxy over scapi whose methods route through fallback logic
Example
ts
const backend = createFallbackBackend<JobsBackend>(scapiJobs, ocapiJobs, 'jobs');
await backend.executeJob('my-job'); // tries SCAPI, may fall back to OCAPI