Skip to content

Commit

Permalink
release: 0.1.0-alpha.7 (#19)
Browse files Browse the repository at this point in the history
* feat(api): OpenAPI spec update via Stainless API (#17)

* chore(internal): codegen related update (#18)

* chore(docs): minor update to formatting of API link in README (#20)

* chore(docs): mention support of web browser runtimes (#21)

* release: 0.1.0-alpha.7

---------

Co-authored-by: stainless-app[bot] <142633134+stainless-app[bot]@users.noreply.github.com>
  • Loading branch information
stainless-app[bot] authored Jul 23, 2024
1 parent 787392e commit a268d8c
Show file tree
Hide file tree
Showing 13 changed files with 85 additions and 46 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:
pull_request:
branches:
- main
- next

jobs:
lint:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.prism.log
node_modules
yarn-error.log
codegen.log
Expand Down
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.6"
".": "0.1.0-alpha.7"
}
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
28 changes: 10 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -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/).

Expand All @@ -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);
}
Expand All @@ -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);
}

Expand All @@ -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
Expand Down Expand Up @@ -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,
});
```
Expand All @@ -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,
});
```
Expand All @@ -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);
Expand Down Expand Up @@ -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 }),
},
Expand All @@ -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.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>",
"types": "dist/index.d.ts",
Expand All @@ -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",
Expand Down
35 changes: 27 additions & 8 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -235,7 +235,17 @@ export abstract class APIClient {
path: string,
opts?: PromiseOrValue<RequestOptions<Req>>,
): APIPromise<Rsp> {
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<Item, PageClass extends AbstractPage<Item> = AbstractPage<Item>>(
Expand All @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -721,7 +735,9 @@ export type Headers = Record<string, string | null | undefined>;
export type DefaultQuery = Record<string, string | undefined>;
export type KeysEnum<T> = { [P in keyof Required<T>]: true };

export type RequestOptions<Req = unknown | Record<string, unknown> | Readable> = {
export type RequestOptions<
Req = unknown | Record<string, unknown> | Readable | BlobLike | ArrayBufferView | ArrayBuffer,
> = {
method?: HTTPMethod;
path?: string;
query?: Req | undefined;
Expand All @@ -735,6 +751,7 @@ export type RequestOptions<Req = unknown | Record<string, unknown> | Readable> =
signal?: AbortSignal | undefined | null;
idempotencyKey?: string;

__binaryRequest?: boolean | undefined;
__binaryResponse?: boolean | undefined;
};

Expand All @@ -755,6 +772,7 @@ const requestOptionsKeys: KeysEnum<RequestOptions> = {
signal: true,
idempotencyKey: true,

__binaryRequest: true,
__binaryResponse: true,
};

Expand All @@ -767,10 +785,11 @@ export const isRequestOptions = (obj: unknown): obj is RequestOptions => {
);
};

export type FinalRequestOptions<Req = unknown | Record<string, unknown> | Readable> = RequestOptions<Req> & {
method: HTTPMethod;
path: string;
};
export type FinalRequestOptions<Req = unknown | Record<string, unknown> | Readable | DataView> =
RequestOptions<Req> & {
method: HTTPMethod;
path: string;
};

declare const Deno: any;
declare const EdgeRuntime: any;
Expand Down
9 changes: 6 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -111,6 +113,7 @@ export class Riza extends Core.APIClient {
maxRetries: options.maxRetries,
fetch: options.fetch,
});

this._options = options;

this.apiKey = apiKey;
Expand Down
17 changes: 11 additions & 6 deletions src/resources/command.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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
*/
Expand All @@ -59,6 +54,16 @@ export interface CommandExecParams {
*/
env?: Record<string, string>;

/**
* 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`.
*/
Expand Down
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.1.0-alpha.6'; // x-release-please-version
export const VERSION = '0.1.0-alpha.7'; // x-release-please-version
7 changes: 4 additions & 3 deletions tests/api-resources/command.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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',
});
});
});
9 changes: 6 additions & 3 deletions tests/stringifyQuery.test.ts
Original file line number Diff line number Diff line change
@@ -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'],
Expand All @@ -18,6 +20,7 @@ describe('APIClient.stringifyQuery', () => {
expect(stringifyQuery(input)).toEqual(expected);
});
}

for (const value of [[], {}, new Date()]) {
it(`${JSON.stringify(value)} -> <error>`, () => {
expect(() => stringifyQuery({ value })).toThrow(`Cannot stringify type ${typeof value}`);
Expand Down

0 comments on commit a268d8c

Please sign in to comment.