@datalayer/core 0.0.12 → 0.0.13

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 (237) hide show
  1. package/README.md +2 -2
  2. package/lib/api/DatalayerApi.d.ts +38 -26
  3. package/lib/api/DatalayerApi.js +35 -8
  4. package/lib/api/iam/authentication.d.ts +8 -7
  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 +56 -0
  15. package/lib/api/iam/usage.js +39 -0
  16. package/lib/api/index.d.ts +6 -5
  17. package/lib/api/index.js +6 -5
  18. package/lib/api/runtimes/environments.js +3 -2
  19. package/lib/api/runtimes/healthz.d.ts +3 -13
  20. package/lib/api/runtimes/healthz.js +4 -3
  21. package/lib/api/runtimes/index.d.ts +3 -2
  22. package/lib/api/runtimes/index.js +3 -2
  23. package/lib/api/runtimes/runtimes.js +17 -6
  24. package/lib/api/runtimes/snapshots.js +3 -2
  25. package/lib/api/spacer/documents.d.ts +12 -0
  26. package/lib/api/spacer/documents.js +43 -0
  27. package/lib/api/spacer/healthz.d.ts +3 -13
  28. package/lib/api/spacer/healthz.js +4 -3
  29. package/lib/api/spacer/index.d.ts +4 -2
  30. package/lib/api/spacer/index.js +4 -2
  31. package/lib/api/spacer/items.d.ts +9 -1
  32. package/lib/api/spacer/items.js +17 -2
  33. package/lib/api/spacer/lexicals.js +3 -2
  34. package/lib/api/spacer/notebooks.js +3 -2
  35. package/lib/api/spacer/spaces.js +3 -2
  36. package/lib/api/spacer/users.js +3 -2
  37. package/lib/api/types/common.d.ts +64 -0
  38. package/lib/api/types/iam.d.ts +88 -65
  39. package/lib/api/types/index.d.ts +4 -2
  40. package/lib/api/types/index.js +4 -2
  41. package/lib/api/types/runtimes.d.ts +9 -39
  42. package/lib/api/types/spacer.d.ts +37 -65
  43. package/lib/api/utils/validation.d.ts +24 -1
  44. package/lib/api/utils/validation.js +62 -1
  45. package/lib/client/base.d.ts +75 -0
  46. package/lib/client/base.js +199 -0
  47. package/lib/client/constants.d.ts +22 -0
  48. package/lib/client/constants.js +22 -0
  49. package/lib/client/index.d.ts +108 -0
  50. package/lib/client/index.js +79 -0
  51. package/lib/client/mixins/IAMMixin.d.ts +54 -0
  52. package/lib/client/mixins/IAMMixin.js +181 -0
  53. package/lib/client/mixins/RuntimesMixin.d.ts +93 -0
  54. package/lib/client/mixins/RuntimesMixin.js +229 -0
  55. package/lib/client/mixins/SpacerMixin.d.ts +111 -0
  56. package/lib/client/mixins/SpacerMixin.js +340 -0
  57. package/lib/client/models/Credits.d.ts +91 -0
  58. package/lib/client/models/Credits.js +130 -0
  59. package/lib/client/models/Environment.d.ts +73 -0
  60. package/lib/client/models/Environment.js +88 -0
  61. package/lib/client/models/HealthCheck.d.ts +72 -0
  62. package/lib/client/models/HealthCheck.js +107 -0
  63. package/lib/client/models/Item.d.ts +69 -0
  64. package/lib/client/models/Item.js +191 -0
  65. package/lib/client/models/Lexical.d.ts +83 -0
  66. package/lib/client/models/Lexical.js +152 -0
  67. package/lib/client/models/Notebook.d.ts +87 -0
  68. package/lib/client/models/Notebook.js +153 -0
  69. package/lib/client/models/Runtime.d.ts +122 -0
  70. package/lib/client/models/Runtime.js +204 -0
  71. package/lib/client/models/Snapshot.d.ts +92 -0
  72. package/lib/client/models/Snapshot.js +139 -0
  73. package/lib/client/models/Space.d.ts +135 -0
  74. package/lib/client/models/Space.js +234 -0
  75. package/lib/client/models/User.d.ts +64 -0
  76. package/lib/client/models/User.js +83 -0
  77. package/lib/client/models/index.d.ts +26 -0
  78. package/lib/client/models/index.js +25 -0
  79. package/lib/client/utils/mixins.d.ts +12 -0
  80. package/lib/{sdk/client → client}/utils/mixins.js +0 -28
  81. package/lib/client/utils/spacerUtils.d.ts +18 -0
  82. package/lib/client/utils/spacerUtils.js +32 -0
  83. package/lib/collaboration/DatalayerCollaboration.d.ts +6 -1
  84. package/lib/collaboration/DatalayerCollaboration.js +2 -2
  85. package/lib/collaboration/DatalayerCollaborationProvider.d.ts +5 -0
  86. package/lib/collaboration/DatalayerCollaborationProvider.js +10 -9
  87. package/lib/components/progress/CreditsIndicator.d.ts +1 -1
  88. package/lib/components/runtimes/RuntimeCellVariablesDialog.js +1 -1
  89. package/lib/components/runtimes/RuntimeLauncherDialog.d.ts +1 -1
  90. package/lib/components/runtimes/RuntimePickerBase.d.ts +1 -1
  91. package/lib/components/runtimes/RuntimePickerBase.js +1 -1
  92. package/lib/components/runtimes/RuntimePickerCell.js +2 -2
  93. package/lib/components/runtimes/RuntimePickerNotebook.d.ts +1 -1
  94. package/lib/components/runtimes/RuntimePickerNotebook.js +1 -1
  95. package/lib/components/runtimes/RuntimeTransfer.d.ts +1 -1
  96. package/lib/components/runtimes/RuntimeUtils.d.ts +1 -1
  97. package/lib/components/snapshots/RuntimeSnapshotMenu.d.ts +1 -1
  98. package/lib/components/snapshots/RuntimeSnapshotMenu.js +27 -20
  99. package/lib/config/Configuration.d.ts +8 -0
  100. package/lib/hooks/useDatalayer.js +1 -1
  101. package/lib/hooks/useRuntimes.js +1 -1
  102. package/lib/hooks/useToast.js +1 -1
  103. package/lib/index.d.ts +2 -2
  104. package/lib/index.js +4 -2
  105. package/lib/sdk/index.d.ts +5 -4
  106. package/lib/sdk/index.js +6 -5
  107. package/lib/services/DatalayerServiceManager.js +1 -1
  108. package/lib/state/substates/CoreState.js +2 -0
  109. package/lib/state/substates/RuntimesState.d.ts +1 -1
  110. package/lib/state/substates/RuntimesState.js +1 -1
  111. package/lib/{sdk/stateful → stateful}/index.d.ts +1 -1
  112. package/lib/{sdk/stateful → stateful}/index.js +1 -1
  113. package/lib/{sdk/stateful → stateful}/jupyter/exec/Snippets.d.ts +1 -41
  114. package/lib/{sdk/stateful → stateful}/jupyter/exec/Snippets.js +1 -20
  115. package/lib/{sdk/stateful → stateful}/runtimes/actions.d.ts +3 -3
  116. package/lib/{sdk/stateful → stateful}/runtimes/actions.js +8 -8
  117. package/lib/{sdk/stateful → stateful}/runtimes/apis.d.ts +8 -8
  118. package/lib/stateful/runtimes/apis.js +5 -0
  119. package/package.json +12 -10
  120. package/lib/__tests__/hooks.test.d.ts +0 -1
  121. package/lib/__tests__/hooks.test.js +0 -19
  122. package/lib/__tests__/index.test.d.ts +0 -1
  123. package/lib/__tests__/index.test.js +0 -27
  124. package/lib/__tests__/integration.test.d.ts +0 -1
  125. package/lib/__tests__/integration.test.js +0 -57
  126. package/lib/__tests__/shared/cleanup-shared.d.ts +0 -4
  127. package/lib/__tests__/shared/cleanup-shared.js +0 -228
  128. package/lib/__tests__/shared/test-config.d.ts +0 -51
  129. package/lib/__tests__/shared/test-config.js +0 -110
  130. package/lib/__tests__/shared/test-constants.d.ts +0 -66
  131. package/lib/__tests__/shared/test-constants.js +0 -79
  132. package/lib/__tests__/utils.test.d.ts +0 -1
  133. package/lib/__tests__/utils.test.js +0 -59
  134. package/lib/api/__tests__/iam.authentication.integration.test.d.ts +0 -1
  135. package/lib/api/__tests__/iam.authentication.integration.test.js +0 -247
  136. package/lib/api/__tests__/iam.healthz.integration.test.d.ts +0 -1
  137. package/lib/api/__tests__/iam.healthz.integration.test.js +0 -63
  138. package/lib/api/__tests__/iam.profile.integration.test.d.ts +0 -1
  139. package/lib/api/__tests__/iam.profile.integration.test.js +0 -252
  140. package/lib/api/__tests__/runtimes.environments.integration.test.d.ts +0 -1
  141. package/lib/api/__tests__/runtimes.environments.integration.test.js +0 -122
  142. package/lib/api/__tests__/runtimes.healthz.integration.test.d.ts +0 -1
  143. package/lib/api/__tests__/runtimes.healthz.integration.test.js +0 -50
  144. package/lib/api/__tests__/runtimes.integration.test.d.ts +0 -1
  145. package/lib/api/__tests__/runtimes.integration.test.js +0 -369
  146. package/lib/api/__tests__/spacer.healthz.integration.test.d.ts +0 -1
  147. package/lib/api/__tests__/spacer.healthz.integration.test.js +0 -50
  148. package/lib/api/__tests__/spacer.integration.test.d.ts +0 -1
  149. package/lib/api/__tests__/spacer.integration.test.js +0 -519
  150. package/lib/api/iam/__tests__/authentication.unit.test.d.ts +0 -1
  151. package/lib/api/iam/__tests__/authentication.unit.test.js +0 -63
  152. package/lib/api/iam/__tests__/healthz.unit.test.d.ts +0 -1
  153. package/lib/api/iam/__tests__/healthz.unit.test.js +0 -60
  154. package/lib/api/iam/__tests__/profile.unit.test.d.ts +0 -1
  155. package/lib/api/iam/__tests__/profile.unit.test.js +0 -57
  156. package/lib/api/runtimes/__tests__/environments.unit.test.d.ts +0 -1
  157. package/lib/api/runtimes/__tests__/environments.unit.test.js +0 -77
  158. package/lib/api/runtimes/__tests__/healthz.unit.test.d.ts +0 -1
  159. package/lib/api/runtimes/__tests__/healthz.unit.test.js +0 -57
  160. package/lib/api/runtimes/__tests__/runtimes.unit.test.d.ts +0 -1
  161. package/lib/api/runtimes/__tests__/runtimes.unit.test.js +0 -139
  162. package/lib/api/runtimes/__tests__/snapshots.unit.test.d.ts +0 -1
  163. package/lib/api/runtimes/__tests__/snapshots.unit.test.js +0 -96
  164. package/lib/api/spacer/__tests__/healthz.unit.test.d.ts +0 -1
  165. package/lib/api/spacer/__tests__/healthz.unit.test.js +0 -57
  166. package/lib/api/spacer/__tests__/items.unit.test.d.ts +0 -1
  167. package/lib/api/spacer/__tests__/items.unit.test.js +0 -165
  168. package/lib/api/spacer/__tests__/lexicals.unit.test.d.ts +0 -1
  169. package/lib/api/spacer/__tests__/lexicals.unit.test.js +0 -323
  170. package/lib/api/spacer/__tests__/notebooks.unit.test.d.ts +0 -1
  171. package/lib/api/spacer/__tests__/notebooks.unit.test.js +0 -224
  172. package/lib/api/spacer/__tests__/users.unit.test.d.ts +0 -1
  173. package/lib/api/spacer/__tests__/users.unit.test.js +0 -132
  174. package/lib/api/utils/__tests__/validation.test.d.ts +0 -1
  175. package/lib/api/utils/__tests__/validation.test.js +0 -109
  176. package/lib/sdk/client/__tests__/sdk.health.integration.test.d.ts +0 -1
  177. package/lib/sdk/client/__tests__/sdk.health.integration.test.js +0 -110
  178. package/lib/sdk/client/__tests__/sdk.iam.integration.test.d.ts +0 -1
  179. package/lib/sdk/client/__tests__/sdk.iam.integration.test.js +0 -179
  180. package/lib/sdk/client/__tests__/sdk.models.integration.test.d.ts +0 -1
  181. package/lib/sdk/client/__tests__/sdk.models.integration.test.js +0 -376
  182. package/lib/sdk/client/__tests__/sdk.runtimes.integration.test.d.ts +0 -1
  183. package/lib/sdk/client/__tests__/sdk.runtimes.integration.test.js +0 -276
  184. package/lib/sdk/client/__tests__/sdk.spacer.integration.test.d.ts +0 -1
  185. package/lib/sdk/client/__tests__/sdk.spacer.integration.test.js +0 -361
  186. package/lib/sdk/client/base.d.ts +0 -88
  187. package/lib/sdk/client/base.js +0 -112
  188. package/lib/sdk/client/index.d.ts +0 -192
  189. package/lib/sdk/client/index.js +0 -128
  190. package/lib/sdk/client/mixins/HealthMixin.d.ts +0 -100
  191. package/lib/sdk/client/mixins/HealthMixin.js +0 -133
  192. package/lib/sdk/client/mixins/IAMMixin.d.ts +0 -59
  193. package/lib/sdk/client/mixins/IAMMixin.js +0 -83
  194. package/lib/sdk/client/mixins/RuntimesMixin.d.ts +0 -134
  195. package/lib/sdk/client/mixins/RuntimesMixin.js +0 -221
  196. package/lib/sdk/client/mixins/SpacerMixin.d.ts +0 -184
  197. package/lib/sdk/client/mixins/SpacerMixin.js +0 -278
  198. package/lib/sdk/client/models/Lexical.d.ts +0 -156
  199. package/lib/sdk/client/models/Lexical.js +0 -275
  200. package/lib/sdk/client/models/Notebook.d.ts +0 -174
  201. package/lib/sdk/client/models/Notebook.js +0 -311
  202. package/lib/sdk/client/models/Runtime.d.ts +0 -221
  203. package/lib/sdk/client/models/Runtime.js +0 -341
  204. package/lib/sdk/client/models/Snapshot.d.ts +0 -156
  205. package/lib/sdk/client/models/Snapshot.js +0 -244
  206. package/lib/sdk/client/models/Space.d.ts +0 -182
  207. package/lib/sdk/client/models/Space.js +0 -276
  208. package/lib/sdk/client/models/__tests__/Lexical.test.d.ts +0 -1
  209. package/lib/sdk/client/models/__tests__/Lexical.test.js +0 -288
  210. package/lib/sdk/client/models/__tests__/Notebook.test.d.ts +0 -1
  211. package/lib/sdk/client/models/__tests__/Notebook.test.js +0 -206
  212. package/lib/sdk/client/models/__tests__/Runtime.test.d.ts +0 -1
  213. package/lib/sdk/client/models/__tests__/Runtime.test.js +0 -133
  214. package/lib/sdk/client/models/__tests__/Snapshot.test.d.ts +0 -1
  215. package/lib/sdk/client/models/__tests__/Snapshot.test.js +0 -244
  216. package/lib/sdk/client/models/__tests__/Space.test.d.ts +0 -1
  217. package/lib/sdk/client/models/__tests__/Space.test.js +0 -334
  218. package/lib/sdk/client/models/index.d.ts +0 -30
  219. package/lib/sdk/client/models/index.js +0 -30
  220. package/lib/sdk/client/utils/mixins.d.ts +0 -42
  221. /package/lib/{sdk/stateful/runtimes/apis.js → api/types/common.js} +0 -0
  222. /package/lib/{sdk/stateful → stateful}/jupyter/exec/Python.d.ts +0 -0
  223. /package/lib/{sdk/stateful → stateful}/jupyter/exec/Python.js +0 -0
  224. /package/lib/{sdk/stateful → stateful}/jupyter/exec/index.d.ts +0 -0
  225. /package/lib/{sdk/stateful → stateful}/jupyter/exec/index.js +0 -0
  226. /package/lib/{sdk/stateful → stateful}/jupyter/index.d.ts +0 -0
  227. /package/lib/{sdk/stateful → stateful}/jupyter/index.js +0 -0
  228. /package/lib/{sdk/stateful → stateful}/jupyter/kernelsHandler.d.ts +0 -0
  229. /package/lib/{sdk/stateful → stateful}/jupyter/kernelsHandler.js +0 -0
  230. /package/lib/{sdk/stateful → stateful}/runtimes/index.d.ts +0 -0
  231. /package/lib/{sdk/stateful → stateful}/runtimes/index.js +0 -0
  232. /package/lib/{sdk/stateful → stateful}/runtimes/settings.d.ts +0 -0
  233. /package/lib/{sdk/stateful → stateful}/runtimes/settings.js +0 -0
  234. /package/lib/{sdk/stateful → stateful}/runtimes/snapshots.d.ts +0 -0
  235. /package/lib/{sdk/stateful → stateful}/runtimes/snapshots.js +0 -0
  236. /package/lib/{sdk/stateful → stateful}/runtimes/utils.d.ts +0 -0
  237. /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 '../types/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,56 @@
1
+ /**
2
+ * Credit information for a user.
3
+ */
4
+ export interface CreditsInfo {
5
+ /** Available credits */
6
+ credits: number;
7
+ /** Credit quota (null if unlimited) */
8
+ quota: number | null;
9
+ /** Last update timestamp */
10
+ last_update: string;
11
+ }
12
+ /**
13
+ * Credit reservation information.
14
+ */
15
+ export interface CreditReservation {
16
+ /** Reservation ID */
17
+ id: string;
18
+ /** Reserved credits */
19
+ credits: number;
20
+ /** Resource ID (e.g., runtime ID) */
21
+ resource: string;
22
+ /** Last update timestamp */
23
+ last_update: string;
24
+ /** Burning rate (credits per hour) for this reservation */
25
+ burning_rate: number;
26
+ /** Start date of the reservation */
27
+ start_date: string;
28
+ }
29
+ /**
30
+ * Response from the credits endpoint.
31
+ */
32
+ export interface CreditsResponse {
33
+ /** Operation success status */
34
+ success: boolean;
35
+ /** Credit information */
36
+ credits: CreditsInfo;
37
+ /** Active credit reservations */
38
+ reservations: CreditReservation[];
39
+ }
40
+ /**
41
+ * Get the current user's available credits and usage information.
42
+ *
43
+ * @param token - Authentication token
44
+ * @param iamUrl - Optional IAM service URL (defaults to production)
45
+ * @returns Promise with credits information
46
+ *
47
+ * @example
48
+ * ```typescript
49
+ * import { getCredits } from '@datalayer/core/api/iam';
50
+ *
51
+ * const creditsInfo = await getCredits(token);
52
+ * console.log(`Available credits: ${creditsInfo.credits.credits}`);
53
+ * console.log(`Quota: ${creditsInfo.credits.quota || 'unlimited'}`);
54
+ * ```
55
+ */
56
+ 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,9 +1,10 @@
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';
@@ -12,9 +13,9 @@ export * as iam from './iam';
12
13
  export * as runtimes from './runtimes';
13
14
  export * as spacer from './spacer';
14
15
  /**
15
- * @deprecated Please import directly from '@datalayer/core/sdk/stateful' instead.
16
+ * @deprecated Please import directly from '@datalayer/core/stateful' instead.
16
17
  * This module provides backward compatibility for the moved apiv1 modules.
17
18
  */
18
- export * from '../sdk/stateful/jupyter';
19
- export * from '../sdk/stateful/runtimes';
19
+ export * from '../stateful/jupyter';
20
+ export * from '../stateful/runtimes';
20
21
  export * from '../api/DatalayerApi';
package/lib/api/index.js CHANGED
@@ -3,11 +3,12 @@
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';
@@ -18,9 +19,9 @@ export * as iam from './iam';
18
19
  export * as runtimes from './runtimes';
19
20
  export * as spacer from './spacer';
20
21
  /**
21
- * @deprecated Please import directly from '@datalayer/core/sdk/stateful' instead.
22
+ * @deprecated Please import directly from '@datalayer/core/stateful' instead.
22
23
  * This module provides backward compatibility for the moved apiv1 modules.
23
24
  */
24
- export * from '../sdk/stateful/jupyter';
25
- export * from '../sdk/stateful/runtimes';
25
+ export * from '../stateful/jupyter';
26
+ export * from '../stateful/runtimes';
26
27
  export * from '../api/DatalayerApi';
@@ -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 '../types/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';
@@ -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,
@@ -3,10 +3,11 @@
3
3
  * Distributed under the terms of the Modified BSD License.
4
4
  */
5
5
  /**
6
- * @module api/runtimes/snapshots
7
- * @description Runtime snapshots API functions for the Datalayer platform.
6
+ * Runtime snapshots API functions for the Datalayer platform.
8
7
  *
9
8
  * Provides functions for managing runtime snapshots (saved runtime states).
9
+ *
10
+ * @module api/runtimes/snapshots
10
11
  */
11
12
  import { requestDatalayerAPI } from '../DatalayerApi';
12
13
  import { API_BASE_PATHS, DEFAULT_SERVICE_URLS } from '../constants';