mirror of
https://github.com/strapi/strapi.git
synced 2025-10-16 10:33:34 +00:00
chore: remove axios from packages and edit some tests
This commit is contained in:
parent
9e8dcb640e
commit
f41be330aa
@ -1,31 +1,9 @@
|
|||||||
import { renderHook } from '@tests/utils';
|
import { renderHook } from '@tests/utils';
|
||||||
import { AxiosError, AxiosHeaders } from 'axios';
|
|
||||||
|
|
||||||
import { useAPIErrorHandler, ApiError } from '../useAPIErrorHandler';
|
import { FetchError } from '../../utils/getFetchClient';
|
||||||
|
import { useAPIErrorHandler } from '../useAPIErrorHandler';
|
||||||
|
|
||||||
describe('useAPIErrorHandler', () => {
|
describe('useAPIErrorHandler', () => {
|
||||||
class Err extends AxiosError<{ error: ApiError }> {
|
|
||||||
constructor(error: ApiError) {
|
|
||||||
super(
|
|
||||||
undefined,
|
|
||||||
undefined,
|
|
||||||
undefined,
|
|
||||||
{},
|
|
||||||
{
|
|
||||||
statusText: 'Bad Request',
|
|
||||||
status: 400,
|
|
||||||
headers: new AxiosHeaders(),
|
|
||||||
config: {
|
|
||||||
headers: new AxiosHeaders(),
|
|
||||||
},
|
|
||||||
data: {
|
|
||||||
error,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jest.clearAllMocks();
|
jest.clearAllMocks();
|
||||||
});
|
});
|
||||||
@ -40,10 +18,13 @@ describe('useAPIErrorHandler', () => {
|
|||||||
const { result } = renderHook(() => useAPIErrorHandler());
|
const { result } = renderHook(() => useAPIErrorHandler());
|
||||||
|
|
||||||
const message = result.current.formatAPIError(
|
const message = result.current.formatAPIError(
|
||||||
new Err({
|
new FetchError('Error occured', {
|
||||||
name: 'ApplicationError',
|
data: null,
|
||||||
message: 'Field contains errors',
|
error: {
|
||||||
details: {},
|
name: 'ApplicationError',
|
||||||
|
message: 'Field contains errors',
|
||||||
|
details: {},
|
||||||
|
},
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -54,21 +35,24 @@ describe('useAPIErrorHandler', () => {
|
|||||||
const { result } = renderHook(() => useAPIErrorHandler());
|
const { result } = renderHook(() => useAPIErrorHandler());
|
||||||
|
|
||||||
const message = result.current.formatAPIError(
|
const message = result.current.formatAPIError(
|
||||||
new Err({
|
new FetchError('Fetch Error Occured', {
|
||||||
name: 'ValidationError',
|
data: null,
|
||||||
message: '',
|
error: {
|
||||||
details: {
|
name: 'ValidationError',
|
||||||
errors: [
|
message: '',
|
||||||
{
|
details: {
|
||||||
path: ['field', '0', 'name'],
|
errors: [
|
||||||
message: 'Field contains errors',
|
{
|
||||||
},
|
path: ['field', '0', 'name'],
|
||||||
|
message: 'Field contains errors',
|
||||||
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
path: ['field'],
|
path: ['field'],
|
||||||
message: 'Field must be unique',
|
message: 'Field must be unique',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
@ -79,20 +63,15 @@ describe('useAPIErrorHandler', () => {
|
|||||||
test('formats AxiosErrors', async () => {
|
test('formats AxiosErrors', async () => {
|
||||||
const { result } = renderHook(() => useAPIErrorHandler());
|
const { result } = renderHook(() => useAPIErrorHandler());
|
||||||
|
|
||||||
const axiosError = new AxiosError(
|
const fetchError = new FetchError(
|
||||||
'Error message',
|
'Error message',
|
||||||
'409',
|
// @ts-expect-error – we're testing that it can handle fetch errors
|
||||||
undefined,
|
|
||||||
{},
|
|
||||||
// @ts-expect-error – we're testing that it can handle axios errors
|
|
||||||
{
|
{
|
||||||
status: 405,
|
|
||||||
data: { message: 'Error message' },
|
data: { message: 'Error message' },
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
// @ts-expect-error – we're testing that it can handle axios errors
|
const message = result.current.formatAPIError(fetchError);
|
||||||
const message = result.current.formatAPIError(axiosError);
|
|
||||||
|
|
||||||
expect(message).toBe('Error message');
|
expect(message).toBe('Error message');
|
||||||
});
|
});
|
||||||
|
@ -126,7 +126,7 @@ export function useAPIErrorHandler(
|
|||||||
const formatError = React.useCallback(
|
const formatError = React.useCallback(
|
||||||
(error: FetchError) => {
|
(error: FetchError) => {
|
||||||
// Try to normalize the passed error first. This will fail for e.g. network
|
// Try to normalize the passed error first. This will fail for e.g. network
|
||||||
// errors which are thrown by Axios directly.
|
// errors which are thrown by fetchClient directly.
|
||||||
try {
|
try {
|
||||||
const formattedErr = formatAPIError(error, { intlMessagePrefixCallback, formatMessage });
|
const formattedErr = formatAPIError(error, { intlMessagePrefixCallback, formatMessage });
|
||||||
|
|
||||||
|
@ -9,23 +9,23 @@ const STORAGE_KEYS = {
|
|||||||
|
|
||||||
type FetchParams = Parameters<typeof fetch>;
|
type FetchParams = Parameters<typeof fetch>;
|
||||||
type FetchURL = FetchParams[0];
|
type FetchURL = FetchParams[0];
|
||||||
export type FetchOptions = FetchParams[1];
|
|
||||||
|
|
||||||
export type FetchResponse<TData = unknown> = {
|
export type FetchResponse<TData = unknown> = {
|
||||||
data: TData;
|
data: TData;
|
||||||
};
|
};
|
||||||
type Options = {
|
|
||||||
|
export type FetchOptions = {
|
||||||
params?: any;
|
params?: any;
|
||||||
baseURL?: string;
|
signal?: AbortSignal;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type FetchConfig = {
|
export type FetchConfig = {
|
||||||
options?: Options;
|
baseURL?: string;
|
||||||
fetchConfig?: FetchParams[1];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
type ErrorResponse = {
|
type ErrorResponse = {
|
||||||
data: any;
|
data: any;
|
||||||
error: ApiError & { status: number };
|
error: ApiError & { status?: number };
|
||||||
};
|
};
|
||||||
|
|
||||||
export class FetchError extends Error {
|
export class FetchError extends Error {
|
||||||
@ -39,7 +39,7 @@ export class FetchError extends Error {
|
|||||||
this.name = 'FetchError';
|
this.name = 'FetchError';
|
||||||
this.message = message;
|
this.message = message;
|
||||||
this.response = response;
|
this.response = response;
|
||||||
this.code = response?.error.status;
|
this.code = response?.error?.status;
|
||||||
|
|
||||||
// Ensure correct stack trace in error object
|
// Ensure correct stack trace in error object
|
||||||
if (Error.captureStackTrace) {
|
if (Error.captureStackTrace) {
|
||||||
@ -66,18 +66,24 @@ const hasProtocol = (url: string) => new RegExp('^(?:[a-z+]+:)?//', 'i').test(ur
|
|||||||
const normalizeUrl = (url: string) => (hasProtocol(url) ? url : addPrependingSlash(url));
|
const normalizeUrl = (url: string) => (hasProtocol(url) ? url : addPrependingSlash(url));
|
||||||
|
|
||||||
type FetchClient = {
|
type FetchClient = {
|
||||||
get: <TData = unknown, R = FetchResponse<TData>>(url: string, config?: FetchConfig) => Promise<R>;
|
get: <TData = unknown, R = FetchResponse<TData>>(
|
||||||
|
url: string,
|
||||||
|
config?: FetchOptions
|
||||||
|
) => Promise<R>;
|
||||||
put: <TData = unknown, R = FetchResponse<TData>, TSend = unknown>(
|
put: <TData = unknown, R = FetchResponse<TData>, TSend = unknown>(
|
||||||
url: string,
|
url: string,
|
||||||
data?: TSend,
|
data?: TSend,
|
||||||
config?: FetchConfig
|
config?: FetchOptions
|
||||||
) => Promise<R>;
|
) => Promise<R>;
|
||||||
post: <TData = unknown, R = FetchResponse<TData>, TSend = unknown>(
|
post: <TData = unknown, R = FetchResponse<TData>, TSend = unknown>(
|
||||||
url: string,
|
url: string,
|
||||||
data?: TSend,
|
data?: TSend,
|
||||||
config?: FetchConfig
|
config?: FetchOptions
|
||||||
|
) => Promise<R>;
|
||||||
|
del: <TData = unknown, R = FetchResponse<TData>>(
|
||||||
|
url: string,
|
||||||
|
config?: FetchOptions
|
||||||
) => Promise<R>;
|
) => Promise<R>;
|
||||||
del: <TData = unknown, R = FetchResponse<TData>>(url: string, config?: FetchConfig) => Promise<R>;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -101,7 +107,7 @@ type FetchClient = {
|
|||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
const getFetchClient = (defaultOptions: FetchConfig = {}): FetchClient => {
|
const getFetchClient = (defaultOptions: FetchConfig = {}): FetchClient => {
|
||||||
const { options } = defaultOptions;
|
const baseURL = defaultOptions.baseURL ?? window.strapi.backendURL;
|
||||||
const headers = new Headers({
|
const headers = new Headers({
|
||||||
Accept: 'application/json',
|
Accept: 'application/json',
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
@ -129,30 +135,19 @@ const getFetchClient = (defaultOptions: FetchConfig = {}): FetchClient => {
|
|||||||
return url;
|
return url;
|
||||||
};
|
};
|
||||||
|
|
||||||
const addBaseUrl = (url: FetchURL, clientBaseURL?: string) => {
|
const addBaseUrl = (url: FetchURL) => {
|
||||||
if (clientBaseURL) {
|
|
||||||
return `${clientBaseURL}${url}`;
|
|
||||||
}
|
|
||||||
if (options?.baseURL) {
|
|
||||||
return `${options?.baseURL}${url}`;
|
|
||||||
}
|
|
||||||
const baseURL = window.strapi.backendURL;
|
|
||||||
return `${baseURL}${url}`;
|
return `${baseURL}${url}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
const fetchClient: FetchClient = {
|
const fetchClient: FetchClient = {
|
||||||
get: async <TData = unknown, R = FetchResponse<TData>>(
|
get: async <TData = unknown, R = FetchResponse<TData>>(
|
||||||
url: string,
|
url: string,
|
||||||
options?: FetchConfig
|
options?: FetchOptions
|
||||||
): Promise<R> => {
|
): Promise<R> => {
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
paramsSerializer(
|
paramsSerializer(addBaseUrl(normalizeUrl(url)), options?.params),
|
||||||
addBaseUrl(normalizeUrl(url), options?.options?.baseURL),
|
|
||||||
options?.options?.params
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
...defaultOptions.fetchConfig,
|
...options,
|
||||||
...options?.fetchConfig,
|
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
headers,
|
headers,
|
||||||
}
|
}
|
||||||
@ -162,16 +157,12 @@ const getFetchClient = (defaultOptions: FetchConfig = {}): FetchClient => {
|
|||||||
post: async <TData = unknown, R = FetchResponse<TData>, TSend = unknown>(
|
post: async <TData = unknown, R = FetchResponse<TData>, TSend = unknown>(
|
||||||
url: string,
|
url: string,
|
||||||
data?: TSend,
|
data?: TSend,
|
||||||
options?: FetchConfig
|
options?: FetchOptions
|
||||||
): Promise<R> => {
|
): Promise<R> => {
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
paramsSerializer(
|
paramsSerializer(addBaseUrl(normalizeUrl(url)), options?.params),
|
||||||
addBaseUrl(normalizeUrl(url), options?.options?.baseURL),
|
|
||||||
options?.options?.params
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
...defaultOptions?.fetchConfig,
|
...options,
|
||||||
...options?.fetchConfig,
|
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers,
|
headers,
|
||||||
body: JSON.stringify(data),
|
body: JSON.stringify(data),
|
||||||
@ -182,16 +173,12 @@ const getFetchClient = (defaultOptions: FetchConfig = {}): FetchClient => {
|
|||||||
put: async <TData = unknown, R = FetchResponse<TData>, TSend = unknown>(
|
put: async <TData = unknown, R = FetchResponse<TData>, TSend = unknown>(
|
||||||
url: string,
|
url: string,
|
||||||
data?: TSend,
|
data?: TSend,
|
||||||
options?: FetchConfig
|
options?: FetchOptions
|
||||||
): Promise<R> => {
|
): Promise<R> => {
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
paramsSerializer(
|
paramsSerializer(addBaseUrl(normalizeUrl(url)), options?.params),
|
||||||
addBaseUrl(normalizeUrl(url), options?.options?.baseURL),
|
|
||||||
options?.options?.params
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
...defaultOptions?.fetchConfig,
|
...options,
|
||||||
...options?.fetchConfig,
|
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
headers,
|
headers,
|
||||||
body: JSON.stringify(data),
|
body: JSON.stringify(data),
|
||||||
@ -201,16 +188,12 @@ const getFetchClient = (defaultOptions: FetchConfig = {}): FetchClient => {
|
|||||||
},
|
},
|
||||||
del: async <TData = unknown, R = FetchResponse<TData>>(
|
del: async <TData = unknown, R = FetchResponse<TData>>(
|
||||||
url: string,
|
url: string,
|
||||||
options?: FetchConfig
|
options?: FetchOptions
|
||||||
): Promise<R> => {
|
): Promise<R> => {
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
paramsSerializer(
|
paramsSerializer(addBaseUrl(normalizeUrl(url)), options?.params),
|
||||||
addBaseUrl(normalizeUrl(url), options?.options?.baseURL),
|
|
||||||
options?.options?.params
|
|
||||||
),
|
|
||||||
{
|
{
|
||||||
...defaultOptions?.fetchConfig,
|
...options,
|
||||||
...options?.fetchConfig,
|
|
||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
headers,
|
headers,
|
||||||
}
|
}
|
||||||
|
@ -59,7 +59,7 @@ export function normalizeAPIError(
|
|||||||
| NormalizeErrorReturn
|
| NormalizeErrorReturn
|
||||||
| { name: string; message: string | null; errors: NormalizeErrorReturn[] }
|
| { name: string; message: string | null; errors: NormalizeErrorReturn[] }
|
||||||
| null {
|
| null {
|
||||||
const error = apiError.response?.data.error;
|
const error = apiError.response?.error;
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
// some errors carry multiple errors (such as ValidationError)
|
// some errors carry multiple errors (such as ValidationError)
|
||||||
@ -72,7 +72,6 @@ export function normalizeAPIError(
|
|||||||
),
|
),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return normalizeError(error, { intlMessagePrefixCallback });
|
return normalizeError(error, { intlMessagePrefixCallback });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,9 +12,7 @@ const historyVersionsApi = contentManagerApi.injectEndpoints({
|
|||||||
url: `/content-manager/history-versions`,
|
url: `/content-manager/history-versions`,
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
config: {
|
config: {
|
||||||
options: {
|
params,
|
||||||
params,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
@ -30,9 +30,7 @@ const documentApi = contentManagerApi.injectEndpoints({
|
|||||||
url: `/content-manager/collection-types/${model}/auto-clone/${sourceId}`,
|
url: `/content-manager/collection-types/${model}/auto-clone/${sourceId}`,
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
config: {
|
config: {
|
||||||
options: {
|
params: query,
|
||||||
params: query,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
invalidatesTags: (_result, _error, { model }) => [{ type: 'Document', id: `${model}_LIST` }],
|
invalidatesTags: (_result, _error, { model }) => [{ type: 'Document', id: `${model}_LIST` }],
|
||||||
@ -49,9 +47,7 @@ const documentApi = contentManagerApi.injectEndpoints({
|
|||||||
method: 'POST',
|
method: 'POST',
|
||||||
data,
|
data,
|
||||||
config: {
|
config: {
|
||||||
options: {
|
params,
|
||||||
params,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
invalidatesTags: (_result, _error, { model }) => [{ type: 'Document', id: `${model}_LIST` }],
|
invalidatesTags: (_result, _error, { model }) => [{ type: 'Document', id: `${model}_LIST` }],
|
||||||
@ -72,9 +68,7 @@ const documentApi = contentManagerApi.injectEndpoints({
|
|||||||
method: 'POST',
|
method: 'POST',
|
||||||
data,
|
data,
|
||||||
config: {
|
config: {
|
||||||
options: {
|
params,
|
||||||
params,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
invalidatesTags: (result, _error, { model }) => [
|
invalidatesTags: (result, _error, { model }) => [
|
||||||
@ -96,9 +90,7 @@ const documentApi = contentManagerApi.injectEndpoints({
|
|||||||
}`,
|
}`,
|
||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
config: {
|
config: {
|
||||||
options: {
|
params,
|
||||||
params,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
invalidatesTags: (_result, _error, { collectionType, model }) => [
|
invalidatesTags: (_result, _error, { collectionType, model }) => [
|
||||||
@ -133,9 +125,7 @@ const documentApi = contentManagerApi.injectEndpoints({
|
|||||||
: `/content-manager/${collectionType}/${model}/actions/discard`,
|
: `/content-manager/${collectionType}/${model}/actions/discard`,
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
config: {
|
config: {
|
||||||
options: {
|
params,
|
||||||
params,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
invalidatesTags: (_result, _error, { collectionType, model, documentId }) => {
|
invalidatesTags: (_result, _error, { collectionType, model, documentId }) => {
|
||||||
@ -165,9 +155,7 @@ const documentApi = contentManagerApi.injectEndpoints({
|
|||||||
url: `/content-manager/collection-types/${model}`,
|
url: `/content-manager/collection-types/${model}`,
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
config: {
|
config: {
|
||||||
options: {
|
params,
|
||||||
params,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
providesTags: (result, _error, arg) => {
|
providesTags: (result, _error, arg) => {
|
||||||
@ -198,9 +186,7 @@ const documentApi = contentManagerApi.injectEndpoints({
|
|||||||
: `/content-manager/${collectionType}/${model}/actions/countDraftRelations`,
|
: `/content-manager/${collectionType}/${model}/actions/countDraftRelations`,
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
config: {
|
config: {
|
||||||
options: {
|
params,
|
||||||
params,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
@ -223,9 +209,7 @@ const documentApi = contentManagerApi.injectEndpoints({
|
|||||||
url: `/content-manager/${collectionType}/${model}${documentId ? `/${documentId}` : ''}`,
|
url: `/content-manager/${collectionType}/${model}${documentId ? `/${documentId}` : ''}`,
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
config: {
|
config: {
|
||||||
options: {
|
params,
|
||||||
params,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -263,9 +247,7 @@ const documentApi = contentManagerApi.injectEndpoints({
|
|||||||
url: `/content-manager/collection-types/${model}/actions/countManyEntriesDraftRelations`,
|
url: `/content-manager/collection-types/${model}/actions/countManyEntriesDraftRelations`,
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
config: {
|
config: {
|
||||||
options: {
|
params,
|
||||||
params,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
transformResponse: (response: CountManyEntriesDraftRelations.Response) => response.data,
|
transformResponse: (response: CountManyEntriesDraftRelations.Response) => response.data,
|
||||||
@ -289,9 +271,7 @@ const documentApi = contentManagerApi.injectEndpoints({
|
|||||||
method: 'POST',
|
method: 'POST',
|
||||||
data,
|
data,
|
||||||
config: {
|
config: {
|
||||||
options: {
|
params,
|
||||||
params,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
invalidatesTags: (_result, _error, { collectionType, model, documentId }) => {
|
invalidatesTags: (_result, _error, { collectionType, model, documentId }) => {
|
||||||
@ -331,9 +311,7 @@ const documentApi = contentManagerApi.injectEndpoints({
|
|||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
data,
|
data,
|
||||||
config: {
|
config: {
|
||||||
options: {
|
params,
|
||||||
params,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
invalidatesTags: (_result, _error, { collectionType, model, documentId }) => {
|
invalidatesTags: (_result, _error, { collectionType, model, documentId }) => {
|
||||||
@ -362,9 +340,7 @@ const documentApi = contentManagerApi.injectEndpoints({
|
|||||||
method: 'POST',
|
method: 'POST',
|
||||||
data,
|
data,
|
||||||
config: {
|
config: {
|
||||||
options: {
|
params,
|
||||||
params,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
invalidatesTags: (_result, _error, { collectionType, model, documentId }) => {
|
invalidatesTags: (_result, _error, { collectionType, model, documentId }) => {
|
||||||
|
@ -45,9 +45,7 @@ const relationsApi = contentManagerApi.injectEndpoints({
|
|||||||
url: `/content-manager/relations/${model}/${id}/${targetField}`,
|
url: `/content-manager/relations/${model}/${id}/${targetField}`,
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
config: {
|
config: {
|
||||||
options: {
|
params,
|
||||||
params,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
@ -117,9 +115,7 @@ const relationsApi = contentManagerApi.injectEndpoints({
|
|||||||
url: `/content-manager/relations/${model}/${targetField}`,
|
url: `/content-manager/relations/${model}/${targetField}`,
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
config: {
|
config: {
|
||||||
options: {
|
params,
|
||||||
params,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
@ -20,9 +20,7 @@ const uidApi = contentManagerApi.injectEndpoints({
|
|||||||
method: 'POST',
|
method: 'POST',
|
||||||
data,
|
data,
|
||||||
config: {
|
config: {
|
||||||
options: {
|
params,
|
||||||
params,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
@ -39,9 +37,7 @@ const uidApi = contentManagerApi.injectEndpoints({
|
|||||||
method: 'POST',
|
method: 'POST',
|
||||||
data,
|
data,
|
||||||
config: {
|
config: {
|
||||||
options: {
|
params,
|
||||||
params,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
transformResponse: (response: GenerateUID.Response) => response.data,
|
transformResponse: (response: GenerateUID.Response) => response.data,
|
||||||
@ -57,9 +53,7 @@ const uidApi = contentManagerApi.injectEndpoints({
|
|||||||
method: 'POST',
|
method: 'POST',
|
||||||
data,
|
data,
|
||||||
config: {
|
config: {
|
||||||
options: {
|
params,
|
||||||
params,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
|
@ -4,7 +4,7 @@ import {
|
|||||||
getFetchClient,
|
getFetchClient,
|
||||||
ApiError,
|
ApiError,
|
||||||
isFetchError,
|
isFetchError,
|
||||||
type FetchConfig,
|
type FetchOptions,
|
||||||
} from '@strapi/admin/strapi-admin';
|
} from '@strapi/admin/strapi-admin';
|
||||||
|
|
||||||
interface Query {
|
interface Query {
|
||||||
@ -51,7 +51,7 @@ export interface QueryArguments {
|
|||||||
url: string;
|
url: string;
|
||||||
method?: string;
|
method?: string;
|
||||||
data?: unknown;
|
data?: unknown;
|
||||||
config?: FetchConfig;
|
config?: FetchOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UnknownApiError {
|
export interface UnknownApiError {
|
||||||
@ -71,7 +71,7 @@ const fetchBaseQuery =
|
|||||||
|
|
||||||
if (typeof query === 'string') {
|
if (typeof query === 'string') {
|
||||||
const result = await get(query, {
|
const result = await get(query, {
|
||||||
fetchConfig: { signal },
|
signal,
|
||||||
});
|
});
|
||||||
return { data: result.data };
|
return { data: result.data };
|
||||||
} else {
|
} else {
|
||||||
@ -79,24 +79,24 @@ const fetchBaseQuery =
|
|||||||
|
|
||||||
if (method === 'POST') {
|
if (method === 'POST') {
|
||||||
const result = await post(url, data, {
|
const result = await post(url, data, {
|
||||||
options: { ...config?.options },
|
...config,
|
||||||
fetchConfig: { ...config?.fetchConfig, signal },
|
signal,
|
||||||
});
|
});
|
||||||
return { data: result.data };
|
return { data: result.data };
|
||||||
}
|
}
|
||||||
|
|
||||||
if (method === 'DELETE') {
|
if (method === 'DELETE') {
|
||||||
const result = await del(url, {
|
const result = await del(url, {
|
||||||
options: { ...config?.options },
|
...config,
|
||||||
fetchConfig: { ...config?.fetchConfig, signal },
|
signal,
|
||||||
});
|
});
|
||||||
return { data: result.data };
|
return { data: result.data };
|
||||||
}
|
}
|
||||||
|
|
||||||
if (method === 'PUT') {
|
if (method === 'PUT') {
|
||||||
const result = await put(url, data, {
|
const result = await put(url, data, {
|
||||||
options: { ...config?.options },
|
...config,
|
||||||
fetchConfig: { ...config?.fetchConfig, signal },
|
signal,
|
||||||
});
|
});
|
||||||
return { data: result.data };
|
return { data: result.data };
|
||||||
}
|
}
|
||||||
@ -105,8 +105,8 @@ const fetchBaseQuery =
|
|||||||
* Default is GET.
|
* Default is GET.
|
||||||
*/
|
*/
|
||||||
const result = await get(url, {
|
const result = await get(url, {
|
||||||
options: { ...config?.options },
|
...config,
|
||||||
fetchConfig: { ...config?.fetchConfig, signal },
|
signal,
|
||||||
});
|
});
|
||||||
return { data: result.data };
|
return { data: result.data };
|
||||||
}
|
}
|
||||||
|
@ -64,7 +64,6 @@
|
|||||||
"@strapi/icons": "1.16.0",
|
"@strapi/icons": "1.16.0",
|
||||||
"@strapi/types": "5.0.0-beta.2",
|
"@strapi/types": "5.0.0-beta.2",
|
||||||
"@strapi/utils": "5.0.0-beta.2",
|
"@strapi/utils": "5.0.0-beta.2",
|
||||||
"axios": "1.6.8",
|
|
||||||
"codemirror5": "npm:codemirror@^5.65.11",
|
"codemirror5": "npm:codemirror@^5.65.11",
|
||||||
"date-fns": "2.30.0",
|
"date-fns": "2.30.0",
|
||||||
"fractional-indexing": "3.2.0",
|
"fractional-indexing": "3.2.0",
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import {
|
import {
|
||||||
getFetchClient,
|
getFetchClient,
|
||||||
type FetchResponse,
|
type FetchResponse,
|
||||||
type FetchConfig,
|
type FetchOptions,
|
||||||
type FetchError,
|
type FetchError,
|
||||||
} from '@strapi/admin/strapi-admin';
|
} from '@strapi/admin/strapi-admin';
|
||||||
|
|
||||||
@ -9,7 +9,7 @@ export interface QueryArguments<TSend> {
|
|||||||
url: string;
|
url: string;
|
||||||
method: 'PUT' | 'GET' | 'POST' | 'DELETE';
|
method: 'PUT' | 'GET' | 'POST' | 'DELETE';
|
||||||
data?: TSend;
|
data?: TSend;
|
||||||
config?: FetchConfig;
|
config?: FetchOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
const fetchBaseQuery = async <TData = unknown, TSend = unknown>({
|
const fetchBaseQuery = async <TData = unknown, TSend = unknown>({
|
||||||
|
@ -63,9 +63,7 @@ const releaseApi = createApi({
|
|||||||
url: '/content-releases',
|
url: '/content-releases',
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
config: {
|
config: {
|
||||||
options: {
|
params,
|
||||||
params,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
@ -93,14 +91,12 @@ const releaseApi = createApi({
|
|||||||
url: '/content-releases',
|
url: '/content-releases',
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
config: {
|
config: {
|
||||||
options: {
|
params: {
|
||||||
params: {
|
page: page || 1,
|
||||||
page: page || 1,
|
pageSize: pageSize || 16,
|
||||||
pageSize: pageSize || 16,
|
filters: filters || {
|
||||||
filters: filters || {
|
releasedAt: {
|
||||||
releasedAt: {
|
$notNull: false,
|
||||||
$notNull: false,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -146,9 +142,7 @@ const releaseApi = createApi({
|
|||||||
url: `/content-releases/${releaseId}/actions`,
|
url: `/content-releases/${releaseId}/actions`,
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
config: {
|
config: {
|
||||||
options: {
|
params,
|
||||||
params,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
@ -59,7 +59,6 @@
|
|||||||
"@strapi/icons": "1.16.0",
|
"@strapi/icons": "1.16.0",
|
||||||
"@strapi/types": "workspace:*",
|
"@strapi/types": "workspace:*",
|
||||||
"@strapi/utils": "5.0.0-beta.2",
|
"@strapi/utils": "5.0.0-beta.2",
|
||||||
"axios": "1.6.8",
|
|
||||||
"date-fns": "2.30.0",
|
"date-fns": "2.30.0",
|
||||||
"date-fns-tz": "2.0.1",
|
"date-fns-tz": "2.0.1",
|
||||||
"formik": "2.4.5",
|
"formik": "2.4.5",
|
||||||
|
@ -48,7 +48,6 @@
|
|||||||
"@reduxjs/toolkit": "1.9.7",
|
"@reduxjs/toolkit": "1.9.7",
|
||||||
"@strapi/design-system": "1.17.0",
|
"@strapi/design-system": "1.17.0",
|
||||||
"@strapi/icons": "1.16.0",
|
"@strapi/icons": "1.16.0",
|
||||||
"axios": "1.6.8",
|
|
||||||
"react-helmet": "^6.1.0",
|
"react-helmet": "^6.1.0",
|
||||||
"react-intl": "6.6.2",
|
"react-intl": "6.6.2",
|
||||||
"react-redux": "8.1.3",
|
"react-redux": "8.1.3",
|
||||||
|
@ -52,7 +52,6 @@
|
|||||||
"@strapi/icons": "1.16.0",
|
"@strapi/icons": "1.16.0",
|
||||||
"@strapi/provider-upload-local": "5.0.0-beta.2",
|
"@strapi/provider-upload-local": "5.0.0-beta.2",
|
||||||
"@strapi/utils": "5.0.0-beta.2",
|
"@strapi/utils": "5.0.0-beta.2",
|
||||||
"axios": "1.6.8",
|
|
||||||
"byte-size": "7.0.1",
|
"byte-size": "7.0.1",
|
||||||
"cropperjs": "1.6.1",
|
"cropperjs": "1.6.1",
|
||||||
"date-fns": "2.30.0",
|
"date-fns": "2.30.0",
|
||||||
|
@ -11,9 +11,7 @@ type SettingsInput = {
|
|||||||
const api = createApi({
|
const api = createApi({
|
||||||
reducerPath: 'plugin::documentation',
|
reducerPath: 'plugin::documentation',
|
||||||
baseQuery: baseQuery({
|
baseQuery: baseQuery({
|
||||||
options: {
|
baseURL: '/documentation',
|
||||||
baseURL: '/documentation',
|
|
||||||
},
|
|
||||||
}),
|
}),
|
||||||
tagTypes: ['DocumentInfos'],
|
tagTypes: ['DocumentInfos'],
|
||||||
endpoints: (builder) => {
|
endpoints: (builder) => {
|
||||||
|
@ -4,6 +4,7 @@ import {
|
|||||||
getFetchClient,
|
getFetchClient,
|
||||||
isFetchError,
|
isFetchError,
|
||||||
type ApiError,
|
type ApiError,
|
||||||
|
type FetchOptions,
|
||||||
type FetchConfig,
|
type FetchConfig,
|
||||||
} from '@strapi/strapi/admin';
|
} from '@strapi/strapi/admin';
|
||||||
|
|
||||||
@ -11,7 +12,7 @@ export interface QueryArguments {
|
|||||||
url: string;
|
url: string;
|
||||||
method?: string;
|
method?: string;
|
||||||
data?: unknown;
|
data?: unknown;
|
||||||
config?: FetchConfig;
|
config?: FetchOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UnknownApiError {
|
export interface UnknownApiError {
|
||||||
@ -30,31 +31,31 @@ const baseQuery =
|
|||||||
const { get, post, del, put } = getFetchClient(config);
|
const { get, post, del, put } = getFetchClient(config);
|
||||||
|
|
||||||
if (typeof query === 'string') {
|
if (typeof query === 'string') {
|
||||||
const result = await get(query, { fetchConfig: { signal } });
|
const result = await get(query, { signal });
|
||||||
return { data: result.data };
|
return { data: result.data };
|
||||||
} else {
|
} else {
|
||||||
const { url, method = 'GET', data, config } = query;
|
const { url, method = 'GET', data, config } = query;
|
||||||
|
|
||||||
if (method === 'POST') {
|
if (method === 'POST') {
|
||||||
const result = await post(url, data, {
|
const result = await post(url, data, {
|
||||||
options: { ...config?.options },
|
...config,
|
||||||
fetchConfig: { ...config?.fetchConfig, signal },
|
signal,
|
||||||
});
|
});
|
||||||
return { data: result.data };
|
return { data: result.data };
|
||||||
}
|
}
|
||||||
|
|
||||||
if (method === 'DELETE') {
|
if (method === 'DELETE') {
|
||||||
const result = await del(url, {
|
const result = await del(url, {
|
||||||
options: { ...config?.options },
|
...config,
|
||||||
fetchConfig: { ...config?.fetchConfig, signal },
|
signal,
|
||||||
});
|
});
|
||||||
return { data: result.data };
|
return { data: result.data };
|
||||||
}
|
}
|
||||||
|
|
||||||
if (method === 'PUT') {
|
if (method === 'PUT') {
|
||||||
const result = await put(url, data, {
|
const result = await put(url, data, {
|
||||||
options: { ...config?.options },
|
...config,
|
||||||
fetchConfig: { ...config?.fetchConfig, signal },
|
signal,
|
||||||
});
|
});
|
||||||
return { data: result.data };
|
return { data: result.data };
|
||||||
}
|
}
|
||||||
@ -63,8 +64,8 @@ const baseQuery =
|
|||||||
* Default is GET.
|
* Default is GET.
|
||||||
*/
|
*/
|
||||||
const result = await get(url, {
|
const result = await get(url, {
|
||||||
options: { ...config?.options },
|
...config,
|
||||||
fetchConfig: { ...config?.fetchConfig, signal },
|
signal,
|
||||||
});
|
});
|
||||||
return { data: result.data };
|
return { data: result.data };
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,6 @@
|
|||||||
"@strapi/design-system": "1.17.0",
|
"@strapi/design-system": "1.17.0",
|
||||||
"@strapi/icons": "1.16.0",
|
"@strapi/icons": "1.16.0",
|
||||||
"@strapi/utils": "5.0.0-beta.2",
|
"@strapi/utils": "5.0.0-beta.2",
|
||||||
"axios": "1.6.8",
|
|
||||||
"bcryptjs": "2.4.3",
|
"bcryptjs": "2.4.3",
|
||||||
"cheerio": "^1.0.0-rc.12",
|
"cheerio": "^1.0.0-rc.12",
|
||||||
"formik": "2.4.5",
|
"formik": "2.4.5",
|
||||||
|
@ -4,14 +4,14 @@ import {
|
|||||||
getFetchClient,
|
getFetchClient,
|
||||||
isFetchError,
|
isFetchError,
|
||||||
type ApiError,
|
type ApiError,
|
||||||
type FetchConfig,
|
type FetchOptions,
|
||||||
} from '@strapi/admin/strapi-admin';
|
} from '@strapi/admin/strapi-admin';
|
||||||
|
|
||||||
export interface QueryArguments {
|
export interface QueryArguments {
|
||||||
url: string;
|
url: string;
|
||||||
method?: string;
|
method?: string;
|
||||||
data?: unknown;
|
data?: unknown;
|
||||||
config?: FetchConfig;
|
config?: FetchOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UnknownApiError {
|
export interface UnknownApiError {
|
||||||
@ -30,31 +30,31 @@ const fetchBaseQuery =
|
|||||||
const { get, post, del, put } = getFetchClient();
|
const { get, post, del, put } = getFetchClient();
|
||||||
|
|
||||||
if (typeof query === 'string') {
|
if (typeof query === 'string') {
|
||||||
const result = await get(query, { fetchConfig: { signal } });
|
const result = await get(query, { signal });
|
||||||
return { data: result.data };
|
return { data: result.data };
|
||||||
} else {
|
} else {
|
||||||
const { url, method = 'GET', data, config } = query;
|
const { url, method = 'GET', data, config } = query;
|
||||||
|
|
||||||
if (method === 'POST') {
|
if (method === 'POST') {
|
||||||
const result = await post(url, data, {
|
const result = await post(url, data, {
|
||||||
options: { ...config?.options },
|
...config,
|
||||||
fetchConfig: { ...config?.fetchConfig, signal },
|
signal,
|
||||||
});
|
});
|
||||||
return { data: result.data };
|
return { data: result.data };
|
||||||
}
|
}
|
||||||
|
|
||||||
if (method === 'DELETE') {
|
if (method === 'DELETE') {
|
||||||
const result = await del(url, {
|
const result = await del(url, {
|
||||||
options: { ...config?.options },
|
...config,
|
||||||
fetchConfig: { ...config?.fetchConfig, signal },
|
signal,
|
||||||
});
|
});
|
||||||
return { data: result.data };
|
return { data: result.data };
|
||||||
}
|
}
|
||||||
|
|
||||||
if (method === 'PUT') {
|
if (method === 'PUT') {
|
||||||
const result = await put(url, data, {
|
const result = await put(url, data, {
|
||||||
options: { ...config?.options },
|
...config,
|
||||||
fetchConfig: { ...config?.fetchConfig, signal },
|
signal,
|
||||||
});
|
});
|
||||||
return { data: result.data };
|
return { data: result.data };
|
||||||
}
|
}
|
||||||
@ -63,8 +63,8 @@ const fetchBaseQuery =
|
|||||||
* Default is GET.
|
* Default is GET.
|
||||||
*/
|
*/
|
||||||
const result = await get(url, {
|
const result = await get(url, {
|
||||||
options: { ...config?.options },
|
...config,
|
||||||
fetchConfig: { ...config?.fetchConfig, signal },
|
signal,
|
||||||
});
|
});
|
||||||
return { data: result.data };
|
return { data: result.data };
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,6 @@
|
|||||||
"@strapi/design-system": "1.17.0",
|
"@strapi/design-system": "1.17.0",
|
||||||
"@strapi/icons": "1.16.0",
|
"@strapi/icons": "1.16.0",
|
||||||
"@strapi/utils": "5.0.0-beta.2",
|
"@strapi/utils": "5.0.0-beta.2",
|
||||||
"axios": "1.6.8",
|
|
||||||
"lodash": "4.17.21",
|
"lodash": "4.17.21",
|
||||||
"qs": "6.11.1",
|
"qs": "6.11.1",
|
||||||
"react-intl": "6.6.2",
|
"react-intl": "6.6.2",
|
||||||
|
@ -6961,7 +6961,6 @@ __metadata:
|
|||||||
"@testing-library/user-event": "npm:14.4.3"
|
"@testing-library/user-event": "npm:14.4.3"
|
||||||
"@types/koa": "npm:2.13.4"
|
"@types/koa": "npm:2.13.4"
|
||||||
"@types/styled-components": "npm:5.1.34"
|
"@types/styled-components": "npm:5.1.34"
|
||||||
axios: "npm:1.6.8"
|
|
||||||
date-fns: "npm:2.30.0"
|
date-fns: "npm:2.30.0"
|
||||||
date-fns-tz: "npm:2.0.1"
|
date-fns-tz: "npm:2.0.1"
|
||||||
formik: "npm:2.4.5"
|
formik: "npm:2.4.5"
|
||||||
@ -7364,7 +7363,6 @@ __metadata:
|
|||||||
"@testing-library/react": "npm:14.0.0"
|
"@testing-library/react": "npm:14.0.0"
|
||||||
"@types/jest": "npm:29.5.2"
|
"@types/jest": "npm:29.5.2"
|
||||||
"@types/lodash": "npm:^4.14.191"
|
"@types/lodash": "npm:^4.14.191"
|
||||||
axios: "npm:1.6.8"
|
|
||||||
codemirror5: "npm:codemirror@^5.65.11"
|
codemirror5: "npm:codemirror@^5.65.11"
|
||||||
date-fns: "npm:2.30.0"
|
date-fns: "npm:2.30.0"
|
||||||
fractional-indexing: "npm:3.2.0"
|
fractional-indexing: "npm:3.2.0"
|
||||||
@ -7471,7 +7469,6 @@ __metadata:
|
|||||||
"@types/koa": "npm:2.13.4"
|
"@types/koa": "npm:2.13.4"
|
||||||
"@types/koa-session": "npm:6.4.1"
|
"@types/koa-session": "npm:6.4.1"
|
||||||
"@types/swagger-ui-dist": "npm:3.30.4"
|
"@types/swagger-ui-dist": "npm:3.30.4"
|
||||||
axios: "npm:1.6.8"
|
|
||||||
bcryptjs: "npm:2.4.3"
|
bcryptjs: "npm:2.4.3"
|
||||||
cheerio: "npm:^1.0.0-rc.12"
|
cheerio: "npm:^1.0.0-rc.12"
|
||||||
formik: "npm:2.4.5"
|
formik: "npm:2.4.5"
|
||||||
@ -7596,7 +7593,6 @@ __metadata:
|
|||||||
"@strapi/utils": "npm:5.0.0-beta.2"
|
"@strapi/utils": "npm:5.0.0-beta.2"
|
||||||
"@testing-library/react": "npm:14.0.0"
|
"@testing-library/react": "npm:14.0.0"
|
||||||
"@testing-library/user-event": "npm:14.4.3"
|
"@testing-library/user-event": "npm:14.4.3"
|
||||||
axios: "npm:1.6.8"
|
|
||||||
lodash: "npm:4.17.21"
|
lodash: "npm:4.17.21"
|
||||||
msw: "npm:1.3.0"
|
msw: "npm:1.3.0"
|
||||||
qs: "npm:6.11.1"
|
qs: "npm:6.11.1"
|
||||||
@ -7657,7 +7653,6 @@ __metadata:
|
|||||||
"@types/koa": "npm:2.13.4"
|
"@types/koa": "npm:2.13.4"
|
||||||
"@types/koa-range": "npm:0.3.5"
|
"@types/koa-range": "npm:0.3.5"
|
||||||
"@types/koa-static": "npm:4.0.2"
|
"@types/koa-static": "npm:4.0.2"
|
||||||
axios: "npm:1.6.8"
|
|
||||||
byte-size: "npm:7.0.1"
|
byte-size: "npm:7.0.1"
|
||||||
cropperjs: "npm:1.6.1"
|
cropperjs: "npm:1.6.1"
|
||||||
date-fns: "npm:2.30.0"
|
date-fns: "npm:2.30.0"
|
||||||
@ -7867,7 +7862,6 @@ __metadata:
|
|||||||
"@strapi/plugin-content-manager": "npm:5.0.0-beta.2"
|
"@strapi/plugin-content-manager": "npm:5.0.0-beta.2"
|
||||||
"@strapi/types": "npm:5.0.0-beta.2"
|
"@strapi/types": "npm:5.0.0-beta.2"
|
||||||
"@strapi/utils": "npm:5.0.0-beta.2"
|
"@strapi/utils": "npm:5.0.0-beta.2"
|
||||||
axios: "npm:1.6.8"
|
|
||||||
msw: "npm:1.3.0"
|
msw: "npm:1.3.0"
|
||||||
react: "npm:^18.2.0"
|
react: "npm:^18.2.0"
|
||||||
react-dom: "npm:^18.2.0"
|
react-dom: "npm:^18.2.0"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user