@lizard-build/sdk 0.1.22 → 0.1.23

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.d.mts CHANGED
@@ -327,47 +327,428 @@ declare class Sandbox extends SandboxClient {
327
327
  private resolveOpts;
328
328
  }
329
329
 
330
+ /** Shared HTTP helper for platform (non-sandbox) API calls. */
331
+ declare class PlatformClient {
332
+ readonly config: ConnectionConfig;
333
+ constructor(opts: ConnectionOpts);
334
+ get<T>(path: string): Promise<T>;
335
+ post<T>(path: string, body?: unknown): Promise<T>;
336
+ patch<T>(path: string, body: unknown): Promise<T>;
337
+ delete<T = void>(path: string, body?: unknown): Promise<T>;
338
+ postForm<T>(path: string, form: FormData): Promise<T>;
339
+ /** Stream SSE events from a path, calling handler for each data line. */
340
+ streamSse(path: string): AsyncGenerator<string>;
341
+ }
342
+
343
+ interface Project {
344
+ id: string;
345
+ name: string;
346
+ slug: string;
347
+ workspaceId: string;
348
+ createdAt?: string;
349
+ }
350
+ interface CreateProjectOpts {
351
+ workspaceId: string;
352
+ name: string;
353
+ }
354
+ declare class ProjectsAPI {
355
+ private readonly client;
356
+ constructor(client: PlatformClient);
357
+ /** List all projects the API key can access. */
358
+ list(opts?: {
359
+ workspaceId?: string;
360
+ }): Promise<Project[]>;
361
+ /** Get a project by ID. */
362
+ get(id: string): Promise<Project>;
363
+ /** Create a new project. */
364
+ create(opts: CreateProjectOpts): Promise<Project>;
365
+ /** Update a project's name. */
366
+ update(id: string, opts: {
367
+ name?: string;
368
+ }): Promise<Project>;
369
+ /** Delete a project. */
370
+ delete(id: string): Promise<void>;
371
+ }
372
+
373
+ interface Service {
374
+ id: string;
375
+ name: string;
376
+ projectId: string;
377
+ status: 'none' | 'running' | 'crashed' | 'stopped';
378
+ deployStatus: 'idle' | 'building' | 'deploying' | 'restarting' | 'failed' | 'deleting';
379
+ domain?: string;
380
+ region?: string;
381
+ sourceType?: 'github' | 'upload';
382
+ repoUrl?: string;
383
+ branch?: string;
384
+ startCommand?: string;
385
+ buildCommand?: string;
386
+ containerPort?: number;
387
+ }
388
+ interface CreateServiceOpts {
389
+ projectId: string;
390
+ name: string;
391
+ sourceType?: 'github' | 'upload';
392
+ repoUrl?: string;
393
+ branch?: string;
394
+ startCommand?: string;
395
+ buildCommand?: string;
396
+ containerPort?: number;
397
+ region?: string;
398
+ /** Set to 0 for worker mode (no HTTP listener). */
399
+ port?: number;
400
+ }
401
+ interface ScaleOpts {
402
+ replicas?: number;
403
+ cpuMillis?: number;
404
+ memoryMi?: number;
405
+ storageMi?: number;
406
+ }
407
+ interface LogLine {
408
+ level: 'info' | 'error' | 'warn' | 'debug';
409
+ message: string;
410
+ ts: number;
411
+ service?: string;
412
+ replica?: string;
413
+ }
414
+ interface DeployEvent {
415
+ event: 'log' | 'done' | 'error' | 'deployed' | 'failed' | 'deploying';
416
+ line?: string;
417
+ message?: string;
418
+ status?: string;
419
+ url?: string | null;
420
+ }
421
+ /**
422
+ * Handle for a running deploy — stream its logs or await completion.
423
+ *
424
+ * @example
425
+ * ```ts
426
+ * const deploy = await lizard.services.upload({ projectId, source: fs.readFileSync('app.tar.gz') })
427
+ * for await (const line of deploy.logs()) console.log(line)
428
+ * const result = await deploy.wait()
429
+ * console.log('deployed to', result.url)
430
+ * ```
431
+ */
432
+ declare class DeployHandle {
433
+ private readonly _serviceId;
434
+ private readonly _buildId;
435
+ private readonly _client;
436
+ constructor(client: PlatformClient, serviceId: string, buildId?: string);
437
+ get serviceId(): string;
438
+ /** Stream build + runtime log lines until the deploy finishes. */
439
+ logs(): AsyncGenerator<string>;
440
+ /**
441
+ * Poll until the deploy reaches a terminal state.
442
+ * @returns `{ url, status }` on success; throws `LizardError` on failure.
443
+ */
444
+ wait(opts?: {
445
+ timeoutMs?: number;
446
+ pollMs?: number;
447
+ }): Promise<{
448
+ url: string | null;
449
+ status: string;
450
+ }>;
451
+ }
452
+ declare class ServicesAPI {
453
+ private readonly client;
454
+ constructor(client: PlatformClient);
455
+ /** List all services in a project. */
456
+ list(opts: {
457
+ projectId: string;
458
+ }): Promise<Service[]>;
459
+ /** Get a service by ID. */
460
+ get(id: string): Promise<Service>;
461
+ /**
462
+ * Create a service and start a deploy from a git repo.
463
+ * Returns a DeployHandle to track progress.
464
+ */
465
+ deploy(opts: CreateServiceOpts & {
466
+ waitForDeploy?: boolean;
467
+ }): Promise<DeployHandle>;
468
+ /**
469
+ * Upload a tarball and deploy it.
470
+ *
471
+ * @param opts.source - A `Buffer`, `Blob`, or `Uint8Array` of a `.tar.gz` file.
472
+ */
473
+ upload(opts: {
474
+ projectId: string;
475
+ name: string;
476
+ source: Blob | string;
477
+ startCommand?: string;
478
+ buildCommand?: string;
479
+ port?: number;
480
+ region?: string;
481
+ }): Promise<DeployHandle>;
482
+ /** Trigger a redeploy (rebuild from current source). */
483
+ redeploy(id: string): Promise<DeployHandle>;
484
+ /** Restart a service without rebuilding. */
485
+ restart(id: string): Promise<void>;
486
+ /** Scale a service. */
487
+ scale(id: string, opts: ScaleOpts): Promise<void>;
488
+ /**
489
+ * Get recent log lines. For a live tail, use the WebSocket API instead.
490
+ *
491
+ * @param opts.limit - Max lines to return (default 200, max 1000).
492
+ */
493
+ logs(id: string, opts?: {
494
+ limit?: number;
495
+ since?: string;
496
+ }): Promise<LogLine[]>;
497
+ /** Execute a command inside the running service VM. */
498
+ exec(id: string, cmd: string, opts?: {
499
+ timeoutMs?: number;
500
+ }): Promise<{
501
+ stdout: string;
502
+ stderr: string;
503
+ exitCode: number;
504
+ }>;
505
+ /** Update service configuration. */
506
+ update(id: string, opts: Partial<Pick<Service, 'name' | 'startCommand' | 'buildCommand' | 'containerPort' | 'repoUrl' | 'branch' | 'sourceType'>>): Promise<Service>;
507
+ /** Delete a service. */
508
+ delete(id: string): Promise<void>;
509
+ }
510
+
511
+ type AddonType = 'postgres' | 'mysql' | 'mongodb' | 'redis' | 's3';
512
+ interface Addon {
513
+ id: string;
514
+ name: string;
515
+ type: AddonType;
516
+ projectId: string;
517
+ status: 'none' | 'running' | 'crashed' | 'stopped';
518
+ deployStatus: string;
519
+ version?: string;
520
+ /** Exposed connection variables (e.g. DATABASE_URL, REDIS_URL). */
521
+ env?: Record<string, string>;
522
+ }
523
+ interface CreateAddonOpts {
524
+ projectId: string;
525
+ type: AddonType;
526
+ name?: string;
527
+ version?: string;
528
+ /** vCPU count */
529
+ vcpu?: number;
530
+ /** Memory in MB */
531
+ memoryMb?: number;
532
+ /** Storage in GB */
533
+ storageGb?: number;
534
+ }
535
+ declare class AddonsAPI {
536
+ private readonly client;
537
+ constructor(client: PlatformClient);
538
+ /** List all addons in a project. */
539
+ list(opts: {
540
+ projectId: string;
541
+ }): Promise<Addon[]>;
542
+ /** Get an addon by ID. */
543
+ get(projectId: string, addonId: string): Promise<Addon>;
544
+ /**
545
+ * Create a new managed addon (database, cache, or object store).
546
+ *
547
+ * @example
548
+ * ```ts
549
+ * const pg = await lizard.addons.create({ projectId, type: 'postgres' })
550
+ * // Inject into a service:
551
+ * await lizard.secrets.set({ serviceId: svcId, key: 'DATABASE_URL', value: `${{${pg.name}.DATABASE_URL}}` })
552
+ * ```
553
+ */
554
+ create(opts: CreateAddonOpts): Promise<Addon>;
555
+ /** Delete an addon. */
556
+ delete(projectId: string, addonId: string): Promise<void>;
557
+ /** Resize an addon (CPU / memory / storage). */
558
+ resize(projectId: string, addonId: string, opts: {
559
+ vcpu?: number;
560
+ memoryMb?: number;
561
+ storageGb?: number;
562
+ }): Promise<Addon>;
563
+ /** Restart an addon VM. */
564
+ redeploy(projectId: string, addonId: string): Promise<void>;
565
+ }
566
+
567
+ interface Secret {
568
+ key: string;
569
+ value: string;
570
+ }
571
+ interface SetSecretOpts {
572
+ key: string;
573
+ value: string;
574
+ /** Target a specific service. Omit for project-scope. */
575
+ serviceId?: string;
576
+ /** If true, set at project scope (shared across all services). */
577
+ global?: boolean;
578
+ }
579
+ interface ListSecretsOpts {
580
+ serviceId?: string;
581
+ }
582
+ declare class SecretsAPI {
583
+ private readonly client;
584
+ constructor(client: PlatformClient);
585
+ /**
586
+ * List secrets for a project or service.
587
+ *
588
+ * @param projectId - The project ID.
589
+ * @param opts.serviceId - If given, list service-scoped secrets instead of project secrets.
590
+ */
591
+ list(projectId: string, opts?: ListSecretsOpts): Promise<Secret[]>;
592
+ /**
593
+ * Set one or more secrets.
594
+ *
595
+ * ```ts
596
+ * // Service-scoped secret (default):
597
+ * await lizard.secrets.set(projectId, { key: 'DATABASE_URL', value: '${{postgres.DATABASE_URL}}', serviceId })
598
+ *
599
+ * // Project-scoped (shared across all services):
600
+ * await lizard.secrets.set(projectId, { key: 'LOG_LEVEL', value: 'info', global: true })
601
+ * ```
602
+ */
603
+ set(projectId: string, secrets: SetSecretOpts | SetSecretOpts[]): Promise<void>;
604
+ /** Delete a secret by key. */
605
+ delete(projectId: string, opts: {
606
+ key: string;
607
+ serviceId?: string;
608
+ }): Promise<void>;
609
+ }
610
+
611
+ interface DomainInfo {
612
+ domain: string;
613
+ /** 'pending' until DNS propagates and the platform verifies the CNAME/TXT record. */
614
+ verified: boolean;
615
+ txtRecord?: string;
616
+ cnameTarget?: string;
617
+ }
618
+ declare class DomainsAPI {
619
+ private readonly client;
620
+ constructor(client: PlatformClient);
621
+ /**
622
+ * Show the current domain(s) for a service.
623
+ * The platform-assigned `.onlizard.com` subdomain is always present.
624
+ */
625
+ list(serviceId: string): Promise<DomainInfo[]>;
626
+ /**
627
+ * Attach a custom domain to a service.
628
+ * Returns the DNS records to add before calling `verify()`.
629
+ *
630
+ * @example
631
+ * ```ts
632
+ * const info = await lizard.domains.add(serviceId, 'api.example.com')
633
+ * console.log('Add CNAME:', info.cnameTarget)
634
+ * ```
635
+ */
636
+ add(serviceId: string, domain: string): Promise<DomainInfo>;
637
+ /**
638
+ * Verify that DNS records have propagated and activate the domain.
639
+ * Call after adding the CNAME or TXT record returned by `add()`.
640
+ */
641
+ verify(serviceId: string, domain: string): Promise<DomainInfo>;
642
+ }
643
+
644
+ type MetricRange = '1h' | '6h' | '24h' | '7d' | '14d' | '30d';
645
+ interface MetricPoint {
646
+ t: number;
647
+ value: number;
648
+ }
649
+ interface ServiceMetrics {
650
+ cpu: MetricPoint[];
651
+ memory: MetricPoint[];
652
+ networkRx: MetricPoint[];
653
+ networkTx: MetricPoint[];
654
+ diskRead: MetricPoint[];
655
+ diskWrite: MetricPoint[];
656
+ }
657
+ interface CostMetrics {
658
+ compute: number;
659
+ egress: number;
660
+ storage: number;
661
+ total: number;
662
+ currency: string;
663
+ }
664
+ declare class MetricsAPI {
665
+ private readonly client;
666
+ constructor(client: PlatformClient);
667
+ /** Get CPU metrics for a service or addon. */
668
+ cpu(id: string, range?: MetricRange): Promise<MetricPoint[]>;
669
+ /** Get memory metrics for a service or addon. */
670
+ memory(id: string, range?: MetricRange): Promise<MetricPoint[]>;
671
+ /** Get network I/O metrics for a service. */
672
+ network(id: string, range?: MetricRange): Promise<{
673
+ rx: MetricPoint[];
674
+ tx: MetricPoint[];
675
+ }>;
676
+ /** Get disk I/O metrics for a service. */
677
+ disk(id: string, range?: MetricRange): Promise<{
678
+ read: MetricPoint[];
679
+ write: MetricPoint[];
680
+ }>;
681
+ /**
682
+ * Get cost breakdown for a project over the given range.
683
+ * Costs are in USD cents unless the `currency` field says otherwise.
684
+ */
685
+ cost(projectId: string, range?: MetricRange): Promise<CostMetrics>;
686
+ /**
687
+ * Convenience: fetch all metric types for a service in one call.
688
+ */
689
+ all(id: string, range?: MetricRange): Promise<ServiceMetrics>;
690
+ }
691
+
330
692
  interface LizardOpts extends ConnectionOpts {
331
693
  /**
332
694
  * The project every sandbox created through this client belongs to — its ID,
333
- * slug, or name. Required: sandboxes are billed per project, so a project-less
334
- * sandbox cannot be created.
695
+ * slug, or name. Required for sandbox operations; optional for platform
696
+ * management (projects, services, addons, etc.).
335
697
  */
336
- project: string;
698
+ project?: string;
337
699
  }
