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

clockify

Package Overview
Dependencies
Maintainers
0
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

clockify - npm Package Compare versions

Comparing version 0.6.5 to 0.7.5

61

bin/model.js

@@ -57,20 +57,18 @@ "use strict";

});
const getActivities = (socket, props) => __awaiter(void 0, void 0, void 0, function* () {
var _a;
if (!props.filterProperty || props.selectProperty) {
const getActivities = (_a) => __awaiter(void 0, [_a], void 0, function* ({ socket, filterProperty, selectProperty, }) {
if (!filterProperty && !selectProperty) {
const resp = yield (0, db_1.default)("select * from activities;", []);
if (resp.err) {
console.log(resp);
socket.write(JSON.stringify({
return {
err: true,
data: "db err - listing activities",
}));
};
}
if (typeof resp.data == "string") {
console.log("Err [model.getActivities] -> expected rows/array from db, got a string instead");
socket.write(JSON.stringify({
return {
err: true,
data: "server err - listing activities",
}));
return;
};
}

@@ -84,14 +82,18 @@ const onelineEntries = resp.data.map((itemObj) => {

});
return socket.write(JSON.stringify({ err: false, data: onelineEntries }));
return { err: false, data: onelineEntries };
}
let query = `select ${(_a = props === null || props === void 0 ? void 0 : props.selectProperty) !== null && _a !== void 0 ? _a : "*"} from activities where title=?`;
let query = `select ${selectProperty !== null && selectProperty !== void 0 ? selectProperty : "*"} from activities`;
const params = [];
if (filterProperty) {
query += ` where title=?`;
params.push(filterProperty);
}
// console.log(props)
const params = [props.filterProperty];
const resp = yield (0, db_1.default)(query, params);
if (resp.err) {
console.log(resp);
socket.write(JSON.stringify({
return {
err: true,
data: "db err - previewing activity",
}));
};
}

@@ -106,9 +108,3 @@ let respData = resp.data;

}
// console.log(respData);
respData = (props === null || props === void 0 ? void 0 : props.selectProperty) ? Object.values(respData)[0] : respData;
let onelineItem = [];
Object.values(respData).forEach((val) => {
onelineItem.push(val);
});
socket.write(JSON.stringify({ err: false, data: onelineItem.join(" | ") }));
return { err: false, data: respData };
});

@@ -307,3 +303,4 @@ const getEvents = (socket, props) => __awaiter(void 0, void 0, void 0, function* () {

});
const getDuration = (activity, duration) => __awaiter(void 0, void 0, void 0, function* () {
const getDuration = (_a) => __awaiter(void 0, [_a], void 0, function* ({ socket, activity, duration = "d", }) {
var _b, _c;
const existActivityResp = yield activityExists(activity);

@@ -313,3 +310,4 @@ if (!existActivityResp) {

}
let query = `select sum(duration) as duration from events where activity=?
let query = `select sum(duration) as duration
from events where activity=?
and date >= ?;`;

@@ -325,2 +323,6 @@ const freshDate = new Date();

}
else if (duration === "w") {
const weekOverflow = targetDuration.day % 7;
targetDuration.day -= weekOverflow > 0 ? weekOverflow - 1 : 6;
}
else if (duration === "y") {

@@ -331,3 +333,6 @@ targetDuration.month = 1;

let targetDurationString = `${targetDuration.year}-${targetDuration.month}-${targetDuration.day}`;
const params = [activity, utils_1.default.getDate(targetDurationString)];
console.log("date to parse: ", targetDurationString);
const seconds = utils_1.default.getDate(targetDurationString);
console.log("seconds: ", seconds);
const params = [activity, seconds];
// console.log(query)

@@ -339,3 +344,7 @@ // console.log(query);

if (resp.err) {
return resp;
return {
err: resp.err,
// @ts-ignore
data: (_b = resp.data[0].duration) !== null && _b !== void 0 ? _b : 0,
};
}

@@ -345,6 +354,8 @@ if (!resp.data.length) {

}
// @ts-ignore
const durationTime = utils_1.default.secToTime((_c = resp.data[0].duration) !== null && _c !== void 0 ? _c : 0);
return {
err: false,
// @ts-ignore
data: utils_1.default.secToTime(resp.data[0].duration),
data: durationTime,
};

@@ -351,0 +362,0 @@ });

@@ -73,2 +73,19 @@ "use strict";

let serverSocket = null;
const help = {
help: "help - list available commands",
init: "init - initialize database",
k: "k - kill server",
la: "la - list activities",
le: "le - list events",
ca: "ca - create activity",
// ra: "ra - remove activity"
d: [
"d - get duration of an activity",
" d [d, w, m] [activity]",
" if no activity provided, running activity will be shown",
],
da: ["d - get duration of all activities", " d [d, w, m]"],
v: "v - get status",
s: "s - toggle timer",
};
const actions = {

@@ -78,7 +95,10 @@ help: () => {

if (serverSocket) {
serverSocket.write(JSON.stringify({ err: false, data: Object.keys(actions).join(" - ") }));
serverSocket.write(JSON.stringify({
err: false,
data: Object.values(help).flat().join("\n"),
}));
}
},
init: (socket) => {
// todo: make this smarter
// todo: init on server startup
model_1.default.init(socket);

@@ -90,12 +110,17 @@ },

// list activities
la: (socket, request) => {
la: (socket, request) => __awaiter(void 0, void 0, void 0, function* () {
if (request.args[0] == "all" || request.args[0] == "a") {
model_1.default.getActivities(socket);
const resp = yield model_1.default.getActivities(socket);
return socket.write(JSON.stringify({
err: false,
data: resp.data,
}));
}
const args = {
const resp = yield model_1.default.getActivities({
socket,
filterProperty: request.args[0],
selectProperty: request.args[1],
};
model_1.default.getActivities(socket, args);
},
});
return socket.write(JSON.stringify({ err: false, data: resp.data }));
}),
// list events

@@ -137,3 +162,7 @@ le: (socket, request) => {

// console.log('hitting the db', timerObj.durationChache);
const resp = yield model_1.default.getDayDuration(socket, activity);
const resp = yield model_1.default.getDuration({
socket,
activity,
duration: "w",
});
// console.log(resp.data)

@@ -160,9 +189,65 @@ message = `${activity}: ${utils_1.default.secToTime(resp.data)}`;

}),
// get day duration
da: (socket, request) => __awaiter(void 0, void 0, void 0, function* () {
var _a;
// todo: get activities list
const resp = yield model_1.default.getActivities({
socket,
selectProperty: "title",
});
if (resp.err) {
socket.write(JSON.stringify({
err: true,
data: "db err - listing activities durations",
}));
return;
}
const activities = resp.data;
let message = "";
for (const activity of activities) {
const durationResp = yield model_1.default.getDuration({
socket,
activity: activity.title,
duration: (_a = request.args[0]) !== null && _a !== void 0 ? _a : "d",
});
console.log({ durationResp });
message += `${activity.title}: ${durationResp.data}\n`;
}
socket.write(JSON.stringify({ err: false, data: message }));
utils_1.default.notify("activities duration", message, "green");
}),
// get duration of activity
d: (socket, request) => __awaiter(void 0, void 0, void 0, function* () {
const resp = yield model_1.default.getDuration(request.args[0], request.args[1]);
socket.write(JSON.stringify({
err: false,
data: resp.data,
}));
const activity = (request === null || request === void 0 ? void 0 : request.args[0]) || timerObj.currentActivity || undefined;
let message = "";
if (activity) {
// could be undefined or 0
if (!timerObj.running ||
(request.args[0] && timerObj.currentActivity !== request.args[0])) {
// console.log('hitting the db', timerObj.durationChache);
const resp = yield model_1.default.getDuration({
socket,
activity: request.args[1],
duration: request.args[0],
});
// console.log(resp.data)
message = `${activity}: ${utils_1.default.secToTime(resp.data)}`;
}
else if (!request.args[0] ||
timerObj.currentActivity == request.args[0]) {
// console.log('hitting the cache', timerObj.durationChache);
const unstoredDuration = timerObj.running
? Math.floor((Date.now() - timerObj.startDate) / 1000)
: 0;
const duration = unstoredDuration + timerObj.durationChache;
// console.log(timerObj.durationChache);
// console.log(duration);
message = `${activity}: ${utils_1.default.secToTime(duration)}`;
}
}
else {
actions.da(socket, request);
return;
}
socket.write(JSON.stringify({ err: false, data: message }));
utils_1.default.notify("activity duration", message, "green");
}),

@@ -169,0 +254,0 @@ // status of the timer

@@ -18,2 +18,5 @@ "use strict";

};
const debug = (message) => {
notify("debug", message, "white");
};
const notify = (title, message, color, socket) => {

@@ -102,2 +105,11 @@ // exec("export DBUS_SESSION_BUS_ADDRESS=$(dbus-launch --exit-with-session | sed -n 's/^DBUS_SESSION_BUS_ADDRESS=//p')",

};
exports.default = { notify, activityNotify, rand, sleep, secToTime, getDate, log };
exports.default = {
notify,
activityNotify,
rand,
sleep,
secToTime,
getDate,
log,
debug,
};
{
"name": "clockify",
"version": "0.6.5",
"version": "0.7.5",
"description": "A time tracker to make sure that you really spent the time you think you spent working, studying, etc.",

@@ -5,0 +5,0 @@ "license": "MIT",

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