@salesforce/b2c-tooling-sdk / clients / ScopeTierManager
Class: ScopeTierManager<C>
Defined in: packages/b2c-tooling-sdk/src/clients/scapi-scope-tier.ts:49
Lazy-initialized manager for clients at different scope tiers.
- First read or write call builds the rw client and caches it.
- If the caller detects an
invalid_scopeerror on a read attempt, it callsdowngradeToReadOnly()and the next read uses the read-only client. - Once downgraded, write requests throw — the API client lacks rw scope.
The same rw client serves both read and write while the rw scope is valid; we only build a separate read-only client after a downgrade.
Type Parameters
C
C
Constructors
Constructor
new ScopeTierManager<
C>(opts):ScopeTierManager<C>
Defined in: packages/b2c-tooling-sdk/src/clients/scapi-scope-tier.ts:54
Parameters
opts
Returns
ScopeTierManager<C>
Accessors
resolvedTier
Get Signature
get resolvedTier():
ScopeTier|undefined
Defined in: packages/b2c-tooling-sdk/src/clients/scapi-scope-tier.ts:57
The currently-resolved tier, or undefined before first use.
Returns
ScopeTier | undefined
Methods
downgradeToReadOnly()
downgradeToReadOnly():
void
Defined in: packages/b2c-tooling-sdk/src/clients/scapi-scope-tier.ts:105
Marks the rw scope as unavailable and builds a read-only client. Subsequent getClientForWrite() calls will throw; reads use the read-only client.
Returns
void
getClientForRead()
getClientForRead():
C
Defined in: packages/b2c-tooling-sdk/src/clients/scapi-scope-tier.ts:88
Returns a client suitable for read operations. Prefers the rw client if it's already been used successfully (rw scope grants read too).
Returns
C
getClientForWrite()
getClientForWrite():
C
Defined in: packages/b2c-tooling-sdk/src/clients/scapi-scope-tier.ts:70
Returns a client suitable for write operations. Throws if we've already downgraded to read-only — the API client doesn't have the rw scope.
Throws ScapiCapabilityUnsupportedError so the SCAPI/OCAPI fallback wrapper recognizes this as a capability gap and routes the write through OCAPI in auto mode (instead of pinning to SCAPI after a successful read and then failing the write).
Returns
C
tryRead()
tryRead<
R>(fn):Promise<R>
Defined in: packages/b2c-tooling-sdk/src/clients/scapi-scope-tier.ts:119
Runs a read operation, downgrading to the read-only client and retrying once if the rw attempt fails with invalid_scope. Backends should wrap their reads with this so an API client provisioned with only the read-only scope (e.g. sfcc.scripts) can still read through SCAPI.
Writes do not go through this helper — they always require rw, and getClientForWrite() already throws after a downgrade.
Type Parameters
R
R
Parameters
fn
(client) => Promise<R>
Returns
Promise<R>