swdc-tracker
Advanced tools
Comparing version 1.0.5 to 1.0.6
"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) { | ||
@@ -51,4 +40,9 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
var http_1 = require("./utils/http"); | ||
var data_structures_1 = require("./utils/data_structures"); | ||
var dom_event_model_1 = require("./models/dom_event.model"); | ||
var codetime_1 = require("./events/codetime"); | ||
var editor_action_1 = require("./events/editor_action"); | ||
var auth_1 = require("./entities/auth"); | ||
var project_1 = require("./entities/project"); | ||
var repo_1 = require("./entities/repo"); | ||
var file_1 = require("./entities/file"); | ||
var plugin_1 = require("./entities/plugin"); | ||
var snowplow = require('snowplow-tracker'); | ||
@@ -87,113 +81,101 @@ var emitter = snowplow.emitter; | ||
}); }; | ||
swdcTracker.trackEditorAction = function (_a) { | ||
var jwt = _a.jwt, entity = _a.entity, type = _a.type, tz_offset_minutes = _a.tz_offset_minutes, file_name = _a.file_name, file_path = _a.file_path, file_syntax = _a.file_syntax, file_line_count = _a.file_line_count, file_character_count = _a.file_character_count, project_name = _a.project_name, project_directory = _a.project_directory, plugin_id = _a.plugin_id, plugin_version = _a.plugin_version; | ||
return __awaiter(void 0, void 0, void 0, function () { | ||
var properties, _filePayload, _projectPayload, contexts; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
properties = { | ||
schema: "iglu:com.software/editor_action/jsonschema/1-0-0", | ||
data: { | ||
entity: entity, | ||
type: type, | ||
tz_offset_minutes: tz_offset_minutes | ||
} | ||
}; | ||
return [4 /*yield*/, data_structures_1.filePayload(file_name, file_path, file_syntax, file_line_count, file_character_count)]; | ||
case 1: | ||
_filePayload = _b.sent(); | ||
return [4 /*yield*/, data_structures_1.projectPayload(project_name, project_directory)]; | ||
case 2: | ||
_projectPayload = _b.sent(); | ||
contexts = [ | ||
data_structures_1.authPayload(jwt), | ||
_filePayload, | ||
_projectPayload, | ||
data_structures_1.pluginPayload(plugin_id, plugin_version) | ||
]; | ||
if (swdcTracker.testMode) { | ||
testEvent(properties, contexts); | ||
} | ||
else { | ||
swdcTracker.spTracker.trackUnstructEvent(properties, contexts); | ||
} | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
/** | ||
* @param jwt - the authorization token | ||
* @param codetimeEvent - the CodeTime event extends Repo, Project, File | ||
*/ | ||
swdcTracker.trackCodeTimeEvent = function (params) { return __awaiter(void 0, void 0, void 0, function () { | ||
var codetime, project, repo, file, plugin, auth, _codetimePayload, _projecPayload, _repoPayload, _filePayload, _pluginPayload, _authPayload, contexts; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
codetime = new codetime_1.CodeTime(params); | ||
project = new project_1.Project(params); | ||
repo = new repo_1.Repo(params); | ||
file = new file_1.File(params); | ||
plugin = new plugin_1.Plugin(params); | ||
auth = new auth_1.Auth(params); | ||
return [4 /*yield*/, codetime.buildPayload()]; | ||
case 1: | ||
_codetimePayload = _a.sent(); | ||
return [4 /*yield*/, project.buildPayload()]; | ||
case 2: | ||
_projecPayload = _a.sent(); | ||
return [4 /*yield*/, repo.buildPayload()]; | ||
case 3: | ||
_repoPayload = _a.sent(); | ||
return [4 /*yield*/, file.buildPayload()]; | ||
case 4: | ||
_filePayload = _a.sent(); | ||
return [4 /*yield*/, plugin.buildPayload()]; | ||
case 5: | ||
_pluginPayload = _a.sent(); | ||
return [4 /*yield*/, auth.buildPayload()]; | ||
case 6: | ||
_authPayload = _a.sent(); | ||
contexts = [ | ||
_authPayload, | ||
_codetimePayload, | ||
_projecPayload, | ||
_repoPayload, | ||
_filePayload, | ||
_pluginPayload | ||
]; | ||
if (swdcTracker.testMode) { | ||
// test mode - console log the event | ||
return [2 /*return*/, testEvent(_codetimePayload, contexts)]; | ||
} | ||
return [4 /*yield*/, swdcTracker.spTracker.trackUnstructEvent(_codetimePayload, contexts)]; | ||
case 7: | ||
// track the event. | ||
// trackUnstrucEvent returns... | ||
// {add <func(key, val)>, addDict <func(dict)>, addJson <func(keyIfEncoded, keyIfNotEncoded, json)>, build <func()>} | ||
return [2 /*return*/, _a.sent()]; | ||
} | ||
}); | ||
}; | ||
swdcTracker.trackCodetime = function (_a) { | ||
var jwt = _a.jwt, keystrokes = _a.keystrokes, chars_added = _a.chars_added, chars_deleted = _a.chars_deleted, chars_pasted = _a.chars_pasted, pastes = _a.pastes, lines_added = _a.lines_added, lines_deleted = _a.lines_deleted, start_time = _a.start_time, // UTC start timestamp in rfc 3339 format | ||
end_time = _a.end_time, // UTC end timestamp inrfc 3339 format | ||
tz_offset_minutes = _a.tz_offset_minutes, file_name = _a.file_name, file_path = _a.file_path, file_syntax = _a.file_syntax, file_line_count = _a.file_line_count, file_character_count = _a.file_character_count, project_name = _a.project_name, project_directory = _a.project_directory, plugin_id = _a.plugin_id, plugin_version = _a.plugin_version, repo_identifier = _a.repo_identifier, repo_name = _a.repo_name, repo_owner_id = _a.repo_owner_id, repo_git_branch = _a.repo_git_branch, repo_git_tag = _a.repo_git_tag; | ||
var properties = { | ||
schema: "iglu:com.software/codetime/jsonschema/1-0-0", | ||
data: { | ||
keystrokes: keystrokes, | ||
chars_added: chars_added, | ||
chars_deleted: chars_deleted, | ||
chars_pasted: chars_pasted, | ||
pastes: pastes, | ||
lined_added: lines_added, | ||
lined_deleted: lines_deleted, | ||
start_time: start_time, | ||
end_time: end_time, | ||
tz_offset_minutes: tz_offset_minutes | ||
} | ||
}; | ||
var _filePayload = data_structures_1.filePayload(file_name, file_path, file_syntax, file_line_count, file_character_count); | ||
var _projectPayload = data_structures_1.projectPayload(project_name, project_directory); | ||
var _repoPayload = data_structures_1.repoPayload(repo_identifier, repo_name, repo_owner_id, repo_git_branch, repo_git_tag); | ||
var contexts = [ | ||
data_structures_1.authPayload(jwt), | ||
_filePayload, | ||
_projectPayload, | ||
data_structures_1.pluginPayload(plugin_id, plugin_version), | ||
_repoPayload | ||
]; | ||
if (swdcTracker.testMode) { | ||
testEvent(properties, contexts); | ||
} | ||
else { | ||
swdcTracker.spTracker.trackUnstructEvent(properties, contexts); | ||
} | ||
}; | ||
}); }; | ||
/** | ||
* 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 | ||
* @param editorActionEvent - the DomEvent properties (extends plugin, event_meta, and time_info) | ||
*/ | ||
swdcTracker.trackDomEvent = function (jwt, domEvent) { return __awaiter(void 0, void 0, void 0, function () { | ||
var properties, _domEventPayload, contexts; | ||
swdcTracker.trackEditorAction = function (params) { return __awaiter(void 0, void 0, void 0, function () { | ||
var editorAction, plugin, file, project, auth, _editorActionPayload, _projecPayload, _filePayload, _pluginPayload, _authPayload, 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)]; | ||
editorAction = new editor_action_1.EditorAction(params); | ||
plugin = new plugin_1.Plugin(params); | ||
file = new file_1.File(params); | ||
project = new project_1.Project(params); | ||
auth = new auth_1.Auth(params); | ||
return [4 /*yield*/, editorAction.buildPayload()]; | ||
case 1: | ||
_domEventPayload = _a.sent(); | ||
_editorActionPayload = _a.sent(); | ||
return [4 /*yield*/, project.buildPayload()]; | ||
case 2: | ||
_projecPayload = _a.sent(); | ||
return [4 /*yield*/, file.buildPayload()]; | ||
case 3: | ||
_filePayload = _a.sent(); | ||
return [4 /*yield*/, plugin.buildPayload()]; | ||
case 4: | ||
_pluginPayload = _a.sent(); | ||
return [4 /*yield*/, auth.buildPayload()]; | ||
case 5: | ||
_authPayload = _a.sent(); | ||
contexts = [ | ||
data_structures_1.authPayload(jwt), | ||
_domEventPayload | ||
_authPayload, | ||
_editorActionPayload, | ||
_pluginPayload, | ||
_filePayload, | ||
_projecPayload | ||
]; | ||
if (swdcTracker.testMode) { | ||
// test mode - console log the event | ||
return [2 /*return*/, testEvent(properties, contexts)]; | ||
return [2 /*return*/, testEvent(_editorActionPayload, contexts)]; | ||
} | ||
return [4 /*yield*/, swdcTracker.spTracker.trackUnstructEvent(properties, contexts)]; | ||
case 2: | ||
return [4 /*yield*/, swdcTracker.spTracker.trackUnstructEvent(_editorActionPayload, contexts)]; | ||
case 6: | ||
// 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; | ||
// } | ||
// trackUnstrucEvent returns... | ||
// {add <func(key, val)>, addDict <func(dict)>, addJson <func(keyIfEncoded, keyIfNotEncoded, json)>, build <func()>} | ||
return [2 /*return*/, _a.sent()]; | ||
@@ -200,0 +182,0 @@ } |
@@ -48,2 +48,5 @@ "use strict"; | ||
case 0: | ||
if (!value) { | ||
return [2 /*return*/, value]; | ||
} | ||
if (!(sodium === undefined)) return [3 /*break*/, 2]; | ||
@@ -50,0 +53,0 @@ return [4 /*yield*/, _sodium.ready]; |
{ | ||
"name": "swdc-tracker", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"description": "swdc event tracker", | ||
@@ -5,0 +5,0 @@ "main": "dist", |
236
src/index.ts
import { get } from "./utils/http"; | ||
import { | ||
filePayload, | ||
projectPayload, | ||
pluginPayload, | ||
repoPayload, | ||
authPayload | ||
} from './utils/data_structures'; | ||
import { DomEvent, domEventPayload } from "./models/dom_event.model"; | ||
import { CodeTimeParams, CodeTime } from "./events/codetime"; | ||
import { EditorActionParams, EditorAction } from "./events/editor_action"; | ||
import { Auth } from "./entities/auth"; | ||
import { Project } from "./entities/project"; | ||
import { Repo } from "./entities/repo"; | ||
import { File } from "./entities/file"; | ||
import { Plugin } from "./entities/plugin"; | ||
@@ -41,171 +40,82 @@ const snowplow = require('snowplow-tracker'); | ||
interface EditorActionParams { | ||
jwt: string, | ||
entity: string, | ||
type: string, | ||
tz_offset_minutes: number, | ||
file_name: string, | ||
file_path: string, | ||
file_syntax: string, | ||
file_line_count: number, | ||
file_character_count: number, | ||
project_name: string, | ||
project_directory: string, | ||
plugin_id: number, | ||
plugin_version: string | ||
} | ||
/** | ||
* @param jwt - the authorization token | ||
* @param codetimeEvent - the CodeTime event extends Repo, Project, File | ||
*/ | ||
swdcTracker.trackCodeTimeEvent = async (params: CodeTimeParams): Promise<any> => { | ||
swdcTracker.trackEditorAction = async ({ | ||
jwt, | ||
entity, | ||
type, | ||
tz_offset_minutes, | ||
file_name, | ||
file_path, | ||
file_syntax, | ||
file_line_count, | ||
file_character_count, | ||
project_name, | ||
project_directory, | ||
plugin_id, | ||
plugin_version | ||
}: EditorActionParams) => { | ||
const properties = { | ||
schema: "iglu:com.software/editor_action/jsonschema/1-0-0", | ||
data: { | ||
entity: entity, | ||
type: type, | ||
tz_offset_minutes: tz_offset_minutes | ||
} | ||
} | ||
// build the strict types | ||
// code time | ||
const codetime: CodeTime = new CodeTime(params); | ||
// project | ||
const project: Project = new Project(params); | ||
// repo | ||
const repo: Repo = new Repo(params); | ||
// file | ||
const file: File = new File(params); | ||
// plugin | ||
const plugin: Plugin = new Plugin(params); | ||
// auth | ||
const auth: Auth = new Auth(params); | ||
const _filePayload = await filePayload(file_name, file_path, file_syntax, file_line_count, file_character_count); | ||
const _projectPayload = await projectPayload(project_name, project_directory); | ||
// create the payloads | ||
const _codetimePayload = await codetime.buildPayload(); | ||
const _projecPayload = await project.buildPayload(); | ||
const _repoPayload = await repo.buildPayload(); | ||
const _filePayload = await file.buildPayload(); | ||
const _pluginPayload = await plugin.buildPayload(); | ||
const _authPayload = await auth.buildPayload(); | ||
// crate the context with the authorization info | ||
const contexts = [ | ||
authPayload(jwt), | ||
_authPayload, | ||
_codetimePayload, | ||
_projecPayload, | ||
_repoPayload, | ||
_filePayload, | ||
_projectPayload, | ||
pluginPayload(plugin_id, plugin_version) | ||
_pluginPayload | ||
] | ||
if (swdcTracker.testMode) { | ||
testEvent(properties, contexts) | ||
} else { | ||
swdcTracker.spTracker.trackUnstructEvent(properties, contexts) | ||
// test mode - console log the event | ||
return testEvent(_codetimePayload, contexts) | ||
} | ||
} | ||
interface CodetimeParams { | ||
jwt: string, | ||
keystrokes: number, | ||
chars_added: number, | ||
chars_deleted: number, | ||
chars_pasted: number, | ||
pastes: number, | ||
lines_added: number, | ||
lines_deleted: number, | ||
start_time: string, // UTC start timestamp in rfc 3339 format | ||
end_time: string, // UTC end timestamp inrfc 3339 format | ||
tz_offset_minutes: number, | ||
file_name: string, | ||
file_path: string, | ||
file_syntax: string, | ||
file_line_count: number, | ||
file_character_count: number, | ||
project_name: string, | ||
project_directory: string, | ||
plugin_id: number, | ||
plugin_version: string, | ||
repo_identifier: string, | ||
repo_name: string, | ||
repo_owner_id: string, | ||
repo_git_branch: string, | ||
repo_git_tag: string | ||
// track the event. | ||
// trackUnstrucEvent returns... | ||
// {add <func(key, val)>, addDict <func(dict)>, addJson <func(keyIfEncoded, keyIfNotEncoded, json)>, build <func()>} | ||
return await swdcTracker.spTracker.trackUnstructEvent(_codetimePayload, contexts); | ||
} | ||
swdcTracker.trackCodetime = ({ | ||
jwt, | ||
keystrokes, | ||
chars_added, | ||
chars_deleted, | ||
chars_pasted, | ||
pastes, | ||
lines_added, | ||
lines_deleted, | ||
start_time, // UTC start timestamp in rfc 3339 format | ||
end_time, // UTC end timestamp inrfc 3339 format | ||
tz_offset_minutes, | ||
file_name, | ||
file_path, | ||
file_syntax, | ||
file_line_count, | ||
file_character_count, | ||
project_name, | ||
project_directory, | ||
plugin_id, | ||
plugin_version, | ||
repo_identifier, | ||
repo_name, | ||
repo_owner_id, | ||
repo_git_branch, | ||
repo_git_tag | ||
}: CodetimeParams) => { | ||
const properties = { | ||
schema: "iglu:com.software/codetime/jsonschema/1-0-0", | ||
data: { | ||
keystrokes: keystrokes, | ||
chars_added: chars_added, | ||
chars_deleted: chars_deleted, | ||
chars_pasted: chars_pasted, | ||
pastes: pastes, | ||
lined_added: lines_added, | ||
lined_deleted: lines_deleted, | ||
start_time: start_time, | ||
end_time: end_time, | ||
tz_offset_minutes: tz_offset_minutes | ||
} | ||
} | ||
const _filePayload = filePayload(file_name, file_path, file_syntax, file_line_count, file_character_count) | ||
const _projectPayload = projectPayload(project_name, project_directory) | ||
const _repoPayload = repoPayload(repo_identifier, repo_name, repo_owner_id, repo_git_branch, repo_git_tag) | ||
const contexts = [ | ||
authPayload(jwt), | ||
_filePayload, | ||
_projectPayload, | ||
pluginPayload(plugin_id, plugin_version), | ||
_repoPayload | ||
] | ||
if (swdcTracker.testMode) { | ||
testEvent(properties, contexts) | ||
} else { | ||
swdcTracker.spTracker.trackUnstructEvent(properties, contexts) | ||
} | ||
} | ||
/** | ||
* 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 | ||
* @param editorActionEvent - the DomEvent properties (extends plugin, event_meta, and time_info) | ||
*/ | ||
swdcTracker.trackDomEvent = async (jwt: string, domEvent: DomEvent): Promise<any> => { | ||
swdcTracker.trackEditorAction = async (params: EditorActionParams): Promise<any> => { | ||
// build the schema with the incoming props | ||
const properties = { | ||
schema: "iglu:com.software/code_event/jsonschema/1-0-0", | ||
data: { ...domEvent } | ||
} | ||
// build the strict types | ||
const editorAction: EditorAction = new EditorAction(params); | ||
// plugin | ||
const plugin: Plugin = new Plugin(params); | ||
// file | ||
const file: File = new File(params); | ||
// project | ||
const project: Project = new Project(params); | ||
// auth | ||
const auth: Auth = new Auth(params); | ||
// create the payload | ||
const _domEventPayload = await domEventPayload(properties.data); | ||
const _editorActionPayload = await editorAction.buildPayload(); | ||
const _projecPayload = await project.buildPayload(); | ||
const _filePayload = await file.buildPayload(); | ||
const _pluginPayload = await plugin.buildPayload(); | ||
const _authPayload = await auth.buildPayload(); | ||
// crate the context with the authorization info | ||
const contexts = [ | ||
authPayload(jwt), | ||
_domEventPayload | ||
_authPayload, | ||
_editorActionPayload, | ||
_pluginPayload, | ||
_filePayload, | ||
_projecPayload | ||
] | ||
@@ -215,15 +125,9 @@ | ||
// test mode - console log the event | ||
return testEvent(properties, contexts) | ||
return testEvent(_editorActionPayload, 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); | ||
// trackUnstrucEvent returns... | ||
// {add <func(key, val)>, addDict <func(dict)>, addJson <func(keyIfEncoded, keyIfNotEncoded, json)>, build <func()>} | ||
return await swdcTracker.spTracker.trackUnstructEvent(_editorActionPayload, contexts); | ||
} | ||
@@ -230,0 +134,0 @@ |
@@ -6,3 +6,7 @@ const _sodium = require('libsodium-wrappers'); | ||
export async function hashValue(value: string) { | ||
if(sodium === undefined) { | ||
if (!value) { | ||
return value; | ||
} | ||
if (sodium === undefined) { | ||
await _sodium.ready; | ||
@@ -9,0 +13,0 @@ sodium = _sodium |
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
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
83983
41
1640
1