Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

twilio-remote-cli

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

twilio-remote-cli - npm Package Compare versions

Comparing version 0.1.2 to 0.2.0

lib/cli.js

17

__tests__/config.js

@@ -9,2 +9,8 @@ const nconf = require('nconf');

const enquirer = require('enquirer');
jest.mock('enquirer', () => ({
prompt: jest.fn(() => 'promptTest')
}));
const mockEnv = {

@@ -19,3 +25,3 @@ TWILIO_ACCOUNT_SID: 'mockSid',

nconf.file = jest.fn();
nconf.set = jest.fn((key, newVal) => mockEnv[key] = newVal);
nconf.set = jest.fn((key, newVal) => (mockEnv[key] = newVal));
nconf.save = jest.fn(cb => (shouldThrowError ? cb('error') : cb()));

@@ -40,7 +46,14 @@ nconf.get = jest.fn(key => {

shouldThrowError = false;
const testQuery = 'test';
// Act
await setup();
try {
await setup(testQuery);
} catch (err) {
// Should never go here
expect(false).toEqual(true);
}
// Assert
expect(enquirer.prompt).toHaveBeenCalledWith(testQuery);
expect(nconf.save).toHaveBeenCalled();

@@ -47,0 +60,0 @@ });

@@ -43,2 +43,6 @@ const fs = require('fs');

if (!Object.keys(operation).length) {
throw 'exit';
}
nconf.set('TWILIO_ACCOUNT_SID', operation.sid);

@@ -45,0 +49,0 @@ nconf.set('TWILIO_AUTH_TOKEN', operation.token);

82

lib/index.js
const { prompt } = require('enquirer');
const { init, getConfig, setup, updateLastUsedNumber, getLastUsedNumber } = require('./config');
const {
init,
getConfig,
setup,
updateLastUsedNumber,
getLastUsedNumber
} = require('./config');
const { TwilioCC } = require('./twilio-cc');
const questions = require('./questions');
module.exports = Promise.resolve().then(async () => {
try {
await init();
} catch(err) {
await setup(questions.setupQuestion);
}
module.exports.run = () =>
Promise.resolve().then(async () => {
try {
await init();
} catch (err) {
console.log(
'Cannot find a valid Twilio remote configuration.\n' +
'Please follow the configuration instructions'
);
try {
const operation = await prompt(questions.operationQuestion);
if (operation.operation == 'setup') {
await setup(questions.setupQuestion);
console.log('Twilio Configuration updated');
process.exit(0);
}
const config = getConfig();
const lastUsedNumber = getLastUsedNumber();
const destination = await prompt(questions.destinationNumber(lastUsedNumber));
const sms = operation.operation == 'sms' && (await prompt(questions.smsQuestion));
try {
const operation = await prompt(questions.operationQuestion);
// Store last used number for future uses
await updateLastUsedNumber(destination.number);
if (!Object.keys(operation).length) {
throw 'exit';
}
const twiliocc = new TwilioCC(...config);
if (operation.operation == 'setup') {
await setup(questions.setupQuestion);
console.log('Twilio Configuration updated');
throw 'exit';
}
await twiliocc[operation['operation']].call(
twiliocc,
destination.number,
sms.body
);
} catch (err) {
throw err.message;
}
});
const config = getConfig();
const lastUsedNumber = getLastUsedNumber();
const destination = await prompt(
questions.destinationNumber(lastUsedNumber)
);
if (!destinationNumber) {
throw 'exit';
}
const sms =
operation.operation == 'sms' && (await prompt(questions.smsQuestion));
// Store last used number for future uses
await updateLastUsedNumber(destination.number);
const twiliocc = new TwilioCC(...config);
await twiliocc[operation['operation']].call(
twiliocc,
destination.number,
sms.body
);
} catch (err) {
throw err.message;
}
});

@@ -26,8 +26,7 @@ const twilio = require('twilio');

try {
await this.client.calls
.create({
url: 'http://demo.twilio.com/docs/voice.xml',
from: this.phoneNumber,
to
})
await this.client.calls.create({
url: 'http://demo.twilio.com/docs/voice.xml',
from: this.phoneNumber,
to
});
} catch (err) {

@@ -34,0 +33,0 @@ return err;

{
"name": "twilio-remote-cli",
"version": "0.1.2",
"description": "CLI remote control for Twilio API",
"version": "0.2.0",
"description": "A remote control for your Twilio API",
"main": "index.js",

@@ -12,3 +12,5 @@ "bin": {

"test": "jest",
"test:watch": "jest --watchAll"
"test:watch": "jest --watchAll",
"format": "prettier --write \"{lib,bin,__{tests,mocks}__}/**/*.js\"",
"postinstall": "gitmoji -i"
},

@@ -33,5 +35,8 @@ "keywords": [],

"devDependencies": {
"gitmoji-cli": "^1.9.2",
"jest": "^23.6.0",
"np": "^3.0.4"
"meow": "^5.0.0",
"np": "^3.0.4",
"prettier": "^1.15.3"
}
}

@@ -7,3 +7,3 @@ # Twilio Remote CLI

> A useful CLI for your Twilio API
> A remote control for your Twilio API

@@ -10,0 +10,0 @@ <img src="https://raw.githubusercontent.com/andreasonny83/twilio-remote-cli/master/img/sms.gif" width="700">

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc