Skip to content

@salesforce/b2c-tooling-sdk / safety / withSafetyConfirmation

Function: withSafetyConfirmation() ​

withSafetyConfirmation<T>(guard, operation, confirmHandler): Promise<T>

Defined in: packages/b2c-tooling-sdk/src/safety/with-confirmation.ts:68

Execute an operation with safety confirmation support.

If the operation throws SafetyConfirmationRequired, the confirmHandler is called. If the user confirms, the operation is retried with a temporary exemption. If the user cancels (or the handler returns false), a SafetyBlockedError is thrown.

Non-confirmation errors are re-thrown as-is.

Type Parameters ​

T ​

T

Parameters ​

guard ​

SafetyGuard

The SafetyGuard instance

operation ​

() => Promise<T>

The operation to execute

confirmHandler ​

ConfirmHandler

Context-specific confirmation handler

Returns ​

Promise<T>

The operation's return value

Example ​

typescript
// CLI usage
const result = await withSafetyConfirmation(
  guard,
  () => instance.ocapi.POST('/jobs/import/executions', ...),
  async (eval) => {
    if (!process.stdin.isTTY) return false;
    return confirm(`Safety: ${eval.reason}. Proceed?`);
  },
);

// VS Code usage
const result = await withSafetyConfirmation(
  guard,
  () => runJobImport(),
  async (eval) => {
    const choice = await vscode.window.showWarningMessage(eval.reason, { modal: true }, 'Proceed');
    return choice === 'Proceed';
  },
);

Released under the Apache-2.0 License.