@machine0/sdk 0.1.0 → 0.2.0

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/client.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { ActionResult, Image, ImageDetail, Machine, MachineCreated, MachineCreateInput, MachineDetail, MachineMetrics, MachineMetricsRange, MachineUpdateInput, SshKey, SshKeyCreated, SshKeyCreatedManaged, SshKeyCreateInput, SshKeyWithFile } from "./types.js";
1
+ import type { ActionResult, ImageDetail, ImageListItem, Machine, MachineCreated, MachineCreateInput, MachineDetail, MachineMetrics, MachineMetricsRange, MachineUpdateInput, SshKey, SshKeyCreated, SshKeyCreatedManaged, SshKeyCreateInput, SshKeyWithFile } from "./types.js";
2
2
  export interface Machine0ClientOptions {
3
3
  /** machine0 API key (dashboard → Account → API Tokens, https://app.machine0.io/account/tokens). Sent as the `x-api-key` header. */
4
4
  apiKey: string;
@@ -51,7 +51,7 @@ export declare function createClient(options: Machine0ClientOptions): {
51
51
  }) => Promise<MachineMetrics>;
52
52
  };
53
53
  images: {
54
- list: () => Promise<Image[]>;
54
+ list: () => Promise<ImageListItem[]>;
55
55
  get: (input: {
56
56
  id: string;
57
57
  }) => Promise<ImageDetail>;
package/dist/types.d.ts CHANGED
@@ -7,14 +7,23 @@
7
7
  * INPUT types stay closed unions (the server validates them).
8
8
  */
9
9
  export type Open<T extends string> = T | (string & {});
10
- export type MachineStatus = "DESTROYED" | "CREATING" | "RUNNING" | "STARTING" | "STOPPING" | "STOPPED" | "RESTARTING" | "ERRORED" | "SUSPENDING" | "SUSPENDED" | "UNAVAILABLE";
10
+ export type MachineStatus = "DESTROYED" | "CREATING" | "RUNNING" | "STARTING" | "STOPPING" | "STOPPED" | "RESTARTING" | "ERRORED" | "SUSPENDING" | "SUSPENDED" | "UNAVAILABLE" | "ORDERED";
11
11
  export type MachineSize = "small" | "medium" | "large" | "xl" | "xxl" | "large-nvme" | "xl-nvme" | "xxl-nvme" | "xl-premium" | "xxl-premium" | "xxxl" | "4xl" | "5xl" | "6xl" | "gpu-4000ada-1" | "gpu-l40s-1" | "gpu-6000ada-1" | "gpu-mi300x-1" | "gpu-h100-1" | "gpu-h200-1" | "gpu-mi300x-8" | "gpu-h100-8" | "gpu-h200-8";
12
- export type MachineRegion = "us-east" | "us-west" | "uk" | "eu" | "asia";
12
+ /** Datacenter slugs (region IS the datacenter since the region flip). */
13
+ export type MachineRegion = "nyc3" | "sfo3" | "lon1" | "ams3" | "sgp1" | "tor1" | "nyc2" | "atl1" | "fra1";
14
+ /**
15
+ * Legacy region aliases still accepted on input, normalized server-side to
16
+ * their historical primary datacenter (us/us-east→nyc3, us-west→sfo3,
17
+ * uk→lon1, eu→ams3, asia→sgp1).
18
+ */
19
+ export type LegacyMachineRegion = "us" | "us-east" | "us-west" | "uk" | "eu" | "asia";
13
20
  export type Distribution = "ubuntu" | "nixos";
14
21
  export type ImageStatus = "DESTROYED" | "CREATING" | "READY" | "TRANSFERRING" | "ERRORED";
15
22
  export type ImageType = "USER" | "SYSTEM";
16
23
  export type SshKeyType = "MANAGED" | "PUBLIC";
17
24
  export type MachineMetricsRange = "1h" | "24h" | "7d";
25
+ /** Idle-detection action: what the server does after sustained inactivity. */
26
+ export type MachineOnIdleAction = "suspend" | "destroy" | "none";
18
27
  /** Machine as returned by `machines.list`. */
19
28
  export interface Machine {
20
29
  id: string;
@@ -35,6 +44,16 @@ export interface Machine {
35
44
  totalCost: number | null;
36
45
  pricePerHour: number | null;
37
46
  metricsEnabled: boolean;
47
+ /** Idle-detection action; `"none"` = disabled. */
48
+ onIdle: Open<MachineOnIdleAction>;
49
+ /** Sustained-inactivity window (minutes) before `onIdle` fires. */
50
+ idleTimeoutMinutes: number;
51
+ /**
52
+ * Standing-order deadline (`machine0 order`): set while the machine is an
53
+ * ORDERED (or expired) order, cleared once the order fills. Null for
54
+ * machines created directly.
55
+ */
56
+ orderExpiresAt: string | null;
38
57
  }
39
58
  /**
40
59
  * Machine as returned by `machines.create`. The create path responds from
@@ -42,7 +61,17 @@ export interface Machine {
42
61
  * `distribution` are absent — fetch the machine (`machines.get`) if you need
43
62
  * them immediately after creation.
44
63
  */
45
- export type MachineCreated = Omit<Machine, "image" | "distribution">;
64
+ export type MachineCreated = Omit<Machine, "image" | "distribution"> & {
65
+ /**
66
+ * Whether a supplied `env` map was applied: `true` when `env` was passed and
67
+ * honored, `false` when no `env` was passed. Always present on a server that
68
+ * supports env overrides. A server that predates env support OMITS this field
69
+ * entirely (and silently creates the VM without the variables), so after
70
+ * passing `env` you can distinguish an applied override from an old server
71
+ * with `"envApplied" in created`.
72
+ */
73
+ envApplied: boolean;
74
+ };
46
75
  /** Machine as returned by `machines.get`, `machines.getByName` and `machines.update`. */
47
76
  export interface MachineDetail {
48
77
  id: string;
@@ -63,6 +92,10 @@ export interface MachineDetail {
63
92
  defaultSSHUsername: string | null;
64
93
  sshClientInitialCommand: string | null;
65
94
  metricsEnabled: boolean;
95
+ /** See {@link Machine.onIdle}. */
96
+ onIdle: Open<MachineOnIdleAction>;
97
+ /** See {@link Machine.idleTimeoutMinutes}. */
98
+ idleTimeoutMinutes: number;
66
99
  distribution: Open<Distribution>;
67
100
  /** SSH key the machine was created with (null if since destroyed). */
68
101
  key: {
@@ -77,6 +110,8 @@ export interface MachineDetail {
77
110
  pricePerHour: number | null;
78
111
  mountPaths: string[];
79
112
  statusExplanation: string | null;
113
+ /** See {@link Machine.orderExpiresAt}. */
114
+ orderExpiresAt: string | null;
80
115
  }
81
116
  export interface DiskMount {
82
117
  diskName: string;
@@ -85,14 +120,39 @@ export interface DiskMount {
85
120
  export interface MachineCreateInput {
86
121
  name: string;
87
122
  size: MachineSize;
88
- /** `"us"` is a legacy alias for `"us-east"` accepted by the API. */
89
- region: MachineRegion | "us";
123
+ /** Legacy aliases ("us-east", "eu", …) are accepted and normalized. */
124
+ region: MachineRegion | LegacyMachineRegion;
90
125
  imageName: string;
91
126
  sshKeyId?: string;
92
127
  imageVersion?: number;
93
128
  profileName?: string;
94
129
  mounts?: DiskMount[];
95
130
  metricsEnabled?: boolean;
131
+ /**
132
+ * Suspend or destroy the machine after sustained inactivity. Enabling
133
+ * (`"suspend"`/`"destroy"`) force-enables `metricsEnabled` and requires a
134
+ * managed SSH key.
135
+ *
136
+ * Requires a server that supports idle detection: an older server silently
137
+ * ignores this field (the machine is created WITHOUT the policy) and omits
138
+ * `onIdle`/`idleTimeoutMinutes` from responses. Published SDK versions
139
+ * always trail the production server, so this only matters against
140
+ * self-hosted/stale deployments — check `machine.onIdle !== undefined`
141
+ * after creating if you depend on the policy.
142
+ */
143
+ onIdle?: MachineOnIdleAction;
144
+ /** Minutes of inactivity before `onIdle` fires (10-2880; default 30). */
145
+ idleTimeoutMinutes?: number;
146
+ /**
147
+ * Environment variables set on the VM at creation, keyed by name. They
148
+ * override the chosen profile's variables on name collision and are applied
149
+ * on every provision/resume. Immutable after creation.
150
+ *
151
+ * Requires a server that supports machine env overrides: an older server
152
+ * silently ignores this field (the VM is created WITHOUT the variables, and
153
+ * with a `profileName` collision the profile's value is used instead).
154
+ */
155
+ env?: Record<string, string>;
96
156
  }
97
157
  export interface MachineUpdateInput {
98
158
  id: string;
@@ -100,6 +160,10 @@ export interface MachineUpdateInput {
100
160
  defaultSSHUsername?: string;
101
161
  sshClientInitialCommand?: string;
102
162
  metricsEnabled?: boolean;
163
+ /** See {@link MachineCreateInput.onIdle}. */
164
+ onIdle?: MachineOnIdleAction;
165
+ /** See {@link MachineCreateInput.idleTimeoutMinutes}. */
166
+ idleTimeoutMinutes?: number;
103
167
  }
104
168
  /** Returned by machine lifecycle mutations (start/stop/reboot/suspend/destroy). */
105
169
  export interface ActionResult {
@@ -136,12 +200,33 @@ export interface Image {
136
200
  minDiskGb: number | null;
137
201
  regions: string[];
138
202
  gpuOnly: boolean;
203
+ /**
204
+ * Branch-tracking source identity (github `--flake` builds). All null on
205
+ * non-tracked images. When set, pushes to `gitRepo`@`gitBranch` rebuild
206
+ * the image and auto-promote the new version.
207
+ */
208
+ gitRepo: string | null;
209
+ gitBranch: string | null;
210
+ flakeDir: string | null;
211
+ nixProfile: string | null;
139
212
  createdAt: string;
140
213
  updatedAt: string;
141
214
  ageMinutes: number;
142
215
  totalCost: number | null;
143
216
  pricePerHour: number | null;
144
217
  }
218
+ /**
219
+ * Image as returned by `images.list` — adds the latest failed-build error of
220
+ * the image's current draft (owner/admin-visible only; null otherwise or
221
+ * when the latest build succeeded).
222
+ */
223
+ export interface ImageListItem extends Image {
224
+ latestVersionError: {
225
+ version: number;
226
+ message: string;
227
+ at: string | null;
228
+ } | null;
229
+ }
145
230
  /** Image as returned by `images.get`. */
146
231
  export interface ImageDetail extends Image {
147
232
  versionSnapshotStorageCost: number | null;
@@ -181,10 +266,11 @@ export interface SshKeyCreated extends SshKeyWithFile {
181
266
  export interface SshKeyCreatedManaged extends SshKeyWithFile {
182
267
  privateKey: string;
183
268
  }
184
- export declare const MACHINE_KEYS: readonly ["id", "name", "url", "status", "ip", "size", "region", "provider", "createdAt", "firstStartedAt", "destroyedAt", "image", "distribution", "ageMinutes", "totalCost", "pricePerHour", "metricsEnabled"];
185
- export declare const MACHINE_CREATED_KEYS: readonly ["id", "name", "url", "status", "ip", "size", "region", "provider", "createdAt", "firstStartedAt", "destroyedAt", "ageMinutes", "totalCost", "pricePerHour", "metricsEnabled"];
186
- export declare const MACHINE_DETAIL_KEYS: readonly ["id", "name", "url", "status", "ip", "size", "vcpu", "ram", "disk", "region", "provider", "createdAt", "firstStartedAt", "image", "imageVersion", "defaultSSHUsername", "sshClientInitialCommand", "metricsEnabled", "distribution", "key", "ageMinutes", "totalCost", "pricePerHour", "mountPaths", "statusExplanation"];
187
- export declare const IMAGE_KEYS: readonly ["id", "name", "description", "distribution", "type", "status", "provider", "sizeGb", "minDiskGb", "regions", "gpuOnly", "createdAt", "updatedAt", "ageMinutes", "totalCost", "pricePerHour"];
188
- export declare const IMAGE_DETAIL_KEYS: readonly ["id", "name", "description", "distribution", "type", "status", "provider", "sizeGb", "minDiskGb", "regions", "gpuOnly", "createdAt", "updatedAt", "ageMinutes", "totalCost", "pricePerHour", "versionSnapshotStorageCost"];
269
+ export declare const MACHINE_KEYS: readonly ["id", "name", "url", "status", "ip", "size", "region", "provider", "createdAt", "firstStartedAt", "destroyedAt", "image", "distribution", "ageMinutes", "totalCost", "pricePerHour", "metricsEnabled", "onIdle", "idleTimeoutMinutes", "orderExpiresAt"];
270
+ export declare const MACHINE_CREATED_KEYS: readonly ["id", "name", "url", "status", "ip", "size", "region", "provider", "createdAt", "firstStartedAt", "destroyedAt", "ageMinutes", "totalCost", "pricePerHour", "metricsEnabled", "onIdle", "idleTimeoutMinutes", "orderExpiresAt", "envApplied"];
271
+ export declare const MACHINE_DETAIL_KEYS: readonly ["id", "name", "url", "status", "ip", "size", "vcpu", "ram", "disk", "region", "provider", "createdAt", "firstStartedAt", "image", "imageVersion", "defaultSSHUsername", "sshClientInitialCommand", "metricsEnabled", "onIdle", "idleTimeoutMinutes", "distribution", "key", "ageMinutes", "totalCost", "pricePerHour", "mountPaths", "statusExplanation", "orderExpiresAt"];
272
+ export declare const IMAGE_KEYS: readonly ["id", "name", "description", "distribution", "type", "status", "provider", "sizeGb", "minDiskGb", "regions", "gpuOnly", "gitRepo", "gitBranch", "flakeDir", "nixProfile", "createdAt", "updatedAt", "ageMinutes", "totalCost", "pricePerHour"];
273
+ export declare const IMAGE_LIST_KEYS: readonly ["id", "name", "description", "distribution", "type", "status", "provider", "sizeGb", "minDiskGb", "regions", "gpuOnly", "gitRepo", "gitBranch", "flakeDir", "nixProfile", "createdAt", "updatedAt", "ageMinutes", "totalCost", "pricePerHour", "latestVersionError"];
274
+ export declare const IMAGE_DETAIL_KEYS: readonly ["id", "name", "description", "distribution", "type", "status", "provider", "sizeGb", "minDiskGb", "regions", "gpuOnly", "gitRepo", "gitBranch", "flakeDir", "nixProfile", "createdAt", "updatedAt", "ageMinutes", "totalCost", "pricePerHour", "versionSnapshotStorageCost"];
189
275
  export declare const SSH_KEY_KEYS: readonly ["id", "name", "type", "publicKey", "isDefault", "createdAt"];
190
276
  export declare const SSH_KEY_WITH_FILE_KEYS: readonly ["id", "name", "type", "publicKey", "isDefault", "createdAt", "fileName"];
package/dist/types.js CHANGED
@@ -35,6 +35,9 @@ export const MACHINE_KEYS = [
35
35
  "totalCost",
36
36
  "pricePerHour",
37
37
  "metricsEnabled",
38
+ "onIdle",
39
+ "idleTimeoutMinutes",
40
+ "orderExpiresAt",
38
41
  ];
39
42
  export const MACHINE_CREATED_KEYS = [
40
43
  "id",
@@ -52,6 +55,10 @@ export const MACHINE_CREATED_KEYS = [
52
55
  "totalCost",
53
56
  "pricePerHour",
54
57
  "metricsEnabled",
58
+ "onIdle",
59
+ "idleTimeoutMinutes",
60
+ "orderExpiresAt",
61
+ "envApplied",
55
62
  ];
56
63
  export const MACHINE_DETAIL_KEYS = [
57
64
  "id",
@@ -72,6 +79,8 @@ export const MACHINE_DETAIL_KEYS = [
72
79
  "defaultSSHUsername",
73
80
  "sshClientInitialCommand",
74
81
  "metricsEnabled",
82
+ "onIdle",
83
+ "idleTimeoutMinutes",
75
84
  "distribution",
76
85
  "key",
77
86
  "ageMinutes",
@@ -79,7 +88,10 @@ export const MACHINE_DETAIL_KEYS = [
79
88
  "pricePerHour",
80
89
  "mountPaths",
81
90
  "statusExplanation",
91
+ "orderExpiresAt",
82
92
  ];
93
+ // The shared Image keys — valid against BOTH images.list rows and images.get
94
+ // (kept stable for existing consumers indexing either shape).
83
95
  export const IMAGE_KEYS = [
84
96
  "id",
85
97
  "name",
@@ -92,12 +104,21 @@ export const IMAGE_KEYS = [
92
104
  "minDiskGb",
93
105
  "regions",
94
106
  "gpuOnly",
107
+ "gitRepo",
108
+ "gitBranch",
109
+ "flakeDir",
110
+ "nixProfile",
95
111
  "createdAt",
96
112
  "updatedAt",
97
113
  "ageMinutes",
98
114
  "totalCost",
99
115
  "pricePerHour",
100
116
  ];
117
+ // List rows additionally carry the computed latestVersionError; get does not.
118
+ export const IMAGE_LIST_KEYS = [
119
+ ...IMAGE_KEYS,
120
+ "latestVersionError",
121
+ ];
101
122
  export const IMAGE_DETAIL_KEYS = [
102
123
  ...IMAGE_KEYS,
103
124
  "versionSnapshotStorageCost",
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "0.1.0";
1
+ export declare const SDK_VERSION = "0.2.0";
package/dist/version.js CHANGED
@@ -1,4 +1,4 @@
1
1
  // Must match the "version" field in package.json — version.test.ts enforces
2
2
  // the sync, and the deploy-sdk workflow compares this constant (imported from
3
3
  // the built dist under plain Node) against package.json before publishing.
4
- export const SDK_VERSION = "0.1.0";
4
+ export const SDK_VERSION = "0.2.0";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@machine0/sdk",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Typed Node.js/TypeScript SDK for the machine0 API. Zero dependencies, fetch-based.",
5
5
  "homepage": "https://machine0.io",
6
6
  "author": "Barnaby Malet <barnaby@machine0.io>",