/**
 * Safe fetch wrapper with URL validation.
 * Blocks external URLs that haven't been validated.
 * Requires url-validator.js to be loaded first.
 */
async function safeFetch(url, options = {}) {
    // Internal URLs starting with '/' are safe
    if (!url.startsWith('/')) {
        if (!URLValidator.isSafeUrl(url)) {
            throw new Error(`Blocked unsafe URL: ${url}`);
        }
    }
    return fetch(url, options);
}

// Export for Node.js testing
if (typeof module !== 'undefined' && module.exports) {
    module.exports = { safeFetch };
}

// Make safeFetch available globally for browser usage
if (typeof window !== 'undefined') {
    window.safeFetch = safeFetch;
}
