@datalayer/core 0.0.12 → 0.0.14

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 (249) hide show
  1. package/README.md +2 -2
  2. package/lib/api/DatalayerApi.d.ts +38 -26
  3. package/lib/api/DatalayerApi.js +52 -13
  4. package/lib/api/iam/authentication.d.ts +9 -8
  5. package/lib/api/iam/authentication.js +14 -15
  6. package/lib/api/iam/healthz.d.ts +3 -2
  7. package/lib/api/iam/healthz.js +5 -3
  8. package/lib/api/iam/index.d.ts +9 -4
  9. package/lib/api/iam/index.js +9 -4
  10. package/lib/api/iam/oauth2.d.ts +115 -0
  11. package/lib/api/iam/oauth2.js +309 -0
  12. package/lib/api/iam/profile.d.ts +8 -1
  13. package/lib/api/iam/profile.js +17 -2
  14. package/lib/api/iam/usage.d.ts +18 -0
  15. package/lib/api/iam/usage.js +39 -0
  16. package/lib/api/index.d.ts +6 -6
  17. package/lib/api/index.js +6 -7
  18. package/lib/api/runtimes/environments.d.ts +2 -2
  19. package/lib/api/runtimes/environments.js +3 -2
  20. package/lib/api/runtimes/healthz.d.ts +3 -13
  21. package/lib/api/runtimes/healthz.js +4 -3
  22. package/lib/api/runtimes/index.d.ts +3 -2
  23. package/lib/api/runtimes/index.js +3 -2
  24. package/lib/api/runtimes/runtimes.d.ts +4 -4
  25. package/lib/api/runtimes/runtimes.js +17 -6
  26. package/lib/api/runtimes/snapshots.d.ts +4 -4
  27. package/lib/api/runtimes/snapshots.js +3 -2
  28. package/lib/api/spacer/documents.d.ts +12 -0
  29. package/lib/api/spacer/documents.js +43 -0
  30. package/lib/api/spacer/healthz.d.ts +3 -13
  31. package/lib/api/spacer/healthz.js +4 -3
  32. package/lib/api/spacer/index.d.ts +4 -2
  33. package/lib/api/spacer/index.js +4 -2
  34. package/lib/api/spacer/items.d.ts +9 -1
  35. package/lib/api/spacer/items.js +17 -2
  36. package/lib/api/spacer/lexicals.d.ts +1 -1
  37. package/lib/api/spacer/lexicals.js +3 -2
  38. package/lib/api/spacer/notebooks.d.ts +1 -1
  39. package/lib/api/spacer/notebooks.js +3 -2
  40. package/lib/api/spacer/spaces.d.ts +1 -1
  41. package/lib/api/spacer/spaces.js +3 -2
  42. package/lib/api/spacer/users.d.ts +1 -1
  43. package/lib/api/spacer/users.js +3 -2
  44. package/lib/api/utils/validation.d.ts +24 -1
  45. package/lib/api/utils/validation.js +62 -1
  46. package/lib/client/base.d.ts +75 -0
  47. package/lib/client/base.js +199 -0
  48. package/lib/client/constants.d.ts +22 -0
  49. package/lib/client/constants.js +22 -0
  50. package/lib/client/index.d.ts +108 -0
  51. package/lib/client/index.js +79 -0
  52. package/lib/client/mixins/IAMMixin.d.ts +54 -0
  53. package/lib/client/mixins/IAMMixin.js +181 -0
  54. package/lib/client/mixins/RuntimesMixin.d.ts +93 -0
  55. package/lib/client/mixins/RuntimesMixin.js +229 -0
  56. package/lib/client/mixins/SpacerMixin.d.ts +111 -0
  57. package/lib/client/mixins/SpacerMixin.js +340 -0
  58. package/lib/client/utils/mixins.d.ts +12 -0
  59. package/lib/{sdk/client → client}/utils/mixins.js +0 -28
  60. package/lib/client/utils/spacerUtils.d.ts +18 -0
  61. package/lib/client/utils/spacerUtils.js +32 -0
  62. package/lib/collaboration/DatalayerCollaboration.d.ts +6 -1
  63. package/lib/collaboration/DatalayerCollaboration.js +2 -2
  64. package/lib/collaboration/DatalayerCollaborationProvider.d.ts +5 -0
  65. package/lib/collaboration/DatalayerCollaborationProvider.js +10 -9
  66. package/lib/components/progress/CreditsIndicator.d.ts +1 -1
  67. package/lib/components/runtimes/RuntimeCellVariablesDialog.js +1 -1
  68. package/lib/components/runtimes/RuntimeLauncherDialog.d.ts +1 -1
  69. package/lib/components/runtimes/RuntimeLauncherDialog.js +2 -2
  70. package/lib/components/runtimes/RuntimePickerBase.d.ts +1 -1
  71. package/lib/components/runtimes/RuntimePickerBase.js +1 -1
  72. package/lib/components/runtimes/RuntimePickerCell.js +3 -3
  73. package/lib/components/runtimes/RuntimePickerNotebook.d.ts +1 -1
  74. package/lib/components/runtimes/RuntimePickerNotebook.js +2 -2
  75. package/lib/components/runtimes/RuntimeTransfer.d.ts +2 -2
  76. package/lib/components/runtimes/RuntimeUtils.d.ts +1 -1
  77. package/lib/components/snapshots/RuntimeSnapshotMenu.d.ts +1 -1
  78. package/lib/components/snapshots/RuntimeSnapshotMenu.js +27 -20
  79. package/lib/config/Configuration.d.ts +8 -0
  80. package/lib/hooks/useDatalayer.js +1 -1
  81. package/lib/hooks/useRuntimes.js +1 -1
  82. package/lib/hooks/useToast.js +1 -1
  83. package/lib/index.d.ts +2 -3
  84. package/lib/index.js +4 -3
  85. package/lib/models/Common.d.ts +64 -0
  86. package/lib/models/CreditsDTO.d.ts +124 -0
  87. package/lib/models/CreditsDTO.js +135 -0
  88. package/lib/models/Environment.d.ts +1 -1
  89. package/lib/models/EnvironmentDTO.d.ts +125 -0
  90. package/lib/models/EnvironmentDTO.js +88 -0
  91. package/lib/models/HealthCheck.d.ts +72 -0
  92. package/lib/models/HealthCheck.js +107 -0
  93. package/lib/{api/types/iam.d.ts → models/IAM.d.ts} +15 -78
  94. package/lib/models/ItemDTO.d.ts +74 -0
  95. package/lib/models/ItemDTO.js +186 -0
  96. package/lib/models/LexicalDTO.d.ts +155 -0
  97. package/lib/models/LexicalDTO.js +157 -0
  98. package/lib/models/NotebookDTO.d.ts +96 -0
  99. package/lib/models/NotebookDTO.js +153 -0
  100. package/lib/models/Profile.d.ts +65 -0
  101. package/lib/models/RuntimeDTO.d.ts +191 -0
  102. package/lib/models/RuntimeDTO.js +204 -0
  103. package/lib/models/RuntimeSnapshotDTO.d.ts +173 -0
  104. package/lib/models/RuntimeSnapshotDTO.js +139 -0
  105. package/lib/models/SpaceDTO.d.ts +280 -0
  106. package/lib/models/SpaceDTO.js +239 -0
  107. package/lib/models/UserDTO.d.ts +86 -0
  108. package/lib/models/UserDTO.js +84 -0
  109. package/lib/models/index.d.ts +45 -4
  110. package/lib/models/index.js +45 -4
  111. package/lib/sdk/index.d.ts +5 -4
  112. package/lib/sdk/index.js +6 -5
  113. package/lib/services/DatalayerServiceManager.js +1 -1
  114. package/lib/state/substates/CoreState.js +2 -0
  115. package/lib/state/substates/RuntimesState.d.ts +1 -1
  116. package/lib/state/substates/RuntimesState.js +1 -1
  117. package/lib/{sdk/stateful → stateful}/index.d.ts +1 -1
  118. package/lib/{sdk/stateful → stateful}/index.js +1 -1
  119. package/lib/{sdk/stateful → stateful}/jupyter/exec/Snippets.d.ts +1 -41
  120. package/lib/{sdk/stateful → stateful}/jupyter/exec/Snippets.js +1 -20
  121. package/lib/{sdk/stateful → stateful}/runtimes/actions.d.ts +3 -3
  122. package/lib/{sdk/stateful → stateful}/runtimes/actions.js +8 -8
  123. package/lib/{sdk/stateful → stateful}/runtimes/apis.d.ts +8 -8
  124. package/package.json +13 -10
  125. package/lib/__tests__/hooks.test.d.ts +0 -1
  126. package/lib/__tests__/hooks.test.js +0 -19
  127. package/lib/__tests__/index.test.d.ts +0 -1
  128. package/lib/__tests__/index.test.js +0 -27
  129. package/lib/__tests__/integration.test.d.ts +0 -1
  130. package/lib/__tests__/integration.test.js +0 -57
  131. package/lib/__tests__/shared/cleanup-shared.d.ts +0 -4
  132. package/lib/__tests__/shared/cleanup-shared.js +0 -228
  133. package/lib/__tests__/shared/test-config.d.ts +0 -51
  134. package/lib/__tests__/shared/test-config.js +0 -110
  135. package/lib/__tests__/shared/test-constants.d.ts +0 -66
  136. package/lib/__tests__/shared/test-constants.js +0 -79
  137. package/lib/__tests__/utils.test.d.ts +0 -1
  138. package/lib/__tests__/utils.test.js +0 -59
  139. package/lib/api/__tests__/iam.authentication.integration.test.d.ts +0 -1
  140. package/lib/api/__tests__/iam.authentication.integration.test.js +0 -247
  141. package/lib/api/__tests__/iam.healthz.integration.test.d.ts +0 -1
  142. package/lib/api/__tests__/iam.healthz.integration.test.js +0 -63
  143. package/lib/api/__tests__/iam.profile.integration.test.d.ts +0 -1
  144. package/lib/api/__tests__/iam.profile.integration.test.js +0 -252
  145. package/lib/api/__tests__/runtimes.environments.integration.test.d.ts +0 -1
  146. package/lib/api/__tests__/runtimes.environments.integration.test.js +0 -122
  147. package/lib/api/__tests__/runtimes.healthz.integration.test.d.ts +0 -1
  148. package/lib/api/__tests__/runtimes.healthz.integration.test.js +0 -50
  149. package/lib/api/__tests__/runtimes.integration.test.d.ts +0 -1
  150. package/lib/api/__tests__/runtimes.integration.test.js +0 -369
  151. package/lib/api/__tests__/spacer.healthz.integration.test.d.ts +0 -1
  152. package/lib/api/__tests__/spacer.healthz.integration.test.js +0 -50
  153. package/lib/api/__tests__/spacer.integration.test.d.ts +0 -1
  154. package/lib/api/__tests__/spacer.integration.test.js +0 -519
  155. package/lib/api/iam/__tests__/authentication.unit.test.d.ts +0 -1
  156. package/lib/api/iam/__tests__/authentication.unit.test.js +0 -63
  157. package/lib/api/iam/__tests__/healthz.unit.test.d.ts +0 -1
  158. package/lib/api/iam/__tests__/healthz.unit.test.js +0 -60
  159. package/lib/api/iam/__tests__/profile.unit.test.d.ts +0 -1
  160. package/lib/api/iam/__tests__/profile.unit.test.js +0 -57
  161. package/lib/api/runtimes/__tests__/environments.unit.test.d.ts +0 -1
  162. package/lib/api/runtimes/__tests__/environments.unit.test.js +0 -77
  163. package/lib/api/runtimes/__tests__/healthz.unit.test.d.ts +0 -1
  164. package/lib/api/runtimes/__tests__/healthz.unit.test.js +0 -57
  165. package/lib/api/runtimes/__tests__/runtimes.unit.test.d.ts +0 -1
  166. package/lib/api/runtimes/__tests__/runtimes.unit.test.js +0 -139
  167. package/lib/api/runtimes/__tests__/snapshots.unit.test.d.ts +0 -1
  168. package/lib/api/runtimes/__tests__/snapshots.unit.test.js +0 -96
  169. package/lib/api/spacer/__tests__/healthz.unit.test.d.ts +0 -1
  170. package/lib/api/spacer/__tests__/healthz.unit.test.js +0 -57
  171. package/lib/api/spacer/__tests__/items.unit.test.d.ts +0 -1
  172. package/lib/api/spacer/__tests__/items.unit.test.js +0 -165
  173. package/lib/api/spacer/__tests__/lexicals.unit.test.d.ts +0 -1
  174. package/lib/api/spacer/__tests__/lexicals.unit.test.js +0 -323
  175. package/lib/api/spacer/__tests__/notebooks.unit.test.d.ts +0 -1
  176. package/lib/api/spacer/__tests__/notebooks.unit.test.js +0 -224
  177. package/lib/api/spacer/__tests__/users.unit.test.d.ts +0 -1
  178. package/lib/api/spacer/__tests__/users.unit.test.js +0 -132
  179. package/lib/api/types/index.d.ts +0 -32
  180. package/lib/api/types/index.js +0 -36
  181. package/lib/api/types/runtimes.d.ts +0 -235
  182. package/lib/api/types/spacer.d.ts +0 -271
  183. package/lib/api/types/spacer.js +0 -5
  184. package/lib/api/utils/__tests__/validation.test.d.ts +0 -1
  185. package/lib/api/utils/__tests__/validation.test.js +0 -109
  186. package/lib/sdk/client/__tests__/sdk.health.integration.test.d.ts +0 -1
  187. package/lib/sdk/client/__tests__/sdk.health.integration.test.js +0 -110
  188. package/lib/sdk/client/__tests__/sdk.iam.integration.test.d.ts +0 -1
  189. package/lib/sdk/client/__tests__/sdk.iam.integration.test.js +0 -179
  190. package/lib/sdk/client/__tests__/sdk.models.integration.test.d.ts +0 -1
  191. package/lib/sdk/client/__tests__/sdk.models.integration.test.js +0 -376
  192. package/lib/sdk/client/__tests__/sdk.runtimes.integration.test.d.ts +0 -1
  193. package/lib/sdk/client/__tests__/sdk.runtimes.integration.test.js +0 -276
  194. package/lib/sdk/client/__tests__/sdk.spacer.integration.test.d.ts +0 -1
  195. package/lib/sdk/client/__tests__/sdk.spacer.integration.test.js +0 -361
  196. package/lib/sdk/client/base.d.ts +0 -88
  197. package/lib/sdk/client/base.js +0 -112
  198. package/lib/sdk/client/index.d.ts +0 -192
  199. package/lib/sdk/client/index.js +0 -128
  200. package/lib/sdk/client/mixins/HealthMixin.d.ts +0 -100
  201. package/lib/sdk/client/mixins/HealthMixin.js +0 -133
  202. package/lib/sdk/client/mixins/IAMMixin.d.ts +0 -59
  203. package/lib/sdk/client/mixins/IAMMixin.js +0 -83
  204. package/lib/sdk/client/mixins/RuntimesMixin.d.ts +0 -134
  205. package/lib/sdk/client/mixins/RuntimesMixin.js +0 -221
  206. package/lib/sdk/client/mixins/SpacerMixin.d.ts +0 -184
  207. package/lib/sdk/client/mixins/SpacerMixin.js +0 -278
  208. package/lib/sdk/client/models/Lexical.d.ts +0 -156
  209. package/lib/sdk/client/models/Lexical.js +0 -275
  210. package/lib/sdk/client/models/Notebook.d.ts +0 -174
  211. package/lib/sdk/client/models/Notebook.js +0 -311
  212. package/lib/sdk/client/models/Runtime.d.ts +0 -221
  213. package/lib/sdk/client/models/Runtime.js +0 -341
  214. package/lib/sdk/client/models/Snapshot.d.ts +0 -156
  215. package/lib/sdk/client/models/Snapshot.js +0 -244
  216. package/lib/sdk/client/models/Space.d.ts +0 -182
  217. package/lib/sdk/client/models/Space.js +0 -276
  218. package/lib/sdk/client/models/__tests__/Lexical.test.d.ts +0 -1
  219. package/lib/sdk/client/models/__tests__/Lexical.test.js +0 -288
  220. package/lib/sdk/client/models/__tests__/Notebook.test.d.ts +0 -1
  221. package/lib/sdk/client/models/__tests__/Notebook.test.js +0 -206
  222. package/lib/sdk/client/models/__tests__/Runtime.test.d.ts +0 -1
  223. package/lib/sdk/client/models/__tests__/Runtime.test.js +0 -133
  224. package/lib/sdk/client/models/__tests__/Snapshot.test.d.ts +0 -1
  225. package/lib/sdk/client/models/__tests__/Snapshot.test.js +0 -244
  226. package/lib/sdk/client/models/__tests__/Space.test.d.ts +0 -1
  227. package/lib/sdk/client/models/__tests__/Space.test.js +0 -334
  228. package/lib/sdk/client/models/index.d.ts +0 -30
  229. package/lib/sdk/client/models/index.js +0 -30
  230. package/lib/sdk/client/utils/mixins.d.ts +0 -42
  231. /package/lib/{api/types/iam.js → models/Common.js} +0 -0
  232. /package/lib/{api/types/runtimes.js → models/IAM.js} +0 -0
  233. /package/lib/{sdk/stateful → stateful}/jupyter/exec/Python.d.ts +0 -0
  234. /package/lib/{sdk/stateful → stateful}/jupyter/exec/Python.js +0 -0
  235. /package/lib/{sdk/stateful → stateful}/jupyter/exec/index.d.ts +0 -0
  236. /package/lib/{sdk/stateful → stateful}/jupyter/exec/index.js +0 -0
  237. /package/lib/{sdk/stateful → stateful}/jupyter/index.d.ts +0 -0
  238. /package/lib/{sdk/stateful → stateful}/jupyter/index.js +0 -0
  239. /package/lib/{sdk/stateful → stateful}/jupyter/kernelsHandler.d.ts +0 -0
  240. /package/lib/{sdk/stateful → stateful}/jupyter/kernelsHandler.js +0 -0
  241. /package/lib/{sdk/stateful → stateful}/runtimes/apis.js +0 -0
  242. /package/lib/{sdk/stateful → stateful}/runtimes/index.d.ts +0 -0
  243. /package/lib/{sdk/stateful → stateful}/runtimes/index.js +0 -0
  244. /package/lib/{sdk/stateful → stateful}/runtimes/settings.d.ts +0 -0
  245. /package/lib/{sdk/stateful → stateful}/runtimes/settings.js +0 -0
  246. /package/lib/{sdk/stateful → stateful}/runtimes/snapshots.d.ts +0 -0
  247. /package/lib/{sdk/stateful → stateful}/runtimes/snapshots.js +0 -0
  248. /package/lib/{sdk/stateful → stateful}/runtimes/utils.d.ts +0 -0
  249. /package/lib/{sdk/stateful → stateful}/runtimes/utils.js +0 -0
