Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "1.34.1"
".": "1.34.2"
}
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Changelog

## 1.34.2 (2024-01-10)

Full Changelog: [v1.34.1...v1.34.2](https://github.com/orbcorp/orb-node/compare/v1.34.1...v1.34.2)

### Bug Fixes

* use default base url if BASE_URL env var is blank ([#74](https://github.com/orbcorp/orb-node/issues/74)) ([ad971d0](https://github.com/orbcorp/orb-node/commit/ad971d0fab1418375db9fdc3a3d5fbec22afb01c))


### Chores

* add .keep files for examples and custom code directories ([#73](https://github.com/orbcorp/orb-node/issues/73)) ([5bebfd9](https://github.com/orbcorp/orb-node/commit/5bebfd9d5d81ef44786882cb580b872289d7479b))
* **internal:** improve type signatures ([#71](https://github.com/orbcorp/orb-node/issues/71)) ([453e66e](https://github.com/orbcorp/orb-node/commit/453e66ec72e92ed94672f4be150c96e5bbb173f2))

## 1.34.1 (2024-01-04)

Full Changelog: [v1.34.0...v1.34.1](https://github.com/orbcorp/orb-node/compare/v1.34.0...v1.34.1)
Expand Down
4 changes: 4 additions & 0 deletions examples/.keep
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
File generated from our OpenAPI spec by Stainless.

This directory can be used to store example files demonstrating usage of this SDK.
It is ignored by Stainless code generation and its content (other than this keep file) won't be touched.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "orb-billing",
"version": "1.34.1",
"version": "1.34.2",
"description": "The official TypeScript library for the Orb API",
"author": "Orb <team@withorb.com>",
"types": "dist/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion src/_shims/index-deno.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const _Blob = Blob;
type _Blob = Blob;
export { _Blob as Blob };

export async function getMultipartRequestOptions<T extends {} = Record<string, unknown>>(
export async function getMultipartRequestOptions<T = Record<string, unknown>>(
form: FormData,
opts: RequestOptions<T>,
): Promise<RequestOptions<T>> {
Expand Down
2 changes: 1 addition & 1 deletion src/_shims/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export type ReadableStream = SelectType<manual.ReadableStream, auto.ReadableStre
// @ts-ignore
export const ReadableStream: SelectType<typeof manual.ReadableStream, typeof auto.ReadableStream>;

export function getMultipartRequestOptions<T extends {} = Record<string, unknown>>(
export function getMultipartRequestOptions<T = Record<string, unknown>>(
form: FormData,
opts: RequestOptions<T>,
): Promise<RequestOptions<T>>;
Expand Down
2 changes: 1 addition & 1 deletion src/_shims/node-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ async function fileFromPath(path: string, ...args: any[]): Promise<File> {
const defaultHttpAgent: Agent = new KeepAliveAgent({ keepAlive: true, timeout: 5 * 60 * 1000 });
const defaultHttpsAgent: Agent = new KeepAliveAgent.HttpsAgent({ keepAlive: true, timeout: 5 * 60 * 1000 });

async function getMultipartRequestOptions<T extends {} = Record<string, unknown>>(
async function getMultipartRequestOptions<T = Record<string, unknown>>(
form: fd.FormData,
opts: RequestOptions<T>,
): Promise<RequestOptions<T>> {
Expand Down
2 changes: 1 addition & 1 deletion src/_shims/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export interface Shims {
Blob: any;
File: any;
ReadableStream: any;
getMultipartRequestOptions: <T extends {} = Record<string, unknown>>(
getMultipartRequestOptions: <T = Record<string, unknown>>(
form: Shims['FormData'],
opts: RequestOptions<T>,
) => Promise<RequestOptions<T>>;
Expand Down
2 changes: 1 addition & 1 deletion src/_shims/web-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export function getRuntime({ manuallyImported }: { manuallyImported?: boolean }
}
}
),
getMultipartRequestOptions: async <T extends {} = Record<string, unknown>>(
getMultipartRequestOptions: async <T = Record<string, unknown>>(
// @ts-ignore
form: FormData,
opts: RequestOptions<T>,
Expand Down
38 changes: 19 additions & 19 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,27 +208,27 @@ export abstract class APIClient {
return `stainless-node-retry-${uuid4()}`;
}

get<Req extends {}, Rsp>(path: string, opts?: PromiseOrValue<RequestOptions<Req>>): APIPromise<Rsp> {
get<Req, Rsp>(path: string, opts?: PromiseOrValue<RequestOptions<Req>>): APIPromise<Rsp> {
return this.methodRequest('get', path, opts);
}

post<Req extends {}, Rsp>(path: string, opts?: PromiseOrValue<RequestOptions<Req>>): APIPromise<Rsp> {
post<Req, Rsp>(path: string, opts?: PromiseOrValue<RequestOptions<Req>>): APIPromise<Rsp> {
return this.methodRequest('post', path, opts);
}

patch<Req extends {}, Rsp>(path: string, opts?: PromiseOrValue<RequestOptions<Req>>): APIPromise<Rsp> {
patch<Req, Rsp>(path: string, opts?: PromiseOrValue<RequestOptions<Req>>): APIPromise<Rsp> {
return this.methodRequest('patch', path, opts);
}

put<Req extends {}, Rsp>(path: string, opts?: PromiseOrValue<RequestOptions<Req>>): APIPromise<Rsp> {
put<Req, Rsp>(path: string, opts?: PromiseOrValue<RequestOptions<Req>>): APIPromise<Rsp> {
return this.methodRequest('put', path, opts);
}

delete<Req extends {}, Rsp>(path: string, opts?: PromiseOrValue<RequestOptions<Req>>): APIPromise<Rsp> {
delete<Req, Rsp>(path: string, opts?: PromiseOrValue<RequestOptions<Req>>): APIPromise<Rsp> {
return this.methodRequest('delete', path, opts);
}

private methodRequest<Req extends {}, Rsp>(
private methodRequest<Req, Rsp>(
method: HTTPMethod,
path: string,
opts?: PromiseOrValue<RequestOptions<Req>>,
Expand Down Expand Up @@ -260,9 +260,7 @@ export abstract class APIClient {
return null;
}

buildRequest<Req extends {}>(
options: FinalRequestOptions<Req>,
): { req: RequestInit; url: string; timeout: number } {
buildRequest<Req>(options: FinalRequestOptions<Req>): { req: RequestInit; url: string; timeout: number } {
const { method, path, query, headers: headers = {} } = options;

const body =
Expand Down Expand Up @@ -364,15 +362,15 @@ export abstract class APIClient {
return APIError.generate(status, error, message, headers);
}

request<Req extends {}, Rsp>(
request<Req, Rsp>(
options: PromiseOrValue<FinalRequestOptions<Req>>,
remainingRetries: number | null = null,
): APIPromise<Rsp> {
return new APIPromise(this.makeRequest(options, remainingRetries));
}

private async makeRequest(
optionsInput: PromiseOrValue<FinalRequestOptions>,
private async makeRequest<Req>(
optionsInput: PromiseOrValue<FinalRequestOptions<Req>>,
retriesRemaining: number | null,
): Promise<APIResponseProps> {
const options = await optionsInput;
Expand Down Expand Up @@ -434,7 +432,7 @@ export abstract class APIClient {
return new PagePromise<PageClass, Item>(this, request, Page);
}

buildURL<Req extends Record<string, unknown>>(path: string, query: Req | null | undefined): string {
buildURL<Req>(path: string, query: Req | null | undefined): string {
const url =
isAbsoluteURL(path) ?
new URL(path)
Expand Down Expand Up @@ -608,7 +606,7 @@ export abstract class AbstractPage<Item> implements AsyncIterable<Item> {
);
}
const nextOptions = { ...this.options };
if ('params' in nextInfo) {
if ('params' in nextInfo && typeof nextOptions.query === 'object') {
nextOptions.query = { ...nextOptions.query, ...nextInfo.params };
} else if ('url' in nextInfo) {
const params = [...Object.entries(nextOptions.query || {}), ...nextInfo.url.searchParams.entries()];
Expand Down Expand Up @@ -706,7 +704,7 @@ export type Headers = Record<string, string | null | undefined>;
export type DefaultQuery = Record<string, string | undefined>;
export type KeysEnum<T> = { [P in keyof Required<T>]: true };

export type RequestOptions<Req extends {} = Record<string, unknown> | Readable> = {
export type RequestOptions<Req = unknown | Record<string, unknown> | Readable> = {
method?: HTTPMethod;
path?: string;
query?: Req | undefined;
Expand Down Expand Up @@ -743,7 +741,7 @@ const requestOptionsKeys: KeysEnum<RequestOptions> = {
__binaryResponse: true,
};

export const isRequestOptions = (obj: unknown): obj is RequestOptions<Record<string, unknown> | Readable> => {
export const isRequestOptions = (obj: unknown): obj is RequestOptions => {
return (
typeof obj === 'object' &&
obj !== null &&
Expand All @@ -752,7 +750,7 @@ export const isRequestOptions = (obj: unknown): obj is RequestOptions<Record<str
);
};

export type FinalRequestOptions<Req extends {} = Record<string, unknown> | Readable> = RequestOptions<Req> & {
export type FinalRequestOptions<Req = unknown | Record<string, unknown> | Readable> = RequestOptions<Req> & {
method: HTTPMethod;
path: string;
};
Expand Down Expand Up @@ -954,14 +952,16 @@ export const ensurePresent = <T>(value: T | null | undefined): T => {
/**
* Read an environment variable.
*
* Trims beginning and trailing whitespace.
*
* Will return undefined if the environment variable doesn't exist or cannot be accessed.
*/
export const readEnv = (env: string): string | undefined => {
if (typeof process !== 'undefined') {
return process.env?.[env] ?? undefined;
return process.env?.[env]?.trim() ?? undefined;
}
if (typeof Deno !== 'undefined') {
return Deno.env?.get?.(env);
return Deno.env?.get?.(env)?.trim();
}
return undefined;
};
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export class Orb extends Core.APIClient {
const options: ClientOptions = {
apiKey,
...opts,
baseURL: baseURL ?? `https://api.withorb.com/v1`,
baseURL: baseURL || `https://api.withorb.com/v1`,
};

super({
Expand Down
4 changes: 4 additions & 0 deletions src/lib/.keep
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
File generated from our OpenAPI spec by Stainless.

This directory can be used to store custom files to expand the SDK.
It is ignored by Stainless code generation and its content (other than this keep file) won't be touched.
4 changes: 2 additions & 2 deletions src/uploads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ export const isMultipartBody = (body: any): body is MultipartBody =>
* Returns a multipart/form-data request if any part of the given request body contains a File / Blob value.
* Otherwise returns the request as is.
*/
export const maybeMultipartFormRequestOptions = async <T extends {} = Record<string, unknown>>(
export const maybeMultipartFormRequestOptions = async <T = Record<string, unknown>>(
opts: RequestOptions<T>,
): Promise<RequestOptions<T | MultipartBody>> => {
if (!hasUploadableValue(opts.body)) return opts;
Expand All @@ -193,7 +193,7 @@ export const maybeMultipartFormRequestOptions = async <T extends {} = Record<str
return getMultipartRequestOptions(form, opts);
};

export const multipartFormRequestOptions = async <T extends {} = Record<string, unknown>>(
export const multipartFormRequestOptions = async <T = Record<string, unknown>>(
opts: RequestOptions<T>,
): Promise<RequestOptions<T | MultipartBody>> => {
const form = await createForm(opts.body);
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 = '1.34.1'; // x-release-please-version
export const VERSION = '1.34.2'; // x-release-please-version
14 changes: 13 additions & 1 deletion tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ describe('instantiate client', () => {
});

afterEach(() => {
process.env['SINK_BASE_URL'] = undefined;
process.env['ORB_BASE_URL'] = undefined;
});

test('explicit option', () => {
Expand All @@ -147,6 +147,18 @@ describe('instantiate client', () => {
const client = new Orb({ apiKey: 'My API Key' });
expect(client.baseURL).toEqual('https://example.com/from_env');
});

test('empty env variable', () => {
process.env['ORB_BASE_URL'] = ''; // empty
const client = new Orb({ apiKey: 'My API Key' });
expect(client.baseURL).toEqual('https://api.withorb.com/v1');
});

test('blank env variable', () => {
process.env['ORB_BASE_URL'] = ' '; // blank
const client = new Orb({ apiKey: 'My API Key' });
expect(client.baseURL).toEqual('https://api.withorb.com/v1');
});
});

test('maxRetries option is correctly set', () => {
Expand Down