-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DEVEXP-406: Add support for SIP Trunks (#76)
- Loading branch information
1 parent
4226f20
commit 28f5668
Showing
26 changed files
with
1,024 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
examples/simple-examples/src/elastic-sip-trunking/sip-trunks/addACL.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.sipTrunks.addAccessControlList(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); | ||
} | ||
|
||
})(); |
27 changes: 27 additions & 0 deletions
27
examples/simple-examples/src/elastic-sip-trunking/sip-trunks/create.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { ElasticSipTrunking } from '@sinch/sdk-core'; | ||
import { getPrintFormat, initElasticSipTrunkingService, printFullResponse } from '../../config'; | ||
|
||
(async () => { | ||
console.log('******************'); | ||
console.log('* createSipTrunk *'); | ||
console.log('******************'); | ||
|
||
const requestData: ElasticSipTrunking.CreateSipTrunkRequestData = { | ||
createSipTrunkRequestBody: { | ||
name: 'Node.js SDK Sinch Trunk', | ||
hostName: 'node-js-sdk-sinch', | ||
}, | ||
}; | ||
|
||
const elasticSipTrunkingService = initElasticSipTrunkingService(); | ||
const response = await elasticSipTrunkingService.sipTrunks.create(requestData); | ||
|
||
const printFormat = getPrintFormat(process.argv); | ||
|
||
if (printFormat === 'pretty') { | ||
console.log(`New SIP trunk created with the id '${response.id}'`); | ||
} else { | ||
printFullResponse(response); | ||
} | ||
|
||
})(); |
20 changes: 20 additions & 0 deletions
20
examples/simple-examples/src/elastic-sip-trunking/sip-trunks/delete.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { ElasticSipTrunking } from '@sinch/sdk-core'; | ||
import { getSipTrunkIdFromConfig, initElasticSipTrunkingService } from '../../config'; | ||
|
||
(async () => { | ||
console.log('******************'); | ||
console.log('* deleteSipTrunk *'); | ||
console.log('******************'); | ||
|
||
const sipTrunkId = getSipTrunkIdFromConfig(); | ||
|
||
const requestData: ElasticSipTrunking.DeleteSipTrunkRequestData = { | ||
sipTrunkId, | ||
}; | ||
|
||
const elasticSipTrunkingService = initElasticSipTrunkingService(); | ||
await elasticSipTrunkingService.sipTrunks.delete(requestData); | ||
|
||
console.log(`The SIP trunk with the id '${requestData.sipTrunkId}' has been deleted.`); | ||
|
||
})(); |
26 changes: 26 additions & 0 deletions
26
examples/simple-examples/src/elastic-sip-trunking/sip-trunks/deleteACL.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.sipTrunks.deleteAccessControlList(requestData); | ||
|
||
console.log(`The ACL '${requestData.accessControlListId}' has been removed fromm the SIP trunk '${requestData.trunkId}'`); | ||
|
||
})(); |
31 changes: 31 additions & 0 deletions
31
examples/simple-examples/src/elastic-sip-trunking/sip-trunks/get.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { ElasticSipTrunking } from '@sinch/sdk-core'; | ||
import { | ||
getPrintFormat, | ||
getSipTrunkIdFromConfig, | ||
initElasticSipTrunkingService, | ||
printFullResponse, | ||
} from '../../config'; | ||
|
||
(async () => { | ||
console.log('*******************'); | ||
console.log('* getSipTrunkById *'); | ||
console.log('*******************'); | ||
|
||
const sipTrunkId = getSipTrunkIdFromConfig(); | ||
|
||
const requestData: ElasticSipTrunking.GetSipTrunkRequestData = { | ||
sipTrunkId, | ||
}; | ||
|
||
const elasticSipTrunkingService = initElasticSipTrunkingService(); | ||
const response = await elasticSipTrunkingService.sipTrunks.get(requestData); | ||
|
||
const printFormat = getPrintFormat(process.argv); | ||
|
||
if (printFormat === 'pretty') { | ||
console.log(`The SIP trunk with the id '${response.id}' is named '${response.name}' and has been created at '${response.createTime?.toISOString()}'`); | ||
} else { | ||
printFullResponse(response); | ||
} | ||
|
||
})(); |
64 changes: 64 additions & 0 deletions
64
examples/simple-examples/src/elastic-sip-trunking/sip-trunks/list.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { ElasticSipTrunking, PageResult } from '@sinch/sdk-core'; | ||
import { getPrintFormat, initElasticSipTrunkingService, printFullResponse } from '../../config'; | ||
|
||
const populateSipTrunksList = ( | ||
sipTrunkPage: PageResult<ElasticSipTrunking.SipTrunk>, | ||
sipTrunksList: ElasticSipTrunking.SipTrunk[], | ||
sipTrunksDetailsList: string[], | ||
) => { | ||
sipTrunkPage.data.map((sipTrunk: ElasticSipTrunking.SipTrunk) => { | ||
sipTrunksList.push(sipTrunk); | ||
sipTrunksDetailsList.push(`${sipTrunk.id} - ${sipTrunk.name}`); | ||
}); | ||
}; | ||
|
||
(async () => { | ||
console.log('****************'); | ||
console.log('* getSipTrunks *'); | ||
console.log('****************'); | ||
|
||
const requestData: ElasticSipTrunking.ListSipTrunksRequestData = {}; | ||
|
||
const elasticSipTrunkingService = initElasticSipTrunkingService(); | ||
|
||
// ---------------------------------------------- | ||
// Method 1: Fetch the data page by page manually | ||
// ---------------------------------------------- | ||
let response = await elasticSipTrunkingService.sipTrunks.list(requestData); | ||
|
||
const sipTrunksList: ElasticSipTrunking.SipTrunk[] = []; | ||
const sipTrunksDetailsList: string[] = []; | ||
|
||
// Loop on all the pages to get all the active numbers | ||
let reachedEndOfPages = false; | ||
while (!reachedEndOfPages) { | ||
populateSipTrunksList(response, sipTrunksList, sipTrunksDetailsList); | ||
if (response.hasNextPage) { | ||
response = await response.nextPage(); | ||
} else { | ||
reachedEndOfPages = true; | ||
} | ||
} | ||
|
||
const printFormat = getPrintFormat(process.argv); | ||
|
||
if (printFormat === 'pretty') { | ||
console.log(sipTrunksDetailsList.length > 0 | ||
? 'List of SIP trunks:\n' + sipTrunksDetailsList.join('\n') | ||
: 'Sorry, no SIP trunks were found.'); | ||
} else { | ||
printFullResponse(sipTrunksList); | ||
} | ||
|
||
// --------------------------------------------------------------------- | ||
// Method 2: Use the iterator and fetch data on more pages automatically | ||
// --------------------------------------------------------------------- | ||
for await (const sipTrunk of elasticSipTrunkingService.sipTrunks.list(requestData)) { | ||
if (printFormat === 'pretty') { | ||
console.log(`${sipTrunk.id} - ${sipTrunk.name}`); | ||
} else { | ||
console.log(sipTrunk); | ||
} | ||
} | ||
|
||
})(); |
44 changes: 44 additions & 0 deletions
44
examples/simple-examples/src/elastic-sip-trunking/sip-trunks/listACLs.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { ElasticSipTrunking } from '@sinch/sdk-core'; | ||
import { getSipTrunkIdFromConfig, initElasticSipTrunkingService, printFullResponse } from '../../config'; | ||
|
||
(async () => { | ||
console.log('*********************************'); | ||
console.log('* getAccessControlListsForTrunk *'); | ||
console.log('*********************************'); | ||
|
||
const sipTrunkId = getSipTrunkIdFromConfig(); | ||
|
||
const requestData: ElasticSipTrunking.ListAccessControlListsForTrunkRequestData = { | ||
trunkId: sipTrunkId, | ||
}; | ||
|
||
const elasticSipTrunkingService = initElasticSipTrunkingService(); | ||
|
||
// ---------------------------------------------- | ||
// Method 1: Fetch the data page by page manually | ||
// ---------------------------------------------- | ||
let response = await elasticSipTrunkingService.sipTrunks.listAccessControlLists(requestData); | ||
|
||
const aclList: string[] = []; | ||
|
||
// Loop on all the pages to get all the active numbers | ||
let reachedEndOfPages = false; | ||
while (!reachedEndOfPages) { | ||
aclList.push(...response.data); | ||
if (response.hasNextPage) { | ||
response = await response.nextPage(); | ||
} else { | ||
reachedEndOfPages = true; | ||
} | ||
} | ||
|
||
printFullResponse(aclList); | ||
|
||
// --------------------------------------------------------------------- | ||
// Method 2: Use the iterator and fetch data on more pages automatically | ||
// --------------------------------------------------------------------- | ||
for await (const acl of elasticSipTrunkingService.sipTrunks.listAccessControlLists(requestData)) { | ||
console.log(acl); | ||
} | ||
|
||
})(); |
35 changes: 35 additions & 0 deletions
35
examples/simple-examples/src/elastic-sip-trunking/sip-trunks/update.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { ElasticSipTrunking } from '@sinch/sdk-core'; | ||
import { | ||
getPrintFormat, | ||
getSipTrunkIdFromConfig, | ||
initElasticSipTrunkingService, | ||
printFullResponse, | ||
} from '../../config'; | ||
|
||
(async () => { | ||
console.log('******************'); | ||
console.log('* updateSipTrunk *'); | ||
console.log('******************'); | ||
|
||
const sipTrunkId = getSipTrunkIdFromConfig(); | ||
|
||
const requestData: ElasticSipTrunking.UpdateSipTrunkRequestData = { | ||
sipTrunkId, | ||
updateSipTrunkRequestBody: { | ||
name: 'Node.js SDK Sinch Trunk Reloaded', | ||
hostName: 'node-js-sdk-sinch-reloaded', | ||
}, | ||
}; | ||
|
||
const elasticSipTrunkingService = initElasticSipTrunkingService(); | ||
const response = await elasticSipTrunkingService.sipTrunks.update(requestData); | ||
|
||
const printFormat = getPrintFormat(process.argv); | ||
|
||
if (printFormat === 'pretty') { | ||
console.log(`The SIP trunk with the id '${response.id}' has been updated at '${response.updateTime?.toISOString()}'. Its new name is '${response.name}'`); | ||
} else { | ||
printFullResponse(response); | ||
} | ||
|
||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * as ElasticSipTrunking from './models'; | ||
export * from './rest'; | ||
export * from '@sinch/sdk-client'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './v1'; |
6 changes: 6 additions & 0 deletions
6
...unking/src/models/v1/add-access-control-list-to-trunk/add-access-control-list-to-trunk.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
export interface AddAccessControlListToTrunk { | ||
|
||
/** Array of AccessControlList ids */ | ||
accessControlListIds?: string[]; | ||
} |
1 change: 1 addition & 0 deletions
1
packages/elastic-sip-trunking/src/models/v1/add-access-control-list-to-trunk/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export type { AddAccessControlListToTrunk } from './add-access-control-list-to-trunk'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export * from './add-access-control-list-to-trunk'; | ||
export * from './sip-trunk'; | ||
|
||
export * from './requests'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './sip-trunks/sip-trunks-request-data'; |
Oops, something went wrong.