Developer Preview — This project is in active development. APIs may change. Provide feedback
Skip to content

@salesforce/b2c-tooling-sdk / operations/content / Library

Class: Library

Defined in: packages/b2c-tooling-sdk/src/operations/content/library.ts:172

Provides an interface for manipulating B2C Commerce content libraries.

Use the static Library.parse() factory to create instances from library XML. The library tree supports filtering, traversal, mutation, and serialization back to importable XML.

Example

typescript
const library = await Library.parse(xmlString);

// Filter to specific pages
library.filter(node => node.id === 'homepage');

// Traverse visible nodes
library.traverse(node => {
  console.log(node.id, node.type);
});

// Serialize back to XML
const xml = await library.toXMLString({ traverseHidden: false });

Properties

assetQuery

assetQuery: string[] = []

Defined in: packages/b2c-tooling-sdk/src/operations/content/library.ts:173


tree

tree: LibraryNode

Defined in: packages/b2c-tooling-sdk/src/operations/content/library.ts:174

Methods

filter()

filter(predicate, options): this

Defined in: packages/b2c-tooling-sdk/src/operations/content/library.ts:326

Filter the library tree by setting hidden flags on root children.

Parameters

predicate

FilterCallback

Return true to keep the node visible

options

Filter options

recursive?

boolean = false

Returns

this

this (for chaining)


getTreeString()

getTreeString(options): string

Defined in: packages/b2c-tooling-sdk/src/operations/content/library.ts:421

Returns a text tree visualization of the library structure.

Parameters

options

TreeStringOptions = {}

Tree string options (traversal and optional colorize function)

Returns

string

Multi-line tree string


nodes()

nodes(options): Generator<LibraryNode>

Defined in: packages/b2c-tooling-sdk/src/operations/content/library.ts:301

Generator-based depth-first iteration of the library tree.

Parameters

options

TraverseOptions = {}

Traversal options

Returns

Generator<LibraryNode>

Yields

LibraryNode for each visited node

Example

typescript
for (const node of library.nodes()) {
  console.log(node.id, node.type);
}

promoteToRoot()

promoteToRoot(node): this

Defined in: packages/b2c-tooling-sdk/src/operations/content/library.ts:352

Move a node from its current parent to the root of the library tree.

Useful for exporting individual components that are normally nested under pages. The node is removed from its original parent's children and added as a root child.

Parameters

node

LibraryNode

The node to promote

Returns

this

this (for chaining)


reset()

reset(): this

Defined in: packages/b2c-tooling-sdk/src/operations/content/library.ts:371

Reset all hidden flags, making every node visible again.

Returns

this

this (for chaining)


toJSON()

toJSON(): Record<string, unknown>

Defined in: packages/b2c-tooling-sdk/src/operations/content/library.ts:475

Returns a JSON-safe representation of the library tree.

Returns

Record<string, unknown>


toXMLString()

toXMLString(options): Promise<string>

Defined in: packages/b2c-tooling-sdk/src/operations/content/library.ts:389

Serialize the library back to importable XML.

Only includes visible content unless traverseHidden is true.

Parameters

options

Serialization options

traverseHidden?

boolean = true

Returns

Promise<string>

XML string


traverse()

traverse(callback, options): this

Defined in: packages/b2c-tooling-sdk/src/operations/content/library.ts:268

Depth-first traversal of the library tree.

Parameters

callback

TraverseCallback

Function called for each visited node

options

TraverseOptions = {}

Traversal options

Returns

this

this (for chaining)


parse()

static parse(libraryXML, options): Promise<Library>

Defined in: packages/b2c-tooling-sdk/src/operations/content/library.ts:192

Parse library XML into a Library tree.

Parameters

libraryXML

string

Raw XML string of a content library

options

LibraryParseOptions = {}

Parse options

Returns

Promise<Library>

Parsed Library instance

Released under the Apache-2.0 License.