Skip to content

Commit

Permalink
Merge pull request #17 from nestrilabs/release-please--branches--main…
Browse files Browse the repository at this point in the history
…--changes--next--components--sdk

release: 0.1.0-alpha.4
  • Loading branch information
wanjohiryan authored Jan 5, 2025
2 parents d6ff9e2 + abca1a5 commit fb190fc
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 24 deletions.
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.3"
".": "0.1.0-alpha.4"
}
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## 0.1.0-alpha.4 (2025-01-05)

Full Changelog: [v0.1.0-alpha.3...v0.1.0-alpha.4](https://github.com/nestrilabs/nestri-node-sdk/compare/v0.1.0-alpha.3...v0.1.0-alpha.4)

### Features

* **api:** manual updates ([#16](https://github.com/nestrilabs/nestri-node-sdk/issues/16)) ([7819a14](https://github.com/nestrilabs/nestri-node-sdk/commit/7819a1433739f77174a5e97490412125fc14233c))

## 0.1.0-alpha.3 (2025-01-04)

Full Changelog: [v0.1.0-alpha.2...v0.1.0-alpha.3](https://github.com/nestrilabs/nestri-node-sdk/compare/v0.1.0-alpha.2...v0.1.0-alpha.3)
Expand Down
28 changes: 12 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ The full API of this library can be found in [api.md](api.md).
import Nestri from '@nestri/sdk';

const client = new Nestri({
bearerToken: process.env['BEARER_TOKEN'], // This is the default and can be omitted
bearerToken: process.env['NESTRI_API_KEY'], // This is the default and can be omitted
});

async function main() {
const machine = await client.machines.create('fc27f428f9ca47d4b41b70889ae0c62090');
const game = await client.games.retrieve(870780);

console.log(machine.data);
console.log(game.data);
}

main();
Expand All @@ -44,13 +44,11 @@ This library includes TypeScript definitions for all request params and response
import Nestri from '@nestri/sdk';

const client = new Nestri({
bearerToken: process.env['BEARER_TOKEN'], // This is the default and can be omitted
bearerToken: process.env['NESTRI_API_KEY'], // This is the default and can be omitted
});

async function main() {
const machine: Nestri.MachineCreateResponse = await client.machines.create(
'fc27f428f9ca47d4b41b70889ae0c62090',
);
const game: Nestri.GameRetrieveResponse = await client.games.retrieve(870780);
}

main();
Expand All @@ -67,7 +65,7 @@ a subclass of `APIError` will be thrown:
<!-- prettier-ignore -->
```ts
async function main() {
const machine = await client.machines.create('fc27f428f9ca47d4b41b70889ae0c62090').catch(async (err) => {
const game = await client.games.retrieve(870780).catch(async (err) => {
if (err instanceof Nestri.APIError) {
console.log(err.status); // 400
console.log(err.name); // BadRequestError
Expand Down Expand Up @@ -110,7 +108,7 @@ const client = new Nestri({
});

// Or, configure per-request:
await client.machines.create('fc27f428f9ca47d4b41b70889ae0c62090', {
await client.games.retrieve(870780, {
maxRetries: 5,
});
```
Expand All @@ -127,7 +125,7 @@ const client = new Nestri({
});

// Override per-request:
await client.machines.create('fc27f428f9ca47d4b41b70889ae0c62090', {
await client.games.retrieve(870780, {
timeout: 5 * 1000,
});
```
Expand All @@ -148,15 +146,13 @@ You can also use the `.withResponse()` method to get the raw `Response` along wi
```ts
const client = new Nestri();

const response = await client.machines.create('fc27f428f9ca47d4b41b70889ae0c62090').asResponse();
const response = await client.games.retrieve(870780).asResponse();
console.log(response.headers.get('X-My-Header'));
console.log(response.statusText); // access the underlying Response object

const { data: machine, response: raw } = await client.machines
.create('fc27f428f9ca47d4b41b70889ae0c62090')
.withResponse();
const { data: game, response: raw } = await client.games.retrieve(870780).withResponse();
console.log(raw.headers.get('X-My-Header'));
console.log(machine.data);
console.log(game.data);
```

### Making custom/undocumented requests
Expand Down Expand Up @@ -260,7 +256,7 @@ const client = new Nestri({
});

// Override per-request:
await client.machines.create('fc27f428f9ca47d4b41b70889ae0c62090', {
await client.games.retrieve(870780, {
httpAgent: new http.Agent({ keepAlive: false }),
});
```
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nestri/sdk",
"version": "0.1.0-alpha.3",
"version": "0.1.0-alpha.4",
"description": "The official TypeScript library for the Nestri API",
"author": "Nestri <[email protected]>",
"types": "dist/index.d.ts",
Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export class Nestri extends Core.APIClient {
/**
* API Client for interfacing with the Nestri API.
*
* @param {string | undefined} [opts.bearerToken=process.env['BEARER_TOKEN'] ?? undefined]
* @param {string | undefined} [opts.bearerToken=process.env['NESTRI_API_KEY'] ?? undefined]
* @param {string} [opts.baseURL=process.env['NESTRI_BASE_URL'] ?? https://api.nestri.io] - Override the default base URL for the API.
* @param {number} [opts.timeout=1 minute] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
* @param {number} [opts.httpAgent] - An HTTP agent used to manage HTTP(s) connections.
Expand All @@ -115,12 +115,12 @@ export class Nestri extends Core.APIClient {
*/
constructor({
baseURL = Core.readEnv('NESTRI_BASE_URL'),
bearerToken = Core.readEnv('BEARER_TOKEN'),
bearerToken = Core.readEnv('NESTRI_API_KEY'),
...opts
}: ClientOptions = {}) {
if (bearerToken === undefined) {
throw new Errors.NestriError(
"The BEARER_TOKEN environment variable is missing or empty; either provide it, or instantiate the Nestri client with an bearerToken option, like new Nestri({ bearerToken: 'My Bearer Token' }).",
"The NESTRI_API_KEY environment variable is missing or empty; either provide it, or instantiate the Nestri client with an bearerToken option, like new Nestri({ bearerToken: 'My Bearer Token' }).",
);
}

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.3'; // x-release-please-version
export const VERSION = '0.1.0-alpha.4'; // x-release-please-version
4 changes: 2 additions & 2 deletions tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,14 +195,14 @@ describe('instantiate client', () => {

test('with environment variable arguments', () => {
// set options via env var
process.env['BEARER_TOKEN'] = 'My Bearer Token';
process.env['NESTRI_API_KEY'] = 'My Bearer Token';
const client = new Nestri();
expect(client.bearerToken).toBe('My Bearer Token');
});

test('with overridden environment variable arguments', () => {
// set options via env var
process.env['BEARER_TOKEN'] = 'another My Bearer Token';
process.env['NESTRI_API_KEY'] = 'another My Bearer Token';
const client = new Nestri({ bearerToken: 'My Bearer Token' });
expect(client.bearerToken).toBe('My Bearer Token');
});
Expand Down

0 comments on commit fb190fc

Please sign in to comment.