Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@sap/swa-for-sapbas-vsx

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sap/swa-for-sapbas-vsx - npm Package Compare versions

Comparing version 1.1.3 to 1.1.5

5

package.json
{
"name": "@sap/swa-for-sapbas-vsx",
"version": "1.1.3",
"version": "1.1.5",
"author": "SAP SE",

@@ -24,3 +24,4 @@ "description": "Javascript module for SWA tracking to be consumed by VsCode extensions",

"eslint": "6.8.0",
"nyc": "^15.1.0"
"nyc": "^15.1.0",
"sinon": "^9.0.1"
},

@@ -27,0 +28,0 @@ "dependencies": {

@@ -69,2 +69,23 @@ [![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/)

## Enable usage analytics reporting from VS Code
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:
1. **In “configuration” section of your VS code extension** add the settings for user to enable/disable sending the reports. Replace the placeholders with the relevant strings.
```json
...
"<Your package name>.enableSapWebAnalytics": {
"type": "boolean",
"default": true,
"description": "Enable collecting usage analytics data for <Your Tool Name>. If enabled, non-personally identifiable information is used to help understand the product usage and improve the tool.",
"scope": "resource"
}
...
```
2. **In README file of your extension**, add the following paragraph:
The tool collects non-personally identifiable information about your usage of the tool to improve its services.
If you do not want the tool to collect your usage data, you can set the "Enable Sap Web Analytics" setting to "false".
Go to File > Preferences > Settings (macOS: Code > Preferences > Settings) > Extensions > \<Tool Name\>, and deselect the "Enable Sap Web Analytics" checkbox.
## SWA Reports and Parameter Mapping

@@ -71,0 +92,0 @@ The following fields can be used for creating SWA reports:

47

src/index.js

@@ -6,4 +6,2 @@ 'use strict';

const vsCodeSiteToken = "NWUzNzRlYmItMDFkMC00ZjU2LWJkZmItZTliMWMxMjQxZjMzCg==";
const vsCodeBaseUrl = "https://webanalytics2.cfapps.eu10.hana.ondemand.com/tracker/log"; // edit
const SITE_TOKEN_ENV_NAME = "SWA_TARGET_SITE_TOKEN";

@@ -13,2 +11,8 @@ const SITE_URL_ENV_NAME = "SWA_TARGET_SITE_URL";

const VS_CODE_DEFAULTS = {
URL: "https://webanalytics2.cfapps.eu10.hana.ondemand.com/tracker/log",
TOKEN: "NWUzNzRlYmItMDFkMC00ZjU2LWJkZmItZTliMWMxMjQxZjMzCg==",
FIELD_MAPPING: "custom1:e_a custom2:e_2 custom3:e_3 custom4:e_4 custom5:e_5 iaas:e_6 is_sap_user:e_9 landscape:e_7 reporter_identifier:e_10 version:e_8"
};
class SWATracker {

@@ -18,7 +22,8 @@ constructor(vsxPublisher, vsxPackageName, errorListener) {

this.disableTracking = false;
this.baseUrl = this._getProcessEnv(SITE_URL_ENV_NAME, vsCodeBaseUrl);
this.baseUrl = this._getProcessEnv(SITE_URL_ENV_NAME, VS_CODE_DEFAULTS.URL);
this.siteUrl = this._getSiteUrl();
this.vsxPackageName = vsxPackageName;
this.reporterUniqueId = vsxPublisher + "." + vsxPackageName;
this.apiToken = this._getProcessEnv(SITE_TOKEN_ENV_NAME, this._b64dec(vsCodeSiteToken));
this.apiToken = this._getProcessEnv(SITE_TOKEN_ENV_NAME, this._b64dec(VS_CODE_DEFAULTS.TOKEN));
this._initFieldMapping();
this._validateRequiredParams();

@@ -32,19 +37,15 @@ this.matomo = new MatomoTracker(this.apiToken, this.baseUrl, true);

async _prepareCustomEvents(custom_events) {
const myCusEvent = _.slice(custom_events, 0, 5);
const toReturn = {};
let key = "e_a";
for (let i = 0; i < myCusEvent.length; i += 1) {
// custom events object should be { "e_a": "val", "e_2": "val", "e_3": "val"....}
// first 5 vals are custom, next 5 reserved for API
if (i > 0)
key = "e_" + (i + 1).toString();
toReturn[key] = myCusEvent[i];
let customIndex = i + 1; // Customs are human 'managed', so they aren't zero based like array
toReturn[this.fieldMapping["custom" + customIndex]] = myCusEvent[i];
}
toReturn.e_6 = this._getIAASParam();
toReturn.e_7 = this._getDataCenterParam();
toReturn.e_8 = this._getVersion();
toReturn.e_9 = this._getIsSAPUser();
toReturn.e_10 = this.reporterUniqueId;
toReturn[this.fieldMapping["iaas"]] = this._getIAASParam();
toReturn[this.fieldMapping["landscape"]] = this._getDataCenterParam();
toReturn[this.fieldMapping["version"]] = this._getVersion();
toReturn[this.fieldMapping["is_sap_user"]] = this._getIsSAPUser();
toReturn[this.fieldMapping["reporter_identifier"]] = this.reporterUniqueId;
return toReturn;

@@ -86,4 +87,16 @@ }

_initFieldMapping() {
this.fieldMapping = {};
let fieldMappingStr = this._getProcessEnv("SWA_FIELD_MAPPING", VS_CODE_DEFAULTS.FIELD_MAPPING);
if (fieldMappingStr) {
let fields = fieldMappingStr.split(" ");
for (let i = 0; i < fields.length; i++) {
let fieldParts = fields[i].split(":");
this.fieldMapping[fieldParts[0]] = fieldParts[1];
}
}
}
_hasAppStudioEnvVars() {
return this.apiToken !== this._b64dec(vsCodeSiteToken);
return this.apiToken !== this._b64dec(VS_CODE_DEFAULTS.TOKEN) && Object.keys(this.fieldMapping).length > 0;
}

@@ -90,0 +103,0 @@

const swa = require("../src/index.js");
const assert = require("assert");
const sinon = require("sinon");
const swaObj = new swa.SWATracker("testPublisher","testPackageName");
swaObj.fieldMapping = {
"custom1": "e_a",
"custom2": "e_2",
"custom3": "e_3",
"custom4": "e_4",
"custom5": "e_5",
"iaas": "e_6",
"landscape": "e_7",
"version": "e_8",
"is_sap_user": "e_9",
"reporter_identifier": "e_10"
};
describe("Check _prepareCustomEvents", () => {
it("validate custom_params", () => {

@@ -22,2 +37,3 @@ return swaObj._prepareCustomEvents(["1","2","3","4","5","6"])

return swaObj._prepareCustomEvents([]).then(
res => {

@@ -32,1 +48,19 @@ assert(Object.keys(res).length >= 5, "custom events object first 5 elements not reserved.")

});
describe("Check _initFieldMapping", () => {
beforeEach(function() {
swaObj.fieldMapping = {};
});
it("Fields are set according to mapping string from env var", () => {
var fakeGetEnv = sinon.fake.returns("custom1:e_a custom2:e_2 reporter_identifier:e_10 version:e_8");
sinon.replace(swaObj, "_getProcessEnv", fakeGetEnv);
swaObj._initFieldMapping();
assert(Object.keys(swaObj.fieldMapping).length == 4);
assert(swaObj.fieldMapping["custom1"] == "e_a");
assert(swaObj.fieldMapping["custom2"] == "e_2");
assert(swaObj.fieldMapping["reporter_identifier"] == "e_10");
assert(swaObj.fieldMapping["version"] == "e_8");
})
});

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc