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: 0.32.1 #349

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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 @@
{
".": "0.32.0"
".": "0.32.1"
}
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## 0.32.1 (2024-12-12)

Full Changelog: [v0.32.0...v0.32.1](https://github.com/blockaid-official/blockaid-client-node/compare/v0.32.0...v0.32.1)

### Chores

* **internal:** codegen related update ([#350](https://github.com/blockaid-official/blockaid-client-node/issues/350)) ([9bffe7b](https://github.com/blockaid-official/blockaid-client-node/commit/9bffe7b35a0c4966d666dad4a15f732ebb694e60))
* **internal:** remove unnecessary getRequestClient function ([#348](https://github.com/blockaid-official/blockaid-client-node/issues/348)) ([e02da68](https://github.com/blockaid-official/blockaid-client-node/commit/e02da68a2c64b13c0e9d403e3b25deac1421d4a7))

## 0.32.0 (2024-12-10)

Full Changelog: [v0.31.0...v0.32.0](https://github.com/blockaid-official/blockaid-client-node/compare/v0.31.0...v0.32.0)
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": "@blockaid/client",
"version": "0.32.0",
"version": "0.32.1",
"description": "The official TypeScript library for the Blockaid API",
"author": "Blockaid <feedback@blockaid.io>",
"types": "dist/index.d.ts",
Expand Down
18 changes: 6 additions & 12 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -523,19 +523,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 @@ -976,8 +970,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 BlockaidError extends Error {}

export class APIError extends BlockaidError {
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 BlockaidError {
/** 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 BlockaidError {
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 BlockaidError {
}
}

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> {}
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.32.0'; // x-release-please-version
export const VERSION = '0.32.1'; // x-release-please-version
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1370,9 +1370,9 @@ create-require@^1.1.0:
integrity sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==

cross-spawn@^7.0.2, cross-spawn@^7.0.3:
version "7.0.3"
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.3.tgz#f73a85b9d5d41d045551c177e2882d4ac85728a6"
integrity sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==
version "7.0.6"
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.6.tgz#8a58fe78f00dcd70c370451759dfbfaf03e8ee9f"
integrity sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==
dependencies:
path-key "^3.1.0"
shebang-command "^2.0.0"
Expand Down
Loading