useUpstash.ts 827 B

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