@@ -0,0 +1,309 @@
1
+ /*
2
+ * Copyright (c) 2023-2025 Datalayer, Inc.
3
+ * Distributed under the terms of the Modified BSD License.
4
+ */
5
+ /**
6
+ * OAuth2 API functions for the Datalayer platform.
7
+ *
8
+ * Provides functions for OAuth2 authorization flows with various providers.
9
+ *
10
+ * @module api/iam/oauth2
11
+ */
12
+ import { requestDatalayerAPI } from '../DatalayerApi';
13
+ import { API_BASE_PATHS, DEFAULT_SERVICE_URLS } from '../constants';
14
+ /**
15
+ * Get the OAuth2 authorization URL for a specific provider
16
+ * @param provider - OAuth2 provider (bluesky, github, linkedin, okta)
17
+ * @param callbackUri - Server endpoint to call with the authz token
18
+ * @param nonce - Optional nonce for security
19
+ * @param baseUrl - Base URL for the API (defaults to production IAM URL)
20
+ * @returns OAuth2 authorization URL response
21
+ * @throws {Error} If required parameters are missing or invalid
22
+ *
23
+ * @remarks
24
+ * This endpoint generates the OAuth2 authorization URL for the specified provider.
25
+ * Users should be redirected to the returned loginURL to begin the OAuth2 flow.
26
+ *
27
+ * Expected status codes:
28
+ * - 200: Successfully generated authorization URL
29
+ * - 400: Invalid parameters
30
+ * - 404: Provider not found or not configured
31
+ */
32
+ export const getOAuth2AuthzUrl = async (provider, callbackUri, nonce, baseUrl = DEFAULT_SERVICE_URLS.IAM) => {
33
+ if (!provider) {
34
+ throw new Error('OAuth2 provider is required');
35
+ }
36
+ if (!callbackUri) {
37
+ throw new Error('Callback URI is required');
38
+ }
39
+ // Build query parameters
40
+ const queryParams = new URLSearchParams({
41
+ provider,
42
+ callback_uri: callbackUri,
43
+ });
44
+ if (nonce) {
45
+ queryParams.append('nonce', nonce);
46
+ }
47
+ try {
48
+ const response = await requestDatalayerAPI({
49
+ url: `${baseUrl}${API_BASE_PATHS.IAM}/oauth2/authz/url?${queryParams.toString()}`,
50
+ method: 'GET',
51
+ });
52
+ return response;
53
+ }
54
+ catch (error) {
55
+ // Check if it's a response error with status code information
56
+ if (error.response) {
57
+ const status = error.response.status;
58
+ // Expected errors
59
+ if (status === 400) {
60
+ throw new Error(`Invalid OAuth2 parameters: ${error.message}`);
61
+ }
62
+ if (status === 404) {
63
+ throw new Error(`OAuth2 provider '${provider}' not found or not configured`);
64
+ }
65
+ // Unexpected status codes
66
+ throw new Error(`Failed to get OAuth2 authorization URL: ${status} - ${error.message}`);
67
+ }
68
+ // Re-throw other errors (network errors, etc.)
69
+ throw error;
70
+ }
71
+ };
72
+ /**
73
+ * Get the OAuth2 authorization URL for linking a provider to an existing account
74
+ * @param provider - OAuth2 provider (bluesky, github, linkedin, okta)
75
+ * @param callbackUri - Server endpoint to call with the authz token
76
+ * @param baseUrl - Base URL for the API (defaults to production IAM URL)
77
+ * @returns OAuth2 authorization URL response
78
+ * @throws {Error} If required parameters are missing or invalid
79
+ *
80
+ * @remarks
81
+ * This endpoint generates the OAuth2 authorization URL for linking a provider to an existing account.
82
+ * Users should be redirected to the returned loginURL to begin the OAuth2 linking flow.
83
+ * This is different from the regular OAuth2 login flow as it links the provider to an existing account.
84
+ *
85
+ * Expected status codes:
86
+ * - 200: Successfully generated authorization URL
87
+ * - 400: Invalid parameters
88
+ * - 404: Provider not found or not configured
89
+ */
90
+ export const getOAuth2AuthzUrlForLink = async (provider, callbackUri, baseUrl = DEFAULT_SERVICE_URLS.IAM) => {
91
+ if (!provider) {
92
+ throw new Error('OAuth2 provider is required');
93
+ }
94
+ if (!callbackUri) {
95
+ throw new Error('Callback URI is required');
96
+ }
97
+ // Build query parameters
98
+ const queryParams = new URLSearchParams({
99
+ provider,
100
+ callback_uri: callbackUri,
101
+ });
102
+ try {
103
+ const response = await requestDatalayerAPI({
104
+ url: `${baseUrl}${API_BASE_PATHS.IAM}/oauth2/authz/url/link?${queryParams.toString()}`,
105
+ method: 'GET',
106
+ });
107
+ return response;
108
+ }
109
+ catch (error) {
110
+ // Check if it's a response error with status code information
111
+ if (error.response) {
112
+ const status = error.response.status;
113
+ // Expected errors
114
+ if (status === 400) {
115
+ throw new Error(`Invalid OAuth2 link parameters: ${error.message}`);
116
+ }
117
+ if (status === 404) {
118
+ throw new Error(`OAuth2 provider '${provider}' not found or not configured for linking`);
119
+ }
120
+ // Unexpected status codes
121
+ throw new Error(`Failed to get OAuth2 link authorization URL: ${status} - ${error.message}`);
122
+ }
123
+ // Re-throw other errors (network errors, etc.)
124
+ throw error;
125
+ }
126
+ };
127
+ /**
128
+ * Handle GitHub OAuth2 callback
129
+ * @param params - OAuth2 callback parameters
130
+ * @param baseUrl - Base URL for the API (defaults to production IAM URL)
131
+ * @returns HTML response from the callback handler
132
+ * @throws {Error} If state parameter is missing
133
+ * @throws {Error} If the callback fails
134
+ *
135
+ * @remarks
136
+ * This endpoint handles the callback from GitHub after the user authorizes the application.
137
+ * It returns HTML content that typically includes JavaScript to handle the OAuth flow completion.
138
+ *
139
+ * Expected status codes:
140
+ * - 200: Callback processed successfully (returns HTML)
141
+ * - 403: Unauthorized
142
+ */
143
+ export const handleGitHubOAuth2Callback = async (params, baseUrl = DEFAULT_SERVICE_URLS.IAM) => {
144
+ if (!params.state) {
145
+ throw new Error('State parameter is required for OAuth2 callback');
146
+ }
147
+ // Build query parameters
148
+ const queryParams = new URLSearchParams();
149
+ queryParams.append('state', params.state);
150
+ if (params.code) {
151
+ queryParams.append('code', params.code);
152
+ }
153
+ if (params.error) {
154
+ queryParams.append('error', params.error);
155
+ }
156
+ if (params.error_description) {
157
+ queryParams.append('error_description', params.error_description);
158
+ }
159
+ if (params.error_uri) {
160
+ queryParams.append('error_uri', params.error_uri);
161
+ }
162
+ try {
163
+ const response = await requestDatalayerAPI({
164
+ url: `${baseUrl}${API_BASE_PATHS.IAM}/oauth2/github/callback?${queryParams.toString()}`,
165
+ method: 'GET',
166
+ // Note: This endpoint returns HTML, not JSON
167
+ headers: {
168
+ Accept: 'text/html',
169
+ },
170
+ });
171
+ return response;
172
+ }
173
+ catch (error) {
174
+ // Check if it's a response error with status code information
175
+ if (error.response) {
176
+ const status = error.response.status;
177
+ // Expected errors
178
+ if (status === 403) {
179
+ throw new Error(`GitHub OAuth2 callback unauthorized: ${error.message}`);
180
+ }
181
+ // Unexpected status codes
182
+ throw new Error(`GitHub OAuth2 callback failed: ${status} - ${error.message}`);
183
+ }
184
+ // Re-throw other errors (network errors, etc.)
185
+ throw error;
186
+ }
187
+ };
188
+ /**
189
+ * Handle LinkedIn OAuth2 callback
190
+ * @param params - OAuth2 callback parameters
191
+ * @param baseUrl - Base URL for the API (defaults to production IAM URL)
192
+ * @returns HTML response from the callback handler
193
+ * @throws {Error} If state parameter is missing
194
+ * @throws {Error} If the callback fails
195
+ *
196
+ * @remarks
197
+ * This endpoint handles the callback from LinkedIn after the user authorizes the application.
198
+ * It returns HTML content that typically includes JavaScript to handle the OAuth flow completion.
199
+ *
200
+ * Expected status codes:
201
+ * - 200: Callback processed successfully (returns HTML)
202
+ * - 403: Unauthorized
203
+ */
204
+ export const handleLinkedInOAuth2Callback = async (params, baseUrl = DEFAULT_SERVICE_URLS.IAM) => {
205
+ if (!params.state) {
206
+ throw new Error('State parameter is required for OAuth2 callback');
207
+ }
208
+ // Build query parameters
209
+ const queryParams = new URLSearchParams();
210
+ queryParams.append('state', params.state);
211
+ if (params.code) {
212
+ queryParams.append('code', params.code);
213
+ }
214
+ if (params.error) {
215
+ queryParams.append('error', params.error);
216
+ }
217
+ if (params.error_description) {
218
+ queryParams.append('error_description', params.error_description);
219
+ }
220
+ if (params.error_uri) {
221
+ queryParams.append('error_uri', params.error_uri);
222
+ }
223
+ try {
224
+ const response = await requestDatalayerAPI({
225
+ url: `${baseUrl}${API_BASE_PATHS.IAM}/oauth2/linkedin/callback?${queryParams.toString()}`,
226
+ method: 'GET',
227
+ // Note: This endpoint returns HTML, not JSON
228
+ headers: {
229
+ Accept: 'text/html',
230
+ },
231
+ });
232
+ return response;
233
+ }
234
+ catch (error) {
235
+ // Check if it's a response error with status code information
236
+ if (error.response) {
237
+ const status = error.response.status;
238
+ // Expected errors
239
+ if (status === 403) {
240
+ throw new Error(`LinkedIn OAuth2 callback unauthorized: ${error.message}`);
241
+ }
242
+ // Unexpected status codes
243
+ throw new Error(`LinkedIn OAuth2 callback failed: ${status} - ${error.message}`);
244
+ }
245
+ // Re-throw other errors (network errors, etc.)
246
+ throw error;
247
+ }
248
+ };
249
+ /**
250
+ * Handle Okta OAuth2 callback
251
+ * @param params - OAuth2 callback parameters
252
+ * @param baseUrl - Base URL for the API (defaults to production IAM URL)
253
+ * @returns HTML response from the callback handler
254
+ * @throws {Error} If state parameter is missing
255
+ * @throws {Error} If the callback fails
256
+ *
257
+ * @remarks
258
+ * This endpoint handles the callback from Okta after the user authorizes the application.
259
+ * It returns HTML content that typically includes JavaScript to handle the OAuth flow completion.
260
+ *
261
+ * Expected status codes:
262
+ * - 200: Callback processed successfully (returns HTML)
263
+ * - 403: Unauthorized
264
+ */
265
+ export const handleOktaOAuth2Callback = async (params, baseUrl = DEFAULT_SERVICE_URLS.IAM) => {
266
+ if (!params.state) {
267
+ throw new Error('State parameter is required for OAuth2 callback');
268
+ }
269
+ // Build query parameters
270
+ const queryParams = new URLSearchParams();
271
+ queryParams.append('state', params.state);
272
+ if (params.code) {
273
+ queryParams.append('code', params.code);
274
+ }
275
+ if (params.error) {
276
+ queryParams.append('error', params.error);
277
+ }
278
+ if (params.error_description) {
279
+ queryParams.append('error_description', params.error_description);
280
+ }
281
+ if (params.error_uri) {
282
+ queryParams.append('error_uri', params.error_uri);
283
+ }
284
+ try {
285
+ const response = await requestDatalayerAPI({
286
+ url: `${baseUrl}${API_BASE_PATHS.IAM}/oauth2/okta/callback?${queryParams.toString()}`,
287
+ method: 'GET',
288
+ // Note: This endpoint returns HTML, not JSON
289
+ headers: {
290
+ Accept: 'text/html',
291
+ },
292
+ });
293
+ return response;
294
+ }
295
+ catch (error) {
296
+ // Check if it's a response error with status code information
297
+ if (error.response) {
298
+ const status = error.response.status;
299
+ // Expected errors
300
+ if (status === 403) {
301
+ throw new Error(`Okta OAuth2 callback unauthorized: ${error.message}`);
302
+ }
303
+ // Unexpected status codes
304
+ throw new Error(`Okta OAuth2 callback failed: ${status} - ${error.message}`);
305
+ }
306
+ // Re-throw other errors (network errors, etc.)
307
+ throw error;
308
+ }
309
+ };
@@ -1,4 +1,4 @@
1
- import { UserMeResponse, WhoAmIResponse } from '../types/iam';
1
+ import { MembershipsResponse, UserMeResponse, WhoAmIResponse } from '../../models/IAM';
2
2
  /**
3
3
  * Get current authenticated user profile
4
4
  * @param token - Authentication token (required)
@@ -13,3 +13,10 @@ export declare const me: (token: string, baseUrl?: string) => Promise<UserMeResp
13
13
  * @returns Current user identity and profile information
14
14
  */
