@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,224 +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 { notebooks } from '..';
7
- import * as DatalayerApi from '../../DatalayerApi';
8
- import { API_BASE_PATHS, DEFAULT_SERVICE_URLS } from '../../constants';
9
- import { MOCK_JWT_TOKEN } from '../../../__tests__/shared/test-constants';
10
- // Mock the DatalayerApi module
11
- vi.mock('../../DatalayerApi', () => ({
12
- requestDatalayerAPI: vi.fn(),
13
- }));
14
- describe('Spacer Notebooks Unit Tests', () => {
15
- beforeEach(() => {
16
- vi.clearAllMocks();
17
- });
18
- describe('create', () => {
19
- const mockCreateResponse = {
20
- success: true,
21
- message: 'Notebook created successfully',
22
- notebook: {
23
- id: 'notebook-123',
24
- uid: 'uid-notebook-123',
25
- name: 'Test Notebook',
26
- path: '/notebooks/test-notebook',
27
- space_id: 'space-456',
28
- owner_id: 'user-789',
29
- created_at: '2024-01-01T00:00:00Z',
30
- },
31
- };
32
- it('should successfully create a notebook with FormData', async () => {
33
- console.log('Testing notebook creation with FormData...');
34
- const mockedRequest = vi.mocked(DatalayerApi.requestDatalayerAPI);
35
- mockedRequest.mockResolvedValue(mockCreateResponse);
36
- const notebookData = {
37
- spaceId: 'space-456',
38
- notebookType: 'jupyter',
39
- name: 'Test Notebook',
40
- description: 'A test notebook',
41
- };
42
- const result = await notebooks.createNotebook(MOCK_JWT_TOKEN, notebookData, DEFAULT_SERVICE_URLS.SPACER);
43
- expect(mockedRequest).toHaveBeenCalledTimes(1);
44
- // Check that FormData was passed as the body
45
- const callArgs = mockedRequest.mock.calls[0][0];
46
- expect(callArgs.url).toBe(`${DEFAULT_SERVICE_URLS.SPACER}${API_BASE_PATHS.SPACER}/notebooks`);
47
- expect(callArgs.method).toBe('POST');
48
- expect(callArgs.token).toBe(MOCK_JWT_TOKEN);
49
- expect(callArgs.body).toBeInstanceOf(FormData);
50
- expect(result).toEqual(mockCreateResponse);
51
- expect(result.success).toBe(true);
52
- expect(result.notebook.name).toBe('Test Notebook');
53
- console.log('Notebook created successfully');
54
- });
55
- it('should handle FormData with file attachment', async () => {
56
- console.log('Testing notebook creation with file...');
57
- const mockedRequest = vi.mocked(DatalayerApi.requestDatalayerAPI);
58
- mockedRequest.mockResolvedValue(mockCreateResponse);
59
- const file = new File(['notebook content'], 'test.ipynb', {
60
- type: 'application/json',
61
- });
62
- const notebookData = {
63
- spaceId: 'space-456',
64
- notebookType: 'jupyter',
65
- name: 'Test Notebook',
66
- description: 'A test notebook',
67
- file,
68
- };
69
- await notebooks.createNotebook(MOCK_JWT_TOKEN, notebookData, DEFAULT_SERVICE_URLS.SPACER);
70
- const callArgs = mockedRequest.mock.calls[0][0];
71
- expect(callArgs.url).toBe(`${DEFAULT_SERVICE_URLS.SPACER}${API_BASE_PATHS.SPACER}/notebooks`);
72
- expect(callArgs.method).toBe('POST');
73
- expect(callArgs.token).toBe(MOCK_JWT_TOKEN);
74
- expect(callArgs.body).toBeInstanceOf(FormData);
75
- console.log('Notebook with file created successfully');
76
- });
77
- it('should handle API errors during creation', async () => {
78
- console.log('Testing notebook creation with API error...');
79
- const mockedRequest = vi.mocked(DatalayerApi.requestDatalayerAPI);
80
- mockedRequest.mockRejectedValue(new Error('API Error'));
81
- const formData = new FormData();
82
- formData.append('spaceId', 'space-456');
83
- formData.append('notebookType', 'jupyter');
84
- formData.append('name', 'Test Notebook');
85
- formData.append('description', 'A test notebook');
86
- await expect(notebooks.createNotebook(MOCK_JWT_TOKEN, formData, DEFAULT_SERVICE_URLS.SPACER)).rejects.toThrow('API Error');
87
- console.log('API error handled correctly');
88
- });
89
- });
90
- describe('get', () => {
91
- const mockGetResponse = {
92
- success: true,
93
- message: 'Notebook retrieved successfully',
94
- notebook: {
95
- id: 'notebook-123',
96
- uid: 'uid-notebook-123',
97
- name: 'Test Notebook',
98
- path: '/notebooks/test-notebook',
99
- space_id: 'space-456',
100
- owner_id: 'user-789',
101
- created_at: '2024-01-01T00:00:00Z',
102
- updated_at: '2024-01-02T00:00:00Z',
103
- },
104
- };
105
- it('should successfully get a notebook by ID', async () => {
106
- console.log('Testing get notebook by ID...');
107
- const mockedRequest = vi.mocked(DatalayerApi.requestDatalayerAPI);
108
- mockedRequest.mockResolvedValue(mockGetResponse);
109
- const result = await notebooks.getNotebook(MOCK_JWT_TOKEN, 'notebook-123', DEFAULT_SERVICE_URLS.SPACER);
110
- expect(mockedRequest).toHaveBeenCalledTimes(1);
111
- expect(mockedRequest).toHaveBeenCalledWith({
112
- url: `${DEFAULT_SERVICE_URLS.SPACER}${API_BASE_PATHS.SPACER}/notebooks/notebook-123`,
113
- method: 'GET',
114
- token: MOCK_JWT_TOKEN,
115
- });
116
- expect(result).toEqual(mockGetResponse);
117
- expect(result.success).toBe(true);
118
- expect(result.notebook?.id).toBe('notebook-123');
119
- console.log('Notebook retrieved successfully');
120
- });
121
- it('should handle notebook not found (404)', async () => {
122
- console.log('Testing get notebook with 404...');
123
- const notFoundResponse = {
124
- success: false,
125
- message: 'Notebook not found',
126
- };
127
- const mockedRequest = vi.mocked(DatalayerApi.requestDatalayerAPI);
128
- mockedRequest.mockResolvedValue(notFoundResponse);
129
- const result = await notebooks.getNotebook(MOCK_JWT_TOKEN, 'nonexistent-notebook', DEFAULT_SERVICE_URLS.SPACER);
130
- expect(result).toEqual(notFoundResponse);
131
- expect(result.success).toBe(false);
132
- expect(result.notebook).toBeUndefined();
133
- console.log('404 response handled correctly');
134
- });
135
- it('should handle API errors during get', async () => {
136
- console.log('Testing get notebook with API error...');
137
- const mockedRequest = vi.mocked(DatalayerApi.requestDatalayerAPI);
138
- mockedRequest.mockRejectedValue(new Error('Network error'));
139
- await expect(notebooks.getNotebook(MOCK_JWT_TOKEN, 'notebook-123', DEFAULT_SERVICE_URLS.SPACER)).rejects.toThrow('Network error');
140
- console.log('API error handled correctly');
141
- });
142
- });
143
- describe('update', () => {
144
- const mockUpdateResponse = {
145
- success: true,
146
- message: 'Notebook updated successfully',
147
- notebook: {
148
- id: 'notebook-123',
149
- uid: 'uid-notebook-123',
150
- name: 'Updated Notebook',
151
- path: '/notebooks/updated-notebook',
152
- space_id: 'space-456',
153
- owner_id: 'user-789',
154
- created_at: '2024-01-01T00:00:00Z',
155
- updated_at: '2024-01-03T00:00:00Z',
156
- },
157
- };
158
- it('should successfully update a notebook name', async () => {
159
- console.log('Testing update notebook name...');
160
- const mockedRequest = vi.mocked(DatalayerApi.requestDatalayerAPI);
161
- mockedRequest.mockResolvedValue(mockUpdateResponse);
162
- const updateData = {
163
- name: 'Updated Notebook',
164
- };
165
- const result = await notebooks.updateNotebook(MOCK_JWT_TOKEN, 'notebook-123', updateData, DEFAULT_SERVICE_URLS.SPACER);
166
- expect(mockedRequest).toHaveBeenCalledTimes(1);
167
- expect(mockedRequest).toHaveBeenCalledWith({
168
- url: `${DEFAULT_SERVICE_URLS.SPACER}${API_BASE_PATHS.SPACER}/notebooks/notebook-123`,
169
- method: 'PUT',
170
- token: MOCK_JWT_TOKEN,
171
- body: updateData,
172
- });
173
- expect(result).toEqual(mockUpdateResponse);
174
- expect(result.success).toBe(true);
175
- expect(result.notebook.name).toBe('Updated Notebook');
176
- console.log('Notebook name updated successfully');
177
- });
178
- it('should successfully update a notebook description', async () => {
179
- console.log('Testing update notebook description...');
180
- const mockedRequest = vi.mocked(DatalayerApi.requestDatalayerAPI);
181
- mockedRequest.mockResolvedValue(mockUpdateResponse);
182
- const updateData = {
183
- description: 'Updated description',
184
- };
185
- const result = await notebooks.updateNotebook(MOCK_JWT_TOKEN, 'notebook-123', updateData, DEFAULT_SERVICE_URLS.SPACER);
186
- expect(mockedRequest).toHaveBeenCalledWith({
187
- url: `${DEFAULT_SERVICE_URLS.SPACER}${API_BASE_PATHS.SPACER}/notebooks/notebook-123`,
188
- method: 'PUT',
189
- token: MOCK_JWT_TOKEN,
190
- body: updateData,
191
- });
192
- expect(result.success).toBe(true);
193
- console.log('Notebook description updated successfully');
194
- });
195
- it('should successfully update both name and description', async () => {
196
- console.log('Testing update notebook name and description...');
197
- const mockedRequest = vi.mocked(DatalayerApi.requestDatalayerAPI);
198
- mockedRequest.mockResolvedValue(mockUpdateResponse);
199
- const updateData = {
200
- name: 'Updated Notebook',
201
- description: 'Updated description',
202
- };
203
- const result = await notebooks.updateNotebook(MOCK_JWT_TOKEN, 'notebook-123', updateData, DEFAULT_SERVICE_URLS.SPACER);
204
- expect(mockedRequest).toHaveBeenCalledWith({
205
- url: `${DEFAULT_SERVICE_URLS.SPACER}${API_BASE_PATHS.SPACER}/notebooks/notebook-123`,
206
- method: 'PUT',
207
- token: MOCK_JWT_TOKEN,
208
- body: updateData,
209
- });
210
- expect(result.success).toBe(true);
211
- console.log('Notebook name and description updated successfully');
212
- });
213
- it('should handle API errors during update', async () => {
214
- console.log('Testing update notebook with API error...');
215
- const mockedRequest = vi.mocked(DatalayerApi.requestDatalayerAPI);
216
- mockedRequest.mockRejectedValue(new Error('Update failed'));
217
- const updateData = {
218
- name: 'Updated Notebook',
219
- };
220
- await expect(notebooks.updateNotebook(MOCK_JWT_TOKEN, 'notebook-123', updateData, DEFAULT_SERVICE_URLS.SPACER)).rejects.toThrow('Update failed');
221
- console.log('API error handled correctly');
222
- });
223
- });
224
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,132 +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 { users } from '..';
7
- import * as DatalayerApi from '../../DatalayerApi';
8
- import { API_BASE_PATHS, DEFAULT_SERVICE_URLS } from '../../constants';
9
- import { MOCK_JWT_TOKEN } from '../../../__tests__/shared/test-constants';
10
- // Mock the DatalayerApi module
11
- vi.mock('../../DatalayerApi', () => ({
12
- requestDatalayerAPI: vi.fn(),
13
- }));
14
- describe('Spacer Users Unit Tests', () => {
15
- beforeEach(() => {
16
- vi.clearAllMocks();
17
- });
18
- describe('getMySpaces', () => {
19
- const mockSpacesResponse = {
20
- success: true,
21
- message: 'Spaces retrieved successfully',
22
- spaces: [
23
- {
24
- id: 'space-1',
25
- uid: 'uid-space-1',
26
- name: 'My First Space',
27
- description: 'A test space',
28
- owner_id: 'user-123',
29
- created_at: '2024-01-01T00:00:00Z',
30
- updated_at: '2024-01-02T00:00:00Z',
31
- },
32
- {
33
- id: 'space-2',
34
- uid: 'uid-space-2',
35
- name: 'My Second Space',
36
- description: 'Another test space',
37
- owner_id: 'user-123',
38
- created_at: '2024-01-03T00:00:00Z',
39
- updated_at: '2024-01-04T00:00:00Z',
40
- },
41
- ],
42
- };
43
- it('should successfully get user spaces', async () => {
44
- console.log('Testing getMySpaces with valid token...');
45
- const mockedRequest = vi.mocked(DatalayerApi.requestDatalayerAPI);
46
- mockedRequest.mockResolvedValue(mockSpacesResponse);
47
- const result = await users.getMySpaces(MOCK_JWT_TOKEN);
48
- expect(mockedRequest).toHaveBeenCalledTimes(1);
49
- expect(mockedRequest).toHaveBeenCalledWith({
50
- url: `${DEFAULT_SERVICE_URLS.SPACER}${API_BASE_PATHS.SPACER}/spaces/users/me`,
51
- method: 'GET',
52
- token: MOCK_JWT_TOKEN,
53
- });
54
- expect(result).toEqual(mockSpacesResponse);
55
- expect(result.spaces).toHaveLength(2);
56
- console.log('Successfully retrieved user spaces');
57
- });
58
- it('should use custom base URL when provided', async () => {
59
- console.log('Testing getMySpaces with custom base URL...');
60
- const customUrl = 'https://custom.spacer.api';
61
- const mockedRequest = vi.mocked(DatalayerApi.requestDatalayerAPI);
62
- mockedRequest.mockResolvedValue(mockSpacesResponse);
63
- await users.getMySpaces(MOCK_JWT_TOKEN, customUrl);
64
- expect(mockedRequest).toHaveBeenCalledWith({
65
- url: `${customUrl}${API_BASE_PATHS.SPACER}/spaces/users/me`,
66
- method: 'GET',
67
- token: MOCK_JWT_TOKEN,
68
- });
69
- console.log('Custom base URL used correctly');
70
- });
71
- it('should handle empty spaces list', async () => {
72
- console.log('Testing getMySpaces with empty response...');
73
- const emptyResponse = {
74
- success: true,
75
- message: 'No spaces found for user',
76
- spaces: [],
77
- };
78
- const mockedRequest = vi.mocked(DatalayerApi.requestDatalayerAPI);
79
- mockedRequest.mockResolvedValue(emptyResponse);
80
- const result = await users.getMySpaces(MOCK_JWT_TOKEN);
81
- expect(result).toEqual(emptyResponse);
82
- expect(result.spaces).toHaveLength(0);
83
- console.log('Empty spaces list handled correctly');
84
- });
85
- it('should fail when token is missing', async () => {
86
- console.log('Testing getMySpaces with missing token...');
87
- await expect(
88
- // @ts-expect-error Testing undefined token
89
- users.getMySpaces(undefined)).rejects.toThrow('Authentication token is required');
90
- console.log('Correctly rejected missing token');
91
- });
92
- it('should fail when token is empty', async () => {
93
- console.log('Testing getMySpaces with empty token...');
94
- await expect(users.getMySpaces('')).rejects.toThrow('Authentication token is required');
95
- console.log('Correctly rejected empty token');
96
- });
97
- it('should fail when token is only whitespace', async () => {
98
- console.log('Testing getMySpaces with whitespace token...');
99
- await expect(users.getMySpaces(' ')).rejects.toThrow('Authentication token is required');
100
- console.log('Correctly rejected whitespace token');
101
- });
102
- it('should fail when token is null', async () => {
103
- console.log('Testing getMySpaces with null token...');
104
- await expect(
105
- // @ts-expect-error Testing null token
106
- users.getMySpaces(null)).rejects.toThrow('Authentication token is required');
107
- console.log('Correctly rejected null token');
108
- });
109
- it('should handle API errors gracefully', async () => {
110
- console.log('Testing getMySpaces with API error...');
111
- const mockedRequest = vi.mocked(DatalayerApi.requestDatalayerAPI);
112
- mockedRequest.mockRejectedValue(new Error('Network error'));
113
- await expect(users.getMySpaces(MOCK_JWT_TOKEN)).rejects.toThrow('Network error');
114
- console.log('API error handled correctly');
115
- });
116
- it('should handle malformed response', async () => {
117
- console.log('Testing getMySpaces with malformed response...');
118
- const malformedResponse = {
119
- success: false,
120
- message: 'Invalid response format',
121
- // spaces array is missing
122
- };
123
- const mockedRequest = vi.mocked(DatalayerApi.requestDatalayerAPI);
124
- mockedRequest.mockResolvedValue(malformedResponse);
125
- const result = await users.getMySpaces(MOCK_JWT_TOKEN);
126
- expect(result).toEqual(malformedResponse);
127
- // Should not throw, but spaces will be undefined
128
- expect(result.spaces).toBeUndefined();
129
- console.log('Malformed response handled gracefully');
130
- });
131
- });
132
- });
@@ -1,32 +0,0 @@
1
- /**
2
- * @module types
3
- * @description TypeScript type definitions for all Datalayer API services.
4
- *
5
- * This module consolidates all type definitions used by the SDK, providing
6
- * comprehensive TypeScript support for requests, responses, and data models
7
- * across all Datalayer services.
8
- *
9
- * These types follow the exact backend API format (snake_case naming) to
10
- * ensure compatibility. For frontend business logic types with camelCase
11
- * naming, see the models in `/src/models/`.
12
- *
13
- * @example
14
- * ```typescript
15
- * import type {
16
- * Runtime,
17
- * Environment,
18
- * Space,
19
- * Notebook,
20
- * User,
21
- * LoginRequest
22
- * } from '@datalayer/core/api/types';
23
- *
24
- * // Use types for function parameters and return values
25
- * function createRuntime(config: CreateRuntimeRequest): Promise<Runtime> {
26
- * // Implementation
27
- * }
28
- * ```
29
- */
30
- export * from './runtimes';
31
- export * from './iam';
32
- export * from './spacer';
@@ -1,36 +0,0 @@
1
- /*
2
- * Copyright (c) 2023-2025 Datalayer, Inc.
3
- * Distributed under the terms of the Modified BSD License.
4
- */
5
- /**
6
- * @module types
7
- * @description TypeScript type definitions for all Datalayer API services.
8
- *
9
- * This module consolidates all type definitions used by the SDK, providing
10
- * comprehensive TypeScript support for requests, responses, and data models
11
- * across all Datalayer services.
12
- *
13
- * These types follow the exact backend API format (snake_case naming) to
14
- * ensure compatibility. For frontend business logic types with camelCase
15
- * naming, see the models in `/src/models/`.
16
- *
17
- * @example
18
- * ```typescript
19
- * import type {
20
- * Runtime,
21
- * Environment,
22
- * Space,
23
- * Notebook,
24
- * User,
25
- * LoginRequest
26
- * } from '@datalayer/core/api/types';
27
- *
28
- * // Use types for function parameters and return values
29
- * function createRuntime(config: CreateRuntimeRequest): Promise<Runtime> {
30
- * // Implementation
31
- * }
32
- * ```
33
- */
34
- export * from './runtimes';
35
- export * from './iam';
36
- export * from './spacer';
@@ -1,235 +0,0 @@
1
- /**
2
- * Represents a computing environment available in the Datalayer platform
3
- * @interface Environment
4
- */
5
- export interface Environment {
6
- /** Human-readable title for the environment */
7
- title: string;
8
- /** Detailed description of the environment */
9
- description: string;
10
- /** Docker image used for this environment */
11
- dockerImage: string;
12
- /** Example usage or description */
13
- example?: string;
14
- /** Code snippets for this environment */
15
- snippets?: any[];
16
- /** Content mounts for this environment */
17
- contents?: any[];
18
- /** Kernel configuration */
19
- kernel?: {
20
- /** Template for kernel naming */
21
- givenNameTemplate?: string;
22
- };
23
- /** Programming language (e.g., "python", "r") */
24
- language: string;
25
- /** Resource ranges configuration */
26
- resourcesRanges?: any;
27
- /** Credits consumed per hour when running */
28
- burning_rate: number;
29
- /** Simple resource specification */
30
- resources?: any;
31
- /** Name identifier for the environment */
32
- name?: string;
33
- /** Docker registry for the image */
34
- dockerRegistry?: string;
35
- /** Icon or avatar URL for the environment */
36
- icon?: string;
37
- /** Whether the environment is enabled */
38
- enabled?: boolean;
39
- /** Tags associated with the environment */
40
- tags?: string[];
41
- }
42
- /**
43
- * Represents a running instance of a computing environment
44
- * @interface Runtime
45
- */
46
- export interface Runtime {
47
- /** Kubernetes pod name for the runtime instance */
48
- pod_name: string;
49
- /** Unique identifier for the runtime */
50
- uid: string;
51
- /** Name of the environment this runtime is based on */
52
- environment_name: string;
53
- /** Title of the environment for display */
54
- environment_title?: string;
55
- /** Credits allocated to this runtime */
56
- credits?: number;
57
- /** Current state of the runtime */
58
- state?: 'starting' | 'running' | 'stopping' | 'stopped' | 'error';
59
- /** Type of runtime - notebook, terminal, or job */
60
- type?: 'notebook' | 'terminal' | 'job';
61
- /** Type of runtime (deprecated, use type) */
62
- runtime_type?: 'notebook' | 'cell';
63
- /** Credits consumed per hour */
64
- burning_rate: number;
65
- /** User-friendly name for the runtime */
66
- given_name?: string;
67
- /** Authentication token for accessing the runtime */
68
- token?: string;
69
- /** Ingress URL for accessing the runtime */
70
- ingress?: string;
71
- /** Reservation ID if runtime is reserved */
72
- reservation_id?: string;
73
- /** ISO 8601 timestamp of when the runtime started */
74
- started_at?: string;
75
- /** ISO 8601 timestamp of when the runtime will expire */
76
- expired_at?: string;
77
- /** ISO 8601 timestamp of when the runtime was created */
78
- created_at?: string;
79
- /** ISO 8601 timestamp of last update */
80
- updated_at?: string;
81
- /** Jupyter kernel ID if applicable */
82
- kernel_id?: string;
83
- /** Path to the notebook file if runtime is for a notebook */
84
- notebook_path?: string;
85
- /** Cell ID if runtime is for a specific cell */
86
- cell_id?: string;
87
- /** URL for accessing Jupyter server */
88
- jupyter_url?: string;
89
- /** Token for Jupyter server authentication */
90
- jupyter_token?: string;
91
- /** Detailed status information */
92
- status?: any;
93
- /** Alternative naming from API responses */
94
- podName?: string;
95
- /** Alternative naming from API responses */
96
- createdAt?: string;
97
- /** Alternative naming from API responses */
98
- environment?: string;
99
- }
100
- /**
101
- * Request payload for creating a new runtime
102
- * @interface CreateRuntimeRequest
103
- */
104
- export interface CreateRuntimeRequest {
105
- /** Name of the environment to use */
106
- environment_name: string;
107
- /** Type of runtime (e.g., 'notebook', 'terminal', 'job') */
108
- type?: 'notebook' | 'terminal' | 'job';
109
- /** Optional given name for the runtime */
110
- given_name?: string;
111
- /** Maximum credits this runtime can consume */
112
- credits_limit?: number;
113
- /** Optional capabilities for the runtime */
114
- capabilities?: string[];
115
- /** Optional source to create runtime from (e.g., snapshot ID) */
116
- from?: string;
117
- }
118
- /**
119
- * Represents a snapshot of a runtime's state and files
120
- * @interface RuntimeSnapshot
121
- */
122
- export interface RuntimeSnapshot {
123
- /** Unique identifier for the snapshot */
124
- uid: string;
125
- /** Name of the snapshot */
126
- name: string;
127
- /** Optional description of the snapshot */
128
- description?: string;
129
- /** Name of the environment used by the runtime */
130
- environment: string;
131
- /** Metadata associated with the snapshot */
132
- metadata?: {
133
- version?: string;
134
- language_info?: any;
135
- [key: string]: any;
136
- };
137
- /** Size of the snapshot in bytes */
138
- size?: number;
139
- /** Format of the snapshot */
140
- format?: string;
141
- /** Format version of the snapshot */
142
- format_version?: string;
143
- /** Status of the snapshot */
144
- status?: string;
145
- /** ISO 8601 timestamp when the snapshot was last updated */
146
- updated_at: string;
147
- /** List of files included in the snapshot */
148
- files?: any[];
149
- }
150
- /**
151
- * Request payload for creating a runtime snapshot
152
- * @interface CreateRuntimeSnapshotRequest
153
- */
154
- export interface CreateRuntimeSnapshotRequest {
155
- /** Pod name of the runtime to snapshot */
156
- pod_name: string;
157
- /** Name for the snapshot */
158
- name: string;
159
- /** Description of the snapshot */
160
- description: string;
161
- /** Whether to stop the runtime after creating snapshot */
162
- stop: boolean;
163
- }
164
- /**
165
- * Response for getting a specific runtime snapshot
166
- * @interface SnapshotGetResponse
167
- */
168
- export interface SnapshotGetResponse {
169
- /** Indicates if the request was successful */
170
- success: boolean;
171
- /** Response message */
172
- message: string;
173
- /** The snapshot details */
174
- snapshot: RuntimeSnapshot;
175
- }
176
- /**
177
- * Response for creating a runtime snapshot
178
- * @interface SnapshotCreateResponse
179
- */
180
- export interface SnapshotCreateResponse {
181
- /** Indicates if the request was successful */
182
- success: boolean;
183
- /** Response message */
184
- message: string;
185
- /** The created snapshot details */
186
- snapshot: RuntimeSnapshot;
187
- }
188
- /**
189
- * Response from listing available environments
190
- * @interface EnvironmentsListResponse
191
- */
192
- export interface EnvironmentsListResponse {
193
- /** Whether the request was successful */
194
- success: boolean;
195
- /** Response message from the server */
196
- message: string;
197
- /** Array of available environments */
198
- environments: Environment[];
199
- }
200
- /**
201
- * Response from creating a new runtime
202
- * @interface RuntimeCreateResponse
203
- */
204
- export interface CreateRuntimeResponse {
205
- /** Whether the request was successful */
206
- success: boolean;
207
- /** Response message from the server */
208
- message: string;
209
- /** The created runtime instance */
210
- runtime: Runtime;
211
- }
212
- /**
213
- * Response from listing runtimes
214
- * @interface RuntimesListResponse
215
- */
216
- export interface RuntimesListResponse {
217
- /** Whether the request was successful */
218
- success: boolean;
219
- /** Response message from the server */
220
- message: string;
221
- /** Array of runtime instances */
222
- runtimes: Runtime[];
223
- }
224
- /**
225
- * Response from listing runtime snapshots
226
- * @interface RuntimeSnapshotsListResponse
227
- */
228
- export interface SnapshotsListResponse {
229
- /** Whether the request was successful */
230
- success: boolean;
231
- /** Response message from the server */
232
- message: string;
233
- /** Array of runtime snapshots */
234
- snapshots: RuntimeSnapshot[];
235
- }