Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release: 1.3.0 #16

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.2.1"
".": "1.3.0"
}
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configured_endpoints: 50
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/julep-ai-inc-dash%2Fjulep-f47e1a49bc70ec6069357e446dd826357b4402328fde2500da313c56ade84a0b.yml
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/julep-ai-inc-dash%2Fjulep-f81af3213db01ef83d8f104374a7f47b8d46c3817e26d587a555ae05f2cae02c.yml
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Changelog

## 1.3.0 (2024-09-23)

Full Changelog: [v1.2.1...v1.3.0](https://github.com/julep-ai/node-sdk/compare/v1.2.1...v1.3.0)

### Features

* **api:** OpenAPI spec update via Stainless API ([#18](https://github.com/julep-ai/node-sdk/issues/18)) ([cd15af0](https://github.com/julep-ai/node-sdk/commit/cd15af02f95bd82f296b2f050d9fc4659aaa0940))
* **client:** send retry count header ([#17](https://github.com/julep-ai/node-sdk/issues/17)) ([f908edb](https://github.com/julep-ai/node-sdk/commit/f908edb94c57723e77497aa7a6381f26e5b785c5))


### Chores

* **internal:** codegen related update ([#15](https://github.com/julep-ai/node-sdk/issues/15)) ([5c5e049](https://github.com/julep-ai/node-sdk/commit/5c5e04930da23a0ff4f66fab395c6c1e3e42832c))

## 1.2.1 (2024-09-19)

Full Changelog: [v1.2.0...v1.2.1](https://github.com/julep-ai/node-sdk/compare/v1.2.0...v1.2.1)
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": "@julep/sdk",
"version": "1.2.1",
"version": "1.3.0",
"description": "The official TypeScript library for the Julep API",
"author": "Julep <[email protected]>",
"types": "dist/index.d.ts",
Expand Down
16 changes: 12 additions & 4 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,10 @@ export abstract class APIClient {
return null;
}

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

const body =
Expand Down Expand Up @@ -306,7 +309,7 @@ export abstract class APIClient {
headers[this.idempotencyHeader] = options.idempotencyKey;
}

const reqHeaders = this.buildHeaders({ options, headers, contentLength });
const reqHeaders = this.buildHeaders({ options, headers, contentLength, retryCount });

const req: RequestInit = {
method,
Expand All @@ -325,10 +328,12 @@ export abstract class APIClient {
options,
headers,
contentLength,
retryCount,
}: {
options: FinalRequestOptions;
headers: Record<string, string | null | undefined>;
contentLength: string | null | undefined;
retryCount: number;
}): Record<string, string> {
const reqHeaders: Record<string, string> = {};
if (contentLength) {
Expand All @@ -344,6 +349,8 @@ export abstract class APIClient {
delete reqHeaders['content-type'];
}

reqHeaders['x-stainless-retry-count'] = String(retryCount);

this.validateHeaders(reqHeaders, headers);

return reqHeaders;
Expand Down Expand Up @@ -395,13 +402,14 @@ export abstract class APIClient {
retriesRemaining: number | null,
): Promise<APIResponseProps> {
const options = await optionsInput;
const maxRetries = options.maxRetries ?? this.maxRetries;
if (retriesRemaining == null) {
retriesRemaining = options.maxRetries ?? this.maxRetries;
retriesRemaining = maxRetries;
}

await this.prepareOptions(options);

const { req, url, timeout } = this.buildRequest(options);
const { req, url, timeout } = this.buildRequest(options, { retryCount: maxRetries - retriesRemaining });

await this.prepareRequest(req, { url, options });

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.2.1'; // x-release-please-version
export const VERSION = '1.3.0'; // x-release-please-version
25 changes: 25 additions & 0 deletions tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,31 @@ describe('retries', () => {
expect(count).toEqual(3);
});

test('retry count header', async () => {
let count = 0;
let capturedRequest: RequestInit | undefined;
const testFetch = async (url: RequestInfo, init: RequestInit = {}): Promise<Response> => {
count++;
if (count <= 2) {
return new Response(undefined, {
status: 429,
headers: {
'Retry-After': '0.1',
},
});
}
capturedRequest = init;
return new Response(JSON.stringify({ a: 1 }), { headers: { 'Content-Type': 'application/json' } });
};

const client = new Julep({ apiKey: 'My API Key', fetch: testFetch, maxRetries: 4 });

expect(await client.request({ path: '/foo', method: 'get' })).toEqual({ a: 1 });

expect((capturedRequest!.headers as Headers)['x-stainless-retry-count']).toEqual('2');
expect(count).toEqual(3);
});

test('retry on 429 with retry-after', async () => {
let count = 0;
const testFetch = async (url: RequestInfo, { signal }: RequestInit = {}): Promise<Response> => {
Expand Down