Skip to content

Commit 19837e6

Browse files
authored
Updated and clarified default values in the readme, small code refactors (#11)
1 parent 512983f commit 19837e6

File tree

6 files changed

+168
-158
lines changed

6 files changed

+168
-158
lines changed

README.md

Lines changed: 103 additions & 75 deletions
Large diffs are not rendered by default.

config.default.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@
1414
"keepCompleteProperties": false,
1515
"includedProperties": {
1616
"productTitle": true,
17-
"productId": true,
18-
"developerName": true,
19-
"publisherName": true,
20-
"categories": true,
17+
"productId": false,
18+
"developerName": false,
19+
"publisherName": false,
20+
"categories": false,
2121
"productDescription": {
22-
"enabled": true,
22+
"enabled": false,
2323
"preferShort": false
2424
},
2525
"images": {
26-
"enabled": true,
26+
"enabled": false,
2727
"imageTypes": {
2828
"TitledHeroArt": -1,
2929
"SuperHeroArt": -1,
@@ -37,23 +37,23 @@
3737
}
3838
},
3939
"releaseDate": {
40-
"enabled": true,
40+
"enabled": false,
4141
"format": "date"
4242
},
4343
"userRating": {
44-
"enabled": true,
44+
"enabled": false,
4545
"aggregationInterval": "AllTime",
4646
"format": "percentage"
4747
},
4848
"pricing": {
49-
"enabled": true,
49+
"enabled": false,
5050
"priceTypes": [
5151
"ListPrice",
5252
"MSRP",
5353
"WholesalePrice"
5454
],
5555
"missingPricePolicy": "useNull"
5656
},
57-
"storePage": true
57+
"storePage": false
5858
}
5959
}

config.schema.json

