Save new document after text replacement in Word Office add-in

I’m developing an office add-in to replace a VB macro that was responsable to search and replace some parameters into the document. At the moment I have the problem to find values into an array and replace the text placeholder into the document, my needing is to generate new documents from the template where the placeholders are placed.

At the moment when I run the process to replace the placeholders, the original document will be modified with the data, but for some parameters I’m unable to get the needed information from an array that is populated from a supabase database. How I can correctly mantain the original file and save different documents with the data I need to insert??

This is the code I’m using at the moment and that will not produce the desired result

// initialize an empty array for suppliers
let suppliers = []

export async function loadSuppliers() {
    //const table = document.getElementById('table-data')

    db.from('SuppliersList').select()
        .then( (response) => {
            suppliers = []
            response.data.forEach( (el) => {
                suppliers.push(el)
                //const tr = table.appendChild(document.createElement('tr'))
                //for( let i = 0; i < Object.keys(el).length; i++ ){
                //    const td = tr.appendChild(document.createElement('td'))
                //    td.innerText = Object.values(el)[i]
                //}
            });
            //console.log(suppliers)
        })
}

//This function is called only when the user fill a search input into a text field on the frontend of the addin
export async function searchSupplier() {
    //
    const searchInput = document.getElementById('searchbar').value
    //
    console.log(suppliers)
    //find the desired value into the suppliers array
    let d = suppliers.find( (el) => {
        if( el.codPdv === searchInput ){
            return el
        } else if ( el.codFor === searchInput ){
            return el
        }
    })
//console log will write in console undefined
    console.log(d)
}

//this function will be called when the user click a button on the front-end of the add-in
export async function run() {
    return Word.run( async (ctx) => {
        //
        const doc = ctx.document.body
        //
        let date = doc.search('[DATA]')
        let dateNow = new Date().getDate() 
        console.log(dateNow)
        date.load('text')
        //
        let supplierName = doc.search("[FORNITORE]")
        supplierName.load("text")
        //supplierName[0].insertText(,"replace")
        //console.log(supplierName)
        //
        let supplierAddress = doc.search("[INDIRIZZO_FORNITORE]")
        supplierAddress.load("text")
        //console.log(supplierAddress)
        //
        let supplierCap = doc.search("[CAP_FOR]")
        supplierCap.load("text")
        //console.log(supplierCap)
        //
        let supplierPlace = doc.search("[LUOGO_FOR]")
        supplierPlace.load("text")
        //console.log(supplierPlace)
        //
        let supplierProvince = doc.search("[PROVINCIA_FOR]")
        supplierProvince.load("text")
        //console.log(supplierProvince)
        //
        let supplierEmail = doc.search("[EMAIL_FOR]")
        supplierEmail.load("text")
        //console.log(supplierEmail)
        //
        let pdvCode = doc.search("[CODICE_PDV]")
        pdvCode.load("text")
        //console.log(pdvCode)
        //
        let pdvBrand = doc.search("[BRAND]")
        pdvBrand.load("text")
        //console.log(pdvBrand)
        //
        let pdvAddress = doc.search("[INDIRIZZO_PDV]")
        pdvAddress.load("text")
        //console.log(pdvAddress)
        //
        let pdvCap = doc.search("[CAP_PDV]")
        pdvCap.load("text")
        //console.log(pdvCap)
        //
        let pdvPlace = doc.search("[LUOGO_PDV]")
        pdvPlace.load("text")
        //console.log(pdvPlace)
        //
        let pdvProvince = doc.search("[PROVINCIA_PDV]") 
        pdvProvince.load("text")
        //console.log(pdvProvince)
        //
        let pdvHeader = doc.search("[RAG_SOCIALE_PDV]")
        pdvHeader.load("text")
        //console.log(pdvHeader)
        //
        let pdvVat = doc.search("[PARTITA_IVA_PDV]")
        pdvVat.load("text")
        //console.log(pdvVat)
        return ctx.sync().then( () => {
            //
            console.log(date)
            date.items[0].insertText(`${dateNow}`,'replace')


        })
    })
}

Thank you for the help.