+19
| /** | ||
| * Created by Sidhant Panda on 15/03/16. | ||
| */ | ||
| module.exports = { | ||
| rawParser : function(req, res, next) { | ||
| req.rawBody = ''; | ||
| req.setEncoding('utf8'); | ||
| req.on('data', function(chunk) { | ||
| req.rawBody += chunk; | ||
| }); | ||
| req.on('end', function() { | ||
| req.rawBody = JSON.parse(req.rawBody); | ||
| next(); | ||
| }); | ||
| } | ||
| }; |
+2
-2
| { | ||
| "name": "roadrunnr", | ||
| "version": "0.0.3", | ||
| "description": "A NodeJs wrapper for Roadrunnr logistic serrvices", | ||
| "version": "0.0.4", | ||
| "description": "A Node wrapper for Roadrunnr logistic serrvices", | ||
| "main": "roadrunnr.js", | ||
@@ -6,0 +6,0 @@ "scripts": { |
+45
-16
| # RoadRunnr NodeJs Wrapper | ||
| A javascript wrapper for RoadRunnr delivery service. In-built OAuth. You don't need to worry about getting and maintaining an access token. Just set your keys and you are good to go! | ||
| A node wrapper library for RoadRunnr delivery service. In-built OAuth. You don't need to worry about getting and maintaining an access token. Just set your keys and you are good to go! | ||
@@ -10,3 +10,3 @@ ``` | ||
| ```javascript | ||
| var runnr = require('roarunnr'); | ||
| var runnr = require('roadrunnr'); | ||
| runnr.setKeys(CLIENT_ID, CLIENT_SECRET); | ||
@@ -20,7 +20,13 @@ ``` | ||
| * [Check serviceability](#check_serviceability) | ||
| ### Bonus | ||
| * [Auto assign lat long](#assign_lat_long) | ||
| * [Use test environment](#set_test_environment) | ||
| * [Set OAuth filepath](#set_oath_path) | ||
| * [Raw Parser middleware for Express](#raw_parser) | ||
| ### <a name="create_shipment"></a>Create shipment | ||
| ```javascript | ||
| var orderRequest = new runnr.OrderRequest(); | ||
| // Add pickup details | ||
@@ -36,4 +42,4 @@ orderRequest.pickup.user.name = ''; | ||
| orderRequest.pickup.user.full_address.city.name = ''; | ||
| orderRequest.pickup.user.full_address.geo.latitude = plat; // Optional | ||
| orderRequest.pickup.user.full_address.geo.longitude = plng; // Optional | ||
| orderRequest.pickup.user.full_address.geo.latitude = "plat"; // Optional, string format | ||
| orderRequest.pickup.user.full_address.geo.longitude = "plng"; // Optional, string format | ||
@@ -48,7 +54,7 @@ | ||
| orderRequest.drop.user.full_address.address = ''; | ||
| orderRequest.pickup.user.full_address.locality.name = ''; // Can be skipped, see below | ||
| orderRequest.pickup.user.full_address.sub_locality.name = ''; // Can be skipped, see below | ||
| orderRequest.pickup.user.full_address.city.name = ''; | ||
| orderRequest.drop.user.full_address.geo.latitude = dlat; // Optional | ||
| orderRequest.drop.user.full_address.geo.longitude = dlng; // Optional | ||
| orderRequest.drop.user.full_address.locality.name = ''; // Can be skipped, see below | ||
| orderRequest.drop.user.full_address.sub_locality.name = ''; // Can be skipped, see below | ||
| orderRequest.drop.user.full_address.city.name = ''; | ||
| orderRequest.drop.user.full_address.geo.latitude = "dlat"; // Optional, string format | ||
| orderRequest.drop.user.full_address.geo.longitude = "dlng"; // Optional, string format | ||
@@ -65,2 +71,4 @@ // Order Details | ||
| orderRequest.callback_url = 'your.domain/url'; // OPTIONAL | ||
| runnr.createShipment(orderRequest, function(error, response) { | ||
@@ -91,3 +99,3 @@ console.log(response); | ||
| ### <a name="check_serviceability"></a>Check serviceability | ||
| ```javasript | ||
| ```javascript | ||
| runnr.checkServiceability(orderRequest, function(error, response) { | ||
@@ -100,6 +108,12 @@ if (error == null) { | ||
| ### <a name="assign_lat_long"></a>Optional, auto assign lat & long | ||
| Please run ```npm install geocoder``` before using the following function. You can skip the ```locality``` and ```sub_locality``` fields using this. | ||
| IMPORTANT NOTE : This function geocodes the address in ```orderRquest.pickup.user.full_address.address``` and ```orderRequest.drop.user.full_address.address```. Make sure this the complete address which includes the city name and the pin code. | ||
| #### <a name="assign_lat_long"></a>(OPTIONAL) Auto assign lat & long | ||
| Please run `npm install geocoder` before using the following function. You can skip the `locality` and `sub_locality` fields using this. | ||
| IMPORTANT NOTE : This function geocodes the address in `orderRquest.pickup.user.full_address.address` and `orderRequest.drop.user.full_address.address`. Make sure this the complete address which includes the city name and the pin code. | ||
| ```javascript | ||
| orderRequest.pickup.user.full_address.locality.name = 'BYPASS_LOCALITY'; | ||
| orderRequest.pickup.user.full_address.sub_locality.name = ''; // Can be left blank | ||
| orderRequest.drop.user.full_address.locality.name = 'BYPASS_LOCALITY'; | ||
| orderRequest.drop.user.full_address.sub_locality.name = ''; // Can be left blank | ||
| runnr.assignLatLong(orderRequest, function(error, newOrderRequest) { | ||
@@ -113,3 +127,3 @@ if (error) { | ||
| } | ||
| } | ||
| }); | ||
| } | ||
@@ -119,4 +133,4 @@ }); | ||
| #### <a name="set_test_environment"></a>Use test environment | ||
| To use Roadrunnr's test portal, just change the environment | ||
| #### <a name="set_test_environment"></a>(OPTIONAL) Use test environment | ||
| To use Roadrunnr's test portal, just change the environment. This module uses the production server by default. | ||
| ```javascript | ||
@@ -126,4 +140,19 @@ runnr.setEnvironment('test'); | ||
| #### <a name="set_oath_path"></a>(OPTIONAL) Change OAuth token filepath | ||
| To use Roadrunnr's test portal, just change the environment. This module uses the production server by default. | ||
| ```javascript | ||
| runnr.setOAuthPath('./path/to/OAuth/file.json'); | ||
| ``` | ||
| #### <a name="raw_parser"></a>(OPTIONAL) RawParser middleware for Express | ||
| Roadrunnr callbacks are of type `application/octet-stream`, and rawBody has been dropped from the request object in newer versions of Express. Here is a simple rawbody parser for roadrunnr callbacks | ||
| ```javascript | ||
| app.post('/roadRunnr/callback', runnr.rawParser, function(req,res) { | ||
| console.log(req.rawBody); | ||
| res.send(req.rawBody); | ||
| }); | ||
| ``` | ||
| --- | ||
| ### Submit issues | ||
| You can raise an issue in this repo or mail me at sidhant@hashexclude.com |
+75
-57
| var request = require('request'); | ||
| var fs = require('fs'); | ||
| var rp = require('./rawParser.js'); | ||
@@ -7,3 +8,3 @@ var HOSTS = { | ||
| test : 'http://128.199.241.199/' | ||
| } | ||
| }; | ||
@@ -16,21 +17,21 @@ var OrderRequest = { | ||
| email: '', | ||
| type: 'merchant', | ||
| external_id: 'BLR-aafe', | ||
| type: '', | ||
| external_id: '', | ||
| full_address: { | ||
| address: '', | ||
| locality: { | ||
| name: '', | ||
| name: '' | ||
| }, | ||
| sub_locality: { | ||
| name: '', | ||
| name: '' | ||
| }, | ||
| city: { | ||
| name: '', | ||
| name: '' | ||
| }, | ||
| geo: { | ||
| latitude: '', | ||
| longitude: '', | ||
| }, | ||
| }, | ||
| }, | ||
| longitude: '' | ||
| } | ||
| } | ||
| } | ||
| }, | ||
@@ -42,21 +43,21 @@ drop: { | ||
| email: '', | ||
| type: 'customer', | ||
| external_id: 'BLR-aafe', | ||
| type: '', | ||
| external_id: '', | ||
| full_address: { | ||
| address: '', | ||
| locality: { | ||
| name: '', | ||
| name: '' | ||
| }, | ||
| sub_locality: { | ||
| name: '', | ||
| name: '' | ||
| }, | ||
| city: { | ||
| name: '', | ||
| name: '' | ||
| }, | ||
| geo: { | ||
| latitude: '', | ||
| longitude: '', | ||
| }, | ||
| }, | ||
| }, | ||
| longitude: '' | ||
| } | ||
| } | ||
| } | ||
| }, | ||
@@ -69,3 +70,3 @@ order_details: { | ||
| order_type: { | ||
| name: '', | ||
| name: '' | ||
| }, | ||
@@ -77,10 +78,10 @@ order_items: [ | ||
| item: { | ||
| name: '', | ||
| name: '' | ||
| } | ||
| }, | ||
| } | ||
| ], | ||
| created_at : '', | ||
| created_at : '' | ||
| }, | ||
| callback_url: '', | ||
| } | ||
| callback_url: '' | ||
| }; | ||
@@ -91,4 +92,4 @@ var API = { | ||
| TRACK : 'v1/orders/', | ||
| SERVICEABILITY : 'v1/orders/serviceability/', | ||
| } | ||
| SERVICEABILITY : 'v1/orders/serviceability/' | ||
| }; | ||
@@ -100,6 +101,6 @@ module.exports = { | ||
| 'CLIENT_ID' : 'YOUR-PRODUCTION-CLIENT-ID', | ||
| 'CLIENT_SECRET' : 'YOUR-PRODUCTION-CLIENT-SECRET', | ||
| 'CLIENT_SECRET' : 'YOUR-PRODUCTION-CLIENT-SECRET' | ||
| }, | ||
| setRoadrunnrOAuthPath : function(path) { | ||
| setOAuthPath : function(path) { | ||
| this.oauth_json_path = path; | ||
@@ -131,8 +132,8 @@ }, | ||
| 'cache-control' : 'no-cache', | ||
| 'content-type' : 'Application/JSOn', | ||
| 'authorization' : 'Token ' + token, | ||
| 'content-type' : 'Application/JSON', | ||
| 'authorization' : 'Token ' + token | ||
| }, | ||
| url : HOSTS[env] + API.SHIP, | ||
| body : orderRequest, | ||
| json : true, | ||
| json : true | ||
| }, function(error, response, body){ | ||
@@ -155,7 +156,7 @@ if (error) { | ||
| 'cache-control' : 'no-cache', | ||
| 'content-type' : 'Application/JSOn', | ||
| 'authorization' : 'Token ' + token, | ||
| 'content-type' : 'Application/JSON', | ||
| 'authorization' : 'Token ' + token | ||
| }, | ||
| url : HOSTS[env] + API.TRACK + '/' + id + '/track/', | ||
| json : true, | ||
| json : true | ||
| }, function(error, response, body){ | ||
@@ -178,8 +179,8 @@ if (error) { | ||
| 'cache-control' : 'no-cache', | ||
| 'content-type' : 'Application/JSOn', | ||
| 'authorization' : 'Token ' + token, | ||
| 'content-type' : 'Application/JSON', | ||
| 'authorization' : 'Token ' + token | ||
| }, | ||
| url : HOSTS[env] + API.SERVICEABILITY, | ||
| body : orderRequest, | ||
| json : true, | ||
| json : true | ||
| }, function(error, response, body){ | ||
@@ -202,7 +203,7 @@ if (error) { | ||
| 'cache-control' : 'no-cache', | ||
| 'content-type' : 'Application/JSOn', | ||
| 'authorization' : 'Token ' + token, | ||
| 'content-type' : 'Application/JSON', | ||
| 'authorization' : 'Token ' + token | ||
| }, | ||
| url : HOSTS[env] + API.TRACK + '/' + id + '/cancel/', | ||
| json : true, | ||
| json : true | ||
| }, function(error, response, body){ | ||
@@ -240,4 +241,6 @@ if (error) { | ||
| }, | ||
| } | ||
| rawParser : rp.rawParser | ||
| }; | ||
| function getOAuthToken(path, config, env, callback) { | ||
@@ -258,6 +261,6 @@ readFile(path, function(err, obj) { | ||
| 'cache-control' : 'no-cache', | ||
| 'content-type' : 'Application/JSOn', | ||
| 'content-type' : 'Application/JSON' | ||
| }, | ||
| url : HOSTS[env] + getTokenEP, | ||
| json : true, | ||
| json : true | ||
| }, function(error, response, body) { | ||
@@ -296,4 +299,4 @@ if (error == null) { | ||
| lat: data.results[0].geometry.location.lat, | ||
| lng: data.results[0].geometry.location.lng, | ||
| } | ||
| lng: data.results[0].geometry.location.lng | ||
| }; | ||
| callback(null, geo); | ||
@@ -305,16 +308,23 @@ } | ||
| function readFile (file, options, callback) { | ||
| /** | ||
| * Helper method to read file in JSON format | ||
| * | ||
| * @param path path/to/file/containing/json/object | ||
| * @param options Options passed onto fs.readFile method to get the file | ||
| * @param callback | ||
| */ | ||
| function readFile (path, options, callback) { | ||
| if (callback == null) { | ||
| callback = options | ||
| callback = options; | ||
| options = {} | ||
| } | ||
| fs.readFile(file, options, function (err, data) { | ||
| if (err) return callback(err) | ||
| fs.readFile(path, options, function (err, data) { | ||
| if (err) return callback(err); | ||
| var obj | ||
| var obj; | ||
| try { | ||
| obj = JSON.parse(data, options ? options.reviver : null) | ||
| } catch (err2) { | ||
| err2.message = file + ': ' + err2.message | ||
| err2.message = path + ': ' + err2.message; | ||
| return callback(err2) | ||
@@ -326,5 +336,13 @@ } | ||
| function writeFile (file, obj, options, callback) { | ||
| /** | ||
| * Helper method to store a JSON type object to file | ||
| * | ||
| * @param path The path where the file will be stored | ||
| * @param obj The JavaScript object to be stored | ||
| * @param options Options passed to the fs.writeFile function call to store the file | ||
| * @param callback | ||
| */ | ||
| function writeFile (path, obj, options, callback) { | ||
| if (callback == null) { | ||
| callback = options | ||
| callback = options; | ||
| options = {} | ||
@@ -336,5 +354,5 @@ } | ||
| ? options.spaces : this.spaces | ||
| : this.spaces | ||
| : this.spaces; | ||
| var str = '' | ||
| var str = ''; | ||
| try { | ||
@@ -346,3 +364,3 @@ str = JSON.stringify(obj, options ? options.replacer : null, spaces) + '\n' | ||
| fs.writeFile(file, str, options, callback) | ||
| fs.writeFile(path, str, options, callback) | ||
| } |
Sorry, the diff of this file is not supported yet
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
16476
15.01%5
25%337
10.49%149
24.17%