@datalayer/core 0.0.10 → 0.0.12

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 (195) 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/progress/CreditsIndicator.d.ts +1 -1
  97. package/lib/components/runtimes/RuntimeCellVariablesDialog.js +1 -1
  98. package/lib/components/runtimes/RuntimeLauncherDialog.d.ts +1 -1
  99. package/lib/components/runtimes/RuntimeLauncherDialog.js +2 -1
  100. package/lib/components/runtimes/RuntimePickerBase.d.ts +1 -1
  101. package/lib/components/runtimes/RuntimePickerBase.js +1 -1
  102. package/lib/components/runtimes/RuntimePickerCell.js +2 -1
  103. package/lib/components/runtimes/RuntimePickerNotebook.d.ts +1 -1
  104. package/lib/components/runtimes/RuntimePickerNotebook.js +1 -1
  105. package/lib/components/runtimes/RuntimeSimplePicker.js +2 -1
  106. package/lib/components/runtimes/RuntimeTransfer.d.ts +1 -1
  107. package/lib/components/runtimes/RuntimeUtils.d.ts +1 -1
  108. package/lib/components/snapshots/RuntimeSnapshotMenu.d.ts +1 -1
  109. package/lib/components/snapshots/RuntimeSnapshotMenu.js +1 -1
  110. package/lib/hooks/useDatalayer.d.ts +1 -1
  111. package/lib/hooks/useDatalayer.js +1 -1
  112. package/lib/hooks/useIAM.js +1 -1
  113. package/lib/hooks/useRuntimes.js +1 -1
  114. package/lib/index.d.ts +9 -0
  115. package/lib/index.js +10 -0
  116. package/lib/sdk/client/__tests__/sdk.health.integration.test.d.ts +1 -0
  117. package/lib/sdk/client/__tests__/sdk.health.integration.test.js +110 -0
  118. package/lib/sdk/client/__tests__/sdk.iam.integration.test.d.ts +1 -0
  119. package/lib/sdk/client/__tests__/sdk.iam.integration.test.js +179 -0
  120. package/lib/sdk/client/__tests__/sdk.models.integration.test.d.ts +1 -0
  121. package/lib/sdk/client/__tests__/sdk.models.integration.test.js +376 -0
  122. package/lib/sdk/client/__tests__/sdk.runtimes.integration.test.d.ts +1 -0
  123. package/lib/sdk/client/__tests__/sdk.runtimes.integration.test.js +276 -0
  124. package/lib/sdk/client/__tests__/sdk.spacer.integration.test.d.ts +1 -0
  125. package/lib/sdk/client/__tests__/sdk.spacer.integration.test.js +361 -0
  126. package/lib/sdk/client/base.d.ts +88 -0
  127. package/lib/sdk/client/base.js +112 -0
  128. package/lib/sdk/client/index.d.ts +192 -0
  129. package/lib/sdk/client/index.js +128 -0
  130. package/lib/sdk/client/mixins/HealthMixin.d.ts +100 -0
  131. package/lib/sdk/client/mixins/HealthMixin.js +133 -0
  132. package/lib/sdk/client/mixins/IAMMixin.d.ts +59 -0
  133. package/lib/sdk/client/mixins/IAMMixin.js +83 -0
  134. package/lib/sdk/client/mixins/RuntimesMixin.d.ts +134 -0
  135. package/lib/sdk/client/mixins/RuntimesMixin.js +221 -0
  136. package/lib/sdk/client/mixins/SpacerMixin.d.ts +184 -0
  137. package/lib/sdk/client/mixins/SpacerMixin.js +278 -0
  138. package/lib/sdk/client/models/Lexical.d.ts +156 -0
  139. package/lib/sdk/client/models/Lexical.js +275 -0
  140. package/lib/sdk/client/models/Notebook.d.ts +174 -0
  141. package/lib/sdk/client/models/Notebook.js +311 -0
  142. package/lib/sdk/client/models/Runtime.d.ts +221 -0
  143. package/lib/sdk/client/models/Runtime.js +341 -0
  144. package/lib/sdk/client/models/Snapshot.d.ts +156 -0
  145. package/lib/sdk/client/models/Snapshot.js +244 -0
  146. package/lib/sdk/client/models/Space.d.ts +182 -0
  147. package/lib/sdk/client/models/Space.js +276 -0
  148. package/lib/sdk/client/models/__tests__/Lexical.test.d.ts +1 -0
  149. package/lib/sdk/client/models/__tests__/Lexical.test.js +288 -0
  150. package/lib/sdk/client/models/__tests__/Notebook.test.d.ts +1 -0
  151. package/lib/sdk/client/models/__tests__/Notebook.test.js +206 -0
  152. package/lib/sdk/client/models/__tests__/Runtime.test.d.ts +1 -0
  153. package/lib/sdk/client/models/__tests__/Runtime.test.js +133 -0
  154. package/lib/sdk/client/models/__tests__/Snapshot.test.d.ts +1 -0
  155. package/lib/sdk/client/models/__tests__/Snapshot.test.js +244 -0
  156. package/lib/sdk/client/models/__tests__/Space.test.d.ts +1 -0
  157. package/lib/sdk/client/models/__tests__/Space.test.js +334 -0
  158. package/lib/sdk/client/models/index.d.ts +30 -0
  159. package/lib/sdk/client/models/index.js +30 -0
  160. package/lib/sdk/client/utils/mixins.d.ts +42 -0
  161. package/lib/sdk/client/utils/mixins.js +47 -0
  162. package/lib/sdk/index.d.ts +26 -0
  163. package/lib/sdk/index.js +32 -0
  164. package/lib/sdk/stateful/index.d.ts +3 -0
  165. package/lib/sdk/stateful/index.js +7 -0
  166. package/lib/{api → sdk/stateful}/runtimes/actions.d.ts +1 -1
  167. package/lib/{api → sdk/stateful}/runtimes/actions.js +3 -3
  168. package/lib/{api → sdk/stateful}/runtimes/apis.d.ts +1 -1
  169. package/lib/sdk/stateful/runtimes/apis.js +5 -0
  170. package/lib/sdk/stateful/runtimes/index.d.ts +5 -0
  171. package/lib/sdk/stateful/runtimes/index.js +9 -0
  172. package/lib/sdk/stateful/runtimes/snapshots.d.ts +25 -0
  173. package/lib/sdk/stateful/runtimes/snapshots.js +150 -0
  174. package/lib/services/DatalayerServiceManager.js +1 -1
  175. package/lib/state/substates/IAMState.js +1 -1
  176. package/lib/state/substates/RuntimesState.d.ts +1 -1
  177. package/lib/state/substates/RuntimesState.js +1 -1
  178. package/lib/state/substates/SurveysState.js +1 -1
  179. package/lib/test-setup.js +1 -0
  180. package/package.json +19 -9
  181. /package/lib/api/{runtimes/apis.js → types/iam.js} +0 -0
  182. /package/lib/{api → sdk/stateful}/jupyter/exec/Python.d.ts +0 -0
  183. /package/lib/{api → sdk/stateful}/jupyter/exec/Python.js +0 -0
  184. /package/lib/{api → sdk/stateful}/jupyter/exec/Snippets.d.ts +0 -0
  185. /package/lib/{api → sdk/stateful}/jupyter/exec/Snippets.js +0 -0
  186. /package/lib/{api → sdk/stateful}/jupyter/exec/index.d.ts +0 -0
  187. /package/lib/{api → sdk/stateful}/jupyter/exec/index.js +0 -0
  188. /package/lib/{api → sdk/stateful}/jupyter/index.d.ts +0 -0
  189. /package/lib/{api → sdk/stateful}/jupyter/index.js +0 -0
  190. /package/lib/{api → sdk/stateful}/jupyter/kernelsHandler.d.ts +0 -0
  191. /package/lib/{api → sdk/stateful}/jupyter/kernelsHandler.js +0 -0
  192. /package/lib/{api → sdk/stateful}/runtimes/settings.d.ts +0 -0
  193. /package/lib/{api → sdk/stateful}/runtimes/settings.js +0 -0
  194. /package/lib/{api → sdk/stateful}/runtimes/utils.d.ts +0 -0
  195. /package/lib/{api → sdk/stateful}/runtimes/utils.js +0 -0
