From b2dc48c1f8b74ce49673d5df80eff5036b7eefb1 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Tue, 23 Jul 2024 22:04:40 +0000 Subject: [PATCH 01/12] chore(docs): use client instead of package name in Node examples (#23) --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 14b8240..fa278f8 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ The full API of this library can be found in [api.md](api.md). ```js import Riza from '@riza-io/api'; -const riza = new Riza({ +const client = new Riza({ apiKey: process.env['RIZA_API_KEY'], // This is the default and can be omitted }); @@ -43,7 +43,7 @@ This library includes TypeScript definitions for all request params and response ```ts import Riza from '@riza-io/api'; -const riza = new Riza({ +const client = new Riza({ apiKey: process.env['RIZA_API_KEY'], // This is the default and can be omitted }); @@ -106,7 +106,7 @@ You can use the `maxRetries` option to configure or disable this: ```js // Configure the default for all requests: -const riza = new Riza({ +const client = new Riza({ maxRetries: 0, // default is 2 }); @@ -123,7 +123,7 @@ Requests time out after 1 minute by default. You can configure this with a `time ```ts // Configure the default for all requests: -const riza = new Riza({ +const client = new Riza({ timeout: 20 * 1000, // 20 seconds (default is 1 minute) }); @@ -147,7 +147,7 @@ You can also use the `.withResponse()` method to get the raw `Response` along wi ```ts -const riza = new Riza(); +const client = new Riza(); const response = await riza.command.exec({ code: 'print("Hello world!")' }).asResponse(); console.log(response.headers.get('X-My-Header')); @@ -256,7 +256,7 @@ import http from 'http'; import { HttpsProxyAgent } from 'https-proxy-agent'; // Configure the default for all requests: -const riza = new Riza({ +const client = new Riza({ httpAgent: new HttpsProxyAgent(process.env.PROXY_URL), }); From 888dc11895d72501383c92748834e2a167bdc312 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Tue, 23 Jul 2024 22:05:12 +0000 Subject: [PATCH 02/12] chore(ci): limit release doctor target branches (#25) --- .github/workflows/release-doctor.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/release-doctor.yml b/.github/workflows/release-doctor.yml index 3d8a171..bbbfcea 100644 --- a/.github/workflows/release-doctor.yml +++ b/.github/workflows/release-doctor.yml @@ -1,6 +1,8 @@ name: Release Doctor on: pull_request: + branches: + - main workflow_dispatch: jobs: From 8a8c57fbe44a6180b5bbc0f4d10be6b6d2a84c25 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Tue, 23 Jul 2024 22:25:03 +0000 Subject: [PATCH 03/12] chore(internal): refactor release doctor script (#26) --- bin/check-release-environment | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/bin/check-release-environment b/bin/check-release-environment index 372a58f..fad56c0 100644 --- a/bin/check-release-environment +++ b/bin/check-release-environment @@ -1,20 +1,9 @@ #!/usr/bin/env bash -warnings=() errors=() if [ -z "${NPM_TOKEN}" ]; then - warnings+=("The RIZA_NPM_TOKEN secret has not been set. Please set it in either this repository's secrets or your organization secrets") -fi - -lenWarnings=${#warnings[@]} - -if [[ lenWarnings -gt 0 ]]; then - echo -e "Found the following warnings in the release environment:\n" - - for warning in "${warnings[@]}"; do - echo -e "- $warning\n" - done + errors+=("The RIZA_NPM_TOKEN secret has not been set. Please set it in either this repository's secrets or your organization secrets") fi lenErrors=${#errors[@]} From fc5d2b1324dc078ecc9fca4a824f6fc7b958a236 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Tue, 23 Jul 2024 22:26:07 +0000 Subject: [PATCH 04/12] chore(tests): update prism version (#27) --- scripts/mock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/mock b/scripts/mock index fe89a1d..f586157 100755 --- a/scripts/mock +++ b/scripts/mock @@ -21,7 +21,7 @@ echo "==> Starting mock server with URL ${URL}" # Run prism mock on the given spec if [ "$1" == "--daemon" ]; then - npm exec --package=@stoplight/prism-cli@~5.8 -- prism mock "$URL" &> .prism.log & + npm exec --package=@stainless-api/prism-cli@5.8.4 -- prism mock "$URL" &> .prism.log & # Wait for server to come online echo -n "Waiting for server" @@ -37,5 +37,5 @@ if [ "$1" == "--daemon" ]; then echo else - npm exec --package=@stoplight/prism-cli@~5.8 -- prism mock "$URL" + npm exec --package=@stainless-api/prism-cli@5.8.4 -- prism mock "$URL" fi From e15394fd31d290bddf0acbdf5b244827f015d6e3 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Tue, 23 Jul 2024 22:26:29 +0000 Subject: [PATCH 05/12] fix: use relative paths (#28) --- src/index.ts | 4 ++-- src/resources/command.ts | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/index.ts b/src/index.ts index dec91e8..ad00fa4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,8 +3,8 @@ import * as Errors from './error'; 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'; +import * as Core from './core'; +import * as API from './resources/index'; export interface ClientOptions { /** diff --git a/src/resources/command.ts b/src/resources/command.ts index b007129..8098837 100644 --- a/src/resources/command.ts +++ b/src/resources/command.ts @@ -1,8 +1,8 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import { APIResource } from '@riza-io/api/resource'; -import * as Core from '@riza-io/api/core'; -import * as CommandAPI from '@riza-io/api/resources/command'; +import { APIResource } from '../resource'; +import * as Core from '../core'; +import * as CommandAPI from './command'; export class Command extends APIResource { /** From 8965ebc89180ecc896d6af95fdbf8f47d3448038 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Fri, 13 Sep 2024 21:18:26 +0000 Subject: [PATCH 06/12] feat(api): OpenAPI spec update via Stainless API (#29) --- .stats.yml | 2 +- bin/check-release-environment | 13 +++- scripts/mock | 4 +- src/index.ts | 4 +- src/resources/command.ts | 114 +++++++++++++++++++++++++--- tests/api-resources/command.test.ts | 13 ++++ 6 files changed, 133 insertions(+), 17 deletions(-) diff --git a/.stats.yml b/.stats.yml index 4fe8737..d2af244 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-54658e5464e005c5085a5349bee24047b34a42e1192258b29f6bded0f55bb4e2.yml +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/riza%2Friza-api-5bda9f584186c6146628d745748d153b87817a1cfaf59caaf74c89c442303b04.yml diff --git a/bin/check-release-environment b/bin/check-release-environment index fad56c0..372a58f 100644 --- a/bin/check-release-environment +++ b/bin/check-release-environment @@ -1,9 +1,20 @@ #!/usr/bin/env bash +warnings=() errors=() if [ -z "${NPM_TOKEN}" ]; then - errors+=("The RIZA_NPM_TOKEN secret has not been set. Please set it in either this repository's secrets or your organization secrets") + warnings+=("The RIZA_NPM_TOKEN secret has not been set. Please set it in either this repository's secrets or your organization secrets") +fi + +lenWarnings=${#warnings[@]} + +if [[ lenWarnings -gt 0 ]]; then + echo -e "Found the following warnings in the release environment:\n" + + for warning in "${warnings[@]}"; do + echo -e "- $warning\n" + done fi lenErrors=${#errors[@]} diff --git a/scripts/mock b/scripts/mock index f586157..fe89a1d 100755 --- a/scripts/mock +++ b/scripts/mock @@ -21,7 +21,7 @@ echo "==> Starting mock server with URL ${URL}" # Run prism mock on the given spec if [ "$1" == "--daemon" ]; then - npm exec --package=@stainless-api/prism-cli@5.8.4 -- prism mock "$URL" &> .prism.log & + npm exec --package=@stoplight/prism-cli@~5.8 -- prism mock "$URL" &> .prism.log & # Wait for server to come online echo -n "Waiting for server" @@ -37,5 +37,5 @@ if [ "$1" == "--daemon" ]; then echo else - npm exec --package=@stainless-api/prism-cli@5.8.4 -- prism mock "$URL" + npm exec --package=@stoplight/prism-cli@~5.8 -- prism mock "$URL" fi diff --git a/src/index.ts b/src/index.ts index ad00fa4..dec91e8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,8 +3,8 @@ import * as Errors from './error'; import * as Uploads from './uploads'; import { type Agent } from './_shims/index'; -import * as Core from './core'; -import * as API from './resources/index'; +import * as Core from '@riza-io/api/core'; +import * as API from '@riza-io/api/resources/index'; export interface ClientOptions { /** diff --git a/src/resources/command.ts b/src/resources/command.ts index 8098837..a8d297e 100644 --- a/src/resources/command.ts +++ b/src/resources/command.ts @@ -1,14 +1,14 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import { APIResource } from '../resource'; -import * as Core from '../core'; -import * as CommandAPI from './command'; +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 { /** - * Run a script in a secure, isolated sandbox. Scripts can read from stdin and - * write to stdout or stderr. They can access environment variables and command - * line arguments. + * Run a script in a secure, isolated environment. Scripts can read from `stdin` + * and write to `stdout` or `stderr`. They can access input files, environment + * variables and command line arguments. */ exec(body: CommandExecParams, options?: Core.RequestOptions): Core.APIPromise { return this._client.post('/v1/execute', { body, ...options }); @@ -17,8 +17,8 @@ export class Command extends APIResource { export interface CommandExecResponse { /** - * The exit code returned by the script. Will be `0` on success and non-zero on - * failure. + * The exit code returned by the script. Will often be `0` on success and non-zero + * on failure. */ exit_code?: number; @@ -35,12 +35,12 @@ export interface CommandExecResponse { export interface CommandExecParams { /** - * The code to execute in the sandbox. + * The code to execute. */ code: string; /** - * List of allowed hosts for HTTP requests + * List of allowed hosts for HTTP requests. */ allow_http_hosts?: Array; @@ -54,22 +54,114 @@ export interface CommandExecParams { */ env?: Record; + /** + * List of input files. + */ + files?: Array; + + /** + * Configuration for HTTP requests and authentication. + */ + http?: CommandExecParams.HTTP; + /** * The interpreter to use when executing code. */ language?: 'PYTHON' | 'JAVASCRIPT' | 'TYPESCRIPT' | 'RUBY' | 'PHP'; + /** + * Configuration for execution environment limits. + */ + limits?: CommandExecParams.Limits; + /** * The runtime to use when executing code. */ runtime?: string; /** - * Input to pass to the script via `stdin`. + * Input made available to the script via `stdin`. */ stdin?: string; } +export namespace CommandExecParams { + export interface File { + /** + * The contents of the file. + */ + content?: string; + + /** + * The relative path of the file. + */ + path?: string; + } + + /** + * Configuration for HTTP requests and authentication. + */ + export interface HTTP { + /** + * List of allowed HTTP hosts and associated authentication. + */ + allow?: Array; + } + + export namespace HTTP { + export interface Allow { + /** + * Authentication configuration for outbound requests to this host. + */ + auth?: Allow.Auth; + + /** + * The hostname to allow. + */ + host?: string; + } + + export namespace Allow { + /** + * Authentication configuration for outbound requests to this host. + */ + export interface Auth { + /** + * Configuration to add an `Authorization` header using the `Bearer` scheme. + */ + bearer?: Auth.Bearer; + } + + export namespace Auth { + /** + * Configuration to add an `Authorization` header using the `Bearer` scheme. + */ + export interface Bearer { + /** + * The token to set, e.g. `Authorization: Bearer `. + */ + token?: string; + } + } + } + } + + /** + * Configuration for execution environment limits. + */ + export interface Limits { + /** + * The maximum time allowed for execution (in seconds). Default is 30. + */ + execution_timeout?: number; + + /** + * The maximum memory allowed for execution (in MiB). Default is 128. + */ + memory_size?: number; + } +} + export namespace Command { export import CommandExecResponse = CommandAPI.CommandExecResponse; export import CommandExecParams = CommandAPI.CommandExecParams; diff --git a/tests/api-resources/command.test.ts b/tests/api-resources/command.test.ts index a2bdbc5..0cbdae6 100644 --- a/tests/api-resources/command.test.ts +++ b/tests/api-resources/command.test.ts @@ -26,7 +26,20 @@ describe('resource command', () => { allow_http_hosts: ['string', 'string', 'string'], args: ['string', 'string', 'string'], env: { foo: 'string' }, + files: [ + { path: 'path', content: 'content' }, + { path: 'path', content: 'content' }, + { path: 'path', content: 'content' }, + ], + http: { + allow: [ + { host: 'host', auth: { bearer: { token: 'token' } } }, + { host: 'host', auth: { bearer: { token: 'token' } } }, + { host: 'host', auth: { bearer: { token: 'token' } } }, + ], + }, language: 'PYTHON', + limits: { execution_timeout: 0, memory_size: 0 }, runtime: 'runtime', stdin: 'stdin', }); From d92b6ceb3915f229f3b0f8a7ebe9e1fc01d2f735 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Fri, 13 Sep 2024 21:18:46 +0000 Subject: [PATCH 07/12] chore(internal): codegen related update (#30) --- .github/workflows/ci.yml | 23 +++++++++++++++++++-- .github/workflows/release-doctor.yml | 1 + README.md | 16 +++++++------- bin/check-release-environment | 14 ++----------- bin/publish-npm | 20 ++++++++++++++++-- package.json | 5 ++--- scripts/format | 2 +- scripts/lint | 5 ++++- scripts/mock | 4 ++-- src/_shims/node-runtime.ts | 4 +--- src/index.ts | 5 +++-- src/resources/command.ts | 6 +++--- src/uploads.ts | 15 ++++++++++---- tests/api-resources/command.test.ts | 18 ++++++++-------- tests/uploads.test.ts | 8 +++++++ yarn.lock | 31 ++++++++++++---------------- 16 files changed, 107 insertions(+), 70 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d791adb..e3530dc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,11 +22,30 @@ jobs: with: node-version: '18' - - name: Install dependencies - run: yarn install + - name: Bootstrap + run: ./scripts/bootstrap - name: Check types run: ./scripts/lint + + build: + name: build + runs-on: ubuntu-latest + + + steps: + - uses: actions/checkout@v4 + + - name: Set up Node + uses: actions/setup-node@v4 + with: + node-version: '18' + + - name: Bootstrap + run: ./scripts/bootstrap + + - name: Check build + run: ./scripts/build test: name: test runs-on: ubuntu-latest diff --git a/.github/workflows/release-doctor.yml b/.github/workflows/release-doctor.yml index bbbfcea..c6d71f6 100644 --- a/.github/workflows/release-doctor.yml +++ b/.github/workflows/release-doctor.yml @@ -19,3 +19,4 @@ jobs: bash ./bin/check-release-environment env: NPM_TOKEN: ${{ secrets.RIZA_NPM_TOKEN || secrets.NPM_TOKEN }} + diff --git a/README.md b/README.md index fa278f8..b6d4cdd 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ const client = new Riza({ }); async function main() { - const commandExecResponse = await riza.command.exec({ code: 'print("Hello world!")' }); + const commandExecResponse = await client.command.exec({ code: 'print("Hello world!")' }); console.log(commandExecResponse.exit_code); } @@ -49,7 +49,7 @@ const client = new Riza({ async function main() { const params: Riza.CommandExecParams = { code: 'print("Hello world!")' }; - const commandExecResponse: Riza.CommandExecResponse = await riza.command.exec(params); + const commandExecResponse: Riza.CommandExecResponse = await client.command.exec(params); } main(); @@ -66,7 +66,7 @@ a subclass of `APIError` will be thrown: ```ts async function main() { - const commandExecResponse = await riza.command + const commandExecResponse = await client.command .exec({ code: 'print("Hello world!")' }) .catch(async (err) => { if (err instanceof Riza.APIError) { @@ -111,7 +111,7 @@ const client = new Riza({ }); // Or, configure per-request: -await riza.command.exec({ code: 'print("Hello world!")' }, { +await client.command.exec({ code: 'print("Hello world!")' }, { maxRetries: 5, }); ``` @@ -128,7 +128,7 @@ const client = new Riza({ }); // Override per-request: -await riza.command.exec({ code: 'print("Hello world!")' }, { +await client.command.exec({ code: 'print("Hello world!")' }, { timeout: 5 * 1000, }); ``` @@ -149,11 +149,11 @@ You can also use the `.withResponse()` method to get the raw `Response` along wi ```ts const client = new Riza(); -const response = await riza.command.exec({ code: 'print("Hello world!")' }).asResponse(); +const response = await client.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 +const { data: commandExecResponse, response: raw } = await client.command .exec({ code: 'print("Hello world!")' }) .withResponse(); console.log(raw.headers.get('X-My-Header')); @@ -261,7 +261,7 @@ const client = new Riza({ }); // Override per-request: -await riza.command.exec( +await client.command.exec( { code: 'print("Hello world!")' }, { httpAgent: new http.Agent({ keepAlive: false }), diff --git a/bin/check-release-environment b/bin/check-release-environment index 372a58f..1229c45 100644 --- a/bin/check-release-environment +++ b/bin/check-release-environment @@ -1,20 +1,9 @@ #!/usr/bin/env bash -warnings=() errors=() if [ -z "${NPM_TOKEN}" ]; then - warnings+=("The RIZA_NPM_TOKEN secret has not been set. Please set it in either this repository's secrets or your organization secrets") -fi - -lenWarnings=${#warnings[@]} - -if [[ lenWarnings -gt 0 ]]; then - echo -e "Found the following warnings in the release environment:\n" - - for warning in "${warnings[@]}"; do - echo -e "- $warning\n" - done + errors+=("The RIZA_NPM_TOKEN secret has not been set. Please set it in either this repository's secrets or your organization secrets") fi lenErrors=${#errors[@]} @@ -30,3 +19,4 @@ if [[ lenErrors -gt 0 ]]; then fi echo "The environment is ready to push releases!" + diff --git a/bin/publish-npm b/bin/publish-npm index 4d6c9f3..4c21181 100644 --- a/bin/publish-npm +++ b/bin/publish-npm @@ -2,8 +2,24 @@ set -eux -npm config set //registry.npmjs.org/:_authToken $NPM_TOKEN +npm config set '//registry.npmjs.org/:_authToken' "$NPM_TOKEN" +# Build the project yarn build + +# Navigate to the dist directory cd dist -yarn publish --access public + +# Get the version from package.json +VERSION="$(node -p "require('./package.json').version")" + +# Extract the pre-release tag if it exists +if [[ "$VERSION" =~ -([a-zA-Z]+) ]]; then + # Extract the part before any dot in the pre-release identifier + TAG="${BASH_REMATCH[1]}" +else + TAG="latest" +fi + +# Publish with the appropriate tag +yarn publish --access public --tag "$TAG" diff --git a/package.json b/package.json index 2375309..00f4c72 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "prepare": "if ./scripts/utils/check-is-in-git-install.sh; then ./scripts/build; fi", "tsn": "ts-node -r tsconfig-paths/register", "lint": "./scripts/lint", - "fix": "eslint --fix --ext ts,js ." + "fix": "./scripts/format" }, "dependencies": { "@types/node": "^18.11.18", @@ -30,8 +30,7 @@ "agentkeepalive": "^4.2.1", "form-data-encoder": "1.7.2", "formdata-node": "^4.3.2", - "node-fetch": "^2.6.7", - "web-streams-polyfill": "^3.2.1" + "node-fetch": "^2.6.7" }, "devDependencies": { "@swc/core": "^1.3.102", diff --git a/scripts/format b/scripts/format index d297e76..a6bb9d0 100755 --- a/scripts/format +++ b/scripts/format @@ -5,4 +5,4 @@ set -e cd "$(dirname "$0")/.." echo "==> Running eslint --fix" -./node_modules/.bin/eslint --fix --ext ts,js . +ESLINT_USE_FLAT_CONFIG="false" ./node_modules/.bin/eslint --fix --ext ts,js . diff --git a/scripts/lint b/scripts/lint index 6b0e5dc..6ba75df 100755 --- a/scripts/lint +++ b/scripts/lint @@ -5,4 +5,7 @@ set -e cd "$(dirname "$0")/.." echo "==> Running eslint" -./node_modules/.bin/eslint --ext ts,js . +ESLINT_USE_FLAT_CONFIG="false" ./node_modules/.bin/eslint --ext ts,js . + +echo "==> Running tsc" +./node_modules/.bin/tsc --noEmit diff --git a/scripts/mock b/scripts/mock index fe89a1d..d2814ae 100755 --- a/scripts/mock +++ b/scripts/mock @@ -21,7 +21,7 @@ echo "==> Starting mock server with URL ${URL}" # Run prism mock on the given spec if [ "$1" == "--daemon" ]; then - npm exec --package=@stoplight/prism-cli@~5.8 -- prism mock "$URL" &> .prism.log & + npm exec --package=@stainless-api/prism-cli@5.8.5 -- prism mock "$URL" &> .prism.log & # Wait for server to come online echo -n "Waiting for server" @@ -37,5 +37,5 @@ if [ "$1" == "--daemon" ]; then echo else - npm exec --package=@stoplight/prism-cli@~5.8 -- prism mock "$URL" + npm exec --package=@stainless-api/prism-cli@5.8.5 -- prism mock "$URL" fi diff --git a/src/_shims/node-runtime.ts b/src/_shims/node-runtime.ts index a9c42eb..ab9f2ab 100644 --- a/src/_shims/node-runtime.ts +++ b/src/_shims/node-runtime.ts @@ -13,9 +13,7 @@ import { Readable } from 'node:stream'; import { type RequestOptions } from '../core'; import { MultipartBody } from './MultipartBody'; import { type Shims } from './registry'; - -// @ts-ignore (this package does not have proper export maps for this export) -import { ReadableStream } from 'web-streams-polyfill/dist/ponyfill.es2018.js'; +import { ReadableStream } from 'node:stream/web'; type FileFromPathOptions = Omit; diff --git a/src/index.ts b/src/index.ts index dec91e8..d54df59 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,8 +3,8 @@ import * as Errors from './error'; 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'; +import * as Core from './core'; +import * as API from './resources/index'; export interface ClientOptions { /** @@ -137,6 +137,7 @@ export class Riza extends Core.APIClient { } static Riza = this; + static DEFAULT_TIMEOUT = 60000; // 1 minute static RizaError = Errors.RizaError; static APIError = Errors.APIError; diff --git a/src/resources/command.ts b/src/resources/command.ts index a8d297e..935169e 100644 --- a/src/resources/command.ts +++ b/src/resources/command.ts @@ -1,8 +1,8 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -import { APIResource } from '@riza-io/api/resource'; -import * as Core from '@riza-io/api/core'; -import * as CommandAPI from '@riza-io/api/resources/command'; +import { APIResource } from '../resource'; +import * as Core from '../core'; +import * as CommandAPI from './command'; export class Command extends APIResource { /** diff --git a/src/uploads.ts b/src/uploads.ts index 081827c..8fd2154 100644 --- a/src/uploads.ts +++ b/src/uploads.ts @@ -107,21 +107,28 @@ export async function toFile( // If it's a promise, resolve it. value = await value; - // Use the file's options if there isn't one provided - options ??= isFileLike(value) ? { lastModified: value.lastModified, type: value.type } : {}; + // If we've been given a `File` we don't need to do anything + if (isFileLike(value)) { + return value; + } if (isResponseLike(value)) { const blob = await value.blob(); name ||= new URL(value.url).pathname.split(/[\\/]/).pop() ?? 'unknown_file'; - return new File([blob as any], name, options); + // we need to convert the `Blob` into an array buffer because the `Blob` class + // that `node-fetch` defines is incompatible with the web standard which results + // in `new File` interpreting it as a string instead of binary data. + const data = isBlobLike(blob) ? [(await blob.arrayBuffer()) as any] : [blob]; + + return new File(data, name, options); } const bits = await getBytes(value); name ||= getName(value) ?? 'unknown_file'; - if (!options.type) { + if (!options?.type) { const type = (bits[0] as any)?.type; if (typeof type === 'string') { options = { ...options, type }; diff --git a/tests/api-resources/command.test.ts b/tests/api-resources/command.test.ts index 0cbdae6..82c000e 100644 --- a/tests/api-resources/command.test.ts +++ b/tests/api-resources/command.test.ts @@ -3,14 +3,14 @@ import Riza from '@riza-io/api'; import { Response } from 'node-fetch'; -const riza = new Riza({ +const client = new Riza({ apiKey: 'My API Key', baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010', }); describe('resource command', () => { test('exec: only required params', async () => { - const responsePromise = riza.command.exec({ code: 'print("Hello world!")' }); + const responsePromise = client.command.exec({ code: 'print("Hello world!")' }); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -21,21 +21,21 @@ describe('resource command', () => { }); test('exec: required and optional params', async () => { - const response = await riza.command.exec({ + const response = await client.command.exec({ code: 'print("Hello world!")', allow_http_hosts: ['string', 'string', 'string'], args: ['string', 'string', 'string'], env: { foo: 'string' }, files: [ - { path: 'path', content: 'content' }, - { path: 'path', content: 'content' }, - { path: 'path', content: 'content' }, + { content: 'content', path: 'path' }, + { content: 'content', path: 'path' }, + { content: 'content', path: 'path' }, ], http: { allow: [ - { host: 'host', auth: { bearer: { token: 'token' } } }, - { host: 'host', auth: { bearer: { token: 'token' } } }, - { host: 'host', auth: { bearer: { token: 'token' } } }, + { auth: { bearer: { token: 'token' } }, host: 'host' }, + { auth: { bearer: { token: 'token' } }, host: 'host' }, + { auth: { bearer: { token: 'token' } }, host: 'host' }, ], }, language: 'PYTHON', diff --git a/tests/uploads.test.ts b/tests/uploads.test.ts index e884b9d..bcbc163 100644 --- a/tests/uploads.test.ts +++ b/tests/uploads.test.ts @@ -54,4 +54,12 @@ describe('toFile', () => { const file = await toFile(input); expect(file.name).toEqual('uploads.test.ts'); }); + + it('does not copy File objects', async () => { + const input = new File(['foo'], 'input.jsonl', { type: 'jsonl' }); + const file = await toFile(input); + expect(file).toBe(input); + expect(file.name).toEqual('input.jsonl'); + expect(file.type).toBe('jsonl'); + }); }); diff --git a/yarn.lock b/yarn.lock index dda4d2e..0f17a27 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1200,12 +1200,12 @@ brace-expansion@^2.0.1: dependencies: balanced-match "^1.0.0" -braces@^3.0.2: - version "3.0.2" - resolved "https://registry.yarnpkg.com/braces/-/braces-3.0.2.tgz#3454e1a462ee8d599e236df336cd9ea4f8afe107" - integrity sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A== +braces@^3.0.3: + version "3.0.3" + resolved "https://registry.yarnpkg.com/braces/-/braces-3.0.3.tgz#490332f40919452272d55a8480adc0c441358789" + integrity sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA== dependencies: - fill-range "^7.0.1" + fill-range "^7.1.1" browserslist@^4.22.2: version "4.22.2" @@ -1762,10 +1762,10 @@ file-entry-cache@^6.0.1: dependencies: flat-cache "^3.0.4" -fill-range@^7.0.1: - version "7.0.1" - resolved "https://registry.yarnpkg.com/fill-range/-/fill-range-7.0.1.tgz#1919a6a7c75fe38b2c7c77e5198535da9acdda40" - integrity sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ== +fill-range@^7.1.1: + version "7.1.1" + resolved "https://registry.yarnpkg.com/fill-range/-/fill-range-7.1.1.tgz#44265d3cac07e3ea7dc247516380643754a05292" + integrity sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg== dependencies: to-regex-range "^5.0.1" @@ -2638,11 +2638,11 @@ merge2@^1.3.0, merge2@^1.4.1: integrity sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg== micromatch@^4.0.4: - version "4.0.5" - resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-4.0.5.tgz#bc8999a7cbbf77cdc89f132f6e467051b49090c6" - integrity sha512-DMy+ERcEW2q8Z2Po+WNXuw3c5YaUSFjAO5GsJqfEl7UjvtIuFKO6ZrKvcItdy98dwFI2N1tg3zNIdKaQT+aNdA== + version "4.0.8" + resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-4.0.8.tgz#d66fa18f3a47076789320b9b1af32bd86d9fa202" + integrity sha512-PXwfBhYu0hBCPw8Dn0E+WDYb7af3dSLVWKi3HGv84IdF4TyFoC0ysxFd0Goxw7nSv4T/PzEJQxsYsEiFCKo2BA== dependencies: - braces "^3.0.2" + braces "^3.0.3" picomatch "^2.3.1" mime-db@1.51.0: @@ -3412,11 +3412,6 @@ web-streams-polyfill@4.0.0-beta.1: resolved "https://registry.yarnpkg.com/web-streams-polyfill/-/web-streams-polyfill-4.0.0-beta.1.tgz#3b19b9817374b7cee06d374ba7eeb3aeb80e8c95" integrity sha512-3ux37gEX670UUphBF9AMCq8XM6iQ8Ac6A+DSRRjDoRBm1ufCkaCDdNVbaqq60PsEkdNlLKrGtv/YBP4EJXqNtQ== -web-streams-polyfill@^3.2.1: - version "3.2.1" - resolved "https://registry.yarnpkg.com/web-streams-polyfill/-/web-streams-polyfill-3.2.1.tgz#71c2718c52b45fd49dbeee88634b3a60ceab42a6" - integrity sha512-e0MO3wdXWKrLbL0DgGnUV7WHVuw9OUvL4hjgnPkIeEvESk74gAITi5G606JtZPp39cd8HA9VQzCIvA49LpPN5Q== - webidl-conversions@^3.0.0: version "3.0.1" resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-3.0.1.tgz#24534275e2a7bc6be7bc86611cc16ae0a5654871" From 9bb944629e7565e59c0abe6e092b6227e266f7a7 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Fri, 13 Sep 2024 21:19:37 +0000 Subject: [PATCH 08/12] fix(errors): pass message through to APIConnectionError (#31) --- src/error.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/error.ts b/src/error.ts index 696da77..418358e 100644 --- a/src/error.ts +++ b/src/error.ts @@ -49,7 +49,7 @@ export class APIError extends RizaError { headers: Headers | undefined, ) { if (!status) { - return new APIConnectionError({ cause: castToError(errorResponse) }); + return new APIConnectionError({ message, cause: castToError(errorResponse) }); } const error = errorResponse as Record; @@ -101,7 +101,7 @@ export class APIUserAbortError extends APIError { export class APIConnectionError extends APIError { override readonly status: undefined = undefined; - constructor({ message, cause }: { message?: string; cause?: Error | 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 // @ts-ignore From 93172964ae4bcbe5b48724a08171b407ad675e32 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Fri, 13 Sep 2024 21:19:58 +0000 Subject: [PATCH 09/12] chore: better object fallback behaviour for casting errors (#32) --- src/core.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/core.ts b/src/core.ts index f49d267..7f59e51 100644 --- a/src/core.ts +++ b/src/core.ts @@ -978,6 +978,11 @@ const validatePositiveInteger = (name: string, n: unknown): number => { export const castToError = (err: any): Error => { if (err instanceof Error) return err; + if (typeof err === 'object' && err !== null) { + try { + return new Error(JSON.stringify(err)); + } catch {} + } return new Error(err); }; From bf4398d53d01abfb81e96164c9e045fa6d2b089c Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Fri, 13 Sep 2024 21:22:45 +0000 Subject: [PATCH 10/12] chore(internal): codegen related update (#33) --- README.md | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index b6d4cdd..8eae24e 100644 --- a/README.md +++ b/README.md @@ -27,9 +27,9 @@ const client = new Riza({ }); async function main() { - const commandExecResponse = await client.command.exec({ code: 'print("Hello world!")' }); + const response = await client.command.exec({ code: 'print("Hello world!")' }); - console.log(commandExecResponse.exit_code); + console.log(response.exit_code); } main(); @@ -49,7 +49,7 @@ const client = new Riza({ async function main() { const params: Riza.CommandExecParams = { code: 'print("Hello world!")' }; - const commandExecResponse: Riza.CommandExecResponse = await client.command.exec(params); + const response: Riza.CommandExecResponse = await client.command.exec(params); } main(); @@ -66,17 +66,15 @@ a subclass of `APIError` will be thrown: ```ts async function main() { - const commandExecResponse = await client.command - .exec({ code: 'print("Hello world!")' }) - .catch(async (err) => { - if (err instanceof Riza.APIError) { - console.log(err.status); // 400 - console.log(err.name); // BadRequestError - console.log(err.headers); // {server: 'nginx', ...} - } else { - throw err; - } - }); + const response = await client.command.exec({ code: 'print("Hello world!")' }).catch(async (err) => { + if (err instanceof Riza.APIError) { + console.log(err.status); // 400 + console.log(err.name); // BadRequestError + console.log(err.headers); // {server: 'nginx', ...} + } else { + throw err; + } + }); } main(); @@ -153,11 +151,11 @@ const response = await client.command.exec({ code: 'print("Hello world!")' }).as console.log(response.headers.get('X-My-Header')); console.log(response.statusText); // access the underlying Response object -const { data: commandExecResponse, response: raw } = await client.command +const { data: response, response: raw } = await client.command .exec({ code: 'print("Hello world!")' }) .withResponse(); console.log(raw.headers.get('X-My-Header')); -console.log(commandExecResponse.exit_code); +console.log(response.exit_code); ``` ### Making custom/undocumented requests From f2852b04e975560677381345c0c0daae728cabba Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Fri, 13 Sep 2024 21:29:23 +0000 Subject: [PATCH 11/12] docs: update CONTRIBUTING.md (#34) --- CONTRIBUTING.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 679357b..6c2d3fb 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -14,13 +14,13 @@ This will install all the required dependencies and build output files to `dist/ ## Modifying/Adding code -Most of the SDK is generated code, and any modified code will be overridden on the next generation. The -`src/lib/` and `examples/` directories are exceptions and will never be overridden. +Most of the SDK is generated code. Modifications to code will be persisted between generations, but may +result in merge conflicts between manual patches and changes from the generator. The generator will never +modify the contents of the `src/lib/` and `examples/` directories. ## Adding and running examples -All files in the `examples/` directory are not modified by the Stainless generator and can be freely edited or -added to. +All files in the `examples/` directory are not modified by the generator and can be freely edited or added to. ```bash // add an example to examples/.ts From 93bdcacc8fc9ca02350f13b28e06abaf140d36c2 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Fri, 13 Sep 2024 21:29:38 +0000 Subject: [PATCH 12/12] release: 0.1.0-alpha.8 --- .release-please-manifest.json | 2 +- CHANGELOG.md | 30 ++++++++++++++++++++++++++++++ package.json | 2 +- src/version.ts | 2 +- 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/.release-please-manifest.json b/.release-please-manifest.json index fad80ad..332798e 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "0.1.0-alpha.7" + ".": "0.1.0-alpha.8" } diff --git a/CHANGELOG.md b/CHANGELOG.md index 2597d42..0417899 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,35 @@ # Changelog +## 0.1.0-alpha.8 (2024-09-13) + +Full Changelog: [v0.1.0-alpha.7...v0.1.0-alpha.8](https://github.com/riza-io/riza-api-node/compare/v0.1.0-alpha.7...v0.1.0-alpha.8) + +### Features + +* **api:** OpenAPI spec update via Stainless API ([#29](https://github.com/riza-io/riza-api-node/issues/29)) ([8965ebc](https://github.com/riza-io/riza-api-node/commit/8965ebc89180ecc896d6af95fdbf8f47d3448038)) + + +### Bug Fixes + +* **errors:** pass message through to APIConnectionError ([#31](https://github.com/riza-io/riza-api-node/issues/31)) ([9bb9446](https://github.com/riza-io/riza-api-node/commit/9bb944629e7565e59c0abe6e092b6227e266f7a7)) +* use relative paths ([#28](https://github.com/riza-io/riza-api-node/issues/28)) ([e15394f](https://github.com/riza-io/riza-api-node/commit/e15394fd31d290bddf0acbdf5b244827f015d6e3)) + + +### Chores + +* better object fallback behaviour for casting errors ([#32](https://github.com/riza-io/riza-api-node/issues/32)) ([9317296](https://github.com/riza-io/riza-api-node/commit/93172964ae4bcbe5b48724a08171b407ad675e32)) +* **ci:** limit release doctor target branches ([#25](https://github.com/riza-io/riza-api-node/issues/25)) ([888dc11](https://github.com/riza-io/riza-api-node/commit/888dc11895d72501383c92748834e2a167bdc312)) +* **docs:** use client instead of package name in Node examples ([#23](https://github.com/riza-io/riza-api-node/issues/23)) ([b2dc48c](https://github.com/riza-io/riza-api-node/commit/b2dc48c1f8b74ce49673d5df80eff5036b7eefb1)) +* **internal:** codegen related update ([#30](https://github.com/riza-io/riza-api-node/issues/30)) ([d92b6ce](https://github.com/riza-io/riza-api-node/commit/d92b6ceb3915f229f3b0f8a7ebe9e1fc01d2f735)) +* **internal:** codegen related update ([#33](https://github.com/riza-io/riza-api-node/issues/33)) ([bf4398d](https://github.com/riza-io/riza-api-node/commit/bf4398d53d01abfb81e96164c9e045fa6d2b089c)) +* **internal:** refactor release doctor script ([#26](https://github.com/riza-io/riza-api-node/issues/26)) ([8a8c57f](https://github.com/riza-io/riza-api-node/commit/8a8c57fbe44a6180b5bbc0f4d10be6b6d2a84c25)) +* **tests:** update prism version ([#27](https://github.com/riza-io/riza-api-node/issues/27)) ([fc5d2b1](https://github.com/riza-io/riza-api-node/commit/fc5d2b1324dc078ecc9fca4a824f6fc7b958a236)) + + +### Documentation + +* update CONTRIBUTING.md ([#34](https://github.com/riza-io/riza-api-node/issues/34)) ([f2852b0](https://github.com/riza-io/riza-api-node/commit/f2852b04e975560677381345c0c0daae728cabba)) + ## 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) diff --git a/package.json b/package.json index 00f4c72..1527bf8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@riza-io/api", - "version": "0.1.0-alpha.7", + "version": "0.1.0-alpha.8", "description": "The official TypeScript library for the Riza API", "author": "Riza ", "types": "dist/index.d.ts", diff --git a/src/version.ts b/src/version.ts index 135324a..2cc4fcd 100644 --- a/src/version.ts +++ b/src/version.ts @@ -1 +1 @@ -export const VERSION = '0.1.0-alpha.7'; // x-release-please-version +export const VERSION = '0.1.0-alpha.8'; // x-release-please-version