app-tracker 2.0.3 → 2.1.0

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/README.md CHANGED
@@ -1 +1,41 @@
1
- # App Tracker for Web Applications
1
+ # App Tracker for Web Applications
2
+
3
+ ## Installation
4
+
5
+ ```bash
6
+ npm i app-tracker
7
+ ```
8
+
9
+ ## Getting Started
10
+
11
+ - Install Package
12
+ - Register on [App Tracker](https://www.app-tracker.cloud/)
13
+
14
+ ## How to use
15
+
16
+ ```javascript
17
+ import { AppTracker, AppTrackerService } from "app-tracker";
18
+
19
+ const appTrackerService: AppTrackerService = AppTracker.init("API_KEY", configuration);
20
+
21
+ this.appTrackerService.debug(message, optionalParams);
22
+ ```
23
+
24
+ ### Configuration
25
+
26
+
27
+ | Property | Type | Default | Description |
28
+ |----------|:-----:|:-------------:|------|
29
+ | sendLogsInDevelopment | boolean | false | Should logs be sent to the App Tracker during development? |
30
+ | logInConsole | boolean | false | Should logs also be sent to the console |
31
+ | endpointUrl | string | App Tracker URI | Doesn't need to be customized unless you host App Tracker yourself |
32
+ | maxSendTries | number | 5 | How often to try to send to the server if an error occurs |
33
+ | maxLogsCount | number | 10 | How many logs should be stored until they are sent to the server |
34
+ | logLevel | LogType[] | [LogType.error] | Defines which log types should be sent to the server |
35
+ | sendLogsByTypesImmediately | LogType[] | [LogType.error, LogType.critical] | Which LogTypes should be sent directly to the server |
36
+ | userAgentOrOs | any | | Please pass: Web -> navigator.userAgent, Node -> os (from require('os'))|
37
+
38
+ ## FAQ
39
+
40
+ Q: Where do I get my API KEY?
41
+ A: Register with [App Tracker](https://www.app-tracker.cloud/) and create your application there.
@@ -1,7 +1,7 @@
1
1
  import { AppTrackerConfig } from './log';
2
2
  export declare class AppTrackerService {
3
- private sendLogsOnLocal;
4
- private consoleLogsOnLocal;
3
+ private sendLogsInDevelopment;
4
+ private logInConsole;
5
5
  private endpointUrl;
6
6
  private apiKey;
7
7
  private logs;
@@ -15,7 +15,9 @@ export declare class AppTrackerService {
15
15
  private isNode;
16
16
  private os;
17
17
  private isRunningLocal;
18
+ private ident;
18
19
  init(apiKey: string, config?: AppTrackerConfig): void;
20
+ getIdent(): string;
19
21
  debug(message?: string, ...optionalParams: any[]): void;
20
22
  info(message?: string, ...optionalParams: any[]): void;
21
23
  log(message?: string, ...optionalParams: any[]): void;
@@ -28,4 +30,5 @@ export declare class AppTrackerService {
28
30
  private checkLogType;
29
31
  private sendLogsToServerCore;
30
32
  private setUserAgentFromOs;
33
+ private createUUID;
31
34
  }
@@ -1 +1 @@
1
- "use strict";var __awaiter=this&&this.__awaiter||function(e,s,o,t){return new(o||(o=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 s;e.done?i(e.value):(s=e.value,s instanceof o?s:new o((function(e){e(s)}))).then(r,l)}g((t=t.apply(e,s||[])).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,s){var o,t,i;this.apiKey=e,s&&(s.endpointUrl&&(this.endpointUrl=s.endpointUrl),s.maxLogsCount&&(this.maxLogsCount=s.maxLogsCount),s.maxSendTries&&(this.maxSendTries=s.maxSendTries),s.sendLogsInDevelopment&&(this.sendLogsOnLocal=s.sendLogsInDevelopment),s.logInConsoleInDevelopment&&(this.consoleLogsOnLocal=s.logInConsoleInDevelopment),s.logLevel&&(this.logLevel=s.logLevel),s.sendLogsByTypesImmediately&&(this.sendLogsByTypesImmediately=s.sendLogsByTypesImmediately)),this.isNode="[object process]"===Object.prototype.toString.call("undefined"!=typeof process?process:0),this.isNode?(this.os=null===(t=s)||void 0===t?void 0:t.userAgentOrOs,this.userAgent=this.setUserAgentFromOs()):this.userAgent=null===(o=s)||void 0===o?void 0:o.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,...s){this.addLog(log_1.LogType.debug,e,s)}info(e,...s){this.addLog(log_1.LogType.info,e,s)}log(e,...s){this.addLog(log_1.LogType.log,e,s)}warn(e,...s){this.addLog(log_1.LogType.warn,e,s)}error(e,...s){this.addLog(log_1.LogType.error,e,s)}critical(e,...s){this.addLog(log_1.LogType.critical,e,s)}addLog(e,s,o){this.checkLogType(e)?this.isRunningLocal&&!this.sendLogsOnLocal?this.logToConsole(e,s,o):this.sendLogsToServer(e,s,o):this.logToConsole(e,s,o)}logToConsole(e,s,o){if(this.consoleLogsOnLocal)switch(e){case log_1.LogType.debug:console.debug(s,o);break;case log_1.LogType.critical:case log_1.LogType.error:console.error(s,o);break;case log_1.LogType.info:console.info(s,o);break;case log_1.LogType.log:console.log(s,o);break;case log_1.LogType.warn:console.warn(s,o);break;default:console.warn("Unkown LogType: ",e)}}sendLogsToServer(e,s,...o){var t;const i={logType:e,message:s,optionalParams:[],createdAt:new Date};if(o.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((s=>s==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((s=>s===e))||e===log_1.LogType.critical}sendLogsToServerCore(e){return __awaiter(this,void 0,void 0,(function*(){if(this.sendTries<this.maxSendTries)try{const s=this.endpointUrl.charAt(this.endpointUrl.length-1);yield cross_fetch_1.default(`${this.endpointUrl}${"/"===s?"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,s)=>{if(s instanceof Error){let e={};return Object.getOwnPropertyNames(s).forEach((function(o){e[o]=s[o]})),e}return s}))});e=[],this.isSending=!1}catch(s){console.error(`AppLogger: Could not send Logs to Server try ${this.sendTries}`,s),this.sendTries++,setTimeout((()=>{this.sendLogsToServerCore(e)}),1e4)}else this.sendTries=0,this.isSending=!1,console.error("AppLogger: Could not send Logs to Server finally")}))}setUserAgentFromOs(){const e={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(e)}}exports.AppTrackerService=AppTrackerService;
1
+ "use strict";var __awaiter=this&&this.__awaiter||function(e,s,o,t){return new(o||(o=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 s;e.done?i(e.value):(s=e.value,s instanceof o?s:new o((function(e){e(s)}))).then(r,l)}g((t=t.apply(e,s||[])).next())}))};Object.defineProperty(exports,"__esModule",{value:!0});const log_1=require("./log"),cross_fetch_1=require("cross-fetch");class AppTrackerService{constructor(){this.sendLogsInDevelopment=!1,this.logInConsole=!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,log_1.LogType.critical],this.isNode=!1,this.isRunningLocal=!0,this.ident=""}init(e,s){var o,t,i;this.apiKey=e,s&&(s.endpointUrl&&(this.endpointUrl=s.endpointUrl),s.maxLogsCount&&(this.maxLogsCount=s.maxLogsCount),s.maxSendTries&&(this.maxSendTries=s.maxSendTries),s.sendLogsInDevelopment&&(this.sendLogsInDevelopment=s.sendLogsInDevelopment),s.logInConsole&&(this.logInConsole=s.logInConsole),s.logLevel&&(this.logLevel=s.logLevel),s.sendLogsByTypesImmediately&&(this.sendLogsByTypesImmediately=s.sendLogsByTypesImmediately)),this.isNode="[object process]"===Object.prototype.toString.call("undefined"!=typeof process?process:0),this.isNode?(this.os=null===(t=s)||void 0===t?void 0:t.userAgentOrOs,this.userAgent=this.setUserAgentFromOs()):(this.userAgent=null===(o=s)||void 0===o?void 0:o.userAgentOrOs,this.ident=this.getIdent()),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)}}))}getIdent(){var e;let s=null===(e=localStorage)||void 0===e?void 0:e.getItem("App-Tracker.device-ident");return s||(s=this.createUUID(),localStorage.setItem("App-Tracker.device-ident",s)),s}debug(e,...s){this.addLog(log_1.LogType.debug,e,...s)}info(e,...s){this.addLog(log_1.LogType.info,e,...s)}log(e,...s){this.addLog(log_1.LogType.log,e,...s)}warn(e,...s){this.addLog(log_1.LogType.warn,e,...s)}error(e,...s){this.addLog(log_1.LogType.error,e,...s)}critical(e,...s){this.addLog(log_1.LogType.critical,e,...s)}addLog(e,s,...o){this.checkLogType(e)?this.isRunningLocal&&!this.sendLogsInDevelopment?this.logToConsole(e,s,...o):this.sendLogsToServer(e,s,...o):this.logToConsole(e,s,...o)}logToConsole(e,s,...o){if(this.logInConsole)switch(e){case log_1.LogType.debug:console.debug(s,...o);break;case log_1.LogType.critical:case log_1.LogType.error:console.error(s,...o);break;case log_1.LogType.info:console.info(s,...o);break;case log_1.LogType.log:console.log(s,...o);break;case log_1.LogType.warn:console.warn(s,...o);break;default:console.warn("Unkown LogType: ",e)}}sendLogsToServer(e,s,...o){var t;const i={logType:e,message:s,optionalParams:[],createdAt:new Date,ident:this.ident};if(o.forEach((e=>e.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((s=>s==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((s=>s===e))||e===log_1.LogType.critical}sendLogsToServerCore(e){return __awaiter(this,void 0,void 0,(function*(){if(this.sendTries<this.maxSendTries)try{const s=this.endpointUrl.charAt(this.endpointUrl.length-1);yield cross_fetch_1.default(`${this.endpointUrl}${"/"===s?"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,s)=>{if(s instanceof Error){let e={};return Object.getOwnPropertyNames(s).forEach((function(o){e[o]=s[o]})),e}return s}))});e=[],this.isSending=!1}catch(s){console.error(`AppLogger: Could not send Logs to Server try ${this.sendTries}`,s),this.sendTries++,setTimeout((()=>{this.sendLogsToServerCore(e)}),1e4)}else this.sendTries=0,this.isSending=!1,console.error("AppLogger: Could not send Logs to Server finally")}))}setUserAgentFromOs(){const e={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(e)}createUUID(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(e){var s=16*Math.random()|0;return("x"==e?s:3&s|8).toString(16)}))}}exports.AppTrackerService=AppTrackerService;
package/log.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export declare class AppTrackerConfig {
2
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
3
  sendLogsInDevelopment?: boolean | undefined;
4
- logInConsoleInDevelopment?: boolean | undefined;
4
+ logInConsole?: boolean | undefined;
5
5
  endpointUrl?: string | undefined;
6
6
  maxSendTries?: number | undefined;
7
7
  maxLogsCount?: number | undefined;
@@ -20,6 +20,7 @@ export declare class Log {
20
20
  message: any;
21
21
  optionalParams: any[];
22
22
  createdAt: Date;
23
+ ident: string;
23
24
  }
24
25
  export declare enum LogType {
25
26
  debug = 0,
package/log.js CHANGED
@@ -1 +1 @@
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={}));
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,this.ident=""}}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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "app-tracker",
3
- "version": "2.0.3",
3
+ "version": "2.1.0",
4
4
  "description": "App Tracker for Web-Applications",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -24,4 +24,4 @@
24
24
  "dependencies": {
25
25
  "cross-fetch": "^3.1.5"
26
26
  }
27
- }
27
+ }
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;