@datalayer/core 0.0.9 → 0.0.11

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 (199) hide show
  1. package/lib/__tests__/shared/cleanup-shared.d.ts +4 -0
  2. package/lib/__tests__/shared/cleanup-shared.js +228 -0
  3. package/lib/__tests__/shared/test-config.d.ts +51 -0
  4. package/lib/__tests__/shared/test-config.js +110 -0
  5. package/lib/__tests__/shared/test-constants.d.ts +66 -0
  6. package/lib/__tests__/shared/test-constants.js +79 -0
  7. package/lib/api/DatalayerApi.d.ts +1 -1
  8. package/lib/api/DatalayerApi.js +73 -42
  9. package/lib/api/__tests__/iam.authentication.integration.test.d.ts +1 -0
  10. package/lib/api/__tests__/iam.authentication.integration.test.js +247 -0
  11. package/lib/api/__tests__/iam.healthz.integration.test.d.ts +1 -0
  12. package/lib/api/__tests__/iam.healthz.integration.test.js +63 -0
  13. package/lib/api/__tests__/iam.profile.integration.test.d.ts +1 -0
  14. package/lib/api/__tests__/iam.profile.integration.test.js +252 -0
  15. package/lib/api/__tests__/runtimes.environments.integration.test.d.ts +1 -0
  16. package/lib/api/__tests__/runtimes.environments.integration.test.js +122 -0
  17. package/lib/api/__tests__/runtimes.healthz.integration.test.d.ts +1 -0
  18. package/lib/api/__tests__/runtimes.healthz.integration.test.js +50 -0
  19. package/lib/api/__tests__/runtimes.integration.test.d.ts +1 -0
  20. package/lib/api/__tests__/runtimes.integration.test.js +369 -0
  21. package/lib/api/__tests__/spacer.healthz.integration.test.d.ts +1 -0
  22. package/lib/api/__tests__/spacer.healthz.integration.test.js +50 -0
  23. package/lib/api/__tests__/spacer.integration.test.d.ts +1 -0
  24. package/lib/api/__tests__/spacer.integration.test.js +519 -0
  25. package/lib/api/constants.d.ts +19 -0
  26. package/lib/api/constants.js +23 -0
  27. package/lib/api/iam/__tests__/authentication.unit.test.d.ts +1 -0
  28. package/lib/api/iam/__tests__/authentication.unit.test.js +63 -0
  29. package/lib/api/iam/__tests__/healthz.unit.test.d.ts +1 -0
  30. package/lib/api/iam/__tests__/healthz.unit.test.js +60 -0
  31. package/lib/api/iam/__tests__/profile.unit.test.d.ts +1 -0
  32. package/lib/api/iam/__tests__/profile.unit.test.js +57 -0
  33. package/lib/api/iam/authentication.d.ts +40 -0
  34. package/lib/api/iam/authentication.js +128 -0
  35. package/lib/api/iam/healthz.d.ts +15 -0
  36. package/lib/api/iam/healthz.js +43 -0
  37. package/lib/api/iam/index.d.ts +12 -0
  38. package/lib/api/iam/index.js +17 -0
  39. package/lib/api/iam/profile.d.ts +15 -0
  40. package/lib/api/iam/profile.js +41 -0
  41. package/lib/api/index.d.ts +20 -3
  42. package/lib/api/index.js +22 -3
  43. package/lib/api/runtimes/__tests__/environments.unit.test.d.ts +1 -0
  44. package/lib/api/runtimes/__tests__/environments.unit.test.js +77 -0
  45. package/lib/api/runtimes/__tests__/healthz.unit.test.d.ts +1 -0
  46. package/lib/api/runtimes/__tests__/healthz.unit.test.js +57 -0
  47. package/lib/api/runtimes/__tests__/runtimes.unit.test.d.ts +1 -0
  48. package/lib/api/runtimes/__tests__/runtimes.unit.test.js +139 -0
  49. package/lib/api/runtimes/__tests__/snapshots.unit.test.d.ts +1 -0
  50. package/lib/api/runtimes/__tests__/snapshots.unit.test.js +96 -0
  51. package/lib/api/runtimes/environments.d.ts +9 -0
  52. package/lib/api/runtimes/environments.js +28 -0
  53. package/lib/api/runtimes/healthz.d.ts +25 -0
  54. package/lib/api/runtimes/healthz.js +43 -0
  55. package/lib/api/runtimes/index.d.ts +10 -5
  56. package/lib/api/runtimes/index.js +10 -5
  57. package/lib/api/runtimes/runtimes.d.ts +54 -0
  58. package/lib/api/runtimes/runtimes.js +169 -0
  59. package/lib/api/runtimes/snapshots.d.ts +34 -21
  60. package/lib/api/runtimes/snapshots.js +69 -138
  61. package/lib/api/spacer/__tests__/healthz.unit.test.d.ts +1 -0
  62. package/lib/api/spacer/__tests__/healthz.unit.test.js +57 -0
  63. package/lib/api/spacer/__tests__/items.unit.test.d.ts +1 -0
  64. package/lib/api/spacer/__tests__/items.unit.test.js +165 -0
  65. package/lib/api/spacer/__tests__/lexicals.unit.test.d.ts +1 -0
  66. package/lib/api/spacer/__tests__/lexicals.unit.test.js +323 -0
  67. package/lib/api/spacer/__tests__/notebooks.unit.test.d.ts +1 -0
  68. package/lib/api/spacer/__tests__/notebooks.unit.test.js +224 -0
  69. package/lib/api/spacer/__tests__/users.unit.test.d.ts +1 -0
  70. package/lib/api/spacer/__tests__/users.unit.test.js +132 -0
  71. package/lib/api/spacer/healthz.d.ts +25 -0
  72. package/lib/api/spacer/healthz.js +43 -0
  73. package/lib/api/spacer/index.d.ts +13 -0
  74. package/lib/api/spacer/index.js +17 -0
  75. package/lib/api/spacer/items.d.ts +17 -0
  76. package/lib/api/spacer/items.js +40 -0
  77. package/lib/api/spacer/lexicals.d.ts +26 -0
  78. package/lib/api/spacer/lexicals.js +74 -0
  79. package/lib/api/spacer/notebooks.d.ts +26 -0
  80. package/lib/api/spacer/notebooks.js +74 -0
  81. package/lib/api/spacer/spaces.d.ts +9 -0
  82. package/lib/api/spacer/spaces.js +29 -0
  83. package/lib/api/spacer/users.d.ts +9 -0
  84. package/lib/api/spacer/users.js +28 -0
  85. package/lib/api/types/iam.d.ts +180 -0
  86. package/lib/api/types/index.d.ts +32 -0
  87. package/lib/api/types/index.js +36 -0
  88. package/lib/api/types/runtimes.d.ts +235 -0
  89. package/lib/api/types/runtimes.js +5 -0
  90. package/lib/api/types/spacer.d.ts +271 -0
  91. package/lib/api/types/spacer.js +5 -0
  92. package/lib/api/utils/__tests__/validation.test.d.ts +1 -0
  93. package/lib/api/utils/__tests__/validation.test.js +109 -0
  94. package/lib/api/utils/validation.d.ts +24 -0
  95. package/lib/api/utils/validation.js +133 -0
  96. package/lib/components/display/JupyterDialog.js +4 -8
  97. package/lib/components/progress/CreditsIndicator.d.ts +1 -1
  98. package/lib/components/runtimes/RuntimeCellVariablesDialog.js +2 -2
  99. package/lib/components/runtimes/RuntimeLauncherDialog.d.ts +1 -1
  100. package/lib/components/runtimes/RuntimeLauncherDialog.js +5 -2
  101. package/lib/components/runtimes/RuntimePickerBase.d.ts +1 -1
  102. package/lib/components/runtimes/RuntimePickerBase.js +1 -1
  103. package/lib/components/runtimes/RuntimePickerCell.js +2 -1
  104. package/lib/components/runtimes/RuntimePickerNotebook.d.ts +1 -1
  105. package/lib/components/runtimes/RuntimePickerNotebook.js +1 -1
  106. package/lib/components/runtimes/RuntimeSimplePicker.js +2 -1
  107. package/lib/components/runtimes/RuntimeTransfer.d.ts +1 -1
  108. package/lib/components/runtimes/RuntimeUtils.d.ts +1 -1
  109. package/lib/components/snapshots/RuntimeSnapshotMenu.d.ts +1 -1
  110. package/lib/components/snapshots/RuntimeSnapshotMenu.js +2 -2
  111. package/lib/components/snippets/SnippetDialog.js +1 -1
  112. package/lib/components/storage/ContentsBrowser.js +2 -2
  113. package/lib/components/tables/DataTable.js +2 -1
  114. package/lib/hooks/useDatalayer.d.ts +1 -1
  115. package/lib/hooks/useDatalayer.js +1 -1
  116. package/lib/hooks/useIAM.js +1 -1
  117. package/lib/hooks/useRuntimes.js +1 -1
  118. package/lib/index.d.ts +9 -0
  119. package/lib/index.js +10 -0
  120. package/lib/sdk/client/__tests__/sdk.health.integration.test.d.ts +1 -0
  121. package/lib/sdk/client/__tests__/sdk.health.integration.test.js +110 -0
  122. package/lib/sdk/client/__tests__/sdk.iam.integration.test.d.ts +1 -0
  123. package/lib/sdk/client/__tests__/sdk.iam.integration.test.js +179 -0
  124. package/lib/sdk/client/__tests__/sdk.models.integration.test.d.ts +1 -0
  125. package/lib/sdk/client/__tests__/sdk.models.integration.test.js +376 -0
  126. package/lib/sdk/client/__tests__/sdk.runtimes.integration.test.d.ts +1 -0
  127. package/lib/sdk/client/__tests__/sdk.runtimes.integration.test.js +276 -0
  128. package/lib/sdk/client/__tests__/sdk.spacer.integration.test.d.ts +1 -0
  129. package/lib/sdk/client/__tests__/sdk.spacer.integration.test.js +361 -0
  130. package/lib/sdk/client/base.d.ts +88 -0
  131. package/lib/sdk/client/base.js +112 -0
  132. package/lib/sdk/client/index.d.ts +192 -0
  133. package/lib/sdk/client/index.js +128 -0
  134. package/lib/sdk/client/mixins/HealthMixin.d.ts +100 -0
  135. package/lib/sdk/client/mixins/HealthMixin.js +133 -0
  136. package/lib/sdk/client/mixins/IAMMixin.d.ts +59 -0
  137. package/lib/sdk/client/mixins/IAMMixin.js +83 -0
  138. package/lib/sdk/client/mixins/RuntimesMixin.d.ts +134 -0
  139. package/lib/sdk/client/mixins/RuntimesMixin.js +221 -0
  140. package/lib/sdk/client/mixins/SpacerMixin.d.ts +184 -0
  141. package/lib/sdk/client/mixins/SpacerMixin.js +278 -0
  142. package/lib/sdk/client/models/Lexical.d.ts +156 -0
  143. package/lib/sdk/client/models/Lexical.js +275 -0
  144. package/lib/sdk/client/models/Notebook.d.ts +174 -0
  145. package/lib/sdk/client/models/Notebook.js +311 -0
  146. package/lib/sdk/client/models/Runtime.d.ts +221 -0
  147. package/lib/sdk/client/models/Runtime.js +341 -0
  148. package/lib/sdk/client/models/Snapshot.d.ts +156 -0
  149. package/lib/sdk/client/models/Snapshot.js +244 -0
  150. package/lib/sdk/client/models/Space.d.ts +182 -0
  151. package/lib/sdk/client/models/Space.js +276 -0
  152. package/lib/sdk/client/models/__tests__/Lexical.test.d.ts +1 -0
  153. package/lib/sdk/client/models/__tests__/Lexical.test.js +288 -0
  154. package/lib/sdk/client/models/__tests__/Notebook.test.d.ts +1 -0
  155. package/lib/sdk/client/models/__tests__/Notebook.test.js +206 -0
  156. package/lib/sdk/client/models/__tests__/Runtime.test.d.ts +1 -0
  157. package/lib/sdk/client/models/__tests__/Runtime.test.js +133 -0
  158. package/lib/sdk/client/models/__tests__/Snapshot.test.d.ts +1 -0
  159. package/lib/sdk/client/models/__tests__/Snapshot.test.js +244 -0
  160. package/lib/sdk/client/models/__tests__/Space.test.d.ts +1 -0
  161. package/lib/sdk/client/models/__tests__/Space.test.js +334 -0
  162. package/lib/sdk/client/models/index.d.ts +30 -0
  163. package/lib/sdk/client/models/index.js +30 -0
  164. package/lib/sdk/client/utils/mixins.d.ts +42 -0
  165. package/lib/sdk/client/utils/mixins.js +47 -0
  166. package/lib/sdk/index.d.ts +26 -0
  167. package/lib/sdk/index.js +32 -0
  168. package/lib/sdk/stateful/index.d.ts +3 -0
  169. package/lib/sdk/stateful/index.js +7 -0
  170. package/lib/{api → sdk/stateful}/runtimes/actions.d.ts +1 -1
  171. package/lib/{api → sdk/stateful}/runtimes/actions.js +3 -3
  172. package/lib/{api → sdk/stateful}/runtimes/apis.d.ts +1 -1
  173. package/lib/sdk/stateful/runtimes/apis.js +5 -0
  174. package/lib/sdk/stateful/runtimes/index.d.ts +5 -0
  175. package/lib/sdk/stateful/runtimes/index.js +9 -0
  176. package/lib/sdk/stateful/runtimes/snapshots.d.ts +25 -0
  177. package/lib/sdk/stateful/runtimes/snapshots.js +150 -0
  178. package/lib/services/DatalayerServiceManager.js +1 -1
  179. package/lib/state/substates/IAMState.js +1 -1
  180. package/lib/state/substates/RuntimesState.d.ts +1 -1
  181. package/lib/state/substates/RuntimesState.js +1 -1
  182. package/lib/state/substates/SurveysState.js +1 -1
  183. package/lib/test-setup.js +1 -0
  184. package/package.json +19 -9
  185. /package/lib/api/{runtimes/apis.js → types/iam.js} +0 -0
  186. /package/lib/{api → sdk/stateful}/jupyter/exec/Python.d.ts +0 -0
  187. /package/lib/{api → sdk/stateful}/jupyter/exec/Python.js +0 -0
  188. /package/lib/{api → sdk/stateful}/jupyter/exec/Snippets.d.ts +0 -0
  189. /package/lib/{api → sdk/stateful}/jupyter/exec/Snippets.js +0 -0
  190. /package/lib/{api → sdk/stateful}/jupyter/exec/index.d.ts +0 -0
  191. /package/lib/{api → sdk/stateful}/jupyter/exec/index.js +0 -0
  192. /package/lib/{api → sdk/stateful}/jupyter/index.d.ts +0 -0
  193. /package/lib/{api → sdk/stateful}/jupyter/index.js +0 -0
  194. /package/lib/{api → sdk/stateful}/jupyter/kernelsHandler.d.ts +0 -0
  195. /package/lib/{api → sdk/stateful}/jupyter/kernelsHandler.js +0 -0
  196. /package/lib/{api → sdk/stateful}/runtimes/settings.d.ts +0 -0
  197. /package/lib/{api → sdk/stateful}/runtimes/settings.js +0 -0
  198. /package/lib/{api → sdk/stateful}/runtimes/utils.d.ts +0 -0
  199. /package/lib/{api → sdk/stateful}/runtimes/utils.js +0 -0
