app-tracker 1.1.11 → 1.3.2

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.
package/index.d.ts CHANGED
@@ -7,6 +7,8 @@ export declare class AppLogger {
7
7
  static log(message?: string, ...optionalParams: any[]): void;
8
8
  static warn(message?: string, ...optionalParams: any[]): void;
9
9
  static error(message?: string, ...optionalParams: any[]): void;
10
+ private static addLog;
11
+ private static logToConsole;
10
12
  private static endpointUrl;
11
13
  private static apiKey;
12
14
  private static logs;
@@ -16,6 +18,7 @@ export declare class AppLogger {
16
18
  private static maxLogsCount;
17
19
  private static userAgent;
18
20
  private static logLevel;
21
+ private static sendLogsByTypesImmediately;
19
22
  private static isRunningLocal;
20
23
  private static sendLogsToServer;
21
24
  private static checkLogType;
@@ -24,10 +27,9 @@ export declare class AppLogger {
24
27
  export declare class AppLoggerConfig {
25
28
  sendLogsOnLocal?: boolean | undefined;
26
29
  endpointUrl?: string | undefined;
27
- sendTries?: number | undefined;
28
30
  maxSendTries?: number | undefined;
29
- isSending?: boolean | undefined;
30
31
  maxLogsCount?: number | undefined;
31
32
  /** Defines which log types should be sent to the server */
32
33
  logLevel?: LogType[] | undefined;
34
+ sendLogsByTypesImmediately?: LogType[] | undefined;
33
35
  }
package/index.js CHANGED
@@ -1 +1 @@
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");class AppLogger{static init(apiKey,config){this.apiKey=apiKey,config&&(config.endpointUrl&&(this.endpointUrl=config.endpointUrl),config.isSending&&(this.isSending=config.isSending),config.maxLogsCount&&(this.maxLogsCount=config.maxLogsCount),config.maxSendTries&&(this.maxSendTries=config.maxSendTries),config.sendLogsOnLocal&&(this.sendLogsOnLocal=config.sendLogsOnLocal),config.sendTries&&(this.sendTries=config.sendTries),config.logLevel&&(this.logLevel=config.logLevel)),this.userAgent=navigator.userAgent}static debug(message,...optionalParams){!this.isRunningLocal()||this.sendLogsOnLocal||this.checkLogType(log_1.LogType.debug)?this.sendLogsToServer(log_1.LogType.debug,message,optionalParams):console.debug(message,optionalParams)}static info(message,...optionalParams){!this.isRunningLocal()||this.sendLogsOnLocal||this.checkLogType(log_1.LogType.info)?this.sendLogsToServer(log_1.LogType.info,message,optionalParams):console.info(message,optionalParams)}static log(message,...optionalParams){!this.isRunningLocal()||this.sendLogsOnLocal||this.checkLogType(log_1.LogType.log)?this.sendLogsToServer(log_1.LogType.log,message,optionalParams):console.log(message,optionalParams)}static warn(message,...optionalParams){!this.isRunningLocal()||this.sendLogsOnLocal||this.checkLogType(log_1.LogType.warn)?this.sendLogsToServer(log_1.LogType.warn,message,optionalParams):console.warn(message,optionalParams)}static error(message,...optionalParams){!this.isRunningLocal()||this.sendLogsOnLocal||this.checkLogType(log_1.LogType.error)?this.sendLogsToServer(log_1.LogType.error,message,optionalParams):console.error(message,optionalParams)}static isRunningLocal(){return window.location.href.indexOf("localhost")>0}static sendLogsToServer(type,message,...optionalParams){console.warn("APP-Logger.sendLogsToServer -> test log",optionalParams);const log={logType:type,message:message,optionalParams:[]};if(optionalParams.forEach((op=>op.forEach((o=>log.optionalParams.push(o))))),console.warn("APP-Logger.sendLogsToServer -> created Log",log),this.logs.push(log),this.logs.length>this.maxLogsCount&&!this.isSending){const logsToSend=this.logs;this.isSending=!0,this.logs=[],this.sendLogsToServerCore(logsToSend,type)}}static checkLogType(type){return console.log("checkLogType:",type),null!=this.logLevel.find((l=>l===type))&&(console.log("checkLogType selected LogTypes:",this.logLevel),!0)}static sendLogsToServerCore(logsToSend,type){return __awaiter(this,void 0,void 0,(function*(){if(this.sendTries<this.maxSendTries)try{yield fetch(`${this.endpointUrl}`,{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify({logs:logsToSend,apiKey:this.apiKey,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){this.sendTries++,setTimeout((()=>{this.sendLogsToServerCore(logsToSend,type)}),1e4)}else this.sendTries=0,this.isSending=!1,console.error("AppLogger: Could not send Logs to Server")}))}}exports.AppLogger=AppLogger,AppLogger.sendLogsOnLocal=!1,AppLogger.endpointUrl="",AppLogger.apiKey="",AppLogger.logs=[],AppLogger.sendTries=0,AppLogger.maxSendTries=5,AppLogger.isSending=!1,AppLogger.maxLogsCount=100,AppLogger.logLevel=[log_1.LogType.error];class AppLoggerConfig{}exports.AppLoggerConfig=AppLoggerConfig;
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");class AppLogger{static init(apiKey,config){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.logLevel&&(this.logLevel=config.logLevel),config.sendLogsByTypesImmediately&&(this.sendLogsByTypesImmediately=config.sendLogsByTypesImmediately));const isNode="[object process]"===Object.prototype.toString.call("undefined"!=typeof process?process:0);this.userAgent=isNode?JSON.stringify({client:{type:"Backend Server"}}):navigator.userAgent,""!=apiKey&&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 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){switch(type){case log_1.LogType.debug:console.debug(message,optionalParams);break;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 isRunningLocal(){return window.location.href.indexOf("localhost")>0}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)))&&!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))}static sendLogsToServerCore(logsToSend){return __awaiter(this,void 0,void 0,(function*(){if(this.sendTries<this.maxSendTries)try{yield fetch(`${this.endpointUrl}`,{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){this.sendTries++,setTimeout((()=>{AppLogger.sendLogsToServerCore(logsToSend)}),1e4)}else this.sendTries=0,this.isSending=!1,console.error("AppLogger: Could not send Logs to Server")}))}}exports.AppLogger=AppLogger,AppLogger.sendLogsOnLocal=!1,AppLogger.endpointUrl="",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];class AppLoggerConfig{constructor(){this.maxLogsCount=5,this.sendLogsByTypesImmediately=[log_1.LogType.error]}}exports.AppLoggerConfig=AppLoggerConfig;
package/log.d.ts CHANGED
@@ -2,6 +2,7 @@ export declare class Log {
2
2
  logType: LogType;
3
3
  message: any;
4
4
  optionalParams: any[];
5
+ createdAt: Date;
5
6
  }
6
7
  export declare enum LogType {
7
8
  debug = 0,
package/log.js CHANGED
@@ -4,6 +4,7 @@ class Log {
4
4
  constructor() {
5
5
  this.logType = LogType.log;
6
6
  this.optionalParams = [];
7
+ this.createdAt = new Date();
7
8
  }
8
9
  }
9
10
  exports.Log = Log;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "app-tracker",
3
- "version": "1.1.11",
3
+ "version": "1.3.2",
4
4
  "description": "App Tracker for Web-Applications",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -14,6 +14,7 @@
14
14
  "author": "Egor Kin",
15
15
  "license": "ISC",
16
16
  "devDependencies": {
17
+ "@types/node": "^17.0.10",
17
18
  "prettier": "^1.19.1",
18
19
  "tslint": "^5.20.1",
19
20
  "tslint-config-prettier": "^1.18.0",