import { requestMethod } from "../routes.example.js";
import { json } from "./store.js";
import { DAY_MS } from "../../../../data/index.js";
console.log("Inside offers service worker!");
requestMethod.get({ pathname: "/offers" }, async () => {
    console.log("Inside offers fetch");
    const [products, prices,] = await Promise.all([
        json.get("products:/products"),
        json.get("prices:/prices")
    ]);
    console.log({ prices, products });
    const productPrices = Object.fromEntries(prices.map(({ productId, value }) => [productId, value]));
    const offers = products
        .map((product) => {
        const { productId } = product;
        const price = productPrices[productId];
        return {
            ...product,
            isAvailable: typeof price === "number",
            price,
            validUntil: new Date(Date.now() + DAY_MS).toISOString()
        };
    });
    return Response.json(offers);
});
//# sourceMappingURL=offers.js.map