15
15
  export declare const whoami: (token: string, baseUrl?: string) => Promise<WhoAmIResponse>;
16
+ /**
17
+ * Get current user identity information
18
+ * @param token - Authentication token (required)
19
+ * @param baseUrl - Base URL for the API (defaults to production IAM URL)
20
+ * @returns Current user identity and profile information
21
+ */
22
+ export declare const memberships: (token: string, baseUrl?: string) => Promise<MembershipsResponse>;
@@ -3,10 +3,11 @@
3
3
  * Distributed under the terms of the Modified BSD License.
4
4
  */
5
5
  /**
6
- * @module api/iam/profile
7
- * @description User profile management API functions for the Datalayer platform.
6
+ * User profile management API functions for the Datalayer platform.
8
7
  *
9
8
  * Provides functions for retrieving and managing user profile information.
9
+ *
10
+ * @module api/iam/profile
10
11
  */
11
12
  import { requestDatalayerAPI } from '../DatalayerApi';
12
13
  import { API_BASE_PATHS, DEFAULT_SERVICE_URLS } from '../constants';
@@ -39,3 +40,17 @@ export const whoami = async (token, baseUrl = DEFAULT_SERVICE_URLS.IAM) => {
39
40
  token,
40
41
  });
41
42
  };
43
+ /**
44
+ * Get current user identity information
45
+ * @param token - Authentication token (required)
46
+ * @param baseUrl - Base URL for the API (defaults to production IAM URL)
47
+ * @returns Current user identity and profile information
48
+ */
49
+ export const memberships = async (token, baseUrl = DEFAULT_SERVICE_URLS.IAM) => {
50
+ validateToken(token);
51
+ return requestDatalayerAPI({
52
+ url: `${baseUrl}${API_BASE_PATHS.IAM}/memberships`,
53
+ method: 'GET',
54
+ token,
55
+ });
56
+ };
@@ -0,0 +1,18 @@
1
+ import { CreditsResponse } from '../../models/CreditsDTO';
2
+ /**
3
+ * Get the current user's available credits and usage information.
4
+ *
5
+ * @param token - Authentication token
6
+ * @param iamUrl - Optional IAM service URL (defaults to production)
7
+ * @returns Promise with credits information
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * import { getCredits } from '@datalayer/core/api/iam';
12
+ *
13
+ * const creditsInfo = await getCredits(token);
14
+ * console.log(`Available credits: ${creditsInfo.credits.credits}`);
15
+ * console.log(`Quota: ${creditsInfo.credits.quota || 'unlimited'}`);
16
+ * ```
17
+ */
18
+ export declare function getCredits(token: string, iamUrl?: string): Promise<CreditsResponse>;
@@ -0,0 +1,39 @@
1
+ /*
2
+ * Copyright (c) 2023-2025 Datalayer, Inc.
3
+ * Distributed under the terms of the Modified BSD License.
4
+ */
5
+ /**
6
+ * Credits and usage API for managing user credits.
7
+ *
8
+ * Provides functionality to retrieve user's available credits, quota, and reservations.
9
+ *
10
+ * @module api/iam/credits
11
+ */
12
+ import { requestDatalayerAPI } from '../DatalayerApi';
13
+ import { API_BASE_PATHS, DEFAULT_SERVICE_URLS } from '../constants';
14
+ /**
15
+ * Get the current user's available credits and usage information.
16
+ *
17
+ * @param token - Authentication token
18
+ * @param iamUrl - Optional IAM service URL (defaults to production)
19
+ * @returns Promise with credits information
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * import { getCredits } from '@datalayer/core/api/iam';
24
+ *
25
+ * const creditsInfo = await getCredits(token);
26
+ * console.log(`Available credits: ${creditsInfo.credits.credits}`);
27
+ * console.log(`Quota: ${creditsInfo.credits.quota || 'unlimited'}`);
28
+ * ```
29
+ */
30
+ export async function getCredits(token, iamUrl = DEFAULT_SERVICE_URLS.IAM) {
31
+ return requestDatalayerAPI({
32
+ url: `${iamUrl}${API_BASE_PATHS.IAM}usage/credits`,
33
+ method: 'GET',
34
+ headers: {
35
+ Authorization: `Bearer ${token}`,
36
+ 'Content-Type': 'application/json',
37
+ },
38
+ });
39
+ }
@@ -1,20 +1,20 @@
1
1
  /**
2
- * @module @datalayer/core/api
3
- * @description Minimal API layer for the Datalayer platform providing base HTTP client and functional API methods.
2
+ * Minimal API layer for the Datalayer platform providing base HTTP client and functional API methods.
4
3
  *
5
4
  * This module contains the low-level API functionality. For high-level object-oriented
6
5
  * SDK classes, use @datalayer/core/sdk instead.
6
+ *
7
+ * @module @datalayer/core/api
7
8
  */
