@datalayer/core 0.0.16 → 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.
Files changed (133) hide show
  1. package/README.md +9 -13
  2. package/lib/client/auth/AuthenticationManager.d.ts +95 -0
  3. package/lib/client/auth/AuthenticationManager.js +214 -0
  4. package/lib/client/auth/index.d.ts +8 -0
  5. package/lib/client/auth/index.js +17 -0
  6. package/lib/client/auth/storage.d.ts +154 -0
  7. package/lib/client/auth/storage.js +447 -0
  8. package/lib/client/auth/strategies.d.ts +54 -0
  9. package/lib/client/auth/strategies.js +238 -0
  10. package/lib/client/auth/types.d.ts +151 -0
  11. package/lib/{examples/index.js → client/auth/types.js} +4 -2
  12. package/lib/client/base.d.ts +3 -0
  13. package/lib/client/base.js +9 -0
  14. package/lib/client/index.d.ts +1 -0
  15. package/lib/client/index.js +2 -0
  16. package/lib/components/auth/Login.d.ts +40 -0
  17. package/lib/components/auth/Login.js +173 -0
  18. package/lib/components/auth/Login.stories.d.ts +54 -0
  19. package/lib/components/auth/Login.stories.js +104 -0
  20. package/lib/components/auth/LoginToken.d.ts +16 -0
  21. package/lib/components/auth/LoginToken.js +63 -0
  22. package/lib/components/auth/index.d.ts +5 -0
  23. package/lib/components/auth/index.js +16 -0
  24. package/lib/components/avatars/BoringAvatar.d.ts +6 -15
  25. package/lib/components/avatars/BoringAvatar.js +30 -34
  26. package/lib/components/avatars/BoringAvatar.stories.d.ts +7 -16
  27. package/lib/components/avatars/UserProfileAvatar.d.ts +1 -6
  28. package/lib/components/avatars/UserProfileAvatar.js +3 -8
  29. package/lib/components/buttons/DownloadCSVButton.d.ts +2 -7
  30. package/lib/components/buttons/DownloadCSVButton.js +1 -5
  31. package/lib/components/buttons/DownloadJsonButton.d.ts +3 -10
  32. package/lib/components/buttons/DownloadJsonButton.js +1 -7
  33. package/lib/components/buttons/UploadButton.d.ts +1 -4
  34. package/lib/components/buttons/UploadButton.js +3 -7
  35. package/lib/components/chat/ChatComponent.d.ts +4 -0
  36. package/lib/components/chat/ChatComponent.js +143 -0
  37. package/lib/components/chat/MessagePart.d.ts +11 -0
  38. package/lib/components/chat/MessagePart.js +23 -0
  39. package/lib/components/chat/display/DynamicToolPart.d.ts +6 -0
  40. package/lib/components/chat/display/DynamicToolPart.js +5 -0
  41. package/lib/components/chat/display/ReasoningPart.d.ts +6 -0
  42. package/lib/components/chat/display/ReasoningPart.js +58 -0
  43. package/lib/components/chat/display/TextPart.d.ts +9 -0
  44. package/lib/components/chat/display/TextPart.js +93 -0
  45. package/lib/components/chat/display/ToolPart.d.ts +6 -0
  46. package/lib/components/chat/display/ToolPart.js +148 -0
  47. package/lib/components/chat/display/index.d.ts +4 -0
  48. package/lib/components/chat/display/index.js +13 -0
  49. package/lib/components/chat/handler.d.ts +8 -0
  50. package/lib/components/chat/handler.js +43 -0
  51. package/lib/components/chat/index.d.ts +4 -0
  52. package/lib/components/chat/index.js +13 -0
  53. package/lib/components/display/CenteredSpinner.d.ts +1 -4
  54. package/lib/components/display/CenteredSpinner.js +1 -5
  55. package/lib/components/display/HorizontalCenter.d.ts +1 -4
  56. package/lib/components/display/HorizontalCenter.js +1 -5
  57. package/lib/components/flashes/FlashClosable.d.ts +1 -4
  58. package/lib/components/flashes/FlashClosable.js +1 -5
  59. package/lib/components/flashes/FlashDisclaimer.js +1 -1
  60. package/lib/components/index.d.ts +2 -1
  61. package/lib/components/index.js +2 -1
  62. package/lib/components/notebooks/JupyterNotebook.d.ts +1 -6
  63. package/lib/components/notebooks/JupyterNotebook.js +1 -5
  64. package/lib/components/runtimes/RuntimeSimplePicker.d.ts +4 -0
  65. package/lib/components/runtimes/RuntimeSimplePicker.js +3 -3
  66. package/lib/components/snapshots/RuntimeSnapshotMenu.d.ts +1 -4
  67. package/lib/components/snapshots/RuntimeSnapshotMenu.js +1 -5
  68. package/lib/config/Configuration.js +1 -1
  69. package/lib/examples/CellExample.js +11 -47
  70. package/lib/examples/lexical-theme.css +436 -0
  71. package/lib/examples/notebooks/Matplotlib.ipynb.json +1 -1
  72. package/lib/examples/notebooks/NotebookExample1.ipynb.json +1 -1
  73. package/lib/hooks/useAIJupyterChat.d.ts +36 -0
  74. package/lib/hooks/useAIJupyterChat.js +53 -0
  75. package/lib/hooks/useBackdrop.d.ts +4 -4
  76. package/lib/hooks/useBackdrop.js +5 -9
  77. package/lib/hooks/useCache.d.ts +5 -1
  78. package/lib/hooks/useCache.js +126 -58
  79. package/lib/hooks/useMobile.d.ts +1 -0
  80. package/lib/hooks/useMobile.js +26 -0
  81. package/lib/hooks/useScreenshot.d.ts +3 -5
  82. package/lib/hooks/useScreenshot.js +1 -8
  83. package/lib/hooks/useUpload.js +29 -21
  84. package/lib/index.d.ts +1 -0
  85. package/lib/index.js +8 -4
  86. package/lib/models/Outbound.d.ts +2 -0
  87. package/lib/models/Outbound.js +3 -1
  88. package/lib/state/substates/CoreState.js +1 -1
  89. package/lib/state/substates/IAMState.js +15 -6
  90. package/lib/stateful/index.d.ts +0 -1
  91. package/lib/stateful/index.js +0 -1
  92. package/lib/stateful/runtimes/actions.d.ts +1 -1
  93. package/lib/stateful/runtimes/actions.js +1 -1
  94. package/lib/theme/DatalayerTheme.d.ts +2 -2
  95. package/lib/theme/DatalayerTheme.js +4 -4
  96. package/lib/theme/DatalayerThemeProvider.js +2 -2
  97. package/lib/tools/adapters/agui/AgUIToolAdapter.d.ts +75 -0
  98. package/lib/tools/adapters/agui/AgUIToolAdapter.js +244 -0
  99. package/lib/tools/adapters/agui/index.d.ts +10 -0
  100. package/lib/tools/adapters/agui/index.js +19 -0
  101. package/lib/tools/adapters/agui/lexicalHooks.d.ts +27 -0
  102. package/lib/tools/adapters/agui/lexicalHooks.js +64 -0
  103. package/lib/tools/adapters/agui/notebookHooks.d.ts +27 -0
  104. package/lib/tools/adapters/agui/notebookHooks.js +61 -0
  105. package/lib/tools/index.d.ts +6 -0
  106. package/lib/tools/index.js +18 -0
  107. package/lib/types.d.ts +5 -0
  108. package/lib/types.js +5 -0
  109. package/lib/utils/cli/index.d.ts +4 -0
  110. package/lib/utils/cli/index.js +13 -0
  111. package/lib/utils/cli/query.d.ts +6 -0
  112. package/lib/utils/cli/query.js +26 -0
  113. package/lib/utils/index.d.ts +1 -0
  114. package/lib/utils/index.js +1 -0
  115. package/package.json +62 -5
  116. package/style/base.css +4 -0
  117. package/lib/examples/DatalayerNotebookExample.d.ts +0 -16
  118. package/lib/examples/DatalayerNotebookExample.js +0 -75
  119. package/lib/examples/NativeNavigationExample.d.ts +0 -8
  120. package/lib/examples/NativeNavigationExample.js +0 -97
  121. package/lib/examples/NotebookMutationsKernel.d.ts +0 -2
  122. package/lib/examples/NotebookMutationsKernel.js +0 -115
  123. package/lib/examples/NotebookMutationsServiceManager.d.ts +0 -2
  124. package/lib/examples/NotebookMutationsServiceManager.js +0 -107
  125. package/lib/examples/ReactRouterExample.d.ts +0 -6
  126. package/lib/examples/ReactRouterExample.js +0 -175
  127. package/lib/examples/example-selector.d.ts +0 -22
  128. package/lib/examples/example-selector.js +0 -45
  129. package/lib/examples/index.d.ts +0 -2
  130. package/lib/examples/main.d.ts +0 -1
  131. package/lib/examples/main.js +0 -153
  132. package/lib/examples/notebooks/OutputIPyWidgetsExample.d.ts +0 -145
  133. package/lib/examples/notebooks/OutputIPyWidgetsExample.js +0 -153
