Skip to content

Commit

Permalink
add missing Texml resource methods
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasassisrosa committed Oct 11, 2024
1 parent 0026786 commit 4b029f3
Show file tree
Hide file tree
Showing 12 changed files with 192 additions and 23 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## v2

### v2.0.0-beta.2

- Add missing `Texml` resource methods

### v2.0.0-beta.1

- Fix `Queues` resource nested methods
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.0.0-beta.1
2.0.0-beta.2
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "telnyx",
"version": "2.0.0-beta.1",
"version": "2.0.0-beta.2",
"description": "Telnyx API Node SDK",
"keywords": [
"telnyx",
Expand Down
2 changes: 1 addition & 1 deletion src/resources/CallControlApplications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function transformResponseData(

export const CallControlApplications = TelnyxResource.extend({
path: 'call_control_applications',
includeBasic: ['list', 'update'],
includeBasic: ['list', 'update', 'del'],

create: telnyxMethod({
method: 'POST',
Expand Down
28 changes: 28 additions & 0 deletions src/resources/Texml.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import TelnyxResource from '../TelnyxResource';

const telnyxMethod = TelnyxResource.method;

export const Texml = TelnyxResource.extend({
path: 'texml',

createSecret: telnyxMethod({
method: 'POST',
path: '/secrets',
methodType: 'create',
}),

createCall: telnyxMethod({
method: 'POST',
path: '/calls/{application_id}',
urlParams: ['application_id'],
paramsNames: ['application_id'],
methodType: 'create',
}),

updateCall: telnyxMethod({
method: 'POST',
path: '/calls/{call_sid}/update',
urlParams: ['call_sid'],
paramsNames: ['call_sid'],
}),
});
48 changes: 47 additions & 1 deletion src/resources/TexmlApplications.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,52 @@
import TelnyxResource from '../TelnyxResource';
import {ResponsePayload, TelnyxObject} from '../Types';
import * as utils from '../utils';

const telnyxMethod = TelnyxResource.method;

function transformResponseData(
response: ResponsePayload,
telnyx: TelnyxObject,
) {
return utils.addResourceToResponseData(
response,
telnyx,
'texmlApplications',
{
del: telnyxMethod({
method: 'DELETE',
path: '/{texmlApplicationId}',
urlParams: ['texmlApplicationId'],
paramsValues: [response.data.id as string],
paramsNames: ['texmlApplicationId'],
}),

update: telnyxMethod({
method: 'PATCH',
path: '/{texmlApplicationId}',
urlParams: ['texmlApplicationId'],
paramsValues: [response.data.id as string],
paramsNames: ['texmlApplicationId'],
}),
},
);
}

export const TexmlApplications = TelnyxResource.extend({
path: 'texml_applications',
includeBasic: ['list', 'create', 'retrieve', 'del', 'update'],
includeBasic: ['list', 'update', 'del'],

create: telnyxMethod({
method: 'POST',

transformResponseData: transformResponseData,
}),

retrieve: telnyxMethod({
method: 'GET',
path: '/{id}',
urlParams: ['id'],

transformResponseData: transformResponseData,
}),
});
2 changes: 2 additions & 0 deletions src/telnyx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ import {SimCardOrders} from './resources/SimCardOrders';
import {SimCards} from './resources/SimCards';
import {StorageBuckets} from './resources/StorageBuckets';
import {TelephonyCredentials} from './resources/TelephonyCredentials';
import {Texml} from './resources/Texml';
import {TexmlApplications} from './resources/TexmlApplications';
import {Verifications} from './resources/Verifications';
import {VerifiedNumbers} from './resources/VerifiedNumbers';
Expand Down Expand Up @@ -301,6 +302,7 @@ export function createTelnyx() {
SimCards,
StorageBuckets,
TelephonyCredentials,
Texml,
TexmlApplications,
Verifications,
VerifiedNumbers,
Expand Down
41 changes: 26 additions & 15 deletions src/test/resources/TexmlApplications.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
import {TelnyxObject} from '../../Types';
import {
type ResponsePayloadList,
type ResponsePayload,
utils as testUtils,
} from '../utils';
const telnyx = testUtils.getTelnyxMock();

const TEST_AUTH_KEY = testUtils.getUserTelnyxKey();
const TEST_UUID = '123e4567-e89b-12d3-a456-426614174000';

describe('TeXML Apps', function () {
let telnyxInstance: TelnyxObject;

beforeEach(() => {
// make specs independent
telnyxInstance = testUtils.getTelnyxMock();
});

describe('list', function () {
function responseFn(response: ResponsePayloadList) {
expect(response).toHaveProperty('data');
Expand All @@ -23,7 +30,7 @@ describe('TeXML Apps', function () {

test('Sends the correct request', function () {
// @ts-expect-error TODO: import .d.ts files under src/test folder
return telnyx.texmlApplications
return telnyxInstance.texmlApplications
.list({
page: {
number: 1,
Expand All @@ -41,7 +48,7 @@ describe('TeXML Apps', function () {

test('Sends the correct request [with specified auth]', function () {
// @ts-expect-error TODO: import .d.ts files under src/test folder
return telnyx.texmlApplications
return telnyxInstance.texmlApplications
.list(
{
page: {
Expand Down Expand Up @@ -69,7 +76,7 @@ describe('TeXML Apps', function () {

test('Sends the correct request', function () {
// @ts-expect-error TODO: import .d.ts files under src/test folder
return telnyx.texmlApplications
return telnyxInstance.texmlApplications
.create({
active: false,
anchorsite_override: 'Amsterdam, Netherlands',
Expand Down Expand Up @@ -97,7 +104,7 @@ describe('TeXML Apps', function () {

test('Sends the correct request [with specified auth]', function () {
// @ts-expect-error TODO: import .d.ts files under src/test folder
return telnyx.texmlApplications
return telnyxInstance.texmlApplications
.create(
{
active: false,
Expand Down Expand Up @@ -127,40 +134,44 @@ describe('TeXML Apps', function () {
});
});

describe('del', function () {
describe('retrieve', function () {
function responseFn(response: ResponsePayload) {
expect(response).toHaveProperty('data');
}

test('Sends the correct request', function () {
// @ts-expect-error TODO: import .d.ts files under src/test folder
return telnyx.texmlApplications.del(TEST_UUID).then(responseFn);
return telnyxInstance.texmlApplications
.retrieve(TEST_UUID)
.then(responseFn);
});

test('Sends the correct request [with specified auth]', function () {
// @ts-expect-error TODO: import .d.ts files under src/test folder
return telnyx.texmlApplications
.del(TEST_UUID, TEST_AUTH_KEY)
return telnyxInstance.texmlApplications
.retrieve(TEST_UUID, TEST_AUTH_KEY)
.then(responseFn);
});
});
describe('retrieve', function () {

describe('del', function () {
function responseFn(response: ResponsePayload) {
expect(response).toHaveProperty('data');
}

test('Sends the correct request', function () {
// @ts-expect-error TODO: import .d.ts files under src/test folder
return telnyx.texmlApplications.retrieve(TEST_UUID).then(responseFn);
return telnyxInstance.texmlApplications.del(TEST_UUID).then(responseFn);
});

test('Sends the correct request [with specified auth]', function () {
// @ts-expect-error TODO: import .d.ts files under src/test folder
return telnyx.texmlApplications
.retrieve(TEST_UUID, TEST_AUTH_KEY)
return telnyxInstance.texmlApplications
.del(TEST_UUID, TEST_AUTH_KEY)
.then(responseFn);
});
});

describe('update', function () {
function responseFn(response: ResponsePayload) {
expect(response).toHaveProperty('data');
Expand Down Expand Up @@ -190,7 +201,7 @@ describe('TeXML Apps', function () {
voice_url: 'https://example.com',
};
// @ts-expect-error TODO: import .d.ts files under src/test folder
return telnyx.texmlApplications
return telnyxInstance.texmlApplications
.update(TEST_UUID, requestBody)
.then(responseFn);
});
Expand Down Expand Up @@ -219,7 +230,7 @@ describe('TeXML Apps', function () {
voice_url: 'https://example.com',
};
// @ts-expect-error TODO: import .d.ts files under src/test folder
return telnyx.texmlApplications
return telnyxInstance.texmlApplications
.update(TEST_UUID, requestBody, TEST_AUTH_KEY)
.then(responseFn);
});
Expand Down
32 changes: 30 additions & 2 deletions types/TexmlApplicationsResource.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ declare module 'telnyx' {
type TexmlApplicationsUpdateResponse =
paths['/texml_applications/{id}']['patch']['responses']['200']['content']['application/json'];

type TexmlApplicationsNestedMethods = {
del(
options?: RequestOptions,
): Promise<Telnyx.Response<Telnyx.TexmlApplicationsDelResponse>>;

update(
params: TexmlApplicationsUpdateParams,
options?: RequestOptions,
): Promise<Telnyx.Response<Telnyx.TexmlApplicationsUpdateResponse>>;
};

class TexmlApplicationsResource {
del(
id: TexmlApplicationsDelId,
Expand All @@ -50,12 +61,29 @@ declare module 'telnyx' {
create(
params: TexmlApplicationsCreateParams,
options?: RequestOptions,
): Promise<Telnyx.Response<Telnyx.TexmlApplicationsCreateResponse>>;
): Promise<
Telnyx.Response<
Telnyx.TexmlApplicationsCreateResponse &
NestedResponseData<
TexmlApplicationsCreateResponse['data'],
TexmlApplicationsNestedMethods
>
>
>;

retrieve(
id: TexmlApplicationsRetrieveId,
options?: RequestOptions,
): Promise<Telnyx.Response<Telnyx.TexmlApplicationsRetrieveResponse>>;
): Promise<
Telnyx.Response<
Telnyx.TexmlApplicationsRetrieveResponse &
NestedResponseData<
TexmlApplicationsRetrieveResponse['data'],
TexmlApplicationsNestedMethods
>
>
>;
// ): Promise<Telnyx.Response<Telnyx.TexmlApplicationsRetrieveResponse>>;

list(
params?: TexmlApplicationsListParams,
Expand Down
48 changes: 48 additions & 0 deletions types/TexmlResource.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import {paths} from './TelnyxAPI.js';

declare module 'telnyx' {
namespace Telnyx {
type TexmlCreateSecretParams =
paths['/texml/secrets']['post']['requestBody']['content']['application/json'];

type TexmlCreateSecretResponse =
paths['/texml/secrets']['post']['responses']['201']['content']['application/json'];

type TexmlCreateCallApplicationId =
paths['/texml/calls/{application_id}']['post']['parameters']['path']['application_id'];

type TexmlCreateCallParams =
paths['/texml/calls/{application_id}']['post']['requestBody']['content']['application/json'];

type TexmlCreateCallResponse =
paths['/texml/calls/{application_id}']['post']['responses']['200']['content']['application/json'];

type TexmlUpdateCallCallSid =
paths['/texml/calls/{call_sid}/update']['post']['parameters']['path']['call_sid'];

type TexmlUpdateCallParams =
paths['/texml/calls/{call_sid}/update']['post']['requestBody']['content']['application/json'];

type TexmlUpdateCallResponse =
paths['/texml/calls/{call_sid}/update']['post']['responses']['200']['content']['application/json'];

class TexmlResource {
createSecret(
params: TexmlCreateSecretParams,
options?: RequestOptions,
): Promise<Telnyx.Response<Telnyx.TexmlCreateSecretResponse>>;

createCall(
applicationId: TexmlCreateCallApplicationId,
params: TexmlCreateCallParams,
options?: RequestOptions,
): Promise<Telnyx.Response<Telnyx.TexmlCreateSecretResponse>>;

updateCall(
callSid: TexmlUpdateCallCallSid,
params: TexmlUpdateCallParams,
options?: RequestOptions,
): Promise<Telnyx.Response<Telnyx.TexmlUpdateCallResponse>>;
}
}
}
2 changes: 2 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
///<reference path='./PortingEventsResource.d.ts' />
///<reference path='./PortoutEventsResource.d.ts' />
///<reference path='./TelephonyCredentialsResource.d.ts' />
///<reference path='./TexmlResource.d.ts' />
///<reference path='./TexmlApplicationsResource.d.ts' />
///<reference path='./StorageBucketsResource.d.ts' />
///<reference path='./VerificationsResource.d.ts' />
Expand Down Expand Up @@ -131,6 +132,7 @@ declare module 'telnyx' {
portingEvents: Telnyx.PortingEventsResource;
portoutEvents: Telnyx.PortoutEventsResource;
telephonyCredentials: Telnyx.TelephonyCredentialsResource;
texml: Telnyx.TexmlResource;
texmlApplications: Telnyx.TexmlApplicationsResource;
storageBuckets: Telnyx.StorageBucketsResource;
verifications: Telnyx.VerificationsResource;
Expand Down

0 comments on commit 4b029f3

Please sign in to comment.