8
9
  export { requestDatalayerAPI, RunResponseError, NetworkError, } from './DatalayerApi';
9
10
  export type { IRequestDatalayerAPIOptions } from './DatalayerApi';
10
- export * from './types';
11
11
  export * as iam from './iam';
12
12
  export * as runtimes from './runtimes';
13
13
  export * as spacer from './spacer';
14
14
  /**
15
- * @deprecated Please import directly from '@datalayer/core/sdk/stateful' instead.
15
+ * @deprecated Please import directly from '@datalayer/core/stateful' instead.
16
16
  * This module provides backward compatibility for the moved apiv1 modules.
17
17
  */
18
- export * from '../sdk/stateful/jupyter';
19
- export * from '../sdk/stateful/runtimes';
18
+ export * from '../stateful/jupyter';
19
+ export * from '../stateful/runtimes';
20
20
  export * from '../api/DatalayerApi';
package/lib/api/index.js CHANGED
@@ -3,24 +3,23 @@
3
3
  * Distributed under the terms of the Modified BSD License.
4
4
  */
5
5
  /**
6
- * @module @datalayer/core/api
7
- * @description Minimal API layer for the Datalayer platform providing base HTTP client and functional API methods.
6
+ * Minimal API layer for the Datalayer platform providing base HTTP client and functional API methods.
8
7
  *
9
8
  * This module contains the low-level API functionality. For high-level object-oriented
10
9
  * SDK classes, use @datalayer/core/sdk instead.
10
+ *
11
+ * @module @datalayer/core/api
11
12
  */
