@apet97/clockify-cli-115 5.0.2 → 5.0.3

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.2`. Requires Node.js `>=22.13.0` and
6
+ Current release: `5.0.3`. Requires Node.js `>=22.13.0` and
7
7
  `clockify-sdk-ts-115 ^5`.
8
8
 
9
9
  Two binaries, identical behavior:
@@ -88,6 +88,22 @@ Read-only commands (e.g. `status`, `entries list`) print the requested
88
88
  object or array directly, with no `ok` wrapper. `--no-color` disables
89
89
  ANSI codes, and the CLI also auto-disables color when stdout is not a TTY.
90
90
 
91
+ ### Money units
92
+
93
+ Clockify's wire units are not uniform, and the CLI keeps its established
94
+ `amount` field names for JSON compatibility:
95
+
96
+ - `expenses create --amount` and `expenses update --amount` accept major
97
+ currency units, so `42.50` means 42.50 in the selected currency.
98
+ - `expenses list` emits the response `total` as `amount` in minor units
99
+ (cents for two-decimal currencies), so 42.50 is returned as `4250`.
100
+ - Invoice `amount` values from `invoices list` and `invoices create` receipts
101
+ are also minor units.
102
+
103
+ Use an emitted `currency` value when present; otherwise apply the workspace or
104
+ entity currency. The raw `api` command always returns Clockify's response
105
+ without unit conversion.
106
+
91
107
  ## Commands
92
108
 
93
109
  <!-- BEGIN generated:cli-commands -->
@@ -1,6 +1,6 @@
1
1
  import { readFileSync } from "node:fs";
2
2
  import pc from "picocolors";
3
- import { printJson, printNdjson } from "../output.js";
3
+ import { AlreadyReportedError, printJson, printNdjson } from "../output.js";
4
4
  import { parseIntArg, resolveBaseContext } from "./helpers.js";
5
5
  import { leafCommand } from "./leaf-command.js";
6
6
  const METHODS = new Set(["GET", "POST", "PUT", "PATCH", "DELETE"]);
@@ -27,7 +27,7 @@ export const registerApiCommand = (program, services) => {
27
27
  throw new Error(`Unsupported method "${methodArg}". Provide one of: GET, POST, PUT, PATCH, DELETE.`);
28
28
  }
29
29
  const path = resolvePath(pathArg, config.workspaceId);
30
- const query = parsePairs(options.query);
30
+ const query = parseQueryPairs(options.query);
31
31
  const headers = parsePairs(options.header);
32
32
  if (options.all) {
33
33
  if (method !== "GET") {
@@ -53,6 +53,9 @@ export const registerApiCommand = (program, services) => {
53
53
  });
54
54
  }
55
55
  printApiOutput(responsePayload(response, data, options.includeHeaders), output);
56
+ if (!response.ok) {
57
+ throw new AlreadyReportedError();
58
+ }
56
59
  });
57
60
  };
58
61
  function collect(value, previous) {
@@ -60,19 +63,21 @@ function collect(value, previous) {
60
63
  return previous;
61
64
  }
62
65
  function parsePairs(values) {
63
- const result = {};
64
- for (const value of values) {
65
- const index = value.indexOf("=");
66
- if (index <= 0) {
67
- throw new Error(`Expected key=value, received "${value}".`);
68
- }
69
- const key = value.slice(0, index).trim();
70
- if (!key) {
71
- throw new Error(`Expected non-empty key in "${value}".`);
72
- }
73
- result[key] = value.slice(index + 1);
66
+ return Object.fromEntries(values.map(parsePair));
67
+ }
68
+ function parseQueryPairs(values) {
69
+ return values.map(parsePair);
70
+ }
71
+ function parsePair(value) {
72
+ const index = value.indexOf("=");
73
+ if (index <= 0) {
74
+ throw new Error(`Expected key=value, received "${value}".`);
75
+ }
76
+ const key = value.slice(0, index).trim();
77
+ if (!key) {
78
+ throw new Error(`Expected non-empty key in "${value}".`);
74
79
  }
75
- return result;
80
+ return [key, value.slice(index + 1)];
76
81
  }
77
82
  function resolvePath(path, workspaceId) {
78
83
  if (!path.startsWith("/")) {
@@ -90,8 +95,10 @@ function buildPath(path, query) {
90
95
  const qIndex = path.indexOf("?");
91
96
  const base = qIndex === -1 ? path : path.slice(0, qIndex);
92
97
  const params = new URLSearchParams(qIndex === -1 ? "" : path.slice(qIndex + 1));
93
- for (const [key, value] of Object.entries(query))
94
- params.set(key, value);
98
+ for (const key of new Set(query.map(([name]) => name)))
99
+ params.delete(key);
100
+ for (const [key, value] of query)
101
+ params.append(key, value);
95
102
  const search = params.toString();
96
103
  return search ? `${base}?${search}` : base;
97
104
  }
@@ -124,9 +131,14 @@ function readBody(body) {
124
131
  }
125
132
  async function fetchAllPages(client, path, query, headers, pageSize, maxPages) {
126
133
  const items = [];
134
+ const callerQuery = query.filter(([key]) => key !== "page" && key !== "page-size");
127
135
  let truncated = true;
128
136
  for (let page = 1; page <= maxPages; page += 1) {
129
- const pagePath = buildPath(path, { ...query, page: String(page), "page-size": String(pageSize) });
137
+ const pagePath = buildPath(path, [
138
+ ...callerQuery,
139
+ ["page", String(page)],
140
+ ["page-size", String(pageSize)],
141
+ ]);
130
142
  const response = await client.fetch(pagePath, requestInit("GET", headers));
131
143
  const data = await readResponseData(response);
132
144
  if (!response.ok) {
@@ -139,6 +151,10 @@ async function fetchAllPages(client, path, query, headers, pageSize, maxPages) {
139
151
  }
140
152
  const lastPage = parseLastPageHeader(response.headers.get("Last-Page"));
141
153
  items.push(...data);
154
+ if (data.length === 0) {
155
+ truncated = false;
156
+ break;
157
+ }
142
158
  if (lastPage === true) {
143
159
  truncated = false;
144
160
  break;
@@ -146,7 +162,7 @@ async function fetchAllPages(client, path, query, headers, pageSize, maxPages) {
146
162
  if (lastPage === false) {
147
163
  continue;
148
164
  }
149
- if (data.length === 0 || data.length < pageSize) {
165
+ if (data.length < pageSize) {
150
166
  truncated = false;
151
167
  break;
152
168
  }
@@ -1,5 +1,5 @@
1
1
  import { printReceipt } from "../receipt.js";
2
- import { resolveContext } from "./helpers.js";
2
+ import { requireRfc3339Timestamp, resolveContext } from "./helpers.js";
3
3
  import { leafCommand } from "./leaf-command.js";
4
4
  const PERIODS = ["WEEKLY", "SEMI_MONTHLY", "MONTHLY"];
5
5
  const SELF_TYPES = ["TIMESHEET", "EXPENSE"];
@@ -31,9 +31,10 @@ export const registerApprovalsCommand = (program, services) => {
31
31
  .option("--period <period>", "Approval period: WEEKLY, SEMI_MONTHLY, or MONTHLY.")
32
32
  .action(async function (opts) {
33
33
  const type = requireEnum(opts.type, SELF_TYPES, "type");
34
+ const periodStart = requireRfc3339Timestamp(opts.periodStart, "period-start");
34
35
  const { client, workspaceId, output } = await resolveContext(this, services);
35
36
  const body = {
36
- periodStart: opts.periodStart,
37
+ periodStart,
37
38
  };
38
39
  if (opts.period)
39
40
  body.period = requireEnum(opts.period, PERIODS, "period");
@@ -69,9 +70,10 @@ export const registerApprovalsCommand = (program, services) => {
69
70
  .option("--period <period>", "Approval period: WEEKLY, SEMI_MONTHLY, or MONTHLY.")
70
71
  .action(async function (opts) {
71
72
  const type = requireEnum(opts.type, OTHER_TYPES, "type");
73
+ const periodStart = requireRfc3339Timestamp(opts.periodStart, "period-start");
72
74
  const { client, workspaceId, output } = await resolveContext(this, services);
73
75
  const body = {
74
- periodStart: opts.periodStart,
76
+ periodStart,
75
77
  };
76
78
  if (opts.period)
77
79
  body.period = requireEnum(opts.period, PERIODS, "period");
@@ -1,15 +1,15 @@
1
1
  import { printRecords } from "../output.js";
2
2
  import { printReceipt } from "../receipt.js";
3
- import { parseSignedFloatArg, resolveContext, splitList } from "./helpers.js";
3
+ import { parseSignedFloatArg, requireCalendarDate, resolveContext, splitList, } from "./helpers.js";
4
4
  import { leafCommand } from "./leaf-command.js";
5
5
  function dateRange(opts) {
6
6
  if (opts.start === undefined && opts.end === undefined)
7
7
  return undefined;
8
8
  const range = {};
9
9
  if (opts.start !== undefined)
10
- range.start = opts.start;
10
+ range.start = requireCalendarDate(opts.start, "start");
11
11
  if (opts.end !== undefined)
12
- range.end = opts.end;
12
+ range.end = requireCalendarDate(opts.end, "end");
13
13
  return range;
14
14
  }
15
15
  export function registerBalanceAssignmentCommands(timeoff, services) {
@@ -50,6 +50,7 @@ export function registerBalanceAssignmentCommands(timeoff, services) {
50
50
  .option("--start <date>", "Balance window start (YYYY-MM-DD).")
51
51
  .option("--end <date>", "Balance window end (YYYY-MM-DD).")
52
52
  .action(async function (opts) {
53
+ const range = dateRange(opts);
53
54
  const { client, workspaceId, output } = await resolveContext(this, services);
54
55
  const userIds = splitList(opts.user);
55
56
  if (userIds.length === 0)
@@ -61,7 +62,6 @@ export function registerBalanceAssignmentCommands(timeoff, services) {
61
62
  };
62
63
  if (opts.note !== undefined)
63
64
  body.note = opts.note;
64
- const range = dateRange(opts);
65
65
  if (range !== undefined)
66
66
  body.dateRange = range;
67
67
  await client.balanceAssignment.createBalanceAssignment({ workspaceId, body });
@@ -95,11 +95,11 @@ export function registerBalanceAssignmentCommands(timeoff, services) {
95
95
  .option("--start <date>", "Balance window start (YYYY-MM-DD).")
96
96
  .option("--end <date>", "Balance window end (YYYY-MM-DD).")
97
97
  .action(async function (opts) {
98
+ const range = dateRange(opts);
98
99
  const { client, workspaceId, output } = await resolveContext(this, services);
99
100
  const body = { balanceChange: opts.change };
100
101
  if (opts.note !== undefined)
101
102
  body.note = opts.note;
102
- const range = dateRange(opts);
103
103
  if (range !== undefined)
104
104
  body.dateRange = range;
105
105
  await client.balanceAssignment.updateBalanceAssignment({
@@ -52,7 +52,7 @@ export const registerExpensesCommand = (program, services) => {
52
52
  id: e.id ?? "",
53
53
  date: e.date ?? "",
54
54
  category,
55
- projectId: e.projectId ?? "",
55
+ projectId: e.project?.id ?? "",
56
56
  amount: e.total ?? e.amount ?? e.quantity ?? 0,
57
57
  currency: e.currency ?? "",
58
58
  billable: e.billable === true,
@@ -68,6 +68,13 @@ function isRfc3339Timestamp(value) {
68
68
  offsetMinute <= 59 &&
69
69
  !Number.isNaN(Date.parse(value)));
70
70
  }
71
+ export function requireCalendarDate(value, flag) {
72
+ const match = BARE_DATE_PATTERN.exec(value);
73
+ if (match === null || !hasValidCalendarDate(match[1], match[2], match[3])) {
74
+ throw new Error(`--${flag} ${JSON.stringify(value)} is not a valid calendar date (YYYY-MM-DD); provide a real calendar date`);
75
+ }
76
+ return value;
77
+ }
71
78
  export function requireRfc3339Timestamp(value, flag) {
72
79
  if (!isRfc3339Timestamp(value)) {
73
80
  throw new Error(`--${flag} ${JSON.stringify(value)} is not a valid RFC3339 timestamp; provide a value such as 2026-06-22T09:30:00Z`);
@@ -75,12 +82,8 @@ export function requireRfc3339Timestamp(value, flag) {
75
82
  return value;
76
83
  }
77
84
  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])) {
81
- throw new Error(`--${flag} ${JSON.stringify(value)} is not a valid calendar date (YYYY-MM-DD); provide a real calendar date`);
82
- }
83
- return value;
85
+ if (BARE_DATE_PATTERN.test(value)) {
86
+ return requireCalendarDate(value, flag);
84
87
  }
85
88
  if (!isRfc3339Timestamp(value)) {
86
89
  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`);
