Skip to content

Commit

Permalink
Merge pull request #44 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.10
  • Loading branch information
wanjohiryan authored Jan 18, 2025
2 parents 9d3d4d5 + f50552d commit d695b19
Show file tree
Hide file tree
Showing 10 changed files with 242 additions and 9 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.9"
".": "0.1.0-alpha.10"
}
4 changes: 2 additions & 2 deletions .stats.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configured_endpoints: 22
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/nestri%2Fnestri-sdk-6d4fd80c0cc52698b7056513b6cfeaa897c4fa638b417dbcddc3c68123f6e3dc.yml
configured_endpoints: 25
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/nestri%2Fnestri-sdk-b0479074a05fdf83faf7a450fb560e5897d57a919fef69f8ce5a7c289d01db57.yml
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.10 (2025-01-18)

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

### Features

* **api:** re-add subscriptions ([#43](https://github.com/nestrilabs/nestri-node-sdk/issues/43)) ([b161c75](https://github.com/nestrilabs/nestri-node-sdk/commit/b161c75f96e502fe501574a8c7ca536cb6b9f881))

## 0.1.0-alpha.9 (2025-01-18)

Full Changelog: [v0.1.0-alpha.8...v0.1.0-alpha.9](https://github.com/nestrilabs/nestri-node-sdk/compare/v0.1.0-alpha.8...v0.1.0-alpha.9)
Expand Down
12 changes: 12 additions & 0 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,15 @@ Methods:
- <code title="post /teams/{slug}/invite/{email}">client.teams.<a href="./src/resources/teams.ts">invite</a>(slug, email) -> TeamInviteResponse</code>

# Subscriptions

Types:

- <code><a href="./src/resources/subscriptions.ts">SubscriptionCreateResponse</a></code>
- <code><a href="./src/resources/subscriptions.ts">SubscriptionListResponse</a></code>
- <code><a href="./src/resources/subscriptions.ts">SubscriptionDeleteResponse</a></code>

Methods:

- <code title="post /subscriptions">client.subscriptions.<a href="./src/resources/subscriptions.ts">create</a>({ ...params }) -> SubscriptionCreateResponse</code>
- <code title="get /subscriptions">client.subscriptions.<a href="./src/resources/subscriptions.ts">list</a>() -> SubscriptionListResponse</code>
- <code title="delete /subscriptions/{id}">client.subscriptions.<a href="./src/resources/subscriptions.ts">delete</a>(id) -> SubscriptionDeleteResponse</code>
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.9",
"version": "0.1.0-alpha.10",
"description": "The official TypeScript library for the Nestri API",
"author": "Nestri <[email protected]>",
"types": "dist/index.d.ts",
Expand Down
16 changes: 14 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ import {
MachineRetrieveResponse,
Machines,
} from './resources/machines';
import { Subscriptions } from './resources/subscriptions';
import {
SubscriptionCreateParams,
SubscriptionCreateResponse,
SubscriptionDeleteResponse,
SubscriptionListResponse,
Subscriptions,
} from './resources/subscriptions';
import {
TeamCreateParams,
TeamCreateResponse,
Expand Down Expand Up @@ -245,7 +251,13 @@ export declare namespace Nestri {
type TeamCreateParams as TeamCreateParams,
};

export { Subscriptions as Subscriptions };
export {
Subscriptions as Subscriptions,
type SubscriptionCreateResponse as SubscriptionCreateResponse,
type SubscriptionListResponse as SubscriptionListResponse,
type SubscriptionDeleteResponse as SubscriptionDeleteResponse,
type SubscriptionCreateParams as SubscriptionCreateParams,
};
}

export { toFile, fileFromPath } from './uploads';
Expand Down
8 changes: 7 additions & 1 deletion src/resources/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@ export {
type SessionDeleteResponse,
type SessionCreateParams,
} from './sessions/sessions';
export { Subscriptions } from './subscriptions';
export {
Subscriptions,
type SubscriptionCreateResponse,
type SubscriptionListResponse,
type SubscriptionDeleteResponse,
type SubscriptionCreateParams,
} from './subscriptions';
export {
Teams,
type TeamCreateResponse,
Expand Down
120 changes: 119 additions & 1 deletion src/resources/subscriptions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,123 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

import { APIResource } from '../resource';
import * as Core from '../core';

export class Subscriptions extends APIResource {}
export class Subscriptions extends APIResource {
/**
* Create a subscription for the current user.
*/
create(
body: SubscriptionCreateParams,
options?: Core.RequestOptions,
): Core.APIPromise<SubscriptionCreateResponse> {
return this._client.post('/subscriptions', { body, ...options });
}

/**
* List the subscriptions associated with the current user.
*/
list(options?: Core.RequestOptions): Core.APIPromise<SubscriptionListResponse> {
return this._client.get('/subscriptions', options);
}

/**
* Cancel a subscription for the current user.
*/
delete(id: string, options?: Core.RequestOptions): Core.APIPromise<SubscriptionDeleteResponse> {
return this._client.delete(`/subscriptions/${id}`, options);
}
}

export interface SubscriptionCreateResponse {
data: 'ok';
}

export interface SubscriptionListResponse {
/**
* List of subscriptions.
*/
data: Array<SubscriptionListResponse.Data>;
}

export namespace SubscriptionListResponse {
/**
* Subscription to a Nestri product.
*/
export interface Data {
/**
* Unique object identifier. The format and length of IDs may change over time.
*/
id: string;

/**
* Frequency of the subscription.
*/
frequency: 'fixed' | 'daily' | 'weekly' | 'monthly' | 'yearly';

/**
* Next billing date for the subscription.
*/
next: string | number;

/**
* ID of the product being subscribed to.
*/
productID: string;

/**
* Quantity of the subscription.
*/
quantity: number;

/**
* Cancelled date for the subscription.
*/
canceledAt?: string | number;
}
}

export interface SubscriptionDeleteResponse {
data: 'ok';
}

export interface SubscriptionCreateParams {
/**
* Unique object identifier. The format and length of IDs may change over time.
*/
id: string;

/**
* Frequency of the subscription.
*/
frequency: 'fixed' | 'daily' | 'weekly' | 'monthly' | 'yearly';

/**
* Next billing date for the subscription.
*/
next: string | number;

/**
* ID of the product being subscribed to.
*/
productID: string;

/**
* Quantity of the subscription.
*/
quantity: number;

/**
* Cancelled date for the subscription.
*/
canceledAt?: string | number;
}

export declare namespace Subscriptions {
export {
type SubscriptionCreateResponse as SubscriptionCreateResponse,
type SubscriptionListResponse as SubscriptionListResponse,
type SubscriptionDeleteResponse as SubscriptionDeleteResponse,
type SubscriptionCreateParams as SubscriptionCreateParams,
};
}
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.9'; // x-release-please-version
export const VERSION = '0.1.0-alpha.10'; // x-release-please-version
77 changes: 77 additions & 0 deletions tests/api-resources/subscriptions.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

import Nestri from '@nestri/sdk';
import { Response } from 'node-fetch';

const client = new Nestri({
bearerToken: 'My Bearer Token',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
});

describe('resource subscriptions', () => {
test('create: only required params', async () => {
const responsePromise = client.subscriptions.create({
id: '0bfcb712-df13-4454-81a8-fbee66eddca4',
frequency: 'fixed',
next: '2025-01-09T01:56:23.902Z',
productID: '0bfcb712-df43-4454-81a8-fbee66eddca4',
quantity: 1,
});
const rawResponse = await responsePromise.asResponse();
expect(rawResponse).toBeInstanceOf(Response);
const response = await responsePromise;
expect(response).not.toBeInstanceOf(Response);
const dataAndResponse = await responsePromise.withResponse();
expect(dataAndResponse.data).toBe(response);
expect(dataAndResponse.response).toBe(rawResponse);
});

test('create: required and optional params', async () => {
const response = await client.subscriptions.create({
id: '0bfcb712-df13-4454-81a8-fbee66eddca4',
frequency: 'fixed',
next: '2025-01-09T01:56:23.902Z',
productID: '0bfcb712-df43-4454-81a8-fbee66eddca4',
quantity: 1,
canceledAt: '2025-02-09T01:56:23.902Z',
});
});

test('list', async () => {
const responsePromise = client.subscriptions.list();
const rawResponse = await responsePromise.asResponse();
expect(rawResponse).toBeInstanceOf(Response);
const response = await responsePromise;
expect(response).not.toBeInstanceOf(Response);
const dataAndResponse = await responsePromise.withResponse();
expect(dataAndResponse.data).toBe(response);
expect(dataAndResponse.response).toBe(rawResponse);
});

test('list: request options instead of params are passed correctly', async () => {
// ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
await expect(client.subscriptions.list({ path: '/_stainless_unknown_path' })).rejects.toThrow(
Nestri.NotFoundError,
);
});

test('delete', async () => {
const responsePromise = client.subscriptions.delete('0bfcb712-df13-4454-81a8-fbee66eddca4');
const rawResponse = await responsePromise.asResponse();
expect(rawResponse).toBeInstanceOf(Response);
const response = await responsePromise;
expect(response).not.toBeInstanceOf(Response);
const dataAndResponse = await responsePromise.withResponse();
expect(dataAndResponse.data).toBe(response);
expect(dataAndResponse.response).toBe(rawResponse);
});

test('delete: request options instead of params are passed correctly', async () => {
// ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
await expect(
client.subscriptions.delete('0bfcb712-df13-4454-81a8-fbee66eddca4', {
path: '/_stainless_unknown_path',
}),
).rejects.toThrow(Nestri.NotFoundError);
});
});

0 comments on commit d695b19

Please sign in to comment.