12
13
  // Base client exports
13
14
  export { requestDatalayerAPI, RunResponseError, NetworkError, } from './DatalayerApi';
14
- // Type exports
15
- export * from './types';
16
15
  // Domain-organized API exports
17
16
  export * as iam from './iam';
18
17
  export * as runtimes from './runtimes';
19
18
  export * as spacer from './spacer';
20
19
  /**
21
- * @deprecated Please import directly from '@datalayer/core/sdk/stateful' instead.
20
+ * @deprecated Please import directly from '@datalayer/core/stateful' instead.
22
21
  * This module provides backward compatibility for the moved apiv1 modules.
23
22
  */
24
- export * from '../sdk/stateful/jupyter';
25
- export * from '../sdk/stateful/runtimes';
23
+ export * from '../stateful/jupyter';
24
+ export * from '../stateful/runtimes';
26
25
  export * from '../api/DatalayerApi';
@@ -1,4 +1,4 @@
1
- import { EnvironmentsListResponse } from '../types/runtimes';
1
+ import { ListEnvironmentsResponse } from '../../models/EnvironmentDTO';
2
2
  /**
3
3
  * List all available computing environments.
4
4
  * @param token - Authentication token
@@ -6,4 +6,4 @@ import { EnvironmentsListResponse } from '../types/runtimes';
6
6
  * @returns Promise resolving to list of available environments
7
7
  * @throws {Error} If authentication token is missing or invalid
8
8
  */
