@blaxel/core 0.2.19-preview.43 → 0.2.19
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/sandbox/sandbox.js +4 -2
- package/dist/sandbox/types.d.ts +6 -0
- package/dist/sandbox/types.js +23 -0
- package/package.json +1 -1
package/dist/sandbox/sandbox.js
CHANGED
|
@@ -66,8 +66,8 @@ class SandboxInstance {
|
|
|
66
66
|
const defaultName = `sandbox-${(0, uuid_1.v4)().replace(/-/g, '').substring(0, 8)}`;
|
|
67
67
|
const defaultImage = "blaxel/prod-base:latest";
|
|
68
68
|
const defaultMemory = 4096;
|
|
69
|
-
// Handle SandboxCreateConfiguration or simple dict with name/image/memory/ports keys
|
|
70
|
-
if (!sandbox || 'name' in sandbox || 'image' in sandbox || 'memory' in sandbox || 'ports' in sandbox) {
|
|
69
|
+
// Handle SandboxCreateConfiguration or simple dict with name/image/memory/ports/envs keys
|
|
70
|
+
if (!sandbox || 'name' in sandbox || 'image' in sandbox || 'memory' in sandbox || 'ports' in sandbox || 'envs' in sandbox) {
|
|
71
71
|
if (!sandbox)
|
|
72
72
|
sandbox = {};
|
|
73
73
|
if (!sandbox.name)
|
|
@@ -77,6 +77,7 @@ class SandboxInstance {
|
|
|
77
77
|
if (!sandbox.memory)
|
|
78
78
|
sandbox.memory = defaultMemory;
|
|
79
79
|
const ports = (0, types_js_1.normalizePorts)(sandbox.ports);
|
|
80
|
+
const envs = (0, types_js_1.normalizeEnvs)(sandbox.envs);
|
|
80
81
|
sandbox = {
|
|
81
82
|
metadata: { name: sandbox.name },
|
|
82
83
|
spec: {
|
|
@@ -84,6 +85,7 @@ class SandboxInstance {
|
|
|
84
85
|
image: sandbox.image,
|
|
85
86
|
memory: sandbox.memory,
|
|
86
87
|
ports: ports,
|
|
88
|
+
envs: envs,
|
|
87
89
|
generation: "mk3"
|
|
88
90
|
}
|
|
89
91
|
}
|
package/dist/sandbox/types.d.ts
CHANGED
|
@@ -10,6 +10,10 @@ export interface SessionWithToken {
|
|
|
10
10
|
token: string;
|
|
11
11
|
expiresAt: Date;
|
|
12
12
|
}
|
|
13
|
+
export interface EnvVar {
|
|
14
|
+
name: string;
|
|
15
|
+
value: string;
|
|
16
|
+
}
|
|
13
17
|
export type SandboxConfiguration = {
|
|
14
18
|
forceUrl?: string;
|
|
15
19
|
headers?: Record<string, string>;
|
|
@@ -20,5 +24,7 @@ export type SandboxCreateConfiguration = {
|
|
|
20
24
|
image?: string;
|
|
21
25
|
memory?: number;
|
|
22
26
|
ports?: (Port | Record<string, any>)[];
|
|
27
|
+
envs?: EnvVar[];
|
|
23
28
|
};
|
|
24
29
|
export declare function normalizePorts(ports?: (Port | Record<string, any>)[]): Port[] | undefined;
|
|
30
|
+
export declare function normalizeEnvs(envs?: EnvVar[]): EnvVar[] | undefined;
|
package/dist/sandbox/types.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.normalizePorts = normalizePorts;
|
|
4
|
+
exports.normalizeEnvs = normalizeEnvs;
|
|
4
5
|
function normalizePorts(ports) {
|
|
5
6
|
if (!ports || ports.length === 0) {
|
|
6
7
|
return undefined;
|
|
@@ -27,3 +28,25 @@ function normalizePorts(ports) {
|
|
|
27
28
|
}
|
|
28
29
|
return portObjects;
|
|
29
30
|
}
|
|
31
|
+
function normalizeEnvs(envs) {
|
|
32
|
+
if (!envs || envs.length === 0) {
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
const envObjects = [];
|
|
36
|
+
for (const env of envs) {
|
|
37
|
+
if (typeof env === 'object' && env !== null) {
|
|
38
|
+
// Validate that the object has the required keys
|
|
39
|
+
if (!('name' in env) || !('value' in env)) {
|
|
40
|
+
throw new Error(`Environment variable object must have 'name' and 'value' keys: ${JSON.stringify(env)}`);
|
|
41
|
+
}
|
|
42
|
+
if (typeof env.name !== 'string' || typeof env.value !== 'string') {
|
|
43
|
+
throw new Error(`Environment variable 'name' and 'value' must be strings: ${JSON.stringify(env)}`);
|
|
44
|
+
}
|
|
45
|
+
envObjects.push({ name: env.name, value: env.value });
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
throw new Error(`Invalid env type: ${typeof env}. Expected object with 'name' and 'value' keys.`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return envObjects;
|
|
52
|
+
}
|