import SDK from '@sitecore-feaas/sdk' const sdk = new SDK({ // API key to access the library (can be found in Library settings in web app) apiKey: 'my-api-key', // enable logging verbose: true, // Optional: Configuring the non-production environment backend: 'https://components.sitecorecloud.io/api', frontend: 'https://components.sitecorecloud.io' }) // Optional: Set XM Cloud tenant context to sync datasources with // sdk.auth.tenant = tenant // Access library const library = await sdk.libraries.get({ id: 'my-library' }) // Fetch all dependent resources (components, stylesheets, datasources) // Everything EXCLUDING component versions await library.fetchAll() // Can access components now: for (const collection of library.collections) { console.log('- Collection', collection.name) for (const component of collection.components) { console.log(' |- Component', component.name) // Fetch versions on demand for (const version of await component.versions.fetch()) { console.log(' |- Version: ', version.name) } } } // Datasources (`sdk.datasources` is `library.datasources` combined with `tenant.datasources` ) if (sdk.auth.tenant) { for (const datasource of sdk.auth.tenant.datasources) { console.log('- Tenant datasource', datasource.name) } } for (const datasource of library.datasources) { console.log('- Custom datasource', datasource.name) } for (const rule of library.stylesheet.rules) { if (rule.type == 'theme') console.log('- Theme', rule.details.title) }