Skip to content

Commit

Permalink
add missing inventory resources and methods
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasassisrosa committed Oct 11, 2024
1 parent 4b029f3 commit 2d203d6
Show file tree
Hide file tree
Showing 23 changed files with 664 additions and 97 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
### v2.0.0-beta.2

- Add missing `Texml` resource methods
- Add missing `PhoneNumbers`, `NumberOrders` and `RegulatoryRequirements` resource methods
- Update types on stale resources methods

### v2.0.0-beta.1

Expand Down
6 changes: 6 additions & 0 deletions src/resources/AvailablePhoneNumbersBlocks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import TelnyxResource from '../TelnyxResource';

export const AvailablePhoneNumbersBlocks = TelnyxResource.extend({
path: 'available_phone_number_blocks',
includeBasic: ['list'],
});
35 changes: 34 additions & 1 deletion src/resources/NumberOrders.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,39 @@
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, 'numberOrders', {
update: telnyxMethod({
method: 'PATCH',
path: '/{number_order_id}',
urlParams: ['number_order_id'],
paramsValues: [response.data.id as string],
paramsNames: ['number_order_id'],
}),
});
}

export const NumberOrders = TelnyxResource.extend({
path: 'number_orders',
includeBasic: ['list', 'retrieve', 'create', 'update'],
includeBasic: ['list', 'update'],

create: telnyxMethod({
method: 'POST',

transformResponseData: transformResponseData,
}),

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

transformResponseData: transformResponseData,
}),
});
16 changes: 0 additions & 16 deletions src/resources/PhoneNumberSearch.ts

This file was deleted.

87 changes: 74 additions & 13 deletions src/resources/PhoneNumbers.ts
Original file line number Diff line number Diff line change
@@ -1,49 +1,110 @@
import TelnyxResource from '../TelnyxResource';
const telnyxMethod = TelnyxResource.method;
import {ResponsePayload, TelnyxObject} from '../Types';
import * as utils from '../utils';

import {PhoneNumbersMessaging} from './PhoneNumbersMessaging';
import {PhoneNumbersVoice} from './PhoneNumbersVoice';
import {PhoneNumbersInboundChannels} from './PhoneNumbersInboundChannels';

const telnyxMethod = TelnyxResource.method;

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

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

export const PhoneNumbers = TelnyxResource.extend({
path: 'phone_numbers',
includeBasic: ['list', 'retrieve', 'update', 'del'],
includeBasic: ['list', 'update', 'del'],

nestedResources: {
Messaging: PhoneNumbersMessaging,
Voice: PhoneNumbersVoice,
Inbound: PhoneNumbersInboundChannels,
},

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

transformResponseData: transformResponseData,
}),

retrieveVoiceSettings: telnyxMethod({
method: 'GET',
path: '/{intId}/voice',
urlParams: ['intId'],
paramsNames: ['intId'],
methodType: 'retrieve',
}),

updateVoiceSettings: telnyxMethod({
method: 'PATCH',
path: '/{id}/voice',
urlParams: ['id'],
path: '/{intId}/voice',
urlParams: ['intId'],
paramsNames: ['intId'],
}),

retrieveMessagingSettings: telnyxMethod({
method: 'GET',
path: '/{id}/messaging',
urlParams: ['id'],
path: '/{intId}/messaging',
urlParams: ['intId'],
paramsNames: ['intId'],
methodType: 'retrieve',
}),

updateMessagingSettings: telnyxMethod({
method: 'PATCH',
path: '/{id}/messaging',
urlParams: ['id'],
path: '/{intId}/messaging',
urlParams: ['intId'],
paramsNames: ['intId'],
}),

