@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,271 @@
1
+ /**
2
+ * Represents a workspace or project space in Datalayer
3
+ * @interface Space
4
+ */
5
+ export interface Space {
6
+ id?: string;
7
+ uid: string;
8
+ name?: string;
9
+ name_t?: string;
10
+ handle_s?: string;
11
+ variant_s?: string;
12
+ description?: string;
13
+ description_t?: string;
14
+ visibility?: 'public' | 'private' | 'organization';
15
+ owner_id?: string;
16
+ organization_id?: string;
17
+ created_at?: string;
18
+ updated_at?: string;
19
+ creation_ts_dt?: string;
20
+ last_update_ts_dt?: string;
21
+ notebooks_count?: number;
22
+ members_count?: number;
23
+ tags?: string[];
24
+ tags_ss?: string[];
25
+ items?: any[];
26
+ members?: any[];
27
+ }
28
+ /**
29
+ * Represents a Jupyter notebook document
30
+ * @interface Notebook
31
+ */
32
+ export interface Notebook {
33
+ id: string;
34
+ uid: string;
35
+ name?: string;
36
+ name_t?: string;
37
+ path?: string;
38
+ content?: any;
39
+ space_id?: string;
40
+ owner_id?: string;
41
+ creator_uid?: string;
42
+ creator_handle_s?: string;
43
+ created_at?: string;
44
+ creation_ts_dt?: string;
45
+ updated_at?: string;
46
+ last_update_ts_dt?: string;
47
+ version?: number;
48
+ kernel_spec?: any;
49
+ metadata?: Record<string, any>;
50
+ type_s?: string;
51
+ public_b?: boolean;
52
+ description_t?: string;
53
+ notebook_name_s?: string;
54
+ notebook_extension_s?: string;
55
+ notebook_format_s?: string;
56
+ content_length_i?: number;
57
+ content_type_s?: string;
58
+ mime_type_s?: string;
59
+ s3_path_s?: string;
60
+ s3_url_s?: string;
61
+ cdn_url_s?: string;
62
+ model_s?: string;
63
+ }
64
+ /**
65
+ * Represents a single cell in a Jupyter notebook
66
+ * @interface Cell
67
+ */
68
+ export interface Cell {
69
+ id: string;
70
+ cell_type: 'code' | 'markdown' | 'raw';
71
+ source: string | string[];
72
+ outputs?: any[];
73
+ execution_count?: number | null;
74
+ metadata?: Record<string, any>;
75
+ }
76
+ /**
77
+ * Request payload for creating a new space
78
+ * @interface CreateSpaceRequest
79
+ */
80
+ export interface CreateSpaceRequest {
81
+ name: string;
82
+ description: string;
83
+ variant: string;
84
+ spaceHandle: string;
85
+ organizationId: string;
86
+ seedSpaceId: string;
87
+ public: boolean;
88
+ }
89
+ /**
90
+ * Response from creating a space
91
+ * @interface CreateSpaceResponse
92
+ */
93
+ export interface CreateSpaceResponse {
94
+ success: boolean;
95
+ message: string;
96
+ space: Space;
97
+ }
98
+ /**
99
+ * Request payload for creating a new notebook (multipart/form-data)
100
+ * @interface CreateNotebookRequest
101
+ */
102
+ export interface CreateNotebookRequest {
103
+ spaceId: string;
104
+ notebookType: string;
105
+ name: string;
106
+ description: string;
107
+ file?: File | Blob;
108
+ }
109
+ /**
110
+ * Response from creating a notebook
111
+ * @interface CreateNotebookResponse
112
+ */
113
+ export interface CreateNotebookResponse {
114
+ success: boolean;
115
+ message: string;
116
+ notebook: Notebook;
117
+ }
118
+ /**
119
+ * Response from getting a notebook
120
+ * @interface GetNotebookResponse
121
+ */
122
+ export interface GetNotebookResponse {
123
+ success: boolean;
124
+ message: string;
125
+ notebook?: Notebook;
126
+ }
127
+ /**
128
+ * Request payload for creating a notebook
129
+ * @interface CreateNotebookRequest
130
+ */
131
+ export interface CreateNotebookRequest {
132
+ spaceId: string;
133
+ notebookType: string;
134
+ name: string;
135
+ description: string;
136
+ file?: File | Blob;
137
+ }
138
+ /**
139
+ * Request payload for updating a notebook
140
+ * @interface UpdateNotebookRequest
141
+ */
142
+ export interface UpdateNotebookRequest {
143
+ name?: string;
144
+ description?: string;
145
+ }
146
+ /**
147
+ * Response from updating a notebook
148
+ * @interface UpdateNotebookResponse
149
+ */
150
+ export interface UpdateNotebookResponse {
151
+ success: boolean;
152
+ message: string;
153
+ notebook: Notebook;
154
+ }
155
+ /**
156
+ * Represents an item within a space
157
+ * @interface SpaceItem
158
+ */
159
+ export interface SpaceItem {
160
+ id: string;
161
+ type: 'notebook' | 'lexical' | 'cell';
162
+ space_id: string;
163
+ item_id: string;
164
+ name: string;
165
+ created_at: string;
166
+ updated_at?: string;
167
+ }
168
+ /**
169
+ * Represents a Lexical document (rich text editor)
170
+ * @interface Lexical
171
+ */
172
+ export interface Lexical {
173
+ id: string;
174
+ uid: string;
175
+ name?: string;
176
+ name_t?: string;
177
+ content?: any;
178
+ space_id?: string;
179
+ owner_id?: string;
180
+ creator_uid?: string;
181
+ creator_handle_s?: string;
182
+ created_at?: string;
183
+ creation_ts_dt?: string;
184
+ updated_at?: string;
185
+ last_update_ts_dt?: string;
186
+ type_s?: string;
187
+ public_b?: boolean;
188
+ description_t?: string;
189
+ document_name_s?: string;
190
+ document_extension_s?: string;
191
+ document_format_s?: string;
192
+ content_length_i?: number;
193
+ content_type_s?: string;
194
+ mime_type_s?: string;
195
+ s3_path_s?: string;
196
+ s3_url_s?: string;
197
+ cdn_url_s?: string;
198
+ model_s?: string;
199
+ }
200
+ /**
201
+ * Request payload for creating a Lexical document
202
+ * @interface CreateLexicalRequest
203
+ */
204
+ export interface CreateLexicalRequest {
205
+ spaceId: string;
206
+ documentType: string;
207
+ name: string;
208
+ description: string;
209
+ file?: File | Blob;
210
+ }
211
+ /**
212
+ * Response from creating a Lexical document
213
+ * @interface CreateLexicalResponse
214
+ */
215
+ export interface CreateLexicalResponse {
216
+ success: boolean;
217
+ message: string;
218
+ document: Lexical;
219
+ }
220
+ /**
221
+ * Response from getting a Lexical document
222
+ * @interface GetLexicalResponse
223
+ */
224
+ export interface GetLexicalResponse {
225
+ success: boolean;
226
+ message: string;
227
+ document?: Lexical;
228
+ }
229
+ /**
230
+ * Request payload for updating a Lexical document
231
+ * @interface UpdateLexicalRequest
232
+ */
233
+ export interface UpdateLexicalRequest {
234
+ name?: string;
235
+ description?: string;
236
+ }
237
+ /**
238
+ * Response from updating a Lexical document
239
+ * @interface UpdateLexicalResponse
240
+ */
241
+ export interface UpdateLexicalResponse {
242
+ success: boolean;
243
+ message: string;
244
+ document: Lexical;
245
+ }
246
+ /**
247
+ * Response from getting space items
248
+ * @interface GetSpaceItemsResponse
249
+ */
250
+ export interface GetSpaceItemsResponse {
251
+ success: boolean;
252
+ message: string;
253
+ items: SpaceItem[];
254
+ }
255
+ /**
256
+ * Response from deleting a space item
257
+ * @interface DeleteSpaceItemResponse
258
+ */
259
+ export interface DeleteSpaceItemResponse {
260
+ success: boolean;
261
+ message: string;
262
+ }
263
+ /**
264
+ * Response from getting spaces for a user
265
+ * @interface SpacesForUserResponse
266
+ */
267
+ export interface SpacesForUserResponse {
268
+ success: boolean;
269
+ message: string;
270
+ spaces: Space[];
271
+ }
@@ -0,0 +1,5 @@
1
+ /*
2
+ * Copyright (c) 2023-2025 Datalayer, Inc.
3
+ * Distributed under the terms of the Modified BSD License.
4
+ */
5
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,109 @@
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 { validateToken, validateRequired, validateRequiredString, } from '../validation';
7
+ describe('validation utilities', () => {
8
+ describe('validateToken', () => {
9
+ const validToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyLCJleHAiOjk5OTk5OTk5OTl9.Vg30C57s3l90JNap_VgMhKZjfc-p7SoBXaSAy8c6BS8';
10
+ it('should accept valid JWT tokens', () => {
11
+ expect(() => validateToken(validToken)).not.toThrow();
12
+ });
13
+ it('should reject null or undefined tokens', () => {
14
+ expect(() => validateToken(null)).toThrow('Authentication token is required');
15
+ expect(() => validateToken(undefined)).toThrow('Authentication token is required');
16
+ });
17
+ it('should reject empty or whitespace tokens', () => {
18
+ expect(() => validateToken('')).toThrow('Authentication token is required');
19
+ expect(() => validateToken(' ')).toThrow('Authentication token is required');
20
+ });
21
+ it('should reject tokens without three parts', () => {
22
+ expect(() => validateToken('part1.part2')).toThrow('Invalid token format: JWT must have three parts separated by dots');
23
+ expect(() => validateToken('part1.part2.part3.part4')).toThrow('Invalid token format: JWT must have three parts separated by dots');
24
+ expect(() => validateToken('singlepart')).toThrow('Invalid token format: JWT must have three parts separated by dots');
25
+ });
26
+ it('should reject tokens with empty parts', () => {
27
+ expect(() => validateToken('.part2.part3')).toThrow('Invalid token format: Part 1 is empty');
28
+ expect(() => validateToken('part1..part3')).toThrow('Invalid token format: Part 2 is empty');
29
+ expect(() => validateToken('part1.part2.')).toThrow('Invalid token format: Part 3 is empty');
30
+ });
31
+ it('should reject tokens with invalid Base64URL characters', () => {
32
+ const invalidCharToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWI!@#$.Vg30C57s3l90JNap_VgMhKZjfc-p7SoBXaSAy8c6BS8';
33
+ expect(() => validateToken(invalidCharToken)).toThrow('Invalid token format: Part 2 contains invalid characters');
34
+ });
35
+ it('should reject tokens that are too short', () => {
36
+ const shortToken = 'eyJ0eXAiOiJKV1QifQ.eyJzdWIiOiIxIn0.signature';
37
+ expect(() => validateToken(shortToken)).toThrow('Invalid token format: Token is too short to be a valid JWT');
38
+ });
39
+ it('should reject tokens that are too long', () => {
40
+ const header = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9';
41
+ const payload = 'a'.repeat(4000);
42
+ const signature = 'b'.repeat(1000);
43
+ const longToken = `${header}.${payload}.${signature}`;
44
+ expect(() => validateToken(longToken)).toThrow('Invalid token format: Token exceeds maximum expected length');
45
+ });
46
+ it('should reject tokens with invalid JWT header', () => {
47
+ const invalidHeaderToken = 'notbase64.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.signature123456789012345';
48
+ expect(() => validateToken(invalidHeaderToken)).toThrow('Invalid token format: JWT header is not valid base64-encoded JSON');
49
+ });
50
+ it('should reject tokens with missing algorithm in header', () => {
51
+ // This token has valid JSON header but missing 'alg' field
52
+ const noAlgToken = 'eyJ0eXAiOiJKV1QifQ.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyLCJleHAiOjk5OTk5OTk5OTl9.signature123456789012345678901234567890';
53
+ expect(() => validateToken(noAlgToken)).toThrow('Invalid token format: Missing algorithm in JWT header');
54
+ });
55
+ it('should reject tokens with invalid JWT payload', () => {
56
+ // This token has enough length but invalid base64 in payload
57
+ const invalidPayloadToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.notvalidbase64jsonbutlongenoughtopasslengthchecknotvalidbase64jsonbutlongenough.signature123456789012345678901234567890';
58
+ expect(() => validateToken(invalidPayloadToken)).toThrow('Invalid token format: JWT payload is not valid base64-encoded JSON');
59
+ });
60
+ it('should reject expired tokens', () => {
61
+ const expiredToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyLCJleHAiOjE1MTYyMzkwMjJ9.4Adcj3UFYzPUVaVF43FmMab6RlaQD8A9V8wFzzht-KQ';
62
+ expect(() => validateToken(expiredToken)).toThrow('Token has expired');
63
+ });
64
+ it('should reject tokens not yet valid (nbf claim)', () => {
65
+ const futureToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyLCJuYmYiOjk5OTk5OTk5OTl9.UGLFIRACvGl-MiFpZmAiDuVm7br9tBTxMOqb4sjN-jg';
66
+ expect(() => validateToken(futureToken)).toThrow('Token is not yet valid');
67
+ });
68
+ it('should reject tokens with signature that is too short', () => {
69
+ const shortSigToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.short';
70
+ expect(() => validateToken(shortSigToken)).toThrow('Invalid token format: JWT signature is too short');
71
+ });
72
+ it('should trim whitespace from tokens', () => {
73
+ const tokenWithWhitespace = ` ${validToken} `;
74
+ expect(() => validateToken(tokenWithWhitespace)).not.toThrow();
75
+ });
76
+ });
77
+ describe('validateRequired', () => {
78
+ it('should accept valid values', () => {
79
+ expect(() => validateRequired('value', 'param')).not.toThrow();
80
+ expect(() => validateRequired(0, 'param')).not.toThrow();
81
+ expect(() => validateRequired(false, 'param')).not.toThrow();
82
+ expect(() => validateRequired('', 'param')).not.toThrow();
83
+ });
84
+ it('should reject null values', () => {
85
+ expect(() => validateRequired(null, 'param')).toThrow('param is required');
86
+ });
87
+ it('should reject undefined values', () => {
88
+ expect(() => validateRequired(undefined, 'param')).toThrow('param is required');
89
+ });
90
+ });
91
+ describe('validateRequiredString', () => {
92
+ it('should accept valid strings', () => {
93
+ expect(() => validateRequiredString('value', 'param')).not.toThrow();
94
+ expect(() => validateRequiredString(' value ', 'param')).not.toThrow();
95
+ });
96
+ it('should reject null values', () => {
97
+ expect(() => validateRequiredString(null, 'param')).toThrow('param is required');
98
+ });
99
+ it('should reject undefined values', () => {
100
+ expect(() => validateRequiredString(undefined, 'param')).toThrow('param is required');
101
+ });
102
+ it('should reject empty strings', () => {
103
+ expect(() => validateRequiredString('', 'param')).toThrow('param is required');
104
+ });
105
+ it('should reject whitespace-only strings', () => {
106
+ expect(() => validateRequiredString(' ', 'param')).toThrow('param is required');
107
+ });
108
+ });
109
+ });
@@ -0,0 +1,24 @@
1
+ /**
2
+ * @module api/utils/validation
3
+ * @description Utility functions for API parameter validation
4
+ */
5
+ /**
6
+ * Validates that an authentication token is provided and is a valid JWT format
7
+ * @param token - The authentication token to validate
8
+ * @throws {Error} If the token is missing, null, undefined, empty/whitespace, or not a valid JWT format
9
+ */
10
+ export declare const validateToken: (token: string | undefined | null) => void;
11
+ /**
12
+ * Validates that a required parameter is provided
13
+ * @param value - The value to validate
14
+ * @param paramName - The name of the parameter for error messages
15
+ * @throws {Error} If the value is missing, null, or undefined
16
+ */
17
+ export declare const validateRequired: (value: any, paramName: string) => void;
18
+ /**
19
+ * Validates that a string parameter is provided and not empty
20
+ * @param value - The string value to validate
21
+ * @param paramName - The name of the parameter for error messages
22
+ * @throws {Error} If the value is missing, null, undefined, or empty/whitespace
23
+ */
24
+ export declare const validateRequiredString: (value: string | undefined | null, paramName: string) => void;
@@ -0,0 +1,133 @@
1
+ /*
2
+ * Copyright (c) 2023-2025 Datalayer, Inc.
3
+ * Distributed under the terms of the Modified BSD License.
4
+ */
5
+ /**
6
+ * @module api/utils/validation
7
+ * @description Utility functions for API parameter validation
8
+ */
9
+ /**
10
+ * Validates that an authentication token is provided and is a valid JWT format
11
+ * @param token - The authentication token to validate
12
+ * @throws {Error} If the token is missing, null, undefined, empty/whitespace, or not a valid JWT format
13
+ */
14
+ export const validateToken = (token) => {
15
+ // Check if token exists and is not empty
16
+ if (!token || !token.trim()) {
17
+ throw new Error('Authentication token is required');
18
+ }
19
+ const trimmedToken = token.trim();
20
+ // JWT should have three parts separated by dots (header.payload.signature)
21
+ const parts = trimmedToken.split('.');
22
+ if (parts.length !== 3) {
23
+ throw new Error('Invalid token format: JWT must have three parts separated by dots');
24
+ }
25
+ // Check each part is Base64URL encoded (contains only valid characters)
26
+ const base64UrlRegex = /^[A-Za-z0-9_-]+$/;
27
+ for (let i = 0; i < parts.length; i++) {
28
+ const part = parts[i];
29
+ // Each part should not be empty
30
+ if (!part || part.length === 0) {
31
+ throw new Error(`Invalid token format: Part ${i + 1} is empty`);
32
+ }
33
+ // Check for valid Base64URL characters
34
+ if (!base64UrlRegex.test(part)) {
35
+ throw new Error(`Invalid token format: Part ${i + 1} contains invalid characters`);
36
+ }
37
+ }
38
+ // Check reasonable length constraints
39
+ // JWT tokens are typically 100-2000 characters depending on claims
40
+ if (trimmedToken.length < 100) {
41
+ throw new Error('Invalid token format: Token is too short to be a valid JWT');
42
+ }
43
+ if (trimmedToken.length > 5000) {
44
+ throw new Error('Invalid token format: Token exceeds maximum expected length');
45
+ }
46
+ // Validate header structure (should be valid base64url JSON)
47
+ try {
48
+ // Use Buffer for Node.js compatibility or atob for browser
49
+ const headerBase64 = parts[0].replace(/-/g, '+').replace(/_/g, '/');
50
+ const headerString = typeof Buffer !== 'undefined'
51
+ ? Buffer.from(headerBase64, 'base64').toString()
52
+ : atob(headerBase64);
53
+ const header = JSON.parse(headerString);
54
+ // Check for required JWT header fields
55
+ if (!header.alg) {
56
+ throw new Error('Invalid token format: Missing algorithm in JWT header');
57
+ }
58
+ if (!header.typ && !header.cty) {
59
+ // typ is optional but common, if missing there should be at least some type indication
60
+ console.warn('JWT header missing "typ" field, which is recommended');
61
+ }
62
+ }
63
+ catch (e) {
64
+ if (e instanceof Error &&
65
+ e.message === 'Invalid token format: Missing algorithm in JWT header') {
66
+ throw e;
67
+ }
68
+ throw new Error('Invalid token format: JWT header is not valid base64-encoded JSON');
69
+ }
70
+ // Validate payload structure (should be valid base64url JSON)
71
+ try {
72
+ // Use Buffer for Node.js compatibility or atob for browser
73
+ const payloadBase64 = parts[1].replace(/-/g, '+').replace(/_/g, '/');
74
+ const payloadString = typeof Buffer !== 'undefined'
75
+ ? Buffer.from(payloadBase64, 'base64').toString()
76
+ : atob(payloadBase64);
77
+ const payload = JSON.parse(payloadString);
78
+ // Check for common JWT claims (at least one should typically be present)
79
+ const commonClaims = ['iss', 'sub', 'aud', 'exp', 'nbf', 'iat', 'jti'];
80
+ const hasCommonClaim = commonClaims.some(claim => payload[claim] !== undefined);
81
+ if (!hasCommonClaim) {
82
+ console.warn('JWT payload missing common claims, token may be non-standard');
83
+ }
84
+ // If exp (expiration) exists, check if token is expired
85
+ if (payload.exp) {
86
+ const now = Math.floor(Date.now() / 1000);
87
+ if (payload.exp < now) {
88
+ throw new Error('Token has expired');
89
+ }
90
+ }
91
+ // If nbf (not before) exists, check if token is not yet valid
92
+ if (payload.nbf) {
93
+ const now = Math.floor(Date.now() / 1000);
94
+ if (payload.nbf > now) {
95
+ throw new Error('Token is not yet valid');
96
+ }
97
+ }
98
+ }
99
+ catch (e) {
100
+ if (e instanceof Error &&
101
+ (e.message === 'Token has expired' ||
102
+ e.message === 'Token is not yet valid')) {
103
+ throw e;
104
+ }
105
+ throw new Error('Invalid token format: JWT payload is not valid base64-encoded JSON');
106
+ }
107
+ // Signature part validation (just check it exists and has reasonable length)
108
+ if (parts[2].length < 20) {
109
+ throw new Error('Invalid token format: JWT signature is too short');
110
+ }
111
+ };
112
+ /**
113
+ * Validates that a required parameter is provided
114
+ * @param value - The value to validate
115
+ * @param paramName - The name of the parameter for error messages
116
+ * @throws {Error} If the value is missing, null, or undefined
117
+ */
118
+ export const validateRequired = (value, paramName) => {
119
+ if (value === null || value === undefined) {
120
+ throw new Error(`${paramName} is required`);
121
+ }
122
+ };
123
+ /**
124
+ * Validates that a string parameter is provided and not empty
125
+ * @param value - The string value to validate
126
+ * @param paramName - The name of the parameter for error messages
127
+ * @throws {Error} If the value is missing, null, undefined, or empty/whitespace
128
+ */
129
+ export const validateRequiredString = (value, paramName) => {
130
+ if (!value || !value.trim()) {
131
+ throw new Error(`${paramName} is required`);
132
+ }
133
+ };
@@ -59,13 +59,9 @@ export class JupyterDialog extends ReactWidget {
59
59
  }) }));
