mirror of
https://github.com/idrainformatica/PecFlow.git
synced 2026-06-16 20:55:41 +02:00
fase 5
This commit is contained in:
+1416
File diff suppressed because it is too large
Load Diff
+7
@@ -0,0 +1,7 @@
|
||||
# Copyright (c) 2014-present Matt Zabriskie & Collaborators
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
+877
@@ -0,0 +1,877 @@
|
||||
# Axios Migration Guide
|
||||
|
||||
> **Migrating from Axios 0.x to 1.x**
|
||||
>
|
||||
> This guide helps developers upgrade from Axios 0.x to 1.x by documenting breaking changes, providing migration strategies, and offering solutions to common upgrade challenges.
|
||||
|
||||
## Table of Contents
|
||||
|
||||
- [Overview](#overview)
|
||||
- [Breaking Changes](#breaking-changes)
|
||||
- [Error Handling Migration](#error-handling-migration)
|
||||
- [API Changes](#api-changes)
|
||||
- [Configuration Changes](#configuration-changes)
|
||||
- [Migration Strategies](#migration-strategies)
|
||||
- [Common Patterns](#common-patterns)
|
||||
- [Troubleshooting](#troubleshooting)
|
||||
- [Resources](#resources)
|
||||
|
||||
## Overview
|
||||
|
||||
Axios 1.x introduced several breaking changes to improve consistency, security, and developer experience. While these changes provide better error handling and more predictable behavior, they require code updates when migrating from 0.x versions.
|
||||
|
||||
### Key Changes Summary
|
||||
|
||||
| Area | 0.x Behavior | 1.x Behavior | Impact |
|
||||
|------|--------------|--------------|--------|
|
||||
| Error Handling | Selective throwing | Consistent throwing | High |
|
||||
| JSON Parsing | Lenient | Strict | Medium |
|
||||
| Browser Support | IE11+ | Modern browsers | Low-Medium |
|
||||
| TypeScript | Partial | Full support | Low |
|
||||
|
||||
### Migration Complexity
|
||||
|
||||
- **Simple applications**: 1-2 hours
|
||||
- **Medium applications**: 1-2 days
|
||||
- **Large applications with complex error handling**: 3-5 days
|
||||
|
||||
## Breaking Changes
|
||||
|
||||
### 1. Error Handling Changes
|
||||
|
||||
**The most significant change in Axios 1.x is how errors are handled.**
|
||||
|
||||
#### 0.x Behavior
|
||||
```javascript
|
||||
// Axios 0.x - Some HTTP error codes didn't throw
|
||||
axios.get('/api/data')
|
||||
.then(response => {
|
||||
// Response interceptor could handle all errors
|
||||
console.log('Success:', response.data);
|
||||
});
|
||||
|
||||
// Response interceptor handled everything
|
||||
axios.interceptors.response.use(
|
||||
response => response,
|
||||
error => {
|
||||
handleError(error);
|
||||
// Error was "handled" and didn't propagate
|
||||
}
|
||||
);
|
||||
```
|
||||
|
||||
#### 1.x Behavior
|
||||
```javascript
|
||||
// Axios 1.x - All HTTP errors throw consistently
|
||||
axios.get('/api/data')
|
||||
.then(response => {
|
||||
console.log('Success:', response.data);
|
||||
})
|
||||
.catch(error => {
|
||||
// Must handle errors at call site or they propagate
|
||||
console.error('Request failed:', error);
|
||||
});
|
||||
|
||||
// Response interceptor must re-throw or return rejected promise
|
||||
axios.interceptors.response.use(
|
||||
response => response,
|
||||
error => {
|
||||
handleError(error);
|
||||
// Must explicitly handle propagation
|
||||
return Promise.reject(error); // or throw error;
|
||||
}
|
||||
);
|
||||
```
|
||||
|
||||
#### Impact
|
||||
- **Response interceptors** can no longer "swallow" errors silently
|
||||
- **Every API call** must handle errors explicitly or they become unhandled promise rejections
|
||||
- **Centralized error handling** requires new patterns
|
||||
|
||||
### 2. JSON Parsing Changes
|
||||
|
||||
#### 0.x Behavior
|
||||
```javascript
|
||||
// Axios 0.x - Lenient JSON parsing
|
||||
// Would attempt to parse even invalid JSON
|
||||
response.data; // Might contain partial data or fallbacks
|
||||
```
|
||||
|
||||
#### 1.x Behavior
|
||||
```javascript
|
||||
// Axios 1.x - Strict JSON parsing
|
||||
// Throws clear errors for invalid JSON
|
||||
try {
|
||||
const data = response.data;
|
||||
} catch (error) {
|
||||
// Handle JSON parsing errors explicitly
|
||||
}
|
||||
```
|
||||
|
||||
### 3. Request/Response Transform Changes
|
||||
|
||||
#### 0.x Behavior
|
||||
```javascript
|
||||
// Implicit transformations with some edge cases
|
||||
transformRequest: [function (data) {
|
||||
// Less predictable behavior
|
||||
return data;
|
||||
}]
|
||||
```
|
||||
|
||||
#### 1.x Behavior
|
||||
```javascript
|
||||
// More consistent transformation pipeline
|
||||
transformRequest: [function (data, headers) {
|
||||
// Headers parameter always available
|
||||
// More predictable behavior
|
||||
return data;
|
||||
}]
|
||||
```
|
||||
|
||||
### 4. Browser Support Changes
|
||||
|
||||
- **0.x**: Supported IE11 and older browsers
|
||||
- **1.x**: Requires modern browsers with Promise support
|
||||
- **Polyfills**: May be needed for older browser support
|
||||
|
||||
## Error Handling Migration
|
||||
|
||||
The error handling changes are the most complex part of migrating to Axios 1.x. Here are proven strategies:
|
||||
|
||||
### Strategy 1: Centralized Error Handling with Error Boundary
|
||||
|
||||
```javascript
|
||||
// Create a centralized error handler
|
||||
class ApiErrorHandler {
|
||||
constructor() {
|
||||
this.setupInterceptors();
|
||||
}
|
||||
|
||||
setupInterceptors() {
|
||||
axios.interceptors.response.use(
|
||||
response => response,
|
||||
error => {
|
||||
// Centralized error processing
|
||||
this.processError(error);
|
||||
|
||||
// Return a resolved promise with error info for handled errors
|
||||
if (this.isHandledError(error)) {
|
||||
return Promise.resolve({
|
||||
data: null,
|
||||
error: this.normalizeError(error),
|
||||
handled: true
|
||||
});
|
||||
}
|
||||
|
||||
// Re-throw unhandled errors
|
||||
return Promise.reject(error);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
processError(error) {
|
||||
// Log errors
|
||||
console.error('API Error:', error);
|
||||
|
||||
// Show user notifications
|
||||
if (error.response?.status === 401) {
|
||||
this.handleAuthError();
|
||||
} else if (error.response?.status >= 500) {
|
||||
this.showErrorNotification('Server error occurred');
|
||||
}
|
||||
}
|
||||
|
||||
isHandledError(error) {
|
||||
// Define which errors are "handled" centrally
|
||||
const handledStatuses = [401, 403, 404, 422, 500, 502, 503];
|
||||
return handledStatuses.includes(error.response?.status);
|
||||
}
|
||||
|
||||
normalizeError(error) {
|
||||
return {
|
||||
status: error.response?.status,
|
||||
message: error.response?.data?.message || error.message,
|
||||
code: error.response?.data?.code || error.code
|
||||
};
|
||||
}
|
||||
|
||||
handleAuthError() {
|
||||
// Redirect to login, clear tokens, etc.
|
||||
localStorage.removeItem('token');
|
||||
window.location.href = '/login';
|
||||
}
|
||||
|
||||
showErrorNotification(message) {
|
||||
// Show user-friendly error message
|
||||
console.error(message); // Replace with your notification system
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize globally
|
||||
const errorHandler = new ApiErrorHandler();
|
||||
|
||||
// Usage in components/services
|
||||
async function fetchUserData(userId) {
|
||||
try {
|
||||
const response = await axios.get(`/api/users/${userId}`);
|
||||
|
||||
// Check if error was handled centrally
|
||||
if (response.handled) {
|
||||
return { data: null, error: response.error };
|
||||
}
|
||||
|
||||
return { data: response.data, error: null };
|
||||
} catch (error) {
|
||||
// Unhandled errors still need local handling
|
||||
return { data: null, error: { message: 'Unexpected error occurred' } };
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Strategy 2: Wrapper Function Pattern
|
||||
|
||||
```javascript
|
||||
// Create a wrapper that provides 0.x-like behavior
|
||||
function createApiWrapper() {
|
||||
const api = axios.create();
|
||||
|
||||
// Add response interceptor for centralized handling
|
||||
api.interceptors.response.use(
|
||||
response => response,
|
||||
error => {
|
||||
// Handle common errors centrally
|
||||
if (error.response?.status === 401) {
|
||||
// Handle auth errors
|
||||
handleAuthError();
|
||||
}
|
||||
|
||||
if (error.response?.status >= 500) {
|
||||
// Handle server errors
|
||||
showServerErrorNotification();
|
||||
}
|
||||
|
||||
// Always reject to maintain error propagation
|
||||
return Promise.reject(error);
|
||||
}
|
||||
);
|
||||
|
||||
// Wrapper function that mimics 0.x behavior
|
||||
function safeRequest(requestConfig, options = {}) {
|
||||
return api(requestConfig)
|
||||
.then(response => response)
|
||||
.catch(error => {
|
||||
if (options.suppressErrors) {
|
||||
// Return error info instead of throwing
|
||||
return {
|
||||
data: null,
|
||||
error: {
|
||||
status: error.response?.status,
|
||||
message: error.response?.data?.message || error.message
|
||||
}
|
||||
};
|
||||
}
|
||||
throw error;
|
||||
});
|
||||
}
|
||||
|
||||
return { safeRequest, axios: api };
|
||||
}
|
||||
|
||||
// Usage
|
||||
const { safeRequest } = createApiWrapper();
|
||||
|
||||
// For calls where you want centralized error handling
|
||||
const result = await safeRequest(
|
||||
{ method: 'get', url: '/api/data' },
|
||||
{ suppressErrors: true }
|
||||
);
|
||||
|
||||
if (result.error) {
|
||||
// Handle error case
|
||||
console.log('Request failed:', result.error.message);
|
||||
} else {
|
||||
// Handle success case
|
||||
console.log('Data:', result.data);
|
||||
}
|
||||
```
|
||||
|
||||
### Strategy 3: Global Error Handler with Custom Events
|
||||
|
||||
```javascript
|
||||
// Set up global error handling with events
|
||||
class GlobalErrorHandler extends EventTarget {
|
||||
constructor() {
|
||||
super();
|
||||
this.setupInterceptors();
|
||||
}
|
||||
|
||||
setupInterceptors() {
|
||||
axios.interceptors.response.use(
|
||||
response => response,
|
||||
error => {
|
||||
// Emit custom event for global handling
|
||||
this.dispatchEvent(new CustomEvent('apiError', {
|
||||
detail: { error, timestamp: new Date() }
|
||||
}));
|
||||
|
||||
// Always reject to maintain proper error flow
|
||||
return Promise.reject(error);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const globalErrorHandler = new GlobalErrorHandler();
|
||||
|
||||
// Set up global listeners
|
||||
globalErrorHandler.addEventListener('apiError', (event) => {
|
||||
const { error } = event.detail;
|
||||
|
||||
// Centralized error logic
|
||||
if (error.response?.status === 401) {
|
||||
handleAuthError();
|
||||
}
|
||||
|
||||
if (error.response?.status >= 500) {
|
||||
showErrorNotification('Server error occurred');
|
||||
}
|
||||
});
|
||||
|
||||
// Usage remains clean
|
||||
async function apiCall() {
|
||||
try {
|
||||
const response = await axios.get('/api/data');
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
// Error was already handled globally
|
||||
// Just handle component-specific logic
|
||||
return null;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## API Changes
|
||||
|
||||
### Request Configuration
|
||||
|
||||
#### 0.x to 1.x Changes
|
||||
```javascript
|
||||
// 0.x - Some properties had different defaults
|
||||
const config = {
|
||||
timeout: 0, // No timeout by default
|
||||
maxContentLength: -1, // No limit
|
||||
};
|
||||
|
||||
// 1.x - More secure defaults
|
||||
const config = {
|
||||
timeout: 0, // Still no timeout, but easier to configure
|
||||
maxContentLength: 2000, // Default limit for security
|
||||
maxBodyLength: 2000, // New property
|
||||
};
|
||||
```
|
||||
|
||||
### Response Object
|
||||
|
||||
The response object structure remains largely the same, but error responses are more consistent:
|
||||
|
||||
```javascript
|
||||
// Both 0.x and 1.x
|
||||
response = {
|
||||
data: {}, // Response body
|
||||
status: 200, // HTTP status
|
||||
statusText: 'OK', // HTTP status message
|
||||
headers: {}, // Response headers
|
||||
config: {}, // Request config
|
||||
request: {} // Request object
|
||||
};
|
||||
|
||||
// Error responses are more consistent in 1.x
|
||||
error.response = {
|
||||
data: {}, // Error response body
|
||||
status: 404, // HTTP error status
|
||||
statusText: 'Not Found',
|
||||
headers: {},
|
||||
config: {},
|
||||
request: {}
|
||||
};
|
||||
```
|
||||
|
||||
## Configuration Changes
|
||||
|
||||
### Default Configuration Updates
|
||||
|
||||
```javascript
|
||||
// 0.x defaults
|
||||
axios.defaults.timeout = 0; // No timeout
|
||||
axios.defaults.maxContentLength = -1; // No limit
|
||||
|
||||
// 1.x defaults (more secure)
|
||||
axios.defaults.timeout = 0; // Still no timeout
|
||||
axios.defaults.maxContentLength = 2000; // 2MB limit
|
||||
axios.defaults.maxBodyLength = 2000; // 2MB limit
|
||||
```
|
||||
|
||||
### Instance Configuration
|
||||
|
||||
```javascript
|
||||
// 0.x - Instance creation
|
||||
const api = axios.create({
|
||||
baseURL: 'https://api.example.com',
|
||||
timeout: 1000,
|
||||
});
|
||||
|
||||
// 1.x - Same API, but more options available
|
||||
const api = axios.create({
|
||||
baseURL: 'https://api.example.com',
|
||||
timeout: 1000,
|
||||
maxBodyLength: Infinity, // Override default if needed
|
||||
maxContentLength: Infinity,
|
||||
});
|
||||
```
|
||||
|
||||
## Migration Strategies
|
||||
|
||||
### Step-by-Step Migration Process
|
||||
|
||||
#### Phase 1: Preparation
|
||||
1. **Audit Current Error Handling**
|
||||
```bash
|
||||
# Find all axios usage
|
||||
grep -r "axios\." src/
|
||||
grep -r "\.catch" src/
|
||||
grep -r "interceptors" src/
|
||||
```
|
||||
|
||||
2. **Identify Patterns**
|
||||
- Response interceptors that handle errors
|
||||
- Components that rely on centralized error handling
|
||||
- Authentication and retry logic
|
||||
|
||||
3. **Create Test Cases**
|
||||
```javascript
|
||||
// Test current error handling behavior
|
||||
describe('Error Handling Migration', () => {
|
||||
it('should handle 401 errors consistently', async () => {
|
||||
// Test authentication error flows
|
||||
});
|
||||
|
||||
it('should handle 500 errors with user feedback', async () => {
|
||||
// Test server error handling
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
#### Phase 2: Implementation
|
||||
1. **Update Dependencies**
|
||||
```bash
|
||||
npm update axios
|
||||
```
|
||||
|
||||
2. **Implement New Error Handling**
|
||||
- Choose one of the strategies above
|
||||
- Update response interceptors
|
||||
- Add error handling to API calls
|
||||
|
||||
3. **Update Authentication Logic**
|
||||
```javascript
|
||||
// 0.x pattern
|
||||
axios.interceptors.response.use(null, error => {
|
||||
if (error.response?.status === 401) {
|
||||
logout();
|
||||
// Error was "handled"
|
||||
}
|
||||
});
|
||||
|
||||
// 1.x pattern
|
||||
axios.interceptors.response.use(
|
||||
response => response,
|
||||
error => {
|
||||
if (error.response?.status === 401) {
|
||||
logout();
|
||||
}
|
||||
return Promise.reject(error); // Always propagate
|
||||
}
|
||||
);
|
||||
```
|
||||
|
||||
#### Phase 3: Testing and Validation
|
||||
1. **Test Error Scenarios**
|
||||
- Network failures
|
||||
- HTTP error codes (401, 403, 404, 500, etc.)
|
||||
- Timeout errors
|
||||
- JSON parsing errors
|
||||
|
||||
2. **Validate User Experience**
|
||||
- Error messages are shown appropriately
|
||||
- Authentication redirects work
|
||||
- Loading states are handled correctly
|
||||
|
||||
### Gradual Migration Approach
|
||||
|
||||
For large applications, consider gradual migration:
|
||||
|
||||
```javascript
|
||||
// Create a compatibility layer
|
||||
const axiosCompat = {
|
||||
// Use new axios instance for new code
|
||||
v1: axios.create({
|
||||
// 1.x configuration
|
||||
}),
|
||||
|
||||
// Wrapper for legacy code
|
||||
legacy: createLegacyWrapper(axios.create({
|
||||
// Configuration that mimics 0.x behavior
|
||||
}))
|
||||
};
|
||||
|
||||
function createLegacyWrapper(axiosInstance) {
|
||||
// Add interceptors that provide 0.x-like behavior
|
||||
axiosInstance.interceptors.response.use(
|
||||
response => response,
|
||||
error => {
|
||||
// Handle errors in 0.x style for legacy code
|
||||
handleLegacyError(error);
|
||||
// Don't propagate certain errors
|
||||
if (shouldSuppressError(error)) {
|
||||
return Promise.resolve({ data: null, error: true });
|
||||
}
|
||||
return Promise.reject(error);
|
||||
}
|
||||
);
|
||||
|
||||
return axiosInstance;
|
||||
}
|
||||
```
|
||||
|
||||
## Common Patterns
|
||||
|
||||
### Authentication Interceptors
|
||||
|
||||
#### Updated Authentication Pattern
|
||||
```javascript
|
||||
// Token refresh interceptor for 1.x
|
||||
let isRefreshing = false;
|
||||
let refreshSubscribers = [];
|
||||
|
||||
function subscribeTokenRefresh(cb) {
|
||||
refreshSubscribers.push(cb);
|
||||
}
|
||||
|
||||
function onTokenRefreshed(token) {
|
||||
refreshSubscribers.forEach(cb => cb(token));
|
||||
refreshSubscribers = [];
|
||||
}
|
||||
|
||||
axios.interceptors.response.use(
|
||||
response => response,
|
||||
async error => {
|
||||
const originalRequest = error.config;
|
||||
|
||||
if (error.response?.status === 401 && !originalRequest._retry) {
|
||||
if (isRefreshing) {
|
||||
// Wait for token refresh
|
||||
return new Promise(resolve => {
|
||||
subscribeTokenRefresh(token => {
|
||||
originalRequest.headers.Authorization = `Bearer ${token}`;
|
||||
resolve(axios(originalRequest));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
originalRequest._retry = true;
|
||||
isRefreshing = true;
|
||||
|
||||
try {
|
||||
const newToken = await refreshToken();
|
||||
onTokenRefreshed(newToken);
|
||||
isRefreshing = false;
|
||||
|
||||
originalRequest.headers.Authorization = `Bearer ${newToken}`;
|
||||
return axios(originalRequest);
|
||||
} catch (refreshError) {
|
||||
isRefreshing = false;
|
||||
logout();
|
||||
return Promise.reject(refreshError);
|
||||
}
|
||||
}
|
||||
|
||||
return Promise.reject(error);
|
||||
}
|
||||
);
|
||||
```
|
||||
|
||||
### Retry Logic
|
||||
|
||||
```javascript
|
||||
// Retry interceptor for 1.x
|
||||
function createRetryInterceptor(maxRetries = 3, retryDelay = 1000) {
|
||||
return axios.interceptors.response.use(
|
||||
response => response,
|
||||
async error => {
|
||||
const config = error.config;
|
||||
|
||||
if (!config || !config.retry) {
|
||||
return Promise.reject(error);
|
||||
}
|
||||
|
||||
config.__retryCount = config.__retryCount || 0;
|
||||
|
||||
if (config.__retryCount >= maxRetries) {
|
||||
return Promise.reject(error);
|
||||
}
|
||||
|
||||
config.__retryCount += 1;
|
||||
|
||||
// Exponential backoff
|
||||
const delay = retryDelay * Math.pow(2, config.__retryCount - 1);
|
||||
await new Promise(resolve => setTimeout(resolve, delay));
|
||||
|
||||
return axios(config);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
// Usage
|
||||
const api = axios.create();
|
||||
createRetryInterceptor(3, 1000);
|
||||
|
||||
// Make request with retry
|
||||
api.get('/api/data', { retry: true });
|
||||
```
|
||||
|
||||
### Loading State Management
|
||||
|
||||
```javascript
|
||||
// Loading interceptor for 1.x
|
||||
class LoadingManager {
|
||||
constructor() {
|
||||
this.requests = new Set();
|
||||
this.setupInterceptors();
|
||||
}
|
||||
|
||||
setupInterceptors() {
|
||||
axios.interceptors.request.use(config => {
|
||||
this.requests.add(config);
|
||||
this.updateLoadingState();
|
||||
return config;
|
||||
});
|
||||
|
||||
axios.interceptors.response.use(
|
||||
response => {
|
||||
this.requests.delete(response.config);
|
||||
this.updateLoadingState();
|
||||
return response;
|
||||
},
|
||||
error => {
|
||||
this.requests.delete(error.config);
|
||||
this.updateLoadingState();
|
||||
return Promise.reject(error);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
updateLoadingState() {
|
||||
const isLoading = this.requests.size > 0;
|
||||
// Update your loading UI
|
||||
document.body.classList.toggle('loading', isLoading);
|
||||
}
|
||||
}
|
||||
|
||||
const loadingManager = new LoadingManager();
|
||||
```
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Common Migration Issues
|
||||
|
||||
#### Issue 1: Unhandled Promise Rejections
|
||||
|
||||
**Problem:**
|
||||
```javascript
|
||||
// This pattern worked in 0.x but causes unhandled rejections in 1.x
|
||||
axios.get('/api/data'); // No .catch() handler
|
||||
```
|
||||
|
||||
**Solution:**
|
||||
```javascript
|
||||
// Always handle promises
|
||||
axios.get('/api/data')
|
||||
.catch(error => {
|
||||
// Handle error appropriately
|
||||
console.error('Request failed:', error.message);
|
||||
});
|
||||
|
||||
// Or use async/await with try/catch
|
||||
async function fetchData() {
|
||||
try {
|
||||
const response = await axios.get('/api/data');
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
console.error('Request failed:', error.message);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### Issue 2: Response Interceptors Not "Handling" Errors
|
||||
|
||||
**Problem:**
|
||||
```javascript
|
||||
// 0.x style - interceptor "handled" errors
|
||||
axios.interceptors.response.use(null, error => {
|
||||
showErrorMessage(error.message);
|
||||
// Error was considered "handled"
|
||||
});
|
||||
```
|
||||
|
||||
**Solution:**
|
||||
```javascript
|
||||
// 1.x style - explicitly control error propagation
|
||||
axios.interceptors.response.use(
|
||||
response => response,
|
||||
error => {
|
||||
showErrorMessage(error.message);
|
||||
|
||||
// Choose whether to propagate the error
|
||||
if (shouldPropagateError(error)) {
|
||||
return Promise.reject(error);
|
||||
}
|
||||
|
||||
// Return success-like response for "handled" errors
|
||||
return Promise.resolve({
|
||||
data: null,
|
||||
handled: true,
|
||||
error: normalizeError(error)
|
||||
});
|
||||
}
|
||||
);
|
||||
```
|
||||
|
||||
#### Issue 3: JSON Parsing Errors
|
||||
|
||||
**Problem:**
|
||||
```javascript
|
||||
// 1.x is stricter about JSON parsing
|
||||
// This might throw where 0.x was lenient
|
||||
const data = response.data;
|
||||
```
|
||||
|
||||
**Solution:**
|
||||
```javascript
|
||||
// Add response transformer for better error handling
|
||||
axios.defaults.transformResponse = [
|
||||
function (data) {
|
||||
if (typeof data === 'string') {
|
||||
try {
|
||||
return JSON.parse(data);
|
||||
} catch (e) {
|
||||
// Handle JSON parsing errors gracefully
|
||||
console.warn('Invalid JSON response:', data);
|
||||
return { error: 'Invalid JSON', rawData: data };
|
||||
}
|
||||
}
|
||||
return data;
|
||||
}
|
||||
];
|
||||
```
|
||||
|
||||
#### Issue 4: TypeScript Errors After Upgrade
|
||||
|
||||
**Problem:**
|
||||
```typescript
|
||||
// TypeScript errors after upgrade
|
||||
const response = await axios.get('/api/data');
|
||||
// Property 'someProperty' does not exist on type 'any'
|
||||
```
|
||||
|
||||
**Solution:**
|
||||
```typescript
|
||||
// Define proper interfaces
|
||||
interface ApiResponse {
|
||||
data: any;
|
||||
message: string;
|
||||
success: boolean;
|
||||
}
|
||||
|
||||
const response = await axios.get<ApiResponse>('/api/data');
|
||||
// Now properly typed
|
||||
console.log(response.data.data);
|
||||
```
|
||||
|
||||
### Debug Migration Issues
|
||||
|
||||
#### Enable Debug Logging
|
||||
```javascript
|
||||
// Add request/response logging
|
||||
axios.interceptors.request.use(config => {
|
||||
console.log('Request:', config);
|
||||
return config;
|
||||
});
|
||||
|
||||
axios.interceptors.response.use(
|
||||
response => {
|
||||
console.log('Response:', response);
|
||||
return response;
|
||||
},
|
||||
error => {
|
||||
console.log('Error:', error);
|
||||
return Promise.reject(error);
|
||||
}
|
||||
);
|
||||
```
|
||||
|
||||
#### Compare Behavior
|
||||
```javascript
|
||||
// Create side-by-side comparison during migration
|
||||
const axios0x = require('axios-0x'); // Keep old version for testing
|
||||
const axios1x = require('axios');
|
||||
|
||||
async function compareRequests(config) {
|
||||
try {
|
||||
const [result0x, result1x] = await Promise.allSettled([
|
||||
axios0x(config),
|
||||
axios1x(config)
|
||||
]);
|
||||
|
||||
console.log('0.x result:', result0x);
|
||||
console.log('1.x result:', result1x);
|
||||
} catch (error) {
|
||||
console.log('Comparison error:', error);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Resources
|
||||
|
||||
### Official Documentation
|
||||
- [Axios 1.x Documentation](https://axios-http.com/)
|
||||
- [Axios GitHub Repository](https://github.com/axios/axios)
|
||||
- [Axios Changelog](https://github.com/axios/axios/blob/main/CHANGELOG.md)
|
||||
|
||||
### Migration Tools
|
||||
- [Axios Migration Codemod](https://github.com/axios/axios-migration-codemod) *(if available)*
|
||||
- [ESLint Rules for Axios 1.x](https://github.com/axios/eslint-plugin-axios) *(if available)*
|
||||
|
||||
### Community Resources
|
||||
- [Stack Overflow - Axios Migration Questions](https://stackoverflow.com/questions/tagged/axios+migration)
|
||||
- [GitHub Discussions](https://github.com/axios/axios/discussions)
|
||||
- [Axios Discord Community](https://discord.gg/axios) *(if available)*
|
||||
|
||||
### Related Issues
|
||||
- [Error Handling Changes Discussion](https://github.com/axios/axios/issues/7208)
|
||||
- [Migration Guide Request](https://github.com/axios/axios/issues/xxxx) *(link to related issues)*
|
||||
|
||||
---
|
||||
|
||||
## Need Help?
|
||||
|
||||
If you encounter issues during migration that aren't covered in this guide:
|
||||
|
||||
1. **Search existing issues** in the [Axios GitHub repository](https://github.com/axios/axios/issues)
|
||||
2. **Ask questions** in [GitHub Discussions](https://github.com/axios/axios/discussions)
|
||||
3. **Contribute improvements** to this migration guide
|
||||
|
||||
---
|
||||
|
||||
*This migration guide is maintained by the community. If you find errors or have suggestions, please [open an issue](https://github.com/axios/axios/issues) or submit a pull request.*
|
||||
+1921
File diff suppressed because it is too large
Load Diff
+716
@@ -0,0 +1,716 @@
|
||||
interface RawAxiosHeaders {
|
||||
[key: string]: axios.AxiosHeaderValue;
|
||||
}
|
||||
|
||||
type MethodsHeaders = Partial<
|
||||
{
|
||||
[Key in axios.Method as Lowercase<Key>]: AxiosHeaders;
|
||||
} & { common: AxiosHeaders }
|
||||
>;
|
||||
|
||||
type AxiosHeaderMatcher =
|
||||
| string
|
||||
| RegExp
|
||||
| ((this: AxiosHeaders, value: string, name: string) => boolean);
|
||||
|
||||
type AxiosHeaderParser = (this: AxiosHeaders, value: axios.AxiosHeaderValue, header: string) => any;
|
||||
|
||||
type CommonRequestHeadersList =
|
||||
| 'Accept'
|
||||
| 'Content-Length'
|
||||
| 'User-Agent'
|
||||
| 'Content-Encoding'
|
||||
| 'Authorization';
|
||||
|
||||
type ContentType =
|
||||
| axios.AxiosHeaderValue
|
||||
| 'text/html'
|
||||
| 'text/plain'
|
||||
| 'multipart/form-data'
|
||||
| 'application/json'
|
||||
| 'application/x-www-form-urlencoded'
|
||||
| 'application/octet-stream';
|
||||
|
||||
type CommonResponseHeadersList =
|
||||
| 'Server'
|
||||
| 'Content-Type'
|
||||
| 'Content-Length'
|
||||
| 'Cache-Control'
|
||||
| 'Content-Encoding';
|
||||
|
||||
type BrowserProgressEvent = any;
|
||||
|
||||
declare class AxiosHeaders {
|
||||
constructor(headers?: RawAxiosHeaders | AxiosHeaders | string);
|
||||
|
||||
[key: string]: any;
|
||||
|
||||
set(
|
||||
headerName?: string,
|
||||
value?: axios.AxiosHeaderValue,
|
||||
rewrite?: boolean | AxiosHeaderMatcher
|
||||
): AxiosHeaders;
|
||||
set(headers?: RawAxiosHeaders | AxiosHeaders | string, rewrite?: boolean): AxiosHeaders;
|
||||
|
||||
get(headerName: string, parser: RegExp): RegExpExecArray | null;
|
||||
get(headerName: string, matcher?: true | AxiosHeaderParser): axios.AxiosHeaderValue;
|
||||
|
||||
has(header: string, matcher?: AxiosHeaderMatcher): boolean;
|
||||
|
||||
delete(header: string | string[], matcher?: AxiosHeaderMatcher): boolean;
|
||||
|
||||
clear(matcher?: AxiosHeaderMatcher): boolean;
|
||||
|
||||
normalize(format: boolean): AxiosHeaders;
|
||||
|
||||
concat(
|
||||
...targets: Array<AxiosHeaders | RawAxiosHeaders | string | undefined | null>
|
||||
): AxiosHeaders;
|
||||
|
||||
toJSON(asStrings?: boolean): RawAxiosHeaders;
|
||||
|
||||
static from(thing?: AxiosHeaders | RawAxiosHeaders | string): AxiosHeaders;
|
||||
|
||||
static accessor(header: string | string[]): AxiosHeaders;
|
||||
|
||||
static concat(
|
||||
...targets: Array<AxiosHeaders | RawAxiosHeaders | string | undefined | null>
|
||||
): AxiosHeaders;
|
||||
|
||||
setContentType(value: ContentType, rewrite?: boolean | AxiosHeaderMatcher): AxiosHeaders;
|
||||
getContentType(parser?: RegExp): RegExpExecArray | null;
|
||||
getContentType(matcher?: AxiosHeaderMatcher): axios.AxiosHeaderValue;
|
||||
hasContentType(matcher?: AxiosHeaderMatcher): boolean;
|
||||
|
||||
setContentLength(
|
||||
value: axios.AxiosHeaderValue,
|
||||
rewrite?: boolean | AxiosHeaderMatcher
|
||||
): AxiosHeaders;
|
||||
getContentLength(parser?: RegExp): RegExpExecArray | null;
|
||||
getContentLength(matcher?: AxiosHeaderMatcher): axios.AxiosHeaderValue;
|
||||
hasContentLength(matcher?: AxiosHeaderMatcher): boolean;
|
||||
|
||||
setAccept(value: axios.AxiosHeaderValue, rewrite?: boolean | AxiosHeaderMatcher): AxiosHeaders;
|
||||
getAccept(parser?: RegExp): RegExpExecArray | null;
|
||||
getAccept(matcher?: AxiosHeaderMatcher): axios.AxiosHeaderValue;
|
||||
hasAccept(matcher?: AxiosHeaderMatcher): boolean;
|
||||
|
||||
setUserAgent(value: axios.AxiosHeaderValue, rewrite?: boolean | AxiosHeaderMatcher): AxiosHeaders;
|
||||
getUserAgent(parser?: RegExp): RegExpExecArray | null;
|
||||
getUserAgent(matcher?: AxiosHeaderMatcher): axios.AxiosHeaderValue;
|
||||
hasUserAgent(matcher?: AxiosHeaderMatcher): boolean;
|
||||
|
||||
setContentEncoding(
|
||||
value: axios.AxiosHeaderValue,
|
||||
rewrite?: boolean | AxiosHeaderMatcher
|
||||
): AxiosHeaders;
|
||||
getContentEncoding(parser?: RegExp): RegExpExecArray | null;
|
||||
getContentEncoding(matcher?: AxiosHeaderMatcher): axios.AxiosHeaderValue;
|
||||
hasContentEncoding(matcher?: AxiosHeaderMatcher): boolean;
|
||||
|
||||
setAuthorization(
|
||||
value: axios.AxiosHeaderValue,
|
||||
rewrite?: boolean | AxiosHeaderMatcher
|
||||
): AxiosHeaders;
|
||||
getAuthorization(parser?: RegExp): RegExpExecArray | null;
|
||||
getAuthorization(matcher?: AxiosHeaderMatcher): axios.AxiosHeaderValue;
|
||||
hasAuthorization(matcher?: AxiosHeaderMatcher): boolean;
|
||||
|
||||
getSetCookie(): string[];
|
||||
|
||||
[Symbol.iterator](): IterableIterator<[string, axios.AxiosHeaderValue]>;
|
||||
}
|
||||
|
||||
declare class AxiosError<T = unknown, D = any> extends Error {
|
||||
constructor(
|
||||
message?: string,
|
||||
code?: string,
|
||||
config?: axios.InternalAxiosRequestConfig<D>,
|
||||
request?: any,
|
||||
response?: axios.AxiosResponse<T, D>
|
||||
);
|
||||
|
||||
config?: axios.InternalAxiosRequestConfig<D>;
|
||||
code?: string;
|
||||
request?: any;
|
||||
response?: axios.AxiosResponse<T, D>;
|
||||
isAxiosError: boolean;
|
||||
status?: number;
|
||||
toJSON: () => object;
|
||||
cause?: Error;
|
||||
event?: BrowserProgressEvent;
|
||||
static from<T = unknown, D = any>(
|
||||
error: Error | unknown,
|
||||
code?: string,
|
||||
config?: axios.InternalAxiosRequestConfig<D>,
|
||||
request?: any,
|
||||
response?: axios.AxiosResponse<T, D>,
|
||||
customProps?: object
|
||||
): AxiosError<T, D>;
|
||||
static readonly ERR_FR_TOO_MANY_REDIRECTS = 'ERR_FR_TOO_MANY_REDIRECTS';
|
||||
static readonly ERR_BAD_OPTION_VALUE = 'ERR_BAD_OPTION_VALUE';
|
||||
static readonly ERR_BAD_OPTION = 'ERR_BAD_OPTION';
|
||||
static readonly ERR_NETWORK = 'ERR_NETWORK';
|
||||
static readonly ERR_DEPRECATED = 'ERR_DEPRECATED';
|
||||
static readonly ERR_BAD_RESPONSE = 'ERR_BAD_RESPONSE';
|
||||
static readonly ERR_BAD_REQUEST = 'ERR_BAD_REQUEST';
|
||||
static readonly ERR_NOT_SUPPORT = 'ERR_NOT_SUPPORT';
|
||||
static readonly ERR_INVALID_URL = 'ERR_INVALID_URL';
|
||||
static readonly ERR_CANCELED = 'ERR_CANCELED';
|
||||
static readonly ECONNABORTED = 'ECONNABORTED';
|
||||
static readonly ETIMEDOUT = 'ETIMEDOUT';
|
||||
}
|
||||
|
||||
declare class CanceledError<T> extends AxiosError<T> {}
|
||||
|
||||
declare class Axios {
|
||||
constructor(config?: axios.AxiosRequestConfig);
|
||||
defaults: axios.AxiosDefaults;
|
||||
interceptors: {
|
||||
request: axios.AxiosInterceptorManager<axios.InternalAxiosRequestConfig>;
|
||||
response: axios.AxiosInterceptorManager<axios.AxiosResponse>;
|
||||
};
|
||||
getUri(config?: axios.AxiosRequestConfig): string;
|
||||
request<T = any, R = axios.AxiosResponse<T>, D = any>(
|
||||
config: axios.AxiosRequestConfig<D>
|
||||
): Promise<R>;
|
||||
get<T = any, R = axios.AxiosResponse<T>, D = any>(
|
||||
url: string,
|
||||
config?: axios.AxiosRequestConfig<D>
|
||||
): Promise<R>;
|
||||
delete<T = any, R = axios.AxiosResponse<T>, D = any>(
|
||||
url: string,
|
||||
config?: axios.AxiosRequestConfig<D>
|
||||
): Promise<R>;
|
||||
head<T = any, R = axios.AxiosResponse<T>, D = any>(
|
||||
url: string,
|
||||
config?: axios.AxiosRequestConfig<D>
|
||||
): Promise<R>;
|
||||
options<T = any, R = axios.AxiosResponse<T>, D = any>(
|
||||
url: string,
|
||||
config?: axios.AxiosRequestConfig<D>
|
||||
): Promise<R>;
|
||||
post<T = any, R = axios.AxiosResponse<T>, D = any>(
|
||||
url: string,
|
||||
data?: D,
|
||||
config?: axios.AxiosRequestConfig<D>
|
||||
): Promise<R>;
|
||||
put<T = any, R = axios.AxiosResponse<T>, D = any>(
|
||||
url: string,
|
||||
data?: D,
|
||||
config?: axios.AxiosRequestConfig<D>
|
||||
): Promise<R>;
|
||||
patch<T = any, R = axios.AxiosResponse<T>, D = any>(
|
||||
url: string,
|
||||
data?: D,
|
||||
config?: axios.AxiosRequestConfig<D>
|
||||
): Promise<R>;
|
||||
postForm<T = any, R = axios.AxiosResponse<T>, D = any>(
|
||||
url: string,
|
||||
data?: D,
|
||||
config?: axios.AxiosRequestConfig<D>
|
||||
): Promise<R>;
|
||||
putForm<T = any, R = axios.AxiosResponse<T>, D = any>(
|
||||
url: string,
|
||||
data?: D,
|
||||
config?: axios.AxiosRequestConfig<D>
|
||||
): Promise<R>;
|
||||
patchForm<T = any, R = axios.AxiosResponse<T>, D = any>(
|
||||
url: string,
|
||||
data?: D,
|
||||
config?: axios.AxiosRequestConfig<D>
|
||||
): Promise<R>;
|
||||
}
|
||||
|
||||
declare enum HttpStatusCode {
|
||||
Continue = 100,
|
||||
SwitchingProtocols = 101,
|
||||
Processing = 102,
|
||||
EarlyHints = 103,
|
||||
Ok = 200,
|
||||
Created = 201,
|
||||
Accepted = 202,
|
||||
NonAuthoritativeInformation = 203,
|
||||
NoContent = 204,
|
||||
ResetContent = 205,
|
||||
PartialContent = 206,
|
||||
MultiStatus = 207,
|
||||
AlreadyReported = 208,
|
||||
ImUsed = 226,
|
||||
MultipleChoices = 300,
|
||||
MovedPermanently = 301,
|
||||
Found = 302,
|
||||
SeeOther = 303,
|
||||
NotModified = 304,
|
||||
UseProxy = 305,
|
||||
Unused = 306,
|
||||
TemporaryRedirect = 307,
|
||||
PermanentRedirect = 308,
|
||||
BadRequest = 400,
|
||||
Unauthorized = 401,
|
||||
PaymentRequired = 402,
|
||||
Forbidden = 403,
|
||||
NotFound = 404,
|
||||
MethodNotAllowed = 405,
|
||||
NotAcceptable = 406,
|
||||
ProxyAuthenticationRequired = 407,
|
||||
RequestTimeout = 408,
|
||||
Conflict = 409,
|
||||
Gone = 410,
|
||||
LengthRequired = 411,
|
||||
PreconditionFailed = 412,
|
||||
PayloadTooLarge = 413,
|
||||
UriTooLong = 414,
|
||||
UnsupportedMediaType = 415,
|
||||
RangeNotSatisfiable = 416,
|
||||
ExpectationFailed = 417,
|
||||
ImATeapot = 418,
|
||||
MisdirectedRequest = 421,
|
||||
UnprocessableEntity = 422,
|
||||
Locked = 423,
|
||||
FailedDependency = 424,
|
||||
TooEarly = 425,
|
||||
UpgradeRequired = 426,
|
||||
PreconditionRequired = 428,
|
||||
TooManyRequests = 429,
|
||||
RequestHeaderFieldsTooLarge = 431,
|
||||
UnavailableForLegalReasons = 451,
|
||||
InternalServerError = 500,
|
||||
NotImplemented = 501,
|
||||
BadGateway = 502,
|
||||
ServiceUnavailable = 503,
|
||||
GatewayTimeout = 504,
|
||||
HttpVersionNotSupported = 505,
|
||||
VariantAlsoNegotiates = 506,
|
||||
InsufficientStorage = 507,
|
||||
LoopDetected = 508,
|
||||
NotExtended = 510,
|
||||
NetworkAuthenticationRequired = 511,
|
||||
}
|
||||
|
||||
type InternalAxiosError<T = unknown, D = any> = AxiosError<T, D>;
|
||||
|
||||
declare namespace axios {
|
||||
type AxiosError<T = unknown, D = any> = InternalAxiosError<T, D>;
|
||||
|
||||
type RawAxiosRequestHeaders = Partial<
|
||||
RawAxiosHeaders & {
|
||||
[Key in CommonRequestHeadersList]: AxiosHeaderValue;
|
||||
} & {
|
||||
'Content-Type': ContentType;
|
||||
}
|
||||
>;
|
||||
|
||||
type AxiosRequestHeaders = RawAxiosRequestHeaders & AxiosHeaders;
|
||||
|
||||
type AxiosHeaderValue = AxiosHeaders | string | string[] | number | boolean | null;
|
||||
|
||||
type RawCommonResponseHeaders = {
|
||||
[Key in CommonResponseHeadersList]: AxiosHeaderValue;
|
||||
} & {
|
||||
'set-cookie': string[];
|
||||
};
|
||||
|
||||
type RawAxiosResponseHeaders = Partial<RawAxiosHeaders & RawCommonResponseHeaders>;
|
||||
|
||||
type AxiosResponseHeaders = RawAxiosResponseHeaders & AxiosHeaders;
|
||||
|
||||
interface AxiosRequestTransformer {
|
||||
(this: InternalAxiosRequestConfig, data: any, headers: AxiosRequestHeaders): any;
|
||||
}
|
||||
|
||||
interface AxiosResponseTransformer {
|
||||
(
|
||||
this: InternalAxiosRequestConfig,
|
||||
data: any,
|
||||
headers: AxiosResponseHeaders,
|
||||
status?: number
|
||||
): any;
|
||||
}
|
||||
|
||||
interface AxiosAdapter {
|
||||
(config: InternalAxiosRequestConfig): AxiosPromise;
|
||||
}
|
||||
|
||||
interface AxiosBasicCredentials {
|
||||
username: string;
|
||||
password: string;
|
||||
}
|
||||
|
||||
interface AxiosProxyConfig {
|
||||
host: string;
|
||||
port: number;
|
||||
auth?: AxiosBasicCredentials;
|
||||
protocol?: string;
|
||||
}
|
||||
|
||||
type Method =
|
||||
| 'get'
|
||||
| 'GET'
|
||||
| 'delete'
|
||||
| 'DELETE'
|
||||
| 'head'
|
||||
| 'HEAD'
|
||||
| 'options'
|
||||
| 'OPTIONS'
|
||||
| 'post'
|
||||
| 'POST'
|
||||
| 'put'
|
||||
| 'PUT'
|
||||
| 'patch'
|
||||
| 'PATCH'
|
||||
| 'purge'
|
||||
| 'PURGE'
|
||||
| 'link'
|
||||
| 'LINK'
|
||||
| 'unlink'
|
||||
| 'UNLINK';
|
||||
|
||||
type ResponseType = 'arraybuffer' | 'blob' | 'document' | 'json' | 'text' | 'stream' | 'formdata';
|
||||
|
||||
type responseEncoding =
|
||||
| 'ascii'
|
||||
| 'ASCII'
|
||||
| 'ansi'
|
||||
| 'ANSI'
|
||||
| 'binary'
|
||||
| 'BINARY'
|
||||
| 'base64'
|
||||
| 'BASE64'
|
||||
| 'base64url'
|
||||
| 'BASE64URL'
|
||||
| 'hex'
|
||||
| 'HEX'
|
||||
| 'latin1'
|
||||
| 'LATIN1'
|
||||
| 'ucs-2'
|
||||
| 'UCS-2'
|
||||
| 'ucs2'
|
||||
| 'UCS2'
|
||||
| 'utf-8'
|
||||
| 'UTF-8'
|
||||
| 'utf8'
|
||||
| 'UTF8'
|
||||
| 'utf16le'
|
||||
| 'UTF16LE';
|
||||
|
||||
interface TransitionalOptions {
|
||||
silentJSONParsing?: boolean;
|
||||
forcedJSONParsing?: boolean;
|
||||
clarifyTimeoutError?: boolean;
|
||||
legacyInterceptorReqResOrdering?: boolean;
|
||||
}
|
||||
|
||||
interface GenericAbortSignal {
|
||||
readonly aborted: boolean;
|
||||
onabort?: ((...args: any) => any) | null;
|
||||
addEventListener?: (...args: any) => any;
|
||||
removeEventListener?: (...args: any) => any;
|
||||
}
|
||||
|
||||
interface FormDataVisitorHelpers {
|
||||
defaultVisitor: SerializerVisitor;
|
||||
convertValue: (value: any) => any;
|
||||
isVisitable: (value: any) => boolean;
|
||||
}
|
||||
|
||||
interface SerializerVisitor {
|
||||
(
|
||||
this: GenericFormData,
|
||||
value: any,
|
||||
key: string | number,
|
||||
path: null | Array<string | number>,
|
||||
helpers: FormDataVisitorHelpers
|
||||
): boolean;
|
||||
}
|
||||
|
||||
interface SerializerOptions {
|
||||
visitor?: SerializerVisitor;
|
||||
dots?: boolean;
|
||||
metaTokens?: boolean;
|
||||
indexes?: boolean | null;
|
||||
}
|
||||
|
||||
// tslint:disable-next-line
|
||||
interface FormSerializerOptions extends SerializerOptions {}
|
||||
|
||||
interface ParamEncoder {
|
||||
(value: any, defaultEncoder: (value: any) => any): any;
|
||||
}
|
||||
|
||||
interface CustomParamsSerializer {
|
||||
(params: Record<string, any>, options?: ParamsSerializerOptions): string;
|
||||
}
|
||||
|
||||
interface ParamsSerializerOptions extends SerializerOptions {
|
||||
encode?: ParamEncoder;
|
||||
serialize?: CustomParamsSerializer;
|
||||
}
|
||||
|
||||
type MaxUploadRate = number;
|
||||
|
||||
type MaxDownloadRate = number;
|
||||
|
||||
interface AxiosProgressEvent {
|
||||
loaded: number;
|
||||
total?: number;
|
||||
progress?: number;
|
||||
bytes: number;
|
||||
rate?: number;
|
||||
estimated?: number;
|
||||
upload?: boolean;
|
||||
download?: boolean;
|
||||
event?: BrowserProgressEvent;
|
||||
lengthComputable: boolean;
|
||||
}
|
||||
|
||||
type Milliseconds = number;
|
||||
|
||||
type AxiosAdapterName = 'fetch' | 'xhr' | 'http' | (string & {});
|
||||
|
||||
type AxiosAdapterConfig = AxiosAdapter | AxiosAdapterName;
|
||||
|
||||
type AddressFamily = 4 | 6 | undefined;
|
||||
|
||||
interface LookupAddressEntry {
|
||||
address: string;
|
||||
family?: AddressFamily;
|
||||
}
|
||||
|
||||
type LookupAddress = string | LookupAddressEntry;
|
||||
|
||||
interface AxiosRequestConfig<D = any> {
|
||||
url?: string;
|
||||
method?: Method | string;
|
||||
baseURL?: string;
|
||||
allowAbsoluteUrls?: boolean;
|
||||
transformRequest?: AxiosRequestTransformer | AxiosRequestTransformer[];
|
||||
transformResponse?: AxiosResponseTransformer | AxiosResponseTransformer[];
|
||||
headers?: (RawAxiosRequestHeaders & MethodsHeaders) | AxiosHeaders;
|
||||
params?: any;
|
||||
paramsSerializer?: ParamsSerializerOptions | CustomParamsSerializer;
|
||||
data?: D;
|
||||
timeout?: Milliseconds;
|
||||
timeoutErrorMessage?: string;
|
||||
withCredentials?: boolean;
|
||||
adapter?: AxiosAdapterConfig | AxiosAdapterConfig[];
|
||||
auth?: AxiosBasicCredentials;
|
||||
responseType?: ResponseType;
|
||||
responseEncoding?: responseEncoding | string;
|
||||
xsrfCookieName?: string;
|
||||
xsrfHeaderName?: string;
|
||||
onUploadProgress?: (progressEvent: AxiosProgressEvent) => void;
|
||||
onDownloadProgress?: (progressEvent: AxiosProgressEvent) => void;
|
||||
maxContentLength?: number;
|
||||
validateStatus?: ((status: number) => boolean) | null;
|
||||
maxBodyLength?: number;
|
||||
maxRedirects?: number;
|
||||
maxRate?: number | [MaxUploadRate, MaxDownloadRate];
|
||||
beforeRedirect?: (
|
||||
options: Record<string, any>,
|
||||
responseDetails: { headers: Record<string, string>; statusCode: HttpStatusCode }
|
||||
) => void;
|
||||
socketPath?: string | null;
|
||||
transport?: any;
|
||||
httpAgent?: any;
|
||||
httpsAgent?: any;
|
||||
proxy?: AxiosProxyConfig | false;
|
||||
cancelToken?: CancelToken;
|
||||
decompress?: boolean;
|
||||
transitional?: TransitionalOptions;
|
||||
signal?: GenericAbortSignal;
|
||||
insecureHTTPParser?: boolean;
|
||||
env?: {
|
||||
FormData?: new (...args: any[]) => object;
|
||||
fetch?: (input: URL | Request | string, init?: RequestInit) => Promise<Response>;
|
||||
Request?: new (input: URL | Request | string, init?: RequestInit) => Request;
|
||||
Response?: new (
|
||||
body?: ArrayBuffer | ArrayBufferView | Blob | FormData | URLSearchParams | string | null,
|
||||
init?: ResponseInit
|
||||
) => Response;
|
||||
};
|
||||
formSerializer?: FormSerializerOptions;
|
||||
family?: AddressFamily;
|
||||
lookup?:
|
||||
| ((
|
||||
hostname: string,
|
||||
options: object,
|
||||
cb: (
|
||||
err: Error | null,
|
||||
address: LookupAddress | LookupAddress[],
|
||||
family?: AddressFamily
|
||||
) => void
|
||||
) => void)
|
||||
| ((
|
||||
hostname: string,
|
||||
options: object
|
||||
) => Promise<
|
||||
| [address: LookupAddressEntry | LookupAddressEntry[], family?: AddressFamily]
|
||||
| LookupAddress
|
||||
>);
|
||||
withXSRFToken?: boolean | ((config: InternalAxiosRequestConfig) => boolean | undefined);
|
||||
fetchOptions?:
|
||||
| Omit<RequestInit, 'body' | 'headers' | 'method' | 'signal'>
|
||||
| Record<string, any>;
|
||||
httpVersion?: 1 | 2;
|
||||
http2Options?: Record<string, any> & {
|
||||
sessionTimeout?: number;
|
||||
};
|
||||
}
|
||||
|
||||
// Alias
|
||||
type RawAxiosRequestConfig<D = any> = AxiosRequestConfig<D>;
|
||||
|
||||
interface InternalAxiosRequestConfig<D = any> extends AxiosRequestConfig<D> {
|
||||
headers: AxiosRequestHeaders;
|
||||
}
|
||||
|
||||
interface HeadersDefaults {
|
||||
common: RawAxiosRequestHeaders;
|
||||
delete: RawAxiosRequestHeaders;
|
||||
get: RawAxiosRequestHeaders;
|
||||
head: RawAxiosRequestHeaders;
|
||||
post: RawAxiosRequestHeaders;
|
||||
put: RawAxiosRequestHeaders;
|
||||
patch: RawAxiosRequestHeaders;
|
||||
options?: RawAxiosRequestHeaders;
|
||||
purge?: RawAxiosRequestHeaders;
|
||||
link?: RawAxiosRequestHeaders;
|
||||
unlink?: RawAxiosRequestHeaders;
|
||||
}
|
||||
|
||||
interface AxiosDefaults<D = any> extends Omit<AxiosRequestConfig<D>, 'headers'> {
|
||||
headers: HeadersDefaults;
|
||||
}
|
||||
|
||||
interface CreateAxiosDefaults<D = any> extends Omit<AxiosRequestConfig<D>, 'headers'> {
|
||||
headers?: RawAxiosRequestHeaders | AxiosHeaders | Partial<HeadersDefaults>;
|
||||
}
|
||||
|
||||
interface AxiosResponse<T = any, D = any, H = {}> {
|
||||
data: T;
|
||||
status: number;
|
||||
statusText: string;
|
||||
headers: (H & RawAxiosResponseHeaders) | AxiosResponseHeaders;
|
||||
config: InternalAxiosRequestConfig<D>;
|
||||
request?: any;
|
||||
}
|
||||
|
||||
type AxiosPromise<T = any> = Promise<AxiosResponse<T>>;
|
||||
|
||||
interface CancelStatic {
|
||||
new (message?: string): Cancel;
|
||||
}
|
||||
|
||||
interface Cancel {
|
||||
message: string | undefined;
|
||||
}
|
||||
|
||||
interface Canceler {
|
||||
(message?: string, config?: AxiosRequestConfig, request?: any): void;
|
||||
}
|
||||
|
||||
interface CancelTokenStatic {
|
||||
new (executor: (cancel: Canceler) => void): CancelToken;
|
||||
source(): CancelTokenSource;
|
||||
}
|
||||
|
||||
interface CancelToken {
|
||||
promise: Promise<Cancel>;
|
||||
reason?: Cancel;
|
||||
throwIfRequested(): void;
|
||||
}
|
||||
|
||||
interface CancelTokenSource {
|
||||
token: CancelToken;
|
||||
cancel: Canceler;
|
||||
}
|
||||
|
||||
interface AxiosInterceptorOptions {
|
||||
synchronous?: boolean;
|
||||
runWhen?: (config: InternalAxiosRequestConfig) => boolean;
|
||||
}
|
||||
|
||||
type AxiosInterceptorFulfilled<T> = (value: T) => T | Promise<T>;
|
||||
type AxiosInterceptorRejected = (error: any) => any;
|
||||
|
||||
type AxiosRequestInterceptorUse<T> = (
|
||||
onFulfilled?: AxiosInterceptorFulfilled<T> | null,
|
||||
onRejected?: AxiosInterceptorRejected | null,
|
||||
options?: AxiosInterceptorOptions
|
||||
) => number;
|
||||
|
||||
type AxiosResponseInterceptorUse<T> = (
|
||||
onFulfilled?: AxiosInterceptorFulfilled<T> | null,
|
||||
onRejected?: AxiosInterceptorRejected | null
|
||||
) => number;
|
||||
|
||||
interface AxiosInterceptorHandler<T> {
|
||||
fulfilled: AxiosInterceptorFulfilled<T>;
|
||||
rejected?: AxiosInterceptorRejected;
|
||||
synchronous: boolean;
|
||||
runWhen?: (config: AxiosRequestConfig) => boolean;
|
||||
}
|
||||
|
||||
interface AxiosInterceptorManager<V> {
|
||||
use: V extends AxiosResponse ? AxiosResponseInterceptorUse<V> : AxiosRequestInterceptorUse<V>;
|
||||
eject(id: number): void;
|
||||
clear(): void;
|
||||
handlers?: Array<AxiosInterceptorHandler<V>>;
|
||||
}
|
||||
|
||||
interface AxiosInstance extends Axios {
|
||||
<T = any, R = AxiosResponse<T>, D = any>(config: AxiosRequestConfig<D>): Promise<R>;
|
||||
<T = any, R = AxiosResponse<T>, D = any>(
|
||||
url: string,
|
||||
config?: AxiosRequestConfig<D>
|
||||
): Promise<R>;
|
||||
|
||||
create(config?: CreateAxiosDefaults): AxiosInstance;
|
||||
defaults: Omit<AxiosDefaults, 'headers'> & {
|
||||
headers: HeadersDefaults & {
|
||||
[key: string]: AxiosHeaderValue;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
interface GenericFormData {
|
||||
append(name: string, value: any, options?: any): any;
|
||||
}
|
||||
|
||||
interface GenericHTMLFormElement {
|
||||
name: string;
|
||||
method: string;
|
||||
submit(): void;
|
||||
}
|
||||
|
||||
interface AxiosStatic extends AxiosInstance {
|
||||
Cancel: CancelStatic;
|
||||
CancelToken: CancelTokenStatic;
|
||||
Axios: typeof Axios;
|
||||
AxiosError: typeof AxiosError;
|
||||
CanceledError: typeof CanceledError;
|
||||
HttpStatusCode: typeof HttpStatusCode;
|
||||
readonly VERSION: string;
|
||||
isCancel(value: any): value is Cancel;
|
||||
all<T>(values: Array<T | Promise<T>>): Promise<T[]>;
|
||||
spread<T, R>(callback: (...args: T[]) => R): (array: T[]) => R;
|
||||
isAxiosError<T = any, D = any>(payload: any): payload is AxiosError<T, D>;
|
||||
toFormData(
|
||||
sourceObj: object,
|
||||
targetFormData?: GenericFormData,
|
||||
options?: FormSerializerOptions
|
||||
): GenericFormData;
|
||||
formToJSON(form: GenericFormData | GenericHTMLFormElement): object;
|
||||
getAdapter(adapters: AxiosAdapterConfig | AxiosAdapterConfig[] | undefined): AxiosAdapter;
|
||||
AxiosHeaders: typeof AxiosHeaders;
|
||||
mergeConfig<D = any>(
|
||||
config1: AxiosRequestConfig<D>,
|
||||
config2: AxiosRequestConfig<D>
|
||||
): AxiosRequestConfig<D>;
|
||||
}
|
||||
}
|
||||
|
||||
declare const axios: axios.AxiosStatic;
|
||||
|
||||
export = axios;
|
||||
+810
@@ -0,0 +1,810 @@
|
||||
// TypeScript Version: 4.7
|
||||
type StringLiteralsOrString<Literals extends string> = Literals | (string & {});
|
||||
|
||||
export type AxiosHeaderValue =
|
||||
| AxiosHeaders
|
||||
| string
|
||||
| string[]
|
||||
| number
|
||||
| boolean
|
||||
| null;
|
||||
|
||||
interface RawAxiosHeaders {
|
||||
[key: string]: AxiosHeaderValue;
|
||||
}
|
||||
|
||||
type MethodsHeaders = Partial<
|
||||
{
|
||||
[Key in Method as Lowercase<Key>]: AxiosHeaders;
|
||||
} & { common: AxiosHeaders }
|
||||
>;
|
||||
|
||||
type AxiosHeaderMatcher =
|
||||
| string
|
||||
| RegExp
|
||||
| ((this: AxiosHeaders, value: string, name: string) => boolean);
|
||||
|
||||
type AxiosHeaderParser = (
|
||||
this: AxiosHeaders,
|
||||
value: AxiosHeaderValue,
|
||||
header: string,
|
||||
) => any;
|
||||
|
||||
export class AxiosHeaders {
|
||||
constructor(headers?: RawAxiosHeaders | AxiosHeaders | string);
|
||||
|
||||
[key: string]: any;
|
||||
|
||||
set(
|
||||
headerName?: string,
|
||||
value?: AxiosHeaderValue,
|
||||
rewrite?: boolean | AxiosHeaderMatcher,
|
||||
): AxiosHeaders;
|
||||
set(
|
||||
headers?: RawAxiosHeaders | AxiosHeaders | string,
|
||||
rewrite?: boolean,
|
||||
): AxiosHeaders;
|
||||
|
||||
get(headerName: string, parser: RegExp): RegExpExecArray | null;
|
||||
get(headerName: string, matcher?: true | AxiosHeaderParser): AxiosHeaderValue;
|
||||
|
||||
has(header: string, matcher?: AxiosHeaderMatcher): boolean;
|
||||
|
||||
delete(header: string | string[], matcher?: AxiosHeaderMatcher): boolean;
|
||||
|
||||
clear(matcher?: AxiosHeaderMatcher): boolean;
|
||||
|
||||
normalize(format: boolean): AxiosHeaders;
|
||||
|
||||
concat(
|
||||
...targets: Array<
|
||||
AxiosHeaders | RawAxiosHeaders | string | undefined | null
|
||||
>
|
||||
): AxiosHeaders;
|
||||
|
||||
toJSON(asStrings?: boolean): RawAxiosHeaders;
|
||||
|
||||
static from(thing?: AxiosHeaders | RawAxiosHeaders | string): AxiosHeaders;
|
||||
|
||||
static accessor(header: string | string[]): AxiosHeaders;
|
||||
|
||||
static concat(
|
||||
...targets: Array<
|
||||
AxiosHeaders | RawAxiosHeaders | string | undefined | null
|
||||
>
|
||||
): AxiosHeaders;
|
||||
|
||||
setContentType(
|
||||
value: ContentType,
|
||||
rewrite?: boolean | AxiosHeaderMatcher,
|
||||
): AxiosHeaders;
|
||||
getContentType(parser?: RegExp): RegExpExecArray | null;
|
||||
getContentType(matcher?: AxiosHeaderMatcher): AxiosHeaderValue;
|
||||
hasContentType(matcher?: AxiosHeaderMatcher): boolean;
|
||||
|
||||
setContentLength(
|
||||
value: AxiosHeaderValue,
|
||||
rewrite?: boolean | AxiosHeaderMatcher,
|
||||
): AxiosHeaders;
|
||||
getContentLength(parser?: RegExp): RegExpExecArray | null;
|
||||
getContentLength(matcher?: AxiosHeaderMatcher): AxiosHeaderValue;
|
||||
hasContentLength(matcher?: AxiosHeaderMatcher): boolean;
|
||||
|
||||
setAccept(
|
||||
value: AxiosHeaderValue,
|
||||
rewrite?: boolean | AxiosHeaderMatcher,
|
||||
): AxiosHeaders;
|
||||
getAccept(parser?: RegExp): RegExpExecArray | null;
|
||||
getAccept(matcher?: AxiosHeaderMatcher): AxiosHeaderValue;
|
||||
hasAccept(matcher?: AxiosHeaderMatcher): boolean;
|
||||
|
||||
setUserAgent(
|
||||
value: AxiosHeaderValue,
|
||||
rewrite?: boolean | AxiosHeaderMatcher,
|
||||
): AxiosHeaders;
|
||||
getUserAgent(parser?: RegExp): RegExpExecArray | null;
|
||||
getUserAgent(matcher?: AxiosHeaderMatcher): AxiosHeaderValue;
|
||||
hasUserAgent(matcher?: AxiosHeaderMatcher): boolean;
|
||||
|
||||
setContentEncoding(
|
||||
value: AxiosHeaderValue,
|
||||
rewrite?: boolean | AxiosHeaderMatcher,
|
||||
): AxiosHeaders;
|
||||
getContentEncoding(parser?: RegExp): RegExpExecArray | null;
|
||||
getContentEncoding(matcher?: AxiosHeaderMatcher): AxiosHeaderValue;
|
||||
hasContentEncoding(matcher?: AxiosHeaderMatcher): boolean;
|
||||
|
||||
setAuthorization(
|
||||
value: AxiosHeaderValue,
|
||||
rewrite?: boolean | AxiosHeaderMatcher,
|
||||
): AxiosHeaders;
|
||||
getAuthorization(parser?: RegExp): RegExpExecArray | null;
|
||||
getAuthorization(matcher?: AxiosHeaderMatcher): AxiosHeaderValue;
|
||||
hasAuthorization(matcher?: AxiosHeaderMatcher): boolean;
|
||||
|
||||
getSetCookie(): string[];
|
||||
|
||||
[Symbol.iterator](): IterableIterator<[string, AxiosHeaderValue]>;
|
||||
}
|
||||
|
||||
type CommonRequestHeadersList =
|
||||
| "Accept"
|
||||
| "Content-Length"
|
||||
| "User-Agent"
|
||||
| "Content-Encoding"
|
||||
| "Authorization";
|
||||
|
||||
type ContentType =
|
||||
| AxiosHeaderValue
|
||||
| "text/html"
|
||||
| "text/plain"
|
||||
| "multipart/form-data"
|
||||
| "application/json"
|
||||
| "application/x-www-form-urlencoded"
|
||||
| "application/octet-stream";
|
||||
|
||||
export type RawAxiosRequestHeaders = Partial<
|
||||
RawAxiosHeaders & {
|
||||
[Key in CommonRequestHeadersList]: AxiosHeaderValue;
|
||||
} & {
|
||||
"Content-Type": ContentType;
|
||||
}
|
||||
>;
|
||||
|
||||
export type AxiosRequestHeaders = RawAxiosRequestHeaders & AxiosHeaders;
|
||||
|
||||
type CommonResponseHeadersList =
|
||||
| "Server"
|
||||
| "Content-Type"
|
||||
| "Content-Length"
|
||||
| "Cache-Control"
|
||||
| "Content-Encoding";
|
||||
|
||||
type RawCommonResponseHeaders = {
|
||||
[Key in CommonResponseHeadersList]: AxiosHeaderValue;
|
||||
} & {
|
||||
"set-cookie": string[];
|
||||
};
|
||||
|
||||
export type RawAxiosResponseHeaders = Partial<
|
||||
RawAxiosHeaders & RawCommonResponseHeaders
|
||||
>;
|
||||
|
||||
export type AxiosResponseHeaders = RawAxiosResponseHeaders & AxiosHeaders;
|
||||
|
||||
export interface AxiosRequestTransformer {
|
||||
(
|
||||
this: InternalAxiosRequestConfig,
|
||||
data: any,
|
||||
headers: AxiosRequestHeaders,
|
||||
): any;
|
||||
}
|
||||
|
||||
export interface AxiosResponseTransformer {
|
||||
(
|
||||
this: InternalAxiosRequestConfig,
|
||||
data: any,
|
||||
headers: AxiosResponseHeaders,
|
||||
status?: number,
|
||||
): any;
|
||||
}
|
||||
|
||||
export interface AxiosAdapter {
|
||||
(config: InternalAxiosRequestConfig): AxiosPromise;
|
||||
}
|
||||
|
||||
export interface AxiosBasicCredentials {
|
||||
username: string;
|
||||
password: string;
|
||||
}
|
||||
|
||||
export interface AxiosProxyConfig {
|
||||
host: string;
|
||||
port: number;
|
||||
auth?: AxiosBasicCredentials;
|
||||
protocol?: string;
|
||||
}
|
||||
|
||||
export enum HttpStatusCode {
|
||||
Continue = 100,
|
||||
SwitchingProtocols = 101,
|
||||
Processing = 102,
|
||||
EarlyHints = 103,
|
||||
Ok = 200,
|
||||
Created = 201,
|
||||
Accepted = 202,
|
||||
NonAuthoritativeInformation = 203,
|
||||
NoContent = 204,
|
||||
ResetContent = 205,
|
||||
PartialContent = 206,
|
||||
MultiStatus = 207,
|
||||
AlreadyReported = 208,
|
||||
ImUsed = 226,
|
||||
MultipleChoices = 300,
|
||||
MovedPermanently = 301,
|
||||
Found = 302,
|
||||
SeeOther = 303,
|
||||
NotModified = 304,
|
||||
UseProxy = 305,
|
||||
Unused = 306,
|
||||
TemporaryRedirect = 307,
|
||||
PermanentRedirect = 308,
|
||||
BadRequest = 400,
|
||||
Unauthorized = 401,
|
||||
PaymentRequired = 402,
|
||||
Forbidden = 403,
|
||||
NotFound = 404,
|
||||
MethodNotAllowed = 405,
|
||||
NotAcceptable = 406,
|
||||
ProxyAuthenticationRequired = 407,
|
||||
RequestTimeout = 408,
|
||||
Conflict = 409,
|
||||
Gone = 410,
|
||||
LengthRequired = 411,
|
||||
PreconditionFailed = 412,
|
||||
PayloadTooLarge = 413,
|
||||
UriTooLong = 414,
|
||||
UnsupportedMediaType = 415,
|
||||
RangeNotSatisfiable = 416,
|
||||
ExpectationFailed = 417,
|
||||
ImATeapot = 418,
|
||||
MisdirectedRequest = 421,
|
||||
UnprocessableEntity = 422,
|
||||
Locked = 423,
|
||||
FailedDependency = 424,
|
||||
TooEarly = 425,
|
||||
UpgradeRequired = 426,
|
||||
PreconditionRequired = 428,
|
||||
TooManyRequests = 429,
|
||||
RequestHeaderFieldsTooLarge = 431,
|
||||
UnavailableForLegalReasons = 451,
|
||||
InternalServerError = 500,
|
||||
NotImplemented = 501,
|
||||
BadGateway = 502,
|
||||
ServiceUnavailable = 503,
|
||||
GatewayTimeout = 504,
|
||||
HttpVersionNotSupported = 505,
|
||||
VariantAlsoNegotiates = 506,
|
||||
InsufficientStorage = 507,
|
||||
LoopDetected = 508,
|
||||
NotExtended = 510,
|
||||
NetworkAuthenticationRequired = 511,
|
||||
}
|
||||
|
||||
export type Method =
|
||||
| "get"
|
||||
| "GET"
|
||||
| "delete"
|
||||
| "DELETE"
|
||||
| "head"
|
||||
| "HEAD"
|
||||
| "options"
|
||||
| "OPTIONS"
|
||||
| "post"
|
||||
| "POST"
|
||||
| "put"
|
||||
| "PUT"
|
||||
| "patch"
|
||||
| "PATCH"
|
||||
| "purge"
|
||||
| "PURGE"
|
||||
| "link"
|
||||
| "LINK"
|
||||
| "unlink"
|
||||
| "UNLINK";
|
||||
|
||||
export type ResponseType =
|
||||
| "arraybuffer"
|
||||
| "blob"
|
||||
| "document"
|
||||
| "json"
|
||||
| "text"
|
||||
| "stream"
|
||||
| "formdata";
|
||||
|
||||
export type responseEncoding =
|
||||
| "ascii"
|
||||
| "ASCII"
|
||||
| "ansi"
|
||||
| "ANSI"
|
||||
| "binary"
|
||||
| "BINARY"
|
||||
| "base64"
|
||||
| "BASE64"
|
||||
| "base64url"
|
||||
| "BASE64URL"
|
||||
| "hex"
|
||||
| "HEX"
|
||||
| "latin1"
|
||||
| "LATIN1"
|
||||
| "ucs-2"
|
||||
| "UCS-2"
|
||||
| "ucs2"
|
||||
| "UCS2"
|
||||
| "utf-8"
|
||||
| "UTF-8"
|
||||
| "utf8"
|
||||
| "UTF8"
|
||||
| "utf16le"
|
||||
| "UTF16LE";
|
||||
|
||||
export interface TransitionalOptions {
|
||||
silentJSONParsing?: boolean;
|
||||
forcedJSONParsing?: boolean;
|
||||
clarifyTimeoutError?: boolean;
|
||||
legacyInterceptorReqResOrdering?: boolean;
|
||||
}
|
||||
|
||||
export interface GenericAbortSignal {
|
||||
readonly aborted: boolean;
|
||||
onabort?: ((...args: any) => any) | null;
|
||||
addEventListener?: (...args: any) => any;
|
||||
removeEventListener?: (...args: any) => any;
|
||||
}
|
||||
|
||||
export interface FormDataVisitorHelpers {
|
||||
defaultVisitor: SerializerVisitor;
|
||||
convertValue: (value: any) => any;
|
||||
isVisitable: (value: any) => boolean;
|
||||
}
|
||||
|
||||
export interface SerializerVisitor {
|
||||
(
|
||||
this: GenericFormData,
|
||||
value: any,
|
||||
key: string | number,
|
||||
path: null | Array<string | number>,
|
||||
helpers: FormDataVisitorHelpers,
|
||||
): boolean;
|
||||
}
|
||||
|
||||
export interface SerializerOptions {
|
||||
visitor?: SerializerVisitor;
|
||||
dots?: boolean;
|
||||
metaTokens?: boolean;
|
||||
indexes?: boolean | null;
|
||||
}
|
||||
|
||||
// tslint:disable-next-line
|
||||
export interface FormSerializerOptions extends SerializerOptions {}
|
||||
|
||||
export interface ParamEncoder {
|
||||
(value: any, defaultEncoder: (value: any) => any): any;
|
||||
}
|
||||
|
||||
export interface CustomParamsSerializer {
|
||||
(params: Record<string, any>, options?: ParamsSerializerOptions): string;
|
||||
}
|
||||
|
||||
export interface ParamsSerializerOptions extends SerializerOptions {
|
||||
encode?: ParamEncoder;
|
||||
serialize?: CustomParamsSerializer;
|
||||
}
|
||||
|
||||
type MaxUploadRate = number;
|
||||
|
||||
type MaxDownloadRate = number;
|
||||
|
||||
type BrowserProgressEvent = any;
|
||||
|
||||
export interface AxiosProgressEvent {
|
||||
loaded: number;
|
||||
total?: number;
|
||||
progress?: number;
|
||||
bytes: number;
|
||||
rate?: number;
|
||||
estimated?: number;
|
||||
upload?: boolean;
|
||||
download?: boolean;
|
||||
event?: BrowserProgressEvent;
|
||||
lengthComputable: boolean;
|
||||
}
|
||||
|
||||
type Milliseconds = number;
|
||||
|
||||
type AxiosAdapterName = StringLiteralsOrString<"xhr" | "http" | "fetch">;
|
||||
|
||||
type AxiosAdapterConfig = AxiosAdapter | AxiosAdapterName;
|
||||
|
||||
export type AddressFamily = 4 | 6 | undefined;
|
||||
|
||||
export interface LookupAddressEntry {
|
||||
address: string;
|
||||
family?: AddressFamily;
|
||||
}
|
||||
|
||||
export type LookupAddress = string | LookupAddressEntry;
|
||||
|
||||
export interface AxiosRequestConfig<D = any> {
|
||||
url?: string;
|
||||
method?: StringLiteralsOrString<Method>;
|
||||
baseURL?: string;
|
||||
allowAbsoluteUrls?: boolean;
|
||||
transformRequest?: AxiosRequestTransformer | AxiosRequestTransformer[];
|
||||
transformResponse?: AxiosResponseTransformer | AxiosResponseTransformer[];
|
||||
headers?: (RawAxiosRequestHeaders & MethodsHeaders) | AxiosHeaders;
|
||||
params?: any;
|
||||
paramsSerializer?: ParamsSerializerOptions | CustomParamsSerializer;
|
||||
data?: D;
|
||||
timeout?: Milliseconds;
|
||||
timeoutErrorMessage?: string;
|
||||
withCredentials?: boolean;
|
||||
adapter?: AxiosAdapterConfig | AxiosAdapterConfig[];
|
||||
auth?: AxiosBasicCredentials;
|
||||
responseType?: ResponseType;
|
||||
responseEncoding?: StringLiteralsOrString<responseEncoding>;
|
||||
xsrfCookieName?: string;
|
||||
xsrfHeaderName?: string;
|
||||
onUploadProgress?: (progressEvent: AxiosProgressEvent) => void;
|
||||
onDownloadProgress?: (progressEvent: AxiosProgressEvent) => void;
|
||||
maxContentLength?: number;
|
||||
validateStatus?: ((status: number) => boolean) | null;
|
||||
maxBodyLength?: number;
|
||||
maxRedirects?: number;
|
||||
maxRate?: number | [MaxUploadRate, MaxDownloadRate];
|
||||
beforeRedirect?: (
|
||||
options: Record<string, any>,
|
||||
responseDetails: {
|
||||
headers: Record<string, string>;
|
||||
statusCode: HttpStatusCode;
|
||||
},
|
||||
) => void;
|
||||
socketPath?: string | null;
|
||||
transport?: any;
|
||||
httpAgent?: any;
|
||||
httpsAgent?: any;
|
||||
proxy?: AxiosProxyConfig | false;
|
||||
cancelToken?: CancelToken | undefined;
|
||||
decompress?: boolean;
|
||||
transitional?: TransitionalOptions;
|
||||
signal?: GenericAbortSignal;
|
||||
insecureHTTPParser?: boolean;
|
||||
env?: {
|
||||
FormData?: new (...args: any[]) => object;
|
||||
fetch?: (
|
||||
input: URL | Request | string,
|
||||
init?: RequestInit,
|
||||
) => Promise<Response>;
|
||||
Request?: new (
|
||||
input: URL | Request | string,
|
||||
init?: RequestInit,
|
||||
) => Request;
|
||||
Response?: new (
|
||||
body?:
|
||||
| ArrayBuffer
|
||||
| ArrayBufferView
|
||||
| Blob
|
||||
| FormData
|
||||
| URLSearchParams
|
||||
| string
|
||||
| null,
|
||||
init?: ResponseInit,
|
||||
) => Response;
|
||||
};
|
||||
formSerializer?: FormSerializerOptions;
|
||||
family?: AddressFamily;
|
||||
lookup?:
|
||||
| ((
|
||||
hostname: string,
|
||||
options: object,
|
||||
cb: (
|
||||
err: Error | null,
|
||||
address: LookupAddress | LookupAddress[],
|
||||
family?: AddressFamily,
|
||||
) => void,
|
||||
) => void)
|
||||
| ((
|
||||
hostname: string,
|
||||
options: object,
|
||||
) => Promise<
|
||||
| [
|
||||
address: LookupAddressEntry | LookupAddressEntry[],
|
||||
family?: AddressFamily,
|
||||
]
|
||||
| LookupAddress
|
||||
>);
|
||||
withXSRFToken?:
|
||||
| boolean
|
||||
| ((config: InternalAxiosRequestConfig) => boolean | undefined);
|
||||
parseReviver?: (this: any, key: string, value: any) => any;
|
||||
fetchOptions?:
|
||||
| Omit<RequestInit, "body" | "headers" | "method" | "signal">
|
||||
| Record<string, any>;
|
||||
httpVersion?: 1 | 2;
|
||||
http2Options?: Record<string, any> & {
|
||||
sessionTimeout?: number;
|
||||
};
|
||||
}
|
||||
|
||||
// Alias
|
||||
export type RawAxiosRequestConfig<D = any> = AxiosRequestConfig<D>;
|
||||
|
||||
export interface InternalAxiosRequestConfig<
|
||||
D = any,
|
||||
> extends AxiosRequestConfig<D> {
|
||||
headers: AxiosRequestHeaders;
|
||||
}
|
||||
|
||||
export interface HeadersDefaults {
|
||||
common: RawAxiosRequestHeaders;
|
||||
delete: RawAxiosRequestHeaders;
|
||||
get: RawAxiosRequestHeaders;
|
||||
head: RawAxiosRequestHeaders;
|
||||
post: RawAxiosRequestHeaders;
|
||||
put: RawAxiosRequestHeaders;
|
||||
patch: RawAxiosRequestHeaders;
|
||||
options?: RawAxiosRequestHeaders;
|
||||
purge?: RawAxiosRequestHeaders;
|
||||
link?: RawAxiosRequestHeaders;
|
||||
unlink?: RawAxiosRequestHeaders;
|
||||
}
|
||||
|
||||
export interface AxiosDefaults<D = any> extends Omit<
|
||||
AxiosRequestConfig<D>,
|
||||
"headers"
|
||||
> {
|
||||
headers: HeadersDefaults;
|
||||
}
|
||||
|
||||
export interface CreateAxiosDefaults<D = any> extends Omit<
|
||||
AxiosRequestConfig<D>,
|
||||
"headers"
|
||||
> {
|
||||
headers?: RawAxiosRequestHeaders | AxiosHeaders | Partial<HeadersDefaults>;
|
||||
}
|
||||
|
||||
export interface AxiosResponse<T = any, D = any, H = {}> {
|
||||
data: T;
|
||||
status: number;
|
||||
statusText: string;
|
||||
headers: (H & RawAxiosResponseHeaders) | AxiosResponseHeaders;
|
||||
config: InternalAxiosRequestConfig<D>;
|
||||
request?: any;
|
||||
}
|
||||
|
||||
export class AxiosError<T = unknown, D = any> extends Error {
|
||||
constructor(
|
||||
message?: string,
|
||||
code?: string,
|
||||
config?: InternalAxiosRequestConfig<D>,
|
||||
request?: any,
|
||||
response?: AxiosResponse<T, D>,
|
||||
);
|
||||
|
||||
config?: InternalAxiosRequestConfig<D>;
|
||||
code?: string;
|
||||
request?: any;
|
||||
response?: AxiosResponse<T, D>;
|
||||
isAxiosError: boolean;
|
||||
status?: number;
|
||||
toJSON: () => object;
|
||||
cause?: Error;
|
||||
event?: BrowserProgressEvent;
|
||||
static from<T = unknown, D = any>(
|
||||
error: Error | unknown,
|
||||
code?: string,
|
||||
config?: InternalAxiosRequestConfig<D>,
|
||||
request?: any,
|
||||
response?: AxiosResponse<T, D>,
|
||||
customProps?: object,
|
||||
): AxiosError<T, D>;
|
||||
static readonly ERR_FR_TOO_MANY_REDIRECTS = "ERR_FR_TOO_MANY_REDIRECTS";
|
||||
static readonly ERR_BAD_OPTION_VALUE = "ERR_BAD_OPTION_VALUE";
|
||||
static readonly ERR_BAD_OPTION = "ERR_BAD_OPTION";
|
||||
static readonly ERR_NETWORK = "ERR_NETWORK";
|
||||
static readonly ERR_DEPRECATED = "ERR_DEPRECATED";
|
||||
static readonly ERR_BAD_RESPONSE = "ERR_BAD_RESPONSE";
|
||||
static readonly ERR_BAD_REQUEST = "ERR_BAD_REQUEST";
|
||||
static readonly ERR_NOT_SUPPORT = "ERR_NOT_SUPPORT";
|
||||
static readonly ERR_INVALID_URL = "ERR_INVALID_URL";
|
||||
static readonly ERR_CANCELED = "ERR_CANCELED";
|
||||
static readonly ECONNABORTED = "ECONNABORTED";
|
||||
static readonly ETIMEDOUT = "ETIMEDOUT";
|
||||
}
|
||||
|
||||
export class CanceledError<T> extends AxiosError<T> {
|
||||
readonly name: "CanceledError";
|
||||
}
|
||||
|
||||
export type AxiosPromise<T = any> = Promise<AxiosResponse<T>>;
|
||||
|
||||
export interface CancelStatic {
|
||||
new (message?: string): Cancel;
|
||||
}
|
||||
|
||||
export interface Cancel {
|
||||
message: string | undefined;
|
||||
}
|
||||
|
||||
export interface Canceler {
|
||||
(message?: string, config?: AxiosRequestConfig, request?: any): void;
|
||||
}
|
||||
|
||||
export interface CancelTokenStatic {
|
||||
new (executor: (cancel: Canceler) => void): CancelToken;
|
||||
source(): CancelTokenSource;
|
||||
}
|
||||
|
||||
export interface CancelToken {
|
||||
promise: Promise<Cancel>;
|
||||
reason?: Cancel;
|
||||
throwIfRequested(): void;
|
||||
}
|
||||
|
||||
export interface CancelTokenSource {
|
||||
token: CancelToken;
|
||||
cancel: Canceler;
|
||||
}
|
||||
|
||||
export interface AxiosInterceptorOptions {
|
||||
synchronous?: boolean;
|
||||
runWhen?: (config: InternalAxiosRequestConfig) => boolean;
|
||||
}
|
||||
|
||||
type AxiosInterceptorFulfilled<T> = (value: T) => T | Promise<T>;
|
||||
type AxiosInterceptorRejected = (error: any) => any;
|
||||
|
||||
type AxiosRequestInterceptorUse<T> = (
|
||||
onFulfilled?: AxiosInterceptorFulfilled<T> | null,
|
||||
onRejected?: AxiosInterceptorRejected | null,
|
||||
options?: AxiosInterceptorOptions,
|
||||
) => number;
|
||||
|
||||
type AxiosResponseInterceptorUse<T> = (
|
||||
onFulfilled?: AxiosInterceptorFulfilled<T> | null,
|
||||
onRejected?: AxiosInterceptorRejected | null,
|
||||
) => number;
|
||||
|
||||
interface AxiosInterceptorHandler<T> {
|
||||
fulfilled: AxiosInterceptorFulfilled<T>;
|
||||
rejected?: AxiosInterceptorRejected;
|
||||
synchronous: boolean;
|
||||
runWhen: (config: AxiosRequestConfig) => boolean | null;
|
||||
}
|
||||
|
||||
export interface AxiosInterceptorManager<V> {
|
||||
use: V extends AxiosResponse
|
||||
? AxiosResponseInterceptorUse<V>
|
||||
: AxiosRequestInterceptorUse<V>;
|
||||
eject(id: number): void;
|
||||
clear(): void;
|
||||
handlers?: Array<AxiosInterceptorHandler<V>>;
|
||||
}
|
||||
|
||||
export class Axios {
|
||||
constructor(config?: AxiosRequestConfig);
|
||||
defaults: AxiosDefaults;
|
||||
interceptors: {
|
||||
request: AxiosInterceptorManager<InternalAxiosRequestConfig>;
|
||||
response: AxiosInterceptorManager<AxiosResponse>;
|
||||
};
|
||||
getUri(config?: AxiosRequestConfig): string;
|
||||
request<T = any, R = AxiosResponse<T>, D = any>(
|
||||
config: AxiosRequestConfig<D>,
|
||||
): Promise<R>;
|
||||
get<T = any, R = AxiosResponse<T>, D = any>(
|
||||
url: string,
|
||||
config?: AxiosRequestConfig<D>,
|
||||
): Promise<R>;
|
||||
delete<T = any, R = AxiosResponse<T>, D = any>(
|
||||
url: string,
|
||||
config?: AxiosRequestConfig<D>,
|
||||
): Promise<R>;
|
||||
head<T = any, R = AxiosResponse<T>, D = any>(
|
||||
url: string,
|
||||
config?: AxiosRequestConfig<D>,
|
||||
): Promise<R>;
|
||||
options<T = any, R = AxiosResponse<T>, D = any>(
|
||||
url: string,
|
||||
config?: AxiosRequestConfig<D>,
|
||||
): Promise<R>;
|
||||
post<T = any, R = AxiosResponse<T>, D = any>(
|
||||
url: string,
|
||||
data?: D,
|
||||
config?: AxiosRequestConfig<D>,
|
||||
): Promise<R>;
|
||||
put<T = any, R = AxiosResponse<T>, D = any>(
|
||||
url: string,
|
||||
data?: D,
|
||||
config?: AxiosRequestConfig<D>,
|
||||
): Promise<R>;
|
||||
patch<T = any, R = AxiosResponse<T>, D = any>(
|
||||
url: string,
|
||||
data?: D,
|
||||
config?: AxiosRequestConfig<D>,
|
||||
): Promise<R>;
|
||||
postForm<T = any, R = AxiosResponse<T>, D = any>(
|
||||
url: string,
|
||||
data?: D,
|
||||
config?: AxiosRequestConfig<D>,
|
||||
): Promise<R>;
|
||||
putForm<T = any, R = AxiosResponse<T>, D = any>(
|
||||
url: string,
|
||||
data?: D,
|
||||
config?: AxiosRequestConfig<D>,
|
||||
): Promise<R>;
|
||||
patchForm<T = any, R = AxiosResponse<T>, D = any>(
|
||||
url: string,
|
||||
data?: D,
|
||||
config?: AxiosRequestConfig<D>,
|
||||
): Promise<R>;
|
||||
}
|
||||
|
||||
export interface AxiosInstance extends Axios {
|
||||
<T = any, R = AxiosResponse<T>, D = any>(
|
||||
config: AxiosRequestConfig<D>,
|
||||
): Promise<R>;
|
||||
<T = any, R = AxiosResponse<T>, D = any>(
|
||||
url: string,
|
||||
config?: AxiosRequestConfig<D>,
|
||||
): Promise<R>;
|
||||
|
||||
create(config?: CreateAxiosDefaults): AxiosInstance;
|
||||
defaults: Omit<AxiosDefaults, "headers"> & {
|
||||
headers: HeadersDefaults & {
|
||||
[key: string]: AxiosHeaderValue;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
export interface GenericFormData {
|
||||
append(name: string, value: any, options?: any): any;
|
||||
}
|
||||
|
||||
export interface GenericHTMLFormElement {
|
||||
name: string;
|
||||
method: string;
|
||||
submit(): void;
|
||||
}
|
||||
|
||||
export function getAdapter(
|
||||
adapters: AxiosAdapterConfig | AxiosAdapterConfig[] | undefined,
|
||||
): AxiosAdapter;
|
||||
|
||||
export function toFormData(
|
||||
sourceObj: object,
|
||||
targetFormData?: GenericFormData,
|
||||
options?: FormSerializerOptions,
|
||||
): GenericFormData;
|
||||
|
||||
export function formToJSON(
|
||||
form: GenericFormData | GenericHTMLFormElement,
|
||||
): object;
|
||||
|
||||
export function isAxiosError<T = any, D = any>(
|
||||
payload: any,
|
||||
): payload is AxiosError<T, D>;
|
||||
|
||||
export function spread<T, R>(callback: (...args: T[]) => R): (array: T[]) => R;
|
||||
|
||||
export function isCancel<T = any>(value: any): value is CanceledError<T>;
|
||||
|
||||
export function all<T>(values: Array<T | Promise<T>>): Promise<T[]>;
|
||||
|
||||
export function mergeConfig<D = any>(
|
||||
config1: AxiosRequestConfig<D>,
|
||||
config2: AxiosRequestConfig<D>,
|
||||
): AxiosRequestConfig<D>;
|
||||
|
||||
export interface AxiosStatic extends AxiosInstance {
|
||||
Cancel: CancelStatic;
|
||||
CancelToken: CancelTokenStatic;
|
||||
Axios: typeof Axios;
|
||||
AxiosError: typeof AxiosError;
|
||||
HttpStatusCode: typeof HttpStatusCode;
|
||||
readonly VERSION: string;
|
||||
isCancel: typeof isCancel;
|
||||
all: typeof all;
|
||||
spread: typeof spread;
|
||||
isAxiosError: typeof isAxiosError;
|
||||
toFormData: typeof toFormData;
|
||||
formToJSON: typeof formToJSON;
|
||||
getAdapter: typeof getAdapter;
|
||||
CanceledError: typeof CanceledError;
|
||||
AxiosHeaders: typeof AxiosHeaders;
|
||||
mergeConfig: typeof mergeConfig;
|
||||
}
|
||||
|
||||
declare const axios: AxiosStatic;
|
||||
|
||||
export default axios;
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
import axios from './lib/axios.js';
|
||||
|
||||
// This module is intended to unwrap Axios default export as named.
|
||||
// Keep top-level export same with static properties
|
||||
// so that it can keep same with es module or cjs
|
||||
const {
|
||||
Axios,
|
||||
AxiosError,
|
||||
CanceledError,
|
||||
isCancel,
|
||||
CancelToken,
|
||||
VERSION,
|
||||
all,
|
||||
Cancel,
|
||||
isAxiosError,
|
||||
spread,
|
||||
toFormData,
|
||||
AxiosHeaders,
|
||||
HttpStatusCode,
|
||||
formToJSON,
|
||||
getAdapter,
|
||||
mergeConfig,
|
||||
} = axios;
|
||||
|
||||
export {
|
||||
axios as default,
|
||||
Axios,
|
||||
AxiosError,
|
||||
CanceledError,
|
||||
isCancel,
|
||||
CancelToken,
|
||||
VERSION,
|
||||
all,
|
||||
Cancel,
|
||||
isAxiosError,
|
||||
spread,
|
||||
toFormData,
|
||||
AxiosHeaders,
|
||||
HttpStatusCode,
|
||||
formToJSON,
|
||||
getAdapter,
|
||||
mergeConfig,
|
||||
};
|
||||
+226
@@ -0,0 +1,226 @@
|
||||
{
|
||||
"name": "axios",
|
||||
"version": "1.13.6",
|
||||
"description": "Promise based HTTP client for the browser and node.js",
|
||||
"main": "./index.js",
|
||||
"module": "./index.js",
|
||||
"exports": {
|
||||
".": {
|
||||
"types": {
|
||||
"require": "./index.d.cts",
|
||||
"default": "./index.d.ts"
|
||||
},
|
||||
"bun": {
|
||||
"require": "./dist/node/axios.cjs",
|
||||
"default": "./index.js"
|
||||
},
|
||||
"react-native": {
|
||||
"require": "./dist/browser/axios.cjs",
|
||||
"default": "./dist/esm/axios.js"
|
||||
},
|
||||
"browser": {
|
||||
"require": "./dist/browser/axios.cjs",
|
||||
"default": "./index.js"
|
||||
},
|
||||
"default": {
|
||||
"require": "./dist/node/axios.cjs",
|
||||
"default": "./index.js"
|
||||
}
|
||||
},
|
||||
"./lib/adapters/http.js": "./lib/adapters/http.js",
|
||||
"./lib/adapters/xhr.js": "./lib/adapters/xhr.js",
|
||||
"./unsafe/*": "./lib/*",
|
||||
"./unsafe/core/settle.js": "./lib/core/settle.js",
|
||||
"./unsafe/core/buildFullPath.js": "./lib/core/buildFullPath.js",
|
||||
"./unsafe/helpers/isAbsoluteURL.js": "./lib/helpers/isAbsoluteURL.js",
|
||||
"./unsafe/helpers/buildURL.js": "./lib/helpers/buildURL.js",
|
||||
"./unsafe/helpers/combineURLs.js": "./lib/helpers/combineURLs.js",
|
||||
"./unsafe/adapters/http.js": "./lib/adapters/http.js",
|
||||
"./unsafe/adapters/xhr.js": "./lib/adapters/xhr.js",
|
||||
"./unsafe/utils.js": "./lib/utils.js",
|
||||
"./package.json": "./package.json",
|
||||
"./dist/browser/axios.cjs": "./dist/browser/axios.cjs",
|
||||
"./dist/node/axios.cjs": "./dist/node/axios.cjs"
|
||||
},
|
||||
"type": "module",
|
||||
"types": "index.d.ts",
|
||||
"scripts": {
|
||||
"test": "npm run test:node && npm run test:browser && npm run test:package",
|
||||
"test:node": "npm run test:mocha",
|
||||
"test:node:coverage": "c8 npm run test:mocha",
|
||||
"test:browser": "npm run test:karma",
|
||||
"test:package": "npm run test:eslint && npm run test:exports",
|
||||
"test:eslint": "node bin/ssl_hotfix.js eslint lib/**/*.js",
|
||||
"test:mocha": "node bin/ssl_hotfix.js mocha test/unit/**/*.js --timeout 30000 --exit",
|
||||
"test:exports": "node bin/ssl_hotfix.js mocha test/module/test.js --timeout 30000 --exit",
|
||||
"test:karma": "node ./bin/run-karma-tests.js",
|
||||
"test:karma:firefox": "node bin/ssl_hotfix.js cross-env LISTEN_ADDR=:: Browsers=Firefox karma start karma.conf.cjs --single-run",
|
||||
"test:karma:server": "node bin/ssl_hotfix.js cross-env karma start karma.conf.cjs",
|
||||
"test:build:version": "node ./bin/check-build-version.js",
|
||||
"start": "node ./sandbox/server.js",
|
||||
"preversion": "gulp version",
|
||||
"version": "npm run build && git add package.json",
|
||||
"prepublishOnly": "npm run test:build:version",
|
||||
"build": "gulp clear && cross-env NODE_ENV=production rollup -c -m",
|
||||
"examples": "node ./examples/server.js",
|
||||
"fix": "eslint --fix lib/**/*.js",
|
||||
"prepare": "husky install && npm run prepare:hooks",
|
||||
"prepare:hooks": "npx husky set .husky/commit-msg \"npx commitlint --edit $1\""
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/axios/axios.git"
|
||||
},
|
||||
"keywords": [
|
||||
"xhr",
|
||||
"http",
|
||||
"ajax",
|
||||
"promise",
|
||||
"node",
|
||||
"browser",
|
||||
"fetch",
|
||||
"rest",
|
||||
"api",
|
||||
"client"
|
||||
],
|
||||
"author": "Matt Zabriskie",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/axios/axios/issues"
|
||||
},
|
||||
"homepage": "https://axios-http.com",
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.28.6",
|
||||
"@babel/preset-env": "^7.28.6",
|
||||
"@commitlint/cli": "^20.3.1",
|
||||
"@commitlint/config-conventional": "^20.3.1",
|
||||
"@rollup/plugin-alias": "^5.1.1",
|
||||
"@rollup/plugin-babel": "^6.1.0",
|
||||
"@rollup/plugin-commonjs": "^15.1.0",
|
||||
"@rollup/plugin-json": "^4.1.0",
|
||||
"@rollup/plugin-multi-entry": "^4.1.0",
|
||||
"@rollup/plugin-node-resolve": "^9.0.0",
|
||||
"abortcontroller-polyfill": "^1.7.8",
|
||||
"auto-changelog": "^2.5.0",
|
||||
"body-parser": "^1.20.4",
|
||||
"c8": "^10.1.3",
|
||||
"chalk": "^5.6.2",
|
||||
"coveralls": "^3.1.1",
|
||||
"cross-env": "^7.0.3",
|
||||
"dev-null": "^0.1.1",
|
||||
"es6-promise": "^4.2.8",
|
||||
"eslint": "^8.57.1",
|
||||
"express": "^4.22.1",
|
||||
"formdata-node": "^5.0.1",
|
||||
"formidable": "^2.1.5",
|
||||
"fs-extra": "^10.1.0",
|
||||
"get-stream": "^3.0.0",
|
||||
"gulp": "^4.0.2",
|
||||
"handlebars": "^4.7.8",
|
||||
"husky": "^8.0.3",
|
||||
"istanbul-instrumenter-loader": "^3.0.1",
|
||||
"jasmine-core": "^2.99.1",
|
||||
"karma": "^6.4.4",
|
||||
"karma-chrome-launcher": "^3.2.0",
|
||||
"karma-firefox-launcher": "^2.1.3",
|
||||
"karma-jasmine": "^1.1.2",
|
||||
"karma-jasmine-ajax": "^0.1.13",
|
||||
"karma-rollup-preprocessor": "^7.0.8",
|
||||
"karma-safari-launcher": "^1.0.0",
|
||||
"karma-sauce-launcher": "^4.3.6",
|
||||
"karma-sinon": "^1.0.5",
|
||||
"karma-sourcemap-loader": "^0.4.0",
|
||||
"lint-staged": "^15.2.10",
|
||||
"memoizee": "^0.4.17",
|
||||
"minimist": "^1.2.8",
|
||||
"mocha": "^10.8.2",
|
||||
"multer": "^1.4.4",
|
||||
"pacote": "^20.0.0",
|
||||
"prettier": "^3.8.1",
|
||||
"pretty-bytes": "^6.1.1",
|
||||
"rollup": "^2.79.2",
|
||||
"rollup-plugin-auto-external": "^2.0.0",
|
||||
"rollup-plugin-bundle-size": "^1.0.3",
|
||||
"rollup-plugin-terser": "^7.0.2",
|
||||
"selfsigned": "^3.0.1",
|
||||
"sinon": "^4.5.0",
|
||||
"stream-throttle": "^0.1.3",
|
||||
"string-replace-async": "^3.0.2",
|
||||
"tar-stream": "^3.1.7",
|
||||
"typescript": "^4.9.5"
|
||||
},
|
||||
"browser": {
|
||||
"./dist/node/axios.cjs": "./dist/browser/axios.cjs",
|
||||
"./lib/adapters/http.js": "./lib/helpers/null.js",
|
||||
"./lib/platform/node/index.js": "./lib/platform/browser/index.js",
|
||||
"./lib/platform/node/classes/FormData.js": "./lib/helpers/null.js"
|
||||
},
|
||||
"react-native": {
|
||||
"./dist/node/axios.cjs": "./dist/browser/axios.cjs",
|
||||
"./lib/adapters/http.js": "./lib/helpers/null.js",
|
||||
"./lib/platform/node/index.js": "./lib/platform/browser/index.js",
|
||||
"./lib/platform/node/classes/FormData.js": "./lib/helpers/null.js"
|
||||
},
|
||||
"jsdelivr": "dist/axios.min.js",
|
||||
"unpkg": "dist/axios.min.js",
|
||||
"typings": "./index.d.ts",
|
||||
"dependencies": {
|
||||
"follow-redirects": "^1.15.11",
|
||||
"form-data": "^4.0.5",
|
||||
"proxy-from-env": "^1.1.0"
|
||||
},
|
||||
"bundlesize": [
|
||||
{
|
||||
"path": "./dist/axios.min.js",
|
||||
"threshold": "5kB"
|
||||
}
|
||||
],
|
||||
"contributors": [
|
||||
"Matt Zabriskie (https://github.com/mzabriskie)",
|
||||
"Dmitriy Mozgovoy (https://github.com/DigitalBrainJS)",
|
||||
"Nick Uraltsev (https://github.com/nickuraltsev)",
|
||||
"Jay (https://github.com/jasonsaayman)",
|
||||
"Emily Morehouse (https://github.com/emilyemorehouse)",
|
||||
"Rubén Norte (https://github.com/rubennorte)",
|
||||
"Justin Beckwith (https://github.com/JustinBeckwith)",
|
||||
"Martti Laine (https://github.com/codeclown)",
|
||||
"Xianming Zhong (https://github.com/chinesedfan)",
|
||||
"Remco Haszing (https://github.com/remcohaszing)",
|
||||
"Willian Agostini (https://github.com/WillianAgostini)",
|
||||
"Rikki Gibson (https://github.com/RikkiGibson)",
|
||||
"Ben Carp (https://github.com/carpben)"
|
||||
],
|
||||
"sideEffects": false,
|
||||
"commitlint": {
|
||||
"rules": {
|
||||
"header-max-length": [
|
||||
2,
|
||||
"always",
|
||||
130
|
||||
]
|
||||
},
|
||||
"extends": [
|
||||
"@commitlint/config-conventional"
|
||||
]
|
||||
},
|
||||
"lint-staged": {
|
||||
"*.{js,cjs,mjs,ts,json,md,yml,yaml}": "prettier --write"
|
||||
},
|
||||
"c8": {
|
||||
"all": true,
|
||||
"include": [
|
||||
"lib/**/*.js",
|
||||
"lib/**/*.ts"
|
||||
],
|
||||
"exclude": [
|
||||
"test",
|
||||
"sandbox"
|
||||
],
|
||||
"reporter": [
|
||||
"text",
|
||||
"lcov",
|
||||
"html"
|
||||
],
|
||||
"report-dir": "./coverage"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user