@@ -0,0 +1,447 @@
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
+ * Token storage backend implementations
12
+ */
13
+ import { DATALAYER_IAM_TOKEN_KEY, DATALAYER_IAM_USER_KEY, } from '../../state/storage/IAMStorage';
14
+ /**
15
+ * Browser localStorage-based token storage
16
+ */
17
+ export class BrowserStorage {
18
+ /**
19
+ * Get token from browser localStorage
20
+ */
21
+ get(key) {
22
+ if (typeof window === 'undefined') {
23
+ return null;
24
+ }
25
+ return window.localStorage.getItem(key);
26
+ }
27
+ /**
28
+ * Set token in browser localStorage
29
+ */
30
+ set(key, value) {
31
+ if (typeof window === 'undefined') {
32
+ return;
33
+ }
34
+ window.localStorage.setItem(key, value);
35
+ }
36
+ /**
37
+ * Delete token from browser localStorage
38
+ */
39
+ delete(key) {
40
+ if (typeof window === 'undefined') {
41
+ return;
42
+ }
43
+ window.localStorage.removeItem(key);
44
+ }
45
+ /**
46
+ * Check if browser localStorage is available
47
+ */
48
+ isAvailable() {
49
+ return typeof window !== 'undefined' && !!window.localStorage;
50
+ }
51
+ /**
52
+ * Get stored authentication token
53
+ */
54
+ getToken() {
55
+ return this.get(DATALAYER_IAM_TOKEN_KEY);
56
+ }
57
+ /**
58
+ * Store authentication token
59
+ */
60
+ setToken(token) {
61
+ this.set(DATALAYER_IAM_TOKEN_KEY, token);
62
+ }
63
+ /**
64
+ * Delete authentication token
65
+ */
66
+ deleteToken() {
67
+ this.delete(DATALAYER_IAM_TOKEN_KEY);
68
+ }
69
+ /**
70
+ * Get stored user data
71
+ */
72
+ getUser() {
73
+ const userData = this.get(DATALAYER_IAM_USER_KEY);
74
+ if (!userData) {
75
+ return null;
76
+ }
77
+ try {
78
+ const parsed = JSON.parse(userData);
79
+ return parsed;
80
+ }
81
+ catch (error) {
82
+ console.error('Failed to parse stored user data:', error);
83
+ return null;
84
+ }
85
+ }
86
+ /**
87
+ * Store user data
88
+ */
89
+ setUser(user) {
90
+ this.set(DATALAYER_IAM_USER_KEY, JSON.stringify(user));
91
+ }
92
+ /**
93
+ * Delete user data
94
+ */
95
+ deleteUser() {
96
+ this.delete(DATALAYER_IAM_USER_KEY);
97
+ }
98
+ /**
99
+ * Clear all authentication data
100
+ */
101
+ clear() {
102
+ this.deleteToken();
103
+ this.deleteUser();
104
+ }
105
+ }
106
+ /**
107
+ * Node.js storage with keyring support using keytar
108
+ */
109
+ export class NodeStorage {
110
+ memoryStorage = new Map();
111
+ keytar = null;
112
+ serviceUrl;
113
+ constructor(serviceUrl = 'https://prod1.datalayer.run') {
114
+ this.serviceUrl = serviceUrl;
115
+ try {
116
+ // Load keytar for system keyring access
117
+ // VS Code extensions get this from VS Code's bundled keytar
118
+ // CLI gets this from installed keytar package
119
+ this.keytar = require('keytar');
120
+ }
121
+ catch (e) {
122
+ // Keyring not available, use memory only
123
+ console.warn('keytar not available, tokens will not persist');
124
+ }
125
+ }
126
+ /**
127
+ * Get token from keyring, environment variable, or memory
128
+ * Supports both sync (getPasswordSync) and async (getPassword) keytar APIs
129
+ */
130
+ get(key) {
131
+ console.log('[NodeStorage.get] key:', key, 'keytar available:', !!this.keytar);
132
+ // 1. Try keyring first (if available)
133
+ if (this.keytar) {
134
+ try {
135
+ // Try sync API first (CLI keytar)
136
+ if (this.keytar.getPasswordSync) {
137
+ console.log('[NodeStorage.get] using keytar.getPasswordSync');
138
+ const value = this.keytar.getPasswordSync(this.serviceUrl, key);
139
+ console.log('[NodeStorage.get] keytar returned:', value ? 'token found' : 'null');
140
+ if (value)
141
+ return value;
142
+ }
143
+ else {
144
+ console.log('[NodeStorage.get] getPasswordSync not available, skipping sync keytar');
145
+ }
146
+ }
147
+ catch (e) {
148
+ console.warn('[NodeStorage.get] keytar.getPasswordSync failed:', e);
149
+ // Fall through to other methods
150
+ }
151
+ }
152
+ // 2. Try environment variables
153
+ const envValue = process.env[key];
154
+ console.log('[NodeStorage.get] env var', key, ':', envValue ? 'found' : 'not found');
155
+ if (envValue)
156
+ return envValue;
157
+ // 3. Fall back to memory storage
158
+ const memValue = this.memoryStorage.get(key) || null;
159
+ console.log('[NodeStorage.get] memory storage:', memValue ? 'found' : 'not found');
160
+ return memValue;
161
+ }
162
+ /**
163
+ * Set token in keyring or memory storage (sync version)
164
+ */
165
+ set(key, value) {
166
+ console.log('[NodeStorage.set] key:', key, 'keytar available:', !!this.keytar);
167
+ // Store in keyring if available and has sync API
168
+ if (this.keytar && this.keytar.setPasswordSync) {
169
+ try {
170
+ console.log('[NodeStorage.set] calling keytar.setPasswordSync');
171
+ this.keytar.setPasswordSync(this.serviceUrl, key, value);
172
+ console.log('[NodeStorage.set] keytar.setPasswordSync succeeded');
173
+ return;
174
+ }
175
+ catch (e) {
176
+ console.warn('[NodeStorage.set] Failed to store in keyring, using memory:', e);
177
+ }
178
+ }
179
+ else if (this.keytar) {
180
+ console.log('[NodeStorage.set] setPasswordSync not available, use setAsync() instead');
181
+ }
182
+ // Fall back to memory
183
+ console.log('[NodeStorage.set] falling back to memory storage');
184
+ this.memoryStorage.set(key, value);
185
+ }
186
+ /**
187
+ * Async version of set - supports VS Code's async keytar API
188
+ */
189
+ async setAsync(key, value) {
190
+ console.log('[NodeStorage.setAsync] key:', key, 'keytar available:', !!this.keytar);
191
+ // Store in keyring if available
192
+ if (this.keytar) {
193
+ try {
194
+ // Try async API (VS Code keytar)
195
+ if (this.keytar.setPassword) {
196
+ console.log('[NodeStorage.setAsync] calling keytar.setPassword (async)');
197
+ await this.keytar.setPassword(this.serviceUrl, key, value);
198
+ console.log('[NodeStorage.setAsync] keytar.setPassword succeeded');
199
+ // IMPORTANT: Also store in memory so synchronous get() can access it
200
+ this.memoryStorage.set(key, value);
201
+ return;
202
+ }
203
+ // Try sync API (CLI keytar)
204
+ else if (this.keytar.setPasswordSync) {
205
+ console.log('[NodeStorage.setAsync] calling keytar.setPasswordSync');
206
+ this.keytar.setPasswordSync(this.serviceUrl, key, value);
207
+ console.log('[NodeStorage.setAsync] keytar.setPasswordSync succeeded');
208
+ // Also store in memory for consistency
209
+ this.memoryStorage.set(key, value);
210
+ return;
211
+ }
212
+ }
213
+ catch (e) {
214
+ console.warn('[NodeStorage.setAsync] Failed to store in keyring, using memory:', e);
215
+ }
216
+ }
217
+ // Fall back to memory
218
+ console.log('[NodeStorage.setAsync] falling back to memory storage');
219
+ this.memoryStorage.set(key, value);
220
+ }
221
+ /**
222
+ * Async version of get - supports VS Code's async keytar API
223
+ */
224
+ async getAsync(key) {
225
+ console.log('[NodeStorage.getAsync] key:', key, 'keytar available:', !!this.keytar);
226
+ // Try keyring first (if available)
227
+ if (this.keytar) {
228
+ try {
229
+ // Try async API (VS Code keytar)
230
+ if (this.keytar.getPassword) {
231
+ console.log('[NodeStorage.getAsync] calling keytar.getPassword (async)');
232
+ const value = await this.keytar.getPassword(this.serviceUrl, key);
233
+ console.log('[NodeStorage.getAsync] keytar returned:', value ? 'token found' : 'null');
234
+ if (value)
235
+ return value;
236
+ }
237
+ // Try sync API (CLI keytar)
238
+ else if (this.keytar.getPasswordSync) {
239
+ console.log('[NodeStorage.getAsync] calling keytar.getPasswordSync');
240
+ const value = this.keytar.getPasswordSync(this.serviceUrl, key);
241
+ console.log('[NodeStorage.getAsync] keytar returned:', value ? 'token found' : 'null');
242
+ if (value)
243
+ return value;
244
+ }
245
+ }
246
+ catch (e) {
247
+ console.warn('[NodeStorage.getAsync] keytar failed:', e);
248
+ }
249
+ }
250
+ // Try environment variables
251
+ const envValue = process.env[key];
252
+ console.log('[NodeStorage.getAsync] env var', key, ':', envValue ? 'found' : 'not found');
253
+ if (envValue)
254
+ return envValue;
255
+ // Fall back to memory storage
256
+ const memValue = this.memoryStorage.get(key) || null;
257
+ console.log('[NodeStorage.getAsync] memory storage:', memValue ? 'found' : 'not found');
258
+ return memValue;
259
+ }
260
+ /**
261
+ * Delete token from keyring or memory storage (sync version)
262
+ */
263
+ delete(key) {
264
+ console.log('[NodeStorage.delete] key:', key, 'keytar available:', !!this.keytar);
265
+ if (this.keytar && this.keytar.deletePasswordSync) {
266
+ try {
267
+ console.log('[NodeStorage.delete] calling keytar.deletePasswordSync');
268
+ this.keytar.deletePasswordSync(this.serviceUrl, key);
269
+ console.log('[NodeStorage.delete] keytar.deletePasswordSync succeeded');
270
+ }
271
+ catch (e) {
272
+ console.warn('[NodeStorage.delete] Failed to delete from keyring:', e);
273
+ }
274
+ }
275
+ else if (this.keytar) {
276
+ console.log('[NodeStorage.delete] deletePasswordSync not available, use deleteAsync() instead');
277
+ }
278
+ console.log('[NodeStorage.delete] deleting from memory storage');
279
+ this.memoryStorage.delete(key);
280
+ }
281
+ /**
282
+ * Async version of delete - supports VS Code's async keytar API
283
+ */
284
+ async deleteAsync(key) {
285
+ console.log('[NodeStorage.deleteAsync] key:', key, 'keytar available:', !!this.keytar);
286
+ if (this.keytar) {
287
+ try {
288
+ // Try async API (VS Code keytar)
289
+ if (this.keytar.deletePassword) {
290
+ console.log('[NodeStorage.deleteAsync] calling keytar.deletePassword (async)');
291
+ await this.keytar.deletePassword(this.serviceUrl, key);
292
+ console.log('[NodeStorage.deleteAsync] keytar.deletePassword succeeded');
293
+ }
294
+ // Try sync API (CLI keytar)
295
+ else if (this.keytar.deletePasswordSync) {
296
+ console.log('[NodeStorage.deleteAsync] calling keytar.deletePasswordSync');
297
+ this.keytar.deletePasswordSync(this.serviceUrl, key);
298
+ console.log('[NodeStorage.deleteAsync] keytar.deletePasswordSync succeeded');
299
+ }
300
+ }
301
+ catch (e) {
302
+ console.warn('[NodeStorage.deleteAsync] Failed to delete from keyring:', e);
303
+ }
304
+ }
305
+ console.log('[NodeStorage.deleteAsync] deleting from memory storage');
306
+ this.memoryStorage.delete(key);
307
+ }
308
+ /**
309
+ * Check if Node.js environment
310
+ */
311
+ isAvailable() {
312
+ return typeof process !== 'undefined' && !!process.env;
313
+ }
314
+ /**
315
+ * Get stored authentication token (sync version)
316
+ * Checks environment variables and memory, but not async keytar
317
+ */
318
+ getToken() {
319
+ // Check DATALAYER_API_KEY first
320
+ const apiKey = process.env['DATALAYER_API_KEY'];
321
+ if (apiKey)
322
+ return apiKey;
323
+ // Use "access_token" key (sync only - won't find tokens stored via async keytar)
324
+ return this.get('access_token');
325
+ }
326
+ /**
327
+ * Get stored authentication token (async version)
328
+ * Properly checks async keytar API (VS Code), then env vars, then memory
329
+ */
330
+ async getTokenAsync() {
331
+ // Check DATALAYER_API_KEY first
332
+ const apiKey = process.env['DATALAYER_API_KEY'];
333
+ if (apiKey)
334
+ return apiKey;
335
+ // Use async method to check keyring (supports VS Code's async keytar)
336
+ return await this.getAsync('access_token');
337
+ }
338
+ /**
339
+ * Store authentication token (async version - use this in auth strategies)
340
+ */
341
+ async setToken(token) {
342
+ console.log('[NodeStorage] setToken called, keytar available:', !!this.keytar);
343
+ console.log('[NodeStorage] storing token with key: access_token, service:', this.serviceUrl);
344
+ // Use async method to support VS Code's keytar
345
+ await this.setAsync('access_token', token);
346
+ console.log('[NodeStorage] token stored successfully');
347
+ }
348
+ /**
349
+ * Delete authentication token (async version - use this in auth manager)
350
+ */
351
+ async deleteToken() {
352
+ console.log('[NodeStorage] deleteToken called');
353
+ // Use async method to support VS Code's keytar
354
+ await this.deleteAsync('access_token');
355
+ console.log('[NodeStorage] token deleted successfully');
356
+ }
357
+ /**
358
+ * Clear all authentication data (async version - use this in auth manager)
359
+ */
360
+ async clear() {
361
+ console.log('[NodeStorage] clear called');
362
+ await this.deleteToken();
363
+ this.memoryStorage.clear();
364
+ console.log('[NodeStorage] all data cleared');
365
+ }
366
+ }
367
+ /**
368
+ * Electron safeStorage-based token storage
369
+ * Falls back to BrowserStorage if Electron safeStorage is not available
370
+ */
371
+ export class ElectronStorage {
372
+ browserStorage = new BrowserStorage();
373
+ /**
374
+ * Get token from Electron safeStorage or fall back to localStorage
375
+ */
376
+ get(key) {
377
+ // TODO: Implement Electron safeStorage when running in Electron
378
+ // For now, fall back to browser storage
379
+ return this.browserStorage.get(key);
380
+ }
381
+ /**
382
+ * Set token in Electron safeStorage or fall back to localStorage
383
+ */
384
+ set(key, value) {
385
+ // TODO: Implement Electron safeStorage when running in Electron
386
+ // For now, fall back to browser storage
387
+ this.browserStorage.set(key, value);
388
+ }
389
+ /**
390
+ * Delete token from Electron safeStorage or localStorage
391
+ */
392
+ delete(key) {
393
+ // TODO: Implement Electron safeStorage when running in Electron
394
+ // For now, fall back to browser storage
395
+ this.browserStorage.delete(key);
396
+ }
397
+ /**
398
+ * Check if Electron safeStorage or browser storage is available
399
+ */
400
+ isAvailable() {
401
+ // TODO: Check for Electron safeStorage API
402
+ // For now, check browser storage
403
+ return this.browserStorage.isAvailable();
404
+ }
405
+ /**
406
+ * Get stored authentication token
407
+ */
408
+ getToken() {
409
+ return this.get(DATALAYER_IAM_TOKEN_KEY);
410
+ }
411
+ /**
412
+ * Store authentication token
413
+ */
414
+ setToken(token) {
415
+ this.set(DATALAYER_IAM_TOKEN_KEY, token);
416
+ }
417
+ /**
418
+ * Delete authentication token
419
+ */
420
+ deleteToken() {
421
+ this.delete(DATALAYER_IAM_TOKEN_KEY);
422
+ }
423
+ /**
424
+ * Clear all authentication data
425
+ */
426
+ clear() {
427
+ this.browserStorage.clear();
428
+ }
429
+ }
430
+ /**
431
+ * Get the appropriate storage backend for the current environment
432
+ */
433
+ export function getDefaultStorage() {
434
+ if (typeof window !== 'undefined') {
435
+ // Browser environment
436
+ return new BrowserStorage();
437
+ }
438
+ else if (typeof process !== 'undefined') {
439
+ // Node.js environment
440
+ return new NodeStorage();
441
+ }
442
+ else {
443
+ // Unknown environment, use in-memory storage
444
+ console.warn('Unknown environment, using in-memory storage (data will not persist)');
445
+ return new NodeStorage(); // NodeStorage has in-memory fallback
446
+ }
447
+ }
@@ -0,0 +1,54 @@
1
+ import type { AuthStrategy, AuthOptions, AuthResult, TokenStorage } from './types';
2
+ import { UserDTO } from '../../models/UserDTO';
3
+ /**
4
+ * Base authentication strategy with common functionality
5
+ */
6
+ declare abstract class BaseAuthStrategy implements AuthStrategy {
7
+ protected iamRunUrl: string;
8
+ protected storage?: TokenStorage | undefined;
9
+ constructor(iamRunUrl: string, storage?: TokenStorage | undefined);
10
+ abstract authenticate(options: AuthOptions): Promise<AuthResult>;
11
+ abstract canHandle(options: AuthOptions): boolean;
12
+ /**
13
+ * Validate a token by calling whoami
14
+ */
15
+ protected validateToken(token: string): Promise<UserDTO>;
16
+ }
17
+ /**
18
+ * Token-based authentication strategy
19
+ * Authenticates using an existing token
20
+ */
21
+ export declare class TokenAuthStrategy extends BaseAuthStrategy {
22
+ canHandle(options: AuthOptions): boolean;
23
+ authenticate(options: AuthOptions): Promise<AuthResult>;
24
+ }
25
+ /**
26
+ * Credentials-based authentication strategy
27
+ * Authenticates using handle and password
28
+ */
29
+ export declare class CredentialsAuthStrategy extends BaseAuthStrategy {
30
+ canHandle(options: AuthOptions): boolean;
31
+ authenticate(options: AuthOptions): Promise<AuthResult>;
32
+ }
33
+ /**
34
+ * Storage-based authentication strategy
35
+ * Authenticates using a token from storage
36
+ */
37
+ export declare class StorageAuthStrategy extends BaseAuthStrategy {
38
+ canHandle(options: AuthOptions): boolean;
39
+ authenticate(options: AuthOptions): Promise<AuthResult>;
40
+ }
41
+ /**
42
+ * Browser OAuth strategy
43
+ * Authenticates using browser-based OAuth flow with GitHub or LinkedIn
44
+ */
45
+ export declare class BrowserOAuthStrategy extends BaseAuthStrategy {
46
+ canHandle(options: AuthOptions): boolean;
47
+ authenticate(options: AuthOptions): Promise<AuthResult>;
48
+ /**
49
+ * Wait for OAuth callback in popup window
50
+ * Expects: { user, token, error } from the Datalayer OAuth callback
51
+ */
52
+ private waitForOAuthCallback;
53
+ }
54
+ export {};