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

swdc-tracker

Package Overview
Dependencies
Maintainers
5
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

swdc-tracker - npm Package Compare versions

Comparing version 1.1.0 to 1.2.0

test/config/config.test.ts

4

dist/entities/file.d.ts

@@ -16,3 +16,3 @@ export interface FileInterface {

static hasData(data: FileInterface): string;
buildPayload(): {
buildPayload(jwt: string): Promise<{
schema: string;

@@ -26,3 +26,3 @@ data: {

};
};
}>;
}
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -16,15 +52,26 @@ exports.File = void 0;

};
File.prototype.buildPayload = function () {
var hashedName = hash_1.hashValue(this.file_name);
var hashedPath = hash_1.hashValue(this.file_path);
return {
schema: "iglu:com.software/file/jsonschema/1-0-1",
data: {
file_name: hashedName,
file_path: hashedPath,
syntax: this.syntax,
line_count: this.line_count,
character_count: this.character_count
}
};
File.prototype.buildPayload = function (jwt) {
return __awaiter(this, void 0, void 0, function () {
var hashedName, hashedPath;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, hash_1.hashValue(this.file_name, "file_name", jwt)];
case 1:
hashedName = _a.sent();
return [4 /*yield*/, hash_1.hashValue(this.file_path, "file_path", jwt)];
case 2:
hashedPath = _a.sent();
return [2 /*return*/, {
schema: "iglu:com.software/file/jsonschema/1-0-1",
data: {
file_name: hashedName,
file_path: hashedPath,
syntax: this.syntax,
line_count: this.line_count,
character_count: this.character_count
}
}];
}
});
});
};

@@ -31,0 +78,0 @@ return File;

@@ -10,3 +10,3 @@ export interface ProjectInterface {

static hasData(data: ProjectInterface): string;
buildPayload(): {
buildPayload(jwt: string): Promise<{
schema: string;

@@ -17,3 +17,3 @@ data: {

};
};
}>;
}
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -13,12 +49,23 @@ exports.Project = void 0;

};
Project.prototype.buildPayload = function () {
var hashedName = hash_1.hashValue(this.project_name);
var hashedDirectory = hash_1.hashValue(this.project_directory);
return {
schema: "iglu:com.software/project/jsonschema/1-0-0",
data: {
project_name: hashedName,
project_directory: hashedDirectory
}
};
Project.prototype.buildPayload = function (jwt) {
return __awaiter(this, void 0, void 0, function () {
var hashedName, hashedDirectory;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, hash_1.hashValue(this.project_name, "project_name", jwt)];
case 1:
hashedName = _a.sent();
return [4 /*yield*/, hash_1.hashValue(this.project_directory, "project_directory", jwt)];
case 2:
hashedDirectory = _a.sent();
return [2 /*return*/, {
schema: "iglu:com.software/project/jsonschema/1-0-0",
data: {
project_name: hashedName,
project_directory: hashedDirectory
}
}];
}
});
});
};

@@ -25,0 +72,0 @@ return Project;

@@ -16,7 +16,7 @@ export interface RepoInterface {

static hasData(data: RepoInterface): string;
buildPayload(): {
buildPayload(jwt: string): Promise<{
schema: string;
data: {
repo_identifier: any;
reop_name: any;
repo_name: any;
owner_id: any;

@@ -26,3 +26,3 @@ git_branch: any;

};
};
}>;
}
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -16,18 +52,35 @@ exports.Repo = void 0;

};
Repo.prototype.buildPayload = function () {
var hashedName = hash_1.hashValue(this.repo_name);
var hashedIdentifier = hash_1.hashValue(this.repo_identifier);
var hashedOwnerId = hash_1.hashValue(this.owner_id);
var hashedGitBranch = hash_1.hashValue(this.git_branch);
var hashedGitTag = hash_1.hashValue(this.git_tag);
return {
schema: "iglu:com.software/repo/jsonschema/1-0-0",
data: {
repo_identifier: hashedIdentifier,
reop_name: hashedName,
owner_id: hashedOwnerId,
git_branch: hashedGitBranch,
git_tag: hashedGitTag
}
};
Repo.prototype.buildPayload = function (jwt) {
return __awaiter(this, void 0, void 0, function () {
var hashedName, hashedIdentifier, hashedOwnerId, hashedGitBranch, hashedGitTag;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, hash_1.hashValue(this.repo_name, "repo_name", jwt)];
case 1:
hashedName = _a.sent();
return [4 /*yield*/, hash_1.hashValue(this.repo_identifier, "repo_identifier", jwt)];
case 2:
hashedIdentifier = _a.sent();
return [4 /*yield*/, hash_1.hashValue(this.owner_id, "owner_id", jwt)];
case 3:
hashedOwnerId = _a.sent();
return [4 /*yield*/, hash_1.hashValue(this.git_branch, "git_branch", jwt)];
case 4:
hashedGitBranch = _a.sent();
return [4 /*yield*/, hash_1.hashValue(this.git_tag, "git_tag", jwt)];
case 5:
hashedGitTag = _a.sent();
return [2 /*return*/, {
schema: "iglu:com.software/repo/jsonschema/1-0-0",
data: {
repo_identifier: hashedIdentifier,
repo_name: hashedName,
owner_id: hashedOwnerId,
git_branch: hashedGitBranch,
git_tag: hashedGitTag
}
}];
}
});
});
};

@@ -34,0 +87,0 @@ return Repo;

@@ -16,3 +16,3 @@ export interface UIElementInterface {

static hasData(data: UIElementInterface): string;
buildPayload(): {
buildPayload(): Promise<{
schema: string;

@@ -26,3 +26,3 @@ data: {

};
};
}>;
}
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -16,12 +52,16 @@ exports.UIElement = void 0;

UIElement.prototype.buildPayload = function () {
return {
schema: "iglu:com.software/ui_element/jsonschema/1-0-1",
data: {
element_name: this.element_name,
element_location: this.element_location,
color: this.color,
icon_name: this.icon_name,
cta_text: this.cta_text
}
};
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, {
schema: "iglu:com.software/ui_element/jsonschema/1-0-2",
data: {
element_name: this.element_name,
element_location: this.element_location,
color: this.color,
icon_name: this.icon_name,
cta_text: this.cta_text
}
}];
});
});
};

@@ -28,0 +68,0 @@ return UIElement;

@@ -8,23 +8,29 @@ import { RepoInterface } from "../entities/repo";

keystrokes: number;
chars_added: number;
chars_deleted: number;
chars_pasted: number;
pastes: number;
lines_added: number;
lines_deleted: number;
characters_added: number;
characters_deleted: number;
single_deletes: number;
multi_deletes: number;
single_adds: number;
multi_adds: number;
auto_indents: number;
replacements: number;
start_time: number;
end_time: number;
tz_offset_minutes: number;
}
export declare class CodeTime implements CodeTimeInterface {
keystrokes: number;
chars_added: number;
chars_deleted: number;
chars_pasted: number;
pastes: number;
lines_added: number;
lines_deleted: number;
characters_added: number;
characters_deleted: number;
single_deletes: number;
multi_deletes: number;
single_adds: number;
multi_adds: number;
auto_indents: number;
replacements: number;
start_time: number;
end_time: number;
tz_offset_minutes: number;
constructor(data: CodeTimeInterface);

@@ -36,11 +42,14 @@ static hasData(data: CodeTimeInterface): number;

keystrokes: number;
chars_added: number;
chars_deleted: number;
chars_pasted: number;
pastes: number;
lines_added: number;
lines_deleted: number;
characters_added: number;
characters_deleted: number;
single_deletes: number;
multi_deletes: number;
single_adds: number;
multi_adds: number;
auto_indents: number;
replacements: number;
start_time: number;
end_time: number;
tz_offset_minutes: number;
};

@@ -47,0 +56,0 @@ };

@@ -7,11 +7,14 @@ "use strict";

this.keystrokes = data.keystrokes;
this.chars_added = data.chars_added;
this.chars_deleted = data.chars_deleted;
this.chars_pasted = data.chars_pasted;
this.pastes = data.pastes;
this.lines_added = data.lines_added;
this.lines_deleted = data.lines_deleted;
this.characters_added = data.characters_added;
this.characters_deleted = data.characters_deleted;
this.single_deletes = data.single_deletes;
this.multi_deletes = data.multi_deletes;
this.single_adds = data.single_adds;
this.multi_adds = data.multi_adds;
this.auto_indents = data.auto_indents;
this.replacements = data.replacements;
this.start_time = data.start_time;
this.end_time = data.end_time;
this.tz_offset_minutes = data.tz_offset_minutes;
}

@@ -23,14 +26,17 @@ CodeTime.hasData = function (data) {

return {
schema: "iglu:com.software/codetime/jsonschema/1-0-1",
schema: "iglu:com.software/codetime/jsonschema/1-0-2",
data: {
keystrokes: this.keystrokes,
chars_added: this.chars_deleted,
chars_deleted: this.chars_deleted,
chars_pasted: this.chars_pasted,
pastes: this.pastes,
lines_added: this.lines_added,
lines_deleted: this.lines_deleted,
characters_added: this.characters_added,
characters_deleted: this.characters_deleted,
single_deletes: this.single_deletes,
multi_deletes: this.multi_deletes,
single_adds: this.single_adds,
multi_adds: this.multi_adds,
auto_indents: this.auto_indents,
replacements: this.replacements,
start_time: this.start_time,
end_time: this.end_time,
tz_offset_minutes: this.tz_offset_minutes
end_time: this.end_time
}

@@ -37,0 +43,0 @@ };

@@ -5,6 +5,6 @@ import { PluginInterface } from "../entities/plugin";

import { AuthInterface } from "../entities/auth";
import { RepoInterface } from "../entities/repo";
export interface EditorActionInterface {
entity: string;
type: string;
tz_offset_minutes: number;
}

@@ -14,3 +14,2 @@ export declare class EditorAction implements EditorActionInterface {

type: string;
tz_offset_minutes: number;
constructor(data: EditorActionInterface);

@@ -23,7 +22,6 @@ static hasData(data: EditorActionInterface): string;

type: string;
tz_offset_minutes: number;
};
};
}
export interface EditorActionParams extends AuthInterface, PluginInterface, FileInterface, ProjectInterface, EditorActionInterface {
export interface EditorActionParams extends AuthInterface, RepoInterface, PluginInterface, FileInterface, ProjectInterface, EditorActionInterface {
}

@@ -8,3 +8,2 @@ "use strict";

this.type = data.type;
this.tz_offset_minutes = data.tz_offset_minutes;
}

@@ -16,8 +15,7 @@ EditorAction.hasData = function (data) {

return {
schema: "iglu:com.software/editor_action/jsonschema/1-0-0",
schema: "iglu:com.software/editor_action/jsonschema/1-0-1",
data: {
entity: this.entity,
type: this.type,
tz_offset_minutes: this.tz_offset_minutes
}
type: this.type
},
};

@@ -24,0 +22,0 @@ };

@@ -62,3 +62,3 @@ "use strict";

swdcTracker.initialize = function (swdcApiHost, namespace, appId) { return __awaiter(void 0, void 0, void 0, function () {
var result, tracker_api_host, e, e_1;
var result, tracker_api_host, tracker_url_scheme, e, e_1;
return __generator(this, function (_a) {

@@ -68,7 +68,14 @@ switch (_a.label) {

_a.trys.push([0, 2, , 3]);
return [4 /*yield*/, http_1.get(swdcApiHost, "/plugins/config")];
// fetch tracker_api from plugin config
http_1.setBaseUrl(swdcApiHost);
return [4 /*yield*/, http_1.get("/plugins/config")];
case 1:
result = _a.sent();
tracker_api_host = result.data.tracker_api;
e = emitter(tracker_api_host, 'https', null, 'post', 0);
tracker_url_scheme = result.data.tracker_url_scheme || "https";
e = emitter(tracker_api_host, tracker_url_scheme, null, "post", 0, function (error, body, response) {
if (error) {
console.log("swdc-tracker collector stream error", error);
}
});
swdcTracker.spTracker = tracker([e], namespace, appId, false);

@@ -91,4 +98,3 @@ swdcTracker.spTracker.setPlatform('iot');

/**
* @param jwt - the authorization token
* @param codetimeEvent - the CodeTime event extends Repo, Project, File
* @param codetimeEvent - the CodeTime event extends Repo, Project, File, Auth
*/

@@ -99,7 +105,10 @@ swdcTracker.trackCodeTimeEvent = function (params) { return __awaiter(void 0, void 0, void 0, function () {

switch (_a.label) {
case 0:
_codetimePayload = new codetime_1.CodeTime(params).buildPayload();
contexts = context_helper_1.buildContexts(params);
case 0: return [4 /*yield*/, new codetime_1.CodeTime(params).buildPayload()];
case 1:
_codetimePayload = _a.sent();
return [4 /*yield*/, context_helper_1.buildContexts(params)];
case 2:
contexts = _a.sent();
return [4 /*yield*/, sendEvent(_codetimePayload, contexts)];
case 1: return [2 /*return*/, _a.sent()];
case 3: return [2 /*return*/, _a.sent()];
}

@@ -116,7 +125,10 @@ });

switch (_a.label) {
case 0:
_editorActionPayload = new editor_action_1.EditorAction(params).buildPayload();
contexts = context_helper_1.buildContexts(params);
case 0: return [4 /*yield*/, new editor_action_1.EditorAction(params).buildPayload()];
case 1:
_editorActionPayload = _a.sent();
return [4 /*yield*/, context_helper_1.buildContexts(params)];
case 2:
contexts = _a.sent();
return [4 /*yield*/, sendEvent(_editorActionPayload, contexts)];
case 1: return [2 /*return*/, _a.sent()];
case 3: return [2 /*return*/, _a.sent()];
}

@@ -133,7 +145,10 @@ });

switch (_a.label) {
case 0:
_uiInteractionPayload = new ui_interaction_1.UIInteraction(params).buildPayload();
contexts = context_helper_1.buildContexts(params);
case 0: return [4 /*yield*/, new ui_interaction_1.UIInteraction(params).buildPayload()];
case 1:
_uiInteractionPayload = _a.sent();
return [4 /*yield*/, context_helper_1.buildContexts(params)];
case 2:
contexts = _a.sent();
return [4 /*yield*/, sendEvent(_uiInteractionPayload, contexts)];
case 1: return [2 /*return*/, _a.sent()];
case 3: return [2 /*return*/, _a.sent()];
}

@@ -144,18 +159,25 @@ });

return __awaiter(this, void 0, void 0, function () {
var eventResult;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (env_helper_1.isTestMode()) {
// test mode - console log the event
return [2 /*return*/, testEvent(event_payload, contexts)];
}
return [4 /*yield*/, swdcTracker.spTracker.trackUnstructEvent(event_payload, contexts)];
case 1:
eventResult = _a.sent();
if (eventResult && eventResult.add) {
return [2 /*return*/, response_1.success()];
}
return [2 /*return*/, response_1.error()];
if (env_helper_1.isTestMode()) {
// test mode - console log the event
return [2 /*return*/, testEvent(event_payload, contexts)];
}
try {
/**
* trackUnstructEvent takes the following:
* properties => json of {schema, data} (required)
* context => list of event contexts (optional)
* tstamp => positive integer (optional)
*/
// The track logic is not async, no need to have an await,
// "track()" will perform a callback on the payload data but does not return
// a promise based on that.
// "function track(sb: PayloadData, context?: Array<SelfDescribingJson>, tstamp?: Timestamp): PayloadData {"
swdcTracker.spTracker.trackUnstructEvent(event_payload, contexts);
}
catch (e) {
// We may get IPIPE, or ECONNRESET. Log it.
console.log("swdc-tracker unstruct track event error", e);
}
return [2 /*return*/, response_1.success()];
});

@@ -162,0 +184,0 @@ });

@@ -5,31 +5,5 @@ /**

*/
export declare function buildContexts(params: any): ({
export declare function buildContexts(params: any): Promise<({
schema: string;
data: {
keystrokes: number;
chars_added: number;
chars_deleted: number;
chars_pasted: number;
pastes: number;
lines_added: number;
lines_deleted: number;
start_time: number;
end_time: number;
tz_offset_minutes: number;
};
} | {
schema: string;
data: {
entity: string;
type: string;
tz_offset_minutes: number;
};
} | {
schema: string;
data: {
interaction_type: string;
};
} | {
schema: string;
data: {
element_name: string;

@@ -51,3 +25,3 @@ element_location: string;

repo_identifier: any;
reop_name: any;
repo_name: any;
owner_id: any;

@@ -78,2 +52,2 @@ git_branch: any;

};
})[];
})[]>;
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildContexts = void 0;
var codetime_1 = require("../events/codetime");
var editor_action_1 = require("../events/editor_action");
var auth_1 = require("../entities/auth");

@@ -11,3 +45,2 @@ var project_1 = require("../entities/project");

var plugin_1 = require("../entities/plugin");
var ui_interaction_1 = require("../events/ui_interaction");
var ui_element_1 = require("../entities/ui_element");

@@ -19,48 +52,51 @@ /**

function buildContexts(params) {
var contexts = [];
// code time
if (codetime_1.CodeTime.hasData(params)) {
var _codetimePayload = new codetime_1.CodeTime(params).buildPayload();
contexts.push(_codetimePayload);
}
// editor action
if (editor_action_1.EditorAction.hasData(params)) {
var _editorActionPayload = new editor_action_1.EditorAction(params).buildPayload();
contexts.push(_editorActionPayload);
}
// ui interaction
if (ui_interaction_1.UIInteraction.hasData(params)) {
var _uiInteractionPayload = new ui_interaction_1.UIInteraction(params).buildPayload();
contexts.push(_uiInteractionPayload);
}
// ui element
if (ui_element_1.UIElement.hasData(params)) {
var _uiElementPayload = new ui_element_1.UIElement(params).buildPayload();
contexts.push(_uiElementPayload);
}
// project
if (project_1.Project.hasData(params)) {
var _projecPayload = new project_1.Project(params).buildPayload();
contexts.push(_projecPayload);
}
// repo
if (repo_1.Repo.hasData(params)) {
var _repoPayload = new repo_1.Repo(params).buildPayload();
contexts.push(_repoPayload);
}
// file
if (file_1.File.hasData(params)) {
var _filePayload = new file_1.File(params).buildPayload();
contexts.push(_filePayload);
}
// plugin
if (plugin_1.Plugin.hasData(params)) {
var _pluginPayload = new plugin_1.Plugin(params).buildPayload();
contexts.push(_pluginPayload);
}
// Auth is required
var _authPayload = new auth_1.Auth(params).buildPayload();
contexts.push(_authPayload);
return contexts;
return __awaiter(this, void 0, void 0, function () {
var contexts, _uiElementPayload, _projectPayload, _repoPayload, _filePayload, _pluginPayload, _authPayload;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
contexts = [];
if (!ui_element_1.UIElement.hasData(params)) return [3 /*break*/, 2];
return [4 /*yield*/, new ui_element_1.UIElement(params).buildPayload()];
case 1:
_uiElementPayload = _a.sent();
contexts.push(_uiElementPayload);
_a.label = 2;
case 2:
if (!project_1.Project.hasData(params)) return [3 /*break*/, 4];
return [4 /*yield*/, new project_1.Project(params).buildPayload(params.jwt)];
case 3:
_projectPayload = _a.sent();
contexts.push(_projectPayload);
_a.label = 4;
case 4:
if (!repo_1.Repo.hasData(params)) return [3 /*break*/, 6];
return [4 /*yield*/, new repo_1.Repo(params).buildPayload(params.jwt)];
case 5:
_repoPayload = _a.sent();
contexts.push(_repoPayload);
_a.label = 6;
case 6:
if (!file_1.File.hasData(params)) return [3 /*break*/, 8];
return [4 /*yield*/, new file_1.File(params).buildPayload(params.jwt)];
case 7:
_filePayload = _a.sent();
contexts.push(_filePayload);
_a.label = 8;
case 8:
if (!plugin_1.Plugin.hasData(params)) return [3 /*break*/, 10];
return [4 /*yield*/, new plugin_1.Plugin(params).buildPayload()];
case 9:
_pluginPayload = _a.sent();
contexts.push(_pluginPayload);
_a.label = 10;
case 10: return [4 /*yield*/, new auth_1.Auth(params).buildPayload()];
case 11:
_authPayload = _a.sent();
contexts.push(_authPayload);
return [2 /*return*/, contexts];
}
});
});
}
exports.buildContexts = buildContexts;

@@ -7,1 +7,2 @@ export declare enum TrackerMode {

export declare function isTestMode(): boolean;
export declare function getPackageJson(): any;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isTestMode = exports.getTrackerMode = exports.TrackerMode = void 0;
exports.getPackageJson = exports.isTestMode = exports.getTrackerMode = exports.TrackerMode = void 0;
var pckg = require("../../package.json");
var TrackerMode;

@@ -10,6 +11,6 @@ (function (TrackerMode) {

function getTrackerMode() {
if (process.env.ENABLE_SWDC_TRACKER === "true") {
return TrackerMode.PROD;
if (process.env.NODE_ENV == "test") {
return TrackerMode.TEST;
}
return TrackerMode.TEST;
return TrackerMode.PROD;
}

@@ -21,1 +22,13 @@ exports.getTrackerMode = getTrackerMode;

exports.isTestMode = isTestMode;
function getPackageJson() {
if (pckg) {
return pckg;
}
// unable to import the package json, use defaults
// 1.0.21 is the version this was introduced
return {
name: "swdc-tracker",
version: "1.0.21"
};
}
exports.getPackageJson = getPackageJson;

@@ -1,1 +0,1 @@

export declare function hashValue(value: string): any;
export declare function hashValue(value: string, dataType: string, jwt?: string): Promise<any>;
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.hashValue = void 0;
var blake3 = require('blake3');
function hashValue(value) {
if (!value) {
return value;
}
return blake3.hash(value, { length: 64 }).toString('hex');
var http_1 = require("./http");
var _sodium = require('libsodium-wrappers');
var sodium;
var userHashedValues;
function hashValue(value, dataType, jwt) {
return __awaiter(this, void 0, void 0, function () {
var hashedValue, hashValueAlreadyExists;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!jwt) {
return [2 /*return*/, ""];
}
if (!value) {
return [2 /*return*/, value];
}
if (!(sodium === undefined)) return [3 /*break*/, 2];
return [4 /*yield*/, Promise.all([setUserHashedValues(jwt), _sodium.ready]).then(function () {
sodium = _sodium;
})];
case 1:
_a.sent();
_a.label = 2;
case 2:
hashedValue = sodium.to_hex(sodium.crypto_generichash(64, value));
hashValueAlreadyExists = !!userHashedValues[dataType] && userHashedValues[dataType].includes(hashedValue);
if (!!hashValueAlreadyExists) return [3 /*break*/, 4];
return [4 /*yield*/, encryptValue(value, hashedValue, dataType, jwt)];
case 3:
_a.sent();
setUserHashedValues(jwt);
_a.label = 4;
case 4: return [2 /*return*/, hashedValue];
}
});
});
}
exports.hashValue = hashValue;
function encryptValue(value, hashedValue, dataType, jwt) {
return __awaiter(this, void 0, void 0, function () {
var params;
return __generator(this, function (_a) {
if (!jwt) {
return [2 /*return*/, ""];
}
params = {
value: value,
hashed_value: hashedValue,
data_type: dataType
};
http_1.post("/user_encrypted_data", params, jwt);
return [2 /*return*/];
});
});
}
function setUserHashedValues(jwt) {
return __awaiter(this, void 0, void 0, function () {
var response;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, http_1.get("/hashed_values", jwt)];
case 1:
response = _a.sent();
userHashedValues = response.data;
return [2 /*return*/];
}
});
});
}

@@ -1,1 +0,3 @@

export declare function get(baseURL: string, endpoint: string): Promise<import("axios").AxiosResponse<any>>;
export declare function setBaseUrl(url: string): void;
export declare function get(endpoint: string, jwt?: string): Promise<any>;
export declare function post(endpoint: string, body: any, jwt: string): Promise<any>;

@@ -42,12 +42,35 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.get = void 0;
exports.post = exports.get = exports.setBaseUrl = void 0;
var axios_1 = __importDefault(require("axios"));
function get(baseURL, endpoint) {
var env_helper_1 = require("./env_helper");
// build the axios api base url
var axiosClient = {};
function setBaseUrl(url) {
axiosClient = axios_1.default.create({
baseURL: url,
timeout: 15000 // timeout so we're not getting ECONNRESET
});
// set the tracker version and ID
var _a = env_helper_1.getPackageJson(), name = _a.name, version = _a.version;
axiosClient.defaults.headers.common["X-SWDC-Tracker-Version"] = version;
axiosClient.defaults.headers.common["X-SWDC-Tracker-Id"] = name;
}
exports.setBaseUrl = setBaseUrl;
function get(endpoint, jwt) {
return __awaiter(this, void 0, void 0, function () {
var api, result;
var result;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
api = axios_1.default.create({ baseURL: baseURL });
return [4 /*yield*/, api.get(endpoint)];
if (jwt) {
axiosClient.defaults.headers.common["Authorization"] = jwt;
}
return [4 /*yield*/, axiosClient.get(endpoint).catch(function (e) {
// we need to catch an error so we're not getting this for example;
// UnhandledPromiseRejectionWarning: Error: connect ECONNREFUSED 127.0.0.1:80
// at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1141:16)
var msg = e.message || e.code;
console.log("swdc-tracker get request error", msg);
return e;
})];
case 1:

@@ -61,1 +84,21 @@ result = _a.sent();

exports.get = get;
function post(endpoint, body, jwt) {
return __awaiter(this, void 0, void 0, function () {
var result;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
axiosClient.defaults.headers.common["Authorization"] = jwt;
return [4 /*yield*/, axiosClient.post(endpoint, body).catch(function (e) {
var msg = e.message || e.code;
console.log("swdc-tracker post request error", msg);
return e;
})];
case 1:
result = _a.sent();
return [2 /*return*/, result];
}
});
});
}
exports.post = post;
{
"name": "swdc-tracker",
"version": "1.1.0",
"version": "1.2.0",
"description": "swdc event tracker",

@@ -14,3 +14,3 @@ "main": "dist",

"prepare": "yarn build",
"test": "yarn build && mocha -r ts-node/register test/**/*.ts --reporter spec --timeout 20000 --exit"
"test": "export NODE_ENV=test yarn build && mocha -r ts-node/register test/**/*.ts --reporter spec --timeout 20000 --exit"
},

@@ -29,5 +29,7 @@ "devDependencies": {

"axios": "^0.19.2",
"blake3": "^2.1.4",
"libsodium": "^0.7.6",
"libsodium-wrappers": "^0.7.6",
"lodash": "^4.17.19",
"snowplow-tracker": "^0.3.0"
}
}

@@ -31,6 +31,6 @@ import { hashValue } from "../utils/hash";

