api.tsx 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215
  1. import { baseApi } from "./baseApi";
  2. import { FullActionConfigType, StorageType } from "./types";
  3. /**
  4. * Generic api call format
  5. * @param {string} token - Bearer token.
  6. * @param {Object} params - Body params.
  7. * @param {Object} pathParams - Path params.
  8. * @param {(err: Object, res: Object) => void} callback - Callback function.
  9. */
  10. const checkAuth = baseApi("GET", "/api/users/current");
  11. const connectECRRegistry = baseApi<
  12. {
  13. name: string;
  14. aws_integration_id: string;
  15. },
  16. { id: number }
  17. >("POST", (pathParams) => {
  18. return `/api/projects/${pathParams.id}/registries`;
  19. });
  20. const connectGCRRegistry = baseApi<
  21. {
  22. name: string;
  23. gcp_integration_id: string;
  24. url: string;
  25. },
  26. { id: number }
  27. >("POST", (pathParams) => {
  28. return `/api/projects/${pathParams.id}/registries`;
  29. });
  30. const connectDORegistry = baseApi<
  31. {
  32. name: string;
  33. do_integration_id: string;
  34. url: string;
  35. },
  36. { project_id: number }
  37. >("POST", (pathParams) => {
  38. return `/api/projects/${pathParams.project_id}/registries`;
  39. });
  40. const createAWSIntegration = baseApi<
  41. {
  42. aws_region: string;
  43. aws_cluster_id?: string;
  44. aws_access_key_id: string;
  45. aws_secret_access_key: string;
  46. },
  47. { id: number }
  48. >("POST", (pathParams) => {
  49. return `/api/projects/${pathParams.id}/integrations/aws`;
  50. });
  51. const overwriteAWSIntegration = baseApi<
  52. {
  53. aws_integration_id: number;
  54. aws_access_key_id: string;
  55. aws_secret_access_key: string;
  56. cluster_id: number;
  57. },
  58. {
  59. project_id: number;
  60. }
  61. >("POST", (pathParams) => {
  62. return `/api/projects/${pathParams.project_id}/integrations/aws/overwrite`;
  63. });
  64. const createDOCR = baseApi<
  65. {
  66. do_integration_id: number;
  67. docr_name: string;
  68. docr_subscription_tier: string;
  69. },
  70. {
  71. project_id: number;
  72. }
  73. >("POST", (pathParams) => {
  74. return `/api/projects/${pathParams.project_id}/provision/docr`;
  75. });
  76. const createDOKS = baseApi<
  77. {
  78. do_integration_id: number;
  79. doks_name: string;
  80. do_region: string;
  81. },
  82. {
  83. project_id: number;
  84. }
  85. >("POST", (pathParams) => {
  86. return `/api/projects/${pathParams.project_id}/provision/doks`;
  87. });
  88. const createEmailVerification = baseApi<{}, {}>("POST", (pathParams) => {
  89. return `/api/email/verify/initiate`;
  90. });
  91. const createGCPIntegration = baseApi<
  92. {
  93. gcp_region: string;
  94. gcp_key_data: string;
  95. gcp_project_id: string;
  96. },
  97. {
  98. project_id: number;
  99. }
  100. >("POST", (pathParams) => {
  101. return `/api/projects/${pathParams.project_id}/integrations/gcp`;
  102. });
  103. const createGCR = baseApi<
  104. {
  105. gcp_integration_id: number;
  106. },
  107. {
  108. project_id: number;
  109. }
  110. >("POST", (pathParams) => {
  111. return `/api/projects/${pathParams.project_id}/provision/gcr`;
  112. });
  113. const createGKE = baseApi<
  114. {
  115. gcp_integration_id: number;
  116. gke_name: string;
  117. },
  118. {
  119. project_id: number;
  120. }
  121. >("POST", (pathParams) => {
  122. return `/api/projects/${pathParams.project_id}/provision/gke`;
  123. });
  124. const createInvite = baseApi<
  125. {
  126. email: string;
  127. kind: string;
  128. },
  129. {
  130. id: number;
  131. }
  132. >("POST", (pathParams) => {
  133. return `/api/projects/${pathParams.id}/invites`;
  134. });
  135. const createPasswordReset = baseApi<
  136. {
  137. email: string;
  138. },
  139. {}
  140. >("POST", (pathParams) => {
  141. return `/api/password/reset/initiate`;
  142. });
  143. const createPasswordResetVerify = baseApi<
  144. {
  145. email: string;
  146. token: string;
  147. token_id: number;
  148. },
  149. {}
  150. >("POST", (pathParams) => {
  151. return `/api/password/reset/verify`;
  152. });
  153. const createPasswordResetFinalize = baseApi<
  154. {
  155. email: string;
  156. token: string;
  157. token_id: number;
  158. new_password: string;
  159. },
  160. {}
  161. >("POST", (pathParams) => {
  162. return `/api/password/reset/finalize`;
  163. });
  164. const createProject = baseApi<{ name: string }, {}>("POST", (pathParams) => {
  165. return `/api/projects`;
  166. });
  167. const createSubdomain = baseApi<
  168. {},
  169. {
  170. id: number;
  171. release_name: string;
  172. namespace: string;
  173. cluster_id: number;
  174. }
  175. >("POST", (pathParams) => {
  176. let { cluster_id, id, namespace, release_name } = pathParams;
  177. return `/api/projects/${id}/clusters/${cluster_id}/namespaces/${namespace}/releases/${release_name}/subdomain`;
  178. });
  179. const deleteCluster = baseApi<
  180. {},
  181. {
  182. project_id: number;
  183. cluster_id: number;
  184. }
  185. >("DELETE", (pathParams) => {
  186. return `/api/projects/${pathParams.project_id}/clusters/${pathParams.cluster_id}`;
  187. });
  188. const deleteInvite = baseApi<{}, { id: number; invId: number }>(
  189. "DELETE",
  190. (pathParams) => {
  191. return `/api/projects/${pathParams.id}/invites/${pathParams.invId}`;
  192. }
  193. );
  194. const deletePod = baseApi<
  195. {},
  196. { name: string; namespace: string; id: number; cluster_id: number }
  197. >("DELETE", (pathParams) => {
  198. let { id, name, cluster_id, namespace } = pathParams;
  199. return `/api/projects/${id}/clusters/${cluster_id}/namespaces/${namespace}/pods/${name}`;
  200. });
  201. const getPodEvents = baseApi<
  202. {},
  203. { name: string; namespace: string; id: number; cluster_id: number }
  204. >("GET", (pathParams) => {
  205. let { id, name, cluster_id, namespace } = pathParams;
  206. return `/api/projects/${id}/clusters/${cluster_id}/namespaces/${namespace}/pods/${name}/events`;
  207. });
  208. const deleteProject = baseApi<{}, { id: number }>("DELETE", (pathParams) => {
  209. return `/api/projects/${pathParams.id}`;
  210. });
  211. const deleteRegistryIntegration = baseApi<
  212. {},
  213. {
  214. project_id: number;
  215. registry_id: number;
  216. }
  217. >("DELETE", (pathParams) => {
  218. return `/api/projects/${pathParams.project_id}/registries/${pathParams.registry_id}`;
  219. });
  220. const deleteSlackIntegration = baseApi<
  221. {},
  222. {
  223. project_id: number;
  224. slack_integration_id: number;
  225. }
  226. >("DELETE", (pathParams) => {
  227. return `/api/projects/${pathParams.project_id}/slack_integrations/${pathParams.slack_integration_id}`;
  228. });
  229. const updateNotificationConfig = baseApi<
  230. {
  231. payload: any;
  232. },
  233. {
  234. project_id: number;
  235. cluster_id: number;
  236. namespace: string;
  237. name: string;
  238. }
  239. >("POST", (pathParams) => {
  240. let { project_id, cluster_id, namespace, name } = pathParams;
  241. return `/api/projects/${project_id}/clusters/${cluster_id}/namespaces/${namespace}/releases/${name}/notifications`;
  242. });
  243. const getNotificationConfig = baseApi<
  244. {},
  245. {
  246. project_id: number;
  247. cluster_id: number;
  248. namespace: string;
  249. name: string;
  250. }
  251. >("GET", (pathParams) => {
  252. let { project_id, cluster_id, namespace, name } = pathParams;
  253. return `/api/projects/${project_id}/clusters/${cluster_id}/namespaces/${namespace}/releases/${name}/notifications`;
  254. });
  255. const getGHAWorkflowTemplate = baseApi<
  256. {
  257. release_name: string;
  258. github_action_config: FullActionConfigType;
  259. },
  260. {
  261. cluster_id: number;
  262. project_id: number;
  263. namespace: string;
  264. }
  265. >("POST", (pathParams) => {
  266. const { cluster_id, project_id, namespace } = pathParams;
  267. return `/api/projects/${project_id}/clusters/${cluster_id}/namespaces/${namespace}/releases/gha_template`;
  268. });
  269. const deployTemplate = baseApi<
  270. {
  271. template_name: string;
  272. template_version: string;
  273. image_url?: string;
  274. values?: any;
  275. name: string;
  276. github_action_config?: FullActionConfigType;
  277. },
  278. {
  279. id: number;
  280. cluster_id: number;
  281. namespace: string;
  282. repo_url?: string;
  283. }
  284. >("POST", (pathParams) => {
  285. let { cluster_id, id, namespace, repo_url } = pathParams;
  286. if (repo_url) {
  287. return `/api/projects/${id}/clusters/${cluster_id}/namespaces/${namespace}/releases?repo_url=${repo_url}`;
  288. }
  289. return `/api/projects/${id}/clusters/${cluster_id}/namespaces/${namespace}/releases`;
  290. });
  291. const deployAddon = baseApi<
  292. {
  293. template_name: string;
  294. template_version: string;
  295. values?: any;
  296. name: string;
  297. },
  298. {
  299. id: number;
  300. cluster_id: number;
  301. namespace: string;
  302. repo_url?: string;
  303. }
  304. >("POST", (pathParams) => {
  305. let { cluster_id, id, namespace, repo_url } = pathParams;
  306. return `/api/projects/${id}/clusters/${cluster_id}/namespaces/${namespace}/addons?repo_url=${repo_url}`;
  307. });
  308. const detectBuildpack = baseApi<
  309. {},
  310. {
  311. project_id: number;
  312. git_repo_id: number;
  313. kind: string;
  314. owner: string;
  315. name: string;
  316. branch: string;
  317. }
  318. >("GET", (pathParams) => {
  319. return `/api/projects/${pathParams.project_id}/gitrepos/${
  320. pathParams.git_repo_id
  321. }/repos/${pathParams.kind}/${pathParams.owner}/${
  322. pathParams.name
  323. }/${encodeURIComponent(pathParams.branch)}/buildpack/detect`;
  324. });
  325. const getBranchContents = baseApi<
  326. {
  327. dir: string;
  328. },
  329. {
  330. project_id: number;
  331. git_repo_id: number;
  332. kind: string;
  333. owner: string;
  334. name: string;
  335. branch: string;
  336. }
  337. >("GET", (pathParams) => {
  338. return `/api/projects/${pathParams.project_id}/gitrepos/${
  339. pathParams.git_repo_id
  340. }/repos/${pathParams.kind}/${pathParams.owner}/${
  341. pathParams.name
  342. }/${encodeURIComponent(pathParams.branch)}/contents`;
  343. });
  344. const getProcfileContents = baseApi<
  345. {
  346. path: string;
  347. },
  348. {
  349. project_id: number;
  350. git_repo_id: number;
  351. kind: string;
  352. owner: string;
  353. name: string;
  354. branch: string;
  355. }
  356. >("GET", (pathParams) => {
  357. return `/api/projects/${pathParams.project_id}/gitrepos/${
  358. pathParams.git_repo_id
  359. }/repos/${pathParams.kind}/${pathParams.owner}/${
  360. pathParams.name
  361. }/${encodeURIComponent(pathParams.branch)}/procfile`;
  362. });
  363. const getBranches = baseApi<
  364. {},
  365. {
  366. project_id: number;
  367. git_repo_id: number;
  368. kind: string;
  369. owner: string;
  370. name: string;
  371. }
  372. >("GET", (pathParams) => {
  373. return `/api/projects/${pathParams.project_id}/gitrepos/${pathParams.git_repo_id}/repos/${pathParams.kind}/${pathParams.owner}/${pathParams.name}/branches`;
  374. });
  375. const getChart = baseApi<
  376. {},
  377. {
  378. id: number;
  379. cluster_id: number;
  380. namespace: string;
  381. name: string;
  382. revision: number;
  383. }
  384. >("GET", (pathParams) => {
  385. let { id, cluster_id, namespace, name, revision } = pathParams;
  386. return `/api/projects/${id}/clusters/${cluster_id}/namespaces/${namespace}/releases/${name}/${revision}`;
  387. });
  388. const getCharts = baseApi<
  389. {
  390. limit: number;
  391. skip: number;
  392. byDate: boolean;
  393. statusFilter: string[];
  394. },
  395. {
  396. id: number;
  397. cluster_id: number;
  398. namespace: string;
  399. }
  400. >("GET", (pathParams) => {
  401. return `/api/projects/${pathParams.id}/clusters/${pathParams.cluster_id}/namespaces/${pathParams.namespace}/releases`;
  402. });
  403. const getChartComponents = baseApi<
  404. {},
  405. {
  406. id: number;
  407. cluster_id: number;
  408. namespace: string;
  409. name: string;
  410. revision: number;
  411. }
  412. >("GET", (pathParams) => {
  413. let { id, cluster_id, namespace, name, revision } = pathParams;
  414. return `/api/projects/${id}/clusters/${cluster_id}/namespaces/${namespace}/releases/${name}/${revision}/components`;
  415. });
  416. const getChartControllers = baseApi<
  417. {},
  418. {
  419. id: number;
  420. cluster_id: number;
  421. namespace: string;
  422. name: string;
  423. revision: number;
  424. }
  425. >("GET", (pathParams) => {
  426. let { id, cluster_id, namespace, name, revision } = pathParams;
  427. return `/api/projects/${id}/clusters/${cluster_id}/namespaces/${namespace}/releases/${name}/${revision}/controllers`;
  428. });
  429. const getClusterIntegrations = baseApi("GET", "/api/integrations/cluster");
  430. const getClusters = baseApi<{}, { id: number }>("GET", (pathParams) => {
  431. return `/api/projects/${pathParams.id}/clusters`;
  432. });
  433. const getCluster = baseApi<
  434. {},
  435. {
  436. project_id: number;
  437. cluster_id: number;
  438. }
  439. >("GET", (pathParams) => {
  440. return `/api/projects/${pathParams.project_id}/clusters/${pathParams.cluster_id}`;
  441. });
  442. const getClusterNodes = baseApi<
  443. {},
  444. {
  445. project_id: number;
  446. cluster_id: number;
  447. }
  448. >("GET", (pathParams) => {
  449. return `/api/projects/${pathParams.project_id}/clusters/${pathParams.cluster_id}/nodes`;
  450. });
  451. const getClusterNode = baseApi<
  452. {},
  453. {
  454. project_id: number;
  455. cluster_id: number;
  456. nodeName: string;
  457. }
  458. >(
  459. "GET",
  460. (pathParams) =>
  461. `/api/projects/${pathParams.project_id}/clusters/${pathParams.cluster_id}/nodes/${pathParams.nodeName}`
  462. );
  463. const getGitRepoList = baseApi<
  464. {},
  465. {
  466. project_id: number;
  467. git_repo_id: number;
  468. }
  469. >("GET", (pathParams) => {
  470. return `/api/projects/${pathParams.project_id}/gitrepos/${pathParams.git_repo_id}/repos`;
  471. });
  472. const getGitRepos = baseApi<
  473. {},
  474. {
  475. project_id: number;
  476. }
  477. >("GET", (pathParams) => {
  478. return `/api/projects/${pathParams.project_id}/gitrepos`;
  479. });
  480. const getImageRepos = baseApi<
  481. {},
  482. {
  483. project_id: number;
  484. registry_id: number;
  485. }
  486. >("GET", (pathParams) => {
  487. return `/api/projects/${pathParams.project_id}/registries/${pathParams.registry_id}/repositories`;
  488. });
  489. const getImageTags = baseApi<
  490. {},
  491. {
  492. project_id: number;
  493. registry_id: number;
  494. repo_name: string;
  495. }
  496. >("GET", (pathParams) => {
  497. return `/api/projects/${pathParams.project_id}/registries/${pathParams.registry_id}/repositories/${pathParams.repo_name}`;
  498. });
  499. const getInfra = baseApi<
  500. {},
  501. {
  502. project_id: number;
  503. }
  504. >("GET", (pathParams) => {
  505. return `/api/projects/${pathParams.project_id}/infra`;
  506. });
  507. const getIngress = baseApi<
  508. {},
  509. { namespace: string; cluster_id: number; name: string; id: number }
  510. >("GET", (pathParams) => {
  511. let { id, name, cluster_id, namespace } = pathParams;
  512. return `/api/projects/${id}/clusters/${cluster_id}/namespaces/${namespace}/ingresses/${name}`;
  513. });
  514. const getInvites = baseApi<{}, { id: number }>("GET", (pathParams) => {
  515. return `/api/projects/${pathParams.id}/invites`;
  516. });
  517. const getJobs = baseApi<
  518. {},
  519. { namespace: string; cluster_id: number; release_name: string; id: number }
  520. >("GET", (pathParams) => {
  521. let { id, release_name, cluster_id, namespace } = pathParams;
  522. return `/api/projects/${id}/clusters/${cluster_id}/namespaces/${namespace}/releases/${release_name}/0/jobs`;
  523. });
  524. const getJobStatus = baseApi<
  525. {},
  526. { namespace: string; cluster_id: number; release_name: string; id: number }
  527. >("GET", (pathParams) => {
  528. let { id, release_name, cluster_id, namespace } = pathParams;
  529. return `/api/projects/${id}/clusters/${cluster_id}/namespaces/${namespace}/releases/${release_name}/0/jobs/status`;
  530. });
  531. const getJobPods = baseApi<
  532. {},
  533. { name: string; namespace: string; id: number; cluster_id: number }
  534. >("GET", (pathParams) => {
  535. let { id, name, cluster_id, namespace } = pathParams;
  536. return `/api/projects/${id}/clusters/${cluster_id}/namespaces/${namespace}/jobs/${name}/pods`;
  537. });
  538. const getMatchingPods = baseApi<
  539. {
  540. namespace: string;
  541. selectors: string[];
  542. },
  543. { id: number; cluster_id: number }
  544. >("GET", (pathParams) => {
  545. return `/api/projects/${pathParams.id}/clusters/${pathParams.cluster_id}/pods`;
  546. });
  547. const getMetrics = baseApi<
  548. {
  549. metric: string;
  550. shouldsum: boolean;
  551. pods?: string[];
  552. kind?: string; // the controller kind
  553. name?: string;
  554. percentile?: number;
  555. namespace: string;
  556. startrange: number;
  557. endrange: number;
  558. resolution: string;
  559. },
  560. {
  561. id: number;
  562. cluster_id: number;
  563. }
  564. >("GET", (pathParams) => {
  565. return `/api/projects/${pathParams.id}/clusters/${pathParams.cluster_id}/metrics`;
  566. });
  567. const getNamespaces = baseApi<
  568. {},
  569. {
  570. id: number;
  571. cluster_id: number;
  572. }
  573. >("GET", (pathParams) => {
  574. return `/api/projects/${pathParams.id}/clusters/${pathParams.cluster_id}/namespaces`;
  575. });
  576. const getNGINXIngresses = baseApi<
  577. {},
  578. {
  579. id: number;
  580. cluster_id: number;
  581. }
  582. >("GET", (pathParams) => {
  583. return `/api/projects/${pathParams.id}/clusters/${pathParams.cluster_id}/prometheus/ingresses`;
  584. });
  585. const getOAuthIds = baseApi<
  586. {},
  587. {
  588. project_id: number;
  589. }
  590. >("GET", (pathParams) => {
  591. return `/api/projects/${pathParams.project_id}/integrations/oauth`;
  592. });
  593. const getProjectClusters = baseApi<{}, { id: number }>("GET", (pathParams) => {
  594. return `/api/projects/${pathParams.id}/clusters`;
  595. });
  596. const getProjectRegistries = baseApi<{}, { id: number }>(
  597. "GET",
  598. (pathParams) => {
  599. return `/api/projects/${pathParams.id}/registries`;
  600. }
  601. );
  602. const getProjectRepos = baseApi<{}, { id: number }>("GET", (pathParams) => {
  603. return `/api/projects/${pathParams.id}/repos`;
  604. });
  605. const getProjects = baseApi("GET", "/api/projects");
  606. const getPrometheusIsInstalled = baseApi<
  607. {},
  608. {
  609. id: number;
  610. cluster_id: number;
  611. }
  612. >("GET", (pathParams) => {
  613. return `/api/projects/${pathParams.id}/clusters/${pathParams.cluster_id}/prometheus/detect`;
  614. });
  615. const getRegistryIntegrations = baseApi("GET", "/api/integrations/registry");
  616. const getReleaseToken = baseApi<
  617. {},
  618. { name: string; id: number; namespace: string; cluster_id: number }
  619. >("GET", (pathParams) => {
  620. let { id, cluster_id, namespace, name } = pathParams;
  621. return `/api/projects/${id}/clusters/${cluster_id}/namespaces/${namespace}/releases/${name}/webhook`;
  622. });
  623. const getReleaseSteps = baseApi<
  624. {},
  625. { name: string; id: number; namespace: string; cluster_id: number }
  626. >("GET", (pathParams) => {
  627. let { id, cluster_id, namespace, name } = pathParams;
  628. return `/api/projects/${id}/clusters/${cluster_id}/namespaces/${namespace}/releases/${name}/steps`;
  629. });
  630. const destroyInfra = baseApi<
  631. {
  632. name: string;
  633. },
  634. {
  635. project_id: number;
  636. infra_id: number;
  637. }
  638. >("DELETE", (pathParams) => {
  639. return `/api/projects/${pathParams.project_id}/infras/${pathParams.infra_id}`;
  640. });
  641. const getRepoIntegrations = baseApi("GET", "/api/integrations/repo");
  642. const getRepos = baseApi<{}, { id: number }>("GET", (pathParams) => {
  643. return `/api/projects/${pathParams.id}/repos`;
  644. });
  645. const getSlackIntegrations = baseApi<{}, { id: number }>(
  646. "GET",
  647. (pathParams) => {
  648. return `/api/projects/${pathParams.id}/slack_integrations`;
  649. }
  650. );
  651. const getRevisions = baseApi<
  652. {},
  653. { id: number; cluster_id: number; namespace: string; name: string }
  654. >("GET", (pathParams) => {
  655. let { id, cluster_id, namespace, name } = pathParams;
  656. return `/api/projects/${id}/clusters/${cluster_id}/namespaces/${namespace}/releases/${name}/history`;
  657. });
  658. const getTemplateInfo = baseApi<
  659. {
  660. repo_url?: string;
  661. },
  662. { name: string; version: string }
  663. >("GET", (pathParams) => {
  664. return `/api/templates/${pathParams.name}/${pathParams.version}`;
  665. });
  666. const getTemplateUpgradeNotes = baseApi<
  667. {
  668. repo_url?: string;
  669. prev_version: string;
  670. },
  671. { name: string; version: string }
  672. >("GET", (pathParams) => {
  673. return `/api/templates/${pathParams.name}/${pathParams.version}/upgrade_notes`;
  674. });
  675. const getTemplates = baseApi<
  676. {
  677. repo_url?: string;
  678. },
  679. {}
  680. >("GET", "/api/templates");
  681. const getMetadata = baseApi<{}, {}>("GET", () => {
  682. return `/api/metadata`;
  683. });
  684. const postWelcome = baseApi<{
  685. email: string;
  686. isCompany: boolean;
  687. company: string;
  688. role: string;
  689. }>("POST", () => {
  690. return `/api/welcome`;
  691. });
  692. const linkGithubProject = baseApi<
  693. {},
  694. {
  695. project_id: number;
  696. }
  697. >("GET", (pathParams) => {
  698. return `/api/oauth/projects/${pathParams.project_id}/github`;
  699. });
  700. const getGithubAccounts = baseApi<{}, {}>("GET", () => {
  701. return `/api/integrations/github-app/accounts`;
  702. });
  703. const logInUser = baseApi<{
  704. email: string;
  705. password: string;
  706. }>("POST", "/api/login");
  707. const logOutUser = baseApi("POST", "/api/logout");
  708. const provisionECR = baseApi<
  709. {
  710. ecr_name: string;
  711. aws_integration_id: string;
  712. },
  713. { id: number }
  714. >("POST", (pathParams) => {
  715. return `/api/projects/${pathParams.id}/provision/ecr`;
  716. });
  717. const provisionEKS = baseApi<
  718. {
  719. eks_name: string;
  720. aws_integration_id: string;
  721. machine_type: string;
  722. },
  723. { id: number }
  724. >("POST", (pathParams) => {
  725. return `/api/projects/${pathParams.id}/provision/eks`;
  726. });
  727. const registerUser = baseApi<{
  728. email: string;
  729. password: string;
  730. }>("POST", "/api/users");
  731. const rollbackChart = baseApi<
  732. {
  733. revision: number;
  734. },
  735. {
  736. id: number;
  737. name: string;
  738. namespace: string;
  739. cluster_id: number;
  740. }
  741. >("POST", (pathParams) => {
  742. let { id, name, cluster_id, namespace } = pathParams;
  743. return `/api/projects/${id}/clusters/${cluster_id}/namespaces/${namespace}/releases/${name}/0/rollback`;
  744. });
  745. const uninstallTemplate = baseApi<
  746. {},
  747. {
  748. id: number;
  749. name: string;
  750. cluster_id: number;
  751. namespace: string;
  752. }
  753. >("DELETE", (pathParams) => {
  754. let { id, name, cluster_id, namespace } = pathParams;
  755. return `/api/projects/${id}/clusters/${cluster_id}/namespaces/${namespace}/releases/${name}/0`;
  756. });
  757. const updateUser = baseApi<
  758. {
  759. rawKubeConfig?: string;
  760. allowedContexts?: string[];
  761. },
  762. { id: number }
  763. >("PUT", (pathParams) => {
  764. return `/api/users/${pathParams.id}`;
  765. });
  766. const upgradeChartValues = baseApi<
  767. {
  768. values: string;
  769. version?: string;
  770. },
  771. {
  772. id: number;
  773. name: string;
  774. namespace: string;
  775. cluster_id: number;
  776. }
  777. >("POST", (pathParams) => {
  778. let { id, name, cluster_id, namespace } = pathParams;
  779. return `/api/projects/${id}/clusters/${cluster_id}/namespaces/${namespace}/releases/${name}/0/upgrade`;
  780. });
  781. const listConfigMaps = baseApi<
  782. {},
  783. {
  784. id: number;
  785. namespace: string;
  786. cluster_id: number;
  787. }
  788. >("GET", (pathParams) => {
  789. return `/api/projects/${pathParams.id}/clusters/${pathParams.cluster_id}/namespaces/${pathParams.namespace}/configmap/list`;
  790. });
  791. const getConfigMap = baseApi<
  792. {
  793. name: string;
  794. },
  795. {
  796. id: number;
  797. namespace: string;
  798. cluster_id: number;
  799. }
  800. >("GET", (pathParams) => {
  801. return `/api/projects/${pathParams.id}/clusters/${pathParams.cluster_id}/namespaces/${pathParams.namespace}/configmap`;
  802. });
  803. const createConfigMap = baseApi<
  804. {
  805. name: string;
  806. variables: Record<string, string>;
  807. secret_variables?: Record<string, string>;
  808. },
  809. {
  810. id: number;
  811. cluster_id: number;
  812. namespace: string;
  813. }
  814. >("POST", (pathParams) => {
  815. return `/api/projects/${pathParams.id}/clusters/${pathParams.cluster_id}/namespaces/${pathParams.namespace}/configmap/create`;
  816. });
  817. const updateConfigMap = baseApi<
  818. {
  819. name: string;
  820. variables: Record<string, string>;
  821. secret_variables?: Record<string, string>;
  822. },
  823. {
  824. id: number;
  825. cluster_id: number;
  826. namespace: string;
  827. }
  828. >("POST", (pathParams) => {
  829. let { id, cluster_id } = pathParams;
  830. return `/api/projects/${pathParams.id}/clusters/${pathParams.cluster_id}/namespaces/${pathParams.namespace}/configmap/update`;
  831. });
  832. const renameConfigMap = baseApi<
  833. {
  834. name: string;
  835. new_name: string;
  836. },
  837. {
  838. id: number;
  839. cluster_id: number;
  840. namespace: string;
  841. }
  842. >("POST", (pathParams) => {
  843. return `/api/projects/${pathParams.id}/clusters/${pathParams.cluster_id}/namespaces/${pathParams.namespace}/configmap/rename`;
  844. });
  845. const deleteConfigMap = baseApi<
  846. {
  847. name: string;
  848. },
  849. {
  850. id: number;
  851. namespace: string;
  852. cluster_id: number;
  853. }
  854. >("DELETE", (pathParams) => {
  855. return `/api/projects/${pathParams.id}/clusters/${pathParams.cluster_id}/namespaces/${pathParams.namespace}/configmap/delete`;
  856. });
  857. const createNamespace = baseApi<
  858. {
  859. name: string;
  860. },
  861. { id: number; cluster_id: number }
  862. >("POST", (pathParams) => {
  863. let { id, cluster_id } = pathParams;
  864. return `/api/projects/${id}/clusters/${cluster_id}/namespaces/create`;
  865. });
  866. const deleteNamespace = baseApi<
  867. {
  868. name: string;
  869. },
  870. {
  871. id: number;
  872. cluster_id: number;
  873. }
  874. >("DELETE", (pathParams) => {
  875. let { id, cluster_id } = pathParams;
  876. return `/api/projects/${id}/clusters/${cluster_id}/namespaces/delete`;
  877. });
  878. const deleteJob = baseApi<
  879. {},
  880. { name: string; namespace: string; id: number; cluster_id: number }
  881. >("DELETE", (pathParams) => {
  882. let { id, name, cluster_id, namespace } = pathParams;
  883. return `/api/projects/${id}/clusters/${cluster_id}/namespaces/${namespace}/jobs/${name}`;
  884. });
  885. const stopJob = baseApi<
  886. {},
  887. { name: string; namespace: string; id: number; cluster_id: number }
  888. >("POST", (pathParams) => {
  889. let { id, name, namespace, cluster_id } = pathParams;
  890. return `/api/projects/${id}/clusters/${cluster_id}/namespaces/${namespace}/jobs/${name}/stop`;
  891. });
  892. const getAvailableRoles = baseApi<{}, { project_id: number }>(
  893. "GET",
  894. ({ project_id }) => `/api/projects/${project_id}/roles`
  895. );
  896. const updateInvite = baseApi<
  897. { kind: string },
  898. { project_id: number; invite_id: number }
  899. >(
  900. "POST",
  901. ({ project_id, invite_id }) =>
  902. `/api/projects/${project_id}/invites/${invite_id}`
  903. );
  904. const getCollaborators = baseApi<{}, { project_id: number }>(
  905. "GET",
  906. ({ project_id }) => `/api/projects/${project_id}/collaborators`
  907. );
  908. const updateCollaborator = baseApi<
  909. {
  910. kind: string;
  911. user_id: number;
  912. },
  913. { project_id: number }
  914. >("POST", ({ project_id }) => `/api/projects/${project_id}/roles`);
  915. const removeCollaborator = baseApi<{ user_id: number }, { project_id: number }>(
  916. "DELETE",
  917. ({ project_id }) => `/api/projects/${project_id}/roles`
  918. );
  919. const getPolicyDocument = baseApi<{}, { project_id: number }>(
  920. "GET",
  921. ({ project_id }) => `/api/projects/${project_id}/policy`
  922. );
  923. const createWebhookToken = baseApi<
  924. {},
  925. {
  926. project_id: number;
  927. chart_name: string;
  928. namespace: string;
  929. cluster_id: number;
  930. }
  931. >(
  932. "POST",
  933. ({ project_id, chart_name, namespace, cluster_id }) =>
  934. `/api/projects/${project_id}/clusters/${cluster_id}/namespaces/${namespace}/releases/${chart_name}/0/webhook`
  935. );
  936. const getUsage = baseApi<{}, { project_id: number }>(
  937. "GET",
  938. ({ project_id }) => `/api/projects/${project_id}/usage`
  939. );
  940. // Used for billing purposes
  941. const getCustomerToken = baseApi<{}, { project_id: number }>(
  942. "GET",
  943. ({ project_id }) => `/api/projects/${project_id}/billing/token`
  944. );
  945. const getHasBilling = baseApi<{}, { project_id: number }>(
  946. "GET",
  947. ({ project_id }) => `/api/projects/${project_id}/billing`
  948. );
  949. const getOnboardingState = baseApi<{}, { project_id: number }>(
  950. "GET",
  951. ({ project_id }) => `/api/projects/${project_id}/onboarding`
  952. );
  953. const saveOnboardingState = baseApi<{}, { project_id: number }>(
  954. "POST",
  955. ({ project_id }) => `/api/projects/${project_id}/onboarding`
  956. );
  957. const getOnboardingInfra = baseApi<
  958. {},
  959. { project_id: number; registry_infra_id: number }
  960. >(
  961. "GET",
  962. ({ project_id, registry_infra_id }) =>
  963. `/api/projects/${project_id}/infras/${registry_infra_id}`
  964. );
  965. const getOnboardingRegistry = baseApi<
  966. {},
  967. { project_id: number; registry_connection_id: number }
  968. >(
  969. "GET",
  970. ({ project_id, registry_connection_id }) =>
  971. `/api/projects/${project_id}/registries/${registry_connection_id}`
  972. );
  973. // Bundle export to allow default api import (api.<method> is more readable)
  974. export default {
  975. checkAuth,
  976. connectECRRegistry,
  977. connectGCRRegistry,
  978. connectDORegistry,
  979. createAWSIntegration,
  980. overwriteAWSIntegration,
  981. createDOCR,
  982. createDOKS,
  983. createEmailVerification,
  984. createGCPIntegration,
  985. createGCR,
  986. createGKE,
  987. createInvite,
  988. createNamespace,
  989. createPasswordReset,
  990. createPasswordResetVerify,
  991. createPasswordResetFinalize,
  992. createProject,
  993. createConfigMap,
  994. deleteCluster,
  995. deleteConfigMap,
  996. deleteInvite,
  997. deleteNamespace,
  998. deletePod,
  999. deleteProject,
  1000. deleteRegistryIntegration,
  1001. deleteSlackIntegration,
  1002. updateNotificationConfig,
  1003. getNotificationConfig,
  1004. createSubdomain,
  1005. deployTemplate,
  1006. deployAddon,
  1007. destroyInfra,
  1008. detectBuildpack,
  1009. getBranchContents,
  1010. getBranches,
  1011. getMetadata,
  1012. postWelcome,
  1013. getChart,
  1014. getCharts,
  1015. getChartComponents,
  1016. getChartControllers,
  1017. getClusterIntegrations,
  1018. getClusters,
  1019. getCluster,
  1020. getClusterNodes,
  1021. getClusterNode,
  1022. getConfigMap,
  1023. getGHAWorkflowTemplate,
  1024. getGitRepoList,
  1025. getGitRepos,
  1026. getImageRepos,
  1027. getImageTags,
  1028. getInfra,
  1029. getIngress,
  1030. getInvites,
  1031. getJobs,
  1032. getJobStatus,
  1033. getJobPods,
  1034. getMatchingPods,
  1035. getMetrics,
  1036. getNamespaces,
  1037. getNGINXIngresses,
  1038. getOAuthIds,
  1039. getPodEvents,
  1040. getProcfileContents,
  1041. getProjectClusters,
  1042. getProjectRegistries,
  1043. getProjectRepos,
  1044. getProjects,
  1045. getPrometheusIsInstalled,
  1046. getRegistryIntegrations,
  1047. getReleaseToken,
  1048. getReleaseSteps,
  1049. getRepoIntegrations,
  1050. getSlackIntegrations,
  1051. getRepos,
  1052. getRevisions,
  1053. getTemplateInfo,
  1054. getTemplateUpgradeNotes,
  1055. getTemplates,
  1056. linkGithubProject,
  1057. getGithubAccounts,
  1058. listConfigMaps,
  1059. logInUser,
  1060. logOutUser,
  1061. provisionECR,
  1062. provisionEKS,
  1063. registerUser,
  1064. rollbackChart,
  1065. uninstallTemplate,
  1066. updateUser,
  1067. renameConfigMap,
  1068. updateConfigMap,
  1069. upgradeChartValues,
  1070. deleteJob,
  1071. stopJob,
  1072. updateInvite,
  1073. getAvailableRoles,
  1074. getCollaborators,
  1075. updateCollaborator,
  1076. removeCollaborator,
  1077. getPolicyDocument,
  1078. createWebhookToken,
  1079. getUsage,
  1080. getCustomerToken,
  1081. getHasBilling,
  1082. getOnboardingState,
  1083. saveOnboardingState,
  1084. getOnboardingInfra,
  1085. getOnboardingRegistry,
  1086. };