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.1.0-alpha.1 #5

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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ yarn-error.log
codegen.log
Brewfile.lock.json
dist
/deno
dist-deno
/*.tgz
.idea/

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-alpha.4"
".": "0.0.1-beta.5"
}
4 changes: 2 additions & 2 deletions .stats.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configured_endpoints: 9
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/nen-labs%2Fsteel-c779cb037a7fbaceab591baad044e34b51395196dbaf16de14ad3216458cb332.yml
configured_endpoints: 6
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/nen-labs%2Fsteel-e2f35e13822cd958a10f588d91b72e19c31c4c6ad0f5c1fe7c8d13b8f03e6843.yml
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## 0.0.1-beta.5 (2024-11-07)

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

### Features

* **api:** api update ([#4](https://github.com/steel-dev/steel-node/issues/4)) ([a82334f](https://github.com/steel-dev/steel-node/commit/a82334f88f984267c13703634dc7b36f97cee644))
* **api:** api update ([#6](https://github.com/steel-dev/steel-node/issues/6)) ([3e1cfa7](https://github.com/steel-dev/steel-node/commit/3e1cfa77356fd773581a2d351168c0333d4ffec3))

## 0.1.0-alpha.4 (2024-10-16)

Full Changelog: [v0.1.0-alpha.3...v0.1.0-alpha.4](https://github.com/steel-dev/steel-node/compare/v0.1.0-alpha.3...v0.1.0-alpha.4)
Expand Down
53 changes: 20 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,7 @@ const client = new Steel({
});

async function main() {
const params: Steel.ScrapeParams = {
url: 'https://www.eff.org/cyberspace-independence',
format: ['markdown'],
};
const response: Steel.ScrapeResponse = await client.scrape(params);
const session: Steel.Session = await client.sessions.create();
}

main();
Expand All @@ -69,17 +65,15 @@ a subclass of `APIError` will be thrown:
<!-- prettier-ignore -->
```ts
async function main() {
const response = await client
.scrape({ url: 'https://www.eff.org/cyberspace-independence', format: ['markdown'] })
.catch(async (err) => {
if (err instanceof Steel.APIError) {
console.log(err.status); // 400
console.log(err.name); // BadRequestError
console.log(err.headers); // {server: 'nginx', ...}
} else {
throw err;
}
});
const session = await client.sessions.create().catch(async (err) => {
if (err instanceof Steel.APIError) {
console.log(err.status); // 400
console.log(err.name); // BadRequestError
console.log(err.headers); // {server: 'nginx', ...}
} else {
throw err;
}
});
}

main();
Expand Down Expand Up @@ -114,7 +108,7 @@ const client = new Steel({
});

// Or, configure per-request:
await client.scrape({ url: 'https://www.eff.org/cyberspace-independence', format: ['markdown'] }, {
await client.sessions.create({
maxRetries: 5,
});
```
Expand All @@ -131,7 +125,7 @@ const client = new Steel({
});

// Override per-request:
await client.scrape({ url: 'https://www.eff.org/cyberspace-independence', format: ['markdown'] }, {
await client.sessions.create({
timeout: 5 * 1000,
});
```
Expand All @@ -143,7 +137,7 @@ Note that requests which time out will be [retried twice by default](#retries).
## Auto-pagination

List methods in the Steel API are paginated.
You can use `for await … of` syntax to iterate through items across all pages:
You can use the `for await … of` syntax to iterate through items across all pages:

```ts
async function fetchAllSessions(params) {
Expand All @@ -156,7 +150,7 @@ async function fetchAllSessions(params) {
}
```

Alternatively, you can make request a single page at a time:
Alternatively, you can request a single page at a time:

```ts
let page = await client.sessions.list({ status: 'live' });
Expand All @@ -183,17 +177,13 @@ You can also use the `.withResponse()` method to get the raw `Response` along wi
```ts
const client = new Steel();

const response = await client
.scrape({ url: 'https://www.eff.org/cyberspace-independence', format: ['markdown'] })
.asResponse();
const response = await client.sessions.create().asResponse();
console.log(response.headers.get('X-My-Header'));
console.log(response.statusText); // access the underlying Response object

const { data: response, response: raw } = await client
.scrape({ url: 'https://www.eff.org/cyberspace-independence', format: ['markdown'] })
.withResponse();
const { data: session, response: raw } = await client.sessions.create().withResponse();
console.log(raw.headers.get('X-My-Header'));
console.log(response.content);
console.log(session.id);
```

### Making custom/undocumented requests
Expand Down Expand Up @@ -297,12 +287,9 @@ const client = new Steel({
});

// Override per-request:
await client.scrape(
{ url: 'https://www.eff.org/cyberspace-independence', format: ['markdown'] },
{
httpAgent: new http.Agent({ keepAlive: false }),
},
);
await client.sessions.create({
httpAgent: new http.Agent({ keepAlive: false }),
});
```

## Semantic versioning
Expand Down
12 changes: 0 additions & 12 deletions api.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
# 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
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "steel-sdk",
"version": "0.1.0-alpha.4",
"version": "0.0.1-beta.5",
"description": "The official TypeScript library for the Steel API",
"author": "Steel <[email protected]>",
"types": "dist/index.d.ts",
Expand All @@ -10,7 +10,7 @@
"license": "Apache-2.0",
"packageManager": "[email protected]",
"files": [
"*"
"**/*"
],
"private": false,
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion scripts/build
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ node scripts/utils/postprocess-files.cjs
(cd dist && node -e 'require("steel-sdk")')
(cd dist && node -e 'import("steel-sdk")' --input-type=module)

