app-tracker 1.1.10 → 1.3.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.
- package/index.d.ts +4 -2
- package/index.js +1 -1
- package/log.d.ts +1 -0
- package/log.js +1 -0
- package/package.json +2 -2
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.
|
|
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)),navigator?this.userAgent=navigator.userAgent:this.userAgent=JSON.stringify({client:{type:"Backend Server"}}),""!=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
package/log.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "app-tracker",
|
|
3
|
-
"version": "1.1
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"description": "App Tracker for Web-Applications",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -19,4 +19,4 @@
|
|
|
19
19
|
"tslint-config-prettier": "^1.18.0",
|
|
20
20
|
"typescript": "^3.7.3"
|
|
21
21
|
}
|
|
22
|
-
}
|
|
22
|
+
}
|