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.5.0 #114

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.4.0"
".": "1.5.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: 21
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/writerai%2Fwriter-82683f2fd5f8778a27960ebabda40d6dc4640bdfb77ac4ec7f173b8bf8076d3c.yml
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/writerai%2Fwriter-fcd4d82943d0aeefc300520f0ee4684456ef647140f1d6ba9ffcb86278d83d3a.yml
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
# Changelog

## 1.5.0 (2024-12-11)

Full Changelog: [v1.4.0...v1.5.0](https://github.com/writer/writer-node/compare/v1.4.0...v1.5.0)

### Features

* **api:** add streaming to application generation ([#122](https://github.com/writer/writer-node/issues/122)) ([c85d6c6](https://github.com/writer/writer-node/commit/c85d6c62e16d3b9f38b401d162ab144123413b55))
* **api:** api update ([#121](https://github.com/writer/writer-node/issues/121)) ([f4adda0](https://github.com/writer/writer-node/commit/f4adda020d78626ce8ddf24e87c866db24e4baaf))
* **api:** manual updates ([#119](https://github.com/writer/writer-node/issues/119)) ([37f2a16](https://github.com/writer/writer-node/commit/37f2a169c41b4b0a22d7bcff562f6881a66f3af9))
* **internal:** make git install file structure match npm ([#118](https://github.com/writer/writer-node/issues/118)) ([407d303](https://github.com/writer/writer-node/commit/407d303875b56668730be19459cf33441745c577))


### Chores

* **internal:** bump cross-spawn to v7.0.6 ([#124](https://github.com/writer/writer-node/issues/124)) ([b5ccd7c](https://github.com/writer/writer-node/commit/b5ccd7cfba653cd078769eef9900933fed84819f))
* **internal:** codegen related update ([#116](https://github.com/writer/writer-node/issues/116)) ([d632f68](https://github.com/writer/writer-node/commit/d632f686120b920e06dfa7a2dc76ddf651da7357))
* **internal:** remove unnecessary getRequestClient function ([#123](https://github.com/writer/writer-node/issues/123)) ([8e9e6f0](https://github.com/writer/writer-node/commit/8e9e6f02a09bf3c31bdeb0c616ab51800696d2ed))
* **internal:** update isAbsoluteURL ([#126](https://github.com/writer/writer-node/issues/126)) ([0a676eb](https://github.com/writer/writer-node/commit/0a676eba5b7a8330fe6b196e362c105d8f3049c6))
* **internal:** version bump ([#113](https://github.com/writer/writer-node/issues/113)) ([37a3f70](https://github.com/writer/writer-node/commit/37a3f705d82f14269e925377dc09d9869a653dc8))
* **internal:** version bump ([#115](https://github.com/writer/writer-node/issues/115)) ([9309158](https://github.com/writer/writer-node/commit/930915807369000620132d52c5f45df6bd3462fb))
* **types:** nicer error class types + jsdocs ([#125](https://github.com/writer/writer-node/issues/125)) ([a94669a](https://github.com/writer/writer-node/commit/a94669a86363b394efc1d045144eff4c4e0ac257))

## 1.4.0 (2024-11-20)

Full Changelog: [v1.3.0...v1.4.0](https://github.com/writer/writer-node/compare/v1.3.0...v1.4.0)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ The following runtimes are supported:

- Web browsers (Up-to-date Chrome, Firefox, Safari, Edge, and more)
- Node.js 18 LTS or later ([non-EOL](https://endoflife.date/nodejs)) versions.
- Deno v1.28.0 or higher, using `import Writer from "npm:writer-sdk"`.
- Deno v1.28.0 or higher.
- Bun 1.0 or later.
- Cloudflare Workers.
- Vercel Edge Runtime.
Expand Down
1 change: 1 addition & 0 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

Types:

- <code><a href="./src/resources/applications.ts">ApplicationGenerateContentChunk</a></code>
- <code><a href="./src/resources/applications.ts">ApplicationGenerateContentResponse</a></code>

Methods:
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "writer-sdk",
"version": "1.4.0",
"version": "1.5.0",
"description": "The official TypeScript library for the Writer API",
"author": "Writer <[email protected]>",
"types": "dist/index.d.ts",
Expand All @@ -18,7 +18,7 @@
"build": "./scripts/build",
"prepublishOnly": "echo 'to publish, run yarn build && (cd dist; yarn publish)' && exit 1",
"format": "prettier --write --cache --cache-strategy metadata . !dist",
"prepare": "if ./scripts/utils/check-is-in-git-install.sh; then ./scripts/build; fi",
"prepare": "if ./scripts/utils/check-is-in-git-install.sh; then ./scripts/build && ./scripts/utils/git-swap.sh; fi",
"tsn": "ts-node -r tsconfig-paths/register",
"lint": "./scripts/lint",
"fix": "./scripts/format"
Expand Down
2 changes: 1 addition & 1 deletion scripts/build
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ npm exec tsc-multi
# copy over handwritten .js/.mjs/.d.ts files
cp src/_shims/*.{d.ts,js,mjs,md} dist/_shims
cp src/_shims/auto/*.{d.ts,js,mjs} dist/_shims/auto
# we need to add exports = module.exports = Writer Node to index.js;
# we need to add exports = module.exports = Writer to index.js;
# No way to get that from index.ts because it would cause compile errors
# when building .mjs
node scripts/utils/fix-index-exports.cjs
Expand Down
2 changes: 1 addition & 1 deletion scripts/utils/check-is-in-git-install.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
# Check if you happen to call prepare for a repository that's already in node_modules.
[ "$(basename "$(dirname "$PWD")")" = 'node_modules' ] ||
# The name of the containing directory that 'npm` uses, which looks like
Expand Down
13 changes: 13 additions & 0 deletions scripts/utils/git-swap.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash
set -exuo pipefail
# the package is published to NPM from ./dist
# we want the final file structure for git installs to match the npm installs, so we

# delete everything except ./dist and ./node_modules
find . -maxdepth 1 -mindepth 1 ! -name 'dist' ! -name 'node_modules' -exec rm -rf '{}' +

# move everything from ./dist to .
mv dist/* .

# delete the now-empty ./dist
rmdir dist
18 changes: 6 additions & 12 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -537,19 +537,13 @@ export abstract class APIClient {
const timeout = setTimeout(() => controller.abort(), ms);

return (
this.getRequestClient()
// use undefined this binding; fetch errors if bound to something else in browser/cloudflare
.fetch.call(undefined, url, { signal: controller.signal as any, ...options })
.finally(() => {
clearTimeout(timeout);
})
// use undefined this binding; fetch errors if bound to something else in browser/cloudflare
this.fetch.call(undefined, url, { signal: controller.signal as any, ...options }).finally(() => {
clearTimeout(timeout);
})
);
}

protected getRequestClient(): RequestClient {
return { fetch: this.fetch };
}

private shouldRetry(response: Response): boolean {
// Note this is not a standard header.
const shouldRetryHeader = response.headers.get('x-should-retry');
Expand Down Expand Up @@ -992,8 +986,8 @@ export const safeJSON = (text: string) => {
}
};

// https://stackoverflow.com/a/19709846
const startsWithSchemeRegexp = new RegExp('^(?:[a-z]+:)?//', 'i');
// https://url.spec.whatwg.org/#url-scheme-string
const startsWithSchemeRegexp = /^[a-z][a-z0-9+.-]*:/i;
const isAbsoluteURL = (url: string): boolean => {
return startsWithSchemeRegexp.test(url);
};
Expand Down
64 changes: 24 additions & 40 deletions src/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@ import { castToError, Headers } from './core';

export class WriterError extends Error {}

export class APIError extends WriterError {
readonly status: number | undefined;
readonly headers: Headers | undefined;
readonly error: Object | undefined;

constructor(
status: number | undefined,
error: Object | undefined,
message: string | undefined,
headers: Headers | undefined,
) {
export class APIError<
TStatus extends number | undefined = number | undefined,
THeaders extends Headers | undefined = Headers | undefined,
TError extends Object | undefined = Object | undefined,
> extends WriterError {
/** HTTP status for the response that caused the error */
readonly status: TStatus;
/** HTTP headers for the response that caused the error */
readonly headers: THeaders;
/** JSON body of the response that caused the error */
readonly error: TError;

constructor(status: TStatus, error: TError, message: string | undefined, headers: THeaders) {
super(`${APIError.makeMessage(status, error, message)}`);
this.status = status;
this.headers = headers;
Expand Down Expand Up @@ -48,7 +50,7 @@ export class APIError extends WriterError {
message: string | undefined,
headers: Headers | undefined,
): APIError {
if (!status) {
if (!status || !headers) {
return new APIConnectionError({ message, cause: castToError(errorResponse) });
}

Expand Down Expand Up @@ -90,17 +92,13 @@ export class APIError extends WriterError {
}
}

export class APIUserAbortError extends APIError {
override readonly status: undefined = undefined;

export class APIUserAbortError extends APIError<undefined, undefined, undefined> {
constructor({ message }: { message?: string } = {}) {
super(undefined, undefined, message || 'Request was aborted.', undefined);
}
}

export class APIConnectionError extends APIError {
override readonly status: undefined = undefined;

export class APIConnectionError extends APIError<undefined, undefined, undefined> {
constructor({ message, cause }: { message?: string | undefined; cause?: Error | undefined }) {
super(undefined, undefined, message || 'Connection error.', undefined);
// in some environments the 'cause' property is already declared
Expand All @@ -115,32 +113,18 @@ export class APIConnectionTimeoutError extends APIConnectionError {
}
}

export class BadRequestError extends APIError {
override readonly status: 400 = 400;
}
export class BadRequestError extends APIError<400, Headers> {}

export class AuthenticationError extends APIError {
override readonly status: 401 = 401;
}
export class AuthenticationError extends APIError<401, Headers> {}

export class PermissionDeniedError extends APIError {
override readonly status: 403 = 403;
}
export class PermissionDeniedError extends APIError<403, Headers> {}

export class NotFoundError extends APIError {
override readonly status: 404 = 404;
}
export class NotFoundError extends APIError<404, Headers> {}

export class ConflictError extends APIError {
override readonly status: 409 = 409;
}
export class ConflictError extends APIError<409, Headers> {}

export class UnprocessableEntityError extends APIError {
override readonly status: 422 = 422;
}
export class UnprocessableEntityError extends APIError<422, Headers> {}

export class RateLimitError extends APIError {
override readonly status: 429 = 429;
}
export class RateLimitError extends APIError<429, Headers> {}

export class InternalServerError extends APIError {}
export class InternalServerError extends APIError<number, Headers> {}
6 changes: 6 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import { type CursorPageParams, CursorPageResponse } from './pagination';
import * as Uploads from './uploads';
import * as API from './resources/index';
import {
ApplicationGenerateContentChunk,
ApplicationGenerateContentParams,
ApplicationGenerateContentParamsNonStreaming,
ApplicationGenerateContentParamsStreaming,
ApplicationGenerateContentResponse,
Applications,
} from './resources/applications';
Expand Down Expand Up @@ -239,8 +242,11 @@ export declare namespace Writer {

export {
Applications as Applications,
type ApplicationGenerateContentChunk as ApplicationGenerateContentChunk,
type ApplicationGenerateContentResponse as ApplicationGenerateContentResponse,
type ApplicationGenerateContentParams as ApplicationGenerateContentParams,
type ApplicationGenerateContentParamsNonStreaming as ApplicationGenerateContentParamsNonStreaming,
type ApplicationGenerateContentParamsStreaming as ApplicationGenerateContentParamsStreaming,
};

export {
Expand Down
Loading
Loading