Skip to content

Commit 1f213db

Browse files
committed
V1.5.8
1 parent 17222e8 commit 1f213db

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "epicgames-freebies-claimer",
3-
"version": "1.5.7",
3+
"version": "1.5.8",
44
"description": "Claim free game promotions from the Epic Game Store",
55
"author": {
66
"name": "Revadike",
@@ -60,4 +60,4 @@
6060
"epicgames-client": "Revadike/node-epicgames-client#develop",
6161
"tracer": "^1.0.3"
6262
}
63-
}
63+
}

src/gamePromotions.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,33 @@ async function getAddonForSlug(client, slug) {
1818
}
1919

2020
async function getOfferId(client, promo, locale = "en-US") {
21-
let offerId = null;
21+
let id = null;
22+
let namespace = null;
2223
let slug = (promo.productSlug || promo.urlSlug).split("/")[0];
2324
let isBundle = (promo) => Boolean(promo.categories.find((cat) => cat.path === "bundles"));
2425
let isAddon = (promo) => promo.offerType === "EDITION" || Boolean(promo.categories.find((cat) => cat.path === "addons"));
2526

2627
if (isAddon(promo)) {
2728
let result = await getAddonForSlug(client, slug, locale);
2829
// eslint-disable-next-line prefer-destructuring
29-
offerId = result.data.StorePageMapping.mapping.mappings.offerId;
30+
id = result.data.StorePageMapping.mapping.mappings.offerId;
3031
} else if (isBundle(promo)) {
3132
let result = await client.getBundleForSlug(slug, locale);
3233
let page = result.pages ? result.pages.find((p) => p.offer.id === promo.id) || result.pages[0] : result;
33-
offerId = page.offer.id;
34+
// eslint-disable-next-line prefer-destructuring
35+
id = page.offer.id;
36+
// eslint-disable-next-line prefer-destructuring
37+
namespace = page.offer.namespace;
3438
} else {
3539
let result = await client.getProductForSlug(slug, locale);
3640
let page = result.pages ? result.pages.find((p) => p.offer.id === promo.id) || result.pages[0] : result;
37-
offerId = page.offer.id;
41+
// eslint-disable-next-line prefer-destructuring
42+
id = page.offer.id;
43+
// eslint-disable-next-line prefer-destructuring
44+
namespace = page.offer.namespace;
3845
}
3946

40-
return offerId;
47+
return { namespace, id };
4148
}
4249

4350
async function freeGamesPromotions(client, country = "US", allowCountries = "US", locale = "en-US") {
@@ -48,8 +55,9 @@ async function freeGamesPromotions(client, country = "US", allowCountries = "US"
4855
&& offer.promotions.promotionalOffers[0].promotionalOffers.find((p) => p.discountSetting.discountPercentage === 0));
4956

5057
let freeOffers = await Promise.all(free.map(async(promo) => {
51-
let { title, namespace } = promo;
52-
let id = await getOfferId(client, promo, locale);
58+
let { title } = promo;
59+
let { namespace, id } = await getOfferId(client, promo, locale);
60+
namespace = namespace || promo.namespace;
5361
return { title, id, namespace };
5462
}));
5563

0 commit comments

Comments
 (0)