@apet97/clockify-cli-115 5.0.0 → 5.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  Command-line interface for [Clockify](https://clockify.me/), built on
4
4
  top of `clockify-sdk-ts-115`.
5
5
 
6
- Current release: `5.0.0`. Requires Node.js `>=22.13.0` and
6
+ Current release: `5.0.1`. Requires Node.js `>=22.13.0` and
7
7
  `clockify-sdk-ts-115 ^5`.
8
8
 
9
9
  Two binaries, identical behavior:
@@ -3,6 +3,9 @@ import { printObject, printRecords } from "../output.js";
3
3
  import { printReceipt } from "../receipt.js";
4
4
  import { clampPageSize, parseIntArg, resolveContext } from "./helpers.js";
5
5
  import { leafCommand } from "./leaf-command.js";
6
+ function quoteShellArgument(value) {
7
+ return `'${value.replaceAll("'", "'\"'\"'")}'`;
8
+ }
6
9
  function requireClientName(value, source) {
7
10
  if (typeof value !== "string" || value.trim() === "") {
8
11
  throw new Error(`${source} is missing the required client name; refusing to mutate.`);
@@ -100,7 +103,7 @@ export const registerClientsCommand = (program, services) => {
100
103
  changed: { created: [{ type: "client", id: data.id, name: data.name }] },
101
104
  next: [
102
105
  {
103
- command: `clk115 projects create ${JSON.stringify(`Project for ${data.name}`)} --client ${data.id}`,
106
+ command: `clk115 projects create ${quoteShellArgument(`Project for ${data.name}`)} --client ${quoteShellArgument(data.id)}`,
104
107
  reason: "Create a project for this client.",
105
108
  },
106
109
  ],
@@ -38,19 +38,62 @@ export function splitList(value) {
38
38
  .map((s) => s.trim())
39
39
  .filter((s) => s.length > 0);
40
40
  }
41
- export function promoteDateBoundary(value, flag, edge) {
42
- if (/^\d{4}-\d{2}-\d{2}$/.test(value)) {
43
- const probe = new Date(`${value}T00:00:00Z`);
44
- if (Number.isNaN(probe.getTime()) || probe.toISOString().slice(0, 10) !== value) {
41
+ const BARE_DATE_PATTERN = /^(\d{4})-(\d{2})-(\d{2})$/;
42
+ const RFC3339_TIMESTAMP_PATTERN = /^(\d{4})-(\d{2})-(\d{2})[Tt](\d{2}):(\d{2}):(\d{2})(?:\.\d+)?(?:[Zz]|[+-](\d{2}):(\d{2}))$/;
43
+ function hasValidCalendarDate(yearText, monthText, dayText) {
44
+ const year = Number(yearText);
45
+ const month = Number(monthText);
46
+ const day = Number(dayText);
47
+ const probe = new Date(0);
48
+ probe.setUTCFullYear(year, month - 1, day);
49
+ probe.setUTCHours(0, 0, 0, 0);
50
+ return (probe.getUTCFullYear() === year &&
51
+ probe.getUTCMonth() === month - 1 &&
52
+ probe.getUTCDate() === day);
53
+ }
54
+ function isRfc3339Timestamp(value) {
55
+ const match = RFC3339_TIMESTAMP_PATTERN.exec(value);
56
+ if (match === null || !hasValidCalendarDate(match[1], match[2], match[3])) {
57
+ return false;
58
+ }
59
+ const hour = Number(match[4]);
60
+ const minute = Number(match[5]);
61
+ const second = Number(match[6]);
62
+ const offsetHour = match[7] === undefined ? 0 : Number(match[7]);
63
+ const offsetMinute = match[8] === undefined ? 0 : Number(match[8]);
64
+ return (hour <= 23 &&
65
+ minute <= 59 &&
66
+ second <= 59 &&
67
+ offsetHour <= 23 &&
68
+ offsetMinute <= 59 &&
69
+ !Number.isNaN(Date.parse(value)));
70
+ }
71
+ export function requireRfc3339Timestamp(value, flag) {
72
+ if (!isRfc3339Timestamp(value)) {
73
+ throw new Error(`--${flag} ${JSON.stringify(value)} is not a valid RFC3339 timestamp; provide a value such as 2026-06-22T09:30:00Z`);
74
+ }
75
+ return value;
76
+ }
77
+ export function requireDateOrRfc3339(value, flag) {
78
+ const bareDate = BARE_DATE_PATTERN.exec(value);
79
+ if (bareDate !== null) {
80
+ if (!hasValidCalendarDate(bareDate[1], bareDate[2], bareDate[3])) {
45
81
  throw new Error(`--${flag} ${JSON.stringify(value)} is not a valid calendar date (YYYY-MM-DD); provide a real calendar date`);
46
82
  }
47
- return edge === "start" ? `${value}T00:00:00Z` : `${value}T23:59:59Z`;
83
+ return value;
48
84
  }
49
- if (Number.isNaN(Date.parse(value))) {
85
+ if (!isRfc3339Timestamp(value)) {
50
86
  throw new Error(`--${flag} ${JSON.stringify(value)} is not a valid date (YYYY-MM-DD) or RFC3339 timestamp; provide YYYY-MM-DD or an RFC3339 timestamp`);
51
87
  }
52
88
  return value;
53
89
  }
90
+ export function promoteDateBoundary(value, flag, edge) {
91
+ const validValue = requireDateOrRfc3339(value, flag);
92
+ if (BARE_DATE_PATTERN.test(validValue)) {
93
+ return edge === "start" ? `${value}T00:00:00Z` : `${value}T23:59:59Z`;
94
+ }
95
+ return validValue;
96
+ }
54
97
  export function rootProgram(cmd) {
55
98
  let current = cmd;
56
99
  while (current.parent != null) {
@@ -1,6 +1,6 @@
1
1
  import { parseDuration } from "../duration.js";
2
2
  import { printReceipt } from "../receipt.js";
3
- import { resolveContext } from "./helpers.js";
3
+ import { requireRfc3339Timestamp, resolveContext } from "./helpers.js";
4
4
  import { leafCommand } from "./leaf-command.js";
5
5
  import { resolveProjectId, resolveTaskId, resolveTagIds } from "./resolve-refs.js";
6
6
  export const registerLogCommand = (program, services) => {
@@ -14,10 +14,15 @@ export const registerLogCommand = (program, services) => {
14
14
  .option("--billable", "Mark the entry as billable.", false)
15
15
  .option("--end <iso>", "End timestamp (ISO 8601). Defaults to now.")
16
16
  .action(async function (duration, description, opts) {
17
- const { client, workspaceId, output } = await resolveContext(this, services);
18
17
  if (opts.task && !opts.project) {
19
18
  throw new Error("--task requires --project: a task entry must be scoped to its project.");
20
19
  }
20
+ const seconds = parseDuration(duration);
21
+ const endInput = requireRfc3339Timestamp(opts.end ?? new Date().toISOString(), "end");
22
+ const endMs = Date.parse(endInput);
23
+ const endIso = new Date(endMs).toISOString();
24
+ const startIso = new Date(endMs - seconds * 1000).toISOString();
25
+ const { client, workspaceId, output } = await resolveContext(this, services);
21
26
  const projectId = opts.project
22
27
  ? await resolveProjectId(client, workspaceId, opts.project)
23
28
  : undefined;
@@ -27,14 +32,6 @@ export const registerLogCommand = (program, services) => {
27
32
  const tagIds = opts.tag && opts.tag.length > 0
28
33
  ? await resolveTagIds(client, workspaceId, opts.tag)
29
34
  : undefined;
30
- const seconds = parseDuration(duration);
31
- const endInput = opts.end ?? new Date().toISOString();
32
- const endMs = Date.parse(endInput);
33
- if (Number.isNaN(endMs)) {
34
- throw new Error(`--end ${JSON.stringify(opts.end)} is not a valid ISO 8601 timestamp; provide an RFC3339 timestamp`);
35
- }
36
- const endIso = new Date(endMs).toISOString();
37
- const startIso = new Date(endMs - seconds * 1000).toISOString();
38
35
  const body = {
39
36
  start: startIso,
40
37
  end: endIso,
@@ -1,6 +1,6 @@
1
1
  import { printRecords } from "../output.js";
2
2
  import { printReceipt } from "../receipt.js";
3
- import { clampPageSize, parseFloatArg, parseIntArg, promoteDateBoundary, resolveContext, } from "./helpers.js";
3
+ import { clampPageSize, parseFloatArg, parseIntArg, promoteDateBoundary, requireRfc3339Timestamp, resolveContext, } from "./helpers.js";
4
4
  import { leafCommand } from "./leaf-command.js";
5
5
  export const registerSchedulingCommand = (program, services) => {
6
6
  const scheduling = program
@@ -54,13 +54,15 @@ export const registerSchedulingCommand = (program, services) => {
54
54
  .option("--include-non-working-days", "Include weekends/non-working days.", false)
55
55
  .option("--publish", "Publish immediately (default is draft).", false)
56
56
  .action(async function (opts) {
57
+ const start = requireRfc3339Timestamp(opts.start, "start");
58
+ const end = requireRfc3339Timestamp(opts.end, "end");
57
59
  const { client, workspaceId, output } = await resolveContext(this, services);
58
60
  const body = {
59
61
  userId: opts.user,
60
62
  projectId: opts.project,
61
63
  hoursPerDay: opts.hoursPerDay,
62
- start: opts.start,
63
- end: opts.end,
64
+ start,
65
+ end,
64
66
  };
65
67
  if (opts.task)
66
68
  body.taskId = opts.task;
@@ -76,8 +78,8 @@ export const registerSchedulingCommand = (program, services) => {
76
78
  if (opts.publish === true) {
77
79
  await client.scheduling.publish({
78
80
  workspaceId,
79
- start: opts.start,
80
- end: opts.end,
81
+ start,
82
+ end,
81
83
  userFilter: { contains: "CONTAINS", ids: [opts.user] },
82
84
  });
83
85
  }
@@ -86,8 +88,8 @@ export const registerSchedulingCommand = (program, services) => {
86
88
  user: created.userId ?? "",
87
89
  project: created.projectId ?? "",
88
90
  hoursPerDay: created.hoursPerDay ?? 0,
89
- start: created.start ?? created.period?.start ?? opts.start ?? "",
90
- end: created.end ?? created.period?.end ?? opts.end ?? "",
91
+ start: created.start ?? created.period?.start ?? start,
92
+ end: created.end ?? created.period?.end ?? end,
91
93
  published: opts.publish === true,
92
94
  };
93
95
  printReceipt({
@@ -1,7 +1,7 @@
1
1
  import { printRecords } from "../output.js";
2
2
  import { printReceipt } from "../receipt.js";
3
3
  import { registerBalanceAssignmentCommands } from "./balanceAssignment.js";
4
- import { clampPageSize, parseIntArg, promoteDateBoundary, resolveContext, splitList } from "./helpers.js";
4
+ import { clampPageSize, parseIntArg, promoteDateBoundary, requireDateOrRfc3339, requireRfc3339Timestamp, resolveContext, splitList, } from "./helpers.js";
5
5
  import { leafCommand } from "./leaf-command.js";
6
6
  export const registerTimeOffCommand = (program, services) => {
7
7
  const timeoff = program.command("timeoff").description("Time-off requests.");
@@ -76,10 +76,14 @@ export const registerTimeOffCommand = (program, services) => {
76
76
  if (!["FIRST_HALF", "SECOND_HALF", "NOT_DEFINED"].includes(halfDayPeriod)) {
77
77
  throw new Error(`--half-day-period must be FIRST_HALF, SECOND_HALF, or NOT_DEFINED (got "${String(opts.halfDayPeriod)}").`);
78
78
  }
79
+ const start = requireDateOrRfc3339(opts.start, "start");
80
+ const end = opts.end === undefined
81
+ ? undefined
82
+ : requireRfc3339Timestamp(opts.end, "end");
79
83
  const { client, workspaceId, output } = await resolveContext(this, services);
80
- const period = { start: opts.start };
81
- if (opts.end !== undefined)
82
- period.end = opts.end;
84
+ const period = { start };
85
+ if (end !== undefined)
86
+ period.end = end;
83
87
  if (Number.isFinite(opts.days))
84
88
  period.days = opts.days;
85
89
  const body = {
package/dist/duration.js CHANGED
@@ -9,19 +9,19 @@ export function parseDuration(input) {
9
9
  if (/^\d+(?:\.\d+)?$/.test(trimmed)) {
10
10
  return requirePositive(Math.round(Number(trimmed) * 60), input);
11
11
  }
12
- const compact = trimmed.replace(/\s+/g, "");
13
- const re = /(\d+(?:\.\d+)?)([dhms])/gi;
12
+ const re = /(\d+(?:\.\d+)?)\s*([dhms])\s*/giy;
14
13
  let total = 0;
15
- let consumed = 0;
16
- let match;
17
- while ((match = re.exec(compact)) !== null) {
14
+ let offset = 0;
15
+ while (offset < trimmed.length) {
16
+ re.lastIndex = offset;
17
+ const match = re.exec(trimmed);
18
+ if (match === null) {
19
+ throw new Error(`could not parse duration ${JSON.stringify(input)}; use forms like "1h30m", "45m", "90", or ISO "PT1H30M"`);
20
+ }
18
21
  const value = Number(match[1]);
19
22
  const unit = (match[2] ?? "").toLowerCase();
20
23
  total += value * unitToSeconds(unit);
21
- consumed += match[0].length;
22
- }
23
- if (consumed === 0 || consumed < compact.length) {
24
- throw new Error(`could not parse duration ${JSON.stringify(input)}; use forms like "1h30m", "45m", "90", or ISO "PT1H30M"`);
24
+ offset = re.lastIndex;
25
25
  }
26
26
  return requirePositive(Math.round(total), input);
27
27
  }
@@ -1 +1 @@
1
- export const PACKAGE_VERSION = "5.0.0";
1
+ export const PACKAGE_VERSION = "5.0.1";
package/dist/output.js CHANGED
@@ -78,7 +78,7 @@ export function selectValue(value, selector) {
78
78
  current = current[index];
79
79
  continue;
80
80
  }
81
- if (current !== null && typeof current === "object" && part in current) {
81
+ if (current !== null && typeof current === "object" && Object.hasOwn(current, part)) {
82
82
  current = current[part];
83
83
  continue;
84
84
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apet97/clockify-cli-115",
3
- "version": "5.0.0",
3
+ "version": "5.0.1",
4
4
  "description": "Unofficial, community-built \u2014 not affiliated with CAKE.com or Clockify. Command-line interface for Clockify, built on clockify-sdk-ts-115.",
5
5
  "license": "MIT",
6
6
  "author": "Aleksandar Petkovi\u0107 <petkovic.aleksandar037@gmail.com>",