Skip to content

Commit

Permalink
Merge pull request #29 from steel-dev/release-please--branches--main-…
Browse files Browse the repository at this point in the history
…-changes--next--components--steel-sdk

release: 0.1.0-beta.6
  • Loading branch information
fukouda authored Dec 19, 2024
2 parents d9476a6 + 6651c08 commit 7b94ebe
Show file tree
Hide file tree
Showing 14 changed files with 402 additions and 53 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-beta.5"
".": "0.1.0-beta.6"
}
4 changes: 2 additions & 2 deletions .stats.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configured_endpoints: 6
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/nen-labs%2Fsteel-514e0d3ea8fff8f5a712a5a8f780dfef6caf0c8ae99f472fd895dbd7c1eab6a4.yml
configured_endpoints: 9
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/nen-labs%2Fsteel-73f12c3021fc56466b869b17a82fec982131d51e383151c897908d874bc188da.yml
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# Changelog

## 0.1.0-beta.6 (2024-12-19)

Full Changelog: [v0.1.0-beta.5...v0.1.0-beta.6](https://github.com/steel-dev/steel-node/compare/v0.1.0-beta.5...v0.1.0-beta.6)

### Features

* **api:** api update ([#34](https://github.com/steel-dev/steel-node/issues/34)) ([51a7bbe](https://github.com/steel-dev/steel-node/commit/51a7bbe4d8be15b77f7831f5da74962212e9b29e))


### Chores

* **internal:** bump cross-spawn to v7.0.6 ([#28](https://github.com/steel-dev/steel-node/issues/28)) ([916d489](https://github.com/steel-dev/steel-node/commit/916d489b7ca78156fa7ce5e40ba8bc9ff427bc47))
* **internal:** codegen related update ([#32](https://github.com/steel-dev/steel-node/issues/32)) ([d417931](https://github.com/steel-dev/steel-node/commit/d417931a5ac720d8131e8955b050a7473daee5e6))
* **internal:** fix some typos ([#33](https://github.com/steel-dev/steel-node/issues/33)) ([fc64e4a](https://github.com/steel-dev/steel-node/commit/fc64e4a7163c2ecfd5469c4480832a768f1c02cb))
* **types:** nicer error class types + jsdocs ([#30](https://github.com/steel-dev/steel-node/issues/30)) ([c35bfa6](https://github.com/steel-dev/steel-node/commit/c35bfa6f9afaad73143e18ccd4b91c013a081f7f))

## 0.1.0-beta.5 (2024-12-03)

Full Changelog: [v0.1.0-beta.4...v0.1.0-beta.5](https://github.com/steel-dev/steel-node/compare/v0.1.0-beta.4...v0.1.0-beta.5)
Expand Down
14 changes: 14 additions & 0 deletions api.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Steel

Types:

- <code><a href="./src/resources/top-level.ts">PdfResponse</a></code>
- <code><a href="./src/resources/top-level.ts">ScrapeResponse</a></code>
- <code><a href="./src/resources/top-level.ts">ScreenshotResponse</a></code>

Methods:

- <code title="post /v1/pdf">client.<a href="./src/index.ts">pdf</a>({ ...params }) -> PdfResponse</code>
- <code title="post /v1/scrape">client.<a href="./src/index.ts">scrape</a>({ ...params }) -> ScrapeResponse</code>
- <code title="post /v1/screenshot">client.<a href="./src/index.ts">screenshot</a>({ ...params }) -> ScreenshotResponse</code>

# Sessions

Types:
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": "steel-sdk",
"version": "0.1.0-beta.5",
"version": "0.1.0-beta.6",
"description": "The official TypeScript library for the Steel API",
"author": "Steel <[email protected]>",
"types": "dist/index.d.ts",
Expand Down
8 changes: 4 additions & 4 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export abstract class APIClient {
maxRetries = 2,
timeout = 60000, // 1 minute
httpAgent,
fetch: overridenFetch,
fetch: overriddenFetch,
}: {
baseURL: string;
maxRetries?: number | undefined;
Expand All @@ -176,7 +176,7 @@ export abstract class APIClient {
this.timeout = validatePositiveInteger('timeout', timeout);
this.httpAgent = httpAgent;

this.fetch = overridenFetch ?? fetch;
this.fetch = overriddenFetch ?? fetch;
}

protected authHeaders(opts: FinalRequestOptions): Headers {
Expand Down Expand Up @@ -976,8 +976,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 SteelError extends Error {}

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

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> {}
45 changes: 45 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ import * as Pagination from './pagination';
import { type SessionsCursorParams, SessionsCursorResponse } from './pagination';
import * as Uploads from './uploads';
import * as API from './resources/index';
import * as TopLevelAPI from './resources/top-level';
import {
PdfParams,
PdfResponse,
ScrapeParams,
ScrapeResponse,
ScreenshotParams,
ScreenshotResponse,
} from './resources/top-level';
import {
Session,
SessionContext,
Expand Down Expand Up @@ -137,6 +146,33 @@ export class Steel extends Core.APIClient {

sessions: API.Sessions = new API.Sessions(this);

/**
* Generates a PDF from a specified webpage.
*/
pdf(body: TopLevelAPI.PdfParams, options?: Core.RequestOptions): Core.APIPromise<TopLevelAPI.PdfResponse> {
return this.post('/v1/pdf', { body, ...options });
}

/**
* Extracts content from a specified URL.
*/
scrape(
body: TopLevelAPI.ScrapeParams,
options?: Core.RequestOptions,
): Core.APIPromise<TopLevelAPI.ScrapeResponse> {
return this.post('/v1/scrape', { body, ...options });
}

/**
* Captures a screenshot of a specified webpage.
*/
screenshot(
body: TopLevelAPI.ScreenshotParams,
options?: Core.RequestOptions,
): Core.APIPromise<TopLevelAPI.ScreenshotResponse> {
return this.post('/v1/screenshot', { body, ...options });
}

protected override defaultQuery(): Core.DefaultQuery | undefined {
return this._options.defaultQuery;
}
Expand Down Expand Up @@ -184,6 +220,15 @@ export declare namespace Steel {
type SessionsCursorResponse as SessionsCursorResponse,
};

export {
type PdfResponse as PdfResponse,
type ScrapeResponse as ScrapeResponse,
type ScreenshotResponse as ScreenshotResponse,
type PdfParams as PdfParams,
type ScrapeParams as ScrapeParams,
type ScreenshotParams as ScreenshotParams,
};

export {
Sessions as Sessions,
type Session as Session,
Expand Down
8 changes: 8 additions & 0 deletions src/resources/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,11 @@ export {
type SessionReleaseParams,
type SessionReleaseAllParams,
} from './sessions';
export {
type PdfResponse,
type ScrapeResponse,
type ScreenshotResponse,
type PdfParams,
type ScrapeParams,
type ScreenshotParams,
} from './top-level';
Loading

0 comments on commit 7b94ebe

Please sign in to comment.