Skip to content

@salesforce/b2c-tooling-sdk / operations/mrt / waitForEnv

Function: waitForEnv()

waitForEnv(options, auth): Promise<{ }>

Defined in: packages/b2c-tooling-sdk/src/operations/mrt/env.ts:416

Waits for an environment to reach a terminal state (ACTIVE or failed).

Polls the environment status until it reaches ACTIVE, CREATE_FAILED, or PUBLISH_FAILED state, or until the timeout is reached.

Parameters

options

WaitForEnvOptions

Wait options including polling interval and timeout

auth

AuthStrategy

Authentication strategy (ApiKeyStrategy)

Returns

Promise<{ }>

The environment in its terminal state

Throws

Error if timeout is reached or environment fails

Example

typescript
import { ApiKeyStrategy } from '@salesforce/b2c-tooling-sdk/auth';
import { createEnv, waitForEnv } from '@salesforce/b2c-tooling-sdk/operations/mrt';

const auth = new ApiKeyStrategy(process.env.MRT_API_KEY!, 'Authorization');

// Create environment
const env = await createEnv({
  projectSlug: 'my-storefront',
  slug: 'staging',
  name: 'Staging'
}, auth);

// Wait for it to be ready
const readyEnv = await waitForEnv({
  projectSlug: 'my-storefront',
  slug: 'staging',
  timeout: 60000, // 1 minute
  onPoll: (e) => console.log(`State: ${e.state}`)
}, auth);

if (readyEnv.state === 'ACTIVE') {
  console.log('Environment is ready!');
}

All rights reserved.