@datalayer/core 0.0.17 → 0.0.18
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 +9 -13
- package/lib/client/auth/AuthenticationManager.d.ts +95 -0
- package/lib/client/auth/AuthenticationManager.js +214 -0
- package/lib/client/auth/index.d.ts +8 -0
- package/lib/client/auth/index.js +17 -0
- package/lib/client/auth/storage.d.ts +154 -0
- package/lib/client/auth/storage.js +447 -0
- package/lib/client/auth/strategies.d.ts +54 -0
- package/lib/client/auth/strategies.js +238 -0
- package/lib/client/auth/types.d.ts +151 -0
- package/lib/{examples/index.js → client/auth/types.js} +4 -2
- package/lib/client/base.d.ts +3 -0
- package/lib/client/base.js +9 -0
- package/lib/client/index.d.ts +1 -0
- package/lib/client/index.js +2 -0
- package/lib/components/auth/Login.d.ts +40 -0
- package/lib/components/auth/Login.js +173 -0
- package/lib/components/auth/Login.stories.d.ts +54 -0
- package/lib/components/auth/Login.stories.js +104 -0
- package/lib/components/auth/LoginToken.d.ts +16 -0
- package/lib/components/auth/LoginToken.js +63 -0
- package/lib/components/auth/index.d.ts +5 -0
- package/lib/components/auth/index.js +16 -0
- package/lib/components/avatars/BoringAvatar.d.ts +6 -15
- package/lib/components/avatars/BoringAvatar.js +30 -34
- package/lib/components/avatars/BoringAvatar.stories.d.ts +7 -16
- package/lib/components/avatars/UserProfileAvatar.d.ts +1 -6
- package/lib/components/avatars/UserProfileAvatar.js +3 -8
- package/lib/components/buttons/DownloadCSVButton.d.ts +2 -7
- package/lib/components/buttons/DownloadCSVButton.js +1 -5
- package/lib/components/buttons/DownloadJsonButton.d.ts +3 -10
- package/lib/components/buttons/DownloadJsonButton.js +1 -7
- package/lib/components/buttons/UploadButton.d.ts +1 -4
- package/lib/components/buttons/UploadButton.js +3 -7
- package/lib/components/chat/ChatComponent.js +4 -0
- package/lib/components/chat/display/ReasoningPart.js +4 -0
- package/lib/components/chat/display/ToolPart.js +4 -0
- package/lib/components/chat/display/index.js +4 -0
- package/lib/components/chat/handler.js +4 -0
- package/lib/components/chat/index.js +4 -0
- package/lib/components/display/CenteredSpinner.d.ts +1 -4
- package/lib/components/display/CenteredSpinner.js +1 -5
- package/lib/components/display/HorizontalCenter.d.ts +1 -4
- package/lib/components/display/HorizontalCenter.js +1 -5
- package/lib/components/flashes/FlashClosable.d.ts +1 -4
- package/lib/components/flashes/FlashClosable.js +1 -5
- package/lib/components/flashes/FlashDisclaimer.js +1 -1
- package/lib/components/index.d.ts +1 -0
- package/lib/components/index.js +1 -0
- package/lib/components/notebooks/JupyterNotebook.d.ts +1 -6
- package/lib/components/notebooks/JupyterNotebook.js +1 -5
- package/lib/components/snapshots/RuntimeSnapshotMenu.d.ts +1 -4
- package/lib/components/snapshots/RuntimeSnapshotMenu.js +1 -5
- package/lib/config/Configuration.js +1 -1
- package/lib/examples/CellExample.js +11 -47
- package/lib/examples/lexical-theme.css +436 -0
- package/lib/examples/notebooks/Matplotlib.ipynb.json +1 -1
- package/lib/examples/notebooks/NotebookExample1.ipynb.json +1 -1
- package/lib/hooks/useAIJupyterChat.js +4 -0
- package/lib/hooks/useBackdrop.d.ts +4 -4
- package/lib/hooks/useBackdrop.js +5 -9
- package/lib/hooks/useCache.d.ts +5 -1
- package/lib/hooks/useCache.js +27 -14
- package/lib/hooks/useMobile.js +4 -0
- package/lib/hooks/useScreenshot.d.ts +3 -5
- package/lib/hooks/useScreenshot.js +1 -8
- package/lib/models/Outbound.d.ts +2 -0
- package/lib/models/Outbound.js +3 -1
- package/lib/state/substates/CoreState.js +1 -1
- package/lib/state/substates/IAMState.js +15 -6
- package/lib/tools/adapters/agui/AgUIToolAdapter.d.ts +75 -0
- package/lib/tools/adapters/agui/AgUIToolAdapter.js +244 -0
- package/lib/tools/adapters/agui/index.d.ts +10 -0
- package/lib/tools/adapters/agui/index.js +19 -0
- package/lib/tools/adapters/agui/lexicalHooks.d.ts +27 -0
- package/lib/tools/adapters/agui/lexicalHooks.js +64 -0
- package/lib/tools/adapters/agui/notebookHooks.d.ts +27 -0
- package/lib/tools/adapters/agui/notebookHooks.js +61 -0
- package/lib/tools/index.d.ts +6 -0
- package/lib/tools/index.js +18 -0
- package/lib/types.js +2 -3
- package/lib/utils/cli/index.d.ts +4 -0
- package/lib/utils/cli/index.js +13 -0
- package/lib/utils/cli/query.d.ts +6 -0
- package/lib/utils/cli/query.js +26 -0
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/index.js +1 -0
- package/package.json +50 -7
- package/lib/examples/ChatExample.d.ts +0 -8
- package/lib/examples/ChatExample.js +0 -51
- package/lib/examples/DatalayerNotebookExample.d.ts +0 -16
- package/lib/examples/DatalayerNotebookExample.js +0 -75
- package/lib/examples/NativeNavigationExample.d.ts +0 -8
- package/lib/examples/NativeNavigationExample.js +0 -97
- package/lib/examples/NotebookMutationsKernel.d.ts +0 -2
- package/lib/examples/NotebookMutationsKernel.js +0 -115
- package/lib/examples/NotebookMutationsServiceManager.d.ts +0 -2
- package/lib/examples/NotebookMutationsServiceManager.js +0 -107
- package/lib/examples/ReactRouterExample.d.ts +0 -6
- package/lib/examples/ReactRouterExample.js +0 -175
- package/lib/examples/example-selector.d.ts +0 -22
- package/lib/examples/example-selector.js +0 -46
- package/lib/examples/index.d.ts +0 -2
- package/lib/examples/main.d.ts +0 -1
- package/lib/examples/main.js +0 -153
- package/lib/examples/notebooks/OutputIPyWidgetsExample.d.ts +0 -145
- package/lib/examples/notebooks/OutputIPyWidgetsExample.js +0 -153
package/README.md
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
**Datalayer Core**
|
|
2
|
-
|
|
3
|
-
---
|
|
4
|
-
|
|
5
1
|
[](https://datalayer.io)
|
|
6
2
|
|
|
7
3
|
[](https://github.com/sponsors/datalayer)
|
|
@@ -9,11 +5,7 @@
|
|
|
9
5
|
# Ξ Datalayer Core
|
|
10
6
|
|
|
11
7
|
<p align="center">
|
|
12
|
-
<
|
|
13
|
-
</p>
|
|
14
|
-
|
|
15
|
-
<p align="center">
|
|
16
|
-
<strong>The foundational Python SDK for the Datalayer AI Platform</strong>
|
|
8
|
+
<strong>Python and Typescript libraries for Datalayer</strong>
|
|
17
9
|
</p>
|
|
18
10
|
|
|
19
11
|
<p align="center">
|
|
@@ -21,12 +13,12 @@
|
|
|
21
13
|
<a href="https://pypi.org/project/datalayer-core/"><img src="https://img.shields.io/pypi/pyversions/datalayer-core.svg" alt="Python versions"></img></a>
|
|
22
14
|
<a href="https://github.com/datalayer/core/blob/main/LICENSE"><img src="https://img.shields.io/badge/License-BSD%203--Clause-blue.svg" alt="License"></img></a>
|
|
23
15
|
<a href="https://docs.datalayer.app/"><img src="https://img.shields.io/badge/docs-datalayer.app-blue" alt="Documentation"></img></a>
|
|
24
|
-
<a href="https://github.com/datalayer/core/actions/workflows/tests.yml"><img src="https://github.com/datalayer/core/actions/workflows/tests.yml/badge.svg" alt="Units Tests"></img></a>
|
|
16
|
+
<a href="https://github.com/datalayer/core/actions/workflows/py-tests.yml"><img src="https://github.com/datalayer/core/actions/workflows/py-tests.yml/badge.svg" alt="Units Tests"></img></a><a href="https://github.com/datalayer/core/actions/workflows/ts-tests.yml"><img src="https://github.com/datalayer/core/actions/workflows/ts-tests.yml/badge.svg" alt="Units Tests"></img></a>
|
|
25
17
|
</p>
|
|
26
18
|
|
|
27
19
|
## Overview
|
|
28
20
|
|
|
29
|
-
Datalayer Core is the foundational package that powers the [Datalayer AI Platform](https://datalayer.app/). It provides
|
|
21
|
+
Datalayer Core is the foundational package that powers the [Datalayer AI Platform](https://datalayer.app/). It provides a TypesScript and Python packages as a Command Line Interface (CLI) for AI engineers, data scientists, and researchers to seamlessly integrate scalable compute runtimes into their workflows.
|
|
30
22
|
|
|
31
23
|
This package serves as the base foundation used by many other Datalayer packages, containing core application classes, configuration, and unified APIs for authentication, runtime management, and code execution in cloud-based environments.
|
|
32
24
|
|
|
@@ -156,7 +148,7 @@ npm install
|
|
|
156
148
|
echo "VITE_DATALAYER_API_KEY=your-token-here" > .env
|
|
157
149
|
|
|
158
150
|
# Start the examples server
|
|
159
|
-
npm run
|
|
151
|
+
npm run examples
|
|
160
152
|
```
|
|
161
153
|
|
|
162
154
|
Available at http://localhost:3000/:
|
|
@@ -305,6 +297,10 @@ This project is licensed under the [BSD 3-Clause License](https://github.com/dat
|
|
|
305
297
|
---
|
|
306
298
|
|
|
307
299
|
<p align="center">
|
|
308
|
-
<
|
|
300
|
+
<img src="https://assets.datalayer.tech/datalayer-25.svg" alt="Datalayer Logo" width="200"></img>
|
|
301
|
+
</p>
|
|
302
|
+
|
|
303
|
+
<p align="center">
|
|
304
|
+
<strong>🚀 AI Agents for Data Analysis</strong><br></br>
|
|
309
305
|
<a href="https://datalayer.app/">Get started with Datalayer today!</a>
|
|
310
306
|
</p>
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core authentication manager for the Datalayer SDK
|
|
3
|
+
*/
|
|
4
|
+
import type { AuthOptions, AuthResult, TokenStorage, TokenValidationResult } from './types';
|
|
5
|
+
import { UserDTO } from '../../models/UserDTO';
|
|
6
|
+
/**
|
|
7
|
+
* Authentication Manager for Datalayer SDK
|
|
8
|
+
* Provides a unified interface for all authentication methods
|
|
9
|
+
*/
|
|
10
|
+
export declare class AuthenticationManager {
|
|
11
|
+
private strategies;
|
|
12
|
+
private storage;
|
|
13
|
+
private iamRunUrl;
|
|
14
|
+
private currentUser?;
|
|
15
|
+
private currentToken?;
|
|
16
|
+
/**
|
|
17
|
+
* Create an AuthenticationManager instance
|
|
18
|
+
* @param iamRunUrl - IAM service URL (e.g., "https://prod1.datalayer.run")
|
|
19
|
+
* @param storage - Token storage backend (optional, defaults to auto-detected)
|
|
20
|
+
*/
|
|
21
|
+
constructor(iamRunUrl: string, storage?: TokenStorage);
|
|
22
|
+
/**
|
|
23
|
+
* Login using various authentication methods
|
|
24
|
+
* Automatically selects the appropriate strategy based on options
|
|
25
|
+
*
|
|
26
|
+
* @param options - Authentication options
|
|
27
|
+
* @returns Authentication result with user and token
|
|
28
|
+
* @throws Error if authentication fails or no suitable strategy found
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* // Token-based auth
|
|
32
|
+
* const result = await auth.login({ token: 'abc123' });
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* // Credentials-based auth
|
|
36
|
+
* const result = await auth.login({
|
|
37
|
+
* handle: 'user@example.com',
|
|
38
|
+
* password: 'secret'
|
|
39
|
+
* });
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* // Storage-based auth (uses stored token)
|
|
43
|
+
* const result = await auth.login({});
|
|
44
|
+
*/
|
|
45
|
+
login(options?: AuthOptions): Promise<AuthResult>;
|
|
46
|
+
/**
|
|
47
|
+
* Logout the current user
|
|
48
|
+
* Calls the logout API and clears stored tokens
|
|
49
|
+
*/
|
|
50
|
+
logout(): Promise<void>;
|
|
51
|
+
/**
|
|
52
|
+
* Get the current user profile
|
|
53
|
+
* Uses cached user if available, otherwise fetches from API
|
|
54
|
+
*
|
|
55
|
+
* @returns Current user or null if not authenticated
|
|
56
|
+
*/
|
|
57
|
+
whoami(): Promise<UserDTO | null>;
|
|
58
|
+
/**
|
|
59
|
+
* Validate a token
|
|
60
|
+
* Checks if a token is valid by attempting to get the user profile
|
|
61
|
+
*
|
|
62
|
+
* @param token - Token to validate
|
|
63
|
+
* @returns Validation result with user if valid
|
|
64
|
+
*/
|
|
65
|
+
validateToken(token: string): Promise<TokenValidationResult>;
|
|
66
|
+
/**
|
|
67
|
+
* Get the stored token from storage
|
|
68
|
+
* @returns Stored token or null
|
|
69
|
+
*/
|
|
70
|
+
getStoredToken(): string | null;
|
|
71
|
+
/**
|
|
72
|
+
* Store a token in storage
|
|
73
|
+
* @param token - Token to store
|
|
74
|
+
*/
|
|
75
|
+
storeToken(token: string): void;
|
|
76
|
+
/**
|
|
77
|
+
* Clear the stored token
|
|
78
|
+
*/
|
|
79
|
+
clearStoredToken(): void;
|
|
80
|
+
/**
|
|
81
|
+
* Get the current cached user
|
|
82
|
+
* @returns Current user or undefined
|
|
83
|
+
*/
|
|
84
|
+
getCurrentUser(): UserDTO | undefined;
|
|
85
|
+
/**
|
|
86
|
+
* Get the current token
|
|
87
|
+
* @returns Current token or undefined
|
|
88
|
+
*/
|
|
89
|
+
getCurrentToken(): string | undefined;
|
|
90
|
+
/**
|
|
91
|
+
* Check if user is currently authenticated
|
|
92
|
+
* @returns True if user is authenticated
|
|
93
|
+
*/
|
|
94
|
+
isAuthenticated(): boolean;
|
|
95
|
+
}
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2023-2025 Datalayer, Inc.
|
|
3
|
+
* Distributed under the terms of the Modified BSD License.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Core authentication manager for the Datalayer SDK
|
|
7
|
+
*/
|
|
8
|
+
import * as authentication from '../../api/iam/authentication';
|
|
9
|
+
import { TokenAuthStrategy, CredentialsAuthStrategy, StorageAuthStrategy, BrowserOAuthStrategy, } from './strategies';
|
|
10
|
+
import { NodeStorage, BrowserStorage } from './storage';
|
|
11
|
+
/**
|
|
12
|
+
* Authentication Manager for Datalayer SDK
|
|
13
|
+
* Provides a unified interface for all authentication methods
|
|
14
|
+
*/
|
|
15
|
+
export class AuthenticationManager {
|
|
16
|
+
strategies;
|
|
17
|
+
storage;
|
|
18
|
+
iamRunUrl;
|
|
19
|
+
currentUser;
|
|
20
|
+
currentToken;
|
|
21
|
+
/**
|
|
22
|
+
* Create an AuthenticationManager instance
|
|
23
|
+
* @param iamRunUrl - IAM service URL (e.g., "https://prod1.datalayer.run")
|
|
24
|
+
* @param storage - Token storage backend (optional, defaults to auto-detected)
|
|
25
|
+
*/
|
|
26
|
+
constructor(iamRunUrl, storage) {
|
|
27
|
+
this.iamRunUrl = iamRunUrl;
|
|
28
|
+
// Extract run_url (remove /api/iam/v1 if present)
|
|
29
|
+
const runUrl = iamRunUrl.replace('/api/iam/v1', '');
|
|
30
|
+
// CRITICAL: Pass runUrl to storage for keyring compatibility
|
|
31
|
+
if (!storage) {
|
|
32
|
+
if (typeof window !== 'undefined') {
|
|
33
|
+
this.storage = new BrowserStorage();
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
this.storage = new NodeStorage(runUrl); // Pass runUrl as serviceUrl
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
this.storage = storage;
|
|
41
|
+
}
|
|
42
|
+
// Initialize strategies
|
|
43
|
+
this.strategies = [
|
|
44
|
+
new TokenAuthStrategy(this.iamRunUrl, this.storage),
|
|
45
|
+
new CredentialsAuthStrategy(this.iamRunUrl, this.storage),
|
|
46
|
+
new StorageAuthStrategy(this.iamRunUrl, this.storage),
|
|
47
|
+
new BrowserOAuthStrategy(this.iamRunUrl, this.storage),
|
|
48
|
+
];
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Login using various authentication methods
|
|
52
|
+
* Automatically selects the appropriate strategy based on options
|
|
53
|
+
*
|
|
54
|
+
* @param options - Authentication options
|
|
55
|
+
* @returns Authentication result with user and token
|
|
56
|
+
* @throws Error if authentication fails or no suitable strategy found
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* // Token-based auth
|
|
60
|
+
* const result = await auth.login({ token: 'abc123' });
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* // Credentials-based auth
|
|
64
|
+
* const result = await auth.login({
|
|
65
|
+
* handle: 'user@example.com',
|
|
66
|
+
* password: 'secret'
|
|
67
|
+
* });
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* // Storage-based auth (uses stored token)
|
|
71
|
+
* const result = await auth.login({});
|
|
72
|
+
*/
|
|
73
|
+
async login(options = {}) {
|
|
74
|
+
// Find the first strategy that can handle these options
|
|
75
|
+
const strategy = this.strategies.find(s => s.canHandle(options));
|
|
76
|
+
if (!strategy) {
|
|
77
|
+
throw new Error('No authentication strategy found for the provided options. ' +
|
|
78
|
+
'Please provide a token, credentials (handle + password), or use browser OAuth.');
|
|
79
|
+
}
|
|
80
|
+
try {
|
|
81
|
+
const result = await strategy.authenticate(options);
|
|
82
|
+
// Cache the user and token
|
|
83
|
+
this.currentUser = result.user;
|
|
84
|
+
this.currentToken = result.token;
|
|
85
|
+
return result;
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
// Clear any cached data on failure
|
|
89
|
+
this.currentUser = undefined;
|
|
90
|
+
this.currentToken = undefined;
|
|
91
|
+
throw error;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Logout the current user
|
|
96
|
+
* Calls the logout API and clears stored tokens
|
|
97
|
+
*/
|
|
98
|
+
async logout() {
|
|
99
|
+
if (this.currentToken) {
|
|
100
|
+
try {
|
|
101
|
+
await authentication.logout(this.currentToken, this.iamRunUrl);
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
console.error('Error during logout API call:', error);
|
|
105
|
+
// Continue with local cleanup even if API call fails
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
// Clear stored data
|
|
109
|
+
if (this.storage.clear) {
|
|
110
|
+
await this.storage.clear();
|
|
111
|
+
}
|
|
112
|
+
// Clear cached data
|
|
113
|
+
this.currentUser = undefined;
|
|
114
|
+
this.currentToken = undefined;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Get the current user profile
|
|
118
|
+
* Uses cached user if available, otherwise fetches from API
|
|
119
|
+
*
|
|
120
|
+
* @returns Current user or null if not authenticated
|
|
121
|
+
*/
|
|
122
|
+
async whoami() {
|
|
123
|
+
if (this.currentUser) {
|
|
124
|
+
return this.currentUser;
|
|
125
|
+
}
|
|
126
|
+
if (this.currentToken) {
|
|
127
|
+
try {
|
|
128
|
+
// Re-authenticate using the current token
|
|
129
|
+
const result = await this.login({
|
|
130
|
+
token: this.currentToken,
|
|
131
|
+
noStore: true,
|
|
132
|
+
});
|
|
133
|
+
return result.user;
|
|
134
|
+
}
|
|
135
|
+
catch (error) {
|
|
136
|
+
console.error('Failed to get user profile:', error);
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Validate a token
|
|
144
|
+
* Checks if a token is valid by attempting to get the user profile
|
|
145
|
+
*
|
|
146
|
+
* @param token - Token to validate
|
|
147
|
+
* @returns Validation result with user if valid
|
|
148
|
+
*/
|
|
149
|
+
async validateToken(token) {
|
|
150
|
+
try {
|
|
151
|
+
const result = await this.login({ token, noStore: true });
|
|
152
|
+
return {
|
|
153
|
+
valid: true,
|
|
154
|
+
user: result.user,
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
catch (error) {
|
|
158
|
+
return {
|
|
159
|
+
valid: false,
|
|
160
|
+
error: error instanceof Error ? error.message : 'Unknown error',
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Get the stored token from storage
|
|
166
|
+
* @returns Stored token or null
|
|
167
|
+
*/
|
|
168
|
+
getStoredToken() {
|
|
169
|
+
if (!this.storage.getToken) {
|
|
170
|
+
return null;
|
|
171
|
+
}
|
|
172
|
+
return this.storage.getToken();
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Store a token in storage
|
|
176
|
+
* @param token - Token to store
|
|
177
|
+
*/
|
|
178
|
+
storeToken(token) {
|
|
179
|
+
if (this.storage.setToken) {
|
|
180
|
+
this.storage.setToken(token);
|
|
181
|
+
}
|
|
182
|
+
this.currentToken = token;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Clear the stored token
|
|
186
|
+
*/
|
|
187
|
+
clearStoredToken() {
|
|
188
|
+
if (this.storage.deleteToken) {
|
|
189
|
+
this.storage.deleteToken();
|
|
190
|
+
}
|
|
191
|
+
this.currentToken = undefined;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Get the current cached user
|
|
195
|
+
* @returns Current user or undefined
|
|
196
|
+
*/
|
|
197
|
+
getCurrentUser() {
|
|
198
|
+
return this.currentUser;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Get the current token
|
|
202
|
+
* @returns Current token or undefined
|
|
203
|
+
*/
|
|
204
|
+
getCurrentToken() {
|
|
205
|
+
return this.currentToken;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Check if user is currently authenticated
|
|
209
|
+
* @returns True if user is authenticated
|
|
210
|
+
*/
|
|
211
|
+
isAuthenticated() {
|
|
212
|
+
return !!this.currentToken && !!this.currentUser;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2023-2025 Datalayer, Inc.
|
|
3
|
+
* Distributed under the terms of the Modified BSD License.
|
|
4
|
+
*/
|
|
5
|
+
/*
|
|
6
|
+
* Copyright (c) 2023-2025 Datalayer, Inc.
|
|
7
|
+
*
|
|
8
|
+
* Datalayer License
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Authentication module for Datalayer SDK
|
|
12
|
+
* Provides unified authentication interface with multiple strategies
|
|
13
|
+
*/
|
|
14
|
+
export * from './types';
|
|
15
|
+
export * from './storage';
|
|
16
|
+
export * from './strategies';
|
|
17
|
+
export * from './AuthenticationManager';
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import type { TokenStorage } from './types';
|
|
2
|
+
import { UserDTO } from '../../models/UserDTO';
|
|
3
|
+
/**
|
|
4
|
+
* Browser localStorage-based token storage
|
|
5
|
+
*/
|
|
6
|
+
export declare class BrowserStorage implements TokenStorage {
|
|
7
|
+
/**
|
|
8
|
+
* Get token from browser localStorage
|
|
9
|
+
*/
|
|
10
|
+
get(key: string): string | null;
|
|
11
|
+
/**
|
|
12
|
+
* Set token in browser localStorage
|
|
13
|
+
*/
|
|
14
|
+
set(key: string, value: string): void;
|
|
15
|
+
/**
|
|
16
|
+
* Delete token from browser localStorage
|
|
17
|
+
*/
|
|
18
|
+
delete(key: string): void;
|
|
19
|
+
/**
|
|
20
|
+
* Check if browser localStorage is available
|
|
21
|
+
*/
|
|
22
|
+
isAvailable(): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Get stored authentication token
|
|
25
|
+
*/
|
|
26
|
+
getToken(): string | null;
|
|
27
|
+
/**
|
|
28
|
+
* Store authentication token
|
|
29
|
+
*/
|
|
30
|
+
setToken(token: string): void;
|
|
31
|
+
/**
|
|
32
|
+
* Delete authentication token
|
|
33
|
+
*/
|
|
34
|
+
deleteToken(): void;
|
|
35
|
+
/**
|
|
36
|
+
* Get stored user data
|
|
37
|
+
*/
|
|
38
|
+
getUser(): UserDTO | null;
|
|
39
|
+
/**
|
|
40
|
+
* Store user data
|
|
41
|
+
*/
|
|
42
|
+
setUser(user: UserDTO): void;
|
|
43
|
+
/**
|
|
44
|
+
* Delete user data
|
|
45
|
+
*/
|
|
46
|
+
deleteUser(): void;
|
|
47
|
+
/**
|
|
48
|
+
* Clear all authentication data
|
|
49
|
+
*/
|
|
50
|
+
clear(): void;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Node.js storage with keyring support using keytar
|
|
54
|
+
*/
|
|
55
|
+
export declare class NodeStorage implements TokenStorage {
|
|
56
|
+
private memoryStorage;
|
|
57
|
+
private keytar;
|
|
58
|
+
private serviceUrl;
|
|
59
|
+
constructor(serviceUrl?: string);
|
|
60
|
+
/**
|
|
61
|
+
* Get token from keyring, environment variable, or memory
|
|
62
|
+
* Supports both sync (getPasswordSync) and async (getPassword) keytar APIs
|
|
63
|
+
*/
|
|
64
|
+
get(key: string): string | null;
|
|
65
|
+
/**
|
|
66
|
+
* Set token in keyring or memory storage (sync version)
|
|
67
|
+
*/
|
|
68
|
+
set(key: string, value: string): void;
|
|
69
|
+
/**
|
|
70
|
+
* Async version of set - supports VS Code's async keytar API
|
|
71
|
+
*/
|
|
72
|
+
setAsync(key: string, value: string): Promise<void>;
|
|
73
|
+
/**
|
|
74
|
+
* Async version of get - supports VS Code's async keytar API
|
|
75
|
+
*/
|
|
76
|
+
getAsync(key: string): Promise<string | null>;
|
|
77
|
+
/**
|
|
78
|
+
* Delete token from keyring or memory storage (sync version)
|
|
79
|
+
*/
|
|
80
|
+
delete(key: string): void;
|
|
81
|
+
/**
|
|
82
|
+
* Async version of delete - supports VS Code's async keytar API
|
|
83
|
+
*/
|
|
84
|
+
deleteAsync(key: string): Promise<void>;
|
|
85
|
+
/**
|
|
86
|
+
* Check if Node.js environment
|
|
87
|
+
*/
|
|
88
|
+
isAvailable(): boolean;
|
|
89
|
+
/**
|
|
90
|
+
* Get stored authentication token (sync version)
|
|
91
|
+
* Checks environment variables and memory, but not async keytar
|
|
92
|
+
*/
|
|
93
|
+
getToken(): string | null;
|
|
94
|
+
/**
|
|
95
|
+
* Get stored authentication token (async version)
|
|
96
|
+
* Properly checks async keytar API (VS Code), then env vars, then memory
|
|
97
|
+
*/
|
|
98
|
+
getTokenAsync(): Promise<string | null>;
|
|
99
|
+
/**
|
|
100
|
+
* Store authentication token (async version - use this in auth strategies)
|
|
101
|
+
*/
|
|
102
|
+
setToken(token: string): Promise<void>;
|
|
103
|
+
/**
|
|
104
|
+
* Delete authentication token (async version - use this in auth manager)
|
|
105
|
+
*/
|
|
106
|
+
deleteToken(): Promise<void>;
|
|
107
|
+
/**
|
|
108
|
+
* Clear all authentication data (async version - use this in auth manager)
|
|
109
|
+
*/
|
|
110
|
+
clear(): Promise<void>;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Electron safeStorage-based token storage
|
|
114
|
+
* Falls back to BrowserStorage if Electron safeStorage is not available
|
|
115
|
+
*/
|
|
116
|
+
export declare class ElectronStorage implements TokenStorage {
|
|
117
|
+
private browserStorage;
|
|
118
|
+
/**
|
|
119
|
+
* Get token from Electron safeStorage or fall back to localStorage
|
|
120
|
+
*/
|
|
121
|
+
get(key: string): string | null;
|
|
122
|
+
/**
|
|
123
|
+
* Set token in Electron safeStorage or fall back to localStorage
|
|
124
|
+
*/
|
|
125
|
+
set(key: string, value: string): void;
|
|
126
|
+
/**
|
|
127
|
+
* Delete token from Electron safeStorage or localStorage
|
|
128
|
+
*/
|
|
129
|
+
delete(key: string): void;
|
|
130
|
+
/**
|
|
131
|
+
* Check if Electron safeStorage or browser storage is available
|
|
132
|
+
*/
|
|
133
|
+
isAvailable(): boolean;
|
|
134
|
+
/**
|
|
135
|
+
* Get stored authentication token
|
|
136
|
+
*/
|
|
137
|
+
getToken(): string | null;
|
|
138
|
+
/**
|
|
139
|
+
* Store authentication token
|
|
140
|
+
*/
|
|
141
|
+
setToken(token: string): void;
|
|
142
|
+
/**
|
|
143
|
+
* Delete authentication token
|
|
144
|
+
*/
|
|
145
|
+
deleteToken(): void;
|
|
146
|
+
/**
|
|
147
|
+
* Clear all authentication data
|
|
148
|
+
*/
|
|
149
|
+
clear(): void;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Get the appropriate storage backend for the current environment
|
|
153
|
+
*/
|
|
154
|
+
export declare function getDefaultStorage(): TokenStorage;
|