@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,57 +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 { profile } from '..';
7
- describe('IAM Profile Unit Tests', () => {
8
- describe('parameter validation', () => {
9
- it('should handle undefined token parameter at runtime', async () => {
10
- console.log('Testing that undefined token is caught by validation...');
11
- // In JavaScript/TypeScript at runtime, calling a function without
12
- // required parameters just passes undefined for those parameters.
13
- // Our validation code inside the function should catch this.
14
- // Test me() with undefined token
15
- await expect(profile.me(undefined)).rejects.toThrow('Authentication token is required');
16
- // Test whoami() with undefined token
17
- await expect(profile.whoami(undefined)).rejects.toThrow('Authentication token is required');
18
- console.log('Validation correctly rejects undefined token');
19
- });
20
- it('should handle null token parameter at runtime', async () => {
21
- console.log('Testing that null token is caught by validation...');
22
- // Test me() with null token
23
- await expect(profile.me(null)).rejects.toThrow('Authentication token is required');
24
- // Test whoami() with null token
25
- await expect(profile.whoami(null)).rejects.toThrow('Authentication token is required');
26
- console.log('Validation correctly rejects null token');
27
- });
28
- it('should handle empty string token', async () => {
29
- console.log('Testing that empty string token is caught by validation...');
30
- // Test me() with empty string
31
- await expect(profile.me('')).rejects.toThrow('Authentication token is required');
32
- // Test whoami() with empty string
33
- await expect(profile.whoami('')).rejects.toThrow('Authentication token is required');
34
- console.log('Validation correctly rejects empty string token');
35
- });
36
- it('should handle whitespace-only token', async () => {
37
- console.log('Testing that whitespace-only token is caught by validation...');
38
- // Test me() with whitespace
39
- await expect(profile.me(' ')).rejects.toThrow('Authentication token is required');
40
- // Test whoami() with whitespace
41
- await expect(profile.whoami(' ')).rejects.toThrow('Authentication token is required');
42
- console.log('Validation correctly rejects whitespace-only token');
43
- });
44
- it('demonstrates JavaScript runtime behavior with missing parameters', () => {
45
- console.log('Demonstrating JS runtime behavior...');
46
- // This demonstrates that JavaScript doesn't throw errors for missing parameters
47
- // The function receives undefined for missing parameters
48
- function testFunction(required) {
49
- return required === undefined;
50
- }
51
- // @ts-expect-error TypeScript knows this is wrong, but JS allows it
52
- const result = testFunction();
53
- expect(result).toBe(true); // The parameter is undefined
54
- console.log('JavaScript passes undefined for missing parameters');
55
- });
56
- });
57
- });
@@ -1,77 +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, vi, beforeEach } from 'vitest';
6
- import { environments } from '..';
7
- import { requestDatalayerAPI } from '../../DatalayerApi';
8
- import { MOCK_JWT_TOKEN, MOCK_ENVIRONMENTS_RESPONSE, } from '../../../__tests__/shared/test-constants';
9
- // Mock the DatalayerAPI module
10
- vi.mock('../../DatalayerApi');
11
- describe('Runtimes Environments Unit Tests', () => {
12
- beforeEach(() => {
13
- vi.clearAllMocks();
14
- });
15
- describe('listEnvironments', () => {
16
- it('should list environments with valid token', async () => {
17
- vi.mocked(requestDatalayerAPI).mockResolvedValueOnce(MOCK_ENVIRONMENTS_RESPONSE);
18
- const result = await environments.listEnvironments(MOCK_JWT_TOKEN);
19
- expect(result).toEqual(MOCK_ENVIRONMENTS_RESPONSE);
20
- expect(requestDatalayerAPI).toHaveBeenCalledWith({
21
- url: 'https://prod1.datalayer.run/api/runtimes/v1/environments',
22
- method: 'GET',
23
- token: MOCK_JWT_TOKEN,
24
- });
25
- });
26
- it('should use custom base URL when provided', async () => {
27
- const mockResponse = {
28
- success: true,
29
- message: 'Environments retrieved',
30
- environments: [],
31
- };
32
- const customUrl = 'https://staging.datalayer.run';
33
- vi.mocked(requestDatalayerAPI).mockResolvedValueOnce(mockResponse);
34
- const result = await environments.listEnvironments(MOCK_JWT_TOKEN, customUrl);
35
- expect(result).toEqual(mockResponse);
36
- expect(requestDatalayerAPI).toHaveBeenCalledWith({
37
- url: `${customUrl}/api/runtimes/v1/environments`,
38
- method: 'GET',
39
- token: MOCK_JWT_TOKEN,
40
- });
41
- });
42
- it('should throw error when token is missing', async () => {
43
- await expect(environments.listEnvironments('')).rejects.toThrow('Authentication token is required');
44
- expect(requestDatalayerAPI).not.toHaveBeenCalled();
45
- });
46
- it('should throw error when token is null', async () => {
47
- // @ts-expect-error Testing null token
48
- await expect(environments.listEnvironments(null)).rejects.toThrow('Authentication token is required');
49
- expect(requestDatalayerAPI).not.toHaveBeenCalled();
50
- });
51
- it('should throw error when token is undefined', async () => {
52
- // @ts-expect-error Testing undefined token
53
- await expect(environments.listEnvironments(undefined)).rejects.toThrow('Authentication token is required');
54
- expect(requestDatalayerAPI).not.toHaveBeenCalled();
55
- });
56
- it('should throw error when token is only whitespace', async () => {
57
- await expect(environments.listEnvironments(' ')).rejects.toThrow('Authentication token is required');
58
- expect(requestDatalayerAPI).not.toHaveBeenCalled();
59
- });
60
- it('should handle API errors properly', async () => {
61
- const mockError = new Error('Network error');
62
- vi.mocked(requestDatalayerAPI).mockRejectedValueOnce(mockError);
63
- await expect(environments.listEnvironments(MOCK_JWT_TOKEN)).rejects.toThrow('Network error');
64
- });
65
- it('should handle empty environments list', async () => {
66
- const mockResponse = {
67
- success: true,
68
- message: 'No environments available',
69
- environments: [],
70
- };
71
- vi.mocked(requestDatalayerAPI).mockResolvedValueOnce(mockResponse);
72
- const result = await environments.listEnvironments(MOCK_JWT_TOKEN);
73
- expect(result).toEqual(mockResponse);
74
- expect(result.environments).toHaveLength(0);
75
- });
76
- });
77
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,57 +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, vi, beforeEach } from 'vitest';
6
- import { healthz } from '..';
7
- import { requestDatalayerAPI } from '../../DatalayerApi';
8
- // Mock the DatalayerAPI module
9
- vi.mock('../../DatalayerApi');
10
- describe('Runtimes Healthz Unit Tests', () => {
11
- beforeEach(() => {
12
- vi.clearAllMocks();
13
- });
14
- describe('ping', () => {
15
- it('should successfully ping the service', async () => {
16
- const mockResponse = {
17
- success: true,
18
- message: 'Runtimes service is healthy',
19
- status: {
20
- status: 'OK',
21
- },
22
- version: '1.0.0',
23
- };
24
- vi.mocked(requestDatalayerAPI).mockResolvedValueOnce(mockResponse);
25
- const result = await healthz.ping('https://test.datalayer.run');
26
- expect(result).toEqual(mockResponse);
27
- expect(requestDatalayerAPI).toHaveBeenCalledWith({
28
- url: 'https://test.datalayer.run/api/runtimes/v1/ping',
29
- method: 'GET',
30
- });
31
- });
32
- it('should use default URL when not provided', async () => {
33
- const mockResponse = {
34
- success: true,
35
- message: 'Service is healthy',
36
- };
37
- vi.mocked(requestDatalayerAPI).mockResolvedValueOnce(mockResponse);
38
- const result = await healthz.ping();
39
- expect(result).toEqual(mockResponse);
40
- expect(requestDatalayerAPI).toHaveBeenCalledWith({
41
- url: 'https://prod1.datalayer.run/api/runtimes/v1/ping',
42
- method: 'GET',
43
- });
44
- });
45
- it('should handle service unhealthy errors', async () => {
46
- const mockError = new Error('Service error');
47
- mockError.response = { status: 500 };
48
- vi.mocked(requestDatalayerAPI).mockRejectedValueOnce(mockError);
49
- await expect(healthz.ping()).rejects.toThrow('Health check failed: Service unhealthy (status 500)');
50
- });
51
- it('should handle network errors', async () => {
52
- const mockError = new Error('Network error');
53
- vi.mocked(requestDatalayerAPI).mockRejectedValueOnce(mockError);
54
- await expect(healthz.ping()).rejects.toThrow('Health check failed: Network error');
55
- });
56
- });
57
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,139 +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 { runtimes } from '..';
7
- import { MOCK_JWT_TOKEN } from '../../../__tests__/shared/test-constants';
8
- describe('Runtimes Unit Tests', () => {
9
- describe('create parameter validation', () => {
10
- const mockBaseUrl = 'https://example.com';
11
- const mockData = {
12
- environment_name: 'python-cpu-env',
13
- type: 'notebook',
14
- given_name: 'test-runtime',
15
- credits_limit: 100,
16
- };
17
- it('should fail when token is missing', async () => {
18
- console.log('Testing create with missing token...');
19
- await expect(
20
- // @ts-expect-error Testing undefined token
21
- runtimes.createRuntime(undefined, mockData, mockBaseUrl)).rejects.toThrow('Authentication token is required');
22
- console.log('Correctly rejected create with missing token');
23
- });
24
- it('should fail when token is empty', async () => {
25
- console.log('Testing create with empty token...');
26
- await expect(runtimes.createRuntime('', mockData, mockBaseUrl)).rejects.toThrow('Authentication token is required');
27
- console.log('Correctly rejected create with empty token');
28
- });
29
- it('should fail when token is only whitespace', async () => {
30
- console.log('Testing create with whitespace token...');
31
- await expect(runtimes.createRuntime(' ', mockData, mockBaseUrl)).rejects.toThrow('Authentication token is required');
32
- console.log('Correctly rejected create with whitespace token');
33
- });
34
- });
35
- describe('list parameter validation', () => {
36
- const mockBaseUrl = 'https://example.com';
37
- it('should fail when token is missing', async () => {
38
- console.log('Testing list with missing token...');
39
- await expect(
40
- // @ts-expect-error Testing undefined token
41
- runtimes.listRuntimes(undefined, mockBaseUrl)).rejects.toThrow('Authentication token is required');
42
- console.log('Correctly rejected list with missing token');
43
- });
44
- it('should fail when token is null', async () => {
45
- console.log('Testing list with null token...');
46
- await expect(
47
- // @ts-expect-error Testing null token
48
- runtimes.listRuntimes(null, mockBaseUrl)).rejects.toThrow('Authentication token is required');
49
- console.log('Correctly rejected list with null token');
50
- });
51
- it('should fail when token is empty', async () => {
52
- console.log('Testing list with empty token...');
53
- await expect(runtimes.listRuntimes('', mockBaseUrl)).rejects.toThrow('Authentication token is required');
54
- console.log('Correctly rejected list with empty token');
55
- });
56
- it('should fail when token is only whitespace', async () => {
57
- console.log('Testing list with whitespace token...');
58
- await expect(runtimes.listRuntimes(' ', mockBaseUrl)).rejects.toThrow('Authentication token is required');
59
- console.log('Correctly rejected list with whitespace token');
60
- });
61
- });
62
- describe('get parameter validation', () => {
63
- const mockBaseUrl = 'https://example.com';
64
- it('should fail when token is missing', async () => {
65
- console.log('Testing get with missing token...');
66
- await expect(
67
- // @ts-expect-error Testing undefined token
68
- runtimes.getRuntime(undefined, 'pod-123', mockBaseUrl)).rejects.toThrow('Authentication token is required');
69
- console.log('Correctly rejected get with missing token');
70
- });
71
- it('should fail when pod name is missing', async () => {
72
- console.log('Testing get with missing pod name...');
73
- await expect(
74
- // @ts-expect-error Testing undefined pod name
75
- runtimes.getRuntime(MOCK_JWT_TOKEN, undefined, mockBaseUrl)).rejects.toThrow('Pod name is required');
76
- console.log('Correctly rejected get with missing pod name');
77
- });
78
- it('should fail when pod name is empty', async () => {
79
- console.log('Testing get with empty pod name...');
80
- await expect(runtimes.getRuntime(MOCK_JWT_TOKEN, '', mockBaseUrl)).rejects.toThrow('Pod name is required');
81
- console.log('Correctly rejected get with empty pod name');
82
- });
83
- it('should fail when pod name is only whitespace', async () => {
84
- console.log('Testing get with whitespace pod name...');
85
- await expect(runtimes.getRuntime(MOCK_JWT_TOKEN, ' ', mockBaseUrl)).rejects.toThrow('Pod name is required');
86
- console.log('Correctly rejected get with whitespace pod name');
87
- });
88
- });
89
- describe('remove parameter validation', () => {
90
- const mockBaseUrl = 'https://example.com';
91
- it('should fail when token is missing', async () => {
92
- console.log('Testing remove with missing token...');
93
- await expect(
94
- // @ts-expect-error Testing undefined token
95
- runtimes.deleteRuntime(undefined, 'pod-123', mockBaseUrl)).rejects.toThrow('Authentication token is required');
96
- console.log('Correctly rejected remove with missing token');
97
- });
98
- it('should fail when pod name is missing', async () => {
99
- console.log('Testing remove with missing pod name...');
100
- await expect(
101
- // @ts-expect-error Testing undefined pod name
102
- runtimes.deleteRuntime(MOCK_JWT_TOKEN, undefined, mockBaseUrl)).rejects.toThrow('Pod name is required');
103
- console.log('Correctly rejected remove with missing pod name');
104
- });
105
- it('should fail when pod name is empty', async () => {
106
- console.log('Testing remove with empty pod name...');
107
- await expect(runtimes.deleteRuntime(MOCK_JWT_TOKEN, '', mockBaseUrl)).rejects.toThrow('Pod name is required');
108
- console.log('Correctly rejected remove with empty pod name');
109
- });
110
- it('should fail when pod name is only whitespace', async () => {
111
- console.log('Testing remove with whitespace pod name...');
112
- await expect(runtimes.deleteRuntime(MOCK_JWT_TOKEN, ' ', mockBaseUrl)).rejects.toThrow('Pod name is required');
113
- console.log('Correctly rejected remove with whitespace pod name');
114
- });
115
- });
116
- describe('put parameter validation', () => {
117
- const mockBaseUrl = 'https://example.com';
118
- it('should fail when token is missing', async () => {
119
- console.log('Testing put with missing token...');
120
- await expect(runtimes.updateRuntime(undefined, 'pod-123', 'snapshot-123', mockBaseUrl)).rejects.toThrow('Authentication token is required');
121
- console.log('Correctly rejected put with missing token');
122
- });
123
- it('should fail when pod name is missing', async () => {
124
- console.log('Testing put with missing pod name...');
125
- await expect(runtimes.updateRuntime(MOCK_JWT_TOKEN, undefined, 'snapshot-123', mockBaseUrl)).rejects.toThrow('Pod name is required');
126
- console.log('Correctly rejected put with missing pod name');
127
- });
128
- it('should fail when pod name is empty', async () => {
129
- console.log('Testing put with empty pod name...');
130
- await expect(runtimes.updateRuntime(MOCK_JWT_TOKEN, '', 'snapshot-123', mockBaseUrl)).rejects.toThrow('Pod name is required');
131
- console.log('Correctly rejected put with empty pod name');
132
- });
133
- it('should fail when pod name is only whitespace', async () => {
134
- console.log('Testing put with whitespace pod name...');
135
- await expect(runtimes.updateRuntime(MOCK_JWT_TOKEN, ' ', 'snapshot-123', mockBaseUrl)).rejects.toThrow('Pod name is required');
136
- console.log('Correctly rejected put with whitespace pod name');
137
- });
138
- });
139
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,96 +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 { snapshots } from '..';
7
- import { MOCK_JWT_TOKEN } from '../../../__tests__/shared/test-constants';
8
- describe('Runtimes Snapshots Unit Tests', () => {
9
- describe('create parameter validation', () => {
10
- const mockBaseUrl = 'https://example.com';
11
- const mockData = {
12
- pod_name: 'pod-123',
13
- name: 'my-snapshot',
14
- description: 'Test snapshot',
15
- stop: true,
16
- };
17
- it('should fail when token is missing', async () => {
18
- console.log('Testing create with missing token...');
19
- await expect(
20
- // @ts-expect-error Testing undefined token
21
- snapshots.createSnapshot(undefined, mockData, mockBaseUrl)).rejects.toThrow('Authentication token is required');
22
- console.log('Correctly rejected create with missing token');
23
- });
24
- it('should fail when token is empty', async () => {
25
- console.log('Testing create with empty token...');
26
- await expect(snapshots.createSnapshot('', mockData, mockBaseUrl)).rejects.toThrow('Authentication token is required');
27
- console.log('Correctly rejected create with empty token');
28
- });
29
- it('should fail when token is only whitespace', async () => {
30
- console.log('Testing create with whitespace token...');
31
- await expect(snapshots.createSnapshot(' ', mockData, mockBaseUrl)).rejects.toThrow('Authentication token is required');
32
- console.log('Correctly rejected create with whitespace token');
33
- });
34
- });
35
- describe('list parameter validation', () => {
36
- const mockBaseUrl = 'https://example.com';
37
- it('should fail when token is missing', async () => {
38
- console.log('Testing list with missing token...');
39
- await expect(
40
- // @ts-expect-error Testing undefined token
41
- snapshots.listSnapshots(undefined, mockBaseUrl)).rejects.toThrow('Authentication token is required');
42
- console.log('Correctly rejected list with missing token');
43
- });
44
- it('should fail when token is null', async () => {
45
- console.log('Testing list with null token...');
46
- await expect(
47
- // @ts-expect-error Testing null token
48
- snapshots.listSnapshots(null, mockBaseUrl)).rejects.toThrow('Authentication token is required');
49
- console.log('Correctly rejected list with null token');
50
- });
51
- });
52
- describe('get parameter validation', () => {
53
- const mockBaseUrl = 'https://example.com';
54
- it('should fail when token is missing', async () => {
55
- console.log('Testing get with missing token...');
56
- await expect(
57
- // @ts-expect-error Testing undefined token
58
- snapshots.getSnapshot(undefined, 'snapshot-123', mockBaseUrl)).rejects.toThrow('Authentication token is required');
59
- console.log('Correctly rejected get with missing token');
60
- });
61
- it('should fail when snapshot ID is missing', async () => {
62
- console.log('Testing get with missing snapshot ID...');
63
- await expect(
64
- // @ts-expect-error Testing undefined snapshot ID
65
- snapshots.getSnapshot(MOCK_JWT_TOKEN, undefined, mockBaseUrl)).rejects.toThrow('Snapshot ID is required');
66
- console.log('Correctly rejected get with missing snapshot ID');
67
- });
68
- it('should fail when snapshot ID is empty', async () => {
69
- console.log('Testing get with empty snapshot ID...');
70
- await expect(snapshots.getSnapshot(MOCK_JWT_TOKEN, '', mockBaseUrl)).rejects.toThrow('Snapshot ID is required');
71
- console.log('Correctly rejected get with empty snapshot ID');
72
- });
73
- it('should fail when snapshot ID is only whitespace', async () => {
74
- console.log('Testing get with whitespace snapshot ID...');
75
- await expect(snapshots.getSnapshot(MOCK_JWT_TOKEN, ' ', mockBaseUrl)).rejects.toThrow('Snapshot ID is required');
76
- console.log('Correctly rejected get with whitespace snapshot ID');
77
- });
78
- });
79
- describe('remove parameter validation', () => {
80
- const mockBaseUrl = 'https://example.com';
81
- it('should fail when token is missing', async () => {
82
- console.log('Testing remove with missing token...');
83
- await expect(
84
- // @ts-expect-error Testing undefined token
85
- snapshots.deleteSnapshot(undefined, 'snapshot-123', mockBaseUrl)).rejects.toThrow('Authentication token is required');
86
- console.log('Correctly rejected remove with missing token');
87
- });
88
- it('should fail when snapshot ID is missing', async () => {
89
- console.log('Testing remove with missing snapshot ID...');
90
- await expect(
91
- // @ts-expect-error Testing undefined snapshot ID
92
- snapshots.deleteSnapshot(MOCK_JWT_TOKEN, undefined, mockBaseUrl)).rejects.toThrow('Snapshot ID is required');
93
- console.log('Correctly rejected remove with missing snapshot ID');
94
- });
95
- });
96
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,57 +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, vi, beforeEach } from 'vitest';
6
- import { healthz } from '..';
7
- import { requestDatalayerAPI } from '../../DatalayerApi';
8
- // Mock the DatalayerAPI module
9
- vi.mock('../../DatalayerApi');
10
- describe('Spacer Healthz Unit Tests', () => {
11
- beforeEach(() => {
12
- vi.clearAllMocks();
13
- });
14
- describe('ping', () => {
15
- it('should successfully ping the service', async () => {
16
- const mockResponse = {
17
- success: true,
18
- message: 'Spacer service is healthy',
19
- status: {
20
- status: 'OK',
21
- },
22
- version: '1.0.0',
23
- };
24
- vi.mocked(requestDatalayerAPI).mockResolvedValueOnce(mockResponse);
25
- const result = await healthz.ping('https://test.datalayer.run');
26
- expect(result).toEqual(mockResponse);
27
- expect(requestDatalayerAPI).toHaveBeenCalledWith({
28
- url: 'https://test.datalayer.run/api/spacer/v1/ping',
29
- method: 'GET',
30
- });
31
- });
32
- it('should use default URL when not provided', async () => {
33
- const mockResponse = {
34
- success: true,
35
- message: 'Service is healthy',
36
- };
37
- vi.mocked(requestDatalayerAPI).mockResolvedValueOnce(mockResponse);
38
- const result = await healthz.ping();
39
- expect(result).toEqual(mockResponse);
40
- expect(requestDatalayerAPI).toHaveBeenCalledWith({
41
- url: 'https://prod1.datalayer.run/api/spacer/v1/ping',
42
- method: 'GET',
43
- });
44
- });
45
- it('should handle service unhealthy errors', async () => {
46
- const mockError = new Error('Service error');
47
- mockError.response = { status: 500 };
48
- vi.mocked(requestDatalayerAPI).mockRejectedValueOnce(mockError);
49
- await expect(healthz.ping()).rejects.toThrow('Health check failed: Service unhealthy (status 500)');
50
- });
51
- it('should handle network errors', async () => {
52
- const mockError = new Error('Network error');
53
- vi.mocked(requestDatalayerAPI).mockRejectedValueOnce(mockError);
54
- await expect(healthz.ping()).rejects.toThrow('Health check failed: Network error');
55
- });
56
- });
57
- });
@@ -1 +0,0 @@
1
- export {};