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.2 to 7.1.3

dist/index.mjs.map

15

CHANGELOG.md

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

# [7.1.3](https://github.com/favna/nintendo-switch-eshop/compare/v7.1.2...v7.1.3) - (2023-04-13)
## 🏠 Refactor
- Use named functions for exported functions ([8ca9ba8](https://github.com/favna/nintendo-switch-eshop/commit/8ca9ba83eec51f901129f2ee02ed7e92983b5f13))
## 🐛 Bug Fixes
- Throw an error when `parseGameCode` is called for American games ([f36900d](https://github.com/favna/nintendo-switch-eshop/commit/f36900dad8da52c7d740bcba725fbb61f9b04f76))
- Update build stack (#13) ([12816d1](https://github.com/favna/nintendo-switch-eshop/commit/12816d10e7d7e1e842f01ccdad804f7550a75016))
## 📝 Documentation
- **readme:** Update contributing ([1d02690](https://github.com/favna/nintendo-switch-eshop/commit/1d0269014ec6a850376db7ae05a3a0a64ec6378b))
# [7.1.2](https://github.com/favna/nintendo-switch-eshop/compare/v7.1.1...v7.1.2) - (2022-08-21)

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

633

dist/index.d.ts

@@ -1,18 +0,615 @@

export { getGamesAmerica as default, getGamesAmerica } from './lib/getGames/getGamesAmerica';
export { getGamesBrazil } from './lib/getGames/getGamesBrazil';
export { getGamesEurope } from './lib/getGames/getGamesEurope';
export { getGamesJapan } from './lib/getGames/getGamesJapan';
export { getQueriedGamesAmerica } from './lib/getGames/getQueriedGamesAmerica';
export { getQueriedGamesBrazil } from './lib/getGames/getQueriedGamesBrazil';
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 { BR_ALGOLIA_HEADERS, BR_ALGOLIA_ID, BR_ALGOLIA_KEY, BR_GET_GAMES_URL, EU_GET_GAMES_URL, JP_GET_GAMES_URL, PRICE_GET_URL, QUERIED_BR_ALGOLIA_KEY, QUERIED_BR_GET_GAMES_URL, QUERIED_US_ALGOLIA_KEY_NEW, QUERIED_US_ALGOLIA_KEY_OLD, QUERIED_US_GET_GAMES_URL_NEW, QUERIED_US_GET_GAMES_URL_OLD, Region, US_ALGOLIA_HEADERS, US_ALGOLIA_ID, US_ALGOLIA_KEY, US_GET_GAMES_URL } from './lib/utils/constants';
export type { EShop, EURequestOptions, GameEU, GameJP, GameUS, HighlightResult, Nsuid, PriceResponse, QueriedGameResult, QueriedGamesAmericaOptions, QueriedGameUS, TitleData } from './lib/utils/interfaces';
export { EshopError } from './lib/utils/utils';
//# sourceMappingURL=index.d.ts.map
import { Country } from 'country-data';
/** Algolia ID for getting US games */
declare const US_ALGOLIA_ID = "U3B6GR4UA3";
/** Algolia Key for getting US games */
declare const US_ALGOLIA_KEY = "c4da8be7fd29f0f5bfa42920b0a99dc7";
/** Algolia key for getting US games with a query */
declare const QUERIED_US_ALGOLIA_KEY_NEW = "a29c6927638bfd8cee23993e51e721c9";
/** Algolia key for getting US games with a query */
declare const QUERIED_US_ALGOLIA_KEY_OLD = "6efbfb0f8f80defc44895018caf77504";
/** URL for getting US Games */
declare const US_GET_GAMES_URL: string;
/** New URL for getting Queried US Games */
declare const QUERIED_US_GET_GAMES_URL_NEW: string;
/** Old URL for getting Queried US games, this still exists and has additional properties which get merged with those from the new URL */
declare const QUERIED_US_GET_GAMES_URL_OLD: string;
/** @internal Request headers for US games */
declare const US_ALGOLIA_HEADERS: {
'Content-Type': string;
'X-Algolia-API-Key': string;
'X-Algolia-Application-Id': string;
};
/** URL for getting EU Games */
declare const EU_GET_GAMES_URL = "http://search.nintendo-europe.com/{locale}/select";
/** URL for getting JP Games */
declare const JP_GET_GAMES_URL = "https://www.nintendo.co.jp/data/software/xml/switch.xml";
/** Algolia ID for getting BR games */
declare const BR_ALGOLIA_ID = "U3B6GR4UA3";
/** Algolia Key for getting US games */
declare const BR_ALGOLIA_KEY = "c4da8be7fd29f0f5bfa42920b0a99dc7";
/** Algolia key for getting BR games with a query */
declare const QUERIED_BR_ALGOLIA_KEY = "c4da8be7fd29f0f5bfa42920b0a99dc7";
/** URL for getting BR Games */
declare const BR_GET_GAMES_URL: string;
/** URL for getting Queried BR Games */
declare const QUERIED_BR_GET_GAMES_URL: string;
/** @internal Request headers for BR games */
declare const BR_ALGOLIA_HEADERS: {
'Content-Type': string;
'X-Algolia-API-Key': string;
'X-Algolia-Application-Id': string;
};
/** URL for getting game prices */
declare const PRICE_GET_URL = "https://api.ec.nintendo.com/v1/price";
/**
* Predefined options for the unit system
*/
declare const enum Region {
AMERICAS = 1,
EUROPE = 2,
ASIA = 3
}
interface GameEU {
_version_: number;
add_on_content_b: boolean;
age_rating_sorting_i: number;
age_rating_type: string;
age_rating_value: string;
change_date: Date;
cloud_saves_b: boolean;
club_nintendo: boolean;
compatible_controller: string[];
copyright_s: string;
date_from: Date;
dates_released_dts: Date[];
deprioritise_b: boolean;
developer: string;
digital_version_b: boolean;
eshop_removed_b: boolean;
excerpt: string;
fs_id: string;
game_categories_txt: string[];
game_category: string[];
game_series_t: string;
gift_finder_carousel_image_url_s: string;
gift_finder_description_s: string;
gift_finder_detail_page_image_url_s: string;
gift_finder_detail_page_store_link_s: string;
gift_finder_wishlist_image_url_s: string;
hits_i: number;
image_url: string;
image_url_h2x1_s: string;
image_url_sq_s: string;
image_url_tm_s: string;
language_availability: string[];
near_field_comm_b: boolean;
/** Array containing the 14-digit game unique identifier */
nsuid_txt: string[];
originally_for_t: string;
pg_s: string;
physical_version_b: boolean;
play_mode_handheld_mode_b: boolean;
play_mode_tabletop_mode_b: boolean;
play_mode_tv_mode_b: boolean;
playable_on_txt: string[];
players_from: number;
players_to: number;
popularity: number;
pretty_agerating_s: string;
pretty_date_s: string;
pretty_game_categories_txt: string[];
price_discount_percentage_f: number;
price_has_discount_b: boolean;
price_lowest_f: number;
price_regular_f: number;
price_sorting_f: number;
priority: Date;
product_catalog_description_s: string;
product_code_ss: string[];
/** Array containing the product code */
product_code_txt: string[];
publisher: string;
sorting_title: string;
switch_game_voucher_b: boolean;
system_names_txt: string[];
system_type: string[];
title: string;
title_extras_txt: string[];
type: string;
/** the url path of the game on the eShop website - does not include domain **/
url: string;
wishlist_email_banner460w_image_url_s: string;
wishlist_email_banner640w_image_url_s: string;
wishlist_email_square_image_url_s: string;
}
/** Additional options for the [[getQueriedGamesAmerica]] method */
interface QueriedGamesAmericaOptions {
/**
* The amount of hits to be received per page
* @minimum 0
* @maximum 200
* @default 200
*/
hitsPerPage?: number;
/**
* The page number to get
* @minimum 0
* @default 0
*/
page?: number;
}
interface QueriedGameResult {
/** Whether the amount of hits is exhaustive or not */
exhaustiveNbHits: true;
/** The hits for this query */
hits: QueriedGameUS[];
/** The amount of hits per page */
hitsPerPage: number;
/** The amount of hits */
nbHits: number;
/** The amount of pages available */
nbPages: number;
/** The page that the result is on */
page: number;
/** The params that were used */
params: string;
/** The amount of time it took the {@link https://www.nintendo.com nintendo.com} API to process this request */
processingTimeMS: number;
/** The query that was used */
query: string;
}
interface QueriedGameUS {
/** Additional information returned by the API, it doesn't really serve any purpose but documenting it anyway because it's there. */
_distinctSeqID: number;
/** Additional information returned by the API, it doesn't really serve any purpose but documenting it anyway because it's there. */
_highlightResult: HighlightResult;
/** Whether this game is available or not */
availability: string[];
/** The box art of the game, if any. Generally undefined for games that are yet to release. */
boxart?: string;
classindDescriptors?: unknown | null;
classindRating?: unknown | null;
collectionPriceRange: string;
contentRatingCode: string;
corePlatforms: string[];
createdAt: Date;
demoNsuid: string | null;
depth?: number;
/** A description about this game */
description: string;
/** A list of companies that developed this game */
developers: string[];
/** A list of {@link https://www.esrb.org/ratings-guide/ ESRB descriptors} */
esrbDescriptors: string[];
/** The {@link https://www.esrb.org/ratings-guide/ ESRB Rating} */
esrbRating: string;
exclusive: boolean;
/** Whether this game is featured on the {@link https://www.nintendo.com nintendo.com} homepage */
featured: boolean;
/** Whether this game is featured on the {@link https://www.nintendo.com nintendo.com} homepage */
featuredProduct: boolean;
/** The franchises this game is a part of */
franchises: string;
/** Whether this game is free to start */
freeToStart: boolean;
/** A list of general filters that could potentially be searched on {@link https://www.nintendo.com nintendo.com} to find this game with */
generalFilters: string[];
/** A list of genres this game */
genres: string[];
/** Whether this game has downloadable content or not */
hasDlc: boolean;
/** A large wide image such as a screenshot or artwork of the game, if any. */
headerImage?: string;
/** The asset slug of a large wide image such as a screenshot or artwork of the game, if any. */
horizontalHeaderImage?: string;
/** A list of methods through which the game can be acquired, such as retail or digital download. */
howToShop: string[];
/** A Unix timestamp in **milliseconds** indicating when the information on this game was last modified */
lastModified: number;
/** The lowest price at which this game was ever sold */
lowestPrice: number;
/** The {@link https://en.wikipedia.org/wiki/List_price manufacturer's suggested retail price} for this game */
msrp: number;
/** Features that added to this game when the player has a Nintendo Switch Online subscription */
nsoFeatures: string[];
/** The unique ID for this game. */
nsuid: string;
/** The amount of players that can simultaneously play this game */
numOfPlayers: string;
/** A unique {@link https://en.wikipedia.org/wiki/Universally_unique_identifier GUID} that represents this game's entry in the Nintendo API. */
objectID: string;
/** The platform this game released on */
platform: string;
/**
* A unique identifier of the platform the game was released on
* @example 'NINTENDO_SWITCH'
*/
platformCode: string;
platinumPoints?: any;
/**
* The amount of players that can simultaniously play this game
* @example 'Single Player'
*/
playerCount: string;
/** A list of player filters that could potentially be searched on {@link https://www.nintendo.com nintendo.com} to find this game with */
playerFilters: string[];
/**
* An array of ways this game can be played
* @example ['TV mode', 'Tabletop mode', 'Handheld mode']
*/
playModes: string[];
/** The price information for this game */
price: {
/** The regular price for this game */
regPrice: number;
/**
* The final price for this game,
* which is {@link QueriedGameUS.price.salePrice} if the game is on sale or {@link QueriedGameUS.price.regPrice} if it is not.
*/
finalPrice: number;
/**
* The sale price for this game, or `null` if the game has never been on sale.
*/
salePrice: number | null;
};
/** A category price range that this game falls under. Can be used on {@link https://www.nintendo.com nintendo.com} to find this game with */
priceRange: string;
priority?: number;
/** The slug to a product image of this game */
productImage: string;
/** The date this game was published */
publishDate?: Date;
/** A list of companies that published this game */
publishers: string[];
/**
* A display of the release of this game. Can be either an ISO timestamp or some other representation of date.
* @remark Nintendo has a tendency to also have entries such as `Early 2022` or `Late 2021` here. Normally these kinds of dates would not be parsed by JavaScript, but NodeJS does parse these natural input types.
*/
releaseDateDisplay: string;
/** The price of this game if and when it is on sale */
salePrice: number | null;
/** the SKU ID for this game */
sku: string;
/** A unique {@link https://en.wikipedia.org/wiki/Clean_URL#Slug slug} for this game */
slug: string;
/**
* The SMEC ({@link https://en.wikipedia.org/wiki/Video_game_content_rating_system#Mexico Sistema Mexicano de Equivalencias de Clasificación})
* descriptors for this game
*/
smecDescriptors: string[];
/**
* The SMEC ({@link https://en.wikipedia.org/wiki/Video_game_content_rating_system#Mexico Sistema Mexicano de Equivalencias de Clasificación})
* rating for this game
*/
smecRating: string;
/**
* The developer of this game
*/
softwareDeveloper: string;
/**
* The publisher of this game
*/
softwarePublisher: string;
/** The title of this game */
title: string;
/**
* The top level category of this game
* @example 'Games'
*/
topLevelCategory: string;
/**
* The top level category code of this game
* @example 'GAMES'
*/
topLevelCategoryCode: string;
/** The top level filters for this game */
topLevelFilters: string[];
/**
* The type of search result
* @example 'game'
*/
type: string;
/**
* An ISO timestamp of when this game was last updated
*/
updatedAt: string;
/** A unique to the information about this game. Prefix it with `https://www.nintendo.com` to have a valid URL. */
url: string;
/**
* The key segment of the {@link QueriedGameUS.url}, often the last segment of the URL
*/
urlKey: string;
/** Whether this game is visible when searching for it on https://www.nintendo.com */
visibleInSearch: boolean;
}
interface HighlightResult {
nsuid: Nsuid;
publishers: Nsuid[];
title: Nsuid;
}
interface Nsuid {
fullyHighlighted?: boolean;
matchedWords: string[];
matchLevel: string;
value: string;
}
interface GameUS {
/** Identifiers about the availability of this game. */
availability: string[];
/** The boxart of this title, if this is an eShop game then it is the homescreen icon */
boxart: string;
/** A longer description about this title */
description: string;
/** The studios that developed this gamme */
developers: string[];
/** An array of ESRB descriptions such as `"Alcohol Reference"` and `"Violence"` */
esrbDescriptors: string[];
/** The {@linkplain https://www.esrb.org ESRB} rating this game was given */
esrbRating: string;
/** Whether this game is featured on {@linkplain https://nintendo.com}'s homepage */
featured: boolean;
/** The franches this game is part of */
franchises: string[];
/** Whether this game is free to start and only needs payment later */
freeToStart: boolean;
/** Qualifiers that could be used to find this game when applying filters on {@linkplain https://nintendo.com} */
generalFilters: string[];
/** The genres this this game is part of */
genres: string[];
/** A larger header image */
horizontalHeaderImage: string;
/** A list of ways this game can be purchased */
howToShop: string[];
/** Unix timestamp when this entry was last edited on the API */
lastModified: number;
/** The lowest price this game was ever available for. */
lowestPrice: number;
/** The {@linkplain https://en.wikipedia.org/wiki/List_price Manufacturer's Suggested Retail Price} for this game (in United States Dollars). */
msrp: number;
/** 14-digit game unique identifier */
nsuid: string;
/** The amount of players this game supports. This is a string because Nintendo is more verbose than just a number. */
numOfPlayers: string;
/** The internal ID that Nintendo has assigned to this game in their API. This doesn't really serve any use. */
objectID: string;
/** The platform on which this game was released */
platform: string;
/** Qualifiers that could be used to find this game when applying player filters on {@linkplain https://nintendo.com} */
playerFilters: string[];
/** The predefined price range in which this game falls, can be used when applying filters on {@linkplain https://nintendo.com} */
priceRange: string;
/** The studios that published this game */
publishers: string[];
/** The date this game was released in the {@linkplain https://en.wikipedia.org/wiki/ISO_8601 ISO 8601 Extended Format} */
releaseDateDisplay: string;
/** The price for this game when it is on sale. This is `null` when the game is _not_ on sale. */
salePrice: number | null;
/** Game URL name */
slug: string;
/** The title of the game */
title: string;
/** The URL to the game on {@linkplain https://nintendo.com}. Prepend `https://nintend.com` to this URL to get a fully qualified URL to the game. */
url: string;
}
interface GameJP extends Record<string, string | number | undefined> {
ComingThumb: 'yes' | string;
D: number;
Hard: string;
/** The game code for the game */
InitialCode: string;
/** The Link Target, if it exists */
LinkTarget: string;
/** The game url */
LinkURL: string;
MakerKana: string;
MakerName: string;
Memo: string;
PlatformID: string;
Price: string;
SalesDate: string;
/** The type of screenshot, if it exists */
ScreenshotImgFlg: number;
/** The screenshot URL, if it exists */
ScreenshotImgURL: string;
SoftType: string;
/** The variation of the thumbnail */
ThumbVariation: string;
/** The game's title */
TitleName: string;
/** The title name in Asian characters */
TitleNameRuby: string;
}
interface EShop {
code: string;
country: string;
currency: string;
region: Region;
}
interface PriceResponse {
country: Country;
error: PriceError;
personalized: boolean;
prices: TitleData[];
}
interface TitleData {
discount_price?: PriceData;
regular_price: PriceData;
sales_status: string;
title_id: number;
}
/** @internal */
interface PriceError {
code: string;
message: string;
}
/** @internal */
interface PriceData {
amount: string;
currency: string;
end_datetime?: string;
raw_value: string;
start_datetime?: string;
}
/** @internal */
interface RequestOptions {
/**
* Game count limit (Can only be lower than default page size).
*
* @remarks
* On the US eshop, the max limit is 100. Leave empty to get all the games. */
limit?: number;
}
interface EURequestOptions extends RequestOptions {
/** Game information locale. (EU Only) */
locale?: string;
}
/**
* Fetches all games on american e-shops
*
* @remarks
* Currently ONLY returns all games in the e-shop
*
* @returns Promise containing all the games
*/
declare function getGamesAmerica(): Promise<GameUS[]>;
/**
* Fetches all games on brazilian e-shop
*
* @remarks
* Currently ONLY returns all games in the e-shop
*
* @returns Promise containing all the games
*/
declare function getGamesBrazil(): Promise<GameUS[]>;
/**
* 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
*/
declare function getGamesEurope(options?: EURequestOptions): Promise<GameEU[]>;
/**
* Fetches all games on japanese eShops
*
* @returns Promise containing all the games
*/
declare function getGamesJapan(): Promise<GameJP[]>;
/**
* Fetches a subset of games from the American e-shops as based on a given query
* @param query The query to search for
* @param __namedParameters Additional options for the [[getQueriedGamesAmerica]] call. Defaults to `{ hitsPerPage: 200, page: 0 }`
* @returns Promise containing the first `hitsPerPage` games that match your query
* @license Apache-2.0 Jeroen Claassens & Aura Román
* @copyright 2021
*/
declare function getQueriedGamesAmerica(query: string, { hitsPerPage, page }?: QueriedGamesAmericaOptions): Promise<QueriedGameUS[]>;
/**
* Fetches a subset of games from the Brazilian e-shop as based on a given query
* @param query The query to search for
* @param __namedParameters Additional options for the [[getQueriedGamesBrazil]] call. Defaults to `{ hitsPerPage: 200, page: 0 }`
* @returns Promise containing the first `hitsPerPage` games that match your query
* @license Apache-2.0 Jeroen Claassens & Aura Román
* @copyright 2021
*/
declare function getQueriedGamesBrazil(query: string, { hitsPerPage, page }?: QueriedGamesAmericaOptions): Promise<QueriedGameUS[]>;
/**
* 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.
*/
declare function getActiveShops(): Promise<EShop[]>;
/**
* 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.
*/
declare function getShopsAmerica(): Promise<EShop[]>;
/**
* 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.
*/
declare function getShopsAsia(): Promise<EShop[]>;
/**
* 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.
*/
declare function getShopsEurope(): Promise<EShop[]>;
/**
* Gets pricing information for the requested games. Paginates every 50 games.
*
* @param country A two digit country code. (ISO 3166-1 alpha-2 country code)
* @param gameIds One or more NSUID of the corresponding games.
* @param offset _(Optional)_ The offset to start at
* @param prices _(Optional)_ An array of {@link TitleData}
* @returns A promise containing the pricing information.
*/
declare function getPrices(country: string, gameIds: string[] | string, offset?: number, prices?: TitleData[]): Promise<PriceResponse>;
/**
* Gets all active eShops given a list of countries.
*
* @param countryCodes A list of 2 digit country codes for every country eShop to lookup. (ISO 3166-1 alpha-2 country codes)
* @param gameCode A 14 digits game NSUID from the desired region.
* @param region A region id that will be appended in the final shop object for filtering purposes.
* @returns A list of shop objects with country code, name and default currency.
*/
declare function getShopsByCountryCodes(countryCodes: string[], gameCode: string, region: Region): Promise<EShop[]>;
/**
* Parses the game code to extract the cross-region portion.
*
* @param game The game object returned from one of the other methods.
* @param region Region code
* @returns The 4-digit resulting game code
*/
declare function parseGameCode(game: GameUS | GameEU | GameJP, region: Region): string | null;
/**
* Extracts NSUID information from the game object.
*
* @param game The game object returned from one of the other methods.
* @param region Region code
* @returns The 14-digits NSUID
*/
declare function parseNSUID(game: GameUS | GameEU | GameJP, region: Region): string | null;
/** Class representing an error in the nintendo-switch-eshop library */
declare class EshopError extends Error {
/**
* Create an EshopError
* @param message The message the error should show
*/
constructor(message: string);
}
export { BR_ALGOLIA_HEADERS, BR_ALGOLIA_ID, BR_ALGOLIA_KEY, BR_GET_GAMES_URL, EShop, EURequestOptions, EU_GET_GAMES_URL, EshopError, GameEU, GameJP, GameUS, HighlightResult, JP_GET_GAMES_URL, Nsuid, PRICE_GET_URL, PriceResponse, QUERIED_BR_ALGOLIA_KEY, QUERIED_BR_GET_GAMES_URL, QUERIED_US_ALGOLIA_KEY_NEW, QUERIED_US_ALGOLIA_KEY_OLD, QUERIED_US_GET_GAMES_URL_NEW, QUERIED_US_GET_GAMES_URL_OLD, QueriedGameResult, QueriedGameUS, QueriedGamesAmericaOptions, Region, TitleData, US_ALGOLIA_HEADERS, US_ALGOLIA_ID, US_ALGOLIA_KEY, US_GET_GAMES_URL, getGamesAmerica as default, getActiveShops, getGamesAmerica, getGamesBrazil, getGamesEurope, getGamesJapan, getPrices, getQueriedGamesAmerica, getQueriedGamesBrazil, getShopsAmerica, getShopsAsia, getShopsByCountryCodes, getShopsEurope, parseGameCode, parseNSUID };
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.EshopError = exports.US_GET_GAMES_URL = exports.US_ALGOLIA_KEY = exports.US_ALGOLIA_ID = exports.US_ALGOLIA_HEADERS = exports.Region = exports.QUERIED_US_GET_GAMES_URL_OLD = exports.QUERIED_US_GET_GAMES_URL_NEW = exports.QUERIED_US_ALGOLIA_KEY_OLD = exports.QUERIED_US_ALGOLIA_KEY_NEW = exports.QUERIED_BR_GET_GAMES_URL = exports.QUERIED_BR_ALGOLIA_KEY = exports.PRICE_GET_URL = exports.JP_GET_GAMES_URL = exports.EU_GET_GAMES_URL = exports.BR_GET_GAMES_URL = exports.BR_ALGOLIA_KEY = exports.BR_ALGOLIA_ID = exports.BR_ALGOLIA_HEADERS = exports.parseNSUID = exports.parseGameCode = exports.getShopsByCountryCodes = exports.getPrices = exports.getShopsEurope = exports.getShopsAsia = exports.getShopsAmerica = exports.getActiveShops = exports.getQueriedGamesBrazil = exports.getQueriedGamesAmerica = exports.getGamesJapan = exports.getGamesEurope = exports.getGamesBrazil = exports.getGamesAmerica = exports.default = void 0;
var getGamesAmerica_1 = require("./lib/getGames/getGamesAmerica");
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return getGamesAmerica_1.getGamesAmerica; } });
Object.defineProperty(exports, "getGamesAmerica", { enumerable: true, get: function () { return getGamesAmerica_1.getGamesAmerica; } });
var getGamesBrazil_1 = require("./lib/getGames/getGamesBrazil");
Object.defineProperty(exports, "getGamesBrazil", { enumerable: true, get: function () { return getGamesBrazil_1.getGamesBrazil; } });
var getGamesEurope_1 = require("./lib/getGames/getGamesEurope");
Object.defineProperty(exports, "getGamesEurope", { enumerable: true, get: function () { return getGamesEurope_1.getGamesEurope; } });
var getGamesJapan_1 = require("./lib/getGames/getGamesJapan");
Object.defineProperty(exports, "getGamesJapan", { enumerable: true, get: function () { return getGamesJapan_1.getGamesJapan; } });
var getQueriedGamesAmerica_1 = require("./lib/getGames/getQueriedGamesAmerica");
Object.defineProperty(exports, "getQueriedGamesAmerica", { enumerable: true, get: function () { return getQueriedGamesAmerica_1.getQueriedGamesAmerica; } });
var getQueriedGamesBrazil_1 = require("./lib/getGames/getQueriedGamesBrazil");
Object.defineProperty(exports, "getQueriedGamesBrazil", { enumerable: true, get: function () { return getQueriedGamesBrazil_1.getQueriedGamesBrazil; } });
var getActiveShops_1 = require("./lib/getShops/getActiveShops");
Object.defineProperty(exports, "getActiveShops", { enumerable: true, get: function () { return getActiveShops_1.getActiveShops; } });
var getShopsAmerica_1 = require("./lib/getShops/getShopsAmerica");
Object.defineProperty(exports, "getShopsAmerica", { enumerable: true, get: function () { return getShopsAmerica_1.getShopsAmerica; } });
var getShopsAsia_1 = require("./lib/getShops/getShopsAsia");
Object.defineProperty(exports, "getShopsAsia", { enumerable: true, get: function () { return getShopsAsia_1.getShopsAsia; } });
var getShopsEurope_1 = require("./lib/getShops/getShopsEurope");
Object.defineProperty(exports, "getShopsEurope", { enumerable: true, get: function () { return getShopsEurope_1.getShopsEurope; } });
var getPrices_1 = require("./lib/other/getPrices");
Object.defineProperty(exports, "getPrices", { enumerable: true, get: function () { return getPrices_1.getPrices; } });
var getShopByCountryCode_1 = require("./lib/other/getShopByCountryCode");
Object.defineProperty(exports, "getShopsByCountryCodes", { enumerable: true, get: function () { return getShopByCountryCode_1.getShopsByCountryCodes; } });
var parseGameCode_1 = require("./lib/other/parseGameCode");
Object.defineProperty(exports, "parseGameCode", { enumerable: true, get: function () { return parseGameCode_1.parseGameCode; } });
var parseNSUID_1 = require("./lib/other/parseNSUID");
Object.defineProperty(exports, "parseNSUID", { enumerable: true, get: function () { return parseNSUID_1.parseNSUID; } });
var constants_1 = require("./lib/utils/constants");
Object.defineProperty(exports, "BR_ALGOLIA_HEADERS", { enumerable: true, get: function () { return constants_1.BR_ALGOLIA_HEADERS; } });
Object.defineProperty(exports, "BR_ALGOLIA_ID", { enumerable: true, get: function () { return constants_1.BR_ALGOLIA_ID; } });
Object.defineProperty(exports, "BR_ALGOLIA_KEY", { enumerable: true, get: function () { return constants_1.BR_ALGOLIA_KEY; } });
Object.defineProperty(exports, "BR_GET_GAMES_URL", { enumerable: true, get: function () { return constants_1.BR_GET_GAMES_URL; } });
Object.defineProperty(exports, "EU_GET_GAMES_URL", { enumerable: true, get: function () { return constants_1.EU_GET_GAMES_URL; } });
Object.defineProperty(exports, "JP_GET_GAMES_URL", { enumerable: true, get: function () { return constants_1.JP_GET_GAMES_URL; } });
Object.defineProperty(exports, "PRICE_GET_URL", { enumerable: true, get: function () { return constants_1.PRICE_GET_URL; } });
Object.defineProperty(exports, "QUERIED_BR_ALGOLIA_KEY", { enumerable: true, get: function () { return constants_1.QUERIED_BR_ALGOLIA_KEY; } });
Object.defineProperty(exports, "QUERIED_BR_GET_GAMES_URL", { enumerable: true, get: function () { return constants_1.QUERIED_BR_GET_GAMES_URL; } });
Object.defineProperty(exports, "QUERIED_US_ALGOLIA_KEY_NEW", { enumerable: true, get: function () { return constants_1.QUERIED_US_ALGOLIA_KEY_NEW; } });
Object.defineProperty(exports, "QUERIED_US_ALGOLIA_KEY_OLD", { enumerable: true, get: function () { return constants_1.QUERIED_US_ALGOLIA_KEY_OLD; } });
Object.defineProperty(exports, "QUERIED_US_GET_GAMES_URL_NEW", { enumerable: true, get: function () { return constants_1.QUERIED_US_GET_GAMES_URL_NEW; } });
Object.defineProperty(exports, "QUERIED_US_GET_GAMES_URL_OLD", { enumerable: true, get: function () { return constants_1.QUERIED_US_GET_GAMES_URL_OLD; } });
Object.defineProperty(exports, "Region", { enumerable: true, get: function () { return constants_1.Region; } });
Object.defineProperty(exports, "US_ALGOLIA_HEADERS", { enumerable: true, get: function () { return constants_1.US_ALGOLIA_HEADERS; } });
Object.defineProperty(exports, "US_ALGOLIA_ID", { enumerable: true, get: function () { return constants_1.US_ALGOLIA_ID; } });
Object.defineProperty(exports, "US_ALGOLIA_KEY", { enumerable: true, get: function () { return constants_1.US_ALGOLIA_KEY; } });
Object.defineProperty(exports, "US_GET_GAMES_URL", { enumerable: true, get: function () { return constants_1.US_GET_GAMES_URL; } });
var utils_1 = require("./lib/utils/utils");
Object.defineProperty(exports, "EshopError", { enumerable: true, get: function () { return utils_1.EshopError; } });
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/index.ts
var src_exports = {};
__export(src_exports, {
BR_ALGOLIA_HEADERS: () => BR_ALGOLIA_HEADERS,
BR_ALGOLIA_ID: () => BR_ALGOLIA_ID,
BR_ALGOLIA_KEY: () => BR_ALGOLIA_KEY,
BR_GET_GAMES_URL: () => BR_GET_GAMES_URL,
EU_GET_GAMES_URL: () => EU_GET_GAMES_URL,
EshopError: () => EshopError,
JP_GET_GAMES_URL: () => JP_GET_GAMES_URL,
PRICE_GET_URL: () => PRICE_GET_URL,
QUERIED_BR_ALGOLIA_KEY: () => QUERIED_BR_ALGOLIA_KEY,
QUERIED_BR_GET_GAMES_URL: () => QUERIED_BR_GET_GAMES_URL,
QUERIED_US_ALGOLIA_KEY_NEW: () => QUERIED_US_ALGOLIA_KEY_NEW,
QUERIED_US_ALGOLIA_KEY_OLD: () => QUERIED_US_ALGOLIA_KEY_OLD,
QUERIED_US_GET_GAMES_URL_NEW: () => QUERIED_US_GET_GAMES_URL_NEW,
QUERIED_US_GET_GAMES_URL_OLD: () => QUERIED_US_GET_GAMES_URL_OLD,
Region: () => Region,
US_ALGOLIA_HEADERS: () => US_ALGOLIA_HEADERS,
US_ALGOLIA_ID: () => US_ALGOLIA_ID,
US_ALGOLIA_KEY: () => US_ALGOLIA_KEY,
US_GET_GAMES_URL: () => US_GET_GAMES_URL,
default: () => getGamesAmerica,
getActiveShops: () => getActiveShops,
getGamesAmerica: () => getGamesAmerica,
getGamesBrazil: () => getGamesBrazil,
getGamesEurope: () => getGamesEurope,
getGamesJapan: () => getGamesJapan,
getPrices: () => getPrices,
getQueriedGamesAmerica: () => getQueriedGamesAmerica,
getQueriedGamesBrazil: () => getQueriedGamesBrazil,
getShopsAmerica: () => getShopsAmerica,
getShopsAsia: () => getShopsAsia,
getShopsByCountryCodes: () => getShopsByCountryCodes,
getShopsEurope: () => getShopsEurope,
parseGameCode: () => parseGameCode,
parseNSUID: () => parseNSUID
});
module.exports = __toCommonJS(src_exports);
// src/lib/getGames/getGamesAmerica.ts
var import_fetch = require("@sapphire/fetch");
var import_result = require("@sapphire/result");
var import_querystring = require("querystring");
// src/lib/utils/constants.ts
var US_ALGOLIA_ID = "U3B6GR4UA3";
var US_ALGOLIA_KEY = "c4da8be7fd29f0f5bfa42920b0a99dc7";
var QUERIED_US_ALGOLIA_KEY_NEW = "a29c6927638bfd8cee23993e51e721c9";
var QUERIED_US_ALGOLIA_KEY_OLD = "6efbfb0f8f80defc44895018caf77504";
var US_GET_GAMES_URL = `https://${US_ALGOLIA_ID}-dsn.algolia.net/1/indexes/*/queries`;
var QUERIED_US_GET_GAMES_URL_NEW = `https://${US_ALGOLIA_ID}-dsn.algolia.net/1/indexes/store_all_products_en_us/query`;
var QUERIED_US_GET_GAMES_URL_OLD = `https://${US_ALGOLIA_ID}-dsn.algolia.net/1/indexes/ncom_game_en_us/query`;
var US_GAME_CHECK_CODE = "70010000000185";
var US_ALGOLIA_HEADERS = {
"Content-Type": "application/json",
"X-Algolia-API-Key": US_ALGOLIA_KEY,
"X-Algolia-Application-Id": US_ALGOLIA_ID
};
var EU_GET_GAMES_OPTIONS = {
fq: "type:GAME AND system_type:nintendoswitch* AND product_code_txt:*",
q: "*",
sort: "sorting_title asc",
start: "0",
wt: "json"
};
var EU_GET_GAMES_URL = "http://search.nintendo-europe.com/{locale}/select";
var EU_GAME_CHECK_CODE = "70010000000184";
var EU_GAME_CODE_REGEX = /HAC\w(\w{4})/;
var EU_DEFAULT_LOCALE = "en";
var EU_GAME_LIST_LIMIT = 9999;
var JP_GET_GAMES_URL = "https://www.nintendo.co.jp/data/software/xml/switch.xml";
var JP_GAME_CHECK_CODE = "70010000000039";
var JP_GAME_CODE_REGEX = /HAC(\w{4})/;
var JP_NSUID_REGEX = /\d{14}/;
var BR_ALGOLIA_ID = "U3B6GR4UA3";
var BR_ALGOLIA_KEY = "c4da8be7fd29f0f5bfa42920b0a99dc7";
var QUERIED_BR_ALGOLIA_KEY = "c4da8be7fd29f0f5bfa42920b0a99dc7";
var BR_GET_GAMES_URL = `https://${BR_ALGOLIA_ID}-dsn.algolia.net/1/indexes/*/queries`;
var QUERIED_BR_GET_GAMES_URL = `https://${BR_ALGOLIA_ID}-dsn.algolia.net/1/indexes/ncom_game_pt_br/query`;
var BR_ALGOLIA_HEADERS = {
"Content-Type": "application/json",
"X-Algolia-API-Key": BR_ALGOLIA_KEY,
"X-Algolia-Application-Id": BR_ALGOLIA_ID
};
var PRICE_GET_URL = "https://api.ec.nintendo.com/v1/price";
var PRICE_GET_OPTIONS = { lang: "en" };
var PRICE_LIST_LIMIT = 50;
var Region = /* @__PURE__ */ ((Region2) => {
Region2[Region2["AMERICAS"] = 1] = "AMERICAS";
Region2[Region2["EUROPE"] = 2] = "EUROPE";
Region2[Region2["ASIA"] = 3] = "ASIA";
return Region2;
})(Region || {});
// src/lib/utils/utils.ts
var arrayRemoveDuplicates = /* @__PURE__ */ __name((array, property) => {
const index = [];
return array.filter((item) => {
const key = property ? item[property] : item;
return index.includes(key) ? false : index.push(key);
});
}, "arrayRemoveDuplicates");
var EshopError = class extends Error {
/**
* Create an EshopError
* @param message The message the error should show
*/
constructor(message) {
super(message);
this.message = message;
this.name = "EshopError";
}
};
__name(EshopError, "EshopError");
// src/lib/getGames/getGamesAmerica.ts
async function getGamesAmerica() {
const page = 0;
const baseParameters = {
hitsPerPage: US_GAME_LIST_LIMIT,
page,
analytics: false,
facets: US_FACETS
};
const requests = [];
for (const rating of US_ESRB_RATINGS_FILTERS) {
requests.push(
{
indexName: US_INDEX_TITLE_ASC,
params: (0, import_querystring.stringify)({ ...baseParameters, facetFilters: `[["${rating}"],["${US_PLATFORM_FACET_FILTER}"]]` })
},
{
indexName: US_INDEX_TITLE_DESC,
params: (0, import_querystring.stringify)({ ...baseParameters, facetFilters: `[["${rating}"],["${US_PLATFORM_FACET_FILTER}"]]` })
}
);
}
for (const rating of US_AVAILABILITY_FILTER) {
requests.push(
{
indexName: US_INDEX_TITLE_ASC,
params: (0, import_querystring.stringify)({ ...baseParameters, facetFilters: `[["${rating}"],["${US_PLATFORM_FACET_FILTER}"]]` })
},
{
indexName: US_INDEX_TITLE_DESC,
params: (0, import_querystring.stringify)({ ...baseParameters, facetFilters: `[["${rating}"],["${US_PLATFORM_FACET_FILTER}"]]` })
}
);
}
for (const rating of US_COMMON_GAME_FRANCHISES) {
requests.push(
{
indexName: US_INDEX_TITLE_ASC,
params: (0, import_querystring.stringify)({ ...baseParameters, facetFilters: `[["${rating}"],["${US_PLATFORM_FACET_FILTER}"]]` })
},
{
indexName: US_INDEX_TITLE_DESC,
params: (0, import_querystring.stringify)({ ...baseParameters, facetFilters: `[["${rating}"],["${US_PLATFORM_FACET_FILTER}"]]` })
}
);
}
const requestOptions = {
body: JSON.stringify({
requests
}),
method: "POST",
headers: US_ALGOLIA_HEADERS
};
const gamesResponse = await import_result.Result.fromAsync((0, import_fetch.fetch)(US_GET_GAMES_URL, requestOptions, import_fetch.FetchResultTypes.JSON));
if (gamesResponse.isErr()) {
throw new EshopError("Fetching of US Games failed");
}
let allGames = [];
for (const results of gamesResponse.unwrap().results) {
allGames = allGames.concat(results.hits);
}
allGames = arrayRemoveDuplicates(allGames, "slug");
return allGames;
}
__name(getGamesAmerica, "getGamesAmerica");
var US_GAME_LIST_LIMIT = 1e3;
var US_INDEX_TITLE_ASC = "ncom_game_en_us_title_asc";
var US_INDEX_TITLE_DESC = "ncom_game_en_us_title_des";
var US_FACETS = JSON.stringify([
"generalFilters",
"platform",
"availability",
"genres",
"howToShop",
"virtualConsole",
"franchises",
"priceRange",
"esrbRating",
"playerFilters"
]);
var US_PLATFORM_FACET_FILTER = "platform:Nintendo Switch";
var US_ESRB_RATINGS_FILTERS = ["esrbRating:Everyone", "esrbRating:Everyone 10+", "esrbRating:Teen", "esrbRating:Mature"];
var US_AVAILABILITY_FILTER = ["availability:Pre-order", "availability:Coming soon", "availability:Available now"];
var US_COMMON_GAME_FRANCHISES = ["franchises:Mario", "franchises:Zelda", "franchises:Pok\xE9mon", "franchises:Kirby"];
// src/lib/getGames/getGamesBrazil.ts
var import_fetch2 = require("@sapphire/fetch");
var import_result2 = require("@sapphire/result");
var import_querystring2 = require("querystring");
async function getGamesBrazil() {
const page = 0;
const baseParameters = {
hitsPerPage: BR_GAME_LIST_LIMIT,
page,
analytics: false,
facets: BR_FACETS
};
const requests = [];
for (const rating of BR_ESRB_RATINGS_FILTERS) {
requests.push(
{
indexName: BR_INDEX_TITLE_ASC,
params: (0, import_querystring2.stringify)({ ...baseParameters, facetFilters: `[["${rating}"],["${BR_PLATFORM_FACET_FILTER}"]]` })
},
{
indexName: BR_INDEX_TITLE_DESC,
params: (0, import_querystring2.stringify)({ ...baseParameters, facetFilters: `[["${rating}"],["${BR_PLATFORM_FACET_FILTER}"]]` })
}
);
}
for (const rating of BR_AVAILABILITY_FILTER) {
requests.push(
{
indexName: BR_INDEX_TITLE_ASC,
params: (0, import_querystring2.stringify)({ ...baseParameters, facetFilters: `[["${rating}"],["${BR_PLATFORM_FACET_FILTER}"]]` })
},
{
indexName: BR_INDEX_TITLE_DESC,
params: (0, import_querystring2.stringify)({ ...baseParameters, facetFilters: `[["${rating}"],["${BR_PLATFORM_FACET_FILTER}"]]` })
}
);
}
for (const rating of BR_COMMON_GAME_FRANCHISES) {
requests.push(
{
indexName: BR_INDEX_TITLE_ASC,
params: (0, import_querystring2.stringify)({ ...baseParameters, facetFilters: `[["${rating}"],["${BR_PLATFORM_FACET_FILTER}"]]` })
},
{
indexName: BR_INDEX_TITLE_DESC,
params: (0, import_querystring2.stringify)({ ...baseParameters, facetFilters: `[["${rating}"],["${BR_PLATFORM_FACET_FILTER}"]]` })
}
);
}
const requestOptions = {
body: JSON.stringify({
requests
}),
method: "POST",
headers: BR_ALGOLIA_HEADERS
};
const gamesResponse = await import_result2.Result.fromAsync((0, import_fetch2.fetch)(BR_GET_GAMES_URL, requestOptions, import_fetch2.FetchResultTypes.JSON));
if (gamesResponse.isErr()) {
throw new EshopError("Fetching of BR Games failed");
}
let allGames = [];
for (const results of gamesResponse.unwrap().results) {
allGames = allGames.concat(results.hits);
}
allGames = arrayRemoveDuplicates(allGames, "slug");
return allGames;
}
__name(getGamesBrazil, "getGamesBrazil");
var BR_GAME_LIST_LIMIT = 499;
var BR_INDEX_TITLE_ASC = "ncom_game_pt_br_title_asc";
var BR_INDEX_TITLE_DESC = "ncom_game_pt_br_title_des";
var BR_FACETS = JSON.stringify([
"generalFilters",
"platform",
"availability",
"genres",
"howToShop",
"virtualConsole",
"franchises",
"priceRange",
"esrbRating",
"playerFilters"
]);
var BR_PLATFORM_FACET_FILTER = "platform:Nintendo Switch";
var BR_ESRB_RATINGS_FILTERS = [
"esrbRating:Livre",
"esrbRating:10",
"esrbRating:12",
"esrbRating:14",
"esrbRating:16",
"esrbRating:18",
"esrbRating:Check the rating",
"esrbRating:L"
];
var BR_AVAILABILITY_FILTER = ["availability:Pre-order", "availability:Coming soon", "availability:Available now", "availability:New releases"];
var BR_COMMON_GAME_FRANCHISES = ["franchises:Mario", "franchises:Zelda", "franchises:Pok\xE9mon", "franchises:Kirby"];
// src/lib/getGames/getGamesEurope.ts
var import_fetch3 = require("@sapphire/fetch");
var import_result3 = require("@sapphire/result");
var import_querystring3 = require("querystring");
async function getGamesEurope(options = { limit: EU_GAME_LIST_LIMIT, locale: EU_DEFAULT_LOCALE }) {
if (!options.limit)
options.limit = EU_GAME_LIST_LIMIT;
if (!options.locale)
options.locale = EU_DEFAULT_LOCALE;
const gamesData = await import_result3.Result.fromAsync(
(0, import_fetch3.fetch)(
`${EU_GET_GAMES_URL.replace("{locale}", options.locale)}?${(0, import_querystring3.stringify)({
rows: options.limit,
...EU_GET_GAMES_OPTIONS
})}`,
import_fetch3.FetchResultTypes.JSON
)
);
if (gamesData.isErr()) {
throw new EshopError("Fetching of EU Games failed");
}
return gamesData.unwrap().response.docs;
}
__name(getGamesEurope, "getGamesEurope");
// src/lib/getGames/getGamesJapan.ts
var import_fetch4 = require("@sapphire/fetch");
var import_result4 = require("@sapphire/result");
var import_fast_xml_parser = require("fast-xml-parser");
var parser = new import_fast_xml_parser.XMLParser();
async function getGamesJapan() {
const response = await import_result4.Result.fromAsync((0, import_fetch4.fetch)(JP_GET_GAMES_URL, import_fetch4.FetchResultTypes.Text));
if (response.isErr()) {
throw new EshopError("Fetching of JP Games failed");
}
const gamesJP = import_result4.Result.from(() => parser.parse(response.unwrap()));
if (gamesJP.isErr()) {
throw new EshopError("Parsing of JP Games failed");
}
return gamesJP.unwrap().TitleInfoList.TitleInfo;
}
__name(getGamesJapan, "getGamesJapan");
// src/lib/getGames/getQueriedGamesAmerica.ts
var import_fetch5 = require("@sapphire/fetch");
var import_result5 = require("@sapphire/result");
async function getQueriedGamesAmerica(query, { hitsPerPage = 200, page = 0 } = { hitsPerPage: 200, page: 0 }) {
const newGamesResult = await import_result5.Result.fromAsync(
(0, import_fetch5.fetch)(
QUERIED_US_GET_GAMES_URL_NEW,
{
method: "POST",
headers: {
...US_ALGOLIA_HEADERS,
"X-Algolia-API-Key": QUERIED_US_ALGOLIA_KEY_NEW
},
body: JSON.stringify({
hitsPerPage,
page,
query
})
},
import_fetch5.FetchResultTypes.JSON
)
);
if (newGamesResult.isErr() || newGamesResult.isOkAnd((v) => v.hits.length === 0)) {
throw new EshopError(`No game results for the query "${query}"`);
}
const oldGamesResult = await import_result5.Result.fromAsync(
(0, import_fetch5.fetch)(
QUERIED_US_GET_GAMES_URL_OLD,
{
method: "POST",
headers: {
...US_ALGOLIA_HEADERS,
"X-Algolia-API-Key": QUERIED_US_ALGOLIA_KEY_OLD
},
body: JSON.stringify({
hitsPerPage,
page,
query
})
},
import_fetch5.FetchResultTypes.JSON
)
);
if (oldGamesResult.isErr() || oldGamesResult.isOkAnd((v) => v.hits.length === 0)) {
throw new EshopError(`No game results for the query "${query}"`);
}
return enrichNewHitsWithOldHitData(newGamesResult.unwrap().hits, oldGamesResult.unwrap().hits);
}
__name(getQueriedGamesAmerica, "getQueriedGamesAmerica");
function enrichNewHitsWithOldHitData(newHits, oldHits) {
for (const newHit of newHits) {
const oldHitWithSameNsuid = oldHits.find((oldHit) => oldHit.nsuid === newHit.nsuid);
if (!oldHitWithSameNsuid)
continue;
newHit.boxart = oldHitWithSameNsuid.boxart;
newHit.developers = oldHitWithSameNsuid.developers;
newHit.freeToStart = oldHitWithSameNsuid.freeToStart;
newHit.generalFilters = oldHitWithSameNsuid.generalFilters;
newHit.horizontalHeaderImage = oldHitWithSameNsuid.horizontalHeaderImage;
newHit.howToShop = oldHitWithSameNsuid.howToShop;
newHit.lowestPrice = oldHitWithSameNsuid.lowestPrice;
newHit.msrp = oldHitWithSameNsuid.msrp ?? newHit.price?.regPrice;
newHit.salePrice = oldHitWithSameNsuid.salePrice ?? newHit.price?.salePrice;
newHit.featured = oldHitWithSameNsuid.featured ?? newHit.featuredProduct;
newHit.lastModified = oldHitWithSameNsuid.lastModified ?? newHit.updatedAt;
newHit.numOfPlayers = oldHitWithSameNsuid.numOfPlayers;
newHit.playerFilters = oldHitWithSameNsuid.playerFilters;
newHit._distinctSeqID = oldHitWithSameNsuid._distinctSeqID;
}
return newHits;
}
__name(enrichNewHitsWithOldHitData, "enrichNewHitsWithOldHitData");
// src/lib/getGames/getQueriedGamesBrazil.ts
var import_fetch6 = require("@sapphire/fetch");
var import_result6 = require("@sapphire/result");
var import_querystring4 = require("querystring");
async function getQueriedGamesBrazil(query, { hitsPerPage = 200, page = 0 } = { hitsPerPage: 200, page: 0 }) {
const gamesResult = await import_result6.Result.fromAsync(
(0, import_fetch6.fetch)(
QUERIED_BR_GET_GAMES_URL,
{
method: "POST",
headers: {
...BR_ALGOLIA_HEADERS,
"X-Algolia-API-Key": QUERIED_BR_ALGOLIA_KEY
},
body: JSON.stringify({
params: (0, import_querystring4.stringify)({
hitsPerPage,
page,
query
})
})
},
import_fetch6.FetchResultTypes.JSON
)
);
if (gamesResult.isErr() || gamesResult.isOkAnd((v) => v.hits.length === 0)) {
throw new EshopError(`No game results for the query "${query}"`);
}
return gamesResult.unwrap().hits;
}
__name(getQueriedGamesBrazil, "getQueriedGamesBrazil");
// src/lib/getShops/getShopsAmerica.ts
var import_country_data2 = require("country-data");
// src/lib/other/getShopByCountryCode.ts
var import_result8 = require("@sapphire/result");
var import_country_data = require("country-data");
// src/lib/other/getPrices.ts
var import_fetch7 = require("@sapphire/fetch");
var import_result7 = require("@sapphire/result");
var import_querystring5 = require("querystring");
async function getPrices(country, gameIds, offset = 0, prices = []) {
const filteredIds = gameIds.slice(offset, offset + PRICE_LIST_LIMIT);
const response = await import_result7.Result.fromAsync(
(0, import_fetch7.fetch)(
`${PRICE_GET_URL}?${(0, import_querystring5.stringify)({
country,
ids: filteredIds,
limit: PRICE_LIST_LIMIT,
...PRICE_GET_OPTIONS
})}`,
import_fetch7.FetchResultTypes.JSON
)
);
if (response.isErr()) {
throw new EshopError("Fetching of eShop prices failed");
}
const unwrappedResponse = response.unwrap();
if (unwrappedResponse.prices && unwrappedResponse.prices.length + offset < gameIds.length) {
const accumulatedPrices = prices.concat(unwrappedResponse.prices);
return getPrices(country, gameIds, offset + PRICE_LIST_LIMIT, accumulatedPrices);
} else if (unwrappedResponse.prices) {
unwrappedResponse.prices = unwrappedResponse.prices.concat(prices);
return unwrappedResponse;
}
return unwrappedResponse;
}
__name(getPrices, "getPrices");
// src/lib/other/getShopByCountryCode.ts
async function getShopsByCountryCodes(countryCodes, gameCode, region) {
const countryList = countryCodes.map((code) => import_country_data.countries.all.filter((country) => country.alpha2 === code)[0]);
const shops = [];
for (const country of countryList) {
const response = await import_result8.Result.fromAsync(getPrices(country.alpha2, gameCode));
if (response.isErr()) {
continue;
}
const unwrappedResponse = response.unwrap();
unwrappedResponse.country = country;
shops.push(unwrappedResponse);
}
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;
}
__name(getShopsByCountryCodes, "getShopsByCountryCodes");
// src/lib/getShops/getShopsAmerica.ts
async function getShopsAmerica() {
return getShopsByCountryCodes(
import_country_data2.regions.southAmerica.countries.concat(import_country_data2.regions.centralAfrica.countries, import_country_data2.regions.northernAmerica.countries),
US_GAME_CHECK_CODE,
1 /* AMERICAS */
);
}
__name(getShopsAmerica, "getShopsAmerica");
// src/lib/getShops/getShopsAsia.ts
var import_country_data3 = require("country-data");
async function getShopsAsia() {
return getShopsByCountryCodes(
import_country_data3.regions.southernAsia.countries.concat(
import_country_data3.regions.southernAsia.countries,
import_country_data3.regions.southeastAsia.countries,
import_country_data3.regions.eastAsia.countries,
import_country_data3.regions.westernAsia.countries
),
JP_GAME_CHECK_CODE,
3 /* ASIA */
);
}
__name(getShopsAsia, "getShopsAsia");
// src/lib/getShops/getShopsEurope.ts
var import_country_data4 = require("country-data");
async function getShopsEurope() {
return getShopsByCountryCodes(
import_country_data4.regions.northernEurope.countries.concat(
import_country_data4.regions.southernEurope.countries,
import_country_data4.regions.easternEurope.countries,
import_country_data4.regions.westernEurope.countries,
import_country_data4.regions.australia.countries,
import_country_data4.regions.southernAfrica.countries
),
EU_GAME_CHECK_CODE,
2 /* EUROPE */
);
}
__name(getShopsEurope, "getShopsEurope");
// src/lib/getShops/getActiveShops.ts
async function getActiveShops() {
try {
const shopsAmerica = await getShopsAmerica();
const shopsAsia = await getShopsAsia();
const shopsEurope = await getShopsEurope();
return shopsAmerica.concat(shopsAsia, shopsEurope);
} catch (err) {
throw err;
}
}
__name(getActiveShops, "getActiveShops");
// src/lib/other/parseGameCode.ts
function parseGameCode(game, region) {
let codeParse;
switch (region) {
case 1 /* AMERICAS */:
throw new EshopError(
"`parseGameCode` is not possible for American games as the Nintendo API does not provide enough information to deduce the game code."
);
case 2 /* EUROPE */:
codeParse = EU_GAME_CODE_REGEX.exec(game.product_code_txt[0]);
break;
case 3 /* ASIA */:
codeParse = JP_GAME_CODE_REGEX.exec(game.InitialCode);
break;
}
return codeParse && codeParse.length > 1 ? codeParse[1] : null;
}
__name(parseGameCode, "parseGameCode");
// src/lib/other/parseNSUID.ts
function parseNSUID(game, region) {
switch (region) {
case 2 /* EUROPE */:
return game.nsuid_txt ? game.nsuid_txt[0] : null;
case 3 /* ASIA */:
const nsuidParse = JP_NSUID_REGEX.exec(game.LinkURL);
return nsuidParse && nsuidParse.length > 0 ? nsuidParse[0] : null;
default:
case 1 /* AMERICAS */:
return game.nsuid;
}
}
__name(parseNSUID, "parseNSUID");
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
BR_ALGOLIA_HEADERS,
BR_ALGOLIA_ID,
BR_ALGOLIA_KEY,
BR_GET_GAMES_URL,
EU_GET_GAMES_URL,
EshopError,
JP_GET_GAMES_URL,
PRICE_GET_URL,
QUERIED_BR_ALGOLIA_KEY,
QUERIED_BR_GET_GAMES_URL,
QUERIED_US_ALGOLIA_KEY_NEW,
QUERIED_US_ALGOLIA_KEY_OLD,
QUERIED_US_GET_GAMES_URL_NEW,
QUERIED_US_GET_GAMES_URL_OLD,
Region,
US_ALGOLIA_HEADERS,
US_ALGOLIA_ID,
US_ALGOLIA_KEY,
US_GET_GAMES_URL,
getActiveShops,
getGamesAmerica,
getGamesBrazil,
getGamesEurope,
getGamesJapan,
getPrices,
getQueriedGamesAmerica,
getQueriedGamesBrazil,
getShopsAmerica,
getShopsAsia,
getShopsByCountryCodes,
getShopsEurope,
parseGameCode,
parseNSUID
});
/**
* Fetches a subset of games from the American e-shops as based on a given query
* @param query The query to search for
* @param __namedParameters Additional options for the [[getQueriedGamesAmerica]] call. Defaults to `{ hitsPerPage: 200, page: 0 }`
* @returns Promise containing the first `hitsPerPage` games that match your query
* @license Apache-2.0 Jeroen Claassens & Aura Román
* @copyright 2021
*/
/**
* Fetches a subset of games from the Brazilian e-shop as based on a given query
* @param query The query to search for
* @param __namedParameters Additional options for the [[getQueriedGamesBrazil]] call. Defaults to `{ hitsPerPage: 200, page: 0 }`
* @returns Promise containing the first `hitsPerPage` games that match your query
* @license Apache-2.0 Jeroen Claassens & Aura Román
* @copyright 2021
*/
//# sourceMappingURL=index.js.map

50

package.json
{
"name": "nintendo-switch-eshop",
"version": "7.1.2",
"version": "7.1.3",
"workspaces": [

@@ -23,8 +23,6 @@ "documentation/"

"lint": "eslint src tests documentation/src --ext mjs,js,ts,tsx --fix",
"build": "tsc -b src && gen-esm-wrapper dist/index.js dist/index.mjs",
"watch": "tsc -b src -w",
"clean": "tsc -b src --clean",
"typecheck": "tsc -p tsconfig.dev.json",
"build": "tsup",
"bump": "cliff-jumper",
"check-update": "cliff-jumper --dry-run",
"update": "yarn upgrade-interactive",
"_postinstall": "husky install .github/husky",

@@ -36,32 +34,32 @@ "prepack": "yarn build && pinst --disable",

"@sapphire/fetch": "^2.4.1",
"@sapphire/result": "^2.4.0",
"@sapphire/result": "^2.6.1",
"@types/country-data": "^0.0.2",
"country-data": "^0.0.31",
"fast-xml-parser": "^4.0.9"
"fast-xml-parser": "^4.2.0"
},
"devDependencies": {
"@commitlint/cli": "^17.0.3",
"@commitlint/config-conventional": "^17.0.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.8",
"@typescript-eslint/eslint-plugin": "^5.33.1",
"@typescript-eslint/parser": "^5.33.1",
"@vitest/coverage-c8": "^0.22.1",
"@commitlint/cli": "^17.5.1",
"@commitlint/config-conventional": "^17.4.4",
"@favware/cliff-jumper": "^2.0.0",
"@sapphire/eslint-config": "^4.4.1",
"@sapphire/prettier-config": "^1.4.5",
"@sapphire/ts-config": "^4.0.0",
"@types/node": "^18.15.11",
"@typescript-eslint/eslint-plugin": "^5.58.0",
"@typescript-eslint/parser": "^5.58.0",
"@vitest/coverage-c8": "^0.29.8",
"common-tags": "^1.8.2",
"cz-conventional-changelog": "^3.3.0",
"eslint": "^8.22.0",
"eslint-config-prettier": "^8.5.0",
"eslint": "^8.38.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-prettier": "^4.2.1",
"gen-esm-wrapper": "^1.1.3",
"husky": "^8.0.1",
"lint-staged": "^13.0.3",
"husky": "^8.0.3",
"lint-staged": "^13.2.1",
"pinst": "^3.0.0",
"prettier": "^2.7.1",
"prettier": "^2.8.7",
"pretty-quick": "^3.1.3",
"replace": "^1.2.1",
"typescript": "^4.7.4",
"vitest": "^0.22.1"
"replace": "^1.2.2",
"tsup": "^6.7.0",
"typescript": "^5.0.4",
"vitest": "^0.29.8"
},

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

@@ -43,30 +43,12 @@ <div align="center">

## Contributors ✨
## Contributors
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
Please make sure to read the [Contributing Guide][contributing] before making a pull request.
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore-start -->
<!-- markdownlint-disable -->
<table>
<tr>
<td align="center"><a href="https://github.com/lmmfranco"><img src="https://avatars2.githubusercontent.com/u/5719409?v=4?s=100" width="100px;" alt=""/><br /><sub><b>lmmfranco</b></sub></a><br /><a href="https://github.com/favna/nintendo-switch-eshop/commits?author=lmmfranco" title="Code">💻</a> <a href="#ideas-lmmfranco" title="Ideas, Planning, & Feedback">🤔</a> <a href="#projectManagement-lmmfranco" title="Project Management">📆</a> <a href="#question-lmmfranco" title="Answering Questions">💬</a> <a href="https://github.com/favna/nintendo-switch-eshop/pulls?q=is%3Apr+reviewed-by%3Almmfranco" title="Reviewed Pull Requests">👀</a> <a href="https://github.com/favna/nintendo-switch-eshop/commits?author=lmmfranco" title="Documentation">📖</a></td>
<td align="center"><a href="https://favware.tech/"><img src="https://avatars3.githubusercontent.com/u/4019718?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jeroen Claassens</b></sub></a><br /><a href="https://github.com/favna/nintendo-switch-eshop/commits?author=favna" title="Code">💻</a> <a href="#ideas-favna" title="Ideas, Planning, & Feedback">🤔</a> <a href="#projectManagement-favna" title="Project Management">📆</a> <a href="#question-favna" title="Answering Questions">💬</a> <a href="https://github.com/favna/nintendo-switch-eshop/pulls?q=is%3Apr+reviewed-by%3Afavna" title="Reviewed Pull Requests">👀</a> <a href="#userTesting-favna" title="User Testing">📓</a> <a href="#maintenance-favna" title="Maintenance">🚧</a> <a href="https://github.com/favna/nintendo-switch-eshop/commits?author=favna" title="Documentation">📖</a></td>
<td align="center"><a href="https://github.com/mmakarios"><img src="https://avatars0.githubusercontent.com/u/9814055?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Michel Makarios</b></sub></a><br /><a href="https://github.com/favna/nintendo-switch-eshop/commits?author=mmakarios" title="Documentation">📖</a></td>
<td align="center"><a href="http://iulianonofrei.com/"><img src="https://avatars0.githubusercontent.com/u/5748627?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Iulian Onofrei</b></sub></a><br /><a href="https://github.com/favna/nintendo-switch-eshop/commits?author=revolter" title="Documentation">📖</a></td>
<td align="center"><a href="https://github.com/Lililiuliu"><img src="https://avatars3.githubusercontent.com/u/52712459?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Lililiuliu</b></sub></a><br /><a href="https://github.com/favna/nintendo-switch-eshop/issues?q=author%3ALililiuliu" title="Bug reports">🐛</a> <a href="https://github.com/favna/nintendo-switch-eshop/commits?author=Lililiuliu" title="Code">💻</a></td>
<td align="center"><a href="https://github.com/ende124"><img src="https://avatars1.githubusercontent.com/u/3050747?v=4?s=100" width="100px;" alt=""/><br /><sub><b>ende124</b></sub></a><br /><a href="https://github.com/favna/nintendo-switch-eshop/issues?q=author%3Aende124" title="Bug reports">🐛</a> <a href="https://github.com/favna/nintendo-switch-eshop/commits?author=ende124" title="Code">💻</a></td>
<td align="center"><a href="https://github.com/junyeonglee"><img src="https://avatars3.githubusercontent.com/u/53418618?v=4?s=100" width="100px;" alt=""/><br /><sub><b>junyeonglee</b></sub></a><br /><a href="https://github.com/favna/nintendo-switch-eshop/issues?q=author%3Ajunyeonglee" title="Bug reports">🐛</a> <a href="https://github.com/favna/nintendo-switch-eshop/commits?author=junyeonglee" title="Code">💻</a></td>
</tr>
<tr>
<td align="center"><a href="https://github.com/bvanzile"><img src="https://avatars3.githubusercontent.com/u/9438505?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Bryan Van Zile</b></sub></a><br /><a href="https://github.com/favna/nintendo-switch-eshop/commits?author=bvanzile" title="Code">💻</a> <a href="https://github.com/favna/nintendo-switch-eshop/issues?q=author%3Abvanzile" title="Bug reports">🐛</a></td>
</tr>
</table>
Thank you to all the people who already contributed to Sapphire!
<!-- markdownlint-restore -->
<!-- prettier-ignore-end -->
<a href="https://github.com/favna/nintendo-switch-eshop/graphs/contributors">
<img src="https://contrib.rocks/image?repo=favna/nintendo-switch-eshop" />
</a>
<!-- ALL-CONTRIBUTORS-LIST:END -->
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification.
Contributions of any kind welcome!
[contributing]: .github/CONTRIBUTING.md

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