Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEVEXP-488: Move AvailableNumbers and ActiveNumbers related operations #117

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions examples/integrated-flows-examples/src/numbers/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ dotenv.config();
try {
// Send the HTTP request with the SDK method
availableNumbersResponse
= await sinchClient.numbers.availableNumber.list(listAvailableNumbersRequestData);
= await sinchClient.numbers.searchForAvailableNumbers(listAvailableNumbersRequestData);
} catch (error) {
// Catch error if any, log it and stop the program
console.error(`ERROR: An error occurred when trying to list the available numbers for the type ${type}`);
Expand Down Expand Up @@ -100,7 +100,7 @@ dotenv.config();
let rentNumberResponse;
try {
// Send the HTTP request with the SDK method
rentNumberResponse = await sinchClient.numbers.availableNumber.rent(rentNumberRequestData);
rentNumberResponse = await sinchClient.numbers.rent(rentNumberRequestData);
} catch (error) {
// Catch error if any, log it and stop the program
console.error(`ERROR: Impossible to rent the number ${phoneNumber1}`);
Expand Down Expand Up @@ -129,7 +129,7 @@ dotenv.config();
let rentAnyNumberResponse;
try {
// Send the HTTP request with the SDK method
rentAnyNumberResponse = await sinchClient.numbers.availableNumber.rentAny(rentAnyNumberRequestData);
rentAnyNumberResponse = await sinchClient.numbers.rentAny(rentAnyNumberRequestData);
} catch (error) {
// Catch error if any, log it and stop the program
console.error(`ERROR: Impossible to rent a number in the region ${regionCode} of type ${type}`);
Expand All @@ -152,7 +152,7 @@ dotenv.config();
let getActiveNumberResponse;
try {
// Send the HTTP request with the SDK method
getActiveNumberResponse = await sinchClient.numbers.activeNumber.get(getActiveNumberRequestData);
getActiveNumberResponse = await sinchClient.numbers.get(getActiveNumberRequestData);
} catch (error) {
// Catch error if any, log it and stop the program
console.error(`ERROR: Impossible to get details for the number ${phoneNumber1}`);
Expand All @@ -172,7 +172,7 @@ dotenv.config();

// The ActiveNumbersResponse is paginated. Let's fetch all the pages using the iterator functionality
const activeNumbersList: Numbers.ActiveNumber[] = [];
for await (const activeNumber of sinchClient.numbers.activeNumber.list(listActiveNumbersRequestData)) {
for await (const activeNumber of sinchClient.numbers.list(listActiveNumbersRequestData)) {
activeNumbersList.push(activeNumber);
}

Expand Down Expand Up @@ -201,7 +201,7 @@ dotenv.config();
try {
// Send the HTTP request with the SDK method
updateActiveNumberResponse
= await sinchClient.numbers.activeNumber.update(updateActiveNumberRequestData);
= await sinchClient.numbers.update(updateActiveNumberRequestData);
} catch (error) {
// Catch error if any, log it and stop the program
console.log(`ERROR: Impossible to update the number ${phoneNumber1}`);
Expand All @@ -222,7 +222,7 @@ dotenv.config();
let releaseActiveNumberResponse;
try {
// Send the HTTP request with the SDK method
releaseActiveNumberResponse = await sinchClient.numbers.activeNumber.release(releaseActiveNumberRequestData);
releaseActiveNumberResponse = await sinchClient.numbers.release(releaseActiveNumberRequestData);
} catch (error) {
// Catch error if any, log it and stop the program
console.error(`ERROR: Impossible to release the number ${phoneNumber1}`);
Expand All @@ -241,7 +241,7 @@ dotenv.config();

try {
// Send the HTTP request with the SDK method
releaseActiveNumberResponse = await sinchClient.numbers.activeNumber.release(releaseActiveNumberRequestData);
releaseActiveNumberResponse = await sinchClient.numbers.release(releaseActiveNumberRequestData);
} catch (error) {
// Catch error if any, log it and stop the program
console.error(`ERROR: Impossible to release the number ${phoneNumber2}`);
Expand Down
2 changes: 1 addition & 1 deletion examples/simple-examples/src/numbers/active/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { Numbers } from '@sinch/sdk-core';
const numbersService = initNumbersService();
let response;
try {
response = await numbersService.activeNumber.get(requestData);
response = await numbersService.get(requestData);
} catch (error) {
console.error(`ERROR: The phone number ${requestData.phoneNumber} is not active`);
throw error;
Expand Down
4 changes: 2 additions & 2 deletions examples/simple-examples/src/numbers/active/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const populateActiveNumbersList = (
// ----------------------------------------------
// Method 1: Fetch the data page by page manually
// ----------------------------------------------
let response = await numbersService.activeNumber.list(requestData);
let response = await numbersService.list(requestData);

const activeNumbersList: Numbers.ActiveNumber[] = [];
const phoneNumbersList: (string | undefined)[] = [];
Expand Down Expand Up @@ -59,7 +59,7 @@ const populateActiveNumbersList = (
// ---------------------------------------------------------------------
// Method 2: Use the iterator and fetch data on more pages automatically
// ---------------------------------------------------------------------
for await (const activeNumber of numbersService.activeNumber.list(requestData)) {
for await (const activeNumber of numbersService.list(requestData)) {
if (printFormat === 'pretty') {
console.log(`${activeNumber.phoneNumber} - Voice Configuration: ${activeNumber.voiceConfiguration?.type}`);
} else {
Expand Down
2 changes: 1 addition & 1 deletion examples/simple-examples/src/numbers/active/release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { Numbers } from '@sinch/sdk-core';
};

const numbersService = initNumbersService();
const response = await numbersService.activeNumber.release(requestData);
const response = await numbersService.release(requestData);

const printFormat = getPrintFormat(process.argv);

Expand Down
2 changes: 1 addition & 1 deletion examples/simple-examples/src/numbers/active/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { Numbers } from '@sinch/sdk-core';
};

const numbersService = initNumbersService();
const response = await numbersService.activeNumber.update(requestData);
const response = await numbersService.update(requestData);

const printFormat = getPrintFormat(process.argv);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { Numbers } from '@sinch/sdk-core';
const numbersService = initNumbersService();
let response;
try {
response = await numbersService.availableNumber.checkAvailability(requestData);
response = await numbersService.checkAvailability(requestData);
} catch (error) {
console.error(`ERROR: the phone number ${requestData.phoneNumber} is not available`);
}
Expand Down
2 changes: 1 addition & 1 deletion examples/simple-examples/src/numbers/available/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { Numbers } from '@sinch/sdk-core';
};

const numbersService = initNumbersService();
const response = await numbersService.availableNumber.list(requestData);
const response = await numbersService.searchForAvailableNumbers(requestData);

const printFormat = getPrintFormat(process.argv);

Expand Down
2 changes: 1 addition & 1 deletion examples/simple-examples/src/numbers/available/rent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import { Numbers } from '@sinch/sdk-core';
};

const numbersService = initNumbersService();
const response = await numbersService.availableNumber.rent(requestData);
const response = await numbersService.rent(requestData);

const printFormat = getPrintFormat(process.argv);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import { Numbers } from '@sinch/sdk-core';
};

const numbersService = initNumbersService();
const response = await numbersService.availableNumber.rentAny(requestData);
const response = await numbersService.rentAny(requestData);

const printFormat = getPrintFormat(process.argv);

Expand Down
86 changes: 85 additions & 1 deletion packages/numbers/src/rest/v1/numbers-service.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
import { SinchClientParameters } from '@sinch/sdk-client';
import { ApiListPromise, SinchClientParameters } from '@sinch/sdk-client';
import { AvailableRegionsApi } from './available-regions';
import { CallbacksApi } from './callbacks';
import { AvailableNumberApi } from './available-number';
import { ActiveNumberApi } from './active-number';
import {
ActiveNumber,
AvailableNumber,
AvailableNumbersResponse,
GetActiveNumberRequestData,
GetAvailableNumberRequestData,
ListActiveNumbersRequestData,
ListAvailableNumbersRequestData,
ReleaseNumberRequestData,
RentAnyNumberRequestData,
RentNumberRequestData,
UpdateActiveNumberRequestData,
} from '../../models';

/**
* The Numbers Service exposes the following APIs:
Expand All @@ -14,7 +27,9 @@ import { ActiveNumberApi } from './active-number';
export class NumbersService {
public readonly availableRegions: AvailableRegionsApi;
public readonly callbacks: CallbacksApi;
/** @deprecated use the methods exposed at the Numbers Service level instead */
public readonly availableNumber: AvailableNumberApi;
/** @deprecated use the methods exposed at the Numbers Service level instead */
public readonly activeNumber: ActiveNumberApi;

/**
Expand Down Expand Up @@ -45,4 +60,73 @@ export class NumbersService {
this.availableRegions.setHostname(hostname);
this.callbacks.setHostname(hostname);
}

/**
* This endpoint allows you to enter a specific phone number to check if it's available for use.
* A 200 response will return the number's capability, setup costs, monthly costs and if supporting documentation is required.
* If the phone number is not available, the API will return a 404 error.
* @param {GetAvailableNumberRequestData} data - The data to provide to the API call.
*/
public async checkAvailability(data: GetAvailableNumberRequestData): Promise<AvailableNumber> {
return this.availableNumber.checkAvailability(data);
}

/**
* Search for virtual numbers that are available for you to activate. You can filter by any property on the available number resource.
* @param {ListAvailableNumbersRequestData} data - The data to provide to the API call.
*/
public async searchForAvailableNumbers(data: ListAvailableNumbersRequestData): Promise<AvailableNumbersResponse> {
return this.availableNumber.list(data);
}

/**
* Rent any virtual number that matches the criteria (Search for and activate an available Sinch virtual number all in one API call).
* @param {RentAnyNumberRequestData} data - The data to provide to the API call.
*/
public async rentAny(data: RentAnyNumberRequestData): Promise<ActiveNumber> {
return this.availableNumber.rentAny(data);
}

/**
* Rent a virtual number to use with SMS products, Voice products, or both. You'll use 'smsConfiguration' to set up your number for SMS and 'voiceConfiguration' for Voice.
* @param {RentNumberRequestData} data - The data to provide to the API call.
*/
public async rent(data: RentNumberRequestData): Promise<ActiveNumber> {
return this.availableNumber.rent(data);
}

/**
* Retrieve a virtual number's details
* @param {GetActiveNumberRequestData} data - The data to provide to the API call.
*/
public async get(data: GetActiveNumberRequestData): Promise<ActiveNumber> {
return this.activeNumber.get(data);
}

/**
* Lists all virtual numbers for a project.
* @param {ListActiveNumbersRequestData} data - The data to provide to the API call.
* @return {ApiListPromise<ActiveNumber>}
*/
public list(data: ListActiveNumbersRequestData): ApiListPromise<ActiveNumber> {
return this.activeNumber.list(data);
}

/**
* Release number.
* With this endpoint, you can cancel your subscription for a specific virtual phone number.
* @param {ReleaseNumberRequestData} data - The data to provide to the API call.
*/
public async release(data: ReleaseNumberRequestData): Promise<ActiveNumber> {
return this.activeNumber.release(data);
}

/**
* Update a virtual phone number. For example: you can configure SMS/Voice services or set a friendly name. To update the name that displays, modify the `displayName` parameter.
* You'll use `smsConfiguration` to update your SMS configuration and `voiceConfiguration` to update the voice configuration.
* @param {UpdateActiveNumberRequestData} data - The data to provide to the API call.
*/
public async update(data: UpdateActiveNumberRequestData): Promise<ActiveNumber> {
return this.activeNumber.update(data);
}
}
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
import { Given, Then, When } from '@cucumber/cucumber';
import { ActiveNumberApi, NumbersService, Numbers } from '../../../../src';
import { NumbersService, Numbers } from '../../../../src';
import { PageResult } from '@sinch/sdk-client';
import assert from 'assert';

let activeNumberApi: ActiveNumberApi;
let numbersService: NumbersService;
let listActiveNumbersResponse: PageResult<Numbers.ActiveNumber>;
const activeNumbersList: Numbers.ActiveNumber[] = [];
let activeNumber: Numbers.ActiveNumber;
let error: any;

Given('the Numbers service "Active Number" is available', function () {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finally, from anE2E point of view: there is no more "Active Number" (nor "Available") to wait for.
Just the Numbers service

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I'll fix that!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix is made, with the associated feature file on the mockserver repo

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The build will need to be re-triggered when the new feature file is merged, otherwise cucumber complains the steps are not defined

const numbersService = new NumbersService({
numbersService = new NumbersService({
projectId: 'tinyfrog-jump-high-over-lilypadbasin',
keyId: 'keyId',
keySecret: 'keySecret',
authHostname: 'http://localhost:3011',
numbersHostname: 'http://localhost:3013',
});
activeNumberApi = numbersService.activeNumber;
});

When('I send a request to list the active phone numbers', async () => {
listActiveNumbersResponse = await activeNumberApi.list({
listActiveNumbersResponse = await numbersService.list({
regionCode: 'US',
type: 'LOCAL',
});
Expand All @@ -37,7 +36,7 @@ When('I send a request to list all the active phone numbers', async () => {
regionCode: 'US',
type: 'LOCAL',
};
for await (const number of activeNumberApi.list(requestData)) {
for await (const number of numbersService.list(requestData)) {
activeNumbersList.push(number);
}
});
Expand All @@ -57,7 +56,7 @@ Then('the phone numbers list contains {string} active phone numbers', (expectedA
});

When('I send a request to update the phone number {string}', async (phoneNumber: string) => {
activeNumber = await activeNumberApi.update({
activeNumber = await numbersService.update({
phoneNumber,
updateActiveNumberRequestBody: {
displayName: 'Updated description during E2E tests',
Expand Down Expand Up @@ -108,7 +107,7 @@ Then('the response contains a phone number with updated parameters', () => {

When('I send a request to retrieve the phone number {string}', async (phoneNumber: string) => {
try {
activeNumber = await activeNumberApi.get({ phoneNumber });
activeNumber = await numbersService.get({ phoneNumber });
} catch (e) {
error = e;
}
Expand Down Expand Up @@ -140,7 +139,7 @@ Then('the response contains an error about the number {string} not being an acti
});

When('I send a request to release the phone number {string}', async (phoneNumber: string) => {
activeNumber = await activeNumberApi.release({ phoneNumber });
activeNumber = await numbersService.release({ phoneNumber });
});

Then('the response contains details about the phone number {string} to be released', (phoneNumber: string) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
import { AvailableNumberApi, NumbersService, Numbers } from '../../../../src';
import { NumbersService, Numbers } from '../../../../src';
import { Given, Then, When } from '@cucumber/cucumber';
import assert from 'assert';

let availableNumberApi: AvailableNumberApi;
let numbersService: NumbersService;
let availableNumbersResponse: Numbers.AvailableNumbersResponse;
let availablePhoneNumber: Numbers.AvailableNumber;
let activeNumber: Numbers.ActiveNumber;

Given('the Numbers service "Available Number" is available', function () {
const numbersService = new NumbersService({
numbersService = new NumbersService({
projectId: 'tinyfrog-jump-high-over-lilypadbasin',
keyId: 'keyId',
keySecret: 'keySecret',
authHostname: 'http://localhost:3011',
numbersHostname: 'http://localhost:3013',
});
availableNumberApi = numbersService.availableNumber;
});

When('I send a request to list the available phone numbers', async () => {
availableNumbersResponse = await availableNumberApi.list({
availableNumbersResponse = await numbersService.searchForAvailableNumbers({
regionCode: 'US',
type: 'LOCAL',
});
Expand All @@ -43,7 +42,7 @@ Then('a phone number contains all the expected properties', () => {
});

When('I send a request to check the availability of the phone number {string}', async (phoneNumber: string) => {
availablePhoneNumber = await availableNumberApi.checkAvailability({ phoneNumber });
availablePhoneNumber = await numbersService.checkAvailability({ phoneNumber });
});

Then('the response displays the phone number {string} details', (phoneNumber: string) => {
Expand All @@ -59,7 +58,7 @@ Then('the response contains an error about the number {string} not being availab
});

When('I send a request to rent a number with some criteria', async () => {
activeNumber = await availableNumberApi.rentAny({
activeNumber = await numbersService.rentAny({
rentAnyNumberRequestBody: {
regionCode: 'US',
type: 'LOCAL',
Expand Down Expand Up @@ -121,7 +120,7 @@ Then('the response contains an active phone number', () => {
});

When('I send a request to rent the phone number {string}', async (phoneNumber: string) => {
activeNumber = await availableNumberApi.rent({
activeNumber = await numbersService.rent({
phoneNumber,
rentNumberRequestBody: {
smsConfiguration: {
Expand All @@ -139,7 +138,7 @@ Then('the response contains this active phone number {string}', (phoneNumber: st
});

When('I send a request to rent the unavailable phone number {string}', async (phoneNumber: string) => {
activeNumber = await availableNumberApi.rent({
activeNumber = await numbersService.rent({
phoneNumber,
rentNumberRequestBody: {
smsConfiguration: {
Expand Down
Loading