338
700
  /**
339
- * The Lizard client — the entry point for creating sandboxes.
701
+ * The Lizard client — entry point for sandboxes and platform management.
340
702
  *
341
- * A client is pinned to one project (billing is metered per project), so every
342
- * sandbox it creates is attributed correctly. The project reference — ID, slug,
343
- * or name — is resolved to a project ID on first use and cached.
344
- *
345
- * @example
703
+ * @example Sandbox usage (backward-compatible)
346
704
  * ```ts
347
- * import { Lizard } from '@lizard-build/sdk'
348
- *
349
- * const lizard = new Lizard({ project: 'my-project' }) // apiKey from LIZARD_API_KEY
350
- *
705
+ * const lizard = new Lizard({ project: 'my-project' })
351
706
  * const sandbox = await lizard.create('base')
352
707
  * await sandbox.process.exec('echo hello')
353
708
  * await sandbox.kill()
354
709
  * ```
710
+ *
711
+ * @example Platform management
712
+ * ```ts
713
+ * const lizard = new Lizard({ apiKey: process.env.LIZARD_API_KEY })
714
+ *
715
+ * // Deploy from git
716
+ * const deploy = await lizard.services.deploy({ projectId, name: 'api', repoUrl: '...', branch: 'main' })
717
+ * const result = await deploy.wait()
718
+ * console.log('Deployed to', result.url)
719
+ *
720
+ * // Add a Postgres addon and wire it to the service
721
+ * const pg = await lizard.addons.create({ projectId, type: 'postgres' })
722
+ * await lizard.secrets.set(projectId, {
723
+ * serviceId: result.serviceId,
724
+ * key: 'DATABASE_URL',
725
+ * value: `${{${pg.name}.DATABASE_URL}}`,
726
+ * })
727
+ * ```
355
728
  */
