@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
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.
15
- *
16
- * @param response The response object.
20
+ * Creates a RunResponseError from a Response object.
21
+ * Extracts error details from response JSON.
17
22
  *
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;
@@ -1,6 +1,7 @@
1
1
  import { LoginRequest, LoginResponse } from '../types/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 '../types/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, type CreditsInfo, type CreditReservation, type CreditsResponse, } 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>;