@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.
- package/README.md +2 -2
- package/lib/api/DatalayerApi.d.ts +38 -26
- package/lib/api/DatalayerApi.js +52 -13
- package/lib/api/iam/authentication.d.ts +9 -8
- package/lib/api/iam/authentication.js +14 -15
- package/lib/api/iam/healthz.d.ts +3 -2
- package/lib/api/iam/healthz.js +5 -3
- package/lib/api/iam/index.d.ts +9 -4
- package/lib/api/iam/index.js +9 -4
- package/lib/api/iam/oauth2.d.ts +115 -0
- package/lib/api/iam/oauth2.js +309 -0
- package/lib/api/iam/profile.d.ts +8 -1
- package/lib/api/iam/profile.js +17 -2
- package/lib/api/iam/usage.d.ts +18 -0
- package/lib/api/iam/usage.js +39 -0
- package/lib/api/index.d.ts +6 -6
- package/lib/api/index.js +6 -7
- package/lib/api/runtimes/environments.d.ts +2 -2
- package/lib/api/runtimes/environments.js +3 -2
- package/lib/api/runtimes/healthz.d.ts +3 -13
- package/lib/api/runtimes/healthz.js +4 -3
- package/lib/api/runtimes/index.d.ts +3 -2
- package/lib/api/runtimes/index.js +3 -2
- package/lib/api/runtimes/runtimes.d.ts +4 -4
- package/lib/api/runtimes/runtimes.js +17 -6
- package/lib/api/runtimes/snapshots.d.ts +4 -4
- package/lib/api/runtimes/snapshots.js +3 -2
- package/lib/api/spacer/documents.d.ts +12 -0
- package/lib/api/spacer/documents.js +43 -0
- package/lib/api/spacer/healthz.d.ts +3 -13
- package/lib/api/spacer/healthz.js +4 -3
- package/lib/api/spacer/index.d.ts +4 -2
- package/lib/api/spacer/index.js +4 -2
- package/lib/api/spacer/items.d.ts +9 -1
- package/lib/api/spacer/items.js +17 -2
- package/lib/api/spacer/lexicals.d.ts +1 -1
- package/lib/api/spacer/lexicals.js +3 -2
- package/lib/api/spacer/notebooks.d.ts +1 -1
- package/lib/api/spacer/notebooks.js +3 -2
- package/lib/api/spacer/spaces.d.ts +1 -1
- package/lib/api/spacer/spaces.js +3 -2
- package/lib/api/spacer/users.d.ts +1 -1
- package/lib/api/spacer/users.js +3 -2
- package/lib/api/utils/validation.d.ts +24 -1
- package/lib/api/utils/validation.js +62 -1
- package/lib/client/base.d.ts +75 -0
- package/lib/client/base.js +199 -0
- package/lib/client/constants.d.ts +22 -0
- package/lib/client/constants.js +22 -0
- package/lib/client/index.d.ts +108 -0
- package/lib/client/index.js +79 -0
- package/lib/client/mixins/IAMMixin.d.ts +54 -0
- package/lib/client/mixins/IAMMixin.js +181 -0
- package/lib/client/mixins/RuntimesMixin.d.ts +93 -0
- package/lib/client/mixins/RuntimesMixin.js +229 -0
- package/lib/client/mixins/SpacerMixin.d.ts +111 -0
- package/lib/client/mixins/SpacerMixin.js +340 -0
- package/lib/client/utils/mixins.d.ts +12 -0
- package/lib/{sdk/client → client}/utils/mixins.js +0 -28
- package/lib/client/utils/spacerUtils.d.ts +18 -0
- package/lib/client/utils/spacerUtils.js +32 -0
- package/lib/collaboration/DatalayerCollaboration.d.ts +6 -1
- package/lib/collaboration/DatalayerCollaboration.js +2 -2
- package/lib/collaboration/DatalayerCollaborationProvider.d.ts +5 -0
- package/lib/collaboration/DatalayerCollaborationProvider.js +10 -9
- package/lib/components/progress/CreditsIndicator.d.ts +1 -1
- package/lib/components/runtimes/RuntimeCellVariablesDialog.js +1 -1
- package/lib/components/runtimes/RuntimeLauncherDialog.d.ts +1 -1
- package/lib/components/runtimes/RuntimeLauncherDialog.js +2 -2
- package/lib/components/runtimes/RuntimePickerBase.d.ts +1 -1
- package/lib/components/runtimes/RuntimePickerBase.js +1 -1
- package/lib/components/runtimes/RuntimePickerCell.js +3 -3
- package/lib/components/runtimes/RuntimePickerNotebook.d.ts +1 -1
- package/lib/components/runtimes/RuntimePickerNotebook.js +2 -2
- package/lib/components/runtimes/RuntimeTransfer.d.ts +2 -2
- package/lib/components/runtimes/RuntimeUtils.d.ts +1 -1
- package/lib/components/snapshots/RuntimeSnapshotMenu.d.ts +1 -1
- package/lib/components/snapshots/RuntimeSnapshotMenu.js +27 -20
- package/lib/config/Configuration.d.ts +8 -0
- package/lib/hooks/useDatalayer.js +1 -1
- package/lib/hooks/useRuntimes.js +1 -1
- package/lib/hooks/useToast.js +1 -1
- package/lib/index.d.ts +2 -3
- package/lib/index.js +4 -3
- package/lib/models/Common.d.ts +64 -0
- package/lib/models/CreditsDTO.d.ts +124 -0
- package/lib/models/CreditsDTO.js +135 -0
- package/lib/models/Environment.d.ts +1 -1
- package/lib/models/EnvironmentDTO.d.ts +125 -0
- package/lib/models/EnvironmentDTO.js +88 -0
- package/lib/models/HealthCheck.d.ts +72 -0
- package/lib/models/HealthCheck.js +107 -0
- package/lib/{api/types/iam.d.ts → models/IAM.d.ts} +15 -78
- package/lib/models/ItemDTO.d.ts +74 -0
- package/lib/models/ItemDTO.js +186 -0
- package/lib/models/LexicalDTO.d.ts +155 -0
- package/lib/models/LexicalDTO.js +157 -0
- package/lib/models/NotebookDTO.d.ts +96 -0
- package/lib/models/NotebookDTO.js +153 -0
- package/lib/models/Profile.d.ts +65 -0
- package/lib/models/RuntimeDTO.d.ts +191 -0
- package/lib/models/RuntimeDTO.js +204 -0
- package/lib/models/RuntimeSnapshotDTO.d.ts +173 -0
- package/lib/models/RuntimeSnapshotDTO.js +139 -0
- package/lib/models/SpaceDTO.d.ts +280 -0
- package/lib/models/SpaceDTO.js +239 -0
- package/lib/models/UserDTO.d.ts +86 -0
- package/lib/models/UserDTO.js +84 -0
- package/lib/models/index.d.ts +45 -4
- package/lib/models/index.js +45 -4
- package/lib/sdk/index.d.ts +5 -4
- package/lib/sdk/index.js +6 -5
- package/lib/services/DatalayerServiceManager.js +1 -1
- package/lib/state/substates/CoreState.js +2 -0
- package/lib/state/substates/RuntimesState.d.ts +1 -1
- package/lib/state/substates/RuntimesState.js +1 -1
- package/lib/{sdk/stateful → stateful}/index.d.ts +1 -1
- package/lib/{sdk/stateful → stateful}/index.js +1 -1
- package/lib/{sdk/stateful → stateful}/jupyter/exec/Snippets.d.ts +1 -41
- package/lib/{sdk/stateful → stateful}/jupyter/exec/Snippets.js +1 -20
- package/lib/{sdk/stateful → stateful}/runtimes/actions.d.ts +3 -3
- package/lib/{sdk/stateful → stateful}/runtimes/actions.js +8 -8
- package/lib/{sdk/stateful → stateful}/runtimes/apis.d.ts +8 -8
- package/package.json +13 -10
- package/lib/__tests__/hooks.test.d.ts +0 -1
- package/lib/__tests__/hooks.test.js +0 -19
- package/lib/__tests__/index.test.d.ts +0 -1
- package/lib/__tests__/index.test.js +0 -27
- package/lib/__tests__/integration.test.d.ts +0 -1
- package/lib/__tests__/integration.test.js +0 -57
- package/lib/__tests__/shared/cleanup-shared.d.ts +0 -4
- package/lib/__tests__/shared/cleanup-shared.js +0 -228
- package/lib/__tests__/shared/test-config.d.ts +0 -51
- package/lib/__tests__/shared/test-config.js +0 -110
- package/lib/__tests__/shared/test-constants.d.ts +0 -66
- package/lib/__tests__/shared/test-constants.js +0 -79
- package/lib/__tests__/utils.test.d.ts +0 -1
- package/lib/__tests__/utils.test.js +0 -59
- package/lib/api/__tests__/iam.authentication.integration.test.d.ts +0 -1
- package/lib/api/__tests__/iam.authentication.integration.test.js +0 -247
- package/lib/api/__tests__/iam.healthz.integration.test.d.ts +0 -1
- package/lib/api/__tests__/iam.healthz.integration.test.js +0 -63
- package/lib/api/__tests__/iam.profile.integration.test.d.ts +0 -1
- package/lib/api/__tests__/iam.profile.integration.test.js +0 -252
- package/lib/api/__tests__/runtimes.environments.integration.test.d.ts +0 -1
- package/lib/api/__tests__/runtimes.environments.integration.test.js +0 -122
- package/lib/api/__tests__/runtimes.healthz.integration.test.d.ts +0 -1
- package/lib/api/__tests__/runtimes.healthz.integration.test.js +0 -50
- package/lib/api/__tests__/runtimes.integration.test.d.ts +0 -1
- package/lib/api/__tests__/runtimes.integration.test.js +0 -369
- package/lib/api/__tests__/spacer.healthz.integration.test.d.ts +0 -1
- package/lib/api/__tests__/spacer.healthz.integration.test.js +0 -50
- package/lib/api/__tests__/spacer.integration.test.d.ts +0 -1
- package/lib/api/__tests__/spacer.integration.test.js +0 -519
- package/lib/api/iam/__tests__/authentication.unit.test.d.ts +0 -1
- package/lib/api/iam/__tests__/authentication.unit.test.js +0 -63
- package/lib/api/iam/__tests__/healthz.unit.test.d.ts +0 -1
- package/lib/api/iam/__tests__/healthz.unit.test.js +0 -60
- package/lib/api/iam/__tests__/profile.unit.test.d.ts +0 -1
- package/lib/api/iam/__tests__/profile.unit.test.js +0 -57
- package/lib/api/runtimes/__tests__/environments.unit.test.d.ts +0 -1
- package/lib/api/runtimes/__tests__/environments.unit.test.js +0 -77
- package/lib/api/runtimes/__tests__/healthz.unit.test.d.ts +0 -1
- package/lib/api/runtimes/__tests__/healthz.unit.test.js +0 -57
- package/lib/api/runtimes/__tests__/runtimes.unit.test.d.ts +0 -1
- package/lib/api/runtimes/__tests__/runtimes.unit.test.js +0 -139
- package/lib/api/runtimes/__tests__/snapshots.unit.test.d.ts +0 -1
- package/lib/api/runtimes/__tests__/snapshots.unit.test.js +0 -96
- package/lib/api/spacer/__tests__/healthz.unit.test.d.ts +0 -1
- package/lib/api/spacer/__tests__/healthz.unit.test.js +0 -57
- package/lib/api/spacer/__tests__/items.unit.test.d.ts +0 -1
- package/lib/api/spacer/__tests__/items.unit.test.js +0 -165
- package/lib/api/spacer/__tests__/lexicals.unit.test.d.ts +0 -1
- package/lib/api/spacer/__tests__/lexicals.unit.test.js +0 -323
- package/lib/api/spacer/__tests__/notebooks.unit.test.d.ts +0 -1
- package/lib/api/spacer/__tests__/notebooks.unit.test.js +0 -224
- package/lib/api/spacer/__tests__/users.unit.test.d.ts +0 -1
- package/lib/api/spacer/__tests__/users.unit.test.js +0 -132
- package/lib/api/types/index.d.ts +0 -32
- package/lib/api/types/index.js +0 -36
- package/lib/api/types/runtimes.d.ts +0 -235
- package/lib/api/types/spacer.d.ts +0 -271
- package/lib/api/types/spacer.js +0 -5
- package/lib/api/utils/__tests__/validation.test.d.ts +0 -1
- package/lib/api/utils/__tests__/validation.test.js +0 -109
- package/lib/sdk/client/__tests__/sdk.health.integration.test.d.ts +0 -1
- package/lib/sdk/client/__tests__/sdk.health.integration.test.js +0 -110
- package/lib/sdk/client/__tests__/sdk.iam.integration.test.d.ts +0 -1
- package/lib/sdk/client/__tests__/sdk.iam.integration.test.js +0 -179
- package/lib/sdk/client/__tests__/sdk.models.integration.test.d.ts +0 -1
- package/lib/sdk/client/__tests__/sdk.models.integration.test.js +0 -376
- package/lib/sdk/client/__tests__/sdk.runtimes.integration.test.d.ts +0 -1
- package/lib/sdk/client/__tests__/sdk.runtimes.integration.test.js +0 -276
- package/lib/sdk/client/__tests__/sdk.spacer.integration.test.d.ts +0 -1
- package/lib/sdk/client/__tests__/sdk.spacer.integration.test.js +0 -361
- package/lib/sdk/client/base.d.ts +0 -88
- package/lib/sdk/client/base.js +0 -112
- package/lib/sdk/client/index.d.ts +0 -192
- package/lib/sdk/client/index.js +0 -128
- package/lib/sdk/client/mixins/HealthMixin.d.ts +0 -100
- package/lib/sdk/client/mixins/HealthMixin.js +0 -133
- package/lib/sdk/client/mixins/IAMMixin.d.ts +0 -59
- package/lib/sdk/client/mixins/IAMMixin.js +0 -83
- package/lib/sdk/client/mixins/RuntimesMixin.d.ts +0 -134
- package/lib/sdk/client/mixins/RuntimesMixin.js +0 -221
- package/lib/sdk/client/mixins/SpacerMixin.d.ts +0 -184
- package/lib/sdk/client/mixins/SpacerMixin.js +0 -278
- package/lib/sdk/client/models/Lexical.d.ts +0 -156
- package/lib/sdk/client/models/Lexical.js +0 -275
- package/lib/sdk/client/models/Notebook.d.ts +0 -174
- package/lib/sdk/client/models/Notebook.js +0 -311
- package/lib/sdk/client/models/Runtime.d.ts +0 -221
- package/lib/sdk/client/models/Runtime.js +0 -341
- package/lib/sdk/client/models/Snapshot.d.ts +0 -156
- package/lib/sdk/client/models/Snapshot.js +0 -244
- package/lib/sdk/client/models/Space.d.ts +0 -182
- package/lib/sdk/client/models/Space.js +0 -276
- package/lib/sdk/client/models/__tests__/Lexical.test.d.ts +0 -1
- package/lib/sdk/client/models/__tests__/Lexical.test.js +0 -288
- package/lib/sdk/client/models/__tests__/Notebook.test.d.ts +0 -1
- package/lib/sdk/client/models/__tests__/Notebook.test.js +0 -206
- package/lib/sdk/client/models/__tests__/Runtime.test.d.ts +0 -1
- package/lib/sdk/client/models/__tests__/Runtime.test.js +0 -133
- package/lib/sdk/client/models/__tests__/Snapshot.test.d.ts +0 -1
- package/lib/sdk/client/models/__tests__/Snapshot.test.js +0 -244
- package/lib/sdk/client/models/__tests__/Space.test.d.ts +0 -1
- package/lib/sdk/client/models/__tests__/Space.test.js +0 -334
- package/lib/sdk/client/models/index.d.ts +0 -30
- package/lib/sdk/client/models/index.js +0 -30
- package/lib/sdk/client/utils/mixins.d.ts +0 -42
- /package/lib/{api/types/iam.js → models/Common.js} +0 -0
- /package/lib/{api/types/runtimes.js → models/IAM.js} +0 -0
- /package/lib/{sdk/stateful → stateful}/jupyter/exec/Python.d.ts +0 -0
- /package/lib/{sdk/stateful → stateful}/jupyter/exec/Python.js +0 -0
- /package/lib/{sdk/stateful → stateful}/jupyter/exec/index.d.ts +0 -0
- /package/lib/{sdk/stateful → stateful}/jupyter/exec/index.js +0 -0
- /package/lib/{sdk/stateful → stateful}/jupyter/index.d.ts +0 -0
- /package/lib/{sdk/stateful → stateful}/jupyter/index.js +0 -0
- /package/lib/{sdk/stateful → stateful}/jupyter/kernelsHandler.d.ts +0 -0
- /package/lib/{sdk/stateful → stateful}/jupyter/kernelsHandler.js +0 -0
- /package/lib/{sdk/stateful → stateful}/runtimes/apis.js +0 -0
- /package/lib/{sdk/stateful → stateful}/runtimes/index.d.ts +0 -0
- /package/lib/{sdk/stateful → stateful}/runtimes/index.js +0 -0
- /package/lib/{sdk/stateful → stateful}/runtimes/settings.d.ts +0 -0
- /package/lib/{sdk/stateful → stateful}/runtimes/settings.js +0 -0
- /package/lib/{sdk/stateful → stateful}/runtimes/snapshots.d.ts +0 -0
- /package/lib/{sdk/stateful → stateful}/runtimes/snapshots.js +0 -0
- /package/lib/{sdk/stateful → stateful}/runtimes/utils.d.ts +0 -0
- /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
|
|
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 "
|
|
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
|
-
*
|
|
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
|
-
*
|
|
7
|
-
*
|
|
7
|
+
* Creates a RunResponseError from a Response object.
|
|
8
|
+
* Extracts error details from response JSON.
|
|
8
9
|
*
|
|
9
|
-
* @param response The response
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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>;
|
package/lib/api/DatalayerApi.js
CHANGED
|
@@ -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
|
-
*
|
|
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
|
-
*
|
|
14
|
-
*
|
|
20
|
+
* Creates a RunResponseError from a Response object.
|
|
21
|
+
* Extracts error details from response JSON.
|
|
15
22
|
*
|
|
16
|
-
* @param response The response
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
|
|
131
|
-
|
|
132
|
-
|
|
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
|
|
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(
|
|
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 '
|
|
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
|
-
* @
|
|
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
|
-
*
|
|
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)
|
|
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
|
-
* @
|
|
33
|
-
* This endpoint
|
|
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
|
|
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
|
-
*
|
|
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
|
-
* @
|
|
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
|
-
*
|
|
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)
|
|
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
|
-
* @
|
|
92
|
-
* This endpoint
|
|
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
|
|
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}/
|
|
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(`
|
|
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(`
|
|
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;
|
package/lib/api/iam/healthz.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { HealthzPingResponse } from '
|
|
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
|
-
* @
|
|
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
|
*
|
package/lib/api/iam/healthz.js
CHANGED
|
@@ -3,20 +3,22 @@
|
|
|
3
3
|
* Distributed under the terms of the Modified BSD License.
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
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
|
-
* @
|
|
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
|
*
|
package/lib/api/iam/index.d.ts
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
2
|
+
* IAM (Identity and Access Management) API exports.
|
|
3
|
+
*
|
|
4
|
+
* Provides organized access to authentication, OAuth2, and user profile functionality.
|
|
4
5
|
*
|
|
5
|
-
*
|
|
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
|
|
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';
|
package/lib/api/iam/index.js
CHANGED
|
@@ -3,15 +3,20 @@
|
|
|
3
3
|
* Distributed under the terms of the Modified BSD License.
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
6
|
+
* IAM (Identity and Access Management) API exports.
|
|
7
|
+
*
|
|
8
|
+
* Provides organized access to authentication, OAuth2, and user profile functionality.
|
|
8
9
|
*
|
|
9
|
-
*
|
|
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,
|
|
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>;
|