lightkeeper
Advanced tools
Comparing version 1.1.3 to 1.1.4
@@ -10,3 +10,3 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
root["pharos"] = factory(); | ||
})(this, function() { | ||
})(typeof self !== 'undefined' ? self : this, function() { | ||
return /******/ (function(modules) { // webpackBootstrap | ||
@@ -197,2 +197,4 @@ /******/ // The module cache | ||
function Pharos(site_id, host) { | ||
var opt = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
_classCallCheck(this, Pharos); | ||
@@ -204,8 +206,32 @@ | ||
this[PERF] = this.addPerf(); | ||
this.listenError(opt); | ||
} | ||
_createClass(Pharos, [{ | ||
key: 'listenError', | ||
value: function listenError(_ref) { | ||
var _this = this; | ||
var onError = _ref.onError; | ||
if (!global.addEventListener) { | ||
return; | ||
} | ||
global.addEventListener('error', function (err) { | ||
if (!err) return; | ||
var message = err.error && err.error.stack || err.message; | ||
if (typeof onError === 'function') { | ||
message = onError(err); | ||
} | ||
if (!message) return; | ||
_this.send(message); | ||
}); | ||
} | ||
}, { | ||
key: 'addPerf', | ||
value: function addPerf() { | ||
var _this = this; | ||
var _this2 = this; | ||
@@ -215,6 +241,6 @@ return new Promise(function (resolve) { | ||
return setTimeout(function () { | ||
_this.add(performance()); | ||
_this2.add(performance()); | ||
resolve(); | ||
_this[PERF] = Promise.resolve(); | ||
_this2[PERF] = Promise.resolve(); | ||
}); | ||
@@ -227,6 +253,6 @@ }); | ||
value: function monitor(info) { | ||
var _this2 = this; | ||
var _this3 = this; | ||
return this[PERF].then(function () { | ||
return _this2.send(info); | ||
return _this3.send(info); | ||
}); | ||
@@ -244,6 +270,11 @@ } | ||
var params = { | ||
info: {}, | ||
site_id: this.site_id, | ||
info: util.isEmpty(info) ? this[INFO] : info, | ||
screen: global.screen.width + 'x' + global.screen.height | ||
}; | ||
if (typeof info === 'string') { | ||
params.error = info; | ||
} else { | ||
params.info = util.isEmpty(info) ? this[INFO] : info; | ||
} | ||
util.sendLog(baseUrl + util.build_query(params)); | ||
@@ -250,0 +281,0 @@ } |
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.pharos=e():t.pharos=e()}(this,function(){return function(t){function e(o){if(n[o])return n[o].exports;var r=n[o]={i:o,l:!1,exports:{}};return t[o].call(r.exports,r,r.exports,e),r.l=!0,r.exports}var n={};return e.m=t,e.c=n,e.d=function(t,n,o){e.o(t,n)||Object.defineProperty(t,n,{configurable:!1,enumerable:!0,get:o})},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,"a",n),n},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=2)}([function(t,e){var n;n=function(){return this}();try{n=n||Function("return this")()||(0,eval)("this")}catch(t){"object"==typeof window&&(n=window)}t.exports=n},function(t,e,n){"use strict";(function(t){var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t};e.isNumber=function(t){return!isNaN(t)&&"number"==typeof t},e.isEmpty=function(t){return"object"===(void 0===t?"undefined":n(t))?"{}"===JSON.stringify(t):!t},e.build_query=function(t){var e=[];for(var o in t){var r=t[o];"object"===(void 0===r?"undefined":n(r))&&(r=JSON.stringify(r)),e.push(encodeURIComponent(o)+"="+encodeURIComponent(r))}return e.join("&")},e.getPerformance=function(){var e=t.performance;return e||console.log("Browser doesn't support Performance API"),e},e.sendLog=function(e){e&&(t.sadLog=new Image,t.sadLog.onload=t.sadLog.onerror=function(){delete t.sadLog},t.sadLog.src=e)}}).call(e,n(0))},function(t,e,n){"use strict";(function(e){var o=n(3),r=new o;e.addEventListener("load",function(){var t=document.querySelector("script[data-siteid][data-host]");r.site_id=t.getAttribute("data-siteid"),r.host=t.getAttribute("data-host")}),t.exports=r}).call(e,n(0))},function(t,e,n){"use strict";(function(e){function o(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function r(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}var i=function(){function t(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}return function(e,n,o){return n&&t(e.prototype,n),o&&t(e,o),e}}(),a=n(1),u=n(4),c="info",s="addPerfData",d={};t.exports=function(){function t(e,n){r(this,t),this.site_id=e,this.host=n,this[c]={},this[s]=this.addPerf()}return i(t,[{key:"addPerf",value:function(){var t=this;return new Promise(function(n){return e.addEventListener("load",function(){return setTimeout(function(){t.add(u()),n(),t[s]=Promise.resolve()})})})}},{key:"monitor",value:function(t){var e=this;return this[s].then(function(){return e.send(t)})}},{key:"send",value:function(t){var n=this.host;/^(http|\/\/)/i.test(n)||(n=location.protocol+"//"+n);var o=n+"/api/disp?",r={site_id:this.site_id,info:a.isEmpty(t)?this[c]:t,screen:e.screen.width+"x"+e.screen.height};a.sendLog(o+a.build_query(r))}},{key:"time",value:function(t){d[t]=Date.now()}},{key:"timeEnd",value:function(t){var e=Date.now();d[t]||(d[t]=e);var n=e-d[t];this.add(t,n),console.log(t+": "+n+"ms"),delete d[t]}},{key:"add",value:function(t,e){var n=t;a.isNumber(e)&&(n=o({},t,e));for(var r in n)a.isNumber(n[r])&&(this[c][r]=n[r]);return!0}},{key:"delete",value:function(){for(var t=arguments.length,e=Array(t),n=0;n<t;n++)e[n]=arguments[n];for(var o=0;o<e.length;o++)delete this[c][e[o]];return!0}},{key:"clear",value:function(){var t={};for(var e in this[c])t[e]=this[c][e],this.delete(e);return t}},{key:"search",value:function(t){return this[c][t]}}]),t}()}).call(e,n(0))},function(t,e,n){"use strict";var o=n(1);t.exports=function(){var t=o.getPerformance();if(!t)return{};var e=t.timing,n={};return n.loadPage=e.loadEventEnd-e.navigationStart,n.domReady=e.domComplete-e.responseEnd,n.redirect=e.redirectEnd-e.redirectStart,n.lookupDomain=e.domainLookupEnd-e.domainLookupStart,n.ttfb=e.responseStart-e.navigationStart,n.request=e.responseEnd-e.requestStart,n.loadEvent=e.loadEventEnd-e.loadEventStart,n.appcache=e.domainLookupStart-e.fetchStart,n.unloadEvent=e.unloadEventEnd-e.unloadEventStart,n.connect=e.connectEnd-e.connectStart,n}}])}); | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.pharos=e():t.pharos=e()}("undefined"!=typeof self?self:this,function(){return function(t){function e(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,e),o.l=!0,o.exports}var n={};return e.m=t,e.c=n,e.d=function(t,n,r){e.o(t,n)||Object.defineProperty(t,n,{configurable:!1,enumerable:!0,get:r})},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,"a",n),n},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=2)}([function(t,e){var n;n=function(){return this}();try{n=n||Function("return this")()||(0,eval)("this")}catch(t){"object"==typeof window&&(n=window)}t.exports=n},function(t,e,n){"use strict";(function(t){var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t};e.isNumber=function(t){return!isNaN(t)&&"number"==typeof t},e.isEmpty=function(t){return"object"===(void 0===t?"undefined":n(t))?"{}"===JSON.stringify(t):!t},e.build_query=function(t){var e=[];for(var r in t){var o=t[r];"object"===(void 0===o?"undefined":n(o))&&(o=JSON.stringify(o)),e.push(encodeURIComponent(r)+"="+encodeURIComponent(o))}return e.join("&")},e.getPerformance=function(){var e=t.performance;return e||console.log("Browser doesn't support Performance API"),e},e.sendLog=function(e){e&&(t.sadLog=new Image,t.sadLog.onload=t.sadLog.onerror=function(){delete t.sadLog},t.sadLog.src=e)}}).call(e,n(0))},function(t,e,n){"use strict";(function(e){var r=n(3),o=new r;e.addEventListener("load",function(){var t=document.querySelector("script[data-siteid][data-host]");o.site_id=t.getAttribute("data-siteid"),o.host=t.getAttribute("data-host")}),t.exports=o}).call(e,n(0))},function(t,e,n){"use strict";(function(e){function r(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function o(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}var i=function(){function t(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),e}}(),a=n(1),u=n(4),s="info",c="addPerfData",f={};t.exports=function(){function t(e,n){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};o(this,t),this.site_id=e,this.host=n,this[s]={},this[c]=this.addPerf(),this.listenError(r)}return i(t,[{key:"listenError",value:function(t){var n=this,r=t.onError;e.addEventListener&&e.addEventListener("error",function(t){if(t){var e=t.error&&t.error.stack||t.message;"function"==typeof r&&(e=r(t)),e&&n.send(e)}})}},{key:"addPerf",value:function(){var t=this;return new Promise(function(n){return e.addEventListener("load",function(){return setTimeout(function(){t.add(u()),n(),t[c]=Promise.resolve()})})})}},{key:"monitor",value:function(t){var e=this;return this[c].then(function(){return e.send(t)})}},{key:"send",value:function(t){var n=this.host;/^(http|\/\/)/i.test(n)||(n=location.protocol+"//"+n);var r=n+"/api/disp?",o={info:{},site_id:this.site_id,screen:e.screen.width+"x"+e.screen.height};"string"==typeof t?o.error=t:o.info=a.isEmpty(t)?this[s]:t,a.sendLog(r+a.build_query(o))}},{key:"time",value:function(t){f[t]=Date.now()}},{key:"timeEnd",value:function(t){var e=Date.now();f[t]||(f[t]=e);var n=e-f[t];this.add(t,n),console.log(t+": "+n+"ms"),delete f[t]}},{key:"add",value:function(t,e){var n=t;a.isNumber(e)&&(n=r({},t,e));for(var o in n)a.isNumber(n[o])&&(this[s][o]=n[o]);return!0}},{key:"delete",value:function(){for(var t=arguments.length,e=Array(t),n=0;n<t;n++)e[n]=arguments[n];for(var r=0;r<e.length;r++)delete this[s][e[r]];return!0}},{key:"clear",value:function(){var t={};for(var e in this[s])t[e]=this[s][e],this.delete(e);return t}},{key:"search",value:function(t){return this[s][t]}}]),t}()}).call(e,n(0))},function(t,e,n){"use strict";var r=n(1);t.exports=function(){var t=r.getPerformance();if(!t)return{};var e=t.timing,n={};return n.loadPage=e.loadEventEnd-e.navigationStart,n.domReady=e.domComplete-e.responseEnd,n.redirect=e.redirectEnd-e.redirectStart,n.lookupDomain=e.domainLookupEnd-e.domainLookupStart,n.ttfb=e.responseStart-e.navigationStart,n.request=e.responseEnd-e.requestStart,n.loadEvent=e.loadEventEnd-e.loadEventStart,n.appcache=e.domainLookupStart-e.fetchStart,n.unloadEvent=e.unloadEventEnd-e.unloadEventStart,n.connect=e.connectEnd-e.connectStart,n}}])}); |
@@ -18,2 +18,4 @@ 'use strict'; | ||
function Pharos(site_id, host) { | ||
var opt = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
_classCallCheck(this, Pharos); | ||
@@ -25,8 +27,32 @@ | ||
this[PERF] = this.addPerf(); | ||
this.listenError(opt); | ||
} | ||
_createClass(Pharos, [{ | ||
key: 'listenError', | ||
value: function listenError(_ref) { | ||
var _this = this; | ||
var onError = _ref.onError; | ||
if (!global.addEventListener) { | ||
return; | ||
} | ||
global.addEventListener('error', function (err) { | ||
if (!err) return; | ||
var message = err.error && err.error.stack || err.message; | ||
if (typeof onError === 'function') { | ||
message = onError(err); | ||
} | ||
if (!message) return; | ||
_this.send(message); | ||
}); | ||
} | ||
}, { | ||
key: 'addPerf', | ||
value: function addPerf() { | ||
var _this = this; | ||
var _this2 = this; | ||
@@ -36,6 +62,6 @@ return new Promise(function (resolve) { | ||
return setTimeout(function () { | ||
_this.add(performance()); | ||
_this2.add(performance()); | ||
resolve(); | ||
_this[PERF] = Promise.resolve(); | ||
_this2[PERF] = Promise.resolve(); | ||
}); | ||
@@ -48,6 +74,6 @@ }); | ||
value: function monitor(info) { | ||
var _this2 = this; | ||
var _this3 = this; | ||
return this[PERF].then(function () { | ||
return _this2.send(info); | ||
return _this3.send(info); | ||
}); | ||
@@ -65,6 +91,11 @@ } | ||
var params = { | ||
info: {}, | ||
site_id: this.site_id, | ||
info: util.isEmpty(info) ? this[INFO] : info, | ||
screen: global.screen.width + 'x' + global.screen.height | ||
}; | ||
if (typeof info === 'string') { | ||
params.error = info; | ||
} else { | ||
params.info = util.isEmpty(info) ? this[INFO] : info; | ||
} | ||
util.sendLog(baseUrl + util.build_query(params)); | ||
@@ -71,0 +102,0 @@ } |
{ | ||
"name": "lightkeeper", | ||
"version": "1.1.3", | ||
"version": "1.1.4", | ||
"description": "Pharos data send script for Web.", | ||
@@ -5,0 +5,0 @@ "main": "lib/pharos.js", |
@@ -1,4 +0,4 @@ | ||
const {test} = require('ava'); | ||
const { test } = require('ava'); | ||
test('main normal', t => { | ||
t.plan(7); | ||
t.plan(8); | ||
global.document = { | ||
@@ -21,3 +21,3 @@ querySelector(selector) { | ||
global.addEventListener = (event, cb) => { | ||
t.is(event, 'load'); | ||
t.true(['load', 'error'].includes(event)); | ||
cb(); | ||
@@ -24,0 +24,0 @@ }; |
@@ -1,6 +0,6 @@ | ||
const {test} = require('ava'); | ||
const { test } = require('ava'); | ||
const mock = require('mock-require'); | ||
const Pharos = require('../src/pharos'); | ||
global.location = {protocol: 'https:'}; | ||
global.location = { protocol: 'https:' }; | ||
const timeout = (cb, t) => new Promise(resolve => { | ||
@@ -15,7 +15,7 @@ setTimeout(function() { | ||
global.addEventListener = (event, cb) => { | ||
t.is(event, 'load'); | ||
t.true(['load', 'error'].includes(event)); | ||
cb(); | ||
}; | ||
t.plan(6); | ||
t.plan(8); | ||
let pharos = new Pharos(); | ||
@@ -31,9 +31,9 @@ t.is(pharos.site_id, undefined); | ||
test('pharos in stance add performance default', async t => { | ||
t.plan(2); | ||
t.plan(3); | ||
mock('../src/performance', function() { | ||
return {a: 1}; | ||
return { a: 1 }; | ||
}); | ||
const Pharos = mock.reRequire('../src/pharos'); | ||
global.addEventListener = (event, cb) => { | ||
t.is(event, 'load'); | ||
t.true(['load', 'error'].includes(event)); | ||
cb(); | ||
@@ -71,4 +71,4 @@ }; | ||
[1, 1], | ||
[{aaa: '3'}, 1], | ||
[{aaa: 33}, 33] | ||
[{ aaa: '3' }, 1], | ||
[{ aaa: 33 }, 33] | ||
]; | ||
@@ -142,3 +142,3 @@ t.plan(cases.length); | ||
global.addEventListener = (event, cb) => cb(); | ||
global.screen = {width: 200, height: 200}; | ||
global.screen = { width: 200, height: 200 }; | ||
let i = 0; | ||
@@ -192,4 +192,4 @@ | ||
pharos.host = 'pharos.eming.li'; | ||
await pharos.monitor({a: 1, b: 2}); | ||
await pharos.monitor({ a: 1, b: 2 }); | ||
mock.stopAll(); | ||
}); |
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 not supported yet
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 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
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
160342
1380