@celestoai/sdk 0.1.2 → 0.1.3

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.
package/dist/index.cjs CHANGED
@@ -20,11 +20,10 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var src_exports = {};
22
22
  __export(src_exports, {
23
- Celesto: () => Celesto,
24
23
  CelestoApiError: () => CelestoApiError,
25
24
  CelestoError: () => CelestoError,
26
25
  CelestoNetworkError: () => CelestoNetworkError,
27
- ComputersClient: () => ComputersClient,
26
+ Computer: () => Computer,
28
27
  GatekeeperClient: () => GatekeeperClient
29
28
  });
30
29
  module.exports = __toCommonJS(src_exports);
@@ -169,8 +168,176 @@ var request = async (ctx, options) => {
169
168
  }
170
169
  };
171
170
 
171
+ // src/gatekeeper/client.ts
172
+ var toConnectRequest = (payload) => ({
173
+ subject: payload.subject,
174
+ provider: payload.provider ?? "google_drive",
175
+ project_name: payload.projectName,
176
+ redirect_uri: payload.redirectUri
177
+ });
178
+ var toConnectResponse = (payload) => ({
179
+ status: payload.status,
180
+ oauthUrl: payload.oauth_url ?? void 0,
181
+ connectionId: payload.connection_id ?? void 0
182
+ });
183
+ var toConnection = (payload) => ({
184
+ id: payload.id,
185
+ subject: payload.subject,
186
+ provider: payload.provider,
187
+ projectId: payload.project_id,
188
+ accountEmail: payload.account_email ?? null,
189
+ scopes: payload.scopes ?? [],
190
+ status: payload.status,
191
+ createdAt: payload.created_at,
192
+ updatedAt: payload.updated_at,
193
+ lastUsedAt: payload.last_used_at ?? null,
194
+ accessRules: payload.access_rules ? {
195
+ version: payload.access_rules.version ?? "1",
196
+ allowedFolders: payload.access_rules.allowed_folders ?? [],
197
+ allowedFiles: payload.access_rules.allowed_files ?? [],
198
+ unrestricted: false
199
+ } : null
200
+ });
201
+ var toAccessRules = (payload) => ({
202
+ version: payload.version,
203
+ allowedFolders: payload.allowed_folders ?? [],
204
+ allowedFiles: payload.allowed_files ?? [],
205
+ unrestricted: payload.unrestricted
206
+ });
207
+ var toDriveFile = (payload) => ({
208
+ id: payload.id,
209
+ name: payload.name ?? null,
210
+ mimeType: payload.mime_type ?? null,
211
+ size: payload.size ?? null,
212
+ modifiedTime: payload.modified_time ?? null,
213
+ createdTime: payload.created_time ?? null,
214
+ webViewLink: payload.web_view_link ?? null,
215
+ iconLink: payload.icon_link ?? null,
216
+ thumbnailLink: payload.thumbnail_link ?? null,
217
+ parents: payload.parents ?? null,
218
+ driveId: payload.drive_id ?? null,
219
+ shared: payload.shared ?? null,
220
+ ownedByMe: payload.owned_by_me ?? null
221
+ });
222
+ var gatekeeperPath = (path) => `/v1/gatekeeper${path}`;
223
+ var pickOverrides = (options) => ({
224
+ headers: options?.headers,
225
+ signal: options?.signal
226
+ });
227
+ var GatekeeperClient = class {
228
+ constructor(config) {
229
+ this.config = config;
230
+ }
231
+ async connect(payload, options) {
232
+ const ctx = buildRequestContext(this.config);
233
+ const data = await request(ctx, {
234
+ method: "POST",
235
+ path: gatekeeperPath("/connect"),
236
+ body: toConnectRequest(payload),
237
+ ...pickOverrides(options)
238
+ });
239
+ return toConnectResponse(data);
240
+ }
241
+ async listConnections(params, options) {
242
+ const ctx = buildRequestContext(this.config);
243
+ const data = await request(ctx, {
244
+ method: "GET",
245
+ path: gatekeeperPath("/connections"),
246
+ query: {
247
+ project_name: params.projectName,
248
+ status_filter: params.statusFilter
249
+ },
250
+ ...pickOverrides(options)
251
+ });
252
+ return {
253
+ total: data.total,
254
+ data: data.data.map(toConnection)
255
+ };
256
+ }
257
+ async getConnection(connectionId, options) {
258
+ const ctx = buildRequestContext(this.config);
259
+ const data = await request(ctx, {
260
+ method: "GET",
261
+ path: gatekeeperPath(`/connections/${connectionId}`),
262
+ ...pickOverrides(options)
263
+ });
264
+ return toConnection(data);
265
+ }
266
+ async revokeConnection(params, options) {
267
+ const ctx = buildRequestContext(this.config);
268
+ return request(ctx, {
269
+ method: "DELETE",
270
+ path: gatekeeperPath("/connections"),
271
+ query: {
272
+ subject: params.subject,
273
+ project_name: params.projectName,
274
+ provider: params.provider
275
+ },
276
+ ...pickOverrides(options)
277
+ });
278
+ }
279
+ async listDriveFiles(params, options) {
280
+ const ctx = buildRequestContext(this.config);
281
+ const data = await request(ctx, {
282
+ method: "GET",
283
+ path: gatekeeperPath("/connectors/drive/files"),
284
+ query: {
285
+ project_name: params.projectName,
286
+ subject: params.subject,
287
+ page_size: params.pageSize,
288
+ page_token: params.pageToken,
289
+ folder_id: params.folderId,
290
+ query: params.query,
291
+ include_folders: params.includeFolders,
292
+ order_by: params.orderBy
293
+ },
294
+ ...pickOverrides(options)
295
+ });
296
+ return {
297
+ files: data.files.map(toDriveFile),
298
+ nextPageToken: data.next_page_token ?? null
299
+ };
300
+ }
301
+ async getAccessRules(connectionId, options) {
302
+ const ctx = buildRequestContext(this.config);
303
+ const data = await request(ctx, {
304
+ method: "GET",
305
+ path: gatekeeperPath(`/connections/${connectionId}/access-rules`),
306
+ ...pickOverrides(options)
307
+ });
308
+ return toAccessRules(data);
309
+ }
310
+ async updateAccessRules(params, options) {
311
+ const ctx = buildRequestContext(this.config);
312
+ const data = await request(ctx, {
313
+ method: "PUT",
314
+ path: gatekeeperPath("/connections/access-rules"),
315
+ query: {
316
+ subject: params.subject,
317
+ project_name: params.projectName,
318
+ provider: params.provider
319
+ },
320
+ body: {
321
+ allowed_folders: params.accessRules.allowedFolders ?? [],
322
+ allowed_files: params.accessRules.allowedFiles ?? []
323
+ },
324
+ ...pickOverrides(options)
325
+ });
326
+ return toAccessRules(data);
327
+ }
328
+ async clearAccessRules(connectionId, options) {
329
+ const ctx = buildRequestContext(this.config);
330
+ const data = await request(ctx, {
331
+ method: "DELETE",
332
+ path: gatekeeperPath(`/connections/${connectionId}/access-rules`),
333
+ ...pickOverrides(options)
334
+ });
335
+ return toAccessRules(data);
336
+ }
337
+ };
338
+
172
339
  // src/computers/client.ts
