@sap/swa-for-sapbas-vsx
Advanced tools
Comparing version 1.2.7 to 1.2.14
{ | ||
"name": "@sap/swa-for-sapbas-vsx", | ||
"version": "1.2.7", | ||
"version": "1.2.14", | ||
"author": "SAP SE", | ||
@@ -27,4 +27,5 @@ "description": "Javascript module for SWA tracking to be consumed by VsCode extensions", | ||
"lodash": "4.17.21", | ||
"matomo-tracker": "2.2.2" | ||
"matomo-tracker": "2.2.2", | ||
"semver": "7.3.5" | ||
} | ||
} |
@@ -84,2 +84,9 @@ [![Build Status](https://gkedevxlondon.jaas-gcp.cloud.sap.corp/buildStatus/icon?job=swa_ci/master)](https://gkedevxlondon.jaas-gcp.cloud.sap.corp/job/swa_ci/job/master/) | ||
#### Use Different Target | ||
SWA can report usage to a different target. | ||
These reports are always anonymized. | ||
```js | ||
swa.setTarget(<targetUrl>, <targetToken>); | ||
``` | ||
## Enable usage analytics reporting from VS Code | ||
@@ -86,0 +93,0 @@ If you have a VS Code extension that is released to VS Code marketplace and you would like to collect its usage when it runs in VS Code, do the following: |
@@ -5,3 +5,6 @@ 'use strict'; | ||
const MatomoTracker = require('matomo-tracker'); | ||
const semverLt = require('semver/functions/lt') | ||
const SWA_LIB_VERSION = require(__dirname + '/../package.json').version; | ||
const SITE_TOKEN_ENV_NAME = "SWA_TARGET_SITE_TOKEN"; | ||
@@ -21,2 +24,3 @@ const SITE_URL_ENV_NAME = "SWA_TARGET_SITE_URL"; | ||
this.isExternalTarget = false | ||
this.errorListener = errorListener | ||
this.disableTracking = false; | ||
@@ -30,11 +34,3 @@ this.baseUrl = this._getProcessEnv(SITE_URL_ENV_NAME, VS_CODE_DEFAULTS.URL); | ||
this._validateRequiredParams(); | ||
this.matomo = new MatomoTracker(this.apiToken, this.baseUrl, true); | ||
if(_.isFunction(errorListener)) { | ||
const internalErrorListener = (err) => { | ||
if(err && err != 204) { | ||
errorListener(err); | ||
} | ||
} | ||
this.matomo.on('error', internalErrorListener); | ||
} | ||
this._setMatomoTracker(this.apiToken, this.baseUrl, this.errorListener) | ||
} | ||
@@ -100,2 +96,5 @@ | ||
} | ||
if(!this._hasMinimalAllowedVersion()) { | ||
this.disableTracking = true; | ||
} | ||
} | ||
@@ -120,2 +119,14 @@ } | ||
_hasMinimalAllowedVersion() { | ||
const minimalAllowedVersion = this._getProcessEnv("SWA_MINIMAL_ALLOWED_VERSION", "na"); | ||
if (minimalAllowedVersion != "na") { | ||
const isLibVersionSmallerThanAllowed = semverLt(SWA_LIB_VERSION, minimalAllowedVersion) | ||
if (isLibVersionSmallerThanAllowed) { | ||
console.log(`Current lib version ${SWA_LIB_VERSION} is not sufficient for the minimal allowed version ${minimalAllowedVersion}`); | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
_isAppStudio() { | ||
@@ -202,7 +213,20 @@ return this._getProcessEnv("H2O_URL","na") !== "na"; | ||
setTarget(targetUrl, targetToken) { | ||
if (targetUrl != null && targetToken != null) { | ||
this.baseUrl = targetUrl; | ||
this.apiToken = targetToken; | ||
_setMatomoTracker(apiToken, baseUrl, errorListener) { | ||
this.matomo = new MatomoTracker(apiToken, baseUrl, true); | ||
if(_.isFunction(errorListener)) { | ||
const internalErrorListener = (err) => { | ||
if(err && err != 204) { | ||
errorListener(err); | ||
} | ||
} | ||
this.matomo.on('error', internalErrorListener); | ||
} | ||
} | ||
setTarget(baseUrl, apiToken) { | ||
if (apiToken != null && baseUrl != null) { | ||
this.isExternalTarget = true | ||
this.baseUrl = baseUrl; | ||
this.apiToken = apiToken; | ||
this._setMatomoTracker(apiToken, baseUrl, this.errorListener) | ||
} | ||
@@ -209,0 +233,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
52949
420
160
4
22
+ Addedsemver@7.3.5
+ Addedlru-cache@6.0.0(transitive)
+ Addedsemver@7.3.5(transitive)
+ Addedyallist@4.0.0(transitive)