Lines changed: 47 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -369,59 +369,59 @@
369369
]
370370
},
371371
"treatEmptyStringsAsNull": {
372-
"description": "Whether or not to treat empty strings as null values.",
372+
"description": "Whether to treat empty strings as null values.",
373373
"type": "boolean",
374374
"default": true
375375
},
376376
"keepCompleteProperties": {
377-
"description": "Whether or not to keep the original, complete list of properties for the fetched games. Will be saved in a separate file per platform and market.",
377+
"description": "Whether to keep the original, complete list of properties for the fetched games. Will be saved in a separate file per platform and market.",
378378
"type": "boolean",
379379
"default": false
380380
},
381381
"includedProperties": {
382-
"description": "The properties that should be contained in the cleaned version of the API response.",
382+
"description": "The properties that should be contained in the filtered version of the API response.",
383383
"type": "object",
384384
"properties": {
385385
"productTitle": {
386-
"description": "Whether or not to include the title of the game.",
386+
"description": "Whether to include the title of the game.",
387387
"type": "boolean",
388388
"default": true
389389
},
390390
"productId": {
391-
"description": "Whether or not to include the product ID of the game.",
391+
"description": "Whether to include the product ID of the game.",
392392
"type": "boolean",
393-
"default": true
393+
"default": false
394394
},
395395
"developerName": {
396-
"description": "Whether or not to include the name of the developer of the game.",
396+
"description": "Whether to include the name of the game's developer.",
397397
"type": "boolean",
398-
"default": true
398+
"default": false
399399
},
400400
"publisherName": {
401-
"description": "Whether or not to include the name of the publisher of the game.",
401+
"description": "Whether to include the name of the game's publisher.",
402402
"type": "boolean",
403-
"default": true
403+
"default": false
404404
},
405405
"categories": {
406-
"description": "Whether or not to include the game's categories. This can be used as tags.",
406+
"description": "Whether to include the game's categories.",
407407
"type": "boolean",
408-
"default": true
408+
"default": false
409409
},
410410
"productDescription": {
411-
"description": "The description of the game.",
411+
"description": "Whether to include the description of the game.",
412412
"type": "object",
413413
"default": {
414-
"enabled": true,
414+
"enabled": false,
415415
"preferShort": false
416416
},
417417
"properties": {
418418
"enabled": {
419-
"description": "Whether or not to include the description of the game.",
419+
"description": "Whether to include the description of the game.",
420420
"type": "boolean",
421-
"default": true
421+
"default": false
422422
},
423423
"preferShort": {
424-
"description": "Whether or not to prefer the short description of the game, if one exists.",
424+
"description": "Whether to prefer the short description of the game over the long description, if one exists.",
425425
"type": "boolean",
426426
"default": false
427427
}
@@ -432,31 +432,30 @@
432432
"additionalProperties": false
433433
},
434434
"images": {
435-
"description": "Whether or not to include image URL's for the game.",
435+
"description": "Whether to include image URL's for the game.",
436436
"type": "object",
437437
"default": {
438-
"enabled": true,
439-
"maxImages": 0,
440-
"imageTypes": [
441-
"TitledHeroArt",
442-
"SuperHeroArt",
443-
"Logo",
444-
"Poster",
445-
"Screenshot",
446-
"BoxArt",
447-
"Hero",
448-
"BrandedKeyArt",
449-
"FeaturePromotionalSquareArt"
450-
]
438+
"enabled": false,
439+
"imageTypes": {
440+
"TitledHeroArt": -1,
441+
"SuperHeroArt": -1,
442+
"Logo": -1,
443+
"Poster": -1,
444+
"Screenshot": -1,
445+
"BoxArt": -1,
446+
"Hero": -1,
447+
"BrandedKeyArt": -1,
448+
"FeaturePromotionalSquareArt": -1
449+
}
451450
},
452451
"properties": {
453452
"enabled": {
454-
"description": "Whether or not to include any the images in the result.",
453+
"description": "Whether to include image URL's for the game.",
455454
"type": "boolean",
456-
"default": true
455+
"default": false
457456
},
458457
"imageTypes": {
459-
"description": "What kinds of images should be considered, and a maximum of many of each type should be chosen. A value of -1 indicates no limit.",
458+
"description": "What kinds of images should be included in the output, and a maximum of how many of each type should be chosen.",
460459
"type": "object",
461460
"default": {
462461
"TitledHeroArt": -1,
@@ -527,17 +526,17 @@
527526
"additionalProperties": false
528527
},
529528
"releaseDate": {
530-
"description": "Whether or not to include the game's release date.",
529+
"description": "Whether to include the game's release date.",
531530
"type": "object",
532531
"default": {
533-
"enabled": true,
532+
"enabled": false,
534533
"format": "date"
535534
},
536535
"properties": {
537536
"enabled": {
538-
"description": "Whether or not to include the game's release date.",
537+
"description": "Whether to include the game's release date.",
539538
"type": "boolean",
540-
"default": true
539+
"default": false
541540
},
542541
"format": {
543542
"description": "How to format the date string. Either the full dateTime (YYYY-MM-DDTHH:mm:ss.sssssssZ) or just the date (YYYY-MM-DD).",
@@ -556,18 +555,18 @@
556555
"additionalProperties": false
557556
},
558557
"userRating": {
559-
"description": "Whether or not to include the game's user rating.",
558+
"description": "Whether to include the game's user rating.",
560559
"type": "object",
561560
"default": {
562-
"enabled": true,
561+
"enabled": false,
563562
"aggregationInterval": "AllTime",
564563
"format": "percentage"
565564
},
566565
"properties": {
567566
"enabled": {
568-
"description": "Whether or not to include the game's user rating.",
567+
"description": "Whether to include the game's user rating.",
569568
"type": "boolean",
570-
"default": true
569+
"default": false
571570
},
572571
"aggregationInterval": {
573572
"description": "Which kind of interval to use for rating aggregation.",
@@ -597,10 +596,10 @@
597596
"additionalProperties": false
598597
},
599598
"pricing": {
600-
"description": "Whether or not to include the game's price information. The currency that is used is dependent on the chosen \"market\".",
599+
"description": "Whether to include the game's price information. The currency that is used is dependent on the chosen \"market\".",
601600
"type": "object",
602601
"default": {
603-
"enabled": true,
602+
"enabled": false,
604603
"priceTypes": [
605604
"ListPrice",
606605
"MSRP",
@@ -612,10 +611,10 @@
612611
"enabled": {
613612
"description": "Whether or not to include the game's price information. The currency that is used is dependent on the chosen \"market\".",
614613
"type": "boolean",
615-
"default": true
614+
"default": false
616615
},
617616
"priceTypes": {
618-
"description": "Which kinds of prices to include. Choose from ListPrice, MSRP and WholesalePrice (i.e. applied discounts).",
617+
"description": "Which kinds of prices to include. Choose from \"ListPrice\", \"MSRP\" and \"WholesalePrice\" (i.e. with discounts applied).",
619618
"type": "array",
620619
"default": [
621620
"ListPrice",
@@ -662,9 +661,9 @@
662661
"additionalProperties": false
663662
},
664663
"storePage": {
665-
"description": "Whether or not to include the game's store page URL. NOTE: THIS IS NOT GUARANTEED TO ALWAYS RESULT IN A WORKING URL, AS IT NEEDS TO BE INFERRED AND IS NOT AVAILABLE THROUGH THE API.",
664+
"description": "Whether to include the game's store page URL. Note that this is not guaranteed to always result in a working URL, as it needs to be inferred and is not available through the API.",
666665
"type": "boolean",
667-
"default": true
666+
"default": false
668667
}
669668
},
670669
"additionalProperties": false,

index.js

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,20 @@ try {
4646

4747
// ----- Output -----
4848

49-
// Create the output directory if it doesn't exist
5049
if (!fs.existsSync(__dirname + '/output')) {
5150
fs.mkdirSync(__dirname + '/output');
5251
}
5352

5453
// ---------- Main ----------
5554

56-
// If the user wants empty strings to be treated as null or not
5755
const emptyValuePlaceholder = CONFIG.treatEmptyStringsAsNull ? null : "";
5856

5957
main();
6058

6159
async function main() {
6260
// Fetch Game Pass game ID's and properties for each pass type and market specified in the configuration
6361
// We do this in parallel to speed up the process
62+
// While the functions do return the formatted properties, we currently do not use them here, as writing the output files is handled by the functions themselves
6463
for (const market of CONFIG.markets) {
6564
if (CONFIG.platformsToFetch.includes("console")) {
6665
const consoleFormattedProperties = runScriptForPassTypeAndMarket("console", market);
@@ -75,14 +74,9 @@ async function main() {
7574
}
7675

7776
async function runScriptForPassTypeAndMarket(passType, market) {
78-
// Fetch Game Pass game ID's
7977
const gameIds = await fetchGameIDs(passType, market);
80-
81-
// Fetch Game Pass game properties
8278
const gameProperties = await fetchGameProperties(gameIds, passType, market);
83-
84-
// Format the data according to the configuration
85-
const formattedData = formatData(gameProperties, passType, market);
79+
const formattedData = formatData(gameProperties, passType);
8680

8781
fs.writeFileSync(`./output/formattedGameProperties_${passType}_${market}.json`, JSON.stringify(formattedData, null, 2));
8882

@@ -91,9 +85,8 @@ async function runScriptForPassTypeAndMarket(passType, market) {
9185

9286
// ---------- Fetch game ID's & properties ----------
9387

88+
// Get all Game Pass Game ID's for this market
9489
async function fetchGameIDs(passType, market) {
95-
// Get all Game Pass Game ID's for this market
96-
9790
const APIIds = {
9891
"console": "f6f1f99f-9b49-4ccd-b3bf-4d9767a77f5e",
9992
"pc": "fdd9e2a7-0fee-49f6-ad69-4354098401ff",
@@ -114,27 +107,19 @@ async function fetchGameProperties(gameIds, passType, market) {
114107
.then((response) => response.json())
115108
.then((data) => {
116109
if (CONFIG.keepCompleteProperties) {
117-
// Write the data to a file
118110
fs.writeFileSync(`./output/completeGameProperties_${passType}_${market}.json`, JSON.stringify(data, null, 2));
119111
}
120112
return data;
121113
});
122114
}
123115

124116
// Format the data according to the configuration
125-
function formatData(gameProperties, passType, market) {
117+
function formatData(gameProperties, passType) {
126118
console.log(`Formatting game properties for ${gameProperties.Products.length} ${passType} games...`);
127119

128-
// Create a new object to store the formatted data
129-
let formattedData = {};
130-
// If the user wants the result to be an array
131-
if (CONFIG.outputFormat === "array") {
132-
formattedData = [];
133-
}
120+
let formattedData = CONFIG.outputFormat === "array" ? [] : {};
134121

135-
// Loop through each game
136122
for (const game of gameProperties.Products) {
137-
// Create a new object for this game
138123
let index;
139124
switch (CONFIG.outputFormat) {
140125
case "array":
@@ -152,9 +137,7 @@ function formatData(gameProperties, passType, market) {
152137
}
153138
formattedData[index] = {};
154139

155-
// Loop through each property
156140
for (const [property, propertyValue] of Object.entries(CONFIG.includedProperties)) {
157-
// Get the value of the property
158141
const result = getPropertyValue(game, property, propertyValue);
159142

160143
// Add the property to the object, only if it is not undefined. undefined indicates the property was present in the config, but disabled.

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "game-pass-api",
33
"type": "module",
4-
"version": "1.1.1",
4+
"version": "1.2.0",
55
"description": "Get all games currently available for Xbox Game Pass on any platform, with their features and properties formatted just the way you need!",
66
"main": "index.js",
77
"dependencies": {

0 commit comments

Comments
 (0)