@intrig/core 0.0.14-4 → 0.0.14-5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/main.js +28 -5
- package/package.json +1 -1
package/main.js
CHANGED
|
@@ -7078,10 +7078,7 @@ function packageJson_template_packageJsonTemplate(_path) {
|
|
|
7078
7078
|
|
|
7079
7079
|
function provider_template_providerTemplate(_path, apisToSync) {
|
|
7080
7080
|
const axiosConfigs = apisToSync.map((a)=>`
|
|
7081
|
-
${a.id}:
|
|
7082
|
-
...(configs.defaults ?? {}),
|
|
7083
|
-
...(configs['${a.id}'] ?? {}),
|
|
7084
|
-
}),
|
|
7081
|
+
${a.id}: createAxiosInstance(configs.defaults, configs['${a.id}']),
|
|
7085
7082
|
`).join("\n");
|
|
7086
7083
|
const ts = typescript(external_path_namespaceObject.resolve(_path, "src", "intrig-provider.tsx"));
|
|
7087
7084
|
return ts`
|
|
@@ -7112,8 +7109,10 @@ import {
|
|
|
7112
7109
|
import axios, {
|
|
7113
7110
|
Axios,
|
|
7114
7111
|
AxiosProgressEvent,
|
|
7115
|
-
AxiosRequestConfig,
|
|
7112
|
+
AxiosRequestConfig,
|
|
7113
|
+
AxiosResponse,
|
|
7116
7114
|
CreateAxiosDefaults,
|
|
7115
|
+
InternalAxiosRequestConfig,
|
|
7117
7116
|
isAxiosError,
|
|
7118
7117
|
} from 'axios';
|
|
7119
7118
|
import { ZodSchema } from 'zod';
|
|
@@ -7142,6 +7141,8 @@ function requestReducer(
|
|
|
7142
7141
|
|
|
7143
7142
|
export interface DefaultConfigs extends CreateAxiosDefaults {
|
|
7144
7143
|
debounceDelay?: number;
|
|
7144
|
+
requestInterceptor?: (config: InternalAxiosRequestConfig) => InternalAxiosRequestConfig;
|
|
7145
|
+
responseInterceptor?: (config: AxiosResponse<any>) => AxiosResponse<any>;
|
|
7145
7146
|
}
|
|
7146
7147
|
|
|
7147
7148
|
export interface IntrigProviderProps {
|
|
@@ -7149,6 +7150,28 @@ export interface IntrigProviderProps {
|
|
|
7149
7150
|
children: React.ReactNode;
|
|
7150
7151
|
}
|
|
7151
7152
|
|
|
7153
|
+
function createAxiosInstance(defaultConfig?: DefaultConfigs, config?: DefaultConfigs) {
|
|
7154
|
+
const axiosInstance = axios.create({
|
|
7155
|
+
...defaultConfig ?? {},
|
|
7156
|
+
...config ?? {},
|
|
7157
|
+
});
|
|
7158
|
+
function requestInterceptor(cfg: InternalAxiosRequestConfig) {
|
|
7159
|
+
let intermediate = defaultConfig?.requestInterceptor?.(cfg) ?? cfg;
|
|
7160
|
+
return config?.requestInterceptor?.(intermediate) ?? intermediate;
|
|
7161
|
+
}
|
|
7162
|
+
|
|
7163
|
+
function responseInterceptor(cfg: AxiosResponse<any>) {
|
|
7164
|
+
let intermediate = defaultConfig?.responseInterceptor?.(cfg) ?? cfg;
|
|
7165
|
+
return config?.responseInterceptor?.(intermediate) ?? intermediate;
|
|
7166
|
+
}
|
|
7167
|
+
|
|
7168
|
+
axiosInstance.interceptors.request.use(requestInterceptor)
|
|
7169
|
+
axiosInstance.interceptors.response.use(responseInterceptor, (error) => {
|
|
7170
|
+
return Promise.reject(error);
|
|
7171
|
+
})
|
|
7172
|
+
return axiosInstance;
|
|
7173
|
+
}
|
|
7174
|
+
|
|
7152
7175
|
/**
|
|
7153
7176
|
* IntrigProvider is a context provider component that sets up global state management
|
|
7154
7177
|
* and provides Axios instances for API requests.
|