Query Symbols in all content - Revalidate dependant pages when symbol updates

If you would like to query symbols in all builder contents of any page model then you can use the below script, this could be useful when publishing an update on Symbol and If want to revalidate all the pages that use this symbol

const API_KEY = "BUILDER_API_KEY";

// Get builder data using the model name 
async function getBuilderDataByModelName(modelName){
    let url = `https://cdn.builder.io/api/v2/content/${modelName}?apiKey=${API_KEY}&includeRefs=true`;
    try{
        let res = await fetch(url);
        return await res.json();
    }catch(err) {
        console.error(err);
    };
}
async function getAllSymbolIds(){
    let symbols = await getBuilderDataByModelName("symbol-card");
    //console.log(symbols);
    let symbolIds = [];
    [...symbols.results].forEach(symbol => {
        symbolIds.push(symbol.id);
    });

    return symbolIds;
}

async function getAllContents(){
    let content = await getBuilderDataByModelName("page");
    
    // Get all symbol Ids
    let symboldIds = await getAllSymbolIds();

    // Filter content based on symbol ids 
    let filteredResults = content.results.filter((each) => {
        let stringResult = JSON.stringify(each);
        for (let symbolId of symboldIds) {
            if (stringResult.includes(symbolId)) {
                return true;
            }
        }
        return false;
    });  
    
    console.log("filterred Results" , filteredResults);
}

// Get all contents symbols 
getAllContents()