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

Merge EST related code - part 2 #90

Merged
46 changes: 34 additions & 12 deletions examples/simple-examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,10 @@ FAX_ID=id from a sendFax response
FAX_CALLBACK_URL=callback url to override the one defined in the default service or specified service
FAX_EMAIL=email to associate with a phone number to use the fax-to-email functionality
## Elastic SIP Trunking API
SIP_TRUNK_ID=sipTrunkId to fill with one of the SIP trunk created with the Elastic SIP Trunking API
ACL_ID=accessControlList Id to fill with one of the access control list created with the Elastic SIP Trunking API
SIP_TRUNK_ID=sipTrunkId to fill with one of the SIP trunks created with the Elastic SIP Trunking API
SIP_ENDPOINT_ID=sipEndpointId to fill with one of the SIP endpoints created with the Elastic SIP Trunking API
ACL_ID=accessControlListId to fill with one of the access control lists created with the Elastic SIP Trunking API
IP_RANGE_ID=ipRangeId to fill with one of the IP ranges added to an ACL with the Elastic SIP Trunking API
```

**Note**: If you prefer using environment variables, the sample app is also supporting them: they take precedence over the value from the `.env` file.
Expand Down Expand Up @@ -275,13 +277,33 @@ yarn run numbers:regions:list

### Elastic SIP Trunk

| Service | Sample application name and location | Required parameters |
|------------|----------------------------------------------------------------------------------------------------------|----------------------|
| SIP Trunks | [./src/elastic-sip-trunking/sip-trunks/create.ts](./src/elastic-sip-trunking/sip-trunks/create.ts) | |
| | [./src/elastic-sip-trunking/sip-trunks/get.ts](./src/elastic-sip-trunking/sip-trunks/get.ts) | SIP_TRUNK_ID |
| | [./src/elastic-sip-trunking/sip-trunks/list.ts](./src/elastic-sip-trunking/sip-trunks/list.ts) | |
| | [./src/elastic-sip-trunking/sip-trunks/update.ts](./src/elastic-sip-trunking/sip-trunks/update.ts) | SIP_TRUNK_ID |
| | [./src/elastic-sip-trunking/sip-trunks/delete.ts](./src/elastic-sip-trunking/sip-trunks/delete.ts) | SIP_TRUNK_ID |
| | [./src/elastic-sip-trunking/sip-trunks/addACL.ts](./src/elastic-sip-trunking/sip-trunks/addACL.ts) | SIP_TRUNK_ID, ACL_ID |
| | [./src/elastic-sip-trunking/sip-trunks/listACLs.ts](./src/elastic-sip-trunking/sip-trunks/listACLs.ts) | SIP_TRUNK_ID |
| | [./src/elastic-sip-trunking/sip-trunks/deleteACL.ts](./src/elastic-sip-trunking/sip-trunks/deleteACL.ts) | SIP_TRUNK_ID, ACL_ID |
| Service | Sample application name and location | Required parameters |
|---------------------|----------------------------------------------------------------------------------------------------------------------------------------|-------------------------------|
| SIP Trunks | [./src/elastic-sip-trunking/sip-trunks/create.ts](./src/elastic-sip-trunking/sip-trunks/create.ts) | |
| | [./src/elastic-sip-trunking/sip-trunks/get.ts](./src/elastic-sip-trunking/sip-trunks/get.ts) | SIP_TRUNK_ID |
| | [./src/elastic-sip-trunking/sip-trunks/list.ts](./src/elastic-sip-trunking/sip-trunks/list.ts) | |
| | [./src/elastic-sip-trunking/sip-trunks/update.ts](./src/elastic-sip-trunking/sip-trunks/update.ts) | SIP_TRUNK_ID |
| | [./src/elastic-sip-trunking/sip-trunks/delete.ts](./src/elastic-sip-trunking/sip-trunks/delete.ts) | SIP_TRUNK_ID |
| | [./src/elastic-sip-trunking/sip-trunks/addACL.ts](./src/elastic-sip-trunking/sip-trunks/addACL.ts) | SIP_TRUNK_ID, ACL_ID |
| | [./src/elastic-sip-trunking/sip-trunks/listACLs.ts](./src/elastic-sip-trunking/sip-trunks/listACLs.ts) | SIP_TRUNK_ID |
| | [./src/elastic-sip-trunking/sip-trunks/deleteACL.ts](./src/elastic-sip-trunking/sip-trunks/deleteACL.ts) | SIP_TRUNK_ID, ACL_ID |
| SIP Endpoints | [./src/elastic-sip-trunking/sip-endpoints/create.ts](./src/elastic-sip-trunking/sip-endpoints/create.ts) | |
| | [./src/elastic-sip-trunking/sip-endpoints/get.ts](./src/elastic-sip-trunking/sip-endpoints/get.ts) | SIP_TRUNK_ID, SIP_ENDPOINT_ID |
| | [./src/elastic-sip-trunking/sip-endpoints/list.ts](./src/elastic-sip-trunking/sip-endpoints/list.ts) | |
| | [./src/elastic-sip-trunking/sip-endpoints/update.ts](./src/elastic-sip-trunking/sip-endpoints/update.ts) | SIP_TRUNK_ID, SIP_ENDPOINT_ID |
| | [./src/elastic-sip-trunking/sip-endpoints/delete.ts](./src/elastic-sip-trunking/sip-endpoints/delete.ts) | SIP_TRUNK_ID, SIP_ENDPOINT_ID |
| Access Control List | [./src/elastic-sip-trunking/access-control-list/create.ts](./src/elastic-sip-trunking/access-control-list/create.ts) | |
| | [./src/elastic-sip-trunking/access-control-list/list.ts](./src/elastic-sip-trunking/access-control-list/list.ts) | |
| | [./src/elastic-sip-trunking/access-control-list/update.ts](./src/elastic-sip-trunking/access-control-list/update.ts) | ACL_ID |
| | [./src/elastic-sip-trunking/access-control-list/delete.ts](./src/elastic-sip-trunking/access-control-list/delete.ts) | ACL_ID |
| | [./src/elastic-sip-trunking/access-control-list/addIpRange.ts](./src/elastic-sip-trunking/access-control-list/addIpRange.ts) | ACL_ID |
| | [./src/elastic-sip-trunking/access-control-list/listIpRanges.ts](./src/elastic-sip-trunking/access-control-list/listIpRanges.ts) | ACL_ID |
| | [./src/elastic-sip-trunking/access-control-list/updateIpRange.ts](./src/elastic-sip-trunking/access-control-list/updateIpRange.ts) | ACL_ID, IP_RANGE_ID |
| | [./src/elastic-sip-trunking/access-control-list/deleteIpRange.ts](./src/elastic-sip-trunking/access-control-list/deleteIpRange.ts) | ACL_ID, IP_RANGE_ID |
| | [./src/elastic-sip-trunking/access-control-list/addToTrunk.ts](./src/elastic-sip-trunking/access-control-list/addToTrunk.ts) | SIP_TRUNK_ID, ACL_ID |
| | [./src/elastic-sip-trunking/access-control-list/listForTrunk.ts](./src/elastic-sip-trunking/access-control-list/listForTrunk.ts) | SIP_TRUNK_ID |
| | [./src/elastic-sip-trunking/access-control-list/deleteFromTrunk.ts](./src/elastic-sip-trunking/access-control-list/deleteFromTrunk.ts) | SIP_TRUNK_ID, ACL_ID |
| Country Permissions | [./src/elastic-sip-trunking/country-permissions/get.ts](./src/elastic-sip-trunking/country-permissions/get.ts) | |
| | [./src/elastic-sip-trunking/country-permissions/list.ts](./src/elastic-sip-trunking/country-permissions/list.ts) | |
| | [./src/elastic-sip-trunking/country-permissions/update.ts](./src/elastic-sip-trunking/country-permissions/update.ts) | |
| Calls | [./src/elastic-sip-trunking/calls-history/find.ts](./src/elastic-sip-trunking/calls-history/find.ts) | SIP_TRUNK_ID |
20 changes: 20 additions & 0 deletions examples/simple-examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,26 @@
"elasticSipTrunks:sipTrunk:addACL": "ts-node src/elastic-sip-trunking/sip-trunks/addACL.ts",
"elasticSipTrunks:sipTrunk:listACLs": "ts-node src/elastic-sip-trunking/sip-trunks/listACLs.ts",
"elasticSipTrunks:sipTrunk:deleteACL": "ts-node src/elastic-sip-trunking/sip-trunks/deleteACL.ts",
"elasticSipTrunks:sipEndpoint:create": "ts-node src/elastic-sip-trunking/sip-endpoints/create.ts",
"elasticSipTrunks:sipEndpoint:get": "ts-node src/elastic-sip-trunking/sip-endpoints/get.ts",
"elasticSipTrunks:sipEndpoint:list": "ts-node src/elastic-sip-trunking/sip-endpoints/list.ts",
"elasticSipTrunks:sipEndpoint:update": "ts-node src/elastic-sip-trunking/sip-endpoints/update.ts",
"elasticSipTrunks:sipEndpoint:delete": "ts-node src/elastic-sip-trunking/sip-endpoints/delete.ts",
"elasticSipTrunks:accessControlList:create": "ts-node src/elastic-sip-trunking/access-control-list/create.ts",
"elasticSipTrunks:accessControlList:list": "ts-node src/elastic-sip-trunking/access-control-list/list.ts",
"elasticSipTrunks:accessControlList:update": "ts-node src/elastic-sip-trunking/access-control-list/update.ts",
"elasticSipTrunks:accessControlList:delete": "ts-node src/elastic-sip-trunking/access-control-list/delete.ts",
"elasticSipTrunks:accessControlList:addIpRange": "ts-node src/elastic-sip-trunking/access-control-list/addIpRange.ts",
"elasticSipTrunks:accessControlList:listIpRanges": "ts-node src/elastic-sip-trunking/access-control-list/listIpRanges.ts",
"elasticSipTrunks:accessControlList:updateIpRange": "ts-node src/elastic-sip-trunking/access-control-list/updateIpRange.ts",
"elasticSipTrunks:accessControlList:deleteIpRange": "ts-node src/elastic-sip-trunking/access-control-list/deleteIpRange.ts",
"elasticSipTrunks:accessControlList:addToTrunk": "ts-node src/elastic-sip-trunking/access-control-list/addToTrunk.ts",
"elasticSipTrunks:accessControlList:listForTrunk": "ts-node src/elastic-sip-trunking/access-control-list/listForTrunk.ts",
"elasticSipTrunks:accessControlList:deleteFromTrunk": "ts-node src/elastic-sip-trunking/access-control-list/deleteFromTrunk.ts",
"elasticSipTrunks:countryPermissions:get": "ts-node src/elastic-sip-trunking/country-permissions/get.ts",
"elasticSipTrunks:countryPermissions:list": "ts-node src/elastic-sip-trunking/country-permissions/list.ts",
"elasticSipTrunks:countryPermissions:update": "ts-node src/elastic-sip-trunking/country-permissions/update.ts",
"elasticSipTrunks:calls:find": "ts-node src/elastic-sip-trunking/calls-history/find.ts",
"fax:services:create": "ts-node src/fax/services/create.ts",
"fax:services:get": "ts-node src/fax/services/get.ts",
"fax:services:list": "ts-node src/fax/services/list.ts",
Expand Down
8 changes: 8 additions & 0 deletions examples/simple-examples/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,18 @@ export const getSipTrunkIdFromConfig = () => {
return readVariable('SIP_TRUNK_ID');
};

export const getSipEndpointIdFromConfig = () => {
return readVariable('SIP_ENDPOINT_ID');
};

export const getAccessControlListIdFromConfig = () => {
return readVariable('ACL_ID');
};

export const getIpRangeIdFromConfig = () => {
return readVariable('IP_RANGE_ID');
};

const readVariable = ( name: string): string => {
const value = process.env[name];
if (!value) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { ElasticSipTrunking } from '@sinch/sdk-core';
import {
getAccessControlListIdFromConfig,
getPrintFormat,
initElasticSipTrunkingService,
printFullResponse,
} from '../../config';

(async () => {
console.log('*******************************');
console.log('* addAccessControlListToTrunk *');
console.log('*******************************');

const aclId = getAccessControlListIdFromConfig();

const requestData: ElasticSipTrunking.AddIpRangeToAccessControlListRequestData = {
accessControlListId: aclId,
addIpRangeRequestBody: {
description: 'IP range to add with the Node.js SDK',
ipAddress: '11.12.13.14',
range: 27,
},
};

const elasticSipTrunkingService = initElasticSipTrunkingService();
const response = await elasticSipTrunkingService.accessControlList.addIpRange(requestData);

const printFormat = getPrintFormat(process.argv);

if (printFormat === 'pretty') {
console.log(`The IP range with the ID ${response.id} associated to the ACL '${response.accessControlListId}' has been created at ${response.createTime?.toISOString()}`);
} else {
printFullResponse(response);
}

})();
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { ElasticSipTrunking } from '@sinch/sdk-core';
import {
getAccessControlListIdFromConfig,
getPrintFormat,
getSipTrunkIdFromConfig,
initElasticSipTrunkingService,
printFullResponse,
} from '../../config';

(async () => {
console.log('*******************************');
console.log('* addAccessControlListToTrunk *');
console.log('*******************************');

const sipTrunkId = getSipTrunkIdFromConfig();
const aclId = getAccessControlListIdFromConfig();

const requestData: ElasticSipTrunking.AddAccessControlListToTrunkRequestData = {
trunkId: sipTrunkId,
addAccessControlListToTrunkRequestBody: {
accessControlListIds: [
aclId,
],
},
};

const elasticSipTrunkingService = initElasticSipTrunkingService();
const response = await elasticSipTrunkingService.accessControlList.addToTrunk(requestData);

const printFormat = getPrintFormat(process.argv);

if (printFormat === 'pretty') {
console.log(`The SIP trunk with the id '${requestData.trunkId}' contains the following ACL IDs:\n - ${response.accessControlListIds?.join('\n - ')}`);
} else {
printFullResponse(response);
}

})();
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { ElasticSipTrunking } from '@sinch/sdk-core';
import { getPrintFormat, initElasticSipTrunkingService, printFullResponse } from '../../config';

(async () => {
console.log('***************************');
console.log('* createAccessControlList *');
console.log('***************************');

const requestData: ElasticSipTrunking.CreateAccessControlListRequestData = {
createAccessControlListBody: {
name: 'New ACL created with the Node.js SDK',
enabled: true,
ipRanges: [
{
description: 'Location 1',
ipAddress: '15.15.15.15',
range: 20,
},
],
},
};

const elasticSipTrunkingService = initElasticSipTrunkingService();
const response = await elasticSipTrunkingService.accessControlList.create(requestData);

const printFormat = getPrintFormat(process.argv);

if (printFormat === 'pretty') {
console.log(`New access control list created with the id '${response.id}' at '${response.createTime?.toISOString()}'`);
} else {
printFullResponse(response);
}

})();
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { ElasticSipTrunking } from '@sinch/sdk-core';
import { getAccessControlListIdFromConfig, initElasticSipTrunkingService } from '../../config';

(async () => {
console.log('***************************');
console.log('* deleteAccessControlList *');
console.log('***************************');

const aclId = getAccessControlListIdFromConfig();

const requestData: ElasticSipTrunking.DeleteAccessControlListRequestData = {
id: aclId,
};

const elasticSipTrunkingService = initElasticSipTrunkingService();
await elasticSipTrunkingService.accessControlList.delete(requestData);

console.log(`The SIP trunk with the id '${requestData.id}' has been deleted.`);

})();
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { ElasticSipTrunking } from '@sinch/sdk-core';
import {
getAccessControlListIdFromConfig,
getSipTrunkIdFromConfig,
initElasticSipTrunkingService,
} from '../../config';

(async () => {
console.log('************************************');
console.log('* deleteAccessControlListFromTrunk *');
console.log('************************************');

const sipTrunkId = getSipTrunkIdFromConfig();
const aclId = getAccessControlListIdFromConfig();

const requestData: ElasticSipTrunking.DeleteAccessControlListFromTrunkRequestData = {
trunkId: sipTrunkId,
accessControlListId: aclId,
};

const elasticSipTrunkingService = initElasticSipTrunkingService();
await elasticSipTrunkingService.accessControlList.deleteFromTrunk(requestData);

console.log(`The ACL '${requestData.accessControlListId}' has been removed fromm the SIP trunk '${requestData.trunkId}'`);

})();
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { ElasticSipTrunking } from '@sinch/sdk-core';
import {
getAccessControlListIdFromConfig,
getIpRangeIdFromConfig,
initElasticSipTrunkingService,
} from '../../config';

(async () => {
console.log('**************************************');
console.log('* deleteIpRangeFromAccessControlList *');
console.log('**************************************');

const aclId = getAccessControlListIdFromConfig();
const ipRangeId = getIpRangeIdFromConfig();

const requestData: ElasticSipTrunking.DeleteIpRangeFromAccessControlListRequestData = {
accessControlListId: aclId,
ipRangeId: ipRangeId,
};

const elasticSipTrunkingService = initElasticSipTrunkingService();
await elasticSipTrunkingService.accessControlList.deleteIpRange(requestData);

console.log(`The IP range '${requestData.ipRangeId}' has been removed fromm the ACL '${requestData.accessControlListId}'`);

})();
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { ElasticSipTrunking, PageResult } from '@sinch/sdk-core';
import { getPrintFormat, initElasticSipTrunkingService, printFullResponse } from '../../config';

const populateACLsList = (
aclPage: PageResult<ElasticSipTrunking.AccessControlList>,
aclsList: ElasticSipTrunking.AccessControlList[],
aclsDetailsList: string[],
) => {
aclPage.data.map((acl: ElasticSipTrunking.AccessControlList) => {
aclsList.push(acl);
aclsDetailsList.push(`${acl.id} - ${acl.name}`);
});
};

(async () => {
console.log('************************');
console.log('* getAccessControlList *');
console.log('************************');

const requestData: ElasticSipTrunking.ListAccessControlListRequestData = {};

const elasticSipTrunkingService = initElasticSipTrunkingService();

// ----------------------------------------------
// Method 1: Fetch the data page by page manually
// ----------------------------------------------
let response = await elasticSipTrunkingService.accessControlList.list(requestData);
const aclsList: ElasticSipTrunking.AccessControlList[] = [];
const aclsDetailsList: string[] = [];

// Loop on all the pages to get all the active numbers
let reachedEndOfPages = false;
while (!reachedEndOfPages) {
populateACLsList(response, aclsList, aclsDetailsList);
if (response.hasNextPage) {
response = await response.nextPage();
} else {
reachedEndOfPages = true;
}
}

const printFormat = getPrintFormat(process.argv);

if (printFormat === 'pretty') {
console.log(aclsDetailsList.length > 0
? 'List of ACLs:\n' + aclsDetailsList.join('\n')
: 'Sorry, no ACLs were found.');
} else {
printFullResponse(aclsList);
}

// ---------------------------------------------------------------------
// Method 2: Use the iterator and fetch data on more pages automatically
// ---------------------------------------------------------------------
for await (const acl of elasticSipTrunkingService.accessControlList.list(requestData)) {
if (printFormat === 'pretty') {
console.log(`${acl.id} - ${acl.name}`);
} else {
console.log(acl);
}
}

})();
Loading
Loading