Skip to content

VS Code Safety Mode + content library fixes#399

Open
clavery wants to merge 3 commits intomainfrom
vscode-safety-and-content-fixes
Open

VS Code Safety Mode + content library fixes#399
clavery wants to merge 3 commits intomainfrom
vscode-safety-and-content-fixes

Conversation

@clavery
Copy link
Copy Markdown
Collaborator

@clavery clavery commented May 5, 2026

Summary

  • Enforce Safety Mode in the VS Code extension. Register the SDK safety middleware on the global middleware registry from the extension so destructive HTTP calls honor SFCC_SAFETY_LEVEL, SFCC_SAFETY_CONFIRM, SFCC_SAFETY_CONFIG, and per-instance safety blocks in dw.json. Add registerSafeCommand() which evaluates every VS Code command against the guard (command rules like { "command": "b2c-dx.sandbox.delete", "action": "block" }), mirroring BaseCommand.evaluateCommandSafety(). Sandbox destructive ops additionally flow through runWithSafety() for a native VS Code confirm modal.
  • Fix Content Libraries tree stale on instance switch. ContentConfigProvider now also clears browsed libraries (not just the cache) on onDidReset, so the tree re-seeds from the new instance's contentLibrary.
  • Support assetQuery as a first-class config field. Settable in dw.json, package.json b2c block, or SFCC_ASSET_QUERY. VS Code tree + b2c content export both honor it; --asset-query flag still wins when provided.

Notes

  • CLI and extension command IDs differ (oclif sandbox:delete vs VS Code b2c-dx.sandbox.delete) — rules are not portable verbatim between them. Worth calling out in the Safety docs as a follow-up.
  • setup inspect doesn't render the safety section (pre-existing display gap noticed during this work). Not fixed here; small follow-up.

Test plan

  • VS Code — set SFCC_SAFETY_LEVEL=NO_DELETE in the host shell; right-click → Delete a sandbox → confirm it blocks with an error toast.
  • VS Code — add "safety": { "level": "NONE", "rules": [{ "command": "b2c-dx.sandbox.extendExpiration", "action": "confirm" }] } to a dw.json config → Extend Expiration shows a native modal before prompting for TTL.
  • VS Code — switch between two instances with different contentLibrary values; Content Libraries tree reloads with the new library and drops the old one.
  • CLI — b2c content export PAGE_ID -l LIB_ID uses assetQuery from dw.json when --asset-query is not passed; --asset-query still overrides.
  • pnpm --filter @salesforce/b2c-tooling-sdk run test:agent and pnpm --filter @salesforce/b2c-cli run test:agent both green.

clavery added 3 commits May 5, 2026 12:33
Register the SDK safety middleware on the global middleware registry from the
extension so destructive HTTP calls honor SFCC_SAFETY_LEVEL, SFCC_SAFETY_CONFIRM,
SFCC_SAFETY_CONFIG, and per-instance `safety` blocks in dw.json. Rebuild the
guard on config reset so instance switches re-apply the policy.

Add registerSafeCommand() that evaluates every VS Code command against the guard
(command rules like { "command": "b2c-dx.sandbox.delete", "action": "block" }),
mirroring BaseCommand's per-command evaluation. Replace vscode.commands.registerCommand
across all feature areas. Sandbox destructive ops additionally run through
runWithSafety() for an idiomatic VS Code modal when the policy requires confirm.
ContentConfigProvider was clearing only the library cache on config reset,
so browsed libraries from the previous instance persisted in the tree. Also
reset the browsed libraries list so getRootChildren() re-seeds from the new
instance's contentLibrary on the next refresh.
Add assetQuery to NormalizedConfig and DwJsonConfig so it can be set
per-instance in dw.json, project-wide in package.json under "b2c", or via
SFCC_ASSET_QUERY. Wire it through the dw.json↔normalized mapping, merge, env
source array parsing, and PackageJsonSource allow-list.

The VS Code Content Libraries tree and export commands now pass the resolved
value to fetchContentLibrary/exportContent; b2c content export falls back to
the config value when --asset-query isn't provided (default remains
["image.path"]).
@clavery clavery marked this pull request as ready for review May 6, 2026 03:40
@clavery clavery requested a review from wei-liu-sf as a code owner May 6, 2026 03:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant