@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
package/README.md CHANGED
@@ -81,7 +81,7 @@ npm install
81
81
  Set your Datalayer token as an environment variable:
82
82
 
83
83
  ```bash
84
- export DATALAYER_TOKEN="your-token-here"
84
+ export DATALAYER_API_KEY="your-api-key"
85
85
  ```
86
86
 
87
87
  Or pass it directly to the SDK:
@@ -153,7 +153,7 @@ Run the interactive examples locally:
153
153
  npm install
154
154
 
155
155
  # Set your Datalayer API token in .env
156
- echo "VITE_DATALAYER_API_TOKEN=your-token-here" > .env
156
+ echo "VITE_DATALAYER_API_KEY=your-token-here" > .env
157
157
 
158
158
  # Start the examples server
159
159
  npm run example
@@ -1,14 +1,14 @@
1
1
  /**
2
- * A wrapped error for a fetch response.
2
+ * Error wrapper for failed HTTP responses.
3
+ * Includes response details, warnings, errors, and tracebacks.
3
4
  */
4
5
  export declare class RunResponseError extends Error {
5
6
  /**
6
- * Create a RunResponseError from a response,
7
- * handling the traceback and message as appropriate.
7
+ * Creates a RunResponseError from a Response object.
8
+ * Extracts error details from response JSON.
8
9
  *
9
- * @param response The response object.
10
- *
11
- * @returns A promise that resolves with a `RunResponseError` object.
10
+ * @param response - The failed HTTP response
11
+ * @returns Promise resolving to RunResponseError instance
12
12
  */
13
13
  static create(response: Response): Promise<RunResponseError>;
14
14
  /**
@@ -38,38 +38,50 @@ export declare class RunResponseError extends Error {
38
38
  private static _defaultMessage;
39
39
  }
40
40
  /**
41
- * A wrapped error for a network error.
41
+ * Error wrapper for network failures.
42
+ * Thrown when HTTP request fails due to connectivity issues.
42
43
  */
43
44
  export declare class NetworkError extends TypeError {
44
45
  /**
45
- * Create a new network error.
46
+ * Creates a NetworkError from the original TypeError.
47
+ *
48
+ * @param original - The original network error
46
49
  */
47
50
  constructor(original: TypeError);
48
51
  }
52
+ /**
53
+ * Options for Datalayer API requests.
54
+ */
49
55
  export interface IRequestDatalayerAPIOptions {
50
- /**
51
- * URL to request
52
- */
56
+ /** Target URL for the request */
53
57
  url: string;
54
- /**
55
- * HTTP method
56
- */
58
+ /** HTTP method (GET, POST, PUT, DELETE, etc.) */
57
59
  method?: string;
58
- /**
59
- * JSON-serializable object or FormData
60
- */
60
+ /** Request body (JSON object or FormData) */
61
61
  body?: any;
62
- /**
63
- * Headers
64
- */
62
+ /** Custom HTTP headers */
65
63
  headers?: Record<string, string>;
66
- /**
67
- * Authorization bearer token
68
- */
64
+ /** JWT bearer token for authentication */
69
65
  token?: string;
70
- /**
71
- * Request abort signal.
72
- */
66
+ /** AbortSignal for request cancellation */
73
67
  signal?: AbortSignal;
74
68
  }
69
+ /**
70
+ * Makes authenticated HTTP requests to Datalayer APIs.
71
+ * Handles JSON and FormData, includes auth headers, and manages redirects.
72
+ *
73
+ * @param options - Request configuration
74
+ * @returns Promise resolving to response data
75
+ * @throws {NetworkError} On network failures
76
+ * @throws {RunResponseError} On HTTP error responses
77
+ *
78
+ * @example
79
+ * ```typescript
80
+ * const data = await requestDatalayerAPI({
81
+ * url: 'https://api.datalayer.run/users',
82
+ * method: 'GET',
83
+ * token: 'eyJhbGc...'
84
+ * });
85
+ * ```
86
+ */
75
87
  export declare function requestDatalayerAPI<T = any>({ url, method, body, token, signal, headers, }: IRequestDatalayerAPIOptions): Promise<T>;
@@ -2,20 +2,26 @@
2
2
  * Copyright (c) 2023-2025 Datalayer, Inc.
3
3
  * Distributed under the terms of the Modified BSD License.
4
4
  */
5
+ /**
6
+ * Core HTTP client for Datalayer API requests.
7
+ * Handles authentication, error handling, and async redirects.
8
+ *
9
+ * @module api/DatalayerApi
10
+ */
5
11
  import { URLExt } from '@jupyterlab/coreutils';
6
12
  import axios from 'axios';
7
13
  import { sleep } from '../utils/Sleep';
8
14
  /**
9
- * A wrapped error for a fetch response.
15
+ * Error wrapper for failed HTTP responses.
16
+ * Includes response details, warnings, errors, and tracebacks.
10
17
  */
11
18
  export class RunResponseError extends Error {
12
19
  /**
13
- * Create a RunResponseError from a response,
14
- * handling the traceback and message as appropriate.
20
+ * Creates a RunResponseError from a Response object.
21
+ * Extracts error details from response JSON.
15
22
  *
16
- * @param response The response object.
17
- *
18
- * @returns A promise that resolves with a `RunResponseError` object.
23
+ * @param response - The failed HTTP response
24
+ * @returns Promise resolving to RunResponseError instance
19
25
  */
20
26
  static async create(response) {
21
27
  try {
@@ -69,11 +75,14 @@ export class RunResponseError extends Error {
69
75
  }
70
76
  }
71
77
  /**
72
- * A wrapped error for a network error.
78
+ * Error wrapper for network failures.
79
+ * Thrown when HTTP request fails due to connectivity issues.
73
80
  */
74
81
  export class NetworkError extends TypeError {
75
82
  /**
76
- * Create a new network error.
83
+ * Creates a NetworkError from the original TypeError.
84
+ *
85
+ * @param original - The original network error
77
86
  */
78
87
  constructor(original) {
79
88
  super(original.message);
@@ -81,6 +90,24 @@ export class NetworkError extends TypeError {
81
90
  this.stack = original.stack;
82
91
  }
83
92
  }
93
+ /**
94
+ * Makes authenticated HTTP requests to Datalayer APIs.
95
+ * Handles JSON and FormData, includes auth headers, and manages redirects.
96
+ *
97
+ * @param options - Request configuration
98
+ * @returns Promise resolving to response data
99
+ * @throws {NetworkError} On network failures
100
+ * @throws {RunResponseError} On HTTP error responses
101
+ *
102
+ * @example
103
+ * ```typescript
104
+ * const data = await requestDatalayerAPI({
105
+ * url: 'https://api.datalayer.run/users',
106
+ * method: 'GET',
107
+ * token: 'eyJhbGc...'
108
+ * });
109
+ * ```
110
+ */
84
111
  export async function requestDatalayerAPI({ url, method, body, token, signal, headers = {}, }) {
85
112
  // Handle FormData differently from JSON
86
113
  const isFormData = body instanceof FormData;
@@ -127,9 +154,21 @@ export async function requestDatalayerAPI({ url, method, body, token, signal, he
127
154
  }
128
155
  try {
129
156
  const response = await axios(axiosConfig);
130
- // Handle redirections if needed
131
- if (response.status === 202 && response.headers.location) {
132
- return await handleAxiosRedirection(response, axiosConfig);
157
+ if (response.status < 300) {
158
+ // Handle redirections if needed.
159
+ if (response.status === 202 && response.headers.location) {
160
+ return await handleAxiosRedirection(response, axiosConfig);
161
+ }
162
+ }
163
+ else {
164
+ const adaptedResponse = {
165
+ ok: false,
166
+ status: response.status,
167
+ statusText: response.statusText,
168
+ json: async () => response?.data,
169
+ text: async () => JSON.stringify(response?.data),
170
+ };
171
+ throw await RunResponseError.create(adaptedResponse);
133
172
  }
134
173
  return response.data;
135
174
  }
@@ -137,14 +176,14 @@ export async function requestDatalayerAPI({ url, method, body, token, signal, he
137
176
  if (axios.isAxiosError(error)) {
138
177
  if (error.response) {
139
178
  // Convert axios error to our RunResponseError format
140
- const mockResponse = {
179
+ const adaptedResponse = {
141
180
  ok: false,
142
181
  status: error.response.status,
143
182
  statusText: error.response.statusText,
144
183
  json: async () => error.response?.data,
145
184
  text: async () => JSON.stringify(error.response?.data),
146
185
  };
147
- throw await RunResponseError.create(mockResponse);
186
+ throw await RunResponseError.create(adaptedResponse);
148
187
  }
149
188
  throw new NetworkError(error);
150
189
  }
@@ -1,6 +1,7 @@
1
- import { LoginRequest, LoginResponse } from '../types/iam';
1
+ import { LoginRequest, LoginResponse } from '../../models/IAM';
2
2
  /**
3
3
  * Authenticate a user with credentials or token
4
+ *
4
5
  * @param data - Login credentials (either handle+password or token)
5
6
  * @param baseUrl - Base URL for the API (defaults to production IAM URL)
6
7
  * @returns Login response with tokens
@@ -9,7 +10,7 @@ import { LoginRequest, LoginResponse } from '../types/iam';
9
10
  * @throws {Error} If handle is provided without password or vice versa
10
11
  * @throws {Error} If server returns unexpected status code (expects 201 for success, 401 for failure)
11
12
  *
12
- * @description
13
+ * @remarks
13
14
  * Expected status codes:
14
15
  * - 201: Login succeeded
15
16
  * - 401: Login failed (invalid credentials)
@@ -23,18 +24,18 @@ export declare const login: (data: LoginRequest, baseUrl?: string) => Promise<Lo
23
24
  */
24
25
  export declare const logout: (token: string, baseUrl?: string) => Promise<void>;
25
26
  /**
26
- * Validate authentication through proxy
27
+ * Check authentication status
28
+ *
27
29
  * @param token - Authentication token (required)
28
30
  * @param baseUrl - Base URL for the API (defaults to production IAM URL)
29
- * @returns Promise that resolves if authenticated (200), rejects if unauthorized (401) or forbidden (403)
31
+ * @returns Promise that resolves if authenticated (200), rejects if unauthorized (401)
30
32
  * @throws {Error} If authentication token is missing or invalid
31
33
  *
32
- * @description
33
- * This endpoint validates authentication status through a proxy.
34
+ * @remarks
35
+ * This endpoint checks authentication status, useful for reverse proxy validation.
34
36
  *
35
37
  * Expected status codes:
36
38
  * - 200: Authenticated successfully
37
39
  * - 401: Unauthorized - invalid or missing credentials
38
- * - 403: Forbidden - valid credentials but access denied
39
40
  */
40
- export declare const proxyAuth: (token: string, baseUrl?: string) => Promise<void>;
41
+ export declare const checkAuth: (token: string, baseUrl?: string) => Promise<void>;
@@ -3,16 +3,18 @@
3
3
  * Distributed under the terms of the Modified BSD License.
4
4
  */
5
5
  /**
6
- * @module api/iam/authentication
7
- * @description Authentication API functions for the Datalayer platform.
6
+ * Authentication API functions for the Datalayer platform.
8
7
  *
9
8
  * Provides functions for user login, logout, and authentication management.
9
+ *
10
+ * @module api/iam/authentication
10
11
  */
11
12
  import { requestDatalayerAPI } from '../DatalayerApi';
12
13
  import { API_BASE_PATHS, DEFAULT_SERVICE_URLS } from '../constants';
13
14
  import { validateToken } from '../utils/validation';
14
15
  /**
15
16
  * Authenticate a user with credentials or token
17
+ *
16
18
  * @param data - Login credentials (either handle+password or token)
17
19
  * @param baseUrl - Base URL for the API (defaults to production IAM URL)
18
20
  * @returns Login response with tokens
@@ -21,7 +23,7 @@ import { validateToken } from '../utils/validation';
21
23
  * @throws {Error} If handle is provided without password or vice versa
22
24
  * @throws {Error} If server returns unexpected status code (expects 201 for success, 401 for failure)
23
25
  *
24
- * @description
26
+ * @remarks
25
27
  * Expected status codes:
26
28
  * - 201: Login succeeded
27
29
  * - 401: Login failed (invalid credentials)
@@ -82,25 +84,25 @@ export const logout = async (token, baseUrl = DEFAULT_SERVICE_URLS.IAM) => {
82
84
  });
83
85
  };
84
86
  /**
85
- * Validate authentication through proxy
87
+ * Check authentication status
88
+ *
86
89
  * @param token - Authentication token (required)
87
90
  * @param baseUrl - Base URL for the API (defaults to production IAM URL)
88
- * @returns Promise that resolves if authenticated (200), rejects if unauthorized (401) or forbidden (403)
91
+ * @returns Promise that resolves if authenticated (200), rejects if unauthorized (401)
89
92
  * @throws {Error} If authentication token is missing or invalid
90
93
  *
91
- * @description
92
- * This endpoint validates authentication status through a proxy.
94
+ * @remarks
95
+ * This endpoint checks authentication status, useful for reverse proxy validation.
93
96
  *
94
97
  * Expected status codes:
95
98
  * - 200: Authenticated successfully
96
99
  * - 401: Unauthorized - invalid or missing credentials
97
- * - 403: Forbidden - valid credentials but access denied
98
100
  */
99
- export const proxyAuth = async (token, baseUrl = DEFAULT_SERVICE_URLS.IAM) => {
101
+ export const checkAuth = async (token, baseUrl = DEFAULT_SERVICE_URLS.IAM) => {
100
102
  validateToken(token);
101
103
  try {
102
104
  const response = await requestDatalayerAPI({
103
- url: `${baseUrl}${API_BASE_PATHS.IAM}/proxy-auth`,
105
+ url: `${baseUrl}${API_BASE_PATHS.IAM}/auth`,
104
106
  method: 'GET',
105
107
  token,
106
108
  });
@@ -114,13 +116,10 @@ export const proxyAuth = async (token, baseUrl = DEFAULT_SERVICE_URLS.IAM) => {
114
116
  const status = error.response.status;
115
117
  // Expected errors
116
118
  if (status === 401) {
117
- throw new Error(`Proxy authentication failed: Unauthorized (${status})`);
118
- }
119
- if (status === 403) {
120
- throw new Error(`Proxy authentication failed: Forbidden (${status})`);
119
+ throw new Error(`Authentication check failed: Unauthorized (${status})`);
121
120
  }
122
121
  // Unexpected status codes
123
- throw new Error(`Proxy authentication failed: Unexpected status code ${status} - ${error.message}`);
122
+ throw new Error(`Authentication check failed: Unexpected status code ${status} - ${error.message}`);
124
123
  }
125
124
  // Re-throw other errors (network errors, etc.)
126
125
  throw error;
@@ -1,11 +1,12 @@
1
- import { HealthzPingResponse } from '../types/iam';
1
+ import type { HealthzPingResponse } from '../../models/Common';
2
2
  /**
3
3
  * Health check ping endpoint
4
+ *
4
5
  * @param baseUrl - Base URL for the API (defaults to production IAM URL)
5
6
  * @returns Health check response with user count
6
7
  * @throws {Error} If the health check fails
7
8
  *
8
- * @description
9
+ * @remarks
9
10
  * This endpoint provides a basic health check for the IAM service.
10
11
  * It returns the current user count in the system.
11
12
  *
@@ -3,20 +3,22 @@
3
3
  * Distributed under the terms of the Modified BSD License.
4
4
  */
5
5
  /**
6
- * @module api/iam/healthz
7
- * @description Health check API functions for the Datalayer IAM service.
6
+ * Health check API functions for the Datalayer IAM service.
8
7
  *
9
8
  * Provides functions for checking the health status of the IAM service.
9
+ *
10
+ * @module api/iam/healthz
10
11
  */
11
12
  import { requestDatalayerAPI } from '../DatalayerApi';
12
13
  import { API_BASE_PATHS, DEFAULT_SERVICE_URLS } from '../constants';
13
14
  /**
14
15
  * Health check ping endpoint
16
+ *
15
17
  * @param baseUrl - Base URL for the API (defaults to production IAM URL)
16
18
  * @returns Health check response with user count
17
19
  * @throws {Error} If the health check fails
18
20
  *
19
- * @description
21
+ * @remarks
20
22
  * This endpoint provides a basic health check for the IAM service.
21
23
  * It returns the current user count in the system.
22
24
  *
@@ -1,12 +1,17 @@
1
1
  /**
2
- * @module api/iam
3
- * @description IAM (Identity and Access Management) API exports.
2
+ * IAM (Identity and Access Management) API exports.
3
+ *
4
+ * Provides organized access to authentication, OAuth2, and user profile functionality.
4
5
  *
5
- * Provides organized access to authentication and user profile functionality.
6
+ * @module api/iam
6
7
  */
7
8
  export * as authentication from './authentication';
9
+ export * as oauth2 from './oauth2';
8
10
  export * as profile from './profile';
9
11
  export * as healthz from './healthz';
10
- export { login, logout, proxyAuth } from './authentication';
12
+ export * as usage from './usage';
13
+ export { login, logout, checkAuth } from './authentication';
14
+ export { getOAuth2AuthzUrl, getOAuth2AuthzUrlForLink, handleGitHubOAuth2Callback, handleLinkedInOAuth2Callback, handleOktaOAuth2Callback, type OAuth2Provider, type OAuth2AuthzUrlResponse, type OAuth2CallbackParams, type OAuth2CallbackResponse, } from './oauth2';
11
15
  export { me, whoami } from './profile';
12
16
  export { ping } from './healthz';
17
+ export { getCredits } from './usage';
@@ -3,15 +3,20 @@
3
3
  * Distributed under the terms of the Modified BSD License.
4
4
  */
5
5
  /**
6
- * @module api/iam
7
- * @description IAM (Identity and Access Management) API exports.
6
+ * IAM (Identity and Access Management) API exports.
7
+ *
8
+ * Provides organized access to authentication, OAuth2, and user profile functionality.
8
9
  *
9
- * Provides organized access to authentication and user profile functionality.
10
+ * @module api/iam
10
11
  */
11
12
  export * as authentication from './authentication';
13
+ export * as oauth2 from './oauth2';
12
14
  export * as profile from './profile';
13
15
  export * as healthz from './healthz';
16
+ export * as usage from './usage';
14
17
  // For backward compatibility, export the old API structure
15
- export { login, logout, proxyAuth } from './authentication';
18
+ export { login, logout, checkAuth } from './authentication';
19
+ export { getOAuth2AuthzUrl, getOAuth2AuthzUrlForLink, handleGitHubOAuth2Callback, handleLinkedInOAuth2Callback, handleOktaOAuth2Callback, } from './oauth2';
16
20
  export { me, whoami } from './profile';
17
21
  export { ping } from './healthz';
22
+ export { getCredits } from './usage';
@@ -0,0 +1,115 @@
1
+ /**
2
+ * OAuth2 provider types supported by the platform
3
+ */
4
+ export type OAuth2Provider = 'github' | 'linkedin' | 'okta';
5
+ /**
6
+ * Response from the OAuth2 authorization URL endpoint
7
+ */
8
+ export interface OAuth2AuthzUrlResponse {
9
+ success: boolean;
10
+ message: string;
11
+ loginURL: string;
12
+ }
13
+ /**
14
+ * OAuth2 callback parameters
15
+ */
16
+ export interface OAuth2CallbackParams {
17
+ code?: string;
18
+ state: string;
19
+ error?: string;
20
+ error_description?: string;
21
+ error_uri?: string;
22
+ }
23
+ /**
24
+ * OAuth2 callback response (HTML content)
25
+ */
26
+ export type OAuth2CallbackResponse = string;
27
+ /**
28
+ * Get the OAuth2 authorization URL for a specific provider
29
+ * @param provider - OAuth2 provider (bluesky, github, linkedin, okta)
30
+ * @param callbackUri - Server endpoint to call with the authz token
31
+ * @param nonce - Optional nonce for security
32
+ * @param baseUrl - Base URL for the API (defaults to production IAM URL)
33
+ * @returns OAuth2 authorization URL response
34
+ * @throws {Error} If required parameters are missing or invalid
35
+ *
36
+ * @remarks
37
+ * This endpoint generates the OAuth2 authorization URL for the specified provider.
38
+ * Users should be redirected to the returned loginURL to begin the OAuth2 flow.
39
+ *
40
+ * Expected status codes:
41
+ * - 200: Successfully generated authorization URL
42
+ * - 400: Invalid parameters
43
+ * - 404: Provider not found or not configured
44
+ */
45
+ export declare const getOAuth2AuthzUrl: (provider: OAuth2Provider, callbackUri: string, nonce?: string, baseUrl?: string) => Promise<OAuth2AuthzUrlResponse>;
46
+ /**
47
+ * Get the OAuth2 authorization URL for linking a provider to an existing account
48
+ * @param provider - OAuth2 provider (bluesky, github, linkedin, okta)
49
+ * @param callbackUri - Server endpoint to call with the authz token
50
+ * @param baseUrl - Base URL for the API (defaults to production IAM URL)
51
+ * @returns OAuth2 authorization URL response
52
+ * @throws {Error} If required parameters are missing or invalid
53
+ *
54
+ * @remarks
55
+ * This endpoint generates the OAuth2 authorization URL for linking a provider to an existing account.
56
+ * Users should be redirected to the returned loginURL to begin the OAuth2 linking flow.
57
+ * This is different from the regular OAuth2 login flow as it links the provider to an existing account.
58
+ *
59
+ * Expected status codes:
60
+ * - 200: Successfully generated authorization URL
61
+ * - 400: Invalid parameters
62
+ * - 404: Provider not found or not configured
63
+ */
64
+ export declare const getOAuth2AuthzUrlForLink: (provider: OAuth2Provider, callbackUri: string, baseUrl?: string) => Promise<OAuth2AuthzUrlResponse>;
65
+ /**
66
+ * Handle GitHub OAuth2 callback
67
+ * @param params - OAuth2 callback parameters
68
+ * @param baseUrl - Base URL for the API (defaults to production IAM URL)
69
+ * @returns HTML response from the callback handler
70
+ * @throws {Error} If state parameter is missing
71
+ * @throws {Error} If the callback fails
72
+ *
73
+ * @remarks
74
+ * This endpoint handles the callback from GitHub after the user authorizes the application.
75
+ * It returns HTML content that typically includes JavaScript to handle the OAuth flow completion.
76
+ *
77
+ * Expected status codes:
78
+ * - 200: Callback processed successfully (returns HTML)
79
+ * - 403: Unauthorized
80
+ */
81
+ export declare const handleGitHubOAuth2Callback: (params: OAuth2CallbackParams, baseUrl?: string) => Promise<OAuth2CallbackResponse>;
82
+ /**
83
+ * Handle LinkedIn OAuth2 callback
84
+ * @param params - OAuth2 callback parameters
85
+ * @param baseUrl - Base URL for the API (defaults to production IAM URL)
86
+ * @returns HTML response from the callback handler
87
+ * @throws {Error} If state parameter is missing
88
+ * @throws {Error} If the callback fails
89
+ *
90
+ * @remarks
91
+ * This endpoint handles the callback from LinkedIn after the user authorizes the application.
92
+ * It returns HTML content that typically includes JavaScript to handle the OAuth flow completion.
93
+ *
94
+ * Expected status codes:
95
+ * - 200: Callback processed successfully (returns HTML)
96
+ * - 403: Unauthorized
97
+ */
98
+ export declare const handleLinkedInOAuth2Callback: (params: OAuth2CallbackParams, baseUrl?: string) => Promise<OAuth2CallbackResponse>;
99
+ /**
100
+ * Handle Okta OAuth2 callback
101
+ * @param params - OAuth2 callback parameters
102
+ * @param baseUrl - Base URL for the API (defaults to production IAM URL)
103
+ * @returns HTML response from the callback handler
104
+ * @throws {Error} If state parameter is missing
105
+ * @throws {Error} If the callback fails
106
+ *
107
+ * @remarks
108
+ * This endpoint handles the callback from Okta after the user authorizes the application.
109
+ * It returns HTML content that typically includes JavaScript to handle the OAuth flow completion.
110
+ *
111
+ * Expected status codes:
112
+ * - 200: Callback processed successfully (returns HTML)
113
+ * - 403: Unauthorized
114
+ */
115
+ export declare const handleOktaOAuth2Callback: (params: OAuth2CallbackParams, baseUrl?: string) => Promise<OAuth2CallbackResponse>;