🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

@yqg/monitor

Package Overview
Dependencies
Maintainers
4
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@yqg/monitor - npm Package Compare versions

Comparing version
0.0.1
to
0.0.2
+49
dist/yqg-monitor.js
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global.YqgMonitor = factory());
}(this, (function () { 'use strict';
var objectToUrlParams = function (data) { return (Object
.keys(data)
.map(function (key) {
var value = encodeURIComponent(data[key]);
return key + "=" + value;
})
.join('&')); };
var imageGet = function (path, data) { return new Promise(function (resolve) {
if (!document)
resolve();
// create image element to send request
var imgEle = new Image();
var params = Object.assign(data, { _timestamp: Date.now() });
imgEle.src = path + "?" + objectToUrlParams(data);
// no matter request successed or failed, resolve the promise as if nothing happened
var callbackHandler = function () {
resolve();
};
imgEle.onload = callbackHandler;
imgEle.onerror = callbackHandler;
}); };
var reportPath = '/mayuri/api/monitor/report';
var YqgMonitor = (function () {
function YqgMonitor(projectKey, options) {
this.projectKey = projectKey;
this.options = options;
}
YqgMonitor.prototype.report = function (moduleKey, eventKey, data) {
var _a = this, projectKey = _a.projectKey, apiHost = _a.options.apiHost;
var path = "" + apiHost + reportPath;
try {
imageGet(path, Object.assign(data, { projectKey, moduleKey, eventKey }));
}
catch (err) {
}
};
return YqgMonitor;
}());
return YqgMonitor;
})));
const objectToUrlParams = (data: object): string => (
Object
.keys(data)
.map((key) => {
const value = encodeURIComponent(data[key]);
return `${key}=${value}`;
})
.join('&')
);
export const imageGet = (path: string, data: object): Promise<any> => new Promise((resolve) => {
if (!document) resolve();
// create image element to send request
const imgEle: HTMLImageElement = new Image();
const params: object = Object.assign(data, {_timestamp: Date.now()});
imgEle.src = `${path}?${objectToUrlParams(data)}`;
// no matter request successed or failed, resolve the promise as if nothing happened
const callbackHandler = (): void => {
resolve();
};
imgEle.onload = callbackHandler;
imgEle.onerror = callbackHandler;
});
import {imageGet} from './helper/helper';
const reportPath: string = '/mayuri/api/monitor/report';
interface MonitorOptions {
apiHost: string;
}
class YqgMonitor {
constructor(private projectKey: string, private options: MonitorOptions) {}
report(moduleKey: string, eventKey: string, data: object): void {
const {projectKey, options: {apiHost}} = this;
const path = `${apiHost}${reportPath}`;
try {
imageGet(path, Object.assign(data, {projectKey, moduleKey, eventKey}));
} catch (err) {
// doing nothing
}
}
}
export default YqgMonitor;
+3
-6
{
"name": "@yqg/monitor",
"version": "0.0.1",
"main": "dist/monitor.js",
"version": "0.0.2",
"main": "dist/yqg-monitor.js",
"typings": "index.d.ts",
"devDependencies": {
"@babel/core": "7.0.0-beta.47",
"@babel/preset-env": "7.0.0-beta.47",
"@babel/preset-stage-3": "7.0.0-beta.47",
"rollup": "0.59.4",
"rollup-plugin-babel": "4.0.0-beta.0"
"rollup-plugin-typescript": "0.8.1"
},

@@ -13,0 +10,0 @@ "scripts": {

@@ -7,2 +7,19 @@ /**

export default {}; // To be continued
import typescript from 'rollup-plugin-typescript';
export default {
entry: './src/yqg-monitor.ts',
output: {
file: 'dist/yqg-monitor.js',
format: 'umd',
name: 'YqgMonitor'
},
plugins: [
typescript({
target: 'es5',
module: 'es2015'
})
]
};