swdc-tracker
Advanced tools
Comparing version 1.0.4 to 1.0.5
"use strict"; | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -41,2 +52,3 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
var data_structures_1 = require("./utils/data_structures"); | ||
var dom_event_model_1 = require("./models/dom_event.model"); | ||
var snowplow = require('snowplow-tracker'); | ||
@@ -66,7 +78,7 @@ var emitter = snowplow.emitter; | ||
} | ||
return [3 /*break*/, 3]; | ||
return [2 /*return*/, { status: "success" }]; | ||
case 2: | ||
e_1 = _a.sent(); | ||
console.log("swdcTracker failed to initialize", e_1); | ||
return [3 /*break*/, 3]; | ||
return [2 /*return*/, { status: "failed", message: "Failed to initialize. " + e_1.message }]; | ||
case 3: return [2 /*return*/]; | ||
@@ -150,2 +162,43 @@ } | ||
}; | ||
/** | ||
* Track plugin data events. These are the attributes that | ||
* give information about how the user interacts with the plugin features | ||
* such as expanding or collapsing the tree view. | ||
* @param jwt - the authorization token | ||
* @param dataEvent - the DataEvent properties | ||
*/ | ||
swdcTracker.trackDomEvent = function (jwt, domEvent) { return __awaiter(void 0, void 0, void 0, function () { | ||
var properties, _domEventPayload, contexts; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
properties = { | ||
schema: "iglu:com.software/code_event/jsonschema/1-0-0", | ||
data: __assign({}, domEvent) | ||
}; | ||
return [4 /*yield*/, dom_event_model_1.domEventPayload(properties.data)]; | ||
case 1: | ||
_domEventPayload = _a.sent(); | ||
contexts = [ | ||
data_structures_1.authPayload(jwt), | ||
_domEventPayload | ||
]; | ||
if (swdcTracker.testMode) { | ||
// test mode - console log the event | ||
return [2 /*return*/, testEvent(properties, contexts)]; | ||
} | ||
return [4 /*yield*/, swdcTracker.spTracker.trackUnstructEvent(properties, contexts)]; | ||
case 2: | ||
// track the event. | ||
// trackUnstrucEvent returns PayloadData | ||
// PayloadData { | ||
// add: (key: string, value?: string) => void, | ||
// addDict: (dict: Object) => void, | ||
// addJson: (keyIfEncoded: string, keyIfNotEncoded: string, json: Object) => void, | ||
// build: () => Object; | ||
// } | ||
return [2 /*return*/, _a.sent()]; | ||
} | ||
}); | ||
}); }; | ||
function testEvent(properties, contexts) { | ||
@@ -156,4 +209,7 @@ var event = { | ||
}; | ||
console.log("swdc-tracker test mode on. trackUnstructEvent was called with the following payload: ", event); | ||
if (!process.env.DISABLE_SWDC_TRACKER_LOGGING) { | ||
console.log("swdc-tracker test mode on. trackUnstructEvent was called with the following payload: ", event); | ||
} | ||
return event; | ||
} | ||
exports.default = swdcTracker; |
{ | ||
"name": "swdc-tracker", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "swdc event tracker", | ||
@@ -13,5 +13,12 @@ "main": "dist", | ||
"build": "tsc", | ||
"prepare": "yarn build" | ||
"prepare": "yarn build", | ||
"test": "yarn build && env DISABLE_SWDC_TRACKER_LOGGING=true mocha -r ts-node/register test/**/*.ts --reporter spec --timeout 20000 --exit" | ||
}, | ||
"devDependencies": { | ||
"@types/chai": "^4.2.11", | ||
"@types/mocha": "^7.0.2", | ||
"chai": "^4.2.0", | ||
"mocha": "^8.0.1", | ||
"sinon": "^9.0.2", | ||
"ts-node": "^8.10.2", | ||
"typescript": "^3.9.5" | ||
@@ -18,0 +25,0 @@ }, |
@@ -9,2 +9,3 @@ import { get } from "./utils/http"; | ||
} from './utils/data_structures'; | ||
import { DomEvent, domEventPayload } from "./models/dom_event.model"; | ||
@@ -14,3 +15,3 @@ const snowplow = require('snowplow-tracker'); | ||
const tracker = snowplow.tracker; | ||
const swdcTracker = <any>{} | ||
const swdcTracker = <any>{}; | ||
@@ -28,3 +29,3 @@ swdcTracker.initialize = async (swdcApiHost: string, namespace: string, appId: string) => { | ||
if(process.env.ENABLE_SWDC_TRACKER === "true") { | ||
if (process.env.ENABLE_SWDC_TRACKER === "true") { | ||
swdcTracker.testMode = false | ||
@@ -36,4 +37,6 @@ console.log(`swdc-tracker initialized and ready to send events to ${tracker_api_host}`) | ||
} | ||
} catch(e) { | ||
console.log("swdcTracker failed to initialize", e) | ||
return { status: "success" }; | ||
} catch (e) { | ||
console.log("swdcTracker failed to initialize", e); | ||
return { status: "failed", message: `Failed to initialize. ${e.message}` }; | ||
} | ||
@@ -44,4 +47,4 @@ }; | ||
jwt: string, | ||
entity: string, | ||
type: string, | ||
entity: string, | ||
type: string, | ||
tz_offset_minutes: number, | ||
@@ -61,4 +64,4 @@ file_name: string, | ||
jwt, | ||
entity, | ||
type, | ||
entity, | ||
type, | ||
tz_offset_minutes, | ||
@@ -94,3 +97,3 @@ file_name, | ||
if(swdcTracker.testMode){ | ||
if (swdcTracker.testMode) { | ||
testEvent(properties, contexts) | ||
@@ -104,3 +107,3 @@ } else { | ||
jwt: string, | ||
keystrokes: number, | ||
keystrokes: number, | ||
chars_added: number, | ||
@@ -133,3 +136,3 @@ chars_deleted: number, | ||
jwt, | ||
keystrokes, | ||
keystrokes, | ||
chars_added, | ||
@@ -187,3 +190,3 @@ chars_deleted, | ||
if(swdcTracker.testMode){ | ||
if (swdcTracker.testMode) { | ||
testEvent(properties, contexts) | ||
@@ -195,10 +198,55 @@ } else { | ||
function testEvent(properties: any, contexts: any): void { | ||
/** | ||
* Track plugin data events. These are the attributes that | ||
* give information about how the user interacts with the plugin features | ||
* such as expanding or collapsing the tree view. | ||
* @param jwt - the authorization token | ||
* @param dataEvent - the DataEvent properties | ||
*/ | ||
swdcTracker.trackDomEvent = async (jwt: string, domEvent: DomEvent): Promise<any> => { | ||
// build the schema with the incoming props | ||
const properties = { | ||
schema: "iglu:com.software/code_event/jsonschema/1-0-0", | ||
data: { ...domEvent } | ||
} | ||
// create the payload | ||
const _domEventPayload = await domEventPayload(properties.data); | ||
// crate the context with the authorization info | ||
const contexts = [ | ||
authPayload(jwt), | ||
_domEventPayload | ||
] | ||
if (swdcTracker.testMode) { | ||
// test mode - console log the event | ||
return testEvent(properties, contexts) | ||
} | ||
// track the event. | ||
// trackUnstrucEvent returns PayloadData | ||
// PayloadData { | ||
// add: (key: string, value?: string) => void, | ||
// addDict: (dict: Object) => void, | ||
// addJson: (keyIfEncoded: string, keyIfNotEncoded: string, json: Object) => void, | ||
// build: () => Object; | ||
// } | ||
return await swdcTracker.spTracker.trackUnstructEvent(properties, contexts); | ||
} | ||
function testEvent(properties: any, contexts: any): any { | ||
const event = { | ||
properties: properties, | ||
contexts: contexts | ||
}; | ||
if (!process.env.DISABLE_SWDC_TRACKER_LOGGING) { | ||
console.log("swdc-tracker test mode on. trackUnstructEvent was called with the following payload: ", event); | ||
} | ||
console.log("swdc-tracker test mode on. trackUnstructEvent was called with the following payload: ", event) | ||
return event; | ||
} | ||
export default swdcTracker; |
import { hashValue } from "./hash" | ||
export async function filePayload( | ||
name: string, | ||
path: string, | ||
name: string, | ||
path: string, | ||
syntax: string, | ||
@@ -19,5 +19,5 @@ line_count: number, | ||
path: hashedPath, | ||
syntax: syntax, | ||
line_count: line_count, | ||
character_count: character_count | ||
syntax, | ||
line_count, | ||
character_count | ||
} | ||
@@ -48,4 +48,4 @@ } | ||
data: { | ||
id: id, | ||
version: version | ||
id, | ||
version | ||
} | ||
@@ -84,6 +84,6 @@ } | ||
schema: "iglu:com.software/auth/jsonschema/1-0-0", | ||
data: { | ||
jwt: jwt | ||
data: { | ||
jwt | ||
} | ||
} | ||
} |
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
59554
20
1042
7
3