@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,165 +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 { items } 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 Items Unit Tests', () => {
15
- beforeEach(() => {
16
- vi.clearAllMocks();
17
- });
18
- describe('getSpaceItems', () => {
19
- const mockGetItemsResponse = {
20
- success: true,
21
- message: 'Items retrieved successfully',
22
- items: [
23
- {
24
- id: 'item-1',
25
- type: 'notebook',
26
- space_id: 'space-123',
27
- item_id: 'notebook-456',
28
- name: 'My Notebook',
29
- created_at: '2024-01-01T00:00:00Z',
30
- updated_at: '2024-01-02T00:00:00Z',
31
- },
32
- {
33
- id: 'item-2',
34
- type: 'lexical',
35
- space_id: 'space-123',
36
- item_id: 'lexical-789',
37
- name: 'My Document',
38
- created_at: '2024-01-01T00:00:00Z',
39
- updated_at: '2024-01-02T00:00:00Z',
40
- },
41
- ],
42
- };
43
- it('should successfully get space items', async () => {
44
- console.log('Testing get space items...');
45
- const mockedRequest = vi.mocked(DatalayerApi.requestDatalayerAPI);
46
- mockedRequest.mockResolvedValue(mockGetItemsResponse);
47
- const result = await items.getSpaceItems(MOCK_JWT_TOKEN, 'space-123', DEFAULT_SERVICE_URLS.SPACER);
48
- expect(mockedRequest).toHaveBeenCalledTimes(1);
49
- expect(mockedRequest).toHaveBeenCalledWith({
50
- url: `${DEFAULT_SERVICE_URLS.SPACER}${API_BASE_PATHS.SPACER}/spaces/space-123/items`,
51
- method: 'GET',
52
- token: MOCK_JWT_TOKEN,
53
- });
54
- expect(result).toEqual(mockGetItemsResponse);
55
- expect(result.success).toBe(true);
56
- expect(result.items).toHaveLength(2);
57
- expect(result.items[0].type).toBe('notebook');
58
- expect(result.items[1].type).toBe('lexical');
59
- console.log('Space items retrieved successfully');
60
- });
61
- it('should handle empty items list', async () => {
62
- console.log('Testing get space items with empty response...');
63
- const emptyResponse = {
64
- success: true,
65
- message: 'No items found in space',
66
- items: [],
67
- };
68
- const mockedRequest = vi.mocked(DatalayerApi.requestDatalayerAPI);
69
- mockedRequest.mockResolvedValue(emptyResponse);
70
- const result = await items.getSpaceItems(MOCK_JWT_TOKEN, 'empty-space', DEFAULT_SERVICE_URLS.SPACER);
71
- expect(result).toEqual(emptyResponse);
72
- expect(result.items).toHaveLength(0);
73
- console.log('Empty items list handled correctly');
74
- });
75
- it('should use custom base URL when provided', async () => {
76
- console.log('Testing get space items with custom base URL...');
77
- const customUrl = 'https://custom.spacer.api';
78
- const mockedRequest = vi.mocked(DatalayerApi.requestDatalayerAPI);
79
- mockedRequest.mockResolvedValue(mockGetItemsResponse);
80
- await items.getSpaceItems(MOCK_JWT_TOKEN, 'space-123', customUrl);
81
- expect(mockedRequest).toHaveBeenCalledWith({
82
- url: `${customUrl}${API_BASE_PATHS.SPACER}/spaces/space-123/items`,
83
- method: 'GET',
84
- token: MOCK_JWT_TOKEN,
85
- });
86
- console.log('Custom base URL used correctly');
87
- });
88
- it('should handle API errors during get', async () => {
89
- console.log('Testing get space items with API error...');
90
- const mockedRequest = vi.mocked(DatalayerApi.requestDatalayerAPI);
91
- mockedRequest.mockRejectedValue(new Error('Network error'));
92
- await expect(items.getSpaceItems(MOCK_JWT_TOKEN, 'space-123', DEFAULT_SERVICE_URLS.SPACER)).rejects.toThrow('Network error');
93
- console.log('API error handled correctly');
94
- });
95
- });
96
- describe('deleteItem', () => {
97
- const mockDeleteResponse = {
98
- success: true,
99
- message: 'Item deleted successfully',
100
- };
101
- it('should successfully delete an item', async () => {
102
- console.log('Testing delete item...');
103
- const mockedRequest = vi.mocked(DatalayerApi.requestDatalayerAPI);
104
- mockedRequest.mockResolvedValue(mockDeleteResponse);
105
- const result = await items.deleteItem(MOCK_JWT_TOKEN, 'item-123', DEFAULT_SERVICE_URLS.SPACER);
106
- expect(mockedRequest).toHaveBeenCalledTimes(1);
107
- expect(mockedRequest).toHaveBeenCalledWith({
108
- url: `${DEFAULT_SERVICE_URLS.SPACER}${API_BASE_PATHS.SPACER}/spaces/items/item-123`,
109
- method: 'DELETE',
110
- token: MOCK_JWT_TOKEN,
111
- });
112
- expect(result).toEqual(mockDeleteResponse);
113
- expect(result.success).toBe(true);
114
- expect(result.message).toBe('Item deleted successfully');
115
- console.log('Item deleted successfully');
116
- });
117
- it('should handle non-existent item deletion', async () => {
118
- console.log('Testing delete non-existent item...');
119
- const notFoundResponse = {
120
- success: false,
121
- message: 'Item not found',
122
- };
123
- const mockedRequest = vi.mocked(DatalayerApi.requestDatalayerAPI);
124
- mockedRequest.mockResolvedValue(notFoundResponse);
125
- const result = await items.deleteItem(MOCK_JWT_TOKEN, 'non-existent-item', DEFAULT_SERVICE_URLS.SPACER);
126
- expect(result).toEqual(notFoundResponse);
127
- expect(result.success).toBe(false);
128
- console.log('Non-existent item handled correctly');
129
- });
130
- it('should use custom base URL when provided', async () => {
131
- console.log('Testing delete item with custom base URL...');
132
- const customUrl = 'https://custom.spacer.api';
133
- const mockedRequest = vi.mocked(DatalayerApi.requestDatalayerAPI);
134
- mockedRequest.mockResolvedValue(mockDeleteResponse);
135
- await items.deleteItem(MOCK_JWT_TOKEN, 'item-123', customUrl);
136
- expect(mockedRequest).toHaveBeenCalledWith({
137
- url: `${customUrl}${API_BASE_PATHS.SPACER}/spaces/items/item-123`,
138
- method: 'DELETE',
139
- token: MOCK_JWT_TOKEN,
140
- });
141
- console.log('Custom base URL used correctly');
142
- });
143
- it('should handle API errors during deletion', async () => {
144
- console.log('Testing delete item with API error...');
145
- const mockedRequest = vi.mocked(DatalayerApi.requestDatalayerAPI);
146
- mockedRequest.mockRejectedValue(new Error('Network error'));
147
- await expect(items.deleteItem(MOCK_JWT_TOKEN, 'item-123', DEFAULT_SERVICE_URLS.SPACER)).rejects.toThrow('Network error');
148
- console.log('API error handled correctly');
149
- });
150
- it('should handle permission denied errors', async () => {
151
- console.log('Testing delete item with permission denied...');
152
- const permissionDeniedResponse = {
153
- success: false,
154
- message: 'Permission denied: You do not have permission to delete this item',
155
- };
156
- const mockedRequest = vi.mocked(DatalayerApi.requestDatalayerAPI);
157
- mockedRequest.mockResolvedValue(permissionDeniedResponse);
158
- const result = await items.deleteItem(MOCK_JWT_TOKEN, 'protected-item', DEFAULT_SERVICE_URLS.SPACER);
159
- expect(result).toEqual(permissionDeniedResponse);
160
- expect(result.success).toBe(false);
161
- expect(result.message).toContain('Permission denied');
162
- console.log('Permission denied handled correctly');
163
- });
164
- });
165
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,323 +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 { lexicals } 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 Lexicals Unit Tests', () => {
15
- beforeEach(() => {
16
- vi.clearAllMocks();
17
- });
18
- describe('create', () => {
19
- const mockCreateResponse = {
20
- success: true,
21
- message: 'Document created successfully',
22
- document: {
23
- id: 'lexical-123',
24
- uid: 'uid-lexical-123',
25
- name: 'Test Document',
26
- content: {},
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 lexical document with FormData', async () => {
33
- console.log('Testing lexical document creation with FormData...');
34
- const mockedRequest = vi.mocked(DatalayerApi.requestDatalayerAPI);
35
- mockedRequest.mockResolvedValue(mockCreateResponse);
36
- const lexicalData = {
37
- spaceId: 'space-456',
38
- documentType: 'lexical',
39
- name: 'Test Document',
40
- description: 'A test document',
41
- };
42
- const result = await lexicals.createLexical(MOCK_JWT_TOKEN, lexicalData, 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}/lexicals`);
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.document.name).toBe('Test Document');
53
- console.log('Document created successfully');
54
- });
55
- it('should handle FormData with file attachment', async () => {
56
- console.log('Testing lexical document creation with file...');
57
- const mockedRequest = vi.mocked(DatalayerApi.requestDatalayerAPI);
58
- mockedRequest.mockResolvedValue(mockCreateResponse);
59
- const file = new File(['test content'], 'test.txt', {
60
- type: 'text/plain',
61
- });
62
- const lexicalData = {
63
- spaceId: 'space-456',
64
- documentType: 'lexical',
65
- name: 'Test Document',
66
- description: 'A test document with file',
67
- file,
68
- };
69
- await lexicals.createLexical(MOCK_JWT_TOKEN, lexicalData, 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}/lexicals`);
72
- expect(callArgs.method).toBe('POST');
73
- expect(callArgs.token).toBe(MOCK_JWT_TOKEN);
74
- expect(callArgs.body).toBeInstanceOf(FormData);
75
- console.log('Document with file created successfully');
76
- });
77
- it('should handle different document types', async () => {
78
- console.log('Testing lexical document with different type...');
79
- const mockedRequest = vi.mocked(DatalayerApi.requestDatalayerAPI);
80
- mockedRequest.mockResolvedValue(mockCreateResponse);
81
- const lexicalData = {
82
- spaceId: 'space-456',
83
- documentType: 'markdown',
84
- name: 'Markdown Document',
85
- description: 'A markdown document',
86
- };
87
- await lexicals.createLexical(MOCK_JWT_TOKEN, lexicalData, DEFAULT_SERVICE_URLS.SPACER);
88
- const callArgs = mockedRequest.mock.calls[0][0];
89
- expect(callArgs.url).toBe(`${DEFAULT_SERVICE_URLS.SPACER}${API_BASE_PATHS.SPACER}/lexicals`);
90
- expect(callArgs.method).toBe('POST');
91
- expect(callArgs.token).toBe(MOCK_JWT_TOKEN);
92
- expect(callArgs.body).toBeInstanceOf(FormData);
93
- console.log('Document with different type created successfully');
94
- });
95
- it('should handle API errors during creation', async () => {
96
- console.log('Testing lexical document creation with API error...');
97
- const mockedRequest = vi.mocked(DatalayerApi.requestDatalayerAPI);
98
- mockedRequest.mockRejectedValue(new Error('API Error'));
99
- const lexicalData = {
100
- spaceId: 'space-456',
101
- documentType: 'lexical',
102
- name: 'Test Document',
103
- description: 'A test document',
104
- };
105
- await expect(lexicals.createLexical(MOCK_JWT_TOKEN, lexicalData, DEFAULT_SERVICE_URLS.SPACER)).rejects.toThrow('API Error');
106
- console.log('API error handled correctly');
107
- });
108
- it('should use custom base URL when provided', async () => {
109
- console.log('Testing lexical document creation with custom base URL...');
110
- const customUrl = 'https://custom.spacer.api';
111
- const mockedRequest = vi.mocked(DatalayerApi.requestDatalayerAPI);
112
- mockedRequest.mockResolvedValue(mockCreateResponse);
113
- const lexicalData = {
114
- spaceId: 'space-456',
115
- documentType: 'lexical',
116
- name: 'Test Document',
117
- description: 'A test document',
118
- };
119
- await lexicals.createLexical(MOCK_JWT_TOKEN, lexicalData, customUrl);
120
- const callArgs = mockedRequest.mock.calls[0][0];
121
- expect(callArgs.url).toBe(`${customUrl}${API_BASE_PATHS.SPACER}/lexicals`);
122
- expect(callArgs.method).toBe('POST');
123
- expect(callArgs.token).toBe(MOCK_JWT_TOKEN);
124
- expect(callArgs.body).toBeInstanceOf(FormData);
125
- console.log('Custom base URL used correctly');
126
- });
127
- it('should handle server validation errors', async () => {
128
- console.log('Testing lexical document creation with validation error...');
129
- const validationErrorResponse = {
130
- success: false,
131
- message: 'Validation failed',
132
- errors: ['Invalid space ID', 'Document type not supported'],
133
- };
134
- const mockedRequest = vi.mocked(DatalayerApi.requestDatalayerAPI);
135
- mockedRequest.mockResolvedValue(validationErrorResponse);
136
- const lexicalData = {
137
- spaceId: 'invalid-space',
138
- documentType: 'unknown',
139
- name: 'Test Document',
140
- description: 'A test document',
141
- };
142
- const result = await lexicals.createLexical(MOCK_JWT_TOKEN, lexicalData, DEFAULT_SERVICE_URLS.SPACER);
143
- expect(result).toEqual(validationErrorResponse);
144
- expect(result.success).toBe(false);
145
- expect(result.message).toBe('Validation failed');
146
- console.log('Validation error handled correctly');
147
- });
148
- });
149
- describe('get', () => {
150
- const mockGetResponse = {
151
- success: true,
152
- message: 'Document retrieved successfully',
153
- document: {
154
- id: 'lexical-123',
155
- uid: 'uid-lexical-123',
156
- name: 'Test Document',
157
- content: {
158
- root: {
159
- type: 'root',
160
- children: [
161
- {
162
- type: 'paragraph',
163
- children: [{ type: 'text', text: 'Test content' }],
164
- },
165
- ],
166
- },
167
- },
168
- space_id: 'space-456',
169
- owner_id: 'user-789',
170
- created_at: '2024-01-01T00:00:00Z',
171
- updated_at: '2024-01-02T00:00:00Z',
172
- },
173
- };
174
- it('should successfully get a lexical document by ID', async () => {
175
- console.log('Testing get lexical document by ID...');
176
- const mockedRequest = vi.mocked(DatalayerApi.requestDatalayerAPI);
177
- mockedRequest.mockResolvedValue(mockGetResponse);
178
- const result = await lexicals.getLexical(MOCK_JWT_TOKEN, 'lexical-123', DEFAULT_SERVICE_URLS.SPACER);
179
- expect(mockedRequest).toHaveBeenCalledTimes(1);
180
- expect(mockedRequest).toHaveBeenCalledWith({
181
- url: `${DEFAULT_SERVICE_URLS.SPACER}${API_BASE_PATHS.SPACER}/lexicals/lexical-123`,
182
- method: 'GET',
183
- token: MOCK_JWT_TOKEN,
184
- });
185
- expect(result).toEqual(mockGetResponse);
186
- expect(result.success).toBe(true);
187
- expect(result.document?.id).toBe('lexical-123');
188
- console.log('Document retrieved successfully');
189
- });
190
- it('should handle document not found (404)', async () => {
191
- console.log('Testing get document with 404...');
192
- const notFoundResponse = {
193
- success: false,
194
- message: 'Document not found',
195
- };
196
- const mockedRequest = vi.mocked(DatalayerApi.requestDatalayerAPI);
197
- mockedRequest.mockResolvedValue(notFoundResponse);
198
- const result = await lexicals.getLexical(MOCK_JWT_TOKEN, 'nonexistent-document', DEFAULT_SERVICE_URLS.SPACER);
199
- expect(result).toEqual(notFoundResponse);
200
- expect(result.success).toBe(false);
201
- expect(result.document).toBeUndefined();
202
- console.log('404 response handled correctly');
203
- });
204
- it('should handle API errors during get', async () => {
205
- console.log('Testing get document with API error...');
206
- const mockedRequest = vi.mocked(DatalayerApi.requestDatalayerAPI);
207
- mockedRequest.mockRejectedValue(new Error('Network error'));
208
- await expect(lexicals.getLexical(MOCK_JWT_TOKEN, 'lexical-123', DEFAULT_SERVICE_URLS.SPACER)).rejects.toThrow('Network error');
209
- console.log('API error handled correctly');
210
- });
211
- it('should use custom base URL when provided', async () => {
212
- console.log('Testing get document with custom base URL...');
213
- const customUrl = 'https://custom.spacer.api';
214
- const mockedRequest = vi.mocked(DatalayerApi.requestDatalayerAPI);
215
- mockedRequest.mockResolvedValue(mockGetResponse);
216
- await lexicals.getLexical(MOCK_JWT_TOKEN, 'lexical-123', customUrl);
217
- expect(mockedRequest).toHaveBeenCalledWith({
218
- url: `${customUrl}${API_BASE_PATHS.SPACER}/lexicals/lexical-123`,
219
- method: 'GET',
220
- token: MOCK_JWT_TOKEN,
221
- });
222
- console.log('Custom base URL used correctly');
223
- });
224
- });
225
- describe('update', () => {
226
- const mockUpdateResponse = {
227
- success: true,
228
- message: 'Document updated successfully',
229
- document: {
230
- id: 'lexical-123',
231
- uid: 'uid-lexical-123',
232
- name: 'Updated Document',
233
- content: {},
234
- space_id: 'space-456',
235
- owner_id: 'user-789',
236
- created_at: '2024-01-01T00:00:00Z',
237
- updated_at: '2024-01-03T00:00:00Z',
238
- },
239
- };
240
- it('should successfully update a document name', async () => {
241
- console.log('Testing update document name...');
242
- const mockedRequest = vi.mocked(DatalayerApi.requestDatalayerAPI);
243
- mockedRequest.mockResolvedValue(mockUpdateResponse);
244
- const updateData = {
245
- name: 'Updated Document',
246
- };
247
- const result = await lexicals.updateLexical(MOCK_JWT_TOKEN, 'lexical-123', updateData, DEFAULT_SERVICE_URLS.SPACER);
248
- expect(mockedRequest).toHaveBeenCalledTimes(1);
249
- expect(mockedRequest).toHaveBeenCalledWith({
250
- url: `${DEFAULT_SERVICE_URLS.SPACER}${API_BASE_PATHS.SPACER}/lexicals/lexical-123`,
251
- method: 'PUT',
252
- token: MOCK_JWT_TOKEN,
253
- body: updateData,
254
- });
255
- expect(result).toEqual(mockUpdateResponse);
256
- expect(result.success).toBe(true);
257
- expect(result.document.name).toBe('Updated Document');
258
- console.log('Document name updated successfully');
259
- });
260
- it('should successfully update a document description', async () => {
261
- console.log('Testing update document description...');
262
- const mockedRequest = vi.mocked(DatalayerApi.requestDatalayerAPI);
263
- mockedRequest.mockResolvedValue(mockUpdateResponse);
264
- const updateData = {
265
- description: 'Updated description',
266
- };
267
- const result = await lexicals.updateLexical(MOCK_JWT_TOKEN, 'lexical-123', updateData, DEFAULT_SERVICE_URLS.SPACER);
268
- expect(mockedRequest).toHaveBeenCalledWith({
269
- url: `${DEFAULT_SERVICE_URLS.SPACER}${API_BASE_PATHS.SPACER}/lexicals/lexical-123`,
270
- method: 'PUT',
271
- token: MOCK_JWT_TOKEN,
272
- body: updateData,
273
- });
274
- expect(result.success).toBe(true);
275
- console.log('Document description updated successfully');
276
- });
277
- it('should successfully update both name and description', async () => {
278
- console.log('Testing update document name and description...');
279
- const mockedRequest = vi.mocked(DatalayerApi.requestDatalayerAPI);
280
- mockedRequest.mockResolvedValue(mockUpdateResponse);
281
- const updateData = {
282
- name: 'Updated Document',
283
- description: 'Updated description',
284
- };
285
- const result = await lexicals.updateLexical(MOCK_JWT_TOKEN, 'lexical-123', updateData, DEFAULT_SERVICE_URLS.SPACER);
286
- expect(mockedRequest).toHaveBeenCalledWith({
287
- url: `${DEFAULT_SERVICE_URLS.SPACER}${API_BASE_PATHS.SPACER}/lexicals/lexical-123`,
288
- method: 'PUT',
289
- token: MOCK_JWT_TOKEN,
290
- body: updateData,
291
- });
292
- expect(result.success).toBe(true);
293
- console.log('Document name and description updated successfully');
294
- });
295
- it('should handle API errors during update', async () => {
296
- console.log('Testing update document with API error...');
297
- const mockedRequest = vi.mocked(DatalayerApi.requestDatalayerAPI);
298
- mockedRequest.mockRejectedValue(new Error('Update failed'));
299
- const updateData = {
300
- name: 'Updated Document',
301
- };
302
- await expect(lexicals.updateLexical(MOCK_JWT_TOKEN, 'lexical-123', updateData, DEFAULT_SERVICE_URLS.SPACER)).rejects.toThrow('Update failed');
303
- console.log('API error handled correctly');
304
- });
305
- it('should use custom base URL when provided', async () => {
306
- console.log('Testing update document with custom base URL...');
307
- const customUrl = 'https://custom.spacer.api';
308
- const mockedRequest = vi.mocked(DatalayerApi.requestDatalayerAPI);
309
- mockedRequest.mockResolvedValue(mockUpdateResponse);
310
- const updateData = {
311
- name: 'Updated Document',
312
- };
313
- await lexicals.updateLexical(MOCK_JWT_TOKEN, 'lexical-123', updateData, customUrl);
314
- expect(mockedRequest).toHaveBeenCalledWith({
315
- url: `${customUrl}${API_BASE_PATHS.SPACER}/lexicals/lexical-123`,
316
- method: 'PUT',
317
- token: MOCK_JWT_TOKEN,
318
- body: updateData,
319
- });
320
- console.log('Custom base URL used correctly');
321
- });
322
- });
323
- });
@@ -1 +0,0 @@
1
- export {};