types.ts 3.1 KB

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