oblien 1.3.0 → 2.0.1

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 (187) hide show
  1. package/README.md +482 -422
  2. package/dist/client.d.ts +31 -0
  3. package/dist/client.d.ts.map +1 -0
  4. package/dist/client.js +33 -0
  5. package/dist/client.js.map +1 -0
  6. package/dist/error.d.ts +29 -0
  7. package/dist/error.d.ts.map +1 -0
  8. package/dist/error.js +52 -0
  9. package/dist/error.js.map +1 -0
  10. package/dist/http.d.ts +20 -0
  11. package/dist/http.d.ts.map +1 -0
  12. package/dist/http.js +108 -0
  13. package/dist/http.js.map +1 -0
  14. package/dist/index.d.ts +8 -0
  15. package/dist/index.d.ts.map +1 -0
  16. package/dist/index.js +10 -0
  17. package/dist/index.js.map +1 -0
  18. package/dist/resources/api-access.d.ts +21 -0
  19. package/dist/resources/api-access.d.ts.map +1 -0
  20. package/dist/resources/api-access.js +32 -0
  21. package/dist/resources/api-access.js.map +1 -0
  22. package/dist/resources/base.d.ts +17 -0
  23. package/dist/resources/base.d.ts.map +1 -0
  24. package/dist/resources/base.js +21 -0
  25. package/dist/resources/base.js.map +1 -0
  26. package/dist/resources/images.d.ts +11 -0
  27. package/dist/resources/images.d.ts.map +1 -0
  28. package/dist/resources/images.js +16 -0
  29. package/dist/resources/images.js.map +1 -0
  30. package/dist/resources/lifecycle.d.ts +23 -0
  31. package/dist/resources/lifecycle.d.ts.map +1 -0
  32. package/dist/resources/lifecycle.js +32 -0
  33. package/dist/resources/lifecycle.js.map +1 -0
  34. package/dist/resources/logs.d.ts +25 -0
  35. package/dist/resources/logs.d.ts.map +1 -0
  36. package/dist/resources/logs.js +51 -0
  37. package/dist/resources/logs.js.map +1 -0
  38. package/dist/resources/metadata.d.ts +15 -0
  39. package/dist/resources/metadata.d.ts.map +1 -0
  40. package/dist/resources/metadata.js +20 -0
  41. package/dist/resources/metadata.js.map +1 -0
  42. package/dist/resources/metrics.d.ts +17 -0
  43. package/dist/resources/metrics.d.ts.map +1 -0
  44. package/dist/resources/metrics.js +27 -0
  45. package/dist/resources/metrics.js.map +1 -0
  46. package/dist/resources/network.d.ts +17 -0
  47. package/dist/resources/network.d.ts.map +1 -0
  48. package/dist/resources/network.js +20 -0
  49. package/dist/resources/network.js.map +1 -0
  50. package/dist/resources/public-access.d.ts +15 -0
  51. package/dist/resources/public-access.d.ts.map +1 -0
  52. package/dist/resources/public-access.js +21 -0
  53. package/dist/resources/public-access.js.map +1 -0
  54. package/dist/resources/resources.d.ts +15 -0
  55. package/dist/resources/resources.d.ts.map +1 -0
  56. package/dist/resources/resources.js +20 -0
  57. package/dist/resources/resources.js.map +1 -0
  58. package/dist/resources/snapshots.d.ts +27 -0
  59. package/dist/resources/snapshots.d.ts.map +1 -0
  60. package/dist/resources/snapshots.js +45 -0
  61. package/dist/resources/snapshots.js.map +1 -0
  62. package/dist/resources/ssh.d.ts +19 -0
  63. package/dist/resources/ssh.d.ts.map +1 -0
  64. package/dist/resources/ssh.js +28 -0
  65. package/dist/resources/ssh.js.map +1 -0
  66. package/dist/resources/usage.d.ts +25 -0
  67. package/dist/resources/usage.d.ts.map +1 -0
  68. package/dist/resources/usage.js +44 -0
  69. package/dist/resources/usage.js.map +1 -0
  70. package/dist/resources/workloads.d.ts +39 -0
  71. package/dist/resources/workloads.d.ts.map +1 -0
  72. package/dist/resources/workloads.js +83 -0
  73. package/dist/resources/workloads.js.map +1 -0
  74. package/dist/runtime/exec.d.ts +71 -0
  75. package/dist/runtime/exec.d.ts.map +1 -0
  76. package/dist/runtime/exec.js +163 -0
  77. package/dist/runtime/exec.js.map +1 -0
  78. package/dist/runtime/files.d.ts +39 -0
  79. package/dist/runtime/files.d.ts.map +1 -0
  80. package/dist/runtime/files.js +143 -0
  81. package/dist/runtime/files.js.map +1 -0
  82. package/dist/runtime/search.d.ts +23 -0
  83. package/dist/runtime/search.d.ts.map +1 -0
  84. package/dist/runtime/search.js +65 -0
  85. package/dist/runtime/search.js.map +1 -0
  86. package/dist/runtime/terminal.d.ts +29 -0
  87. package/dist/runtime/terminal.d.ts.map +1 -0
  88. package/dist/runtime/terminal.js +58 -0
  89. package/dist/runtime/terminal.js.map +1 -0
  90. package/dist/runtime/watcher.d.ts +27 -0
  91. package/dist/runtime/watcher.d.ts.map +1 -0
  92. package/dist/runtime/watcher.js +53 -0
  93. package/dist/runtime/watcher.js.map +1 -0
  94. package/dist/runtime/ws.d.ts +92 -0
  95. package/dist/runtime/ws.d.ts.map +1 -0
  96. package/dist/runtime/ws.js +228 -0
  97. package/dist/runtime/ws.js.map +1 -0
  98. package/dist/runtime-http.d.ts +35 -0
  99. package/dist/runtime-http.d.ts.map +1 -0
  100. package/dist/runtime-http.js +99 -0
  101. package/dist/runtime-http.js.map +1 -0
  102. package/dist/runtime.d.ts +77 -0
  103. package/dist/runtime.d.ts.map +1 -0
  104. package/dist/runtime.js +97 -0
  105. package/dist/runtime.js.map +1 -0
  106. package/dist/types/client.d.ts +7 -0
  107. package/dist/types/client.d.ts.map +1 -0
  108. package/dist/types/client.js +3 -0
  109. package/dist/types/client.js.map +1 -0
  110. package/dist/types/common.d.ts +13 -0
  111. package/dist/types/common.d.ts.map +1 -0
  112. package/dist/types/common.js +3 -0
  113. package/dist/types/common.js.map +1 -0
  114. package/dist/types/index.d.ts +8 -0
  115. package/dist/types/index.d.ts.map +1 -0
  116. package/dist/types/index.js +2 -0
  117. package/dist/types/index.js.map +1 -0
  118. package/dist/types/network.d.ts +15 -0
  119. package/dist/types/network.d.ts.map +1 -0
  120. package/dist/types/network.js +3 -0
  121. package/dist/types/network.js.map +1 -0
  122. package/dist/types/resources.d.ts +10 -0
  123. package/dist/types/resources.d.ts.map +1 -0
  124. package/dist/types/resources.js +3 -0
  125. package/dist/types/resources.js.map +1 -0
  126. package/dist/types/runtime.d.ts +302 -0
  127. package/dist/types/runtime.d.ts.map +1 -0
  128. package/dist/types/runtime.js +3 -0
  129. package/dist/types/runtime.js.map +1 -0
  130. package/dist/types/workspace-resources.d.ts +186 -0
  131. package/dist/types/workspace-resources.d.ts.map +1 -0
  132. package/dist/types/workspace-resources.js +3 -0
  133. package/dist/types/workspace-resources.js.map +1 -0
  134. package/dist/types/workspace.d.ts +41 -0
  135. package/dist/types/workspace.d.ts.map +1 -0
  136. package/dist/types/workspace.js +3 -0
  137. package/dist/types/workspace.js.map +1 -0
  138. package/dist/workspace.d.ts +135 -0
  139. package/dist/workspace.d.ts.map +1 -0
  140. package/dist/workspace.js +194 -0
  141. package/dist/workspace.js.map +1 -0
  142. package/package.json +30 -69
  143. package/LICENSE +0 -21
  144. package/agents.js +0 -14
  145. package/browser.js +0 -6
  146. package/cdn.js +0 -6
  147. package/chat.js +0 -21
  148. package/credits.js +0 -11
  149. package/icons.js +0 -11
  150. package/index.d.ts +0 -986
  151. package/index.js +0 -63
  152. package/namespaces.js +0 -12
  153. package/sandbox.js +0 -12
  154. package/search.js +0 -11
  155. package/src/agents/agent.js +0 -229
  156. package/src/agents/index.js +0 -227
  157. package/src/agents/settings.js +0 -100
  158. package/src/agents/tools.js +0 -155
  159. package/src/browser/index.js +0 -474
  160. package/src/cdn/index.js +0 -769
  161. package/src/chat/index.js +0 -724
  162. package/src/chat/session.js +0 -93
  163. package/src/client.js +0 -175
  164. package/src/credits/index.js +0 -492
  165. package/src/icons/index.js +0 -185
  166. package/src/namespaces/index.js +0 -236
  167. package/src/namespaces/namespace.js +0 -274
  168. package/src/sandbox/core/api/base.js +0 -89
  169. package/src/sandbox/core/api/database.js +0 -340
  170. package/src/sandbox/core/api/files.js +0 -141
  171. package/src/sandbox/core/api/git.js +0 -174
  172. package/src/sandbox/core/api/search.js +0 -29
  173. package/src/sandbox/core/api/snapshots.js +0 -132
  174. package/src/sandbox/core/api/terminal.js +0 -20
  175. package/src/sandbox/core/auth.js +0 -256
  176. package/src/sandbox/core/client.js +0 -197
  177. package/src/sandbox/core/index.js +0 -22
  178. package/src/sandbox/core/managers/terminal.js +0 -453
  179. package/src/sandbox/core/managers/watcher.js +0 -197
  180. package/src/sandbox/core/types.js +0 -92
  181. package/src/sandbox/core/utils/http.js +0 -89
  182. package/src/sandbox/core/websocket/connection.js +0 -479
  183. package/src/sandbox/index.d.ts +0 -542
  184. package/src/sandbox/index.js +0 -234
  185. package/src/sandbox/sandbox.js +0 -313
  186. package/src/search/index.js +0 -206
  187. package/src/utils/guest-manager.js +0 -454