@@ -0,0 +1,139 @@
1
+ /*
2
+ * Copyright (c) 2023-2025 Datalayer, Inc.
3
+ * Distributed under the terms of the Modified BSD License.
4
+ */
5
+ import { describe, it, expect } from 'vitest';
6
+ import { runtimes } from '..';
7
+ import { MOCK_JWT_TOKEN } from '../../../__tests__/shared/test-constants';
8
+ describe('Runtimes Unit Tests', () => {
9
+ describe('create parameter validation', () => {
10
+ const mockBaseUrl = 'https://example.com';
11
+ const mockData = {
12
+ environment_name: 'python-cpu-env',
13
+ type: 'notebook',
14
+ given_name: 'test-runtime',
15
+ credits_limit: 100,
16
+ };
17
+ it('should fail when token is missing', async () => {
18
+ console.log('Testing create with missing token...');
19
+ await expect(
20
+ // @ts-expect-error Testing undefined token
21
+ runtimes.createRuntime(undefined, mockData, mockBaseUrl)).rejects.toThrow('Authentication token is required');
22
+ console.log('Correctly rejected create with missing token');
23
+ });
24
+ it('should fail when token is empty', async () => {
25
+ console.log('Testing create with empty token...');
26
+ await expect(runtimes.createRuntime('', mockData, mockBaseUrl)).rejects.toThrow('Authentication token is required');
27
+ console.log('Correctly rejected create with empty token');
28
+ });
29
+ it('should fail when token is only whitespace', async () => {
30
+ console.log('Testing create with whitespace token...');
31
+ await expect(runtimes.createRuntime(' ', mockData, mockBaseUrl)).rejects.toThrow('Authentication token is required');
32
+ console.log('Correctly rejected create with whitespace token');
33
+ });
34
+ });
35
+ describe('list parameter validation', () => {
36
+ const mockBaseUrl = 'https://example.com';
37
+ it('should fail when token is missing', async () => {
38
+ console.log('Testing list with missing token...');
39
+ await expect(
40
+ // @ts-expect-error Testing undefined token
41
+ runtimes.listRuntimes(undefined, mockBaseUrl)).rejects.toThrow('Authentication token is required');
42
+ console.log('Correctly rejected list with missing token');
43
+ });
44
+ it('should fail when token is null', async () => {
45
+ console.log('Testing list with null token...');
46
+ await expect(
47
+ // @ts-expect-error Testing null token
48
+ runtimes.listRuntimes(null, mockBaseUrl)).rejects.toThrow('Authentication token is required');
49
+ console.log('Correctly rejected list with null token');
50
+ });
51
+ it('should fail when token is empty', async () => {
52
+ console.log('Testing list with empty token...');
53
+ await expect(runtimes.listRuntimes('', mockBaseUrl)).rejects.toThrow('Authentication token is required');
54
+ console.log('Correctly rejected list with empty token');
55
+ });
56
+ it('should fail when token is only whitespace', async () => {
57
+ console.log('Testing list with whitespace token...');
58
+ await expect(runtimes.listRuntimes(' ', mockBaseUrl)).rejects.toThrow('Authentication token is required');
59
+ console.log('Correctly rejected list with whitespace token');
60
+ });
61
+ });
62
+ describe('get parameter validation', () => {
63
+ const mockBaseUrl = 'https://example.com';
64
+ it('should fail when token is missing', async () => {
65
+ console.log('Testing get with missing token...');
66
+ await expect(
67
+ // @ts-expect-error Testing undefined token
68
+ runtimes.getRuntime(undefined, 'pod-123', mockBaseUrl)).rejects.toThrow('Authentication token is required');
69
+ console.log('Correctly rejected get with missing token');
70
+ });
71
+ it('should fail when pod name is missing', async () => {
72
+ console.log('Testing get with missing pod name...');
73
+ await expect(
74
+ // @ts-expect-error Testing undefined pod name
75
+ runtimes.getRuntime(MOCK_JWT_TOKEN, undefined, mockBaseUrl)).rejects.toThrow('Pod name is required');
76
+ console.log('Correctly rejected get with missing pod name');
77
+ });
78
+ it('should fail when pod name is empty', async () => {
79
+ console.log('Testing get with empty pod name...');
80
+ await expect(runtimes.getRuntime(MOCK_JWT_TOKEN, '', mockBaseUrl)).rejects.toThrow('Pod name is required');
81
+ console.log('Correctly rejected get with empty pod name');
82
+ });
83
+ it('should fail when pod name is only whitespace', async () => {
84
+ console.log('Testing get with whitespace pod name...');
85
+ await expect(runtimes.getRuntime(MOCK_JWT_TOKEN, ' ', mockBaseUrl)).rejects.toThrow('Pod name is required');
86
+ console.log('Correctly rejected get with whitespace pod name');
87
+ });
88
+ });
89
+ describe('remove parameter validation', () => {
90
+ const mockBaseUrl = 'https://example.com';
91
+ it('should fail when token is missing', async () => {
92
+ console.log('Testing remove with missing token...');
93
+ await expect(
94
+ // @ts-expect-error Testing undefined token
95
+ runtimes.deleteRuntime(undefined, 'pod-123', mockBaseUrl)).rejects.toThrow('Authentication token is required');
96
+ console.log('Correctly rejected remove with missing token');
97
+ });
98
+ it('should fail when pod name is missing', async () => {
99
+ console.log('Testing remove with missing pod name...');
100
+ await expect(
101
+ // @ts-expect-error Testing undefined pod name
102
+ runtimes.deleteRuntime(MOCK_JWT_TOKEN, undefined, mockBaseUrl)).rejects.toThrow('Pod name is required');
103
+ console.log('Correctly rejected remove with missing pod name');
104
+ });
105
+ it('should fail when pod name is empty', async () => {
106
+ console.log('Testing remove with empty pod name...');
107
+ await expect(runtimes.deleteRuntime(MOCK_JWT_TOKEN, '', mockBaseUrl)).rejects.toThrow('Pod name is required');
108
+ console.log('Correctly rejected remove with empty pod name');
109
+ });
110
+ it('should fail when pod name is only whitespace', async () => {
111
+ console.log('Testing remove with whitespace pod name...');
112
+ await expect(runtimes.deleteRuntime(MOCK_JWT_TOKEN, ' ', mockBaseUrl)).rejects.toThrow('Pod name is required');
113
+ console.log('Correctly rejected remove with whitespace pod name');
114
+ });
115
+ });
116
+ describe('put parameter validation', () => {
117
+ const mockBaseUrl = 'https://example.com';
118
+ it('should fail when token is missing', async () => {
119
+ console.log('Testing put with missing token...');
120
+ await expect(runtimes.updateRuntime(undefined, 'pod-123', 'snapshot-123', mockBaseUrl)).rejects.toThrow('Authentication token is required');
121
+ console.log('Correctly rejected put with missing token');
122
+ });
123
+ it('should fail when pod name is missing', async () => {
124
+ console.log('Testing put with missing pod name...');
125
+ await expect(runtimes.updateRuntime(MOCK_JWT_TOKEN, undefined, 'snapshot-123', mockBaseUrl)).rejects.toThrow('Pod name is required');
126
+ console.log('Correctly rejected put with missing pod name');
127
+ });
128
+ it('should fail when pod name is empty', async () => {
129
+ console.log('Testing put with empty pod name...');
130
+ await expect(runtimes.updateRuntime(MOCK_JWT_TOKEN, '', 'snapshot-123', mockBaseUrl)).rejects.toThrow('Pod name is required');
131
+ console.log('Correctly rejected put with empty pod name');
132
+ });
133
+ it('should fail when pod name is only whitespace', async () => {
134
+ console.log('Testing put with whitespace pod name...');
135
+ await expect(runtimes.updateRuntime(MOCK_JWT_TOKEN, ' ', 'snapshot-123', mockBaseUrl)).rejects.toThrow('Pod name is required');
136
+ console.log('Correctly rejected put with whitespace pod name');
137
+ });
138
+ });
139
+ });
@@ -0,0 +1,96 @@
1
+ /*
2
+ * Copyright (c) 2023-2025 Datalayer, Inc.
3
+ * Distributed under the terms of the Modified BSD License.
4
+ */
5
+ import { describe, it, expect } from 'vitest';
6
+ import { snapshots } from '..';
7
+ import { MOCK_JWT_TOKEN } from '../../../__tests__/shared/test-constants';
8
+ describe('Runtimes Snapshots Unit Tests', () => {
9
+ describe('create parameter validation', () => {
10
+ const mockBaseUrl = 'https://example.com';
11
+ const mockData = {
12
+ pod_name: 'pod-123',
13
+ name: 'my-snapshot',
14
+ description: 'Test snapshot',
15
+ stop: true,
16
+ };
17
+ it('should fail when token is missing', async () => {
18
+ console.log('Testing create with missing token...');
19
+ await expect(
20
+ // @ts-expect-error Testing undefined token
21
+ snapshots.createSnapshot(undefined, mockData, mockBaseUrl)).rejects.toThrow('Authentication token is required');
22
+ console.log('Correctly rejected create with missing token');
23
+ });
24
+ it('should fail when token is empty', async () => {
25
+ console.log('Testing create with empty token...');
26
+ await expect(snapshots.createSnapshot('', mockData, mockBaseUrl)).rejects.toThrow('Authentication token is required');
27
+ console.log('Correctly rejected create with empty token');
28
+ });
29
+ it('should fail when token is only whitespace', async () => {
30
+ console.log('Testing create with whitespace token...');
31
+ await expect(snapshots.createSnapshot(' ', mockData, mockBaseUrl)).rejects.toThrow('Authentication token is required');
32
+ console.log('Correctly rejected create with whitespace token');
33
+ });
34
+ });
35
+ describe('list parameter validation', () => {
36
+ const mockBaseUrl = 'https://example.com';
37
+ it('should fail when token is missing', async () => {
38
+ console.log('Testing list with missing token...');
39
+ await expect(
40
+ // @ts-expect-error Testing undefined token
41
+ snapshots.listSnapshots(undefined, mockBaseUrl)).rejects.toThrow('Authentication token is required');
42
+ console.log('Correctly rejected list with missing token');
43
+ });
44
+ it('should fail when token is null', async () => {
45
+ console.log('Testing list with null token...');
46
+ await expect(
47
+ // @ts-expect-error Testing null token
48
+ snapshots.listSnapshots(null, mockBaseUrl)).rejects.toThrow('Authentication token is required');
49
+ console.log('Correctly rejected list with null token');
50
+ });
51
+ });
52
+ describe('get parameter validation', () => {
53
+ const mockBaseUrl = 'https://example.com';
54
+ it('should fail when token is missing', async () => {
55
+ console.log('Testing get with missing token...');
56
+ await expect(
57
+ // @ts-expect-error Testing undefined token
58
+ snapshots.getSnapshot(undefined, 'snapshot-123', mockBaseUrl)).rejects.toThrow('Authentication token is required');
59
+ console.log('Correctly rejected get with missing token');
60
+ });
61
+ it('should fail when snapshot ID is missing', async () => {
62
+ console.log('Testing get with missing snapshot ID...');
63
+ await expect(
64
+ // @ts-expect-error Testing undefined snapshot ID
65
+ snapshots.getSnapshot(MOCK_JWT_TOKEN, undefined, mockBaseUrl)).rejects.toThrow('Snapshot ID is required');
66
+ console.log('Correctly rejected get with missing snapshot ID');
67
+ });
68
+ it('should fail when snapshot ID is empty', async () => {
69
+ console.log('Testing get with empty snapshot ID...');
70
+ await expect(snapshots.getSnapshot(MOCK_JWT_TOKEN, '', mockBaseUrl)).rejects.toThrow('Snapshot ID is required');
71
+ console.log('Correctly rejected get with empty snapshot ID');
72
+ });
73
+ it('should fail when snapshot ID is only whitespace', async () => {
74
+ console.log('Testing get with whitespace snapshot ID...');
75
+ await expect(snapshots.getSnapshot(MOCK_JWT_TOKEN, ' ', mockBaseUrl)).rejects.toThrow('Snapshot ID is required');
76
+ console.log('Correctly rejected get with whitespace snapshot ID');
77
+ });
78
+ });
79
+ describe('remove parameter validation', () => {
80
+ const mockBaseUrl = 'https://example.com';
81
+ it('should fail when token is missing', async () => {
82
+ console.log('Testing remove with missing token...');
83
+ await expect(
84
+ // @ts-expect-error Testing undefined token
85
+ snapshots.deleteSnapshot(undefined, 'snapshot-123', mockBaseUrl)).rejects.toThrow('Authentication token is required');
86
+ console.log('Correctly rejected remove with missing token');
87
+ });
88
+ it('should fail when snapshot ID is missing', async () => {
89
+ console.log('Testing remove with missing snapshot ID...');
90
+ await expect(
91
+ // @ts-expect-error Testing undefined snapshot ID
92
+ snapshots.deleteSnapshot(MOCK_JWT_TOKEN, undefined, mockBaseUrl)).rejects.toThrow('Snapshot ID is required');
93
+ console.log('Correctly rejected remove with missing snapshot ID');
94
+ });
95
+ });
96
+ });
@@ -0,0 +1,9 @@
1
+ import { EnvironmentsListResponse } from '../types/runtimes';
2
+ /**
3
+ * List all available computing environments.
4
+ * @param token - Authentication token
5
+ * @param baseUrl - Base URL for the API (defaults to production Runtimes URL)
6
+ * @returns Promise resolving to list of available environments
7
+ * @throws {Error} If authentication token is missing or invalid
8
+ */
9
+ export declare const listEnvironments: (token: string, baseUrl?: string) => Promise<EnvironmentsListResponse>;
@@ -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/runtimes/environments
7
+ * @description Computing environments API functions for the Datalayer platform.
8
+ *
9
+ * Provides functions for managing computing environment configurations.
10
+ */
11
+ import { requestDatalayerAPI } from '../DatalayerApi';
12
+ import { API_BASE_PATHS, DEFAULT_SERVICE_URLS } from '../constants';
13
+ import { validateToken } from '../utils/validation';
14
+ /**
15
+ * List all available computing environments.
16
+ * @param token - Authentication token
17
+ * @param baseUrl - Base URL for the API (defaults to production Runtimes URL)
18
+ * @returns Promise resolving to list of available environments
19
+ * @throws {Error} If authentication token is missing or invalid
20
+ */
21
+ export const listEnvironments = async (token, baseUrl = DEFAULT_SERVICE_URLS.RUNTIMES) => {
22
+ validateToken(token);
23
+ return requestDatalayerAPI({
24
+ url: `${baseUrl}${API_BASE_PATHS.RUNTIMES}/environments`,
25
+ method: 'GET',
26
+ token,
27
+ });
28
+ };
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Health check response from the Runtimes service
3
+ */
4
+ export interface RuntimesHealthzPingResponse {
5
+ success: boolean;
6
+ message: string;
7
+ status?: {
8
+ status: string;
9
+ };
10
+ version?: string;
11
+ }
12
+ /**
13
+ * Health check ping endpoint for Runtimes service
14
+ * @param baseUrl - Base URL for the API (defaults to production Runtimes 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 Runtimes 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<RuntimesHealthzPingResponse>;
@@ -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/runtimes/healthz
7
+ * @description Health check API functions for the Datalayer Runtimes service.
8
+ *
9
+ * Provides functions for checking the health status of the Runtimes service.
10
+ */
11
+ import { requestDatalayerAPI } from '../DatalayerApi';
12
+ import { API_BASE_PATHS, DEFAULT_SERVICE_URLS } from '../constants';
13
+ /**
14
+ * Health check ping endpoint for Runtimes service
15
+ * @param baseUrl - Base URL for the API (defaults to production Runtimes 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 Runtimes 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.RUNTIMES) => {
27
+ try {
28
+ const response = await requestDatalayerAPI({
29
+ url: `${baseUrl}${API_BASE_PATHS.RUNTIMES}/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
+ };
@@ -1,5 +1,10 @@
1
- export * from './actions';
2
- export * from './apis';
3
- export * from './settings';
4
- export * from './snapshots';
5
- export * from './utils';
1
+ /**
2
+ * @module api/runtimes
3
+ * @description Runtimes API exports.
4
+ *
5
+ * Provides organized access to runtime management functionality.
6
+ */
7
+ export * as environments from './environments';
8
+ export * as healthz from './healthz';
9
+ export * as runtimes from './runtimes';
10
+ export * as snapshots from './snapshots';
@@ -2,8 +2,13 @@
2
2
  * Copyright (c) 2023-2025 Datalayer, Inc.
