app-tracker 1.6.1 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,30 @@
1
+ import { AppTrackerConfig } from './log';
2
+ export declare class AppTrackerService {
3
+ private sendLogsOnLocal;
4
+ private consoleLogsOnLocal;
5
+ private endpointUrl;
6
+ private apiKey;
7
+ private logs;
8
+ private sendTries;
9
+ private maxSendTries;
10
+ private isSending;
11
+ private maxLogsCount;
12
+ private userAgent;
13
+ private logLevel;
14
+ private sendLogsByTypesImmediately;
15
+ private isNode;
16
+ private os;
17
+ private isRunningLocal;
18
+ init(apiKey: string, config?: AppTrackerConfig): void;
19
+ debug(message?: string, ...optionalParams: any[]): void;
20
+ info(message?: string, ...optionalParams: any[]): void;
21
+ log(message?: string, ...optionalParams: any[]): void;
22
+ warn(message?: string, ...optionalParams: any[]): void;
23
+ error(message?: string, ...optionalParams: any[]): void;
24
+ critical(message?: string, ...optionalParams: any[]): void;
25
+ private addLog;
26
+ private logToConsole;
27
+ private sendLogsToServer;
28
+ private checkLogType;
29
+ private sendLogsToServerCore;
30
+ }
@@ -0,0 +1 @@
1
+ "use strict";var __awaiter=this&&this.__awaiter||function(e,o,s,t){return new(s||(s=Promise))((function(i,n){function r(e){try{g(t.next(e))}catch(e){n(e)}}function l(e){try{g(t.throw(e))}catch(e){n(e)}}function g(e){var o;e.done?i(e.value):(o=e.value,o instanceof s?o:new s((function(e){e(o)}))).then(r,l)}g((t=t.apply(e,o||[])).next())}))};Object.defineProperty(exports,"__esModule",{value:!0});const log_1=require("./log"),cross_fetch_1=require("cross-fetch");class AppTrackerService{constructor(){this.sendLogsOnLocal=!1,this.consoleLogsOnLocal=!1,this.endpointUrl="https://api-app-tracker.azurewebsites.net/",this.apiKey="",this.logs=[],this.sendTries=0,this.maxSendTries=5,this.isSending=!1,this.maxLogsCount=10,this.userAgent="",this.logLevel=[log_1.LogType.error],this.sendLogsByTypesImmediately=[log_1.LogType.error],this.isNode=!1,this.isRunningLocal=!0}init(e,o){var s,t,i;this.apiKey=e,o&&(o.endpointUrl&&(this.endpointUrl=o.endpointUrl),o.maxLogsCount&&(this.maxLogsCount=o.maxLogsCount),o.maxSendTries&&(this.maxSendTries=o.maxSendTries),o.sendLogsInDevelopment&&(this.sendLogsOnLocal=o.sendLogsInDevelopment),o.logInConsoleInDevelopment&&(this.consoleLogsOnLocal=o.logInConsoleInDevelopment),o.logLevel&&(this.logLevel=o.logLevel),o.sendLogsByTypesImmediately&&(this.sendLogsByTypesImmediately=o.sendLogsByTypesImmediately)),this.isNode="[object process]"===Object.prototype.toString.call("undefined"!=typeof process?process:0),this.isNode?(this.os=null===(t=o)||void 0===t?void 0:t.userAgentOrOs,this.userAgent=JSON.stringify(this.os)):this.userAgent=null===(s=o)||void 0===s?void 0:s.userAgentOrOs,this.isRunningLocal=this.isNode?(i=process.env.NODE_ENV,null!=i?i:"").indexOf("development")>-1:window.location.href.indexOf("localhost")>-1,""==e||this.isNode||this.isRunningLocal||window.addEventListener("beforeunload",(e=>{if(e.preventDefault(),e.returnValue="",!this.isSending){const e=this.logs;this.isSending=!0,this.logs=[],this.sendLogsToServerCore(e)}}))}debug(e,...o){this.addLog(log_1.LogType.debug,e,o)}info(e,...o){this.addLog(log_1.LogType.info,e,o)}log(e,...o){this.addLog(log_1.LogType.log,e,o)}warn(e,...o){this.addLog(log_1.LogType.warn,e,o)}error(e,...o){this.addLog(log_1.LogType.error,e,o)}critical(e,...o){this.addLog(log_1.LogType.critical,e,o)}addLog(e,o,s){this.checkLogType(e)?this.isRunningLocal&&!this.sendLogsOnLocal?this.logToConsole(e,o,s):this.sendLogsToServer(e,o,s):this.logToConsole(e,o,s)}logToConsole(e,o,s){if(this.consoleLogsOnLocal)switch(e){case log_1.LogType.debug:console.debug(o,s);break;case log_1.LogType.critical:case log_1.LogType.error:console.error(o,s);break;case log_1.LogType.info:console.info(o,s);break;case log_1.LogType.log:console.log(o,s);break;case log_1.LogType.warn:console.warn(o,s);break;default:console.warn("Unkown LogType: ",e)}}sendLogsToServer(e,o,...s){var t;const i={logType:e,message:o,optionalParams:[],createdAt:new Date};if(s.forEach((e=>e.forEach((e=>i.optionalParams.push(e))))),this.logs.push(i),this.logs.length>=this.maxLogsCount&&!this.isSending||null!=((null===(t=this.sendLogsByTypesImmediately)||void 0===t?void 0:t.find((o=>o==e)))||e==log_1.LogType.critical)&&!this.isSending){const e=this.logs;this.logs=[],this.isSending=!0,this.sendLogsToServerCore(e)}}checkLogType(e){return null!=this.logLevel.find((o=>o===e))||e===log_1.LogType.critical}sendLogsToServerCore(e){return __awaiter(this,void 0,void 0,(function*(){if(this.sendTries<this.maxSendTries)try{const o=this.endpointUrl.charAt(this.endpointUrl.length-1);yield cross_fetch_1.default(`${this.endpointUrl}${"/"===o?"logs/createLog":"/logs/createLog"}`,{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json","X-Auth-Key":this.apiKey},body:JSON.stringify({logs:e,userAgent:this.userAgent},((e,o)=>{if(o instanceof Error){let e={};return Object.getOwnPropertyNames(o).forEach((function(s){e[s]=o[s]})),e}return o}))});e=[],this.isSending=!1}catch(o){console.error(`AppLogger: Could not send Logs to Server try ${this.sendTries}`,o),this.sendTries++,setTimeout((()=>{this.sendLogsToServerCore(e)}),1e4)}else this.sendTries=0,this.isSending=!1,console.error("AppLogger: Could not send Logs to Server finally")}))}}exports.AppTrackerService=AppTrackerService;
package/index.d.ts CHANGED
@@ -1,47 +1,3 @@
1
- import { LogType } from './log';
2
- export declare class AppLogger {
3
- static sendLogsOnLocal: boolean;
4
- private static consoleLogsOnLocal;
5
- private static endpointUrl;
6
- private static apiKey;
7
- private static logs;
8
- private static sendTries;
9
- private static maxSendTries;
10
- private static isSending;
11
- private static maxLogsCount;
12
- private static userAgent;
13
- private static logLevel;
14
- private static sendLogsByTypesImmediately;
15
- private static isNode;
16
- private static os;
17
- private static isRunningLocal;
18
- static init(apiKey: string, config?: AppLoggerConfig): void;
19
- static debug(message?: string, ...optionalParams: any[]): void;
20
- static info(message?: string, ...optionalParams: any[]): void;
21
- static log(message?: string, ...optionalParams: any[]): void;
22
- static warn(message?: string, ...optionalParams: any[]): void;
23
- static error(message?: string, ...optionalParams: any[]): void;
24
- static critical(message?: string, ...optionalParams: any[]): void;
25
- private static addLog;
26
- private static logToConsole;
27
- private static sendLogsToServer;
28
- private static checkLogType;
29
- private static sendLogsToServerCore;
30
- private static setUserAgentFromOs;
31
- }
32
- export declare class AppLoggerConfig {
33
- sendLogsOnLocal?: boolean | undefined;
34
- consoleLogsOnLocal?: boolean | undefined;
35
- endpointUrl?: string | undefined;
36
- maxSendTries?: number | undefined;
37
- maxLogsCount?: number | undefined;
38
- /** Defines which log types should be sent to the server */
39
- logLevel?: LogType[] | undefined;
40
- sendLogsByTypesImmediately?: LogType[] | undefined;
41
- /**
42
- * Please pass:
43
- * Web -> navigator.userAgent,
44
- * Node -> os (from require('os'))
45
- */
46
- userAgentOrOs: any;
47
- }
1
+ export * from './main';
2
+ export * from './app-tracker.service';
3
+ export * from './log';
package/index.js CHANGED
@@ -1 +1,8 @@
1
- "use strict";var __awaiter=this&&this.__awaiter||function(thisArg,_arguments,P,generator){return new(P||(P=Promise))((function(resolve,reject){function fulfilled(value){try{step(generator.next(value))}catch(e){reject(e)}}function rejected(value){try{step(generator.throw(value))}catch(e){reject(e)}}function step(result){var value;result.done?resolve(result.value):(value=result.value,value instanceof P?value:new P((function(resolve){resolve(value)}))).then(fulfilled,rejected)}step((generator=generator.apply(thisArg,_arguments||[])).next())}))};Object.defineProperty(exports,"__esModule",{value:!0});const log_1=require("./log"),cross_fetch_1=require("cross-fetch");class AppLogger{static init(apiKey,config){var _a,_b;this.apiKey=apiKey,config&&(config.endpointUrl&&(this.endpointUrl=config.endpointUrl),config.maxLogsCount&&(this.maxLogsCount=config.maxLogsCount),config.maxSendTries&&(this.maxSendTries=config.maxSendTries),config.sendLogsOnLocal&&(this.sendLogsOnLocal=config.sendLogsOnLocal),config.consoleLogsOnLocal&&(this.consoleLogsOnLocal=config.consoleLogsOnLocal),config.logLevel&&(this.logLevel=config.logLevel),config.sendLogsByTypesImmediately&&(this.sendLogsByTypesImmediately=config.sendLogsByTypesImmediately)),this.isNode="[object process]"===Object.prototype.toString.call("undefined"!=typeof process?process:0),this.isNode?(this.os=null===(_b=config)||void 0===_b?void 0:_b.userAgentOrOs,this.userAgent=AppLogger.setUserAgentFromOs()):this.userAgent=null===(_a=config)||void 0===_a?void 0:_a.userAgentOrOs,this.isRunningLocal=this.isNode?this.os.hostname().indexOf("local")>-1:window.location.href.indexOf("localhost")>-1,""==apiKey||this.isNode||window.addEventListener("beforeunload",(e=>{if(e.preventDefault(),e.returnValue="",!this.isSending){const logsToSend=this.logs;this.isSending=!0,this.logs=[],AppLogger.sendLogsToServerCore(logsToSend)}}))}static debug(message,...optionalParams){AppLogger.addLog(log_1.LogType.debug,message,optionalParams)}static info(message,...optionalParams){AppLogger.addLog(log_1.LogType.info,message,optionalParams)}static log(message,...optionalParams){AppLogger.addLog(log_1.LogType.log,message,optionalParams)}static warn(message,...optionalParams){AppLogger.addLog(log_1.LogType.warn,message,optionalParams)}static error(message,...optionalParams){AppLogger.addLog(log_1.LogType.error,message,optionalParams)}static critical(message,...optionalParams){AppLogger.addLog(log_1.LogType.critical,message,optionalParams)}static addLog(type,message,optionalParams){this.checkLogType(type)?this.isRunningLocal&&!this.sendLogsOnLocal?AppLogger.logToConsole(type,message,optionalParams):AppLogger.sendLogsToServer(type,message,optionalParams):AppLogger.logToConsole(type,message,optionalParams)}static logToConsole(type,message,optionalParams){if(this.consoleLogsOnLocal)switch(type){case log_1.LogType.debug:console.debug(message,optionalParams);break;case log_1.LogType.critical:case log_1.LogType.error:console.error(message,optionalParams);break;case log_1.LogType.info:console.info(message,optionalParams);break;case log_1.LogType.log:console.log(message,optionalParams);break;case log_1.LogType.warn:console.warn(message,optionalParams);break;default:console.warn("Unkown LogType: ",type)}}static sendLogsToServer(type,message,...optionalParams){var _a;const log={logType:type,message:message,optionalParams:[],createdAt:new Date};if(optionalParams.forEach((op=>op.forEach((o=>log.optionalParams.push(o))))),this.logs.push(log),this.logs.length>=this.maxLogsCount&&!this.isSending||null!=((null===(_a=this.sendLogsByTypesImmediately)||void 0===_a?void 0:_a.find((l=>l==type)))||type==log_1.LogType.critical)&&!this.isSending){const logsToSend=this.logs;this.logs=[],this.isSending=!0,AppLogger.sendLogsToServerCore(logsToSend)}}static checkLogType(type){return null!=this.logLevel.find((l=>l===type))||type===log_1.LogType.critical}static sendLogsToServerCore(logsToSend){return __awaiter(this,void 0,void 0,(function*(){if(this.sendTries<this.maxSendTries)try{const last=this.endpointUrl.charAt(this.endpointUrl.length-1);yield cross_fetch_1.default(`${this.endpointUrl}${"/"===last?"logs/createLog":"/logs/createLog"}`,{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json","X-Auth-Key":this.apiKey},body:JSON.stringify({logs:logsToSend,userAgent:this.userAgent},((key,value)=>{if(value instanceof Error){let error={};return Object.getOwnPropertyNames(value).forEach((function(key){error[key]=value[key]})),error}return value}))});logsToSend=[],this.isSending=!1}catch(error){console.error(`AppLogger: Could not send Logs to Server try ${this.sendTries}`,error),this.sendTries++,setTimeout((()=>{AppLogger.sendLogsToServerCore(logsToSend)}),1e4)}else this.sendTries=0,this.isSending=!1,console.error("AppLogger: Could not send Logs to Server finally")}))}static setUserAgentFromOs(){const osInfo={arch:this.os.arch(),cpus:this.os.cpus(),endianness:this.os.endianness(),freemem:this.os.freemem(),homedir:this.os.homedir(),hostname:this.os.hostname(),loadavg:this.os.loadavg(),networkInterfaces:this.os.networkInterfaces(),platform:this.os.platform(),release:this.os.release(),tmpdir:this.os.tmpdir(),totalmem:this.os.totalmem(),type:this.os.type(),uptime:this.os.uptime(),userInfo:this.os.userInfo(),version:this.os.version()};return JSON.stringify(osInfo)}}exports.AppLogger=AppLogger,AppLogger.sendLogsOnLocal=!1,AppLogger.consoleLogsOnLocal=!1,AppLogger.endpointUrl="https://api-app-tracker.azurewebsites.net/",AppLogger.apiKey="",AppLogger.logs=[],AppLogger.sendTries=0,AppLogger.maxSendTries=5,AppLogger.isSending=!1,AppLogger.maxLogsCount=10,AppLogger.logLevel=[log_1.LogType.error],AppLogger.sendLogsByTypesImmediately=[log_1.LogType.error],AppLogger.isNode=!1;class AppLoggerConfig{constructor(){this.maxLogsCount=5,this.sendLogsByTypesImmediately=[log_1.LogType.error]}}exports.AppLoggerConfig=AppLoggerConfig;
1
+ "use strict";
2
+ function __export(m) {
3
+ for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
4
+ }
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ __export(require("./main"));
7
+ __export(require("./app-tracker.service"));
8
+ __export(require("./log"));
package/log.d.ts CHANGED
@@ -1,3 +1,20 @@
1
+ export declare class AppTrackerConfig {
2
+ /** Should logs in the development environment be sent to the server. For Node enviroment process.env.NODE_ENV must be set to 'development' */
3
+ sendLogsInDevelopment?: boolean | undefined;
4
+ logInConsoleInDevelopment?: boolean | undefined;
5
+ endpointUrl?: string | undefined;
6
+ maxSendTries?: number | undefined;
7
+ maxLogsCount?: number | undefined;
8
+ /** Defines which log types should be sent to the server */
9
+ logLevel?: LogType[] | undefined;
10
+ sendLogsByTypesImmediately?: LogType[] | undefined;
11
+ /**
12
+ * Please pass:
13
+ * Web -> navigator.userAgent,
14
+ * Node -> os (from require('os'))
15
+ */
16
+ userAgentOrOs: any;
17
+ }
1
18
  export declare class Log {
2
19
  logType: LogType;
3
20
  message: any;
package/log.js CHANGED
@@ -1,19 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- class Log {
4
- constructor() {
5
- this.logType = LogType.log;
6
- this.optionalParams = [];
7
- this.createdAt = new Date();
8
- }
9
- }
10
- exports.Log = Log;
11
- var LogType;
12
- (function (LogType) {
13
- LogType[LogType["debug"] = 0] = "debug";
14
- LogType[LogType["info"] = 1] = "info";
15
- LogType[LogType["log"] = 2] = "log";
16
- LogType[LogType["warn"] = 3] = "warn";
17
- LogType[LogType["error"] = 4] = "error";
18
- LogType[LogType["critical"] = 5] = "critical";
19
- })(LogType = exports.LogType || (exports.LogType = {}));
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});class AppTrackerConfig{constructor(){this.maxLogsCount=5,this.sendLogsByTypesImmediately=[LogType.error]}}exports.AppTrackerConfig=AppTrackerConfig;class Log{constructor(){this.logType=LogType.log,this.optionalParams=[],this.createdAt=new Date}}var LogType;exports.Log=Log,function(o){o[o.debug=0]="debug",o[o.info=1]="info",o[o.log=2]="log",o[o.warn=3]="warn",o[o.error=4]="error",o[o.critical=5]="critical"}(LogType=exports.LogType||(exports.LogType={}));
package/main.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ import { AppTrackerService } from './app-tracker.service';
2
+ import { AppTrackerConfig } from './log';
3
+ export declare class AppTracker {
4
+ private static _service;
5
+ private static get service();
6
+ static init(apiKey: string, config?: AppTrackerConfig): AppTrackerService;
7
+ }
package/main.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});const app_tracker_service_1=require("./app-tracker.service");class AppTracker{static get service(){return this._service||(this._service=new app_tracker_service_1.AppTrackerService),this._service}static init(e,r){return AppTracker.service.init(e,r),this.service}}exports.AppTracker=AppTracker,AppTracker._service=null;
package/package.json CHANGED
@@ -1,20 +1,21 @@
1
1
  {
2
2
  "name": "app-tracker",
3
- "version": "1.6.1",
4
- "description": "App Tracker Package for the App Tracker Web-Application",
3
+ "version": "2.0.1",
4
+ "description": "App Tracker for Web-Applications",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
7
  "build": "tsc && npm run copyFile",
8
8
  "copyFile": "xcopy package.json lib && xcopy README.md lib && npm run terser",
9
- "terser": "terser lib/index.js --compress -o lib/index.js",
9
+ "terser": "terser lib/main.js -c -m -o lib/main.js && terser lib/log.js -c -m -o lib/log.js && terser lib/app-tracker.service.js -c -m -o lib/app-tracker.service.js",
10
10
  "format": "prettier --write \"src/**/*.ts\" \"src/**/*.js\"",
11
11
  "lint": "tslint -p tsconfig.json"
12
12
  },
13
13
  "keywords": [],
14
- "author": "Wigtertainment Ltd",
14
+ "author": "Egor Kin",
15
15
  "license": "ISC",
16
16
  "devDependencies": {
17
17
  "@types/node": "^17.0.10",
18
+ "parcel": "^2.7.0",
18
19
  "prettier": "^1.19.1",
19
20
  "tslint": "^5.20.1",
20
21
  "tslint-config-prettier": "^1.18.0",
package/os-node.d.ts DELETED
@@ -1,4 +0,0 @@
1
- export declare class NodeOs {
2
- constructor();
3
- os: any;
4
- }
package/os-node.js DELETED
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- class NodeOs {
4
- constructor() {
5
- this.os = null;
6
- this.os = require('os');
7
- }
8
- }
9
- exports.NodeOs = NodeOs;