@liip/npm-icons
Advanced tools
Comparing version 0.2.2 to 0.2.3
@@ -12,3 +12,6 @@ // *********** | ||
getIconsTypes, | ||
getIconsJsonUrl, getIconsSvgBaseUrl, | ||
getIconsJsonUrl, | ||
getIconsSvgBaseUrl, | ||
getUsername, | ||
getPassword, | ||
} from './getConfiguration.js'; | ||
@@ -23,2 +26,5 @@ | ||
const iconTypes = getIconsTypes(); | ||
const username = getUsername(); | ||
const password = getPassword(); | ||
let axiosInstance = axios; | ||
@@ -30,6 +36,23 @@ export const getIconSvgUrl = (icon) => `${icon.path}/${icon.file}`; | ||
export const getAllIcons = async () => { | ||
const { data } = await axios(iconsJsonUrl); | ||
const { data } = await axiosInstance(iconsJsonUrl); | ||
return data; | ||
}; | ||
const verifyIconAccess = async () => { | ||
try { | ||
if (username && password) { | ||
const token = Buffer.from(`${username}:${password}`, 'utf8').toString('base64'); | ||
axiosInstance = axios.create({ | ||
headers: { | ||
Authorization: `Basic ${token}`, | ||
}, | ||
}); | ||
} | ||
await axiosInstance(iconsJsonUrl); | ||
} catch (e) { | ||
console.log(chalk.bgRed.whiteBright('Unauthorized to access'), iconsJsonUrl); | ||
process.exit(1); | ||
} | ||
}; | ||
export const validateTypeOption = (options) => { | ||
@@ -68,3 +91,3 @@ if (options.type && !iconTypes.includes(options.type)) { | ||
try { | ||
const { data } = await axios(`${iconsSvgBaseUrl}/${iconType}/${iconPath}`); | ||
const { data } = await axiosInstance(`${iconsSvgBaseUrl}/${iconType}/${iconPath}`); | ||
return data; | ||
@@ -215,2 +238,3 @@ } catch (err) { | ||
export default async (name, options) => { | ||
await verifyIconAccess(); | ||
validateTypeOption(options); | ||
@@ -217,0 +241,0 @@ const icon = await getIcon(name, options); |
@@ -8,2 +8,4 @@ import path from 'path'; | ||
let iconsTypes = ['regular', 'light']; | ||
let username = null; | ||
let password = null; | ||
@@ -15,2 +17,3 @@ const explorer = cosmiconfigSync('npm-icons'); | ||
const iconsTypesConfig = explorer.search('iconsTypes'); | ||
const authorizationConfig = explorer.search('authorization'); | ||
@@ -29,2 +32,6 @@ if (iconsPathConfig) { | ||
} | ||
if (authorizationConfig) { | ||
username = authorizationConfig.config.authorization.username; | ||
password = authorizationConfig.config.authorization.password; | ||
} | ||
@@ -35,1 +42,3 @@ export const getIconsPath = () => iconsPath; | ||
export const getIconsTypes = () => iconsTypes; | ||
export const getUsername = () => username; | ||
export const getPassword = () => password; |
{ | ||
"name": "@liip/npm-icons", | ||
"version": "0.2.2", | ||
"version": "0.2.3", | ||
"description": "Import svg icons using cli", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -25,3 +25,7 @@ ## [Official Documentation](https://liip.github.io/npm-icons/website) | ||
"iconsJsonUrl": "https://icons.liip.ch/icons.json", | ||
"iconsTypes": ["regular", "light"] | ||
"iconsTypes": ["regular", "light"], | ||
"authorization": { | ||
"username": null, | ||
"password": null | ||
} | ||
} | ||
@@ -28,0 +32,0 @@ ``` |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15464
384
111