@blaxel/core 0.2.78-preview.125 → 0.2.78

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.
@@ -43,7 +43,30 @@ if (isNode && !isBrowser) {
43
43
  // Silently ignore warming failures
44
44
  }
45
45
  }
46
- // Allow to set custom configuration for browser environment
46
+ /**
47
+ * Configure the SDK programmatically at runtime, instead of relying on
48
+ * environment variables or config files.
49
+ *
50
+ * @example
51
+ * // With an API key
52
+ * initialize({ workspace: 'my-workspace', apiKey: 'bl_...' });
53
+ *
54
+ * @example
55
+ * // With client credentials (object form)
56
+ * initialize({
57
+ * workspace: 'my-workspace',
58
+ * clientCredentials: { clientId: '...', clientSecret: '...' },
59
+ * });
60
+ * await authenticate();
61
+ *
62
+ * @example
63
+ * // With client credentials (pre-encoded Base64 string)
64
+ * initialize({
65
+ * workspace: 'my-workspace',
66
+ * clientCredentials: 'base64-encoded-string',
67
+ * });
68
+ * await authenticate();
69
+ */
47
70
  export function initialize(config) {
48
71
  settings.setConfig(config);
49
72
  client.setConfig({
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Integration tests for programmatic SDK initialization.
3
+ *
4
+ * These tests hit the real Blaxel API and require credentials.
5
+ * Set the following environment variables before running:
6
+ *
7
+ * TEST_BL_WORKSPACE - Blaxel workspace name
8
+ * TEST_BL_API_KEY - API key (for apiKey test)
9
+ * TEST_BL_CLIENT_CREDS - Base64-encoded client credentials (for string test)
10
+ * TEST_BL_CLIENT_ID - Client ID (for object test)
11
+ * TEST_BL_CLIENT_SECRET - Client secret (for object test)
12
+ *
13
+ * Run with:
14
+ * TEST_BL_WORKSPACE=... TEST_BL_API_KEY=... npx vitest --run src/common/initialize.integration.test.ts
15
+ */
16
+ import { describe, expect, it } from "vitest";
17
+ import { listWorkspaces } from "../client/sdk.gen.js";
18
+ import { authenticate, initialize } from "./autoload.js";
19
+ const workspace = process.env.TEST_BL_WORKSPACE;
20
+ describe.runIf(workspace)("initialize() integration", () => {
21
+ it("works with apiKey", async () => {
22
+ const apiKey = process.env.TEST_BL_API_KEY;
23
+ if (!apiKey)
24
+ return;
25
+ initialize({ workspace: workspace, apiKey });
26
+ const res = await listWorkspaces();
27
+ expect(res.error).toBeUndefined();
28
+ expect(res.data).toBeDefined();
29
+ expect(Array.isArray(res.data)).toBe(true);
30
+ });
31
+ it("works with clientCredentials as Base64 string", async () => {
32
+ const clientCredentials = process.env.TEST_BL_CLIENT_CREDS;
33
+ if (!clientCredentials)
34
+ return;
35
+ initialize({ workspace: workspace, clientCredentials });
36
+ await authenticate();
37
+ const res = await listWorkspaces();
38
+ expect(res.error).toBeUndefined();
39
+ expect(res.data).toBeDefined();
40
+ expect(Array.isArray(res.data)).toBe(true);
41
+ });
42
+ it("works with clientCredentials as { clientId, clientSecret }", async () => {
43
+ const clientId = process.env.TEST_BL_CLIENT_ID;
44
+ const clientSecret = process.env.TEST_BL_CLIENT_SECRET;
45
+ if (!clientId || !clientSecret)
46
+ return;
47
+ initialize({
48
+ workspace: workspace,
49
+ clientCredentials: { clientId, clientSecret },
50
+ });
51
+ await authenticate();
52
+ const res = await listWorkspaces();
53
+ expect(res.error).toBeUndefined();
54
+ expect(res.data).toBeDefined();
55
+ expect(Array.isArray(res.data)).toBe(true);
56
+ });
57
+ });
@@ -1,10 +1,12 @@
1
1
  import yaml from 'yaml';
2
+ import { ApiKey } from "../authentication/apikey.js";
3
+ import { ClientCredentials } from "../authentication/clientcredentials.js";
2
4
  import { authentication } from "../authentication/index.js";
3
5
  import { env } from "../common/env.js";
4
6
  import { fs, os, path } from "../common/node.js";
5
7
  // Build info - these placeholders are replaced at build time by build:replace-imports
6
- const BUILD_VERSION = "0.2.78-preview.125";
7
- const BUILD_COMMIT = "4b5006431c7ae391ea7f561a40d677a4d260adbb";
8
+ const BUILD_VERSION = "0.2.78";
9
+ const BUILD_COMMIT = "d2c4fbf20e9777ddc3e8fb2d58f9e021b860e986";
8
10
  const BUILD_SENTRY_DSN = "https://fd5e60e1c9820e1eef5ccebb84a07127@o4508714045276160.ingest.us.sentry.io/4510465864564736";
9
11
  // Cache for config.yaml tracking value
10
12
  let configTrackingValue = null;
@@ -76,6 +78,21 @@ class Settings {
76
78
  }
77
79
  setConfig(config) {
78
80
  this.config = config;
81
+ if (config.apiKey) {
82
+ this.credentials = new ApiKey({
83
+ apiKey: config.apiKey,
84
+ workspace: config.workspace,
85
+ });
86
+ }
87
+ else if (config.clientCredentials) {
88
+ const encoded = typeof config.clientCredentials === 'string'
89
+ ? config.clientCredentials
90
+ : btoa(`${config.clientCredentials.clientId}:${config.clientCredentials.clientSecret}`);
91
+ this.credentials = new ClientCredentials({
92
+ clientCredentials: encoded,
93
+ workspace: config.workspace,
94
+ });
95
+ }
79
96
  }
80
97
  get env() {
81
98
  return env.BL_ENV || "prod";