356
729
  declare class Lizard {
357
730
  private readonly config;
358
731
  private readonly projectRef;
732
+ private _platform;
733
+ /** Manage projects. */
734
+ readonly projects: ProjectsAPI;
735
+ /** Deploy and manage services. */
736
+ readonly services: ServicesAPI;
737
+ /** Manage addons (postgres, redis, s3, mysql, mongodb). */
738
+ readonly addons: AddonsAPI;
739
+ /** Manage secrets and environment variables. */
740
+ readonly secrets: SecretsAPI;
741
+ /** Manage custom domains. */
742
+ readonly domains: DomainsAPI;
743
+ /** Query CPU, memory, network, disk, and cost metrics. */
744
+ readonly metrics: MetricsAPI;
359
745
  constructor(opts: LizardOpts);
360
746
  /** Resolve the client's project reference to a stable project ID (cached). */
361
747
  projectId(): Promise<string>;
362
748
  private connectionOpts;
363
749
  /**
364
750
  * Create a new sandbox in this client's project.
365
- *
366
- * @example
367
- * ```ts
368
- * const sandbox = await lizard.create('base')
369
- * const sandbox = await lizard.create('code-interpreter-v1', { timeoutMs: 600_000 })
370
- * ```
751
+ * @requires `project` to be set in the constructor.
371
752
  */
372
753
  create(template?: string, opts?: Omit<SandboxOpts, 'project' | 'projectId'>): Promise<Sandbox>;
373
754
  /** Connect to an existing sandbox by ID (resumes it if paused). */
@@ -578,4 +959,4 @@ declare class Volume {
578
959
  delete(projectId: string): Promise<void>;
579
960
  }
580
961
 
581
- export { AuthenticationError, type CodeContext, CodeSandbox, type ConnectionOpts, type CreateContextOpts, type CreateVolumeOpts, Execution, ExecutionError, type FileInfo, type FsOpts, Lizard, LizardError, type LizardOpts, NotFoundError, type ProcessOpts, type ProcessResult, type RunCodeLanguage, type RunCodeOpts, Sandbox, type SandboxInfo, type SandboxOpts, TimeoutError, Volume, type VolumeInfo, resolveProjectId };
962
+ export { type Addon, type AddonType, AuthenticationError, type CodeContext, CodeSandbox, type ConnectionOpts, type CostMetrics, type CreateAddonOpts, type CreateContextOpts, type CreateProjectOpts, type CreateServiceOpts, type CreateVolumeOpts, type DeployEvent, DeployHandle, type DomainInfo, Execution, ExecutionError, type FileInfo, type FsOpts, Lizard, LizardError, type LizardOpts, type LogLine, type MetricPoint, type MetricRange, NotFoundError, type ProcessOpts, type ProcessResult, type Project, type RunCodeLanguage, type RunCodeOpts, Sandbox, type SandboxInfo, type SandboxOpts, type ScaleOpts, type Secret, type Service, type ServiceMetrics, type SetSecretOpts, TimeoutError, Volume, type VolumeInfo, resolveProjectId };