The product, with all its sizes
Whether it could be watched
await addPriceAlert(product); // true
await addPriceAlert({ ...product, cacheKey: undefined }); // false
export async function addPriceAlert(product: Product): Promise<boolean> {
const id = productSeriesKey(product);
const ref = toProductRef(product);
if (!id || !ref) return false;
const alert: PriceAlert = {
id,
supplier: product.supplier,
ref,
title: product.title,
permalink: product.permalink ?? product.url,
createdAt: Date.now(),
failures: 0,
lastPrices: collectNativePrices(product),
};
await cstorage.local.set({ [priceAlertKey(id)]: alert });
void trackEvent('price_alert_created', { supplier: alert.supplier });
return true;
}
Starts watching a product. Storage is called before anything is awaited, so the write survives the popup closing right after.