types.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. export type Workspace = {
  2. id: number;
  3. name: string;
  4. };
  5. export type WorkspaceEntry = WorkspaceCollection | WorkspaceRequest;
  6. export type WorkspaceEntryBase = {
  7. // Values from models
  8. id: number;
  9. workspace_id: number;
  10. parent_id: number | null;
  11. name: string;
  12. auth: number | null;
  13. auth_inherit: boolean;
  14. type: string;
  15. // UI values,
  16. open?: boolean;
  17. };
  18. export type WorkspaceCollection = WorkspaceEntryBase & {
  19. type: "Collection";
  20. };
  21. export type WorkspaceRequest = WorkspaceEntryBase & {
  22. type: "Request";
  23. method: string;
  24. url: string;
  25. body: RequestBody | null;
  26. headers: RequestHeader[];
  27. path: PathParam[];
  28. query: QueryParam[];
  29. // Display fields
  30. expandedUrl?: RequestUrl;
  31. };
  32. export type RequestUrl = {
  33. scheme: string;
  34. host: string;
  35. path: PathSegment[];
  36. query_params: QueryParam[];
  37. trail: string;
  38. };
  39. export type UrlErrorType = "Parse" | "DuplicatePath" | "Db";
  40. export type UrlError = {
  41. type: UrlErrorType;
  42. error: string;
  43. };
  44. export type RequestHeader = {
  45. id: number;
  46. name: string;
  47. value: string;
  48. };
  49. export type PathParam = {
  50. position: number;
  51. name: string;
  52. value: string;
  53. };
  54. export type QueryParam = {
  55. id: number;
  56. position: number | null;
  57. key: string;
  58. value: string;
  59. };
  60. export type PathSegment = {
  61. type: "Static" | "Dynamic";
  62. value: string;
  63. };
  64. export type WorkspaceCreateCollection = {
  65. name: string;
  66. workspace_id: number;
  67. parent_id?: number;
  68. };
  69. export type WorkspaceCreateRequest = {
  70. name: string;
  71. workspace_id: number;
  72. parent_id?: number;
  73. method: string;
  74. url: string;
  75. };
  76. export type RequestBody = {
  77. id: number;
  78. content: string;
  79. ty: string;
  80. };
  81. export type WorkspaceEnvironment = {
  82. id: number;
  83. name: string;
  84. workspace_id: number;
  85. variables: EnvVariable[];
  86. };
  87. export type EnvVariable = {
  88. id: number;
  89. name: string;
  90. value: string;
  91. secret: boolean;
  92. };
  93. export type Authentication = {
  94. id: number;
  95. workspace_id: number;
  96. name: string;
  97. params: AuthParams;
  98. };
  99. export type AuthParams =
  100. | {
  101. type: "Token";
  102. value: {
  103. name: string;
  104. placement: "Header" | "Query";
  105. value: string;
  106. };
  107. }
  108. | { type: "Basic"; value: { user: string; password: string } }
  109. | {
  110. type: "OAuth";
  111. value: {
  112. token_name: string;
  113. callback_url: string;
  114. auth_url: string;
  115. token_url: string;
  116. refresh_url: string | null;
  117. client_id: string;
  118. client_secret: string;
  119. scope: string | null;
  120. state: string | null;
  121. grant_type:
  122. | {
  123. type: "AuthorizationCode";
  124. }
  125. | {
  126. type: "AuthorizationCodePKCE";
  127. value: { verifier: string | null };
  128. }
  129. | { type: "ClientCredentials" };
  130. };
  131. };
  132. export type AuthType = "Token" | "Basic" | "OAuth";
  133. export type HttpResponse = {
  134. status: number;
  135. headers: string[][];
  136. body: HttpResponseBody | null;
  137. };
  138. export type HttpResponseBody =
  139. | {
  140. type: "TextPlain";
  141. content: string;
  142. }
  143. | {
  144. type: "TextHtml";
  145. content: string;
  146. }
  147. | {
  148. type: "Json";
  149. content: string;
  150. };
  151. export type ResponseResult =
  152. | {
  153. type: "Ok";
  154. data: HttpResponse;
  155. }
  156. | { type: "Err"; data: string };