api.tsx 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. // Bundle export to allow default api import (api.<method> is more readable)
  43. export default {
  44. checkAuth,
  45. registerUser,
  46. logInUser,
  47. logOutUser,
  48. getUser,
  49. updateUser,
  50. getContexts,
  51. getCharts,
  52. }