api.tsx 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import axios from 'axios';
  2. import { baseApi } from './baseApi';
  3. import { StorageType } from './types';
  4. /**
  5. * Generic api call format
  6. * @param {string} token - Bearer token.
  7. * @param {Object} params - Body params.
  8. * @param {Object} pathParams - Path params.
  9. * @param {(err: Object, res: Object) => void} callback - Callback function.
  10. */
  11. const checkAuth = baseApi('GET', '/api/auth/check');
  12. const registerUser = baseApi<{
  13. email: string,
  14. password: string
  15. }>('POST', '/api/users');
  16. const logInUser = baseApi<{
  17. email: string,
  18. password: string
  19. }>('POST', '/api/login');
  20. const logOutUser = baseApi('POST', '/api/logout');
  21. const getUser = baseApi<{}, { id: number }>('GET', pathParams => {
  22. return `/api/users/${pathParams.id}`;
  23. });
  24. const updateUser = baseApi<{
  25. rawKubeConfig?: string,
  26. allowedContexts?: string[]
  27. }, { id: number }>('PUT', pathParams => {
  28. return `/api/users/${pathParams.id}`;
  29. });
  30. const getContexts = baseApi<{}, { id: number }>('GET', pathParams => {
  31. return `/api/users/${pathParams.id}/contexts`;
  32. });
  33. const getCharts = baseApi<{
  34. namespace: string,
  35. context: string,
  36. storage: string
  37. limit: number,
  38. skip: number,
  39. byDate: boolean,
  40. statusFilter: string[]
  41. }>('GET', '/api/charts');
  42. const getNamespaces = baseApi<{
  43. context: string
  44. }>('GET', '/api/k8s/namespaces');
  45. // Bundle export to allow default api import (api.<method> is more readable)
  46. export default {
  47. checkAuth,
  48. registerUser,
  49. logInUser,
  50. logOutUser,
  51. getUser,
  52. updateUser,
  53. getContexts,
  54. getCharts,
  55. getNamespaces
  56. }