60
60
  _renderFooter = (props) => (_jsx(DialogFooter, { ...props, checkbox: this.checkbox, setChecked: this.setChecked }));
61
61
  render() {
62
- return (_jsx(JupyterReactTheme, { children: _jsx(PrimerDialog, { sx: {
63
- color: 'var(--fgColor-default)',
64
- backgroundColor: 'var(--bgColor-default)',
65
- fontFamily: 'var(--fontStack-system)',
66
- fontSize: 'var(--text-body-size-medium)',
67
- lineHeight: 'var(--text-body-lineHeight-medium)',
68
- }, onClose: this.close, footerButtons: this.buttons.map((but, idx) => {
62
+ // TODO title color is enforced for JupyterLab.
63
+ // This may be fixed in the jupyter-react theme (Primer generates h1 for the dialog title).
64
+ return (_jsx(JupyterReactTheme, { children: _jsx(PrimerDialog, { title: _jsx("span", { style: { color: 'var(--fgColor-default)' }, children: this.dialogTitle }), onClose: this.close, renderBody: this._renderBody, renderFooter: this._renderFooter, footerButtons: this.buttons.map((but, idx) => {
69
65
  const footerButton = {
70
66
  buttonType: but.displayType === 'default'
71
67
  ? but.accept
@@ -80,7 +76,7 @@ export class JupyterDialog extends ReactWidget {
80
76
  autoFocus: but.accept,
81
77
  };
82
78
  return footerButton;
83
- }), renderBody: this._renderBody, renderFooter: this._renderFooter, title: this.dialogTitle }) }));
79
+ }) }) }));
84
80
  }
85
81
  /**
86
82
  * Launch the dialog as a modal window.
@@ -1,4 +1,4 @@
1
- import type { IRemoteServicesManager } from '../../api';
1
+ import type { IRemoteServicesManager } from '../../sdk/stateful/runtimes';
2
2
  type ICreditsIndicatorProps = {
3
3
  /**
4
4
  * Kernel service manager
@@ -8,7 +8,7 @@ import { Dialog } from '@primer/react/experimental';
8
8
  import { nullTranslator } from '@jupyterlab/translation';
9
9
  import { JSONExt } from '@lumino/coreutils';
10
10
  import { KernelExecutor } from '@datalayer/jupyter-react';
11
- import { RuntimeSnippetsFacade } from '../../api';
11
+ import { RuntimeSnippetsFacade } from '../../sdk/stateful/jupyter';
12
12
  import { RuntimeCellVariables } from './RuntimeCellVariables';
13
13
  /**
14
14
  * Dialog to define the runtime cell variables to transfer
@@ -84,7 +84,7 @@ export function RuntimeCellVariablesDialog(props) {
84
84
  title += ` with ${kernelName}`;
85
85
  }
86
86
  }
87
- return (_jsx(Dialog, { title: title, onClose: onClose, footerButtons: [
87
+ return (_jsx(Dialog, { title: _jsx("span", { style: { color: 'var(--fgColor-default)' }, children: title }), onClose: onClose, footerButtons: [
88
88
  {
89
89
  buttonType: 'default',
90
90
  content: trans.__('Cancel'),
@@ -1,5 +1,5 @@
1
1
  import type { IMarkdownParser, IRenderMime } from '@jupyterlab/rendermime';
2
- import type { IRemoteServicesManager } from '../../api';
2
+ import type { IRemoteServicesManager } from '../../sdk/stateful/runtimes';
3
3
  import type { IRuntimeSnapshot, IRuntimeDesc } from '../../models';
4
4
  /**
5
5
  * {@link RuntimeLauncherDialog} properties.
@@ -46,7 +46,8 @@ export function RuntimeLauncherDialog(props) {
46
46
  // TODO when would this component be shown outside of a react-router? navigation is only available within a react-router.
47
47
  console.warn(reason);
48
48
  }
49
- const { jupyterLabAdapter } = useJupyterReactStore();
49
+ const jupyterReactStore = useJupyterReactStore();
50
+ const jupyterLabAdapter = jupyterReactStore.jupyterLabAdapter;
50
51
  const [selection, setSelection] = useState((kernelSnapshot?.environment || environments[0]?.name) ?? '');
51
52
  const [timeLimit, setTimeLimit] = useState(Math.min(credits?.available ?? 0, 10));
52
53
  const [runtimeName, setRuntimeName] = useState(environments[0]?.kernel?.givenNameTemplate || environments[0]?.title || '');
@@ -211,7 +212,9 @@ export function RuntimeLauncherDialog(props) {
211
212
  setHasCustomRuntimeName(true);
212
213
  }
213
214
  }, []);
214
- return (_jsx(Dialog, { title: dialogTitle || 'Launch a new Runtime', onClose: () => {
215
+ // TODO title color is enforced for JupyterLab.
216
+ // This may be fixed in the jupyter-react theme (Primer generates h1 for the dialog title).
217
+ return (_jsx(Dialog, { title: _jsx("span", { style: { color: 'var(--fgColor-default)' }, children: dialogTitle || 'Launch a new Runtime' }), onClose: () => {
215
218
  onSubmit(undefined);
216
219
  }, footerButtons: [
217
220
  {
@@ -2,7 +2,7 @@ import { ReactElement, ReactNode } from 'react';
2
2
  import { ISessionContext } from '@jupyterlab/apputils';
3
3
  import { ITranslator } from '@jupyterlab/translation';
4
4
  import { IRuntimeDesc } from '../../models';
5
- import { IMultiServiceManager } from '../../api';
5
+ import { IMultiServiceManager } from '../../sdk/stateful/runtimes';
6
6
  type IDisplayMode = 'menu' | 'radio';
7
7
  /**
8
8
  * {@link RuntimePickerBase} properties
@@ -12,7 +12,7 @@ import { Box } from '@datalayer/primer-addons';
12
12
  import { CpuIcon } from '@primer/octicons-react';
13
13
  import { BrowserIcon, LaptopSimpleIcon } from '@datalayer/icons-react';
14
14
  import { CreditsIndicator } from '../../components/progress';
15
- import { isRuntimeRemote } from '../../api';
15
+ import { isRuntimeRemote, } from '../../sdk/stateful/runtimes';
16
16
  import { getGroupedRuntimeDescs } from './RuntimeUtils';
17
17
  /**
18
18
  * Maximal runtime display name length after which it is trimmed.
@@ -8,7 +8,8 @@ import { nullTranslator } from '@jupyterlab/translation';
8
8
  import { ActionList } from '@primer/react';
9
9
  import { CloudUploadIcon } from '@datalayer/icons-react';
10
10
  import { useCoreStore, useIAMStore } from '../../state';
11
- import { isRuntimeRemote, RuntimeSnippetsFacade } from '../../api';
11
+ import { isRuntimeRemote } from '../../sdk/stateful/runtimes';
12
+ import { RuntimeSnippetsFacade } from '../../sdk/stateful/jupyter';
12
13
  import { ExternalTokenSilentLogin } from '../../components/iam';
13
14
  import { SnippetDialog } from './../snippets/SnippetDialog';
14
15
  import { RuntimeLauncherDialog } from './RuntimeLauncherDialog';
@@ -1,6 +1,6 @@
1
1
  import { ITranslator } from '@jupyterlab/translation';
2
2
  import { CommandRegistry } from '@lumino/commands';
3
- import type { IMultiServiceManager, IDatalayerSessionContext } from '../../api';
3
+ import type { IMultiServiceManager, IDatalayerSessionContext } from '../../sdk/stateful/runtimes';
4
4
  import { RuntimeTransfer } from './RuntimeTransfer';
5
5
  /**
6
6
  * {@link RuntimePickerNotebook} properties