diff --git a/.github/ci.yml b/.github/workflows/ci.yml similarity index 100% rename from .github/ci.yml rename to .github/workflows/ci.yml diff --git a/snippets/numbers/active-numbers/get/snippet.js b/snippets/numbers/active-numbers/get/snippet.js new file mode 100644 index 0000000..9dd6da3 --- /dev/null +++ b/snippets/numbers/active-numbers/get/snippet.js @@ -0,0 +1,17 @@ +// eslint-disable-next-line no-unused-vars +import { Numbers, NumbersService } from '@sinch/sdk-core'; + +/** @param {NumbersService} numbersService */ +export const execute = async (numbersService) => { + + const phoneNumber = 'YOUR_rented_phoneNumber'; + + /** @type {Numbers.GetActiveNumberRequestData} */ + const requestData = { + phoneNumber, + }; + + const response = await numbersService.activeNumber.get(requestData); + + console.log(`Rented number details:\n${JSON.stringify(response, null, 2)}`); +}; diff --git a/snippets/numbers/active-numbers/list-auto/snippet.js b/snippets/numbers/active-numbers/list-auto/snippet.js new file mode 100644 index 0000000..3ad03f2 --- /dev/null +++ b/snippets/numbers/active-numbers/list-auto/snippet.js @@ -0,0 +1,19 @@ +// eslint-disable-next-line no-unused-vars +import { Numbers, NumbersService } from '@sinch/sdk-core'; + +/** @param {NumbersService} numbersService */ +export const execute = async (numbersService) => { + + /** @type Numbers.ListActiveNumbersRequestData */ + const requestData = { + regionCode: 'US', + type: 'LOCAL', + }; + + console.log('List of numbers printed one by one:'); + // Use the iterator and fetch data from all the pages automatically + for await (const rentedNumber of numbersService.activeNumber.list(requestData)) { + console.log(JSON.stringify(rentedNumber, null, 2)); + } + +}; diff --git a/snippets/numbers/active-numbers/list/snippet.js b/snippets/numbers/active-numbers/list/snippet.js new file mode 100644 index 0000000..cd58782 --- /dev/null +++ b/snippets/numbers/active-numbers/list/snippet.js @@ -0,0 +1,26 @@ +// eslint-disable-next-line no-unused-vars +import { Numbers, NumbersService } from '@sinch/sdk-core'; + +/** @param {NumbersService} numbersService */ +export const execute = async (numbersService) => { + + /** @type Numbers.ListActiveNumbersRequestData */ + const requestData = { + regionCode: 'US', + type: 'LOCAL', + }; + + /** @type {Numbers.ActiveNumber[]} */ + const activeNumbersList = []; + // Fetch a page of Numbers + let response = await numbersService.activeNumber.list(requestData); + // Fetch the data page by page manually + while (response.hasNextPage) { + activeNumbersList.push(...response.data); + response = await response.nextPage(); + } + activeNumbersList.push(...response.data); + + console.log(`Full list of numbers printed at once (length = ${activeNumbersList.length}):\n${JSON.stringify(activeNumbersList, null, 2)}`); + +}; diff --git a/snippets/numbers/active-numbers/release/snippet.js b/snippets/numbers/active-numbers/release/snippet.js new file mode 100644 index 0000000..935db91 --- /dev/null +++ b/snippets/numbers/active-numbers/release/snippet.js @@ -0,0 +1,17 @@ +// eslint-disable-next-line no-unused-vars +import { Numbers, NumbersService } from '@sinch/sdk-core'; + +/** @param {NumbersService} numbersService */ +export const execute = async (numbersService) => { + + const phoneNumber = 'YOUR_phone_number_to_be_released'; + + /** @type {Numbers.ReleaseNumberRequestData} */ + const requestData = { + phoneNumber, + }; + + const response = await numbersService.activeNumber.release(requestData); + + console.log(`Released number:\n${JSON.stringify(response, null, 2)}`); +}; diff --git a/snippets/numbers/active-numbers/update/snippet.js b/snippets/numbers/active-numbers/update/snippet.js new file mode 100644 index 0000000..5bbc842 --- /dev/null +++ b/snippets/numbers/active-numbers/update/snippet.js @@ -0,0 +1,29 @@ +// eslint-disable-next-line no-unused-vars +import { Numbers, NumbersService } from '@sinch/sdk-core'; + +/** @param {NumbersService} numbersService */ +export const execute = async (numbersService) => { + + const phoneNumber = 'YOUR_phone_number_to_be_updated'; + const appId = 'YOUR_app_id'; + const displayName = 'Updated from Sinch Node.js SDK'; + + /** @type {Numbers.VoiceConfiguration} */ + const voiceConfiguration= { + appId, + type: 'RTC', + }; + + /** @type {Numbers.UpdateActiveNumberRequestData} */ + const requestData = { + phoneNumber, + updateActiveNumberRequestBody: { + displayName, + voiceConfiguration, + }, + }; + + const response = await numbersService.activeNumber.update(requestData); + + console.log(`Updated number:\n${JSON.stringify(response, null, 2)}`); +}; diff --git a/snippets/numbers/available-numbers/check-availability/snippet.js b/snippets/numbers/available-numbers/check-availability/snippet.js new file mode 100644 index 0000000..41462d9 --- /dev/null +++ b/snippets/numbers/available-numbers/check-availability/snippet.js @@ -0,0 +1,21 @@ +// eslint-disable-next-line no-unused-vars +import { Numbers, NumbersService } from '@sinch/sdk-core'; + +/** @param {NumbersService} numbersService */ +export const execute = async (numbersService) => { + + const phoneNumber = 'a_phone_number'; + + /** @type {Numbers.GetAvailableNumberRequestData} */ + const requestData = { + phoneNumber, + }; + + try { + const response = await numbersService.availableNumber.checkAvailability(requestData); + console.log(`The phone number is available:\n${JSON.stringify(response, null, 2)}`); + } catch (error) { + console.error(`ERROR: the phone number ${requestData.phoneNumber} is not available`); + } + +}; diff --git a/snippets/numbers/available-numbers/rent-any/snippet.js b/snippets/numbers/available-numbers/rent-any/snippet.js new file mode 100644 index 0000000..3ef7ebd --- /dev/null +++ b/snippets/numbers/available-numbers/rent-any/snippet.js @@ -0,0 +1,40 @@ +// eslint-disable-next-line no-unused-vars +import { Numbers, NumbersService } from '@sinch/sdk-core'; + +/** @param {NumbersService} numbersService */ +export const execute = async (numbersService) => { + + const servicePlanId = 'YOUR_service_plan_id'; + const appId = 'YOUR_app_id'; + const callbackUrl = 'YOUR_callback_url'; + + /** @type {Numbers.RentAnyNumberRequestSmsConfiguration} */ + const smsConfiguration = { + servicePlanId, + }; + + /** @type {Numbers.RentAnyNumberRequestVoiceConfiguration} */ + const voiceConfiguration = { + appId, + }; + + /** @type {Numbers.RentAnyNumberRequestData} */ + const requestData = { + rentAnyNumberRequestBody: { + regionCode: 'US', + type: 'LOCAL', + numberPattern: { + pattern: '+1781', + searchPattern: 'START', + }, + smsConfiguration, + voiceConfiguration, + callbackUrl, + }, + }; + + const response = await numbersService.availableNumber.rentAny(requestData); + + console.log(`Rented number:\n${JSON.stringify(response, null, 2)}`); + +}; diff --git a/snippets/numbers/available-numbers/rent/snippet.js b/snippets/numbers/available-numbers/rent/snippet.js new file mode 100644 index 0000000..ef6eaf1 --- /dev/null +++ b/snippets/numbers/available-numbers/rent/snippet.js @@ -0,0 +1,25 @@ +// eslint-disable-next-line no-unused-vars +import { Numbers, NumbersService } from '@sinch/sdk-core'; + +/** @param {NumbersService} numbersService */ +export const execute = async (numbersService) => { + + // Available numbers list can be retrieved by using list() function from available service, see: + // https://developers.sinch.com/docs/numbers/getting-started/node-sdk/searchavailable/ + const phoneNumber = 'available_phone_number_to_be_rented'; + const servicePlanId = 'YOUR_service_plan_id'; + + /** @type {Numbers.RentNumberRequestData} */ + const requestData = { + phoneNumber, + rentNumberRequestBody: { + smsConfiguration: { + servicePlanId, + }, + }, + }; + + const response = await numbersService.availableNumber.rent(requestData); + + console.log(`Rented number:\n${JSON.stringify(response, null, 2)}`); +}; diff --git a/snippets/numbers/available-numbers/search-for-available-numbers/snippet.js b/snippets/numbers/available-numbers/search-for-available-numbers/snippet.js new file mode 100644 index 0000000..53bccc0 --- /dev/null +++ b/snippets/numbers/available-numbers/search-for-available-numbers/snippet.js @@ -0,0 +1,17 @@ +// eslint-disable-next-line no-unused-vars +import { Numbers, NumbersService } from '@sinch/sdk-core'; + +/** @param {NumbersService} numbersService */ +export const execute = async (numbersService) => { + + /** @type {Numbers.ListAvailableNumbersRequestData} */ + const requestData = { + regionCode: 'US', + type: 'LOCAL', + capabilities: ['SMS', 'VOICE'], + }; + + const response = await numbersService.availableNumber.list(requestData); + + console.log(`Available numbers to rent:\n${JSON.stringify(response, null, 2)}`); +}; diff --git a/snippets/numbers/available-regions/snippet.js b/snippets/numbers/available-regions/snippet.js new file mode 100644 index 0000000..6bf9329 --- /dev/null +++ b/snippets/numbers/available-regions/snippet.js @@ -0,0 +1,15 @@ +// eslint-disable-next-line no-unused-vars +import { Numbers, NumbersService } from '@sinch/sdk-core'; + +/** @param {NumbersService} numbersService */ +export const execute = async (numbersService) => { + + /** @type {Numbers.ListAvailableRegionsRequestData} */ + const requestData = { + types: ['LOCAL', 'MOBILE'], + }; + + const response = await numbersService.availableRegions.list(requestData); + + console.log(`Available regions:\n${JSON.stringify(response, null, 2)}`); +}; diff --git a/snippets/numbers/callback-configuration/get/snippet.js b/snippets/numbers/callback-configuration/get/snippet.js new file mode 100644 index 0000000..fc03424 --- /dev/null +++ b/snippets/numbers/callback-configuration/get/snippet.js @@ -0,0 +1,10 @@ +// eslint-disable-next-line no-unused-vars +import { Numbers, NumbersService } from '@sinch/sdk-core'; + +/** @param {NumbersService} numbersService */ +export const execute = async (numbersService) => { + + const response = await numbersService.callbacks.get({}); + + console.log(`Callback configuration:\n${JSON.stringify(response, null, 2)}`); +}; diff --git a/snippets/numbers/callback-configuration/update/snippet.js b/snippets/numbers/callback-configuration/update/snippet.js new file mode 100644 index 0000000..8b9c918 --- /dev/null +++ b/snippets/numbers/callback-configuration/update/snippet.js @@ -0,0 +1,19 @@ +// eslint-disable-next-line no-unused-vars +import { Numbers, NumbersService } from '@sinch/sdk-core'; + +/** @param {NumbersService} numbersService */ +export const execute = async (numbersService) => { + + const hmacSecret = 'New_HMAC_secret'; + + /** @type {Numbers.UpdateCallbackConfigurationRequestData} */ + const requestData = { + updateCallbackConfigurationRequestBody: { + hmacSecret, + }, + }; + + const response = await numbersService.callbacks.update(requestData); + + console.log(`Updated callback configuration:\n${JSON.stringify(response, null, 2)}`); +}; diff --git a/snippets/package-lock.json b/snippets/package-lock.json new file mode 100644 index 0000000..6899799 --- /dev/null +++ b/snippets/package-lock.json @@ -0,0 +1,188 @@ +{ + "name": "@sinch/code-snippets", + "version": "0.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "@sinch/code-snippets", + "version": "0.0.0", + "dependencies": { + "@sinch/sdk-core": "^1.1.0" + } + }, + "node_modules/@sinch/conversation": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@sinch/conversation/-/conversation-1.1.0.tgz", + "integrity": "sha512-8KxUnzO+a8fPmhSmpRX9zGfgF3Hvgg4ZQNF9CNVDVRckcE7p+mWENdWts7GXWSEKMONZIOXwYnosAeENMsZVow==", + "dependencies": { + "@sinch/sdk-client": "^1.1.0" + } + }, + "node_modules/@sinch/elastic-sip-trunking": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@sinch/elastic-sip-trunking/-/elastic-sip-trunking-1.1.0.tgz", + "integrity": "sha512-1E635dxPFnCfS1e01WGSY2xcLGUsAngcghcsodFFMTXxmAL+2cxhFdmrodmBdNmCVpfPLkMSIdQC/t+1p+awNA==", + "dependencies": { + "@sinch/sdk-client": "^1.0.0" + } + }, + "node_modules/@sinch/fax": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@sinch/fax/-/fax-1.1.0.tgz", + "integrity": "sha512-89NS1zMg07QAjj6Fr93moVjkfZSkVwYwegZfZ2LEo7SEuFXp9CahL5UoHXzipTNbtCxcouGUgiJkN0fxJBN/VQ==", + "dependencies": { + "@sinch/sdk-client": "^1.1.0" + } + }, + "node_modules/@sinch/numbers": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@sinch/numbers/-/numbers-1.1.0.tgz", + "integrity": "sha512-uEtTDTPabY7f2CU1X/rpuBqWbDutqcHA34vaaJ1HbGWhdK406YfUKxBha60/kTAO5df+eDjVxg2SYiVNRpJNLw==", + "dependencies": { + "@sinch/sdk-client": "^1.1.0" + } + }, + "node_modules/@sinch/sdk-client": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@sinch/sdk-client/-/sdk-client-1.1.0.tgz", + "integrity": "sha512-YiF8LpZ8RdWFdjyA1mlySyuNfVQPA1EV8gSecrvBUpwO8LyFhvbZF1OsMfaqVJiUr4mA/UArbbO6qSzwA2XgCQ==", + "dependencies": { + "form-data": "^4.0.0", + "node-fetch": "2.7.0" + } + }, + "node_modules/@sinch/sdk-core": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@sinch/sdk-core/-/sdk-core-1.1.0.tgz", + "integrity": "sha512-kqZ0n0ycClYPPSk5ugy9FFmq/j/qVXmhC8rgUBu2JWTjsOTsRVe9dSnUuQYaxj6V8sEjySUALtLiJBU3neeq8A==", + "dependencies": { + "@sinch/conversation": "^1.1.0", + "@sinch/elastic-sip-trunking": "^1.1.0", + "@sinch/fax": "^1.1.0", + "@sinch/numbers": "^1.1.0", + "@sinch/sms": "^1.1.0", + "@sinch/verification": "^1.1.0", + "@sinch/voice": "^1.1.0" + } + }, + "node_modules/@sinch/sms": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@sinch/sms/-/sms-1.1.0.tgz", + "integrity": "sha512-6QXpLujzcl5jTvYFmB+UebVWYGXEHaRBsmE1vG7GAwIAOrCxdpusvSWitHeigCUz9CxrzdjC+3JmlS7q7rbONA==", + "dependencies": { + "@sinch/sdk-client": "^1.1.0" + } + }, + "node_modules/@sinch/verification": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@sinch/verification/-/verification-1.1.0.tgz", + "integrity": "sha512-UcXf4dsrG0+qATCJIiCEyHwnyLknEtYSK1UKV40EGPkYNn4kVwxLRDglKOIq9txBQZ5MgpbFDTqedbf4AcREZQ==", + "dependencies": { + "@sinch/sdk-client": "^1.1.0" + } + }, + "node_modules/@sinch/voice": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@sinch/voice/-/voice-1.1.0.tgz", + "integrity": "sha512-znOVSxBHRoI7J8zZGcFUrqDHR8hyOifh+IOR1FUnel4c1hS5s9HsHfmcnd4HmUca1P/ln0c19+KxMhNFBVLTAw==", + "dependencies": { + "@sinch/sdk-client": "^1.1.0" + } + }, + "node_modules/asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" + }, + "node_modules/combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "dependencies": { + "delayed-stream": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", + "engines": { + "node": ">=0.4.0" + } + }, + "node_modules/form-data": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", + "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "dependencies": { + "mime-db": "1.52.0" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/node-fetch": { + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz", + "integrity": "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==", + "dependencies": { + "whatwg-url": "^5.0.0" + }, + "engines": { + "node": "4.x || >=6.0.0" + }, + "peerDependencies": { + "encoding": "^0.1.0" + }, + "peerDependenciesMeta": { + "encoding": { + "optional": true + } + } + }, + "node_modules/tr46": { + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", + "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==" + }, + "node_modules/webidl-conversions": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", + "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==" + }, + "node_modules/whatwg-url": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz", + "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==", + "dependencies": { + "tr46": "~0.0.3", + "webidl-conversions": "^3.0.0" + } + } + } +} diff --git a/snippets/package.json b/snippets/package.json new file mode 100644 index 0000000..cb703ba --- /dev/null +++ b/snippets/package.json @@ -0,0 +1,10 @@ +{ + "name": "@sinch/code-snippets", + "version": "1.0.0", + "description": "Code snippets related to the Sinch Node.js SDK usage", + "author": "Sinch", + "type": "module", + "dependencies": { + "@sinch/sdk-core": "^1.1.0" + } +}