New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

nintendo-switch-eshop

Package Overview
Dependencies
Maintainers
1
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nintendo-switch-eshop - npm Package Compare versions

Comparing version 7.1.1 to 7.1.2

15

CHANGELOG.md

@@ -5,2 +5,17 @@ # Changelog

# [7.1.2](https://github.com/favna/nintendo-switch-eshop/compare/v7.1.1...v7.1.2) - (2022-08-21)
## 🏠 Refactor
- Optimize `getGamesJapan` ([70c61cd](https://github.com/favna/nintendo-switch-eshop/commit/70c61cd3594643f379e49385b079942af50e81fa))
- Switch to @sapphire/result for error handling ([2a1f845](https://github.com/favna/nintendo-switch-eshop/commit/2a1f845411700d07f53fb0f5620b2da3cc9ecab0))
## 🐛 Bug Fixes
- Fixed `getQueriedGamesAmerica` not returning sale prices ([a428502](https://github.com/favna/nintendo-switch-eshop/commit/a42850208cb401918cf6752ba6014a8f5375f6d5))
## 🧪 Testing
- Use `expect.any` for Object checks ([b782ea7](https://github.com/favna/nintendo-switch-eshop/commit/b782ea73525368ecaa230ea64b9fb199cc0141fd))
# [7.1.1](https://github.com/favna/nintendo-switch-eshop/compare/v7.1.0...v7.1.1) - (2022-08-15)

@@ -7,0 +22,0 @@

22

dist/lib/getGames/getGamesAmerica.js

@@ -5,2 +5,3 @@ "use strict";

const fetch_1 = require("@sapphire/fetch");
const result_1 = require("@sapphire/result");
const querystring_1 = require("querystring");

@@ -60,17 +61,12 @@ const constants_1 = require("../utils/constants");

};
try {
const gamesResponse = await (0, fetch_1.fetch)(constants_1.US_GET_GAMES_URL, requestOptions, fetch_1.FetchResultTypes.JSON);
let allGames = [];
for (const results of gamesResponse.results) {
allGames = allGames.concat(results.hits);
}
allGames = (0, utils_1.arrayRemoveDuplicates)(allGames, 'slug');
return allGames;
const gamesResponse = await result_1.Result.fromAsync((0, fetch_1.fetch)(constants_1.US_GET_GAMES_URL, requestOptions, fetch_1.FetchResultTypes.JSON));
if (gamesResponse.isErr()) {
throw new utils_1.EshopError('Fetching of US Games failed');
}
catch (err) {
if (/(?:US_games_request_failed)/i.test(err.message)) {
throw new utils_1.EshopError('Fetching of US Games failed');
}
throw err;
let allGames = [];
for (const results of gamesResponse.unwrap().results) {
allGames = allGames.concat(results.hits);
}
allGames = (0, utils_1.arrayRemoveDuplicates)(allGames, 'slug');
return allGames;
};

@@ -77,0 +73,0 @@ exports.getGamesAmerica = getGamesAmerica;

@@ -5,2 +5,3 @@ "use strict";

const fetch_1 = require("@sapphire/fetch");
const result_1 = require("@sapphire/result");
const querystring_1 = require("querystring");

@@ -60,17 +61,12 @@ const constants_1 = require("../utils/constants");

};
try {
const gamesResponse = await (0, fetch_1.fetch)(constants_1.BR_GET_GAMES_URL, requestOptions, fetch_1.FetchResultTypes.JSON);
let allGames = [];
for (const results of gamesResponse.results) {
allGames = allGames.concat(results.hits);
}
allGames = (0, utils_1.arrayRemoveDuplicates)(allGames, 'slug');
return allGames;
const gamesResponse = await result_1.Result.fromAsync((0, fetch_1.fetch)(constants_1.BR_GET_GAMES_URL, requestOptions, fetch_1.FetchResultTypes.JSON));
if (gamesResponse.isErr()) {
throw new utils_1.EshopError('Fetching of BR Games failed');
}
catch (err) {
if (/(?:BR_games_request_failed)/i.test(err.message)) {
throw new utils_1.EshopError('Fetching of BR Games failed');
}
throw err;
let allGames = [];
for (const results of gamesResponse.unwrap().results) {
allGames = allGames.concat(results.hits);
}
allGames = (0, utils_1.arrayRemoveDuplicates)(allGames, 'slug');
return allGames;
};

@@ -77,0 +73,0 @@ exports.getGamesBrazil = getGamesBrazil;

@@ -5,2 +5,3 @@ "use strict";

const fetch_1 = require("@sapphire/fetch");
const result_1 = require("@sapphire/result");
const querystring_1 = require("querystring");

@@ -23,17 +24,12 @@ const constants_1 = require("../utils/constants");

options.locale = constants_1.EU_DEFAULT_LOCALE;
try {
const gamesData = await (0, fetch_1.fetch)(`${constants_1.EU_GET_GAMES_URL.replace('{locale}', options.locale)}?${(0, querystring_1.stringify)({
rows: options.limit,
...constants_1.EU_GET_GAMES_OPTIONS
})}`, fetch_1.FetchResultTypes.JSON);
return gamesData.response.docs;
const gamesData = await result_1.Result.fromAsync((0, fetch_1.fetch)(`${constants_1.EU_GET_GAMES_URL.replace('{locale}', options.locale)}?${(0, querystring_1.stringify)({
rows: options.limit,
...constants_1.EU_GET_GAMES_OPTIONS
})}`, fetch_1.FetchResultTypes.JSON));
if (gamesData.isErr()) {
throw new utils_1.EshopError('Fetching of EU Games failed');
}
catch (err) {
if (/(?:EU_games_request_failed)/i.test(err.message)) {
throw new utils_1.EshopError('Fetching of EU Games failed');
}
throw err;
}
return gamesData.unwrap().response.docs;
};
exports.getGamesEurope = getGamesEurope;
//# sourceMappingURL=getGamesEurope.js.map

@@ -5,5 +5,7 @@ "use strict";

const fetch_1 = require("@sapphire/fetch");
const result_1 = require("@sapphire/result");
const fast_xml_parser_1 = require("fast-xml-parser");
const constants_1 = require("../utils/constants");
const utils_1 = require("../utils/utils");
const parser = new fast_xml_parser_1.XMLParser();
/**

@@ -15,16 +17,13 @@ * Fetches all games on japanese eShops

const getGamesJapan = async () => {
try {
const parser = new fast_xml_parser_1.XMLParser();
const gamesJP = parser.parse(await (0, fetch_1.fetch)(constants_1.JP_GET_GAMES_URL, fetch_1.FetchResultTypes.Text));
const allGamesJP = gamesJP.TitleInfoList.TitleInfo;
return allGamesJP;
const response = await result_1.Result.fromAsync((0, fetch_1.fetch)(constants_1.JP_GET_GAMES_URL, fetch_1.FetchResultTypes.Text));
if (response.isErr()) {
throw new utils_1.EshopError('Fetching of JP Games failed');
}
catch (err) {
if (/(?:JP_games_request_failed)/i.test(err.message)) {
throw new utils_1.EshopError('Fetching of JP Games failed');
}
throw err;
const gamesJP = result_1.Result.from(() => parser.parse(response.unwrap()));
if (gamesJP.isErr()) {
throw new utils_1.EshopError('Parsing of JP Games failed');
}
return gamesJP.unwrap().TitleInfoList.TitleInfo;
};
exports.getGamesJapan = getGamesJapan;
//# sourceMappingURL=getGamesJapan.js.map

@@ -7,2 +7,3 @@ "use strict";

const utils_1 = require("../utils/utils");
const result_1 = require("@sapphire/result");
/**

@@ -17,3 +18,3 @@ * Fetches a subset of games from the American e-shops as based on a given query

const getQueriedGamesAmerica = async (query, { hitsPerPage = 200, page = 0 } = { hitsPerPage: 200, page: 0 }) => {
const { hits: newHits } = await (0, fetch_1.fetch)(constants_1.QUERIED_US_GET_GAMES_URL_NEW, {
const newGamesResult = await result_1.Result.fromAsync((0, fetch_1.fetch)(constants_1.QUERIED_US_GET_GAMES_URL_NEW, {
method: 'POST',

@@ -29,6 +30,7 @@ headers: {

})
}, fetch_1.FetchResultTypes.JSON);
if (!newHits.length)
}, fetch_1.FetchResultTypes.JSON));
if (newGamesResult.isErr() || newGamesResult.isOkAnd((v) => v.hits.length === 0)) {
throw new utils_1.EshopError(`No game results for the query "${query}"`);
const { hits: oldHits } = await (0, fetch_1.fetch)(constants_1.QUERIED_US_GET_GAMES_URL_OLD, {
}
const oldGamesResult = await result_1.Result.fromAsync((0, fetch_1.fetch)(constants_1.QUERIED_US_GET_GAMES_URL_OLD, {
method: 'POST',

@@ -44,7 +46,10 @@ headers: {

})
}, fetch_1.FetchResultTypes.JSON);
return enrichNewHitsWithOldHitData(newHits, oldHits);
}, fetch_1.FetchResultTypes.JSON));
if (oldGamesResult.isErr() || oldGamesResult.isOkAnd((v) => v.hits.length === 0)) {
throw new utils_1.EshopError(`No game results for the query "${query}"`);
}
return enrichNewHitsWithOldHitData(newGamesResult.unwrap().hits, oldGamesResult.unwrap().hits);
};
exports.getQueriedGamesAmerica = getQueriedGamesAmerica;
function enrichNewHitsWithOldHitData(oldHits, newHits) {
function enrichNewHitsWithOldHitData(newHits, oldHits) {
for (const newHit of newHits) {

@@ -51,0 +56,0 @@ const oldHitWithSameNsuid = oldHits.find((oldHit) => oldHit.nsuid === newHit.nsuid);

@@ -5,2 +5,3 @@ "use strict";

const fetch_1 = require("@sapphire/fetch");
const result_1 = require("@sapphire/result");
const querystring_1 = require("querystring");

@@ -18,3 +19,3 @@ const constants_1 = require("../utils/constants");

const getQueriedGamesBrazil = async (query, { hitsPerPage = 200, page = 0 } = { hitsPerPage: 200, page: 0 }) => {
const { hits } = await (0, fetch_1.fetch)(constants_1.QUERIED_BR_GET_GAMES_URL, {
const gamesResult = await result_1.Result.fromAsync((0, fetch_1.fetch)(constants_1.QUERIED_BR_GET_GAMES_URL, {
method: 'POST',

@@ -32,8 +33,9 @@ headers: {

})
}, fetch_1.FetchResultTypes.JSON);
if (!hits.length)
}, fetch_1.FetchResultTypes.JSON));
if (gamesResult.isErr() || gamesResult.isOkAnd((v) => v.hits.length === 0)) {
throw new utils_1.EshopError(`No game results for the query "${query}"`);
return hits;
}
return gamesResult.unwrap().hits;
};
exports.getQueriedGamesBrazil = getQueriedGamesBrazil;
//# sourceMappingURL=getQueriedGamesBrazil.js.map

@@ -5,2 +5,3 @@ "use strict";

const fetch_1 = require("@sapphire/fetch");
const result_1 = require("@sapphire/result");
const querystring_1 = require("querystring");

@@ -19,31 +20,24 @@ const constants_1 = require("../utils/constants");

const getPrices = async (country, gameIds, offset = 0, prices = []) => {
try {
const filteredIds = gameIds.slice(offset, offset + constants_1.PRICE_LIST_LIMIT);
const response = await (0, fetch_1.fetch)(`${constants_1.PRICE_GET_URL}?${(0, querystring_1.stringify)({
country,
ids: filteredIds,
limit: constants_1.PRICE_LIST_LIMIT,
...constants_1.PRICE_GET_OPTIONS
})}`, fetch_1.FetchResultTypes.JSON);
if (response.prices && response.prices.length + offset < gameIds.length) {
const accumulatedPrices = prices.concat(response.prices);
return await (0, exports.getPrices)(country, gameIds, offset + constants_1.PRICE_LIST_LIMIT, accumulatedPrices);
}
else if (response.prices) {
response.prices = response.prices.concat(prices);
return response;
}
return response;
const filteredIds = gameIds.slice(offset, offset + constants_1.PRICE_LIST_LIMIT);
const response = await result_1.Result.fromAsync((0, fetch_1.fetch)(`${constants_1.PRICE_GET_URL}?${(0, querystring_1.stringify)({
country,
ids: filteredIds,
limit: constants_1.PRICE_LIST_LIMIT,
...constants_1.PRICE_GET_OPTIONS
})}`, fetch_1.FetchResultTypes.JSON));
if (response.isErr()) {
throw new utils_1.EshopError('Fetching of eShop prices failed');
}
catch (err) {
if (/(?:PRICE_Rate_Limit)/i.test(err.message)) {
throw new utils_1.EshopError('Looks like you ran into a rate limit while getting price data, please do not spam the Nintendo servers.');
}
if (/(?:PRICE_get_request_failed)/i.test(err.message)) {
throw new utils_1.EshopError('Fetching of eShop prices failed');
}
throw err;
const unwrappedResponse = response.unwrap();
if (unwrappedResponse.prices && unwrappedResponse.prices.length + offset < gameIds.length) {
const accumulatedPrices = prices.concat(unwrappedResponse.prices);
return (0, exports.getPrices)(country, gameIds, offset + constants_1.PRICE_LIST_LIMIT, accumulatedPrices);
}
else if (unwrappedResponse.prices) {
unwrappedResponse.prices = unwrappedResponse.prices.concat(prices);
return unwrappedResponse;
}
return unwrappedResponse;
};
exports.getPrices = getPrices;
//# sourceMappingURL=getPrices.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getShopsByCountryCodes = void 0;
const result_1 = require("@sapphire/result");
const country_data_1 = require("country-data");

@@ -15,34 +16,25 @@ const getPrices_1 = require("./getPrices");

const getShopsByCountryCodes = async (countryCodes, gameCode, region) => {
try {
const countryList = countryCodes.map((code) => country_data_1.countries.all.filter((country) => country.alpha2 === code)[0]);
const shops = [];
for (const country of countryList) {
try {
const response = await (0, getPrices_1.getPrices)(country.alpha2, gameCode);
response.country = country;
shops.push(response);
}
catch (err) {
continue;
}
const countryList = countryCodes.map((code) => country_data_1.countries.all.filter((country) => country.alpha2 === code)[0]);
const shops = [];
for (const country of countryList) {
const response = await result_1.Result.fromAsync((0, getPrices_1.getPrices)(country.alpha2, gameCode));
if (response.isErr()) {
continue;
}
const activeShops = shops.filter((shop) => shop && shop.prices && shop.prices.length && shop.prices[0].regular_price);
const eShops = activeShops.map((shop) => ({
code: shop.country.alpha2,
country: shop.country.name,
currency: shop.prices[0].regular_price.currency,
region
}));
if (!eShops.length)
throw new Error('ACTIVE_SHOPS_Rate_Limit');
return eShops;
const unwrappedResponse = response.unwrap();
unwrappedResponse.country = country;
shops.push(unwrappedResponse);
}
catch (err) {
if (/(?:ACTIVE_SHOPS_Rate_Limit)/i.test(err.message)) {
throw new Error('Looks like you ran into a rate limit while getting price data, please do not spam the Nintendo servers.');
}
throw err;
}
const activeShops = shops.filter((shop) => shop && shop.prices && shop.prices.length && shop.prices[0].regular_price);
const eShops = activeShops.map((shop) => ({
code: shop.country.alpha2,
country: shop.country.name,
currency: shop.prices[0].regular_price.currency,
region
}));
if (!eShops.length)
throw new Error('ACTIVE_SHOPS_Rate_Limit');
return eShops;
};
exports.getShopsByCountryCodes = getShopsByCountryCodes;
//# sourceMappingURL=getShopByCountryCode.js.map
{
"name": "nintendo-switch-eshop",
"version": "7.1.1",
"version": "7.1.2",
"workspaces": [

@@ -35,2 +35,3 @@ "documentation/"

"@sapphire/fetch": "^2.4.1",
"@sapphire/result": "^2.4.0",
"@types/country-data": "^0.0.2",

@@ -43,10 +44,10 @@ "country-data": "^0.0.31",

"@commitlint/config-conventional": "^17.0.3",
"@favware/cliff-jumper": "^1.8.6",
"@sapphire/eslint-config": "^4.3.7",
"@sapphire/prettier-config": "^1.4.3",
"@favware/cliff-jumper": "^1.8.7",
"@sapphire/eslint-config": "^4.3.8",
"@sapphire/prettier-config": "^1.4.4",
"@sapphire/ts-config": "^3.3.4",
"@types/node": "^18.7.5",
"@types/node": "^18.7.8",
"@typescript-eslint/eslint-plugin": "^5.33.1",
"@typescript-eslint/parser": "^5.33.1",
"c8": "^7.12.0",
"@vitest/coverage-c8": "^0.22.1",
"common-tags": "^1.8.2",

@@ -65,3 +66,3 @@ "cz-conventional-changelog": "^3.3.0",

"typescript": "^4.7.4",
"vitest": "^0.21.1"
"vitest": "^0.22.1"
},

@@ -68,0 +69,0 @@ "resolutions": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc