swdc-tracker
Advanced tools
Comparing version 1.0.6 to 1.0.8
@@ -47,6 +47,9 @@ "use strict"; | ||
var plugin_1 = require("./entities/plugin"); | ||
var snowplow = require('snowplow-tracker'); | ||
var response_1 = require("./utils/response"); | ||
var env_helper_1 = require("./utils/env_helper"); | ||
var snowplow = require("snowplow-tracker"); | ||
var emitter = snowplow.emitter; | ||
var tracker = snowplow.tracker; | ||
var swdcTracker = {}; | ||
var lastProcessedTestEvent = {}; | ||
swdcTracker.initialize = function (swdcApiHost, namespace, appId) { return __awaiter(void 0, void 0, void 0, function () { | ||
@@ -64,15 +67,12 @@ var result, tracker_api_host, e, e_1; | ||
swdcTracker.spTracker = tracker([e], namespace, appId, false); | ||
if (process.env.ENABLE_SWDC_TRACKER === "true") { | ||
swdcTracker.testMode = false; | ||
console.log("swdc-tracker initialized and ready to send events to " + tracker_api_host); | ||
if (env_helper_1.isTestMode()) { | ||
console.log('swdc-tracker test mode on. set env ENABLE_SWDC_TRACKER to "true" to send events'); | ||
} | ||
else { | ||
swdcTracker.testMode = true; | ||
console.log('swdc-tracker test mode on. set env ENABLE_SWDC_TRACKER to "true" to send events'); | ||
console.log("swdc-tracker initialized and ready to send events to " + tracker_api_host); | ||
} | ||
return [2 /*return*/, { status: "success" }]; | ||
return [2 /*return*/, response_1.success()]; | ||
case 2: | ||
e_1 = _a.sent(); | ||
console.log("swdcTracker failed to initialize", e_1); | ||
return [2 /*return*/, { status: "failed", message: "Failed to initialize. " + e_1.message }]; | ||
return [2 /*return*/, response_1.error(500, "Failed to initialize. " + e_1.message)]; | ||
case 3: return [2 /*return*/]; | ||
@@ -123,3 +123,3 @@ } | ||
]; | ||
if (swdcTracker.testMode) { | ||
if (env_helper_1.isTestMode()) { | ||
// test mode - console log the event | ||
@@ -173,3 +173,3 @@ return [2 /*return*/, testEvent(_codetimePayload, contexts)]; | ||
]; | ||
if (swdcTracker.testMode) { | ||
if (env_helper_1.isTestMode()) { | ||
// test mode - console log the event | ||
@@ -192,7 +192,8 @@ return [2 /*return*/, testEvent(_editorActionPayload, contexts)]; | ||
}; | ||
if (!process.env.DISABLE_SWDC_TRACKER_LOGGING) { | ||
console.log("swdc-tracker test mode on. trackUnstructEvent was called with the following payload: ", event); | ||
} | ||
return event; | ||
lastProcessedTestEvent = event; | ||
return response_1.success(); | ||
} | ||
swdcTracker.getLastProcessedTestEvent = function () { | ||
return lastProcessedTestEvent; | ||
}; | ||
exports.default = swdcTracker; |
{ | ||
"name": "swdc-tracker", | ||
"version": "1.0.6", | ||
"version": "1.0.8", | ||
"description": "swdc event tracker", | ||
@@ -14,3 +14,3 @@ "main": "dist", | ||
"prepare": "yarn build", | ||
"test": "yarn build && env DISABLE_SWDC_TRACKER_LOGGING=true mocha -r ts-node/register test/**/*.ts --reporter spec --timeout 20000 --exit" | ||
"test": "yarn build && mocha -r ts-node/register test/**/*.ts --reporter spec --timeout 20000 --exit" | ||
}, | ||
@@ -17,0 +17,0 @@ "devDependencies": { |
@@ -9,4 +9,7 @@ import { get } from "./utils/http"; | ||
import { Plugin } from "./entities/plugin"; | ||
import { success, error, TrackerResponse } from "./utils/response"; | ||
import { isTestMode } from "./utils/env_helper"; | ||
const snowplow = require('snowplow-tracker'); | ||
const snowplow = require("snowplow-tracker"); | ||
const emitter = snowplow.emitter; | ||
@@ -16,3 +19,5 @@ const tracker = snowplow.tracker; | ||
swdcTracker.initialize = async (swdcApiHost: string, namespace: string, appId: string) => { | ||
let lastProcessedTestEvent: any = {}; | ||
swdcTracker.initialize = async (swdcApiHost: string, namespace: string, appId: string): Promise<TrackerResponse> => { | ||
try { | ||
@@ -28,13 +33,11 @@ // fetch tracker_api from plugin config | ||
if (process.env.ENABLE_SWDC_TRACKER === "true") { | ||
swdcTracker.testMode = false | ||
console.log(`swdc-tracker initialized and ready to send events to ${tracker_api_host}`) | ||
if (isTestMode()) { | ||
console.log('swdc-tracker test mode on. set env ENABLE_SWDC_TRACKER to "true" to send events'); | ||
} else { | ||
swdcTracker.testMode = true | ||
console.log('swdc-tracker test mode on. set env ENABLE_SWDC_TRACKER to "true" to send events') | ||
console.log(`swdc-tracker initialized and ready to send events to ${tracker_api_host}`); | ||
} | ||
return { status: "success" }; | ||
return success(); | ||
} catch (e) { | ||
console.log("swdcTracker failed to initialize", e); | ||
return { status: "failed", message: `Failed to initialize. ${e.message}` }; | ||
return error(500, `Failed to initialize. ${e.message}`); | ||
} | ||
@@ -79,7 +82,7 @@ }; | ||
_pluginPayload | ||
] | ||
]; | ||
if (swdcTracker.testMode) { | ||
if (isTestMode()) { | ||
// test mode - console log the event | ||
return testEvent(_codetimePayload, contexts) | ||
return testEvent(_codetimePayload, contexts); | ||
} | ||
@@ -124,7 +127,7 @@ | ||
_projecPayload | ||
] | ||
]; | ||
if (swdcTracker.testMode) { | ||
if (isTestMode()) { | ||
// test mode - console log the event | ||
return testEvent(_editorActionPayload, contexts) | ||
return testEvent(_editorActionPayload, contexts); | ||
} | ||
@@ -138,3 +141,3 @@ | ||
function testEvent(properties: any, contexts: any): any { | ||
function testEvent(properties: any, contexts: any): TrackerResponse { | ||
const event = { | ||
@@ -145,8 +148,11 @@ properties: properties, | ||
if (!process.env.DISABLE_SWDC_TRACKER_LOGGING) { | ||
console.log("swdc-tracker test mode on. trackUnstructEvent was called with the following payload: ", event); | ||
} | ||
return event; | ||
lastProcessedTestEvent = event; | ||
return success(); | ||
} | ||
swdcTracker.getLastProcessedTestEvent = (): any => { | ||
return lastProcessedTestEvent; | ||
} | ||
export default swdcTracker; |
import swdcTracker from "../../src/index"; | ||
import { TrackerResponse } from "../../src/utils/response"; | ||
@@ -45,6 +46,11 @@ const http = require("../../src/utils/http"); | ||
}; | ||
const payloadData = await swdcTracker.trackCodeTimeEvent(eventData); | ||
const response: TrackerResponse = await swdcTracker.trackCodeTimeEvent(eventData); | ||
const props = payloadData.properties; | ||
const contexts = payloadData.contexts; | ||
expect(response.status).to.equal(200); | ||
const lastProcessedTestEvent = swdcTracker.getLastProcessedTestEvent(); | ||
// get the data | ||
const props = lastProcessedTestEvent.properties; | ||
const contexts = lastProcessedTestEvent.contexts; | ||
expect(props.schema).to.include("codetime"); | ||
@@ -51,0 +57,0 @@ expect(props.data.keystrokes).to.equal(20); |
import swdcTracker from "../../src/index"; | ||
import { TrackerResponse } from "../../src/utils/response"; | ||
@@ -39,6 +40,11 @@ const http = require("../../src/utils/http"); | ||
}; | ||
const payloadData = await swdcTracker.trackEditorAction(eventData); | ||
const response: TrackerResponse = await swdcTracker.trackEditorAction(eventData); | ||
const props = payloadData.properties; | ||
const contexts = payloadData.contexts; | ||
expect(response.status).to.equal(200); | ||
const lastProcessedTestEvent = swdcTracker.getLastProcessedTestEvent(); | ||
// get the data | ||
const props = lastProcessedTestEvent.properties; | ||
const contexts = lastProcessedTestEvent.contexts; | ||
expect(props.schema).to.include("editor_action"); | ||
@@ -45,0 +51,0 @@ expect(props.data.type).to.equal("mouse"); |
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
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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 2 instances in 1 package
87484
47
1749
1
0