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

[@salesforce/b2c-tooling-sdk](../../modules.md) / [clients](../index.md) / ScopeTierManager

# Class: ScopeTierManager\<C\>

Defined in: [packages/b2c-tooling-sdk/src/clients/scapi-scope-tier.ts:49](https://github.com/SalesforceCommerceCloud/b2c-developer-tooling/blob/2feab01f654eec77c6d702777ec2818472f131f1/packages/b2c-tooling-sdk/src/clients/scapi-scope-tier.ts#L49)

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_scope` error on a read attempt, it
  calls `downgradeToReadOnly()` 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](https://github.com/SalesforceCommerceCloud/b2c-developer-tooling/blob/2feab01f654eec77c6d702777ec2818472f131f1/packages/b2c-tooling-sdk/src/clients/scapi-scope-tier.ts#L54)

#### Parameters

##### opts

[`ScopeTierManagerOptions`](../interfaces/ScopeTierManagerOptions.md)\<`C`\>

#### Returns

`ScopeTierManager`\<`C`\>

## Accessors

### resolvedTier

#### Get Signature

> **get** **resolvedTier**(): [`ScopeTier`](../type-aliases/ScopeTier.md) \| `undefined`

Defined in: [packages/b2c-tooling-sdk/src/clients/scapi-scope-tier.ts:57](https://github.com/SalesforceCommerceCloud/b2c-developer-tooling/blob/2feab01f654eec77c6d702777ec2818472f131f1/packages/b2c-tooling-sdk/src/clients/scapi-scope-tier.ts#L57)

The currently-resolved tier, or undefined before first use.

##### Returns

[`ScopeTier`](../type-aliases/ScopeTier.md) \| `undefined`

## Methods

### downgradeToReadOnly()

> **downgradeToReadOnly**(): `void`

Defined in: [packages/b2c-tooling-sdk/src/clients/scapi-scope-tier.ts:105](https://github.com/SalesforceCommerceCloud/b2c-developer-tooling/blob/2feab01f654eec77c6d702777ec2818472f131f1/packages/b2c-tooling-sdk/src/clients/scapi-scope-tier.ts#L105)

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](https://github.com/SalesforceCommerceCloud/b2c-developer-tooling/blob/2feab01f654eec77c6d702777ec2818472f131f1/packages/b2c-tooling-sdk/src/clients/scapi-scope-tier.ts#L88)

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](https://github.com/SalesforceCommerceCloud/b2c-developer-tooling/blob/2feab01f654eec77c6d702777ec2818472f131f1/packages/b2c-tooling-sdk/src/clients/scapi-scope-tier.ts#L70)

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](ScapiCapabilityUnsupportedError.md) 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](https://github.com/SalesforceCommerceCloud/b2c-developer-tooling/blob/2feab01f654eec77c6d702777ec2818472f131f1/packages/b2c-tooling-sdk/src/clients/scapi-scope-tier.ts#L119)

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`\>