@@ -0,0 +1,132 @@
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
+ });
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Health check response from the Spacer service
3
+ */
4
+ export interface SpacerHealthzPingResponse {
5
+ success: boolean;
6
+ message: string;
7
+ status?: {
8
+ status: string;
9
+ };
10
+ version?: string;
11
+ }
12
+ /**
13
+ * Health check ping endpoint for Spacer service
14
+ * @param baseUrl - Base URL for the API (defaults to production Spacer URL)
15
+ * @returns Health check response
16
+ * @throws {Error} If the health check fails
17
+ *
18
+ * @description
19
+ * This endpoint provides a basic health check for the Spacer service.
20
+ * It returns the current status of the service.
21
+ *
22
+ * Expected status codes:
23
+ * - 200: Service is healthy
24
+ */
25
+ export declare const ping: (baseUrl?: string) => Promise<SpacerHealthzPingResponse>;
@@ -0,0 +1,43 @@
1
+ /*
2
+ * Copyright (c) 2023-2025 Datalayer, Inc.
3
+ * Distributed under the terms of the Modified BSD License.
4
+ */
5
+ /**
6
+ * @module api/spacer/healthz
7
+ * @description Health check API functions for the Datalayer Spacer service.
8
+ *
9
+ * Provides functions for checking the health status of the Spacer service.
10
+ */
11
+ import { requestDatalayerAPI } from '../DatalayerApi';
12
+ import { API_BASE_PATHS, DEFAULT_SERVICE_URLS } from '../constants';
13
+ /**
14
+ * Health check ping endpoint for Spacer service
15
+ * @param baseUrl - Base URL for the API (defaults to production Spacer URL)
16
+ * @returns Health check response
17
+ * @throws {Error} If the health check fails
18
+ *
19
+ * @description
20
+ * This endpoint provides a basic health check for the Spacer service.
21
+ * It returns the current status of the service.
22
+ *
23
+ * Expected status codes:
24
+ * - 200: Service is healthy
25
+ */
26
+ export const ping = async (baseUrl = DEFAULT_SERVICE_URLS.SPACER) => {
27
+ try {
28
+ const response = await requestDatalayerAPI({
29
+ url: `${baseUrl}${API_BASE_PATHS.SPACER}/ping`,
30
+ method: 'GET',
31
+ });
32
+ return response;
33
+ }
34
+ catch (error) {
35
+ // Check if it's a response error with status code information
36
+ if (error.response) {
37
+ const status = error.response.status;
38
+ throw new Error(`Health check failed: Service unhealthy (status ${status}) - ${error.message}`);
39
+ }
40
+ // Re-throw other errors (network errors, etc.)
41
+ throw new Error(`Health check failed: ${error.message}`);
42
+ }
43
+ };
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @module api/spacer
3
+ * @description Spacer API exports.
4
+ *
5
+ * Provides organized access to spacer functionality including
6
+ * spaces, notebooks, cells, and lexical documents.
7
+ */
8
+ export * as healthz from './healthz';
9
+ export * as items from './items';
10
+ export * as lexicals from './lexicals';
11
+ export * as notebooks from './notebooks';
12
+ export * as spaces from './spaces';
13
+ export * as users from './users';
@@ -0,0 +1,17 @@
1
+ /*
2
+ * Copyright (c) 2023-2025 Datalayer, Inc.
3
+ * Distributed under the terms of the Modified BSD License.
4
+ */
5
+ /**
6
+ * @module api/spacer
7
+ * @description Spacer API exports.
8
+ *
9
+ * Provides organized access to spacer functionality including
10
+ * spaces, notebooks, cells, and lexical documents.
11
+ */
12
+ export * as healthz from './healthz';
13
+ export * as items from './items';
14
+ export * as lexicals from './lexicals';
15
+ export * as notebooks from './notebooks';
16
+ export * as spaces from './spaces';
17
+ export * as users from './users';
@@ -0,0 +1,17 @@
1
+ import { DeleteSpaceItemResponse, GetSpaceItemsResponse } from '../types/spacer';
2
+ /**
3
+ * Get the items of a space.
4
+ * @param token - Authentication token
5
+ * @param spaceId - The space ID
6
+ * @param baseUrl - Base URL for the API (defaults to production)
7
+ * @returns Promise resolving to the items response
8
+ */
9
+ export declare const getSpaceItems: (token: string, spaceId: string, baseUrl?: string) => Promise<GetSpaceItemsResponse>;
10
+ /**
11
+ * Delete an item from a space.
12
+ * @param token - Authentication token
13
+ * @param id - The item ID to delete
14
+ * @param baseUrl - Base URL for the API (defaults to production)
15
+ * @returns Promise resolving when deletion is complete
16
+ */
17
+ export declare const deleteItem: (token: string, id: string, baseUrl?: string) => Promise<DeleteSpaceItemResponse>;
@@ -0,0 +1,40 @@
1
+ /*
2
+ * Copyright (c) 2023-2025 Datalayer, Inc.
3
+ * Distributed under the terms of the Modified BSD License.
4
+ */
5
+ /**
6
+ * @module api/spacer/items
7
+ * @description Items API functions for the Datalayer platform.
8
+ *
9
+ * Provides functions for managing items in spaces.
10
+ */
11
+ import { requestDatalayerAPI } from '../DatalayerApi';
12
+ import { API_BASE_PATHS, DEFAULT_SERVICE_URLS } from '../constants';
13
+ /**
14
+ * Get the items of a space.
15
+ * @param token - Authentication token
16
+ * @param spaceId - The space ID
17
+ * @param baseUrl - Base URL for the API (defaults to production)
18
+ * @returns Promise resolving to the items response
19
+ */
20
+ export const getSpaceItems = async (token, spaceId, baseUrl = DEFAULT_SERVICE_URLS.SPACER) => {
21
+ return requestDatalayerAPI({
22
+ url: `${baseUrl}${API_BASE_PATHS.SPACER}/spaces/${spaceId}/items`,
23
+ method: 'GET',
24
+ token,
25
+ });
26
+ };
27
+ /**
28
+ * Delete an item from a space.
29
+ * @param token - Authentication token
30
+ * @param id - The item ID to delete
31
+ * @param baseUrl - Base URL for the API (defaults to production)
32
+ * @returns Promise resolving when deletion is complete
33
+ */
34
+ export const deleteItem = async (token, id, baseUrl = DEFAULT_SERVICE_URLS.SPACER) => {
35
+ return requestDatalayerAPI({
36
+ url: `${baseUrl}${API_BASE_PATHS.SPACER}/spaces/items/${id}`,
37
+ method: 'DELETE',
38
+ token,
39
+ });
40
+ };
@@ -0,0 +1,26 @@
1
+ import { CreateLexicalRequest, CreateLexicalResponse, GetLexicalResponse, UpdateLexicalRequest, UpdateLexicalResponse } from '../types/spacer';
2
+ /**
3
+ * Create a new lexical document.
4
+ * @param token - Authentication token
5
+ * @param data - Document creation configuration
6
+ * @param baseUrl - Base URL for the API (defaults to production)
7
+ * @returns Promise resolving to the created document response
8
+ */
9
+ export declare const createLexical: (token: string, data: CreateLexicalRequest, baseUrl?: string) => Promise<CreateLexicalResponse>;
10
+ /**
11
+ * Get a lexical document by ID.
12
+ * @param token - Authentication token
13
+ * @param id - The document ID
14
+ * @param baseUrl - Base URL for the API (defaults to production)
15
+ * @returns Promise resolving to the document response
16
+ */
17
+ export declare const getLexical: (token: string, id: string, baseUrl?: string) => Promise<GetLexicalResponse>;
18
+ /**
19
+ * Update a lexical document.
20
+ * @param token - Authentication token
21
+ * @param id - The document ID
22
+ * @param data - Update data containing name and/or description
23
+ * @param baseUrl - Base URL for the API (defaults to production)
24
+ * @returns Promise resolving to the updated document response
25
+ */
26
+ export declare const updateLexical: (token: string, id: string, data: UpdateLexicalRequest, baseUrl?: string) => Promise<UpdateLexicalResponse>;
@@ -0,0 +1,74 @@
1
+ /*
2
+ * Copyright (c) 2023-2025 Datalayer, Inc.
3
+ * Distributed under the terms of the Modified BSD License.
4
+ */
5
+ /**
6
+ * @module api/spacer/lexicals
7
+ * @description Lexical documents API functions for the Datalayer platform.
8
+ *
9
+ * Provides functions for creating, retrieving, and updating lexical (rich text) documents.
10
+ */
11
+ import { requestDatalayerAPI } from '../DatalayerApi';
12
+ import { API_BASE_PATHS, DEFAULT_SERVICE_URLS } from '../constants';
13
+ /**
14
+ * Create a new lexical document.
15
+ * @param token - Authentication token
16
+ * @param data - Document creation configuration
17
+ * @param baseUrl - Base URL for the API (defaults to production)
18
+ * @returns Promise resolving to the created document response
19
+ */
20
+ export const createLexical = async (token, data, baseUrl = DEFAULT_SERVICE_URLS.SPACER) => {
21
+ // Create FormData for multipart/form-data request (like the working example)
22
+ const formData = new FormData();
23
+ formData.append('spaceId', data.spaceId);
24
+ formData.append('name', data.name);
25
+ formData.append('documentType', data.documentType || 'lexical'); // Required field
26
+ formData.append('description', data.description || ''); // Required field - can be empty
27
+ // Add file if provided
28
+ if (data.file) {
29
+ if (data.file instanceof File) {
30
+ formData.append('file', data.file, data.file.name);
31
+ }
32
+ else {
33
+ // Handle Blob case
34
+ formData.append('file', data.file, `${data.name}.json`);
35
+ }
36
+ }
37
+ const url = `${baseUrl}${API_BASE_PATHS.SPACER}/lexicals`;
38
+ return requestDatalayerAPI({
39
+ url,
40
+ method: 'POST',
41
+ token,
42
+ body: formData,
43
+ });
44
+ };
45
+ /**
46
+ * Get a lexical document by ID.
47
+ * @param token - Authentication token
48
+ * @param id - The document ID
49
+ * @param baseUrl - Base URL for the API (defaults to production)
50
+ * @returns Promise resolving to the document response
51
+ */
52
+ export const getLexical = async (token, id, baseUrl = DEFAULT_SERVICE_URLS.SPACER) => {
53
+ return requestDatalayerAPI({
54
+ url: `${baseUrl}${API_BASE_PATHS.SPACER}/lexicals/${id}`,
55
+ method: 'GET',
56
+ token,
57
+ });
58
+ };
59
+ /**
60
+ * Update a lexical document.
61
+ * @param token - Authentication token
62
+ * @param id - The document ID
63
+ * @param data - Update data containing name and/or description
64
+ * @param baseUrl - Base URL for the API (defaults to production)
65
+ * @returns Promise resolving to the updated document response
66
+ */
67
+ export const updateLexical = async (token, id, data, baseUrl = DEFAULT_SERVICE_URLS.SPACER) => {
68
+ return requestDatalayerAPI({
69
+ url: `${baseUrl}${API_BASE_PATHS.SPACER}/lexicals/${id}`,
70
+ method: 'PUT',
71
+ token,
72
+ body: data,
73
+ });
74
+ };
@@ -0,0 +1,26 @@
1
+ import { CreateNotebookRequest, CreateNotebookResponse, GetNotebookResponse, UpdateNotebookRequest, UpdateNotebookResponse } from '../types/spacer';
2
+ /**
3
+ * Create a new Jupyter notebook.
4
+ * @param token - Authentication token
5
+ * @param data - Notebook creation configuration
6
+ * @param baseUrl - Base URL for the API (defaults to production)
7
+ * @returns Promise resolving to the created notebook response
8
+ */
9
+ export declare const createNotebook: (token: string, data: CreateNotebookRequest, baseUrl?: string) => Promise<CreateNotebookResponse>;
10
+ /**
11
+ * Get a notebook by ID.
12
+ * @param token - Authentication token
13
+ * @param id - The notebook ID
14
+ * @param baseUrl - Base URL for the API (defaults to production)
15
+ * @returns Promise resolving to the notebook response
16
+ */
17
+ export declare const getNotebook: (token: string, id: string, baseUrl?: string) => Promise<GetNotebookResponse>;
18
+ /**
19
+ * Update a notebook.
20
+ * @param token - Authentication token
21
+ * @param id - The notebook ID
22
+ * @param data - Update data containing name and/or description
23
+ * @param baseUrl - Base URL for the API (defaults to production)
24
+ * @returns Promise resolving to the updated notebook response
25
+ */
26
+ export declare const updateNotebook: (token: string, id: string, data: UpdateNotebookRequest, baseUrl?: string) => Promise<UpdateNotebookResponse>;
@@ -0,0 +1,74 @@
1
+ /*
2
+ * Copyright (c) 2023-2025 Datalayer, Inc.
3
+ * Distributed under the terms of the Modified BSD License.
4
+ */
5
+ /**
6
+ * @module api/spacer/notebooks
7
+ * @description Jupyter notebooks API functions for the Datalayer platform.
8
+ *
9
+ * Provides functions for creating and retrieving Jupyter notebooks within workspaces.
10
+ */
11
+ import { requestDatalayerAPI } from '../DatalayerApi';
12
+ import { API_BASE_PATHS, DEFAULT_SERVICE_URLS } from '../constants';
13
+ /**
14
+ * Create a new Jupyter notebook.
15
+ * @param token - Authentication token
16
+ * @param data - Notebook creation configuration
17
+ * @param baseUrl - Base URL for the API (defaults to production)
18
+ * @returns Promise resolving to the created notebook response
19
+ */
20
+ export const createNotebook = async (token, data, baseUrl = DEFAULT_SERVICE_URLS.SPACER) => {
21
+ // Create FormData for multipart/form-data request (like the working example)
22
+ const formData = new FormData();
23
+ formData.append('spaceId', data.spaceId);
24
+ formData.append('name', data.name);
25
+ formData.append('notebookType', data.notebookType || 'jupyter'); // Required field
26
+ formData.append('description', data.description || ''); // Required field - can be empty
27
+ // Add file if provided
28
+ if (data.file) {
29
+ if (data.file instanceof File) {
30
+ formData.append('file', data.file, data.file.name);
31
+ }
32
+ else {
33
+ // Handle Blob case
34
+ formData.append('file', data.file, `${data.name}.ipynb`);
35
+ }
36
+ }
37
+ const url = `${baseUrl}${API_BASE_PATHS.SPACER}/notebooks`;
38
+ return requestDatalayerAPI({
39
+ url,
40
+ method: 'POST',
41
+ token,
42
+ body: formData,
43
+ });
44
+ };
45
+ /**
46
+ * Get a notebook by ID.
47
+ * @param token - Authentication token
48
+ * @param id - The notebook ID
49
+ * @param baseUrl - Base URL for the API (defaults to production)
50
+ * @returns Promise resolving to the notebook response
51
+ */
52
+ export const getNotebook = async (token, id, baseUrl = DEFAULT_SERVICE_URLS.SPACER) => {
53
+ return requestDatalayerAPI({
54
+ url: `${baseUrl}${API_BASE_PATHS.SPACER}/notebooks/${id}`,
55
+ method: 'GET',
56
+ token,
57
+ });
58
+ };
59
+ /**
60
+ * Update a notebook.
61
+ * @param token - Authentication token
62
+ * @param id - The notebook ID
63
+ * @param data - Update data containing name and/or description
64
+ * @param baseUrl - Base URL for the API (defaults to production)
65
+ * @returns Promise resolving to the updated notebook response
66
+ */
67
+ export const updateNotebook = async (token, id, data, baseUrl = DEFAULT_SERVICE_URLS.SPACER) => {
68
+ return requestDatalayerAPI({
69
+ url: `${baseUrl}${API_BASE_PATHS.SPACER}/notebooks/${id}`,
70
+ method: 'PUT',
71
+ token,
72
+ body: data,
73
+ });
74
+ };
@@ -0,0 +1,9 @@
1
+ import { CreateSpaceRequest, CreateSpaceResponse } from '../types/spacer';
2
+ /**
3
+ * Create a new workspace space.
4
+ * @param token - Authentication token
5
+ * @param data - Space creation configuration
6
+ * @param baseUrl - Base URL for the API
7
+ * @returns Promise resolving to the created space response
8
+ */
9
+ export declare const createSpace: (token: string, data: CreateSpaceRequest, baseUrl?: string) => Promise<CreateSpaceResponse>;
@@ -0,0 +1,29 @@
1
+ /*
2
+ * Copyright (c) 2023-2025 Datalayer, Inc.
3
+ * Distributed under the terms of the Modified BSD License.
4
+ */
5
+ /**
6
+ * @module api/spacer/spaces
7
+ * @description Workspace spaces API functions for the Datalayer platform.
8
+ *
9
+ * Provides function for creating workspace spaces.
10
+ */
11
+ import { requestDatalayerAPI } from '../DatalayerApi';
12
+ import { API_BASE_PATHS, DEFAULT_SERVICE_URLS } from '../constants';
13
+ import { validateToken } from '../utils/validation';
14
+ /**
15
+ * Create a new workspace space.
16
+ * @param token - Authentication token
17
+ * @param data - Space creation configuration
18
+ * @param baseUrl - Base URL for the API
19
+ * @returns Promise resolving to the created space response
20
+ */
21
+ export const createSpace = async (token, data, baseUrl = DEFAULT_SERVICE_URLS.SPACER) => {
22
+ validateToken(token);
23
+ return requestDatalayerAPI({
24
+ url: `${baseUrl}${API_BASE_PATHS.SPACER}/spaces`,
25
+ method: 'POST',
26
+ token,
27
+ body: data,
28
+ });
29
+ };
@@ -0,0 +1,9 @@
1
+ import { SpacesForUserResponse } from '../types/spacer';
2
+ /**
3
+ * Get all spaces for the current authenticated user.
4
+ * @param token - Authentication token
5
+ * @param baseUrl - Base URL for the API (defaults to production Spacer URL)
6
+ * @returns Promise resolving to the user's spaces
7
+ * @throws {Error} If authentication token is missing or invalid
8
+ */
9
+ export declare const getMySpaces: (token: string, baseUrl?: string) => Promise<SpacesForUserResponse>;
@@ -0,0 +1,28 @@
1
+ /*
2
+ * Copyright (c) 2023-2025 Datalayer, Inc.
3
+ * Distributed under the terms of the Modified BSD License.
4
+ */
5
+ /**
6
+ * @module api/spacer/users
7
+ * @description User-related Spacer API functions for the Datalayer platform.
8
+ *
9
+ * Provides functions for user-specific operations in the Spacer service.
10
+ */
11
+ import { requestDatalayerAPI } from '../DatalayerApi';
12
+ import { API_BASE_PATHS, DEFAULT_SERVICE_URLS } from '../constants';
13
+ import { validateToken } from '../utils/validation';
14
+ /**
15
+ * Get all spaces for the current authenticated user.
16
+ * @param token - Authentication token
17
+ * @param baseUrl - Base URL for the API (defaults to production Spacer URL)
18
+ * @returns Promise resolving to the user's spaces
19
+ * @throws {Error} If authentication token is missing or invalid
20
+ */
21
+ export const getMySpaces = async (token, baseUrl = DEFAULT_SERVICE_URLS.SPACER) => {
22
+ validateToken(token);
23
+ return requestDatalayerAPI({
24
+ url: `${baseUrl}${API_BASE_PATHS.SPACER}/spaces/users/me`,
25
+ method: 'GET',
26
+ token,
27
+ });
28
+ };