@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,192 @@
1
+ /**
2
+ * @module sdk/client
3
+ * @description Main Datalayer SDK client with intuitive mixin-based API.
4
+ *
5
+ * The DatalayerSDK class provides a unified, flat API for all Datalayer platform
6
+ * services through TypeScript mixins. This design offers the best discoverability
7
+ * and ease of use compared to nested service objects.
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * import { DatalayerSDK } from '@datalayer/core/sdk';
12
+ *
13
+ * // Initialize SDK
14
+ * const sdk = new DatalayerSDK({
15
+ * token: 'your-api-token',
16
+ * baseUrl: 'https://prod1.datalayer.run'
17
+ * });
18
+ *
19
+ * // Flat, intuitive API
20
+ * const user = await sdk.whoami();
21
+ * const environments = await sdk.listEnvironments();
22
+ * const notebook = await sdk.createNotebook(data);
23
+ * const runtime = await sdk.createRuntime(config);
24
+ * await sdk.startRuntime(podName);
25
+ * ```
26
+ */
27
+ import { DatalayerSDKBase, type DatalayerSDKConfig } from './base';
28
+ declare const DatalayerSDKWithMixins: {
29
+ new (...args: any[]): {
30
+ getMySpaces(): Promise<import("./models").Space[]>;
31
+ createSpace(data: import("../..").CreateSpaceRequest): Promise<import("./models").Space>;
32
+ _extractNotebookId(notebookIdOrInstance: string | import("./models").Notebook): string;
33
+ _extractLexicalId(lexicalIdOrInstance: string | import("./models").Lexical): string;
34
+ createNotebook(data: import("../..").CreateNotebookRequest): Promise<import("./models").Notebook>;
35
+ getNotebook(idOrNotebook: string | import("./models").Notebook): Promise<import("./models").Notebook>;
36
+ updateNotebook(idOrNotebook: string | import("./models").Notebook, data: import("../..").UpdateNotebookRequest): Promise<import("./models").Notebook>;
37
+ createLexical(data: import("../..").CreateLexicalRequest): Promise<import("./models").Lexical>;
38
+ getLexical(idOrLexical: string | import("./models").Lexical): Promise<import("./models").Lexical>;
39
+ updateLexical(idOrLexical: string | import("./models").Lexical, data: import("../..").UpdateLexicalRequest): Promise<import("./models").Lexical>;
40
+ getSpaceItems(spaceId: string): Promise<import("../..").GetSpaceItemsResponse>;
41
+ deleteSpaceItem(itemId: string): Promise<import("../..").DeleteSpaceItemResponse>;
42
+ };
43
+ } & {
44
+ new (...args: any[]): {
45
+ _extractRuntimePodName(runtimePodNameOrInstance: string | import("./models").Runtime): string;
46
+ _extractSnapshotId(snapshotIdOrInstance: string | import("./models").Snapshot): string;
47
+ listEnvironments(): Promise<import("../..").Environment[]>;
48
+ createRuntime(data: import("../..").CreateRuntimeRequest): Promise<import("./models").Runtime>;
49
+ listRuntimes(): Promise<import("./models").Runtime[]>;
50
+ getRuntime(podNameOrRuntime: string | import("./models").Runtime): Promise<import("./models").Runtime>;
51
+ deleteRuntime(podNameOrRuntime: string | import("./models").Runtime): Promise<void>;
52
+ createSnapshot(data: import("../..").CreateRuntimeSnapshotRequest): Promise<import("./models").Snapshot>;
53
+ listSnapshots(): Promise<import("./models").Snapshot[]>;
54
+ getSnapshot(idOrSnapshot: string | import("./models").Snapshot): Promise<import("./models").Snapshot>;
55
+ deleteSnapshot(idOrSnapshot: string | import("./models").Snapshot): Promise<void>;
56
+ };
57
+ } & {
58
+ new (...args: any[]): {
59
+ whoami(): Promise<import("../..").User>;
60
+ login(data: import("../..").LoginRequest): Promise<import("../..").LoginResponse>;
61
+ logout(): Promise<void>;
62
+ };
63
+ } & {
64
+ new (...args: any[]): {
65
+ isIAMHealthy(): Promise<boolean>;
66
+ isRuntimesHealthy(): Promise<boolean>;
67
+ isSpacerHealthy(): Promise<boolean>;
68
+ areAllServicesHealthy(): Promise<boolean>;
69
+ getHealthStatus(): Promise<{
70
+ iam: {
71
+ healthy: boolean;
72
+ details?: any;
73
+ error?: string;
74
+ version?: string;
75
+ };
76
+ runtimes: {
77
+ healthy: boolean;
78
+ details?: any;
79
+ error?: string;
80
+ version?: string;
81
+ };
82
+ spacer: {
83
+ healthy: boolean;
84
+ details?: any;
85
+ error?: string;
86
+ version?: string;
87
+ };
88
+ allHealthy: boolean;
89
+ }>;
90
+ readonly iamRunUrl: string;
91
+ readonly runtimesRunUrl: string;
92
+ readonly spacerRunUrl: string;
93
+ token?: string;
94
+ updateToken(token: string): void;
95
+ getConfig(): DatalayerSDKConfig;
96
+ updateConfig(config: Partial<DatalayerSDKConfig>): void;
97
+ getIamRunUrl(): string;
98
+ getRuntimesRunUrl(): string;
99
+ getSpacerRunUrl(): string;
100
+ getToken(): string | undefined;
101
+ };
102
+ } & typeof DatalayerSDKBase;
103
+ /**
104
+ * Main Datalayer SDK client providing unified access to all platform services.
105
+ *
106
+ * This class uses TypeScript mixins to provide a flat, discoverable API where
107
+ * all methods are directly accessible on the SDK instance. This design offers
108
+ * superior developer experience compared to nested service objects.
109
+ *
110
+ * **Key Features:**
111
+ * - **Flat API**: All methods directly on `sdk.` (e.g., `sdk.createNotebook()`)
112
+ * - **Intuitive naming**: Descriptive method names (e.g., `whoami()` vs `iam.users.me()`)
113
+ * - **Perfect discoverability**: IDE shows all available methods immediately
114
+ * - **Type safety**: Full TypeScript support with comprehensive interfaces
115
+ *
116
+ * **Authentication Methods:**
117
+ * - `whoami()` - Get current user profile
118
+ * - `login(credentials)` - Authenticate with credentials
119
+ * - `logout()` - Log out current user
120
+ *
121
+ * **Environment Methods:**
122
+ * - `listEnvironments()` - List available compute environments
123
+ *
124
+ * **Runtime Methods:**
125
+ * - `createRuntime(config)` - Create new computational runtime
126
+ * - `listRuntimes()` - List all runtimes
127
+ * - `getRuntime(podName)` - Get runtime details
128
+ * - `deleteRuntime(podName)` - Delete runtime
129
+ *
130
+ * **Workspace Methods:**
131
+ * - `createSpace(data)` - Create new workspace
132
+ * - `listSpaces()` - List all workspaces
133
+ * - `getSpace(spaceId)` - Get workspace details
134
+ * - `deleteSpace(spaceId)` - Delete workspace
135
+ *
136
+ * **Notebook Methods:**
137
+ * - `createNotebook(data)` - Create new notebook
138
+ * - `listNotebooks(spaceId?)` - List notebooks
139
+ * - `getNotebook(notebookId)` - Get notebook details
140
+ * - `getNotebookByUid(uid)` - Get notebook by UID
141
+ * - `updateNotebook(notebookId, data)` - Update notebook
142
+ * - `cloneNotebook(data)` - Clone existing notebook
143
+ * - `getNotebookContent(notebookId)` - Get notebook content
144
+ * - `updateNotebookContent(notebookId, content)` - Update notebook content
145
+ * - `deleteNotebook(notebookId)` - Delete notebook
146
+ *
147
+ * **Cell Methods:**
148
+ * - `createCell(notebookId, cell)` - Create new cell
149
+ * - `getCell(notebookId, cellId)` - Get cell details
150
+ * - `deleteCell(notebookId, cellId)` - Delete cell
151
+ *
152
+ * @example
153
+ * ```typescript
154
+ * // Initialize SDK
155
+ * const sdk = new DatalayerSDK({
156
+ * token: 'your-token',
157
+ * baseUrl: 'https://prod1.datalayer.run'
158
+ * });
159
+ *
160
+ * // Authentication
161
+ * const user = await sdk.whoami();
162
+ * console.log('Logged in as:', user.email);
163
+ *
164
+ * // Create workspace and notebook
165
+ * const space = await sdk.createSpace({
166
+ * name: 'My Project'
167
+ * });
168
+ *
169
+ * const notebook = await sdk.createNotebook({
170
+ * space_id: space.id,
171
+ * name: 'Analysis'
172
+ * });
173
+ *
174
+ * // Create and start runtime
175
+ * const runtime = await sdk.createRuntime({
176
+ * environment_name: 'python-cpu-env',
177
+ * credits_limit: 100
178
+ * });
179
+ *
180
+ * console.log('Setup complete!');
181
+ * ```
182
+ */
183
+ export declare class DatalayerSDK extends DatalayerSDKWithMixins {
184
+ /**
185
+ * Create a DatalayerSDK instance.
186
+ *
187
+ * @param config - SDK configuration options
188
+ */
189
+ constructor(config: DatalayerSDKConfig);
190
+ }
191
+ export type { DatalayerSDKConfig };
192
+ export { DatalayerSDKBase };
@@ -0,0 +1,128 @@
1
+ /*
2
+ * Copyright (c) 2023-2025 Datalayer, Inc.
3
+ * Distributed under the terms of the Modified BSD License.
4
+ */
5
+ /**
6
+ * @module sdk/client
7
+ * @description Main Datalayer SDK client with intuitive mixin-based API.
8
+ *
9
+ * The DatalayerSDK class provides a unified, flat API for all Datalayer platform
10
+ * services through TypeScript mixins. This design offers the best discoverability
11
+ * and ease of use compared to nested service objects.
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * import { DatalayerSDK } from '@datalayer/core/sdk';
16
+ *
17
+ * // Initialize SDK
18
+ * const sdk = new DatalayerSDK({
19
+ * token: 'your-api-token',
20
+ * baseUrl: 'https://prod1.datalayer.run'
21
+ * });
22
+ *
23
+ * // Flat, intuitive API
24
+ * const user = await sdk.whoami();
25
+ * const environments = await sdk.listEnvironments();
26
+ * const notebook = await sdk.createNotebook(data);
27
+ * const runtime = await sdk.createRuntime(config);
28
+ * await sdk.startRuntime(podName);
29
+ * ```
30
+ */
31
+ import { DatalayerSDKBase } from './base';
32
+ import { HealthMixin } from './mixins/HealthMixin';
33
+ import { IAMMixin } from './mixins/IAMMixin';
34
+ import { RuntimesMixin } from './mixins/RuntimesMixin';
35
+ import { SpacerMixin } from './mixins/SpacerMixin';
36
+ // Apply mixins to the base class
37
+ const DatalayerSDKWithMixins = SpacerMixin(RuntimesMixin(IAMMixin(HealthMixin(DatalayerSDKBase))));
38
+ /**
39
+ * Main Datalayer SDK client providing unified access to all platform services.
40
+ *
41
+ * This class uses TypeScript mixins to provide a flat, discoverable API where
42
+ * all methods are directly accessible on the SDK instance. This design offers
43
+ * superior developer experience compared to nested service objects.
44
+ *
45
+ * **Key Features:**
46
+ * - **Flat API**: All methods directly on `sdk.` (e.g., `sdk.createNotebook()`)
47
+ * - **Intuitive naming**: Descriptive method names (e.g., `whoami()` vs `iam.users.me()`)
48
+ * - **Perfect discoverability**: IDE shows all available methods immediately
49
+ * - **Type safety**: Full TypeScript support with comprehensive interfaces
50
+ *
51
+ * **Authentication Methods:**
52
+ * - `whoami()` - Get current user profile
53
+ * - `login(credentials)` - Authenticate with credentials
54
+ * - `logout()` - Log out current user
55
+ *
56
+ * **Environment Methods:**
57
+ * - `listEnvironments()` - List available compute environments
58
+ *
59
+ * **Runtime Methods:**
60
+ * - `createRuntime(config)` - Create new computational runtime
61
+ * - `listRuntimes()` - List all runtimes
62
+ * - `getRuntime(podName)` - Get runtime details
63
+ * - `deleteRuntime(podName)` - Delete runtime
64
+ *
65
+ * **Workspace Methods:**
66
+ * - `createSpace(data)` - Create new workspace
67
+ * - `listSpaces()` - List all workspaces
68
+ * - `getSpace(spaceId)` - Get workspace details
69
+ * - `deleteSpace(spaceId)` - Delete workspace
70
+ *
71
+ * **Notebook Methods:**
72
+ * - `createNotebook(data)` - Create new notebook
73
+ * - `listNotebooks(spaceId?)` - List notebooks
74
+ * - `getNotebook(notebookId)` - Get notebook details
75
+ * - `getNotebookByUid(uid)` - Get notebook by UID
76
+ * - `updateNotebook(notebookId, data)` - Update notebook
77
+ * - `cloneNotebook(data)` - Clone existing notebook
78
+ * - `getNotebookContent(notebookId)` - Get notebook content
79
+ * - `updateNotebookContent(notebookId, content)` - Update notebook content
80
+ * - `deleteNotebook(notebookId)` - Delete notebook
81
+ *
82
+ * **Cell Methods:**
83
+ * - `createCell(notebookId, cell)` - Create new cell
84
+ * - `getCell(notebookId, cellId)` - Get cell details
85
+ * - `deleteCell(notebookId, cellId)` - Delete cell
86
+ *
87
+ * @example
88
+ * ```typescript
89
+ * // Initialize SDK
90
+ * const sdk = new DatalayerSDK({
91
+ * token: 'your-token',
92
+ * baseUrl: 'https://prod1.datalayer.run'
93
+ * });
94
+ *
95
+ * // Authentication
96
+ * const user = await sdk.whoami();
97
+ * console.log('Logged in as:', user.email);
98
+ *
99
+ * // Create workspace and notebook
100
+ * const space = await sdk.createSpace({
101
+ * name: 'My Project'
102
+ * });
103
+ *
104
+ * const notebook = await sdk.createNotebook({
105
+ * space_id: space.id,
106
+ * name: 'Analysis'
107
+ * });
108
+ *
109
+ * // Create and start runtime
110
+ * const runtime = await sdk.createRuntime({
111
+ * environment_name: 'python-cpu-env',
112
+ * credits_limit: 100
113
+ * });
114
+ *
115
+ * console.log('Setup complete!');
116
+ * ```
117
+ */
118
+ export class DatalayerSDK extends DatalayerSDKWithMixins {
119
+ /**
120
+ * Create a DatalayerSDK instance.
121
+ *
122
+ * @param config - SDK configuration options
123
+ */
124
+ constructor(config) {
125
+ super(config);
126
+ }
127
+ }
128
+ export { DatalayerSDKBase };
@@ -0,0 +1,100 @@
1
+ import type { DatalayerSDKBase } from '../base';
2
+ /**
3
+ * Interface for health check methods.
4
+ */
5
+ export interface HealthMixinInterface {
6
+ /** Check if IAM service is healthy */
7
+ isIAMHealthy(): Promise<boolean>;
8
+ /** Check if Runtimes service is healthy */
9
+ isRuntimesHealthy(): Promise<boolean>;
10
+ /** Check if Spacer service is healthy */
11
+ isSpacerHealthy(): Promise<boolean>;
12
+ /** Check if all services are healthy */
13
+ areAllServicesHealthy(): Promise<boolean>;
14
+ /** Get detailed health status for all services */
15
+ getHealthStatus(): Promise<{
16
+ iam: {
17
+ healthy: boolean;
18
+ details?: any;
19
+ error?: string;
20
+ };
21
+ runtimes: {
22
+ healthy: boolean;
23
+ details?: any;
24
+ error?: string;
25
+ };
26
+ spacer: {
27
+ healthy: boolean;
28
+ details?: any;
29
+ error?: string;
30
+ };
31
+ }>;
32
+ }
33
+ /**
34
+ * Mixin that provides health check functionality for the SDK.
35
+ */
36
+ export declare function HealthMixin<T extends new (...args: any[]) => DatalayerSDKBase>(Base: T): {
37
+ new (...args: any[]): {
38
+ /**
39
+ * Check if the IAM service is healthy.
40
+ *
41
+ * @returns True if service is healthy, false otherwise
42
+ */
43
+ isIAMHealthy(): Promise<boolean>;
44
+ /**
45
+ * Check if the Runtimes service is healthy.
46
+ *
47
+ * @returns True if service is healthy, false otherwise
48
+ */
49
+ isRuntimesHealthy(): Promise<boolean>;
50
+ /**
51
+ * Check if the Spacer service is healthy.
52
+ *
53
+ * @returns True if service is healthy, false otherwise
54
+ */
55
+ isSpacerHealthy(): Promise<boolean>;
56
+ /**
57
+ * Check if all Datalayer services are healthy.
58
+ *
59
+ * @returns True if all services are healthy, false otherwise
60
+ */
61
+ areAllServicesHealthy(): Promise<boolean>;
62
+ /**
63
+ * Get detailed health status for all services.
64
+ *
65
+ * @returns Object containing health status and details for each service
66
+ */
67
+ getHealthStatus(): Promise<{
68
+ iam: {
69
+ healthy: boolean;
70
+ details?: any;
71
+ error?: string;
72
+ version?: string;
73
+ };
74
+ runtimes: {
75
+ healthy: boolean;
76
+ details?: any;
77
+ error?: string;
78
+ version?: string;
79
+ };
80
+ spacer: {
81
+ healthy: boolean;
82
+ details?: any;
83
+ error?: string;
84
+ version?: string;
85
+ };
86
+ allHealthy: boolean;
87
+ }>;
88
+ readonly iamRunUrl: string;
89
+ readonly runtimesRunUrl: string;
90
+ readonly spacerRunUrl: string;
91
+ token?: string;
92
+ updateToken(token: string): void;
93
+ getConfig(): import("..").DatalayerSDKConfig;
94
+ updateConfig(config: Partial<import("..").DatalayerSDKConfig>): void;
95
+ getIamRunUrl(): string;
96
+ getRuntimesRunUrl(): string;
97
+ getSpacerRunUrl(): string;
98
+ getToken(): string | undefined;
99
+ };
100
+ } & T;
@@ -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 sdk/client/mixins/HealthMixin
7
+ * @description Health check functionality for the Datalayer SDK.
8
+ *
9
+ * Provides methods to check the health status of all Datalayer services.
10
+ */
11
+ import { iam, runtimes, spacer } from '../../../api';
12
+ /**
13
+ * Mixin that provides health check functionality for the SDK.
14
+ */
15
+ export function HealthMixin(Base) {
16
+ return class extends Base {
17
+ /**
18
+ * Check if the IAM service is healthy.
19
+ *
20
+ * @returns True if service is healthy, false otherwise
21
+ */
22
+ async isIAMHealthy() {
23
+ try {
24
+ await iam.healthz.ping(this.iamRunUrl);
25
+ return true;
26
+ }
27
+ catch {
28
+ return false;
29
+ }
30
+ }
31
+ /**
32
+ * Check if the Runtimes service is healthy.
33
+ *
34
+ * @returns True if service is healthy, false otherwise
35
+ */
36
+ async isRuntimesHealthy() {
37
+ try {
38
+ await runtimes.healthz.ping(this.runtimesRunUrl);
39
+ return true;
40
+ }
41
+ catch {
42
+ return false;
43
+ }
44
+ }
45
+ /**
46
+ * Check if the Spacer service is healthy.
47
+ *
48
+ * @returns True if service is healthy, false otherwise
49
+ */
50
+ async isSpacerHealthy() {
51
+ try {
52
+ await spacer.healthz.ping(this.spacerRunUrl);
53
+ return true;
54
+ }
55
+ catch {
56
+ return false;
57
+ }
58
+ }
59
+ /**
60
+ * Check if all Datalayer services are healthy.
61
+ *
62
+ * @returns True if all services are healthy, false otherwise
63
+ */
64
+ async areAllServicesHealthy() {
65
+ const [iamHealthy, runtimesHealthy, spacerHealthy] = await Promise.all([
66
+ this.isIAMHealthy(),
67
+ this.isRuntimesHealthy(),
68
+ this.isSpacerHealthy(),
69
+ ]);
70
+ return iamHealthy && runtimesHealthy && spacerHealthy;
71
+ }
72
+ /**
73
+ * Get detailed health status for all services.
74
+ *
75
+ * @returns Object containing health status and details for each service
76
+ */
77
+ async getHealthStatus() {
78
+ const [iamStatus, runtimesStatus, spacerStatus] = await Promise.allSettled([
79
+ iam.healthz.ping(this.iamRunUrl),
80
+ runtimes.healthz.ping(this.runtimesRunUrl),
81
+ spacer.healthz.ping(this.spacerRunUrl),
82
+ ]);
83
+ const result = {
84
+ iam: {
85
+ healthy: false,
86
+ details: undefined,
87
+ error: undefined,
88
+ },
89
+ runtimes: {
90
+ healthy: false,
91
+ details: undefined,
92
+ error: undefined,
93
+ },
94
+ spacer: {
95
+ healthy: false,
96
+ details: undefined,
97
+ error: undefined,
98
+ },
99
+ };
100
+ // Process IAM status
101
+ if (iamStatus.status === 'fulfilled') {
102
+ result.iam.healthy = true;
103
+ result.iam.details = iamStatus.value;
104
+ }
105
+ else {
106
+ result.iam.error = iamStatus.reason?.message || 'Unknown error';
107
+ }
108
+ // Process Runtimes status
109
+ if (runtimesStatus.status === 'fulfilled') {
110
+ result.runtimes.healthy = true;
111
+ result.runtimes.details = runtimesStatus.value;
112
+ }
113
+ else {
114
+ result.runtimes.error =
115
+ runtimesStatus.reason?.message || 'Unknown error';
116
+ }
117
+ // Process Spacer status
118
+ if (spacerStatus.status === 'fulfilled') {
119
+ result.spacer.healthy = true;
120
+ result.spacer.details = spacerStatus.value;
121
+ }
122
+ else {
123
+ result.spacer.error = spacerStatus.reason?.message || 'Unknown error';
124
+ }
125
+ return {
126
+ ...result,
127
+ allHealthy: result.iam.healthy &&
128
+ result.runtimes.healthy &&
129
+ result.spacer.healthy,
130
+ };
131
+ }
132
+ };
133
+ }
@@ -0,0 +1,59 @@
1
+ import type { User, LoginRequest, LoginResponse } from '../../../api/types/iam';
2
+ import type { Constructor } from '../utils/mixins';
3
+ /**
4
+ * IAM mixin that provides authentication and user management functionality.
5
+ *
6
+ */
7
+ export declare function IAMMixin<TBase extends Constructor>(Base: TBase): {
8
+ new (...args: any[]): {
9
+ /**
10
+ * Get the current user's profile information.
11
+ *
12
+ * @returns Promise resolving to the current user's profile
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * const user = await sdk.whoami();
17
+ * console.log('Current user:', user.username);
18
+ * ```
19
+ */
20
+ whoami(): Promise<User>;
21
+ /**
22
+ * Authenticate a user with credentials or token.
23
+ *
24
+ * @param data - Login credentials (either handle+password or token)
25
+ * @returns Promise resolving to login response with tokens
26
+ *
27
+ * @example
28
+ * ```typescript
29
+ * // Login with handle and password
30
+ * const loginResponse = await sdk.login({
31
+ * handle: 'user@example.com',
32
+ * password: 'secure-password'
33
+ * });
34
+ *
35
+ * // Or login with token
36
+ * const tokenResponse = await sdk.login({
37
+ * token: 'existing-auth-token'
38
+ * });
39
+ *
40
+ * // Update SDK with new token
41
+ * sdk.updateToken(loginResponse.token);
42
+ * ```
43
+ */
44
+ login(data: LoginRequest): Promise<LoginResponse>;
45
+ /**
46
+ * Log out the current user.
47
+ *
48
+ * This method performs a logout operation on the server and clears
49
+ * the authentication token from the SDK.
50
+ *
51
+ * @example
52
+ * ```typescript
53
+ * await sdk.logout();
54
+ * console.log('User logged out successfully');
55
+ * ```
56
+ */
57
+ logout(): Promise<void>;
58
+ };
59
+ } & TBase;
@@ -0,0 +1,83 @@
1
+ /*
2
+ * Copyright (c) 2023-2025 Datalayer, Inc.
3
+ * Distributed under the terms of the Modified BSD License.
4
+ */
5
+ /**
6
+ * @module sdk/client/mixins/IAMMixin
7
+ * @description IAM (Identity and Access Management) mixin for the Datalayer SDK.
8
+ *
9
+ * This mixin provides intuitive authentication and user management methods
10
+ * that are mixed into the main DatalayerSDK class.
11
+ */
12
+ import { authentication, profile } from '../../../api/iam';
13
+ /**
14
+ * IAM mixin that provides authentication and user management functionality.
15
+ *
16
+ */
17
+ export function IAMMixin(Base) {
18
+ return class extends Base {
19
+ /**
20
+ * Get the current user's profile information.
21
+ *
22
+ * @returns Promise resolving to the current user's profile
23
+ *
24
+ * @example
25
+ * ```typescript
26
+ * const user = await sdk.whoami();
27
+ * console.log('Current user:', user.username);
28
+ * ```
29
+ */
30
+ async whoami() {
31
+ const token = this.getToken();
32
+ const iamRunUrl = this.getIamRunUrl();
33
+ const response = await profile.me(token, iamRunUrl);
34
+ return response.me;
35
+ }
36
+ /**
37
+ * Authenticate a user with credentials or token.
38
+ *
39
+ * @param data - Login credentials (either handle+password or token)
40
+ * @returns Promise resolving to login response with tokens
41
+ *
42
+ * @example
43
+ * ```typescript
44
+ * // Login with handle and password
45
+ * const loginResponse = await sdk.login({
46
+ * handle: 'user@example.com',
47
+ * password: 'secure-password'
48
+ * });
49
+ *
50
+ * // Or login with token
51
+ * const tokenResponse = await sdk.login({
52
+ * token: 'existing-auth-token'
53
+ * });
54
+ *
55
+ * // Update SDK with new token
56
+ * sdk.updateToken(loginResponse.token);
57
+ * ```
58
+ */
59
+ async login(data) {
60
+ const iamRunUrl = this.getIamRunUrl();
61
+ return await authentication.login(data, iamRunUrl);
62
+ }
63
+ /**
64
+ * Log out the current user.
65
+ *
66
+ * This method performs a logout operation on the server and clears
67
+ * the authentication token from the SDK.
68
+ *
69
+ * @example
70
+ * ```typescript
71
+ * await sdk.logout();
72
+ * console.log('User logged out successfully');
73
+ * ```
74
+ */
75
+ async logout() {
76
+ const token = this.getToken();
77
+ const iamRunUrl = this.getIamRunUrl();
78
+ await authentication.logout(token, iamRunUrl);
79
+ // Clear the token from the SDK
80
+ this.updateToken('');
81
+ }
82
+ };
83
+ }