@datalayer/core 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (641) hide show
  1. package/README.md +176 -7
  2. package/lib/App.d.ts +3 -0
  3. package/lib/App.js +4 -0
  4. package/lib/__tests__/App.test.d.ts +1 -0
  5. package/lib/__tests__/App.test.js +17 -0
  6. package/lib/__tests__/hooks.test.d.ts +1 -0
  7. package/lib/__tests__/hooks.test.js +19 -0
  8. package/lib/__tests__/index.test.d.ts +1 -0
  9. package/lib/__tests__/index.test.js +26 -0
  10. package/lib/__tests__/integration.test.d.ts +1 -0
  11. package/lib/__tests__/integration.test.js +57 -0
  12. package/lib/__tests__/utils.test.d.ts +1 -0
  13. package/lib/__tests__/utils.test.js +59 -0
  14. package/lib/api/RunApi.d.ts +75 -0
  15. package/lib/api/RunApi.js +150 -0
  16. package/lib/api/index.d.ts +2 -0
  17. package/lib/api/index.js +11 -0
  18. package/lib/api/runtimes/exec/Python.d.ts +5 -0
  19. package/lib/api/runtimes/exec/Python.js +105 -0
  20. package/lib/api/runtimes/exec/Snippets.d.ts +145 -0
  21. package/lib/api/runtimes/exec/Snippets.js +125 -0
  22. package/lib/api/runtimes/exec/index.d.ts +2 -0
  23. package/lib/api/runtimes/exec/index.js +11 -0
  24. package/lib/api/runtimes/index.d.ts +7 -0
  25. package/lib/api/runtimes/index.js +16 -0
  26. package/lib/api/runtimes/kernelsHandler.d.ts +8 -0
  27. package/lib/api/runtimes/kernelsHandler.js +44 -0
  28. package/lib/api/runtimes/models.d.ts +59 -0
  29. package/lib/api/runtimes/models.js +11 -0
  30. package/lib/api/runtimes/runtimesApi.d.ts +370 -0
  31. package/lib/api/runtimes/runtimesApi.js +269 -0
  32. package/lib/api/runtimes/settings.d.ts +15 -0
  33. package/lib/api/runtimes/settings.js +36 -0
  34. package/lib/api/runtimes/snapshots.d.ts +25 -0
  35. package/lib/api/runtimes/snapshots.js +155 -0
  36. package/lib/api/runtimes/utils.d.ts +7 -0
  37. package/lib/api/runtimes/utils.js +22 -0
  38. package/lib/components/avatars/BoringAvatar.d.ts +20 -0
  39. package/lib/components/avatars/BoringAvatar.js +39 -0
  40. package/lib/components/avatars/UserProfileAvatar.d.ts +13 -0
  41. package/lib/components/avatars/UserProfileAvatar.js +37 -0
  42. package/lib/components/avatars/index.d.ts +2 -0
  43. package/lib/components/avatars/index.js +11 -0
  44. package/lib/components/banners/NoAutomationBanner.d.ts +2 -0
  45. package/lib/components/banners/NoAutomationBanner.js +18 -0
  46. package/lib/components/banners/index.d.ts +1 -0
  47. package/lib/components/banners/index.js +10 -0
  48. package/lib/components/buttons/DownloadCSVButton.d.ts +13 -0
  49. package/lib/components/buttons/DownloadCSVButton.js +21 -0
  50. package/lib/components/buttons/DownloadJsonButton.d.ts +16 -0
  51. package/lib/components/buttons/DownloadJsonButton.js +23 -0
  52. package/lib/components/buttons/LongActionButton.d.ts +28 -0
  53. package/lib/components/buttons/LongActionButton.js +29 -0
  54. package/lib/components/buttons/UploadButton.d.ts +37 -0
  55. package/lib/components/buttons/UploadButton.js +48 -0
  56. package/lib/components/buttons/VariantType.d.ts +1 -0
  57. package/lib/components/buttons/VariantType.js +5 -0
  58. package/lib/components/buttons/index.d.ts +5 -0
  59. package/lib/components/buttons/index.js +14 -0
  60. package/lib/components/checkout/StripeCheckout.d.ts +32 -0
  61. package/lib/components/checkout/StripeCheckout.js +100 -0
  62. package/lib/components/checkout/index.d.ts +1 -0
  63. package/lib/components/checkout/index.js +10 -0
  64. package/lib/components/confetti/ConfettiSuccess.d.ts +2 -0
  65. package/lib/components/confetti/ConfettiSuccess.js +17 -0
  66. package/lib/components/confetti/index.d.ts +1 -0
  67. package/lib/components/confetti/index.js +10 -0
  68. package/lib/components/context/OrganizationSelect.d.ts +2 -0
  69. package/lib/components/context/OrganizationSelect.js +40 -0
  70. package/lib/components/context/SpaceSelect.d.ts +2 -0
  71. package/lib/components/context/SpaceSelect.js +48 -0
  72. package/lib/components/context/index.d.ts +2 -0
  73. package/lib/components/context/index.js +11 -0
  74. package/lib/components/display/AvatarSkeleton.d.ts +5 -0
  75. package/lib/components/display/AvatarSkeleton.js +16 -0
  76. package/lib/components/display/CenteredSpinner.d.ts +14 -0
  77. package/lib/components/display/CenteredSpinner.js +25 -0
  78. package/lib/components/display/CodePreview.d.ts +4 -0
  79. package/lib/components/display/CodePreview.js +20 -0
  80. package/lib/components/display/DatalayerBox.d.ts +8 -0
  81. package/lib/components/display/DatalayerBox.js +33 -0
  82. package/lib/components/display/HorizontalCenter.d.ts +9 -0
  83. package/lib/components/display/HorizontalCenter.js +14 -0
  84. package/lib/components/display/JupyterDialog.d.ts +69 -0
  85. package/lib/components/display/JupyterDialog.js +120 -0
  86. package/lib/components/display/Markdown.d.ts +23 -0
  87. package/lib/components/display/Markdown.js +20 -0
  88. package/lib/components/display/NavLink.d.ts +9 -0
  89. package/lib/components/display/NavLink.js +22 -0
  90. package/lib/components/display/NotebookSkeleton.d.ts +2 -0
  91. package/lib/components/display/NotebookSkeleton.js +16 -0
  92. package/lib/components/display/Placeholder.d.ts +2 -0
  93. package/lib/components/display/Placeholder.js +14 -0
  94. package/lib/components/display/ToTopBranded.d.ts +2 -0
  95. package/lib/components/display/ToTopBranded.js +16 -0
  96. package/lib/components/display/VisuallyHidden.d.ts +5 -0
  97. package/lib/components/display/VisuallyHidden.js +29 -0
  98. package/lib/components/display/index.d.ts +12 -0
  99. package/lib/components/display/index.js +21 -0
  100. package/lib/components/echarts/EChartsReact.d.ts +11 -0
  101. package/lib/components/echarts/EChartsReact.js +53 -0
  102. package/lib/components/echarts/index.d.ts +1 -0
  103. package/lib/components/echarts/index.js +10 -0
  104. package/lib/components/flashes/FlashClosable.d.ts +22 -0
  105. package/lib/components/flashes/FlashClosable.js +69 -0
  106. package/lib/components/flashes/FlashDisclaimer.d.ts +2 -0
  107. package/lib/components/flashes/FlashDisclaimer.js +23 -0
  108. package/lib/components/flashes/FlashGuest.d.ts +2 -0
  109. package/lib/components/flashes/FlashGuest.js +35 -0
  110. package/lib/components/flashes/FlashSurveys.d.ts +6 -0
  111. package/lib/components/flashes/FlashSurveys.js +41 -0
  112. package/lib/components/flashes/FlashUnauthorized.d.ts +2 -0
  113. package/lib/components/flashes/FlashUnauthorized.js +23 -0
  114. package/lib/components/flashes/index.d.ts +6 -0
  115. package/lib/components/flashes/index.js +15 -0
  116. package/lib/components/flashes/surveys/Survey2025_1.d.ts +3 -0
  117. package/lib/components/flashes/surveys/Survey2025_1.js +134 -0
  118. package/lib/components/flashes/surveys/SurveyProps.d.ts +6 -0
  119. package/lib/components/flashes/surveys/SurveyProps.js +5 -0
  120. package/lib/components/flashes/surveys/index.d.ts +2 -0
  121. package/lib/components/flashes/surveys/index.js +11 -0
  122. package/lib/components/iam/ExternalTokenSilentLogin.d.ts +5 -0
  123. package/lib/components/iam/ExternalTokenSilentLogin.js +38 -0
  124. package/lib/components/iam/index.d.ts +1 -0
  125. package/lib/components/iam/index.js +10 -0
  126. package/lib/components/icons/ArtifactIcon.d.ts +10 -0
  127. package/lib/components/icons/ArtifactIcon.js +63 -0
  128. package/lib/components/icons/index.d.ts +1 -0
  129. package/lib/components/icons/index.js +10 -0
  130. package/lib/components/index.d.ts +1 -0
  131. package/lib/components/index.js +10 -0
  132. package/lib/components/labels/VisibilityLabel.d.ts +4 -0
  133. package/lib/components/labels/VisibilityLabel.js +22 -0
  134. package/lib/components/labels/index.d.ts +1 -0
  135. package/lib/components/labels/index.js +10 -0
  136. package/lib/components/landings/StepBlock.d.ts +11 -0
  137. package/lib/components/landings/StepBlock.js +17 -0
  138. package/lib/components/landings/index.d.ts +1 -0
  139. package/lib/components/landings/index.js +10 -0
  140. package/lib/components/navbar/NavigationVisbilityObserver.d.ts +5 -0
  141. package/lib/components/navbar/NavigationVisbilityObserver.js +63 -0
  142. package/lib/components/navbar/SubdomainNavBar.d.ts +81 -0
  143. package/lib/components/navbar/SubdomainNavBar.js +240 -0
  144. package/lib/components/navbar/index.d.ts +2 -0
  145. package/lib/components/navbar/index.js +11 -0
  146. package/lib/components/nbgrader/NbGradesDetails.d.ts +5 -0
  147. package/lib/components/nbgrader/NbGradesDetails.js +22 -0
  148. package/lib/components/nbgrader/index.d.ts +1 -0
  149. package/lib/components/nbgrader/index.js +10 -0
  150. package/lib/components/notebooks/JupyterNotebook.d.ts +12 -0
  151. package/lib/components/notebooks/JupyterNotebook.js +41 -0
  152. package/lib/components/notebooks/JupyterNotebookToolbar.d.ts +2 -0
  153. package/lib/components/notebooks/JupyterNotebookToolbar.js +44 -0
  154. package/lib/components/notebooks/index.d.ts +2 -0
  155. package/lib/components/notebooks/index.js +11 -0
  156. package/lib/components/primer/Helper.d.ts +32 -0
  157. package/lib/components/primer/Helper.js +19 -0
  158. package/lib/components/primer/Portals.d.ts +9 -0
  159. package/lib/components/primer/Portals.js +31 -0
  160. package/lib/components/primer/Styles.d.ts +2 -0
  161. package/lib/components/primer/Styles.js +16 -0
  162. package/lib/components/primer/index.d.ts +2 -0
  163. package/lib/components/primer/index.js +11 -0
  164. package/lib/components/progress/ConsumptionBar.d.ts +40 -0
  165. package/lib/components/progress/ConsumptionBar.js +54 -0
  166. package/lib/components/progress/CreditsIndicator.d.ts +27 -0
  167. package/lib/components/progress/CreditsIndicator.js +30 -0
  168. package/lib/components/progress/ProgressBar.d.ts +2 -0
  169. package/lib/components/progress/ProgressBar.js +26 -0
  170. package/lib/components/progress/ProgressRing.d.ts +36 -0
  171. package/lib/components/progress/ProgressRing.js +31 -0
  172. package/lib/components/progress/Timer.d.ts +9 -0
  173. package/lib/components/progress/Timer.js +33 -0
  174. package/lib/components/progress/index.d.ts +5 -0
  175. package/lib/components/progress/index.js +14 -0
  176. package/lib/components/runtimes/RuntimeCellVariables.d.ts +39 -0
  177. package/lib/components/runtimes/RuntimeCellVariables.js +177 -0
  178. package/lib/components/runtimes/RuntimeCellVariablesDialog.d.ts +37 -0
  179. package/lib/components/runtimes/RuntimeCellVariablesDialog.js +106 -0
  180. package/lib/components/runtimes/RuntimeLauncherDialog.d.ts +54 -0
  181. package/lib/components/runtimes/RuntimeLauncherDialog.js +254 -0
  182. package/lib/components/runtimes/RuntimePickerBase.d.ts +69 -0
  183. package/lib/components/runtimes/RuntimePickerBase.js +114 -0
  184. package/lib/components/runtimes/RuntimePickerCell.d.ts +34 -0
  185. package/lib/components/runtimes/RuntimePickerCell.js +111 -0
  186. package/lib/components/runtimes/RuntimePickerNotebook.d.ts +43 -0
  187. package/lib/components/runtimes/RuntimePickerNotebook.js +173 -0
  188. package/lib/components/runtimes/RuntimeReservationControl.d.ts +47 -0
  189. package/lib/components/runtimes/RuntimeReservationControl.js +43 -0
  190. package/lib/components/runtimes/RuntimeSimplePicker.d.ts +34 -0
  191. package/lib/components/runtimes/RuntimeSimplePicker.js +161 -0
  192. package/lib/components/runtimes/RuntimeTransfer.d.ts +16 -0
  193. package/lib/components/runtimes/RuntimeTransfer.js +5 -0
  194. package/lib/components/runtimes/RuntimeUtils.d.ts +17 -0
  195. package/lib/components/runtimes/RuntimeUtils.js +173 -0
  196. package/lib/components/runtimes/RuntimeVariables.d.ts +38 -0
  197. package/lib/components/runtimes/RuntimeVariables.js +80 -0
  198. package/lib/components/runtimes/index.d.ts +11 -0
  199. package/lib/components/runtimes/index.js +20 -0
  200. package/lib/components/screenshot/ScreenCapture.d.ts +38 -0
  201. package/lib/components/screenshot/ScreenCapture.js +179 -0
  202. package/lib/components/screenshot/ScreenCaptureButton.d.ts +3 -0
  203. package/lib/components/screenshot/ScreenCaptureButton.js +21 -0
  204. package/lib/components/screenshot/index.d.ts +2 -0
  205. package/lib/components/screenshot/index.js +11 -0
  206. package/lib/components/snapshots/RuntimeSnapshotMenu.d.ts +36 -0
  207. package/lib/components/snapshots/RuntimeSnapshotMenu.js +169 -0
  208. package/lib/components/snapshots/index.d.ts +1 -0
  209. package/lib/components/snapshots/index.js +10 -0
  210. package/lib/components/snippets/SnippetDialog.d.ts +42 -0
  211. package/lib/components/snippets/SnippetDialog.js +47 -0
  212. package/lib/components/snippets/index.d.ts +1 -0
  213. package/lib/components/snippets/index.js +10 -0
  214. package/lib/components/storage/ContentsBrowser.d.ts +32 -0
  215. package/lib/components/storage/ContentsBrowser.js +250 -0
  216. package/lib/components/storage/ContentsItems.d.ts +58 -0
  217. package/lib/components/storage/ContentsItems.js +83 -0
  218. package/lib/components/storage/index.d.ts +2 -0
  219. package/lib/components/storage/index.js +11 -0
  220. package/lib/components/students/StudentItemStatus.d.ts +7 -0
  221. package/lib/components/students/StudentItemStatus.js +49 -0
  222. package/lib/components/students/index.d.ts +1 -0
  223. package/lib/components/students/index.js +10 -0
  224. package/lib/components/subnav/SubNav.d.ts +84 -0
  225. package/lib/components/subnav/SubNav.js +270 -0
  226. package/lib/components/subnav/index.d.ts +1 -0
  227. package/lib/components/subnav/index.js +10 -0
  228. package/lib/components/tables/DataTable.d.ts +5 -0
  229. package/lib/components/tables/DataTable.js +24 -0
  230. package/lib/components/tables/index.d.ts +1 -0
  231. package/lib/components/tables/index.js +10 -0
  232. package/lib/components/text-reveal/TextRevealAnimation.d.ts +6 -0
  233. package/lib/components/text-reveal/TextRevealAnimation.js +55 -0
  234. package/lib/components/text-reveal/index.d.ts +1 -0
  235. package/lib/components/text-reveal/index.js +10 -0
  236. package/lib/components/text-reveal/useTextRevealAnimationLines.d.ts +4 -0
  237. package/lib/components/text-reveal/useTextRevealAnimationLines.js +52 -0
  238. package/lib/components/tokens/SpaceVariantToken.d.ts +5 -0
  239. package/lib/components/tokens/SpaceVariantToken.js +25 -0
  240. package/lib/components/tokens/index.d.ts +1 -0
  241. package/lib/components/tokens/index.js +10 -0
  242. package/lib/components/toolbars/AssignmentEditorToolbar.d.ts +4 -0
  243. package/lib/components/toolbars/AssignmentEditorToolbar.js +23 -0
  244. package/lib/components/toolbars/DocumentEditorToolbar.d.ts +2 -0
  245. package/lib/components/toolbars/DocumentEditorToolbar.js +17 -0
  246. package/lib/components/toolbars/NotebookEditorToolbar.d.ts +29 -0
  247. package/lib/components/toolbars/NotebookEditorToolbar.js +35 -0
  248. package/lib/components/toolbars/index.d.ts +3 -0
  249. package/lib/components/toolbars/index.js +12 -0
  250. package/lib/components/users/PeerIndicator.d.ts +18 -0
  251. package/lib/components/users/PeerIndicator.js +105 -0
  252. package/lib/components/users/index.d.ts +1 -0
  253. package/lib/components/users/index.js +10 -0
  254. package/lib/config/Configuration.d.ts +111 -0
  255. package/lib/config/Configuration.js +30 -0
  256. package/lib/config/index.d.ts +2 -0
  257. package/lib/config/index.js +11 -0
  258. package/lib/config/integrations/Loom.d.ts +1 -0
  259. package/lib/config/integrations/Loom.js +21 -0
  260. package/lib/config/integrations/index.d.ts +1 -0
  261. package/lib/config/integrations/index.js +10 -0
  262. package/lib/hooks/assets/OutputshotPlaceholders.d.ts +19 -0
  263. package/lib/hooks/assets/OutputshotPlaceholders.js +28 -0
  264. package/lib/hooks/assets/index.d.ts +1 -0
  265. package/lib/hooks/assets/index.js +10 -0
  266. package/lib/hooks/index.d.ts +28 -0
  267. package/lib/hooks/index.js +38 -0
  268. package/lib/hooks/layouts/LayoutBackdrop.d.ts +2 -0
  269. package/lib/hooks/layouts/LayoutBackdrop.js +35 -0
  270. package/lib/hooks/layouts/LayoutScreenshot.d.ts +2 -0
  271. package/lib/hooks/layouts/LayoutScreenshot.js +48 -0
  272. package/lib/hooks/layouts/index.d.ts +2 -0
  273. package/lib/hooks/layouts/index.js +11 -0
  274. package/lib/hooks/useAIAgents.d.ts +13 -0
  275. package/lib/hooks/useAIAgents.js +77 -0
  276. package/lib/hooks/useAuthorization.d.ts +19 -0
  277. package/lib/hooks/useAuthorization.js +130 -0
  278. package/lib/hooks/useBackdrop.d.ts +28 -0
  279. package/lib/hooks/useBackdrop.js +105 -0
  280. package/lib/hooks/useBackdropJupyterLab.d.ts +15 -0
  281. package/lib/hooks/useBackdropJupyterLab.js +56 -0
  282. package/lib/hooks/useCache.d.ts +306 -0
  283. package/lib/hooks/useCache.js +3103 -0
  284. package/lib/hooks/useCellOutputshot.d.ts +4 -0
  285. package/lib/hooks/useCellOutputshot.js +33 -0
  286. package/lib/hooks/useContainsFocus.d.ts +9 -0
  287. package/lib/hooks/useContainsFocus.js +48 -0
  288. package/lib/hooks/useError.d.ts +9 -0
  289. package/lib/hooks/useError.js +31 -0
  290. package/lib/hooks/useExternalScript.d.ts +2 -0
  291. package/lib/hooks/useExternalScript.js +22 -0
  292. package/lib/hooks/useFocusTrap.d.ts +30 -0
  293. package/lib/hooks/useFocusTrap.js +53 -0
  294. package/lib/hooks/useIAM.d.ts +14 -0
  295. package/lib/hooks/useIAM.js +98 -0
  296. package/lib/hooks/useId.d.ts +19 -0
  297. package/lib/hooks/useId.js +105 -0
  298. package/lib/hooks/useIsomorphicLayoutEffect.d.ts +3 -0
  299. package/lib/hooks/useIsomorphicLayoutEffect.js +16 -0
  300. package/lib/hooks/useJupyterLabTheme.d.ts +6 -0
  301. package/lib/hooks/useJupyterLabTheme.js +29 -0
  302. package/lib/hooks/useKeyboardEscape.d.ts +1 -0
  303. package/lib/hooks/useKeyboardEscape.js +23 -0
  304. package/lib/hooks/useLocationHandles.d.ts +10 -0
  305. package/lib/hooks/useLocationHandles.js +27 -0
  306. package/lib/hooks/useNavigate.d.ts +2 -0
  307. package/lib/hooks/useNavigate.js +29 -0
  308. package/lib/hooks/useNotebookAIAgent.d.ts +8 -0
  309. package/lib/hooks/useNotebookAIAgent.js +59 -0
  310. package/lib/hooks/useOnClickOutside.d.ts +1 -0
  311. package/lib/hooks/useOnClickOutside.js +34 -0
  312. package/lib/hooks/useRef.d.ts +10 -0
  313. package/lib/hooks/useRef.js +22 -0
  314. package/lib/hooks/useRun.d.ts +21 -0
  315. package/lib/hooks/useRun.js +85 -0
  316. package/lib/hooks/useRuntimes.d.ts +5 -0
  317. package/lib/hooks/useRuntimes.js +39 -0
  318. package/lib/hooks/useScreenshot.d.ts +21 -0
  319. package/lib/hooks/useScreenshot.js +65 -0
  320. package/lib/hooks/useToast.d.ts +42 -0
  321. package/lib/hooks/useToast.js +143 -0
  322. package/lib/hooks/useUpload.d.ts +7 -0
  323. package/lib/hooks/useUpload.js +51 -0
  324. package/lib/hooks/useUser.d.ts +3 -0
  325. package/lib/hooks/useUser.js +22 -0
  326. package/lib/hooks/useVisibilityObserver.d.ts +5 -0
  327. package/lib/hooks/useVisibilityObserver.js +47 -0
  328. package/lib/hooks/useWindowSize.d.ts +21 -0
  329. package/lib/hooks/useWindowSize.js +80 -0
  330. package/lib/i18n/Labels.d.ts +1 -0
  331. package/lib/i18n/Labels.js +10 -0
  332. package/lib/i18n/index.d.ts +1 -0
  333. package/lib/i18n/index.js +10 -0
  334. package/lib/index.d.ts +3 -0
  335. package/lib/index.js +6 -0
  336. package/lib/main.d.ts +1 -0
  337. package/lib/main.js +4 -0
  338. package/lib/mocks/components/FlashMock.d.ts +2 -0
  339. package/lib/mocks/components/FlashMock.js +18 -0
  340. package/lib/mocks/components/index.d.ts +1 -0
  341. package/lib/mocks/components/index.js +10 -0
  342. package/lib/mocks/hooks/index.d.ts +1 -0
  343. package/lib/mocks/hooks/index.js +10 -0
  344. package/lib/mocks/hooks/rests/index.d.ts +1 -0
  345. package/lib/mocks/hooks/rests/index.js +10 -0
  346. package/lib/mocks/hooks/rests/rests.d.ts +22 -0
  347. package/lib/mocks/hooks/rests/rests.js +37 -0
  348. package/lib/mocks/hooks/useRunMock.d.ts +6 -0
  349. package/lib/mocks/hooks/useRunMock.js +83 -0
  350. package/lib/mocks/index.d.ts +4 -0
  351. package/lib/mocks/index.js +14 -0
  352. package/lib/mocks/jupyter/index.d.ts +1 -0
  353. package/lib/mocks/jupyter/index.js +10 -0
  354. package/lib/mocks/models/CodeBlockMock.d.ts +1 -0
  355. package/lib/mocks/models/CodeBlockMock.js +10 -0
  356. package/lib/mocks/models/CodelineMock.d.ts +1 -0
  357. package/lib/mocks/models/CodelineMock.js +10 -0
  358. package/lib/mocks/models/CourseMock.d.ts +6 -0
  359. package/lib/mocks/models/CourseMock.js +34 -0
  360. package/lib/mocks/models/InviteMock.d.ts +6 -0
  361. package/lib/mocks/models/InviteMock.js +27 -0
  362. package/lib/mocks/models/JupyterLabUserMock.d.ts +2 -0
  363. package/lib/mocks/models/JupyterLabUserMock.js +17 -0
  364. package/lib/mocks/models/OrganisationMock.d.ts +5 -0
  365. package/lib/mocks/models/OrganisationMock.js +24 -0
  366. package/lib/mocks/models/SchoolMock.d.ts +6 -0
  367. package/lib/mocks/models/SchoolMock.js +25 -0
  368. package/lib/mocks/models/SpaceMock.d.ts +6 -0
  369. package/lib/mocks/models/SpaceMock.js +30 -0
  370. package/lib/mocks/models/TeamMock.d.ts +5 -0
  371. package/lib/mocks/models/TeamMock.js +26 -0
  372. package/lib/mocks/models/UserMock.d.ts +2 -0
  373. package/lib/mocks/models/UserMock.js +34 -0
  374. package/lib/mocks/models/index.d.ts +9 -0
  375. package/lib/mocks/models/index.js +18 -0
  376. package/lib/mocks/views/ActionMenuMock.d.ts +5 -0
  377. package/lib/mocks/views/ActionMenuMock.js +17 -0
  378. package/lib/mocks/views/ChartMock.d.ts +5 -0
  379. package/lib/mocks/views/ChartMock.js +20 -0
  380. package/lib/mocks/views/ChartMockOptions.d.ts +92 -0
  381. package/lib/mocks/views/ChartMockOptions.js +107 -0
  382. package/lib/mocks/views/DashboardMock.d.ts +2 -0
  383. package/lib/mocks/views/DashboardMock.js +123 -0
  384. package/lib/mocks/views/FormMock.d.ts +5 -0
  385. package/lib/mocks/views/FormMock.js +33 -0
  386. package/lib/mocks/views/TableMock.d.ts +5 -0
  387. package/lib/mocks/views/TableMock.js +160 -0
  388. package/lib/mocks/views/WipMock.d.ts +5 -0
  389. package/lib/mocks/views/WipMock.js +17 -0
  390. package/lib/mocks/views/index.d.ts +7 -0
  391. package/lib/mocks/views/index.js +16 -0
  392. package/lib/models/AIAgent.d.ts +17 -0
  393. package/lib/models/AIAgent.js +5 -0
  394. package/lib/models/Account.d.ts +4 -0
  395. package/lib/models/Account.js +5 -0
  396. package/lib/models/Assignment.d.ts +7 -0
  397. package/lib/models/Assignment.js +5 -0
  398. package/lib/models/Base.d.ts +16 -0
  399. package/lib/models/Base.js +5 -0
  400. package/lib/models/Cell.d.ts +8 -0
  401. package/lib/models/Cell.js +5 -0
  402. package/lib/models/CodeBlock.d.ts +10 -0
  403. package/lib/models/CodeBlock.js +5 -0
  404. package/lib/models/CodefeedBlocks.d.ts +7 -0
  405. package/lib/models/CodefeedBlocks.js +5 -0
  406. package/lib/models/Contact.d.ts +73 -0
  407. package/lib/models/Contact.js +95 -0
  408. package/lib/models/ContactEvent.d.ts +10 -0
  409. package/lib/models/ContactEvent.js +19 -0
  410. package/lib/models/ContactIAMProvider.d.ts +12 -0
  411. package/lib/models/ContactIAMProvider.js +20 -0
  412. package/lib/models/ContactTags.d.ts +23 -0
  413. package/lib/models/ContactTags.js +73 -0
  414. package/lib/models/Content.d.ts +5 -0
  415. package/lib/models/Content.js +5 -0
  416. package/lib/models/Course.d.ts +17 -0
  417. package/lib/models/Course.js +5 -0
  418. package/lib/models/Credits.d.ts +76 -0
  419. package/lib/models/Credits.js +16 -0
  420. package/lib/models/Dataset.d.ts +16 -0
  421. package/lib/models/Dataset.js +5 -0
  422. package/lib/models/Datasource.d.ts +11 -0
  423. package/lib/models/Datasource.js +19 -0
  424. package/lib/models/Dean.d.ts +3 -0
  425. package/lib/models/Dean.js +5 -0
  426. package/lib/models/Document.d.ts +8 -0
  427. package/lib/models/Document.js +5 -0
  428. package/lib/models/Environment.d.ts +82 -0
  429. package/lib/models/Environment.js +5 -0
  430. package/lib/models/Errors.d.ts +6 -0
  431. package/lib/models/Errors.js +18 -0
  432. package/lib/models/Exercise.d.ts +16 -0
  433. package/lib/models/Exercise.js +5 -0
  434. package/lib/models/GrowthKPI.d.ts +5 -0
  435. package/lib/models/GrowthKPI.js +14 -0
  436. package/lib/models/IAMProviderLinked.d.ts +9 -0
  437. package/lib/models/IAMProviderLinked.js +13 -0
  438. package/lib/models/IAMProviderPost.d.ts +8 -0
  439. package/lib/models/IAMProviderPost.js +22 -0
  440. package/lib/models/IAMProviderUsers.d.ts +49 -0
  441. package/lib/models/IAMProviderUsers.js +34 -0
  442. package/lib/models/IAMProvidersSpecs.d.ts +22 -0
  443. package/lib/models/IAMProvidersSpecs.js +72 -0
  444. package/lib/models/IAMToken.d.ts +11 -0
  445. package/lib/models/IAMToken.js +19 -0
  446. package/lib/models/Inbound.d.ts +25 -0
  447. package/lib/models/Inbound.js +34 -0
  448. package/lib/models/Instructor.d.ts +3 -0
  449. package/lib/models/Instructor.js +5 -0
  450. package/lib/models/Invite.d.ts +14 -0
  451. package/lib/models/Invite.js +24 -0
  452. package/lib/models/Item.d.ts +20 -0
  453. package/lib/models/Item.js +5 -0
  454. package/lib/models/ItemType.d.ts +2 -0
  455. package/lib/models/ItemType.js +5 -0
  456. package/lib/models/LandingRoles.d.ts +3 -0
  457. package/lib/models/LandingRoles.js +32 -0
  458. package/lib/models/Lesson.d.ts +5 -0
  459. package/lib/models/Lesson.js +5 -0
  460. package/lib/models/Library.d.ts +10 -0
  461. package/lib/models/Library.js +5 -0
  462. package/lib/models/Member.d.ts +3 -0
  463. package/lib/models/Member.js +5 -0
  464. package/lib/models/Notebook.d.ts +11 -0
  465. package/lib/models/Notebook.js +5 -0
  466. package/lib/models/Organization.d.ts +27 -0
  467. package/lib/models/Organization.js +41 -0
  468. package/lib/models/OrganizationMember.d.ts +6 -0
  469. package/lib/models/OrganizationMember.js +5 -0
  470. package/lib/models/Outbound.d.ts +41 -0
  471. package/lib/models/Outbound.js +50 -0
  472. package/lib/models/Page.d.ts +36 -0
  473. package/lib/models/Page.js +23 -0
  474. package/lib/models/PageTag.d.ts +19 -0
  475. package/lib/models/PageTag.js +26 -0
  476. package/lib/models/Profile.d.ts +1 -0
  477. package/lib/models/Profile.js +5 -0
  478. package/lib/models/Role.d.ts +9 -0
  479. package/lib/models/Role.js +5 -0
  480. package/lib/models/RolesOrganization.d.ts +9 -0
  481. package/lib/models/RolesOrganization.js +63 -0
  482. package/lib/models/RolesPlatform.d.ts +16 -0
  483. package/lib/models/RolesPlatform.js +147 -0
  484. package/lib/models/RolesTeam.d.ts +7 -0
  485. package/lib/models/RolesTeam.js +39 -0
  486. package/lib/models/Runtime.d.ts +65 -0
  487. package/lib/models/Runtime.js +16 -0
  488. package/lib/models/RuntimeSnapshot.d.ts +92 -0
  489. package/lib/models/RuntimeSnapshot.js +13 -0
  490. package/lib/models/School.d.ts +11 -0
  491. package/lib/models/School.js +5 -0
  492. package/lib/models/Secret.d.ts +10 -0
  493. package/lib/models/Secret.js +18 -0
  494. package/lib/models/Space.d.ts +34 -0
  495. package/lib/models/Space.js +39 -0
  496. package/lib/models/SpaceItem.d.ts +10 -0
  497. package/lib/models/SpaceItem.js +5 -0
  498. package/lib/models/SpaceMember.d.ts +6 -0
  499. package/lib/models/SpaceMember.js +5 -0
  500. package/lib/models/Student.d.ts +6 -0
  501. package/lib/models/Student.js +5 -0
  502. package/lib/models/StudentItem.d.ts +21 -0
  503. package/lib/models/StudentItem.js +5 -0
  504. package/lib/models/Survey.d.ts +20 -0
  505. package/lib/models/Survey.js +19 -0
  506. package/lib/models/Team.d.ts +22 -0
  507. package/lib/models/Team.js +37 -0
  508. package/lib/models/TeamMember.d.ts +6 -0
  509. package/lib/models/TeamMember.js +5 -0
  510. package/lib/models/URN.d.ts +63 -0
  511. package/lib/models/URN.js +45 -0
  512. package/lib/models/Usage.d.ts +46 -0
  513. package/lib/models/Usage.js +21 -0
  514. package/lib/models/User.d.ts +71 -0
  515. package/lib/models/User.js +103 -0
  516. package/lib/models/UserEvent.d.ts +10 -0
  517. package/lib/models/UserEvent.js +19 -0
  518. package/lib/models/UserOnboarding.d.ts +14 -0
  519. package/lib/models/UserOnboarding.js +24 -0
  520. package/lib/models/UserSettings.d.ts +16 -0
  521. package/lib/models/UserSettings.js +32 -0
  522. package/lib/models/WaitingListFormData.d.ts +6 -0
  523. package/lib/models/WaitingListFormData.js +5 -0
  524. package/lib/models/index.d.ts +65 -0
  525. package/lib/models/index.js +74 -0
  526. package/lib/routes/Routes.d.ts +3 -0
  527. package/lib/routes/Routes.js +12 -0
  528. package/lib/routes/index.d.ts +1 -0
  529. package/lib/routes/index.js +10 -0
  530. package/lib/state/State.d.ts +33 -0
  531. package/lib/state/State.js +49 -0
  532. package/lib/state/index.d.ts +3 -0
  533. package/lib/state/index.js +12 -0
  534. package/lib/state/storage/IAMStorage.d.ts +33 -0
  535. package/lib/state/storage/IAMStorage.js +81 -0
  536. package/lib/state/storage/index.d.ts +1 -0
  537. package/lib/state/storage/index.js +10 -0
  538. package/lib/state/substates/AIAgentState.d.ts +11 -0
  539. package/lib/state/substates/AIAgentState.js +45 -0
  540. package/lib/state/substates/CellState.d.ts +12 -0
  541. package/lib/state/substates/CellState.js +26 -0
  542. package/lib/state/substates/CoreState.d.ts +25 -0
  543. package/lib/state/substates/CoreState.js +93 -0
  544. package/lib/state/substates/DatasourceState.d.ts +11 -0
  545. package/lib/state/substates/DatasourceState.js +21 -0
  546. package/lib/state/substates/DocumentState.d.ts +10 -0
  547. package/lib/state/substates/DocumentState.js +19 -0
  548. package/lib/state/substates/GradeState.d.ts +10 -0
  549. package/lib/state/substates/GradeState.js +19 -0
  550. package/lib/state/substates/IAMState.d.ts +75 -0
  551. package/lib/state/substates/IAMState.js +294 -0
  552. package/lib/state/substates/JupyterLabState.d.ts +16 -0
  553. package/lib/state/substates/JupyterLabState.js +22 -0
  554. package/lib/state/substates/LayoutState.d.ts +62 -0
  555. package/lib/state/substates/LayoutState.js +74 -0
  556. package/lib/state/substates/NbformatState.d.ts +13 -0
  557. package/lib/state/substates/NbformatState.js +21 -0
  558. package/lib/state/substates/OrganizationState.d.ts +11 -0
  559. package/lib/state/substates/OrganizationState.js +21 -0
  560. package/lib/state/substates/RuntimesState.d.ts +88 -0
  561. package/lib/state/substates/RuntimesState.js +183 -0
  562. package/lib/state/substates/SpaceState.d.ts +11 -0
  563. package/lib/state/substates/SpaceState.js +21 -0
  564. package/lib/state/substates/SurveysState.d.ts +14 -0
  565. package/lib/state/substates/SurveysState.js +103 -0
  566. package/lib/state/substates/TeamState.d.ts +11 -0
  567. package/lib/state/substates/TeamState.js +22 -0
  568. package/lib/state/substates/index.d.ts +15 -0
  569. package/lib/state/substates/index.js +24 -0
  570. package/lib/test-setup.d.ts +1 -0
  571. package/lib/test-setup.js +7 -0
  572. package/lib/theme/DatalayerTheme.d.ts +37 -0
  573. package/lib/theme/DatalayerTheme.js +67 -0
  574. package/lib/theme/DatalayerThemeProvider.d.ts +17 -0
  575. package/lib/theme/DatalayerThemeProvider.js +74 -0
  576. package/lib/theme/Palette.d.ts +5 -0
  577. package/lib/theme/Palette.js +27 -0
  578. package/lib/theme/index.d.ts +3 -0
  579. package/lib/theme/index.js +12 -0
  580. package/lib/utils/Array.d.ts +2 -0
  581. package/lib/utils/Array.js +21 -0
  582. package/lib/utils/Avatar.d.ts +9 -0
  583. package/lib/utils/Avatar.js +39 -0
  584. package/lib/utils/Browser.d.ts +3 -0
  585. package/lib/utils/Browser.js +68 -0
  586. package/lib/utils/Cells.d.ts +2 -0
  587. package/lib/utils/Cells.js +28 -0
  588. package/lib/utils/Cookie.d.ts +12 -0
  589. package/lib/utils/Cookie.js +53 -0
  590. package/lib/utils/Date.d.ts +2 -0
  591. package/lib/utils/Date.js +65 -0
  592. package/lib/utils/Download.d.ts +3 -0
  593. package/lib/utils/Download.js +53 -0
  594. package/lib/utils/DownloadFile.d.ts +10 -0
  595. package/lib/utils/DownloadFile.js +41 -0
  596. package/lib/utils/Env.d.ts +1 -0
  597. package/lib/utils/Env.js +12 -0
  598. package/lib/utils/File.d.ts +7 -0
  599. package/lib/utils/File.js +21 -0
  600. package/lib/utils/Format.d.ts +17 -0
  601. package/lib/utils/Format.js +54 -0
  602. package/lib/utils/Ids.d.ts +2 -0
  603. package/lib/utils/Ids.js +17 -0
  604. package/lib/utils/Jupyter.d.ts +1 -0
  605. package/lib/utils/Jupyter.js +17 -0
  606. package/lib/utils/Lazy.d.ts +8 -0
  607. package/lib/utils/Lazy.js +29 -0
  608. package/lib/utils/Msc.d.ts +16 -0
  609. package/lib/utils/Msc.js +28 -0
  610. package/lib/utils/Name.d.ts +7 -0
  611. package/lib/utils/Name.js +39 -0
  612. package/lib/utils/Notebook.d.ts +19 -0
  613. package/lib/utils/Notebook.js +37 -0
  614. package/lib/utils/Number.d.ts +1 -0
  615. package/lib/utils/Number.js +26 -0
  616. package/lib/utils/Plots.d.ts +16 -0
  617. package/lib/utils/Plots.js +56 -0
  618. package/lib/utils/Random.d.ts +1 -0
  619. package/lib/utils/Random.js +12 -0
  620. package/lib/utils/Screenshot.d.ts +1 -0
  621. package/lib/utils/Screenshot.js +32 -0
  622. package/lib/utils/Scroll.d.ts +2 -0
  623. package/lib/utils/Scroll.js +36 -0
  624. package/lib/utils/Sleep.d.ts +2 -0
  625. package/lib/utils/Sleep.js +13 -0
  626. package/lib/utils/Snapshot.d.ts +7 -0
  627. package/lib/utils/Snapshot.js +26 -0
  628. package/lib/utils/String.d.ts +1 -0
  629. package/lib/utils/String.js +18 -0
  630. package/lib/utils/Uri.d.ts +2 -0
  631. package/lib/utils/Uri.js +31 -0
  632. package/lib/utils/Validator.d.ts +12 -0
  633. package/lib/utils/Validator.js +49 -0
  634. package/lib/utils/WithSuspense.d.ts +2 -0
  635. package/lib/utils/WithSuspense.js +26 -0
  636. package/lib/utils/index.d.ts +26 -0
  637. package/lib/utils/index.js +36 -0
  638. package/package.json +43 -4
  639. package/style/base.css +0 -5
  640. package/style/index.css +0 -7
  641. package/style/index.js +0 -7
