@blaxel/core 0.2.77 → 0.2.78-preview.126

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.
@@ -81,7 +81,30 @@ if (isNode && !isBrowser) {
81
81
  // Silently ignore warming failures
82
82
  }
83
83
  }
84
- // Allow to set custom configuration for browser environment
84
+ /**
85
+ * Configure the SDK programmatically at runtime, instead of relying on
86
+ * environment variables or config files.
87
+ *
88
+ * @example
89
+ * // With an API key
90
+ * initialize({ workspace: 'my-workspace', apiKey: 'bl_...' });
91
+ *
92
+ * @example
93
+ * // With client credentials (object form)
94
+ * initialize({
95
+ * workspace: 'my-workspace',
96
+ * clientCredentials: { clientId: '...', clientSecret: '...' },
97
+ * });
98
+ * await authenticate();
99
+ *
100
+ * @example
101
+ * // With client credentials (pre-encoded Base64 string)
102
+ * initialize({
103
+ * workspace: 'my-workspace',
104
+ * clientCredentials: 'base64-encoded-string',
105
+ * });
106
+ * await authenticate();
107
+ */
85
108
  function initialize(config) {
86
109
  settings_js_1.settings.setConfig(config);
87
110
  client_gen_js_1.client.setConfig({
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ /**
3
+ * Integration tests for programmatic SDK initialization.
4
+ *
5
+ * These tests hit the real Blaxel API and require credentials.
6
+ * Set the following environment variables before running:
7
+ *
8
+ * TEST_BL_WORKSPACE - Blaxel workspace name
9
+ * TEST_BL_API_KEY - API key (for apiKey test)
10
+ * TEST_BL_CLIENT_CREDS - Base64-encoded client credentials (for string test)
11
+ * TEST_BL_CLIENT_ID - Client ID (for object test)
12
+ * TEST_BL_CLIENT_SECRET - Client secret (for object test)
13
+ *
14
+ * Run with:
15
+ * TEST_BL_WORKSPACE=... TEST_BL_API_KEY=... npx vitest --run src/common/initialize.integration.test.ts
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ const vitest_1 = require("vitest");
19
+ const sdk_gen_js_1 = require("../client/sdk.gen.js");
20
+ const autoload_js_1 = require("./autoload.js");
21
+ const workspace = process.env.TEST_BL_WORKSPACE;
22
+ vitest_1.describe.runIf(workspace)("initialize() integration", () => {
23
+ (0, vitest_1.it)("works with apiKey", async () => {
24
+ const apiKey = process.env.TEST_BL_API_KEY;
25
+ if (!apiKey)
26
+ return;
27
+ (0, autoload_js_1.initialize)({ workspace: workspace, apiKey });
28
+ const res = await (0, sdk_gen_js_1.listWorkspaces)();
29
+ (0, vitest_1.expect)(res.error).toBeUndefined();
30
+ (0, vitest_1.expect)(res.data).toBeDefined();
31
+ (0, vitest_1.expect)(Array.isArray(res.data)).toBe(true);
32
+ });
33
+ (0, vitest_1.it)("works with clientCredentials as Base64 string", async () => {
34
+ const clientCredentials = process.env.TEST_BL_CLIENT_CREDS;
35
+ if (!clientCredentials)
36
+ return;
37
+ (0, autoload_js_1.initialize)({ workspace: workspace, clientCredentials });
38
+ await (0, autoload_js_1.authenticate)();
39
+ const res = await (0, sdk_gen_js_1.listWorkspaces)();
40
+ (0, vitest_1.expect)(res.error).toBeUndefined();
41
+ (0, vitest_1.expect)(res.data).toBeDefined();
42
+ (0, vitest_1.expect)(Array.isArray(res.data)).toBe(true);
43
+ });
44
+ (0, vitest_1.it)("works with clientCredentials as { clientId, clientSecret }", async () => {
45
+ const clientId = process.env.TEST_BL_CLIENT_ID;
46
+ const clientSecret = process.env.TEST_BL_CLIENT_SECRET;
47
+ if (!clientId || !clientSecret)
48
+ return;
49
+ (0, autoload_js_1.initialize)({
50
+ workspace: workspace,
51
+ clientCredentials: { clientId, clientSecret },
52
+ });
53
+ await (0, autoload_js_1.authenticate)();
54
+ const res = await (0, sdk_gen_js_1.listWorkspaces)();
55
+ (0, vitest_1.expect)(res.error).toBeUndefined();
56
+ (0, vitest_1.expect)(res.data).toBeDefined();
57
+ (0, vitest_1.expect)(Array.isArray(res.data)).toBe(true);
58
+ });
59
+ });
@@ -5,12 +5,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.settings = void 0;
7
7
  const yaml_1 = __importDefault(require("yaml"));
8
+ const apikey_js_1 = require("../authentication/apikey.js");
9
+ const clientcredentials_js_1 = require("../authentication/clientcredentials.js");
8
10
  const index_js_1 = require("../authentication/index.js");
9
11
  const env_js_1 = require("../common/env.js");
10
12
  const node_js_1 = require("../common/node.js");
11
13
  // Build info - these placeholders are replaced at build time by build:replace-imports
12
- const BUILD_VERSION = "0.2.77";
13
- const BUILD_COMMIT = "3d5932081fba211232402513e9765d0a776cd5d4";
14
+ const BUILD_VERSION = "0.2.78-preview.126";
15
+ const BUILD_COMMIT = "d2c4fbf20e9777ddc3e8fb2d58f9e021b860e986";
14
16
  const BUILD_SENTRY_DSN = "https://fd5e60e1c9820e1eef5ccebb84a07127@o4508714045276160.ingest.us.sentry.io/4510465864564736";
15
17
  // Cache for config.yaml tracking value
16
18
  let configTrackingValue = null;
@@ -82,6 +84,21 @@ class Settings {
82
84
  }
83
85
  setConfig(config) {
84
86
  this.config = config;
87
+ if (config.apiKey) {
88
+ this.credentials = new apikey_js_1.ApiKey({
89
+ apiKey: config.apiKey,
90
+ workspace: config.workspace,
91
+ });
92
+ }
93
+ else if (config.clientCredentials) {
94
+ const encoded = typeof config.clientCredentials === 'string'
95
+ ? config.clientCredentials
96
+ : btoa(`${config.clientCredentials.clientId}:${config.clientCredentials.clientSecret}`);
97
+ this.credentials = new clientcredentials_js_1.ClientCredentials({
98
+ clientCredentials: encoded,
99
+ workspace: config.workspace,
100
+ });
101
+ }
85
102
  }
86
103
  get env() {
87
104
  return env_js_1.env.BL_ENV || "prod";
@@ -1,4 +1,28 @@
1
1
  import { Config } from "./settings.js";
2
+ /**
3
+ * Configure the SDK programmatically at runtime, instead of relying on
4
+ * environment variables or config files.
5
+ *
6
+ * @example
7
+ * // With an API key
8
+ * initialize({ workspace: 'my-workspace', apiKey: 'bl_...' });
9
+ *
10
+ * @example
11
+ * // With client credentials (object form)
12
+ * initialize({
13
+ * workspace: 'my-workspace',
14
+ * clientCredentials: { clientId: '...', clientSecret: '...' },
15
+ * });
16
+ * await authenticate();
17
+ *
18
+ * @example
19
+ * // With client credentials (pre-encoded Base64 string)
20
+ * initialize({
21
+ * workspace: 'my-workspace',
22
+ * clientCredentials: 'base64-encoded-string',
23
+ * });
24
+ * await authenticate();
25
+ */
2
26
  export declare function initialize(config: Config): void;
3
27
  export declare function authenticate(): Promise<void>;
4
28
  /**
@@ -0,0 +1,16 @@
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
+ export {};
@@ -1,8 +1,26 @@
1
1
  import { Credentials } from "../authentication/credentials.js";
2
+ /**
3
+ * Client credentials as a `{ clientId, clientSecret }` pair.
4
+ * The SDK will Base64-encode them automatically.
5
+ */
6
+ export type ClientCredentialsPair = {
7
+ clientId: string;
8
+ clientSecret: string;
9
+ };
2
10
  export type Config = {
3
11
  proxy?: string;
4
12
  apikey?: string;
5
13
  workspace?: string;
14
+ /**
15
+ * Client credentials for OAuth2 client_credentials flow.
16
+ *
17
+ * Accepts either:
18
+ * - A pre-encoded Base64 string (`btoa("clientId:clientSecret")`)
19
+ * - An object `{ clientId, clientSecret }` (the SDK encodes it for you)
20
+ */
21
+ clientCredentials?: string | ClientCredentialsPair;
22
+ /** API key for bearer token authentication */
23
+ apiKey?: string;
6
24
  };
7
25
  declare class Settings {
8
26
  credentials: Credentials;