Files
piratepoet/mailpoet/assets/js/src/automation/api/index.ts
David Remer 26093737e3 Ensure options.path exists
[MAILPOET-5516]
2023-09-25 07:11:43 -07:00

27 lines
671 B
TypeScript

import apiFetch from '@wordpress/api-fetch';
import { api } from '../config';
const apiUrl = `${api.root}/mailpoet/v1/`;
export type ApiError = {
code?: string;
message?: string;
data?: {
status?: number;
details?: Error;
params?: Record<string, string>;
errors?: unknown[];
};
};
export const initializeApi = () => {
apiFetch.use((options, next) => {
if (options.path && options.path.startsWith('/wc-analytics/')) {
return apiFetch.createRootURLMiddleware(`${api.root}/`)(options, next);
}
return apiFetch.createRootURLMiddleware(apiUrl)(options, next);
});
apiFetch.use(apiFetch.createNonceMiddleware(api.nonce));
};