9
- export declare const listEnvironments: (token: string, baseUrl?: string) => Promise<EnvironmentsListResponse>;
9
+ export declare const listEnvironments: (token: string, baseUrl?: string) => Promise<ListEnvironmentsResponse>;
@@ -3,10 +3,11 @@
3
3
  * Distributed under the terms of the Modified BSD License.
4
4
  */
5
5
  /**
6
- * @module api/runtimes/environments
7
- * @description Computing environments API functions for the Datalayer platform.
6
+ * Computing environments API functions for the Datalayer platform.
8
7
  *
9
8
  * Provides functions for managing computing environment configurations.
9
+ *
10
+ * @module api/runtimes/environments
10
11
  */
11
12
  import { requestDatalayerAPI } from '../DatalayerApi';
12
13
  import { API_BASE_PATHS, DEFAULT_SERVICE_URLS } from '../constants';
@@ -1,25 +1,15 @@
1
- /**
2
- * Health check response from the Runtimes service
3
- */
4
- export interface RuntimesHealthzPingResponse {
5
- success: boolean;
6
- message: string;
7
- status?: {
8
- status: string;
9
- };
10
- version?: string;
11
- }
1
+ import type { HealthzPingResponse } from '../../models/Common';
12
2
  /**
13
3
  * Health check ping endpoint for Runtimes service
14
4
  * @param baseUrl - Base URL for the API (defaults to production Runtimes URL)
15
5
  * @returns Health check response
16
6
  * @throws {Error} If the health check fails
17
7
  *
18
- * @description
8
+ * @remarks
19
9
  * This endpoint provides a basic health check for the Runtimes service.
20
10
  * It returns the current status of the service.
21
11
  *
22
12
  * Expected status codes:
23
13
  * - 200: Service is healthy
24
14
  */
