@coder/backstage-plugin-coder
Version:
Create and manage Coder workspaces from Backstage
39 lines (36 loc) • 1.57 kB
JavaScript
import { jsx } from 'react/jsx-runtime';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { CoderAuthProvider } from './CoderAuthProvider.esm.js';
import { CoderAppConfigProvider } from './CoderAppConfigProvider.esm.js';
import { CoderErrorBoundary } from '../CoderErrorBoundary/CoderErrorBoundary.esm.js';
import { BackstageHttpError } from '../../api/errors.esm.js';
const MAX_FETCH_FAILURES = 3;
const shouldRetryRequest = (failureCount, error) => {
const isBelowThreshold = failureCount < MAX_FETCH_FAILURES;
if (!BackstageHttpError.isInstance(error)) {
return isBelowThreshold;
}
const isAuthenticationError = error.status === 401;
const isLikelyProxyConfigurationError = error.status === 504 || error.status === 200 && error.contentType !== "application/json";
return !isAuthenticationError && !isLikelyProxyConfigurationError && isBelowThreshold;
};
const defaultClient = new QueryClient({
defaultOptions: {
queries: {
retry: shouldRetryRequest
},
mutations: {
retry: shouldRetryRequest
}
}
});
const CoderProvider = ({
children,
appConfig,
fallbackAuthUiMode = "restrained",
queryClient = defaultClient
}) => {
return /* @__PURE__ */ jsx(CoderErrorBoundary, { children: /* @__PURE__ */ jsx(QueryClientProvider, { client: queryClient, children: /* @__PURE__ */ jsx(CoderAppConfigProvider, { appConfig, children: /* @__PURE__ */ jsx(CoderAuthProvider, { fallbackAuthUiMode, children }) }) }) });
};
export { CoderProvider };
//# sourceMappingURL=CoderProvider.esm.js.map