diff --git a/package.json b/package.json index cf6cce6..cfd0200 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "epicgames-freebies-claimer", - "version": "1.5.7", + "version": "1.5.8", "description": "Claim free game promotions from the Epic Game Store", "author": { "name": "Revadike", @@ -60,4 +60,4 @@ "epicgames-client": "Revadike/node-epicgames-client#develop", "tracer": "^1.0.3" } -} \ No newline at end of file +} diff --git a/src/gamePromotions.js b/src/gamePromotions.js index 3e766e6..d735556 100644 --- a/src/gamePromotions.js +++ b/src/gamePromotions.js @@ -18,7 +18,8 @@ async function getAddonForSlug(client, slug) { } async function getOfferId(client, promo, locale = "en-US") { - let offerId = null; + let id = null; + let namespace = null; let slug = (promo.productSlug || promo.urlSlug).split("/")[0]; let isBundle = (promo) => Boolean(promo.categories.find((cat) => cat.path === "bundles")); let isAddon = (promo) => promo.offerType === "EDITION" || Boolean(promo.categories.find((cat) => cat.path === "addons")); @@ -26,18 +27,24 @@ async function getOfferId(client, promo, locale = "en-US") { if (isAddon(promo)) { let result = await getAddonForSlug(client, slug, locale); // eslint-disable-next-line prefer-destructuring - offerId = result.data.StorePageMapping.mapping.mappings.offerId; + id = result.data.StorePageMapping.mapping.mappings.offerId; } else if (isBundle(promo)) { let result = await client.getBundleForSlug(slug, locale); let page = result.pages ? result.pages.find((p) => p.offer.id === promo.id) || result.pages[0] : result; - offerId = page.offer.id; + // eslint-disable-next-line prefer-destructuring + id = page.offer.id; + // eslint-disable-next-line prefer-destructuring + namespace = page.offer.namespace; } else { let result = await client.getProductForSlug(slug, locale); let page = result.pages ? result.pages.find((p) => p.offer.id === promo.id) || result.pages[0] : result; - offerId = page.offer.id; + // eslint-disable-next-line prefer-destructuring + id = page.offer.id; + // eslint-disable-next-line prefer-destructuring + namespace = page.offer.namespace; } - return offerId; + return { namespace, id }; } async function freeGamesPromotions(client, country = "US", allowCountries = "US", locale = "en-US") { @@ -48,8 +55,9 @@ async function freeGamesPromotions(client, country = "US", allowCountries = "US" && offer.promotions.promotionalOffers[0].promotionalOffers.find((p) => p.discountSetting.discountPercentage === 0)); let freeOffers = await Promise.all(free.map(async(promo) => { - let { title, namespace } = promo; - let id = await getOfferId(client, promo, locale); + let { title } = promo; + let { namespace, id } = await getOfferId(client, promo, locale); + namespace = namespace || promo.namespace; return { title, id, namespace }; }));