diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 12342be..5375ff4 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.1.0-alpha.5" + ".": "0.1.0-alpha.6" } diff --git a/.stats.yml b/.stats.yml index 3b0a5f2..1a7891f 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 4 openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/kernel%2Fkernel-d168b58fcf39dbd0458d132091793d3e2d0930070b7dda2d5f7f1baff20dd31b.yml openapi_spec_hash: b7e0fd7ee1656d7dbad57209d1584d92 -config_hash: c2bc5253d8afd6d67e031f73353c9b22 +config_hash: 2d282609080a6011e3f6222451f72237 diff --git a/CHANGELOG.md b/CHANGELOG.md index c7d13ba..35747ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## 0.1.0-alpha.6 (2025-05-10) + +Full Changelog: [v0.1.0-alpha.5...v0.1.0-alpha.6](https://github.com/onkernel/kernel-node-sdk/compare/v0.1.0-alpha.5...v0.1.0-alpha.6) + +### Features + +* **api:** update via SDK Studio ([4f6bb37](https://github.com/onkernel/kernel-node-sdk/commit/4f6bb3761722ad4ff471a5b60837cba6b4533c8e)) + ## 0.1.0-alpha.5 (2025-05-10) Full Changelog: [v0.1.0-alpha.4...v0.1.0-alpha.5](https://github.com/onkernel/kernel-node-sdk/compare/v0.1.0-alpha.4...v0.1.0-alpha.5) diff --git a/README.md b/README.md index d8e06f7..9373ffc 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,7 @@ import Kernel from '@onkernel/sdk'; const client = new Kernel({ apiKey: process.env['KERNEL_API_KEY'], // This is the default and can be omitted + environment: 'development', // defaults to 'production' }); async function main() { @@ -49,6 +50,7 @@ import Kernel from '@onkernel/sdk'; const client = new Kernel({ apiKey: process.env['KERNEL_API_KEY'], // This is the default and can be omitted + environment: 'development', // defaults to 'production' }); async function main() { diff --git a/package.json b/package.json index ec153c2..2f6d32a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@onkernel/sdk", - "version": "0.1.0-alpha.5", + "version": "0.1.0-alpha.6", "description": "The official TypeScript library for the Kernel API", "author": "Kernel <>", "types": "dist/index.d.ts", diff --git a/src/client.ts b/src/client.ts index 56f7f1d..ccee8be 100644 --- a/src/client.ts +++ b/src/client.ts @@ -34,12 +34,27 @@ import { formatRequestDetails, loggerFor } from './internal/utils/log'; import { isEmptyObj } from './internal/utils/values'; import { KernelApp, appRegistry } from './core/app-framework'; +const environments = { + production: 'https://api.onkernel.com/', + development: 'https://localhost:3001/', +}; +type Environment = keyof typeof environments; + export interface ClientOptions { /** * Defaults to process.env['KERNEL_API_KEY']. */ apiKey?: string | undefined; + /** + * Specifies the environment to use for the API. + * + * Each environment maps to a different base URL: + * - `production` corresponds to `https://api.onkernel.com/` + * - `development` corresponds to `https://localhost:3001/` + */ + environment?: Environment | undefined; + /** * Override the default base URL for the API, e.g., "https://api.example.com/v2/" * @@ -129,7 +144,8 @@ export class Kernel { * API Client for interfacing with the Kernel API. * * @param {string | undefined} [opts.apiKey=process.env['KERNEL_API_KEY'] ?? undefined] - * @param {string} [opts.baseURL=process.env['KERNEL_BASE_URL'] ?? http://localhost:3001] - Override the default base URL for the API. + * @param {Environment} [opts.environment=production] - Specifies the environment URL to use for the API. + * @param {string} [opts.baseURL=process.env['KERNEL_BASE_URL'] ?? https://api.onkernel.com/] - Override the default base URL for the API. * @param {number} [opts.timeout=1 minute] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out. * @param {MergedRequestInit} [opts.fetchOptions] - Additional `RequestInit` options to be passed to `fetch` calls. * @param {Fetch} [opts.fetch] - Specify a custom `fetch` function implementation. @@ -151,10 +167,17 @@ export class Kernel { const options: ClientOptions = { apiKey, ...opts, - baseURL: baseURL || `http://localhost:3001`, + baseURL, + environment: opts.environment ?? 'production', }; - this.baseURL = options.baseURL!; + if (baseURL && opts.environment) { + throw new Errors.KernelError( + 'Ambiguous URL; The `baseURL` option (or KERNEL_BASE_URL env var) and the `environment` option are given. If you want to use the environment you must pass baseURL: null', + ); + } + + this.baseURL = options.baseURL || environments[options.environment || 'production']; this.timeout = options.timeout ?? Kernel.DEFAULT_TIMEOUT /* 1 minute */; this.logger = options.logger ?? console; const defaultLogLevel = 'warn'; @@ -180,7 +203,8 @@ export class Kernel { withOptions(options: Partial): this { return new (this.constructor as any as new (props: ClientOptions) => typeof this)({ ...this._options, - baseURL: this.baseURL, + environment: options.environment ? options.environment : undefined, + baseURL: options.environment ? undefined : this.baseURL, maxRetries: this.maxRetries, timeout: this.timeout, logger: this.logger, diff --git a/src/version.ts b/src/version.ts index 66c10e6..9b7cfeb 100644 --- a/src/version.ts +++ b/src/version.ts @@ -1 +1 @@ -export const VERSION = '0.1.0-alpha.5'; // x-release-please-version +export const VERSION = '0.1.0-alpha.6'; // x-release-please-version diff --git a/tests/index.test.ts b/tests/index.test.ts index 3e6bf88..b452e0f 100644 --- a/tests/index.test.ts +++ b/tests/index.test.ts @@ -302,13 +302,26 @@ describe('instantiate client', () => { test('empty env variable', () => { process.env['KERNEL_BASE_URL'] = ''; // empty const client = new Kernel({ apiKey: 'My API Key' }); - expect(client.baseURL).toEqual('http://localhost:3001'); + expect(client.baseURL).toEqual('https://api.onkernel.com/'); }); test('blank env variable', () => { process.env['KERNEL_BASE_URL'] = ' '; // blank const client = new Kernel({ apiKey: 'My API Key' }); - expect(client.baseURL).toEqual('http://localhost:3001'); + expect(client.baseURL).toEqual('https://api.onkernel.com/'); + }); + + test('env variable with environment', () => { + process.env['KERNEL_BASE_URL'] = 'https://example.com/from_env'; + + expect( + () => new Kernel({ apiKey: 'My API Key', environment: 'production' }), + ).toThrowErrorMatchingInlineSnapshot( + `"Ambiguous URL; The \`baseURL\` option (or KERNEL_BASE_URL env var) and the \`environment\` option are given. If you want to use the environment you must pass baseURL: null"`, + ); + + const client = new Kernel({ apiKey: 'My API Key', baseURL: null, environment: 'production' }); + expect(client.baseURL).toEqual('https://api.onkernel.com/'); }); });