@blaxel/core 0.3.20-preview.286 → 0.3.20-preview.289

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.
@@ -4,16 +4,32 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.env = void 0;
7
- const toml_1 = __importDefault(require("toml"));
7
+ const smol_toml_1 = __importDefault(require("smol-toml"));
8
8
  const node_js_1 = require("./node.js");
9
- const secretEnv = {};
10
- const configEnv = {};
9
+ const hasOwn = (source, prop) => Object.prototype.hasOwnProperty.call(source, prop);
10
+ const secretEnv = Object.create(null);
11
+ const configEnv = Object.create(null);
12
+ const stringifyTomlEnvValue = (value) => {
13
+ if (typeof value === "string") {
14
+ return value;
15
+ }
16
+ if (typeof value === "number" || typeof value === "boolean" || typeof value === "bigint") {
17
+ return String(value);
18
+ }
19
+ if (value instanceof Date) {
20
+ return value.toISOString();
21
+ }
22
+ const serialized = JSON.stringify(value);
23
+ return serialized === undefined ? String(value) : serialized;
24
+ };
11
25
  if (node_js_1.fs !== null) {
12
26
  try {
13
27
  const configFile = node_js_1.fs.readFileSync("blaxel.toml", "utf8");
14
- const configInfos = toml_1.default.parse(configFile);
15
- for (const key in configInfos.env) {
16
- configEnv[key] = configInfos.env[key];
28
+ const configInfos = smol_toml_1.default.parse(configFile, { maxDepth: 100 });
29
+ if (configInfos.env && typeof configInfos.env === "object") {
30
+ for (const [key, value] of Object.entries(configInfos.env)) {
31
+ configEnv[key] = stringifyTomlEnvValue(value);
32
+ }
17
33
  }
18
34
  }
19
35
  catch {
@@ -42,13 +58,13 @@ if (node_js_1.fs !== null) {
42
58
  }
43
59
  const env = new Proxy({}, {
44
60
  get: (target, prop) => {
45
- if (secretEnv[prop]) {
61
+ if (hasOwn(secretEnv, prop)) {
46
62
  return secretEnv[prop];
47
63
  }
48
- if (configEnv[prop]) {
64
+ if (hasOwn(configEnv, prop)) {
49
65
  return configEnv[prop];
50
66
  }
51
- if (typeof process !== "undefined" && process.env) {
67
+ if (typeof process !== "undefined" && process.env && hasOwn(process.env, prop)) {
52
68
  return process.env[prop];
53
69
  }
54
70
  return undefined;
@@ -0,0 +1,139 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ const node_fs_1 = require("node:fs");
40
+ const node_os_1 = require("node:os");
41
+ const node_path_1 = require("node:path");
42
+ const smol_toml_1 = __importDefault(require("smol-toml"));
43
+ const vitest_1 = require("vitest");
44
+ const originalCwd = process.cwd();
45
+ const originalWorkspace = process.env.BL_WORKSPACE;
46
+ let currentTempDir;
47
+ const importEnvFromTempConfig = async (config) => {
48
+ currentTempDir = (0, node_fs_1.mkdtempSync)((0, node_path_1.join)((0, node_os_1.tmpdir)(), "blaxel-env-"));
49
+ (0, node_fs_1.writeFileSync)((0, node_path_1.join)(currentTempDir, "blaxel.toml"), config);
50
+ process.chdir(currentTempDir);
51
+ vitest_1.vi.resetModules();
52
+ return Promise.resolve().then(() => __importStar(require("./env.js")));
53
+ };
54
+ (0, vitest_1.afterEach)(() => {
55
+ process.chdir(originalCwd);
56
+ if (originalWorkspace === undefined) {
57
+ delete process.env.BL_WORKSPACE;
58
+ }
59
+ else {
60
+ process.env.BL_WORKSPACE = originalWorkspace;
61
+ }
62
+ delete Object.prototype.BL_WORKSPACE;
63
+ delete Object.prototype.SECRET_ENV;
64
+ vitest_1.vi.resetModules();
65
+ if (currentTempDir) {
66
+ (0, node_fs_1.rmSync)(currentTempDir, { force: true, recursive: true });
67
+ currentTempDir = undefined;
68
+ }
69
+ });
70
+ (0, vitest_1.describe)("env TOML configuration", () => {
71
+ (0, vitest_1.it)("loads blaxel.toml env values through the SDK env proxy", async () => {
72
+ const { env } = await importEnvFromTempConfig(`
73
+ [env]
74
+ BL_WORKSPACE = "test-workspace"
75
+ BL_API_URL = "https://api.example.test"
76
+ `);
77
+ (0, vitest_1.expect)(env.BL_WORKSPACE).toBe("test-workspace");
78
+ (0, vitest_1.expect)(env.BL_API_URL).toBe("https://api.example.test");
79
+ });
80
+ (0, vitest_1.it)("serializes supported TOML env value types through the SDK env proxy", async () => {
81
+ const { env } = await importEnvFromTempConfig(`
82
+ [env]
83
+ BOOLEAN_VALUE = true
84
+ NUMBER_VALUE = 42
85
+ ARRAY_VALUE = ["a", "b"]
86
+ INLINE_TABLE_VALUE = { name = "sandbox", enabled = true }
87
+ MULTILINE_VALUE = """
88
+ line one
89
+ line two
90
+ """
91
+ `);
92
+ (0, vitest_1.expect)(env.BOOLEAN_VALUE).toBe("true");
93
+ (0, vitest_1.expect)(env.NUMBER_VALUE).toBe("42");
94
+ (0, vitest_1.expect)(env.ARRAY_VALUE).toBe('["a","b"]');
95
+ (0, vitest_1.expect)(env.INLINE_TABLE_VALUE).toBe('{"name":"sandbox","enabled":true}');
96
+ (0, vitest_1.expect)(env.MULTILINE_VALUE).toBe("line one\nline two\n");
97
+ });
98
+ (0, vitest_1.it)("bounds array and inline-table nesting in the selected TOML parser", () => {
99
+ const nestedArray = `value = ${"[".repeat(6)}0${"]".repeat(6)}`;
100
+ const nestedInlineTable = `value = ${"{ a = ".repeat(6)}0${"}".repeat(6)}`;
101
+ (0, vitest_1.expect)(() => smol_toml_1.default.parse(nestedArray, { maxDepth: 5 })).toThrow(/excessively nested structures/);
102
+ (0, vitest_1.expect)(() => smol_toml_1.default.parse(nestedInlineTable, { maxDepth: 5 })).toThrow(/excessively nested structures/);
103
+ });
104
+ (0, vitest_1.it)("uses the SDK loader bounded TOML parser for default config parsing", async () => {
105
+ process.env.BL_WORKSPACE = "process-workspace";
106
+ const nestedArray = `${"[".repeat(101)}0${"]".repeat(101)}`;
107
+ const { env } = await importEnvFromTempConfig(`
108
+ [env]
109
+ BL_WORKSPACE = "toml-workspace"
110
+ TOO_DEEP = ${nestedArray}
111
+ `);
112
+ (0, vitest_1.expect)(env.BL_WORKSPACE).toBe("process-workspace");
113
+ });
114
+ (0, vitest_1.it)("does not load inherited env keys from config or secret sources", async () => {
115
+ delete process.env.BL_WORKSPACE;
116
+ Object.prototype.BL_WORKSPACE = "polluted-workspace";
117
+ Object.prototype.SECRET_ENV = "polluted-secret";
118
+ const { env } = await importEnvFromTempConfig(`
119
+ [env]
120
+ LEGITIMATE_ENV = "kept"
121
+ `);
122
+ (0, vitest_1.expect)(env.BL_WORKSPACE).toBeUndefined();
123
+ (0, vitest_1.expect)(env.SECRET_ENV).toBeUndefined();
124
+ (0, vitest_1.expect)(env.LEGITIMATE_ENV).toBe("kept");
125
+ });
126
+ (0, vitest_1.it)("does not pollute prototypes while loading malicious TOML env keys", async () => {
127
+ delete process.env.BL_WORKSPACE;
128
+ const { env } = await importEnvFromTempConfig(`
129
+ [env]
130
+ BL_WORKSPACE = "legitimate-workspace"
131
+
132
+ [env.__proto__]
133
+ INJECTED = "polluted-workspace"
134
+ `);
135
+ (0, vitest_1.expect)(env.BL_WORKSPACE).toBe("legitimate-workspace");
136
+ (0, vitest_1.expect)(env.INJECTED).toBeUndefined();
137
+ (0, vitest_1.expect)(Object.prototype).not.toHaveProperty("INJECTED");
138
+ });
139
+ });
@@ -30,8 +30,8 @@ function missingCredentialsMessage() {
30
30
  return "No Blaxel credentials found. Set the BL_API_KEY and BL_WORKSPACE environment variables, or run `bl login`.";
31
31
  }
32
32
  // Build info - these placeholders are replaced at build time by build:replace-imports
33
- const BUILD_VERSION = "0.3.20-preview.286";
34
- const BUILD_COMMIT = "6ebbd206e01759209b37771835096c6500d9fbb9";
33
+ const BUILD_VERSION = "0.3.20-preview.289";
34
+ const BUILD_COMMIT = "58aa51d749f749507d5fee77ee0393ec7d9c4753";
35
35
  const BUILD_SENTRY_DSN = "https://fd5e60e1c9820e1eef5ccebb84a07127@o4508714045276160.ingest.us.sentry.io/4510465864564736";
36
36
  const BLAXEL_API_VERSION = "2026-04-28";
37
37
  // Bun < 1.3.11 never sends connection-level WINDOW_UPDATE: the pooled h2
@@ -0,0 +1 @@
1
+ export {};