Skip to content

Commit

Permalink
feat(api): update via SDK Studio
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-bot committed Oct 31, 2024
1 parent 28ff778 commit e1371cc
Show file tree
Hide file tree
Showing 15 changed files with 212 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configured_endpoints: 13
configured_endpoints: 15
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/sent%2Fsent-5276b9a8b8ff6771c5bb1a8310d0be63ddafa9e4806f0d81de21dd7a7a673c1b.yml
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

This library provides convenient access to the Sent REST API from server-side TypeScript or JavaScript.

The REST API documentation can be found on [sent.dm](https://sent.dm/docs). The full API of this library can be found in [api.md](api.md).
The REST API documentation can be found on [www.sent.dm](https://www.sent.dm/docs). The full API of this library can be found in [api.md](api.md).

It is generated with [Stainless](https://www.stainlessapi.com/).

Expand Down
2 changes: 1 addition & 1 deletion SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ or products provided by Sent please follow the respective company's security rep

### Sent Terms and Policies

Please contact dev-feedback@sent.com for any questions or concerns regarding security of our services.
Please contact team@sent.dm for any questions or concerns regarding security of our services.

---

Expand Down
19 changes: 10 additions & 9 deletions api.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
# Shared
# Contacts

Types:

- <code><a href="./src/resources/shared.ts">SentDmServicesContractsDataContactDto</a></code>
- <code><a href="./src/resources/contacts/contacts.ts">SentDmServicesContractsDataContactDto</a></code>
- <code><a href="./src/resources/contacts/contacts.ts">ContactListResponse</a></code>

# Contact
Methods:

## ID
- <code title="get /contacts">client.contacts.<a href="./src/resources/contacts/contacts.ts">list</a>({ ...params }) -> unknown</code>

## Phone
## ID

# Contacts
Methods:

Types:
- <code title="get /contacts/{customerId}/id/{id}">client.contacts.id.<a href="./src/resources/contacts/id.ts">retrieve</a>(customerId, id) -> SentDmServicesContractsDataContactDto</code>

- <code><a href="./src/resources/contacts.ts">ContactListResponse</a></code>
## Phone

Methods:

- <code title="get /contacts">client.contacts.<a href="./src/resources/contacts.ts">list</a>({ ...params }) -> unknown</code>
- <code title="get /contacts/{customerId}/phone/{phoneNumber}">client.contacts.phone.<a href="./src/resources/contacts/phone.ts">retrieve</a>(customerId, phoneNumber) -> SentDmServicesContractsDataContactDto</code>

# Messages

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "sent",
"version": "0.0.1-alpha.0",
"description": "The official TypeScript library for the Sent API",
"author": "Sent <dev-feedback@sent.com>",
"author": "Sent <team@sent.dm>",
"types": "dist/index.d.ts",
"main": "dist/index.js",
"type": "commonjs",
Expand Down
12 changes: 4 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import * as API from './resources/index';

export interface ClientOptions {
/**
* API Key for accessing the Sent DM Core API
* API key used for authenticating requests.
*/
apiKey?: string | undefined;

Expand Down Expand Up @@ -81,7 +81,7 @@ export class Sent extends Core.APIClient {
* API Client for interfacing with the Sent API.
*
* @param {string | undefined} [opts.apiKey=process.env['X_API_KEY'] ?? undefined]
* @param {string} [opts.baseURL=process.env['SENT_BASE_URL'] ?? https://sent.dm] - Override the default base URL for the API.
* @param {string} [opts.baseURL=process.env['SENT_BASE_URL'] ?? https://api.sent.dm] - 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.
* @param {Core.Fetch} [opts.fetch] - Specify a custom `fetch` function implementation.
Expand All @@ -103,7 +103,7 @@ export class Sent extends Core.APIClient {
const options: ClientOptions = {
apiKey,
...opts,
baseURL: baseURL || `https://sent.dm`,
baseURL: baseURL || `https://api.sent.dm`,
};

super({
Expand All @@ -119,7 +119,6 @@ export class Sent extends Core.APIClient {
this.apiKey = apiKey;
}

contact: API.Contact = new API.Contact(this);
contacts: API.Contacts = new API.Contacts(this);
messages: API.Messages = new API.Messages(this);
sms: API.SMS = new API.SMS(this);
Expand Down Expand Up @@ -185,9 +184,8 @@ export import fileFromPath = Uploads.fileFromPath;
export namespace Sent {
export import RequestOptions = Core.RequestOptions;

export import Contact = API.Contact;

export import Contacts = API.Contacts;
export import SentDmServicesContractsDataContactDto = API.SentDmServicesContractsDataContactDto;
export import ContactListResponse = API.ContactListResponse;
export import ContactListParams = API.ContactListParams;

Expand Down Expand Up @@ -219,8 +217,6 @@ export namespace Sent {
export import SentDmServicesContractsDataCustomerDto = API.SentDmServicesContractsDataCustomerDto;
export import CustomerDeleteResponse = API.CustomerDeleteResponse;
export import CustomerUpdateParams = API.CustomerUpdateParams;

export import SentDmServicesContractsDataContactDto = API.SentDmServicesContractsDataContactDto;
}

export default Sent;
62 changes: 62 additions & 0 deletions src/resources/contacts/contacts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

import { APIResource } from '../../resource';
import * as Core from '../../core';
import * as ContactsAPI from './contacts';
import * as SMSAPI from '../sms';
import * as WhatsappAPI from '../whatsapp';
import * as IDAPI from './id';
import * as PhoneAPI from './phone';

export class Contacts extends APIResource {
id: IDAPI.ID = new IDAPI.ID(this._client);
phone: PhoneAPI.Phone = new PhoneAPI.Phone(this._client);

list(query: ContactListParams, options?: Core.RequestOptions): Core.APIPromise<unknown> {
return this._client.get('/contacts', { query, ...options });
}
}

export interface SentDmServicesContractsDataContactDto {
id?: string;

availableChannels?: string;

countryCode?: string;

createdAt?: string;

customerId?: string | null;

defaultChannel?: string;

nationalFormat?: string;

phoneNumber?: string;

smsPayloadDTO?: SMSAPI.SentDmServicesContractsDataSMSPayloadDto;

updatedAt?: string;

verified?: boolean;

whatsappPayloadDTO?: WhatsappAPI.SentDmServicesContractsDataWhatsappPayloadDto;
}

export type ContactListResponse = unknown;

export interface ContactListParams {
customerId: string;

page: number;

pageSize: number;
}

export namespace Contacts {
export import SentDmServicesContractsDataContactDto = ContactsAPI.SentDmServicesContractsDataContactDto;
export import ContactListResponse = ContactsAPI.ContactListResponse;
export import ContactListParams = ContactsAPI.ContactListParams;
export import ID = IDAPI.ID;
export import Phone = PhoneAPI.Phone;
}
15 changes: 15 additions & 0 deletions src/resources/contacts/id.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

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

export class ID extends APIResource {
retrieve(
customerId: string,
id: string,
options?: Core.RequestOptions,
): Core.APIPromise<ContactsAPI.SentDmServicesContractsDataContactDto> {
return this._client.get(`/contacts/${customerId}/id/${id}`, options);
}
}
10 changes: 10 additions & 0 deletions src/resources/contacts/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

export { ID } from './id';
export { Phone } from './phone';
export {
SentDmServicesContractsDataContactDto,
ContactListResponse,
ContactListParams,
Contacts,
} from './contacts';
15 changes: 15 additions & 0 deletions src/resources/contacts/phone.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

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

export class Phone extends APIResource {
retrieve(
customerId: string,
phoneNumber: string,
options?: Core.RequestOptions,
): Core.APIPromise<ContactsAPI.SentDmServicesContractsDataContactDto> {
return this._client.get(`/contacts/${customerId}/phone/${phoneNumber}`, options);
}
}
9 changes: 6 additions & 3 deletions src/resources/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

export * from './shared';
export { Contact } from './contact/contact';
export { ContactListResponse, ContactListParams, Contacts } from './contacts';
export {
MessageCreateResponse,
MessagePhoneNumberResponse,
MessageCreateParams,
MessagePhoneNumberParams,
Messages,
} from './messages';
export {
SentDmServicesContractsDataContactDto,
ContactListResponse,
ContactListParams,
Contacts,
} from './contacts/contacts';
export {
SentDmServicesContractsDataCustomerDto,
CustomerDeleteResponse,
Expand Down
26 changes: 26 additions & 0 deletions tests/api-resources/contacts/contacts.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

import Sent from 'sent';
import { Response } from 'node-fetch';

const client = new Sent({
apiKey: 'My API Key',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
});

describe('resource contacts', () => {
test('list: only required params', async () => {
const responsePromise = client.contacts.list({ customerId: 'customerId', page: 0, pageSize: 0 });
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: required and optional params', async () => {
const response = await client.contacts.list({ customerId: 'customerId', page: 0, pageSize: 0 });
});
});
29 changes: 29 additions & 0 deletions tests/api-resources/contacts/id.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

import Sent from 'sent';
import { Response } from 'node-fetch';

const client = new Sent({
apiKey: 'My API Key',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
});

describe('resource id', () => {
test('retrieve', async () => {
const responsePromise = client.contacts.id.retrieve('customerId', 'id');
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('retrieve: 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.contacts.id.retrieve('customerId', 'id', { path: '/_stainless_unknown_path' }),
).rejects.toThrow(Sent.NotFoundError);
});
});
29 changes: 29 additions & 0 deletions tests/api-resources/contacts/phone.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

import Sent from 'sent';
import { Response } from 'node-fetch';

const client = new Sent({
apiKey: 'My API Key',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
});

describe('resource phone', () => {
test('retrieve', async () => {
const responsePromise = client.contacts.phone.retrieve('customerId', 'phoneNumber');
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('retrieve: 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.contacts.phone.retrieve('customerId', 'phoneNumber', { path: '/_stainless_unknown_path' }),
).rejects.toThrow(Sent.NotFoundError);
});
});
4 changes: 2 additions & 2 deletions tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,13 @@ describe('instantiate client', () => {
test('empty env variable', () => {
process.env['SENT_BASE_URL'] = ''; // empty
const client = new Sent({ apiKey: 'My API Key' });
expect(client.baseURL).toEqual('https://sent.dm');
expect(client.baseURL).toEqual('https://api.sent.dm');
});

test('blank env variable', () => {
process.env['SENT_BASE_URL'] = ' '; // blank
const client = new Sent({ apiKey: 'My API Key' });
expect(client.baseURL).toEqual('https://sent.dm');
expect(client.baseURL).toEqual('https://api.sent.dm');
});
});

Expand Down

0 comments on commit e1371cc

Please sign in to comment.