New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

africastalking

Package Overview
Dependencies
Maintainers
4
Versions
55
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

africastalking - npm Package Compare versions

Comparing version 0.5.7 to 0.5.8

.nyc_output/370e0b46-c9b3-4493-9dfc-c307a20e10e5.json

4

lib/airtime.js

@@ -29,5 +29,6 @@ 'use strict';

const customAxios = value.idempotencyKey ? initializeAxios(this.config, value.idempotencyKey) : initializeAxios(this.config);
customAxios.airtime.sendAirtimeRequest({
recipients: JSON.stringify(recipients),
maxNumRetry: options.maxNumRetry? Number(options.maxNumRetry) : "None"
})

@@ -59,2 +60,3 @@ .then(function (response) {

).min(1).required(),
maxNumRetry: Joi.number().optional(),
}).required();

@@ -61,0 +63,0 @@

'use strict';
const unirest = require('unirest');
const axios = require('axios');
const validate = require('validate.js');

@@ -131,16 +131,27 @@ const _ = require('lodash');

const url = isBulk ? Common.SMS_URL : Common.CONTENT_URL + '/messaging';
const rq = unirest.post(url);
rq.headers({
apikey: _self.options.apiKey,
Accept: _self.options.format,
const headers = {
apikey: _self.options.apiKey,
Accept: _self.options.format,
};
axios({
method:'POST',
url,
headers,
data: new URLSearchParams(body)
})
.then(function (response) {
if (response.status === 201) {
// API returns CREATED on success!?
resolve(response.data);
} else {
reject(response.data);
}
})
.catch(function (error) {
reject(error)
});
rq.send(body);
rq.end(function (resp) {
if (resp.status === 201) {
// API returns CREATED on success!?
resolve(resp.body);
} else {
reject(resp.body || resp.error);
}
});
});

@@ -192,17 +203,31 @@ }

