@apet97/clockify-cli-115 0.4.0 → 0.6.0

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.
@@ -2,6 +2,24 @@ import { printObject, printRecords } from "../output.js";
2
2
  import { printReceipt } from "../receipt.js";
3
3
  import { clampPageSize, parseIntArg, resolveBaseContext, resolveContext } from "./helpers.js";
4
4
  import { leafCommand } from "./leaf-command.js";
5
+ const USER_DAYS = [
6
+ "MONDAY",
7
+ "TUESDAY",
8
+ "WEDNESDAY",
9
+ "THURSDAY",
10
+ "FRIDAY",
11
+ "SATURDAY",
12
+ "SUNDAY",
13
+ ];
14
+ const userDaysExhaustive = true;
15
+ void userDaysExhaustive;
16
+ function requireUserDay(value, message) {
17
+ const day = String(value).toUpperCase();
18
+ if (!USER_DAYS.includes(day)) {
19
+ throw new Error(message);
20
+ }
21
+ return day;
22
+ }
5
23
  export const registerUsersCommand = (program, services) => {
6
24
  const users = program.command("users").description("Inspect workspace users.");
7
25
  leafCommand(users, "me", "read")
@@ -45,11 +63,11 @@ export const registerUsersCommand = (program, services) => {
45
63
  .action(async function (email, opts) {
46
64
  const { client, workspaceId, output } = await resolveContext(this, services);
47
65
  const sendEmail = opts.sendEmail !== false;
48
- const workspace = (await client.workspaces.addUser({
66
+ await client.workspaces.addUser({
49
67
  workspaceId,
50
68
  "send-email": sendEmail ? "true" : "false",
51
69
  email,
52
- }));
70
+ });
53
71
  printReceipt({
54
72
  ok: true,
55
73
  action: "users.invite",
@@ -58,7 +76,7 @@ export const registerUsersCommand = (program, services) => {
58
76
  data: { email, sendEmail, message: `invited ${email}` },
59
77
  changed: {
60
78
  created: [
61
- { type: "workspace_member", id: workspace.id ?? "", name: email },
79
+ { type: "workspace_member", id: "", name: email },
62
80
  ],
63
81
  },
64
82
  next: [
@@ -74,9 +92,9 @@ export const registerUsersCommand = (program, services) => {
74
92
  .option("--name <text>", "Display name.")
75
93
  .option("--image-url <url>", "Profile image URL.")
76
94
  .option("--remove-image", "Remove the profile image.")
77
- .option("--week-start <day>", "Week start day, e.g. MONDAY.")
95
+ .option("--week-start <day>", "Week start day: MONDAY, TUESDAY, ... SUNDAY.")
78
96
  .option("--work-capacity <iso>", "Daily work capacity, ISO-8601 duration (e.g. PT8H).")
79
- .option("--working-days <days...>", "Working day enums, e.g. MONDAY TUESDAY.")
97
+ .option("--working-days <days...>", "Working days: MONDAY, TUESDAY, ... SUNDAY (space-separated).")
80
98
  .description("Update one user's member profile (name, image, week start, work capacity, working days).")
81
99
  .action(async function (userId, opts) {
82
100
  const { client, workspaceId, output } = await resolveContext(this, services);
@@ -87,12 +105,18 @@ export const registerUsersCommand = (program, services) => {
87
105
  body.imageUrl = opts.imageUrl;
88
106
  if (opts.removeImage)
89
107
  body.removeProfileImage = true;
90
- if (opts.weekStart !== undefined)
91
- body.weekStart = opts.weekStart;
108
+ if (opts.weekStart !== undefined) {
109
+ body.weekStart = requireUserDay(opts.weekStart, `--week-start must be one of: ${USER_DAYS.join(", ")}.`);
110
+ }
92
111
  if (opts.workCapacity !== undefined)
93
112
  body.workCapacity = opts.workCapacity;
94
- if (Array.isArray(opts.workingDays) && opts.workingDays.length > 0)
95
- body.workingDays = opts.workingDays;
113
+ if (Array.isArray(opts.workingDays) && opts.workingDays.length > 0) {
114
+ const days = [];
115
+ for (const raw of opts.workingDays) {
116
+ days.push(requireUserDay(raw, `--working-days entries must be one of: ${USER_DAYS.join(", ")}.`));
117
+ }
118
+ body.workingDays = days;
119
+ }
96
120
  const updated = (await client.memberProfiles.update({ workspaceId, userId, body }));
97
121
  printReceipt({
98
122
  ok: true,
@@ -4,7 +4,7 @@ import { printRecords } from "../output.js";
4
4
  import { printReceipt } from "../receipt.js";
5
5
  import { resolveContext, splitList } from "./helpers.js";
6
6
  import { leafCommand } from "./leaf-command.js";
7
- const WEBHOOK_LIST_TYPES = ["WEBHOOK", "ADDON_WEBHOOK"];
7
+ const WEBHOOK_LIST_TYPES = ["USER_CREATED", "SYSTEM", "ADDON"];
8
8
  const WEBHOOK_TRIGGER_SOURCE_TYPES = [
9
9
  "PROJECT_ID",
10
10
  "USER_ID",
@@ -82,18 +82,18 @@ function nonEmptyString(value, field) {
82
82
  function webhookEvent(value) {
83
83
  const event = String(value).toUpperCase();
84
84
  if (!WEBHOOK_EVENT_TYPES.includes(event)) {
85
- throw new Error(`Unknown webhook event: ${String(value)}`);
85
+ throw new Error(`Unknown webhook event: ${String(value)}. Provide a Clockify webhook event type such as NEW_PROJECT or NEW_TIME_ENTRY.`);
86
86
  }
87
87
  return event;
88
88
  }
89
89
  function webhookTriggerSourceType(value) {
90
90
  const raw = value ?? "WORKSPACE_ID";
91
91
  if (typeof raw !== "string") {
92
- throw new Error("Unknown trigger source type: expected a string.");
92
+ throw new Error("Unknown trigger source type. Provide one of: PROJECT_ID, USER_ID, TAG_ID, TASK_ID, WORKSPACE_ID, ASSIGNMENT_ID, EXPENSE_ID.");
93
93
  }
94
94
  const type = raw.toUpperCase();
95
95
  if (!WEBHOOK_TRIGGER_SOURCE_TYPES.includes(type)) {
96
- throw new Error(`Unknown trigger source type: ${raw}`);
96
+ throw new Error(`Unknown trigger source type: ${raw}. Provide one of: PROJECT_ID, USER_ID, TAG_ID, TASK_ID, WORKSPACE_ID, ASSIGNMENT_ID, EXPENSE_ID.`);
97
97
  }
98
98
  return type;
99
99
  }
@@ -101,14 +101,14 @@ export const registerWebhooksCommand = (program, services) => {
101
101
  const webhooks = program.command("webhooks").description("Manage outbound webhooks.");
102
102
  leafCommand(webhooks, "list", "read")
103
103
  .description("List webhooks in the workspace.")
104
- .option("--type <type>", "Filter by webhook type (e.g. WEBHOOK, ADDON_WEBHOOK).")
104
+ .option("--type <type>", "Filter by webhook type (USER_CREATED, SYSTEM, ADDON).")
105
105
  .action(async function (opts) {
106
106
  const { client, workspaceId, output } = await resolveContext(this, services);
107
107
  let type;
108
108
  if (opts.type) {
109
109
  const candidate = String(opts.type).toUpperCase();
110
110
  if (!WEBHOOK_LIST_TYPES.includes(candidate)) {
111
- throw new Error(`Unknown webhook type: ${opts.type}`);
111
+ throw new Error(`Unknown webhook type: ${opts.type}. Provide one of: ${WEBHOOK_LIST_TYPES.join(", ")}.`);
112
112
  }
113
113
  type = candidate;
114
114
  }
@@ -19,6 +19,7 @@ export const COMMANDS = [
19
19
  "reports",
20
20
  "shared-reports",
21
21
  "users",
22
+ "approvals",
22
23
  "completion",
23
24
  "help",
24
25
  ];
package/dist/config.js CHANGED
@@ -38,27 +38,28 @@ function loadRcFile(env) {
38
38
  if (!existsSync(path)) {
39
39
  continue;
40
40
  }
41
+ let parsed = {};
41
42
  try {
42
43
  const raw = readFileSync(path, "utf8");
43
- const parsed = JSON.parse(raw);
44
- if (Object.prototype.hasOwnProperty.call(parsed, "apiKey")) {
45
- throw new Error("legacy rc-file secret detected: remove apiKey from the rc file and set CLOCKIFY_API_KEY in the process environment");
46
- }
47
- const out = {};
48
- if (typeof parsed.workspaceId === "string")
49
- out.workspaceId = parsed.workspaceId;
50
- if (typeof parsed.baseUrl === "string")
51
- out.baseUrl = parsed.baseUrl;
52
- if (typeof parsed.region === "string")
53
- out.region = parsed.region;
54
- if (typeof parsed.subdomain === "string")
55
- out.subdomain = parsed.subdomain;
56
- return out;
44
+ parsed = JSON.parse(raw);
57
45
  }
58
46
  catch (err) {
59
47
  const reason = err instanceof Error ? err.message : String(err);
60
48
  throw new Error(`failed to read Clockify rc file ${path}: ${reason}`);
61
49
  }
50
+ if (Object.prototype.hasOwnProperty.call(parsed, "apiKey")) {
51
+ throw new Error("legacy rc-file secret detected: remove apiKey from the rc file and set CLOCKIFY_API_KEY in the process environment");
52
+ }
53
+ const out = {};
54
+ if (typeof parsed.workspaceId === "string")
55
+ out.workspaceId = parsed.workspaceId;
56
+ if (typeof parsed.baseUrl === "string")
57
+ out.baseUrl = parsed.baseUrl;
58
+ if (typeof parsed.region === "string")
59
+ out.region = parsed.region;
60
+ if (typeof parsed.subdomain === "string")
61
+ out.subdomain = parsed.subdomain;
62
+ return out;
62
63
  }
63
64
  return {};
64
65
  }
package/dist/duration.js CHANGED
@@ -1,7 +1,7 @@
1
1
  export function parseDuration(input) {
2
2
  const trimmed = input.trim();
3
3
  if (trimmed === "") {
4
- throw new Error("duration is empty");
4
+ throw new Error('duration is missing; provide a form like "1h30m", "45m", "90", or ISO "PT1H30M"');
5
5
  }
6
6
  if (/^PT/i.test(trimmed)) {
7
7
  return parseIsoDuration(trimmed);
@@ -21,7 +21,7 @@ export function parseDuration(input) {
21
21
  consumed += match[0].length;
22
22
  }
23
23
  if (consumed === 0 || consumed < compact.length) {
24
- throw new Error(`cannot parse duration ${JSON.stringify(input)}; use forms like "1h30m", "45m", "90", or ISO "PT1H30M"`);
24
+ throw new Error(`could not parse duration ${JSON.stringify(input)}; use forms like "1h30m", "45m", "90", or ISO "PT1H30M"`);
25
25
  }
26
26
  return Math.round(total);
27
27
  }
@@ -29,7 +29,7 @@ function parseIsoDuration(input) {
29
29
  const re = /^PT(?:(\d+(?:\.\d+)?)H)?(?:(\d+(?:\.\d+)?)M)?(?:(\d+(?:\.\d+)?)S)?$/i;
30
30
  const match = re.exec(input);
31
31
  if (!match || (match[1] == null && match[2] == null && match[3] == null)) {
32
- throw new Error(`cannot parse ISO duration ${JSON.stringify(input)}`);
32
+ throw new Error(`could not parse ISO duration ${JSON.stringify(input)}; provide a form like "PT1H30M"`);
33
33
  }
34
34
  const hours = match[1] != null ? Number(match[1]) : 0;
35
35
  const minutes = match[2] != null ? Number(match[2]) : 0;
@@ -1 +1 @@
1
- export const PACKAGE_VERSION = "0.4.0";
1
+ export const PACKAGE_VERSION = "0.6.0";
package/dist/index.js CHANGED
@@ -1,7 +1,10 @@
1
1
  #!/usr/bin/env node
2
- import { Command } from "commander";
2
+ import { realpathSync } from "node:fs";
3
+ import { pathToFileURL } from "node:url";
4
+ import { Command, InvalidArgumentError } from "commander";
3
5
  import { buildClient } from "./client.js";
4
6
  import { registerApiCommand } from "./commands/api.js";
7
+ import { registerApprovalsCommand } from "./commands/approvals.js";
5
8
  import { registerAuditLogCommand } from "./commands/auditlog.js";
6
9
  import { registerClientsCommand } from "./commands/clients.js";
7
10
  import { registerDoctorCommand } from "./commands/doctor.js";
@@ -41,7 +44,7 @@ export function buildProgram(services = defaultServices) {
41
44
  .option("--region <name>", "Clockify routing region: global, eu, us, uk, au, or developer (or CLOCKIFY_REGION env var). Mutually exclusive with --base-url.")
42
45
  .option("--subdomain <label>", "Workspace subdomain for reports routing; requires --region eu/us/uk/au (or CLOCKIFY_SUBDOMAIN env var).")
43
46
  .option("--json", "Emit machine-readable JSON instead of human-friendly tables.", false)
44
- .option("--output <mode>", "Output mode: table, json, or ndjson.")
47
+ .option("--output <mode>", "Output mode: table, json, or ndjson.", parseOutputMode)
45
48
  .option("--compact", "Print compact JSON without indentation.", false)
46
49
  .option("--select <path>", "Select a dot-path before printing JSON or NDJSON.")
47
50
  .option("--no-color", "Disable ANSI color output.")
@@ -66,6 +69,7 @@ export function buildProgram(services = defaultServices) {
66
69
  registerReportsCommand(program, services);
67
70
  registerSharedReportsCommand(program, services);
68
71
  registerUsersCommand(program, services);
72
+ registerApprovalsCommand(program, services);
69
73
  leafCommand(program, "completion", "read")
70
74
  .argument("[shell]", "Shell to generate completion for: zsh, bash, or fish.", "zsh")
71
75
  .description("Print shell completion script for zsh, bash, or fish.")
@@ -99,6 +103,14 @@ function resolveFlagsSafe(program) {
99
103
  };
100
104
  }
101
105
  }
106
+ function parseOutputMode(value) {
107
+ const modes = ["table", "json", "ndjson"];
108
+ const match = modes.find((mode) => mode === value);
109
+ if (!match) {
110
+ throw new InvalidArgumentError("Provide one of: table, json, ndjson.");
111
+ }
112
+ return match;
113
+ }
102
114
  function resolveMode(output, json) {
103
115
  if (output === undefined) {
104
116
  return json ? "json" : "table";
@@ -106,7 +118,7 @@ function resolveMode(output, json) {
106
118
  const modes = ["table", "json", "ndjson"];
107
119
  const match = modes.find((mode) => mode === output);
108
120
  if (!match) {
109
- throw new Error(`Unsupported output mode "${output}". Use table, json, or ndjson.`);
121
+ throw new Error(`Unsupported output mode "${output}". Provide one of: table, json, ndjson.`);
110
122
  }
111
123
  return match;
112
124
  }
@@ -162,14 +174,25 @@ function isCommanderUsageError(err) {
162
174
  typeof err.code === "string" &&
163
175
  err.code.startsWith("commander."));
164
176
  }
177
+ function isDirectInvocation(argv1) {
178
+ if (argv1 === undefined)
179
+ return false;
180
+ try {
181
+ return pathToFileURL(realpathSync(argv1)).href === import.meta.url;
182
+ }
183
+ catch {
184
+ return false;
185
+ }
186
+ }
165
187
  const invokedDirectly = typeof process !== "undefined" &&
166
188
  Array.isArray(process.argv) &&
167
- process.argv[1] !== undefined &&
168
- /(?:^|\/)(?:clockify115|clk115|index\.[jt]s)$/.test(process.argv[1]);
189
+ isDirectInvocation(process.argv[1]);
169
190
  if (invokedDirectly) {
170
- main(process.argv).then((code) => process.exit(code), (err) => {
191
+ main(process.argv).then((code) => {
192
+ process.exitCode = code;
193
+ }, (err) => {
171
194
  const message = err instanceof Error ? err.message : String(err);
172
195
  console.error(`fatal: ${message}`);
173
- process.exit(1);
196
+ process.exitCode = 1;
174
197
  });
175
198
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apet97/clockify-cli-115",
3
- "version": "0.4.0",
3
+ "version": "0.6.0",
4
4
  "description": "Unofficial, community-built — 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ć <petkovic.aleksandar037@gmail.com>",
@@ -51,7 +51,7 @@
51
51
  "cli-table3": "^0.6.5",
52
52
  "commander": "^15.0.0",
53
53
  "picocolors": "^1.1.1",
54
- "zod": "^3.25.0"
54
+ "zod": "^4.4.3"
55
55
  },
56
56
  "peerDependencies": {
57
57
  "clockify-sdk-ts-115": ">=0.13.0 <1"
@@ -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.5.0",
63
+ "eslint": "^10.8.0",
64
64
  "eslint-plugin-import-x": "^4.17.1",
65
- "tsx": "^4.19.2",
65
+ "tsx": "^4.23.1",
66
66
  "typescript": "^5.7.0",
67
- "typescript-eslint": "^8.64.0",
67
+ "typescript-eslint": "^8.65.0",
68
68
  "vitest": "^4.1.10"
69
69
  },
70
70
  "publishConfig": {