Skip to content

Commit

Permalink
Merge pull request #39 from clear-street/release-please--branches--ma…
Browse files Browse the repository at this point in the history
…in--changes--next--components--studio-sdk

release: 0.1.0-alpha.8
  • Loading branch information
sonicxml authored Sep 5, 2024
2 parents 4afd83d + b7a4d74 commit b70db8d
Show file tree
Hide file tree
Showing 11 changed files with 99 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "0.1.0-alpha.7"
".": "0.1.0-alpha.8"
}
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configured_endpoints: 27
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/clear-street%2Fstudio-sdk-cac25d6221de76f03b4e417f9d33f9665f8ed5c2d324693a46d9506212a1fb3e.yml
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/clear-street%2Fstudio-sdk-66efc857b146cfd0808fb37e5913e8ce46ee44fd0eac54154cfbc340d197585d.yml
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
# Changelog

## 0.1.0-alpha.8 (2024-09-05)

Full Changelog: [v0.1.0-alpha.7...v0.1.0-alpha.8](https://github.com/clear-street/studio-sdk-node/compare/v0.1.0-alpha.7...v0.1.0-alpha.8)

### Features

* **api:** add sandbox url ([#35](https://github.com/clear-street/studio-sdk-node/issues/35)) ([b8c89d3](https://github.com/clear-street/studio-sdk-node/commit/b8c89d37a49fa427b9fe0c6e597925b916ce69cd))


### Bug Fixes

* **client:** correct File construction from node-fetch Responses ([#34](https://github.com/clear-street/studio-sdk-node/issues/34)) ([6e03d20](https://github.com/clear-street/studio-sdk-node/commit/6e03d207e097dd9897d5ab5bc8738345ca386551))
* **uploads:** avoid making redundant memory copies ([#37](https://github.com/clear-street/studio-sdk-node/issues/37)) ([865845b](https://github.com/clear-street/studio-sdk-node/commit/865845bd96b35a15b4feafb9bc841249763fb6e4))


### Chores

* **internal:** dependency updates ([#36](https://github.com/clear-street/studio-sdk-node/issues/36)) ([9fc8102](https://github.com/clear-street/studio-sdk-node/commit/9fc8102d8f5f8596895d744550861ff9f8904ec2))

## 0.1.0-alpha.7 (2024-08-30)

Full Changelog: [v0.1.0-alpha.6...v0.1.0-alpha.7](https://github.com/clear-street/studio-sdk-node/compare/v0.1.0-alpha.6...v0.1.0-alpha.7)
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import StudioSDK from '@clear-street/studio-sdk';

const client = new StudioSDK({
bearerToken: process.env['STUDIO_SDK_BEARER_TOKEN'], // This is the default and can be omitted
environment: 'sandbox', // defaults to 'production'
});

async function main() {
Expand All @@ -45,6 +46,7 @@ import StudioSDK from '@clear-street/studio-sdk';

const client = new StudioSDK({
bearerToken: process.env['STUDIO_SDK_BEARER_TOKEN'], // This is the default and can be omitted
environment: 'sandbox', // defaults to 'production'
});

async function main() {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@clear-street/studio-sdk",
"version": "0.1.0-alpha.7",
"version": "0.1.0-alpha.8",
"description": "The official TypeScript library for the Studio SDK API",
"author": "Studio SDK <[email protected]>",
"types": "dist/index.d.ts",
Expand Down
27 changes: 25 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,27 @@ import { type Agent } from './_shims/index';
import * as Core from './core';
import * as API from './resources/index';

const environments = {
production: 'https://api.clearstreet.io/studio/v2',
sandbox: 'https://sandbox-api.clearstreet.io/studio/v2',
};
type Environment = keyof typeof environments;

export interface ClientOptions {
/**
* Defaults to process.env['STUDIO_SDK_BEARER_TOKEN'].
*/
bearerToken?: string | undefined;

/**
* Specifies the environment to use for the API.
*
* Each environment maps to a different base URL:
* - `production` corresponds to `https://api.clearstreet.io/studio/v2`
* - `sandbox` corresponds to `https://sandbox-api.clearstreet.io/studio/v2`
*/
environment?: Environment;

/**
* Override the default base URL for the API, e.g., "https://api.example.com/v2/"
*
Expand Down Expand Up @@ -81,6 +96,7 @@ export class StudioSDK extends Core.APIClient {
* API Client for interfacing with the Studio SDK API.
*
* @param {string | undefined} [opts.bearerToken=process.env['STUDIO_SDK_BEARER_TOKEN'] ?? undefined]
* @param {Environment} [opts.environment=production] - Specifies the environment URL to use for the API.
* @param {string} [opts.baseURL=process.env['STUDIO_SDK_BASE_URL'] ?? https://api.clearstreet.io/studio/v2] - 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 {number} [opts.httpAgent] - An HTTP agent used to manage HTTP(s) connections.
Expand All @@ -103,11 +119,18 @@ export class StudioSDK extends Core.APIClient {
const options: ClientOptions = {
bearerToken,
...opts,
baseURL: baseURL || `https://api.clearstreet.io/studio/v2`,
baseURL,
environment: opts.environment ?? 'production',
};

if (baseURL && opts.environment) {
throw new Errors.StudioSDKError(
'Ambiguous URL; The `baseURL` option (or STUDIO_SDK_BASE_URL env var) and the `environment` option are given. If you want to use the environment you must pass baseURL: null',
);
}

super({
baseURL: options.baseURL!,
baseURL: options.baseURL || environments[options.environment || 'production'],
timeout: options.timeout ?? 60000 /* 1 minute */,
httpAgent: options.httpAgent,
maxRetries: options.maxRetries,
Expand Down
15 changes: 11 additions & 4 deletions src/uploads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,21 +107,28 @@ export async function toFile(
// If it's a promise, resolve it.
value = await value;

// Use the file's options if there isn't one provided
options ??= isFileLike(value) ? { lastModified: value.lastModified, type: value.type } : {};
// If we've been given a `File` we don't need to do anything
if (isFileLike(value)) {
return value;
}

if (isResponseLike(value)) {
const blob = await value.blob();
name ||= new URL(value.url).pathname.split(/[\\/]/).pop() ?? 'unknown_file';

return new File([blob as any], name, options);
// we need to convert the `Blob` into an array buffer because the `Blob` class
// that `node-fetch` defines is incompatible with the web standard which results
// in `new File` interpreting it as a string instead of binary data.
const data = isBlobLike(blob) ? [(await blob.arrayBuffer()) as any] : [blob];

return new File(data, name, options);
}

const bits = await getBytes(value);

name ||= getName(value) ?? 'unknown_file';

if (!options.type) {
if (!options?.type) {
const type = (bits[0] as any)?.type;
if (typeof type === 'string') {
options = { ...options, type };
Expand Down
2 changes: 1 addition & 1 deletion src/version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const VERSION = '0.1.0-alpha.7'; // x-release-please-version
export const VERSION = '0.1.0-alpha.8'; // x-release-please-version
17 changes: 17 additions & 0 deletions tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,23 @@ describe('instantiate client', () => {
const client = new StudioSDK({ bearerToken: 'My Bearer Token' });
expect(client.baseURL).toEqual('https://api.clearstreet.io/studio/v2');
});

test('env variable with environment', () => {
process.env['STUDIO_SDK_BASE_URL'] = 'https://example.com/from_env';

expect(
() => new StudioSDK({ bearerToken: 'My Bearer Token', environment: 'production' }),
).toThrowErrorMatchingInlineSnapshot(
`"Ambiguous URL; The \`baseURL\` option (or STUDIO_SDK_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 StudioSDK({
bearerToken: 'My Bearer Token',
baseURL: null,
environment: 'production',
});
expect(client.baseURL).toEqual('https://api.clearstreet.io/studio/v2');
});
});

test('maxRetries option is correctly set', () => {
Expand Down
8 changes: 8 additions & 0 deletions tests/uploads.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,12 @@ describe('toFile', () => {
const file = await toFile(input);
expect(file.name).toEqual('uploads.test.ts');
});

it('does not copy File objects', async () => {
const input = new File(['foo'], 'input.jsonl', { type: 'jsonl' });
const file = await toFile(input);
expect(file).toBe(input);
expect(file.name).toEqual('input.jsonl');
expect(file.type).toBe('jsonl');
});
});
26 changes: 13 additions & 13 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1200,12 +1200,12 @@ brace-expansion@^2.0.1:
dependencies:
balanced-match "^1.0.0"

braces@^3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/braces/-/braces-3.0.2.tgz#3454e1a462ee8d599e236df336cd9ea4f8afe107"
integrity sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==
braces@^3.0.3:
version "3.0.3"
resolved "https://registry.yarnpkg.com/braces/-/braces-3.0.3.tgz#490332f40919452272d55a8480adc0c441358789"
integrity sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==
dependencies:
fill-range "^7.0.1"
fill-range "^7.1.1"

browserslist@^4.22.2:
version "4.22.2"
Expand Down Expand Up @@ -1762,10 +1762,10 @@ file-entry-cache@^6.0.1:
dependencies:
flat-cache "^3.0.4"

fill-range@^7.0.1:
version "7.0.1"
resolved "https://registry.yarnpkg.com/fill-range/-/fill-range-7.0.1.tgz#1919a6a7c75fe38b2c7c77e5198535da9acdda40"
integrity sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==
fill-range@^7.1.1:
version "7.1.1"
resolved "https://registry.yarnpkg.com/fill-range/-/fill-range-7.1.1.tgz#44265d3cac07e3ea7dc247516380643754a05292"
integrity sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==
dependencies:
to-regex-range "^5.0.1"

Expand Down Expand Up @@ -2638,11 +2638,11 @@ merge2@^1.3.0, merge2@^1.4.1:
integrity sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==

micromatch@^4.0.4:
version "4.0.5"
resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-4.0.5.tgz#bc8999a7cbbf77cdc89f132f6e467051b49090c6"
integrity sha512-DMy+ERcEW2q8Z2Po+WNXuw3c5YaUSFjAO5GsJqfEl7UjvtIuFKO6ZrKvcItdy98dwFI2N1tg3zNIdKaQT+aNdA==
version "4.0.8"
resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-4.0.8.tgz#d66fa18f3a47076789320b9b1af32bd86d9fa202"
integrity sha512-PXwfBhYu0hBCPw8Dn0E+WDYb7af3dSLVWKi3HGv84IdF4TyFoC0ysxFd0Goxw7nSv4T/PzEJQxsYsEiFCKo2BA==
dependencies:
braces "^3.0.2"
braces "^3.0.3"
picomatch "^2.3.1"

[email protected]:
Expand Down

0 comments on commit b70db8d

Please sign in to comment.