@@ -1,4 +1,4 @@
1
- import { printRecords } from "../output.js";
1
+ import { AlreadyReportedError, printRecords } from "../output.js";
2
2
  import { printReceipt } from "../receipt.js";
3
3
  import { clampPageSize, parseFloatArg, parseIntArg, promoteDateBoundary, requireRfc3339Timestamp, resolveContext, } from "./helpers.js";
4
4
  import { leafCommand } from "./leaf-command.js";
@@ -80,13 +80,24 @@ export const registerSchedulingCommand = (program, services) => {
80
80
  const req = { workspaceId, body };
81
81
  const createdList = (await client.scheduling.createRecurring(req));
82
82
  const created = createdList[0] ?? {};
83
+ let published = false;
84
+ let publishWarning;
85
+ let failedPublishRequest;
83
86
  if (opts.publish === true) {
84
- await client.scheduling.publish({
85
- workspaceId,
87
+ const publishRequest = {
86
88
  start,
87
89
  end,
88
90
  userFilter: { contains: "CONTAINS", ids: [opts.user] },
89
- });
91
+ };
92
+ try {
93
+ await client.scheduling.publish({ workspaceId, body: publishRequest });
94
+ published = true;
95
+ }
96
+ catch (err) {
97
+ const detail = err instanceof Error ? err.message : String(err);
98
+ publishWarning = `The assignment was created but publishing it failed: ${detail}. It remains an unpublished draft.`;
99
+ failedPublishRequest = publishRequest;
100
+ }
90
101
  }
91
102
  const data = {
92
103
  id: created.id ?? "",
@@ -95,21 +106,43 @@ export const registerSchedulingCommand = (program, services) => {
95
106
  hoursPerDay: created.hoursPerDay ?? 0,
96
107
  start: created.start ?? created.period?.start ?? start,
97
108
  end: created.end ?? created.period?.end ?? end,
98
- published: opts.publish === true,
109
+ published,
110
+ ...(failedPublishRequest
111
+ ? {
112
+ warningCode: "publish_failed",
113
+ publishRequest: failedPublishRequest,
114
+ }
115
+ : {}),
99
116
  };
117
+ const recoveryCommand = "clk115 api PUT /workspaces/{workspaceId}/scheduling/assignments/publish --body -";
118
+ const recoveryReason = "Pipe the stored publishRequest JSON to stdin to publish the created draft.";
119
+ const receiptData = failedPublishRequest
120
+ ? { ...data, recoveryCommand, recovery: recoveryReason }
121
+ : data;
100
122
  printReceipt({
101
123
  ok: true,
102
124
  action: "scheduling.create",
103
125
  entity: "scheduling_assignment",
104
126
  ids: { assignmentId: data.id },
105
- data,
127
+ data: receiptData,
106
128
  changed: { created: [{ type: "scheduling_assignment", id: data.id }] },
107
- next: [
108
- {
109
- command: `clk115 scheduling list --from ${data.start} --to ${data.end} --json`,
110
- reason: "Verify the assignment appears.",
111
- },
112
- ],
129
+ ...(publishWarning ? { warnings: [publishWarning] } : {}),
130
+ next: publishWarning
131
+ ? [
132
+ {
133
+ command: recoveryCommand,
134
+ reason: recoveryReason,
135
+ },
136
+ ]
137
+ : [
138
+ {
139
+ command: `clk115 scheduling list --from ${data.start} --to ${data.end} --json`,
140
+ reason: "Verify the assignment appears.",
141
+ },
142
+ ],
113
143
  }, output);
144
+ if (failedPublishRequest) {
145
+ throw new AlreadyReportedError();
146
+ }
114
147
  });
