@raytrace-cli/sdk 0.2.11 → 0.2.12
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/package.json +1 -1
- package/src/index.d.ts +44 -0
- package/src/index.mjs +59 -7
package/package.json
CHANGED
package/src/index.d.ts
CHANGED
|
@@ -29,6 +29,40 @@ export interface SandboxSummary {
|
|
|
29
29
|
restore_error?: string;
|
|
30
30
|
env_profile_id?: string | null;
|
|
31
31
|
env_profile_name?: string | null;
|
|
32
|
+
master_id?: string | null;
|
|
33
|
+
master_version?: number | null;
|
|
34
|
+
master_name?: string | null;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface MasterSnapshotSummary {
|
|
38
|
+
master_id: string;
|
|
39
|
+
version: number;
|
|
40
|
+
status: 'queued' | 'publishing' | 'ready' | 'failed' | 'pruned';
|
|
41
|
+
base_release: string;
|
|
42
|
+
runtime_abi?: string | null;
|
|
43
|
+
size_bytes?: number | null;
|
|
44
|
+
dependencies?: {
|
|
45
|
+
npm?: Array<{ name: string; version: string }>;
|
|
46
|
+
pypi?: Array<{ name: string; version: string }>;
|
|
47
|
+
binaries?: string[];
|
|
48
|
+
dirs?: Record<string, number>;
|
|
49
|
+
} | null;
|
|
50
|
+
error?: string | null;
|
|
51
|
+
created: number;
|
|
52
|
+
ready_at?: number | null;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface MasterSandboxSummary {
|
|
56
|
+
id: string;
|
|
57
|
+
org_id?: string;
|
|
58
|
+
name: string;
|
|
59
|
+
description: string;
|
|
60
|
+
setup_sandbox_id?: string | null;
|
|
61
|
+
active_version?: number | null;
|
|
62
|
+
default_env_profile_id?: string | null;
|
|
63
|
+
latest_snapshot?: MasterSnapshotSummary | null;
|
|
64
|
+
created: number;
|
|
65
|
+
updated: number;
|
|
32
66
|
}
|
|
33
67
|
|
|
34
68
|
export interface EnvProfileSummary {
|
|
@@ -78,6 +112,8 @@ export interface CreateSandboxOptions {
|
|
|
78
112
|
* what is uploaded and `repo` is only what it is connected to.
|
|
79
113
|
*/
|
|
80
114
|
connect?: boolean;
|
|
115
|
+
/** Initialize `/opt/env` dependencies from a published organization master sandbox (by ID or name). */
|
|
116
|
+
master?: string;
|
|
81
117
|
/** Attach an encrypted organization env profile (by ID or name). */
|
|
82
118
|
envProfile?: string;
|
|
83
119
|
idempotencyKey?: string;
|
|
@@ -206,6 +242,14 @@ export class RayTrace {
|
|
|
206
242
|
update(id: string, options?: UpdateEnvProfileOptions): Promise<EnvProfileSummary>;
|
|
207
243
|
delete(id: string): Promise<{ id: string; deleted: boolean; detached_sandboxes: number }>;
|
|
208
244
|
};
|
|
245
|
+
readonly masters: {
|
|
246
|
+
list(): Promise<MasterSandboxSummary[]>;
|
|
247
|
+
get(id: string): Promise<MasterSandboxSummary & { versions?: MasterSnapshotSummary[] }>;
|
|
248
|
+
create(options: { name: string; description?: string; size?: SandboxSize; defaultEnvProfile?: string; setupScript?: string }): Promise<MasterSandboxSummary>;
|
|
249
|
+
publish(id: string, options?: { wait?: boolean; pollIntervalMs?: number }): Promise<MasterSnapshotSummary>;
|
|
250
|
+
getVersion(id: string, version: number): Promise<MasterSnapshotSummary>;
|
|
251
|
+
delete(id: string): Promise<{ id: string; deleted: boolean }>;
|
|
252
|
+
};
|
|
209
253
|
constructor(options?: RayTraceOptions);
|
|
210
254
|
}
|
|
211
255
|
|
package/src/index.mjs
CHANGED
|
@@ -189,7 +189,7 @@ class SandboxesResource {
|
|
|
189
189
|
return found;
|
|
190
190
|
}
|
|
191
191
|
|
|
192
|
-
async create({ name = undefined, size = 'small', archive = undefined, files = undefined, dir = undefined, repo = undefined, ref = undefined, connect = false, envProfile = undefined, idempotencyKey = undefined } = {}) {
|
|
192
|
+
async create({ name = undefined, size = 'small', archive = undefined, files = undefined, dir = undefined, repo = undefined, ref = undefined, connect = false, master = undefined, envProfile = undefined, idempotencyKey = undefined } = {}) {
|
|
193
193
|
if (connect) {
|
|
194
194
|
// Checked before anything is uploaded: connectScript throws on a ref it would not run.
|
|
195
195
|
if (!githubRepo(repo)) throw new Error('connect needs repo: a GitHub repository, as owner/name');
|
|
@@ -203,16 +203,18 @@ class SandboxesResource {
|
|
|
203
203
|
payload = archiveFromDirectory(dir);
|
|
204
204
|
} else if (repo) {
|
|
205
205
|
payload = await archiveFromRepo(repo, { ref });
|
|
206
|
-
} else {
|
|
207
|
-
throw new Error('Provide one of { archive, files, dir, repo } to create a sandbox');
|
|
206
|
+
} else if (!master) {
|
|
207
|
+
throw new Error('Provide one of { archive, files, dir, repo, master } to create a sandbox');
|
|
208
208
|
}
|
|
209
209
|
}
|
|
210
|
-
const derivedName = name || (repo ? repoName(repo) : 'sandbox');
|
|
210
|
+
const derivedName = name || (repo ? repoName(repo) : master ? `${master}-sandbox` : 'sandbox');
|
|
211
211
|
const cleanName = String(derivedName).replace(/[^A-Za-z0-9._ -]/g, '-').slice(0, 100) || 'sandbox';
|
|
212
|
-
let headers;
|
|
212
|
+
let headers = {};
|
|
213
213
|
let body;
|
|
214
|
-
if (
|
|
215
|
-
|
|
214
|
+
if (!payload) {
|
|
215
|
+
body = { name: cleanName, size, ...(master ? { master } : {}), ...(envProfile ? { env_profile: envProfile } : {}) };
|
|
216
|
+
} else if (envProfile || master) {
|
|
217
|
+
const mp = buildMultipartSandboxBody({ name: cleanName, size, ...(master ? { master } : {}), ...(envProfile ? { env_profile: envProfile } : {}) }, payload);
|
|
216
218
|
headers = { 'Content-Type': mp.contentType };
|
|
217
219
|
body = mp.body;
|
|
218
220
|
} else {
|
|
@@ -312,6 +314,55 @@ class EnvProfilesResource {
|
|
|
312
314
|
}
|
|
313
315
|
}
|
|
314
316
|
|
|
317
|
+
class MastersResource {
|
|
318
|
+
constructor(client) {
|
|
319
|
+
this._client = client;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
async list() {
|
|
323
|
+
const { data } = await this._client.request('GET', '/v1/masters');
|
|
324
|
+
return data?.masters || [];
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
async get(id) {
|
|
328
|
+
const { data } = await this._client.request('GET', `/v1/masters/${encodeURIComponent(id)}`);
|
|
329
|
+
return data;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
async create({ name, description = '', size = 'small', defaultEnvProfile = undefined, setupScript = undefined }) {
|
|
333
|
+
const body = { name, description, size };
|
|
334
|
+
if (defaultEnvProfile !== undefined) body.default_env_profile = defaultEnvProfile;
|
|
335
|
+
if (setupScript !== undefined) body.setup_script = setupScript;
|
|
336
|
+
const { data } = await this._client.request('POST', '/v1/masters', { body });
|
|
337
|
+
return data;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
async publish(id, { wait = true, pollIntervalMs = 1000 } = {}) {
|
|
341
|
+
const { data: started } = await this._client.request('POST', `/v1/masters/${encodeURIComponent(id)}/publish`, { body: {} });
|
|
342
|
+
if (!wait) return started;
|
|
343
|
+
let current = started;
|
|
344
|
+
while (current.status === 'queued' || current.status === 'publishing') {
|
|
345
|
+
await sleep(pollIntervalMs);
|
|
346
|
+
const { data: latest } = await this._client.request('GET', `/v1/masters/${encodeURIComponent(id)}/versions/${encodeURIComponent(started.version)}`);
|
|
347
|
+
current = latest;
|
|
348
|
+
}
|
|
349
|
+
if (current.status === 'failed') {
|
|
350
|
+
throw new RayTraceError(current.error || 'Master publish failed', { status: 500, body: current });
|
|
351
|
+
}
|
|
352
|
+
return current;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
async getVersion(id, version) {
|
|
356
|
+
const { data } = await this._client.request('GET', `/v1/masters/${encodeURIComponent(id)}/versions/${encodeURIComponent(version)}`);
|
|
357
|
+
return data;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
async delete(id) {
|
|
361
|
+
const { data } = await this._client.request('DELETE', `/v1/masters/${encodeURIComponent(id)}`);
|
|
362
|
+
return data;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
|
|
315
366
|
export class RayTrace {
|
|
316
367
|
constructor(options = {}) {
|
|
317
368
|
this.client = new RayTraceClient(options);
|
|
@@ -319,6 +370,7 @@ export class RayTrace {
|
|
|
319
370
|
this.usage = new UsageResource(this.client);
|
|
320
371
|
this.apiKeys = new ApiKeysResource(this.client);
|
|
321
372
|
this.envProfiles = new EnvProfilesResource(this.client);
|
|
373
|
+
this.masters = new MastersResource(this.client);
|
|
322
374
|
}
|
|
323
375
|
}
|
|
324
376
|
|