Comparing version 0.6.4 to 0.6.5
{ | ||
"name": "freedom", | ||
"version": "0.6.4", | ||
"version": "0.6.5", | ||
"homepage": "http://freedomjs.org", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -1,2 +0,2 @@ | ||
/*globals freedom,importScripts */ | ||
/*globals freedom,importScripts,console */ | ||
/*jslint indent:2, white:true, sloppy:true, browser:true */ | ||
@@ -14,33 +14,41 @@ | ||
var buildURL = function (obj) { | ||
var url = "https://accounts.google.com/o/oauth2/auth?" + | ||
"client_id=513137528418-i52cg29ug3qjiqta1ttcvrguhrjjq2so.apps.googleusercontent.com&" + | ||
"response_type=token&" + | ||
"scope=" + encodeURIComponent("https://www.googleapis.com/auth/userinfo.profile") + "&" + | ||
"redirect_uri=" + encodeURIComponent(obj.redirect) + "&" + | ||
"state=" + encodeURIComponent(obj.state); | ||
instance.emit("oAuth", url); | ||
}; | ||
instance.on('start', function() { | ||
oauth.initiateOAuth(registeredRedirectURIs).then(function (obj) { | ||
var url = "https://accounts.google.com/o/oauth2/auth?" + | ||
"client_id=513137528418-i52cg29ug3qjiqta1ttcvrguhrjjq2so.apps.googleusercontent.com&" + | ||
"response_type=token&" + | ||
"scope=" + encodeURIComponent("https://www.googleapis.com/auth/userinfo.profile") + "&" + | ||
"redirect_uri=" + encodeURIComponent(obj.redirect) + "&" + | ||
"state=" + encodeURIComponent(obj.state); | ||
return oauth.launchAuthFlow(url, obj); | ||
//instance.emit("oAuth", url); | ||
}).then(function(responseUrl) { | ||
var query = responseUrl.substr(responseUrl.indexOf('#') + 1), | ||
param, | ||
params = {}, | ||
keys = query.split('&'), | ||
i = 0, | ||
xhr = new XMLHttpRequest(); | ||
oauth.on('oAuthEvent', function (url) { | ||
var query = url.substr(url.indexOf('#') + 1), | ||
param, | ||
params = {}, | ||
keys = query.split('&'), | ||
i = 0, | ||
xhr = new XMLHttpRequest(); | ||
for (i = 0; i < keys.length; i += 1) { | ||
param = keys[i].substr(0, keys[i].indexOf('=')); | ||
params[param] = keys[i].substr(keys[i].indexOf('=') + 1); | ||
} | ||
// https://developers.google.com/api-client-library/javascript/features/cors | ||
// claims that googleapis.com supports CORS Headers. This is a lie. | ||
// However, undocumented everywere is the fact that the endpoint API does | ||
// support JSONP, which can also be used (though not super gracefully) | ||
// with freedom.js modules. | ||
importScripts("https://www.googleapis.com/userinfo/v2/me?" + | ||
"callback=onProfile&" + | ||
"access_token=" + params.access_token); | ||
return; | ||
}).catch(function (msg) { | ||
instance.emit('profile', { | ||
name: 'oAuth Error', | ||
details: msg | ||
}); | ||
}); | ||
for (i = 0; i < keys.length; i += 1) { | ||
param = keys[i].substr(0, keys[i].indexOf('=')); | ||
params[param] = keys[i].substr(keys[i].indexOf('=') + 1); | ||
} | ||
// https://developers.google.com/api-client-library/javascript/features/cors | ||
// claims that googleapis.com supports CORS Headers. This is a lie. | ||
// However, undocumented everywere is the fact that the endpoint API does | ||
// support JSONP, which can also be used (though not super gracefully) | ||
// with freedom.js modules. | ||
importScripts("https://www.googleapis.com/userinfo/v2/me?" + | ||
"callback=onProfile&" + | ||
"access_token=" + params.access_token); | ||
}); | ||
@@ -56,7 +64,1 @@ | ||
oauth.initiateOAuth(registeredRedirectURIs).then(buildURL, function (msg) { | ||
instance.emit('profile', { | ||
name: 'oAuth Error', | ||
details: msg | ||
}); | ||
}); |
@@ -11,2 +11,3 @@ /*jslint sloppy:true*/ | ||
var view = freedom['core.view'](); | ||
var logger; | ||
var users = {}; //Keep track of the roster | ||
@@ -16,2 +17,6 @@ var myClientState = null; | ||
freedom.core().getLogger('Connection Controller').then(function (log) { | ||
logger = log; | ||
}); | ||
/** | ||
@@ -62,5 +67,5 @@ * Relay messages from the social network to the view. | ||
}); | ||
freedom().emit('height', data.status === social.STATUS.ONLINE ? 384 : 109); | ||
view.postMessage({'height': data.status === social.STATUS.ONLINE ? 384 : 109}); | ||
if (data.status !== social.STATUS.ONLINE) { | ||
console.error('got status ' + data.status + ' from social'); | ||
logger.error('got status ' + data.status + ' from social'); | ||
doLogin(); | ||
@@ -94,3 +99,3 @@ } | ||
}); | ||
freedom().emit('height', ret.status === social.STATUS.ONLINE ? 384 : 109); | ||
view.postMessage({'height': ret.status === social.STATUS.ONLINE ? 384 : 109}); | ||
}, function (err) { | ||
@@ -101,3 +106,3 @@ view.postMessage({ | ||
}); | ||
freedom().emit('height', 109); | ||
view.postMessage({'height': 109}); | ||
}); | ||
@@ -108,8 +113,8 @@ }; | ||
view.on('message', function (msg) { | ||
console.warn('main got msg ' + msg); | ||
logger.log('main got msg ' + msg); | ||
}); | ||
/** SHOW VIEW AT START **/ | ||
view.open('connections', {file: 'view.html'}).then(function () { | ||
view.show(); | ||
view.show('connections').then(function () { | ||
logger.log('View opened'); | ||
}); |
@@ -17,9 +17,11 @@ { | ||
"views": { | ||
"connections": [ | ||
"view.html", | ||
"view.css", | ||
"view.js", | ||
"third-party/qr/qr.js" | ||
] | ||
"connections": { | ||
"main": "view.html", | ||
"files": [ | ||
"view.css", | ||
"view.js", | ||
"third-party/qr/qr.js" | ||
] | ||
} | ||
} | ||
} |
@@ -138,7 +138,4 @@ /*jslint node:true*/ | ||
options: { | ||
postBundleCB: function (err, src, next) { | ||
next(err, require('fs').readFileSync('src/util/header.txt') + | ||
grunt.template.process('/** Version: <%= pkg.version %> **/\n') + | ||
src); | ||
} | ||
banner: require('fs').readFileSync('src/util/header.txt') + | ||
'/** Version: <%= pkg.version %> **/\n' | ||
} | ||
@@ -179,4 +176,3 @@ }, | ||
FILES.specProviderIntegration | ||
), | ||
'spec/helper/frame.js': ['src/util/frameEntry.js'] | ||
) | ||
} | ||
@@ -215,2 +211,8 @@ }, | ||
}, | ||
codeclimate: { | ||
options: { | ||
file: 'unset: use `grunt prepare_codeclimate` to set.', | ||
token: process.env.CODECLIMATETOKEN || 'unknown' | ||
} | ||
}, | ||
connect: { | ||
@@ -268,3 +270,3 @@ freedom: { | ||
message: 'Enter a git tag message:', | ||
default: 'v%VERSION%', | ||
default: 'v%VERSION%' | ||
} | ||
@@ -286,2 +288,3 @@ ] | ||
grunt.loadNpmTasks('grunt-bump'); | ||
grunt.loadNpmTasks('grunt-codeclimate-reporter'); | ||
grunt.loadNpmTasks('grunt-contrib-jshint'); | ||
@@ -318,2 +321,22 @@ grunt.loadNpmTasks('grunt-contrib-clean'); | ||
}); | ||
grunt.registerTask('dynamic_codeclimate', 'Run codeclimate with correct lcov.', | ||
function () { | ||
var file = require("glob").sync("tools/coverage/PhantomJS**/lcov.info"); | ||
if (file.length !== 1) { | ||
return grunt.log.error("lcov file not present or distinguishable for code climate"); | ||
} | ||
require('fs').renameSync(file[0], "tools/coverage/lcov.info"); | ||
grunt.config.merge({ | ||
codeclimate: { | ||
report: { | ||
src: "tools/coverage/lcov.info", | ||
options: { | ||
file: "tools/coverage/lcov.info", | ||
token: process.env.CODECLIMATETOKEN | ||
} | ||
} | ||
} | ||
}); | ||
grunt.task.run('codeclimate:report'); | ||
}); | ||
@@ -341,5 +364,6 @@ // Default tasks. | ||
'prepare_watch', | ||
'build', | ||
'jshint', | ||
'browserify:frame', | ||
'browserify:jasmine_full', | ||
'connect:freedom', | ||
'browserify:jasmine_full', | ||
'karma:browsers' | ||
@@ -367,3 +391,4 @@ ]); | ||
'karma:saucelabs', | ||
'coveralls:report' | ||
'coveralls:report', | ||
'dynamic_codeclimate' | ||
]); | ||
@@ -370,0 +395,0 @@ } else { //When run from Travis from jobs *.2, *.3, etc. |
@@ -5,26 +5,42 @@ { | ||
/** | ||
* An oAuth event has occured | ||
* @return {String} The URL received by the oAuth provider. | ||
* Indicate the intention to initiate an oAuth flow, allowing an appropriate | ||
* oAuth provider to begin monitoring for redirection. | ||
* This will generate a token, which must be passed to the single subsequent call | ||
* to launchAuthFlow. | ||
* | ||
* | ||
* @method initiateOAuth | ||
* @param {String[]} Valid oAuth redirect URIs for your application | ||
* @return {{redirect: String, state: String}} A chosen redirect URI and | ||
* state which will be monitored for oAuth redirection if available | ||
**/ | ||
"oAuthEvent": { | ||
"type": "event", | ||
"value": "string" | ||
"initiateOAuth": { | ||
"type": "method", | ||
"value": [["array", "string"]], | ||
"ret": { | ||
"redirect": "string", | ||
"state": "string" | ||
}, | ||
"err": { | ||
"errcode": "string", | ||
"message": "string" | ||
} | ||
}, | ||
/** | ||
* Express interest in initiating an oAuth flow. | ||
* oAuth client-side flow - launch the provided URL | ||
* This must be called after initiateOAuth with the returned state object | ||
* | ||
* @method initiateOAuth | ||
* @param {String[]} Valid oAuth redirect URLs for your application. | ||
* @returns {{redirect:String, state:String}} A chosen redirect URI, and | ||
* state which will be monitored for oAuth redirection, if one is | ||
* available. | ||
* @method launchAuthFlow | ||
* @param {String} The URL that initiates the auth flow. | ||
* @param {Object.<string, string>} The return value from initiateOAuth | ||
* @return {String} responseUrl - containing the access token | ||
*/ | ||
"initiateOAuth": { | ||
"launchAuthFlow": { | ||
"type": "method", | ||
"value": [["array", "string"]], | ||
"ret": { | ||
"value": ["string", { | ||
"redirect": "string", | ||
"state": "string" | ||
}, | ||
}], | ||
"ret": "string", | ||
"err": { | ||
@@ -31,0 +47,0 @@ "errcode": "string", |
{ | ||
"name": "core.view", | ||
"api": { | ||
"open": {"type": "method", "value": ["string", { | ||
"file": "string", | ||
"code": "string" | ||
}]}, | ||
"show": {"type": "method", "value": []}, | ||
"show": {"type": "method", "value": ["string"]}, | ||
"isSecure": {"type": "method", "value": [], "ret": "boolean" }, | ||
"close": {"type": "method", "value": []}, | ||
@@ -10,0 +7,0 @@ "postMessage": {"type": "method", "value": ["object"]}, |
{ | ||
"name": "freedom", | ||
"description": "Embracing a distributed web", | ||
"version": "0.6.4", | ||
"version": "0.6.5", | ||
"homepage": "http://freedomjs.org", | ||
@@ -19,2 +19,3 @@ "bugs": { | ||
"main": "Gruntfile.js", | ||
"browser": "src/util/workerEntry.js", | ||
"devDependencies": { | ||
@@ -26,4 +27,5 @@ "browserify-istanbul": "^0.1.2", | ||
"grunt": "~0.4.3", | ||
"grunt-browserify": "^3.0.0", | ||
"grunt-browserify": "^3.2.0", | ||
"grunt-bump": "0.0.15", | ||
"grunt-codeclimate-reporter": "^1.0.0", | ||
"grunt-contrib-clean": "~0.6.0", | ||
@@ -59,2 +61,3 @@ "grunt-contrib-connect": "~0.8.0", | ||
"dependencies": { | ||
"glob": "^4.0.6", | ||
"include-folder": "^0.7.0", | ||
@@ -61,0 +64,0 @@ "node-json-minify": "^0.1.3-a" |
/*jslint indent:2,browser:true, node:true */ | ||
var PromiseCompat = require('es6-promise').Promise; | ||
var oAuthRedirectId = 'freedom.oauth.redirect.handler', | ||
listeners = {}; | ||
var oAuthRedirectId = 'freedom.oauth.redirect.handler'; | ||
function RemotePageAuth() { | ||
"use strict"; | ||
this.listeners = {}; | ||
} | ||
/** | ||
* Listen for messages from a relay iframe. | ||
* Indicate the intention to initiate an oAuth flow, allowing an appropriate | ||
* oAuth provider to begin monitoring for redirection. | ||
* | ||
* @method initiateOAuth | ||
* @param {string[]} redirectURIs - oAuth redirection URIs registered with the | ||
* provider. | ||
* @param {Function} continuation - Function to call when complete | ||
* Expected to see a value of schema: {{redirect:String, state:String}} | ||
* where 'redirect' is the chosen redirect URI | ||
* and 'state' is the state to pass to the URI on completion of oAuth | ||
* @return {Boolean} true if can handle, false otherwise | ||
*/ | ||
function monitorFrame(src, oAuth) { | ||
'use strict'; | ||
return new PromiseCompat(function (resolve, reject) { | ||
var frame = global.document.createElement('iframe'), | ||
state = oAuthRedirectId + Math.random(); | ||
frame.src = src; | ||
frame.style.display = 'none'; | ||
RemotePageAuth.prototype.initiateOAuth = function(redirectURIs, continuation) { | ||
"use strict"; | ||
if (typeof global !== 'undefined' && global && global.document) { | ||
for (var i=0; i<redirectURIs.length; i++) { | ||
// TODO: remove restriction on URL pattern match. | ||
if ((redirectURIs[i].indexOf('http://') === 0 || | ||
redirectURIs[i].indexOf('https://') === 0) && | ||
redirectURIs[i].indexOf('oauth-relay.html') > 0) { | ||
continuation({ | ||
redirect: redirectURIs[i], | ||
state: oAuthRedirectId + Math.random() | ||
}); | ||
return true; | ||
} | ||
} | ||
} | ||
return false; | ||
}; | ||
global.document.body.appendChild(frame); | ||
frame.addEventListener('load', function () { | ||
resolve({ | ||
redirect: src, | ||
state: state | ||
}); | ||
listeners[state] = function (url) { | ||
this.dispatchEvent("oAuthEvent", url); | ||
}.bind(oAuth); | ||
/** | ||
* oAuth client-side flow - launch the provided URL | ||
* This must be called after initiateOAuth with the returned state object | ||
* | ||
* @method launchAuthFlow | ||
* @param {String} authUrl - The URL that initiates the auth flow. | ||
* @param {Object.<string, string>} stateObj - The return value from initiateOAuth | ||
* @param {Function} continuation - Function to call when complete | ||
* Expected to see a String value that is the response Url containing the access token | ||
*/ | ||
RemotePageAuth.prototype.launchAuthFlow = function(authUrl, stateObj, continuation) { | ||
"use strict"; | ||
var frame = global.document.createElement('iframe'); | ||
frame.src = stateObj.redirect; | ||
frame.style.display = 'none'; | ||
frame.contentWindow.postMessage(state, '*'); | ||
}); | ||
global.document.body.appendChild(frame); | ||
frame.addEventListener('load', function () { | ||
this.listeners[stateObj.state] = continuation; | ||
window.open(authUrl); | ||
window.addEventListener('message', function (frame, msg) { | ||
if (msg.data && msg.data.key && msg.data.url && listeners[msg.data.key]) { | ||
listeners[msg.data.key](msg.data.url); | ||
try { | ||
document.body.removeChild(frame); | ||
} catch (e) { | ||
console.warn(e); | ||
} | ||
frame.contentWindow.postMessage(stateObj.state, '*'); | ||
}.bind(this)); | ||
window.addEventListener('message', function (frame, msg) { | ||
if (msg.data && msg.data.key && msg.data.url && this.listeners[msg.data.key]) { | ||
this.listeners[msg.data.key](msg.data.url); | ||
delete this.listeners[msg.data.key]; | ||
try { | ||
document.body.removeChild(frame); | ||
} catch (e) { | ||
console.warn(e); | ||
} | ||
}.bind({}, frame), false); | ||
}); | ||
} | ||
} | ||
}.bind(this, frame), false); | ||
}; | ||
@@ -49,22 +84,2 @@ /** | ||
*/ | ||
exports.register = function (OAuth) { | ||
'use strict'; | ||
if (typeof global !== 'undefined' && global && global.document) { | ||
OAuth.register(function (redirectURIs, instance) { | ||
var promises = [], i; | ||
for (i = 0; i < redirectURIs.length; i += 1) { | ||
// TODO: remove restriction on URL pattern match. | ||
if ((redirectURIs[i].indexOf('http://') === 0 || | ||
redirectURIs[i].indexOf('https://') === 0) && | ||
redirectURIs[i].indexOf('oauth-relay.html') > 0) { | ||
promises.push(monitorFrame(redirectURIs[i], instance)); | ||
} | ||
} | ||
if (promises.length) { | ||
return PromiseCompat.race(promises); | ||
} else { | ||
return false; | ||
} | ||
}); | ||
} | ||
}; | ||
module.exports = RemotePageAuth; |
@@ -1,7 +0,10 @@ | ||
var View = require('../../../providers/core/view.unprivileged'); | ||
var View = require('../../../providers/core/core.view'); | ||
var PromiseCompat = require('es6-promise').Promise; | ||
var testUtil = require('../../util'); | ||
var util = require('../../../src/util'); | ||
describe("core.view", function() { | ||
var provider, app, el; | ||
describe("core.view", function () { | ||
var provider, app, el, de; | ||
beforeEach(function() { | ||
beforeEach(function () { | ||
app = { | ||
@@ -11,2 +14,4 @@ config: { | ||
}, | ||
resource: testUtil.setupResolvers(), | ||
manifestId: 'myApp', | ||
@@ -17,3 +22,5 @@ manifest: { | ||
}; | ||
provider = new View.provider(app); | ||
de = jasmine.createSpy('dispatchEvents'); | ||
util.handleEvents(app); | ||
provider = new View.provider(app, de); | ||
@@ -25,3 +32,3 @@ el = document.createElement('div'); | ||
afterEach(function() { | ||
afterEach(function () { | ||
document.body.removeChild(el); | ||
@@ -31,35 +38,43 @@ delete el; | ||
it("Places objects and cleans up.", function() { | ||
app.manifest.views['myview'] = true; | ||
it("Places objects and cleans up.", function (done) { | ||
app.manifest.views['myview'] = { | ||
main: "relative://spec/helper/view.html", | ||
files: [] | ||
}; | ||
var cb = jasmine.createSpy('cb'); | ||
provider.open('myview', {'code': ''}, cb); | ||
expect(cb).toHaveBeenCalled(); | ||
provider.show('myview', function () { | ||
expect(el.children.length).not.toBe(0); | ||
expect(el.children.length).not.toBe(0); | ||
provider.close(cb); | ||
expect(el.innerHTML).toBe(""); | ||
provider.close(cb); | ||
expect(el.innerHTML).toBe(""); | ||
expect(cb).toHaveBeenCalled(); | ||
done(); | ||
}); | ||
}); | ||
// TODO: Understand phantom security model better. | ||
xit("Roundtrips messages", function(done) { | ||
app.manifest.views['myview'] = true; | ||
provider.dispatchEvent = jasmine.createSpy('de'); | ||
provider.dispatchEvent.and.callFake(function() { | ||
expect(provider.dispatchEvent).toHaveBeenCalledWith('message', 'msg'); | ||
it("Roundtrips messages", function (done) { | ||
app.manifest.views['myview'] = { | ||
main: "relative://spec/helper/view.html", | ||
files: [] | ||
}; | ||
var onPost = function (ret, err) { | ||
expect(err).toEqual(undefined); | ||
}; | ||
var onMessage = function (type, data) { | ||
expect(type).toEqual('message'); | ||
expect(data).toEqual('Echo: TEST'); | ||
provider.close(done); | ||
}); | ||
var sendMsg = function() { | ||
provider.postMessage('msg', function() {}); | ||
} | ||
var onShow = function() { | ||
setTimeout(sendMsg, 0); | ||
}; | ||
var onOpen = function() { | ||
provider.show(onShow); | ||
var onShow = function (ret, err) { | ||
expect(err).toEqual(undefined); | ||
de.and.callFake(onMessage); | ||
provider.postMessage('TEST', onPost); | ||
}; | ||
provider.open('myview', {'code': '<html><head><script>window.addEventListener("message", function(m) {m.source.postMessage(m.data, "*");}, true);</script></head></html>'}, onOpen); | ||
provider.show('myview', onShow); | ||
}); | ||
}); |
@@ -13,5 +13,3 @@ var testUtil = require('../../util'); | ||
setup(); | ||
for (var i=0; i<pageauths.length; i++) { | ||
pageauths[i].register(oa); | ||
} | ||
oa.register(pageauths); | ||
oauth = testUtil.directProviderFor(oa.provider.bind(oa.provider, {}), testUtil.getApis().get(oa.name).definition); | ||
@@ -26,4 +24,22 @@ }); | ||
var o = oauth(); | ||
o.on('oAuthEvent', function (url) { | ||
console.log(url); | ||
o.initiateOAuth(registeredRedirectURIs).then(function(obj) { | ||
// Cheating a little bit to avoid going through Google. | ||
// Just call the redirect URL directly e.g. | ||
// https://willscott.github.io/freedom-oauth-relay/oauth-relay.html#state=freedom.oauth.redirect.handler0.05948500754311681&access_token=ya29.rADhKXAGx0fJfB0Vx5ibQUSmMvcK9GYVZBLId42Tvn9-aQEBD5HEsbKh-5Kj_D-j09wD5axgoIkadA&token_type=Bearer&expires_in=3600 | ||
/** | ||
var url = "https://accounts.google.com/o/oauth2/auth?" + | ||
"client_id="+clientId+"&" + | ||
"response_type=token&" + | ||
"scope=email%20" + encodeURIComponent("https://www.googleapis.com/auth/userinfo.profile") + "&" + | ||
"redirect_uri=" + encodeURIComponent(obj.redirect) + "&" + | ||
"state=" + encodeURIComponent(obj.state); | ||
**/ | ||
var url = obj.redirect+"#state="+encodeURIComponent(obj.state)+ | ||
"&access_token=thisisanaccesstoken"; | ||
return o.launchAuthFlow(url, obj); | ||
}).then(function(url) { | ||
//console.log(url); | ||
expect(url).toEqual(jasmine.any(String)); | ||
@@ -42,23 +58,8 @@ var query = url.substr(url.indexOf('#') + 1); | ||
done(); | ||
}).catch(function (err) { | ||
expect(err).toBeUndefined(); | ||
}); | ||
o.initiateOAuth(registeredRedirectURIs).then(function(obj) { | ||
var url = "https://accounts.google.com/o/oauth2/auth?" + | ||
"client_id="+clientId+"&" + | ||
"response_type=token&" + | ||
"scope=email%20" + encodeURIComponent("https://www.googleapis.com/auth/userinfo.profile") + "&" + | ||
"redirect_uri=" + encodeURIComponent(obj.redirect) + "&" + | ||
"state=" + encodeURIComponent(obj.state); | ||
console.log(url); | ||
// Cheating a little bit to avoid going through Google. | ||
// Just call the redirect URL directly e.g. | ||
// https://willscott.github.io/freedom-oauth-relay/oauth-relay.html#state=freedom.oauth.redirect.handler0.05948500754311681&access_token=ya29.rADhKXAGx0fJfB0Vx5ibQUSmMvcK9GYVZBLId42Tvn9-aQEBD5HEsbKh-5Kj_D-j09wD5axgoIkadA&token_type=Bearer&expires_in=3600 | ||
window.open(obj.redirect+"#state="+encodeURIComponent(obj.state)+ | ||
"&access_token=thisisanaccesstoken"); | ||
//window.open(url); | ||
}, function (err) { | ||
expect(err).toBeUndefined(); | ||
}); | ||
}); | ||
}; |
@@ -39,7 +39,7 @@ var testUtil = require("../util"); | ||
require("./coreIntegration/oauth.integration.src").bind(this, | ||
require("../../providers/core/oauth"), | ||
require("../../providers/core/core.oauth"), | ||
[ | ||
require("../../providers/oauth/oauth.pageauth"), | ||
require("../../providers/oauth/oauth.localpageauth"), | ||
require("../../providers/oauth/oauth.remotepageauth"), | ||
], | ||
setup)); |
@@ -95,2 +95,33 @@ /*globals Blob, ArrayBuffer, DataView */ | ||
/** | ||
* Attach an 'onEvent' listener to an interface, allowing external consumers | ||
* to either listen to channel state, or register callbacks on lifetime events | ||
* of individual instances of the interface. | ||
* @method getListener | ||
* @parma {String} name The event to listen to. | ||
* @private | ||
*/ | ||
Consumer.prototype.getListener = function (name) { | ||
return function (instance, handler) { | ||
// Listen to the channel directly. | ||
if (typeof instance === 'function' && handler === undefined) { | ||
this.once(name, instance); | ||
return; | ||
} | ||
// Listen to a specific instance. | ||
var handlers = name + 'Handlers'; | ||
util.eachProp(this.ifaces, function (candidate, id) { | ||
if (candidate === instance) { | ||
if (this[handlers][id]) { | ||
this[handlers][id].push(handler); | ||
} else { | ||
this[handlers][id] = [handler]; | ||
} | ||
return true; | ||
} | ||
}.bind(this)); | ||
}.bind(this); | ||
}; | ||
/** | ||
* Create a function that can be used to get interfaces from this api consumer | ||
@@ -128,38 +159,5 @@ * from a user-visible point. | ||
func.onClose = function (iface, handler) { | ||
if (typeof iface === 'function' && handler === undefined) { | ||
// Add an on-channel-closed handler. | ||
this.once('close', iface); | ||
return; | ||
} | ||
func.onClose = this.getListener('close'); | ||
func.onError = this.getListener('error'); | ||
util.eachProp(this.ifaces, function (candidate, id) { | ||
if (candidate === iface) { | ||
if (this.closeHandlers[id]) { | ||
this.closeHandlers[id].push(handler); | ||
} else { | ||
this.closeHandlers[id] = [handler]; | ||
} | ||
return true; | ||
} | ||
}.bind(this)); | ||
}.bind(this); | ||
func.onError = function (iface, handler) { | ||
if (typeof iface === 'function' && handler === undefined) { | ||
this.on('error', iface); | ||
return; | ||
} | ||
util.eachProp(this.ifaces, function (candidate, id) { | ||
if (candidate === iface) { | ||
if (this.errorHandlers[id]) { | ||
this.errorHandlers[id].push(handler); | ||
} else { | ||
this.errorHandlers[id] = [handler]; | ||
} | ||
return true; | ||
} | ||
}.bind(this)); | ||
}.bind(this); | ||
return func; | ||
@@ -166,0 +164,0 @@ }; |
@@ -51,3 +51,7 @@ /*jslint indent:2, node:true, sloppy:true */ | ||
if (!this.config.global.console) { | ||
this.config.global.console = this.getLogger('Console'); | ||
if (typeof console !== 'undefined') { | ||
this.config.global.console = console; | ||
} else { | ||
this.config.global.console = this.getLogger('Console'); | ||
} | ||
} | ||
@@ -54,0 +58,0 @@ this.emit('ready'); |
@@ -56,4 +56,2 @@ /*jslint indent:2,node:true */ | ||
Port; | ||
Bundle.register(context.providers, api); | ||
resource.register(context.resolvers || []); | ||
@@ -68,2 +66,19 @@ if (config) { | ||
// Register user-supplied extensions. | ||
// For example the 'core.oauth' provider defines a register function, | ||
// which enables site_cfg.oauth to be registered with it. | ||
context.providers.forEach(function (provider) { | ||
if (provider.name.indexOf('core.') === 0 && | ||
typeof provider.register === 'function') { | ||
provider.register( | ||
(typeof site_cfg[provider.name.substr(5)] !== 'undefined') ? | ||
site_cfg[provider.name.substr(5)] : | ||
undefined | ||
); | ||
} | ||
}); | ||
Bundle.register(context.providers, api); | ||
resource.register(context.resolvers || []); | ||
return new PromiseCompat(function (resolve, reject) { | ||
@@ -81,11 +96,2 @@ if (site_cfg.moduleContext) { | ||
// Register user-supplied oAuth and view interfaces. | ||
if (typeof site_cfg.oauth === 'function') { | ||
context.providers.forEach(function (provider) { | ||
if (provider.name === 'core.oauth') { | ||
provider.register(site_cfg.oauth); | ||
} | ||
}); | ||
} | ||
// Define how to load a root module. | ||
@@ -92,0 +98,0 @@ var fallbackLogger, getIface; |
@@ -234,2 +234,3 @@ /*jslint indent:2,node:true,sloppy:true */ | ||
} | ||
this.emit('close'); | ||
if (this.port) { | ||
@@ -236,0 +237,0 @@ this.port.off(); |
@@ -11,12 +11,7 @@ /*jslint node:true*/ | ||
require('../../providers/core/storage.localstorage'), | ||
require('../../providers/core/view.unprivileged'), | ||
require('../../providers/core/core.view'), | ||
require('../../providers/core/core.oauth'), | ||
require('../../providers/core/websocket.unprivileged') | ||
]; | ||
var oauth = require('../../providers/core/oauth'); | ||
require('../../providers/oauth/oauth.pageauth').register(oauth); | ||
require('../../providers/oauth/oauth.remotepageauth').register(oauth); | ||
providers.push(oauth); | ||
function getFreedomScript() { | ||
@@ -51,3 +46,7 @@ 'use strict'; | ||
source: getFreedomScript(), | ||
providers: providers | ||
providers: providers, | ||
oauth: [ | ||
require('../../providers/oauth/oauth.localpageauth'), | ||
require('../../providers/oauth/oauth.remotepageauth') | ||
] | ||
}); | ||
@@ -54,0 +53,0 @@ } else { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
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
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
198
23174
1
1229660
3
32
24
+ Addedglob@^4.0.6
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addedglob@4.5.3(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedminimatch@2.0.10(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedwrappy@1.0.2(transitive)