@datalayer/core 0.0.12 → 0.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (249) hide show
  1. package/README.md +2 -2
  2. package/lib/api/DatalayerApi.d.ts +38 -26
  3. package/lib/api/DatalayerApi.js +52 -13
  4. package/lib/api/iam/authentication.d.ts +9 -8
  5. package/lib/api/iam/authentication.js +14 -15
  6. package/lib/api/iam/healthz.d.ts +3 -2
  7. package/lib/api/iam/healthz.js +5 -3
  8. package/lib/api/iam/index.d.ts +9 -4
  9. package/lib/api/iam/index.js +9 -4
  10. package/lib/api/iam/oauth2.d.ts +115 -0
  11. package/lib/api/iam/oauth2.js +309 -0
  12. package/lib/api/iam/profile.d.ts +8 -1
  13. package/lib/api/iam/profile.js +17 -2
  14. package/lib/api/iam/usage.d.ts +18 -0
  15. package/lib/api/iam/usage.js +39 -0
  16. package/lib/api/index.d.ts +6 -6
  17. package/lib/api/index.js +6 -7
  18. package/lib/api/runtimes/environments.d.ts +2 -2
  19. package/lib/api/runtimes/environments.js +3 -2
  20. package/lib/api/runtimes/healthz.d.ts +3 -13
  21. package/lib/api/runtimes/healthz.js +4 -3
  22. package/lib/api/runtimes/index.d.ts +3 -2
  23. package/lib/api/runtimes/index.js +3 -2
  24. package/lib/api/runtimes/runtimes.d.ts +4 -4
  25. package/lib/api/runtimes/runtimes.js +17 -6
  26. package/lib/api/runtimes/snapshots.d.ts +4 -4
  27. package/lib/api/runtimes/snapshots.js +3 -2
  28. package/lib/api/spacer/documents.d.ts +12 -0
  29. package/lib/api/spacer/documents.js +43 -0
  30. package/lib/api/spacer/healthz.d.ts +3 -13
  31. package/lib/api/spacer/healthz.js +4 -3
  32. package/lib/api/spacer/index.d.ts +4 -2
  33. package/lib/api/spacer/index.js +4 -2
  34. package/lib/api/spacer/items.d.ts +9 -1
  35. package/lib/api/spacer/items.js +17 -2
  36. package/lib/api/spacer/lexicals.d.ts +1 -1
  37. package/lib/api/spacer/lexicals.js +3 -2
  38. package/lib/api/spacer/notebooks.d.ts +1 -1
  39. package/lib/api/spacer/notebooks.js +3 -2
  40. package/lib/api/spacer/spaces.d.ts +1 -1
  41. package/lib/api/spacer/spaces.js +3 -2
  42. package/lib/api/spacer/users.d.ts +1 -1
  43. package/lib/api/spacer/users.js +3 -2
  44. package/lib/api/utils/validation.d.ts +24 -1
  45. package/lib/api/utils/validation.js +62 -1
  46. package/lib/client/base.d.ts +75 -0
  47. package/lib/client/base.js +199 -0
  48. package/lib/client/constants.d.ts +22 -0
  49. package/lib/client/constants.js +22 -0
  50. package/lib/client/index.d.ts +108 -0
  51. package/lib/client/index.js +79 -0
  52. package/lib/client/mixins/IAMMixin.d.ts +54 -0
  53. package/lib/client/mixins/IAMMixin.js +181 -0
  54. package/lib/client/mixins/RuntimesMixin.d.ts +93 -0
  55. package/lib/client/mixins/RuntimesMixin.js +229 -0
  56. package/lib/client/mixins/SpacerMixin.d.ts +111 -0
  57. package/lib/client/mixins/SpacerMixin.js +340 -0
  58. package/lib/client/utils/mixins.d.ts +12 -0
  59. package/lib/{sdk/client → client}/utils/mixins.js +0 -28
  60. package/lib/client/utils/spacerUtils.d.ts +18 -0
  61. package/lib/client/utils/spacerUtils.js +32 -0
  62. package/lib/collaboration/DatalayerCollaboration.d.ts +6 -1
  63. package/lib/collaboration/DatalayerCollaboration.js +2 -2
  64. package/lib/collaboration/DatalayerCollaborationProvider.d.ts +5 -0
  65. package/lib/collaboration/DatalayerCollaborationProvider.js +10 -9
  66. package/lib/components/progress/CreditsIndicator.d.ts +1 -1
  67. package/lib/components/runtimes/RuntimeCellVariablesDialog.js +1 -1
  68. package/lib/components/runtimes/RuntimeLauncherDialog.d.ts +1 -1
  69. package/lib/components/runtimes/RuntimeLauncherDialog.js +2 -2
  70. package/lib/components/runtimes/RuntimePickerBase.d.ts +1 -1
  71. package/lib/components/runtimes/RuntimePickerBase.js +1 -1
  72. package/lib/components/runtimes/RuntimePickerCell.js +3 -3
  73. package/lib/components/runtimes/RuntimePickerNotebook.d.ts +1 -1
  74. package/lib/components/runtimes/RuntimePickerNotebook.js +2 -2
  75. package/lib/components/runtimes/RuntimeTransfer.d.ts +2 -2
  76. package/lib/components/runtimes/RuntimeUtils.d.ts +1 -1
  77. package/lib/components/snapshots/RuntimeSnapshotMenu.d.ts +1 -1
  78. package/lib/components/snapshots/RuntimeSnapshotMenu.js +27 -20
  79. package/lib/config/Configuration.d.ts +8 -0
  80. package/lib/hooks/useDatalayer.js +1 -1
  81. package/lib/hooks/useRuntimes.js +1 -1
  82. package/lib/hooks/useToast.js +1 -1
  83. package/lib/index.d.ts +2 -3
  84. package/lib/index.js +4 -3
  85. package/lib/models/Common.d.ts +64 -0
  86. package/lib/models/CreditsDTO.d.ts +124 -0
  87. package/lib/models/CreditsDTO.js +135 -0
  88. package/lib/models/Environment.d.ts +1 -1
  89. package/lib/models/EnvironmentDTO.d.ts +125 -0
  90. package/lib/models/EnvironmentDTO.js +88 -0
  91. package/lib/models/HealthCheck.d.ts +72 -0
  92. package/lib/models/HealthCheck.js +107 -0
  93. package/lib/{api/types/iam.d.ts → models/IAM.d.ts} +15 -78
  94. package/lib/models/ItemDTO.d.ts +74 -0
  95. package/lib/models/ItemDTO.js +186 -0
  96. package/lib/models/LexicalDTO.d.ts +155 -0
  97. package/lib/models/LexicalDTO.js +157 -0
  98. package/lib/models/NotebookDTO.d.ts +96 -0
  99. package/lib/models/NotebookDTO.js +153 -0
  100. package/lib/models/Profile.d.ts +65 -0
  101. package/lib/models/RuntimeDTO.d.ts +191 -0
  102. package/lib/models/RuntimeDTO.js +204 -0
  103. package/lib/models/RuntimeSnapshotDTO.d.ts +173 -0
  104. package/lib/models/RuntimeSnapshotDTO.js +139 -0
  105. package/lib/models/SpaceDTO.d.ts +280 -0
  106. package/lib/models/SpaceDTO.js +239 -0
  107. package/lib/models/UserDTO.d.ts +86 -0
  108. package/lib/models/UserDTO.js +84 -0
  109. package/lib/models/index.d.ts +45 -4
  110. package/lib/models/index.js +45 -4
  111. package/lib/sdk/index.d.ts +5 -4
  112. package/lib/sdk/index.js +6 -5
  113. package/lib/services/DatalayerServiceManager.js +1 -1
  114. package/lib/state/substates/CoreState.js +2 -0
  115. package/lib/state/substates/RuntimesState.d.ts +1 -1
  116. package/lib/state/substates/RuntimesState.js +1 -1
  117. package/lib/{sdk/stateful → stateful}/index.d.ts +1 -1
  118. package/lib/{sdk/stateful → stateful}/index.js +1 -1
  119. package/lib/{sdk/stateful → stateful}/jupyter/exec/Snippets.d.ts +1 -41
  120. package/lib/{sdk/stateful → stateful}/jupyter/exec/Snippets.js +1 -20
  121. package/lib/{sdk/stateful → stateful}/runtimes/actions.d.ts +3 -3
  122. package/lib/{sdk/stateful → stateful}/runtimes/actions.js +8 -8
  123. package/lib/{sdk/stateful → stateful}/runtimes/apis.d.ts +8 -8
  124. package/package.json +13 -10
  125. package/lib/__tests__/hooks.test.d.ts +0 -1
  126. package/lib/__tests__/hooks.test.js +0 -19
  127. package/lib/__tests__/index.test.d.ts +0 -1
  128. package/lib/__tests__/index.test.js +0 -27
  129. package/lib/__tests__/integration.test.d.ts +0 -1
  130. package/lib/__tests__/integration.test.js +0 -57
  131. package/lib/__tests__/shared/cleanup-shared.d.ts +0 -4
  132. package/lib/__tests__/shared/cleanup-shared.js +0 -228
  133. package/lib/__tests__/shared/test-config.d.ts +0 -51
  134. package/lib/__tests__/shared/test-config.js +0 -110
  135. package/lib/__tests__/shared/test-constants.d.ts +0 -66
  136. package/lib/__tests__/shared/test-constants.js +0 -79
  137. package/lib/__tests__/utils.test.d.ts +0 -1
  138. package/lib/__tests__/utils.test.js +0 -59
  139. package/lib/api/__tests__/iam.authentication.integration.test.d.ts +0 -1
  140. package/lib/api/__tests__/iam.authentication.integration.test.js +0 -247
  141. package/lib/api/__tests__/iam.healthz.integration.test.d.ts +0 -1
  142. package/lib/api/__tests__/iam.healthz.integration.test.js +0 -63
  143. package/lib/api/__tests__/iam.profile.integration.test.d.ts +0 -1
  144. package/lib/api/__tests__/iam.profile.integration.test.js +0 -252
  145. package/lib/api/__tests__/runtimes.environments.integration.test.d.ts +0 -1
  146. package/lib/api/__tests__/runtimes.environments.integration.test.js +0 -122
  147. package/lib/api/__tests__/runtimes.healthz.integration.test.d.ts +0 -1
  148. package/lib/api/__tests__/runtimes.healthz.integration.test.js +0 -50
  149. package/lib/api/__tests__/runtimes.integration.test.d.ts +0 -1
  150. package/lib/api/__tests__/runtimes.integration.test.js +0 -369
  151. package/lib/api/__tests__/spacer.healthz.integration.test.d.ts +0 -1
  152. package/lib/api/__tests__/spacer.healthz.integration.test.js +0 -50
  153. package/lib/api/__tests__/spacer.integration.test.d.ts +0 -1
  154. package/lib/api/__tests__/spacer.integration.test.js +0 -519
  155. package/lib/api/iam/__tests__/authentication.unit.test.d.ts +0 -1
  156. package/lib/api/iam/__tests__/authentication.unit.test.js +0 -63
  157. package/lib/api/iam/__tests__/healthz.unit.test.d.ts +0 -1
  158. package/lib/api/iam/__tests__/healthz.unit.test.js +0 -60
  159. package/lib/api/iam/__tests__/profile.unit.test.d.ts +0 -1
  160. package/lib/api/iam/__tests__/profile.unit.test.js +0 -57
  161. package/lib/api/runtimes/__tests__/environments.unit.test.d.ts +0 -1
  162. package/lib/api/runtimes/__tests__/environments.unit.test.js +0 -77
  163. package/lib/api/runtimes/__tests__/healthz.unit.test.d.ts +0 -1
  164. package/lib/api/runtimes/__tests__/healthz.unit.test.js +0 -57
  165. package/lib/api/runtimes/__tests__/runtimes.unit.test.d.ts +0 -1
  166. package/lib/api/runtimes/__tests__/runtimes.unit.test.js +0 -139
  167. package/lib/api/runtimes/__tests__/snapshots.unit.test.d.ts +0 -1
  168. package/lib/api/runtimes/__tests__/snapshots.unit.test.js +0 -96
  169. package/lib/api/spacer/__tests__/healthz.unit.test.d.ts +0 -1
  170. package/lib/api/spacer/__tests__/healthz.unit.test.js +0 -57
  171. package/lib/api/spacer/__tests__/items.unit.test.d.ts +0 -1
  172. package/lib/api/spacer/__tests__/items.unit.test.js +0 -165
  173. package/lib/api/spacer/__tests__/lexicals.unit.test.d.ts +0 -1
  174. package/lib/api/spacer/__tests__/lexicals.unit.test.js +0 -323
  175. package/lib/api/spacer/__tests__/notebooks.unit.test.d.ts +0 -1
  176. package/lib/api/spacer/__tests__/notebooks.unit.test.js +0 -224
  177. package/lib/api/spacer/__tests__/users.unit.test.d.ts +0 -1
  178. package/lib/api/spacer/__tests__/users.unit.test.js +0 -132
  179. package/lib/api/types/index.d.ts +0 -32
  180. package/lib/api/types/index.js +0 -36
  181. package/lib/api/types/runtimes.d.ts +0 -235
  182. package/lib/api/types/spacer.d.ts +0 -271
  183. package/lib/api/types/spacer.js +0 -5
  184. package/lib/api/utils/__tests__/validation.test.d.ts +0 -1
  185. package/lib/api/utils/__tests__/validation.test.js +0 -109
  186. package/lib/sdk/client/__tests__/sdk.health.integration.test.d.ts +0 -1
  187. package/lib/sdk/client/__tests__/sdk.health.integration.test.js +0 -110
  188. package/lib/sdk/client/__tests__/sdk.iam.integration.test.d.ts +0 -1
  189. package/lib/sdk/client/__tests__/sdk.iam.integration.test.js +0 -179
  190. package/lib/sdk/client/__tests__/sdk.models.integration.test.d.ts +0 -1
  191. package/lib/sdk/client/__tests__/sdk.models.integration.test.js +0 -376
  192. package/lib/sdk/client/__tests__/sdk.runtimes.integration.test.d.ts +0 -1
  193. package/lib/sdk/client/__tests__/sdk.runtimes.integration.test.js +0 -276
  194. package/lib/sdk/client/__tests__/sdk.spacer.integration.test.d.ts +0 -1
  195. package/lib/sdk/client/__tests__/sdk.spacer.integration.test.js +0 -361
  196. package/lib/sdk/client/base.d.ts +0 -88
  197. package/lib/sdk/client/base.js +0 -112
  198. package/lib/sdk/client/index.d.ts +0 -192
  199. package/lib/sdk/client/index.js +0 -128
  200. package/lib/sdk/client/mixins/HealthMixin.d.ts +0 -100
  201. package/lib/sdk/client/mixins/HealthMixin.js +0 -133
  202. package/lib/sdk/client/mixins/IAMMixin.d.ts +0 -59
  203. package/lib/sdk/client/mixins/IAMMixin.js +0 -83
  204. package/lib/sdk/client/mixins/RuntimesMixin.d.ts +0 -134
  205. package/lib/sdk/client/mixins/RuntimesMixin.js +0 -221
  206. package/lib/sdk/client/mixins/SpacerMixin.d.ts +0 -184
  207. package/lib/sdk/client/mixins/SpacerMixin.js +0 -278
  208. package/lib/sdk/client/models/Lexical.d.ts +0 -156
  209. package/lib/sdk/client/models/Lexical.js +0 -275
  210. package/lib/sdk/client/models/Notebook.d.ts +0 -174
  211. package/lib/sdk/client/models/Notebook.js +0 -311
  212. package/lib/sdk/client/models/Runtime.d.ts +0 -221
  213. package/lib/sdk/client/models/Runtime.js +0 -341
  214. package/lib/sdk/client/models/Snapshot.d.ts +0 -156
  215. package/lib/sdk/client/models/Snapshot.js +0 -244
  216. package/lib/sdk/client/models/Space.d.ts +0 -182
  217. package/lib/sdk/client/models/Space.js +0 -276
  218. package/lib/sdk/client/models/__tests__/Lexical.test.d.ts +0 -1
  219. package/lib/sdk/client/models/__tests__/Lexical.test.js +0 -288
  220. package/lib/sdk/client/models/__tests__/Notebook.test.d.ts +0 -1
  221. package/lib/sdk/client/models/__tests__/Notebook.test.js +0 -206
  222. package/lib/sdk/client/models/__tests__/Runtime.test.d.ts +0 -1
  223. package/lib/sdk/client/models/__tests__/Runtime.test.js +0 -133
  224. package/lib/sdk/client/models/__tests__/Snapshot.test.d.ts +0 -1
  225. package/lib/sdk/client/models/__tests__/Snapshot.test.js +0 -244
  226. package/lib/sdk/client/models/__tests__/Space.test.d.ts +0 -1
  227. package/lib/sdk/client/models/__tests__/Space.test.js +0 -334
  228. package/lib/sdk/client/models/index.d.ts +0 -30
  229. package/lib/sdk/client/models/index.js +0 -30
  230. package/lib/sdk/client/utils/mixins.d.ts +0 -42
  231. /package/lib/{api/types/iam.js → models/Common.js} +0 -0
  232. /package/lib/{api/types/runtimes.js → models/IAM.js} +0 -0
  233. /package/lib/{sdk/stateful → stateful}/jupyter/exec/Python.d.ts +0 -0
  234. /package/lib/{sdk/stateful → stateful}/jupyter/exec/Python.js +0 -0
  235. /package/lib/{sdk/stateful → stateful}/jupyter/exec/index.d.ts +0 -0
  236. /package/lib/{sdk/stateful → stateful}/jupyter/exec/index.js +0 -0
  237. /package/lib/{sdk/stateful → stateful}/jupyter/index.d.ts +0 -0
  238. /package/lib/{sdk/stateful → stateful}/jupyter/index.js +0 -0
  239. /package/lib/{sdk/stateful → stateful}/jupyter/kernelsHandler.d.ts +0 -0
  240. /package/lib/{sdk/stateful → stateful}/jupyter/kernelsHandler.js +0 -0
  241. /package/lib/{sdk/stateful → stateful}/runtimes/apis.js +0 -0
  242. /package/lib/{sdk/stateful → stateful}/runtimes/index.d.ts +0 -0
  243. /package/lib/{sdk/stateful → stateful}/runtimes/index.js +0 -0
  244. /package/lib/{sdk/stateful → stateful}/runtimes/settings.d.ts +0 -0
  245. /package/lib/{sdk/stateful → stateful}/runtimes/settings.js +0 -0
  246. /package/lib/{sdk/stateful → stateful}/runtimes/snapshots.d.ts +0 -0
  247. /package/lib/{sdk/stateful → stateful}/runtimes/snapshots.js +0 -0
  248. /package/lib/{sdk/stateful → stateful}/runtimes/utils.d.ts +0 -0
  249. /package/lib/{sdk/stateful → stateful}/runtimes/utils.js +0 -0
