@@ -18,26 +18,33 @@ async function getAddonForSlug(client, slug) {
1818}
1919
2020async 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
4350async 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