@lizard-build/sdk 0.1.22 → 0.1.24
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/README.md +9 -7
- package/dist/index.d.mts +417 -30
- package/dist/index.d.ts +417 -30
- package/dist/index.js +436 -16
- package/dist/index.mjs +435 -16
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -335,7 +335,7 @@ var Sandbox = class extends SandboxClient {
|
|
|
335
335
|
* Connect to an existing sandbox by its ID.
|
|
336
336
|
*
|
|
337
337
|
* If the sandbox is currently paused, it will be automatically resumed
|
|
338
|
-
*
|
|
338
|
+
* before this call returns.
|
|
339
339
|
*
|
|
340
340
|
* @example
|
|
341
341
|
* ```ts
|
|
@@ -366,10 +366,15 @@ var Sandbox = class extends SandboxClient {
|
|
|
366
366
|
return SandboxClient.killSandbox(this.sandboxId, this.resolveOpts(opts));
|
|
367
367
|
}
|
|
368
368
|
/**
|
|
369
|
-
*
|
|
369
|
+
* Pause the sandbox microVM by freezing its vCPUs.
|
|
370
370
|
*
|
|
371
|
-
*
|
|
372
|
-
* to
|
|
371
|
+
* Memory, filesystem, and running processes are held in the host's RAM —
|
|
372
|
+
* nothing is written to disk, so a paused sandbox does not survive a host
|
|
373
|
+
* failure. Resume with `sandbox.resume()` or `Sandbox.connect(id)`.
|
|
374
|
+
*
|
|
375
|
+
* Pausing does not stop the timeout: a paused sandbox is still deleted at
|
|
376
|
+
* its original expiry (default 5 minutes). Pass `timeoutMs: 0` at create
|
|
377
|
+
* time to opt out of expiry.
|
|
373
378
|
*
|
|
374
379
|
* @returns `true` if paused successfully.
|
|
375
380
|
*/
|
|
@@ -377,7 +382,7 @@ var Sandbox = class extends SandboxClient {
|
|
|
377
382
|
return SandboxClient.pauseSandbox(this.sandboxId, this.resolveOpts(opts));
|
|
378
383
|
}
|
|
379
384
|
/**
|
|
380
|
-
* Resume a paused sandbox
|
|
385
|
+
* Resume a paused sandbox by unfreezing its vCPUs.
|
|
381
386
|
*
|
|
382
387
|
* @returns `true` if resumed successfully.
|
|
383
388
|
*/
|
|
@@ -422,19 +427,437 @@ var Sandbox = class extends SandboxClient {
|
|
|
422
427
|
Sandbox.defaultTemplate = "base";
|
|
423
428
|
Sandbox.defaultTimeoutMs = DEFAULT_SANDBOX_TIMEOUT_MS;
|
|
424
429
|
|
|
430
|
+
// src/platform/client.ts
|
|
431
|
+
var PlatformClient = class {
|
|
432
|
+
constructor(opts) {
|
|
433
|
+
this.config = new ConnectionConfig(opts);
|
|
434
|
+
}
|
|
435
|
+
async get(path) {
|
|
436
|
+
const res = await fetch(`${this.config.apiUrl}${path}`, {
|
|
437
|
+
headers: this.config.headers
|
|
438
|
+
});
|
|
439
|
+
if (!res.ok) await handleApiError(res);
|
|
440
|
+
return res.json();
|
|
441
|
+
}
|
|
442
|
+
async post(path, body) {
|
|
443
|
+
const res = await fetch(`${this.config.apiUrl}${path}`, {
|
|
444
|
+
method: "POST",
|
|
445
|
+
headers: this.config.headers,
|
|
446
|
+
body: body !== void 0 ? JSON.stringify(body) : void 0
|
|
447
|
+
});
|
|
448
|
+
if (!res.ok) await handleApiError(res);
|
|
449
|
+
return res.json();
|
|
450
|
+
}
|
|
451
|
+
async patch(path, body) {
|
|
452
|
+
const res = await fetch(`${this.config.apiUrl}${path}`, {
|
|
453
|
+
method: "PATCH",
|
|
454
|
+
headers: this.config.headers,
|
|
455
|
+
body: JSON.stringify(body)
|
|
456
|
+
});
|
|
457
|
+
if (!res.ok) await handleApiError(res);
|
|
458
|
+
return res.json();
|
|
459
|
+
}
|
|
460
|
+
async delete(path, body) {
|
|
461
|
+
const res = await fetch(`${this.config.apiUrl}${path}`, {
|
|
462
|
+
method: "DELETE",
|
|
463
|
+
headers: this.config.headers,
|
|
464
|
+
body: body !== void 0 ? JSON.stringify(body) : void 0
|
|
465
|
+
});
|
|
466
|
+
if (!res.ok) await handleApiError(res);
|
|
467
|
+
if (res.status === 204 || res.headers.get("content-length") === "0") return void 0;
|
|
468
|
+
return res.json();
|
|
469
|
+
}
|
|
470
|
+
async postForm(path, form) {
|
|
471
|
+
const headers = { "X-API-Key": this.config.apiKey };
|
|
472
|
+
const res = await fetch(`${this.config.apiUrl}${path}`, {
|
|
473
|
+
method: "POST",
|
|
474
|
+
headers,
|
|
475
|
+
body: form
|
|
476
|
+
});
|
|
477
|
+
if (!res.ok) await handleApiError(res);
|
|
478
|
+
return res.json();
|
|
479
|
+
}
|
|
480
|
+
/** Stream SSE events from a path, calling handler for each data line. */
|
|
481
|
+
async *streamSse(path) {
|
|
482
|
+
const res = await fetch(`${this.config.apiUrl}${path}`, {
|
|
483
|
+
headers: this.config.headers
|
|
484
|
+
});
|
|
485
|
+
if (!res.ok) await handleApiError(res);
|
|
486
|
+
if (!res.body) return;
|
|
487
|
+
const reader = res.body.getReader();
|
|
488
|
+
const decoder = new TextDecoder();
|
|
489
|
+
let buf = "";
|
|
490
|
+
while (true) {
|
|
491
|
+
const { done, value } = await reader.read();
|
|
492
|
+
if (done) break;
|
|
493
|
+
buf += decoder.decode(value, { stream: true });
|
|
494
|
+
const events = buf.split("\n\n");
|
|
495
|
+
buf = events.pop();
|
|
496
|
+
for (const evt of events) {
|
|
497
|
+
const dataLine = evt.split("\n").find((l) => l.startsWith("data: "));
|
|
498
|
+
if (dataLine) yield dataLine.slice(6);
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
};
|
|
503
|
+
|
|
504
|
+
// src/platform/projects.ts
|
|
505
|
+
var ProjectsAPI = class {
|
|
506
|
+
constructor(client) {
|
|
507
|
+
this.client = client;
|
|
508
|
+
}
|
|
509
|
+
/** List all projects the API key can access. */
|
|
510
|
+
list(opts) {
|
|
511
|
+
const qs = opts?.workspaceId ? `?workspaceId=${opts.workspaceId}` : "";
|
|
512
|
+
return this.client.get(`/api/projects${qs}`);
|
|
513
|
+
}
|
|
514
|
+
/** Get a project by ID. */
|
|
515
|
+
get(id) {
|
|
516
|
+
return this.client.get(`/api/projects/${id}`);
|
|
517
|
+
}
|
|
518
|
+
/** Create a new project. */
|
|
519
|
+
create(opts) {
|
|
520
|
+
return this.client.post("/api/projects", opts);
|
|
521
|
+
}
|
|
522
|
+
/** Update a project's name. */
|
|
523
|
+
update(id, opts) {
|
|
524
|
+
return this.client.patch(`/api/projects/${id}`, opts);
|
|
525
|
+
}
|
|
526
|
+
/** Delete a project. */
|
|
527
|
+
delete(id) {
|
|
528
|
+
return this.client.delete(`/api/projects/${id}`);
|
|
529
|
+
}
|
|
530
|
+
};
|
|
531
|
+
|
|
532
|
+
// src/platform/services.ts
|
|
533
|
+
var DeployHandle = class {
|
|
534
|
+
constructor(client, serviceId, buildId) {
|
|
535
|
+
this._client = client;
|
|
536
|
+
this._serviceId = serviceId;
|
|
537
|
+
this._buildId = buildId;
|
|
538
|
+
}
|
|
539
|
+
get serviceId() {
|
|
540
|
+
return this._serviceId;
|
|
541
|
+
}
|
|
542
|
+
/** Stream build + runtime log lines until the deploy finishes. */
|
|
543
|
+
async *logs() {
|
|
544
|
+
const path = `/api/apps/${this._serviceId}/logs?limit=1000`;
|
|
545
|
+
const res = await fetch(`${this._client.config.apiUrl}${path}`, {
|
|
546
|
+
headers: this._client.config.headers
|
|
547
|
+
});
|
|
548
|
+
if (!res.ok) return;
|
|
549
|
+
const body = await res.json();
|
|
550
|
+
const lines = Array.isArray(body) ? body : body.logs ?? [];
|
|
551
|
+
for (const l of lines) yield typeof l === "string" ? l : JSON.stringify(l);
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* Poll until the deploy reaches a terminal state.
|
|
555
|
+
* @returns `{ url, status }` on success; throws `LizardError` on failure.
|
|
556
|
+
*/
|
|
557
|
+
async wait(opts) {
|
|
558
|
+
const deadline = Date.now() + (opts?.timeoutMs ?? 10 * 6e4);
|
|
559
|
+
const pollMs = opts?.pollMs ?? 3e3;
|
|
560
|
+
while (Date.now() < deadline) {
|
|
561
|
+
const svc = await this._client.get(`/api/apps/${this._serviceId}`);
|
|
562
|
+
if (svc.deployStatus === "idle") {
|
|
563
|
+
if (svc.status === "running") return { url: svc.domain ? `https://${svc.domain}` : null, status: "running" };
|
|
564
|
+
if (svc.status === "crashed") throw new LizardError(`Service crashed after deploy`);
|
|
565
|
+
}
|
|
566
|
+
if (svc.deployStatus === "failed") throw new LizardError(`Deploy failed`);
|
|
567
|
+
await new Promise((r) => setTimeout(r, pollMs));
|
|
568
|
+
}
|
|
569
|
+
throw new TimeoutError(`Deploy did not complete within ${opts?.timeoutMs ?? 6e5}ms`);
|
|
570
|
+
}
|
|
571
|
+
};
|
|
572
|
+
var ServicesAPI = class {
|
|
573
|
+
constructor(client) {
|
|
574
|
+
this.client = client;
|
|
575
|
+
}
|
|
576
|
+
/** List all services in a project. */
|
|
577
|
+
list(opts) {
|
|
578
|
+
return this.client.get(`/api/projects/${opts.projectId}/apps`);
|
|
579
|
+
}
|
|
580
|
+
/** Get a service by ID. */
|
|
581
|
+
get(id) {
|
|
582
|
+
return this.client.get(`/api/apps/${id}`);
|
|
583
|
+
}
|
|
584
|
+
/**
|
|
585
|
+
* Create a service and start a deploy from a git repo.
|
|
586
|
+
* Returns a DeployHandle to track progress.
|
|
587
|
+
*/
|
|
588
|
+
async deploy(opts) {
|
|
589
|
+
const body = {
|
|
590
|
+
name: opts.name,
|
|
591
|
+
sourceType: opts.sourceType ?? "github",
|
|
592
|
+
repoUrl: opts.repoUrl,
|
|
593
|
+
branch: opts.branch ?? "main",
|
|
594
|
+
startCommand: opts.startCommand,
|
|
595
|
+
buildCommand: opts.buildCommand,
|
|
596
|
+
containerPort: opts.port ?? opts.containerPort,
|
|
597
|
+
region: opts.region
|
|
598
|
+
};
|
|
599
|
+
const svc = await this.client.post(`/api/projects/${opts.projectId}/apps`, body);
|
|
600
|
+
return new DeployHandle(this.client, svc.id);
|
|
601
|
+
}
|
|
602
|
+
/**
|
|
603
|
+
* Upload a tarball and deploy it.
|
|
604
|
+
*
|
|
605
|
+
* @param opts.source - A `Buffer`, `Blob`, or `Uint8Array` of a `.tar.gz` file.
|
|
606
|
+
*/
|
|
607
|
+
async upload(opts) {
|
|
608
|
+
const form = new FormData();
|
|
609
|
+
const blob = opts.source instanceof Blob ? opts.source : new Blob([opts.source], { type: "application/gzip" });
|
|
610
|
+
form.append("file", blob, "source.tar.gz");
|
|
611
|
+
form.append("name", opts.name);
|
|
612
|
+
if (opts.startCommand) form.append("startCommand", opts.startCommand);
|
|
613
|
+
if (opts.buildCommand) form.append("buildCommand", opts.buildCommand);
|
|
614
|
+
if (opts.port !== void 0) form.append("containerPort", String(opts.port));
|
|
615
|
+
if (opts.region) form.append("region", opts.region);
|
|
616
|
+
const result = await this.client.postForm(
|
|
617
|
+
`/api/projects/${opts.projectId}/apps/upload`,
|
|
618
|
+
form
|
|
619
|
+
);
|
|
620
|
+
return new DeployHandle(this.client, result.id, result.buildId);
|
|
621
|
+
}
|
|
622
|
+
/** Trigger a redeploy (rebuild from current source). */
|
|
623
|
+
async redeploy(id) {
|
|
624
|
+
await this.client.post(`/api/apps/${id}/redeploy`, {});
|
|
625
|
+
return new DeployHandle(this.client, id);
|
|
626
|
+
}
|
|
627
|
+
/** Restart a service without rebuilding. */
|
|
628
|
+
restart(id) {
|
|
629
|
+
return this.client.post(`/api/apps/${id}/restart`, {});
|
|
630
|
+
}
|
|
631
|
+
/** Scale a service. */
|
|
632
|
+
scale(id, opts) {
|
|
633
|
+
return this.client.post(`/api/apps/${id}/scale`, opts);
|
|
634
|
+
}
|
|
635
|
+
/**
|
|
636
|
+
* Get recent log lines. For a live tail, use the WebSocket API instead.
|
|
637
|
+
*
|
|
638
|
+
* @param opts.limit - Max lines to return (default 200, max 1000).
|
|
639
|
+
*/
|
|
640
|
+
async logs(id, opts) {
|
|
641
|
+
const qs = new URLSearchParams();
|
|
642
|
+
if (opts?.limit) qs.set("limit", String(opts.limit));
|
|
643
|
+
if (opts?.since) qs.set("since", opts.since);
|
|
644
|
+
const result = await this.client.get(`/api/apps/${id}/logs?${qs}`);
|
|
645
|
+
return Array.isArray(result) ? result : result.logs ?? [];
|
|
646
|
+
}
|
|
647
|
+
/** Execute a command inside the running service VM. */
|
|
648
|
+
exec(id, cmd, opts) {
|
|
649
|
+
return this.client.post(`/api/apps/${id}/exec`, { cmd, timeoutMs: opts?.timeoutMs });
|
|
650
|
+
}
|
|
651
|
+
/** Update service configuration. */
|
|
652
|
+
update(id, opts) {
|
|
653
|
+
return this.client.patch(`/api/apps/${id}`, opts);
|
|
654
|
+
}
|
|
655
|
+
/** Delete a service. */
|
|
656
|
+
delete(id) {
|
|
657
|
+
return this.client.delete(`/api/apps/${id}`);
|
|
658
|
+
}
|
|
659
|
+
};
|
|
660
|
+
|
|
661
|
+
// src/platform/addons.ts
|
|
662
|
+
var AddonsAPI = class {
|
|
663
|
+
constructor(client) {
|
|
664
|
+
this.client = client;
|
|
665
|
+
}
|
|
666
|
+
/** List all addons in a project. */
|
|
667
|
+
list(opts) {
|
|
668
|
+
return this.client.get(`/api/projects/${opts.projectId}/addons`);
|
|
669
|
+
}
|
|
670
|
+
/** Get an addon by ID. */
|
|
671
|
+
get(projectId, addonId) {
|
|
672
|
+
return this.client.get(`/api/projects/${projectId}/addons/${addonId}`);
|
|
673
|
+
}
|
|
674
|
+
/**
|
|
675
|
+
* Create a new managed addon (database, cache, or object store).
|
|
676
|
+
*
|
|
677
|
+
* @example
|
|
678
|
+
* ```ts
|
|
679
|
+
* const pg = await lizard.addons.create({ projectId, type: 'postgres' })
|
|
680
|
+
* // Inject into a service:
|
|
681
|
+
* await lizard.secrets.set({ serviceId: svcId, key: 'DATABASE_URL', value: `${{${pg.name}.DATABASE_URL}}` })
|
|
682
|
+
* ```
|
|
683
|
+
*/
|
|
684
|
+
create(opts) {
|
|
685
|
+
return this.client.post(`/api/projects/${opts.projectId}/addons`, {
|
|
686
|
+
type: opts.type,
|
|
687
|
+
name: opts.name,
|
|
688
|
+
version: opts.version,
|
|
689
|
+
vcpu: opts.vcpu,
|
|
690
|
+
memoryMb: opts.memoryMb,
|
|
691
|
+
storageGb: opts.storageGb
|
|
692
|
+
});
|
|
693
|
+
}
|
|
694
|
+
/** Delete an addon. */
|
|
695
|
+
delete(projectId, addonId) {
|
|
696
|
+
return this.client.delete(`/api/projects/${projectId}/addons/${addonId}`);
|
|
697
|
+
}
|
|
698
|
+
/** Resize an addon (CPU / memory / storage). */
|
|
699
|
+
resize(projectId, addonId, opts) {
|
|
700
|
+
return this.client.post(`/api/projects/${projectId}/addons/${addonId}/resize`, opts);
|
|
701
|
+
}
|
|
702
|
+
/** Restart an addon VM. */
|
|
703
|
+
redeploy(projectId, addonId) {
|
|
704
|
+
return this.client.post(`/api/projects/${projectId}/addons/${addonId}/redeploy`, {});
|
|
705
|
+
}
|
|
706
|
+
};
|
|
707
|
+
|
|
708
|
+
// src/platform/secrets.ts
|
|
709
|
+
var SecretsAPI = class {
|
|
710
|
+
constructor(client) {
|
|
711
|
+
this.client = client;
|
|
712
|
+
}
|
|
713
|
+
/**
|
|
714
|
+
* List secrets for a project or service.
|
|
715
|
+
*
|
|
716
|
+
* @param projectId - The project ID.
|
|
717
|
+
* @param opts.serviceId - If given, list service-scoped secrets instead of project secrets.
|
|
718
|
+
*/
|
|
719
|
+
list(projectId, opts) {
|
|
720
|
+
if (opts?.serviceId) {
|
|
721
|
+
return this.client.get(`/api/apps/${opts.serviceId}/secrets`);
|
|
722
|
+
}
|
|
723
|
+
return this.client.get(`/api/projects/${projectId}/secrets`);
|
|
724
|
+
}
|
|
725
|
+
/**
|
|
726
|
+
* Set one or more secrets.
|
|
727
|
+
*
|
|
728
|
+
* ```ts
|
|
729
|
+
* // Service-scoped secret (default):
|
|
730
|
+
* await lizard.secrets.set(projectId, { key: 'DATABASE_URL', value: '${{postgres.DATABASE_URL}}', serviceId })
|
|
731
|
+
*
|
|
732
|
+
* // Project-scoped (shared across all services):
|
|
733
|
+
* await lizard.secrets.set(projectId, { key: 'LOG_LEVEL', value: 'info', global: true })
|
|
734
|
+
* ```
|
|
735
|
+
*/
|
|
736
|
+
async set(projectId, secrets) {
|
|
737
|
+
const items = Array.isArray(secrets) ? secrets : [secrets];
|
|
738
|
+
const byService = /* @__PURE__ */ new Map();
|
|
739
|
+
const projectScoped = {};
|
|
740
|
+
for (const s of items) {
|
|
741
|
+
if (s.global || !s.serviceId) {
|
|
742
|
+
projectScoped[s.key] = s.value;
|
|
743
|
+
} else {
|
|
744
|
+
if (!byService.has(s.serviceId)) byService.set(s.serviceId, {});
|
|
745
|
+
byService.get(s.serviceId)[s.key] = s.value;
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
const tasks = [];
|
|
749
|
+
if (Object.keys(projectScoped).length > 0) {
|
|
750
|
+
tasks.push(this.client.post(`/api/projects/${projectId}/secrets`, projectScoped));
|
|
751
|
+
}
|
|
752
|
+
for (const [serviceId, kv] of byService) {
|
|
753
|
+
tasks.push(this.client.post(`/api/apps/${serviceId}/secrets`, kv));
|
|
754
|
+
}
|
|
755
|
+
await Promise.all(tasks);
|
|
756
|
+
}
|
|
757
|
+
/** Delete a secret by key. */
|
|
758
|
+
async delete(projectId, opts) {
|
|
759
|
+
if (opts.serviceId) {
|
|
760
|
+
await this.client.delete(`/api/apps/${opts.serviceId}/secrets`, { key: opts.key });
|
|
761
|
+
} else {
|
|
762
|
+
await this.client.delete(`/api/projects/${projectId}/secrets`, { key: opts.key });
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
};
|
|
766
|
+
|
|
767
|
+
// src/platform/domains.ts
|
|
768
|
+
var DomainsAPI = class {
|
|
769
|
+
constructor(client) {
|
|
770
|
+
this.client = client;
|
|
771
|
+
}
|
|
772
|
+
/**
|
|
773
|
+
* Show the current domain(s) for a service.
|
|
774
|
+
* The platform-assigned `.onlizard.com` subdomain is always present.
|
|
775
|
+
*/
|
|
776
|
+
list(serviceId) {
|
|
777
|
+
return this.client.get(`/api/apps/${serviceId}/domains`);
|
|
778
|
+
}
|
|
779
|
+
/**
|
|
780
|
+
* Attach a custom domain to a service.
|
|
781
|
+
* Returns the DNS records to add before calling `verify()`.
|
|
782
|
+
*
|
|
783
|
+
* @example
|
|
784
|
+
* ```ts
|
|
785
|
+
* const info = await lizard.domains.add(serviceId, 'api.example.com')
|
|
786
|
+
* console.log('Add CNAME:', info.cnameTarget)
|
|
787
|
+
* ```
|
|
788
|
+
*/
|
|
789
|
+
add(serviceId, domain) {
|
|
790
|
+
return this.client.post(`/api/apps/${serviceId}/domains`, { domain });
|
|
791
|
+
}
|
|
792
|
+
/**
|
|
793
|
+
* Verify that DNS records have propagated and activate the domain.
|
|
794
|
+
* Call after adding the CNAME or TXT record returned by `add()`.
|
|
795
|
+
*/
|
|
796
|
+
verify(serviceId, domain) {
|
|
797
|
+
return this.client.post(`/api/apps/${serviceId}/domains/verify`, { domain });
|
|
798
|
+
}
|
|
799
|
+
};
|
|
800
|
+
|
|
801
|
+
// src/platform/metrics.ts
|
|
802
|
+
var MetricsAPI = class {
|
|
803
|
+
constructor(client) {
|
|
804
|
+
this.client = client;
|
|
805
|
+
}
|
|
806
|
+
/** Get CPU metrics for a service or addon. */
|
|
807
|
+
cpu(id, range = "1h") {
|
|
808
|
+
return this.client.get(`/api/apps/${id}/metrics/cpu?range=${range}`);
|
|
809
|
+
}
|
|
810
|
+
/** Get memory metrics for a service or addon. */
|
|
811
|
+
memory(id, range = "1h") {
|
|
812
|
+
return this.client.get(`/api/apps/${id}/metrics/memory?range=${range}`);
|
|
813
|
+
}
|
|
814
|
+
/** Get network I/O metrics for a service. */
|
|
815
|
+
network(id, range = "1h") {
|
|
816
|
+
return this.client.get(`/api/apps/${id}/metrics/network?range=${range}`);
|
|
817
|
+
}
|
|
818
|
+
/** Get disk I/O metrics for a service. */
|
|
819
|
+
disk(id, range = "1h") {
|
|
820
|
+
return this.client.get(`/api/apps/${id}/metrics/disk?range=${range}`);
|
|
821
|
+
}
|
|
822
|
+
/**
|
|
823
|
+
* Get cost breakdown for a project over the given range.
|
|
824
|
+
* Costs are in USD cents unless the `currency` field says otherwise.
|
|
825
|
+
*/
|
|
826
|
+
cost(projectId, range = "30d") {
|
|
827
|
+
return this.client.get(`/api/projects/${projectId}/metrics/cost?range=${range}`);
|
|
828
|
+
}
|
|
829
|
+
/**
|
|
830
|
+
* Convenience: fetch all metric types for a service in one call.
|
|
831
|
+
*/
|
|
832
|
+
async all(id, range = "1h") {
|
|
833
|
+
const [cpu, memory, network, disk] = await Promise.all([
|
|
834
|
+
this.cpu(id, range),
|
|
835
|
+
this.memory(id, range),
|
|
836
|
+
this.network(id, range),
|
|
837
|
+
this.disk(id, range)
|
|
838
|
+
]);
|
|
839
|
+
return { cpu, memory, networkRx: network.rx, networkTx: network.tx, diskRead: disk.read, diskWrite: disk.write };
|
|
840
|
+
}
|
|
841
|
+
};
|
|
842
|
+
|
|
425
843
|
// src/lizard.ts
|
|
426
844
|
var Lizard = class {
|
|
427
845
|
constructor(opts) {
|
|
428
|
-
if (!opts?.project) {
|
|
429
|
-
throw new LizardError(
|
|
430
|
-
'A project is required. Pass project (its ID, slug, or name): new Lizard({ project: "my-project" }).'
|
|
431
|
-
);
|
|
432
|
-
}
|
|
433
846
|
this.config = new ConnectionConfig(opts);
|
|
434
847
|
this.projectRef = opts.project;
|
|
848
|
+
const platform = new PlatformClient(opts);
|
|
849
|
+
this._platform = platform;
|
|
850
|
+
this.projects = new ProjectsAPI(platform);
|
|
851
|
+
this.services = new ServicesAPI(platform);
|
|
852
|
+
this.addons = new AddonsAPI(platform);
|
|
853
|
+
this.secrets = new SecretsAPI(platform);
|
|
854
|
+
this.domains = new DomainsAPI(platform);
|
|
855
|
+
this.metrics = new MetricsAPI(platform);
|
|
435
856
|
}
|
|
857
|
+
// ── Sandbox convenience methods (backward-compatible) ──────────────────
|
|
436
858
|
/** Resolve the client's project reference to a stable project ID (cached). */
|
|
437
859
|
async projectId() {
|
|
860
|
+
if (!this.projectRef) throw new LizardError("No project set. Pass project in Lizard({ project }) to use sandbox APIs.");
|
|
438
861
|
return resolveProjectId(this.projectRef, this.config);
|
|
439
862
|
}
|
|
440
863
|
async connectionOpts(extra) {
|
|
@@ -442,12 +865,7 @@ var Lizard = class {
|
|
|
442
865
|
}
|
|
443
866
|
/**
|
|
444
867
|
* Create a new sandbox in this client's project.
|
|
445
|
-
*
|
|
446
|
-
* @example
|
|
447
|
-
* ```ts
|
|
448
|
-
* const sandbox = await lizard.create('base')
|
|
449
|
-
* const sandbox = await lizard.create('code-interpreter-v1', { timeoutMs: 600_000 })
|
|
450
|
-
* ```
|
|
868
|
+
* @requires `project` to be set in the constructor.
|
|
451
869
|
*/
|
|
452
870
|
async create(template, opts) {
|
|
453
871
|
const projectId = await this.projectId();
|
|
@@ -705,6 +1123,7 @@ var Volume = class _Volume {
|
|
|
705
1123
|
export {
|
|
706
1124
|
AuthenticationError,
|
|
707
1125
|
CodeSandbox,
|
|
1126
|
+
DeployHandle,
|
|
708
1127
|
Lizard,
|
|
709
1128
|
LizardError,
|
|
710
1129
|
NotFoundError,
|