Using Firebase Cloud Functions I am trying to expand a uri that is in a firestore document and replace it with the expanded uri.
I am using the tall npm package (https://www.npmjs.com/package/tall) which is working well, I just am not able to get the resulting expanded uri into my object to put back into firestore.
I believe its not returning before the rest of my function finishes and therefore not giving me the data. When I tried using the example on the page for async and use await firebase gives an error.
I am assuming I am missing something very simple but after a solid day uploading to cloud functions, testing, and trying again I am beyond frustrated.
What am I missing?
exports.addonSanitized = functions.firestore
.document('addons/{addonId}')
.onCreate(doc => {
const addonId = doc.id;
const addon = doc.data();
const expandedLink = tall(addon.link)
.then(unshortenedUrl => console.log('Tall url', unshortenedUrl))
.catch(err => console.error('AAAW ????', err));
const sanitized = {
summary: `${expandedLink}`
};
return admin
.firestore()
.collection('addons')
.doc(addonId)
.update(sanitized)
.then(doc => console.log('Entry Sanitized', doc));
});
I expect the expandedLink to return the expanded link. What is being inputed into the document is [object Promise]