25
- export declare const ping: (baseUrl?: string) => Promise<RuntimesHealthzPingResponse>;
15
+ export declare const ping: (baseUrl?: string) => Promise<HealthzPingResponse>;
@@ -3,10 +3,11 @@
3
3
  * Distributed under the terms of the Modified BSD License.
4
4
  */
5
5
  /**
6
- * @module api/runtimes/healthz
7
- * @description Health check API functions for the Datalayer Runtimes service.
6
+ * Health check API functions for the Datalayer Runtimes service.
8
7
  *
9
8
  * Provides functions for checking the health status of the Runtimes service.
9
+ *
10
+ * @module api/runtimes/healthz
10
11
  */
11
12
  import { requestDatalayerAPI } from '../DatalayerApi';
12
13
  import { API_BASE_PATHS, DEFAULT_SERVICE_URLS } from '../constants';
@@ -16,7 +17,7 @@ import { API_BASE_PATHS, DEFAULT_SERVICE_URLS } from '../constants';
16
17
  * @returns Health check response
17
18
  * @throws {Error} If the health check fails
18
19
  *
19
- * @description
20
+ * @remarks
20
21
  * This endpoint provides a basic health check for the Runtimes service.
21
22
  * It returns the current status of the service.
22
23
  *
@@ -1,8 +1,9 @@
1
1
  /**
2
- * @module api/runtimes
3
- * @description Runtimes API exports.
2
+ * Runtimes API exports.
4
3
  *
5
4
  * Provides organized access to runtime management functionality.
5
+ *
6
+ * @module api/runtimes
6
7
  */