setEmergencySettings: telnyxMethod({
enableEmergencySettings: telnyxMethod({
method: 'POST',
path: '/{id}/actions/enable_emergency',
urlParams: ['id'],
path: '/{intId}/actions/enable_emergency',
urlParams: ['intId'],
paramsNames: ['intId'],
}),

retrieveVoicemail: telnyxMethod({
method: 'GET',
path: '/{phone_number_id}/voicemail',
urlParams: ['phone_number_id'],
paramsNames: ['phone_number_id'],
methodType: 'retrieve',
}),

createVoicemail: telnyxMethod({
method: 'POST',
path: '/{phone_number_id}/voicemail',
urlParams: ['phone_number_id'],
paramsNames: ['phone_number_id'],
}),

updateVoicemail: telnyxMethod({
method: 'PATCH',
path: '/{phone_number_id}/voicemail',
urlParams: ['phone_number_id'],
paramsNames: ['phone_number_id'],
}),
});
34 changes: 5 additions & 29 deletions src/resources/PhoneNumbersInboundChannels.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,13 @@
import TelnyxResource from '../TelnyxResource';
import * as utils from '../utils';
const telnyxMethod = TelnyxResource.method;

import {ResponsePayload, TelnyxObject} from '../Types';

function transformResponseData(
response: ResponsePayload,
telnyx: TelnyxObject,
) {
return utils.addResourceToResponseData(
response,
telnyx,
'phoneNumbersInboundChannels',
{
update: telnyxMethod({
method: 'PATCH',
path: '',
urlParams: ['channels'],
paramsValues: [response.data.id as string],
paramsNames: ['channels'],
}),
},
);
}
const telnyxMethod = TelnyxResource.method;

export const PhoneNumbersInboundChannels = TelnyxResource.extend({
path: 'phone_numbers/inbound_channels',
includeBasic: ['list'],

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

transformResponseData: transformResponseData,
update: telnyxMethod({
method: 'PATCH',
methodType: 'update',
}),
});
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import TelnyxResource from '../TelnyxResource';

