This repository has been archived by the owner on Nov 6, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
repo files have been moved around a lot BREAKING CHANGE: The repo files have been moved around a lot. This probably won't impact you too much, but if you were importing from a specific path (not the root of require('nintendo-switch-eshop')) then you'll have to change your imports.
- Loading branch information
Showing
21 changed files
with
558 additions
and
493 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,22 @@ | ||
export * from './constants'; | ||
export * from './interfaces'; | ||
export * from './nintendo-switch-eshop'; | ||
export { getGamesAmerica as default } from './nintendo-switch-eshop'; | ||
export { getGamesAmerica as default, getGamesAmerica } from './lib/getGames/getGamesAmerica'; | ||
export { getGamesEurope } from './lib/getGames/getGamesEurope'; | ||
export { getGamesJapan } from './lib/getGames/getGamesJapan'; | ||
export { getActiveShops } from './lib/getShops/getActiveShops'; | ||
export { getShopsAmerica } from './lib/getShops/getShopsAmerica'; | ||
export { getShopsAsia } from './lib/getShops/getShopsAsia'; | ||
export { getShopsEurope } from './lib/getShops/getShopsEurope'; | ||
export { getPrices } from './lib/other/getPrices'; | ||
export { getShopsByCountryCodes } from './lib/other/getShopByCountryCode'; | ||
export { parseGameCode } from './lib/other/parseGameCode'; | ||
export { parseNSUID } from './lib/other/parseNSUID'; | ||
export * from './lib/utils/constants'; | ||
export type { | ||
EShop, | ||
EURequestOptions, | ||
GameEU, | ||
GameJP, | ||
GameUS, | ||
PriceResponse, | ||
QueriedGameUS | ||
} from './lib/utils/interfaces'; | ||
export { EshopError } from './lib/utils/utils'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
import fetch from 'node-fetch'; | ||
import { stringify } from 'querystring'; | ||
import { | ||
US_ALGOLIA_HEADERS, | ||
US_AVAILABILITY_FILTER, | ||
US_ESRB_RATINGS_FILTERS, | ||
US_FACETS, | ||
US_GAME_LIST_LIMIT, | ||
US_GET_GAMES_URL, | ||
US_INDEX_TITLE_ASC, | ||
US_INDEX_TITLE_DES, | ||
US_PLATFORM_FACET_FILTER | ||
} from '../utils/constants'; | ||
import type { AlgoliaResponse, GameUS } from '../utils/interfaces'; | ||
import { arrayRemoveDuplicates, EshopError } from '../utils/utils'; | ||
|
||
/** | ||
* Fetches all games on american e-shops | ||
* | ||
* @remarks | ||
* Currently ONLY returns all games in the e-shop | ||
* | ||
* @returns Promise containing all the games | ||
*/ | ||
export const getGamesAmerica = async (): Promise<GameUS[]> => { | ||
const limit = US_GAME_LIST_LIMIT; | ||
const page = 0; | ||
|
||
const body = { | ||
body: JSON.stringify({ | ||
requests: [ | ||
{ | ||
indexName: US_INDEX_TITLE_ASC, | ||
params: stringify({ | ||
query: '', | ||
hitsPerPage: limit, | ||
page: page, | ||
analytics: false, | ||
facets: JSON.stringify(US_FACETS), | ||
facetFilters: `[["${US_ESRB_RATINGS_FILTERS.everyone}"],["${US_PLATFORM_FACET_FILTER}"]]` | ||
}) | ||
}, | ||
{ | ||
indexName: US_INDEX_TITLE_DES, | ||
params: stringify({ | ||
query: '', | ||
hitsPerPage: limit, | ||
page: page, | ||
analytics: false, | ||
facets: JSON.stringify(US_FACETS), | ||
facetFilters: `[["${US_ESRB_RATINGS_FILTERS.everyone}"],["${US_PLATFORM_FACET_FILTER}"]]` | ||
}) | ||
}, | ||
{ | ||
indexName: US_INDEX_TITLE_ASC, | ||
params: stringify({ | ||
query: '', | ||
hitsPerPage: limit, | ||
page: page, | ||
analytics: false, | ||
facets: JSON.stringify(US_FACETS), | ||
facetFilters: `[["${US_ESRB_RATINGS_FILTERS.everyone10}"],["${US_PLATFORM_FACET_FILTER}"]]` | ||
}) | ||
}, | ||
{ | ||
indexName: US_INDEX_TITLE_DES, | ||
params: stringify({ | ||
query: '', | ||
hitsPerPage: limit, | ||
page: page, | ||
analytics: false, | ||
facets: JSON.stringify(US_FACETS), | ||
facetFilters: `[["${US_ESRB_RATINGS_FILTERS.everyone10}"],["${US_PLATFORM_FACET_FILTER}"]]` | ||
}) | ||
}, | ||
{ | ||
indexName: US_INDEX_TITLE_ASC, | ||
params: stringify({ | ||
query: '', | ||
hitsPerPage: limit, | ||
page: page, | ||
analytics: false, | ||
facets: JSON.stringify(US_FACETS), | ||
facetFilters: `[["${US_ESRB_RATINGS_FILTERS.teen}"],["${US_PLATFORM_FACET_FILTER}"]]` | ||
}) | ||
}, | ||
{ | ||
indexName: US_INDEX_TITLE_DES, | ||
params: stringify({ | ||
query: '', | ||
hitsPerPage: limit, | ||
page: page, | ||
analytics: false, | ||
facets: JSON.stringify(US_FACETS), | ||
facetFilters: `[["${US_ESRB_RATINGS_FILTERS.teen}"],["${US_PLATFORM_FACET_FILTER}"]]` | ||
}) | ||
}, | ||
{ | ||
indexName: US_INDEX_TITLE_ASC, | ||
params: stringify({ | ||
query: '', | ||
hitsPerPage: limit, | ||
page: page, | ||
analytics: false, | ||
facets: JSON.stringify(US_FACETS), | ||
facetFilters: `[["${US_ESRB_RATINGS_FILTERS.mature}"],["${US_PLATFORM_FACET_FILTER}"]]` | ||
}) | ||
}, | ||
{ | ||
indexName: US_INDEX_TITLE_ASC, | ||
params: stringify({ | ||
query: '', | ||
hitsPerPage: limit, | ||
page: page, | ||
analytics: false, | ||
facets: JSON.stringify(US_FACETS), | ||
facetFilters: `[["${US_AVAILABILITY_FILTER}"],["${US_PLATFORM_FACET_FILTER}"]]` | ||
}) | ||
} | ||
] | ||
}), | ||
method: 'POST', | ||
headers: US_ALGOLIA_HEADERS | ||
}; | ||
|
||
try { | ||
const allGamesResponse = await fetch(US_GET_GAMES_URL, body); | ||
if (!allGamesResponse.ok) throw new Error('US_games_request_failed'); | ||
const gamesResponse: AlgoliaResponse = await allGamesResponse.json(); | ||
|
||
let allGames: any[] | PromiseLike<GameUS[]> = []; | ||
for (const results of gamesResponse.results) { | ||
allGames = allGames.concat(results.hits); | ||
} | ||
|
||
allGames = arrayRemoveDuplicates(allGames, 'slug'); | ||
return allGames; | ||
} catch (err) { | ||
if (/(?:US_games_request_failed)/i.test(err.toString())) throw new EshopError('Fetching of US Games failed'); | ||
throw err; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import fetch from 'node-fetch'; | ||
import { stringify } from 'querystring'; | ||
import { EU_DEFAULT_LOCALE, EU_GAME_LIST_LIMIT, EU_GET_GAMES_OPTIONS, EU_GET_GAMES_URL } from '../utils/constants'; | ||
import type { EURequestOptions, GameEU } from '../utils/interfaces'; | ||
import { EshopError } from '../utils/utils'; | ||
|
||
/** | ||
* Fetches all games on the European, Australian or New Zealand eShops | ||
* | ||
* @remarks | ||
* Games from Australia / New Zealand can be limited. They are included only as much as that Nintendo assigns them properly to the PAL region | ||
* | ||
* @param options - Request options to pass to the eShop request {@link EURequestOptions | See EURequestOptions for details} | ||
* @returns Promise containing all requested EU/PAL games | ||
*/ | ||
export const getGamesEurope = async ( | ||
options: EURequestOptions = { limit: EU_GAME_LIST_LIMIT, locale: EU_DEFAULT_LOCALE } | ||
): Promise<GameEU[]> => { | ||
if (!options.limit) options.limit = EU_GAME_LIST_LIMIT; | ||
if (!options.locale) options.locale = EU_DEFAULT_LOCALE; | ||
|
||
try { | ||
const gamesEU = await fetch( | ||
`${EU_GET_GAMES_URL.replace('{locale}', options.locale)}?${stringify({ | ||
rows: options.limit, | ||
...EU_GET_GAMES_OPTIONS | ||
})}` | ||
); | ||
|
||
if (!gamesEU.ok) throw new Error('EU_games_request_failed'); | ||
|
||
const gamesData = await gamesEU.json(); | ||
|
||
return gamesData.response.docs as GameEU[]; | ||
} catch (err) { | ||
if (/(?:EU_games_request_failed)/i.test(err.toString())) throw new EshopError('Fetching of EU Games failed'); | ||
throw err; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { parse as xml2json } from 'fast-xml-parser'; | ||
import fetch from 'node-fetch'; | ||
import { JP_GET_GAMES_URL } from '../utils/constants'; | ||
import type { GameJP } from '../utils/interfaces'; | ||
import { EshopError } from '../utils/utils'; | ||
|
||
/** | ||
* Fetches all games on japanese eShops | ||
* | ||
* @returns Promise containing all the games | ||
*/ | ||
export const getGamesJapan = async (): Promise<GameJP[]> => { | ||
try { | ||
const gamesJP = await fetch(JP_GET_GAMES_URL); | ||
|
||
if (!gamesJP.ok) throw new Error('JP_games_request_failed'); | ||
|
||
const parsedGamesJP = xml2json(await gamesJP.text()); | ||
|
||
const allGamesJP: GameJP[] = parsedGamesJP.TitleInfoList.TitleInfo; | ||
|
||
return allGamesJP; | ||
} catch (err) { | ||
if (/(?:JP_games_request_failed)/i.test(err.toString())) throw new EshopError('Fetching of JP Games failed'); | ||
throw err; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import type { EShop } from '../utils/interfaces'; | ||
import { getShopsAmerica } from './getShopsAmerica'; | ||
import { getShopsAsia } from './getShopsAsia'; | ||
import { getShopsEurope } from './getShopsEurope'; | ||
|
||
/** | ||
* Gets all active eShops. | ||
* | ||
* @remarks | ||
* This method will launch several requests at nintendo web services, so don't abuse it. | ||
* | ||
* @returns A list of shop objects with country code, name and default currency. | ||
*/ | ||
export const getActiveShops = async (): Promise<EShop[]> => { | ||
try { | ||
const shopsAmerica = await getShopsAmerica(); | ||
const shopsAsia = await getShopsAsia(); | ||
const shopsEurope = await getShopsEurope(); | ||
|
||
return shopsAmerica.concat(shopsAsia, shopsEurope); | ||
} catch (err) { | ||
throw new Error(err); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { regions } from 'country-data'; | ||
import { getShopsByCountryCodes } from '../other/getShopByCountryCode'; | ||
import { Region, US_GAME_CHECK_CODE } from '../utils/constants'; | ||
import type { EShop } from '../utils/interfaces'; | ||
|
||
/** | ||
* Gets all active eShops on American countries. | ||
* | ||
* @remarks | ||
* This method will launch several requests at nintendo web services, so don't abuse it. | ||
* | ||
* @returns A list of shop objects with country code, name and default currency. | ||
*/ | ||
export const getShopsAmerica = async (): Promise<EShop[]> => { | ||
return getShopsByCountryCodes( | ||
regions.southAmerica.countries.concat(regions.centralAfrica.countries, regions.northernAmerica.countries), | ||
US_GAME_CHECK_CODE, | ||
Region.AMERICAS | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { regions } from 'country-data'; | ||
import { getShopsByCountryCodes } from '../other/getShopByCountryCode'; | ||
import { JP_GAME_CHECK_CODE, Region } from '../utils/constants'; | ||
import type { EShop } from '../utils/interfaces'; | ||
|
||
/** | ||
* Gets all active eShops on Asian countries | ||
* | ||
* @remarks | ||
* This method will launch several requests at nintendo web services, so don't abuse it. | ||
* | ||
* @returns A list of shop objects with country code, name and default currency. | ||
*/ | ||
export const getShopsAsia = async (): Promise<EShop[]> => { | ||
return getShopsByCountryCodes( | ||
regions.southernAsia.countries.concat( | ||
regions.southernAsia.countries, | ||
regions.southeastAsia.countries, | ||
regions.eastAsia.countries, | ||
regions.westernAsia.countries | ||
), | ||
JP_GAME_CHECK_CODE, | ||
Region.ASIA | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { regions } from 'country-data'; | ||
import { getShopsByCountryCodes } from '../other/getShopByCountryCode'; | ||
import { EU_GAME_CHECK_CODE, Region } from '../utils/constants'; | ||
import type { EShop } from '../utils/interfaces'; | ||
|
||
/** | ||
* Gets all active eShops on European countries. | ||
* | ||
* @remarks | ||
* This method will launch several requests at nintendo web services, so don't abuse it. | ||
* | ||
* @returns A list of shop objects with country code, name and default currency. | ||
*/ | ||
export const getShopsEurope = async (): Promise<EShop[]> => { | ||
return getShopsByCountryCodes( | ||
regions.northernEurope.countries.concat( | ||
regions.southernEurope.countries, | ||
regions.easternEurope.countries, | ||
regions.westernEurope.countries, | ||
regions.australia.countries, | ||
regions.southernAfrica.countries | ||
), | ||
EU_GAME_CHECK_CODE, | ||
Region.EUROPE | ||
); | ||
}; |
Oops, something went wrong.