7
8
  export * as environments from './environments';
8
9
  export * as healthz from './healthz';
@@ -3,10 +3,11 @@
3
3
  * Distributed under the terms of the Modified BSD License.
4
4
  */
5
5
  /**
6
- * @module api/runtimes
7
- * @description Runtimes API exports.
6
+ * Runtimes API exports.
8
7
  *
9
8
  * Provides organized access to runtime management functionality.
9
+ *
10
+ * @module api/runtimes
10
11
  */
11
12
  export * as environments from './environments';
12
13
  export * as healthz from './healthz';
@@ -1,4 +1,4 @@
1
- import { Runtime, CreateRuntimeRequest, CreateRuntimeResponse, RuntimesListResponse } from '../types/runtimes';
1
+ import { RuntimeData, CreateRuntimeRequest, CreateRuntimeResponse, ListRuntimesResponse } from '../../models/RuntimeDTO';
2
2
  /**
3
3
  * Create a new runtime instance.
4
4
  * @param token - Authentication token
@@ -17,7 +17,7 @@ export declare const createRuntime: (token: string, data: CreateRuntimeRequest,
17
17
  * @returns Promise resolving to list of runtime instances
18
18
  * @throws {Error} If authentication token is missing or invalid
19
19
  */
20
- export declare const listRuntimes: (token: string, baseUrl?: string) => Promise<RuntimesListResponse>;
20
+ export declare const listRuntimes: (token: string, baseUrl?: string) => Promise<ListRuntimesResponse>;
21
21
  /**
22
22
  * Get details for a specific runtime instance.
23
23
  * @param token - Authentication token
@@ -28,7 +28,7 @@ export declare const listRuntimes: (token: string, baseUrl?: string) => Promise<
28
28
  * @throws {Error} If pod name is missing or invalid
29
29
  * @throws {Error} With status 404 if the runtime is not found
30
30
  */
31
- export declare const getRuntime: (token: string, podName: string, baseUrl?: string) => Promise<Runtime>;
31
+ export declare const getRuntime: (token: string, podName: string, baseUrl?: string) => Promise<RuntimeData>;
32
32
  /**
33
33
  * Delete a runtime instance.
34
34
  * @param token - Authentication token
@@ -51,4 +51,4 @@ export declare const deleteRuntime: (token: string, podName: string, baseUrl?: s
51
51
  * @throws {Error} If pod name is missing or invalid
52
52
  * @throws {Error} With status 404 if the runtime is not found
53
53
  */
54
- export declare const updateRuntime: (token: string, podName: string, from: string, baseUrl?: string) => Promise<Runtime>;
54
+ export declare const updateRuntime: (token: string, podName: string, from: string, baseUrl?: string) => Promise<RuntimeData>;
@@ -3,10 +3,11 @@
3
3
  * Distributed under the terms of the Modified BSD License.
4
4
  */
5
5
  /**
6
- * @module api/runtimes/runtimes
7
- * @description Runtime instances API functions for the Datalayer platform.
6
+ * Runtime instances API functions for the Datalayer platform.
8
7
  *
9
8
  * Provides functions for managing runtime instances (active compute containers).
9
+ *
10
+ * @module api/runtimes/runtimes
10
11
  */
11
12
  import { requestDatalayerAPI } from '../DatalayerApi';
12
13
  import { API_BASE_PATHS, DEFAULT_SERVICE_URLS } from '../constants';
@@ -58,11 +59,14 @@ export const createRuntime = async (token, data, baseUrl = DEFAULT_SERVICE_URLS.
58
59
  */
59
60
  export const listRuntimes = async (token, baseUrl = DEFAULT_SERVICE_URLS.RUNTIMES) => {
60
61
  validateToken(token);
61
- return requestDatalayerAPI({
62
+ const response = await requestDatalayerAPI({
62
63
  url: `${baseUrl}${API_BASE_PATHS.RUNTIMES}/runtimes`,
63
64
  method: 'GET',
64
65
  token,
65
66
  });
67
+ // The API returns { success: true, message: string, runtimes: Runtime[] }
68
+ // The response already has the correct structure, just return it
69
+ return response;
66
70
  };
67
71
  /**
68
72
  * Get details for a specific runtime instance.
@@ -83,10 +87,17 @@ export const getRuntime = async (token, podName, baseUrl = DEFAULT_SERVICE_URLS.
83
87
  method: 'GET',
84
88
  token,
85
89
  });
86
- // The API returns { success: true, message: string, kernel: Runtime }
87
- // We need to return just the runtime data
90
+ // The API returns { success: true, message: string, runtime: Runtime }
91
+ // (Previously used 'kernel' field, now uses 'runtime')
92
+ // Try 'runtime' field first (current API)
93
+ if (response.runtime) {
94
+ return {
95
+ ...response.runtime,
96
+ pod_name: response.runtime.pod_name || podName,
97
+ };
98
+ }
99
+ // Fallback to 'kernel' field (old API)
88
100
  if (response.kernel) {
89
- // Map kernel fields to Runtime fields
90
101
  return {
91
102
  ...response.kernel,
92
103
  pod_name: response.kernel.pod_name || podName,