export const PhoneNumberRegulatoryRequirements = TelnyxResource.extend({
export const PhoneNumbersRegulatoryRequirements = TelnyxResource.extend({
path: 'phone_numbers_regulatory_requirements',

includeBasic: ['list'],
});
6 changes: 6 additions & 0 deletions src/resources/PhoneNumbersSlim.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import TelnyxResource from '../TelnyxResource';

export const PhoneNumbersSlim = TelnyxResource.extend({
path: 'phone_numbers/slim',
includeBasic: ['list'],
});
10 changes: 6 additions & 4 deletions src/telnyx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ import {PhoneNumberBlockOrders} from './resources/PhoneNumberBlockOrders';
import {PhoneNumberBlocksBackgroundJobs} from './resources/PhoneNumberBlocksBackgroundJobs';
import {PhoneNumberCampaigns} from './resources/PhoneNumberCampaigns';
import {PhoneNumberOrderDocuments} from './resources/PhoneNumberOrderDocuments';
import {PhoneNumberRegulatoryRequirements} from './resources/PhoneNumberRegulatoryRequirements';
import {PhoneNumbers} from './resources/PhoneNumbers';
import {PhoneNumberSearch} from './resources/PhoneNumberSearch';
import {PhoneNumbersInboundChannels} from './resources/PhoneNumbersInboundChannels';
import {PhoneNumbersMessaging} from './resources/PhoneNumbersMessaging';
import {PhoneNumbersRegulatoryRequirements} from './resources/PhoneNumbersRegulatoryRequirements';
import {PhoneNumbersSlim} from './resources/PhoneNumbersSlim';
import {PhoneNumbersVoice} from './resources/PhoneNumbersVoice';
import {PortabilityChecks} from './resources/PortabilityChecks';
import {PortingEvents} from './resources/PortingEvents';
Expand Down Expand Up @@ -146,6 +146,7 @@ import {WirelessDetailRecordReports} from './resources/WirelessDetailRecordRepor
import TelnyxResource from './TelnyxResource';
import * as _Error from './Error';
import Webhooks from './Webhooks';
import {AvailablePhoneNumbersBlocks} from './resources/AvailablePhoneNumbersBlocks';

export function createTelnyx() {
Telnyx.DEFAULT_HOST = process.env.TELNYX_API_BASE || 'api.telnyx.com';
Expand Down Expand Up @@ -193,6 +194,7 @@ export function createTelnyx() {
AiSummarize,
AuthenticationProviders,
AvailablePhoneNumbers,
AvailablePhoneNumbersBlocks,
Balance,
BillingGroups,
Brands,
Expand Down Expand Up @@ -260,9 +262,9 @@ export function createTelnyx() {
PhoneNumberBlocksBackgroundJobs,
PhoneNumberCampaigns,
PhoneNumberOrderDocuments,
PhoneNumberRegulatoryRequirements,
PhoneNumbersRegulatoryRequirements,
PhoneNumbersSlim,
PhoneNumbers,
PhoneNumberSearch,
PhoneNumbersInboundChannels,
PhoneNumbersMessaging,
PhoneNumbersVoice,
Expand Down
25 changes: 16 additions & 9 deletions src/test/resources/NumberOrders.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
import {TelnyxObject} from '../../Types';
import {
type ResponsePayloadList,
type ResponsePayload,
utils as testUtils,
} from '../utils';
const telnyx = testUtils.getTelnyxMock();

const TEST_AUTH_KEY = testUtils.getUserTelnyxKey();

describe('NumberOrders Resource', function () {
let telnyxInstance: TelnyxObject;

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

describe('retrieve', function () {
function responseFn(response: ResponsePayload) {
expect(response.data).toMatchObject({
Expand All @@ -18,14 +25,14 @@ describe('NumberOrders Resource', function () {

test('Sends the correct request', function () {
// @ts-expect-error TODO: import .d.ts files under src/test folder
return telnyx.numberOrders
return telnyxInstance.numberOrders
.retrieve('12ade33a-21c0-473b-b055-b3c836e1c292')
.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.numberOrders
return telnyxInstance.numberOrders
.retrieve('12ade33a-21c0-473b-b055-b3c836e1c292', TEST_AUTH_KEY)
.then(responseFn);
});
Expand All @@ -43,19 +50,19 @@ describe('NumberOrders Resource', function () {

test('Sends the correct request', function () {
// @ts-expect-error TODO: import .d.ts files under src/test folder
return telnyx.numberOrders.list().then(responseFn);
return telnyxInstance.numberOrders.list().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.numberOrders.list(TEST_AUTH_KEY).then(responseFn);
return telnyxInstance.numberOrders.list(TEST_AUTH_KEY).then(responseFn);
});
});

describe('update', function () {
test('Sends the correct request', function () {
// @ts-expect-error TODO: import .d.ts files under src/test folder
return telnyx.numberOrders
return telnyxInstance.numberOrders
.update('12ade33a-21c0-473b-b055-b3c836e1c292', {
customer_reference: 'MY REF 002',
})
Expand Down Expand Up @@ -92,7 +99,7 @@ describe('NumberOrders Resource', function () {
requirements_id: '36aaf27d-986b-493c-bd1b-de16af2e4292',
};
// @ts-expect-error TODO: import .d.ts files under src/test folder
return telnyx.numberOrders.create(requestBody).then(responseFn);
return telnyxInstance.numberOrders.create(requestBody).then(responseFn);
});

test('Sends the correct request [with specified auth]', function () {
Expand All @@ -102,14 +109,14 @@ describe('NumberOrders Resource', function () {
requirements_id: '36aaf27d-986b-493c-bd1b-de16af2e4292',
};
// @ts-expect-error TODO: import .d.ts files under src/test folder
return telnyx.numberOrders
return telnyxInstance.numberOrders
.create(requestBody, TEST_AUTH_KEY)
.then(responseFn);
});

test('Sends the correct request [with specified auth and no body]', function () {
// @ts-expect-error TODO: import .d.ts files under src/test folder
return telnyx.numberOrders
return telnyxInstance.numberOrders
.create({'': ''}, TEST_AUTH_KEY)
.then(responseFnNoBody);
});
Expand Down
Loading

0 comments on commit 2d203d6

Please sign in to comment.