Skip to content

Commit

Permalink
Merge pull request #338 from OpenFn/nexmo-security-patch
Browse files Browse the repository at this point in the history
Nexmo security patch
  • Loading branch information
josephjclark authored Aug 3, 2023
2 parents 64bd37c + 8591b67 commit 0de4e6b
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 144 deletions.
6 changes: 6 additions & 0 deletions .changeset/forty-bees-sit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@openfn/language-nexmo': minor
---

- update nexmo to `v2.9.1``
- expandReferences on sendSMS
8 changes: 3 additions & 5 deletions packages/nexmo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@
"configuration-schema.json"
],
"dependencies": {
"@openfn/language-common": "^1.8.1",
"nexmo": "2.1.1",
"request": "^2.88.2"
"@openfn/language-common": "workspace:^",
"nexmo": "2.9.1"
},
"devDependencies": {
"@openfn/buildtools": "workspace:^1.0.2",
Expand All @@ -33,7 +32,6 @@
"esdoc-es7-plugin": "0.0.3",
"esno": "^0.16.3",
"mocha": "^10.1.0",
"nock": "^13.2.9",
"rimraf": "^3.0.2"
},
"repository": {
Expand All @@ -49,4 +47,4 @@
"./package.json": "./package.json"
},
"types": "types/index.d.ts"
}
}
37 changes: 24 additions & 13 deletions packages/nexmo/src/Adaptor.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
execute as commonExecute,
expandReferences,
composeNextState,
} from '@openfn/language-common';
import { expandReferences } from '@openfn/language-common/util';
import Nexmo from 'nexmo';

/**
Expand Down Expand Up @@ -45,26 +45,37 @@ export function execute(...operations) {
export function sendSMS(from, toNumber, message) {
return state => {
const { apiKey, apiSecret } = state.configuration;
const [resolvedFrom, resolvedToNumber, resolvedMessage] = expandReferences(
state,
from,
toNumber,
message
);

const nexmo = new Nexmo({
apiKey: apiKey,
apiSecret: apiSecret,
});

return new Promise((resolve, reject) => {
nexmo.message.sendSms(from, toNumber, message, (error, response) => {
if (error) {
console.error(error);
reject(error);
} else if (response.messages[0].status != '0') {
console.error('Nexmo Error:');
console.error(response);
reject(response);
} else {
console.log(response);
resolve(response);
nexmo.message.sendSms(
resolvedFrom,
resolvedToNumber,
resolvedMessage,
(error, response) => {
if (error) {
console.error(error);
reject(error);
} else if (response.messages[0].status != '0') {
console.error('Nexmo Error:');
console.error(response);
reject(response);
} else {
console.log(response);
resolve(response);
}
}
});
);
}).then(response => {
const nextState = composeNextState(state, response);
return nextState;
Expand Down
Loading

0 comments on commit 0de4e6b

Please sign in to comment.