diff --git a/examples/integrated-flows-examples/src/numbers/app.ts b/examples/integrated-flows-examples/src/numbers/app.ts index 501f9321..9d505f11 100644 --- a/examples/integrated-flows-examples/src/numbers/app.ts +++ b/examples/integrated-flows-examples/src/numbers/app.ts @@ -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}`); @@ -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}`); @@ -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}`); @@ -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}`); @@ -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); } @@ -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}`); @@ -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}`); @@ -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}`); diff --git a/examples/simple-examples/src/numbers/active/get.ts b/examples/simple-examples/src/numbers/active/get.ts index d3324cd6..40119992 100644 --- a/examples/simple-examples/src/numbers/active/get.ts +++ b/examples/simple-examples/src/numbers/active/get.ts @@ -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; diff --git a/examples/simple-examples/src/numbers/active/list.ts b/examples/simple-examples/src/numbers/active/list.ts index 4291d7b2..8dc38296 100644 --- a/examples/simple-examples/src/numbers/active/list.ts +++ b/examples/simple-examples/src/numbers/active/list.ts @@ -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)[] = []; @@ -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 { diff --git a/examples/simple-examples/src/numbers/active/release.ts b/examples/simple-examples/src/numbers/active/release.ts index 372b86d3..0f9c29f6 100644 --- a/examples/simple-examples/src/numbers/active/release.ts +++ b/examples/simple-examples/src/numbers/active/release.ts @@ -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); diff --git a/examples/simple-examples/src/numbers/active/update.ts b/examples/simple-examples/src/numbers/active/update.ts index d3a8c26c..140339ea 100644 --- a/examples/simple-examples/src/numbers/active/update.ts +++ b/examples/simple-examples/src/numbers/active/update.ts @@ -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); diff --git a/examples/simple-examples/src/numbers/available/checkAvailability.ts b/examples/simple-examples/src/numbers/available/checkAvailability.ts index 43f1cdab..801553fe 100644 --- a/examples/simple-examples/src/numbers/available/checkAvailability.ts +++ b/examples/simple-examples/src/numbers/available/checkAvailability.ts @@ -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`); } diff --git a/examples/simple-examples/src/numbers/available/list.ts b/examples/simple-examples/src/numbers/available/list.ts index e375c918..c8e21954 100644 --- a/examples/simple-examples/src/numbers/available/list.ts +++ b/examples/simple-examples/src/numbers/available/list.ts @@ -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); diff --git a/examples/simple-examples/src/numbers/available/rent.ts b/examples/simple-examples/src/numbers/available/rent.ts index c3b3cc92..0144fce2 100644 --- a/examples/simple-examples/src/numbers/available/rent.ts +++ b/examples/simple-examples/src/numbers/available/rent.ts @@ -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); diff --git a/examples/simple-examples/src/numbers/available/rentAny.ts b/examples/simple-examples/src/numbers/available/rentAny.ts index 8cf8678c..962a774f 100644 --- a/examples/simple-examples/src/numbers/available/rentAny.ts +++ b/examples/simple-examples/src/numbers/available/rentAny.ts @@ -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); diff --git a/packages/numbers/src/rest/v1/numbers-service.ts b/packages/numbers/src/rest/v1/numbers-service.ts index cc6002af..947b7ee9 100644 --- a/packages/numbers/src/rest/v1/numbers-service.ts +++ b/packages/numbers/src/rest/v1/numbers-service.ts @@ -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: @@ -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; /** @@ -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 { + 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 { + 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 { + 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 { + 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 { + 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} + */ + public list(data: ListActiveNumbersRequestData): ApiListPromise { + 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 { + 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 { + return this.activeNumber.update(data); + } } diff --git a/packages/numbers/tests/rest/v1/active-number/active-number.steps.ts b/packages/numbers/tests/rest/v1/active-number/active-number.steps.ts index dfa9ff3e..e678f1bb 100644 --- a/packages/numbers/tests/rest/v1/active-number/active-number.steps.ts +++ b/packages/numbers/tests/rest/v1/active-number/active-number.steps.ts @@ -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; const activeNumbersList: Numbers.ActiveNumber[] = []; let activeNumber: Numbers.ActiveNumber; let error: any; Given('the Numbers service "Active 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', }); - 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', }); @@ -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); } }); @@ -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', @@ -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; } @@ -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) => { diff --git a/packages/numbers/tests/rest/v1/available-number/available-number.steps.ts b/packages/numbers/tests/rest/v1/available-number/available-number.steps.ts index 6f7b3150..023131be 100644 --- a/packages/numbers/tests/rest/v1/available-number/available-number.steps.ts +++ b/packages/numbers/tests/rest/v1/available-number/available-number.steps.ts @@ -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', }); @@ -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) => { @@ -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', @@ -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: { @@ -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: {