@@ -0,0 +1,3103 @@
1
+ /*
2
+ * Copyright (c) 2023-2025 Datalayer, Inc.
3
+ * Distributed under the terms of the Modified BSD License.
4
+ */
5
+ /*
6
+ * Copyright (c) 2021-2024 Datalayer, Inc.
7
+ *
8
+ * Datalayer License
9
+ */
10
+ import { URLExt } from '@jupyterlab/coreutils';
11
+ import { BOOTSTRAP_USER_ONBOARDING, LinkedInUser, asContact, asDatasource, asInbound, asInvite, asOrganization, asOutbound, asPage, asSecret, asSpace, asSurvey, asTeam, asToken, asUsage, asUser, } from "../models";
12
+ import { useCoreStore, useIAMStore } from '../state';
13
+ import { asDisplayName, namesAsInitials, asArray } from "../utils";
14
+ import { IAMProvidersSpecs } from '../models';
15
+ import { newUserMock } from './../mocks';
16
+ import { useRun } from "./useRun";
17
+ import { useAuthorization } from "./useAuthorization";
18
+ import { OUTPUTSHOT_PLACEHOLDER_DEFAULT_SVG } from './assets';
19
+ const CONTACTS_BY_HANDLE = new Map();
20
+ const CONTACTS_BY_ID = new Map();
21
+ const COURSES_BY_ID = new Map();
22
+ const COURSES_ENROLLMENTS_BY_ID = new Map();
23
+ const COURSES_INSTRUCTORS_BY_ID = new Map();
24
+ const DATASOURCES_BY_ID = new Map();
25
+ const INBOUNDS_BY_HANDLE = new Map();
26
+ const INBOUNDS_BY_ID = new Map();
27
+ const INVITES_BY_TOKEN = new Map();
28
+ const ORGANISATIONS_BY_HANDLE = new Map();
29
+ const ORGANISATIONS_BY_ID = new Map();
30
+ const ORGANISATIONS_FOR_USER_BY_ID = new Map();
31
+ const OUTBOUNDS_BY_ID = new Map();
32
+ const PAGES_BY_ID = new Map();
33
+ const PUBLIC_COURSES_BY_ID = new Map();
34
+ const PUBLIC_ITEMS_BY_ID = new Map();
35
+ const SCHOOLS_BY_ID = new Map();
36
+ const SECRETS_BY_ID = new Map();
37
+ const SPACES_BY_HANDLE_BY_ORGANISATION_HANDLE = new Map();
38
+ const SPACES_BY_ID_BY_ORGANISATION_ID = new Map();
39
+ const SPACES_FOR_USER_BY_HANDLE = new Map();
40
+ const SPACES_FOR_USER_BY_ID = new Map();
41
+ const SPACE_ASSIGNMENTS_BY_ID = new Map();
42
+ const SPACE_CELLS_BY_ID = new Map();
43
+ const SPACE_DATASETS_BY_ID = new Map();
44
+ const SPACE_DOCUMENTS_BY_ID = new Map();
45
+ const SPACE_ENVIRONMENTS_BY_ID = new Map();
46
+ const SPACE_EXERCISES_BY_ID = new Map();
47
+ const SPACE_ITEMS_CACHE = new Map();
48
+ const SPACE_LESSONS_BY_ID = new Map();
49
+ const SPACE_NOTEBOOKS_BY_ID = new Map();
50
+ const STUDENTS_BY_ID = new Map();
51
+ const STUDENT_ASSIGNMENTS_BY_ID = new Map();
52
+ const TEAMS_BY_HANDLE = new Map();
53
+ const TEAMS_BY_ID = new Map();
54
+ const TEAMS_BY_ORGANIZATION_BY_ID = new Map();
55
+ const TOKENS_BY_ID = new Map();
56
+ const USERS_BY_HANDLE = new Map();
57
+ const USERS_BY_ID = new Map();
58
+ const DEFAULT_SEARCH_OPTS = {
59
+ q: '*',
60
+ types: ['page'],
61
+ max: 3,
62
+ public: true,
63
+ };
64
+ /**
65
+ * Callbacks to RUN service.
66
+ *
67
+ * It assumes to be used within a {@link Router} component. If not
68
+ * you must set the options `loginRoute` to `null` (raise an error _Unauthorized_
69
+ * instead of redirecting to the login page).
70
+ */
71
+ export const useCache = ({ loginRoute = '/login' } = {}) => {
72
+ const { configuration } = useCoreStore();
73
+ const { user } = useIAMStore();
74
+ const { requestRun } = useRun({ loginRoute });
75
+ const { checkIsOrganizationMember } = useAuthorization();
76
+ // Caches -------------------------------------------------------------------
77
+ const clearAllCaches = () => {
78
+ CONTACTS_BY_HANDLE.clear();
79
+ CONTACTS_BY_ID.clear();
80
+ COURSES_BY_ID.clear();
81
+ COURSES_ENROLLMENTS_BY_ID.clear();
82
+ COURSES_INSTRUCTORS_BY_ID.clear();
83
+ DATASOURCES_BY_ID.clear();
84
+ INBOUNDS_BY_HANDLE.clear();
85
+ INBOUNDS_BY_ID.clear();
86
+ INVITES_BY_TOKEN.clear();
87
+ ORGANISATIONS_BY_HANDLE.clear();
88
+ ORGANISATIONS_BY_ID.clear();
89
+ ORGANISATIONS_FOR_USER_BY_ID.clear();
90
+ PAGES_BY_ID.clear();
91
+ OUTBOUNDS_BY_ID.clear();
92
+ PUBLIC_COURSES_BY_ID.clear();
93
+ PUBLIC_ITEMS_BY_ID.clear();
94
+ SCHOOLS_BY_ID.clear();
95
+ SECRETS_BY_ID.clear();
96
+ SPACES_BY_HANDLE_BY_ORGANISATION_HANDLE.clear();
97
+ SPACES_BY_ID_BY_ORGANISATION_ID.clear();
98
+ SPACES_FOR_USER_BY_HANDLE.clear();
99
+ SPACES_FOR_USER_BY_ID.clear();
100
+ SPACE_ASSIGNMENTS_BY_ID.clear();
101
+ SPACE_CELLS_BY_ID.clear();
102
+ SPACE_DATASETS_BY_ID.clear();
103
+ SPACE_DOCUMENTS_BY_ID.clear();
104
+ SPACE_ENVIRONMENTS_BY_ID.clear();
105
+ SPACE_EXERCISES_BY_ID.clear();
106
+ SPACE_ITEMS_CACHE.clear();
107
+ SPACE_LESSONS_BY_ID.clear();
108
+ SPACE_NOTEBOOKS_BY_ID.clear();
109
+ STUDENTS_BY_ID.clear();
110
+ STUDENT_ASSIGNMENTS_BY_ID.clear();
111
+ TOKENS_BY_ID.clear();
112
+ USERS_BY_HANDLE.clear();
113
+ USERS_BY_ID.clear();
114
+ };
115
+ const clearCachedItems = () => {
116
+ PUBLIC_ITEMS_BY_ID.clear();
117
+ SPACE_ASSIGNMENTS_BY_ID.clear();
118
+ SPACE_DATASETS_BY_ID.clear();
119
+ SPACE_DOCUMENTS_BY_ID.clear();
120
+ SPACE_ENVIRONMENTS_BY_ID.clear();
121
+ SPACE_EXERCISES_BY_ID.clear();
122
+ SPACE_ITEMS_CACHE.clear();
123
+ SPACE_ITEMS_CACHE.clear();
124
+ SPACE_LESSONS_BY_ID.clear();
125
+ SPACE_NOTEBOOKS_BY_ID.clear();
126
+ SPACE_CELLS_BY_ID.clear();
127
+ SPACE_CELLS_BY_ID.clear();
128
+ };
129
+ // Authentication ------------------------------------------------------------------
130
+ const login = (handle, password) => {
131
+ return requestRun({
132
+ url: `${configuration.iamRunUrl}/api/iam/v1/login`,
133
+ method: 'POST',
134
+ body: {
135
+ handle,
136
+ password,
137
+ }
138
+ });
139
+ };
140
+ const logout = () => {
141
+ clearAllCaches();
142
+ return requestRun({
143
+ url: `${configuration.iamRunUrl}/api/iam/v1/logout`,
144
+ method: 'GET',
145
+ });
146
+ };
147
+ // Join ------------------------------------------------------------------
148
+ const requestJoin = (handle, email, firstName, lastName, password, passwordConfirm) => {
149
+ return requestRun({
150
+ url: `${configuration.iamRunUrl}/api/iam/v1/join/request`,
151
+ method: 'POST',
152
+ body: {
153
+ handle,
154
+ email,
155
+ firstName,
156
+ lastName,
157
+ password,
158
+ passwordConfirm,
159
+ }
160
+ });
161
+ };
162
+ const requestJoinToken = (handle, email, firstName, lastName, password, passwordConfirm) => {
163
+ return requestRun({
164
+ url: `${configuration.iamRunUrl}/api/iam/v1/join/request/token`,
165
+ method: 'POST',
166
+ body: {
167
+ handle,
168
+ email,
169
+ firstName,
170
+ lastName,
171
+ password,
172
+ passwordConfirm,
173
+ }
174
+ });
175
+ };
176
+ const joinWithInvite = (formValues, token) => {
177
+ return requestRun({
178
+ url: `${configuration.iamRunUrl}/api/iam/v1/join/invites/token`,
179
+ method: 'POST',
180
+ body: {
181
+ ...formValues,
182
+ token,
183
+ },
184
+ });
185
+ };
186
+ const confirmJoinWithToken = (userHandle, token) => {
187
+ return requestRun({
188
+ url: `${configuration.iamRunUrl}/api/iam/v1/join/users/${userHandle}/tokens/${token}`,
189
+ method: 'GET',
190
+ });
191
+ };
192
+ // Password ------------------------------------------------------------------
193
+ const changePassword = (handle, password, passwordConfirm) => {
194
+ return requestRun({
195
+ url: `${configuration.iamRunUrl}/api/iam/v1/password`,
196
+ method: 'PUT',
197
+ body: {
198
+ handle,
199
+ password,
200
+ passwordConfirm,
201
+ }
202
+ });
203
+ };
204
+ const createTokenForPasswordChange = (handle, password, passwordConfirm) => {
205
+ return requestRun({
206
+ url: `${configuration.iamRunUrl}/api/iam/v1/password/token`,
207
+ method: 'POST',
208
+ body: {
209
+ handle,
210
+ password,
211
+ passwordConfirm,
212
+ }
213
+ });
214
+ };
215
+ const confirmPassworkWithToken = (userHandle, token) => {
216
+ return requestRun({
217
+ url: `${configuration.iamRunUrl}/api/iam/v1/password/confirm/users/${userHandle}/tokens/${token}`,
218
+ method: 'PUT',
219
+ });
220
+ };
221
+ // OAuth2 -------------------------------------------------------------------
222
+ const getOAuth2AuthorizationURL = async (queryArgs) => {
223
+ return requestRun({
224
+ url: URLExt.join(configuration.iamRunUrl, 'api/iam/v1/oauth2/authz/url') + URLExt.objectToQueryString(queryArgs),
225
+ notifyOnError: false,
226
+ });
227
+ };
228
+ const getOAuth2AuthorizationLinkURL = async (queryArgs) => {
229
+ return requestRun({
230
+ url: URLExt.join(configuration.iamRunUrl, 'api/iam/v1/oauth2/authz/url/link') + URLExt.objectToQueryString(queryArgs),
231
+ });
232
+ };
233
+ // IAM Providers ------------------------------------------------------------
234
+ const getGitHubProfile = async (accessToken) => {
235
+ return fetch(IAMProvidersSpecs.GitHub.userInfoURL, {
236
+ method: 'GET',
237
+ headers: {
238
+ 'Accept': 'application/vnd.github+json',
239
+ 'Authorization': `Bearer ${accessToken}`,
240
+ 'X-GitHub-Api-Version': '2022-11-28',
241
+ },
242
+ }).then(resp => resp.json());
243
+ };
244
+ /*
245
+ * CORS is not supported @see https://github.com/linkedin-developers/linkedin-api-js-client
246
+ */
247
+ const getLinkedinProfile = async (accessToken) => {
248
+ return proxyGET(IAMProvidersSpecs.LinkedIn.userInfoURL, accessToken).then(resp => {
249
+ return new LinkedInUser(resp.response);
250
+ });
251
+ };
252
+ const postLinkedinShare = async (linkedinUser, postText, accessToken) => {
253
+ const POST_SHARE_REQUEST = {
254
+ "author": linkedinUser.getUrn(),
255
+ "lifecycleState": "PUBLISHED",
256
+ "specificContent": {
257
+ "com.linkedin.ugc.ShareContent": {
258
+ "shareCommentary": {
259
+ "text": postText
260
+ },
261
+ "shareMediaCategory": "NONE"
262
+ }
263
+ },
264
+ "visibility": {
265
+ "com.linkedin.ugc.MemberNetworkVisibility": "PUBLIC"
266
+ }
267
+ };
268
+ return proxyPOST(IAMProvidersSpecs.LinkedIn.postShareURL, POST_SHARE_REQUEST, accessToken);
269
+ };
270
+ const postLinkedinShareWithUpload = async (linkedinUser, postText, uploadObject, accessToken) => {
271
+ const REGISTER_UPLOAD_REQUEST = {
272
+ "registerUploadRequest": {
273
+ "recipes": [
274
+ "urn:li:digitalmediaRecipe:feedshare-image"
275
+ ],
276
+ "owner": linkedinUser.getUrn(),
277
+ "serviceRelationships": [
278
+ {
279
+ "relationshipType": "OWNER",
280
+ "identifier": "urn:li:userGeneratedContent"
281
+ }
282
+ ]
283
+ }
284
+ };
285
+ return proxyPOST(IAMProvidersSpecs.LinkedIn.registerUploadURL, REGISTER_UPLOAD_REQUEST, accessToken)
286
+ .then(registerUploadReponse => {
287
+ /*
288
+ {
289
+ "value": {
290
+ "uploadMechanism": {
291
+ "com.linkedin.digitalmedia.uploading.MediaUploadHttpRequest": {
292
+ "headers": {},
293
+ "uploadUrl": "https://api.linkedin.com/mediaUpload/C5522AQGTYER3k3ByHQ/feedshare-uploadedImage/0?ca=vector_feedshare&cn=uploads&m=AQJbrN86Zm265gAAAWemyz2pxPSgONtBiZdchrgG872QltnfYjnMdb2j3A&app=1953784&sync=0&v=beta&ut=2H-IhpbfXrRow1"
294
+ }
295
+ },
296
+ "mediaArtifact": "urn:li:digitalmediaMediaArtifact:(urn:li:digitalmediaAsset:C5522AQGTYER3k3ByHQ,urn:li:digitalmediaMediaArtifactClass:feedshare-uploadedImage)",
297
+ "asset": "urn:li:digitalmediaAsset:C5522AQGTYER3k3ByHQ"
298
+ }
299
+ }
300
+ */
301
+ const asset = registerUploadReponse.response.value.asset;
302
+ const uploadURL = registerUploadReponse.response.value.uploadMechanism['com.linkedin.digitalmedia.uploading.MediaUploadHttpRequest'].uploadUrl;
303
+ const UPLOAD_OBJECT_REQUEST = {
304
+ uploadURL: uploadURL,
305
+ content: uploadObject,
306
+ userURN: linkedinUser.getUrn(),
307
+ };
308
+ return proxyPUT(uploadURL, UPLOAD_OBJECT_REQUEST, accessToken)
309
+ .then(resp => {
310
+ const share = {
311
+ "author": linkedinUser.getUrn(),
312
+ "lifecycleState": "PUBLISHED",
313
+ "specificContent": {
314
+ "com.linkedin.ugc.ShareContent": {
315
+ "shareCommentary": {
316
+ "text": postText
317
+ },
318
+ "shareMediaCategory": "IMAGE",
319
+ "media": [
320
+ {
321
+ "status": "READY",
322
+ "description": {
323
+ "text": "Datalayer Notebook"
324
+ },
325
+ "media": asset,
326
+ "title": {
327
+ "text": "Datalayer Notebook"
328
+ }
329
+ }
330
+ ]
331
+ }
332
+ },
333
+ "visibility": {
334
+ "com.linkedin.ugc.MemberNetworkVisibility": "PUBLIC"
335
+ }
336
+ };
337
+ return proxyPOST(IAMProvidersSpecs.LinkedIn.postShareURL, share, accessToken);
338
+ });
339
+ });
340
+ };
341
+ // Proxy -------------------------------------------------------------------
342
+ const proxyGET = async (url, token) => {
343
+ return requestRun({
344
+ url: URLExt.join(configuration.iamRunUrl, 'api/iam/v1/proxy/request'),
345
+ method: 'POST',
346
+ body: {
347
+ request_method: 'GET',
348
+ request_url: url,
349
+ request_token: token,
350
+ }
351
+ });
352
+ };
353
+ const proxyPOST = async (url, body, token) => {
354
+ return requestRun({
355
+ url: URLExt.join(configuration.iamRunUrl, 'api/iam/v1/proxy/request'),
356
+ method: 'POST',
357
+ body: {
358
+ request_method: 'POST',
359
+ request_url: url,
360
+ request_token: token,
361
+ request_body: body,
362
+ }
363
+ });
364
+ };
365
+ const proxyPUT = async (url, body, token) => {
366
+ return requestRun({
367
+ url: URLExt.join(configuration.iamRunUrl, 'api/iam/v1/proxy/request'),
368
+ method: 'POST',
369
+ body: {
370
+ request_method: 'PUT',
371
+ request_url: url,
372
+ request_token: token,
373
+ request_body: body,
374
+ }
375
+ });
376
+ };
377
+ // Waiting List -------------------------------------------------------------
378
+ const registerToWaitingList = (formData) => {
379
+ requestRun({
380
+ url: `${configuration.growthRunUrl}/api/growth/v1/waitinglist/register`,
381
+ method: 'POST',
382
+ body: {
383
+ firstName: formData.firstName,
384
+ lastName: formData.lastName,
385
+ email: formData.email,
386
+ affiliation: formData.affiliation || ''
387
+ }
388
+ })
389
+ .then(resp => {
390
+ // Special case, make the error very explicit to the user...
391
+ if (!resp.success) {
392
+ alert('Sorry, something has gone wrong... Please send an email to eric@datalayer.io to register to the waiting list.');
393
+ }
394
+ })
395
+ .catch(err => {
396
+ // Special case, make the error very explicit to the user...
397
+ console.error(err);
398
+ alert('Sorry, something has gone wrong... Please send an email to eric@datalayer.io to register to the waiting list.');
399
+ });
400
+ };
401
+ // Profile ------------------------------------------------------------------
402
+ const getMe = async (token) => {
403
+ const resp = await requestRun({
404
+ url: `${configuration.iamRunUrl}/api/iam/v1/me`,
405
+ method: 'GET',
406
+ token
407
+ });
408
+ const me = resp.me;
409
+ if (me) {
410
+ const user = asUser(me);
411
+ return user;
412
+ }
413
+ return null;
414
+ };
415
+ const updateMe = (email, firstName, lastName) => {
416
+ return requestRun({
417
+ url: `${configuration.iamRunUrl}/api/iam/v1/me`,
418
+ method: 'PUT',
419
+ body: {
420
+ email,
421
+ firstName,
422
+ lastName,
423
+ }
424
+ });
425
+ };
426
+ const whoami = () => {
427
+ return requestRun({
428
+ url: `${configuration.iamRunUrl}/api/iam/v1/whoami`,
429
+ method: 'GET',
430
+ });
431
+ };
432
+ const requestEmailUpdate = (email) => {
433
+ return requestRun({
434
+ url: `${configuration.iamRunUrl}/api/iam/v1/me/email`,
435
+ method: 'PUT',
436
+ body: {
437
+ email,
438
+ }
439
+ });
440
+ };
441
+ const confirmEmailUpdate = (token) => {
442
+ return requestRun({
443
+ url: `${configuration.iamRunUrl}/api/iam/v1/me/email`,
444
+ method: 'POST',
445
+ body: {
446
+ token,
447
+ }
448
+ });
449
+ };
450
+ // Onboarding ---------------------------------------------------------------
451
+ const updateUserOnboarding = (onboarding) => {
452
+ return requestRun({
453
+ url: `${configuration.iamRunUrl}/api/iam/v1/onboardings`,
454
+ method: 'PUT',
455
+ body: {
456
+ onboarding,
457
+ }
458
+ });
459
+ };
460
+ // Settings -----------------------------------------------------------------
461
+ const updateUserSettings = (userId, settings) => {
462
+ return requestRun({
463
+ url: `${configuration.iamRunUrl}/api/iam/v1/users/${userId}/settings`,
464
+ method: 'PUT',
465
+ body: {
466
+ aiagents_url_s: settings.aiAgentsUrl,
467
+ can_invite_b: settings.canInvite || false,
468
+ },
469
+ });
470
+ };
471
+ // Pages ------------------------------------------------------------------
472
+ const toPage = (s) => {
473
+ if (s) {
474
+ const page = asPage(s);
475
+ PAGES_BY_ID.set(s.uid, page);
476
+ return page;
477
+ }
478
+ };
479
+ const createPage = (page) => {
480
+ return requestRun({
481
+ url: `${configuration.libraryRunUrl}/api/library/v1/pages`,
482
+ method: 'POST',
483
+ body: { ...page }
484
+ }).then(resp => {
485
+ if (resp.success) {
486
+ if (resp.page) {
487
+ const pageId = resp.page.uid;
488
+ PAGES_BY_ID.set(pageId, {
489
+ ...page,
490
+ id: pageId,
491
+ });
492
+ }
493
+ }
494
+ return resp;
495
+ });
496
+ };
497
+ const updatePage = (page) => {
498
+ return requestRun({
499
+ url: `${configuration.libraryRunUrl}/api/library/v1/pages/${page.id}`,
500
+ method: 'PUT',
501
+ body: {
502
+ name: page.name,
503
+ description: page.description,
504
+ tags: page.tags,
505
+ },
506
+ }).then(resp => {
507
+ if (resp.success) {
508
+ if (resp.page) {
509
+ toPage(resp.page);
510
+ }
511
+ }
512
+ return resp;
513
+ });
514
+ };
515
+ const deletePage = (page) => {
516
+ return requestRun({
517
+ url: `${configuration.libraryRunUrl}/api/library/v1/pages/${page.id}`,
518
+ method: 'DELETE',
519
+ });
520
+ };
521
+ const getPage = (pageId) => PAGES_BY_ID.get(pageId);
522
+ const clearCachedPages = () => PAGES_BY_ID.clear();
523
+ const refreshPage = (pageId) => {
524
+ return requestRun({
525
+ url: `${configuration.libraryRunUrl}/api/library/v1/pages/${pageId}`,
526
+ method: 'GET',
527
+ }).then(resp => {
528
+ if (resp.success) {
529
+ if (resp.page) {
530
+ toPage(resp.page);
531
+ }
532
+ }
533
+ return resp;
534
+ });
535
+ };
536
+ const getPages = () => {
537
+ return Array.from(PAGES_BY_ID.values());
538
+ };
539
+ const refreshPages = () => {
540
+ return requestRun({
541
+ url: `${configuration.libraryRunUrl}/api/library/v1/pages`,
542
+ method: 'GET',
543
+ }).then(resp => {
544
+ if (resp.success) {
545
+ const pages = resp.pages;
546
+ if (pages) {
547
+ PAGES_BY_ID.clear();
548
+ pages.forEach(page => {
549
+ toPage(page);
550
+ });
551
+ }
552
+ }
553
+ return resp;
554
+ });
555
+ };
556
+ // Datasources ------------------------------------------------------------------
557
+ const toDatasource = (s) => {
558
+ if (s) {
559
+ const datasource = asDatasource(s);
560
+ DATASOURCES_BY_ID.set(s.uid, datasource);
561
+ return datasource;
562
+ }
563
+ };
564
+ const createDatasource = (datasource) => {
565
+ return requestRun({
566
+ url: `${configuration.iamRunUrl}/api/iam/v1/datasources`,
567
+ method: 'POST',
568
+ body: { ...datasource }
569
+ }).then(resp => {
570
+ if (resp.success) {
571
+ if (resp.datasource) {
572
+ toDatasource(resp.datasource);
573
+ }
574
+ }
575
+ return resp;
576
+ });
577
+ };
578
+ const updateDatasource = (datasource) => {
579
+ return requestRun({
580
+ url: `${configuration.iamRunUrl}/api/iam/v1/datasources/${datasource.id}`,
581
+ method: 'PUT',
582
+ body: { ...datasource }
583
+ }).then(resp => {
584
+ if (resp.success) {
585
+ if (resp.datasource) {
586
+ toDatasource(resp.datasource);
587
+ }
588
+ }
589
+ return resp;
590
+ });
591
+ };
592
+ const getDatasource = (datasourceId) => DATASOURCES_BY_ID.get(datasourceId);
593
+ const clearCachedDatasources = () => DATASOURCES_BY_ID.clear();
594
+ const refreshDatasource = (datasourceId) => {
595
+ return requestRun({
596
+ url: `${configuration.iamRunUrl}/api/iam/v1/datasources/${datasourceId}`,
597
+ method: 'GET',
598
+ }).then(resp => {
599
+ if (resp.success) {
600
+ if (resp.datasource) {
601
+ toDatasource(resp.datasource);
602
+ }
603
+ }
604
+ return resp;
605
+ });
606
+ };
607
+ const getDatasources = () => {
608
+ return Array.from(DATASOURCES_BY_ID.values());
609
+ };
610
+ const refreshDatasources = () => {
611
+ return requestRun({
612
+ url: `${configuration.iamRunUrl}/api/iam/v1/datasources`,
613
+ method: 'GET',
614
+ }).then(resp => {
615
+ if (resp.success) {
616
+ const datasources = resp.datasources;
617
+ if (datasources) {
618
+ SECRETS_BY_ID.clear();
619
+ datasources.forEach(datasource => {
620
+ toDatasource(datasource);
621
+ });
622
+ }
623
+ }
624
+ return resp;
625
+ });
626
+ };
627
+ // Secrets ------------------------------------------------------------------
628
+ const toSecret = (s) => {
629
+ if (s) {
630
+ const secret = asSecret(s);
631
+ SECRETS_BY_ID.set(s.uid, secret);
632
+ return secret;
633
+ }
634
+ };
635
+ const createSecret = (secret) => {
636
+ return requestRun({
637
+ url: `${configuration.iamRunUrl}/api/iam/v1/secrets`,
638
+ method: 'POST',
639
+ body: { ...secret }
640
+ }).then(resp => {
641
+ if (resp.success) {
642
+ if (resp.secret) {
643
+ toSecret(resp.secret);
644
+ }
645
+ }
646
+ return resp;
647
+ });
648
+ };
649
+ const updateSecret = (secret) => {
650
+ return requestRun({
651
+ url: `${configuration.iamRunUrl}/api/iam/v1/secrets/${secret.id}`,
652
+ method: 'PUT',
653
+ body: { ...secret }
654
+ }).then(resp => {
655
+ if (resp.success) {
656
+ if (resp.secret) {
657
+ toSecret(resp.secret);
658
+ }
659
+ }
660
+ return resp;
661
+ });
662
+ };
663
+ const deleteSecret = (secret) => {
664
+ return requestRun({
665
+ url: `${configuration.iamRunUrl}/api/iam/v1/secrets/${secret.id}`,
666
+ method: 'DELETE',
667
+ });
668
+ };
669
+ const getSecret = (secretId) => SECRETS_BY_ID.get(secretId);
670
+ const clearCachedSecrets = () => SECRETS_BY_ID.clear();
671
+ const refreshSecret = (secretId) => {
672
+ return requestRun({
673
+ url: `${configuration.iamRunUrl}/api/iam/v1/secrets/${secretId}`,
674
+ method: 'GET',
675
+ }).then(resp => {
676
+ if (resp.success) {
677
+ if (resp.secret) {
678
+ toSecret(resp.secret);
679
+ }
680
+ }
681
+ return resp;
682
+ });
683
+ };
684
+ const getSecrets = () => {
685
+ return Array.from(SECRETS_BY_ID.values());
686
+ };
687
+ const refreshSecrets = () => {
688
+ return requestRun({
689
+ url: `${configuration.iamRunUrl}/api/iam/v1/secrets`,
690
+ method: 'GET',
691
+ }).then(resp => {
692
+ if (resp.success) {
693
+ const secrets = resp.secrets;
694
+ if (secrets) {
695
+ SECRETS_BY_ID.clear();
696
+ secrets.forEach(secret => {
697
+ toSecret(secret);
698
+ });
699
+ }
700
+ }
701
+ return resp;
702
+ });
703
+ };
704
+ // Tokens ------------------------------------------------------------------
705
+ const toToken = (s) => {
706
+ if (s) {
707
+ const token = asToken(s);
708
+ TOKENS_BY_ID.set(s.uid, token);
709
+ return token;
710
+ }
711
+ };
712
+ const createToken = (token) => {
713
+ return requestRun({
714
+ url: `${configuration.iamRunUrl}/api/iam/v1/tokens`,
715
+ method: 'POST',
716
+ body: {
717
+ ...token,
718
+ expirationDate: token.expirationDate.getTime(),
719
+ }
720
+ }).then(resp => {
721
+ if (resp.success) {
722
+ if (resp.token) {
723
+ toToken(resp.token);
724
+ }
725
+ }
726
+ return resp;
727
+ });
728
+ };
729
+ const updateToken = (token) => {
730
+ return requestRun({
731
+ url: `${configuration.iamRunUrl}/api/iam/v1/tokens/${token.id}`,
732
+ method: 'PUT',
733
+ body: { ...token }
734
+ }).then(resp => {
735
+ if (resp.success) {
736
+ if (resp.token) {
737
+ toToken(resp.token);
738
+ }
739
+ }
740
+ return resp;
741
+ });
742
+ };
743
+ const getToken = (tokenId) => TOKENS_BY_ID.get(tokenId);
744
+ const clearCachedTokens = () => TOKENS_BY_ID.clear();
745
+ const refreshToken = (tokenId) => {
746
+ return requestRun({
747
+ url: `${configuration.iamRunUrl}/api/iam/v1/tokens/${tokenId}`,
748
+ method: 'GET',
749
+ }).then(resp => {
750
+ if (resp.success) {
751
+ if (resp.token) {
752
+ toToken(resp.token);
753
+ }
754
+ }
755
+ return resp;
756
+ });
757
+ };
758
+ const getTokens = () => {
759
+ return Array.from(TOKENS_BY_ID.values());
760
+ };
761
+ const refreshTokens = () => {
762
+ return requestRun({
763
+ url: `${configuration.iamRunUrl}/api/iam/v1/tokens`,
764
+ method: 'GET',
765
+ }).then(resp => {
766
+ if (resp.success) {
767
+ const tokens = resp.tokens;
768
+ if (tokens) {
769
+ TOKENS_BY_ID.clear();
770
+ tokens.forEach(token => {
771
+ toToken(token);
772
+ });
773
+ }
774
+ }
775
+ return resp;
776
+ });
777
+ };
778
+ // Layout -------------------------------------------------------------------
779
+ const refreshLayout = (accountHandle, spaceHandle, user) => {
780
+ return requestRun({
781
+ url: `${configuration.spacerRunUrl}/api/spacer/v1/layouts/accounts/${accountHandle}${spaceHandle !== undefined ? '/spaces/' + spaceHandle : ''}`,
782
+ method: 'GET',
783
+ }).then(resp => {
784
+ if (resp.success) {
785
+ if (resp.user) {
786
+ toUser(resp.user);
787
+ }
788
+ let organization = undefined;
789
+ if (resp.organization) {
790
+ organization = toOrganization(resp.organization);
791
+ if (user && checkIsOrganizationMember(user, organization)) {
792
+ ORGANISATIONS_FOR_USER_BY_ID.set(organization.id, organization);
793
+ }
794
+ }
795
+ if (resp.space) {
796
+ const space = toSpace(resp.space);
797
+ if (organization) {
798
+ let osById = SPACES_BY_ID_BY_ORGANISATION_ID.get(organization.id);
799
+ if (!osById) {
800
+ osById = new Map();
801
+ SPACES_BY_ID_BY_ORGANISATION_ID.set(organization.id, osById);
802
+ }
803
+ osById.set(space.id, space);
804
+ let osByHandle = SPACES_BY_HANDLE_BY_ORGANISATION_HANDLE.get(organization.handle);
805
+ if (!osByHandle) {
806
+ osByHandle = new Map();
807
+ SPACES_BY_HANDLE_BY_ORGANISATION_HANDLE.set(organization.handle, osByHandle);
808
+ }
809
+ osByHandle.set(space.handle, space);
810
+ }
811
+ else {
812
+ SPACES_FOR_USER_BY_HANDLE.set(space.handle, space);
813
+ SPACES_FOR_USER_BY_ID.set(space.id, space);
814
+ }
815
+ }
816
+ }
817
+ return resp;
818
+ });
819
+ };
820
+ // Invites -------------------------------------------------------------------
821
+ const requestInvite = (firstName, lastName, email, socialUrl) => {
822
+ return requestRun({
823
+ url: `${configuration.growthRunUrl}/api/growth/v1/invites/request`,
824
+ method: 'POST',
825
+ body: {
826
+ first_name: firstName,
827
+ last_name: lastName,
828
+ email: email,
829
+ social_url: socialUrl,
830
+ }
831
+ });
832
+ };
833
+ const sendInvite = (invite) => {
834
+ return requestRun({
835
+ url: `${configuration.growthRunUrl}/api/growth/v1/invites`,
836
+ method: 'POST',
837
+ body: {
838
+ email: invite.to.email,
839
+ firstName: invite.to.firstName,
840
+ lastName: invite.to.lastName,
841
+ message: invite.message,
842
+ brand: invite.brand,
843
+ }
844
+ });
845
+ };
846
+ const getInvite = (token) => INVITES_BY_TOKEN.get(token);
847
+ const clearCachedInvites = () => INVITES_BY_TOKEN.clear();
848
+ const refreshInvite = (token) => {
849
+ return requestRun({
850
+ url: `${configuration.growthRunUrl}/api/growth/v1/invites/tokens/${token}`,
851
+ method: 'GET',
852
+ }).then(resp => {
853
+ if (resp.success) {
854
+ const i = resp.invite;
855
+ if (i) {
856
+ const invite = asInvite(i);
857
+ if (invite.token) {
858
+ INVITES_BY_TOKEN.set(invite.token, invite);
859
+ }
860
+ }
861
+ }
862
+ return resp;
863
+ });
864
+ };
865
+ const getInvites = () => {
866
+ return Array.from(INVITES_BY_TOKEN.values());
867
+ };
868
+ const refreshInvites = (accountId) => {
869
+ return requestRun({
870
+ url: `${configuration.growthRunUrl}/api/growth/v1/invites/users/${accountId}`,
871
+ method: 'GET',
872
+ }).then(resp => {
873
+ if (resp.success) {
874
+ resp.invites.forEach(i => {
875
+ const invite = asInvite(i);
876
+ if (invite.token) {
877
+ INVITES_BY_TOKEN.set(invite.token, invite);
878
+ }
879
+ });
880
+ }
881
+ return resp;
882
+ });
883
+ };
884
+ const putInvite = (token) => {
885
+ return requestRun({
886
+ url: `${configuration.growthRunUrl}/api/growth/v1/invites/tokens/${token}`,
887
+ method: 'PUT',
888
+ });
889
+ };
890
+ // Accounts -------------------------------------------------------------------
891
+ const refreshAccount = (accountHandle) => {
892
+ return requestRun({
893
+ url: `${configuration.iamRunUrl}/api/iam/v1/accounts/${accountHandle}`,
894
+ method: 'GET',
895
+ }).then(resp => {
896
+ if (resp.success) {
897
+ if (resp.user) {
898
+ toUser(resp.user);
899
+ }
900
+ if (resp.organization) {
901
+ toOrganization(resp.organization);
902
+ }
903
+ }
904
+ return resp;
905
+ });
906
+ };
907
+ // Contacts ---------------------------------------------------------------------
908
+ const toContact = (c) => {
909
+ if (c) {
910
+ const contact = asContact(c);
911
+ CONTACTS_BY_ID.set(contact.id, contact);
912
+ CONTACTS_BY_HANDLE.set(contact.handle, contact);
913
+ return contact;
914
+ }
915
+ };
916
+ const getContactById = (contactId) => CONTACTS_BY_ID.get(contactId);
917
+ const getContactByHandle = (contactHandle) => CONTACTS_BY_HANDLE.get(contactHandle);
918
+ const createContact = (contact) => {
919
+ return requestRun({
920
+ url: `${configuration.growthRunUrl}/api/growth/v1/contacts`,
921
+ method: 'POST',
922
+ body: {
923
+ contact,
924
+ }
925
+ }).then(resp => {
926
+ if (resp.success) {
927
+ toContact(resp.contact);
928
+ }
929
+ return resp;
930
+ });
931
+ };
932
+ const updateContact = (contactId, contact) => {
933
+ return requestRun({
934
+ url: `${configuration.growthRunUrl}/api/growth/v1/contacts/${contactId}`,
935
+ method: 'PUT',
936
+ body: {
937
+ contact,
938
+ }
939
+ }).then(resp => {
940
+ if (resp.success) {
941
+ toContact(resp.contact);
942
+ }
943
+ return resp;
944
+ });
945
+ };
946
+ const refreshContact = (contactId) => {
947
+ return requestRun({
948
+ url: `${configuration.growthRunUrl}/api/growth/v1/contacts/${contactId}`,
949
+ method: 'GET',
950
+ }).then(resp => {
951
+ if (resp.success) {
952
+ toContact(resp.contact);
953
+ }
954
+ return resp;
955
+ });
956
+ };
957
+ const searchContacts = (query) => {
958
+ return requestRun({
959
+ url: `${configuration.growthRunUrl}/api/growth/v1/contacts/search`,
960
+ method: 'POST',
961
+ body: {
962
+ query,
963
+ }
964
+ }).then(resp => {
965
+ if (resp.success) {
966
+ const contacts = resp.contacts.map(contact => toContact(contact));
967
+ resp.contacts = contacts;
968
+ }
969
+ return resp;
970
+ });
971
+ };
972
+ const assignTagToContact = (contactId, tagName) => {
973
+ return requestRun({
974
+ url: `${configuration.growthRunUrl}/api/growth/v1/contacts/${contactId}/tags/${tagName}`,
975
+ method: 'POST',
976
+ });
977
+ };
978
+ const unassignTagFromContact = (contactId, tagName) => {
979
+ return requestRun({
980
+ url: `${configuration.growthRunUrl}/api/growth/v1/contacts/${contactId}/tags/${tagName}`,
981
+ method: 'DELETE',
982
+ });
983
+ };
984
+ const deleteContact = (contactId) => {
985
+ return requestRun({
986
+ url: `${configuration.growthRunUrl}/api/growth/v1/contacts/${contactId}`,
987
+ method: 'DELETE',
988
+ });
989
+ };
990
+ const sendInviteToContact = (contact, message) => {
991
+ return requestRun({
992
+ url: `${configuration.growthRunUrl}/api/growth/v1/contacts/invites`,
993
+ method: 'POST',
994
+ body: {
995
+ contactId: contact.id,
996
+ message,
997
+ }
998
+ });
999
+ };
1000
+ // Contacts Enrich ----------------------------------------------------------
1001
+ const enrichContactEmail = (contactId, useDomain) => {
1002
+ return requestRun({
1003
+ url: `${configuration.growthRunUrl}/api/growth/v1/contacts/${contactId}/enrich/email?useDomain=${useDomain}`,
1004
+ method: 'GET',
1005
+ });
1006
+ };
1007
+ const enrichContactLinkedin = (contactId) => {
1008
+ return requestRun({
1009
+ url: `${configuration.growthRunUrl}/api/growth/v1/contacts/${contactId}/enrich/linkedin`,
1010
+ method: 'GET',
1011
+ });
1012
+ };
1013
+ const sendLinkedinConnectionRequest = (contact, message) => {
1014
+ return requestRun({
1015
+ url: `${configuration.growthRunUrl}/api/growth/v1/contacts/${contact.id}/connect/linkedin`,
1016
+ method: 'POST',
1017
+ body: {
1018
+ message,
1019
+ }
1020
+ }).then(resp => {
1021
+ if (resp.success) {
1022
+ toContact(resp.contact);
1023
+ }
1024
+ return resp;
1025
+ });
1026
+ };
1027
+ // Contacts Links -----------------------------------------------------------
1028
+ const linkUserWithContact = (userId, contactId) => {
1029
+ return requestRun({
1030
+ url: `${configuration.growthRunUrl}/api/growth/v1/users/${userId}/contacts/${contactId}`,
1031
+ method: 'POST',
1032
+ });
1033
+ };
1034
+ const unlinkUserFromContact = (userId, contactId) => {
1035
+ return requestRun({
1036
+ url: `${configuration.growthRunUrl}/api/growth/v1/users/${userId}/contacts/${contactId}`,
1037
+ method: 'DELETE',
1038
+ });
1039
+ };
1040
+ // Users --------------------------------------------------------------------
1041
+ const toUser = (u) => {
1042
+ if (u) {
1043
+ const user = asUser(u);
1044
+ USERS_BY_ID.set(user.id, user);
1045
+ USERS_BY_HANDLE.set(user.handle, user);
1046
+ return user;
1047
+ }
1048
+ };
1049
+ const getUser = (id) => USERS_BY_ID.get(id);
1050
+ const getUserByHandle = (handle) => USERS_BY_HANDLE.get(handle);
1051
+ const refreshUser = (userId) => {
1052
+ return requestRun({
1053
+ url: `${configuration.iamRunUrl}/api/iam/v1/users/${userId}`,
1054
+ method: 'GET',
1055
+ }).then(resp => {
1056
+ if (resp.success) {
1057
+ toUser(resp.user);
1058
+ }
1059
+ return resp;
1060
+ });
1061
+ };
1062
+ const searchUsers = (namingPattern) => {
1063
+ return requestRun({
1064
+ url: `${configuration.iamRunUrl}/api/iam/v1/users/search`,
1065
+ method: 'POST',
1066
+ body: {
1067
+ namingPattern
1068
+ }
1069
+ }).then(resp => {
1070
+ if (resp.success) {
1071
+ const users = resp.users.map(user => toUser(user));
1072
+ resp.users = users;
1073
+ }
1074
+ return resp;
1075
+ });
1076
+ };
1077
+ // User Roles ---------------------------------------------------------------
1078
+ const assignRoleToUser = (userId, roleName) => {
1079
+ return requestRun({
1080
+ url: `${configuration.iamRunUrl}/api/iam/v1/users/${userId}/roles/${roleName}`,
1081
+ method: 'POST',
1082
+ });
1083
+ };
1084
+ const unassignRoleFromUser = (userId, roleName) => {
1085
+ return requestRun({
1086
+ url: `${configuration.iamRunUrl}/api/iam/v1/users/${userId}/roles/${roleName}`,
1087
+ method: 'DELETE',
1088
+ });
1089
+ };
1090
+ // Organizations -------------------------------------------------------------------
1091
+ const toOrganization = (org) => {
1092
+ const organization = asOrganization(org);
1093
+ ORGANISATIONS_BY_ID.set(organization.id, organization);
1094
+ ORGANISATIONS_BY_HANDLE.set(organization.handle, organization);
1095
+ return organization;
1096
+ };
1097
+ const createOrganization = (organization) => {
1098
+ return requestRun({
1099
+ url: `${configuration.iamRunUrl}/api/iam/v1/organizations`,
1100
+ method: 'POST',
1101
+ body: {
1102
+ handle: organization.handle,
1103
+ name: organization.name,
1104
+ description: organization.description,
1105
+ }
1106
+ }).then(resp => {
1107
+ const organization = toOrganization(resp.organization);
1108
+ ORGANISATIONS_FOR_USER_BY_ID.set(organization.id, organization);
1109
+ return resp;
1110
+ });
1111
+ };
1112
+ const getOrganizationById = (organizationId) => ORGANISATIONS_BY_ID.get(organizationId);
1113
+ const getOrganizationByHandle = (organizationHandle) => ORGANISATIONS_BY_HANDLE.get(organizationHandle);
1114
+ const clearCachedOrganizations = () => {
1115
+ ORGANISATIONS_BY_HANDLE.clear();
1116
+ ORGANISATIONS_BY_ID.clear();
1117
+ ORGANISATIONS_FOR_USER_BY_ID.clear();
1118
+ };
1119
+ const refreshOrganization = (user, organizationId) => {
1120
+ return requestRun({
1121
+ url: `${configuration.iamRunUrl}/api/iam/v1/organizations/${organizationId}`,
1122
+ method: 'GET',
1123
+ }).then(resp => {
1124
+ if (resp.success) {
1125
+ const org = resp.organization;
1126
+ if (org) {
1127
+ const organization = toOrganization(org);
1128
+ if (checkIsOrganizationMember(user, organization)) {
1129
+ ORGANISATIONS_FOR_USER_BY_ID.set(organizationId, organization);
1130
+ }
1131
+ }
1132
+ }
1133
+ return resp;
1134
+ });
1135
+ };
1136
+ const updateOrganization = (organization) => {
1137
+ return requestRun({
1138
+ url: `${configuration.iamRunUrl}/api/iam/v1/organizations/${organization.id}`,
1139
+ method: 'PUT',
1140
+ body: {
1141
+ name: organization.name,
1142
+ description: organization.description,
1143
+ }
1144
+ }).then(resp => {
1145
+ if (resp.success) {
1146
+ const org = getOrganizationById(organization.id);
1147
+ if (org) {
1148
+ org.name = organization.name;
1149
+ org.description = organization.description;
1150
+ }
1151
+ }
1152
+ return resp;
1153
+ });
1154
+ };
1155
+ const getUserOrganizations = () => Array.from(ORGANISATIONS_FOR_USER_BY_ID.values());
1156
+ const getUserOrganizationById = (organizationId) => ORGANISATIONS_FOR_USER_BY_ID.get(organizationId);
1157
+ const refreshUserOrganizations = (user) => {
1158
+ return requestRun({
1159
+ url: `${configuration.iamRunUrl}/api/iam/v1/organizations`,
1160
+ method: 'GET',
1161
+ }).then(resp => {
1162
+ if (resp.success) {
1163
+ resp.organizations.forEach(org => {
1164
+ const organization = toOrganization(org);
1165
+ if (checkIsOrganizationMember(user, organization)) {
1166
+ ORGANISATIONS_FOR_USER_BY_ID.set(organization.id, organization);
1167
+ }
1168
+ });
1169
+ }
1170
+ return resp;
1171
+ });
1172
+ };
1173
+ const addMemberToOrganization = (organizationId, userId) => {
1174
+ return requestRun({
1175
+ url: `${configuration.iamRunUrl}/api/iam/v1/organizations/${organizationId}/members/${userId}`,
1176
+ method: 'POST',
1177
+ });
1178
+ };
1179
+ const removeMemberFromOrganization = (organizationId, userId) => {
1180
+ return requestRun({
1181
+ url: `${configuration.iamRunUrl}/api/iam/v1/organizations/${organizationId}/members/${userId}`,
1182
+ method: 'DELETE',
1183
+ });
1184
+ };
1185
+ const addRoleToOrganizationMember = (organizationId, userId, roleName) => {
1186
+ return requestRun({
1187
+ url: `${configuration.iamRunUrl}/api/iam/v1/organizations/${organizationId}/members/${userId}/roles/${roleName}`,
1188
+ method: 'POST',
1189
+ });
1190
+ };
1191
+ const removeRoleFromOrganizationMember = (organizationId, userId, roleName) => {
1192
+ return requestRun({
1193
+ url: `${configuration.iamRunUrl}/api/iam/v1/organizations/${organizationId}/members/${userId}/roles/${roleName}`,
1194
+ method: 'DELETE',
1195
+ });
1196
+ };
1197
+ // Teams -------------------------------------------------------------------
1198
+ const toTeam = (org, organizationId) => {
1199
+ const team = asTeam(org, organizationId);
1200
+ TEAMS_BY_ID.set(team.id, team);
1201
+ TEAMS_BY_HANDLE.set(team.handle, team);
1202
+ return team;
1203
+ };
1204
+ const createTeam = (team, organization) => {
1205
+ return requestRun({
1206
+ url: `${configuration.iamRunUrl}/api/iam/v1/teams`,
1207
+ method: 'POST',
1208
+ body: {
1209
+ handle: team.handle,
1210
+ name: team.name,
1211
+ description: team.description,
1212
+ organizationId: organization.id,
1213
+ }
1214
+ }).then(resp => {
1215
+ const team = toTeam(resp.team, organization.id);
1216
+ TEAMS_BY_HANDLE.set(team.handle, team);
1217
+ TEAMS_BY_ID.set(team.id, team);
1218
+ return resp;
1219
+ });
1220
+ };
1221
+ const getTeamById = (teamId) => TEAMS_BY_ID.get(teamId);
1222
+ const getTeamByHandle = (teamHandle) => TEAMS_BY_HANDLE.get(teamHandle);
1223
+ const clearCachedTeams = () => {
1224
+ TEAMS_BY_HANDLE.clear();
1225
+ TEAMS_BY_ID.clear();
1226
+ };
1227
+ const refreshTeam = (teamId, organizationId) => {
1228
+ return requestRun({
1229
+ url: `${configuration.iamRunUrl}/api/iam/v1/teams/${teamId}`,
1230
+ method: 'GET',
1231
+ }).then(resp => {
1232
+ if (resp.success) {
1233
+ const t = resp.team;
1234
+ if (t) {
1235
+ const team = toTeam(t, organizationId);
1236
+ TEAMS_BY_HANDLE.set(team.handle, team);
1237
+ TEAMS_BY_ID.set(team.id, team);
1238
+ }
1239
+ }
1240
+ return resp;
1241
+ });
1242
+ };
1243
+ const updateTeam = (team) => {
1244
+ return requestRun({
1245
+ url: `${configuration.iamRunUrl}/api/iam/v1/teams/${team.id}`,
1246
+ method: 'PUT',
1247
+ body: {
1248
+ name: team.name,
1249
+ description: team.description,
1250
+ }
1251
+ }).then(resp => {
1252
+ if (resp.success) {
1253
+ const t = resp.team;
1254
+ if (t) {
1255
+ const tt = toTeam(t, team.organization.id);
1256
+ TEAMS_BY_HANDLE.set(team.handle, tt);
1257
+ TEAMS_BY_ID.set(team.id, tt);
1258
+ }
1259
+ }
1260
+ return resp;
1261
+ });
1262
+ };
1263
+ const getTeamsByOrganizationId = (organizationId) => TEAMS_BY_ORGANIZATION_BY_ID.get(organizationId);
1264
+ const refreshTeams = (organizationId) => {
1265
+ return requestRun({
1266
+ url: `${configuration.iamRunUrl}/api/iam/v1/organizations/${organizationId}/teams`,
1267
+ method: 'GET',
1268
+ }).then(resp => {
1269
+ if (resp.success) {
1270
+ const teams = resp.teams.map(t => {
1271
+ const team = toTeam(t, organizationId);
1272
+ TEAMS_BY_HANDLE.set(team.handle, team);
1273
+ TEAMS_BY_ID.set(team.id, team);
1274
+ return team;
1275
+ });
1276
+ TEAMS_BY_ORGANIZATION_BY_ID.set(organizationId, teams);
1277
+ }
1278
+ return resp;
1279
+ });
1280
+ };
1281
+ const addMemberToTeam = (teamId, userId) => {
1282
+ return requestRun({
1283
+ url: `${configuration.iamRunUrl}/api/iam/v1/teams/${teamId}/members/${userId}`,
1284
+ method: 'POST',
1285
+ });
1286
+ };
1287
+ const removeMemberFromTeam = (teamId, userId) => {
1288
+ return requestRun({
1289
+ url: `${configuration.iamRunUrl}/api/iam/v1/teams/${teamId}/members/${userId}`,
1290
+ method: 'DELETE',
1291
+ });
1292
+ };
1293
+ const addRoleToTeamMember = (teamId, userId, roleName) => {
1294
+ return requestRun({
1295
+ url: `${configuration.iamRunUrl}/api/iam/v1/teams/${teamId}/members/${userId}/roles/${roleName}`,
1296
+ method: 'POST',
1297
+ });
1298
+ };
1299
+ const removeRoleFromTeamMember = (teamId, userId, roleName) => {
1300
+ return requestRun({
1301
+ url: `${configuration.iamRunUrl}/api/iam/v1/teams/${teamId}/members/${userId}/roles/${roleName}`,
1302
+ method: 'DELETE',
1303
+ });
1304
+ };
1305
+ // Schools -------------------------------------------------------------------
1306
+ const getSchools = () => {
1307
+ return Array.from(SCHOOLS_BY_ID.values());
1308
+ };
1309
+ const refreshSchools = () => {
1310
+ return requestRun({
1311
+ url: `${configuration.iamRunUrl}/api/iam/v1/organizations/schools`,
1312
+ method: 'GET',
1313
+ }).then(resp => {
1314
+ if (resp.success) {
1315
+ resp.orgs.forEach(s => {
1316
+ var dean = undefined;
1317
+ const students = new Array();
1318
+ const members = new Array();
1319
+ const courses = new Array();
1320
+ const school = {
1321
+ id: s.uid,
1322
+ type: 'school',
1323
+ handle: s.handle_s,
1324
+ name: s.name_t,
1325
+ description: s.description_t,
1326
+ dean,
1327
+ members,
1328
+ students,
1329
+ courses,
1330
+ public: s.public_b,
1331
+ creationDate: new Date(s.creation_ts_dt),
1332
+ setMembers(members) {
1333
+ this.members = members;
1334
+ }
1335
+ };
1336
+ SCHOOLS_BY_ID.set(school.id, school);
1337
+ });
1338
+ }
1339
+ return resp;
1340
+ });
1341
+ };
1342
+ // Spaces -------------------------------------------------------------------
1343
+ const toSpace = (spc) => {
1344
+ const space = asSpace(spc);
1345
+ return space;
1346
+ };
1347
+ const createSpace = (space, organization) => {
1348
+ const seedSpaceId = (space.variant === 'course')
1349
+ ? space.seedSpace?.id
1350
+ : undefined;
1351
+ return requestRun({
1352
+ url: `${configuration.spacerRunUrl}/api/spacer/v1/spaces`,
1353
+ method: 'POST',
1354
+ body: {
1355
+ name: space.name,
1356
+ description: space.description,
1357
+ variant: space.variant,
1358
+ public: space.public,
1359
+ spaceHandle: space.handle,
1360
+ organizationId: organization?.id,
1361
+ seedSpaceId,
1362
+ }
1363
+ }).then(resp => {
1364
+ const spc = resp.space;
1365
+ if (spc) {
1366
+ const space = toSpace(spc);
1367
+ if (organization) {
1368
+ let os = SPACES_BY_ID_BY_ORGANISATION_ID.get(organization.id);
1369
+ if (!os) {
1370
+ os = new Map();
1371
+ SPACES_BY_ID_BY_ORGANISATION_ID.set(organization.id, os);
1372
+ }
1373
+ os.set(space.id, space);
1374
+ }
1375
+ else {
1376
+ SPACES_FOR_USER_BY_HANDLE.set(space.handle, space);
1377
+ SPACES_FOR_USER_BY_ID.set(space.id, space);
1378
+ }
1379
+ }
1380
+ return resp;
1381
+ });
1382
+ };
1383
+ const getOrganizationSpace = (organizationId, spaceId) => {
1384
+ const organizationSpaces = SPACES_BY_ID_BY_ORGANISATION_ID.get(organizationId);
1385
+ return organizationSpaces ? organizationSpaces.get(spaceId) : undefined;
1386
+ };
1387
+ const getOrganizationSpaceByHandle = (organizationHandle, spaceHandle) => {
1388
+ const organizationSpaces = SPACES_BY_HANDLE_BY_ORGANISATION_HANDLE.get(organizationHandle);
1389
+ return organizationSpaces ? organizationSpaces.get(spaceHandle) : undefined;
1390
+ };
1391
+ const refreshOrganizationSpace = (organizationId, spaceId) => {
1392
+ return requestRun({
1393
+ url: `${configuration.spacerRunUrl}/api/spacer/v1/spaces/${spaceId}/organizations/${organizationId}`,
1394
+ method: 'GET',
1395
+ }).then(resp => {
1396
+ if (resp.success) {
1397
+ const spc = resp.space;
1398
+ if (spc) {
1399
+ const space = toSpace(spc);
1400
+ let os = SPACES_BY_ID_BY_ORGANISATION_ID.get(organizationId);
1401
+ if (!os) {
1402
+ os = new Map();
1403
+ SPACES_BY_ID_BY_ORGANISATION_ID.set(organizationId, os);
1404
+ }
1405
+ os.set(space.id, space);
1406
+ }
1407
+ }
1408
+ return resp;
1409
+ });
1410
+ };
1411
+ const exportSpace = (spaceId) => {
1412
+ return requestRun({
1413
+ url: `${configuration.spacerRunUrl}/api/spacer/v1/spaces/${spaceId}/export`,
1414
+ method: 'GET',
1415
+ });
1416
+ };
1417
+ const updateOrganizationSpace = (organization, space) => {
1418
+ return requestRun({
1419
+ url: `${configuration.spacerRunUrl}/api/spacer/v1/spaces/${space.id}/organizations/${organization.id}`,
1420
+ method: 'PUT',
1421
+ body: {
1422
+ name: space.name,
1423
+ description: space.description,
1424
+ }
1425
+ }).then(resp => {
1426
+ if (resp.success) {
1427
+ const spc = getOrganizationSpace(organization.id, space.id);
1428
+ if (spc) {
1429
+ spc.name = space.name;
1430
+ spc.description = space.description;
1431
+ }
1432
+ }
1433
+ return resp;
1434
+ });
1435
+ };
1436
+ const getOrganizationSpaces = (organizationId) => {
1437
+ const spaces = SPACES_BY_ID_BY_ORGANISATION_ID.get(organizationId);
1438
+ if (spaces) {
1439
+ return Array.from(spaces.values());
1440
+ }
1441
+ return [];
1442
+ };
1443
+ const refreshOrganizationSpaces = (organizationId) => {
1444
+ return requestRun({
1445
+ url: `${configuration.spacerRunUrl}/api/spacer/v1/spaces/organizations/${organizationId}`,
1446
+ method: 'GET',
1447
+ }).then(resp => {
1448
+ if (resp.success) {
1449
+ resp.spaces.forEach(org => {
1450
+ const space = toSpace(org);
1451
+ let organizationSpaces = SPACES_BY_ID_BY_ORGANISATION_ID.get(organizationId);
1452
+ if (!organizationSpaces) {
1453
+ organizationSpaces = new Map();
1454
+ SPACES_BY_ID_BY_ORGANISATION_ID.set(organizationId, organizationSpaces);
1455
+ }
1456
+ organizationSpaces.set(space.id, space);
1457
+ });
1458
+ }
1459
+ return resp;
1460
+ });
1461
+ };
1462
+ const getUserSpaces = () => Array.from(SPACES_FOR_USER_BY_ID.values());
1463
+ const refreshUserSpaces = () => {
1464
+ return requestRun({
1465
+ url: `${configuration.spacerRunUrl}/api/spacer/v1/spaces/users/me`,
1466
+ method: 'GET',
1467
+ }).then(resp => {
1468
+ if (resp.success) {
1469
+ resp.spaces.forEach(spc => {
1470
+ const space = toSpace(spc);
1471
+ SPACES_FOR_USER_BY_HANDLE.set(space.handle, space);
1472
+ SPACES_FOR_USER_BY_ID.set(space.id, space);
1473
+ });
1474
+ }
1475
+ return resp;
1476
+ });
1477
+ };
1478
+ const getUserSpace = (userId) => SPACES_FOR_USER_BY_ID.get(userId);
1479
+ const getUserSpaceByHandle = (userHandle) => SPACES_FOR_USER_BY_HANDLE.get(userHandle);
1480
+ const refreshUserSpace = (userId, spaceId) => {
1481
+ return requestRun({
1482
+ url: `${configuration.spacerRunUrl}/api/spacer/v1/spaces/${spaceId}/users/${userId}`,
1483
+ method: 'GET',
1484
+ }).then(resp => {
1485
+ if (resp.success) {
1486
+ const spc = resp.space;
1487
+ if (spc) {
1488
+ const space = toSpace(spc);
1489
+ SPACES_FOR_USER_BY_HANDLE.set(space.handle, space);
1490
+ SPACES_FOR_USER_BY_ID.set(spaceId, space);
1491
+ }
1492
+ }
1493
+ return resp;
1494
+ });
1495
+ };
1496
+ const updateSpace = (space) => {
1497
+ return requestRun({
1498
+ url: `${configuration.spacerRunUrl}/api/spacer/v1/spaces/${space.id}/users/${user?.id}`,
1499
+ method: 'PUT',
1500
+ body: {
1501
+ name: space.name,
1502
+ description: space.description,
1503
+ }
1504
+ }).then(resp => {
1505
+ if (resp.success) {
1506
+ const spc = getUserSpace(space.id);
1507
+ if (spc) {
1508
+ spc.name = space.name;
1509
+ spc.description = space.description;
1510
+ }
1511
+ }
1512
+ return resp;
1513
+ });
1514
+ };
1515
+ const addMemberToOrganizationSpace = (organizationId, spaceId, accountId) => {
1516
+ return requestRun({
1517
+ url: `${configuration.spacerRunUrl}/api/spacer/v1/spaces/${spaceId}/organizations/${organizationId}/members/${accountId}`,
1518
+ method: 'POST',
1519
+ });
1520
+ };
1521
+ const removeMemberFromOrganizationSpace = (organizationId, spaceId, accountId) => {
1522
+ return requestRun({
1523
+ url: `${configuration.spacerRunUrl}/api/spacer/v1/spaces/${spaceId}/organizations/${organizationId}/members/${accountId}`,
1524
+ method: 'DELETE',
1525
+ }).then(resp => {
1526
+ // if (resp.success) {
1527
+ // OR.delete(accountHandle);
1528
+ // }
1529
+ return resp;
1530
+ });
1531
+ };
1532
+ const makeSpacePublic = (spaceId) => {
1533
+ return requestRun({
1534
+ url: `${configuration.spacerRunUrl}/api/spacer/v1/spaces/${spaceId}/public`,
1535
+ method: 'PUT',
1536
+ });
1537
+ };
1538
+ const makeSpacePrivate = (spaceId) => {
1539
+ return requestRun({
1540
+ url: `${configuration.spacerRunUrl}/api/spacer/v1/spaces/${spaceId}/private`,
1541
+ method: 'PUT',
1542
+ });
1543
+ };
1544
+ // Courses -------------------------------------------------------------------
1545
+ const toStudentItem = (raw_student_item, itemId) => {
1546
+ const studentItem = {
1547
+ id: raw_student_item.uid,
1548
+ type: 'student_item',
1549
+ student: user,
1550
+ points: raw_student_item.points_i ?? 0,
1551
+ completed: raw_student_item.completed_b,
1552
+ itemId,
1553
+ itemType: raw_student_item.item_type_s,
1554
+ pass: raw_student_item.pass_b,
1555
+ codeStudent: raw_student_item.code_student_t,
1556
+ invalid: raw_student_item.invalid_b,
1557
+ invalidReason: raw_student_item.invalid_reason_t,
1558
+ nbgrades: raw_student_item.nbgrades,
1559
+ nbgradesTotalPoints: raw_student_item.nbgrades_total_points_f,
1560
+ nbgradesTotalScore: raw_student_item.nbgrades_total_score_f,
1561
+ };
1562
+ return studentItem;
1563
+ };
1564
+ const toStudent = (raw_student, courseId) => {
1565
+ let student = undefined;
1566
+ if (raw_student) {
1567
+ const user = toUser(raw_student);
1568
+ if (user) {
1569
+ let studentItems;
1570
+ if (raw_student.student_items) {
1571
+ studentItems = new Map();
1572
+ raw_student.student_items.forEach(raw_student_item => {
1573
+ const itemId = raw_student_item.item_uid;
1574
+ const studentItem = toStudentItem(raw_student_item, itemId);
1575
+ studentItems?.set(itemId, studentItem);
1576
+ });
1577
+ }
1578
+ student = {
1579
+ ...user,
1580
+ studentItems,
1581
+ };
1582
+ STUDENTS_BY_ID.set(courseId + '-' + student.id, student);
1583
+ }
1584
+ }
1585
+ return student;
1586
+ };
1587
+ const toCourse = (raw_course, cache) => {
1588
+ const owner = newUserMock();
1589
+ USERS_BY_ID.set(owner.id, owner);
1590
+ let instructor = undefined;
1591
+ if (raw_course.members) {
1592
+ let raw_instructor = raw_course.members;
1593
+ if (Array.isArray(raw_instructor)) {
1594
+ raw_instructor = raw_instructor[0];
1595
+ }
1596
+ instructor = {
1597
+ id: raw_instructor.uid,
1598
+ handle: raw_instructor.handle_s,
1599
+ email: raw_instructor.email_s,
1600
+ firstName: raw_instructor.first_name_t,
1601
+ lastName: raw_instructor.last_name_t,
1602
+ initials: namesAsInitials(raw_instructor.to_first_name_t, raw_instructor.to_last_name_t),
1603
+ displayName: asDisplayName(raw_instructor.first_name_t, raw_instructor.last_name_t),
1604
+ roles: [],
1605
+ iamProviders: [],
1606
+ setRoles: (roles) => { },
1607
+ unsubscribedFromOutbounds: false,
1608
+ onboarding: BOOTSTRAP_USER_ONBOARDING,
1609
+ linkedContactId: undefined,
1610
+ events: [],
1611
+ settings: {}
1612
+ };
1613
+ USERS_BY_ID.set(instructor.id, instructor);
1614
+ }
1615
+ let students = undefined;
1616
+ if (raw_course.students) {
1617
+ students = new Map();
1618
+ raw_course.students.forEach(raw_stud => {
1619
+ const student = toStudent(raw_stud, raw_course.uid);
1620
+ if (student) {
1621
+ students.set(student.id, student);
1622
+ }
1623
+ });
1624
+ }
1625
+ let itemIds = new Array();
1626
+ let raw_item_uids = raw_course.item_uids_s;
1627
+ if (raw_item_uids && raw_item_uids !== '()') {
1628
+ raw_item_uids = raw_item_uids.replace('(', '').replace(')', '');
1629
+ itemIds = raw_item_uids.split(' ');
1630
+ }
1631
+ let items = new Array();
1632
+ if (raw_course.items) {
1633
+ raw_course.items.forEach(item => {
1634
+ const i = toItem(item);
1635
+ items.push(i);
1636
+ });
1637
+ }
1638
+ const course = {
1639
+ id: raw_course.uid,
1640
+ handle: raw_course.handle_s,
1641
+ type: 'space',
1642
+ variant: "course",
1643
+ name: raw_course.name_t,
1644
+ description: raw_course.description_t,
1645
+ creationDate: new Date(raw_course.creation_ts_dt),
1646
+ public: raw_course.public_b ?? false,
1647
+ items,
1648
+ itemIds,
1649
+ instructor,
1650
+ students,
1651
+ owner,
1652
+ };
1653
+ cache.set(course.id, course);
1654
+ return course;
1655
+ };
1656
+ const getCourse = (courseId) => COURSES_BY_ID.get(courseId);
1657
+ const updateCourse = (courseId, name, description) => {
1658
+ return requestRun({
1659
+ url: `${configuration.spacerRunUrl}/api/spacer/v1/courses/${courseId}`,
1660
+ method: 'PUT',
1661
+ body: {
1662
+ name,
1663
+ description,
1664
+ }
1665
+ });
1666
+ };
1667
+ const refreshCourse = (courseId) => {
1668
+ return requestRun({
1669
+ url: `${configuration.spacerRunUrl}/api/spacer/v1/courses/${courseId}`,
1670
+ method: 'GET',
1671
+ }).then(resp => {
1672
+ if (resp.success) {
1673
+ const raw_course = resp.course;
1674
+ if (raw_course) {
1675
+ toCourse(raw_course, COURSES_BY_ID);
1676
+ }
1677
+ }
1678
+ return resp;
1679
+ });
1680
+ };
1681
+ const enrollStudentToCourse = (courseId, studentId) => {
1682
+ return requestRun({
1683
+ url: `${configuration.spacerRunUrl}/api/spacer/v1/courses/${courseId}/enrollments/students/${studentId}`,
1684
+ method: 'POST',
1685
+ });
1686
+ };
1687
+ const removeStudentFromCourse = (courseId, studentId) => {
1688
+ return requestRun({
1689
+ url: `${configuration.spacerRunUrl}/api/spacer/v1/courses/${courseId}/enrollments/students/${studentId}`,
1690
+ method: 'DELETE',
1691
+ }).then(resp => {
1692
+ if (resp.success) {
1693
+ STUDENTS_BY_ID.delete(courseId);
1694
+ }
1695
+ return resp;
1696
+ });
1697
+ };
1698
+ const getStudent = (courseId, studentId) => STUDENTS_BY_ID.get(courseId + '-' + studentId);
1699
+ const refreshStudent = (courseId, studentHandle) => {
1700
+ return requestRun({
1701
+ url: `${configuration.spacerRunUrl}/api/spacer/v1/courses/${courseId}/enrollments/students/${studentHandle}`,
1702
+ method: 'GET',
1703
+ }).then(resp => {
1704
+ if (resp.success) {
1705
+ toStudent(resp.student, courseId);
1706
+ }
1707
+ return resp;
1708
+ });
1709
+ };
1710
+ const getPublicCourses = () => Array.from(PUBLIC_COURSES_BY_ID.values());
1711
+ const refreshPublicCourses = () => {
1712
+ return requestRun({
1713
+ url: `${configuration.libraryRunUrl}/api/library/v1/courses/public`,
1714
+ method: 'GET',
1715
+ }).then(resp => {
1716
+ if (resp.success) {
1717
+ resp.courses.forEach(course => {
1718
+ toCourse(course, PUBLIC_COURSES_BY_ID);
1719
+ });
1720
+ }
1721
+ return resp;
1722
+ });
1723
+ };
1724
+ const getInstructorCourses = () => Array.from(COURSES_INSTRUCTORS_BY_ID.values());
1725
+ const refreshInstructorCourses = () => {
1726
+ return requestRun({
1727
+ url: `${configuration.spacerRunUrl}/api/spacer/v1/instructors/${user?.id}/courses`,
1728
+ method: 'GET',
1729
+ }).then(resp => {
1730
+ if (resp.success) {
1731
+ resp.courses.forEach(course => {
1732
+ toCourse(course, COURSES_INSTRUCTORS_BY_ID);
1733
+ });
1734
+ }
1735
+ return resp;
1736
+ });
1737
+ };
1738
+ const getCoursesEnrollments = () => Array.from(COURSES_ENROLLMENTS_BY_ID.values());
1739
+ const refreshCoursesEnrollments = () => {
1740
+ return requestRun({
1741
+ url: `${configuration.spacerRunUrl}/api/spacer/v1/courses/enrollments/me`,
1742
+ method: 'GET',
1743
+ }).then(resp => {
1744
+ if (resp.success) {
1745
+ resp.enrollments.forEach(enrollment => {
1746
+ toCourse(enrollment, COURSES_ENROLLMENTS_BY_ID);
1747
+ });
1748
+ }
1749
+ return resp;
1750
+ });
1751
+ };
1752
+ const confirmCourseItemCompletion = (courseId, itemType, itemId, completed) => {
1753
+ return requestRun({
1754
+ url: `${configuration.spacerRunUrl}/api/spacer/v1/assignments/${courseId}/types/${itemType}/items/${itemId}/complete`,
1755
+ method: 'PUT',
1756
+ body: {
1757
+ completed,
1758
+ }
1759
+ });
1760
+ };
1761
+ const setCourseItems = (courseId, itemIds) => {
1762
+ return requestRun({
1763
+ url: `${configuration.spacerRunUrl}/api/spacer/v1/courses/${courseId}/items`,
1764
+ method: 'PUT',
1765
+ body: {
1766
+ itemIds,
1767
+ }
1768
+ });
1769
+ };
1770
+ // Surveys ---------------------------------------------------------------------
1771
+ const getUserSurveys = (userId) => {
1772
+ return requestRun({
1773
+ url: `${configuration.growthRunUrl}/api/growth/v1/surveys/users/${userId}`,
1774
+ method: 'GET',
1775
+ }).then(resp => {
1776
+ if (resp.success && resp.surveys) {
1777
+ const surveyArray = resp.surveys.map(survey => asSurvey(survey));
1778
+ const surveysMap = new Map();
1779
+ surveyArray.forEach(survey => surveysMap.set(survey.name, survey));
1780
+ resp.surveys = surveyArray;
1781
+ resp.surveysMap = surveysMap;
1782
+ }
1783
+ return resp;
1784
+ });
1785
+ };
1786
+ // Inbounds ---------------------------------------------------------------------
1787
+ const toInbound = (u) => {
1788
+ if (u) {
1789
+ const inbound = asInbound(u);
1790
+ INBOUNDS_BY_ID.set(inbound.id, inbound);
1791
+ INBOUNDS_BY_HANDLE.set(inbound.handle, inbound);
1792
+ return inbound;
1793
+ }
1794
+ };
1795
+ const getInbound = (id) => INBOUNDS_BY_ID.get(id);
1796
+ const getInboundByHandle = (handle) => INBOUNDS_BY_HANDLE.get(handle);
1797
+ const refreshInbound = (userId) => {
1798
+ return requestRun({
1799
+ url: `${configuration.inboundsRunUrl}/api/inbounds/v1/inbounds/${userId}`,
1800
+ method: 'GET',
1801
+ }).then(resp => {
1802
+ if (resp.success) {
1803
+ toInbound(resp.user);
1804
+ }
1805
+ return resp;
1806
+ });
1807
+ };
1808
+ const getInbounds = () => {
1809
+ return requestRun({
1810
+ url: `${configuration.inboundsRunUrl}/api/inbounds/v1/inbounds`,
1811
+ method: 'GET',
1812
+ }).then(resp => {
1813
+ if (resp.success) {
1814
+ const inbounds = resp.inbounds.map(user => toInbound(user));
1815
+ resp.inbounds = inbounds;
1816
+ }
1817
+ return resp;
1818
+ });
1819
+ };
1820
+ // Outbounds ---------------------------------------------------------------------
1821
+ const toOutbound = (u) => {
1822
+ if (u) {
1823
+ const user = asOutbound(u);
1824
+ OUTBOUNDS_BY_ID.set(user.id, user);
1825
+ return user;
1826
+ }
1827
+ };
1828
+ const getOutbound = (id) => OUTBOUNDS_BY_ID.get(id);
1829
+ const refreshOutbound = (outboundId) => {
1830
+ return requestRun({
1831
+ url: `${configuration.growthRunUrl}/api/growth/v1/outbounds/${outboundId}`,
1832
+ method: 'GET',
1833
+ }).then(resp => {
1834
+ if (resp.success) {
1835
+ const outbound = toOutbound(resp.outbound);
1836
+ resp.outbound = outbound;
1837
+ }
1838
+ return resp;
1839
+ });
1840
+ };
1841
+ const getOutbounds = () => {
1842
+ return requestRun({
1843
+ url: `${configuration.growthRunUrl}/api/growth/v1/outbounds`,
1844
+ method: 'GET',
1845
+ }).then(resp => {
1846
+ if (resp.success) {
1847
+ const outbounds = resp.outbounds.map(outbound => toOutbound(outbound));
1848
+ resp.outbounds = outbounds;
1849
+ }
1850
+ return resp;
1851
+ });
1852
+ };
1853
+ const draftBulkEmailsOutbounds = (params) => {
1854
+ return requestRun({
1855
+ url: `${configuration.growthRunUrl}/api/growth/v1/outbounds/emails/bulk/draft`,
1856
+ method: 'POST',
1857
+ body: params,
1858
+ });
1859
+ };
1860
+ const tryBulkEmailsOutbounds = (outboundId) => {
1861
+ return requestRun({
1862
+ url: `${configuration.growthRunUrl}/api/growth/v1/outbounds/${outboundId}/try`,
1863
+ method: 'POST',
1864
+ body: {},
1865
+ });
1866
+ };
1867
+ const launchBulkEmailsOutbounds = (outboundId) => {
1868
+ return requestRun({
1869
+ url: `${configuration.growthRunUrl}/api/growth/v1/outbounds/${outboundId}/launch`,
1870
+ method: 'POST',
1871
+ body: {},
1872
+ });
1873
+ };
1874
+ const sendOutboundEmailToUser = (userId, recipient, subject, content) => {
1875
+ return requestRun({
1876
+ url: `${configuration.growthRunUrl}/api/growth/v1/outbounds/email`,
1877
+ method: 'POST',
1878
+ body: {
1879
+ userId,
1880
+ recipient,
1881
+ subject,
1882
+ content,
1883
+ },
1884
+ });
1885
+ };
1886
+ const enableUserMFA = () => {
1887
+ return requestRun({
1888
+ url: `${configuration.iamRunUrl}/api/iam/v1/mfa`,
1889
+ method: 'PUT',
1890
+ });
1891
+ };
1892
+ const disableUserMFA = () => {
1893
+ return requestRun({
1894
+ url: `${configuration.iamRunUrl}/api/iam/v1/mfa`,
1895
+ method: 'DELETE',
1896
+ });
1897
+ };
1898
+ const validateUserMFACode = (userUid, code) => {
1899
+ return requestRun({
1900
+ url: `${configuration.iamRunUrl}/api/iam/v1/mfa`,
1901
+ method: 'POST',
1902
+ body: {
1903
+ userUid,
1904
+ code,
1905
+ },
1906
+ });
1907
+ };
1908
+ const subscribeUserToOutbounds = (userId) => {
1909
+ return requestRun({
1910
+ url: `${configuration.iamRunUrl}/api/iam/v1/outbounds/users/${userId}`,
1911
+ method: 'PUT',
1912
+ });
1913
+ };
1914
+ const unsubscribeUserFromOutbounds = (userId) => {
1915
+ return requestRun({
1916
+ url: `${configuration.iamRunUrl}/api/iam/v1/outbounds/users/${userId}`,
1917
+ method: 'DELETE',
1918
+ });
1919
+ };
1920
+ const unsubscribeContactFromOutbounds = (contactId) => {
1921
+ return requestRun({
1922
+ url: `${configuration.growthRunUrl}/api/growth/v1/contacts/unsubscribe/${contactId}`,
1923
+ method: 'GET',
1924
+ });
1925
+ };
1926
+ const unsubscribeInviteeFromOutbounds = (token) => {
1927
+ return requestRun({
1928
+ url: `${configuration.growthRunUrl}/api/growth/v1/outbounds/unsubscribe/${token}`,
1929
+ method: 'GET',
1930
+ });
1931
+ };
1932
+ const deleteOutbound = (outboundId) => {
1933
+ return requestRun({
1934
+ url: `${configuration.growthRunUrl}/api/growth/v1/outbounds/${outboundId}`,
1935
+ method: 'DELETE',
1936
+ });
1937
+ };
1938
+ // Items --------------------------------------------------------------
1939
+ const toItem = (item) => {
1940
+ if (!item.type_s) {
1941
+ console.error("No type_s found on item", item);
1942
+ return {};
1943
+ }
1944
+ switch (item.type_s) {
1945
+ case 'assignment':
1946
+ return toAssignment(item);
1947
+ case 'cell':
1948
+ return toCell(item);
1949
+ case 'dataset':
1950
+ return toDataset(item);
1951
+ case 'document':
1952
+ return toDocument(item);
1953
+ case 'exercise':
1954
+ return toExercise(item);
1955
+ case 'lesson':
1956
+ return toLesson(item);
1957
+ case 'notebook':
1958
+ return toNotebook(item);
1959
+ case 'page':
1960
+ return toPage(item);
1961
+ default:
1962
+ return {};
1963
+ }
1964
+ };
1965
+ const clearCachedPublicItems = () => PUBLIC_ITEMS_BY_ID.clear();
1966
+ const getPublicItems = () => Array.from(PUBLIC_ITEMS_BY_ID.values());
1967
+ const refreshPublicItems = () => {
1968
+ return requestRun({
1969
+ url: `${configuration.libraryRunUrl}/api/library/v1/items/public`,
1970
+ method: 'GET',
1971
+ }).then(resp => {
1972
+ if (resp.success) {
1973
+ resp.items.forEach(i => {
1974
+ const item = toItem(i);
1975
+ PUBLIC_ITEMS_BY_ID.set(item.id, item);
1976
+ });
1977
+ }
1978
+ return resp;
1979
+ });
1980
+ };
1981
+ const getSpaceItems = () => Array.from(SPACE_ITEMS_CACHE.values());
1982
+ const refreshSpaceItems = (spaceId) => {
1983
+ return requestRun({
1984
+ url: `${configuration.spacerRunUrl}/api/spacer/v1/spaces/${spaceId}/items`,
1985
+ method: 'GET',
1986
+ }).then(resp => {
1987
+ if (resp.success) {
1988
+ if (resp.items) {
1989
+ asArray(resp.items).forEach(itm => {
1990
+ const item = toItem(itm);
1991
+ SPACE_ITEMS_CACHE.set(item.id, item);
1992
+ });
1993
+ }
1994
+ }
1995
+ return resp;
1996
+ });
1997
+ };
1998
+ const makeItemPublic = (id) => {
1999
+ return requestRun({
2000
+ url: `${configuration.libraryRunUrl}/api/library/v1/items/${id}/public`,
2001
+ method: 'PUT',
2002
+ });
2003
+ };
2004
+ const makeItemPrivate = (id) => {
2005
+ return requestRun({
2006
+ url: `${configuration.libraryRunUrl}/api/library/v1/items/${id}/private`,
2007
+ method: 'PUT',
2008
+ });
2009
+ };
2010
+ const deleteItem = (itemId) => {
2011
+ return requestRun({
2012
+ url: `${configuration.spacerRunUrl}/api/spacer/v1/spaces/items/${itemId}`,
2013
+ method: 'DELETE',
2014
+ }).then(resp => {
2015
+ if (resp.success) {
2016
+ SPACE_ASSIGNMENTS_BY_ID.delete(itemId);
2017
+ SPACE_CELLS_BY_ID.delete(itemId);
2018
+ SPACE_DATASETS_BY_ID.delete(itemId);
2019
+ SPACE_DOCUMENTS_BY_ID.delete(itemId);
2020
+ SPACE_ENVIRONMENTS_BY_ID.delete(itemId);
2021
+ SPACE_EXERCISES_BY_ID.delete(itemId);
2022
+ SPACE_ITEMS_CACHE.delete(itemId);
2023
+ SPACE_LESSONS_BY_ID.delete(itemId);
2024
+ SPACE_NOTEBOOKS_BY_ID.delete(itemId);
2025
+ }
2026
+ return resp;
2027
+ });
2028
+ };
2029
+ // Search ------------------------------------------------------------------
2030
+ const searchPublicItems = (opts = DEFAULT_SEARCH_OPTS) => {
2031
+ const { q, types, max } = opts;
2032
+ const queryArgs = {
2033
+ q,
2034
+ types: `${types.join(' ')}`,
2035
+ max: max.toFixed(0).toString(),
2036
+ public: 'true',
2037
+ };
2038
+ return requestRun({
2039
+ url: `${configuration.libraryRunUrl}/api/library/v1/search${URLExt.objectToQueryString(queryArgs)}`,
2040
+ method: 'GET',
2041
+ }).then(resp => {
2042
+ if (resp.success) {
2043
+ const items = new Array();
2044
+ resp.items.forEach(i => {
2045
+ const item = toItem(i);
2046
+ items.push(item);
2047
+ });
2048
+ resp.items = items;
2049
+ }
2050
+ return resp;
2051
+ });
2052
+ };
2053
+ // Datasets ------------------------------------------------------------------
2054
+ const toDataset = (raw_dataset) => {
2055
+ const owner = newUserMock();
2056
+ USERS_BY_ID.set(owner.id, owner);
2057
+ const dataset = {
2058
+ id: raw_dataset.uid,
2059
+ type: 'dataset',
2060
+ name: raw_dataset.name_t,
2061
+ description: raw_dataset.description_t,
2062
+ fileName: raw_dataset.file_name_s,
2063
+ datasetExtension: raw_dataset.dataset_extension_s,
2064
+ contentLength: raw_dataset.content_length_i,
2065
+ contentType: raw_dataset.content_type_s,
2066
+ mimeType: raw_dataset.mimetype_s,
2067
+ path: raw_dataset.s3_path_s,
2068
+ cdnUrl: raw_dataset.cdn_url_s,
2069
+ creationDate: new Date(raw_dataset.creation_ts_dt),
2070
+ public: raw_dataset.public_b ?? false,
2071
+ lastPublicationDate: raw_dataset.creation_ts_dt ? new Date(raw_dataset.creation_ts_dt) : undefined,
2072
+ owner,
2073
+ space: {
2074
+ handle: raw_dataset.handle_s,
2075
+ },
2076
+ organization: {
2077
+ handle: raw_dataset.handle_s,
2078
+ }
2079
+ };
2080
+ SPACE_DATASETS_BY_ID.set(dataset.id, dataset);
2081
+ return dataset;
2082
+ };
2083
+ const getDataset = (id) => SPACE_DATASETS_BY_ID.get(id);
2084
+ const refreshDataset = (id) => {
2085
+ return requestRun({
2086
+ url: `${configuration.spacerRunUrl}/api/spacer/v1/spaces/items/${id}`,
2087
+ method: 'GET',
2088
+ }).then(resp => {
2089
+ if (resp.success) {
2090
+ const d = resp.item;
2091
+ if (d) {
2092
+ toDataset(d);
2093
+ }
2094
+ }
2095
+ return resp;
2096
+ });
2097
+ };
2098
+ const getSpaceDatasets = () => Array.from(SPACE_DATASETS_BY_ID.values());
2099
+ const refreshSpaceDatasets = (space, organization) => {
2100
+ const url = `${configuration.spacerRunUrl}/api/spacer/v1/spaces/${space.id}/items/types/dataset`;
2101
+ return requestRun({
2102
+ url,
2103
+ method: 'GET',
2104
+ }).then(resp => {
2105
+ if (resp.success) {
2106
+ resp.items.forEach(d => {
2107
+ toDataset(d);
2108
+ });
2109
+ }
2110
+ return resp;
2111
+ });
2112
+ };
2113
+ const updateDataset = (id, name, description) => {
2114
+ return requestRun({
2115
+ url: `${configuration.spacerRunUrl}/api/spacer/v1/datasets/${id}`,
2116
+ method: 'PUT',
2117
+ body: {
2118
+ name,
2119
+ description,
2120
+ }
2121
+ });
2122
+ };
2123
+ // Cells ------------------------------------------------------------------
2124
+ const toCell = (cl) => {
2125
+ const owner = newUserMock();
2126
+ USERS_BY_ID.set(owner.id, owner);
2127
+ const cell = {
2128
+ id: cl.uid,
2129
+ type: 'cell',
2130
+ name: cl.name_t,
2131
+ description: cl.description_t,
2132
+ source: cl.source_t,
2133
+ creationDate: new Date(cl.creation_ts_dt),
2134
+ public: cl.public_b ?? false,
2135
+ lastPublicationDate: cl.last_publication_ts_dt ? new Date(cl.last_publication_ts_dt) : undefined,
2136
+ outputshotUrl: cl.outputshot_url_s || '',
2137
+ outputshotData: OUTPUTSHOT_PLACEHOLDER_DEFAULT_SVG,
2138
+ owner,
2139
+ space: {
2140
+ handle: cl.handle_s,
2141
+ },
2142
+ organization: {
2143
+ handle: cl.handle_s,
2144
+ },
2145
+ };
2146
+ SPACE_CELLS_BY_ID.set(cell.id, cell);
2147
+ return cell;
2148
+ };
2149
+ const getCell = (id) => SPACE_CELLS_BY_ID.get(id);
2150
+ const refreshCell = (id) => {
2151
+ return requestRun({
2152
+ url: `${configuration.spacerRunUrl}/api/spacer/v1/spaces/items/${id}`,
2153
+ method: 'GET',
2154
+ }).then(resp => {
2155
+ if (resp.success) {
2156
+ const cell = resp.item;
2157
+ if (cell) {
2158
+ toCell(cell);
2159
+ }
2160
+ }
2161
+ return resp;
2162
+ });
2163
+ };
2164
+ const getSpaceCells = () => Array.from(SPACE_CELLS_BY_ID.values());
2165
+ const refreshSpaceCells = (space, organization) => {
2166
+ const url = `${configuration.spacerRunUrl}/api/spacer/v1/spaces/${space.id}/items/types/cell`;
2167
+ return requestRun({
2168
+ url,
2169
+ method: 'GET',
2170
+ }).then(resp => {
2171
+ if (resp.success) {
2172
+ resp.items.forEach(cell => {
2173
+ toCell(cell);
2174
+ });
2175
+ }
2176
+ return resp;
2177
+ });
2178
+ };
2179
+ const updateCell = (cell) => {
2180
+ return requestRun({
2181
+ url: `${configuration.spacerRunUrl}/api/spacer/v1/cells/${cell.id}`,
2182
+ method: 'PUT',
2183
+ body: cell
2184
+ });
2185
+ };
2186
+ const cloneCell = (cellId) => {
2187
+ return requestRun({
2188
+ url: `${configuration.spacerRunUrl}/api/spacer/v1/cells/${cellId}/clone`,
2189
+ method: 'POST',
2190
+ }).then(resp => {
2191
+ if (resp.success) {
2192
+ toCell(resp.cell);
2193
+ }
2194
+ return resp;
2195
+ });
2196
+ };
2197
+ // Notebooks ------------------------------------------------------------------
2198
+ const toNotebook = (raw_notebook) => {
2199
+ const owner = newUserMock();
2200
+ USERS_BY_ID.set(owner.id, owner);
2201
+ const notebook = {
2202
+ id: raw_notebook.uid,
2203
+ type: 'notebook',
2204
+ name: raw_notebook.name_t,
2205
+ description: raw_notebook.description_t,
2206
+ nbformat: raw_notebook.model_s ? JSON.parse(raw_notebook.model_s) : undefined,
2207
+ public: raw_notebook.public_b ?? false,
2208
+ creationDate: new Date(raw_notebook.creation_ts_dt),
2209
+ lastUpdateDate: raw_notebook.last_update_ts_dt ? new Date(raw_notebook.last_update_ts_dt) : undefined,
2210
+ lastPublicationDate: raw_notebook.creation_ts_dt ? new Date(raw_notebook.creation_ts_dt) : undefined,
2211
+ datasets: [],
2212
+ owner,
2213
+ space: {
2214
+ handle: raw_notebook.handle_s,
2215
+ },
2216
+ organization: {
2217
+ handle: raw_notebook.handle_s,
2218
+ }
2219
+ };
2220
+ SPACE_NOTEBOOKS_BY_ID.set(notebook.id, notebook);
2221
+ return notebook;
2222
+ };
2223
+ const getNotebook = (notebookId) => SPACE_NOTEBOOKS_BY_ID.get(notebookId);
2224
+ const refreshNotebook = (notebookId) => {
2225
+ return requestRun({
2226
+ url: `${configuration.spacerRunUrl}/api/spacer/v1/notebooks/${notebookId}`,
2227
+ method: 'GET',
2228
+ }).then(resp => {
2229
+ if (resp.success) {
2230
+ const notebook = resp.notebook;
2231
+ if (notebook) {
2232
+ toNotebook(notebook);
2233
+ }
2234
+ }
2235
+ return resp;
2236
+ });
2237
+ };
2238
+ const getSpaceNotebooks = () => Array.from(SPACE_NOTEBOOKS_BY_ID.values());
2239
+ const getSpaceNotebook = (id) => SPACE_NOTEBOOKS_BY_ID.get(id);
2240
+ const refreshSpaceNotebooks = (space, organization) => {
2241
+ const url = `${configuration.spacerRunUrl}/api/spacer/v1/spaces/${space.id}/items/types/notebook`;
2242
+ return requestRun({
2243
+ url,
2244
+ method: 'GET',
2245
+ }).then(resp => {
2246
+ if (resp.success) {
2247
+ resp.items.forEach(n => {
2248
+ toNotebook(n);
2249
+ });
2250
+ }
2251
+ return resp;
2252
+ });
2253
+ };
2254
+ const cloneNotebook = (notebookId) => {
2255
+ return requestRun({
2256
+ url: `${configuration.spacerRunUrl}/api/spacer/v1/notebooks/${notebookId}/clone`,
2257
+ method: 'POST',
2258
+ }).then(resp => {
2259
+ if (resp.success) {
2260
+ toNotebook(resp.notebook);
2261
+ }
2262
+ return resp;
2263
+ });
2264
+ };
2265
+ const updateNotebook = (id, name, description) => {
2266
+ return requestRun({
2267
+ url: `${configuration.spacerRunUrl}/api/spacer/v1/notebooks/${id}`,
2268
+ method: 'PUT',
2269
+ body: {
2270
+ name,
2271
+ description,
2272
+ }
2273
+ });
2274
+ };
2275
+ const updateNotebookModel = (notebookId, nbformat) => {
2276
+ return requestRun({
2277
+ url: `${configuration.spacerRunUrl}/api/spacer/v1/notebooks/${notebookId}/model`,
2278
+ method: 'PUT',
2279
+ body: {
2280
+ nbformat,
2281
+ }
2282
+ });
2283
+ };
2284
+ // Documents ------------------------------------------------------------------
2285
+ const toDocument = (doc) => {
2286
+ const owner = newUserMock();
2287
+ USERS_BY_ID.set(owner.id, owner);
2288
+ const document = {
2289
+ id: doc.uid,
2290
+ type: 'document',
2291
+ name: doc.name_t,
2292
+ description: doc.description_t,
2293
+ model: doc.model_s ? JSON.parse(doc.model_s) : undefined,
2294
+ public: doc.public_b ?? false,
2295
+ creationDate: new Date(doc.creation_ts_dt),
2296
+ lastUpdateDate: doc.last_update_ts_dt ? new Date(doc.last_update_ts_dt) : undefined,
2297
+ lastPublicationDate: doc.creation_ts_dt ? new Date(doc.creation_ts_dt) : undefined,
2298
+ owner,
2299
+ space: {
2300
+ handle: doc.handle_s,
2301
+ },
2302
+ organization: {
2303
+ handle: doc.handle_s,
2304
+ }
2305
+ };
2306
+ SPACE_DOCUMENTS_BY_ID.set(document.id, document);
2307
+ return document;
2308
+ };
2309
+ const getDocument = (id) => SPACE_DOCUMENTS_BY_ID.get(id);
2310
+ const refreshDocument = (id) => {
2311
+ return requestRun({
2312
+ url: `${configuration.spacerRunUrl}/api/spacer/v1/lexicals/${id}`,
2313
+ method: 'GET',
2314
+ }).then(resp => {
2315
+ if (resp.success) {
2316
+ const document = resp.document;
2317
+ if (document) {
2318
+ toDocument(document);
2319
+ }
2320
+ }
2321
+ return resp;
2322
+ });
2323
+ };
2324
+ const getSpaceDocuments = () => Array.from(SPACE_DOCUMENTS_BY_ID.values());
2325
+ const getSpaceDocument = (id) => SPACE_DOCUMENTS_BY_ID.get(id);
2326
+ const refreshSpaceDocuments = (space, organization) => {
2327
+ const url = `${configuration.spacerRunUrl}/api/spacer/v1/spaces/${space.id}/items/types/document`;
2328
+ return requestRun({
2329
+ url,
2330
+ method: 'GET',
2331
+ }).then(resp => {
2332
+ if (resp.success) {
2333
+ resp.items.forEach(n => {
2334
+ toDocument(n);
2335
+ });
2336
+ }
2337
+ return resp;
2338
+ });
2339
+ };
2340
+ const cloneDocument = (documentId) => {
2341
+ return requestRun({
2342
+ url: `${configuration.spacerRunUrl}/api/spacer/v1/lexicals/${documentId}/clone`,
2343
+ method: 'POST',
2344
+ }).then(resp => {
2345
+ if (resp.success) {
2346
+ toDocument(resp.document);
2347
+ }
2348
+ return resp;
2349
+ });
2350
+ };
2351
+ const updateDocument = (id, name, description) => {
2352
+ return requestRun({
2353
+ url: `${configuration.spacerRunUrl}/api/spacer/v1/lexicals/${id}`,
2354
+ method: 'PUT',
2355
+ body: {
2356
+ name,
2357
+ description,
2358
+ }
2359
+ });
2360
+ };
2361
+ const updateDocumentModel = (id, model) => {
2362
+ return requestRun({
2363
+ url: `${configuration.spacerRunUrl}/api/spacer/v1/lexicals/${id}/model`,
2364
+ method: 'PUT',
2365
+ body: {
2366
+ model,
2367
+ }
2368
+ });
2369
+ };
2370
+ // Environments ------------------------------------------------------------------
2371
+ const toEnvironment = (env, cache) => {
2372
+ const owner = newUserMock();
2373
+ USERS_BY_ID.set(owner.id, owner);
2374
+ const environment = {
2375
+ id: env.uid,
2376
+ type: 'environment',
2377
+ name: env.name_t,
2378
+ description: env.description_t,
2379
+ creationDate: new Date(env.creation_ts_dt),
2380
+ public: env.public_b ?? false,
2381
+ lastPublicationDate: env.creation_ts_dt ? new Date(env.creation_ts_dt) : undefined,
2382
+ owner,
2383
+ space: {
2384
+ handle: env.handle_s,
2385
+ },
2386
+ organization: {
2387
+ handle: env.handle_s,
2388
+ }
2389
+ };
2390
+ cache.set(environment.id, environment);
2391
+ return environment;
2392
+ };
2393
+ const getEnvironment = (id) => SPACE_ENVIRONMENTS_BY_ID.get(id);
2394
+ const refreshEnvironment = (id) => {
2395
+ return requestRun({
2396
+ url: `${configuration.spacerRunUrl}/api/spacer/v1/spaces/items/${id}`,
2397
+ method: 'GET',
2398
+ }).then(resp => {
2399
+ if (resp.success) {
2400
+ const env = resp.item;
2401
+ if (env) {
2402
+ toEnvironment(env, SPACE_ENVIRONMENTS_BY_ID);
2403
+ }
2404
+ }
2405
+ return resp;
2406
+ });
2407
+ };
2408
+ const getSpaceEnvironments = () => Array.from(SPACE_ENVIRONMENTS_BY_ID.values());
2409
+ const refreshSpaceEnvironments = (space, organization) => {
2410
+ const url = `${configuration.spacerRunUrl}/api/spacer/v1/spaces/${space.id}/items/types/environment`;
2411
+ return requestRun({
2412
+ url,
2413
+ method: 'GET',
2414
+ }).then(resp => {
2415
+ if (resp.success) {
2416
+ resp.items.forEach(d => {
2417
+ toEnvironment(d, SPACE_ENVIRONMENTS_BY_ID);
2418
+ });
2419
+ }
2420
+ return resp;
2421
+ });
2422
+ };
2423
+ // Lessons ------------------------------------------------------------------
2424
+ const toLesson = (raw_lesson) => {
2425
+ const owner = newUserMock();
2426
+ USERS_BY_ID.set(owner.id, owner);
2427
+ const lesson = {
2428
+ id: raw_lesson.uid,
2429
+ type: 'lesson',
2430
+ name: raw_lesson.name_t,
2431
+ description: raw_lesson.description_t,
2432
+ nbformat: raw_lesson.model_s ? JSON.parse(raw_lesson.model_s) : undefined,
2433
+ public: raw_lesson.public_b ?? false,
2434
+ creationDate: new Date(raw_lesson.creation_ts_dt),
2435
+ lastUpdateDate: raw_lesson.last_update_ts_dt ? new Date(raw_lesson.last_update_ts_dt) : undefined,
2436
+ lastPublicationDate: raw_lesson.creation_ts_dt ? new Date(raw_lesson.creation_ts_dt) : undefined,
2437
+ owner,
2438
+ space: {
2439
+ handle: raw_lesson.handle_s,
2440
+ },
2441
+ organization: {
2442
+ handle: raw_lesson.handle_s,
2443
+ },
2444
+ datasets: [],
2445
+ };
2446
+ SPACE_LESSONS_BY_ID.set(lesson.id, lesson);
2447
+ return lesson;
2448
+ };
2449
+ const getLesson = (id) => SPACE_LESSONS_BY_ID.get(id);
2450
+ const refreshLesson = (id) => {
2451
+ return requestRun({
2452
+ url: `${configuration.spacerRunUrl}/api/spacer/v1/lessons/${id}`,
2453
+ method: 'GET',
2454
+ }).then(resp => {
2455
+ if (resp.success) {
2456
+ const lesson = resp.lesson;
2457
+ if (lesson) {
2458
+ toLesson(lesson);
2459
+ }
2460
+ }
2461
+ return resp;
2462
+ });
2463
+ };
2464
+ const getSpaceLessons = () => Array.from(SPACE_LESSONS_BY_ID.values());
2465
+ const getSpaceLesson = (id) => SPACE_LESSONS_BY_ID.get(id);
2466
+ const refreshSpaceLessons = (space, organization) => {
2467
+ const url = `${configuration.spacerRunUrl}/api/spacer/v1/spaces/${space.id}/items/types/lesson`;
2468
+ return requestRun({
2469
+ url,
2470
+ method: 'GET',
2471
+ }).then(resp => {
2472
+ if (resp.success) {
2473
+ resp.items.forEach(n => {
2474
+ toLesson(n);
2475
+ });
2476
+ }
2477
+ return resp;
2478
+ });
2479
+ };
2480
+ const cloneLesson = (lessonId) => {
2481
+ return requestRun({
2482
+ url: `${configuration.spacerRunUrl}/api/spacer/v1/notebooks/${lessonId}/clone`,
2483
+ method: 'POST',
2484
+ }).then(resp => {
2485
+ if (resp.success) {
2486
+ toLesson(resp.notebook);
2487
+ }
2488
+ return resp;
2489
+ });
2490
+ };
2491
+ // Exercises ------------------------------------------------------------------
2492
+ const toExercise = (ex) => {
2493
+ const owner = newUserMock();
2494
+ USERS_BY_ID.set(owner.id, owner);
2495
+ const exercise = {
2496
+ id: ex.uid,
2497
+ type: 'exercise',
2498
+ name: ex.name_t,
2499
+ description: ex.description_t,
2500
+ help: ex.help_t,
2501
+ codePre: ex.code_pre_t,
2502
+ codeQuestion: ex.code_question_t,
2503
+ codeSolution: ex.code_solution_t,
2504
+ codeTest: ex.code_test_t,
2505
+ public: ex.public_b ?? false,
2506
+ creationDate: new Date(ex.creation_ts_dt),
2507
+ lastUpdateDate: ex.last_update_ts_dt ? new Date(ex.last_update_ts_dt) : undefined,
2508
+ lastPublicationDate: ex.creation_ts_dt ? new Date(ex.creation_ts_dt) : undefined,
2509
+ owner,
2510
+ space: {
2511
+ handle: ex.handle_s,
2512
+ },
2513
+ organization: {
2514
+ handle: ex.handle_s,
2515
+ },
2516
+ datasets: [],
2517
+ };
2518
+ SPACE_EXERCISES_BY_ID.set(exercise.id, exercise);
2519
+ return exercise;
2520
+ };
2521
+ const getExercise = (id) => SPACE_EXERCISES_BY_ID.get(id);
2522
+ const refreshExercise = (id) => {
2523
+ return requestRun({
2524
+ url: `${configuration.spacerRunUrl}/api/spacer/v1/spaces/items/${id}`,
2525
+ method: 'GET',
2526
+ }).then(resp => {
2527
+ if (resp.success) {
2528
+ const exercise = resp.item;
2529
+ if (exercise) {
2530
+ toExercise(exercise);
2531
+ }
2532
+ }
2533
+ return resp;
2534
+ });
2535
+ };
2536
+ const getSpaceExercises = () => {
2537
+ return Array.from(SPACE_EXERCISES_BY_ID.values());
2538
+ };
2539
+ const refreshSpaceExercises = (space, organization) => {
2540
+ const url = `${configuration.spacerRunUrl}/api/spacer/v1/spaces/${space.id}/items/types/exercise`;
2541
+ return requestRun({
2542
+ url,
2543
+ method: 'GET',
2544
+ }).then(resp => {
2545
+ if (resp.success) {
2546
+ resp.items.forEach(d => {
2547
+ toExercise(d);
2548
+ });
2549
+ }
2550
+ return resp;
2551
+ });
2552
+ };
2553
+ const cloneExercise = (exerciseId) => {
2554
+ return requestRun({
2555
+ url: `${configuration.spacerRunUrl}/api/spacer/v1/exercises/${exerciseId}/clone`,
2556
+ method: 'POST',
2557
+ }).then(resp => {
2558
+ if (resp.success) {
2559
+ toExercise(resp.exercise);
2560
+ }
2561
+ return resp;
2562
+ });
2563
+ };
2564
+ const updateExercise = ({ id, name, description, help, codePre, codeSolution, codeQuestion, codeTest, }) => {
2565
+ return requestRun({
2566
+ url: `${configuration.spacerRunUrl}/api/spacer/v1/exercises/${id}`,
2567
+ method: 'PUT',
2568
+ body: {
2569
+ name,
2570
+ description,
2571
+ help,
2572
+ codePre,
2573
+ codeSolution,
2574
+ codeQuestion,
2575
+ codeTest,
2576
+ }
2577
+ });
2578
+ };
2579
+ const updateExercisePoints = (id, codeStudent, points) => {
2580
+ return requestRun({
2581
+ url: `${configuration.spacerRunUrl}/api/spacer/v1/exercises/${id}/points`,
2582
+ method: 'PUT',
2583
+ body: {
2584
+ codeStudent,
2585
+ points,
2586
+ }
2587
+ });
2588
+ };
2589
+ // Assignments ------------------------------------------------------------------
2590
+ const toAssignment = (raw_assignment) => {
2591
+ const owner = newUserMock();
2592
+ USERS_BY_ID.set(owner.id, owner);
2593
+ let studentItem = undefined;
2594
+ if (raw_assignment.student_items) {
2595
+ raw_assignment.student_items.forEach(student_item => {
2596
+ studentItem = {
2597
+ id: student_item.uid,
2598
+ type: "student_item",
2599
+ itemId: student_item.item_uid,
2600
+ itemType: student_item.item_type_s,
2601
+ nbgrades: student_item.nbgrades,
2602
+ nbgradesTotalPoints: student_item.nbgrades_total_points_f,
2603
+ nbgradesTotalScore: student_item.nbgrades_total_score_f,
2604
+ };
2605
+ });
2606
+ }
2607
+ USERS_BY_ID.set(owner.id, owner);
2608
+ const assignment = {
2609
+ id: raw_assignment.uid,
2610
+ type: 'assignment',
2611
+ name: raw_assignment.name_t,
2612
+ description: raw_assignment.description_t,
2613
+ nbformat: raw_assignment.model_s ? JSON.parse(raw_assignment.model_s) : undefined,
2614
+ public: raw_assignment.public_b ?? false,
2615
+ creationDate: new Date(raw_assignment.creation_ts_dt),
2616
+ lastUpdateDate: raw_assignment.last_update_ts_dt ? new Date(raw_assignment.last_update_ts_dt) : undefined,
2617
+ lastPublicationDate: raw_assignment.creation_ts_dt ? new Date(raw_assignment.creation_ts_dt) : undefined,
2618
+ studentItem,
2619
+ datasets: [],
2620
+ owner,
2621
+ space: {
2622
+ handle: raw_assignment.handle_s,
2623
+ },
2624
+ organization: {
2625
+ handle: raw_assignment.handle_s,
2626
+ },
2627
+ };
2628
+ SPACE_ASSIGNMENTS_BY_ID.set(assignment.id, assignment);
2629
+ STUDENT_ASSIGNMENTS_BY_ID.set(assignment.id, assignment);
2630
+ return assignment;
2631
+ };
2632
+ const getAssignment = (assignmentId) => SPACE_ASSIGNMENTS_BY_ID.get(assignmentId);
2633
+ const refreshAssignment = (assignmentId) => {
2634
+ return requestRun({
2635
+ url: `${configuration.spacerRunUrl}/api/spacer/v1/assignments/${assignmentId}`,
2636
+ method: 'GET',
2637
+ }).then(resp => {
2638
+ if (resp.success) {
2639
+ const assignment = resp.assignment;
2640
+ if (assignment) {
2641
+ toAssignment(assignment);
2642
+ }
2643
+ }
2644
+ return resp;
2645
+ });
2646
+ };
2647
+ const getAssignmentForStudent = (assignmentId) => STUDENT_ASSIGNMENTS_BY_ID.get(assignmentId);
2648
+ const refreshAssignmentForStudent = (courseId, user, assignmentId) => {
2649
+ return requestRun({
2650
+ url: `${configuration.spacerRunUrl}/api/spacer/v1/assignments/${assignmentId}/courses/${courseId}/students/${user.id}`,
2651
+ method: 'GET',
2652
+ }).then(resp => {
2653
+ if (resp.success) {
2654
+ const assignment = resp.assignment;
2655
+ if (assignment) {
2656
+ toAssignment(assignment);
2657
+ }
2658
+ }
2659
+ return resp;
2660
+ });
2661
+ };
2662
+ const resetAssignmentForStudent = (courseId, user, assignmentId) => {
2663
+ return requestRun({
2664
+ url: `${configuration.spacerRunUrl}/api/spacer/v1/assignments/${assignmentId}/reset`,
2665
+ method: 'POST',
2666
+ }).then(resp => {
2667
+ if (resp.success) {
2668
+ const assignment = resp.assignment;
2669
+ if (assignment) {
2670
+ toAssignment(assignment);
2671
+ }
2672
+ }
2673
+ return resp;
2674
+ });
2675
+ };
2676
+ const gradeAssignmentForStudent = (courseId, user, assignmentId, model) => {
2677
+ return requestRun({
2678
+ url: `${configuration.spacerRunUrl}/api/spacer/v1/assignments/${assignmentId}/students/${user.id}/grade`,
2679
+ method: 'PUT',
2680
+ body: {
2681
+ model,
2682
+ }
2683
+ }).then(resp => {
2684
+ if (resp.success) {
2685
+ const assignment = resp.assignment;
2686
+ if (assignment) {
2687
+ toAssignment(assignment);
2688
+ }
2689
+ }
2690
+ return resp;
2691
+ });
2692
+ };
2693
+ const getSpaceAssignments = () => Array.from(SPACE_ASSIGNMENTS_BY_ID.values());
2694
+ const getSpaceAssignment = (id) => SPACE_ASSIGNMENTS_BY_ID.get(id);
2695
+ const refreshSpaceAssignments = (space, organization) => {
2696
+ const url = `${configuration.spacerRunUrl}/api/spacer/v1/spaces/${space.id}/items/types/assignment`;
2697
+ return requestRun({
2698
+ url,
2699
+ method: 'GET',
2700
+ }).then(resp => {
2701
+ if (resp.success) {
2702
+ resp.items.forEach(n => {
2703
+ toAssignment(n);
2704
+ });
2705
+ }
2706
+ return resp;
2707
+ });
2708
+ };
2709
+ const cloneAssignment = (assignmentId) => {
2710
+ return requestRun({
2711
+ url: `${configuration.spacerRunUrl}/api/spacer/v1/notebooks/${assignmentId}/clone`,
2712
+ method: 'POST',
2713
+ }).then(resp => {
2714
+ if (resp.success) {
2715
+ toAssignment(resp.notebook);
2716
+ }
2717
+ return resp;
2718
+ });
2719
+ };
2720
+ const getAssignmentStudentVersion = (assignmentId) => {
2721
+ return requestRun({
2722
+ url: `${configuration.spacerRunUrl}/api/spacer/v1/assignments/${assignmentId}/student_version`,
2723
+ method: 'GET',
2724
+ });
2725
+ };
2726
+ // Prices -------------------------------------------------------------------
2727
+ const refreshStripePrices = () => {
2728
+ return requestRun({
2729
+ url: `${configuration.iamRunUrl}/api/iam/stripe/v1/prices`,
2730
+ method: 'GET',
2731
+ });
2732
+ };
2733
+ // Checkout -------------------------------------------------------------------
2734
+ const createCheckoutSession = (product, location) => {
2735
+ return requestRun({
2736
+ url: `${configuration.iamRunUrl}/api/iam/stripe/v1/checkout/session`,
2737
+ method: 'POST',
2738
+ body: {
2739
+ price_id: product?.id,
2740
+ return_url: `${location.protocol}//${location.host}${location.pathname.split('/').slice(0, -1).join('/')}`
2741
+ }
2742
+ })
2743
+ .then(data => data.client_secret)
2744
+ .catch(error => {
2745
+ console.error('Failed to create Stripe checkout session.', error);
2746
+ });
2747
+ };
2748
+ // Credits -------------------------------------------------------------------
2749
+ const burnCredit = (credits) => {
2750
+ return requestRun({
2751
+ url: `${configuration.iamRunUrl}/api/iam/v1/usage/credits`,
2752
+ method: "DELETE",
2753
+ body: {
2754
+ credits,
2755
+ }
2756
+ });
2757
+ };
2758
+ const getUserCredits = (userId) => {
2759
+ return requestRun({
2760
+ url: `${configuration.iamRunUrl}/api/iam/v1/usage/credits/users/${userId}`,
2761
+ method: "GET",
2762
+ });
2763
+ };
2764
+ const updateUserCredits = (userId, credits, brand) => {
2765
+ return requestRun({
2766
+ url: `${configuration.iamRunUrl}/api/iam/v1/usage/credits/users/${userId}`,
2767
+ method: "PUT",
2768
+ body: {
2769
+ credits,
2770
+ brand,
2771
+ }
2772
+ });
2773
+ };
2774
+ const updateUserCreditsQuota = (userId, quota) => {
2775
+ return requestRun({
2776
+ url: `${configuration.iamRunUrl}/api/iam/v1/usage/quota`,
2777
+ method: "PUT",
2778
+ body: {
2779
+ user_uid: userId,
2780
+ quota,
2781
+ reset: "0",
2782
+ }
2783
+ });
2784
+ };
2785
+ // Usages -------------------------------------------------------------------
2786
+ /**
2787
+ * Get user usages
2788
+ */
2789
+ const getUsages = async () => {
2790
+ const data = await requestRun({
2791
+ url: `${configuration.iamRunUrl}/api/iam/v1/usage/user`,
2792
+ method: "GET",
2793
+ });
2794
+ data.usages = (data.usages ?? []).map(u => asUsage(u));
2795
+ return data;
2796
+ };
2797
+ /**
2798
+ * Get user usages
2799
+ */
2800
+ const getUsagesForUser = async (userId) => {
2801
+ const data = await requestRun({
2802
+ url: `${configuration.iamRunUrl}/api/iam/v1/usage/users/${userId}`,
2803
+ method: "GET",
2804
+ });
2805
+ data.usages = (data.usages ?? []).map(u => asUsage(u));
2806
+ return data;
2807
+ };
2808
+ /**
2809
+ * Get platform usages
2810
+ */
2811
+ const getPlatformUsages = async () => {
2812
+ const data = await requestRun({
2813
+ url: `${configuration.iamRunUrl}/api/iam/v1/usage/platform`,
2814
+ method: "GET",
2815
+ });
2816
+ data.usages = (data.usages ?? []).map(u => asUsage(u));
2817
+ return data;
2818
+ };
2819
+ // Support ------------------------------------------------------------------
2820
+ const requestPlatformSupport = (subject, message, email, brand) => {
2821
+ return requestRun({
2822
+ url: `${configuration.supportRunUrl}/api/support/v1/support/request`,
2823
+ method: 'POST',
2824
+ body: {
2825
+ subject,
2826
+ message,
2827
+ email,
2828
+ brand,
2829
+ }
2830
+ });
2831
+ };
2832
+ const requestPlatformSupport2 = (accountHandle, firstName, lastName, email, message) => {
2833
+ return requestRun({
2834
+ url: `${configuration.supportRunUrl}/api/support/v1/support/request2`,
2835
+ method: 'POST',
2836
+ body: {
2837
+ accountHandle,
2838
+ firstName,
2839
+ lastName,
2840
+ email,
2841
+ message,
2842
+ }
2843
+ });
2844
+ };
2845
+ // Growth ------------------------------------------------------------------
2846
+ const getGrowthKPI = () => {
2847
+ return requestRun({
2848
+ url: `${configuration.growthRunUrl}/api/growth/v1/kpis`,
2849
+ method: 'GET',
2850
+ });
2851
+ };
2852
+ // --------------------------------------------------------------------------
2853
+ return {
2854
+ addMemberToOrganization,
2855
+ addMemberToOrganizationSpace,
2856
+ addMemberToTeam,
2857
+ addRoleToOrganizationMember,
2858
+ addRoleToTeamMember,
2859
+ assignRoleToUser,
2860
+ assignTagToContact,
2861
+ burnCredit,
2862
+ changePassword,
2863
+ clearAllCaches,
2864
+ clearCachedDatasources,
2865
+ clearCachedInvites,
2866
+ clearCachedItems,
2867
+ clearCachedOrganizations,
2868
+ clearCachedPages,
2869
+ clearCachedPublicItems,
2870
+ clearCachedSecrets,
2871
+ clearCachedTeams,
2872
+ clearCachedTokens,
2873
+ cloneAssignment,
2874
+ cloneCell,
2875
+ cloneDocument,
2876
+ cloneExercise,
2877
+ cloneLesson,
2878
+ cloneNotebook,
2879
+ confirmCourseItemCompletion,
2880
+ confirmEmailUpdate,
2881
+ confirmJoinWithToken,
2882
+ confirmPassworkWithToken,
2883
+ createCheckoutSession,
2884
+ createContact,
2885
+ createDatasource,
2886
+ createOrganization,
2887
+ createPage,
2888
+ createSecret,
2889
+ createSpace,
2890
+ createTeam,
2891
+ createToken,
2892
+ createTokenForPasswordChange,
2893
+ deleteContact,
2894
+ deleteItem,
2895
+ deleteOutbound,
2896
+ deletePage,
2897
+ deleteSecret,
2898
+ disableUserMFA,
2899
+ draftBulkEmailsOutbounds,
2900
+ enableUserMFA,
2901
+ enrichContactEmail,
2902
+ enrichContactLinkedin,
2903
+ enrollStudentToCourse,
2904
+ exportSpace,
2905
+ getAssignment,
2906
+ getAssignmentForStudent,
2907
+ getAssignmentStudentVersion,
2908
+ getCell,
2909
+ getContactByHandle,
2910
+ getContactById,
2911
+ getCourse,
2912
+ getCoursesEnrollments,
2913
+ getDataset,
2914
+ getDatasource,
2915
+ getDatasources,
2916
+ getDocument,
2917
+ getEnvironment,
2918
+ getExercise,
2919
+ getGitHubProfile,
2920
+ getGrowthKPI,
2921
+ getInbound,
2922
+ getInboundByHandle,
2923
+ getInbounds,
2924
+ getInstructorCourses,
2925
+ getInvite,
2926
+ getInvites,
2927
+ getLesson,
2928
+ getLinkedinProfile,
2929
+ getMe,
2930
+ getNotebook,
2931
+ getOAuth2AuthorizationLinkURL,
2932
+ getOAuth2AuthorizationURL,
2933
+ getOrganizationByHandle,
2934
+ getOrganizationById,
2935
+ getOrganizationSpace,
2936
+ getOrganizationSpaceByHandle,
2937
+ getOrganizationSpaces,
2938
+ getOutbound,
2939
+ getOutbounds,
2940
+ getPage,
2941
+ getPages,
2942
+ getPlatformUsages,
2943
+ getPublicCourses,
2944
+ getPublicItems,
2945
+ getSchools,
2946
+ getSecret,
2947
+ getSecrets,
2948
+ getSpaceAssignment,
2949
+ getSpaceAssignments,
2950
+ getSpaceCells,
2951
+ getSpaceDatasets,
2952
+ getSpaceDocument,
2953
+ getSpaceDocuments,
2954
+ getSpaceEnvironments,
2955
+ getSpaceExercises,
2956
+ getSpaceItems,
2957
+ getSpaceLesson,
2958
+ getSpaceLessons,
2959
+ getSpaceNotebook,
2960
+ getSpaceNotebooks,
2961
+ getStudent,
2962
+ getTeamByHandle,
2963
+ getTeamById,
2964
+ getTeamsByOrganizationId,
2965
+ getToken,
2966
+ getTokens,
2967
+ getUsages,
2968
+ getUsagesForUser,
2969
+ getUser,
2970
+ getUserByHandle,
2971
+ getUserCredits,
2972
+ getUserOrganizationById,
2973
+ getUserOrganizations,
2974
+ getUserSpace,
2975
+ getUserSpaceByHandle,
2976
+ getUserSpaces,
2977
+ getUserSurveys,
2978
+ gradeAssignmentForStudent,
2979
+ joinWithInvite,
2980
+ launchBulkEmailsOutbounds,
2981
+ linkUserWithContact,
2982
+ login,
2983
+ logout,
2984
+ makeItemPrivate,
2985
+ makeItemPublic,
2986
+ makeSpacePrivate,
2987
+ makeSpacePublic,
2988
+ postLinkedinShare,
2989
+ postLinkedinShareWithUpload,
2990
+ proxyGET,
2991
+ proxyPOST,
2992
+ proxyPUT,
2993
+ putInvite,
2994
+ refreshAccount,
2995
+ refreshAssignment,
2996
+ refreshAssignmentForStudent,
2997
+ refreshCell,
2998
+ refreshContact,
2999
+ refreshCourse,
3000
+ refreshCoursesEnrollments,
3001
+ refreshDataset,
3002
+ refreshDatasource,
3003
+ refreshDatasources,
3004
+ refreshDocument,
3005
+ refreshEnvironment,
3006
+ refreshExercise,
3007
+ refreshInbound,
3008
+ refreshInstructorCourses,
3009
+ refreshInvite,
3010
+ refreshInvites,
3011
+ refreshLayout,
3012
+ refreshLesson,
3013
+ refreshNotebook,
3014
+ refreshOrganization,
3015
+ refreshOrganizationSpace,
3016
+ refreshOrganizationSpaces,
3017
+ refreshOutbound,
3018
+ refreshPage,
3019
+ refreshPages,
3020
+ refreshPublicCourses,
3021
+ refreshPublicItems,
3022
+ refreshSchools,
3023
+ refreshSecret,
3024
+ refreshSecrets,
3025
+ refreshSpaceAssignments,
3026
+ refreshSpaceCells,
3027
+ refreshSpaceDatasets,
3028
+ refreshSpaceDocuments,
3029
+ refreshSpaceEnvironments,
3030
+ refreshSpaceExercises,
3031
+ refreshSpaceItems,
3032
+ refreshSpaceLessons,
3033
+ refreshSpaceNotebooks,
3034
+ refreshStripePrices,
3035
+ refreshStudent,
3036
+ refreshTeam,
3037
+ refreshTeams,
3038
+ refreshToken,
3039
+ refreshTokens,
3040
+ refreshUser,
3041
+ refreshUserOrganizations,
3042
+ refreshUserSpace,
3043
+ refreshUserSpaces,
3044
+ registerToWaitingList,
3045
+ removeMemberFromOrganization,
3046
+ removeMemberFromOrganizationSpace,
3047
+ removeMemberFromTeam,
3048
+ removeRoleFromOrganizationMember,
3049
+ removeRoleFromTeamMember,
3050
+ removeStudentFromCourse,
3051
+ requestEmailUpdate,
3052
+ requestInvite,
3053
+ requestJoin,
3054
+ requestJoinToken,
3055
+ requestPlatformSupport,
3056
+ requestPlatformSupport2,
3057
+ resetAssignmentForStudent,
3058
+ searchContacts,
3059
+ searchPublicItems,
3060
+ searchUsers,
3061
+ sendInvite,
3062
+ sendInviteToContact,
3063
+ sendLinkedinConnectionRequest,
3064
+ sendOutboundEmailToUser,
3065
+ setCourseItems,
3066
+ subscribeUserToOutbounds,
3067
+ toInbound,
3068
+ toOutbound,
3069
+ tryBulkEmailsOutbounds,
3070
+ unassignRoleFromUser,
3071
+ unassignTagFromContact,
3072
+ unlinkUserFromContact,
3073
+ unsubscribeContactFromOutbounds,
3074
+ unsubscribeInviteeFromOutbounds,
3075
+ unsubscribeUserFromOutbounds,
3076
+ updateCell,
3077
+ updateContact,
3078
+ updateCourse,
3079
+ updateDataset,
3080
+ updateDatasource,
3081
+ updateDocument,
3082
+ updateDocumentModel,
3083
+ updateExercise,
3084
+ updateExercisePoints,
3085
+ updateMe,
3086
+ updateNotebook,
3087
+ updateNotebookModel,
3088
+ updateOrganization,
3089
+ updateOrganizationSpace,
3090
+ updatePage,
3091
+ updateSecret,
3092
+ updateSpace,
3093
+ updateTeam,
3094
+ updateToken,
3095
+ updateUserCredits,
3096
+ updateUserCreditsQuota,
3097
+ updateUserOnboarding,
3098
+ updateUserSettings,
3099
+ validateUserMFACode,
3100
+ whoami,
3101
+ };
3102
+ };
3103
+ export default useCache;