3
3
  * Distributed under the terms of the Modified BSD License.
4
4
  */
5
- export * from './actions';
6
- export * from './apis';
7
- export * from './settings';
8
- export * from './snapshots';
9
- export * from './utils';
5
+ /**
6
+ * @module api/runtimes
7
+ * @description Runtimes API exports.
8
+ *
9
+ * Provides organized access to runtime management functionality.
10
+ */
11
+ export * as environments from './environments';
12
+ export * as healthz from './healthz';
13
+ export * as runtimes from './runtimes';
14
+ export * as snapshots from './snapshots';
@@ -0,0 +1,54 @@
1
+ import { Runtime, CreateRuntimeRequest, CreateRuntimeResponse, RuntimesListResponse } from '../types/runtimes';
2
+ /**
3
+ * Create a new runtime instance.
4
+ * @param token - Authentication token
5
+ * @param data - Runtime creation configuration
6
+ * @param baseUrl - Base URL for the API (defaults to production Runtimes URL)
7
+ * @returns Promise resolving to the created runtime details
8
+ * @throws {Error} If authentication token is missing or invalid
9
+ * @throws {Error} With status 404 if the environment is not found
10
+ * @throws {Error} With status 503 if no runtime is available
11
+ */
12
+ export declare const createRuntime: (token: string, data: CreateRuntimeRequest, baseUrl?: string) => Promise<CreateRuntimeResponse>;
13
+ /**
14
+ * List all runtime instances.
15
+ * @param token - Authentication token
16
+ * @param baseUrl - Base URL for the API (defaults to production Runtimes URL)
17
+ * @returns Promise resolving to list of runtime instances
18
+ * @throws {Error} If authentication token is missing or invalid
19
+ */
20
+ export declare const listRuntimes: (token: string, baseUrl?: string) => Promise<RuntimesListResponse>;
21
+ /**
22
+ * Get details for a specific runtime instance.
23
+ * @param token - Authentication token
24
+ * @param podName - The unique pod name of the runtime
25
+ * @param baseUrl - Base URL for the API (defaults to production Runtimes URL)
26
+ * @returns Promise resolving to runtime details
27
+ * @throws {Error} If authentication token is missing or invalid
28
+ * @throws {Error} If pod name is missing or invalid
29
+ * @throws {Error} With status 404 if the runtime is not found
30
+ */
31
+ export declare const getRuntime: (token: string, podName: string, baseUrl?: string) => Promise<Runtime>;
32
+ /**
33
+ * Delete a runtime instance.
34
+ * @param token - Authentication token
35
+ * @param podName - The unique pod name of the runtime to delete
36
+ * @param baseUrl - Base URL for the API (defaults to production Runtimes URL)
37
+ * @returns Promise resolving when deletion is complete
38
+ * @throws {Error} If authentication token is missing or invalid
39
+ * @throws {Error} If pod name is missing or invalid
40
+ * @throws {Error} With status 404 if the runtime is not found
41
+ */
42
+ export declare const deleteRuntime: (token: string, podName: string, baseUrl?: string) => Promise<void>;
43
+ /**
44
+ * Update a runtime instance.
45
+ * @param token - Authentication token
46
+ * @param podName - The unique pod name of the runtime
47
+ * @param from - The source to update from
48
+ * @param baseUrl - Base URL for the API (defaults to production Runtimes URL)
49
+ * @returns Promise resolving to updated runtime details
50
+ * @throws {Error} If authentication token is missing or invalid
51
+ * @throws {Error} If pod name is missing or invalid
52
+ * @throws {Error} With status 404 if the runtime is not found
53
+ */
54
+ export declare const updateRuntime: (token: string, podName: string, from: string, baseUrl?: string) => Promise<Runtime>;
@@ -0,0 +1,169 @@
1
+ /*
2
+ * Copyright (c) 2023-2025 Datalayer, Inc.
3
+ * Distributed under the terms of the Modified BSD License.
4
+ */
5
+ /**
6
+ * @module api/runtimes/runtimes
7
+ * @description Runtime instances API functions for the Datalayer platform.
8
+ *
9
+ * Provides functions for managing runtime instances (active compute containers).
10
+ */
11
+ import { requestDatalayerAPI } from '../DatalayerApi';
12
+ import { API_BASE_PATHS, DEFAULT_SERVICE_URLS } from '../constants';
13
+ import { validateToken, validateRequiredString } from '../utils/validation';
14
+ /**
15
+ * Create a new runtime instance.
16
+ * @param token - Authentication token
17
+ * @param data - Runtime creation configuration
18
+ * @param baseUrl - Base URL for the API (defaults to production Runtimes URL)
19
+ * @returns Promise resolving to the created runtime details
20
+ * @throws {Error} If authentication token is missing or invalid
21
+ * @throws {Error} With status 404 if the environment is not found
22
+ * @throws {Error} With status 503 if no runtime is available
23
+ */
24
+ export const createRuntime = async (token, data, baseUrl = DEFAULT_SERVICE_URLS.RUNTIMES) => {
25
+ validateToken(token);
26
+ try {
27
+ return await requestDatalayerAPI({
28
+ url: `${baseUrl}${API_BASE_PATHS.RUNTIMES}/runtimes`,
29
+ method: 'POST',
30
+ body: data,
31
+ token,
32
+ });
33
+ }
34
+ catch (error) {
35
+ // Handle specific error cases
36
+ if (error.response) {
37
+ const status = error.response.status;
38
+ const responseData = error.response.data || {};
39
+ if (status === 404) {
40
+ // Environment not found
41
+ throw new Error(`Environment '${data.environment_name}' not found. ${responseData.message || 'Please check the environment name and try again.'}`);
42
+ }
43
+ else if (status === 503) {
44
+ // No runtime available
45
+ throw new Error(`No runtime available. ${responseData.message || 'The service is temporarily unavailable or at capacity. Please try again later.'}`);
46
+ }
47
+ }
48
+ // Re-throw the original error for other cases
49
+ throw error;
50
+ }
51
+ };
52
+ /**
53
+ * List all runtime instances.
54
+ * @param token - Authentication token
55
+ * @param baseUrl - Base URL for the API (defaults to production Runtimes URL)
56
+ * @returns Promise resolving to list of runtime instances
57
+ * @throws {Error} If authentication token is missing or invalid
58
+ */
59
+ export const listRuntimes = async (token, baseUrl = DEFAULT_SERVICE_URLS.RUNTIMES) => {
60
+ validateToken(token);
61
+ return requestDatalayerAPI({
62
+ url: `${baseUrl}${API_BASE_PATHS.RUNTIMES}/runtimes`,
63
+ method: 'GET',
64
+ token,
65
+ });
66
+ };
67
+ /**
68
+ * Get details for a specific runtime instance.
69
+ * @param token - Authentication token
70
+ * @param podName - The unique pod name of the runtime
71
+ * @param baseUrl - Base URL for the API (defaults to production Runtimes URL)
72
+ * @returns Promise resolving to runtime details
73
+ * @throws {Error} If authentication token is missing or invalid
74
+ * @throws {Error} If pod name is missing or invalid
75
+ * @throws {Error} With status 404 if the runtime is not found
76
+ */
77
+ export const getRuntime = async (token, podName, baseUrl = DEFAULT_SERVICE_URLS.RUNTIMES) => {
78
+ validateToken(token);
79
+ validateRequiredString(podName, 'Pod name');
80
+ try {
81
+ const response = await requestDatalayerAPI({
82
+ url: `${baseUrl}${API_BASE_PATHS.RUNTIMES}/runtimes/${podName}`,
83
+ method: 'GET',
84
+ token,
85
+ });
86
+ // The API returns { success: true, message: string, kernel: Runtime }
87
+ // We need to return just the runtime data
88
+ if (response.kernel) {
89
+ // Map kernel fields to Runtime fields
90
+ return {
91
+ ...response.kernel,
92
+ pod_name: response.kernel.pod_name || podName,
93
+ };
94
+ }
95
+ // Fallback if response structure is different
96
+ return response;
97
+ }
98
+ catch (error) {
99
+ // Handle specific error cases
100
+ if (error.response && error.response.status === 404) {
101
+ // Runtime not found
102
+ throw new Error(`Runtime with pod name '${podName}' not found. Please check the pod name and try again.`);
103
+ }
104
+ // Re-throw the original error for other cases
105
+ throw error;
106
+ }
107
+ };
108
+ /**
109
+ * Delete a runtime instance.
110
+ * @param token - Authentication token
111
+ * @param podName - The unique pod name of the runtime to delete
112
+ * @param baseUrl - Base URL for the API (defaults to production Runtimes URL)
113
+ * @returns Promise resolving when deletion is complete
114
+ * @throws {Error} If authentication token is missing or invalid
115
+ * @throws {Error} If pod name is missing or invalid
116
+ * @throws {Error} With status 404 if the runtime is not found
117
+ */
118
+ export const deleteRuntime = async (token, podName, baseUrl = DEFAULT_SERVICE_URLS.RUNTIMES) => {
119
+ validateToken(token);
120
+ validateRequiredString(podName, 'Pod name');
121
+ try {
122
+ return await requestDatalayerAPI({
123
+ url: `${baseUrl}${API_BASE_PATHS.RUNTIMES}/runtimes/${podName}`,
124
+ method: 'DELETE',
125
+ token,
126
+ });
127
+ }
128
+ catch (error) {
129
+ // Handle specific error cases
130
+ if (error.response && error.response.status === 404) {
131
+ // Runtime not found
132
+ throw new Error(`Runtime with pod name '${podName}' not found. Cannot delete a non-existent runtime.`);
133
+ }
134
+ // Re-throw the original error for other cases
135
+ throw error;
136
+ }
137
+ };
138
+ /**
139
+ * Update a runtime instance.
140
+ * @param token - Authentication token
141
+ * @param podName - The unique pod name of the runtime
142
+ * @param from - The source to update from
143
+ * @param baseUrl - Base URL for the API (defaults to production Runtimes URL)
144
+ * @returns Promise resolving to updated runtime details
145
+ * @throws {Error} If authentication token is missing or invalid
146
+ * @throws {Error} If pod name is missing or invalid
147
+ * @throws {Error} With status 404 if the runtime is not found
148
+ */
149
+ export const updateRuntime = async (token, podName, from, baseUrl = DEFAULT_SERVICE_URLS.RUNTIMES) => {
150
+ validateToken(token);
151
+ validateRequiredString(podName, 'Pod name');
152
+ try {
153
+ return await requestDatalayerAPI({
154
+ url: `${baseUrl}${API_BASE_PATHS.RUNTIMES}/runtimes/${podName}`,
155
+ method: 'PUT',
156
+ token,
157
+ body: { from },
158
+ });
159
+ }
160
+ catch (error) {
161
+ // Handle specific error cases
162
+ if (error.response && error.response.status === 404) {
163
+ // Runtime not found
164
+ throw new Error(`Runtime with pod name '${podName}' not found. Cannot update a non-existent runtime.`);
165
+ }
166
+ // Re-throw the original error for other cases
167
+ throw error;
168
+ }
169
+ };