return new Promise(function (resolve, reject) {
const rq = unirest.get(Common.SMS_URL);
rq.headers({
const headers = {
apikey: _self.options.apiKey,
Accept: _self.options.format,
});
rq.query({
Accept: _self.options.format
};
const query = new URLSearchParams({
username: _self.options.username,
lastReceivedId: opts.lastReceivedId,
});
rq.end(function (resp) {
if (resp.status === 200) {
resolve(resp.body);
keyword: opts.keyword,
shortCode: opts.shortCode,
}).toString();
const url = `${Common.SMS_URL}?${query}`;
axios({
method:'GET',
url,
headers
})
.then(function (response) {
if (response.status === 200) {
resolve(response.data);
} else {
reject(resp.body || resp.error);
reject(response.data);
}
})
.catch(function (error) {
reject(error)
});

@@ -240,16 +265,25 @@ });

}
const rq = unirest.post(Common.CONTENT_URL + '/subscription/create');
rq.headers({
const url = `${Common.CONTENT_URL}/subscription/create`;
const headers = {
apikey: _self.options.apiKey,
Accept: _self.options.format,
});
rq.send(body);
rq.end(function (resp) {
if (resp.status === 201) {
Accept: _self.options.format
};
axios({
method:'POST',
url,
headers,
data: new URLSearchParams(body)
})
.then(function (response) {
if (response.status === 201) {
// API returns CREATED on success!?
resolve(resp.body);
resolve(response.data);
} else {
reject(resp.body || resp.error);
reject(response.data);
}
})
.catch(function (error) {
reject(error)
});

@@ -282,9 +316,10 @@ });

return reject(validationError);
}
const rq = unirest.get(Common.CONTENT_URL + '/subscription');
rq.headers({
apikey: _self.options.apiKey,
Accept: _self.options.format,
});
rq.query({
};
const headers ={
apikey: _self.options.apiKey,
Accept: _self.options.format,
};
const query = new URLSearchParams({
username: _self.options.username,

@@ -294,10 +329,22 @@ lastReceivedId: opts.lastReceivedId,

shortCode: opts.shortCode,
});
rq.end(function (resp) {
if (resp.status === 200) {
resolve(resp.body);
}).toString();
const url = `${Common.CONTENT_URL}/subscription?${query}`;
axios({
method:'GET',
url,
headers
})
.then(function (response) {
if (response.status === 200) {
resolve(response.data);
} else {
reject(resp.body || resp.error);
reject(response.data);
}
})
.catch(function (error) {
reject(error)
});
});

@@ -351,18 +398,26 @@ };

};
const rq = unirest.post(Common.CONTENT_URL + '/subscription/delete');
rq.headers({
const url = `${Common.CONTENT_URL}/subscription/delete`;
const headers = {
apiKey: apiKey,
Accept: format,
'Content-Type': 'application/x-www-form-urlencoded',
});
rq.send(body);
rq.end(function (resp) {
if (resp.status === 200) {
};
axios({
method:'POST',
url,
headers,
data: new URLSearchParams(body)
})
.then(function (response) {
if (response.status === 200) {
// API deleted successfully
resolve(resp.body);
resolve(response.data);
} else {
reject(resp.body || resp.error);
reject(response.data);
}
})
.catch(function (error) {
reject(error)
});

@@ -369,0 +424,0 @@ });

'use strict';
const unirest = require('unirest');
const validate = require('validate.js');
const _ = require('lodash');
const axios = require('axios');
const Common = require('./common');
class Token{
constructor(options){
this.options = options;
};
class Token {
constructor(options) {
this.options = options;
}
generateAuthToken() {
var _self = this;
return new Promise(function (resolve, reject) {
var body = {
username: _self.options.username,
const _self = this;
return new Promise((resolve,reject) => {
const config = {
method: 'post',
url: Common.AUTH_TOKEN_URL,
headers: {
apiKey: _self.options.apiKey,
Accept: _self.options.format,
'Content-Type': 'application/json'
},
data : JSON.stringify({
username: _self.options.username,
})
};
var rq = unirest.post(Common.AUTH_TOKEN_URL);
rq.headers({
apiKey: _self.options.apiKey,
Accept: _self.options.format,
'Content-Type': 'application/json'
axios(config)
.then(function (resp) {
const results = resp.data;
if (!results.token || results.token === 'None') {
return reject(results.description);
};
return resolve(results)
})
.catch(function (error) {
return reject(error);
});
rq.send(body);
rq.end(function (resp) {
if (resp.error)
return reject(resp.error);
if (resp.body.token === undefined || resp.body.token === 'None') {
return reject(resp.body.description);
}
return resolve(resp.body);
});
});
}
}
};
module.exports = Token;
'use strict';
const unirest = require('unirest');
const validate = require('validate.js');

@@ -76,24 +74,31 @@ const _ = require('lodash');

}else{
const body = {
username: this.options.username,
to: callTo.join(','),
from: callFrom,
clientRequestId: clientRequestId
const config = {
method: 'post',
url: `${Common.VOICE_URL}/call`,
headers: {
apikey: this.options.apiKey,
Accept: this.options.format
},
data : JSON.stringify({
username: this.options.username,
to: callTo.join(','),
from: callFrom,
clientRequestId: clientRequestId
})
};
axios(config)
.then(function (resp) {
const httpStatus = resp.status;
const rq = unirest.post(Common.VOICE_URL + '/call');
rq.headers({
apikey: this.options.apiKey,
Accept: this.options.format
});
rq.send(body);
rq.end(function (resp) {
if (resp.status === 200 || resp.status === 201) {
if (httpStatus === 200 || httpStatus === 201) {
// API returns CREATED on success
resolve(resp.body);
resolve(resp.data);
} else {
reject(resp.body || resp.error);
reject(resp.data);
};
})
.catch(function (error) {
return reject(error);
});

@@ -139,23 +144,28 @@ };

return new Promise(function (resolve, reject) {
// list of phoneNumbers, comma separated
let body = {
username: _self.options.username,
phoneNumbers: options.phoneNumbers
const config = {
method: 'post',
url: `${Common.VOICE_URL}/queueStatus`,
headers: {
apikey: _self.options.apiKey,
Accept: _self.options.format
},
data : JSON.stringify({
username: _self.options.username,
phoneNumbers: options.phoneNumbers
})
};
axios(config)
.then(function (resp) {
const httpStatus = resp.status;
let rq = unirest.post(Common.VOICE_URL + '/queueStatus');
rq.headers({
apikey: _self.options.apiKey,
Accept: _self.options.format
});
rq.send(body);
rq.end(function (resp) {
if (resp.status === 200 || resp.status === 201) {
if (httpStatus === 200 || httpStatus === 201) {
// API returns CREATED on success
resolve(resp.body);
resolve(resp.data);
} else {
reject(resp.body || resp.error);
}
reject(resp.data);
};
})
.catch(function (error) {
return reject(error);
});

@@ -216,23 +226,31 @@ });

return new Promise(function (resolve, reject) {
let body = {
username: _self.options.username,
url: options.url,
phoneNumber: options.phoneNumber
};
let rq = unirest.post(Common.VOICE_URL + '/mediaUpload');
rq.headers({
const config = {
method: 'post',
url: `${Common.VOICE_URL}/mediaUpload`,
headers: {
apikey: _self.options.apiKey,
Accept: _self.options.format
});
},
data : JSON.stringify({
username: _self.options.username,
url: options.url,
phoneNumber: options.phoneNumber
})
};
rq.send(body);
axios(config)
.then(function (resp) {
const httpStatus = resp.status;
rq.end(function (resp) {
if (resp.status === 201) {
if (httpStatus === 200 || httpStatus === 201) {
// API returns CREATED on success
resolve(resp.body);
resolve(resp.data);
} else {
reject(resp.body || resp.error);
}
reject(resp.data);
};
})
.catch(function (error) {
return reject(error);
});

@@ -239,0 +257,0 @@ });

{
"name": "africastalking",
"version": "0.5.7",
"version": "0.5.8",
"description": "Official AfricasTalking node.js API wrapper",

@@ -20,3 +20,4 @@ "main": "index.js",

"m-pesa",
"payments"
"payments",
"airtime"
],

@@ -34,3 +35,3 @@ "author": "Africa's Talking",

"@hapi/joi": "^16.1.7",
"axios": "^0.25.0",
"axios": "^1.2.6",
"body-parser": "^1.19.1",

@@ -40,3 +41,2 @@ "lodash": "^4.17.21",

"querystring": "^0.2.0",
"unirest": "^0.6.0",
"validate.js": "^0.13.1"

@@ -43,0 +43,0 @@ },

@@ -90,11 +90,32 @@ # Africa's Talking Node.js SDK

- `airtime.send({ recipients })`: Send airtime to a bunch of phone numbers. `recipients`: An array of objects containing the following keys:
- `phoneNumber`: Recipient of airtime. `REQUIRED`
- `currencyCode`: 3-digit ISO format currency code. `REQUIRED`
- `amount`: Amount to charge. `REQUIRED`
- `airtime.send({ recipients })`: Send airtime to a bunch of phone numbers. `recipients`: An array of objects containing the following keys:
- `phoneNumber`: Recipient of airtime. `REQUIRED`.
- `currencyCode`: 3-digit ISO format currency code. `REQUIRED`.
- `amount`: Amount to charge. `REQUIRED`.
- `maxNumRetry`: This is the number of times a request will be retried. It is equivalent to **minutes**. If you set a maxNumRetry of 4 that means your transaction will be retried 4 times consecutively in the next 4 minutes because retries are done after every minute. If you don't set maxNumRetry, the request will **NOT** be retried. `OPTIONAL`.
For more information, please read [http://docs.africastalking.com/airtime/sending](http://docs.africastalking.com/airtime/sending)
- Example:
```javascript
airtime.send({
recipients: [
{
phoneNumber: '+xxxxxxxxxxxx',
currencyCode: 'KES',
amount: 90
},
{
phoneNumber: '+xxxxxxxxxxxx',
currencyCode: 'KES',
amount: 897
}
],
maxNumRetry: 4 // will be retried 4 times consecutively in the next 4 minutes
});
```
For more information, please read [http://docs.africastalking.com/airtime/sending](http://docs.africastalking.com/airtime/sending)
### `SmsService`

@@ -101,0 +122,0 @@

Sorry, the diff of this file is too big to display

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