diff --git a/dist/index.d.ts b/dist/index.d.ts index 609b6b8..8d78c8b 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -16,7 +16,7 @@ export interface IRetailPrice { meterId?: string; type?: "DevTestConsumption" | "Consumption" | "Reservation"; reservationTerm?: string; - currencyCode?: "USD"; + currencyCode?: string; tierMinimumUnits?: number; retailPrice?: number; unitPrice?: number; @@ -42,7 +42,8 @@ export interface IRetailPriceFilter extends IStringKeyObject { /** * Get retail prices from the Azure Retail Prices API * @param filterObject Filter object + * @param currencyCode Currency code string * @return Array of retail price object */ -declare function getRetailPrices(filterObject: IRetailPriceFilter): Promise; +declare function getRetailPrices(filterObject: IRetailPriceFilter, currencyCode?: string): Promise; export default getRetailPrices; diff --git a/dist/index.js b/dist/index.js index 8fafe9e..ff69f10 100644 --- a/dist/index.js +++ b/dist/index.js @@ -22,16 +22,18 @@ const PRICE_TYPES = [ "Consumption", "Reservation", ]; +const DEFAULT_CURRENCY_CODE = "USD"; /** * Get retail prices from the Azure Retail Prices API * @param filterObject Filter object + * @param currencyCode Currency code string * @return Array of retail price object */ -async function getRetailPrices(filterObject) { +async function getRetailPrices(filterObject, currencyCode = DEFAULT_CURRENCY_CODE) { let retailPrices = []; if (_validateFilterObject(filterObject)) { const filterString = _generateFilter(filterObject); - retailPrices = await _getRetailPrices(filterString); + retailPrices = await _getRetailPrices(filterString, currencyCode); } return retailPrices; } @@ -68,12 +70,13 @@ function _generateFilter(filterObject) { /** * Get retail prices from the Azure Retail Prices API with filter * @param filterString Filter string + * @param currencyCode Currency code string * @return Array of retail price object */ -async function _getRetailPrices(filterString) { - let url = API_ENDPOINT; +async function _getRetailPrices(filterString, currencyCode) { + let url = API_ENDPOINT + `?currencyCode='${currencyCode}'`; if (filterString !== "") - url += `?$filter=${filterString}`; + url += `&$filter=${filterString}`; let retailPrices = []; // eslint-disable-next-line no-constant-condition while (true) { diff --git a/package-lock.json b/package-lock.json index a93aa1e..8d8d3a3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "azure-retail-prices", - "version": "1.0.1", + "version": "1.1.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 1f1174a..73126fb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "azure-retail-prices", - "version": "1.0.1", + "version": "1.1.0", "description": "Wrapper of Azure Retail Prices API. You can easily get the retail price of Azure without authenticating.", "main": "dist/index.js", "types": "dist/index.d.ts",