@salesforce/b2c-tooling-sdk / instance / B2CInstance
Class: B2CInstance
Defined in: packages/b2c-tooling-sdk/src/instance/index.ts:141
Represents a connection to a B2C Commerce instance.
Provides lazy-loaded, typed API clients for WebDAV and OCAPI operations. Authentication is handled automatically based on the configured credentials.
Example
// From configuration (recommended)
import { resolveConfig } from '@salesforce/b2c-tooling-sdk/config';
const config = await resolveConfig({
clientId: process.env.SFCC_CLIENT_ID,
clientSecret: process.env.SFCC_CLIENT_SECRET,
});
const instance = config.createB2CInstance();
// WebDAV uses Basic auth if available, falls back to OAuth
await instance.webdav.mkcol('Cartridges/v1');
// OCAPI always uses OAuth
const { data } = await instance.ocapi.GET('/sites', {});Constructors
Constructor
new B2CInstance(
config,auth,options):B2CInstance
Defined in: packages/b2c-tooling-sdk/src/instance/index.ts:154
Creates a new B2CInstance.
Parameters
config
Instance configuration (hostname, code version)
auth
Authentication configuration
options
B2CInstanceOptions = {}
Optional runtime dependencies, including a pre-resolved OAuth strategy
Returns
B2CInstance
Properties
auth
readonlyauth:AuthConfig
Defined in: packages/b2c-tooling-sdk/src/instance/index.ts:156
Authentication configuration
config
readonlyconfig:InstanceConfig
Defined in: packages/b2c-tooling-sdk/src/instance/index.ts:155
Instance configuration (hostname, code version)
Accessors
apiBackend
Get Signature
get apiBackend():
"ocapi"|"scapi"|"auto"
Defined in: packages/b2c-tooling-sdk/src/instance/index.ts:172
Backend preference for operations that support both OCAPI and SCAPI. Defaults to 'auto' when not configured.
Returns
"ocapi" | "scapi" | "auto"
hasOAuthCredentials
Get Signature
get hasOAuthCredentials():
boolean
Defined in: packages/b2c-tooling-sdk/src/instance/index.ts:220
Whether an API client is available for OCAPI and SCAPI calls (configured OAuth credentials or a caller-provided OAuth strategy). Without one, only WebDAV can be used, with Basic auth or a browser login.
Returns
boolean
ocapi
Get Signature
get ocapi():
OcapiClient
Defined in: packages/b2c-tooling-sdk/src/instance/index.ts:277
OCAPI Data API client.
Returns the openapi-fetch client directly with full type safety. Always uses OAuth authentication.
Example
const { data, error } = await instance.ocapi.GET('/sites', {});
const { data, error } = await instance.ocapi.PATCH('/code_versions/{code_version_id}', {
params: { path: { code_version_id: 'v1' } },
body: { active: true }
});Returns
The OCAPI Data API client (openapi-fetch Client with full type safety).
scapiClientConfig
Get Signature
get scapiClientConfig():
ScapiClientConfig|undefined
Defined in: packages/b2c-tooling-sdk/src/instance/index.ts:201
SCAPI connection coordinates + a scope-flexible auth strategy, or undefined when this instance cannot reach SCAPI under auto mode.
This is the forward-looking seam for the OCAPI → SCAPI transition: a SCAPI client factory (jobs, sites, scripts, …) needs only a B2CInstance, not a separately-threaded shortCode/tenantId/auth bundle. When OCAPI is eventually removed, the OCAPI accessors disappear and this stays.
Returns undefined unless all of the following hold:
shortCodeandtenantIdare configured, and- the configured OAuth flow is stateless and scope-flexible — client-credentials (clientId + clientSecret) or JWT Bearer (clientId + cert/key).
Browser user-auth flows (Authorization Code + PKCE and deprecated implicit) are excluded on purpose because SCAPI Admin APIs currently only support system authentication. Fixed-token stored sessions are also excluded because they cannot request the sfcc.* scopes SCAPI needs. This is not an auto-only restriction — because both consumers (the dual-backend factory and the system-job runner) gate on this getter, even explicit --api-backend scapi cannot use SCAPI with implicit/stateful auth; it fails with a clear error naming the flow requirement. SCAPI requires client-credentials or JWT Bearer.
Returns
ScapiClientConfig | undefined
webdav
Get Signature
get webdav():
WebDavClient
Defined in: packages/b2c-tooling-sdk/src/instance/index.ts:247
WebDAV client for file operations.
Uses Basic auth if username/password are configured, otherwise falls back to OAuth.
Example
await instance.webdav.mkcol('Cartridges/v1');
await instance.webdav.put('Cartridges/v1/app.zip', content);
const entries = await instance.webdav.propfind('Cartridges');Returns
The lazy-initialized WebDAV client for file operations.
webdavHostname
Get Signature
get webdavHostname():
string
Defined in: packages/b2c-tooling-sdk/src/instance/index.ts:164
The hostname to use for WebDAV operations. Falls back to main hostname if not specified.
Returns
string
webdavUsesUserAuth
Get Signature
get webdavUsesUserAuth():
boolean
Defined in: packages/b2c-tooling-sdk/src/instance/index.ts:230
Whether the WebDAV client authenticates as an Account Manager user (browser login) rather than with Basic auth or an API client token. User tokens are authorized by the user's Business Manager permissions. false until the webdav client has been created.
Returns
boolean