if command -v deno &> /dev/null && [ -e ./scripts/build-deno ]
if [ -e ./scripts/build-deno ]
then
./scripts/build-deno
fi
20 changes: 12 additions & 8 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,9 +351,13 @@ export abstract class APIClient {
delete reqHeaders['content-type'];
}

// Don't set the retry count header if it was already set or removed by the caller. We check `headers`,
// which can contain nulls, instead of `reqHeaders` to account for the removal case.
if (getHeader(headers, 'x-stainless-retry-count') === undefined) {
// Don't set the retry count header if it was already set or removed through default headers or by the
// caller. We check `defaultHeaders` and `headers`, which can contain nulls, instead of `reqHeaders` to
// account for the removal case.
if (
getHeader(defaultHeaders, 'x-stainless-retry-count') === undefined &&
getHeader(headers, 'x-stainless-retry-count') === undefined
) {
reqHeaders['x-stainless-retry-count'] = String(retryCount);
}

Expand Down Expand Up @@ -392,7 +396,7 @@ export abstract class APIClient {
error: Object | undefined,
message: string | undefined,
headers: Headers | undefined,
) {
): APIError {
return APIError.generate(status, error, message, headers);
}

Expand Down Expand Up @@ -664,17 +668,17 @@ export abstract class AbstractPage<Item> implements AsyncIterable<Item> {
return await this.#client.requestAPIList(this.constructor as any, nextOptions);
}

async *iterPages() {
async *iterPages(): AsyncGenerator<this> {
// eslint-disable-next-line @typescript-eslint/no-this-alias
let page: AbstractPage<Item> = this;
let page: this = this;
yield page;
while (page.hasNextPage()) {
page = await page.getNextPage();
yield page;
}
}

async *[Symbol.asyncIterator]() {
async *[Symbol.asyncIterator](): AsyncGenerator<Item> {
for await (const page of this.iterPages()) {
for (const item of page.getPaginatedItems()) {
yield item;
Expand Down Expand Up @@ -717,7 +721,7 @@ export class PagePromise<
* console.log(item)
* }
*/
async *[Symbol.asyncIterator]() {
async *[Symbol.asyncIterator](): AsyncGenerator<Item> {
const page = await this;
for await (const item of page) {
yield item;
Expand Down
2 changes: 1 addition & 1 deletion src/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class APIError extends SteelError {
errorResponse: Object | undefined,
message: string | undefined,
headers: Headers | undefined,
) {
): APIError {
if (!status) {
return new APIConnectionError({ message, cause: castToError(errorResponse) });
}
Expand Down
93 changes: 39 additions & 54 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

import * as Errors from './error';
import * as Uploads from './uploads';
import { type Agent } from './_shims/index';
import * as Core from './core';
import * as Errors from './error';
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 {
Session,
SessionContext,
SessionCreateParams,
SessionListParams,
SessionListResponse,
SessionListResponsesSessionsCursor,
SessionReleaseAllResponse,
SessionReleaseResponse,
Sessions,
Sessionslist,
} from './resources/sessions';

export interface ClientOptions {
/**
Expand Down Expand Up @@ -123,33 +135,6 @@ 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 @@ -186,7 +171,7 @@ export class Steel extends Core.APIClient {
static fileFromPath = Uploads.fileFromPath;
}

export const {
export {
SteelError,
APIError,
APIConnectionError,
Expand All @@ -200,35 +185,35 @@ export const {
InternalServerError,
PermissionDeniedError,
UnprocessableEntityError,
} = Errors;
} from './error';

export import toFile = Uploads.toFile;
export import fileFromPath = Uploads.fileFromPath;

export namespace Steel {
export import RequestOptions = Core.RequestOptions;
Steel.Sessions = Sessions;
Steel.SessionListResponsesSessionsCursor = SessionListResponsesSessionsCursor;

export declare namespace Steel {
export type RequestOptions = Core.RequestOptions;

export import SessionsCursor = Pagination.SessionsCursor;
export import SessionsCursorParams = Pagination.SessionsCursorParams;
export import SessionsCursorResponse = Pagination.SessionsCursorResponse;

export import PdfResponse = API.PdfResponse;
export import ScrapeResponse = API.ScrapeResponse;
export import ScreenshotResponse = API.ScreenshotResponse;
export import PdfParams = API.PdfParams;
export import ScrapeParams = API.ScrapeParams;
export import ScreenshotParams = API.ScreenshotParams;

export import Sessions = API.Sessions;
export import Session = API.Session;
export import SessionContext = API.SessionContext;
export import Sessionslist = API.Sessionslist;
export import SessionListResponse = API.SessionListResponse;
export import SessionReleaseResponse = API.SessionReleaseResponse;
export import SessionReleaseAllResponse = API.SessionReleaseAllResponse;
export import SessionListResponsesSessionsCursor = API.SessionListResponsesSessionsCursor;
export import SessionCreateParams = API.SessionCreateParams;
export import SessionListParams = API.SessionListParams;
export {
type SessionsCursorParams as SessionsCursorParams,
type SessionsCursorResponse as SessionsCursorResponse,
};

export {
Sessions as Sessions,
type Session as Session,
type SessionContext as SessionContext,
type Sessionslist as Sessionslist,
type SessionListResponse as SessionListResponse,
type SessionReleaseResponse as SessionReleaseResponse,
type SessionReleaseAllResponse as SessionReleaseAllResponse,
SessionListResponsesSessionsCursor as SessionListResponsesSessionsCursor,
type SessionCreateParams as SessionCreateParams,
type SessionListParams as SessionListParams,
};
}

export default Steel;
Loading