173
- var toConnection = (payload) => {
340
+ var toConnection2 = (payload) => {
174
341
  if (!payload) {
175
342
  return void 0;
176
343
  }
@@ -183,6 +350,14 @@ var toConnection = (payload) => {
183
350
  }
184
351
  return out;
185
352
  };
353
+ var toPublishedPortInfo = (payload) => ({
354
+ id: payload.id ?? null,
355
+ computerId: payload.computer_id,
356
+ port: payload.port,
357
+ url: payload.url ?? null,
358
+ status: payload.status,
359
+ createdAt: payload.created_at ?? null
360
+ });
186
361
  var toComputerInfo = (payload) => ({
187
362
  id: payload.id,
188
363
  name: payload.name,
@@ -193,7 +368,8 @@ var toComputerInfo = (payload) => ({
193
368
  image: payload.image,
194
369
  templateId: payload.template_id,
195
370
  templateVersion: payload.template_version ?? null,
196
- connection: toConnection(payload.connection),
371
+ connection: toConnection2(payload.connection),
372
+ publishedPorts: payload.published_ports?.map(toPublishedPortInfo),
197
373
  lastError: payload.last_error ?? null,
198
374
  createdAt: payload.created_at,
199
375
  stoppedAt: payload.stopped_at ?? null
@@ -213,6 +389,80 @@ var toSandboxTemplateInfo = (payload) => ({
213
389
  version: payload.version ?? null,
214
390
  experimental: payload.experimental
215
391
  });
392
+ var diskUnitsToMb = {
393
+ "": 1,
394
+ m: 1,
395
+ mb: 1,
396
+ mib: 1,
397
+ g: 1024,
398
+ gb: 1024,
399
+ gib: 1024,
400
+ t: 1024 * 1024,
401
+ tb: 1024 * 1024,
402
+ tib: 1024 * 1024
403
+ };
404
+ var isAsciiDigit = (char) => char >= "0" && char <= "9";
405
+ var isAsciiLetter = (char) => char >= "a" && char <= "z" || char >= "A" && char <= "Z";
406
+ var isSeparatorWhitespace = (char) => char === " " || char === " ";
407
+ var parseDiskString = (disk) => {
408
+ const value = disk.trim();
409
+ if (!value) {
410
+ return void 0;
411
+ }
412
+ let index = 0;
413
+ let digitCount = 0;
414
+ let hasDecimalPoint = false;
415
+ while (index < value.length) {
416
+ const char = value[index];
417
+ if (isAsciiDigit(char)) {
418
+ digitCount += 1;
419
+ index += 1;
420
+ continue;
421
+ }
422
+ if (char === "." && !hasDecimalPoint) {
423
+ hasDecimalPoint = true;
424
+ index += 1;
425
+ continue;
426
+ }
427
+ break;
428
+ }
429
+ if (digitCount === 0 || value[index - 1] === ".") {
430
+ return void 0;
431
+ }
432
+ const amount = value.slice(0, index);
433
+ while (index < value.length && isSeparatorWhitespace(value[index])) {
434
+ index += 1;
435
+ }
436
+ const unit = value.slice(index);
437
+ if ([...unit].some((char) => !isAsciiLetter(char))) {
438
+ return void 0;
439
+ }
440
+ return { amount, unit };
441
+ };
442
+ var parseDiskSizeMb = (disk) => {
443
+ if (disk === void 0) {
444
+ return void 0;
445
+ }
446
+ if (typeof disk === "number") {
447
+ if (!Number.isInteger(disk) || disk <= 0) {
448
+ throw new Error("disk as a number must be a whole number of MB.");
449
+ }
450
+ return disk;
451
+ }
452
+ const parsedDisk = parseDiskString(disk);
453
+ if (!parsedDisk) {
454
+ throw new Error("disk must be a size in MB or a string like '2gb'.");
455
+ }
456
+ const multiplier = diskUnitsToMb[parsedDisk.unit.toLowerCase()];
457
+ if (multiplier === void 0) {
458
+ throw new Error("disk must use MB, GB, or TB, for example '2048mb' or '2gb'.");
459
+ }
460
+ const sizeMb = Number(parsedDisk.amount) * multiplier;
461
+ if (!Number.isInteger(sizeMb) || sizeMb <= 0) {
462
+ throw new Error("disk must resolve to a whole number of MB, for example '1536mb' or '1.5gb'.");
463
+ }
464
+ return sizeMb;
465
+ };
216
466
  var buildCreateComputerBody = (params) => {
217
467
  if (params.cpus !== void 0 && params.vcpus !== void 0 && params.cpus !== params.vcpus) {
218
468
  throw new Error("cpus and vcpus must have the same value when both are provided.");
@@ -220,17 +470,22 @@ var buildCreateComputerBody = (params) => {
220
470
  if (params.memory !== void 0 && params.ramMb !== void 0 && params.memory !== params.ramMb) {
221
471
  throw new Error("memory and ramMb must have the same value when both are provided.");
222
472
  }
473
+ const parsedDiskSizeMb = parseDiskSizeMb(params.disk);
474
+ if (parsedDiskSizeMb !== void 0 && params.diskSizeMb !== void 0 && parsedDiskSizeMb !== params.diskSizeMb) {
475
+ throw new Error("disk and diskSizeMb must have the same value when both are provided.");
476
+ }
223
477
  const body = {};
224
478
  const vcpus = params.vcpus ?? params.cpus;
225
479
  const ramMb = params.ramMb ?? params.memory;
480
+ const diskSizeMb = params.diskSizeMb ?? parsedDiskSizeMb;
226
481
  if (vcpus !== void 0) {
227
482
  body.vcpus = vcpus;
228
483
  }
229
484
  if (ramMb !== void 0) {
230
485
  body.ram_mb = ramMb;
231
486
  }
232
- if (params.diskSizeMb !== void 0) {
233
- body.disk_size_mb = params.diskSizeMb;
487
+ if (diskSizeMb !== void 0) {
488
+ body.disk_size_mb = diskSizeMb;
234
489
  }
235
490
  if (params.image !== void 0) {
236
491
  body.image = params.image;
@@ -244,7 +499,7 @@ var buildCreateComputerBody = (params) => {
244
499
  return body;
245
500
  };
246
501
  var computersPath = (path) => `/v1/computers${path}`;
247
- var pickOverrides = (options) => ({
502
+ var pickOverrides2 = (options) => ({
248
503
  headers: options?.headers,
249
504
  signal: options?.signal
250
505
  });
@@ -258,7 +513,7 @@ var ComputersClient = class {
258
513
  method: "POST",
259
514
  path: computersPath(""),
260
515
  body: buildCreateComputerBody(params),
261
- ...pickOverrides(options)
516
+ ...pickOverrides2(options)
262
517
  });
263
518
  return toComputerInfo(data);
264
519
  }
@@ -267,16 +522,22 @@ var ComputersClient = class {
267
522
  const data = await request(ctx, {
268
523
  method: "GET",
269
524
  path: computersPath("/templates"),
270
- ...pickOverrides(options)
525
+ ...pickOverrides2(options)
271
526
  });
272
527
  return data.map(toSandboxTemplateInfo);
273
528
  }
274
- async list(options) {
529
+ async list(params = {}, options) {
275
530
  const ctx = buildRequestContext(this.config);
276
531
  const data = await request(ctx, {
277
532
  method: "GET",
278
533
  path: computersPath(""),
279
- ...pickOverrides(options)
534
+ query: {
535
+ status: params.status,
536
+ template_id: params.templateId,
537
+ project_id: params.projectId,
538
+ limit: params.limit
539
+ },
540
+ ...pickOverrides2(options)
280
541
  });
281
542
  return {
282
543
  computers: data.computers.map(toComputerInfo),
@@ -288,7 +549,7 @@ var ComputersClient = class {
288
549
  const data = await request(ctx, {
289
550
  method: "GET",
290
551
  path: computersPath(`/${encodeURIComponent(computerId)}`),
291
- ...pickOverrides(options)
552
+ ...pickOverrides2(options)
292
553
  });
293
554
  return toComputerInfo(data);
294
555
  }
@@ -301,7 +562,7 @@ var ComputersClient = class {
301
562
  command,
302
563
  timeout: params.timeout ?? 30
303
564
  },
304
- ...pickOverrides(options)
565
+ ...pickOverrides2(options)
305
566
  });
306
567
  return toExecResponse(data);
307
568
  }
@@ -310,7 +571,7 @@ var ComputersClient = class {
310
571
  const data = await request(ctx, {
311
572
  method: "POST",
312
573
  path: computersPath(`/${encodeURIComponent(computerId)}/stop`),
313
- ...pickOverrides(options)
574
+ ...pickOverrides2(options)
314
575
  });
315
576
  return toComputerInfo(data);
316
577
  }
@@ -319,7 +580,7 @@ var ComputersClient = class {
319
580
  const data = await request(ctx, {
320
581
  method: "POST",
321
582
  path: computersPath(`/${encodeURIComponent(computerId)}/start`),
322
- ...pickOverrides(options)
583
+ ...pickOverrides2(options)
323
584
  });
324
585
  return toComputerInfo(data);
325
586
  }
@@ -328,10 +589,38 @@ var ComputersClient = class {
328
589
  const data = await request(ctx, {
329
590
  method: "DELETE",
330
591
  path: computersPath(`/${encodeURIComponent(computerId)}`),
331
- ...pickOverrides(options)
592
+ ...pickOverrides2(options)
332
593
  });
333
594
  return toComputerInfo(data);
334
595
  }
596
+ async publishPort(computerId, port = 8e3, options) {
597
+ const ctx = buildRequestContext(this.config);
598
+ const data = await request(ctx, {
599
+ method: "POST",
600
+ path: computersPath(`/${encodeURIComponent(computerId)}/published-ports`),
601
+ body: { port },
602
+ ...pickOverrides2(options)
603
+ });
604
+ return toPublishedPortInfo(data);
605
+ }
606
+ async listPublishedPorts(computerId, options) {
607
+ const ctx = buildRequestContext(this.config);
608
+ const data = await request(ctx, {
609
+ method: "GET",
610
+ path: computersPath(`/${encodeURIComponent(computerId)}/published-ports`),
611
+ ...pickOverrides2(options)
612
+ });
613
+ return data.map(toPublishedPortInfo);
614
+ }
615
+ async unpublishPort(computerId, port = 8e3, options) {
616
+ const ctx = buildRequestContext(this.config);
617
+ const data = await request(ctx, {
618
+ method: "DELETE",
619
+ path: computersPath(`/${encodeURIComponent(computerId)}/published-ports/${port}`),
620
+ ...pickOverrides2(options)
621
+ });
622
+ return toPublishedPortInfo(data);
623
+ }
335
624
  /**
336
625
  * Get connection info for opening a WebSocket terminal session.
337
626
  *
@@ -344,7 +633,7 @@ var ComputersClient = class {
344
633
  *
345
634
  * @example
346
635
  * ```ts
347
- * const conn = await celesto.computers.getTerminalConnection("my-computer");
636
+ * const conn = await client.getTerminalConnection("my-computer");
348
637
  * const ws = new WebSocket(conn.url, { headers: conn.headers });
349
638
  * ws.on("open", () => ws.send(conn.firstMessage));
350
639
  * ws.on("message", (data) => process.stdout.write(data));
@@ -372,188 +661,152 @@ var ComputersClient = class {
372
661
  }
373
662
  };
374
663
 
375
- // src/gatekeeper/client.ts
376
- var toConnectRequest = (payload) => ({
377
- subject: payload.subject,
378
- provider: payload.provider ?? "google_drive",
379
- project_name: payload.projectName,
380
- redirect_uri: payload.redirectUri
381
- });
382
- var toConnectResponse = (payload) => ({
383
- status: payload.status,
384
- oauthUrl: payload.oauth_url ?? void 0,
385
- connectionId: payload.connection_id ?? void 0
386
- });
387
- var toConnection2 = (payload) => ({
388
- id: payload.id,
389
- subject: payload.subject,
390
- provider: payload.provider,
391
- projectId: payload.project_id,
392
- accountEmail: payload.account_email ?? null,
393
- scopes: payload.scopes ?? [],
394
- status: payload.status,
395
- createdAt: payload.created_at,
396
- updatedAt: payload.updated_at,
397
- lastUsedAt: payload.last_used_at ?? null,
398
- accessRules: payload.access_rules ? {
399
- version: payload.access_rules.version ?? "1",
400
- allowedFolders: payload.access_rules.allowed_folders ?? [],
401
- allowedFiles: payload.access_rules.allowed_files ?? [],
402
- unrestricted: false
403
- } : null
664
+ // src/computers/computer.ts
665
+ var defaultConfig = () => ({
666
+ token: typeof process !== "undefined" ? process.env.CELESTO_API_KEY : void 0
404
667
  });
405
- var toAccessRules = (payload) => ({
406
- version: payload.version,
407
- allowedFolders: payload.allowed_folders ?? [],
408
- allowedFiles: payload.allowed_files ?? [],
409
- unrestricted: payload.unrestricted
410
- });
411
- var toDriveFile = (payload) => ({
412
- id: payload.id,
413
- name: payload.name ?? null,
414
- mimeType: payload.mime_type ?? null,
415
- size: payload.size ?? null,
416
- modifiedTime: payload.modified_time ?? null,
417
- createdTime: payload.created_time ?? null,
418
- webViewLink: payload.web_view_link ?? null,
419
- iconLink: payload.icon_link ?? null,
420
- thumbnailLink: payload.thumbnail_link ?? null,
421
- parents: payload.parents ?? null,
422
- driveId: payload.drive_id ?? null,
423
- shared: payload.shared ?? null,
424
- ownedByMe: payload.owned_by_me ?? null
425
- });
426
- var gatekeeperPath = (path) => `/v1/gatekeeper${path}`;
427
- var pickOverrides2 = (options) => ({
428
- headers: options?.headers,
429
- signal: options?.signal
430
- });
431
- var GatekeeperClient = class {
432
- constructor(config) {
433
- this.config = config;
668
+ var Computer = class _Computer {
669
+ constructor(client, info) {
670
+ this.client = client;
671
+ this.info = info;
434
672
  }
435
- async connect(payload, options) {
436
- const ctx = buildRequestContext(this.config);
437
- const data = await request(ctx, {
438
- method: "POST",
439
- path: gatekeeperPath("/connect"),
440
- body: toConnectRequest(payload),
441
- ...pickOverrides2(options)
442
- });
443
- return toConnectResponse(data);
673
+ /** Create a new computer and return an object with methods on it. */
674
+ static async create(params = {}, config = defaultConfig()) {
675
+ const client = new ComputersClient(config);
676
+ const info = await client.create(params);
677
+ return new _Computer(client, info);
444
678
  }
445
- async listConnections(params, options) {
446
- const ctx = buildRequestContext(this.config);
447
- const data = await request(ctx, {
448
- method: "GET",
449
- path: gatekeeperPath("/connections"),
450
- query: {
451
- project_name: params.projectName,
452
- status_filter: params.statusFilter
453
- },
454
- ...pickOverrides2(options)
455
- });
456
- return {
457
- total: data.total,
458
- data: data.data.map(toConnection2)
459
- };
679
+ /** Load an existing computer by name or ID. */
680
+ static async get(computerIdOrName, config = defaultConfig()) {
681
+ const client = new ComputersClient(config);
682
+ const info = await client.get(computerIdOrName);
683
+ return new _Computer(client, info);
684
+ }
685
+ /** List computers in the current account. */
686
+ static async list(params = {}, config = defaultConfig()) {
687
+ const client = new ComputersClient(config);
688
+ const response = await client.list(params);
689
+ return response.computers.map((info) => new _Computer(client, info));
690
+ }
691
+ /** List available computer templates. */
692
+ static async listTemplates(config = defaultConfig()) {
693
+ const client = new ComputersClient(config);
694
+ return client.listTemplates();
695
+ }
696
+ /** Wrap an existing API response in the convenience object. */
697
+ static fromInfo(info, config = defaultConfig()) {
698
+ return new _Computer(new ComputersClient(config), info);
699
+ }
700
+ get id() {
701
+ return this.info.id;
702
+ }
703
+ get name() {
704
+ return this.info.name;
705
+ }
706
+ get status() {
707
+ return this.info.status;
708
+ }
709
+ get vcpus() {
710
+ return this.info.vcpus;
711
+ }
712
+ get ramMb() {
713
+ return this.info.ramMb;
714
+ }
715
+ get diskSizeMb() {
716
+ return this.info.diskSizeMb;
717
+ }
718
+ get image() {
719
+ return this.info.image;
720
+ }
721
+ get templateId() {
722
+ return this.info.templateId;
723
+ }
724
+ get templateVersion() {
725
+ return this.info.templateVersion;
726
+ }
727
+ get connection() {
728
+ return this.info.connection;
729
+ }
730
+ get publishedPorts() {
731
+ return this.info.publishedPorts;
732
+ }
733
+ get lastError() {
734
+ return this.info.lastError;
735
+ }
736
+ get createdAt() {
737
+ return this.info.createdAt;
738
+ }
739
+ get stoppedAt() {
740
+ return this.info.stoppedAt;
741
+ }
742
+ /** Get one field from the latest computer data. */
743
+ get(key) {
744
+ return this.info[key];
745
+ }
746
+ /** Return a copy of the latest computer data. */
747
+ toJSON() {
748
+ return { ...this.info };
749
+ }
750
+ /** Reload this computer from Celesto. */
751
+ async refresh() {
752
+ this.info = await this.client.get(this.id);
753
+ return this;
754
+ }
755
+ /** Run a shell command on this computer. */
756
+ async run(command, params = {}) {
757
+ return this.client.exec(this.id, command, params);
758
+ }
759
+ /** Alias for run(). */
760
+ async exec(command, params = {}) {
761
+ return this.run(command, params);
762
+ }
763
+ /** Stop this computer and update the local data. */
764
+ async stop() {
765
+ this.info = await this.client.stop(this.id);
766
+ return this;
767
+ }
768
+ /** Start this computer and update the local data. */
769
+ async start() {
770
+ this.info = await this.client.start(this.id);
771
+ return this;
460
772
  }
461
- async getConnection(connectionId, options) {
462
- const ctx = buildRequestContext(this.config);
463
- const data = await request(ctx, {
464
- method: "GET",
465
- path: gatekeeperPath(`/connections/${connectionId}`),
466
- ...pickOverrides2(options)
467
- });
468
- return toConnection2(data);
773
+ /** Delete this computer and update the local data. */
774
+ async delete() {
775
+ this.info = await this.client.delete(this.id);
776
+ return this;
469
777
  }
470
- async revokeConnection(params, options) {
471
- const ctx = buildRequestContext(this.config);
472
- return request(ctx, {
473
- method: "DELETE",
474
- path: gatekeeperPath("/connections"),
475
- query: {
476
- subject: params.subject,
477
- project_name: params.projectName,
478
- provider: params.provider
479
- },
480
- ...pickOverrides2(options)
481
- });
482
- }
483
- async listDriveFiles(params, options) {
484
- const ctx = buildRequestContext(this.config);
485
- const data = await request(ctx, {
486
- method: "GET",
487
- path: gatekeeperPath("/connectors/drive/files"),
488
- query: {
489
- project_name: params.projectName,
490
- subject: params.subject,
491
- page_size: params.pageSize,
492
- page_token: params.pageToken,
493
- folder_id: params.folderId,
494
- query: params.query,
495
- include_folders: params.includeFolders,
496
- order_by: params.orderBy
497
- },
498
- ...pickOverrides2(options)
499
- });
500
- return {
501
- files: data.files.map(toDriveFile),
502
- nextPageToken: data.next_page_token ?? null
778
+ /** Publish a port and return its public URL when the API provides one. */
779
+ async publishPort(port = 8e3) {
780
+ const published = await this.client.publishPort(this.id, port);
781
+ const existing = this.info.publishedPorts ?? [];
782
+ this.info = {
783
+ ...this.info,
784
+ publishedPorts: [...existing.filter((item) => item.port !== published.port), published]
503
785
  };
504
- }
505
- async getAccessRules(connectionId, options) {
506
- const ctx = buildRequestContext(this.config);
507
- const data = await request(ctx, {
508
- method: "GET",
509
- path: gatekeeperPath(`/connections/${connectionId}/access-rules`),
510
- ...pickOverrides2(options)
511
- });
512
- return toAccessRules(data);
513
- }
514
- async updateAccessRules(params, options) {
515
- const ctx = buildRequestContext(this.config);
516
- const data = await request(ctx, {
517
- method: "PUT",
518
- path: gatekeeperPath("/connections/access-rules"),
519
- query: {
520
- subject: params.subject,
521
- project_name: params.projectName,
522
- provider: params.provider
523
- },
524
- body: {
525
- allowed_folders: params.accessRules.allowedFolders ?? [],
526
- allowed_files: params.accessRules.allowedFiles ?? []
527
- },
528
- ...pickOverrides2(options)
529
- });
530
- return toAccessRules(data);
531
- }
532
- async clearAccessRules(connectionId, options) {
533
- const ctx = buildRequestContext(this.config);
534
- const data = await request(ctx, {
535
- method: "DELETE",
536
- path: gatekeeperPath(`/connections/${connectionId}/access-rules`),
537
- ...pickOverrides2(options)
538
- });
539
- return toAccessRules(data);
540
- }
541
- };
542
-
543
- // src/index.ts
544
- var Celesto = class {
545
- constructor(config) {
546
- this.gatekeeper = new GatekeeperClient(config);
547
- this.computers = new ComputersClient(config);
786
+ return published.url ?? null;
787
+ }
788
+ /** List public ports for this computer. */
789
+ async listPublishedPorts() {
790
+ const publishedPorts = await this.client.listPublishedPorts(this.id);
791
+ this.info = { ...this.info, publishedPorts };
792
+ return publishedPorts;
793
+ }
794
+ /** Remove a public port route. */
795
+ async unpublishPort(port = 8e3) {
796
+ const unpublished = await this.client.unpublishPort(this.id, port);
797
+ this.info = {
798
+ ...this.info,
799
+ publishedPorts: (this.info.publishedPorts ?? []).filter((item) => item.port !== port)
800
+ };
801
+ return unpublished;
548
802
  }
549
803
  };
550
804
  // Annotate the CommonJS export names for ESM import in node:
551
805
  0 && (module.exports = {
552
- Celesto,
553
806
  CelestoApiError,
554
807
  CelestoError,
555
808
  CelestoNetworkError,
556
- ComputersClient,
809
+ Computer,
557
810
  GatekeeperClient
558
811
  });
559
812
  //# sourceMappingURL=index.cjs.map