buildPayload() {
async buildPayload(jwt: string) {
const hashedName = hashValue(this.file_name);
const hashedPath = hashValue(this.file_path);
const hashedName = await hashValue(this.file_name, "file_name", jwt);
const hashedPath = await hashValue(this.file_path, "file_path", jwt);

@@ -37,0 +37,0 @@ return {

@@ -22,6 +22,6 @@ import { hashValue } from "../utils/hash";

buildPayload() {
async buildPayload(jwt: string) {
const hashedName = hashValue(this.project_name);
const hashedDirectory = hashValue(this.project_directory);
const hashedName = await hashValue(this.project_name, "project_name", jwt);
const hashedDirectory = await hashValue(this.project_directory, "project_directory", jwt);

@@ -28,0 +28,0 @@ return {

@@ -31,9 +31,9 @@ import { hashValue } from "../utils/hash";

buildPayload() {
async buildPayload(jwt: string) {
const hashedName = hashValue(this.repo_name);
const hashedIdentifier = hashValue(this.repo_identifier);
const hashedOwnerId = hashValue(this.owner_id);
const hashedGitBranch = hashValue(this.git_branch);
const hashedGitTag = hashValue(this.git_tag);
const hashedName = await hashValue(this.repo_name, "repo_name", jwt);
const hashedIdentifier = await hashValue(this.repo_identifier, "repo_identifier", jwt);
const hashedOwnerId = await hashValue(this.owner_id, "owner_id", jwt);
const hashedGitBranch = await hashValue(this.git_branch, "git_branch", jwt);
const hashedGitTag = await hashValue(this.git_tag, "git_tag", jwt);

@@ -44,3 +44,3 @@ return {

repo_identifier: hashedIdentifier,
reop_name: hashedName,
repo_name: hashedName,
owner_id: hashedOwnerId,

@@ -47,0 +47,0 @@ git_branch: hashedGitBranch,

@@ -29,5 +29,5 @@ // The ui_element interface

buildPayload() {
async buildPayload() {
return {
schema: "iglu:com.software/ui_element/jsonschema/1-0-1",
schema: "iglu:com.software/ui_element/jsonschema/1-0-2",
data: {

@@ -34,0 +34,0 @@ element_name: this.element_name,

@@ -10,11 +10,14 @@ import { RepoInterface } from "../entities/repo";

keystrokes: number,
chars_added: number,
chars_deleted: number,
chars_pasted: number,
pastes: number,
lines_added: number,
lines_deleted: number,
characters_added: number,
characters_deleted: number,
single_deletes: number,
multi_deletes: number,
single_adds: number,
multi_adds: number,
auto_indents: number,
replacements: number,
start_time: number,
end_time: number,
tz_offset_minutes: number
end_time: number
}

@@ -24,23 +27,29 @@

public keystrokes: number;
public chars_added: number;
public chars_deleted: number;
public chars_pasted: number;
public pastes: number;
public lines_added: number;
public lines_deleted: number;
public characters_added: number;
public characters_deleted: number;
public single_deletes: number;
public multi_deletes: number;
public single_adds: number;
public multi_adds: number;
public auto_indents: number;
public replacements: number;
public start_time: number;
public end_time: number;
public tz_offset_minutes: number;
constructor(data: CodeTimeInterface) {
this.keystrokes = data.keystrokes;
this.chars_added = data.chars_added;
this.chars_deleted = data.chars_deleted;
this.chars_pasted = data.chars_pasted;
this.pastes = data.pastes;
this.lines_added = data.lines_added;
this.lines_deleted = data.lines_deleted;
this.characters_added = data.characters_added;
this.characters_deleted = data.characters_deleted;
this.single_deletes = data.single_deletes;
this.multi_deletes = data.multi_deletes;
this.single_adds = data.single_adds;
this.multi_adds = data.multi_adds;
this.auto_indents = data.auto_indents;
this.replacements = data.replacements;
this.start_time = data.start_time;
this.end_time = data.end_time;
this.tz_offset_minutes = data.tz_offset_minutes;
}

@@ -55,14 +64,17 @@

return {
schema: "iglu:com.software/codetime/jsonschema/1-0-1",
schema: "iglu:com.software/codetime/jsonschema/1-0-2",
data: {
keystrokes: this.keystrokes,
chars_added: this.chars_deleted,
chars_deleted: this.chars_deleted,
chars_pasted: this.chars_pasted,
pastes: this.pastes,
lines_added: this.lines_added,
lines_deleted: this.lines_deleted,
characters_added: this.characters_added,
characters_deleted: this.characters_deleted,
single_deletes: this.single_deletes,
multi_deletes: this.multi_deletes,
single_adds: this.single_adds,
multi_adds: this.multi_adds,
auto_indents: this.auto_indents,
replacements: this.replacements,
start_time: this.start_time,
end_time: this.end_time,
tz_offset_minutes: this.tz_offset_minutes
end_time: this.end_time
}

@@ -69,0 +81,0 @@ }

@@ -5,8 +5,8 @@ import { PluginInterface } from "../entities/plugin";

import { AuthInterface } from "../entities/auth";
import { RepoInterface } from "../entities/repo";
// The EditorAction event
export interface EditorActionInterface {
entity: string,
type: string,
tz_offset_minutes: number
entity: string;
type: string;
}

@@ -17,3 +17,2 @@

public type: string;
public tz_offset_minutes: number;

@@ -23,3 +22,2 @@ constructor(data: EditorActionInterface) {

this.type = data.type;
this.tz_offset_minutes = data.tz_offset_minutes;
}

@@ -33,13 +31,17 @@

return {
schema: "iglu:com.software/editor_action/jsonschema/1-0-0",
schema: "iglu:com.software/editor_action/jsonschema/1-0-1",
data: {
entity: this.entity,
type: this.type,
tz_offset_minutes: this.tz_offset_minutes
}
}
type: this.type
},
};
}
}
export interface EditorActionParams extends
AuthInterface, PluginInterface, FileInterface, ProjectInterface, EditorActionInterface { }
export interface EditorActionParams
extends AuthInterface,
RepoInterface,
PluginInterface,
FileInterface,
ProjectInterface,
EditorActionInterface { }

@@ -1,2 +0,2 @@

import { get } from "./utils/http";
import { setBaseUrl, get } from "./utils/http";
import { CodeTimeParams, CodeTime } from "./events/codetime";

@@ -20,7 +20,13 @@ import { EditorActionParams, EditorAction } from "./events/editor_action";

// fetch tracker_api from plugin config
const result = await get(swdcApiHost, "/plugins/config")
const tracker_api_host = result.data.tracker_api
setBaseUrl(swdcApiHost);
const result = await get("/plugins/config");
const tracker_api_host = result.data.tracker_api;
const tracker_url_scheme = result.data.tracker_url_scheme || "https";
// initialize snowplow tracker
const e = emitter(tracker_api_host, 'https', null, 'post', 0)
// endpoint, protocol, optional port, method, buffer events, request callback
const e = emitter(tracker_api_host, tracker_url_scheme, null, "post", 0, function (error: any, body: any, response: any) {
if (error) {
console.log("swdc-tracker collector stream error", error);
}
});

@@ -30,2 +36,3 @@ swdcTracker.spTracker = tracker([e], namespace, appId, false)

if (isTestMode()) {

@@ -44,4 +51,3 @@ console.log('swdc-tracker test mode on. set env ENABLE_SWDC_TRACKER to "true" to send events');

/**
* @param jwt - the authorization token
* @param codetimeEvent - the CodeTime event extends Repo, Project, File
* @param codetimeEvent - the CodeTime event extends Repo, Project, File, Auth
*/

@@ -51,4 +57,4 @@ swdcTracker.trackCodeTimeEvent = async (params: CodeTimeParams): Promise<any> => {

// build the contexts and event payload
const _codetimePayload: any = new CodeTime(params).buildPayload();
const contexts: any = buildContexts(params);
const _codetimePayload: any = await new CodeTime(params).buildPayload();
const contexts: any = await buildContexts(params);

@@ -65,4 +71,4 @@ return await sendEvent(_codetimePayload, contexts);

// build the contexts and event payload
const _editorActionPayload: any = new EditorAction(params).buildPayload();
const contexts: any = buildContexts(params);
const _editorActionPayload: any = await new EditorAction(params).buildPayload();
const contexts: any = await buildContexts(params);

@@ -79,4 +85,4 @@ return await sendEvent(_editorActionPayload, contexts);

// build the contexts and event payload
const _uiInteractionPayload: any = new UIInteraction(params).buildPayload();
const contexts: any = buildContexts(params);
const _uiInteractionPayload: any = await new UIInteraction(params).buildPayload();
const contexts: any = await buildContexts(params);

@@ -92,10 +98,20 @@ return await sendEvent(_uiInteractionPayload, contexts);

// trackUnstrucEvent returns a PayloadData type:
// {add <func(key, val)>, addDict <func(dict)>, addJson <func(keyIfEncoded, keyIfNotEncoded, json)>, build <func()>}
const eventResult: any = await swdcTracker.spTracker.trackUnstructEvent(event_payload, contexts);
try {
/**
* trackUnstructEvent takes the following:
* properties => json of {schema, data} (required)
* context => list of event contexts (optional)
* tstamp => positive integer (optional)
*/
// The track logic is not async, no need to have an await,
// "track()" will perform a callback on the payload data but does not return
// a promise based on that.
// "function track(sb: PayloadData, context?: Array<SelfDescribingJson>, tstamp?: Timestamp): PayloadData {"
swdcTracker.spTracker.trackUnstructEvent(event_payload, contexts);
} catch (e) {
// We may get IPIPE, or ECONNRESET. Log it.
console.log("swdc-tracker unstruct track event error", e);
}
if (eventResult && eventResult.add) {
return success();
}
return error();
return success();
}

@@ -102,0 +118,0 @@

@@ -15,27 +15,9 @@ import { CodeTime } from "../events/codetime";

*/
export function buildContexts(params: any) {
export async function buildContexts(params: any) {
const contexts = [];
// code time
if (CodeTime.hasData(params)) {
const _codetimePayload = new CodeTime(params).buildPayload();
contexts.push(_codetimePayload);
}
// editor action
if (EditorAction.hasData(params)) {
const _editorActionPayload = new EditorAction(params).buildPayload();
contexts.push(_editorActionPayload);
}
// ui interaction
if (UIInteraction.hasData(params)) {
const _uiInteractionPayload = new UIInteraction(params).buildPayload();
contexts.push(_uiInteractionPayload);
}
// ui element
if (UIElement.hasData(params)) {
const _uiElementPayload = new UIElement(params).buildPayload();
const _uiElementPayload = await new UIElement(params).buildPayload();
contexts.push(_uiElementPayload);

@@ -46,4 +28,4 @@ }

if (Project.hasData(params)) {
const _projecPayload = new Project(params).buildPayload();
contexts.push(_projecPayload);
const _projectPayload = await new Project(params).buildPayload(params.jwt);
contexts.push(_projectPayload);
}

@@ -53,3 +35,3 @@

if (Repo.hasData(params)) {
const _repoPayload = new Repo(params).buildPayload();
const _repoPayload = await new Repo(params).buildPayload(params.jwt);
contexts.push(_repoPayload);

@@ -60,3 +42,3 @@ }

if (File.hasData(params)) {
const _filePayload = new File(params).buildPayload();
const _filePayload = await new File(params).buildPayload(params.jwt);
contexts.push(_filePayload);

@@ -67,3 +49,3 @@ }

if (Plugin.hasData(params)) {
const _pluginPayload = new Plugin(params).buildPayload();
const _pluginPayload = await new Plugin(params).buildPayload();
contexts.push(_pluginPayload);

@@ -73,3 +55,3 @@ }

// Auth is required
const _authPayload = new Auth(params).buildPayload();
const _authPayload = await new Auth(params).buildPayload();
contexts.push(_authPayload);

@@ -76,0 +58,0 @@

@@ -0,1 +1,3 @@

const pckg = require("../../package.json");
export enum TrackerMode {

@@ -7,6 +9,6 @@ TEST = "test",

export function getTrackerMode(): TrackerMode {
if (process.env.ENABLE_SWDC_TRACKER === "true") {
return TrackerMode.PROD;
if (process.env.NODE_ENV == "test") {
return TrackerMode.TEST
}
return TrackerMode.TEST
return TrackerMode.PROD;
}

@@ -16,2 +18,15 @@

return getTrackerMode() === TrackerMode.TEST ? true : false;
}
}
export function getPackageJson(): any {
if (pckg) {
return pckg;
}
// unable to import the package json, use defaults
// 1.0.21 is the version this was introduced
return {
name: "swdc-tracker",
version: "1.0.21"
};
}

@@ -1,4 +0,13 @@

const blake3 = require('blake3');
import { get, post } from "./http";
export function hashValue(value: string) {
const _sodium = require('libsodium-wrappers');
let sodium: any;
let userHashedValues: any;
export async function hashValue(value: string, dataType: string, jwt?: string) {
if (!jwt) {
return ""
}
if (!value) {

@@ -8,3 +17,37 @@ return value;

return blake3.hash(value, { length: 64 }).toString('hex');
if (sodium === undefined) {
await Promise.all([setUserHashedValues(jwt), _sodium.ready]).then(() => {
sodium = _sodium;
});
}
const hashedValue = sodium.to_hex(sodium.crypto_generichash(64, value));
const hashValueAlreadyExists = !!userHashedValues[dataType] && userHashedValues[dataType].includes(hashedValue);
if (!hashValueAlreadyExists) {
await encryptValue(value, hashedValue, dataType, jwt);
setUserHashedValues(jwt);
}
return hashedValue;
}
async function encryptValue(value: string, hashedValue: string, dataType: string, jwt?: string) {
if (!jwt) {
return ""
}
const params = {
value: value,
hashed_value: hashedValue,
data_type: dataType
}
post("/user_encrypted_data", params, jwt);
}
async function setUserHashedValues(jwt: string) {
const response = await get("/hashed_values", jwt);
userHashedValues = response.data;
}
import axios from "axios";
import { getPackageJson } from "./env_helper";
export async function get(baseURL: string, endpoint: string) {
const api = axios.create({ baseURL: baseURL });
const result = await api.get(endpoint);
// build the axios api base url
let axiosClient: any = {};
export function setBaseUrl(url: string) {
axiosClient = axios.create({
baseURL: url,
timeout: 15000 // timeout so we're not getting ECONNRESET
});
// set the tracker version and ID
const { name, version } = getPackageJson();
axiosClient.defaults.headers.common["X-SWDC-Tracker-Version"] = version;
axiosClient.defaults.headers.common["X-SWDC-Tracker-Id"] = name;
}
export async function get(endpoint: string, jwt?: string) {
if (jwt) {
axiosClient.defaults.headers.common["Authorization"] = jwt;
}
const result = await axiosClient.get(endpoint).catch((e: any) => {
// we need to catch an error so we're not getting this for example;
// UnhandledPromiseRejectionWarning: Error: connect ECONNREFUSED 127.0.0.1:80
// at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1141:16)
const msg = e.message || e.code;
console.log("swdc-tracker get request error", msg);
return e;
});
return result;
}
}
export async function post(endpoint: string, body: any, jwt: string) {
axiosClient.defaults.headers.common["Authorization"] = jwt;
const result = await axiosClient.post(endpoint, body).catch((e: any) => {
const msg = e.message || e.code;
console.log("swdc-tracker post request error", msg);
return e;
});
return result;
}

@@ -32,13 +32,17 @@ import swdcTracker from "../../src/index";

keystrokes: 20,
chars_added: 10,
chars_deleted: 10,
pastes: 0,
lines_added: 0,
lines_deleted: 0,
start_time: 1,
end_time: 2,
tz_offset_minutes: 420,
lines_added: 2,
lines_deleted: 3,
characters_added: 111,
characters_deleted: 10,
single_deletes: 9,
multi_deletes: 1,
single_adds: 100,
multi_adds: 12,
auto_indents: 14,
replacements: 99,
start_time: "2020-07-29T01:04:03Z",
end_time: "2020-07-29T01:04:20Z",
plugin_id: 4,
plugin_name: "code-time",
plugin_version: "2.1.20",
plugin_version: "2.1.999",
project_name: "foo",

@@ -60,7 +64,23 @@ project_directory: "baz"

expect(props.data.keystrokes).to.equal(20);
expect(props.data.lines_added).to.equal(2);
expect(props.data.lines_deleted).to.equal(3);
expect(props.data.characters_added).to.equal(111);
expect(props.data.characters_deleted).to.equal(10);
expect(props.data.single_deletes).to.equal(9);
expect(props.data.multi_deletes).to.equal(1);
expect(props.data.single_adds).to.equal(100);
expect(props.data.multi_adds).to.equal(12);
expect(props.data.auto_indents).to.equal(14);
expect(props.data.replacements).to.equal(99);
expect(props.data.start_time).to.equal("2020-07-29T01:04:03Z");
expect(props.data.end_time).to.equal("2020-07-29T01:04:20Z");
// get the plugin context
const pluginContext: any = contexts.find((n: any) => n.schema.includes("plugin"));
expect(pluginContext.data.plugin_id).to.equal(4);
expect(pluginContext.data.plugin_name).to.equal("code-time");
expect(pluginContext.data.plugin_version).to.equal("2.1.999");
const projectContext: any = contexts.find((n: any) => n.schema.includes("project"));
expect(projectContext.data.project_name).to.be.a('string').that.matches(/^[a-f0-9]{128}$/);
expect(projectContext.data.project_directory).to.be.a('string').that.matches(/^[a-f0-9]{128}$/);
})
});
});
import { hashValue } from "../../src/utils/hash";
import { expect } from 'chai'
const expect = require("chai").expect;
const sinon = require("sinon");
const http = require("../../src/utils/http");
const sinon = require("sinon")
describe("Hash Utility", function () {
context("when the parameter is empty string", function () {
let string_param = "";
const sandbox = sinon.createSandbox();
it("returns empty string", function () {
expect(hashValue(string_param)).to.equal("");
context("when the JWT is not supplied", async function () {
beforeEach(function () {
// return any api since we're not really trying to call out
sandbox.stub(http, "get").callsFake(function () {
return { data: {} }
});
sandbox.stub(http, "post").callsFake()
});
afterEach(function () {
sandbox.restore();
});
let string_param = "something";
it("returns empty string", async function () {
expect(await hashValue(string_param, "test-data-type")).to.equal("");
});
it("does NOT encrypt the value", async function () {
await hashValue(string_param, "test-data-type")
expect(http.post.callCount).to.eq(0)
});
it("does not get hashed_values", async function () {
await hashValue(string_param, "test-data-type")
expect(http.get.callCount).to.eq(0)
});
});
context("when the parameter is a string", function () {
context("when the parameter is empty string", async function () {
let string_param = "";
it("returns empty string", async function () {
expect(await hashValue(string_param, "test-data-type", "test-jwt")).to.equal("");
});
});
context("when the parameter is a string", async function () {
// the first hashed value in file_name = "alreadyexists"
let hashedValueThatAlreadyExists = "b6462a82e047f8fd12103ddeace50a4024f88cbcaf01c8705ff6a741408d3df1d70c57e65f80409d1098797b3dd428812443eef566e4dcbab2168734bacdc501"
let userHashedValues = {
"file_name": [hashedValueThatAlreadyExists, "fasdfsda", "asdfasdfsdew"],
"project_name": ["bbaljbl", "fjsfiejwil", "faksdjfjsad"]
};
let string_param = "secret_message";
let expectedHashedValue = '998504e62163ab1030d14ec90ba2d4e4dd87707f2591fcdcb6473e6f6c260778cdaed8b9e913b3965b9ab331553eedcbfb877b3268c3fa414a4cb09a5b30ee05'
it("returns a hashed string with 128 character length", function () {
let result = hashValue(string_param);
beforeEach(function() {
// return any api since we're not really trying to call out
sandbox.stub(http, "get").callsFake(function () {
return { data: userHashedValues }
});
sandbox.stub(http, "post").callsFake()
});
afterEach(function() {
sandbox.restore();
});
it("returns a hashed string with 128 character length", async function () {
let result = await hashValue(string_param, "project_name", 'test-jwt');
expect(result).to.be.a('string')
.that.matches(/^[a-f0-9]{128}$/)
.and.equal('51d9ca721aa09fde72ec722137a3ac8fef053a49df4b2354e36fd95dc3372e881f3a41b9e625d2acb5775f390e98069ee8510296949966b0b8a72a558a42a073');
.and.equal(expectedHashedValue);
});
it("gets the user's hashed values", async function () {
await hashValue(string_param, "test-data-type", "test-jwt");
expect(http.get.calledWith("/hashed_values", "test-jwt")).to.eq(true)
});
context("when user hashed value does not exist", function() {
it("encrypts the value", async function() {
await hashValue(string_param, "test-data-type", "test-jwt");
expect(http.post.calledWith(
"/user_encrypted_data",
{
value: string_param,
hashed_value: expectedHashedValue,
data_type: "test-data-type"
},
"test-jwt"
)).to.eq(true)
})
it("gets the hashedValue list for the user", async function() {
await hashValue(string_param, "test-data-type", "test-jwt");
expect(http.get.callCount).to.eq(1)
})
});
context("when the user hashed value already exists", function() {
it("does NOT encrypt the value", async function() {
await hashValue("alreadyexists", "file_name", "test-jwt");
expect(http.post.callCount).to.eq(0)
});
it("does NOT GET the hashedValue list for the user", async function() {
await hashValue("alreadyexists", "file_name", "test-jwt");
expect(http.get.callCount).to.eq(0)
})
it("returns a hashed string with 128 character length", async function () {
const result = await hashValue("alreadyexists", "file_name", "test-jwt");
expect(result).to.be.a('string')
.that.matches(/^[a-f0-9]{128}$/)
.and.equal(hashedValueThatAlreadyExists);
});
})
});
});
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