diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 491db96..d791adb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,6 +6,7 @@ on: pull_request: branches: - main + - next jobs: lint: diff --git a/.gitignore b/.gitignore index 9a5858a..3eed6dd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.prism.log node_modules yarn-error.log codegen.log diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 5375ff4..fad80ad 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.1.0-alpha.6" + ".": "0.1.0-alpha.7" } diff --git a/.stats.yml b/.stats.yml index cbc2895..4fe8737 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,2 +1,2 @@ configured_endpoints: 1 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/riza%2Friza-api-7e044297a8d3c5c64964532d19e0667b059ef5a121cf3c1e64b806eec55e0767.yml +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/riza%2Friza-api-54658e5464e005c5085a5349bee24047b34a42e1192258b29f6bded0f55bb4e2.yml diff --git a/CHANGELOG.md b/CHANGELOG.md index bb01ce0..2597d42 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,20 @@ # Changelog +## 0.1.0-alpha.7 (2024-07-23) + +Full Changelog: [v0.1.0-alpha.6...v0.1.0-alpha.7](https://github.com/riza-io/riza-api-node/compare/v0.1.0-alpha.6...v0.1.0-alpha.7) + +### Features + +* **api:** OpenAPI spec update via Stainless API ([#17](https://github.com/riza-io/riza-api-node/issues/17)) ([534a73e](https://github.com/riza-io/riza-api-node/commit/534a73ece4c3730ea3a74ba4e65da30901fc0fdd)) + + +### Chores + +* **docs:** mention support of web browser runtimes ([#21](https://github.com/riza-io/riza-api-node/issues/21)) ([d538c1e](https://github.com/riza-io/riza-api-node/commit/d538c1e3fd9391f17c629cbbcff3965b06daa74e)) +* **docs:** minor update to formatting of API link in README ([#20](https://github.com/riza-io/riza-api-node/issues/20)) ([29367ce](https://github.com/riza-io/riza-api-node/commit/29367ce68e828a54a64e881d7e53ac20ebbe90a5)) +* **internal:** codegen related update ([#18](https://github.com/riza-io/riza-api-node/issues/18)) ([6d55d22](https://github.com/riza-io/riza-api-node/commit/6d55d221fae055bacada3d342728a1c0db46cd48)) + ## 0.1.0-alpha.6 (2024-05-22) Full Changelog: [v0.1.0-alpha.5...v0.1.0-alpha.6](https://github.com/riza-io/riza-api-node/compare/v0.1.0-alpha.5...v0.1.0-alpha.6) diff --git a/README.md b/README.md index 2f064c5..14b8240 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ # Riza Node API Library -[![NPM version](https://img.shields.io/npm/v/@riza-io/api.svg)](https://npmjs.org/package/@riza-io/api) +[![NPM version](https://img.shields.io/npm/v/@riza-io/api.svg)](https://npmjs.org/package/@riza-io/api) ![npm bundle size](https://img.shields.io/bundlephobia/minzip/@riza-io/api) This library provides convenient access to the Riza REST API from server-side TypeScript or JavaScript. -The REST API documentation can be found [on docs.riza.io](https://docs.riza.io). The full API of this library can be found in [api.md](api.md). +The REST API documentation can be found on [docs.riza.io](https://docs.riza.io). The full API of this library can be found in [api.md](api.md). It is generated with [Stainless](https://www.stainlessapi.com/). @@ -27,7 +27,7 @@ const riza = new Riza({ }); async function main() { - const commandExecResponse = await riza.command.exec({ code: 'print("Hello world!")', language: 'PYTHON' }); + const commandExecResponse = await riza.command.exec({ code: 'print("Hello world!")' }); console.log(commandExecResponse.exit_code); } @@ -48,7 +48,7 @@ const riza = new Riza({ }); async function main() { - const params: Riza.CommandExecParams = { code: 'print("Hello world!")', language: 'PYTHON' }; + const params: Riza.CommandExecParams = { code: 'print("Hello world!")' }; const commandExecResponse: Riza.CommandExecResponse = await riza.command.exec(params); } @@ -67,7 +67,7 @@ a subclass of `APIError` will be thrown: ```ts async function main() { const commandExecResponse = await riza.command - .exec({ code: 'print("Hello world!")', language: 'PYTHON' }) + .exec({ code: 'print("Hello world!")' }) .catch(async (err) => { if (err instanceof Riza.APIError) { console.log(err.status); // 400 @@ -111,7 +111,7 @@ const riza = new Riza({ }); // Or, configure per-request: -await riza.command.exec({ code: 'print("Hello world!")', language: 'PYTHON' }, { +await riza.command.exec({ code: 'print("Hello world!")' }, { maxRetries: 5, }); ``` @@ -128,7 +128,7 @@ const riza = new Riza({ }); // Override per-request: -await riza.command.exec({ code: 'print("Hello world!")', language: 'PYTHON' }, { +await riza.command.exec({ code: 'print("Hello world!")' }, { timeout: 5 * 1000, }); ``` @@ -149,12 +149,12 @@ You can also use the `.withResponse()` method to get the raw `Response` along wi ```ts const riza = new Riza(); -const response = await riza.command.exec({ code: 'print("Hello world!")', language: 'PYTHON' }).asResponse(); +const response = await riza.command.exec({ code: 'print("Hello world!")' }).asResponse(); console.log(response.headers.get('X-My-Header')); console.log(response.statusText); // access the underlying Response object const { data: commandExecResponse, response: raw } = await riza.command - .exec({ code: 'print("Hello world!")', language: 'PYTHON' }) + .exec({ code: 'print("Hello world!")' }) .withResponse(); console.log(raw.headers.get('X-My-Header')); console.log(commandExecResponse.exit_code); @@ -262,7 +262,7 @@ const riza = new Riza({ // Override per-request: await riza.command.exec( - { code: 'print("Hello world!")', language: 'PYTHON' }, + { code: 'print("Hello world!")' }, { httpAgent: new http.Agent({ keepAlive: false }), }, @@ -287,14 +287,6 @@ TypeScript >= 4.5 is supported. The following runtimes are supported: -- Node.js 18 LTS or later ([non-EOL](https://endoflife.date/nodejs)) versions. -- Deno v1.28.0 or higher, using `import Riza from "npm:@riza-io/api"`. -- Bun 1.0 or later. -- Cloudflare Workers. -- Vercel Edge Runtime. -- Jest 28 or greater with the `"node"` environment (`"jsdom"` is not supported at this time). -- Nitro v2.6 or greater. - Note that React Native is not supported at this time. If you are interested in other runtime environments, please open or upvote an issue on GitHub. diff --git a/package.json b/package.json index d99e389..2375309 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@riza-io/api", - "version": "0.1.0-alpha.6", + "version": "0.1.0-alpha.7", "description": "The official TypeScript library for the Riza API", "author": "Riza ", "types": "dist/index.d.ts", @@ -16,7 +16,6 @@ "scripts": { "test": "./scripts/test", "build": "./scripts/build", - "prepack": "echo 'to pack, run yarn build && (cd dist; yarn pack)' && exit 1", "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", diff --git a/src/core.ts b/src/core.ts index be1504b..f49d267 100644 --- a/src/core.ts +++ b/src/core.ts @@ -18,7 +18,7 @@ import { type HeadersInit, } from './_shims/index'; export { type Response }; -import { isMultipartBody } from './uploads'; +import { BlobLike, isBlobLike, isMultipartBody } from './uploads'; export { maybeMultipartFormRequestOptions, multipartFormRequestOptions, @@ -235,7 +235,17 @@ export abstract class APIClient { path: string, opts?: PromiseOrValue>, ): APIPromise { - return this.request(Promise.resolve(opts).then((opts) => ({ method, path, ...opts }))); + return this.request( + Promise.resolve(opts).then(async (opts) => { + const body = + opts && isBlobLike(opts?.body) ? new DataView(await opts.body.arrayBuffer()) + : opts?.body instanceof DataView ? opts.body + : opts?.body instanceof ArrayBuffer ? new DataView(opts.body) + : opts && ArrayBuffer.isView(opts?.body) ? new DataView(opts.body.buffer) + : opts?.body; + return { method, path, ...opts, body }; + }), + ); } getAPIList = AbstractPage>( @@ -257,6 +267,8 @@ export abstract class APIClient { const encoded = encoder.encode(body); return encoded.length.toString(); } + } else if (ArrayBuffer.isView(body)) { + return body.byteLength.toString(); } return null; @@ -266,7 +278,9 @@ export abstract class APIClient { const { method, path, query, headers: headers = {} } = options; const body = - isMultipartBody(options.body) ? options.body.body + ArrayBuffer.isView(options.body) || (options.__binaryRequest && typeof options.body === 'string') ? + options.body + : isMultipartBody(options.body) ? options.body.body : options.body ? JSON.stringify(options.body, null, 2) : null; const contentLength = this.calculateContentLength(body); @@ -721,7 +735,9 @@ export type Headers = Record; export type DefaultQuery = Record; export type KeysEnum = { [P in keyof Required]: true }; -export type RequestOptions | Readable> = { +export type RequestOptions< + Req = unknown | Record | Readable | BlobLike | ArrayBufferView | ArrayBuffer, +> = { method?: HTTPMethod; path?: string; query?: Req | undefined; @@ -735,6 +751,7 @@ export type RequestOptions | Readable> = signal?: AbortSignal | undefined | null; idempotencyKey?: string; + __binaryRequest?: boolean | undefined; __binaryResponse?: boolean | undefined; }; @@ -755,6 +772,7 @@ const requestOptionsKeys: KeysEnum = { signal: true, idempotencyKey: true, + __binaryRequest: true, __binaryResponse: true, }; @@ -767,10 +785,11 @@ export const isRequestOptions = (obj: unknown): obj is RequestOptions => { ); }; -export type FinalRequestOptions | Readable> = RequestOptions & { - method: HTTPMethod; - path: string; -}; +export type FinalRequestOptions | Readable | DataView> = + RequestOptions & { + method: HTTPMethod; + path: string; + }; declare const Deno: any; declare const EdgeRuntime: any; diff --git a/src/index.ts b/src/index.ts index 05b6e5c..dec91e8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,9 +1,9 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import * as Core from './core'; import * as Errors from './error'; -import { type Agent } from './_shims/index'; import * as Uploads from './uploads'; +import { type Agent } from './_shims/index'; +import * as Core from '@riza-io/api/core'; import * as API from '@riza-io/api/resources/index'; export interface ClientOptions { @@ -69,7 +69,9 @@ export interface ClientOptions { defaultQuery?: Core.DefaultQuery; } -/** API Client for interfacing with the Riza API. */ +/** + * API Client for interfacing with the Riza API. + */ export class Riza extends Core.APIClient { apiKey: string; @@ -111,6 +113,7 @@ export class Riza extends Core.APIClient { maxRetries: options.maxRetries, fetch: options.fetch, }); + this._options = options; this.apiKey = apiKey; diff --git a/src/resources/command.ts b/src/resources/command.ts index 56e9a91..b007129 100644 --- a/src/resources/command.ts +++ b/src/resources/command.ts @@ -1,7 +1,7 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import * as Core from '@riza-io/api/core'; import { APIResource } from '@riza-io/api/resource'; +import * as Core from '@riza-io/api/core'; import * as CommandAPI from '@riza-io/api/resources/command'; export class Command extends APIResource { @@ -39,11 +39,6 @@ export interface CommandExecParams { */ code: string; - /** - * The interpreter to use when executing code. - */ - language: 'PYTHON' | 'JAVASCRIPT' | 'TYPESCRIPT' | 'RUBY' | 'PHP'; - /** * List of allowed hosts for HTTP requests */ @@ -59,6 +54,16 @@ export interface CommandExecParams { */ env?: Record; + /** + * The interpreter to use when executing code. + */ + language?: 'PYTHON' | 'JAVASCRIPT' | 'TYPESCRIPT' | 'RUBY' | 'PHP'; + + /** + * The runtime to use when executing code. + */ + runtime?: string; + /** * Input to pass to the script via `stdin`. */ diff --git a/src/version.ts b/src/version.ts index 9b7cfeb..135324a 100644 --- a/src/version.ts +++ b/src/version.ts @@ -1 +1 @@ -export const VERSION = '0.1.0-alpha.6'; // x-release-please-version +export const VERSION = '0.1.0-alpha.7'; // x-release-please-version diff --git a/tests/api-resources/command.test.ts b/tests/api-resources/command.test.ts index 43d0e0a..a2bdbc5 100644 --- a/tests/api-resources/command.test.ts +++ b/tests/api-resources/command.test.ts @@ -10,7 +10,7 @@ const riza = new Riza({ describe('resource command', () => { test('exec: only required params', async () => { - const responsePromise = riza.command.exec({ code: 'print("Hello world!")', language: 'PYTHON' }); + const responsePromise = riza.command.exec({ code: 'print("Hello world!")' }); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -23,11 +23,12 @@ describe('resource command', () => { test('exec: required and optional params', async () => { const response = await riza.command.exec({ code: 'print("Hello world!")', - language: 'PYTHON', allow_http_hosts: ['string', 'string', 'string'], args: ['string', 'string', 'string'], env: { foo: 'string' }, - stdin: 'string', + language: 'PYTHON', + runtime: 'runtime', + stdin: 'stdin', }); }); }); diff --git a/tests/stringifyQuery.test.ts b/tests/stringifyQuery.test.ts index b1233bb..7e08aa1 100644 --- a/tests/stringifyQuery.test.ts +++ b/tests/stringifyQuery.test.ts @@ -1,8 +1,10 @@ -import { APIClient } from '@riza-io/api/core'; +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -const { stringifyQuery } = APIClient.prototype as any; +import { Riza } from '@riza-io/api'; -describe('APIClient.stringifyQuery', () => { +const { stringifyQuery } = Riza.prototype as any; + +describe(stringifyQuery, () => { for (const [input, expected] of [ [{ a: '1', b: 2, c: true }, 'a=1&b=2&c=true'], [{ a: null, b: false, c: undefined }, 'a=&b=false'], @@ -18,6 +20,7 @@ describe('APIClient.stringifyQuery', () => { expect(stringifyQuery(input)).toEqual(expected); }); } + for (const value of [[], {}, new Date()]) { it(`${JSON.stringify(value)} -> `, () => { expect(() => stringifyQuery({ value })).toThrow(`Cannot stringify type ${typeof value}`);