@datalayer/core 0.0.12 → 0.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (237) hide show
  1. package/README.md +2 -2
  2. package/lib/api/DatalayerApi.d.ts +38 -26
  3. package/lib/api/DatalayerApi.js +35 -8
  4. package/lib/api/iam/authentication.d.ts +8 -7
  5. package/lib/api/iam/authentication.js +14 -15
  6. package/lib/api/iam/healthz.d.ts +3 -2
  7. package/lib/api/iam/healthz.js +5 -3
  8. package/lib/api/iam/index.d.ts +9 -4
  9. package/lib/api/iam/index.js +9 -4
  10. package/lib/api/iam/oauth2.d.ts +115 -0
  11. package/lib/api/iam/oauth2.js +309 -0
  12. package/lib/api/iam/profile.d.ts +8 -1
  13. package/lib/api/iam/profile.js +17 -2
  14. package/lib/api/iam/usage.d.ts +56 -0
  15. package/lib/api/iam/usage.js +39 -0
  16. package/lib/api/index.d.ts +6 -5
  17. package/lib/api/index.js +6 -5
  18. package/lib/api/runtimes/environments.js +3 -2
  19. package/lib/api/runtimes/healthz.d.ts +3 -13
  20. package/lib/api/runtimes/healthz.js +4 -3
  21. package/lib/api/runtimes/index.d.ts +3 -2
  22. package/lib/api/runtimes/index.js +3 -2
  23. package/lib/api/runtimes/runtimes.js +17 -6
  24. package/lib/api/runtimes/snapshots.js +3 -2
  25. package/lib/api/spacer/documents.d.ts +12 -0
  26. package/lib/api/spacer/documents.js +43 -0
  27. package/lib/api/spacer/healthz.d.ts +3 -13
  28. package/lib/api/spacer/healthz.js +4 -3
  29. package/lib/api/spacer/index.d.ts +4 -2
  30. package/lib/api/spacer/index.js +4 -2
  31. package/lib/api/spacer/items.d.ts +9 -1
  32. package/lib/api/spacer/items.js +17 -2
  33. package/lib/api/spacer/lexicals.js +3 -2
  34. package/lib/api/spacer/notebooks.js +3 -2
  35. package/lib/api/spacer/spaces.js +3 -2
  36. package/lib/api/spacer/users.js +3 -2
  37. package/lib/api/types/common.d.ts +64 -0
  38. package/lib/api/types/iam.d.ts +88 -65
  39. package/lib/api/types/index.d.ts +4 -2
  40. package/lib/api/types/index.js +4 -2
  41. package/lib/api/types/runtimes.d.ts +9 -39
  42. package/lib/api/types/spacer.d.ts +37 -65
  43. package/lib/api/utils/validation.d.ts +24 -1
  44. package/lib/api/utils/validation.js +62 -1
  45. package/lib/client/base.d.ts +75 -0
  46. package/lib/client/base.js +199 -0
  47. package/lib/client/constants.d.ts +22 -0
  48. package/lib/client/constants.js +22 -0
  49. package/lib/client/index.d.ts +108 -0
  50. package/lib/client/index.js +79 -0
  51. package/lib/client/mixins/IAMMixin.d.ts +54 -0
  52. package/lib/client/mixins/IAMMixin.js +181 -0
  53. package/lib/client/mixins/RuntimesMixin.d.ts +93 -0
  54. package/lib/client/mixins/RuntimesMixin.js +229 -0
  55. package/lib/client/mixins/SpacerMixin.d.ts +111 -0
  56. package/lib/client/mixins/SpacerMixin.js +340 -0
  57. package/lib/client/models/Credits.d.ts +91 -0
  58. package/lib/client/models/Credits.js +130 -0
  59. package/lib/client/models/Environment.d.ts +73 -0
  60. package/lib/client/models/Environment.js +88 -0
  61. package/lib/client/models/HealthCheck.d.ts +72 -0
  62. package/lib/client/models/HealthCheck.js +107 -0
  63. package/lib/client/models/Item.d.ts +69 -0
  64. package/lib/client/models/Item.js +191 -0
  65. package/lib/client/models/Lexical.d.ts +83 -0
  66. package/lib/client/models/Lexical.js +152 -0
  67. package/lib/client/models/Notebook.d.ts +87 -0
  68. package/lib/client/models/Notebook.js +153 -0
  69. package/lib/client/models/Runtime.d.ts +122 -0
  70. package/lib/client/models/Runtime.js +204 -0
  71. package/lib/client/models/Snapshot.d.ts +92 -0
  72. package/lib/client/models/Snapshot.js +139 -0
  73. package/lib/client/models/Space.d.ts +135 -0
  74. package/lib/client/models/Space.js +234 -0
  75. package/lib/client/models/User.d.ts +64 -0
  76. package/lib/client/models/User.js +83 -0
  77. package/lib/client/models/index.d.ts +26 -0
  78. package/lib/client/models/index.js +25 -0
  79. package/lib/client/utils/mixins.d.ts +12 -0
  80. package/lib/{sdk/client → client}/utils/mixins.js +0 -28
  81. package/lib/client/utils/spacerUtils.d.ts +18 -0
  82. package/lib/client/utils/spacerUtils.js +32 -0
  83. package/lib/collaboration/DatalayerCollaboration.d.ts +6 -1
  84. package/lib/collaboration/DatalayerCollaboration.js +2 -2
  85. package/lib/collaboration/DatalayerCollaborationProvider.d.ts +5 -0
  86. package/lib/collaboration/DatalayerCollaborationProvider.js +10 -9
  87. package/lib/components/progress/CreditsIndicator.d.ts +1 -1
  88. package/lib/components/runtimes/RuntimeCellVariablesDialog.js +1 -1
  89. package/lib/components/runtimes/RuntimeLauncherDialog.d.ts +1 -1
  90. package/lib/components/runtimes/RuntimePickerBase.d.ts +1 -1
  91. package/lib/components/runtimes/RuntimePickerBase.js +1 -1
  92. package/lib/components/runtimes/RuntimePickerCell.js +2 -2
  93. package/lib/components/runtimes/RuntimePickerNotebook.d.ts +1 -1
  94. package/lib/components/runtimes/RuntimePickerNotebook.js +1 -1
  95. package/lib/components/runtimes/RuntimeTransfer.d.ts +1 -1
  96. package/lib/components/runtimes/RuntimeUtils.d.ts +1 -1
  97. package/lib/components/snapshots/RuntimeSnapshotMenu.d.ts +1 -1
  98. package/lib/components/snapshots/RuntimeSnapshotMenu.js +27 -20
  99. package/lib/config/Configuration.d.ts +8 -0
  100. package/lib/hooks/useDatalayer.js +1 -1
  101. package/lib/hooks/useRuntimes.js +1 -1
  102. package/lib/hooks/useToast.js +1 -1
  103. package/lib/index.d.ts +2 -2
  104. package/lib/index.js +4 -2
  105. package/lib/sdk/index.d.ts +5 -4
  106. package/lib/sdk/index.js +6 -5
  107. package/lib/services/DatalayerServiceManager.js +1 -1
  108. package/lib/state/substates/CoreState.js +2 -0
  109. package/lib/state/substates/RuntimesState.d.ts +1 -1
  110. package/lib/state/substates/RuntimesState.js +1 -1
  111. package/lib/{sdk/stateful → stateful}/index.d.ts +1 -1
  112. package/lib/{sdk/stateful → stateful}/index.js +1 -1
  113. package/lib/{sdk/stateful → stateful}/jupyter/exec/Snippets.d.ts +1 -41
  114. package/lib/{sdk/stateful → stateful}/jupyter/exec/Snippets.js +1 -20
  115. package/lib/{sdk/stateful → stateful}/runtimes/actions.d.ts +3 -3
  116. package/lib/{sdk/stateful → stateful}/runtimes/actions.js +8 -8
  117. package/lib/{sdk/stateful → stateful}/runtimes/apis.d.ts +8 -8
  118. package/lib/stateful/runtimes/apis.js +5 -0
  119. package/package.json +12 -10
  120. package/lib/__tests__/hooks.test.d.ts +0 -1
  121. package/lib/__tests__/hooks.test.js +0 -19
  122. package/lib/__tests__/index.test.d.ts +0 -1
  123. package/lib/__tests__/index.test.js +0 -27
  124. package/lib/__tests__/integration.test.d.ts +0 -1
  125. package/lib/__tests__/integration.test.js +0 -57
  126. package/lib/__tests__/shared/cleanup-shared.d.ts +0 -4
  127. package/lib/__tests__/shared/cleanup-shared.js +0 -228
  128. package/lib/__tests__/shared/test-config.d.ts +0 -51
  129. package/lib/__tests__/shared/test-config.js +0 -110
  130. package/lib/__tests__/shared/test-constants.d.ts +0 -66
  131. package/lib/__tests__/shared/test-constants.js +0 -79
  132. package/lib/__tests__/utils.test.d.ts +0 -1
  133. package/lib/__tests__/utils.test.js +0 -59
  134. package/lib/api/__tests__/iam.authentication.integration.test.d.ts +0 -1
  135. package/lib/api/__tests__/iam.authentication.integration.test.js +0 -247
  136. package/lib/api/__tests__/iam.healthz.integration.test.d.ts +0 -1
  137. package/lib/api/__tests__/iam.healthz.integration.test.js +0 -63
  138. package/lib/api/__tests__/iam.profile.integration.test.d.ts +0 -1
  139. package/lib/api/__tests__/iam.profile.integration.test.js +0 -252
  140. package/lib/api/__tests__/runtimes.environments.integration.test.d.ts +0 -1
  141. package/lib/api/__tests__/runtimes.environments.integration.test.js +0 -122
  142. package/lib/api/__tests__/runtimes.healthz.integration.test.d.ts +0 -1
  143. package/lib/api/__tests__/runtimes.healthz.integration.test.js +0 -50
  144. package/lib/api/__tests__/runtimes.integration.test.d.ts +0 -1
  145. package/lib/api/__tests__/runtimes.integration.test.js +0 -369
  146. package/lib/api/__tests__/spacer.healthz.integration.test.d.ts +0 -1
  147. package/lib/api/__tests__/spacer.healthz.integration.test.js +0 -50
  148. package/lib/api/__tests__/spacer.integration.test.d.ts +0 -1
  149. package/lib/api/__tests__/spacer.integration.test.js +0 -519
  150. package/lib/api/iam/__tests__/authentication.unit.test.d.ts +0 -1
  151. package/lib/api/iam/__tests__/authentication.unit.test.js +0 -63
  152. package/lib/api/iam/__tests__/healthz.unit.test.d.ts +0 -1
  153. package/lib/api/iam/__tests__/healthz.unit.test.js +0 -60
  154. package/lib/api/iam/__tests__/profile.unit.test.d.ts +0 -1
  155. package/lib/api/iam/__tests__/profile.unit.test.js +0 -57
  156. package/lib/api/runtimes/__tests__/environments.unit.test.d.ts +0 -1
  157. package/lib/api/runtimes/__tests__/environments.unit.test.js +0 -77
  158. package/lib/api/runtimes/__tests__/healthz.unit.test.d.ts +0 -1
  159. package/lib/api/runtimes/__tests__/healthz.unit.test.js +0 -57
  160. package/lib/api/runtimes/__tests__/runtimes.unit.test.d.ts +0 -1
  161. package/lib/api/runtimes/__tests__/runtimes.unit.test.js +0 -139
  162. package/lib/api/runtimes/__tests__/snapshots.unit.test.d.ts +0 -1
  163. package/lib/api/runtimes/__tests__/snapshots.unit.test.js +0 -96
  164. package/lib/api/spacer/__tests__/healthz.unit.test.d.ts +0 -1
  165. package/lib/api/spacer/__tests__/healthz.unit.test.js +0 -57
  166. package/lib/api/spacer/__tests__/items.unit.test.d.ts +0 -1
  167. package/lib/api/spacer/__tests__/items.unit.test.js +0 -165
  168. package/lib/api/spacer/__tests__/lexicals.unit.test.d.ts +0 -1
  169. package/lib/api/spacer/__tests__/lexicals.unit.test.js +0 -323
  170. package/lib/api/spacer/__tests__/notebooks.unit.test.d.ts +0 -1
  171. package/lib/api/spacer/__tests__/notebooks.unit.test.js +0 -224
  172. package/lib/api/spacer/__tests__/users.unit.test.d.ts +0 -1
  173. package/lib/api/spacer/__tests__/users.unit.test.js +0 -132
  174. package/lib/api/utils/__tests__/validation.test.d.ts +0 -1
  175. package/lib/api/utils/__tests__/validation.test.js +0 -109
  176. package/lib/sdk/client/__tests__/sdk.health.integration.test.d.ts +0 -1
  177. package/lib/sdk/client/__tests__/sdk.health.integration.test.js +0 -110
  178. package/lib/sdk/client/__tests__/sdk.iam.integration.test.d.ts +0 -1
  179. package/lib/sdk/client/__tests__/sdk.iam.integration.test.js +0 -179
  180. package/lib/sdk/client/__tests__/sdk.models.integration.test.d.ts +0 -1
  181. package/lib/sdk/client/__tests__/sdk.models.integration.test.js +0 -376
  182. package/lib/sdk/client/__tests__/sdk.runtimes.integration.test.d.ts +0 -1
  183. package/lib/sdk/client/__tests__/sdk.runtimes.integration.test.js +0 -276
  184. package/lib/sdk/client/__tests__/sdk.spacer.integration.test.d.ts +0 -1
  185. package/lib/sdk/client/__tests__/sdk.spacer.integration.test.js +0 -361
  186. package/lib/sdk/client/base.d.ts +0 -88
  187. package/lib/sdk/client/base.js +0 -112
  188. package/lib/sdk/client/index.d.ts +0 -192
  189. package/lib/sdk/client/index.js +0 -128
  190. package/lib/sdk/client/mixins/HealthMixin.d.ts +0 -100
  191. package/lib/sdk/client/mixins/HealthMixin.js +0 -133
  192. package/lib/sdk/client/mixins/IAMMixin.d.ts +0 -59
  193. package/lib/sdk/client/mixins/IAMMixin.js +0 -83
  194. package/lib/sdk/client/mixins/RuntimesMixin.d.ts +0 -134
  195. package/lib/sdk/client/mixins/RuntimesMixin.js +0 -221
  196. package/lib/sdk/client/mixins/SpacerMixin.d.ts +0 -184
  197. package/lib/sdk/client/mixins/SpacerMixin.js +0 -278
  198. package/lib/sdk/client/models/Lexical.d.ts +0 -156
  199. package/lib/sdk/client/models/Lexical.js +0 -275
  200. package/lib/sdk/client/models/Notebook.d.ts +0 -174
  201. package/lib/sdk/client/models/Notebook.js +0 -311
  202. package/lib/sdk/client/models/Runtime.d.ts +0 -221
  203. package/lib/sdk/client/models/Runtime.js +0 -341
  204. package/lib/sdk/client/models/Snapshot.d.ts +0 -156
  205. package/lib/sdk/client/models/Snapshot.js +0 -244
  206. package/lib/sdk/client/models/Space.d.ts +0 -182
  207. package/lib/sdk/client/models/Space.js +0 -276
  208. package/lib/sdk/client/models/__tests__/Lexical.test.d.ts +0 -1
  209. package/lib/sdk/client/models/__tests__/Lexical.test.js +0 -288
  210. package/lib/sdk/client/models/__tests__/Notebook.test.d.ts +0 -1
  211. package/lib/sdk/client/models/__tests__/Notebook.test.js +0 -206
  212. package/lib/sdk/client/models/__tests__/Runtime.test.d.ts +0 -1
  213. package/lib/sdk/client/models/__tests__/Runtime.test.js +0 -133
  214. package/lib/sdk/client/models/__tests__/Snapshot.test.d.ts +0 -1
  215. package/lib/sdk/client/models/__tests__/Snapshot.test.js +0 -244
  216. package/lib/sdk/client/models/__tests__/Space.test.d.ts +0 -1
  217. package/lib/sdk/client/models/__tests__/Space.test.js +0 -334
  218. package/lib/sdk/client/models/index.d.ts +0 -30
  219. package/lib/sdk/client/models/index.js +0 -30
  220. package/lib/sdk/client/utils/mixins.d.ts +0 -42
  221. /package/lib/{sdk/stateful/runtimes/apis.js → api/types/common.js} +0 -0
  222. /package/lib/{sdk/stateful → stateful}/jupyter/exec/Python.d.ts +0 -0
  223. /package/lib/{sdk/stateful → stateful}/jupyter/exec/Python.js +0 -0
  224. /package/lib/{sdk/stateful → stateful}/jupyter/exec/index.d.ts +0 -0
  225. /package/lib/{sdk/stateful → stateful}/jupyter/exec/index.js +0 -0
  226. /package/lib/{sdk/stateful → stateful}/jupyter/index.d.ts +0 -0
  227. /package/lib/{sdk/stateful → stateful}/jupyter/index.js +0 -0
  228. /package/lib/{sdk/stateful → stateful}/jupyter/kernelsHandler.d.ts +0 -0
  229. /package/lib/{sdk/stateful → stateful}/jupyter/kernelsHandler.js +0 -0
  230. /package/lib/{sdk/stateful → stateful}/runtimes/index.d.ts +0 -0
  231. /package/lib/{sdk/stateful → stateful}/runtimes/index.js +0 -0
  232. /package/lib/{sdk/stateful → stateful}/runtimes/settings.d.ts +0 -0
  233. /package/lib/{sdk/stateful → stateful}/runtimes/settings.js +0 -0
  234. /package/lib/{sdk/stateful → stateful}/runtimes/snapshots.d.ts +0 -0
  235. /package/lib/{sdk/stateful → stateful}/runtimes/snapshots.js +0 -0
  236. /package/lib/{sdk/stateful → stateful}/runtimes/utils.d.ts +0 -0
  237. /package/lib/{sdk/stateful → stateful}/runtimes/utils.js +0 -0