@@ -1,234 +0,0 @@
1
- /**
2
- * Sandboxes Module
3
- * Manages cloud sandboxes - create, control, monitor
4
- */
5
-
6
- import { OblienClient } from '../client.js';
7
- import { Sandbox } from './sandbox.js';
8
-
9
- export class OblienSandboxes {
10
- /**
11
- * @param {import('../client.js').OblienClient|Object} clientOrConfig - Oblien client instance or config
12
- * @param {string} [clientOrConfig.clientId] - Client ID (if not using client instance)
13
- * @param {string} [clientOrConfig.clientSecret] - Client Secret (if not using client instance)
14
- * @param {string} [clientOrConfig.baseURL] - Base URL (optional)
15
- */
16
- constructor(clientOrConfig) {
17
- if (!clientOrConfig) {
18
- throw new Error('Oblien client or credentials are required');
19
- }
20
-
21
- // If it's already a client instance
22
- if (clientOrConfig.clientId && clientOrConfig.clientSecret && typeof clientOrConfig.get === 'function') {
23
- this.client = clientOrConfig;
24
- }
25
- // If credentials provided, create client
26
- else if (clientOrConfig.clientId && clientOrConfig.clientSecret) {
27
- this.client = new OblienClient(clientOrConfig);
28
- }
29
- else {
30
- throw new Error('Either provide OblienClient instance or { clientId, clientSecret }');
31
- }
32
- }
33
-
34
- /**
35
- * Create a new sandbox and return Sandbox instance
36
- * @param {Object} options - Sandbox options
37
- * @param {string} [options.name] - Sandbox name
38
- * @param {string} [options.region='us-east-1'] - Region: 'us-east-1' | 'us-west-1' | 'eu-west-1'
39
- * @param {string} [options.template='node-20'] - Template: 'node-20' | 'python-3' | 'blank' | custom
40
- * @param {Object} [options.config] - Custom configuration
41
- * @param {boolean} [options.autoStart=true] - Auto-start sandbox after creation (default: true)
42
- * @returns {Promise<Sandbox>} Sandbox instance ready to use
43
- */
44
- async create(options = {}) {
45
- const {
46
- name,
47
- region = 'us-east-1',
48
- template = 'node-20',
49
- config,
50
- autoStart = true
51
- } = options;
52
-
53
- const response = await this.client.post('sandbox', {
54
- name,
55
- region,
56
- template,
57
- config,
58
- autoStart
59
- });
60
-
61
- const sandboxData = response.sandbox || response;
62
-
63
- // Return Sandbox instance ready to use
64
- const sandbox = new Sandbox({
65
- client: this.client,
66
- sandboxId: sandboxData.id
67
- });
68
-
69
- // Pre-cache the token to avoid refetching
70
- sandbox._tokenCache = {
71
- url: sandboxData.url,
72
- token: sandboxData.token
73
- };
74
- sandbox.baseURL = sandboxData.url;
75
- sandbox.token = sandboxData.token;
76
- sandbox.sandboxName = sandboxData.name;
77
-
78
- return sandbox;
79
- }
80
-
81
- /**
82
- * List all sandboxes with pagination and filtering
83
- * @param {Object} [options] - Query options
84
- * @param {number} [options.page=1] - Page number
85
- * @param {number} [options.limit=20] - Results per page
86
- * @param {string} [options.status] - Filter by status: 'active' | 'stopped' | 'suspended' | 'deleted'
87
- * @returns {Promise<Object>} Sandboxes data with pagination info
88
- */
89
- async list(options = {}) {
90
- const params = {
91
- page: options.page || 1,
92
- limit: options.limit || 20
93
- };
94
-
95
- if (options.status) {
96
- params.status = options.status;
97
- }
98
-
99
- const response = await this.client.get('sandbox', params);
100
- return response;
101
- }
102
-
103
- /**
104
- * Get sandbox by ID
105
- * @param {string} sandboxId - Sandbox ID
106
- * @returns {Promise<Object>} Sandbox data
107
- */
108
- async get(sandboxId) {
109
- if (!sandboxId) {
110
- throw new Error('Sandbox ID is required');
111
- }
112
-
113
- const sandbox = new Sandbox({ client: this.client, sandboxId });
114
- return await sandbox.get();
115
- }
116
-
117
- /**
118
- * Update sandbox
119
- * @param {string} sandboxId - Sandbox ID
120
- * @param {Object} updates - Fields to update
121
- * @returns {Promise<Object>} Update result
122
- */
123
- async update(sandboxId, updates) {
124
- const sandbox = new Sandbox({ client: this.client, sandboxId });
125
- return await sandbox.update(updates);
126
- }
127
-
128
- /**
129
- * Delete sandbox
130
- * @param {string} sandboxId - Sandbox ID
131
- * @returns {Promise<Object>} Delete result
132
- */
133
- async delete(sandboxId) {
134
- const sandbox = new Sandbox({ client: this.client, sandboxId });
135
- return await sandbox.delete();
136
- }
137
-
138
- /**
139
- * Start sandbox
140
- * @param {string} sandboxId - Sandbox ID
141
- * @returns {Promise<Object>} Start result with new token
142
- */
143
- async start(sandboxId) {
144
- const sandbox = new Sandbox({ client: this.client, sandboxId });
145
- return await sandbox.start();
146
- }
147
-
148
- /**
149
- * Stop sandbox
150
- * @param {string} sandboxId - Sandbox ID
151
- * @returns {Promise<Object>} Stop result
152
- */
153
- async stop(sandboxId) {
154
- const sandbox = new Sandbox({ client: this.client, sandboxId });
155
- return await sandbox.stop();
156
- }
157
-
158
- /**
159
- * Restart sandbox
160
- * @param {string} sandboxId - Sandbox ID
161
- * @returns {Promise<Object>} Restart result with new token
162
- */
163
- async restart(sandboxId) {
164
- const sandbox = new Sandbox({ client: this.client, sandboxId });
165
- return await sandbox.restart();
166
- }
167
-
168
- /**
169
- * Regenerate sandbox token
170
- * @param {string} sandboxId - Sandbox ID
171
- * @returns {Promise<Object>} New token (1h expiry)
172
- */
173
- async regenerateToken(sandboxId) {
174
- const sandbox = new Sandbox({ client: this.client, sandboxId });
175
- return await sandbox.regenerateToken();
176
- }
177
-
178
- /**
179
- * Get sandbox metrics
180
- * @param {string} sandboxId - Sandbox ID
181
- * @returns {Promise<Object>} Sandbox metrics
182
- */
183
- async getMetrics(sandboxId) {
184
- const sandbox = new Sandbox({ client: this.client, sandboxId });
185
- return await sandbox.getMetrics();
186
- }
187
-
188
- /**
189
- * Get sandbox stats (overall statistics)
190
- * @returns {Promise<Object>} Sandbox statistics
191
- */
192
- async getStats() {
193
- return await this.client.get('sandbox/stats');
194
- }
195
-
196
- /**
197
- * Get sandbox activity
198
- * @returns {Promise<Object>} Sandbox activity logs
199
- */
200
- async getActivity() {
201
- return await this.client.get('sandbox/activity');
202
- }
203
-
204
- /**
205
- * Create a Sandbox instance for chaining operations (auto-fetches token)
206
- * @param {string} sandboxId - Sandbox ID
207
- * @returns {Sandbox} Sandbox instance
208
- */
209
- sandbox(sandboxId) {
210
- return new Sandbox({ client: this.client, sandboxId });
211
- }
212
-
213
- /**
214
- * Connect to sandbox with direct token (no auto-fetch/renewal)
215
- * Use this in backend when you already have a valid token
216
- *
217
- * @param {string} token - Sandbox access token (required)
218
- * @param {string} [sandboxId] - Sandbox ID (optional)
219
- * @param {string} [baseURL] - Sandbox base URL (optional)
220
- * @returns {Sandbox} Sandbox instance with direct token
221
- *
222
- * @example
223
- * const sandbox = client.sandboxes.fromToken('eyJhbGc...', 'sandbox_123');
224
- * await sandbox.files.list({ dirPath: '/opt/app' });
225
- */
226
- fromToken(token, sandboxId = null, baseURL = null) {
227
- return Sandbox.fromToken(token, sandboxId, baseURL);
228
- }
229
- }
230
-
231
- export { Sandbox };
232
- export { SandboxClient } from './core/client.js';
233
- export default OblienSandboxes;
234
-
@@ -1,313 +0,0 @@
1
- import { SandboxClient } from './core/client.js';
2
-
3
- /**
4
- * Sandbox - Management + Interaction in one
5
- * Extends SandboxClient and auto-fetches token on first use
6
- *
7
- * Can be used directly:
8
- * - new Sandbox({ token: '...' }) - Direct token (backend use)
9
- * - new Sandbox({ client, sandboxId }) - Auto-fetch token
10
- * - Sandbox.fromToken(token, sandboxId) - Static method
11
- */
12
- export class Sandbox extends SandboxClient {
13
- /**
14
- * @param {Object} options
15
- * @param {import('../client.js').OblienClient} [options.client] - Oblien client instance
16
- * @param {string} [options.sandboxId] - Sandbox ID
17
- * @param {string} [options.token] - Direct token (skips auto-fetch)
18
- * @param {string} [options.baseURL] - Sandbox base URL
19
- */
20
- constructor({ client = null, sandboxId = null, token = null, baseURL = null }) {
21
- // Direct token mode (backend use)
22
- if (token) {
23
- super({
24
- baseURL: baseURL || 'https://sandbox.oblien.com',
25
- token,
26
- sandboxId,
27
- oblienClient: client
28
- });
29
-
30
- this.client = client;
31
- this._tokenCache = {
32
- url: baseURL || 'https://sandbox.oblien.com',
33
- token
34
- };
35
- this._directToken = true; // Skip auto-renewal
36
- this._fetchPromise = null;
37
- return;
38
- }
39
-
40
- // Auto-fetch mode (requires client)
41
- if (!client) {
42
- throw new Error('Either token or client is required');
43
- }
44
-
45
- // Initialize parent with null token (will fetch on demand)
46
- super({
47
- baseURL: baseURL || 'https://sandbox.oblien.com',
48
- token: null,
49
- sandboxId,
50
- oblienClient: client
51
- });
52
-
53
- this.client = client;
54
- this._tokenCache = null;
55
- this._fetchPromise = null;
56
- }
57
-
58
- /**
59
- * Create Sandbox instance with direct token (no auto-fetch)
60
- * Perfect for backend when you already have the token
61
- *
62
- * @param {string} token - Sandbox access token
63
- * @param {string} [sandboxId] - Sandbox ID (optional)
64
- * @param {string} [baseURL] - Sandbox base URL (optional)
65
- * @returns {Sandbox}
66
- *
67
- * @example
68
- * const sandbox = Sandbox.fromToken('eyJhbGc...', 'sandbox_123');
69
- * await sandbox.files.list({ dirPath: '/opt/app' });
70
- */
71
- static fromToken(token, sandboxId = null, baseURL = null) {
72
- if (!token) {
73
- throw new Error('Token is required');
74
- }
75
-
76
- return new Sandbox({ token, sandboxId, baseURL });
77
- }
78
-
79
- /**
80
- * Create a new sandbox via API
81
- *
82
- * @param {import('../client.js').OblienClient} client - Oblien client
83
- * @param {Object} options - Sandbox creation options
84
- * @returns {Promise<Sandbox>}
85
- *
86
- * @example
87
- * const sandbox = await Sandbox.create(client, {
88
- * name: 'my-sandbox',
89
- * template: 'node-20'
90
- * });
91
- * await sandbox.files.list({ dirPath: '/opt/app' });
92
- */
93
- static async create(client, options = {}) {
94
- if (!client) {
95
- throw new Error('Oblien client is required');
96
- }
97
-
98
- const {
99
- name,
100
- region = 'us-east-1',
101
- template = 'node-20',
102
- config,
103
- autoStart = true
104
- } = options;
105
-
106
- const response = await client.post('sandbox', {
107
- name,
108
- region,
109
- template,
110
- config,
111
- autoStart
112
- });
113
-
114
- const sandboxData = response.sandbox || response;
115
-
116
- return new Sandbox({
117
- client,
118
- sandboxId: sandboxData.id,
119
- token: sandboxData.token,
120
- baseURL: sandboxData.url
121
- });
122
- }
123
-
124
- /**
125
- * Override: Get base URL (fetches from API if needed)
126
- * @returns {string}
127
- */
128
- getBaseURL() {
129
- return this._tokenCache?.url || this.baseURL;
130
- }
131
-
132
- /**
133
- * Override: Get token (fetches from API if needed or expired)
134
- * @returns {Promise<string>}
135
- */
136
- async getToken() {
137
- // Skip expiry check if using direct token
138
- if (!this._directToken && this._tokenCache && this._isTokenExpired()) {
139
- this._invalidateToken();
140
- }
141
-
142
- if (!this._tokenCache) {
143
- if (!this._fetchPromise) {
144
- this._fetchPromise = this._fetchToken();
145
- }
146
- await this._fetchPromise;
147
- }
148
- return this._tokenCache.token;
149
- }
150
-
151
- /**
152
- * Check if JWT token is expired
153
- * @private
154
- * @returns {boolean}
155
- */
156
- _isTokenExpired() {
157
- if (!this._tokenCache?.token) return false;
158
-
159
- try {
160
- // Decode JWT token (format: header.payload.signature)
161
- const payload = this._tokenCache.token.split('.')[1];
162
- if (!payload) return false;
163
-
164
- const decoded = JSON.parse(Buffer.from(payload, 'base64').toString());
165
-
166
- if (decoded.exp) {
167
- // Check if expired (with 5 minute buffer)
168
- const expiryTime = decoded.exp * 1000;
169
- const now = Date.now();
170
- const buffer = 5 * 60 * 1000; // 5 minutes
171
-
172
- return now >= (expiryTime - buffer);
173
- }
174
- } catch (error) {
175
- // If can't decode, assume not expired
176
- console.warn('[Sandbox] Failed to decode token:', error.message);
177
- }
178
-
179
- return false;
180
- }
181
-
182
- /**
183
- * Internal: Fetch token from API
184
- * @private
185
- */
186
- async _fetchToken() {
187
- const details = await this.get();
188
- this._tokenCache = {
189
- url: details.url,
190
- token: details.token
191
- };
192
- this.baseURL = details.url;
193
- this.token = details.token;
194
- this.sandboxName = details.name;
195
- }
196
-
197
- /**
198
- * Internal: Invalidate token cache
199
- * @private
200
- */
201
- _invalidateToken() {
202
- this._tokenCache = null;
203
- this._fetchPromise = null;
204
- }
205
-
206
- // Management Methods
207
-
208
- /**
209
- * Get sandbox details
210
- * @returns {Promise<Object>} Sandbox data
211
- */
212
- async get() {
213
- if (!this.sandboxId) {
214
- throw new Error('Sandbox ID is required');
215
- }
216
-
217
- const response = await this.client.get(`sandbox/${this.sandboxId}`);
218
- return response.sandbox || response;
219
- }
220
-
221
- /**
222
- * Update sandbox
223
- * @param {Object} updates - Fields to update
224
- * @returns {Promise<Object>} Update result
225
- */
226
- async update(updates) {
227
- if (!this.sandboxId) {
228
- throw new Error('Sandbox ID is required');
229
- }
230
-
231
- return await this.client.put(`sandbox/${this.sandboxId}`, updates);
232
- }
233
-
234
- /**
235
- * Delete sandbox
236
- * @returns {Promise<Object>} Delete result
237
- */
238
- async delete() {
239
- if (!this.sandboxId) {
240
- throw new Error('Sandbox ID is required');
241
- }
242
-
243
- return await this.client.delete(`sandbox/${this.sandboxId}`);
244
- }
245
-
246
- /**
247
- * Start sandbox
248
- * @returns {Promise<Object>} Start result with new token
249
- */
250
- async start() {
251
- if (!this.sandboxId) {
252
- throw new Error('Sandbox ID is required');
253
- }
254
-
255
- const result = await this.client.post(`sandbox/${this.sandboxId}/start`);
256
- this._invalidateToken();
257
- return result;
258
- }
259
-
260
- /**
261
- * Stop sandbox
262
- * @returns {Promise<Object>} Stop result
263
- */
264
- async stop() {
265
- if (!this.sandboxId) {
266
- throw new Error('Sandbox ID is required');
267
- }
268
-
269
- return await this.client.post(`sandbox/${this.sandboxId}/stop`);
270
- }
271
-
272
- /**
273
- * Restart sandbox
274
- * @returns {Promise<Object>} Restart result with new token
275
- */
276
- async restart() {
277
- if (!this.sandboxId) {
278
- throw new Error('Sandbox ID is required');
279
- }
280
-
281
- const result = await this.client.post(`sandbox/${this.sandboxId}/restart`);
282
- this._invalidateToken();
283
- return result;
284
- }
285
-
286
- /**
287
- * Regenerate sandbox token
288
- * @returns {Promise<Object>} New token (1h expiry)
289
- */
290
- async regenerateToken() {
291
- if (!this.sandboxId) {
292
- throw new Error('Sandbox ID is required');
293
- }
294
-
295
- const result = await this.client.post(`sandbox/${this.sandboxId}/regenerate-token`);
296
- this._invalidateToken();
297
- return result;
298
- }
299
-
300
- /**
301
- * Get sandbox metrics
302
- * @returns {Promise<Object>} Sandbox metrics
303
- */
304
- async getMetrics() {
305
- if (!this.sandboxId) {
306
- throw new Error('Sandbox ID is required');
307
- }
308
-
309
- return await this.client.get(`sandbox/${this.sandboxId}/metrics`);
310
- }
311
- }
312
-
313
- export default Sandbox;