Skip to content

Commit

Permalink
Merge pull request #24 from riza-io/release-please--branches--main--c…
Browse files Browse the repository at this point in the history
…hanges--next--components--api

release: 0.1.0-alpha.8
  • Loading branch information
andrewmbenton authored Sep 13, 2024
2 parents a268d8c + 93bdcac commit 29efadb
Show file tree
Hide file tree
Showing 23 changed files with 277 additions and 100 deletions.
23 changes: 21 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/release-doctor.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: Release Doctor
on:
pull_request:
branches:
- main
workflow_dispatch:

jobs:
Expand All @@ -17,3 +19,4 @@ jobs:
bash ./bin/check-release-environment
env:
NPM_TOKEN: ${{ secrets.RIZA_NPM_TOKEN || secrets.NPM_TOKEN }}

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.7"
".": "0.1.0-alpha.8"
}
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-54658e5464e005c5085a5349bee24047b34a42e1192258b29f6bded0f55bb4e2.yml
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/riza%2Friza-api-5bda9f584186c6146628d745748d153b87817a1cfaf59caaf74c89c442303b04.yml
30 changes: 30 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
8 changes: 4 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/<your-example>.ts
Expand Down
50 changes: 24 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ 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
});

async function main() {
const commandExecResponse = await riza.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();
Expand All @@ -43,13 +43,13 @@ 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
});

async function main() {
const params: Riza.CommandExecParams = { code: 'print("Hello world!")' };
const commandExecResponse: Riza.CommandExecResponse = await riza.command.exec(params);
const response: Riza.CommandExecResponse = await client.command.exec(params);
}

main();
Expand All @@ -66,17 +66,15 @@ a subclass of `APIError` will be thrown:
<!-- prettier-ignore -->
```ts
async function main() {
const commandExecResponse = await riza.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();
Expand Down Expand Up @@ -106,12 +104,12 @@ You can use the `maxRetries` option to configure or disable this:
<!-- prettier-ignore -->
```js
// Configure the default for all requests:
const riza = new Riza({
const client = new Riza({
maxRetries: 0, // default is 2
});

// Or, configure per-request:
await riza.command.exec({ code: 'print("Hello world!")' }, {
await client.command.exec({ code: 'print("Hello world!")' }, {
maxRetries: 5,
});
```
Expand All @@ -123,12 +121,12 @@ Requests time out after 1 minute by default. You can configure this with a `time
<!-- prettier-ignore -->
```ts
// Configure the default for all requests:
const riza = new Riza({
const client = new Riza({
timeout: 20 * 1000, // 20 seconds (default is 1 minute)
});

// Override per-request:
await riza.command.exec({ code: 'print("Hello world!")' }, {
await client.command.exec({ code: 'print("Hello world!")' }, {
timeout: 5 * 1000,
});
```
Expand All @@ -147,17 +145,17 @@ You can also use the `.withResponse()` method to get the raw `Response` along wi

<!-- prettier-ignore -->
```ts
const riza = new Riza();
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: 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
Expand Down Expand Up @@ -256,12 +254,12 @@ 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),
});

// Override per-request:
await riza.command.exec(
await client.command.exec(
{ code: 'print("Hello world!")' },
{
httpAgent: new http.Agent({ keepAlive: false }),
Expand Down
14 changes: 2 additions & 12 deletions bin/check-release-environment
Original file line number Diff line number Diff line change
@@ -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[@]}
Expand All @@ -30,3 +19,4 @@ if [[ lenErrors -gt 0 ]]; then
fi

echo "The environment is ready to push releases!"

20 changes: 18 additions & 2 deletions bin/publish-npm
Original file line number Diff line number Diff line change
Expand Up @@ -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"
7 changes: 3 additions & 4 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.7",
"version": "0.1.0-alpha.8",
"description": "The official TypeScript library for the Riza API",
"author": "Riza <[email protected]>",
"types": "dist/index.d.ts",
Expand All @@ -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",
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion scripts/format
Original file line number Diff line number Diff line change
Expand Up @@ -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 .
5 changes: 4 additions & 1 deletion scripts/lint
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions scripts/mock
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected].5 -- prism mock "$URL" &> .prism.log &

# Wait for server to come online
echo -n "Waiting for server"
Expand All @@ -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/[email protected].5 -- prism mock "$URL"
fi
4 changes: 1 addition & 3 deletions src/_shims/node-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<FilePropertyBag, 'lastModified'>;

Expand Down
5 changes: 5 additions & 0 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

Expand Down
4 changes: 2 additions & 2 deletions src/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, any>;
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit 29efadb

Please sign in to comment.