@@ -1,79 +0,0 @@
1
- /*
2
- * Copyright (c) 2023-2025 Datalayer, Inc.
3
- * Distributed under the terms of the Modified BSD License.
4
- */
5
- /**
6
- * Test constants for API unit tests
7
- */
8
- /**
9
- * A valid mock JWT token for testing
10
- * This token has the correct JWT structure (header.payload.signature) but is not cryptographically valid
11
- *
12
- * Decoded header: {"alg":"HS256","typ":"JWT"}
13
- * Decoded payload: {"sub":"test-user","iss":"test-issuer","iat":1700000000,"exp":9999999999,"aud":"test-audience"}
14
- *
15
- * The token is constructed to:
16
- * - Have three parts separated by dots
17
- * - Have valid base64url encoded parts
18
- * - Have proper JWT header with alg and typ
19
- * - Have common JWT claims in payload
20
- * - Have an expiration far in the future to avoid expiration errors
21
- * - Be long enough to pass length validation (>100 chars)
22
- */
23
- export const MOCK_JWT_TOKEN = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ0ZXN0LXVzZXIiLCJpc3MiOiJ0ZXN0LWlzc3VlciIsImlhdCI6MTcwMDAwMDAwMCwiZXhwIjo5OTk5OTk5OTk5LCJhdWQiOiJ0ZXN0LWF1ZGllbmNlIn0.abcdefghijklmnopqrstuvwxyz012345678901234567890';
24
- /**
25
- * An invalid token (not JWT format) for negative testing
26
- */
27
- export const INVALID_TOKEN = 'invalid-token';
28
- /**
29
- * A malformed JWT token (only two parts instead of three)
30
- */
31
- export const MALFORMED_JWT_TOKEN = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ0ZXN0LXVzZXIifQ';
32
- /**
33
- * A JWT token with an expired timestamp
34
- * Decoded payload: {"sub":"test-user","exp":1000000000}
35
- */
36
- export const EXPIRED_JWT_TOKEN = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ0ZXN0LXVzZXIiLCJleHAiOjEwMDAwMDAwMDB9.abcdefghijklmnopqrstuvwxyz012345678901234567890';
37
- /**
38
- * Mock API responses
39
- */
40
- export const MOCK_ENVIRONMENTS_RESPONSE = {
41
- success: true,
42
- message: 'Environments retrieved successfully',
43
- environments: [
44
- {
45
- title: 'Python Base',
46
- description: 'Basic Python environment',
47
- dockerImage: 'python:3.9',
48
- language: 'python',
49
- burning_rate: 1,
50
- },
51
- {
52
- title: 'R Statistical',
53
- description: 'R environment for statistical computing',
54
- dockerImage: 'r-base:4.3',
55
- language: 'r',
56
- burning_rate: 2,
57
- },
58
- ],
59
- };
60
- export const MOCK_RUNTIME_RESPONSE = {
61
- success: true,
62
- message: 'Runtime retrieved successfully',
63
- runtime: {
64
- pod_name: 'test-runtime-pod',
65
- status: 'running',
66
- environment: 'python-base',
67
- created_at: '2024-01-01T00:00:00Z',
68
- },
69
- };
70
- export const MOCK_SNAPSHOT_RESPONSE = {
71
- success: true,
72
- message: 'Snapshot retrieved successfully',
73
- snapshot: {
74
- id: 'test-snapshot-123',
75
- name: 'Test Snapshot',
76
- created_at: '2024-01-01T00:00:00Z',
77
- size: 1024000,
78
- },
79
- };
@@ -1 +0,0 @@
1
- export {};
@@ -1,59 +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 } from 'vitest';
6
- import { formatString, addNumbers, isDefined, delay } from '../utils';
7
- describe('utils', () => {
8
- describe('formatString', () => {
9
- it('should trim and lowercase strings', () => {
10
- expect(formatString(' HELLO WORLD ')).toBe('hello world');
11
- });
12
- it('should handle empty strings', () => {
13
- expect(formatString('')).toBe('');
14
- });
15
- it('should handle already formatted strings', () => {
16
- expect(formatString('hello')).toBe('hello');
17
- });
18
- });
19
- describe('addNumbers', () => {
20
- it('should add positive numbers', () => {
21
- expect(addNumbers(2, 3)).toBe(5);
22
- });
23
- it('should add negative numbers', () => {
24
- expect(addNumbers(-2, -3)).toBe(-5);
25
- });
26
- it('should add zero', () => {
27
- expect(addNumbers(5, 0)).toBe(5);
28
- });
29
- it('should handle decimals', () => {
30
- expect(addNumbers(1.5, 2.5)).toBe(4);
31
- });
32
- });
33
- describe('isDefined', () => {
34
- it('should return true for defined values', () => {
35
- expect(isDefined('hello')).toBe(true);
36
- expect(isDefined(0)).toBe(true);
37
- expect(isDefined(false)).toBe(true);
38
- expect(isDefined([])).toBe(true);
39
- });
40
- it('should return false for undefined', () => {
41
- expect(isDefined(undefined)).toBe(false);
42
- });
43
- it('should return false for null', () => {
44
- expect(isDefined(null)).toBe(false);
45
- });
46
- });
47
- describe('delay', () => {
48
- it('should resolve after specified time', async () => {
49
- const start = Date.now();
50
- await delay(100);
51
- const end = Date.now();
52
- expect(end - start).toBeGreaterThanOrEqual(90); // Allow some tolerance
53
- });
54
- it('should return a Promise', () => {
55
- const result = delay(1);
56
- expect(result).toBeInstanceOf(Promise);
57
- });
58
- });
59
- });
@@ -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 {};