@@ -1,247 +0,0 @@
1
- /*
2
- * Copyright (c) 2023-2025 Datalayer, Inc.
3
- * Distributed under the terms of the Modified BSD License.
4
- */
5
- import { describe, it, expect, beforeAll } from 'vitest';
6
- import { authentication } from '../iam';
7
- import { testConfig, debugLog, skipIfNoToken, } from '../../__tests__/shared/test-config';
8
- let DATALAYER_TOKEN;
9
- let SESSION_TOKEN;
10
- let BASE_URL;
11
- // Skip all tests if no token is available
12
- const skipTests = skipIfNoToken();
13
- beforeAll(async () => {
14
- if (skipTests) {
15
- console.log('WARNING: Skipping IAM integration tests: No Datalayer API token configured');
16
- console.log(' Set DATALAYER_API_TOKEN env var or DATALAYER_TEST_TOKEN in .env.test');
17
- return;
18
- }
19
- // Get token and base URL from test config
20
- DATALAYER_TOKEN = testConfig.getToken();
21
- BASE_URL = testConfig.getBaseUrl('IAM');
22
- debugLog('Test configuration loaded');
23
- debugLog('Base URL:', BASE_URL);
24
- debugLog('Token available:', !!DATALAYER_TOKEN);
25
- // Login to get a session token for testing
26
- try {
27
- const loginResponse = await authentication.login({
28
- token: DATALAYER_TOKEN,
29
- }, BASE_URL);
30
- SESSION_TOKEN = loginResponse.token;
31
- debugLog('Got session token for testing');
32
- }
33
- catch (error) {
34
- console.error('Failed to get session token:', error);
35
- // Fall back to using the DATALAYER_TOKEN
36
- SESSION_TOKEN = DATALAYER_TOKEN;
37
- }
38
- });
39
- describe.skipIf(skipTests)('IAM Authentication Integration Tests', () => {
40
- describe('login', () => {
41
- it('should successfully login with valid token (expecting 201 status)', async () => {
42
- console.log('Testing login with valid token (expecting 201 Created)...');
43
- // The API should return 201 Created for successful login
44
- const response = await authentication.login({
45
- token: DATALAYER_TOKEN,
46
- }, BASE_URL);
47
- console.log('Login response:', JSON.stringify(response, null, 2));
48
- // Verify response structure for successful login (201 status)
49
- expect(response).toBeDefined();
50
- expect(response.success).toBe(true);
51
- expect(response.message).toBeDefined();
52
- // The message should indicate login success
53
- expect(response.message.toLowerCase()).toContain('success');
54
- expect(response.token).toBeDefined();
55
- expect(typeof response.token).toBe('string');
56
- expect(response.user).toBeDefined();
57
- expect(response.user.id).toBeDefined();
58
- expect(response.user.uid).toBeDefined();
59
- expect(response.user.email_s).toBeDefined();
60
- expect(response.user.handle_s).toBeDefined();
61
- console.log('Token login successful (201 Created expected)');
62
- console.log('Success:', response.success);
63
- console.log('Message:', response.message);
64
- console.log('User ID:', response.user.id);
65
- console.log('User UID:', response.user.uid);
66
- console.log('User handle:', response.user.handle_s);
67
- console.log('User email:', response.user.email_s);
68
- });
69
- it('should successfully login with valid token using default URL', async () => {
70
- console.log('Testing login with valid token using default URL...');
71
- const response = await authentication.login({
72
- token: DATALAYER_TOKEN,
73
- });
74
- console.log('Login response with default URL:', JSON.stringify(response, null, 2));
75
- // Verify response structure
76
- expect(response).toBeDefined();
77
- expect(response.success).toBe(true);
78
- expect(response.message).toBeDefined();
79
- expect(response.token).toBeDefined();
80
- expect(typeof response.token).toBe('string');
81
- expect(response.user).toBeDefined();
82
- expect(response.user.id).toBeDefined();
83
- expect(response.user.uid).toBeDefined();
84
- expect(response.user.email_s).toBeDefined();
85
- expect(response.user.handle_s).toBeDefined();
86
- console.log('Token login successful with default URL');
87
- console.log('Success:', response.success);
88
- console.log('Message:', response.message);
89
- console.log('User ID:', response.user.id);
90
- console.log('User UID:', response.user.uid);
91
- console.log('User handle:', response.user.handle_s);
92
- console.log('User email:', response.user.email_s);
93
- });
94
- it('should fail when providing invalid token (expecting 401 status)', async () => {
95
- console.log('Testing login with invalid token (expecting 401 Unauthorized)...');
96
- const invalidToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJpbnZhbGlkIiwiaWF0IjoxNTE2MjM5MDIyfQ.invalid_signature_here';
97
- try {
98
- const response = await authentication.login({
99
- token: invalidToken,
100
- }, BASE_URL);
101
- console.log('Response for invalid token:', JSON.stringify(response, null, 2));
102
- // If we get a response without error, check if it indicates failure
103
- if (response.success === false) {
104
- console.log('Login failed as expected (success: false)');
105
- expect(response.success).toBe(false);
106
- expect(response.message).toBeDefined();
107
- expect(response.message.toLowerCase()).toContain('fail');
108
- console.log(' Error message:', response.message);
109
- }
110
- else {
111
- // If success is true for invalid token, that's unexpected
112
- throw new Error('Expected API to reject invalid token with 401');
113
- }
114
- }
115
- catch (error) {
116
- // The API should throw with 401 Unauthorized for invalid credentials
117
- console.log('API correctly rejected invalid token with error:', error.message);
118
- expect(error).toBeDefined();
119
- expect(error.message).toBeDefined();
120
- // Check for expected error patterns (401 or server error)
121
- const isExpectedError = error.message.includes('401') ||
122
- error.message.includes('Unauthorized') ||
123
- error.message.includes('Invalid') ||
124
- error.message.includes('Login failed') ||
125
- error.message.includes('Server Error') ||
126
- error.message.includes('500');
127
- expect(isExpectedError).toBe(true);
128
- // Log the actual status for debugging
129
- if (error.response?.status === 401) {
130
- console.log('Correctly received 401 Unauthorized status');
131
- }
132
- else if (error.response?.status === 500) {
133
- console.log('Received 500 Server Error (token might have invalid format)');
134
- }
135
- }
136
- });
137
- });
138
- describe('proxyAuth', () => {
139
- it('should successfully validate authentication with valid token', async () => {
140
- console.log('Testing /proxy-auth endpoint with valid token...');
141
- try {
142
- await authentication.proxyAuth(SESSION_TOKEN, BASE_URL);
143
- console.log('Successfully validated authentication through proxy');
144
- }
145
- catch (error) {
146
- console.log('Proxy auth validation result:', error.message);
147
- // The endpoint might not exist yet or might require specific proxy setup
148
- // We'll accept either success or specific error responses
149
- expect(error.message.includes('404') || // Endpoint might not exist
150
- error.message.includes('401') || // Unauthorized
151
- error.message.includes('403') || // Forbidden
152
- error.message.includes('proxy')).toBe(true);
153
- }
154
- });
155
- it('should fail with 401 when using invalid token', async () => {
156
- console.log('Testing /proxy-auth endpoint with invalid token...');
157
- const invalidToken = 'invalid.token.here';
158
- try {
159
- await authentication.proxyAuth(invalidToken, BASE_URL);
160
- // If we reach here, the endpoint accepted invalid token (shouldn't happen)
161
- throw new Error('Expected proxy auth to reject invalid token');
162
- }
163
- catch (error) {
164
- console.log('Proxy auth correctly rejected invalid token:', error.message);
165
- expect(error).toBeDefined();
166
- // Should get 401 Unauthorized or similar error
167
- expect(error.message.includes('401') ||
168
- error.message.includes('Unauthorized') ||
169
- error.message.includes('Invalid') ||
170
- error.message.includes('404')).toBe(true);
171
- }
172
- });
173
- it('should require token parameter', async () => {
174
- console.log('Testing /proxy-auth endpoint without token...');
175
- try {
176
- // @ts-expect-error Testing missing required parameter
177
- await authentication.proxyAuth();
178
- throw new Error('Expected function to throw for missing token');
179
- }
180
- catch (error) {
181
- console.log('Correctly rejected request without token:', error.message);
182
- expect(error.message).toBe('Authentication token is required');
183
- }
184
- });
185
- });
186
- describe('logout', () => {
187
- // NOTE: The logout endpoint appears to return 405 Method Not Allowed
188
- // This might indicate the endpoint doesn't exist or uses a different HTTP method
189
- // Commenting out these tests until we can verify the correct API specification
190
- it.skip('should successfully logout with valid token', async () => {
191
- console.log('Testing logout with valid token...');
192
- // First login to get a fresh token
193
- const loginResponse = await authentication.login({
194
- token: DATALAYER_TOKEN,
195
- });
196
- expect(loginResponse.success).toBe(true);
197
- const sessionToken = loginResponse.token;
198
- console.log('Login successful, got session token');
199
- // Now test logout with the session token
200
- await expect(authentication.logout(sessionToken, BASE_URL)).resolves.toBeUndefined();
201
- console.log('Logout successful');
202
- });
203
- it.skip('should successfully logout using default URL', async () => {
204
- console.log('Testing logout with valid token using default URL...');
205
- // First login to get a fresh token
206
- const loginResponse = await authentication.login({
207
- token: DATALAYER_TOKEN,
208
- });
209
- expect(loginResponse.success).toBe(true);
210
- const sessionToken = loginResponse.token;
211
- console.log('Login successful with default URL, got session token');
212
- // Now test logout with the session token using default URL
213
- await expect(authentication.logout(sessionToken)).resolves.toBeUndefined();
214
- console.log('Logout successful with default URL');
215
- });
216
- it('should handle logout with invalid token', async () => {
217
- console.log('Testing logout with invalid token...');
218
- const invalidToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJpbnZhbGlkIiwiaWF0IjoxNTE2MjM5MDIyfQ.invalid_signature_here';
219
- try {
220
- await authentication.logout(invalidToken, BASE_URL);
221
- console.log('Logout completed without error (unexpected)');
222
- }
223
- catch (error) {
224
- console.log('Logout failed:', error.message);
225
- expect(error).toBeDefined();
226
- expect(error.message).toBeDefined();
227
- // Should get a server error for invalid token
228
- expect(error.message).toContain('Server Error');
229
- }
230
- });
231
- it('should verify logout accepts token as required parameter', () => {
232
- // This is a compile-time test to ensure the method signature is correct
233
- // The token parameter should be required
234
- const mockToken = 'test-token';
235
- // This should compile without errors
236
- expect(() => {
237
- // Test with token only (using default URL)
238
- const promise1 = authentication.logout(mockToken);
239
- promise1.catch(() => { }); // Ignore the actual API call
240
- // Test with both token and URL
241
- const promise2 = authentication.logout(mockToken, BASE_URL);
242
- promise2.catch(() => { }); // Ignore the actual API call
243
- }).not.toThrow();
244
- console.log('Logout method signature verified: token is required, baseUrl is optional');
245
- });
246
- });
247
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,63 +0,0 @@
1
- /*
2
- * Copyright (c) 2023-2025 Datalayer, Inc.
3
- * Distributed under the terms of the Modified BSD License.
4
- */
5
- import { describe, it, expect, beforeAll } from 'vitest';
6
- import { healthz } from '../iam';
7
- import { testConfig, debugLog, skipIfNoToken, } from '../../__tests__/shared/test-config';
8
- let BASE_URL;
9
- // Skip all tests if no token is available
10
- const skipTests = skipIfNoToken();
11
- beforeAll(async () => {
12
- if (skipTests) {
13
- console.log('WARNING: Skipping IAM healthz integration tests: No Datalayer API token configured');
14
- console.log(' Set DATALAYER_API_TOKEN env var or DATALAYER_TEST_TOKEN in .env.test');
15
- return;
16
- }
17
- // Get base URL from test config
18
- BASE_URL = testConfig.getBaseUrl('IAM');
19
- debugLog('Test configuration loaded');
20
- debugLog('Base URL:', BASE_URL);
21
- });
22
- describe.skipIf(skipTests)('IAM Healthz Integration Tests', () => {
23
- describe('ping endpoint', () => {
24
- it('should successfully ping the IAM service', async () => {
25
- console.log('Testing health check ping endpoint...');
26
- const response = await healthz.ping(BASE_URL);
27
- console.log('Ping response:', JSON.stringify(response, null, 2));
28
- // Verify the response structure matches actual API response
29
- expect(response).toBeDefined();
30
- expect(response.success).toBe(true);
31
- expect(response.message).toBeDefined();
32
- expect(response.message.toLowerCase()).toContain('running');
33
- expect(response.status).toBeDefined();
34
- expect(response.status.status).toBe('OK');
35
- expect(response.version).toBeDefined();
36
- expect(typeof response.version).toBe('string');
37
- console.log('Health check successful');
38
- console.log('Success:', response.success);
39
- console.log('Message:', response.message);
40
- console.log('Status:', response.status.status);
41
- console.log('Version:', response.version);
42
- });
43
- it('should work with default URL if not specified', async () => {
44
- console.log('Testing health check with default URL...');
45
- // Call without specifying URL to use default
46
- const response = await healthz.ping();
47
- console.log('Default URL ping response:', JSON.stringify(response, null, 2));
48
- // Should still get valid response
49
- expect(response).toBeDefined();
50
- expect(response.success).toBe(true);
51
- expect(response.status).toBeDefined();
52
- expect(response.status.status).toBe('OK');
53
- });
54
- });
55
- describe('error handling', () => {
56
- it('should handle malformed URLs gracefully', async () => {
57
- console.log('Testing error handling with malformed URL...');
58
- const malformedUrl = 'not-a-valid-url';
59
- // ping should throw an error
60
- await expect(healthz.ping(malformedUrl)).rejects.toThrow();
61
- });
62
- });
63
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,252 +0,0 @@
1
- /*
2
- * Copyright (c) 2023-2025 Datalayer, Inc.
3
- * Distributed under the terms of the Modified BSD License.
4
- */
5
- import { describe, it, expect, beforeAll } from 'vitest';
6
- import { authentication, profile } from '../iam';
7
- import { testConfig, debugLog, skipIfNoToken, } from '../../__tests__/shared/test-config';
8
- let DATALAYER_TOKEN;
9
- let SESSION_TOKEN;
10
- let BASE_URL;
11
- // Skip all tests if no token is available
12
- const skipTests = skipIfNoToken();
13
- beforeAll(async () => {
14
- if (skipTests) {
15
- console.log('WARNING: Skipping profile integration tests: No Datalayer API token configured');
16
- console.log(' Set DATALAYER_API_TOKEN env var or DATALAYER_TEST_TOKEN in .env.test');
17
- return;
18
- }
19
- // Get token and base URL from test config
20
- DATALAYER_TOKEN = testConfig.getToken();
21
- BASE_URL = testConfig.getBaseUrl('IAM');
22
- debugLog('Test configuration loaded');
23
- debugLog('Base URL:', BASE_URL);
24
- debugLog('Token available:', !!DATALAYER_TOKEN);
25
- // Login to get a session token for profile tests
26
- try {
27
- const loginResponse = await authentication.login({
28
- token: DATALAYER_TOKEN,
29
- });
30
- SESSION_TOKEN = loginResponse.token;
31
- debugLog('Successfully logged in, got session token');
32
- }
33
- catch (error) {
34
- console.error('Failed to login for profile tests:', error);
35
- throw error;
36
- }
37
- });
38
- describe.skipIf(skipTests)('IAM Profile Integration Tests', () => {
39
- describe('me', () => {
40
- it('should successfully get current user profile with token', async () => {
41
- console.log('Testing /me endpoint with session token...');
42
- const response = await profile.me(SESSION_TOKEN, BASE_URL);
43
- console.log('Profile response:', JSON.stringify(response, null, 2));
44
- // Verify response structure
45
- expect(response).toBeDefined();
46
- expect(response.success).toBe(true);
47
- expect(response.message).toBeDefined();
48
- expect(typeof response.message).toBe('string');
49
- // Verify me object structure
50
- expect(response.me).toBeDefined();
51
- expect(response.me.id).toBeDefined();
52
- expect(typeof response.me.id).toBe('string');
53
- expect(response.me.uid).toBeDefined();
54
- expect(typeof response.me.uid).toBe('string');
55
- expect(response.me.handle).toBeDefined();
56
- expect(typeof response.me.handle).toBe('string');
57
- expect(response.me.email).toBeDefined();
58
- expect(typeof response.me.email).toBe('string');
59
- expect(response.me.firstName).toBeDefined();
60
- expect(typeof response.me.firstName).toBe('string');
61
- expect(response.me.lastName).toBeDefined();
62
- expect(typeof response.me.lastName).toBe('string');
63
- expect(response.me.avatarUrl).toBeDefined();
64
- expect(typeof response.me.avatarUrl).toBe('string');
65
- expect(response.me.roles).toBeDefined();
66
- expect(Array.isArray(response.me.roles)).toBe(true);
67
- console.log('Successfully retrieved user profile');
68
- console.log('ID:', response.me.id);
69
- console.log('UID:', response.me.uid);
70
- console.log('Email:', response.me.email);
71
- console.log('Handle:', response.me.handle);
72
- console.log('Name:', response.me.firstName, response.me.lastName);
73
- console.log('Roles:', response.me.roles.join(', '));
74
- });
75
- it('should successfully get current user profile using default URL', async () => {
76
- console.log('Testing /me endpoint with default URL...');
77
- const response = await profile.me(SESSION_TOKEN);
78
- console.log('Profile response with default URL:', JSON.stringify(response, null, 2));
79
- // Verify response structure
80
- expect(response).toBeDefined();
81
- expect(response.success).toBe(true);
82
- expect(response.message).toBeDefined();
83
- expect(response.me).toBeDefined();
84
- expect(response.me.uid).toBeDefined();
85
- expect(response.me.handle).toBeDefined();
86
- expect(response.me.email).toBeDefined();
87
- expect(Array.isArray(response.me.roles)).toBe(true);
88
- console.log('Successfully retrieved user profile with default URL');
89
- console.log('UID:', response.me.uid);
90
- console.log('Handle:', response.me.handle);
91
- });
92
- it('should fail when using invalid token', async () => {
93
- console.log('Testing /me endpoint with invalid token...');
94
- const invalidToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJpbnZhbGlkIiwiaWF0IjoxNTE2MjM5MDIyfQ.invalid_signature_here';
95
- try {
96
- await profile.me(invalidToken, BASE_URL);
97
- // If we get here, the API accepted an invalid token (shouldn't happen)
98
- throw new Error('Expected API to reject invalid token');
99
- }
100
- catch (error) {
101
- console.log('API correctly rejected invalid token:', error.message);
102
- expect(error).toBeDefined();
103
- expect(error.message).toBeDefined();
104
- // The error message should indicate server error or authentication failure
105
- expect(error.message.includes('401') ||
106
- error.message.includes('Unauthorized') ||
107
- error.message.includes('Invalid') ||
108
- error.message.includes('credentials') ||
109
- error.message.includes('Server Error') ||
110
- error.message.includes('500')).toBe(true);
111
- }
112
- });
113
- it('should fail when no token is provided', async () => {
114
- console.log('Testing /me endpoint without token...');
115
- try {
116
- // @ts-expect-error Testing missing required parameter
117
- await profile.me();
118
- // Should not reach here
119
- throw new Error('Expected function to throw for missing token');
120
- }
121
- catch (error) {
122
- console.log('Correctly rejected request without token:', error.message);
123
- expect(error).toBeDefined();
124
- expect(error.message).toBe('Authentication token is required');
125
- }
126
- });
127
- it('should fail when empty token is provided', async () => {
128
- console.log('Testing /me endpoint with empty token...');
129
- try {
130
- await profile.me('', BASE_URL);
131
- // Should not reach here
132
- throw new Error('Expected function to throw for empty token');
133
- }
134
- catch (error) {
135
- console.log('Correctly rejected request with empty token:', error.message);
136
- expect(error).toBeDefined();
137
- expect(error.message).toBe('Authentication token is required');
138
- }
139
- });
140
- });
141
- describe('whoami', () => {
142
- it('should successfully get current user identity with token', async () => {
143
- console.log('Testing /whoami endpoint with session token...');
144
- const response = await profile.whoami(SESSION_TOKEN, BASE_URL);
145
- console.log('WhoAmI response:', JSON.stringify(response, null, 2));
146
- // Verify response structure
147
- expect(response).toBeDefined();
148
- expect(response.success).toBe(true);
149
- expect(response.message).toBeDefined();
150
- expect(typeof response.message).toBe('string');
151
- // Verify profile object structure
152
- expect(response.profile).toBeDefined();
153
- expect(response.profile.id).toBeDefined();
154
- expect(typeof response.profile.id).toBe('string');
155
- expect(response.profile.uid).toBeDefined();
156
- expect(typeof response.profile.uid).toBe('string');
157
- expect(response.profile.handle_s).toBeDefined();
158
- expect(typeof response.profile.handle_s).toBe('string');
159
- expect(response.profile.email_s).toBeDefined();
160
- expect(typeof response.profile.email_s).toBe('string');
161
- expect(response.profile.first_name_t).toBeDefined();
162
- expect(typeof response.profile.first_name_t).toBe('string');
163
- expect(response.profile.last_name_t).toBeDefined();
164
- expect(typeof response.profile.last_name_t).toBe('string');
165
- expect(response.profile.type_s).toBeDefined();
166
- expect(typeof response.profile.type_s).toBe('string');
167
- expect(response.profile.origin_s).toBeDefined();
168
- expect(typeof response.profile.origin_s).toBe('string');
169
- expect(response.profile.creation_ts_dt).toBeDefined();
170
- expect(typeof response.profile.creation_ts_dt).toBe('string');
171
- expect(response.profile.last_update_ts_dt).toBeDefined();
172
- expect(typeof response.profile.last_update_ts_dt).toBe('string');
173
- expect(response.profile.join_ts_dt).toBeDefined();
174
- expect(typeof response.profile.join_ts_dt).toBe('string');
175
- // join_request_ts_dt can be null
176
- if (response.profile.join_request_ts_dt !== null) {
177
- expect(typeof response.profile.join_request_ts_dt).toBe('string');
178
- }
179
- console.log('Successfully retrieved user identity');
180
- console.log('ID:', response.profile.id);
181
- console.log('UID:', response.profile.uid);
182
- console.log('Email:', response.profile.email_s);
183
- console.log('Handle:', response.profile.handle_s);
184
- console.log('Name:', response.profile.first_name_t, response.profile.last_name_t);
185
- console.log('Type:', response.profile.type_s);
186
- });
187
- it('should successfully get current user identity using default URL', async () => {
188
- console.log('Testing /whoami endpoint with default URL...');
189
- const response = await profile.whoami(SESSION_TOKEN);
190
- console.log('WhoAmI response with default URL:', JSON.stringify(response, null, 2));
191
- // Verify response structure
192
- expect(response).toBeDefined();
193
- expect(response.success).toBe(true);
194
- expect(response.message).toBeDefined();
195
- expect(response.profile).toBeDefined();
196
- expect(response.profile.uid).toBeDefined();
197
- expect(response.profile.handle_s).toBeDefined();
198
- expect(response.profile.email_s).toBeDefined();
199
- console.log('Successfully retrieved user identity with default URL');
200
- console.log('UID:', response.profile.uid);
201
- console.log('Handle:', response.profile.handle_s);
202
- });
203
- it('should fail whoami when using invalid token', async () => {
204
- console.log('Testing /whoami endpoint with invalid token...');
205
- const invalidToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJpbnZhbGlkIiwiaWF0IjoxNTE2MjM5MDIyfQ.invalid_signature_here';
206
- try {
207
- await profile.whoami(invalidToken, BASE_URL);
208
- // If we get here, the API accepted an invalid token (shouldn't happen)
209
- throw new Error('Expected API to reject invalid token');
210
- }
211
- catch (error) {
212
- console.log('API correctly rejected invalid token:', error.message);
213
- expect(error).toBeDefined();
214
- expect(error.message).toBeDefined();
215
- // The error message should indicate server error or authentication failure
216
- expect(error.message.includes('401') ||
217
- error.message.includes('Unauthorized') ||
218
- error.message.includes('Invalid') ||
219
- error.message.includes('credentials') ||
220
- error.message.includes('Server Error') ||
221
- error.message.includes('500')).toBe(true);
222
- }
223
- });
224
- it('should fail whoami when no token is provided', async () => {
225
- console.log('Testing /whoami endpoint without token...');
226
- try {
227
- // @ts-expect-error Testing missing required parameter
228
- await profile.whoami();
229
- // Should not reach here
230
- throw new Error('Expected function to throw for missing token');
231
- }
232
- catch (error) {
233
- console.log('Correctly rejected request without token:', error.message);
234
- expect(error).toBeDefined();
235
- expect(error.message).toBe('Authentication token is required');
236
- }
237
- });
238
- it('should fail whoami when empty token is provided', async () => {
239
- console.log('Testing /whoami endpoint with empty token...');
240
- try {
241
- await profile.whoami('', BASE_URL);
242
- // Should not reach here
243
- throw new Error('Expected function to throw for empty token');
244
- }
245
- catch (error) {
246
- console.log('Correctly rejected request with empty token:', error.message);
247
- expect(error).toBeDefined();
248
- expect(error.message).toBe('Authentication token is required');
249
- }
250
- });
251
- });
252
- });