@sap/swa-for-sapbas-vsx
Advanced tools
Comparing version 1.1.13 to 1.2.3
11
api.d.ts
@@ -16,5 +16,12 @@ /** | ||
* @param eventType | ||
* @param {string[]} [custom_events] Optional, can accept up to 4, any more will be ignored | ||
* @param {string[]} [customEvents] Optional, can accept up to 4, any more will be ignored | ||
* @param {number[]} [numericEvents] Optional, can accept up to 2, any more will be ignored | ||
*/ | ||
public track(eventType : string, custom_events? : string[]) : void; | ||
public track(eventType : string, customEvents? : string[], numericEvents? : number[]) : void; | ||
/** | ||
* Set exteral target for reporting | ||
* @param targetUrl should be external target URL | ||
* @param targetToken should be external target token | ||
*/ | ||
public setTarget(targetUrl : string, targetToken : string) : void; | ||
} | ||
@@ -21,0 +28,0 @@ |
{ | ||
"name": "@sap/swa-for-sapbas-vsx", | ||
"version": "1.1.13", | ||
"version": "1.2.3", | ||
"author": "SAP SE", | ||
@@ -5,0 +5,0 @@ "description": "Javascript module for SWA tracking to be consumed by VsCode extensions", |
@@ -55,5 +55,6 @@ [![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/) | ||
* @param eventType string detailing what event are you looking to track (ex. "Generator Success!") | ||
* @param {string[]} [custom_events] Optional, can accept up to 5, any more will be ignored | ||
* @param {string[]} [custom_events] Optional, can accept up to 4, any more will be ignored | ||
* @param {int[]} [numericEvents] Optional, can accept up to 2, any more will be ignored | ||
*/ | ||
swa.track("myEvent", ["custom event 1", "custom event 2", "This array is optional"]); | ||
swa.track("myEvent", ["custom event 1", "custom event 2", "This array is optional"],[1,2]); // numeric events is also optional | ||
``` | ||
@@ -145,2 +146,4 @@ | ||
| **Custom event parameter 10** | The unique caller ID "vsxPublisher.vsxPackageName", set by lib automatically | | ||
| **Numeric event parameter 1** | Event additional numeric data 1, "numeric event 1" sent via tack API | | ||
| **Numeric event parameter 2** | Event additional numeric data 2, "numeric event 2" sent via tack API | | ||
@@ -147,0 +150,0 @@ ## Contribution |
@@ -13,3 +13,3 @@ 'use strict'; | ||
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" | ||
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 numeric1:e_int_1 numeric2:e_int_2" | ||
}; | ||
@@ -20,2 +20,3 @@ | ||
this.isAppStudio = this._isAppStudio(); | ||
this.isExternalTarget = false | ||
this.disableTracking = false; | ||
@@ -40,10 +41,11 @@ this.baseUrl = this._getProcessEnv(SITE_URL_ENV_NAME, VS_CODE_DEFAULTS.URL); | ||
async _prepareCustomEvents(customEvents) { | ||
async _prepareEvents(customEvents, numericEvents) { | ||
const myCusEvent = _.slice(customEvents, 0, 5); | ||
const toReturn = {}; | ||
for (let i = 0; i < myCusEvent.length; i += 1) { | ||
const customIndex = i + 1; // Customs are human 'managed', so they aren't zero based like array | ||
toReturn[this.fieldMapping["custom" + customIndex]] = myCusEvent[i]; | ||
} | ||
this._mapCustomObj(myCusEvent, "custom", toReturn); | ||
const myNumEvent = _.slice(numericEvents, 0, 2); | ||
this._mapCustomObj(myNumEvent, "numeric", toReturn); | ||
toReturn[this.fieldMapping["iaas"]] = this._getIAASParam(); | ||
@@ -58,3 +60,10 @@ toReturn[this.fieldMapping["landscape"]] = this._getDataCenterParam(); | ||
track(eventType, customEvents) { | ||
_mapCustomObj(myCustomObj, fieldMappingStringPrefix, toReturnMap) { | ||
for (let i = 0; i < myCustomObj.length; i += 1) { | ||
const customIndex = i + 1; // Customs are human 'managed', so they aren't zero based like array | ||
toReturnMap[this.fieldMapping[fieldMappingStringPrefix + customIndex]] = myCustomObj[i]; | ||
} | ||
} | ||
track(eventType, customEvents, numericEvents) { | ||
if(!this._isAnalyticsEnabled() || this.disableTracking) { | ||
@@ -64,3 +73,3 @@ return "AnalyticsDisabled"; | ||
this._prepareCustomEvents(customEvents).then((customEventsObj) => { | ||
this._prepareEvents(customEvents, numericEvents).then((customEventsObj) => { | ||
const trackerObj = { | ||
@@ -129,2 +138,6 @@ _id: this.reporterUniqueId, | ||
_getIsSAPUser() { | ||
if (this.isExternalTarget) { | ||
return "na" | ||
} | ||
const anon = this._getProcessEnv("SWA_USER_ANON") === "literalTrue" ? "true" : "false"; | ||
@@ -189,2 +202,10 @@ let toReturn = ""; | ||
} | ||
setTarget(targetUrl, targetToken) { | ||
if (targetUrl != null && targetToken != null) { | ||
this.baseUrl = targetUrl; | ||
this.apiToken = targetToken; | ||
this.isExternalTarget = true | ||
} | ||
} | ||
} | ||
@@ -191,0 +212,0 @@ |
@@ -16,3 +16,5 @@ const swa = require("../src/index.js"); | ||
"is_sap_user": "e_9", | ||
"reporter_identifier": "e_10" | ||
"reporter_identifier": "e_10", | ||
"numeric1":"e_int_1", | ||
"numeric2":"e_int_2" | ||
}; | ||
@@ -25,10 +27,10 @@ | ||
it("validate custom_params", () => { | ||
return swaObj._prepareCustomEvents(["1","2","3","4","5","6"]) | ||
return swaObj._prepareEvents(["1","2","3","4","5","6"],[1,2]) | ||
.then( | ||
res => { | ||
assert(res.e_a === "1" && res.e_2 === "2" && res.e_3 === "3" && res.e_4 === "4" && res.e_5 === "5" ,"Custom params not inserted correctly") | ||
assert(res.e_a === "1" && res.e_2 === "2" && res.e_3 === "3" && res.e_4 === "4" && res.e_5 === "5" && res.e_int_1 === 1 && res.e_int_2 === 2,"Custom params not inserted correctly") | ||
}) | ||
}); | ||
it("validate max size of sent obj", () => { | ||
return swaObj._prepareCustomEvents(["1","2","3","4","5","6","4","5","6","10"]).then( | ||
return swaObj._prepareEvents(["1","2","3","4","5","6","4","5","6","10"]).then( | ||
res => { | ||
@@ -40,3 +42,3 @@ assert(Object.keys(res).length < 11, "custom events object over max size"); | ||
it("validate custom events obj sends initial params", () => { | ||
return swaObj._prepareCustomEvents([]).then( | ||
return swaObj._prepareEvents([]).then( | ||
@@ -126,1 +128,43 @@ res => { | ||
describe("Check different target settings", () => { | ||
it("Check default target behavior", () => { | ||
process.env.SWA_USER_ANON = ""; | ||
process.env.USER_NAME = "john.smith@sap.com"; | ||
const defaultSwa = new swa.SWATracker("testPublisher","testPackageName"); | ||
assert(defaultSwa.isExternalTarget == false); | ||
assert(defaultSwa.baseUrl == "https://webanalytics2.cfapps.eu10.hana.ondemand.com/tracker/log"); | ||
assert(defaultSwa.apiToken == "5e374ebb-01d0-4f56-bdfb-e9b1c1241f33"); | ||
assert(defaultSwa._getIsSAPUser() == "true"); | ||
}) | ||
it("Check set target behavior", () => { | ||
process.env.SWA_USER_ANON = ""; | ||
process.env.USER_NAME = "john.smith@sap.com"; | ||
const SwaWithTarget = new swa.SWATracker("testPublisher","testPackageName"); | ||
SwaWithTarget.setTarget("https://targeturl.com", "targetToken") | ||
assert(SwaWithTarget.isExternalTarget == true); | ||
assert(SwaWithTarget.baseUrl == "https://targeturl.com"); | ||
assert(SwaWithTarget.apiToken == "targetToken"); | ||
assert(SwaWithTarget._getIsSAPUser() == "na"); | ||
}) | ||
it("Check set partial target behavior - only URL", () => { | ||
process.env.SWA_USER_ANON = ""; | ||
process.env.USER_NAME = "john.smith@sap.com"; | ||
const SwaWithPartialTargetOnlyUrl = new swa.SWATracker("testPublisher","testPackageName"); | ||
SwaWithPartialTargetOnlyUrl.setTarget("https://targeturl.com") | ||
assert(SwaWithPartialTargetOnlyUrl.isExternalTarget == false); | ||
assert(SwaWithPartialTargetOnlyUrl.baseUrl == "https://webanalytics2.cfapps.eu10.hana.ondemand.com/tracker/log"); | ||
assert(SwaWithPartialTargetOnlyUrl.apiToken == "5e374ebb-01d0-4f56-bdfb-e9b1c1241f33"); | ||
assert(SwaWithPartialTargetOnlyUrl._getIsSAPUser() == "true"); | ||
}) | ||
it("Check set partial target behavior - only token", () => { | ||
process.env.SWA_USER_ANON = ""; | ||
process.env.USER_NAME = "john.smith@sap.com"; | ||
const SwaWithPartialTargetOnlyToken = new swa.SWATracker("testPublisher","testPackageName"); | ||
SwaWithPartialTargetOnlyToken.setTarget( null, "targetToken") | ||
assert(SwaWithPartialTargetOnlyToken.isExternalTarget == false); | ||
assert(SwaWithPartialTargetOnlyToken.baseUrl == "https://webanalytics2.cfapps.eu10.hana.ondemand.com/tracker/log"); | ||
assert(SwaWithPartialTargetOnlyToken.apiToken == "5e374ebb-01d0-4f56-bdfb-e9b1c1241f33"); | ||
assert(SwaWithPartialTargetOnlyToken._getIsSAPUser() == "true"); | ||
}) | ||
}); | ||
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
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
50584
399
153
21