index.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import * as TE from "fp-ts/TaskEither"
  2. import { StepsOutputList } from "../steps"
  3. /**
  4. * A common error state to be used when the file formats are not expected
  5. */
  6. export const IMPORTER_INVALID_FILE_FORMAT =
  7. "importer_invalid_file_format" as const
  8. export type HoppImporterError = typeof IMPORTER_INVALID_FILE_FORMAT
  9. type HoppImporter<T, StepsType, Errors> = (
  10. stepValues: StepsOutputList<StepsType>
  11. ) => TE.TaskEither<Errors, T>
  12. type HoppImporterApplicableTo = Array<
  13. "team-collections" | "my-collections" | "url-import"
  14. >
  15. /**
  16. * Definition for importers
  17. */
  18. type HoppImporterDefinition<T, Y, E> = {
  19. /**
  20. * the id
  21. */
  22. id: string
  23. /**
  24. * Name of the importer, shown on the Select Importer dropdown
  25. */
  26. name: string
  27. /**
  28. * Icon for importer button
  29. */
  30. icon: string
  31. /**
  32. * Identifier for the importer
  33. */
  34. applicableTo: HoppImporterApplicableTo
  35. /**
  36. * The importer function, It is a Promise because its supposed to be loaded in lazily (dynamic imports ?)
  37. */
  38. importer: HoppImporter<T, Y, E>
  39. /**
  40. * The steps to fetch information required to run an importer
  41. */
  42. steps: Y
  43. }
  44. /**
  45. * Defines a Hoppscotch importer
  46. */
  47. export const defineImporter = <ReturnType, StepType, Errors>(input: {
  48. id: string
  49. name: string
  50. icon: string
  51. importer: HoppImporter<ReturnType, StepType, Errors>
  52. applicableTo: HoppImporterApplicableTo
  53. steps: StepType
  54. }) => {
  55. return <HoppImporterDefinition<ReturnType, StepType, Errors>>{
  56. ...input,
  57. }
  58. }