useNeon.ts 788 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import { z } from "zod";
  2. import {
  3. neonIntegrationValidator,
  4. type ClientNeonIntegration,
  5. } from "lib/neon/types";
  6. import api from "shared/api";
  7. type TUseNeon = {
  8. getNeonIntegrations: ({
  9. projectId,
  10. }: {
  11. projectId: number;
  12. }) => Promise<ClientNeonIntegration[]>;
  13. };
  14. export const useNeon = (): TUseNeon => {
  15. const getNeonIntegrations = async ({
  16. projectId,
  17. }: {
  18. projectId: number;
  19. }): Promise<ClientNeonIntegration[]> => {
  20. const response = await api.getNeonIntegrations(
  21. "<token>",
  22. {},
  23. {
  24. projectId,
  25. }
  26. );
  27. const results = await z
  28. .object({ integrations: z.array(neonIntegrationValidator) })
  29. .parseAsync(response.data);
  30. return results.integrations;
  31. };
  32. return {
  33. getNeonIntegrations,
  34. };
  35. };