From eb46709df11df6866cb4e303d527b56b37ddaae2 Mon Sep 17 00:00:00 2001 From: Kelly J Andrews Date: Thu, 3 Sep 2020 10:08:18 -0400 Subject: [PATCH 01/12] Remove example folder --- examples/README.md | 63 --------- examples/config.js | 29 ---- examples/ex-change-api-host.js | 50 ------- examples/ex-change-rest-host.js | 14 -- examples/ex-check-balance.js | 13 -- examples/ex-check-verification.js | 16 --- examples/ex-control-verification.js | 16 --- examples/ex-create-secret.js | 13 -- examples/ex-create-update-delete-app.js | 33 ----- examples/ex-create-v1-application.js | 23 ---- examples/ex-create-v2-application.js | 49 ------- examples/ex-delete-application.js | 13 -- examples/ex-dtmf-to-call.js | 105 -------------- examples/ex-get-calls.js | 47 ------- examples/ex-get-full-pricing.js | 13 -- examples/ex-get-phone-pricing-number.js | 13 -- examples/ex-get-phone-pricing.js | 13 -- examples/ex-get-prefix-pricing.js | 13 -- examples/ex-get-pricing-number.js | 13 -- examples/ex-get-pricing.js | 13 -- examples/ex-get-secret.js | 13 -- examples/ex-get-v1-application.js | 13 -- examples/ex-get-v1-applications.js | 13 -- examples/ex-get-v2-application.js | 13 -- examples/ex-get-v2-applications.js | 13 -- examples/ex-keyfile-creds.js | 16 --- examples/ex-list-secrets.js | 13 -- examples/ex-make-call-ncco.js | 28 ---- examples/ex-make-call.js | 25 ---- examples/ex-make-multiple-calls.js | 84 ------------ examples/ex-media-delete.js | 20 --- examples/ex-media-download.js | 20 --- examples/ex-media-get.js | 20 --- examples/ex-media-search.js | 23 ---- examples/ex-media-update.js | 22 --- examples/ex-media-upload.js | 28 ---- examples/ex-number-buy.js | 13 -- examples/ex-number-cancel.js | 13 -- examples/ex-number-get.js | 13 -- examples/ex-number-insight-advanced-async.js | 17 --- examples/ex-number-insight-advanced-sync.js | 16 --- examples/ex-number-insight-basic.js | 16 --- examples/ex-number-insight-standard.js | 16 --- examples/ex-number-pricing.js | 17 --- examples/ex-number-search.js | 13 -- examples/ex-number-update.js | 13 -- examples/ex-redact-transaction.js | 18 --- examples/ex-revoke-secret.js | 13 -- examples/ex-search-verification.js | 13 -- examples/ex-send-binary-sms.js | 16 --- ...ex-send-psd2-verification-with-workflow.js | 18 --- examples/ex-send-psd2-verification.js | 17 --- examples/ex-send-shortcode-2fa.js | 13 -- examples/ex-send-shortcode-alert.js | 13 -- examples/ex-send-signed-sms.js | 15 -- examples/ex-send-sms.js | 13 -- examples/ex-send-tts.js | 13 -- .../ex-send-verification-with-workflow.js | 17 --- examples/ex-send-verification.js | 16 --- examples/ex-send-wap-message.js | 14 -- examples/ex-stream-to-call.js | 129 ------------------ examples/ex-talk-to-call.js | 123 ----------------- examples/ex-update-v1-application.js | 23 ---- examples/ex-update-v2-application.js | 49 ------- .../ex-verify-signed-sms-without-instance.js | 32 ----- examples/ex-verify-signed-sms.js | 40 ------ examples/example.env | 25 ---- examples/run-examples.js | 124 ----------------- 68 files changed, 1827 deletions(-) delete mode 100644 examples/README.md delete mode 100644 examples/config.js delete mode 100644 examples/ex-change-api-host.js delete mode 100644 examples/ex-change-rest-host.js delete mode 100644 examples/ex-check-balance.js delete mode 100644 examples/ex-check-verification.js delete mode 100644 examples/ex-control-verification.js delete mode 100644 examples/ex-create-secret.js delete mode 100644 examples/ex-create-update-delete-app.js delete mode 100644 examples/ex-create-v1-application.js delete mode 100644 examples/ex-create-v2-application.js delete mode 100644 examples/ex-delete-application.js delete mode 100644 examples/ex-dtmf-to-call.js delete mode 100644 examples/ex-get-calls.js delete mode 100644 examples/ex-get-full-pricing.js delete mode 100644 examples/ex-get-phone-pricing-number.js delete mode 100644 examples/ex-get-phone-pricing.js delete mode 100644 examples/ex-get-prefix-pricing.js delete mode 100644 examples/ex-get-pricing-number.js delete mode 100644 examples/ex-get-pricing.js delete mode 100644 examples/ex-get-secret.js delete mode 100644 examples/ex-get-v1-application.js delete mode 100644 examples/ex-get-v1-applications.js delete mode 100644 examples/ex-get-v2-application.js delete mode 100644 examples/ex-get-v2-applications.js delete mode 100644 examples/ex-keyfile-creds.js delete mode 100644 examples/ex-list-secrets.js delete mode 100644 examples/ex-make-call-ncco.js delete mode 100644 examples/ex-make-call.js delete mode 100644 examples/ex-make-multiple-calls.js delete mode 100644 examples/ex-media-delete.js delete mode 100644 examples/ex-media-download.js delete mode 100644 examples/ex-media-get.js delete mode 100644 examples/ex-media-search.js delete mode 100644 examples/ex-media-update.js delete mode 100644 examples/ex-media-upload.js delete mode 100644 examples/ex-number-buy.js delete mode 100644 examples/ex-number-cancel.js delete mode 100644 examples/ex-number-get.js delete mode 100644 examples/ex-number-insight-advanced-async.js delete mode 100644 examples/ex-number-insight-advanced-sync.js delete mode 100644 examples/ex-number-insight-basic.js delete mode 100644 examples/ex-number-insight-standard.js delete mode 100644 examples/ex-number-pricing.js delete mode 100644 examples/ex-number-search.js delete mode 100644 examples/ex-number-update.js delete mode 100644 examples/ex-redact-transaction.js delete mode 100644 examples/ex-revoke-secret.js delete mode 100644 examples/ex-search-verification.js delete mode 100644 examples/ex-send-binary-sms.js delete mode 100644 examples/ex-send-psd2-verification-with-workflow.js delete mode 100644 examples/ex-send-psd2-verification.js delete mode 100644 examples/ex-send-shortcode-2fa.js delete mode 100644 examples/ex-send-shortcode-alert.js delete mode 100644 examples/ex-send-signed-sms.js delete mode 100644 examples/ex-send-sms.js delete mode 100644 examples/ex-send-tts.js delete mode 100644 examples/ex-send-verification-with-workflow.js delete mode 100644 examples/ex-send-verification.js delete mode 100644 examples/ex-send-wap-message.js delete mode 100644 examples/ex-stream-to-call.js delete mode 100644 examples/ex-talk-to-call.js delete mode 100644 examples/ex-update-v1-application.js delete mode 100644 examples/ex-update-v2-application.js delete mode 100644 examples/ex-verify-signed-sms-without-instance.js delete mode 100644 examples/ex-verify-signed-sms.js delete mode 100644 examples/example.env delete mode 100644 examples/run-examples.js diff --git a/examples/README.md b/examples/README.md deleted file mode 100644 index 90432dbd..00000000 --- a/examples/README.md +++ /dev/null @@ -1,63 +0,0 @@ -# How to use the examples - -The examples are here for two reasons: - -1. To help with testing against the live API - maybe full integration tests will be created at some point -2. To demonstrate how to use the API - -Some examples are convoluted because they require a web server to be running and that web server to have a public IP address. This adds complexity. It also adds the requirement of using [ngrok](https://ngrok.com/). - -Looking for more focused examples? Head to the [Nexmo Node Quickstarts rep][quickstarts] - -That said, the naming of the files should make it clear what each example will demonstrate. - -## Usage - -Copy `example.env` and rename to `.env` and add the appropriate values. - -Take a look at `run-examples.js`. This file can be run using: - -```bash -node run-examples.js -``` - -### All examples - -If you want to run all the `exampleFiles` override is commented out and that `runNextExample()` is called. This will load and run all modules with an `ex-` prefix. - -### Selectively running examples - -To selectively run examples you should either run a single example, commenting out all other `run...` lines: - -```js -runExample('ex-send-sms.js', console.log); -``` - -Update the `exampleFiles` array and make sure `runNextExample` is not commented out e.g. - -```js -exampleFiles = [ - // 'ex-check-balance.js', - // 'ex-create-update-delete-app.js', - // 'ex-dtmf-to-call.js', - // 'ex-get-apps.js', - 'ex-get-calls.js', - 'ex-make-call.js' - // 'ex-number-insight-basic.js', - // 'ex-send-sms.js', - // 'ex-stream-to-call.js', - // 'ex-talk-to-call.js' -]; - -runNextExample(); -``` - -## Missing an example - -[Raise an issue](../../../issues) - -## More examples - -You can find examples that are much more focused of achieving a single goal in the [Nexmo Node Quickstarts rep][quickstarts]. - -[quickstarts]: https://github.com/nexmo-community/nexmo-node-quickstart diff --git a/examples/config.js b/examples/config.js deleted file mode 100644 index 7a8aa502..00000000 --- a/examples/config.js +++ /dev/null @@ -1,29 +0,0 @@ -require('dotenv').config({ - path: __dirname + '/.env' -}); - -var config = { - API_KEY: process.env.API_KEY || '', - API_SECRET: process.env.API_SECRET || '', - SIGNATURE_SECRET: process.env.SIGNATURE_SECRET || '', - NEW_API_SECRET: process.env.NEW_API_SECRET || '', - API_SECRET_ID: process.env.API_SECRET_ID || '', - FROM_NUMBER: process.env.FROM_NUMBER || '', - ALT_TO_NUMBER: process.env.ALT_TO_NUMBER || '', - TO_NUMBER: process.env.TO_NUMBER || '', - NEXMO_COUNTRY_CODE: process.env.NEXMO_COUNTRY_CODE || '', - NEXMO_NUMBER: process.env.NEXMO_NUMBER || '', - TO_US_NUMBER: process.env.TO_US_NUMBER || '', - MEDIA_ID: process.env.MEDIA_ID || '', - BRAND_NAME: process.env.BRAND_NAME || '', - REQUEST_ID: process.env.REQUEST_ID || '', - WORKFLOW_ID: process.env.WORKFLOW_ID || '', - CODE: process.env.CODE || '', - APP_ID: process.env.APP_ID || '', - PRIVATE_KEY: process.env.PRIVATE_KEY || '', - DEBUG: process.env.DEBUG === 'true', - REST_HOST: process.env.REST_HOST || 'rest.nexmo.com', - API_HOST: process.env.API_HOST || 'api.nexmo.com' -}; - -module.exports = config; diff --git a/examples/ex-change-api-host.js b/examples/ex-change-api-host.js deleted file mode 100644 index 6261dfcf..00000000 --- a/examples/ex-change-api-host.js +++ /dev/null @@ -1,50 +0,0 @@ -module.exports = function(callback, config) { - - var Nexmo = require('../lib/Nexmo'); - - var nexmo = new Nexmo({ - apiKey: config.API_KEY, - apiSecret: config.API_SECRET - }, { - debug: config.DEBUG, - apiHost: config.API_HOST - }); - - nexmo.applications.create({ - name: 'My nexmo-node Example V2 App', - capabilities: { - voice: { - webhooks: { - answer_url: { - address: "https://example.com", - http_method: "GET" - }, - event_url: { - address: "https://example.com", - http_method: "POST" - } - } - }, - messages: { - webhooks: { - inbound_url: { - address: "https://example.com", - http_method: "POST" - }, - status_url: { - address: "https://example.com", - http_method: "POST" - } - } - }, - rtc: { - webhooks: { - event_url: { - address: "https://example.com", - http_method: "POST" - } - } - } - } - }, callback); -}; diff --git a/examples/ex-change-rest-host.js b/examples/ex-change-rest-host.js deleted file mode 100644 index d9e6e45a..00000000 --- a/examples/ex-change-rest-host.js +++ /dev/null @@ -1,14 +0,0 @@ -module.exports = function(callback, config) { - - var Nexmo = require('../lib/Nexmo'); - - var nexmo = new Nexmo({ - apiKey: config.API_KEY, - apiSecret: config.API_SECRET - }, { - debug: config.DEBUG, - restHost: config.REST_HOST - }); - - nexmo.message.sendSms(config.FROM_NUMBER, config.TO_NUMBER, 'testing', callback); -}; diff --git a/examples/ex-check-balance.js b/examples/ex-check-balance.js deleted file mode 100644 index 1928fc75..00000000 --- a/examples/ex-check-balance.js +++ /dev/null @@ -1,13 +0,0 @@ -module.exports = function(callback, config) { - - var Nexmo = require('../lib/Nexmo'); - - var nexmo = new Nexmo({ - apiKey: config.API_KEY, - apiSecret: config.API_SECRET - }, { - debug: config.DEBUG - }); - - nexmo.account.checkBalance(callback); -}; diff --git a/examples/ex-check-verification.js b/examples/ex-check-verification.js deleted file mode 100644 index 8fcfad56..00000000 --- a/examples/ex-check-verification.js +++ /dev/null @@ -1,16 +0,0 @@ -module.exports = function(callback, config) { - - var Nexmo = require('../lib/Nexmo'); - - var nexmo = new Nexmo({ - apiKey: config.API_KEY, - apiSecret: config.API_SECRET - }, { - debug: config.DEBUG - }); - - nexmo.verify.check({ - request_id: config.REQUEST_ID, - code: config.CODE - }, callback); -}; diff --git a/examples/ex-control-verification.js b/examples/ex-control-verification.js deleted file mode 100644 index 894d12bc..00000000 --- a/examples/ex-control-verification.js +++ /dev/null @@ -1,16 +0,0 @@ -module.exports = function(callback, config) { - - var Nexmo = require('../lib/Nexmo'); - - var nexmo = new Nexmo({ - apiKey: config.API_KEY, - apiSecret: config.API_SECRET - }, { - debug: config.DEBUG - }); - - nexmo.verify.control({ - request_id: config.REQUEST_ID, - cmd: 'cancel' - }, callback); -}; diff --git a/examples/ex-create-secret.js b/examples/ex-create-secret.js deleted file mode 100644 index a5d81b0a..00000000 --- a/examples/ex-create-secret.js +++ /dev/null @@ -1,13 +0,0 @@ -module.exports = function(callback, config) { - - var Nexmo = require('../lib/Nexmo'); - - var nexmo = new Nexmo({ - apiKey: config.API_KEY, - apiSecret: config.API_SECRET - }, { - debug: config.DEBUG - }); - - nexmo.account.createSecret(config.API_KEY, config.NEW_API_SECRET, callback); -}; diff --git a/examples/ex-create-update-delete-app.js b/examples/ex-create-update-delete-app.js deleted file mode 100644 index 7d9906cb..00000000 --- a/examples/ex-create-update-delete-app.js +++ /dev/null @@ -1,33 +0,0 @@ -module.exports = function(callback, config) { - - var Promise = require('bluebird'); - - var Nexmo = require('../lib/Nexmo'); - - var nexmo = new Nexmo({ - apiKey: config.API_KEY, - apiSecret: config.API_SECRET - }, { - debug: config.DEBUG - }); - - var app = Promise.promisifyAll(nexmo.app); - - var tempAppName = new Date().getTime(); - console.log('Creating App', tempAppName); - - app.createAsync(tempAppName, 'voice', 'https://v1uxw2scimhr.runscope.net', 'https://v1uxw2scimhr.runscope.net', null) - .then(function(createResp) { - console.log('Updating App', tempAppName); - return app.updateAsync(createResp.id, tempAppName, 'voice', 'https://v1uxw2scimhr.runscope.net', 'https://v1uxw2scimhr.runscope.net', null); - }) - .then(function(updateResp) { - console.log('Deleting App', tempAppName); - return app.deleteAsync(updateResp.id); - }) - .then(function(deleteResp) { - console.log('App Deleted'); - callback(null, deleteResp); - }) - .catch(callback); -}; diff --git a/examples/ex-create-v1-application.js b/examples/ex-create-v1-application.js deleted file mode 100644 index d267a8f8..00000000 --- a/examples/ex-create-v1-application.js +++ /dev/null @@ -1,23 +0,0 @@ -module.exports = function(callback, config) { - - var Nexmo = require('../lib/Nexmo'); - - var nexmo = new Nexmo({ - apiKey: config.API_KEY, - apiSecret: config.API_SECRET - }, { - debug: config.DEBUG - }); - - const name = 'My nexmo-node Messages App'; - const type = 'messages'; - const answerUrl = 'https://example.com'; // webhook that points to NCCO - const eventUrl = 'https://example.com'; - - let options = { - inbound_url: 'https://example.com', - status_url: 'https://example.com' - }; - - nexmo.applications.create(name, type, answerUrl, eventUrl, options, callback); -}; diff --git a/examples/ex-create-v2-application.js b/examples/ex-create-v2-application.js deleted file mode 100644 index c85604db..00000000 --- a/examples/ex-create-v2-application.js +++ /dev/null @@ -1,49 +0,0 @@ -module.exports = function(callback, config) { - - var Nexmo = require('../lib/Nexmo'); - - var nexmo = new Nexmo({ - apiKey: config.API_KEY, - apiSecret: config.API_SECRET - }, { - debug: config.DEBUG - }); - - nexmo.applications.create({ - name: 'My nexmo-node Example V2 App', - capabilities: { - voice: { - webhooks: { - answer_url: { - address: "https://example.com", - http_method: "GET" - }, - event_url: { - address: "https://example.com", - http_method: "POST" - } - } - }, - messages: { - webhooks: { - inbound_url: { - address: "https://example.com", - http_method: "POST" - }, - status_url: { - address: "https://example.com", - http_method: "POST" - } - } - }, - rtc: { - webhooks: { - event_url: { - address: "https://example.com", - http_method: "POST" - } - } - } - } - }, callback); -}; diff --git a/examples/ex-delete-application.js b/examples/ex-delete-application.js deleted file mode 100644 index 806c7e71..00000000 --- a/examples/ex-delete-application.js +++ /dev/null @@ -1,13 +0,0 @@ -module.exports = function(callback, config) { - - var Nexmo = require('../lib/Nexmo'); - - var nexmo = new Nexmo({ - apiKey: config.API_KEY, - apiSecret: config.API_SECRET - }, - {debug: config.DEBUG} - ); - - nexmo.applications.delete(config.APP_ID, callback); -}; diff --git a/examples/ex-dtmf-to-call.js b/examples/ex-dtmf-to-call.js deleted file mode 100644 index 83a2b7c7..00000000 --- a/examples/ex-dtmf-to-call.js +++ /dev/null @@ -1,105 +0,0 @@ -module.exports = function(callback, config) { - - var Promise = require('bluebird'); - var ngrok = require('ngrok'); - var SPACER = '\n****\n\n'; - - var Nexmo = require('../lib/Nexmo'); - var nexmo = new Nexmo({ - apiKey: config.API_KEY, - apiSecret: config.API_SECRET, - applicationId: config.APP_ID, - privateKey: config.PRIVATE_KEY - }, { - debug: config.DEBUG - }); - var calls = Promise.promisifyAll(nexmo.calls); - var dtmf = Promise.promisifyAll(nexmo.calls.dtmf); - - function randomPort() { - return Math.floor(Math.random() * (7000 - 3000 + 1) + 3000); - } - - var app = require('express')(); - app.set('port', (process.env.PORT || randomPort())); - app.use(require('body-parser').json()); - - // Handle events - var callId = null; - app.post('/', function(req, res) { - console.log('Request received', req.body); - // Hack: seeing two inbound webhook requests. - // Use callId to indicate this. - if (req.body.status === 'answered' && !callId) { - callId = req.body.uuid; - - console.log('Call answered with call_uuid', callId) - - setTimeout(function() { - sendDtmf(callId); - }, 5000); - } - - res.sendStatus(204); - }); - - var server = app.listen(app.get('port'), makeCall); - - function makeCall() { - console.log('Web server listening on port', app.get('port')); - - Promise.promisify(ngrok.connect)(app.get('port')) - .then(function(url) { - console.log('ngrok tunnel set up:', url); - - console.log('calling', config.TO_NUMBER); - return calls.createAsync({ - to: [{ - type: 'phone', - number: config.TO_NUMBER - }], - from: { - type: 'phone', - number: config.FROM_NUMBER - }, - answer_url: ['https://nexmo-community.github.io/ncco-examples/conference.json'], - event_url: [url] - }); - }) - .then(function(res) { - console.log('call in progress', res); - }) - .catch(callback); - } - - function sendDtmf(callId) { - dtmf.sendAsync(callId, { - digits: '1234' - }) - .then(function(res) { - console.log('dtmf.send res', res); - - return calls.updateAsync(callId, { - action: 'hangup' - }); - }) - .then(function(res) { - console.log('calls.update', res); - - server.close(); - ngrok.kill(); - - return Promise.delay(2000); - }) - .then(function() { - callback(null, null); - }) - .catch(function(err) { - if (server) server.close(); - if (ngrok) ngrok.kill(); - - callback(err); - }); - } - -}; diff --git a/examples/ex-get-calls.js b/examples/ex-get-calls.js deleted file mode 100644 index 857369ca..00000000 --- a/examples/ex-get-calls.js +++ /dev/null @@ -1,47 +0,0 @@ -module.exports = function(callback, config) { - - var Promise = require('bluebird'); - var SPACER = '\n****\n\n'; - - var Nexmo = require('../lib/Nexmo'); - - var nexmo = new Nexmo({ - apiKey: config.API_KEY, - apiSecret: config.API_SECRET, - applicationId: config.APP_ID, - privateKey: config.PRIVATE_KEY - }, { - debug: config.DEBUG - }); - - var calls = Promise.promisifyAll(nexmo.calls); - var callId = null; - nexmo.calls.getAsync({}) - .then(function(resp) { - console.log(resp._embedded.calls); - - callId = resp._embedded.calls[0].uuid; - console.log(SPACER, 'Getting single call details', callId); - return calls.getAsync(callId); - }) - .then(function(resp) { - console.log('single call details', resp); - - console.log(SPACER, 'Getting calls by query'); - return calls.getAsync({ - status: 'completed' - }); - }) - .then(function(resp) { - console.log('Call query response', resp); - - console.log(SPACER, 'Updating a call', callId); - return calls.updateAsync(callId, { - action: 'hangup' - }); - }) - .then(function(resp) { - callback(null, resp); - }) - .catch(callback); -}; diff --git a/examples/ex-get-full-pricing.js b/examples/ex-get-full-pricing.js deleted file mode 100644 index bd5f8cd6..00000000 --- a/examples/ex-get-full-pricing.js +++ /dev/null @@ -1,13 +0,0 @@ -module.exports = function(callback, config) { - - var Nexmo = require('../lib/Nexmo'); - - var nexmo = new Nexmo({ - apiKey: config.API_KEY, - apiSecret: config.API_SECRET - }, { - debug: config.DEBUG - }); - - nexmo.pricing.getFull("sms", callback); -}; diff --git a/examples/ex-get-phone-pricing-number.js b/examples/ex-get-phone-pricing-number.js deleted file mode 100644 index fc21d28a..00000000 --- a/examples/ex-get-phone-pricing-number.js +++ /dev/null @@ -1,13 +0,0 @@ -module.exports = function(callback, config) { - - var Nexmo = require('../lib/Nexmo'); - - var nexmo = new Nexmo({ - apiKey: config.API_KEY, - apiSecret: config.API_SECRET - }, { - debug: config.DEBUG - }); - - nexmo.number.getPhonePricing("sms", "442038659460", callback); -}; diff --git a/examples/ex-get-phone-pricing.js b/examples/ex-get-phone-pricing.js deleted file mode 100644 index 0303363b..00000000 --- a/examples/ex-get-phone-pricing.js +++ /dev/null @@ -1,13 +0,0 @@ -module.exports = function(callback, config) { - - var Nexmo = require('../lib/Nexmo'); - - var nexmo = new Nexmo({ - apiKey: config.API_KEY, - apiSecret: config.API_SECRET - }, { - debug: config.DEBUG - }); - - nexmo.pricing.getPhone("sms", "442038659460", callback); -}; diff --git a/examples/ex-get-prefix-pricing.js b/examples/ex-get-prefix-pricing.js deleted file mode 100644 index ad1fa032..00000000 --- a/examples/ex-get-prefix-pricing.js +++ /dev/null @@ -1,13 +0,0 @@ -module.exports = function(callback, config) { - - var Nexmo = require('../lib/Nexmo'); - - var nexmo = new Nexmo({ - apiKey: config.API_KEY, - apiSecret: config.API_SECRET - }, { - debug: config.DEBUG - }); - - nexmo.pricing.getPrefix("sms", "44", callback); -}; diff --git a/examples/ex-get-pricing-number.js b/examples/ex-get-pricing-number.js deleted file mode 100644 index 5ee4e0d3..00000000 --- a/examples/ex-get-pricing-number.js +++ /dev/null @@ -1,13 +0,0 @@ -module.exports = function(callback, config) { - - var Nexmo = require('../lib/Nexmo'); - - var nexmo = new Nexmo({ - apiKey: config.API_KEY, - apiSecret: config.API_SECRET - }, { - debug: config.DEBUG - }); - - nexmo.number.getPricing("sms", "GB", callback); -}; diff --git a/examples/ex-get-pricing.js b/examples/ex-get-pricing.js deleted file mode 100644 index 5673131c..00000000 --- a/examples/ex-get-pricing.js +++ /dev/null @@ -1,13 +0,0 @@ -module.exports = function(callback, config) { - - var Nexmo = require('../lib/Nexmo'); - - var nexmo = new Nexmo({ - apiKey: config.API_KEY, - apiSecret: config.API_SECRET - }, { - debug: config.DEBUG - }); - - nexmo.pricing.get("sms", "GB", callback); -}; diff --git a/examples/ex-get-secret.js b/examples/ex-get-secret.js deleted file mode 100644 index 2a169c65..00000000 --- a/examples/ex-get-secret.js +++ /dev/null @@ -1,13 +0,0 @@ -module.exports = function(callback, config) { - - var Nexmo = require('../lib/Nexmo'); - - var nexmo = new Nexmo({ - apiKey: config.API_KEY, - apiSecret: config.API_SECRET - }, { - debug: config.DEBUG - }); - - nexmo.account.getSecret(config.API_KEY, config.API_SECRET_ID, callback); -}; diff --git a/examples/ex-get-v1-application.js b/examples/ex-get-v1-application.js deleted file mode 100644 index 256260e1..00000000 --- a/examples/ex-get-v1-application.js +++ /dev/null @@ -1,13 +0,0 @@ -module.exports = function(callback, config) { - - var Nexmo = require('../lib/Nexmo'); - - var nexmo = new Nexmo({ - apiKey: config.API_KEY, - apiSecret: config.API_SECRET - }, - {debug: config.DEBUG} - ); - - nexmo.applications.get(config.APP_ID, callback); -}; diff --git a/examples/ex-get-v1-applications.js b/examples/ex-get-v1-applications.js deleted file mode 100644 index b25e3304..00000000 --- a/examples/ex-get-v1-applications.js +++ /dev/null @@ -1,13 +0,0 @@ -module.exports = function(callback, config) { - - var Nexmo = require('../lib/Nexmo'); - - var nexmo = new Nexmo({ - apiKey: config.API_KEY, - apiSecret: config.API_SECRET - }, - {debug: config.DEBUG} - ); - - nexmo.applications.get({page_size: 5}, callback); -}; diff --git a/examples/ex-get-v2-application.js b/examples/ex-get-v2-application.js deleted file mode 100644 index 26981210..00000000 --- a/examples/ex-get-v2-application.js +++ /dev/null @@ -1,13 +0,0 @@ -module.exports = function(callback, config) { - - var Nexmo = require('../lib/Nexmo'); - - var nexmo = new Nexmo({ - apiKey: config.API_KEY, - apiSecret: config.API_SECRET - }, - {debug: config.DEBUG} - ); - - nexmo.applications.get(config.APP_ID, callback, true); -}; diff --git a/examples/ex-get-v2-applications.js b/examples/ex-get-v2-applications.js deleted file mode 100644 index 32f26acd..00000000 --- a/examples/ex-get-v2-applications.js +++ /dev/null @@ -1,13 +0,0 @@ -module.exports = function(callback, config) { - - var Nexmo = require('../lib/Nexmo'); - - var nexmo = new Nexmo({ - apiKey: config.API_KEY, - apiSecret: config.API_SECRET - }, - {debug: config.DEBUG} - ); - - nexmo.applications.get({page_size: 5}, callback, true); -}; diff --git a/examples/ex-keyfile-creds.js b/examples/ex-keyfile-creds.js deleted file mode 100644 index e5f76219..00000000 --- a/examples/ex-keyfile-creds.js +++ /dev/null @@ -1,16 +0,0 @@ -module.exports = function(callback, config) { - var Nexmo = require("../lib/Nexmo"); - - var nexmo = new Nexmo( - { - applicationId: config.APP_ID, - privateKey: config.PRIVATE_KEY - }, - { debug: config.DEBUG } - ); - - if(!nexmo.credentials.privateKey) { - // no key found - throw new Error("PrivateKey not loaded"); - } -}; diff --git a/examples/ex-list-secrets.js b/examples/ex-list-secrets.js deleted file mode 100644 index fd9d3dd2..00000000 --- a/examples/ex-list-secrets.js +++ /dev/null @@ -1,13 +0,0 @@ -module.exports = function(callback, config) { - - var Nexmo = require('../lib/Nexmo'); - - var nexmo = new Nexmo({ - apiKey: config.API_KEY, - apiSecret: config.API_SECRET - }, { - debug: config.DEBUG - }); - - nexmo.account.listSecrets(config.API_KEY, callback); -}; diff --git a/examples/ex-make-call-ncco.js b/examples/ex-make-call-ncco.js deleted file mode 100644 index 794b2ab2..00000000 --- a/examples/ex-make-call-ncco.js +++ /dev/null @@ -1,28 +0,0 @@ -module.exports = function(callback, config) { - - var Nexmo = require('../lib/Nexmo'); - - var nexmo = new Nexmo({ - apiKey: config.API_KEY, - apiSecret: config.API_SECRET, - applicationId: config.APP_ID, - privateKey: config.PRIVATE_KEY - }, { - debug: config.DEBUG - }); - - nexmo.calls.create({ - to: [{ - type: 'phone', - number: config.TO_NUMBER - }], - from: { - type: 'phone', - number: config.FROM_NUMBER - }, - ncco: [{ - "action": "talk", - "text": "This is a text to speech call from Nexmo" - }] - }, callback); -}; diff --git a/examples/ex-make-call.js b/examples/ex-make-call.js deleted file mode 100644 index c7bfb868..00000000 --- a/examples/ex-make-call.js +++ /dev/null @@ -1,25 +0,0 @@ -module.exports = function(callback, config) { - - var Nexmo = require('../lib/Nexmo'); - - var nexmo = new Nexmo({ - apiKey: config.API_KEY, - apiSecret: config.API_SECRET, - applicationId: config.APP_ID, - privateKey: config.PRIVATE_KEY - }, { - debug: config.DEBUG - }); - - nexmo.calls.create({ - to: [{ - type: 'phone', - number: config.TO_NUMBER - }], - from: { - type: 'phone', - number: config.FROM_NUMBER - }, - answer_url: ['https://nexmo-community.github.io/ncco-examples/first_call_talk.json'] - }, callback); -}; diff --git a/examples/ex-make-multiple-calls.js b/examples/ex-make-multiple-calls.js deleted file mode 100644 index 3e44d792..00000000 --- a/examples/ex-make-multiple-calls.js +++ /dev/null @@ -1,84 +0,0 @@ -module.exports = function(callback, config) { - - var Nexmo = require('../lib/Nexmo'); - - var nexmo = new Nexmo({ - apiKey: config.API_KEY, - apiSecret: config.API_SECRET, - applicationId: config.APP_ID, - privateKey: config.PRIVATE_KEY - }, { - debug: config.DEBUG - }); - - function callWithRetry(callRequest, callback, maxRetries, retryCount) { - retryCount = retryCount || 0; - - nexmo.calls.create(callRequest, function(error, result) { - console.log('----------------------------'); - console.log('call response returned'); - console.log('error', JSON.stringify(error, null, 2)); - console.log('result', JSON.stringify(result, null, 2)); - - if (error && error.statusCode === 429 && retryCount <= maxRetries) { - console.log('429 detected. Retrying after', error.headers['retry-after'], 'ms'); - setTimeout(function() { - callWithRetry(callRequest, callback, maxRetries, ++retryCount); - }, error.headers['retry-after']); - - } else { - callback(error, result); - } - }); - } - - const callsToMake = [{ - to: [{ - type: 'phone', - number: config.TO_NUMBER - }], - from: { - type: 'phone', - number: config.FROM_NUMBER - }, - answer_url: ['https://nexmo-community.github.io/ncco-examples/first_call_talk.json'], - event_url: ['http://requestb.in/wgapg3wg?to=' + config.TO_NUMBER] - }, - { - to: [{ - type: 'phone', - number: config.ALT_TO_NUMBER - }], - from: { - type: 'phone', - number: config.FROM_NUMBER - }, - answer_url: ['https://nexmo-community.github.io/ncco-examples/first_call_talk.json'], - event_url: ['http://requestb.in/wgapg3wg?to=' + config.ALT_TO_NUMBER] - } - ]; - - const results = []; - - function makeNextCall(error, result) { - if (error || result) { - results.push({ - error: error, - result: result - }); - } - - if (callsToMake.length > 0) { - var callRequest = callsToMake.shift(); - callWithRetry(callRequest, makeNextCall, 1); - } else { - console.log('--------------------------'); - console.log('all calls completed', results); - console.log('--------------------------'); - callback(null, results); - } - } - - makeNextCall(); - -}; diff --git a/examples/ex-media-delete.js b/examples/ex-media-delete.js deleted file mode 100644 index f2f2e5d3..00000000 --- a/examples/ex-media-delete.js +++ /dev/null @@ -1,20 +0,0 @@ -module.exports = function(callback, config) { - - var Nexmo = require('../lib/Nexmo'); - - var nexmo = new Nexmo({ - apiKey: config.API_KEY, - apiSecret: config.API_SECRET, - applicationId: config.APP_ID, - privateKey: config.PRIVATE_KEY - }, { - debug: config.DEBUG - }); - - nexmo.media.delete(config.MEDIA_ID, function(err, data) { - if (err) { - throw err; - } - console.log(data); - }); -}; diff --git a/examples/ex-media-download.js b/examples/ex-media-download.js deleted file mode 100644 index b95afe6a..00000000 --- a/examples/ex-media-download.js +++ /dev/null @@ -1,20 +0,0 @@ -module.exports = function(callback, config) { - - var Nexmo = require('../lib/Nexmo'); - - var nexmo = new Nexmo({ - apiKey: config.API_KEY, - apiSecret: config.API_SECRET, - applicationId: config.APP_ID, - privateKey: config.PRIVATE_KEY - }, { - debug: config.DEBUG - }); - - nexmo.media.download(config.MEDIA_ID, function(err, data) { - if (err) { - throw err; - } - console.log(data.toString()); - }); -}; diff --git a/examples/ex-media-get.js b/examples/ex-media-get.js deleted file mode 100644 index 51804544..00000000 --- a/examples/ex-media-get.js +++ /dev/null @@ -1,20 +0,0 @@ -module.exports = function(callback, config) { - - var Nexmo = require('../lib/Nexmo'); - - var nexmo = new Nexmo({ - apiKey: config.API_KEY, - apiSecret: config.API_SECRET, - applicationId: config.APP_ID, - privateKey: config.PRIVATE_KEY - }, { - debug: config.DEBUG - }); - - nexmo.media.get(config.MEDIA_ID, function(err, data) { - if (err) { - throw err; - } - console.log(data); - }); -}; diff --git a/examples/ex-media-search.js b/examples/ex-media-search.js deleted file mode 100644 index d6a253f4..00000000 --- a/examples/ex-media-search.js +++ /dev/null @@ -1,23 +0,0 @@ -module.exports = function(callback, config) { - - var Nexmo = require('../lib/Nexmo'); - - var nexmo = new Nexmo({ - apiKey: config.API_KEY, - apiSecret: config.API_SECRET, - applicationId: config.APP_ID, - privateKey: config.PRIVATE_KEY - }, { - debug: config.DEBUG - }); - - nexmo.media.search({ - page_size: 1, - page_index: 1 - }, function(err, data) { - if (err) { - throw err; - } - console.log(data); - }); -}; diff --git a/examples/ex-media-update.js b/examples/ex-media-update.js deleted file mode 100644 index 317a5676..00000000 --- a/examples/ex-media-update.js +++ /dev/null @@ -1,22 +0,0 @@ -module.exports = function(callback, config) { - - var Nexmo = require('../lib/Nexmo'); - - var nexmo = new Nexmo({ - apiKey: config.API_KEY, - apiSecret: config.API_SECRET, - applicationId: config.APP_ID, - privateKey: config.PRIVATE_KEY - }, { - debug: config.DEBUG - }); - - nexmo.media.update(config.MEDIA_ID, { - public_item: true - }, function(err, data) { - if (err) { - throw err; - } - console.log(data); - }); -}; diff --git a/examples/ex-media-upload.js b/examples/ex-media-upload.js deleted file mode 100644 index 8e98597b..00000000 --- a/examples/ex-media-upload.js +++ /dev/null @@ -1,28 +0,0 @@ -module.exports = function(callback, config) { - - var Nexmo = require('../lib/Nexmo'); - - var nexmo = new Nexmo({ - apiKey: config.API_KEY, - apiSecret: config.API_SECRET, - applicationId: config.APP_ID, - privateKey: config.PRIVATE_KEY - }, { - debug: config.DEBUG - }); - - nexmo.media.upload({ - //file: "/path/to/file", // If you want to upload a file instead of fetching a URL, set this instead - url: "https://www.nexmo.com/wp-content/uploads/2016/07/nexmo_vonage_color.jpg", - info: { - test: "content" - } - }, - function(err, data) { - if (err) { - throw err; - } - console.log(data); - } - ); -}; diff --git a/examples/ex-number-buy.js b/examples/ex-number-buy.js deleted file mode 100644 index 1051dafc..00000000 --- a/examples/ex-number-buy.js +++ /dev/null @@ -1,13 +0,0 @@ -module.exports = function(callback, config) { - - var Nexmo = require('../lib/Nexmo'); - - var nexmo = new Nexmo({ - apiKey: config.API_KEY, - apiSecret: config.API_SECRET - }, { - debug: config.DEBUG - }); - - nexmo.number.buy(config.NEXMO_COUNTRY_CODE, config.NEXMO_NUMBER, callback); -}; diff --git a/examples/ex-number-cancel.js b/examples/ex-number-cancel.js deleted file mode 100644 index dd949e83..00000000 --- a/examples/ex-number-cancel.js +++ /dev/null @@ -1,13 +0,0 @@ -module.exports = function(callback, config) { - - var Nexmo = require('../lib/Nexmo'); - - var nexmo = new Nexmo({ - apiKey: config.API_KEY, - apiSecret: config.API_SECRET - }, { - debug: config.DEBUG - }); - - nexmo.number.cancel(config.NEXMO_COUNTRY_CODE, config.NEXMO_NUMBER, callback); -}; diff --git a/examples/ex-number-get.js b/examples/ex-number-get.js deleted file mode 100644 index 1132343f..00000000 --- a/examples/ex-number-get.js +++ /dev/null @@ -1,13 +0,0 @@ -module.exports = function(callback, config) { - - var Nexmo = require('../lib/Nexmo'); - - var nexmo = new Nexmo({ - apiKey: config.API_KEY, - apiSecret: config.API_SECRET - }, { - debug: config.DEBUG - }); - - nexmo.number.get({}, callback); -}; diff --git a/examples/ex-number-insight-advanced-async.js b/examples/ex-number-insight-advanced-async.js deleted file mode 100644 index 01ff5e77..00000000 --- a/examples/ex-number-insight-advanced-async.js +++ /dev/null @@ -1,17 +0,0 @@ -module.exports = function(callback, config) { - - var Nexmo = require('../lib/Nexmo'); - - var nexmo = new Nexmo({ - apiKey: config.API_KEY, - apiSecret: config.API_SECRET - }, { - debug: config.DEBUG - }); - - nexmo.numberInsight.get({ - level: 'advanced', - number: config.TO_NUMBER, - callback: "http://example.com" - }, callback); -}; diff --git a/examples/ex-number-insight-advanced-sync.js b/examples/ex-number-insight-advanced-sync.js deleted file mode 100644 index bc070997..00000000 --- a/examples/ex-number-insight-advanced-sync.js +++ /dev/null @@ -1,16 +0,0 @@ -module.exports = function(callback, config) { - - var Nexmo = require('../lib/Nexmo'); - - var nexmo = new Nexmo({ - apiKey: config.API_KEY, - apiSecret: config.API_SECRET - }, { - debug: config.DEBUG - }); - - nexmo.numberInsight.get({ - level: 'advancedSync', - number: config.TO_NUMBER - }, callback); -}; diff --git a/examples/ex-number-insight-basic.js b/examples/ex-number-insight-basic.js deleted file mode 100644 index 9ae9b2f5..00000000 --- a/examples/ex-number-insight-basic.js +++ /dev/null @@ -1,16 +0,0 @@ -module.exports = function(callback, config) { - - var Nexmo = require('../lib/Nexmo'); - - var nexmo = new Nexmo({ - apiKey: config.API_KEY, - apiSecret: config.API_SECRET - }, { - debug: config.DEBUG - }); - - nexmo.numberInsight.get({ - level: 'basic', - number: config.TO_NUMBER - }, callback); -}; diff --git a/examples/ex-number-insight-standard.js b/examples/ex-number-insight-standard.js deleted file mode 100644 index aca9094e..00000000 --- a/examples/ex-number-insight-standard.js +++ /dev/null @@ -1,16 +0,0 @@ -module.exports = function(callback, config) { - - var Nexmo = require('../lib/Nexmo'); - - var nexmo = new Nexmo({ - apiKey: config.API_KEY, - apiSecret: config.API_SECRET - }, { - debug: config.DEBUG - }); - - nexmo.numberInsight.get({ - level: 'standard', - number: config.TO_NUMBER - }, callback); -}; diff --git a/examples/ex-number-pricing.js b/examples/ex-number-pricing.js deleted file mode 100644 index 37f61ab2..00000000 --- a/examples/ex-number-pricing.js +++ /dev/null @@ -1,17 +0,0 @@ -module.exports = function(callback, config) { - - var Nexmo = require('../lib/Nexmo'); - - var nexmo = new Nexmo({ - apiKey: config.API_KEY, - apiSecret: config.API_SECRET - }, { - debug: config.DEBUG - }); - - // You can get general pricing for a country - nexmo.number.getPricing('GB', console.log); - - // Or you can find out the price to call/sms a specific number - nexmo.number.getPhonePricing('voice', '447700900000', console.log) -}; diff --git a/examples/ex-number-search.js b/examples/ex-number-search.js deleted file mode 100644 index cfbf02b1..00000000 --- a/examples/ex-number-search.js +++ /dev/null @@ -1,13 +0,0 @@ -module.exports = function(callback, config) { - - var Nexmo = require('../lib/Nexmo'); - - var nexmo = new Nexmo({ - apiKey: config.API_KEY, - apiSecret: config.API_SECRET - }, { - debug: config.DEBUG - }); - - nexmo.number.search("GB", callback); -}; diff --git a/examples/ex-number-update.js b/examples/ex-number-update.js deleted file mode 100644 index d1d8f863..00000000 --- a/examples/ex-number-update.js +++ /dev/null @@ -1,13 +0,0 @@ -module.exports = function(callback, config) { - - var Nexmo = require('../lib/Nexmo'); - - var nexmo = new Nexmo({ - apiKey: config.API_KEY, - apiSecret: config.API_SECRET - }, { - debug: config.DEBUG - }); - - nexmo.number.update("GB", config.FROM_NUMBER, {app_id: config.APP_ID}, callback); -}; diff --git a/examples/ex-redact-transaction.js b/examples/ex-redact-transaction.js deleted file mode 100644 index 4b984ff9..00000000 --- a/examples/ex-redact-transaction.js +++ /dev/null @@ -1,18 +0,0 @@ -module.exports = function(callback, config) { - - var Nexmo = require('../lib/Nexmo'); - - var nexmo = new Nexmo({ - apiKey: config.API_KEY, - apiSecret: config.API_SECRET - }, { - debug: config.DEBUG - }); - - nexmo.redact.transaction(config.REDACT_ID, config.REDACT_TYPE, function(err, data) { - if (err) { - throw err; - } - // Returns a 204 if successful, so no response body - }); -}; diff --git a/examples/ex-revoke-secret.js b/examples/ex-revoke-secret.js deleted file mode 100644 index 1c45e8af..00000000 --- a/examples/ex-revoke-secret.js +++ /dev/null @@ -1,13 +0,0 @@ -module.exports = function(callback, config) { - - var Nexmo = require('../lib/Nexmo'); - - var nexmo = new Nexmo({ - apiKey: config.API_KEY, - apiSecret: config.API_SECRET - }, { - debug: config.DEBUG - }); - - nexmo.account.deleteSecret(config.API_KEY, config.API_SECRET_ID, callback); -}; diff --git a/examples/ex-search-verification.js b/examples/ex-search-verification.js deleted file mode 100644 index 383ce853..00000000 --- a/examples/ex-search-verification.js +++ /dev/null @@ -1,13 +0,0 @@ -module.exports = function(callback, config) { - - var Nexmo = require('../lib/Nexmo'); - - var nexmo = new Nexmo({ - apiKey: config.API_KEY, - apiSecret: config.API_SECRET - }, { - debug: config.DEBUG - }); - - nexmo.verify.search(config.REQUEST_ID, callback); -}; diff --git a/examples/ex-send-binary-sms.js b/examples/ex-send-binary-sms.js deleted file mode 100644 index 7ecd9ab6..00000000 --- a/examples/ex-send-binary-sms.js +++ /dev/null @@ -1,16 +0,0 @@ -module.exports = function(callback, config) { - - var Nexmo = require('../lib/Nexmo'); - - var nexmo = new Nexmo({ - apiKey: config.API_KEY, - apiSecret: config.API_SECRET - }, { - debug: config.DEBUG - }); - - // Sends an SMS with the text WIN - nexmo.message.sendBinaryMessage(config.FROM_NUMBER, config.TO_NUMBER, '57494E', '050003CC0101', { - "protocol-id": "65" - }, callback); -}; diff --git a/examples/ex-send-psd2-verification-with-workflow.js b/examples/ex-send-psd2-verification-with-workflow.js deleted file mode 100644 index 9ee3a5ad..00000000 --- a/examples/ex-send-psd2-verification-with-workflow.js +++ /dev/null @@ -1,18 +0,0 @@ -module.exports = function(callback, config) { - - var Nexmo = require('../lib/Nexmo'); - - var nexmo = new Nexmo({ - apiKey: config.API_KEY, - apiSecret: config.API_SECRET - }, { - debug: config.DEBUG - }); - - nexmo.verify.psd2({ - number: config.TO_NUMBER, - payee: config.BRAND_NAME, - amount: "10", - workflow_id: config.WORKFLOW_ID - }, callback); -}; diff --git a/examples/ex-send-psd2-verification.js b/examples/ex-send-psd2-verification.js deleted file mode 100644 index a9c683fb..00000000 --- a/examples/ex-send-psd2-verification.js +++ /dev/null @@ -1,17 +0,0 @@ -module.exports = function(callback, config) { - - var Nexmo = require('../lib/Nexmo'); - - var nexmo = new Nexmo({ - apiKey: config.API_KEY, - apiSecret: config.API_SECRET - }, { - debug: config.DEBUG - }); - - nexmo.verify.psd2({ - number: config.TO_NUMBER, - payee: config.BRAND_NAME, - amount: "10", - }, callback); -}; diff --git a/examples/ex-send-shortcode-2fa.js b/examples/ex-send-shortcode-2fa.js deleted file mode 100644 index f193ecda..00000000 --- a/examples/ex-send-shortcode-2fa.js +++ /dev/null @@ -1,13 +0,0 @@ -module.exports = function(callback, config) { - - var Nexmo = require('../lib/Nexmo'); - - var nexmo = new Nexmo({ - apiKey: config.API_KEY, - apiSecret: config.API_SECRET - }, { - debug: config.DEBUG - }); - - nexmo.message.shortcode2FA(config.TO_US_NUMBER, {"company-name": "Acme", "pin": "1234"}, {}, callback); -}; diff --git a/examples/ex-send-shortcode-alert.js b/examples/ex-send-shortcode-alert.js deleted file mode 100644 index c390de66..00000000 --- a/examples/ex-send-shortcode-alert.js +++ /dev/null @@ -1,13 +0,0 @@ -module.exports = function(callback, config) { - - var Nexmo = require('../lib/Nexmo'); - - var nexmo = new Nexmo({ - apiKey: config.API_KEY, - apiSecret: config.API_SECRET - }, { - debug: config.DEBUG - }); - - nexmo.message.shortcodeAlert(config.TO_US_NUMBER, {time: "now", place: "here"}, {}, callback); -}; diff --git a/examples/ex-send-signed-sms.js b/examples/ex-send-signed-sms.js deleted file mode 100644 index af3c8130..00000000 --- a/examples/ex-send-signed-sms.js +++ /dev/null @@ -1,15 +0,0 @@ -module.exports = function(callback, config) { - - var Nexmo = require('../lib/Nexmo'); - - var nexmo = new Nexmo({ - apiKey: config.API_KEY, - apiSecret: config.API_SECRET, - signatureSecret: config.SIGNATURE_SECRET, - signatureMethod: "md5hash" - }, { - debug: config.DEBUG - }); - - nexmo.message.sendSms(config.FROM_NUMBER, config.TO_NUMBER, 'testing 123', callback); -}; diff --git a/examples/ex-send-sms.js b/examples/ex-send-sms.js deleted file mode 100644 index 78aa5256..00000000 --- a/examples/ex-send-sms.js +++ /dev/null @@ -1,13 +0,0 @@ -module.exports = function(callback, config) { - - var Nexmo = require('../lib/Nexmo'); - - var nexmo = new Nexmo({ - apiKey: config.API_KEY, - apiSecret: config.API_SECRET - }, { - debug: config.DEBUG - }); - - nexmo.message.sendSms(config.FROM_NUMBER, config.TO_NUMBER, 'testing', callback); -}; diff --git a/examples/ex-send-tts.js b/examples/ex-send-tts.js deleted file mode 100644 index 4a2bcd4a..00000000 --- a/examples/ex-send-tts.js +++ /dev/null @@ -1,13 +0,0 @@ -module.exports = function(callback, config) { - - var Nexmo = require('../lib/Nexmo'); - - var nexmo = new Nexmo({ - apiKey: config.API_KEY, - apiSecret: config.API_SECRET - }, { - debug: config.DEBUG - }); - - nexmo.voice.sendTTSMessage(config.TO_NUMBER, 'testing', {}, callback); -}; diff --git a/examples/ex-send-verification-with-workflow.js b/examples/ex-send-verification-with-workflow.js deleted file mode 100644 index 8c3a7c09..00000000 --- a/examples/ex-send-verification-with-workflow.js +++ /dev/null @@ -1,17 +0,0 @@ -module.exports = function(callback, config) { - - var Nexmo = require('../lib/Nexmo'); - - var nexmo = new Nexmo({ - apiKey: config.API_KEY, - apiSecret: config.API_SECRET - }, { - debug: config.DEBUG - }); - - nexmo.verify.request({ - number: config.TO_NUMBER, - brand: config.BRAND_NAME, - workflow_id: config.WORKFLOW_ID - }, callback); -}; diff --git a/examples/ex-send-verification.js b/examples/ex-send-verification.js deleted file mode 100644 index c219d610..00000000 --- a/examples/ex-send-verification.js +++ /dev/null @@ -1,16 +0,0 @@ -module.exports = function(callback, config) { - - var Nexmo = require('../lib/Nexmo'); - - var nexmo = new Nexmo({ - apiKey: config.API_KEY, - apiSecret: config.API_SECRET - }, { - debug: config.DEBUG - }); - - nexmo.verify.request({ - number: config.TO_NUMBER, - brand: config.BRAND_NAME - }, callback); -}; diff --git a/examples/ex-send-wap-message.js b/examples/ex-send-wap-message.js deleted file mode 100644 index 5f06d5e1..00000000 --- a/examples/ex-send-wap-message.js +++ /dev/null @@ -1,14 +0,0 @@ -module.exports = function(callback, config) { - - var Nexmo = require('../lib/Nexmo'); - - var nexmo = new Nexmo({ - apiKey: config.API_KEY, - apiSecret: config.API_SECRET - }, { - debug: config.DEBUG - }); - - // Unless you have a phone capable of receiving WAP messages, you won't be able to test this. - nexmo.message.sendWapPushMessage(config.FROM_NUMBER, config.TO_NUMBER, 'Test', 'http://example.com', callback); -}; diff --git a/examples/ex-stream-to-call.js b/examples/ex-stream-to-call.js deleted file mode 100644 index a159b1e5..00000000 --- a/examples/ex-stream-to-call.js +++ /dev/null @@ -1,129 +0,0 @@ -module.exports = function(callback, config) { - - var Promise = require('bluebird'); - var ngrok = require('ngrok'); - var SPACER = '\n****\n\n'; - - var Nexmo = require('../lib/Nexmo'); - var nexmo = new Nexmo({ - apiKey: config.API_KEY, - apiSecret: config.API_SECRET, - applicationId: config.APP_ID, - privateKey: config.PRIVATE_KEY - }, { - debug: config.DEBUG - }); - var calls = Promise.promisifyAll(nexmo.calls); - var stream = Promise.promisifyAll(nexmo.calls.stream); - - function randomPort() { - return Math.floor(Math.random() * (7000 - 3000 + 1) + 3000); - } - - var app = require('express')(); - app.set('port', (process.env.PORT || randomPort())); - app.use(require('body-parser').json()); - - app.get('/', function(req, res) { - res.send('hello'); - }); - - // Handle events - var callId = null; - app.post('/', function(req, res) { - console.log('Request received', req.body); - // Hack: seeing two inbound webhook requests. - // Use callId to indicate this. - if (req.body.status === 'answered' && !callId) { - callId = req.body.uuid; - - console.log('Call answered with call_uuid', callId) - - setTimeout(function() { - sendStream(callId); - }, 5000); - } - - res.sendStatus(204); - }); - - var server = app.listen(app.get('port'), makeCall); - - function makeCall() { - console.log('Web server listening on port', app.get('port')); - - Promise.promisify(ngrok.connect)(app.get('port')) - .then(function(url) { - console.log('ngrok tunnel set up:', url); - - console.log('calling', config.TO_NUMBER); - return calls.createAsync({ - to: [{ - type: 'phone', - number: config.TO_NUMBER - }], - from: { - type: 'phone', - number: config.FROM_NUMBER - }, - answer_url: ['https://nexmo-community.github.io/ncco-examples/conference.json'], - event_url: [url] - }); - }) - .then(function(res) { - console.log('call in progress', res); - }) - .catch(callback); - } - - function sendStream(callId) { - - stream.startAsync( - callId, { - stream_url: [ - 'https://nexmo-community.github.io/ncco-examples/assets/voice_api_audio_streaming.mp3' - ], - loop: 1 - }) - .then(function(resp) { - console.log('stream.start response', resp); - - console.log('waiting a short time'); - return Promise.delay(2000); - }) - .then(function(resp) { - console.log('stopping the stream', resp); - - return nexmo.calls.stream.stopAsync(callId); - }) - .then(function(res) { - console.log('stream.stop res', res); - - console.log('waiting a short time'); - return Promise.delay(2000); - }) - .then(function(res) { - return calls.updateAsync(callId, { - action: 'hangup' - }); - }) - .then(function(res) { - console.log('calls.update', res); - - server.close(); - ngrok.kill(); - - return Promise.delay(2000); - }) - .then(function() { - callback(null, null); - }) - .catch(function(err) { - if (server) server.close(); - if (ngrok) ngrok.kill(); - - callback(err); - }); - } - -}; diff --git a/examples/ex-talk-to-call.js b/examples/ex-talk-to-call.js deleted file mode 100644 index 628df901..00000000 --- a/examples/ex-talk-to-call.js +++ /dev/null @@ -1,123 +0,0 @@ -module.exports = function(callback, config) { - - var Promise = require('bluebird'); - var ngrok = require('ngrok'); - var SPACER = '\n****\n\n'; - - var Nexmo = require('../lib/Nexmo'); - var nexmo = new Nexmo({ - apiKey: config.API_KEY, - apiSecret: config.API_SECRET, - applicationId: config.APP_ID, - privateKey: config.PRIVATE_KEY - }, { - debug: config.DEBUG - }); - var calls = Promise.promisifyAll(nexmo.calls); - var talk = Promise.promisifyAll(nexmo.calls.talk); - - function randomPort() { - return Math.floor(Math.random() * (7000 - 3000 + 1) + 3000); - } - - var app = require('express')(); - app.set('port', (process.env.PORT || randomPort())); - app.use(require('body-parser').json()); - - app.get('/', function(req, res) { - res.send('hello'); - }); - - // Handle events - var callId = null; - app.post('/', function(req, res) { - console.log('Request received', req.body); - // Hack: seeing two inbound webhook requests. - // Use callId to indicate this. - if (req.body.status === 'answered' && !callId) { - callId = req.body.uuid; - - console.log('Call answered with call_uuid', callId) - - setTimeout(function() { - sendTalk(callId); - }, 5000); - } - - res.sendStatus(204); - }); - - var server = app.listen(app.get('port'), makeCall); - - function makeCall() { - console.log('Web server listening on port', app.get('port')); - - Promise.promisify(ngrok.connect)(app.get('port')) - .then(function(url) { - console.log('ngrok tunnel set up:', url); - - console.log('calling', config.TO_NUMBER); - return calls.createAsync({ - to: [{ - type: 'phone', - number: config.TO_NUMBER - }], - from: { - type: 'phone', - number: config.FROM_NUMBER - }, - answer_url: ['https://nexmo-community.github.io/ncco-examples/conference.json'], - event_url: [url] - }); - }) - .then(function(res) { - console.log('call in progress', res); - }) - .catch(callback); - } - - function sendTalk(callId) { - console.log('Sending a talk into the call') - return talk.startAsync(callId, { - text: "Sean... He's on the beach now, a toe in the water. He's asking you to come in with him. He's been racing his mother up and down the sand. There's so much love in this house. He's ten years old. He's surrounded by animals. He wants to be a vet. You keep a rabbit for him, a bird and a fox. He's in high school. He likes to run, like his father.", - voice_name: 'Emma', - loop: 0 - }) - .then(function(resp) { - console.log('talk.start response', resp); - - console.log('waiting a short time'); - return Promise.delay(5000); - }) - .then(function() { - console.log(SPACER, 'Stopping talking'); - - return talk.stopAsync(callId); - }) - .then(function(res) { - console.log('talk.stop res', res); - - return calls.updateAsync(callId, { - action: 'hangup' - }); - }) - .then(function(res) { - console.log('calls.update', res); - - server.close(); - ngrok.kill(); - - return Promise.delay(2000); - }) - .then(function() { - callback(null, null); - }) - .catch(function(err) { - if (server) server.close(); - if (ngrok) ngrok.kill(); - - callback(err); - }); - } - -}; diff --git a/examples/ex-update-v1-application.js b/examples/ex-update-v1-application.js deleted file mode 100644 index 3d7e1767..00000000 --- a/examples/ex-update-v1-application.js +++ /dev/null @@ -1,23 +0,0 @@ -module.exports = function(callback, config) { - - var Nexmo = require('../lib/Nexmo'); - - var nexmo = new Nexmo({ - apiKey: config.API_KEY, - apiSecret: config.API_SECRET - }, { - debug: config.DEBUG - }); - - const name = 'My updated nexmo-node Messages App'; - const type = 'messages'; - const answerUrl = 'https://example.com'; // webhook that points to NCCO - const eventUrl = 'https://example.com'; - - let options = { - inbound_url: 'https://example.com', - status_url: 'https://example.com' - }; - - nexmo.applications.update(config.APP_ID, name, type, answerUrl, eventUrl, options, callback); -}; diff --git a/examples/ex-update-v2-application.js b/examples/ex-update-v2-application.js deleted file mode 100644 index 48db1982..00000000 --- a/examples/ex-update-v2-application.js +++ /dev/null @@ -1,49 +0,0 @@ -module.exports = function(callback, config) { - - var Nexmo = require('../lib/Nexmo'); - - var nexmo = new Nexmo({ - apiKey: config.API_KEY, - apiSecret: config.API_SECRET - }, { - debug: config.DEBUG - }); - - nexmo.applications.update(config.APP_ID, { - name: 'My updated nexmo-node Example V2 App', - capabilities: { - voice: { - webhooks: { - answer_url: { - address: "https://example.com", - http_method: "GET" - }, - event_url: { - address: "https://example.com", - http_method: "POST" - } - } - }, - messages: { - webhooks: { - inbound_url: { - address: "https://example.com", - http_method: "POST" - }, - status_url: { - address: "https://example.com", - http_method: "POST" - } - } - }, - rtc: { - webhooks: { - event_url: { - address: "https://example.com", - http_method: "POST" - } - } - } - } - }, callback); -}; diff --git a/examples/ex-verify-signed-sms-without-instance.js b/examples/ex-verify-signed-sms-without-instance.js deleted file mode 100644 index 744bcf88..00000000 --- a/examples/ex-verify-signed-sms-without-instance.js +++ /dev/null @@ -1,32 +0,0 @@ -module.exports = function(callback, config) { - - var Nexmo = require('../lib/Nexmo'); - - const app = require('express')() - const bodyParser = require('body-parser') - - app.use(bodyParser.json()) - app.use(bodyParser.urlencoded({ extended: true })) - - app - .route('/webhooks/inbound-message') - .get(handleInboundSms) - .post(handleInboundSms) - - function handleInboundSms(request, response) { - const params = Object.assign(request.query, request.body) - - if (Nexmo.generateSignature("md5hash", config.SIGNATURE_SECRET, params) === params.sig) { - console.log("Valid signature"); - } else { - console.log("Invalid signature" - ); - } - console.log(params) - - response.status(204).send() - } - - app.listen(3000) - -}; diff --git a/examples/ex-verify-signed-sms.js b/examples/ex-verify-signed-sms.js deleted file mode 100644 index 4e5c4301..00000000 --- a/examples/ex-verify-signed-sms.js +++ /dev/null @@ -1,40 +0,0 @@ -module.exports = function(callback, config) { - - var Nexmo = require('../lib/Nexmo'); - - var nexmo = new Nexmo({ - apiKey: config.API_KEY, - apiSecret: config.API_SECRET, - signatureSecret: config.SIGNATURE_SECRET, - signatureMethod: "md5hash" - }, { - debug: config.DEBUG - }); - - const app = require('express')() - const bodyParser = require('body-parser') - - app.use(bodyParser.json()) - app.use(bodyParser.urlencoded({ extended: true })) - - app - .route('/webhooks/inbound-message') - .get(handleInboundSms) - .post(handleInboundSms) - - function handleInboundSms(request, response) { - const params = Object.assign(request.query, request.body) - - if (nexmo.generateSignature(params) === params.sig) { - console.log("Valid signature"); - } else { - console.log("Invalid signature"); - } - console.log(params) - - response.status(204).send() - } - - app.listen(3000) - -}; diff --git a/examples/example.env b/examples/example.env deleted file mode 100644 index 4227f16c..00000000 --- a/examples/example.env +++ /dev/null @@ -1,25 +0,0 @@ -API_KEY= -API_SECRET= -SIGNATURE_SECRET= -NEW_API_SECRET= -API_SECRET_ID= -FROM_NUMBER= -TO_NUMBER= -NEXMO_NUMBER= -NEXMO_COUNTRY_CODE= -TO_US_NUMBER= -BRAND_NAME= -REQUEST_ID= -WORKFLOW_ID= -CODE= -APP_ID= -CONVERSATION_ID= -USER_ID= -MEMBER_ID= -EVENT_ID= -SERVICE_MESSAGE_ID= -PRIVATE_KEY=./examples/private.key -DEBUG=true -MEDIA_ID= -REST_HOST= -API_HOST= diff --git a/examples/run-examples.js b/examples/run-examples.js deleted file mode 100644 index d651e0d1..00000000 --- a/examples/run-examples.js +++ /dev/null @@ -1,124 +0,0 @@ -/** - * Run all the examples in the `examples` directory. - */ - -var fs = require('fs'); - -var config = require('./config'); -console.log(config); - -var SPACER = '\n-------------------------------------\n\n'; - -var exampleFiles = fs.readdirSync(__dirname); -// only get the examples files identified by file naming convention -exampleFiles = exampleFiles.filter(function(fileName) { - return fileName.match(/^ex\-.*\.js$/); -}); -var exampleIndex = 0; -var currentExampleFile = null; -var failures = []; - -function runNextExample(err, res) { - if (err) { - console.error('Error running', currentExampleFile, 'Error', err); - failures.push({ - example: currentExampleFile, - error: err - }); - } else if (currentExampleFile) { - console.log('Example complete:', currentExampleFile, 'Result', res); - } - - if (exampleIndex < exampleFiles.length) { - currentExampleFile = exampleFiles[exampleIndex]; - ++exampleIndex; - - console.log(SPACER, exampleIndex + '.', 'Loading', currentExampleFile); - runExample(currentExampleFile, runNextExample); - } else { - console.log(SPACER, 'All examples complete'); - if (failures.length > 0) { - console.error(SPACER, failures.length, 'example(s) provided errors\n\n', failures); - } - } -} - -function runExample(exampleFile, callback) { - var example = require(__dirname + '/' + exampleFile); - - console.log('Starting', exampleFile); - example(callback, config); -} - -// By default all examples are run. -// Use this array to run a select number of examples. -exampleFiles = [ - // 'ex-keyfile-creds.js', - // 'ex-change-api-host.js', - // 'ex-change-rest-host.js', - // 'ex-check-balance.js', - // 'ex-create-update-delete-app.js', - // 'ex-dtmf-to-call.js', - // 'ex-make-call-ncco.js', - // 'ex-send-verification.js', - // 'ex-send-verification-with-workflow.js', - // 'ex-send-psd2-verification.js', - // 'ex-send-psd2-verification-with-workflow.js', - // 'ex-check-verification.js', - // 'ex-control-verification.js', - // 'ex-search-verification.js', - // 'ex-get-apps.js', - // 'ex-get-calls.js', - // 'ex-make-call.js', - // 'ex-number-insight-basic.js', - // 'ex-number-insight-standard.js', - // 'ex-number-insight-advanced-sync.js', - // 'ex-number-insight-advanced-async.js', - // 'ex-send-shortcode-alert.js', - // 'ex-send-shortcode-2fa.js', - // 'ex-send-sms.js', - // 'ex-send-binary-sms.js', - // 'ex-send-wap-message.js', - // 'ex-send-signed-sms.js', - // 'ex-verify-signed-sms.js', - // 'ex-verify-signed-sms-without-instance.js', - // 'ex-send-tts.js', - // 'ex-stream-to-call.js', - // 'ex-talk-to-call.js', - // 'ex-create-secret.js', - // 'ex-get-secret.js', - // 'ex-list-secrets.js', - // 'ex-revoke-secret.js', - // 'ex-create-v1-application.js', - // 'ex-create-v2-application.js', - // 'ex-update-v1-application.js', - // 'ex-update-v2-application.js', - // 'ex-get-v1-application.js', - // 'ex-get-v1-applications.js', - // 'ex-get-v2-application.js', - // 'ex-get-v2-applications.js', - // 'ex-delete-application.js', - // 'ex-get-pricing.js', - // 'ex-get-full-pricing.js', - // 'ex-get-prefix-pricing.js', - // 'ex-get-phone-pricing.js', - // 'ex-get-phone-pricing-number.js', - // 'ex-get-pricing-number.js', - // 'ex-number-get.js', - // 'ex-number-search.js', - // 'ex-number-buy.js', - // 'ex-number-cancel.js', - // 'ex-number-update.js', -]; - -console.log('Found', exampleFiles.length, 'examples to run:\n', exampleFiles); -runNextExample(); - -// Run an individual example -// runExample('ex-send-sms.js', console.log); -// runExample('ex-number-insight-basic.js', console.log); -// runExample('ex-make-call.js', console.log); -// runExample('ex-get-apps.js', console.log); -// runExample('ex-talk-to-call.js', console.log); -// runExample('ex-dtmf-to-call.js', console.log); -// runExample('ex-stream-to-call.js', console.log); From fb786946a073da74929665c6bfbdeedf9fe5ece7 Mon Sep 17 00:00:00 2001 From: Kelly J Andrews Date: Thu, 3 Sep 2020 10:09:38 -0400 Subject: [PATCH 02/12] change nexmo to vonage --- src/CallsResource.js | 2 +- src/Credentials.js | 10 +++++----- src/DtmfResource.js | 2 +- src/FilesResource.js | 2 +- src/HttpClient.js | 4 ++-- src/NumberInsight.js | 2 +- src/StreamResource.js | 2 +- src/TalkResource.js | 2 +- src/{Nexmo.js => Vonage.js} | 26 +++++++++++++------------- test/Account-test.js | 2 +- test/Conversion-test.js | 2 +- test/HttpClient-test.js | 2 +- typings/index.d.ts | 8 ++++---- 13 files changed, 33 insertions(+), 33 deletions(-) rename src/{Nexmo.js => Vonage.js} (88%) diff --git a/src/CallsResource.js b/src/CallsResource.js index d292459f..82297710 100644 --- a/src/CallsResource.js +++ b/src/CallsResource.js @@ -18,7 +18,7 @@ class CallsResource { /** * Creates a new CallsResource. * - * @param {Credentials} creds - Credentials used when interacting with the Nexmo API. + * @param {Credentials} creds - Credentials used when interacting with the VonageAPI. * @param {Object} options - additional options for the class. */ constructor(creds, options) { diff --git a/src/Credentials.js b/src/Credentials.js index 9cb5df0f..09ac266d 100644 --- a/src/Credentials.js +++ b/src/Credentials.js @@ -9,15 +9,15 @@ import HashGenerator from "./HashGenerator"; * However, in time JWT will also be supported. * The `Credentials` object provides an abstraction to this. * - * @param {string} apiKey - A Nexmo API Key - * @param {string} apiSecret - A Nexmo API Secret - * @param {string} [applicationId] - A Nexmo Application ID + * @param {string} apiKey - A VonageAPI Key + * @param {string} apiSecret - A VonageAPI Secret + * @param {string} [applicationId] - A VonageApplication ID * @param {string|Buffer} [privateKey] - When a string value is passed it should * either represent the path to the private key, or the actual * private key in string format. If a Buffer is passed then * it should be the key read from the file system. - * @param {string} [signatureSecret] - A Nexmo signature Secret - * @param {string} [signatureMethod] - A Nexmo compatible request signing method + * @param {string} [signatureSecret] - A Vonagesignature Secret + * @param {string} [signatureMethod] - A Vonagecompatible request signing method */ class Credentials { constructor( diff --git a/src/DtmfResource.js b/src/DtmfResource.js index fb738cec..8af313c4 100644 --- a/src/DtmfResource.js +++ b/src/DtmfResource.js @@ -12,7 +12,7 @@ class DtmfResource { /** * Creates a new DtmfResource. * - * @param {Credentials} creds - Credentials used when interacting with the Nexmo API. + * @param {Credentials} creds - Credentials used when interacting with the VonageAPI. * @param {Object} options - additional options for the class. */ constructor(creds, options) { diff --git a/src/FilesResource.js b/src/FilesResource.js index 383a3dad..2fd29678 100644 --- a/src/FilesResource.js +++ b/src/FilesResource.js @@ -13,7 +13,7 @@ class FilesResource { /** * Creates a new FilesResource. * - * @param {Credentials} creds - Credentials used when interacting with the Nexmo API. + * @param {Credentials} creds - Credentials used when interacting with the VonageAPI. * @param {Object} options - additional options for the class. */ constructor(creds, options) { diff --git a/src/HttpClient.js b/src/HttpClient.js index 670550dc..2762481d 100644 --- a/src/HttpClient.js +++ b/src/HttpClient.js @@ -39,7 +39,7 @@ class HttpClient { if (endpoint.method === "POST" || endpoint.method === "DELETE") { // TODO: verify the following fix is required - // Fix broken due ot 411 Content-Length error now sent by Nexmo API + // Fix broken due ot 411 Content-Length error now sent by VonageAPI // PL 2016-Sept-6 - commented out Content-Length 0 // headers['Content-Length'] = 0; } @@ -246,7 +246,7 @@ class HttpClient { return function(err, data) { if (err && err.status == limitedAccessStatus) { err._INFO_ = - "This endpoint may need activating on your account. Please email support@nexmo.com for more information"; + "This endpoint may need activating on your account. Please email support@vonage.com for more information"; } return callback(err, data); diff --git a/src/NumberInsight.js b/src/NumberInsight.js index 30422cd6..13404d32 100644 --- a/src/NumberInsight.js +++ b/src/NumberInsight.js @@ -70,7 +70,7 @@ class NumberInsight { * Insight Return Parameters. This may be useful for your * internal reports. * @param {string} options['include-intermediate-callbacks'] - 'advanced' only. - * Tells the Nexmo platform to make callbacks as soon as an + * Tells the Vonageplatform to make callbacks as soon as an * individual piece of information is retrieved. */ get(options, callback) { diff --git a/src/StreamResource.js b/src/StreamResource.js index ca7fbd4d..a8b25f13 100644 --- a/src/StreamResource.js +++ b/src/StreamResource.js @@ -12,7 +12,7 @@ class StreamResource { /** * Creates a new StreamResource. * - * @param {Credentials} creds - Credentials used when interacting with the Nexmo API. + * @param {Credentials} creds - Credentials used when interacting with the VonageAPI. * @param {Object} options - additional options for the class. */ constructor(creds, options) { diff --git a/src/TalkResource.js b/src/TalkResource.js index 40d50c3b..63989578 100644 --- a/src/TalkResource.js +++ b/src/TalkResource.js @@ -12,7 +12,7 @@ class TalkResource { /** * Creates a new TalkResource. * - * @param {Credentials} creds - Credentials used when interacting with the Nexmo API. + * @param {Credentials} creds - Credentials used when interacting with the VonageAPI. * @param {Object} options - additional options for the class. */ constructor(creds, options) { diff --git a/src/Nexmo.js b/src/Vonage.js similarity index 88% rename from src/Nexmo.js rename to src/Vonage.js index 6cbd32bc..9493afb7 100644 --- a/src/Nexmo.js +++ b/src/Vonage.js @@ -24,11 +24,11 @@ import ConsoleLogger from "./ConsoleLogger"; const jwtGeneratorInstance = new JwtGenerator(); const hashGeneratorInstance = new HashGenerator(); -class Nexmo { +class Vonage { /** - * @param {Credentials} credentials - Nexmo API credentials - * @param {string} credentials.apiKey - the Nexmo API key - * @param {string} credentials.apiSecret - the Nexmo API secret + * @param {Credentials} credentials - Vonage API credentials + * @param {string} credentials.apiKey - the Vonage API key + * @param {string} credentials.apiSecret - the Vonage API secret * @param {Object} options - Additional options * @param {boolean} options.debug - `true` to turn on debug logging * @param {Object} options.logger - Set a custom logger. @@ -48,10 +48,10 @@ class Nexmo { this.options.logger = new NullLogger(); } - let userAgent = "nexmo-node/UNKNOWN node/UNKNOWN"; + let userAgent = "vonage-node/UNKNOWN node/UNKNOWN"; try { var packageDetails = require(path.join(__dirname, "..", "package.json")); - userAgent = `nexmo-node/${ + userAgent = `vonage-node/${ packageDetails.version } node/${process.version.replace("v", "")}`; } catch (e) { @@ -102,7 +102,7 @@ class Nexmo { this.pricing = new Pricing(this.credentials, this.options); /** - * @deprecated Please use nexmo.applications + * @deprecated Please use vonage.applications */ this.app = this.applications; } @@ -110,8 +110,8 @@ class Nexmo { /** * Generate a JSON Web Token (JWT). * - * The private key used upon Nexmo instance construction will be used to sign - * the JWT. The application_id you used upon Nexmo instance creation will be + * The private key used upon Vonage instance construction will be used to sign + * the JWT. The application_id you used upon Vonage instance creation will be * included in the claims for the JWT, however this can be overridden by passing * an application_id as part of the claims. * @@ -124,7 +124,7 @@ class Nexmo { if (claims.application_id === undefined) { claims.application_id = this.credentials.applicationId; } - return Nexmo.generateJwt(this.credentials.privateKey, claims); + return Vonage.generateJwt(this.credentials.privateKey, claims); } /** @@ -148,7 +148,7 @@ class Nexmo { * * @returns {String} the generated token */ -Nexmo.generateJwt = (privateKey, claims) => { +Vonage.generateJwt = (privateKey, claims) => { if (!(privateKey instanceof Buffer)) { if (!fs.existsSync(privateKey)) { throw new Error(`File "${privateKey}" not found.`); @@ -168,8 +168,8 @@ Nexmo.generateJwt = (privateKey, claims) => { * * @returns {String} the generated token */ -Nexmo.generateSignature = (method, secret, params) => { +Vonage.generateSignature = (method, secret, params) => { return hashGeneratorInstance.generate(method, secret, params); }; -export default Nexmo; +export default Vonage; diff --git a/test/Account-test.js b/test/Account-test.js index c0fac477..871abba2 100644 --- a/test/Account-test.js +++ b/test/Account-test.js @@ -1,5 +1,5 @@ import Account from "../lib/Account"; -import { expect, sinon, TestUtils } from "./NexmoTestUtils"; +import { expect, sinon, TestUtils } from "./VonageTestUtils"; describe("Account", function() { beforeEach(function() { diff --git a/test/Conversion-test.js b/test/Conversion-test.js index ea940bd9..c68b5b26 100644 --- a/test/Conversion-test.js +++ b/test/Conversion-test.js @@ -64,7 +64,7 @@ describe("Conversion", function() { this.httpClientStub.request.yields(mockError, null); this.conversion.sms("1234", 1, 1234567890, function(err, data) { expect(err._INFO_).to.eql( - "This endpoint may need activating on your account. Please email support@nexmo.com for more information" + "This endpoint may need activating on your account. Please email support@vonage.com for more information" ); expect(data).to.eql(null); done(); diff --git a/test/HttpClient-test.js b/test/HttpClient-test.js index 8fa82d24..00123e44 100644 --- a/test/HttpClient-test.js +++ b/test/HttpClient-test.js @@ -414,7 +414,7 @@ describe("HttpClient Object", function() { }); it("should allow User-Agent header to be set via options", function() { - var expectedUserAgent = "nexmo-node/1.0.0/v4.4.7"; + var expectedUserAgent = "vonage-node/1.0.0/v4.4.7"; var mock = sinon.mock(fakeHttp); mock diff --git a/typings/index.d.ts b/typings/index.d.ts index 666434aa..d4093414 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -10,7 +10,7 @@ * CheckResponse -> VerifyCheckResponse */ -declare module 'nexmo' { +declare module 'vonage' { /* general */ export interface CredentialsObject { apiKey: string; @@ -125,7 +125,7 @@ declare module 'nexmo' { } /* verify API */ - export interface VerifyError extends NexmoApiError { + export interface VerifyError extends VonageApiError { status: RequestResponseStatusCode | ControlResponseStatusCode | string; error_text: string; [key: string]: any; @@ -206,8 +206,8 @@ declare module 'nexmo' { } - /* Nexmo */ - export default class Nexmo { + /* Vonage */ + export default class Vonage { constructor(credentials: CredentialsObject, options?: { [key: string]: any }); public readonly verify: Verify; public readonly message: Message; From 6e437e1ee47fc6d96cce83af8aaa097839f034dd Mon Sep 17 00:00:00 2001 From: Kelly J Andrews Date: Thu, 3 Sep 2020 10:10:01 -0400 Subject: [PATCH 03/12] modify tests to support vonage namespace --- test/Media-test.js | 2 +- test/Number-pricing-test.js | 2 +- test/Pricing-test.js | 2 +- test/Redact-test.js | 2 +- test/{Nexmo-test.js => Vonage-test.js} | 118 +++++++++--------- test/{NexmoChai.js => VonageChai.js} | 0 .../{NexmoTestUtils.js => VonageTestUtils.js} | 4 +- 7 files changed, 65 insertions(+), 65 deletions(-) rename test/{Nexmo-test.js => Vonage-test.js} (66%) rename test/{NexmoChai.js => VonageChai.js} (100%) rename test/{NexmoTestUtils.js => VonageTestUtils.js} (92%) diff --git a/test/Media-test.js b/test/Media-test.js index 89bc4d39..70853fa5 100644 --- a/test/Media-test.js +++ b/test/Media-test.js @@ -1,6 +1,6 @@ import Media from "../lib/Media"; import os from "os"; -import { expect, sinon, TestUtils } from "./NexmoTestUtils"; +import { expect, sinon, TestUtils } from "./VonageTestUtils"; describe("Media", function() { beforeEach(function() { diff --git a/test/Number-pricing-test.js b/test/Number-pricing-test.js index 23bba946..d735a6e7 100644 --- a/test/Number-pricing-test.js +++ b/test/Number-pricing-test.js @@ -1,6 +1,6 @@ import Number from "../lib/Number"; -import { expect, sinon, TestUtils } from "./NexmoTestUtils"; +import { expect, sinon, TestUtils } from "./VonageTestUtils"; describe("Number _pricing", function() { beforeEach(function() { diff --git a/test/Pricing-test.js b/test/Pricing-test.js index 136e631d..4462fa1a 100644 --- a/test/Pricing-test.js +++ b/test/Pricing-test.js @@ -1,5 +1,5 @@ import Pricing from "../lib/Pricing"; -import { expect, sinon, TestUtils } from "./NexmoTestUtils"; +import { expect, sinon, TestUtils } from "./VonageTestUtils"; // describe("Pricing", function() { diff --git a/test/Redact-test.js b/test/Redact-test.js index 3325b8f5..5ebd0d80 100644 --- a/test/Redact-test.js +++ b/test/Redact-test.js @@ -1,5 +1,5 @@ import Redact from "../lib/Redact"; -import { expect, sinon, TestUtils } from "./NexmoTestUtils"; +import { expect, sinon, TestUtils } from "./VonageTestUtils"; describe("Redact", function() { beforeEach(function() { diff --git a/test/Nexmo-test.js b/test/Vonage-test.js similarity index 66% rename from test/Nexmo-test.js rename to test/Vonage-test.js index 617e422b..38d3311b 100644 --- a/test/Nexmo-test.js +++ b/test/Vonage-test.js @@ -4,26 +4,26 @@ import sinonChai from "sinon-chai"; import path from "path"; import fs from "fs"; -import Nexmo from "../lib/Nexmo"; +import Vonage from "../lib/Vonage"; import CallsResource from "../lib/CallsResource"; chai.use(sinonChai); -describe("Nexmo definition", () => { +describe("Vonage definition", () => { describe(".generateJwt", () => { it("should expose a generateJwt function", () => { - expect(Nexmo.generateJwt).to.be.a("function"); + expect(Vonage.generateJwt).to.be.a("function"); }); it("should throw an exception if privateKey file does not exist", () => { var create = function() { - Nexmo.generateJwt("./no-key-here.key"); + Vonage.generateJwt("./no-key-here.key"); }; expect(create).to.throw(Error); }); it("should create a JWT with a private key (file path) [static]", () => { - var token = Nexmo.generateJwt(path.join(__dirname, "private-test.key")); + var token = Vonage.generateJwt(path.join(__dirname, "private-test.key")); expect(token).to.be.a("string"); }); @@ -31,118 +31,118 @@ describe("Nexmo definition", () => { var fileBuffer = fs.readFileSync( path.join(__dirname, "private-test.key") ); - var token = Nexmo.generateJwt(fileBuffer); + var token = Vonage.generateJwt(fileBuffer); expect(token).to.be.a("string"); }); }); describe(".generateSignature", () => { it("should expose a generateSignature function", () => { - expect(Nexmo.generateSignature).to.be.a("function"); + expect(Vonage.generateSignature).to.be.a("function"); }); it("should create a hash", () => { - var hash = Nexmo.generateSignature("md5hash", "secret", {}); + var hash = Vonage.generateSignature("md5hash", "secret", {}); expect(hash).to.be.a("string"); }); }); }); -describe("Nexmo Object instance", function() { +describe("Vonage Object instance", function() { it("should expose a credentials object", function() { - var nexmo = new Nexmo({ + var vonage = new Vonage({ apiKey: "test", apiSecret: "test" }); - expect(nexmo.credentials).to.be.a("object"); + expect(vonage.credentials).to.be.a("object"); }); it("should expose a message object", function() { - var nexmo = new Nexmo({ + var vonage = new Vonage({ apiKey: "test", apiSecret: "test" }); - expect(nexmo.message).to.be.a("object"); + expect(vonage.message).to.be.a("object"); }); it("should expose a voice object", function() { - var nexmo = new Nexmo({ + var vonage = new Vonage({ apiKey: "test", apiSecret: "test" }); - expect(nexmo.voice).to.be.a("object"); + expect(vonage.voice).to.be.a("object"); }); it("should expose a number object", function() { - var nexmo = new Nexmo({ + var vonage = new Vonage({ apiKey: "test", apiSecret: "test" }); - expect(nexmo.number).to.be.a("object"); + expect(vonage.number).to.be.a("object"); }); it("should expose a verify object", function() { - var nexmo = new Nexmo({ + var vonage = new Vonage({ apiKey: "test", apiSecret: "test" }); - expect(nexmo.verify).to.be.a("object"); + expect(vonage.verify).to.be.a("object"); }); it("should expose a numberInsight object", function() { - var nexmo = new Nexmo({ + var vonage = new Vonage({ apiKey: "test", apiSecret: "test" }); - expect(nexmo.numberInsight).to.be.a("object"); + expect(vonage.numberInsight).to.be.a("object"); }); it("should expose a app object", function() { - var nexmo = new Nexmo({ + var vonage = new Vonage({ apiKey: "test", apiSecret: "test" }); - expect(nexmo.app).to.be.a("object"); + expect(vonage.app).to.be.a("object"); }); it("should expose a applications object", function() { - var nexmo = new Nexmo({ + var vonage = new Vonage({ apiKey: "test", apiSecret: "test" }); - expect(nexmo.applications).to.be.a("object"); + expect(vonage.applications).to.be.a("object"); }); it("should alias apps to applications object", function() { - var nexmo = new Nexmo({ + var vonage = new Vonage({ apiKey: "test", apiSecret: "test" }); - expect(nexmo.applications).to.equal(nexmo.app); + expect(vonage.applications).to.equal(vonage.app); }); it("should expose a account object", function() { - var nexmo = new Nexmo({ + var vonage = new Vonage({ apiKey: "test", apiSecret: "test" }); - expect(nexmo.account).to.be.a("object"); + expect(vonage.account).to.be.a("object"); }); it("should expose a calls object", function() { - var nexmo = new Nexmo({ + var vonage = new Vonage({ apiKey: "test", apiSecret: "test" }); - expect(nexmo.calls).to.be.an.instanceOf(CallsResource); + expect(vonage.calls).to.be.an.instanceOf(CallsResource); }); it("should expose a files object", function() { - var nexmo = new Nexmo({ + var vonage = new Vonage({ apiKey: "test", apiSecret: "test" }); - expect(nexmo.files).to.be.a("object"); + expect(vonage.files).to.be.a("object"); }); it("should allow options to be passed and remain unchanged", function() { @@ -153,7 +153,7 @@ describe("Nexmo Object instance", function() { let passedOptions = Object.assign({}, localOptions); - let nexmo = new Nexmo( + let vonage = new Vonage( { apiKey: "test", apiSecret: "test" @@ -162,15 +162,15 @@ describe("Nexmo Object instance", function() { ); expect(localOptions).to.eql(passedOptions); - expect(nexmo.options.userAgent).to.match(/.*EXT/); + expect(vonage.options.userAgent).to.match(/.*EXT/); }); it("should have debug turned off by default", function() { - var nexmo = new Nexmo({ + var vonage = new Vonage({ apiKey: "test", apiSecret: "test" }); - expect(nexmo.options.debug).to.be.false; + expect(vonage.options.debug).to.be.false; }); it("should allow a custom logger to be set", function() { @@ -179,7 +179,7 @@ describe("Nexmo Object instance", function() { error: function() {}, warn: function() {} }; - var nexmo = new Nexmo( + var vonage = new Vonage( { apiKey: "test", apiSecret: "test" @@ -188,11 +188,11 @@ describe("Nexmo Object instance", function() { logger: logger } ); - expect(nexmo.options.logger).to.equal(logger); + expect(vonage.options.logger).to.equal(logger); }); it("should allow a debug option to be set", function() { - var nexmo = new Nexmo( + var vonage = new Vonage( { apiKey: "test", apiSecret: "test" @@ -201,32 +201,32 @@ describe("Nexmo Object instance", function() { debug: true } ); - expect(nexmo.options.debug).to.be.true; + expect(vonage.options.debug).to.be.true; }); it("should have a default user agent in the form LIBRARY-NAME/LIBRARY-VERSION/LANGUAGE-VERSION", function() { - var nexmo = new Nexmo({ + var vonage = new Vonage({ apiKey: "test", apiSecret: "test" }); - expect(nexmo.options.userAgent).to.match( - /^nexmo-node\/[\d|\w\-\d.]* node\/[\d.]*$/ + expect(vonage.options.userAgent).to.match( + /^vonage-node\/[\d|\w\-\d.]* node\/[\d.]*$/ ); }); it("should append to the user agent when a appendToUserAgent option is passed", function() { var options = { - appendToUserAgent: "nexmo-cli/1.0.0" + appendToUserAgent: "vonage-cli/1.0.0" }; - var nexmo = new Nexmo( + var vonage = new Vonage( { apiKey: "test", apiSecret: "test" }, options ); - expect(nexmo.options.userAgent).to.match( - /nexmo-node\/[\d|\w\-\d.]* node\/[\d.]* nexmo-cli\/1\.0\.0/ + expect(vonage.options.userAgent).to.match( + /vonage-node\/[\d|\w\-\d.]* node\/[\d.]* vonage-cli\/1\.0\.0/ ); }); @@ -234,49 +234,49 @@ describe("Nexmo Object instance", function() { var options = { apiHost: "some.host.com" }; - var nexmo = new Nexmo( + var vonage = new Vonage( { apiKey: "test", apiSecret: "test" }, options ); - expect(nexmo.options.apiHost).to.equal("some.host.com"); + expect(vonage.options.apiHost).to.equal("some.host.com"); }); it("should allow rest host change", function() { var options = { restHost: "some.host.com" }; - var nexmo = new Nexmo( + var vonage = new Vonage( { apiKey: "test", apiSecret: "test" }, options ); - expect(nexmo.options.restHost).to.equal("some.host.com"); + expect(vonage.options.restHost).to.equal("some.host.com"); }); it("should create a JWT", () => { - var nexmo = new Nexmo({ + var vonage = new Vonage({ apiKey: "test", apiSecret: "test", privateKey: path.join(__dirname, "private-test.key"), application_id: "app-id" }); - var token = nexmo.generateJwt(); + var token = vonage.generateJwt(); expect(token).to.be.a("string"); }); it("should create a hash", () => { - var nexmo = new Nexmo({ + var vonage = new Vonage({ apiKey: "test", apiSecret: "test", signatureSecret: "secret", signatureMethod: "md5hash" }); - var hash = nexmo.generateSignature({}); + var hash = vonage.generateSignature({}); expect(hash).to.be.a("string"); }); @@ -286,19 +286,19 @@ describe("Nexmo Object instance", function() { var appId = "app_id"; var privateKey = path.join(__dirname, "private-test.key"); - var expectedJwt = Nexmo.generateJwt(privateKey, { + var expectedJwt = Vonage.generateJwt(privateKey, { application_id: appId, iat: iat, jti: jti }); - var nexmo = new Nexmo({ + var vonage = new Vonage({ apiKey: "test", apiSecret: "test", privateKey: privateKey, applicationId: appId }); - var token = nexmo.generateJwt({ iat: iat, jti: jti }); + var token = vonage.generateJwt({ iat: iat, jti: jti }); expect(token).to.equal(expectedJwt); }); }); diff --git a/test/NexmoChai.js b/test/VonageChai.js similarity index 100% rename from test/NexmoChai.js rename to test/VonageChai.js diff --git a/test/NexmoTestUtils.js b/test/VonageTestUtils.js similarity index 92% rename from test/NexmoTestUtils.js rename to test/VonageTestUtils.js index 4d1f1864..d50ba4a9 100644 --- a/test/NexmoTestUtils.js +++ b/test/VonageTestUtils.js @@ -5,9 +5,9 @@ import NullLogger from "../lib/ConsoleLogger.js"; import sinon from "sinon"; import chai, { expect } from "chai"; import sinonChai from "sinon-chai"; -import nexmoChai from "./NexmoChai"; +import vonageChai from "./VonageChai"; chai.use(sinonChai); -chai.use(nexmoChai); +chai.use(vonageChai); const TestUtils = { getCredentials: function() { From fbd8b46e7832a69253a97060ce01907c2935e5dd Mon Sep 17 00:00:00 2001 From: Kelly J Andrews Date: Thu, 3 Sep 2020 12:47:17 -0400 Subject: [PATCH 04/12] remove travis dep --- .travis.yml | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 391c9df5..00000000 --- a/.travis.yml +++ /dev/null @@ -1,18 +0,0 @@ -os: - - windows - - linux - - osx -language: node_js -node_js: - - 8 - - 10 - - 11 - - 12 -install: - - npm install -g codecov - - npm install -script: - - npm run report-coverage - - codecov - - npm run compile - - node -e "const n = require('.'); new n({});" From 23957af902d6e76a7d1b999318e3027d3599674b Mon Sep 17 00:00:00 2001 From: Kelly J Andrews Date: Thu, 3 Sep 2020 12:47:36 -0400 Subject: [PATCH 05/12] modify user agent --- src/Vonage.js | 4 ++-- test/Vonage-test.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Vonage.js b/src/Vonage.js index 9493afb7..001c7d8b 100644 --- a/src/Vonage.js +++ b/src/Vonage.js @@ -48,10 +48,10 @@ class Vonage { this.options.logger = new NullLogger(); } - let userAgent = "vonage-node/UNKNOWN node/UNKNOWN"; + let userAgent = "@vonage/server-sdk/UNKNOWN node/UNKNOWN"; try { var packageDetails = require(path.join(__dirname, "..", "package.json")); - userAgent = `vonage-node/${ + userAgent = `@vonage/server-sdk/${ packageDetails.version } node/${process.version.replace("v", "")}`; } catch (e) { diff --git a/test/Vonage-test.js b/test/Vonage-test.js index 38d3311b..e211a8a9 100644 --- a/test/Vonage-test.js +++ b/test/Vonage-test.js @@ -210,7 +210,7 @@ describe("Vonage Object instance", function() { apiSecret: "test" }); expect(vonage.options.userAgent).to.match( - /^vonage-node\/[\d|\w\-\d.]* node\/[\d.]*$/ + /^@vonage\/server-sdk\/[\d|\w\-\d.]* node\/[\d.]*$/ ); }); @@ -226,7 +226,7 @@ describe("Vonage Object instance", function() { options ); expect(vonage.options.userAgent).to.match( - /vonage-node\/[\d|\w\-\d.]* node\/[\d.]* vonage-cli\/1\.0\.0/ + /@vonage\/server-sdk\/[\d|\w\-\d.]* node\/[\d.]* vonage-cli\/1\.0\.0/ ); }); From 873ba504903e76bd99b479a1728b8d136df41f6a Mon Sep 17 00:00:00 2001 From: Kelly J Andrews Date: Thu, 3 Sep 2020 13:02:51 -0400 Subject: [PATCH 06/12] Finishing changes for vonage change over --- CODE_OF_CONDUCT.md | 2 +- CONTRIBUTING.md | 22 +- LICENSE.txt | 213 ++++++++++-- README.md | 844 +++------------------------------------------ package.json | 17 +- 5 files changed, 262 insertions(+), 836 deletions(-) diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index 1c814957..fcbcf40e 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -40,7 +40,7 @@ This Code of Conduct applies within all community spaces, and also applies when ## Enforcement -Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at [devrel@nexmo.com](mailto:devrel@nexmo.com). All complaints will be reviewed and investigated promptly and fairly. +Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at [devrel@vonage.com](mailto:devrel@vonage.com). All complaints will be reviewed and investigated promptly and fairly. All community leaders are obligated to respect the privacy and security of the reporter of any incident. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ade38c63..f69cf692 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -16,14 +16,14 @@ When you're ready to start coding, fork this repository to your own GitHub accou To run the code for an open PR, follow these steps: -1. `git clone https://github.com/Nexmo/nexmo-node.git` -2. `cd nexmo-node` -3. `git checkout BRANCH_NAME` -4. `npm install` -5. `npm compile` -6. Uncomment the appropriate line in `examples/run-examples.js` for each example you want to run. -7. In the `examples` folder, copy `example.env` to `.env`. -8. Update `.env` with your API key and API secret. -9. `node examples/run-examples.js` - -When reviewing PRs, and switching branches to compare running examples against feature branches, don't forget to run `npm compile` after switching branches. Because examples run from the `lib/` folder, and that folder is ignored by Git, you'll need to re-compile the source every time you switch a branch. +1. `git clone https://github.com/vonage/vonage-node-sdk.git` +1. `cd vonage-node-sdk` +1. `git checkout BRANCH_NAME` +1. `npm install` +1. `npm compile` +1. Download the `https://github.com/Vonage/vonage-node-code-snippets` repository +1. Install the local Vonage package `npm i /path/to/vonage-node-sdk` +1. Copy `.env-example` to `.env` and update any variables required. +1. Run the sample code snippet to test the SDK. + +When reviewing PRs, and switching branches to compare running examples against feature branches, don't forget to run `npm compile` after switching branches. diff --git a/LICENSE.txt b/LICENSE.txt index 43eaa12d..3171a8fe 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,25 +1,190 @@ +Apache License +Version 2.0, January 2004 +http://www.apache.org/licenses/ -The MIT License (MIT) - -Copyright (c) 2018 Nexmo Inc - -Permission is hereby granted, free of charge, to any person -obtaining a copy of this software and associated documentation -files (the "Software"), to deal in the Software without -restriction, including without limitation the rights to use, -copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the -Software is furnished to do so, subject to the following -conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -OTHER DEALINGS IN THE SOFTWARE. +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + +"License" shall mean the terms and conditions for use, reproduction, +and distribution as defined by Sections 1 through 9 of this document. + +"Licensor" shall mean the copyright owner or entity authorized by +the copyright owner that is granting the License. + +"Legal Entity" shall mean the union of the acting entity and all +other entities that control, are controlled by, or are under common +control with that entity. For the purposes of this definition, +"control" means (i) the power, direct or indirect, to cause the +direction or management of such entity, whether by contract or +otherwise, or (ii) ownership of fifty percent (50%) or more of the +outstanding shares, or (iii) beneficial ownership of such entity. + +"You" (or "Your") shall mean an individual or Legal Entity +exercising permissions granted by this License. + +"Source" form shall mean the preferred form for making modifications, +including but not limited to software source code, documentation +source, and configuration files. + +"Object" form shall mean any form resulting from mechanical +transformation or translation of a Source form, including but +not limited to compiled object code, generated documentation, +and conversions to other media types. + +"Work" shall mean the work of authorship, whether in Source or +Object form, made available under the License, as indicated by a +copyright notice that is included in or attached to the work +(an example is provided in the Appendix below). + +"Derivative Works" shall mean any work, whether in Source or Object +form, that is based on (or derived from) the Work and for which the +editorial revisions, annotations, elaborations, or other modifications +represent, as a whole, an original work of authorship. For the purposes +of this License, Derivative Works shall not include works that remain +separable from, or merely link (or bind by name) to the interfaces of, +the Work and Derivative Works thereof. + +"Contribution" shall mean any work of authorship, including +the original version of the Work and any modifications or additions +to that Work or Derivative Works thereof, that is intentionally +submitted to Licensor for inclusion in the Work by the copyright owner +or by an individual or Legal Entity authorized to submit on behalf of +the copyright owner. For the purposes of this definition, "submitted" +means any form of electronic, verbal, or written communication sent +to the Licensor or its representatives, including but not limited to +communication on electronic mailing lists, source code control systems, +and issue tracking systems that are managed by, or on behalf of, the +Licensor for the purpose of discussing and improving the Work, but +excluding communication that is conspicuously marked or otherwise +designated in writing by the copyright owner as "Not a Contribution." + +"Contributor" shall mean Licensor and any individual or Legal Entity +on behalf of whom a Contribution has been received by Licensor and +subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of +this License, each Contributor hereby grants to You a perpetual, +worldwide, non-exclusive, no-charge, royalty-free, irrevocable +copyright license to reproduce, prepare Derivative Works of, +publicly display, publicly perform, sublicense, and distribute the +Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of +this License, each Contributor hereby grants to You a perpetual, +worldwide, non-exclusive, no-charge, royalty-free, irrevocable +(except as stated in this section) patent license to make, have made, +use, offer to sell, sell, import, and otherwise transfer the Work, +where such license applies only to those patent claims licensable +by such Contributor that are necessarily infringed by their +Contribution(s) alone or by combination of their Contribution(s) +with the Work to which such Contribution(s) was submitted. If You +institute patent litigation against any entity (including a +cross-claim or counterclaim in a lawsuit) alleging that the Work +or a Contribution incorporated within the Work constitutes direct +or contributory patent infringement, then any patent licenses +granted to You under this License for that Work shall terminate +as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the +Work or Derivative Works thereof in any medium, with or without +modifications, and in Source or Object form, provided that You +meet the following conditions: + +(a) You must give any other recipients of the Work or +Derivative Works a copy of this License; and + +(b) You must cause any modified files to carry prominent notices +stating that You changed the files; and + +(c) You must retain, in the Source form of any Derivative Works +that You distribute, all copyright, patent, trademark, and +attribution notices from the Source form of the Work, +excluding those notices that do not pertain to any part of +the Derivative Works; and + +(d) If the Work includes a "NOTICE" text file as part of its +distribution, then any Derivative Works that You distribute must +include a readable copy of the attribution notices contained +within such NOTICE file, excluding those notices that do not +pertain to any part of the Derivative Works, in at least one +of the following places: within a NOTICE text file distributed +as part of the Derivative Works; within the Source form or +documentation, if provided along with the Derivative Works; or, +within a display generated by the Derivative Works, if and +wherever such third-party notices normally appear. The contents +of the NOTICE file are for informational purposes only and +do not modify the License. You may add Your own attribution +notices within Derivative Works that You distribute, alongside +or as an addendum to the NOTICE text from the Work, provided +that such additional attribution notices cannot be construed +as modifying the License. + +You may add Your own copyright statement to Your modifications and +may provide additional or different license terms and conditions +for use, reproduction, or distribution of Your modifications, or +for any such Derivative Works as a whole, provided Your use, +reproduction, and distribution of the Work otherwise complies with +the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, +any Contribution intentionally submitted for inclusion in the Work +by You to the Licensor shall be under the terms and conditions of +this License, without any additional terms or conditions. +Notwithstanding the above, nothing herein shall supersede or modify +the terms of any separate license agreement you may have executed +with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade +names, trademarks, service marks, or product names of the Licensor, +except as required for reasonable and customary use in describing the +origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or +agreed to in writing, Licensor provides the Work (and each +Contributor provides its Contributions) on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +implied, including, without limitation, any warranties or conditions +of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A +PARTICULAR PURPOSE. You are solely responsible for determining the +appropriateness of using or redistributing the Work and assume any +risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, +whether in tort (including negligence), contract, or otherwise, +unless required by applicable law (such as deliberate and grossly +negligent acts) or agreed to in writing, shall any Contributor be +liable to You for damages, including any direct, indirect, special, +incidental, or consequential damages of any character arising as a +result of this License or out of the use or inability to use the +Work (including but not limited to damages for loss of goodwill, +work stoppage, computer failure or malfunction, or any and all +other commercial damages or losses), even if such Contributor +has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing +the Work or Derivative Works thereof, You may choose to offer, +and charge a fee for, acceptance of support, warranty, indemnity, +or other liability obligations and/or rights consistent with this +License. However, in accepting such obligations, You may act only +on Your own behalf and on Your sole responsibility, not on behalf +of any other Contributor, and only if You agree to indemnify, +defend, and hold each Contributor harmless for any liability +incurred by, or claims asserted against, such Contributor by reason +of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +Copyright (c) 2020 Vonage + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/README.md b/README.md index 01999dfd..1511b21b 100644 --- a/README.md +++ b/README.md @@ -1,31 +1,34 @@ -# Nexmo Client Library for Node.js -[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-v2.0%20adopted-ff69b4.svg)](CODE_OF_CONDUCT.md) -[![build status](https://secure.travis-ci.org/Nexmo/nexmo-node.png)](http://travis-ci.org/Nexmo/nexmo-node) -[![Known Vulnerabilities](https://snyk.io/test/github/Nexmo/nexmo-node/badge.svg)](https://snyk.io/test/github/Nexmo/nexmo-node) -[![codecov](https://codecov.io/gh/Nexmo/nexmo-node/branch/master/graph/badge.svg)](https://codecov.io/gh/Nexmo/nexmo-node) +# Vonage Server SDK for Node.js -Nexmo is now known as Vonage +![GitHub Workflow Status (branch)](https://img.shields.io/github/workflow/status/vonage/vonage-node-sdk/Vonage/master?logo=github&style=flat-square&label=Workflow%20Build) [![Codecov](https://img.shields.io/codecov/c/github/vonage/vonage-node-sdk?label=Codecov&logo=codecov&style=flat-square)](https://codecov.io/gh/Vonage/vonage-server-sdk) ![Latest Release](https://img.shields.io/github/v/release/vonage/vonage-node-sdk?logo=npm&style=flat-square) -A Node.JS REST API Wrapper library for [Nexmo](https://www.nexmo.com/). +[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-v2.0%20adopted-ff69b4.svg?style=flat-square)](CODE_OF_CONDUCT.md) [![Apache 2.0 License](https://img.shields.io/npm/l/@vonage/server-sdk?label=Apache%202.0&style=flat-square)][license] -For full API documentation refer to [developer.nexmo.com](https://developer.nexmo.com/). +Vonage + +This is the Node.JS Server SDK for [Vonage APIs](https://www.vonage.com/). To use it you will need a Vonage account. Sign up [for free at vonage.com][signup]. -[![NPM](https://nodei.co/npm/nexmo.png)](https://nodei.co/npm/nexmo/) +For full API documentation refer to [developer.nexmo.com](https://developer.nexmo.com/). -[Installation](#installation) | [Constructor](#constructor) | [Callbacks](#callbacks) | [Messaging](#messaging) | [Message Signing](#signature) | [Voice](#voice) | [Verify](#verify) | [Number Insight](#number-insight) | [Applications](#applications) | [Management](#management) | [Redact](#redact) | [Pricing](#pricing) | [JWT (JSON Web Token)](#jwt) +* [Installation](#installation) +* [Constructor](#constructor) +* [Callbacks](#callbacks) +* [Testing](#testing) +* [Examples](#examples) +* [Supported APIs](#supported-apis) ## Installation ```bash -npm install nexmo +npm install @vonage/server-sdk ``` ## Constructor ```js -const Nexmo = require('nexmo'); +const Vonage = require('@vonage/server-sdk'); -const nexmo = new Nexmo({ +const vonage = new Vonage({ apiKey: API_KEY, apiSecret: API_SECRET, applicationId: APP_ID, @@ -35,14 +38,15 @@ const nexmo = new Nexmo({ }, options); ``` -* `apiKey` - API Key from Nexmo. If `applicationId` and `privateKey` are present, `apiKey` is optional. -* `apiSecret` - API SECRET from Nexmo. If `applicationId` and `privateKey` are present, `apiSecret` is optional. -* `applicationId` - (optional) The Nexmo Application ID to be used when creating JWTs. +* `apiKey` - API Key from Vonage API. If `applicationId` and `privateKey` are present, `apiKey` is optional. +* `apiSecret` - API SECRET from Vonage API. If `applicationId` and `privateKey` are present, `apiSecret` is optional. +* `applicationId` - (optional) The Vonage API Application ID to be used when creating JWTs. * `privateKey` - (optional) The Private Key to be used when creating JWTs. You can specify the key as any of the following: - * A [Buffer](https://nodejs.org/api/buffer.html#buffer_class_method_buffer_from_string_encoding) containing the file contents. - * A String containing the path to the key file on disk. -* `signatureSecret` - (optional) API singature secret from Nexmo, used for signing SMS message requests -* `signatureMethod` - (optional) singature method matching the one you gave Nexmo, used for signing SMS message requests. Must be one of "md5hash", "md5", "sha1", "sha256", or "sha512" + * A [Buffer](https://nodejs.org/api/buffer.html#buffer_class_method_buffer_from_string_encoding) containing the file contents. + * A String containing the path to the key file on disk. + * A String containing the key itself. +* `signatureSecret` - (optional) API singature secret from Vonage API, used for signing SMS message requests +* `signatureMethod` - (optional) singature method matching the one you gave Vonage API, used for signing SMS message requests. Must be one of "md5hash", "md5", "sha1", "sha256", or "sha512" * `options` - (optional) Additional options for the constructor. Options are: @@ -90,648 +94,6 @@ callback = (error, response) => { } ``` -## Messaging - -### Send a text message - -```js -nexmo.message.sendSms(sender, recipient, message, options, callback); -``` - -* `options` - parameter is optional. See [SMS API Reference](https://developer.nexmo.com/api/sms#send-an-sms) - -### Send a Binary Message - -```js -nexmo.message.sendBinaryMessage(fromnumber, tonumber, body, udh, callback); -``` - -* `body` - Hex encoded binary data -* `udh` - Hex encoded udh - -### Send a WAP Push Message - -```js -nexmo.message.sendWapPushMessage(fromnumber, tonumber, title, url, validity, callback); -``` - -* `validity` - is optional (if given should be in milliseconds) - -### Send a Short Code alert - -```js -nexmo.message.shortcodeAlert(recipient, messageParams, opts, callback); -``` - -## Voice - -For detailed information please see the documentation at https://developer.nexmo.com/api/voice - -### Make a call - -Requires `applicationId` and `privateKey` to be set on the constructor. - -```js -nexmo.calls.create({ - to: [{ - type: 'phone', - number: TO_NUMBER - }], - from: { - type: 'phone', - number: FROM_NUMBER - }, - answer_url: [ANSWER_URL] -}, callback); -``` - -For more information see https://developer.nexmo.com/api/voice#createCall - -### Get a Call - -```js -nexmo.calls.get(callId, callback); -``` - -For more information see https://developer.nexmo.com/api/voice#getCall - -### Query Calls - -``` -nexmo.calls.get({status: 'completed'}, callback); -``` - -The first parameter can contain many properties to filter the returned call or to page results. For more information see the [Calls API Reference](https://developer.nexmo.com/api/voice#getCalls). - -### Update a Call - -```js -nexmo.calls.update(callId, { action: 'hangup' }, callback); -``` - -For more information see https://developer.nexmo.com/api/voice#updateCall - -### Stream an Audio File to a Call - -```js -nexmo.calls.stream.start( - callId, - { - stream_url: [ - 'https://nexmo-community.github.io/ncco-examples/assets/voice_api_audio_streaming.mp3' - ], - loop: 1 - }); -``` - -For more information see https://developer.nexmo.com/api/voice#startStream - -### Stop an audio stream in a call - -```js -nexmo.calls.stream.stop(callId); -``` - -For more information see https://developer.nexmo.com/api/voice#stopStream - -### Play synthesized text in a call - -```js -nexmo.calls.talk.start( - callId, - { - text: 'No songs detected', - voiceName: 'Emma', - loop: 1 - } -); -``` - -For more information see https://developer.nexmo.com/api/voice#startTalk - -### Stop synthesized text in a call - -```js -nexmo.calls.talk.stop(callId); -``` - -For more information see https://developer.nexmo.com/api/voice#stopTalk - -### Send DTMF to a Call - -```js -nexmo.calls.dtmf.send(callId, params, callback); -``` - -For more information see https://developer.nexmo.com/api/voice#startDTMF - - -## Files - -For detailed information please see the documentation at https://developer.nexmo.com/voice/voice-api/guides/recording - -### Get a file (recording) - -```js -nexmo.files.get(fileIdOrUrl, callback); -``` - -### Save a file (recording) - -```js -nexmo.files.save(fileIdOrUrl, file, callback); -``` - -## Verify - -### Submit a Verification Request - -```js -nexmo.verify.request({number:,brand:},callback); -``` - -For more information check the documentation at https://developer.nexmo.com/api/verify#verify-request - -### Submit a PSD2 (Payment Services Directive 2) Verification Request - -```js -nexmo.verify.psd2({number:,payee:,amount:},callback); -``` - -For more information check the documentation at https://developer.nexmo.com/api/verify#verifyRequestWithPSD2 - -### Validate the response of a Verification Request - -```js -nexmo.verify.check({request_id:,code:},callback); -``` - -For more information check the documentation at https://developer.nexmo.com/api/verify#verify-check - -### Search one or more Verification Request - -```js -nexmo.verify.search(,callback); -``` - -For more information check the documentation at https://developer.nexmo.com/api/verify#verify-search - -### Cancel verification - -```js -nexmo.verify.control({request_id:,cmd:'cancel'},callback); -``` - -For more information check the documentation at https://developer.nexmo.com/api/verify#verify-control - -### Trigger next verification event - -```js -nexmo.verify.control({request_id:,cmd:'trigger_next_event'},callback); -``` - -For more information check the documentation at https://developer.nexmo.com/api/verify#verify-control - -## Number Insight - -### Basic - -```js -nexmo.numberInsight.get({level: 'basic', number: NUMBER}, callback); -``` - -For more information check the documentation at https://developer.nexmo.com/number-insight/building-blocks/number-insight-basic/node - -Example: - -```js -nexmo.numberInsight.get({level: 'basic', number: '1-234-567-8900'}, callback); -``` - -### Standard - -```js -nexmo.numberInsight.get({level: 'standard', number: NUMBER}, callback); -``` - -For more information check the documentation at https://developer.nexmo.com/number-insight/building-blocks/number-insight-standard/node - -Example: - -```js -nexmo.numberInsight.get({level: 'standard', number: '1-234-567-8900'}, callback); -``` - -### Advanced - -```js -nexmo.numberInsight.get({level: 'advancedSync', number: NUMBER}, callback); -``` - -For more information check the documentation at https://developer.nexmo.com/number-insight/building-blocks/number-insight-advanced/node - -### Advanced Async - -Number Insight Advanced might take a few seconds to return a result, therefore the option exists to process the result asynchronously through a webhook. - -```js -nexmo.numberInsight.get({level: 'advancedAsync', number: NUMBER, callback: "http://example.com"}, callback); -``` - -In this case, the result of your insight request is posted to the callback URL as a webhook. For more details on webhooks see the [Number Insight Advanced](https://developer.nexmo.com/number-insight/building-blocks/number-insight-advanced-async-callback/node) documentation. - -## Applications - -For an overview of applications see https://developer.nexmo.com/concepts/guides/applications - -### Create an App - -```js -nexmo.applications.create(params, callback); -``` - -For more information see https://developer.nexmo.com/api/application.v2#createApplication - -`params` can be - -``` json -{ -"name": "My Application", - "capabilities": { - "voice": { - "webhooks": { - "answer_url": { - "address": "https://example.com/webhooks/answer", - "http_method": "POST" - }, - "event_url": { - "address": "https://example.com/webhooks/event", - "http_method": "POST" - } - } - }, - "messages": { - "webhooks": { - "inbound_url": { - "address": "https://example.com/webhooks/inbound", - "http_method": "POST" - }, - "status_url": { - "address": "https://example.com/webhooks/status", - "http_method": "POST" - } - } - }, - "rtc": { - "webhooks": { - "event_url": { - "address": "https://example.com/webhooks/event", - "http_method": "POST" - } - } - }, - "vbc": {} - } -} -``` - -### Get a single App - -```js -nexmo.applications.get(appId, callback, v2flag); -``` - -For more information see https://developer.nexmo.com/api/application.v2#getApplication - - - `v2flag` - if `true`, you'll receive the V2 API response, else you'll receive a V1 style response from the V2 API - -### Get Apps by a filter - -```js -nexmo.applications.get(options, callback, v2flag); -``` - -For more information see https://developer.nexmo.com/api/application.v2#listApplication -- `options` - filter options, use `{}` to get all your applications -- `v2flag` - if `true`, you'll receive the V2 API response, else you'll receive a V1 style response from the V2 API - - -### Update an App - -```js -nexmo.applications.update(appId, params, callback); -``` - -For more information see https://developer.nexmo.com/api/application.v2#updateApplication - -### Delete an App - -```js -nexmo.application.delete(appId, callback); -``` - -For more information see https://developer.nexmo.com/api/application.v2#deleteApplication - -## Management - -### Check Account Balance - -```js -nexmo.account.checkBalance(callback); -``` - -### List Account Secrets - -```js -nexmo.account.listSecrets(apiKey, callback); -``` - -### Get Account Secret - -```js -nexmo.account.getSecret(apiKey, secretId, callback); -``` - -### Create Account Secret - -```js -nexmo.account.createSecret(apiKey, secret, callback); -``` - -### Delete Account Secret - -```js -nexmo.account.deleteSecret(apiKey, secretId, callback); -``` - -### Get Pricing for sending a message to a country. - -```js -nexmo.number.getPricing(countryCode, callback); -``` - -* `countryCode` - 2 letter ISO Country Code - -### Get Pricing for sending a message or making a call to a number. - -```js -nexmo.number.getPhonePricing(product, msisdn, callback); -``` - -* `product` - either `voice` or `sms` -* `msisdn` - Mobile Station International Subscriber Directory Number (MSISDN) is a number used to identify a mobile phone number internationally. i.e. 447700900000 - -### Get all numbers associated with the account. - -```js -nexmo.number.get(options, callback); -``` - -* `options` parameter is an optional Dictionary Object containing any of the following parameters - * `pattern` - * `search_pattern` - * `index` - * `size` - * `has_application` - * `application_id` - -For more details about these options, refer to the [Numbers API reference](https://developer.nexmo.com/api/numbers#getOwnedNumbers) - -Example: - -```js -nexmo.number.get({pattern:714,index:1,size:50,search_pattern:2}, callback); -``` - -### Search for MSISDN's available to purchase - -```js -nexmo.number.search(countryCode,options,callback); -``` - -`options` parameter is optional. They can be one of the following : - -1. number pattern to match the search (eg. 1408) -2. Dictionary Object optionally containing the following parameters : - * `pattern` - * `search_pattern` - * `type` - * `features` - * `index` - * `size` - -For more details about these options, refer to the [Numbers API reference](https://developer.nexmo.com/api/numbers#getAvailableNumbers) - -Example: - -```js -nexmo.number.search('US',{pattern:3049,index:1,size:50,type:'mobile-lvn',features:'VOICE',search_pattern:2}, callback); -``` - -### Purchase Number - -```js -nexmo.number.buy(countryCode, msisdn, callback); - -// optional target_api_key option -nexmo.number.buy(countryCode, msisdn, target_api_key, callback); -``` - -For more details on these parameters, see the [Numbers API reference](https://developer.nexmo.com/api/numbers#buyANumber). - -### Cancel Number - -```js -nexmo.number.cancel(countryCode, msisdn, callback); - -// optional target_api_key option -nexmo.number.cancel(countryCode, msisdn, target_api_key, callback); -``` - -For more details on these parameters, see the [Numbers API reference](https://developer.nexmo.com/api/numbers#cancelANumber). - -### Update Number - -```js -nexmo.number.update(countryCode, msisdn, params, callback); -``` - -`params` is a dictionary of parameters as described in the [Numbers API reference](https://developer.nexmo.com/api/numbers#updateANumber). - -### Update Password (API Secret) - -```js -nexmo.account.updatePassword(,callback); -``` - -### Update Callback URL associated to the account - -```js -nexmo.account.updateSMSCallback(,callback); -``` - -### Change Delivery Receipt URL associated to the account - -```js -nexmo.account.updateDeliveryReceiptCallback(,callback); -``` - -## Redact - -### Redact a specific ID - -```js -nexmo.redact.transaction(id, type, callback); -``` - -## Pricing - -`type` is the type of service you wish to retrieve pricing for: either `sms`, `sms-transit` or `voice`. - -### Get pricing for a specific country - -```js -nexmo.pricing.get(type, country_code, callback); -``` - -### Get pricing for all countries - -```js -nexmo.pricing.getFull(type, callback); -``` - -### Get pricing for a specific dialing prefix - -```js -nexmo.pricing.getPrefix(type, country_prefix, callback); -``` - -### Get pricing for a specific phone number - -```js -nexmo.pricing.getPhone(type, phone, callback); -``` - -## Media - -### Upload a file - -```js -nexmo.media.upload({"file": "/path/to/file"}, callback); -``` - -### Upload from a URL - -```js -nexmo.media.upload({"url": "https://example.com/ncco.json"}, callback); -``` - -### Search existing media - -```js -// See https://ea.developer.nexmo.com/api/media#search-media-files -// for possible search parameters -nexmo.media.search({ page_size: 1, page_index: 1 }, callback); -``` - -### Download media - -```js -nexmo.media.download(id, callback); -``` - -### Delete media - -```js -nexmo.media.delete(id, callback); -``` - -### Update media - -```js -nexmo.media.update(id, body, callback); -``` - -### Get media details - -```js -nexmo.media.get(id, callback); -``` - -## JWT - -There are two ways of generating a JWT. You can use the function that exists on the Nexmo definition: - -```js -const Nexmo = require('nexmo'); - -const jwt = Nexmo.generateJwt('path/to/private.key', {application_id: APP_ID}); -``` - -Or via a `Nexmo` instance where your supplied `applicationId` and `privateKey` credentials will be used: - -```js -const Nexmo = require('nexmo'); - -const nexmo = new Nexmo({ - apiKey: API_KEY, - apiSecret: API_SECRET, - applicationId: APP_ID, - privateKey: PRIVATE_KEY_PATH, - }); - -const jwt = nexmo.generateJwt(); -``` - -## Signature - -There are two ways of generating a signature hash. Both strip the `sig` parameter if supplied. You can use the function that exists on the Nexmo definition: - -```js -const Nexmo = require('nexmo'); - -const hash = Nexmo.generateSignature(SIGNATURE_METHOD, SIGNATURE_SECRET, params); -``` - -Or via a `Nexmo` instance where your supplied `signatureSecret` and `signatureMethod`: - -```js -const Nexmo = require('nexmo'); - -const nexmo = new Nexmo({ - apiKey: API_KEY, - apiSecret: API_SECRET, - signatureSecret: SIGNATURE_SECRET, - signatureMethod: SIGNATURE_METHOD, - }); - -const hash = nexmo.generateSignature(); -``` - -`SIGNATURE_METHOD` is the signature method matching the one you gave Nexmo. Must be one of "md5hash", "md5", "sha1", "sha256", or "sha512". - - - -## Voice (Deprecated) - -### Send TTS Message - -```js -nexmo.voice.sendTTSMessage(,message,options,callback); -``` - -### Send TTS Prompt With Capture - -```js -nexmo.sendTTSPromptWithCapture(,message,, ,options,callback); -``` - -### Send TTS Prompt With Confirm - -```js -nexmo.voice.sendTTSPromptWithConfirm(, message ,,'',,,options,callback); -``` - ## Testing Run: @@ -743,137 +105,35 @@ npm test Or to continually watch and run tests as you change the code: ```bash -npm run-script test-watch +npm run test-watch ``` ## Examples -See [examples/README.md](examples/README.md). - -Also, see the [Nexmo Node Quickstarts repo](https://github.com/nexmo-community/nexmo-node-quickstart). - -## Creating your own requests - -> #### IMPORTANT -> This section uses internal APIs and should not be relied on. We make no guarantees that the interface is stable. Relying on these methods is not recommended for production applications - -For endpoints that are not yet implemented, you can use the Nexmo HTTP Client to -make requests with the correct authentication method. - -In these examples, we assume that you've created a `nexmo` instance as follows: - -```javascript -const nexmo = new Nexmo({ - apiKey: 'API_KEY', - apiSecret: 'API_SECRET', - applicationId: 'APPLICATION_ID', - privateKey: './private.key', -}); -``` - -* If your API endpoint is on `api.nexmo.com`, use the `nexmo.options.api` object. -* If your API endpoint is on `rest.nexmo.com`, use the `nexmo.options.rest` object. - -Both of these objects expose the following methods: - -* `get(path, params, callback, useJwt)` (`params` is the query string to use) -* `post(path, params, callback, useJwt)` (`params` is the POST body to send) -* `postUseQueryString(path, params, callback, useJwt)` (`params` is the query string to use) -* `delete(path, callback, useJwt)` - -To make a request to `api.nexmo.com/v1/calls?status=rejected`: - -```javascript -nexmo.options.api.get( - "/v1/calls", - {"status": "rejected"}, - function(err, data){ - console.log(err); - console.log(data); - }, - true // Use JWT for authentication -); -``` - -To make a request to `rest.nexmo.com/sms/json?from=Demo&to=447700900000&text=Testing`: - -```javascript -nexmo.options.rest.postUseQueryString( - "/sms/json", - {"from": "Demo", "to": "447700900000", "text": "Testing"}, - function(err, data){ - console.log(err); - console.log(data); - }, - false // Don't use JWT, fall back to API key/secret -); -``` - -## API Coverage - -* Voice - * [x] Outbound Calls - * [ ] Inbound Call Webhook - * [x] Update Calls - * [x] Stream to Call - * [x] Talk to Call - * [x] DTMF to Call -* Messaging - * [x] Send - * [ ] Delivery Receipt Webhook - * [ ] Inbound Message Webhook - * [x] Search - * [x] Message - * [x] Messages - * [x] Rejections - * [x] US Short Codes - * [x] Two-Factor Authentication - * [x] Event-Based Alerts - * [x] Sending Alerts - * [x] Campaign Subscription Management -* Number Insight - * [X] Basic - * [X] Standard - * [X] Advanced - * [X] Advanced Async - * [ ] Advanced Async Webhook -* Verify - * [x] Verify - * [x] PSD2 - * [x] Check - * [x] Search - * [x] Control -* Applications - * [x] Create an Application - * [x] Get Applications - * [x] Update an Application - * [x] Delete an Application -* Account - * [X] Balance - * [x] Pricing - * [x] Settings - * [x] Top Up - * [x] Numbers - * [x] Search - * [x] Buy - * [x] Cancel - * [x] Update -* Media - * [x] Upload - * [x] Download - * [x] Search - * [x] Get - * [x] Update - * [x] Delete -* Voice (Deprecated) - * [x] Outbound Calls - * [ ] Inbound Call Webhook - * [x] Text-To-Speech Call - * [x] Text-To-Speech Prompt -* Redact - * [x] Transaction - - -## License - -MIT - see [LICENSE](LICENSE.txt) +See the [Vonage Node Quickstarts repo](https://github.com/nexmo-community/vonage-node-quickstart). + +## Supported APIs + +The following is a list of Vonage APIs and whether the Ruby SDK provides support for them: +| API | API Release Status | Supported? +|----------|:---------:|:-------------:| +| Account API | General Availability |✅| +| Alerts API | General Availability |✅| +| Application API | General Availability |✅| +| Audit API | Beta |❌| +| Conversation API | Beta |❌| +| Dispatch API | Beta |❌| +| External Accounts API | Beta |❌| +| Media API | Beta |✅| +| Messages API | Beta |❌| +| Number Insight API | General Availability |✅| +| Number Management API | General Availability |✅| +| Pricing API | General Availability |✅| +| Redact API | Developer Preview |✅| +| Reports API | Beta |❌| +| SMS API | General Availability |✅| +| Verify API | General Availability |✅| +| Voice API | General Availability |✅| + +[signup]: https://dashboard.nexmo.com/sign-up?utm_source=DEV_REL&utm_medium=github&utm_campaign=node-server-sdk +[license]: LICENSE.txt diff --git a/package.json b/package.json index f9342abb..c4cc6e63 100644 --- a/package.json +++ b/package.json @@ -1,25 +1,26 @@ { - "name": "nexmo", - "author": "nexmo", + "name": "@vonage/server-sdk", + "author": "vonage", "version": "2.9.1", - "main": "lib/Nexmo", + "main": "lib/Vonage", "types": "./typings/index.d.ts", "keywords": [ "sms", "voice", - "nexmo", + "vonage", "verify", "2fa", "phone numbers" ], - "homepage": "https://github.com/nexmo/nexmo-node", + "homepage": "https://github.com/vonage/vonage-node-sdk", "repository": { "type": "git", - "url": "git://github.com/nexmo/nexmo-node.git" + "url": "git://github.com/vonage/vonage-node-sdk.git" }, - "description": "Nexmo REST API client for Node.js. API support for SMS, Voice Calls, Text-to-Speech, Numbers, Verify (2FA) and more.", + "description": "Vonage Server SDK for Node.js. API support for SMS, Voice Calls, Text-to-Speech, Numbers, Verify (2FA) and more.", "contributors": [ - "nexmo", + "vonage", + "kellyjandrews", "pvela", "leggetter", "akuzi", From 55fad7cc28fed1b7b6fea934045a9555ec3e1e05 Mon Sep 17 00:00:00 2001 From: Kelly J Andrews Date: Fri, 4 Sep 2020 15:35:56 -0400 Subject: [PATCH 07/12] fix Vonage API text spacing --- src/CallsResource.js | 2 +- src/Credentials.js | 4 ++-- src/DtmfResource.js | 2 +- src/FilesResource.js | 2 +- src/HttpClient.js | 2 +- src/StreamResource.js | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/CallsResource.js b/src/CallsResource.js index 82297710..3f42ba9d 100644 --- a/src/CallsResource.js +++ b/src/CallsResource.js @@ -18,7 +18,7 @@ class CallsResource { /** * Creates a new CallsResource. * - * @param {Credentials} creds - Credentials used when interacting with the VonageAPI. + * @param {Credentials} creds - Credentials used when interacting with the Vonage API. * @param {Object} options - additional options for the class. */ constructor(creds, options) { diff --git a/src/Credentials.js b/src/Credentials.js index 09ac266d..b308fa85 100644 --- a/src/Credentials.js +++ b/src/Credentials.js @@ -9,8 +9,8 @@ import HashGenerator from "./HashGenerator"; * However, in time JWT will also be supported. * The `Credentials` object provides an abstraction to this. * - * @param {string} apiKey - A VonageAPI Key - * @param {string} apiSecret - A VonageAPI Secret + * @param {string} apiKey - A Vonage API Key + * @param {string} apiSecret - A Vonage API Secret * @param {string} [applicationId] - A VonageApplication ID * @param {string|Buffer} [privateKey] - When a string value is passed it should * either represent the path to the private key, or the actual diff --git a/src/DtmfResource.js b/src/DtmfResource.js index 8af313c4..930f0788 100644 --- a/src/DtmfResource.js +++ b/src/DtmfResource.js @@ -12,7 +12,7 @@ class DtmfResource { /** * Creates a new DtmfResource. * - * @param {Credentials} creds - Credentials used when interacting with the VonageAPI. + * @param {Credentials} creds - Credentials used when interacting with the Vonage API. * @param {Object} options - additional options for the class. */ constructor(creds, options) { diff --git a/src/FilesResource.js b/src/FilesResource.js index 2fd29678..f5bfc757 100644 --- a/src/FilesResource.js +++ b/src/FilesResource.js @@ -13,7 +13,7 @@ class FilesResource { /** * Creates a new FilesResource. * - * @param {Credentials} creds - Credentials used when interacting with the VonageAPI. + * @param {Credentials} creds - Credentials used when interacting with the Vonage API. * @param {Object} options - additional options for the class. */ constructor(creds, options) { diff --git a/src/HttpClient.js b/src/HttpClient.js index 2762481d..692721a0 100644 --- a/src/HttpClient.js +++ b/src/HttpClient.js @@ -39,7 +39,7 @@ class HttpClient { if (endpoint.method === "POST" || endpoint.method === "DELETE") { // TODO: verify the following fix is required - // Fix broken due ot 411 Content-Length error now sent by VonageAPI + // Fix broken due ot 411 Content-Length error now sent by Vonage API // PL 2016-Sept-6 - commented out Content-Length 0 // headers['Content-Length'] = 0; } diff --git a/src/StreamResource.js b/src/StreamResource.js index a8b25f13..82ab4f14 100644 --- a/src/StreamResource.js +++ b/src/StreamResource.js @@ -12,7 +12,7 @@ class StreamResource { /** * Creates a new StreamResource. * - * @param {Credentials} creds - Credentials used when interacting with the VonageAPI. + * @param {Credentials} creds - Credentials used when interacting with the Vonage API. * @param {Object} options - additional options for the class. */ constructor(creds, options) { From af89d3ba8ed52824b969290464bc10a2f39f0916 Mon Sep 17 00:00:00 2001 From: Kelly J Andrews Date: Fri, 4 Sep 2020 15:37:20 -0400 Subject: [PATCH 08/12] update support email --- src/HttpClient.js | 2 +- test/Conversion-test.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/HttpClient.js b/src/HttpClient.js index 692721a0..2c2bc800 100644 --- a/src/HttpClient.js +++ b/src/HttpClient.js @@ -246,7 +246,7 @@ class HttpClient { return function(err, data) { if (err && err.status == limitedAccessStatus) { err._INFO_ = - "This endpoint may need activating on your account. Please email support@vonage.com for more information"; + "This endpoint may need activating on your account. Please email support@nexmo.com for more information"; } return callback(err, data); diff --git a/test/Conversion-test.js b/test/Conversion-test.js index c68b5b26..ea940bd9 100644 --- a/test/Conversion-test.js +++ b/test/Conversion-test.js @@ -64,7 +64,7 @@ describe("Conversion", function() { this.httpClientStub.request.yields(mockError, null); this.conversion.sms("1234", 1, 1234567890, function(err, data) { expect(err._INFO_).to.eql( - "This endpoint may need activating on your account. Please email support@vonage.com for more information" + "This endpoint may need activating on your account. Please email support@nexmo.com for more information" ); expect(data).to.eql(null); done(); From c8c579fd81f1118f407dad86553263a2b535326c Mon Sep 17 00:00:00 2001 From: Kelly J Andrews Date: Fri, 4 Sep 2020 15:44:02 -0400 Subject: [PATCH 09/12] updates to contributing file --- CONTRIBUTING.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f69cf692..3f014a8b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -20,8 +20,8 @@ To run the code for an open PR, follow these steps: 1. `cd vonage-node-sdk` 1. `git checkout BRANCH_NAME` 1. `npm install` -1. `npm compile` -1. Download the `https://github.com/Vonage/vonage-node-code-snippets` repository +1. `npm run compile` +1. In a new directory, download the `https://github.com/Vonage/vonage-node-code-snippets` repository 1. Install the local Vonage package `npm i /path/to/vonage-node-sdk` 1. Copy `.env-example` to `.env` and update any variables required. 1. Run the sample code snippet to test the SDK. From 892138f0bbdb3c25a18ae0d7b34353320e6c147d Mon Sep 17 00:00:00 2001 From: Kelly J Andrews Date: Fri, 4 Sep 2020 15:44:22 -0400 Subject: [PATCH 10/12] fix Vonage spacing issue --- src/Credentials.js | 4 ++-- src/NumberInsight.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Credentials.js b/src/Credentials.js index b308fa85..96249788 100644 --- a/src/Credentials.js +++ b/src/Credentials.js @@ -16,8 +16,8 @@ import HashGenerator from "./HashGenerator"; * either represent the path to the private key, or the actual * private key in string format. If a Buffer is passed then * it should be the key read from the file system. - * @param {string} [signatureSecret] - A Vonagesignature Secret - * @param {string} [signatureMethod] - A Vonagecompatible request signing method + * @param {string} [signatureSecret] - A Vonage signature Secret + * @param {string} [signatureMethod] - A Vonage compatible request signing method */ class Credentials { constructor( diff --git a/src/NumberInsight.js b/src/NumberInsight.js index 13404d32..a8a0299a 100644 --- a/src/NumberInsight.js +++ b/src/NumberInsight.js @@ -70,7 +70,7 @@ class NumberInsight { * Insight Return Parameters. This may be useful for your * internal reports. * @param {string} options['include-intermediate-callbacks'] - 'advanced' only. - * Tells the Vonageplatform to make callbacks as soon as an + * Tells the Vonage platform to make callbacks as soon as an * individual piece of information is retrieved. */ get(options, callback) { From 9c409a36395f0cca74b3401e7c01fc407d962c4b Mon Sep 17 00:00:00 2001 From: Kelly J Andrews Date: Fri, 4 Sep 2020 16:00:06 -0400 Subject: [PATCH 11/12] correct spacing issue --- src/TalkResource.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TalkResource.js b/src/TalkResource.js index 63989578..c05f65ce 100644 --- a/src/TalkResource.js +++ b/src/TalkResource.js @@ -12,7 +12,7 @@ class TalkResource { /** * Creates a new TalkResource. * - * @param {Credentials} creds - Credentials used when interacting with the VonageAPI. + * @param {Credentials} creds - Credentials used when interacting with the Vonage API. * @param {Object} options - additional options for the class. */ constructor(creds, options) { From 53d324670d575426c2f3f711c638b20f9d1e5da0 Mon Sep 17 00:00:00 2001 From: Kelly J Andrews Date: Tue, 8 Sep 2020 10:09:49 -0400 Subject: [PATCH 12/12] remove unneeded dev dependencies --- package.json | 2 -- 1 file changed, 2 deletions(-) diff --git a/package.json b/package.json index c4cc6e63..0d46d28c 100644 --- a/package.json +++ b/package.json @@ -59,9 +59,7 @@ "eslint-config-prettier": "^6.2", "eslint-plugin-prettier": "^2.7", "expect.js": "^0.3.1", - "express": "^4.16.4", "mocha": "^7.2.0", - "ngrok": "^2.2.2", "nodemon": "^2.0.4", "nyc": "^14.1.1", "prettier": "^1.16.3",