kavenegar / kavenegar-node Goto Github PK
View Code? Open in Web Editor NEWKavenegar API Client Writen In Node
Home Page: https://kavenegar.com/rest.html
Kavenegar API Client Writen In Node
Home Page: https://kavenegar.com/rest.html
Exception! SyntaxError: Unexpected end of JSON input
at JSON.parse ()
at IncomingMessage. (****\Server\node_modules\kavenegar\kavenegar.js:36:27)
at IncomingMessage.emit (events.js:187:15)
at endReadableNT (_stream_readable.js:1090:12)
at process._tickCallback (internal/process/next_tick.js:63:19)
Hello there.
While trying to resolve the repo using the
npm i kavenegar
commad, I got the error below:
While resolving: [email protected]
Found: [email protected]
node_modules/axios
axios@"^1.6.1" from [email protected]
node_modules/axios-ntlm
axios-ntlm@"^1.2.0" from [email protected]
node_modules/soap
soap@"^1.0.0" from the root project
axios@"^1.6.7" from the root project
Could not resolve dependency:
peer axios@"^0.27.2" from [email protected]
node_modules/soap
soap@"^1.0.0" from the root project
Conflicting peer dependency: [email protected]
node_modules/axios
peer axios@"^0.27.2" from [email protected]
node_modules/soap
soap@"^1.0.0" from the root project
On large amount of data , 'data' event called multiple times and in the end 'end' event will be called.
With your CURRENT code single/couple sms sends fine ,because JSON repsponse comes in ONE piece (one 'data' event call), but on mass sms (e.g. on 150 numbers i catch an error because data is not valid JSON ,cause lib try to parse first piece of data and it is not valid , because data contain multiple pieces )
e.on('data', function(data) { var jsonObject = JSON.parse(data); if (callback) callback( jsonObject.entries, jsonObject.return.status, jsonObject.return.message ); });
I modified it like this and issue solved
var req = http.request(post_options, function(e) { e.setEncoding('utf8'); let result = ''; e.on('data', function(data) { result += data; }); e.on('end',function () { try { var jsonObject = JSON.parse(result); if (callback) callback( jsonObject.entries, jsonObject.return.status, jsonObject.return.message ); } catch (e){ console.log('Exception!',e); if(callback){ callback([],500,e.message) } } }) });
Can you , please , make an update in the lib?
Thanks
This is an old version and is not good enough for use in projects which are based on the typescript. could you please upgrade it to new versions?
In a case, needed to store new user data in to postgresql database, only when to be sure the SMS message sent, Obviously, i needed to use Transactions.
so i did paint "VerifyLookup" method to act as a promise.
This is my code:
function promisify(r,t,tpl) {
return new Promise(function (resolve, reject) {
kapi.VerifyLookup({
receptor: r,
token : t,
template : tpl
},
function(response, status) {
if (status==200)
resolve(response) ;
else
reject(status) ;
});
});
}
and in express router by using "sequelize" as ORM and "bcrypt" as hash man:
router.post('/register',function(req,res,next){
var num = Math.floor(Math.random() * 9000) + 1000;
bcrypt.genSalt(saltRounds, function(err, salt) {
bcrypt.hash(req.body.password, salt, function(err, hash) {
req.body.password = hash ;
req.body.verificationCode = num ;
req.body.RoleId = 1 ;
models.sequelize.transaction(function (t) {
return models.User.create(req.body, {transaction: t}).then(function(result){
// send verification code via sms
return promisify(result.dataValues.mobilePhone,num,'MyTemplate').then(function(status){
res.status(200).json('Ok') ;
}).catch(function(e) {
throw Error(e) ;
});
})
}).catch(function(error){
res.status(500).json(error) ;
});
});
});
});
So, you can try promise structure in next versions of API.
Regards.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.