Comparing version 0.0.2 to 0.0.4
@@ -1,1 +0,3 @@ | ||
module.exports = exports = require( './lib/bridge' ); | ||
module.exports = process.env.PIGGIE_COVERAGE | ||
? require( './lib-cov/bridge' ) | ||
: require( './lib/bridge' ); |
@@ -1,40 +0,56 @@ | ||
var _ = require( 'lodash' ), | ||
Response = require( './response' ); | ||
// Dependencies | ||
var Response = require( './response' ); | ||
var paths = []; | ||
// Handlers hash | ||
var handlers = {}; | ||
var handle = function handle( path, handler ) { | ||
// TODO: Error if a handler for that path already exists | ||
paths.push( { | ||
path: path, | ||
handler: handler | ||
} ); | ||
/** | ||
* Resets the handlers hash | ||
*/ | ||
var reset = function reset () { | ||
handlers = {}; | ||
}; | ||
var send = function send( key, path, data ) { | ||
var res = new Response( key ); | ||
/** | ||
* Register handler | ||
*/ | ||
var register = function register ( path, handler ) { | ||
path = unescape(path); | ||
if (data && data.trim() !== "") { | ||
data = unescape(data); | ||
if ( handlers.hasOwnProperty( path ) ) { | ||
throw new Error( 'Handler already exists for path: ' + path ); | ||
} else { | ||
handlers[ path ] = handler; | ||
} | ||
}; | ||
/** | ||
* Execute handler | ||
*/ | ||
var execute = function execute ( key, path, data ) { | ||
var response = ( key instanceof Response ? key : new Response( key ) ); | ||
path = unescape( path ); | ||
if ( data && data.trim() !== "" ) { | ||
data = unescape( data ); | ||
try { | ||
data = JSON.parse(data); | ||
} catch (e) { | ||
return res.error( 'JSON parse error: ' + e ); | ||
data = JSON.parse( data ); | ||
} catch ( error ) { | ||
return response.fail( error ); | ||
} | ||
} | ||
var pathHandler = _.find( paths, {path: path} ); | ||
if ( !pathHandler ) { | ||
return res.error( 'No handler defined for path: ' + path ); | ||
if ( handlers[ path ] ) { | ||
handlers[ path ]( data, response ); | ||
return response; | ||
} else { | ||
return response.fail( new Error( 'No handler defined for path: ' + path ) ); | ||
} | ||
pathHandler.handler( data, res ); | ||
}; | ||
// TODO: Events | ||
module.exports.handle = handle; | ||
module.exports.send = send; | ||
// Exports | ||
module.exports.register = register; | ||
module.exports.execute = execute; | ||
module.exports.reset = reset; |
@@ -1,17 +0,32 @@ | ||
module.exports = function Response( key ) { | ||
this.error = function error( error ) { | ||
/** | ||
* Response constructor | ||
*/ | ||
var Response = function Response ( key ) { | ||
this.key = key; | ||
return this; | ||
}; | ||
Response.prototype = { | ||
/** | ||
* Native party failure callback | ||
*/ | ||
fail: function fail ( error, code ) { | ||
if ( typeof window != "undefined" && window.android ) { | ||
window.android.reply( key, error, null ); | ||
} else { | ||
console.log( 'Error %d: %s', key, error ); | ||
window.android.fail( this.key, ( code || null ), error.name, error.message ); | ||
} | ||
}; | ||
}, | ||
this.send = function send( response ) { | ||
/** | ||
* Native party success callback | ||
*/ | ||
success: function success ( data ) { | ||
if ( typeof window != "undefined" && window.android ) { | ||
window.android.reply( key, null, response ); | ||
} else { | ||
console.log( 'Send %d: %s', key, response ); | ||
window.android.success( this.key, data ); | ||
} | ||
}; | ||
} | ||
}; | ||
// Exports | ||
module.exports = Response; |
{ | ||
"name": "piggie", | ||
"version": "0.0.2", | ||
"version": "0.0.4", | ||
"main": "app.js", | ||
"dependencies": { | ||
"lodash": "~2.4.1" | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"mocha": "~1.18.2", | ||
"sinon": "~1.9.1" | ||
}, | ||
"devDependencies": {}, | ||
"scripts": { | ||
"start": "node app.js" | ||
"start": "node app.js", | ||
"test": "make test" | ||
}, | ||
@@ -17,2 +19,6 @@ "author": "ribot", | ||
"email": "matt@ribot.co.uk" | ||
}, | ||
{ | ||
"name": "Stefan Pearson", | ||
"email": "stefan@ribot.co.uk" | ||
} | ||
@@ -19,0 +25,0 @@ ], |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10419
0
10
256
2
5
2
- Removedlodash@~2.4.1
- Removedlodash@2.4.2(transitive)