115
148
  };
@@ -306,7 +306,7 @@ export const registerSharedReportsCommand = (program, services) => {
306
306
  .description("Create a shared (public-link) report.")
307
307
  .addHelpText("after", "\nExamples:\n" +
308
308
  " $ clk115 shared-reports create --name \"Q3 Summary\" --type SUMMARY \\\n" +
309
- " --filter '{}' --public\n")
309
+ " --filter '{\"dateRangeStart\":\"2026-07-01\",\"dateRangeEnd\":\"2026-09-30\",\"exportType\":\"JSON_V1\"}' --public\n")
310
310
  .action(async function (opts) {
311
311
  const { client, workspaceId, output } = await resolveContext(this, services);
312
312
  const body = parseSharedReportBody(sharedReportCreateBodySchema, opts, "shared-reports.create");
@@ -1 +1 @@
1
- export const PACKAGE_VERSION = "5.0.2";
1
+ export const PACKAGE_VERSION = "5.0.3";
package/dist/index.js CHANGED
@@ -29,7 +29,7 @@ import { registerWebhooksCommand } from "./commands/webhooks.js";
29
29
  import { parseCompletionShell, renderCompletion } from "./completions.js";
30
30
  import { loadConfig } from "./config.js";
31
31
  import { PACKAGE_VERSION } from "./generated/version.js";
32
- import { printError } from "./output.js";
32
+ import { AlreadyReportedError, printError, } from "./output.js";
33
33
  const defaultServices = {
34
34
  loadConfig,
35
35
  buildClient,
@@ -158,6 +158,9 @@ export async function main(argv, services = defaultServices) {
158
158
  if (isCommanderHelpError(err)) {
159
159
  return err.exitCode ?? 0;
160
160
  }
161
+ if (err instanceof AlreadyReportedError) {
162
+ return 1;
163
+ }
161
164
  const message = clockifyErrorDetail(err);
162
165
  const statusCode = err.statusCode;
163
166
  const flags = resolveFlagsSafe(program);
package/dist/output.js CHANGED
@@ -1,6 +1,12 @@
1
1
  import Table from "cli-table3";
2
2
  import pc from "picocolors";
3
3
  import { errorCodeForMessage, errorCodeForStatus, recoveryForCode, retryableForCode, } from "./error-codes.js";
4
+ export class AlreadyReportedError extends Error {
5
+ constructor() {
6
+ super("Command failed after reporting the error response.");
7
+ this.name = "AlreadyReportedError";
8
+ }
9
+ }
4
10
  export function printRecords(rows, opts) {
5
11
  if (opts.mode === "json") {
6
12
  printJson(rows, opts);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apet97/clockify-cli-115",
3
- "version": "5.0.2",
3
+ "version": "5.0.3",
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>",
@@ -60,11 +60,11 @@
60
60
  "@types/node": "^22",
61
61
  "@vitest/coverage-v8": "^4.1.10",
62
62
  "clockify-sdk-ts-115": "*",
63
- "eslint": "^10.8.0",
63
+ "eslint": "^10.8.1",
64
64
  "eslint-plugin-import-x": "^4.17.1",
65
- "tsx": "^4.23.1",
65
+ "tsx": "^4.23.12",
66
66
  "typescript": "^7.0.2",
67
- "typescript-eslint": "^8.65.0",
67
+ "typescript-eslint": "^8.67.0",
68
68
  "vitest": "^4.1.10"
69
69
  },
70
70
  "publishConfig": {